From owner-svn-src-all@freebsd.org Thu Aug 20 14:51:15 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BFFC79BF83E; Thu, 20 Aug 2015 14:51:15 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A48371A22; Thu, 20 Aug 2015 14:51:15 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7KEpFWF084357; Thu, 20 Aug 2015 14:51:15 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7KEpCUl084342; Thu, 20 Aug 2015 14:51:12 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201508201451.t7KEpCUl084342@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 20 Aug 2015 14:51:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286963 - head/usr.bin/truss X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Aug 2015 14:51:15 -0000 Author: jhb Date: Thu Aug 20 14:51:11 2015 New Revision: 286963 URL: https://svnweb.freebsd.org/changeset/base/286963 Log: Handle the conditional decoding of execve() argument and environment arrays generically rather than duplicating a hack in all of the backends. - Add two new system call argument types and use them instead of StringArray for the argument and environment arguments execve and linux_execve. - Honor the -a/-e flags in the handling of these new types. - Instead of printing "" when the decoding is disabled, print the raw pointer value. Modified: head/usr.bin/truss/amd64-fbsd.c head/usr.bin/truss/amd64-fbsd32.c head/usr.bin/truss/amd64-linux32.c head/usr.bin/truss/arm-fbsd.c head/usr.bin/truss/i386-fbsd.c head/usr.bin/truss/i386-linux.c head/usr.bin/truss/mips-fbsd.c head/usr.bin/truss/powerpc-fbsd.c head/usr.bin/truss/powerpc64-fbsd.c head/usr.bin/truss/sparc64-fbsd.c head/usr.bin/truss/syscall.h head/usr.bin/truss/syscalls.c Modified: head/usr.bin/truss/amd64-fbsd.c ============================================================================== --- head/usr.bin/truss/amd64-fbsd.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/amd64-fbsd.c Thu Aug 20 14:51:11 2015 (r286963) @@ -233,28 +233,6 @@ amd64_syscall_entry(struct trussinfo *tr fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/amd64-fbsd32.c ============================================================================== --- head/usr.bin/truss/amd64-fbsd32.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/amd64-fbsd32.c Thu Aug 20 14:51:11 2015 (r286963) @@ -233,28 +233,6 @@ amd64_fbsd32_syscall_entry(struct trussi fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "freebsd32_execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "freebsd32_execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/amd64-linux32.c ============================================================================== --- head/usr.bin/truss/amd64-linux32.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/amd64-linux32.c Thu Aug 20 14:51:11 2015 (r286963) @@ -206,28 +206,6 @@ amd64_linux32_syscall_entry(struct truss fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "linux_execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/arm-fbsd.c ============================================================================== --- head/usr.bin/truss/arm-fbsd.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/arm-fbsd.c Thu Aug 20 14:51:11 2015 (r286963) @@ -264,28 +264,6 @@ arm_syscall_entry(struct trussinfo *trus fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/i386-fbsd.c ============================================================================== --- head/usr.bin/truss/i386-fbsd.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/i386-fbsd.c Thu Aug 20 14:51:11 2015 (r286963) @@ -227,28 +227,6 @@ i386_syscall_entry(struct trussinfo *tru fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/i386-linux.c ============================================================================== --- head/usr.bin/truss/i386-linux.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/i386-linux.c Thu Aug 20 14:51:11 2015 (r286963) @@ -206,28 +206,6 @@ i386_linux_syscall_entry(struct trussinf fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "linux_execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/mips-fbsd.c ============================================================================== --- head/usr.bin/truss/mips-fbsd.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/mips-fbsd.c Thu Aug 20 14:51:11 2015 (r286963) @@ -261,28 +261,6 @@ mips_syscall_entry(struct trussinfo *tru fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/powerpc-fbsd.c ============================================================================== --- head/usr.bin/truss/powerpc-fbsd.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/powerpc-fbsd.c Thu Aug 20 14:51:11 2015 (r286963) @@ -238,28 +238,6 @@ powerpc_syscall_entry(struct trussinfo * fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/powerpc64-fbsd.c ============================================================================== --- head/usr.bin/truss/powerpc64-fbsd.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/powerpc64-fbsd.c Thu Aug 20 14:51:11 2015 (r286963) @@ -226,28 +226,6 @@ powerpc64_syscall_entry(struct trussinfo fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name && (strcmp(fsc->name, "execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/sparc64-fbsd.c ============================================================================== --- head/usr.bin/truss/sparc64-fbsd.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/sparc64-fbsd.c Thu Aug 20 14:51:11 2015 (r286963) @@ -255,28 +255,6 @@ sparc64_syscall_entry(struct trussinfo * fprintf(trussinfo->outfile, "\n"); #endif - if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 || - strcmp(fsc->name, "exit") == 0)) { - /* - * XXX - * This could be done in a more general - * manner but it still wouldn't be very pretty. - */ - if (strcmp(fsc->name, "execve") == 0) { - if ((trussinfo->flags & EXECVEARGS) == 0) { - if (fsc->s_args[1]) { - free(fsc->s_args[1]); - fsc->s_args[1] = NULL; - } - } - if ((trussinfo->flags & EXECVEENVS) == 0) { - if (fsc->s_args[2]) { - free(fsc->s_args[2]); - fsc->s_args[2] = NULL; - } - } - } - } trussinfo->curthread->fsc = fsc; } Modified: head/usr.bin/truss/syscall.h ============================================================================== --- head/usr.bin/truss/syscall.h Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/syscall.h Thu Aug 20 14:51:11 2015 (r286963) @@ -42,7 +42,7 @@ enum Argtype { None = 1, Hex, Octal, Int Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2, Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl, LinuxSockArgs, Umtxop, Atfd, Atflags, Timespec2, Accessmode, Long, - Sysarch }; + Sysarch, ExecArgs, ExecEnv }; #define ARG_MASK 0xff #define OUT 0x100 Modified: head/usr.bin/truss/syscalls.c ============================================================================== --- head/usr.bin/truss/syscalls.c Thu Aug 20 14:33:30 2015 (r286962) +++ head/usr.bin/truss/syscalls.c Thu Aug 20 14:51:11 2015 (r286963) @@ -245,11 +245,11 @@ static struct syscall syscalls[] = { .args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 }, { Hex, 3 }, { Sockaddr | IN, 4 }, { Ptr | IN, 5 } } }, { .name = "execve", .ret_type = 1, .nargs = 3, - .args = { { Name | IN, 0 }, { StringArray | IN, 1 }, - { StringArray | IN, 2 } } }, + .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 }, + { ExecEnv | IN, 2 } } }, { .name = "linux_execve", .ret_type = 1, .nargs = 3, - .args = { { Name | IN, 0 }, { StringArray | IN, 1 }, - { StringArray | IN, 2 } } }, + .args = { { Name | IN, 0 }, { ExecArgs | IN, 1 }, + { ExecEnv | IN, 2 } } }, { .name = "kldload", .ret_type = 0, .nargs = 1, .args = { { Name | IN, 0 } } }, { .name = "kldunload", .ret_type = 0, .nargs = 1, @@ -912,6 +912,8 @@ print_arg(struct syscall_args *sc, unsig } break; } + case ExecArgs: + case ExecEnv: case StringArray: { uintptr_t addr; union { @@ -923,6 +925,18 @@ print_arg(struct syscall_args *sc, unsig int first, i; /* + * Only parse argv[] and environment arrays from exec calls + * if requested. + */ + if (((sc->type & ARG_MASK) == ExecArgs && + (trussinfo->flags & EXECVEARGS) == 0) || + ((sc->type & ARG_MASK) == ExecEnv && + (trussinfo->flags & EXECVEENVS) == 0)) { + fprintf(fp, "0x%lx", args[sc->offset]); + break; + } + + /* * Read a page of pointers at a time. Punt if the top-level * pointer is not aligned. Note that the first read is of * a partial page.