aboutsummaryrefslogtreecommitdiff
path: root/scripts/gdb/kstd
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-05-01 21:00:39 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-05-01 21:00:39 +0200
commit128e4a2adca6721254e8ffd290b670cc58b7a898 (patch)
tree9c971205dd4a1ce733507961f6096bc96f511499 /scripts/gdb/kstd
parent61949538ad6d114c1c2a788928a0b9706b4efc76 (diff)
downloadkernel-128e4a2adca6721254e8ffd290b670cc58b7a898.tar.xz
kernel-128e4a2adca6721254e8ffd290b670cc58b7a898.zip
debug: add support for smart pointer pretty printing
Diffstat (limited to 'scripts/gdb/kstd')
-rw-r--r--scripts/gdb/kstd/__init__.py3
-rw-r--r--scripts/gdb/kstd/smart_pointers.py50
2 files changed, 53 insertions, 0 deletions
diff --git a/scripts/gdb/kstd/__init__.py b/scripts/gdb/kstd/__init__.py
index 7dc1596..fc5e8fb 100644
--- a/scripts/gdb/kstd/__init__.py
+++ b/scripts/gdb/kstd/__init__.py
@@ -3,6 +3,7 @@ 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():
@@ -10,6 +11,8 @@ def build_pretty_printers():
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
diff --git a/scripts/gdb/kstd/smart_pointers.py b/scripts/gdb/kstd/smart_pointers.py
new file mode 100644
index 0000000..9af16fd
--- /dev/null
+++ b/scripts/gdb/kstd/smart_pointers.py
@@ -0,0 +1,50 @@
+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["m_ptr"]
+ 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"]
+ cb = self.val["control_block"]
+
+ if int(pointer) == 0 or int(cb) == 0:
+ return f"kstd::shared_ptr<{self.type}> (empty)"
+
+ strong_refs = int(cb["m_strong_refs"])
+ weak_refs = int(cb["m_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"]
+
+ if int(pointer) != 0:
+ yield ("get()", pointer)
+ yield ("*get()", pointer.dereference())
+
+ if int(control_block) != 0:
+ yield ("[control_block]", control_block.dereference())