diff options
-rw-r--r-- | lib/libc/sys/ktrace.2 | 5 | ||||
-rw-r--r-- | usr.bin/kdump/kdump.1 | 7 | ||||
-rw-r--r-- | usr.bin/kdump/kdump.c | 232 | ||||
-rw-r--r-- | usr.bin/kdump/kdump_subr.h | 3 | ||||
-rw-r--r-- | usr.bin/kdump/mksubr | 4 | ||||
-rw-r--r-- | usr.bin/ktrace/ktrace.1 | 11 | ||||
-rw-r--r-- | usr.bin/ktrace/ktrace.h | 4 | ||||
-rw-r--r-- | usr.bin/ktrace/subr.c | 5 |
8 files changed, 253 insertions, 18 deletions
diff --git a/lib/libc/sys/ktrace.2 b/lib/libc/sys/ktrace.2 index bc5540ff951..b1cae715ba6 100644 --- a/lib/libc/sys/ktrace.2 +++ b/lib/libc/sys/ktrace.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ktrace.2,v 1.19 2007/07/17 16:30:10 jmc Exp $ +.\" $OpenBSD: ktrace.2,v 1.20 2011/07/08 19:30:32 otto Exp $ .\" $NetBSD: ktrace.2,v 1.2 1995/02/27 12:33:58 cgd Exp $ .\" .\" Copyright (c) 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)ktrace.2 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: July 17 2007 $ +.Dd $Mdocdate: July 8 2011 $ .Dt KTRACE 2 .Os .Sh NAME @@ -93,6 +93,7 @@ generate much output). .It Dv KTRFAC_PSIG Trace posted signals. .It Dv KTRFAC_EMUL Trace emulation changes. .It Dv KTRFAC_CSW Trace context switch points. +.It Dv KTRFAC_STRUCT Trace various structs .It Dv KTRFAC_INHERIT Inherit tracing to future children. .El .Pp diff --git a/usr.bin/kdump/kdump.1 b/usr.bin/kdump/kdump.1 index 2a837898b98..f8015bc780e 100644 --- a/usr.bin/kdump/kdump.1 +++ b/usr.bin/kdump/kdump.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kdump.1,v 1.17 2007/05/31 19:20:11 jmc Exp $ +.\" $OpenBSD: kdump.1,v 1.18 2011/07/08 19:29:44 otto Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)kdump.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: July 8 2011 $ .Dt KDUMP 1 .Os .Sh NAME @@ -96,6 +96,9 @@ Show output only for the specified. .It Fl R Display relative timestamps (time since previous entry). +.It Fl r +When decoding STRU records, display structure members such as UIDs, +GIDs, dates etc. symbolically instead of numerically. .It Fl T Display absolute timestamps for each entry (seconds since the Epoch). .It Fl t Op ceinsw diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 2b88b181017..d332e2dc48c 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kdump.c,v 1.54 2011/07/07 06:39:48 otto Exp $ */ +/* $OpenBSD: kdump.c,v 1.55 2011/07/08 19:29:44 otto Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -37,6 +37,11 @@ #include <sys/ptrace.h> #include <sys/socket.h> #include <sys/sysctl.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/stat.h> +#include <netinet/in.h> +#include <arpa/inet.h> #define _KERNEL #include <sys/errno.h> #undef _KERNEL @@ -46,7 +51,10 @@ #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <stdint.h> #include <string.h> +#include <grp.h> +#include <pwd.h> #include <unistd.h> #include <vis.h> @@ -55,11 +63,12 @@ #include "kdump_subr.h" #include "extern.h" -int timestamp, decimal, iohex, fancy = 1, tail, maxdata; +int timestamp, decimal, iohex, fancy = 1, tail, maxdata, resolv; char *tracefile = DEF_TRACEFILE; struct ktr_header ktr_header; pid_t pid = -1; +#define TIME_FORMAT "%b %e %T %Y" #define eqs(s1, s2) (strcmp((s1), (s2)) == 0) #include <sys/syscall.h> @@ -120,6 +129,7 @@ static void ktrnamei(const char *, size_t); static void ktrpsig(struct ktr_psig *); static void ktrsyscall(struct ktr_syscall *); static void ktrsysret(struct ktr_sysret *); +static void ktrstruct(char *, size_t); static void setemul(const char *); static void usage(void); @@ -133,7 +143,7 @@ main(int argc, char *argv[]) current = &emulations[0]; /* native */ - while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:xX")) != -1) + while ((ch = getopt(argc, argv, "e:f:dlm:nrRp:Tt:xX")) != -1) switch (ch) { case 'e': setemul(optarg); @@ -156,6 +166,9 @@ main(int argc, char *argv[]) case 'p': pid = atoi(optarg); break; + case 'r': + resolv = 1; + break; case 'R': timestamp = 2; /* relative timestamp */ break; @@ -228,6 +241,9 @@ main(int argc, char *argv[]) case KTR_EMUL: ktremul(m, ktrlen); break; + case KTR_STRUCT: + ktrstruct(m, ktrlen); + break; } if (tail) (void)fflush(stdout); @@ -276,6 +292,9 @@ dumpheader(struct ktr_header *kth) case KTR_EMUL: type = "EMUL"; break; + case KTR_STRUCT: + type = "STRU"; + break; default: (void)snprintf(unknown, sizeof unknown, "UNKNOWN(%d)", kth->ktr_type); @@ -870,13 +889,218 @@ ktrcsw(struct ktr_csw *cs) cs->user ? "user" : "kernel"); } + + +void +ktrsockaddr(struct sockaddr *sa) +{ +/* + TODO: Support additional address families + #include <netnatm/natm.h> + struct sockaddr_natm *natm; + #include <netsmb/netbios.h> + struct sockaddr_nb *nb; +*/ + char addr[64]; + + /* + * note: ktrstruct() has already verified that sa points to a + * buffer at least sizeof(struct sockaddr) bytes long and exactly + * sa->sa_len bytes long. + */ + printf("struct sockaddr { "); + sockfamilyname(sa->sa_family); + printf(", "); + +#define check_sockaddr_len(n) \ + if (sa_##n->s##n##_len < sizeof(struct sockaddr_##n)) { \ + printf("invalid"); \ + break; \ + } + + switch(sa->sa_family) { + case AF_INET: { + struct sockaddr_in *sa_in; + + sa_in = (struct sockaddr_in *)sa; + check_sockaddr_len(in); + inet_ntop(AF_INET, &sa_in->sin_addr, addr, sizeof addr); + printf("%s:%u", addr, ntohs(sa_in->sin_port)); + break; + } +#ifdef NETATALK + case AF_APPLETALK: { + struct sockaddr_at *sa_at; + struct netrange *nr; + + sa_at = (struct sockaddr_at *)sa; + check_sockaddr_len(at); + nr = &sa_at->sat_range.r_netrange; + printf("%d.%d, %d-%d, %d", ntohs(sa_at->sat_addr.s_net), + sa_at->sat_addr.s_node, ntohs(nr->nr_firstnet), + ntohs(nr->nr_lastnet), nr->nr_phase); + break; + } +#endif + case AF_INET6: { + struct sockaddr_in6 *sa_in6; + + sa_in6 = (struct sockaddr_in6 *)sa; + check_sockaddr_len(in6); + inet_ntop(AF_INET6, &sa_in6->sin6_addr, addr, sizeof addr); + printf("[%s]:%u", addr, htons(sa_in6->sin6_port)); + break; + } +#ifdef IPX + case AF_IPX: { + struct sockaddr_ipx *sa_ipx; + + sa_ipx = (struct sockaddr_ipx *)sa; + check_sockaddr_len(ipx); + /* XXX wish we had ipx_ntop */ + printf("%s", ipx_ntoa(sa_ipx->sipx_addr)); + break; + } +#endif + case AF_UNIX: { + struct sockaddr_un *sa_un; + + sa_un = (struct sockaddr_un *)sa; + if (sa_un->sun_len <= sizeof(sa_un->sun_len) + + sizeof(sa_un->sun_family)) { + printf("invalid"); + break; + } + printf("\"%.*s\"", (int)(sa_un->sun_len - + sizeof(sa_un->sun_len) - sizeof(sa_un->sun_family)), + sa_un->sun_path); + break; + } + default: + printf("unknown address family"); + } + printf(" }\n"); +} + +void +ktrstat(struct stat *statp) +{ + char mode[12], timestr[PATH_MAX + 4]; + struct passwd *pwd; + struct group *grp; + struct tm *tm; + + /* + * note: ktrstruct() has already verified that statp points to a + * buffer exactly sizeof(struct stat) bytes long. + */ + printf("struct stat {"); + strmode(statp->st_mode, mode); + printf("dev=%d, ino=%u, mode=%s, nlink=%u, ", + statp->st_dev, statp->st_ino, mode, statp->st_nlink); + if (resolv == 0 || (pwd = getpwuid(statp->st_uid)) == NULL) + printf("uid=%u, ", statp->st_uid); + else + printf("uid=\"%s\", ", pwd->pw_name); + if (resolv == 0 || (grp = getgrgid(statp->st_gid)) == NULL) + printf("gid=%u, ", statp->st_gid); + else + printf("gid=\"%s\", ", grp->gr_name); + printf("rdev=%d, ", statp->st_rdev); + printf("atime="); + if (resolv == 0) + printf("%jd", (intmax_t)statp->st_atim.tv_sec); + else { + tm = localtime(&statp->st_atim.tv_sec); + (void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm); + printf("\"%s\"", timestr); + } + if (statp->st_atim.tv_nsec != 0) + printf(".%09ld, ", statp->st_atim.tv_nsec); + else + printf(", "); + printf("stime="); + if (resolv == 0) + printf("%jd", (intmax_t)statp->st_mtim.tv_sec); + else { + tm = localtime(&statp->st_mtim.tv_sec); + (void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm); + printf("\"%s\"", timestr); + } + if (statp->st_mtim.tv_nsec != 0) + printf(".%09ld, ", statp->st_mtim.tv_nsec); + else + printf(", "); + printf("ctime="); + if (resolv == 0) + printf("%jd", (intmax_t)statp->st_ctim.tv_sec); + else { + tm = localtime(&statp->st_ctim.tv_sec); + (void)strftime(timestr, sizeof(timestr), TIME_FORMAT, tm); + printf("\"%s\"", timestr); + } + if (statp->st_ctim.tv_nsec != 0) + printf(".%09ld, ", statp->st_ctim.tv_nsec); + else + printf(", "); + printf("size=%lld, blocks=%lld, blksize=%u, flags=0x%x, gen=0x%x", + statp->st_size, statp->st_blocks, statp->st_blksize, + statp->st_flags, statp->st_gen); + printf(" }\n"); +} + +void +ktrstruct(char *buf, size_t buflen) +{ + char *name, *data; + size_t namelen, datalen; + int i; + struct stat sb; + struct sockaddr_storage ss; + + for (name = buf, namelen = 0; namelen < buflen && name[namelen] != '\0'; + ++namelen) + /* nothing */; + if (namelen == buflen) + goto invalid; + if (name[namelen] != '\0') + goto invalid; + data = buf + namelen + 1; + datalen = buflen - namelen - 1; + if (datalen == 0) + goto invalid; + /* sanity check */ + for (i = 0; i < namelen; ++i) + if (!isalpha((unsigned char)name[i])) + goto invalid; + if (strcmp(name, "stat") == 0) { + if (datalen != sizeof(struct stat)) + goto invalid; + memcpy(&sb, data, datalen); + ktrstat(&sb); + } else if (strcmp(name, "sockaddr") == 0) { + if (datalen > sizeof(ss)) + goto invalid; + memcpy(&ss, data, datalen); + if ((ss.ss_family != AF_UNIX && + datalen < sizeof(struct sockaddr)) || datalen != ss.ss_len) + goto invalid; + ktrsockaddr((struct sockaddr *)&ss); + } else { + printf("unknown structure\n"); + } + return; +invalid: + printf("invalid record\n"); +} + static void usage(void) { extern char *__progname; fprintf(stderr, "usage: %s " - "[-dlnRTXx] [-e emulation] [-f file] [-m maxdata] [-p pid]\n" + "[-dlnRrTXx] [-e emulation] [-f file] [-m maxdata] [-p pid]\n" "%*s[-t [ceinsw]]\n", __progname, (int)(sizeof("usage: ") + strlen(__progname)), ""); exit(1); diff --git a/usr.bin/kdump/kdump_subr.h b/usr.bin/kdump/kdump_subr.h index 0d470637523..b08742ef538 100644 --- a/usr.bin/kdump/kdump_subr.h +++ b/usr.bin/kdump/kdump_subr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kdump_subr.h,v 1.2 2011/07/04 06:44:52 otto Exp $ */ +/* $OpenBSD: kdump_subr.h,v 1.3 2011/07/08 19:29:44 otto Exp $ */ /* * Copyright(c) 2006 2006 David Kirchner <dpk@dpk.net> * @@ -40,6 +40,7 @@ void sockoptlevelname(int); void sockdomainname(int); void sockipprotoname(int); void socktypename(int); +void sockfamilyname(int); void thrcreateflagsname(int); void mlockallname(int); void shmatname(int); diff --git a/usr.bin/kdump/mksubr b/usr.bin/kdump/mksubr index 454a32af46b..6652aa99a81 100644 --- a/usr.bin/kdump/mksubr +++ b/usr.bin/kdump/mksubr @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: mksubr,v 1.4 2011/07/04 06:44:52 otto Exp $ +# $OpenBSD: mksubr,v 1.5 2011/07/08 19:29:44 otto Exp $ # # Copyright (c) 2006 David Kirchner <dpk@dpk.net> # @@ -365,7 +365,7 @@ auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal auto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h" #auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h" auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" -#auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" +auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h" auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h" auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h" diff --git a/usr.bin/ktrace/ktrace.1 b/usr.bin/ktrace/ktrace.1 index 2c7afe1538e..c5105c5a43c 100644 --- a/usr.bin/ktrace/ktrace.1 +++ b/usr.bin/ktrace/ktrace.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ktrace.1,v 1.20 2011/06/25 18:44:43 jmc Exp $ +.\" $OpenBSD: ktrace.1,v 1.21 2011/07/08 19:29:44 otto Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)ktrace.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: June 25 2011 $ +.Dd $Mdocdate: July 8 2011 $ .Dt KTRACE 1 .Os .Sh NAME @@ -108,8 +108,9 @@ The default flags are .Cm e , .Cm i , .Cm n , -and -.Cm s . +.Cm s , +and +.Cm t . The following table equates the letters with the tracepoints: .Pp .Bl -tag -width flag -offset indent -compact @@ -123,6 +124,8 @@ trace I/O trace namei translations .It Cm s trace signal processing +.It Cm t +trace various structures .It Cm w trace context switch points .It Cm + diff --git a/usr.bin/ktrace/ktrace.h b/usr.bin/ktrace/ktrace.h index fdf135f8c27..f0ce8b9394b 100644 --- a/usr.bin/ktrace/ktrace.h +++ b/usr.bin/ktrace/ktrace.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: ktrace.h,v 1.3 2003/06/03 02:56:09 millert Exp $*/ +/* * $OpenBSD: ktrace.h,v 1.4 2011/07/08 19:29:44 otto Exp $*/ /*- * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -31,7 +31,7 @@ */ #define DEF_POINTS (KTRFAC_SYSCALL | KTRFAC_SYSRET | KTRFAC_NAMEI | \ - KTRFAC_GENIO | KTRFAC_PSIG | KTRFAC_EMUL) + KTRFAC_GENIO | KTRFAC_PSIG | KTRFAC_EMUL | KTRFAC_STRUCT) #define ALL_POINTS (DEF_POINTS | KTRFAC_CSW) diff --git a/usr.bin/ktrace/subr.c b/usr.bin/ktrace/subr.c index 2702c4ccd76..0b44bb02498 100644 --- a/usr.bin/ktrace/subr.c +++ b/usr.bin/ktrace/subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr.c,v 1.6 2009/10/27 23:59:39 deraadt Exp $ */ +/* $OpenBSD: subr.c,v 1.7 2011/07/08 19:29:44 otto Exp $ */ /* $NetBSD: subr.c,v 1.6 1995/08/31 23:01:45 jtc Exp $ */ /*- @@ -68,6 +68,9 @@ getpoints(s) case 'w': facs |= KTRFAC_CSW; break; + case 't': + facs |= KTRFAC_STRUCT; + break; case '+': facs |= DEF_POINTS; break; |