From db7bf2b3b7012cafee486c06e7fb905f3c08eed3 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 6 Jun 2015 18:04:20 -0700 Subject: [PATCH] Added Linux check for debugger presence. --- CMakeLists.txt | 7 +++++++ Sources/Plasma/CoreLib/HeadSpin.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0d9d164..e38406e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,12 +22,19 @@ include(cmake/CompilerChecks.cmake) if(WIN32 AND NOT CYGWIN) add_definitions(-DHS_BUILD_FOR_WIN32) endif(WIN32 AND NOT CYGWIN) + if(UNIX) + # This is set for both Linux and Mac builds add_definitions(-DHS_BUILD_FOR_UNIX) endif(UNIX) + if(APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") add_definitions(-DHS_BUILD_FOR_OSX) endif(APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + add_definitions(-DHS_BUILD_FOR_LINUX) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") # End HeadSpin Configuration set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index ecac79fb..2be9e794 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -46,6 +46,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifdef _MSC_VER # include #endif + +#if defined(HS_DEBUGGING) && defined(HS_BUILD_FOR_LINUX) +# include +# include +# include +# include +#endif #pragma hdrstop #include "hsTemplates.h" @@ -139,8 +146,27 @@ void ErrorAssert(int line, const char* file, const char* fmt, ...) bool DebugIsDebuggerPresent() { -#ifdef _MSC_VER +#if defined(HS_BUILD_FOR_WIN32) return IsDebuggerPresent(); +#elif defined(HS_BUILD_FOR_LINUX) + // From http://google-perftools.googlecode.com/svn/trunk/src/heap-checker.cc + char buf[256]; // TracerPid comes relatively earlier in status output + int fd = open("/proc/self/status", O_RDONLY); + if (fd == -1) { + return false; // Can't tell for sure. + } + const int len = read(fd, buf, sizeof(buf)); + bool rc = false; + if (len > 0) { + const char* const kTracerPid = "TracerPid:\t"; + buf[len - 1] = '\0'; + const char* p = strstr(buf, kTracerPid); + if (p) { + rc = (strncmp(p + strlen(kTracerPid), "0\n", 2) != 0); + } + } + close(fd); + return rc; #else // FIXME return false;