https://github.com/python/cpython/commit/dd2ad70b29402cae56f13a08e890ca7177a589f2
commit: dd2ad70b29402cae56f13a08e890ca7177a589f2
branch: 3.13
author: Tian Gao <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2024-12-01T17:58:08-05:00
summary:

[3.13] gh-127321: Avoid stopping at an opcode without an associated line number 
for breakpoint() (GH-127457) (#127487)

(cherry picked from commit 1bc4f076d193ad157bdc69a1d62685a15f95113f)

files:
A Misc/NEWS.d/next/Library/2024-11-30-21-46-15.gh-issue-127321.M78fBv.rst
M Lib/pdb.py
M Lib/test/test_pdb.py

diff --git a/Lib/pdb.py b/Lib/pdb.py
index d34ccbe1c701b1..9b6dffda1cfcd1 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -436,6 +436,13 @@ def user_line(self, frame):
             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
         if self.bp_commands(frame):
             self.interaction(frame, None)
 
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 56b939d6904661..5b25f514b9e772 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -2719,6 +2719,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
index 00000000000000..69b6ce68a47509
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-11-30-21-46-15.gh-issue-127321.M78fBv.rst
@@ -0,0 +1 @@
+:func:`pdb.set_trace` will not stop at an opcode that does not have an 
associated line number anymore.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to