Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
show kernhist in crash
Anyone interested in the patch of adding show kernhist to crash(8)?
--- src/sys/sys/kernhist.h.orig 2014-03-31 16:25:43.000000000 +0900
+++ src/sys/sys/kernhist.h 2015-05-09 22:32:06.000000000 +0900
@@ -86,7 +86,7 @@ LIST_HEAD(kern_history_head, kern_histor
#define KERNHIST_UVMUBCHIST 0x00000004 /* ubchist */
#define KERNHIST_UVMLOANHIST 0x00000008 /* loanhist */
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_KMEMUSER)
/*
* macros to use the history/tracing code. note that KERNHIST_LOG
@@ -216,6 +216,10 @@ do { \
#endif
+#ifdef _KMEMUSER
+#include <stdio.h> /* for printf */
+#endif
+
static inline void kernhist_entry_print(const struct kern_history_ent *);
static inline void
--- src/usr.sbin/crash/Makefile.orig 2015-02-10 18:49:36.000000000 +0900
+++ src/usr.sbin/crash/Makefile 2015-05-09 22:35:11.000000000 +0900
@@ -35,6 +35,7 @@ S= ${.CURDIR}/../../sys
CPPFLAGS+= -I${.CURDIR} -I${.OBJDIR} -I${S} -fno-strict-aliasing
CPPFLAGS+= -DDDB_VERBOSE_HELP -DDB_MAX_LINE=10000000 -D_KMEMUSER
CPPFLAGS+= -UDB_MACHINE_COMMANDS
+CPPFLAGS+= -DKERNHIST -DDDB -Wno-format-nonliteral
# ddb files from kernel
.PATH: $S/ddb
@@ -42,6 +43,7 @@ SRCS+= db_command.c db_lwp.c db_proc.c d
SRCS+= db_access.c db_elf.c db_examine.c
SRCS+= db_expr.c db_lex.c db_output.c db_print.c
SRCS+= db_sym.c db_variables.c db_write_cmd.c
+CPPFLAGS.db_command.c += -DKERNHIST -DDDB -Wno-format-nonliteral
.PATH: ${S}/arch/${MACHINE}/${MACHINE}
.PATH: ${S}/arch/${MACHINE_ARCH}/${MACHINE_ARCH}
--- src/usr.sbin/crash/crash.c.orig 2014-10-06 22:57:38.000000000 +0900
+++ src/usr.sbin/crash/crash.c 2015-05-09 23:10:13.000000000 +0900
@@ -53,6 +53,7 @@ __RCSID("$NetBSD: crash.c,v 1.8 2014/10/
#include <err.h>
#include <ctype.h>
#include <util.h>
+#include <sys/kernhist.h>
#include "extern.h"
@@ -72,6 +73,8 @@ static struct nlist nl[] = {
{ .n_name = "_osrelease" },
#define X_PANICSTR 1
{ .n_name = "_panicstr" },
+#define X_KERN_HISTORIES 2
+ { .n_name = "_kern_histories" },
{ .n_name = NULL },
};
@@ -301,6 +304,50 @@ cnputc(int c)
putc(c, ofp);
}
+#define FMTLEN 1024
+#define FNLEN 128
+
+void
+kernhist_dump(struct kern_history *l)
+{
+ unsigned int lcv;
+ struct kern_history kh;
+ struct kern_history_ent ke;
+ char fmt[FMTLEN];
+ char fn[FNLEN];
+
+ db_read_bytes((db_addr_t)l, sizeof(kh), (char *)&kh);
+ lcv = kh.f;
+ do {
+ db_read_bytes((db_addr_t)&kh.e[lcv], sizeof(ke), (char *)&ke);
+ if (ke.fmt) {
+ db_read_bytes((db_addr_t)ke.fmt, sizeof(fmt), fmt);
+ db_read_bytes((db_addr_t)ke.fn, sizeof(fn), fn);
+ fmt[FMTLEN-1] = '\0';
+ fn[FNLEN-1] = '\0';
+ ke.fmt = fmt;
+ ke.fn = fn;
+ kernhist_entry_print(&ke);
+ }
+ lcv = (lcv + 1) % kh.n;
+ } while (lcv != kh.f);
+}
+
+void
+kernhist_print(void (*pr)(const char *, ...))
+{
+ struct kern_history_head khh;
+
+ if (nl[X_KERN_HISTORIES].n_value == 0) {
+ warnx("kernhist is not available");
+ return;
+ }
+
+ db_read_bytes(nl[X_KERN_HISTORIES].n_value, sizeof(khh), (char *)&khh);
+
+ kernhist_dump(LIST_FIRST(&khh));
+}
+
__dead static void
usage(void)
{
--
t-hash
Home |
Main Index |
Thread Index |
Old Index