about summary refs log tree commit diff stats
path: root/src/libtools
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-10-27 18:42:07 +0200
committerptitSeb <sebastien.chev@gmail.com>2022-10-27 18:42:07 +0200
commitcfeb0626ccc6f335d95089bf6c4f7baecdce9c8a (patch)
tree27bb96cf9e28c9fb26749f7ae132925338565d66 /src/libtools
parent3f2c4ed7943ac0985608e332948b40d873cc741c (diff)
downloadbox64-cfeb0626ccc6f335d95089bf6c4f7baecdce9c8a.tar.gz
box64-cfeb0626ccc6f335d95089bf6c4f7baecdce9c8a.zip
Added BOX64_SHOWBT env. var. to have a backtrace on segfault
Diffstat (limited to 'src/libtools')
-rwxr-xr-xsrc/libtools/signals.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libtools/signals.c b/src/libtools/signals.c
index 6dcfb8b0..dfc351d6 100755
--- a/src/libtools/signals.c
+++ b/src/libtools/signals.c
@@ -12,6 +12,7 @@
 #include <setjmp.h>
 #include <sys/mman.h>
 #include <pthread.h>
+#include <execinfo.h>
 
 #include "box64context.h"
 #include "debug.h"
@@ -1007,6 +1008,29 @@ exit(-1);
                 }
             }
         }
+        if(box64_showbt) {
+            // 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);
+            }
+            extern int my_backtrace(x64emu_t* emu, void** buffer, int size);   // in wrappedlibc
+            extern char** my_backtrace_symbols(x64emu_t* emu, uintptr_t* buffer, int size);
+            nptrs = my_backtrace(emu, buffer, BT_BUF_SIZE);
+            strings = my_backtrace_symbols(emu, (uintptr_t*)buffer, nptrs);
+            if(strings) {
+                for (int j = 0; j < nptrs; j++)
+                    printf_log(log_minimum, "EmulatedBT: %s\n", strings[j]);
+                free(strings);
+            }
+        }
 #ifdef DYNAREC
         uint32_t hash = 0;
         if(db)