=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/kdump/kdump.c,v retrieving revision 1.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- src/usr.bin/kdump/kdump.c 2011/07/19 18:20:11 1.61 +++ src/usr.bin/kdump/kdump.c 2011/07/28 10:33:36 1.62 @@ -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 #include #include +#include +#include #include +#include +#include #include #include #include #include +#include #include +#include #include #include #define _KERNEL #include #undef _KERNEL +#include +#include #include #include @@ -140,6 +148,7 @@ 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 @@ 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 = '.'; } @@ -823,6 +836,115 @@ narg--; } (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