diff --git a/src/os/unix/crashlog_unix.cpp b/src/os/unix/crashlog_unix.cpp index 44f579a257..0128d2478f 100644 --- a/src/os/unix/crashlog_unix.cpp +++ b/src/os/unix/crashlog_unix.cpp @@ -540,6 +540,32 @@ class CrashLogUnix : public CrashLog { void *func_addr = info.dli_saddr; const char *file_name = nullptr; unsigned int line_num = 0; + const int ptr_str_size = (2 + sizeof(void*) * 2); + if (dladdr_result && info.dli_fname) { + char *saved_buffer = buffer; + char addr_ptr_buffer[64]; + seprintf(addr_ptr_buffer, lastof(addr_ptr_buffer), PRINTF_SIZEX, (char *)trace[i] - (char *)info.dli_fbase); + const char *args[] = { + "addr2line", + "-e", + info.dli_fname, + "-C", + "-i", + "-f", + "-p", + addr_ptr_buffer, + nullptr, + }; + buffer += seprintf(buffer, last, " [%02i] %*p %-40s ", i, ptr_str_size, trace[i], info.dli_fname); + const char *buffer_start = buffer; + bool result = ExecReadStdout("addr2line", const_cast(args), buffer, last); + if (result && strstr(buffer_start, "??") == nullptr) { + while (buffer[-1] == '\n' && buffer[-2] == '\n') buffer--; + continue; + } + buffer = saved_buffer; + *buffer = 0; + } #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(reinterpret_cast(trace[i]) - reinterpret_cast(info.dli_fbase) - 1); @@ -552,7 +578,6 @@ class CrashLogUnix : public CrashLog { } #endif /* WITH_BFD */ bool ok = true; - const int ptr_str_size = (2 + sizeof(void*) * 2); if (dladdr_result && func_name) { int status = -1; char *demangled = nullptr;