]> granicus.if.org Git - nethack/commitdiff
Add stopping in the debugger when nhassert() is hit in the windows port.
authorBart House <bart@barthouse.com>
Sat, 13 Jul 2019 23:00:14 +0000 (16:00 -0700)
committerBart House <bart@barthouse.com>
Mon, 19 Oct 2020 22:56:49 +0000 (15:56 -0700)
When stopping in the debugger after having called impossible, the windowing
state will have been modified since the assertion was hit.  This made
examining state that caused the nhassert to fire no longer possible.
To avoid this issue, we now detect the debugger and stop in the debugger
prior to impossible.

sys/winnt/winnt.c

index 09ee0c9b48c7805a761e9e4389628b4d0625d1e2..f34a68397528eb3e5905220ba6ae42079340a3df 100644 (file)
@@ -726,9 +726,19 @@ nt_assert_failed(expression, filepath, line)
 {
     const char * filename;
 
-    /* get file name from path */
     filename = strrchr(filepath, '\\');
     filename = (filename == NULL ? filepath : filename + 1);
+
+    if (IsDebuggerPresent()) {
+        char message[BUFSIZ];
+        snprintf(message, sizeof(message), 
+            "nhassert(%s) failed in file '%s' at line %d",
+            expression, filename, line);
+        OutputDebugStringA(message);
+        DebugBreak();
+    }
+
+    /* get file name from path */
     impossible("nhassert(%s) failed in file '%s' at line %d",
                 expression, filename, line);
 }