| .. | .. |
|---|
| 16 | 16 | from linux import utils |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | list_head = utils.CachedType("struct list_head") |
|---|
| 19 | +hlist_head = utils.CachedType("struct hlist_head") |
|---|
| 20 | +hlist_node = utils.CachedType("struct hlist_node") |
|---|
| 19 | 21 | |
|---|
| 20 | 22 | |
|---|
| 21 | 23 | def list_for_each(head): |
|---|
| 22 | 24 | if head.type == list_head.get_type().pointer(): |
|---|
| 23 | 25 | head = head.dereference() |
|---|
| 24 | 26 | elif head.type != list_head.get_type(): |
|---|
| 25 | | - raise gdb.GdbError("Must be struct list_head not {}" |
|---|
| 27 | + raise TypeError("Must be struct list_head not {}" |
|---|
| 26 | 28 | .format(head.type)) |
|---|
| 27 | 29 | |
|---|
| 28 | 30 | node = head['next'].dereference() |
|---|
| .. | .. |
|---|
| 33 | 35 | |
|---|
| 34 | 36 | def list_for_each_entry(head, gdbtype, member): |
|---|
| 35 | 37 | for node in list_for_each(head): |
|---|
| 36 | | - if node.type != list_head.get_type().pointer(): |
|---|
| 37 | | - raise TypeError("Type {} found. Expected struct list_head *." |
|---|
| 38 | | - .format(node.type)) |
|---|
| 38 | + yield utils.container_of(node, gdbtype, member) |
|---|
| 39 | + |
|---|
| 40 | + |
|---|
| 41 | +def hlist_for_each(head): |
|---|
| 42 | + if head.type == hlist_head.get_type().pointer(): |
|---|
| 43 | + head = head.dereference() |
|---|
| 44 | + elif head.type != hlist_head.get_type(): |
|---|
| 45 | + raise TypeError("Must be struct hlist_head not {}" |
|---|
| 46 | + .format(head.type)) |
|---|
| 47 | + |
|---|
| 48 | + node = head['first'].dereference() |
|---|
| 49 | + while node.address: |
|---|
| 50 | + yield node.address |
|---|
| 51 | + node = node['next'].dereference() |
|---|
| 52 | + |
|---|
| 53 | + |
|---|
| 54 | +def hlist_for_each_entry(head, gdbtype, member): |
|---|
| 55 | + for node in hlist_for_each(head): |
|---|
| 39 | 56 | yield utils.container_of(node, gdbtype, member) |
|---|
| 40 | 57 | |
|---|
| 41 | 58 | |
|---|
| .. | .. |
|---|
| 110 | 127 | raise gdb.GdbError("lx-list-check takes one argument") |
|---|
| 111 | 128 | list_check(gdb.parse_and_eval(argv[0])) |
|---|
| 112 | 129 | |
|---|
| 130 | + |
|---|
| 113 | 131 | LxListChk() |
|---|