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