Support to multi-threading and pthread interface (POSIX.1-2008) (#23)
[lunaix-os.git] / lunaix-os / scripts / gdb / lunadbg / utils.py
index b48adee776a8bc2961c134ef0a8aa84cde6d07a3..3e5682d2d163a3be051a71ff0267eec62782aace 100644 (file)
@@ -1,6 +1,42 @@
+import gdb
 
 def pid_argument(argument):
     if not argument:
         return "__current"
     else:
 
 def pid_argument(argument):
     if not argument:
         return "__current"
     else:
-        return f"sched_ctx._procs[({argument})]"
\ No newline at end of file
+        return f"sched_ctx.procs[({argument})]"
+
+def llist_foreach(head: gdb.Value, container_type: gdb.Type, field, cb, inclusive=True):
+    c = head
+    i = 0
+    offset = gdb.Value(0).cast(container_type)[field].address
+    offset_p = int(offset)
+
+    if not inclusive:
+        c = c["next"]
+        if c == head:
+            return 0
+
+    while (True):
+        current = gdb.Value(int(c) - offset_p)
+        el = current.cast(container_type)
+        cb(i, el)
+        c = c["next"]
+        i+=1
+        if c == head:
+            break
+    return i
+
+def get_dnode_name(dnode):
+    return dnode['name']['value'].string()
+
+def get_dnode_path(dnode):
+    components = []
+    current = dnode
+    while (current != 0 and current != current['parent']):
+        components.append(get_dnode_name(current))
+        current = current['parent']
+    if len(components) == 0:
+        components.append('')
+    components.append('')
+    return '/'.join(reversed(components))
\ No newline at end of file