MCPcopy Create free account
hub / github.com/apache/trafficserver / isDebuggerActive

Function isDebuggerActive

lib/catch2/catch.hpp:10420–10449  ·  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

10418 // Returns true if the current process is being debugged (either
10419 // running under the debugger or has a debugger attached post facto).
10420 bool isDebuggerActive(){
10421 int mib[4];
10422 struct kinfo_proc info;
10423 std::size_t size;
10424
10425 // Initialize the flags so that, if sysctl fails for some bizarre
10426 // reason, we get a predictable result.
10427
10428 info.kp_proc.p_flag = 0;
10429
10430 // Initialize mib, which tells sysctl the info we want, in this case
10431 // we're looking for information about a specific process ID.
10432
10433 mib[0] = CTL_KERN;
10434 mib[1] = KERN_PROC;
10435 mib[2] = KERN_PROC_PID;
10436 mib[3] = getpid();
10437
10438 // Call sysctl.
10439
10440 size = sizeof(info);
10441 if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) {
10442 Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
10443 return false;
10444 }
10445
10446 // We're being debugged if the P_TRACED flag is set.
10447
10448 return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
10449 }
10450 #else
10451 bool isDebuggerActive() {
10452 // 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