PERFORCE change 32321 for review
Peter Wemm
peter at FreeBSD.org
Sun Jun 1 13:45:26 PDT 2003
http://perforce.freebsd.org/chv.cgi?CH=32321
Change 32321 by peter at peter_daintree on 2003/06/01 13:45:03
GRRR! I'm sick of kdump being so lousy. add a -p pid argument so
kdump can single out a particular pid from a ktrace -i dump.
hexdump the binary genio data instead of strvis. strvis for
binary sucks.
Affected files ...
.. //depot/projects/hammer/usr.bin/kdump/kdump.c#3 edit
Differences ...
==== //depot/projects/hammer/usr.bin/kdump/kdump.c#3 (text+ko) ====
@@ -72,6 +72,7 @@
void ktrsyscall(struct ktr_syscall *);
void ktrsysret(struct ktr_sysret *);
void ktrnamei(char *, int);
+void hd(void *, int);
void ktrgenio(struct ktr_genio *, int);
void ktrpsig(struct ktr_psig *);
void ktrcsw(struct ktr_csw *);
@@ -91,10 +92,11 @@
void *m;
int trpoints = ALL_POINTS;
int drop_logged;
+ pid_t pid = 0;
(void) setlocale(LC_CTYPE, "");
- while ((ch = getopt(argc,argv,"f:dlm:nRTt:")) != -1)
+ while ((ch = getopt(argc,argv,"f:dlm:np:RTt:")) != -1)
switch((char)ch) {
case 'f':
tracefile = optarg;
@@ -111,6 +113,9 @@
case 'n':
fancy = 0;
break;
+ case 'p':
+ pid = atoi(optarg);
+ break;
case 'R':
timestamp = 2; /* relative timestamp */
break;
@@ -146,7 +151,8 @@
}
}
if (trpoints & (1<<ktr_header.ktr_type))
- dumpheader(&ktr_header);
+ if (pid == 0 || ktr_header.ktr_pid == pid)
+ dumpheader(&ktr_header);
if ((ktrlen = ktr_header.ktr_len) < 0)
errx(1, "bogus length 0x%x", ktrlen);
if (ktrlen > size) {
@@ -157,6 +163,8 @@
}
if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
errx(1, "data too short");
+ if (pid && ktr_header.ktr_pid != pid)
+ continue;
if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
continue;
drop_logged = 0;
@@ -388,6 +396,42 @@
}
void
+hd(void *buf, int len)
+{
+ unsigned char *p;
+ int n, i;
+
+ p = buf;
+ for (n = 0; n < len; n += 16) {
+ for (i = n; i < n + 16; i++) {
+ if ((i % 16) == 0) { /* beginning of line */
+ printf(" 0x%04x\t", i);
+ }
+ if ((i % 2) == 0) {
+ printf(" ");
+ }
+ if (i < len)
+ printf("%02x", p[i]);
+ else
+ printf(" ");
+ }
+ printf("\t");
+ for (i = n; i < n + 16; i++) {
+ if (i >= len)
+ break;
+ if (p[i] >= ' ' && p[i] <= '~')
+ printf("%c", p[i]);
+ else
+ printf(".");
+ }
+ printf("\n");
+ }
+ if ((i % 16) != 0) {
+ printf("\n");
+ }
+}
+
+void
ktrgenio(struct ktr_genio *ktr, int len)
{
int datalen = len - sizeof (struct ktr_genio);
@@ -397,6 +441,7 @@
int width;
char visbuf[5];
static int screenwidth = 0;
+ int i, binary;
if (screenwidth == 0) {
struct winsize ws;
@@ -412,42 +457,54 @@
datalen == 1 ? "" : "s");
if (maxdata && datalen > maxdata)
datalen = maxdata;
- (void)printf(" \"");
- col = 8;
- for (;datalen > 0; datalen--, dp++) {
- (void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
- cp = visbuf;
- /*
- * Keep track of printables and
- * space chars (like fold(1)).
- */
- if (col == 0) {
- (void)putchar('\t');
- col = 8;
- }
- switch(*cp) {
- case '\n':
- col = 0;
- (void)putchar('\n');
+
+ for (i = 0, binary = 0; i < datalen && binary == 0; i++) {
+ if (dp[i] >= 32 && dp[i] < 127)
+ continue;
+ if (dp[i] == 10 || dp[i] == 13 || dp[i] == 0 || dp[i] == 9)
continue;
- case '\t':
- width = 8 - (col&07);
- break;
- default:
- width = strlen(cp);
+ binary = 1;
+ }
+ if (binary) {
+ hd(dp, datalen);
+ } else {
+ (void)printf(" \"");
+ col = 8;
+ for (;datalen > 0; datalen--, dp++) {
+ (void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
+ cp = visbuf;
+ /*
+ * Keep track of printables and
+ * space chars (like fold(1)).
+ */
+ if (col == 0) {
+ (void)putchar('\t');
+ col = 8;
+ }
+ switch(*cp) {
+ case '\n':
+ col = 0;
+ (void)putchar('\n');
+ continue;
+ case '\t':
+ width = 8 - (col&07);
+ break;
+ default:
+ width = strlen(cp);
+ }
+ if (col + width > (screenwidth-2)) {
+ (void)printf("\\\n\t");
+ col = 8;
+ }
+ col += width;
+ do {
+ (void)putchar(*cp++);
+ } while (*cp);
}
- if (col + width > (screenwidth-2)) {
- (void)printf("\\\n\t");
- col = 8;
- }
- col += width;
- do {
- (void)putchar(*cp++);
- } while (*cp);
+ if (col == 0)
+ (void)printf(" ");
+ (void)printf("\"\n");
}
- if (col == 0)
- (void)printf(" ");
- (void)printf("\"\n");
}
const char *signames[] = {
More information about the p4-projects
mailing list