mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-09 19:10:38 +00:00
Unix: Try using addr2line for crash log backtrace symbol resolution
This commit is contained in:
parent
e3896b69d3
commit
0811990d4a
@ -540,6 +540,32 @@ class CrashLogUnix : public CrashLog {
|
|||||||
void *func_addr = info.dli_saddr;
|
void *func_addr = info.dli_saddr;
|
||||||
const char *file_name = nullptr;
|
const char *file_name = nullptr;
|
||||||
unsigned int line_num = 0;
|
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<char* const*>(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)
|
#if defined(WITH_BFD)
|
||||||
/* subtract one to get the line before the return address, i.e. the function call line */
|
/* 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);
|
sym_info_bfd bfd_info(reinterpret_cast<bfd_vma>(trace[i]) - reinterpret_cast<bfd_vma>(info.dli_fbase) - 1);
|
||||||
@ -552,7 +578,6 @@ class CrashLogUnix : public CrashLog {
|
|||||||
}
|
}
|
||||||
#endif /* WITH_BFD */
|
#endif /* WITH_BFD */
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
const int ptr_str_size = (2 + sizeof(void*) * 2);
|
|
||||||
if (dladdr_result && func_name) {
|
if (dladdr_result && func_name) {
|
||||||
int status = -1;
|
int status = -1;
|
||||||
char *demangled = nullptr;
|
char *demangled = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user