gdbinit.kernel revision 256281
1142425Snectar# $FreeBSD: stable/10/tools/debugscripts/gdbinit.kernel 137923 2004-11-20 02:32:42Z das $ 2160814Ssimon# General kernel macros 3142425Snectar 4142425Snectar# Print the command name of the current process 5142425Snectardefine pname 6142425Snectarp (char *)curproc->p_comm 7142425Snectarend 8142425Snectardocument pname 9142425SnectarPrint the command name of the current process. 10142425Snectarend 11142425Snectar 12142425Snectar# Show contents of bp supplied as first parameter: 13142425Snectar# 14142425Snectar# (gdb) bpp bp 15142425Snectardefine bpp 16142425Snectarset $bp = (struct buf *) $arg0 17142425Snectar if $bp->b_io.bio_dev 18142425Snectar printf " Buffer at 0x%x: dev 0x%x data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 19142425Snectar $bp, \ 20160814Ssimon $bp->b_io.bio_dev->si_udev, \ 21142425Snectar $bp->b_io.bio_data, \ 22142425Snectar $bp->b_io.bio_bcount, \ 23142425Snectar $bp->b_io.bio_blkno, \ 24142425Snectar $bp->b_io.bio_resid 25142425Snectar else 26142425Snectar printf " Buffer at 0x%x: dev (none) data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 27142425Snectar $bp, \ 28142425Snectar $bp->b_io.bio_data, \ 29142425Snectar $bp->b_io.bio_bcount, \ 30142425Snectar $bp->b_io.bio_blkno, \ 31142425Snectar $bp->b_io.bio_resid 32142425Snectar end 33142425Snectar printf " flags 0x%x: ", $bp->b_flags 34142425Snectar if $bp->b_flags & 0x10 35142425Snectar printf "busy " 36142425Snectar end 37142425Snectar if $bp->b_flags & 0x40 38142425Snectar printf "call " 39142425Snectar end 40142425Snectar if $bp->b_flags & 0x200 41142425Snectar printf "done " 42142425Snectar end 43142425Snectar if $bp->b_flags & 0x800 44142425Snectar printf "error " 45142425Snectar end 46142425Snectar if $bp->b_flags & 0x40000 47160814Ssimon printf "phys " 48160814Ssimon end 49160814Ssimon if $bp->b_flags & 0x100000 50160814Ssimon printf "read " 51160814Ssimon end 52160814Ssimon printf "\n" 53142425Snectarend 54160814Ssimondocument bpp 55160814SsimonShow summary information about the buffer header (struct bp) pointed at by the parameter. 56142425Snectarend 57142425Snectar 58142425Snectar# Show more detailed contents of bp supplied as first parameter: 59142425Snectar# 60142425Snectar# (gdb) bpl bp 61142425Snectardefine bpl 62142425Snectarset $bp = (struct buf *) $arg0 63142425Snectarprintf "b_proc: " 64142425Snectaroutput $bp->b_proc 65160814Ssimonprintf "\nb_flags: " 66160814Ssimonoutput $bp->b_flags 67160814Ssimonprintf "\nb_qindex: " 68160814Ssimonoutput $bp->b_qindex 69160814Ssimonprintf "\nb_usecount: " 70160814Ssimonoutput $bp->b_usecount 71142425Snectarprintf "\nb_error: " 72142425Snectaroutput $bp->b_error 73142425Snectarprintf "\nb_bufsize: " 74142425Snectaroutput $bp->b_bufsize 75142425Snectarprintf "\nb_io.bio_bcount: " 76142425Snectaroutput $bp->b_io.bio_bcount 77142425Snectarprintf "\nb_io.bio_resid: " 78142425Snectaroutput $bp->b_io.bio_resid 79142425Snectarprintf "\nb_io.bio_dev: " 80142425Snectaroutput $bp->b_io.bio_dev 81142425Snectarprintf "\nb_io.bio_data: " 82142425Snectaroutput $bp->b_io.bio_data 83142425Snectarprintf "\nb_kvasize: " 84142425Snectaroutput $bp->b_kvasize 85160814Ssimonprintf "\nb_lblkno: " 86142425Snectaroutput $bp->b_lblkno 87142425Snectarprintf "\nb_io.bio_blkno: " 88142425Snectaroutput $bp->b_io.bio_blkno 89142425Snectarprintf "\nb_iodone: " 90142425Snectaroutput $bp->b_iodone 91142425Snectarprintf "\nb_vp: " 92142425Snectaroutput $bp->b_vp 93160814Ssimonprintf "\nb_dirtyoff: " 94142425Snectaroutput $bp->b_dirtyoff 95142425Snectarprintf "\nb_dirtyend: " 96142425Snectaroutput $bp->b_dirtyend 97142425Snectarprintf "\nb_generation: " 98142425Snectaroutput $bp->b_generation 99142425Snectarprintf "\nb_rcred: " 100142425Snectaroutput $bp->b_rcred 101142425Snectarprintf "\nb_wcred: " 102142425Snectaroutput $bp->b_wcred 103142425Snectarprintf "\nb_validoff: " 104142425Snectaroutput $bp->b_validoff 105142425Snectarprintf "\nb_validend: " 106142425Snectaroutput $bp->b_validend 107142425Snectarprintf "\nb_pblkno: " 108output $bp->b_pblkno 109printf "\nb_saveaddr: " 110output $bp->b_saveaddr 111printf "\nb_savekva: " 112output $bp->b_savekva 113printf "\nb_driver1: " 114output $bp->b_driver1 115printf "\nb_driver2: " 116output $bp->b_driver2 117printf "\nb_spc: " 118output $bp->b_spc 119printf "\nb_npages: " 120output $bp->b_npages 121printf "\n" 122end 123document bpl 124Show detailed information about the buffer header (struct bp) pointed at by the parameter. 125end 126 127# Show contents of buffer header in local variable bp. 128define bp 129bpp bp 130end 131document bp 132Show information about the buffer header pointed to by the variable bp in the current frame. 133end 134 135# Show data of buffer header in local variable bp as string. 136define bpd 137 printf "Buffer data:\n%s", (char *) bp->b_io.bio_data 138end 139document bpd 140Show the contents (char*) of bp->data in the current frame. 141end 142document bpl 143Show detailed information about the buffer header (struct bp) pointed at by the local variable bp. 144end 145define bx 146printf "\n b_vnbufs " 147output/x bp->b_vnbufs 148printf "\n b_freelist " 149output/x bp->b_freelist 150printf "\n b_act " 151output/x bp->b_act 152printf "\n b_flags " 153output/x bp->b_flags 154printf "\n b_qindex " 155output/x bp->b_qindex 156printf "\n b_usecount " 157output/x bp->b_usecount 158printf "\n b_error " 159output/x bp->b_error 160printf "\n b_bufsize " 161output/x bp->b_bufsize 162printf "\n b_io.bio_bcount " 163output/x bp->b_io.bio_bcount 164printf "\n b_io.bio_resid " 165output/x bp->b_io.bio_resid 166printf "\n b_io.bio_dev " 167output/x bp->b_io.bio_dev 168printf "\n b_io.bio_data " 169output/x bp->b_io.bio_data 170printf "\n b_kvasize " 171output/x bp->b_kvasize 172printf "\n b_io.bio_blkno " 173output/x bp->b_io.bio_blkno 174printf "\n b_iodone_chain " 175output/x bp->b_iodone_chain 176printf "\n b_vp " 177output/x bp->b_vp 178printf "\n b_dirtyoff " 179output/x bp->b_dirtyoff 180printf "\n b_validoff " 181output/x bp->b_validoff 182echo \n 183end 184document bx 185Print a number of fields from the buffer header pointed at in by the pointer bp in the current environment. 186end 187 188# Switch back to ddb 189define ddb 190set boothowto=0x80000000 191s 192end 193document ddb 194Switch back to ddb. 195end 196 197# ps: equivalent of the userland command 198define ps 199 set $nproc = nprocs 200 set $aproc = allproc.lh_first 201 set $proc = allproc.lh_first 202 printf " pid proc uid ppid pgrp flag stat comm wchan\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 set $thread = $proc->p_threads.tqh_first 210 while ($thread) 211 printf "%5d %08x %4d %5d %5d %06x %d %-10s ", \ 212 $proc.p_pid, $aproc, \ 213 $proc.p_ucred->cr_ruid, $pptr->p_pid, \ 214 $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \ 215 &$proc.p_comm[0] 216 if ($thread.td_wchan) 217 if ($thread.td_wmesg) 218 printf "%s ", $thread.td_wmesg 219 end 220 printf "%x", $thread.td_wchan 221 end 222 printf "\n" 223 set $thread = $thread->td_plist.tqe_next 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 232end 233document ps 234Show process status without options. 235end 236 237# Specify a process for other commands to refer to. 238# Most are machine-dependent. 239define 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 274end 275document defproc 276Specify a process for btpp and fr commands. 277end 278 279define vdev 280if (vp->v_type == VBLK) 281 p *vp->v_un.vu_spec.vu_specinfo 282 printf "numoutput: %d\n", vp->v_numoutput 283else 284 echo "Not a block device" 285end 286end 287document vdev 288Show some information of the vnode pointed to by the local variable vp. 289end 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). 296define y 297echo Check your .gdbinit: it contains a y command\n 298end 299 300document y 301Kludge for writing macros This is a no-op except for printing a message See gdb(4) for more details. 302end 303 304# dmesg: print msgbuf. Can take forever. 305define dmesg 306printf "%s", msgbufp->msg_ptr 307end 308document dmesg 309Print 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 310end 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 317define checkmem 318set $offset = $arg0 319# XXX sizeof int. Needs changing for 64 bit machines. 320# subtract 1 because the last word is always different. 321set $length = $arg1 / 4 - 1 322set $word = 0 323while ($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 328end 329end 330 331document checkmem 332Check unallocated memory for modifications This assumes that DIAGNOSTIC is set which causes free memory to be set to 0xdeadc0de. 333end 334 335define kernel 336 exec-file kernel.$arg0 337 symbol-file symbols.$arg0 338 core-file vmcore.$arg0 339end 340 341define 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 349end 350 351document kldstat 352 Lists the modules that were loaded when the kernel crashed. 353end 354 355define 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 370end 371