GeezerVison is showing github.com — Add a way of printing a C backtrace to `faulthandler` · Issue #127604 · python/cpython
Add a way of printing a C backtrace to faulthandler #127604DescriptionFeature or enhancement
Proposal:
The faulthandler module allows registering a SIGSEGV handler to print a Python stacktrace if the program encounters a segfault. However, if developing C/C++ extension modules that may not be particularly useful on its own, and you also want the the C stacktrace.
The suggested API would be a kwarg to faulthandler.enable().
Implementation could use https://github.com/timmaxw/cfaulthandler as a starting point, timmaxw/cfaulthandler@561dbdd in particular.
The availability/usability of the feature would likely depend on platform and/or compile flags.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/print-c-stacktrace-with-faulthandler/56834
where @gpshead approved of opening a feature request
Linked PRs
Reacted by Gregory P. Smith and Daniel Colascione Reacted by Freya Bruhin ActivityZeroIntensity commented on Dec 7, 2024 Would you like to submit the starting PR? jakkdl commented on Dec 9, 2024
Would you like to submit the starting PR?
I might give it a try, but if anybody else wants to you're super welcome. I'm not especially well versed with faulthandler myself. ZeroIntensity commented on Dec 21, 2024 I went ahead and tried this myself: #128159 gpshead commented on Apr 21, 2025 pablogsal commented on Apr 21, 2025 serhiy-storchaka commented on Apr 22, 2025 dprintf() is not available on OpenIndiana.
Python/traceback.c: In function '_Py_backtrace_symbols_fd':
Python/traceback.c:1213:13: error: implicit declaration of function 'dprintf'; did you mean 'wprintf'? [-Wimplicit-function-declaration]
1213 | dprintf(fd, " Binary file '<unknown>' [%p]\n", array[i]);
| ^~~~~~~
| wprintf
ZeroIntensity commented on Apr 22, 2025 Will put up a fix later today. kulikjak commented on Apr 23, 2025 Hi, not sure whether this is a platform difference or some other issue, but on Oracle Solaris, I see all test_dump_c_stack/test_dump_c_stack_file fail with:
======================================================================
FAIL: test_dump_c_stack (test.test_faulthandler.FaultHandlerTests.test_dump_c_stack) (line=' Binary file "/builds/python/build/amd64/libpython3.14.so.1.0", at _PyEval_EvalFrameDefault+0x96a1 [7fe012df2091]')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builds/python/cpython-main/Lib/test/test_faulthandler.py", line 971, in check_c_stack
self.assertRegex(line, C_STACK_REGEX[1])
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Regex didn't match: '( Binary file ".+"(, at .*(\\+|-)0x[0-9a-f]+)? \\[0x[0-9a-f]+\\])|(<.+>)' not found in ' Binary file "/builds/python/build/amd64/libpython3.14.so.1.0", at _PyEval_EvalFrameDefault+0x96a1 [7fe012df2091]'
presumably because the address in square brackets is not prefixed with 0x.
When I change ADDRESS_EXPR = "0x[0-9a-f]+" to "(0x)?[0-9a-f]+", the issue goes away. ZeroIntensity commented on Apr 23, 2025 I'd like to prevent conflicts, so feel free to make a PR once #132800 gets merged. added 2 commits that reference this issue on Apr 27, 2025gh-127604: ensure `-ldl` is passed to the linker when `dladdr1` is fo… added a commit that references this issue on Apr 30, 2025gh-127604: Optimize -ldl usage on platforms that use dlopen for libFF… pablogsal commented on May 5, 2025 Closing for now, if you want to reopen feel free to do that The-Compiler commented on Nov 2, 2025 Oh wow! 🤯 I have a Python application which builts on top of a lot of C++ code (Qt/Chromium) and has an automated crash report dialog. Just got the first crash report with a C++ stacktrace, and this is nothing but amazing, makes them infinitely more useful! Thanks to everyone who was involved in this 💜. Reacted by Victor Stinner, Peter Bierma, Gregory P. Smith, Sergey Miryanov, Pablo Galindo Salgado and John Litborn pablogsal commented on Nov 3, 2025
Oh wow! 🤯 I have a Python application which builts on top of a lot of C++ code (Qt/Chromium) and has an automated crash report dialog. Just got the first crash report with a C++ stacktrace, and this is nothing but amazing, makes them infinitely more useful! Thanks to everyone who was involved in this 💜.
Thanks for taking the time to come back and report it!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|