Skip to content

Instantly share code, notes, and snippets.

Last active August 25, 2020 17:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Setting up a Python debug environment to investigate a segfaulting Python C extension

Notes on setting up a Python debug environment

Used to investigate a segfault in a Python C extension within a Python package.

  1. Install debug Python build using pyenv then check is available for use:

    pyenv install -g 3.8.5
    pyenv versions
  2. Switch to locally using that interpreter within a dir:

    cd path/to/some/repo
    pyenv local 3.8.5-debug
    which python
  3. Install certain dependencies for this project using that interpreter:

    python -m pip install cython matplotlib
  4. Edit and ensure the extra_compile_args parameter is set to ['-Wall', '-O', '-g'] for relevant setuptools.Extensions to ensure they can be (re)built with debug support.

  5. (Re)build all Python C extensions for the package:

    python clean --all
    python develop
  6. Run Python in a debugger:

    gdb -ex r --args /bin/bash python tests/

Further resources:

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