Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: base/debug/debugger_posix.cc

Issue 13597005: Android: improve native debuggability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nitpick (end namespace comment) Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 namespace {
darin (slow to review) 2013/04/08 18:56:14 nit: the contents of namespaces should not be inde
Mostyn Bramley-Moore 2013/04/08 19:44:08 Done.
222 if (!BeingDebugged()) { \ 222 void DebugBreak() {
223 abort(); \ 223 do {
darin (slow to review) 2013/04/08 18:56:14 nit: The "do { ... } while (0)" wrapper should no
Mostyn Bramley-Moore 2013/04/08 19:44:08 Done.
224 } else { \ 224 if (!BeingDebugged()) {
225 volatile int go = 0; \ 225 abort();
226 while (!go) { \ 226 } else {
227 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); \ 227 volatile int go = 0;
228 } \ 228 while (!go) {
229 } \ 229 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
230 } while (0) 230 }
231 }
232 } while (0);
233 }
234 } // namespace
235 #define DEBUG_BREAK() DebugBreak()
231 #else 236 #else
232 // ARM && !ANDROID 237 // ARM && !ANDROID
233 #define DEBUG_BREAK() asm("bkpt 0") 238 #define DEBUG_BREAK() asm("bkpt 0")
234 #endif 239 #endif
235 #elif defined(ARCH_CPU_MIPS_FAMILY) 240 #elif defined(ARCH_CPU_MIPS_FAMILY)
236 #define DEBUG_BREAK() asm("break 2") 241 #define DEBUG_BREAK() asm("break 2")
237 #else 242 #else
238 #define DEBUG_BREAK() asm("int3") 243 #define DEBUG_BREAK() asm("int3")
239 #endif 244 #endif
240 245
241 void BreakDebugger() { 246 void BreakDebugger() {
242 // NOTE: This code MUST be async-signal safe (it's used by in-process 247 // 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. 248 // stack dumping signal handler). NO malloc or stdio is allowed here.
244 249
245 DEBUG_BREAK(); 250 DEBUG_BREAK();
246 #if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD) 251 #if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD)
247 // For Android development we always build release (debug builds are 252 // For Android development we always build release (debug builds are
248 // unmanageably large), so the unofficial build is used for debugging. It is 253 // unmanageably large), so the unofficial build is used for debugging. It is
249 // helpful to be able to insert BreakDebugger() statements in the source, 254 // 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 255 // attach the debugger, inspect the state of the program and then resume it by
251 // setting the 'go' variable above. 256 // setting the 'go' variable above.
252 #elif defined(NDEBUG) 257 #elif defined(NDEBUG)
253 // Terminate the program after signaling the debug break. 258 // Terminate the program after signaling the debug break.
254 _exit(1); 259 _exit(1);
255 #endif 260 #endif
256 } 261 }
257 262
258 } // namespace debug 263 } // namespace debug
259 } // namespace base 264 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698