Skip to content

Instantly share code, notes, and snippets.

@FelixK15
Forked from anonymous/debuggerutil.c
Created March 30, 2017 13:59
Show Gist options
  • Save FelixK15/14e8628cb0b04702c42a05c5c2848f9e to your computer and use it in GitHub Desktop.
Save FelixK15/14e8628cb0b04702c42a05c5c2848f9e to your computer and use it in GitHub Desktop.
#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