Merge from vendor branch GDB:
[dragonfly.git] / test / debug / gdb.kernel
1 # $DragonFly: src/test/debug/gdb.kernel,v 1.2 2004/06/26 13:19:06 hmp Exp $
2 #
3 # Command file for the GNU Debugger, for kernel debugging.
4 #
5 # This file can either be put in your home directory as ~/.gdbinit,
6 # or selected at run time as:
7 #
8 #       'gdb -k -q -x /usr/src/test/debug/gdb.kernel ...'
9 #
10 # Here is a list of macros and short one-line descriptions:
11 #
12 #    kldstat    - kldstat(1) command style output of loaded modules 
13 #    pcomm      - print command name of arg0's (thread's) process pointer
14 #    psx        - process listing with wchan information
15 #    running_threads - the current running thread on each CPU.
16 #
17 set print union
18 set history expansion on
19
20 define pcomm
21         printf "%10s\n",$arg0->td_comm
22 end
23
24 define kldstat
25         set $kld = linker_files.tqh_first
26         printf "Id Refs Address    Size     Name\n"
27         while ($kld != 0)
28                 printf "%2d %4d 0x%08x %-8x %s\n", \
29                 $kld->id, $kld->refs, $kld->address, $kld->size, $kld->filename
30                 set $kld = $kld->link.tqe_next
31         end
32 end
33
34 define psx 
35     set $cpu = 0
36     printf "cpu  pid    thread    flags comm       wchan wmesg\n"
37     while ($cpu < ncpus)
38         set $gd = &((struct privatespace *)&CPU_prvspace)[$cpu].mdglobaldata
39         set $td = $gd->mi.gd_tdallq.tqh_first
40         while ( $td != 0 )
41             if ( $td->td_proc != 0 )
42                 set $pid = $td->td_proc->p_pid
43             else
44                 set $pid = -1
45             end
46             if ( $td->td_wmesg != 0 )
47                 printf "%3d %5d %08x %08x %-10s %08x %s\n",     \
48                     $cpu, $pid, $td, $td->td_flags, $td->td_comm, $td->td_wchan, \
49                     $td->td_wmesg
50             else
51                 printf "%3d %5d %08x %08x %-10s %08x\n",        \
52                     $cpu, $pid, $td, $td->td_flags, $td->td_comm, $td->td_wchan
53             end
54             set $td = $td->td_allq.tqe_next
55         end
56         set $cpu = $cpu + 1
57     end
58 end
59
60
61 define running_threads
62     set $icpu = 0
63         printf "cpu    curthread    wchan\n"
64         while ($icpu < ncpus)
65             set $ipvspace = (struct privatespace *)&CPU_prvspace
66                 set $gd = $ipvspace[$icpu].mdglobaldata.mi
67                 set $td = $gd.gd_curthread
68             printf "%d    %10s    %08x\n", \
69                         $gd.gd_cpuid, $td->td_comm, $td->td_wchan
70             set $icpu = $icpu + 1
71         end
72 end
73
74 # Documentation, usable within GDB using the 'help' command.
75 document kldstat
76 Output list of loaded kernel modules in kldstat(1) style.
77 end
78
79 document pcomm
80 Print command name of the given thread pointer (first argument).
81 end
82
83 document psx
84 Output a list of processes with wait-channel (wchan) informaiton.
85 end
86
87 document running_threads
88 List the threads which are currently running and their CPU number.
89 end