diff --git a/source/loader/layers/sanitizer/common.hpp b/source/loader/layers/sanitizer/common.hpp index 2b6a7c22c3..90402b9429 100644 --- a/source/loader/layers/sanitizer/common.hpp +++ b/source/loader/layers/sanitizer/common.hpp @@ -127,6 +127,7 @@ inline uint64_t GetSizeAndRedzoneSizeForLocal(uint64_t Size, return Result; \ } +using BacktraceFrame = void *; using BacktraceInfo = std::string; struct SourceInfo { diff --git a/source/loader/layers/sanitizer/linux/backtrace.cpp b/source/loader/layers/sanitizer/linux/backtrace.cpp index b336dc3675..5975515678 100644 --- a/source/loader/layers/sanitizer/linux/backtrace.cpp +++ b/source/loader/layers/sanitizer/linux/backtrace.cpp @@ -17,20 +17,20 @@ namespace ur_sanitizer_layer { StackTrace GetCurrentBacktrace() { void *Frames[MAX_BACKTRACE_FRAMES]; int FrameCount = backtrace(Frames, MAX_BACKTRACE_FRAMES); - char **Symbols = backtrace_symbols(Frames, FrameCount); - - if (Symbols == nullptr) { - return StackTrace(); - } StackTrace Stack; - for (int i = 0; i < FrameCount; i++) { - BacktraceInfo addr_info(Symbols[i]); - Stack.stack.emplace_back(addr_info); - } - free(Symbols); + Stack.stack = + std::vector(&Frames[0], &Frames[FrameCount - 1]); return Stack; } +char **GetBacktraceSymbols(const std::vector &BacktraceFrames) { + assert(!BacktraceFrames.empty()); + + char **BacktraceSymbols = + backtrace_symbols(&BacktraceFrames[0], BacktraceFrames.size()); + return BacktraceSymbols; +} + } // namespace ur_sanitizer_layer diff --git a/source/loader/layers/sanitizer/stacktrace.cpp b/source/loader/layers/sanitizer/stacktrace.cpp index 38bef94811..8adaa2cd34 100644 --- a/source/loader/layers/sanitizer/stacktrace.cpp +++ b/source/loader/layers/sanitizer/stacktrace.cpp @@ -86,7 +86,11 @@ void StackTrace::print() const { unsigned index = 0; - for (auto &BI : stack) { + char **BacktraceSymbols = GetBacktraceSymbols(stack); + + for (size_t i = 0; i < stack.size(); i++) { + BacktraceInfo BI = BacktraceSymbols[i]; + // Skip runtime modules if (Contains(BI, "libsycl.so") || Contains(BI, "libpi_unified_runtime.so") || @@ -123,6 +127,8 @@ void StackTrace::print() const { ++index; } getContext()->logger.always(""); + + free(BacktraceSymbols); } } // namespace ur_sanitizer_layer diff --git a/source/loader/layers/sanitizer/stacktrace.hpp b/source/loader/layers/sanitizer/stacktrace.hpp index 31b661cc7d..a98c310473 100644 --- a/source/loader/layers/sanitizer/stacktrace.hpp +++ b/source/loader/layers/sanitizer/stacktrace.hpp @@ -18,14 +18,16 @@ namespace ur_sanitizer_layer { -constexpr size_t MAX_BACKTRACE_FRAMES = 64; +constexpr size_t MAX_BACKTRACE_FRAMES = 48; struct StackTrace { - std::vector stack; + std::vector stack; void print() const; }; StackTrace GetCurrentBacktrace(); +char **GetBacktraceSymbols(const std::vector &BacktraceFrames); + } // namespace ur_sanitizer_layer