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>
40 #include <sys/ktrace.h>
41 #include <sys/ioctl.h>
42 #include <sys/ptrace.h>
52 #include "kdump_subr.h"
54 extern const char *ioctlname(u_long
);
56 static int dumpheader(struct ktr_header
*);
57 static int fread_tail(void *, int, int);
58 static void ktrcsw(struct ktr_csw
*);
59 static void ktrgenio(struct ktr_genio
*, int);
60 static void ktrnamei(char *, int);
61 static void ktrpsig(struct ktr_psig
*);
62 static void ktrsyscall(struct ktr_syscall
*);
63 static void ktrsysret(struct ktr_sysret
*);
64 static void ktruser(int, unsigned char *);
65 static void ktruser_malloc(int, unsigned char *);
66 static void ktruser_rtld(int, unsigned char *);
67 static void timevalfix(struct timeval
*);
68 static void timevalsub(struct timeval
*, struct timeval
*);
69 static void usage(void);
71 int timestamp
, decimal
, fancy
= 1, tail
, maxdata
= 64;
74 const char *tracefile
= DEF_TRACEFILE
;
75 struct ktr_header ktr_header
;
77 #define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
80 main(int argc
, char **argv
)
82 int ch
, col
, ktrlen
, size
;
85 int trpoints
= ALL_POINTS
;
88 setlocale(LC_CTYPE
, "");
90 while ((ch
= getopt(argc
,argv
,"acf:djlm:np:RTt:")) != -1)
102 timestamp
= 2; /* relative timestamp */
112 maxdata
= atoi(optarg
);
118 do_pid
= strtoul(optarg
, &cp
, 0);
120 errx(1,"invalid number %s", optarg
);
123 timestamp
= 2; /* relative timestamp */
129 trpoints
= getpoints(optarg
);
131 errx(1, "unknown trace point in %s", optarg
);
140 m
= (void *)malloc(size
= 1025);
142 errx(1, "%s", strerror(ENOMEM
));
143 if (!freopen(tracefile
, "r", stdin
))
144 err(1, "%s", tracefile
);
145 while (fread_tail(&ktr_header
, sizeof(struct ktr_header
), 1)) {
146 if (trpoints
& (1 << ktr_header
.ktr_type
) &&
147 (do_pid
== -1 || ktr_header
.ktr_pid
== do_pid
))
148 col
= dumpheader(&ktr_header
);
151 if ((ktrlen
= ktr_header
.ktr_len
) < 0)
152 errx(1, "bogus length 0x%x", ktrlen
);
154 m
= (void *)realloc(m
, ktrlen
+1);
156 errx(1, "%s", strerror(ENOMEM
));
159 if (ktrlen
&& fread_tail(m
, ktrlen
, 1) == 0)
160 errx(1, "data too short");
161 if ((trpoints
& (1<<ktr_header
.ktr_type
)) == 0)
165 switch (ktr_header
.ktr_type
) {
167 ktrsyscall((struct ktr_syscall
*)m
);
170 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
) {
237 sprintf(unknown
, "UNKNOWN(%d)", kth
->ktr_type
);
241 if (kth
->ktr_tid
|| (kth
->ktr_flags
& KTRH_THREADED
) || fixedformat
)
242 col
= printf("%5d:%-4d", kth
->ktr_pid
, kth
->ktr_tid
);
244 col
= printf("%5d", kth
->ktr_pid
);
246 col
+= printf(" %2d", KTRH_CPUID_DECODE(kth
->ktr_flags
));
247 col
+= printf(" %-8.*s ", MAXCOMLEN
, kth
->ktr_comm
);
249 if (timestamp
== 2) {
250 temp
= kth
->ktr_time
;
251 timevalsub(&kth
->ktr_time
, &prevtime
);
254 col
+= printf("%ld.%06ld ",
255 kth
->ktr_time
.tv_sec
, kth
->ktr_time
.tv_usec
);
257 col
+= printf("%s ", type
);
261 #include <sys/syscall.h>
263 #include <sys/kern/syscalls.c>
265 int nsyscalls
= sizeof (syscallnames
) / sizeof (syscallnames
[0]);
267 static const char *ptrace_ops
[] = {
268 "PT_TRACE_ME", "PT_READ_I", "PT_READ_D", "PT_READ_U",
269 "PT_WRITE_I", "PT_WRITE_D", "PT_WRITE_U", "PT_CONTINUE",
270 "PT_KILL", "PT_STEP", "PT_ATTACH", "PT_DETACH",
274 ktrsyscall(struct ktr_syscall
*ktr
)
276 int narg
= ktr
->ktr_narg
;
279 if (ktr
->ktr_code
>= nsyscalls
|| ktr
->ktr_code
< 0)
280 printf("[%d]", ktr
->ktr_code
);
282 printf("%s", syscallnames
[ktr
->ktr_code
]);
283 ip
= &ktr
->ktr_args
[0];
288 #define print_number(i,n,c) do { \
290 printf("%c%ld", c, (long)*i); \
292 printf("%c%#lx", c, (long)*i); \
298 if (ktr
->ktr_code
== SYS_ioctl
) {
300 print_number(ip
,narg
,c
);
301 if ((cp
= ioctlname(*ip
)) != NULL
)
305 printf(",%ld", (long)*ip
);
307 printf(",%#lx ", (long)*ip
);
312 } else if (ktr
->ktr_code
== SYS_access
||
313 ktr
->ktr_code
== SYS_eaccess
||
314 ktr
->ktr_code
== SYS_faccessat
) {
315 if (ktr
->ktr_code
== SYS_faccessat
)
316 print_number(ip
,narg
,c
);
317 print_number(ip
,narg
,c
);
319 accessmodename ((int)*ip
);
322 if (ktr
->ktr_code
== SYS_faccessat
) {
324 atflagsname((int)*ip
);
328 } else if (ktr
->ktr_code
== SYS_open
||
329 ktr
->ktr_code
== SYS_mq_open
) {
332 print_number(ip
,narg
,c
);
336 flagsandmodename (flags
, mode
, decimal
);
339 } else if (ktr
->ktr_code
== SYS_wait4
) {
340 print_number(ip
,narg
,c
);
341 print_number(ip
,narg
,c
);
343 wait4optname ((int)*ip
);
346 } else if (ktr
->ktr_code
== SYS_chmod
||
347 ktr
->ktr_code
== SYS_fchmod
||
348 ktr
->ktr_code
== SYS_fchmodat
||
349 ktr
->ktr_code
== SYS_lchmod
) {
350 if (ktr
->ktr_code
== SYS_fchmodat
)
351 print_number(ip
,narg
,c
);
352 print_number(ip
,narg
,c
);
357 if (ktr
->ktr_code
== SYS_fchmodat
) {
359 atflagsname((int)*ip
);
363 } else if (ktr
->ktr_code
== SYS_fchownat
||
364 ktr
->ktr_code
== SYS_fstatat
||
365 ktr
->ktr_code
== SYS_linkat
||
366 ktr
->ktr_code
== SYS_unlinkat
||
367 ktr
->ktr_code
== SYS_utimensat
) {
368 print_number(ip
,narg
,c
);
369 print_number(ip
,narg
,c
);
370 if (ktr
->ktr_code
!= SYS_unlinkat
)
371 print_number(ip
,narg
,c
);
372 if (ktr
->ktr_code
== SYS_fchownat
||
373 ktr
->ktr_code
== SYS_linkat
)
374 print_number(ip
,narg
,c
);
376 atflagsname((int)*ip
);
379 } else if (ktr
->ktr_code
== SYS_mknod
) {
380 print_number(ip
,narg
,c
);
385 } else if (ktr
->ktr_code
== SYS_getfsstat
||
386 ktr
->ktr_code
== SYS_getvfsstat
) {
387 print_number(ip
,narg
,c
);
388 if (ktr
->ktr_code
== SYS_getvfsstat
)
389 print_number(ip
,narg
,c
);
390 print_number(ip
,narg
,c
);
392 getfsstatflagsname ((int)*ip
);
395 } else if (ktr
->ktr_code
== SYS_mount
) {
396 print_number(ip
,narg
,c
);
397 print_number(ip
,narg
,c
);
399 mountflagsname ((int)*ip
);
402 } else if (ktr
->ktr_code
== SYS_unmount
) {
403 print_number(ip
,narg
,c
);
405 mountflagsname ((int)*ip
);
408 } else if (ktr
->ktr_code
== SYS_recvmsg
||
409 ktr
->ktr_code
== SYS_sendmsg
) {
410 print_number(ip
,narg
,c
);
411 print_number(ip
,narg
,c
);
413 sendrecvflagsname ((int)*ip
);
416 } else if (ktr
->ktr_code
== SYS_recvfrom
||
417 ktr
->ktr_code
== SYS_sendto
) {
418 print_number(ip
,narg
,c
);
419 print_number(ip
,narg
,c
);
420 print_number(ip
,narg
,c
);
422 sendrecvflagsname ((int)*ip
);
425 } else if (ktr
->ktr_code
== SYS_chflags
||
426 ktr
->ktr_code
== SYS_chflagsat
||
427 ktr
->ktr_code
== SYS_fchflags
||
428 ktr
->ktr_code
== SYS_lchflags
) {
429 if (ktr
->ktr_code
== SYS_chflagsat
)
430 print_number(ip
,narg
,c
);
431 print_number(ip
,narg
,c
);
433 chflagsname((int)*ip
);
436 if (ktr
->ktr_code
== SYS_chflagsat
) {
438 atflagsname((int)*ip
);
442 } else if (ktr
->ktr_code
== SYS_kill
) {
443 print_number(ip
,narg
,c
);
448 } else if (ktr
->ktr_code
== SYS_reboot
) {
450 rebootoptname((int)*ip
);
453 } else if (ktr
->ktr_code
== SYS_umask
) {
458 } else if (ktr
->ktr_code
== SYS_msync
) {
459 print_number(ip
,narg
,c
);
460 print_number(ip
,narg
,c
);
462 msyncflagsname((int)*ip
);
465 } else if (ktr
->ktr_code
== SYS_mmap
) {
466 print_number(ip
,narg
,c
);
467 print_number(ip
,narg
,c
);
469 mmapprotname ((int)*ip
);
473 mmapflagsname ((int)*ip
);
476 } else if (ktr
->ktr_code
== SYS_mprotect
) {
477 print_number(ip
,narg
,c
);
478 print_number(ip
,narg
,c
);
480 mmapprotname ((int)*ip
);
483 } else if (ktr
->ktr_code
== SYS_madvise
) {
484 print_number(ip
,narg
,c
);
485 print_number(ip
,narg
,c
);
487 madvisebehavname((int)*ip
);
490 } else if (ktr
->ktr_code
== SYS_setpriority
) {
496 print_number(ip
,narg
,c
);
497 print_number(ip
,narg
,c
);
498 } else if (ktr
->ktr_code
== SYS_fcntl
) {
501 print_number(ip
,narg
,c
);
505 fcntlcmdname(cmd
, arg
, decimal
);
508 } else if (ktr
->ktr_code
== SYS_socket
) {
510 sockdomainname((int)*ip
);
514 socktypename((int)*ip
);
518 } else if (ktr
->ktr_code
== SYS_setsockopt
||
519 ktr
->ktr_code
== SYS_getsockopt
) {
520 print_number(ip
,narg
,c
);
522 sockoptlevelname((int)*ip
, decimal
);
526 sockoptname((int)*ip
);
529 } else if (ktr
->ktr_code
== SYS_lseek
) {
530 print_number(ip
,narg
,c
);
531 /* Hidden 'pad' argument, not in lseek(2) */
532 print_number(ip
,narg
,c
);
533 print_number(ip
,narg
,c
);
535 whencename ((int)*ip
);
538 } else if (ktr
->ktr_code
== SYS_flock
) {
539 print_number(ip
,narg
,c
);
544 } else if (ktr
->ktr_code
== SYS_mkfifo
||
545 ktr
->ktr_code
== SYS_mkdir
) {
546 print_number(ip
,narg
,c
);
551 } else if (ktr
->ktr_code
== SYS_shutdown
) {
552 print_number(ip
,narg
,c
);
554 shutdownhowname((int)*ip
);
557 } else if (ktr
->ktr_code
== SYS_socketpair
) {
559 sockdomainname((int)*ip
);
563 socktypename((int)*ip
);
567 } else if (ktr
->ktr_code
== SYS_getrlimit
||
568 ktr
->ktr_code
== SYS_setrlimit
) {
570 rlimitname((int)*ip
);
574 } else if (ktr
->ktr_code
== SYS_quotactl
) {
575 print_number(ip
,narg
,c
);
576 quotactlname((int)*ip
);
580 } else if (ktr
->ktr_code
== SYS_rtprio
) {
582 rtprioname((int)*ip
);
586 } else if (ktr
->ktr_code
== SYS___semctl
) {
587 print_number(ip
,narg
,c
);
588 print_number(ip
,narg
,c
);
589 semctlname((int)*ip
);
592 } else if (ktr
->ktr_code
== SYS_semget
) {
593 print_number(ip
,narg
,c
);
594 print_number(ip
,narg
,c
);
595 semgetname((int)*ip
);
598 } else if (ktr
->ktr_code
== SYS_msgctl
) {
599 print_number(ip
,narg
,c
);
600 shmctlname((int)*ip
);
603 } else if (ktr
->ktr_code
== SYS_shmat
) {
604 print_number(ip
,narg
,c
);
605 print_number(ip
,narg
,c
);
609 } else if (ktr
->ktr_code
== SYS_shmctl
) {
610 print_number(ip
,narg
,c
);
611 shmctlname((int)*ip
);
614 } else if (ktr
->ktr_code
== SYS_minherit
) {
615 print_number(ip
,narg
,c
);
616 print_number(ip
,narg
,c
);
617 minheritname((int)*ip
);
620 } else if (ktr
->ktr_code
== SYS_rfork
) {
626 } else if (ktr
->ktr_code
== SYS_lio_listio
) {
628 lio_listioname((int)*ip
);
632 } else if (ktr
->ktr_code
== SYS_mlockall
) {
634 mlockallname((int)*ip
);
637 } else if (ktr
->ktr_code
== SYS_sched_setscheduler
) {
638 print_number(ip
,narg
,c
);
639 schedpolicyname((int)*ip
);
642 } else if (ktr
->ktr_code
== SYS_sched_get_priority_max
||
643 ktr
->ktr_code
== SYS_sched_get_priority_min
) {
645 schedpolicyname((int)*ip
);
648 } else if (ktr
->ktr_code
== SYS_sendfile
) {
649 print_number(ip
,narg
,c
);
650 print_number(ip
,narg
,c
);
651 print_number(ip
,narg
,c
);
652 print_number(ip
,narg
,c
);
653 print_number(ip
,narg
,c
);
654 print_number(ip
,narg
,c
);
655 sendfileflagsname((int)*ip
);
658 } else if (ktr
->ktr_code
== SYS_kldsym
) {
659 print_number(ip
,narg
,c
);
660 kldsymcmdname((int)*ip
);
663 } else if (ktr
->ktr_code
== SYS_sigprocmask
) {
665 sigprocmaskhowname((int)*ip
);
669 } else if (ktr
->ktr_code
== SYS___acl_get_file
||
670 ktr
->ktr_code
== SYS___acl_set_file
||
671 ktr
->ktr_code
== SYS___acl_get_fd
||
672 ktr
->ktr_code
== SYS___acl_set_fd
||
673 ktr
->ktr_code
== SYS___acl_delete_file
||
674 ktr
->ktr_code
== SYS___acl_delete_fd
||
675 ktr
->ktr_code
== SYS___acl_aclcheck_file
||
676 ktr
->ktr_code
== SYS___acl_aclcheck_fd
) {
677 print_number(ip
,narg
,c
);
678 acltypename((int)*ip
);
681 } else if (ktr
->ktr_code
== SYS_sigaction
) {
687 } else if (ktr
->ktr_code
== SYS_extattrctl
) {
688 print_number(ip
,narg
,c
);
689 extattrctlname((int)*ip
);
692 } else if (ktr
->ktr_code
== SYS_ptrace
) {
693 if (*ip
< (register_t
)(sizeof(ptrace_ops
) /
694 sizeof(ptrace_ops
[0])) && *ip
>= 0)
695 printf("(%s", ptrace_ops
[*ip
]);
697 else if (*ip
== PT_GETREGS
)
698 printf("(%s", "PT_GETREGS");
701 else if (*ip
== PT_SETREGS
)
702 printf("(%s", "PT_SETREGS");
705 else if (*ip
== PT_GETFPREGS
)
706 printf("(%s", "PT_GETFPREGS");
709 else if (*ip
== PT_SETFPREGS
)
710 printf("(%s", "PT_SETFPREGS");
713 else if (*ip
== PT_GETDBREGS
)
714 printf("(%s", "PT_GETDBREGS");
717 else if (*ip
== PT_SETDBREGS
)
718 printf("(%s", "PT_SETDBREGS");
721 printf("(%ld", (long)*ip
);
725 } else if (ktr
->ktr_code
== SYS_clock_getres
||
726 ktr
->ktr_code
== SYS_clock_gettime
||
727 ktr
->ktr_code
== SYS_clock_settime
) {
729 clockidname((int)*ip
);
733 } else if (ktr
->ktr_code
== SYS_fpathconf
||
734 ktr
->ktr_code
== SYS_lpathconf
||
735 ktr
->ktr_code
== SYS_pathconf
) {
736 print_number(ip
,narg
,c
);
738 pathconfname((int)*ip
);
741 } else if (ktr
->ktr_code
== SYS_kenv
) {
743 kenvactname((int)*ip
);
747 } else if (ktr
->ktr_code
== SYS_usched_set
) {
748 print_number(ip
,narg
,c
);
750 uschedcmdname((int)*ip
);
753 } else if (ktr
->ktr_code
== SYS_sys_checkpoint
) {
755 ckpttypename((int)*ip
);
759 } else if (ktr
->ktr_code
== SYS_procctl
) {
760 print_number(ip
,narg
,c
);
761 print_number(ip
,narg
,c
);
763 procctlcmdname((int)*ip
);
767 } else if (ktr
->ktr_code
== SYS_mountctl
) {
768 print_number(ip
,narg
,c
);
770 mountctlopname((int)*ip
);
774 } else if (ktr
->ktr_code
== SYS_varsym_list
||
775 ktr
->ktr_code
== SYS_varsym_set
) {
777 varsymlvlname((int)*ip
);
784 print_number(ip
,narg
,c
);
792 ktrsysret(struct ktr_sysret
*ktr
)
794 register_t ret
= ktr
->ktr_retval
;
795 int error
= ktr
->ktr_error
;
796 int code
= ktr
->ktr_code
;
798 if (code
>= nsyscalls
|| code
< 0)
799 printf("[%d] ", code
);
801 printf("%s ", syscallnames
[code
]);
805 printf("%ld", (long)ret
);
806 if (ret
< 0 || ret
> 9)
807 printf("/%#lx", (long)ret
);
810 printf("%ld", (long)ret
);
812 printf("%#lx", (long)ret
);
814 } else if (error
== ERESTART
)
816 else if (error
== EJUSTRETURN
)
817 printf("JUSTRETURN");
819 printf("-1 errno %d", ktr
->ktr_error
);
821 printf(" %s", strerror(ktr
->ktr_error
));
827 ktrnamei(char *cp
, int len
)
829 printf("\"%.*s\"\n", len
, cp
);
833 ktrgenio(struct ktr_genio
*ktr
, int len
)
835 int datalen
= len
- sizeof (struct ktr_genio
);
836 char *dp
= (char *)ktr
+ sizeof (struct ktr_genio
);
841 static int screenwidth
= 0;
843 if (screenwidth
== 0) {
846 if (fancy
&& ioctl(fileno(stderr
), TIOCGWINSZ
, &ws
) != -1 &&
848 screenwidth
= ws
.ws_col
;
852 printf("fd %d %s %d byte%s\n", ktr
->ktr_fd
,
853 ktr
->ktr_rw
== UIO_READ
? "read" : "wrote", datalen
,
854 datalen
== 1 ? "" : "s");
855 if (maxdata
&& datalen
> maxdata
)
859 for (;datalen
> 0; datalen
--, dp
++) {
860 vis(visbuf
, *dp
, VIS_CSTYLE
, *(dp
+1));
863 * Keep track of printables and
864 * space chars (like fold(1)).
876 width
= 8 - (col
&07);
881 if (col
+ width
> (screenwidth
-2)) {
895 const char *signames
[NSIG
] = {
896 "NULL", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", /* 1 - 6 */
897 "EMT", "FPE", "KILL", "BUS", "SEGV", "SYS", /* 7 - 12 */
898 "PIPE", "ALRM", "TERM", "URG", "STOP", "TSTP", /* 13 - 18 */
899 "CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU", /* 19 - 24 */
900 "XFSZ", "VTALRM", "PROF", "WINCH", "29", "USR1", /* 25 - 30 */
901 "USR2", NULL
, /* 31 - 32 */
905 ktrpsig(struct ktr_psig
*psig
)
907 printf("SIG%s ", signames
[psig
->signo
]);
908 if (psig
->action
== SIG_DFL
)
911 printf("caught handler=0x%lx mask=0x%x code=0x%x\n",
912 (u_long
)psig
->action
, psig
->mask
.__bits
[0], psig
->code
);
916 ktrcsw(struct ktr_csw
*cs
)
918 printf("%s %s\n", cs
->out
? "stop" : "resume",
919 cs
->user
? "user" : "kernel");
922 #define UTRACE_DLOPEN_START 1
923 #define UTRACE_DLOPEN_STOP 2
924 #define UTRACE_DLCLOSE_START 3
925 #define UTRACE_DLCLOSE_STOP 4
926 #define UTRACE_LOAD_OBJECT 5
927 #define UTRACE_UNLOAD_OBJECT 6
928 #define UTRACE_ADD_RUNDEP 7
929 #define UTRACE_PRELOAD_FINISHED 8
930 #define UTRACE_INIT_CALL 9
931 #define UTRACE_FINI_CALL 10
934 char sig
[4]; /* 'RTLD' */
940 char name
[MAXPATHLEN
];
944 ktruser_rtld(int len
, unsigned char *p
)
946 struct utrace_rtld
*ut
= (struct utrace_rtld
*)p
;
951 case UTRACE_DLOPEN_START
:
953 printf("dlopen(%s, ", ut
->name
);
954 switch (mode
& RTLD_MODEMASK
) {
962 printf("%#x", mode
& RTLD_MODEMASK
);
964 if (mode
& RTLD_GLOBAL
)
965 printf(" | RTLD_GLOBAL");
966 if (mode
& RTLD_TRACE
)
967 printf(" | RTLD_TRACE");
968 if (mode
& ~(RTLD_MODEMASK
| RTLD_GLOBAL
| RTLD_TRACE
))
969 printf(" | %#x", mode
&
970 ~(RTLD_MODEMASK
| RTLD_GLOBAL
| RTLD_TRACE
));
973 case UTRACE_DLOPEN_STOP
:
974 printf("%p = dlopen(%s) ref %d\n", ut
->handle
, ut
->name
,
977 case UTRACE_DLCLOSE_START
:
978 printf("dlclose(%p) (%s, %d)\n", ut
->handle
, ut
->name
,
981 case UTRACE_DLCLOSE_STOP
:
982 printf("dlclose(%p) finished\n", ut
->handle
);
984 case UTRACE_LOAD_OBJECT
:
985 printf("RTLD: loaded %p @ %p - %p (%s)\n", ut
->handle
,
986 ut
->mapbase
, (char *)ut
->mapbase
+ ut
->mapsize
- 1,
989 case UTRACE_UNLOAD_OBJECT
:
990 printf("RTLD: unloaded %p @ %p - %p (%s)\n", ut
->handle
,
991 ut
->mapbase
, (char *)ut
->mapbase
+ ut
->mapsize
- 1,
994 case UTRACE_ADD_RUNDEP
:
995 parent
= ut
->mapbase
;
996 printf("RTLD: %p now depends on %p (%s, %d)\n", parent
,
997 ut
->handle
, ut
->name
, ut
->refcnt
);
999 case UTRACE_PRELOAD_FINISHED
:
1000 printf("RTLD: LD_PRELOAD finished\n");
1002 case UTRACE_INIT_CALL
:
1003 printf("RTLD: init %p for %p (%s)\n", ut
->mapbase
, ut
->handle
,
1006 case UTRACE_FINI_CALL
:
1007 printf("RTLD: fini %p for %p (%s)\n", ut
->mapbase
, ut
->handle
,
1013 printf("RTLD: %d ", len
);
1016 printf(" %d", *p
++);
1018 printf(" %02x", *p
++);
1023 struct utrace_malloc
{
1030 ktruser_malloc(int len __unused
, unsigned char *p
)
1032 struct utrace_malloc
*ut
= (struct utrace_malloc
*)p
;
1034 if (ut
->p
== NULL
) {
1035 if (ut
->s
== 0 && ut
->r
== NULL
)
1036 printf("malloc_init()\n");
1038 printf("%p = malloc(%zu)\n", ut
->r
, ut
->s
);
1041 printf("free(%p)\n", ut
->p
);
1043 printf("%p = realloc(%p, %zu)\n", ut
->r
, ut
->p
, ut
->s
);
1048 ktruser(int len
, unsigned char *p
)
1051 if (len
>= 8 && bcmp(p
, "RTLD", 4) == 0) {
1052 ktruser_rtld(len
, p
);
1056 if (len
== sizeof(struct utrace_malloc
)) {
1057 ktruser_malloc(len
, p
);
1063 printf(" %02x", *p
++);
1071 "usage: kdump [-dnlRT] [-f trfile] [-m maxdata] [-t [cnisuw]] [-p pid]\n");
1076 timevalsub(struct timeval
*t1
, struct timeval
*t2
)
1078 t1
->tv_sec
-= t2
->tv_sec
;
1079 t1
->tv_usec
-= t2
->tv_usec
;
1084 timevalfix(struct timeval
*t1
)
1086 if (t1
->tv_usec
< 0) {
1088 t1
->tv_usec
+= 1000000;
1090 if (t1
->tv_usec
>= 1000000) {
1092 t1
->tv_usec
-= 1000000;