Annotation of src/sys/ddb/db_xxx.c, Revision 1.70
1.70 ! matt 1: /* $NetBSD: db_xxx.c,v 1.69 2013/01/06 03:34:52 christos Exp $ */
1.1 gwr 2:
3: /*
4: * Copyright (c) 1982, 1986, 1989, 1991, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
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.
1.26 agc 15: * 3. Neither the name of the University nor the names of its contributors
1.1 gwr 16: * may be used to endorse or promote products derived from this software
17: * without specific prior written permission.
18: *
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.
30: *
31: * from: kern_proc.c 8.4 (Berkeley) 1/4/94
32: */
33:
34: /*
35: * Miscellaneous DDB functions that are intimate (xxx) with various
36: * data structures and functions used by the kernel (proc, callout).
37: */
1.15 lukem 38:
1.46 dsl 39: #include <sys/cdefs.h>
1.70 ! matt 40: __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.69 2013/01/06 03:34:52 christos Exp $");
1.46 dsl 41:
1.57 ad 42: #ifdef _KERNEL_OPT
1.21 briggs 43: #include "opt_kgdb.h"
1.53 ad 44: #include "opt_aio.h"
1.62 rmind 45: #include "opt_mqueue.h"
1.57 ad 46: #endif
47:
1.59 mrg 48: #ifndef _KERNEL
49: #include <stdbool.h>
50: #endif
51:
1.1 gwr 52: #include <sys/param.h>
53: #include <sys/systm.h>
54: #include <sys/kernel.h>
55: #include <sys/proc.h>
1.12 atatat 56: #include <sys/msgbuf.h>
1.1 gwr 57: #include <sys/callout.h>
1.49 blymn 58: #include <sys/file.h>
59: #include <sys/filedesc.h>
60: #include <sys/lockdebug.h>
1.1 gwr 61: #include <sys/signalvar.h>
1.3 ross 62: #include <sys/resourcevar.h>
1.34 he 63: #include <sys/pool.h>
1.57 ad 64: #include <sys/uio.h>
1.38 elad 65: #include <sys/kauth.h>
1.47 rmind 66: #include <sys/mqueue.h>
1.49 blymn 67: #include <sys/vnode.h>
1.54 ad 68: #include <sys/module.h>
1.55 ad 69: #include <sys/cpu.h>
1.56 yamt 70: #include <sys/vmem.h>
1.1 gwr 71:
1.57 ad 72: #include <ddb/ddb.h>
1.58 mrg 73: #include <ddb/db_user.h>
1.1 gwr 74:
1.21 briggs 75: #ifdef KGDB
76: #include <sys/kgdb.h>
77: #endif
1.1 gwr 78:
79: void
1.42 matt 80: db_kill_proc(db_expr_t addr, bool haddr,
1.40 christos 81: db_expr_t count, const char *modif)
1.1 gwr 82: {
1.63 christos 83: #ifdef _KERNEL /* XXX CRASH(8) */
84: struct proc *p;
85: ksiginfo_t ksi;
86: db_expr_t pid, sig;
87: int t;
88:
89: /* What pid? */
90: if (!db_expression(&pid)) {
91: db_error("pid?\n");
92: /*NOTREACHED*/
93: }
94: /* What sig? */
95: t = db_read_token();
96: if (t == tCOMMA) {
97: if (!db_expression(&sig)) {
98: db_error("sig?\n");
99: /*NOTREACHED*/
100: }
101: } else {
102: db_unread_token(t);
103: sig = 15;
104: }
105: if (db_read_token() != tEOL) {
106: db_error("?\n");
107: /*NOTREACHED*/
108: }
1.65 christos 109: /* We might stop when the mutex is held or when not */
110: t = mutex_tryenter(proc_lock);
1.66 christos 111: #ifdef DIAGNOSTIC
112: if (!t) {
113: db_error("could not acquire proc_lock mutex\n");
114: /*NOTREACHED*/
115: }
116: #endif
1.63 christos 117: p = proc_find((pid_t)pid);
118: if (p == NULL) {
1.66 christos 119: if (t)
120: mutex_exit(proc_lock);
121: db_error("no such proc\n");
122: /*NOTREACHED*/
1.63 christos 123: }
124: KSI_INIT(&ksi);
125: ksi.ksi_signo = sig;
126: ksi.ksi_code = SI_USER;
127: ksi.ksi_pid = 0;
128: ksi.ksi_uid = 0;
1.66 christos 129: mutex_enter(p->p_lock);
1.63 christos 130: kpsignal2(p, &ksi);
1.66 christos 131: mutex_exit(p->p_lock);
132: if (t)
133: mutex_exit(proc_lock);
1.63 christos 134: #else
1.57 ad 135: db_printf("This command is not currently supported.\n");
1.63 christos 136: #endif
1.1 gwr 137: }
1.21 briggs 138:
139: #ifdef KGDB
140: void
1.42 matt 141: db_kgdb_cmd(db_expr_t addr, bool haddr,
1.40 christos 142: db_expr_t count, const char *modif)
1.21 briggs 143: {
144: kgdb_active++;
145: kgdb_trap(db_trap_type, DDB_REGS);
146: kgdb_active--;
147: }
148: #endif
1.1 gwr 149:
150: void
1.49 blymn 151: db_show_files_cmd(db_expr_t addr, bool haddr,
152: db_expr_t count, const char *modif)
153: {
1.57 ad 154: #ifdef _KERNEL /* XXX CRASH(8) */
1.49 blymn 155: struct proc *p;
156: int i;
1.50 blymn 157: filedesc_t *fdp;
158: fdfile_t *ff;
159: file_t *fp;
1.70 ! matt 160: struct vnode *vp;
1.49 blymn 161: bool full = false;
1.61 ad 162: fdtab_t *dt;
1.49 blymn 163:
164: if (modif[0] == 'f')
165: full = true;
166:
1.52 rmind 167: p = (struct proc *) (uintptr_t) addr;
1.49 blymn 168:
1.50 blymn 169: fdp = p->p_fd;
1.61 ad 170: dt = fdp->fd_dt;
171: for (i = 0; i < dt->dt_nfiles; i++) {
172: if ((ff = dt->dt_ff[i]) == NULL)
1.49 blymn 173: continue;
174:
175: fp = ff->ff_file;
176:
177: /* Only look at vnodes... */
1.70 ! matt 178: if (fp != NULL && fp->f_type == DTYPE_VNODE
! 179: && fp->f_vnode != NULL) {
! 180: vp = fp->f_vnode;
! 181: vfs_vnode_print(vp, full, db_printf);
1.49 blymn 182:
183: #ifdef LOCKDEBUG
1.70 ! matt 184: db_printf("\nv_uobj.vmobjlock lock details:\n");
! 185: lockdebug_lock_print(vp->v_uobj.vmobjlock, db_printf);
! 186: db_printf("\n");
1.49 blymn 187: #endif
188: }
189: }
1.57 ad 190: #endif
1.49 blymn 191: }
192:
1.53 ad 193: #ifdef AIO
1.49 blymn 194: void
1.43 rmind 195: db_show_aio_jobs(db_expr_t addr, bool haddr,
196: db_expr_t count, const char *modif)
197: {
1.57 ad 198:
1.43 rmind 199: aio_print_jobs(db_printf);
200: }
1.53 ad 201: #endif
1.43 rmind 202:
1.62 rmind 203: #ifdef MQUEUE
1.43 rmind 204: void
1.47 rmind 205: db_show_mqueue_cmd(db_expr_t addr, bool haddr,
206: db_expr_t count, const char *modif)
207: {
1.57 ad 208:
209: #ifdef _KERNEL /* XXX CRASH(8) */
1.47 rmind 210: mqueue_print_list(db_printf);
1.57 ad 211: #endif
1.47 rmind 212: }
1.62 rmind 213: #endif
1.47 rmind 214:
215: void
1.54 ad 216: db_show_module_cmd(db_expr_t addr, bool haddr,
217: db_expr_t count, const char *modif)
218: {
1.57 ad 219:
220: #ifdef _KERNEL /* XXX CRASH(8) */
1.54 ad 221: module_print_list(db_printf);
1.57 ad 222: #endif
1.12 atatat 223: }
224:
225: void
1.42 matt 226: db_show_all_pools(db_expr_t addr, bool haddr,
1.40 christos 227: db_expr_t count, const char *modif)
1.33 yamt 228: {
229:
1.57 ad 230: #ifdef _KERNEL /* XXX CRASH(8) */
1.33 yamt 231: pool_printall(modif, db_printf);
1.57 ad 232: #endif
1.33 yamt 233: }
234:
235: void
1.56 yamt 236: db_show_all_vmems(db_expr_t addr, bool have_addr,
237: db_expr_t count, const char *modif)
238: {
239:
1.57 ad 240: #ifdef _KERNEL /* XXX CRASH(8) */
1.56 yamt 241: vmem_printall(modif, db_printf);
1.57 ad 242: #endif
1.56 yamt 243: }
244:
245: void
1.60 ad 246: db_dmesg(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
1.12 atatat 247: {
1.60 ad 248: struct kern_msgbuf mb, *mbp;
1.25 simonb 249: db_expr_t print;
1.60 ad 250: int newl, skip, i;
251: char *p, *bufdata, ch;
1.22 atatat 252:
1.60 ad 253: if (!db_read_int("msgbufenabled")) {
254: db_printf("message buffer not available\n");
255: return;
256: }
257: mbp = (struct kern_msgbuf *)db_read_ptr("msgbufp");
258: db_read_bytes((db_addr_t)mbp, sizeof(mb), (char *)&mb);
259: if (mb.msg_magic != MSG_MAGIC) {
1.22 atatat 260: db_printf("message buffer not available\n");
261: return;
262: }
1.12 atatat 263:
264: bufdata = &mbp->msg_bufc[0];
265:
1.60 ad 266: if (haddr && addr < mb.msg_bufs)
1.25 simonb 267: print = addr;
268: else
1.60 ad 269: print = mb.msg_bufs;
1.25 simonb 270:
1.60 ad 271: for (newl = skip = i = 0, p = bufdata + mb.msg_bufx;
272: i < mb.msg_bufs; i++, p++) {
273: if (p == bufdata + mb.msg_bufs)
1.12 atatat 274: p = bufdata;
1.60 ad 275: if (i < mb.msg_bufs - print) {
1.25 simonb 276: continue;
1.60 ad 277: }
278: db_read_bytes((db_addr_t)p, sizeof(ch), &ch);
1.12 atatat 279: /* Skip "\n<.*>" syslog sequences. */
280: if (skip) {
281: if (ch == '>')
282: newl = skip = 0;
283: continue;
284: }
285: if (newl && ch == '<') {
286: skip = 1;
287: continue;
288: }
289: if (ch == '\0')
290: continue;
291: newl = ch == '\n';
292: db_printf("%c", ch);
293: }
294: if (!newl)
295: db_printf("\n");
1.28 thorpej 296: }
297:
298: void
1.42 matt 299: db_show_sched_qs(db_expr_t addr, bool haddr,
1.40 christos 300: db_expr_t count, const char *modif)
1.28 thorpej 301: {
1.44 yamt 302:
1.57 ad 303: #ifdef _KERNEL /* XXX CRASH(8) */
1.44 yamt 304: sched_print_runqueue(db_printf);
1.57 ad 305: #endif
1.1 gwr 306: }
1.67 christos 307:
308: void
309: db_show_panic(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
310: {
311: #ifdef _KERNEL /* XXX CRASH(8) */
312: int s;
313:
314: s = splhigh();
315:
316: db_printf("Panic string: %s\n", panicstr);
317:
318: (void)splx(s);
319: #endif
320: }
CVSweb <webmaster@jp.NetBSD.org>