Skip to content

missing frame.f_lineno on JUMP_ABSOLUTE #91241

Closed

Description

@graingert
mannequin
BPO 47085
Nosy @nedbat, @markshannon, @graingert

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2022-03-22.11:00:07.217>
created_at = <Date 2022-03-21.19:21:07.574>
labels = ['invalid', '3.10', '3.11']
title = 'missing frame.f_lineno on JUMP_ABSOLUTE'
updated_at = <Date 2022-03-22.11:00:07.216>
user = 'https://github.com/graingert'

bugs.python.org fields:

activity = <Date 2022-03-22.11:00:07.216>
actor = 'Mark.Shannon'
assignee = 'none'
closed = True
closed_date = <Date 2022-03-22.11:00:07.217>
closer = 'Mark.Shannon'
components = []
creation = <Date 2022-03-21.19:21:07.574>
creator = 'graingert'
dependencies = []
files = []
hgrepos = []
issue_num = 47085
keywords = []
message_count = 2.0
messages = ['415697', '415759']
nosy_count = 3.0
nosy_names = ['nedbat', 'Mark.Shannon', 'graingert']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue47085'
versions = ['Python 3.10', 'Python 3.11']

Activity

  1. graingert commented on Mar 21, 2022

    graingertmannequin
    MannequinAuthor

    the following code prints:

    import sys
    import dis
    
    import pprint
    
    def demo():
        for i in range(1):
            if i >= 0:
                pass
    
    
    class Tracer:
        def __init__(self):
            self.events = []
    
        def trace(self, frame, event, arg):
            self.events.append((frame.f_lineno, frame.f_lasti, event))
            frame.f_trace_lines = True
            frame.f_trace_opcodes = True
            return self.trace
    
    def main():
        t = Tracer()
        old_trace = sys.gettrace()
        try:
            sys.settrace(t.trace)
            demo()
        finally:
            sys.settrace(old_trace)
        dis.dis(demo)
        pprint.pp(t.events)
    
    
    if __name__ == "__main__":
        sys.exit(main())

    7 0 LOAD_GLOBAL 0 (range)
    2 LOAD_CONST 1 (1)
    4 CALL_FUNCTION 1
    6 GET_ITER
    >> 8 FOR_ITER 7 (to 24)
    10 STORE_FAST 0 (i)

    8 12 LOAD_FAST 0 (i)
    14 LOAD_CONST 2 (0)
    16 COMPARE_OP 5 (>=)
    18 POP_JUMP_IF_FALSE 11 (to 22)

    9 20 NOP
    >> 22 JUMP_ABSOLUTE 4 (to 8)

    7 >> 24 LOAD_CONST 0 (None)
    26 RETURN_VALUE
    [(6, -1, 'call'),
    (7, 0, 'line'),
    (7, 0, 'opcode'),
    (7, 2, 'opcode'),
    (7, 4, 'opcode'),
    (7, 6, 'opcode'),
    (7, 8, 'opcode'),
    (7, 10, 'opcode'),
    (8, 12, 'line'),
    (8, 12, 'opcode'),
    (8, 14, 'opcode'),
    (8, 16, 'opcode'),
    (8, 18, 'opcode'),
    (9, 20, 'line'),
    (9, 20, 'opcode'),
    (None, 22, 'opcode'),
    (7, 8, 'line'),
    (7, 8, 'opcode'),
    (7, 24, 'opcode'),
    (7, 26, 'opcode'),
    (7, 26, 'return')]

    but I'd expect (9, 22, 'opcode') instead of (None, 22, 'opcode'),

  2. markshannon commented on Mar 22, 2022

    @markshannon
    Member

    The JUMP_ABSOLUTE doesn't have a line number, as it doesn't correspond to any source.

    The jump back to the top could follow either the `if i >= 0:` or the `pass`, so cannot have a line number.

    Don't expect every bytecode to map directly back to the source, especially if it cannot raise an exception.

    Per-line tracing is well defined by PEP-626. Per-opcode tracing is not.

  3. transferred this issue fromon Apr 10, 2022
  4. graingert commented on Jul 19, 2022

    @graingert
    ContributorAuthor

    looks like this was fixed by ddc4a78 #93229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of life3.11only security fixes

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions