From 6ad2f7ae2428e5fe4101eaec6c48de497cc04c50 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 5 Jul 2015 16:11:30 -0700 Subject: [PATCH] Fix ErrorAssert handling to allow bypassing the assert if we're attached to a debugger --- Sources/Plasma/CoreLib/HeadSpin.cpp | 22 +++++++++++++++++----- Sources/Plasma/CoreLib/HeadSpin.h | 5 +++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index 5dc94413..bbb46fb6 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -135,16 +135,13 @@ void ErrorAssert(int line, const char* file, const char* fmt, ...) if (s_GuiAsserts) { if (_CrtDbgReport(_CRT_ASSERT, file, line, NULL, msg)) - DebugBreak(); + DebugBreakAlways(); } else #endif // _MSC_VER { char str[] = "-------\nASSERTION FAILED:\nFile: %s Line: %i\nMessage: %s\n-------"; DebugMsg(str, file, line, msg); - DebugBreakIfDebuggerPresent(); - - // In case the debug trap is ignored - abort(); + DebugBreakAlways(); } #endif // HS_DEBUGGING #else @@ -191,8 +188,23 @@ void DebugBreakIfDebuggerPresent() // Debugger not present or some such shwiz. // Whatever. Don't crash here. } +#elif defined(HS_BUILD_FOR_UNIX) + if (DebugIsDebuggerPresent()) + raise(SIGTRAP); +#else + // FIXME +#endif // _MSC_VER +} + +void DebugBreakAlways() +{ +#if defined(_MSC_VER) + DebugBreak(); #elif defined(HS_BUILD_FOR_UNIX) raise(SIGTRAP); +#else + // FIXME + abort(); #endif // _MSC_VER } diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 9a4d567a..5ec7725a 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -374,8 +374,9 @@ hsDebugMessageProc hsSetStatusMessageProc(hsDebugMessageProc newProc); void ErrorEnableGui (bool enabled); void ErrorAssert (int line, const char* file, const char* fmt, ...); -bool DebugIsDebuggerPresent (); -void DebugBreakIfDebuggerPresent (); +bool DebugIsDebuggerPresent(); +void DebugBreakIfDebuggerPresent(); +void DebugBreakAlways(); void DebugMsg(const char* fmt, ...); #ifdef HS_DEBUGGING