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

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

一、命令整理

pdb调试命令
完整命令简写命令描述
argsa打印当前函数的参数
breakb设置断点
clearcl清除断点
condition设置条件断点
continuec或者cont继续运行,知道遇到断点或者脚本结束
disable禁用断点
enable启用断点
helph查看pdb帮助
ignore忽略断点
jumpj跳转到指定行数运行
listl列出脚本清单
nextn执行下条语句,遇到函数不进入其内部
pp打印变量值,也可以用print
quitq退出 pdb
returnr一直运行到函数返回
tbreak设置临时断点,断点只中断一次
steps执行下一条语句,遇到函数进入其内部
wherew查看所在的位置
!在pdb中执行语句

二 pdb实例

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

100到110之间的素数为:

> 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>()

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

以上是 python的pdb调试命令的命令整理及实例 的全部内容, 来源链接: utcz.com/z/324797.html

回到顶部