Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/kdump Add ioctlprint - descriptive ioctl value printer



details:   https://anonhg.NetBSD.org/src/rev/6b81cd15dde7
branches:  trunk
changeset: 970701:6b81cd15dde7
user:      kamil <kamil%NetBSD.org@localhost>
date:      Thu Apr 02 03:32:46 2020 +0000

description:
Add ioctlprint - descriptive ioctl value printer

ioctlprint(1) is embedded in the kdump(1) program.

diffstat:

 distrib/sets/lists/base/mi |   3 +-
 distrib/sets/lists/man/mi  |   5 ++-
 usr.bin/kdump/Makefile     |   4 +-
 usr.bin/kdump/ioctlprint.1 |  89 ++++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/kdump/kdump.c      |  84 +++++++++++++++++++++++++++++++++++++++----
 5 files changed, 174 insertions(+), 11 deletions(-)

diffs (truncated from 318 to 300 lines):

diff -r 2f85c471b491 -r 6b81cd15dde7 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Thu Apr 02 00:00:16 2020 +0000
+++ b/distrib/sets/lists/base/mi        Thu Apr 02 03:32:46 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1235 2020/03/29 17:13:46 christos Exp $
+# $NetBSD: mi,v 1.1236 2020/04/02 03:32:46 kamil Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -797,6 +797,7 @@
 ./usr/bin/install                              base-util-bin
 ./usr/bin/install-info                         base-texinfo-bin
 ./usr/bin/install-sid                          base-gnats-bin
+./usr/bin/ioctlprint                           base-debug-bin
 ./usr/bin/ipcrm                                        base-util-bin
 ./usr/bin/ipcs                                 base-util-bin
 ./usr/bin/join                                 base-util-bin
diff -r 2f85c471b491 -r 6b81cd15dde7 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Thu Apr 02 00:00:16 2020 +0000
+++ b/distrib/sets/lists/man/mi Thu Apr 02 03:32:46 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1684 2020/03/29 17:13:46 christos Exp $
+# $NetBSD: mi,v 1.1685 2020/04/02 03:32:46 kamil Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -226,6 +226,7 @@
 ./usr/share/man/cat1/install-info.0            man-texinfo-catman      .cat
 ./usr/share/man/cat1/install.0                 man-util-catman         .cat
 ./usr/share/man/cat1/intro.0                   man-sys-catman          .cat
+./usr/share/man/cat1/ioctlprint.0              man-debug-catman        .cat
 ./usr/share/man/cat1/ipcrm.0                   man-util-catman         .cat
 ./usr/share/man/cat1/ipcs.0                    man-util-catman         .cat
 ./usr/share/man/cat1/ipftest.0                 man-ipf-catman          ipfilter,.cat
@@ -3512,6 +3513,7 @@
 ./usr/share/man/html1/install-info.html                man-texinfo-htmlman     html
 ./usr/share/man/html1/install.html             man-util-htmlman        html
 ./usr/share/man/html1/intro.html               man-sys-htmlman         html
+./usr/share/man/html1/ioctlprint.html          man-debug-htmlman       html
 ./usr/share/man/html1/ipcrm.html               man-util-htmlman        html
 ./usr/share/man/html1/ipcs.html                        man-util-htmlman        html
 ./usr/share/man/html1/ipftest.html             man-ipf-htmlman         ipfilter,html
@@ -6436,6 +6438,7 @@
 ./usr/share/man/man1/install-info.1            man-texinfo-man         .man
 ./usr/share/man/man1/install.1                 man-util-man            .man
 ./usr/share/man/man1/intro.1                   man-sys-man             .man
+./usr/share/man/man1/ioctlprint.1              man-debug-man           .man
 ./usr/share/man/man1/ipcrm.1                   man-util-man            .man
 ./usr/share/man/man1/ipcs.1                    man-util-man            .man
 ./usr/share/man/man1/ipftest.1                 man-ipf-man             ipfilter,.man
diff -r 2f85c471b491 -r 6b81cd15dde7 usr.bin/kdump/Makefile
--- a/usr.bin/kdump/Makefile    Thu Apr 02 00:00:16 2020 +0000
+++ b/usr.bin/kdump/Makefile    Thu Apr 02 03:32:46 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.32 2016/01/23 21:22:49 christos Exp $
+#      $NetBSD: Makefile,v 1.33 2020/04/02 03:32:46 kamil Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 .include <bsd.own.mk>          # for MKDYNAMICROOT & NETBSDSRCDIR
@@ -6,6 +6,8 @@
 USE_FORT?= yes # cryptographic software
 
 PROG=  kdump
+LINKS= ${BINDIR}/kdump ${BINDIR}/ioctlprint
+MAN=   kdump.1 ioctlprint.1
 SRCS=  kdump.c subr.c setemul.c siginfo.c
 .PATH: ${NETBSDSRCDIR}/usr.bin/ktrace
 CLEANFILES+=siginfo.c
diff -r 2f85c471b491 -r 6b81cd15dde7 usr.bin/kdump/ioctlprint.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/kdump/ioctlprint.1        Thu Apr 02 03:32:46 2020 +0000
@@ -0,0 +1,89 @@
+.\"
+.\" Copyright (c) 2020 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Kamil Rytarowski.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 2, 2020
+.Dt IOCTLPRINT 1
+.Os
+.Sh NAME
+.Nm ioctlprint
+.Nd display descriptive ioctl value
+.Sh SYNOPSIS
+.Nm
+.Op Fl e Ar emulation
+.Op Fl f Ar format
+.Op Ar arg ...
+.Sh DESCRIPTION
+The
+.Nm
+utility displays information about the file ioctl operation pointed to by one or more
+.Ar arg
+arguments.
+.Pp
+The options are as follows:
+.Bl -tag -width Fl
+.It Fl e Ar emulation
+If an emulation of a process is unknown,
+interpret system call maps assuming the named emulation instead of
+default "netbsd".
+.It Fl f Ar format
+The argument is a
+.Xr printf 3
+style format string that allows customization of
+.Nm ioctlprint Ns 's
+output.
+.Pp
+The following conversion characters can be used:
+.Bl -tag -width xxxx
+.It \&%e
+Decoded ioctl string.
+.It \&%n
+Descriptive ioctl operation name.
+.It \&%x
+Hexadecimal ioctl number.
+.It \&%o
+Octal ioctl number.
+.It \&%d or \&%i
+Decimal ioctl number.
+.El
+.Pp
+The default format is:
+.Bd -literal -offset indent
+"%n %e %x\\n"
+.Ed
+.El
+.Pp
+.Sh SEE ALSO
+.Xr kdump 1
+.Xr ktrace 1
+.Sh HISTORY
+The
+.Nm
+command first appeared in
+.Nx 10 .
+.Sh AUTHORS
+.An Kamil Rytarowski Aq Mt kamil%NetBSD.org@localhost
diff -r 2f85c471b491 -r 6b81cd15dde7 usr.bin/kdump/kdump.c
--- a/usr.bin/kdump/kdump.c     Thu Apr 02 00:00:16 2020 +0000
+++ b/usr.bin/kdump/kdump.c     Thu Apr 02 03:32:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kdump.c,v 1.132 2019/07/23 01:54:51 nonaka Exp $       */
+/*     $NetBSD: kdump.c,v 1.133 2020/04/02 03:32:46 kamil Exp $        */
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)kdump.c    8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: kdump.c,v 1.132 2019/07/23 01:54:51 nonaka Exp $");
+__RCSID("$NetBSD: kdump.c,v 1.133 2020/04/02 03:32:46 kamil Exp $");
 #endif
 #endif /* not lint */
 
@@ -58,6 +58,7 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <inttypes.h>
 #include <signal.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -107,6 +108,9 @@
        "PTRACE_SYSCALL",
 };
 
+static const char default_format[] = { "%n %e %x\n" };
+
+static void    fmtprint(const char *, unsigned long int);
 static int     fread_tail(void *, size_t, size_t);
 static int     dumpheader(struct ktr_header *);
 static int     output_ts(const struct timespec *);
@@ -132,25 +136,33 @@
 int
 main(int argc, char **argv)
 {
+       unsigned long int u;
        unsigned int ktrlen, size;
        int ch;
        void *m;
        int trpoints = 0;
        int trset = 0;
        const char *emul_name = "netbsd";
+       const char *format = default_format;
        int col;
+       int e;
        char *cp;
 
        setprogname(argv[0]);
 
-       if (strcmp(getprogname(), "ioctlname") == 0) {
+       if (strcmp(getprogname(), "ioctlprint") == 0) {
                int i;
 
-               while ((ch = getopt(argc, argv, "e:")) != -1)
+               while ((ch = getopt(argc, argv, "e:f:")) != -1)
                        switch (ch) {
                        case 'e':
                                emul_name = optarg;
                                break;
+                       case 'f':
+                               if (format != default_format)
+                                       errx(1, "Too many formats");
+                               format = optarg;
+                               break;
                        default:
                                usage();
                                break;
@@ -163,8 +175,10 @@
                        usage();
 
                for (i = 0; i < argc; i++) {
-                       ioctldecode(strtoul(argv[i], NULL, 0));
-                       (void)putchar('\n');
+                       u = strtou(argv[i], NULL, 0, 0, ULONG_MAX, &e);
+                       if (e)
+                               errc(1, e, "invalid argument: `%s'", argv[i]);
+                       fmtprint(format, u);
                }
                return 0;
        }
@@ -323,6 +337,60 @@
        return (0);
 }
 
+static void
+fmtprint(const char *fmt, unsigned long int u)
+{
+       const char *name;
+       int c;
+
+       while ((c = *fmt++) != '\0') {
+               switch (c) {
+               default:
+                       putchar(c);
+                       continue;
+               case '\\':
+                       switch (c = *fmt) {
+                               case '\0':
+                               continue;
+                       case 'n':
+                               putchar('\n');
+                               break;
+                       case 't':
+                               putchar('\t');
+                               break;
+                       }
+                       break;
+               case '%':
+                       switch (c = *fmt) {
+                       case '\0':
+                               continue;
+                       case '%':
+                       default:
+                               putchar(c);
+                               break;
+                       case 'e':
+                               ioctldecode(u);
+                               break;
+                       case 'n':
+                               name = ioctlname(u);
+                               printf("%s", name ? name : "(null)");
+                               break;
+                       case 'x':
+                               printf("%#lx", u);
+                               break;
+                       case 'o':
+                               printf("%#lo", u);
+                               break;
+                       case 'd': case 'i':
+                               printf("%ld", u);
+                               break;
+                       }
+                       break;
+               }



Home | Main Index | Thread Index | Old Index