summary refs log tree commit diff
path: root/src/Common
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-04-09 02:19:37 +0200
committerMel <einebeere@gmail.com>2024-04-09 02:19:37 +0200
commit15237a469afe1fd6a6958466bae761ec68b647dc (patch)
tree9553ddfd2402c13558670b17a27cd65be404e55b /src/Common
parent3ae3891ca2698d5fd2160fbed5b780a91651a218 (diff)
downloadmeowcraft-15237a469afe1fd6a6958466bae761ec68b647dc.tar.zst
meowcraft-15237a469afe1fd6a6958466bae761ec68b647dc.zip
Send SIGABRT on Assert fail when on MinGW-w64 and debugging
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Assert.hpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Common/Assert.hpp b/src/Common/Assert.hpp
index d30e724..bbafcd6 100644
--- a/src/Common/Assert.hpp
+++ b/src/Common/Assert.hpp
@@ -4,6 +4,17 @@
 #include <cstdio>
 #include <cstring>
 
+namespace Assert::Detail {
+#ifdef _WIN32
+    // MinGW has weird behavior with SIGTRAP,
+    // and debugging won't be done on Windows anyway,
+    // so SIGABRT is used instead.
+    constexpr int DebugSignal = SIGABRT;
+#else
+    constexpr int DebugSignal = SIGTRAP;
+#endif
+}
+
 // https://stackoverflow.com/a/26100478/11342122
 // Two levels are needed to make sure that the argument is expanded before stringification
 #define _ASSERT_IS_DEFINED(x) _ASSERT_IS_DEFINED2(x)
@@ -11,7 +22,7 @@
 #define _ASSERT_IS_DEFINED2(x) (#x[0] == 0 || (#x[0] >= '1' && #x[0] <= '9'))
 
 // Stopping macro, non-fatal in debug mode
-#define _ASSERT_STOP (_ASSERT_IS_DEFINED(NDEBUG) ? std::abort() : (void)raise(SIGTRAP))
+#define _ASSERT_STOP (_ASSERT_IS_DEFINED(NDEBUG) ? std::abort() : (void)raise(Assert::Detail::DebugSignal))
 
 // Assertion message macros, with optional message
 #define _ASSERT_NOTIFY_NO_MESSAGE(start) fprintf(stderr, start ".\n", __FILE__, __LINE__)
@@ -30,4 +41,4 @@
 #define UNREACHABLE(...) do { \
     _ASSERT_NOTIFY("UNREACHABLE() reached at %s:%d", __VA_ARGS__); \
     _ASSERT_STOP; \
-} while (0)
\ No newline at end of file
+} while (0)