#+TITLE: Python GDB
There's a significant amount of documentation of using GDB on the
Python wiki: but first, I need to get debug symbols for Python on Arch
linux.
* Getting debug symbols for Arch linux (abandoned)
The Arch Wiki has a lot of helpful documentation about this (as
expected), which recommends doing a custom package build:
#+begin_src sh
pacman -S asp asp checkout python
cp -r python/repos/repo-x86_64/PKGBUILD python-dbg
#+end_src
Added options\=(debug !strip) to the file to retain debug symbols.
Finally, to do makepkg I also had to download some dependencies (one
of which, deliciously, was GDB). I also had to accept the GPG key for
python, which is a slightly scary experience; I wonder if I could
simply have built my python checkout instead.
#+begin_src sh
makepkg
#+end_src
Kicked off the actual build for python, which I expect to take some
time and a significant number of cycles. The compilation ultimately
failed with a failed ncurses test; and I can't say I'm excited about
debugging those.
* Simply building python locally
Cloning and building python master was far simpler and more
convenient, nicely documented on the cpython devguide.
#+begin_src sh
./configure --with-pydebug
make -j4
#+end_src
Building also generates the magical python-gdb.py file in the root
directory, which extends GDB's with python to pretty print
python. This is also conveniently documented in the devguide.
DebuggingWithGDB discusses how to actually run a python program under
GDB.
#+begin_src sh
gdb python
run <program>.py
#+end_src
* The python-gdb.py extension
* Other references
** Py-spy looks fascinating, and might be something I want to play with.
https://github.com/benfred/py-spy