faulthandler: only log fatal exceptions
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 13:44:14 +0000 (14:44 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 13:44:14 +0000 (14:44 +0100)
Issue #23848, #26622:

* faulthandler now only logs fatal Windows exceptions.
* write error code as decimal, not as hexadecimal
* replace "Windows exception" with "Windows fatal exception"

Lib/test/test_faulthandler.py
Modules/faulthandler.c

index fbd535b9f93bf1ad001cb0ac500d172b2cb900e7..a3a211667fb9362fcc23d928d72e7bf4f7c95cc0 100644 (file)
@@ -115,7 +115,7 @@ class FaultHandlerTests(unittest.TestCase):
         self.check_error(code, line_number, fatal_error, **kw)
 
     def check_windows_exception(self, code, line_number, name_regex, **kw):
-        fatal_error = 'Windows exception: %s' % name_regex
+        fatal_error = 'Windows fatal exception: %s' % name_regex
         self.check_error(code, line_number, fatal_error, **kw)
 
     @unittest.skipIf(sys.platform.startswith('aix'),
index 22144661bc7fa3db1c78fbea18bc485f9fa1f695..e86f2bbc847bb162faf99d7474ad04fa293d4606 100644 (file)
@@ -367,8 +367,15 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
 {
     const int fd = fatal_error.fd;
     DWORD code = exc_info->ExceptionRecord->ExceptionCode;
+    DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;
 
-    PUTS(fd, "Windows exception: ");
+    /* only log fatal exceptions */
+    if (flags & EXCEPTION_NONCONTINUABLE) {
+        /* call the next exception handler */
+        return EXCEPTION_CONTINUE_SEARCH;
+    }
+
+    PUTS(fd, "Windows fatal exception: ");
     switch (code)
     {
     /* only format most common errors */
@@ -380,8 +387,8 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
     case EXCEPTION_IN_PAGE_ERROR: PUTS(fd, "page error"); break;
     case EXCEPTION_STACK_OVERFLOW: PUTS(fd, "stack overflow"); break;
     default:
-        PUTS(fd, "code 0x");
-        _Py_DumpHexadecimal(fd, code, sizeof(DWORD));
+        PUTS(fd, "code ");
+        _Py_DumpDecimal(fd, code, sizeof(DWORD));
     }
     PUTS(fd, "\n\n");