Skip to content
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

frame.f_lineno doesn't get updated after local trace function assigned to it #51487

Closed
eggy mannequin opened this issue Oct 29, 2009 · 4 comments
Closed

frame.f_lineno doesn't get updated after local trace function assigned to it #51487

eggy mannequin opened this issue Oct 29, 2009 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@eggy
Copy link
Mannequin

eggy mannequin commented Oct 29, 2009

BPO 7238
Nosy @jcea, @ncoghlan, @xdegaye, @iritkatriel
Files
  • tracer_testcase.py
  • 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-01-18.09:38:25.051>
    created_at = <Date 2009-10-29.17:16:57.647>
    labels = ['interpreter-core', 'type-bug']
    title = "frame.f_lineno doesn't get updated after local trace function assigned to it"
    updated_at = <Date 2022-01-18.09:38:25.050>
    user = 'https://bugs.python.org/eggy'

    bugs.python.org fields:

    activity = <Date 2022-01-18.09:38:25.050>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-18.09:38:25.051>
    closer = 'iritkatriel'
    components = ['Interpreter Core']
    creation = <Date 2009-10-29.17:16:57.647>
    creator = 'eggy'
    dependencies = []
    files = ['15229']
    hgrepos = []
    issue_num = 7238
    keywords = []
    message_count = 4.0
    messages = ['94681', '122279', '175969', '410265']
    nosy_count = 6.0
    nosy_names = ['jcea', 'ncoghlan', 'eggy', 'ysj.ray', 'xdegaye', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue7238'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    @eggy
    Copy link
    Mannequin Author

    eggy mannequin commented Oct 29, 2009

    As you can see, when a local trace function sets f_lineno, f_lineno
    doesn't get updated on subsequent lines. Otherwise it works fine.
    $ python tracer_testcase.py
    12
    12
    12

    13
    14
    15

    The reference manual (for python 2.6) states the following: "f_lineno is
    the current line number of the frame — writing to this from within a
    trace function jumps to the given line (only for the bottom-most frame).
    A debugger can implement a Jump command (aka Set Next Statement) by
    writing to f_lineno.". This is contradictory with the shown results,
    because apparently it doesn't always represent the current line number.

    @eggy eggy mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Oct 29, 2009
    @ysjray
    Copy link
    Mannequin

    ysjray mannequin commented Nov 24, 2010

    It's not a bug. What happens is like this:

    1, You set trace function using sys.settrace(tracer).
    2, When the following func() is called, tracer is called with a "call" event, so the trace function in PyThreadState is set to NULL since "sys.settrace(None)" is execute, but since the return value is a valid local trace function, the frame of called function("func()") has its local trace function.
    3, The called function("func()") executes, though its frame has a local trace function, but it will not be executed since PyThreadState->c_tracefunc is NULL. When you get f_lineno from frame, you get the not refreshed f_lineno value but not the dynamically computed lineno, as the f_lineno's getter function said:
    if(f->f_trace)
    return f->f_lineno;
    else
    return PyCode_Addr2Line(f->f_code, f->f_lasti);

    Here because your frame's local trace function is not executed, the f_lineno is not refreshed.

    4, When the second time func() calls, there is no global trace function. Each time you get the f_lineno, it uses PyCode_Addr2Line() to get the dynamically computed line number.

    I think this situation is so rarely that the doc saying "f_lineno is
    the current line number of the frame" is correct.

    @xdegaye
    Copy link
    Mannequin

    xdegaye mannequin commented Nov 19, 2012

    See also the related bpo-16482.

    @iritkatriel
    Copy link
    Member

    I am unable to reproduce this on 3.11, I get this:

    iritkatriel@Irits-MBP cpython % ./python.exe tracer_testcase.py
    14
    15
    16

    14
    15
    16

    I am also unable to reproduce the problem in the related bpo-16482.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant