-
Notifications
You must be signed in to change notification settings - Fork 74
Open
Description
Hi,
I am using this code quite a while and I had no problems.
Would be cool if it could be added to develop:
#elif CHOC_ANDROID
#include <sys/ptrace.h>
#include <unistd.h>
#include <fcntl.h>
#include <string>
#include <android/log.h>
inline bool choc::isDebuggerActive()
{
// Method 1: Check TracerPid in /proc/self/status (similar to Linux)
auto readTracerPid = []() -> int
{
int tracerPid = 0;
int fd = open("/proc/self/status", O_RDONLY);
if (fd == -1)
return 0;
char buf[512];
ssize_t n = read(fd, buf, sizeof(buf)-1);
close(fd);
if (n <= 0)
return 0;
buf[n] = '\0';
std::string status(buf);
std::string tracerPidStr = "TracerPid:";
size_t pos = status.find(tracerPidStr);
if (pos != std::string::npos)
{
size_t lineEnd = status.find('\n', pos);
std::string line = status.substr(pos, lineEnd - pos);
try
{
tracerPid = std::stoi(line.substr(tracerPidStr.length()));
}
catch (...) {}
}
return tracerPid;
};
return readTracerPid() > 0;
}
Thanks!
Metadata
Metadata
Assignees
Labels
No labels