aboutsummaryrefslogtreecommitdiff
path: root/scripts/gdb/pretty_printers.py
blob: 83db49181641eee5fd71e0668e75d60cb21f0dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import os
import gdb
import importlib.util

script_path = os.path.abspath(__file__)
repo_root = os.path.dirname(os.path.dirname(os.path.dirname(script_path)))

components = {
    "kstd": "libs/kstd/gdb",
    "kapi": "kapi/gdb",
}

for component, path in components.items():
    full_path = os.path.join(repo_root, *path.split("/"))
    init_file = os.path.join(full_path, "__init__.py")

    if os.path.isfile(init_file):
        try:
            spec = importlib.util.spec_from_file_location(component, init_file)
            module = importlib.util.module_from_spec(spec)
            sys.modules[component] = module
            spec.loader.exec_module(module)

            if hasattr(module, "register_printers"):
                module.register_printers(gdb.current_objfile())
                gdb.write(f"Info: Registered pretty printers for '{component}'.\n")
            else:
                gdb.write(
                    f"Warning: '{component}' does not have 'register_printers' function\n"
                )
        except Exception as e:
            gdb.write(f"Warning: Failed to load '{component}' pretty printers: {e}\n")
    else:
        gdb.write(f"Warning: GDB extension init not found: '{init_file}'\n")

gdb.write("Info: Loaded TeachOS pretty printers.\n")