Skip to content

Instantly share code, notes, and snippets.

@splbio
Last active August 29, 2015 14:23
Show Gist options
  • Save splbio/58519a96b0ae72577975 to your computer and use it in GitHub Desktop.
Save splbio/58519a96b0ae72577975 to your computer and use it in GitHub Desktop.
How to get python stacktraces in gdb on FreeBSD
# First build the python package with DEBUG, and then install the resulting python-gdb.py script into a place where gdb will find it.
/usr/ports/lang/python27 # make config OPTIONS_FILE_SET=DEBUG
/usr/ports/lang/python27 # find . -name python-gdb.py
./work/Python-2.7.8/python-gdb.py
cp ./work/Python-2.7.8/python-gdb.py \
/usr/local/bin/python2.7-gdb.py
# Now install gdb with python support:
/usr/ports/devel/gdb # make config OPTIONS_FILE_SET=PYTHON
# Then run your script:
gdb78 --args /usr/local/bin/python ~alfred/t.py
GNU gdb (GDB) 7.8 [GDB v7.8 for FreeBSD]
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-portbld-freebsd10.1".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/local/bin/python...done.
(gdb) run
Starting program: /usr/local/bin/python /home/alfred/t.py
^C[New Thread 802006400 (LWP 100848)]
Program received signal SIGINT, Interrupt.
[Switching to Thread 802006400 (LWP 100848)]
0x0000000800b886c2 in PyEval_EvalFrameEx (
f=Frame 0x800806250, for file /home/alfred/t.py, line 4, in deep (x=28),
throwflag=0) at Python/ceval.c:1139
1139 PUSH(x);
(gdb) py-bt
#0 Frame 0x800806250, for file /home/alfred/t.py, line 4, in deep (x=28)
if x < 50:
#3 Frame 0x800806060, for file /home/alfred/t.py, line 5, in deep (x=27)
deep(x+1)
#6 Frame 0x8007b3df0, for file /home/alfred/t.py, line 5, in deep (x=26)
deep(x+1)
#9 Frame 0x8007b3c00, for file /home/alfred/t.py, line 5, in deep (x=25)
deep(x+1)
#12 Frame 0x8007b3a10, for file /home/alfred/t.py, line 5, in deep (x=24)
deep(x+1)
#15 Frame 0x8007b3820, for file /home/alfred/t.py, line 5, in deep (x=23)
deep(x+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment