Index: Misc/gdbinit =================================================================== --- Misc/gdbinit (révision 65882) +++ Misc/gdbinit (copie de travail) @@ -31,9 +31,9 @@ set $_i = 0 while $_i < f->f_nlocals if f->f_localsplus + $_i != 0 - set $_names = co->co_varnames - set $_name = PyUnicode_AsString(PyTuple_GetItem($_names, $_i)) - printf "%s:\n", $_name + py_printstr PyTuple_GetItem(co->co_varnames, $_i) + printf ":\n" + # side effect of calling _PyObject_Dump is to dump the object's # info - assigning just prevents gdb from printing the # NULL return value @@ -43,27 +43,10 @@ end end -# A rewrite of the Python interpreter's line number calculator in GDB's -# command language +# print the current frame line number 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 *)((PyStringObject *)$__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 - end - set $__li = $__li + *$__p - set $__p = $__p + 1 - end - printf "%d", $__li + set $__lineno = PyCode_Addr2Line(co, f->f_lasti) + printf "%d", $__lineno end # print the current frame - verbose @@ -72,12 +55,26 @@ pylocals end +define py_decref + set $__obj = $arg0 + set $__obj->ob_refcnt -= 1 + set $__obj = _Py_Dealloc($__obj) +end + +define py_printstr + set $__obj = PyUnicodeUCS2_AsUTF8String($arg0) + printf "%s", ((PyBytesObject*)$__obj)->ob_sval + py_decref $__obj +end + define pyframe - set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval - set $__n = PyUnicode_AsString(co->co_name) - printf "%s (", $__fn + py_printstr co->co_filename + printf " (" lineno - printf "): %s\n", $__n + printf "): " + py_printstr co->co_name + printf "\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