import gdb import sys # CSTRING ============================================================================================================== class CStringPrinter: def __init__(self, val): self.val = val def to_string(self): return self.val['_cstr'] def children(self): size = int(self.val['_size']) start = self.val['_cstr'] return (('[{}]'.format(i), start[i]) for i in range(size)) # ALLOCATION =========================================================================================================== class StringPrinter: def __init__(self, val): self.val = val def to_string(self): return str("fennec::allocation = {value}").format(value = self.val['_str']['_data']) def children(self): size = int(self.val['_str']['_capacity']) start = self.val['_str']['_data'] return (('[{}]'.format(i), start[i]) for i in range(size)) # OPTIONAL ================================================================================================================= class OptionalPrinter: """Print a fennec::optional""" def __init__(self, val): self.val = val def to_string(self): is_initialized = self.val['_set'] if is_initialized: return "Value = {}".format(self.val['_val']) else: return "empty" # ALLOCATION =========================================================================================================== class AllocationPrinter: def __init__(self, val): self.val = val def to_string(self): return "fennec::allocation" def children(self): size = int(self.val['_capacity']) start = self.val['_data'] return (('[{}]'.format(i), start[i]) for i in range(size)) # LIST ================================================================================================================= class ListPrinter: """Print a fennec::list""" class Iterator: def __init__(self, val): self.list = val self.node = self.list['_root'] #self.index = 0 def __iter__(self): return self def __next__(self): if self.node == 18446744073709551615: raise StopIteration value = self.list['_table']['_data'][self.node]['value']['_val'] self.node = self.list['_table']['_data'][self.node]['next'] return value #index = self.index #self.index = self.index + 1 #value = self.list['_table']['_data'][self.node]['value']['_val'] #self.node = self.list['_table']['_data'][self.node]['next'] #return str("value[{index}] = {value}").format(index = index, value = value) def __init__(self, val): self.val = val def to_string(self): return "fennec::list" def children(self): return enumerate(self.Iterator(self.val)) # GDB CODE ============================================================================================================= def lookup_function(val): type = str(val.type) if type.startswith('const '): type = type[6:] if type.startswith('fennec::cstring') or type.startswith('fennec::wcstring'): return CStringPrinter(val) if type.startswith('fennec::string') or type.startswith('fennec::wstring'): return StringPrinter(val) if type.startswith('fennec::optional'): return OptionalPrinter(val) if type.startswith('fennec::list'): return ListPrinter(val) if type.startswith('fennec::allocation'): return AllocationPrinter(val) return None gdb.pretty_printers.append(lookup_function)