summaryrefslogtreecommitdiffstats
path: root/usr.bin/kdump/kdump.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/kdump/kdump.c')
-rw-r--r--usr.bin/kdump/kdump.c125
1 files changed, 53 insertions, 72 deletions
diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index 988bbbc..5a1f279 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -38,7 +38,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)kdump.c 8.1 (Berkeley) 6/6/93";
+static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95";
#endif /* not lint */
#include <sys/param.h>
@@ -51,10 +51,15 @@ static char sccsid[] = "@(#)kdump.c 8.1 (Berkeley) 6/6/93";
#define KERNEL
#include <sys/errno.h>
#undef KERNEL
-#include <vis.h>
+
+#include <err.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <vis.h>
+
#include "ktrace.h"
int timestamp, decimal, fancy = 1, tail, maxdata;
@@ -63,18 +68,17 @@ struct ktr_header ktr_header;
#define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
+int
main(argc, argv)
int argc;
char *argv[];
{
- extern int optind;
- extern char *optarg;
int ch, ktrlen, size;
register void *m;
int trpoints = ALL_POINTS;
- while ((ch = getopt(argc,argv,"f:dlm:nRTt:")) != EOF)
- switch((char)ch) {
+ while ((ch = getopt(argc, argv, "f:dlm:nRTt:")) != -1)
+ switch (ch) {
case 'f':
tracefile = optarg;
break;
@@ -98,12 +102,8 @@ main(argc, argv)
break;
case 't':
trpoints = getpoints(optarg);
- if (trpoints < 0) {
- (void)fprintf(stderr,
- "kdump: unknown trace point in %s\n",
- optarg);
- exit(1);
- }
+ if (trpoints < 0)
+ errx(1, "unknown trace point in %s", optarg);
break;
default:
usage();
@@ -115,36 +115,23 @@ main(argc, argv)
usage();
m = (void *)malloc(size = 1025);
- if (m == NULL) {
- (void)fprintf(stderr, "kdump: %s.\n", strerror(ENOMEM));
- exit(1);
- }
- if (!freopen(tracefile, "r", stdin)) {
- (void)fprintf(stderr,
- "kdump: %s: %s.\n", tracefile, strerror(errno));
- exit(1);
- }
+ if (m == NULL)
+ errx(1, "%s", strerror(ENOMEM));
+ if (!freopen(tracefile, "r", stdin))
+ err(1, "%s", tracefile);
while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
if (trpoints & (1<<ktr_header.ktr_type))
dumpheader(&ktr_header);
- if ((ktrlen = ktr_header.ktr_len) < 0) {
- (void)fprintf(stderr,
- "kdump: bogus length 0x%x\n", ktrlen);
- exit(1);
- }
+ if ((ktrlen = ktr_header.ktr_len) < 0)
+ errx(1, "bogus length 0x%x", ktrlen);
if (ktrlen > size) {
m = (void *)realloc(m, ktrlen+1);
- if (m == NULL) {
- (void)fprintf(stderr,
- "kdump: %s.\n", strerror(ENOMEM));
- exit(1);
- }
+ if (m == NULL)
+ errx(1, "%s", strerror(ENOMEM));
size = ktrlen;
}
- if (ktrlen && fread_tail(m, ktrlen, 1) == 0) {
- (void)fprintf(stderr, "kdump: data too short.\n");
- exit(1);
- }
+ if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
+ errx(1, "data too short");
if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
continue;
switch (ktr_header.ktr_type) {
@@ -244,55 +231,58 @@ static char *ptrace_ops[] = {
ktrsyscall(ktr)
register struct ktr_syscall *ktr;
{
- register narg = ktr->ktr_narg;
- register int *ip;
+ register argsize = ktr->ktr_argsize;
+ register register_t *ap;
char *ioctlname();
if (ktr->ktr_code >= nsyscalls || ktr->ktr_code < 0)
(void)printf("[%d]", ktr->ktr_code);
else
(void)printf("%s", syscallnames[ktr->ktr_code]);
- ip = (int *)((char *)ktr + sizeof(struct ktr_syscall));
- if (narg) {
+ ap = (register_t *)((char *)ktr + sizeof(struct ktr_syscall));
+ if (argsize) {
char c = '(';
if (fancy) {
if (ktr->ktr_code == SYS_ioctl) {
char *cp;
if (decimal)
- (void)printf("(%d", *ip);
+ (void)printf("(%ld", (long)*ap);
else
- (void)printf("(%#x", *ip);
- ip++;
- narg--;
- if ((cp = ioctlname(*ip)) != NULL)
+ (void)printf("(%#lx", (long)*ap);
+ ap++;
+ argsize -= sizeof(register_t);
+ if ((cp = ioctlname(*ap)) != NULL)
(void)printf(",%s", cp);
else {
if (decimal)
- (void)printf(",%d", *ip);
+ (void)printf(",%ld",
+ (long)*ap);
else
- (void)printf(",%#x ", *ip);
+ (void)printf(",%#lx ",
+ (long)*ap);
}
c = ',';
- ip++;
- narg--;
+ ap++;
+ argsize -= sizeof(register_t);
} else if (ktr->ktr_code == SYS_ptrace) {
- if (*ip <= PT_STEP && *ip >= 0)
- (void)printf("(%s", ptrace_ops[*ip]);
+ if (*ap >= 0 && *ap <=
+ sizeof(ptrace_ops) / sizeof(ptrace_ops[0]))
+ (void)printf("(%s", ptrace_ops[*ap]);
else
- (void)printf("(%d", *ip);
+ (void)printf("(%ld", (long)*ap);
c = ',';
- ip++;
- narg--;
+ ap++;
+ argsize -= sizeof(register_t);
}
}
- while (narg) {
+ while (argsize) {
if (decimal)
- (void)printf("%c%d", c, *ip);
+ (void)printf("%c%ld", c, (long)*ap);
else
- (void)printf("%c%#x", c, *ip);
+ (void)printf("%c%#lx", c, (long)*ap);
c = ',';
- ip++;
- narg--;
+ ap++;
+ argsize -= sizeof(register_t);
}
(void)putchar(')');
}
@@ -366,7 +356,7 @@ ktrgenio(ktr, len)
datalen = maxdata;
(void)printf(" \"");
col = 8;
- for (;datalen > 0; datalen--, dp++) {
+ for (; datalen > 0; datalen--, dp++) {
(void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
cp = visbuf;
/*
@@ -402,31 +392,22 @@ ktrgenio(ktr, len)
(void)printf("\"\n");
}
-char *signames[] = {
- "NULL", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", /* 1 - 6 */
- "EMT", "FPE", "KILL", "BUS", "SEGV", "SYS", /* 7 - 12 */
- "PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", /* 13 - 18 */
- "CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU", /* 19 - 24 */
- "XFSZ", "VTALRM", "PROF", "WINCH", "29", "USR1", /* 25 - 30 */
- "USR2", NULL, /* 31 - 32 */
-};
-
ktrpsig(psig)
struct ktr_psig *psig;
{
- (void)printf("SIG%s ", signames[psig->signo]);
+ (void)printf("SIG%s ", sys_signame[psig->signo]);
if (psig->action == SIG_DFL)
(void)printf("SIG_DFL\n");
else
- (void)printf("caught handler=0x%x mask=0x%x code=0x%x\n",
- (u_int)psig->action, psig->mask, psig->code);
+ (void)printf("caught handler=0x%lx mask=0x%x code=0x%x\n",
+ (u_long)psig->action, psig->mask, psig->code);
}
ktrcsw(cs)
struct ktr_csw *cs;
{
(void)printf("%s %s\n", cs->out ? "stop" : "resume",
- cs->user ? "user" : "kernel");
+ cs->user ? "user" : "kernel");
}
usage()
OpenPOWER on IntegriCloud