gobject.py: Don't install frame filters when GDB does not support them

Stock GDB (both versions 7.0 and 7.1) does not come with the new
backtrace code and python API. To prevent an ugly python backtrace when
auto-loading gobject.py, let's catch the exception and not register the
FrameWrapper and the FrameFilter.

https://bugzilla.gnome.org/show_bug.cgi?id=613732
This commit is contained in:
Damien Lespiau 2010-03-23 15:18:12 +00:00 committed by Colin Walters
parent 4846fd923d
commit 91d4659bbf

View File

@ -1,7 +1,15 @@
import os.path
import gdb import gdb
import glib import glib
try:
import gdb.backtrace import gdb.backtrace
import gdb.command.backtrace import gdb.command.backtrace
except ImportError:
print(os.path.basename(__file__) + ": gdb was not built with "
"custom backtrace support, disabling.")
HAVE_GDB_BACKTRACE = 0
else:
HAVE_GDB_BACKTRACE = 1
# This is not quite right, as local vars may override symname # This is not quite right, as local vars may override symname
def read_global_var (symname): def read_global_var (symname):
@ -107,6 +115,7 @@ class GFrameWrapper:
return getattr (self.frame, name) return getattr (self.frame, name)
# Monkey patch FrameWrapper to avoid IA__ in symbol names # Monkey patch FrameWrapper to avoid IA__ in symbol names
if HAVE_GDB_BACKTRACE:
old__init__ = gdb.command.backtrace.FrameWrapper.__init__ old__init__ = gdb.command.backtrace.FrameWrapper.__init__
def monkey_patched_init(self, frame): def monkey_patched_init(self, frame):
name = frame.name() name = frame.name()
@ -301,5 +310,6 @@ def register (obj):
if obj == None: if obj == None:
obj = gdb obj = gdb
if HAVE_GDB_BACKTRACE:
gdb.backtrace.push_frame_filter (GFrameFilter) gdb.backtrace.push_frame_filter (GFrameFilter)
obj.pretty_printers.append(pretty_printer_lookup) obj.pretty_printers.append(pretty_printer_lookup)