python断点调试pdb(lovejunelove)
运行上面的命令后进入以下界面,可以输入类似 gdb 的命令来改变程序的执行流程:
$ python -m pdb 程序名.py
命令 | 用途 | break 或 b | 设置断点 | continue 或 c | 继续执行程序 | list 或 l | 查看当前行的代码段 | step 或 s | 进入函数 | return 或 r | 执行代码直到从当前函数返回 | exit 或 q | 中止并退出 | next 或 n | 执行下一行 | pp | 打印变量的值 | help | 帮助 |
代码中引用pdb:
import pdb
以下是设置方法:
| set_break(self, filename, lineno, temporary=0, cond=None, funcname=None)
|
| set_continue(self)
|
| set_next(self, frame)
| Stop on the next line in or below the given frame.
|
| set_quit(self)
|
| set_return(self, frame)
| Stop when returning from the given frame.
|
| set_step(self)
| Stop after one line of code.
|
| set_trace(self, frame=None)
| Start debugging from `frame`.
|
| If frame is not specified, debugging starts from caller's frame.
|
| set_until(self, frame)
| Stop when the line with the line no greater than the current one is
| reached or when returning from current frame
|
|