Index: utils/gdb-scripts/prettyprinters.py =================================================================== --- utils/gdb-scripts/prettyprinters.py +++ utils/gdb-scripts/prettyprinters.py @@ -1,4 +1,17 @@ import gdb.printing + +class Iterator: + def __iter__(self): + return self + + # Python 2 compatibility + def next(self): + return self.__next__() + + def children(self): + return self + + class SmallStringPrinter: """Print an llvm::SmallString object.""" @@ -103,6 +116,26 @@ def display_hint (self): return 'array' +class ExpectedPrinter(Iterator): + """Print an llvm::Expected object.""" + + def __init__(self, val): + self.val = val + + 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()) + + def to_string(self): + return 'llvm::Expected<{}>'.format(str(self.val.type.template_argument(0))) + class OptionalPrinter: """Print an llvm::Optional object.""" @@ -315,6 +348,7 @@ pp.add_printer('llvm::StringRef', '^llvm::StringRef$', StringRefPrinter) pp.add_printer('llvm::SmallVectorImpl', '^llvm::SmallVector(Impl)?<.*>$', SmallVectorPrinter) pp.add_printer('llvm::ArrayRef', '^llvm::(Const)?ArrayRef<.*>$', ArrayRefPrinter) +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::Twine', '^llvm::Twine$', TwinePrinter)