From: otto Date: Sun, 16 Apr 2023 19:42:40 +0000 (+0000) Subject: Add a -u label option to print selected utrace records, used by upcoming X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c5cd0970df1a93c42bfd1d783c28aef14a26e915;p=openbsd Add a -u label option to print selected utrace records, used by upcoming malloc (leak) dump fucntion. ok semarie@ --- diff --git a/usr.bin/kdump/kdump.1 b/usr.bin/kdump/kdump.1 index bbf53a51892..bd26fcfa015 100644 --- a/usr.bin/kdump/kdump.1 +++ b/usr.bin/kdump/kdump.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kdump.1,v 1.35 2022/07/30 07:19:30 jsg Exp $ +.\" $OpenBSD: kdump.1,v 1.36 2023/04/16 19:42:40 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 30 2022 $ +.Dd $Mdocdate: April 16 2023 $ .Dt KDUMP 1 .Os .Sh NAME @@ -42,6 +42,7 @@ .Op Fl m Ar maxdata .Op Fl p Ar pid .Op Fl t Ar trstr +.Op Fl u Ar label .Sh DESCRIPTION .Nm displays the kernel trace files produced with @@ -106,12 +107,31 @@ See the option of .Xr ktrace 1 for the meaning of the letters. +.It Fl u Ar label +Display +.Xr utrace 2 +tracepoints having +.XR utrace 2 +label +.Ar label +as strings with +.Xr vis 3 +escaping, without +.Xr ktrace 2 +header information. .It Fl X Display I/O data with hexadecimal data and printable ASCII characters side by side. .It Fl x Display I/O data in hexadecimal. .El +.Pp +The +.Fl t +and +.Fl u +options are mutually exclusive, +the last one specified overrides any previous ones. .Sh FILES .Bl -tag -width ktrace.out -compact .It Pa ktrace.out diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 86a68f0992c..6b1c118cdcd 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kdump.c,v 1.156 2023/02/17 18:01:26 deraadt Exp $ */ +/* $OpenBSD: kdump.c,v 1.157 2023/04/16 19:42:40 otto Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -88,6 +88,7 @@ int needtid, tail, basecol; char *tracefile = DEF_TRACEFILE; struct ktr_header ktr_header; pid_t pid_opt = -1; +char* utracefilter; #define eqs(s1, s2) (strcmp((s1), (s2)) == 0) @@ -168,7 +169,7 @@ main(int argc, char *argv[]) screenwidth = 80; } - while ((ch = getopt(argc, argv, "f:dHlm:np:RTt:xX")) != -1) + while ((ch = getopt(argc, argv, "f:dHlm:np:RTt:u:xX")) != -1) switch (ch) { case 'f': tracefile = optarg; @@ -211,6 +212,11 @@ main(int argc, char *argv[]) trpoints = getpoints(optarg, DEF_POINTS); if (trpoints < 0) errx(1, "unknown trace point in %s", optarg); + utracefilter = NULL; + break; + case 'u': + utracefilter = optarg; + trpoints = KTRFAC_USER; break; case 'x': iohex = 1; @@ -246,7 +252,8 @@ main(int argc, char *argv[]) silent = 0; if (pid_opt != -1 && pid_opt != ktr_header.ktr_pid) silent = 1; - if (silent == 0 && trpoints & (1< size) { @@ -1254,10 +1261,16 @@ showbufc(int col, unsigned char *dp, size_t datalen, int flags) static void showbuf(unsigned char *dp, size_t datalen) { - int i, j; + size_t i, j; int col = 0, bpl; unsigned char c; + char visbuf[4 * KTR_USER_MAXLEN + 1]; + if (utracefilter != NULL) { + strvisx(visbuf, dp, datalen, VIS_SAFE | VIS_OCTAL); + printf("%s", visbuf); + return; + } if (iohex == 1) { putchar('\t'); col = 8; @@ -1280,7 +1293,7 @@ showbuf(unsigned char *dp, size_t datalen) if (bpl <= 0) bpl = 1; for (i = 0; i < datalen; i += bpl) { - printf(" %04x: ", i); + printf(" %04zx: ", i); for (j = 0; j < bpl; j++) { if (i+j >= datalen) printf(" "); @@ -1413,9 +1426,12 @@ ktruser(struct ktr_user *usr, size_t len) if (len < sizeof(struct ktr_user)) errx(1, "invalid ktr user length %zu", len); len -= sizeof(struct ktr_user); - printf("%.*s:", KTR_USER_MAXIDLEN, usr->ktr_id); - printf(" %zu bytes\n", len); - showbuf((unsigned char *)(usr + 1), len); + if (utracefilter == NULL) { + printf("%.*s:", KTR_USER_MAXIDLEN, usr->ktr_id); + printf(" %zu bytes\n", len); + showbuf((unsigned char *)(usr + 1), len); + } else if (strncmp(usr->ktr_id, utracefilter, KTR_USER_MAXIDLEN) == 0) + showbuf((unsigned char *)(usr + 1), len); } static void @@ -1473,8 +1489,8 @@ usage(void) extern char *__progname; fprintf(stderr, "usage: %s " - "[-dHlnRTXx] [-f file] [-m maxdata] [-p pid] [-t trstr]\n", - __progname); + "[-dHlnRTXx] [-f file] [-m maxdata] [-p pid] [-t trstr] " + "[-u label]\n", __progname); exit(1); }