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/debugger.h" | 5 #include "base/debug/debugger.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 #if defined(OS_FREEBSD) | 115 #if defined(OS_FREEBSD) |
116 being_debugged = (info.ki_flag & P_TRACED) != 0; | 116 being_debugged = (info.ki_flag & P_TRACED) != 0; |
117 #elif defined(OS_BSD) | 117 #elif defined(OS_BSD) |
118 being_debugged = (info.p_flag & P_TRACED) != 0; | 118 being_debugged = (info.p_flag & P_TRACED) != 0; |
119 #else | 119 #else |
120 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; | 120 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; |
121 #endif | 121 #endif |
122 return being_debugged; | 122 return being_debugged; |
123 } | 123 } |
124 | 124 |
125 #elif defined(OS_LINUX) || defined(OS_ANDROID) | 125 #elif defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_AIX) |
126 | 126 |
127 // We can look in /proc/self/status for TracerPid. We are likely used in crash | 127 // We can look in /proc/self/status for TracerPid. We are likely used in crash |
128 // handling, so we are careful not to use the heap or have side effects. | 128 // handling, so we are careful not to use the heap or have side effects. |
129 // Another option that is common is to try to ptrace yourself, but then we | 129 // Another option that is common is to try to ptrace yourself, but then we |
130 // can't detach without forking(), and that's not so great. | 130 // can't detach without forking(), and that's not so great. |
131 // static | 131 // static |
132 bool BeingDebugged() { | 132 bool BeingDebugged() { |
133 // NOTE: This code MUST be async-signal safe (it's used by in-process | 133 // NOTE: This code MUST be async-signal safe (it's used by in-process |
134 // stack dumping signal handler). NO malloc or stdio is allowed here. | 134 // stack dumping signal handler). NO malloc or stdio is allowed here. |
135 | 135 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // attach the debugger, inspect the state of the program and then resume it by | 256 // attach the debugger, inspect the state of the program and then resume it by |
257 // setting the 'go' variable above. | 257 // setting the 'go' variable above. |
258 #elif defined(NDEBUG) | 258 #elif defined(NDEBUG) |
259 // Terminate the program after signaling the debug break. | 259 // Terminate the program after signaling the debug break. |
260 _exit(1); | 260 _exit(1); |
261 #endif | 261 #endif |
262 } | 262 } |
263 | 263 |
264 } // namespace debug | 264 } // namespace debug |
265 } // namespace base | 265 } // namespace base |
OLD | NEW |