当我使用Python的调试版本时如何使用gdb?

时间:2014-01-06 13:51:22

标签: python gdb

我的gdb版本与我的系统python链接,但我目前正在使用python的特殊调试版本。因此,gdb无法正确启动,出现如下错误:

$ 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

......或者可能是这样的错误:

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

即使我的LD_LIBRARY_PATH上存在非系统版本的Python,我如何使用gdb?

1 个答案:

答案 0 :(得分:2)

我在rootpy Documentation中找到答案:

  

解决这个问题的方法是通过设置预加载正确的库   LD_PRELOAD,然后在程序执行之前取消设置。对于   例如,这将调试my-program-to-debug:

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

请注意,您需要将LD_PRELOAD设置为正确版本的python   那个gdb是针对编译的,你可以用ldd $找到它(哪个   gdb)来自一个新的环境。