diff --git a/src/xenia/base/debugging_posix.cc b/src/xenia/base/debugging_posix.cc index 32d212d60..0e432886a 100644 --- a/src/xenia/base/debugging_posix.cc +++ b/src/xenia/base/debugging_posix.cc @@ -11,14 +11,46 @@ #include #include +#include +#include +#include #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