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:47:43 -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:42:46 -03:00
|
|
|
# See Tools/gdb/libpython.py and http://bugs.python.org/issue8032.
|
2010-10-17 15:47:43 -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:47:43 -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:47:43 -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:17: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
|
|
|
|
set $_name = PyString_AsString(PyTuple_GetItem($_names, $_i))
|
|
|
|
printf "%s:\n", $_name
|
2010-10-17 15:47:43 -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
|
|
|
|
set $__sz = ((PyStringObject *)$__co->co_lnotab)->ob_size/2
|
|
|
|
set $__p = (unsigned char *)((PyStringObject *)$__co->co_lnotab)->ob_sval
|
|
|
|
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
|
Merged revisions 85768-85771,85773,85777,85823,85825 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85768 | georg.brandl | 2010-10-21 14:59:14 +0200 (Do, 21 Okt 2010) | 1 line
#9919: fix off-by-one error in lineno command in Misc/gdbinit; also add newline to its output.
........
r85769 | georg.brandl | 2010-10-21 15:01:23 +0200 (Do, 21 Okt 2010) | 1 line
Fix missing import.
........
r85770 | georg.brandl | 2010-10-21 15:29:10 +0200 (Do, 21 Okt 2010) | 1 line
#3077: fix h2py substitution of character literals.
........
r85771 | georg.brandl | 2010-10-21 15:34:51 +0200 (Do, 21 Okt 2010) | 1 line
#1203650: allow larger list of files in windows makefile for freeze.
........
r85773 | georg.brandl | 2010-10-21 15:45:52 +0200 (Do, 21 Okt 2010) | 1 line
#4829: better error message for invalid file mode
........
r85777 | georg.brandl | 2010-10-21 17:44:51 +0200 (Do, 21 Okt 2010) | 1 line
Add .hgeol file for the Mercurial EOL extension.
........
r85823 | georg.brandl | 2010-10-24 16:32:45 +0200 (So, 24 Okt 2010) | 1 line
Fix style.
........
r85825 | georg.brandl | 2010-10-24 17:16:02 +0200 (So, 24 Okt 2010) | 1 line
Add documentation about the default warnings filters.
........
2010-11-26 04:10:41 -04:00
|
|
|
else
|
|
|
|
set $__li = $__li + *$__p
|
|
|
|
set $__p = $__p + 1
|
2005-01-08 17:56:43 -04:00
|
|
|
end
|
|
|
|
end
|
Merged revisions 85843,85849-85850,85867,85907,85914,86134,86187,86315-86316,86390,86424-86425,86428 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85843 | georg.brandl | 2010-10-26 08:59:23 +0200 (Di, 26 Okt 2010) | 1 line
Markup fix.
........
r85849 | georg.brandl | 2010-10-26 21:31:06 +0200 (Di, 26 Okt 2010) | 1 line
#10200: typo.
........
r85850 | georg.brandl | 2010-10-26 21:58:11 +0200 (Di, 26 Okt 2010) | 1 line
#10200: typo.
........
r85867 | georg.brandl | 2010-10-27 22:01:51 +0200 (Mi, 27 Okt 2010) | 1 line
Add David.
........
r85907 | georg.brandl | 2010-10-29 06:54:13 +0200 (Fr, 29 Okt 2010) | 1 line
#10222: fix for overzealous AIX compiler.
........
r85914 | georg.brandl | 2010-10-29 08:17:38 +0200 (Fr, 29 Okt 2010) | 1 line
(?:...) is a non-capturing, but still grouping construct.
........
r86134 | georg.brandl | 2010-11-03 08:41:00 +0100 (Mi, 03 Nov 2010) | 1 line
A newline in lineno output breaks pyframe output.
........
r86187 | georg.brandl | 2010-11-05 08:10:41 +0100 (Fr, 05 Nov 2010) | 1 line
Move glossary entry to the right position and fix link.
........
r86315 | georg.brandl | 2010-11-08 12:05:18 +0100 (Mo, 08 Nov 2010) | 1 line
Fix latex conversion glitch in property/feature descriptions.
........
r86316 | georg.brandl | 2010-11-08 12:08:35 +0100 (Mo, 08 Nov 2010) | 1 line
Fix typo.
........
r86390 | georg.brandl | 2010-11-10 08:57:10 +0100 (Mi, 10 Nov 2010) | 1 line
Fix typo.
........
r86424 | georg.brandl | 2010-11-12 07:19:48 +0100 (Fr, 12 Nov 2010) | 1 line
Build a PDF of the FAQs too.
........
r86425 | georg.brandl | 2010-11-12 07:20:12 +0100 (Fr, 12 Nov 2010) | 1 line
#10008: Fix duplicate index entry.
........
r86428 | georg.brandl | 2010-11-12 09:09:26 +0100 (Fr, 12 Nov 2010) | 1 line
Fix weird line block in table.
........
2010-11-26 04:20:18 -04:00
|
|
|
printf "%d", $__li
|
2005-01-08 17:56:43 -04:00
|
|
|
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
|
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:12:34 -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:12:34 -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:12:34 -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
|
2009-03-31 19:35:46 -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
|