mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
bpo-42923: Dump extension modules on fatal error (GH-24207)
The Py_FatalError() function and the faulthandler module now dump the list of extension modules on a fatal error. Add _Py_DumpExtensionModules() and _PyModule_IsExtension() internal functions.
This commit is contained in:
parent
f7b5bacd7a
commit
250035d134
8 changed files with 96 additions and 0 deletions
|
@ -2,6 +2,7 @@ from contextlib import contextmanager
|
|||
import datetime
|
||||
import faulthandler
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -329,6 +330,24 @@ class FaultHandlerTests(unittest.TestCase):
|
|||
"%r is present in %r" % (not_expected, stderr))
|
||||
self.assertNotEqual(exitcode, 0)
|
||||
|
||||
@skip_segfault_on_android
|
||||
def test_dump_ext_modules(self):
|
||||
code = """
|
||||
import faulthandler
|
||||
faulthandler.enable()
|
||||
faulthandler._sigsegv()
|
||||
"""
|
||||
stderr, exitcode = self.get_output(code)
|
||||
stderr = '\n'.join(stderr)
|
||||
match = re.search('^Extension modules:(.*)$', stderr, re.MULTILINE)
|
||||
if not match:
|
||||
self.fail(f"Cannot find 'Extension modules:' in {stderr!r}")
|
||||
modules = set(match.group(1).strip().split(', '))
|
||||
# Only check for a few extensions, the list doesn't have to be
|
||||
# exhaustive.
|
||||
for ext in ('sys', 'builtins', '_io', 'faulthandler'):
|
||||
self.assertIn(ext, modules)
|
||||
|
||||
def test_is_enabled(self):
|
||||
orig_stderr = sys.stderr
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue