python的断点调试(转自:http://control.blog.sina.com.cn/admin/article/article_add.php)
清晰一点的文章:
http://blog.chinaunix.net/uid-26058276-id-1741956.html
首先你选择运行的 py
python -m pdb myscript.py
(Pdb) 会自动停在第一行,等待调试,这时你可以看看 帮助
(Pdb) h
说明下这几个关键 命令>断点设置
(Pdb)b 10 #断点设置在本py的第10行
或(Pdb)b ots.py:20 #断点设置到 ots.py第20行
删除断点(Pdb)b #查看断点编号
(Pdb)cl 2 #删除第2个断点
>运行
(Pdb)n #单步运行
(Pdb)s #细点运行 也就是会下到,方法
(Pdb)c #跳到下个断点
>查看
(Pdb)p param #查看当前 变量值
(Pdb)l #查看运行到某处代码
(Pdb)a #查看全部栈内变量>如果是在 命令行里的调试为:
import pdb
def tt():
pdb.set_trace()
for i in range(1, 5):
print i>>> tt()
#这里支持 n p c 而已
> <stdin>(3)tt()
(Pdb) n
--------------------------------------------------------
附一些有用的调试命令:
w(here) 显式当前堆栈结构。往下的是新的,就像X86构架中的那样。
d(own) 移向新的一帧
u(p) 移向旧的一帧
b(reak) [([filename:]lineno | function) [, condition] ]
如果没有指定文件名则使用当前文件
condition是一个字符串,必须等价于 true
The condition argument, if present, is a string which must
evaluate to true in order for the breakpoint to be honored.
tbreak [([filename:]lineno | function) [, condition] ]
临时的breakpoint
cl(ear) [bpnumber [bpnumber ...]]
空格进行分割,清除这些断点
disable bpnumber [bpnumber ...]
disable 断点,可以enable之后
ignore bpnumber count
设置某个断点的count,当count为0的时候断点状态为active,count不为0的时候每一次进入断点时候count自减
condition bpnumber condition
s(tep) 单步执行,步入
n(ext) 单步执行,步过函数
c(ont(inue)) 执行直到断点
l(ist) [first [,last]]
列出11行附近的代码
a(rgs)
打印出当前函数的参数
p expression
答应表达式的值
(!) statement
执行statement
whatis arg
答应 arg 的类型
q(uit)