Skip to content

Commit b465455

Browse files
committed
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
1 parent 2a8cbdd commit b465455

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvm/utils/gdb-scripts/prettyprinters.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def children(self):
211211
it = self.val['TheTable']
212212
end = (it + self.val['NumBuckets'])
213213
value_ty = self.val.type.template_argument(0)
214-
entry_ty = gdb.lookup_type('llvm::StringMapEntry<{}>'.format(value_ty.name))
214+
entry_base_ty = gdb.lookup_type('llvm::StringMapEntryBase')
215215
tombstone = gdb.parse_and_eval('llvm::StringMapImpl::TombstoneIntVal');
216216

217217
while it != end:
@@ -220,15 +220,17 @@ def children(self):
220220
it = it + 1
221221
continue
222222

223-
entry_ptr = it_deref.cast(entry_ty.pointer())
223+
entry_ptr = it_deref.cast(entry_base_ty.pointer())
224224
entry = entry_ptr.dereference()
225225

226226
str_len = entry['keyLength']
227-
str_data = (entry_ptr + 1).cast(gdb.lookup_type('char').const().pointer())
227+
value_ptr = (entry_ptr + 1).cast(value_ty.pointer())
228+
str_data = (entry_ptr + 1).cast(gdb.lookup_type('uintptr_t')) + max(value_ty.sizeof, entry_base_ty.alignof)
229+
str_data = str_data.cast(gdb.lookup_type('char').const().pointer())
228230
string_ref = gdb.Value(struct.pack('PN', int(str_data), int(str_len)), gdb.lookup_type('llvm::StringRef'))
229231
yield 'key', string_ref
230232

231-
value = entry['second']
233+
value = value_ptr.dereference()
232234
yield 'value', value
233235

234236
it = it + 1

0 commit comments

Comments
 (0)