1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Added GDB pretty printer for StringMap

Reviewed By: csigg, dblaikie

Differential Revision: https://reviews.llvm.org/D91183
This commit is contained in:
Moritz Sichert 2020-11-18 15:36:06 -08:00 committed by David Blaikie
parent dd58cefb43
commit 0fadcfd431
2 changed files with 45 additions and 3 deletions

View File

@ -78,10 +78,12 @@ protected:
void init(unsigned Size);
public:
static constexpr uintptr_t TombstoneIntVal =
static_cast<uintptr_t>(-1)
<< PointerLikeTypeTraits<StringMapEntryBase *>::NumLowBitsAvailable;
static StringMapEntryBase *getTombstoneVal() {
uintptr_t Val = static_cast<uintptr_t>(-1);
Val <<= PointerLikeTypeTraits<StringMapEntryBase *>::NumLowBitsAvailable;
return reinterpret_cast<StringMapEntryBase *>(Val);
return reinterpret_cast<StringMapEntryBase *>(TombstoneIntVal);
}
unsigned getNumBuckets() const { return NumBuckets; }

View File

@ -1,4 +1,5 @@
from __future__ import print_function
import struct
import sys
import gdb.printing
@ -200,6 +201,44 @@ class DenseMapPrinter:
def display_hint(self):
return 'map'
class StringMapPrinter:
"Print a StringMap"
def __init__(self, val):
self.val = val
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))
tombstone = gdb.parse_and_eval('llvm::StringMapImpl::TombstoneIntVal');
while it != end:
it_deref = it.dereference()
if it_deref == 0 or it_deref == tombstone:
it = it + 1
continue
entry_ptr = it_deref.cast(entry_ty.pointer())
entry = entry_ptr.dereference()
str_len = entry['keyLength']
str_data = (entry_ptr + 1).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']
yield 'value', value
it = it + 1
def to_string(self):
return 'llvm::StringMap with %d elements' % (self.val['NumItems'])
def display_hint(self):
return 'map'
class TwinePrinter:
"Print a Twine"
@ -442,6 +481,7 @@ pp.add_printer('llvm::ArrayRef', '^llvm::(Mutable)?ArrayRef<.*>$', ArrayRefPrint
pp.add_printer('llvm::Expected', '^llvm::Expected<.*>$', ExpectedPrinter)
pp.add_printer('llvm::Optional', '^llvm::Optional<.*>$', OptionalPrinter)
pp.add_printer('llvm::DenseMap', '^llvm::DenseMap<.*>$', DenseMapPrinter)
pp.add_printer('llvm::StringMap', '^llvm::StringMap<.*>$', StringMapPrinter)
pp.add_printer('llvm::Twine', '^llvm::Twine$', TwinePrinter)
pp.add_printer('llvm::PointerIntPair', '^llvm::PointerIntPair<.*>$', make_pointer_int_pair_printer)
pp.add_printer('llvm::PointerUnion', '^llvm::PointerUnion<.*>$', make_pointer_union_printer)