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

Annotation of src/usr.bin/kdump/kdump.c, Revision 1.92

1.92    ! guenther    1: /*     $OpenBSD: kdump.c,v 1.91 2014/10/13 03:46:33 guenther Exp $     */
1.4       deraadt     2:
1.1       deraadt     3: /*-
                      4:  * Copyright (c) 1988, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
1.21      millert    15:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
                     31:
                     32: #include <sys/param.h>
                     33: #include <sys/time.h>
                     34: #include <sys/uio.h>
                     35: #include <sys/ktrace.h>
                     36: #include <sys/ioctl.h>
1.62      otto       37: #include <sys/malloc.h>
                     38: #include <sys/namei.h>
1.1       deraadt    39: #include <sys/ptrace.h>
1.62      otto       40: #include <sys/sem.h>
                     41: #include <sys/shm.h>
1.51      otto       42: #include <sys/socket.h>
1.28      deraadt    43: #include <sys/sysctl.h>
1.63      deraadt    44: #include <sys/siginfo.h>
1.62      otto       45: #include <sys/vmmeter.h>
                     46: #include <sys/tty.h>
1.82      guenther   47: #include <sys/wait.h>
1.1       deraadt    48: #define _KERNEL
1.84      guenther   49: #include <errno.h>
1.1       deraadt    50: #undef _KERNEL
1.62      otto       51: #include <ddb/db_var.h>
                     52: #include <machine/cpu.h>
1.1       deraadt    53:
1.33      tedu       54: #include <ctype.h>
1.1       deraadt    55: #include <err.h>
1.61      matthew    56: #include <fcntl.h>
1.64      guenther   57: #include <limits.h>
1.77      guenther   58: #include <poll.h>
1.1       deraadt    59: #include <signal.h>
                     60: #include <stdio.h>
                     61: #include <stdlib.h>
1.55      otto       62: #include <stdint.h>
1.1       deraadt    63: #include <string.h>
                     64: #include <unistd.h>
                     65: #include <vis.h>
                     66:
                     67: #include "ktrace.h"
1.22      deraadt    68: #include "kdump.h"
1.51      otto       69: #include "kdump_subr.h"
1.12      espie      70: #include "extern.h"
1.1       deraadt    71:
1.67      mikeb      72: int timestamp, decimal, iohex, fancy = 1, maxdata = INT_MAX;
                     73: int needtid, resolv, tail;
1.1       deraadt    74: char *tracefile = DEF_TRACEFILE;
                     75: struct ktr_header ktr_header;
1.85      guenther   76: pid_t pid_opt = -1;
1.1       deraadt    77:
                     78: #define eqs(s1, s2)    (strcmp((s1), (s2)) == 0)
                     79:
                     80: #include <sys/syscall.h>
                     81:
1.25      mickey     82: #include <compat/linux/linux_syscall.h>
1.1       deraadt    83:
                     84: #define KTRACE
1.19      mickey     85: #define PTRACE
1.7       deraadt    86: #define NFSCLIENT
                     87: #define NFSSERVER
                     88: #define SYSVSEM
                     89: #define SYSVMSG
                     90: #define SYSVSHM
                     91: #define LFS
1.25      mickey     92: #include <kern/syscalls.c>
1.1       deraadt    93:
1.25      mickey     94: #include <compat/linux/linux_syscalls.c>
1.1       deraadt    95: #undef KTRACE
1.19      mickey     96: #undef PTRACE
1.7       deraadt    97: #undef NFSCLIENT
                     98: #undef NFSSERVER
                     99: #undef SYSVSEM
                    100: #undef SYSVMSG
                    101: #undef SYSVSHM
                    102: #undef LFS
1.1       deraadt   103:
                    104: struct emulation {
                    105:        char *name;             /* Emulation name */
                    106:        char **sysnames;        /* Array of system call names */
                    107:        int  nsysnames;         /* Number of */
                    108: };
                    109:
                    110: static struct emulation emulations[] = {
1.9       deraadt   111:        { "native",     syscallnames,           SYS_MAXSYSCALL },
                    112:        { "linux",      linux_syscallnames,     LINUX_SYS_MAXSYSCALL },
1.49      miod      113:        { NULL,         NULL,                   0 }
1.1       deraadt   114: };
                    115:
1.59      otto      116: static struct emulation *current;
1.60      otto      117: static struct emulation *def_emul;
1.59      otto      118:
                    119: struct pid_emul {
                    120:        struct emulation *e;
                    121:        pid_t p;
                    122: };
                    123:
                    124: static struct pid_emul *pe_table;
                    125: static size_t pe_size;
1.1       deraadt   126:
                    127:
                    128: static char *ptrace_ops[] = {
                    129:        "PT_TRACE_ME",  "PT_READ_I",    "PT_READ_D",    "PT_READ_U",
                    130:        "PT_WRITE_I",   "PT_WRITE_D",   "PT_WRITE_U",   "PT_CONTINUE",
1.15      art       131:        "PT_KILL",      "PT_ATTACH",    "PT_DETACH",    "PT_IO",
1.64      guenther  132:        "PT_SET_EVENT_MASK", "PT_GET_EVENT_MASK", "PT_GET_PROCESS_STATE",
1.71      guenther  133:        "PT_GET_THREAD_FIRST", "PT_GET_THREAD_NEXT",
1.1       deraadt   134: };
                    135:
1.59      otto      136: static void mappidtoemul(pid_t, struct emulation *);
                    137: static struct emulation * findemul(pid_t);
1.37      tedu      138: static int fread_tail(void *, size_t, size_t);
1.13      millert   139: static void dumpheader(struct ktr_header *);
                    140: static void ktrcsw(struct ktr_csw *);
1.37      tedu      141: static void ktremul(char *, size_t);
                    142: static void ktrgenio(struct ktr_genio *, size_t);
                    143: static void ktrnamei(const char *, size_t);
1.13      millert   144: static void ktrpsig(struct ktr_psig *);
                    145: static void ktrsyscall(struct ktr_syscall *);
1.62      otto      146: static const char *kresolvsysctl(int, int *, int);
1.13      millert   147: static void ktrsysret(struct ktr_sysret *);
1.81      miod      148: static void ktruser(struct ktr_user *, size_t);
1.13      millert   149: static void setemul(const char *);
                    150: static void usage(void);
1.92    ! guenther  151: static void ioctldecode(int);
        !           152: static void ptracedecode(int);
1.61      matthew   153: static void atfd(int);
1.77      guenther  154: static void polltimeout(int);
1.82      guenther  155: static void wait4pid(int);
1.83      guenther  156: static void signame(int);
                    157: static void semctlname(int);
                    158: static void shmctlname(int);
                    159: static void semgetname(int);
1.92    ! guenther  160: static void flagsandmodename(int);
1.83      guenther  161: static void clockname(int);
                    162: static void sockoptlevelname(int);
1.88      guenther  163: static void ktraceopname(int);
1.12      espie     164:
1.1       deraadt   165: int
1.17      deraadt   166: main(int argc, char *argv[])
1.1       deraadt   167: {
1.37      tedu      168:        int ch, silent;
                    169:        size_t ktrlen, size;
1.17      deraadt   170:        int trpoints = ALL_POINTS;
1.12      espie     171:        void *m;
1.1       deraadt   172:
1.60      otto      173:        def_emul = current = &emulations[0];    /* native */
1.1       deraadt   174:
1.67      mikeb     175:        while ((ch = getopt(argc, argv, "e:f:dHlm:nrRp:Tt:xX")) != -1)
1.1       deraadt   176:                switch (ch) {
                    177:                case 'e':
                    178:                        setemul(optarg);
1.60      otto      179:                        def_emul = current;
1.1       deraadt   180:                        break;
                    181:                case 'f':
                    182:                        tracefile = optarg;
                    183:                        break;
                    184:                case 'd':
                    185:                        decimal = 1;
                    186:                        break;
1.67      mikeb     187:                case 'H':
                    188:                        needtid = 1;
                    189:                        break;
1.1       deraadt   190:                case 'l':
                    191:                        tail = 1;
                    192:                        break;
                    193:                case 'm':
                    194:                        maxdata = atoi(optarg);
                    195:                        break;
                    196:                case 'n':
                    197:                        fancy = 0;
                    198:                        break;
1.17      deraadt   199:                case 'p':
1.85      guenther  200:                        pid_opt = atoi(optarg);
1.17      deraadt   201:                        break;
1.55      otto      202:                case 'r':
                    203:                        resolv = 1;
                    204:                        break;
1.1       deraadt   205:                case 'R':
                    206:                        timestamp = 2;  /* relative timestamp */
                    207:                        break;
                    208:                case 'T':
                    209:                        timestamp = 1;
                    210:                        break;
                    211:                case 't':
                    212:                        trpoints = getpoints(optarg);
                    213:                        if (trpoints < 0)
                    214:                                errx(1, "unknown trace point in %s", optarg);
                    215:                        break;
1.31      tedu      216:                case 'x':
                    217:                        iohex = 1;
                    218:                        break;
                    219:                case 'X':
                    220:                        iohex = 2;
                    221:                        break;
1.1       deraadt   222:                default:
                    223:                        usage();
                    224:                }
1.5       deraadt   225:        if (argc > optind)
1.1       deraadt   226:                usage();
                    227:
1.37      tedu      228:        m = malloc(size = 1025);
1.1       deraadt   229:        if (m == NULL)
1.37      tedu      230:                err(1, NULL);
1.1       deraadt   231:        if (!freopen(tracefile, "r", stdin))
                    232:                err(1, "%s", tracefile);
1.67      mikeb     233:        if (fread_tail(&ktr_header, sizeof(struct ktr_header), 1) == 0 ||
                    234:            ktr_header.ktr_type != htobe32(KTR_START))
                    235:                errx(1, "%s: not a dump", tracefile);
1.1       deraadt   236:        while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
1.17      deraadt   237:                silent = 0;
1.59      otto      238:                if (pe_size == 0)
                    239:                        mappidtoemul(ktr_header.ktr_pid, current);
1.85      guenther  240:                if (pid_opt != -1 && pid_opt != ktr_header.ktr_pid)
1.17      deraadt   241:                        silent = 1;
                    242:                if (silent == 0 && trpoints & (1<<ktr_header.ktr_type))
1.1       deraadt   243:                        dumpheader(&ktr_header);
1.37      tedu      244:                ktrlen = ktr_header.ktr_len;
1.1       deraadt   245:                if (ktrlen > size) {
1.23      tedu      246:                        void *newm;
                    247:
1.64      guenther  248:                        if (ktrlen == SIZE_MAX)
                    249:                                errx(1, "data too long");
1.23      tedu      250:                        newm = realloc(m, ktrlen+1);
                    251:                        if (newm == NULL)
1.66      deraadt   252:                                err(1, "realloc");
1.23      tedu      253:                        m = newm;
1.1       deraadt   254:                        size = ktrlen;
                    255:                }
                    256:                if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
                    257:                        errx(1, "data too short");
1.17      deraadt   258:                if (silent)
                    259:                        continue;
1.1       deraadt   260:                if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
                    261:                        continue;
1.59      otto      262:                current = findemul(ktr_header.ktr_pid);
1.1       deraadt   263:                switch (ktr_header.ktr_type) {
                    264:                case KTR_SYSCALL:
                    265:                        ktrsyscall((struct ktr_syscall *)m);
                    266:                        break;
                    267:                case KTR_SYSRET:
                    268:                        ktrsysret((struct ktr_sysret *)m);
                    269:                        break;
                    270:                case KTR_NAMEI:
                    271:                        ktrnamei(m, ktrlen);
                    272:                        break;
                    273:                case KTR_GENIO:
                    274:                        ktrgenio((struct ktr_genio *)m, ktrlen);
                    275:                        break;
                    276:                case KTR_PSIG:
                    277:                        ktrpsig((struct ktr_psig *)m);
                    278:                        break;
                    279:                case KTR_CSW:
                    280:                        ktrcsw((struct ktr_csw *)m);
                    281:                        break;
                    282:                case KTR_EMUL:
                    283:                        ktremul(m, ktrlen);
1.59      otto      284:                        mappidtoemul(ktr_header.ktr_pid, current);
1.1       deraadt   285:                        break;
1.55      otto      286:                case KTR_STRUCT:
                    287:                        ktrstruct(m, ktrlen);
                    288:                        break;
1.81      miod      289:                case KTR_USER:
                    290:                        ktruser(m, ktrlen);
                    291:                        break;
1.1       deraadt   292:                }
                    293:                if (tail)
                    294:                        (void)fflush(stdout);
                    295:        }
1.12      espie     296:        exit(0);
1.1       deraadt   297: }
                    298:
1.59      otto      299: static void
                    300: mappidtoemul(pid_t pid, struct emulation *emul)
                    301: {
                    302:        size_t i;
                    303:        struct pid_emul *tmp;
                    304:
                    305:        for (i = 0; i < pe_size; i++) {
                    306:                if (pe_table[i].p == pid) {
                    307:                        pe_table[i].e = emul;
                    308:                        return;
                    309:                }
                    310:        }
1.90      doug      311:        tmp = reallocarray(pe_table, pe_size + 1, sizeof(*pe_table));
1.59      otto      312:        if (tmp == NULL)
                    313:                err(1, NULL);
                    314:        pe_table = tmp;
                    315:        pe_table[pe_size].p = pid;
                    316:        pe_table[pe_size].e = emul;
                    317:        pe_size++;
                    318: }
                    319:
                    320: static struct emulation*
                    321: findemul(pid_t pid)
                    322: {
                    323:        size_t i;
                    324:
                    325:        for (i = 0; i < pe_size; i++)
                    326:                if (pe_table[i].p == pid)
                    327:                        return pe_table[i].e;
1.60      otto      328:        return def_emul;
1.59      otto      329: }
                    330:
1.12      espie     331: static int
1.37      tedu      332: fread_tail(void *buf, size_t size, size_t num)
1.1       deraadt   333: {
                    334:        int i;
                    335:
                    336:        while ((i = fread(buf, size, num, stdin)) == 0 && tail) {
                    337:                (void)sleep(1);
                    338:                clearerr(stdin);
                    339:        }
                    340:        return (i);
                    341: }
                    342:
1.12      espie     343: static void
1.17      deraadt   344: dumpheader(struct ktr_header *kth)
1.1       deraadt   345: {
1.67      mikeb     346:        static struct timespec prevtime;
1.1       deraadt   347:        char unknown[64], *type;
1.67      mikeb     348:        struct timespec temp;
1.1       deraadt   349:
                    350:        switch (kth->ktr_type) {
                    351:        case KTR_SYSCALL:
                    352:                type = "CALL";
                    353:                break;
                    354:        case KTR_SYSRET:
                    355:                type = "RET ";
                    356:                break;
                    357:        case KTR_NAMEI:
                    358:                type = "NAMI";
                    359:                break;
                    360:        case KTR_GENIO:
                    361:                type = "GIO ";
                    362:                break;
                    363:        case KTR_PSIG:
                    364:                type = "PSIG";
                    365:                break;
                    366:        case KTR_CSW:
                    367:                type = "CSW";
                    368:                break;
                    369:        case KTR_EMUL:
                    370:                type = "EMUL";
                    371:                break;
1.55      otto      372:        case KTR_STRUCT:
                    373:                type = "STRU";
                    374:                break;
1.81      miod      375:        case KTR_USER:
                    376:                type = "USER";
                    377:                break;
1.1       deraadt   378:        default:
1.17      deraadt   379:                (void)snprintf(unknown, sizeof unknown, "UNKNOWN(%d)",
                    380:                    kth->ktr_type);
1.1       deraadt   381:                type = unknown;
                    382:        }
                    383:
1.67      mikeb     384:        (void)printf("%6ld", (long)kth->ktr_pid);
                    385:        if (needtid)
1.69      mikeb     386:                (void)printf("/%-7ld", (long)kth->ktr_tid);
1.67      mikeb     387:        (void)printf(" %-8.*s ", MAXCOMLEN, kth->ktr_comm);
1.1       deraadt   388:        if (timestamp) {
                    389:                if (timestamp == 2) {
1.67      mikeb     390:                        timespecsub(&kth->ktr_time, &prevtime, &temp);
1.1       deraadt   391:                        prevtime = kth->ktr_time;
                    392:                } else
                    393:                        temp = kth->ktr_time;
1.79      deraadt   394:                printf("%lld.%06ld ", (long long)temp.tv_sec,
                    395:                    temp.tv_nsec / 1000);
1.1       deraadt   396:        }
                    397:        (void)printf("%s  ", type);
                    398: }
                    399:
1.92    ! guenther  400: /*
        !           401:  * Base Formatters
        !           402:  */
        !           403:
        !           404: /* some syscalls have padding that shouldn't be shown */
        !           405: static int
        !           406: pad(long arg)
        !           407: {
        !           408:        /* nothing printed */
        !           409:        return (1);
        !           410: }
        !           411:
        !           412: /* a formatter that just saves the argument for the next formatter */
        !           413: int arg1;
        !           414: static int
        !           415: pass_two(long arg)
        !           416: {
        !           417:        arg1 = (int)arg;
        !           418:
        !           419:        /* nothing printed */
        !           420:        return (1);
        !           421: }
        !           422:
        !           423: static int
        !           424: pdeclong(long arg)
        !           425: {
        !           426:        (void)printf("%ld", arg);
        !           427:        return (0);
        !           428: }
        !           429:
        !           430: static int
        !           431: pdeculong(long arg)
1.2       deraadt   432: {
1.92    ! guenther  433:        (void)printf("%lu", arg);
        !           434:        return (0);
        !           435: }
1.2       deraadt   436:
1.92    ! guenther  437: static int
        !           438: phexlong(long arg)
        !           439: {
        !           440:        (void)printf("%#lx", arg);
        !           441:        return (0);
        !           442: }
1.2       deraadt   443:
1.92    ! guenther  444: static int
        !           445: pnonfancy(long arg)
        !           446: {
        !           447:        if (decimal)
        !           448:                (void)printf("%ld", arg);
1.2       deraadt   449:        else
1.92    ! guenther  450:                (void)printf("%#lx", arg);
        !           451:        return (0);
1.2       deraadt   452: }
1.1       deraadt   453:
1.52      otto      454: static void
1.92    ! guenther  455: pdecint(int arg)
1.52      otto      456: {
1.92    ! guenther  457:        (void)printf("%d", arg);
1.52      otto      458: }
                    459:
                    460: static void
1.92    ! guenther  461: pdecuint(int arg)
1.52      otto      462: {
1.92    ! guenther  463:        (void)printf("%u", arg);
1.52      otto      464: }
                    465:
                    466: static void
1.92    ! guenther  467: phexint(int arg)
1.52      otto      468: {
1.92    ! guenther  469:        (void)printf("%#x", arg);
1.52      otto      470: }
1.92    ! guenther  471:
1.52      otto      472: static void
1.92    ! guenther  473: poctint(int arg)
        !           474: {
        !           475:        (void)printf("%#o", arg);
        !           476: }
        !           477:
        !           478:
        !           479: #ifdef __LP64__
        !           480:
        !           481: /* on LP64, long long arguments are the same as long arguments */
        !           482: #define Phexlonglong   Phexlong
        !           483: #define phexll         NULL            /* not actually used on LP64 */
        !           484:
        !           485: #else /* __LP64__ */
        !           486:
        !           487: /* on ILP32, long long arguments are passed as two 32bit args */
        !           488: #define Phexlonglong   PASS_LONGLONG, Phexll
        !           489:
        !           490: static int
        !           491: phexll(long arg2)
1.52      otto      492: {
1.92    ! guenther  493:        long long val;
        !           494:
        !           495: #if _BYTE_ORDER == _LITTLE_ENDIAN
        !           496:        val = ((long long)arg2 << 32) | ((long long)arg1 & 0xffffffff);
        !           497: #else
        !           498:        val = ((long long)arg1 << 32) | ((long long)arg2 & 0xffffffff);
        !           499: #endif
        !           500:
        !           501:        if (fancy || !decimal)
        !           502:                (void)printf("%#llx", val);
        !           503:        else
1.52      otto      504:                (void)printf("%lld", val);
1.92    ! guenther  505:        return (0);
1.52      otto      506: }
1.92    ! guenther  507:
        !           508: #endif /* __LP64__ */
        !           509:
        !           510: static int (*long_formatters[])(long) = {
        !           511:        NULL,
        !           512:        pdeclong,
        !           513:        pdeculong,
        !           514:        phexlong,
        !           515:        pass_two,
        !           516:        pass_two,
        !           517:        phexll,
        !           518:        pad,
        !           519:        pnonfancy,
        !           520: };
        !           521:
        !           522: static void (*formatters[])(int) = {
        !           523:        NULL,
        !           524:        pdecint,
        !           525:        phexint,
        !           526:        poctint,
        !           527:        pdecuint,
        !           528:        ioctldecode,
        !           529:        ptracedecode,
        !           530:        atfd,
        !           531:        polltimeout,
        !           532:        wait4pid,
        !           533:        signame,
        !           534:        semctlname,
        !           535:        shmctlname,
        !           536:        semgetname,
        !           537:        flagsandmodename,
        !           538:        clockname,
        !           539:        sockoptlevelname,
        !           540:        ktraceopname,
        !           541:        fcntlcmdname,
        !           542:        modename,
        !           543:        flagsname,
        !           544:        openflagsname,
        !           545:        atflagsname,
        !           546:        accessmodename,
        !           547:        mmapprotname,
        !           548:        mmapflagsname,
        !           549:        wait4optname,
        !           550:        sendrecvflagsname,
        !           551:        mountflagsname,
        !           552:        rebootoptname,
        !           553:        flockname,
        !           554:        sockoptname,
        !           555:        sockdomainname,
        !           556:        sockipprotoname,
        !           557:        socktypename,
        !           558:        sockflagsname,
        !           559:        sockfamilyname,
        !           560:        mlockallname,
        !           561:        shmatname,
        !           562:        whencename,
        !           563:        pathconfname,
        !           564:        rlimitname,
        !           565:        shutdownhowname,
        !           566:        prioname,
        !           567:        madvisebehavname,
        !           568:        msyncflagsname,
        !           569:        clocktypename,
        !           570:        rusagewho,
        !           571:        sigactionflagname,
        !           572:        sigprocmaskhowname,
        !           573:        minheritname,
        !           574:        quotactlname,
        !           575:        sigill_name,
        !           576:        sigtrap_name,
        !           577:        sigemt_name,
        !           578:        sigfpe_name,
        !           579:        sigbus_name,
        !           580:        sigsegv_name,
        !           581:        sigchld_name,
        !           582:        ktracefacname,
        !           583:        itimername,
        !           584:        sigset,
        !           585: };
        !           586:
        !           587: enum {
        !           588:        /* the end of the (known) arguments is recognized by the zero fill */
        !           589:        end_of_args     =  0,
        !           590:
        !           591:        /* negative are the negative of the index into long_formatters[] */
        !           592:        Pdeclong        = -1,
        !           593:        Pdeculong       = -2,
        !           594:        Phexlong        = -3,
        !           595:        PASS_TWO        = -4,
        !           596:
        !           597: /* the remaining long formatters still get called when non-fancy (-n option) */
        !           598: #define FMT_IS_NONFANCY(x)     ((x) <= PASS_LONGLONG)
        !           599:        PASS_LONGLONG   = -5,
        !           600:        Phexll          = -6,
        !           601:        PAD             = -7,
        !           602:        Pnonfancy       = -8,
        !           603:
        !           604:        /* positive values are the index into formatters[] */
        !           605:        Pdecint         = 1,
        !           606:        Phexint,
        !           607:        Poctint,
        !           608:        Pdecuint,
        !           609:        Ioctldecode,
        !           610:        Ptracedecode,
        !           611:        Atfd,
        !           612:        Polltimeout,
        !           613:        Wait4pid,
        !           614:        Signame,
        !           615:        Semctlname,
        !           616:        Shmctlname,
        !           617:        Semgetname,
        !           618:        Flagsandmodename,
        !           619:        Clockname,
        !           620:        Sockoptlevelname,
        !           621:        Ktraceopname,
        !           622:        Fcntlcmdname,
        !           623:        Modename,
        !           624:        Flagsname,
        !           625:        Openflagsname,
        !           626:        Atflagsname,
        !           627:        Accessmodename,
        !           628:        Mmapprotname,
        !           629:        Mmapflagsname,
        !           630:        Wait4optname,
        !           631:        Sendrecvflagsname,
        !           632:        Mountflagsname,
        !           633:        Rebootoptname,
        !           634:        Flockname,
        !           635:        Sockoptname,
        !           636:        Sockdomainname,
        !           637:        Sockipprotoname,
        !           638:        Socktypename,
        !           639:        Sockflagsname,
        !           640:        Sockfamilyname,
        !           641:        Mlockallname,
        !           642:        Shmatname,
        !           643:        Whencename,
        !           644:        Pathconfname,
        !           645:        Rlimitname,
        !           646:        Shutdownhowname,
        !           647:        Prioname,
        !           648:        Madvisebehavname,
        !           649:        Msyncflagsname,
        !           650:        Clocktypename,
        !           651:        Rusagewho,
        !           652:        Sigactionflagname,
        !           653:        Sigprocmaskhowname,
        !           654:        Minheritname,
        !           655:        Quotactlname,
        !           656:        Sigill_name,
        !           657:        Sigtrap_name,
        !           658:        Sigemt_name,
        !           659:        Sigfpe_name,
        !           660:        Sigbus_name,
        !           661:        Sigsegv_name,
        !           662:        Sigchld_name,
        !           663:        Ktracefacname,
        !           664:        Itimername,
        !           665:        Sigset,
        !           666: };
        !           667:
        !           668: #define Pptr           Phexlong
        !           669: #define        Psize           Pdeculong       /* size_t for small buffers */
        !           670: #define        Pbigsize        Phexlong        /* size_t for I/O buffers */
        !           671: #define Pcount         Pdecint         /* int for a count of something */
        !           672: #define Pfd            Pdecint
        !           673: #define Ppath          Phexlong
        !           674: #define Pdev_t         Pdecint
        !           675: #define Ppid_t         Pdecint
        !           676: #define Ppgid          Pdecint         /* pid or negative pgid */
        !           677: #define Poff_t         Phexlonglong
        !           678: #define Pmsqid         Pdecint
        !           679: #define Pshmid         Pdecint
        !           680: #define Psemid         Pdecint
        !           681: #define Pkey_t         Pdecint
        !           682: #define Pucount                Pdecuint
        !           683: #define Puid_t         Pdecuint
        !           684: #define Pgid_t         Pdecuint
        !           685: #define Chflagsname    Phexlong        /* to be added */
        !           686: #define Sockprotoname  Phexlong        /* to be added */
        !           687: #define Swapctlname    Phexlong        /* to be added */
        !           688: #define Msgflgname     Phexlong        /* to be added */
        !           689:
        !           690:
        !           691: typedef signed char formatter;
        !           692: static const formatter scargs[][8] = {
        !           693:     [SYS_exit]         = { Pdecint },
        !           694:     [SYS_read]         = { Pfd, Pptr, Pbigsize },
        !           695:     [SYS_write]                = { Pfd, Pptr, Pbigsize },
        !           696:     [SYS_open]         = { Ppath, PASS_TWO, Flagsandmodename },
        !           697:     [SYS_close]                = { Pfd },
        !           698:     [SYS_getentropy]   = { Pptr, Psize },
        !           699:     [SYS___tfork]      = { Pptr, Psize },
        !           700:     [SYS_link]         = { Ppath, Ppath },
        !           701:     [SYS_unlink]       = { Ppath },
        !           702:     [SYS_wait4]                = { Wait4pid, Pptr, Wait4optname },
        !           703:     [SYS_chdir]                = { Ppath },
        !           704:     [SYS_fchdir]       = { Pfd },
        !           705:     [SYS_mknod]                = { Ppath, Modename, Pdev_t },
        !           706:     [SYS_chmod]                = { Ppath, Modename },
        !           707:     [SYS_chown]                = { Ppath, Puid_t, Pgid_t },
        !           708:     [SYS_break]                = { Pptr },
        !           709:     [SYS_getrusage]    = { Rusagewho, Pptr },
        !           710:     [SYS_mount]                = { Pptr, Ppath, Mountflagsname, Pptr },
        !           711:     [SYS_unmount]      = { Ppath, Mountflagsname },
        !           712:     [SYS_setuid]       = { Puid_t },
        !           713:     [SYS_ptrace]       = { Ptracedecode, Ppid_t, Pptr, Pdecint },
        !           714:     [SYS_recvmsg]      = { Pfd, Pptr, Sendrecvflagsname },
        !           715:     [SYS_sendmsg]      = { Pfd, Pptr, Sendrecvflagsname },
        !           716:     [SYS_recvfrom]     = { Pfd, Pptr, Pbigsize, Sendrecvflagsname },
        !           717:     [SYS_accept]       = { Pfd, Pptr, Pptr },
        !           718:     [SYS_getpeername]  = { Pfd, Pptr, Pptr },
        !           719:     [SYS_getsockname]  = { Pfd, Pptr, Pptr },
        !           720:     [SYS_access]       = { Ppath, Accessmodename },
        !           721:     [SYS_chflags]      = { Ppath, Chflagsname },
        !           722:     [SYS_fchflags]     = { Pfd, Chflagsname },
        !           723:     [SYS_kill]         = { Ppgid, Signame },
        !           724:     [SYS_stat]         = { Ppath, Pptr },
        !           725:     [SYS_lstat]                = { Ppath, Pptr },
        !           726:     [SYS_dup]          = { Pfd },
        !           727:     [SYS_fstatat]      = { Atfd, Ppath, Pptr, Atflagsname },
        !           728:     [SYS_profil]       = { Pptr, Pbigsize, Pbigsize, Pdecuint },
        !           729:     [SYS_ktrace]       = { Ppath, Ktraceopname, Ktracefacname, Ppgid },
        !           730:     [SYS_sigaction]    = { Signame, Pptr, Pptr },
        !           731:     [SYS_sigprocmask]  = { Sigprocmaskhowname, Sigset },
        !           732:     [SYS_getlogin]     = { Pptr, Pucount },
        !           733:     [SYS_setlogin]     = { Pptr },
        !           734:     [SYS_acct]         = { Ppath },
        !           735:     [SYS_fstat]                = { Pfd, Pptr },
        !           736:     [SYS_ioctl]                = { Pfd, Ioctldecode, Pptr },
        !           737:     [SYS_reboot]       = { Rebootoptname },
        !           738:     [SYS_revoke]       = { Ppath },
        !           739:     [SYS_symlink]      = { Ppath, Ppath },
        !           740:     [SYS_readlink]     = { Ppath, Pptr, Psize },
        !           741:     [SYS_execve]       = { Ppath, Pptr, Pptr },
        !           742:     [SYS_umask]                = { Modename },
        !           743:     [SYS_chroot]       = { Ppath },
        !           744:     [SYS_getfsstat]    = { Pptr, Pbigsize, Mountflagsname },
        !           745:     [SYS_statfs]       = { Ppath, Pptr },
        !           746:     [SYS_fstatfs]      = { Pfd, Pptr },
        !           747:     [SYS_fhstatfs]     = { Pptr, Pptr },
        !           748:     [SYS_gettimeofday] = { Pptr, Pptr },
        !           749:     [SYS_settimeofday] = { Pptr, Pptr },
        !           750:     [SYS_setitimer]    = { Itimername, Pptr, Pptr },
        !           751:     [SYS_getitimer]    = { Itimername, Pptr },
        !           752:     [SYS_select]       = { Pcount, Pptr, Pptr, Pptr, Pptr },
        !           753:     [SYS_kevent]       = { Pfd, Pptr, Pcount, Pptr, Pcount, Pptr },
        !           754:     [SYS_munmap]       = { Pptr, Pbigsize },
        !           755:     [SYS_mprotect]     = { Pptr, Pbigsize, Mmapprotname },
        !           756:     [SYS_madvise]      = { Pptr, Pbigsize, Madvisebehavname },
        !           757:     [SYS_utimes]       = { Ppath, Pptr },
        !           758:     [SYS_futimes]      = { Pfd, Pptr },
        !           759:     [SYS_mincore]      = { Pptr, Pbigsize, Pptr },
        !           760:     [SYS_getgroups]    = { Pcount, Pptr },
        !           761:     [SYS_setgroups]    = { Pcount, Pptr },
        !           762:     [SYS_setpgid]      = { Ppid_t, Ppid_t },
        !           763:     [SYS_sendsyslog]   = { Pptr, Psize },
        !           764:     [SYS_utimensat]    = { Atfd, Ppath, Pptr, Atflagsname },
        !           765:     [SYS_futimens]     = { Pfd, Pptr },
        !           766:     [SYS_clock_gettime]        = { Clockname, Pptr },
        !           767:     [SYS_clock_settime]        = { Clockname, Pptr },
        !           768:     [SYS_clock_getres] = { Clockname, Pptr },
        !           769:     [SYS_dup2]         = { Pfd, Pfd },
        !           770:     [SYS_nanosleep]    = { Pptr, Pptr },
        !           771:     [SYS_fcntl]                = { Pfd, PASS_TWO, Fcntlcmdname },
        !           772:     [SYS_accept4]      = { Pfd, Pptr, Pptr, Sockflagsname },
        !           773:     [SYS___thrsleep]   = { Pptr, Clockname, Pptr, Pptr, Pptr },
        !           774:     [SYS_fsync]                = { Pfd },
        !           775:     [SYS_setpriority]  = { Prioname, Ppid_t, Pdecint },
        !           776:     [SYS_socket]       = { Sockdomainname, Socktypename, Sockprotoname },
        !           777:     [SYS_connect]      = { Pfd, Pptr, Pucount },
        !           778:     [SYS_getdents]     = { Pfd, Pptr, Pbigsize },
        !           779:     [SYS_getpriority]  = { Prioname, Ppid_t },
        !           780:     [SYS_pipe2]                = { Pptr, Flagsname },
        !           781:     [SYS_dup3]         = { Pfd, Pfd, Flagsname },
        !           782:     [SYS_sigreturn]    = { Pptr },
        !           783:     [SYS_bind]         = { Pfd, Pptr, Pucount },
        !           784:     [SYS_setsockopt]   = { Pfd, PASS_TWO, Sockoptlevelname, Pptr, Pdecint },
        !           785:     [SYS_listen]       = { Pfd, Pdecint },
        !           786:     [SYS_chflagsat]    = { Atfd, Ppath, Chflagsname, Atflagsname },
        !           787:     [SYS_ppoll]                = { Pptr, Pucount, Pptr, Pptr },
        !           788:     [SYS_pselect]      = { Pcount, Pptr, Pptr, Pptr, Pptr, Pptr },
        !           789:     [SYS_sigsuspend]   = { Sigset },
        !           790:     [SYS_getsockopt]   = { Pfd, PASS_TWO, Sockoptlevelname, Pptr, Pptr },
        !           791:     [SYS_readv]                = { Pfd, Pptr, Pcount },
        !           792:     [SYS_writev]       = { Pfd, Pptr, Pcount },
        !           793:     [SYS_fchown]       = { Pfd, Puid_t, Pgid_t },
        !           794:     [SYS_fchmod]       = { Pfd, Modename },
        !           795:     [SYS_setreuid]     = { Puid_t, Puid_t },
        !           796:     [SYS_setregid]     = { Pgid_t, Pgid_t },
        !           797:     [SYS_rename]       = { Ppath, Ppath },
        !           798:     [SYS_flock]                = { Pfd, Flockname },
        !           799:     [SYS_mkfifo]       = { Ppath, Modename },
        !           800:     [SYS_sendto]       = { Pfd, Pptr, Pbigsize, Sendrecvflagsname },
        !           801:     [SYS_shutdown]     = { Pfd, Shutdownhowname },
        !           802:     [SYS_socketpair]   = { Sockdomainname, Socktypename, Sockprotoname, Pptr },
        !           803:     [SYS_mkdir]                = { Ppath, Modename },
        !           804:     [SYS_rmdir]                = { Ppath },
        !           805:     [SYS_adjtime]      = { Pptr, Pptr },
        !           806:     [SYS_quotactl]     = { Ppath, Quotactlname, Puid_t, Pptr },
        !           807:     [SYS_nfssvc]       = { Phexint, Pptr },
        !           808:     [SYS_getfh]                = { Ppath, Pptr },
        !           809:     [SYS_sysarch]      = { Pdecint, Pptr },
        !           810:     [SYS_pread]                = { Pfd, Pptr, Pbigsize, PAD, Poff_t },
        !           811:     [SYS_pwrite]       = { Pfd, Pptr, Pbigsize, PAD, Poff_t },
        !           812:     [SYS_setgid]       = { Pgid_t },
        !           813:     [SYS_setegid]      = { Pgid_t },
        !           814:     [SYS_seteuid]      = { Puid_t },
        !           815:     [SYS_pathconf]     = { Ppath, Pathconfname },
        !           816:     [SYS_fpathconf]    = { Pfd, Pathconfname },
        !           817:     [SYS_swapctl]      = { Swapctlname, Pptr, Pdecint },
        !           818:     [SYS_getrlimit]    = { Rlimitname, Pptr },
        !           819:     [SYS_setrlimit]    = { Rlimitname, Pptr },
        !           820:     [SYS_mmap]         = { Pptr, Pbigsize, Mmapprotname, Mmapflagsname, Pfd, PAD, Poff_t },
        !           821:     [SYS_lseek]                = { Pfd, PAD, Poff_t, Whencename },
        !           822:     [SYS_truncate]     = { Ppath, PAD, Poff_t },
        !           823:     [SYS_ftruncate]    = { Pfd, PAD, Poff_t },
        !           824:     /* [SYS___sysctl]  = { }, Magic */
        !           825:     [SYS_mlock]                = { Pptr, Pbigsize },
        !           826:     [SYS_munlock]      = { Pptr, Pbigsize },
        !           827:     [SYS_getpgid]      = { Ppid_t },
        !           828:     [SYS_utrace]       = { Pptr, Pptr, Psize },
        !           829:     [SYS_semget]       = { Pkey_t, Pcount, Semgetname },
        !           830:     [SYS_msgget]       = { Pkey_t, Msgflgname },
        !           831:     [SYS_msgsnd]       = { Pmsqid, Pptr, Psize, Msgflgname },
        !           832:     [SYS_msgrcv]       = { Pmsqid, Pptr, Psize, Pdeclong, Msgflgname },
        !           833:     [SYS_shmat]                = { Pshmid, Pptr, Shmatname },
        !           834:     [SYS_shmdt]                = { Pptr },
        !           835:     [SYS_minherit]     = { Pptr, Pbigsize, Minheritname },
        !           836:     [SYS_poll]         = { Pptr, Pucount, Polltimeout },
        !           837:     [SYS_lchown]       = { Ppath, Puid_t, Pgid_t },
        !           838:     [SYS_getsid]       = { Ppid_t },
        !           839:     [SYS_msync]                = { Pptr, Pbigsize, Msyncflagsname },
        !           840:     [SYS_pipe]         = { Pptr },
        !           841:     [SYS_fhopen]       = { Pptr, Openflagsname },
        !           842:     [SYS_preadv]       = { Pfd, Pptr, Pcount, PAD, Poff_t },
        !           843:     [SYS_pwritev]      = { Pfd, Pptr, Pcount, PAD, Poff_t },
        !           844:     [SYS_mlockall]     = { Mlockallname },
        !           845:     [SYS_getresuid]    = { Pptr, Pptr, Pptr },
        !           846:     [SYS_setresuid]    = { Puid_t, Puid_t, Puid_t },
        !           847:     [SYS_getresgid]    = { Pptr, Pptr, Pptr },
        !           848:     [SYS_setresgid]    = { Pgid_t, Pgid_t, Pgid_t },
        !           849:     [SYS_mquery]       = { Pptr, Pbigsize, Mmapprotname, Mmapflagsname, Pfd, PAD, Poff_t },
        !           850:     [SYS_closefrom]    = { Pfd },
        !           851:     [SYS_sigaltstack]  = { Pptr, Pptr },
        !           852:     [SYS_shmget]       = { Pkey_t, Pbigsize, Semgetname },
        !           853:     [SYS_semop]                = { Psemid, Pptr, Psize },
        !           854:     [SYS_fhstat]       = { Pptr, Pptr },
        !           855:     [SYS___semctl]     = { Psemid, Pcount, Semctlname, Pptr },
        !           856:     [SYS_shmctl]       = { Pshmid, Shmctlname, Pptr },
        !           857:     [SYS_msgctl]       = { Pmsqid, Shmctlname, Pptr },
        !           858:     [SYS___thrwakeup]  = { Pptr, Pcount },
        !           859:     [SYS___threxit]    = { Pptr },
        !           860:     [SYS___thrsigdivert] = { Sigset, Pptr, Pptr },
        !           861:     [SYS___getcwd]     = { Pptr, Psize },
        !           862:     [SYS_adjfreq]      = { Pptr, Pptr },
        !           863:     [SYS_setrtable]    = { Pdecint },
        !           864:     [SYS_faccessat]    = { Atfd, Ppath, Accessmodename, Atflagsname },
        !           865:     [SYS_fchmodat]     = { Atfd, Ppath, Modename, Atflagsname },
        !           866:     [SYS_fchownat]     = { Atfd, Ppath, Puid_t, Pgid_t, Atflagsname },
        !           867:     [SYS_linkat]       = { Atfd, Ppath, Atfd, Ppath, Atflagsname },
        !           868:     [SYS_mkdirat]      = { Atfd, Ppath, Modename },
        !           869:     [SYS_mkfifoat]     = { Atfd, Ppath, Modename },
        !           870:     [SYS_mknodat]      = { Atfd, Ppath, Modename, Pdev_t },
        !           871:     [SYS_openat]       = { Atfd, Ppath, PASS_TWO, Flagsandmodename },
        !           872:     [SYS_readlinkat]   = { Atfd, Ppath, Pptr, Psize },
        !           873:     [SYS_renameat]     = { Atfd, Ppath, Atfd, Ppath },
        !           874:     [SYS_symlinkat]    = { Atfd, Ppath, Ppath },
        !           875:     [SYS_unlinkat]     = { Atfd, Ppath, Atflagsname },
        !           876:     [SYS___set_tcb]    = { Pptr },
        !           877: };
        !           878:
1.51      otto      879:
1.12      espie     880: static void
1.17      deraadt   881: ktrsyscall(struct ktr_syscall *ktr)
1.1       deraadt   882: {
1.92    ! guenther  883:        register_t *ap;
        !           884:        int narg;
        !           885:        char sep;
        !           886:
1.52      otto      887:        narg = ktr->ktr_argsize / sizeof(register_t);
                    888:        sep = '\0';
1.1       deraadt   889:
                    890:        if (ktr->ktr_code >= current->nsysnames || ktr->ktr_code < 0)
                    891:                (void)printf("[%d]", ktr->ktr_code);
                    892:        else
                    893:                (void)printf("%s", current->sysnames[ktr->ktr_code]);
                    894:        ap = (register_t *)((char *)ktr + sizeof(struct ktr_syscall));
1.27      mickey    895:        (void)putchar('(');
1.52      otto      896:
1.54      otto      897:        if (current != &emulations[0])
                    898:                goto nonnative;
                    899:
1.92    ! guenther  900:        if (ktr->ktr_code == SYS___sysctl) {
1.62      otto      901:                const char *s;
                    902:                int *np, n, i, *top;
1.52      otto      903:
                    904:                if (!fancy)
1.92    ! guenther  905:                        goto nonnative;
1.52      otto      906:                n = ap[1];
                    907:                if (n > CTL_MAXNAME)
                    908:                        n = CTL_MAXNAME;
1.62      otto      909:                np = top = (int *)(ap + 6);
                    910:                for (i = 0; n--; np++, i++) {
1.52      otto      911:                        if (sep)
                    912:                                putchar(sep);
1.62      otto      913:                        if (resolv && (s = kresolvsysctl(i, top, *np)) != NULL)
                    914:                                printf("%s", s);
                    915:                        else
                    916:                                printf("%d", *np);
1.52      otto      917:                        sep = '.';
1.1       deraadt   918:                }
1.52      otto      919:
                    920:                sep = ',';
                    921:                ap += 2;
                    922:                narg -= 2;
1.92    ! guenther  923:        } else if (ktr->ktr_code < nitems(scargs)) {
        !           924:                const formatter *fmts = scargs[ktr->ktr_code];
        !           925:                int fmt;
1.52      otto      926:
1.92    ! guenther  927:                while (narg && (fmt = *fmts) != 0) {
        !           928:                        if (sep)
        !           929:                                putchar(sep);
        !           930:                        sep = ',';
        !           931:                        if (!fancy && !FMT_IS_NONFANCY(fmt))
        !           932:                                fmt = Pnonfancy;
        !           933:                        if (fmt > 0)
        !           934:                                formatters[fmt]((int)*ap);
        !           935:                        else if (long_formatters[-fmt](*ap))
        !           936:                                sep = '\0';
        !           937:                        fmts++;
        !           938:                        ap++;
        !           939:                        narg--;
        !           940:                }
1.52      otto      941:        }
                    942:
1.54      otto      943: nonnative:
1.52      otto      944:        while (narg) {
                    945:                if (sep)
                    946:                        putchar(sep);
                    947:                if (decimal)
                    948:                        (void)printf("%ld", (long)*ap);
                    949:                else
                    950:                        (void)printf("%#lx", (long)*ap);
                    951:                sep = ',';
                    952:                ap++;
                    953:                narg--;
1.1       deraadt   954:        }
1.27      mickey    955:        (void)printf(")\n");
1.62      otto      956: }
                    957:
                    958: static struct ctlname topname[] = CTL_NAMES;
                    959: static struct ctlname kernname[] = CTL_KERN_NAMES;
                    960: static struct ctlname vmname[] = CTL_VM_NAMES;
                    961: static struct ctlname fsname[] = CTL_FS_NAMES;
                    962: static struct ctlname netname[] = CTL_NET_NAMES;
                    963: static struct ctlname hwname[] = CTL_HW_NAMES;
                    964: static struct ctlname debugname[CTL_DEBUG_MAXID];
                    965: static struct ctlname kernmallocname[] = CTL_KERN_MALLOC_NAMES;
                    966: static struct ctlname forkstatname[] = CTL_KERN_FORKSTAT_NAMES;
                    967: static struct ctlname nchstatsname[] = CTL_KERN_NCHSTATS_NAMES;
1.88      guenther  968: static struct ctlname kernprocname[] = {
1.64      guenther  969:        { NULL },
                    970:        { "all" },
                    971:        { "pid" },
                    972:        { "pgrp" },
                    973:        { "session" },
                    974:        { "tty" },
                    975:        { "uid" },
                    976:        { "ruid" },
1.77      guenther  977:        { "kthread" },
1.64      guenther  978: };
1.62      otto      979: static struct ctlname ttysname[] = CTL_KERN_TTY_NAMES;
                    980: static struct ctlname semname[] = CTL_KERN_SEMINFO_NAMES;
                    981: static struct ctlname shmname[] = CTL_KERN_SHMINFO_NAMES;
                    982: static struct ctlname watchdogname[] = CTL_KERN_WATCHDOG_NAMES;
                    983: static struct ctlname tcname[] = CTL_KERN_TIMECOUNTER_NAMES;
                    984: #ifdef CTL_MACHDEP_NAMES
                    985: static struct ctlname machdepname[] = CTL_MACHDEP_NAMES;
                    986: #endif
                    987: static struct ctlname ddbname[] = CTL_DDB_NAMES;
                    988:
                    989: #ifndef nitems
                    990: #define nitems(_a)    (sizeof((_a)) / sizeof((_a)[0]))
                    991: #endif
                    992:
                    993: #define SETNAME(name) do { names = (name); limit = nitems(name); } while (0)
                    994:
                    995: static const char *
                    996: kresolvsysctl(int depth, int *top, int idx)
                    997: {
                    998:        struct ctlname *names;
                    999:        size_t          limit;
                   1000:
                   1001:        names = NULL;
                   1002:
                   1003:        switch (depth) {
                   1004:        case 0:
                   1005:                SETNAME(topname);
                   1006:                break;
                   1007:        case 1:
                   1008:                switch (top[0]) {
                   1009:                case CTL_KERN:
                   1010:                        SETNAME(kernname);
                   1011:                        break;
                   1012:                case CTL_VM:
                   1013:                        SETNAME(vmname);
                   1014:                        break;
                   1015:                case CTL_FS:
                   1016:                        SETNAME(fsname);
                   1017:                        break;
                   1018:                case CTL_NET:
                   1019:                        SETNAME(netname);
                   1020:                        break;
                   1021:                case CTL_DEBUG:
                   1022:                        SETNAME(debugname);
                   1023:                        break;
                   1024:                case CTL_HW:
                   1025:                        SETNAME(hwname);
                   1026:                        break;
                   1027: #ifdef CTL_MACHDEP_NAMES
                   1028:                case CTL_MACHDEP:
                   1029:                        SETNAME(machdepname);
                   1030:                        break;
                   1031: #endif
                   1032:                case CTL_DDB:
                   1033:                        SETNAME(ddbname);
                   1034:                        break;
                   1035:                }
                   1036:                break;
                   1037:        case 2:
                   1038:                switch (top[0]) {
                   1039:                case CTL_KERN:
                   1040:                        switch (top[1]) {
                   1041:                        case KERN_MALLOCSTATS:
                   1042:                                SETNAME(kernmallocname);
                   1043:                                break;
                   1044:                        case KERN_FORKSTAT:
                   1045:                                SETNAME(forkstatname);
                   1046:                                break;
                   1047:                        case KERN_NCHSTATS:
                   1048:                                SETNAME(nchstatsname);
                   1049:                                break;
                   1050:                        case KERN_TTY:
                   1051:                                SETNAME(ttysname);
                   1052:                                break;
                   1053:                        case KERN_SEMINFO:
                   1054:                                SETNAME(semname);
                   1055:                                break;
                   1056:                        case KERN_SHMINFO:
                   1057:                                SETNAME(shmname);
                   1058:                                break;
                   1059:                        case KERN_WATCHDOG:
                   1060:                                SETNAME(watchdogname);
                   1061:                                break;
1.64      guenther 1062:                        case KERN_PROC:
                   1063:                                idx++;  /* zero is valid at this level */
                   1064:                                SETNAME(kernprocname);
                   1065:                                break;
1.62      otto     1066:                        case KERN_TIMECOUNTER:
                   1067:                                SETNAME(tcname);
                   1068:                                break;
                   1069:                        }
                   1070:                }
                   1071:                break;
                   1072:        }
                   1073:        if (names != NULL && idx > 0 && idx < limit)
                   1074:                return (names[idx].ctl_name);
                   1075:        return (NULL);
1.1       deraadt  1076: }
                   1077:
1.12      espie    1078: static void
1.17      deraadt  1079: ktrsysret(struct ktr_sysret *ktr)
1.1       deraadt  1080: {
1.50      deraadt  1081:        register_t ret = ktr->ktr_retval;
1.12      espie    1082:        int error = ktr->ktr_error;
                   1083:        int code = ktr->ktr_code;
1.1       deraadt  1084:
                   1085:        if (code >= current->nsysnames || code < 0)
                   1086:                (void)printf("[%d] ", code);
1.59      otto     1087:        else {
1.1       deraadt  1088:                (void)printf("%s ", current->sysnames[code]);
1.59      otto     1089:                if (ret > 0 && (strcmp(current->sysnames[code], "fork") == 0 ||
                   1090:                    strcmp(current->sysnames[code], "vfork") == 0 ||
1.64      guenther 1091:                    strcmp(current->sysnames[code], "__tfork") == 0 ||
1.59      otto     1092:                    strcmp(current->sysnames[code], "clone") == 0))
                   1093:                        mappidtoemul(ret, current);
                   1094:        }
1.1       deraadt  1095:
                   1096:        if (error == 0) {
                   1097:                if (fancy) {
1.64      guenther 1098:                        switch (current == &emulations[0] ? code : -1) {
                   1099:                        case SYS_sigprocmask:
1.73      guenther 1100:                        case SYS_sigpending:
1.64      guenther 1101:                                sigset(ret);
                   1102:                                break;
                   1103:                        case SYS___thrsigdivert:
                   1104:                                signame(ret);
                   1105:                                break;
                   1106:                        case -1:        /* non-default emulation */
                   1107:                        default:
                   1108:                                (void)printf("%ld", (long)ret);
                   1109:                                if (ret < 0 || ret > 9)
                   1110:                                        (void)printf("/%#lx", (long)ret);
                   1111:                        }
1.1       deraadt  1112:                } else {
                   1113:                        if (decimal)
1.50      deraadt  1114:                                (void)printf("%ld", (long)ret);
1.1       deraadt  1115:                        else
1.50      deraadt  1116:                                (void)printf("%#lx", (long)ret);
1.1       deraadt  1117:                }
                   1118:        } else if (error == ERESTART)
                   1119:                (void)printf("RESTART");
                   1120:        else if (error == EJUSTRETURN)
                   1121:                (void)printf("JUSTRETURN");
                   1122:        else {
                   1123:                (void)printf("-1 errno %d", ktr->ktr_error);
                   1124:                if (fancy)
                   1125:                        (void)printf(" %s", strerror(ktr->ktr_error));
                   1126:        }
                   1127:        (void)putchar('\n');
                   1128: }
                   1129:
1.12      espie    1130: static void
1.37      tedu     1131: ktrnamei(const char *cp, size_t len)
1.1       deraadt  1132: {
1.37      tedu     1133:        (void)printf("\"%.*s\"\n", (int)len, cp);
1.1       deraadt  1134: }
                   1135:
1.12      espie    1136: static void
1.37      tedu     1137: ktremul(char *cp, size_t len)
1.1       deraadt  1138: {
                   1139:        char name[1024];
                   1140:
                   1141:        if (len >= sizeof(name))
                   1142:                errx(1, "Emulation name too long");
                   1143:
                   1144:        strncpy(name, cp, len);
                   1145:        name[len] = '\0';
                   1146:        (void)printf("\"%s\"\n", name);
                   1147:
                   1148:        setemul(name);
                   1149: }
                   1150:
1.12      espie    1151: static void
1.81      miod     1152: showbuf(unsigned char *dp, size_t datalen)
1.1       deraadt  1153: {
1.37      tedu     1154:        int i, j;
1.81      miod     1155:        static int screenwidth;
1.31      tedu     1156:        int col = 0, width, bpl;
1.32      tedu     1157:        unsigned char visbuf[5], *cp, c;
1.1       deraadt  1158:
                   1159:        if (screenwidth == 0) {
                   1160:                struct winsize ws;
                   1161:
                   1162:                if (fancy && ioctl(fileno(stderr), TIOCGWINSZ, &ws) != -1 &&
                   1163:                    ws.ws_col > 8)
                   1164:                        screenwidth = ws.ws_col;
                   1165:                else
                   1166:                        screenwidth = 80;
                   1167:        }
1.31      tedu     1168:        if (iohex == 1) {
                   1169:                putchar('\t');
                   1170:                col = 8;
                   1171:                for (i = 0; i < datalen; i++) {
1.35      tedu     1172:                        printf("%02x", dp[i]);
1.31      tedu     1173:                        col += 3;
                   1174:                        if (i < datalen - 1) {
                   1175:                                if (col + 3 > screenwidth) {
                   1176:                                        printf("\n\t");
                   1177:                                        col = 8;
                   1178:                                } else
                   1179:                                        putchar(' ');
                   1180:                        }
                   1181:                }
                   1182:                putchar('\n');
                   1183:                return;
                   1184:        }
                   1185:        if (iohex == 2) {
                   1186:                bpl = (screenwidth - 13)/4;
                   1187:                if (bpl <= 0)
                   1188:                        bpl = 1;
                   1189:                for (i = 0; i < datalen; i += bpl) {
                   1190:                        printf("   %04x:  ", i);
                   1191:                        for (j = 0; j < bpl; j++) {
                   1192:                                if (i+j >= datalen)
                   1193:                                        printf("   ");
                   1194:                                else
1.35      tedu     1195:                                        printf("%02x ", dp[i+j]);
1.31      tedu     1196:                        }
                   1197:                        putchar(' ');
                   1198:                        for (j = 0; j < bpl; j++) {
                   1199:                                if (i+j >= datalen)
                   1200:                                        break;
                   1201:                                c = dp[i+j];
                   1202:                                if (!isprint(c))
                   1203:                                        c = '.';
                   1204:                                putchar(c);
                   1205:                        }
                   1206:                        putchar('\n');
                   1207:                }
                   1208:                return;
                   1209:        }
1.1       deraadt  1210:        (void)printf("       \"");
                   1211:        col = 8;
                   1212:        for (; datalen > 0; datalen--, dp++) {
1.31      tedu     1213:                (void)vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
1.1       deraadt  1214:                cp = visbuf;
1.17      deraadt  1215:
1.1       deraadt  1216:                /*
                   1217:                 * Keep track of printables and
                   1218:                 * space chars (like fold(1)).
                   1219:                 */
                   1220:                if (col == 0) {
                   1221:                        (void)putchar('\t');
                   1222:                        col = 8;
                   1223:                }
1.17      deraadt  1224:                switch (*cp) {
1.1       deraadt  1225:                case '\n':
                   1226:                        col = 0;
                   1227:                        (void)putchar('\n');
                   1228:                        continue;
                   1229:                case '\t':
                   1230:                        width = 8 - (col&07);
                   1231:                        break;
                   1232:                default:
                   1233:                        width = strlen(cp);
                   1234:                }
                   1235:                if (col + width > (screenwidth-2)) {
                   1236:                        (void)printf("\\\n\t");
                   1237:                        col = 8;
                   1238:                }
                   1239:                col += width;
                   1240:                do {
                   1241:                        (void)putchar(*cp++);
                   1242:                } while (*cp);
                   1243:        }
                   1244:        if (col == 0)
                   1245:                (void)printf("       ");
                   1246:        (void)printf("\"\n");
                   1247: }
                   1248:
1.12      espie    1249: static void
1.81      miod     1250: ktrgenio(struct ktr_genio *ktr, size_t len)
                   1251: {
                   1252:        unsigned char *dp = (unsigned char *)ktr + sizeof(struct ktr_genio);
                   1253:        size_t datalen = len - sizeof(struct ktr_genio);
                   1254:
                   1255:        printf("fd %d %s %zu bytes\n", ktr->ktr_fd,
                   1256:                ktr->ktr_rw == UIO_READ ? "read" : "wrote", datalen);
                   1257:        if (maxdata == 0)
                   1258:                return;
                   1259:        if (datalen > maxdata)
                   1260:                datalen = maxdata;
                   1261:        if (iohex && !datalen)
                   1262:                return;
                   1263:        showbuf(dp, datalen);
                   1264: }
                   1265:
                   1266: static void
1.17      deraadt  1267: ktrpsig(struct ktr_psig *psig)
1.1       deraadt  1268: {
                   1269:        (void)printf("SIG%s ", sys_signame[psig->signo]);
                   1270:        if (psig->action == SIG_DFL)
1.63      deraadt  1271:                (void)printf("SIG_DFL");
1.64      guenther 1272:        else {
                   1273:                (void)printf("caught handler=0x%lx mask=",
                   1274:                    (u_long)psig->action);
                   1275:                sigset(psig->mask);
                   1276:        }
1.63      deraadt  1277:        if (psig->code) {
                   1278:                printf(" code ");
                   1279:                if (fancy) {
                   1280:                        switch (psig->signo) {
                   1281:                        case SIGILL:
                   1282:                                sigill_name(psig->code);
                   1283:                                break;
                   1284:                        case SIGTRAP:
                   1285:                                sigtrap_name(psig->code);
                   1286:                                break;
                   1287:                        case SIGEMT:
                   1288:                                sigemt_name(psig->code);
                   1289:                                break;
                   1290:                        case SIGFPE:
                   1291:                                sigfpe_name(psig->code);
                   1292:                                break;
                   1293:                        case SIGBUS:
                   1294:                                sigbus_name(psig->code);
                   1295:                                break;
                   1296:                        case SIGSEGV:
                   1297:                                sigsegv_name(psig->code);
                   1298:                                break;
                   1299:                        case SIGCHLD:
                   1300:                                sigchld_name(psig->code);
                   1301:                                break;
                   1302:                        }
                   1303:                }
                   1304:                printf("<%d>", psig->code);
                   1305:        }
                   1306:
1.14      deraadt  1307:        switch (psig->signo) {
                   1308:        case SIGSEGV:
                   1309:        case SIGILL:
                   1310:        case SIGBUS:
                   1311:        case SIGFPE:
                   1312:                printf(" addr=%p trapno=%d", psig->si.si_addr,
                   1313:                    psig->si.si_trapno);
                   1314:                break;
                   1315:        default:
                   1316:                break;
                   1317:        }
                   1318:        printf("\n");
1.1       deraadt  1319: }
                   1320:
1.12      espie    1321: static void
1.17      deraadt  1322: ktrcsw(struct ktr_csw *cs)
1.1       deraadt  1323: {
                   1324:        (void)printf("%s %s\n", cs->out ? "stop" : "resume",
                   1325:            cs->user ? "user" : "kernel");
                   1326: }
                   1327:
1.64      guenther 1328: static void
1.81      miod     1329: ktruser(struct ktr_user *usr, size_t len)
                   1330: {
                   1331:        len -= sizeof(struct ktr_user);
                   1332:        printf("%.*s:", KTR_USER_MAXIDLEN, usr->ktr_id);
                   1333:        printf(" %zu bytes\n", len);
                   1334:        showbuf((unsigned char *)(usr + 1), len);
                   1335: }
                   1336:
                   1337: static void
1.17      deraadt  1338: usage(void)
1.1       deraadt  1339: {
                   1340:
1.19      mickey   1341:        extern char *__progname;
                   1342:        fprintf(stderr, "usage: %s "
1.68      jmc      1343:            "[-dHlnRrTXx] [-e emulation] [-f file] [-m maxdata] [-p pid]\n"
1.81      miod     1344:            "%*s[-t [ceinstuw]]\n",
1.51      otto     1345:            __progname, (int)(sizeof("usage: ") + strlen(__progname)), "");
1.1       deraadt  1346:        exit(1);
                   1347: }
                   1348:
1.12      espie    1349: static void
1.17      deraadt  1350: setemul(const char *name)
1.1       deraadt  1351: {
                   1352:        int i;
1.17      deraadt  1353:
1.1       deraadt  1354:        for (i = 0; emulations[i].name != NULL; i++)
                   1355:                if (strcmp(emulations[i].name, name) == 0) {
                   1356:                        current = &emulations[i];
                   1357:                        return;
                   1358:                }
                   1359:        warnx("Emulation `%s' unknown", name);
1.61      matthew  1360: }
                   1361:
1.92    ! guenther 1362: /*
        !          1363:  * FORMATTERS
        !          1364:  */
        !          1365:
        !          1366: static void
        !          1367: ioctldecode(int cmd)
        !          1368: {
        !          1369:        char dirbuf[4], *dir = dirbuf;
        !          1370:        const char *cp;
        !          1371:
        !          1372:        if ((cp = ioctlname((unsigned)cmd)) != NULL) {
        !          1373:                (void)printf("%s", cp);
        !          1374:                return;
        !          1375:        }
        !          1376:
        !          1377:        if (cmd & IOC_IN)
        !          1378:                *dir++ = 'W';
        !          1379:        if (cmd & IOC_OUT)
        !          1380:                *dir++ = 'R';
        !          1381:        *dir = '\0';
        !          1382:
        !          1383:        printf("_IO%s('%c',%lu",
        !          1384:            dirbuf, (int)((cmd >> 8) & 0xff), cmd & 0xff);
        !          1385:        if ((cmd & IOC_VOID) == 0)
        !          1386:                printf(decimal ? ",%u)" : ",%#x)", (cmd >> 16) & 0xff);
        !          1387:        else
        !          1388:                printf(")");
        !          1389: }
        !          1390:
        !          1391: static void
        !          1392: ptracedecode(int request)
        !          1393: {
        !          1394:        if (request >= 0 && request < nitems(ptrace_ops))
        !          1395:                (void)printf("%s", ptrace_ops[request]);
        !          1396:        else switch(request) {
        !          1397: #ifdef PT_GETFPREGS
        !          1398:        case PT_GETFPREGS:
        !          1399:                (void)printf("PT_GETFPREGS");
        !          1400:                break;
        !          1401: #endif
        !          1402:        case PT_GETREGS:
        !          1403:                (void)printf("PT_GETREGS");
        !          1404:                break;
        !          1405: #ifdef PT_GETXMMREGS
        !          1406:        case PT_GETXMMREGS:
        !          1407:                (void)printf("PT_GETXMMREGS");
        !          1408:                break;
        !          1409: #endif
        !          1410: #ifdef PT_SETFPREGS
        !          1411:        case PT_SETFPREGS:
        !          1412:                (void)printf("PT_SETFPREGS");
        !          1413:                break;
        !          1414: #endif
        !          1415:        case PT_SETREGS:
        !          1416:                (void)printf("PT_SETREGS");
        !          1417:                break;
        !          1418: #ifdef PT_SETXMMREGS
        !          1419:        case PT_SETXMMREGS:
        !          1420:                (void)printf("PT_SETXMMREGS");
        !          1421:                break;
        !          1422: #endif
        !          1423: #ifdef PT_STEP
        !          1424:        case PT_STEP:
        !          1425:                (void)printf("PT_STEP");
        !          1426:                break;
        !          1427: #endif
        !          1428: #ifdef PT_WCOOKIE
        !          1429:        case PT_WCOOKIE:
        !          1430:                (void)printf("PT_WCOOKIE");
        !          1431:                break;
        !          1432: #endif
        !          1433:        default:
        !          1434:                pdecint(request);
        !          1435:        }
        !          1436: }
        !          1437:
        !          1438:
1.61      matthew  1439: static void
                   1440: atfd(int fd)
                   1441: {
                   1442:        if (fd == AT_FDCWD)
                   1443:                (void)printf("AT_FDCWD");
                   1444:        else
1.92    ! guenther 1445:                pdecint(fd);
1.77      guenther 1446: }
                   1447:
                   1448: static void
                   1449: polltimeout(int timeout)
                   1450: {
                   1451:        if (timeout == INFTIM)
                   1452:                (void)printf("INFTIM");
                   1453:        else
1.92    ! guenther 1454:                pdecint(timeout);
1.82      guenther 1455: }
                   1456:
                   1457: static void
                   1458: wait4pid(int pid)
                   1459: {
                   1460:        if (pid == WAIT_ANY)
                   1461:                (void)printf("WAIT_ANY");
                   1462:        else if (pid == WAIT_MYPGRP)
                   1463:                (void)printf("WAIT_MYPGRP");
                   1464:        else
1.92    ! guenther 1465:                pdecint(pid);           /* ppgid */
1.1       deraadt  1466: }
1.83      guenther 1467:
                   1468: static void
                   1469: signame(int sig)
                   1470: {
                   1471:        if (sig > 0 && sig < NSIG)
                   1472:                (void)printf("SIG%s", sys_signame[sig]);
                   1473:        else
                   1474:                (void)printf("SIG %d", sig);
                   1475: }
                   1476:
1.84      guenther 1477: void
1.83      guenther 1478: sigset(int ss)
                   1479: {
                   1480:        int     or = 0;
                   1481:        int     cnt = 0;
                   1482:        int     i;
                   1483:
                   1484:        for (i = 1; i < NSIG; i++)
                   1485:                if (sigismember(&ss, i))
                   1486:                        cnt++;
                   1487:        if (cnt > (NSIG-1)/2) {
                   1488:                ss = ~ss;
                   1489:                putchar('~');
                   1490:        }
                   1491:
                   1492:        if (ss == 0) {
                   1493:                (void)printf("0<>");
                   1494:                return;
                   1495:        }
                   1496:
                   1497:        printf("%#x<", ss);
                   1498:        for (i = 1; i < NSIG; i++)
                   1499:                if (sigismember(&ss, i)) {
                   1500:                        if (or) putchar('|'); else or=1;
                   1501:                        signame(i);
                   1502:                }
                   1503:        printf(">");
                   1504: }
                   1505:
                   1506: static void
                   1507: semctlname(int cmd)
                   1508: {
                   1509:        switch (cmd) {
                   1510:        case GETNCNT:
                   1511:                (void)printf("GETNCNT");
                   1512:                break;
                   1513:        case GETPID:
                   1514:                (void)printf("GETPID");
                   1515:                break;
                   1516:        case GETVAL:
                   1517:                (void)printf("GETVAL");
                   1518:                break;
                   1519:        case GETALL:
                   1520:                (void)printf("GETALL");
                   1521:                break;
                   1522:        case GETZCNT:
                   1523:                (void)printf("GETZCNT");
                   1524:                break;
                   1525:        case SETVAL:
                   1526:                (void)printf("SETVAL");
                   1527:                break;
                   1528:        case SETALL:
                   1529:                (void)printf("SETALL");
                   1530:                break;
                   1531:        case IPC_RMID:
                   1532:                (void)printf("IPC_RMID");
                   1533:                break;
                   1534:        case IPC_SET:
                   1535:                (void)printf("IPC_SET");
                   1536:                break;
                   1537:        case IPC_STAT:
                   1538:                (void)printf("IPC_STAT");
                   1539:                break;
                   1540:        default: /* Should not reach */
1.92    ! guenther 1541:                (void)printf("<invalid=%d>", cmd);
1.83      guenther 1542:        }
                   1543: }
                   1544:
                   1545: static void
1.88      guenther 1546: shmctlname(int cmd)
                   1547: {
1.83      guenther 1548:        switch (cmd) {
                   1549:        case IPC_RMID:
                   1550:                (void)printf("IPC_RMID");
                   1551:                break;
                   1552:        case IPC_SET:
                   1553:                (void)printf("IPC_SET");
                   1554:                break;
                   1555:        case IPC_STAT:
                   1556:                (void)printf("IPC_STAT");
                   1557:                break;
                   1558:        default: /* Should not reach */
1.92    ! guenther 1559:                (void)printf("<invalid=%d>", cmd);
1.83      guenther 1560:        }
                   1561: }
                   1562:
                   1563:
                   1564: static void
1.88      guenther 1565: semgetname(int flag)
                   1566: {
1.83      guenther 1567:        int     or = 0;
                   1568:        if_print_or(flag, IPC_CREAT, or);
                   1569:        if_print_or(flag, IPC_EXCL, or);
                   1570:        if_print_or(flag, SEM_R, or);
                   1571:        if_print_or(flag, SEM_A, or);
                   1572:        if_print_or(flag, (SEM_R>>3), or);
                   1573:        if_print_or(flag, (SEM_A>>3), or);
                   1574:        if_print_or(flag, (SEM_R>>6), or);
                   1575:        if_print_or(flag, (SEM_A>>6), or);
1.92    ! guenther 1576:
        !          1577:        if (flag & ~(IPC_CREAT|IPC_EXCL|SEM_R|SEM_A|((SEM_R|SEM_A)>>3)|
        !          1578:            ((SEM_R|SEM_A)>>6)))
        !          1579:                printf("<invalid=%#x>", flag);
1.83      guenther 1580: }
                   1581:
                   1582:
                   1583: /*
1.92    ! guenther 1584:  * Only used by SYS_open and SYS_openat. Unless O_CREAT is set in flags, the
1.83      guenther 1585:  * mode argument is unused (and often bogus and misleading).
                   1586:  */
                   1587: static void
1.92    ! guenther 1588: flagsandmodename(int mode)
1.88      guenther 1589: {
1.92    ! guenther 1590:        openflagsname(arg1);
        !          1591:        if ((arg1 & O_CREAT) == O_CREAT) {
1.83      guenther 1592:                (void)putchar(',');
1.92    ! guenther 1593:                modename(mode);
        !          1594:        } else if (!fancy)
        !          1595:                (void)printf(",<unused>%#o", mode);
1.83      guenther 1596: }
                   1597:
                   1598: static void
                   1599: clockname(int clockid)
                   1600: {
                   1601:        clocktypename(__CLOCK_TYPE(clockid));
                   1602:        if (__CLOCK_PTID(clockid) != 0)
                   1603:                printf("(%d)", __CLOCK_PTID(clockid));
                   1604: }
                   1605:
                   1606: /*
                   1607:  * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
                   1608:  * referring to a line in /etc/protocols . It might be appropriate
                   1609:  * to use getprotoent(3) here.
                   1610:  */
                   1611: static void
                   1612: sockoptlevelname(int level)
                   1613: {
1.92    ! guenther 1614:        if (level == SOL_SOCKET)
1.83      guenther 1615:                (void)printf("SOL_SOCKET");
1.92    ! guenther 1616:        else
        !          1617:                pdecint(level);
1.83      guenther 1618: }
                   1619:
1.88      guenther 1620: static void
                   1621: ktraceopname(int ops)
                   1622: {
                   1623:        int invalid = 0;
                   1624:
                   1625:        printf("%#x<", ops);
                   1626:        switch (KTROP(ops)) {
                   1627:        case KTROP_SET:
                   1628:                printf("KTROP_SET");
                   1629:                break;
                   1630:        case KTROP_CLEAR:
                   1631:                printf("KTROP_CLEAR");
                   1632:                break;
                   1633:        case KTROP_CLEARFILE:
                   1634:                printf("KTROP_CLEARFILE");
                   1635:                break;
                   1636:        default:
                   1637:                printf("KTROP(%d)", KTROP(ops));
                   1638:                invalid = 1;
                   1639:                break;
                   1640:        }
1.92    ! guenther 1641:        if (ops & KTRFLAG_DESCEND) printf("|KTRFLAG_DESCEND");
1.88      guenther 1642:        printf(">");
                   1643:        if (invalid || (ops & ~(KTROP((unsigned)-1) | KTRFLAG_DESCEND)))
1.92    ! guenther 1644:                (void)printf("<invalid>%d", ops);
1.88      guenther 1645: }