diff options
author | jhb <jhb@FreeBSD.org> | 2015-12-22 20:33:49 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2015-12-22 20:33:49 +0000 |
commit | b665ac07581ab1fbd0d71db29a027b4a39734789 (patch) | |
tree | 12efcb04d4bc19b74d2554032b084f8fee602ddf /usr.bin/kdump | |
parent | 2a6353954347e51fe7f57c094b3d03b9199fae99 (diff) | |
download | FreeBSD-src-b665ac07581ab1fbd0d71db29a027b4a39734789.zip FreeBSD-src-b665ac07581ab1fbd0d71db29a027b4a39734789.tar.gz |
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
Diffstat (limited to 'usr.bin/kdump')
-rw-r--r-- | usr.bin/kdump/Makefile | 14 | ||||
-rw-r--r-- | usr.bin/kdump/kdump.c | 17 | ||||
-rw-r--r-- | usr.bin/kdump/mkioctls | 118 |
3 files changed, 17 insertions, 132 deletions
diff --git a/usr.bin/kdump/Makefile b/usr.bin/kdump/Makefile index 52c0a09..f149e80 100644 --- a/usr.bin/kdump/Makefile +++ b/usr.bin/kdump/Makefile @@ -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.conf ${.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} diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 8165bc7..7af99fb 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -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_int flags) case SYS_ioctl: { print_number(ip, narg, c); putchar(c); - ioctlname(*ip, decimal); + ioctlname(*ip); c = ','; ip++; narg--; diff --git a/usr.bin/kdump/mkioctls b/usr.bin/kdump/mkioctls deleted file mode 100644 index a563341..0000000 --- a/usr.bin/kdump/mkioctls +++ /dev/null @@ -1,118 +0,0 @@ -#!/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" - exit 1 -fi - -style="$1" -includedir="$2" - -LC_ALL=C; export LC_ALL - -# Build a list of headers that have ioctls in them. -# XXX should we use an ANSI cpp? -ioctl_includes=$( - cd $includedir - find -H -s * -name '*.h' | \ - egrep -v '(.*disk.*|net/pfvar|net/if_pfsync)\.h' | \ - xargs egrep -l \ -'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | - awk '{printf("#include <%s>\\n", $1)}' -) - -: ${MACHINE=$(uname -m)} -case "${MACHINE}" in -*pc98*) - ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n" - ;; -*) - ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n" - ;; -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" ' -BEGIN { - print "/* XXX obnoxious prerequisites. */" - print "#define COMPAT_43" - print "#define COMPAT_43TTY" - print "#include <sys/param.h>" - print "#include <sys/devicestat.h>" - print "#include <sys/disklabel.h>" - print "#include <sys/socket.h>" - print "#include <sys/time.h>" - print "#include <sys/tty.h>" - print "#include <bsm/audit.h>" - print "#include <net/ethernet.h>" - print "#include <net/if.h>" - print "#ifdef PF" - print "#include <net/pfvar.h>" - print "#include <net/if_pfsync.h>" - print "#endif" - print "#include <net/route.h>" - print "#include <netinet/in.h>" - print "#include <netinet/ip_mroute.h>" - print "#include <netinet6/in6_var.h>" - print "#include <netinet6/nd6.h>" - print "#include <netinet6/ip6_mroute.h>" - print "#include <stdio.h>" - print "#include <cam/cam.h>" - print "#include <stddef.h>" - print "#include <stdint.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 "{" - print "\tconst char *str = NULL;" - print "" -} - -/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { - - # find where the name starts - for (i = 1; i <= NF; i++) - if ($i ~ /define/) - break; - ++i; - # - printf("\t"); - if (n++ > 0) - printf("else "); - printf("if (val == %s)\n", $i); - printf("\t\tstr = \"%s\";\n", $i); -} -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 "}" -} -' |