MCPcopy Index your code
hub / github.com/Audio4Linux/JDSP4Linux / debuggerIsAttached

Function debuggerIsAttached

src/utils/DebuggerUtils.h:10–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <ctype.h>
9
10bool debuggerIsAttached()
11{
12 char buf[4096];
13
14 const int status_fd = ::open("/proc/self/status", O_RDONLY);
15 if (status_fd == -1)
16 return false;
17
18 const ssize_t num_read = ::read(status_fd, buf, sizeof(buf) - 1);
19 ::close(status_fd);
20
21 if (num_read <= 0)
22 return false;
23
24 buf[num_read] = '\0';
25 constexpr char tracerPidString[] = "TracerPid:";
26 const auto tracer_pid_ptr = ::strstr(buf, tracerPidString);
27 if (!tracer_pid_ptr)
28 return false;
29
30 for (const char* characterPtr = tracer_pid_ptr + sizeof(tracerPidString) - 1; characterPtr <= buf + num_read; ++characterPtr)
31 {
32 if (::isspace(*characterPtr))
33 continue;
34 else
35 return ::isdigit(*characterPtr) != 0 && *characterPtr != '0';
36 }
37
38 return false;
39}
40#endif // DEBUGGERUTILS_H

Callers 1

MainWindowMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected