2 # gdb helper commands and functions for Linux kernel debugging
6 # Copyright (c) Thiebaud Weksteen, 2015
9 # Thiebaud Weksteen <thiebaud@weksteen.fr>
11 # This work is licensed under the terms of the GNU GPL version 2.
16 from linux
import utils
18 list_head
= utils
.CachedType("struct list_head")
21 def list_for_each(head
):
22 if head
.type == list_head
.get_type().pointer():
23 head
= head
.dereference()
24 elif head
.type != list_head
.get_type():
25 raise gdb
.GdbError("Must be struct list_head not {}"
28 node
= head
['next'].dereference()
29 while node
.address
!= head
.address
:
31 node
= node
['next'].dereference()
34 def list_for_each_entry(head
, gdbtype
, member
):
35 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 *."
39 yield utils
.container_of(node
, gdbtype
, member
)
44 if (head
.type == list_head
.get_type().pointer()):
45 head
= head
.dereference()
46 elif (head
.type != list_head
.get_type()):
47 raise gdb
.GdbError('argument must be of type (struct list_head [*])')
50 gdb
.write("Starting with: {}\n".format(c
))
51 except gdb
.MemoryError:
52 gdb
.write('head is not accessible\n')
55 p
= c
['prev'].dereference()
56 n
= c
['next'].dereference()
58 if p
['next'] != c
.address
:
59 gdb
.write('prev.next != current: '
60 'current@{current_addr}={current} '
61 'prev@{p_addr}={p}\n'.format(
62 current_addr
=c
.address
,
68 except gdb
.MemoryError:
69 gdb
.write('prev is not accessible: '
70 'current@{current_addr}={current}\n'.format(
71 current_addr
=c
.address
,
76 if n
['prev'] != c
.address
:
77 gdb
.write('next.prev != current: '
78 'current@{current_addr}={current} '
79 'next@{n_addr}={n}\n'.format(
80 current_addr
=c
.address
,
86 except gdb
.MemoryError:
87 gdb
.write('next is not accessible: '
88 'current@{current_addr}={current}\n'.format(
89 current_addr
=c
.address
,
96 gdb
.write("list is consistent: {} node(s)\n".format(nb
))
100 class LxListChk(gdb
.Command
):
101 """Verify a list consistency"""
104 super(LxListChk
, self
).__init
__("lx-list-check", gdb
.COMMAND_DATA
,
105 gdb
.COMPLETE_EXPRESSION
)
107 def invoke(self
, arg
, from_tty
):
108 argv
= gdb
.string_to_argv(arg
)
110 raise gdb
.GdbError("lx-list-check takes one argument")
111 list_check(gdb
.parse_and_eval(argv
[0]))
This page took 0.034146 seconds and 6 git commands to generate.