2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#) Copyright (c) 1988, 1993 The Regents of the University of California. All rights reserved.
30 * @(#)kdump.c 8.1 (Berkeley) 6/6/93
31 * $FreeBSD: src/usr.bin/kdump/kdump.c,v 1.29 2006/05/20 14:27:22 netchild Exp $
34 #define _KERNEL_STRUCTURES
36 #include <sys/errno.h>
37 #include <sys/param.h>
39 #include <sys/ktrace.h>
40 #include <sys/ioctl.h>
41 #include <sys/ptrace.h>
51 #include "kdump_subr.h"
53 extern const char *ioctlname(u_long
);
55 static int dumpheader(struct ktr_header
*);
56 static int fread_tail(void *, int, int);
57 static void ktrcsw(struct ktr_csw
*);
58 static void ktrgenio(struct ktr_genio
*, int);
59 static void ktrnamei(char *, int);
60 static void ktrpsig(struct ktr_psig
*);
61 static void ktrsyscall(struct ktr_syscall
*);
62 static void ktrsysret(struct ktr_sysret
*);
63 static void ktruser(int, unsigned char *);
64 static void ktruser_malloc(int, unsigned char *);
65 static void ktruser_rtld(int, unsigned char *);
66 static void timevalfix(struct timeval
*);
67 static void timevalsub(struct timeval
*, struct timeval
*);
68 static void usage(void);
70 int timestamp
, decimal
, fancy
= 1, tail
, maxdata
= 64;
73 const char *tracefile
= DEF_TRACEFILE
;
74 struct ktr_header ktr_header
;
76 #define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
79 main(int argc
, char **argv
)
81 int ch
, col
, ktrlen
, size
;
84 int trpoints
= ALL_POINTS
;
87 setlocale(LC_CTYPE
, "");
89 while ((ch
= getopt(argc
,argv
,"acf:djlm:np:RTt:")) != -1)
101 timestamp
= 2; /* relative timestamp */
111 maxdata
= atoi(optarg
);
117 do_pid
= strtoul(optarg
, &cp
, 0);
119 errx(1,"invalid number %s", optarg
);
122 timestamp
= 2; /* relative timestamp */
128 trpoints
= getpoints(optarg
);
130 errx(1, "unknown trace point in %s", optarg
);
139 m
= (void *)malloc(size
= 1025);
141 errx(1, "%s", strerror(ENOMEM
));
142 if (!freopen(tracefile
, "r", stdin
))
143 err(1, "%s", tracefile
);
144 while (fread_tail(&ktr_header
, sizeof(struct ktr_header
), 1)) {
145 if (trpoints
& (1 << ktr_header
.ktr_type
) &&
146 (do_pid
== -1 || ktr_header
.ktr_pid
== do_pid
))
147 col
= dumpheader(&ktr_header
);
150 if ((ktrlen
= ktr_header
.ktr_len
) < 0)
151 errx(1, "bogus length 0x%x", ktrlen
);
153 m
= (void *)realloc(m
, ktrlen
+1);
155 errx(1, "%s", strerror(ENOMEM
));
158 if (ktrlen
&& fread_tail(m
, ktrlen
, 1) == 0)
159 errx(1, "data too short");
160 if ((trpoints
& (1<<ktr_header
.ktr_type
)) == 0)
164 switch (ktr_header
.ktr_type
) {
166 ktrsyscall((struct ktr_syscall
*)m
);
169 ktrsysret((struct ktr_sysret
*)m
);
176 ktrgenio((struct ktr_genio
*)m
, ktrlen
);
179 ktrpsig((struct ktr_psig
*)m
);
182 ktrcsw((struct ktr_csw
*)m
);
195 fread_tail(void *buf
, int size
, int num
)
199 while ((i
= fread(buf
, size
, num
, stdin
)) == 0 && tail
) {
207 dumpheader(struct ktr_header
*kth
)
209 static char unknown
[64];
210 static struct timeval prevtime
, temp
;
214 switch (kth
->ktr_type
) {
240 sprintf(unknown
, "UNKNOWN(%d)", kth
->ktr_type
);
244 if (kth
->ktr_tid
|| (kth
->ktr_flags
& KTRH_THREADED
) || fixedformat
)
245 col
= printf("%5d:%-4d", kth
->ktr_pid
, kth
->ktr_tid
);
247 col
= printf("%5d", kth
->ktr_pid
);
249 col
+= printf(" %2d", KTRH_CPUID_DECODE(kth
->ktr_flags
));
250 col
+= printf(" %-8.*s ", MAXCOMLEN
, kth
->ktr_comm
);
252 if (timestamp
== 2) {
253 temp
= kth
->ktr_time
;
254 timevalsub(&kth
->ktr_time
, &prevtime
);
257 col
+= printf("%ld.%06ld ",
258 kth
->ktr_time
.tv_sec
, kth
->ktr_time
.tv_usec
);
260 col
+= printf("%s ", type
);
264 #include <sys/syscall.h>
266 #include <kern/syscalls.c>
268 int nsyscalls
= sizeof (syscallnames
) / sizeof (syscallnames
[0]);
270 static const char *ptrace_ops
[] = {
271 "PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U",
272 "PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE",
273 "PT_KILL", "PT_STEP", "PT_ATTACH", "PT_DETACH",
277 ktrsyscall(struct ktr_syscall
*ktr
)
279 int narg
= ktr
->ktr_narg
;
282 if (ktr
->ktr_code
>= nsyscalls
|| ktr
->ktr_code
< 0)
283 printf("[%d]", ktr
->ktr_code
);
285 printf("%s", syscallnames
[ktr
->ktr_code
]);
286 ip
= &ktr
->ktr_args
[0];
291 #define print_number(i,n,c) do { \
293 printf("%c%ld", c, (long)*i); \
295 printf("%c%#lx", c, (long)*i); \
301 if (ktr
->ktr_code
== SYS_ioctl
) {
303 print_number(ip
,narg
,c
);
304 if ((cp
= ioctlname(*ip
)) != NULL
)
308 printf(",%ld", (long)*ip
);
310 printf(",%#lx ", (long)*ip
);
315 } else if (ktr
->ktr_code
== SYS_access
||
316 ktr
->ktr_code
== SYS_eaccess
||
317 ktr
->ktr_code
== SYS_faccessat
) {
318 if (ktr
->ktr_code
== SYS_faccessat
)
319 print_number(ip
,narg
,c
);
320 print_number(ip
,narg
,c
);
322 accessmodename ((int)*ip
);
325 if (ktr
->ktr_code
== SYS_faccessat
) {
327 atflagsname((int)*ip
);
331 } else if (ktr
->ktr_code
== SYS_open
||
332 ktr
->ktr_code
== SYS_mq_open
) {
335 print_number(ip
,narg
,c
);
339 flagsandmodename (flags
, mode
, decimal
);
342 } else if (ktr
->ktr_code
== SYS_wait4
) {
343 print_number(ip
,narg
,c
);
344 print_number(ip
,narg
,c
);
346 wait4optname ((int)*ip
);
349 } else if (ktr
->ktr_code
== SYS_chmod
||
350 ktr
->ktr_code
== SYS_fchmod
||
351 ktr
->ktr_code
== SYS_fchmodat
||
352 ktr
->ktr_code
== SYS_lchmod
) {
353 if (ktr
->ktr_code
== SYS_fchmodat
)
354 print_number(ip
,narg
,c
);
355 print_number(ip
,narg
,c
);
360 if (ktr
->ktr_code
== SYS_fchmodat
) {
362 atflagsname((int)*ip
);
366 } else if (ktr
->ktr_code
== SYS_fchownat
||
367 ktr
->ktr_code
== SYS_fstatat
||
368 ktr
->ktr_code
== SYS_linkat
||
369 ktr
->ktr_code
== SYS_unlinkat
||
370 ktr
->ktr_code
== SYS_utimensat
) {
371 print_number(ip
,narg
,c
);
372 print_number(ip
,narg
,c
);
373 if (ktr
->ktr_code
!= SYS_unlinkat
)
374 print_number(ip
,narg
,c
);
375 if (ktr
->ktr_code
== SYS_fchownat
||
376 ktr
->ktr_code
== SYS_linkat
)
377 print_number(ip
,narg
,c
);
379 atflagsname((int)*ip
);
382 } else if (ktr
->ktr_code
== SYS_mknod
) {
383 print_number(ip
,narg
,c
);
388 } else if (ktr
->ktr_code
== SYS_getfsstat
||
389 ktr
->ktr_code
== SYS_getvfsstat
) {
390 print_number(ip
,narg
,c
);
391 if (ktr
->ktr_code
== SYS_getvfsstat
)
392 print_number(ip
,narg
,c
);
393 print_number(ip
,narg
,c
);
395 getfsstatflagsname ((int)*ip
);
398 } else if (ktr
->ktr_code
== SYS_mount
) {
399 print_number(ip
,narg
,c
);
400 print_number(ip
,narg
,c
);
402 mountflagsname ((int)*ip
);
405 } else if (ktr
->ktr_code
== SYS_unmount
) {
406 print_number(ip
,narg
,c
);
408 mountflagsname ((int)*ip
);
411 } else if (ktr
->ktr_code
== SYS_recvmsg
||
412 ktr
->ktr_code
== SYS_sendmsg
) {
413 print_number(ip
,narg
,c
);
414 print_number(ip
,narg
,c
);
416 sendrecvflagsname ((int)*ip
);
419 } else if (ktr
->ktr_code
== SYS_recvfrom
||
420 ktr
->ktr_code
== SYS_sendto
) {
421 print_number(ip
,narg
,c
);
422 print_number(ip
,narg
,c
);
423 print_number(ip
,narg
,c
);
425 sendrecvflagsname ((int)*ip
);
428 } else if (ktr
->ktr_code
== SYS_chflags
||
429 ktr
->ktr_code
== SYS_chflagsat
||
430 ktr
->ktr_code
== SYS_fchflags
||
431 ktr
->ktr_code
== SYS_lchflags
) {
432 if (ktr
->ktr_code
== SYS_chflagsat
)
433 print_number(ip
,narg
,c
);
434 print_number(ip
,narg
,c
);
436 chflagsname((long)*ip
);
439 if (ktr
->ktr_code
== SYS_chflagsat
) {
441 atflagsname((int)*ip
);
445 } else if (ktr
->ktr_code
== SYS_kill
) {
446 print_number(ip
,narg
,c
);
451 } else if (ktr
->ktr_code
== SYS_reboot
) {
453 rebootoptname((int)*ip
);
456 } else if (ktr
->ktr_code
== SYS_umask
) {
461 } else if (ktr
->ktr_code
== SYS_msync
) {
462 print_number(ip
,narg
,c
);
463 print_number(ip
,narg
,c
);
465 msyncflagsname((int)*ip
);
468 } else if (ktr
->ktr_code
== SYS_mmap
) {
469 print_number(ip
,narg
,c
);
470 print_number(ip
,narg
,c
);
472 mmapprotname ((int)*ip
);
476 mmapflagsname ((int)*ip
);
479 } else if (ktr
->ktr_code
== SYS_mprotect
) {
480 print_number(ip
,narg
,c
);
481 print_number(ip
,narg
,c
);
483 mmapprotname ((int)*ip
);
486 } else if (ktr
->ktr_code
== SYS_madvise
) {
487 print_number(ip
,narg
,c
);
488 print_number(ip
,narg
,c
);
490 madvisebehavname((int)*ip
);
493 } else if (ktr
->ktr_code
== SYS_setpriority
) {
499 print_number(ip
,narg
,c
);
500 print_number(ip
,narg
,c
);
501 } else if (ktr
->ktr_code
== SYS_fcntl
) {
504 print_number(ip
,narg
,c
);
508 fcntlcmdname(cmd
, arg
, decimal
);
511 } else if (ktr
->ktr_code
== SYS_socket
) {
513 sockdomainname((int)*ip
);
517 socktypename((int)*ip
);
521 } else if (ktr
->ktr_code
== SYS_setsockopt
||
522 ktr
->ktr_code
== SYS_getsockopt
) {
523 print_number(ip
,narg
,c
);
525 sockoptlevelname((int)*ip
, decimal
);
529 sockoptname((int)*ip
);
532 } else if (ktr
->ktr_code
== SYS_lseek
) {
533 print_number(ip
,narg
,c
);
534 /* Hidden 'pad' argument, not in lseek(2) */
535 print_number(ip
,narg
,c
);
536 print_number(ip
,narg
,c
);
538 whencename ((int)*ip
);
541 } else if (ktr
->ktr_code
== SYS_flock
) {
542 print_number(ip
,narg
,c
);
547 } else if (ktr
->ktr_code
== SYS_mkfifo
||
548 ktr
->ktr_code
== SYS_mkdir
) {
549 print_number(ip
,narg
,c
);
554 } else if (ktr
->ktr_code
== SYS_shutdown
) {
555 print_number(ip
,narg
,c
);
557 shutdownhowname((int)*ip
);
560 } else if (ktr
->ktr_code
== SYS_socketpair
) {
562 sockdomainname((int)*ip
);
566 socktypename((int)*ip
);
570 } else if (ktr
->ktr_code
== SYS_getrlimit
||
571 ktr
->ktr_code
== SYS_setrlimit
) {
573 rlimitname((int)*ip
);
577 } else if (ktr
->ktr_code
== SYS_quotactl
) {
578 print_number(ip
,narg
,c
);
579 quotactlname((int)*ip
);
583 } else if (ktr
->ktr_code
== SYS_rtprio
) {
585 rtprioname((int)*ip
);
589 } else if (ktr
->ktr_code
== SYS___semctl
) {
590 print_number(ip
,narg
,c
);
591 print_number(ip
,narg
,c
);
592 semctlname((int)*ip
);
595 } else if (ktr
->ktr_code
== SYS_semget
) {
596 print_number(ip
,narg
,c
);
597 print_number(ip
,narg
,c
);
598 semgetname((int)*ip
);
601 } else if (ktr
->ktr_code
== SYS_msgctl
) {
602 print_number(ip
,narg
,c
);
603 shmctlname((int)*ip
);
606 } else if (ktr
->ktr_code
== SYS_shmat
) {
607 print_number(ip
,narg
,c
);
608 print_number(ip
,narg
,c
);
612 } else if (ktr
->ktr_code
== SYS_shmctl
) {
613 print_number(ip
,narg
,c
);
614 shmctlname((int)*ip
);
617 } else if (ktr
->ktr_code
== SYS_minherit
) {
618 print_number(ip
,narg
,c
);
619 print_number(ip
,narg
,c
);
620 minheritname((int)*ip
);
623 } else if (ktr
->ktr_code
== SYS_rfork
) {
629 } else if (ktr
->ktr_code
== SYS_lio_listio
) {
631 lio_listioname((int)*ip
);
635 } else if (ktr
->ktr_code
== SYS_mlockall
) {
637 mlockallname((int)*ip
);
640 } else if (ktr
->ktr_code
== SYS_sched_setscheduler
) {
641 print_number(ip
,narg
,c
);
642 schedpolicyname((int)*ip
);
645 } else if (ktr
->ktr_code
== SYS_sched_get_priority_max
||
646 ktr
->ktr_code
== SYS_sched_get_priority_min
) {
648 schedpolicyname((int)*ip
);
651 } else if (ktr
->ktr_code
== SYS_sendfile
) {
652 print_number(ip
,narg
,c
);
653 print_number(ip
,narg
,c
);
654 print_number(ip
,narg
,c
);
655 print_number(ip
,narg
,c
);
656 print_number(ip
,narg
,c
);
657 print_number(ip
,narg
,c
);
658 sendfileflagsname((int)*ip
);
661 } else if (ktr
->ktr_code
== SYS_kldsym
) {
662 print_number(ip
,narg
,c
);
663 kldsymcmdname((int)*ip
);
666 } else if (ktr
->ktr_code
== SYS_sigprocmask
) {
668 sigprocmaskhowname((int)*ip
);
672 } else if (ktr
->ktr_code
== SYS___acl_get_file
||
673 ktr
->ktr_code
== SYS___acl_set_file
||
674 ktr
->ktr_code
== SYS___acl_get_fd
||
675 ktr
->ktr_code
== SYS___acl_set_fd
||
676 ktr
->ktr_code
== SYS___acl_delete_file
||
677 ktr
->ktr_code
== SYS___acl_delete_fd
||
678 ktr
->ktr_code
== SYS___acl_aclcheck_file
||
679 ktr
->ktr_code
== SYS___acl_aclcheck_fd
) {
680 print_number(ip
,narg
,c
);
681 acltypename((int)*ip
);
684 } else if (ktr
->ktr_code
== SYS_sigaction
) {
690 } else if (ktr
->ktr_code
== SYS_extattrctl
) {
691 print_number(ip
,narg
,c
);
692 extattrctlname((int)*ip
);
695 } else if (ktr
->ktr_code
== SYS_ptrace
) {
696 if (*ip
< (register_t
)NELEM(ptrace_ops
) && *ip
>= 0)
697 printf("(%s", ptrace_ops
[*ip
]);
699 else if (*ip
== PT_GETREGS
)
700 printf("(%s", "PT_GETREGS");
703 else if (*ip
== PT_SETREGS
)
704 printf("(%s", "PT_SETREGS");
707 else if (*ip
== PT_GETFPREGS
)
708 printf("(%s", "PT_GETFPREGS");
711 else if (*ip
== PT_SETFPREGS
)
712 printf("(%s", "PT_SETFPREGS");
715 else if (*ip
== PT_GETDBREGS
)
716 printf("(%s", "PT_GETDBREGS");
719 else if (*ip
== PT_SETDBREGS
)
720 printf("(%s", "PT_SETDBREGS");
723 printf("(%ld", (long)*ip
);
727 } else if (ktr
->ktr_code
== SYS_clock_getres
||
728 ktr
->ktr_code
== SYS_clock_gettime
||
729 ktr
->ktr_code
== SYS_clock_settime
) {
731 clockidname((int)*ip
);
735 } else if (ktr
->ktr_code
== SYS_fpathconf
||
736 ktr
->ktr_code
== SYS_lpathconf
||
737 ktr
->ktr_code
== SYS_pathconf
) {
738 print_number(ip
,narg
,c
);
740 pathconfname((int)*ip
);
743 } else if (ktr
->ktr_code
== SYS_kenv
) {
745 kenvactname((int)*ip
);
749 } else if (ktr
->ktr_code
== SYS_usched_set
) {
750 print_number(ip
,narg
,c
);
752 uschedcmdname((int)*ip
);
755 } else if (ktr
->ktr_code
== SYS_sys_checkpoint
) {
757 ckpttypename((int)*ip
);
761 } else if (ktr
->ktr_code
== SYS_procctl
) {
762 print_number(ip
,narg
,c
);
763 print_number(ip
,narg
,c
);
765 procctlcmdname((int)*ip
);
769 } else if (ktr
->ktr_code
== SYS_mountctl
) {
770 print_number(ip
,narg
,c
);
772 mountctlopname((int)*ip
);
776 } else if (ktr
->ktr_code
== SYS_varsym_list
||
777 ktr
->ktr_code
== SYS_varsym_set
) {
779 varsymlvlname((int)*ip
);
786 print_number(ip
,narg
,c
);
794 ktrsysret(struct ktr_sysret
*ktr
)
796 register_t ret
= ktr
->ktr_retval
;
797 int error
= ktr
->ktr_error
;
798 int code
= ktr
->ktr_code
;
800 if (code
>= nsyscalls
|| code
< 0)
801 printf("[%d] ", code
);
803 printf("%s ", syscallnames
[code
]);
807 printf("%ld", (long)ret
);
808 if (ret
< 0 || ret
> 9)
809 printf("/%#lx", (long)ret
);
812 printf("%ld", (long)ret
);
814 printf("%#lx", (long)ret
);
816 } else if (error
== ERESTART
)
818 else if (error
== EJUSTRETURN
)
819 printf("JUSTRETURN");
821 printf("-1 errno %d", ktr
->ktr_error
);
823 printf(" %s", strerror(ktr
->ktr_error
));
829 ktrnamei(char *cp
, int len
)
831 printf("\"%.*s\"\n", len
, cp
);
835 ktrgenio(struct ktr_genio
*ktr
, int len
)
837 int datalen
= len
- sizeof (struct ktr_genio
);
838 char *dp
= (char *)ktr
+ sizeof (struct ktr_genio
);
843 static int screenwidth
= 0;
845 if (screenwidth
== 0) {
848 if (fancy
&& ioctl(fileno(stderr
), TIOCGWINSZ
, &ws
) != -1 &&
850 screenwidth
= ws
.ws_col
;
854 printf("fd %d %s %d byte%s\n", ktr
->ktr_fd
,
855 ktr
->ktr_rw
== UIO_READ
? "read" : "wrote", datalen
,
856 datalen
== 1 ? "" : "s");
857 if (maxdata
&& datalen
> maxdata
)
861 for (;datalen
> 0; datalen
--, dp
++) {
862 vis(visbuf
, *dp
, VIS_CSTYLE
, *(dp
+1));
865 * Keep track of printables and
866 * space chars (like fold(1)).
878 width
= 8 - (col
&07);
883 if (col
+ width
> (screenwidth
-2)) {
897 const char *signames
[NSIG
] = {
898 "NULL", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", /* 1 - 6 */
899 "EMT", "FPE", "KILL", "BUS", "SEGV", "SYS", /* 7 - 12 */
900 "PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", /* 13 - 18 */
901 "CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU", /* 19 - 24 */
902 "XFSZ", "VTALRM", "PROF", "WINCH", "29", "USR1", /* 25 - 30 */
903 "USR2", NULL
, /* 31 - 32 */
907 ktrpsig(struct ktr_psig
*psig
)
909 printf("SIG%s ", signames
[psig
->signo
]);
910 if (psig
->action
== SIG_DFL
)
913 printf("caught handler=0x%lx mask=0x%x code=0x%x\n",
914 (u_long
)psig
->action
, psig
->mask
.__bits
[0], psig
->code
);
918 ktrcsw(struct ktr_csw
*cs
)
920 printf("%s %s\n", cs
->out
? "stop" : "resume",
921 cs
->user
? "user" : "kernel");
924 #define UTRACE_DLOPEN_START 1
925 #define UTRACE_DLOPEN_STOP 2
926 #define UTRACE_DLCLOSE_START 3
927 #define UTRACE_DLCLOSE_STOP 4
928 #define UTRACE_LOAD_OBJECT 5
929 #define UTRACE_UNLOAD_OBJECT 6
930 #define UTRACE_ADD_RUNDEP 7
931 #define UTRACE_PRELOAD_FINISHED 8
932 #define UTRACE_INIT_CALL 9
933 #define UTRACE_FINI_CALL 10
936 char sig
[4]; /* 'RTLD' */
942 char name
[MAXPATHLEN
];
946 ktruser_rtld(int len
, unsigned char *p
)
948 struct utrace_rtld
*ut
= (struct utrace_rtld
*)p
;
953 case UTRACE_DLOPEN_START
:
955 printf("dlopen(%s, ", ut
->name
);
956 switch (mode
& RTLD_MODEMASK
) {
964 printf("%#x", mode
& RTLD_MODEMASK
);
966 if (mode
& RTLD_GLOBAL
)
967 printf(" | RTLD_GLOBAL");
968 if (mode
& RTLD_TRACE
)
969 printf(" | RTLD_TRACE");
970 if (mode
& ~(RTLD_MODEMASK
| RTLD_GLOBAL
| RTLD_TRACE
))
971 printf(" | %#x", mode
&
972 ~(RTLD_MODEMASK
| RTLD_GLOBAL
| RTLD_TRACE
));
975 case UTRACE_DLOPEN_STOP
:
976 printf("%p = dlopen(%s) ref %d\n", ut
->handle
, ut
->name
,
979 case UTRACE_DLCLOSE_START
:
980 printf("dlclose(%p) (%s, %d)\n", ut
->handle
, ut
->name
,
983 case UTRACE_DLCLOSE_STOP
:
984 printf("dlclose(%p) finished\n", ut
->handle
);
986 case UTRACE_LOAD_OBJECT
:
987 printf("RTLD: loaded %p @ %p - %p (%s)\n", ut
->handle
,
988 ut
->mapbase
, (char *)ut
->mapbase
+ ut
->mapsize
- 1,
991 case UTRACE_UNLOAD_OBJECT
:
992 printf("RTLD: unloaded %p @ %p - %p (%s)\n", ut
->handle
,
993 ut
->mapbase
, (char *)ut
->mapbase
+ ut
->mapsize
- 1,
996 case UTRACE_ADD_RUNDEP
:
997 parent
= ut
->mapbase
;
998 printf("RTLD: %p now depends on %p (%s, %d)\n", parent
,
999 ut
->handle
, ut
->name
, ut
->refcnt
);
1001 case UTRACE_PRELOAD_FINISHED
:
1002 printf("RTLD: LD_PRELOAD finished\n");
1004 case UTRACE_INIT_CALL
:
1005 printf("RTLD: init %p for %p (%s)\n", ut
->mapbase
, ut
->handle
,
1008 case UTRACE_FINI_CALL
:
1009 printf("RTLD: fini %p for %p (%s)\n", ut
->mapbase
, ut
->handle
,
1015 printf("RTLD: %d ", len
);
1018 printf(" %d", *p
++);
1020 printf(" %02x", *p
++);
1025 struct utrace_malloc
{
1032 ktruser_malloc(int len __unused
, unsigned char *p
)
1034 struct utrace_malloc
*ut
= (struct utrace_malloc
*)p
;
1036 if (ut
->p
== NULL
) {
1037 if (ut
->s
== 0 && ut
->r
== NULL
)
1038 printf("malloc_init()\n");
1040 printf("%p = malloc(%zu)\n", ut
->r
, ut
->s
);
1043 printf("free(%p)\n", ut
->p
);
1045 printf("%p = realloc(%p, %zu)\n", ut
->r
, ut
->p
, ut
->s
);
1050 ktruser(int len
, unsigned char *p
)
1053 if (len
>= 8 && bcmp(p
, "RTLD", 4) == 0) {
1054 ktruser_rtld(len
, p
);
1058 if (len
== sizeof(struct utrace_malloc
)) {
1059 ktruser_malloc(len
, p
);
1065 printf(" %02x", *p
++);
1073 "usage: kdump [-dnlRT] [-f trfile] [-m maxdata] [-t [cnisuw]] [-p pid]\n");
1078 timevalsub(struct timeval
*t1
, struct timeval
*t2
)
1080 t1
->tv_sec
-= t2
->tv_sec
;
1081 t1
->tv_usec
-= t2
->tv_usec
;
1086 timevalfix(struct timeval
*t1
)
1088 if (t1
->tv_usec
< 0) {
1090 t1
->tv_usec
+= 1000000;
1092 if (t1
->tv_usec
>= 1000000) {
1094 t1
->tv_usec
-= 1000000;