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

Function isDebuggerActive

unittests/catch.hpp:7107–7137  ·  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

7105 // Returns true if the current process is being debugged (either
7106 // running under the debugger or has a debugger attached post facto).
7107 bool isDebuggerActive(){
7108
7109 int mib[4];
7110 struct kinfo_proc info;
7111 std::size_t size;
7112
7113 // Initialize the flags so that, if sysctl fails for some bizarre
7114 // reason, we get a predictable result.
7115
7116 info.kp_proc.p_flag = 0;
7117
7118 // Initialize mib, which tells sysctl the info we want, in this case
7119 // we're looking for information about a specific process ID.
7120
7121 mib[0] = CTL_KERN;
7122 mib[1] = KERN_PROC;
7123 mib[2] = KERN_PROC_PID;
7124 mib[3] = getpid();
7125
7126 // Call sysctl.
7127
7128 size = sizeof(info);
7129 if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) {
7130 Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
7131 return false;
7132 }
7133
7134 // We're being debugged if the P_TRACED flag is set.
7135
7136 return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
7137 }
7138 } // namespace Catch
7139
7140#elif defined(CATCH_PLATFORM_LINUX)

Callers 1

useColourOnPlatformFunction · 0.85

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected