1030b9a7cSGreg Lehey# $FreeBSD$ 2030b9a7cSGreg Lehey# General kernel macros 3030b9a7cSGreg Lehey 4030b9a7cSGreg Lehey# Print the command name of the current process 5030b9a7cSGreg Leheydefine pname 6030b9a7cSGreg Leheyp (char *)curproc->p_comm 7030b9a7cSGreg Leheyend 8030b9a7cSGreg Leheydocument pname 9030b9a7cSGreg LeheyPrint the command name of the current process 10030b9a7cSGreg Leheyend 11030b9a7cSGreg Lehey 12030b9a7cSGreg Lehey# Show contents of bp supplied as first parameter: 13030b9a7cSGreg Lehey# 14030b9a7cSGreg Lehey# (gdb) bpp bp 15030b9a7cSGreg Leheydefine bpp 16030b9a7cSGreg Leheyset $bp = (struct buf *) $arg0 17030b9a7cSGreg Lehey if $bp->b_io.bio_dev 18030b9a7cSGreg Lehey printf " Buffer at 0x%x: dev 0x%x data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 19030b9a7cSGreg Lehey $bp, \ 20030b9a7cSGreg Lehey $bp->b_io.bio_dev->si_udev, \ 21030b9a7cSGreg Lehey $bp->b_io.bio_data, \ 22030b9a7cSGreg Lehey $bp->b_io.bio_bcount, \ 23030b9a7cSGreg Lehey $bp->b_io.bio_blkno, \ 24030b9a7cSGreg Lehey $bp->b_io.bio_resid 25030b9a7cSGreg Lehey else 26030b9a7cSGreg Lehey printf " Buffer at 0x%x: dev (none) data 0x%x bcount 0x%x blkno 0x%x resid 0x%x\n", \ 27030b9a7cSGreg Lehey $bp, \ 28030b9a7cSGreg Lehey $bp->b_io.bio_data, \ 29030b9a7cSGreg Lehey $bp->b_io.bio_bcount, \ 30030b9a7cSGreg Lehey $bp->b_io.bio_blkno, \ 31030b9a7cSGreg Lehey $bp->b_io.bio_resid 32030b9a7cSGreg Lehey end 33030b9a7cSGreg Lehey printf " flags 0x%x: ", $bp->b_flags 34030b9a7cSGreg Lehey if $bp->b_flags & 0x10 35030b9a7cSGreg Lehey printf "busy " 36030b9a7cSGreg Lehey end 37030b9a7cSGreg Lehey if $bp->b_flags & 0x40 38030b9a7cSGreg Lehey printf "call " 39030b9a7cSGreg Lehey end 40030b9a7cSGreg Lehey if $bp->b_flags & 0x200 41030b9a7cSGreg Lehey printf "done " 42030b9a7cSGreg Lehey end 43030b9a7cSGreg Lehey if $bp->b_flags & 0x800 44030b9a7cSGreg Lehey printf "error " 45030b9a7cSGreg Lehey end 46030b9a7cSGreg Lehey if $bp->b_flags & 0x40000 47030b9a7cSGreg Lehey printf "phys " 48030b9a7cSGreg Lehey end 49030b9a7cSGreg Lehey if $bp->b_flags & 0x100000 50030b9a7cSGreg Lehey printf "read " 51030b9a7cSGreg Lehey end 52030b9a7cSGreg Lehey printf "\n" 53030b9a7cSGreg Leheyend 54030b9a7cSGreg Leheydocument bpp 55030b9a7cSGreg LeheyShow summary information about the buffer header (struct bp) pointed 56030b9a7cSGreg Leheyat by the parameter. 57030b9a7cSGreg Leheyend 58030b9a7cSGreg Lehey 59030b9a7cSGreg Lehey# Show more detailed contents of bp supplied as first parameter: 60030b9a7cSGreg Lehey# 61030b9a7cSGreg Lehey# (gdb) bpl bp 62030b9a7cSGreg Leheydefine bpl 63030b9a7cSGreg Leheyset $bp = (struct buf *) $arg0 64030b9a7cSGreg Leheyprintf "b_proc: " 65030b9a7cSGreg Leheyoutput $bp->b_proc 66030b9a7cSGreg Leheyprintf "\nb_flags: " 67030b9a7cSGreg Leheyoutput $bp->b_flags 68030b9a7cSGreg Leheyprintf "\nb_qindex: " 69030b9a7cSGreg Leheyoutput $bp->b_qindex 70030b9a7cSGreg Leheyprintf "\nb_usecount: " 71030b9a7cSGreg Leheyoutput $bp->b_usecount 72030b9a7cSGreg Leheyprintf "\nb_error: " 73030b9a7cSGreg Leheyoutput $bp->b_error 74030b9a7cSGreg Leheyprintf "\nb_bufsize: " 75030b9a7cSGreg Leheyoutput $bp->b_bufsize 76030b9a7cSGreg Leheyprintf "\nb_io.bio_bcount: " 77030b9a7cSGreg Leheyoutput $bp->b_io.bio_bcount 78030b9a7cSGreg Leheyprintf "\nb_io.bio_resid: " 79030b9a7cSGreg Leheyoutput $bp->b_io.bio_resid 80030b9a7cSGreg Leheyprintf "\nb_io.bio_dev: " 81030b9a7cSGreg Leheyoutput $bp->b_io.bio_dev 82030b9a7cSGreg Leheyprintf "\nb_io.bio_data: " 83030b9a7cSGreg Leheyoutput $bp->b_io.bio_data 84030b9a7cSGreg Leheyprintf "\nb_kvasize: " 85030b9a7cSGreg Leheyoutput $bp->b_kvasize 86030b9a7cSGreg Leheyprintf "\nb_lblkno: " 87030b9a7cSGreg Leheyoutput $bp->b_lblkno 88030b9a7cSGreg Leheyprintf "\nb_io.bio_blkno: " 89030b9a7cSGreg Leheyoutput $bp->b_io.bio_blkno 90030b9a7cSGreg Leheyprintf "\nb_iodone: " 91030b9a7cSGreg Leheyoutput $bp->b_iodone 92030b9a7cSGreg Leheyprintf "\nb_vp: " 93030b9a7cSGreg Leheyoutput $bp->b_vp 94030b9a7cSGreg Leheyprintf "\nb_dirtyoff: " 95030b9a7cSGreg Leheyoutput $bp->b_dirtyoff 96030b9a7cSGreg Leheyprintf "\nb_dirtyend: " 97030b9a7cSGreg Leheyoutput $bp->b_dirtyend 98030b9a7cSGreg Leheyprintf "\nb_generation: " 99030b9a7cSGreg Leheyoutput $bp->b_generation 100030b9a7cSGreg Leheyprintf "\nb_rcred: " 101030b9a7cSGreg Leheyoutput $bp->b_rcred 102030b9a7cSGreg Leheyprintf "\nb_wcred: " 103030b9a7cSGreg Leheyoutput $bp->b_wcred 104030b9a7cSGreg Leheyprintf "\nb_validoff: " 105030b9a7cSGreg Leheyoutput $bp->b_validoff 106030b9a7cSGreg Leheyprintf "\nb_validend: " 107030b9a7cSGreg Leheyoutput $bp->b_validend 108030b9a7cSGreg Leheyprintf "\nb_pblkno: " 109030b9a7cSGreg Leheyoutput $bp->b_pblkno 110030b9a7cSGreg Leheyprintf "\nb_saveaddr: " 111030b9a7cSGreg Leheyoutput $bp->b_saveaddr 112030b9a7cSGreg Leheyprintf "\nb_savekva: " 113030b9a7cSGreg Leheyoutput $bp->b_savekva 114030b9a7cSGreg Leheyprintf "\nb_driver1: " 115030b9a7cSGreg Leheyoutput $bp->b_driver1 116030b9a7cSGreg Leheyprintf "\nb_driver2: " 117030b9a7cSGreg Leheyoutput $bp->b_driver2 118030b9a7cSGreg Leheyprintf "\nb_spc: " 119030b9a7cSGreg Leheyoutput $bp->b_spc 120030b9a7cSGreg Leheyprintf "\nb_npages: " 121030b9a7cSGreg Leheyoutput $bp->b_npages 122030b9a7cSGreg Leheyprintf "\n" 123030b9a7cSGreg Leheyend 124030b9a7cSGreg Leheydocument bpl 125030b9a7cSGreg LeheyShow detailed information about the buffer header (struct bp) pointed 126030b9a7cSGreg Leheyat by the parameter. 127030b9a7cSGreg Leheyend 128030b9a7cSGreg Lehey 129030b9a7cSGreg Lehey# Show contents of buffer header in local variable bp. 130030b9a7cSGreg Leheydefine bp 131030b9a7cSGreg Leheybpp bp 132030b9a7cSGreg Leheyend 133030b9a7cSGreg Leheydocument bp 134030b9a7cSGreg LeheyShow information about the buffer header pointed to by the 135030b9a7cSGreg Leheyvariable bp in the current frame. 136030b9a7cSGreg Leheyend 137030b9a7cSGreg Lehey 138030b9a7cSGreg Lehey# Show data of buffer header in local variable bp as string. 139030b9a7cSGreg Leheydefine bpd 140030b9a7cSGreg Lehey printf "Buffer data:\n%s", (char *) bp->b_io.bio_data 141030b9a7cSGreg Leheyend 142030b9a7cSGreg Leheydocument bpd 143030b9a7cSGreg LeheyShow the contents (char*) of bp->data in the current frame. 144030b9a7cSGreg Leheyend 145030b9a7cSGreg Leheydocument bpl 146030b9a7cSGreg LeheyShow detailled information about the buffer header (struct bp) pointed 147030b9a7cSGreg Leheyat by the local variable bp. 148030b9a7cSGreg Leheyend 149030b9a7cSGreg Leheydefine bx 150030b9a7cSGreg Leheyprintf "\n b_vnbufs " 151030b9a7cSGreg Leheyoutput/x bp->b_vnbufs 152030b9a7cSGreg Leheyprintf "\n b_freelist " 153030b9a7cSGreg Leheyoutput/x bp->b_freelist 154030b9a7cSGreg Leheyprintf "\n b_act " 155030b9a7cSGreg Leheyoutput/x bp->b_act 156030b9a7cSGreg Leheyprintf "\n b_flags " 157030b9a7cSGreg Leheyoutput/x bp->b_flags 158030b9a7cSGreg Leheyprintf "\n b_qindex " 159030b9a7cSGreg Leheyoutput/x bp->b_qindex 160030b9a7cSGreg Leheyprintf "\n b_usecount " 161030b9a7cSGreg Leheyoutput/x bp->b_usecount 162030b9a7cSGreg Leheyprintf "\n b_error " 163030b9a7cSGreg Leheyoutput/x bp->b_error 164030b9a7cSGreg Leheyprintf "\n b_bufsize " 165030b9a7cSGreg Leheyoutput/x bp->b_bufsize 166030b9a7cSGreg Leheyprintf "\n b_io.bio_bcount " 167030b9a7cSGreg Leheyoutput/x bp->b_io.bio_bcount 168030b9a7cSGreg Leheyprintf "\n b_io.bio_resid " 169030b9a7cSGreg Leheyoutput/x bp->b_io.bio_resid 170030b9a7cSGreg Leheyprintf "\n b_io.bio_dev " 171030b9a7cSGreg Leheyoutput/x bp->b_io.bio_dev 172030b9a7cSGreg Leheyprintf "\n b_io.bio_data " 173030b9a7cSGreg Leheyoutput/x bp->b_io.bio_data 174030b9a7cSGreg Leheyprintf "\n b_kvasize " 175030b9a7cSGreg Leheyoutput/x bp->b_kvasize 176030b9a7cSGreg Leheyprintf "\n b_io.bio_blkno " 177030b9a7cSGreg Leheyoutput/x bp->b_io.bio_blkno 178030b9a7cSGreg Leheyprintf "\n b_iodone_chain " 179030b9a7cSGreg Leheyoutput/x bp->b_iodone_chain 180030b9a7cSGreg Leheyprintf "\n b_vp " 181030b9a7cSGreg Leheyoutput/x bp->b_vp 182030b9a7cSGreg Leheyprintf "\n b_dirtyoff " 183030b9a7cSGreg Leheyoutput/x bp->b_dirtyoff 184030b9a7cSGreg Leheyprintf "\n b_validoff " 185030b9a7cSGreg Leheyoutput/x bp->b_validoff 186030b9a7cSGreg Leheyecho \n 187030b9a7cSGreg Leheyend 188030b9a7cSGreg Lehey 189030b9a7cSGreg Lehey# Switch back to ddb 190030b9a7cSGreg Leheydefine ddb 191030b9a7cSGreg Leheyset boothowto=0x80000000 192030b9a7cSGreg Leheys 193030b9a7cSGreg Leheyend 194030b9a7cSGreg Leheydocument ddb 195030b9a7cSGreg LeheySwitch back to ddb. 196030b9a7cSGreg Leheyend 197030b9a7cSGreg Lehey 198030b9a7cSGreg Lehey# ps: equivalent of the userland command 199030b9a7cSGreg Leheydefine ps 200030b9a7cSGreg Lehey set $nproc = nprocs 201030b9a7cSGreg Lehey set $aproc = allproc.lh_first 202030b9a7cSGreg Lehey set $proc = allproc.lh_first 203030b9a7cSGreg Lehey printf " pid proc addr uid ppid pgrp flag stat comm wchan\n" 204030b9a7cSGreg Lehey while (--$nproc >= 0) 205030b9a7cSGreg Lehey set $pptr = $proc.p_pptr 206030b9a7cSGreg Lehey if ($pptr == 0) 207030b9a7cSGreg Lehey set $pptr = $proc 208030b9a7cSGreg Lehey end 209030b9a7cSGreg Lehey if ($proc.p_state) 210030b9a7cSGreg Lehey set $thread = $proc->p_threads.tqh_first 211030b9a7cSGreg Lehey while ($thread) 212030b9a7cSGreg Lehey printf "%5d %08x %08x %4d %5d %5d %06x %d %-10s ", \ 213030b9a7cSGreg Lehey $proc.p_pid, $aproc, \ 214030b9a7cSGreg Lehey $proc.p_uarea, $proc.p_ucred->cr_ruid, $pptr->p_pid, \ 215030b9a7cSGreg Lehey $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_state, \ 216030b9a7cSGreg Lehey &$proc.p_comm[0] 217030b9a7cSGreg Lehey if ($thread.td_wchan) 218030b9a7cSGreg Lehey if ($thread.td_wmesg) 219030b9a7cSGreg Lehey printf "%s ", $thread.td_wmesg 220030b9a7cSGreg Lehey end 221030b9a7cSGreg Lehey printf "%x", $thread.td_wchan 222030b9a7cSGreg Lehey end 223030b9a7cSGreg Lehey printf "\n" 224030b9a7cSGreg Lehey set $thread = $thread->td_plist.tqe_next 225030b9a7cSGreg Lehey end 226030b9a7cSGreg Lehey end 227030b9a7cSGreg Lehey set $aproc = $proc.p_list.le_next 228030b9a7cSGreg Lehey if ($aproc == 0 && $nproc > 0) 229030b9a7cSGreg Lehey set $aproc = zombproc 230030b9a7cSGreg Lehey end 231030b9a7cSGreg Lehey set $proc = $aproc 232030b9a7cSGreg Lehey end 233030b9a7cSGreg Leheyend 234030b9a7cSGreg Leheydocument ps 235030b9a7cSGreg LeheyShow process status. No options. 236030b9a7cSGreg Leheyend 237030b9a7cSGreg Lehey 238030b9a7cSGreg Lehey# Specify a process for other commands to refer to. 239030b9a7cSGreg Lehey# Most are machine-dependent. 240030b9a7cSGreg Leheydefine defproc 241030b9a7cSGreg Lehey set $nproc = nprocs 242030b9a7cSGreg Lehey set $aproc = allproc.lh_first 243030b9a7cSGreg Lehey set $proc = allproc.lh_first 244030b9a7cSGreg Lehey while (--$nproc >= 0) 245030b9a7cSGreg Lehey if ($proc->p_pid == $arg0) 246030b9a7cSGreg Lehey set $pptr = $proc.p_pptr 247030b9a7cSGreg Lehey if ($pptr == 0) 248030b9a7cSGreg Lehey set $pptr = $proc 249030b9a7cSGreg Lehey end 250030b9a7cSGreg Lehey set $myvectorproc = $proc 251030b9a7cSGreg Lehey if ($proc.p_stat) 252030b9a7cSGreg Lehey printf "%5d %08x %08x %4d %5d %5d %06x %d %-10s ", \ 253030b9a7cSGreg Lehey $proc.p_pid, $aproc, \ 254030b9a7cSGreg Lehey $proc.p_uarea, $proc.p_cred->p_ruid, $pptr->p_pid, \ 255030b9a7cSGreg Lehey $proc.p_pgrp->pg_id, $proc.p_flag, $proc.p_stat, \ 256030b9a7cSGreg Lehey &$proc.p_comm[0] 257030b9a7cSGreg Lehey if ($proc.p_wchan) 258030b9a7cSGreg Lehey if ($proc.p_wmesg) 259030b9a7cSGreg Lehey printf "%s ", $proc.p_wmesg 260030b9a7cSGreg Lehey end 261030b9a7cSGreg Lehey printf "%x", $proc.p_wchan 262030b9a7cSGreg Lehey end 263030b9a7cSGreg Lehey printf "\n" 264030b9a7cSGreg Lehey end 265030b9a7cSGreg Lehey btpp 266030b9a7cSGreg Lehey set $nproc = 0 267030b9a7cSGreg Lehey else 268030b9a7cSGreg Lehey set $proc = $proc.p_list.le_next 269030b9a7cSGreg Lehey end 270030b9a7cSGreg Lehey end 271030b9a7cSGreg Leheyend 272030b9a7cSGreg Leheydocument defproc 273030b9a7cSGreg LeheySpecify a process for btpp and fr commands. 274030b9a7cSGreg Leheyend 275030b9a7cSGreg Lehey 276030b9a7cSGreg Leheydefine vdev 277030b9a7cSGreg Leheyif (vp->v_type == VBLK) 278030b9a7cSGreg Lehey p *vp->v_un.vu_spec.vu_specinfo 279030b9a7cSGreg Lehey printf "numoutput: %d\n", vp->v_numoutput 280030b9a7cSGreg Leheyelse 281030b9a7cSGreg Lehey echo "Not a block device" 282030b9a7cSGreg Leheyend 283030b9a7cSGreg Leheyend 284030b9a7cSGreg Leheydocument vdev 285030b9a7cSGreg LeheyShow some information of the vnode pointed to by the local variable vp. 286030b9a7cSGreg Leheyend 287030b9a7cSGreg Lehey 288030b9a7cSGreg Lehey# Kludge. When changing macros, it's convenient to copy and paste 289030b9a7cSGreg Lehey# definitions from the editor into the debugger window. 290030b9a7cSGreg Lehey# Unfortunately, gdb insists on asking for confirmation after the 291030b9a7cSGreg Lehey# "define" line. y enables you to insert the confirmation in the 292030b9a7cSGreg Lehey# definition without affecting the way the macro runs (much). 293030b9a7cSGreg Leheydefine y 294030b9a7cSGreg Leheyecho Check your .gdbinit, it contains a y command\n 295030b9a7cSGreg Leheyend 296030b9a7cSGreg Lehey 297030b9a7cSGreg Lehey# kldstat(1) lookalike 298030b9a7cSGreg Leheydefine kldstat 299030b9a7cSGreg Lehey set $file = linker_files.tqh_first 300030b9a7cSGreg Lehey printf "Id Refs Address Size Name\n" 301030b9a7cSGreg Lehey while ($file != 0) 302030b9a7cSGreg Lehey printf "%2d %4d 0x%8x %8x %s\n", \ 303030b9a7cSGreg Lehey $file->id, \ 304030b9a7cSGreg Lehey $file->refs, \ 305030b9a7cSGreg Lehey $file->address, \ 306030b9a7cSGreg Lehey $file->size, \ 307030b9a7cSGreg Lehey $file->filename 308030b9a7cSGreg Lehey set $file = $file->link.tqe_next 309030b9a7cSGreg Lehey end 310030b9a7cSGreg Leheyend 311030b9a7cSGreg Leheydocument kldstat 312030b9a7cSGreg LeheyEquivalent of the kldstat(9) command, without options. 313030b9a7cSGreg Leheyend 314030b9a7cSGreg Lehey 315030b9a7cSGreg Lehey# msgbuf: print msgbuf. Can take forever. 316030b9a7cSGreg Leheydefine msgbuf 317030b9a7cSGreg Leheyprintf "%s", msgbufp->msg_ptr 318030b9a7cSGreg Leheyend 319030b9a7cSGreg Leheydocument msgbuf 320030b9a7cSGreg 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. 321030b9a7cSGreg Leheyend 322030b9a7cSGreg Lehey 323030b9a7cSGreg Lehey# checkmem: check unallocated memory for modifications 324030b9a7cSGreg Lehey# this assumes that DIAGNOSTIC is set, which causes 325030b9a7cSGreg Lehey# free memory to be set to 0xdeadc0de 326030b9a7cSGreg Lehey# 327030b9a7cSGreg Lehey# Use: checkmem offset length 328030b9a7cSGreg Leheydefine checkmem 329030b9a7cSGreg Leheyset $offset = $arg0 330030b9a7cSGreg Lehey# XXX sizeof int. Needs changing for 64 bit machines. 331030b9a7cSGreg Lehey# subtract 1 because the last word is always different. 332030b9a7cSGreg Leheyset $length = $arg1 / 4 - 1 333030b9a7cSGreg Leheyset $word = 0 334030b9a7cSGreg Leheywhile ($word < $length) 335030b9a7cSGreg Lehey if ((int *) $offset) [$word] != 0xdeadc0de 336030b9a7cSGreg Lehey printf "invalid word 0x%x at 0x%x\n", ((int *) $offset) [$word], &((int *) $offset) [$word] 337030b9a7cSGreg Lehey end 338030b9a7cSGreg Lehey set $word = $word + 1 339030b9a7cSGreg Leheyend 340030b9a7cSGreg Leheyend 341