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

Incorrect stacktrace from pdb #61897

Closed
donaldcallen mannequin opened this issue Apr 11, 2013 · 5 comments
Closed

Incorrect stacktrace from pdb #61897

donaldcallen mannequin opened this issue Apr 11, 2013 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@donaldcallen
Copy link
Mannequin

donaldcallen mannequin commented Apr 11, 2013

BPO 17697
Nosy @ned-deily, @asmeurer, @xdegaye
Files
  • python_bug.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 = None
    created_at = <Date 2013-04-11.15:07:39.468>
    labels = ['type-bug', 'library']
    title = 'Incorrect stacktrace from pdb'
    updated_at = <Date 2015-05-08.00:14:38.192>
    user = 'https://bugs.python.org/donaldcallen'

    bugs.python.org fields:

    activity = <Date 2015-05-08.00:14:38.192>
    actor = 'Aaron.Meurer'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-04-11.15:07:39.468>
    creator = 'donaldcallen'
    dependencies = []
    files = ['29777']
    hgrepos = []
    issue_num = 17697
    keywords = []
    message_count = 4.0
    messages = ['186561', '186581', '186584', '186637']
    nosy_count = 5.0
    nosy_names = ['ikelly', 'ned.deily', 'Aaron.Meurer', 'xdegaye', 'donaldcallen']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17697'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    @donaldcallen
    Copy link
    Mannequin Author

    donaldcallen mannequin commented Apr 11, 2013

    Give the attached file execute permission and run it. At the first breakpoint, the backtrace will be correct. Continue. At the second breakpoint, a backtrace will show the foo('first call') on the stack when, in fact, the call came from foo('second call'), as verified by the printed message.

    I am running this on an up-to-date 64-bit Arch Linux system. Python 3.3.1.

    @donaldcallen donaldcallen mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 11, 2013
    @ikelly
    Copy link
    Mannequin

    ikelly mannequin commented Apr 11, 2013

    The bug also occurs using 32-bit Python 3.3.1 on Windows 7.

    @ned-deily
    Copy link
    Member

    On python-list, Robert Kern used "where" to demonstrate the problem:

    $ python pdbbug.py
    first call
    --Return--
     > /Users/rkern/scratch/pdbbug.py(4)foo()->None
    -> pdb.set_trace()
    (Pdb) where
       /Users/rkern/scratch/pdbbug.py(5)<module>()
    -> foo('first call')
     > /Users/rkern/scratch/pdbbug.py(4)foo()->None
    -> pdb.set_trace()
    (Pdb) c
    second call
    --Return--
     > /Users/rkern/scratch/pdbbug.py(4)foo()->None
    -> pdb.set_trace()
    (Pdb) where
       /Users/rkern/scratch/pdbbug.py(5)<module>()
    -> foo('first call')
     > /Users/rkern/scratch/pdbbug.py(4)foo()->None
    -> pdb.set_trace()
    (Pdb)

    Searching other open pdb issues, applying the suggested fix from bpo-16482 seems to correct the problem here.

    @xdegaye
    Copy link
    Mannequin

    xdegaye mannequin commented Apr 12, 2013

    The call to set_trace() installs a local trace function on all the
    frames of the stack, including on the oldest frame, i.e. the module
    level frame. This causes the invocation of frame_settrace() in
    frameobject.c and the module frame f_lineno is evaluated by
    PyCode_Addr2Line() (this happens only on the first call to set_trace()
    since the module frame local trace is never removed).

    Next, the 'continue' command sets the global trace function to None
    and removes the local trace function of all the frames of the stack,
    *except* the module frame (see set_continue() in bdb.py).

    On printing the stack with the 'where' command, the bdb get_stack()
    function invokes frame_getlineno() that calls PyFrame_GetLineNumber()
    that assumes that the module frame f_lineno is correct since it has a
    local trace function. But as the global trace function has been set
    to None by the 'continue' command, f_lineno is not updated by
    the interpreter tracing code when running the module level frame.
    Hence the problem.

    The root cause is that PyFrame_GetLineNumber assumes incorrectly that
    when a frame has a local trace function, its f_lineno is correct.

    bpo-7238 and bpo-17277 are also related to this issue.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @gaogaotiantian
    Copy link
    Member

    This is already fixed somewhere along the way. Not reproducible in Python 3.13. Close for done.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants