-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path.gdbinit
224 lines (204 loc) · 4.49 KB
/
.gdbinit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
set history filename .gdb_history
set history save
set print pretty on
set $wire_switched = 0
define list_len
set $start = &$arg0
set $count = 0
set $i = $start.next
while $count < 1000 && $i != $start
set $count = $count+1
set $i = $i.next
end
if $i == $start
echo list size:
p $count
else
echo size more than 1000\n
end
end
document list_len
show the size of a list like list.h's
end
define list_iter_start
set $li_start = &$arg0
set $li_count = 0
set $li_item = $li_start.next
if $li_item == $li_start
set $li_item = 0
end
end
document list_iter_start
Setup iteration through the linked list, use list_iter_next to go through it
args: <list>
end
define list_iter_next
if $li_item == 0
print "End of list"
return
end
set $li_item = $li_item.next
if $li_item == $li_start
set $li_item = 0
end
end
document list_iter_next
Go through the list as setup by list_iter_start
args: <none>
result: $li_item
end
define list_print
set $start = &$arg0
set $count = 0
set $i = $start.next
while $count < 1000 && $i != $start
p $arg1
set $count = $count+1
set $i = $i.next
end
end
document list_print
print all elements in list
args: <list> <transform>
end
define list_print_cond
set $start = &$arg0
set $count = 0
set $i = $start.next
while $count < 1000 && $i != $start
if $arg2
p $arg1
end
set $count = $count+1
set $i = $i.next
end
end
document list_print_cond
print all elements in list conditionally
args: <list> <transform> <condition>
end
define list_find
list_find_next $arg0 $arg1 $arg2 $arg0
end
document list_find
find element in a linked list like list.h's
args: <list> <transform> <condition>
transform is a transformation on list element $i
condition should use transformation result $x
end
define list_find_next
set $start = &$arg0
set $count = 0
set $i = $arg3.next
set $x = $arg1
while $count < 1000 && $i != $start && !($arg2)
set $count = $count+1
set $i = $i.next
set $x = $arg1
end
if $count == 1000 || $i == $start
echo not found\n
else
echo found\n
p $x
end
end
document list_find_next
find next element in a linked list like list.h's
args: <list> <transform> <condition> <start>
transform is a transformation on list element $i
condition should use transformation result $x
end
def _struct_from_elem
set $sfe = ($arg0 *) (((char*) $arg2) - (int) &(($arg0 *) 0).$arg1)
end
define struct_from_elem
_struct_from_elem $arg0 $arg1 $arg2
print $sfe
end
document struct_from_elem
get a struct from a pointer of its element.
args: <struct-type> <struct-elem-name> <elem-ptr>
end
define list_ready
list_iter_start g_wire_thread.ready_list
while $li_item != 0
_struct_from_elem wire_t list $li_item
printf "wire '%s': *(struct list_head*)0x%x -- *(wire_t*) 0x%x\n", $sfe.name, $li_item, $sfe
list_iter_next
end
end
document list_ready
Display the ready task list
end
define list_suspend
list_iter_start g_wire_thread.suspend_list
while $li_item != 0
_struct_from_elem wire_t list $li_item
printf "wire '%s': *(struct list_head*)0x%x -- *(wire_t*) 0x%x\n", $sfe.name, $li_item, $sfe
list_iter_next
end
end
document list_suspend
Display the suspended task list
end
define bt_wire
set $wire = (wire_t*)$arg0
set $new_rsp = $wire->ctx.sp
set $old_rsp = $rsp
set $old_rip = $rip
set $old_rbp = $rbp
set $rsp = $new_rsp
set $rip = *(uint64_t *)($new_rsp + 6)
set $rbp = *(uint64_t *)($new_rsp + 7)
printf "Wire '%s' rip=0x%x:\n", $wire->name, $rip
bt
set $rsp = $old_rsp
set $rip = $old_rip
set $rbp = $old_rbp
end
document bt_wire
Display the backtrace of a wire
end
define switch_wire
if $wire_switched != 1
set $old_rsp1 = $rsp
set $old_rip1 = $ip
set $old_rbp1 = $rbp
set $wire_switched = 1
end
set $wire = (wire_t*)$arg0
set $new_rsp = $wire->ctx.sp
set $rsp = $new_rsp
set $rip = *(uint64_t *)($new_rsp + 6)
set $rbp = *(uint64_t *)($new_rsp + 7)
printf "Wire '%s' rip=0x%x:\n", $wire->name, $rip
bt
end
document switch_wire
Switch to the wire given as an arg, use restore_wire to get back to the original place left
end
define restore_wire
if $wire_switched == 1
set $rsp = $old_rsp1
set $rip = $old_rip1
set $rbp = $old_rbp1
set $wire_switched = 0
end
end
document restore_wire
Switch back the original wire we left in switch_wire
end
define list_to_wire
struct_from_elem wire_t list $arg0
end
document list_to_wire
Get the wire from its list element
args: <list_head>
end
define list_to_wire_i
list_to_wire $i
end
document list_to_wire_i
Useful for list_find in the wire list, uses \$i as the argument
end