diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 13:10:21 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 13:10:21 +0200 |
| commit | 8bec65ba723c9c628d934ec02021d5ce09c01105 (patch) | |
| tree | 2eec65a312bf523bbe94811f1b8c9f904d07327b | |
| parent | 83f264c22326ae37a0eb38284935a32895a48efb (diff) | |
| download | kernel-8bec65ba723c9c628d934ec02021d5ce09c01105.tar.xz kernel-8bec65ba723c9c628d934ec02021d5ce09c01105.zip | |
chore: clean up python scripts
| -rw-r--r-- | arch/x86_64/arch/cpu/flags.cpp | 2 | ||||
| -rw-r--r-- | kapi/gdb/__init__.py | 6 | ||||
| -rw-r--r-- | kapi/gdb/boot_modules/boot_module.py | 2 | ||||
| -rw-r--r-- | kapi/gdb/boot_modules/boot_module_registry.py | 2 | ||||
| -rw-r--r-- | kapi/gdb/devices/device.py | 2 | ||||
| -rw-r--r-- | kapi/gdb/devices/resource.py | 2 | ||||
| -rw-r--r-- | kapi/gdb/filesystem/device_number.py | 2 | ||||
| -rw-r--r-- | kapi/gdb/memory/address.py | 2 | ||||
| -rw-r--r-- | kapi/gdb/memory/chunk.py | 2 | ||||
| -rw-r--r-- | libs/kstd/gdb/__init__.py | 16 | ||||
| -rw-r--r-- | libs/kstd/gdb/error_code.py | 9 | ||||
| -rw-r--r-- | libs/kstd/gdb/flat_map.py | 6 | ||||
| -rw-r--r-- | libs/kstd/gdb/result.py | 4 | ||||
| -rw-r--r-- | libs/kstd/gdb/smart_pointers.py | 2 | ||||
| -rw-r--r-- | libs/kstd/gdb/string.py | 2 | ||||
| -rw-r--r-- | libs/kstd/gdb/units.py | 6 | ||||
| -rw-r--r-- | libs/kstd/gdb/vector.py | 2 | ||||
| -rw-r--r-- | scripts/ci/parse_clang_tidy.py | 56 | ||||
| -rw-r--r-- | scripts/gdb/teachos.py | 15 | ||||
| -rw-r--r-- | scripts/gdb/teachos/dump_mb2i.py | 16 | ||||
| -rw-r--r-- | scripts/gdb/toolchain.py | 14 |
21 files changed, 113 insertions, 57 deletions
diff --git a/arch/x86_64/arch/cpu/flags.cpp b/arch/x86_64/arch/cpu/flags.cpp index 12a2ceee..dc70555d 100644 --- a/arch/x86_64/arch/cpu/flags.cpp +++ b/arch/x86_64/arch/cpu/flags.cpp @@ -1,5 +1,7 @@ #include <arch/cpu/flags.hpp> +#include <kstd/vector.hpp> + namespace arch::cpu { diff --git a/kapi/gdb/__init__.py b/kapi/gdb/__init__.py index c48db922..5d411a0e 100644 --- a/kapi/gdb/__init__.py +++ b/kapi/gdb/__init__.py @@ -1,4 +1,4 @@ -import gdb.printing +import gdb.printing # pyright: ignore[reportMissingModuleSource] from .boot_modules import * from .devices import * @@ -40,5 +40,5 @@ def build_pretty_printers(): return pp -def register_printers(objfile): - gdb.printing.register_pretty_printer(objfile, build_pretty_printers(), replace=True) +def register_printers(object_file): + gdb.printing.register_pretty_printer(object_file, build_pretty_printers(), replace=True) diff --git a/kapi/gdb/boot_modules/boot_module.py b/kapi/gdb/boot_modules/boot_module.py index 97e6584b..cd45e4c0 100644 --- a/kapi/gdb/boot_modules/boot_module.py +++ b/kapi/gdb/boot_modules/boot_module.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] from teachos import format_size diff --git a/kapi/gdb/boot_modules/boot_module_registry.py b/kapi/gdb/boot_modules/boot_module_registry.py index 599a8234..262d46f3 100644 --- a/kapi/gdb/boot_modules/boot_module_registry.py +++ b/kapi/gdb/boot_modules/boot_module_registry.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] from teachos import format_size diff --git a/kapi/gdb/devices/device.py b/kapi/gdb/devices/device.py index 18c6e166..d378759a 100644 --- a/kapi/gdb/devices/device.py +++ b/kapi/gdb/devices/device.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KapiDevicesDevicePrinter(gdb.ValuePrinter): diff --git a/kapi/gdb/devices/resource.py b/kapi/gdb/devices/resource.py index dd5fd320..96d64d41 100644 --- a/kapi/gdb/devices/resource.py +++ b/kapi/gdb/devices/resource.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] # Map from the resource_type enum integer value to a readable name. diff --git a/kapi/gdb/filesystem/device_number.py b/kapi/gdb/filesystem/device_number.py index e215dd3a..ae3111af 100644 --- a/kapi/gdb/filesystem/device_number.py +++ b/kapi/gdb/filesystem/device_number.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KapiFilesystemDeviceNumberPrinter(gdb.ValuePrinter): diff --git a/kapi/gdb/memory/address.py b/kapi/gdb/memory/address.py index 429db1de..3eb03575 100644 --- a/kapi/gdb/memory/address.py +++ b/kapi/gdb/memory/address.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KapiMemoryAddressPrinter(gdb.ValuePrinter): diff --git a/kapi/gdb/memory/chunk.py b/kapi/gdb/memory/chunk.py index 74b1407f..5912636d 100644 --- a/kapi/gdb/memory/chunk.py +++ b/kapi/gdb/memory/chunk.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] from teachos import format_size diff --git a/libs/kstd/gdb/__init__.py b/libs/kstd/gdb/__init__.py index a4aee9cd..671d203f 100644 --- a/libs/kstd/gdb/__init__.py +++ b/libs/kstd/gdb/__init__.py @@ -1,4 +1,4 @@ -import gdb.printing +import gdb.printing # pyright: ignore[reportMissingModuleSource] from .flat_map import KstdFlatMapPrinter @@ -24,12 +24,18 @@ def build_pretty_printers(): pp.add_printer("shared_ptr", "^kstd::shared_ptr<.*>$", KstdSharedPtrPrinter) pp.add_printer("weak_ptr", "^kstd::weak_ptr<.*>$", KstdWeakPtrPrinter) pp.add_printer("observer_ptr", "^kstd::observer_ptr<.*>$", KstdObserverPtrPrinter) - pp.add_printer("bytes", "^kstd::basic_unit<.*, kstd::bytes_tag, .*>$", KstdBytesPrinter) - pp.add_printer("offset", "^kstd::basic_unit<.*, kstd::byte_offset_tag, .*>$", KstdBytesPrinter) + pp.add_printer( + "bytes", "^kstd::basic_unit<.*, kstd::bytes_tag, .*>$", KstdBytesPrinter + ) + pp.add_printer( + "offset", "^kstd::basic_unit<.*, kstd::byte_offset_tag, .*>$", KstdBytesPrinter + ) pp.add_printer("error_code", "^kstd::error_code$", KstdErrorCodePrinter) pp.add_printer("result", "^std::expected<.*, kstd::error_code>$", KstdResultPrinter) return pp -def register_printers(objfile): - gdb.printing.register_pretty_printer(objfile, build_pretty_printers(), replace=True) +def register_printers(object_file): + gdb.printing.register_pretty_printer( + object_file, build_pretty_printers(), replace=True + ) diff --git a/libs/kstd/gdb/error_code.py b/libs/kstd/gdb/error_code.py index 1569f59a..74aa125c 100644 --- a/libs/kstd/gdb/error_code.py +++ b/libs/kstd/gdb/error_code.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KstdErrorCodePrinter(gdb.ValuePrinter): @@ -23,7 +23,7 @@ class KstdErrorCodePrinter(gdb.ValuePrinter): if name.endswith("_t"): name = name[:-2] return name - except (gdb.error, AttributeError): + except gdb.error, AttributeError: return "?" def _message(self): @@ -41,10 +41,10 @@ class KstdErrorCodePrinter(gdb.ValuePrinter): length = int(result["_M_len"]) if int(ptr) != 0 and length > 0: return ptr.string(length=length) - except (gdb.error, AttributeError, KeyError): + except gdb.error, AttributeError, KeyError: pass return str(result) - except (gdb.error, RuntimeError): + except gdb.error, RuntimeError: return None def to_string(self): @@ -63,4 +63,3 @@ class KstdErrorCodePrinter(gdb.ValuePrinter): def display_hint(self): return None - diff --git a/libs/kstd/gdb/flat_map.py b/libs/kstd/gdb/flat_map.py index f5f37cb5..3891e515 100644 --- a/libs/kstd/gdb/flat_map.py +++ b/libs/kstd/gdb/flat_map.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KstdFlatMapPrinter(gdb.ValuePrinter): @@ -38,7 +38,9 @@ class KstdFlatMapPrinter(gdb.ValuePrinter): self.__val_type = val.type.template_argument(1) def to_string(self): - return f"flat_map<{self.__key_type}, {self.__val_type}> with {self.__size} entries" + return ( + f"flat_map<{self.__key_type}, {self.__val_type}> with {self.__size} entries" + ) def children(self): return self._Iterator(self.__keys_ptr, self.__vals_ptr, self.__size) diff --git a/libs/kstd/gdb/result.py b/libs/kstd/gdb/result.py index 8cef0fed..ec0c74de 100644 --- a/libs/kstd/gdb/result.py +++ b/libs/kstd/gdb/result.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] from .error_code import KstdErrorCodePrinter @@ -10,7 +10,7 @@ class KstdResultPrinter(gdb.ValuePrinter): try: t = val.type.template_argument(0) self.__is_void = t.code == gdb.TYPE_CODE_VOID - except (gdb.error, AttributeError): + except gdb.error, AttributeError: self.__is_void = False @property diff --git a/libs/kstd/gdb/smart_pointers.py b/libs/kstd/gdb/smart_pointers.py index c7b6c660..838f0274 100644 --- a/libs/kstd/gdb/smart_pointers.py +++ b/libs/kstd/gdb/smart_pointers.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] def _dereference_dynamic(pointer): diff --git a/libs/kstd/gdb/string.py b/libs/kstd/gdb/string.py index b60cbe67..521db077 100644 --- a/libs/kstd/gdb/string.py +++ b/libs/kstd/gdb/string.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KstdStringPrinter(gdb.ValuePrinter): diff --git a/libs/kstd/gdb/units.py b/libs/kstd/gdb/units.py index 2ba533bd..9956ed94 100644 --- a/libs/kstd/gdb/units.py +++ b/libs/kstd/gdb/units.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KstdBytesPrinter(gdb.ValuePrinter): @@ -8,7 +8,7 @@ class KstdBytesPrinter(gdb.ValuePrinter): self.__value = val["value"] def to_string(self): - units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'] + units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"] size_in_bytes = int(self.__value) if size_in_bytes == 0: @@ -28,5 +28,3 @@ class KstdBytesPrinter(gdb.ValuePrinter): def children(self): yield ("value", self.__value) - - diff --git a/libs/kstd/gdb/vector.py b/libs/kstd/gdb/vector.py index f11e064c..d2ab112d 100644 --- a/libs/kstd/gdb/vector.py +++ b/libs/kstd/gdb/vector.py @@ -1,4 +1,4 @@ -import gdb +import gdb # pyright: ignore[reportMissingModuleSource] class KstdVectorPrinter(gdb.ValuePrinter): 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: |
