Merge remote-tracking branch 'bwr/linux_debug' into canary

This commit is contained in:
Prism Tutaj 2019-09-07 20:58:28 -05:00
commit 94d71c918e
1 changed files with 35 additions and 3 deletions

View File

@ -11,14 +11,46 @@
#include <signal.h>
#include <cstdarg>
#include <fstream>
#include <iostream>
#include <sstream>
#include "xenia/base/string_buffer.h"
namespace xe {
namespace debugging {
bool IsDebuggerAttached() { return false; }
void Break() { raise(SIGTRAP); }
bool IsDebuggerAttached() {
std::ifstream proc_status_stream("/proc/self/status");
if (proc_status_stream.is_open()) {
return false;
}
std::string line;
while (std::getline(proc_status_stream, line)) {
std::istringstream line_stream(line);
std::string key;
line_stream >> key;
if (key == "TracerPid:") {
uint32_t tracer_pid;
line_stream >> tracer_pid;
return tracer_pid != 0;
}
}
return false;
}
static bool SigTrapInstalled = false;
static void SigTrapHandler(int signum) {
signal(SIGTRAP, SIG_DFL);
SigTrapInstalled = true;
}
void Break() {
if (!SigTrapInstalled) {
signal(SIGTRAP, SigTrapHandler);
}
raise(SIGTRAP);
}
void DebugPrint(const char* fmt, ...) {
StringBuffer buff;
@ -28,7 +60,7 @@ void DebugPrint(const char* fmt, ...) {
buff.AppendVarargs(fmt, va);
va_end(va);
// OutputDebugStringA(buff.GetString());
std::clog << buff.GetString() << std::endl;
}
} // namespace debugging