61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
/**
|
|
******************************************************************************
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
******************************************************************************
|
|
* Copyright 2017 Ben Vanik. All rights reserved. *
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
******************************************************************************
|
|
*
|
|
* @modified Tom Clay, 2026 - Adapted for ReXGlue runtime
|
|
*/
|
|
|
|
#include <csignal>
|
|
#include <cstdarg>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <mutex>
|
|
#include <sstream>
|
|
|
|
#include <rex/dbg.h>
|
|
#include <rex/string/buffer.h>
|
|
|
|
namespace rex::debug {
|
|
|
|
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;
|
|
}
|
|
|
|
void Break() {
|
|
static std::once_flag flag;
|
|
std::call_once(flag, []() {
|
|
// Install handler for sigtrap only once
|
|
std::signal(SIGTRAP, [](int) {
|
|
// Forward signal to default handler after being caught
|
|
std::signal(SIGTRAP, SIG_DFL);
|
|
});
|
|
});
|
|
std::raise(SIGTRAP);
|
|
}
|
|
|
|
namespace detail {
|
|
void DebugPrint(const char* s) {
|
|
std::clog << s << std::endl;
|
|
}
|
|
} // namespace detail
|
|
|
|
} // namespace rex::debug
|