svn commit: r327919 - head/usr.bin/truss

Michael Tuexen tuexen at FreeBSD.org
Sat Jan 13 13:59:36 UTC 2018


Author: tuexen
Date: Sat Jan 13 13:59:35 2018
New Revision: 327919
URL: https://svnweb.freebsd.org/changeset/base/327919

Log:
  Add support for readv() and writev() to truss.
  
  Sponsored by:	Netflix, Inc.

Modified:
  head/usr.bin/truss/syscall.h
  head/usr.bin/truss/syscalls.c

Modified: head/usr.bin/truss/syscall.h
==============================================================================
--- head/usr.bin/truss/syscall.h	Sat Jan 13 13:53:05 2018	(r327918)
+++ head/usr.bin/truss/syscall.h	Sat Jan 13 13:59:35 2018	(r327919)
@@ -82,7 +82,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: head/usr.bin/truss/syscalls.c
==============================================================================
--- head/usr.bin/truss/syscalls.c	Sat Jan 13 13:53:05 2018	(r327918)
+++ head/usr.bin/truss/syscalls.c	Sat Jan 13 13:59:35 2018	(r327919)
@@ -386,6 +386,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,
@@ -520,6 +522,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,
@@ -2137,6 +2141,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-all mailing list