mirror of
https://github.com/python/cpython.git
synced 2024-11-24 10:24:35 +08:00
f65e25b626
svn+ssh://svn.python.org/python/branches/py3k ........ r86134 | georg.brandl | 2010-11-03 08:41:00 +0100 (Mi, 03 Nov 2010) | 1 line A newline in lineno output breaks pyframe output. ........ 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. ........ r86550 | georg.brandl | 2010-11-20 11:24:34 +0100 (Sa, 20 Nov 2010) | 1 line Fix rst markup errors. ........ r86561 | georg.brandl | 2010-11-20 12:47:10 +0100 (Sa, 20 Nov 2010) | 1 line #10460: Update indent.pro to match PEP 7 better. ........ r86562 | georg.brandl | 2010-11-20 14:44:41 +0100 (Sa, 20 Nov 2010) | 1 line #10439: document PyCodec C APIs. ........ r86564 | georg.brandl | 2010-11-20 15:08:53 +0100 (Sa, 20 Nov 2010) | 1 line #10460: an even better indent.pro. ........ r86565 | georg.brandl | 2010-11-20 15:16:17 +0100 (Sa, 20 Nov 2010) | 1 line socket.gethostbyname(socket.gethostname()) can fail when host name resolution is not set up correctly; do not fail test_socket if this is the case. ........ r86705 | georg.brandl | 2010-11-23 08:54:19 +0100 (Di, 23 Nov 2010) | 1 line #10468: document Unicode exception creation and access functions. ........ r86708 | georg.brandl | 2010-11-23 09:37:54 +0100 (Di, 23 Nov 2010) | 2 lines #10511: clarification of what heaps are; suggested by Johannes Hoff. ........ r86713 | georg.brandl | 2010-11-23 19:14:57 +0100 (Di, 23 Nov 2010) | 1 line assert.h is also included. Thanks to Savio Sena. ........
163 lines
4.7 KiB
Plaintext
163 lines
4.7 KiB
Plaintext
# 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)
|
|
#
|
|
# 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.
|
|
# See Tools/gdb/libpython.py and http://bugs.python.org/issue8032.
|
|
|
|
# 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
|
|
# 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)
|
|
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
|
|
print _PyGC_Dump($arg0)
|
|
end
|
|
|
|
# print the local variables of the current frame
|
|
define pylocals
|
|
set $_i = 0
|
|
while $_i < f->f_code->co_nlocals
|
|
if f->f_localsplus + $_i != 0
|
|
set $_names = co->co_varnames
|
|
set $_name = _PyUnicode_AsString(PyTuple_GetItem($_names, $_i))
|
|
printf "%s:\n", $_name
|
|
pyo f->f_localsplus[$_i]
|
|
end
|
|
set $_i = $_i + 1
|
|
end
|
|
end
|
|
|
|
# A rewrite of the Python interpreter's line number calculator in GDB's
|
|
# command language
|
|
define lineno
|
|
set $__continue = 1
|
|
set $__co = f->f_code
|
|
set $__lasti = f->f_lasti
|
|
set $__sz = ((PyVarObject *)$__co->co_lnotab)->ob_size/2
|
|
set $__p = (unsigned char *)((PyBytesObject *)$__co->co_lnotab)->ob_sval
|
|
set $__li = $__co->co_firstlineno
|
|
set $__ad = 0
|
|
while ($__sz-1 >= 0 && $__continue)
|
|
set $__sz = $__sz - 1
|
|
set $__ad = $__ad + *$__p
|
|
set $__p = $__p + 1
|
|
if ($__ad > $__lasti)
|
|
set $__continue = 0
|
|
else
|
|
set $__li = $__li + *$__p
|
|
set $__p = $__p + 1
|
|
end
|
|
end
|
|
printf "%d", $__li
|
|
end
|
|
|
|
# print the current frame - verbose
|
|
define pyframev
|
|
pyframe
|
|
pylocals
|
|
end
|
|
|
|
define pyframe
|
|
set $__fn = _PyUnicode_AsString(co->co_filename)
|
|
set $__n = _PyUnicode_AsString(co->co_name)
|
|
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
|
|
if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
|
|
pyframe
|
|
else
|
|
frame
|
|
end
|
|
end
|
|
|
|
# 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 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.
|
|
|
|
# print the entire Python call stack
|
|
define pystack
|
|
while $pc < Py_Main || $pc > Py_GetArgcArgv
|
|
if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
|
|
pyframe
|
|
end
|
|
up-silently 1
|
|
end
|
|
select-frame 0
|
|
end
|
|
|
|
# print the entire Python call stack - verbose mode
|
|
define pystackv
|
|
while $pc < Py_Main || $pc > Py_GetArgcArgv
|
|
if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
|
|
pyframev
|
|
end
|
|
up-silently 1
|
|
end
|
|
select-frame 0
|
|
end
|
|
|
|
# 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
|