From 64d8f6ac77e3f68da9cb6b4a5b429570baaddbf9 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 19 Jun 2024 18:02:03 -0700 Subject: [PATCH 1/3] Add pdb meta command to print frame status. --- Lib/pdb.py | 26 +++++++++++++++++--------- Lib/test/test_pdb.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index b1be207a9fa98a..4af16d0a087c8c 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -517,7 +517,7 @@ def _validate_file_mtime(self): # Called before loop, handles display expressions # Set up convenience variable containers - def preloop(self): + def _show_display(self): displaying = self.displaying.get(self.curframe) if displaying: for expr, oldvalue in displaying.items(): @@ -605,15 +605,13 @@ def interaction(self, frame, tb_or_exc): self.setup(frame, tb) # We should print the stack entry if and only if the user input # is expected, and we should print it right before the user input. - # If self.cmdqueue is not empty, we append a "w 0" command to the - # queue, which is equivalent to print_stack_entry - if self.cmdqueue: - self.cmdqueue.append('w 0') - else: - self.print_stack_entry(self.stack[self.curindex]) + # We achieve this by appending _pdbcmd_print_frame_status to the + # command queue. If cmdqueue is not exausted, the user input is + # not expected and we will not print the stack entry. + self.cmdqueue.append('_pdbcmd_print_frame_status') self._cmdloop() - # If "w 0" is not used, pop it out - if self.cmdqueue and self.cmdqueue[-1] == 'w 0': + # If _pdbcmd_print_frame_status is not used, pop it out + if self.cmdqueue and self.cmdqueue[-1] == '_pdbcmd_print_frame_status': self.cmdqueue.pop() self.forget() @@ -846,6 +844,10 @@ def onecmd(self, line): """ if not self.commands_defining: self._validate_file_mtime() + if line.startswith('_pdbcmd'): + command, arg, line = self.parseline(line) + if hasattr(self, command): + return getattr(self, command)(arg) return cmd.Cmd.onecmd(self, line) else: return self.handle_command_def(line) @@ -982,6 +984,12 @@ def completedefault(self, text, line, begidx, endidx): state += 1 return matches + # Pdb meta commands, only intended to be used internally by pdb + + def _pdbcmd_print_frame_status(self, arg): + self.print_stack_trace(0) + self._show_display() + # Command definitions, called by cmdloop() # The argument is the remaining string on the command line # Return true to exit from the command loop diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index b2b78f1ab9ecca..9e54725e4eccb2 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -496,6 +496,37 @@ def test_pdb_pp_repr_exc(): (Pdb) continue """ +def test_pdb_empty_line(): + """Test that empty line repeats the last command. + + >>> def test_function(): + ... x = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... y = 2 + + >>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE + ... 'p x', + ... '', # Should repeat p x + ... 'n ;; p 0 ;; p x', # Fill cmdqueue with multiple commands + ... '', # Should still repeat p x + ... 'continue', + ... ]): + ... test_function() + > (3)test_function() + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) p x + 1 + (Pdb) + 1 + (Pdb) n ;; p 0 ;; p x + 0 + 1 + > (4)test_function() + -> y = 2 + (Pdb) + 1 + (Pdb) continue + """ def do_nothing(): pass From 87e354f31dff88a305b1d0b4c83041c62294417d Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 20 Jun 2024 01:31:26 +0000 Subject: [PATCH 2/3] =?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-06-20-01-31-24.gh-issue-120769.PfiMrc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-06-20-01-31-24.gh-issue-120769.PfiMrc.rst diff --git a/Misc/NEWS.d/next/Library/2024-06-20-01-31-24.gh-issue-120769.PfiMrc.rst b/Misc/NEWS.d/next/Library/2024-06-20-01-31-24.gh-issue-120769.PfiMrc.rst new file mode 100644 index 00000000000000..8ee6bf1a9c6480 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-06-20-01-31-24.gh-issue-120769.PfiMrc.rst @@ -0,0 +1 @@ +Make empty line in :mod:`pdb` repeats the last command even when the command is from ``cmdqueue``. From 30a6be98320e5c30447f9b4cef8bc4716c040043 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 19 Jun 2024 18:32:39 -0700 Subject: [PATCH 3/3] Remove spaces --- Lib/test/test_pdb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 9e54725e4eccb2..71240157e324a1 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -516,14 +516,14 @@ def test_pdb_empty_line(): -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() (Pdb) p x 1 - (Pdb) + (Pdb) 1 (Pdb) n ;; p 0 ;; p x 0 1 > (4)test_function() -> y = 2 - (Pdb) + (Pdb) 1 (Pdb) continue """