svn commit: r332239 - stable/11/usr.bin/truss
Michael Tuexen
tuexen at FreeBSD.org
Sat Apr 7 20:52:06 UTC 2018
Author: tuexen
Date: Sat Apr 7 20:52:05 2018
New Revision: 332239
URL: https://svnweb.freebsd.org/changeset/base/332239
Log:
MFC r327919:
Add support for readv() and writev() to truss.
Sponsored by:i Netflix, Inc.
Modified:
stable/11/usr.bin/truss/syscall.h
stable/11/usr.bin/truss/syscalls.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/usr.bin/truss/syscall.h
==============================================================================
--- stable/11/usr.bin/truss/syscall.h Sat Apr 7 20:47:25 2018 (r332238)
+++ stable/11/usr.bin/truss/syscall.h Sat Apr 7 20:52:05 2018 (r332239)
@@ -81,7 +81,7 @@ enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHe
Sockoptname, Msgflags, CapRights, PUInt, PQuadHex, Acltype,
Extattrnamespace, Minherit, Mlockall, Mountflags, Msync, Priowhich,
Ptraceop, Quotactlcmd, Reboothowto, Rtpriofunc, Schedpolicy, Schedparam,
- PSig, Siginfo, Kevent11,
+ PSig, Siginfo, Kevent11, Iovec,
CloudABIAdvice, CloudABIClockID, ClouduABIFDSFlags,
CloudABIFDStat, CloudABIFileStat, CloudABIFileType,
Modified: stable/11/usr.bin/truss/syscalls.c
==============================================================================
--- stable/11/usr.bin/truss/syscalls.c Sat Apr 7 20:47:25 2018 (r332238)
+++ stable/11/usr.bin/truss/syscalls.c Sat Apr 7 20:52:05 2018 (r332239)
@@ -370,6 +370,8 @@ static struct syscall decoded_syscalls[] = {
.args = { { Name, 0 }, { Quotactlcmd, 1 }, { Int, 2 }, { Ptr, 3 } } },
{ .name = "read", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { BinString | OUT, 1 }, { Sizet, 2 } } },
+ { .name = "readv", .ret_type = 1, .nargs = 3,
+ .args = { { Int, 0 }, { Iovec, 1 }, { Int, 2 } } },
{ .name = "readlink", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Sizet, 2 } } },
{ .name = "readlinkat", .ret_type = 1, .nargs = 4,
@@ -504,6 +506,8 @@ static struct syscall decoded_syscalls[] = {
{ Siginfo | OUT, 5 } } },
{ .name = "write", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { BinString | IN, 1 }, { Sizet, 2 } } },
+ { .name = "writev", .ret_type = 1, .nargs = 3,
+ .args = { { Int, 0 }, { Iovec, 1 }, { Int, 2 } } },
/* Linux ABI */
{ .name = "linux_access", .ret_type = 1, .nargs = 2,
@@ -2062,6 +2066,68 @@ print_arg(struct syscall_args *sc, unsigned long *args
fprintf(fp, " }");
} else
fprintf(fp, "0x%lx", args[sc->offset]);
+ break;
+ }
+#define IOV_LIMIT 26
+ case Iovec: {
+ /*
+ * Print argument as an array of struct iovec, where the next
+ * syscall argument is the number of elements of the array.
+ */
+ struct iovec iov[IOV_LIMIT];
+ size_t max_string = trussinfo->strsize;
+ char tmp2[max_string + 1], *tmp3;
+ size_t len;
+ int i, iovcnt;
+ bool buf_truncated, iov_truncated;
+
+ iovcnt = args[sc->offset + 1];
+ if (iovcnt <= 0) {
+ fprintf(fp, "0x%lx", args[sc->offset]);
+ break;
+ }
+ if (iovcnt > IOV_LIMIT) {
+ iovcnt = IOV_LIMIT;
+ iov_truncated = true;
+ } else {
+ iov_truncated = false;
+ }
+ if (get_struct(pid, (void *)args[sc->offset],
+ &iov, iovcnt * sizeof(struct iovec)) == -1) {
+ fprintf(fp, "0x%lx", args[sc->offset]);
+ break;
+ }
+
+ fprintf(fp, "%s", "[");
+ for (i = 0; i < iovcnt; i++) {
+ len = iov[i].iov_len;
+ if (len > max_string) {
+ len = max_string;
+ buf_truncated = true;
+ } else {
+ buf_truncated = false;
+ }
+ fprintf(fp, "%s{", (i > 0) ? "," : "");
+ if (len && get_struct(pid, iov[i].iov_base, &tmp2, len)
+ != -1) {
+ tmp3 = malloc(len * 4 + 1);
+ while (len) {
+ if (strvisx(tmp3, tmp2, len,
+ VIS_CSTYLE|VIS_TAB|VIS_NL) <=
+ (int)max_string)
+ break;
+ len--;
+ buf_truncated = true;
+ }
+ fprintf(fp, "\"%s\"%s", tmp3,
+ buf_truncated ? "..." : "");
+ free(tmp3);
+ } else {
+ fprintf(fp, "0x%p", iov[i].iov_base);
+ }
+ fprintf(fp, ",%zu}", iov[i].iov_len);
+ }
+ fprintf(fp, "%s%s", iov_truncated ? ",..." : "", "]");
break;
}
More information about the svn-src-stable-11
mailing list