No empty .Rs/.Re
[netbsd-mini2440.git] / sys / ddb / db_xxx.c
blob35d27108c9b6d1eb27e1c3dab42cde5bf9a17e43
1 /* $NetBSD: db_xxx.c,v 1.61 2009/05/24 21:41:25 ad Exp $ */
3 /*
4 * Copyright (c) 1982, 1986, 1989, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
31 * from: kern_proc.c 8.4 (Berkeley) 1/4/94
35 * Miscellaneous DDB functions that are intimate (xxx) with various
36 * data structures and functions used by the kernel (proc, callout).
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.61 2009/05/24 21:41:25 ad Exp $");
42 #ifdef _KERNEL_OPT
43 #include "opt_kgdb.h"
44 #include "opt_aio.h"
45 #include "opt_mqueue.h"
46 #endif
48 #ifndef _KERNEL
49 #include <stdbool.h>
50 #endif
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
55 #include <sys/proc.h>
56 #include <sys/msgbuf.h>
57 #include <sys/callout.h>
58 #include <sys/file.h>
59 #include <sys/filedesc.h>
60 #include <sys/lockdebug.h>
61 #include <sys/signalvar.h>
62 #include <sys/resourcevar.h>
63 #include <sys/pool.h>
64 #include <sys/uio.h>
65 #include <sys/kauth.h>
66 #include <sys/mqueue.h>
67 #include <sys/vnode.h>
68 #include <sys/module.h>
69 #include <sys/cpu.h>
70 #include <sys/vmem.h>
72 #include <ddb/ddb.h>
73 #include <ddb/db_user.h>
75 #ifdef KGDB
76 #include <sys/kgdb.h>
77 #endif
79 void
80 db_kill_proc(db_expr_t addr, bool haddr,
81 db_expr_t count, const char *modif)
84 db_printf("This command is not currently supported.\n");
87 #ifdef KGDB
88 void
89 db_kgdb_cmd(db_expr_t addr, bool haddr,
90 db_expr_t count, const char *modif)
92 kgdb_active++;
93 kgdb_trap(db_trap_type, DDB_REGS);
94 kgdb_active--;
96 #endif
98 void
99 db_show_files_cmd(db_expr_t addr, bool haddr,
100 db_expr_t count, const char *modif)
102 #ifdef _KERNEL /* XXX CRASH(8) */
103 struct proc *p;
104 int i;
105 filedesc_t *fdp;
106 fdfile_t *ff;
107 file_t *fp;
108 struct vnode *vn;
109 bool full = false;
110 fdtab_t *dt;
112 if (modif[0] == 'f')
113 full = true;
115 p = (struct proc *) (uintptr_t) addr;
117 fdp = p->p_fd;
118 dt = fdp->fd_dt;
119 for (i = 0; i < dt->dt_nfiles; i++) {
120 if ((ff = dt->dt_ff[i]) == NULL)
121 continue;
123 fp = ff->ff_file;
125 /* Only look at vnodes... */
126 if ((fp != NULL) && (fp->f_type == DTYPE_VNODE)) {
127 if (fp->f_data != NULL) {
128 vn = (struct vnode *) fp->f_data;
129 vfs_vnode_print(vn, full, db_printf);
131 #ifdef LOCKDEBUG
132 db_printf("\nv_uobj.vmobjlock lock details:\n");
133 lockdebug_lock_print(&(vn->v_uobj.vmobjlock),
134 db_printf);
135 db_printf("\n");
136 #endif
140 #endif
143 #ifdef AIO
144 void
145 db_show_aio_jobs(db_expr_t addr, bool haddr,
146 db_expr_t count, const char *modif)
149 aio_print_jobs(db_printf);
151 #endif
153 #ifdef MQUEUE
154 void
155 db_show_mqueue_cmd(db_expr_t addr, bool haddr,
156 db_expr_t count, const char *modif)
159 #ifdef _KERNEL /* XXX CRASH(8) */
160 mqueue_print_list(db_printf);
161 #endif
163 #endif
165 void
166 db_show_module_cmd(db_expr_t addr, bool haddr,
167 db_expr_t count, const char *modif)
170 #ifdef _KERNEL /* XXX CRASH(8) */
171 module_print_list(db_printf);
172 #endif
175 void
176 db_show_all_pools(db_expr_t addr, bool haddr,
177 db_expr_t count, const char *modif)
180 #ifdef _KERNEL /* XXX CRASH(8) */
181 pool_printall(modif, db_printf);
182 #endif
185 void
186 db_show_all_vmems(db_expr_t addr, bool have_addr,
187 db_expr_t count, const char *modif)
190 #ifdef _KERNEL /* XXX CRASH(8) */
191 vmem_printall(modif, db_printf);
192 #endif
195 void
196 db_dmesg(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
198 struct kern_msgbuf mb, *mbp;
199 db_expr_t print;
200 int newl, skip, i;
201 char *p, *bufdata, ch;
203 if (!db_read_int("msgbufenabled")) {
204 db_printf("message buffer not available\n");
205 return;
207 mbp = (struct kern_msgbuf *)db_read_ptr("msgbufp");
208 db_read_bytes((db_addr_t)mbp, sizeof(mb), (char *)&mb);
209 if (mb.msg_magic != MSG_MAGIC) {
210 db_printf("message buffer not available\n");
211 return;
214 bufdata = &mbp->msg_bufc[0];
216 if (haddr && addr < mb.msg_bufs)
217 print = addr;
218 else
219 print = mb.msg_bufs;
221 for (newl = skip = i = 0, p = bufdata + mb.msg_bufx;
222 i < mb.msg_bufs; i++, p++) {
223 if (p == bufdata + mb.msg_bufs)
224 p = bufdata;
225 if (i < mb.msg_bufs - print) {
226 continue;
228 db_read_bytes((db_addr_t)p, sizeof(ch), &ch);
229 /* Skip "\n<.*>" syslog sequences. */
230 if (skip) {
231 if (ch == '>')
232 newl = skip = 0;
233 continue;
235 if (newl && ch == '<') {
236 skip = 1;
237 continue;
239 if (ch == '\0')
240 continue;
241 newl = ch == '\n';
242 db_printf("%c", ch);
244 if (!newl)
245 db_printf("\n");
248 void
249 db_show_sched_qs(db_expr_t addr, bool haddr,
250 db_expr_t count, const char *modif)
253 #ifdef _KERNEL /* XXX CRASH(8) */
254 sched_print_runqueue(db_printf);
255 #endif