2001-01-23 12:25:19 -04:00
|
|
|
# -*- ksh -*-
|
|
|
|
#
|
|
|
|
# If you use the GNU debugger gdb to debug the Python C runtime, you
|
|
|
|
# might find some of the following commands useful. Copy this to your
|
|
|
|
# ~/.gdbinit file and it'll get loaded into gdb automatically when you
|
|
|
|
# start it up. Then, at the gdb prompt you can do things like:
|
|
|
|
#
|
|
|
|
# (gdb) pyo apyobjectptr
|
|
|
|
# <module 'foobar' (built-in)>
|
|
|
|
# refcounts: 1
|
|
|
|
# address : 84a7a2c
|
|
|
|
# $1 = void
|
|
|
|
# (gdb)
|
|
|
|
|
|
|
|
# Prints a representation of the object to stderr, along with the
|
|
|
|
# number of reference counts it current has and the hex address the
|
|
|
|
# object is allocated at. The argument must be a PyObject*
|
|
|
|
define pyo
|
2001-01-24 00:18:13 -04:00
|
|
|
print _PyObject_Dump($arg0)
|
2001-01-23 12:25:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Prints a representation of the object to stderr, along with the
|
|
|
|
# number of reference counts it current has and the hex address the
|
|
|
|
# object is allocated at. The argument must be a PyGC_Head*
|
|
|
|
define pyg
|
2001-01-24 00:18:13 -04:00
|
|
|
print _PyGC_Dump($arg0)
|
2001-01-23 12:25:19 -04:00
|
|
|
end
|
2003-10-03 17:56:15 -03:00
|
|
|
|
2004-04-02 10:51:13 -04:00
|
|
|
# print the local variables of the current frame
|
|
|
|
define pylocals
|
|
|
|
set $_i = 0
|
|
|
|
while $_i < f->f_nlocals
|
|
|
|
if f->f_localsplus + $_i != 0
|
|
|
|
set $_names = co->co_varnames
|
|
|
|
set $_name = PyString_AsString(PyTuple_GetItem($_names, $_i))
|
|
|
|
printf "%s:\n", $_name
|
|
|
|
# side effect of calling _PyObject_Dump is to dump the object's
|
|
|
|
# info - assigning just prevents gdb from printing the
|
|
|
|
# NULL return value
|
|
|
|
set $_val = _PyObject_Dump(f->f_localsplus[$_i])
|
|
|
|
end
|
|
|
|
set $_i = $_i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-11-17 12:04:15 -04:00
|
|
|
# print the current frame - verbose
|
|
|
|
define pyframev
|
|
|
|
pyframe
|
|
|
|
pylocals
|
|
|
|
end
|
|
|
|
|
2004-04-02 10:51:13 -04:00
|
|
|
define pyframe
|
2004-11-17 12:04:15 -04:00
|
|
|
set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval
|
|
|
|
set $__n = (char *)((PyStringObject *)co->co_name)->ob_sval
|
2004-04-02 10:51:13 -04:00
|
|
|
printf "%s (%d): %s\n", $__fn, f->f_lineno, $__n
|
|
|
|
end
|
|
|
|
|
2004-04-02 10:53:55 -04:00
|
|
|
# Here's a somewhat fragile way to print the entire Python stack from gdb.
|
|
|
|
# It's fragile because the tests for the value of $pc depend on the layout
|
|
|
|
# of specific functions in the C source code.
|
|
|
|
|
|
|
|
# Explanation of while and if tests: We want to pop up the stack until we
|
|
|
|
# land in Py_Main (this is probably an incorrect assumption in an embedded
|
|
|
|
# interpreter, but the test can be extended by an interested party). If
|
|
|
|
# Py_Main <= $pc <= Py_GetArgcArv is true, $pc is in Py_Main(), so the while
|
|
|
|
# tests succeeds as long as it's not true. In a similar fashion the if
|
|
|
|
# statement tests to see if we are in eval_frame().
|
|
|
|
|
2004-04-02 10:51:13 -04:00
|
|
|
# print the entire Python call stack
|
|
|
|
define pystack
|
|
|
|
while $pc < Py_Main || $pc > Py_GetArgcArgv
|
2004-08-07 17:11:22 -03:00
|
|
|
if $pc > PyEval_EvalFrame && $pc < PyEval_EvalCodeEx
|
2004-04-02 10:51:13 -04:00
|
|
|
pyframe
|
|
|
|
end
|
|
|
|
up-silently 1
|
|
|
|
end
|
|
|
|
select-frame 0
|
|
|
|
end
|
2004-11-17 12:04:15 -04:00
|
|
|
|
|
|
|
# print the entire Python call stack - verbose mode
|
|
|
|
define pystackv
|
|
|
|
while $pc < Py_Main || $pc > Py_GetArgcArgv
|
|
|
|
if $pc > PyEval_EvalFrame && $pc < PyEval_EvalCodeEx
|
|
|
|
pyframev
|
|
|
|
end
|
|
|
|
up-silently 1
|
|
|
|
end
|
|
|
|
select-frame 0
|
|
|
|
end
|