MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / Plat_IsInDebugSession

Function Plat_IsInDebugSession

src/tier0/dbg.cpp:53–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51#endif
52
53bool Plat_IsInDebugSession()
54{
55#ifdef _WIN32
56 return (IsDebuggerPresent() != 0);
57#elif IsOSX()
58 int mib[4];
59 struct kinfo_proc info;
60 size_t size;
61 mib[0] = CTL_KERN;
62 mib[1] = KERN_PROC;
63 mib[2] = KERN_PROC_PID;
64 mib[3] = getpid();
65 size = sizeof(info);
66 info.kp_proc.p_flag = 0;
67 sysctl(mib,4,&info,&size,NULL,0);
68 return ((info.kp_proc.p_flag & P_TRACED) == P_TRACED);
69#elif IsFreeBSD()
70 int mib[4];
71 struct kinfo_proc info;
72 size_t size;
73 mib[0] = CTL_KERN;
74 mib[1] = KERN_PROC;
75 mib[2] = KERN_PROC_PID;
76 mib[3] = getpid();
77 size = sizeof(info);
78 if (sysctl(mib, 4, &info, &size, NULL, 0) == -1)
79 return false;
80 return ((info.ki_flag & P_TRACED) != 0);
81#elif IsOpenBSD()
82 int mib[4];
83 struct kinfo_proc info;
84 size_t size;
85 mib[0] = CTL_KERN;
86 mib[1] = KERN_PROC;
87 mib[2] = KERN_PROC_PID;
88 mib[3] = getpid();
89 size = sizeof(info);
90 if (sysctl(mib, 4, &info, &size, NULL, 0) == -1)
91 return false;
92 return ((info.p_psflags & PS_TRACED) != 0);
93#elif IsLinux()
94 static FILE *fp;
95 if ( !fp )
96 {
97 char rgchProcStatusFile[256]; rgchProcStatusFile[0] = '\0';
98 snprintf( rgchProcStatusFile, sizeof(rgchProcStatusFile), "/proc/%d/status", getpid() );
99 fp = fopen( rgchProcStatusFile, "r" );
100 }
101
102 char rgchLine[256]; rgchLine[0] = '\0';
103 int nTracePid = 0;
104 if ( fp )
105 {
106 const char *pszSearchString = "TracerPid:";
107 const uint cchSearchString = strlen( pszSearchString );
108 rewind( fp );
109 while ( fgets( rgchLine, sizeof(rgchLine), fp ) )
110 {

Callers 3

AssertMsgImplementationVFunction · 0.85
AboutToUnlockMethod · 0.85
PollRawUDPSocketsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected