Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1397797

[PATCH 03/18] scripts/gdb: Provide kernel list item generators

From Jan Kiszka <jan.kiszka@siemens.com>
Newsgroups linux.kernel
Subject [PATCH 03/18] scripts/gdb: Provide kernel list item generators
Date 2016-05-10 09:50 +0200
Message-ID <rxaAz-6l0-57@gated-at.bofh.it> (permalink)
References <rxaAx-6l0-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Kieran Bingham <kieran.bingham@linaro.org>

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

CC: Jeff Mahoney <jeffm@suse.com>

Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 scripts/gdb/linux/lists.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py
index 3a3775b..2f335fb 100644
--- a/scripts/gdb/linux/lists.py
+++ b/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()):
-- 
2.1.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/18] scripts/gdb: Updates for 4.7 Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 13/18] scripts/gdb: Add documentation example for radix tree Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 03/18] scripts/gdb: Provide kernel list item generators Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 12/18] scripts/gdb: Add a Radix Tree Parser Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 06/18] scripts/gdb: Support !CONFIG_MODULES gracefully Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 07/18] scripts/gdb: Provide a dentry_name VFS path helper Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 17/18] scripts/gdb: decode bytestream on dmesg for Python3 Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 09/18] scripts/gdb: Add mount point list command Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200
  [PATCH 15/18] scripts/gdb: Improve types abstraction for gdb python scripts Jan Kiszka <jan.kiszka@siemens.com> - 2016-05-10 09:50 +0200

csiph-web