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 /* 235891Sraf * Copyright 2008 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", 4416515Sraf OFFSET(ul_self), 4426515Sraf prt_addr(ulwp.ul_self, 1), 4436515Sraf prt_addr(ulwp.ul_uberdata, 0)); 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate HD("tlsent ntlsent"); 4460Sstevel@tonic-gate mdb_printf(OFFSTR "%s %ld\n", 4476515Sraf OFFSET(ul_tlsent), 4486515Sraf prt_addr(ulwp.ul_tlsent, 1), 4496515Sraf ulwp.ul_ntlsent); 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate HD("forw back next"); 4520Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 4536515Sraf OFFSET(ul_forw), 4546515Sraf prt_addr(ulwp.ul_forw, 1), 4556515Sraf prt_addr(ulwp.ul_back, 1), 4566515Sraf 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", 4606515Sraf OFFSET(ul_hash), 4616515Sraf prt_addr(ulwp.ul_hash, 1), 4626515Sraf prt_addr(ulwp.ul_rval, 1), 4636515Sraf 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", 4676515Sraf OFFSET(ul_mapsiz), 4686515Sraf ulwp.ul_mapsiz, 4696515Sraf ulwp.ul_guardsize, 4706515Sraf prt_addr((void *)ulwp.ul_stktop, 1), 4716515Sraf 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", 4756515Sraf OFFSET(ul_ustack.ss_sp), 4766515Sraf prt_addr(ulwp.ul_ustack.ss_sp, 1), 4776515Sraf ulwp.ul_ustack.ss_size, 4786515Sraf stack_flags(&ulwp.ul_ustack)); 4790Sstevel@tonic-gate 4806247Sraf HD("ix lwpid pri epri policy cid"); 4810Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 4826515Sraf OFFSET(ul_ix), 4836515Sraf ulwp.ul_ix, 4846515Sraf ulwp.ul_lwpid, 4856515Sraf ulwp.ul_pri, 4866515Sraf ulwp.ul_epri, 4876515Sraf ulwp.ul_policy, 4886515Sraf ulwp.ul_cid); 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate HD("cursig pleasestop stop signalled dead unwind"); 4910Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d ", 4926515Sraf OFFSET(ul_cursig), 4936515Sraf ulwp.ul_cursig); 4940Sstevel@tonic-gate mdb_printf(ulwp.ul_pleasestop? "0x%-8x " : "%-10d ", 4956515Sraf ulwp.ul_pleasestop); 4960Sstevel@tonic-gate mdb_printf(ulwp.ul_stop? "0x%-8x " : "%-10d ", 4976515Sraf ulwp.ul_stop); 4980Sstevel@tonic-gate mdb_printf("%-10d %-10d %d\n", 4996515Sraf ulwp.ul_signalled, 5006515Sraf ulwp.ul_dead, 5016515Sraf 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", 5056515Sraf OFFSET(ul_detached), 5066515Sraf ulwp.ul_detached, 5076515Sraf ulwp.ul_writer, 5086515Sraf ulwp.ul_stopping, 5096515Sraf ulwp.ul_cancel_prologue, 5106515Sraf ulwp.ul_preempt, 5116515Sraf 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", 5156515Sraf OFFSET(ul_sigsuspend), 5166515Sraf ulwp.ul_sigsuspend, 5176515Sraf ulwp.ul_main, 5186515Sraf ulwp.ul_fork, 5196515Sraf ulwp.ul_primarymap, 5206515Sraf ulwp.ul_max_spinners, 5216515Sraf ulwp.ul_door_noreserve); 5220Sstevel@tonic-gate 5236247Sraf HD("queue_fifo c'w'defer e'detect' async_safe rt rtqueued"); 5240Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5256515Sraf OFFSET(ul_queue_fifo), 5266515Sraf ulwp.ul_queue_fifo, 5276515Sraf ulwp.ul_cond_wait_defer, 5286515Sraf ulwp.ul_error_detection, 5296515Sraf ulwp.ul_async_safe, 5306515Sraf ulwp.ul_rt, 5316515Sraf ulwp.ul_rtqueued); 5320Sstevel@tonic-gate 533*7255Sraf HD("misaligned adapt'spin queue_spin critical sigdefer vfork"); 534*7255Sraf mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 535*7255Sraf OFFSET(ul_misaligned), 536*7255Sraf ulwp.ul_misaligned, 5376515Sraf ulwp.ul_adaptive_spin, 5386515Sraf ulwp.ul_queue_spin, 5396515Sraf ulwp.ul_critical, 5406515Sraf ulwp.ul_sigdefer, 5416515Sraf 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", 5456515Sraf OFFSET(ul_cancelable), 5466515Sraf ulwp.ul_cancelable, 5476515Sraf ulwp.ul_cancel_pending, 5486515Sraf ulwp.ul_cancel_disabled, 5496515Sraf ulwp.ul_cancel_async, 5506515Sraf ulwp.ul_save_async, 5516515Sraf 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", 5556515Sraf OFFSET(ul_created), 5566515Sraf ulwp.ul_created, 5576515Sraf ulwp.ul_replace, 5586515Sraf ulwp.ul_nocancel, 5596515Sraf ulwp.ul_errno, 5606515Sraf 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", 5646515Sraf OFFSET(ul_clnup_hdr), 5656515Sraf prt_addr(ulwp.ul_clnup_hdr, 1), 5666515Sraf prt_addr(ulwp.ul_schedctl_called, 1), 5676515Sraf prt_addr((void *)ulwp.ul_schedctl, 0)); 5680Sstevel@tonic-gate 5695891Sraf HD("bindflags libc_locks stsd &ftsd"); 5700Sstevel@tonic-gate mdb_printf(OFFSTR, 5716515Sraf OFFSET(ul_bindflags)); 5720Sstevel@tonic-gate mdb_printf(ulwp.ul_bindflags? "0x%-8x " : "%-10d ", 5736515Sraf ulwp.ul_bindflags); 5745891Sraf mdb_printf("%-10d ", ulwp.ul_libc_locks); 5750Sstevel@tonic-gate mdb_printf("%s %s\n", 5766515Sraf prt_addr(ulwp.ul_stsd, 1), 5776515Sraf 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", 5816515Sraf OFFSET(ul_td_evbuf.eventmask.event_bits[0]), 5826515Sraf ulwp.ul_td_evbuf.eventmask.event_bits[0], 5836515Sraf ulwp.ul_td_evbuf.eventmask.event_bits[1], 5846515Sraf ulwp.ul_td_evbuf.eventnum, 5856515Sraf 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 ", 5896515Sraf OFFSET(ul_td_events_enable), 5906515Sraf ulwp.ul_td_events_enable, 5916515Sraf ulwp.ul_sync_obj_reg, 5926515Sraf ulwp.ul_qtype, 5936515Sraf ulwp.ul_cv_wake); 5940Sstevel@tonic-gate mdb_printf(ulwp.ul_usropts? "0x%x\n" : "%d\n", 5956515Sraf ulwp.ul_usropts); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate HD("startpc startarg wchan"); 5980Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 5996515Sraf OFFSET(ul_startpc), 6006515Sraf prt_addr((void *)ulwp.ul_startpc, 1), 6016515Sraf prt_addr(ulwp.ul_startarg, 1), 6026515Sraf 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", 6066515Sraf OFFSET(ul_link), 6076515Sraf prt_addr(ulwp.ul_link, 1), 6086515Sraf prt_addr(ulwp.ul_sleepq, 1), 6096515Sraf prt_addr(ulwp.ul_cvmutex, 0)); 6100Sstevel@tonic-gate 6116247Sraf HD("mxchain save_state"); 6126247Sraf mdb_printf(OFFSTR "%s %d\n", 6136515Sraf OFFSET(ul_mxchain), 6146515Sraf prt_addr(ulwp.ul_mxchain, 1), 6156515Sraf ulwp.ul_save_state); 6160Sstevel@tonic-gate 6174574Sraf HD("rdlockcnt rd_rwlock rd_count"); 6184574Sraf mdb_printf(OFFSTR "%-21d %s %d\n", 6196515Sraf OFFSET(ul_rdlockcnt), 6206515Sraf ulwp.ul_rdlockcnt, 6216515Sraf prt_addr(ulwp.ul_readlock.single.rd_rwlock, 1), 6226515Sraf ulwp.ul_readlock.single.rd_count); 6234574Sraf 6244574Sraf HD("heldlockcnt heldlocks tpdp"); 6254574Sraf mdb_printf(OFFSTR "%-21d %s %s\n", 6266515Sraf OFFSET(ul_heldlockcnt), 6276515Sraf ulwp.ul_heldlockcnt, 6286515Sraf prt_addr(ulwp.ul_heldlocks.single, 1), 6296515Sraf prt_addr(ulwp.ul_tpdp, 0)); 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate HD("siglink s'l'spin s'l'spin2 s'l'sleep s'l'wakeup"); 6326247Sraf mdb_printf(OFFSTR "%s %-10d %-10d %-10d %d\n", 6336515Sraf OFFSET(ul_siglink), 6346515Sraf prt_addr(ulwp.ul_siglink, 1), 6356515Sraf ulwp.ul_spin_lock_spin, 6366515Sraf ulwp.ul_spin_lock_spin2, 6376515Sraf ulwp.ul_spin_lock_sleep, 6386515Sraf ulwp.ul_spin_lock_wakeup); 6390Sstevel@tonic-gate 6406247Sraf HD("&queue_root rtclassid pilocks"); 6416247Sraf mdb_printf(OFFSTR "%s %-10d %d\n", 6426515Sraf OFFSET(ul_queue_root), 6436515Sraf prt_addr((void *)(addr + OFFSET(ul_queue_root)), 1), 6446515Sraf ulwp.ul_rtclassid, 6456515Sraf ulwp.ul_pilocks); 6466247Sraf 6470Sstevel@tonic-gate /* 6480Sstevel@tonic-gate * The remainder of the ulwp_t structure 6490Sstevel@tonic-gate * is invalid if this is a replacement. 6500Sstevel@tonic-gate */ 6510Sstevel@tonic-gate if (ulwp.ul_replace) 6520Sstevel@tonic-gate return (DCMD_OK); 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate HD("sigmask[0..3]"); 6550Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 6566515Sraf OFFSET(ul_sigmask.__sigbits[0]), 6576515Sraf ulwp.ul_sigmask.__sigbits[0], 6586515Sraf ulwp.ul_sigmask.__sigbits[1], 6596515Sraf ulwp.ul_sigmask.__sigbits[2], 6606515Sraf ulwp.ul_sigmask.__sigbits[3]); 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate HD("tmpmask[0..3]"); 6630Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 6646515Sraf OFFSET(ul_tmpmask.__sigbits[0]), 6656515Sraf ulwp.ul_tmpmask.__sigbits[0], 6666515Sraf ulwp.ul_tmpmask.__sigbits[1], 6676515Sraf ulwp.ul_tmpmask.__sigbits[2], 6686515Sraf ulwp.ul_tmpmask.__sigbits[3]); 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate HD("&siginfo &spinlock &fpuenv"); 6710Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 6726515Sraf OFFSET(ul_siginfo), 6736515Sraf prt_addr((void *)(addr + OFFSET(ul_siginfo)), 1), 6746515Sraf prt_addr((void *)(addr + OFFSET(ul_spinlock)), 1), 6756515Sraf prt_addr((void *)(addr + OFFSET(ul_fpuenv)), 0)); 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate return (DCMD_OK); 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate /* 6810Sstevel@tonic-gate * Get the address of the unique uberdata_t structure. 6820Sstevel@tonic-gate */ 6830Sstevel@tonic-gate static uintptr_t 6840Sstevel@tonic-gate uberdata_addr(void) 6850Sstevel@tonic-gate { 6860Sstevel@tonic-gate uintptr_t uaddr; 6870Sstevel@tonic-gate uintptr_t addr; 6880Sstevel@tonic-gate GElf_Sym sym; 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_tdb_bootstrap", &sym) != 0) { 6910Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_tdb_bootstrap"); 6920Sstevel@tonic-gate return (NULL); 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate if (mdb_vread(&addr, sizeof (addr), sym.st_value) == sizeof (addr) && 6950Sstevel@tonic-gate addr != NULL && 6960Sstevel@tonic-gate mdb_vread(&uaddr, sizeof (uaddr), addr) == sizeof (uaddr) && 6970Sstevel@tonic-gate uaddr != NULL) { 6980Sstevel@tonic-gate return (uaddr); 6990Sstevel@tonic-gate } 7000Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_uberdata", &sym) != 0) { 7010Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_uberdata"); 7020Sstevel@tonic-gate return (NULL); 7030Sstevel@tonic-gate } 7040Sstevel@tonic-gate return ((uintptr_t)sym.st_value); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate #undef OFFSET 7080Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(uberdata_t, member)) 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate /*ARGSUSED*/ 7110Sstevel@tonic-gate static int 7120Sstevel@tonic-gate d_uberdata(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 7130Sstevel@tonic-gate { 7140Sstevel@tonic-gate uberdata_t uberdata; 7150Sstevel@tonic-gate int i; 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate if (argc != 0) 7180Sstevel@tonic-gate return (DCMD_USAGE); 7190Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) && (addr = uberdata_addr()) == NULL) 7200Sstevel@tonic-gate return (DCMD_ERR); 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate if (mdb_vread(&uberdata, sizeof (uberdata), addr) != 7230Sstevel@tonic-gate sizeof (uberdata)) { 7240Sstevel@tonic-gate mdb_warn("failed to read uberdata at 0x%p", addr); 7250Sstevel@tonic-gate return (DCMD_ERR); 7260Sstevel@tonic-gate } 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate mdb_printf("%#a\n", addr); 7290Sstevel@tonic-gate 7306515Sraf HD("&link_lock &ld_lock &fork_lock"); 7310Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7326515Sraf OFFSET(link_lock), 7336515Sraf prt_addr((void *)(addr + OFFSET(link_lock)), 1), 7346515Sraf prt_addr((void *)(addr + OFFSET(ld_lock)), 1), 7356515Sraf prt_addr((void *)(addr + OFFSET(fork_lock)), 0)); 7360Sstevel@tonic-gate 7376515Sraf HD("&atfork_lock &callout_lock &tdb_hash_lock"); 7380Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7396515Sraf OFFSET(atfork_lock), 7406515Sraf prt_addr((void *)(addr + OFFSET(atfork_lock)), 1), 7416515Sraf prt_addr((void *)(addr + OFFSET(callout_lock)), 1), 7426515Sraf prt_addr((void *)(addr + OFFSET(tdb_hash_lock)), 0)); 7436515Sraf 7446515Sraf HD("&tdb_hash_lock_stats &siguaction[0]"); 7456515Sraf mdb_printf(OFFSTR "%s %s\n", 7466515Sraf OFFSET(tdb_hash_lock_stats), 7476515Sraf prt_addr((void *)(addr + OFFSET(tdb_hash_lock_stats)), 1), 7486515Sraf prt_addr((void *)(addr + OFFSET(siguaction)), 0)); 7490Sstevel@tonic-gate 7500Sstevel@tonic-gate HD("&bucket free_list chunks"); 7510Sstevel@tonic-gate for (i = 0; i < NBUCKETS; i++) { 7520Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7536515Sraf OFFSET(bucket[i]), 7546515Sraf prt_addr((void *)(addr + OFFSET(bucket[i])), 1), 7556515Sraf prt_addr(uberdata.bucket[i].free_list, 1), 7566515Sraf uberdata.bucket[i].chunks); 7570Sstevel@tonic-gate } 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate HD("&atexit_root head exit_frame_monitor"); 7600Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7616515Sraf OFFSET(atexit_root), 7626515Sraf prt_addr((void *)(addr + OFFSET(atexit_root.exitfns_lock)), 1), 7636515Sraf prt_addr(uberdata.atexit_root.head, 1), 7646515Sraf prt_addr(uberdata.atexit_root.exit_frame_monitor, 0)); 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate HD("&tsd_metadata tsdm_nkeys tsdm_nused tsdm_destro"); 7670Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %s\n", 7686515Sraf OFFSET(tsd_metadata), 7696515Sraf prt_addr((void *)(addr + OFFSET(tsd_metadata.tsdm_lock)), 1), 7706515Sraf uberdata.tsd_metadata.tsdm_nkeys, 7716515Sraf uberdata.tsd_metadata.tsdm_nused, 7726515Sraf prt_addr((void *)uberdata.tsd_metadata.tsdm_destro, 0)); 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate HD("&tls_metadata tls_modinfo.data tls_modinfo.size"); 7750Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7766515Sraf OFFSET(tls_metadata), 7776515Sraf prt_addr((void *)(addr + OFFSET(tls_metadata.tls_lock)), 1), 7786515Sraf prt_addr(uberdata.tls_metadata.tls_modinfo.tls_data, 1), 7796515Sraf uberdata.tls_metadata.tls_modinfo.tls_size); 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate HD(" static_tls.data static_tls.size"); 7820Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7836515Sraf OFFSET(tls_metadata.static_tls), 7846515Sraf " ", 7856515Sraf prt_addr(uberdata.tls_metadata.static_tls.tls_data, 1), 7866515Sraf uberdata.tls_metadata.static_tls.tls_size); 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate HD("primary_ma bucket_ini uflags.mt uflags.pad uflags.trs uflags.ted"); 7890Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 7906515Sraf OFFSET(primary_map), 7916515Sraf uberdata.primary_map, 7926515Sraf uberdata.bucket_init, 7936515Sraf uberdata.uberflags.uf_x.x_mt, 7946515Sraf uberdata.uberflags.uf_x.x_pad, 7956515Sraf uberdata.uberflags.uf_x.x_tdb_register_sync, 7966515Sraf uberdata.uberflags.uf_x.x_thread_error_detection); 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate HD("queue_head thr_hash_table hash_size hash_mask"); 7990Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d 0x%x\n", 8006515Sraf OFFSET(queue_head), 8016515Sraf prt_addr(uberdata.queue_head, 1), 8026515Sraf prt_addr(uberdata.thr_hash_table, 1), 8036515Sraf uberdata.hash_size, 8046515Sraf uberdata.hash_mask); 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate HD("ulwp_one all_lwps all_zombies"); 8070Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 8086515Sraf OFFSET(ulwp_one), 8096515Sraf prt_addr(uberdata.ulwp_one, 1), 8106515Sraf prt_addr(uberdata.all_lwps, 1), 8116515Sraf prt_addr(uberdata.all_zombies, 0)); 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate HD("nthreads nzombies ndaemons pid sigacthandler"); 8140Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", 8156515Sraf OFFSET(nthreads), 8166515Sraf uberdata.nthreads, 8176515Sraf uberdata.nzombies, 8186515Sraf uberdata.ndaemons, 8196515Sraf (int)uberdata.pid, 8206515Sraf prt_addr((void *)uberdata.sigacthandler, 0)); 8210Sstevel@tonic-gate 8220Sstevel@tonic-gate HD("lwp_stacks lwp_laststack nfreestack stk_cache"); 8230Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 8246515Sraf OFFSET(lwp_stacks), 8256515Sraf prt_addr(uberdata.lwp_stacks, 1), 8266515Sraf prt_addr(uberdata.lwp_laststack, 1), 8276515Sraf uberdata.nfreestack, 8286515Sraf uberdata.thread_stack_cache); 8290Sstevel@tonic-gate 8306515Sraf HD("ulwp_freelist ulwp_lastfree ulwp_replace_free"); 8316515Sraf mdb_printf(OFFSTR "%s %s %s\n", 8326515Sraf OFFSET(ulwp_freelist), 8336515Sraf prt_addr(uberdata.ulwp_freelist, 1), 8346515Sraf prt_addr(uberdata.ulwp_lastfree, 1), 8356515Sraf prt_addr(uberdata.ulwp_replace_free, 0)); 8364574Sraf 8376515Sraf HD("ulwp_replace_last atforklist robustlocks"); 8386515Sraf mdb_printf(OFFSTR "%s %s %s\n", 8396515Sraf OFFSET(ulwp_replace_last), 8406515Sraf prt_addr(uberdata.ulwp_replace_last, 1), 8416515Sraf prt_addr(uberdata.atforklist, 1), 8426515Sraf prt_addr(uberdata.robustlocks, 0)); 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate HD("tdb_bootstrap tdb_sync_addr_hash tdb_'count tdb_'fail"); 8450Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 8466515Sraf OFFSET(tdb_bootstrap), 8476515Sraf prt_addr(uberdata.tdb_bootstrap, 1), 8486515Sraf prt_addr(uberdata.tdb.tdb_sync_addr_hash, 1), 8496515Sraf uberdata.tdb.tdb_register_count, 8506515Sraf uberdata.tdb.tdb_hash_alloc_failed); 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate HD("tdb_sync_addr_free tdb_sync_addr_last tdb_sync_alloc"); 8530Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 8546515Sraf OFFSET(tdb.tdb_sync_addr_free), 8556515Sraf prt_addr(uberdata.tdb.tdb_sync_addr_free, 1), 8566515Sraf prt_addr(uberdata.tdb.tdb_sync_addr_last, 1), 8576515Sraf uberdata.tdb.tdb_sync_alloc); 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate HD("tdb_ev_global_mask tdb_events"); 8600Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %s\n", 8616515Sraf OFFSET(tdb.tdb_ev_global_mask), 8626515Sraf uberdata.tdb.tdb_ev_global_mask.event_bits[0], 8636515Sraf uberdata.tdb.tdb_ev_global_mask.event_bits[1], 8646515Sraf prt_addr((void *)uberdata.tdb.tdb_events, 0)); 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate return (DCMD_OK); 8670Sstevel@tonic-gate } 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate static int 8700Sstevel@tonic-gate ulwp_walk_init(mdb_walk_state_t *wsp) 8710Sstevel@tonic-gate { 8720Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 8730Sstevel@tonic-gate uintptr_t uber_addr; 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate if (addr == NULL && 8760Sstevel@tonic-gate ((uber_addr = uberdata_addr()) == NULL || 8770Sstevel@tonic-gate mdb_vread(&addr, sizeof (addr), 8780Sstevel@tonic-gate uber_addr + OFFSETOF(uberdata_t, all_lwps)) 8790Sstevel@tonic-gate != sizeof (addr))) { 8800Sstevel@tonic-gate mdb_warn("cannot find 'uberdata.all_lwps'"); 8810Sstevel@tonic-gate return (WALK_ERR); 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate if (addr == NULL) 8840Sstevel@tonic-gate return (WALK_DONE); 8850Sstevel@tonic-gate wsp->walk_addr = addr; 8860Sstevel@tonic-gate wsp->walk_data = (void *)addr; 8870Sstevel@tonic-gate return (WALK_NEXT); 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate static int 8910Sstevel@tonic-gate ulwp_walk_step(mdb_walk_state_t *wsp) 8920Sstevel@tonic-gate { 8930Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 8940Sstevel@tonic-gate ulwp_t ulwp; 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate if (addr == NULL) 8970Sstevel@tonic-gate return (WALK_DONE); 8980Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && 8990Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)), 9000Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { 9010Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr); 9020Sstevel@tonic-gate return (WALK_ERR); 9030Sstevel@tonic-gate } 9040Sstevel@tonic-gate /* 9050Sstevel@tonic-gate * If we have looped around to the beginning 9060Sstevel@tonic-gate * of the circular linked list, we are done. 9070Sstevel@tonic-gate */ 9080Sstevel@tonic-gate if ((wsp->walk_addr = (uintptr_t)ulwp.ul_forw) 9090Sstevel@tonic-gate == (uintptr_t)wsp->walk_data) 9100Sstevel@tonic-gate wsp->walk_addr = NULL; 9110Sstevel@tonic-gate return (wsp->walk_callback(addr, &ulwp, wsp->walk_cbdata)); 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate /* 9150Sstevel@tonic-gate * ======================================================= 9160Sstevel@tonic-gate * End of thread (previously libthread) interfaces. 9170Sstevel@tonic-gate * ==================== threads ========================== 9180Sstevel@tonic-gate */ 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 9210Sstevel@tonic-gate { "jmp_buf", ":", "print jmp_buf contents", d_jmp_buf, NULL }, 9220Sstevel@tonic-gate { "sigjmp_buf", ":", "print sigjmp_buf contents", d_sigjmp_buf, NULL }, 9230Sstevel@tonic-gate { "siginfo", ":", "print siginfo_t structure", d_siginfo, NULL }, 9240Sstevel@tonic-gate { "ucontext", ":", "print ucontext_t structure", d_ucontext, NULL }, 9250Sstevel@tonic-gate { "ulwp", ":", "print ulwp_t structure", d_ulwp, NULL }, 9260Sstevel@tonic-gate { "uberdata", ":", "print uberdata_t structure", d_uberdata, NULL }, 9270Sstevel@tonic-gate { NULL } 9280Sstevel@tonic-gate }; 9290Sstevel@tonic-gate 9300Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 9310Sstevel@tonic-gate { "ucontext", "walk ucontext_t uc_link list", 9320Sstevel@tonic-gate NULL, uc_walk_step, NULL, NULL }, 9330Sstevel@tonic-gate { "oldcontext", "walk per-lwp oldcontext pointers", 9340Sstevel@tonic-gate oldc_walk_init, oldc_walk_step, oldc_walk_fini, NULL }, 9350Sstevel@tonic-gate { "ulwps", "walk list of ulwp_t pointers", 9360Sstevel@tonic-gate ulwp_walk_init, ulwp_walk_step, NULL, NULL }, 9370Sstevel@tonic-gate { NULL } 9380Sstevel@tonic-gate }; 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 9410Sstevel@tonic-gate 9420Sstevel@tonic-gate const mdb_modinfo_t * 9430Sstevel@tonic-gate _mdb_init(void) 9440Sstevel@tonic-gate { 9450Sstevel@tonic-gate return (&modinfo); 9460Sstevel@tonic-gate } 947