- Timestamp:
- Sep 15, 2015 3:15:27 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/main.cpp
r57764 r57765 132 132 133 133 134 #if defined(DEBUG) && defined(Q_WS_X11) && defined(RT_OS_LINUX)135 /** X11, Linux, Debug: The signal handler that prints out a backtrace of the call stack.136 * @remarks The code is taken from http://www.linuxjournal.com/article/6391. */137 static void BackTraceSignalHandler(int sig, siginfo_t *pInfo, void *pSecret)138 {139 void *trace[16];140 char **messages = (char **)0;141 int i, iTraceSize = 0;142 ucontext_t *uc = (ucontext_t *)pSecret;143 144 /* Do something useful with siginfo_t: */145 if (sig == SIGSEGV)146 Log(("GUI: Got signal %d, faulty address is %p, from %p\n",147 sig, pInfo->si_addr, uc->uc_mcontext.gregs[REG_PC]));148 /* Or do nothing by default: */149 else150 Log(("GUI: Got signal %d\n", sig));151 152 /* Acquire backtrace of 16 lvls depth: */153 iTraceSize = backtrace(trace, 16);154 155 /* Overwrite sigaction with caller's address: */156 trace[1] = (void *)uc->uc_mcontext.gregs[REG_PC];157 158 /* Translate the addresses into an array of messages: */159 messages = backtrace_symbols(trace, iTraceSize);160 161 /* Skip first stack frame (points here): */162 Log(("GUI: [bt] Execution path:\n"));163 for (i = 1; i < iTraceSize; ++i)164 Log(("GUI: [bt] %s\n", messages[i]));165 166 exit(0);167 }168 169 /** X11, Linux, Debug: Installs signal handler printing backtrace of the call stack. */170 static void InstallSignalHandler()171 {172 struct sigaction sa;173 sa.sa_sigaction = BackTraceSignalHandler;174 sigemptyset(&sa.sa_mask);175 sa.sa_flags = SA_RESTART | SA_SIGINFO;176 sigaction(SIGSEGV, &sa, 0);177 sigaction(SIGBUS, &sa, 0);178 sigaction(SIGUSR1, &sa, 0);179 }180 #endif /* DEBUG && Q_WS_X11 && RT_OS_LINUX */181 182 134 #ifdef Q_WS_MAC 183 135 /** Mac OS X: Really ugly hack to prevent silly check in AppKit. */ … … 197 149 } 198 150 #endif /* Q_WS_MAC */ 151 152 #ifdef Q_WS_X11 153 /** X11: For versions of Xlib which are aware of multi-threaded environments this function 154 * calls for XInitThreads() which initializes Xlib support for concurrent threads. 155 * @returns @c non-zero unless it is unsafe to make multi-threaded calls to Xlib. 156 * @remarks This is a workaround for a bug on old Xlib versions, fixed in commit 157 * 941f02e and released in Xlib version 1.1. We check for the symbol 158 * "xcb_connect" which was introduced in that version. */ 159 static Status MakeSureMultiThreadingIsSafe() 160 { 161 /* Success by default: */ 162 Status rc = 1; 163 /* Get a global handle to process symbols: */ 164 void *pvProcess = dlopen(0, RTLD_GLOBAL | RTLD_LAZY); 165 /* Initialize multi-thread environment only if we can obtain 166 * an address of xcb_connect symbol in this process: */ 167 if (pvProcess && dlsym(pvProcess, "xcb_connect")) 168 rc = XInitThreads(); 169 /* Close the handle: */ 170 if (pvProcess) 171 dlclose(pvProcess); 172 /* Return result: */ 173 return rc; 174 } 175 176 # if defined(RT_OS_LINUX) && defined(DEBUG) 177 /** X11, Linux, Debug: The signal handler that prints out a backtrace of the call stack. 178 * @remarks The code is taken from http://www.linuxjournal.com/article/6391. */ 179 static void BackTraceSignalHandler(int sig, siginfo_t *pInfo, void *pSecret) 180 { 181 void *trace[16]; 182 char **messages = (char **)0; 183 int i, iTraceSize = 0; 184 ucontext_t *uc = (ucontext_t *)pSecret; 185 186 /* Do something useful with siginfo_t: */ 187 if (sig == SIGSEGV) 188 Log(("GUI: Got signal %d, faulty address is %p, from %p\n", 189 sig, pInfo->si_addr, uc->uc_mcontext.gregs[REG_PC])); 190 /* Or do nothing by default: */ 191 else 192 Log(("GUI: Got signal %d\n", sig)); 193 194 /* Acquire backtrace of 16 lvls depth: */ 195 iTraceSize = backtrace(trace, 16); 196 197 /* Overwrite sigaction with caller's address: */ 198 trace[1] = (void *)uc->uc_mcontext.gregs[REG_PC]; 199 200 /* Translate the addresses into an array of messages: */ 201 messages = backtrace_symbols(trace, iTraceSize); 202 203 /* Skip first stack frame (points here): */ 204 Log(("GUI: [bt] Execution path:\n")); 205 for (i = 1; i < iTraceSize; ++i) 206 Log(("GUI: [bt] %s\n", messages[i])); 207 208 exit(0); 209 } 210 211 /** X11, Linux, Debug: Installs signal handler printing backtrace of the call stack. */ 212 static void InstallSignalHandler() 213 { 214 struct sigaction sa; 215 sa.sa_sigaction = BackTraceSignalHandler; 216 sigemptyset(&sa.sa_mask); 217 sa.sa_flags = SA_RESTART | SA_SIGINFO; 218 sigaction(SIGSEGV, &sa, 0); 219 sigaction(SIGBUS, &sa, 0); 220 sigaction(SIGUSR1, &sa, 0); 221 } 222 # endif /* RT_OS_LINUX && DEBUG */ 223 #endif /* Q_WS_X11 */ 199 224 200 225 /** Qt message handler, function that prints out … … 291 316 } 292 317 293 #ifdef Q_WS_X11294 /** X11: For versions of Xlib which are aware of multi-threaded environments this function295 * calls for XInitThreads() which initializes Xlib support for concurrent threads.296 * @returns @c non-zero unless it is unsafe to make multi-threaded calls to Xlib.297 * @remarks This is a workaround for a bug on old Xlib versions, fixed in commit298 * 941f02e and released in Xlib version 1.1. We check for the symbol299 * "xcb_connect" which was introduced in that version. */300 static Status MakeSureMultiThreadingIsSafe()301 {302 /* Success by default: */303 Status rc = 1;304 /* Get a global handle to process symbols: */305 void *pvProcess = dlopen(0, RTLD_GLOBAL | RTLD_LAZY);306 /* Initialize multi-thread environment only if we can obtain307 * an address of xcb_connect symbol in this process: */308 if (pvProcess && dlsym(pvProcess, "xcb_connect"))309 rc = XInitThreads();310 /* Close the handle: */311 if (pvProcess)312 dlclose(pvProcess);313 /* Return result: */314 return rc;315 }316 #endif /* Q_WS_X11 */317 318 318 extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char ** /*envp*/) 319 319 {
Note:
See TracChangeset
for help on using the changeset viewer.