xref: /illumos-gate/usr/src/cmd/truss/actions.c (revision 8fd04b83)
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 /*
23*8fd04b83SRoger A. Faulkner  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <stdio.h>
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <memory.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <limits.h>
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
397c478bd9Sstevel@tonic-gate #include <sys/stack.h>
407c478bd9Sstevel@tonic-gate #include <signal.h>
417c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
427c478bd9Sstevel@tonic-gate #include <libproc.h>
437c478bd9Sstevel@tonic-gate #include <priv.h>
447c478bd9Sstevel@tonic-gate #include "ramdata.h"
457c478bd9Sstevel@tonic-gate #include "systable.h"
467c478bd9Sstevel@tonic-gate #include "print.h"
477c478bd9Sstevel@tonic-gate #include "proto.h"
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Actions to take when process stops.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * Function prototypes for static routines in this module.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate int	stopsig(private_t *);
577c478bd9Sstevel@tonic-gate void	showpaths(private_t *, const struct systable *);
587c478bd9Sstevel@tonic-gate void	showargs(private_t *, int);
597c478bd9Sstevel@tonic-gate void	dumpargs(private_t *, long, const char *);
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Report an lwp to be sleeping (if true).
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate void
657c478bd9Sstevel@tonic-gate report_sleeping(private_t *pri, int dotrace)
667c478bd9Sstevel@tonic-gate {
677c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
687c478bd9Sstevel@tonic-gate 	int sys = Lsp->pr_syscall;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	if (!prismember(&trace, sys) || !dotrace ||
717c478bd9Sstevel@tonic-gate 	    !(Lsp->pr_flags & (PR_ASLEEP|PR_VFORKP))) {
727c478bd9Sstevel@tonic-gate 		/* Make sure we catch sysexit even if we're not tracing it. */
737c478bd9Sstevel@tonic-gate 		(void) Psysexit(Proc, sys, TRUE);
747c478bd9Sstevel@tonic-gate 		return;
757c478bd9Sstevel@tonic-gate 	}
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	pri->length = 0;
787c478bd9Sstevel@tonic-gate 	pri->Errno = 0;
797c478bd9Sstevel@tonic-gate 	pri->ErrPriv = PRIV_NONE;
807c478bd9Sstevel@tonic-gate 	pri->Rval1 = pri->Rval2 = 0;
817c478bd9Sstevel@tonic-gate 	(void) sysentry(pri, dotrace);
827c478bd9Sstevel@tonic-gate 	make_pname(pri, 0);
837c478bd9Sstevel@tonic-gate 	putpname(pri);
847c478bd9Sstevel@tonic-gate 	timestamp(pri);
857c478bd9Sstevel@tonic-gate 	pri->length += printf("%s", pri->sys_string);
867c478bd9Sstevel@tonic-gate 	pri->sys_leng = 0;
877c478bd9Sstevel@tonic-gate 	*pri->sys_string = '\0';
887c478bd9Sstevel@tonic-gate 	pri->length >>= 3;
897c478bd9Sstevel@tonic-gate 	if (Lsp->pr_flags & PR_VFORKP)
907c478bd9Sstevel@tonic-gate 		pri->length += 2;
917c478bd9Sstevel@tonic-gate 	if (pri->length >= 4)
927c478bd9Sstevel@tonic-gate 		(void) fputc(' ', stdout);
937c478bd9Sstevel@tonic-gate 	for (; pri->length < 4; pri->length++)
947c478bd9Sstevel@tonic-gate 		(void) fputc('\t', stdout);
957c478bd9Sstevel@tonic-gate 	if (Lsp->pr_flags & PR_VFORKP)
967c478bd9Sstevel@tonic-gate 		(void) fputs("(waiting for child to exit()/exec()...)\n",
975403172aSRoger A. Faulkner 		    stdout);
987c478bd9Sstevel@tonic-gate 	else
997c478bd9Sstevel@tonic-gate 		(void) fputs("(sleeping...)\n", stdout);
1007c478bd9Sstevel@tonic-gate 	pri->length = 0;
1017c478bd9Sstevel@tonic-gate 	if (prismember(&verbose, sys)) {
1027c478bd9Sstevel@tonic-gate 		int raw = prismember(&rawout, sys);
1037c478bd9Sstevel@tonic-gate 		pri->Errno = 1;
1047c478bd9Sstevel@tonic-gate 		expound(pri, 0, raw);
1057c478bd9Sstevel@tonic-gate 		pri->Errno = 0;
1067c478bd9Sstevel@tonic-gate 	}
1077c478bd9Sstevel@tonic-gate 	Flush();
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * requested() gets called for these reasons:
1127c478bd9Sstevel@tonic-gate  *	flag == JOBSIG:		report nothing; change state to JOBSTOP
1137c478bd9Sstevel@tonic-gate  *	flag == JOBSTOP:	report "Continued ..."
1147c478bd9Sstevel@tonic-gate  *	default:		report sleeping system call
1157c478bd9Sstevel@tonic-gate  *
1167c478bd9Sstevel@tonic-gate  * It returns a new flag:  JOBSTOP or SLEEPING or 0.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate int
1197c478bd9Sstevel@tonic-gate requested(private_t *pri, int flag, int dotrace)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
1227c478bd9Sstevel@tonic-gate 	int sig = Lsp->pr_cursig;
1237c478bd9Sstevel@tonic-gate 	int newflag = 0;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	switch (flag) {
1267c478bd9Sstevel@tonic-gate 	case JOBSIG:
1277c478bd9Sstevel@tonic-gate 		return (JOBSTOP);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	case JOBSTOP:
1307c478bd9Sstevel@tonic-gate 		if (dotrace && !cflag && prismember(&signals, sig)) {
1317c478bd9Sstevel@tonic-gate 			pri->length = 0;
1327c478bd9Sstevel@tonic-gate 			putpname(pri);
1337c478bd9Sstevel@tonic-gate 			timestamp(pri);
1347c478bd9Sstevel@tonic-gate 			(void) printf("    Continued with signal #%d, %s",
1355403172aSRoger A. Faulkner 			    sig, signame(pri, sig));
1367c478bd9Sstevel@tonic-gate 			if (Lsp->pr_action.sa_handler == SIG_DFL)
1377c478bd9Sstevel@tonic-gate 				(void) printf(" [default]");
1387c478bd9Sstevel@tonic-gate 			else if (Lsp->pr_action.sa_handler == SIG_IGN)
1397c478bd9Sstevel@tonic-gate 				(void) printf(" [ignored]");
1407c478bd9Sstevel@tonic-gate 			else
1417c478bd9Sstevel@tonic-gate 				(void) printf(" [caught]");
1427c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stdout);
1437c478bd9Sstevel@tonic-gate 			Flush();
1447c478bd9Sstevel@tonic-gate 		}
1457c478bd9Sstevel@tonic-gate 		newflag = 0;
1467c478bd9Sstevel@tonic-gate 		break;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	default:
1497c478bd9Sstevel@tonic-gate 		newflag = SLEEPING;
1507c478bd9Sstevel@tonic-gate 		if (!cflag)
1517c478bd9Sstevel@tonic-gate 			report_sleeping(pri, dotrace);
1527c478bd9Sstevel@tonic-gate 		break;
1537c478bd9Sstevel@tonic-gate 	}
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	return (newflag);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate int
1597c478bd9Sstevel@tonic-gate jobcontrol(private_t *pri, int dotrace)
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
1627c478bd9Sstevel@tonic-gate 	int sig = stopsig(pri);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if (sig == 0)
1657c478bd9Sstevel@tonic-gate 		return (0);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	if (dotrace && !cflag &&		/* not just counting */
1687c478bd9Sstevel@tonic-gate 	    prismember(&signals, sig)) {	/* tracing this signal */
1697c478bd9Sstevel@tonic-gate 		int sys;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 		pri->length = 0;
1727c478bd9Sstevel@tonic-gate 		putpname(pri);
1737c478bd9Sstevel@tonic-gate 		timestamp(pri);
1747c478bd9Sstevel@tonic-gate 		(void) printf("    Stopped by signal #%d, %s",
1755403172aSRoger A. Faulkner 		    sig, signame(pri, sig));
1767c478bd9Sstevel@tonic-gate 		if ((Lsp->pr_flags & PR_ASLEEP) &&
1777c478bd9Sstevel@tonic-gate 		    (sys = Lsp->pr_syscall) > 0 && sys <= PRMAXSYS)
1787c478bd9Sstevel@tonic-gate 			(void) printf(", in %s()",
1795403172aSRoger A. Faulkner 			    sysname(pri, sys, getsubcode(pri)));
1807c478bd9Sstevel@tonic-gate 		(void) fputc('\n', stdout);
1817c478bd9Sstevel@tonic-gate 		Flush();
1827c478bd9Sstevel@tonic-gate 	}
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	return (JOBSTOP);
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * Return the signal the process stopped on iff process is already stopped on
1897c478bd9Sstevel@tonic-gate  * PR_JOBCONTROL or is stopped on PR_SIGNALLED or PR_REQUESTED with a current
1907c478bd9Sstevel@tonic-gate  * signal that will cause a JOBCONTROL stop when the process is set running.
1917c478bd9Sstevel@tonic-gate  */
1927c478bd9Sstevel@tonic-gate int
1937c478bd9Sstevel@tonic-gate stopsig(private_t *pri)
1947c478bd9Sstevel@tonic-gate {
1957c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
1967c478bd9Sstevel@tonic-gate 	int sig = 0;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if (Lsp->pr_flags & PR_STOPPED) {
1997c478bd9Sstevel@tonic-gate 		switch (Lsp->pr_why) {
2007c478bd9Sstevel@tonic-gate 		case PR_JOBCONTROL:
2017c478bd9Sstevel@tonic-gate 			sig = Lsp->pr_what;
2027c478bd9Sstevel@tonic-gate 			if (sig < 0 || sig > PRMAXSIG)
2037c478bd9Sstevel@tonic-gate 				sig = 0;
2047c478bd9Sstevel@tonic-gate 			break;
2057c478bd9Sstevel@tonic-gate 		case PR_SIGNALLED:
2067c478bd9Sstevel@tonic-gate 		case PR_REQUESTED:
2077c478bd9Sstevel@tonic-gate 			if (Lsp->pr_action.sa_handler == SIG_DFL) {
2087c478bd9Sstevel@tonic-gate 				switch (Lsp->pr_cursig) {
2097c478bd9Sstevel@tonic-gate 				case SIGSTOP:
2107c478bd9Sstevel@tonic-gate 					sig = SIGSTOP;
2117c478bd9Sstevel@tonic-gate 					break;
2127c478bd9Sstevel@tonic-gate 				case SIGTSTP:
2137c478bd9Sstevel@tonic-gate 				case SIGTTIN:
2147c478bd9Sstevel@tonic-gate 				case SIGTTOU:
2157c478bd9Sstevel@tonic-gate 					if (!(Lsp->pr_flags & PR_ORPHAN))
2167c478bd9Sstevel@tonic-gate 						sig = Lsp->pr_cursig;
2177c478bd9Sstevel@tonic-gate 					break;
2187c478bd9Sstevel@tonic-gate 				}
2197c478bd9Sstevel@tonic-gate 			}
2207c478bd9Sstevel@tonic-gate 			break;
2217c478bd9Sstevel@tonic-gate 		}
2227c478bd9Sstevel@tonic-gate 	}
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	return (sig);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate int
2287c478bd9Sstevel@tonic-gate signalled(private_t *pri, int flag, int dotrace)
2297c478bd9Sstevel@tonic-gate {
2307c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
2317c478bd9Sstevel@tonic-gate 	int sig = Lsp->pr_what;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	if (sig <= 0 || sig > PRMAXSIG)	/* check bounds */
2347c478bd9Sstevel@tonic-gate 		return (0);
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	if (dotrace && cflag) {			/* just counting */
2377c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&count_lock);
2387c478bd9Sstevel@tonic-gate 		Cp->sigcount[sig]++;
2397c478bd9Sstevel@tonic-gate 		(void) mutex_unlock(&count_lock);
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	if (sig == SIGCONT && (flag == JOBSIG || flag == JOBSTOP))
2437c478bd9Sstevel@tonic-gate 		flag = requested(pri, JOBSTOP, dotrace);
2447c478bd9Sstevel@tonic-gate 	else if ((flag = jobcontrol(pri, dotrace)) == 0 &&
2457c478bd9Sstevel@tonic-gate 	    !cflag && dotrace &&
2467c478bd9Sstevel@tonic-gate 	    prismember(&signals, sig)) {
2477c478bd9Sstevel@tonic-gate 		int sys;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 		pri->length = 0;
2507c478bd9Sstevel@tonic-gate 		putpname(pri);
2517c478bd9Sstevel@tonic-gate 		timestamp(pri);
2527c478bd9Sstevel@tonic-gate 		(void) printf("    Received signal #%d, %s",
2535403172aSRoger A. Faulkner 		    sig, signame(pri, sig));
2547c478bd9Sstevel@tonic-gate 		if ((Lsp->pr_flags & PR_ASLEEP) &&
2557c478bd9Sstevel@tonic-gate 		    (sys = Lsp->pr_syscall) > 0 && sys <= PRMAXSYS)
2567c478bd9Sstevel@tonic-gate 			(void) printf(", in %s()",
2575403172aSRoger A. Faulkner 			    sysname(pri, sys, getsubcode(pri)));
2587c478bd9Sstevel@tonic-gate 		if (Lsp->pr_action.sa_handler == SIG_DFL)
2597c478bd9Sstevel@tonic-gate 			(void) printf(" [default]");
2607c478bd9Sstevel@tonic-gate 		else if (Lsp->pr_action.sa_handler == SIG_IGN)
2617c478bd9Sstevel@tonic-gate 			(void) printf(" [ignored]");
2627c478bd9Sstevel@tonic-gate 		else
2637c478bd9Sstevel@tonic-gate 			(void) printf(" [caught]");
2647c478bd9Sstevel@tonic-gate 		(void) fputc('\n', stdout);
2657c478bd9Sstevel@tonic-gate 		if (Lsp->pr_info.si_code != 0 ||
2667c478bd9Sstevel@tonic-gate 		    Lsp->pr_info.si_pid != 0)
2677c478bd9Sstevel@tonic-gate 			print_siginfo(pri, &Lsp->pr_info);
2687c478bd9Sstevel@tonic-gate 		Flush();
2697c478bd9Sstevel@tonic-gate 	}
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	if (flag == JOBSTOP)
2727c478bd9Sstevel@tonic-gate 		flag = JOBSIG;
2737c478bd9Sstevel@tonic-gate 	return (flag);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate int
2777c478bd9Sstevel@tonic-gate faulted(private_t *pri, int dotrace)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
2807c478bd9Sstevel@tonic-gate 	int flt = Lsp->pr_what;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	if ((uint_t)flt > PRMAXFAULT || !prismember(&faults, flt) || !dotrace)
2837c478bd9Sstevel@tonic-gate 		return (0);
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	(void) mutex_lock(&count_lock);
2867c478bd9Sstevel@tonic-gate 	Cp->fltcount[flt]++;
2877c478bd9Sstevel@tonic-gate 	(void) mutex_unlock(&count_lock);
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	if (cflag)		/* just counting */
2907c478bd9Sstevel@tonic-gate 		return (1);
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	pri->length = 0;
2937c478bd9Sstevel@tonic-gate 	putpname(pri);
2947c478bd9Sstevel@tonic-gate 	timestamp(pri);
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	(void) printf("    Incurred fault #%d, %s  %%pc = 0x%.8lX",
2975403172aSRoger A. Faulkner 	    flt, proc_fltname(flt, pri->flt_name, sizeof (pri->flt_name)),
2985403172aSRoger A. Faulkner 	    (long)Lsp->pr_reg[R_PC]);
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	if (flt == FLTPAGE)
3017c478bd9Sstevel@tonic-gate 		(void) printf("  addr = 0x%.8lX",
3025403172aSRoger A. Faulkner 		    (long)Lsp->pr_info.si_addr);
3037c478bd9Sstevel@tonic-gate 	(void) fputc('\n', stdout);
3047c478bd9Sstevel@tonic-gate 	if (Lsp->pr_info.si_signo != 0)
3057c478bd9Sstevel@tonic-gate 		print_siginfo(pri, &Lsp->pr_info);
3067c478bd9Sstevel@tonic-gate 	Flush();
3077c478bd9Sstevel@tonic-gate 	return (1);
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate  * Set up pri->sys_nargs and pri->sys_args[] (syscall args).
3127c478bd9Sstevel@tonic-gate  */
3137c478bd9Sstevel@tonic-gate void
3147c478bd9Sstevel@tonic-gate setupsysargs(private_t *pri, int what)
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
3177c478bd9Sstevel@tonic-gate 	int nargs;
3187c478bd9Sstevel@tonic-gate 	int i;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate #if sparc
3217c478bd9Sstevel@tonic-gate 	/* determine whether syscall is indirect */
3227c478bd9Sstevel@tonic-gate 	pri->sys_indirect = (Lsp->pr_reg[R_G1] == SYS_syscall)? 1 : 0;
3237c478bd9Sstevel@tonic-gate #else
3247c478bd9Sstevel@tonic-gate 	pri->sys_indirect = 0;
3257c478bd9Sstevel@tonic-gate #endif
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	(void) memset(pri->sys_args, 0, sizeof (pri->sys_args));
3287c478bd9Sstevel@tonic-gate 	if (what != Lsp->pr_syscall) {	/* assertion */
3297c478bd9Sstevel@tonic-gate 		(void) printf("%s\t*** Inconsistent syscall: %d vs %d ***\n",
3305403172aSRoger A. Faulkner 		    pri->pname, what, Lsp->pr_syscall);
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 	nargs = Lsp->pr_nsysarg;
3337c478bd9Sstevel@tonic-gate 	for (i = 0;
3347c478bd9Sstevel@tonic-gate 	    i < nargs && i < sizeof (pri->sys_args) / sizeof (pri->sys_args[0]);
3357c478bd9Sstevel@tonic-gate 	    i++)
3367c478bd9Sstevel@tonic-gate 		pri->sys_args[i] = Lsp->pr_sysarg[i];
3377c478bd9Sstevel@tonic-gate 	pri->sys_nargs = nargs;
3387c478bd9Sstevel@tonic-gate }
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate #define	ISREAD(code) \
3417c478bd9Sstevel@tonic-gate 	((code) == SYS_read || (code) == SYS_pread || \
3427c478bd9Sstevel@tonic-gate 	(code) == SYS_pread64 || (code) == SYS_readv || \
3437c478bd9Sstevel@tonic-gate 	(code) == SYS_recv || (code) == SYS_recvfrom)
3447c478bd9Sstevel@tonic-gate #define	ISWRITE(code) \
3457c478bd9Sstevel@tonic-gate 	((code) == SYS_write || (code) == SYS_pwrite || \
3467c478bd9Sstevel@tonic-gate 	(code) == SYS_pwrite64 || (code) == SYS_writev || \
3477c478bd9Sstevel@tonic-gate 	(code) == SYS_send || (code) == SYS_sendto)
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate  * Return TRUE iff syscall is being traced.
3517c478bd9Sstevel@tonic-gate  */
3527c478bd9Sstevel@tonic-gate int
3537c478bd9Sstevel@tonic-gate sysentry(private_t *pri, int dotrace)
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate 	pid_t pid = Pstatus(Proc)->pr_pid;
3567c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
3577c478bd9Sstevel@tonic-gate 	long arg;
3587c478bd9Sstevel@tonic-gate 	int nargs;
3597c478bd9Sstevel@tonic-gate 	int i;
3607c478bd9Sstevel@tonic-gate 	int x;
3617c478bd9Sstevel@tonic-gate 	int len;
3627c478bd9Sstevel@tonic-gate 	char *s;
3637c478bd9Sstevel@tonic-gate 	const struct systable *stp;
3647c478bd9Sstevel@tonic-gate 	int what = Lsp->pr_what;
3657c478bd9Sstevel@tonic-gate 	int subcode;
3667c478bd9Sstevel@tonic-gate 	int istraced;
3677c478bd9Sstevel@tonic-gate 	int raw;
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 	/* for reporting sleeping system calls */
3707c478bd9Sstevel@tonic-gate 	if (what == 0 && (Lsp->pr_flags & (PR_ASLEEP|PR_VFORKP)))
3717c478bd9Sstevel@tonic-gate 		what = Lsp->pr_syscall;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	/* protect ourself from operating system error */
3747c478bd9Sstevel@tonic-gate 	if (what <= 0 || what > PRMAXSYS)
3757c478bd9Sstevel@tonic-gate 		what = 0;
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	/*
3787c478bd9Sstevel@tonic-gate 	 * Set up the system call arguments (pri->sys_nargs & pri->sys_args[]).
3797c478bd9Sstevel@tonic-gate 	 */
3807c478bd9Sstevel@tonic-gate 	setupsysargs(pri, what);
3817c478bd9Sstevel@tonic-gate 	nargs = pri->sys_nargs;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	/* get systable entry for this syscall */
3847c478bd9Sstevel@tonic-gate 	subcode = getsubcode(pri);
3857c478bd9Sstevel@tonic-gate 	stp = subsys(what, subcode);
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	if (nargs > stp->nargs)
3887c478bd9Sstevel@tonic-gate 		nargs = stp->nargs;
3897c478bd9Sstevel@tonic-gate 	pri->sys_nargs = nargs;
3907c478bd9Sstevel@tonic-gate 
391*8fd04b83SRoger A. Faulkner 	/*
392*8fd04b83SRoger A. Faulkner 	 * Fetch and remember first argument if it's a string,
393*8fd04b83SRoger A. Faulkner 	 * or second argument if SYS_openat or SYS_openat64.
394*8fd04b83SRoger A. Faulkner 	 */
3957c478bd9Sstevel@tonic-gate 	pri->sys_valid = FALSE;
396*8fd04b83SRoger A. Faulkner 	if ((nargs > 0 && stp->arg[0] == STG) ||
397*8fd04b83SRoger A. Faulkner 	    (nargs > 1 && (what == SYS_openat || what == SYS_openat64))) {
3987c478bd9Sstevel@tonic-gate 		long offset;
3997c478bd9Sstevel@tonic-gate 		uint32_t offset32;
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 		/*
4027c478bd9Sstevel@tonic-gate 		 * Special case for exit from exec().
4037c478bd9Sstevel@tonic-gate 		 * The address in pri->sys_args[0] refers to the old process
4047c478bd9Sstevel@tonic-gate 		 * image.  We must fetch the string from the new image.
4057c478bd9Sstevel@tonic-gate 		 */
406*8fd04b83SRoger A. Faulkner 		if (Lsp->pr_why == PR_SYSEXIT && what == SYS_execve) {
4077c478bd9Sstevel@tonic-gate 			psinfo_t psinfo;
4087c478bd9Sstevel@tonic-gate 			long argv;
4097c478bd9Sstevel@tonic-gate 			auxv_t auxv[32];
4107c478bd9Sstevel@tonic-gate 			int naux;
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 			offset = 0;
4137c478bd9Sstevel@tonic-gate 			naux = proc_get_auxv(pid, auxv, 32);
4147c478bd9Sstevel@tonic-gate 			for (i = 0; i < naux; i++) {
4157c478bd9Sstevel@tonic-gate 				if (auxv[i].a_type == AT_SUN_EXECNAME) {
4167c478bd9Sstevel@tonic-gate 					offset = (long)auxv[i].a_un.a_ptr;
4177c478bd9Sstevel@tonic-gate 					break;
4187c478bd9Sstevel@tonic-gate 				}
4197c478bd9Sstevel@tonic-gate 			}
4207c478bd9Sstevel@tonic-gate 			if (offset == 0 &&
4217c478bd9Sstevel@tonic-gate 			    proc_get_psinfo(pid, &psinfo) == 0) {
4227c478bd9Sstevel@tonic-gate 				argv = (long)psinfo.pr_argv;
4237c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_LP64)
4247c478bd9Sstevel@tonic-gate 					(void) Pread(Proc, &offset,
4255403172aSRoger A. Faulkner 					    sizeof (offset), argv);
4267c478bd9Sstevel@tonic-gate 				else {
4277c478bd9Sstevel@tonic-gate 					offset32 = 0;
4287c478bd9Sstevel@tonic-gate 					(void) Pread(Proc, &offset32,
4295403172aSRoger A. Faulkner 					    sizeof (offset32), argv);
4307c478bd9Sstevel@tonic-gate 					offset = offset32;
4317c478bd9Sstevel@tonic-gate 				}
4327c478bd9Sstevel@tonic-gate 			}
433*8fd04b83SRoger A. Faulkner 		} else if (stp->arg[0] == STG) {
4347c478bd9Sstevel@tonic-gate 			offset = pri->sys_args[0];
435*8fd04b83SRoger A. Faulkner 		} else {
436*8fd04b83SRoger A. Faulkner 			offset = pri->sys_args[1];
4377c478bd9Sstevel@tonic-gate 		}
4387c478bd9Sstevel@tonic-gate 		if ((s = fetchstring(pri, offset, PATH_MAX)) != NULL) {
4397c478bd9Sstevel@tonic-gate 			pri->sys_valid = TRUE;
4407c478bd9Sstevel@tonic-gate 			len = strlen(s);
4417c478bd9Sstevel@tonic-gate 			/* reallocate if necessary */
4427c478bd9Sstevel@tonic-gate 			while (len >= pri->sys_psize) {
4437c478bd9Sstevel@tonic-gate 				free(pri->sys_path);
4447c478bd9Sstevel@tonic-gate 				pri->sys_path = my_malloc(pri->sys_psize *= 2,
4455403172aSRoger A. Faulkner 				    "pathname buffer");
4467c478bd9Sstevel@tonic-gate 			}
4477c478bd9Sstevel@tonic-gate 			(void) strcpy(pri->sys_path, s); /* remember pathname */
4487c478bd9Sstevel@tonic-gate 		}
4497c478bd9Sstevel@tonic-gate 	}
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	istraced = dotrace && prismember(&trace, what);
4527c478bd9Sstevel@tonic-gate 	raw = prismember(&rawout, what);
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 	/* force tracing of read/write buffer dump syscalls */
4557c478bd9Sstevel@tonic-gate 	if (!istraced && nargs > 2) {
4567c478bd9Sstevel@tonic-gate 		int fdp1 = (int)pri->sys_args[0] + 1;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 		if (ISREAD(what)) {
4597c478bd9Sstevel@tonic-gate 			if (prismember(&readfd, fdp1))
4607c478bd9Sstevel@tonic-gate 				istraced = TRUE;
4617c478bd9Sstevel@tonic-gate 		} else if (ISWRITE(what)) {
4627c478bd9Sstevel@tonic-gate 			if (prismember(&writefd, fdp1))
4637c478bd9Sstevel@tonic-gate 				istraced = TRUE;
4647c478bd9Sstevel@tonic-gate 		}
4657c478bd9Sstevel@tonic-gate 	}
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	pri->sys_leng = 0;
4687c478bd9Sstevel@tonic-gate 	if (cflag || !istraced)		/* just counting */
4697c478bd9Sstevel@tonic-gate 		*pri->sys_string = 0;
4707c478bd9Sstevel@tonic-gate 	else {
4717c478bd9Sstevel@tonic-gate 		int argprinted = FALSE;
4727c478bd9Sstevel@tonic-gate 		const char *name;
4737c478bd9Sstevel@tonic-gate 
474657b1f3dSraf 		name = sysname(pri, what, raw? -1 : subcode);
4757c478bd9Sstevel@tonic-gate 		grow(pri, strlen(name) + 1);
4767c478bd9Sstevel@tonic-gate 		pri->sys_leng = snprintf(pri->sys_string, pri->sys_ssize,
4775403172aSRoger A. Faulkner 		    "%s(", name);
4787c478bd9Sstevel@tonic-gate 		for (i = 0; i < nargs; i++) {
4797c478bd9Sstevel@tonic-gate 			arg = pri->sys_args[i];
4807c478bd9Sstevel@tonic-gate 			x = stp->arg[i];
4817c478bd9Sstevel@tonic-gate 
482*8fd04b83SRoger A. Faulkner 			if (!raw && pri->sys_valid &&
483*8fd04b83SRoger A. Faulkner 			    ((i == 0 && x == STG) ||
484*8fd04b83SRoger A. Faulkner 			    (i == 1 && (what == SYS_openat ||
485*8fd04b83SRoger A. Faulkner 			    what == SYS_openat64)))) {	/* already fetched */
4867c478bd9Sstevel@tonic-gate 				escape_string(pri, pri->sys_path);
4877c478bd9Sstevel@tonic-gate 				argprinted = TRUE;
4887c478bd9Sstevel@tonic-gate 			} else if (x != HID || raw) {
4897c478bd9Sstevel@tonic-gate 				if (argprinted)
4907c478bd9Sstevel@tonic-gate 					outstring(pri, ", ");
4917c478bd9Sstevel@tonic-gate 				if (x == LLO)
4927c478bd9Sstevel@tonic-gate 					(*Print[x])(pri, raw, arg,
4935403172aSRoger A. Faulkner 					    pri->sys_args[++i]);
4947c478bd9Sstevel@tonic-gate 				else
4957c478bd9Sstevel@tonic-gate 					(*Print[x])(pri, raw, arg);
4967c478bd9Sstevel@tonic-gate 				/*
4977c478bd9Sstevel@tonic-gate 				 * if nothing printed, then don't print ", "
4987c478bd9Sstevel@tonic-gate 				 */
4997c478bd9Sstevel@tonic-gate 				if (x == NOV)
5007c478bd9Sstevel@tonic-gate 					argprinted = FALSE;
5017c478bd9Sstevel@tonic-gate 				else
5027c478bd9Sstevel@tonic-gate 					argprinted = TRUE;
5037c478bd9Sstevel@tonic-gate 			}
5047c478bd9Sstevel@tonic-gate 		}
5057c478bd9Sstevel@tonic-gate 		outstring(pri, ")");
5067c478bd9Sstevel@tonic-gate 	}
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	return (istraced);
5097c478bd9Sstevel@tonic-gate }
5107c478bd9Sstevel@tonic-gate #undef	ISREAD
5117c478bd9Sstevel@tonic-gate #undef	ISWRITE
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate /*
5147c478bd9Sstevel@tonic-gate  * sysexit() returns non-zero if anything was printed.
5157c478bd9Sstevel@tonic-gate  */
5167c478bd9Sstevel@tonic-gate int
5177c478bd9Sstevel@tonic-gate sysexit(private_t *pri, int dotrace)
5187c478bd9Sstevel@tonic-gate {
5197c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
5207c478bd9Sstevel@tonic-gate 	int what = Lsp->pr_what;
5217c478bd9Sstevel@tonic-gate 	struct syscount *scp;
5227c478bd9Sstevel@tonic-gate 	const struct systable *stp;
5237c478bd9Sstevel@tonic-gate 	int subcode;
5247c478bd9Sstevel@tonic-gate 	int istraced;
5257c478bd9Sstevel@tonic-gate 	int raw;
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	/* protect ourself from operating system error */
5287c478bd9Sstevel@tonic-gate 	if (what <= 0 || what > PRMAXSYS)
5297c478bd9Sstevel@tonic-gate 		return (0);
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	/*
5327c478bd9Sstevel@tonic-gate 	 * If we aren't supposed to be tracing this one, then
5337c478bd9Sstevel@tonic-gate 	 * delete it from the traced signal set.  We got here
5347c478bd9Sstevel@tonic-gate 	 * because the process was sleeping in an untraced syscall.
5357c478bd9Sstevel@tonic-gate 	 */
5367c478bd9Sstevel@tonic-gate 	if (!prismember(&traceeven, what)) {
5377c478bd9Sstevel@tonic-gate 		(void) Psysexit(Proc, what, FALSE);
5387c478bd9Sstevel@tonic-gate 		return (0);
5397c478bd9Sstevel@tonic-gate 	}
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 	/* pick up registers & set pri->Errno before anything else */
5427c478bd9Sstevel@tonic-gate 	pri->Errno = Lsp->pr_errno;
5437c478bd9Sstevel@tonic-gate 	pri->ErrPriv = Lsp->pr_errpriv;
5447c478bd9Sstevel@tonic-gate 	pri->Rval1 = Lsp->pr_rval1;
5457c478bd9Sstevel@tonic-gate 	pri->Rval2 = Lsp->pr_rval2;
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 	switch (what) {
5487c478bd9Sstevel@tonic-gate 	case SYS_exit:		/* these are traced on entry */
5497c478bd9Sstevel@tonic-gate 	case SYS_lwp_exit:
5507c478bd9Sstevel@tonic-gate 	case SYS_context:
5517c478bd9Sstevel@tonic-gate 		istraced = dotrace && prismember(&trace, what);
5527c478bd9Sstevel@tonic-gate 		break;
553*8fd04b83SRoger A. Faulkner 	case SYS_execve:	/* this is normally traced on entry */
5547c478bd9Sstevel@tonic-gate 		istraced = dotrace && prismember(&trace, what);
5557c478bd9Sstevel@tonic-gate 		if (pri->exec_string && *pri->exec_string) {
5567c478bd9Sstevel@tonic-gate 			if (!cflag && istraced) { /* print exec() string now */
5577c478bd9Sstevel@tonic-gate 				if (pri->exec_pname[0] != '\0')
5587c478bd9Sstevel@tonic-gate 					(void) fputs(pri->exec_pname, stdout);
5597c478bd9Sstevel@tonic-gate 				timestamp(pri);
5607c478bd9Sstevel@tonic-gate 				(void) fputs(pri->exec_string, stdout);
5617c478bd9Sstevel@tonic-gate 			}
5627c478bd9Sstevel@tonic-gate 			pri->exec_pname[0] = '\0';
5637c478bd9Sstevel@tonic-gate 			pri->exec_string[0] = '\0';
5647c478bd9Sstevel@tonic-gate 			break;
5657c478bd9Sstevel@tonic-gate 		}
5667c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
5677c478bd9Sstevel@tonic-gate 	default:
5687c478bd9Sstevel@tonic-gate 		/* we called sysentry() in main() for these */
569*8fd04b83SRoger A. Faulkner 		if (what == SYS_openat || what == SYS_openat64 ||
570*8fd04b83SRoger A. Faulkner 		    what == SYS_open || what == SYS_open64)
5717c478bd9Sstevel@tonic-gate 			istraced = dotrace && prismember(&trace, what);
5727c478bd9Sstevel@tonic-gate 		else
5737c478bd9Sstevel@tonic-gate 			istraced = sysentry(pri, dotrace) && dotrace;
5747c478bd9Sstevel@tonic-gate 		pri->length = 0;
5757c478bd9Sstevel@tonic-gate 		if (!cflag && istraced) {
5767c478bd9Sstevel@tonic-gate 			putpname(pri);
5777c478bd9Sstevel@tonic-gate 			timestamp(pri);
5787c478bd9Sstevel@tonic-gate 			pri->length += printf("%s", pri->sys_string);
5797c478bd9Sstevel@tonic-gate 		}
5807c478bd9Sstevel@tonic-gate 		pri->sys_leng = 0;
5817c478bd9Sstevel@tonic-gate 		*pri->sys_string = '\0';
5827c478bd9Sstevel@tonic-gate 		break;
5837c478bd9Sstevel@tonic-gate 	}
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	/* get systable entry for this syscall */
5867c478bd9Sstevel@tonic-gate 	subcode = getsubcode(pri);
5877c478bd9Sstevel@tonic-gate 	stp = subsys(what, subcode);
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 	if (cflag && istraced) {
5907c478bd9Sstevel@tonic-gate 		(void) mutex_lock(&count_lock);
5917c478bd9Sstevel@tonic-gate 		scp = Cp->syscount[what];
592657b1f3dSraf 		if (what == SYS_forksys && subcode >= 3)
593657b1f3dSraf 			scp += subcode - 3;
594657b1f3dSraf 		else if (subcode != -1 &&
595*8fd04b83SRoger A. Faulkner 		    (what != SYS_openat && what != SYS_openat64 &&
596*8fd04b83SRoger A. Faulkner 		    what != SYS_open && what != SYS_open64 &&
5977c478bd9Sstevel@tonic-gate 		    what != SYS_lwp_create))
5987c478bd9Sstevel@tonic-gate 			scp += subcode;
5997c478bd9Sstevel@tonic-gate 		scp->count++;
6007c478bd9Sstevel@tonic-gate 		accumulate(&scp->stime, &Lsp->pr_stime, &pri->syslast);
6017c478bd9Sstevel@tonic-gate 		accumulate(&Cp->usrtotal, &Lsp->pr_utime, &pri->usrlast);
6027c478bd9Sstevel@tonic-gate 		pri->syslast = Lsp->pr_stime;
6037c478bd9Sstevel@tonic-gate 		pri->usrlast = Lsp->pr_utime;
6047c478bd9Sstevel@tonic-gate 		(void) mutex_unlock(&count_lock);
6057c478bd9Sstevel@tonic-gate 	}
6067c478bd9Sstevel@tonic-gate 
607657b1f3dSraf 	raw = prismember(&rawout, what);
608657b1f3dSraf 
6097c478bd9Sstevel@tonic-gate 	if (!cflag && istraced) {
610*8fd04b83SRoger A. Faulkner 		if ((what == SYS_vfork || what == SYS_forksys) &&
6117c478bd9Sstevel@tonic-gate 		    pri->Errno == 0 && pri->Rval2 != 0) {
6127c478bd9Sstevel@tonic-gate 			pri->length &= ~07;
613657b1f3dSraf 			if (strlen(sysname(pri, what, raw? -1 : subcode)) < 6) {
6147c478bd9Sstevel@tonic-gate 				(void) fputc('\t', stdout);
615657b1f3dSraf 				pri->length += 8;
616657b1f3dSraf 			}
6177c478bd9Sstevel@tonic-gate 			pri->length +=
6185403172aSRoger A. Faulkner 			    7 + printf("\t(returning as child ...)");
6197c478bd9Sstevel@tonic-gate 		}
6207c478bd9Sstevel@tonic-gate 		if (what == SYS_lwp_create &&
6217c478bd9Sstevel@tonic-gate 		    pri->Errno == 0 && pri->Rval1 == 0) {
6227c478bd9Sstevel@tonic-gate 			pri->length &= ~07;
6237c478bd9Sstevel@tonic-gate 			pri->length +=
6245403172aSRoger A. Faulkner 			    7 + printf("\t(returning as new lwp ...)");
6257c478bd9Sstevel@tonic-gate 		}
626*8fd04b83SRoger A. Faulkner 		if (pri->Errno != 0 || what != SYS_execve) {
6277c478bd9Sstevel@tonic-gate 			/* prepare to print the return code */
6287c478bd9Sstevel@tonic-gate 			pri->length >>= 3;
6297c478bd9Sstevel@tonic-gate 			if (pri->length >= 6)
6307c478bd9Sstevel@tonic-gate 				(void) fputc(' ', stdout);
6317c478bd9Sstevel@tonic-gate 			for (; pri->length < 6; pri->length++)
6327c478bd9Sstevel@tonic-gate 				(void) fputc('\t', stdout);
6337c478bd9Sstevel@tonic-gate 		}
6347c478bd9Sstevel@tonic-gate 	}
6357c478bd9Sstevel@tonic-gate 	pri->length = 0;
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 	if (pri->Errno != 0) {		/* error in syscall */
6387c478bd9Sstevel@tonic-gate 		if (istraced) {
6397c478bd9Sstevel@tonic-gate 			if (cflag)
6407c478bd9Sstevel@tonic-gate 				scp->error++;
6417c478bd9Sstevel@tonic-gate 			else {
6427c478bd9Sstevel@tonic-gate 				const char *ename = errname(pri->Errno);
6437c478bd9Sstevel@tonic-gate 				const char *privname;
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 				(void) printf("Err#%d", pri->Errno);
6467c478bd9Sstevel@tonic-gate 				if (ename != NULL) {
6477c478bd9Sstevel@tonic-gate 					(void) fputc(' ', stdout);
6487c478bd9Sstevel@tonic-gate 					(void) fputs(ename, stdout);
6497c478bd9Sstevel@tonic-gate 				}
6507c478bd9Sstevel@tonic-gate 				switch (pri->ErrPriv) {
6517c478bd9Sstevel@tonic-gate 				case PRIV_NONE:
6527c478bd9Sstevel@tonic-gate 					privname = NULL;
6537c478bd9Sstevel@tonic-gate 					break;
6547c478bd9Sstevel@tonic-gate 				case PRIV_ALL:
6557c478bd9Sstevel@tonic-gate 					privname = "ALL";
6567c478bd9Sstevel@tonic-gate 					break;
6577c478bd9Sstevel@tonic-gate 				case PRIV_MULTIPLE:
6587c478bd9Sstevel@tonic-gate 					privname = "MULTIPLE";
6597c478bd9Sstevel@tonic-gate 					break;
6607c478bd9Sstevel@tonic-gate 				case PRIV_ALLZONE:
6617c478bd9Sstevel@tonic-gate 					privname = "ZONE";
6627c478bd9Sstevel@tonic-gate 					break;
6637c478bd9Sstevel@tonic-gate 				default:
6647c478bd9Sstevel@tonic-gate 					privname = priv_getbynum(pri->ErrPriv);
6657c478bd9Sstevel@tonic-gate 					break;
6667c478bd9Sstevel@tonic-gate 				}
6677c478bd9Sstevel@tonic-gate 				if (privname != NULL)
6687c478bd9Sstevel@tonic-gate 					(void) printf(" [%s]", privname);
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 				(void) fputc('\n', stdout);
6717c478bd9Sstevel@tonic-gate 			}
6727c478bd9Sstevel@tonic-gate 		}
6737c478bd9Sstevel@tonic-gate 	} else {
6747c478bd9Sstevel@tonic-gate 		/* show arguments on successful exec */
675*8fd04b83SRoger A. Faulkner 		if (what == SYS_execve) {
6767c478bd9Sstevel@tonic-gate 			if (!cflag && istraced)
6777c478bd9Sstevel@tonic-gate 				showargs(pri, raw);
6787c478bd9Sstevel@tonic-gate 		} else if (!cflag && istraced) {
6797c478bd9Sstevel@tonic-gate 			const char *fmt = NULL;
6807c478bd9Sstevel@tonic-gate 			long rv1 = pri->Rval1;
6817c478bd9Sstevel@tonic-gate 			long rv2 = pri->Rval2;
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate #ifdef _LP64
6847c478bd9Sstevel@tonic-gate 			/*
6857c478bd9Sstevel@tonic-gate 			 * 32-bit system calls return 32-bit values. We
6867c478bd9Sstevel@tonic-gate 			 * later mask out the upper bits if we want to
6877c478bd9Sstevel@tonic-gate 			 * print these as unsigned values.
6887c478bd9Sstevel@tonic-gate 			 */
6897c478bd9Sstevel@tonic-gate 			if (data_model == PR_MODEL_ILP32) {
6907c478bd9Sstevel@tonic-gate 				rv1 = (int)rv1;
6917c478bd9Sstevel@tonic-gate 				rv2 = (int)rv2;
6927c478bd9Sstevel@tonic-gate 			}
6937c478bd9Sstevel@tonic-gate #endif
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 			switch (what) {
6967c478bd9Sstevel@tonic-gate 			case SYS_llseek:
6977c478bd9Sstevel@tonic-gate 				rv1 &= 0xffffffff;
6987c478bd9Sstevel@tonic-gate 				rv2 &= 0xffffffff;
6997c478bd9Sstevel@tonic-gate #ifdef _LONG_LONG_LTOH	/* first long of a longlong is the low order */
7007c478bd9Sstevel@tonic-gate 				if (rv2 != 0) {
7017c478bd9Sstevel@tonic-gate 					long temp = rv1;
7027c478bd9Sstevel@tonic-gate 					fmt = "= 0x%lX%.8lX";
7037c478bd9Sstevel@tonic-gate 					rv1 = rv2;
7047c478bd9Sstevel@tonic-gate 					rv2 = temp;
7057c478bd9Sstevel@tonic-gate 					break;
7067c478bd9Sstevel@tonic-gate 				}
7077c478bd9Sstevel@tonic-gate #else	/* the other way around */
7087c478bd9Sstevel@tonic-gate 				if (rv1 != 0) {
7097c478bd9Sstevel@tonic-gate 					fmt = "= 0x%lX%.8lX";
7107c478bd9Sstevel@tonic-gate 					break;
7117c478bd9Sstevel@tonic-gate 				}
7127c478bd9Sstevel@tonic-gate 				rv1 = rv2;	/* ugly */
7137c478bd9Sstevel@tonic-gate #endif
7147c478bd9Sstevel@tonic-gate 				/* FALLTHROUGH */
7157c478bd9Sstevel@tonic-gate 			case SYS_lseek:
7167c478bd9Sstevel@tonic-gate 			case SYS_ulimit:
7177c478bd9Sstevel@tonic-gate 				if (rv1 & 0xff000000) {
7187c478bd9Sstevel@tonic-gate #ifdef _LP64
7197c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7207c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7217c478bd9Sstevel@tonic-gate #endif
7227c478bd9Sstevel@tonic-gate 					fmt = "= 0x%.8lX";
7237c478bd9Sstevel@tonic-gate 				}
7247c478bd9Sstevel@tonic-gate 				break;
7257c478bd9Sstevel@tonic-gate 			case SYS_sigtimedwait:
7267c478bd9Sstevel@tonic-gate 				if (raw)
7277c478bd9Sstevel@tonic-gate 					/* EMPTY */;
7287c478bd9Sstevel@tonic-gate 				else if ((fmt = rawsigname(pri, rv1)) != NULL) {
7297c478bd9Sstevel@tonic-gate 					rv1 = (long)fmt;	/* filthy */
7307c478bd9Sstevel@tonic-gate 					fmt = "= %s";
7317c478bd9Sstevel@tonic-gate 				}
7327c478bd9Sstevel@tonic-gate 				break;
7337c478bd9Sstevel@tonic-gate 			case SYS_port:
7347c478bd9Sstevel@tonic-gate #ifdef _LP64
7357c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_LP64) {
7367c478bd9Sstevel@tonic-gate 					rv2 = rv1 & 0xffffffff;
7377c478bd9Sstevel@tonic-gate 					rv1 = rv1 >> 32;
7387c478bd9Sstevel@tonic-gate 				}
7397c478bd9Sstevel@tonic-gate #endif
7407c478bd9Sstevel@tonic-gate 				break;
7417c478bd9Sstevel@tonic-gate 			}
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 			if (fmt == NULL) {
7447c478bd9Sstevel@tonic-gate 				switch (stp->rval[0]) {
7457c478bd9Sstevel@tonic-gate 				case HEX:
7467c478bd9Sstevel@tonic-gate #ifdef _LP64
7477c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7487c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7497c478bd9Sstevel@tonic-gate #endif
7507c478bd9Sstevel@tonic-gate 					fmt = "= 0x%.8lX";
7517c478bd9Sstevel@tonic-gate 					break;
7527c478bd9Sstevel@tonic-gate 				case HHX:
7537c478bd9Sstevel@tonic-gate #ifdef _LP64
7547c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7557c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7567c478bd9Sstevel@tonic-gate #endif
7577c478bd9Sstevel@tonic-gate 					fmt = "= 0x%.4lX";
7587c478bd9Sstevel@tonic-gate 					break;
7597c478bd9Sstevel@tonic-gate 				case OCT:
7607c478bd9Sstevel@tonic-gate #ifdef _LP64
7617c478bd9Sstevel@tonic-gate 					if (data_model == PR_MODEL_ILP32)
7627c478bd9Sstevel@tonic-gate 						rv1 &= 0xffffffff;
7637c478bd9Sstevel@tonic-gate #endif
7647c478bd9Sstevel@tonic-gate 					fmt = "= %#lo";
7657c478bd9Sstevel@tonic-gate 					break;
766f48205beScasper 				case UNS:
767f48205beScasper #ifdef _LP64
768f48205beScasper 					if (data_model == PR_MODEL_ILP32)
769f48205beScasper 						rv1 &= 0xffffffff;
770f48205beScasper #endif
771f48205beScasper 					fmt = "= %lu";
772f48205beScasper 					break;
7737c478bd9Sstevel@tonic-gate 				default:
7747c478bd9Sstevel@tonic-gate 					fmt = "= %ld";
7757c478bd9Sstevel@tonic-gate 					break;
7767c478bd9Sstevel@tonic-gate 				}
7777c478bd9Sstevel@tonic-gate 			}
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 			(void) printf(fmt, rv1, rv2);
7807c478bd9Sstevel@tonic-gate 
7817c478bd9Sstevel@tonic-gate 			switch (stp->rval[1]) {
7827c478bd9Sstevel@tonic-gate 			case NOV:
7837c478bd9Sstevel@tonic-gate 				fmt = NULL;
7847c478bd9Sstevel@tonic-gate 				break;
7857c478bd9Sstevel@tonic-gate 			case HEX:
7867c478bd9Sstevel@tonic-gate #ifdef _LP64
7877c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_ILP32)
7887c478bd9Sstevel@tonic-gate 					rv2 &= 0xffffffff;
7897c478bd9Sstevel@tonic-gate #endif
7907c478bd9Sstevel@tonic-gate 				fmt = " [0x%.8lX]";
7917c478bd9Sstevel@tonic-gate 				break;
7927c478bd9Sstevel@tonic-gate 			case HHX:
7937c478bd9Sstevel@tonic-gate #ifdef _LP64
7947c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_ILP32)
7957c478bd9Sstevel@tonic-gate 					rv2 &= 0xffffffff;
7967c478bd9Sstevel@tonic-gate #endif
7977c478bd9Sstevel@tonic-gate 				fmt = " [0x%.4lX]";
7987c478bd9Sstevel@tonic-gate 				break;
7997c478bd9Sstevel@tonic-gate 			case OCT:
8007c478bd9Sstevel@tonic-gate #ifdef _LP64
8017c478bd9Sstevel@tonic-gate 				if (data_model == PR_MODEL_ILP32)
8027c478bd9Sstevel@tonic-gate 					rv2 &= 0xffffffff;
8037c478bd9Sstevel@tonic-gate #endif
8047c478bd9Sstevel@tonic-gate 				fmt = " [%#lo]";
8057c478bd9Sstevel@tonic-gate 				break;
806f48205beScasper 			case UNS:
807f48205beScasper #ifdef _LP64
808f48205beScasper 				if (data_model == PR_MODEL_ILP32)
809f48205beScasper 					rv2 &= 0xffffffff;
810f48205beScasper #endif
811f48205beScasper 				fmt = " [%lu]";
812f48205beScasper 				break;
8137c478bd9Sstevel@tonic-gate 			default:
8147c478bd9Sstevel@tonic-gate 				fmt = " [%ld]";
8157c478bd9Sstevel@tonic-gate 				break;
8167c478bd9Sstevel@tonic-gate 			}
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate 			if (fmt != NULL)
8197c478bd9Sstevel@tonic-gate 				(void) printf(fmt, rv2);
8207c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stdout);
8217c478bd9Sstevel@tonic-gate 		}
8227c478bd9Sstevel@tonic-gate 
823*8fd04b83SRoger A. Faulkner 		if (what == SYS_vfork || what == SYS_forksys) {
8247c478bd9Sstevel@tonic-gate 			if (pri->Rval2 == 0)		/* child was created */
8257c478bd9Sstevel@tonic-gate 				pri->child = pri->Rval1;
8267c478bd9Sstevel@tonic-gate 			else if (cflag && istraced)	/* this is the child */
8277c478bd9Sstevel@tonic-gate 				scp->count--;
8287c478bd9Sstevel@tonic-gate 		}
8297c478bd9Sstevel@tonic-gate 		if (what == SYS_lwp_create && pri->Rval1 == 0 &&
8307c478bd9Sstevel@tonic-gate 		    cflag && istraced)		/* this is the created lwp */
8317c478bd9Sstevel@tonic-gate 			scp->count--;
8327c478bd9Sstevel@tonic-gate 	}
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate #define	ISREAD(code) \
8357c478bd9Sstevel@tonic-gate 	((code) == SYS_read || (code) == SYS_pread || (code) == SYS_pread64 || \
8367c478bd9Sstevel@tonic-gate 	(code) == SYS_recv || (code) == SYS_recvfrom)
8377c478bd9Sstevel@tonic-gate #define	ISWRITE(code) \
8387c478bd9Sstevel@tonic-gate 	((code) == SYS_write || (code) == SYS_pwrite || \
8397c478bd9Sstevel@tonic-gate 	(code) == SYS_pwrite64 || (code) == SYS_send || (code) == SYS_sendto)
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate 	if (!cflag && istraced) {
8427c478bd9Sstevel@tonic-gate 		int fdp1 = (int)pri->sys_args[0] + 1; /* filedescriptor + 1 */
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 		if (raw) {
845*8fd04b83SRoger A. Faulkner 			if (what != SYS_execve)
8467c478bd9Sstevel@tonic-gate 				showpaths(pri, stp);
8477c478bd9Sstevel@tonic-gate 			if (ISREAD(what) || ISWRITE(what)) {
8487c478bd9Sstevel@tonic-gate 				if (pri->iob_buf[0] != '\0')
8497c478bd9Sstevel@tonic-gate 					(void) printf("%s     0x%.8lX: %s\n",
8505403172aSRoger A. Faulkner 					    pri->pname, pri->sys_args[1],
8515403172aSRoger A. Faulkner 					    pri->iob_buf);
8527c478bd9Sstevel@tonic-gate 			}
8537c478bd9Sstevel@tonic-gate 		}
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 		/*
8567c478bd9Sstevel@tonic-gate 		 * Show buffer contents for read()/pread() or write()/pwrite().
8577c478bd9Sstevel@tonic-gate 		 * IOBSIZE bytes have already been shown;
8587c478bd9Sstevel@tonic-gate 		 * don't show them again unless there's more.
8597c478bd9Sstevel@tonic-gate 		 */
8607c478bd9Sstevel@tonic-gate 		if ((ISREAD(what) && pri->Errno == 0 &&
8617c478bd9Sstevel@tonic-gate 		    prismember(&readfd, fdp1)) ||
8627c478bd9Sstevel@tonic-gate 		    (ISWRITE(what) && prismember(&writefd, fdp1))) {
8637c478bd9Sstevel@tonic-gate 			long nb = ISWRITE(what) ? pri->sys_args[2] : pri->Rval1;
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 			if (nb > IOBSIZE) {
8667c478bd9Sstevel@tonic-gate 				/* enter region of lengthy output */
8677c478bd9Sstevel@tonic-gate 				if (nb > MYBUFSIZ / 4)
8687c478bd9Sstevel@tonic-gate 					Eserialize();
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 				showbuffer(pri, pri->sys_args[1], nb);
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate 				/* exit region of lengthy output */
8737c478bd9Sstevel@tonic-gate 				if (nb > MYBUFSIZ / 4)
8747c478bd9Sstevel@tonic-gate 					Xserialize();
8757c478bd9Sstevel@tonic-gate 			}
8767c478bd9Sstevel@tonic-gate 		}
8777c478bd9Sstevel@tonic-gate #undef	ISREAD
8787c478bd9Sstevel@tonic-gate #undef	ISWRITE
8797c478bd9Sstevel@tonic-gate 		/*
8807c478bd9Sstevel@tonic-gate 		 * Do verbose interpretation if requested.
8817c478bd9Sstevel@tonic-gate 		 * If buffer contents for read or write have been requested and
8827c478bd9Sstevel@tonic-gate 		 * this is a readv() or writev(), force verbose interpretation.
8837c478bd9Sstevel@tonic-gate 		 */
8847c478bd9Sstevel@tonic-gate 		if (prismember(&verbose, what) ||
88581006e0fSja 		    ((what == SYS_readv || what == SYS_recvmsg) &&
88681006e0fSja 		    pri->Errno == 0 && prismember(&readfd, fdp1)) ||
88781006e0fSja 		    ((what == SYS_writev || what == SYS_sendfilev ||
88881006e0fSja 		    what == SYS_sendmsg) &&
8897c478bd9Sstevel@tonic-gate 		    prismember(&writefd, fdp1)))
8907c478bd9Sstevel@tonic-gate 			expound(pri, pri->Rval1, raw);
8917c478bd9Sstevel@tonic-gate 	}
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 	return (!cflag && istraced);
8947c478bd9Sstevel@tonic-gate }
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate void
8977c478bd9Sstevel@tonic-gate showpaths(private_t *pri, const struct systable *stp)
8987c478bd9Sstevel@tonic-gate {
899*8fd04b83SRoger A. Faulkner 	int what = pri->lwpstat->pr_what;
9007c478bd9Sstevel@tonic-gate 	int i;
9017c478bd9Sstevel@tonic-gate 
9027c478bd9Sstevel@tonic-gate 	for (i = 0; i < pri->sys_nargs; i++) {
903*8fd04b83SRoger A. Faulkner 		if (stp->arg[i] == ATC && (int)pri->sys_args[i] == AT_FDCWD) {
904*8fd04b83SRoger A. Faulkner 			(void) printf("%s     0x%.8X: AT_FDCWD\n",
905*8fd04b83SRoger A. Faulkner 			    pri->pname, AT_FDCWD);
906*8fd04b83SRoger A. Faulkner 		} else if ((stp->arg[i] == STG) ||
9077c478bd9Sstevel@tonic-gate 		    (stp->arg[i] == RST && !pri->Errno) ||
9087c478bd9Sstevel@tonic-gate 		    (stp->arg[i] == RLK && !pri->Errno && pri->Rval1 > 0)) {
9097c478bd9Sstevel@tonic-gate 			long addr = pri->sys_args[i];
9107c478bd9Sstevel@tonic-gate 			int maxleng =
9117c478bd9Sstevel@tonic-gate 			    (stp->arg[i] == RLK)? (int)pri->Rval1 : PATH_MAX;
9127c478bd9Sstevel@tonic-gate 			char *s;
9137c478bd9Sstevel@tonic-gate 
914*8fd04b83SRoger A. Faulkner 			if (pri->sys_valid &&
915*8fd04b83SRoger A. Faulkner 			    ((i == 0 && stp->arg[0] == STG) ||
916*8fd04b83SRoger A. Faulkner 			    (i == 1 && (what == SYS_openat ||
917*8fd04b83SRoger A. Faulkner 			    what == SYS_openat64))))	/* already fetched */
9187c478bd9Sstevel@tonic-gate 				s = pri->sys_path;
9197c478bd9Sstevel@tonic-gate 			else
9207c478bd9Sstevel@tonic-gate 				s = fetchstring(pri, addr,
9217c478bd9Sstevel@tonic-gate 				    maxleng > PATH_MAX ? PATH_MAX : maxleng);
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 			if (s != (char *)NULL)
9247c478bd9Sstevel@tonic-gate 				(void) printf("%s     0x%.8lX: \"%s\"\n",
9255403172aSRoger A. Faulkner 				    pri->pname, addr, s);
9267c478bd9Sstevel@tonic-gate 		}
9277c478bd9Sstevel@tonic-gate 	}
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate /*
9317c478bd9Sstevel@tonic-gate  * Display arguments to successful exec().
9327c478bd9Sstevel@tonic-gate  */
9337c478bd9Sstevel@tonic-gate void
9347c478bd9Sstevel@tonic-gate showargs(private_t *pri, int raw)
9357c478bd9Sstevel@tonic-gate {
9367c478bd9Sstevel@tonic-gate 	const lwpstatus_t *Lsp = pri->lwpstat;
9377c478bd9Sstevel@tonic-gate 	int nargs;
9387c478bd9Sstevel@tonic-gate 	long ap;
9397c478bd9Sstevel@tonic-gate 	int ptrsize;
9407c478bd9Sstevel@tonic-gate 	int fail;
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	pri->length = 0;
9437c478bd9Sstevel@tonic-gate 	ptrsize = (data_model == PR_MODEL_LP64)? 8 : 4;
9447c478bd9Sstevel@tonic-gate 
9457c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)	/* XX64 */
9467c478bd9Sstevel@tonic-gate 	ap = (long)Lsp->pr_reg[R_SP];
9477c478bd9Sstevel@tonic-gate 	fail = (Pread(Proc, &nargs, sizeof (nargs), ap) != sizeof (nargs));
9487c478bd9Sstevel@tonic-gate 	ap += ptrsize;
9497c478bd9Sstevel@tonic-gate #endif /* i386 */
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate #if sparc
9527c478bd9Sstevel@tonic-gate 	if (data_model == PR_MODEL_LP64) {
9537c478bd9Sstevel@tonic-gate 		int64_t xnargs;
9547c478bd9Sstevel@tonic-gate 		ap = (long)(Lsp->pr_reg[R_SP]) + 16 * sizeof (int64_t)
9555403172aSRoger A. Faulkner 		    + STACK_BIAS;
9567c478bd9Sstevel@tonic-gate 		fail = (Pread(Proc, &xnargs, sizeof (xnargs), ap) !=
9575403172aSRoger A. Faulkner 		    sizeof (xnargs));
9587c478bd9Sstevel@tonic-gate 		nargs = (int)xnargs;
9597c478bd9Sstevel@tonic-gate 	} else {
9607c478bd9Sstevel@tonic-gate 		ap = (long)(Lsp->pr_reg[R_SP]) + 16 * sizeof (int32_t);
9617c478bd9Sstevel@tonic-gate 		fail = (Pread(Proc, &nargs, sizeof (nargs), ap) !=
9625403172aSRoger A. Faulkner 		    sizeof (nargs));
9637c478bd9Sstevel@tonic-gate 	}
9647c478bd9Sstevel@tonic-gate 	ap += ptrsize;
9657c478bd9Sstevel@tonic-gate #endif /* sparc */
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate 	if (fail) {
9687c478bd9Sstevel@tonic-gate 		(void) printf("\n%s\t*** Bad argument list? ***\n", pri->pname);
9697c478bd9Sstevel@tonic-gate 		return;
9707c478bd9Sstevel@tonic-gate 	}
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 	(void) printf("  argc = %d\n", nargs);
9737c478bd9Sstevel@tonic-gate 	if (raw)
974*8fd04b83SRoger A. Faulkner 		showpaths(pri, &systable[SYS_execve]);
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	show_cred(pri, FALSE);
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 	if (aflag || eflag) {		/* dump args or environment */
9797c478bd9Sstevel@tonic-gate 
9807c478bd9Sstevel@tonic-gate 		/* enter region of (potentially) lengthy output */
9817c478bd9Sstevel@tonic-gate 		Eserialize();
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 		if (aflag)		/* dump the argument list */
9847c478bd9Sstevel@tonic-gate 			dumpargs(pri, ap, "argv:");
9857c478bd9Sstevel@tonic-gate 		ap += (nargs+1) * ptrsize;
9867c478bd9Sstevel@tonic-gate 		if (eflag)		/* dump the environment */
9877c478bd9Sstevel@tonic-gate 			dumpargs(pri, ap, "envp:");
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate 		/* exit region of lengthy output */
9907c478bd9Sstevel@tonic-gate 		Xserialize();
9917c478bd9Sstevel@tonic-gate 	}
9927c478bd9Sstevel@tonic-gate }
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate void
9957c478bd9Sstevel@tonic-gate dumpargs(private_t *pri, long ap, const char *str)
9967c478bd9Sstevel@tonic-gate {
9977c478bd9Sstevel@tonic-gate 	char *string;
9987c478bd9Sstevel@tonic-gate 	unsigned int leng = 0;
9997c478bd9Sstevel@tonic-gate 	int ptrsize;
10007c478bd9Sstevel@tonic-gate 	long arg = 0;
10017c478bd9Sstevel@tonic-gate 	char *argaddr;
10027c478bd9Sstevel@tonic-gate 	char badaddr[32];
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate 	if (interrupt)
10057c478bd9Sstevel@tonic-gate 		return;
10067c478bd9Sstevel@tonic-gate 
10077c478bd9Sstevel@tonic-gate #ifdef _LP64
10087c478bd9Sstevel@tonic-gate 	if (data_model == PR_MODEL_LP64) {
10097c478bd9Sstevel@tonic-gate 		argaddr = (char *)&arg;
10107c478bd9Sstevel@tonic-gate 		ptrsize = 8;
10117c478bd9Sstevel@tonic-gate 	} else {
10127c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
10137c478bd9Sstevel@tonic-gate 		argaddr = (char *)&arg;
10147c478bd9Sstevel@tonic-gate #else
10157c478bd9Sstevel@tonic-gate 		argaddr = (char *)&arg + 4;
10167c478bd9Sstevel@tonic-gate #endif
10177c478bd9Sstevel@tonic-gate 		ptrsize = 4;
10187c478bd9Sstevel@tonic-gate 	}
10197c478bd9Sstevel@tonic-gate #else
10207c478bd9Sstevel@tonic-gate 	argaddr = (char *)&arg;
10217c478bd9Sstevel@tonic-gate 	ptrsize = 4;
10227c478bd9Sstevel@tonic-gate #endif
10237c478bd9Sstevel@tonic-gate 	putpname(pri);
10247c478bd9Sstevel@tonic-gate 	(void) fputc(' ', stdout);
10257c478bd9Sstevel@tonic-gate 	(void) fputs(str, stdout);
10267c478bd9Sstevel@tonic-gate 	leng += 1 + strlen(str);
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	while (!interrupt) {
10297c478bd9Sstevel@tonic-gate 		if (Pread(Proc, argaddr, ptrsize, ap) != ptrsize) {
10307c478bd9Sstevel@tonic-gate 			(void) printf("\n%s\t*** Bad argument list? ***\n",
10315403172aSRoger A. Faulkner 			    pri->pname);
10327c478bd9Sstevel@tonic-gate 			return;
10337c478bd9Sstevel@tonic-gate 		}
10347c478bd9Sstevel@tonic-gate 		ap += ptrsize;
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 		if (arg == 0)
10377c478bd9Sstevel@tonic-gate 			break;
10387c478bd9Sstevel@tonic-gate 		string = fetchstring(pri, arg, PATH_MAX);
10397c478bd9Sstevel@tonic-gate 		if (string == NULL) {
10407c478bd9Sstevel@tonic-gate 			(void) sprintf(badaddr, "BadAddress:0x%.8lX", arg);
10417c478bd9Sstevel@tonic-gate 			string = badaddr;
10427c478bd9Sstevel@tonic-gate 		}
10437c478bd9Sstevel@tonic-gate 		if ((leng += strlen(string)) < 63) {
10447c478bd9Sstevel@tonic-gate 			(void) fputc(' ', stdout);
10457c478bd9Sstevel@tonic-gate 			leng++;
10467c478bd9Sstevel@tonic-gate 		} else {
10477c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stdout);
10487c478bd9Sstevel@tonic-gate 			leng = 0;
10497c478bd9Sstevel@tonic-gate 			putpname(pri);
10507c478bd9Sstevel@tonic-gate 			(void) fputs("  ", stdout);
10517c478bd9Sstevel@tonic-gate 			leng += 2 + strlen(string);
10527c478bd9Sstevel@tonic-gate 		}
10537c478bd9Sstevel@tonic-gate 		(void) fputs(string, stdout);
10547c478bd9Sstevel@tonic-gate 	}
10557c478bd9Sstevel@tonic-gate 	(void) fputc('\n', stdout);
10567c478bd9Sstevel@tonic-gate }
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate /*
10597c478bd9Sstevel@tonic-gate  * Display contents of read() or write() buffer.
10607c478bd9Sstevel@tonic-gate  */
10617c478bd9Sstevel@tonic-gate void
10627c478bd9Sstevel@tonic-gate showbuffer(private_t *pri, long offset, long count)
10637c478bd9Sstevel@tonic-gate {
10647c478bd9Sstevel@tonic-gate 	char buffer[320];
10657c478bd9Sstevel@tonic-gate 	int nbytes;
10667c478bd9Sstevel@tonic-gate 	char *buf;
10677c478bd9Sstevel@tonic-gate 	int n;
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate 	while (count > 0 && !interrupt) {
10707c478bd9Sstevel@tonic-gate 		nbytes = (count < sizeof (buffer))? count : sizeof (buffer);
10717c478bd9Sstevel@tonic-gate 		if ((nbytes = Pread(Proc, buffer, nbytes, offset)) <= 0)
10727c478bd9Sstevel@tonic-gate 			break;
10737c478bd9Sstevel@tonic-gate 		count -= nbytes;
10747c478bd9Sstevel@tonic-gate 		offset += nbytes;
10757c478bd9Sstevel@tonic-gate 		buf = buffer;
10767c478bd9Sstevel@tonic-gate 		while (nbytes > 0 && !interrupt) {
10777c478bd9Sstevel@tonic-gate 			char obuf[65];
10787c478bd9Sstevel@tonic-gate 
10797c478bd9Sstevel@tonic-gate 			n = (nbytes < 32)? nbytes : 32;
10807c478bd9Sstevel@tonic-gate 			showbytes(buf, n, obuf);
10817c478bd9Sstevel@tonic-gate 
10827c478bd9Sstevel@tonic-gate 			putpname(pri);
10837c478bd9Sstevel@tonic-gate 			(void) fputs("  ", stdout);
10847c478bd9Sstevel@tonic-gate 			(void) fputs(obuf, stdout);
10857c478bd9Sstevel@tonic-gate 			(void) fputc('\n', stdout);
10867c478bd9Sstevel@tonic-gate 			nbytes -= n;
10877c478bd9Sstevel@tonic-gate 			buf += n;
10887c478bd9Sstevel@tonic-gate 		}
10897c478bd9Sstevel@tonic-gate 	}
10907c478bd9Sstevel@tonic-gate }
10917c478bd9Sstevel@tonic-gate 
10927c478bd9Sstevel@tonic-gate void
10937c478bd9Sstevel@tonic-gate showbytes(const char *buf, int n, char *obuf)
10947c478bd9Sstevel@tonic-gate {
10957c478bd9Sstevel@tonic-gate 	int c;
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 	while (--n >= 0) {
10987c478bd9Sstevel@tonic-gate 		int c1 = '\\';
10997c478bd9Sstevel@tonic-gate 		int c2;
11007c478bd9Sstevel@tonic-gate 
11017c478bd9Sstevel@tonic-gate 		switch (c = (*buf++ & 0xff)) {
11027c478bd9Sstevel@tonic-gate 		case '\0':
11037c478bd9Sstevel@tonic-gate 			c2 = '0';
11047c478bd9Sstevel@tonic-gate 			break;
11057c478bd9Sstevel@tonic-gate 		case '\b':
11067c478bd9Sstevel@tonic-gate 			c2 = 'b';
11077c478bd9Sstevel@tonic-gate 			break;
11087c478bd9Sstevel@tonic-gate 		case '\t':
11097c478bd9Sstevel@tonic-gate 			c2 = 't';
11107c478bd9Sstevel@tonic-gate 			break;
11117c478bd9Sstevel@tonic-gate 		case '\n':
11127c478bd9Sstevel@tonic-gate 			c2 = 'n';
11137c478bd9Sstevel@tonic-gate 			break;
11147c478bd9Sstevel@tonic-gate 		case '\v':
11157c478bd9Sstevel@tonic-gate 			c2 = 'v';
11167c478bd9Sstevel@tonic-gate 			break;
11177c478bd9Sstevel@tonic-gate 		case '\f':
11187c478bd9Sstevel@tonic-gate 			c2 = 'f';
11197c478bd9Sstevel@tonic-gate 			break;
11207c478bd9Sstevel@tonic-gate 		case '\r':
11217c478bd9Sstevel@tonic-gate 			c2 = 'r';
11227c478bd9Sstevel@tonic-gate 			break;
11237c478bd9Sstevel@tonic-gate 		default:
11247c478bd9Sstevel@tonic-gate 			if (isprint(c)) {
11257c478bd9Sstevel@tonic-gate 				c1 = ' ';
11267c478bd9Sstevel@tonic-gate 				c2 = c;
11277c478bd9Sstevel@tonic-gate 			} else {
11287c478bd9Sstevel@tonic-gate 				c1 = c>>4;
11297c478bd9Sstevel@tonic-gate 				c1 += (c1 < 10)? '0' : 'A'-10;
11307c478bd9Sstevel@tonic-gate 				c2 = c&0xf;
11317c478bd9Sstevel@tonic-gate 				c2 += (c2 < 10)? '0' : 'A'-10;
11327c478bd9Sstevel@tonic-gate 			}
11337c478bd9Sstevel@tonic-gate 			break;
11347c478bd9Sstevel@tonic-gate 		}
11357c478bd9Sstevel@tonic-gate 		*obuf++ = (char)c1;
11367c478bd9Sstevel@tonic-gate 		*obuf++ = (char)c2;
11377c478bd9Sstevel@tonic-gate 	}
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 	*obuf = '\0';
11407c478bd9Sstevel@tonic-gate }
1141