@@ -316,25 +316,12 @@ def string_from_twine_object(self, twine):
316316 def to_string (self ):
317317 return self .string_from_twine_object (self ._val )
318318
319- def make_printer (string = None , children = None , hint = None ):
320- """Create a printer from the parameters."""
321- class Printer : pass
322- printer = Printer ()
323- if string :
324- setattr (printer , 'to_string' , lambda : string )
325- if children :
326- setattr (printer , 'children' , lambda : children )
327- if hint :
328- setattr (printer , 'display_hint' , lambda : hint )
329- return printer
330-
331319def get_pointer_int_pair (val ):
332320 """Get tuple from llvm::PointerIntPair."""
333321 info_name = val .type .template_argument (4 ).strip_typedefs ().name
334- try :
335- enum_type = gdb .lookup_type (info_name + '::MaskAndShiftConstants' )
336- except gdb .error :
337- return (None , None )
322+ # Note: this throws a gdb.error if the info type is not used (by means of a
323+ # call to getPointer() or similar) in the current translation unit.
324+ enum_type = gdb .lookup_type (info_name + '::MaskAndShiftConstants' )
338325 enum_dict = gdb .types .make_enum_dict (enum_type )
339326 ptr_mask = enum_dict [info_name + '::PointerBitMask' ]
340327 int_shift = enum_dict [info_name + '::IntShift' ]
@@ -344,26 +331,48 @@ def get_pointer_int_pair(val):
344331 value = ((pair_union >> int_shift ) & int_mask )
345332 return (pointer , value )
346333
334+ class PointerIntPairPrinter :
335+ """Print a PointerIntPair."""
336+
337+ def __init__ (self , pointer , value ):
338+ self .pointer = pointer
339+ self .value = value
340+
341+ def children (self ):
342+ yield ('pointer' , self .pointer )
343+ yield ('value' , self .value )
344+
347345def make_pointer_int_pair_printer (val ):
348346 """Factory for an llvm::PointerIntPair printer."""
349- pointer , value = get_pointer_int_pair (val )
350- if not pointer or not value :
351- return None
347+ try :
348+ pointer , value = get_pointer_int_pair (val )
349+ except gdb .error :
350+ return None # If PointerIntPair cannot be analyzed, print as raw value.
352351 pointer_type = val .type .template_argument (0 )
353352 value_type = val .type .template_argument (2 )
354- string = 'llvm::PointerIntPair<%s>' % pointer_type
355- children = [('pointer' , pointer .cast (pointer_type )),
356- ('value' , value .cast (value_type ))]
357- return make_printer (string , children )
353+ return PointerIntPairPrinter (pointer .cast (pointer_type ),
354+ value .cast (value_type ))
355+
356+ class PointerUnionPrinter :
357+ """Print a PointerUnion."""
358+
359+ def __init__ (self , pointer ):
360+ self .pointer = pointer
361+
362+ def children (self ):
363+ yield ('pointer' , self .pointer )
364+
365+ def to_string (self ):
366+ return "Containing %s" % self .pointer .type
358367
359368def make_pointer_union_printer (val ):
360369 """Factory for an llvm::PointerUnion printer."""
361- pointer , value = get_pointer_int_pair (val ['Val' ])
362- if not pointer or not value :
363- return None
370+ try :
371+ pointer , value = get_pointer_int_pair (val ['Val' ])
372+ except gdb .error :
373+ return None # If PointerIntPair cannot be analyzed, print as raw value.
364374 pointer_type = val .type .template_argument (int (value ))
365- string = 'llvm::PointerUnion containing %s' % pointer_type
366- return make_printer (string , [('pointer' , pointer .cast (pointer_type ))])
375+ return PointerUnionPrinter (pointer .cast (pointer_type ))
367376
368377class IlistNodePrinter :
369378 """Print an llvm::ilist_node object."""
0 commit comments