2019-01-03 22:11:33 +08:00
|
|
|
from __future__ import print_function
|
2020-11-19 07:36:06 +08:00
|
|
|
import struct
|
2019-01-03 23:43:14 +08:00
|
|
|
import sys
|
2019-01-03 22:11:33 +08:00
|
|
|
|
2016-06-01 09:02:32 +08:00
|
|
|
import gdb.printing
|
2020-01-28 00:23:39 +08:00
|
|
|
import gdb.types
|
2018-06-26 07:38:48 +08:00
|
|
|
|
|
|
|
class Iterator:
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
|
2019-01-03 23:43:14 +08:00
|
|
|
if sys.version_info.major == 2:
|
|
|
|
def next(self):
|
|
|
|
return self.__next__()
|
2018-06-26 07:38:48 +08:00
|
|
|
|
|
|
|
def children(self):
|
|
|
|
return self
|
|
|
|
|
2018-06-26 08:41:49 +08:00
|
|
|
def escape_bytes(val, l):
|
|
|
|
return '"' + val.string(encoding='Latin-1', length=l).encode('unicode_escape').decode() + '"'
|
2018-06-26 07:38:48 +08:00
|
|
|
|
2016-06-01 09:02:32 +08:00
|
|
|
class SmallStringPrinter:
|
|
|
|
"""Print an llvm::SmallString object."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
begin = self.val['BeginX']
|
2018-07-24 05:33:51 +08:00
|
|
|
return escape_bytes(begin.cast(gdb.lookup_type('char').pointer()), self.val['Size'])
|
2016-06-01 09:02:32 +08:00
|
|
|
|
|
|
|
class StringRefPrinter:
|
|
|
|
"""Print an llvm::StringRef object."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def to_string(self):
|
2018-06-26 08:41:49 +08:00
|
|
|
return escape_bytes(self.val['Data'], self.val['Length'])
|
2016-06-01 09:02:32 +08:00
|
|
|
|
2018-07-24 05:33:51 +08:00
|
|
|
class SmallVectorPrinter(Iterator):
|
2016-06-01 09:02:32 +08:00
|
|
|
"""Print an llvm::SmallVector object."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
2018-07-24 05:33:51 +08:00
|
|
|
t = val.type.template_argument(0).pointer()
|
|
|
|
self.begin = val['BeginX'].cast(t)
|
|
|
|
self.size = val['Size']
|
|
|
|
self.i = 0
|
|
|
|
|
|
|
|
def __next__(self):
|
|
|
|
if self.i == self.size:
|
|
|
|
raise StopIteration
|
|
|
|
ret = '[{}]'.format(self.i), (self.begin+self.i).dereference()
|
|
|
|
self.i += 1
|
|
|
|
return ret
|
2016-06-01 09:02:32 +08:00
|
|
|
|
|
|
|
def to_string(self):
|
2018-07-24 05:33:51 +08:00
|
|
|
return 'llvm::SmallVector of Size {}, Capacity {}'.format(self.size, self.val['Capacity'])
|
2016-06-01 09:02:32 +08:00
|
|
|
|
|
|
|
def display_hint (self):
|
|
|
|
return 'array'
|
|
|
|
|
|
|
|
class ArrayRefPrinter:
|
|
|
|
"""Print an llvm::ArrayRef object."""
|
|
|
|
|
|
|
|
class _iterator:
|
|
|
|
def __init__(self, begin, end):
|
|
|
|
self.cur = begin
|
|
|
|
self.end = end
|
|
|
|
self.count = 0
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
|
2019-01-03 23:43:14 +08:00
|
|
|
def __next__(self):
|
2016-06-01 09:02:32 +08:00
|
|
|
if self.cur == self.end:
|
|
|
|
raise StopIteration
|
|
|
|
count = self.count
|
|
|
|
self.count = self.count + 1
|
|
|
|
cur = self.cur
|
|
|
|
self.cur = self.cur + 1
|
|
|
|
return '[%d]' % count, cur.dereference()
|
|
|
|
|
2019-01-03 23:43:14 +08:00
|
|
|
if sys.version_info.major == 2:
|
|
|
|
next = __next__
|
2016-08-06 00:48:31 +08:00
|
|
|
|
2016-06-01 09:02:32 +08:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
data = self.val['Data']
|
|
|
|
return self._iterator(data, data + self.val['Length'])
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return 'llvm::ArrayRef of length %d' % (self.val['Length'])
|
|
|
|
|
|
|
|
def display_hint (self):
|
|
|
|
return 'array'
|
|
|
|
|
2018-06-26 07:38:48 +08:00
|
|
|
class ExpectedPrinter(Iterator):
|
|
|
|
"""Print an llvm::Expected object."""
|
2016-12-17 03:16:22 +08:00
|
|
|
|
2018-06-26 07:38:48 +08:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
2016-12-17 03:16:22 +08:00
|
|
|
|
2018-06-26 07:38:48 +08:00
|
|
|
def __next__(self):
|
|
|
|
val = self.val
|
|
|
|
if val is None:
|
|
|
|
raise StopIteration
|
|
|
|
self.val = None
|
|
|
|
if val['HasError']:
|
|
|
|
return ('error', val['ErrorStorage'].address.cast(
|
|
|
|
gdb.lookup_type('llvm::ErrorInfoBase').pointer()).dereference())
|
|
|
|
return ('value', val['TStorage'].address.cast(
|
|
|
|
val.type.template_argument(0).pointer()).dereference())
|
2016-12-17 03:16:22 +08:00
|
|
|
|
2018-06-26 07:38:48 +08:00
|
|
|
def to_string(self):
|
|
|
|
return 'llvm::Expected{}'.format(' is error' if self.val['HasError'] else '')
|
2016-12-17 03:16:22 +08:00
|
|
|
|
2018-06-26 07:38:48 +08:00
|
|
|
class OptionalPrinter(Iterator):
|
|
|
|
"""Print an llvm::Optional object."""
|
2016-12-17 03:16:22 +08:00
|
|
|
|
2018-06-26 07:38:48 +08:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def __next__(self):
|
|
|
|
val = self.val
|
|
|
|
if val is None:
|
|
|
|
raise StopIteration
|
|
|
|
self.val = None
|
|
|
|
if not val['Storage']['hasVal']:
|
|
|
|
raise StopIteration
|
2019-05-29 04:22:16 +08:00
|
|
|
return ('value', val['Storage']['value'])
|
2016-12-17 03:16:22 +08:00
|
|
|
|
|
|
|
def to_string(self):
|
2018-06-26 07:38:48 +08:00
|
|
|
return 'llvm::Optional{}'.format('' if self.val['Storage']['hasVal'] else ' is not initialized')
|
2016-12-17 03:16:22 +08:00
|
|
|
|
2016-12-17 07:53:14 +08:00
|
|
|
class DenseMapPrinter:
|
|
|
|
"Print a DenseMap"
|
|
|
|
|
|
|
|
class _iterator:
|
|
|
|
def __init__(self, key_info_t, begin, end):
|
|
|
|
self.key_info_t = key_info_t
|
|
|
|
self.cur = begin
|
|
|
|
self.end = end
|
|
|
|
self.advancePastEmptyBuckets()
|
|
|
|
self.first = True
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def advancePastEmptyBuckets(self):
|
|
|
|
# disabled until the comments below can be addressed
|
|
|
|
# keeping as notes/posterity/hints for future contributors
|
|
|
|
return
|
|
|
|
n = self.key_info_t.name
|
|
|
|
is_equal = gdb.parse_and_eval(n + '::isEqual')
|
|
|
|
empty = gdb.parse_and_eval(n + '::getEmptyKey()')
|
|
|
|
tombstone = gdb.parse_and_eval(n + '::getTombstoneKey()')
|
|
|
|
# the following is invalid, GDB fails with:
|
|
|
|
# Python Exception <class 'gdb.error'> Attempt to take address of value
|
|
|
|
# not located in memory.
|
|
|
|
# because isEqual took parameter (for the unsigned long key I was testing)
|
|
|
|
# by const ref, and GDB
|
|
|
|
# It's also not entirely general - we should be accessing the "getFirst()"
|
|
|
|
# member function, not the 'first' member variable, but I've yet to figure
|
|
|
|
# out how to find/call member functions (especially (const) overloaded
|
|
|
|
# ones) on a gdb.Value.
|
|
|
|
while self.cur != self.end and (is_equal(self.cur.dereference()['first'], empty) or is_equal(self.cur.dereference()['first'], tombstone)):
|
|
|
|
self.cur = self.cur + 1
|
|
|
|
|
2019-01-03 23:43:14 +08:00
|
|
|
def __next__(self):
|
2016-12-17 07:53:14 +08:00
|
|
|
if self.cur == self.end:
|
|
|
|
raise StopIteration
|
|
|
|
cur = self.cur
|
|
|
|
v = cur.dereference()['first' if self.first else 'second']
|
|
|
|
if not self.first:
|
|
|
|
self.cur = self.cur + 1
|
|
|
|
self.advancePastEmptyBuckets()
|
|
|
|
self.first = True
|
|
|
|
else:
|
|
|
|
self.first = False
|
|
|
|
return 'x', v
|
|
|
|
|
2019-01-03 23:43:14 +08:00
|
|
|
if sys.version_info.major == 2:
|
|
|
|
next = __next__
|
2018-07-10 02:51:50 +08:00
|
|
|
|
2016-12-17 07:53:14 +08:00
|
|
|
def __init__(self, val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
t = self.val.type.template_argument(3).pointer()
|
|
|
|
begin = self.val['Buckets'].cast(t)
|
|
|
|
end = (begin + self.val['NumBuckets']).cast(t)
|
|
|
|
return self._iterator(self.val.type.template_argument(2), begin, end)
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return 'llvm::DenseMap with %d elements' % (self.val['NumEntries'])
|
|
|
|
|
|
|
|
def display_hint(self):
|
|
|
|
return 'map'
|
|
|
|
|
2020-11-19 07:36:06 +08:00
|
|
|
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)
|
2021-01-11 22:55:20 +08:00
|
|
|
entry_base_ty = gdb.lookup_type('llvm::StringMapEntryBase')
|
2020-11-19 07:36:06 +08:00
|
|
|
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
|
|
|
|
|
2021-01-11 22:55:20 +08:00
|
|
|
entry_ptr = it_deref.cast(entry_base_ty.pointer())
|
2020-11-19 07:36:06 +08:00
|
|
|
entry = entry_ptr.dereference()
|
|
|
|
|
|
|
|
str_len = entry['keyLength']
|
2021-01-11 22:55:20 +08:00
|
|
|
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())
|
2020-11-19 07:36:06 +08:00
|
|
|
string_ref = gdb.Value(struct.pack('PN', int(str_data), int(str_len)), gdb.lookup_type('llvm::StringRef'))
|
|
|
|
yield 'key', string_ref
|
|
|
|
|
2021-01-11 22:55:20 +08:00
|
|
|
value = value_ptr.dereference()
|
2020-11-19 07:36:06 +08:00
|
|
|
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'
|
|
|
|
|
2017-03-16 04:51:44 +08:00
|
|
|
class TwinePrinter:
|
|
|
|
"Print a Twine"
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self._val = val
|
|
|
|
|
|
|
|
def display_hint(self):
|
|
|
|
return 'string'
|
|
|
|
|
|
|
|
def string_from_pretty_printer_lookup(self, val):
|
|
|
|
'''Lookup the default pretty-printer for val and use it.
|
|
|
|
|
|
|
|
If no pretty-printer is defined for the type of val, print an error and
|
|
|
|
return a placeholder string.'''
|
|
|
|
|
|
|
|
pp = gdb.default_visualizer(val)
|
|
|
|
if pp:
|
|
|
|
s = pp.to_string()
|
|
|
|
|
|
|
|
# The pretty-printer may return a LazyString instead of an actual Python
|
|
|
|
# string. Convert it to a Python string. However, GDB doesn't seem to
|
|
|
|
# register the LazyString type, so we can't check
|
|
|
|
# "type(s) == gdb.LazyString".
|
|
|
|
if 'LazyString' in type(s).__name__:
|
|
|
|
s = s.value().address.string()
|
|
|
|
|
|
|
|
else:
|
|
|
|
print(('No pretty printer for {} found. The resulting Twine ' +
|
|
|
|
'representation will be incomplete.').format(val.type.name))
|
|
|
|
s = '(missing {})'.format(val.type.name)
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
def is_twine_kind(self, kind, expected):
|
|
|
|
if not kind.endswith(expected):
|
|
|
|
return False
|
|
|
|
# apparently some GDB versions add the NodeKind:: namespace
|
|
|
|
# (happens for me on GDB 7.11)
|
|
|
|
return kind in ('llvm::Twine::' + expected,
|
|
|
|
'llvm::Twine::NodeKind::' + expected)
|
|
|
|
|
2017-03-16 04:51:44 +08:00
|
|
|
def string_from_child(self, child, kind):
|
|
|
|
'''Return the string representation of the Twine::Child child.'''
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'EmptyKind') or self.is_twine_kind(kind, 'NullKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return ''
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'TwineKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return self.string_from_twine_object(child['twine'].dereference())
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'CStringKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return child['cString'].string()
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'StdStringKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
val = child['stdString'].dereference()
|
|
|
|
return self.string_from_pretty_printer_lookup(val)
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'StringRefKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
val = child['stringRef'].dereference()
|
|
|
|
pp = StringRefPrinter(val)
|
|
|
|
return pp.to_string()
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'SmallStringKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
val = child['smallString'].dereference()
|
|
|
|
pp = SmallStringPrinter(val)
|
|
|
|
return pp.to_string()
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'CharKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return chr(child['character'])
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'DecUIKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return str(child['decUI'])
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'DecIKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return str(child['decI'])
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'DecULKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return str(child['decUL'].dereference())
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'DecLKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return str(child['decL'].dereference())
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'DecULLKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return str(child['decULL'].dereference())
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'DecLLKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
return str(child['decLL'].dereference())
|
|
|
|
|
2017-06-04 11:27:12 +08:00
|
|
|
if self.is_twine_kind(kind, 'UHexKind'):
|
2017-03-16 04:51:44 +08:00
|
|
|
val = child['uHex'].dereference()
|
|
|
|
return hex(int(val))
|
|
|
|
|
|
|
|
print(('Unhandled NodeKind {} in Twine pretty-printer. The result will be '
|
|
|
|
'incomplete.').format(kind))
|
|
|
|
|
|
|
|
return '(unhandled {})'.format(kind)
|
|
|
|
|
|
|
|
def string_from_twine_object(self, twine):
|
|
|
|
'''Return the string representation of the Twine object twine.'''
|
|
|
|
|
|
|
|
lhs_str = ''
|
|
|
|
rhs_str = ''
|
|
|
|
|
|
|
|
lhs = twine['LHS']
|
|
|
|
rhs = twine['RHS']
|
|
|
|
lhs_kind = str(twine['LHSKind'])
|
|
|
|
rhs_kind = str(twine['RHSKind'])
|
|
|
|
|
|
|
|
lhs_str = self.string_from_child(lhs, lhs_kind)
|
|
|
|
rhs_str = self.string_from_child(rhs, rhs_kind)
|
|
|
|
|
|
|
|
return lhs_str + rhs_str
|
|
|
|
|
|
|
|
def to_string(self):
|
|
|
|
return self.string_from_twine_object(self._val)
|
2016-12-17 07:53:14 +08:00
|
|
|
|
2020-01-28 00:23:39 +08:00
|
|
|
def get_pointer_int_pair(val):
|
|
|
|
"""Get tuple from llvm::PointerIntPair."""
|
|
|
|
info_name = val.type.template_argument(4).strip_typedefs().name
|
2020-01-29 16:57:54 +08:00
|
|
|
# Note: this throws a gdb.error if the info type is not used (by means of a
|
|
|
|
# call to getPointer() or similar) in the current translation unit.
|
|
|
|
enum_type = gdb.lookup_type(info_name + '::MaskAndShiftConstants')
|
2020-01-28 00:23:39 +08:00
|
|
|
enum_dict = gdb.types.make_enum_dict(enum_type)
|
|
|
|
ptr_mask = enum_dict[info_name + '::PointerBitMask']
|
|
|
|
int_shift = enum_dict[info_name + '::IntShift']
|
|
|
|
int_mask = enum_dict[info_name + '::IntMask']
|
|
|
|
pair_union = val['Value']
|
|
|
|
pointer = (pair_union & ptr_mask)
|
|
|
|
value = ((pair_union >> int_shift) & int_mask)
|
|
|
|
return (pointer, value)
|
|
|
|
|
2020-01-29 16:57:54 +08:00
|
|
|
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)
|
|
|
|
|
2020-01-28 00:23:39 +08:00
|
|
|
def make_pointer_int_pair_printer(val):
|
|
|
|
"""Factory for an llvm::PointerIntPair printer."""
|
2020-01-29 16:57:54 +08:00
|
|
|
try:
|
|
|
|
pointer, value = get_pointer_int_pair(val)
|
|
|
|
except gdb.error:
|
|
|
|
return None # If PointerIntPair cannot be analyzed, print as raw value.
|
2020-01-28 00:23:39 +08:00
|
|
|
pointer_type = val.type.template_argument(0)
|
|
|
|
value_type = val.type.template_argument(2)
|
2020-01-29 16:57:54 +08:00
|
|
|
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
|
2020-01-28 00:23:39 +08:00
|
|
|
|
|
|
|
def make_pointer_union_printer(val):
|
|
|
|
"""Factory for an llvm::PointerUnion printer."""
|
2020-01-29 16:57:54 +08:00
|
|
|
try:
|
|
|
|
pointer, value = get_pointer_int_pair(val['Val'])
|
|
|
|
except gdb.error:
|
|
|
|
return None # If PointerIntPair cannot be analyzed, print as raw value.
|
2020-01-28 00:23:39 +08:00
|
|
|
pointer_type = val.type.template_argument(int(value))
|
2020-01-29 16:57:54 +08:00
|
|
|
return PointerUnionPrinter(pointer.cast(pointer_type))
|
2020-01-28 00:23:39 +08:00
|
|
|
|
2020-01-29 05:02:17 +08:00
|
|
|
class IlistNodePrinter:
|
|
|
|
"""Print an llvm::ilist_node object."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
impl_type = val.type.fields()[0].type
|
|
|
|
base_type = impl_type.fields()[0].type
|
|
|
|
derived_type = val.type.template_argument(0)
|
|
|
|
|
|
|
|
def get_prev_and_sentinel(base):
|
|
|
|
# One of Prev and PrevAndSentinel exists. Depending on #defines used to
|
|
|
|
# compile LLVM, the base_type's template argument is either true of false.
|
|
|
|
if base_type.template_argument(0):
|
|
|
|
return get_pointer_int_pair(base['PrevAndSentinel'])
|
|
|
|
return base['Prev'], None
|
|
|
|
|
|
|
|
# Casts a base_type pointer to the appropriate derived type.
|
|
|
|
def cast_pointer(pointer):
|
|
|
|
sentinel = get_prev_and_sentinel(pointer.dereference())[1]
|
|
|
|
pointer = pointer.cast(impl_type.pointer())
|
|
|
|
if sentinel:
|
|
|
|
return pointer
|
|
|
|
return pointer.cast(derived_type.pointer())
|
|
|
|
|
|
|
|
# Repeated cast becaue val.type's base_type is ambiguous when using tags.
|
|
|
|
base = val.cast(impl_type).cast(base_type)
|
|
|
|
(prev, sentinel) = get_prev_and_sentinel(base)
|
|
|
|
prev = prev.cast(base_type.pointer())
|
|
|
|
self.prev = cast_pointer(prev)
|
|
|
|
self.next = cast_pointer(val['Next'])
|
|
|
|
self.sentinel = sentinel
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
if self.sentinel:
|
|
|
|
yield 'sentinel', 'yes'
|
|
|
|
yield 'prev', self.prev
|
|
|
|
yield 'next', self.next
|
|
|
|
|
|
|
|
class IlistPrinter:
|
|
|
|
"""Print an llvm::simple_ilist or llvm::iplist object."""
|
|
|
|
|
|
|
|
def __init__(self, val):
|
|
|
|
self.node_type = val.type.template_argument(0)
|
|
|
|
sentinel = val['Sentinel']
|
|
|
|
# First field is common base type of sentinel and ilist_node.
|
|
|
|
base_type = sentinel.type.fields()[0].type
|
|
|
|
self.sentinel = sentinel.address.cast(base_type.pointer())
|
|
|
|
|
|
|
|
def _pointers(self):
|
|
|
|
pointer = self.sentinel
|
|
|
|
while True:
|
|
|
|
pointer = pointer['Next'].cast(pointer.type)
|
|
|
|
if pointer == self.sentinel:
|
|
|
|
return
|
|
|
|
yield pointer.cast(self.node_type.pointer())
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
for k, v in enumerate(self._pointers()):
|
|
|
|
yield ('[%d]' % k, v.dereference())
|
|
|
|
|
|
|
|
|
2016-06-01 09:02:32 +08:00
|
|
|
pp = gdb.printing.RegexpCollectionPrettyPrinter("LLVMSupport")
|
|
|
|
pp.add_printer('llvm::SmallString', '^llvm::SmallString<.*>$', SmallStringPrinter)
|
|
|
|
pp.add_printer('llvm::StringRef', '^llvm::StringRef$', StringRefPrinter)
|
|
|
|
pp.add_printer('llvm::SmallVectorImpl', '^llvm::SmallVector(Impl)?<.*>$', SmallVectorPrinter)
|
2020-01-07 18:01:29 +08:00
|
|
|
pp.add_printer('llvm::ArrayRef', '^llvm::(Mutable)?ArrayRef<.*>$', ArrayRefPrinter)
|
2018-06-26 07:38:48 +08:00
|
|
|
pp.add_printer('llvm::Expected', '^llvm::Expected<.*>$', ExpectedPrinter)
|
2016-12-17 03:16:22 +08:00
|
|
|
pp.add_printer('llvm::Optional', '^llvm::Optional<.*>$', OptionalPrinter)
|
2016-12-17 07:53:14 +08:00
|
|
|
pp.add_printer('llvm::DenseMap', '^llvm::DenseMap<.*>$', DenseMapPrinter)
|
2020-11-19 07:36:06 +08:00
|
|
|
pp.add_printer('llvm::StringMap', '^llvm::StringMap<.*>$', StringMapPrinter)
|
2017-03-16 04:51:44 +08:00
|
|
|
pp.add_printer('llvm::Twine', '^llvm::Twine$', TwinePrinter)
|
2020-01-28 00:23:39 +08:00
|
|
|
pp.add_printer('llvm::PointerIntPair', '^llvm::PointerIntPair<.*>$', make_pointer_int_pair_printer)
|
|
|
|
pp.add_printer('llvm::PointerUnion', '^llvm::PointerUnion<.*>$', make_pointer_union_printer)
|
2020-01-29 05:02:17 +08:00
|
|
|
pp.add_printer('llvm::ilist_node', '^llvm::ilist_node<.*>$', IlistNodePrinter)
|
|
|
|
pp.add_printer('llvm::iplist', '^llvm::iplist<.*>$', IlistPrinter)
|
|
|
|
pp.add_printer('llvm::simple_ilist', '^llvm::simple_ilist<.*>$', IlistPrinter)
|
2016-06-01 09:02:32 +08:00
|
|
|
gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)
|