diff options
Diffstat (limited to 'base/process_util_posix.cc')
-rw-r--r-- | base/process_util_posix.cc | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 07e3125..8a97dcd 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -101,9 +101,52 @@ int WaitpidWithTimeout(ProcessHandle handle, int64 wait_milliseconds, return status; } -void StackDumpSignalHandler(int signal) { +void StackDumpSignalHandler(int signal, siginfo_t* info, ucontext_t* context) { LOG(ERROR) << "Received signal " << signal; debug::StackTrace().PrintBacktrace(); + + // TODO(shess): Port to Linux. +#if defined(OS_MACOSX) + // TODO(shess): Port to 64-bit. +#if ARCH_CPU_32_BITS + char buf[1024]; + size_t len; + + // NOTE: Even |snprintf()| is not on the approved list for signal + // handlers, but buffered I/O is definitely not on the list due to + // potential for |malloc()|. + len = static_cast<size_t>( + snprintf(buf, sizeof(buf), + "ax: %x, bx: %x, cx: %x, dx: %x\n", + context->uc_mcontext->__ss.__eax, + context->uc_mcontext->__ss.__ebx, + context->uc_mcontext->__ss.__ecx, + context->uc_mcontext->__ss.__edx)); + write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); + + len = static_cast<size_t>( + snprintf(buf, sizeof(buf), + "di: %x, si: %x, bp: %x, sp: %x, ss: %x, flags: %x\n", + context->uc_mcontext->__ss.__edi, + context->uc_mcontext->__ss.__esi, + context->uc_mcontext->__ss.__ebp, + context->uc_mcontext->__ss.__esp, + context->uc_mcontext->__ss.__ss, + context->uc_mcontext->__ss.__eflags)); + write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); + + len = static_cast<size_t>( + snprintf(buf, sizeof(buf), + "ip: %x, cs: %x, ds: %x, es: %x, fs: %x, gs: %x\n", + context->uc_mcontext->__ss.__eip, + context->uc_mcontext->__ss.__cs, + context->uc_mcontext->__ss.__ds, + context->uc_mcontext->__ss.__es, + context->uc_mcontext->__ss.__fs, + context->uc_mcontext->__ss.__gs)); + write(STDERR_FILENO, buf, std::min(len, sizeof(buf) - 1)); +#endif // ARCH_CPU_32_BITS +#endif // defined(OS_MACOSX) _exit(1); } @@ -571,12 +614,13 @@ bool EnableInProcessStackDumping() { sigemptyset(&action.sa_mask); bool success = (sigaction(SIGPIPE, &action, NULL) == 0); - success &= (signal(SIGILL, &StackDumpSignalHandler) != SIG_ERR); - success &= (signal(SIGABRT, &StackDumpSignalHandler) != SIG_ERR); - success &= (signal(SIGFPE, &StackDumpSignalHandler) != SIG_ERR); - success &= (signal(SIGBUS, &StackDumpSignalHandler) != SIG_ERR); - success &= (signal(SIGSEGV, &StackDumpSignalHandler) != SIG_ERR); - success &= (signal(SIGSYS, &StackDumpSignalHandler) != SIG_ERR); + sig_t handler = reinterpret_cast<sig_t>(&StackDumpSignalHandler); + success &= (signal(SIGILL, handler) != SIG_ERR); + success &= (signal(SIGABRT, handler) != SIG_ERR); + success &= (signal(SIGFPE, handler) != SIG_ERR); + success &= (signal(SIGBUS, handler) != SIG_ERR); + success &= (signal(SIGSEGV, handler) != SIG_ERR); + success &= (signal(SIGSYS, handler) != SIG_ERR); return success; } |