]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44682: Handle invalid arg to pdb's "commands" directive (#27252)
authorandrei kulakov <andrei.avk@gmail.com>
Wed, 28 Jul 2021 16:55:03 +0000 (12:55 -0400)
committerGitHub <noreply@github.com>
Wed, 28 Jul 2021 16:55:03 +0000 (18:55 +0200)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2021-07-20-00-11-47.bpo-44682.3m2qVV.rst [new file with mode: 0644]

index 8aa899f90b7d9a4e118edf731ce0512648578282..d7110074538ace364548c83fbfbd9fdb72d1b2ea 100755 (executable)
@@ -640,6 +640,12 @@ class Pdb(bdb.Bdb, cmd.Cmd):
             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:
index 5794e67aafdb1a67c51b79c204b982a8017d2919..5bb8069021d89dbf06a7cdee590e9c32c6262ec1 100644 (file)
@@ -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()
@@ -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
+    *** cannot set commands: Breakpoint number 10 out of range
+    (Pdb) commands a
+    *** Usage: commands [bnum]
+            ...
+            end
+    (Pdb) commands 4
+    *** cannot set commands: Breakpoint 4 already deleted
     (Pdb) continue
     3
     4
diff --git a/Misc/NEWS.d/next/Library/2021-07-20-00-11-47.bpo-44682.3m2qVV.rst b/Misc/NEWS.d/next/Library/2021-07-20-00-11-47.bpo-44682.3m2qVV.rst
new file mode 100644 (file)
index 0000000..308053a
--- /dev/null
@@ -0,0 +1,2 @@
+Change the :mod:`pdb` *commands* directive to disallow setting commands
+for an invalid breakpoint and to display an appropriate error.