Home | History | Annotate | Line # | Download | only in kdump
kdump.c revision 1.12
      1   1.1       cgd /*-
      2   1.1       cgd  * Copyright (c) 1988, 1993
      3   1.1       cgd  *	The Regents of the University of California.  All rights reserved.
      4   1.1       cgd  *
      5   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      6   1.1       cgd  * modification, are permitted provided that the following conditions
      7   1.1       cgd  * are met:
      8   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
      9   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     10   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     12   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     13   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     14   1.1       cgd  *    must display the following acknowledgement:
     15   1.1       cgd  *	This product includes software developed by the University of
     16   1.1       cgd  *	California, Berkeley and its contributors.
     17   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     18   1.1       cgd  *    may be used to endorse or promote products derived from this software
     19   1.1       cgd  *    without specific prior written permission.
     20   1.1       cgd  *
     21   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31   1.1       cgd  * SUCH DAMAGE.
     32   1.1       cgd  */
     33   1.1       cgd 
     34   1.1       cgd #ifndef lint
     35   1.1       cgd static char copyright[] =
     36   1.1       cgd "@(#) Copyright (c) 1988, 1993\n\
     37   1.1       cgd 	The Regents of the University of California.  All rights reserved.\n";
     38   1.1       cgd #endif /* not lint */
     39   1.1       cgd 
     40   1.1       cgd #ifndef lint
     41  1.12       jtc #if 0
     42  1.12       jtc static char sccsid[] = "@(#)kdump.c	8.4 (Berkeley) 4/28/95";
     43  1.12       jtc #endif
     44  1.12       jtc static char *rcsid = "$NetBSD: kdump.c,v 1.12 1995/08/31 23:18:33 jtc Exp $";
     45   1.1       cgd #endif /* not lint */
     46   1.1       cgd 
     47   1.1       cgd #include <sys/param.h>
     48   1.1       cgd #include <sys/errno.h>
     49   1.1       cgd #include <sys/time.h>
     50   1.1       cgd #include <sys/uio.h>
     51   1.1       cgd #include <sys/ktrace.h>
     52   1.1       cgd #include <sys/ioctl.h>
     53   1.1       cgd #include <sys/ptrace.h>
     54   1.8       jtc #define _KERNEL
     55   1.1       cgd #include <sys/errno.h>
     56   1.8       jtc #undef _KERNEL
     57   1.4   mycroft 
     58   1.4   mycroft #include <err.h>
     59   1.4   mycroft #include <signal.h>
     60   1.1       cgd #include <stdio.h>
     61   1.1       cgd #include <stdlib.h>
     62   1.1       cgd #include <string.h>
     63   1.4   mycroft #include <unistd.h>
     64   1.4   mycroft #include <vis.h>
     65   1.4   mycroft 
     66   1.1       cgd #include "ktrace.h"
     67   1.1       cgd 
     68   1.1       cgd int timestamp, decimal, fancy = 1, tail, maxdata;
     69   1.1       cgd char *tracefile = DEF_TRACEFILE;
     70   1.1       cgd struct ktr_header ktr_header;
     71   1.1       cgd 
     72   1.1       cgd #define eqs(s1, s2)	(strcmp((s1), (s2)) == 0)
     73   1.1       cgd 
     74  1.11  christos #include <sys/syscall.h>
     75  1.11  christos 
     76  1.11  christos #include "../../sys/compat/hpux/hpux_syscall.h"
     77  1.11  christos #include "../../sys/compat/ibcs2/ibcs2_syscall.h"
     78  1.11  christos #include "../../sys/compat/linux/linux_syscall.h"
     79  1.11  christos #include "../../sys/compat/osf1/osf1_syscall.h"
     80  1.11  christos #include "../../sys/compat/sunos/sunos_syscall.h"
     81  1.11  christos #include "../../sys/compat/svr4/svr4_syscall.h"
     82  1.11  christos #include "../../sys/compat/ultrix/ultrix_syscall.h"
     83  1.11  christos 
     84  1.11  christos #define KTRACE
     85  1.11  christos #include "../../sys/kern/syscalls.c"
     86  1.11  christos 
     87  1.11  christos #include "../../sys/compat/hpux/hpux_syscalls.c"
     88  1.11  christos #include "../../sys/compat/ibcs2/ibcs2_syscalls.c"
     89  1.11  christos #include "../../sys/compat/linux/linux_syscalls.c"
     90  1.11  christos #include "../../sys/compat/osf1/osf1_syscalls.c"
     91  1.11  christos #include "../../sys/compat/sunos/sunos_syscalls.c"
     92  1.11  christos #include "../../sys/compat/svr4/svr4_syscalls.c"
     93  1.11  christos #include "../../sys/compat/ultrix/ultrix_syscalls.c"
     94  1.11  christos #undef KTRACE
     95  1.11  christos 
     96  1.11  christos struct emulation {
     97  1.11  christos 	char *name;		/* Emulation name */
     98  1.11  christos 	char **sysnames;	/* Array of system call names */
     99  1.11  christos 	int  nsysnames;		/* Number of */
    100  1.11  christos };
    101  1.11  christos 
    102  1.11  christos static struct emulation emulations[] = {
    103  1.11  christos 	{ "netbsd",	     syscallnames,        SYS_MAXSYSCALL },
    104  1.11  christos 	{ "hpux",	hpux_syscallnames,   HPUX_SYS_MAXSYSCALL },
    105  1.11  christos 	{ "ibcs2",     ibcs2_syscallnames,  IBCS2_SYS_MAXSYSCALL },
    106  1.11  christos 	{ "linux",     linux_syscallnames,  LINUX_SYS_MAXSYSCALL },
    107  1.11  christos 	{ "osf1",       osf1_syscallnames,   OSF1_SYS_MAXSYSCALL },
    108  1.11  christos 	{ "sunos",     sunos_syscallnames,  SUNOS_SYS_MAXSYSCALL },
    109  1.11  christos 	{ "svr4",       svr4_syscallnames,   SVR4_SYS_MAXSYSCALL },
    110  1.11  christos 	{ "ultrix",   ultrix_syscallnames, ULTRIX_SYS_MAXSYSCALL },
    111  1.11  christos 	{ NULL,			     NULL,		    NULL }
    112  1.11  christos };
    113  1.11  christos 
    114  1.11  christos struct emulation *current;
    115  1.11  christos 
    116  1.11  christos 
    117  1.11  christos static char *ptrace_ops[] = {
    118  1.11  christos 	"PT_TRACE_ME",	"PT_READ_I",	"PT_READ_D",	"PT_READ_U",
    119  1.11  christos 	"PT_WRITE_I",	"PT_WRITE_D",	"PT_WRITE_U",	"PT_CONTINUE",
    120  1.11  christos 	"PT_KILL",	"PT_ATTACH",	"PT_DETACH",
    121  1.11  christos };
    122  1.11  christos 
    123   1.4   mycroft int
    124   1.1       cgd main(argc, argv)
    125   1.1       cgd 	int argc;
    126   1.1       cgd 	char *argv[];
    127   1.1       cgd {
    128   1.1       cgd 	int ch, ktrlen, size;
    129   1.1       cgd 	register void *m;
    130   1.1       cgd 	int trpoints = ALL_POINTS;
    131   1.1       cgd 
    132  1.11  christos 	current = &emulations[0];	/* NetBSD */
    133  1.11  christos 
    134  1.11  christos 	while ((ch = getopt(argc, argv, "e:f:dlm:nRTt:")) != -1)
    135   1.4   mycroft 		switch (ch) {
    136  1.11  christos 		case 'e':
    137  1.11  christos 			setemul(optarg);
    138  1.11  christos 			break;
    139   1.1       cgd 		case 'f':
    140   1.1       cgd 			tracefile = optarg;
    141   1.1       cgd 			break;
    142   1.1       cgd 		case 'd':
    143   1.1       cgd 			decimal = 1;
    144   1.1       cgd 			break;
    145   1.1       cgd 		case 'l':
    146   1.1       cgd 			tail = 1;
    147   1.1       cgd 			break;
    148   1.1       cgd 		case 'm':
    149   1.1       cgd 			maxdata = atoi(optarg);
    150   1.1       cgd 			break;
    151   1.1       cgd 		case 'n':
    152   1.1       cgd 			fancy = 0;
    153   1.1       cgd 			break;
    154   1.1       cgd 		case 'R':
    155   1.1       cgd 			timestamp = 2;	/* relative timestamp */
    156   1.1       cgd 			break;
    157   1.1       cgd 		case 'T':
    158   1.1       cgd 			timestamp = 1;
    159   1.1       cgd 			break;
    160   1.1       cgd 		case 't':
    161   1.1       cgd 			trpoints = getpoints(optarg);
    162   1.4   mycroft 			if (trpoints < 0)
    163   1.4   mycroft 				errx(1, "unknown trace point in %s", optarg);
    164   1.1       cgd 			break;
    165   1.1       cgd 		default:
    166   1.1       cgd 			usage();
    167   1.1       cgd 		}
    168   1.1       cgd 	argv += optind;
    169   1.1       cgd 	argc -= optind;
    170   1.1       cgd 
    171   1.1       cgd 	if (argc > 1)
    172   1.1       cgd 		usage();
    173   1.1       cgd 
    174   1.1       cgd 	m = (void *)malloc(size = 1025);
    175   1.4   mycroft 	if (m == NULL)
    176   1.4   mycroft 		errx(1, "%s", strerror(ENOMEM));
    177   1.4   mycroft 	if (!freopen(tracefile, "r", stdin))
    178   1.4   mycroft 		err(1, "%s", tracefile);
    179   1.1       cgd 	while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
    180   1.1       cgd 		if (trpoints & (1<<ktr_header.ktr_type))
    181   1.1       cgd 			dumpheader(&ktr_header);
    182   1.4   mycroft 		if ((ktrlen = ktr_header.ktr_len) < 0)
    183   1.4   mycroft 			errx(1, "bogus length 0x%x", ktrlen);
    184   1.1       cgd 		if (ktrlen > size) {
    185   1.1       cgd 			m = (void *)realloc(m, ktrlen+1);
    186   1.4   mycroft 			if (m == NULL)
    187   1.4   mycroft 				errx(1, "%s", strerror(ENOMEM));
    188   1.1       cgd 			size = ktrlen;
    189   1.1       cgd 		}
    190   1.4   mycroft 		if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
    191   1.4   mycroft 			errx(1, "data too short");
    192   1.1       cgd 		if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
    193   1.1       cgd 			continue;
    194   1.1       cgd 		switch (ktr_header.ktr_type) {
    195   1.1       cgd 		case KTR_SYSCALL:
    196   1.1       cgd 			ktrsyscall((struct ktr_syscall *)m);
    197   1.1       cgd 			break;
    198   1.1       cgd 		case KTR_SYSRET:
    199   1.1       cgd 			ktrsysret((struct ktr_sysret *)m);
    200   1.1       cgd 			break;
    201   1.1       cgd 		case KTR_NAMEI:
    202   1.1       cgd 			ktrnamei(m, ktrlen);
    203   1.1       cgd 			break;
    204   1.1       cgd 		case KTR_GENIO:
    205   1.1       cgd 			ktrgenio((struct ktr_genio *)m, ktrlen);
    206   1.1       cgd 			break;
    207   1.1       cgd 		case KTR_PSIG:
    208   1.1       cgd 			ktrpsig((struct ktr_psig *)m);
    209   1.1       cgd 			break;
    210   1.1       cgd 		case KTR_CSW:
    211   1.1       cgd 			ktrcsw((struct ktr_csw *)m);
    212   1.1       cgd 			break;
    213  1.11  christos 		case KTR_EMUL:
    214  1.11  christos 			ktremul(m, ktrlen);
    215  1.11  christos 			break;
    216   1.1       cgd 		}
    217   1.1       cgd 		if (tail)
    218   1.1       cgd 			(void)fflush(stdout);
    219   1.1       cgd 	}
    220   1.1       cgd }
    221   1.1       cgd 
    222   1.1       cgd fread_tail(buf, size, num)
    223   1.1       cgd 	char *buf;
    224   1.1       cgd 	int num, size;
    225   1.1       cgd {
    226   1.1       cgd 	int i;
    227   1.1       cgd 
    228   1.1       cgd 	while ((i = fread(buf, size, num, stdin)) == 0 && tail) {
    229   1.1       cgd 		(void)sleep(1);
    230   1.1       cgd 		clearerr(stdin);
    231   1.1       cgd 	}
    232   1.1       cgd 	return (i);
    233   1.1       cgd }
    234   1.1       cgd 
    235   1.1       cgd dumpheader(kth)
    236   1.1       cgd 	struct ktr_header *kth;
    237   1.1       cgd {
    238   1.6   mycroft 	char unknown[64], *type;
    239   1.6   mycroft 	static struct timeval prevtime;
    240   1.6   mycroft 	struct timeval temp;
    241   1.1       cgd 
    242   1.1       cgd 	switch (kth->ktr_type) {
    243   1.1       cgd 	case KTR_SYSCALL:
    244   1.1       cgd 		type = "CALL";
    245   1.1       cgd 		break;
    246   1.1       cgd 	case KTR_SYSRET:
    247   1.1       cgd 		type = "RET ";
    248   1.1       cgd 		break;
    249   1.1       cgd 	case KTR_NAMEI:
    250   1.1       cgd 		type = "NAMI";
    251   1.1       cgd 		break;
    252   1.1       cgd 	case KTR_GENIO:
    253   1.1       cgd 		type = "GIO ";
    254   1.1       cgd 		break;
    255   1.1       cgd 	case KTR_PSIG:
    256   1.1       cgd 		type = "PSIG";
    257   1.1       cgd 		break;
    258   1.1       cgd 	case KTR_CSW:
    259   1.1       cgd 		type = "CSW";
    260   1.1       cgd 		break;
    261  1.11  christos 	case KTR_EMUL:
    262  1.11  christos 		type = "EMUL";
    263  1.11  christos 		break;
    264   1.1       cgd 	default:
    265   1.1       cgd 		(void)sprintf(unknown, "UNKNOWN(%d)", kth->ktr_type);
    266   1.1       cgd 		type = unknown;
    267   1.1       cgd 	}
    268   1.1       cgd 
    269  1.10       cgd 	(void)printf("%6d %-8.*s ", kth->ktr_pid, MAXCOMLEN, kth->ktr_comm);
    270   1.1       cgd 	if (timestamp) {
    271   1.1       cgd 		if (timestamp == 2) {
    272   1.5   mycroft 			timersub(&kth->ktr_time, &prevtime, &temp);
    273   1.5   mycroft 			prevtime = kth->ktr_time;
    274   1.5   mycroft 		} else
    275   1.1       cgd 			temp = kth->ktr_time;
    276   1.5   mycroft 		(void)printf("%ld.%06ld ", temp.tv_sec, temp.tv_usec);
    277   1.1       cgd 	}
    278   1.1       cgd 	(void)printf("%s  ", type);
    279   1.1       cgd }
    280   1.1       cgd 
    281   1.1       cgd 
    282   1.1       cgd ktrsyscall(ktr)
    283   1.1       cgd 	register struct ktr_syscall *ktr;
    284   1.1       cgd {
    285   1.7       cgd 	register argsize = ktr->ktr_argsize;
    286   1.7       cgd 	register register_t *ap;
    287   1.1       cgd 	char *ioctlname();
    288   1.1       cgd 
    289  1.11  christos 	if (ktr->ktr_code >= current->nsysnames || ktr->ktr_code < 0)
    290   1.1       cgd 		(void)printf("[%d]", ktr->ktr_code);
    291   1.1       cgd 	else
    292  1.11  christos 		(void)printf("%s", current->sysnames[ktr->ktr_code]);
    293   1.7       cgd 	ap = (register_t *)((char *)ktr + sizeof(struct ktr_syscall));
    294   1.7       cgd 	if (argsize) {
    295   1.1       cgd 		char c = '(';
    296   1.1       cgd 		if (fancy) {
    297   1.1       cgd 			if (ktr->ktr_code == SYS_ioctl) {
    298   1.1       cgd 				char *cp;
    299   1.1       cgd 				if (decimal)
    300   1.7       cgd 					(void)printf("(%ld", (long)*ap);
    301   1.1       cgd 				else
    302   1.7       cgd 					(void)printf("(%#lx", (long)*ap);
    303   1.7       cgd 				ap++;
    304   1.7       cgd 				argsize -= sizeof(register_t);
    305   1.7       cgd 				if ((cp = ioctlname(*ap)) != NULL)
    306   1.1       cgd 					(void)printf(",%s", cp);
    307   1.1       cgd 				else {
    308   1.1       cgd 					if (decimal)
    309   1.7       cgd 						(void)printf(",%ld",
    310   1.7       cgd 						    (long)*ap);
    311   1.1       cgd 					else
    312   1.7       cgd 						(void)printf(",%#lx ",
    313   1.7       cgd 						    (long)*ap);
    314   1.1       cgd 				}
    315   1.1       cgd 				c = ',';
    316   1.7       cgd 				ap++;
    317   1.7       cgd 				argsize -= sizeof(register_t);
    318   1.1       cgd 			} else if (ktr->ktr_code == SYS_ptrace) {
    319  1.12       jtc 				if (*ap >= 0 && *ap <=
    320  1.12       jtc 				    sizeof(ptrace_ops) / sizeof(ptrace_ops[0]))
    321   1.7       cgd 					(void)printf("(%s", ptrace_ops[*ap]);
    322   1.1       cgd 				else
    323   1.7       cgd 					(void)printf("(%ld", (long)*ap);
    324   1.1       cgd 				c = ',';
    325   1.7       cgd 				ap++;
    326   1.7       cgd 				argsize -= sizeof(register_t);
    327   1.1       cgd 			}
    328   1.1       cgd 		}
    329   1.7       cgd 		while (argsize) {
    330   1.1       cgd 			if (decimal)
    331   1.7       cgd 				(void)printf("%c%ld", c, (long)*ap);
    332   1.1       cgd 			else
    333   1.7       cgd 				(void)printf("%c%#lx", c, (long)*ap);
    334   1.1       cgd 			c = ',';
    335   1.7       cgd 			ap++;
    336   1.7       cgd 			argsize -= sizeof(register_t);
    337   1.1       cgd 		}
    338   1.1       cgd 		(void)putchar(')');
    339   1.1       cgd 	}
    340   1.1       cgd 	(void)putchar('\n');
    341   1.1       cgd }
    342   1.1       cgd 
    343   1.1       cgd ktrsysret(ktr)
    344   1.1       cgd 	struct ktr_sysret *ktr;
    345   1.1       cgd {
    346   1.1       cgd 	register int ret = ktr->ktr_retval;
    347   1.1       cgd 	register int error = ktr->ktr_error;
    348   1.1       cgd 	register int code = ktr->ktr_code;
    349   1.1       cgd 
    350  1.11  christos 	if (code >= current->nsysnames || code < 0)
    351   1.1       cgd 		(void)printf("[%d] ", code);
    352   1.1       cgd 	else
    353  1.11  christos 		(void)printf("%s ", current->sysnames[code]);
    354   1.1       cgd 
    355   1.1       cgd 	if (error == 0) {
    356   1.1       cgd 		if (fancy) {
    357   1.1       cgd 			(void)printf("%d", ret);
    358   1.1       cgd 			if (ret < 0 || ret > 9)
    359   1.1       cgd 				(void)printf("/%#x", ret);
    360   1.1       cgd 		} else {
    361   1.1       cgd 			if (decimal)
    362   1.1       cgd 				(void)printf("%d", ret);
    363   1.1       cgd 			else
    364   1.1       cgd 				(void)printf("%#x", ret);
    365   1.1       cgd 		}
    366   1.1       cgd 	} else if (error == ERESTART)
    367   1.1       cgd 		(void)printf("RESTART");
    368   1.1       cgd 	else if (error == EJUSTRETURN)
    369   1.1       cgd 		(void)printf("JUSTRETURN");
    370   1.1       cgd 	else {
    371   1.1       cgd 		(void)printf("-1 errno %d", ktr->ktr_error);
    372   1.1       cgd 		if (fancy)
    373   1.1       cgd 			(void)printf(" %s", strerror(ktr->ktr_error));
    374   1.1       cgd 	}
    375   1.1       cgd 	(void)putchar('\n');
    376   1.1       cgd }
    377   1.1       cgd 
    378   1.1       cgd ktrnamei(cp, len)
    379   1.1       cgd 	char *cp;
    380   1.1       cgd {
    381   1.1       cgd 	(void)printf("\"%.*s\"\n", len, cp);
    382   1.1       cgd }
    383   1.1       cgd 
    384  1.11  christos ktremul(cp, len)
    385  1.11  christos 	char *cp;
    386  1.11  christos {
    387  1.11  christos 	char name[1024];
    388  1.11  christos 
    389  1.11  christos 	if (len >= sizeof(name))
    390  1.11  christos 		errx(1, "Emulation name too long");
    391  1.11  christos 
    392  1.11  christos 	strncpy(name, cp, len);
    393  1.11  christos 	name[len] = '\0';
    394  1.11  christos 	(void)printf("\"%s\"\n", name);
    395  1.11  christos 
    396  1.11  christos 	setemul(name);
    397  1.11  christos }
    398  1.11  christos 
    399   1.1       cgd ktrgenio(ktr, len)
    400   1.1       cgd 	struct ktr_genio *ktr;
    401   1.1       cgd {
    402   1.1       cgd 	register int datalen = len - sizeof (struct ktr_genio);
    403   1.1       cgd 	register char *dp = (char *)ktr + sizeof (struct ktr_genio);
    404   1.1       cgd 	register char *cp;
    405   1.1       cgd 	register int col = 0;
    406   1.1       cgd 	register width;
    407   1.1       cgd 	char visbuf[5];
    408   1.1       cgd 	static screenwidth = 0;
    409   1.1       cgd 
    410   1.1       cgd 	if (screenwidth == 0) {
    411   1.1       cgd 		struct winsize ws;
    412   1.1       cgd 
    413   1.1       cgd 		if (fancy && ioctl(fileno(stderr), TIOCGWINSZ, &ws) != -1 &&
    414   1.1       cgd 		    ws.ws_col > 8)
    415   1.1       cgd 			screenwidth = ws.ws_col;
    416   1.1       cgd 		else
    417   1.1       cgd 			screenwidth = 80;
    418   1.1       cgd 	}
    419   1.1       cgd 	printf("fd %d %s %d bytes\n", ktr->ktr_fd,
    420   1.1       cgd 		ktr->ktr_rw == UIO_READ ? "read" : "wrote", datalen);
    421   1.1       cgd 	if (maxdata && datalen > maxdata)
    422   1.1       cgd 		datalen = maxdata;
    423   1.1       cgd 	(void)printf("       \"");
    424   1.1       cgd 	col = 8;
    425   1.4   mycroft 	for (; datalen > 0; datalen--, dp++) {
    426   1.1       cgd 		(void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
    427   1.1       cgd 		cp = visbuf;
    428   1.1       cgd 		/*
    429   1.1       cgd 		 * Keep track of printables and
    430   1.1       cgd 		 * space chars (like fold(1)).
    431   1.1       cgd 		 */
    432   1.1       cgd 		if (col == 0) {
    433   1.1       cgd 			(void)putchar('\t');
    434   1.1       cgd 			col = 8;
    435   1.1       cgd 		}
    436   1.1       cgd 		switch(*cp) {
    437   1.1       cgd 		case '\n':
    438   1.1       cgd 			col = 0;
    439   1.1       cgd 			(void)putchar('\n');
    440   1.1       cgd 			continue;
    441   1.1       cgd 		case '\t':
    442   1.1       cgd 			width = 8 - (col&07);
    443   1.1       cgd 			break;
    444   1.1       cgd 		default:
    445   1.1       cgd 			width = strlen(cp);
    446   1.1       cgd 		}
    447   1.1       cgd 		if (col + width > (screenwidth-2)) {
    448   1.1       cgd 			(void)printf("\\\n\t");
    449   1.1       cgd 			col = 8;
    450   1.1       cgd 		}
    451   1.1       cgd 		col += width;
    452   1.1       cgd 		do {
    453   1.1       cgd 			(void)putchar(*cp++);
    454   1.1       cgd 		} while (*cp);
    455   1.1       cgd 	}
    456   1.1       cgd 	if (col == 0)
    457   1.1       cgd 		(void)printf("       ");
    458   1.1       cgd 	(void)printf("\"\n");
    459   1.1       cgd }
    460   1.1       cgd 
    461   1.1       cgd ktrpsig(psig)
    462   1.1       cgd 	struct ktr_psig *psig;
    463   1.1       cgd {
    464   1.4   mycroft 	(void)printf("SIG%s ", sys_signame[psig->signo]);
    465   1.1       cgd 	if (psig->action == SIG_DFL)
    466   1.1       cgd 		(void)printf("SIG_DFL\n");
    467   1.1       cgd 	else
    468   1.7       cgd 		(void)printf("caught handler=0x%lx mask=0x%x code=0x%x\n",
    469   1.7       cgd 		    (u_long)psig->action, psig->mask, psig->code);
    470   1.1       cgd }
    471   1.1       cgd 
    472   1.1       cgd ktrcsw(cs)
    473   1.1       cgd 	struct ktr_csw *cs;
    474   1.1       cgd {
    475   1.1       cgd 	(void)printf("%s %s\n", cs->out ? "stop" : "resume",
    476   1.4   mycroft 	    cs->user ? "user" : "kernel");
    477   1.1       cgd }
    478   1.1       cgd 
    479   1.1       cgd usage()
    480   1.1       cgd {
    481   1.4   mycroft 
    482   1.1       cgd 	(void)fprintf(stderr,
    483  1.11  christos "usage: kdump [-dnlRT] [-e emulation] [-f trfile] [-m maxdata] [-t [cnis]]\n");
    484   1.1       cgd 	exit(1);
    485  1.11  christos }
    486  1.11  christos 
    487  1.11  christos setemul(name)
    488  1.11  christos 	char *name;
    489  1.11  christos {
    490  1.11  christos 	int i;
    491  1.11  christos 	for (i = 0; emulations[i].name != NULL; i++)
    492  1.11  christos 		if (strcmp(emulations[i].name, name) == 0) {
    493  1.11  christos 			current = &emulations[i];
    494  1.11  christos 			return;
    495  1.11  christos 		}
    496  1.11  christos 	warnx("Emulation `%s' unknown", name);
    497   1.1       cgd }
    498