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 51885Sraf * Common Development and Distribution License (the "License"). 61885Sraf * 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 */ 211885Sraf 220Sstevel@tonic-gate /* 233446Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/mdb_modapi.h> 300Sstevel@tonic-gate #include <procfs.h> 310Sstevel@tonic-gate #include <ucontext.h> 320Sstevel@tonic-gate #include <siginfo.h> 330Sstevel@tonic-gate #include <signal.h> 340Sstevel@tonic-gate #include <setjmp.h> 350Sstevel@tonic-gate #include <string.h> 360Sstevel@tonic-gate #include <thr_uberdata.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate static const char * 390Sstevel@tonic-gate stack_flags(const stack_t *sp) 400Sstevel@tonic-gate { 410Sstevel@tonic-gate static char buf[32]; 420Sstevel@tonic-gate 430Sstevel@tonic-gate if (sp->ss_flags == 0) 440Sstevel@tonic-gate (void) strcpy(buf, " 0"); 450Sstevel@tonic-gate else if (sp->ss_flags & ~(SS_ONSTACK | SS_DISABLE)) 460Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buf), " 0x%x", sp->ss_flags); 470Sstevel@tonic-gate else { 480Sstevel@tonic-gate buf[0] = '\0'; 490Sstevel@tonic-gate if (sp->ss_flags & SS_ONSTACK) 500Sstevel@tonic-gate (void) strcat(buf, "|ONSTACK"); 510Sstevel@tonic-gate if (sp->ss_flags & SS_DISABLE) 520Sstevel@tonic-gate (void) strcat(buf, "|DISABLE"); 530Sstevel@tonic-gate } 540Sstevel@tonic-gate 550Sstevel@tonic-gate return (buf + 1); 560Sstevel@tonic-gate } 570Sstevel@tonic-gate 580Sstevel@tonic-gate /*ARGSUSED*/ 590Sstevel@tonic-gate static int 600Sstevel@tonic-gate d_jmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 610Sstevel@tonic-gate { 620Sstevel@tonic-gate jmp_buf jb; 630Sstevel@tonic-gate const ulong_t *b = (const ulong_t *)jb; 640Sstevel@tonic-gate 650Sstevel@tonic-gate if (argc != 0) 660Sstevel@tonic-gate return (DCMD_USAGE); 670Sstevel@tonic-gate 680Sstevel@tonic-gate if (mdb_vread(&jb, sizeof (jb), addr) != sizeof (jb)) { 690Sstevel@tonic-gate mdb_warn("failed to read jmp_buf at %p", addr); 700Sstevel@tonic-gate return (DCMD_ERR); 710Sstevel@tonic-gate } 720Sstevel@tonic-gate 730Sstevel@tonic-gate #if defined(__sparc) 740Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx\n", b[1]); 750Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", b[2], b[2]); 760Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx\n", b[3]); 770Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", b[4], b[4]); 780Sstevel@tonic-gate #elif defined(__amd64) 790Sstevel@tonic-gate mdb_printf(" %%rbx = 0x%lx\n", b[0]); 800Sstevel@tonic-gate mdb_printf(" %%r12 = 0x%lx\n", b[1]); 810Sstevel@tonic-gate mdb_printf(" %%r13 = 0x%lx\n", b[2]); 820Sstevel@tonic-gate mdb_printf(" %%r14 = 0x%lx\n", b[3]); 830Sstevel@tonic-gate mdb_printf(" %%r15 = 0x%lx\n", b[4]); 840Sstevel@tonic-gate mdb_printf(" %%rbp = 0x%lx\n", b[5]); 850Sstevel@tonic-gate mdb_printf(" %%rsp = 0x%lx\n", b[6]); 860Sstevel@tonic-gate mdb_printf(" %%rip = 0x%lx %lA\n", b[7], b[7]); 870Sstevel@tonic-gate #elif defined(__i386) 880Sstevel@tonic-gate mdb_printf(" %%ebx = 0x%lx\n", b[0]); 890Sstevel@tonic-gate mdb_printf(" %%esi = 0x%lx\n", b[1]); 900Sstevel@tonic-gate mdb_printf(" %%edi = 0x%lx\n", b[2]); 910Sstevel@tonic-gate mdb_printf(" %%ebp = 0x%lx\n", b[3]); 920Sstevel@tonic-gate mdb_printf(" %%esp = 0x%lx\n", b[4]); 930Sstevel@tonic-gate mdb_printf(" %%eip = 0x%lx %lA\n", b[5], b[5]); 940Sstevel@tonic-gate #endif 950Sstevel@tonic-gate return (DCMD_OK); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate 980Sstevel@tonic-gate /*ARGSUSED*/ 990Sstevel@tonic-gate static int 1000Sstevel@tonic-gate d_ucontext(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1010Sstevel@tonic-gate { 1020Sstevel@tonic-gate ucontext_t uc; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate if (argc != 0) 1050Sstevel@tonic-gate return (DCMD_USAGE); 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 1080Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 1090Sstevel@tonic-gate return (DCMD_ERR); 1100Sstevel@tonic-gate } 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate mdb_printf(" flags = 0x%lx\n", uc.uc_flags); 1130Sstevel@tonic-gate mdb_printf(" link = 0x%p\n", uc.uc_link); 1140Sstevel@tonic-gate mdb_printf(" sigmask = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1150Sstevel@tonic-gate uc.uc_sigmask.__sigbits[0], uc.uc_sigmask.__sigbits[1], 1160Sstevel@tonic-gate uc.uc_sigmask.__sigbits[2], uc.uc_sigmask.__sigbits[3]); 1170Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n", 1180Sstevel@tonic-gate uc.uc_stack.ss_sp, uc.uc_stack.ss_size, stack_flags(&uc.uc_stack)); 1190Sstevel@tonic-gate mdb_printf(" mcontext = 0x%p\n", 1200Sstevel@tonic-gate addr + OFFSETOF(ucontext_t, uc_mcontext)); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate return (DCMD_OK); 1230Sstevel@tonic-gate } 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /*ARGSUSED*/ 1260Sstevel@tonic-gate static int 1270Sstevel@tonic-gate d_sigjmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1280Sstevel@tonic-gate { 1290Sstevel@tonic-gate #if defined(__sparc) 1300Sstevel@tonic-gate struct { 1310Sstevel@tonic-gate int sjs_flags; 1320Sstevel@tonic-gate greg_t sjs_sp; 1330Sstevel@tonic-gate greg_t sjs_pc; 1340Sstevel@tonic-gate greg_t sjs_fp; 1350Sstevel@tonic-gate greg_t sjs_i7; 1360Sstevel@tonic-gate ucontext_t *sjs_uclink; 1370Sstevel@tonic-gate ulong_t sjs_pad[_JBLEN - 6]; 1380Sstevel@tonic-gate sigset_t sjs_sigmask; 1390Sstevel@tonic-gate #if defined(_LP64) 1400Sstevel@tonic-gate ulong_t sjs_pad1[2]; 1410Sstevel@tonic-gate #endif 1420Sstevel@tonic-gate stack_t sjs_stack; 1430Sstevel@tonic-gate } s; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate if (argc != 0) 1460Sstevel@tonic-gate return (DCMD_USAGE); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate if (mdb_vread(&s, sizeof (s), addr) != sizeof (s)) { 1490Sstevel@tonic-gate mdb_warn("failed to read sigjmp_buf at %p", addr); 1500Sstevel@tonic-gate return (DCMD_ERR); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate mdb_printf(" flags = 0x%x\n", s.sjs_flags); 1540Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx %lA\n", s.sjs_sp, s.sjs_sp); 1550Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", s.sjs_pc, s.sjs_pc); 1560Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx %lA\n", s.sjs_fp, s.sjs_fp); 1570Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", s.sjs_i7, s.sjs_i7); 1580Sstevel@tonic-gate mdb_printf(" uclink = %p\n", s.sjs_uclink); 1590Sstevel@tonic-gate mdb_printf(" sigset = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1600Sstevel@tonic-gate s.sjs_sigmask.__sigbits[0], s.sjs_sigmask.__sigbits[1], 1610Sstevel@tonic-gate s.sjs_sigmask.__sigbits[2], s.sjs_sigmask.__sigbits[3]); 1620Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n", 1630Sstevel@tonic-gate s.sjs_stack.ss_sp, s.sjs_stack.ss_size, stack_flags(&s.sjs_stack)); 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate return (DCMD_OK); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64) 1680Sstevel@tonic-gate return (d_ucontext(addr, flags, argc, argv)); 1690Sstevel@tonic-gate #endif 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate /*ARGSUSED*/ 1730Sstevel@tonic-gate static int 1740Sstevel@tonic-gate d_siginfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1750Sstevel@tonic-gate { 1760Sstevel@tonic-gate static const char *const msname[] = { 1770Sstevel@tonic-gate "USER", "SYSTEM", "TRAP", "TFAULT", "DFAULT", "KFAULT", 1780Sstevel@tonic-gate "USER_LOCK", "SLEEP", "WAIT_CPU", "STOPPED" 1790Sstevel@tonic-gate }; 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate char signame[SIG2STR_MAX]; 1820Sstevel@tonic-gate siginfo_t si; 1830Sstevel@tonic-gate int i; 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate if (argc != 0) 1860Sstevel@tonic-gate return (DCMD_USAGE); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate if (mdb_vread(&si, sizeof (si), addr) != sizeof (si)) { 1890Sstevel@tonic-gate mdb_warn("failed to read siginfo at %p", addr); 1900Sstevel@tonic-gate return (DCMD_ERR); 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate if (sig2str(si.si_signo, signame) == -1) 1940Sstevel@tonic-gate (void) strcpy(signame, "unknown"); 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate mdb_printf(" signal %5d (%s)\n", si.si_signo, signame); 1970Sstevel@tonic-gate mdb_printf(" code %5d (", si.si_code); 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate switch (si.si_code) { 2000Sstevel@tonic-gate case SI_NOINFO: 2010Sstevel@tonic-gate mdb_printf("no info"); 2020Sstevel@tonic-gate break; 2030Sstevel@tonic-gate case SI_DTRACE: 2040Sstevel@tonic-gate mdb_printf("from DTrace raise() action"); 2050Sstevel@tonic-gate break; 2060Sstevel@tonic-gate case SI_RCTL: 2070Sstevel@tonic-gate mdb_printf("from rctl action"); 2080Sstevel@tonic-gate break; 2090Sstevel@tonic-gate case SI_USER: 2100Sstevel@tonic-gate mdb_printf("user generated via kill"); 2110Sstevel@tonic-gate break; 2120Sstevel@tonic-gate case SI_LWP: 2130Sstevel@tonic-gate mdb_printf("user generated via lwp_kill"); 2140Sstevel@tonic-gate break; 2150Sstevel@tonic-gate case SI_QUEUE: 2160Sstevel@tonic-gate mdb_printf("user generated via sigqueue"); 2170Sstevel@tonic-gate break; 2180Sstevel@tonic-gate case SI_TIMER: 2190Sstevel@tonic-gate mdb_printf("from timer expiration"); 2200Sstevel@tonic-gate break; 2210Sstevel@tonic-gate case SI_ASYNCIO: 2220Sstevel@tonic-gate mdb_printf("from async i/o completion"); 2230Sstevel@tonic-gate break; 2240Sstevel@tonic-gate case SI_MESGQ: 2250Sstevel@tonic-gate mdb_printf("from message arrival"); 2260Sstevel@tonic-gate break; 2270Sstevel@tonic-gate default: 2280Sstevel@tonic-gate if (SI_FROMUSER(&si)) 2290Sstevel@tonic-gate mdb_printf("from user process"); 2300Sstevel@tonic-gate else 2310Sstevel@tonic-gate mdb_printf("from kernel"); 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate mdb_printf(")\n errno %5d (%s)\n", 2350Sstevel@tonic-gate si.si_errno, strerror(si.si_errno)); 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate if (si.si_code == SI_USER || si.si_code == SI_QUEUE) { 2380Sstevel@tonic-gate mdb_printf(" signal sent from PID %d (uid %d)\n", 2390Sstevel@tonic-gate si.si_pid, si.si_uid); 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate if (si.si_code == SI_QUEUE) { 2430Sstevel@tonic-gate mdb_printf(" signal value = 0t%d / %p\n", 2440Sstevel@tonic-gate si.si_value.sival_int, si.si_value.sival_ptr); 2450Sstevel@tonic-gate } 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate switch (si.si_signo) { 2480Sstevel@tonic-gate case SIGCLD: 2490Sstevel@tonic-gate mdb_printf(" signal sent from child PID %d (uid %d)\n", 2500Sstevel@tonic-gate si.si_pid, si.si_uid); 2510Sstevel@tonic-gate mdb_printf(" usr time = 0t%ld ticks, sys time = 0t%ld ticks\n", 2520Sstevel@tonic-gate si.si_utime, si.si_stime); 2530Sstevel@tonic-gate mdb_printf(" wait status = 0x%x\n", si.si_status); 2540Sstevel@tonic-gate break; 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate case SIGSEGV: 2570Sstevel@tonic-gate case SIGBUS: 2580Sstevel@tonic-gate case SIGILL: 2590Sstevel@tonic-gate case SIGTRAP: 2600Sstevel@tonic-gate case SIGFPE: 2610Sstevel@tonic-gate mdb_printf(" fault address = 0x%p\n trapno = %d\n", 2620Sstevel@tonic-gate si.si_addr, si.si_trapno); 2630Sstevel@tonic-gate mdb_printf(" instruction address = 0x%p %lA\n", 2640Sstevel@tonic-gate si.si_pc, si.si_pc); 2650Sstevel@tonic-gate break; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate case SIGPOLL: 2680Sstevel@tonic-gate case SIGXFSZ: 2690Sstevel@tonic-gate mdb_printf(" fd = %d band = 0x%lx\n", 2700Sstevel@tonic-gate si.si_fd, si.si_band); 2710Sstevel@tonic-gate break; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate case SIGPROF: 2740Sstevel@tonic-gate mdb_printf(" last fault address = 0x%p fault type = %d\n", 2750Sstevel@tonic-gate si.si_faddr, si.si_fault); 2760Sstevel@tonic-gate mdb_printf(" timestamp = 0t%ld sec 0t%ld nsec\n", 2770Sstevel@tonic-gate si.si_tstamp.tv_sec, si.si_tstamp.tv_nsec); 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate if (si.__data.__prof.__syscall != 0) { 2800Sstevel@tonic-gate mdb_printf(" system call %d (", si.si_syscall); 2810Sstevel@tonic-gate if (si.si_nsysarg > 0) { 2820Sstevel@tonic-gate mdb_printf("%lx", si.si_sysarg[0]); 2830Sstevel@tonic-gate for (i = 1; i < si.si_nsysarg; i++) 2840Sstevel@tonic-gate mdb_printf(", %lx", si.si_sysarg[i]); 2850Sstevel@tonic-gate } 2860Sstevel@tonic-gate mdb_printf(" )\n"); 2870Sstevel@tonic-gate } 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate for (i = 0; i < sizeof (msname) / sizeof (msname[0]); i++) { 2900Sstevel@tonic-gate mdb_printf(" mstate[\"%s\"] = %d\n", 2910Sstevel@tonic-gate msname[i], si.si_mstate[i]); 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate break; 2940Sstevel@tonic-gate } 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate return (DCMD_OK); 2970Sstevel@tonic-gate } 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate static int 3000Sstevel@tonic-gate uc_walk_step(mdb_walk_state_t *wsp) 3010Sstevel@tonic-gate { 3020Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 3030Sstevel@tonic-gate ucontext_t uc; 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate if (addr == NULL) 3060Sstevel@tonic-gate return (WALK_DONE); 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 3090Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 3100Sstevel@tonic-gate return (WALK_ERR); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)uc.uc_link; 3140Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata)); 3150Sstevel@tonic-gate } 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate static int 3180Sstevel@tonic-gate oldc_walk_init(mdb_walk_state_t *wsp) 3190Sstevel@tonic-gate { 3200Sstevel@tonic-gate ssize_t nbytes = mdb_get_xdata("lwpstatus", NULL, 0); 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate if (nbytes <= 0) { 3230Sstevel@tonic-gate mdb_warn("lwpstatus information not available"); 3240Sstevel@tonic-gate return (WALK_ERR); 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate if (wsp->walk_addr != NULL) { 3280Sstevel@tonic-gate mdb_warn("walker only supports global walk\n"); 3290Sstevel@tonic-gate return (WALK_ERR); 3300Sstevel@tonic-gate } 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate wsp->walk_addr = nbytes; /* Use walk_addr to track size */ 3330Sstevel@tonic-gate wsp->walk_data = mdb_alloc(nbytes, UM_SLEEP); 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate if (mdb_get_xdata("lwpstatus", wsp->walk_data, nbytes) != nbytes) { 3360Sstevel@tonic-gate mdb_warn("failed to read lwpstatus information"); 3370Sstevel@tonic-gate mdb_free(wsp->walk_data, nbytes); 3380Sstevel@tonic-gate return (WALK_ERR); 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate wsp->walk_arg = wsp->walk_data; /* Use walk_arg to track pointer */ 3420Sstevel@tonic-gate return (WALK_NEXT); 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate static int 3460Sstevel@tonic-gate oldc_walk_step(mdb_walk_state_t *wsp) 3470Sstevel@tonic-gate { 3480Sstevel@tonic-gate const lwpstatus_t *lsp, *end; 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate end = (const lwpstatus_t *)((uintptr_t)wsp->walk_data + wsp->walk_addr); 3510Sstevel@tonic-gate lsp = wsp->walk_arg; 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate wsp->walk_arg = (void *)(lsp + 1); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate if (lsp < end) { 3560Sstevel@tonic-gate uintptr_t addr = lsp->pr_oldcontext; 3570Sstevel@tonic-gate ucontext_t uc; 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate if (addr == NULL) 3600Sstevel@tonic-gate return (WALK_NEXT); 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 3630Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 3640Sstevel@tonic-gate return (WALK_NEXT); 3650Sstevel@tonic-gate } 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata)); 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate return (WALK_DONE); 3710Sstevel@tonic-gate } 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate static void 3740Sstevel@tonic-gate oldc_walk_fini(mdb_walk_state_t *wsp) 3750Sstevel@tonic-gate { 3760Sstevel@tonic-gate mdb_free(wsp->walk_data, wsp->walk_addr); /* walk_addr has size */ 3770Sstevel@tonic-gate } 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate /* 3800Sstevel@tonic-gate * ==================== threads ========================== 3810Sstevel@tonic-gate * These are the interfaces that used to require libthread. 3820Sstevel@tonic-gate * Now, libthread has been folded into libc. 3830Sstevel@tonic-gate * ======================================================= 3840Sstevel@tonic-gate */ 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate /* 3870Sstevel@tonic-gate * prt_addr() is called up to three times to generate arguments for 3880Sstevel@tonic-gate * one call to mdb_printf(). We must return at least three different 3890Sstevel@tonic-gate * pointers to static storage for consecutive calls to prt_addr(). 3900Sstevel@tonic-gate */ 3910Sstevel@tonic-gate static const char * 3920Sstevel@tonic-gate prt_addr(void *addr, int pad) 3930Sstevel@tonic-gate { 3940Sstevel@tonic-gate static char buffer[4][24]; 3950Sstevel@tonic-gate static int ix = 0; 3960Sstevel@tonic-gate char *buf; 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate if (ix == 4) /* use buffers in sequence: 0, 1, 2, 3 */ 3990Sstevel@tonic-gate ix = 0; 4000Sstevel@tonic-gate buf = buffer[ix++]; 4010Sstevel@tonic-gate if (addr == NULL) 4020Sstevel@tonic-gate return (pad? "<NULL> " : "<NULL>"); 4030Sstevel@tonic-gate else { 4040Sstevel@tonic-gate #ifdef _LP64 4050Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%016lx", addr); 4060Sstevel@tonic-gate if (pad) 4070Sstevel@tonic-gate (void) strcpy(buf + 18, " "); 4080Sstevel@tonic-gate #else 4090Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%08lx", addr); 4100Sstevel@tonic-gate if (pad) 4110Sstevel@tonic-gate (void) strcpy(buf + 10, " "); 4120Sstevel@tonic-gate #endif /* _LP64 */ 4130Sstevel@tonic-gate return (buf); 4140Sstevel@tonic-gate } 4150Sstevel@tonic-gate } 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate #define HD(str) mdb_printf(" " str "\n") 4180Sstevel@tonic-gate #define OFFSTR "+0x%-7lx " 4190Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(ulwp_t, member)) 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate /*ARGSUSED*/ 4220Sstevel@tonic-gate static int 4230Sstevel@tonic-gate d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4240Sstevel@tonic-gate { 4250Sstevel@tonic-gate ulwp_t ulwp; 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate if (argc != 0 || !(flags & DCMD_ADDRSPEC)) 4280Sstevel@tonic-gate return (DCMD_USAGE); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && 4310Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)), 4320Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { 4330Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr); 4340Sstevel@tonic-gate return (DCMD_ERR); 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate mdb_printf("%#a\n", addr); 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate HD("self uberdata"); 4400Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s\n", 4410Sstevel@tonic-gate OFFSET(ul_self), 4420Sstevel@tonic-gate prt_addr(ulwp.ul_self, 1), 4430Sstevel@tonic-gate prt_addr(ulwp.ul_uberdata, 0)); 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate HD("tlsent ntlsent"); 4460Sstevel@tonic-gate mdb_printf(OFFSTR "%s %ld\n", 4470Sstevel@tonic-gate OFFSET(ul_tlsent), 4480Sstevel@tonic-gate prt_addr(ulwp.ul_tlsent, 1), 4490Sstevel@tonic-gate ulwp.ul_ntlsent); 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate HD("forw back next"); 4520Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 4530Sstevel@tonic-gate OFFSET(ul_forw), 4540Sstevel@tonic-gate prt_addr(ulwp.ul_forw, 1), 4550Sstevel@tonic-gate prt_addr(ulwp.ul_back, 1), 4560Sstevel@tonic-gate prt_addr(ulwp.ul_next, 0)); 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate HD("hash rval stk"); 4590Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 4600Sstevel@tonic-gate OFFSET(ul_hash), 4610Sstevel@tonic-gate prt_addr(ulwp.ul_hash, 1), 4620Sstevel@tonic-gate prt_addr(ulwp.ul_rval, 1), 4630Sstevel@tonic-gate prt_addr(ulwp.ul_stk, 0)); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate HD("mapsiz guardsize stktop stksiz"); 4660Sstevel@tonic-gate mdb_printf(OFFSTR "%-10ld %-10ld %s %ld\n", 4670Sstevel@tonic-gate OFFSET(ul_mapsiz), 4680Sstevel@tonic-gate ulwp.ul_mapsiz, 4690Sstevel@tonic-gate ulwp.ul_guardsize, 4700Sstevel@tonic-gate prt_addr((void *)ulwp.ul_stktop, 1), 4710Sstevel@tonic-gate ulwp.ul_stksiz); 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate HD("ustack.ss_sp ustack.ss_size ustack.ss_flags"); 4740Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-21ld %s\n", 4750Sstevel@tonic-gate OFFSET(ul_ustack.ss_sp), 4760Sstevel@tonic-gate prt_addr(ulwp.ul_ustack.ss_sp, 1), 4770Sstevel@tonic-gate ulwp.ul_ustack.ss_size, 4780Sstevel@tonic-gate stack_flags(&ulwp.ul_ustack)); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate HD("ix lwpid pri mappedpri policy pri_mapped"); 4810Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 4820Sstevel@tonic-gate OFFSET(ul_ix), 4830Sstevel@tonic-gate ulwp.ul_ix, 4840Sstevel@tonic-gate ulwp.ul_lwpid, 4850Sstevel@tonic-gate ulwp.ul_pri, 4860Sstevel@tonic-gate ulwp.ul_mappedpri, 4870Sstevel@tonic-gate ulwp.ul_policy, 4880Sstevel@tonic-gate ulwp.ul_pri_mapped); 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate HD("cursig pleasestop stop signalled dead unwind"); 4910Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d ", 4920Sstevel@tonic-gate OFFSET(ul_cursig), 4930Sstevel@tonic-gate ulwp.ul_cursig); 4940Sstevel@tonic-gate mdb_printf(ulwp.ul_pleasestop? "0x%-8x " : "%-10d ", 4950Sstevel@tonic-gate ulwp.ul_pleasestop); 4960Sstevel@tonic-gate mdb_printf(ulwp.ul_stop? "0x%-8x " : "%-10d ", 4970Sstevel@tonic-gate ulwp.ul_stop); 4980Sstevel@tonic-gate mdb_printf("%-10d %-10d %d\n", 4990Sstevel@tonic-gate ulwp.ul_signalled, 5000Sstevel@tonic-gate ulwp.ul_dead, 5010Sstevel@tonic-gate ulwp.ul_unwind); 5020Sstevel@tonic-gate 5031885Sraf HD("detached writer stopping can'prolog preempt savpreempt"); 5040Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5050Sstevel@tonic-gate OFFSET(ul_detached), 5060Sstevel@tonic-gate ulwp.ul_detached, 5070Sstevel@tonic-gate ulwp.ul_writer, 5080Sstevel@tonic-gate ulwp.ul_stopping, 5091885Sraf ulwp.ul_cancel_prologue, 5100Sstevel@tonic-gate ulwp.ul_preempt, 5110Sstevel@tonic-gate ulwp.ul_savpreempt); 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate HD("sigsuspend main fork primarymap m'spinners d'noreserv"); 5140Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5150Sstevel@tonic-gate OFFSET(ul_sigsuspend), 5160Sstevel@tonic-gate ulwp.ul_sigsuspend, 5170Sstevel@tonic-gate ulwp.ul_main, 5180Sstevel@tonic-gate ulwp.ul_fork, 5190Sstevel@tonic-gate ulwp.ul_primarymap, 5200Sstevel@tonic-gate ulwp.ul_max_spinners, 5210Sstevel@tonic-gate ulwp.ul_door_noreserve); 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate HD("queue_fifo c'w'defer e'detect' async_safe pad1[0] pad1[1]"); 5240Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5250Sstevel@tonic-gate OFFSET(ul_queue_fifo), 5260Sstevel@tonic-gate ulwp.ul_queue_fifo, 5270Sstevel@tonic-gate ulwp.ul_cond_wait_defer, 5280Sstevel@tonic-gate ulwp.ul_error_detection, 5290Sstevel@tonic-gate ulwp.ul_async_safe, 5300Sstevel@tonic-gate ulwp.ul_pad1[0], 5310Sstevel@tonic-gate ulwp.ul_pad1[1]); 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate HD("adapt'spin rele'spin queue_spin critical sigdefer vfork"); 5340Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5350Sstevel@tonic-gate OFFSET(ul_adaptive_spin), 5360Sstevel@tonic-gate ulwp.ul_adaptive_spin, 5370Sstevel@tonic-gate ulwp.ul_release_spin, 5380Sstevel@tonic-gate ulwp.ul_queue_spin, 5390Sstevel@tonic-gate ulwp.ul_critical, 5400Sstevel@tonic-gate ulwp.ul_sigdefer, 5410Sstevel@tonic-gate ulwp.ul_vfork); 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate HD("cancelable c'pending c'disabled c'async save_async mutator"); 5440Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5450Sstevel@tonic-gate OFFSET(ul_cancelable), 5460Sstevel@tonic-gate ulwp.ul_cancelable, 5470Sstevel@tonic-gate ulwp.ul_cancel_pending, 5480Sstevel@tonic-gate ulwp.ul_cancel_disabled, 5490Sstevel@tonic-gate ulwp.ul_cancel_async, 5500Sstevel@tonic-gate ulwp.ul_save_async, 5510Sstevel@tonic-gate ulwp.ul_mutator); 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate HD("created replace nocancel errno errnop"); 5540Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", 5550Sstevel@tonic-gate OFFSET(ul_created), 5560Sstevel@tonic-gate ulwp.ul_created, 5570Sstevel@tonic-gate ulwp.ul_replace, 5580Sstevel@tonic-gate ulwp.ul_nocancel, 5590Sstevel@tonic-gate ulwp.ul_errno, 5600Sstevel@tonic-gate prt_addr(ulwp.ul_errnop, 0)); 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate HD("clnup_hdr schedctl_called schedctl"); 5630Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 5640Sstevel@tonic-gate OFFSET(ul_clnup_hdr), 5650Sstevel@tonic-gate prt_addr(ulwp.ul_clnup_hdr, 1), 5660Sstevel@tonic-gate prt_addr(ulwp.ul_schedctl_called, 1), 5670Sstevel@tonic-gate prt_addr((void *)ulwp.ul_schedctl, 0)); 5680Sstevel@tonic-gate 5693446Smrj HD("bindflags pad2 stsd &ftsd"); 5700Sstevel@tonic-gate mdb_printf(OFFSTR, 5710Sstevel@tonic-gate OFFSET(ul_bindflags)); 5720Sstevel@tonic-gate mdb_printf(ulwp.ul_bindflags? "0x%-8x " : "%-10d ", 5730Sstevel@tonic-gate ulwp.ul_bindflags); 5743446Smrj mdb_printf("%-10d ", ulwp.ul_pad2); 5750Sstevel@tonic-gate mdb_printf("%s %s\n", 5760Sstevel@tonic-gate prt_addr(ulwp.ul_stsd, 1), 5770Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_ftsd[0])), 0)); 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate HD("eventmask[0..1] eventnum eventdata"); 5800Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %-21d %s\n", 5810Sstevel@tonic-gate OFFSET(ul_td_evbuf.eventmask.event_bits[0]), 5820Sstevel@tonic-gate ulwp.ul_td_evbuf.eventmask.event_bits[0], 5830Sstevel@tonic-gate ulwp.ul_td_evbuf.eventmask.event_bits[1], 5840Sstevel@tonic-gate ulwp.ul_td_evbuf.eventnum, 5850Sstevel@tonic-gate prt_addr(ulwp.ul_td_evbuf.eventdata, 0)); 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate HD("td'enable sync'reg qtype cv_wake usropts"); 5880Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d ", 5890Sstevel@tonic-gate OFFSET(ul_td_events_enable), 5900Sstevel@tonic-gate ulwp.ul_td_events_enable, 5910Sstevel@tonic-gate ulwp.ul_sync_obj_reg, 5920Sstevel@tonic-gate ulwp.ul_qtype, 5930Sstevel@tonic-gate ulwp.ul_cv_wake); 5940Sstevel@tonic-gate mdb_printf(ulwp.ul_usropts? "0x%x\n" : "%d\n", 5950Sstevel@tonic-gate ulwp.ul_usropts); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate HD("startpc startarg wchan"); 5980Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 5990Sstevel@tonic-gate OFFSET(ul_startpc), 6000Sstevel@tonic-gate prt_addr((void *)ulwp.ul_startpc, 1), 6010Sstevel@tonic-gate prt_addr(ulwp.ul_startarg, 1), 6020Sstevel@tonic-gate prt_addr(ulwp.ul_wchan, 0)); 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate HD("link sleepq cvmutex"); 6050Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 6060Sstevel@tonic-gate OFFSET(ul_link), 6070Sstevel@tonic-gate prt_addr(ulwp.ul_link, 1), 6080Sstevel@tonic-gate prt_addr(ulwp.ul_sleepq, 1), 6090Sstevel@tonic-gate prt_addr(ulwp.ul_cvmutex, 0)); 6100Sstevel@tonic-gate 611*4574Sraf HD("mxchain epri emappedpri"); 612*4574Sraf mdb_printf(OFFSTR "%s %-10d %d\n", 6130Sstevel@tonic-gate OFFSET(ul_mxchain), 6140Sstevel@tonic-gate prt_addr(ulwp.ul_mxchain, 1), 6150Sstevel@tonic-gate ulwp.ul_epri, 616*4574Sraf ulwp.ul_emappedpri); 6170Sstevel@tonic-gate 618*4574Sraf HD("rdlockcnt rd_rwlock rd_count"); 619*4574Sraf mdb_printf(OFFSTR "%-21d %s %d\n", 620*4574Sraf OFFSET(ul_rdlockcnt), 621*4574Sraf ulwp.ul_rdlockcnt, 6220Sstevel@tonic-gate prt_addr(ulwp.ul_readlock.single.rd_rwlock, 1), 623*4574Sraf ulwp.ul_readlock.single.rd_count); 624*4574Sraf 625*4574Sraf HD("heldlockcnt heldlocks tpdp"); 626*4574Sraf mdb_printf(OFFSTR "%-21d %s %s\n", 627*4574Sraf OFFSET(ul_heldlockcnt), 628*4574Sraf ulwp.ul_heldlockcnt, 629*4574Sraf prt_addr(ulwp.ul_heldlocks.single, 1), 6300Sstevel@tonic-gate prt_addr(ulwp.ul_tpdp, 0)); 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate HD("siglink s'l'spin s'l'spin2 s'l'sleep s'l'wakeup"); 6330Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %-10d %-10d\n", 6340Sstevel@tonic-gate OFFSET(ul_siglink), 6350Sstevel@tonic-gate prt_addr(ulwp.ul_siglink, 1), 6360Sstevel@tonic-gate ulwp.ul_spin_lock_spin, 6370Sstevel@tonic-gate ulwp.ul_spin_lock_spin2, 6380Sstevel@tonic-gate ulwp.ul_spin_lock_sleep, 6390Sstevel@tonic-gate ulwp.ul_spin_lock_wakeup); 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate /* 6420Sstevel@tonic-gate * The remainder of the ulwp_t structure 6430Sstevel@tonic-gate * is invalid if this is a replacement. 6440Sstevel@tonic-gate */ 6450Sstevel@tonic-gate if (ulwp.ul_replace) 6460Sstevel@tonic-gate return (DCMD_OK); 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate HD("sigmask[0..3]"); 6490Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 6500Sstevel@tonic-gate OFFSET(ul_sigmask.__sigbits[0]), 6510Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[0], 6520Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[1], 6530Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[2], 6540Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[3]); 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate HD("tmpmask[0..3]"); 6570Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 6580Sstevel@tonic-gate OFFSET(ul_tmpmask.__sigbits[0]), 6590Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[0], 6600Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[1], 6610Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[2], 6620Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[3]); 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate HD("&siginfo &spinlock &fpuenv"); 6650Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 6660Sstevel@tonic-gate OFFSET(ul_siginfo), 6670Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_siginfo)), 1), 6680Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_spinlock)), 1), 6690Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_fpuenv)), 0)); 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate return (DCMD_OK); 6720Sstevel@tonic-gate } 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate /* 6750Sstevel@tonic-gate * Get the address of the unique uberdata_t structure. 6760Sstevel@tonic-gate */ 6770Sstevel@tonic-gate static uintptr_t 6780Sstevel@tonic-gate uberdata_addr(void) 6790Sstevel@tonic-gate { 6800Sstevel@tonic-gate uintptr_t uaddr; 6810Sstevel@tonic-gate uintptr_t addr; 6820Sstevel@tonic-gate GElf_Sym sym; 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_tdb_bootstrap", &sym) != 0) { 6850Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_tdb_bootstrap"); 6860Sstevel@tonic-gate return (NULL); 6870Sstevel@tonic-gate } 6880Sstevel@tonic-gate if (mdb_vread(&addr, sizeof (addr), sym.st_value) == sizeof (addr) && 6890Sstevel@tonic-gate addr != NULL && 6900Sstevel@tonic-gate mdb_vread(&uaddr, sizeof (uaddr), addr) == sizeof (uaddr) && 6910Sstevel@tonic-gate uaddr != NULL) { 6920Sstevel@tonic-gate return (uaddr); 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_uberdata", &sym) != 0) { 6950Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_uberdata"); 6960Sstevel@tonic-gate return (NULL); 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate return ((uintptr_t)sym.st_value); 6990Sstevel@tonic-gate } 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate #undef OFFSET 7020Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(uberdata_t, member)) 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate /*ARGSUSED*/ 7050Sstevel@tonic-gate static int 7060Sstevel@tonic-gate d_uberdata(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 7070Sstevel@tonic-gate { 7080Sstevel@tonic-gate uberdata_t uberdata; 7090Sstevel@tonic-gate int i; 7100Sstevel@tonic-gate 7110Sstevel@tonic-gate if (argc != 0) 7120Sstevel@tonic-gate return (DCMD_USAGE); 7130Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) && (addr = uberdata_addr()) == NULL) 7140Sstevel@tonic-gate return (DCMD_ERR); 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate if (mdb_vread(&uberdata, sizeof (uberdata), addr) != 7170Sstevel@tonic-gate sizeof (uberdata)) { 7180Sstevel@tonic-gate mdb_warn("failed to read uberdata at 0x%p", addr); 7190Sstevel@tonic-gate return (DCMD_ERR); 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate mdb_printf("%#a\n", addr); 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate HD("&link_lock &fork_lock fork_owner"); 7250Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7260Sstevel@tonic-gate OFFSET(link_lock), 7270Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(link_lock)), 1), 7280Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(fork_lock)), 1), 7290Sstevel@tonic-gate prt_addr((void *)uberdata.fork_owner, 0)); 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate HD("&tdb_hash_lock &tdb_hash_lock_stats &siguaction[0]"); 7320Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7330Sstevel@tonic-gate OFFSET(tdb_hash_lock), 7340Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tdb_hash_lock)), 1), 7350Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tdb_hash_lock_stats)), 1), 7360Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(siguaction)), 0)); 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate HD("&bucket free_list chunks"); 7390Sstevel@tonic-gate for (i = 0; i < NBUCKETS; i++) { 7400Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7410Sstevel@tonic-gate OFFSET(bucket[i]), 7420Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(bucket[i])), 1), 7430Sstevel@tonic-gate prt_addr(uberdata.bucket[i].free_list, 1), 7440Sstevel@tonic-gate uberdata.bucket[i].chunks); 7450Sstevel@tonic-gate } 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate HD("&atexit_root head exit_frame_monitor"); 7480Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7490Sstevel@tonic-gate OFFSET(atexit_root), 7500Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(atexit_root.exitfns_lock)), 1), 7510Sstevel@tonic-gate prt_addr(uberdata.atexit_root.head, 1), 7520Sstevel@tonic-gate prt_addr(uberdata.atexit_root.exit_frame_monitor, 0)); 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate HD("&tsd_metadata tsdm_nkeys tsdm_nused tsdm_destro"); 7550Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %s\n", 7560Sstevel@tonic-gate OFFSET(tsd_metadata), 7570Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tsd_metadata.tsdm_lock)), 1), 7580Sstevel@tonic-gate uberdata.tsd_metadata.tsdm_nkeys, 7590Sstevel@tonic-gate uberdata.tsd_metadata.tsdm_nused, 7600Sstevel@tonic-gate prt_addr((void *)uberdata.tsd_metadata.tsdm_destro, 0)); 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate HD("&tls_metadata tls_modinfo.data tls_modinfo.size"); 7630Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7640Sstevel@tonic-gate OFFSET(tls_metadata), 7650Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tls_metadata.tls_lock)), 1), 7660Sstevel@tonic-gate prt_addr(uberdata.tls_metadata.tls_modinfo.tls_data, 1), 7670Sstevel@tonic-gate uberdata.tls_metadata.tls_modinfo.tls_size); 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate HD(" static_tls.data static_tls.size"); 7700Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7710Sstevel@tonic-gate OFFSET(tls_metadata.static_tls), 7720Sstevel@tonic-gate " ", 7730Sstevel@tonic-gate prt_addr(uberdata.tls_metadata.static_tls.tls_data, 1), 7740Sstevel@tonic-gate uberdata.tls_metadata.static_tls.tls_size); 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate HD("primary_ma bucket_ini uflags.mt uflags.pad uflags.trs uflags.ted"); 7770Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 7780Sstevel@tonic-gate OFFSET(primary_map), 7790Sstevel@tonic-gate uberdata.primary_map, 7800Sstevel@tonic-gate uberdata.bucket_init, 7810Sstevel@tonic-gate uberdata.uberflags.uf_x.x_mt, 7820Sstevel@tonic-gate uberdata.uberflags.uf_x.x_pad, 7830Sstevel@tonic-gate uberdata.uberflags.uf_x.x_tdb_register_sync, 7840Sstevel@tonic-gate uberdata.uberflags.uf_x.x_thread_error_detection); 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate HD("queue_head thr_hash_table hash_size hash_mask"); 7870Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d 0x%x\n", 7880Sstevel@tonic-gate OFFSET(queue_head), 7890Sstevel@tonic-gate prt_addr(uberdata.queue_head, 1), 7900Sstevel@tonic-gate prt_addr(uberdata.thr_hash_table, 1), 7910Sstevel@tonic-gate uberdata.hash_size, 7920Sstevel@tonic-gate uberdata.hash_mask); 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate HD("ulwp_one all_lwps all_zombies"); 7950Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7960Sstevel@tonic-gate OFFSET(ulwp_one), 7970Sstevel@tonic-gate prt_addr(uberdata.ulwp_one, 1), 7980Sstevel@tonic-gate prt_addr(uberdata.all_lwps, 1), 7990Sstevel@tonic-gate prt_addr(uberdata.all_zombies, 0)); 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate HD("nthreads nzombies ndaemons pid sigacthandler"); 8020Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", 8030Sstevel@tonic-gate OFFSET(nthreads), 8040Sstevel@tonic-gate uberdata.nthreads, 8050Sstevel@tonic-gate uberdata.nzombies, 8060Sstevel@tonic-gate uberdata.ndaemons, 8070Sstevel@tonic-gate (int)uberdata.pid, 8080Sstevel@tonic-gate prt_addr((void *)uberdata.sigacthandler, 0)); 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate HD("lwp_stacks lwp_laststack nfreestack stk_cache"); 8110Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 8120Sstevel@tonic-gate OFFSET(lwp_stacks), 8130Sstevel@tonic-gate prt_addr(uberdata.lwp_stacks, 1), 8140Sstevel@tonic-gate prt_addr(uberdata.lwp_laststack, 1), 8150Sstevel@tonic-gate uberdata.nfreestack, 8160Sstevel@tonic-gate uberdata.thread_stack_cache); 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate HD("ulwp_freelist ulwp_lastfree"); 8190Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s\n", 8200Sstevel@tonic-gate OFFSET(ulwp_freelist), 8210Sstevel@tonic-gate prt_addr(uberdata.ulwp_freelist, 1), 8220Sstevel@tonic-gate prt_addr(uberdata.ulwp_lastfree, 0)); 8230Sstevel@tonic-gate 824*4574Sraf HD("ulwp_replace_free ulwp_replace_last"); 825*4574Sraf mdb_printf(OFFSTR "%s %s\n", 8260Sstevel@tonic-gate OFFSET(ulwp_replace_free), 8270Sstevel@tonic-gate prt_addr(uberdata.ulwp_replace_free, 1), 828*4574Sraf prt_addr(uberdata.ulwp_replace_last, 0)); 829*4574Sraf 830*4574Sraf HD("atforklist robustlocks"); 831*4574Sraf mdb_printf(OFFSTR "%s %s\n", 832*4574Sraf OFFSET(atforklist), 833*4574Sraf prt_addr(uberdata.atforklist, 1), 834*4574Sraf prt_addr(uberdata.robustlocks, 0)); 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate HD("tdb_bootstrap tdb_sync_addr_hash tdb_'count tdb_'fail"); 8370Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 8380Sstevel@tonic-gate OFFSET(tdb_bootstrap), 8390Sstevel@tonic-gate prt_addr(uberdata.tdb_bootstrap, 1), 8400Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_hash, 1), 8410Sstevel@tonic-gate uberdata.tdb.tdb_register_count, 8420Sstevel@tonic-gate uberdata.tdb.tdb_hash_alloc_failed); 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate HD("tdb_sync_addr_free tdb_sync_addr_last tdb_sync_alloc"); 8450Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 8460Sstevel@tonic-gate OFFSET(tdb.tdb_sync_addr_free), 8470Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_free, 1), 8480Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_last, 1), 8490Sstevel@tonic-gate uberdata.tdb.tdb_sync_alloc); 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate HD("tdb_ev_global_mask tdb_events"); 8520Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %s\n", 8530Sstevel@tonic-gate OFFSET(tdb.tdb_ev_global_mask), 8540Sstevel@tonic-gate uberdata.tdb.tdb_ev_global_mask.event_bits[0], 8550Sstevel@tonic-gate uberdata.tdb.tdb_ev_global_mask.event_bits[1], 8560Sstevel@tonic-gate prt_addr((void *)uberdata.tdb.tdb_events, 0)); 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate return (DCMD_OK); 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate static int 8620Sstevel@tonic-gate ulwp_walk_init(mdb_walk_state_t *wsp) 8630Sstevel@tonic-gate { 8640Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 8650Sstevel@tonic-gate uintptr_t uber_addr; 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate if (addr == NULL && 8680Sstevel@tonic-gate ((uber_addr = uberdata_addr()) == NULL || 8690Sstevel@tonic-gate mdb_vread(&addr, sizeof (addr), 8700Sstevel@tonic-gate uber_addr + OFFSETOF(uberdata_t, all_lwps)) 8710Sstevel@tonic-gate != sizeof (addr))) { 8720Sstevel@tonic-gate mdb_warn("cannot find 'uberdata.all_lwps'"); 8730Sstevel@tonic-gate return (WALK_ERR); 8740Sstevel@tonic-gate } 8750Sstevel@tonic-gate if (addr == NULL) 8760Sstevel@tonic-gate return (WALK_DONE); 8770Sstevel@tonic-gate wsp->walk_addr = addr; 8780Sstevel@tonic-gate wsp->walk_data = (void *)addr; 8790Sstevel@tonic-gate return (WALK_NEXT); 8800Sstevel@tonic-gate } 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate static int 8830Sstevel@tonic-gate ulwp_walk_step(mdb_walk_state_t *wsp) 8840Sstevel@tonic-gate { 8850Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 8860Sstevel@tonic-gate ulwp_t ulwp; 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate if (addr == NULL) 8890Sstevel@tonic-gate return (WALK_DONE); 8900Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && 8910Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)), 8920Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { 8930Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr); 8940Sstevel@tonic-gate return (WALK_ERR); 8950Sstevel@tonic-gate } 8960Sstevel@tonic-gate /* 8970Sstevel@tonic-gate * If we have looped around to the beginning 8980Sstevel@tonic-gate * of the circular linked list, we are done. 8990Sstevel@tonic-gate */ 9000Sstevel@tonic-gate if ((wsp->walk_addr = (uintptr_t)ulwp.ul_forw) 9010Sstevel@tonic-gate == (uintptr_t)wsp->walk_data) 9020Sstevel@tonic-gate wsp->walk_addr = NULL; 9030Sstevel@tonic-gate return (wsp->walk_callback(addr, &ulwp, wsp->walk_cbdata)); 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate /* 9070Sstevel@tonic-gate * ======================================================= 9080Sstevel@tonic-gate * End of thread (previously libthread) interfaces. 9090Sstevel@tonic-gate * ==================== threads ========================== 9100Sstevel@tonic-gate */ 9110Sstevel@tonic-gate 9120Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 9130Sstevel@tonic-gate { "jmp_buf", ":", "print jmp_buf contents", d_jmp_buf, NULL }, 9140Sstevel@tonic-gate { "sigjmp_buf", ":", "print sigjmp_buf contents", d_sigjmp_buf, NULL }, 9150Sstevel@tonic-gate { "siginfo", ":", "print siginfo_t structure", d_siginfo, NULL }, 9160Sstevel@tonic-gate { "ucontext", ":", "print ucontext_t structure", d_ucontext, NULL }, 9170Sstevel@tonic-gate { "ulwp", ":", "print ulwp_t structure", d_ulwp, NULL }, 9180Sstevel@tonic-gate { "uberdata", ":", "print uberdata_t structure", d_uberdata, NULL }, 9190Sstevel@tonic-gate { NULL } 9200Sstevel@tonic-gate }; 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 9230Sstevel@tonic-gate { "ucontext", "walk ucontext_t uc_link list", 9240Sstevel@tonic-gate NULL, uc_walk_step, NULL, NULL }, 9250Sstevel@tonic-gate { "oldcontext", "walk per-lwp oldcontext pointers", 9260Sstevel@tonic-gate oldc_walk_init, oldc_walk_step, oldc_walk_fini, NULL }, 9270Sstevel@tonic-gate { "ulwps", "walk list of ulwp_t pointers", 9280Sstevel@tonic-gate ulwp_walk_init, ulwp_walk_step, NULL, NULL }, 9290Sstevel@tonic-gate { NULL } 9300Sstevel@tonic-gate }; 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate const mdb_modinfo_t * 9350Sstevel@tonic-gate _mdb_init(void) 9360Sstevel@tonic-gate { 9370Sstevel@tonic-gate return (&modinfo); 9380Sstevel@tonic-gate } 939