python debug with gdb
添加时间:2013-5-7 点击量:
1,一般的景象下可以用python自带的debug包pdb来debug一个简单的routine。
用法如下:
python -m pdb /path/script_name.py
[root@cdntest-2 ~]# python -m pdb gdb.py
> /root/gdb.py(1)<module>()
-> import sys
(Pdb) help
Documented commands (type help <topic>):
========================================
EOF bt cont enable jump pp run unt
a c continue exit l q s until
alias cl d h list quit step up
args clear debug help n r tbreak w
b commands disable ignore next restart u whatis
break condition down j p return unalias where
Miscellaneous help topics:
==========================
exec pdb
Undocumented commands:
======================
retval rv
(Pdb)
然则一些bug很难用这种python自带的debug模块来进行调试,比如如下的几种:
1,段错误(不是没有捕获的python Exception)
2,挂起的过程(这种景象是不成能是debug with python -m pdb的)
3,失控的守护过程(coredump)
碰着这些类似的景象,那么我们就须要更强大的debug对象GDB了。
2,gdb python
有两种办法来attach gdb 到 python 过程
1,在gdb的景象下运行python法度,比及题目产生
[root@cdntest-2 jenkins]# gdb python
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5)
Copyright (C) 2009 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-redhat-linux-gnu.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols /usr/local/bin/python...done.
(gdb) run script_name.py [argv]
这会运行这个法度直到它停止,或者碰着段错误或者终止这个法度(ctrl+c)
2,attach 住python的过程号
gdb python [pid of python process]
attach 一个过程就像让这个过程停止一样,你可以让它持续运行。
项目组内容参考自python官网:http://wiki.python.org/moin/DebuggingWithGdb
我们永远不要期待别人的拯救,只有自己才能升华自己。自己已准备好了多少容量,方能吸引对等的人与我们相遇,否则再美好的人出现、再动人的事情降临身边,我们也没有能量去理解与珍惜,终将擦肩而过。—— 姚谦《品味》