diff --git a/.gdbinit b/.gdbinit new file mode 100644 index 000000000..411a7ce14 --- /dev/null +++ b/.gdbinit @@ -0,0 +1 @@ +source tools/gdb/pretty_printers/utils/static_vector_pp.py diff --git a/tools/gdb/pretty_printers/utils/static_vector_pp.py b/tools/gdb/pretty_printers/utils/static_vector_pp.py new file mode 100644 index 000000000..506992354 --- /dev/null +++ b/tools/gdb/pretty_printers/utils/static_vector_pp.py @@ -0,0 +1,35 @@ +import gdb + + +class StaticVectorPrinter(gdb.ValuePrinter): + def __init__(self, val): + self._val = val + + def to_string(self): + return f"{self._val.type} of length {self.num_children()}" + + def display_hint(self): + return "array" + + def children(self): + return map(lambda i: self.child(i), range(self.num_children())) + + def num_children(self): + return int(self._val["size_"]) + + def child(self, n): + return (f"[{n}]", self._elements()[n]) + + def _elements(self): + return self._val["data_"].reinterpret_cast(self._element_type().pointer()) + + def _element_type(self): + return self._val.type.template_argument(0) + + +def StaticVectorPrinter_fn(val): + if str(val.type).startswith("devilution::StaticVector<"): + return StaticVectorPrinter(val) + + +gdb.pretty_printers.append(StaticVectorPrinter_fn)