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

Improve gdbinit of Python 2.6 #47881

Closed
vstinner opened this issue Aug 21, 2008 · 12 comments
Closed

Improve gdbinit of Python 2.6 #47881

vstinner opened this issue Aug 21, 2008 · 12 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

BPO 3631
Nosy @loewis, @smontanaro, @gpshead, @vstinner
Files
  • gdbinit_python26.patch: Patch to improve gdbinit macros
  • 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 = 'https://github.com/gpshead'
    closed_at = <Date 2010-10-17.19:44:42.992>
    created_at = <Date 2008-08-21.12:28:59.732>
    labels = ['type-feature']
    title = 'Improve gdbinit of Python 2.6'
    updated_at = <Date 2010-10-17.19:44:42.991>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2010-10-17.19:44:42.991>
    actor = 'gregory.p.smith'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2010-10-17.19:44:42.992>
    closer = 'gregory.p.smith'
    components = ['None']
    creation = <Date 2008-08-21.12:28:59.732>
    creator = 'vstinner'
    dependencies = []
    files = ['11191']
    hgrepos = []
    issue_num = 3631
    keywords = ['patch']
    message_count = 12.0
    messages = ['71627', '71632', '71639', '103795', '118947', '118958', '118961', '118962', '118963', '118964', '118965', '118970']
    nosy_count = 5.0
    nosy_names = ['loewis', 'skip.montanaro', 'gregory.p.smith', 'vstinner', 'thomasvs']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue3631'
    versions = ['Python 2.6']

    @vstinner
    Copy link
    Member Author

    I wrote a patch to improve gdbinit (gdb macros):

    • implement py_decref
    • reuse pyo in pylocals
    • direclty call PyCode_Addr2Line() in lineno instead of a long and
      complex reimplemention in gdb script language
    • avoid memory leak in pylocals: call py_decref($_name)

    See also bpo-3610 (for Python 3.0).

    @vstinner vstinner added the type-feature A feature request or enhancement label Aug 21, 2008
    @smontanaro
    Copy link
    Contributor

    Thanks for the patch. Most of it looks okay except for the rewrite of
    the lineno command. That was written in gdb's command language so
    that you could get a python stack from a core dump, not just from a
    running process. Is there some reason it can't remain as it was
    (changes to line number data structures between versions, perhaps)?

    @vstinner
    Copy link
    Member Author

    @Skip: oh yes, you're right about the core file :-) So forget the
    changes in lineno. I first rewrote lineno for Python 3.0 because the
    code changed and it was easier for me to reuse PyCode_Addr2Line() :-)

    @gpshead gpshead self-assigned this Sep 22, 2008
    @vstinner
    Copy link
    Member Author

    Gdb7 now supports Python as a script language, and Python trunk/py3k has a gdb library to debug Python programs. It's much better than the old Misc/gdbinit script.

    Close this issue as "out of date".

    @thomasvs
    Copy link
    Mannequin

    thomasvs mannequin commented Oct 17, 2010

    It's too bad this is closed out of date because
    a) the macro is still there being distributed
    b) it simply hangs!
    c) there's no easy way to figure out that you should be using something else instead.

    I spent a few hours of my life figuring out why it fails and writing an alternative implementation that works for me.

    Instead of just closing this ticket, something should be done about the distributions of python so that they don't suggest something that you consider outdated and doesn't actually work.

    Here's my working version, for reference:

    # THOMAS: the test for between Py_Main and Py_GetArgcArgv is because
    # code is in that order in the C file; see Modules/main.c and its comment
    # print the entire Python call stack
    # same for eval in Python/ceval.c

    # in 2.6, PyEval_EvalFrame is only bw compatible, and code now calls
    # PyEval_EvalFrameEx
    define pystack
    set $__lastpc = $pc
    set $__same = -1

    while 1 == 1
    \# select the highest frame with the same $pc
    \# this will automatically terminate if we reach the top
        while $pc == $__lastpc
            up-silently
        end
        down-silently
    
        if $pc \> PyEval_EvalFrameEx && $pc \< PyEval_EvalCodeEx
        pyframe
        else
            \# frame
        end
        up-silently 1
        set $__lastpc = $pc
    
    end
    select-frame 0
    

    end

    @gpshead
    Copy link
    Member

    gpshead commented Oct 17, 2010

    fyi - for information on using gdb 7 with python see http://bugs.python.org/issue8032

    I'm looking at the .gdbinit improvements regardless as not everyone has gdb 7 (notably OS X).

    @gpshead gpshead reopened this Oct 17, 2010
    @gpshead
    Copy link
    Member

    gpshead commented Oct 17, 2010

    everything except the lineno change from gdbinit_python26.patch has been committed in r85646.

    @gpshead
    Copy link
    Member

    gpshead commented Oct 17, 2010

    and the py_decref in there isn't quite right, fixing...

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 17, 2010

    I think the reference to EasierPythonDebugging is outdated and should be corrected. Dave Malcolm's work is already part of Python, and available with every Python build.

    @gpshead
    Copy link
    Member

    gpshead commented Oct 17, 2010

    do we have official python docs on this that I should point to?

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Oct 17, 2010

    do we have official python docs on this that I should point to?

    I only know of the doc string of libpython.py itself, in Tools/gdb

    @gpshead
    Copy link
    Member

    gpshead commented Oct 17, 2010

    I updated the note in gdbinit to point to Tools/gdb/libpython.py for py3k (3.2) and 2.7.

    Thomas: I didn't do anything with your version of pystack because the existing versions in 3.2 and 2.7 appear to work fine for me.

    @gpshead gpshead closed this as completed Oct 17, 2010
    @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
    type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants