diff --git a/Lib/bdb.py b/Lib/bdb.py index 0f3eec653baaad..1acf7957f0d669 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -32,6 +32,7 @@ def __init__(self, skip=None): 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 @@ def set_trace(self, frame=None): 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 @@ def set_continue(self): 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. diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 5fef8365f59710..ff9e7c2142fe33 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -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() + > (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 index 00000000000000..a4bc679be905d6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-14-20-15-53.gh-issue-80675._M-cQC.rst @@ -0,0 +1 @@ +Set ``f_trace_lines = True`` on all frames upon :func:`pdb.set_trace()`