]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-80675: Set `f_trace_lines = True` on all frames upon `pdb.set_trace()` (#110881)
authorTian Gao <gaogaotiantian@hotmail.com>
Sat, 4 Nov 2023 19:59:36 +0000 (12:59 -0700)
committerGitHub <noreply@github.com>
Sat, 4 Nov 2023 19:59:36 +0000 (19:59 +0000)
Lib/bdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2023-10-14-20-15-53.gh-issue-80675._M-cQC.rst [new file with mode: 0644]

index 0f3eec653baaad49553f0dffe238b3e0aa5f0550..1acf7957f0d66931f32cc9fefb9f4e4e0b45c7f3 100644 (file)
@@ -32,6 +32,7 @@ class Bdb:
         self.skip = set(skip) if skip else None
         self.breaks = {}
         self.fncache = {}
+        self.frame_trace_lines = {}
         self.frame_returning = None
 
         self._load_breaks()
@@ -331,6 +332,9 @@ class Bdb:
         while frame:
             frame.f_trace = self.trace_dispatch
             self.botframe = frame
+            # We need f_trace_liens == True for the debugger to work
+            self.frame_trace_lines[frame] = frame.f_trace_lines
+            frame.f_trace_lines = True
             frame = frame.f_back
         self.set_step()
         sys.settrace(self.trace_dispatch)
@@ -349,6 +353,9 @@ class Bdb:
             while frame and frame is not self.botframe:
                 del frame.f_trace
                 frame = frame.f_back
+            for frame, prev_trace_lines in self.frame_trace_lines.items():
+                frame.f_trace_lines = prev_trace_lines
+            self.frame_trace_lines = {}
 
     def set_quit(self):
         """Set quitting attribute to True.
index 5fef8365f597101ace67018b4a80d3895e0c7717..ff9e7c2142fe331576b99ceb1daed549479cc750 100644 (file)
@@ -2350,6 +2350,30 @@ def test_pdb_ambiguous_statements():
     (Pdb) continue
     """
 
+def test_pdb_f_trace_lines():
+    """GH-80675
+
+    pdb should work even if f_trace_lines is set to False on some frames.
+
+    >>> reset_Breakpoint()
+
+    >>> def test_function():
+    ...     import sys
+    ...     frame = sys._getframe()
+    ...     frame.f_trace_lines = False
+    ...     import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+    ...     if frame.f_trace_lines != False:
+    ...         print("f_trace_lines is not reset after continue!")
+
+    >>> with PdbTestInput([  # doctest: +NORMALIZE_WHITESPACE
+    ...     'continue'
+    ... ]):
+    ...    test_function()
+    > <doctest test.test_pdb.test_pdb_f_trace_lines[1]>(6)test_function()
+    -> if frame.f_trace_lines != False:
+    (Pdb) continue
+    """
+
 def test_pdb_function_break():
     """Testing the line number of break on function
 
diff --git a/Misc/NEWS.d/next/Library/2023-10-14-20-15-53.gh-issue-80675._M-cQC.rst b/Misc/NEWS.d/next/Library/2023-10-14-20-15-53.gh-issue-80675._M-cQC.rst
new file mode 100644 (file)
index 0000000..a4bc679
--- /dev/null
@@ -0,0 +1 @@
+Set ``f_trace_lines = True`` on all frames upon :func:`pdb.set_trace()`