[BACK]Return to mksubr CVS log [TXT][DIR] Up to [local] / src / usr.bin / kdump

Annotation of src/usr.bin/kdump/mksubr, Revision 1.21

1.1       otto        1: #!/bin/sh
1.21    ! guenther    2: # $OpenBSD: mksubr,v 1.20 2014/07/02 06:32:07 otto Exp $
1.1       otto        3: #
                      4: # Copyright (c) 2006 David Kirchner <dpk@dpk.net>
                      5: #
                      6: # Permission to use, copy, modify, and distribute this software for any
                      7: # purpose with or without fee is hereby granted, provided that the above
                      8: # copyright notice and this permission notice appear in all copies.
                      9: #
                     10: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17: #
                     18: # $FreeBSD: src/usr.bin/kdump/mksubr,v 1.17 2011/06/06 19:00:38 dchagin Exp $
                     19: #
                     20: # Generates kdump_subr.c
                     21: # mkioctls is a special-purpose script, and works fine as it is
                     22: # now, so it remains independent. The idea behind how it generates
                     23: # its list was heavily borrowed here.
                     24: #
                     25: # Some functions here are automatically generated. This can mean
                     26: # the user will see unusual kdump output or errors while building
                     27: # if the underlying .h files are changed significantly.
                     28: #
                     29: # Key:
                     30: # AUTO: Completely auto-generated with either the "or" or the "switch"
                     31: # method.
                     32: # AUTO - Special: Generated automatically, but with some extra commands
                     33: # that the auto_*_type() functions are inappropriate for.
                     34: # MANUAL: Manually entered and must therefore be manually updated.
                     35:
                     36: set -e
                     37:
                     38: LC_ALL=C; export LC_ALL
                     39:
                     40: if [ -z "$1" ]
                     41: then
                     42:        echo "usage: sh $0 include-dir"
                     43:        exit 1
                     44: fi
                     45: include_dir=$1
                     46:
                     47: #
                     48: # Automatically generates a C function that will print out the
                     49: # numeric input as a pipe-delimited string of the appropriate
                     50: # #define keys. ex:
1.12      guenther   51: # 0x1a4<S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH>
1.1       otto       52: # The XOR is necessary to prevent including the "0"-value in every
                     53: # line.
                     54: #
                     55: auto_or_type () {
                     56:        local name grep file
                     57:        name=$1
                     58:        grep=$2
                     59:        file=$3
1.21    ! guenther   60:        format=${4-%#x}
1.1       otto       61:
                     62:        cat <<_EOF_
                     63: /* AUTO */
                     64: void
                     65: $name (int arg)
                     66: {
                     67:        int     or = 0;
1.21    ! guenther   68:        printf("$format<", arg);
1.1       otto       69: _EOF_
                     70:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                     71:                $include_dir/$file | \
                     72:        awk '{ for (i = 1; i <= NF; i++) \
                     73:                if ($i ~ /define/) \
                     74:                        break; \
                     75:                ++i; \
                     76:                printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
                     77: cat <<_EOF_
                     78:        printf(">");
                     79:        if (or == 0)
                     80:                (void)printf("<invalid>%ld", (long)arg);
                     81: }
                     82:
                     83: _EOF_
                     84: }
                     85:
                     86: #
1.8       guenther   87: # Like auto_or_type(), but a zero value is valid and prints as "0<>"
                     88: #
                     89: auto_orz_type () {
                     90:        local name grep file
                     91:        name=$1
                     92:        grep=$2
                     93:        file=$3
1.21    ! guenther   94:        format=${4-%#x}
1.8       guenther   95:
                     96:        cat <<_EOF_
                     97: /* AUTO */
                     98: void
                     99: $name (int arg)
                    100: {
                    101:        int     or = 0;
                    102:        if (arg == 0) {
                    103:                printf("0<>");
                    104:                return;
                    105:        }
1.21    ! guenther  106:        printf("$format<", arg);
1.8       guenther  107: _EOF_
                    108:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    109:                $include_dir/$file | \
                    110:        awk '{ for (i = 1; i <= NF; i++) \
                    111:                if ($i ~ /define/) \
                    112:                        break; \
                    113:                ++i; \
                    114:                printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
                    115: cat <<_EOF_
                    116:        printf(">");
                    117:        if (or == 0)
                    118:                (void)printf("<invalid>%ld", (long)arg);
                    119: }
                    120:
                    121: _EOF_
                    122: }
                    123:
                    124: #
1.12      guenther  125: # Automatically generates a C function that will print out a
                    126: # file flags input as a pipe-delimited string of the appropriate
                    127: # #define keys. ex:
                    128: # 0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>
                    129: # This is different than the others to handle O_RDONLY correctly when
                    130: # other flags are present and to diagnose an invalid O_ACCMODE value
                    131: #
                    132: auto_fflags_type () {
                    133:        local name grep file
                    134:        name=$1
                    135:        grep=$2
                    136:        file=$3
                    137:
                    138:        cat <<_EOF_
                    139: /* AUTO */
                    140: void
                    141: $name (int arg)
                    142: {
                    143:        printf("%#x<", arg);
                    144:        switch (arg & O_ACCMODE) {
                    145:        case O_RDONLY:
                    146:                printf("O_RDONLY");
                    147:                break;
                    148:        case O_WRONLY:
                    149:                printf("O_WRONLY");
                    150:                break;
                    151:        case O_RDWR:
                    152:                printf("O_RDWR");
                    153:                break;
                    154:        default:
                    155:                printf("<invalid>O_ACCMODE");
                    156:                break;
                    157:        }
                    158: _EOF_
                    159:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    160:                $include_dir/$file | \
                    161:        egrep -v 'O_(RD(ONLY|WR)|WRONLY|ACCMODE)' | \
                    162:        awk '{ for (i = 1; i <= NF; i++) \
                    163:                if ($i ~ /define/) \
                    164:                        break; \
                    165:                ++i; \
                    166:                printf "\tif (arg & %s) printf (\"|%%s\", \"%s\");\n", $i, $i }'
                    167: cat <<_EOF_
                    168:        printf(">");
                    169: }
                    170:
                    171: _EOF_
                    172: }
                    173:
                    174:
                    175: #
1.1       otto      176: # Automatically generates a C function used when the argument
                    177: # maps to a single, specific #definition
                    178: #
                    179: auto_switch_type () {
                    180:        local name grep file
                    181:        name=$1
                    182:        grep=$2
                    183:        file=$3
                    184:
                    185:        cat <<_EOF_
                    186: /* AUTO */
                    187: void
                    188: $name (int arg)
                    189: {
                    190:        switch (arg) {
                    191: _EOF_
                    192:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    193:                $include_dir/$file | \
                    194:        awk '{ for (i = 1; i <= NF; i++) \
                    195:                if ($i ~ /define/) \
                    196:                        break; \
                    197:                ++i; \
                    198:                printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }'
                    199: cat <<_EOF_
                    200:        default: /* Should not reach */
                    201:                (void)printf("<invalid=%ld>", (long)arg);
                    202:        }
                    203: }
                    204:
                    205: _EOF_
                    206: }
                    207:
                    208: #
                    209: # Automatically generates a C function used when the argument
                    210: # maps to a #definition
                    211: #
                    212: auto_if_type () {
                    213:        local name grep file
                    214:        name=$1
                    215:        grep=$2
                    216:        file=$3
                    217:
                    218:        cat <<_EOF_
                    219: /* AUTO */
                    220: void
                    221: $name (int arg)
                    222: {
                    223: _EOF_
                    224:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    225:                $include_dir/$file | \
                    226:        awk '{ printf "\t"; \
                    227:                if (NR > 1) \
                    228:                        printf "else " ; \
                    229:                printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
                    230: cat <<_EOF_
                    231:        else /* Should not reach */
                    232:                (void)printf("<invalid=%ld>", (long)arg);
                    233: }
                    234:
                    235: _EOF_
                    236: }
                    237:
                    238: # C start
                    239:
                    240: cat <<_EOF_
                    241: #include <stdio.h>
1.2       otto      242: #include <sys/param.h>
1.1       otto      243: #include <sys/fcntl.h>
                    244: #include <sys/stat.h>
                    245: #include <sys/unistd.h>
1.19      matthew   246: #define _KERNEL
1.1       otto      247: #include <sys/mman.h>
1.19      matthew   248: #undef _KERNEL
1.1       otto      249: #include <sys/wait.h>
1.2       otto      250: #include <sys/proc.h>
1.1       otto      251: #define _KERNEL
1.2       otto      252: #define COMPAT_43
1.1       otto      253: #include <sys/socket.h>
                    254: #undef _KERNEL
                    255: #include <netinet/in.h>
                    256: #include <sys/param.h>
                    257: #include <sys/mount.h>
1.14      guenther  258: #include <sys/poll.h>
1.1       otto      259: #include <sys/ptrace.h>
                    260: #include <sys/resource.h>
                    261: #include <sys/reboot.h>
1.18      guenther  262: #include <sys/uio.h>
                    263: #include <sys/ktrace.h>
1.1       otto      264: #include <sched.h>
1.2       otto      265: #if 0
1.1       otto      266: #include <sys/linker.h>
                    267: #define _KERNEL
                    268: #include <sys/thr.h>
                    269: #undef _KERNEL
                    270: #include <sys/extattr.h>
                    271: #include <sys/acl.h>
                    272: #include <aio.h>
1.2       otto      273: #endif
1.1       otto      274: #include <sys/sem.h>
                    275: #include <sys/ipc.h>
1.2       otto      276: #if 0
1.1       otto      277: #include <sys/rtprio.h>
1.2       otto      278: #endif
1.1       otto      279: #include <sys/shm.h>
1.2       otto      280: #if 0
1.1       otto      281: #include <nfsserver/nfs.h>
1.2       otto      282: #endif
1.1       otto      283: #include <ufs/ufs/quota.h>
                    284:
                    285: #include "kdump_subr.h"
                    286:
                    287: _EOF_
                    288:
1.21    ! guenther  289: auto_orz_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h" "%#o"
1.12      guenther  290: auto_fflags_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
1.8       guenther  291: auto_orz_type "atflagsname" "AT_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
1.3       otto      292: auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
1.1       otto      293: auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
1.13      matthew   294: auto_or_type "mmapflagsname" "(__)?MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
1.8       guenther  295: auto_orz_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
                    296: #auto_or_type "timerflagsname" "TIMER_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/time.h"
1.2       otto      297: #auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
                    298: #auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
                    299: #auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
1.3       otto      300: auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
1.2       otto      301: #auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
1.3       otto      302: auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
1.8       guenther  303: auto_orz_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}" "sys/shm.h"
1.2       otto      304: #auto_or_type "nfssvcname" "NFSSVC_[A-Z]+[[:space:]]+0x[0-9]+" "nfsserver/nfs.h"
                    305: #
1.3       otto      306: auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
1.14      guenther  307: auto_switch_type "pathconfname" "_PC_[_A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
1.3       otto      308: auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
1.14      guenther  309: auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
1.2       otto      310: #auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
1.3       otto      311: auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
                    312: auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
1.15      guenther  313: auto_switch_type "clocktypename" "CLOCK_[_A-Z]+[[:space:]]+[0-9]+" "sys/_time.h"
1.2       otto      314: #auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
                    315: #auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
                    316: #auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
                    317: #auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
                    318: #auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
                    319: #auto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h"
1.16      guenther  320: auto_switch_type "rusagewho" "RUSAGE_[A-Z]+[[:space:]]+[-0-9()]+" "sys/resource.h"
1.9       guenther  321: auto_orz_type "sigactionflagname" "SA_[A-Z]+[[:space:]]+0x[0-9]+" "sys/signal.h"
1.1       otto      322: auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
1.7       deraadt   323: auto_switch_type "sigill_name" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    324: auto_switch_type "sigtrap_name" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    325: auto_switch_type "sigemt_name" "EMT_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    326: auto_switch_type "sigfpe_name" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    327: auto_switch_type "sigbus_name" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    328: auto_switch_type "sigsegv_name" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    329: auto_switch_type "sigchld_name" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
1.2       otto      330: #auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
1.20      otto      331: auto_switch_type "minheritname" "MAP_INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
1.2       otto      332: #auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
1.3       otto      333: auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
1.5       otto      334: auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
1.3       otto      335: auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
                    336: auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
                    337: auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
1.2       otto      338: #auto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h"
1.18      guenther  339: auto_orz_type "ktracefacname" "KTRFAC_[^M][[:alnum:]_]+" "sys/ktrace.h"
                    340: auto_switch_type "itimername" "ITIMER_[[:alnum:]_]+" "sys/time.h"
1.1       otto      341:
                    342: cat <<_EOF_
                    343: /*
                    344:  * AUTO - Special
                    345:  * F_ is used to specify fcntl commands as well as arguments. Both sets are
                    346:  * grouped in fcntl.h, and this awk script grabs the first group.
                    347:  */
                    348: void
1.4       otto      349: fcntlcmdname (int cmd, int arg)
1.1       otto      350: {
                    351:        switch (cmd) {
                    352: _EOF_
1.6       matthew   353: egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z_]+[[:space:]]+[0-9]+[[:space:]]*" \
1.1       otto      354:        $include_dir/sys/fcntl.h | \
                    355:        awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \
                    356:                if ($i ~ /define/) \
                    357:                        break; \
                    358:                ++i; \
                    359:                if (o <= $(i+1)) \
                    360:                        printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i; \
                    361:                else \
                    362:                        exit; \
                    363:                o = $(i+1) }'
                    364: cat <<_EOF_
                    365:        default: /* Should not reach */
                    366:                (void)printf("<invalid=%ld>", (long)cmd);
                    367:        }
1.14      guenther  368:        if (cmd == F_SETFD) {
                    369:                (void)putchar(',');
1.1       otto      370:                if (arg == FD_CLOEXEC)
                    371:                        (void)printf("FD_CLOEXEC");
                    372:                else if (arg == 0)
                    373:                        (void)printf("0");
                    374:                else {
                    375:                        if (decimal)
                    376:                                (void)printf("<invalid>%ld", (long)arg);
                    377:                        else
                    378:                                (void)printf("<invalid>%#lx", (long)arg);
                    379:                }
1.14      guenther  380:
1.1       otto      381:        } else if (cmd == F_SETFL) {
1.14      guenther  382:                (void)putchar(',');
1.1       otto      383:                flagsname(arg);
1.14      guenther  384:        } else if (!fancy || (cmd != F_GETFD && cmd != F_GETFL)) {
                    385:                (void)putchar(',');
1.1       otto      386:                if (decimal)
                    387:                        (void)printf("%ld", (long)arg);
                    388:                else
                    389:                        (void)printf("%#lx", (long)arg);
                    390:        }
                    391: }
                    392:
                    393: /*
                    394:  * AUTO - Special
                    395:  *
                    396:  * The send and recv functions have a flags argument which can be
                    397:  * set to 0. There is no corresponding #define. The auto_ functions
                    398:  * detect this as "invalid", which is incorrect here.
                    399:  */
                    400: void
                    401: sendrecvflagsname (int flags)
                    402: {
                    403:        int     or = 0;
                    404:
                    405:        if (flags == 0) {
                    406:                (void)printf("0");
                    407:                return;
                    408:        }
                    409:
                    410:        printf("%#x<", flags);
                    411: _EOF_
                    412: egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \
                    413:        awk '{ for (i = 1; i <= NF; i++) \
                    414:                if ($i ~ /define/) \
                    415:                        break; \
                    416:                ++i; \
                    417:                printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'
                    418: cat <<_EOF_
                    419:        printf(">");
                    420: }
                    421:
                    422: _EOF_