[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.45

1.45    ! tedu        1: /*     $OpenBSD: kdump.c,v 1.44 2010/06/30 20:43:36 tedu 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>
                     37: #include <sys/ptrace.h>
1.28      deraadt    38: #include <sys/sysctl.h>
1.1       deraadt    39: #define _KERNEL
                     40: #include <sys/errno.h>
                     41: #undef _KERNEL
                     42:
1.33      tedu       43: #include <ctype.h>
1.1       deraadt    44: #include <err.h>
                     45: #include <signal.h>
                     46: #include <stdio.h>
                     47: #include <stdlib.h>
                     48: #include <string.h>
                     49: #include <unistd.h>
                     50: #include <vis.h>
                     51:
                     52: #include "ktrace.h"
1.22      deraadt    53: #include "kdump.h"
1.12      espie      54: #include "extern.h"
1.1       deraadt    55:
1.31      tedu       56: int timestamp, decimal, iohex, fancy = 1, tail, maxdata;
1.1       deraadt    57: char *tracefile = DEF_TRACEFILE;
                     58: struct ktr_header ktr_header;
1.17      deraadt    59: pid_t pid = -1;
1.1       deraadt    60:
                     61: #define eqs(s1, s2)    (strcmp((s1), (s2)) == 0)
                     62:
                     63: #include <sys/syscall.h>
                     64:
1.25      mickey     65: #include <compat/bsdos/bsdos_syscall.h>
                     66: #include <compat/freebsd/freebsd_syscall.h>
                     67: #include <compat/linux/linux_syscall.h>
                     68: #include <compat/sunos/sunos_syscall.h>
                     69: #include <compat/svr4/svr4_syscall.h>
1.1       deraadt    70:
                     71: #define KTRACE
1.19      mickey     72: #define PTRACE
1.7       deraadt    73: #define NFSCLIENT
                     74: #define NFSSERVER
                     75: #define SYSVSEM
                     76: #define SYSVMSG
                     77: #define SYSVSHM
                     78: #define LFS
1.30      miod       79: #define RTHREADS
1.25      mickey     80: #include <kern/syscalls.c>
1.1       deraadt    81:
1.25      mickey     82: #include <compat/bsdos/bsdos_syscalls.c>
                     83: #include <compat/freebsd/freebsd_syscalls.c>
                     84: #include <compat/linux/linux_syscalls.c>
                     85: #include <compat/sunos/sunos_syscalls.c>
                     86: #include <compat/svr4/svr4_syscalls.c>
1.1       deraadt    87: #undef KTRACE
1.19      mickey     88: #undef PTRACE
1.7       deraadt    89: #undef NFSCLIENT
                     90: #undef NFSSERVER
                     91: #undef SYSVSEM
                     92: #undef SYSVMSG
                     93: #undef SYSVSHM
                     94: #undef LFS
1.30      miod       95: #undef RTHREADS
1.1       deraadt    96:
                     97: struct emulation {
                     98:        char *name;             /* Emulation name */
                     99:        char **sysnames;        /* Array of system call names */
                    100:        int  nsysnames;         /* Number of */
                    101: };
                    102:
                    103: static struct emulation emulations[] = {
1.9       deraadt   104:        { "native",     syscallnames,           SYS_MAXSYSCALL },
                    105:        { "linux",      linux_syscallnames,     LINUX_SYS_MAXSYSCALL },
                    106:        { "sunos",      sunos_syscallnames,     SUNOS_SYS_MAXSYSCALL },
                    107:        { "svr4",       svr4_syscallnames,      SVR4_SYS_MAXSYSCALL },
                    108:        { "bsdos",      bsdos_syscallnames,     BSDOS_SYS_MAXSYSCALL },
                    109:        { "freebsd",    freebsd_syscallnames,   FREEBSD_SYS_MAXSYSCALL },
                    110:        { NULL,         NULL,                   NULL }
1.1       deraadt   111: };
                    112:
                    113: struct emulation *current;
                    114:
                    115:
                    116: static char *ptrace_ops[] = {
                    117:        "PT_TRACE_ME",  "PT_READ_I",    "PT_READ_D",    "PT_READ_U",
                    118:        "PT_WRITE_I",   "PT_WRITE_D",   "PT_WRITE_U",   "PT_CONTINUE",
1.15      art       119:        "PT_KILL",      "PT_ATTACH",    "PT_DETACH",    "PT_IO",
1.1       deraadt   120: };
                    121:
1.37      tedu      122: static int fread_tail(void *, size_t, size_t);
1.13      millert   123: static void dumpheader(struct ktr_header *);
                    124: static void ktrcsw(struct ktr_csw *);
1.37      tedu      125: static void ktremul(char *, size_t);
                    126: static void ktrgenio(struct ktr_genio *, size_t);
                    127: static void ktrnamei(const char *, size_t);
1.13      millert   128: static void ktrpsig(struct ktr_psig *);
                    129: static void ktrsyscall(struct ktr_syscall *);
                    130: static void ktrsysret(struct ktr_sysret *);
                    131: static void setemul(const char *);
                    132: static void usage(void);
1.12      espie     133:
1.1       deraadt   134: int
1.17      deraadt   135: main(int argc, char *argv[])
1.1       deraadt   136: {
1.37      tedu      137:        int ch, silent;
                    138:        size_t ktrlen, size;
1.17      deraadt   139:        int trpoints = ALL_POINTS;
1.12      espie     140:        void *m;
1.1       deraadt   141:
1.3       deraadt   142:        current = &emulations[0];       /* native */
1.1       deraadt   143:
1.31      tedu      144:        while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:xX")) != -1)
1.1       deraadt   145:                switch (ch) {
                    146:                case 'e':
                    147:                        setemul(optarg);
                    148:                        break;
                    149:                case 'f':
                    150:                        tracefile = optarg;
                    151:                        break;
                    152:                case 'd':
                    153:                        decimal = 1;
                    154:                        break;
                    155:                case 'l':
                    156:                        tail = 1;
                    157:                        break;
                    158:                case 'm':
                    159:                        maxdata = atoi(optarg);
                    160:                        break;
                    161:                case 'n':
                    162:                        fancy = 0;
                    163:                        break;
1.17      deraadt   164:                case 'p':
                    165:                        pid = atoi(optarg);
                    166:                        break;
1.1       deraadt   167:                case 'R':
                    168:                        timestamp = 2;  /* relative timestamp */
                    169:                        break;
                    170:                case 'T':
                    171:                        timestamp = 1;
                    172:                        break;
                    173:                case 't':
                    174:                        trpoints = getpoints(optarg);
                    175:                        if (trpoints < 0)
                    176:                                errx(1, "unknown trace point in %s", optarg);
                    177:                        break;
1.31      tedu      178:                case 'x':
                    179:                        iohex = 1;
                    180:                        break;
                    181:                case 'X':
                    182:                        iohex = 2;
                    183:                        break;
1.1       deraadt   184:                default:
                    185:                        usage();
                    186:                }
1.5       deraadt   187:        if (argc > optind)
1.1       deraadt   188:                usage();
                    189:
1.37      tedu      190:        m = malloc(size = 1025);
1.1       deraadt   191:        if (m == NULL)
1.37      tedu      192:                err(1, NULL);
1.1       deraadt   193:        if (!freopen(tracefile, "r", stdin))
                    194:                err(1, "%s", tracefile);
                    195:        while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
1.17      deraadt   196:                silent = 0;
                    197:                if (pid != -1 && pid != ktr_header.ktr_pid)
                    198:                        silent = 1;
                    199:                if (silent == 0 && trpoints & (1<<ktr_header.ktr_type))
1.1       deraadt   200:                        dumpheader(&ktr_header);
1.37      tedu      201:                ktrlen = ktr_header.ktr_len;
1.1       deraadt   202:                if (ktrlen > size) {
1.23      tedu      203:                        void *newm;
                    204:
                    205:                        newm = realloc(m, ktrlen+1);
                    206:                        if (newm == NULL)
1.37      tedu      207:                                err(1, NULL);
1.23      tedu      208:                        m = newm;
1.1       deraadt   209:                        size = ktrlen;
                    210:                }
                    211:                if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
                    212:                        errx(1, "data too short");
1.17      deraadt   213:                if (silent)
                    214:                        continue;
1.1       deraadt   215:                if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
                    216:                        continue;
                    217:                switch (ktr_header.ktr_type) {
                    218:                case KTR_SYSCALL:
                    219:                        ktrsyscall((struct ktr_syscall *)m);
                    220:                        break;
                    221:                case KTR_SYSRET:
                    222:                        ktrsysret((struct ktr_sysret *)m);
                    223:                        break;
                    224:                case KTR_NAMEI:
                    225:                        ktrnamei(m, ktrlen);
                    226:                        break;
                    227:                case KTR_GENIO:
                    228:                        ktrgenio((struct ktr_genio *)m, ktrlen);
                    229:                        break;
                    230:                case KTR_PSIG:
                    231:                        ktrpsig((struct ktr_psig *)m);
                    232:                        break;
                    233:                case KTR_CSW:
                    234:                        ktrcsw((struct ktr_csw *)m);
                    235:                        break;
                    236:                case KTR_EMUL:
                    237:                        ktremul(m, ktrlen);
                    238:                        break;
                    239:                }
                    240:                if (tail)
                    241:                        (void)fflush(stdout);
                    242:        }
1.12      espie     243:        exit(0);
1.1       deraadt   244: }
                    245:
1.12      espie     246: static int
1.37      tedu      247: fread_tail(void *buf, size_t size, size_t num)
1.1       deraadt   248: {
                    249:        int i;
                    250:
                    251:        while ((i = fread(buf, size, num, stdin)) == 0 && tail) {
                    252:                (void)sleep(1);
                    253:                clearerr(stdin);
                    254:        }
                    255:        return (i);
                    256: }
                    257:
1.12      espie     258: static void
1.17      deraadt   259: dumpheader(struct ktr_header *kth)
1.1       deraadt   260: {
1.17      deraadt   261:        static struct timeval prevtime;
1.1       deraadt   262:        char unknown[64], *type;
                    263:        struct timeval temp;
                    264:
                    265:        switch (kth->ktr_type) {
                    266:        case KTR_SYSCALL:
                    267:                type = "CALL";
                    268:                break;
                    269:        case KTR_SYSRET:
                    270:                type = "RET ";
                    271:                break;
                    272:        case KTR_NAMEI:
                    273:                type = "NAMI";
                    274:                break;
                    275:        case KTR_GENIO:
                    276:                type = "GIO ";
                    277:                break;
                    278:        case KTR_PSIG:
                    279:                type = "PSIG";
                    280:                break;
                    281:        case KTR_CSW:
                    282:                type = "CSW";
                    283:                break;
                    284:        case KTR_EMUL:
                    285:                type = "EMUL";
                    286:                break;
                    287:        default:
1.17      deraadt   288:                (void)snprintf(unknown, sizeof unknown, "UNKNOWN(%d)",
                    289:                    kth->ktr_type);
1.1       deraadt   290:                type = unknown;
                    291:        }
                    292:
1.16      mpech     293:        (void)printf("%6ld %-8.*s ", (long)kth->ktr_pid, MAXCOMLEN,
                    294:            kth->ktr_comm);
1.1       deraadt   295:        if (timestamp) {
                    296:                if (timestamp == 2) {
                    297:                        timersub(&kth->ktr_time, &prevtime, &temp);
                    298:                        prevtime = kth->ktr_time;
                    299:                } else
                    300:                        temp = kth->ktr_time;
                    301:                (void)printf("%ld.%06ld ", temp.tv_sec, temp.tv_usec);
                    302:        }
                    303:        (void)printf("%s  ", type);
                    304: }
                    305:
1.12      espie     306: static void
1.17      deraadt   307: ioctldecode(u_long cmd)
1.2       deraadt   308: {
                    309:        char dirbuf[4], *dir = dirbuf;
                    310:
1.6       deraadt   311:        if (cmd & IOC_IN)
                    312:                *dir++ = 'W';
1.2       deraadt   313:        if (cmd & IOC_OUT)
                    314:                *dir++ = 'R';
                    315:        *dir = '\0';
                    316:
1.33      tedu      317:        printf(decimal ? ",_IO%s('%c',%lu" : ",_IO%s('%c',%#lx",
                    318:            dirbuf, (int)((cmd >> 8) & 0xff), cmd & 0xff);
1.2       deraadt   319:        if ((cmd & IOC_VOID) == 0)
1.34      tedu      320:                printf(decimal ? ",%lu)" : ",%#lx)", (cmd >> 16) & 0xff);
1.2       deraadt   321:        else
                    322:                printf(")");
                    323: }
1.1       deraadt   324:
1.12      espie     325: static void
1.17      deraadt   326: ktrsyscall(struct ktr_syscall *ktr)
1.1       deraadt   327: {
1.12      espie     328:        int argsize = ktr->ktr_argsize;
                    329:        register_t *ap;
1.1       deraadt   330:
                    331:        if (ktr->ktr_code >= current->nsysnames || ktr->ktr_code < 0)
                    332:                (void)printf("[%d]", ktr->ktr_code);
                    333:        else
                    334:                (void)printf("%s", current->sysnames[ktr->ktr_code]);
                    335:        ap = (register_t *)((char *)ktr + sizeof(struct ktr_syscall));
1.27      mickey    336:        (void)putchar('(');
1.1       deraadt   337:        if (argsize) {
1.27      mickey    338:                char c = '\0';
1.1       deraadt   339:                if (fancy) {
                    340:                        if (ktr->ktr_code == SYS_ioctl) {
1.12      espie     341:                                const char *cp;
1.17      deraadt   342:
1.1       deraadt   343:                                if (decimal)
1.27      mickey    344:                                        (void)printf("%ld", (long)*ap);
1.1       deraadt   345:                                else
1.27      mickey    346:                                        (void)printf("%#lx", (long)*ap);
1.1       deraadt   347:                                ap++;
                    348:                                argsize -= sizeof(register_t);
                    349:                                if ((cp = ioctlname(*ap)) != NULL)
                    350:                                        (void)printf(",%s", cp);
1.2       deraadt   351:                                else
                    352:                                        ioctldecode(*ap);
1.1       deraadt   353:                                c = ',';
                    354:                                ap++;
                    355:                                argsize -= sizeof(register_t);
1.27      mickey    356:                        } else if (ktr->ktr_code == SYS___sysctl) {
                    357:                                int *np, n;
                    358:
                    359:                                n = ap[1];
1.28      deraadt   360:                                if (n > CTL_MAXNAME)
                    361:                                        n = CTL_MAXNAME;
1.27      mickey    362:                                np = (int *)(ap + 6);
                    363:                                for (; n--; np++) {
                    364:                                        if (c)
                    365:                                                putchar(c);
                    366:                                        printf("%d", *np);
                    367:                                        c = '.';
                    368:                                }
                    369:
                    370:                                c = ',';
                    371:                                ap += 2;
                    372:                                argsize -= 2 * sizeof(register_t);
1.1       deraadt   373:                        } else if (ktr->ktr_code == SYS_ptrace) {
1.24      miod      374:                                if (*ap >= 0 && *ap <
1.1       deraadt   375:                                    sizeof(ptrace_ops) / sizeof(ptrace_ops[0]))
1.27      mickey    376:                                        (void)printf("%s", ptrace_ops[*ap]);
1.24      miod      377:                                else switch(*ap) {
                    378: #ifdef PT_GETFPREGS
                    379:                                case PT_GETFPREGS:
1.27      mickey    380:                                        (void)printf("PT_GETFPREGS");
1.24      miod      381:                                        break;
                    382: #endif
                    383:                                case PT_GETREGS:
1.27      mickey    384:                                        (void)printf("PT_GETREGS");
1.24      miod      385:                                        break;
                    386: #ifdef PT_SETFPREGS
                    387:                                case PT_SETFPREGS:
1.27      mickey    388:                                        (void)printf("PT_SETFPREGS");
1.24      miod      389:                                        break;
                    390: #endif
                    391:                                case PT_SETREGS:
1.27      mickey    392:                                        (void)printf("PT_SETREGS");
1.24      miod      393:                                        break;
                    394: #ifdef PT_STEP
                    395:                                case PT_STEP:
1.27      mickey    396:                                        (void)printf("PT_STEP");
1.24      miod      397:                                        break;
                    398: #endif
                    399: #ifdef PT_WCOOKIE
                    400:                                case PT_WCOOKIE:
1.27      mickey    401:                                        (void)printf("PT_WCOOKIE");
1.24      miod      402:                                        break;
                    403: #endif
                    404:                                default:
1.27      mickey    405:                                        (void)printf("%ld", (long)*ap);
1.24      miod      406:                                        break;
                    407:                                }
1.1       deraadt   408:                                c = ',';
                    409:                                ap++;
                    410:                                argsize -= sizeof(register_t);
                    411:                        }
                    412:                }
                    413:                while (argsize) {
1.27      mickey    414:                        if (c)
                    415:                                putchar(c);
1.1       deraadt   416:                        if (decimal)
1.27      mickey    417:                                (void)printf("%ld", (long)*ap);
1.1       deraadt   418:                        else
1.27      mickey    419:                                (void)printf("%#lx", (long)*ap);
1.1       deraadt   420:                        c = ',';
                    421:                        ap++;
                    422:                        argsize -= sizeof(register_t);
                    423:                }
                    424:        }
1.27      mickey    425:        (void)printf(")\n");
1.1       deraadt   426: }
                    427:
1.12      espie     428: static void
1.17      deraadt   429: ktrsysret(struct ktr_sysret *ktr)
1.1       deraadt   430: {
1.12      espie     431:        int ret = ktr->ktr_retval;
                    432:        int error = ktr->ktr_error;
                    433:        int code = ktr->ktr_code;
1.1       deraadt   434:
                    435:        if (code >= current->nsysnames || code < 0)
                    436:                (void)printf("[%d] ", code);
                    437:        else
                    438:                (void)printf("%s ", current->sysnames[code]);
                    439:
                    440:        if (error == 0) {
                    441:                if (fancy) {
                    442:                        (void)printf("%d", ret);
                    443:                        if (ret < 0 || ret > 9)
                    444:                                (void)printf("/%#x", ret);
                    445:                } else {
                    446:                        if (decimal)
                    447:                                (void)printf("%d", ret);
                    448:                        else
                    449:                                (void)printf("%#x", ret);
                    450:                }
                    451:        } else if (error == ERESTART)
                    452:                (void)printf("RESTART");
                    453:        else if (error == EJUSTRETURN)
                    454:                (void)printf("JUSTRETURN");
                    455:        else {
                    456:                (void)printf("-1 errno %d", ktr->ktr_error);
                    457:                if (fancy)
                    458:                        (void)printf(" %s", strerror(ktr->ktr_error));
                    459:        }
                    460:        (void)putchar('\n');
                    461: }
                    462:
1.12      espie     463: static void
1.37      tedu      464: ktrnamei(const char *cp, size_t len)
1.1       deraadt   465: {
1.37      tedu      466:        (void)printf("\"%.*s\"\n", (int)len, cp);
1.1       deraadt   467: }
                    468:
1.12      espie     469: static void
1.37      tedu      470: ktremul(char *cp, size_t len)
1.1       deraadt   471: {
                    472:        char name[1024];
                    473:
                    474:        if (len >= sizeof(name))
                    475:                errx(1, "Emulation name too long");
                    476:
                    477:        strncpy(name, cp, len);
                    478:        name[len] = '\0';
                    479:        (void)printf("\"%s\"\n", name);
                    480:
                    481:        setemul(name);
                    482: }
                    483:
1.12      espie     484: static void
1.37      tedu      485: ktrgenio(struct ktr_genio *ktr, size_t len)
1.1       deraadt   486: {
1.37      tedu      487:        unsigned char *dp = (unsigned char *)ktr + sizeof(struct ktr_genio);
                    488:        int i, j;
                    489:        size_t datalen = len - sizeof(struct ktr_genio);
1.12      espie     490:        static int screenwidth = 0;
1.31      tedu      491:        int col = 0, width, bpl;
1.32      tedu      492:        unsigned char visbuf[5], *cp, c;
1.1       deraadt   493:
                    494:        if (screenwidth == 0) {
                    495:                struct winsize ws;
                    496:
                    497:                if (fancy && ioctl(fileno(stderr), TIOCGWINSZ, &ws) != -1 &&
                    498:                    ws.ws_col > 8)
                    499:                        screenwidth = ws.ws_col;
                    500:                else
                    501:                        screenwidth = 80;
                    502:        }
1.37      tedu      503:        printf("fd %d %s %zu bytes\n", ktr->ktr_fd,
1.1       deraadt   504:                ktr->ktr_rw == UIO_READ ? "read" : "wrote", datalen);
                    505:        if (maxdata && datalen > maxdata)
                    506:                datalen = maxdata;
1.31      tedu      507:        if (iohex && !datalen)
                    508:                return;
                    509:        if (iohex == 1) {
                    510:                putchar('\t');
                    511:                col = 8;
                    512:                for (i = 0; i < datalen; i++) {
1.35      tedu      513:                        printf("%02x", dp[i]);
1.31      tedu      514:                        col += 3;
                    515:                        if (i < datalen - 1) {
                    516:                                if (col + 3 > screenwidth) {
                    517:                                        printf("\n\t");
                    518:                                        col = 8;
                    519:                                } else
                    520:                                        putchar(' ');
                    521:                        }
                    522:                }
                    523:                putchar('\n');
                    524:                return;
                    525:        }
                    526:        if (iohex == 2) {
                    527:                bpl = (screenwidth - 13)/4;
                    528:                if (bpl <= 0)
                    529:                        bpl = 1;
                    530:                for (i = 0; i < datalen; i += bpl) {
                    531:                        printf("   %04x:  ", i);
                    532:                        for (j = 0; j < bpl; j++) {
                    533:                                if (i+j >= datalen)
                    534:                                        printf("   ");
                    535:                                else
1.35      tedu      536:                                        printf("%02x ", dp[i+j]);
1.31      tedu      537:                        }
                    538:                        putchar(' ');
                    539:                        for (j = 0; j < bpl; j++) {
                    540:                                if (i+j >= datalen)
                    541:                                        break;
                    542:                                c = dp[i+j];
                    543:                                if (!isprint(c))
                    544:                                        c = '.';
                    545:                                putchar(c);
                    546:                        }
                    547:                        putchar('\n');
                    548:                }
                    549:                return;
                    550:        }
1.1       deraadt   551:        (void)printf("       \"");
                    552:        col = 8;
                    553:        for (; datalen > 0; datalen--, dp++) {
1.31      tedu      554:                (void)vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
1.1       deraadt   555:                cp = visbuf;
1.17      deraadt   556:
1.1       deraadt   557:                /*
                    558:                 * Keep track of printables and
                    559:                 * space chars (like fold(1)).
                    560:                 */
                    561:                if (col == 0) {
                    562:                        (void)putchar('\t');
                    563:                        col = 8;
                    564:                }
1.17      deraadt   565:                switch (*cp) {
1.1       deraadt   566:                case '\n':
                    567:                        col = 0;
                    568:                        (void)putchar('\n');
                    569:                        continue;
                    570:                case '\t':
                    571:                        width = 8 - (col&07);
                    572:                        break;
                    573:                default:
                    574:                        width = strlen(cp);
                    575:                }
                    576:                if (col + width > (screenwidth-2)) {
                    577:                        (void)printf("\\\n\t");
                    578:                        col = 8;
                    579:                }
                    580:                col += width;
                    581:                do {
                    582:                        (void)putchar(*cp++);
                    583:                } while (*cp);
                    584:        }
                    585:        if (col == 0)
                    586:                (void)printf("       ");
                    587:        (void)printf("\"\n");
                    588: }
                    589:
1.12      espie     590: static void
1.17      deraadt   591: ktrpsig(struct ktr_psig *psig)
1.1       deraadt   592: {
                    593:        (void)printf("SIG%s ", sys_signame[psig->signo]);
                    594:        if (psig->action == SIG_DFL)
1.14      deraadt   595:                (void)printf("SIG_DFL code %d", psig->code);
1.1       deraadt   596:        else
1.14      deraadt   597:                (void)printf("caught handler=0x%lx mask=0x%x",
                    598:                    (u_long)psig->action, psig->mask);
                    599:        switch (psig->signo) {
                    600:        case SIGSEGV:
                    601:        case SIGILL:
                    602:        case SIGBUS:
                    603:        case SIGFPE:
                    604:                printf(" addr=%p trapno=%d", psig->si.si_addr,
                    605:                    psig->si.si_trapno);
                    606:                break;
                    607:        default:
                    608:                break;
                    609:        }
                    610:        printf("\n");
1.1       deraadt   611: }
                    612:
1.12      espie     613: static void
1.17      deraadt   614: ktrcsw(struct ktr_csw *cs)
1.1       deraadt   615: {
                    616:        (void)printf("%s %s\n", cs->out ? "stop" : "resume",
                    617:            cs->user ? "user" : "kernel");
                    618: }
                    619:
1.12      espie     620: static void
1.17      deraadt   621: usage(void)
1.1       deraadt   622: {
                    623:
1.19      mickey    624:        extern char *__progname;
                    625:        fprintf(stderr, "usage: %s "
1.40      sobrado   626:            "[-dlnRTXx] [-e emulation] [-f file] [-m maxdata] [-p pid]\n"
                    627:            "%*s[-t [ceinsw]]\n",
                    628:            __progname, sizeof("usage: ") + strlen(__progname), "");
1.1       deraadt   629:        exit(1);
                    630: }
                    631:
1.12      espie     632: static void
1.17      deraadt   633: setemul(const char *name)
1.1       deraadt   634: {
                    635:        int i;
1.17      deraadt   636:
1.1       deraadt   637:        for (i = 0; emulations[i].name != NULL; i++)
                    638:                if (strcmp(emulations[i].name, name) == 0) {
                    639:                        current = &emulations[i];
                    640:                        return;
                    641:                }
                    642:        warnx("Emulation `%s' unknown", name);
                    643: }