This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: The pdb command 'clear bpnumber' may delete more than one breakpoint
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: orsenthil, xdegaye
Priority: normal Keywords:

Created on 2010-11-28 11:38 by xdegaye, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg122652 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2010-11-28 11:38
Description:
------------
1. When deleting a single breakpoint, all the breakpoints located on
   the line of this breakpoint are also deleted. See the test case
   below.

2. The pdb 'clear' command documentation does not mention that all the
   breakpoints on a line can be deleted with the command:

        clear filename:lineno

See the proposed bdb patch and documentation patch below.


Test case:
----------
#####   File foobar.py   #####
def main():
    pass

if __name__ == '__main__':
    main()
#####   Test case   #####
xavier$ /usr/local/bin/python2.7
Python 2.7 (r27:82500, Jul 13 2010, 21:30:27)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb, foobar
>>> pdb.run('foobar.main()')
> <string>(1)<module>()
(Pdb) break foobar.main
Breakpoint 1 at /home/xavier/tmp/foobar.py:1
(Pdb) break foobar.main
Breakpoint 2 at /home/xavier/tmp/foobar.py:1
(Pdb) break
Num Type         Disp Enb   Where
1   breakpoint   keep yes   at /home/xavier/tmp/foobar.py:1
2   breakpoint   keep yes   at /home/xavier/tmp/foobar.py:1
(Pdb) clear 1
Deleted breakpoint 1
(Pdb) break
(Pdb)
#########################


Patch:
------
Index: Doc/library/pdb.rst
===================================================================
--- Doc/library/pdb.rst	(revision 86836)
+++ Doc/library/pdb.rst	(working copy)
@@ -239,7 +239,8 @@
    Temporary breakpoint, which is removed automatically when it is first hit.  The
    arguments are the same as break.
 
-cl(ear) [*bpnumber* [*bpnumber ...*]]
+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.
    Without argument, clear all breaks (but first ask confirmation).
 
Index: Lib/bdb.py
===================================================================
--- Lib/bdb.py	(revision 86836)
+++ Lib/bdb.py	(working copy)
@@ -250,6 +250,12 @@
             list.append(lineno)
         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):
         filename = self.canonic(filename)
         if not filename in self.breaks:
@@ -261,10 +267,7 @@
         # pair, then remove the breaks entry
         for bp in Breakpoint.bplist[filename, lineno][:]:
             bp.deleteMe()
-        if (filename, lineno) not in Breakpoint.bplist:
-            self.breaks[filename].remove(lineno)
-        if not self.breaks[filename]:
-            del self.breaks[filename]
+        self.prune_breaks(filename, lineno)
 
     def clear_bpbynumber(self, arg):
         try:
@@ -277,7 +280,8 @@
             return 'Breakpoint number (%d) out of range' % number
         if not bp:
             return 'Breakpoint (%d) already deleted' % number
-        self.clear_break(bp.file, bp.line)
+        bp.deleteMe()
+        self.prune_breaks(bp.file, bp.line)
 
     def clear_all_file_breaks(self, filename):
         filename = self.canonic(filename)
===================================================================
msg122791 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-29 12:02
Fixed in r86861. Xavier, I noticed that pdb.py itself was not calling the proper method. Added the tests to the patch. Thanks.

BTW, please provide patches against py3k as that is development version.
msg122796 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-29 12:41
r86862 - release31-maint and r86863 - release27-maint.
History
Date User Action Args
2022-04-11 14:57:09adminsetgithub: 54770
2010-11-29 12:41:30orsenthilsetstatus: open -> closed

messages: + msg122796
versions: + Python 3.1, Python 2.7
2010-11-29 12:02:19orsenthilsetassignee: orsenthil
versions: + Python 3.2, - Python 2.7
nosy: + orsenthil

messages: + msg122791
resolution: fixed
stage: resolved
2010-11-28 11:38:54xdegayecreate