aboutsummaryrefslogtreecommitdiff
path: root/scripts/gdb
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-09-30 13:10:21 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-09-30 13:10:21 +0200
commit8bec65ba723c9c628d934ec02021d5ce09c01105 (patch)
tree2eec65a312bf523bbe94811f1b8c9f904d07327b /scripts/gdb
parent83f264c22326ae37a0eb38284935a32895a48efb (diff)
downloadkernel-8bec65ba723c9c628d934ec02021d5ce09c01105.tar.xz
kernel-8bec65ba723c9c628d934ec02021d5ce09c01105.zip
chore: clean up python scripts
Diffstat (limited to 'scripts/gdb')
-rw-r--r--scripts/gdb/teachos.py15
-rw-r--r--scripts/gdb/teachos/dump_mb2i.py16
-rw-r--r--scripts/gdb/toolchain.py14
3 files changed, 31 insertions, 14 deletions
diff --git a/scripts/gdb/teachos.py b/scripts/gdb/teachos.py
index 355f6b97..616a9c50 100644
--- a/scripts/gdb/teachos.py
+++ b/scripts/gdb/teachos.py
@@ -1,6 +1,6 @@
import sys
import os
-import gdb
+import gdb # pyright: ignore[reportMissingModuleSource]
import importlib.util
script_path = os.path.abspath(__file__)
@@ -24,9 +24,20 @@ for component, path in components.items():
if os.path.isfile(init_file):
try:
spec = importlib.util.spec_from_file_location(component, init_file)
+
+ if spec is None:
+ gdb.write(f"Warning: Could not create spec for '{component}' from '{init_file}'\n")
+ continue
+
module = importlib.util.module_from_spec(spec)
sys.modules[component] = module
- spec.loader.exec_module(module)
+
+ loader = spec.loader
+ if loader is None:
+ gdb.write(f"Warning: No loader found for '{component}' from '{init_file}'\n")
+ continue
+
+ loader.exec_module(module)
if hasattr(module, "register_printers"):
module.register_printers(gdb.current_objfile())
diff --git a/scripts/gdb/teachos/dump_mb2i.py b/scripts/gdb/teachos/dump_mb2i.py
index 0657ebde..518e696f 100644
--- a/scripts/gdb/teachos/dump_mb2i.py
+++ b/scripts/gdb/teachos/dump_mb2i.py
@@ -1,7 +1,8 @@
-import gdb
-import struct
from enum import IntEnum
from teachos import format_size
+from typing import override
+import gdb # pyright: ignore[reportMissingModuleSource]
+import struct
class TagType(IntEnum):
@@ -97,15 +98,16 @@ class DumpMB2I(gdb.Command):
def __init__(self):
super(DumpMB2I, self).__init__("dump_mb2i", gdb.COMMAND_USER)
- def invoke(self, arg, from_tty):
- if not arg:
+ @override
+ def invoke(self, argument, from_tty):
+ if not argument:
gdb.write(
"Error: please provide the address of the Multiboot2 information structure.\n"
)
return
try:
- address = int(gdb.parse_and_eval(arg))
+ address = int(gdb.parse_and_eval(argument))
except gdb.error as e:
gdb.write(f"Error: Invalid address expression: {e}\n")
return
@@ -215,7 +217,7 @@ class DumpMB2I(gdb.Command):
for i in range(num_entries):
entry_offset = 8 + i * entry_size
base, length, memory_type = struct.unpack_from("<QQI", data, entry_offset)
- type_string = MEMORY_TYPES.get(memory_type, "Unknown")
+ type_string = MEMORY_TYPES.get(MemoryType(memory_type), "Unknown")
gdb.write(
f"{INDENT}[{i:02d}] {base:#018x} - {base + length:#018x} | {format_size(length)} | type: {type_string}\n"
)
@@ -226,7 +228,7 @@ class DumpMB2I(gdb.Command):
def _write_framebuffer_info_tag(self, data):
address, pitch, width, height, bpp, type = struct.unpack_from("<QIIIBB", data)
- type_string = FRAMEBUFFER_TYPES.get(type, "Unknown")
+ type_string = FRAMEBUFFER_TYPES.get(FramebufferType(type), "Unknown")
gdb.write(f"{INDENT}address: {address:#010x} | type: {type_string}\n")
gdb.write(f"{INDENT}depth: {bpp} | pitch: {format_size(pitch)}\n")
if type == FramebufferType.TEXT:
diff --git a/scripts/gdb/toolchain.py b/scripts/gdb/toolchain.py
index bbb78102..b9cb90ad 100644
--- a/scripts/gdb/toolchain.py
+++ b/scripts/gdb/toolchain.py
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
+import importlib.util
def setup_toolchain_debugging():
@@ -21,11 +22,14 @@ def setup_toolchain_debugging():
if python_dir:
sys.path.insert(0, python_dir)
- from libstdcxx.v6.printers import register_libstdcxx_printers
- from libstdcxx.v6.xmethods import register_libstdcxx_xmethods
-
- register_libstdcxx_printers(None)
- register_libstdcxx_xmethods(None)
+ if importlib.util.find_spec("libstdcxx.v6.printers") is None:
+ print(f"libstdcxx.v6.printers not found in {python_dir}, libstdc++ printers and XMethods will not be available.")
+ return
+
+ printers = importlib.import_module("libstdcxx.v6.printers")
+ xmethods = importlib.import_module("libstdcxx.v6.xmethods")
+ printers.register_libstdcxx_printers(None)
+ xmethods.register_libstdcxx_xmethods(None)
print(f"Loaded Printers & Xmethods from: {python_dir}")
except Exception as e: