10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51914Scasper * Common Development and Distribution License (the "License").
61914Scasper * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
213235Sraf
220Sstevel@tonic-gate /*
23*11948SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <stdio.h>
281914Scasper #include <stdio_ext.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <unistd.h>
310Sstevel@tonic-gate #include <ctype.h>
320Sstevel@tonic-gate #include <fcntl.h>
330Sstevel@tonic-gate #include <strings.h>
340Sstevel@tonic-gate #include <dirent.h>
350Sstevel@tonic-gate #include <errno.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/int_fmtio.h>
380Sstevel@tonic-gate #include <libproc.h>
390Sstevel@tonic-gate
400Sstevel@tonic-gate typedef struct look_arg {
410Sstevel@tonic-gate int pflags;
420Sstevel@tonic-gate const char *lwps;
430Sstevel@tonic-gate int count;
440Sstevel@tonic-gate } look_arg_t;
450Sstevel@tonic-gate
460Sstevel@tonic-gate static int look(char *);
470Sstevel@tonic-gate static int lwplook(look_arg_t *, const lwpstatus_t *, const lwpsinfo_t *);
480Sstevel@tonic-gate static char *prflags(int);
490Sstevel@tonic-gate static char *prwhy(int);
500Sstevel@tonic-gate static char *prwhat(int, int);
510Sstevel@tonic-gate static void dumpregs(const prgregset_t, int);
520Sstevel@tonic-gate #if defined(__sparc) && defined(_ILP32)
530Sstevel@tonic-gate static void dumpregs_v8p(const prgregset_t, const prxregset_t *, int);
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate
560Sstevel@tonic-gate static char *command;
570Sstevel@tonic-gate static struct ps_prochandle *Pr;
580Sstevel@tonic-gate
590Sstevel@tonic-gate static int is64; /* Is current process 64-bit? */
600Sstevel@tonic-gate static int rflag; /* Show registers? */
610Sstevel@tonic-gate
620Sstevel@tonic-gate #define LWPFLAGS \
630Sstevel@tonic-gate (PR_STOPPED|PR_ISTOP|PR_DSTOP|PR_ASLEEP|PR_PCINVAL|PR_STEP \
643235Sraf |PR_AGENT|PR_DETACH|PR_DAEMON)
650Sstevel@tonic-gate
660Sstevel@tonic-gate #define PROCFLAGS \
673235Sraf (PR_ISSYS|PR_VFORKP|PR_ORPHAN|PR_NOSIGCHLD|PR_WAITPID \
683235Sraf |PR_FORK|PR_RLC|PR_KLC|PR_ASYNC|PR_BPTADJ|PR_MSACCT|PR_MSFORK|PR_PTRACE)
690Sstevel@tonic-gate
700Sstevel@tonic-gate #define ALLFLAGS (LWPFLAGS|PROCFLAGS)
710Sstevel@tonic-gate
720Sstevel@tonic-gate int
main(int argc,char ** argv)730Sstevel@tonic-gate main(int argc, char **argv)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate int rc = 0;
760Sstevel@tonic-gate int errflg = 0;
770Sstevel@tonic-gate int opt;
780Sstevel@tonic-gate struct rlimit rlim;
790Sstevel@tonic-gate
800Sstevel@tonic-gate if ((command = strrchr(argv[0], '/')) != NULL)
810Sstevel@tonic-gate command++;
820Sstevel@tonic-gate else
830Sstevel@tonic-gate command = argv[0];
840Sstevel@tonic-gate
850Sstevel@tonic-gate /* options */
860Sstevel@tonic-gate while ((opt = getopt(argc, argv, "r")) != EOF) {
870Sstevel@tonic-gate switch (opt) {
880Sstevel@tonic-gate case 'r': /* show registers */
890Sstevel@tonic-gate rflag = 1;
900Sstevel@tonic-gate break;
910Sstevel@tonic-gate default:
920Sstevel@tonic-gate errflg = 1;
930Sstevel@tonic-gate break;
940Sstevel@tonic-gate }
950Sstevel@tonic-gate }
960Sstevel@tonic-gate
970Sstevel@tonic-gate argc -= optind;
980Sstevel@tonic-gate argv += optind;
990Sstevel@tonic-gate
1000Sstevel@tonic-gate if (errflg || argc <= 0) {
1010Sstevel@tonic-gate (void) fprintf(stderr,
1020Sstevel@tonic-gate "usage:\t%s [-r] { pid | core }[/lwps] ...\n", command);
1030Sstevel@tonic-gate (void) fprintf(stderr, " (report process status flags)\n");
1040Sstevel@tonic-gate (void) fprintf(stderr, " -r : report registers\n");
1050Sstevel@tonic-gate return (2);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate * Make sure we'll have enough file descriptors to handle a target
1100Sstevel@tonic-gate * that has many many mappings.
1110Sstevel@tonic-gate */
1120Sstevel@tonic-gate if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
1130Sstevel@tonic-gate rlim.rlim_cur = rlim.rlim_max;
1140Sstevel@tonic-gate (void) setrlimit(RLIMIT_NOFILE, &rlim);
1151914Scasper (void) enable_extended_FILE_stdio(-1, -1);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate while (argc-- > 0)
1190Sstevel@tonic-gate rc += look(*argv++);
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate return (rc);
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate static int
look(char * arg)1250Sstevel@tonic-gate look(char *arg)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate int gcode;
1280Sstevel@tonic-gate int gcode2;
1290Sstevel@tonic-gate pstatus_t pstatus;
1300Sstevel@tonic-gate psinfo_t psinfo;
1310Sstevel@tonic-gate int flags;
1320Sstevel@tonic-gate sigset_t sigmask;
1330Sstevel@tonic-gate fltset_t fltmask;
1340Sstevel@tonic-gate sysset_t entryset;
1350Sstevel@tonic-gate sysset_t exitset;
136*11948SRoger.Faulkner@Sun.COM uint32_t sigtrace, sigtrace1, sigtrace2, fltbits;
137*11948SRoger.Faulkner@Sun.COM uint32_t sigpend, sigpend1, sigpend2;
1380Sstevel@tonic-gate uint32_t *bits;
1390Sstevel@tonic-gate char buf[PRSIGBUFSZ];
1400Sstevel@tonic-gate look_arg_t lookarg;
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate if ((Pr = proc_arg_xgrab(arg, NULL, PR_ARG_ANY,
1430Sstevel@tonic-gate PGRAB_RETAIN | PGRAB_FORCE | PGRAB_RDONLY | PGRAB_NOSTOP, &gcode,
1440Sstevel@tonic-gate &lookarg.lwps)) == NULL) {
1450Sstevel@tonic-gate if (gcode == G_NOPROC &&
1460Sstevel@tonic-gate proc_arg_psinfo(arg, PR_ARG_PIDS, &psinfo, &gcode2) > 0 &&
1470Sstevel@tonic-gate psinfo.pr_nlwp == 0) {
1480Sstevel@tonic-gate (void) printf("%d:\t<defunct>\n\n", (int)psinfo.pr_pid);
1490Sstevel@tonic-gate return (0);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate (void) fprintf(stderr, "%s: cannot examine %s: %s\n",
152*11948SRoger.Faulkner@Sun.COM command, arg, Pgrab_error(gcode));
1530Sstevel@tonic-gate return (1);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate (void) memcpy(&pstatus, Pstatus(Pr), sizeof (pstatus_t));
1570Sstevel@tonic-gate (void) memcpy(&psinfo, Ppsinfo(Pr), sizeof (psinfo_t));
1580Sstevel@tonic-gate proc_unctrl_psinfo(&psinfo);
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate if (psinfo.pr_nlwp == 0) {
1610Sstevel@tonic-gate (void) printf("%d:\t<defunct>\n\n", (int)psinfo.pr_pid);
1620Sstevel@tonic-gate Prelease(Pr, PRELEASE_RETAIN);
1630Sstevel@tonic-gate return (0);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate is64 = (pstatus.pr_dmodel == PR_MODEL_LP64);
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate sigmask = pstatus.pr_sigtrace;
1690Sstevel@tonic-gate fltmask = pstatus.pr_flttrace;
1700Sstevel@tonic-gate entryset = pstatus.pr_sysentry;
1710Sstevel@tonic-gate exitset = pstatus.pr_sysexit;
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate if (Pstate(Pr) == PS_DEAD) {
1740Sstevel@tonic-gate (void) printf("core '%s' of %d:\t%.70s\n",
1750Sstevel@tonic-gate arg, (int)psinfo.pr_pid, psinfo.pr_psargs);
1760Sstevel@tonic-gate } else {
1770Sstevel@tonic-gate (void) printf("%d:\t%.70s\n",
1780Sstevel@tonic-gate (int)psinfo.pr_pid, psinfo.pr_psargs);
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate (void) printf("\tdata model = %s", is64? "_LP64" : "_ILP32");
1820Sstevel@tonic-gate if ((flags = (pstatus.pr_flags & PROCFLAGS)) != 0)
1830Sstevel@tonic-gate (void) printf(" flags = %s", prflags(flags));
1840Sstevel@tonic-gate (void) printf("\n");
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate fltbits = *((uint32_t *)&fltmask);
1870Sstevel@tonic-gate if (fltbits)
1880Sstevel@tonic-gate (void) printf("\tflttrace = 0x%.8x\n", fltbits);
1890Sstevel@tonic-gate
190*11948SRoger.Faulkner@Sun.COM #if (MAXSIG > 2 * 32) && (MAXSIG <= 3 * 32) /* assumption */
1910Sstevel@tonic-gate sigtrace = *((uint32_t *)&sigmask);
192*11948SRoger.Faulkner@Sun.COM sigtrace1 = *((uint32_t *)&sigmask + 1);
193*11948SRoger.Faulkner@Sun.COM sigtrace2 = *((uint32_t *)&sigmask + 2);
194*11948SRoger.Faulkner@Sun.COM #else
195*11948SRoger.Faulkner@Sun.COM #error "fix me: MAXSIG out of bounds"
196*11948SRoger.Faulkner@Sun.COM #endif
197*11948SRoger.Faulkner@Sun.COM if (sigtrace | sigtrace1 | sigtrace2)
198*11948SRoger.Faulkner@Sun.COM (void) printf("\tsigtrace = 0x%.8x 0x%.8x 0x%.8x\n\t %s\n",
199*11948SRoger.Faulkner@Sun.COM sigtrace, sigtrace1, sigtrace2,
2000Sstevel@tonic-gate proc_sigset2str(&sigmask, "|", 1, buf, sizeof (buf)));
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate bits = ((uint32_t *)&entryset);
2030Sstevel@tonic-gate if (bits[0] | bits[1] | bits[2] | bits[3] |
2040Sstevel@tonic-gate bits[4] | bits[5] | bits[6] | bits[7])
2050Sstevel@tonic-gate (void) printf(
206*11948SRoger.Faulkner@Sun.COM "\tentryset = "
207*11948SRoger.Faulkner@Sun.COM "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n"
208*11948SRoger.Faulkner@Sun.COM "\t "
209*11948SRoger.Faulkner@Sun.COM "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n",
210*11948SRoger.Faulkner@Sun.COM bits[0], bits[1], bits[2], bits[3],
211*11948SRoger.Faulkner@Sun.COM bits[4], bits[5], bits[6], bits[7]);
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate bits = ((uint32_t *)&exitset);
2140Sstevel@tonic-gate if (bits[0] | bits[1] | bits[2] | bits[3] |
2150Sstevel@tonic-gate bits[4] | bits[5] | bits[6] | bits[7])
2160Sstevel@tonic-gate (void) printf(
217*11948SRoger.Faulkner@Sun.COM "\texitset = "
218*11948SRoger.Faulkner@Sun.COM "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n"
219*11948SRoger.Faulkner@Sun.COM "\t "
220*11948SRoger.Faulkner@Sun.COM "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n",
221*11948SRoger.Faulkner@Sun.COM bits[0], bits[1], bits[2], bits[3],
222*11948SRoger.Faulkner@Sun.COM bits[4], bits[5], bits[6], bits[7]);
2230Sstevel@tonic-gate
224*11948SRoger.Faulkner@Sun.COM #if (MAXSIG > 2 * 32) && (MAXSIG <= 3 * 32) /* assumption */
2250Sstevel@tonic-gate sigpend = *((uint32_t *)&pstatus.pr_sigpend);
226*11948SRoger.Faulkner@Sun.COM sigpend1 = *((uint32_t *)&pstatus.pr_sigpend + 1);
227*11948SRoger.Faulkner@Sun.COM sigpend2 = *((uint32_t *)&pstatus.pr_sigpend + 2);
228*11948SRoger.Faulkner@Sun.COM #else
229*11948SRoger.Faulkner@Sun.COM #error "fix me: MAXSIG out of bounds"
230*11948SRoger.Faulkner@Sun.COM #endif
231*11948SRoger.Faulkner@Sun.COM if (sigpend | sigpend1 | sigpend2)
232*11948SRoger.Faulkner@Sun.COM (void) printf("\tsigpend = 0x%.8x,0x%.8x,0x%.8x\n",
233*11948SRoger.Faulkner@Sun.COM sigpend, sigpend1, sigpend2);
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate lookarg.pflags = pstatus.pr_flags;
2360Sstevel@tonic-gate lookarg.count = 0;
2370Sstevel@tonic-gate (void) Plwp_iter_all(Pr, (proc_lwp_all_f *)lwplook, &lookarg);
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate if (lookarg.count == 0)
2400Sstevel@tonic-gate (void) printf("No matching lwps found");
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate (void) printf("\n");
2430Sstevel@tonic-gate Prelease(Pr, PRELEASE_RETAIN);
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate return (0);
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate
2480Sstevel@tonic-gate static int
lwplook_zombie(const lwpsinfo_t * pip)2490Sstevel@tonic-gate lwplook_zombie(const lwpsinfo_t *pip)
2500Sstevel@tonic-gate {
2510Sstevel@tonic-gate (void) printf(" /%d:\t<defunct>\n", (int)pip->pr_lwpid);
2520Sstevel@tonic-gate return (0);
2530Sstevel@tonic-gate }
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate static int
lwplook(look_arg_t * arg,const lwpstatus_t * psp,const lwpsinfo_t * pip)2560Sstevel@tonic-gate lwplook(look_arg_t *arg, const lwpstatus_t *psp, const lwpsinfo_t *pip)
2570Sstevel@tonic-gate {
2580Sstevel@tonic-gate int flags;
259*11948SRoger.Faulkner@Sun.COM uint32_t sighold, sighold1, sighold2;
260*11948SRoger.Faulkner@Sun.COM uint32_t sigpend, sigpend1, sigpend2;
2610Sstevel@tonic-gate int cursig;
2620Sstevel@tonic-gate char buf[32];
2630Sstevel@tonic-gate
2640Sstevel@tonic-gate if (!proc_lwp_in_set(arg->lwps, pip->pr_lwpid))
2650Sstevel@tonic-gate return (0);
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate arg->count++;
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate if (psp == NULL)
2700Sstevel@tonic-gate return (lwplook_zombie(pip));
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate /*
2730Sstevel@tonic-gate * PR_PCINVAL is just noise if the lwp is not stopped.
2740Sstevel@tonic-gate * Don't bother reporting it unless the lwp is stopped.
2750Sstevel@tonic-gate */
2760Sstevel@tonic-gate flags = psp->pr_flags & LWPFLAGS;
2770Sstevel@tonic-gate if (!(flags & PR_STOPPED))
2780Sstevel@tonic-gate flags &= ~PR_PCINVAL;
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate (void) printf(" /%d:\tflags = %s", (int)psp->pr_lwpid, prflags(flags));
2810Sstevel@tonic-gate if ((flags & PR_ASLEEP) || (psp->pr_syscall &&
2820Sstevel@tonic-gate !(arg->pflags & PR_ISSYS))) {
2830Sstevel@tonic-gate if (flags & PR_ASLEEP) {
2840Sstevel@tonic-gate if ((flags & ~PR_ASLEEP) != 0)
2850Sstevel@tonic-gate (void) printf("|");
2860Sstevel@tonic-gate (void) printf("ASLEEP");
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate if (psp->pr_syscall && !(arg->pflags & PR_ISSYS)) {
2890Sstevel@tonic-gate uint_t i;
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate (void) printf(" %s(",
2920Sstevel@tonic-gate proc_sysname(psp->pr_syscall, buf, sizeof (buf)));
2930Sstevel@tonic-gate for (i = 0; i < psp->pr_nsysarg; i++) {
2940Sstevel@tonic-gate if (i != 0)
2950Sstevel@tonic-gate (void) printf(",");
2960Sstevel@tonic-gate (void) printf("0x%lx", psp->pr_sysarg[i]);
2970Sstevel@tonic-gate }
2980Sstevel@tonic-gate (void) printf(")");
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate (void) printf("\n");
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate if (flags & PR_STOPPED) {
3040Sstevel@tonic-gate (void) printf("\twhy = %s", prwhy(psp->pr_why));
3050Sstevel@tonic-gate if (psp->pr_why != PR_REQUESTED &&
3060Sstevel@tonic-gate psp->pr_why != PR_SUSPENDED)
3070Sstevel@tonic-gate (void) printf(" what = %s",
308*11948SRoger.Faulkner@Sun.COM prwhat(psp->pr_why, psp->pr_what));
3090Sstevel@tonic-gate (void) printf("\n");
3100Sstevel@tonic-gate }
3110Sstevel@tonic-gate
312*11948SRoger.Faulkner@Sun.COM #if (MAXSIG > 2 * 32) && (MAXSIG <= 3 * 32) /* assumption */
3130Sstevel@tonic-gate sighold = *((uint32_t *)&psp->pr_lwphold);
314*11948SRoger.Faulkner@Sun.COM sighold1 = *((uint32_t *)&psp->pr_lwphold + 1);
315*11948SRoger.Faulkner@Sun.COM sighold2 = *((uint32_t *)&psp->pr_lwphold + 2);
3160Sstevel@tonic-gate sigpend = *((uint32_t *)&psp->pr_lwppend);
317*11948SRoger.Faulkner@Sun.COM sigpend1 = *((uint32_t *)&psp->pr_lwppend + 1);
318*11948SRoger.Faulkner@Sun.COM sigpend2 = *((uint32_t *)&psp->pr_lwppend + 2);
319*11948SRoger.Faulkner@Sun.COM #else
320*11948SRoger.Faulkner@Sun.COM #error "fix me: MAXSIG out of bounds"
321*11948SRoger.Faulkner@Sun.COM #endif
3220Sstevel@tonic-gate cursig = psp->pr_cursig;
3230Sstevel@tonic-gate
324*11948SRoger.Faulkner@Sun.COM if (sighold | sighold1 | sighold2)
325*11948SRoger.Faulkner@Sun.COM (void) printf("\tsigmask = 0x%.8x,0x%.8x,0x%.8x\n",
326*11948SRoger.Faulkner@Sun.COM sighold, sighold1, sighold2);
327*11948SRoger.Faulkner@Sun.COM if (sigpend | sigpend1 | sigpend2)
328*11948SRoger.Faulkner@Sun.COM (void) printf("\tlwppend = 0x%.8x,0x%.8x,0x%.8x\n",
329*11948SRoger.Faulkner@Sun.COM sigpend, sigpend1, sigpend2);
330*11948SRoger.Faulkner@Sun.COM if (cursig)
331*11948SRoger.Faulkner@Sun.COM (void) printf("\tcursig = %s\n",
332*11948SRoger.Faulkner@Sun.COM proc_signame(cursig, buf, sizeof (buf)));
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate if (rflag) {
3350Sstevel@tonic-gate if (Pstate(Pr) == PS_DEAD || (arg->pflags & PR_STOPPED)) {
3360Sstevel@tonic-gate #if defined(__sparc) && defined(_ILP32)
3370Sstevel@tonic-gate /*
3380Sstevel@tonic-gate * If we're SPARC/32-bit, see if we can get extra
3390Sstevel@tonic-gate * register state for this lwp. If it's a v8plus
3400Sstevel@tonic-gate * program, print the 64-bit register values.
3410Sstevel@tonic-gate */
3420Sstevel@tonic-gate prxregset_t prx;
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate if (Plwp_getxregs(Pr, psp->pr_lwpid, &prx) == 0 &&
3450Sstevel@tonic-gate prx.pr_type == XR_TYPE_V8P)
3460Sstevel@tonic-gate dumpregs_v8p(psp->pr_reg, &prx, is64);
3470Sstevel@tonic-gate else
3480Sstevel@tonic-gate #endif /* __sparc && _ILP32 */
3490Sstevel@tonic-gate dumpregs(psp->pr_reg, is64);
3500Sstevel@tonic-gate } else
3510Sstevel@tonic-gate (void) printf("\tNot stopped, can't show registers\n");
3520Sstevel@tonic-gate }
3530Sstevel@tonic-gate
3540Sstevel@tonic-gate return (0);
3550Sstevel@tonic-gate }
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate static char *
prflags(int arg)3580Sstevel@tonic-gate prflags(int arg)
3590Sstevel@tonic-gate {
3600Sstevel@tonic-gate static char code_buf[200];
3610Sstevel@tonic-gate char *str = code_buf;
3620Sstevel@tonic-gate
3630Sstevel@tonic-gate if (arg == 0)
3640Sstevel@tonic-gate return ("0");
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate if (arg & ~ALLFLAGS)
3670Sstevel@tonic-gate (void) sprintf(str, "0x%x", arg & ~ALLFLAGS);
3680Sstevel@tonic-gate else
3690Sstevel@tonic-gate *str = '\0';
3700Sstevel@tonic-gate
3710Sstevel@tonic-gate /*
3720Sstevel@tonic-gate * Display the semi-permanent lwp flags first.
3730Sstevel@tonic-gate */
3740Sstevel@tonic-gate if (arg & PR_DAEMON) /* daemons are always detached so */
3750Sstevel@tonic-gate (void) strcat(str, "|DAEMON");
3760Sstevel@tonic-gate else if (arg & PR_DETACH) /* report detach only if non-daemon */
3770Sstevel@tonic-gate (void) strcat(str, "|DETACH");
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate if (arg & PR_STOPPED)
3800Sstevel@tonic-gate (void) strcat(str, "|STOPPED");
3810Sstevel@tonic-gate if (arg & PR_ISTOP)
3820Sstevel@tonic-gate (void) strcat(str, "|ISTOP");
3830Sstevel@tonic-gate if (arg & PR_DSTOP)
3840Sstevel@tonic-gate (void) strcat(str, "|DSTOP");
3850Sstevel@tonic-gate #if 0 /* displayed elsewhere */
3860Sstevel@tonic-gate if (arg & PR_ASLEEP)
3870Sstevel@tonic-gate (void) strcat(str, "|ASLEEP");
3880Sstevel@tonic-gate #endif
3890Sstevel@tonic-gate if (arg & PR_PCINVAL)
3900Sstevel@tonic-gate (void) strcat(str, "|PCINVAL");
3910Sstevel@tonic-gate if (arg & PR_STEP)
3920Sstevel@tonic-gate (void) strcat(str, "|STEP");
3930Sstevel@tonic-gate if (arg & PR_AGENT)
3940Sstevel@tonic-gate (void) strcat(str, "|AGENT");
3950Sstevel@tonic-gate if (arg & PR_ISSYS)
3960Sstevel@tonic-gate (void) strcat(str, "|ISSYS");
3970Sstevel@tonic-gate if (arg & PR_VFORKP)
3980Sstevel@tonic-gate (void) strcat(str, "|VFORKP");
3990Sstevel@tonic-gate if (arg & PR_ORPHAN)
4000Sstevel@tonic-gate (void) strcat(str, "|ORPHAN");
4013235Sraf if (arg & PR_NOSIGCHLD)
4023235Sraf (void) strcat(str, "|NOSIGCHLD");
4033235Sraf if (arg & PR_WAITPID)
4043235Sraf (void) strcat(str, "|WAITPID");
4050Sstevel@tonic-gate if (arg & PR_FORK)
4060Sstevel@tonic-gate (void) strcat(str, "|FORK");
4070Sstevel@tonic-gate if (arg & PR_RLC)
4080Sstevel@tonic-gate (void) strcat(str, "|RLC");
4090Sstevel@tonic-gate if (arg & PR_KLC)
4100Sstevel@tonic-gate (void) strcat(str, "|KLC");
4110Sstevel@tonic-gate if (arg & PR_ASYNC)
4120Sstevel@tonic-gate (void) strcat(str, "|ASYNC");
4130Sstevel@tonic-gate if (arg & PR_BPTADJ)
4140Sstevel@tonic-gate (void) strcat(str, "|BPTADJ");
4150Sstevel@tonic-gate if (arg & PR_MSACCT)
4160Sstevel@tonic-gate (void) strcat(str, "|MSACCT");
4170Sstevel@tonic-gate if (arg & PR_MSFORK)
4180Sstevel@tonic-gate (void) strcat(str, "|MSFORK");
4190Sstevel@tonic-gate if (arg & PR_PTRACE)
4200Sstevel@tonic-gate (void) strcat(str, "|PTRACE");
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate if (*str == '|')
4230Sstevel@tonic-gate str++;
4240Sstevel@tonic-gate
4250Sstevel@tonic-gate return (str);
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate static char *
prwhy(int why)4290Sstevel@tonic-gate prwhy(int why)
4300Sstevel@tonic-gate {
4310Sstevel@tonic-gate static char buf[20];
4320Sstevel@tonic-gate char *str;
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate switch (why) {
4350Sstevel@tonic-gate case PR_REQUESTED:
4360Sstevel@tonic-gate str = "PR_REQUESTED";
4370Sstevel@tonic-gate break;
4380Sstevel@tonic-gate case PR_SIGNALLED:
4390Sstevel@tonic-gate str = "PR_SIGNALLED";
4400Sstevel@tonic-gate break;
4410Sstevel@tonic-gate case PR_SYSENTRY:
4420Sstevel@tonic-gate str = "PR_SYSENTRY";
4430Sstevel@tonic-gate break;
4440Sstevel@tonic-gate case PR_SYSEXIT:
4450Sstevel@tonic-gate str = "PR_SYSEXIT";
4460Sstevel@tonic-gate break;
4470Sstevel@tonic-gate case PR_JOBCONTROL:
4480Sstevel@tonic-gate str = "PR_JOBCONTROL";
4490Sstevel@tonic-gate break;
4500Sstevel@tonic-gate case PR_FAULTED:
4510Sstevel@tonic-gate str = "PR_FAULTED";
4520Sstevel@tonic-gate break;
4530Sstevel@tonic-gate case PR_SUSPENDED:
4540Sstevel@tonic-gate str = "PR_SUSPENDED";
4550Sstevel@tonic-gate break;
4560Sstevel@tonic-gate default:
4570Sstevel@tonic-gate str = buf;
4580Sstevel@tonic-gate (void) sprintf(str, "%d", why);
4590Sstevel@tonic-gate break;
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate return (str);
4630Sstevel@tonic-gate }
4640Sstevel@tonic-gate
4650Sstevel@tonic-gate static char *
prwhat(int why,int what)4660Sstevel@tonic-gate prwhat(int why, int what)
4670Sstevel@tonic-gate {
4680Sstevel@tonic-gate static char buf[32];
4690Sstevel@tonic-gate char *str;
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate switch (why) {
4720Sstevel@tonic-gate case PR_SIGNALLED:
4730Sstevel@tonic-gate case PR_JOBCONTROL:
4740Sstevel@tonic-gate str = proc_signame(what, buf, sizeof (buf));
4750Sstevel@tonic-gate break;
4760Sstevel@tonic-gate case PR_SYSENTRY:
4770Sstevel@tonic-gate case PR_SYSEXIT:
4780Sstevel@tonic-gate str = proc_sysname(what, buf, sizeof (buf));
4790Sstevel@tonic-gate break;
4800Sstevel@tonic-gate case PR_FAULTED:
4810Sstevel@tonic-gate str = proc_fltname(what, buf, sizeof (buf));
4820Sstevel@tonic-gate break;
4830Sstevel@tonic-gate default:
4840Sstevel@tonic-gate (void) sprintf(str = buf, "%d", what);
4850Sstevel@tonic-gate break;
4860Sstevel@tonic-gate }
4870Sstevel@tonic-gate
4880Sstevel@tonic-gate return (str);
4890Sstevel@tonic-gate }
4900Sstevel@tonic-gate
4910Sstevel@tonic-gate #if defined(__sparc)
4920Sstevel@tonic-gate static const char * const regname[NPRGREG] = {
4930Sstevel@tonic-gate " %g0", " %g1", " %g2", " %g3", " %g4", " %g5", " %g6", " %g7",
4940Sstevel@tonic-gate " %o0", " %o1", " %o2", " %o3", " %o4", " %o5", " %sp", " %o7",
4950Sstevel@tonic-gate " %l0", " %l1", " %l2", " %l3", " %l4", " %l5", " %l6", " %l7",
4960Sstevel@tonic-gate " %i0", " %i1", " %i2", " %i3", " %i4", " %i5", " %fp", " %i7",
4970Sstevel@tonic-gate #ifdef __sparcv9
4980Sstevel@tonic-gate "%ccr", " %pc", "%npc", " %y", "%asi", "%fprs"
4990Sstevel@tonic-gate #else
5000Sstevel@tonic-gate "%psr", " %pc", "%npc", " %y", "%wim", "%tbr"
5010Sstevel@tonic-gate #endif
5020Sstevel@tonic-gate };
5030Sstevel@tonic-gate #endif /* __sparc */
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate #if defined(__amd64)
5060Sstevel@tonic-gate static const char * const regname[NPRGREG] = {
5070Sstevel@tonic-gate "%r15", "%r14", "%r13", "%r12", "%r11", "%r10", " %r9", " %r8",
5080Sstevel@tonic-gate "%rdi", "%rsi", "%rbp", "%rbx", "%rdx", "%rcx", "%rax", "%trapno",
5090Sstevel@tonic-gate "%err", "%rip", " %cs", "%rfl", "%rsp", " %ss", " %fs", " %gs",
5100Sstevel@tonic-gate " %es", " %ds", "%fsbase", "%gsbase"
5110Sstevel@tonic-gate };
5120Sstevel@tonic-gate
5130Sstevel@tonic-gate static const char * const regname32[NPRGREG32] = {
5140Sstevel@tonic-gate " %gs", " %fs", " %es", " %ds", "%edi", "%esi", "%ebp", "%esp",
5150Sstevel@tonic-gate "%ebx", "%edx", "%ecx", "%eax", "%trapno", "%err", "%eip", " %cs",
5160Sstevel@tonic-gate "%efl", "%uesp", " %ss"
5170Sstevel@tonic-gate };
5180Sstevel@tonic-gate
5190Sstevel@tonic-gate /* XX64 Do we want to expose this through libproc */
5200Sstevel@tonic-gate void
prgregset_n_to_32(const prgreg_t * src,prgreg32_t * dst)5210Sstevel@tonic-gate prgregset_n_to_32(const prgreg_t *src, prgreg32_t *dst)
5220Sstevel@tonic-gate {
5230Sstevel@tonic-gate bzero(dst, NPRGREG32 * sizeof (prgreg32_t));
5240Sstevel@tonic-gate dst[GS] = src[REG_GS];
5250Sstevel@tonic-gate dst[FS] = src[REG_FS];
5260Sstevel@tonic-gate dst[DS] = src[REG_DS];
5270Sstevel@tonic-gate dst[ES] = src[REG_ES];
5280Sstevel@tonic-gate dst[EDI] = src[REG_RDI];
5290Sstevel@tonic-gate dst[ESI] = src[REG_RSI];
5300Sstevel@tonic-gate dst[EBP] = src[REG_RBP];
5310Sstevel@tonic-gate dst[EBX] = src[REG_RBX];
5320Sstevel@tonic-gate dst[EDX] = src[REG_RDX];
5330Sstevel@tonic-gate dst[ECX] = src[REG_RCX];
5340Sstevel@tonic-gate dst[EAX] = src[REG_RAX];
5350Sstevel@tonic-gate dst[TRAPNO] = src[REG_TRAPNO];
5360Sstevel@tonic-gate dst[ERR] = src[REG_ERR];
5370Sstevel@tonic-gate dst[EIP] = src[REG_RIP];
5380Sstevel@tonic-gate dst[CS] = src[REG_CS];
5390Sstevel@tonic-gate dst[EFL] = src[REG_RFL];
5400Sstevel@tonic-gate dst[UESP] = src[REG_RSP];
5410Sstevel@tonic-gate dst[SS] = src[REG_SS];
5420Sstevel@tonic-gate }
5430Sstevel@tonic-gate
5440Sstevel@tonic-gate #elif defined(__i386)
5450Sstevel@tonic-gate static const char * const regname[NPRGREG] = {
5460Sstevel@tonic-gate " %gs", " %fs", " %es", " %ds", "%edi", "%esi", "%ebp", "%esp",
5470Sstevel@tonic-gate "%ebx", "%edx", "%ecx", "%eax", "%trapno", "%err", "%eip", " %cs",
5480Sstevel@tonic-gate "%efl", "%uesp", " %ss"
5490Sstevel@tonic-gate };
5500Sstevel@tonic-gate #endif /* __i386 */
5510Sstevel@tonic-gate
5520Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
5530Sstevel@tonic-gate static void
dumpregs32(const prgregset_t reg)5540Sstevel@tonic-gate dumpregs32(const prgregset_t reg)
5550Sstevel@tonic-gate {
5560Sstevel@tonic-gate prgregset32_t reg32;
5570Sstevel@tonic-gate int i;
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate prgregset_n_to_32(reg, reg32);
5600Sstevel@tonic-gate
5610Sstevel@tonic-gate for (i = 0; i < NPRGREG32; i++) {
5620Sstevel@tonic-gate (void) printf(" %s = 0x%.8X",
563*11948SRoger.Faulkner@Sun.COM regname32[i], reg32[i]);
5640Sstevel@tonic-gate if ((i+1) % 4 == 0)
5650Sstevel@tonic-gate (void) putchar('\n');
5660Sstevel@tonic-gate }
5670Sstevel@tonic-gate if (i % 4 != 0)
5680Sstevel@tonic-gate (void) putchar('\n');
5690Sstevel@tonic-gate }
5700Sstevel@tonic-gate #endif
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate static void
dumpregs(const prgregset_t reg,int is64)5730Sstevel@tonic-gate dumpregs(const prgregset_t reg, int is64)
5740Sstevel@tonic-gate {
5750Sstevel@tonic-gate int width = is64? 16 : 8;
5760Sstevel@tonic-gate int cols = is64? 2 : 4;
5770Sstevel@tonic-gate int i;
5780Sstevel@tonic-gate
5790Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64)
5800Sstevel@tonic-gate if (!is64) {
5810Sstevel@tonic-gate dumpregs32(reg);
5820Sstevel@tonic-gate return;
5830Sstevel@tonic-gate }
5840Sstevel@tonic-gate #endif
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate for (i = 0; i < NPRGREG; i++) {
5870Sstevel@tonic-gate (void) printf(" %s = 0x%.*lX",
588*11948SRoger.Faulkner@Sun.COM regname[i], width, (long)reg[i]);
5890Sstevel@tonic-gate if ((i+1) % cols == 0)
5900Sstevel@tonic-gate (void) putchar('\n');
5910Sstevel@tonic-gate }
5920Sstevel@tonic-gate if (i % cols != 0)
5930Sstevel@tonic-gate (void) putchar('\n');
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate
5960Sstevel@tonic-gate #if defined(__sparc) && defined(_ILP32)
5970Sstevel@tonic-gate static void
dumpregs_v8p(const prgregset_t reg,const prxregset_t * xreg,int is64)5980Sstevel@tonic-gate dumpregs_v8p(const prgregset_t reg, const prxregset_t *xreg, int is64)
5990Sstevel@tonic-gate {
6000Sstevel@tonic-gate static const uint32_t zero[8] = { 0 };
6010Sstevel@tonic-gate int gr, xr, cols = 2;
6020Sstevel@tonic-gate uint64_t xval;
6030Sstevel@tonic-gate
6040Sstevel@tonic-gate if (memcmp(xreg->pr_un.pr_v8p.pr_xg, zero, sizeof (zero)) == 0 &&
6050Sstevel@tonic-gate memcmp(xreg->pr_un.pr_v8p.pr_xo, zero, sizeof (zero)) == 0) {
6060Sstevel@tonic-gate dumpregs(reg, is64);
6070Sstevel@tonic-gate return;
6080Sstevel@tonic-gate }
6090Sstevel@tonic-gate
6100Sstevel@tonic-gate for (gr = R_G0, xr = XR_G0; gr <= R_G7; gr++, xr++) {
6110Sstevel@tonic-gate xval = (uint64_t)xreg->pr_un.pr_v8p.pr_xg[xr] << 32 |
6120Sstevel@tonic-gate (uint64_t)(uint32_t)reg[gr];
6130Sstevel@tonic-gate (void) printf(" %s = 0x%.16" PRIX64, regname[gr], xval);
6140Sstevel@tonic-gate if ((gr + 1) % cols == 0)
6150Sstevel@tonic-gate (void) putchar('\n');
6160Sstevel@tonic-gate }
6170Sstevel@tonic-gate
6180Sstevel@tonic-gate for (gr = R_O0, xr = XR_O0; gr <= R_O7; gr++, xr++) {
6190Sstevel@tonic-gate xval = (uint64_t)xreg->pr_un.pr_v8p.pr_xo[xr] << 32 |
6200Sstevel@tonic-gate (uint64_t)(uint32_t)reg[gr];
6210Sstevel@tonic-gate (void) printf(" %s = 0x%.16" PRIX64, regname[gr], xval);
6220Sstevel@tonic-gate if ((gr + 1) % cols == 0)
6230Sstevel@tonic-gate (void) putchar('\n');
6240Sstevel@tonic-gate }
6250Sstevel@tonic-gate
6260Sstevel@tonic-gate for (gr = R_L0; gr < NPRGREG; gr++) {
6270Sstevel@tonic-gate (void) printf(" %s = 0x%.8lX",
6280Sstevel@tonic-gate regname[gr], (long)reg[gr]);
6290Sstevel@tonic-gate if ((gr + 1) % cols == 0)
6300Sstevel@tonic-gate (void) putchar('\n');
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate
6330Sstevel@tonic-gate if (gr % cols != 0)
6340Sstevel@tonic-gate (void) putchar('\n');
6350Sstevel@tonic-gate }
6360Sstevel@tonic-gate #endif /* __sparc && _ILP32 */
637