1030b9a7cSGreg Lehey# General kernel macros 2030b9a7cSGreg Lehey 3030b9a7cSGreg Lehey# Print the command name of the current process 4030b9a7cSGreg Leheydefine pname 5030b9a7cSGreg Leheyp (char *)curproc->p_comm 6030b9a7cSGreg Leheyend 7030b9a7cSGreg Leheydocument pname 8410b51e7SGreg LeheyPrint the command name of the current process. 9030b9a7cSGreg Leheyend 10030b9a7cSGreg Lehey 11030b9a7cSGreg Lehey# Show contents of bp supplied as first parameter: 12030b9a7cSGreg Lehey# 13030b9a7cSGreg Lehey# (gdb) bpp bp 14030b9a7cSGreg Leheydefine bpp 15030b9a7cSGreg Leheyset $bp = (struct buf *) $arg0 16030b9a7cSGreg Lehey if $bp->b_io.bio_dev 17030b9a7cSGreg Lehey printf " Buffer at 0x%x: dev 0x%x data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 18030b9a7cSGreg Lehey $bp, \ 19030b9a7cSGreg Lehey $bp->b_io.bio_dev->si_udev, \ 20030b9a7cSGreg Lehey $bp->b_io.bio_data, \ 21030b9a7cSGreg Lehey $bp->b_io.bio_bcount, \ 22030b9a7cSGreg Lehey $bp->b_io.bio_blkno, \ 23030b9a7cSGreg Lehey $bp->b_io.bio_resid 24030b9a7cSGreg Lehey else 25030b9a7cSGreg Lehey printf " Buffer at 0x%x: dev (none) data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 26030b9a7cSGreg Lehey $bp, \ 27030b9a7cSGreg Lehey $bp->b_io.bio_data, \ 28030b9a7cSGreg Lehey $bp->b_io.bio_bcount, \ 29030b9a7cSGreg Lehey $bp->b_io.bio_blkno, \ 30030b9a7cSGreg Lehey $bp->b_io.bio_resid 31030b9a7cSGreg Lehey end 32030b9a7cSGreg Lehey printf " flags 0x%x: ", $bp->b_flags 33030b9a7cSGreg Lehey if $bp->b_flags & 0x10 34030b9a7cSGreg Lehey printf "busy " 35030b9a7cSGreg Lehey end 36030b9a7cSGreg Lehey if $bp->b_flags & 0x40 37030b9a7cSGreg Lehey printf "call " 38030b9a7cSGreg Lehey end 39030b9a7cSGreg Lehey if $bp->b_flags & 0x200 40030b9a7cSGreg Lehey printf "done " 41030b9a7cSGreg Lehey end 42030b9a7cSGreg Lehey if $bp->b_flags & 0x800 43030b9a7cSGreg Lehey printf "error " 44030b9a7cSGreg Lehey end 45030b9a7cSGreg Lehey if $bp->b_flags & 0x40000 46030b9a7cSGreg Lehey printf "phys " 47030b9a7cSGreg Lehey end 48030b9a7cSGreg Lehey if $bp->b_flags & 0x100000 49030b9a7cSGreg Lehey printf "read " 50030b9a7cSGreg Lehey end 51030b9a7cSGreg Lehey printf "\n" 52030b9a7cSGreg Leheyend 53030b9a7cSGreg Leheydocument bpp 54410b51e7SGreg LeheyShow summary information about the buffer header (struct bp) pointed at by the parameter. 55030b9a7cSGreg Leheyend 56030b9a7cSGreg Lehey 57030b9a7cSGreg Lehey# Show more detailed contents of bp supplied as first parameter: 58030b9a7cSGreg Lehey# 59030b9a7cSGreg Lehey# (gdb) bpl bp 60030b9a7cSGreg Leheydefine bpl 61030b9a7cSGreg Leheyset $bp = (struct buf *) $arg0 62030b9a7cSGreg Leheyprintf "b_proc: " 63030b9a7cSGreg Leheyoutput $bp->b_proc 64030b9a7cSGreg Leheyprintf "\nb_flags: " 65030b9a7cSGreg Leheyoutput $bp->b_flags 66030b9a7cSGreg Leheyprintf "\nb_qindex: " 67030b9a7cSGreg Leheyoutput $bp->b_qindex 68030b9a7cSGreg Leheyprintf "\nb_usecount: " 69030b9a7cSGreg Leheyoutput $bp->b_usecount 70030b9a7cSGreg Leheyprintf "\nb_error: " 71030b9a7cSGreg Leheyoutput $bp->b_error 72030b9a7cSGreg Leheyprintf "\nb_bufsize: " 73030b9a7cSGreg Leheyoutput $bp->b_bufsize 74030b9a7cSGreg Leheyprintf "\nb_io.bio_bcount: " 75030b9a7cSGreg Leheyoutput $bp->b_io.bio_bcount 76030b9a7cSGreg Leheyprintf "\nb_io.bio_resid: " 77030b9a7cSGreg Leheyoutput $bp->b_io.bio_resid 78030b9a7cSGreg Leheyprintf "\nb_io.bio_dev: " 79030b9a7cSGreg Leheyoutput $bp->b_io.bio_dev 80030b9a7cSGreg Leheyprintf "\nb_io.bio_data: " 81030b9a7cSGreg Leheyoutput $bp->b_io.bio_data 82030b9a7cSGreg Leheyprintf "\nb_kvasize: " 83030b9a7cSGreg Leheyoutput $bp->b_kvasize 84030b9a7cSGreg Leheyprintf "\nb_lblkno: " 85030b9a7cSGreg Leheyoutput $bp->b_lblkno 86030b9a7cSGreg Leheyprintf "\nb_io.bio_blkno: " 87030b9a7cSGreg Leheyoutput $bp->b_io.bio_blkno 88030b9a7cSGreg Leheyprintf "\nb_iodone: " 89030b9a7cSGreg Leheyoutput $bp->b_iodone 90030b9a7cSGreg Leheyprintf "\nb_vp: " 91030b9a7cSGreg Leheyoutput $bp->b_vp 92030b9a7cSGreg Leheyprintf "\nb_dirtyoff: " 93030b9a7cSGreg Leheyoutput $bp->b_dirtyoff 94030b9a7cSGreg Leheyprintf "\nb_dirtyend: " 95030b9a7cSGreg Leheyoutput $bp->b_dirtyend 96030b9a7cSGreg Leheyprintf "\nb_generation: " 97030b9a7cSGreg Leheyoutput $bp->b_generation 98030b9a7cSGreg Leheyprintf "\nb_rcred: " 99030b9a7cSGreg Leheyoutput $bp->b_rcred 100030b9a7cSGreg Leheyprintf "\nb_wcred: " 101030b9a7cSGreg Leheyoutput $bp->b_wcred 102030b9a7cSGreg Leheyprintf "\nb_validoff: " 103030b9a7cSGreg Leheyoutput $bp->b_validoff 104030b9a7cSGreg Leheyprintf "\nb_validend: " 105030b9a7cSGreg Leheyoutput $bp->b_validend 106030b9a7cSGreg Leheyprintf "\nb_pblkno: " 107030b9a7cSGreg Leheyoutput $bp->b_pblkno 108030b9a7cSGreg Leheyprintf "\nb_saveaddr: " 109030b9a7cSGreg Leheyoutput $bp->b_saveaddr 110030b9a7cSGreg Leheyprintf "\nb_savekva: " 111030b9a7cSGreg Leheyoutput $bp->b_savekva 112030b9a7cSGreg Leheyprintf "\nb_driver1: " 113030b9a7cSGreg Leheyoutput $bp->b_driver1 114030b9a7cSGreg Leheyprintf "\nb_driver2: " 115030b9a7cSGreg Leheyoutput $bp->b_driver2 116030b9a7cSGreg Leheyprintf "\nb_spc: " 117030b9a7cSGreg Leheyoutput $bp->b_spc 118030b9a7cSGreg Leheyprintf "\nb_npages: " 119030b9a7cSGreg Leheyoutput $bp->b_npages 120030b9a7cSGreg Leheyprintf "\n" 121030b9a7cSGreg Leheyend 122030b9a7cSGreg Leheydocument bpl 123410b51e7SGreg LeheyShow detailed information about the buffer header (struct bp) pointed at by the parameter. 124030b9a7cSGreg Leheyend 125030b9a7cSGreg Lehey 126030b9a7cSGreg Lehey# Show contents of buffer header in local variable bp. 127030b9a7cSGreg Leheydefine bp 128030b9a7cSGreg Leheybpp bp 129030b9a7cSGreg Leheyend 130030b9a7cSGreg Leheydocument bp 131410b51e7SGreg LeheyShow information about the buffer header pointed to by the variable bp in the current frame. 132030b9a7cSGreg Leheyend 133030b9a7cSGreg Lehey 134030b9a7cSGreg Lehey# Show data of buffer header in local variable bp as string. 135030b9a7cSGreg Leheydefine bpd 136030b9a7cSGreg Lehey printf "Buffer data:\n%s", (char *) bp->b_io.bio_data 137030b9a7cSGreg Leheyend 138030b9a7cSGreg Leheydocument bpd 139030b9a7cSGreg LeheyShow the contents (char*) of bp->data in the current frame. 140030b9a7cSGreg Leheyend 141030b9a7cSGreg Leheydocument bpl 142410b51e7SGreg LeheyShow detailed information about the buffer header (struct bp) pointed at by the local variable bp. 143030b9a7cSGreg Leheyend 144030b9a7cSGreg Leheydefine bx 145030b9a7cSGreg Leheyprintf "\n b_vnbufs " 146030b9a7cSGreg Leheyoutput/x bp->b_vnbufs 147030b9a7cSGreg Leheyprintf "\n b_freelist " 148030b9a7cSGreg Leheyoutput/x bp->b_freelist 149030b9a7cSGreg Leheyprintf "\n b_act " 150030b9a7cSGreg Leheyoutput/x bp->b_act 151030b9a7cSGreg Leheyprintf "\n b_flags " 152030b9a7cSGreg Leheyoutput/x bp->b_flags 153030b9a7cSGreg Leheyprintf "\n b_qindex " 154030b9a7cSGreg Leheyoutput/x bp->b_qindex 155030b9a7cSGreg Leheyprintf "\n b_usecount " 156030b9a7cSGreg Leheyoutput/x bp->b_usecount 157030b9a7cSGreg Leheyprintf "\n b_error " 158030b9a7cSGreg Leheyoutput/x bp->b_error 159030b9a7cSGreg Leheyprintf "\n b_bufsize " 160030b9a7cSGreg Leheyoutput/x bp->b_bufsize 161030b9a7cSGreg Leheyprintf "\n b_io.bio_bcount " 162030b9a7cSGreg Leheyoutput/x bp->b_io.bio_bcount 163030b9a7cSGreg Leheyprintf "\n b_io.bio_resid " 164030b9a7cSGreg Leheyoutput/x bp->b_io.bio_resid 165030b9a7cSGreg Leheyprintf "\n b_io.bio_dev " 166030b9a7cSGreg Leheyoutput/x bp->b_io.bio_dev 167030b9a7cSGreg Leheyprintf "\n b_io.bio_data " 168030b9a7cSGreg Leheyoutput/x bp->b_io.bio_data 169030b9a7cSGreg Leheyprintf "\n b_kvasize " 170030b9a7cSGreg Leheyoutput/x bp->b_kvasize 171030b9a7cSGreg Leheyprintf "\n b_io.bio_blkno " 172030b9a7cSGreg Leheyoutput/x bp->b_io.bio_blkno 173030b9a7cSGreg Leheyprintf "\n b_iodone_chain " 174030b9a7cSGreg Leheyoutput/x bp->b_iodone_chain 175030b9a7cSGreg Leheyprintf "\n b_vp " 176030b9a7cSGreg Leheyoutput/x bp->b_vp 177030b9a7cSGreg Leheyprintf "\n b_dirtyoff " 178030b9a7cSGreg Leheyoutput/x bp->b_dirtyoff 179030b9a7cSGreg Leheyprintf "\n b_validoff " 180030b9a7cSGreg Leheyoutput/x bp->b_validoff 181030b9a7cSGreg Leheyecho \n 182030b9a7cSGreg Leheyend 183410b51e7SGreg Leheydocument bx 184410b51e7SGreg LeheyPrint a number of fields from the buffer header pointed at in by the pointer bp in the current environment. 185410b51e7SGreg Leheyend 186030b9a7cSGreg Lehey 187030b9a7cSGreg Lehey# Switch back to ddb 188030b9a7cSGreg Leheydefine ddb 189030b9a7cSGreg Leheyset boothowto=0x80000000 190030b9a7cSGreg Leheys 191030b9a7cSGreg Leheyend 192030b9a7cSGreg Leheydocument ddb 193030b9a7cSGreg LeheySwitch back to ddb. 194030b9a7cSGreg Leheyend 195030b9a7cSGreg Lehey 196030b9a7cSGreg Lehey# ps: equivalent of the userland command 197030b9a7cSGreg Leheydefine ps 198030b9a7cSGreg Lehey set $nproc = nprocs 199030b9a7cSGreg Lehey set $aproc = allproc.lh_first 200030b9a7cSGreg Lehey set $proc = allproc.lh_first 201*e7dd6e94SGleb Smirnoff set $tid = 1 202*e7dd6e94SGleb Smirnoff printf "pid/ID ppid/tid uid pgrp flag st comm/name proc/thread\n" 203030b9a7cSGreg Lehey while (--$nproc >= 0) 204030b9a7cSGreg Lehey set $pptr = $proc.p_pptr 205030b9a7cSGreg Lehey if ($pptr == 0) 206030b9a7cSGreg Lehey set $pptr = $proc 207030b9a7cSGreg Lehey end 208030b9a7cSGreg Lehey if ($proc.p_state) 209*e7dd6e94SGleb Smirnoff printf " %5d %6d %4d %5d %8x %2d %-10s %p\n", \ 210*e7dd6e94SGleb Smirnoff $proc.p_pid, $pptr->p_pid, \ 211*e7dd6e94SGleb Smirnoff $proc.p_ucred->cr_ruid, \ 212*e7dd6e94SGleb Smirnoff $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \ 213*e7dd6e94SGleb Smirnoff &$proc.p_comm[0], $aproc 214030b9a7cSGreg Lehey set $thread = $proc->p_threads.tqh_first 215030b9a7cSGreg Lehey while ($thread) 216*e7dd6e94SGleb Smirnoff printf "(%5d) %6d %-10s %p", \ 217*e7dd6e94SGleb Smirnoff $tid, $thread->td_tid, $thread->td_name, $thread 218030b9a7cSGreg Lehey if ($thread.td_wmesg) 219030b9a7cSGreg Lehey printf " %s", $thread.td_wmesg 220030b9a7cSGreg Lehey end 221030b9a7cSGreg Lehey printf "\n" 222030b9a7cSGreg Lehey set $thread = $thread->td_plist.tqe_next 223*e7dd6e94SGleb Smirnoff set $tid = $tid + 1 224030b9a7cSGreg Lehey end 225030b9a7cSGreg Lehey end 226030b9a7cSGreg Lehey set $aproc = $proc.p_list.le_next 227030b9a7cSGreg Lehey if ($aproc == 0 && $nproc > 0) 228030b9a7cSGreg Lehey set $aproc = zombproc 229030b9a7cSGreg Lehey end 230030b9a7cSGreg Lehey set $proc = $aproc 231030b9a7cSGreg Lehey end 232030b9a7cSGreg Leheyend 233030b9a7cSGreg Leheydocument ps 234410b51e7SGreg LeheyShow process status without options. 235030b9a7cSGreg Leheyend 236030b9a7cSGreg Lehey 237030b9a7cSGreg Lehey# Specify a process for other commands to refer to. 238030b9a7cSGreg Lehey# Most are machine-dependent. 239030b9a7cSGreg Leheydefine defproc 240030b9a7cSGreg Lehey set $nproc = nprocs 241030b9a7cSGreg Lehey set $aproc = allproc.lh_first 242030b9a7cSGreg Lehey set $proc = allproc.lh_first 243030b9a7cSGreg Lehey while (--$nproc >= 0) 244030b9a7cSGreg Lehey if ($proc->p_pid == $arg0) 245030b9a7cSGreg Lehey set $pptr = $proc.p_pptr 246030b9a7cSGreg Lehey if ($pptr == 0) 247030b9a7cSGreg Lehey set $pptr = $proc 248030b9a7cSGreg Lehey end 249030b9a7cSGreg Lehey set $myvectorproc = $proc 25036572f48SGreg Lehey if ($proc.p_state) 25136572f48SGreg Lehey set $thread = $proc->p_threads.tqh_first 25236572f48SGreg Lehey while ($thread) 253030b9a7cSGreg Lehey printf "%5d %08x %08x %4d %5d %5d %06x %d %-10s ", \ 254030b9a7cSGreg Lehey $proc.p_pid, $aproc, \ 25536572f48SGreg Lehey $proc.p_uarea, $proc.p_ucred->cr_ruid, $pptr->p_pid, \ 25636572f48SGreg Lehey $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \ 257030b9a7cSGreg Lehey &$proc.p_comm[0] 25836572f48SGreg Lehey if ($thread.td_wchan) 25936572f48SGreg Lehey if ($thread.td_wmesg) 26036572f48SGreg Lehey printf "%s ", $thread.td_wmesg 261030b9a7cSGreg Lehey end 26236572f48SGreg Lehey printf "%x", $thread.td_wchan 263030b9a7cSGreg Lehey end 264030b9a7cSGreg Lehey printf "\n" 26536572f48SGreg Lehey set $thread = $thread->td_plist.tqe_next 26636572f48SGreg Lehey end 267030b9a7cSGreg Lehey end 268030b9a7cSGreg Lehey btpp 269030b9a7cSGreg Lehey set $nproc = 0 270030b9a7cSGreg Lehey else 271030b9a7cSGreg Lehey set $proc = $proc.p_list.le_next 272030b9a7cSGreg Lehey end 273030b9a7cSGreg Lehey end 274030b9a7cSGreg Leheyend 275030b9a7cSGreg Leheydocument defproc 276030b9a7cSGreg LeheySpecify a process for btpp and fr commands. 277030b9a7cSGreg Leheyend 278030b9a7cSGreg Lehey 279030b9a7cSGreg Leheydefine vdev 280030b9a7cSGreg Leheyif (vp->v_type == VBLK) 281030b9a7cSGreg Lehey p *vp->v_un.vu_spec.vu_specinfo 282030b9a7cSGreg Lehey printf "numoutput: %d\n", vp->v_numoutput 283030b9a7cSGreg Leheyelse 284030b9a7cSGreg Lehey echo "Not a block device" 285030b9a7cSGreg Leheyend 286030b9a7cSGreg Leheyend 287030b9a7cSGreg Leheydocument vdev 288030b9a7cSGreg LeheyShow some information of the vnode pointed to by the local variable vp. 289030b9a7cSGreg Leheyend 290030b9a7cSGreg Lehey 291030b9a7cSGreg Lehey# Kludge. When changing macros, it's convenient to copy and paste 292030b9a7cSGreg Lehey# definitions from the editor into the debugger window. 293030b9a7cSGreg Lehey# Unfortunately, gdb insists on asking for confirmation after the 294030b9a7cSGreg Lehey# "define" line. y enables you to insert the confirmation in the 295030b9a7cSGreg Lehey# definition without affecting the way the macro runs (much). 296030b9a7cSGreg Leheydefine y 297410b51e7SGreg Leheyecho Check your .gdbinit: it contains a y command\n 298410b51e7SGreg Leheyend 299410b51e7SGreg Lehey 300410b51e7SGreg Leheydocument y 301410b51e7SGreg LeheyKludge for writing macros This is a no-op except for printing a message See gdb(4) for more details. 302030b9a7cSGreg Leheyend 303030b9a7cSGreg Lehey 304a783ff94SGreg Lehey# dmesg: print msgbuf. Can take forever. 305a783ff94SGreg Leheydefine dmesg 306030b9a7cSGreg Leheyprintf "%s", msgbufp->msg_ptr 307030b9a7cSGreg Leheyend 308a783ff94SGreg Leheydocument dmesg 309a783ff94SGreg LeheyPrint 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 310030b9a7cSGreg Leheyend 311030b9a7cSGreg Lehey 312030b9a7cSGreg Lehey# checkmem: check unallocated memory for modifications 313030b9a7cSGreg Lehey# this assumes that DIAGNOSTIC is set, which causes 314030b9a7cSGreg Lehey# free memory to be set to 0xdeadc0de 315030b9a7cSGreg Lehey# 316030b9a7cSGreg Lehey# Use: checkmem offset length 317030b9a7cSGreg Leheydefine checkmem 318030b9a7cSGreg Leheyset $offset = $arg0 319030b9a7cSGreg Lehey# XXX sizeof int. Needs changing for 64 bit machines. 320030b9a7cSGreg Lehey# subtract 1 because the last word is always different. 321030b9a7cSGreg Leheyset $length = $arg1 / 4 - 1 322030b9a7cSGreg Leheyset $word = 0 323030b9a7cSGreg Leheywhile ($word < $length) 324030b9a7cSGreg Lehey if ((int *) $offset) [$word] != 0xdeadc0de 325030b9a7cSGreg Lehey printf "invalid word 0x%x at 0x%x\n", ((int *) $offset) [$word], &((int *) $offset) [$word] 326030b9a7cSGreg Lehey end 327030b9a7cSGreg Lehey set $word = $word + 1 328030b9a7cSGreg Leheyend 329030b9a7cSGreg Leheyend 330410b51e7SGreg Lehey 331410b51e7SGreg Leheydocument checkmem 332410b51e7SGreg LeheyCheck unallocated memory for modifications This assumes that DIAGNOSTIC is set which causes free memory to be set to 0xdeadc0de. 333410b51e7SGreg Leheyend 3341cff4d0cSGreg Lehey 3351cff4d0cSGreg Leheydefine kernel 3361cff4d0cSGreg Lehey exec-file kernel.$arg0 3371cff4d0cSGreg Lehey symbol-file symbols.$arg0 3381cff4d0cSGreg Lehey core-file vmcore.$arg0 3391cff4d0cSGreg Leheyend 3401cff4d0cSGreg Lehey 3411cff4d0cSGreg Leheydefine kldstat 3421cff4d0cSGreg Lehey set $kld = linker_files.tqh_first 3431cff4d0cSGreg Lehey printf "Id Refs Address Size Name\n" 3441cff4d0cSGreg Lehey while ($kld != 0) 3451cff4d0cSGreg Lehey printf "%2d %4d 0x%08x %-8x %s\n", \ 3461cff4d0cSGreg Lehey $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename 3471cff4d0cSGreg Lehey set $kld = $kld->link.tqe_next 3481cff4d0cSGreg Lehey end 3491cff4d0cSGreg Leheyend 3501cff4d0cSGreg Lehey 3511cff4d0cSGreg Leheydocument kldstat 3521cff4d0cSGreg Lehey Lists the modules that were loaded when the kernel crashed. 3531cff4d0cSGreg Leheyend 3541cff4d0cSGreg Lehey 3551cff4d0cSGreg Leheydefine kldstat-v 3561cff4d0cSGreg Lehey set $kld = linker_files.tqh_first 3571cff4d0cSGreg Lehey printf "Id Refs Address Size Name\n" 3581cff4d0cSGreg Lehey while ($kld != 0) 3591cff4d0cSGreg Lehey printf "%2d %4d 0x%08x %-8x %s\n", \ 3601cff4d0cSGreg Lehey $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename 3611cff4d0cSGreg Lehey printf " Contains modules:\n" 3621cff4d0cSGreg Lehey printf " Id Name\n" 3631cff4d0cSGreg Lehey set $module = $kld->modules.tqh_first 3641cff4d0cSGreg Lehey while ($module != 0) 3651cff4d0cSGreg Lehey printf " %2d %s\n", $module->id, $module->name 3661cff4d0cSGreg Lehey set $module = $module->link.tqe_next 3671cff4d0cSGreg Lehey end 3681cff4d0cSGreg Lehey set $kld = $kld->link.tqe_next 3691cff4d0cSGreg Lehey end 3701cff4d0cSGreg Leheyend 371