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