Skip to content

Instantly share code, notes, and snippets.

@lvii
Created March 5, 2013 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvii/5087791 to your computer and use it in GitHub Desktop.
Save lvii/5087791 to your computer and use it in GitHub Desktop.
python pdb
我 google 到两篇文章相关文章:
Title: pdb throws AttributeError at end of debugging session
http://bugs.python.org/issue13044
提到 set_trace() 是断点
For now set_trace() works as breakpoint set up by program
...
use set_trace() as a hard-coded breakpoint
但是文档里面没有说 set_trace() 是用作断点的
set_trace([frame])
Start debugging from frame. If frame is not specified, debugging starts from caller’s frame.
在调试到最后一步,使用 'c' (continue) 替换 ‘n' (next) 会退出
查看帮助,说 'c' 会在遇到断点的时候,退出
这说明调试到最后,遇到了端点,单不是在 set_trace() 调用处,而是在脚本的最后
(Pdb) h c
c(ont(inue))
Continue execution, only stop when a breakpoint is encountered.
> /home/i/me/debug_test.py(15)<module>()
-> print ret
(Pdb) n
hello world
--Return--
> /home/i/me/debug_test.py(15)<module>()->None
-> print ret
(Pdb) l
10
11 import pdb
12 pdb.Pdb().set_trace()
13
14 ret=foo()
15 -> print ret
[EOF] ## 调试运行道脚本最后,按 'c' 就退出了
(Pdb) c
而用 python2 -m pdb 方式调试:
-> print ret
(Pdb) l
10
11 import pdb
12 pdb.Pdb().set_trace()
13
14 ret=foo()
15 -> print ret
[EOF]
(Pdb) n
--Return--
> <string>(1)<module>()->None
(Pdb) n
> /usr/lib/python2.7/bdb.py(404)run()
-> self.quitting = 1
(Pdb) n
> /usr/lib/python2.7/bdb.py(405)run()
-> sys.settrace(None)
(Pdb) n
The program finished and will be restarted
继续 ’n' 会再次从 第一行 进行调试
Title: pdb raises BdbQuit on 'quit' when started with set_trace
http://bugs.python.org/issue16446
篇提到 退出 抛出异常说是个 bug,但是不知道是否被确认是 bug 并被接受
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment