Skip to content

Commit 37b3d29

Browse files
Stop on calling frame unconditionally for inline breakpoints
1 parent 6c450f4 commit 37b3d29

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

Lib/bdb.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ def dispatch_opcode(self, frame, arg):
215215
If the debugger stops on the current opcode, invoke
216216
self.user_opcode(). Raise BdbQuit if self.quitting is set.
217217
Return self.trace_dispatch to continue tracing in this scope.
218+
219+
Opcode event will always trigger the user calback. For now the only
220+
opcode event is from an inline set_trace() and we want to stop there
221+
unconditionally.
218222
"""
219-
if self.stop_here(frame) or self.break_here(frame):
220-
self.user_opcode(frame)
221-
if self.quitting: raise BdbQuit
223+
self.user_opcode(frame)
224+
if self.quitting: raise BdbQuit
222225
return self.trace_dispatch
223226

224227
# Normally derived classes don't override the following

Lib/test/test_pdb.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,6 +4341,28 @@ def test_quit(self):
43414341
# The quit prompt should be printed exactly twice
43424342
self.assertEqual(stdout.count("Quit anyway"), 2)
43434343

4344+
def test_set_trace_with_skip(self):
4345+
"""GH-82897
4346+
Inline set_trace() should break unconditionally. This example is a
4347+
bit oversimplified, but as `pdb.set_trace()` uses the previous Pdb
4348+
instance, it's possible that we had a previous pdb instance with
4349+
skip values when we use `pdb.set_trace()` - it would be confusing
4350+
to users when such inline breakpoints won't break immediately.
4351+
"""
4352+
script = textwrap.dedent("""
4353+
import pdb
4354+
def foo():
4355+
x = 40 + 2
4356+
pdb.Pdb(skip=['__main__']).set_trace()
4357+
foo()
4358+
""")
4359+
commands = """
4360+
p x
4361+
c
4362+
"""
4363+
stdout, _ = self._run_script(script, commands)
4364+
self.assertIn("42", stdout)
4365+
43444366

43454367
@support.requires_subprocess()
43464368
class PdbTestReadline(unittest.TestCase):

0 commit comments

Comments
 (0)