- Timestamp:
- Sep 14, 2015 7:35:38 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/main.cpp
r57748 r57750 115 115 116 116 #if defined(DEBUG) && defined(Q_WS_X11) && defined(RT_OS_LINUX) 117 118 117 #include <signal.h> 119 118 #include <execinfo.h> 120 121 119 /* get REG_EIP from ucontext.h */ 122 120 #ifndef __USE_GNU … … 130 128 #endif 131 129 132 133 134 /** 135 * the signal handler that prints out a backtrace of the call stack. 136 * the code is taken from http://www.linuxjournal.com/article/6391. 137 */ 138 void bt_sighandler (int sig, siginfo_t *info, void *secret) { 139 130 /** X11, Linux, Debug: The signal handler that prints out a backtrace of the call stack. 131 * @remarks The code is taken from http://www.linuxjournal.com/article/6391. */ 132 static void BackTraceSignalHandler(int sig, siginfo_t *pInfo, void *pSecret) 133 { 140 134 void *trace[16]; 141 char **messages = (char **) NULL;142 int i, trace_size = 0;143 ucontext_t *uc = (ucontext_t *) secret;144 145 /* Do something useful with siginfo_t */135 char **messages = (char **)0; 136 int i, iTraceSize = 0; 137 ucontext_t *uc = (ucontext_t *)pSecret; 138 139 /* Do something useful with siginfo_t: */ 146 140 if (sig == SIGSEGV) 147 Log (("GUI: Got signal %d, faulty address is %p, from %p\n", 148 sig, info->si_addr, uc->uc_mcontext.gregs[REG_PC])); 141 Log(("GUI: Got signal %d, faulty address is %p, from %p\n", 142 sig, pInfo->si_addr, uc->uc_mcontext.gregs[REG_PC])); 143 /* Or do nothing by default: */ 149 144 else 150 Log (("GUI: Got signal %d\n", sig)); 151 152 trace_size = backtrace (trace, 16); 153 /* overwrite sigaction with caller's address */ 154 trace[1] = (void *) uc->uc_mcontext.gregs [REG_PC]; 155 156 messages = backtrace_symbols (trace, trace_size); 157 /* skip first stack frame (points here) */ 158 Log (("GUI: [bt] Execution path:\n")); 159 for (i = 1; i < trace_size; ++i) 160 Log (("GUI: [bt] %s\n", messages[i])); 161 162 exit (0); 163 } 164 165 #endif /* DEBUG && X11 && LINUX*/ 145 Log(("GUI: Got signal %d\n", sig)); 146 147 /* Acquire backtrace of 16 lvls depth: */ 148 iTraceSize = backtrace(trace, 16); 149 150 /* Overwrite sigaction with caller's address: */ 151 trace[1] = (void *)uc->uc_mcontext.gregs[REG_PC]; 152 153 /* Translate the addresses into an array of messages: */ 154 messages = backtrace_symbols(trace, iTraceSize); 155 156 /* Skip first stack frame (points here): */ 157 Log(("GUI: [bt] Execution path:\n")); 158 for (i = 1; i < iTraceSize; ++i) 159 Log(("GUI: [bt] %s\n", messages[i])); 160 161 exit(0); 162 } 163 164 /** X11, Linux, Debug: Installs signal handler printing backtrace of the call stack. */ 165 static void InstallSignalHandler() 166 { 167 struct sigaction sa; 168 sa.sa_sigaction = BackTraceSignalHandler; 169 sigemptyset(&sa.sa_mask); 170 sa.sa_flags = SA_RESTART | SA_SIGINFO; 171 sigaction(SIGSEGV, &sa, 0); 172 sigaction(SIGBUS, &sa, 0); 173 sigaction(SIGUSR1, &sa, 0); 174 } 175 #endif /* DEBUG && Q_WS_X11 && RT_OS_LINUX */ 166 176 167 177 #ifdef Q_WS_MAC … … 344 354 345 355 #if defined(DEBUG) && defined(Q_WS_X11) && defined(RT_OS_LINUX) 346 /* Install our signal handler to backtrace the call stack: */ 347 struct sigaction sa; 348 sa.sa_sigaction = bt_sighandler; 349 sigemptyset(&sa.sa_mask); 350 sa.sa_flags = SA_RESTART | SA_SIGINFO; 351 sigaction(SIGSEGV, &sa, NULL); 352 sigaction(SIGBUS, &sa, NULL); 353 sigaction(SIGUSR1, &sa, NULL); 354 #endif 356 /* Install signal handler to backtrace the call stack: */ 357 InstallSignalHandler(); 358 #endif /* DEBUG && Q_WS_X11 && RT_OS_LINUX */ 355 359 356 360 #ifdef VBOX_WITH_HARDENING
Note:
See TracChangeset
for help on using the changeset viewer.