aboutsummaryrefslogtreecommitdiff
path: root/tools/debugscripts/gdbinit.kernel
blob: 274eb73d743be16bfba50542d85cd8d987697df7 (plain) (blame)
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# $FreeBSD$
# General kernel macros

# Print the command name of the current process
define pname
p (char *)curproc->p_comm
end 
document pname
Print the command name of the current process.
end

# Show contents of bp supplied as first parameter:
#
# (gdb) bpp bp
define bpp
set $bp = (struct buf *) $arg0
    if $bp->b_io.bio_dev
      printf "  Buffer at 0x%x: dev 0x%x  data 0x%x  bcount 0x%x  blkno 0x%x resid 0x%x\n", \
        $bp, \
        $bp->b_io.bio_dev->si_udev, \
        $bp->b_io.bio_data, \
        $bp->b_io.bio_bcount, \
        $bp->b_io.bio_blkno, \
        $bp->b_io.bio_resid
    else
      printf "  Buffer at 0x%x: dev (none) data 0x%x  bcount 0x%x  blkno 0x%x resid 0x%x\n", \
        $bp, \
        $bp->b_io.bio_data, \
        $bp->b_io.bio_bcount, \
        $bp->b_io.bio_blkno, \
        $bp->b_io.bio_resid
    end
    printf "   flags 0x%x: ", $bp->b_flags
      if $bp->b_flags & 0x10
        printf "busy "
      end
      if $bp->b_flags & 0x40
        printf "call "
      end
      if $bp->b_flags & 0x200
        printf "done "
      end
      if $bp->b_flags & 0x800
        printf "error "
      end
      if $bp->b_flags & 0x40000
        printf "phys "
      end
      if $bp->b_flags & 0x100000
        printf "read "
      end
    printf "\n"
end
document bpp
Show summary information about the buffer header (struct bp) pointed at by the parameter.
end

# Show more detailed contents of bp supplied as first parameter:
#
# (gdb) bpl bp
define bpl
set $bp = (struct buf *) $arg0
printf "b_proc: "
output $bp->b_proc
printf "\nb_flags:      "
output $bp->b_flags
printf "\nb_qindex:     "
output $bp->b_qindex
printf "\nb_usecount:   "
output $bp->b_usecount
printf "\nb_error:      "
output $bp->b_error
printf "\nb_bufsize:    "
output $bp->b_bufsize
printf "\nb_io.bio_bcount:     "
output $bp->b_io.bio_bcount
printf "\nb_io.bio_resid:      "
output $bp->b_io.bio_resid
printf "\nb_io.bio_dev:        "
output $bp->b_io.bio_dev
printf "\nb_io.bio_data:       "
output $bp->b_io.bio_data
printf "\nb_kvasize:    "
output $bp->b_kvasize
printf "\nb_lblkno:     "
output $bp->b_lblkno
printf "\nb_io.bio_blkno:      "
output $bp->b_io.bio_blkno
printf "\nb_iodone:     "
output $bp->b_iodone
printf "\nb_vp: "
output $bp->b_vp
printf "\nb_dirtyoff:   "
output $bp->b_dirtyoff
printf "\nb_dirtyend:   "
output $bp->b_dirtyend
printf "\nb_generation: "
output $bp->b_generation
printf "\nb_rcred:      "
output $bp->b_rcred
printf "\nb_wcred:      "
output $bp->b_wcred
printf "\nb_validoff:   "
output $bp->b_validoff
printf "\nb_validend:   "
output $bp->b_validend
printf "\nb_pblkno:     "
output $bp->b_pblkno
printf "\nb_saveaddr:   "
output $bp->b_saveaddr
printf "\nb_savekva:    "
output $bp->b_savekva
printf "\nb_driver1:    "
output $bp->b_driver1
printf "\nb_driver2:    "
output $bp->b_driver2
printf "\nb_spc:        "
output $bp->b_spc
printf "\nb_npages:     "
output $bp->b_npages
printf "\n"
end
document bpl
Show detailed information about the buffer header (struct bp) pointed at by the parameter.
end

# Show contents of buffer header in local variable bp. 
define bp
bpp bp
end
document bp
Show information about the buffer header pointed to by the variable bp in the current frame.
end

# Show data of buffer header in local variable bp as string.
define bpd
    printf "Buffer data:\n%s", (char *) bp->b_io.bio_data
end
document bpd
Show the contents (char*) of bp->data in the current frame.
end
document bpl
Show detailed information about the buffer header (struct bp) pointed at by the local variable bp.
end
define bx
printf "\n b_vnbufs " 
output/x bp->b_vnbufs
printf "\n b_freelist " 
output/x bp->b_freelist
printf "\n b_act " 
output/x bp->b_act
printf "\n b_flags " 
output/x bp->b_flags
printf "\n b_qindex " 
output/x bp->b_qindex
printf "\n b_usecount " 
output/x bp->b_usecount
printf "\n b_error " 
output/x bp->b_error
printf "\n b_bufsize " 
output/x bp->b_bufsize
printf "\n b_io.bio_bcount " 
output/x bp->b_io.bio_bcount
printf "\n b_io.bio_resid " 
output/x bp->b_io.bio_resid
printf "\n b_io.bio_dev " 
output/x bp->b_io.bio_dev
printf "\n b_io.bio_data " 
output/x bp->b_io.bio_data
printf "\n b_kvasize " 
output/x bp->b_kvasize
printf "\n b_io.bio_blkno " 
output/x bp->b_io.bio_blkno
printf "\n b_iodone_chain " 
output/x bp->b_iodone_chain
printf "\n b_vp " 
output/x bp->b_vp
printf "\n b_dirtyoff " 
output/x bp->b_dirtyoff
printf "\n b_validoff " 
output/x bp->b_validoff
echo \n
end
document bx
Print a number of fields from the buffer header pointed at in by the pointer bp in the current environment.
end

# Switch back to ddb
define ddb
set boothowto=0x80000000
s
end
document ddb
Switch back to ddb.
end

# ps: equivalent of the userland command
define ps
    set $nproc = nprocs
    set $aproc = allproc.lh_first
    set $proc = allproc.lh_first
    set $tid = 1
    printf "pid/ID ppid/tid uid  pgrp     flag st comm/name  proc/thread\n"
    while (--$nproc >= 0)
        set $pptr = $proc.p_pptr
        if ($pptr == 0)
           set $pptr = $proc
        end
        if ($proc.p_state)
            printf " %5d  %6d %4d %5d %8x %2d %-10s %p\n", \
                   $proc.p_pid, $pptr->p_pid, \
                   $proc.p_ucred->cr_ruid, \
                   $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \
                   &$proc.p_comm[0], $aproc
            set $thread = $proc->p_threads.tqh_first
            while ($thread)
                printf "(%5d) %6d                        %-10s %p", \
                   $tid, $thread->td_tid, $thread->td_name, $thread
                if ($thread.td_wmesg)
                    printf " %s", $thread.td_wmesg
                end
                printf "\n"
                set $thread = $thread->td_plist.tqe_next
                set $tid = $tid + 1
            end
        end
        set $aproc = $proc.p_list.le_next
        if ($aproc == 0 && $nproc > 0)
            set $aproc = zombproc
        end
        set $proc = $aproc
    end
end
document ps
Show process status without options. 
end

# Specify a process for other commands to refer to.
# Most are machine-dependent.
define defproc
    set $nproc = nprocs
    set $aproc = allproc.lh_first
    set $proc = allproc.lh_first
    while (--$nproc >= 0)
        if ($proc->p_pid == $arg0)
	   set $pptr = $proc.p_pptr
           if ($pptr == 0)
              set $pptr = $proc
           end
	   set $myvectorproc = $proc
           if ($proc.p_state)
               set $thread = $proc->p_threads.tqh_first
               while ($thread)
                   printf "%5d %08x %08x %4d %5d %5d  %06x  %d  %-10s   ", \
                          $proc.p_pid, $aproc, \
                          $proc.p_uarea, $proc.p_ucred->cr_ruid, $pptr->p_pid, \
                          $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \
                          &$proc.p_comm[0]
                   if ($thread.td_wchan)
                       if ($thread.td_wmesg)
                           printf "%s ", $thread.td_wmesg
                       end
                       printf "%x", $thread.td_wchan
                   end
                   printf "\n"     
                   set $thread = $thread->td_plist.tqe_next
               end
           end
           btpp
	   set $nproc = 0
	else
           set $proc = $proc.p_list.le_next
        end
   end
end
document defproc
Specify a process for btpp and fr commands.
end

define vdev
if (vp->v_type == VBLK)
  p *vp->v_un.vu_spec.vu_specinfo
  printf "numoutput: %d\n", vp->v_numoutput
else
  echo "Not a block device"
end
end
document vdev
Show some information of the vnode pointed to by the local variable vp.
end

# Kludge.  When changing macros, it's convenient to copy and paste
# definitions from the editor into the debugger window.
# Unfortunately, gdb insists on asking for confirmation after the
# "define" line.  y enables you to insert the confirmation in the
# definition without affecting the way the macro runs (much).
define y
echo Check your .gdbinit: it contains a y command\n
end

document y
Kludge for writing macros   This is a no-op except for printing a message   See gdb(4) for more details.
end

# dmesg: print msgbuf.  Can take forever.
define dmesg
printf "%s", msgbufp->msg_ptr
end
document dmesg
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
end

# checkmem: check unallocated memory for modifications
# this assumes that DIAGNOSTIC is set, which causes
# free memory to be set to 0xdeadc0de
#
# Use: checkmem offset length
define checkmem
set $offset = $arg0
# XXX sizeof int.   Needs changing for 64 bit machines.
# subtract 1 because the last word is always different.
set $length = $arg1 / 4 - 1
set $word = 0
while ($word < $length)
   if ((int *) $offset) [$word] != 0xdeadc0de
      printf "invalid word 0x%x at 0x%x\n", ((int *) $offset) [$word], &((int *) $offset) [$word]
   end
   set $word = $word + 1
end
end

document checkmem
Check unallocated memory for modifications  This assumes that DIAGNOSTIC is set which causes free memory to be set to 0xdeadc0de.
end

define kernel
  exec-file kernel.$arg0   
  symbol-file symbols.$arg0
  core-file vmcore.$arg0
end

define kldstat
  set $kld = linker_files.tqh_first
  printf "Id Refs Address    Size     Name\n"
  while ($kld != 0)
    printf "%2d %4d 0x%08x %-8x %s\n", \
      $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename
    set $kld = $kld->link.tqe_next
  end
end
 
document kldstat
  Lists the modules that were loaded when the kernel crashed.
end
 
define kldstat-v
  set $kld = linker_files.tqh_first
  printf "Id Refs Address    Size     Name\n"
  while ($kld != 0)
    printf "%2d %4d 0x%08x %-8x %s\n", \
      $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename
    printf "        Contains modules:\n"
    printf "                Id Name\n"
    set $module = $kld->modules.tqh_first
    while ($module != 0)
      printf "                %2d %s\n", $module->id, $module->name
      set $module = $module->link.tqe_next
    end
    set $kld = $kld->link.tqe_next
  end
end