diff options
author | David Malcolm <dmalcolm@redhat.com> | 2010-02-05 18:04:53 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2010-02-05 18:04:53 -0500 |
commit | 36a517ef7848cbd0b3dcc7371f32e47ac4c87eba (patch) | |
tree | eece65b6488fdc8f3aa1f7efe4141405ce2f0b19 | |
parent | 0016aaed5aa060ed4a7c024228c431a44edc39e3 (diff) | |
download | libpython-0.1.tar.gz libpython-0.1.tar.xz libpython-0.1.zip |
Better registration of the pretty-printer; minor cleanupsV0.1
-rw-r--r-- | libpython.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/libpython.py b/libpython.py index 3f843db..afb9869 100644 --- a/libpython.py +++ b/libpython.py @@ -456,21 +456,33 @@ 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: +During development, I've been manually invoking the code in this way: (gdb) python import sys sys.path.append('/home/david/coding/python-gdb') import libpython -reload(libpython) - end + +then reloading it after each edit like this: +(gdb) python reload(libpython) + +The following code should ensure that the prettyprinter is registered +if the code is autoloaded by gdb when visiting libpython.so, provided +that this python file is installed to the same path as the library (or its +.debug file) plus a "-gdb.py" suffix, e.g: + /usr/lib/libpython2.6.so.1.0-gdb.py + /usr/lib/debug/usr/lib/libpython2.6.so.1.0.debug-gdb.py """ +def register (obj): + if obj == None: + obj = gdb + + # Wire up the pretty-printer + obj.pretty_printers.append(pretty_printer_lookup) + +register (gdb.current_objfile ()) # Remainder of the file is work-in-progress; don't use: @@ -482,7 +494,7 @@ def pyframe(): fi = FrameInfo(fval) print fi -def mybt(): +def pybt(): ''' Attempt at writing a replacement backtrace hook Ought to be integrated into pluggable gdb backtrace hook @@ -504,12 +516,8 @@ def mybt(): for i, gdbframe in enumerate(gdb.selected_thread().frames()): #print dir(gdbframe), gdbframe.name() - print '#%i' % i, if 'PyEval_EvalFrameEx' == gdbframe.name(): + print '#%i' % i, print_EvalFrameEx(gdbframe) - print ' 0x%x in %s' % (gdbframe.pc(), gdbframe.name()) - -#pyframe() -#if gdb.selected_thread(): -# mybt() - + print + #print ' 0x%x in %s' % (gdbframe.pc(), gdbframe.name()) |