mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-59013: Make line number of function breakpoint more precise (#110582)
This commit is contained in:
parent
77bb0d5f50
commit
1c9a0c4079
3 changed files with 63 additions and 3 deletions
19
Lib/pdb.py
19
Lib/pdb.py
|
@ -887,7 +887,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
#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
|
||||
|
@ -990,6 +990,23 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
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 ...]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue