GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #127604

New issue
Copy link
New issue
Copy link
Closed
Closed
Add a way of printing a C backtrace to faulthandler#127604
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

Description

@jakkdl
jakkdl
opened on Dec 4, 2024
Issue body actions

Feature 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

  • gh-127604: Add C stack dumps to faulthandler #128159
  • gh-127604: Don't rely on dprintf() for faulthandler C stacks #132800
  • gh-127604: Fix refleak in faulthandler_dump_c_stack_py() #132840
  • gh-127604: Allow faulthandler to dumpC stack on MacOS #132841
  • gh-127604: Replace dprintf() with _Py_write_noraise() #132854
  • gh-127604: Only define dump_pointer() if CAN_C_BACKTRACE #132897
  • gh-127604: ensure -ldl is passed to the linker when dladdr1 is found #133040
  • gh-127604: ensure -ldl is passed only once to the linker #133071
  • gh-127604: Optimize -ldl usage on platforms that use dlopen for libFFI. #133081
  • gh-127604: Docs: Include a C stack in the faulthandler example #136081
  • [3.14] gh-127604: Docs: Include a C stack in the faulthandler example (GH-136081) #136102
Reacted by Gregory P. Smith and Daniel Colascione
Reacted by Freya Bruhin

Activity

Next
  1. jakkdl
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Dec 4, 2024
  2. ZeroIntensity commented on Dec 7, 2024

    @ZeroIntensity
    ZeroIntensity
    on Dec 7, 2024
    Member
    More actions

    Would you like to submit the starting PR?

  3. picnixz
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Dec 7, 2024
  4. jakkdl commented on Dec 9, 2024

    @jakkdl
    jakkdl
    on Dec 9, 2024
    Author
    More actions

    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.

  5. ZeroIntensity commented on Dec 21, 2024

    @ZeroIntensity
    ZeroIntensity
    on Dec 21, 2024
    Member
    More actions

    I went ahead and tried this myself: #128159

    Reacted by John Litborn
  6. gpshead commented on Apr 21, 2025

    @gpshead
    gpshead
    on Apr 21, 2025
    Member
    More actions

    For future reference as I expect people may want something better in the future beyond what we're able to provide via this issue: https://github.com/abseil/abseil-cpp/tree/master/absl/debugging has code that does a nice job of emitting symbolized C/C++/Rust stack traces on failure. Also: a lot more complicated.

  7. pablogsal
    added a commit that references this issue on Apr 21, 2025

    gh-127604: Add C stack dumps to `faulthandler` (#128159)

    8dfa840
  8. pablogsal commented on Apr 21, 2025

    @pablogsal
    pablogsal
    on Apr 21, 2025
    Member
    More actions

    We do a similar thing in https://github.com/bloomberg/pystack where we have a custom DWARF parser. Also: a lot more complcated as well :)

  9. serhiy-storchaka commented on Apr 22, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Apr 22, 2025
    Member
    More actions

    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
    
  10. ZeroIntensity commented on Apr 22, 2025

    @ZeroIntensity
    ZeroIntensity
    on Apr 22, 2025
    Member
    More actions

    Will put up a fix later today.

  11. kulikjak commented on Apr 23, 2025

    @kulikjak
    kulikjak
    on Apr 23, 2025
    Contributor
    More actions

    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.

  12. ZeroIntensity commented on Apr 23, 2025

    @ZeroIntensity
    ZeroIntensity
    on Apr 23, 2025
    Member
    More actions

    I'd like to prevent conflicts, so feel free to make a PR once #132800 gets merged.

    Reacted by Jakub Kulík
  13. vstinner
    added a commit that references this issue on Apr 23, 2025

    pythongh-127604: Fix refleak in faulthandler_dump_c_stack_py()

    e8d5805
  14. pablogsal
    added a commit that references this issue on Apr 23, 2025

    pythongh-127604: Allow faulthandler to dumpC stack on MacOS

    75e05b8
  15. vstinner
    added a commit that references this issue on Apr 23, 2025

    gh-127604: Fix refleak in faulthandler_dump_c_stack_py() (#132840)

    1aaca7a
  16. 11 remaining items

  17. picnixz
    added 2 commits that reference this issue on Apr 27, 2025

    gh-127604: ensure `-ldl` is passed to the linker when `dladdr1` is fo…

    2443662

    gh-127604: ensure `-ldl` is passed only once to the linker (#133071)

    af3f6fc
  18. freakboy3742
    added a commit that references this issue on Apr 30, 2025

    gh-127604: Optimize -ldl usage on platforms that use dlopen for libFF…

    58a0f40
  19. pablogsal
    closed this as completedon May 5, 2025
  20. pablogsal commented on May 5, 2025

    @pablogsal
    pablogsal
    on May 5, 2025
    Member
    More actions

    Closing for now, if you want to reopen feel free to do that

  21. ZeroIntensity
    added a commit that references this issue on Jun 29, 2025

    gh-127604: Docs: Include a C stack in the `faulthandler` example (GH-…

    3947847
  22. miss-islington
    added a commit that references this issue on Jun 29, 2025

    pythongh-127604: Docs: Include a C stack in the `faulthandler` example (

    735f775
  23. ZeroIntensity
    added a commit that references this issue on Jun 29, 2025

    [3.14] gh-127604: Docs: Include a C stack in the `faulthandler` examp…

    231d801
  24. AndPuQing
    added a commit that references this issue on Jul 11, 2025

    pythongh-127604: Docs: Include a C stack in the `faulthandler` example (

    c74b91b
  25. Pranjal095
    added a commit that references this issue on Jul 12, 2025

    pythongh-127604: Docs: Include a C stack in the `faulthandler` example (

    7fde5da
  26. picnixz
    added a commit that references this issue on Jul 13, 2025

    pythongh-127604: Docs: Include a C stack in the `faulthandler` example (

    9d489ee
  27. taegyunkim
    added a commit that references this issue on Aug 4, 2025

    pythongh-127604: Docs: Include a C stack in the `faulthandler` example (

    47cddbe
  28. Agent-Hellboy
    added a commit that references this issue on Aug 19, 2025

    pythongh-127604: Docs: Include a C stack in the `faulthandler` example (

    ae6401b
  29. The-Compiler commented on Nov 2, 2025

    @The-Compiler
    The-Compiler
    on Nov 2, 2025
    Contributor
    More actions

    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
  30. pablogsal commented on Nov 3, 2025

    @pablogsal
    pablogsal
    on Nov 3, 2025
    Member
    More actions

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.