svn commit: r226608 - in head/usr.bin: kdump truss

Dag-Erling Smorgrav des at FreeBSD.org
Fri Oct 21 11:08:26 UTC 2011


Author: des
Date: Fri Oct 21 11:08:25 2011
New Revision: 226608
URL: http://svn.freebsd.org/changeset/base/226608

Log:
  It turns out that truss also used kdump's mkioctls script, and expected
  ioctlname() to return a pointer to the name rather than print it.  This did
  not show up in testing because truss had its own prototype for ioctlname(),
  so it would build fine and run fine as long as the program being traced did
  not issue an ioctl.
  
  Teach mkioctls to generate different versions of ioctlname() based on its
  first command-line argument.
  
  Pointed out by:	Garrett Cooper <yanegomi at gmail.com>

Modified:
  head/usr.bin/kdump/Makefile
  head/usr.bin/kdump/mkioctls
  head/usr.bin/truss/Makefile
  head/usr.bin/truss/extern.h

Modified: head/usr.bin/kdump/Makefile
==============================================================================
--- head/usr.bin/kdump/Makefile	Fri Oct 21 06:41:46 2011	(r226607)
+++ head/usr.bin/kdump/Makefile	Fri Oct 21 11:08:25 2011	(r226608)
@@ -22,7 +22,7 @@ CLEANFILES=	ioctl.c kdump_subr.c kdump_s
 
 ioctl.c: mkioctls
 	env MACHINE=${MACHINE} \
-	    sh ${.CURDIR}/mkioctls ${DESTDIR}/usr/include > ${.TARGET}
+	    sh ${.CURDIR}/mkioctls print ${DESTDIR}/usr/include > ${.TARGET}
 
 kdump_subr.h: mksubr
 	sh ${.CURDIR}/mksubr ${DESTDIR}/usr/include | \

Modified: head/usr.bin/kdump/mkioctls
==============================================================================
--- head/usr.bin/kdump/mkioctls	Fri Oct 21 06:41:46 2011	(r226607)
+++ head/usr.bin/kdump/mkioctls	Fri Oct 21 11:08:25 2011	(r226608)
@@ -1,20 +1,26 @@
 #!/bin/sh
 #
 # $FreeBSD$
+#
+# When editing this script, keep in mind that truss also uses it.
+#
 
 set -e
 
-if [ -z "$1" ]; then
-	echo "usage: sh $0 include-dir"
+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 $1
+	cd $includedir
 	find -H -s * -name '*.h' | grep -v '.*disk.*\.h' | \
 		xargs egrep -l \
 '^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO[^a-z0-9_]' |
@@ -33,7 +39,7 @@ esac
 
 awk -v x="$ioctl_includes" 'BEGIN {print x}' |
 	gcc -E -I$1 -dM -DCOMPAT_43TTY - |
-	awk -v ioctl_includes="$ioctl_includes" '
+	awk -v ioctl_includes="$ioctl_includes" -v style="$style" '
 BEGIN {
 	print "/* XXX obnoxious prerequisites. */"
 	print "#define COMPAT_43"
@@ -58,12 +64,19 @@ BEGIN {
 	print "#include <stdio.h>"
 	print "#include <cam/cam.h>"
 	print ""
-	print "void ioctlname(unsigned long val, int decimal);"
-	print ""
 	print ioctl_includes
 	print ""
-	print "void"
-	print "ioctlname(unsigned long val, int decimal)"
+	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 ""
@@ -77,20 +90,24 @@ BEGIN {
 			break;
 	++i;
 	#
-	print("\t");
+	printf("\t");
 	if (n++ > 0)
-		print("else ");
+		printf("else ");
 	printf("if (val == %s)\n", $i);
 	printf("\t\tstr = \"%s\";\n", $i);
 }
 END {
-	print "\n"
-	print "\tif (str != NULL)\n"
-	print "\t\tprintf(\"%s\", str);\n"
-	print "\telse if (decimal)\n"
-	print "\t\tprintf(\"%lu\", val);\n"
-	print "\telse\n"
-	print "\t\tprintf(\"%#lx\", val);\n"
+	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 "}"
 }
 '

Modified: head/usr.bin/truss/Makefile
==============================================================================
--- head/usr.bin/truss/Makefile	Fri Oct 21 06:41:46 2011	(r226607)
+++ head/usr.bin/truss/Makefile	Fri Oct 21 11:08:25 2011	(r226608)
@@ -23,7 +23,8 @@ syscalls.h:	syscalls.master
 		${.CURDIR}/i386.conf
 
 ioctl.c: ${.CURDIR}/../kdump/mkioctls
-	sh ${.CURDIR}/../kdump/mkioctls ${DESTDIR}/usr/include > ${.TARGET}
+	env MACHINE=${MACHINE} \
+		/bin/sh ${.CURDIR}/../kdump/mkioctls return ${DESTDIR}/usr/include > ${.TARGET}
 
 .if ${MACHINE_CPUARCH} == "i386"
 SRCS+=	i386-linux.c linux_syscalls.h

Modified: head/usr.bin/truss/extern.h
==============================================================================
--- head/usr.bin/truss/extern.h	Fri Oct 21 06:41:46 2011	(r226607)
+++ head/usr.bin/truss/extern.h	Fri Oct 21 11:08:25 2011	(r226608)
@@ -35,7 +35,7 @@ extern int setup_and_wait(char **);
 extern int start_tracing(int);
 extern void restore_proc(int);
 extern void waitevent(struct trussinfo *);
-extern const char *ioctlname(register_t val);
+extern const char *ioctlname(unsigned long val);
 extern char *strsig(int sig);
 #ifdef __amd64__
 extern void amd64_syscall_entry(struct trussinfo *, int);


More information about the svn-src-head mailing list