Skip to content

Commit 47d0d12

Browse files
cdleonardtorvalds
authored andcommitted
scripts/gdb: add hlist utilities
This allows easily examining kernel hlists in python. Link: http://lkml.kernel.org/r/Message-ID: Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com> Reviewed-by: Stephen Boyd <sboyd@kernel.org> Cc: Jason Wessel <jason.wessel@windriver.com> Cc: Jan Kiszka <jan.kiszka@siemens.com> Cc: Kieran Bingham <kbingham@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 494dbe0 commit 47d0d12

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎scripts/gdb/linux/lists.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from linux import utils
1717

1818
list_head = utils.CachedType("struct list_head")
19+
hlist_head = utils.CachedType("struct hlist_head")
20+
hlist_node = utils.CachedType("struct hlist_node")
1921

2022

2123
def list_for_each(head):
@@ -39,6 +41,27 @@ def list_for_each_entry(head, gdbtype, member):
3941
yield utils.container_of(node, gdbtype, member)
4042

4143

44+
def hlist_for_each(head):
45+
if head.type == hlist_head.get_type().pointer():
46+
head = head.dereference()
47+
elif head.type != hlist_head.get_type():
48+
raise gdb.GdbError("Must be struct hlist_head not {}"
49+
.format(head.type))
50+
51+
node = head['first'].dereference()
52+
while node.address:
53+
yield node.address
54+
node = node['next'].dereference()
55+
56+
57+
def hlist_for_each_entry(head, gdbtype, member):
58+
for node in hlist_for_each(head):
59+
if node.type != hlist_node.get_type().pointer():
60+
raise TypeError("Type {} found. Expected struct hlist_head *."
61+
.format(node.type))
62+
yield utils.container_of(node, gdbtype, member)
63+
64+
4265
def list_check(head):
4366
nb = 0
4467
if (head.type == list_head.get_type().pointer()):

0 commit comments

Comments
 (0)