Files
spark/src/lib/utils/bts_debugger.h
T
John Colvin 3b1a2357cc fix build (client): Change 'WIN32' macros to '_WIN32'
Not sure exactly how this broke, but the WIN32 macro is no longer defined.
2023-01-02 18:42:39 -05:00

42 lines
804 B
C++

#pragma once
#include "windows_wrapper.h"
#include <csignal>
#include <fcntl.h>
#include <sys/stat.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
}