2002-02-15 10:33:48 +03:00
|
|
|
/* $NetBSD: db_xxx.c,v 1.16 2002/02/15 07:33:54 simonb 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* 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>
|
2002-02-15 10:33:48 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.16 2002/02/15 07:33:54 simonb Exp $");
|
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>
|
|
|
|
#include <sys/signalvar.h>
|
1998-01-31 07:14:46 +03:00
|
|
|
#include <sys/resourcevar.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>
|
|
|
|
|
|
|
|
void
|
2002-02-15 10:33:48 +03:00
|
|
|
db_kill_proc(db_expr_t addr, int haddr, db_expr_t count, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-15 10:33:48 +03:00
|
|
|
db_show_all_procs(db_expr_t addr, int haddr, db_expr_t count, char *modif)
|
1997-05-21 23:54:00 +04:00
|
|
|
{
|
1998-01-31 07:14:46 +03:00
|
|
|
int i;
|
1997-10-24 22:26:36 +04:00
|
|
|
char *mode;
|
1997-05-21 23:54:00 +04:00
|
|
|
struct proc *p, *pp;
|
2001-09-15 22:20:53 +04:00
|
|
|
struct timeval tv[2];
|
1998-09-09 03:50:13 +04:00
|
|
|
const struct proclist_desc *pd;
|
2002-02-15 10:33:48 +03:00
|
|
|
|
1997-10-24 22:26:36 +04:00
|
|
|
if (modif[0] == 0)
|
|
|
|
modif[0] = 'n'; /* default == normal mode */
|
|
|
|
|
|
|
|
mode = strchr("mawn", modif[0]);
|
|
|
|
if (mode == NULL || *mode == 'm') {
|
|
|
|
db_printf("usage: show all procs [/a] [/n] [/w]\n");
|
|
|
|
db_printf("\t/a == show process address info\n");
|
|
|
|
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;
|
|
|
|
case 'n':
|
1998-01-31 07:14:46 +03:00
|
|
|
db_printf(" PID %10s %10s %10s S %7s %16s %7s\n",
|
1997-10-24 22:26:36 +04:00
|
|
|
"PPID", "PGRP", "UID", "FLAGS", "COMMAND", "WAIT");
|
|
|
|
break;
|
|
|
|
case 'w':
|
1998-01-31 07:14:46 +03:00
|
|
|
db_printf(" PID %10s %8s %4s %5s %5s %-12s%s\n",
|
|
|
|
"COMMAND", "EMUL", "PRI", "UTIME", "STIME",
|
|
|
|
"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;
|
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;
|
|
|
|
}
|
1997-10-24 22:26:36 +04:00
|
|
|
|
1998-01-31 07:14:46 +03:00
|
|
|
db_printf("%c%-10d", " >"[curproc == p], p->p_pid);
|
1997-10-24 22:26:36 +04:00
|
|
|
|
|
|
|
switch (*mode) {
|
|
|
|
|
|
|
|
case 'a':
|
|
|
|
db_printf("%10.10s %18p %18p %18p\n",
|
|
|
|
p->p_comm, p, p->p_addr, p->p_vmspace);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
db_printf("%10d %10d %10d %d %#7x %16s %7.7s\n",
|
|
|
|
pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
|
|
|
|
p->p_cred->p_ruid, p->p_stat, p->p_flag,
|
|
|
|
p->p_comm, (p->p_wchan && p->p_wmesg) ?
|
|
|
|
p->p_wmesg : "");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
1998-01-31 07:14:46 +03:00
|
|
|
db_printf("%10s %8s %4d", p->p_comm,
|
|
|
|
p->p_emul->e_name,p->p_priority);
|
2001-09-15 22:20:53 +04:00
|
|
|
calcru(p, &tv[0], &tv[1], NULL);
|
|
|
|
for (i = 0; i < 2; ++i) {
|
2000-03-27 00:24:12 +04:00
|
|
|
db_printf("%4ld.%1ld",
|
|
|
|
(long)tv[i].tv_sec,
|
|
|
|
(long)tv[i].tv_usec/100000);
|
1998-01-31 07:14:46 +03:00
|
|
|
}
|
2001-09-15 22:20:53 +04:00
|
|
|
if (p->p_wchan && p->p_wmesg) {
|
1998-01-31 07:14:46 +03:00
|
|
|
db_printf(" %-12s", p->p_wmesg);
|
1998-08-13 06:10:37 +04:00
|
|
|
db_printsym((db_expr_t)p->p_wchan,
|
2000-05-25 23:57:30 +04:00
|
|
|
DB_STGY_XTRN, db_printf);
|
1998-01-31 07:14:46 +03:00
|
|
|
}
|
|
|
|
db_printf("\n");
|
1997-10-24 22:26:36 +04:00
|
|
|
break;
|
|
|
|
|
1997-05-21 23:54:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-15 10:33:48 +03:00
|
|
|
db_show_callout(db_expr_t addr, int haddr, db_expr_t count, char *modif)
|
1997-05-21 23:54:00 +04:00
|
|
|
{
|
2001-09-11 08:32:19 +04:00
|
|
|
uint64_t hint;
|
2000-11-28 22:20:37 +03:00
|
|
|
int i;
|
2000-03-23 10:01:25 +03:00
|
|
|
|
2000-11-29 00:44:34 +03:00
|
|
|
for (i = 0; i < callwheelsize; i++) {
|
2000-11-28 22:20:37 +03:00
|
|
|
struct callout_queue *bucket = &callwheel[i];
|
2001-09-11 08:32:19 +04:00
|
|
|
struct callout *c = TAILQ_FIRST(&bucket->cq_q);
|
2000-11-28 22:20:37 +03:00
|
|
|
|
2001-09-11 08:32:19 +04:00
|
|
|
if (c) {
|
|
|
|
db_printf("bucket %d (hint %llx):\n", i,
|
|
|
|
(long long) bucket->cq_hint);
|
|
|
|
hint = UQUAD_MAX;
|
|
|
|
while (c) {
|
|
|
|
if (c->c_time < hint)
|
|
|
|
hint = c->c_time;
|
|
|
|
db_printf("%p: time %llx arg %p flags %x "
|
|
|
|
"func %p: ", c, (long long) c->c_time,
|
|
|
|
c->c_arg, c->c_flags, c->c_func);
|
|
|
|
db_printsym((u_long)c->c_func, DB_STGY_PROC,
|
|
|
|
db_printf);
|
|
|
|
db_printf("\n");
|
|
|
|
c = TAILQ_NEXT(c, c_link);
|
|
|
|
}
|
|
|
|
if (bucket->cq_hint < hint)
|
|
|
|
printf("** HINT IS STALE\n");
|
2000-11-28 22:20:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-05-21 23:54:00 +04:00
|
|
|
}
|
2001-07-31 08:28:16 +04:00
|
|
|
|
|
|
|
void
|
2002-02-15 10:33:48 +03:00
|
|
|
db_dmesg(db_expr_t addr, int haddr, db_expr_t count, char *modif)
|
2001-07-31 08:28:16 +04:00
|
|
|
{
|
|
|
|
struct kern_msgbuf *mbp;
|
|
|
|
int ch, newl, skip, i;
|
|
|
|
char *p, *bufdata;
|
|
|
|
|
|
|
|
mbp = msgbufp;
|
|
|
|
bufdata = &mbp->msg_bufc[0];
|
|
|
|
|
|
|
|
for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
|
|
|
|
i < mbp->msg_bufs; i++, p++) {
|
|
|
|
if (p == bufdata + mbp->msg_bufs)
|
|
|
|
p = bufdata;
|
|
|
|
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");
|
|
|
|
}
|