Skip to content

Commit

Permalink
scripts/gdb: provide kernel list item generators
Browse files Browse the repository at this point in the history
Facilitate linked-list items by providing a generator to return the
dereferenced, and type-cast objects from a kernel linked list

Link: http://lkml.kernel.org/r/2b0998564e6e5abe53585d466f87e491331fd2a4.1462865983.git.jan.kiszka@siemens.com
Signed-off-by: Kieran Bingham <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
Cc: Jeff Mahoney <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kbingham authored and torvalds committed May 24, 2016
1 parent f197d75 commit a84be61
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/gdb/linux/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@
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()):
Expand Down

0 comments on commit a84be61

Please sign in to comment.