X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/92f6e64a6da763c45ff9f4ab5eafcab3d8766dcb..b60166b327a9108b07e3069fa6568a451529ffd9:/lunaix-os/scripts/gdb/lunadbg/structs/region.py diff --git a/lunaix-os/scripts/gdb/lunadbg/structs/region.py b/lunaix-os/scripts/gdb/lunadbg/structs/region.py new file mode 100644 index 0000000..df50501 --- /dev/null +++ b/lunaix-os/scripts/gdb/lunadbg/structs/region.py @@ -0,0 +1,60 @@ +from gdb import Type, Value, lookup_type +from . import KernelStruct +from ..utils import get_dnode_path + +class MemRegion(KernelStruct): + def __init__(self, gdb_inferior: Value) -> None: + super().__init__(gdb_inferior, MemRegion) + self.__attr = self._kstruct["attr"] + + @staticmethod + def get_type() -> Type: + return lookup_type("struct mm_region").pointer() + + def print_abstract(self, pp, *args): + self.print_detailed(pp, *args) + + def print_simple(self, pp, *args): + self.print_detailed(pp, *args) + + def print_detailed(self, pp, *args): + pp.print( "0x%x...0x%x [0x%x]"%( + self._kstruct['start'], self._kstruct['end'], + self._kstruct['end'] - self._kstruct['start'])) + + pp.printf("attributes: %s (0x%x)", ", ".join([self.get_vmr_kind(), self.get_protection()]), self.__attr) + + file = self._kstruct["mfile"] + if file == 0: + pp.print("anonymous region") + else: + pp.print("file mapped:") + ppp = pp.next_level() + ppp.print("dnode: %s @0x%x"%(get_dnode_path(file["dnode"]), file)) + ppp.print("range: 0x%x+0x%x"%(self._kstruct["foff"], self._kstruct["flen"])) + + def get_protection(self): + attr_str = [] + if (self.__attr & (1 << 2)): + attr_str.append("R") + if (self.__attr & (1 << 3)): + attr_str.append("W") + if (self.__attr & (1 << 4)): + attr_str.append("X") + return ''.join(attr_str) + + def get_vmr_kind(self): + """ + #define REGION_TYPE_CODE (1 << 16) + #define REGION_TYPE_GENERAL (2 << 16) + #define REGION_TYPE_HEAP (3 << 16) + #define REGION_TYPE_STACK (4 << 16) + """ + types = ["exec", "data", "heap", "stack"] + attr = ((self.__attr >> 16) & 0xf) - 1 + if attr >= len(types): + return "unknown kind %d"%attr + return types[attr] + + + \ No newline at end of file