about summary refs log tree commit diff stats
path: root/src/libtools/signals.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-03-17 15:36:23 +0100
committerptitSeb <sebastien.chev@gmail.com>2025-03-17 15:36:23 +0100
commit7b065eb17a28fdf46bbdec1d6a02b6f08df0ccdf (patch)
tree66aa01fceaa896501802790a3e3ae476c3a28e54 /src/libtools/signals.c
parent7f23664566370bd040840daa83f759e0dd507b27 (diff)
downloadbox64-7b065eb17a28fdf46bbdec1d6a02b6f08df0ccdf.tar.gz
box64-7b065eb17a28fdf46bbdec1d6a02b6f08df0ccdf.zip
[TRACE] Improved native backtrace, and create a function so it can be use elsewhere
Diffstat (limited to 'src/libtools/signals.c')
-rw-r--r--src/libtools/signals.c42
1 files changed, 32 insertions, 10 deletions
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)
 {