-
Notifications
You must be signed in to change notification settings - Fork 7
Debugging Python SegFault with gdb
Louis Maddox edited this page Nov 10, 2017
·
3 revisions
-
here's a tutorial (PDF, 21 pages) via U. Maryland ⠶ Samuel Huang — CMSC212: Introduction to Low-Level Programming Concepts
- gives an idea of the program [but more intended toward use with C rather than Python]
- "How to interpret a gdb backtrace
- StackOverflow question (about C++, not Python[/Cython])
- Official Python dev guide: gdb Support
- wiki.python.org ⠶ DebuggingWithGdb
- make a python file e.g.
segger.py
which causes the segfault - [in a terminal] run
gdb python
- N.B. - this just worked for me, there's mention online of needing to recompile with gdb support on some systems
- in the interactive gdb session, type
run segger.py
[or whatever you called your script], to give something like:
Starting program: /home/myusername/anaconda3/bin/python segger.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff12ab700 (LWP 12345)]
[New Thread 0x7ffff89yz700 (LWP 12346)]
…
[New Thread 0x7ffff89yz700 (LWP 12350)]
Program received signal SIGSEGV, Segmentation fault.
Capitalised_Snake_Case_Ref_1 (a=0x123f4567890a1b23, b=0x7fffabfcdf00 <sipVoidPtr_Type>) at Path/to.c:1343
1234 Path/to.c: {Error message goes here}.
(gdb)
- where:
-
anaconda3
may differ if you're not using an anaconda3 installation - number of threads may vary based on your system
-
Capitalised_Snake_Case_Ref_1
andsipVoidPtr_Type
refer to a function in cpython and variable in C respectively- you can search for the function in github.com/python/cpython/
e.g.
PyType_IsSubtype
at Objects/typeobject.c ⠶ line 1386 though note that line numbers on the repo may differ since your installation was released [releases are tagged] - N.B. the "sip" refers to "Sessions Initiation Protocol" (SIP), see riverbankcomputing.com ⠶ intro and wiki.python.org ⠶ SIP
- you can search for the function in github.com/python/cpython/
e.g.
-