From 1246e00478fb5ab2a357de17066fd8738395d9f1 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 4 May 2026 08:20:42 +0200 Subject: debug: split gdb modules --- scripts/gdb/kstd/__init__.py | 20 --------------- scripts/gdb/kstd/smart_pointers.py | 50 -------------------------------------- scripts/gdb/kstd/std_types.py | 15 ------------ scripts/gdb/kstd/string.py | 27 -------------------- scripts/gdb/kstd/vector.py | 22 ----------------- 5 files changed, 134 deletions(-) delete mode 100644 scripts/gdb/kstd/__init__.py delete mode 100644 scripts/gdb/kstd/smart_pointers.py delete mode 100644 scripts/gdb/kstd/std_types.py delete mode 100644 scripts/gdb/kstd/string.py delete mode 100644 scripts/gdb/kstd/vector.py (limited to 'scripts/gdb/kstd') diff --git a/scripts/gdb/kstd/__init__.py b/scripts/gdb/kstd/__init__.py deleted file mode 100644 index fc5e8fb..0000000 --- a/scripts/gdb/kstd/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -import gdb.printing - -from .vector import KstdVectorPrinter -from .string import KstdStringPrinter -from .std_types import StdBytePrinter -from .smart_pointers import KstdUniquePtrPrinter, KstdSharedPtrPrinter - - -def build_pretty_printers(): - pp = gdb.printing.RegexpCollectionPrettyPrinter("kstd") - pp.add_printer("vector", "^kstd::vector<.*>$", KstdVectorPrinter) - pp.add_printer("string", "^kstd::string$", KstdStringPrinter) - pp.add_printer("std_byte", "^std::byte$", StdBytePrinter) - pp.add_printer("unique_ptr", "^kstd::unique_ptr<.*>$", KstdUniquePtrPrinter) - pp.add_printer("shared_ptr", "^kstd::shared_ptr<.*>$", KstdSharedPtrPrinter) - return pp - - -def register_printers(objfile): - gdb.printing.register_pretty_printer(objfile, build_pretty_printers(), replace=True) diff --git a/scripts/gdb/kstd/smart_pointers.py b/scripts/gdb/kstd/smart_pointers.py deleted file mode 100644 index 6e4a4f9..0000000 --- a/scripts/gdb/kstd/smart_pointers.py +++ /dev/null @@ -1,50 +0,0 @@ -import gdb - - -class KstdUniquePtrPrinter: - - def __init__(self, val): - self.val = val - self.type = val.type.template_argument(0) - - def to_string(self): - pointer = self.val["pointer"] - if int(pointer) == 0: - return f"kstd::unique_ptr<{self.type}> (empty)" - return f"kstd::unique_ptr<{self.type}>" - - def children(self): - pointer = self.val["pointer"] - if int(pointer) != 0: - yield ("get()", pointer) - yield ("*get()", pointer.dereference()) - - -class KstdSharedPtrPrinter: - - def __init__(self, val): - self.val = val - self.type = val.type.template_argument(0) - - def to_string(self): - pointer = self.val["pointer"] - control_block = self.val["control"] - - if int(pointer) == 0 or int(control_block) == 0: - return f"kstd::shared_ptr<{self.type}> (empty)" - - strong_refs = int(control_block["shared_count"]["_M_i"]) - weak_refs = int(control_block["weak_count"]["_M_i"]) - - return f"kstd::shared_ptr<{self.type}> (use_count={strong_refs}, weak_count={weak_refs})" - - def children(self): - pointer = self.val["pointer"] - control_block = self.val["control"] - - if int(pointer) != 0: - yield ("get()", pointer) - yield ("*get()", pointer.dereference()) - - if int(control_block) != 0: - yield ("[control_block]", control_block.dereference()) diff --git a/scripts/gdb/kstd/std_types.py b/scripts/gdb/kstd/std_types.py deleted file mode 100644 index 78d094c..0000000 --- a/scripts/gdb/kstd/std_types.py +++ /dev/null @@ -1,15 +0,0 @@ -import gdb - - -class StdBytePrinter: - - def __init__(self, val): - self.val = val - - def to_string(self): - try: - uint8_type = gdb.lookup_type("unsigned char") - numeric_value = int(self.val.cast(uint8_type)) - return f"{numeric_value:#04x}" - except gdb.error: - return f"" diff --git a/scripts/gdb/kstd/string.py b/scripts/gdb/kstd/string.py deleted file mode 100644 index 8230b21..0000000 --- a/scripts/gdb/kstd/string.py +++ /dev/null @@ -1,27 +0,0 @@ -import gdb - - -class KstdStringPrinter: - - def __init__(self, val): - self.val = val - - def to_string(self): - storage = self.val["m_storage"] - storage_size = int(storage["m_size"]) - - if storage_size <= 0: - return '""' - - data_pointer = storage["m_data"] - string_length = storage_size - 1 - - try: - if hasattr(data_pointer, "lazy_string"): - return data_pointer.lazy_string(encoding="utf-8", length=string_length) - return data_pointer.string(encoding="utf-8", length=string_length) - except gdb.error: - return "" - - def display_hint(self): - return "string" diff --git a/scripts/gdb/kstd/vector.py b/scripts/gdb/kstd/vector.py deleted file mode 100644 index 597ffdc..0000000 --- a/scripts/gdb/kstd/vector.py +++ /dev/null @@ -1,22 +0,0 @@ -import gdb - - -class KstdVectorPrinter: - - def __init__(self, val): - self.val = val - self.type = val.type.template_argument(0) - - def to_string(self): - size = int(self.val["m_size"]) - capacity = int(self.val["m_capacity"]) - return f"kstd::vector of length {size}, capacity {capacity}" - - def children(self): - size = int(self.val["m_size"]) - data_pointer = self.val["m_data"] - for i in range(size): - yield (f"[{i}]", (data_pointer + i).dereference()) - - def display_hint(self): - return "array" -- cgit v1.2.3