4

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Quick followup: For some reason, I have to load the module python-2.7.6/Tools/gdb/libpython.py (from the downloaded tarball) to my sys.path or else special python commands like py-bt etc. commands aren't available. (Undefined command: "py-bt". Try "help".) One way to do load that module can be seen in this answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.