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*134a1f4eSCasper 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 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", 967c478bd9Sstevel@tonic-gate 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 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", 1347c478bd9Sstevel@tonic-gate 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 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", 1747c478bd9Sstevel@tonic-gate 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()", 1787c478bd9Sstevel@tonic-gate 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 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 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", 2527c478bd9Sstevel@tonic-gate 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()", 2567c478bd9Sstevel@tonic-gate 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 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", 2967c478bd9Sstevel@tonic-gate flt, proc_fltname(flt, pri->flt_name, sizeof (pri->flt_name)), 2977c478bd9Sstevel@tonic-gate (long)Lsp->pr_reg[R_PC]); 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate if (flt == FLTPAGE) 3007c478bd9Sstevel@tonic-gate (void) printf(" addr = 0x%.8lX", 3017c478bd9Sstevel@tonic-gate (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 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", 3297c478bd9Sstevel@tonic-gate 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 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, 4247c478bd9Sstevel@tonic-gate sizeof (offset), argv); 4257c478bd9Sstevel@tonic-gate else { 4267c478bd9Sstevel@tonic-gate offset32 = 0; 4277c478bd9Sstevel@tonic-gate (void) Pread(Proc, &offset32, 4287c478bd9Sstevel@tonic-gate 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, 4447c478bd9Sstevel@tonic-gate "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 4737c478bd9Sstevel@tonic-gate 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, 4767c478bd9Sstevel@tonic-gate "%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 */ 4857c478bd9Sstevel@tonic-gate escape_string(pri, pri->sys_path); 4867c478bd9Sstevel@tonic-gate argprinted = TRUE; 4877c478bd9Sstevel@tonic-gate } else if (x != HID || raw) { 4887c478bd9Sstevel@tonic-gate if (argprinted) 4897c478bd9Sstevel@tonic-gate outstring(pri, ", "); 4907c478bd9Sstevel@tonic-gate if (x == LLO) 4917c478bd9Sstevel@tonic-gate (*Print[x])(pri, raw, arg, 4927c478bd9Sstevel@tonic-gate pri->sys_args[++i]); 4937c478bd9Sstevel@tonic-gate else 4947c478bd9Sstevel@tonic-gate (*Print[x])(pri, raw, arg); 4957c478bd9Sstevel@tonic-gate /* 4967c478bd9Sstevel@tonic-gate * if nothing printed, then don't print ", " 4977c478bd9Sstevel@tonic-gate */ 4987c478bd9Sstevel@tonic-gate if (x == NOV) 4997c478bd9Sstevel@tonic-gate argprinted = FALSE; 5007c478bd9Sstevel@tonic-gate else 5017c478bd9Sstevel@tonic-gate argprinted = TRUE; 5027c478bd9Sstevel@tonic-gate } 5037c478bd9Sstevel@tonic-gate } 5047c478bd9Sstevel@tonic-gate outstring(pri, ")"); 5057c478bd9Sstevel@tonic-gate } 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate return (istraced); 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate #undef ISREAD 5107c478bd9Sstevel@tonic-gate #undef ISWRITE 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate /* 5137c478bd9Sstevel@tonic-gate * sysexit() returns non-zero if anything was printed. 5147c478bd9Sstevel@tonic-gate */ 5157c478bd9Sstevel@tonic-gate int 5167c478bd9Sstevel@tonic-gate sysexit(private_t *pri, int dotrace) 5177c478bd9Sstevel@tonic-gate { 5187c478bd9Sstevel@tonic-gate const lwpstatus_t *Lsp = pri->lwpstat; 5197c478bd9Sstevel@tonic-gate int what = Lsp->pr_what; 5207c478bd9Sstevel@tonic-gate struct syscount *scp; 5217c478bd9Sstevel@tonic-gate const struct systable *stp; 5227c478bd9Sstevel@tonic-gate int subcode; 5237c478bd9Sstevel@tonic-gate int istraced; 5247c478bd9Sstevel@tonic-gate int raw; 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate /* protect ourself from operating system error */ 5277c478bd9Sstevel@tonic-gate if (what <= 0 || what > PRMAXSYS) 5287c478bd9Sstevel@tonic-gate return (0); 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate /* 5317c478bd9Sstevel@tonic-gate * If we aren't supposed to be tracing this one, then 5327c478bd9Sstevel@tonic-gate * delete it from the traced signal set. We got here 5337c478bd9Sstevel@tonic-gate * because the process was sleeping in an untraced syscall. 5347c478bd9Sstevel@tonic-gate */ 5357c478bd9Sstevel@tonic-gate if (!prismember(&traceeven, what)) { 5367c478bd9Sstevel@tonic-gate (void) Psysexit(Proc, what, FALSE); 5377c478bd9Sstevel@tonic-gate return (0); 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate /* pick up registers & set pri->Errno before anything else */ 5417c478bd9Sstevel@tonic-gate pri->Errno = Lsp->pr_errno; 5427c478bd9Sstevel@tonic-gate pri->ErrPriv = Lsp->pr_errpriv; 5437c478bd9Sstevel@tonic-gate pri->Rval1 = Lsp->pr_rval1; 5447c478bd9Sstevel@tonic-gate pri->Rval2 = Lsp->pr_rval2; 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate switch (what) { 5477c478bd9Sstevel@tonic-gate case SYS_exit: /* these are traced on entry */ 5487c478bd9Sstevel@tonic-gate case SYS_lwp_exit: 5497c478bd9Sstevel@tonic-gate case SYS_context: 5507c478bd9Sstevel@tonic-gate istraced = dotrace && prismember(&trace, what); 5517c478bd9Sstevel@tonic-gate break; 5528fd04b83SRoger A. Faulkner case SYS_execve: /* this is normally traced on entry */ 5537c478bd9Sstevel@tonic-gate istraced = dotrace && prismember(&trace, what); 5547c478bd9Sstevel@tonic-gate if (pri->exec_string && *pri->exec_string) { 5557c478bd9Sstevel@tonic-gate if (!cflag && istraced) { /* print exec() string now */ 5567c478bd9Sstevel@tonic-gate if (pri->exec_pname[0] != '\0') 5577c478bd9Sstevel@tonic-gate (void) fputs(pri->exec_pname, stdout); 5587c478bd9Sstevel@tonic-gate timestamp(pri); 5597c478bd9Sstevel@tonic-gate (void) fputs(pri->exec_string, stdout); 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate pri->exec_pname[0] = '\0'; 5627c478bd9Sstevel@tonic-gate pri->exec_string[0] = '\0'; 5637c478bd9Sstevel@tonic-gate break; 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 5667c478bd9Sstevel@tonic-gate default: 5677c478bd9Sstevel@tonic-gate /* we called sysentry() in main() for these */ 5688fd04b83SRoger A. Faulkner if (what == SYS_openat || what == SYS_openat64 || 5698fd04b83SRoger A. Faulkner what == SYS_open || what == SYS_open64) 5707c478bd9Sstevel@tonic-gate istraced = dotrace && prismember(&trace, what); 5717c478bd9Sstevel@tonic-gate else 5727c478bd9Sstevel@tonic-gate istraced = sysentry(pri, dotrace) && dotrace; 5737c478bd9Sstevel@tonic-gate pri->length = 0; 5747c478bd9Sstevel@tonic-gate if (!cflag && istraced) { 5757c478bd9Sstevel@tonic-gate putpname(pri); 5767c478bd9Sstevel@tonic-gate timestamp(pri); 5777c478bd9Sstevel@tonic-gate pri->length += printf("%s", pri->sys_string); 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate pri->sys_leng = 0; 5807c478bd9Sstevel@tonic-gate *pri->sys_string = '\0'; 5817c478bd9Sstevel@tonic-gate break; 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate /* get systable entry for this syscall */ 5857c478bd9Sstevel@tonic-gate subcode = getsubcode(pri); 5867c478bd9Sstevel@tonic-gate stp = subsys(what, subcode); 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate if (cflag && istraced) { 5897c478bd9Sstevel@tonic-gate (void) mutex_lock(&count_lock); 5907c478bd9Sstevel@tonic-gate scp = Cp->syscount[what]; 591657b1f3dSraf if (what == SYS_forksys && subcode >= 3) 592657b1f3dSraf scp += subcode - 3; 593657b1f3dSraf else if (subcode != -1 && 5948fd04b83SRoger A. Faulkner (what != SYS_openat && what != SYS_openat64 && 5958fd04b83SRoger A. Faulkner what != SYS_open && what != SYS_open64 && 5967c478bd9Sstevel@tonic-gate what != SYS_lwp_create)) 5977c478bd9Sstevel@tonic-gate scp += subcode; 5987c478bd9Sstevel@tonic-gate scp->count++; 5997c478bd9Sstevel@tonic-gate accumulate(&scp->stime, &Lsp->pr_stime, &pri->syslast); 6007c478bd9Sstevel@tonic-gate accumulate(&Cp->usrtotal, &Lsp->pr_utime, &pri->usrlast); 6017c478bd9Sstevel@tonic-gate pri->syslast = Lsp->pr_stime; 6027c478bd9Sstevel@tonic-gate pri->usrlast = Lsp->pr_utime; 6037c478bd9Sstevel@tonic-gate (void) mutex_unlock(&count_lock); 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate 606657b1f3dSraf raw = prismember(&rawout, what); 607657b1f3dSraf 6087c478bd9Sstevel@tonic-gate if (!cflag && istraced) { 6098fd04b83SRoger A. Faulkner if ((what == SYS_vfork || what == SYS_forksys) && 6107c478bd9Sstevel@tonic-gate pri->Errno == 0 && pri->Rval2 != 0) { 6117c478bd9Sstevel@tonic-gate pri->length &= ~07; 612657b1f3dSraf if (strlen(sysname(pri, what, raw? -1 : subcode)) < 6) { 6137c478bd9Sstevel@tonic-gate (void) fputc('\t', stdout); 614657b1f3dSraf pri->length += 8; 615657b1f3dSraf } 6167c478bd9Sstevel@tonic-gate pri->length += 617657b1f3dSraf 7 + printf("\t(returning as child ...)"); 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate if (what == SYS_lwp_create && 6207c478bd9Sstevel@tonic-gate pri->Errno == 0 && pri->Rval1 == 0) { 6217c478bd9Sstevel@tonic-gate pri->length &= ~07; 6227c478bd9Sstevel@tonic-gate pri->length += 6237c478bd9Sstevel@tonic-gate 7 + printf("\t(returning as new lwp ...)"); 6247c478bd9Sstevel@tonic-gate } 6258fd04b83SRoger A. Faulkner if (pri->Errno != 0 || what != SYS_execve) { 6267c478bd9Sstevel@tonic-gate /* prepare to print the return code */ 6277c478bd9Sstevel@tonic-gate pri->length >>= 3; 6287c478bd9Sstevel@tonic-gate if (pri->length >= 6) 6297c478bd9Sstevel@tonic-gate (void) fputc(' ', stdout); 6307c478bd9Sstevel@tonic-gate for (; pri->length < 6; pri->length++) 6317c478bd9Sstevel@tonic-gate (void) fputc('\t', stdout); 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate pri->length = 0; 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate if (pri->Errno != 0) { /* error in syscall */ 6377c478bd9Sstevel@tonic-gate if (istraced) { 6387c478bd9Sstevel@tonic-gate if (cflag) 6397c478bd9Sstevel@tonic-gate scp->error++; 6407c478bd9Sstevel@tonic-gate else { 6417c478bd9Sstevel@tonic-gate const char *ename = errname(pri->Errno); 6427c478bd9Sstevel@tonic-gate const char *privname; 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate (void) printf("Err#%d", pri->Errno); 6457c478bd9Sstevel@tonic-gate if (ename != NULL) { 6467c478bd9Sstevel@tonic-gate (void) fputc(' ', stdout); 6477c478bd9Sstevel@tonic-gate (void) fputs(ename, stdout); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate switch (pri->ErrPriv) { 6507c478bd9Sstevel@tonic-gate case PRIV_NONE: 6517c478bd9Sstevel@tonic-gate privname = NULL; 6527c478bd9Sstevel@tonic-gate break; 6537c478bd9Sstevel@tonic-gate case PRIV_ALL: 6547c478bd9Sstevel@tonic-gate privname = "ALL"; 6557c478bd9Sstevel@tonic-gate break; 6567c478bd9Sstevel@tonic-gate case PRIV_MULTIPLE: 6577c478bd9Sstevel@tonic-gate privname = "MULTIPLE"; 6587c478bd9Sstevel@tonic-gate break; 6597c478bd9Sstevel@tonic-gate case PRIV_ALLZONE: 6607c478bd9Sstevel@tonic-gate privname = "ZONE"; 6617c478bd9Sstevel@tonic-gate break; 6627c478bd9Sstevel@tonic-gate default: 6637c478bd9Sstevel@tonic-gate privname = priv_getbynum(pri->ErrPriv); 6647c478bd9Sstevel@tonic-gate break; 6657c478bd9Sstevel@tonic-gate } 6667c478bd9Sstevel@tonic-gate if (privname != NULL) 6677c478bd9Sstevel@tonic-gate (void) printf(" [%s]", privname); 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate (void) fputc('\n', stdout); 6707c478bd9Sstevel@tonic-gate } 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate } else { 6737c478bd9Sstevel@tonic-gate /* show arguments on successful exec */ 6748fd04b83SRoger A. Faulkner if (what == SYS_execve) { 6757c478bd9Sstevel@tonic-gate if (!cflag && istraced) 6767c478bd9Sstevel@tonic-gate showargs(pri, raw); 6777c478bd9Sstevel@tonic-gate } else if (!cflag && istraced) { 6787c478bd9Sstevel@tonic-gate const char *fmt = NULL; 6797c478bd9Sstevel@tonic-gate long rv1 = pri->Rval1; 6807c478bd9Sstevel@tonic-gate long rv2 = pri->Rval2; 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate #ifdef _LP64 6837c478bd9Sstevel@tonic-gate /* 6847c478bd9Sstevel@tonic-gate * 32-bit system calls return 32-bit values. We 6857c478bd9Sstevel@tonic-gate * later mask out the upper bits if we want to 6867c478bd9Sstevel@tonic-gate * print these as unsigned values. 6877c478bd9Sstevel@tonic-gate */ 6887c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) { 6897c478bd9Sstevel@tonic-gate rv1 = (int)rv1; 6907c478bd9Sstevel@tonic-gate rv2 = (int)rv2; 6917c478bd9Sstevel@tonic-gate } 6927c478bd9Sstevel@tonic-gate #endif 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate switch (what) { 6957c478bd9Sstevel@tonic-gate case SYS_llseek: 6967c478bd9Sstevel@tonic-gate rv1 &= 0xffffffff; 6977c478bd9Sstevel@tonic-gate rv2 &= 0xffffffff; 6987c478bd9Sstevel@tonic-gate #ifdef _LONG_LONG_LTOH /* first long of a longlong is the low order */ 6997c478bd9Sstevel@tonic-gate if (rv2 != 0) { 7007c478bd9Sstevel@tonic-gate long temp = rv1; 7017c478bd9Sstevel@tonic-gate fmt = "= 0x%lX%.8lX"; 7027c478bd9Sstevel@tonic-gate rv1 = rv2; 7037c478bd9Sstevel@tonic-gate rv2 = temp; 7047c478bd9Sstevel@tonic-gate break; 7057c478bd9Sstevel@tonic-gate } 7067c478bd9Sstevel@tonic-gate #else /* the other way around */ 7077c478bd9Sstevel@tonic-gate if (rv1 != 0) { 7087c478bd9Sstevel@tonic-gate fmt = "= 0x%lX%.8lX"; 7097c478bd9Sstevel@tonic-gate break; 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate rv1 = rv2; /* ugly */ 7127c478bd9Sstevel@tonic-gate #endif 7137c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 7147c478bd9Sstevel@tonic-gate case SYS_lseek: 7157c478bd9Sstevel@tonic-gate case SYS_ulimit: 7167c478bd9Sstevel@tonic-gate if (rv1 & 0xff000000) { 7177c478bd9Sstevel@tonic-gate #ifdef _LP64 7187c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) 7197c478bd9Sstevel@tonic-gate rv1 &= 0xffffffff; 7207c478bd9Sstevel@tonic-gate #endif 7217c478bd9Sstevel@tonic-gate fmt = "= 0x%.8lX"; 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate break; 7247c478bd9Sstevel@tonic-gate case SYS_sigtimedwait: 7257c478bd9Sstevel@tonic-gate if (raw) 7267c478bd9Sstevel@tonic-gate /* EMPTY */; 7277c478bd9Sstevel@tonic-gate else if ((fmt = rawsigname(pri, rv1)) != NULL) { 7287c478bd9Sstevel@tonic-gate rv1 = (long)fmt; /* filthy */ 7297c478bd9Sstevel@tonic-gate fmt = "= %s"; 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate break; 7327c478bd9Sstevel@tonic-gate case SYS_port: 7337c478bd9Sstevel@tonic-gate #ifdef _LP64 7347c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_LP64) { 7357c478bd9Sstevel@tonic-gate rv2 = rv1 & 0xffffffff; 7367c478bd9Sstevel@tonic-gate rv1 = rv1 >> 32; 7377c478bd9Sstevel@tonic-gate } 7387c478bd9Sstevel@tonic-gate #endif 7397c478bd9Sstevel@tonic-gate break; 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate if (fmt == NULL) { 7437c478bd9Sstevel@tonic-gate switch (stp->rval[0]) { 7447c478bd9Sstevel@tonic-gate case HEX: 7457c478bd9Sstevel@tonic-gate #ifdef _LP64 7467c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) 7477c478bd9Sstevel@tonic-gate rv1 &= 0xffffffff; 7487c478bd9Sstevel@tonic-gate #endif 7497c478bd9Sstevel@tonic-gate fmt = "= 0x%.8lX"; 7507c478bd9Sstevel@tonic-gate break; 7517c478bd9Sstevel@tonic-gate case HHX: 7527c478bd9Sstevel@tonic-gate #ifdef _LP64 7537c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) 7547c478bd9Sstevel@tonic-gate rv1 &= 0xffffffff; 7557c478bd9Sstevel@tonic-gate #endif 7567c478bd9Sstevel@tonic-gate fmt = "= 0x%.4lX"; 7577c478bd9Sstevel@tonic-gate break; 7587c478bd9Sstevel@tonic-gate case OCT: 7597c478bd9Sstevel@tonic-gate #ifdef _LP64 7607c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) 7617c478bd9Sstevel@tonic-gate rv1 &= 0xffffffff; 7627c478bd9Sstevel@tonic-gate #endif 7637c478bd9Sstevel@tonic-gate fmt = "= %#lo"; 7647c478bd9Sstevel@tonic-gate break; 765f48205beScasper case UNS: 766f48205beScasper #ifdef _LP64 767f48205beScasper if (data_model == PR_MODEL_ILP32) 768f48205beScasper rv1 &= 0xffffffff; 769f48205beScasper #endif 770f48205beScasper fmt = "= %lu"; 771f48205beScasper break; 7727c478bd9Sstevel@tonic-gate default: 7737c478bd9Sstevel@tonic-gate fmt = "= %ld"; 7747c478bd9Sstevel@tonic-gate break; 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate } 7777c478bd9Sstevel@tonic-gate 7787c478bd9Sstevel@tonic-gate (void) printf(fmt, rv1, rv2); 7797c478bd9Sstevel@tonic-gate 7807c478bd9Sstevel@tonic-gate switch (stp->rval[1]) { 7817c478bd9Sstevel@tonic-gate case NOV: 7827c478bd9Sstevel@tonic-gate fmt = NULL; 7837c478bd9Sstevel@tonic-gate break; 7847c478bd9Sstevel@tonic-gate case HEX: 7857c478bd9Sstevel@tonic-gate #ifdef _LP64 7867c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) 7877c478bd9Sstevel@tonic-gate rv2 &= 0xffffffff; 7887c478bd9Sstevel@tonic-gate #endif 7897c478bd9Sstevel@tonic-gate fmt = " [0x%.8lX]"; 7907c478bd9Sstevel@tonic-gate break; 7917c478bd9Sstevel@tonic-gate case HHX: 7927c478bd9Sstevel@tonic-gate #ifdef _LP64 7937c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) 7947c478bd9Sstevel@tonic-gate rv2 &= 0xffffffff; 7957c478bd9Sstevel@tonic-gate #endif 7967c478bd9Sstevel@tonic-gate fmt = " [0x%.4lX]"; 7977c478bd9Sstevel@tonic-gate break; 7987c478bd9Sstevel@tonic-gate case OCT: 7997c478bd9Sstevel@tonic-gate #ifdef _LP64 8007c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_ILP32) 8017c478bd9Sstevel@tonic-gate rv2 &= 0xffffffff; 8027c478bd9Sstevel@tonic-gate #endif 8037c478bd9Sstevel@tonic-gate fmt = " [%#lo]"; 8047c478bd9Sstevel@tonic-gate break; 805f48205beScasper case UNS: 806f48205beScasper #ifdef _LP64 807f48205beScasper if (data_model == PR_MODEL_ILP32) 808f48205beScasper rv2 &= 0xffffffff; 809f48205beScasper #endif 810f48205beScasper fmt = " [%lu]"; 811f48205beScasper break; 8127c478bd9Sstevel@tonic-gate default: 8137c478bd9Sstevel@tonic-gate fmt = " [%ld]"; 8147c478bd9Sstevel@tonic-gate break; 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate if (fmt != NULL) 8187c478bd9Sstevel@tonic-gate (void) printf(fmt, rv2); 8197c478bd9Sstevel@tonic-gate (void) fputc('\n', stdout); 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate 8228fd04b83SRoger A. Faulkner if (what == SYS_vfork || what == SYS_forksys) { 8237c478bd9Sstevel@tonic-gate if (pri->Rval2 == 0) /* child was created */ 8247c478bd9Sstevel@tonic-gate pri->child = pri->Rval1; 8257c478bd9Sstevel@tonic-gate else if (cflag && istraced) /* this is the child */ 8267c478bd9Sstevel@tonic-gate scp->count--; 8277c478bd9Sstevel@tonic-gate } 8287c478bd9Sstevel@tonic-gate if (what == SYS_lwp_create && pri->Rval1 == 0 && 8297c478bd9Sstevel@tonic-gate cflag && istraced) /* this is the created lwp */ 8307c478bd9Sstevel@tonic-gate scp->count--; 8317c478bd9Sstevel@tonic-gate } 8327c478bd9Sstevel@tonic-gate 8337c478bd9Sstevel@tonic-gate #define ISREAD(code) \ 8347c478bd9Sstevel@tonic-gate ((code) == SYS_read || (code) == SYS_pread || (code) == SYS_pread64 || \ 8357c478bd9Sstevel@tonic-gate (code) == SYS_recv || (code) == SYS_recvfrom) 8367c478bd9Sstevel@tonic-gate #define ISWRITE(code) \ 8377c478bd9Sstevel@tonic-gate ((code) == SYS_write || (code) == SYS_pwrite || \ 8387c478bd9Sstevel@tonic-gate (code) == SYS_pwrite64 || (code) == SYS_send || (code) == SYS_sendto) 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate if (!cflag && istraced) { 8417c478bd9Sstevel@tonic-gate int fdp1 = (int)pri->sys_args[0] + 1; /* filedescriptor + 1 */ 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate if (raw) { 8448fd04b83SRoger A. Faulkner if (what != SYS_execve) 8457c478bd9Sstevel@tonic-gate showpaths(pri, stp); 8467c478bd9Sstevel@tonic-gate if (ISREAD(what) || ISWRITE(what)) { 8477c478bd9Sstevel@tonic-gate if (pri->iob_buf[0] != '\0') 8487c478bd9Sstevel@tonic-gate (void) printf("%s 0x%.8lX: %s\n", 8497c478bd9Sstevel@tonic-gate pri->pname, pri->sys_args[1], 8507c478bd9Sstevel@tonic-gate pri->iob_buf); 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate } 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate /* 8557c478bd9Sstevel@tonic-gate * Show buffer contents for read()/pread() or write()/pwrite(). 8567c478bd9Sstevel@tonic-gate * IOBSIZE bytes have already been shown; 8577c478bd9Sstevel@tonic-gate * don't show them again unless there's more. 8587c478bd9Sstevel@tonic-gate */ 8597c478bd9Sstevel@tonic-gate if ((ISREAD(what) && pri->Errno == 0 && 8607c478bd9Sstevel@tonic-gate prismember(&readfd, fdp1)) || 8617c478bd9Sstevel@tonic-gate (ISWRITE(what) && prismember(&writefd, fdp1))) { 8627c478bd9Sstevel@tonic-gate long nb = ISWRITE(what) ? pri->sys_args[2] : pri->Rval1; 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate if (nb > IOBSIZE) { 8657c478bd9Sstevel@tonic-gate /* enter region of lengthy output */ 8667c478bd9Sstevel@tonic-gate if (nb > MYBUFSIZ / 4) 8677c478bd9Sstevel@tonic-gate Eserialize(); 8687c478bd9Sstevel@tonic-gate 8697c478bd9Sstevel@tonic-gate showbuffer(pri, pri->sys_args[1], nb); 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate /* exit region of lengthy output */ 8727c478bd9Sstevel@tonic-gate if (nb > MYBUFSIZ / 4) 8737c478bd9Sstevel@tonic-gate Xserialize(); 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate } 8767c478bd9Sstevel@tonic-gate #undef ISREAD 8777c478bd9Sstevel@tonic-gate #undef ISWRITE 8787c478bd9Sstevel@tonic-gate /* 8797c478bd9Sstevel@tonic-gate * Do verbose interpretation if requested. 8807c478bd9Sstevel@tonic-gate * If buffer contents for read or write have been requested and 8817c478bd9Sstevel@tonic-gate * this is a readv() or writev(), force verbose interpretation. 8827c478bd9Sstevel@tonic-gate */ 8837c478bd9Sstevel@tonic-gate if (prismember(&verbose, what) || 88481006e0fSja97890 ((what == SYS_readv || what == SYS_recvmsg) && 88581006e0fSja97890 pri->Errno == 0 && prismember(&readfd, fdp1)) || 88681006e0fSja97890 ((what == SYS_writev || what == SYS_sendfilev || 88781006e0fSja97890 what == SYS_sendmsg) && 8887c478bd9Sstevel@tonic-gate prismember(&writefd, fdp1))) 8897c478bd9Sstevel@tonic-gate expound(pri, pri->Rval1, raw); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate 8927c478bd9Sstevel@tonic-gate return (!cflag && istraced); 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate 8957c478bd9Sstevel@tonic-gate void 8967c478bd9Sstevel@tonic-gate showpaths(private_t *pri, const struct systable *stp) 8977c478bd9Sstevel@tonic-gate { 8988fd04b83SRoger A. Faulkner int what = pri->lwpstat->pr_what; 8997c478bd9Sstevel@tonic-gate int i; 9007c478bd9Sstevel@tonic-gate 9017c478bd9Sstevel@tonic-gate for (i = 0; i < pri->sys_nargs; i++) { 9028fd04b83SRoger A. Faulkner if (stp->arg[i] == ATC && (int)pri->sys_args[i] == AT_FDCWD) { 9038fd04b83SRoger A. Faulkner (void) printf("%s 0x%.8X: AT_FDCWD\n", 9048fd04b83SRoger A. Faulkner pri->pname, AT_FDCWD); 9058fd04b83SRoger A. Faulkner } else if ((stp->arg[i] == STG) || 9067c478bd9Sstevel@tonic-gate (stp->arg[i] == RST && !pri->Errno) || 9077c478bd9Sstevel@tonic-gate (stp->arg[i] == RLK && !pri->Errno && pri->Rval1 > 0)) { 9087c478bd9Sstevel@tonic-gate long addr = pri->sys_args[i]; 9097c478bd9Sstevel@tonic-gate int maxleng = 9107c478bd9Sstevel@tonic-gate (stp->arg[i] == RLK)? (int)pri->Rval1 : PATH_MAX; 9117c478bd9Sstevel@tonic-gate char *s; 9127c478bd9Sstevel@tonic-gate 9138fd04b83SRoger A. Faulkner if (pri->sys_valid && 9148fd04b83SRoger A. Faulkner ((i == 0 && stp->arg[0] == STG) || 9158fd04b83SRoger A. Faulkner (i == 1 && (what == SYS_openat || 9168fd04b83SRoger A. Faulkner what == SYS_openat64)))) /* already fetched */ 9177c478bd9Sstevel@tonic-gate s = pri->sys_path; 9187c478bd9Sstevel@tonic-gate else 9197c478bd9Sstevel@tonic-gate s = fetchstring(pri, addr, 9207c478bd9Sstevel@tonic-gate maxleng > PATH_MAX ? PATH_MAX : maxleng); 9217c478bd9Sstevel@tonic-gate 9227c478bd9Sstevel@tonic-gate if (s != (char *)NULL) 9237c478bd9Sstevel@tonic-gate (void) printf("%s 0x%.8lX: \"%s\"\n", 9247c478bd9Sstevel@tonic-gate pri->pname, addr, s); 9257c478bd9Sstevel@tonic-gate } 9267c478bd9Sstevel@tonic-gate } 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate 9297c478bd9Sstevel@tonic-gate /* 9307c478bd9Sstevel@tonic-gate * Display arguments to successful exec(). 9317c478bd9Sstevel@tonic-gate */ 9327c478bd9Sstevel@tonic-gate void 9337c478bd9Sstevel@tonic-gate showargs(private_t *pri, int raw) 9347c478bd9Sstevel@tonic-gate { 9357c478bd9Sstevel@tonic-gate const lwpstatus_t *Lsp = pri->lwpstat; 9367c478bd9Sstevel@tonic-gate int nargs; 9377c478bd9Sstevel@tonic-gate long ap; 9387c478bd9Sstevel@tonic-gate int ptrsize; 9397c478bd9Sstevel@tonic-gate int fail; 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate pri->length = 0; 9427c478bd9Sstevel@tonic-gate ptrsize = (data_model == PR_MODEL_LP64)? 8 : 4; 9437c478bd9Sstevel@tonic-gate 9447c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) /* XX64 */ 9457c478bd9Sstevel@tonic-gate ap = (long)Lsp->pr_reg[R_SP]; 9467c478bd9Sstevel@tonic-gate fail = (Pread(Proc, &nargs, sizeof (nargs), ap) != sizeof (nargs)); 9477c478bd9Sstevel@tonic-gate ap += ptrsize; 9487c478bd9Sstevel@tonic-gate #endif /* i386 */ 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate #if sparc 9517c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_LP64) { 9527c478bd9Sstevel@tonic-gate int64_t xnargs; 9537c478bd9Sstevel@tonic-gate ap = (long)(Lsp->pr_reg[R_SP]) + 16 * sizeof (int64_t) 9547c478bd9Sstevel@tonic-gate + STACK_BIAS; 9557c478bd9Sstevel@tonic-gate fail = (Pread(Proc, &xnargs, sizeof (xnargs), ap) != 9567c478bd9Sstevel@tonic-gate sizeof (xnargs)); 9577c478bd9Sstevel@tonic-gate nargs = (int)xnargs; 9587c478bd9Sstevel@tonic-gate } else { 9597c478bd9Sstevel@tonic-gate ap = (long)(Lsp->pr_reg[R_SP]) + 16 * sizeof (int32_t); 9607c478bd9Sstevel@tonic-gate fail = (Pread(Proc, &nargs, sizeof (nargs), ap) != 9617c478bd9Sstevel@tonic-gate sizeof (nargs)); 9627c478bd9Sstevel@tonic-gate } 9637c478bd9Sstevel@tonic-gate ap += ptrsize; 9647c478bd9Sstevel@tonic-gate #endif /* sparc */ 9657c478bd9Sstevel@tonic-gate 9667c478bd9Sstevel@tonic-gate if (fail) { 9677c478bd9Sstevel@tonic-gate (void) printf("\n%s\t*** Bad argument list? ***\n", pri->pname); 9687c478bd9Sstevel@tonic-gate return; 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate (void) printf(" argc = %d\n", nargs); 9727c478bd9Sstevel@tonic-gate if (raw) 9738fd04b83SRoger A. Faulkner showpaths(pri, &systable[SYS_execve]); 9747c478bd9Sstevel@tonic-gate 975*134a1f4eSCasper H.S. Dik show_cred(pri, FALSE, FALSE); 9767c478bd9Sstevel@tonic-gate 9777c478bd9Sstevel@tonic-gate if (aflag || eflag) { /* dump args or environment */ 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate /* enter region of (potentially) lengthy output */ 9807c478bd9Sstevel@tonic-gate Eserialize(); 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate if (aflag) /* dump the argument list */ 9837c478bd9Sstevel@tonic-gate dumpargs(pri, ap, "argv:"); 9847c478bd9Sstevel@tonic-gate ap += (nargs+1) * ptrsize; 9857c478bd9Sstevel@tonic-gate if (eflag) /* dump the environment */ 9867c478bd9Sstevel@tonic-gate dumpargs(pri, ap, "envp:"); 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate /* exit region of lengthy output */ 9897c478bd9Sstevel@tonic-gate Xserialize(); 9907c478bd9Sstevel@tonic-gate } 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate 9937c478bd9Sstevel@tonic-gate void 9947c478bd9Sstevel@tonic-gate dumpargs(private_t *pri, long ap, const char *str) 9957c478bd9Sstevel@tonic-gate { 9967c478bd9Sstevel@tonic-gate char *string; 9977c478bd9Sstevel@tonic-gate unsigned int leng = 0; 9987c478bd9Sstevel@tonic-gate int ptrsize; 9997c478bd9Sstevel@tonic-gate long arg = 0; 10007c478bd9Sstevel@tonic-gate char *argaddr; 10017c478bd9Sstevel@tonic-gate char badaddr[32]; 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate if (interrupt) 10047c478bd9Sstevel@tonic-gate return; 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate #ifdef _LP64 10077c478bd9Sstevel@tonic-gate if (data_model == PR_MODEL_LP64) { 10087c478bd9Sstevel@tonic-gate argaddr = (char *)&arg; 10097c478bd9Sstevel@tonic-gate ptrsize = 8; 10107c478bd9Sstevel@tonic-gate } else { 10117c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 10127c478bd9Sstevel@tonic-gate argaddr = (char *)&arg; 10137c478bd9Sstevel@tonic-gate #else 10147c478bd9Sstevel@tonic-gate argaddr = (char *)&arg + 4; 10157c478bd9Sstevel@tonic-gate #endif 10167c478bd9Sstevel@tonic-gate ptrsize = 4; 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate #else 10197c478bd9Sstevel@tonic-gate argaddr = (char *)&arg; 10207c478bd9Sstevel@tonic-gate ptrsize = 4; 10217c478bd9Sstevel@tonic-gate #endif 10227c478bd9Sstevel@tonic-gate putpname(pri); 10237c478bd9Sstevel@tonic-gate (void) fputc(' ', stdout); 10247c478bd9Sstevel@tonic-gate (void) fputs(str, stdout); 10257c478bd9Sstevel@tonic-gate leng += 1 + strlen(str); 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate while (!interrupt) { 10287c478bd9Sstevel@tonic-gate if (Pread(Proc, argaddr, ptrsize, ap) != ptrsize) { 10297c478bd9Sstevel@tonic-gate (void) printf("\n%s\t*** Bad argument list? ***\n", 10307c478bd9Sstevel@tonic-gate pri->pname); 10317c478bd9Sstevel@tonic-gate return; 10327c478bd9Sstevel@tonic-gate } 10337c478bd9Sstevel@tonic-gate ap += ptrsize; 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate if (arg == 0) 10367c478bd9Sstevel@tonic-gate break; 10377c478bd9Sstevel@tonic-gate string = fetchstring(pri, arg, PATH_MAX); 10387c478bd9Sstevel@tonic-gate if (string == NULL) { 10397c478bd9Sstevel@tonic-gate (void) sprintf(badaddr, "BadAddress:0x%.8lX", arg); 10407c478bd9Sstevel@tonic-gate string = badaddr; 10417c478bd9Sstevel@tonic-gate } 10427c478bd9Sstevel@tonic-gate if ((leng += strlen(string)) < 63) { 10437c478bd9Sstevel@tonic-gate (void) fputc(' ', stdout); 10447c478bd9Sstevel@tonic-gate leng++; 10457c478bd9Sstevel@tonic-gate } else { 10467c478bd9Sstevel@tonic-gate (void) fputc('\n', stdout); 10477c478bd9Sstevel@tonic-gate leng = 0; 10487c478bd9Sstevel@tonic-gate putpname(pri); 10497c478bd9Sstevel@tonic-gate (void) fputs(" ", stdout); 10507c478bd9Sstevel@tonic-gate leng += 2 + strlen(string); 10517c478bd9Sstevel@tonic-gate } 10527c478bd9Sstevel@tonic-gate (void) fputs(string, stdout); 10537c478bd9Sstevel@tonic-gate } 10547c478bd9Sstevel@tonic-gate (void) fputc('\n', stdout); 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate /* 10587c478bd9Sstevel@tonic-gate * Display contents of read() or write() buffer. 10597c478bd9Sstevel@tonic-gate */ 10607c478bd9Sstevel@tonic-gate void 10617c478bd9Sstevel@tonic-gate showbuffer(private_t *pri, long offset, long count) 10627c478bd9Sstevel@tonic-gate { 10637c478bd9Sstevel@tonic-gate char buffer[320]; 10647c478bd9Sstevel@tonic-gate int nbytes; 10657c478bd9Sstevel@tonic-gate char *buf; 10667c478bd9Sstevel@tonic-gate int n; 10677c478bd9Sstevel@tonic-gate 10687c478bd9Sstevel@tonic-gate while (count > 0 && !interrupt) { 10697c478bd9Sstevel@tonic-gate nbytes = (count < sizeof (buffer))? count : sizeof (buffer); 10707c478bd9Sstevel@tonic-gate if ((nbytes = Pread(Proc, buffer, nbytes, offset)) <= 0) 10717c478bd9Sstevel@tonic-gate break; 10727c478bd9Sstevel@tonic-gate count -= nbytes; 10737c478bd9Sstevel@tonic-gate offset += nbytes; 10747c478bd9Sstevel@tonic-gate buf = buffer; 10757c478bd9Sstevel@tonic-gate while (nbytes > 0 && !interrupt) { 10767c478bd9Sstevel@tonic-gate char obuf[65]; 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate n = (nbytes < 32)? nbytes : 32; 10797c478bd9Sstevel@tonic-gate showbytes(buf, n, obuf); 10807c478bd9Sstevel@tonic-gate 10817c478bd9Sstevel@tonic-gate putpname(pri); 10827c478bd9Sstevel@tonic-gate (void) fputs(" ", stdout); 10837c478bd9Sstevel@tonic-gate (void) fputs(obuf, stdout); 10847c478bd9Sstevel@tonic-gate (void) fputc('\n', stdout); 10857c478bd9Sstevel@tonic-gate nbytes -= n; 10867c478bd9Sstevel@tonic-gate buf += n; 10877c478bd9Sstevel@tonic-gate } 10887c478bd9Sstevel@tonic-gate } 10897c478bd9Sstevel@tonic-gate } 10907c478bd9Sstevel@tonic-gate 10917c478bd9Sstevel@tonic-gate void 10927c478bd9Sstevel@tonic-gate showbytes(const char *buf, int n, char *obuf) 10937c478bd9Sstevel@tonic-gate { 10947c478bd9Sstevel@tonic-gate int c; 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate while (--n >= 0) { 10977c478bd9Sstevel@tonic-gate int c1 = '\\'; 10987c478bd9Sstevel@tonic-gate int c2; 10997c478bd9Sstevel@tonic-gate 11007c478bd9Sstevel@tonic-gate switch (c = (*buf++ & 0xff)) { 11017c478bd9Sstevel@tonic-gate case '\0': 11027c478bd9Sstevel@tonic-gate c2 = '0'; 11037c478bd9Sstevel@tonic-gate break; 11047c478bd9Sstevel@tonic-gate case '\b': 11057c478bd9Sstevel@tonic-gate c2 = 'b'; 11067c478bd9Sstevel@tonic-gate break; 11077c478bd9Sstevel@tonic-gate case '\t': 11087c478bd9Sstevel@tonic-gate c2 = 't'; 11097c478bd9Sstevel@tonic-gate break; 11107c478bd9Sstevel@tonic-gate case '\n': 11117c478bd9Sstevel@tonic-gate c2 = 'n'; 11127c478bd9Sstevel@tonic-gate break; 11137c478bd9Sstevel@tonic-gate case '\v': 11147c478bd9Sstevel@tonic-gate c2 = 'v'; 11157c478bd9Sstevel@tonic-gate break; 11167c478bd9Sstevel@tonic-gate case '\f': 11177c478bd9Sstevel@tonic-gate c2 = 'f'; 11187c478bd9Sstevel@tonic-gate break; 11197c478bd9Sstevel@tonic-gate case '\r': 11207c478bd9Sstevel@tonic-gate c2 = 'r'; 11217c478bd9Sstevel@tonic-gate break; 11227c478bd9Sstevel@tonic-gate default: 11237c478bd9Sstevel@tonic-gate if (isprint(c)) { 11247c478bd9Sstevel@tonic-gate c1 = ' '; 11257c478bd9Sstevel@tonic-gate c2 = c; 11267c478bd9Sstevel@tonic-gate } else { 11277c478bd9Sstevel@tonic-gate c1 = c>>4; 11287c478bd9Sstevel@tonic-gate c1 += (c1 < 10)? '0' : 'A'-10; 11297c478bd9Sstevel@tonic-gate c2 = c&0xf; 11307c478bd9Sstevel@tonic-gate c2 += (c2 < 10)? '0' : 'A'-10; 11317c478bd9Sstevel@tonic-gate } 11327c478bd9Sstevel@tonic-gate break; 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate *obuf++ = (char)c1; 11357c478bd9Sstevel@tonic-gate *obuf++ = (char)c2; 11367c478bd9Sstevel@tonic-gate } 11377c478bd9Sstevel@tonic-gate 11387c478bd9Sstevel@tonic-gate *obuf = '\0'; 11397c478bd9Sstevel@tonic-gate } 1140