aboutsummaryrefslogtreecommitdiff
path: root/scripts/gdb/toolchain.py
blob: bbb78102d7785f608e8c004d77e8af49f20ecbc9 (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
import os
import subprocess
import sys


def setup_toolchain_debugging():
    try:
        gcc_path = (
            subprocess.check_output(["which", "x86_64-pc-elf-g++"])
            .decode("utf-8")
            .strip()
        )
        python_dir = None

        share_path = os.path.join(os.path.dirname(os.path.dirname(gcc_path)), "share")
        for root, dirs, _ in os.walk(share_path):
            if "libstdcxx" in dirs:
                python_dir = root
                break

        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)

            print(f"Loaded Printers & Xmethods from: {python_dir}")
    except Exception as e:
        print(f"Debug setup failed: {e}")


setup_toolchain_debugging()