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 DEBUG_BREAK() { |
darin (slow to review)
2013/03/19 22:24:14
nit: I recommend preserving the DEBUG_BREAK macro
mostynb%opera.com
2013/03/20 05:32:39
Done.
| |
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 } | |
231 #else | 233 #else |
232 // ARM && !ANDROID | 234 // ARM && !ANDROID |
233 #define DEBUG_BREAK() asm("bkpt 0") | 235 #define DEBUG_BREAK() asm("bkpt 0") |
234 #endif | 236 #endif |
235 #elif defined(ARCH_CPU_MIPS_FAMILY) | 237 #elif defined(ARCH_CPU_MIPS_FAMILY) |
236 #define DEBUG_BREAK() asm("break 2") | 238 #define DEBUG_BREAK() asm("break 2") |
237 #else | 239 #else |
238 #define DEBUG_BREAK() asm("int3") | 240 #define DEBUG_BREAK() asm("int3") |
239 #endif | 241 #endif |
240 | 242 |
241 void BreakDebugger() { | 243 void BreakDebugger() { |
242 // NOTE: This code MUST be async-signal safe (it's used by in-process | 244 // 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. | 245 // stack dumping signal handler). NO malloc or stdio is allowed here. |
244 | 246 |
245 DEBUG_BREAK(); | 247 DEBUG_BREAK(); |
246 #if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD) | 248 #if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD) |
247 // For Android development we always build release (debug builds are | 249 // For Android development we always build release (debug builds are |
248 // unmanageably large), so the unofficial build is used for debugging. It is | 250 // unmanageably large), so the unofficial build is used for debugging. It is |
249 // helpful to be able to insert BreakDebugger() statements in the source, | 251 // 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 | 252 // attach the debugger, inspect the state of the program and then resume it by |
251 // setting the 'go' variable above. | 253 // setting the 'go' variable above. |
252 #elif defined(NDEBUG) | 254 #elif defined(NDEBUG) |
253 // Terminate the program after signaling the debug break. | 255 // Terminate the program after signaling the debug break. |
254 _exit(1); | 256 _exit(1); |
255 #endif | 257 #endif |
256 } | 258 } |
257 | 259 |
258 } // namespace debug | 260 } // namespace debug |
259 } // namespace base | 261 } // namespace base |
OLD | NEW |