2008-07-10 16:42:24 +04:00
|
|
|
/* $NetBSD: db_xxx.c,v 1.49 2008/07/10 12:42:24 blymn Exp $ */
|
1997-05-21 23:54:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986, 1989, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1997-05-21 23:54:00 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* from: kern_proc.c 8.4 (Berkeley) 1/4/94
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Miscellaneous DDB functions that are intimate (xxx) with various
|
|
|
|
* data structures and functions used by the kernel (proc, callout).
|
|
|
|
*/
|
|
|
|
|
2001-11-13 01:54:03 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-07-10 16:42:24 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.49 2008/07/10 12:42:24 blymn Exp $");
|
2007-07-20 01:54:51 +04:00
|
|
|
|
|
|
|
#include "opt_kgdb.h"
|
2001-11-13 01:54:03 +03:00
|
|
|
|
1997-05-21 23:54:00 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
2001-07-31 08:28:16 +04:00
|
|
|
#include <sys/msgbuf.h>
|
1997-05-21 23:54:00 +04:00
|
|
|
|
|
|
|
#include <sys/callout.h>
|
2008-07-10 16:42:24 +04:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/lockdebug.h>
|
1997-05-21 23:54:00 +04:00
|
|
|
#include <sys/signalvar.h>
|
1998-01-31 07:14:46 +03:00
|
|
|
#include <sys/resourcevar.h>
|
2005-12-04 01:47:25 +03:00
|
|
|
#include <sys/pool.h>
|
2006-05-15 01:19:33 +04:00
|
|
|
#include <sys/kauth.h>
|
2007-09-07 22:56:02 +04:00
|
|
|
#include <sys/mqueue.h>
|
2008-07-10 16:42:24 +04:00
|
|
|
#include <sys/vnode.h>
|
1997-05-21 23:54:00 +04:00
|
|
|
|
|
|
|
#include <machine/db_machdep.h>
|
|
|
|
|
|
|
|
#include <ddb/db_access.h>
|
|
|
|
#include <ddb/db_command.h>
|
|
|
|
#include <ddb/db_interface.h>
|
|
|
|
#include <ddb/db_lex.h>
|
|
|
|
#include <ddb/db_output.h>
|
|
|
|
#include <ddb/db_sym.h>
|
|
|
|
#include <ddb/db_extern.h>
|
2003-04-28 06:49:54 +04:00
|
|
|
#ifdef KGDB
|
|
|
|
#include <sys/kgdb.h>
|
|
|
|
#endif
|
1997-05-21 23:54:00 +04:00
|
|
|
|
|
|
|
void
|
2007-02-22 07:38:02 +03:00
|
|
|
db_kill_proc(db_expr_t addr, bool haddr,
|
2006-11-16 04:32:37 +03:00
|
|
|
db_expr_t count, const char *modif)
|
1997-05-21 23:54:00 +04:00
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
db_expr_t pid, sig;
|
|
|
|
int t;
|
|
|
|
|
|
|
|
/* What pid? */
|
|
|
|
if (!db_expression(&pid)) {
|
|
|
|
db_error("pid?\n");
|
2002-02-15 10:33:48 +03:00
|
|
|
/*NOTREACHED*/
|
1997-05-21 23:54:00 +04:00
|
|
|
}
|
|
|
|
/* What sig? */
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tCOMMA) {
|
|
|
|
if (!db_expression(&sig)) {
|
|
|
|
db_error("sig?\n");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
db_unread_token(t);
|
|
|
|
sig = 15;
|
|
|
|
}
|
|
|
|
if (db_read_token() != tEOL) {
|
2002-02-15 10:33:48 +03:00
|
|
|
db_error("?\n");
|
|
|
|
/*NOTREACHED*/
|
1997-05-21 23:54:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
p = pfind((pid_t)pid);
|
|
|
|
if (p == NULL) {
|
|
|
|
db_error("no such proc\n");
|
2002-02-15 10:33:48 +03:00
|
|
|
/*NOTREACHED*/
|
1997-05-21 23:54:00 +04:00
|
|
|
}
|
|
|
|
psignal(p, (int)sig);
|
|
|
|
}
|
|
|
|
|
2003-04-28 06:49:54 +04:00
|
|
|
#ifdef KGDB
|
|
|
|
void
|
2007-02-22 07:38:02 +03:00
|
|
|
db_kgdb_cmd(db_expr_t addr, bool haddr,
|
2006-11-16 04:32:37 +03:00
|
|
|
db_expr_t count, const char *modif)
|
2003-04-28 06:49:54 +04:00
|
|
|
{
|
|
|
|
kgdb_active++;
|
|
|
|
kgdb_trap(db_trap_type, DDB_REGS);
|
|
|
|
kgdb_active--;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-07-10 16:42:24 +04:00
|
|
|
void
|
|
|
|
db_show_files_cmd(db_expr_t addr, bool haddr,
|
|
|
|
db_expr_t count, const char *modif)
|
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
int i;
|
|
|
|
filedesc_t *fdp;
|
|
|
|
fdfile_t *ff;
|
|
|
|
file_t *fp;
|
|
|
|
struct vnode *vn;
|
|
|
|
bool full = false;
|
|
|
|
|
|
|
|
if (modif[0] == 'f')
|
|
|
|
full = true;
|
|
|
|
|
|
|
|
p = (struct proc *) (intptr_t) addr;
|
|
|
|
|
|
|
|
fdp = p->p_fd;
|
|
|
|
for (i = 0; i < fdp->fd_nfiles; i++) {
|
|
|
|
if ((ff = fdp->fd_ofiles[i]) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fp = ff->ff_file;
|
|
|
|
|
|
|
|
/* Only look at vnodes... */
|
|
|
|
if (fp->f_type == DTYPE_VNODE) {
|
|
|
|
vn = (struct vnode *) fp->f_data;
|
|
|
|
vfs_vnode_print(vn, full, db_printf);
|
|
|
|
|
|
|
|
#ifdef LOCKDEBUG
|
|
|
|
lockdebug_lock_print(&(vn->v_uobj.vmobjlock),
|
|
|
|
db_printf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-04-30 18:44:28 +04:00
|
|
|
void
|
|
|
|
db_show_aio_jobs(db_expr_t addr, bool haddr,
|
|
|
|
db_expr_t count, const char *modif)
|
|
|
|
{
|
|
|
|
aio_print_jobs(db_printf);
|
|
|
|
}
|
|
|
|
|
2007-09-07 22:56:02 +04:00
|
|
|
void
|
|
|
|
db_show_mqueue_cmd(db_expr_t addr, bool haddr,
|
|
|
|
db_expr_t count, const char *modif)
|
|
|
|
{
|
|
|
|
mqueue_print_list(db_printf);
|
|
|
|
}
|
|
|
|
|
1997-05-21 23:54:00 +04:00
|
|
|
void
|
2007-02-22 07:38:02 +03:00
|
|
|
db_show_all_procs(db_expr_t addr, bool haddr,
|
2006-11-16 04:32:37 +03:00
|
|
|
db_expr_t count, const char *modif)
|
1997-05-21 23:54:00 +04:00
|
|
|
{
|
2005-06-01 16:25:27 +04:00
|
|
|
const char *mode;
|
2003-01-18 11:51:40 +03:00
|
|
|
struct proc *p, *pp, *cp;
|
|
|
|
struct lwp *l, *cl;
|
1998-09-09 03:50:13 +04:00
|
|
|
const struct proclist_desc *pd;
|
2008-07-10 16:42:24 +04:00
|
|
|
char db_nbuf[MAXCOMLEN + 1];
|
2002-02-15 10:33:48 +03:00
|
|
|
|
1997-10-24 22:26:36 +04:00
|
|
|
if (modif[0] == 0)
|
2005-06-01 16:25:27 +04:00
|
|
|
mode = "n"; /* default == normal mode */
|
|
|
|
else
|
|
|
|
mode = strchr("mawln", modif[0]);
|
1997-10-24 22:26:36 +04:00
|
|
|
|
|
|
|
if (mode == NULL || *mode == 'm') {
|
2006-01-22 03:50:51 +03:00
|
|
|
db_printf("usage: show all procs [/a] [/l] [/n] [/w]\n");
|
1997-10-24 22:26:36 +04:00
|
|
|
db_printf("\t/a == show process address info\n");
|
2003-01-18 11:51:40 +03:00
|
|
|
db_printf("\t/l == show LWP info\n");
|
1997-10-24 22:26:36 +04:00
|
|
|
db_printf("\t/n == show normal process info [default]\n");
|
|
|
|
db_printf("\t/w == show process wait/emul info\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-15 10:33:48 +03:00
|
|
|
switch (*mode) {
|
1997-10-24 22:26:36 +04:00
|
|
|
case 'a':
|
1998-01-31 07:14:46 +03:00
|
|
|
db_printf(" PID %10s %18s %18s %18s\n",
|
1997-10-24 22:26:36 +04:00
|
|
|
"COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
|
|
|
|
break;
|
2003-01-18 11:51:40 +03:00
|
|
|
case 'l':
|
2007-07-10 00:51:58 +04:00
|
|
|
db_printf(" PID %4s S %9s %18s %18s %-8s\n",
|
|
|
|
"LID", "FLAGS", "STRUCT LWP *", "NAME", "WAIT");
|
2003-01-18 11:51:40 +03:00
|
|
|
break;
|
1997-10-24 22:26:36 +04:00
|
|
|
case 'n':
|
2003-01-18 11:51:40 +03:00
|
|
|
db_printf(" PID %8s %8s %10s S %7s %4s %16s %7s\n",
|
|
|
|
"PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
|
1997-10-24 22:26:36 +04:00
|
|
|
break;
|
|
|
|
case 'w':
|
2007-12-02 22:35:33 +03:00
|
|
|
db_printf(" PID %4s %16s %8s %4s %-12s%s\n",
|
|
|
|
"LID", "COMMAND", "EMUL", "PRI", "WAIT-MSG",
|
|
|
|
"WAIT-CHANNEL");
|
1997-10-24 22:26:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-07-23 01:11:26 +04:00
|
|
|
/* XXX LOCKING XXX */
|
1998-09-09 03:50:13 +04:00
|
|
|
pd = proclists;
|
2003-01-18 11:51:40 +03:00
|
|
|
cp = curproc;
|
|
|
|
cl = curlwp;
|
2001-09-15 22:20:53 +04:00
|
|
|
for (pd = proclists; pd->pd_list != NULL; pd++) {
|
|
|
|
LIST_FOREACH(p, pd->pd_list, p_list) {
|
|
|
|
pp = p->p_pptr;
|
|
|
|
if (p->p_stat == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-06-30 02:28:00 +04:00
|
|
|
l = LIST_FIRST(&p->p_lwps);
|
2006-01-22 03:47:50 +03:00
|
|
|
db_printf("%c%-10d", (cp == p ? '>' : ' '), p->p_pid);
|
1997-10-24 22:26:36 +04:00
|
|
|
|
|
|
|
switch (*mode) {
|
|
|
|
|
|
|
|
case 'a':
|
2007-07-10 00:51:58 +04:00
|
|
|
db_printf("%10.10s %18lx %18lx %18lx\n",
|
|
|
|
p->p_comm, (long)p,
|
|
|
|
(long)(l != NULL ? l->l_addr : 0),
|
|
|
|
(long)p->p_vmspace);
|
2003-01-18 11:51:40 +03:00
|
|
|
break;
|
|
|
|
case 'l':
|
2003-01-23 15:41:33 +03:00
|
|
|
while (l != NULL) {
|
2007-07-10 00:51:58 +04:00
|
|
|
if (l->l_name != NULL) {
|
2008-07-10 16:42:24 +04:00
|
|
|
snprintf(db_nbuf,
|
|
|
|
sizeof(db_nbuf),
|
2007-07-10 00:51:58 +04:00
|
|
|
"%s", l->l_name);
|
|
|
|
} else
|
2008-07-10 16:42:24 +04:00
|
|
|
snprintf(db_nbuf,
|
|
|
|
sizeof(db_nbuf),
|
2007-07-10 00:51:58 +04:00
|
|
|
"%s", p->p_comm);
|
|
|
|
db_printf("%c%4d %d %9x %18lx %18s %-8s\n",
|
2006-01-22 03:47:50 +03:00
|
|
|
(cl == l ? '>' : ' '), l->l_lid,
|
2008-07-10 16:42:24 +04:00
|
|
|
l->l_stat, l->l_flag, (long)l,
|
|
|
|
db_nbuf,
|
2003-01-18 11:51:40 +03:00
|
|
|
(l->l_wchan && l->l_wmesg) ?
|
|
|
|
l->l_wmesg : "");
|
|
|
|
|
|
|
|
l = LIST_NEXT(l, l_sibling);
|
|
|
|
if (l)
|
|
|
|
db_printf("%11s","");
|
2003-01-23 15:41:33 +03:00
|
|
|
}
|
1997-10-24 22:26:36 +04:00
|
|
|
break;
|
|
|
|
case 'n':
|
2003-01-18 11:51:40 +03:00
|
|
|
db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
|
1997-10-24 22:26:36 +04:00
|
|
|
pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
|
2006-05-15 01:19:33 +04:00
|
|
|
kauth_cred_getuid(p->p_cred), p->p_stat, p->p_flag,
|
2003-01-18 11:51:40 +03:00
|
|
|
p->p_nlwps, p->p_comm,
|
2003-01-23 15:41:33 +03:00
|
|
|
(p->p_nlwps != 1) ? "*" : (
|
2005-02-27 01:58:54 +03:00
|
|
|
(l->l_wchan && l->l_wmesg) ?
|
2003-01-18 11:51:40 +03:00
|
|
|
l->l_wmesg : ""));
|
1997-10-24 22:26:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
2007-12-02 22:35:33 +03:00
|
|
|
while (l != NULL) {
|
|
|
|
db_printf(
|
|
|
|
"%4d %16s %8s %4d %-12s %-18lx\n",
|
|
|
|
l->l_lid, p->p_comm,
|
|
|
|
p->p_emul->e_name, l->l_priority,
|
|
|
|
(l->l_wchan && l->l_wmesg) ?
|
|
|
|
l->l_wmesg : "", (long)l->l_wchan);
|
|
|
|
l = LIST_NEXT(l, l_sibling);
|
|
|
|
if (l != NULL) {
|
|
|
|
db_printf("%c%-10d", (cp == p ?
|
|
|
|
'>' : ' '), p->p_pid);
|
|
|
|
}
|
1998-01-31 07:14:46 +03:00
|
|
|
}
|
1997-10-24 22:26:36 +04:00
|
|
|
break;
|
1997-05-21 23:54:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-01 16:21:05 +03:00
|
|
|
void
|
2007-02-22 07:38:02 +03:00
|
|
|
db_show_all_pools(db_expr_t addr, bool haddr,
|
2006-11-16 04:32:37 +03:00
|
|
|
db_expr_t count, const char *modif)
|
2005-12-01 16:21:05 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
pool_printall(modif, db_printf);
|
|
|
|
}
|
|
|
|
|
2001-07-31 08:28:16 +04:00
|
|
|
void
|
2007-02-22 07:38:02 +03:00
|
|
|
db_dmesg(db_expr_t addr, bool haddr, db_expr_t count,
|
2006-11-16 04:32:37 +03:00
|
|
|
const char *modif)
|
2001-07-31 08:28:16 +04:00
|
|
|
{
|
|
|
|
struct kern_msgbuf *mbp;
|
2003-07-02 11:05:29 +04:00
|
|
|
db_expr_t print;
|
2001-07-31 08:28:16 +04:00
|
|
|
int ch, newl, skip, i;
|
|
|
|
char *p, *bufdata;
|
|
|
|
|
2003-05-15 17:18:18 +04:00
|
|
|
if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
|
|
|
|
db_printf("message buffer not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-31 08:28:16 +04:00
|
|
|
mbp = msgbufp;
|
|
|
|
bufdata = &mbp->msg_bufc[0];
|
|
|
|
|
2003-07-02 11:05:29 +04:00
|
|
|
if (haddr && addr < mbp->msg_bufs)
|
|
|
|
print = addr;
|
|
|
|
else
|
|
|
|
print = mbp->msg_bufs;
|
|
|
|
|
2001-07-31 08:28:16 +04:00
|
|
|
for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
|
|
|
|
i < mbp->msg_bufs; i++, p++) {
|
|
|
|
if (p == bufdata + mbp->msg_bufs)
|
|
|
|
p = bufdata;
|
2003-07-02 11:05:29 +04:00
|
|
|
if (i < mbp->msg_bufs - print)
|
|
|
|
continue;
|
2001-07-31 08:28:16 +04:00
|
|
|
ch = *p;
|
|
|
|
/* Skip "\n<.*>" syslog sequences. */
|
|
|
|
if (skip) {
|
|
|
|
if (ch == '>')
|
|
|
|
newl = skip = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (newl && ch == '<') {
|
|
|
|
skip = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch == '\0')
|
|
|
|
continue;
|
|
|
|
newl = ch == '\n';
|
|
|
|
db_printf("%c", ch);
|
|
|
|
}
|
|
|
|
if (!newl)
|
|
|
|
db_printf("\n");
|
|
|
|
}
|
2003-09-20 07:02:03 +04:00
|
|
|
|
|
|
|
void
|
2007-02-22 07:38:02 +03:00
|
|
|
db_show_sched_qs(db_expr_t addr, bool haddr,
|
2006-11-16 04:32:37 +03:00
|
|
|
db_expr_t count, const char *modif)
|
2003-09-20 07:02:03 +04:00
|
|
|
{
|
2007-05-17 18:51:11 +04:00
|
|
|
|
|
|
|
sched_print_runqueue(db_printf);
|
2003-09-20 07:02:03 +04:00
|
|
|
}
|