]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127321: Avoid stopping at an opcode without an associated line number for breakpoi...
authorTian Gao <gaogaotiantian@hotmail.com>
Sun, 1 Dec 2024 16:57:03 +0000 (08:57 -0800)
committerGitHub <noreply@github.com>
Sun, 1 Dec 2024 16:57:03 +0000 (11:57 -0500)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2024-11-30-21-46-15.gh-issue-127321.M78fBv.rst [new file with mode: 0644]

index b7f6fd4323407eebf3f1840f8985a32900044477..10d1923cdad2d67fda786e6c1d9da20f88ed8020 100644 (file)
@@ -438,6 +438,13 @@ class Pdb(bdb.Bdb, cmd.Cmd):
             if (self.mainpyfile != self.canonic(frame.f_code.co_filename)):
                 return
             self._wait_for_mainpyfile = False
+        if self.trace_opcodes:
+            # GH-127321
+            # We want to avoid stopping at an opcode that does not have
+            # an associated line number because pdb does not like it
+            if frame.f_lineno is None:
+                self.set_stepinstr()
+                return
         self.bp_commands(frame)
         self.interaction(frame, None)
 
index e5f9848319021ad4ca4b298b63bb10fb5c1fd50b..48a4c5686518791e36403cbe7b233e00e18952bd 100644 (file)
@@ -2931,6 +2931,22 @@ def test_pdb_issue_gh_108976():
     (Pdb) continue
     """
 
+def test_pdb_issue_gh_127321():
+    """See GH-127321
+    breakpoint() should stop at a opcode that has a line number
+    >>> def test_function():
+    ...     import pdb; pdb_instance = pdb.Pdb(nosigint=True, readrc=False)
+    ...     [1, 2] and pdb_instance.set_trace()
+    ...     a = 1
+    >>> with PdbTestInput([  # doctest: +NORMALIZE_WHITESPACE
+    ...     'continue'
+    ... ]):
+    ...    test_function()
+    > <doctest test.test_pdb.test_pdb_issue_gh_127321[0]>(4)test_function()
+    -> a = 1
+    (Pdb) continue
+    """
+
 
 def test_pdb_issue_gh_80731():
     """See GH-80731
diff --git a/Misc/NEWS.d/next/Library/2024-11-30-21-46-15.gh-issue-127321.M78fBv.rst b/Misc/NEWS.d/next/Library/2024-11-30-21-46-15.gh-issue-127321.M78fBv.rst
new file mode 100644 (file)
index 0000000..69b6ce6
--- /dev/null
@@ -0,0 +1 @@
+:func:`pdb.set_trace` will not stop at an opcode that does not have an associated line number anymore.