]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - tools/debugscripts/gdbinit.i386
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / tools / debugscripts / gdbinit.i386
1 # $FreeBSD$
2 # Assembler-level macros for i386
3 # Disassemble the next 10 instructions.
4 define xi
5 x/10i $eip
6 end
7
8 # Top 12 words on stack
9 define xs
10 x/12x $esp
11 end
12
13 # Top 12 words from frame pointer
14 define xb
15 x/12x $ebp
16 end
17
18 # single step through calls and disassemble the next instruction
19 define z
20 ni
21 x/1i $eip
22 end
23
24 # single step over calls and disassemble the next instruction
25 define zs
26 si
27 x/1i $eip
28 end
29
30 # show current stack frame and first 4 parameters
31 define xp
32 printf "      esp: " 
33 output/x $esp
34 echo  (
35 output (((int)$ebp)-(int)$esp)/4-4
36 printf " words on stack)\n      ebp: " 
37 output/x $ebp
38 printf "\n      eip: " 
39 x/1i $eip
40 printf "Saved ebp: " 
41 output/x *(int*)$ebp
42 printf " (maximum of "  
43 output ((*(int*)$ebp)-(int)$ebp)/4-4
44 printf " parameters possible)\nSaved eip: " 
45 x/1i *(int*)($ebp+4)
46 printf "\nParm 1 at " 
47 output/x (int) ($ebp+8)
48 printf ":    " 
49 output (char*) *(int*)($ebp+8)
50 printf "\nParm 2 at " 
51 output/x (int) ($ebp+12)
52 printf ":    " 
53 output (char*) *(int*)($ebp+12)
54 printf "\nParm 3 at " 
55 output/x (int) ($ebp+16)
56 printf ":    " 
57 output (char*) *(int*)($ebp+16)
58 printf "\nParm 4 at " 
59 output/x (int) ($ebp+20)
60 printf ":    " 
61 output (char*) *(int*)($ebp+20)
62 echo \n
63 end
64 document xp
65 Show the register contents and the first four parameter
66 words of the current frame.
67 end
68
69 # show current stack frame and first 10 parameters
70 define xxp
71 printf "      esp: " 
72 output/x $esp
73 printf "\n      ebp: " 
74 output/x $ebp
75 printf "\n      eip: " 
76 x/1i $eip
77 printf "Saved ebp: " 
78 output/x *(int*)$ebp
79 printf " (maximum of "  
80 output ((*(int*)$ebp)-(int)$ebp)/4-4
81 printf " parameters possible)\nSaved eip: " 
82 x/1i *(int*)($ebp+4)
83 printf "\nParm  1 at " 
84 output/x (int) ($ebp+8)
85 printf ":    " 
86 output (char*) *(int*)($ebp+8)
87 printf "\nParm  2 at " 
88 output/x (int) ($ebp+12)
89 printf ":    " 
90 output (char*) *(int*)($ebp+12)
91 printf "\nParm  3 at " 
92 output/x (int) ($ebp+16)
93 printf ":    " 
94 output (char*) *(int*)($ebp+16)
95 printf "\nParm  4 at " 
96 output/x (int) ($ebp+20)
97 printf ":    " 
98 output (char*) *(int*)($ebp+20)
99 printf "\nParm  5 at " 
100 output/x (int) ($ebp+24)
101 printf ":    " 
102 output (char*) *(int*)($ebp+24)
103 printf "\nParm  6 at " 
104 output/x (int) ($ebp+28)
105 printf ":    " 
106 output (char*) *(int*)($ebp+28)
107 printf "\nParm  7 at " 
108 output/x (int) ($ebp+32)
109 printf ":    " 
110 output (char*) *(int*)($ebp+32)
111 printf "\nParm  8 at " 
112 output/x (int) ($ebp+36)
113 printf ":    " 
114 output (char*) *(int*)($ebp+36)
115 printf "\nParm  9 at " 
116 output/x (int) ($ebp+40)
117 printf ":    " 
118 output (char*) *(int*)($ebp+40)
119 printf "\nParm 10 at " 
120 output/x (int) ($ebp+44)
121 printf ":    " 
122 output (char*) *(int*)($ebp+44)
123 echo \n
124 end
125 document xxp
126 Show the register contents and the first ten parameter
127 words of the current frame.
128 end
129
130 # Show first to fifth parameters of current frame as int, int * and char *.
131 define xp0
132 x/12x *(int*)$esp
133 p *(int*)$esp
134 p (char*)*$esp
135 end
136 define xp1
137 x/12x *(int*)($ebp+4)
138 p *(int*)($ebp+4)
139 p (char**)($ebp+4)
140 end
141 define xp2
142 x/12x *(int*)($ebp+8)
143 p *(int*)($ebp+8)
144 p *(char**)($ebp+8)
145 end
146 define xp3
147 x/12x *(int*)($ebp+12)
148 p *(int*)($ebp+12)
149 p (char**)($ebp+12)
150 end
151 define xp4
152 x/12x *(int*)($ebp+16)
153 p *(int*)($ebp+16)
154 p (char**)($ebp+16)
155 end
156 document xp0
157 Show the first parameter of current stack frame in various formats
158 end
159 document xp1
160 Show the second parameter of current stack frame in various formats
161 end
162 document xp2
163 Show the third parameter of current stack frame in various formats
164 end
165 document xp3
166 Show the fourth parameter of current stack frame in various formats
167 end
168 document xp4
169 Show the fifth parameter of current stack frame in various formats
170 end
171
172 # Select frame 0 to 5 and show stack information.
173 define f0
174 f 0
175 xp
176 end
177 define f1
178 f 1
179 xp
180 end
181 define f2
182 f 2
183 xp
184 end
185 define f3
186 f 3
187 xp
188 end
189 define f4
190 f 4
191 xp
192 end
193 define f5
194 f 5
195 xp
196 end
197 document f0
198 Select stack frame 0 and show assembler-level details
199 end
200 document f1
201 Select stack frame 1 and show assembler-level details
202 end
203 document f2
204 Select stack frame 2 and show assembler-level details
205 end
206 document f3
207 Select stack frame 3 and show assembler-level details
208 end
209 document f4
210 Select stack frame 4 and show assembler-level details
211 end
212 document f5
213 Select stack frame 5 and show assembler-level details
214 end
215 document z
216 Single step 1 instruction (over calls) and show next instruction.
217 end
218 document zs
219 Single step 1 instruction (through calls) and show next instruction.
220 end
221 document xi
222 List the next 10 instructions from the current IP value
223 end
224 document xs
225 Show the last 12 words on stack in hex
226 end
227 document xb
228 Show 12 words starting at current BP value in hex
229 end
230
231 # pcb <pid>
232 # show contents of pcb, currently only i386.
233 define pcb
234     set $nproc = nprocs
235     set $aproc = allproc.lh_first
236     set $proc = allproc.lh_first
237     while (--$nproc >= 0)
238         set $pptr = $proc.p_pptr
239         if ($proc->p_pid == $arg0)
240            set $pcba = $proc->p_threads.tqh_first->td_pcb
241            printf "ip: %08x sp: %08x bp: %08x bx: %08x\n", $pcba->pcb_eip, $pcba->pcb_esp, $pcba->pcb_ebp, $pcba->pcb_ebx
242            x/1i $pcba->pcb_eip
243            set $nproc = 0
244         end
245         set $aproc = $proc.p_list.le_next
246         if ($aproc == 0 && $nproc > 0)
247             set $aproc = zombproc
248         end
249         set $proc = $aproc
250     end
251 end
252 document pcb
253 Show some pcb contents of process whose pid is specified.
254 end
255
256 # btr <frame>
257 # primitive backtrace.  frame is a memory address.
258 define btr
259 set $frame = $arg0
260 set $fno = 0
261 while (*(int *) $frame > 0xc0000000)
262   set $myebp = *(int *) $frame
263   set $myeip = *(int *) ($frame + 4)
264   printf " frame %d at %p: ebp %8x, eip ", $fno, $frame, $myebp
265   x/1i $myeip
266   set $frame = $myebp
267   set $fno = $fno + 1
268 end
269 end
270 document btr
271 Show a backtrace from the ebp address specified.  This can be used to get a backtrace from any stack resident in memory.  It's the user's responsiblity to ensure that the address is meaningful.
272 end
273
274 # btp <pid>
275 # backtrace for process <pid>.  Uses btr (machine dependent) to perform the backtrace.
276 # may produce nonsense.
277 define btp
278     set $nproc = nprocs
279     set $aproc = allproc.lh_first
280     set $proc = allproc.lh_first
281     while (--$nproc >= 0)
282         if ($proc->p_pid == $arg0)
283            btr $proc->p_threads.tqh_first->td_pcb->pcb_ebp
284            set $nproc = 0
285         else
286            set $aproc = $proc.p_list.le_next
287            if ($aproc == 0 && $nproc > 0)
288               set $aproc = zombproc
289            end
290            set $proc = $aproc
291         end
292    end
293 end
294 document btp
295 Show a backtrace for the process whose pid is specified as a parameter.
296 end
297
298 # Do backtraces for all processes in the system.
299 # Uses btr (machine dependent) to perform the backtrace.
300 define btpa
301     set $nproc = nprocs
302     set $aproc = allproc.lh_first
303     set $proc = allproc.lh_first
304     printf "  pid    proc   uid  ppid  pgrp   flag stat comm         wchan\n"
305     while (--$nproc >= 0)
306         set $pptr = $proc.p_pptr
307         if ($pptr == 0)
308            set $pptr = $proc
309         end
310         if ($proc.p_stat)
311             printf "%5d %08x %4d %5d %5d  %06x %d  %-10s   ", \
312                    $proc.p_pid, $aproc, \
313                    $proc.p_cred->p_ruid, $pptr->p_pid, \
314                    $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_stat, \
315                    &$proc.p_comm[0]
316             if ($proc.p_wchan)
317                 if ($proc.p_wmesg)
318                     printf "%s ", $proc.p_wmesg
319                 end
320                 printf "%x", $proc.p_wchan
321             end
322             printf "\n"
323            if ($proc->p_flag & 4)
324               btr $proc->p_threads.tqh_first->td_pcb->pcb_ebp
325            else
326               echo (not loaded)\n
327            end
328         end
329         set $aproc = $proc.p_list.le_next
330         if ($aproc == 0 && $nproc > 0)
331             set $aproc = zombproc
332         end
333         set $proc = $aproc
334     end
335 end
336 document btpa
337 Show backtraces for all processes in the system.
338 end
339
340 # Show backtrace for process selected with "defproc"
341 define btpp
342 btr $myvectorproc->p_threads.tqh_first->td_pcb->pcb_ebp
343 end
344 document btpp
345 Show a backtrace for the process previously selected with 'defproc'.
346 end
347
348 # Specific stack fram of process selected with "defproc".
349 define fr
350 set $fno = 0
351 set $searching = 1
352 set $frame = $myvectorproc->p_threads.tqh_first->td_pcb->pcb_ebp
353 while (($searching == 1) && (*(int *) $frame > 0xc0000000))
354   set $myebp = *(int *) $frame
355   set $myeip = *(int *) ($frame + 4)
356   if ($fno == $arg0)
357     printf " frame %d at %p: ebp %8x, eip ", $fno, $frame, $myebp
358     x/1i $myeip
359     printf "Called from %8x, stack frame at %8x\n", *(int *) ($myebp+4), *(int *) $myebp
360     printf "last 20 local variables:\n"
361     x/20x ($myebp-80)
362     printf "call parameters:\n"
363     x/8x ($myebp+8)
364     set $searching = 0
365   else
366     set $frame = $myebp
367     set $fno = $fno + 1
368   end
369 end
370 if ($searching == 1)
371   echo frame not found\n
372 end
373 end
374 document fr
375 Show the frame of the stack of the process previously selected with 'defproc'.
376 end