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


class KapiMemoryAddressPrinter(gdb.ValuePrinter):
    def __init__(self, val):
        self.__val = val
        self.__type = val.type.template_argument(0)

    def to_string(self):
        try:
            raw_address = int(self.__val["m_value"])
            type_string = str(self.__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.__type):
            pointer_type = gdb.lookup_type("std::byte").pointer()
            yield ("[bytes]", self.__val["m_value"].cast(pointer_type))

    def display_hint(self):
        return None