[fix](stacktrace) Fix dwarf_location_info_mode is passed as parameter to stack trace (#33863)
dwarf_location_info_mode is passed as parameter to stack trace
This commit is contained in:
@ -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() {
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user