Crashlog: Re-use BFD instances for the same object

This commit is contained in:
Jonathan G Rennison
2024-02-02 20:06:44 +00:00
parent fcc6529b6a
commit a4c14171a7
4 changed files with 51 additions and 17 deletions

View File

@@ -521,6 +521,7 @@ class CrashLogUnix : public CrashLog {
char **messages = backtrace_symbols(trace, trace_size);
#if defined(WITH_BFD)
sym_bfd_obj_cache bfd_cache;
bfd_init();
#endif /* WITH_BFD */
@@ -574,7 +575,7 @@ class CrashLogUnix : public CrashLog {
/* subtract one to get the line before the return address, i.e. the function call line */
sym_info_bfd bfd_info(reinterpret_cast<bfd_vma>(trace[i]) - reinterpret_cast<bfd_vma>(info.dli_fbase) - 1);
if (dladdr_result && info.dli_fname) {
lookup_addr_bfd(info.dli_fname, bfd_info);
lookup_addr_bfd(info.dli_fname, bfd_cache, bfd_info);
if (bfd_info.file_name != nullptr) file_name = bfd_info.file_name;
if (bfd_info.function_name != nullptr) func_name = bfd_info.function_name;
if (bfd_info.function_addr != 0) func_addr = reinterpret_cast<void *>(bfd_info.function_addr + reinterpret_cast<bfd_vma>(info.dli_fbase));

View File

@@ -399,6 +399,11 @@ static const uint MAX_FRAMES = 64;
std::array<DWORD64, 8> last_offsets = {};
#if defined(WITH_BFD)
sym_bfd_obj_cache bfd_cache;
bfd_init();
#endif /* WITH_BFD */
/* Walk stack at most MAX_FRAMES deep in case the stack is corrupt. */
for (uint num = 0; num < MAX_FRAMES; num++) {
auto guard = scope_guard([&]() {
@@ -448,7 +453,7 @@ static const uint MAX_FRAMES = 64;
#if defined (WITH_BFD)
/* subtract one to get the line before the return address, i.e. the function call line */
sym_info_bfd bfd_info(static_cast<bfd_vma>(frame.AddrPC.Offset) - 1);
lookup_addr_bfd(image_name, bfd_info);
lookup_addr_bfd(image_name, bfd_cache, bfd_info);
if (bfd_info.function_name != nullptr) {
const char *func_name = bfd_info.function_name;
#if defined(WITH_DEMANGLE)