Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Dec 2015 00:05:07 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r292236 - in head: contrib/mdocml lib lib/libc/sys lib/libsysdecode share/mk usr.bin/kdump usr.bin/truss
Message-ID:  <201512150005.tBF057l2097434@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Dec 15 00:05:07 2015
New Revision: 292236
URL: https://svnweb.freebsd.org/changeset/base/292236

Log:
  Start on a new library (libsysdecode) that provides routines for decoding
  system call information such as system call arguments.  Initially this
  will consist of pulling duplicated code out of truss and kdump though it
  may prove useful for other utilities in the future.
  
  This commit moves the shared utrace(2) record parser out of kdump into
  the library and updates kdump and truss to use it.  One difference from
  the previous version is that the library version treats unknown events
  that start with the "RTLD" signature as unknown events.  This simplifies
  the interface and allows the consumer to decide how to handle all
  non-recognized events.  Instead, this function only generates a string
  description for known malloc() and RTLD records.
  
  Reviewed by:	bdrewery
  Differential Revision:	https://reviews.freebsd.org/D4537

Added:
  head/lib/libsysdecode/
  head/lib/libsysdecode/Makefile   (contents, props changed)
  head/lib/libsysdecode/sysdecode.3   (contents, props changed)
  head/lib/libsysdecode/sysdecode.h   (contents, props changed)
  head/lib/libsysdecode/sysdecode_utrace.3   (contents, props changed)
  head/lib/libsysdecode/utrace.c
     - copied, changed from r292235, head/usr.bin/kdump/utrace.c
Deleted:
  head/usr.bin/kdump/utrace.c
Modified:
  head/contrib/mdocml/lib.in
  head/lib/Makefile
  head/lib/libc/sys/utrace.2
  head/share/mk/bsd.libnames.mk
  head/share/mk/src.libnames.mk
  head/usr.bin/kdump/Makefile
  head/usr.bin/kdump/Makefile.depend
  head/usr.bin/kdump/kdump.c
  head/usr.bin/truss/Makefile
  head/usr.bin/truss/Makefile.depend.amd64
  head/usr.bin/truss/syscalls.c

Modified: head/contrib/mdocml/lib.in
==============================================================================
--- head/contrib/mdocml/lib.in	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/contrib/mdocml/lib.in	Tue Dec 15 00:05:07 2015	(r292236)
@@ -110,6 +110,7 @@ LINE("libsdp",		"Bluetooth Service Disco
 LINE("libssp",		"Buffer Overflow Protection Library (libssp, \\-lssp)")
 LINE("libstdthreads",	"C11 Threads Library (libstdthreads, \\-lstdthreads)")
 LINE("libSystem",	"System Library (libSystem, \\-lSystem)")
+LINE("libsysdcode",	"System Argument Decoding Library (libsysdecode, \\-lsysdecode)")
 LINE("libtacplus",	"TACACS+ Client Library (libtacplus, \\-ltacplus)")
 LINE("libtcplay",	"TrueCrypt-compatible API library (libtcplay, \\-ltcplay)")
 LINE("libtermcap",	"Termcap Access Library (libtermcap, \\-ltermcap)")

Modified: head/lib/Makefile
==============================================================================
--- head/lib/Makefile	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/lib/Makefile	Tue Dec 15 00:05:07 2015	(r292236)
@@ -98,6 +98,7 @@ SUBDIR=	${SUBDIR_ORDERED} \
 	libstand \
 	libstdbuf \
 	libstdthreads \
+	libsysdecode \
 	libtacplus \
 	${_libtelnet} \
 	${_libthr} \

Modified: head/lib/libc/sys/utrace.2
==============================================================================
--- head/lib/libc/sys/utrace.2	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/lib/libc/sys/utrace.2	Tue Dec 15 00:05:07 2015	(r292236)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd October 5, 2015
+.Dd December 11, 2015
 .Dt UTRACE 2
 .Os
 .Sh NAME
@@ -71,7 +71,8 @@ support
 .Xr kdump 1 ,
 .Xr ktrace 1 ,
 .Xr ktrace 2 ,
-.Xr truss 1
+.Xr truss 1 ,
+.Xr sysdecode_utrace 3
 .Sh HISTORY
 The
 .Fn utrace

Added: head/lib/libsysdecode/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libsysdecode/Makefile	Tue Dec 15 00:05:07 2015	(r292236)
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+.include <src.opts.mk>
+
+LIB=	sysdecode
+
+SRCS=	utrace.c
+INCS=	sysdecode.h
+
+MAN+=	sysdecode.3 \
+	sysdecode_utrace.3
+
+.include <bsd.lib.mk>

Added: head/lib/libsysdecode/sysdecode.3
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libsysdecode/sysdecode.3	Tue Dec 15 00:05:07 2015	(r292236)
@@ -0,0 +1,47 @@
+.\"
+.\" Copyright (c) 2015 John Baldwin <jhb@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 10, 2015
+.Dt SYSDECODE 3
+.Os
+.Sh NAME
+.Nm sysdecode
+.Nd system argument decoding library
+.Sh LIBRARY
+.Lb libsysdecode
+.Sh DESCRIPTION
+The
+.Nm
+library includes several functions that provide descriptive names of
+values associated with system calls.
+.Sh SEE ALSO
+.Xr sysdecode_utrace 3
+.Sh HISTORY
+The
+.Nm
+library first appeared in
+.Fx 11.0 .

Added: head/lib/libsysdecode/sysdecode.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libsysdecode/sysdecode.h	Tue Dec 15 00:05:07 2015	(r292236)
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef __SYSDECODE_H__
+#define	__SYSDECODE_H__
+
+int	sysdecode_utrace(FILE *_fp, void *_buf, size_t _len);
+
+#endif /* !__SYSDECODE_H__ */

Added: head/lib/libsysdecode/sysdecode_utrace.3
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/lib/libsysdecode/sysdecode_utrace.3	Tue Dec 15 00:05:07 2015	(r292236)
@@ -0,0 +1,73 @@
+.\"
+.\" Copyright (c) 2015 John Baldwin <jhb@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd December 11, 2015
+.Dt sysdecode_utrace 3
+.Os
+.Sh NAME
+.Nm sysdecode_utrace
+.Nd produce text description of a utrace record
+.Sh LIBRARY
+.Lb libsysdecode
+.Sh SYNOPSIS
+.Ft int
+.Fn sysdecode_utrace "FILE *fp" "void *buf" "size_t len" "int decimal"
+.Sh DESCRIPTION
+The
+.Fn sysdecode_utrace
+function outputs a textual representation of a
+.Xr utrace 2
+record identified by
+.Fa buf
+and
+.Fa len
+to the output stream
+.Fa fp .
+.Pp
+The function only outputs a representation for certain types of records.
+If a record is recognized,
+the function outputs the description and returns a non-zero value.
+If the record is not recognized,
+the function does not output anything and returns zero.
+The
+.Fn sysdecode_utrace
+function currently recognizes
+.Xr utrace 2
+records generated by
+.Xr malloc 3
+and
+.Xr rtld 1 .
+.Sh RETURN VALUES
+The
+.Fn sysdecode_utrace
+function returns a non-zero value if it recognizes a
+.Xr utrace 2
+record;
+otherwise it returns zero.
+.Sh SEE ALSO
+.Xr utrace 2 ,
+.Xr sysdecode 3

Copied and modified: head/lib/libsysdecode/utrace.c (from r292235, head/usr.bin/kdump/utrace.c)
==============================================================================
--- head/usr.bin/kdump/utrace.c	Mon Dec 14 23:25:31 2015	(r292235, copy source)
+++ head/lib/libsysdecode/utrace.c	Tue Dec 15 00:05:07 2015	(r292236)
@@ -34,8 +34,7 @@ __FBSDID("$FreeBSD$");
 #include <dlfcn.h>
 #include <stdio.h>
 #include <strings.h>
-
-int kdump_print_utrace(FILE *, void *, size_t, int);
+#include <sysdecode.h>
 
 #define	UTRACE_DLOPEN_START		1
 #define	UTRACE_DLOPEN_STOP		2
@@ -60,11 +59,10 @@ struct utrace_rtld {
 	char name[MAXPATHLEN];
 };
 
-static void
-print_utrace_rtld(FILE *fp, void *p, size_t len, int decimal)
+static int
+print_utrace_rtld(FILE *fp, void *p)
 {
 	struct utrace_rtld *ut = p;
-	unsigned char *cp;
 	void *parent;
 	int mode;
 
@@ -136,16 +134,9 @@ print_utrace_rtld(FILE *fp, void *p, siz
 		    ut->name);
 		break;
 	default:
-		cp = p;
-		cp += 4;
-		len -= 4;
-		fprintf(fp, "RTLD: %zu ", len);
-		while (len--)
-			if (decimal)
-				fprintf(fp, " %d", *cp++);
-			else
-				fprintf(fp, " %02x", *cp++);
+		return (0);
 	}
+	return (1);
 }
 
 struct utrace_malloc {
@@ -170,12 +161,11 @@ print_utrace_malloc(FILE *fp, void *p)
 }
 
 int
-kdump_print_utrace(FILE *fp, void *p, size_t len, int decimal)
+sysdecode_utrace(FILE *fp, void *p, size_t len)
 {
 
-	if (len >= 8 && bcmp(p, "RTLD", 4) == 0) {
-		print_utrace_rtld(fp, p, len, decimal);
-		return (1);
+	if (len == sizeof(struct utrace_rtld) && bcmp(p, "RTLD", 4) == 0) {
+		return (print_utrace_rtld(fp, p));
 	}
 
 	if (len == sizeof(struct utrace_malloc)) {

Modified: head/share/mk/bsd.libnames.mk
==============================================================================
--- head/share/mk/bsd.libnames.mk	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/share/mk/bsd.libnames.mk	Tue Dec 15 00:05:07 2015	(r292236)
@@ -134,6 +134,7 @@ LIBSSP_NONSHARED?=	${DESTDIR}${LIBDIR}/l
 LIBSTAND?=	${DESTDIR}${LIBDIR}/libstand.a
 LIBSTDCPLUSPLUS?= ${DESTDIR}${LIBDIR}/libstdc++.a
 LIBSTDTHREADS?=	${DESTDIR}${LIBDIR}/libstdthreads.a
+LIBSYSDECODE?=	${DESTDIR}${LIBDIR}/libsysdecode.a
 LIBTACPLUS?=	${DESTDIR}${LIBDIR}/libtacplus.a
 LIBTERMCAP?=	${DESTDIR}${LIBDIR}/libtermcap.a
 LIBTERMCAPW?=	${DESTDIR}${LIBDIR}/libtermcapw.a

Modified: head/share/mk/src.libnames.mk
==============================================================================
--- head/share/mk/src.libnames.mk	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/share/mk/src.libnames.mk	Tue Dec 15 00:05:07 2015	(r292236)
@@ -148,6 +148,7 @@ _LIBRARIES=	\
 		ssp_nonshared \
 		stdthreads \
 		supcplusplus \
+		sysdecode \
 		tacplus \
 		termcap \
 		termcapw \

Modified: head/usr.bin/kdump/Makefile
==============================================================================
--- head/usr.bin/kdump/Makefile	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/usr.bin/kdump/Makefile	Tue Dec 15 00:05:07 2015	(r292236)
@@ -6,11 +6,12 @@
 .PATH: ${.CURDIR}/../ktrace
 
 PROG=		kdump
-SRCS=		kdump_subr.c kdump_subr.h kdump.c ioctl.c subr.c utrace.c
+SRCS=		kdump_subr.c kdump_subr.h kdump.c ioctl.c subr.c
 CFLAGS+=	-I${.CURDIR}/../ktrace -I${.CURDIR} -I${.CURDIR}/../.. -I.
 
+LIBADD=		sysdecode
 .if ${MK_CASPER} != "no"
-LIBADD=	capsicum
+LIBADD+=	capsicum
 CFLAGS+=-DHAVE_LIBCAPSICUM
 .endif
 

Modified: head/usr.bin/kdump/Makefile.depend
==============================================================================
--- head/usr.bin/kdump/Makefile.depend	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/usr.bin/kdump/Makefile.depend	Tue Dec 15 00:05:07 2015	(r292236)
@@ -13,6 +13,7 @@ DIRDEPS = \
 	lib/libcapsicum \
 	lib/libcompiler_rt \
 	lib/libnv \
+	lib/libsysdecode \
 
 
 .include <dirdeps.mk>

Modified: head/usr.bin/kdump/kdump.c
==============================================================================
--- head/usr.bin/kdump/kdump.c	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/usr.bin/kdump/kdump.c	Tue Dec 15 00:05:07 2015	(r292236)
@@ -83,6 +83,7 @@ extern int errno;
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sysdecode.h>
 #include <termios.h>
 #include <time.h>
 #include <unistd.h>
@@ -116,7 +117,6 @@ void ktrfaultend(struct ktr_faultend *);
 void limitfd(int fd);
 void usage(void);
 void ioctlname(unsigned long, int);
-int kdump_print_utrace(FILE *, void *, size_t, int);
 
 #define	TIMESTAMP_NONE		0x0
 #define	TIMESTAMP_ABSOLUTE	0x1
@@ -1541,7 +1541,7 @@ ktruser(int len, void *p)
 {
 	unsigned char *cp;
 
-	if (kdump_print_utrace(stdout, p, len, decimal)) {
+	if (sysdecode_utrace(stdout, p, len)) {
 		printf("\n");
 		return;
 	}

Modified: head/usr.bin/truss/Makefile
==============================================================================
--- head/usr.bin/truss/Makefile	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/usr.bin/truss/Makefile	Tue Dec 15 00:05:07 2015	(r292236)
@@ -4,8 +4,7 @@ NO_WERROR=
 PROG=	truss
 SRCS=	cloudabi.c ioctl.c main.c setup.c syscalls.c
 
-.PATH:	${.CURDIR:H}/kdump
-SRCS+=	utrace.c
+LIBADD=	sysdecode
 
 CFLAGS+= -I${.CURDIR} -I. -I${.CURDIR}/../../sys
 CLEANFILES= ioctl.c

Modified: head/usr.bin/truss/Makefile.depend.amd64
==============================================================================
--- head/usr.bin/truss/Makefile.depend.amd64	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/usr.bin/truss/Makefile.depend.amd64	Tue Dec 15 00:05:07 2015	(r292236)
@@ -11,6 +11,7 @@ DIRDEPS = \
 	lib/${CSU_DIR} \
 	lib/libc \
 	lib/libcompiler_rt \
+	lib/libsysdecode \
 
 
 .include <dirdeps.mk>

Modified: head/usr.bin/truss/syscalls.c
==============================================================================
--- head/usr.bin/truss/syscalls.c	Mon Dec 14 23:25:31 2015	(r292235)
+++ head/usr.bin/truss/syscalls.c	Tue Dec 15 00:05:07 2015	(r292236)
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sysdecode.h>
 #include <time.h>
 #include <unistd.h>
 #include <vis.h>
@@ -75,9 +76,6 @@ __FBSDID("$FreeBSD$");
 #include "extern.h"
 #include "syscall.h"
 
-/* usr.bin/kdump/utrace.c */
-int kdump_print_utrace(FILE *, void *, size_t, int);
-
 /* 64-bit alignment on 32-bit platforms. */
 #if !defined(__LP64__) && defined(__powerpc__)
 #define	QUAD_ALIGN	1
@@ -1108,7 +1106,7 @@ print_utrace(FILE *fp, void *utrace_addr
 	unsigned char *utrace_buffer;
 
 	fprintf(fp, "{ ");
-	if (kdump_print_utrace(fp, utrace_addr, len, 0)) {
+	if (sysdecode_utrace(fp, utrace_addr, len)) {
 		fprintf(fp, " }");
 		return;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201512150005.tBF057l2097434>