Search code examples
pythongdb

Can't enable py-bt for gdb


I have downloaded and compiled Python 3.5 on a CentOS 6.5 machine. It works without problems. The problem is I have to use gdb to debug a subtle bug involving cpu overuse during my python program execution.

From official Python documentation about gdb extension, they says the only thing to do is to add

add-auto-load-safe-path /path/to/dir/with/python-gdb.py

to ~/.gdbinit. I tested it with

gdb --args /path/to/python3.5/binary
(gdb) py-bt

but I get

Undefined command: "py-bt"

gdb is version 7.2 and have python support enabled.


Solution

  • Found it! You must add /PATH_TO_PYTHON_SRC/Tools/gdb to PYTHONPATH, then in gdb you should be able to execute:

    python import libpython
    

    Source: https://web.archive.org/web/20141105062553/http://sumitkgaur.wordpress.com/2014/05/13/python-debugging/