8000 gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 by iritkatriel · Pull Request #111368 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 #111368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
03335e6
use RESUME oparg to store exception depth info
iritkatriel Oct 26, 2023
8b4e89d
remove the arg from YIELD_VALUE
iritkatriel Oct 26, 2023
84fbfc3
add docs
iritkatriel Oct 26, 2023
3a111ab
fix test_dis
iritkatriel Oct 26, 2023
6005db5
add news
iritkatriel Oct 26, 2023
00a0cef
regen-all
iritkatriel Oct 26, 2023
50e2d25
Merge branch 'main' into gen_close
iritkatriel Oct 26, 2023
59b3cce
regen-all
iritkatriel Oct 26, 2023
dd8af2d
Merge branch 'main' into gen_close
iritkatriel Oct 27, 2023
c4b4583
Fix typos in import system docs (#111396)
jonathanberthias Oct 27, 2023
c48ec85
gh-111406: Fix broken link to bpython's site (#111407)
zmc Oct 27, 2023
64ca0a9
gh-108765: Include explicitly <unistd.h> in signalmodule.c (#111402)
vstinner Oct 27, 2023
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
Next Next commit
gh-59013: Make line number of function breakpoint more precise (#110582)
  • Loading branch information
gaogaotiantian authored and iritkatriel committed Oct 29, 2023
commit 3aeffca7e12c2fa6cbd396e739d1ef86f32a0196
19 changes: 18 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def do_break(self, arg, temporary = 0):
#use co_name to identify the bkpt (function names
#could be aliased, but co_name is invariant)
funcname = code.co_name
lineno = code.co_firstlineno
lineno = self._find_first_executable_line(code)
filename = code.co_filename
except:
# last thing to try
Expand Down Expand Up @@ -990,6 +990,23 @@ def checkline(self, filename, lineno):
return 0
return 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 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):
"""enable bpnumber [bpnumber ...]

Expand Down
46 changes: 44 additions & 2 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ def test_next_until_return_at_return_event():
> <doctest test.test_pdb.test_next_until_return_at_return_event[1]>(3)test_function()
-> test_function_2()
(Pdb) break test_function_2
Breakpoint 1 at <doctest test.test_pdb.test_next_until_return_at_return_event[0]>:1
Breakpoint 1 at <doctest test.test_pdb.test_next_until_return_at_return_event[0]>:2
(Pdb) continue
> <doctest test.test_pdb.test_next_until_return_at_return_event[0]>(2)test_function_2()
-> x = 1
Expand Down 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 @@ -2350,6 +2350,48 @@ def test_pdb_ambiguous_statements():
(Pdb) continue
"""

def test_pdb_function_break():
"""Testing the line number of break on function

>>> def foo(): pass

>>> def bar():
...
... pass

>>> def boo():
... # comments
... global x
... x = 1

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

>>> def test_function():
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... pass

>>> with PdbTestInput([ # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
... 'break foo',
... 'break bar',
... 'break boo',
... 'break gen',
... 'continue'
... ]):
... 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
"""

def test_pdb_issue_gh_65052():
"""See GH-65052

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make line number of function breakpoint more precise in :mod:`pdb`
0