* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char copyright
[] =
"@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)kdump.c 8.1 (Berkeley) 6/6/93";
int timestamp
, decimal
, fancy
= 1, tail
, maxdata
;
char *tracefile
= DEF_TRACEFILE
;
struct ktr_header ktr_header
;
#define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
int trpoints
= ALL_POINTS
;
while ((ch
= getopt(argc
,argv
,"f:dlm:nRTt:")) != EOF
)
timestamp
= 2; /* relative timestamp */
trpoints
= getpoints(optarg
);
"kdump: unknown trace point in %s\n",
m
= (void *)malloc(size
= 1025);
(void)fprintf(stderr
, "kdump: %s.\n", strerror(ENOMEM
));
if (!freopen(tracefile
, "r", stdin
)) {
"kdump: %s: %s.\n", tracefile
, strerror(errno
));
while (fread_tail(&ktr_header
, sizeof(struct ktr_header
), 1)) {
if (trpoints
& (1<<ktr_header
.ktr_type
))
if ((ktrlen
= ktr_header
.ktr_len
) < 0) {
"kdump: bogus length 0x%x\n", ktrlen
);
m
= (void *)realloc(m
, ktrlen
+1);
"kdump: %s.\n", strerror(ENOMEM
));
if (ktrlen
&& fread_tail(m
, ktrlen
, 1) == 0) {
(void)fprintf(stderr
, "kdump: data too short.\n");
if ((trpoints
& (1<<ktr_header
.ktr_type
)) == 0)
switch (ktr_header
.ktr_type
) {
ktrsyscall((struct ktr_syscall
*)m
);
ktrsysret((struct ktr_sysret
*)m
);
ktrgenio((struct ktr_genio
*)m
, ktrlen
);
ktrpsig((struct ktr_psig
*)m
);
ktrcsw((struct ktr_csw
*)m
);
fread_tail(buf
, size
, num
)
while ((i
= fread(buf
, size
, num
, stdin
)) == 0 && tail
) {
static struct timeval prevtime
, temp
;
(void)sprintf(unknown
, "UNKNOWN(%d)", kth
->ktr_type
);
(void)printf("%6d %-8s ", kth
->ktr_pid
, kth
->ktr_comm
);
timevalsub(&kth
->ktr_time
, &prevtime
);
(void)printf("%ld.%06ld ",
kth
->ktr_time
.tv_sec
, kth
->ktr_time
.tv_usec
);
(void)printf("%s ", type
);
#include "/sys/kern/syscalls.c"
int nsyscalls
= sizeof (syscallnames
) / sizeof (syscallnames
[0]);
static char *ptrace_ops
[] = {
"PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U",
"PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE",
register struct ktr_syscall
*ktr
;
register narg
= ktr
->ktr_narg
;
if (ktr
->ktr_code
>= nsyscalls
|| ktr
->ktr_code
< 0)
(void)printf("[%d]", ktr
->ktr_code
);
(void)printf("%s", syscallnames
[ktr
->ktr_code
]);
ip
= (int *)((char *)ktr
+ sizeof(struct ktr_syscall
));
if (ktr
->ktr_code
== SYS_ioctl
) {
(void)printf("(%d", *ip
);
(void)printf("(%#x", *ip
);
if ((cp
= ioctlname(*ip
)) != NULL
)
(void)printf(",%d", *ip
);
(void)printf(",%#x ", *ip
);
} else if (ktr
->ktr_code
== SYS_ptrace
) {
if (*ip
<= PT_STEP
&& *ip
>= 0)
(void)printf("(%s", ptrace_ops
[*ip
]);
(void)printf("(%d", *ip
);
(void)printf("%c%d", c
, *ip
);
(void)printf("%c%#x", c
, *ip
);
register int ret
= ktr
->ktr_retval
;
register int error
= ktr
->ktr_error
;
register int code
= ktr
->ktr_code
;
if (code
>= nsyscalls
|| code
< 0)
(void)printf("[%d] ", code
);
(void)printf("%s ", syscallnames
[code
]);
(void)printf("/%#x", ret
);
(void)printf("%#x", ret
);
} else if (error
== ERESTART
)
else if (error
== EJUSTRETURN
)
(void)printf("JUSTRETURN");
(void)printf("-1 errno %d", ktr
->ktr_error
);
(void)printf(" %s", strerror(ktr
->ktr_error
));
(void)printf("\"%.*s\"\n", len
, cp
);
register int datalen
= len
- sizeof (struct ktr_genio
);
register char *dp
= (char *)ktr
+ sizeof (struct ktr_genio
);
if (fancy
&& ioctl(fileno(stderr
), TIOCGWINSZ
, &ws
) != -1 &&
printf("fd %d %s %d bytes\n", ktr
->ktr_fd
,
ktr
->ktr_rw
== UIO_READ
? "read" : "wrote", datalen
);
if (maxdata
&& datalen
> maxdata
)
for (;datalen
> 0; datalen
--, dp
++) {
(void) vis(visbuf
, *dp
, VIS_CSTYLE
, *(dp
+1));
* Keep track of printables and
* space chars (like fold(1)).
if (col
+ width
> (screenwidth
-2)) {
"NULL", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", /* 1 - 6 */
"EMT", "FPE", "KILL", "BUS", "SEGV", "SYS", /* 7 - 12 */
"PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", /* 13 - 18 */
"CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU", /* 19 - 24 */
"XFSZ", "VTALRM", "PROF", "WINCH", "29", "USR1", /* 25 - 30 */
"USR2", NULL
, /* 31 - 32 */
(void)printf("SIG%s ", signames
[psig
->signo
]);
if (psig
->action
== SIG_DFL
)
(void)printf("SIG_DFL\n");
(void)printf("caught handler=0x%x mask=0x%x code=0x%x\n",
(u_int
)psig
->action
, psig
->mask
, psig
->code
);
(void)printf("%s %s\n", cs
->out
? "stop" : "resume",
cs
->user
? "user" : "kernel");
"usage: kdump [-dnlRT] [-f trfile] [-m maxdata] [-t [cnis]]\n");