Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The pdb command 'clear bpnumber' may delete more than one breakpoint #54770

Closed
xdegaye mannequin opened this issue Nov 28, 2010 · 3 comments
Closed

The pdb command 'clear bpnumber' may delete more than one breakpoint #54770

xdegaye mannequin opened this issue Nov 28, 2010 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented Nov 28, 2010

BPO 10561
Nosy @orsenthil, @xdegaye

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/orsenthil'
closed_at = <Date 2010-11-29.12:41:30.950>
created_at = <Date 2010-11-28.11:38:54.706>
labels = ['type-bug', 'library']
title = "The pdb command 'clear bpnumber' may delete more than one breakpoint"
updated_at = <Date 2010-11-29.12:41:30.948>
user = 'https://github.com/xdegaye'

bugs.python.org fields:

activity = <Date 2010-11-29.12:41:30.948>
actor = 'orsenthil'
assignee = 'orsenthil'
closed = True
closed_date = <Date 2010-11-29.12:41:30.950>
closer = 'orsenthil'
components = ['Library (Lib)']
creation = <Date 2010-11-28.11:38:54.706>
creator = 'xdegaye'
dependencies = []
files = []
hgrepos = []
issue_num = 10561
keywords = []
message_count = 3.0
messages = ['122652', '122791', '122796']
nosy_count = 2.0
nosy_names = ['orsenthil', 'xdegaye']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue10561'
versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

@xdegaye
Copy link
Mannequin Author

xdegaye mannequin commented Nov 28, 2010

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)

===================================================================

@xdegaye xdegaye mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 28, 2010
@orsenthil
Copy link
Member

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.

@orsenthil orsenthil self-assigned this Nov 29, 2010
@orsenthil
Copy link
Member

r86862 - release31-maint and r86863 - release27-maint.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant