xref: /aosp_15_r20/external/cronet/base/debug/debugger.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This is a cross platform interface for helper functions related to
6 // debuggers.  You should use this to test if you're running under a debugger,
7 // and if you would like to yield (breakpoint) into the debugger.
8 
9 #ifndef BASE_DEBUG_DEBUGGER_H_
10 #define BASE_DEBUG_DEBUGGER_H_
11 
12 #include "base/base_export.h"
13 
14 namespace base {
15 namespace debug {
16 
17 // Waits wait_seconds seconds for a debugger to attach to the current process.
18 // When silent is false, an exception is thrown when a debugger is detected.
19 BASE_EXPORT bool WaitForDebugger(int wait_seconds, bool silent);
20 
21 // Returns true if the given process is being run under a debugger.
22 //
23 // On OS X, the underlying mechanism doesn't work when the sandbox is enabled.
24 // To get around this, this function caches its value.
25 //
26 // WARNING: Because of this, on OS X, a call MUST be made to this function
27 // BEFORE the sandbox is enabled.
28 BASE_EXPORT bool BeingDebugged();
29 
30 // Break into the debugger, assumes a debugger is present.
31 BASE_EXPORT void BreakDebugger();
32 // Async-safe version of BreakDebugger(). In particular, this does not allocate
33 // any memory. More broadly, must be safe to call from anywhere, including
34 // signal handlers.
35 BASE_EXPORT void BreakDebuggerAsyncSafe();
36 
37 // Used in test code, this controls whether showing dialogs and breaking into
38 // the debugger is suppressed for debug errors, even in debug mode (normally
39 // release mode doesn't do this stuff --  this is controlled separately).
40 // Normally UI is not suppressed.  This is normally used when running automated
41 // tests where we want a crash rather than a dialog or a debugger.
42 BASE_EXPORT void SetSuppressDebugUI(bool suppress);
43 BASE_EXPORT bool IsDebugUISuppressed();
44 
45 // If a debugger is present, verifies that it is properly set up, and DCHECK()s
46 // if misconfigured.  Currently only verifies that //tools/gdb/gdbinit has been
47 // sourced when using gdb on Linux and //tools/lldb/lldbinit.py has been sourced
48 // when using lldb on macOS.
49 BASE_EXPORT void VerifyDebugger();
50 
51 }  // namespace debug
52 }  // namespace base
53 
54 #endif  // BASE_DEBUG_DEBUGGER_H_
55