-
-
Save FelixK15/14e8628cb0b04702c42a05c5c2848f9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
bool isDebuggerAttached() | |
{ | |
char buf[128] = {}; | |
bool debugger_present = false; | |
int status_fd = open("/proc/self/status", O_RDONLY); | |
if (-1 == status_fd) | |
{ | |
HC_LOG_ERROR("Failed to open status file"); | |
return debugger_present; | |
} | |
ssize_t num_read = read(status_fd, buf, sizeof(buf)); | |
if (num_read > 0) | |
{ | |
buf[num_read] = 0; | |
char* tracer_pid = HC_FIND_SUBSTRING(buf, "TracerPid:"); | |
if (NULL != tracer_pid) | |
{ | |
debugger_present = (0 != atoi(tracer_pid + 10)); | |
} | |
} | |
return debugger_present; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment