Added BOX86_BACKTRACE option to try show some backtrace on segfault

This commit is contained in:
ptitSeb 2022-07-15 18:18:39 +02:00
parent 2ff0562a82
commit 7389dc616b
4 changed files with 40 additions and 0 deletions

View File

@ -199,6 +199,16 @@ Fix/Don't fix 64bit inodes
* 0 : Don't fix 64bit inodes. (Default.)
* 1 : Fix 64bit inodes. Helps when running on Filesystems with 64bit inodes. Is useful when a program uses API functions which doesn't support it and the program doesn't use inodes information.
#### BOX86_SHOWSEGV
Show Segfault signal even if a signal handler is present
* 0 : Don't force segfault details when a signal handler is install (Default, to limit message spamming)
* 1 : Show segfault details
#### BOX86_BACKTRACE
Show a backtrace (native and emulated) on Signal
* 0 : Don't show any backtrace (Default.)
* 1 : Show native backtrace when a signal is dumped
#### BOX86_JITGDB
* 0 : Just print the Segfault message on segfault (default)

View File

@ -9,6 +9,7 @@ extern int box86_dynarec_log;
extern int box86_dynarec;
extern int box86_pagesize;
extern uintptr_t box86_load_addr;
extern int box86_backtrace;
#ifdef DYNAREC
extern int box86_dynarec_dump;
extern int box86_dynarec_trace;
@ -68,4 +69,9 @@ extern FILE* ftrace;
#define EXPORTDYN
#endif
extern void* __libc_malloc(size_t);
extern void* __libc_realloc(size_t, void*);
extern void* __libc_calloc(size_t, size_t);
extern void __libc_free(void*);
#endif //__DEBUG_H_

View File

@ -11,6 +11,7 @@
#include <ucontext.h>
#include <setjmp.h>
#include <sys/mman.h>
#include <execinfo.h>
#include "box86context.h"
#include "debug.h"
@ -871,6 +872,19 @@ exit(-1);
printf_log(log_minimum, " x86opcode=%02X %02X %02X %02X %02X %02X %02X %02X\n", ((uint8_t*)x86pc)[0], ((uint8_t*)x86pc)[1], ((uint8_t*)x86pc)[2], ((uint8_t*)x86pc)[3], ((uint8_t*)x86pc)[4], ((uint8_t*)x86pc)[5], ((uint8_t*)x86pc)[6], ((uint8_t*)x86pc)[7]);
else
printf_log(log_minimum, "\n");
if(box86_backtrace && (log_minimum<=box86_log)) {
int nptrs;
void *buffer[200];
char **strings;
printf_log(LOG_NONE, "Native bactrace:\n");
nptrs = backtrace(buffer, 200);
strings = backtrace_symbols(buffer, nptrs);
for(int j=0; j<nptrs; j++)
printf_log(LOG_NONE, "\t%s\n", strings[j]);
free(strings);
}
}
#if 1
if(sig==SIGSEGV && (info->si_code==2 && ((prot&~PROT_DYNAREC)==7 || (prot&~PROT_DYNAREC)==5))) {

View File

@ -49,6 +49,7 @@ int box86_nobanner = 0;
int box86_dynarec_log = LOG_NONE;
int box86_pagesize;
uintptr_t box86_load_addr = 0;
int box86_backtrace = 0;
#ifdef DYNAREC
int box86_dynarec = 1;
int box86_dynarec_dump = 0;
@ -528,6 +529,15 @@ void LoadLogEnv()
if(box86_showsegv)
printf_log(LOG_INFO, "Show Segfault signal even if a signal handler is present\n");
}
p = getenv("BOX86_BACKTRACE");
if(p) {
if(strlen(p)==1) {
if(p[0]>='0' && p[0]<='0'+1)
box86_backtrace = p[0]-'0';
}
if(box86_backtrace)
printf_log(LOG_INFO, "Show Backtrace for signals\n");
}
box86_pagesize = sysconf(_SC_PAGESIZE);
if(!box86_pagesize)
box86_pagesize = 4096;