MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / isDebuggerActive

Function isDebuggerActive

extlibs/catch/include/catch/catch.hpp:10042–10071  ·  view source on GitHub ↗

Returns true if the current process is being debugged (either running under the debugger or has a debugger attached post facto).

Source from the content-addressed store, hash-verified

10040 // Returns true if the current process is being debugged (either
10041 // running under the debugger or has a debugger attached post facto).
10042 bool isDebuggerActive(){
10043 int mib[4];
10044 struct kinfo_proc info;
10045 std::size_t size;
10046
10047 // Initialize the flags so that, if sysctl fails for some bizarre
10048 // reason, we get a predictable result.
10049
10050 info.kp_proc.p_flag = 0;
10051
10052 // Initialize mib, which tells sysctl the info we want, in this case
10053 // we're looking for information about a specific process ID.
10054
10055 mib[0] = CTL_KERN;
10056 mib[1] = KERN_PROC;
10057 mib[2] = KERN_PROC_PID;
10058 mib[3] = getpid();
10059
10060 // Call sysctl.
10061
10062 size = sizeof(info);
10063 if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) {
10064 Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
10065 return false;
10066 }
10067
10068 // We're being debugged if the P_TRACED flag is set.
10069
10070 return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
10071 }
10072 #else
10073 bool isDebuggerActive() {
10074 // We need to find another way to determine this for non-appleclang compilers on macOS

Callers 1

useColourOnPlatformFunction · 0.85

Calls 2

compareMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected