From 37ffcab23b4981b1b3aad12ca06ed4cc75bb7f3b Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 6 Aug 2017 01:54:29 +0200 Subject: [PATCH] kdump(8): Add more support for printing flag etc. names. * New support for: eaccess() modes, faccessat() modes and atflag, fchmodat() atflag, fchownat() atflag, fstatat() atflag, linkat() atflag, unlinkat() atflag, utimensat() atflag, getvfsstat() flags, lchflags() flags, chflagsat() flags and atflag, kenv() actions, usched_set() commands, sys_checkpoint() types, procctl() commands, mountctl() operations, and varsym_{list,set}() levels. * Fix flags printing in chflags() and fchflags(). * Better separate mount() and getfsstat() flags definitions. * Adjust grepping for fcntl() commands send/recvmsg() etc. flags to include flags with more than one underscore in their name, like F_DUPFD_CLOEXEC. Still missing: extexit()'s 'how' argument. --- usr.bin/kdump/kdump.c | 96 ++++++++++++++++++++++++++++++++++++++++++++-- usr.bin/kdump/kdump_subr.h | 8 ++++ usr.bin/kdump/mksubr | 45 ++++++++++++++++++++-- 3 files changed, 141 insertions(+), 8 deletions(-) diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index b9d67906ad..955ba2bad7 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -309,12 +309,22 @@ ktrsyscall(struct ktr_syscall *ktr) c = ','; ip++; narg--; - } else if (ktr->ktr_code == SYS_access) { + } else if (ktr->ktr_code == SYS_access || + ktr->ktr_code == SYS_eaccess || + ktr->ktr_code == SYS_faccessat) { + if (ktr->ktr_code == SYS_faccessat) + print_number(ip,narg,c); print_number(ip,narg,c); putchar(','); accessmodename ((int)*ip); ip++; narg--; + if (ktr->ktr_code == SYS_faccessat) { + putchar(','); + atflagsname((int)*ip); + ip++; + narg--; + } } else if (ktr->ktr_code == SYS_open || ktr->ktr_code == SYS_mq_open) { int flags; @@ -335,20 +345,48 @@ ktrsyscall(struct ktr_syscall *ktr) narg--; } else if (ktr->ktr_code == SYS_chmod || ktr->ktr_code == SYS_fchmod || + ktr->ktr_code == SYS_fchmodat || ktr->ktr_code == SYS_lchmod) { + if (ktr->ktr_code == SYS_fchmodat) + print_number(ip,narg,c); print_number(ip,narg,c); putchar(','); modename ((int)*ip); ip++; narg--; + if (ktr->ktr_code == SYS_fchmodat) { + putchar(','); + atflagsname((int)*ip); + ip++; + narg--; + } + } else if (ktr->ktr_code == SYS_fchownat || + ktr->ktr_code == SYS_fstatat || + ktr->ktr_code == SYS_linkat || + ktr->ktr_code == SYS_unlinkat || + ktr->ktr_code == SYS_utimensat) { + print_number(ip,narg,c); + print_number(ip,narg,c); + if (ktr->ktr_code != SYS_unlinkat) + print_number(ip,narg,c); + if (ktr->ktr_code == SYS_fchownat || + ktr->ktr_code == SYS_linkat) + print_number(ip,narg,c); + putchar(','); + atflagsname((int)*ip); + ip++; + narg--; } else if (ktr->ktr_code == SYS_mknod) { print_number(ip,narg,c); putchar(','); modename ((int)*ip); ip++; narg--; - } else if (ktr->ktr_code == SYS_getfsstat) { + } else if (ktr->ktr_code == SYS_getfsstat || + ktr->ktr_code == SYS_getvfsstat) { print_number(ip,narg,c); + if (ktr->ktr_code == SYS_getvfsstat) + print_number(ip,narg,c); print_number(ip,narg,c); putchar(','); getfsstatflagsname ((int)*ip); @@ -385,12 +423,22 @@ ktrsyscall(struct ktr_syscall *ktr) ip++; narg--; } else if (ktr->ktr_code == SYS_chflags || - ktr->ktr_code == SYS_fchflags) { + ktr->ktr_code == SYS_chflagsat || + ktr->ktr_code == SYS_fchflags || + ktr->ktr_code == SYS_lchflags) { + if (ktr->ktr_code == SYS_chflagsat) + print_number(ip,narg,c); print_number(ip,narg,c); putchar(','); - modename((int)*ip); + chflagsname((int)*ip); ip++; narg--; + if (ktr->ktr_code == SYS_chflagsat) { + putchar(','); + atflagsname((int)*ip); + ip++; + narg--; + } } else if (ktr->ktr_code == SYS_kill) { print_number(ip,narg,c); putchar(','); @@ -690,6 +738,46 @@ ktrsyscall(struct ktr_syscall *ktr) pathconfname((int)*ip); ip++; narg--; + } else if (ktr->ktr_code == SYS_kenv) { + putchar('('); + kenvactname((int)*ip); + ip++; + narg--; + c = ','; + } else if (ktr->ktr_code == SYS_usched_set) { + print_number(ip,narg,c); + putchar(','); + uschedcmdname((int)*ip); + ip++; + narg--; + } else if (ktr->ktr_code == SYS_sys_checkpoint) { + putchar('('); + ckpttypename((int)*ip); + ip++; + narg--; + c = ','; + } else if (ktr->ktr_code == SYS_procctl) { + print_number(ip,narg,c); + print_number(ip,narg,c); + putchar(','); + procctlcmdname((int)*ip); + ip++; + narg--; + c = ','; + } else if (ktr->ktr_code == SYS_mountctl) { + print_number(ip,narg,c); + putchar(','); + mountctlopname((int)*ip); + ip++; + narg--; + c = ','; + } else if (ktr->ktr_code == SYS_varsym_list || + ktr->ktr_code == SYS_varsym_set) { + putchar('('); + varsymlvlname((int)*ip); + ip++; + narg--; + c = ','; } } while (narg > 0) { diff --git a/usr.bin/kdump/kdump_subr.h b/usr.bin/kdump/kdump_subr.h index d807b435ad..d80b6a1e9f 100644 --- a/usr.bin/kdump/kdump_subr.h +++ b/usr.bin/kdump/kdump_subr.h @@ -47,3 +47,11 @@ void minheritname (int); void quotactlname (int); void clockidname (int); void pathconfname (int); +void kenvactname (int); +void uschedcmdname (int); +void ckpttypename (int); +void procctlcmdname (int); +void mountctlopname (int); +void chflagsname (int); +void atflagsname (int); +void varsymlvlname (int); diff --git a/usr.bin/kdump/mksubr b/usr.bin/kdump/mksubr index fc53bfe10a..a6044ec03e 100644 --- a/usr.bin/kdump/mksubr +++ b/usr.bin/kdump/mksubr @@ -160,6 +160,7 @@ cat <<_EOF_ #include #include #include +#include #include #include #include @@ -169,6 +170,11 @@ cat <<_EOF_ #include #include #include +#include +#include +#include +#include +#include #include "kdump_subr.h" @@ -319,13 +325,15 @@ auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h" auto_or_type "mmapflagsname" "MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h" auto_or_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h" -auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h" -auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h" +auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9][0-9][0-9][0-9][^0-9]" "sys/mount.h" +auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9][0-9][0-9][0-9][0-9]+" "sys/mount.h" auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h" auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h" auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h" auto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h" auto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h" +auto_or_type "chflagsname" "[SU]F_[A-Z]+[[:space:]]+0x[0-9]+" "sys/stat.h" +auto_or_type "atflagsname" "AT_[A-Z_]+[[:space:]]+[1-9]+[0-9]*" "sys/fcntl.h" auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h" auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h" @@ -348,6 +356,11 @@ auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h" auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h" auto_switch_type "clockidname" "CLOCK_[[:alnum:]]+" "time.h" "noinvdef" auto_switch_type "pathconfname" "_PC_[[:alnum:]]+" "sys/unistd.h" +auto_switch_type "uschedcmdname" "USCHED_[[:alnum:]]+" "sys/usched.h" +auto_switch_type "ckpttypename" "CKPT_[[:alnum:]]+" "sys/checkpoint.h" +auto_switch_type "procctlcmdname" "PROC_[[:alnum:]]+" "sys/procctl.h" +auto_switch_type "mountctlopname" "MOUNTCTL_[[:alnum:]]+" "sys/mountctl.h" +auto_switch_type "varsymlvlname" "VARSYM_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/varsym.h" cat <<_EOF_ /* @@ -360,7 +373,7 @@ fcntlcmdname (int cmd, int arg, int decimal) { switch (cmd) { _EOF_ -egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z]+[[:space:]]+[0-9]+[[:space:]]*" \ +egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z0-9_]+[[:space:]]+[0-9]+[[:space:]]*" \ $include_dir/sys/fcntl.h | \ awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \ if ($i ~ /define/) \ @@ -441,7 +454,7 @@ sendrecvflagsname (int flags) printf("%#x<", flags); _EOF_ -egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \ +egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z_]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \ awk '{ for (i = 1; i <= NF; i++) \ if ($i ~ /define/) \ break; \ @@ -451,4 +464,28 @@ cat <<_EOF_ printf(">"); } +/* + * AUTO - Special + * + * The only reason this is not fully automated is due to the + * grep -vw ... statement. A better egrep line should + * make this capable of being a auto_switch_type() function. + */ +void +kenvactname (int act) +{ + switch (act) { +_EOF_ +egrep "^#[[:space:]]*define[[:space:]]+KENV_[A-Z]+[[:space:]]+[0-9]+[[:space:]]*" \ + $include_dir/sys/kenv.h | grep -vw -e KENV_MNAMELEN -e KENV_MVALLEN | \ + awk '{ for (i = 1; i <= NF; i++) \ + if ($i ~ /define/) \ + break; \ + ++i; \ + printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }' +cat <<_EOF_ + default: /* Should not reach */ + printf("", (long)act); + } +} _EOF_ -- 2.11.4.GIT