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: pdb does not output the prompt message when successfully clear breakpoints by "filename:lineno"
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: hjzin, iritkatriel, miss-islington
Priority: normal Keywords: patch

Created on 2021-02-25 06:55 by hjzin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24646 merged hjzin, 2021-02-25 08:11
PR 26674 merged miss-islington, 2021-06-11 15:18
PR 26675 merged miss-islington, 2021-06-11 15:18
Messages (8)
msg387649 - (view) Author: ZhaoJie Hu (hjzin) * Date: 2021-02-25 08:11
In Pdb, when successfully clear breakpoints, the Pdb should output a message:"Deleted XXX", but when breakpoints are cleared by filename:lineno, the message can't be output.

I think it's related to the following code.

```python
pdb.py:

def do_clear(self, arg):
    ...
  
    if ':' in arg:
        # Make sure it works for "clear C:\foo\bar.py:12"
        i = arg.rfind(':')
        filename = arg[:i]
        arg = arg[i+1:]
        try:
            lineno = int(arg)
        except ValueError:
            err = "Invalid line number (%s)" % arg
        else:
            bplist = self.get_breaks(filename, lineno)
            err = self.clear_break(filename, lineno)
        if err:
            self.error(err)
        else:
            for bp in bplist:
                self.message('Deleted %s' % bp)
        return
```
self.get_breaks is called to get the breakpoints to be deleted,  the result is in bplist. self.clear_break is called to delete the breakpoints in bplist. Each element in bplist is a reference to a Breakpoint object, so when all Breakpoint objects are removed, the bplist will become an empty list when self.clear_break is called, so pdb can't output the prompt message.

It can be simply fixed by following code:
```python
    bplist = self.get_breaks(filename, lineno)[:]
```
msg387661 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-25 12:00
Please provide instructions how to reproduce the bug. The patch would need a unit test as well.
msg387666 - (view) Author: ZhaoJie Hu (hjzin) * Date: 2021-02-25 12:37
Accroding to my test, it appears in python 3.8.0 and the latest 3.10 master branch, and I think other versions also have this bug.

The steps to reproduce the bug:

1. start pdb: python -m pdb foo.py

2. set a breakpoint on any line of the file:

(Pdb) b 2
Breakpoint 1 at foo.py:2
(Pdb) b
Num Type         Disp Enb   Where
1   breakpoint   keep yes   at foo.py:2

3. when clear the breakpoint using breakpoint number, it will get a output("Deleted breakpoint 1 at ..."):

(Pdb) cl 1
Deleted breakpoint 1 at foo.py:2

4. set another breakpoint:

(Pdb) b 3
Breakpoint 2 at foo.py:3

5. if breakpoint is cleared using (filename:lineno), it gets nothing:

(Pdb)cl foo.py:2
(Pdb)
msg391428 - (view) Author: ZhaoJie Hu (hjzin) * Date: 2021-04-20 10:58
I found a typo in the reproduce step. I'm going to fix it here.

The unit test is updated in PR. Now it has some conflicts with the master branch, and I will resolve them soon.

The steps to reproduce the bug:

Assume the file to be debugged is foo.py(You can use any file you want).

1. start pdb: python -m pdb foo.py

2. set a breakpoint on any line of the file:

(Pdb) b 2
Breakpoint 1 at foo.py:2
(Pdb) b
Num Type         Disp Enb   Where
1   breakpoint   keep yes   at foo.py:2

3. when clear the breakpoint using breakpoint number, it will get a output("Deleted breakpoint 1 at ..."):

(Pdb) cl 1
Deleted breakpoint 1 at foo.py:2

4. set another breakpoint:

(Pdb) b 3
Breakpoint 2 at foo.py:3

5. if breakpoint is cleared using (filename:lineno), it gets nothing:

(Pdb)cl foo.py:3
(Pdb)
msg395540 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-10 14:50
Your fix looks correct - the problem is that the list of breakpoints gets emptied by the clear_break call, and you copy the list so that it can be echoed later if clear_break does not err.

I made some polishing comments on the PR, and it also need to be rebased because there is not a merge conflict on test_pdb.
msg395639 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-11 15:18
New changeset 4cb6ba14325cff98589c2660d1d2c65f4aacfee4 by huzhaojie in branch 'main':
bpo-43318: Fix a bug where pdb does not always echo cleared breakpoints (GH-24646)
https://github.com/python/cpython/commit/4cb6ba14325cff98589c2660d1d2c65f4aacfee4
msg395644 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-11 16:18
New changeset 9c0180ae7761b352116a2528aae61eea10e31045 by Miss Islington (bot) in branch '3.10':
bpo-43318: Fix a bug where pdb does not always echo cleared breakpoints (GH-24646) (GH-26674)
https://github.com/python/cpython/commit/9c0180ae7761b352116a2528aae61eea10e31045
msg395645 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-11 16:18
New changeset 6df926f1c46eb6db7b5dcd0227c6b532c78525c9 by Miss Islington (bot) in branch '3.9':
bpo-43318: Fix a bug where pdb does not always echo cleared breakpoints (GH-24646) (GH-26675)
https://github.com/python/cpython/commit/6df926f1c46eb6db7b5dcd0227c6b532c78525c9
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87484
2021-06-11 16:19:12iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-06-11 16:18:52iritkatrielsetmessages: + msg395645
2021-06-11 16:18:27iritkatrielsetmessages: + msg395644
2021-06-11 15:18:11miss-islingtonsetpull_requests: + pull_request25261
2021-06-11 15:18:06miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25260
2021-06-11 15:18:04iritkatrielsetmessages: + msg395639
2021-06-10 14:50:03iritkatrielsettitle: pdb can't output the prompt message when successfully clear breakpoints by "filename:lineno" -> pdb does not output the prompt message when successfully clear breakpoints by "filename:lineno"
messages: + msg395540
versions: + Python 3.11, - Python 3.8
2021-04-20 10:58:06hjzinsetmessages: + msg391428
2021-02-25 12:37:15hjzinsetmessages: + msg387666
2021-02-25 12:00:28iritkatrielsetnosy: + iritkatriel
messages: + msg387661
2021-02-25 08:11:28hjzinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23431
2021-02-25 08:11:10hjzinsetmessages: + msg387649
title: pdb can't output the prompt message when successfully clear a breakpoint by "filename:lineno" -> pdb can't output the prompt message when successfully clear breakpoints by "filename:lineno"
2021-02-25 06:55:08hjzincreate