47 lines
819 B
C++
Executable File
47 lines
819 B
C++
Executable File
#pragma once
|
|
|
|
#include <csignal>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include "windows_wrapper.h"
|
|
|
|
inline bool is_debugger_present()
|
|
{
|
|
#ifdef WIN32
|
|
return IsDebuggerPresent();
|
|
#else
|
|
char buf[1024];
|
|
int debugger_present = 0;
|
|
|
|
int status_fd = open("/proc/self/status", O_RDONLY);
|
|
if (status_fd == -1)
|
|
return 0;
|
|
|
|
ssize_t num_read = read(status_fd, buf, sizeof(buf)-1);
|
|
|
|
if (num_read > 0)
|
|
{
|
|
static const char TracerPid[] = "TracerPid:";
|
|
char *tracer_pid;
|
|
|
|
buf[num_read] = 0;
|
|
tracer_pid = strstr(buf, TracerPid);
|
|
if (tracer_pid)
|
|
debugger_present = !!atoi(tracer_pid + sizeof(TracerPid) - 1);
|
|
}
|
|
|
|
return debugger_present;
|
|
#endif
|
|
}
|
|
|
|
inline void debug_break()
|
|
{
|
|
#ifdef _WIN32
|
|
__debugbreak();
|
|
#else
|
|
std::raise(SIGINT);
|
|
#endif
|
|
}
|
|
|
|
|