gdbinit.kernel revision 115929
1# $FreeBSD: head/tools/debugscripts/gdbinit.kernel 115929 2003-06-07 01:17:04Z grog $ 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_stat) 252 printf "%5d %08x %08x %4d %5d %5d %06x %d %-10s ", \ 253 $proc.p_pid, $aproc, \ 254 $proc.p_uarea, $proc.p_cred->p_ruid, $pptr->p_pid, \ 255 $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_stat, \ 256 &$proc.p_comm[0] 257 if ($proc.p_wchan) 258 if ($proc.p_wmesg) 259 printf "%s ", $proc.p_wmesg 260 end 261 printf "%x", $proc.p_wchan 262 end 263 printf "\n" 264 end 265 btpp 266 set $nproc = 0 267 else 268 set $proc = $proc.p_list.le_next 269 end 270 end 271end 272document defproc 273Specify a process for btpp and fr commands. 274end 275 276define vdev 277if (vp->v_type == VBLK) 278 p *vp->v_un.vu_spec.vu_specinfo 279 printf "numoutput: %d\n", vp->v_numoutput 280else 281 echo "Not a block device" 282end 283end 284document vdev 285Show some information of the vnode pointed to by the local variable vp. 286end 287 288# Kludge. When changing macros, it's convenient to copy and paste 289# definitions from the editor into the debugger window. 290# Unfortunately, gdb insists on asking for confirmation after the 291# "define" line. y enables you to insert the confirmation in the 292# definition without affecting the way the macro runs (much). 293define y 294echo Check your .gdbinit, it contains a y command\n 295end 296 297# kldstat(8) lookalike 298define kldstat 299 set $file = linker_files.tqh_first 300 printf "Id Refs Address Size Name\n" 301 while ($file != 0) 302 printf "%2d %4d 0x%8x %8x %s\n", \ 303 $file->id, \ 304 $file->refs, \ 305 $file->address, \ 306 $file->size, \ 307 $file->filename 308 set $file = $file->link.tqe_next 309 end 310end 311document kldstat 312Equivalent of the kldstat(8) command, without options. 313end 314 315# msgbuf: print msgbuf. Can take forever. 316define msgbuf 317printf "%s", msgbufp->msg_ptr 318end 319document msgbuf 320Print 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. 321end 322 323# checkmem: check unallocated memory for modifications 324# this assumes that DIAGNOSTIC is set, which causes 325# free memory to be set to 0xdeadc0de 326# 327# Use: checkmem offset length 328define checkmem 329set $offset = $arg0 330# XXX sizeof int. Needs changing for 64 bit machines. 331# subtract 1 because the last word is always different. 332set $length = $arg1 / 4 - 1 333set $word = 0 334while ($word < $length) 335 if ((int *) $offset) [$word] != 0xdeadc0de 336 printf "invalid word 0x%x at 0x%x\n", ((int *) $offset) [$word], &((int *) $offset) [$word] 337 end 338 set $word = $word + 1 339end 340end 341