問題描述
我想使用 gdb 7 的支持來調(diào)試 Python劣質(zhì)進(jìn)程".
我需要什么才能做到這一點(diǎn)?
例如:
運(yùn)行劣質(zhì) Python 的配置腳本需要使用哪些標(biāo)志?
低級(jí) Python 進(jìn)程是否必須是 Python 2.7 或更高版本(我看到那是 Python 源代碼樹中的 gdb 支持的部分提交的時(shí)候)?還是只有 gdb 進(jìn)程本身需要 Python 2.7?
需要安裝哪些文件可能不會(huì)被所有發(fā)行版打包?例如,在 packages.ubuntu.com 上我沒有得到任何關(guān)于 python-gdb.py 的點(diǎn)擊,我認(rèn)為這是需要的.
了解特定發(fā)行版的需求會(huì)非常方便.我對(duì) Ubuntu 和 Centos 的需求特別感興趣.
Python好像需要用--with-pydebug
編譯(在Ubuntu 12.04上,包python-dbg
包含一個(gè)合適的 Python 可執(zhí)行文件,它本身稱為 python-dbg
).劣質(zhì)的 Python 不需要是 Python 2.7 -- 2.6 可以成功加載 2.7 gdb 擴(kuò)展(請(qǐng)參閱下面的調(diào)試會(huì)話).至少在 Ubuntu 12.04 上,安裝的定義 gdb 擴(kuò)展的文件稱為 libpython.py
,而不是 python-gdb.py
(出于某種原因,構(gòu)建 Python 會(huì)產(chǎn)生包含這兩個(gè)文件的構(gòu)建目錄——它們是相同的).
但是,我認(rèn)為目前無法使用生產(chǎn)核心文件進(jìn)行調(diào)試:看起來 Python 劣等進(jìn)程的 gdb 擴(kuò)展試圖獲取在生產(chǎn)二進(jìn)制文件中得到優(yōu)化的變量(例如,fPyEval_EvalFrameEx
中的變量).似乎 Linux/gdb 和 Python 尚未達(dá)到在 Illumos 上實(shí)現(xiàn) JavaScript 的出色水平,Bryan Cantrill 在這里報(bào)告說能夠以這種方式調(diào)試生產(chǎn)核心轉(zhuǎn)儲(chǔ):
http://www.infoq.com/presentations/Debugging-Production-Systemsp>
這是 Ubuntu 12.04 上的調(diào)試會(huì)話,顯示 gdb 使用 Python 2.7 的 gdb 擴(kuò)展運(yùn)行 Python 2.6 次等進(jìn)程來調(diào)試段錯(cuò)誤.首先是導(dǎo)致段錯(cuò)誤的代碼:
~/Downloads/Python-2.6.4$ cat ~/bin/dumpcore.pyFoo類:定義欄(自我):從 ctypes 導(dǎo)入 string_atstring_at(0xDEADBEEF) # 此代碼將導(dǎo)致 Python 出現(xiàn)段錯(cuò)誤定義主():f = Foo()f.someattr = 42f.someotherattr = {'one':1, 'two':2L, 'three':[(), (None,), (None, None)]}f.bar()如果 __name__ == "__main__":主要的()
和調(diào)試會(huì)話:
~/Downloads/Python-2.6.4$ gdb --args ./python ~/bin/dumpcore.pyGNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04版權(quán)所有 (C) 2012 Free Software Foundation, Inc.許可證 GPLv3+:GNU GPL 版本 3 或更高版本 <http://gnu.org/licenses/gpl.html>這是免費(fèi)軟件:您可以自由更改和重新分發(fā)它.在法律允許的范圍內(nèi),不提供任何保證.輸入顯示復(fù)制"和顯示保修"了解詳情.此 GDB 配置為x86_64-linux-gnu".有關(guān)錯(cuò)誤報(bào)告說明,請(qǐng)參閱:<http://bugs.launchpad.net/gdb-linaro/>...從/home/john/Downloads/Python-2.6.4/python...讀取符號(hào)...完成.(gdb) 運(yùn)行啟動(dòng)程序:/home/john/Downloads/Python-2.6.4/python/home/john/bin/dumpcore.py[啟用使用 libthread_db 進(jìn)行線程調(diào)試]使用主機(jī) libthread_db 庫(kù)/lib/x86_64-linux-gnu/libthread_db.so.1".程序收到信號(hào) SIGSEGV,分段錯(cuò)誤.0x0000000000468d67 in PyString_FromString (str=0xdeadbeef <Address 0xdeadbeef out of bounds>) at Objects/stringobject.c:116116 大小 = strlen(str);(gdb) py-bt未定義的命令:py-bt".試試幫助".(gdb) 蟒蛇>導(dǎo)入系統(tǒng)>sys.path.insert(0, "/home/john/Downloads/Python-2.7/Tools/gdb")>導(dǎo)入 libpython>(gdb) py-bt#10 幀 0x8f0f90,用于文件/home/john/Downloads/Python-2.6.4/Lib/ctypes/__init__.py,第 496 行,在 string_at 中(ptr=3735928559,size=-1)返回 _string_at(ptr, 大小)#14 幀 0x8ebf90,用于文件/home/john/bin/dumpcore.py,第 5 行,in bar (self=<Foo(someattr=42, someotherattr={'three': [(), (None,),(None, None)], 'two': 2L, 'one': 1}) 在遠(yuǎn)程 0x7ffff6e03240>, string_at=)string_at(0xDEADBEEF) # 此代碼將導(dǎo)致 Python 出現(xiàn)段錯(cuò)誤#17 幀 0x8ebd80,用于文件/home/john/bin/dumpcore.py,第 12 行,在 main (f=<Foo(someattr=42, someotherattr={'three': [(), (None,),(None, None)], 'two': 2L, 'one': 1}) 在遠(yuǎn)程 0x7ffff6e03240>)f.bar()#20 幀 0x8eb680,用于文件/home/john/bin/dumpcore.py,第 16 行,在 <module>()主要的()(gdb)
I'd like to use gdb 7's support for debugging Python "inferior processes".
What do I need to be able to do that?
For example:
What flags does the inferior Python's configure script need to have been run with?
Does the inferior Python process have to be Python 2.7 or newer (I see that's when the part of the gdb support for this that's in Python source tree was committed)? Or is Python 2.7 only needed by the gdb process itself?
What files need to have been installed that might not be packaged by all distributions? For example, on packages.ubuntu.com I don't get any hits for python-gdb.py, which I believe is needed.
It would be very handy to know what's needed on particular distributions. I am particularly interested in what's needed for Ubuntu and Centos.
Python seems to need to have been compiled with --with-pydebug
(on Ubuntu 12.04, package python-dbg
contains a suitable Python executable, itself called python-dbg
). The inferior Python does not need to be Python 2.7 -- 2.6 loads the 2.7 gdb extensions successfully (see the debugging session below). At least on Ubuntu 12.04, the file that gets installed that defines the gdb extensions is called libpython.py
, not python-gdb.py
(for some reason, building Python yields a build directory containing both those files -- they are identical).
However, I don't think it's currently possible to debug using production core files: it looks like the gdb extensions for Python inferior processes try to get hold of variables that get optimized away in a production binary (for example, the f variable in PyEval_EvalFrameEx
). It seems Linux / gdb, and Python has yet to reach the level of awesomeness achieved for JavaScript on Illumos which Bryan Cantrill reports here is able to debug production core dumps in this way:
http://www.infoq.com/presentations/Debugging-Production-Systems
Here's the debug session on Ubuntu 12.04 showing gdb running a Python 2.6 inferior process to debug a segfault, using Python 2.7's gdb extensions. First the code to cause the segfault:
~/Downloads/Python-2.6.4$ cat ~/bin/dumpcore.py
class Foo:
def bar(self):
from ctypes import string_at
string_at(0xDEADBEEF) # this code will cause Python to segfault
def main():
f = Foo()
f.someattr = 42
f.someotherattr = {'one':1, 'two':2L, 'three':[(), (None,), (None, None)]}
f.bar()
if __name__ == "__main__":
main()
and the debugging session:
~/Downloads/Python-2.6.4$ gdb --args ./python ~/bin/dumpcore.py
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 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-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/john/Downloads/Python-2.6.4/python...done.
(gdb) run
Starting program: /home/john/Downloads/Python-2.6.4/python /home/john/bin/dumpcore.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000468d67 in PyString_FromString (str=0xdeadbeef <Address 0xdeadbeef out of bounds>) at Objects/stringobject.c:116
116 size = strlen(str);
(gdb) py-bt
Undefined command: "py-bt". Try "help".
(gdb) python
>import sys
>sys.path.insert(0, "/home/john/Downloads/Python-2.7/Tools/gdb")
>import libpython
>(gdb) py-bt
#10 Frame 0x8f0f90, for file /home/john/Downloads/Python-2.6.4/Lib/ctypes/__init__.py, line 496, in string_at (ptr=3735928559, size=-1)
return _string_at(ptr, size)
#14 Frame 0x8ebf90, for file /home/john/bin/dumpcore.py, line 5, in bar (self=<Foo(someattr=42, someotherattr={'three': [(), (None,), (None, None)], 'two': 2L, 'one': 1}) at remote 0x7ffff6e03240>, string_at=<function at remote 0x7ffff6e1c990>)
string_at(0xDEADBEEF) # this code will cause Python to segfault
#17 Frame 0x8ebd80, for file /home/john/bin/dumpcore.py, line 12, in main (f=<Foo(someattr=42, someotherattr={'three': [(), (None,), (None, None)], 'two': 2L, 'one': 1}) at remote 0x7ffff6e03240>)
f.bar()
#20 Frame 0x8eb680, for file /home/john/bin/dumpcore.py, line 16, in <module> ()
main()
(gdb)
這篇關(guān)于使用 gdb 7 對(duì)調(diào)試 Python 程序的支持需要什么?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!