【转】Python PDB调试

进入命令行Debug模式,python -m pdb test.py

h:(help)帮助

l:(list)列出源码

        l 列出当前执行语句周围11条代码

        l first 列出first行周围11条代码

        l first second 列出first--second范围的代码,如果second<first,second将被解析为行数

a:(args)列出当前执行函数的函数

p expression:(print)输出expression的值

pp expression:好看一点的p expression

s:(step)step into,如果本句是函数调用,则s会执行到函数的第一句

n:(next)执行下一条语句

r:(return)执行当前运行函数到结束

c:(continue)继续执行,直到遇到下一条断点

b:(break)添加断点

        b 列出当前所有断点,和断点执行到统计次数

        b line_no:当前脚本的line_no行添加断点

        b filename:line_no:脚本filename的line_no行添加断点

        b function:在函数function的第一条可执行语句处添加断点

tbreak:(temporary break)临时断点,在第一次执行到这个断点之后,就自动删除这个断点,用法和b一样

cl:(clear)清除断点

        cl 清除所有断点

        cl bpnumber1 bpnumber2... 清除断点号为bpnumber1,bpnumber2...的断点

        cl lineno 清除当前脚本lineno行的断点

        cl filename:line_no 清除脚本filename的line_no行的断点

disable:停用断点,参数为bpnumber,和cl的区别是,断点依然存在,只是不启用

enable:激活断点,参数为bpnumber

w:(where)打印当前执行堆栈

bt:等同于where

u:(up)执行跳转到当前堆栈的上一层

d:(down)执行跳转到在当前堆栈的深一层

run:重新启动debug,相当于restart

q:(quit)退出debug

j lineno:(jump)设置下条执行的语句函数

        只能在堆栈的最底层跳转,向后重新执行,向前可直接执行到行号

unt:(until)执行到下一行(跳出循环),或者当前堆栈结束

condition bpnumber conditon,给断点设置条件,当参数condition返回True的时候bpnumber断点有效,否则bpnumber断点无效

参考链接:

https://blog.csdn.net/wyb_009/article/details/8896744

https://blog.csdn.net/qq_37049781/article/details/84635652

https://www.cnblogs.com/chencheng/p/3161778.html

猜你喜欢

转载自www.cnblogs.com/gooneybird/p/13180690.html