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