HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
debugger.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_ARCH_DEBUGGER_H
8 #define PXR_BASE_ARCH_DEBUGGER_H
9 
10 /// \file arch/debugger.h
11 /// Routines for interacting with a debugger.
12 
13 #include "pxr/pxr.h"
14 #include "pxr/base/arch/api.h"
16 
18 
19 /// Stop in a debugger.
20 ///
21 /// This function will do one of the following: start a debugger
22 /// attached to this process stopped on this function; stop in an
23 /// already attached debugger; stop and wait for a debugger to
24 /// attach, or nothing.
25 ///
26 /// On Linux this will start a debugger using \c ArchDebuggerAttach()
27 /// if no debugger is attached. If a debugger is (or was) attached it
28 /// will stop on this function due to \c SIGTRAP. Alternatively, users
29 /// can configure the debugger to not stop on \c SIGTRAP and instead
30 /// break on \c ArchDebuggerTrap().
31 ///
32 /// If a debugger is not attached, \c ArchDebuggerAttach() does not
33 /// attach one, and \c ArchDebuggerWait() has been most recently
34 /// called with \c true then this will wait for a debugger to attach,
35 /// otherwise it does nothing and the process does not stop. The user
36 /// can continue the process from the debugger simply by issuing the
37 /// continue command. The user can also continue the process from an
38 /// attached terminal by putting the process into the foreground or
39 /// background.
40 ///
42 void ArchDebuggerTrap() ARCH_NOINLINE;
43 
44 /// Cause debug traps to wait for the debugger or not.
45 ///
46 /// When \p wait is \c true the next call to \c ArchDebuggerTrap()
47 /// will cause the process to wait for a signal. The user can attach
48 /// a debugger to continue the process. The process will not wait
49 /// again until another call to this function with \p wait \c true.
50 ///
52 void ArchDebuggerWait(bool wait);
53 
54 /// Attach a debugger.
55 ///
56 /// Attaches the debugger by running the contents of the enviroment variable
57 /// ARCH_DEBUGGER using /bin/sh. Any '%p' in the contents of this variable
58 /// will be replaced with the process id of the process launching the debugger.
59 /// Any '%e' will be replaced with the path to the executable for the process.
60 ///
61 /// Returns true if ARCH_DEBUGGER is set and the debugger was successfully
62 /// launched, otherwise returns false.
64 bool ArchDebuggerAttach() ARCH_NOINLINE;
65 
66 /// Test if a debugger is attached
67 ///
68 /// Attempts to detect if a debugger is currently attached to the process.
70 bool ArchDebuggerIsAttached() ARCH_NOINLINE;
71 
72 /// Abort. This will try to avoid the JIT debugger if any if ARCH_AVOID_JIT
73 /// is in the environment and the debugger isn't already attached. In that
74 /// case it will _exit(134). If \p logging is \c false then this will
75 /// attempt to bypass any crash logging.
76 [[noreturn]]
78 void ArchAbort(bool logging = true);
79 
80 /// Stop in the debugger.
81 ///
82 /// This macro expands to \c ArchDebuggerTrap() and, if necessary and
83 /// possible, code to prevent optimization so the caller appears in the
84 /// debugger's stack trace. The calling functions should also use the
85 /// \c ARCH_NOINLINE function attribute.
86 #if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
87 #define ARCH_DEBUGGER_TRAP do { ArchDebuggerTrap(); asm(""); } while (0)
88 #else
89 #define ARCH_DEBUGGER_TRAP do { ArchDebuggerTrap(); } while (0)
90 #endif
91 
93 
94 #endif // PXR_BASE_ARCH_DEBUGGER_H
ARCH_API void ArchAbort(bool logging=true)
ARCH_API void ArchDebuggerWait(bool wait)
ARCH_API bool ArchDebuggerIsAttached() ARCH_NOINLINE
*tasks wait()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
PXR_NAMESPACE_OPEN_SCOPE ARCH_API void ArchDebuggerTrap() ARCH_NOINLINE
#define ARCH_API
Definition: api.h:23
ARCH_API bool ArchDebuggerAttach() ARCH_NOINLINE