summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTian Gao <gaogaotiantian@hotmail.com>2024-09-29 23:46:16 (GMT)
committerGitHub <noreply@github.com>2024-09-29 23:46:16 (GMT)
commitb5774603a0c877f19b33fb922e2fb967b1d50329 (patch)
tree34cb1de768ff60269307f9cc8c28db4dc5f3c7c7
parent4b83c03ce964af7fb204144db9adaa524c113a82 (diff)
downloadcpython-b5774603a0c877f19b33fb922e2fb967b1d50329.zip
cpython-b5774603a0c877f19b33fb922e2fb967b1d50329.tar.gz
cpython-b5774603a0c877f19b33fb922e2fb967b1d50329.tar.bz2
gh-124400: Use the normal command path for breakpoint commands (#124401)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
-rw-r--r--Doc/library/pdb.rst13
-rw-r--r--Lib/pdb.py55
-rw-r--r--Lib/test/test_pdb.py48
-rw-r--r--Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst1
4 files changed, 77 insertions, 40 deletions
diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst
index 1682eb0..6c099b2 100644
--- a/Doc/library/pdb.rst
+++ b/Doc/library/pdb.rst
@@ -439,17 +439,20 @@ 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 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.
+
+ .. 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 2827016..aea6fb7 100644
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -350,10 +350,6 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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
@@ -437,8 +433,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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
@@ -453,18 +449,9 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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."""
@@ -863,15 +850,15 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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_silence_frame_status')
+ return False # continue to handle other cmd def in the cmd list
if arg:
cmdlist.append(cmd+' '+arg)
else:
@@ -883,7 +870,6 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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
@@ -996,6 +982,13 @@ class Pdb(bdb.Bdb, cmd.Cmd):
self.print_stack_trace(0)
self._show_display()
+ def _pdbcmd_silence_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
@@ -1054,14 +1047,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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) '
@@ -1070,14 +1059,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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
@@ -2093,7 +2078,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
# 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 84c0e10..4c64a80 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()
+ > <doctest test.test_pdb.test_pdb_commands[0]>(2)test_function()
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) b 3
+ Breakpoint 1 at <doctest test.test_pdb.test_pdb_commands[0]>:3
+ (Pdb) commands
+ (com) silent
+ (com) p "hello"
+ (com) end
+ (Pdb) b 4
+ Breakpoint 2 at <doctest test.test_pdb.test_pdb_commands[0]>:4
+ (Pdb) commands
+ (com) until 5
+ (Pdb) continue
+ 'hello'
+ (Pdb)
+ 1
+ 2
+ > <doctest test.test_pdb.test_pdb_commands[0]>(5)test_function()
+ -> print(3)
+ (Pdb)
+ 3
+ """
+
def test_pdb_breakpoint_with_filename():
"""Breakpoints with filename:lineno
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 0000000..25ee01e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-09-24-00-01-24.gh-issue-124400.0XCgfe.rst
@@ -0,0 +1 @@
+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.