1# 2# Command file for the GNU Debugger, for kernel debugging. 3# 4# This file can either be put in your home directory as ~/.gdbinit, 5# or selected at run time as: 6# 7# 'gdb -k -q -x /usr/share/misc/gdbinit ...' 8# 9set print union 10set history expansion on 11 12define pcomm 13 printf "%10s\n",$arg0->td_comm 14end 15 16define lsvfs 17 set $vfc = (struct vfsconf *)vfsconf_list.stqh_first 18 printf "\nFilesystem Refs Flags\n" 19 while ($vfc != 0) 20 printf "%-10s %6d 0x%08x\n", $vfc->vfc_name, \ 21 $vfc->vfc_refcount, $vfc->vfc_flags 22 set $vfc = $vfc->vfc_next.stqe_next 23 end 24end 25 26define lsmount 27 set $mnt = (mountlist->tqh_first) 28 while ($mnt != 0) 29 print *$mnt 30 set $mnt = $mnt->mnt_list->tqe_next 31 end 32end 33 34define lsvfsops 35 set $vfc = (struct vfsconf *)vfsconf_list.stqh_first 36 while ($vfc != 0) 37 printf "Filesystem: %s, Refs: %d, Flags: 0x%08x\n", \ 38 $vfc->vfc_name, $vfc->vfc_refcount, $vfc->vfc_flags 39 printf "VFS ops: \n" 40 set print pretty 41 print *$vfc->vfc_vfsops 42 set print pretty off 43 set $vfc = $vfc->vfc_next.stqe_next 44 end 45end 46 47 48define kldstat 49 set $kld = linker_files.tqh_first 50 printf "\nId Refs Address Size Name\n" 51 while ($kld != 0) 52 printf "%2d %4d 0x%08x %-8x %s\n", \ 53 $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename 54 set $kld = $kld->link.tqe_next 55 end 56end 57 58define psx 59 set $cpu = 0 60 printf "\ncpu pid thread flags comm wchan wmesg\n" 61 while ($cpu < ncpus) 62 set $gd = &((struct privatespace *)&CPU_prvspace)[$cpu].mdglobaldata 63 set $td = $gd->mi.gd_tdallq.tqh_first 64 while ( $td != 0 ) 65 if ( $td->td_proc != 0 ) 66 set $pid = $td->td_proc->p_pid 67 else 68 set $pid = -1 69 end 70 if ( $td->td_wmesg != 0 ) 71 printf "%3d %5d %08x %08x %-18s %08x %s\n", \ 72 $cpu, $pid, $td, $td->td_flags, $td->td_comm, $td->td_wchan, \ 73 $td->td_wmesg 74 else 75 printf "%3d %5d %08x %08x %-18s %08x\n", \ 76 $cpu, $pid, $td, $td->td_flags, $td->td_comm, $td->td_wchan 77 end 78 set $td = $td->td_allq.tqe_next 79 end 80 set $cpu = $cpu + 1 81 end 82end 83 84 85define running_threads 86 set $icpu = 0 87 printf "\ncpu curthread wchan\n" 88 while ($icpu < ncpus) 89 set $ipvspace = (struct privatespace *)&CPU_prvspace 90 set $gd = $ipvspace[$icpu].mdglobaldata.mi 91 set $td = $gd.gd_curthread 92 printf "%d %10s %08x\n", \ 93 $gd.gd_cpuid, $td->td_comm, $td->td_wchan 94 set $icpu = $icpu + 1 95 end 96end 97 98define psax 99 set $pos = 0 100 while $pos < allproc_hsize 101 set $proc = allprocs[$pos++]->lh_first 102 while $proc != 0 103 printf "%p%6d%10s\n",$proc,$proc->p_pid,$proc->p_comm 104 set $proc = $proc->p_list.le_next 105 end 106 end 107end 108 109define _infotok 110 set $token = ($arg0) 111 set $tokref = $token->t_ref 112 if ($tokref != 0) 113 printf "%-15s %10d 0x%08x\n", $token->t_desc, \ 114 $token->t_collisions, $tokref->tr_owner 115 else 116 printf "%-15s %10d not held\n", $token->t_desc, \ 117 $token->t_collisions 118 end 119end 120 121define infotok 122 printf "\nToken collisions owner\n" 123 _infotok ($arg0) 124end 125 126define lstok 127 set $tok = 0 128 set $obj = 0 129 printf "\nToken collisions owner\n" 130 _infotok &pmap_token 131 _infotok &dev_token 132 _infotok &vm_token 133 _infotok &vmspace_token 134 _infotok &kvm_token 135 while $tok < allproc_hsize 136 if (proc_tokens[$tok].t_collisions > 0) 137 _infotok &proc_tokens[$tok] 138 end 139 set $tok = $tok + 1 140 end 141 _infotok &tty_token 142 _infotok &vnode_token 143 while $obj < 64 144 if (vmobj_tokens[$obj].t_collisions > 0) 145 _infotok &vmobj_tokens[$obj] 146 end 147 set $obj = $obj + 1 148 end 149end 150 151define lstdtok 152 set $mytd=($arg0) 153 printf "\nTokens for td %p (%s)\n", $mytd, $mytd->td_comm 154 printf "\nToken collisions owner\n" 155 set $pos = 0 156 while (td->td_toks_array[$pos]->tr_tok) != 0 157 _infotok &td->td_toks_array[$pos++]->tr_tok 158 end 159end 160 161define dmesg 162 set $bufp = msgbufp->msg_ptr 163 set $size = msgbufp->msg_size 164 set $rseq = msgbufp->msg_bufr % $size 165 set $wseq = msgbufp->msg_bufx % $size 166 if ( $bufp != 0 && $size != 0 && $rseq != $wseq ) 167 while ( $rseq < $wseq ) 168 set $c = $bufp + $rseq 169 printf "%c", *$c 170 set $rseq = $rseq + 1 171 if ( $rseq == msgbufp->msg_size ) 172 set $rseq = 0 173 end 174 end 175 if ( *$c == '\n' ) 176 printf "\n" 177 end 178 printf "\n" 179 end 180end 181 182# Documentation, usable within GDB using the 'help' command. 183document lsvfs 184Output list of loaded file systems, refcount, similar to the 185lsvfs(1) utility. 186end 187 188document lsmount 189Iterate the current list of mount structures loaded from the 190memory core, there should be one per loaded VFS. 191end 192 193document lsvfsops 194Display the VFS operations vector for each file system found in 195the memory core, preceded by a summarised header. 196end 197 198document kldstat 199Output list of loaded kernel modules in kldstat(1) style. 200end 201 202document pcomm 203Print command name of the given thread pointer (first argument). 204end 205 206document psx 207Output a list of processes with wait-channel (wchan) information. 208end 209 210document running_threads 211List the threads which are currently running and their CPU number. 212end 213 214document psax 215Output a list of processes. 216end 217 218document lstok 219Display all known global tokens and some information about them. 220end 221 222document lstdtok 223Display all tokens related to the specified thread. 224end 225 226document infotok 227Takes one argument, a struct lwkt_token * (pointer) and prints some 228information about that token. 229end 230 231document dmesg 232Shows the unread portion of the kernel message buffer. 233end 234