diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2025-03-17 15:36:23 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2025-03-17 15:36:23 +0100 |
| commit | 7b065eb17a28fdf46bbdec1d6a02b6f08df0ccdf (patch) | |
| tree | 66aa01fceaa896501802790a3e3ae476c3a28e54 | |
| parent | 7f23664566370bd040840daa83f759e0dd507b27 (diff) | |
| download | box64-7b065eb17a28fdf46bbdec1d6a02b6f08df0ccdf.tar.gz box64-7b065eb17a28fdf46bbdec1d6a02b6f08df0ccdf.zip | |
[TRACE] Improved native backtrace, and create a function so it can be use elsewhere
| -rw-r--r-- | src/include/signals.h | 2 | ||||
| -rw-r--r-- | src/libtools/signals.c | 42 |
2 files changed, 34 insertions, 10 deletions
diff --git a/src/include/signals.h b/src/include/signals.h index 2fae6c60..df295dea 100644 --- a/src/include/signals.h +++ b/src/include/signals.h @@ -76,4 +76,6 @@ void emit_interruption(x64emu_t* emu, int num, void* addr); void emit_div0(x64emu_t* emu, void* addr, int code); void check_exec(x64emu_t* emu, uintptr_t addr); +void showNativeBT(int log_minimum); + #endif //__SIGNALS_H__ diff --git a/src/libtools/signals.c b/src/libtools/signals.c index 9b5cee6b..0abea7ee 100644 --- a/src/libtools/signals.c +++ b/src/libtools/signals.c @@ -1889,21 +1889,13 @@ dynarec_log(/*LOG_DEBUG*/LOG_INFO, "%04d|Repeated SIGSEGV with Access error on % if((BOX64ENV(showbt) || sig==SIGABRT) && log_minimum<=BOX64ENV(log)) { // show native bt + showNativeBT(log_minimum); + #define BT_BUF_SIZE 100 int nptrs; void *buffer[BT_BUF_SIZE]; char **strings; -#ifndef ANDROID - nptrs = backtrace(buffer, BT_BUF_SIZE); - strings = backtrace_symbols(buffer, nptrs); - if(strings) { - for (int j = 0; j < nptrs; j++) - printf_log(log_minimum, "NativeBT: %s\n", strings[j]); - free(strings); - } else - printf_log(log_minimum, "NativeBT: none (%d/%s)\n", errno, strerror(errno)); -#endif extern int my_backtrace_ip(x64emu_t* emu, void** buffer, int size); // in wrappedlibc extern char** my_backtrace_symbols(x64emu_t* emu, uintptr_t* buffer, int size); // save and set real RIP/RSP @@ -2590,6 +2582,36 @@ EXPORT int my_swapcontext(x64emu_t* emu, void* ucp1, void* ucp2) my_setcontext(emu, ucp2); return 0; } + +void showNativeBT(int log_minimum) +{ +#ifndef ANDROID + // grab current name + // and temporarily rename binary to original box64 + // to get exact backtrace + size_t boxpath_lenth = strlen(my_context->box64path)+1; + char current_name[boxpath_lenth]; + memcpy(current_name, my_context->orig_argv[0], boxpath_lenth); + memcpy(my_context->orig_argv[0], my_context->box64path, boxpath_lenth); + // show native bt + #define BT_BUF_SIZE 100 + int nptrs; + void *buffer[BT_BUF_SIZE]; + char **strings; + + nptrs = backtrace(buffer, BT_BUF_SIZE); + strings = backtrace_symbols(buffer, nptrs); + if(strings) { + for (int j = 0; j < nptrs; j++) + printf_log(log_minimum, "NativeBT: %s\n", strings[j]); + free(strings); + } else + printf_log(log_minimum, "NativeBT: none (%d/%s)\n", errno, strerror(errno)); + // restore modified name + memcpy(my_context->box64path, my_context->orig_argv[0], boxpath_lenth); +#endif +} + #ifdef USE_SIGNAL_MUTEX static void atfork_child_dynarec_prot(void) { |