import gdb; import re; class VectorWrapperPrinter: def __init__(self, parVal): self.val = parVal; def to_string(self): sz = int(self.val["m_wrapped"].type.template_argument(1)); arr_vals = ", ".join(str(self.val["m_wrapped"]["_M_elems"][z]) for z in range(0, sz)); return "<{0}>".format(arr_vals); def display_hint(self): return "array"; class TileCoordsPrinter: def __init__(self, parVal): self.val = parVal; def to_string(self): return "{{m_pos = {0}, m_size = {1} (upper)}}".format(self.val["m_pos"], self.val["m_size"]); def display_hint(self): return "map"; class LayerBasePrinter: def __init__(self, parVal): self.val = parVal; def to_string(self): m_haveFrom = self.val["m_haveFrom"]; m_haveTo = self.val["m_haveTo"]; return "{{have from-to = {0}-{1}}}".format(m_haveFrom, m_haveTo); def display_hint(self): return "map"; class TylerPrinter: def __init__(self, parVal): self.val = parVal; def to_string(self): m_size = str(self.val["m_size"]); m_tilesize = str(self.val["m_tilesize"]); start = self.val["m_layers"]["_M_impl"]["_M_start"]; finish = self.val["m_layers"]["_M_impl"]["_M_finish"]; end = self.val["m_layers"]["_M_impl"]["_M_end_of_storage"]; layers_count = int(finish - start); m_layers = ", ".join( "{0}: {1}".format(str(self.val["m_layers"]["_M_impl"]["_M_start"][z]["_M_t"]["_M_head_impl"].type.target()), str(self.val["m_layers"]["_M_impl"]["_M_start"][z]["_M_t"]["_M_head_impl"].dereference())) for z in range(0, layers_count)); capacity = int(end - start); return "{{m_size = {0}, m_tilesize = {1}, m_layers ({2}/{3}) = {{{4}}}}}".format(m_size, m_tilesize, layers_count, capacity, m_layers); def display_hint(self): return "map"; def vector_wrapper_match(parVal): tag_value = str(parVal.type.strip_typedefs().tag); if tag_value == None: return None; reg_vecbase = re.compile("^vwr::implem::VecBase<.*>$"); reg_vec = re.compile("^vwr::Vec<.*>$"); reg_tilecoords = re.compile("^dk::TileCoords<.*>$"); reg_tyler = re.compile("^dk::Tyler<.*>$"); reg_layerbase = re.compile("^dk::LayerBase<.*>$"); if reg_vecbase.match(tag_value) or reg_vec.match(tag_value): return VectorWrapperPrinter(parVal); elif reg_tilecoords.match(tag_value): return TileCoordsPrinter(parVal); elif reg_tyler.match(tag_value): return TylerPrinter(parVal); elif reg_layerbase.match(tag_value): return LayerBasePrinter(parVal); else: return None; def register_printers(parObjfile): parObjfile.pretty_printers.append(vector_wrapper_match);