Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add generator test and use instr after RESUME
  • Loading branch information
gaogaotiantian committed Oct 12, 2023
commit 3955333bc11d8c3b3f8aaa373a4b157b060434ad
11 changes: 9 additions & 2 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,18 @@ def checkline(self, filename, lineno):
def _find_first_executable_line(self, code):
""" Try to find the first executable line of the code object.

Equivalently, find the line number of the instruction that's
after RESUME

Return code.co_firstlineno if no executable line is found.
"""
prev = None
for instr in dis.get_instructions(code):
if instr.opname != 'RESUME' and instr.positions.lineno is not None:
return instr.positions.lineno
if prev is not None and prev.opname == 'RESUME':
if instr.positions.lineno is not None:
return instr.positions.lineno
return code.co_firstlineno
prev = instr
return code.co_firstlineno

def do_enable(self, arg):
Expand Down
10 changes: 8 additions & 2 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ def test_pdb_next_command_in_generator_for_loop():
> <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function()
-> for i in test_gen():
(Pdb) break test_gen
Breakpoint 1 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1
Breakpoint 1 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:2
(Pdb) continue
> <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(2)test_gen()
-> yield 0
Expand Down Expand Up @@ -2364,6 +2364,9 @@ def test_pdb_function_break():
... global x
... x = 1

>>> def gen():
... yield 42

>>> def test_function():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... pass
Expand All @@ -2372,17 +2375,20 @@ def test_pdb_function_break():
... 'break foo',
... 'break bar',
... 'break boo',
... 'break gen',
... 'continue'
... ]):
... test_function()
> <doctest test.test_pdb.test_pdb_function_break[3]>(3)test_function()
> <doctest test.test_pdb.test_pdb_function_break[4]>(3)test_function()
-> pass
(Pdb) break foo
Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[0]>:1
(Pdb) break bar
Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[1]>:3
(Pdb) break boo
Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[2]>:4
(Pdb) break gen
Breakpoint ... at <doctest test.test_pdb.test_pdb_function_break[3]>:2
(Pdb) continue
"""

Expand Down