This repository contains UDB extensions for debugging Python programs.
The extensions are built on top of the cpython GDB
library.
Clone the repository or copy the following files into your current working directory
libpython.gdblibpython.pylibpython_extensions.pylibpython_ui.pytui_windows.py
and start UDB while sourcing the libpython.gdb file from the same directory
$ udb --ex "source ./libpython.gdb"
The supported version of Python is currently cpython 3.10. The interpreter must have been compiled with full debug information (-g3) and without cpython's "computed gotos" feature.
You can use the ./setup-python script to install a suitable version of Python with pyenv:
$ source ./setup-python
$ python --version
Python 3.10.15
Use the following commands to inspect Python state:
py-print(pp) to print Python objectspy-eval(pe) to evaluate Python expressionspy-listto list Python source codepy-btto show Python backtracepy-localsto show local Python variablespy-disto list Python bytecode disassembly
Use the following commands to navigate:
py-step(pys) to step Python bytecodepy-reverse-step(pyrs) to step Python bytecode backwardspy-advance-function(pya) to continue until the next Python function callpy-reverse-advance-function(pyra) to continue backwards until the previous Python function callpy-last-attr(pyla) to search backwards or forwards until an object attribute is assigned
The py-step and py-reverse-step commands take an optional argument specifying the Python bytecode opcode to step until.
The py-advance-function and py-reverse-advance-function commands take an optional argument specifying which function to advance to.
The py-last-attr command takes an optional argument to specify which attribute name to search for.
Switch to the Python layout in TUI mode to get a better overview of your program.
> layout python
If your Python source code does not show up you might have to use the py-substitute-path command
to inform the debugger about the location of your local checkout of the Python source code.