Make 'show event', 'dmesg' work with crash(8).

XXX dmesg fails exactly the same way as /sbin/dmesg.
This commit is contained in:
ad 2009-03-21 13:06:39 +00:00
parent 5d2a6ba964
commit 912b4160fd
4 changed files with 69 additions and 76 deletions

View File

@ -1,4 +1,34 @@
/* $NetBSD: db_command.c,v 1.130 2009/03/11 13:29:44 nakayama Exp $ */
/* $NetBSD: db_command.c,v 1.131 2009/03/21 13:06:39 ad Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Adam Hamsik, and by Andrew Doran.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
@ -24,41 +54,13 @@
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
/*
* Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Adam Hamsik.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Command dispatcher.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.130 2009/03/11 13:29:44 nakayama Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.131 2009/03/21 13:06:39 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_aio.h"
@ -1058,13 +1060,23 @@ db_event_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif)
{
bool full = false;
struct evcnt ev, *evp;
char buf[80];
if (modif[0] == 'f')
full = true;
#ifdef _KERNEL /* XXX CRASH(8) */
event_print(full, db_printf);
#endif
evp = (struct evcnt *)db_read_ptr("allevents");
while (evp != NULL) {
db_read_bytes((db_addr_t)evp, sizeof(ev), (char *)&ev);
evp = ev.ev_list.tqe_next;
if (ev.ev_count == 0 && !full)
continue;
db_read_bytes((db_addr_t)ev.ev_group, ev.ev_grouplen + 1, buf);
db_printf("evcnt type %d: %s ", ev.ev_type, buf);
db_read_bytes((db_addr_t)ev.ev_name, ev.ev_namelen + 1, buf);
db_printf("%s = %lld\n", buf, (long long)ev.ev_count);
}
}
/*ARGSUSED*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_xxx.c,v 1.59 2009/03/09 06:07:05 mrg Exp $ */
/* $NetBSD: db_xxx.c,v 1.60 2009/03/21 13:06:39 ad Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.59 2009/03/09 06:07:05 mrg Exp $");
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.60 2009/03/21 13:06:39 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_kgdb.h"
@ -188,35 +188,39 @@ db_show_all_vmems(db_expr_t addr, bool have_addr,
}
void
db_dmesg(db_expr_t addr, bool haddr, db_expr_t count,
const char *modif)
db_dmesg(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
{
#ifdef _KERNEL /* XXX CRASH(8) */
struct kern_msgbuf *mbp;
struct kern_msgbuf mb, *mbp;
db_expr_t print;
int ch, newl, skip, i;
char *p, *bufdata;
int newl, skip, i;
char *p, *bufdata, ch;
if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
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) {
db_printf("message buffer not available\n");
return;
}
mbp = msgbufp;
bufdata = &mbp->msg_bufc[0];
if (haddr && addr < mbp->msg_bufs)
if (haddr && addr < mb.msg_bufs)
print = addr;
else
print = mbp->msg_bufs;
print = mb.msg_bufs;
for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
i < mbp->msg_bufs; i++, p++) {
if (p == bufdata + mbp->msg_bufs)
for (newl = skip = i = 0, p = bufdata + mb.msg_bufx;
i < mb.msg_bufs; i++, p++) {
if (p == bufdata + mb.msg_bufs)
p = bufdata;
if (i < mbp->msg_bufs - print)
if (i < mb.msg_bufs - print) {
continue;
ch = *p;
}
db_read_bytes((db_addr_t)p, sizeof(ch), &ch);
/* Skip "\n<.*>" syslog sequences. */
if (skip) {
if (ch == '>')
@ -234,7 +238,6 @@ db_dmesg(db_expr_t addr, bool haddr, db_expr_t count,
}
if (!newl)
db_printf("\n");
#endif
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_evcnt.c,v 1.4 2005/12/11 12:24:30 christos Exp $ */
/* $NetBSD: subr_evcnt.c,v 1.5 2009/03/21 13:06:39 ad Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -77,9 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_evcnt.c,v 1.4 2005/12/11 12:24:30 christos Exp $");
#include "opt_ddb.h"
__KERNEL_RCSID(0, "$NetBSD: subr_evcnt.c,v 1.5 2009/03/21 13:06:39 ad Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -164,19 +162,3 @@ evcnt_detach(struct evcnt *ev)
TAILQ_REMOVE(&allevents, ev, ev_list);
}
#ifdef DDB
void
event_print(int full, void (*pr)(const char *, ...))
{
struct evcnt *evp;
TAILQ_FOREACH(evp, &allevents, ev_list) {
if (evp->ev_count == 0 && !full)
continue;
(*pr)("evcnt type %d: %s %s = %lld\n", evp->ev_type,
evp->ev_group, evp->ev_name, evp->ev_count);
}
}
#endif /* DDB */

View File

@ -1,4 +1,4 @@
/* $NetBSD: evcnt.h,v 1.5 2007/12/16 20:45:59 dyoung Exp $ */
/* $NetBSD: evcnt.h,v 1.6 2009/03/21 13:06:39 ad Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -132,10 +132,6 @@ void evcnt_attach_static(struct evcnt *);
void evcnt_attach_dynamic(struct evcnt *, int, const struct evcnt *,
const char *, const char *);
void evcnt_detach(struct evcnt *);
#ifdef DDB
void event_print(int, void (*)(const char *, ...));
#endif
#endif /* _KERNEL */
#endif /* !_SYS_EVCNT_H_ */