diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2006-05-11 06:49:01 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2006-05-11 06:49:01 +0000 |
commit | c174d78098019849c8b9721c1bbbc40a719b99ce (patch) | |
tree | d5a06c7643a9e7b4886e19a7f2d81755251cf6ad /usr.bin/kdump | |
parent | 9142cb7a1c033802c17868effae75807e5be727d (diff) |
-x and -X options to print io output in hex. from cedric berger
ok mickey
Diffstat (limited to 'usr.bin/kdump')
-rw-r--r-- | usr.bin/kdump/kdump.1 | 6 | ||||
-rw-r--r-- | usr.bin/kdump/kdump.c | 68 |
2 files changed, 64 insertions, 10 deletions
diff --git a/usr.bin/kdump/kdump.1 b/usr.bin/kdump/kdump.1 index b3faf553f1a..f651d4dcc20 100644 --- a/usr.bin/kdump/kdump.1 +++ b/usr.bin/kdump/kdump.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kdump.1,v 1.12 2003/09/03 12:12:47 jmc Exp $ +.\" $OpenBSD: kdump.1,v 1.13 2006/05/11 06:49:00 tedu Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -104,6 +104,10 @@ Selects which tracepoints to display. See the option of .Xr ktrace 1 for the definitions of the flags. +.It Fl x +Display I/O data in hexadecimal. +.It Fl X +Display I/O data with hexadecimal data and printable ASCII characters side by side. .El .Sh FILES .Bl -tag -width ktrace.out -compact diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 5ce9b5eed87..47b4e0fb5fd 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kdump.c,v 1.30 2005/12/31 20:56:37 miod Exp $ */ +/* $OpenBSD: kdump.c,v 1.31 2006/05/11 06:49:00 tedu Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95"; #endif -static char *rcsid = "$OpenBSD: kdump.c,v 1.30 2005/12/31 20:56:37 miod Exp $"; +static char *rcsid = "$OpenBSD: kdump.c,v 1.31 2006/05/11 06:49:00 tedu Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -65,7 +65,7 @@ static char *rcsid = "$OpenBSD: kdump.c,v 1.30 2005/12/31 20:56:37 miod Exp $"; #include "kdump.h" #include "extern.h" -int timestamp, decimal, fancy = 1, tail, maxdata; +int timestamp, decimal, iohex, fancy = 1, tail, maxdata; char *tracefile = DEF_TRACEFILE; struct ktr_header ktr_header; pid_t pid = -1; @@ -173,7 +173,7 @@ main(int argc, char *argv[]) current = &emulations[0]; /* native */ - while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:")) != -1) + while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:xX")) != -1) switch (ch) { case 'e': setemul(optarg); @@ -207,6 +207,12 @@ main(int argc, char *argv[]) if (trpoints < 0) errx(1, "unknown trace point in %s", optarg); break; + case 'x': + iohex = 1; + break; + case 'X': + iohex = 2; + break; default: usage(); } @@ -512,10 +518,10 @@ static void ktrgenio(struct ktr_genio *ktr, int len) { char *dp = (char *)ktr + sizeof (struct ktr_genio); - int datalen = len - sizeof (struct ktr_genio); + int i, j, datalen = len - sizeof (struct ktr_genio); static int screenwidth = 0; - int col = 0, width; - char visbuf[5], *cp; + int col = 0, width, bpl; + char visbuf[5], *cp, c; if (screenwidth == 0) { struct winsize ws; @@ -530,10 +536,54 @@ ktrgenio(struct ktr_genio *ktr, int len) ktr->ktr_rw == UIO_READ ? "read" : "wrote", datalen); if (maxdata && datalen > maxdata) datalen = maxdata; + if (iohex && !datalen) + return; + if (iohex == 1) { + putchar('\t'); + col = 8; + for (i = 0; i < datalen; i++) { + printf("%02x", dp[i] & 0xff); + col += 3; + if (i < datalen - 1) { + if (col + 3 > screenwidth) { + printf("\n\t"); + col = 8; + } else + putchar(' '); + } + } + putchar('\n'); + return; + } + if (iohex == 2) { + bpl = (screenwidth - 13)/4; + if (bpl <= 0) + bpl = 1; + for (i = 0; i < datalen; i += bpl) { + printf(" %04x: ", i); + for (j = 0; j < bpl; j++) { + if (i+j >= datalen) + printf(" "); + else + printf("%02x ", dp[i+j] & 0xff); + } + putchar(' '); + for (j = 0; j < bpl; j++) { + if (i+j >= datalen) + break; + c = dp[i+j]; + if (!isprint(c)) + c = '.'; + putchar(c); + } + putchar('\n'); + } + return; + } (void)printf(" \""); col = 8; for (; datalen > 0; datalen--, dp++) { - (void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1)); + (void)vis(visbuf, *dp, VIS_CSTYLE, *(dp+1)); cp = visbuf; /* @@ -605,7 +655,7 @@ usage(void) extern char *__progname; fprintf(stderr, "usage: %s " - "[-dnlRT] [-e emulation] [-p pid] [-f trfile] [-m maxdata] " + "[-dnlRTxX] [-e emulation] [-p pid] [-f trfile] [-m maxdata] " "[-t [ceinsw]]\n", __progname); exit(1); } |