python的pdb调试命令的命令整理及实例

时间:2022-10-26 16:32:39

pythonpdb调试命令的命令整理及实例

一、命令整理

 

pdb调试命令
完整命令 简写命令 描述
args a 打印当前函数的参数
break b 设置断点
clear cl 清除断点
condition 设置条件断点
continue c或者cont 继续运行,知道遇到断点或者脚本结束
disable 禁用断点
enable 启用断点
help h 查看pdb帮助
ignore 忽略断点
jump j 跳转到指定行数运行
list l 列出脚本清单
next n 执行下条语句,遇到函数不进入其内部
p p 打印变量值,也可以用print
quit q 退出 pdb
return r 一直运行到函数返回
tbreak 设置临时断点,断点只中断一次
step s 执行下一条语句,遇到函数进入其内部
where w 查看所在的位置
! 在pdb中执行语句

 

二 pdb实例

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
E:\python\work>python -m pdb prime.py
> e:\python\work\prime.py(1)<module>()
->import math
(Pdb) list
1->import math
2def isprime(i):
3for t in range(2,int(math.sqrt(i))+1):
4if i % t ==0:
5return0
6else:
7return1
8
9print('100到110之间的素数为:')
10for i in range(100,110):
11if isprime(i):
(Pdb) l 12,15
12print(i)
13
14
15
(Pdb) b 12
Breakpoint1 at e:\python\work\prime.py:12
(Pdb) b 7
Breakpoint2 at e:\python\work\prime.py:7
(Pdb) c
100110之间的素数为:
> e:\python\work\prime.py(7)isprime()
->return1
(Pdb) c
> e:\python\work\prime.py(12)<module>()
->print(i)
(Pdb) n
101
> e:\python\work\prime.py(10)<module>()
->for i in range(100,110):
(Pdb) n
> e:\python\work\prime.py(11)<module>()
->if isprime(i):
(Pdb) n
> e:\python\work\prime.py(10)<module>()
->for i in range(100,110):
(Pdb) n
> e:\python\work\prime.py(11)<module>()
->if isprime(i):
(Pdb)print i
***SyntaxError:Missing parentheses in call to 'print'
(Pdb) p i
103
(Pdb) where
 d:\python36\lib\bdb.py(431)run()
->exec(cmd, globals, locals)
<string>(1)<module>()
> e:\python\work\prime.py(11)<module>()
->if isprime(i):
(Pdb)break
NumTypeDispEnbWhere
1  breakpoint  keep yes  at e:\python\work\prime.py:12
    breakpoint already hit 1 time
2  breakpoint  keep yes  at e:\python\work\prime.py:7
    breakpoint already hit 1 time
(Pdb) disable 1
Disabled breakpoint 1 at e:\python\work\prime.py:12
(Pdb)break
NumTypeDispEnbWhere
1  breakpoint  keep no  at e:\python\work\prime.py:12
    breakpoint already hit 1 time
2  breakpoint  keep yes  at e:\python\work\prime.py:7
    breakpoint already hit 1 time
(Pdb) n
> e:\python\work\prime.py(7)isprime()
->return1
(Pdb) where
 d:\python36\lib\bdb.py(431)run()
->exec(cmd, globals, locals)
<string>(1)<module>()
 e:\python\work\prime.py(11)<module>()
->if isprime(i):
> e:\python\work\prime.py(7)isprime()
->return1
(Pdb) cl
Clear all breaks? y
Deleted breakpoint 1 at e:\python\work\prime.py:12
Deleted breakpoint 2 at e:\python\work\prime.py:7
(Pdb)break
(Pdb) c
103
105
107
109
The program finished and will be restarted
> e:\python\work\prime.py(1)<module>()

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

原文链接:http://cakin24.iteye.com/blog/2383524