From 9c02ed624ab7e794ccc36a8d1d7fcfe2cff1a854 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 4 Feb 2010 13:54:45 -0500 Subject: Clean up the work-in-progress stuff at the end of the file --- libpython.py | 80 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/libpython.py b/libpython.py index 8e3e0f5..dc93177 100644 --- a/libpython.py +++ b/libpython.py @@ -396,39 +396,6 @@ class FrameInfo: ', '.join(['%s=%s' % (k, stringify(v)) for k, v in self.locals])) ) - -def pyframe(): - fval = PyFrameObjectPtr.from_pyobject_ptr(gdb.selected_frame().read_var('f')) #.dereference() - fi = FrameInfo(fval) - print fi - -def mybt(): - def print_EvalFrameEx(gdbframe): - try: - f = gdbframe.read_var('f') - except ValueError: - print '(unable to print python frame, could not access "f")', - return - - try: - fval = PyFrameObjectPtr.from_pyobject_ptr(f) #.dereference() - fi = FrameInfo(fval) - print fi, - except RuntimeError: - print '(unable to print python frame; corrupt data?)', - - - for i, gdbframe in enumerate(gdb.selected_thread().frames()): - #print dir(gdbframe), gdbframe.name() - print '#%i' % i, - if 'PyEval_EvalFrameEx' == gdbframe.name(): - print_EvalFrameEx(gdbframe) - print ' 0x%x in %s' % (gdbframe.pc(), gdbframe.name()) - -#pyframe() -#if gdb.selected_thread(): -# mybt() - class PyObjectPtrPrinter: "Prints a (PyObject*)" @@ -458,9 +425,12 @@ def pretty_printer_lookup(gdbval): return PyFrameObjectPtrPrinter(gdbval) +# Wire up the pretty-printer +# FIXME: is there a better way to do this than to simply do it on import? gdb.pretty_printers.append(pretty_printer_lookup) """ +Here's how I've been invoking this code: (gdb) python import sys @@ -471,6 +441,44 @@ reload(libpython) end """ -# TODO: -# - write actual backtrace -# - integrate into backtrace hook + +# Remainder of the file is work-in-progress; don't use: +def pyframe(): + ''' + Work towards a reimplementation of "pyframe" from the gdbinit file + ''' + fval = PyFrameObjectPtr.from_pyobject_ptr(gdb.selected_frame().read_var('f')) #.dereference() + fi = FrameInfo(fval) + print fi + +def mybt(): + ''' + Attempt at writing a replacement backtrace hook + Ought to be integrated into pluggable gdb backtrace hook + ''' + def print_EvalFrameEx(gdbframe): + try: + f = gdbframe.read_var('f') + except ValueError: + print '(unable to print python frame, could not access "f")', + return + + try: + fval = PyFrameObjectPtr.from_pyobject_ptr(f) #.dereference() + fi = FrameInfo(fval) + print fi, + except RuntimeError: + print '(unable to print python frame; corrupt data?)', + + + for i, gdbframe in enumerate(gdb.selected_thread().frames()): + #print dir(gdbframe), gdbframe.name() + print '#%i' % i, + if 'PyEval_EvalFrameEx' == gdbframe.name(): + print_EvalFrameEx(gdbframe) + print ' 0x%x in %s' % (gdbframe.pc(), gdbframe.name()) + +#pyframe() +#if gdb.selected_thread(): +# mybt() + -- cgit