diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-05-08 17:12:24 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-05-08 17:12:24 +0200 |
| commit | 07fb219869099c719b0fbfeae81b95512487639e (patch) | |
| tree | 87c7bc3c6d6d3897bf8853c0bf6291ba136277c5 /scripts/gdb | |
| parent | fb09cd6633b26ef2cfb4f21b8cd852611cfe59d8 (diff) | |
| download | kernel-07fb219869099c719b0fbfeae81b95512487639e.tar.xz kernel-07fb219869099c719b0fbfeae81b95512487639e.zip | |
debug: add page and frame formatters
Diffstat (limited to 'scripts/gdb')
| -rw-r--r-- | scripts/gdb/teachos/__init__.py | 8 | ||||
| -rw-r--r-- | scripts/gdb/teachos/dump_mb2i.py | 22 |
2 files changed, 15 insertions, 15 deletions
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("<II", data) string = data[8:].split(b"\x00")[0].decode("ascii", "replace") gdb.write( - f"{INDENT}start: {start:#010x} | end: {end:#010x} | size: {self._format_size(end - start)}\n" + f"{INDENT}start: {start:#010x} | end: {end:#010x} | size: {format_size(end - start)}\n" ) if string: gdb.write(f'{INDENT}string: "{string}"\n') @@ -206,7 +198,7 @@ class DumpMB2I(gdb.Command): def _write_basic_memory_info_tag(self, data): lower, upper = struct.unpack_from("<II", data) gdb.write( - f"{INDENT}upper memory: {self._format_size(upper * 1024)} | lower memory: {self._format_size(lower * 1024)}\n" + f"{INDENT}upper memory: {format_size(upper * 1024)} | lower memory: {format_size(lower * 1024)}\n" ) def _write_boot_device_tag(self, data): @@ -225,7 +217,7 @@ class DumpMB2I(gdb.Command): base, length, memory_type = struct.unpack_from("<QQI", data, entry_offset) type_string = MEMORY_TYPES.get(memory_type, "Unknown") gdb.write( - f"{INDENT}[{i:02d}] {base:#018x} - {base + length:#018x} | {self._format_size(length)} | type: {type_string}\n" + f"{INDENT}[{i:02d}] {base:#018x} - {base + length:#018x} | {format_size(length)} | type: {type_string}\n" ) def _write_image_load_base_physical_address_tag(self, data): @@ -236,7 +228,7 @@ class DumpMB2I(gdb.Command): address, pitch, width, height, bpp, type = struct.unpack_from("<QIIIBB", data) type_string = FRAMEBUFFER_TYPES.get(type, "Unknown") gdb.write(f"{INDENT}address: {address:#010x} | type: {type_string}\n") - gdb.write(f"{INDENT}depth: {bpp} | pitch: {self._format_size(pitch)}\n") + gdb.write(f"{INDENT}depth: {bpp} | pitch: {format_size(pitch)}\n") if type == FramebufferType.TEXT: gdb.write(f"{INDENT}width: {width} chars | height: {height} chars\n") else: |
