From 07fb219869099c719b0fbfeae81b95512487639e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 8 May 2026 17:12:24 +0200 Subject: debug: add page and frame formatters --- scripts/gdb/teachos/__init__.py | 8 ++++++++ scripts/gdb/teachos/dump_mb2i.py | 22 +++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'scripts/gdb') diff --git a/scripts/gdb/teachos/__init__.py b/scripts/gdb/teachos/__init__.py index e69de29..a5eca92 100644 --- a/scripts/gdb/teachos/__init__.py +++ b/scripts/gdb/teachos/__init__.py @@ -0,0 +1,8 @@ +def format_size(size): + for unit in ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"]: + if size < 1024.0: + if unit == "Bytes": + return f"{int(size)} {unit}" + return f"{size:.2f} {unit}" + size /= 1024.0 + return f"{size:.2f} PiB" diff --git a/scripts/gdb/teachos/dump_mb2i.py b/scripts/gdb/teachos/dump_mb2i.py index 3a9ee4a..0657ebd 100644 --- a/scripts/gdb/teachos/dump_mb2i.py +++ b/scripts/gdb/teachos/dump_mb2i.py @@ -1,6 +1,7 @@ import gdb import struct from enum import IntEnum +from teachos import format_size class TagType(IntEnum): @@ -150,19 +151,10 @@ class DumpMB2I(gdb.Command): offset += (tag_size + 7) & ~7 - def _format_size(self, size): - for unit in ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"]: - if size < 1024.0: - if unit == "Bytes": - return f"{int(size)} {unit}" - return f"{size:.2f} {unit}" - size /= 1024.0 - return f"{size:.2f} PiB" - def _print_tag(self, inferior, tag_address, tag_type, tag_size): name = TAG_NAMES.get(tag_type, f"Unknown Tag") - size = self._format_size(tag_size) - payload = self._format_size(tag_size - 8) + size = format_size(tag_size) + payload = format_size(tag_size - 8) gdb.write(f"[Tag {tag_type:#04x}] {name} (size: {size} | payload: {payload})\n") if tag_size <= 8 and tag_type != TagType.END: @@ -198,7 +190,7 @@ class DumpMB2I(gdb.Command): start, end = struct.unpack_from("