diff --git a/debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.gdb b/debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.gdb --- a/debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.gdb +++ b/debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.gdb @@ -39,10 +39,10 @@ # CHECK: "\"foo\"\"bar\"" p Twine -# CHECK: llvm::PointerIntPair = {pointer = 0xabc, value = 1} +# CHECK: {pointer = 0xabc, value = 1} p PointerIntPair -# CHECK: llvm::PointerUnion containing int * = {pointer = 0xabc} +# CHECK: Containing int * = {pointer = 0xabc} p PointerUnion # Switch to print pretty adds newlines to the following statements. diff --git a/llvm/utils/gdb-scripts/prettyprinters.py b/llvm/utils/gdb-scripts/prettyprinters.py --- a/llvm/utils/gdb-scripts/prettyprinters.py +++ b/llvm/utils/gdb-scripts/prettyprinters.py @@ -316,18 +316,6 @@ def to_string(self): return self.string_from_twine_object(self._val) -def make_printer(string = None, children = None, hint = None): - """Create a printer from the parameters.""" - class Printer : pass - printer = Printer() - if string: - setattr(printer, 'to_string', lambda: string) - if children: - setattr(printer, 'children', lambda: children) - if hint: - setattr(printer, 'display_hint', lambda: hint) - return printer - def get_pointer_int_pair(val): """Get tuple from llvm::PointerIntPair.""" info_name = val.type.template_argument(4).strip_typedefs().name @@ -344,6 +332,17 @@ value = ((pair_union >> int_shift) & int_mask) return (pointer, value) +class PointerIntPairPrinter: + """Print a PointerIntPair.""" + + def __init__(self, pointer, value): + self.pointer = pointer + self.value = value + + def children(self): + yield ('pointer', self.pointer) + yield ('value', self.value) + def make_pointer_int_pair_printer(val): """Factory for an llvm::PointerIntPair printer.""" pointer, value = get_pointer_int_pair(val) @@ -351,10 +350,20 @@ return None pointer_type = val.type.template_argument(0) value_type = val.type.template_argument(2) - string = 'llvm::PointerIntPair<%s>' % pointer_type - children = [('pointer', pointer.cast(pointer_type)), - ('value', value.cast(value_type))] - return make_printer(string, children) + return PointerIntPairPrinter(pointer.cast(pointer_type), + value.cast(value_type)) + +class PointerUnionPrinter: + """Print a PointerUnion.""" + + def __init__(self, pointer): + self.pointer = pointer + + def children(self): + yield ('pointer', self.pointer) + + def to_string(self): + return "Containing %s" % self.pointer.type def make_pointer_union_printer(val): """Factory for an llvm::PointerUnion printer.""" @@ -362,8 +371,7 @@ if not pointer or not value: return None pointer_type = val.type.template_argument(int(value)) - string = 'llvm::PointerUnion containing %s' % pointer_type - return make_printer(string, [('pointer', pointer.cast(pointer_type))]) + return PointerUnionPrinter(pointer.cast(pointer_type)) class IlistNodePrinter: """Print an llvm::ilist_node object."""