cd4ee2df0ccd0db6aca1892fb5d4c2706d30528e
[dragonfly.git] / share / misc / gdbinit
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 #
9 set print union
10 set history expansion on
11
12 define pcomm
13         printf "%10s\n",$arg0->td_comm
14 end
15
16 define 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
24 end
25
26 define lsmount
27         set $mnt = (mountlist->tqh_first)
28         while ($mnt != 0)
29                 print *$mnt
30                 set $mnt = $mnt->mnt_list->tqe_next
31         end
32 end
33
34 define 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
45 end
46
47
48 define 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
56 end
57
58 define 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
82 end
83
84
85 define 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
96 end
97
98 define psax
99     set $proc = allproc->lh_first
100     while $proc != 0
101         printf "%p%6d%10s\n",$proc,$proc->p_pid,$proc->p_comm
102         set $proc = $proc->p_list.le_next
103     end
104 end
105
106 define _infotok
107         set $token = ($arg0)
108         set $tokref = $token->t_ref
109         if ($tokref != 0)
110                 printf "%-15s %10d 0x%08x\n", $token->t_desc, \
111                         $token->t_collisions, $tokref->tr_owner
112         else
113                 printf "%-15s %10d not held\n", $token->t_desc, \
114                         $token->t_collisions
115         end
116 end
117
118 define infotok
119         printf "\nToken           collisions owner\n"
120         _infotok ($arg0)
121 end
122
123 define lstok
124         printf "\nToken           collisions owner\n"
125         _infotok &pmap_token
126         _infotok &dev_token
127         _infotok &vm_token
128         _infotok &vmspace_token
129         _infotok &kvm_token
130         _infotok &proc_token
131         _infotok &tty_token
132         _infotok &vnode_token
133         _infotok &vmobj_token
134 end
135
136 define dmesg
137         set $bufp = msgbufp->msg_ptr
138         set $size = msgbufp->msg_size
139         set $rseq = msgbufp->msg_bufr
140         set $wseq = msgbufp->msg_bufx
141         set $rseq = $rseq % $size
142         set $wseq = $wseq % $size
143         if ( $bufp != 0 && $size != 0 && $rseq != $wseq )
144                 while ( $rseq < $wseq )
145                         set $c = $bufp + $rseq
146                         printf "%c", *$c
147                         set $rseq = $rseq + 1
148                         if ( $rseq == msgbufp->msg_size )
149                                 set $rseq = 0
150                         end
151                 end
152                 if ( *$c == '\n' )
153                         printf "\n"
154                 end
155                 printf "\n"
156         end
157 end
158
159 # Documentation, usable within GDB using the 'help' command.
160 document lsvfs
161 Output list of loaded file systems, refcount, similar to the
162 lsvfs(1) utility.
163 end
164
165 document lsmount
166 Iterate the current list of mount structures loaded from the
167 memory core, there should be one per loaded VFS.
168 end
169
170 document lsvfsops
171 Display the VFS operations vector for each file system found in
172 the memory core, preceded by a summarised header.
173 end
174
175 document kldstat
176 Output list of loaded kernel modules in kldstat(1) style.
177 end
178
179 document pcomm
180 Print command name of the given thread pointer (first argument).
181 end
182
183 document psx
184 Output a list of processes with wait-channel (wchan) informaiton.
185 end
186
187 document running_threads
188 List the threads which are currently running and their CPU number.
189 end
190
191 document psax
192 Output a list of processes.
193 end
194
195 document lstok
196 Display all known global tokens and some information about them.
197 end
198
199 document infotok
200 Takes one argument, a struct lwkt_token * (pointer) and prints some
201 information about that token.
202 end
203
204 document dmesg
205 Shows the unread portion of the kernel message buffer.
206 end