[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/debug/stack_trace.h" |
| 6 | |
| 7 | #include <signal.h> |
| 8 | #include <sys/types.h> |
| 9 | #include <unistd.h> |
| 10 | |
| 11 | #include "base/logging.h" |
| 12 | |
| 13 | namespace base { |
| 14 | namespace debug { |
| 15 | |
| 16 | StackTrace::StackTrace() { |
| 17 | } |
| 18 | |
| 19 | StackTrace::~StackTrace() { |
| 20 | } |
| 21 | |
| 22 | const void* const* StackTrace::Addresses(size_t* count) const { |
| 23 | NOTIMPLEMENTED(); |
| 24 | return NULL; |
| 25 | } |
| 26 | |
| 27 | // Sends fake SIGSTKFLT signals to let the Android linker and debuggerd dump |
| 28 | // stack. See inlined comments and Android bionic/linker/debugger.c and |
| 29 | // system/core/debuggerd/debuggerd.c for details. |
| 30 | void StackTrace::PrintBacktrace() const { |
| 31 | // Get the current handler of SIGSTKFLT for later use. |
| 32 | sighandler_t sig_handler = signal(SIGSTKFLT, SIG_DFL); |
| 33 | signal(SIGSTKFLT, sig_handler); |
| 34 | |
| 35 | // The Android linker will handle this signal and send a stack dumping request |
| 36 | // to debuggerd which will ptrace_attach this process. Before returning from |
| 37 | // the signal handler, the linker sets the signal handler to SIG_IGN. |
| 38 | kill(gettid(), SIGSTKFLT); |
| 39 | |
| 40 | // Because debuggerd will wait for the process to be stopped by the actual |
| 41 | // signal in crashing scenarios, signal is sent again to met the expectation. |
| 42 | // Debuggerd will dump stack into the system log and /data/tombstones/ files. |
| 43 | // NOTE: If this process runs in the interactive shell, it will be put |
| 44 | // in the background. To resume it in the foreground, use 'fg' command. |
| 45 | kill(gettid(), SIGSTKFLT); |
| 46 | |
| 47 | // Restore the signal handler so that this method can work the next time. |
| 48 | signal(SIGSTKFLT, sig_handler); |
| 49 | } |
| 50 | |
| 51 | void StackTrace::OutputToStream(std::ostream* os) const { |
| 52 | NOTIMPLEMENTED(); |
| 53 | } |
| 54 | |
| 55 | } // namespace debug |
| 56 | } // namespace base |