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

bpo-44682: Handle invalid arg to pdb's "commands" directive #27252

Merged
merged 12 commits into from Jul 28, 2021
Merged
6 changes: 6 additions & 0 deletions Lib/pdb.py
Expand Up @@ -562,6 +562,12 @@ def do_commands(self, arg):
except:
self.error("Usage: commands [bnum]\n ...\n end")
return
try:
self.get_bpbynumber(bnum)
except ValueError as err:
self.error('cannot set commands: %s' % err)
return

self.commands_bnum = bnum
# Save old definitions for the case of a keyboard interrupt.
if bnum in self.commands:
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_pdb.py
Expand Up @@ -260,6 +260,9 @@ def test_pdb_breakpoint_commands():
... 'tbreak 5',
... 'continue', # will stop at temporary breakpoint
... 'break', # make sure breakpoint is gone
... 'commands 10', # out of range
... 'commands a', # display help
... 'commands 4', # already deleted
... 'continue',
... ]):
... test_function()
Expand Down Expand Up @@ -319,6 +322,14 @@ def test_pdb_breakpoint_commands():
> <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function()
-> print(3)
(Pdb) break
(Pdb) commands 10
*** Breakpoint number 10 out of range
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
(Pdb) commands a
*** Usage: commands [bnum]
...
end
(Pdb) commands 4
*** Breakpoint 4 already deleted
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
(Pdb) continue
3
4
Expand Down
@@ -0,0 +1,2 @@
In :mod:`pdb`, *commands* directive was fixed to disallow setting commands
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
for an invalid breakpoint and to display an appropriate error.