From 64b655b565026536d59861af82b9c4293186061f Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 23 Sep 2024 16:30:30 -0700 Subject: [PATCH 1/7] Use the normal command path for breakpoint commands --- Doc/library/pdb.rst | 18 +++++++++++---- Lib/pdb.py | 55 ++++++++++++++++---------------------------- Lib/test/test_pdb.py | 48 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 40 deletions(-) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index d696161876e99d..2f7281a0006ca0 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -423,17 +423,25 @@ can be overridden by the local file. Specifying any command resuming execution (currently :pdbcmd:`continue`, :pdbcmd:`step`, :pdbcmd:`next`, - :pdbcmd:`return`, :pdbcmd:`jump`, :pdbcmd:`quit` and their abbreviations) + :pdbcmd:`return`, :pdbcmd:`until`, :pdbcmd:`jump`, :pdbcmd:`quit` and their abbreviations) terminates the command list (as if that command was immediately followed by end). This is because any time you resume execution (even with a simple next or step), you may encounter another breakpoint—which could have its own command list, leading to ambiguities about which list to execute. - If you use the ``silent`` command in the command list, the usual message about - stopping at a breakpoint is not printed. This may be desirable for breakpoints - that are to print a specific message and then continue. If none of the other - commands print anything, you see no sign that the breakpoint was reached. + If you have a command that resumes execution in the command list, the normal + frame information before you interact with pdb is not displayed. If none of + the other commands print anything, you see no sign that the breakpoint was + reached. + + If you don't have a command that resumes execution in the command list, you + can also use the ``silent`` command anywhere in the command list to suppress + the frame information. + + .. versionchanged:: 3.14 + Frame information will not be displayed if a command that resumes execution + is present in the command list. .. pdbcommand:: s(tep) diff --git a/Lib/pdb.py b/Lib/pdb.py index 228de489a9cef1..5d21e5a6d20dec 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -349,10 +349,6 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, pass self.commands = {} # associates a command list to breakpoint numbers - self.commands_doprompt = {} # for each bp num, tells if the prompt - # must be disp. after execing the cmd list - self.commands_silent = {} # for each bp num, tells if the stack trace - # must be disp. after execing the cmd list self.commands_defining = False # True while in the process of defining # a command list self.commands_bnum = None # The breakpoint number for which we are @@ -439,8 +435,8 @@ def user_line(self, frame): or frame.f_lineno <= 0): return self._wait_for_mainpyfile = False - if self.bp_commands(frame): - self.interaction(frame, None) + self.bp_commands(frame) + self.interaction(frame, None) user_opcode = user_line @@ -455,18 +451,9 @@ def bp_commands(self, frame): self.currentbp in self.commands: currentbp = self.currentbp self.currentbp = 0 - lastcmd_back = self.lastcmd - self.setup(frame, None) for line in self.commands[currentbp]: - self.onecmd(line) - self.lastcmd = lastcmd_back - if not self.commands_silent[currentbp]: - self.print_stack_entry(self.stack[self.curindex]) - if self.commands_doprompt[currentbp]: - self._cmdloop() - self.forget() - return - return 1 + self.cmdqueue.append(line) + self.cmdqueue.append(f'_pdbcmd_restore_lastcmd {self.lastcmd}') def user_return(self, frame, return_value): """This function is called when a return trap is set here.""" @@ -865,15 +852,15 @@ def handle_command_def(self, line): cmd, arg, line = self.parseline(line) if not cmd: return False - if cmd == 'silent': - self.commands_silent[self.commands_bnum] = True - return False # continue to handle other cmd def in the cmd list - elif cmd == 'end': + if cmd == 'end': return True # end of cmd list elif cmd == 'EOF': print('') return True # end of cmd list cmdlist = self.commands[self.commands_bnum] + if cmd == 'silent': + cmdlist.append('_pdbcmd_silent_frame_status') + return False # continue to handle other cmd def in the cmd list if arg: cmdlist.append(cmd+' '+arg) else: @@ -885,7 +872,6 @@ def handle_command_def(self, line): func = self.default # one of the resuming commands if func.__name__ in self.commands_resuming: - self.commands_doprompt[self.commands_bnum] = False return True return False @@ -998,6 +984,13 @@ def _pdbcmd_print_frame_status(self, arg): self.print_stack_trace(0) self._show_display() + def _pdbcmd_silent_frame_status(self, arg): + if self.cmdqueue and self.cmdqueue[-1] == '_pdbcmd_print_frame_status': + self.cmdqueue.pop() + + def _pdbcmd_restore_lastcmd(self, arg): + self.lastcmd = arg + # Command definitions, called by cmdloop() # The argument is the remaining string on the command line # Return true to exit from the command loop @@ -1056,14 +1049,10 @@ def do_commands(self, arg): self.commands_bnum = bnum # Save old definitions for the case of a keyboard interrupt. if bnum in self.commands: - old_command_defs = (self.commands[bnum], - self.commands_doprompt[bnum], - self.commands_silent[bnum]) + old_commands = self.commands[bnum] else: - old_command_defs = None + old_commands = None self.commands[bnum] = [] - self.commands_doprompt[bnum] = True - self.commands_silent[bnum] = False prompt_back = self.prompt self.prompt = '(com) ' @@ -1072,14 +1061,10 @@ def do_commands(self, arg): self.cmdloop() except KeyboardInterrupt: # Restore old definitions. - if old_command_defs: - self.commands[bnum] = old_command_defs[0] - self.commands_doprompt[bnum] = old_command_defs[1] - self.commands_silent[bnum] = old_command_defs[2] + if old_commands: + self.commands[bnum] = old_commands else: del self.commands[bnum] - del self.commands_doprompt[bnum] - del self.commands_silent[bnum] self.error('command definition aborted, old commands restored') finally: self.commands_defining = False @@ -2091,7 +2076,7 @@ def complete_unalias(self, text, line, begidx, endidx): # List of all the commands making the program resume execution. commands_resuming = ['do_continue', 'do_step', 'do_next', 'do_return', - 'do_quit', 'do_jump'] + 'do_until', 'do_quit', 'do_jump'] # Print a traceback starting at the top stack frame. # The most recently entered frame is printed last; diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index db7d1b1e9cd935..51e5ba61aff292 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -363,6 +363,54 @@ def test_pdb_breakpoint_commands(): 4 """ +def test_pdb_commands(): + """Test the commands command of pdb. + + >>> def test_function(): + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... print(1) + ... print(2) + ... print(3) + + >>> reset_Breakpoint() + + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... 'b 3', + ... 'commands', + ... 'silent', # suppress the frame status output + ... 'p "hello"', + ... 'end', + ... 'b 4', + ... 'commands', + ... 'until 5', # no output, should stop at line 5 + ... 'continue', # hit breakpoint at line 3 + ... '', # repeat continue, hit breakpoint at line 4 then `until` to line 5 + ... '', + ... ]): + ... test_function() + > (2)test_function() + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) b 3 + Breakpoint 1 at :3 + (Pdb) commands + (com) silent + (com) p "hello" + (com) end + (Pdb) b 4 + Breakpoint 2 at :4 + (Pdb) commands + (com) until 5 + (Pdb) continue + 'hello' + (Pdb) + 1 + 2 + > (5)test_function() + -> print(3) + (Pdb) + 3 + """ + def test_pdb_breakpoint_with_filename(): """Breakpoints with filename:lineno From 44617d00067aceecfe6cf99e19b2aa828cc55ada Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:01:28 +0000 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst diff --git a/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst b/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst new file mode 100644 index 00000000000000..1391c7060f23c0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst @@ -0,0 +1 @@ +``until`` in ``commands`` executes correctly now in :mod:`pdb`. Breakpoint commands will not print the frame information if there's a command that resumes execution in the command list. From e02c57c1a069101d41d69a6212bcf5e9acf8967d Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 26 Sep 2024 09:33:14 -0700 Subject: [PATCH 3/7] Update Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- .../next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst b/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst index 1391c7060f23c0..f1c7edf6e933b9 100644 --- a/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst +++ b/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst @@ -1 +1 @@ -``until`` in ``commands`` executes correctly now in :mod:`pdb`. Breakpoint commands will not print the frame information if there's a command that resumes execution in the command list. +Fixed :mod:`pdb` bug where ``until`` has no effect when it appears in a ``commands`` sequence. Also avoid printing the frame information at a breakpoint if it has a command list containing a command that resumes execution. From 9d11e1cf558a7755a8d9e49d515a4ad13922f5b0 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 26 Sep 2024 09:47:46 -0700 Subject: [PATCH 4/7] Change silent to silence --- Lib/pdb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 5d21e5a6d20dec..3b6fadcfed884c 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -859,7 +859,7 @@ def handle_command_def(self, line): return True # end of cmd list cmdlist = self.commands[self.commands_bnum] if cmd == 'silent': - cmdlist.append('_pdbcmd_silent_frame_status') + cmdlist.append('_pdbcmd_silence_frame_status') return False # continue to handle other cmd def in the cmd list if arg: cmdlist.append(cmd+' '+arg) @@ -984,7 +984,7 @@ def _pdbcmd_print_frame_status(self, arg): self.print_stack_trace(0) self._show_display() - def _pdbcmd_silent_frame_status(self, arg): + def _pdbcmd_silence_frame_status(self, arg): if self.cmdqueue and self.cmdqueue[-1] == '_pdbcmd_print_frame_status': self.cmdqueue.pop() From 24e201f6296810d31a72cccbd61f3a967509beb2 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 26 Sep 2024 10:57:22 -0700 Subject: [PATCH 5/7] Update Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- .../next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst b/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst index f1c7edf6e933b9..25ee01e3108bf8 100644 --- a/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst +++ b/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst @@ -1 +1 @@ -Fixed :mod:`pdb` bug where ``until`` has no effect when it appears in a ``commands`` sequence. Also avoid printing the frame information at a breakpoint if it has a command list containing a command that resumes execution. +Fixed a :mod:`pdb` bug where ``until`` has no effect when it appears in a ``commands`` sequence. Also avoid printing the frame information at a breakpoint that has a command list containing a command that resumes execution. From 316a1e9c7c426c11ec2a3d44f38a49df9dbbd1ca Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 27 Sep 2024 13:02:20 -0700 Subject: [PATCH 6/7] Update pdb.rst --- Doc/library/pdb.rst | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 2f7281a0006ca0..f328e484c36b5b 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -430,14 +430,9 @@ can be overridden by the local file. breakpoint—which could have its own command list, leading to ambiguities about which list to execute. - If you have a command that resumes execution in the command list, the normal - frame information before you interact with pdb is not displayed. If none of - the other commands print anything, you see no sign that the breakpoint was - reached. - - If you don't have a command that resumes execution in the command list, you - can also use the ``silent`` command anywhere in the command list to suppress - the frame information. + If the command list contains the ``silent`` command, or a command that + resumes execution, then the breakpoint message containing information about + the frame is not displayed. .. versionchanged:: 3.14 Frame information will not be displayed if a command that resumes execution From bc30eb43817f444c6d2fc539c845140d2cafe6ab Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 29 Sep 2024 17:11:37 -0400 Subject: [PATCH 7/7] Update Doc/library/pdb.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- Doc/library/pdb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index f328e484c36b5b..3b2e2d14f46819 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -430,7 +430,7 @@ can be overridden by the local file. breakpoint—which could have its own command list, leading to ambiguities about which list to execute. - If the command list contains the ``silent`` command, or a command that + If the list of commands contains the ``silent`` command, or a command that resumes execution, then the breakpoint message containing information about the frame is not displayed.