freebsd-skq/lib/libsysdecode/mkioctls
John Baldwin 9289f547a2 Move mksubr from kdump into libsysdecode.
Restructure this script so that it generates a header of tables instead
of a source file.  The tables are included in a flags.c source file which
provides functions to decode various system call arguments.

For functions that decode an enumeration, the function returns a pointer
to a string for known values and NULL for unknown values.

For functions that do more complex decoding (typically of a bitmask), the
function accepts a pointer to a FILE object (open_memstream() can be used
as a string builder) to which decoded values are written.  If the
function operates on a bitmask, the function returns true if any bits
were decoded or false if the entire value was valid.  Additionally, the
third argument accepts a pointer to a value to which any undecoded bits
are stored.  This pointer can be NULL if the caller doesn't care about
remaining bits.

Convert kdump over to using decoder functions from libsysdecode instead of
mksubr.  truss also uses decoders from libsysdecode instead of private
lookup tables, though lookup tables for objects not decoded by kdump remain
in truss for now.  Eventually most of these tables should move into
libsysdecode as the automated table generation approach from mksubr is
less stale than the static tables in truss.

Some changes have been made to truss and kdump output:
- The flags passed to open() are now properly decoded in that one of
  O_RDONLY, O_RDWR, O_WRONLY, or O_EXEC is always included in a decoded
  mask.
- Optional arguments to open(), openat(), and fcntl() are only printed
  in kdump if they exist (e.g. the mode is only printed for open() if
  O_CREAT is set in the flags).
- Print argument to F_GETLK/SETLK/SETLKW in kdump as a pointer, not int.
- Include all procctl() commands.
- Correctly decode pipe2() flags in truss by not assuming full
  open()-like flags with O_RDONLY, etc.
- Decode file flags passed to *chflags() as file flags (UF_* and SF_*)
  rather than as a file mode.
- Fix decoding of quotactl() commands by splitting out the two command
  components instead of assuming the raw command value matches the
  primary command component.

In addition, truss and kdump now build without triggering any warnings.
All of the sysdecode manpages now include the required headers in the
synopsis.

Reviewed by:	kib (several older versions), wblock (manpages)
MFC after:	2 months
Differential Revision:	https://reviews.freebsd.org/D7847
2016-10-17 22:37:07 +00:00

99 lines
2.2 KiB
Bash

#!/bin/sh
#
# $FreeBSD$
set -e
if [ $# -ne 1 ]; then
echo "usage: sh $0 include-dir"
exit 1
fi
includedir="$1"
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" '
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 <stdbool.h>"
print "#include <stddef.h>"
print "#include <stdint.h>"
print "#include <sysdecode.h>"
print ""
print ioctl_includes
print ""
print "const char *"
print "sysdecode_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 ""
print "\treturn (str);"
print "}"
}
'