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 #include "base/process_util.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 namespace debug { | 15 namespace debug { |
15 | 16 |
16 bool EnableInProcessStackDumping() { | 17 bool EnableInProcessStackDumping() { |
17 // When running in an application, our code typically expects SIGPIPE | 18 // When running in an application, our code typically expects SIGPIPE |
18 // to be ignored. Therefore, when testing that same code, it should run | 19 // to be ignored. Therefore, when testing that same code, it should run |
19 // with SIGPIPE ignored as well. | 20 // with SIGPIPE ignored as well. |
20 // TODO(phajdan.jr): De-duplicate this SIGPIPE code. | 21 // TODO(phajdan.jr): Ignoring SIGPIPE has nothing to do with stack dumping. |
21 struct sigaction action; | 22 return base::IgnoreSigPipe(); |
22 memset(&action, 0, sizeof(action)); | |
23 action.sa_handler = SIG_IGN; | |
24 sigemptyset(&action.sa_mask); | |
25 return (sigaction(SIGPIPE, &action, NULL) == 0); | |
26 } | 23 } |
27 | 24 |
28 StackTrace::StackTrace() { | 25 StackTrace::StackTrace() { |
29 } | 26 } |
30 | 27 |
31 // Sends fake SIGSTKFLT signals to let the Android linker and debuggerd dump | 28 // Sends fake SIGSTKFLT signals to let the Android linker and debuggerd dump |
32 // stack. See inlined comments and Android bionic/linker/debugger.c and | 29 // stack. See inlined comments and Android bionic/linker/debugger.c and |
33 // system/core/debuggerd/debuggerd.c for details. | 30 // system/core/debuggerd/debuggerd.c for details. |
34 void StackTrace::PrintBacktrace() const { | 31 void StackTrace::PrintBacktrace() const { |
35 // Get the current handler of SIGSTKFLT for later use. | 32 // Get the current handler of SIGSTKFLT for later use. |
(...skipping 15 matching lines...) Expand all Loading... |
51 // Restore the signal handler so that this method can work the next time. | 48 // Restore the signal handler so that this method can work the next time. |
52 signal(SIGSTKFLT, sig_handler); | 49 signal(SIGSTKFLT, sig_handler); |
53 } | 50 } |
54 | 51 |
55 void StackTrace::OutputToStream(std::ostream* os) const { | 52 void StackTrace::OutputToStream(std::ostream* os) const { |
56 NOTIMPLEMENTED(); | 53 NOTIMPLEMENTED(); |
57 } | 54 } |
58 | 55 |
59 } // namespace debug | 56 } // namespace debug |
60 } // namespace base | 57 } // namespace base |
OLD | NEW |