diff options
Diffstat (limited to '3rdparty/catch/include/internal/catch_debugger.hpp')
-rw-r--r-- | 3rdparty/catch/include/internal/catch_debugger.hpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/3rdparty/catch/include/internal/catch_debugger.hpp b/3rdparty/catch/include/internal/catch_debugger.hpp index 8c552661972..77ab29ccb4d 100644 --- a/3rdparty/catch/include/internal/catch_debugger.hpp +++ b/3rdparty/catch/include/internal/catch_debugger.hpp @@ -61,6 +61,33 @@ } } // namespace Catch +#elif defined(CATCH_PLATFORM_LINUX) + #include <fstream> + #include <string> + + namespace Catch{ + // The standard POSIX way of detecting a debugger is to attempt to + // ptrace() the process, but this needs to be done from a child and not + // this process itself to still allow attaching to this process later + // if wanted, so is rather heavy. Under Linux we have the PID of the + // "debugger" (which doesn't need to be gdb, of course, it could also + // be strace, for example) in /proc/$PID/status, so just get it from + // there instead. + bool isDebuggerActive(){ + std::ifstream in("/proc/self/status"); + for( std::string line; std::getline(in, line); ) { + static const int PREFIX_LEN = 11; + if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { + // We're traced if the PID is not 0 and no other PID starts + // with 0 digit, so it's enough to check for just a single + // character. + return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; + } + } + + return false; + } + } // namespace Catch #elif defined(_MSC_VER) extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); namespace Catch { |