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 #include "build/build_config.h" | 6 #include "build/build_config.h" |
7 | 7 |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 #define DEBUG_BREAK() abort() | 211 #define DEBUG_BREAK() abort() |
212 #elif defined(ARCH_CPU_ARM_FAMILY) | 212 #elif defined(ARCH_CPU_ARM_FAMILY) |
213 #if defined(OS_ANDROID) | 213 #if defined(OS_ANDROID) |
214 // Though Android has a "helpful" process called debuggerd to catch native | 214 // Though Android has a "helpful" process called debuggerd to catch native |
215 // signals on the general assumption that they are fatal errors. The bkpt | 215 // signals on the general assumption that they are fatal errors. The bkpt |
216 // instruction appears to cause SIGBUS which is trapped by debuggerd, and | 216 // instruction appears to cause SIGBUS which is trapped by debuggerd, and |
217 // we've had great difficulty continuing in a debugger once we stop from | 217 // we've had great difficulty continuing in a debugger once we stop from |
218 // SIG triggered by native code. | 218 // SIG triggered by native code. |
219 // | 219 // |
220 // Use GDB to set |go| to 1 to resume execution. | 220 // Use GDB to set |go| to 1 to resume execution. |
221 #define DEBUG_BREAK() do { \ | 221 void DebugBreak() { |
darin (slow to review)
2013/03/20 06:24:34
nit: oh, this should probably have static linkage
| |
222 if (!BeingDebugged()) { \ | 222 do { |
223 abort(); \ | 223 if (!BeingDebugged()) { |
224 } else { \ | 224 abort(); |
225 volatile int go = 0; \ | 225 } else { |
226 while (!go) { \ | 226 volatile int go = 0; |
227 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); \ | 227 while (!go) { |
228 } \ | 228 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
229 } \ | 229 } |
230 } while (0) | 230 } |
231 } while (0); | |
232 } | |
233 #define DEBUG_BREAK() DebugBreak() | |
231 #else | 234 #else |
232 // ARM && !ANDROID | 235 // ARM && !ANDROID |
233 #define DEBUG_BREAK() asm("bkpt 0") | 236 #define DEBUG_BREAK() asm("bkpt 0") |
234 #endif | 237 #endif |
235 #elif defined(ARCH_CPU_MIPS_FAMILY) | 238 #elif defined(ARCH_CPU_MIPS_FAMILY) |
236 #define DEBUG_BREAK() asm("break 2") | 239 #define DEBUG_BREAK() asm("break 2") |
237 #else | 240 #else |
238 #define DEBUG_BREAK() asm("int3") | 241 #define DEBUG_BREAK() asm("int3") |
239 #endif | 242 #endif |
240 | 243 |
241 void BreakDebugger() { | 244 void BreakDebugger() { |
242 // NOTE: This code MUST be async-signal safe (it's used by in-process | 245 // NOTE: This code MUST be async-signal safe (it's used by in-process |
243 // stack dumping signal handler). NO malloc or stdio is allowed here. | 246 // stack dumping signal handler). NO malloc or stdio is allowed here. |
244 | 247 |
245 DEBUG_BREAK(); | 248 DEBUG_BREAK(); |
246 #if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD) | 249 #if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD) |
247 // For Android development we always build release (debug builds are | 250 // For Android development we always build release (debug builds are |
248 // unmanageably large), so the unofficial build is used for debugging. It is | 251 // unmanageably large), so the unofficial build is used for debugging. It is |
249 // helpful to be able to insert BreakDebugger() statements in the source, | 252 // helpful to be able to insert BreakDebugger() statements in the source, |
250 // attach the debugger, inspect the state of the program and then resume it by | 253 // attach the debugger, inspect the state of the program and then resume it by |
251 // setting the 'go' variable above. | 254 // setting the 'go' variable above. |
252 #elif defined(NDEBUG) | 255 #elif defined(NDEBUG) |
253 // Terminate the program after signaling the debug break. | 256 // Terminate the program after signaling the debug break. |
254 _exit(1); | 257 _exit(1); |
255 #endif | 258 #endif |
256 } | 259 } |
257 | 260 |
258 } // namespace debug | 261 } // namespace debug |
259 } // namespace base | 262 } // namespace base |
OLD | NEW |