2001-01-23 12:25:19 -04:00
|
|
|
# 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)
|
2010-10-17 15:38:04 -03:00
|
|
|
#
|
|
|
|
# NOTE: If you have gdb 7 or later, it supports debugging of Python directly
|
|
|
|
# with embedded macros that you may find superior to what is in here.
|
2010-10-17 16:40:59 -03:00
|
|
|
# See Tools/gdb/libpython.py and http://bugs.python.org/issue8032.
|
2010-10-17 15:38:04 -03:00
|
|
|
|
2001-01-23 12:25:19 -04:00
|
|
|
# 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
|
2010-10-17 15:38:04 -03:00
|
|
|
# side effect of calling _PyObject_Dump is to dump the object's
|
|
|
|
# info - assigning just prevents gdb from printing the
|
|
|
|
# NULL return value
|
|
|
|
set $_unused_void = _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
|
2010-10-17 15:38:04 -03: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
|
2009-07-23 06:19:09 -03:00
|
|
|
while $_i < f->f_code->co_nlocals
|
2004-04-02 10:51:13 -04:00
|
|
|
if f->f_localsplus + $_i != 0
|
|
|
|
set $_names = co->co_varnames
|
2008-08-24 17:59:23 -03:00
|
|
|
set $_name = _PyUnicode_AsString(PyTuple_GetItem($_names, $_i))
|
2004-04-02 10:51:13 -04:00
|
|
|
printf "%s:\n", $_name
|
2010-10-17 15:38:04 -03:00
|
|
|
pyo f->f_localsplus[$_i]
|
2004-04-02 10:51:13 -04:00
|
|
|
end
|
|
|
|
set $_i = $_i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-01-08 17:56:43 -04:00
|
|
|
# A rewrite of the Python interpreter's line number calculator in GDB's
|
|
|
|
# command language
|
|
|
|
define lineno
|
2005-09-05 13:16:49 -03:00
|
|
|
set $__continue = 1
|
2005-01-08 17:56:43 -04:00
|
|
|
set $__co = f->f_code
|
|
|
|
set $__lasti = f->f_lasti
|
2007-08-26 23:49:29 -03:00
|
|
|
set $__sz = ((PyVarObject *)$__co->co_lnotab)->ob_size/2
|
2008-08-24 17:59:23 -03:00
|
|
|
set $__p = (unsigned char *)((PyBytesObject *)$__co->co_lnotab)->ob_sval
|
2005-01-08 17:56:43 -04:00
|
|
|
set $__li = $__co->co_firstlineno
|
|
|
|
set $__ad = 0
|
2005-09-05 13:16:49 -03:00
|
|
|
while ($__sz-1 >= 0 && $__continue)
|
2005-01-08 17:56:43 -04:00
|
|
|
set $__sz = $__sz - 1
|
|
|
|
set $__ad = $__ad + *$__p
|
|
|
|
set $__p = $__p + 1
|
|
|
|
if ($__ad > $__lasti)
|
2005-09-05 13:16:49 -03:00
|
|
|
set $__continue = 0
|
2005-01-08 17:56:43 -04:00
|
|
|
end
|
|
|
|
set $__li = $__li + *$__p
|
|
|
|
set $__p = $__p + 1
|
|
|
|
end
|
|
|
|
printf "%d", $__li
|
|
|
|
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
|
2008-08-24 17:59:23 -03:00
|
|
|
set $__fn = _PyUnicode_AsString(co->co_filename)
|
|
|
|
set $__n = _PyUnicode_AsString(co->co_name)
|
2005-01-08 17:56:43 -04:00
|
|
|
printf "%s (", $__fn
|
|
|
|
lineno
|
|
|
|
printf "): %s\n", $__n
|
|
|
|
### Uncomment these lines when using from within Emacs/XEmacs so it will
|
|
|
|
### automatically track/display the current Python source line
|
|
|
|
# printf "%c%c%s:", 032, 032, $__fn
|
|
|
|
# lineno
|
|
|
|
# printf ":1\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
### Use these at your own risk. It appears that a bug in gdb causes it
|
|
|
|
### to crash in certain circumstances.
|
|
|
|
|
|
|
|
#define up
|
|
|
|
# up-silently 1
|
|
|
|
# printframe
|
|
|
|
#end
|
|
|
|
|
|
|
|
#define down
|
|
|
|
# down-silently 1
|
|
|
|
# printframe
|
|
|
|
#end
|
|
|
|
|
|
|
|
define printframe
|
2005-08-12 21:28:41 -03:00
|
|
|
if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
|
2005-01-08 17:56:43 -04:00
|
|
|
pyframe
|
|
|
|
else
|
|
|
|
frame
|
|
|
|
end
|
2004-04-02 10:51:13 -04:00
|
|
|
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
|
2010-01-13 21:14:50 -04:00
|
|
|
# statement tests to see if we are in PyEval_EvalFrameEx().
|
|
|
|
|
|
|
|
# Note: The name of the main interpreter function and the function which
|
|
|
|
# follow it has changed over time. This version of pystack works with this
|
|
|
|
# version of Python. If you try using it with older or newer versions of
|
|
|
|
# the interpreter you may will have to change the functions you compare with
|
|
|
|
# $pc.
|
2004-04-02 10:53:55 -04:00
|
|
|
|
2004-04-02 10:51:13 -04:00
|
|
|
# print the entire Python call stack
|
|
|
|
define pystack
|
|
|
|
while $pc < Py_Main || $pc > Py_GetArgcArgv
|
2010-01-13 21:14:50 -04:00
|
|
|
if $pc > PyEval_EvalFrameEx && $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
|
2010-01-13 21:14:50 -04:00
|
|
|
if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
|
2004-11-17 12:04:15 -04:00
|
|
|
pyframev
|
|
|
|
end
|
|
|
|
up-silently 1
|
|
|
|
end
|
|
|
|
select-frame 0
|
|
|
|
end
|
Merged revisions 70912,70944,70968,71033,71041,71208,71263,71286,71395-71396,71405-71406,71485,71492,71494 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70912 | georg.brandl | 2009-03-31 17:35:46 -0500 (Tue, 31 Mar 2009) | 1 line
#5617: add a handy function to print a unicode string to gdbinit.
........
r70944 | georg.brandl | 2009-03-31 23:32:39 -0500 (Tue, 31 Mar 2009) | 1 line
#5631: add upload to list of possible commands, which is presented in --help-commands.
........
r70968 | michael.foord | 2009-04-01 13:25:38 -0500 (Wed, 01 Apr 2009) | 1 line
Adding Wing project file
........
r71033 | brett.cannon | 2009-04-01 22:34:53 -0500 (Wed, 01 Apr 2009) | 3 lines
Fix two issues introduced by issue #71031 by changing the signature of
PyImport_AppendInittab() to take a const char *.
........
r71041 | jesse.noller | 2009-04-02 00:17:26 -0500 (Thu, 02 Apr 2009) | 1 line
Add custom initializer argument to multiprocess.Manager*, courtesy of lekma
........
r71208 | michael.foord | 2009-04-04 20:15:01 -0500 (Sat, 04 Apr 2009) | 4 lines
Change the way unittest.TestSuite use their tests to always access them through iteration. Non behavior changing, this allows you to create custom subclasses that override __iter__.
Issue #5693
........
r71263 | michael.foord | 2009-04-05 14:19:28 -0500 (Sun, 05 Apr 2009) | 4 lines
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
........
r71286 | tarek.ziade | 2009-04-05 17:04:38 -0500 (Sun, 05 Apr 2009) | 1 line
added a simplest test to distutils.spawn._nt_quote_args
........
r71395 | benjamin.peterson | 2009-04-08 08:27:29 -0500 (Wed, 08 Apr 2009) | 1 line
these must be installed to correctly run tests
........
r71396 | benjamin.peterson | 2009-04-08 08:29:41 -0500 (Wed, 08 Apr 2009) | 1 line
fix syntax
........
r71405 | andrew.kuchling | 2009-04-09 06:22:47 -0500 (Thu, 09 Apr 2009) | 1 line
Add items
........
r71406 | andrew.kuchling | 2009-04-09 06:23:36 -0500 (Thu, 09 Apr 2009) | 1 line
Typo fixes
........
r71485 | andrew.kuchling | 2009-04-11 11:12:23 -0500 (Sat, 11 Apr 2009) | 1 line
Add various items
........
r71492 | georg.brandl | 2009-04-11 13:19:27 -0500 (Sat, 11 Apr 2009) | 1 line
Take credit for a patch of mine.
........
r71494 | benjamin.peterson | 2009-04-11 14:31:00 -0500 (Sat, 11 Apr 2009) | 1 line
ignore py3_test_grammar when compiling the library
........
2009-04-11 17:45:40 -03:00
|
|
|
|
|
|
|
# generally useful macro to print a Unicode string
|
|
|
|
def pu
|
|
|
|
set $uni = $arg0
|
|
|
|
set $i = 0
|
|
|
|
while (*$uni && $i++<100)
|
|
|
|
if (*$uni < 0x80)
|
|
|
|
print *(char*)$uni++
|
|
|
|
else
|
|
|
|
print /x *(short*)$uni++
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|