aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/gdb/__init__.py
blob: 671d203fb921a21da7be439c8b8a9229f1e12f8b (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
38
39
40
41
import gdb.printing  # pyright: ignore[reportMissingModuleSource]


from .flat_map import KstdFlatMapPrinter
from .error_code import KstdErrorCodePrinter
from .result import KstdResultPrinter
from .smart_pointers import (
    KstdUniquePtrPrinter,
    KstdSharedPtrPrinter,
    KstdObserverPtrPrinter,
    KstdWeakPtrPrinter,
)
from .string import KstdStringPrinter
from .units import KstdBytesPrinter
from .vector import KstdVectorPrinter


def build_pretty_printers():
    pp = gdb.printing.RegexpCollectionPrettyPrinter("kstd")
    pp.add_printer("vector", "^kstd::vector<.*>$", KstdVectorPrinter)
    pp.add_printer("flat_map", "^kstd::flat_map<.*>$", KstdFlatMapPrinter)
    pp.add_printer("string", "^kstd::basic_string<.*>$", KstdStringPrinter)
    pp.add_printer("unique_ptr", "^kstd::unique_ptr<.*>$", KstdUniquePtrPrinter)
    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("error_code", "^kstd::error_code$", KstdErrorCodePrinter)
    pp.add_printer("result", "^std::expected<.*, kstd::error_code>$", KstdResultPrinter)
    return pp


def register_printers(object_file):
    gdb.printing.register_pretty_printer(
        object_file, build_pretty_printers(), replace=True
    )