Skip to contentSkip to conversation

scripts/gdb: provide kernel list item generators

PATCH New [email protected] 1 participant 1 message May 23, 2016 GDB kernel debugging helper scripts

lore
Share & tools
lore
#0 lore raw

PATCH 50/84 scripts/gdb: provide kernel list item generators

From: Kieran Bingham <[email protected]>
Subject: scripts/gdb: provide kernel list item generators

Facilitate linked-list items by providing a generator to return the dereferenced, and type-cast objects from a kernel linked list

---

 scripts/gdb/linux/lists.py |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
scripts/gdb/linux/lists.py renamed from scripts/gdb/linux/lists.py~scripts-gdb-provide-kernel-list-item-generators +21 -0
diff -puN scripts/gdb/linux/lists.py~scripts-gdb-provide-kernel-list-item-generators scripts/gdb/linux/lists.py
@@ -18,6 +18,27 @@ from linux import utils
 list_head = utils.CachedType("struct list_head")
 
 
+def list_for_each(head):
+    if head.type == list_head.get_type().pointer():
+        head = head.dereference()
+    elif head.type != list_head.get_type():
+        raise gdb.GdbError("Must be struct list_head not {}"
+                           .format(head.type))
+
+    node = head['next'].dereference()
+    while node.address != head.address:
+        yield node.address
+        node = node['next'].dereference()
+
+
+def list_for_each_entry(head, gdbtype, member):
+    for node in list_for_each(head):
+        if node.type != list_head.get_type().pointer():
+            raise TypeError("Type {} found. Expected struct list_head *."
+                            .format(node.type))
+        yield utils.container_of(node, gdbtype, member)
+
+
 def list_check(head):
     nb = 0
     if (head.type == list_head.get_type().pointer()):

_