All the problems raised in this issue are caused by self.botframe
being set in a Pdb frame.
In the following pdb session run with python 3.2.2, the first two
frames in the printed stack are Pdb frames, this is wrong. And the
second step command steps incorrectly into the exec() frame that is
called by the Bdb run() method. What prevents the third step command
to step into the run() frame, is that this frame does not have a trace
function setup initially.
=== foo.py =================================
i = 1
=================================================
$ python3 -m pdb foo.py
> path_to/foo.py(1)<module>()
-> i = 1
(Pdb) import sys; print(sys.version)
3.2.2 (default, Dec 27 2011, 17:35:55)
[GCC 4.3.2]
(Pdb) where
/usr/local/lib/python3.2/bdb.py(392)run()
-> exec(cmd, globals, locals)
<string>(1)<module>()
> path_to/foo.py(1)<module>()
-> i = 1
(Pdb) step
--Return--
> path_to/foo.py(1)<module>()->None
-> i = 1
(Pdb) step
--Return--
> <string>(1)<module>()->None
(Pdb) step
The program finished and will be restarted
> path_to/foo.py(1)<module>()
-> i = 1
(Pdb) quit
=================================================
In the following pdb session run with python built from the default
branch (i.e. after issue 13183 has been fixed) the third step command
steps into the run() method of Bdb and the backtrace printed after the
quit command shows duplicate entries. Pdb is trying to debug itself !
Pdb steps in the run() method because after the fix in issue 13183,
Pdb knows now how to step when returning into the caller frame with no
trace function.
=== foo.py =================================
i = 1
=================================================
$ python -m pdb foo.py
> path_to/foo.py(1)<module>()
-> i = 1
(Pdb) step
--Return--
> path_to/foo.py(1)<module>()->None
-> i = 1
(Pdb) step
--Return--
> <string>(1)<module>()->None
(Pdb) step
> path_to/cpython/Lib/bdb.py(409)run()
-> self.quitting = True
(Pdb) quit
Traceback (most recent call last):
File "path_to/cpython/Lib/pdb.py", line 1651, in main
pdb._runscript(mainpyfile)
File "path_to/cpython/Lib/pdb.py", line 1532, in _runscript
self.run(statement)
File "path_to/cpython/Lib/bdb.py", line 409, in run
self.quitting = True
File "path_to/cpython/Lib/bdb.py", line 409, in run
self.quitting = True
File "path_to/cpython/Lib/bdb.py", line 47, in trace_dispatch
return self.dispatch_line(frame)
File "path_to/cpython/Lib/bdb.py", line 66, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> path_to/cpython/Lib/bdb.py(66)dispatch_line()
-> if self.quitting: raise BdbQuit
(Pdb) quit
Post mortem debugger finished. The foo.py will be restarted
> path_to/foo.py(1)<module>()
-> i = 1
(Pdb) quit
=================================================
In the following pdb session run with python 3.2.2, the session is
interrupted with <Ctl-C>. The same problems occur as in the previous
case.
=================================================
import time
i = 1
while i:
time.sleep(.100)
i = 0
=================================================
$ python3 -m pdb foo.py
> path_to/foo.py(1)<module>()
-> import time
(Pdb) import sys; print(sys.version)
3.2.2 (default, Dec 27 2011, 17:35:55)
[GCC 4.3.2]
(Pdb) continue
^C
Program interrupted. (Use 'cont' to resume).
> path_to/foo.py(3)<module>()
-> while i:
(Pdb) !i=0
(Pdb) step
> path_to/foo.py(5)<module>()
-> i = 0
(Pdb) step
--Return--
> path_to/foo.py(5)<module>()->None
-> i = 0
(Pdb) step
--Return--
> <string>(1)<module>()->None
(Pdb) step
> /usr/local/lib/python3.2/bdb.py(396)run()
-> self.quitting = True
(Pdb) quit
Traceback (most recent call last):
File "/usr/local/lib/python3.2/pdb.py", line 1556, in main
pdb._runscript(mainpyfile)
File "/usr/local/lib/python3.2/pdb.py", line 1437, in _runscript
self.run(statement)
File "/usr/local/lib/python3.2/bdb.py", line 396, in run
self.quitting = True
File "/usr/local/lib/python3.2/bdb.py", line 396, in run
self.quitting = True
File "/usr/local/lib/python3.2/bdb.py", line 46, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/local/lib/python3.2/bdb.py", line 65, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /usr/local/lib/python3.2/bdb.py(65)dispatch_line()
-> if self.quitting: raise BdbQuit
(Pdb) quit
Post mortem debugger finished. The foo.py will be restarted
> path_to/foo.py(1)<module>()
-> import time
(Pdb) quit
=================================================
The attached patch fixes all those problems. The patch applies to the
default branch.
|