diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/kdump/kdump.1 | 11 | ||||
-rw-r--r-- | usr.bin/kdump/kdump.c | 132 |
2 files changed, 134 insertions, 9 deletions
diff --git a/usr.bin/kdump/kdump.1 b/usr.bin/kdump/kdump.1 index 26baa9db5fe..419ed3ab0ad 100644 --- a/usr.bin/kdump/kdump.1 +++ b/usr.bin/kdump/kdump.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kdump.1,v 1.20 2011/07/09 15:43:38 otto Exp $ +.\" $OpenBSD: kdump.1,v 1.21 2011/07/28 10:33:36 otto Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)kdump.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: July 9 2011 $ +.Dd $Mdocdate: July 28 2011 $ .Dt KDUMP 1 .Os .Sh NAME @@ -97,8 +97,11 @@ specified. .It Fl R Display relative timestamps (time since previous entry). .It Fl r -When decoding STRU records, display structure members such as UIDs, -GIDs, dates etc. symbolically instead of numerically. +When decoding the name in +.Xr sysctl 3 +CALL records or structure members in STRU records +(UIDs, GIDs, dates, etc), +display symbolically instead of numerically. .It Fl T Display absolute timestamps for each entry (seconds since the Epoch). .It Fl t Op ceinstw diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 8de69c1822d..a4d08496715 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kdump.c,v 1.61 2011/07/19 18:20:11 matthew Exp $ */ +/* $OpenBSD: kdump.c,v 1.62 2011/07/28 10:33:36 otto Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -34,17 +34,25 @@ #include <sys/uio.h> #include <sys/ktrace.h> #include <sys/ioctl.h> +#include <sys/malloc.h> +#include <sys/namei.h> #include <sys/ptrace.h> +#include <sys/sem.h> +#include <sys/shm.h> #include <sys/socket.h> #include <sys/sysctl.h> #include <sys/socket.h> #include <sys/un.h> +#include <sys/vmmeter.h> #include <sys/stat.h> +#include <sys/tty.h> #include <netinet/in.h> #include <arpa/inet.h> #define _KERNEL #include <sys/errno.h> #undef _KERNEL +#include <ddb/db_var.h> +#include <machine/cpu.h> #include <ctype.h> #include <err.h> @@ -140,6 +148,7 @@ static void ktrgenio(struct ktr_genio *, size_t); static void ktrnamei(const char *, size_t); static void ktrpsig(struct ktr_psig *); static void ktrsyscall(struct ktr_syscall *); +static const char *kresolvsysctl(int, int *, int); static void ktrsysret(struct ktr_sysret *); static void ktrstruct(char *, size_t); static void setemul(const char *); @@ -511,18 +520,22 @@ ktrsyscall(struct ktr_syscall *ktr) break; } case SYS___sysctl: { - int *np, n; + const char *s; + int *np, n, i, *top; if (!fancy) break; n = ap[1]; if (n > CTL_MAXNAME) n = CTL_MAXNAME; - np = (int *)(ap + 6); - for (; n--; np++) { + np = top = (int *)(ap + 6); + for (i = 0; n--; np++, i++) { if (sep) putchar(sep); - printf("%d", *np); + if (resolv && (s = kresolvsysctl(i, top, *np)) != NULL) + printf("%s", s); + else + printf("%d", *np); sep = '.'; } @@ -825,6 +838,115 @@ nonnative: (void)printf(")\n"); } +static struct ctlname topname[] = CTL_NAMES; +static struct ctlname kernname[] = CTL_KERN_NAMES; +static struct ctlname vmname[] = CTL_VM_NAMES; +static struct ctlname fsname[] = CTL_FS_NAMES; +static struct ctlname netname[] = CTL_NET_NAMES; +static struct ctlname hwname[] = CTL_HW_NAMES; +static struct ctlname username[] = CTL_USER_NAMES; +static struct ctlname debugname[CTL_DEBUG_MAXID]; +static struct ctlname kernmallocname[] = CTL_KERN_MALLOC_NAMES; +static struct ctlname forkstatname[] = CTL_KERN_FORKSTAT_NAMES; +static struct ctlname nchstatsname[] = CTL_KERN_NCHSTATS_NAMES; +static struct ctlname ttysname[] = CTL_KERN_TTY_NAMES; +static struct ctlname semname[] = CTL_KERN_SEMINFO_NAMES; +static struct ctlname shmname[] = CTL_KERN_SHMINFO_NAMES; +static struct ctlname watchdogname[] = CTL_KERN_WATCHDOG_NAMES; +static struct ctlname tcname[] = CTL_KERN_TIMECOUNTER_NAMES; +#ifdef CTL_MACHDEP_NAMES +static struct ctlname machdepname[] = CTL_MACHDEP_NAMES; +#endif +static struct ctlname ddbname[] = CTL_DDB_NAMES; + +#ifndef nitems +#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) +#endif + +#define SETNAME(name) do { names = (name); limit = nitems(name); } while (0) + +static const char * +kresolvsysctl(int depth, int *top, int idx) +{ + struct ctlname *names; + size_t limit; + + names = NULL; + + switch (depth) { + case 0: + SETNAME(topname); + break; + case 1: + switch (top[0]) { + case CTL_KERN: + SETNAME(kernname); + break; + case CTL_VM: + SETNAME(vmname); + break; + case CTL_FS: + SETNAME(fsname); + break; + case CTL_NET: + SETNAME(netname); + break; + case CTL_DEBUG: + SETNAME(debugname); + break; + case CTL_HW: + SETNAME(hwname); + break; +#ifdef CTL_MACHDEP_NAMES + case CTL_MACHDEP: + SETNAME(machdepname); + break; +#endif + case CTL_USER: + SETNAME(username); + break; + case CTL_DDB: + SETNAME(ddbname); + break; + } + break; + case 2: + switch (top[0]) { + case CTL_KERN: + switch (top[1]) { + case KERN_MALLOCSTATS: + SETNAME(kernmallocname); + break; + case KERN_FORKSTAT: + SETNAME(forkstatname); + break; + case KERN_NCHSTATS: + SETNAME(nchstatsname); + break; + case KERN_TTY: + SETNAME(ttysname); + break; + case KERN_SEMINFO: + SETNAME(semname); + break; + case KERN_SHMINFO: + SETNAME(shmname); + break; + case KERN_WATCHDOG: + SETNAME(watchdogname); + break; + case KERN_TIMECOUNTER: + SETNAME(tcname); + break; + } + } + break; + } + if (names != NULL && idx > 0 && idx < limit) + return (names[idx].ctl_name); + return (NULL); +} + static void ktrsysret(struct ktr_sysret *ktr) { |