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

pdb does not output the prompt message when successfully clear breakpoints by "filename:lineno" #87484

Closed
hjzin mannequin opened this issue Feb 25, 2021 · 8 comments
Closed
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@hjzin
Copy link
Mannequin

hjzin mannequin commented Feb 25, 2021

BPO 43318
Nosy @miss-islington, @iritkatriel, @hjzin
PRs
  • bpo-43318: Fix a bug where pdb does not always echo cleared breakpoints. #24646
  • [3.10] bpo-43318: Fix a bug where pdb does not always echo cleared breakpoints (GH-24646) #26674
  • [3.9] bpo-43318: Fix a bug where pdb does not always echo cleared breakpoints (GH-24646) #26675
  • 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 = None
    closed_at = <Date 2021-06-11.16:19:12.169>
    created_at = <Date 2021-02-25.06:55:08.080>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'pdb does not output the prompt message when successfully clear breakpoints by "filename:lineno"'
    updated_at = <Date 2021-06-11.16:19:12.168>
    user = 'https://github.com/hjzin'

    bugs.python.org fields:

    activity = <Date 2021-06-11.16:19:12.168>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-11.16:19:12.169>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2021-02-25.06:55:08.080>
    creator = 'hjzin'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43318
    keywords = ['patch']
    message_count = 8.0
    messages = ['387649', '387661', '387666', '391428', '395540', '395639', '395644', '395645']
    nosy_count = 3.0
    nosy_names = ['miss-islington', 'iritkatriel', 'hjzin']
    pr_nums = ['24646', '26674', '26675']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43318'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @hjzin hjzin mannequin added 3.8 only security fixes 3.10 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 25, 2021
    @hjzin
    Copy link
    Mannequin Author

    hjzin mannequin commented Feb 25, 2021

    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.

    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:

        bplist = self.get_breaks(filename, lineno)[:]

    @hjzin hjzin mannequin changed the 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" Feb 25, 2021
    @hjzin hjzin mannequin changed the 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" Feb 25, 2021
    @iritkatriel
    Copy link
    Member

    Please provide instructions how to reproduce the bug. The patch would need a unit test as well.

    @hjzin
    Copy link
    Mannequin Author

    hjzin mannequin commented Feb 25, 2021

    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

    1. 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

    1. set another breakpoint:

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

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

    (Pdb)cl foo.py:2
    (Pdb)

    @hjzin
    Copy link
    Mannequin Author

    hjzin mannequin commented Apr 20, 2021

    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

    1. 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

    1. set another breakpoint:

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

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

    (Pdb)cl foo.py:3
    (Pdb)

    @iritkatriel
    Copy link
    Member

    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.

    @iritkatriel iritkatriel added 3.11 only security fixes and removed 3.8 only security fixes labels Jun 10, 2021
    @iritkatriel iritkatriel changed the title 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" Jun 10, 2021
    @iritkatriel iritkatriel added 3.11 only security fixes and removed 3.8 only security fixes labels Jun 10, 2021
    @iritkatriel iritkatriel changed the title 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" Jun 10, 2021
    @iritkatriel
    Copy link
    Member

    New changeset 4cb6ba1 by huzhaojie in branch 'main':
    bpo-43318: Fix a bug where pdb does not always echo cleared breakpoints (GH-24646)
    4cb6ba1

    @iritkatriel
    Copy link
    Member

    New changeset 9c0180a 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)
    9c0180a

    @iritkatriel
    Copy link
    Member

    New changeset 6df926f 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)
    6df926f

    @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
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes 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