Fallback for to backtrace_syminfo for CPPTRACE_FULL_TRACE_WITH_LIBBACKTRACE too

This commit is contained in:
Jeremy 2023-07-02 23:19:15 -04:00
parent 4dac00a87f
commit 1a1c0d9875
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4

View File

@ -36,6 +36,11 @@ namespace cpptrace {
return 0;
}
void syminfo_callback(void* data, uintptr_t, const char* symbol, uintptr_t, uintptr_t) {
stacktrace_frame& frame = *static_cast<stacktrace_frame*>(data);
frame.symbol = symbol ? symbol : "";
}
void error_callback(void*, const char*, int) {
// nothing for now
}
@ -57,6 +62,18 @@ namespace cpptrace {
skip++; // add one for this call
trace_data data { frames, skip };
backtrace_full(get_backtrace_state(), 0, full_callback, error_callback, &data);
for(auto& frame : frames) {
if(frame.symbol.empty()) {
// fallback, try to at least recover the symbol name with backtrace_syminfo
backtrace_syminfo(
get_backtrace_state(),
reinterpret_cast<uintptr_t>(frame.address),
syminfo_callback,
error_callback,
&frame
);
}
}
return frames;
}
}