classification
Title: pdb "break" command messes up "continue"
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, petr.viktorin, swapnil
Priority: normal Keywords:

Created on 2009-02-17 11:51 by petr.viktorin, last changed 2010-07-30 10:29 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
bdb.diff swapnil, 2009-11-24 12:53
Messages (4)
msg82322 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2009-02-17 11:51
Consider this program:

import pdb

pdb.set_trace()

print ("At line 5")
print ("At line 6")
print ("At line 7")
print ("At line 8")
print ("At line 9")

When set_trace starts the debugger, I set a breakpoint at line 8. When I
do that, the continue command starts single-stepping instead of what it
usually does.
Also, the module will appear twice on the call stack (although pdb won't
show this).

Here is the pdb session:

$ python pdbfail.py
> /home/petr/tmp/pdbfail.py(5)<module>()
-> print ("At line 5")
(Pdb) break 8
Breakpoint 1 at /home/petr/tmp/pdbfail.py:8
(Pdb) continue
At line 5
> /home/petr/tmp/pdbfail.py(6)<module>()
-> print ("At line 6")
(Pdb) continue
At line 6
> /home/petr/tmp/pdbfail.py(7)<module>()
-> print ("At line 7")
(Pdb) where
> /home/petr/tmp/pdbfail.py(7)<module>()
-> print ("At line 7")
(Pdb) quit
Traceback (most recent call last):
  File "pdbfail.py", line 7, in <module>
    print ("At line 7")
  File "pdbfail.py", line 7, in <module>
    print ("At line 7")
  File "/usr/lib/python2.5/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python2.5/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
msg82324 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2009-02-17 12:06
It doesn't matter whether the breakpoint is set from within a function
or not, but only the module-level frame is affected.

import pdb

def test():
    print ("At line 4")
    print ("At line 5")
    print ("At line 6")
    print ("At line 7")

pdb.set_trace()

print ("At line 11")
print ("At line 12")
test()
print ("At line 13")
print ("At line 14")

$ python pdbfail.py
> /home/petr/tmp/pdbfail.py(11)<module>()
-> print ("At line 11")

...[single-step to line 4]...

> /home/petr/tmp/pdbfail.py(4)test()
-> print ("At line 4")
(Pdb) b 14
Breakpoint 1 at /home/petr/tmp/pdbfail.py:14
(Pdb) c
At line 4
At line 5
At line 6
At line 7
> /home/petr/tmp/pdbfail.py(14)<module>()
-> print ("At line 13")
(Pdb) c
At line 13
> /home/petr/tmp/pdbfail.py(15)<module>()
-> print ("At line 14")
(Pdb) c
At line 14
--Return--
> /home/petr/tmp/pdbfail.py(15)<module>()->None
-> print ("At line 14")
(Pdb) c
msg95673 - (view) Author: Swapnil Talekar (swapnil) Date: 2009-11-24 12:53
The problem it seems is actually in the bdb module and not in pdb. The 
set_next function sets the current frame as stopframe but it does not 
specify the stoplineno. Hence it's always -1. When you do c(ontinue), 
set_continue just sets botframe as stopframe, if there are no breakpoints.  
Hence, stop_here wrongly returns True on every line event. To rectify 
this, set_next should also specify stoplineno for the stopframe and this 
should be checked in stop_here before returning True. Here is the patch.
msg112060 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-30 10:29
Fixed in r83272 with a slightly different patch.  Thanks very much for the report!
History
Date User Action Args
2010-07-30 10:29:44georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112060

resolution: fixed
2009-11-24 12:53:10swapnilsetfiles: + bdb.diff

nosy: + swapnil
messages: + msg95673

type: behavior
2009-02-17 12:06:20petr.viktorinsetmessages: + msg82324
2009-02-17 11:51:44petr.viktorincreate