Fix #10561 - Fix pdb behavior. Delete the breakpoints by breakpoint number.

Handle multiple breakpoints at same line. Update docs/test.
Patch by Xavier de Gaye.
This commit is contained in:
Senthil Kumaran 2010-11-29 11:54:17 +00:00
parent ead22227cc
commit 6f1070485f
5 changed files with 31 additions and 9 deletions

View File

@ -256,8 +256,9 @@ by the local file.
Temporary breakpoint, which is removed automatically when it is first hit. Temporary breakpoint, which is removed automatically when it is first hit.
The arguments are the same as for :pdbcmd:`break`. The arguments are the same as for :pdbcmd:`break`.
.. pdbcommand:: cl(ear) [bpnumber [bpnumber ...]] .. pdbcommand:: cl(ear) [filename:lineno | bpnumber [bpnumber ...]]
With a *filename:lineno* argument, clear all the breakpoints at this line.
With a space separated list of breakpoint numbers, clear those breakpoints. With a space separated list of breakpoint numbers, clear those breakpoints.
Without argument, clear all breaks (but first ask confirmation). Without argument, clear all breaks (but first ask confirmation).

View File

@ -252,6 +252,12 @@ class Bdb:
list.append(lineno) list.append(lineno)
bp = Breakpoint(filename, lineno, temporary, cond, funcname) bp = Breakpoint(filename, lineno, temporary, cond, funcname)
def _prune_breaks(self, filename, lineno):
if (filename, lineno) not in Breakpoint.bplist:
self.breaks[filename].remove(lineno)
if not self.breaks[filename]:
del self.breaks[filename]
def clear_break(self, filename, lineno): def clear_break(self, filename, lineno):
filename = self.canonic(filename) filename = self.canonic(filename)
if not filename in self.breaks: if not filename in self.breaks:
@ -263,17 +269,15 @@ class Bdb:
# pair, then remove the breaks entry # pair, then remove the breaks entry
for bp in Breakpoint.bplist[filename, lineno][:]: for bp in Breakpoint.bplist[filename, lineno][:]:
bp.deleteMe() bp.deleteMe()
if (filename, lineno) not in Breakpoint.bplist: self._prune_breaks(filename, lineno)
self.breaks[filename].remove(lineno)
if not self.breaks[filename]:
del self.breaks[filename]
def clear_bpbynumber(self, arg): def clear_bpbynumber(self, arg):
try: try:
bp = self.get_bpbynumber(arg) bp = self.get_bpbynumber(arg)
except ValueError as err: except ValueError as err:
return str(err) return str(err)
self.clear_break(bp.file, bp.line) bp.deleteMe()
self._prune_breaks(bp.file, bp.line)
def clear_all_file_breaks(self, filename): def clear_all_file_breaks(self, filename):
filename = self.canonic(filename) filename = self.canonic(filename)

View File

@ -774,7 +774,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
except ValueError as err: except ValueError as err:
self.error(err) self.error(err)
else: else:
self.clear_break(bp.file, bp.line) self.clear_bpbynumber(i)
#self.clear_break(bp.file, bp.line)
self.message('Deleted %s' % bp) self.message('Deleted %s' % bp)
do_cl = do_clear # 'c' is already an abbreviation for 'continue' do_cl = do_clear # 'c' is already an abbreviation for 'continue'

View File

@ -192,6 +192,9 @@ def test_pdb_breakpoint_commands():
... 'ignore 1 10', ... 'ignore 1 10',
... 'condition 1 1 < 2', ... 'condition 1 1 < 2',
... 'break 4', ... 'break 4',
... 'break 4',
... 'break',
... 'clear 3',
... 'break', ... 'break',
... 'condition 1', ... 'condition 1',
... 'enable 1', ... 'enable 1',
@ -220,6 +223,17 @@ def test_pdb_breakpoint_commands():
New condition set for breakpoint 1. New condition set for breakpoint 1.
(Pdb) break 4 (Pdb) break 4
Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 Breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) break 4
Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) break
Num Type Disp Enb Where
1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
stop only if 1 < 2
ignore next 10 hits
2 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
3 breakpoint keep yes at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) clear 3
Deleted breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) break (Pdb) break
Num Type Disp Enb Where Num Type Disp Enb Where
1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3 1 breakpoint keep no at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:3
@ -244,10 +258,10 @@ def test_pdb_breakpoint_commands():
Clear all breaks? y Clear all breaks? y
Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4 Deleted breakpoint 2 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:4
(Pdb) tbreak 5 (Pdb) tbreak 5
Breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5 Breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
(Pdb) continue (Pdb) continue
2 2
Deleted breakpoint 3 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5 Deleted breakpoint 4 at <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>:5
> <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function() > <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function()
-> print(3) -> print(3)
(Pdb) break (Pdb) break

View File

@ -49,6 +49,8 @@ Library
- Issue #10242: Fixed implementation of unittest.ItemsEqual and gave it - Issue #10242: Fixed implementation of unittest.ItemsEqual and gave it
a new more informative name, unittest.CountEqual. a new more informative name, unittest.CountEqual.
- Issue #10561: In pdb, clear the breakpoints by the breakpoint number.
- Issue #2986: difflib.SequenceMatcher gets a new parameter, autojunk, which - Issue #2986: difflib.SequenceMatcher gets a new parameter, autojunk, which
can be set to False to turn off the previously undocumented 'popularity' can be set to False to turn off the previously undocumented 'popularity'
heuristic. Patch by Terry Reedy and Eli Bendersky. heuristic. Patch by Terry Reedy and Eli Bendersky.