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 /* 23*12061SRoger.Faulkner@Oracle.COM * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <sys/mdb_modapi.h> 2710610SJonathan.Adams@Sun.COM #include <mdb/mdb_whatis.h> 280Sstevel@tonic-gate #include <procfs.h> 290Sstevel@tonic-gate #include <ucontext.h> 300Sstevel@tonic-gate #include <siginfo.h> 310Sstevel@tonic-gate #include <signal.h> 320Sstevel@tonic-gate #include <setjmp.h> 330Sstevel@tonic-gate #include <string.h> 340Sstevel@tonic-gate #include <thr_uberdata.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate static const char * 370Sstevel@tonic-gate stack_flags(const stack_t *sp) 380Sstevel@tonic-gate { 390Sstevel@tonic-gate static char buf[32]; 400Sstevel@tonic-gate 410Sstevel@tonic-gate if (sp->ss_flags == 0) 420Sstevel@tonic-gate (void) strcpy(buf, " 0"); 430Sstevel@tonic-gate else if (sp->ss_flags & ~(SS_ONSTACK | SS_DISABLE)) 440Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buf), " 0x%x", sp->ss_flags); 450Sstevel@tonic-gate else { 460Sstevel@tonic-gate buf[0] = '\0'; 470Sstevel@tonic-gate if (sp->ss_flags & SS_ONSTACK) 480Sstevel@tonic-gate (void) strcat(buf, "|ONSTACK"); 490Sstevel@tonic-gate if (sp->ss_flags & SS_DISABLE) 500Sstevel@tonic-gate (void) strcat(buf, "|DISABLE"); 510Sstevel@tonic-gate } 520Sstevel@tonic-gate 530Sstevel@tonic-gate return (buf + 1); 540Sstevel@tonic-gate } 550Sstevel@tonic-gate 560Sstevel@tonic-gate /*ARGSUSED*/ 570Sstevel@tonic-gate static int 580Sstevel@tonic-gate d_jmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 590Sstevel@tonic-gate { 600Sstevel@tonic-gate jmp_buf jb; 610Sstevel@tonic-gate const ulong_t *b = (const ulong_t *)jb; 620Sstevel@tonic-gate 630Sstevel@tonic-gate if (argc != 0) 640Sstevel@tonic-gate return (DCMD_USAGE); 650Sstevel@tonic-gate 660Sstevel@tonic-gate if (mdb_vread(&jb, sizeof (jb), addr) != sizeof (jb)) { 670Sstevel@tonic-gate mdb_warn("failed to read jmp_buf at %p", addr); 680Sstevel@tonic-gate return (DCMD_ERR); 690Sstevel@tonic-gate } 700Sstevel@tonic-gate 710Sstevel@tonic-gate #if defined(__sparc) 720Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx\n", b[1]); 730Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", b[2], b[2]); 740Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx\n", b[3]); 750Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", b[4], b[4]); 760Sstevel@tonic-gate #elif defined(__amd64) 770Sstevel@tonic-gate mdb_printf(" %%rbx = 0x%lx\n", b[0]); 780Sstevel@tonic-gate mdb_printf(" %%r12 = 0x%lx\n", b[1]); 790Sstevel@tonic-gate mdb_printf(" %%r13 = 0x%lx\n", b[2]); 800Sstevel@tonic-gate mdb_printf(" %%r14 = 0x%lx\n", b[3]); 810Sstevel@tonic-gate mdb_printf(" %%r15 = 0x%lx\n", b[4]); 820Sstevel@tonic-gate mdb_printf(" %%rbp = 0x%lx\n", b[5]); 830Sstevel@tonic-gate mdb_printf(" %%rsp = 0x%lx\n", b[6]); 840Sstevel@tonic-gate mdb_printf(" %%rip = 0x%lx %lA\n", b[7], b[7]); 850Sstevel@tonic-gate #elif defined(__i386) 860Sstevel@tonic-gate mdb_printf(" %%ebx = 0x%lx\n", b[0]); 870Sstevel@tonic-gate mdb_printf(" %%esi = 0x%lx\n", b[1]); 880Sstevel@tonic-gate mdb_printf(" %%edi = 0x%lx\n", b[2]); 890Sstevel@tonic-gate mdb_printf(" %%ebp = 0x%lx\n", b[3]); 900Sstevel@tonic-gate mdb_printf(" %%esp = 0x%lx\n", b[4]); 910Sstevel@tonic-gate mdb_printf(" %%eip = 0x%lx %lA\n", b[5], b[5]); 920Sstevel@tonic-gate #endif 930Sstevel@tonic-gate return (DCMD_OK); 940Sstevel@tonic-gate } 950Sstevel@tonic-gate 960Sstevel@tonic-gate /*ARGSUSED*/ 970Sstevel@tonic-gate static int 980Sstevel@tonic-gate d_ucontext(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 990Sstevel@tonic-gate { 1000Sstevel@tonic-gate ucontext_t uc; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate if (argc != 0) 1030Sstevel@tonic-gate return (DCMD_USAGE); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 1060Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 1070Sstevel@tonic-gate return (DCMD_ERR); 1080Sstevel@tonic-gate } 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate mdb_printf(" flags = 0x%lx\n", uc.uc_flags); 1110Sstevel@tonic-gate mdb_printf(" link = 0x%p\n", uc.uc_link); 1120Sstevel@tonic-gate mdb_printf(" sigmask = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1130Sstevel@tonic-gate uc.uc_sigmask.__sigbits[0], uc.uc_sigmask.__sigbits[1], 1140Sstevel@tonic-gate uc.uc_sigmask.__sigbits[2], uc.uc_sigmask.__sigbits[3]); 1150Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n", 1160Sstevel@tonic-gate uc.uc_stack.ss_sp, uc.uc_stack.ss_size, stack_flags(&uc.uc_stack)); 1170Sstevel@tonic-gate mdb_printf(" mcontext = 0x%p\n", 1180Sstevel@tonic-gate addr + OFFSETOF(ucontext_t, uc_mcontext)); 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate return (DCMD_OK); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /*ARGSUSED*/ 1240Sstevel@tonic-gate static int 1250Sstevel@tonic-gate d_sigjmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1260Sstevel@tonic-gate { 1270Sstevel@tonic-gate #if defined(__sparc) 1280Sstevel@tonic-gate struct { 1290Sstevel@tonic-gate int sjs_flags; 1300Sstevel@tonic-gate greg_t sjs_sp; 1310Sstevel@tonic-gate greg_t sjs_pc; 1320Sstevel@tonic-gate greg_t sjs_fp; 1330Sstevel@tonic-gate greg_t sjs_i7; 1340Sstevel@tonic-gate ucontext_t *sjs_uclink; 1350Sstevel@tonic-gate ulong_t sjs_pad[_JBLEN - 6]; 1360Sstevel@tonic-gate sigset_t sjs_sigmask; 1370Sstevel@tonic-gate #if defined(_LP64) 138*12061SRoger.Faulkner@Oracle.COM greg_t sjs_asi; 139*12061SRoger.Faulkner@Oracle.COM greg_t sjs_fprs; 1400Sstevel@tonic-gate #endif 1410Sstevel@tonic-gate stack_t sjs_stack; 1420Sstevel@tonic-gate } s; 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate if (argc != 0) 1450Sstevel@tonic-gate return (DCMD_USAGE); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate if (mdb_vread(&s, sizeof (s), addr) != sizeof (s)) { 1480Sstevel@tonic-gate mdb_warn("failed to read sigjmp_buf at %p", addr); 1490Sstevel@tonic-gate return (DCMD_ERR); 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate mdb_printf(" flags = 0x%x\n", s.sjs_flags); 1530Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx %lA\n", s.sjs_sp, s.sjs_sp); 1540Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", s.sjs_pc, s.sjs_pc); 1550Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx %lA\n", s.sjs_fp, s.sjs_fp); 1560Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", s.sjs_i7, s.sjs_i7); 1570Sstevel@tonic-gate mdb_printf(" uclink = %p\n", s.sjs_uclink); 1580Sstevel@tonic-gate mdb_printf(" sigset = 0x%08x 0x%08x 0x%08x 0x%08x\n", 1590Sstevel@tonic-gate s.sjs_sigmask.__sigbits[0], s.sjs_sigmask.__sigbits[1], 1600Sstevel@tonic-gate s.sjs_sigmask.__sigbits[2], s.sjs_sigmask.__sigbits[3]); 161*12061SRoger.Faulkner@Oracle.COM #if defined(_LP64) 162*12061SRoger.Faulkner@Oracle.COM mdb_printf(" %%asi = 0x%lx\n", s.sjs_asi); 163*12061SRoger.Faulkner@Oracle.COM mdb_printf(" %%fprs = 0x%lx\n", s.sjs_fprs); 164*12061SRoger.Faulkner@Oracle.COM #endif 1650Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n", 1660Sstevel@tonic-gate s.sjs_stack.ss_sp, s.sjs_stack.ss_size, stack_flags(&s.sjs_stack)); 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate return (DCMD_OK); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64) 1710Sstevel@tonic-gate return (d_ucontext(addr, flags, argc, argv)); 1720Sstevel@tonic-gate #endif 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /*ARGSUSED*/ 1760Sstevel@tonic-gate static int 1770Sstevel@tonic-gate d_siginfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 1780Sstevel@tonic-gate { 1790Sstevel@tonic-gate static const char *const msname[] = { 1800Sstevel@tonic-gate "USER", "SYSTEM", "TRAP", "TFAULT", "DFAULT", "KFAULT", 1810Sstevel@tonic-gate "USER_LOCK", "SLEEP", "WAIT_CPU", "STOPPED" 1820Sstevel@tonic-gate }; 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate char signame[SIG2STR_MAX]; 1850Sstevel@tonic-gate siginfo_t si; 1860Sstevel@tonic-gate int i; 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate if (argc != 0) 1890Sstevel@tonic-gate return (DCMD_USAGE); 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate if (mdb_vread(&si, sizeof (si), addr) != sizeof (si)) { 1920Sstevel@tonic-gate mdb_warn("failed to read siginfo at %p", addr); 1930Sstevel@tonic-gate return (DCMD_ERR); 1940Sstevel@tonic-gate } 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate if (sig2str(si.si_signo, signame) == -1) 1970Sstevel@tonic-gate (void) strcpy(signame, "unknown"); 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate mdb_printf(" signal %5d (%s)\n", si.si_signo, signame); 2000Sstevel@tonic-gate mdb_printf(" code %5d (", si.si_code); 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate switch (si.si_code) { 2030Sstevel@tonic-gate case SI_NOINFO: 2040Sstevel@tonic-gate mdb_printf("no info"); 2050Sstevel@tonic-gate break; 2060Sstevel@tonic-gate case SI_DTRACE: 2070Sstevel@tonic-gate mdb_printf("from DTrace raise() action"); 2080Sstevel@tonic-gate break; 2090Sstevel@tonic-gate case SI_RCTL: 2100Sstevel@tonic-gate mdb_printf("from rctl action"); 2110Sstevel@tonic-gate break; 2120Sstevel@tonic-gate case SI_USER: 2130Sstevel@tonic-gate mdb_printf("user generated via kill"); 2140Sstevel@tonic-gate break; 2150Sstevel@tonic-gate case SI_LWP: 2160Sstevel@tonic-gate mdb_printf("user generated via lwp_kill"); 2170Sstevel@tonic-gate break; 2180Sstevel@tonic-gate case SI_QUEUE: 2190Sstevel@tonic-gate mdb_printf("user generated via sigqueue"); 2200Sstevel@tonic-gate break; 2210Sstevel@tonic-gate case SI_TIMER: 2220Sstevel@tonic-gate mdb_printf("from timer expiration"); 2230Sstevel@tonic-gate break; 2240Sstevel@tonic-gate case SI_ASYNCIO: 2250Sstevel@tonic-gate mdb_printf("from async i/o completion"); 2260Sstevel@tonic-gate break; 2270Sstevel@tonic-gate case SI_MESGQ: 2280Sstevel@tonic-gate mdb_printf("from message arrival"); 2290Sstevel@tonic-gate break; 2300Sstevel@tonic-gate default: 2310Sstevel@tonic-gate if (SI_FROMUSER(&si)) 2320Sstevel@tonic-gate mdb_printf("from user process"); 2330Sstevel@tonic-gate else 2340Sstevel@tonic-gate mdb_printf("from kernel"); 2350Sstevel@tonic-gate } 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate mdb_printf(")\n errno %5d (%s)\n", 2380Sstevel@tonic-gate si.si_errno, strerror(si.si_errno)); 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate if (si.si_code == SI_USER || si.si_code == SI_QUEUE) { 2410Sstevel@tonic-gate mdb_printf(" signal sent from PID %d (uid %d)\n", 2420Sstevel@tonic-gate si.si_pid, si.si_uid); 2430Sstevel@tonic-gate } 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate if (si.si_code == SI_QUEUE) { 2460Sstevel@tonic-gate mdb_printf(" signal value = 0t%d / %p\n", 2470Sstevel@tonic-gate si.si_value.sival_int, si.si_value.sival_ptr); 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate switch (si.si_signo) { 2510Sstevel@tonic-gate case SIGCLD: 2520Sstevel@tonic-gate mdb_printf(" signal sent from child PID %d (uid %d)\n", 2530Sstevel@tonic-gate si.si_pid, si.si_uid); 2540Sstevel@tonic-gate mdb_printf(" usr time = 0t%ld ticks, sys time = 0t%ld ticks\n", 2550Sstevel@tonic-gate si.si_utime, si.si_stime); 2560Sstevel@tonic-gate mdb_printf(" wait status = 0x%x\n", si.si_status); 2570Sstevel@tonic-gate break; 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate case SIGSEGV: 2600Sstevel@tonic-gate case SIGBUS: 2610Sstevel@tonic-gate case SIGILL: 2620Sstevel@tonic-gate case SIGTRAP: 2630Sstevel@tonic-gate case SIGFPE: 2640Sstevel@tonic-gate mdb_printf(" fault address = 0x%p\n trapno = %d\n", 2650Sstevel@tonic-gate si.si_addr, si.si_trapno); 2660Sstevel@tonic-gate mdb_printf(" instruction address = 0x%p %lA\n", 2670Sstevel@tonic-gate si.si_pc, si.si_pc); 2680Sstevel@tonic-gate break; 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate case SIGPOLL: 2710Sstevel@tonic-gate case SIGXFSZ: 2720Sstevel@tonic-gate mdb_printf(" fd = %d band = 0x%lx\n", 2730Sstevel@tonic-gate si.si_fd, si.si_band); 2740Sstevel@tonic-gate break; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate case SIGPROF: 2770Sstevel@tonic-gate mdb_printf(" last fault address = 0x%p fault type = %d\n", 2780Sstevel@tonic-gate si.si_faddr, si.si_fault); 2790Sstevel@tonic-gate mdb_printf(" timestamp = 0t%ld sec 0t%ld nsec\n", 2800Sstevel@tonic-gate si.si_tstamp.tv_sec, si.si_tstamp.tv_nsec); 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate if (si.__data.__prof.__syscall != 0) { 2830Sstevel@tonic-gate mdb_printf(" system call %d (", si.si_syscall); 2840Sstevel@tonic-gate if (si.si_nsysarg > 0) { 2850Sstevel@tonic-gate mdb_printf("%lx", si.si_sysarg[0]); 2860Sstevel@tonic-gate for (i = 1; i < si.si_nsysarg; i++) 2870Sstevel@tonic-gate mdb_printf(", %lx", si.si_sysarg[i]); 2880Sstevel@tonic-gate } 2890Sstevel@tonic-gate mdb_printf(" )\n"); 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate for (i = 0; i < sizeof (msname) / sizeof (msname[0]); i++) { 2930Sstevel@tonic-gate mdb_printf(" mstate[\"%s\"] = %d\n", 2940Sstevel@tonic-gate msname[i], si.si_mstate[i]); 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate break; 2970Sstevel@tonic-gate } 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate return (DCMD_OK); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate static int 3030Sstevel@tonic-gate uc_walk_step(mdb_walk_state_t *wsp) 3040Sstevel@tonic-gate { 3050Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 3060Sstevel@tonic-gate ucontext_t uc; 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate if (addr == NULL) 3090Sstevel@tonic-gate return (WALK_DONE); 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 3120Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 3130Sstevel@tonic-gate return (WALK_ERR); 3140Sstevel@tonic-gate } 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)uc.uc_link; 3170Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata)); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate static int 3210Sstevel@tonic-gate oldc_walk_init(mdb_walk_state_t *wsp) 3220Sstevel@tonic-gate { 3230Sstevel@tonic-gate ssize_t nbytes = mdb_get_xdata("lwpstatus", NULL, 0); 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate if (nbytes <= 0) { 3260Sstevel@tonic-gate mdb_warn("lwpstatus information not available"); 3270Sstevel@tonic-gate return (WALK_ERR); 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate if (wsp->walk_addr != NULL) { 3310Sstevel@tonic-gate mdb_warn("walker only supports global walk\n"); 3320Sstevel@tonic-gate return (WALK_ERR); 3330Sstevel@tonic-gate } 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate wsp->walk_addr = nbytes; /* Use walk_addr to track size */ 3360Sstevel@tonic-gate wsp->walk_data = mdb_alloc(nbytes, UM_SLEEP); 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate if (mdb_get_xdata("lwpstatus", wsp->walk_data, nbytes) != nbytes) { 3390Sstevel@tonic-gate mdb_warn("failed to read lwpstatus information"); 3400Sstevel@tonic-gate mdb_free(wsp->walk_data, nbytes); 3410Sstevel@tonic-gate return (WALK_ERR); 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate wsp->walk_arg = wsp->walk_data; /* Use walk_arg to track pointer */ 3450Sstevel@tonic-gate return (WALK_NEXT); 3460Sstevel@tonic-gate } 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate static int 3490Sstevel@tonic-gate oldc_walk_step(mdb_walk_state_t *wsp) 3500Sstevel@tonic-gate { 3510Sstevel@tonic-gate const lwpstatus_t *lsp, *end; 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate end = (const lwpstatus_t *)((uintptr_t)wsp->walk_data + wsp->walk_addr); 3540Sstevel@tonic-gate lsp = wsp->walk_arg; 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate wsp->walk_arg = (void *)(lsp + 1); 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate if (lsp < end) { 3590Sstevel@tonic-gate uintptr_t addr = lsp->pr_oldcontext; 3600Sstevel@tonic-gate ucontext_t uc; 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate if (addr == NULL) 3630Sstevel@tonic-gate return (WALK_NEXT); 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 3660Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 3670Sstevel@tonic-gate return (WALK_NEXT); 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata)); 3710Sstevel@tonic-gate } 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate return (WALK_DONE); 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate static void 3770Sstevel@tonic-gate oldc_walk_fini(mdb_walk_state_t *wsp) 3780Sstevel@tonic-gate { 3790Sstevel@tonic-gate mdb_free(wsp->walk_data, wsp->walk_addr); /* walk_addr has size */ 3800Sstevel@tonic-gate } 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate /* 3830Sstevel@tonic-gate * ==================== threads ========================== 3840Sstevel@tonic-gate * These are the interfaces that used to require libthread. 3850Sstevel@tonic-gate * Now, libthread has been folded into libc. 3860Sstevel@tonic-gate * ======================================================= 3870Sstevel@tonic-gate */ 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate /* 3900Sstevel@tonic-gate * prt_addr() is called up to three times to generate arguments for 3910Sstevel@tonic-gate * one call to mdb_printf(). We must return at least three different 3920Sstevel@tonic-gate * pointers to static storage for consecutive calls to prt_addr(). 3930Sstevel@tonic-gate */ 3940Sstevel@tonic-gate static const char * 3950Sstevel@tonic-gate prt_addr(void *addr, int pad) 3960Sstevel@tonic-gate { 3970Sstevel@tonic-gate static char buffer[4][24]; 3980Sstevel@tonic-gate static int ix = 0; 3990Sstevel@tonic-gate char *buf; 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate if (ix == 4) /* use buffers in sequence: 0, 1, 2, 3 */ 4020Sstevel@tonic-gate ix = 0; 4030Sstevel@tonic-gate buf = buffer[ix++]; 4040Sstevel@tonic-gate if (addr == NULL) 4050Sstevel@tonic-gate return (pad? "<NULL> " : "<NULL>"); 4060Sstevel@tonic-gate else { 4070Sstevel@tonic-gate #ifdef _LP64 4080Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%016lx", addr); 4090Sstevel@tonic-gate if (pad) 4100Sstevel@tonic-gate (void) strcpy(buf + 18, " "); 4110Sstevel@tonic-gate #else 4120Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%08lx", addr); 4130Sstevel@tonic-gate if (pad) 4140Sstevel@tonic-gate (void) strcpy(buf + 10, " "); 4150Sstevel@tonic-gate #endif /* _LP64 */ 4160Sstevel@tonic-gate return (buf); 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate } 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate #define HD(str) mdb_printf(" " str "\n") 4210Sstevel@tonic-gate #define OFFSTR "+0x%-7lx " 4220Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(ulwp_t, member)) 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate /*ARGSUSED*/ 4250Sstevel@tonic-gate static int 4260Sstevel@tonic-gate d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 4270Sstevel@tonic-gate { 4280Sstevel@tonic-gate ulwp_t ulwp; 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate if (argc != 0 || !(flags & DCMD_ADDRSPEC)) 4310Sstevel@tonic-gate return (DCMD_USAGE); 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && 4340Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)), 4350Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { 4360Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr); 4370Sstevel@tonic-gate return (DCMD_ERR); 4380Sstevel@tonic-gate } 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate mdb_printf("%#a\n", addr); 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate HD("self uberdata"); 4430Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s\n", 4446515Sraf OFFSET(ul_self), 4456515Sraf prt_addr(ulwp.ul_self, 1), 4466515Sraf prt_addr(ulwp.ul_uberdata, 0)); 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate HD("tlsent ntlsent"); 4490Sstevel@tonic-gate mdb_printf(OFFSTR "%s %ld\n", 4506515Sraf OFFSET(ul_tlsent), 4516515Sraf prt_addr(ulwp.ul_tlsent, 1), 4526515Sraf ulwp.ul_ntlsent); 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate HD("forw back next"); 4550Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 4566515Sraf OFFSET(ul_forw), 4576515Sraf prt_addr(ulwp.ul_forw, 1), 4586515Sraf prt_addr(ulwp.ul_back, 1), 4596515Sraf prt_addr(ulwp.ul_next, 0)); 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate HD("hash rval stk"); 4620Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 4636515Sraf OFFSET(ul_hash), 4646515Sraf prt_addr(ulwp.ul_hash, 1), 4656515Sraf prt_addr(ulwp.ul_rval, 1), 4666515Sraf prt_addr(ulwp.ul_stk, 0)); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate HD("mapsiz guardsize stktop stksiz"); 4690Sstevel@tonic-gate mdb_printf(OFFSTR "%-10ld %-10ld %s %ld\n", 4706515Sraf OFFSET(ul_mapsiz), 4716515Sraf ulwp.ul_mapsiz, 4726515Sraf ulwp.ul_guardsize, 4736515Sraf prt_addr((void *)ulwp.ul_stktop, 1), 4746515Sraf ulwp.ul_stksiz); 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate HD("ustack.ss_sp ustack.ss_size ustack.ss_flags"); 4770Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-21ld %s\n", 4786515Sraf OFFSET(ul_ustack.ss_sp), 4796515Sraf prt_addr(ulwp.ul_ustack.ss_sp, 1), 4806515Sraf ulwp.ul_ustack.ss_size, 4816515Sraf stack_flags(&ulwp.ul_ustack)); 4820Sstevel@tonic-gate 4836247Sraf HD("ix lwpid pri epri policy cid"); 4840Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 4856515Sraf OFFSET(ul_ix), 4866515Sraf ulwp.ul_ix, 4876515Sraf ulwp.ul_lwpid, 4886515Sraf ulwp.ul_pri, 4896515Sraf ulwp.ul_epri, 4906515Sraf ulwp.ul_policy, 4916515Sraf ulwp.ul_cid); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate HD("cursig pleasestop stop signalled dead unwind"); 4940Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d ", 4956515Sraf OFFSET(ul_cursig), 4966515Sraf ulwp.ul_cursig); 4970Sstevel@tonic-gate mdb_printf(ulwp.ul_pleasestop? "0x%-8x " : "%-10d ", 4986515Sraf ulwp.ul_pleasestop); 4990Sstevel@tonic-gate mdb_printf(ulwp.ul_stop? "0x%-8x " : "%-10d ", 5006515Sraf ulwp.ul_stop); 5010Sstevel@tonic-gate mdb_printf("%-10d %-10d %d\n", 5026515Sraf ulwp.ul_signalled, 5036515Sraf ulwp.ul_dead, 5046515Sraf ulwp.ul_unwind); 5050Sstevel@tonic-gate 5061885Sraf HD("detached writer stopping can'prolog preempt savpreempt"); 5070Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5086515Sraf OFFSET(ul_detached), 5096515Sraf ulwp.ul_detached, 5106515Sraf ulwp.ul_writer, 5116515Sraf ulwp.ul_stopping, 5126515Sraf ulwp.ul_cancel_prologue, 5136515Sraf ulwp.ul_preempt, 5146515Sraf ulwp.ul_savpreempt); 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate HD("sigsuspend main fork primarymap m'spinners d'noreserv"); 5170Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5186515Sraf OFFSET(ul_sigsuspend), 5196515Sraf ulwp.ul_sigsuspend, 5206515Sraf ulwp.ul_main, 5216515Sraf ulwp.ul_fork, 5226515Sraf ulwp.ul_primarymap, 5236515Sraf ulwp.ul_max_spinners, 5246515Sraf ulwp.ul_door_noreserve); 5250Sstevel@tonic-gate 5266247Sraf HD("queue_fifo c'w'defer e'detect' async_safe rt rtqueued"); 5270Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5286515Sraf OFFSET(ul_queue_fifo), 5296515Sraf ulwp.ul_queue_fifo, 5306515Sraf ulwp.ul_cond_wait_defer, 5316515Sraf ulwp.ul_error_detection, 5326515Sraf ulwp.ul_async_safe, 5336515Sraf ulwp.ul_rt, 5346515Sraf ulwp.ul_rtqueued); 5350Sstevel@tonic-gate 5367255Sraf HD("misaligned adapt'spin queue_spin critical sigdefer vfork"); 5377255Sraf mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5387255Sraf OFFSET(ul_misaligned), 5397255Sraf ulwp.ul_misaligned, 5406515Sraf ulwp.ul_adaptive_spin, 5416515Sraf ulwp.ul_queue_spin, 5426515Sraf ulwp.ul_critical, 5436515Sraf ulwp.ul_sigdefer, 5446515Sraf ulwp.ul_vfork); 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate HD("cancelable c'pending c'disabled c'async save_async mutator"); 5470Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 5486515Sraf OFFSET(ul_cancelable), 5496515Sraf ulwp.ul_cancelable, 5506515Sraf ulwp.ul_cancel_pending, 5516515Sraf ulwp.ul_cancel_disabled, 5526515Sraf ulwp.ul_cancel_async, 5536515Sraf ulwp.ul_save_async, 5546515Sraf ulwp.ul_mutator); 5550Sstevel@tonic-gate 5560Sstevel@tonic-gate HD("created replace nocancel errno errnop"); 5570Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", 5586515Sraf OFFSET(ul_created), 5596515Sraf ulwp.ul_created, 5606515Sraf ulwp.ul_replace, 5616515Sraf ulwp.ul_nocancel, 5626515Sraf ulwp.ul_errno, 5636515Sraf prt_addr(ulwp.ul_errnop, 0)); 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate HD("clnup_hdr schedctl_called schedctl"); 5660Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 5676515Sraf OFFSET(ul_clnup_hdr), 5686515Sraf prt_addr(ulwp.ul_clnup_hdr, 1), 5696515Sraf prt_addr(ulwp.ul_schedctl_called, 1), 5706515Sraf prt_addr((void *)ulwp.ul_schedctl, 0)); 5710Sstevel@tonic-gate 5725891Sraf HD("bindflags libc_locks stsd &ftsd"); 5730Sstevel@tonic-gate mdb_printf(OFFSTR, 5746515Sraf OFFSET(ul_bindflags)); 5750Sstevel@tonic-gate mdb_printf(ulwp.ul_bindflags? "0x%-8x " : "%-10d ", 5766515Sraf ulwp.ul_bindflags); 5775891Sraf mdb_printf("%-10d ", ulwp.ul_libc_locks); 5780Sstevel@tonic-gate mdb_printf("%s %s\n", 5796515Sraf prt_addr(ulwp.ul_stsd, 1), 5806515Sraf prt_addr((void *)(addr + OFFSET(ul_ftsd[0])), 0)); 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate HD("eventmask[0..1] eventnum eventdata"); 5830Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %-21d %s\n", 5846515Sraf OFFSET(ul_td_evbuf.eventmask.event_bits[0]), 5856515Sraf ulwp.ul_td_evbuf.eventmask.event_bits[0], 5866515Sraf ulwp.ul_td_evbuf.eventmask.event_bits[1], 5876515Sraf ulwp.ul_td_evbuf.eventnum, 5886515Sraf prt_addr(ulwp.ul_td_evbuf.eventdata, 0)); 5890Sstevel@tonic-gate 59010637SRoger.Faulkner@Sun.COM HD("td'enable sync'reg qtype cv_wake rtld usropts"); 59110637SRoger.Faulkner@Sun.COM mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d ", 5926515Sraf OFFSET(ul_td_events_enable), 5936515Sraf ulwp.ul_td_events_enable, 5946515Sraf ulwp.ul_sync_obj_reg, 5956515Sraf ulwp.ul_qtype, 59610637SRoger.Faulkner@Sun.COM ulwp.ul_cv_wake, 59710637SRoger.Faulkner@Sun.COM ulwp.ul_rtld); 5980Sstevel@tonic-gate mdb_printf(ulwp.ul_usropts? "0x%x\n" : "%d\n", 5996515Sraf ulwp.ul_usropts); 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate HD("startpc startarg wchan"); 6020Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 6036515Sraf OFFSET(ul_startpc), 6046515Sraf prt_addr((void *)ulwp.ul_startpc, 1), 6056515Sraf prt_addr(ulwp.ul_startarg, 1), 6066515Sraf prt_addr(ulwp.ul_wchan, 0)); 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate HD("link sleepq cvmutex"); 6090Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 6106515Sraf OFFSET(ul_link), 6116515Sraf prt_addr(ulwp.ul_link, 1), 6126515Sraf prt_addr(ulwp.ul_sleepq, 1), 6136515Sraf prt_addr(ulwp.ul_cvmutex, 0)); 6140Sstevel@tonic-gate 6156247Sraf HD("mxchain save_state"); 6166247Sraf mdb_printf(OFFSTR "%s %d\n", 6176515Sraf OFFSET(ul_mxchain), 6186515Sraf prt_addr(ulwp.ul_mxchain, 1), 6196515Sraf ulwp.ul_save_state); 6200Sstevel@tonic-gate 6214574Sraf HD("rdlockcnt rd_rwlock rd_count"); 6224574Sraf mdb_printf(OFFSTR "%-21d %s %d\n", 6236515Sraf OFFSET(ul_rdlockcnt), 6246515Sraf ulwp.ul_rdlockcnt, 6256515Sraf prt_addr(ulwp.ul_readlock.single.rd_rwlock, 1), 6266515Sraf ulwp.ul_readlock.single.rd_count); 6274574Sraf 6284574Sraf HD("heldlockcnt heldlocks tpdp"); 6294574Sraf mdb_printf(OFFSTR "%-21d %s %s\n", 6306515Sraf OFFSET(ul_heldlockcnt), 6316515Sraf ulwp.ul_heldlockcnt, 6326515Sraf prt_addr(ulwp.ul_heldlocks.single, 1), 6336515Sraf prt_addr(ulwp.ul_tpdp, 0)); 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate HD("siglink s'l'spin s'l'spin2 s'l'sleep s'l'wakeup"); 6366247Sraf mdb_printf(OFFSTR "%s %-10d %-10d %-10d %d\n", 6376515Sraf OFFSET(ul_siglink), 6386515Sraf prt_addr(ulwp.ul_siglink, 1), 6396515Sraf ulwp.ul_spin_lock_spin, 6406515Sraf ulwp.ul_spin_lock_spin2, 6416515Sraf ulwp.ul_spin_lock_sleep, 6426515Sraf ulwp.ul_spin_lock_wakeup); 6430Sstevel@tonic-gate 6446247Sraf HD("&queue_root rtclassid pilocks"); 6456247Sraf mdb_printf(OFFSTR "%s %-10d %d\n", 6466515Sraf OFFSET(ul_queue_root), 6476515Sraf prt_addr((void *)(addr + OFFSET(ul_queue_root)), 1), 6486515Sraf ulwp.ul_rtclassid, 6496515Sraf ulwp.ul_pilocks); 6506247Sraf 6510Sstevel@tonic-gate /* 6520Sstevel@tonic-gate * The remainder of the ulwp_t structure 6530Sstevel@tonic-gate * is invalid if this is a replacement. 6540Sstevel@tonic-gate */ 6550Sstevel@tonic-gate if (ulwp.ul_replace) 6560Sstevel@tonic-gate return (DCMD_OK); 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate HD("sigmask[0..3]"); 6590Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 6606515Sraf OFFSET(ul_sigmask.__sigbits[0]), 6616515Sraf ulwp.ul_sigmask.__sigbits[0], 6626515Sraf ulwp.ul_sigmask.__sigbits[1], 6636515Sraf ulwp.ul_sigmask.__sigbits[2], 6646515Sraf ulwp.ul_sigmask.__sigbits[3]); 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate HD("tmpmask[0..3]"); 6670Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 6686515Sraf OFFSET(ul_tmpmask.__sigbits[0]), 6696515Sraf ulwp.ul_tmpmask.__sigbits[0], 6706515Sraf ulwp.ul_tmpmask.__sigbits[1], 6716515Sraf ulwp.ul_tmpmask.__sigbits[2], 6726515Sraf ulwp.ul_tmpmask.__sigbits[3]); 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate HD("&siginfo &spinlock &fpuenv"); 6750Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 6766515Sraf OFFSET(ul_siginfo), 6776515Sraf prt_addr((void *)(addr + OFFSET(ul_siginfo)), 1), 6786515Sraf prt_addr((void *)(addr + OFFSET(ul_spinlock)), 1), 6796515Sraf prt_addr((void *)(addr + OFFSET(ul_fpuenv)), 0)); 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate return (DCMD_OK); 6820Sstevel@tonic-gate } 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate /* 6850Sstevel@tonic-gate * Get the address of the unique uberdata_t structure. 6860Sstevel@tonic-gate */ 6870Sstevel@tonic-gate static uintptr_t 6880Sstevel@tonic-gate uberdata_addr(void) 6890Sstevel@tonic-gate { 6900Sstevel@tonic-gate uintptr_t uaddr; 6910Sstevel@tonic-gate uintptr_t addr; 6920Sstevel@tonic-gate GElf_Sym sym; 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_tdb_bootstrap", &sym) != 0) { 6950Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_tdb_bootstrap"); 6960Sstevel@tonic-gate return (NULL); 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate if (mdb_vread(&addr, sizeof (addr), sym.st_value) == sizeof (addr) && 6990Sstevel@tonic-gate addr != NULL && 7000Sstevel@tonic-gate mdb_vread(&uaddr, sizeof (uaddr), addr) == sizeof (uaddr) && 7010Sstevel@tonic-gate uaddr != NULL) { 7020Sstevel@tonic-gate return (uaddr); 7030Sstevel@tonic-gate } 7040Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_uberdata", &sym) != 0) { 7050Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_uberdata"); 7060Sstevel@tonic-gate return (NULL); 7070Sstevel@tonic-gate } 7080Sstevel@tonic-gate return ((uintptr_t)sym.st_value); 7090Sstevel@tonic-gate } 7100Sstevel@tonic-gate 7110Sstevel@tonic-gate #undef OFFSET 7120Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(uberdata_t, member)) 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate /*ARGSUSED*/ 7150Sstevel@tonic-gate static int 7160Sstevel@tonic-gate d_uberdata(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 7170Sstevel@tonic-gate { 7180Sstevel@tonic-gate uberdata_t uberdata; 7190Sstevel@tonic-gate int i; 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate if (argc != 0) 7220Sstevel@tonic-gate return (DCMD_USAGE); 7230Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) && (addr = uberdata_addr()) == NULL) 7240Sstevel@tonic-gate return (DCMD_ERR); 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate if (mdb_vread(&uberdata, sizeof (uberdata), addr) != 7270Sstevel@tonic-gate sizeof (uberdata)) { 7280Sstevel@tonic-gate mdb_warn("failed to read uberdata at 0x%p", addr); 7290Sstevel@tonic-gate return (DCMD_ERR); 7300Sstevel@tonic-gate } 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate mdb_printf("%#a\n", addr); 7330Sstevel@tonic-gate 7346515Sraf HD("&link_lock &ld_lock &fork_lock"); 7350Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7366515Sraf OFFSET(link_lock), 7376515Sraf prt_addr((void *)(addr + OFFSET(link_lock)), 1), 7386515Sraf prt_addr((void *)(addr + OFFSET(ld_lock)), 1), 7396515Sraf prt_addr((void *)(addr + OFFSET(fork_lock)), 0)); 7400Sstevel@tonic-gate 7416515Sraf HD("&atfork_lock &callout_lock &tdb_hash_lock"); 7420Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7436515Sraf OFFSET(atfork_lock), 7446515Sraf prt_addr((void *)(addr + OFFSET(atfork_lock)), 1), 7456515Sraf prt_addr((void *)(addr + OFFSET(callout_lock)), 1), 7466515Sraf prt_addr((void *)(addr + OFFSET(tdb_hash_lock)), 0)); 7476515Sraf 7486515Sraf HD("&tdb_hash_lock_stats &siguaction[0]"); 7496515Sraf mdb_printf(OFFSTR "%s %s\n", 7506515Sraf OFFSET(tdb_hash_lock_stats), 7516515Sraf prt_addr((void *)(addr + OFFSET(tdb_hash_lock_stats)), 1), 7526515Sraf prt_addr((void *)(addr + OFFSET(siguaction)), 0)); 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate HD("&bucket free_list chunks"); 7550Sstevel@tonic-gate for (i = 0; i < NBUCKETS; i++) { 7560Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7576515Sraf OFFSET(bucket[i]), 7586515Sraf prt_addr((void *)(addr + OFFSET(bucket[i])), 1), 7596515Sraf prt_addr(uberdata.bucket[i].free_list, 1), 7606515Sraf uberdata.bucket[i].chunks); 7610Sstevel@tonic-gate } 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate HD("&atexit_root head exit_frame_monitor"); 7640Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 7656515Sraf OFFSET(atexit_root), 7666515Sraf prt_addr((void *)(addr + OFFSET(atexit_root.exitfns_lock)), 1), 7676515Sraf prt_addr(uberdata.atexit_root.head, 1), 7686515Sraf prt_addr(uberdata.atexit_root.exit_frame_monitor, 0)); 7690Sstevel@tonic-gate 7700Sstevel@tonic-gate HD("&tsd_metadata tsdm_nkeys tsdm_nused tsdm_destro"); 7710Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %s\n", 7726515Sraf OFFSET(tsd_metadata), 7736515Sraf prt_addr((void *)(addr + OFFSET(tsd_metadata.tsdm_lock)), 1), 7746515Sraf uberdata.tsd_metadata.tsdm_nkeys, 7756515Sraf uberdata.tsd_metadata.tsdm_nused, 7766515Sraf prt_addr((void *)uberdata.tsd_metadata.tsdm_destro, 0)); 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate HD("&tls_metadata tls_modinfo.data tls_modinfo.size"); 7790Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7806515Sraf OFFSET(tls_metadata), 7816515Sraf prt_addr((void *)(addr + OFFSET(tls_metadata.tls_lock)), 1), 7826515Sraf prt_addr(uberdata.tls_metadata.tls_modinfo.tls_data, 1), 7836515Sraf uberdata.tls_metadata.tls_modinfo.tls_size); 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate HD(" static_tls.data static_tls.size"); 7860Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 7876515Sraf OFFSET(tls_metadata.static_tls), 7886515Sraf " ", 7896515Sraf prt_addr(uberdata.tls_metadata.static_tls.tls_data, 1), 7906515Sraf uberdata.tls_metadata.static_tls.tls_size); 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate HD("primary_ma bucket_ini uflags.mt uflags.pad uflags.trs uflags.ted"); 7930Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 7946515Sraf OFFSET(primary_map), 7956515Sraf uberdata.primary_map, 7966515Sraf uberdata.bucket_init, 7976515Sraf uberdata.uberflags.uf_x.x_mt, 7986515Sraf uberdata.uberflags.uf_x.x_pad, 7996515Sraf uberdata.uberflags.uf_x.x_tdb_register_sync, 8006515Sraf uberdata.uberflags.uf_x.x_thread_error_detection); 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate HD("queue_head thr_hash_table hash_size hash_mask"); 8030Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d 0x%x\n", 8046515Sraf OFFSET(queue_head), 8056515Sraf prt_addr(uberdata.queue_head, 1), 8066515Sraf prt_addr(uberdata.thr_hash_table, 1), 8076515Sraf uberdata.hash_size, 8086515Sraf uberdata.hash_mask); 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate HD("ulwp_one all_lwps all_zombies"); 8110Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 8126515Sraf OFFSET(ulwp_one), 8136515Sraf prt_addr(uberdata.ulwp_one, 1), 8146515Sraf prt_addr(uberdata.all_lwps, 1), 8156515Sraf prt_addr(uberdata.all_zombies, 0)); 8160Sstevel@tonic-gate 8170Sstevel@tonic-gate HD("nthreads nzombies ndaemons pid sigacthandler"); 8180Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", 8196515Sraf OFFSET(nthreads), 8206515Sraf uberdata.nthreads, 8216515Sraf uberdata.nzombies, 8226515Sraf uberdata.ndaemons, 8236515Sraf (int)uberdata.pid, 8246515Sraf prt_addr((void *)uberdata.sigacthandler, 0)); 8250Sstevel@tonic-gate 8260Sstevel@tonic-gate HD("lwp_stacks lwp_laststack nfreestack stk_cache"); 8270Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 8286515Sraf OFFSET(lwp_stacks), 8296515Sraf prt_addr(uberdata.lwp_stacks, 1), 8306515Sraf prt_addr(uberdata.lwp_laststack, 1), 8316515Sraf uberdata.nfreestack, 8326515Sraf uberdata.thread_stack_cache); 8330Sstevel@tonic-gate 8346515Sraf HD("ulwp_freelist ulwp_lastfree ulwp_replace_free"); 8356515Sraf mdb_printf(OFFSTR "%s %s %s\n", 8366515Sraf OFFSET(ulwp_freelist), 8376515Sraf prt_addr(uberdata.ulwp_freelist, 1), 8386515Sraf prt_addr(uberdata.ulwp_lastfree, 1), 8396515Sraf prt_addr(uberdata.ulwp_replace_free, 0)); 8404574Sraf 8419170SRoger.Faulkner@Sun.COM HD("ulwp_replace_last atforklist"); 8429170SRoger.Faulkner@Sun.COM mdb_printf(OFFSTR "%s %s\n", 8436515Sraf OFFSET(ulwp_replace_last), 8446515Sraf prt_addr(uberdata.ulwp_replace_last, 1), 8459170SRoger.Faulkner@Sun.COM prt_addr(uberdata.atforklist, 0)); 8469170SRoger.Faulkner@Sun.COM 8479170SRoger.Faulkner@Sun.COM HD("robustlocks robustlist"); 8489170SRoger.Faulkner@Sun.COM mdb_printf(OFFSTR "%s %s\n", 8499170SRoger.Faulkner@Sun.COM OFFSET(robustlocks), 8509170SRoger.Faulkner@Sun.COM prt_addr(uberdata.robustlocks, 1), 8519170SRoger.Faulkner@Sun.COM prt_addr(uberdata.robustlist, 0)); 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate HD("tdb_bootstrap tdb_sync_addr_hash tdb_'count tdb_'fail"); 8540Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 8556515Sraf OFFSET(tdb_bootstrap), 8566515Sraf prt_addr(uberdata.tdb_bootstrap, 1), 8576515Sraf prt_addr(uberdata.tdb.tdb_sync_addr_hash, 1), 8586515Sraf uberdata.tdb.tdb_register_count, 8596515Sraf uberdata.tdb.tdb_hash_alloc_failed); 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate HD("tdb_sync_addr_free tdb_sync_addr_last tdb_sync_alloc"); 8620Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 8636515Sraf OFFSET(tdb.tdb_sync_addr_free), 8646515Sraf prt_addr(uberdata.tdb.tdb_sync_addr_free, 1), 8656515Sraf prt_addr(uberdata.tdb.tdb_sync_addr_last, 1), 8666515Sraf uberdata.tdb.tdb_sync_alloc); 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate HD("tdb_ev_global_mask tdb_events"); 8690Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %s\n", 8706515Sraf OFFSET(tdb.tdb_ev_global_mask), 8716515Sraf uberdata.tdb.tdb_ev_global_mask.event_bits[0], 8726515Sraf uberdata.tdb.tdb_ev_global_mask.event_bits[1], 8736515Sraf prt_addr((void *)uberdata.tdb.tdb_events, 0)); 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate return (DCMD_OK); 8760Sstevel@tonic-gate } 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate static int 8790Sstevel@tonic-gate ulwp_walk_init(mdb_walk_state_t *wsp) 8800Sstevel@tonic-gate { 8810Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 8820Sstevel@tonic-gate uintptr_t uber_addr; 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate if (addr == NULL && 8850Sstevel@tonic-gate ((uber_addr = uberdata_addr()) == NULL || 8860Sstevel@tonic-gate mdb_vread(&addr, sizeof (addr), 8870Sstevel@tonic-gate uber_addr + OFFSETOF(uberdata_t, all_lwps)) 8880Sstevel@tonic-gate != sizeof (addr))) { 8890Sstevel@tonic-gate mdb_warn("cannot find 'uberdata.all_lwps'"); 8900Sstevel@tonic-gate return (WALK_ERR); 8910Sstevel@tonic-gate } 8920Sstevel@tonic-gate if (addr == NULL) 8930Sstevel@tonic-gate return (WALK_DONE); 8940Sstevel@tonic-gate wsp->walk_addr = addr; 8950Sstevel@tonic-gate wsp->walk_data = (void *)addr; 8960Sstevel@tonic-gate return (WALK_NEXT); 8970Sstevel@tonic-gate } 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate static int 9000Sstevel@tonic-gate ulwp_walk_step(mdb_walk_state_t *wsp) 9010Sstevel@tonic-gate { 9020Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 9030Sstevel@tonic-gate ulwp_t ulwp; 9040Sstevel@tonic-gate 9050Sstevel@tonic-gate if (addr == NULL) 9060Sstevel@tonic-gate return (WALK_DONE); 9070Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && 9080Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)), 9090Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { 9100Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr); 9110Sstevel@tonic-gate return (WALK_ERR); 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate /* 9140Sstevel@tonic-gate * If we have looped around to the beginning 9150Sstevel@tonic-gate * of the circular linked list, we are done. 9160Sstevel@tonic-gate */ 9170Sstevel@tonic-gate if ((wsp->walk_addr = (uintptr_t)ulwp.ul_forw) 9180Sstevel@tonic-gate == (uintptr_t)wsp->walk_data) 9190Sstevel@tonic-gate wsp->walk_addr = NULL; 9200Sstevel@tonic-gate return (wsp->walk_callback(addr, &ulwp, wsp->walk_cbdata)); 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate 92310610SJonathan.Adams@Sun.COM /* Avoid classifying NULL pointers as part of the main stack on x86 */ 92410610SJonathan.Adams@Sun.COM #define MIN_STACK_ADDR (0x10000ul) 92510610SJonathan.Adams@Sun.COM 92610610SJonathan.Adams@Sun.COM static int 92710610SJonathan.Adams@Sun.COM whatis_walk_ulwp(uintptr_t addr, const ulwp_t *ulwp, mdb_whatis_t *w) 92810610SJonathan.Adams@Sun.COM { 92910610SJonathan.Adams@Sun.COM uintptr_t cur; 93010610SJonathan.Adams@Sun.COM lwpid_t id = ulwp->ul_lwpid; 93110610SJonathan.Adams@Sun.COM uintptr_t top, base, size; 93210610SJonathan.Adams@Sun.COM 93310610SJonathan.Adams@Sun.COM while (mdb_whatis_match(w, addr, sizeof (ulwp_t), &cur)) 93410610SJonathan.Adams@Sun.COM mdb_whatis_report_object(w, cur, addr, 93510610SJonathan.Adams@Sun.COM "allocated as thread %#r's ulwp_t\n", id); 93610610SJonathan.Adams@Sun.COM 93710610SJonathan.Adams@Sun.COM top = (uintptr_t)ulwp->ul_stktop; 93810610SJonathan.Adams@Sun.COM size = ulwp->ul_stksiz; 93910610SJonathan.Adams@Sun.COM 94010610SJonathan.Adams@Sun.COM /* 94110610SJonathan.Adams@Sun.COM * The main stack ends up being a little weird, especially if 94210610SJonathan.Adams@Sun.COM * the stack ulimit is unlimited. This tries to take that into 94310610SJonathan.Adams@Sun.COM * account. 94410610SJonathan.Adams@Sun.COM */ 94510610SJonathan.Adams@Sun.COM if (size > top) 94610610SJonathan.Adams@Sun.COM size = top; 94710610SJonathan.Adams@Sun.COM if (top > MIN_STACK_ADDR && top - size < MIN_STACK_ADDR) 94810610SJonathan.Adams@Sun.COM size = top - MIN_STACK_ADDR; 94910610SJonathan.Adams@Sun.COM 95010610SJonathan.Adams@Sun.COM base = top - size; 95110610SJonathan.Adams@Sun.COM 95210610SJonathan.Adams@Sun.COM while (mdb_whatis_match(w, base, size, &cur)) 95310610SJonathan.Adams@Sun.COM mdb_whatis_report_address(w, cur, "in [ stack tid=%#r ]\n", id); 95410610SJonathan.Adams@Sun.COM 95510610SJonathan.Adams@Sun.COM if (ulwp->ul_ustack.ss_flags & SS_ONSTACK) { 95610610SJonathan.Adams@Sun.COM base = (uintptr_t)ulwp->ul_ustack.ss_sp; 95710610SJonathan.Adams@Sun.COM size = ulwp->ul_ustack.ss_size; 95810610SJonathan.Adams@Sun.COM 95910610SJonathan.Adams@Sun.COM while (mdb_whatis_match(w, base, size, &cur)) 96010610SJonathan.Adams@Sun.COM mdb_whatis_report_address(w, cur, 96110610SJonathan.Adams@Sun.COM "in [ altstack tid=%#r ]\n", id); 96210610SJonathan.Adams@Sun.COM } 96310610SJonathan.Adams@Sun.COM 96410610SJonathan.Adams@Sun.COM return (WHATIS_WALKRET(w)); 96510610SJonathan.Adams@Sun.COM } 96610610SJonathan.Adams@Sun.COM 96710610SJonathan.Adams@Sun.COM /*ARGSUSED*/ 96810610SJonathan.Adams@Sun.COM static int 96910610SJonathan.Adams@Sun.COM whatis_run_ulwps(mdb_whatis_t *w, void *arg) 97010610SJonathan.Adams@Sun.COM { 97110610SJonathan.Adams@Sun.COM if (mdb_walk("ulwps", (mdb_walk_cb_t)whatis_walk_ulwp, w) == -1) { 97210610SJonathan.Adams@Sun.COM mdb_warn("couldn't find ulwps walker"); 97310610SJonathan.Adams@Sun.COM return (1); 97410610SJonathan.Adams@Sun.COM } 97510610SJonathan.Adams@Sun.COM return (0); 97610610SJonathan.Adams@Sun.COM } 97710610SJonathan.Adams@Sun.COM 9780Sstevel@tonic-gate /* 9790Sstevel@tonic-gate * ======================================================= 9800Sstevel@tonic-gate * End of thread (previously libthread) interfaces. 9810Sstevel@tonic-gate * ==================== threads ========================== 9820Sstevel@tonic-gate */ 9830Sstevel@tonic-gate 9840Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 9850Sstevel@tonic-gate { "jmp_buf", ":", "print jmp_buf contents", d_jmp_buf, NULL }, 9860Sstevel@tonic-gate { "sigjmp_buf", ":", "print sigjmp_buf contents", d_sigjmp_buf, NULL }, 9870Sstevel@tonic-gate { "siginfo", ":", "print siginfo_t structure", d_siginfo, NULL }, 9880Sstevel@tonic-gate { "ucontext", ":", "print ucontext_t structure", d_ucontext, NULL }, 9890Sstevel@tonic-gate { "ulwp", ":", "print ulwp_t structure", d_ulwp, NULL }, 9900Sstevel@tonic-gate { "uberdata", ":", "print uberdata_t structure", d_uberdata, NULL }, 9910Sstevel@tonic-gate { NULL } 9920Sstevel@tonic-gate }; 9930Sstevel@tonic-gate 9940Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 9950Sstevel@tonic-gate { "ucontext", "walk ucontext_t uc_link list", 9960Sstevel@tonic-gate NULL, uc_walk_step, NULL, NULL }, 9970Sstevel@tonic-gate { "oldcontext", "walk per-lwp oldcontext pointers", 9980Sstevel@tonic-gate oldc_walk_init, oldc_walk_step, oldc_walk_fini, NULL }, 9990Sstevel@tonic-gate { "ulwps", "walk list of ulwp_t pointers", 10000Sstevel@tonic-gate ulwp_walk_init, ulwp_walk_step, NULL, NULL }, 10010Sstevel@tonic-gate { NULL } 10020Sstevel@tonic-gate }; 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 10050Sstevel@tonic-gate 10060Sstevel@tonic-gate const mdb_modinfo_t * 10070Sstevel@tonic-gate _mdb_init(void) 10080Sstevel@tonic-gate { 100910610SJonathan.Adams@Sun.COM mdb_whatis_register("threads", whatis_run_ulwps, NULL, 101010610SJonathan.Adams@Sun.COM WHATIS_PRIO_EARLY, WHATIS_REG_NO_ID); 101110610SJonathan.Adams@Sun.COM 10120Sstevel@tonic-gate return (&modinfo); 10130Sstevel@tonic-gate } 1014