]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/debugscripts/gdbinit.kernel
misc: Remove ancient SCCS tags.
[FreeBSD/FreeBSD.git] / tools / debugscripts / gdbinit.kernel
1 # General kernel macros
2
3 # Print the command name of the current process
4 define pname
5 p (char *)curproc->p_comm
6 end 
7 document pname
8 Print the command name of the current process.
9 end
10
11 # Show contents of bp supplied as first parameter:
12 #
13 # (gdb) bpp bp
14 define bpp
15 set $bp = (struct buf *) $arg0
16     if $bp->b_io.bio_dev
17       printf "  Buffer at 0x%x: dev 0x%x  data 0x%x  bcount 0x%x  blkno 0x%x resid 0x%x\n", \
18         $bp, \
19         $bp->b_io.bio_dev->si_udev, \
20         $bp->b_io.bio_data, \
21         $bp->b_io.bio_bcount, \
22         $bp->b_io.bio_blkno, \
23         $bp->b_io.bio_resid
24     else
25       printf "  Buffer at 0x%x: dev (none) data 0x%x  bcount 0x%x  blkno 0x%x resid 0x%x\n", \
26         $bp, \
27         $bp->b_io.bio_data, \
28         $bp->b_io.bio_bcount, \
29         $bp->b_io.bio_blkno, \
30         $bp->b_io.bio_resid
31     end
32     printf "   flags 0x%x: ", $bp->b_flags
33       if $bp->b_flags & 0x10
34         printf "busy "
35       end
36       if $bp->b_flags & 0x40
37         printf "call "
38       end
39       if $bp->b_flags & 0x200
40         printf "done "
41       end
42       if $bp->b_flags & 0x800
43         printf "error "
44       end
45       if $bp->b_flags & 0x40000
46         printf "phys "
47       end
48       if $bp->b_flags & 0x100000
49         printf "read "
50       end
51     printf "\n"
52 end
53 document bpp
54 Show summary information about the buffer header (struct bp) pointed at by the parameter.
55 end
56
57 # Show more detailed contents of bp supplied as first parameter:
58 #
59 # (gdb) bpl bp
60 define bpl
61 set $bp = (struct buf *) $arg0
62 printf "b_proc: "
63 output $bp->b_proc
64 printf "\nb_flags:      "
65 output $bp->b_flags
66 printf "\nb_qindex:     "
67 output $bp->b_qindex
68 printf "\nb_usecount:   "
69 output $bp->b_usecount
70 printf "\nb_error:      "
71 output $bp->b_error
72 printf "\nb_bufsize:    "
73 output $bp->b_bufsize
74 printf "\nb_io.bio_bcount:     "
75 output $bp->b_io.bio_bcount
76 printf "\nb_io.bio_resid:      "
77 output $bp->b_io.bio_resid
78 printf "\nb_io.bio_dev:        "
79 output $bp->b_io.bio_dev
80 printf "\nb_io.bio_data:       "
81 output $bp->b_io.bio_data
82 printf "\nb_kvasize:    "
83 output $bp->b_kvasize
84 printf "\nb_lblkno:     "
85 output $bp->b_lblkno
86 printf "\nb_io.bio_blkno:      "
87 output $bp->b_io.bio_blkno
88 printf "\nb_iodone:     "
89 output $bp->b_iodone
90 printf "\nb_vp: "
91 output $bp->b_vp
92 printf "\nb_dirtyoff:   "
93 output $bp->b_dirtyoff
94 printf "\nb_dirtyend:   "
95 output $bp->b_dirtyend
96 printf "\nb_generation: "
97 output $bp->b_generation
98 printf "\nb_rcred:      "
99 output $bp->b_rcred
100 printf "\nb_wcred:      "
101 output $bp->b_wcred
102 printf "\nb_validoff:   "
103 output $bp->b_validoff
104 printf "\nb_validend:   "
105 output $bp->b_validend
106 printf "\nb_pblkno:     "
107 output $bp->b_pblkno
108 printf "\nb_saveaddr:   "
109 output $bp->b_saveaddr
110 printf "\nb_savekva:    "
111 output $bp->b_savekva
112 printf "\nb_driver1:    "
113 output $bp->b_driver1
114 printf "\nb_driver2:    "
115 output $bp->b_driver2
116 printf "\nb_spc:        "
117 output $bp->b_spc
118 printf "\nb_npages:     "
119 output $bp->b_npages
120 printf "\n"
121 end
122 document bpl
123 Show detailed information about the buffer header (struct bp) pointed at by the parameter.
124 end
125
126 # Show contents of buffer header in local variable bp. 
127 define bp
128 bpp bp
129 end
130 document bp
131 Show information about the buffer header pointed to by the variable bp in the current frame.
132 end
133
134 # Show data of buffer header in local variable bp as string.
135 define bpd
136     printf "Buffer data:\n%s", (char *) bp->b_io.bio_data
137 end
138 document bpd
139 Show the contents (char*) of bp->data in the current frame.
140 end
141 document bpl
142 Show detailed information about the buffer header (struct bp) pointed at by the local variable bp.
143 end
144 define bx
145 printf "\n b_vnbufs " 
146 output/x bp->b_vnbufs
147 printf "\n b_freelist " 
148 output/x bp->b_freelist
149 printf "\n b_act " 
150 output/x bp->b_act
151 printf "\n b_flags " 
152 output/x bp->b_flags
153 printf "\n b_qindex " 
154 output/x bp->b_qindex
155 printf "\n b_usecount " 
156 output/x bp->b_usecount
157 printf "\n b_error " 
158 output/x bp->b_error
159 printf "\n b_bufsize " 
160 output/x bp->b_bufsize
161 printf "\n b_io.bio_bcount " 
162 output/x bp->b_io.bio_bcount
163 printf "\n b_io.bio_resid " 
164 output/x bp->b_io.bio_resid
165 printf "\n b_io.bio_dev " 
166 output/x bp->b_io.bio_dev
167 printf "\n b_io.bio_data " 
168 output/x bp->b_io.bio_data
169 printf "\n b_kvasize " 
170 output/x bp->b_kvasize
171 printf "\n b_io.bio_blkno " 
172 output/x bp->b_io.bio_blkno
173 printf "\n b_iodone_chain " 
174 output/x bp->b_iodone_chain
175 printf "\n b_vp " 
176 output/x bp->b_vp
177 printf "\n b_dirtyoff " 
178 output/x bp->b_dirtyoff
179 printf "\n b_validoff " 
180 output/x bp->b_validoff
181 echo \n
182 end
183 document bx
184 Print a number of fields from the buffer header pointed at in by the pointer bp in the current environment.
185 end
186
187 # Switch back to ddb
188 define ddb
189 set boothowto=0x80000000
190 s
191 end
192 document ddb
193 Switch back to ddb.
194 end
195
196 # ps: equivalent of the userland command
197 define ps
198     set $nproc = nprocs
199     set $aproc = allproc.lh_first
200     set $proc = allproc.lh_first
201     set $tid = 1
202     printf "pid/ID ppid/tid uid  pgrp     flag st comm/name  proc/thread\n"
203     while (--$nproc >= 0)
204         set $pptr = $proc.p_pptr
205         if ($pptr == 0)
206            set $pptr = $proc
207         end
208         if ($proc.p_state)
209             printf " %5d  %6d %4d %5d %8x %2d %-10s %p\n", \
210                    $proc.p_pid, $pptr->p_pid, \
211                    $proc.p_ucred->cr_ruid, \
212                    $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \
213                    &$proc.p_comm[0], $aproc
214             set $thread = $proc->p_threads.tqh_first
215             while ($thread)
216                 printf "(%5d) %6d                        %-10s %p", \
217                    $tid, $thread->td_tid, $thread->td_name, $thread
218                 if ($thread.td_wmesg)
219                     printf " %s", $thread.td_wmesg
220                 end
221                 printf "\n"
222                 set $thread = $thread->td_plist.tqe_next
223                 set $tid = $tid + 1
224             end
225         end
226         set $aproc = $proc.p_list.le_next
227         if ($aproc == 0 && $nproc > 0)
228             set $aproc = zombproc
229         end
230         set $proc = $aproc
231     end
232 end
233 document ps
234 Show process status without options. 
235 end
236
237 # Specify a process for other commands to refer to.
238 # Most are machine-dependent.
239 define defproc
240     set $nproc = nprocs
241     set $aproc = allproc.lh_first
242     set $proc = allproc.lh_first
243     while (--$nproc >= 0)
244         if ($proc->p_pid == $arg0)
245            set $pptr = $proc.p_pptr
246            if ($pptr == 0)
247               set $pptr = $proc
248            end
249            set $myvectorproc = $proc
250            if ($proc.p_state)
251                set $thread = $proc->p_threads.tqh_first
252                while ($thread)
253                    printf "%5d %08x %08x %4d %5d %5d  %06x  %d  %-10s   ", \
254                           $proc.p_pid, $aproc, \
255                           $proc.p_uarea, $proc.p_ucred->cr_ruid, $pptr->p_pid, \
256                           $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \
257                           &$proc.p_comm[0]
258                    if ($thread.td_wchan)
259                        if ($thread.td_wmesg)
260                            printf "%s ", $thread.td_wmesg
261                        end
262                        printf "%x", $thread.td_wchan
263                    end
264                    printf "\n"     
265                    set $thread = $thread->td_plist.tqe_next
266                end
267            end
268            btpp
269            set $nproc = 0
270         else
271            set $proc = $proc.p_list.le_next
272         end
273    end
274 end
275 document defproc
276 Specify a process for btpp and fr commands.
277 end
278
279 define vdev
280 if (vp->v_type == VBLK)
281   p *vp->v_un.vu_spec.vu_specinfo
282   printf "numoutput: %d\n", vp->v_numoutput
283 else
284   echo "Not a block device"
285 end
286 end
287 document vdev
288 Show some information of the vnode pointed to by the local variable vp.
289 end
290
291 # Kludge.  When changing macros, it's convenient to copy and paste
292 # definitions from the editor into the debugger window.
293 # Unfortunately, gdb insists on asking for confirmation after the
294 # "define" line.  y enables you to insert the confirmation in the
295 # definition without affecting the way the macro runs (much).
296 define y
297 echo Check your .gdbinit: it contains a y command\n
298 end
299
300 document y
301 Kludge for writing macros   This is a no-op except for printing a message   See gdb(4) for more details.
302 end
303
304 # dmesg: print msgbuf.  Can take forever.
305 define dmesg
306 printf "%s", msgbufp->msg_ptr
307 end
308 document dmesg
309 Print the system message buffer (dmesg) This can take a long time due to the time it takes to transmit the data across a serial line and even on a firewire connection the processing time slows it down
310 end
311
312 # checkmem: check unallocated memory for modifications
313 # this assumes that DIAGNOSTIC is set, which causes
314 # free memory to be set to 0xdeadc0de
315 #
316 # Use: checkmem offset length
317 define checkmem
318 set $offset = $arg0
319 # XXX sizeof int.   Needs changing for 64 bit machines.
320 # subtract 1 because the last word is always different.
321 set $length = $arg1 / 4 - 1
322 set $word = 0
323 while ($word < $length)
324    if ((int *) $offset) [$word] != 0xdeadc0de
325       printf "invalid word 0x%x at 0x%x\n", ((int *) $offset) [$word], &((int *) $offset) [$word]
326    end
327    set $word = $word + 1
328 end
329 end
330
331 document checkmem
332 Check unallocated memory for modifications  This assumes that DIAGNOSTIC is set which causes free memory to be set to 0xdeadc0de.
333 end
334
335 define kernel
336   exec-file kernel.$arg0   
337   symbol-file symbols.$arg0
338   core-file vmcore.$arg0
339 end
340
341 define kldstat
342   set $kld = linker_files.tqh_first
343   printf "Id Refs Address    Size     Name\n"
344   while ($kld != 0)
345     printf "%2d %4d 0x%08x %-8x %s\n", \
346       $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename
347     set $kld = $kld->link.tqe_next
348   end
349 end
350  
351 document kldstat
352   Lists the modules that were loaded when the kernel crashed.
353 end
354  
355 define kldstat-v
356   set $kld = linker_files.tqh_first
357   printf "Id Refs Address    Size     Name\n"
358   while ($kld != 0)
359     printf "%2d %4d 0x%08x %-8x %s\n", \
360       $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename
361     printf "        Contains modules:\n"
362     printf "                Id Name\n"
363     set $module = $kld->modules.tqh_first
364     while ($module != 0)
365       printf "                %2d %s\n", $module->id, $module->name
366       set $module = $module->link.tqe_next
367     end
368     set $kld = $kld->link.tqe_next
369   end
370 end