aboutsummaryrefslogtreecommitdiff
path: root/scripts
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
parent83f264c22326ae37a0eb38284935a32895a48efb (diff)
downloadkernel-8bec65ba723c9c628d934ec02021d5ce09c01105.tar.xz
kernel-8bec65ba723c9c628d934ec02021d5ce09c01105.zip
chore: clean up python scripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/ci/parse_clang_tidy.py56
-rw-r--r--scripts/gdb/teachos.py15
-rw-r--r--scripts/gdb/teachos/dump_mb2i.py16
-rw-r--r--scripts/gdb/toolchain.py14
4 files changed, 75 insertions, 26 deletions
diff --git a/scripts/ci/parse_clang_tidy.py b/scripts/ci/parse_clang_tidy.py
index ec51d777..d2155afd 100644
--- a/scripts/ci/parse_clang_tidy.py
+++ b/scripts/ci/parse_clang_tidy.py
@@ -3,9 +3,38 @@ import json
import os
import re
import sys
+from typing import Dict, List
-def parse_clang_tidy(log_file_path: str) -> list[dict]:
+class SourceRange(dict):
+ def __init__(self, begin: int, end: int, column: int):
+ super().__init__(begin=begin, end=end, column=column)
+
+
+class SourceLocation(dict):
+ def __init__(self, path: str, lines: Dict[str, int]):
+ super().__init__(path=path, lines=lines)
+
+
+class ClangTidyError(dict):
+ def __init__(
+ self,
+ description: str,
+ check_name: str,
+ fingerprint: str,
+ severity: str,
+ location: SourceLocation,
+ ):
+ super().__init__(
+ description=description,
+ check_name=check_name,
+ fingerprint=fingerprint,
+ severity=severity,
+ location=location,
+ )
+
+
+def parse_clang_tidy(log_file_path: str) -> List[ClangTidyError]:
issues = []
pattern = re.compile(
r"^(.*?):(\d+):(\d+):\s+(warning|error|note):\s+(.*?)\s+\[(.*?)\]$"
@@ -30,17 +59,20 @@ def parse_clang_tidy(log_file_path: str) -> list[dict]:
fingerprint = hashlib.sha256(fingerprint_data.encode()).hexdigest()
issues.append(
- {
- "description": f"{message} ({name})",
- "fingerprint": fingerprint,
- "severity": severity,
- "location": {
- "path": path,
- "lines": {
- "begin": int(line),
- },
- },
- }
+ ClangTidyError(
+ description=f"{message}",
+ check_name=name,
+ fingerprint=fingerprint,
+ severity=severity,
+ location=SourceLocation(
+ path=path,
+ lines=SourceRange(
+ begin=int(line),
+ end=int(line),
+ column=int(column),
+ ),
+ ),
+ )
)
return issues
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: