2009-07-19 06:37:33 +04:00
|
|
|
/* $NetBSD: db_xxx.c,v 1.62 2009/07/19 02:37:33 rmind 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>
|
2009-07-19 06:37:33 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.62 2009/07/19 02:37:33 rmind Exp $");
|
2007-07-20 01:54:51 +04:00
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL_OPT
|
2007-07-20 01:54:51 +04:00
|
|
|
#include "opt_kgdb.h"
|
2008-11-15 02:37:50 +03:00
|
|
|
#include "opt_aio.h"
|
2009-07-19 06:37:33 +04:00
|
|
|
#include "opt_mqueue.h"
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
|
|
|
|
2009-03-09 09:07:05 +03:00
|
|
|
#ifndef _KERNEL
|
|
|
|
#include <stdbool.h>
|
|
|
|
#endif
|
|
|
|
|
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>
|
2009-03-08 01:02:16 +03:00
|
|
|
#include <sys/uio.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>
|
2008-11-25 18:14:07 +03:00
|
|
|
#include <sys/module.h>
|
2009-02-04 23:17:58 +03:00
|
|
|
#include <sys/cpu.h>
|
2009-02-18 16:31:59 +03:00
|
|
|
#include <sys/vmem.h>
|
1997-05-21 23:54:00 +04:00
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#include <ddb/ddb.h>
|
2009-03-08 14:40:00 +03:00
|
|
|
#include <ddb/db_user.h>
|
1997-05-21 23:54:00 +04:00
|
|
|
|
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
|
|
|
{
|
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
db_printf("This command is not currently supported.\n");
|
1997-05-21 23:54:00 +04:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL /* XXX CRASH(8) */
|
2008-07-10 16:42:24 +04:00
|
|
|
struct proc *p;
|
|
|
|
int i;
|
2008-07-10 17:28:23 +04:00
|
|
|
filedesc_t *fdp;
|
|
|
|
fdfile_t *ff;
|
|
|
|
file_t *fp;
|
2008-07-10 16:42:24 +04:00
|
|
|
struct vnode *vn;
|
|
|
|
bool full = false;
|
2009-05-25 01:41:25 +04:00
|
|
|
fdtab_t *dt;
|
2008-07-10 16:42:24 +04:00
|
|
|
|
|
|
|
if (modif[0] == 'f')
|
|
|
|
full = true;
|
|
|
|
|
2008-10-03 18:52:11 +04:00
|
|
|
p = (struct proc *) (uintptr_t) addr;
|
2008-07-10 16:42:24 +04:00
|
|
|
|
2008-07-10 17:28:23 +04:00
|
|
|
fdp = p->p_fd;
|
2009-05-25 01:41:25 +04:00
|
|
|
dt = fdp->fd_dt;
|
|
|
|
for (i = 0; i < dt->dt_nfiles; i++) {
|
|
|
|
if ((ff = dt->dt_ff[i]) == NULL)
|
2008-07-10 16:42:24 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
fp = ff->ff_file;
|
|
|
|
|
|
|
|
/* Only look at vnodes... */
|
2008-07-14 14:15:11 +04:00
|
|
|
if ((fp != NULL) && (fp->f_type == DTYPE_VNODE)) {
|
|
|
|
if (fp->f_data != NULL) {
|
|
|
|
vn = (struct vnode *) fp->f_data;
|
|
|
|
vfs_vnode_print(vn, full, db_printf);
|
2008-07-10 16:42:24 +04:00
|
|
|
|
|
|
|
#ifdef LOCKDEBUG
|
2008-07-14 14:15:11 +04:00
|
|
|
db_printf("\nv_uobj.vmobjlock lock details:\n");
|
|
|
|
lockdebug_lock_print(&(vn->v_uobj.vmobjlock),
|
|
|
|
db_printf);
|
|
|
|
db_printf("\n");
|
2008-07-10 16:42:24 +04:00
|
|
|
#endif
|
2008-07-14 14:15:11 +04:00
|
|
|
}
|
2008-07-10 16:42:24 +04:00
|
|
|
}
|
|
|
|
}
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2008-07-10 16:42:24 +04:00
|
|
|
}
|
|
|
|
|
2008-11-15 02:37:50 +03:00
|
|
|
#ifdef AIO
|
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)
|
|
|
|
{
|
2009-03-08 01:02:16 +03:00
|
|
|
|
2007-04-30 18:44:28 +04:00
|
|
|
aio_print_jobs(db_printf);
|
|
|
|
}
|
2008-11-15 02:37:50 +03:00
|
|
|
#endif
|
2007-04-30 18:44:28 +04:00
|
|
|
|
2009-07-19 06:37:33 +04:00
|
|
|
#ifdef MQUEUE
|
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)
|
|
|
|
{
|
2009-03-08 01:02:16 +03:00
|
|
|
|
|
|
|
#ifdef _KERNEL /* XXX CRASH(8) */
|
2007-09-07 22:56:02 +04:00
|
|
|
mqueue_print_list(db_printf);
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2007-09-07 22:56:02 +04:00
|
|
|
}
|
2009-07-19 06:37:33 +04:00
|
|
|
#endif
|
2007-09-07 22:56:02 +04:00
|
|
|
|
2008-11-25 18:14:07 +03:00
|
|
|
void
|
|
|
|
db_show_module_cmd(db_expr_t addr, bool haddr,
|
|
|
|
db_expr_t count, const char *modif)
|
|
|
|
{
|
1997-10-24 22:26:36 +04:00
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL /* XXX CRASH(8) */
|
|
|
|
module_print_list(db_printf);
|
|
|
|
#endif
|
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
|
|
|
{
|
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL /* XXX CRASH(8) */
|
2005-12-01 16:21:05 +03:00
|
|
|
pool_printall(modif, db_printf);
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2005-12-01 16:21:05 +03:00
|
|
|
}
|
|
|
|
|
2009-02-18 16:31:59 +03:00
|
|
|
void
|
|
|
|
db_show_all_vmems(db_expr_t addr, bool have_addr,
|
|
|
|
db_expr_t count, const char *modif)
|
|
|
|
{
|
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL /* XXX CRASH(8) */
|
2009-02-18 16:31:59 +03:00
|
|
|
vmem_printall(modif, db_printf);
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2009-02-18 16:31:59 +03:00
|
|
|
}
|
|
|
|
|
2001-07-31 08:28:16 +04:00
|
|
|
void
|
2009-03-21 16:06:39 +03:00
|
|
|
db_dmesg(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
|
2001-07-31 08:28:16 +04:00
|
|
|
{
|
2009-03-21 16:06:39 +03:00
|
|
|
struct kern_msgbuf mb, *mbp;
|
2003-07-02 11:05:29 +04:00
|
|
|
db_expr_t print;
|
2009-03-21 16:06:39 +03:00
|
|
|
int newl, skip, i;
|
|
|
|
char *p, *bufdata, ch;
|
2001-07-31 08:28:16 +04:00
|
|
|
|
2009-03-21 16:06:39 +03:00
|
|
|
if (!db_read_int("msgbufenabled")) {
|
|
|
|
db_printf("message buffer not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mbp = (struct kern_msgbuf *)db_read_ptr("msgbufp");
|
|
|
|
db_read_bytes((db_addr_t)mbp, sizeof(mb), (char *)&mb);
|
|
|
|
if (mb.msg_magic != MSG_MAGIC) {
|
2003-05-15 17:18:18 +04:00
|
|
|
db_printf("message buffer not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-31 08:28:16 +04:00
|
|
|
bufdata = &mbp->msg_bufc[0];
|
|
|
|
|
2009-03-21 16:06:39 +03:00
|
|
|
if (haddr && addr < mb.msg_bufs)
|
2003-07-02 11:05:29 +04:00
|
|
|
print = addr;
|
|
|
|
else
|
2009-03-21 16:06:39 +03:00
|
|
|
print = mb.msg_bufs;
|
2003-07-02 11:05:29 +04:00
|
|
|
|
2009-03-21 16:06:39 +03:00
|
|
|
for (newl = skip = i = 0, p = bufdata + mb.msg_bufx;
|
|
|
|
i < mb.msg_bufs; i++, p++) {
|
|
|
|
if (p == bufdata + mb.msg_bufs)
|
2001-07-31 08:28:16 +04:00
|
|
|
p = bufdata;
|
2009-03-21 16:06:39 +03:00
|
|
|
if (i < mb.msg_bufs - print) {
|
2003-07-02 11:05:29 +04:00
|
|
|
continue;
|
2009-03-21 16:06:39 +03:00
|
|
|
}
|
|
|
|
db_read_bytes((db_addr_t)p, sizeof(ch), &ch);
|
2001-07-31 08:28:16 +04:00
|
|
|
/* 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
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL /* XXX CRASH(8) */
|
2007-05-17 18:51:11 +04:00
|
|
|
sched_print_runqueue(db_printf);
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2003-09-20 07:02:03 +04:00
|
|
|
}
|