xref: /illumos-gate/usr/src/cmd/truss/actions.c (revision c4d3e299)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5657b1f3dSraf  * Common Development and Distribution License (the "License").
6657b1f3dSraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21657b1f3dSraf 
227c478bd9Sstevel@tonic-gate /*
23134a1f4eSCasper H.S. Dik  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <stdlib.h>
317c478bd9Sstevel@tonic-gate #include <unistd.h>
327c478bd9Sstevel@tonic-gate #include <ctype.h>
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate #include <memory.h>
357c478bd9Sstevel@tonic-gate #include <errno.h>
367c478bd9Sstevel@tonic-gate #include <limits.h>
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <sys/stack.h>
397c478bd9Sstevel@tonic-gate #include <signal.h>
407c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
417c478bd9Sstevel@tonic-gate #include <libproc.h>
427c478bd9Sstevel@tonic-gate #include <priv.h>
437c478bd9Sstevel@tonic-gate #include "ramdata.h"
447c478bd9Sstevel@tonic-gate #include "systable.h"
457c478bd9Sstevel@tonic-gate #include "print.h"
467c478bd9Sstevel@tonic-gate #include "proto.h"
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Actions to take when process stops.
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Function prototypes for static routines in this module.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate int	stopsig(private_t *);
567c478bd9Sstevel@tonic-gate void	showpaths(private_t *, const struct systable *);
577c478bd9Sstevel@tonic-gate void	showargs(private_t *, int);
587c478bd9Sstevel@tonic-gate void	dumpargs(private_t *, long, const char *);
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * Report an lwp to be sleeping (if true).
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate void
report_sleeping(private_t * pri,int dotrace)647c478bd9Sstevel@tonic-gate report_sleeping(private_t *pri, int dotrace)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
677c478bd9Sstevel@tonic-gate 	int sys = Lsp->pr_syscall;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	if (!prismember(&trace, sys) || !dotrace ||
707c478bd9Sstevel@tonic-gate 	    !(Lsp->pr_flags & (PR_ASLEEP|PR_VFORKP))) {
717c478bd9Sstevel@tonic-gate 		/* Make sure we catch sysexit even if we're not tracing it. */
727c478bd9Sstevel@tonic-gate 		(void) Psysexit(Proc, sys, TRUE);
737c478bd9Sstevel@tonic-gate 		return;
747c478bd9Sstevel@tonic-gate 	}
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	pri->length = 0;
777c478bd9Sstevel@tonic-gate 	pri->Errno = 0;
787c478bd9Sstevel@tonic-gate 	pri->ErrPriv = PRIV_NONE;
797c478bd9Sstevel@tonic-gate 	pri->Rval1 = pri->Rval2 = 0;
807c478bd9Sstevel@tonic-gate 	(void) sysentry(pri, dotrace);
817c478bd9Sstevel@tonic-gate 	make_pname(pri, 0);
827c478bd9Sstevel@tonic-gate 	putpname(pri);
837c478bd9Sstevel@tonic-gate 	timestamp(pri);
847c478bd9Sstevel@tonic-gate 	pri->length += printf("%s", pri->sys_string);
857c478bd9Sstevel@tonic-gate 	pri->sys_leng = 0;
867c478bd9Sstevel@tonic-gate 	*pri->sys_string = '\0';
877c478bd9Sstevel@tonic-gate 	pri->length >>= 3;
887c478bd9Sstevel@tonic-gate 	if (Lsp->pr_flags & PR_VFORKP)
897c478bd9Sstevel@tonic-gate 		pri->length += 2;
907c478bd9Sstevel@tonic-gate 	if (pri->length >= 4)
917c478bd9Sstevel@tonic-gate 		(void) fputc(' ', stdout);
927c478bd9Sstevel@tonic-gate 	for (; pri->length < 4; pri->length++)
937c478bd9Sstevel@tonic-gate 		(void) fputc('\t', stdout);
947c478bd9Sstevel@tonic-gate 	if (Lsp->pr_flags & PR_VFORKP)
957c478bd9Sstevel@tonic-gate 		(void) fputs("(waiting for child to exit()/exec()...)\n",
965403172aSRoger A. Faulkner 		    stdout);
977c478bd9Sstevel@tonic-gate 	else
987c478bd9Sstevel@tonic-gate 		(void) fputs("(sleeping...)\n", stdout);
997c478bd9Sstevel@tonic-gate 	pri->length = 0;
1007c478bd9Sstevel@tonic-gate 	if (prismember(&verbose, sys)) {
1017c478bd9Sstevel@tonic-gate 		int raw = prismember(&rawout, sys);
1027c478bd9Sstevel@tonic-gate 		pri->Errno = 1;
1037c478bd9Sstevel@tonic-gate 		expound(pri, 0, raw);
1047c478bd9Sstevel@tonic-gate 		pri->Errno = 0;
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 	Flush();
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * requested() gets called for these reasons:
1117c478bd9Sstevel@tonic-gate  *	flag == JOBSIG:		report nothing; change state to JOBSTOP
1127c478bd9Sstevel@tonic-gate  *	flag == JOBSTOP:	report "Continued ..."
1137c478bd9Sstevel@tonic-gate  *	default:		report sleeping system call
1147c478bd9Sstevel@tonic-gate  *
1157c478bd9Sstevel@tonic-gate  * It returns a new flag:  JOBSTOP or SLEEPING or 0.
1167c478bd9Sstevel@tonic-gate  */
1177c478bd9Sstevel@tonic-gate int
requested(private_t * pri,int flag,int dotrace)1187c478bd9Sstevel@tonic-gate requested(private_t *pri, int flag, int dotrace)
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
1217c478bd9Sstevel@tonic-gate 	int sig = Lsp->pr_cursig;
1227c478bd9Sstevel@tonic-gate 	int newflag = 0;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	switch (flag) {
1257c478bd9Sstevel@tonic-gate 	case JOBSIG:
1267c478bd9Sstevel@tonic-gate 		return (JOBSTOP);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	case JOBSTOP:
1297c478bd9Sstevel@tonic-gate 		if (dotrace && !cflag && prismember(&signals, sig)) {
1307c478bd9Sstevel@tonic-gate 			pri->length = 0;
1317c478bd9Sstevel@tonic-gate 			putpname(pri);
1327c478bd9Sstevel@tonic-gate 			timestamp(pri);
1337c478bd9Sstevel@tonic-gate 			(void) printf("    Continued with signal #%d, %s",
1345403172aSRoger A. Faulkner 			    sig, signame(pri, sig));
1357c478bd9Sstevel@tonic-gate 			if (Lsp->pr_action.sa_handler == SIG_DFL)
1367c478bd9Sstevel@tonic-gate 				(void) printf(" [default]");
1377c478bd9Sstevel@tonic-gate 			else if (Lsp->pr_action.sa_handler == SIG_IGN)
1387c478bd9Sstevel@tonic-gate 				(void) printf(" [ignored]");
1397c478bd9Sstevel@tonic-gate 			else
1407c478bd9Sstevel@tonic-gate 				(void) printf(" [caught]");
1417c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stdout);
1427c478bd9Sstevel@tonic-gate 			Flush();
1437c478bd9Sstevel@tonic-gate 		}
1447c478bd9Sstevel@tonic-gate 		newflag = 0;
1457c478bd9Sstevel@tonic-gate 		break;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	default:
1487c478bd9Sstevel@tonic-gate 		newflag = SLEEPING;
1497c478bd9Sstevel@tonic-gate 		if (!cflag)
1507c478bd9Sstevel@tonic-gate 			report_sleeping(pri, dotrace);
1517c478bd9Sstevel@tonic-gate 		break;
1527c478bd9Sstevel@tonic-gate 	}
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	return (newflag);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate int
jobcontrol(private_t * pri,int dotrace)1587c478bd9Sstevel@tonic-gate jobcontrol(private_t *pri, int dotrace)
1597c478bd9Sstevel@tonic-gate {
1607c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
1617c478bd9Sstevel@tonic-gate 	int sig = stopsig(pri);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	if (sig == 0)
1647c478bd9Sstevel@tonic-gate 		return (0);
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	if (dotrace && !cflag &&		/* not just counting */
1677c478bd9Sstevel@tonic-gate 	    prismember(&signals, sig)) {	/* tracing this signal */
1687c478bd9Sstevel@tonic-gate 		int sys;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 		pri->length = 0;
1717c478bd9Sstevel@tonic-gate 		putpname(pri);
1727c478bd9Sstevel@tonic-gate 		timestamp(pri);
1737c478bd9Sstevel@tonic-gate 		(void) printf("    Stopped by signal #%d, %s",
1745403172aSRoger A. Faulkner 		    sig, signame(pri, sig));
1757c478bd9Sstevel@tonic-gate 		if ((Lsp->pr_flags & PR_ASLEEP) &&
1767c478bd9Sstevel@tonic-gate 		    (sys = Lsp->pr_syscall) > 0 && sys <= PRMAXSYS)
1777c478bd9Sstevel@tonic-gate 			(void) printf(", in %s()",
1785403172aSRoger A. Faulkner 			    sysname(pri, sys, getsubcode(pri)));
1797c478bd9Sstevel@tonic-gate 		(void) fputc('\n', stdout);
1807c478bd9Sstevel@tonic-gate 		Flush();
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	return (JOBSTOP);
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * Return the signal the process stopped on iff process is already stopped on
1887c478bd9Sstevel@tonic-gate  * PR_JOBCONTROL or is stopped on PR_SIGNALLED or PR_REQUESTED with a current
1897c478bd9Sstevel@tonic-gate  * signal that will cause a JOBCONTROL stop when the process is set running.
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate int
stopsig(private_t * pri)1927c478bd9Sstevel@tonic-gate stopsig(private_t *pri)
1937c478bd9Sstevel@tonic-gate {
1947c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
1957c478bd9Sstevel@tonic-gate 	int sig = 0;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	if (Lsp->pr_flags & PR_STOPPED) {
1987c478bd9Sstevel@tonic-gate 		switch (Lsp->pr_why) {
1997c478bd9Sstevel@tonic-gate 		case PR_JOBCONTROL:
2007c478bd9Sstevel@tonic-gate 			sig = Lsp->pr_what;
2017c478bd9Sstevel@tonic-gate 			if (sig < 0 || sig > PRMAXSIG)
2027c478bd9Sstevel@tonic-gate 				sig = 0;
2037c478bd9Sstevel@tonic-gate 			break;
2047c478bd9Sstevel@tonic-gate 		case PR_SIGNALLED:
2057c478bd9Sstevel@tonic-gate 		case PR_REQUESTED:
2067c478bd9Sstevel@tonic-gate 			if (Lsp->pr_action.sa_handler == SIG_DFL) {
2077c478bd9Sstevel@tonic-gate 				switch (Lsp->pr_cursig) {
2087c478bd9Sstevel@tonic-gate 				case SIGSTOP:
2097c478bd9Sstevel@tonic-gate 					sig = SIGSTOP;
2107c478bd9Sstevel@tonic-gate 					break;
2117c478bd9Sstevel@tonic-gate 				case SIGTSTP:
2127c478bd9Sstevel@tonic-gate 				case SIGTTIN:
2137c478bd9Sstevel@tonic-gate 				case SIGTTOU:
2147c478bd9Sstevel@tonic-gate 					if (!(Lsp->pr_flags & PR_ORPHAN))
2157c478bd9Sstevel@tonic-gate 						sig = Lsp->pr_cursig;
2167c478bd9Sstevel@tonic-gate 					break;
2177c478bd9Sstevel@tonic-gate 				}
2187c478bd9Sstevel@tonic-gate 			}
2197c478bd9Sstevel@tonic-gate 			break;
2207c478bd9Sstevel@tonic-gate 		}
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	return (sig);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate int
signalled(private_t * pri,int flag,int dotrace)2277c478bd9Sstevel@tonic-gate signalled(private_t *pri, int flag, int dotrace)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
2307c478bd9Sstevel@tonic-gate 	int sig = Lsp->pr_what;
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	if (sig <= 0 || sig > PRMAXSIG)	/* check bounds */
2337c478bd9Sstevel@tonic-gate 		return (0);
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	if (dotrace && cflag) {			/* just counting */
2367c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&count_lock);
2377c478bd9Sstevel@tonic-gate 		Cp->sigcount[sig]++;
2387c478bd9Sstevel@tonic-gate 		(void) mutex_unlock(&count_lock);
2397c478bd9Sstevel@tonic-gate 	}
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	if (sig == SIGCONT && (flag == JOBSIG || flag == JOBSTOP))
2427c478bd9Sstevel@tonic-gate 		flag = requested(pri, JOBSTOP, dotrace);
2437c478bd9Sstevel@tonic-gate 	else if ((flag = jobcontrol(pri, dotrace)) == 0 &&
2447c478bd9Sstevel@tonic-gate 	    !cflag && dotrace &&
2457c478bd9Sstevel@tonic-gate 	    prismember(&signals, sig)) {
2467c478bd9Sstevel@tonic-gate 		int sys;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 		pri->length = 0;
2497c478bd9Sstevel@tonic-gate 		putpname(pri);
2507c478bd9Sstevel@tonic-gate 		timestamp(pri);
2517c478bd9Sstevel@tonic-gate 		(void) printf("    Received signal #%d, %s",
2525403172aSRoger A. Faulkner 		    sig, signame(pri, sig));
2537c478bd9Sstevel@tonic-gate 		if ((Lsp->pr_flags & PR_ASLEEP) &&
2547c478bd9Sstevel@tonic-gate 		    (sys = Lsp->pr_syscall) > 0 && sys <= PRMAXSYS)
2557c478bd9Sstevel@tonic-gate 			(void) printf(", in %s()",
2565403172aSRoger A. Faulkner 			    sysname(pri, sys, getsubcode(pri)));
2577c478bd9Sstevel@tonic-gate 		if (Lsp->pr_action.sa_handler == SIG_DFL)
2587c478bd9Sstevel@tonic-gate 			(void) printf(" [default]");
2597c478bd9Sstevel@tonic-gate 		else if (Lsp->pr_action.sa_handler == SIG_IGN)
2607c478bd9Sstevel@tonic-gate 			(void) printf(" [ignored]");
2617c478bd9Sstevel@tonic-gate 		else
2627c478bd9Sstevel@tonic-gate 			(void) printf(" [caught]");
2637c478bd9Sstevel@tonic-gate 		(void) fputc('\n', stdout);
2647c478bd9Sstevel@tonic-gate 		if (Lsp->pr_info.si_code != 0 ||
2657c478bd9Sstevel@tonic-gate 		    Lsp->pr_info.si_pid != 0)
2667c478bd9Sstevel@tonic-gate 			print_siginfo(pri, &Lsp->pr_info);
2677c478bd9Sstevel@tonic-gate 		Flush();
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	if (flag == JOBSTOP)
2717c478bd9Sstevel@tonic-gate 		flag = JOBSIG;
2727c478bd9Sstevel@tonic-gate 	return (flag);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate int
faulted(private_t * pri,int dotrace)2767c478bd9Sstevel@tonic-gate faulted(private_t *pri, int dotrace)
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
2797c478bd9Sstevel@tonic-gate 	int flt = Lsp->pr_what;
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	if ((uint_t)flt > PRMAXFAULT || !prismember(&faults, flt) || !dotrace)
2827c478bd9Sstevel@tonic-gate 		return (0);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	(void) mutex_lock(&count_lock);
2857c478bd9Sstevel@tonic-gate 	Cp->fltcount[flt]++;
2867c478bd9Sstevel@tonic-gate 	(void) mutex_unlock(&count_lock);
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	if (cflag)		/* just counting */
2897c478bd9Sstevel@tonic-gate 		return (1);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	pri->length = 0;
2927c478bd9Sstevel@tonic-gate 	putpname(pri);
2937c478bd9Sstevel@tonic-gate 	timestamp(pri);
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	(void) printf("    Incurred fault #%d, %s  %%pc = 0x%.8lX",
2965403172aSRoger A. Faulkner 	    flt, proc_fltname(flt, pri->flt_name, sizeof (pri->flt_name)),
2975403172aSRoger A. Faulkner 	    (long)Lsp->pr_reg[R_PC]);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	if (flt == FLTPAGE)
3007c478bd9Sstevel@tonic-gate 		(void) printf("  addr = 0x%.8lX",
3015403172aSRoger A. Faulkner 		    (long)Lsp->pr_info.si_addr);
3027c478bd9Sstevel@tonic-gate 	(void) fputc('\n', stdout);
3037c478bd9Sstevel@tonic-gate 	if (Lsp->pr_info.si_signo != 0)
3047c478bd9Sstevel@tonic-gate 		print_siginfo(pri, &Lsp->pr_info);
3057c478bd9Sstevel@tonic-gate 	Flush();
3067c478bd9Sstevel@tonic-gate 	return (1);
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate /*
3107c478bd9Sstevel@tonic-gate  * Set up pri->sys_nargs and pri->sys_args[] (syscall args).
3117c478bd9Sstevel@tonic-gate  */
3127c478bd9Sstevel@tonic-gate void
setupsysargs(private_t * pri,int what)3137c478bd9Sstevel@tonic-gate setupsysargs(private_t *pri, int what)
3147c478bd9Sstevel@tonic-gate {
3157c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
3167c478bd9Sstevel@tonic-gate 	int nargs;
3177c478bd9Sstevel@tonic-gate 	int i;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate #if sparc
3207c478bd9Sstevel@tonic-gate 	/* determine whether syscall is indirect */
3217c478bd9Sstevel@tonic-gate 	pri->sys_indirect = (Lsp->pr_reg[R_G1] == SYS_syscall)? 1 : 0;
3227c478bd9Sstevel@tonic-gate #else
3237c478bd9Sstevel@tonic-gate 	pri->sys_indirect = 0;
3247c478bd9Sstevel@tonic-gate #endif
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	(void) memset(pri->sys_args, 0, sizeof (pri->sys_args));
3277c478bd9Sstevel@tonic-gate 	if (what != Lsp->pr_syscall) {	/* assertion */
3287c478bd9Sstevel@tonic-gate 		(void) printf("%s\t*** Inconsistent syscall: %d vs %d ***\n",
3295403172aSRoger A. Faulkner 		    pri->pname, what, Lsp->pr_syscall);
3307c478bd9Sstevel@tonic-gate 	}
3317c478bd9Sstevel@tonic-gate 	nargs = Lsp->pr_nsysarg;
3327c478bd9Sstevel@tonic-gate 	for (i = 0;
3337c478bd9Sstevel@tonic-gate 	    i < nargs && i < sizeof (pri->sys_args) / sizeof (pri->sys_args[0]);
3347c478bd9Sstevel@tonic-gate 	    i++)
3357c478bd9Sstevel@tonic-gate 		pri->sys_args[i] = Lsp->pr_sysarg[i];
3367c478bd9Sstevel@tonic-gate 	pri->sys_nargs = nargs;
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate #define	ISREAD(code) \
3407c478bd9Sstevel@tonic-gate 	((code) == SYS_read || (code) == SYS_pread || \
3417c478bd9Sstevel@tonic-gate 	(code) == SYS_pread64 || (code) == SYS_readv || \
3427c478bd9Sstevel@tonic-gate 	(code) == SYS_recv || (code) == SYS_recvfrom)
3437c478bd9Sstevel@tonic-gate #define	ISWRITE(code) \
3447c478bd9Sstevel@tonic-gate 	((code) == SYS_write || (code) == SYS_pwrite || \
3457c478bd9Sstevel@tonic-gate 	(code) == SYS_pwrite64 || (code) == SYS_writev || \
3467c478bd9Sstevel@tonic-gate 	(code) == SYS_send || (code) == SYS_sendto)
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate /*
3497c478bd9Sstevel@tonic-gate  * Return TRUE iff syscall is being traced.
3507c478bd9Sstevel@tonic-gate  */
3517c478bd9Sstevel@tonic-gate int
sysentry(private_t * pri,int dotrace)3527c478bd9Sstevel@tonic-gate sysentry(private_t *pri, int dotrace)
3537c478bd9Sstevel@tonic-gate {
3547c478bd9Sstevel@tonic-gate 	pid_t pid = Pstatus(Proc)->pr_pid;
3557c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
3567c478bd9Sstevel@tonic-gate 	long arg;
3577c478bd9Sstevel@tonic-gate 	int nargs;
3587c478bd9Sstevel@tonic-gate 	int i;
3597c478bd9Sstevel@tonic-gate 	int x;
3607c478bd9Sstevel@tonic-gate 	int len;
3617c478bd9Sstevel@tonic-gate 	char *s;
3627c478bd9Sstevel@tonic-gate 	const struct systable *stp;
3637c478bd9Sstevel@tonic-gate 	int what = Lsp->pr_what;
3647c478bd9Sstevel@tonic-gate 	int subcode;
3657c478bd9Sstevel@tonic-gate 	int istraced;
3667c478bd9Sstevel@tonic-gate 	int raw;
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	/* for reporting sleeping system calls */
3697c478bd9Sstevel@tonic-gate 	if (what == 0 && (Lsp->pr_flags & (PR_ASLEEP|PR_VFORKP)))
3707c478bd9Sstevel@tonic-gate 		what = Lsp->pr_syscall;
3717c478bd9Sstevel@tonic-gate 
3727c478bd9Sstevel@tonic-gate 	/* protect ourself from operating system error */
3737c478bd9Sstevel@tonic-gate 	if (what <= 0 || what > PRMAXSYS)
3747c478bd9Sstevel@tonic-gate 		what = 0;
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	/*
3777c478bd9Sstevel@tonic-gate 	 * Set up the system call arguments (pri->sys_nargs & pri->sys_args[]).
3787c478bd9Sstevel@tonic-gate 	 */
3797c478bd9Sstevel@tonic-gate 	setupsysargs(pri, what);
3807c478bd9Sstevel@tonic-gate 	nargs = pri->sys_nargs;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	/* get systable entry for this syscall */
3837c478bd9Sstevel@tonic-gate 	subcode = getsubcode(pri);
3847c478bd9Sstevel@tonic-gate 	stp = subsys(what, subcode);
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	if (nargs > stp->nargs)
3877c478bd9Sstevel@tonic-gate 		nargs = stp->nargs;
3887c478bd9Sstevel@tonic-gate 	pri->sys_nargs = nargs;
3897c478bd9Sstevel@tonic-gate 
3908fd04b83SRoger A. Faulkner 	/*
3918fd04b83SRoger A. Faulkner 	 * Fetch and remember first argument if it's a string,
3928fd04b83SRoger A. Faulkner 	 * or second argument if SYS_openat or SYS_openat64.
3938fd04b83SRoger A. Faulkner 	 */
3947c478bd9Sstevel@tonic-gate 	pri->sys_valid = FALSE;
3958fd04b83SRoger A. Faulkner 	if ((nargs > 0 && stp->arg[0] == STG) ||
3968fd04b83SRoger A. Faulkner 	    (nargs > 1 && (what == SYS_openat || what == SYS_openat64))) {
3977c478bd9Sstevel@tonic-gate 		long offset;
3987c478bd9Sstevel@tonic-gate 		uint32_t offset32;
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 		/*
4017c478bd9Sstevel@tonic-gate 		 * Special case for exit from exec().
4027c478bd9Sstevel@tonic-gate 		 * The address in pri->sys_args[0] refers to the old process
4037c478bd9Sstevel@tonic-gate 		 * image.  We must fetch the string from the new image.
4047c478bd9Sstevel@tonic-gate 		 */
4058fd04b83SRoger A. Faulkner 		if (Lsp->pr_why == PR_SYSEXIT && what == SYS_execve) {
4067c478bd9Sstevel@tonic-gate 			psinfo_t psinfo;
4077c478bd9Sstevel@tonic-gate 			long argv;
4087c478bd9Sstevel@tonic-gate 			auxv_t auxv[32];
4097c478bd9Sstevel@tonic-gate 			int naux;
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate 			offset = 0;
4127c478bd9Sstevel@tonic-gate 			naux = proc_get_auxv(pid, auxv, 32);
4137c478bd9Sstevel@tonic-gate 			for (i = 0; i < naux; i++) {
4147c478bd9Sstevel@tonic-gate 				if (auxv[i].a_type == AT_SUN_EXECNAME) {
4157c478bd9Sstevel@tonic-gate 					offset = (long)auxv[i].a_un.a_ptr;
4167c478bd9Sstevel@tonic-gate 					break;
4177c478bd9Sstevel@tonic-gate 				}
4187c478bd9Sstevel@tonic-gate 			}
4197c478bd9Sstevel@tonic-gate 			if (offset == 0 &&
4207c478bd9Sstevel@tonic-gate 			    proc_get_psinfo(pid, &psinfo) == 0) {
4217c478bd9Sstevel@tonic-gate 				argv = (long)psinfo.pr_argv;
4227c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_LP64)
4237c478bd9Sstevel@tonic-gate 					(void) Pread(Proc, &offset,
4245403172aSRoger A. Faulkner 					    sizeof (offset), argv);
4257c478bd9Sstevel@tonic-gate 				else {
4267c478bd9Sstevel@tonic-gate 					offset32 = 0;
4277c478bd9Sstevel@tonic-gate 					(void) Pread(Proc, &offset32,
4285403172aSRoger A. Faulkner 					    sizeof (offset32), argv);
4297c478bd9Sstevel@tonic-gate 					offset = offset32;
4307c478bd9Sstevel@tonic-gate 				}
4317c478bd9Sstevel@tonic-gate 			}
4328fd04b83SRoger A. Faulkner 		} else if (stp->arg[0] == STG) {
4337c478bd9Sstevel@tonic-gate 			offset = pri->sys_args[0];
4348fd04b83SRoger A. Faulkner 		} else {
4358fd04b83SRoger A. Faulkner 			offset = pri->sys_args[1];
4367c478bd9Sstevel@tonic-gate 		}
4377c478bd9Sstevel@tonic-gate 		if ((s = fetchstring(pri, offset, PATH_MAX)) != NULL) {
4387c478bd9Sstevel@tonic-gate 			pri->sys_valid = TRUE;
4397c478bd9Sstevel@tonic-gate 			len = strlen(s);
4407c478bd9Sstevel@tonic-gate 			/* reallocate if necessary */
4417c478bd9Sstevel@tonic-gate 			while (len >= pri->sys_psize) {
4427c478bd9Sstevel@tonic-gate 				free(pri->sys_path);
4437c478bd9Sstevel@tonic-gate 				pri->sys_path = my_malloc(pri->sys_psize *= 2,
4445403172aSRoger A. Faulkner 				    "pathname buffer");
4457c478bd9Sstevel@tonic-gate 			}
4467c478bd9Sstevel@tonic-gate 			(void) strcpy(pri->sys_path, s); /* remember pathname */
4477c478bd9Sstevel@tonic-gate 		}
4487c478bd9Sstevel@tonic-gate 	}
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	istraced = dotrace && prismember(&trace, what);
4517c478bd9Sstevel@tonic-gate 	raw = prismember(&rawout, what);
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 	/* force tracing of read/write buffer dump syscalls */
4547c478bd9Sstevel@tonic-gate 	if (!istraced && nargs > 2) {
4557c478bd9Sstevel@tonic-gate 		int fdp1 = (int)pri->sys_args[0] + 1;
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 		if (ISREAD(what)) {
4587c478bd9Sstevel@tonic-gate 			if (prismember(&readfd, fdp1))
4597c478bd9Sstevel@tonic-gate 				istraced = TRUE;
4607c478bd9Sstevel@tonic-gate 		} else if (ISWRITE(what)) {
4617c478bd9Sstevel@tonic-gate 			if (prismember(&writefd, fdp1))
4627c478bd9Sstevel@tonic-gate 				istraced = TRUE;
4637c478bd9Sstevel@tonic-gate 		}
4647c478bd9Sstevel@tonic-gate 	}
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	pri->sys_leng = 0;
4677c478bd9Sstevel@tonic-gate 	if (cflag || !istraced)		/* just counting */
4687c478bd9Sstevel@tonic-gate 		*pri->sys_string = 0;
4697c478bd9Sstevel@tonic-gate 	else {
4707c478bd9Sstevel@tonic-gate 		int argprinted = FALSE;
4717c478bd9Sstevel@tonic-gate 		const char *name;
4727c478bd9Sstevel@tonic-gate 
473657b1f3dSraf 		name = sysname(pri, what, raw? -1 : subcode);
4747c478bd9Sstevel@tonic-gate 		grow(pri, strlen(name) + 1);
4757c478bd9Sstevel@tonic-gate 		pri->sys_leng = snprintf(pri->sys_string, pri->sys_ssize,
4765403172aSRoger A. Faulkner 		    "%s(", name);
4777c478bd9Sstevel@tonic-gate 		for (i = 0; i < nargs; i++) {
4787c478bd9Sstevel@tonic-gate 			arg = pri->sys_args[i];
4797c478bd9Sstevel@tonic-gate 			x = stp->arg[i];
4807c478bd9Sstevel@tonic-gate 
4818fd04b83SRoger A. Faulkner 			if (!raw && pri->sys_valid &&
4828fd04b83SRoger A. Faulkner 			    ((i == 0 && x == STG) ||
4838fd04b83SRoger A. Faulkner 			    (i == 1 && (what == SYS_openat ||
4848fd04b83SRoger A. Faulkner 			    what == SYS_openat64)))) {	/* already fetched */
485*c4d3e299SBrent Paulson 				if (argprinted)
486*c4d3e299SBrent Paulson 					outstring(pri, ", ");
4877c478bd9Sstevel@tonic-gate 				escape_string(pri, pri->sys_path);
4887c478bd9Sstevel@tonic-gate 				argprinted = TRUE;
489*c4d3e299SBrent Paulson 			} else if (x != NOV && (x != HID || raw)) {
4907c478bd9Sstevel@tonic-gate 				if (argprinted)
4917c478bd9Sstevel@tonic-gate 					outstring(pri, ", ");
4927c478bd9Sstevel@tonic-gate 				if (x == LLO)
4937c478bd9Sstevel@tonic-gate 					(*Print[x])(pri, raw, arg,
4945403172aSRoger A. Faulkner 					    pri->sys_args[++i]);
4957c478bd9Sstevel@tonic-gate 				else
4967c478bd9Sstevel@tonic-gate 					(*Print[x])(pri, raw, arg);
497*c4d3e299SBrent Paulson 				argprinted = TRUE;
4987c478bd9Sstevel@tonic-gate 			}
4997c478bd9Sstevel@tonic-gate 		}
5007c478bd9Sstevel@tonic-gate 		outstring(pri, ")");
5017c478bd9Sstevel@tonic-gate 	}
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	return (istraced);
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate #undef	ISREAD
5067c478bd9Sstevel@tonic-gate #undef	ISWRITE
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate /*
5097c478bd9Sstevel@tonic-gate  * sysexit() returns non-zero if anything was printed.
5107c478bd9Sstevel@tonic-gate  */
5117c478bd9Sstevel@tonic-gate int
sysexit(private_t * pri,int dotrace)5127c478bd9Sstevel@tonic-gate sysexit(private_t *pri, int dotrace)
5137c478bd9Sstevel@tonic-gate {
5147c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
5157c478bd9Sstevel@tonic-gate 	int what = Lsp->pr_what;
5167c478bd9Sstevel@tonic-gate 	struct syscount *scp;
5177c478bd9Sstevel@tonic-gate 	const struct systable *stp;
5187c478bd9Sstevel@tonic-gate 	int subcode;
5197c478bd9Sstevel@tonic-gate 	int istraced;
5207c478bd9Sstevel@tonic-gate 	int raw;
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 	/* protect ourself from operating system error */
5237c478bd9Sstevel@tonic-gate 	if (what <= 0 || what > PRMAXSYS)
5247c478bd9Sstevel@tonic-gate 		return (0);
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	/*
5277c478bd9Sstevel@tonic-gate 	 * If we aren't supposed to be tracing this one, then
5287c478bd9Sstevel@tonic-gate 	 * delete it from the traced signal set.  We got here
5297c478bd9Sstevel@tonic-gate 	 * because the process was sleeping in an untraced syscall.
5307c478bd9Sstevel@tonic-gate 	 */
5317c478bd9Sstevel@tonic-gate 	if (!prismember(&traceeven, what)) {
5327c478bd9Sstevel@tonic-gate 		(void) Psysexit(Proc, what, FALSE);
5337c478bd9Sstevel@tonic-gate 		return (0);
5347c478bd9Sstevel@tonic-gate 	}
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	/* pick up registers & set pri->Errno before anything else */
5377c478bd9Sstevel@tonic-gate 	pri->Errno = Lsp->pr_errno;
5387c478bd9Sstevel@tonic-gate 	pri->ErrPriv = Lsp->pr_errpriv;
5397c478bd9Sstevel@tonic-gate 	pri->Rval1 = Lsp->pr_rval1;
5407c478bd9Sstevel@tonic-gate 	pri->Rval2 = Lsp->pr_rval2;
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	switch (what) {
5437c478bd9Sstevel@tonic-gate 	case SYS_exit:		/* these are traced on entry */
5447c478bd9Sstevel@tonic-gate 	case SYS_lwp_exit:
5457c478bd9Sstevel@tonic-gate 	case SYS_context:
5467c478bd9Sstevel@tonic-gate 		istraced = dotrace && prismember(&trace, what);
5477c478bd9Sstevel@tonic-gate 		break;
5488fd04b83SRoger A. Faulkner 	case SYS_execve:	/* this is normally traced on entry */
5497c478bd9Sstevel@tonic-gate 		istraced = dotrace && prismember(&trace, what);
5507c478bd9Sstevel@tonic-gate 		if (pri->exec_string && *pri->exec_string) {
5517c478bd9Sstevel@tonic-gate 			if (!cflag && istraced) { /* print exec() string now */
5527c478bd9Sstevel@tonic-gate 				if (pri->exec_pname[0] != '\0')
5537c478bd9Sstevel@tonic-gate 					(void) fputs(pri->exec_pname, stdout);
5547c478bd9Sstevel@tonic-gate 				timestamp(pri);
5557c478bd9Sstevel@tonic-gate 				(void) fputs(pri->exec_string, stdout);
5567c478bd9Sstevel@tonic-gate 			}
5577c478bd9Sstevel@tonic-gate 			pri->exec_pname[0] = '\0';
5587c478bd9Sstevel@tonic-gate 			pri->exec_string[0] = '\0';
5597c478bd9Sstevel@tonic-gate 			break;
5607c478bd9Sstevel@tonic-gate 		}
5617c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
5627c478bd9Sstevel@tonic-gate 	default:
5637c478bd9Sstevel@tonic-gate 		/* we called sysentry() in main() for these */
5648fd04b83SRoger A. Faulkner 		if (what == SYS_openat || what == SYS_openat64 ||
5658fd04b83SRoger A. Faulkner 		    what == SYS_open || what == SYS_open64)
5667c478bd9Sstevel@tonic-gate 			istraced = dotrace && prismember(&trace, what);
5677c478bd9Sstevel@tonic-gate 		else
5687c478bd9Sstevel@tonic-gate 			istraced = sysentry(pri, dotrace) && dotrace;
5697c478bd9Sstevel@tonic-gate 		pri->length = 0;
5707c478bd9Sstevel@tonic-gate 		if (!cflag && istraced) {
5717c478bd9Sstevel@tonic-gate 			putpname(pri);
5727c478bd9Sstevel@tonic-gate 			timestamp(pri);
5737c478bd9Sstevel@tonic-gate 			pri->length += printf("%s", pri->sys_string);
5747c478bd9Sstevel@tonic-gate 		}
5757c478bd9Sstevel@tonic-gate 		pri->sys_leng = 0;
5767c478bd9Sstevel@tonic-gate 		*pri->sys_string = '\0';
5777c478bd9Sstevel@tonic-gate 		break;
5787c478bd9Sstevel@tonic-gate 	}
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	/* get systable entry for this syscall */
5817c478bd9Sstevel@tonic-gate 	subcode = getsubcode(pri);
5827c478bd9Sstevel@tonic-gate 	stp = subsys(what, subcode);
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	if (cflag && istraced) {
5857c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&count_lock);
5867c478bd9Sstevel@tonic-gate 		scp = Cp->syscount[what];
587657b1f3dSraf 		if (what == SYS_forksys && subcode >= 3)
588657b1f3dSraf 			scp += subcode - 3;
589657b1f3dSraf 		else if (subcode != -1 &&
5908fd04b83SRoger A. Faulkner 		    (what != SYS_openat && what != SYS_openat64 &&
5918fd04b83SRoger A. Faulkner 		    what != SYS_open && what != SYS_open64 &&
5927c478bd9Sstevel@tonic-gate 		    what != SYS_lwp_create))
5937c478bd9Sstevel@tonic-gate 			scp += subcode;
5947c478bd9Sstevel@tonic-gate 		scp->count++;
5957c478bd9Sstevel@tonic-gate 		accumulate(&scp->stime, &Lsp->pr_stime, &pri->syslast);
5967c478bd9Sstevel@tonic-gate 		accumulate(&Cp->usrtotal, &Lsp->pr_utime, &pri->usrlast);
5977c478bd9Sstevel@tonic-gate 		pri->syslast = Lsp->pr_stime;
5987c478bd9Sstevel@tonic-gate 		pri->usrlast = Lsp->pr_utime;
5997c478bd9Sstevel@tonic-gate 		(void) mutex_unlock(&count_lock);
6007c478bd9Sstevel@tonic-gate 	}
6017c478bd9Sstevel@tonic-gate 
602657b1f3dSraf 	raw = prismember(&rawout, what);
603657b1f3dSraf 
6047c478bd9Sstevel@tonic-gate 	if (!cflag && istraced) {
6058fd04b83SRoger A. Faulkner 		if ((what == SYS_vfork || what == SYS_forksys) &&
6067c478bd9Sstevel@tonic-gate 		    pri->Errno == 0 && pri->Rval2 != 0) {
6077c478bd9Sstevel@tonic-gate 			pri->length &= ~07;
608657b1f3dSraf 			if (strlen(sysname(pri, what, raw? -1 : subcode)) < 6) {
6097c478bd9Sstevel@tonic-gate 				(void) fputc('\t', stdout);
610657b1f3dSraf 				pri->length += 8;
611657b1f3dSraf 			}
6127c478bd9Sstevel@tonic-gate 			pri->length +=
6135403172aSRoger A. Faulkner 			    7 + printf("\t(returning as child ...)");
6147c478bd9Sstevel@tonic-gate 		}
6157c478bd9Sstevel@tonic-gate 		if (what == SYS_lwp_create &&
6167c478bd9Sstevel@tonic-gate 		    pri->Errno == 0 && pri->Rval1 == 0) {
6177c478bd9Sstevel@tonic-gate 			pri->length &= ~07;
6187c478bd9Sstevel@tonic-gate 			pri->length +=
6195403172aSRoger A. Faulkner 			    7 + printf("\t(returning as new lwp ...)");
6207c478bd9Sstevel@tonic-gate 		}
6218fd04b83SRoger A. Faulkner 		if (pri->Errno != 0 || what != SYS_execve) {
6227c478bd9Sstevel@tonic-gate 			/* prepare to print the return code */
6237c478bd9Sstevel@tonic-gate 			pri->length >>= 3;
6247c478bd9Sstevel@tonic-gate 			if (pri->length >= 6)
6257c478bd9Sstevel@tonic-gate 				(void) fputc(' ', stdout);
6267c478bd9Sstevel@tonic-gate 			for (; pri->length < 6; pri->length++)
6277c478bd9Sstevel@tonic-gate 				(void) fputc('\t', stdout);
6287c478bd9Sstevel@tonic-gate 		}
6297c478bd9Sstevel@tonic-gate 	}
6307c478bd9Sstevel@tonic-gate 	pri->length = 0;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate 	if (pri->Errno != 0) {		/* error in syscall */
6337c478bd9Sstevel@tonic-gate 		if (istraced) {
6347c478bd9Sstevel@tonic-gate 			if (cflag)
6357c478bd9Sstevel@tonic-gate 				scp->error++;
6367c478bd9Sstevel@tonic-gate 			else {
6377c478bd9Sstevel@tonic-gate 				const char *ename = errname(pri->Errno);
6387c478bd9Sstevel@tonic-gate 				const char *privname;
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 				(void) printf("Err#%d", pri->Errno);
6417c478bd9Sstevel@tonic-gate 				if (ename != NULL) {
6427c478bd9Sstevel@tonic-gate 					(void) fputc(' ', stdout);
6437c478bd9Sstevel@tonic-gate 					(void) fputs(ename, stdout);
6447c478bd9Sstevel@tonic-gate 				}
6457c478bd9Sstevel@tonic-gate 				switch (pri->ErrPriv) {
6467c478bd9Sstevel@tonic-gate 				case PRIV_NONE:
6477c478bd9Sstevel@tonic-gate 					privname = NULL;
6487c478bd9Sstevel@tonic-gate 					break;
6497c478bd9Sstevel@tonic-gate 				case PRIV_ALL:
6507c478bd9Sstevel@tonic-gate 					privname = "ALL";
6517c478bd9Sstevel@tonic-gate 					break;
6527c478bd9Sstevel@tonic-gate 				case PRIV_MULTIPLE:
6537c478bd9Sstevel@tonic-gate 					privname = "MULTIPLE";
6547c478bd9Sstevel@tonic-gate 					break;
6557c478bd9Sstevel@tonic-gate 				case PRIV_ALLZONE:
6567c478bd9Sstevel@tonic-gate 					privname = "ZONE";
6577c478bd9Sstevel@tonic-gate 					break;
6587c478bd9Sstevel@tonic-gate 				default:
6597c478bd9Sstevel@tonic-gate 					privname = priv_getbynum(pri->ErrPriv);
6607c478bd9Sstevel@tonic-gate 					break;
6617c478bd9Sstevel@tonic-gate 				}
6627c478bd9Sstevel@tonic-gate 				if (privname != NULL)
6637c478bd9Sstevel@tonic-gate 					(void) printf(" [%s]", privname);
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 				(void) fputc('\n', stdout);
6667c478bd9Sstevel@tonic-gate 			}
6677c478bd9Sstevel@tonic-gate 		}
6687c478bd9Sstevel@tonic-gate 	} else {
6697c478bd9Sstevel@tonic-gate 		/* show arguments on successful exec */
6708fd04b83SRoger A. Faulkner 		if (what == SYS_execve) {
6717c478bd9Sstevel@tonic-gate 			if (!cflag && istraced)
6727c478bd9Sstevel@tonic-gate 				showargs(pri, raw);
6737c478bd9Sstevel@tonic-gate 		} else if (!cflag && istraced) {
6747c478bd9Sstevel@tonic-gate 			const char *fmt = NULL;
6757c478bd9Sstevel@tonic-gate 			long rv1 = pri->Rval1;
6767c478bd9Sstevel@tonic-gate 			long rv2 = pri->Rval2;
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate #ifdef _LP64
6797c478bd9Sstevel@tonic-gate 			/*
6807c478bd9Sstevel@tonic-gate 			 * 32-bit system calls return 32-bit values. We
6817c478bd9Sstevel@tonic-gate 			 * later mask out the upper bits if we want to
6827c478bd9Sstevel@tonic-gate 			 * print these as unsigned values.
6837c478bd9Sstevel@tonic-gate 			 */
6847c478bd9Sstevel@tonic-gate 			if (data_model == PR_MODEL_ILP32) {
6857c478bd9Sstevel@tonic-gate 				rv1 = (int)rv1;
6867c478bd9Sstevel@tonic-gate 				rv2 = (int)rv2;
6877c478bd9Sstevel@tonic-gate 			}
6887c478bd9Sstevel@tonic-gate #endif
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 			switch (what) {
6917c478bd9Sstevel@tonic-gate 			case SYS_llseek:
6927c478bd9Sstevel@tonic-gate 				rv1 &= 0xffffffff;
6937c478bd9Sstevel@tonic-gate 				rv2 &= 0xffffffff;
6947c478bd9Sstevel@tonic-gate #ifdef _LONG_LONG_LTOH	/* first long of a longlong is the low order */
6957c478bd9Sstevel@tonic-gate 				if (rv2 != 0) {
6967c478bd9Sstevel@tonic-gate 					long temp = rv1;
6977c478bd9Sstevel@tonic-gate 					fmt = "= 0x%lX%.8lX";
6987c478bd9Sstevel@tonic-gate 					rv1 = rv2;
6997c478bd9Sstevel@tonic-gate 					rv2 = temp;
7007c478bd9Sstevel@tonic-gate 					break;
7017c478bd9Sstevel@tonic-gate 				}
7027c478bd9Sstevel@tonic-gate #else	/* the other way around */
7037c478bd9Sstevel@tonic-gate 				if (rv1 != 0) {
7047c478bd9Sstevel@tonic-gate 					fmt = "= 0x%lX%.8lX";
7057c478bd9Sstevel@tonic-gate 					break;
7067c478bd9Sstevel@tonic-gate 				}
7077c478bd9Sstevel@tonic-gate 				rv1 = rv2;	/* ugly */
7087c478bd9Sstevel@tonic-gate #endif
7097c478bd9Sstevel@tonic-gate 				/* FALLTHROUGH */
7107c478bd9Sstevel@tonic-gate 			case SYS_lseek:
7117c478bd9Sstevel@tonic-gate 			case SYS_ulimit:
7127c478bd9Sstevel@tonic-gate 				if (rv1 & 0xff000000) {
7137c478bd9Sstevel@tonic-gate #ifdef _LP64
7147c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7157c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7167c478bd9Sstevel@tonic-gate #endif
7177c478bd9Sstevel@tonic-gate 					fmt = "= 0x%.8lX";
7187c478bd9Sstevel@tonic-gate 				}
7197c478bd9Sstevel@tonic-gate 				break;
7207c478bd9Sstevel@tonic-gate 			case SYS_sigtimedwait:
7217c478bd9Sstevel@tonic-gate 				if (raw)
7227c478bd9Sstevel@tonic-gate 					/* EMPTY */;
7237c478bd9Sstevel@tonic-gate 				else if ((fmt = rawsigname(pri, rv1)) != NULL) {
7247c478bd9Sstevel@tonic-gate 					rv1 = (long)fmt;	/* filthy */
7257c478bd9Sstevel@tonic-gate 					fmt = "= %s";
7267c478bd9Sstevel@tonic-gate 				}
7277c478bd9Sstevel@tonic-gate 				break;
7287c478bd9Sstevel@tonic-gate 			case SYS_port:
7297c478bd9Sstevel@tonic-gate #ifdef _LP64
7307c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_LP64) {
7317c478bd9Sstevel@tonic-gate 					rv2 = rv1 & 0xffffffff;
7327c478bd9Sstevel@tonic-gate 					rv1 = rv1 >> 32;
7337c478bd9Sstevel@tonic-gate 				}
7347c478bd9Sstevel@tonic-gate #endif
7357c478bd9Sstevel@tonic-gate 				break;
7367c478bd9Sstevel@tonic-gate 			}
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 			if (fmt == NULL) {
7397c478bd9Sstevel@tonic-gate 				switch (stp->rval[0]) {
7407c478bd9Sstevel@tonic-gate 				case HEX:
7417c478bd9Sstevel@tonic-gate #ifdef _LP64
7427c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7437c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7447c478bd9Sstevel@tonic-gate #endif
7457c478bd9Sstevel@tonic-gate 					fmt = "= 0x%.8lX";
7467c478bd9Sstevel@tonic-gate 					break;
7477c478bd9Sstevel@tonic-gate 				case HHX:
7487c478bd9Sstevel@tonic-gate #ifdef _LP64
7497c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7507c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7517c478bd9Sstevel@tonic-gate #endif
7527c478bd9Sstevel@tonic-gate 					fmt = "= 0x%.4lX";
7537c478bd9Sstevel@tonic-gate 					break;
7547c478bd9Sstevel@tonic-gate 				case OCT:
7557c478bd9Sstevel@tonic-gate #ifdef _LP64
7567c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7577c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7587c478bd9Sstevel@tonic-gate #endif
7597c478bd9Sstevel@tonic-gate 					fmt = "= %#lo";
7607c478bd9Sstevel@tonic-gate 					break;
761f48205beScasper 				case UNS:
762f48205beScasper #ifdef _LP64
763f48205beScasper 					if (data_model == PR_MODEL_ILP32)
764f48205beScasper 						rv1 &= 0xffffffff;
765f48205beScasper #endif
766f48205beScasper 					fmt = "= %lu";
767f48205beScasper 					break;
7687c478bd9Sstevel@tonic-gate 				default:
7697c478bd9Sstevel@tonic-gate 					fmt = "= %ld";
7707c478bd9Sstevel@tonic-gate 					break;
7717c478bd9Sstevel@tonic-gate 				}
7727c478bd9Sstevel@tonic-gate 			}
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 			(void) printf(fmt, rv1, rv2);
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 			switch (stp->rval[1]) {
7777c478bd9Sstevel@tonic-gate 			case NOV:
7787c478bd9Sstevel@tonic-gate 				fmt = NULL;
7797c478bd9Sstevel@tonic-gate 				break;
7807c478bd9Sstevel@tonic-gate 			case HEX:
7817c478bd9Sstevel@tonic-gate #ifdef _LP64
7827c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_ILP32)
7837c478bd9Sstevel@tonic-gate 					rv2 &= 0xffffffff;
7847c478bd9Sstevel@tonic-gate #endif
7857c478bd9Sstevel@tonic-gate 				fmt = " [0x%.8lX]";
7867c478bd9Sstevel@tonic-gate 				break;
7877c478bd9Sstevel@tonic-gate 			case HHX:
7887c478bd9Sstevel@tonic-gate #ifdef _LP64
7897c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_ILP32)
7907c478bd9Sstevel@tonic-gate 					rv2 &= 0xffffffff;
7917c478bd9Sstevel@tonic-gate #endif
7927c478bd9Sstevel@tonic-gate 				fmt = " [0x%.4lX]";
7937c478bd9Sstevel@tonic-gate 				break;
7947c478bd9Sstevel@tonic-gate 			case OCT:
7957c478bd9Sstevel@tonic-gate #ifdef _LP64
7967c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_ILP32)
7977c478bd9Sstevel@tonic-gate 					rv2 &= 0xffffffff;
7987c478bd9Sstevel@tonic-gate #endif
7997c478bd9Sstevel@tonic-gate 				fmt = " [%#lo]";
8007c478bd9Sstevel@tonic-gate 				break;
801f48205beScasper 			case UNS:
802f48205beScasper #ifdef _LP64
803f48205beScasper 				if (data_model == PR_MODEL_ILP32)
804f48205beScasper 					rv2 &= 0xffffffff;
805f48205beScasper #endif
806f48205beScasper 				fmt = " [%lu]";
807f48205beScasper 				break;
8087c478bd9Sstevel@tonic-gate 			default:
8097c478bd9Sstevel@tonic-gate 				fmt = " [%ld]";
8107c478bd9Sstevel@tonic-gate 				break;
8117c478bd9Sstevel@tonic-gate 			}
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 			if (fmt != NULL)
8147c478bd9Sstevel@tonic-gate 				(void) printf(fmt, rv2);
8157c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stdout);
8167c478bd9Sstevel@tonic-gate 		}
8177c478bd9Sstevel@tonic-gate 
8188fd04b83SRoger A. Faulkner 		if (what == SYS_vfork || what == SYS_forksys) {
8197c478bd9Sstevel@tonic-gate 			if (pri->Rval2 == 0)		/* child was created */
8207c478bd9Sstevel@tonic-gate 				pri->child = pri->Rval1;
8217c478bd9Sstevel@tonic-gate 			else if (cflag && istraced)	/* this is the child */
8227c478bd9Sstevel@tonic-gate 				scp->count--;
8237c478bd9Sstevel@tonic-gate 		}
8247c478bd9Sstevel@tonic-gate 		if (what == SYS_lwp_create && pri->Rval1 == 0 &&
8257c478bd9Sstevel@tonic-gate 		    cflag && istraced)		/* this is the created lwp */
8267c478bd9Sstevel@tonic-gate 			scp->count--;
8277c478bd9Sstevel@tonic-gate 	}
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate #define	ISREAD(code) \
8307c478bd9Sstevel@tonic-gate 	((code) == SYS_read || (code) == SYS_pread || (code) == SYS_pread64 || \
8317c478bd9Sstevel@tonic-gate 	(code) == SYS_recv || (code) == SYS_recvfrom)
8327c478bd9Sstevel@tonic-gate #define	ISWRITE(code) \
8337c478bd9Sstevel@tonic-gate 	((code) == SYS_write || (code) == SYS_pwrite || \
8347c478bd9Sstevel@tonic-gate 	(code) == SYS_pwrite64 || (code) == SYS_send || (code) == SYS_sendto)
8357c478bd9Sstevel@tonic-gate 
8367c478bd9Sstevel@tonic-gate 	if (!cflag && istraced) {
8377c478bd9Sstevel@tonic-gate 		int fdp1 = (int)pri->sys_args[0] + 1; /* filedescriptor + 1 */
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 		if (raw) {
8408fd04b83SRoger A. Faulkner 			if (what != SYS_execve)
8417c478bd9Sstevel@tonic-gate 				showpaths(pri, stp);
8427c478bd9Sstevel@tonic-gate 			if (ISREAD(what) || ISWRITE(what)) {
8437c478bd9Sstevel@tonic-gate 				if (pri->iob_buf[0] != '\0')
8447c478bd9Sstevel@tonic-gate 					(void) printf("%s     0x%.8lX: %s\n",
8455403172aSRoger A. Faulkner 					    pri->pname, pri->sys_args[1],
8465403172aSRoger A. Faulkner 					    pri->iob_buf);
8477c478bd9Sstevel@tonic-gate 			}
8487c478bd9Sstevel@tonic-gate 		}
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 		/*
8517c478bd9Sstevel@tonic-gate 		 * Show buffer contents for read()/pread() or write()/pwrite().
8527c478bd9Sstevel@tonic-gate 		 * IOBSIZE bytes have already been shown;
8537c478bd9Sstevel@tonic-gate 		 * don't show them again unless there's more.
8547c478bd9Sstevel@tonic-gate 		 */
8557c478bd9Sstevel@tonic-gate 		if ((ISREAD(what) && pri->Errno == 0 &&
8567c478bd9Sstevel@tonic-gate 		    prismember(&readfd, fdp1)) ||
8577c478bd9Sstevel@tonic-gate 		    (ISWRITE(what) && prismember(&writefd, fdp1))) {
8587c478bd9Sstevel@tonic-gate 			long nb = ISWRITE(what) ? pri->sys_args[2] : pri->Rval1;
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 			if (nb > IOBSIZE) {
8617c478bd9Sstevel@tonic-gate 				/* enter region of lengthy output */
8627c478bd9Sstevel@tonic-gate 				if (nb > MYBUFSIZ / 4)
8637c478bd9Sstevel@tonic-gate 					Eserialize();
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 				showbuffer(pri, pri->sys_args[1], nb);
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 				/* exit region of lengthy output */
8687c478bd9Sstevel@tonic-gate 				if (nb > MYBUFSIZ / 4)
8697c478bd9Sstevel@tonic-gate 					Xserialize();
8707c478bd9Sstevel@tonic-gate 			}
8717c478bd9Sstevel@tonic-gate 		}
8727c478bd9Sstevel@tonic-gate #undef	ISREAD
8737c478bd9Sstevel@tonic-gate #undef	ISWRITE
8747c478bd9Sstevel@tonic-gate 		/*
8757c478bd9Sstevel@tonic-gate 		 * Do verbose interpretation if requested.
8767c478bd9Sstevel@tonic-gate 		 * If buffer contents for read or write have been requested and
8777c478bd9Sstevel@tonic-gate 		 * this is a readv() or writev(), force verbose interpretation.
8787c478bd9Sstevel@tonic-gate 		 */
8797c478bd9Sstevel@tonic-gate 		if (prismember(&verbose, what) ||
88081006e0fSja 		    ((what == SYS_readv || what == SYS_recvmsg) &&
88181006e0fSja 		    pri->Errno == 0 && prismember(&readfd, fdp1)) ||
88281006e0fSja 		    ((what == SYS_writev || what == SYS_sendfilev ||
88381006e0fSja 		    what == SYS_sendmsg) &&
8847c478bd9Sstevel@tonic-gate 		    prismember(&writefd, fdp1)))
8857c478bd9Sstevel@tonic-gate 			expound(pri, pri->Rval1, raw);
8867c478bd9Sstevel@tonic-gate 	}
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	return (!cflag && istraced);
8897c478bd9Sstevel@tonic-gate }
8907c478bd9Sstevel@tonic-gate 
8917c478bd9Sstevel@tonic-gate void
showpaths(private_t * pri,const struct systable * stp)8927c478bd9Sstevel@tonic-gate showpaths(private_t *pri, const struct systable *stp)
8937c478bd9Sstevel@tonic-gate {
8948fd04b83SRoger A. Faulkner 	int what = pri->lwpstat->pr_what;
8957c478bd9Sstevel@tonic-gate 	int i;
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 	for (i = 0; i < pri->sys_nargs; i++) {
8988fd04b83SRoger A. Faulkner 		if (stp->arg[i] == ATC && (int)pri->sys_args[i] == AT_FDCWD) {
8998fd04b83SRoger A. Faulkner 			(void) printf("%s     0x%.8X: AT_FDCWD\n",
9008fd04b83SRoger A. Faulkner 			    pri->pname, AT_FDCWD);
9018fd04b83SRoger A. Faulkner 		} else if ((stp->arg[i] == STG) ||
9027c478bd9Sstevel@tonic-gate 		    (stp->arg[i] == RST && !pri->Errno) ||
9037c478bd9Sstevel@tonic-gate 		    (stp->arg[i] == RLK && !pri->Errno && pri->Rval1 > 0)) {
9047c478bd9Sstevel@tonic-gate 			long addr = pri->sys_args[i];
9057c478bd9Sstevel@tonic-gate 			int maxleng =
9067c478bd9Sstevel@tonic-gate 			    (stp->arg[i] == RLK)? (int)pri->Rval1 : PATH_MAX;
9077c478bd9Sstevel@tonic-gate 			char *s;
9087c478bd9Sstevel@tonic-gate 
9098fd04b83SRoger A. Faulkner 			if (pri->sys_valid &&
9108fd04b83SRoger A. Faulkner 			    ((i == 0 && stp->arg[0] == STG) ||
9118fd04b83SRoger A. Faulkner 			    (i == 1 && (what == SYS_openat ||
9128fd04b83SRoger A. Faulkner 			    what == SYS_openat64))))	/* already fetched */
9137c478bd9Sstevel@tonic-gate 				s = pri->sys_path;
9147c478bd9Sstevel@tonic-gate 			else
9157c478bd9Sstevel@tonic-gate 				s = fetchstring(pri, addr,
9167c478bd9Sstevel@tonic-gate 				    maxleng > PATH_MAX ? PATH_MAX : maxleng);
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate 			if (s != (char *)NULL)
9197c478bd9Sstevel@tonic-gate 				(void) printf("%s     0x%.8lX: \"%s\"\n",
9205403172aSRoger A. Faulkner 				    pri->pname, addr, s);
9217c478bd9Sstevel@tonic-gate 		}
9227c478bd9Sstevel@tonic-gate 	}
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate /*
9267c478bd9Sstevel@tonic-gate  * Display arguments to successful exec().
9277c478bd9Sstevel@tonic-gate  */
9287c478bd9Sstevel@tonic-gate void
showargs(private_t * pri,int raw)9297c478bd9Sstevel@tonic-gate showargs(private_t *pri, int raw)
9307c478bd9Sstevel@tonic-gate {
9317c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
9327c478bd9Sstevel@tonic-gate 	int nargs;
9337c478bd9Sstevel@tonic-gate 	long ap;
9347c478bd9Sstevel@tonic-gate 	int ptrsize;
9357c478bd9Sstevel@tonic-gate 	int fail;
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 	pri->length = 0;
9387c478bd9Sstevel@tonic-gate 	ptrsize = (data_model == PR_MODEL_LP64)? 8 : 4;
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)	/* XX64 */
9417c478bd9Sstevel@tonic-gate 	ap = (long)Lsp->pr_reg[R_SP];
9427c478bd9Sstevel@tonic-gate 	fail = (Pread(Proc, &nargs, sizeof (nargs), ap) != sizeof (nargs));
9437c478bd9Sstevel@tonic-gate 	ap += ptrsize;
9447c478bd9Sstevel@tonic-gate #endif /* i386 */
9457c478bd9Sstevel@tonic-gate 
9467c478bd9Sstevel@tonic-gate #if sparc
9477c478bd9Sstevel@tonic-gate 	if (data_model == PR_MODEL_LP64) {
9487c478bd9Sstevel@tonic-gate 		int64_t xnargs;
9497c478bd9Sstevel@tonic-gate 		ap = (long)(Lsp->pr_reg[R_SP]) + 16 * sizeof (int64_t)
9505403172aSRoger A. Faulkner 		    + STACK_BIAS;
9517c478bd9Sstevel@tonic-gate 		fail = (Pread(Proc, &xnargs, sizeof (xnargs), ap) !=
9525403172aSRoger A. Faulkner 		    sizeof (xnargs));
9537c478bd9Sstevel@tonic-gate 		nargs = (int)xnargs;
9547c478bd9Sstevel@tonic-gate 	} else {
9557c478bd9Sstevel@tonic-gate 		ap = (long)(Lsp->pr_reg[R_SP]) + 16 * sizeof (int32_t);
9567c478bd9Sstevel@tonic-gate 		fail = (Pread(Proc, &nargs, sizeof (nargs), ap) !=
9575403172aSRoger A. Faulkner 		    sizeof (nargs));
9587c478bd9Sstevel@tonic-gate 	}
9597c478bd9Sstevel@tonic-gate 	ap += ptrsize;
9607c478bd9Sstevel@tonic-gate #endif /* sparc */
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 	if (fail) {
9637c478bd9Sstevel@tonic-gate 		(void) printf("\n%s\t*** Bad argument list? ***\n", pri->pname);
9647c478bd9Sstevel@tonic-gate 		return;
9657c478bd9Sstevel@tonic-gate 	}
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate 	(void) printf("  argc = %d\n", nargs);
9687c478bd9Sstevel@tonic-gate 	if (raw)
9698fd04b83SRoger A. Faulkner 		showpaths(pri, &systable[SYS_execve]);
9707c478bd9Sstevel@tonic-gate 
971134a1f4eSCasper H.S. Dik 	show_cred(pri, FALSE, FALSE);
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 	if (aflag || eflag) {		/* dump args or environment */
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate 		/* enter region of (potentially) lengthy output */
9767c478bd9Sstevel@tonic-gate 		Eserialize();
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 		if (aflag)		/* dump the argument list */
9797c478bd9Sstevel@tonic-gate 			dumpargs(pri, ap, "argv:");
9807c478bd9Sstevel@tonic-gate 		ap += (nargs+1) * ptrsize;
9817c478bd9Sstevel@tonic-gate 		if (eflag)		/* dump the environment */
9827c478bd9Sstevel@tonic-gate 			dumpargs(pri, ap, "envp:");
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 		/* exit region of lengthy output */
9857c478bd9Sstevel@tonic-gate 		Xserialize();
9867c478bd9Sstevel@tonic-gate 	}
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate void
dumpargs(private_t * pri,long ap,const char * str)9907c478bd9Sstevel@tonic-gate dumpargs(private_t *pri, long ap, const char *str)
9917c478bd9Sstevel@tonic-gate {
9927c478bd9Sstevel@tonic-gate 	char *string;
9937c478bd9Sstevel@tonic-gate 	unsigned int leng = 0;
9947c478bd9Sstevel@tonic-gate 	int ptrsize;
9957c478bd9Sstevel@tonic-gate 	long arg = 0;
9967c478bd9Sstevel@tonic-gate 	char *argaddr;
9977c478bd9Sstevel@tonic-gate 	char badaddr[32];
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate 	if (interrupt)
10007c478bd9Sstevel@tonic-gate 		return;
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate #ifdef _LP64
10037c478bd9Sstevel@tonic-gate 	if (data_model == PR_MODEL_LP64) {
10047c478bd9Sstevel@tonic-gate 		argaddr = (char *)&arg;
10057c478bd9Sstevel@tonic-gate 		ptrsize = 8;
10067c478bd9Sstevel@tonic-gate 	} else {
10077c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
10087c478bd9Sstevel@tonic-gate 		argaddr = (char *)&arg;
10097c478bd9Sstevel@tonic-gate #else
10107c478bd9Sstevel@tonic-gate 		argaddr = (char *)&arg + 4;
10117c478bd9Sstevel@tonic-gate #endif
10127c478bd9Sstevel@tonic-gate 		ptrsize = 4;
10137c478bd9Sstevel@tonic-gate 	}
10147c478bd9Sstevel@tonic-gate #else
10157c478bd9Sstevel@tonic-gate 	argaddr = (char *)&arg;
10167c478bd9Sstevel@tonic-gate 	ptrsize = 4;
10177c478bd9Sstevel@tonic-gate #endif
10187c478bd9Sstevel@tonic-gate 	putpname(pri);
10197c478bd9Sstevel@tonic-gate 	(void) fputc(' ', stdout);
10207c478bd9Sstevel@tonic-gate 	(void) fputs(str, stdout);
10217c478bd9Sstevel@tonic-gate 	leng += 1 + strlen(str);
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 	while (!interrupt) {
10247c478bd9Sstevel@tonic-gate 		if (Pread(Proc, argaddr, ptrsize, ap) != ptrsize) {
10257c478bd9Sstevel@tonic-gate 			(void) printf("\n%s\t*** Bad argument list? ***\n",
10265403172aSRoger A. Faulkner 			    pri->pname);
10277c478bd9Sstevel@tonic-gate 			return;
10287c478bd9Sstevel@tonic-gate 		}
10297c478bd9Sstevel@tonic-gate 		ap += ptrsize;
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 		if (arg == 0)
10327c478bd9Sstevel@tonic-gate 			break;
10337c478bd9Sstevel@tonic-gate 		string = fetchstring(pri, arg, PATH_MAX);
10347c478bd9Sstevel@tonic-gate 		if (string == NULL) {
10357c478bd9Sstevel@tonic-gate 			(void) sprintf(badaddr, "BadAddress:0x%.8lX", arg);
10367c478bd9Sstevel@tonic-gate 			string = badaddr;
10377c478bd9Sstevel@tonic-gate 		}
10387c478bd9Sstevel@tonic-gate 		if ((leng += strlen(string)) < 63) {
10397c478bd9Sstevel@tonic-gate 			(void) fputc(' ', stdout);
10407c478bd9Sstevel@tonic-gate 			leng++;
10417c478bd9Sstevel@tonic-gate 		} else {
10427c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stdout);
10437c478bd9Sstevel@tonic-gate 			leng = 0;
10447c478bd9Sstevel@tonic-gate 			putpname(pri);
10457c478bd9Sstevel@tonic-gate 			(void) fputs("  ", stdout);
10467c478bd9Sstevel@tonic-gate 			leng += 2 + strlen(string);
10477c478bd9Sstevel@tonic-gate 		}
10487c478bd9Sstevel@tonic-gate 		(void) fputs(string, stdout);
10497c478bd9Sstevel@tonic-gate 	}
10507c478bd9Sstevel@tonic-gate 	(void) fputc('\n', stdout);
10517c478bd9Sstevel@tonic-gate }
10527c478bd9Sstevel@tonic-gate 
10537c478bd9Sstevel@tonic-gate /*
10547c478bd9Sstevel@tonic-gate  * Display contents of read() or write() buffer.
10557c478bd9Sstevel@tonic-gate  */
10567c478bd9Sstevel@tonic-gate void
showbuffer(private_t * pri,long offset,long count)10577c478bd9Sstevel@tonic-gate showbuffer(private_t *pri, long offset, long count)
10587c478bd9Sstevel@tonic-gate {
10597c478bd9Sstevel@tonic-gate 	char buffer[320];
10607c478bd9Sstevel@tonic-gate 	int nbytes;
10617c478bd9Sstevel@tonic-gate 	char *buf;
10627c478bd9Sstevel@tonic-gate 	int n;
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate 	while (count > 0 && !interrupt) {
10657c478bd9Sstevel@tonic-gate 		nbytes = (count < sizeof (buffer))? count : sizeof (buffer);
10667c478bd9Sstevel@tonic-gate 		if ((nbytes = Pread(Proc, buffer, nbytes, offset)) <= 0)
10677c478bd9Sstevel@tonic-gate 			break;
10687c478bd9Sstevel@tonic-gate 		count -= nbytes;
10697c478bd9Sstevel@tonic-gate 		offset += nbytes;
10707c478bd9Sstevel@tonic-gate 		buf = buffer;
10717c478bd9Sstevel@tonic-gate 		while (nbytes > 0 && !interrupt) {
10727c478bd9Sstevel@tonic-gate 			char obuf[65];
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 			n = (nbytes < 32)? nbytes : 32;
10757c478bd9Sstevel@tonic-gate 			showbytes(buf, n, obuf);
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate 			putpname(pri);
10787c478bd9Sstevel@tonic-gate 			(void) fputs("  ", stdout);
10797c478bd9Sstevel@tonic-gate 			(void) fputs(obuf,