Skip to content

Commit

Permalink
Use co_lines to find executable lines if available
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Dec 4, 2023
1 parent 8c8f9d4 commit 58667e0
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pudb/lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""


import sys
import logging
from datetime import datetime

Expand Down Expand Up @@ -94,17 +95,22 @@ def _init_loggers():
# {{{ breakpoint validity

def generate_executable_lines_for_code(code):
lineno = code.co_firstlineno
yield lineno
# See https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt

for line_incr in code.co_lnotab[1::2]:
# NB: This code is specific to Python 3.6 and higher
# https://github.com/python/cpython/blob/v3.6.0/Objects/lnotab_notes.txt
if line_incr >= 0x80:
line_incr -= 0x100
lineno += line_incr
if sys.version_info >= (3, 10):
for _start, _end, lineno in code.co_lines():
if lineno is not None:
yield lineno
else:
lineno = code.co_firstlineno
yield lineno
# See https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt

for line_incr in code.co_lnotab[1::2]:
# NB: This code is specific to Python 3.6 and higher
# https://github.com/python/cpython/blob/v3.6.0/Objects/lnotab_notes.txt
if line_incr >= 0x80:
line_incr -= 0x100
lineno += line_incr
yield lineno


def get_executable_lines_for_codes_recursive(codes):
Expand Down

0 comments on commit 58667e0

Please sign in to comment.