GDB pretty-printer for GHashTable no longer works
Since #dc983d74, the GHashPrinter
pretty-printer class in glib_gdb.py no longer works, as it's now trying to dereference a gpointer
when trying to access keys/values, which results in an exception thrown.
I've made a simple patch to support small pointer arrays, although I didn't test this in case the arrays are actually small (32bit):
--- a/glib/glib_gdb.py 2019-05-08 00:18:27.000000000 +0200
+++ b/glib/glib_gdb.py 2019-05-16 11:16:50.927116707 +0200
@@ -86,11 +86,27 @@ class GHashPrinter:
"Prints a GHashTable"
class _iterator:
+ class _pointer_array:
+ def __init__(self, ptr, big_items):
+ self._big_items = big_items
+ self._gpointer_type = gdb.lookup_type("gpointer")
+ item_type = self._gpointer_type if self._big_items else gdb.lookup_type("guint")
+
+ self._items = ptr.cast(item_type.pointer())
+
+ def __getitem__(self, item):
+ item = self._items[item]
+
+ if not self._big_items:
+ item = item.cast(self._gpointer_type)
+
+ return item
+
def __init__(self, ht, keys_are_strings):
self.ht = ht
if ht != 0:
- self.keys = ht["keys"]
- self.values = ht["values"]
+ self.keys = self._pointer_array(ht["keys"], ht["have_big_keys"])
+ self.values = self._pointer_array(ht["values"], ht["have_big_values"])
self.hashes = ht["hashes"]
self.size = ht["size"]
self.pos = 0