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 5*004388ebScasper * Common Development and Distribution License (the "License"). 6*004388ebScasper * 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 */ 217c478bd9Sstevel@tonic-gate /* 22*004388ebScasper * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <stdio.h> 29*004388ebScasper #include <stdio_ext.h> 307c478bd9Sstevel@tonic-gate #include <stdlib.h> 317c478bd9Sstevel@tonic-gate #include <unistd.h> 327c478bd9Sstevel@tonic-gate #include <ctype.h> 337c478bd9Sstevel@tonic-gate #include <fcntl.h> 347c478bd9Sstevel@tonic-gate #include <strings.h> 357c478bd9Sstevel@tonic-gate #include <dirent.h> 367c478bd9Sstevel@tonic-gate #include <errno.h> 377c478bd9Sstevel@tonic-gate #include <sys/types.h> 387c478bd9Sstevel@tonic-gate #include <sys/int_fmtio.h> 397c478bd9Sstevel@tonic-gate #include <libproc.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate typedef struct look_arg { 427c478bd9Sstevel@tonic-gate int pflags; 437c478bd9Sstevel@tonic-gate const char *lwps; 447c478bd9Sstevel@tonic-gate int count; 457c478bd9Sstevel@tonic-gate } look_arg_t; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate static int look(char *); 487c478bd9Sstevel@tonic-gate static int lwplook(look_arg_t *, const lwpstatus_t *, const lwpsinfo_t *); 497c478bd9Sstevel@tonic-gate static char *prflags(int); 507c478bd9Sstevel@tonic-gate static char *prwhy(int); 517c478bd9Sstevel@tonic-gate static char *prwhat(int, int); 527c478bd9Sstevel@tonic-gate static void dumpregs(const prgregset_t, int); 537c478bd9Sstevel@tonic-gate #if defined(__sparc) && defined(_ILP32) 547c478bd9Sstevel@tonic-gate static void dumpregs_v8p(const prgregset_t, const prxregset_t *, int); 557c478bd9Sstevel@tonic-gate #endif 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate static char *command; 587c478bd9Sstevel@tonic-gate static struct ps_prochandle *Pr; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate static int is64; /* Is current process 64-bit? */ 617c478bd9Sstevel@tonic-gate static int rflag; /* Show registers? */ 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #define LWPFLAGS \ 647c478bd9Sstevel@tonic-gate (PR_STOPPED|PR_ISTOP|PR_DSTOP|PR_ASLEEP|PR_PCINVAL|PR_STEP \ 657c478bd9Sstevel@tonic-gate |PR_ASLWP|PR_AGENT|PR_DETACH|PR_DAEMON) 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate #define PROCFLAGS \ 687c478bd9Sstevel@tonic-gate (PR_ISSYS|PR_VFORKP|PR_ORPHAN|PR_FORK|PR_RLC|PR_KLC|PR_ASYNC \ 697c478bd9Sstevel@tonic-gate |PR_BPTADJ|PR_MSACCT|PR_MSFORK|PR_PTRACE) 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate #define ALLFLAGS (LWPFLAGS|PROCFLAGS) 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate int 747c478bd9Sstevel@tonic-gate main(int argc, char **argv) 757c478bd9Sstevel@tonic-gate { 767c478bd9Sstevel@tonic-gate int rc = 0; 777c478bd9Sstevel@tonic-gate int errflg = 0; 787c478bd9Sstevel@tonic-gate int opt; 797c478bd9Sstevel@tonic-gate struct rlimit rlim; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate if ((command = strrchr(argv[0], '/')) != NULL) 827c478bd9Sstevel@tonic-gate command++; 837c478bd9Sstevel@tonic-gate else 847c478bd9Sstevel@tonic-gate command = argv[0]; 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* options */ 877c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "r")) != EOF) { 887c478bd9Sstevel@tonic-gate switch (opt) { 897c478bd9Sstevel@tonic-gate case 'r': /* show registers */ 907c478bd9Sstevel@tonic-gate rflag = 1; 917c478bd9Sstevel@tonic-gate break; 927c478bd9Sstevel@tonic-gate default: 937c478bd9Sstevel@tonic-gate errflg = 1; 947c478bd9Sstevel@tonic-gate break; 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate argc -= optind; 997c478bd9Sstevel@tonic-gate argv += optind; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate if (errflg || argc <= 0) { 1027c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1037c478bd9Sstevel@tonic-gate "usage:\t%s [-r] { pid | core }[/lwps] ...\n", command); 1047c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " (report process status flags)\n"); 1057c478bd9Sstevel@tonic-gate (void) fprintf(stderr, " -r : report registers\n"); 1067c478bd9Sstevel@tonic-gate return (2); 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* 1107c478bd9Sstevel@tonic-gate * Make sure we'll have enough file descriptors to handle a target 1117c478bd9Sstevel@tonic-gate * that has many many mappings. 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) { 1147c478bd9Sstevel@tonic-gate rlim.rlim_cur = rlim.rlim_max; 1157c478bd9Sstevel@tonic-gate (void) setrlimit(RLIMIT_NOFILE, &rlim); 116*004388ebScasper (void) enable_extended_FILE_stdio(-1, -1); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate while (argc-- > 0) 1207c478bd9Sstevel@tonic-gate rc += look(*argv++); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate return (rc); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate static int 1267c478bd9Sstevel@tonic-gate look(char *arg) 1277c478bd9Sstevel@tonic-gate { 1287c478bd9Sstevel@tonic-gate int gcode; 1297c478bd9Sstevel@tonic-gate int gcode2; 1307c478bd9Sstevel@tonic-gate pstatus_t pstatus; 1317c478bd9Sstevel@tonic-gate psinfo_t psinfo; 1327c478bd9Sstevel@tonic-gate int flags; 1337c478bd9Sstevel@tonic-gate sigset_t sigmask; 1347c478bd9Sstevel@tonic-gate fltset_t fltmask; 1357c478bd9Sstevel@tonic-gate sysset_t entryset; 1367c478bd9Sstevel@tonic-gate sysset_t exitset; 1377c478bd9Sstevel@tonic-gate uint32_t sigtrace, sigtrace2, fltbits; 1387c478bd9Sstevel@tonic-gate uint32_t sigpend, sigpend2; 1397c478bd9Sstevel@tonic-gate uint32_t *bits; 1407c478bd9Sstevel@tonic-gate char buf[PRSIGBUFSZ]; 1417c478bd9Sstevel@tonic-gate look_arg_t lookarg; 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate if ((Pr = proc_arg_xgrab(arg, NULL, PR_ARG_ANY, 1447c478bd9Sstevel@tonic-gate PGRAB_RETAIN | PGRAB_FORCE | PGRAB_RDONLY | PGRAB_NOSTOP, &gcode, 1457c478bd9Sstevel@tonic-gate &lookarg.lwps)) == NULL) { 1467c478bd9Sstevel@tonic-gate if (gcode == G_NOPROC && 1477c478bd9Sstevel@tonic-gate proc_arg_psinfo(arg, PR_ARG_PIDS, &psinfo, &gcode2) > 0 && 1487c478bd9Sstevel@tonic-gate psinfo.pr_nlwp == 0) { 1497c478bd9Sstevel@tonic-gate (void) printf("%d:\t<defunct>\n\n", (int)psinfo.pr_pid); 1507c478bd9Sstevel@tonic-gate return (0); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: cannot examine %s: %s\n", 1537c478bd9Sstevel@tonic-gate command, arg, Pgrab_error(gcode)); 1547c478bd9Sstevel@tonic-gate return (1); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate (void) memcpy(&pstatus, Pstatus(Pr), sizeof (pstatus_t)); 1587c478bd9Sstevel@tonic-gate (void) memcpy(&psinfo, Ppsinfo(Pr), sizeof (psinfo_t)); 1597c478bd9Sstevel@tonic-gate proc_unctrl_psinfo(&psinfo); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate if (psinfo.pr_nlwp == 0) { 1627c478bd9Sstevel@tonic-gate (void) printf("%d:\t<defunct>\n\n", (int)psinfo.pr_pid); 1637c478bd9Sstevel@tonic-gate Prelease(Pr, PRELEASE_RETAIN); 1647c478bd9Sstevel@tonic-gate return (0); 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate is64 = (pstatus.pr_dmodel == PR_MODEL_LP64); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate sigmask = pstatus.pr_sigtrace; 1707c478bd9Sstevel@tonic-gate fltmask = pstatus.pr_flttrace; 1717c478bd9Sstevel@tonic-gate entryset = pstatus.pr_sysentry; 1727c478bd9Sstevel@tonic-gate exitset = pstatus.pr_sysexit; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate if (Pstate(Pr) == PS_DEAD) { 1757c478bd9Sstevel@tonic-gate (void) printf("core '%s' of %d:\t%.70s\n", 1767c478bd9Sstevel@tonic-gate arg, (int)psinfo.pr_pid, psinfo.pr_psargs); 1777c478bd9Sstevel@tonic-gate } else { 1787c478bd9Sstevel@tonic-gate (void) printf("%d:\t%.70s\n", 1797c478bd9Sstevel@tonic-gate (int)psinfo.pr_pid, psinfo.pr_psargs); 1807c478bd9Sstevel@tonic-gate } 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate (void) printf("\tdata model = %s", is64? "_LP64" : "_ILP32"); 1837c478bd9Sstevel@tonic-gate if ((flags = (pstatus.pr_flags & PROCFLAGS)) != 0) 1847c478bd9Sstevel@tonic-gate (void) printf(" flags = %s", prflags(flags)); 1857c478bd9Sstevel@tonic-gate (void) printf("\n"); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate fltbits = *((uint32_t *)&fltmask); 1887c478bd9Sstevel@tonic-gate if (fltbits) 1897c478bd9Sstevel@tonic-gate (void) printf("\tflttrace = 0x%.8x\n", fltbits); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate sigtrace = *((uint32_t *)&sigmask); 1927c478bd9Sstevel@tonic-gate sigtrace2 = *((uint32_t *)&sigmask + 1); 1937c478bd9Sstevel@tonic-gate if (sigtrace | sigtrace2) { 1947c478bd9Sstevel@tonic-gate (void) printf("\tsigtrace = 0x%.8x 0x%.8x\n\t %s\n", 1957c478bd9Sstevel@tonic-gate sigtrace, sigtrace2, 1967c478bd9Sstevel@tonic-gate proc_sigset2str(&sigmask, "|", 1, buf, sizeof (buf))); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate bits = ((uint32_t *)&entryset); 2007c478bd9Sstevel@tonic-gate if (bits[0] | bits[1] | bits[2] | bits[3] | 2017c478bd9Sstevel@tonic-gate bits[4] | bits[5] | bits[6] | bits[7]) 2027c478bd9Sstevel@tonic-gate (void) printf( 2037c478bd9Sstevel@tonic-gate "\tentryset = " 2047c478bd9Sstevel@tonic-gate "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n" 2057c478bd9Sstevel@tonic-gate "\t " 2067c478bd9Sstevel@tonic-gate "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n", 2077c478bd9Sstevel@tonic-gate bits[0], bits[1], bits[2], bits[3], 2087c478bd9Sstevel@tonic-gate bits[4], bits[5], bits[6], bits[7]); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate bits = ((uint32_t *)&exitset); 2117c478bd9Sstevel@tonic-gate if (bits[0] | bits[1] | bits[2] | bits[3] | 2127c478bd9Sstevel@tonic-gate bits[4] | bits[5] | bits[6] | bits[7]) 2137c478bd9Sstevel@tonic-gate (void) printf( 2147c478bd9Sstevel@tonic-gate "\texitset = " 2157c478bd9Sstevel@tonic-gate "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n" 2167c478bd9Sstevel@tonic-gate "\t " 2177c478bd9Sstevel@tonic-gate "0x%.8x 0x%.8x 0x%.8x 0x%.8x\n", 2187c478bd9Sstevel@tonic-gate bits[0], bits[1], bits[2], bits[3], 2197c478bd9Sstevel@tonic-gate bits[4], bits[5], bits[6], bits[7]); 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate sigpend = *((uint32_t *)&pstatus.pr_sigpend); 2227c478bd9Sstevel@tonic-gate sigpend2 = *((uint32_t *)&pstatus.pr_sigpend + 1); 2237c478bd9Sstevel@tonic-gate if (sigpend | sigpend2) 2247c478bd9Sstevel@tonic-gate (void) printf("\tsigpend = 0x%.8x,0x%.8x\n", 2257c478bd9Sstevel@tonic-gate sigpend, sigpend2); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate lookarg.pflags = pstatus.pr_flags; 2287c478bd9Sstevel@tonic-gate lookarg.count = 0; 2297c478bd9Sstevel@tonic-gate (void) Plwp_iter_all(Pr, (proc_lwp_all_f *)lwplook, &lookarg); 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate if (lookarg.count == 0) 2327c478bd9Sstevel@tonic-gate (void) printf("No matching lwps found"); 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate (void) printf("\n"); 2357c478bd9Sstevel@tonic-gate Prelease(Pr, PRELEASE_RETAIN); 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate return (0); 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate static int 2417c478bd9Sstevel@tonic-gate lwplook_zombie(const lwpsinfo_t *pip) 2427c478bd9Sstevel@tonic-gate { 2437c478bd9Sstevel@tonic-gate (void) printf(" /%d:\t<defunct>\n", (int)pip->pr_lwpid); 2447c478bd9Sstevel@tonic-gate return (0); 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate static int 2487c478bd9Sstevel@tonic-gate lwplook(look_arg_t *arg, const lwpstatus_t *psp, const lwpsinfo_t *pip) 2497c478bd9Sstevel@tonic-gate { 2507c478bd9Sstevel@tonic-gate int flags; 2517c478bd9Sstevel@tonic-gate uint32_t sighold, sighold2; 2527c478bd9Sstevel@tonic-gate uint32_t sigpend, sigpend2; 2537c478bd9Sstevel@tonic-gate int cursig; 2547c478bd9Sstevel@tonic-gate char buf[32]; 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate if (!proc_lwp_in_set(arg->lwps, pip->pr_lwpid)) 2577c478bd9Sstevel@tonic-gate return (0); 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate arg->count++; 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate if (psp == NULL) 2627c478bd9Sstevel@tonic-gate return (lwplook_zombie(pip)); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * PR_PCINVAL is just noise if the lwp is not stopped. 2667c478bd9Sstevel@tonic-gate * Don't bother reporting it unless the lwp is stopped. 2677c478bd9Sstevel@tonic-gate */ 2687c478bd9Sstevel@tonic-gate flags = psp->pr_flags & LWPFLAGS; 2697c478bd9Sstevel@tonic-gate if (!(flags & PR_STOPPED)) 2707c478bd9Sstevel@tonic-gate flags &= ~PR_PCINVAL; 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate (void) printf(" /%d:\tflags = %s", (int)psp->pr_lwpid, prflags(flags)); 2737c478bd9Sstevel@tonic-gate if ((flags & PR_ASLEEP) || (psp->pr_syscall && 2747c478bd9Sstevel@tonic-gate !(arg->pflags & PR_ISSYS))) { 2757c478bd9Sstevel@tonic-gate if (flags & PR_ASLEEP) { 2767c478bd9Sstevel@tonic-gate if ((flags & ~PR_ASLEEP) != 0) 2777c478bd9Sstevel@tonic-gate (void) printf("|"); 2787c478bd9Sstevel@tonic-gate (void) printf("ASLEEP"); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate if (psp->pr_syscall && !(arg->pflags & PR_ISSYS)) { 2817c478bd9Sstevel@tonic-gate uint_t i; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate (void) printf(" %s(", 2847c478bd9Sstevel@tonic-gate proc_sysname(psp->pr_syscall, buf, sizeof (buf))); 2857c478bd9Sstevel@tonic-gate for (i = 0; i < psp->pr_nsysarg; i++) { 2867c478bd9Sstevel@tonic-gate if (i != 0) 2877c478bd9Sstevel@tonic-gate (void) printf(","); 2887c478bd9Sstevel@tonic-gate (void) printf("0x%lx", psp->pr_sysarg[i]); 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate (void) printf(")"); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate (void) printf("\n"); 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate if (flags & PR_STOPPED) { 2967c478bd9Sstevel@tonic-gate (void) printf("\twhy = %s", prwhy(psp->pr_why)); 2977c478bd9Sstevel@tonic-gate if (psp->pr_why != PR_REQUESTED && 2987c478bd9Sstevel@tonic-gate psp->pr_why != PR_SUSPENDED) 2997c478bd9Sstevel@tonic-gate (void) printf(" what = %s", 3007c478bd9Sstevel@tonic-gate prwhat(psp->pr_why, psp->pr_what)); 3017c478bd9Sstevel@tonic-gate (void) printf("\n"); 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate sighold = *((uint32_t *)&psp->pr_lwphold); 3057c478bd9Sstevel@tonic-gate sighold2 = *((uint32_t *)&psp->pr_lwphold + 1); 3067c478bd9Sstevel@tonic-gate sigpend = *((uint32_t *)&psp->pr_lwppend); 3077c478bd9Sstevel@tonic-gate sigpend2 = *((uint32_t *)&psp->pr_lwppend + 1); 3087c478bd9Sstevel@tonic-gate cursig = psp->pr_cursig; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate if (sighold | sighold2 | sigpend | sigpend2 | cursig) { 3117c478bd9Sstevel@tonic-gate (void) printf("\t"); 3127c478bd9Sstevel@tonic-gate if (sighold | sighold2) { 3137c478bd9Sstevel@tonic-gate (void) printf("sigmask = 0x%.8x,0x%.8x", 3147c478bd9Sstevel@tonic-gate sighold, sighold2); 3157c478bd9Sstevel@tonic-gate if (sigpend | sigpend2 | cursig) 3167c478bd9Sstevel@tonic-gate (void) printf(" "); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate if (sigpend | sigpend2) { 3197c478bd9Sstevel@tonic-gate (void) printf("lwppend = 0x%.8x,0x%.8x", 3207c478bd9Sstevel@tonic-gate sigpend, sigpend2); 3217c478bd9Sstevel@tonic-gate if (cursig) 3227c478bd9Sstevel@tonic-gate (void) printf(" "); 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate if (cursig) 3257c478bd9Sstevel@tonic-gate (void) printf("cursig = %s", 3267c478bd9Sstevel@tonic-gate proc_signame(cursig, buf, sizeof (buf))); 3277c478bd9Sstevel@tonic-gate (void) printf("\n"); 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate if (rflag) { 3317c478bd9Sstevel@tonic-gate if (Pstate(Pr) == PS_DEAD || (arg->pflags & PR_STOPPED)) { 3327c478bd9Sstevel@tonic-gate #if defined(__sparc) && defined(_ILP32) 3337c478bd9Sstevel@tonic-gate /* 3347c478bd9Sstevel@tonic-gate * If we're SPARC/32-bit, see if we can get extra 3357c478bd9Sstevel@tonic-gate * register state for this lwp. If it's a v8plus 3367c478bd9Sstevel@tonic-gate * program, print the 64-bit register values. 3377c478bd9Sstevel@tonic-gate */ 3387c478bd9Sstevel@tonic-gate prxregset_t prx; 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate if (Plwp_getxregs(Pr, psp->pr_lwpid, &prx) == 0 && 3417c478bd9Sstevel@tonic-gate prx.pr_type == XR_TYPE_V8P) 3427c478bd9Sstevel@tonic-gate dumpregs_v8p(psp->pr_reg, &prx, is64); 3437c478bd9Sstevel@tonic-gate else 3447c478bd9Sstevel@tonic-gate #endif /* __sparc && _ILP32 */ 3457c478bd9Sstevel@tonic-gate dumpregs(psp->pr_reg, is64); 3467c478bd9Sstevel@tonic-gate } else 3477c478bd9Sstevel@tonic-gate (void) printf("\tNot stopped, can't show registers\n"); 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate return (0); 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate static char * 3547c478bd9Sstevel@tonic-gate prflags(int arg) 3557c478bd9Sstevel@tonic-gate { 3567c478bd9Sstevel@tonic-gate static char code_buf[200]; 3577c478bd9Sstevel@tonic-gate char *str = code_buf; 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate if (arg == 0) 3607c478bd9Sstevel@tonic-gate return ("0"); 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate if (arg & ~ALLFLAGS) 3637c478bd9Sstevel@tonic-gate (void) sprintf(str, "0x%x", arg & ~ALLFLAGS); 3647c478bd9Sstevel@tonic-gate else 3657c478bd9Sstevel@tonic-gate *str = '\0'; 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate /* 3687c478bd9Sstevel@tonic-gate * Display the semi-permanent lwp flags first. 3697c478bd9Sstevel@tonic-gate */ 3707c478bd9Sstevel@tonic-gate if (arg & PR_DAEMON) /* daemons are always detached so */ 3717c478bd9Sstevel@tonic-gate (void) strcat(str, "|DAEMON"); 3727c478bd9Sstevel@tonic-gate else if (arg & PR_DETACH) /* report detach only if non-daemon */ 3737c478bd9Sstevel@tonic-gate (void) strcat(str, "|DETACH"); 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate if (arg & PR_STOPPED) 3767c478bd9Sstevel@tonic-gate (void) strcat(str, "|STOPPED"); 3777c478bd9Sstevel@tonic-gate if (arg & PR_ISTOP) 3787c478bd9Sstevel@tonic-gate (void) strcat(str, "|ISTOP"); 3797c478bd9Sstevel@tonic-gate if (arg & PR_DSTOP) 3807c478bd9Sstevel@tonic-gate (void) strcat(str, "|DSTOP"); 3817c478bd9Sstevel@tonic-gate #if 0 /* displayed elsewhere */ 3827c478bd9Sstevel@tonic-gate if (arg & PR_ASLEEP) 3837c478bd9Sstevel@tonic-gate (void) strcat(str, "|ASLEEP"); 3847c478bd9Sstevel@tonic-gate #endif 3857c478bd9Sstevel@tonic-gate if (arg & PR_PCINVAL) 3867c478bd9Sstevel@tonic-gate (void) strcat(str, "|PCINVAL"); 3877c478bd9Sstevel@tonic-gate if (arg & PR_STEP) 3887c478bd9Sstevel@tonic-gate (void) strcat(str, "|STEP"); 3897c478bd9Sstevel@tonic-gate if (arg & PR_AGENT) 3907c478bd9Sstevel@tonic-gate (void) strcat(str, "|AGENT"); 3917c478bd9Sstevel@tonic-gate if (arg & PR_ISSYS) 3927c478bd9Sstevel@tonic-gate (void) strcat(str, "|ISSYS"); 3937c478bd9Sstevel@tonic-gate if (arg & PR_VFORKP) 3947c478bd9Sstevel@tonic-gate (void) strcat(str, "|VFORKP"); 3957c478bd9Sstevel@tonic-gate if (arg & PR_ORPHAN) 3967c478bd9Sstevel@tonic-gate (void) strcat(str, "|ORPHAN"); 3977c478bd9Sstevel@tonic-gate if (arg & PR_FORK) 3987c478bd9Sstevel@tonic-gate (void) strcat(str, "|FORK"); 3997c478bd9Sstevel@tonic-gate if (arg & PR_RLC) 4007c478bd9Sstevel@tonic-gate (void) strcat(str, "|RLC"); 4017c478bd9Sstevel@tonic-gate if (arg & PR_KLC) 4027c478bd9Sstevel@tonic-gate (void) strcat(str, "|KLC"); 4037c478bd9Sstevel@tonic-gate if (arg & PR_ASYNC) 4047c478bd9Sstevel@tonic-gate (void) strcat(str, "|ASYNC"); 4057c478bd9Sstevel@tonic-gate if (arg & PR_BPTADJ) 4067c478bd9Sstevel@tonic-gate (void) strcat(str, "|BPTADJ"); 4077c478bd9Sstevel@tonic-gate if (arg & PR_MSACCT) 4087c478bd9Sstevel@tonic-gate (void) strcat(str, "|MSACCT"); 4097c478bd9Sstevel@tonic-gate if (arg & PR_MSFORK) 4107c478bd9Sstevel@tonic-gate (void) strcat(str, "|MSFORK"); 4117c478bd9Sstevel@tonic-gate if (arg & PR_PTRACE) 4127c478bd9Sstevel@tonic-gate (void) strcat(str, "|PTRACE"); 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate if (*str == '|') 4157c478bd9Sstevel@tonic-gate str++; 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate return (str); 4187c478bd9Sstevel@tonic-gate } 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate static char * 4217c478bd9Sstevel@tonic-gate prwhy(int why) 4227c478bd9Sstevel@tonic-gate { 4237c478bd9Sstevel@tonic-gate static char buf[20]; 4247c478bd9Sstevel@tonic-gate char *str; 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate switch (why) { 4277c478bd9Sstevel@tonic-gate case PR_REQUESTED: 4287c478bd9Sstevel@tonic-gate str = "PR_REQUESTED"; 4297c478bd9Sstevel@tonic-gate break; 4307c478bd9Sstevel@tonic-gate case PR_SIGNALLED: 4317c478bd9Sstevel@tonic-gate str = "PR_SIGNALLED"; 4327c478bd9Sstevel@tonic-gate break; 4337c478bd9Sstevel@tonic-gate case PR_SYSENTRY: 4347c478bd9Sstevel@tonic-gate str = "PR_SYSENTRY"; 4357c478bd9Sstevel@tonic-gate break; 4367c478bd9Sstevel@tonic-gate case PR_SYSEXIT: 4377c478bd9Sstevel@tonic-gate str = "PR_SYSEXIT"; 4387c478bd9Sstevel@tonic-gate break; 4397c478bd9Sstevel@tonic-gate case PR_JOBCONTROL: 4407c478bd9Sstevel@tonic-gate str = "PR_JOBCONTROL"; 4417c478bd9Sstevel@tonic-gate break; 4427c478bd9Sstevel@tonic-gate case PR_FAULTED: 4437c478bd9Sstevel@tonic-gate str = "PR_FAULTED"; 4447c478bd9Sstevel@tonic-gate break; 4457c478bd9Sstevel@tonic-gate case PR_SUSPENDED: 4467c478bd9Sstevel@tonic-gate str = "PR_SUSPENDED"; 4477c478bd9Sstevel@tonic-gate break; 4487c478bd9Sstevel@tonic-gate default: 4497c478bd9Sstevel@tonic-gate str = buf; 4507c478bd9Sstevel@tonic-gate (void) sprintf(str, "%d", why); 4517c478bd9Sstevel@tonic-gate break; 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate return (str); 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate static char * 4587c478bd9Sstevel@tonic-gate prwhat(int why, int what) 4597c478bd9Sstevel@tonic-gate { 4607c478bd9Sstevel@tonic-gate static char buf[32]; 4617c478bd9Sstevel@tonic-gate char *str; 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate switch (why) { 4647c478bd9Sstevel@tonic-gate case PR_SIGNALLED: 4657c478bd9Sstevel@tonic-gate case PR_JOBCONTROL: 4667c478bd9Sstevel@tonic-gate str = proc_signame(what, buf, sizeof (buf)); 4677c478bd9Sstevel@tonic-gate break; 4687c478bd9Sstevel@tonic-gate case PR_SYSENTRY: 4697c478bd9Sstevel@tonic-gate case PR_SYSEXIT: 4707c478bd9Sstevel@tonic-gate str = proc_sysname(what, buf, sizeof (buf)); 4717c478bd9Sstevel@tonic-gate break; 4727c478bd9Sstevel@tonic-gate case PR_FAULTED: 4737c478bd9Sstevel@tonic-gate str = proc_fltname(what, buf, sizeof (buf)); 4747c478bd9Sstevel@tonic-gate break; 4757c478bd9Sstevel@tonic-gate default: 4767c478bd9Sstevel@tonic-gate (void) sprintf(str = buf, "%d", what); 4777c478bd9Sstevel@tonic-gate break; 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate return (str); 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate #if defined(__sparc) 4847c478bd9Sstevel@tonic-gate static const char * const regname[NPRGREG] = { 4857c478bd9Sstevel@tonic-gate " %g0", " %g1", " %g2", " %g3", " %g4", " %g5", " %g6", " %g7", 4867c478bd9Sstevel@tonic-gate " %o0", " %o1", " %o2", " %o3", " %o4", " %o5", " %sp", " %o7", 4877c478bd9Sstevel@tonic-gate " %l0", " %l1", " %l2", " %l3", " %l4", " %l5", " %l6", " %l7", 4887c478bd9Sstevel@tonic-gate " %i0", " %i1", " %i2", " %i3", " %i4", " %i5", " %fp", " %i7", 4897c478bd9Sstevel@tonic-gate #ifdef __sparcv9 4907c478bd9Sstevel@tonic-gate "%ccr", " %pc", "%npc", " %y", "%asi", "%fprs" 4917c478bd9Sstevel@tonic-gate #else 4927c478bd9Sstevel@tonic-gate "%psr", " %pc", "%npc", " %y", "%wim", "%tbr" 4937c478bd9Sstevel@tonic-gate #endif 4947c478bd9Sstevel@tonic-gate }; 4957c478bd9Sstevel@tonic-gate #endif /* __sparc */ 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate #if defined(__amd64) 4987c478bd9Sstevel@tonic-gate static const char * const regname[NPRGREG] = { 4997c478bd9Sstevel@tonic-gate "%r15", "%r14", "%r13", "%r12", "%r11", "%r10", " %r9", " %r8", 5007c478bd9Sstevel@tonic-gate "%rdi", "%rsi", "%rbp", "%rbx", "%rdx", "%rcx", "%rax", "%trapno", 5017c478bd9Sstevel@tonic-gate "%err", "%rip", " %cs", "%rfl", "%rsp", " %ss", " %fs", " %gs", 5027c478bd9Sstevel@tonic-gate " %es", " %ds", "%fsbase", "%gsbase" 5037c478bd9Sstevel@tonic-gate }; 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate static const char * const regname32[NPRGREG32] = { 5067c478bd9Sstevel@tonic-gate " %gs", " %fs", " %es", " %ds", "%edi", "%esi", "%ebp", "%esp", 5077c478bd9Sstevel@tonic-gate "%ebx", "%edx", "%ecx", "%eax", "%trapno", "%err", "%eip", " %cs", 5087c478bd9Sstevel@tonic-gate "%efl", "%uesp", " %ss" 5097c478bd9Sstevel@tonic-gate }; 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate /* XX64 Do we want to expose this through libproc */ 5127c478bd9Sstevel@tonic-gate void 5137c478bd9Sstevel@tonic-gate prgregset_n_to_32(const prgreg_t *src, prgreg32_t *dst) 5147c478bd9Sstevel@tonic-gate { 5157c478bd9Sstevel@tonic-gate bzero(dst, NPRGREG32 * sizeof (prgreg32_t)); 5167c478bd9Sstevel@tonic-gate dst[GS] = src[REG_GS]; 5177c478bd9Sstevel@tonic-gate dst[FS] = src[REG_FS]; 5187c478bd9Sstevel@tonic-gate dst[DS] = src[REG_DS]; 5197c478bd9Sstevel@tonic-gate dst[ES] = src[REG_ES]; 5207c478bd9Sstevel@tonic-gate dst[EDI] = src[REG_RDI]; 5217c478bd9Sstevel@tonic-gate dst[ESI] = src[REG_RSI]; 5227c478bd9Sstevel@tonic-gate dst[EBP] = src[REG_RBP]; 5237c478bd9Sstevel@tonic-gate dst[EBX] = src[REG_RBX]; 5247c478bd9Sstevel@tonic-gate dst[EDX] = src[REG_RDX]; 5257c478bd9Sstevel@tonic-gate dst[ECX] = src[REG_RCX]; 5267c478bd9Sstevel@tonic-gate dst[EAX] = src[REG_RAX]; 5277c478bd9Sstevel@tonic-gate dst[TRAPNO] = src[REG_TRAPNO]; 5287c478bd9Sstevel@tonic-gate dst[ERR] = src[REG_ERR]; 5297c478bd9Sstevel@tonic-gate dst[EIP] = src[REG_RIP]; 5307c478bd9Sstevel@tonic-gate dst[CS] = src[REG_CS]; 5317c478bd9Sstevel@tonic-gate dst[EFL] = src[REG_RFL]; 5327c478bd9Sstevel@tonic-gate dst[UESP] = src[REG_RSP]; 5337c478bd9Sstevel@tonic-gate dst[SS] = src[REG_SS]; 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate #elif defined(__i386) 5377c478bd9Sstevel@tonic-gate static const char * const regname[NPRGREG] = { 5387c478bd9Sstevel@tonic-gate " %gs", " %fs", " %es", " %ds", "%edi", "%esi", "%ebp", "%esp", 5397c478bd9Sstevel@tonic-gate "%ebx", "%edx", "%ecx", "%eax", "%trapno", "%err", "%eip", " %cs", 5407c478bd9Sstevel@tonic-gate "%efl", "%uesp", " %ss" 5417c478bd9Sstevel@tonic-gate }; 5427c478bd9Sstevel@tonic-gate #endif /* __i386 */ 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64) 5457c478bd9Sstevel@tonic-gate static void 5467c478bd9Sstevel@tonic-gate dumpregs32(const prgregset_t reg) 5477c478bd9Sstevel@tonic-gate { 5487c478bd9Sstevel@tonic-gate prgregset32_t reg32; 5497c478bd9Sstevel@tonic-gate int i; 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate prgregset_n_to_32(reg, reg32); 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate for (i = 0; i < NPRGREG32; i++) { 5547c478bd9Sstevel@tonic-gate (void) printf(" %s = 0x%.8X", 5557c478bd9Sstevel@tonic-gate regname32[i], reg32[i]); 5567c478bd9Sstevel@tonic-gate if ((i+1) % 4 == 0) 5577c478bd9Sstevel@tonic-gate (void) putchar('\n'); 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate if (i % 4 != 0) 5607c478bd9Sstevel@tonic-gate (void) putchar('\n'); 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate #endif 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate static void 5657c478bd9Sstevel@tonic-gate dumpregs(const prgregset_t reg, int is64) 5667c478bd9Sstevel@tonic-gate { 5677c478bd9Sstevel@tonic-gate int width = is64? 16 : 8; 5687c478bd9Sstevel@tonic-gate int cols = is64? 2 : 4; 5697c478bd9Sstevel@tonic-gate int i; 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate #if defined(__amd64) && defined(_LP64) 5727c478bd9Sstevel@tonic-gate if (!is64) { 5737c478bd9Sstevel@tonic-gate dumpregs32(reg); 5747c478bd9Sstevel@tonic-gate return; 5757c478bd9Sstevel@tonic-gate } 5767c478bd9Sstevel@tonic-gate #endif 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate for (i = 0; i < NPRGREG; i++) { 5797c478bd9Sstevel@tonic-gate (void) printf(" %s = 0x%.*lX", 5807c478bd9Sstevel@tonic-gate regname[i], width, (long)reg[i]); 5817c478bd9Sstevel@tonic-gate if ((i+1) % cols == 0) 5827c478bd9Sstevel@tonic-gate (void) putchar('\n'); 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate if (i % cols != 0) 5857c478bd9Sstevel@tonic-gate (void) putchar('\n'); 5867c478bd9Sstevel@tonic-gate } 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate #if defined(__sparc) && defined(_ILP32) 5897c478bd9Sstevel@tonic-gate static void 5907c478bd9Sstevel@tonic-gate dumpregs_v8p(const prgregset_t reg, const prxregset_t *xreg, int is64) 5917c478bd9Sstevel@tonic-gate { 5927c478bd9Sstevel@tonic-gate static const uint32_t zero[8] = { 0 }; 5937c478bd9Sstevel@tonic-gate int gr, xr, cols = 2; 5947c478bd9Sstevel@tonic-gate uint64_t xval; 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate if (memcmp(xreg->pr_un.pr_v8p.pr_xg, zero, sizeof (zero)) == 0 && 5977c478bd9Sstevel@tonic-gate memcmp(xreg->pr_un.pr_v8p.pr_xo, zero, sizeof (zero)) == 0) { 5987c478bd9Sstevel@tonic-gate dumpregs(reg, is64); 5997c478bd9Sstevel@tonic-gate return; 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate for (gr = R_G0, xr = XR_G0; gr <= R_G7; gr++, xr++) { 6037c478bd9Sstevel@tonic-gate xval = (uint64_t)xreg->pr_un.pr_v8p.pr_xg[xr] << 32 | 6047c478bd9Sstevel@tonic-gate (uint64_t)(uint32_t)reg[gr]; 6057c478bd9Sstevel@tonic-gate (void) printf(" %s = 0x%.16" PRIX64, regname[gr], xval); 6067c478bd9Sstevel@tonic-gate if ((gr + 1) % cols == 0) 6077c478bd9Sstevel@tonic-gate (void) putchar('\n'); 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate for (gr = R_O0, xr = XR_O0; gr <= R_O7; gr++, xr++) { 6117c478bd9Sstevel@tonic-gate xval = (uint64_t)xreg->pr_un.pr_v8p.pr_xo[xr] << 32 | 6127c478bd9Sstevel@tonic-gate (uint64_t)(uint32_t)reg[gr]; 6137c478bd9Sstevel@tonic-gate (void) printf(" %s = 0x%.16" PRIX64, regname[gr], xval); 6147c478bd9Sstevel@tonic-gate if ((gr + 1) % cols == 0) 6157c478bd9Sstevel@tonic-gate (void) putchar('\n'); 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate for (gr = R_L0; gr < NPRGREG; gr++) { 6197c478bd9Sstevel@tonic-gate (void) printf(" %s = 0x%.8lX", 6207c478bd9Sstevel@tonic-gate regname[gr], (long)reg[gr]); 6217c478bd9Sstevel@tonic-gate if ((gr + 1) % cols == 0) 6227c478bd9Sstevel@tonic-gate (void) putchar('\n'); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate if (gr % cols != 0) 6267c478bd9Sstevel@tonic-gate (void) putchar('\n'); 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate #endif /* __sparc && _ILP32 */ 629