From 8fe002819e4b528a91e2322ac783dd8a7f660b07 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Wed, 4 Mar 2026 13:21:20 +0100 Subject: [PATCH] [Linux] Improve crash trace symbols Uses `addr2line` to also demangle symbols when available. --- platform/linuxbsd/crash_handler_linuxbsd.cpp | 47 +++++++++++--------- platform/linuxbsd/detect.py | 5 --- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/platform/linuxbsd/crash_handler_linuxbsd.cpp b/platform/linuxbsd/crash_handler_linuxbsd.cpp index ca7969ae38..a7a13ab67d 100644 --- a/platform/linuxbsd/crash_handler_linuxbsd.cpp +++ b/platform/linuxbsd/crash_handler_linuxbsd.cpp @@ -141,39 +141,46 @@ static void handle_crash(int sig) { } args.push_back("-e"); args.push_back(_execpath); + args.push_back("-f"); + args.push_back("-p"); + args.push_back("-C"); // Try to get the file/line number using addr2line String output; Error err = OS::get_singleton()->execute(exe_name, args, &output, &ret); - Vector addr2line_results; if (err == OK) { - addr2line_results = output.substr(0, output.length() - 1).split("\n", false); - } + Vector addr2line_results = output.substr(0, output.length() - 1).split("\n", false); - for (size_t i = 1; i < size; i++) { - char fname[1024]; - Dl_info info; + for (size_t i = 1; i < size; i++) { + // Simplify printed file paths to remove redundant `/./` sections (e.g. `/opt/godot/./core` -> `/opt/godot/core`). + print_error(vformat("[%d] %x - %s", (int64_t)i, (uint64_t)bt_buffer[i], addr2line_results[i].replace("/./", "/"))); + } + } else { + // Otherwise fall back to trace symbols. + for (size_t i = 1; i < size; i++) { + char fname[1024]; + Dl_info info; - snprintf(fname, 1024, "%s", strings[i]); + snprintf(fname, 1024, "%s", strings[i]); - // Try to demangle the function name to provide a more readable one - if (dladdr(bt_buffer[i], &info) && info.dli_sname) { - if (info.dli_sname[0] == '_') { - int status = 0; - char *demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status); + // Try to demangle the function name to provide a more readable one. + if (dladdr(bt_buffer[i], &info) && info.dli_sname) { + if (info.dli_sname[0] == '_') { + int status = 0; + char *demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status); - if (status == 0 && demangled) { - snprintf(fname, 1024, "%s", demangled); - } + if (status == 0 && demangled) { + snprintf(fname, 1024, "%s", demangled); + } - if (demangled) { - free(demangled); + if (demangled) { + free(demangled); + } } } - } - // Simplify printed file paths to remove redundant `/./` sections (e.g. `/opt/godot/./core` -> `/opt/godot/core`). - print_error(vformat("[%d] %x - %s (%s)", (int64_t)i, (uint64_t)bt_buffer[i], fname, err == OK ? addr2line_results[i].replace("/./", "/") : "")); + print_error(vformat("[%d] %x - %s", (int64_t)i, (uint64_t)bt_buffer[i], fname)); + } } free(strings); diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py index dc843efc3a..456e71950e 100644 --- a/platform/linuxbsd/detect.py +++ b/platform/linuxbsd/detect.py @@ -100,11 +100,6 @@ def configure(env: "SConsEnvironment"): ## Build type - if env.dev_build: - # This is needed for our crash handler to work properly. - # gdb works fine without it though, so maybe our crash handler could too. - env.Append(LINKFLAGS=["-rdynamic"]) - # Cross-compilation # TODO: Support cross-compilation on architectures other than x86. host_is_64_bit = sys.maxsize > 2**32