[glib/glib-2-38] gobject.py: Don't install frame filters when GDB does not support them



commit 8c2f7c09f3ce66fa53bbfe1eb2d8de1c138216e6
Author: Damien Lespiau <damien lespiau intel com>
Date:   Tue Mar 23 15:18:12 2010 +0000

    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

 gobject/gobject.py |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/gobject/gobject.py b/gobject/gobject.py
index b96d150..ce2a7f7 100644
--- a/gobject/gobject.py
+++ b/gobject/gobject.py
@@ -1,7 +1,15 @@
+import os.path
 import gdb
 import glib
-import gdb.backtrace
-import gdb.command.backtrace
+try:
+    import gdb.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
 def read_global_var (symname):
@@ -107,13 +115,14 @@ class GFrameWrapper:
         return getattr (self.frame, name)
 
 # Monkey patch FrameWrapper to avoid IA__ in symbol names
-old__init__ = gdb.command.backtrace.FrameWrapper.__init__
-def monkey_patched_init(self, frame):
-    name = frame.name()
-    if name and name.startswith("IA__"):
-        frame = GFrameWrapper(frame)
-    old__init__(self,frame)
-gdb.command.backtrace.FrameWrapper.__init__ = monkey_patched_init
+if HAVE_GDB_BACKTRACE:
+    old__init__ = gdb.command.backtrace.FrameWrapper.__init__
+    def monkey_patched_init(self, frame):
+        name = frame.name()
+        if name and name.startswith("IA__"):
+            frame = GFrameWrapper(frame)
+        old__init__(self,frame)
+    gdb.command.backtrace.FrameWrapper.__init__ = monkey_patched_init
 
 class DummyFrame:
     def __init__ (self, frame):
@@ -301,5 +310,6 @@ def register (obj):
     if obj == None:
         obj = gdb
 
-    gdb.backtrace.push_frame_filter (GFrameFilter)
+    if HAVE_GDB_BACKTRACE:
+        gdb.backtrace.push_frame_filter (GFrameFilter)
     obj.pretty_printers.append(pretty_printer_lookup)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]