diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-09-14 18:07:30 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-09-14 18:07:30 +0100 |
commit | 0384d71960af4c2124c50b82fd6c0a9bad1ab44d (patch) | |
tree | 55fad643d29b75ed934ce688471a316e02a6c034 | |
parent | 30f116fd2d20cbeb13ed20f1f780d8aa92e67983 (diff) |
old WiP: a gdb hook for libdbuswip-gdb
-rw-r--r-- | dbus/gdb_dbus.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/dbus/gdb_dbus.py b/dbus/gdb_dbus.py new file mode 100644 index 00000000..8b3675c8 --- /dev/null +++ b/dbus/gdb_dbus.py @@ -0,0 +1,67 @@ +import gdb + +class DBusHashIter(object): + def __init__(self, val): + self.val = val + self.bucket = None + self.entry = None + self.next_entry = None + self.next_bucket = 0 + + def __iter__(self): + return self + + def next(self): + while self.next_entry is None: + if self.next_bucket > long(self.val['n_buckets']): + self.entry = None + self.val = None + self.bucket = None + raise StopIteration + + self.bucket = self.val['buckets'][self.next_bucket].address + assert self.bucket is not None + self.next_entry = self.bucket.dereference() + self.next_bucket = self.next_bucket + 1 + + assert self.next_entry is not None + assert self.bucket is not None + + self.entry = self.next_entry + self.next_entry = self.next_entry['next'] + + # FIXME: assumes string keys + return (self.entry['key'].cast(gdb.lookup_type('char').pointer()), self.entry['value'].cast(gdb.lookup_type('DBusList').pointer().pointer())) + +class DBusHashPrinter(object): + def __init__(self, val): + self.val = val + + def to_string(self): + return 'DBusHash with %d entries' % (self.val['n_entries']) + + def display_hint(self): + return 'map' + + def children(self): + kids = [] + + for kid in DBusHashIter(self.val): + kids.append(kid[0]) + kids.append(kid[1]) + + return kids + +def dbus_lookup_function(val): + lookup_tag = str(val.type) + + Printer = { + 'DBusHashTable *': DBusHashPrinter, + }.get(lookup_tag, None) + + if Printer is not None: + return Printer(val) + + return None + +gdb.current_progspace().pretty_printers.append(dbus_lookup_function) |