source: trunk/essentials/dev-lang/python/Misc/gdbinit@ 3298

Last change on this file since 3298 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 4.0 KB
Line 
1# -*- ksh -*-
2#
3# If you use the GNU debugger gdb to debug the Python C runtime, you
4# might find some of the following commands useful. Copy this to your
5# ~/.gdbinit file and it'll get loaded into gdb automatically when you
6# start it up. Then, at the gdb prompt you can do things like:
7#
8# (gdb) pyo apyobjectptr
9# <module 'foobar' (built-in)>
10# refcounts: 1
11# address : 84a7a2c
12# $1 = void
13# (gdb)
14
15# Prints a representation of the object to stderr, along with the
16# number of reference counts it current has and the hex address the
17# object is allocated at. The argument must be a PyObject*
18define pyo
19print _PyObject_Dump($arg0)
20end
21
22# Prints a representation of the object to stderr, along with the
23# number of reference counts it current has and the hex address the
24# object is allocated at. The argument must be a PyGC_Head*
25define pyg
26print _PyGC_Dump($arg0)
27end
28
29# print the local variables of the current frame
30define pylocals
31 set $_i = 0
32 while $_i < f->f_nlocals
33 if f->f_localsplus + $_i != 0
34 set $_names = co->co_varnames
35 set $_name = PyString_AsString(PyTuple_GetItem($_names, $_i))
36 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])
41 end
42 set $_i = $_i + 1
43 end
44end
45
46# A rewrite of the Python interpreter's line number calculator in GDB's
47# command language
48define lineno
49 set $__continue = 1
50 set $__co = f->f_code
51 set $__lasti = f->f_lasti
52 set $__sz = ((PyStringObject *)$__co->co_lnotab)->ob_size/2
53 set $__p = (unsigned char *)((PyStringObject *)$__co->co_lnotab)->ob_sval
54 set $__li = $__co->co_firstlineno