feat: owloysius - dynamic init function invocator
[lunaix-os.git] / lunaix-os / scripts / gdb / lunadbg / region_dump.py
index 92ee65d75fb8f9c6a2939799b8c7f80a61cb8c3a..223766bff3eb9c7413366196d741f2195311b989 100644 (file)
@@ -1,11 +1,35 @@
 import gdb
-from .utils import pid_argument
+from .utils import pid_argument, llist_foreach
 
 class MemoryRegionDump(gdb.Command):
     """Dump virtual memory regions associated with a process"""
     def __init__(self) -> None:
         super().__init__("vmrs", gdb.COMMAND_USER)
 
+    def region_callback(self, idx, region):
+        print(f"VMR #{idx}:")
+        print( "  0x%x...0x%x [0x%x]"%(
+            region['start'], region['end'], 
+            region['end'] - region['start']))
+        
+        attr = region["attr"]
+        attr_str = []
+        if (attr & (1 << 2)):
+            attr_str.append("R")
+        if (attr & (1 << 3)):
+            attr_str.append("W")
+        if (attr & (1 << 4)):
+            attr_str.append("X")
+        print( "  attr: 0x%x (%s)"%(attr, "".join(attr_str)))
+        
+        file = region["mfile"]
+        if file == 0:
+            print( "  anonymous region")
+        else:
+            print( "  file mapped:")
+            print( "     dnode: %s @0x%x"%(file["dnode"]["name"]["value"].string(), file))
+            print( "     frange: 0x%x+0x%x"%(region["foff"], region["flen"]))
+
     def invoke(self, argument: str, from_tty: bool) -> None:
         argument = pid_argument(argument)
         
@@ -19,31 +43,4 @@ class MemoryRegionDump(gdb.Command):
         
         print("VMRS (pid: %d)"%(pid))
 
-        i = 0
-        while(val["next"] != head):
-            region = val["next"].cast(region_t)
-            print(f"VMR #{i}:")
-            print( "  0x%x...0x%x [0x%x]"%(
-                region['start'], region['end'], 
-                region['end'] - region['start']))
-            
-            attr = region["attr"]
-            attr_str = []
-            if (attr & (1 << 2)):
-                attr_str.append("R")
-            if (attr & (1 << 3)):
-                attr_str.append("W")
-            if (attr & (1 << 4)):
-                attr_str.append("X")
-            print( "  attr: 0x%x (%s)"%(attr, "".join(attr_str)))
-            
-            file = region["mfile"]
-            if file == 0:
-                print( "  anonymous region")
-            else:
-                print( "  file mapped:")
-                print( "     dnode: %s @0x%x"%(file["dnode"]["name"]["value"].string(), file))
-                print( "     frange: 0x%x+0x%x"%(region["foff"], region["flen"]))
-
-            val = val["next"]
-            i+=1
+        llist_foreach(val, region_t, lambda a,b: self.region_callback(a,b))