[llvm-branch-commits] [llvm] b465455 - Avoid fragile type lookups in GDB pretty printer

Moritz Sichert via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 22 06:01:52 PST 2021


Author: Moritz Sichert
Date: 2021-01-22T14:56:32+01:00
New Revision: b46545542b3010749b530f37d24e24a6abdd58e9

URL: https://github.com/llvm/llvm-project/commit/b46545542b3010749b530f37d24e24a6abdd58e9
DIFF: https://github.com/llvm/llvm-project/commit/b46545542b3010749b530f37d24e24a6abdd58e9.diff

LOG: Avoid fragile type lookups in GDB pretty printer

Instead of using the type llvm::StringMapEntry<{stringified_value_type}>
use only the base class llvm::StringMapEntryBase and calculate the
offsets of the member variables manually. The approach with stringifying
the name of the value type is pretty fragile as it can easily break with
local and dependent types.

Differential Revision: https://reviews.llvm.org/D94431

Added: 
    

Modified: 
    llvm/utils/gdb-scripts/prettyprinters.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gdb-scripts/prettyprinters.py b/llvm/utils/gdb-scripts/prettyprinters.py
index 787269c7bb96..b774e336f2fe 100644
--- a/llvm/utils/gdb-scripts/prettyprinters.py
+++ b/llvm/utils/gdb-scripts/prettyprinters.py
@@ -211,7 +211,7 @@ def children(self):
     it = self.val['TheTable']
     end = (it + self.val['NumBuckets'])
     value_ty = self.val.type.template_argument(0)
-    entry_ty = gdb.lookup_type('llvm::StringMapEntry<{}>'.format(value_ty.name))
+    entry_base_ty = gdb.lookup_type('llvm::StringMapEntryBase')
     tombstone = gdb.parse_and_eval('llvm::StringMapImpl::TombstoneIntVal');
 
     while it != end:
@@ -220,15 +220,17 @@ def children(self):
         it = it + 1
         continue
 
-      entry_ptr = it_deref.cast(entry_ty.pointer())
+      entry_ptr = it_deref.cast(entry_base_ty.pointer())
       entry = entry_ptr.dereference()
 
       str_len = entry['keyLength']
-      str_data = (entry_ptr + 1).cast(gdb.lookup_type('char').const().pointer())
+      value_ptr = (entry_ptr + 1).cast(value_ty.pointer())
+      str_data = (entry_ptr + 1).cast(gdb.lookup_type('uintptr_t')) + max(value_ty.sizeof, entry_base_ty.alignof)
+      str_data = str_data.cast(gdb.lookup_type('char').const().pointer())
       string_ref = gdb.Value(struct.pack('PN', int(str_data), int(str_len)), gdb.lookup_type('llvm::StringRef'))
       yield 'key', string_ref
 
-      value = entry['second']
+      value = value_ptr.dereference()
       yield 'value', value
 
       it = it + 1


        


More information about the llvm-branch-commits mailing list