Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use gdb when I'm using a debug version of Python?

Tags:

python

gdb

My version of gdb is linked against my system python, but I am currently working with a special debug build of python. Hence, gdb fails to launch correctly, with errors like this:

$ gdb
gdb: Symbol `_Py_ZeroStruct' has different size in shared object, consider re-linking
gdb: Symbol `PyBool_Type' has different size in shared object, consider re-linking
gdb: Symbol `_Py_NotImplementedStruct' has different size in shared object, consider re-linking
gdb: Symbol `PyFloat_Type' has different size in shared object, consider re-linking
gdb: Symbol `_Py_TrueStruct' has different size in shared object, consider re-linking
gdb: Symbol `_Py_NoneStruct' has different size in shared object, consider re-linking
Segmentation fault

...or maybe errors like this:

gdb: symbol lookup error: gdb: undefined symbol: PyUnicodeUCS4_FromEncodedObject

How can I use gdb even though a non-system version of Python exists on my LD_LIBRARY_PATH?

like image 473
Stuart Berg Avatar asked Oct 29 '25 23:10

Stuart Berg


1 Answers

I found the answer in the rootpy Documentation:

The way around this is to preload the correct library by setting LD_PRELOAD, and then unsetting it before your program is executed. For example, this will debug my-program-to-debug:

LD_PRELOAD=/usr/lib/libpython2.7.so gdb -ex 'set environ LD_PRELOAD' --args my-program-to-debug

Note that you need to set LD_PRELOAD to the right version of python that gdb was compiled against, which you can find with ldd $(which gdb) from a fresh environment.

like image 98
Stuart Berg Avatar answered Nov 01 '25 13:11

Stuart Berg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!