diff options
| author | vvvv <[email protected]> | 2025-10-06 11:26:09 +0300 |
|---|---|---|
| committer | vvvv <[email protected]> | 2025-10-06 11:53:26 +0300 |
| commit | 60f45e69a4d7dbc6131208e16c45faf35aa5a985 (patch) | |
| tree | 4daa45b52c295a178c7620e4c93921465fcf7950 /yql/essentials/utils/backtrace/backtrace_lib.cpp | |
| parent | 1bded1a65a7e6e9171418f3e1c691d390125b64e (diff) | |
YQL-20086 utils
init
commit_hash:54feccd520ebd0ab23612bc0cb830914dff9d0e8
Diffstat (limited to 'yql/essentials/utils/backtrace/backtrace_lib.cpp')
| -rw-r--r-- | yql/essentials/utils/backtrace/backtrace_lib.cpp | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/yql/essentials/utils/backtrace/backtrace_lib.cpp b/yql/essentials/utils/backtrace/backtrace_lib.cpp index dd2d295dc30..473b227cc4a 100644 --- a/yql/essentials/utils/backtrace/backtrace_lib.cpp +++ b/yql/essentials/utils/backtrace/backtrace_lib.cpp @@ -6,74 +6,73 @@ #include <algorithm> #if defined(_linux_) && defined(_x86_64_) -#include <dlfcn.h> -#include <link.h> + #include <dlfcn.h> + #include <link.h> #endif namespace { - const size_t Limit = 400; - void* Stack[Limit]; +const size_t Limit = 400; +void* Stack[Limit]; - struct TDllInfo { - const char* Path; - ui64 BaseAddress; - }; +struct TDllInfo { + const char* Path; + ui64 BaseAddress; +}; - const size_t MaxDLLCnt = 100; - TDllInfo DLLs[MaxDLLCnt]; - size_t DLLCount = 0; +const size_t MaxDLLCnt = 100; +TDllInfo DLLs[MaxDLLCnt]; +size_t DLLCount = 0; #if defined(_linux_) && defined(_x86_64_) - int DlIterCallback(struct dl_phdr_info *info, size_t, void *data) { - if (*info->dlpi_name) { - if (DLLCount + 1 < MaxDLLCnt) { - reinterpret_cast<std::remove_reference_t<decltype(DLLs[0])>*>(data)[DLLCount++] = { info->dlpi_name, (ui64)info->dlpi_addr }; - } +int DlIterCallback(struct dl_phdr_info* info, size_t, void* data) { + if (*info->dlpi_name) { + if (DLLCount + 1 < MaxDLLCnt) { + reinterpret_cast<std::remove_reference_t<decltype(DLLs[0])>*>(data)[DLLCount++] = {info->dlpi_name, (ui64)info->dlpi_addr}; } - return 0; } + return 0; +} #endif - bool Comp(const TDllInfo& a, const TDllInfo& b) { - return strcmp(a.Path, b.Path) < 0; - } - +bool Comp(const TDllInfo& a, const TDllInfo& b) { + return strcmp(a.Path, b.Path) < 0; } +} // namespace + namespace NYql { - namespace NBacktrace { - TCollectedFrame::TCollectedFrame(uintptr_t addr) { - File = GetPersistentExecPath().c_str(); - Address = addr; +namespace NBacktrace { +TCollectedFrame::TCollectedFrame(uintptr_t addr) { + File = GetPersistentExecPath().c_str(); + Address = addr; #if defined(_linux_) && defined(_x86_64_) - Dl_info dlInfo; - memset(&dlInfo, 0, sizeof(dlInfo)); - auto ret = dladdr(reinterpret_cast<void*>(addr), &dlInfo); - if (ret) { - auto it = std::lower_bound(DLLs, DLLs + DLLCount, std::remove_reference_t<decltype(DLLs[0])> {dlInfo.dli_fname, {}}, Comp); - if (it != DLLs + DLLCount && !strcmp(it->Path, dlInfo.dli_fname)) { - File = it->Path; - Address -= it->BaseAddress; - } - } -#endif + Dl_info dlInfo; + memset(&dlInfo, 0, sizeof(dlInfo)); + auto ret = dladdr(reinterpret_cast<void*>(addr), &dlInfo); + if (ret) { + auto it = std::lower_bound(DLLs, DLLs + DLLCount, std::remove_reference_t<decltype(DLLs[0])>{dlInfo.dli_fname, {}}, Comp); + if (it != DLLs + DLLCount && !strcmp(it->Path, dlInfo.dli_fname)) { + File = it->Path; + Address -= it->BaseAddress; } + } +#endif +} - size_t CollectFrames(TCollectedFrame* frames, void* data) { +size_t CollectFrames(TCollectedFrame* frames, void* data) { #if defined(_linux_) && defined(_x86_64_) - DLLCount = 0; - dl_iterate_phdr(DlIterCallback, &DLLs); + DLLCount = 0; + dl_iterate_phdr(DlIterCallback, &DLLs); #endif - std::stable_sort(DLLs, DLLs + DLLCount, Comp); - size_t cnt = CollectBacktrace(Stack, Limit, data); - return CollectFrames(frames, Stack, cnt); - } + std::stable_sort(DLLs, DLLs + DLLCount, Comp); + size_t cnt = CollectBacktrace(Stack, Limit, data); + return CollectFrames(frames, Stack, cnt); +} - size_t CollectFrames(TCollectedFrame* frames, void** stack, size_t cnt) { - for (size_t i = 0; i < cnt; ++i) { - new (frames + i)TCollectedFrame(reinterpret_cast<uintptr_t>(stack[i])); - } - return cnt; - } +size_t CollectFrames(TCollectedFrame* frames, void** stack, size_t cnt) { + for (size_t i = 0; i < cnt; ++i) { + new (frames + i) TCollectedFrame(reinterpret_cast<uintptr_t>(stack[i])); } + return cnt; } - +} // namespace NBacktrace +} // namespace NYql |
