mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-03 01:19:38 +01:00
Alter linux debug stacktraces handling to support more environments
- Use -gdwarf-4 to support both LLVM and GCC when calling addr2line - Subtract position-independant execuable relocation when passing the address to addr2line (cherry picked from commit 5e041eee11e611bc2c89dd54b1dad28d0660f335)
This commit is contained in:
parent
9a1705eac2
commit
2bac27b711
@ -51,7 +51,6 @@ def get_flags():
|
|||||||
|
|
||||||
|
|
||||||
def configure(env):
|
def configure(env):
|
||||||
|
|
||||||
## Build type
|
## Build type
|
||||||
|
|
||||||
if env["target"] == "release":
|
if env["target"] == "release":
|
||||||
@ -76,6 +75,11 @@ def configure(env):
|
|||||||
env.Prepend(CCFLAGS=["-g3"])
|
env.Prepend(CCFLAGS=["-g3"])
|
||||||
env.Append(LINKFLAGS=["-rdynamic"])
|
env.Append(LINKFLAGS=["-rdynamic"])
|
||||||
|
|
||||||
|
if env["debug_symbols"]:
|
||||||
|
# Adding dwarf-4 explicitly makes stacktraces work with clang builds,
|
||||||
|
# otherwise addr2line doesn't understand them
|
||||||
|
env.Append(CCFLAGS=["-gdwarf-4"])
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
is64 = sys.maxsize > 2 ** 32
|
is64 = sys.maxsize > 2 ** 32
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
#include <link.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -79,7 +80,27 @@ static void handle_crash(int sig) {
|
|||||||
}
|
}
|
||||||
print_error(vformat("Dumping the backtrace. %s", msg));
|
print_error(vformat("Dumping the backtrace. %s", msg));
|
||||||
char **strings = backtrace_symbols(bt_buffer, size);
|
char **strings = backtrace_symbols(bt_buffer, size);
|
||||||
|
// PIE executable relocation, zero for non-PIE executables
|
||||||
|
uintptr_t relocation = _r_debug.r_map->l_addr;
|
||||||
if (strings) {
|
if (strings) {
|
||||||
|
List<String> args;
|
||||||
|
for (size_t i = 0; i < size; i++) {
|
||||||
|
char str[1024];
|
||||||
|
snprintf(str, 1024, "%p", (void *)((uintptr_t)bt_buffer[i] - relocation));
|
||||||
|
args.push_back(str);
|
||||||
|
}
|
||||||
|
args.push_back("-e");
|
||||||
|
args.push_back(_execpath);
|
||||||
|
|
||||||
|
// Try to get the file/line number using addr2line
|
||||||
|
int ret;
|
||||||
|
String output = "";
|
||||||
|
Error err = OS::get_singleton()->execute(String("addr2line"), args, true, nullptr, &output, &ret);
|
||||||
|
Vector<String> addr2line_results;
|
||||||
|
if (err == OK) {
|
||||||
|
addr2line_results = output.substr(0, output.length() - 1).split("\n", false);
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 1; i < size; i++) {
|
for (size_t i = 1; i < size; i++) {
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
Dl_info info;
|
Dl_info info;
|
||||||
@ -102,24 +123,7 @@ static void handle_crash(int sig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> args;
|
print_error(vformat("[%d] %s (%s)", (int64_t)i, fname, err == OK ? addr2line_results[i] : ""));
|
||||||
|
|
||||||
char str[1024];
|
|
||||||
snprintf(str, 1024, "%p", bt_buffer[i]);
|
|
||||||
args.push_back(str);
|
|
||||||
args.push_back("-e");
|
|
||||||
args.push_back(_execpath);
|
|
||||||
|
|
||||||
String output = "";
|
|
||||||
|
|
||||||
// Try to get the file/line number using addr2line
|
|
||||||
int ret;
|
|
||||||
Error err = OS::get_singleton()->execute(String("addr2line"), args, true, nullptr, &output, &ret);
|
|
||||||
if (err == OK) {
|
|
||||||
output.erase(output.length() - 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
print_error(vformat("[%d] %s (%s)", (int64_t)i, fname, output));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(strings);
|
free(strings);
|
||||||
|
@ -111,6 +111,11 @@ def configure(env):
|
|||||||
env.Prepend(CCFLAGS=["-g3"])
|
env.Prepend(CCFLAGS=["-g3"])
|
||||||
env.Append(LINKFLAGS=["-rdynamic"])
|
env.Append(LINKFLAGS=["-rdynamic"])
|
||||||
|
|
||||||
|
if env["debug_symbols"]:
|
||||||
|
# Adding dwarf-4 explicitly makes stacktraces work with clang builds,
|
||||||
|
# otherwise addr2line doesn't understand them
|
||||||
|
env.Append(CCFLAGS=["-gdwarf-4"])
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
is64 = sys.maxsize > 2**32
|
is64 = sys.maxsize > 2**32
|
||||||
|
Loading…
Reference in New Issue
Block a user