aboutsummaryrefslogtreecommitdiff
path: root/kapi/gdb/boot_modules/boot_module.py
diff options
context:
space:
mode:
Diffstat (limited to 'kapi/gdb/boot_modules/boot_module.py')
-rw-r--r--kapi/gdb/boot_modules/boot_module.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/kapi/gdb/boot_modules/boot_module.py b/kapi/gdb/boot_modules/boot_module.py
new file mode 100644
index 0000000..97e6584
--- /dev/null
+++ b/kapi/gdb/boot_modules/boot_module.py
@@ -0,0 +1,44 @@
+import gdb
+from teachos import format_size
+
+
+class KapiBootModulesBootModulePrinter(gdb.ValuePrinter):
+ class Iterator:
+ def __init__(self, begin: gdb.Value, end: gdb.Value):
+ self._item = begin
+ self._end = end
+ self._count = 0
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ count = self._count
+ self._count = count + 1
+
+ if self._item == self._end:
+ raise StopIteration
+
+ element = self._item.dereference()
+ self._item += 1
+ return (f"[{count}]", element)
+
+ def __init__(self, val):
+ self.__pointer_type = gdb.lookup_type("std::byte").pointer()
+
+ self.__val = val
+ self.__name = val["name"]
+ self.__start = val["start_address"]
+ self.__size = int(val["size"])
+ self.__begin = val["start_address"]["m_value"].cast(self.__pointer_type)
+ self.__end = self.__begin + self.__size
+ self.__pretty_name = " " + str(self.__name) if str(self.__name) != '""' else ""
+
+ def to_string(self):
+ return f"boot module{self.__pretty_name} of size {format_size(self.__size)}, at {self.__start.cast(self.__pointer_type)}"
+
+ def children(self):
+ return self.Iterator(self.__begin, self.__end)
+
+ def display_hint(self):
+ return "array"