Author: jhb
Date: Tue Dec 22 20:33:49 2015
New Revision: 292622
URL: https://svnweb.freebsd.org/changeset/base/292622

Log:
  Move the mkioctls script to libsysdecode and use it to generate a
  sysdecode_ioctlname() function.  This function matches the behavior
  of the truss variant in that it returns a pointer to a string description
  for known ioctls.  The caller is responsible for displaying unknown
  ioctl requests.  For kdump this meant moving the logic to handle unknown
  ioctl requests out of the generated function and into an ioctlname()
  function in kdump.c instead.
  
  Differential Revision:        https://reviews.freebsd.org/D4610

Added:
  head/lib/libsysdecode/mkioctls
     - copied, changed from r292620, head/usr.bin/kdump/mkioctls
  head/lib/libsysdecode/sysdecode_ioctlname.3   (contents, props changed)
Deleted:
  head/usr.bin/kdump/mkioctls
Modified:
  head/lib/libsysdecode/Makefile
  head/lib/libsysdecode/sysdecode.3
  head/lib/libsysdecode/sysdecode.h
  head/usr.bin/kdump/Makefile
  head/usr.bin/kdump/kdump.c
  head/usr.bin/truss/Makefile
  head/usr.bin/truss/syscalls.c

Modified: head/lib/libsysdecode/Makefile
==============================================================================
--- head/lib/libsysdecode/Makefile      Tue Dec 22 20:22:17 2015        
(r292621)
+++ head/lib/libsysdecode/Makefile      Tue Dec 22 20:33:49 2015        
(r292622)
@@ -4,10 +4,31 @@
 
 LIB=   sysdecode
 
-SRCS=  utrace.c
+SRCS=  ioctl.c utrace.c
 INCS=  sysdecode.h
 
 MAN+=  sysdecode.3 \
+       sysdecode_ioctlname.3 \
        sysdecode_utrace.3
 
+CLEANFILES= ioctl.c
+
+.if defined(COMPAT_32BIT)
+CPP+=  -m32
+.endif
+
+.if ${MK_PF} != "no"
+CFLAGS+=-DPF
+.endif
+
+# Workaround duplicate declarations in <netinet/ip_compat.h>
+CFLAGS.gcc.ioctl.c+= -Wno-redundant-decls
+CFLAGS.gcc+=   ${CFLAGS.gcc.${.IMPSRC}}
+
+ioctl.c: mkioctls
+       env MACHINE=${MACHINE} CPP="${CPP}" \
+               /bin/sh ${.CURDIR}/mkioctls ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
+
+beforedepend: ioctl.c
+
 .include <bsd.lib.mk>

Copied and modified: head/lib/libsysdecode/mkioctls (from r292620, 
head/usr.bin/kdump/mkioctls)
==============================================================================
--- head/usr.bin/kdump/mkioctls Tue Dec 22 20:12:52 2015        (r292620, copy 
source)
+++ head/lib/libsysdecode/mkioctls      Tue Dec 22 20:33:49 2015        
(r292622)
@@ -1,19 +1,15 @@
 #!/bin/sh
 #
 # $FreeBSD$
-#
-# When editing this script, keep in mind that truss also uses it.
-#
 
 set -e
 
-if [ $# -ne 2 -o \( $1 != "print" -a $1 != "return" \) ]; then
-       echo "usage: sh $0 print|return include-dir"
+if [ $# -ne 1 ]; then
+       echo "usage: sh $0 include-dir"
        exit 1
 fi
 
-style="$1"
-includedir="$2"
+includedir="$1"
 
 LC_ALL=C; export LC_ALL
 
@@ -40,7 +36,7 @@ esac
 
 awk -v x="$ioctl_includes" 'BEGIN {print x}' |
        $CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - |
-       awk -v ioctl_includes="$ioctl_includes" -v style="$style" '
+       awk -v ioctl_includes="$ioctl_includes" '
 BEGIN {
        print "/* XXX obnoxious prerequisites. */"
        print "#define COMPAT_43"
@@ -68,20 +64,12 @@ BEGIN {
        print "#include <cam/cam.h>"
        print "#include <stddef.h>"
        print "#include <stdint.h>"
+       print "#include <sysdecode.h>"
        print ""
        print ioctl_includes
        print ""
-       if (style == "print") {
-               print "void ioctlname(unsigned long val, int decimal);"
-               print ""
-               print "void"
-               print "ioctlname(unsigned long val, int decimal)"
-       } else {
-               print "const char *ioctlname(unsigned long val);"
-               print ""
-               print "const char *"
-               print "ioctlname(unsigned long val)"
-       }
+       print "const char *"
+       print "sysdecode_ioctlname(unsigned long val)"
        print "{"
        print "\tconst char *str = NULL;"
        print ""
@@ -103,16 +91,7 @@ BEGIN {
 }
 END {
        print ""
-       if (style == "print") {
-               print "\tif (str != NULL)"
-               print "\t\tprintf(\"%s\", str);"
-               print "\telse if (decimal)"
-               print "\t\tprintf(\"%lu\", val);"
-               print "\telse"
-               print "\t\tprintf(\"%#lx\", val);"
-       } else {
-               print "\treturn (str);"
-       }
+       print "\treturn (str);"
        print "}"
 }
 '

Modified: head/lib/libsysdecode/sysdecode.3
==============================================================================
--- head/lib/libsysdecode/sysdecode.3   Tue Dec 22 20:22:17 2015        
(r292621)
+++ head/lib/libsysdecode/sysdecode.3   Tue Dec 22 20:33:49 2015        
(r292622)
@@ -39,6 +39,7 @@ The
 library includes several functions that provide descriptive names of
 values associated with system calls.
 .Sh SEE ALSO
+.Xr sysdecode_ioctlname 3 ,
 .Xr sysdecode_utrace 3
 .Sh HISTORY
 The

Modified: head/lib/libsysdecode/sysdecode.h
==============================================================================
--- head/lib/libsysdecode/sysdecode.h   Tue Dec 22 20:22:17 2015        
(r292621)
+++ head/lib/libsysdecode/sysdecode.h   Tue Dec 22 20:33:49 2015        
(r292622)
@@ -29,6 +29,7 @@
 #ifndef __SYSDECODE_H__
 #define        __SYSDECODE_H__
 
+const char *sysdecode_ioctlname(unsigned long _val);
 int    sysdecode_utrace(FILE *_fp, void *_buf, size_t _len);
 
 #endif /* !__SYSDECODE_H__ */

Added: head/lib/libsysdecode/sysdecode_ioctlname.3
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/lib/libsysdecode/sysdecode_ioctlname.3 Tue Dec 22 20:33:49 2015        
(r292622)
@@ -0,0 +1,57 @@
+.\"
+.\" Copyright (c) 2015 John Baldwin <[email protected]>
+.\" All rights reserved.
+.\"
+.\" 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 AUTHOR 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 12, 2015
+.Dt sysdecode_ioctlname 3
+.Os
+.Sh NAME
+.Nm sysdecode_ioctlname
+.Nd lookup name of device control command
+.Sh LIBRARY
+.Lb libsysdecode
+.Sh SYNOPSIS
+.Ft conts char *
+.Fn sysdecode_ioctlname "unsigned long request"
+.Sh DESCRIPTION
+The
+.Fn sysdecode_ioctlname
+function returns the name of a device control request identified by
+.Fa request .
+A table of names is generated during the build of the
+.Nm sysdecode
+library from system headers that maps device control request values to
+the name of the corresponding C macro.
+.Sh RETURN VALUES
+The
+.Fn sysdecode_ioctlname
+function returns the name of a device control request if
+.Fa request
+is a known value;
+otherwise
+.Dv NULL .
+.Sh SEE ALSO
+.Xr sysdecode 3

Modified: head/usr.bin/kdump/Makefile
==============================================================================
--- head/usr.bin/kdump/Makefile Tue Dec 22 20:22:17 2015        (r292621)
+++ head/usr.bin/kdump/Makefile Tue Dec 22 20:33:49 2015        (r292622)
@@ -6,7 +6,7 @@
 .PATH: ${.CURDIR}/../ktrace
 
 PROG=          kdump
-SRCS=          kdump_subr.c kdump_subr.h kdump.c ioctl.c subr.c
+SRCS=          kdump_subr.c kdump_subr.h kdump.c subr.c
 CFLAGS+=       -I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I.
 
 LIBADD=                sysdecode
@@ -15,15 +15,9 @@ LIBADD+=     capsicum
 CFLAGS+=-DHAVE_LIBCAPSICUM
 .endif
 
-.if ${MK_PF} != "no"
-CFLAGS+=-DPF
-.endif
-
 NO_WERROR?=    YES
 
-CLEANFILES=    ioctl.c kdump_subr.c kdump_subr.h
-
-beforedepend: ioctl.c
+CLEANFILES=    kdump_subr.c kdump_subr.h
 
 .if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386")
 beforedepend: linux_syscalls.c
@@ -44,10 +38,6 @@ linux32_syscalls.c: linux32_syscalls.con
            ${.CURDIR}/../../sys/${MACHINE_ARCH}/linux32/syscalls.master 
${.CURDIR}/linux32_syscalls.conf
 .endif
 
-ioctl.c: mkioctls
-       env MACHINE=${MACHINE} CPP="${CPP}" \
-           sh ${.CURDIR}/mkioctls print ${DESTDIR}${INCLUDEDIR} > ${.TARGET}
-
 kdump_subr.h: mksubr
        sh ${.CURDIR}/mksubr ${DESTDIR}${INCLUDEDIR} | \
            sed -n 's/^\([a-z].*)\)$$/void \1;/p' >${.TARGET}

Modified: head/usr.bin/kdump/kdump.c
==============================================================================
--- head/usr.bin/kdump/kdump.c  Tue Dec 22 20:22:17 2015        (r292621)
+++ head/usr.bin/kdump/kdump.c  Tue Dec 22 20:33:49 2015        (r292622)
@@ -116,7 +116,6 @@ void ktrfault(struct ktr_fault *);
 void ktrfaultend(struct ktr_faultend *);
 void limitfd(int fd);
 void usage(void);
-void ioctlname(unsigned long, int);
 
 #define        TIMESTAMP_NONE          0x0
 #define        TIMESTAMP_ABSOLUTE      0x1
@@ -693,6 +692,20 @@ dumpheader(struct ktr_header *kth)
 #undef KTRACE
 int nsyscalls = sizeof (syscallnames) / sizeof (syscallnames[0]);
 
+static void
+ioctlname(unsigned long val)
+{
+       const char *str;
+
+       str = sysdecode_ioctlname(val);
+       if (str != NULL)
+               printf("%s", str);
+       else if (decimal)
+               printf("%lu", val);
+       else
+               printf("%#lx", val);
+}
+
 void
 ktrsyscall(struct ktr_syscall *ktr, u_int flags)
 {
@@ -741,7 +754,7 @@ ktrsyscall(struct ktr_syscall *ktr, u_in
                        case SYS_ioctl: {
                                print_number(ip, narg, c);
                                putchar(c);
-                               ioctlname(*ip, decimal);
+                               ioctlname(*ip);
                                c = ',';
                                ip++;
                                narg--;

Modified: head/usr.bin/truss/Makefile
==============================================================================
--- head/usr.bin/truss/Makefile Tue Dec 22 20:22:17 2015        (r292621)
+++ head/usr.bin/truss/Makefile Tue Dec 22 20:33:49 2015        (r292622)
@@ -2,16 +2,11 @@
 
 NO_WERROR=
 PROG=  truss
-SRCS=  cloudabi.c ioctl.c main.c setup.c syscalls.c
+SRCS=  cloudabi.c main.c setup.c syscalls.c
 
 LIBADD=        sysdecode
 
 CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys
-CLEANFILES= ioctl.c
-
-ioctl.c: ${.CURDIR}/../kdump/mkioctls
-       env MACHINE=${MACHINE} CPP="${CPP}" \
-               /bin/sh ${.CURDIR}/../kdump/mkioctls return 
${DESTDIR}${INCLUDEDIR} > ${.TARGET}
 
 # Define where to generate syscalls for each ABI.
 ABI_SYSPATH.freebsd=           sys/kern

Modified: head/usr.bin/truss/syscalls.c
==============================================================================
--- head/usr.bin/truss/syscalls.c       Tue Dec 22 20:22:17 2015        
(r292621)
+++ head/usr.bin/truss/syscalls.c       Tue Dec 22 20:33:49 2015        
(r292622)
@@ -1315,7 +1315,7 @@ print_arg(struct syscall_args *sc, unsig
                unsigned long cmd;
 
                cmd = args[sc->offset];
-               temp = ioctlname(cmd);
+               temp = sysdecode_ioctlname(cmd);
                if (temp)
                        fputs(temp, fp);
                else {
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to