aboutsummaryrefslogtreecommitdiff
path: root/scripts/gdb/kapi/address.py
blob: 677c9aaa73e9ebf6b894b5c92252d63d9e1c44d1 (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
import gdb


class KapiMemoryAddressPrinter:
    """Print kapi::MemoryAddress."""

    def __init__(self, val):
        self.val = val
        self.address_type = val.type.template_argument(0)

    def to_string(self):
        try:
            raw_address = int(self.val["m_value"])
            type_string = str(self.address_type)

            if "linear" in type_string:
                suffix = "%lin"
            elif "physical" in type_string:
                suffix = "%phy"
            else:
                suffix = "%???"

            return f"{raw_address:#018x}{suffix}"
        except Exception as e:
            return f"{self.val}: {e}"

    def children(self):
        if "linear" in str(self.address_type):
            yield (
                "std::byte *",
                self.val["m_value"].cast(gdb.lookup_type("std::byte").pointer()),
            )
        yield ("m_value", self.val["m_value"])