# 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.define pyo# side effect of calling _PyObject_Dump is to dump the object's# info - assigning just prevents gdb from printing the# NULL return valueset $_unused_void = _PyObject_Dump($arg0)enddocument pyoPrints a representation of the object to stderr, along with thenumber of reference counts it currently has and the hex address theobject is allocated at. The argument must be a PyObject*enddefine pygprint _PyGC_Dump($arg0)enddocument pygPrints a representation of the object to stderr, along with thenumber of reference counts it currently has and the hex address theobject is allocated at. The argument must be a PyGC_Head*enddefine pylocalsset $_i = 0while $_i < f->f_code->co_nlocalsif f->f_localsplus + $_i != 0set $_names = f->f_code->co_varnamesset $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i))printf "%s:\n", $_namepyo f->f_localsplus[$_i]endset $_i = $_i + 1endenddocument pylocalsPrint the local variables of the current frame.end# A rewrite of the Python interpreter's line number calculator in GDB's# command languagedefine linenoset $__continue = 1set $__co = f->f_codeset $__lasti = f->f_lastiset $__sz = ((PyVarObject *)$__co->co_lnotab)->ob_size/2set $__p = (unsigned char *)((PyBytesObject *)$__co->co_lnotab)->ob_svalset $__li = $__co->co_firstlinenoset $__ad = 0while ($__sz-1 >= 0 && $__continue)set $__sz = $__sz - 1set $__ad = $__ad + *$__pset $__p = $__p + 1if ($__ad > $__lasti)set $__continue = 0elseset $__li = $__li + *$__pset $__p = $__p + 1endendprintf "%d", $__lienddefine pyframevpyframepylocalsenddocument pyframevPrint the current frame - verboseenddefine pyframeset $__fn = PyUnicode_AsUTF8(f->f_code->co_filename)set $__n = PyUnicode_AsUTF8(f->f_code->co_name)printf "%s (", $__fnlinenoprintf "): %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#enddefine printframeif $pc > PyEval_EvalFrameEx && $pc < _PyEval_EvalFrameDefaultpyframeelseframeendend# 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.define pystackwhile $pc < Py_Main || $pc > Py_GetArgcArgvif $pc > PyEval_EvalFrameEx && $pc < _PyEval_EvalFrameDefaultpyframeendup-silently 1endselect-frame 0enddocument pystackPrint the entire Python call stackenddefine pystackvwhile $pc < Py_Main || $pc > Py_GetArgcArgvif $pc > PyEval_EvalFrameEx && $pc < _PyEval_EvalFrameDefaultpyframevendup-silently 1endselect-frame 0enddocument pystackvPrint the entire Python call stack - verbose modeenddef puset $uni = $arg0set $i = 0while (*$uni && $i++<100)if (*$uni < 0x80)print *(char*)$uni++elseprint /x *(short*)$uni++endendenddocument puGenerally useful macro to print a Unicode stringend
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。