Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/kdump *** empty log message ***



details:   https://anonhg.NetBSD.org/src/rev/ef42f90c342d
branches:  trunk
changeset: 746495:ef42f90c342d
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Apr 02 17:40:33 2020 +0000

description:
*** empty log message ***

diffstat:

 usr.bin/kdump/ioctlprint.1 |  15 ++++++-
 usr.bin/kdump/kdump.c      |  88 +++++++++++++++++++++++++++++++++++----------
 usr.bin/kdump/mkioctls     |  39 +++++++++++++++-----
 3 files changed, 110 insertions(+), 32 deletions(-)

diffs (300 lines):

diff -r d3faf8c4ea04 -r ef42f90c342d usr.bin/kdump/ioctlprint.1
--- a/usr.bin/kdump/ioctlprint.1        Thu Apr 02 16:31:37 2020 +0000
+++ b/usr.bin/kdump/ioctlprint.1        Thu Apr 02 17:40:33 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: ioctlprint.1,v 1.2 2020/04/02 08:38:22 wiz Exp $
+.\" $NetBSD: ioctlprint.1,v 1.3 2020/04/02 17:40:33 christos Exp $
 .\"
 .\" Copyright (c) 2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -35,6 +35,7 @@
 .Nd display descriptive ioctl value
 .Sh SYNOPSIS
 .Nm
+.Op Fl l
 .Op Fl e Ar emulation
 .Op Fl f Ar format
 .Op Ar arg ...
@@ -45,6 +46,10 @@
 to by one or more
 .Ar arg
 arguments.
+The argument can either be an
+.Xr ioctl
+symbolic name or the
+ioctl value.
 .Pp
 The options are as follows:
 .Bl -tag -width Fl
@@ -61,8 +66,10 @@
 .Pp
 The following conversion characters can be used:
 .Bl -tag -width xxxx
+.It \&%E
+Symbolic decoded ioctl string.
 .It \&%e
-Decoded ioctl string.
+Decoded ioctl string with hex values.
 .It \&%n
 Descriptive ioctl operation name.
 .It \&%x
@@ -77,6 +84,10 @@
 .Bd -literal -offset indent
 "%n %e %x\\n"
 .Ed
+.It Fl l
+List all 
+.Xr ioctl 2
+known.
 .El
 .Sh SEE ALSO
 .Xr kdump 1 ,
diff -r d3faf8c4ea04 -r ef42f90c342d usr.bin/kdump/kdump.c
--- a/usr.bin/kdump/kdump.c     Thu Apr 02 16:31:37 2020 +0000
+++ b/usr.bin/kdump/kdump.c     Thu Apr 02 17:40:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kdump.c,v 1.133 2020/04/02 03:32:46 kamil Exp $        */
+/*     $NetBSD: kdump.c,v 1.134 2020/04/02 17:40:33 christos 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.133 2020/04/02 03:32:46 kamil Exp $");
+__RCSID("$NetBSD: kdump.c,v 1.134 2020/04/02 17:40:33 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -108,9 +108,9 @@
        "PTRACE_SYSCALL",
 };
 
-static const char default_format[] = { "%n %e %x\n" };
+static const char default_format[] = { "%n\t%E\t%x\n" };
 
-static void    fmtprint(const char *, unsigned long int);
+static void    fmtprint(const char *, const struct ioctlinfo *ii);
 static int     fread_tail(void *, size_t, size_t);
 static int     dumpheader(struct ktr_header *);
 static int     output_ts(const struct timespec *);
@@ -132,11 +132,11 @@
 static const char *signame(long, int);
 static void hexdump_buf(const void *, int, int);
 static void visdump_buf(const void *, int, int);
+static const struct ioctlinfo *find_ioctl(const char *);
 
 int
 main(int argc, char **argv)
 {
-       unsigned long int u;
        unsigned int ktrlen, size;
        int ch;
        void *m;
@@ -145,15 +145,16 @@
        const char *emul_name = "netbsd";
        const char *format = default_format;
        int col;
-       int e;
        char *cp;
 
        setprogname(argv[0]);
 
        if (strcmp(getprogname(), "ioctlprint") == 0) {
+               const struct ioctlinfo *ii;
+               int list = 0;
                int i;
 
-               while ((ch = getopt(argc, argv, "e:f:")) != -1)
+               while ((ch = getopt(argc, argv, "e:f:l")) != -1)
                        switch (ch) {
                        case 'e':
                                emul_name = optarg;
@@ -163,22 +164,34 @@
                                        errx(1, "Too many formats");
                                format = optarg;
                                break;
+                       case 'l':
+                               list = 1;
+                               break;
                        default:
                                usage();
                                break;
                        }
+
                setemul(emul_name, 0, 0);
                argv += optind;
                argc -= optind;
 
-               if (argc < 1)
+               if (argc < 1 && !list)
                        usage();
 
+               if (list) {
+                       for (i = 0; ioctlinfo[i].name != NULL; i++) {
+                               fmtprint(format, &ioctlinfo[i]);
+                       }
+                       return 0;
+               }
+
                for (i = 0; i < argc; i++) {
-                       u = strtou(argv[i], NULL, 0, 0, ULONG_MAX, &e);
-                       if (e)
-                               errc(1, e, "invalid argument: `%s'", argv[i]);
-                       fmtprint(format, u);
+                       if ((ii = find_ioctl(argv[i])) == NULL) {
+                               warnx("Can't find ioctl `%s'", argv[i]);
+                               continue;
+                       }
+                       fmtprint(format, ii);
                }
                return 0;
        }
@@ -338,11 +351,11 @@
 }
 
 static void
-fmtprint(const char *fmt, unsigned long int u)
+fmtprint(const char *fmt, const struct ioctlinfo *ii)
 {
-       const char *name;
        int c;
 
+
        while ((c = *fmt++) != '\0') {
                switch (c) {
                default:
@@ -368,21 +381,23 @@
                        default:
                                putchar(c);
                                break;
+                       case 'E':
+                               printf("%s", ii->expr);
+                               break;
                        case 'e':
-                               ioctldecode(u);
+                               ioctldecode(ii->value);
                                break;
                        case 'n':
-                               name = ioctlname(u);
-                               printf("%s", name ? name : "(null)");
+                               printf("%s", ii->name);
                                break;
                        case 'x':
-                               printf("%#lx", u);
+                               printf("%#lx", ii->value);
                                break;
                        case 'o':
-                               printf("%#lo", u);
+                               printf("%#lo", ii->value);
                                break;
                        case 'd': case 'i':
-                               printf("%ld", u);
+                               printf("%ld", ii->value);
                                break;
                        }
                        break;
@@ -1313,3 +1328,36 @@
        }
        exit(1);
 }
+
+static const struct ioctlinfo *
+find_ioctl_by_name(const char *name)
+{
+       for (size_t i = 0; ioctlinfo[i].name != NULL; i++) {
+               if (strcmp(name, ioctlinfo[i].name) == 0)
+                       return &ioctlinfo[i];
+       }
+       return NULL;
+}
+
+static const struct ioctlinfo *
+find_ioctl_by_value(unsigned long value)
+{
+       for (size_t i = 0; ioctlinfo[i].name != NULL; i++) {
+               if (value == ioctlinfo[i].value)
+                       return &ioctlinfo[i];
+       }
+       return NULL;
+}
+
+static const struct ioctlinfo *
+find_ioctl(const char *name)
+{
+       if (isalpha((unsigned char)*name)) {
+               return find_ioctl_by_name(name);
+       }
+       int e;
+       unsigned long u = strtou(name, NULL, 0, 0, ULONG_MAX, &e);
+       if (e)
+               errc(1, e, "invalid argument: `%s'", name);
+       return find_ioctl_by_value(u);
+}
diff -r d3faf8c4ea04 -r ef42f90c342d usr.bin/kdump/mkioctls
--- a/usr.bin/kdump/mkioctls    Thu Apr 02 16:31:37 2020 +0000
+++ b/usr.bin/kdump/mkioctls    Thu Apr 02 17:40:33 2020 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-#      $NetBSD: mkioctls,v 1.53 2018/09/29 14:41:36 rmind Exp $
+#      $NetBSD: mkioctls,v 1.54 2020/04/02 17:40:33 christos Exp $
 #
 # Copyright (c) 1994
 #      The Regents of the University of California.  All rights reserved.
@@ -39,6 +39,9 @@
 : ${CC:=cc}
 : ${SED:=sed}
 
+set -x
+AWK=gawk
+
 echo "/* Automatically generated file, do not edit! */"
 #echo "#define const"  # XXX: timepps lossage
 echo "#define COMPAT_43"
@@ -198,20 +201,36 @@
                if ($i ~ /define/)
                        break;
        ++i;
-       printf("/* %s [%s] */\n", $0, $i);
+       name = $i;
+       printf("/* %s [%s] */\n", $0, name);
        # 
-       if ($i ~ /^[A-Z0-9a-z_]*$/) {
-               if (keep[$i] != 1) {
-                       printf("\t#ifdef %s\n", $i);
-                       printf("\tcase %s:\n\t\treturn \"%s\";\n", $i, $i);
-                       printf("\t#endif /* %s */\n", $i);
-                       keep[$i] = 1;
-               }
-       }
+       if (name !~ /^[A-Z0-9a-z_]*$/)
+               next;
+       if (keep[name] == 1)
+               next;
+       keep[name] = 1;
+       printf("\t#ifdef %s\n", name);
+       printf("\tcase %s:\n\t\treturn \"%s\";\n", name, name);
+       printf("\t#endif /* %s */\n", $i);
+       name = name;
+       names[name] = name;
+       exprs[name] = "";
+       files[name] = filename;
+       do {
+               ++i;
+               exprs[name] = exprs[name] " " $i;
+       } while ($i !~ /.*)/);
+       exprs[name] = substr(exprs[name], 2);
 }
 END {
        print "\tdefault:\n\t\treturn NULL;\n"
        print "\t}\n"
        print "}"
+       print "const struct ioctlinfo ioctlinfo[] = {\n";
+       for (name in names) {
+               printf("\t{ .name = \"%s\", .expr = \"%s\", .value = %s },\n",
+                   names[name], exprs[name], names[name]);
+       }
+       print "\t{ .name = NULL, .expr = NULL, .value = 0 },\n};";
 }
 '



Home | Main Index | Thread Index | Old Index