/
gdbinit-mipsel
341 lines (293 loc) · 6.17 KB
/
gdbinit-mipsel
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#
# MIPSEL .gdbinit
#
# thx to mammon for "the" original gdbinit :>
# some of his stuff is in here verbatim, the x86
# specific stuff was obviously either removed (i.e. flags)
# or replaced (i.e. regs)
define bp
set $SHOW_CONTEXT = 1
break * $arg0
end
document bp
Set a breakpoint on address
Usage: bp addr
end
define bpc
clear $arg0
end
document bpc
Clear breakpoint at function/address
Usage: bpc addr
end
define bpe
enable $arg0
end
document bpe
Enable breakpoint #
Usage: bpe num
end
define bpd
disable $arg0
end
document bpd
Disable breakpoint #
Usage: bpd num
end
define bpt
set $SHOW_CONTEXT = 1
tbreak $arg0
end
document bpt
Set a temporary breakpoint on address
Usage: bpt addr
end
define bpm
set $SHOW_CONTEXT = 1
awatch $arg0
end
document bpm
Set a read/write breakpoint on address
Usage: bpm addr
end
define argv
show args
end
document argv
Print program arguments
end
define lib
info sharedlibrary
end
document lib
Print shared libraries linked to target
end
define sig
info signals
end
document sig
Print signal actions for target
end
define dis
disassemble $arg0
end
document dis
Disassemble address
Usage: dis addr
end
define ascii_char
set $_c=*(unsigned char *)($arg0)
if ( $_c < 0x20 || $_c > 0x7E )
printf "."
else
printf "%c", $_c
end
end
document ascii_char
Print the ASCII value of arg0 or '.' if value is unprintable
end
define hex_quad
printf "%02X %02X %02X %02X %02X %02X %02X %02X", \
*(unsigned char*)($arg0), *(unsigned char*)($arg0 + 1), \
*(unsigned char*)($arg0 + 2), *(unsigned char*)($arg0 + 3), \
*(unsigned char*)($arg0 + 4), *(unsigned char*)($arg0 + 5), \
*(unsigned char*)($arg0 + 6), *(unsigned char*)($arg0 + 7)
end
document hex_quad
Print eight hexadecimal bytes starting at arg0
end
define hexdump
printf "%s %08X : ", $arg0, $arg1
hex_quad $arg1
printf " - "
hex_quad ($arg1+8)
printf "\t"
ascii_char ($arg1)
ascii_char ($arg1+1)
ascii_char ($arg1+2)
ascii_char ($arg1+3)
ascii_char ($arg1+4)
ascii_char ($arg1+5)
ascii_char ($arg1+6)
ascii_char ($arg1+7)
ascii_char ($arg1+8)
ascii_char ($arg1+9)
ascii_char ($arg1+0xA)
ascii_char ($arg1+0xB)
ascii_char ($arg1+0xC)
ascii_char ($arg1+0xD)
ascii_char ($arg1+0xE)
ascii_char ($arg1+0xF)
printf "\n"
end
document hexdump
Display a 16-byte hex/ASCII dump of arg1 with label arg0
end
define context
printf "_______________________________________"
printf "________________________________________\n"
regs
printf "STACK @ 0x%.8x\n", $sp
printf "---------------------------------------"
printf "---------------------------------------\n"
hexdump "$sp[+0x30]" $sp+0x30
hexdump "$sp[+0x20]" $sp+0x20
hexdump "$sp[+0x10]" $sp+0x10
hexdump "$sp[=0x00]" $sp
hexdump "$sp[-0x20]" $sp-0x10
hexdump "$sp[-0x20]" $sp-0x20
hexdump "$sp[-0x30]" $sp-0x30
printf "CODE @ 0x%.8x\n", $pc
printf "-------------------------\n"
x /6i $pc
printf "---------------------------------------"
printf "---------------------------------------\n"
end
document context
Print regs, stack, ds:esi, and disassemble cs:eip
end
define context-on
set $SHOW_CONTEXT = 1
end
document context-on
Enable display of context on every program stop
end
define context-off
set $SHOW_CONTEXT = 1
end
document context-on
Disable display of context on every program stop
end
define n
ni
end
document n
Step one instruction
end
define pret
finish
end
document pret
Step out of current call
end
define init
set $SHOW_CONTEXT=1
set $SHOW_NEST_INSN=0
tbreak _init
r
end
document init
Run program; break on _init()
end
define start
set $SHOW_CONTEXT = 1
set $SHOW_NEST_INSN=0
tbreak _start
r
end
document start
Run program; break on _start()
end
define main
set $SHOW_CONTEXT=1
set $SHOW_NEST_INSN=0
tbreak main
r
end
document main
Run program; break on main()
end
#
# Sometimes gdb i r breaks, but it lets you access registers individually
# This is most common when debugging remote targets. It's nice to choose
# your own format for register output anyway
#
define regs
printf "\n"
printf "$a0: 0x%.8x $a1:0x%.8x\n", $a0, $a1
printf "$a2: 0x%.8x $a3:0x%.8x\n", $a2, $a3
printf "--\n"
printf "$t0: 0x%.8x $t1: 0x%.8x $t2: 0x%.8x\n", $t0, $t1, $t2
printf "$t3: 0x%.8x $t4: 0x%.8x $t5: 0x%.8x\n", $t3, $t4, $t5
printf "$t6: 0x%.8x $t7: 0x%.8x $t8: 0x%.8x\n", $t6, $t7, $t8
printf "--\n"
printf "$t9: 0x%.8x\n", $t9
printf "--\n"
printf "$v0: 0x%.8x $v1: 0x%.8x\n", $v0, $v1
printf "--\n"
printf "$s0: 0x%.8x $s1: 0x%.8x $s2: 0x%.8x\n", $s0, $s1, $s2
printf "$s3: 0x%.8x $s4: 0x%.8x $s5: 0x%.8x\n", $s3, $s4, $s5
printf "$s6: 0x%.8x $s7: 0x%.8x $s8: 0x%.8x\n", $s6, $s7, $s8
printf "--\n"
printf "$fp: 0x%.8x\n", $fp
printf "$sp: 0x%.8x\n", $sp
printf "$gp: 0x%.8x\n", $gp
printf "$ra: 0x%.8x\n", $ra
printf "$pc: 0x%.8x\n", $pc
printf "\n"
printf "-----------------------------------------------------------------\n"
end
document regs
Show registers
end
def ct
continue
end
document ct
Continue with execution
end
# If your gdb is broken or things are crashing or exiting you
# might need to use these. Sometimes it has to be turned off/on
# before after you attach to a remote target process.. ??
def fix
set unwindonsignal on
end
document fix
Turn on unwind on signal
end
def unfix
set unwindonsignal on
end
document unfix
turn on unwind on signal
end
# Tell gdb where the shared libraries are when debugging a
# remote target
define sopath
set solib-search-path $arg0
end
document sopath
Alias for set solib-search-path
Usage: sopath /path/to/libs
end
# Remote debugging
define go
target remote 127.0.0.1:12345
end
document go
Do some commands that you do often, generic alias
end
define plop
set unwindonsignal on
go
set unwindonsignal off
end
document plop
Same as go, but works around strange behavior
end
# Default GDB settings
set pagination off
set confirm off
set verbose off
set prompt gdb>
set output-radix 10
set input-radix 10
set history save on
set history size unlimited
set history filename .gdb_history
# These make gdb never pause in its output
set height 0
set width 0
# YMMV, good luck
set $SHOW_CONTEXT=1
set $SHOW_NEST_INSN=0