aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/gdb
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-05-04 12:01:01 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-05-04 12:01:01 +0200
commit78e42a1b6e0a857865be1e60f82871ac13c91bb1 (patch)
tree34cc53f3367b660320a0be6aa1c0c451135f83e0 /libs/kstd/gdb
parent1246e00478fb5ab2a357de17066fd8738395d9f1 (diff)
downloadkernel-78e42a1b6e0a857865be1e60f82871ac13c91bb1.tar.xz
kernel-78e42a1b6e0a857865be1e60f82871ac13c91bb1.zip
debug: improve pretty printer implementations
Diffstat (limited to 'libs/kstd/gdb')
-rw-r--r--libs/kstd/gdb/smart_pointers.py43
-rw-r--r--libs/kstd/gdb/std_types.py8
-rw-r--r--libs/kstd/gdb/string.py4
-rw-r--r--libs/kstd/gdb/vector.py19
4 files changed, 37 insertions, 37 deletions
diff --git a/libs/kstd/gdb/smart_pointers.py b/libs/kstd/gdb/smart_pointers.py
index 6e4a4f9..3e5da02 100644
--- a/libs/kstd/gdb/smart_pointers.py
+++ b/libs/kstd/gdb/smart_pointers.py
@@ -1,50 +1,51 @@
import gdb
+from teachos import TeachOSBasePrinter
-class KstdUniquePtrPrinter:
-
+class KstdUniquePtrPrinter(TeachOSBasePrinter):
def __init__(self, val):
- self.val = val
- self.type = val.type.template_argument(0)
+ super().__init__(val)
+ self.__type = val.type.template_argument(0)
def to_string(self):
- pointer = self.val["pointer"]
+ pointer = self.value["pointer"]
if int(pointer) == 0:
- return f"kstd::unique_ptr<{self.type}> (empty)"
- return f"kstd::unique_ptr<{self.type}>"
+ return f"kstd::unique_ptr<{self.__type}> (empty)"
+ return f"kstd::unique_ptr<{self.__type}>"
def children(self):
- pointer = self.val["pointer"]
+ pointer = self.value["pointer"]
if int(pointer) != 0:
- yield ("get()", pointer)
- yield ("*get()", pointer.dereference())
+ yield ("[object]", pointer.dereference())
+ yield from super().children()
-class KstdSharedPtrPrinter:
+class KstdSharedPtrPrinter(TeachOSBasePrinter):
def __init__(self, val):
- self.val = val
- self.type = val.type.template_argument(0)
+ super().__init__(val)
+ self.__type = val.type.template_argument(0)
def to_string(self):
- pointer = self.val["pointer"]
- control_block = self.val["control"]
+ pointer = self.value["pointer"]
+ control_block = self.value["control"]
if int(pointer) == 0 or int(control_block) == 0:
- return f"kstd::shared_ptr<{self.type}> (empty)"
+ 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})"
+ 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"]
+ pointer = self.value["pointer"]
+ control_block = self.value["control"]
if int(pointer) != 0:
- yield ("get()", pointer)
- yield ("*get()", pointer.dereference())
+ yield ("[object]", pointer.dereference())
if int(control_block) != 0:
yield ("[control_block]", control_block.dereference())
+
+ yield from super().children()
diff --git a/libs/kstd/gdb/std_types.py b/libs/kstd/gdb/std_types.py
index 78d094c..deb5c58 100644
--- a/libs/kstd/gdb/std_types.py
+++ b/libs/kstd/gdb/std_types.py
@@ -1,15 +1,13 @@
import gdb
+from teachos import TeachOSBasePrinter
-class StdBytePrinter:
-
- def __init__(self, val):
- self.val = val
+class StdBytePrinter(TeachOSBasePrinter):
def to_string(self):
try:
uint8_type = gdb.lookup_type("unsigned char")
- numeric_value = int(self.val.cast(uint8_type))
+ numeric_value = int(self.value.cast(uint8_type))
return f"{numeric_value:#04x}"
except gdb.error:
return f"<optimized out or unreadable>"
diff --git a/libs/kstd/gdb/string.py b/libs/kstd/gdb/string.py
index 8230b21..2688061 100644
--- a/libs/kstd/gdb/string.py
+++ b/libs/kstd/gdb/string.py
@@ -4,10 +4,10 @@ import gdb
class KstdStringPrinter:
def __init__(self, val):
- self.val = val
+ self.__val = val
def to_string(self):
- storage = self.val["m_storage"]
+ storage = self.__val["m_storage"]
storage_size = int(storage["m_size"])
if storage_size <= 0:
diff --git a/libs/kstd/gdb/vector.py b/libs/kstd/gdb/vector.py
index 597ffdc..4340ef4 100644
--- a/libs/kstd/gdb/vector.py
+++ b/libs/kstd/gdb/vector.py
@@ -1,20 +1,21 @@
import gdb
+from teachos import TeachOSBasePrinter
-class KstdVectorPrinter:
-
+class KstdVectorPrinter(TeachOSBasePrinter):
def __init__(self, val):
- self.val = val
- self.type = val.type.template_argument(0)
+ super().__init__(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}"
+ size = int(self.value["m_size"])
+ capacity = int(self.value["m_capacity"])
+ return f"kstd::vector<{self.__type}> (size={size}, capacity={capacity})"
def children(self):
- size = int(self.val["m_size"])
- data_pointer = self.val["m_data"]
+ yield from super().children()
+ size = int(self.value["m_size"])
+ data_pointer = self.value["m_data"]
for i in range(size):
yield (f"[{i}]", (data_pointer + i).dereference())