]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-30557: faulthandler now correctly filters and displays exception codes on Windows...
authorSteve Dower <steve.dower@microsoft.com>
Mon, 5 Jun 2017 22:54:15 +0000 (15:54 -0700)
committerGitHub <noreply@github.com>
Mon, 5 Jun 2017 22:54:15 +0000 (15:54 -0700)
* bpo-30557: faulthandler now correctly filters and displays exception codes on Windows

* Adds test for non-fatal exceptions.

* Adds bpo number to comment.

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

index 626e2458dcd9a665e98b21c211a24f18c146d735..c965d67db3437dee91abba9da288adb40ad13543 100644 (file)
@@ -754,6 +754,32 @@ class FaultHandlerTests(unittest.TestCase):
                 3,
                 name)
 
+    @unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
+    def test_raise_nonfatal_exception(self):
+        # These exceptions are not strictly errors. Letting
+        # faulthandler display the traceback when they are
+        # raised is likely to result in noise. However, they
+        # may still terminate the process if there is no
+        # handler installed for them (which there typically
+        # is, e.g. for debug messages).
+        for exc in (
+            0x00000000,
+            0x34567890,
+            0x40000000,
+            0x40001000,
+            0x70000000,
+            0x7FFFFFFF,
+        ):
+            output, exitcode = self.get_output(f"""
+                import faulthandler
+                faulthandler.enable()
+                faulthandler._raise_exception(0x{exc:x})
+                """
+            )
+            self.assertEqual(output, [])
+            # Actual exception code has bit 4 cleared
+            self.assertEqual(exitcode, exc & ~0x10000000)
+
     @unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
     def test_disable_windows_exc_handler(self):
         code = dedent("""
index e6e8f95f4653bad045b9d04e0a9759af01b5111d..1b5794b44f1c0c57df96e449a6024edbd43c0ad4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -345,6 +345,9 @@ Extension Modules
 Library
 -------
 
+- bpo-30557: faulthandler now correctly filters and displays exception codes
+  on Windows
+
 - bpo-30526: Add TextIOWrapper.reconfigure() and a TextIOWrapper.write_through
   attribute.
 
index dcfebf2781f6c93fc4661bf47adb00d562e4d3b4..39b70bcf3a10b4a9349d784d719e2fd53e24e0c7 100644 (file)
@@ -373,8 +373,8 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
     DWORD code = exc_info->ExceptionRecord->ExceptionCode;
     DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;
 
-    /* only log fatal exceptions */
-    if (flags & EXCEPTION_NONCONTINUABLE) {
+    /* bpo-30557: only log fatal exceptions */
+    if (!(code & 0x80000000)) {
         /* call the next exception handler */
         return EXCEPTION_CONTINUE_SEARCH;
     }
@@ -391,8 +391,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 ");
-        _Py_DumpDecimal(fd, code);
+        PUTS(fd, "code 0x");
+        _Py_DumpHexadecimal(fd, code, 8);
     }
     PUTS(fd, "\n\n");