diff --git a/be/src/common/stack_trace.cpp b/be/src/common/stack_trace.cpp index c32e2a03a1..19a585a908 100644 --- a/be/src/common/stack_trace.cpp +++ b/be/src/common/stack_trace.cpp @@ -439,7 +439,8 @@ static StackTraceCache& cacheInstance() { static std::mutex stacktrace_cache_mutex; -std::string toStringCached(const StackTrace::FramePointers& pointers, size_t offset, size_t size) { +std::string toStringCached(const StackTrace::FramePointers& pointers, size_t offset, size_t size, + const std::string& dwarf_location_info_mode) { /// Calculation of stack trace text is extremely slow. /// We use simple cache because otherwise the server could be overloaded by trash queries. /// Note that this cache can grow unconditionally, but practically it should be small. @@ -452,29 +453,32 @@ std::string toStringCached(const StackTrace::FramePointers& pointers, size_t off return it->second; } else { std::stringstream out; - toStringEveryLineImpl(doris::config::dwarf_location_info_mode, key, + toStringEveryLineImpl(dwarf_location_info_mode, key, [&](std::string_view str) { out << str << '\n'; }); return cache.emplace(StackTraceTriple {pointers, offset, size}, out.str()).first->second; } } -std::string StackTrace::toString(int start_pointers_index) const { +std::string StackTrace::toString(int start_pointers_index, + const std::string& dwarf_location_info_mode) const { // Default delete the first three frame pointers, which are inside the stack_trace.cpp. start_pointers_index += 3; StackTrace::FramePointers frame_pointers_raw {}; std::copy(frame_pointers.begin() + start_pointers_index, frame_pointers.end(), frame_pointers_raw.begin()); - return toStringCached(frame_pointers_raw, offset, size - start_pointers_index); + return toStringCached(frame_pointers_raw, offset, size - start_pointers_index, + dwarf_location_info_mode); } -std::string StackTrace::toString(void** frame_pointers_raw, size_t offset, size_t size) { +std::string StackTrace::toString(void** frame_pointers_raw, size_t offset, size_t size, + const std::string& dwarf_location_info_mode) { __msan_unpoison(frame_pointers_raw, size * sizeof(*frame_pointers_raw)); StackTrace::FramePointers frame_pointers {}; std::copy_n(frame_pointers_raw, size, frame_pointers.begin()); - return toStringCached(frame_pointers, offset, size); + return toStringCached(frame_pointers, offset, size, dwarf_location_info_mode); } void StackTrace::createCache() { diff --git a/be/src/common/stack_trace.h b/be/src/common/stack_trace.h index ed6466fd2a..1d29b935f2 100644 --- a/be/src/common/stack_trace.h +++ b/be/src/common/stack_trace.h @@ -73,9 +73,11 @@ public: [[nodiscard]] constexpr size_t getSize() const { return size; } [[nodiscard]] constexpr size_t getOffset() const { return offset; } [[nodiscard]] const FramePointers& getFramePointers() const { return frame_pointers; } - [[nodiscard]] std::string toString(int start_pointers_index = 0) const; + [[nodiscard]] std::string toString(int start_pointers_index = 0, + const std::string& dwarf_location_info_mode = "FAST") const; - static std::string toString(void** frame_pointers, size_t offset, size_t size); + static std::string toString(void** frame_pointers, size_t offset, size_t size, + const std::string& dwarf_location_info_mode = "FAST"); static void createCache(); static void dropCache(); static void symbolize(const FramePointers& frame_pointers, size_t offset, size_t size, diff --git a/be/src/util/stack_util.cpp b/be/src/util/stack_util.cpp index ef21f3f010..5dfde1bd45 100644 --- a/be/src/util/stack_util.cpp +++ b/be/src/util/stack_util.cpp @@ -35,8 +35,11 @@ void DumpStackTraceToString(std::string* stacktrace); namespace doris { -std::string get_stack_trace(int start_pointers_index) { +std::string get_stack_trace(int start_pointers_index, std::string dwarf_location_info_mode) { #ifdef ENABLE_STACKTRACE + if (dwarf_location_info_mode.empty()) { + dwarf_location_info_mode = config::dwarf_location_info_mode; + } auto tool = config::get_stack_trace_tool; if (tool == "glog") { return get_stack_trace_by_glog(); @@ -48,7 +51,7 @@ std::string get_stack_trace(int start_pointers_index) { #if defined(__APPLE__) // TODO return get_stack_trace_by_glog(); #endif - return get_stack_trace_by_libunwind(start_pointers_index); + return get_stack_trace_by_libunwind(start_pointers_index, dwarf_location_info_mode); } else { return "no stack"; } @@ -80,8 +83,9 @@ std::string get_stack_trace_by_glibc() { return out.str(); } -std::string get_stack_trace_by_libunwind(int start_pointers_index) { - return "\n" + StackTrace().toString(start_pointers_index); +std::string get_stack_trace_by_libunwind(int start_pointers_index, + const std::string& dwarf_location_info_mode) { + return "\n" + StackTrace().toString(start_pointers_index, dwarf_location_info_mode); } } // namespace doris diff --git a/be/src/util/stack_util.h b/be/src/util/stack_util.h index 65b2d8bad2..3f406da707 100644 --- a/be/src/util/stack_util.h +++ b/be/src/util/stack_util.h @@ -29,7 +29,8 @@ namespace doris { // boost: 1000 times cost 1min, has line numbers, but has memory leak. // glibc: 1000 times cost 1min, no line numbers, unresolved backtrace symbol. // libunwind: cost is negligible, has line numbers. -std::string get_stack_trace(int start_pointers_index = 0); +std::string get_stack_trace(int start_pointers_index = 0, + std::string dwarf_location_info_mode = ""); // Note: there is a libc bug that causes this not to work on 64 bit machines // for recursive calls. @@ -53,6 +54,7 @@ std::string get_stack_trace_by_glibc(); // 2. Support signal handle // 3. libunwid support unw_backtrace for jemalloc // 4. Use of undefined compile option USE_MUSL for later -std::string get_stack_trace_by_libunwind(int start_pointers_index); +std::string get_stack_trace_by_libunwind(int start_pointers_index, + const std::string& dwarf_location_info_mode); } // namespace doris