This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve gdbinit of Python 2.6
Type: enhancement Stage:
Components: None Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: gregory.p.smith, loewis, skip.montanaro, thomasvs, vstinner
Priority: normal Keywords: patch

Created on 2008-08-21 12:28 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gdbinit_python26.patch vstinner, 2008-08-21 12:28 Patch to improve gdbinit macros
Messages (12)
msg71627 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-08-21 12:28
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 #3610 (for Python 3.0).
msg71632 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2008-08-21 12:59
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)?
msg71639 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-08-21 13:39
@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() :-)
msg103795 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-20 23:46
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".
msg118947 - (view) Author: Thomas Vander Stichele (thomasvs) Date: 2010-10-17 16:04
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
msg118958 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2010-10-17 18:05
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).
msg118961 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2010-10-17 18:51
everything except the lineno change from gdbinit_python26.patch has been committed in r85646.
msg118962 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2010-10-17 18:55
and the py_decref in there isn't quite right, fixing...
msg118963 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-10-17 18:59
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.
msg118964 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2010-10-17 19:03
do we have official python docs on this that I should point to?
msg118965 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-10-17 19:10
> 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
msg118970 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2010-10-17 19:44
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.
History
Date User Action Args
2022-04-11 14:56:37adminsetgithub: 47881
2010-10-17 19:44:42gregory.p.smithsetstatus: open -> closed
resolution: accepted
messages: + msg118970
2010-10-17 19:10:22loewissetmessages: + msg118965
2010-10-17 19:03:23gregory.p.smithsetmessages: + msg118964
2010-10-17 18:59:03loewissetnosy: + loewis
messages: + msg118963
2010-10-17 18:55:29gregory.p.smithsetmessages: + msg118962
2010-10-17 18:51:31gregory.p.smithsetmessages: + msg118961
2010-10-17 18:05:56gregory.p.smithsetstatus: closed -> open
resolution: out of date -> (no value)
messages: + msg118958
2010-10-17 16:04:59thomasvssetnosy: + thomasvs
messages: + msg118947
2010-04-20 23:46:25vstinnersetstatus: open -> closed
resolution: out of date
messages: + msg103795
2008-09-22 01:21:44gregory.p.smithsetpriority: normal
assignee: gregory.p.smith
nosy: + gregory.p.smith
2008-08-21 13:39:19vstinnersetmessages: + msg71639
2008-08-21 12:59:16skip.montanarosetnosy: + skip.montanaro
messages: + msg71632
2008-08-21 12:30:00vstinnersettype: enhancement
components: + None
versions: + Python 2.6
2008-08-21 12:29:00vstinnercreate