Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03efcf2

Browse files
committed
* Applys part of the patch from http://bugs.python.org/issue3631 to add
a py_decref macro, fixup the pyo macro and reuse it and avoid a memory leak introduced by the pylocals macro. * Adds a note about gdb 7 python debugging support with links for more info on that.
1 parent 8690ae5 commit 03efcf2

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

Misc/gdbinit

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
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
@@ -11,19 +9,36 @@
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*
1830
define 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)
2035
end
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*
2540
define pyg
26-
print _PyGC_Dump($arg0)
41+
print _PyGC_Dump($arg0)
2742
end
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

Comments
 (0)