1- # -*- ksh -*-
2- #
31# If you use the GNU debugger gdb to debug the Python C runtime, you
42# might find some of the following commands useful. Copy this to your
53# ~/.gdbinit file and it'll get loaded into gdb automatically when you
119# address : 84a7a2c
1210# $1 = void
1311# (gdb)
12+ #
13+ # NOTE: If you have gdb 7 or later, it supports debugging of Python directly
14+ # with embedded macros that you may find superior to what is in here.
15+ # See https://fedoraproject.org/wiki/Features/EasierPythonDebugging
16+ # and http://bugs.python.org/issue8032 for more gdb 7 python information.
17+
18+ # gdb version of Py_DECREF(obj) macro
19+ define py_decref
20+ set $__obj = $arg0
21+ set $__obj->ob_refcnt -= 1
22+ if ($__obj->ob_refcnt == 0)
23+ set $__obj = _Py_Dealloc($__obj)
24+ end
25+ end
1426
1527# Prints a representation of the object to stderr, along with the
1628# number of reference counts it current has and the hex address the
1729# object is allocated at. The argument must be a PyObject*
1830define pyo
19- print _PyObject_Dump($arg0)
31+ # side effect of calling _PyObject_Dump is to dump the object's
32+ # info - assigning just prevents gdb from printing the
33+ # NULL return value
34+ set $_unused_void = _PyObject_Dump($arg0)
2035end
2136
2237# Prints a representation of the object to stderr, along with the
2338# number of reference counts it current has and the hex address the
2439# object is allocated at. The argument must be a PyGC_Head*
2540define pyg
26- print _PyGC_Dump($arg0)
41+ print _PyGC_Dump($arg0)
2742end
2843
2944# print the local variables of the current frame
@@ -34,10 +49,8 @@ define pylocals
3449 set $_names = co->co_varnames
3550 set $_name = _PyUnicode_AsString(PyTuple_GetItem($_names, $_i))
3651 printf "%s:\n", $_name
37- # side effect of calling _PyObject_Dump is to dump the object's
38- # info - assigning just prevents gdb from printing the
39- # NULL return value
40- set $_val = _PyObject_Dump(f->f_localsplus[$_i])
52+ py_decref $_name
53+ pyo f->f_localsplus[$_i]
4154 end
4255 set $_i = $_i + 1
4356 end
0 commit comments