17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
534709573Sraf * Common Development and Distribution License (the "License").
634709573Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
2134709573Sraf
227c478bd9Sstevel@tonic-gate /*
233cd8a1a6SRoger A. Faulkner * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
2428e4da25SMatthew Ahrens * Copyright (c) 2012 by Delphix. All rights reserved.
257c478bd9Sstevel@tonic-gate */
263e3d658fSRobert Mustacchi /*
27*0cd35134SJoshua M. Clulow * Copyright (c) 2015, Joyent, Inc.
283e3d658fSRobert Mustacchi */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #include <sys/mdb_modapi.h>
314a1c2431SJonathan Adams #include <mdb/mdb_whatis.h>
3228e4da25SMatthew Ahrens #include <mdb/mdb_ctf.h>
337c478bd9Sstevel@tonic-gate #include <procfs.h>
347c478bd9Sstevel@tonic-gate #include <ucontext.h>
357c478bd9Sstevel@tonic-gate #include <siginfo.h>
367c478bd9Sstevel@tonic-gate #include <signal.h>
377c478bd9Sstevel@tonic-gate #include <setjmp.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate #include <thr_uberdata.h>
40c9a6ea2eSBryan Cantrill #include "findstack.h"
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate static const char *
stack_flags(const stack_t * sp)437c478bd9Sstevel@tonic-gate stack_flags(const stack_t *sp)
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate static char buf[32];
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate if (sp->ss_flags == 0)
487c478bd9Sstevel@tonic-gate (void) strcpy(buf, " 0");
497c478bd9Sstevel@tonic-gate else if (sp->ss_flags & ~(SS_ONSTACK | SS_DISABLE))
507c478bd9Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buf), " 0x%x", sp->ss_flags);
517c478bd9Sstevel@tonic-gate else {
527c478bd9Sstevel@tonic-gate buf[0] = '\0';
537c478bd9Sstevel@tonic-gate if (sp->ss_flags & SS_ONSTACK)
547c478bd9Sstevel@tonic-gate (void) strcat(buf, "|ONSTACK");
557c478bd9Sstevel@tonic-gate if (sp->ss_flags & SS_DISABLE)
567c478bd9Sstevel@tonic-gate (void) strcat(buf, "|DISABLE");
577c478bd9Sstevel@tonic-gate }
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate return (buf + 1);
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*ARGSUSED*/
637c478bd9Sstevel@tonic-gate static int
d_jmp_buf(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)647c478bd9Sstevel@tonic-gate d_jmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate jmp_buf jb;
677c478bd9Sstevel@tonic-gate const ulong_t *b = (const ulong_t *)jb;
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate if (argc != 0)
707c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate if (mdb_vread(&jb, sizeof (jb), addr) != sizeof (jb)) {
737c478bd9Sstevel@tonic-gate mdb_warn("failed to read jmp_buf at %p", addr);
747c478bd9Sstevel@tonic-gate return (DCMD_ERR);
757c478bd9Sstevel@tonic-gate }
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate #if defined(__sparc)
787c478bd9Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx\n", b[1]);
797c478bd9Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", b[2], b[2]);
807c478bd9Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx\n", b[3]);
817c478bd9Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", b[4], b[4]);
827c478bd9Sstevel@tonic-gate #elif defined(__amd64)
837c478bd9Sstevel@tonic-gate mdb_printf(" %%rbx = 0x%lx\n", b[0]);
847c478bd9Sstevel@tonic-gate mdb_printf(" %%r12 = 0x%lx\n", b[1]);
857c478bd9Sstevel@tonic-gate mdb_printf(" %%r13 = 0x%lx\n", b[2]);
867c478bd9Sstevel@tonic-gate mdb_printf(" %%r14 = 0x%lx\n", b[3]);
877c478bd9Sstevel@tonic-gate mdb_printf(" %%r15 = 0x%lx\n", b[4]);
887c478bd9Sstevel@tonic-gate mdb_printf(" %%rbp = 0x%lx\n", b[5]);
897c478bd9Sstevel@tonic-gate mdb_printf(" %%rsp = 0x%lx\n", b[6]);
907c478bd9Sstevel@tonic-gate mdb_printf(" %%rip = 0x%lx %lA\n", b[7], b[7]);
917c478bd9Sstevel@tonic-gate #elif defined(__i386)
927c478bd9Sstevel@tonic-gate mdb_printf(" %%ebx = 0x%lx\n", b[0]);
937c478bd9Sstevel@tonic-gate mdb_printf(" %%esi = 0x%lx\n", b[1]);
947c478bd9Sstevel@tonic-gate mdb_printf(" %%edi = 0x%lx\n", b[2]);
957c478bd9Sstevel@tonic-gate mdb_printf(" %%ebp = 0x%lx\n", b[3]);
967c478bd9Sstevel@tonic-gate mdb_printf(" %%esp = 0x%lx\n", b[4]);
977c478bd9Sstevel@tonic-gate mdb_printf(" %%eip = 0x%lx %lA\n", b[5], b[5]);
987c478bd9Sstevel@tonic-gate #endif
997c478bd9Sstevel@tonic-gate return (DCMD_OK);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
102*0cd35134SJoshua M. Clulow const mdb_bitmask_t uc_flags_bits[] = {
103*0cd35134SJoshua M. Clulow { "UC_SIGMASK", UC_SIGMASK, UC_SIGMASK },
104*0cd35134SJoshua M. Clulow { "UC_STACK", UC_STACK, UC_STACK },
105*0cd35134SJoshua M. Clulow { "UC_CPU", UC_CPU, UC_CPU },
106*0cd35134SJoshua M. Clulow { "UC_FPU", UC_FPU, UC_FPU },
107*0cd35134SJoshua M. Clulow #if defined(UC_INTR)
108*0cd35134SJoshua M. Clulow { "UC_INTR", UC_INTR, UC_INTR },
109*0cd35134SJoshua M. Clulow #endif
110*0cd35134SJoshua M. Clulow #if defined(UC_ASR)
111*0cd35134SJoshua M. Clulow { "UC_ASR", UC_ASR, UC_ASR },
112*0cd35134SJoshua M. Clulow #endif
113*0cd35134SJoshua M. Clulow { NULL, 0, 0 }
114*0cd35134SJoshua M. Clulow };
115*0cd35134SJoshua M. Clulow
1167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1177c478bd9Sstevel@tonic-gate static int
d_ucontext(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1187c478bd9Sstevel@tonic-gate d_ucontext(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate ucontext_t uc;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if (argc != 0)
1237c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) {
1267c478bd9Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr);
1277c478bd9Sstevel@tonic-gate return (DCMD_ERR);
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate
130*0cd35134SJoshua M. Clulow mdb_printf(" flags = 0x%lx <%b>\n", uc.uc_flags,
131*0cd35134SJoshua M. Clulow (uint_t)uc.uc_flags, uc_flags_bits);
1327c478bd9Sstevel@tonic-gate mdb_printf(" link = 0x%p\n", uc.uc_link);
1337c478bd9Sstevel@tonic-gate mdb_printf(" sigmask = 0x%08x 0x%08x 0x%08x 0x%08x\n",
1347c478bd9Sstevel@tonic-gate uc.uc_sigmask.__sigbits[0], uc.uc_sigmask.__sigbits[1],
1357c478bd9Sstevel@tonic-gate uc.uc_sigmask.__sigbits[2], uc.uc_sigmask.__sigbits[3]);
1367c478bd9Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n",
1377c478bd9Sstevel@tonic-gate uc.uc_stack.ss_sp, uc.uc_stack.ss_size, stack_flags(&uc.uc_stack));
1387c478bd9Sstevel@tonic-gate mdb_printf(" mcontext = 0x%p\n",
1397c478bd9Sstevel@tonic-gate addr + OFFSETOF(ucontext_t, uc_mcontext));
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate return (DCMD_OK);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1457c478bd9Sstevel@tonic-gate static int
d_sigjmp_buf(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1467c478bd9Sstevel@tonic-gate d_sigjmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1477c478bd9Sstevel@tonic-gate {
1487c478bd9Sstevel@tonic-gate #if defined(__sparc)
1497c478bd9Sstevel@tonic-gate struct {
1507c478bd9Sstevel@tonic-gate int sjs_flags;
1517c478bd9Sstevel@tonic-gate greg_t sjs_sp;
1527c478bd9Sstevel@tonic-gate greg_t sjs_pc;
1537c478bd9Sstevel@tonic-gate greg_t sjs_fp;
1547c478bd9Sstevel@tonic-gate greg_t sjs_i7;
1557c478bd9Sstevel@tonic-gate ucontext_t *sjs_uclink;
1567c478bd9Sstevel@tonic-gate ulong_t sjs_pad[_JBLEN - 6];
1577c478bd9Sstevel@tonic-gate sigset_t sjs_sigmask;
1587c478bd9Sstevel@tonic-gate #if defined(_LP64)
1593cd8a1a6SRoger A. Faulkner greg_t sjs_asi;
1603cd8a1a6SRoger A. Faulkner greg_t sjs_fprs;
1617c478bd9Sstevel@tonic-gate #endif
1627c478bd9Sstevel@tonic-gate stack_t sjs_stack;
1637c478bd9Sstevel@tonic-gate } s;
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate if (argc != 0)
1667c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate if (mdb_vread(&s, sizeof (s), addr) != sizeof (s)) {
1697c478bd9Sstevel@tonic-gate mdb_warn("failed to read sigjmp_buf at %p", addr);
1707c478bd9Sstevel@tonic-gate return (DCMD_ERR);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate mdb_printf(" flags = 0x%x\n", s.sjs_flags);
1747c478bd9Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx %lA\n", s.sjs_sp, s.sjs_sp);
1757c478bd9Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", s.sjs_pc, s.sjs_pc);
1767c478bd9Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx %lA\n", s.sjs_fp, s.sjs_fp);
1777c478bd9Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", s.sjs_i7, s.sjs_i7);
1787c478bd9Sstevel@tonic-gate mdb_printf(" uclink = %p\n", s.sjs_uclink);
1797c478bd9Sstevel@tonic-gate mdb_printf(" sigset = 0x%08x 0x%08x 0x%08x 0x%08x\n",
1807c478bd9Sstevel@tonic-gate s.sjs_sigmask.__sigbits[0], s.sjs_sigmask.__sigbits[1],
1817c478bd9Sstevel@tonic-gate s.sjs_sigmask.__sigbits[2], s.sjs_sigmask.__sigbits[3]);
1823cd8a1a6SRoger A. Faulkner #if defined(_LP64)
1833cd8a1a6SRoger A. Faulkner mdb_printf(" %%asi = 0x%lx\n", s.sjs_asi);
1843cd8a1a6SRoger A. Faulkner mdb_printf(" %%fprs = 0x%lx\n", s.sjs_fprs);
1853cd8a1a6SRoger A. Faulkner #endif
1867c478bd9Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n",
1877c478bd9Sstevel@tonic-gate s.sjs_stack.ss_sp, s.sjs_stack.ss_size, stack_flags(&s.sjs_stack));
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate return (DCMD_OK);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64)
1927c478bd9Sstevel@tonic-gate return (d_ucontext(addr, flags, argc, argv));
1937c478bd9Sstevel@tonic-gate #endif
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1977c478bd9Sstevel@tonic-gate static int
d_siginfo(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1987c478bd9Sstevel@tonic-gate d_siginfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate static const char *const msname[] = {
2017c478bd9Sstevel@tonic-gate "USER", "SYSTEM", "TRAP", "TFAULT", "DFAULT", "KFAULT",
2027c478bd9Sstevel@tonic-gate "USER_LOCK", "SLEEP", "WAIT_CPU", "STOPPED"
2037c478bd9Sstevel@tonic-gate };
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate char signame[SIG2STR_MAX];
2067c478bd9Sstevel@tonic-gate siginfo_t si;
2077c478bd9Sstevel@tonic-gate int i;
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate if (argc != 0)
2107c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate if (mdb_vread(&si, sizeof (si), addr) != sizeof (si)) {
2137c478bd9Sstevel@tonic-gate mdb_warn("failed to read siginfo at %p", addr);
2147c478bd9Sstevel@tonic-gate return (DCMD_ERR);
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate if (sig2str(si.si_signo, signame) == -1)
2187c478bd9Sstevel@tonic-gate (void) strcpy(signame, "unknown");
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate mdb_printf(" signal %5d (%s)\n", si.si_signo, signame);
2217c478bd9Sstevel@tonic-gate mdb_printf(" code %5d (", si.si_code);
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate switch (si.si_code) {
2247c478bd9Sstevel@tonic-gate case SI_NOINFO:
2257c478bd9Sstevel@tonic-gate mdb_printf("no info");
2267c478bd9Sstevel@tonic-gate break;
2277c478bd9Sstevel@tonic-gate case SI_DTRACE:
2287c478bd9Sstevel@tonic-gate mdb_printf("from DTrace raise() action");
2297c478bd9Sstevel@tonic-gate break;
2307c478bd9Sstevel@tonic-gate case SI_RCTL:
2317c478bd9Sstevel@tonic-gate mdb_printf("from rctl action");
2327c478bd9Sstevel@tonic-gate break;
2337c478bd9Sstevel@tonic-gate case SI_USER:
2347c478bd9Sstevel@tonic-gate mdb_printf("user generated via kill");
2357c478bd9Sstevel@tonic-gate break;
2367c478bd9Sstevel@tonic-gate case SI_LWP:
2377c478bd9Sstevel@tonic-gate mdb_printf("user generated via lwp_kill");
2387c478bd9Sstevel@tonic-gate break;
2397c478bd9Sstevel@tonic-gate case SI_QUEUE:
2407c478bd9Sstevel@tonic-gate mdb_printf("user generated via sigqueue");
2417c478bd9Sstevel@tonic-gate break;
2427c478bd9Sstevel@tonic-gate case SI_TIMER:
2437c478bd9Sstevel@tonic-gate mdb_printf("from timer expiration");
2447c478bd9Sstevel@tonic-gate break;
2457c478bd9Sstevel@tonic-gate case SI_ASYNCIO:
2467c478bd9Sstevel@tonic-gate mdb_printf("from async i/o completion");
2477c478bd9Sstevel@tonic-gate break;
2487c478bd9Sstevel@tonic-gate case SI_MESGQ:
2497c478bd9Sstevel@tonic-gate mdb_printf("from message arrival");
2507c478bd9Sstevel@tonic-gate break;
2517c478bd9Sstevel@tonic-gate default:
2527c478bd9Sstevel@tonic-gate if (SI_FROMUSER(&si))
2537c478bd9Sstevel@tonic-gate mdb_printf("from user process");
2547c478bd9Sstevel@tonic-gate else
2557c478bd9Sstevel@tonic-gate mdb_printf("from kernel");
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate mdb_printf(")\n errno %5d (%s)\n",
2597c478bd9Sstevel@tonic-gate si.si_errno, strerror(si.si_errno));
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate if (si.si_code == SI_USER || si.si_code == SI_QUEUE) {
2627c478bd9Sstevel@tonic-gate mdb_printf(" signal sent from PID %d (uid %d)\n",
2637c478bd9Sstevel@tonic-gate si.si_pid, si.si_uid);
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate if (si.si_code == SI_QUEUE) {
2677c478bd9Sstevel@tonic-gate mdb_printf(" signal value = 0t%d / %p\n",
2687c478bd9Sstevel@tonic-gate si.si_value.sival_int, si.si_value.sival_ptr);
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate switch (si.si_signo) {
2727c478bd9Sstevel@tonic-gate case SIGCLD:
2737c478bd9Sstevel@tonic-gate mdb_printf(" signal sent from child PID %d (uid %d)\n",
2747c478bd9Sstevel@tonic-gate si.si_pid, si.si_uid);
2757c478bd9Sstevel@tonic-gate mdb_printf(" usr time = 0t%ld ticks, sys time = 0t%ld ticks\n",
2767c478bd9Sstevel@tonic-gate si.si_utime, si.si_stime);
2777c478bd9Sstevel@tonic-gate mdb_printf(" wait status = 0x%x\n", si.si_status);
2787c478bd9Sstevel@tonic-gate break;
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate case SIGSEGV:
2817c478bd9Sstevel@tonic-gate case SIGBUS:
2827c478bd9Sstevel@tonic-gate case SIGILL:
2837c478bd9Sstevel@tonic-gate case SIGTRAP:
2847c478bd9Sstevel@tonic-gate case SIGFPE:
2857c478bd9Sstevel@tonic-gate mdb_printf(" fault address = 0x%p\n trapno = %d\n",
2867c478bd9Sstevel@tonic-gate si.si_addr, si.si_trapno);
2877c478bd9Sstevel@tonic-gate mdb_printf(" instruction address = 0x%p %lA\n",
2887c478bd9Sstevel@tonic-gate si.si_pc, si.si_pc);
2897c478bd9Sstevel@tonic-gate break;
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate case SIGPOLL:
2927c478bd9Sstevel@tonic-gate case SIGXFSZ:
2937c478bd9Sstevel@tonic-gate mdb_printf(" fd = %d band = 0x%lx\n",
2947c478bd9Sstevel@tonic-gate si.si_fd, si.si_band);
2957c478bd9Sstevel@tonic-gate break;
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate case SIGPROF:
2987c478bd9Sstevel@tonic-gate mdb_printf(" last fault address = 0x%p fault type = %d\n",
2997c478bd9Sstevel@tonic-gate si.si_faddr, si.si_fault);
3007c478bd9Sstevel@tonic-gate mdb_printf(" timestamp = 0t%ld sec 0t%ld nsec\n",
3017c478bd9Sstevel@tonic-gate si.si_tstamp.tv_sec, si.si_tstamp.tv_nsec);
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate if (si.__data.__prof.__syscall != 0) {
3047c478bd9Sstevel@tonic-gate mdb_printf(" system call %d (", si.si_syscall);
3057c478bd9Sstevel@tonic-gate if (si.si_nsysarg > 0) {
3067c478bd9Sstevel@tonic-gate mdb_printf("%lx", si.si_sysarg[0]);
3077c478bd9Sstevel@tonic-gate for (i = 1; i < si.si_nsysarg; i++)
3087c478bd9Sstevel@tonic-gate mdb_printf(", %lx", si.si_sysarg[i]);
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate mdb_printf(" )\n");
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate
3137c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (msname) / sizeof (msname[0]); i++) {
3147c478bd9Sstevel@tonic-gate mdb_printf(" mstate[\"%s\"] = %d\n",
3157c478bd9Sstevel@tonic-gate msname[i], si.si_mstate[i]);
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate break;
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate return (DCMD_OK);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate static int
uc_walk_step(mdb_walk_state_t * wsp)3247c478bd9Sstevel@tonic-gate uc_walk_step(mdb_walk_state_t *wsp)
3257c478bd9Sstevel@tonic-gate {
3267c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr;
3277c478bd9Sstevel@tonic-gate ucontext_t uc;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate if (addr == NULL)
3307c478bd9Sstevel@tonic-gate return (WALK_DONE);
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) {
3337c478bd9Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr);
3347c478bd9Sstevel@tonic-gate return (WALK_ERR);
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)uc.uc_link;
3387c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata));
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate static int
oldc_walk_init(mdb_walk_state_t * wsp)3427c478bd9Sstevel@tonic-gate oldc_walk_init(mdb_walk_state_t *wsp)
3437c478bd9Sstevel@tonic-gate {
3447c478bd9Sstevel@tonic-gate ssize_t nbytes = mdb_get_xdata("lwpstatus", NULL, 0);
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate if (nbytes <= 0) {
3477c478bd9Sstevel@tonic-gate mdb_warn("lwpstatus information not available");
3487c478bd9Sstevel@tonic-gate return (WALK_ERR);
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate if (wsp->walk_addr != NULL) {
3527c478bd9Sstevel@tonic-gate mdb_warn("walker only supports global walk\n");
3537c478bd9Sstevel@tonic-gate return (WALK_ERR);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate wsp->walk_addr = nbytes; /* Use walk_addr to track size */
3577c478bd9Sstevel@tonic-gate wsp->walk_data = mdb_alloc(nbytes, UM_SLEEP);
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate if (mdb_get_xdata("lwpstatus", wsp->walk_data, nbytes) != nbytes) {
3607c478bd9Sstevel@tonic-gate mdb_warn("failed to read lwpstatus information");
3617c478bd9Sstevel@tonic-gate mdb_free(wsp->walk_data, nbytes);
3627c478bd9Sstevel@tonic-gate return (WALK_ERR);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate wsp->walk_arg = wsp->walk_data; /* Use walk_arg to track pointer */
3667c478bd9Sstevel@tonic-gate return (WALK_NEXT);
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate static int
oldc_walk_step(mdb_walk_state_t * wsp)3707c478bd9Sstevel@tonic-gate oldc_walk_step(mdb_walk_state_t *wsp)
3717c478bd9Sstevel@tonic-gate {
3727c478bd9Sstevel@tonic-gate const lwpstatus_t *lsp, *end;
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate end = (const lwpstatus_t *)((uintptr_t)wsp->walk_data + wsp->walk_addr);
3757c478bd9Sstevel@tonic-gate lsp = wsp->walk_arg;
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate wsp->walk_arg = (void *)(lsp + 1);
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate if (lsp < end) {
3807c478bd9Sstevel@tonic-gate uintptr_t addr = lsp->pr_oldcontext;
3817c478bd9Sstevel@tonic-gate ucontext_t uc;
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate if (addr == NULL)
3847c478bd9Sstevel@tonic-gate return (WALK_NEXT);
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) {
3877c478bd9Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr);
3887c478bd9Sstevel@tonic-gate return (WALK_NEXT);
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata));
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate return (WALK_DONE);
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate static void
oldc_walk_fini(mdb_walk_state_t * wsp)3987c478bd9Sstevel@tonic-gate oldc_walk_fini(mdb_walk_state_t *wsp)
3997c478bd9Sstevel@tonic-gate {
4007c478bd9Sstevel@tonic-gate mdb_free(wsp->walk_data, wsp->walk_addr); /* walk_addr has size */
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate /*
4047c478bd9Sstevel@tonic-gate * ==================== threads ==========================
4057c478bd9Sstevel@tonic-gate * These are the interfaces that used to require libthread.
4067c478bd9Sstevel@tonic-gate * Now, libthread has been folded into libc.
4077c478bd9Sstevel@tonic-gate * =======================================================
4087c478bd9Sstevel@tonic-gate */
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate /*
4117c478bd9Sstevel@tonic-gate * prt_addr() is called up to three times to generate arguments for
4127c478bd9Sstevel@tonic-gate * one call to mdb_printf(). We must return at least three different
4137c478bd9Sstevel@tonic-gate * pointers to static storage for consecutive calls to prt_addr().
4147c478bd9Sstevel@tonic-gate */
4157c478bd9Sstevel@tonic-gate static const char *
prt_addr(void * addr,int pad)4167c478bd9Sstevel@tonic-gate prt_addr(void *addr, int pad)
4177c478bd9Sstevel@tonic-gate {
4187c478bd9Sstevel@tonic-gate static char buffer[4][24];
4197c478bd9Sstevel@tonic-gate static int ix = 0;
4207c478bd9Sstevel@tonic-gate char *buf;
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate if (ix == 4) /* use buffers in sequence: 0, 1, 2, 3 */
4237c478bd9Sstevel@tonic-gate ix = 0;
4247c478bd9Sstevel@tonic-gate buf = buffer[ix++];
4257c478bd9Sstevel@tonic-gate if (addr == NULL)
4267c478bd9Sstevel@tonic-gate return (pad? "<NULL> " : "<NULL>");
4277c478bd9Sstevel@tonic-gate else {
4287c478bd9Sstevel@tonic-gate #ifdef _LP64
4297c478bd9Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%016lx", addr);
4307c478bd9Sstevel@tonic-gate if (pad)
4317c478bd9Sstevel@tonic-gate (void) strcpy(buf + 18, " ");
4327c478bd9Sstevel@tonic-gate #else
4337c478bd9Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%08lx", addr);
4347c478bd9Sstevel@tonic-gate if (pad)
4357c478bd9Sstevel@tonic-gate (void) strcpy(buf + 10, " ");
4367c478bd9Sstevel@tonic-gate #endif /* _LP64 */
4377c478bd9Sstevel@tonic-gate return (buf);
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate #define HD(str) mdb_printf(" " str "\n")
4427c478bd9Sstevel@tonic-gate #define OFFSTR "+0x%-7lx "
4437c478bd9Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(ulwp_t, member))
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4467c478bd9Sstevel@tonic-gate static int
d_ulwp(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4477c478bd9Sstevel@tonic-gate d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4487c478bd9Sstevel@tonic-gate {
4497c478bd9Sstevel@tonic-gate ulwp_t ulwp;
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate if (argc != 0 || !(flags & DCMD_ADDRSPEC))
4527c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) &&
4557c478bd9Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)),
4567c478bd9Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) {
4577c478bd9Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr);
4587c478bd9Sstevel@tonic-gate return (DCMD_ERR);
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate mdb_printf("%#a\n", addr);
4627c478bd9Sstevel@tonic-gate
4637c478bd9Sstevel@tonic-gate HD("self uberdata");
4647c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s\n",
4657c478bd9Sstevel@tonic-gate OFFSET(ul_self),
4667c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_self, 1),
4677c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_uberdata, 0));
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate HD("tlsent ntlsent");
4707c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %ld\n",
4717c478bd9Sstevel@tonic-gate OFFSET(ul_tlsent),
4727c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_tlsent, 1),
4737c478bd9Sstevel@tonic-gate ulwp.ul_ntlsent);
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate HD("forw back next");
4767c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
4777c478bd9Sstevel@tonic-gate OFFSET(ul_forw),
4787c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_forw, 1),
4797c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_back, 1),
4807c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_next, 0));
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate HD("hash rval stk");
4837c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
4847c478bd9Sstevel@tonic-gate OFFSET(ul_hash),
4857c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_hash, 1),
4867c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_rval, 1),
4877c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_stk, 0));
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate HD("mapsiz guardsize stktop stksiz");
4907c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10ld %-10ld %s %ld\n",
4917c478bd9Sstevel@tonic-gate OFFSET(ul_mapsiz),
4927c478bd9Sstevel@tonic-gate ulwp.ul_mapsiz,
4937c478bd9Sstevel@tonic-gate ulwp.ul_guardsize,
4947c478bd9Sstevel@tonic-gate prt_addr((void *)ulwp.ul_stktop, 1),
4957c478bd9Sstevel@tonic-gate ulwp.ul_stksiz);
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate HD("ustack.ss_sp ustack.ss_size ustack.ss_flags");
4987c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-21ld %s\n",
4997c478bd9Sstevel@tonic-gate OFFSET(ul_ustack.ss_sp),
5007c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_ustack.ss_sp, 1),
5017c478bd9Sstevel@tonic-gate ulwp.ul_ustack.ss_size,
5027c478bd9Sstevel@tonic-gate stack_flags(&ulwp.ul_ustack));
5037c478bd9Sstevel@tonic-gate
504d4204c85Sraf HD("ix lwpid pri epri policy cid");
5057c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n",
5067c478bd9Sstevel@tonic-gate OFFSET(ul_ix),
5077c478bd9Sstevel@tonic-gate ulwp.ul_ix,
5087c478bd9Sstevel@tonic-gate ulwp.ul_lwpid,
5097c478bd9Sstevel@tonic-gate ulwp.ul_pri,
510d4204c85Sraf ulwp.ul_epri,
5117c478bd9Sstevel@tonic-gate ulwp.ul_policy,
512d4204c85Sraf ulwp.ul_cid);
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate HD("cursig pleasestop stop signalled dead unwind");
5157c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d ",
5167c478bd9Sstevel@tonic-gate OFFSET(ul_cursig),
5177c478bd9Sstevel@tonic-gate ulwp.ul_cursig);
5187c478bd9Sstevel@tonic-gate mdb_printf(ulwp.ul_pleasestop? "0x%-8x " : "%-10d ",
5197c478bd9Sstevel@tonic-gate ulwp.ul_pleasestop);
5207c478bd9Sstevel@tonic-gate mdb_printf(ulwp.ul_stop? "0x%-8x " : "%-10d ",
5217c478bd9Sstevel@tonic-gate ulwp.ul_stop);
5227c478bd9Sstevel@tonic-gate mdb_printf("%-10d %-10d %d\n",
5237c478bd9Sstevel@tonic-gate ulwp.ul_signalled,
5247c478bd9Sstevel@tonic-gate ulwp.ul_dead,
5257c478bd9Sstevel@tonic-gate ulwp.ul_unwind);
5267c478bd9Sstevel@tonic-gate
52734709573Sraf HD("detached writer stopping can'prolog preempt savpreempt");
5287c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n",
5297c478bd9Sstevel@tonic-gate OFFSET(ul_detached),
5307c478bd9Sstevel@tonic-gate ulwp.ul_detached,
5317c478bd9Sstevel@tonic-gate ulwp.ul_writer,
5327c478bd9Sstevel@tonic-gate ulwp.ul_stopping,
53334709573Sraf ulwp.ul_cancel_prologue,
5347c478bd9Sstevel@tonic-gate ulwp.ul_preempt,
5357c478bd9Sstevel@tonic-gate ulwp.ul_savpreempt);
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate HD("sigsuspend main fork primarymap m'spinners d'noreserv");
5387c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n",
5397c478bd9Sstevel@tonic-gate OFFSET(ul_sigsuspend),
5407c478bd9Sstevel@tonic-gate ulwp.ul_sigsuspend,
5417c478bd9Sstevel@tonic-gate ulwp.ul_main,
5427c478bd9Sstevel@tonic-gate ulwp.ul_fork,
5437c478bd9Sstevel@tonic-gate ulwp.ul_primarymap,
5447c478bd9Sstevel@tonic-gate ulwp.ul_max_spinners,
5457c478bd9Sstevel@tonic-gate ulwp.ul_door_noreserve);
5467c478bd9Sstevel@tonic-gate
547d4204c85Sraf HD("queue_fifo c'w'defer e'detect' async_safe rt rtqueued");
5487c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n",
5497c478bd9Sstevel@tonic-gate OFFSET(ul_queue_fifo),
5507c478bd9Sstevel@tonic-gate ulwp.ul_queue_fifo,
5517c478bd9Sstevel@tonic-gate ulwp.ul_cond_wait_defer,
5527c478bd9Sstevel@tonic-gate ulwp.ul_error_detection,
5537c478bd9Sstevel@tonic-gate ulwp.ul_async_safe,
554d4204c85Sraf ulwp.ul_rt,
555d4204c85Sraf ulwp.ul_rtqueued);
5567c478bd9Sstevel@tonic-gate
5577c5714f6Sraf HD("misaligned adapt'spin queue_spin critical sigdefer vfork");
5587c5714f6Sraf mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n",
5597c5714f6Sraf OFFSET(ul_misaligned),
5607c5714f6Sraf ulwp.ul_misaligned,
5617c478bd9Sstevel@tonic-gate ulwp.ul_adaptive_spin,
5627c478bd9Sstevel@tonic-gate ulwp.ul_queue_spin,
5637c478bd9Sstevel@tonic-gate ulwp.ul_critical,
5647c478bd9Sstevel@tonic-gate ulwp.ul_sigdefer,
5657c478bd9Sstevel@tonic-gate ulwp.ul_vfork);
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate HD("cancelable c'pending c'disabled c'async save_async mutator");
5687c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n",
5697c478bd9Sstevel@tonic-gate OFFSET(ul_cancelable),
5707c478bd9Sstevel@tonic-gate ulwp.ul_cancelable,
5717c478bd9Sstevel@tonic-gate ulwp.ul_cancel_pending,
5727c478bd9Sstevel@tonic-gate ulwp.ul_cancel_disabled,
5737c478bd9Sstevel@tonic-gate ulwp.ul_cancel_async,
5747c478bd9Sstevel@tonic-gate ulwp.ul_save_async,
5757c478bd9Sstevel@tonic-gate ulwp.ul_mutator);
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate HD("created replace nocancel errno errnop");
5787c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n",
5797c478bd9Sstevel@tonic-gate OFFSET(ul_created),
5807c478bd9Sstevel@tonic-gate ulwp.ul_created,
5817c478bd9Sstevel@tonic-gate ulwp.ul_replace,
5827c478bd9Sstevel@tonic-gate ulwp.ul_nocancel,
5837c478bd9Sstevel@tonic-gate ulwp.ul_errno,
5847c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_errnop, 0));
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate HD("clnup_hdr schedctl_called schedctl");
5877c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
5887c478bd9Sstevel@tonic-gate OFFSET(ul_clnup_hdr),
5897c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_clnup_hdr, 1),
5907c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_schedctl_called, 1),
5917c478bd9Sstevel@tonic-gate prt_addr((void *)ulwp.ul_schedctl, 0));
5927c478bd9Sstevel@tonic-gate
593a574db85Sraf HD("bindflags libc_locks stsd &ftsd");
5947c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR,
5957c478bd9Sstevel@tonic-gate OFFSET(ul_bindflags));
5967c478bd9Sstevel@tonic-gate mdb_printf(ulwp.ul_bindflags? "0x%-8x " : "%-10d ",
5977c478bd9Sstevel@tonic-gate ulwp.ul_bindflags);
598a574db85Sraf mdb_printf("%-10d ", ulwp.ul_libc_locks);
5997c478bd9Sstevel@tonic-gate mdb_printf("%s %s\n",
6007c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_stsd, 1),
6017c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_ftsd[0])), 0));
6027c478bd9Sstevel@tonic-gate
6037c478bd9Sstevel@tonic-gate HD("eventmask[0..1] eventnum eventdata");
6047c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %-21d %s\n",
6057c478bd9Sstevel@tonic-gate OFFSET(ul_td_evbuf.eventmask.event_bits[0]),
6067c478bd9Sstevel@tonic-gate ulwp.ul_td_evbuf.eventmask.event_bits[0],
6077c478bd9Sstevel@tonic-gate ulwp.ul_td_evbuf.eventmask.event_bits[1],
6087c478bd9Sstevel@tonic-gate ulwp.ul_td_evbuf.eventnum,
6097c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_td_evbuf.eventdata, 0));
6107c478bd9Sstevel@tonic-gate
611e54ab87fSRoger A. Faulkner HD("td'enable sync'reg qtype cv_wake rtld usropts");
612e54ab87fSRoger A. Faulkner mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d ",
6137c478bd9Sstevel@tonic-gate OFFSET(ul_td_events_enable),
6147c478bd9Sstevel@tonic-gate ulwp.ul_td_events_enable,
6157c478bd9Sstevel@tonic-gate ulwp.ul_sync_obj_reg,
6167c478bd9Sstevel@tonic-gate ulwp.ul_qtype,
617e54ab87fSRoger A. Faulkner ulwp.ul_cv_wake,
618e54ab87fSRoger A. Faulkner ulwp.ul_rtld);
6197c478bd9Sstevel@tonic-gate mdb_printf(ulwp.ul_usropts? "0x%x\n" : "%d\n",
6207c478bd9Sstevel@tonic-gate ulwp.ul_usropts);
6217c478bd9Sstevel@tonic-gate
6227c478bd9Sstevel@tonic-gate HD("startpc startarg wchan");
6237c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
6247c478bd9Sstevel@tonic-gate OFFSET(ul_startpc),
6257c478bd9Sstevel@tonic-gate prt_addr((void *)ulwp.ul_startpc, 1),
6267c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_startarg, 1),
6277c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_wchan, 0));
6287c478bd9Sstevel@tonic-gate
6297c478bd9Sstevel@tonic-gate HD("link sleepq cvmutex");
6307c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
6317c478bd9Sstevel@tonic-gate OFFSET(ul_link),
6327c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_link, 1),
6337c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_sleepq, 1),
6347c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_cvmutex, 0));
6357c478bd9Sstevel@tonic-gate
636d4204c85Sraf HD("mxchain save_state");
637d4204c85Sraf mdb_printf(OFFSTR "%s %d\n",
6387c478bd9Sstevel@tonic-gate OFFSET(ul_mxchain),
6397c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_mxchain, 1),
640d4204c85Sraf ulwp.ul_save_state);
6417c478bd9Sstevel@tonic-gate
642883492d5Sraf HD("rdlockcnt rd_rwlock rd_count");
643883492d5Sraf mdb_printf(OFFSTR "%-21d %s %d\n",
644883492d5Sraf OFFSET(ul_rdlockcnt),
645883492d5Sraf ulwp.ul_rdlockcnt,
6467c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_readlock.single.rd_rwlock, 1),
647883492d5Sraf ulwp.ul_readlock.single.rd_count);
648883492d5Sraf
649883492d5Sraf HD("heldlockcnt heldlocks tpdp");
650883492d5Sraf mdb_printf(OFFSTR "%-21d %s %s\n",
651883492d5Sraf OFFSET(ul_heldlockcnt),
652883492d5Sraf ulwp.ul_heldlockcnt,
653883492d5Sraf prt_addr(ulwp.ul_heldlocks.single, 1),
6547c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_tpdp, 0));
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate HD("siglink s'l'spin s'l'spin2 s'l'sleep s'l'wakeup");
657d4204c85Sraf mdb_printf(OFFSTR "%s %-10d %-10d %-10d %d\n",
6587c478bd9Sstevel@tonic-gate OFFSET(ul_siglink),
6597c478bd9Sstevel@tonic-gate prt_addr(ulwp.ul_siglink, 1),
6607c478bd9Sstevel@tonic-gate ulwp.ul_spin_lock_spin,
6617c478bd9Sstevel@tonic-gate ulwp.ul_spin_lock_spin2,
6627c478bd9Sstevel@tonic-gate ulwp.ul_spin_lock_sleep,
6637c478bd9Sstevel@tonic-gate ulwp.ul_spin_lock_wakeup);
6647c478bd9Sstevel@tonic-gate
665d4204c85Sraf HD("&queue_root rtclassid pilocks");
666d4204c85Sraf mdb_printf(OFFSTR "%s %-10d %d\n",
667d4204c85Sraf OFFSET(ul_queue_root),
668d4204c85Sraf prt_addr((void *)(addr + OFFSET(ul_queue_root)), 1),
669d4204c85Sraf ulwp.ul_rtclassid,
670d4204c85Sraf ulwp.ul_pilocks);
671d4204c85Sraf
6727c478bd9Sstevel@tonic-gate /*
6737c478bd9Sstevel@tonic-gate * The remainder of the ulwp_t structure
6747c478bd9Sstevel@tonic-gate * is invalid if this is a replacement.
6757c478bd9Sstevel@tonic-gate */
6767c478bd9Sstevel@tonic-gate if (ulwp.ul_replace)
6777c478bd9Sstevel@tonic-gate return (DCMD_OK);
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate HD("sigmask[0..3]");
6807c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n",
6817c478bd9Sstevel@tonic-gate OFFSET(ul_sigmask.__sigbits[0]),
6827c478bd9Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[0],
6837c478bd9Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[1],
6847c478bd9Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[2],
6857c478bd9Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[3]);
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate HD("tmpmask[0..3]");
6887c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n",
6897c478bd9Sstevel@tonic-gate OFFSET(ul_tmpmask.__sigbits[0]),
6907c478bd9Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[0],
6917c478bd9Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[1],
6927c478bd9Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[2],
6937c478bd9Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[3]);
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate HD("&siginfo &spinlock &fpuenv");
6967c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
6977c478bd9Sstevel@tonic-gate OFFSET(ul_siginfo),
6987c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_siginfo)), 1),
6997c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_spinlock)), 1),
7007c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_fpuenv)), 0));
7017c478bd9Sstevel@tonic-gate
7023e3d658fSRobert Mustacchi HD("tmem.size &tmem.roots");
7033e3d658fSRobert Mustacchi mdb_printf(OFFSTR "%-21H %s\n",
7043e3d658fSRobert Mustacchi OFFSET(ul_tmem),
7053e3d658fSRobert Mustacchi ulwp.ul_tmem.tm_size,
7063e3d658fSRobert Mustacchi prt_addr((void *)(addr + OFFSET(ul_tmem) + sizeof (size_t)), 0));
7073e3d658fSRobert Mustacchi
7087c478bd9Sstevel@tonic-gate return (DCMD_OK);
7097c478bd9Sstevel@tonic-gate }
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate /*
7127c478bd9Sstevel@tonic-gate * Get the address of the unique uberdata_t structure.
7137c478bd9Sstevel@tonic-gate */
7147c478bd9Sstevel@tonic-gate static uintptr_t
uberdata_addr(void)7157c478bd9Sstevel@tonic-gate uberdata_addr(void)
7167c478bd9Sstevel@tonic-gate {
7177c478bd9Sstevel@tonic-gate uintptr_t uaddr;
7187c478bd9Sstevel@tonic-gate uintptr_t addr;
7197c478bd9Sstevel@tonic-gate GElf_Sym sym;
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_tdb_bootstrap", &sym) != 0) {
7227c478bd9Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_tdb_bootstrap");
7237c478bd9Sstevel@tonic-gate return (NULL);
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate if (mdb_vread(&addr, sizeof (addr), sym.st_value) == sizeof (addr) &&
7267c478bd9Sstevel@tonic-gate addr != NULL &&
7277c478bd9Sstevel@tonic-gate mdb_vread(&uaddr, sizeof (uaddr), addr) == sizeof (uaddr) &&
7287c478bd9Sstevel@tonic-gate uaddr != NULL) {
7297c478bd9Sstevel@tonic-gate return (uaddr);
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_uberdata", &sym) != 0) {
7327c478bd9Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_uberdata");
7337c478bd9Sstevel@tonic-gate return (NULL);
7347c478bd9Sstevel@tonic-gate }
7357c478bd9Sstevel@tonic-gate return ((uintptr_t)sym.st_value);
7367c478bd9Sstevel@tonic-gate }
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate #undef OFFSET
7397c478bd9Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(uberdata_t, member))
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7427c478bd9Sstevel@tonic-gate static int
d_uberdata(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)7437c478bd9Sstevel@tonic-gate d_uberdata(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7447c478bd9Sstevel@tonic-gate {
7457c478bd9Sstevel@tonic-gate uberdata_t uberdata;
7467c478bd9Sstevel@tonic-gate int i;
7477c478bd9Sstevel@tonic-gate
7487c478bd9Sstevel@tonic-gate if (argc != 0)
7497c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
7507c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) && (addr = uberdata_addr()) == NULL)
7517c478bd9Sstevel@tonic-gate return (DCMD_ERR);
7527c478bd9Sstevel@tonic-gate
7537c478bd9Sstevel@tonic-gate if (mdb_vread(&uberdata, sizeof (uberdata), addr) !=
7547c478bd9Sstevel@tonic-gate sizeof (uberdata)) {
7557c478bd9Sstevel@tonic-gate mdb_warn("failed to read uberdata at 0x%p", addr);
7567c478bd9Sstevel@tonic-gate return (DCMD_ERR);
7577c478bd9Sstevel@tonic-gate }
7587c478bd9Sstevel@tonic-gate
7597c478bd9Sstevel@tonic-gate mdb_printf("%#a\n", addr);
7607c478bd9Sstevel@tonic-gate
7618cd45542Sraf HD("&link_lock &ld_lock &fork_lock");
7627c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
7637c478bd9Sstevel@tonic-gate OFFSET(link_lock),
7647c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(link_lock)), 1),
7658cd45542Sraf prt_addr((void *)(addr + OFFSET(ld_lock)), 1),
7668cd45542Sraf prt_addr((void *)(addr + OFFSET(fork_lock)), 0));
7677c478bd9Sstevel@tonic-gate
7688cd45542Sraf HD("&atfork_lock &callout_lock &tdb_hash_lock");
7697c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
7708cd45542Sraf OFFSET(atfork_lock),
7718cd45542Sraf prt_addr((void *)(addr + OFFSET(atfork_lock)), 1),
77298c1a6b4Sraf prt_addr((void *)(addr + OFFSET(callout_lock)), 1),
7738cd45542Sraf prt_addr((void *)(addr + OFFSET(tdb_hash_lock)), 0));
7748cd45542Sraf
7758cd45542Sraf HD("&tdb_hash_lock_stats &siguaction[0]");
7768cd45542Sraf mdb_printf(OFFSTR "%s %s\n",
7778cd45542Sraf OFFSET(tdb_hash_lock_stats),
7788cd45542Sraf prt_addr((void *)(addr + OFFSET(tdb_hash_lock_stats)), 1),
7797c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(siguaction)), 0));
7807c478bd9Sstevel@tonic-gate
7817c478bd9Sstevel@tonic-gate HD("&bucket free_list chunks");
7827c478bd9Sstevel@tonic-gate for (i = 0; i < NBUCKETS; i++) {
7837c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n",
7847c478bd9Sstevel@tonic-gate OFFSET(bucket[i]),
7857c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(bucket[i])), 1),
7867c478bd9Sstevel@tonic-gate prt_addr(uberdata.bucket[i].free_list, 1),
7877c478bd9Sstevel@tonic-gate uberdata.bucket[i].chunks);
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate HD("&atexit_root head exit_frame_monitor");
7917c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
7927c478bd9Sstevel@tonic-gate OFFSET(atexit_root),
7937c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(atexit_root.exitfns_lock)), 1),
7947c478bd9Sstevel@tonic-gate prt_addr(uberdata.atexit_root.head, 1),
7957c478bd9Sstevel@tonic-gate prt_addr(uberdata.atexit_root.exit_frame_monitor, 0));
7967c478bd9Sstevel@tonic-gate
7977c478bd9Sstevel@tonic-gate HD("&tsd_metadata tsdm_nkeys tsdm_nused tsdm_destro");
7987c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %s\n",
7997c478bd9Sstevel@tonic-gate OFFSET(tsd_metadata),
8007c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tsd_metadata.tsdm_lock)), 1),
8017c478bd9Sstevel@tonic-gate uberdata.tsd_metadata.tsdm_nkeys,
8027c478bd9Sstevel@tonic-gate uberdata.tsd_metadata.tsdm_nused,
8037c478bd9Sstevel@tonic-gate prt_addr((void *)uberdata.tsd_metadata.tsdm_destro, 0));
8047c478bd9Sstevel@tonic-gate
8057c478bd9Sstevel@tonic-gate HD("&tls_metadata tls_modinfo.data tls_modinfo.size");
8067c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n",
8077c478bd9Sstevel@tonic-gate OFFSET(tls_metadata),
8087c478bd9Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tls_metadata.tls_lock)), 1),
8097c478bd9Sstevel@tonic-gate prt_addr(uberdata.tls_metadata.tls_modinfo.tls_data, 1),
8107c478bd9Sstevel@tonic-gate uberdata.tls_metadata.tls_modinfo.tls_size);
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate HD(" static_tls.data static_tls.size");
8137c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n",
8147c478bd9Sstevel@tonic-gate OFFSET(tls_metadata.static_tls),
8157c478bd9Sstevel@tonic-gate " ",
8167c478bd9Sstevel@tonic-gate prt_addr(uberdata.tls_metadata.static_tls.tls_data, 1),
8177c478bd9Sstevel@tonic-gate uberdata.tls_metadata.static_tls.tls_size);
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate HD("primary_ma bucket_ini uflags.mt uflags.pad uflags.trs uflags.ted");
8207c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n",
8217c478bd9Sstevel@tonic-gate OFFSET(primary_map),
8227c478bd9Sstevel@tonic-gate uberdata.primary_map,
8237c478bd9Sstevel@tonic-gate uberdata.bucket_init,
8247c478bd9Sstevel@tonic-gate uberdata.uberflags.uf_x.x_mt,
8257c478bd9Sstevel@tonic-gate uberdata.uberflags.uf_x.x_pad,
8267c478bd9Sstevel@tonic-gate uberdata.uberflags.uf_x.x_tdb_register_sync,
8277c478bd9Sstevel@tonic-gate uberdata.uberflags.uf_x.x_thread_error_detection);
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate HD("queue_head thr_hash_table hash_size hash_mask");
8307c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d 0x%x\n",
8317c478bd9Sstevel@tonic-gate OFFSET(queue_head),
8327c478bd9Sstevel@tonic-gate prt_addr(uberdata.queue_head, 1),
8337c478bd9Sstevel@tonic-gate prt_addr(uberdata.thr_hash_table, 1),
8347c478bd9Sstevel@tonic-gate uberdata.hash_size,
8357c478bd9Sstevel@tonic-gate uberdata.hash_mask);
8367c478bd9Sstevel@tonic-gate
8377c478bd9Sstevel@tonic-gate HD("ulwp_one all_lwps all_zombies");
8387c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n",
8397c478bd9Sstevel@tonic-gate OFFSET(ulwp_one),
8407c478bd9Sstevel@tonic-gate prt_addr(uberdata.ulwp_one, 1),
8417c478bd9Sstevel@tonic-gate prt_addr(uberdata.all_lwps, 1),
8427c478bd9Sstevel@tonic-gate prt_addr(uberdata.all_zombies, 0));
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate HD("nthreads nzombies ndaemons pid sigacthandler");
8457c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n",
8467c478bd9Sstevel@tonic-gate OFFSET(nthreads),
8477c478bd9Sstevel@tonic-gate uberdata.nthreads,
8487c478bd9Sstevel@tonic-gate uberdata.nzombies,
8497c478bd9Sstevel@tonic-gate uberdata.ndaemons,
8507c478bd9Sstevel@tonic-gate (int)uberdata.pid,
8517c478bd9Sstevel@tonic-gate prt_addr((void *)uberdata.sigacthandler, 0));
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate HD("lwp_stacks lwp_laststack nfreestack stk_cache");
8547c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n",
8557c478bd9Sstevel@tonic-gate OFFSET(lwp_stacks),
8567c478bd9Sstevel@tonic-gate prt_addr(uberdata.lwp_stacks, 1),
8577c478bd9Sstevel@tonic-gate prt_addr(uberdata.lwp_laststack, 1),
8587c478bd9Sstevel@tonic-gate uberdata.nfreestack,
8597c478bd9Sstevel@tonic-gate uberdata.thread_stack_cache);
8607c478bd9Sstevel@tonic-gate
8618cd45542Sraf HD("ulwp_freelist ulwp_lastfree ulwp_replace_free");
8628cd45542Sraf mdb_printf(OFFSTR "%s %s %s\n",
8637c478bd9Sstevel@tonic-gate OFFSET(ulwp_freelist),
8647c478bd9Sstevel@tonic-gate prt_addr(uberdata.ulwp_freelist, 1),
8658cd45542Sraf prt_addr(uberdata.ulwp_lastfree, 1),
8668cd45542Sraf prt_addr(uberdata.ulwp_replace_free, 0));
8677c478bd9Sstevel@tonic-gate
86809ce0d4aSRoger A. Faulkner HD("ulwp_replace_last atforklist");
86909ce0d4aSRoger A. Faulkner mdb_printf(OFFSTR "%s %s\n",
8708cd45542Sraf OFFSET(ulwp_replace_last),
8718cd45542Sraf prt_addr(uberdata.ulwp_replace_last, 1),
87209ce0d4aSRoger A. Faulkner prt_addr(uberdata.atforklist, 0));
87309ce0d4aSRoger A. Faulkner
87423a1cceaSRoger A. Faulkner HD("robustlocks robustlist progname");
87523a1cceaSRoger A. Faulkner mdb_printf(OFFSTR "%s %s %s\n",
87609ce0d4aSRoger A. Faulkner OFFSET(robustlocks),
87709ce0d4aSRoger A. Faulkner prt_addr(uberdata.robustlocks, 1),
87823a1cceaSRoger A. Faulkner prt_addr(uberdata.robustlist, 1),
87923a1cceaSRoger A. Faulkner prt_addr(uberdata.progname, 0));
8807c478bd9Sstevel@tonic-gate
8817c478bd9Sstevel@tonic-gate HD("tdb_bootstrap tdb_sync_addr_hash tdb_'count tdb_'fail");
8827c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n",
8837c478bd9Sstevel@tonic-gate OFFSET(tdb_bootstrap),
8847c478bd9Sstevel@tonic-gate prt_addr(uberdata.tdb_bootstrap, 1),
8857c478bd9Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_hash, 1),
8867c478bd9Sstevel@tonic-gate uberdata.tdb.tdb_register_count,
8877c478bd9Sstevel@tonic-gate uberdata.tdb.tdb_hash_alloc_failed);
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate HD("tdb_sync_addr_free tdb_sync_addr_last tdb_sync_alloc");
8907c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n",
8917c478bd9Sstevel@tonic-gate OFFSET(tdb.tdb_sync_addr_free),
8927c478bd9Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_free, 1),
8937c478bd9Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_last, 1),
8947c478bd9Sstevel@tonic-gate uberdata.tdb.tdb_sync_alloc);
8957c478bd9Sstevel@tonic-gate
8967c478bd9Sstevel@tonic-gate HD("tdb_ev_global_mask tdb_events");
8977c478bd9Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %s\n",
8987c478bd9Sstevel@tonic-gate OFFSET(tdb.tdb_ev_global_mask),
8997c478bd9Sstevel@tonic-gate uberdata.tdb.tdb_ev_global_mask.event_bits[0],
9007c478bd9Sstevel@tonic-gate uberdata.tdb.tdb_ev_global_mask.event_bits[1],
9017c478bd9Sstevel@tonic-gate prt_addr((void *)uberdata.tdb.tdb_events, 0));
9027c478bd9Sstevel@tonic-gate
9037c478bd9Sstevel@tonic-gate return (DCMD_OK);
9047c478bd9Sstevel@tonic-gate }
9057c478bd9Sstevel@tonic-gate
9067c478bd9Sstevel@tonic-gate static int
ulwp_walk_init(mdb_walk_state_t * wsp)9077c478bd9Sstevel@tonic-gate ulwp_walk_init(mdb_walk_state_t *wsp)
9087c478bd9Sstevel@tonic-gate {
9097c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr;
9107c478bd9Sstevel@tonic-gate uintptr_t uber_addr;
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate if (addr == NULL &&
9137c478bd9Sstevel@tonic-gate ((uber_addr = uberdata_addr()) == NULL ||
9147c478bd9Sstevel@tonic-gate mdb_vread(&addr, sizeof (addr),
9157c478bd9Sstevel@tonic-gate uber_addr + OFFSETOF(uberdata_t, all_lwps))
9167c478bd9Sstevel@tonic-gate != sizeof (addr))) {
9177c478bd9Sstevel@tonic-gate mdb_warn("cannot find 'uberdata.all_lwps'");
9187c478bd9Sstevel@tonic-gate return (WALK_ERR);
9197c478bd9Sstevel@tonic-gate }
9207c478bd9Sstevel@tonic-gate if (addr == NULL)
9217c478bd9Sstevel@tonic-gate return (WALK_DONE);
9227c478bd9Sstevel@tonic-gate wsp->walk_addr = addr;
9237c478bd9Sstevel@tonic-gate wsp->walk_data = (void *)addr;
9247c478bd9Sstevel@tonic-gate return (WALK_NEXT);
9257c478bd9Sstevel@tonic-gate }
9267c478bd9Sstevel@tonic-gate
9277c478bd9Sstevel@tonic-gate static int
ulwp_walk_step(mdb_walk_state_t * wsp)9287c478bd9Sstevel@tonic-gate ulwp_walk_step(mdb_walk_state_t *wsp)
9297c478bd9Sstevel@tonic-gate {
9307c478bd9Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr;
9317c478bd9Sstevel@tonic-gate ulwp_t ulwp;
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate if (addr == NULL)
9347c478bd9Sstevel@tonic-gate return (WALK_DONE);
9357c478bd9Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) &&
9367c478bd9Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)),
9377c478bd9Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) {
9387c478bd9Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr);
9397c478bd9Sstevel@tonic-gate return (WALK_ERR);
9407c478bd9Sstevel@tonic-gate }
9417c478bd9Sstevel@tonic-gate /*
9427c478bd9Sstevel@tonic-gate * If we have looped around to the beginning
9437c478bd9Sstevel@tonic-gate * of the circular linked list, we are done.
9447c478bd9Sstevel@tonic-gate */
9457c478bd9Sstevel@tonic-gate if ((wsp->walk_addr = (uintptr_t)ulwp.ul_forw)
9467c478bd9Sstevel@tonic-gate == (uintptr_t)wsp->walk_data)
9477c478bd9Sstevel@tonic-gate wsp->walk_addr = NULL;
9487c478bd9Sstevel@tonic-gate return (wsp->walk_callback(addr, &ulwp, wsp->walk_cbdata));
9497c478bd9Sstevel@tonic-gate }
9507c478bd9Sstevel@tonic-gate
9514a1c2431SJonathan Adams /* Avoid classifying NULL pointers as part of the main stack on x86 */
9524a1c2431SJonathan Adams #define MIN_STACK_ADDR (0x10000ul)
9534a1c2431SJonathan Adams
9544a1c2431SJonathan Adams static int
whatis_walk_ulwp(uintptr_t addr,const ulwp_t * ulwp,mdb_whatis_t * w)9554a1c2431SJonathan Adams whatis_walk_ulwp(uintptr_t addr, const ulwp_t *ulwp, mdb_whatis_t *w)
9564a1c2431SJonathan Adams {
9574a1c2431SJonathan Adams uintptr_t cur;
9584a1c2431SJonathan Adams lwpid_t id = ulwp->ul_lwpid;
9594a1c2431SJonathan Adams uintptr_t top, base, size;
9604a1c2431SJonathan Adams
9614a1c2431SJonathan Adams while (mdb_whatis_match(w, addr, sizeof (ulwp_t), &cur))
9624a1c2431SJonathan Adams mdb_whatis_report_object(w, cur, addr,
9634a1c2431SJonathan Adams "allocated as thread %#r's ulwp_t\n", id);
9644a1c2431SJonathan Adams
9654a1c2431SJonathan Adams top = (uintptr_t)ulwp->ul_stktop;
9664a1c2431SJonathan Adams size = ulwp->ul_stksiz;
9674a1c2431SJonathan Adams
9684a1c2431SJonathan Adams /*
9694a1c2431SJonathan Adams * The main stack ends up being a little weird, especially if
9704a1c2431SJonathan Adams * the stack ulimit is unlimited. This tries to take that into
9714a1c2431SJonathan Adams * account.
9724a1c2431SJonathan Adams */
9734a1c2431SJonathan Adams if (size > top)
9744a1c2431SJonathan Adams size = top;
9754a1c2431SJonathan Adams if (top > MIN_STACK_ADDR && top - size < MIN_STACK_ADDR)
9764a1c2431SJonathan Adams size = top - MIN_STACK_ADDR;
9774a1c2431SJonathan Adams
9784a1c2431SJonathan Adams base = top - size;
9794a1c2431SJonathan Adams
9804a1c2431SJonathan Adams while (mdb_whatis_match(w, base, size, &cur))
9814a1c2431SJonathan Adams mdb_whatis_report_address(w, cur, "in [ stack tid=%#r ]\n", id);
9824a1c2431SJonathan Adams
9834a1c2431SJonathan Adams if (ulwp->ul_ustack.ss_flags & SS_ONSTACK) {
9844a1c2431SJonathan Adams base = (uintptr_t)ulwp->ul_ustack.ss_sp;
9854a1c2431SJonathan Adams size = ulwp->ul_ustack.ss_size;
9864a1c2431SJonathan Adams
9874a1c2431SJonathan Adams while (mdb_whatis_match(w, base, size, &cur))
9884a1c2431SJonathan Adams mdb_whatis_report_address(w, cur,
9894a1c2431SJonathan Adams "in [ altstack tid=%#r ]\n", id);
9904a1c2431SJonathan Adams }
9914a1c2431SJonathan Adams
9924a1c2431SJonathan Adams return (WHATIS_WALKRET(w));
9934a1c2431SJonathan Adams }
9944a1c2431SJonathan Adams
9954a1c2431SJonathan Adams /*ARGSUSED*/
9964a1c2431SJonathan Adams static int
whatis_run_ulwps(mdb_whatis_t * w,void * arg)9974a1c2431SJonathan Adams whatis_run_ulwps(mdb_whatis_t *w, void *arg)
9984a1c2431SJonathan Adams {
9994a1c2431SJonathan Adams if (mdb_walk("ulwps", (mdb_walk_cb_t)whatis_walk_ulwp, w) == -1) {
10004a1c2431SJonathan Adams mdb_warn("couldn't find ulwps walker");
10014a1c2431SJonathan Adams return (1);
10024a1c2431SJonathan Adams }
10034a1c2431SJonathan Adams return (0);
10044a1c2431SJonathan Adams }
10054a1c2431SJonathan Adams
10067c478bd9Sstevel@tonic-gate /*
10077c478bd9Sstevel@tonic-gate * =======================================================
10087c478bd9Sstevel@tonic-gate * End of thread (previously libthread) interfaces.
10097c478bd9Sstevel@tonic-gate * ==================== threads ==========================
10107c478bd9Sstevel@tonic-gate */
10117c478bd9Sstevel@tonic-gate
1012c9a6ea2eSBryan Cantrill int
stacks_dcmd(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1013c9a6ea2eSBryan Cantrill stacks_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1014c9a6ea2eSBryan Cantrill {
1015c9a6ea2eSBryan Cantrill int rval = stacks(addr, flags, argc, argv);
1016c9a6ea2eSBryan Cantrill
1017c9a6ea2eSBryan Cantrill /*
1018c9a6ea2eSBryan Cantrill * For the user-level variant of ::stacks, we don't bother caching
1019c9a6ea2eSBryan Cantrill * state, as even a very large program is unlikely to compare to the
1020c9a6ea2eSBryan Cantrill * kernel in terms of number of threads. (And if you find yourself
1021c9a6ea2eSBryan Cantrill * here in anger, frustrated about how long ::stacks is running on
1022c9a6ea2eSBryan Cantrill * your galactically complicated zillion-thread program, hopefully
1023c9a6ea2eSBryan Cantrill * you will find some solace in the irony. Okay, probably not...)
1024c9a6ea2eSBryan Cantrill */
1025c9a6ea2eSBryan Cantrill stacks_cleanup(B_TRUE);
1026c9a6ea2eSBryan Cantrill return (rval);
1027c9a6ea2eSBryan Cantrill }
1028c9a6ea2eSBryan Cantrill
1029c9a6ea2eSBryan Cantrill typedef struct tid2ulwp_walk {
1030c9a6ea2eSBryan Cantrill lwpid_t t2u_tid;
1031c9a6ea2eSBryan Cantrill uintptr_t t2u_lwp;
1032c9a6ea2eSBryan Cantrill boolean_t t2u_found;
1033c9a6ea2eSBryan Cantrill } tid2ulwp_walk_t;
1034c9a6ea2eSBryan Cantrill
1035c9a6ea2eSBryan Cantrill /*ARGSUSED*/
1036c9a6ea2eSBryan Cantrill static int
tid2ulwp_walk(uintptr_t addr,ulwp_t * ulwp,tid2ulwp_walk_t * t2u)1037c9a6ea2eSBryan Cantrill tid2ulwp_walk(uintptr_t addr, ulwp_t *ulwp, tid2ulwp_walk_t *t2u)
1038c9a6ea2eSBryan Cantrill {
1039c9a6ea2eSBryan Cantrill if (ulwp->ul_lwpid == t2u->t2u_tid) {
1040c9a6ea2eSBryan Cantrill t2u->t2u_lwp = addr;
1041c9a6ea2eSBryan Cantrill t2u->t2u_found = B_TRUE;
1042c9a6ea2eSBryan Cantrill return (WALK_DONE);
1043c9a6ea2eSBryan Cantrill }
1044c9a6ea2eSBryan Cantrill
1045c9a6ea2eSBryan Cantrill return (WALK_NEXT);
1046c9a6ea2eSBryan Cantrill }
1047c9a6ea2eSBryan Cantrill
1048c9a6ea2eSBryan Cantrill static int
tid2ulwp_impl(uintptr_t tid_addr,uintptr_t * ulwp_addrp)104928e4da25SMatthew Ahrens tid2ulwp_impl(uintptr_t tid_addr, uintptr_t *ulwp_addrp)
1050c9a6ea2eSBryan Cantrill {
1051c9a6ea2eSBryan Cantrill tid2ulwp_walk_t t2u;
1052c9a6ea2eSBryan Cantrill
1053c9a6ea2eSBryan Cantrill bzero(&t2u, sizeof (t2u));
105428e4da25SMatthew Ahrens t2u.t2u_tid = (lwpid_t)tid_addr;
1055c9a6ea2eSBryan Cantrill
1056c9a6ea2eSBryan Cantrill if (mdb_walk("ulwp", (mdb_walk_cb_t)tid2ulwp_walk, &t2u) != 0) {
1057c9a6ea2eSBryan Cantrill mdb_warn("can't walk 'ulwp'");
1058c9a6ea2eSBryan Cantrill return (DCMD_ERR);
1059c9a6ea2eSBryan Cantrill }
1060c9a6ea2eSBryan Cantrill
1061c9a6ea2eSBryan Cantrill if (!t2u.t2u_found) {
1062c9a6ea2eSBryan Cantrill mdb_warn("thread ID %d not found", t2u.t2u_tid);
1063c9a6ea2eSBryan Cantrill return (DCMD_ERR);
1064c9a6ea2eSBryan Cantrill }
106528e4da25SMatthew Ahrens *ulwp_addrp = t2u.t2u_lwp;
106628e4da25SMatthew Ahrens return (DCMD_OK);
106728e4da25SMatthew Ahrens }
1068c9a6ea2eSBryan Cantrill
106928e4da25SMatthew Ahrens /*ARGSUSED*/
107028e4da25SMatthew Ahrens static int
tid2ulwp(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)107128e4da25SMatthew Ahrens tid2ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
107228e4da25SMatthew Ahrens {
107328e4da25SMatthew Ahrens uintptr_t ulwp_addr;
107428e4da25SMatthew Ahrens int error;
1075c9a6ea2eSBryan Cantrill
107628e4da25SMatthew Ahrens if (argc != 0)
107728e4da25SMatthew Ahrens return (DCMD_USAGE);
107828e4da25SMatthew Ahrens
107928e4da25SMatthew Ahrens error = tid2ulwp_impl(addr, &ulwp_addr);
108028e4da25SMatthew Ahrens if (error == DCMD_OK)
108128e4da25SMatthew Ahrens mdb_printf("%p\n", ulwp_addr);
108228e4da25SMatthew Ahrens return (error);
108328e4da25SMatthew Ahrens }
108428e4da25SMatthew Ahrens
108528e4da25SMatthew Ahrens typedef struct mdb_libc_ulwp {
108628e4da25SMatthew Ahrens void *ul_ftsd[TSD_NFAST];
108728e4da25SMatthew Ahrens tsd_t *ul_stsd;
108828e4da25SMatthew Ahrens } mdb_libc_ulwp_t;
108928e4da25SMatthew Ahrens
109028e4da25SMatthew Ahrens /*
109128e4da25SMatthew Ahrens * Map from thread pointer to tsd for given key
109228e4da25SMatthew Ahrens */
109328e4da25SMatthew Ahrens static int
d_tsd(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)109428e4da25SMatthew Ahrens d_tsd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
109528e4da25SMatthew Ahrens {
109628e4da25SMatthew Ahrens mdb_libc_ulwp_t u;
109728e4da25SMatthew Ahrens uintptr_t ulwp_addr;
109828e4da25SMatthew Ahrens uintptr_t key = NULL;
109928e4da25SMatthew Ahrens void *element = NULL;
110028e4da25SMatthew Ahrens
110128e4da25SMatthew Ahrens if (mdb_getopts(argc, argv, 'k', MDB_OPT_UINTPTR, &key, NULL) != argc)
110228e4da25SMatthew Ahrens return (DCMD_USAGE);
110328e4da25SMatthew Ahrens
110428e4da25SMatthew Ahrens if (!(flags & DCMD_ADDRSPEC) || key == NULL)
110528e4da25SMatthew Ahrens return (DCMD_USAGE);
110628e4da25SMatthew Ahrens
110728e4da25SMatthew Ahrens if (tid2ulwp_impl(addr, &ulwp_addr) != DCMD_OK)
110828e4da25SMatthew Ahrens return (DCMD_ERR);
110928e4da25SMatthew Ahrens
111028e4da25SMatthew Ahrens if (mdb_ctf_vread(&u, "ulwp_t", "mdb_libc_ulwp_t", ulwp_addr, 0) == -1)
111128e4da25SMatthew Ahrens return (DCMD_ERR);
111228e4da25SMatthew Ahrens
111328e4da25SMatthew Ahrens if (key < TSD_NFAST) {
111428e4da25SMatthew Ahrens element = u.ul_ftsd[key];
111528e4da25SMatthew Ahrens } else if (u.ul_stsd != NULL) {
111628e4da25SMatthew Ahrens uint_t nalloc;
111728e4da25SMatthew Ahrens /* tsd_t is a union, so we can't use ctf_vread() on it. */
111828e4da25SMatthew Ahrens if (mdb_vread(&nalloc, sizeof (nalloc),
111928e4da25SMatthew Ahrens (uintptr_t)&u.ul_stsd->tsd_nalloc) == -1) {
112028e4da25SMatthew Ahrens mdb_warn("failed to read tsd_t at %p", u.ul_stsd);
112128e4da25SMatthew Ahrens return (DCMD_ERR);
112228e4da25SMatthew Ahrens }
112328e4da25SMatthew Ahrens if (key < nalloc) {
112428e4da25SMatthew Ahrens if (mdb_vread(&element, sizeof (element),
112528e4da25SMatthew Ahrens (uintptr_t)&u.ul_stsd->tsd_data[key]) == -1) {
112628e4da25SMatthew Ahrens mdb_warn("failed to read tsd_t at %p",
112728e4da25SMatthew Ahrens u.ul_stsd);
112828e4da25SMatthew Ahrens return (DCMD_ERR);
112928e4da25SMatthew Ahrens }
113028e4da25SMatthew Ahrens }
113128e4da25SMatthew Ahrens }
113228e4da25SMatthew Ahrens
113328e4da25SMatthew Ahrens if (element == NULL && (flags & DCMD_PIPE))
113428e4da25SMatthew Ahrens return (DCMD_OK);
113528e4da25SMatthew Ahrens
113628e4da25SMatthew Ahrens mdb_printf("%p\n", element);
1137c9a6ea2eSBryan Cantrill return (DCMD_OK);
1138c9a6ea2eSBryan Cantrill }
1139c9a6ea2eSBryan Cantrill
11407c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
11417c478bd9Sstevel@tonic-gate { "jmp_buf", ":", "print jmp_buf contents", d_jmp_buf, NULL },
11427c478bd9Sstevel@tonic-gate { "sigjmp_buf", ":", "print sigjmp_buf contents", d_sigjmp_buf, NULL },
11437c478bd9Sstevel@tonic-gate { "siginfo", ":", "print siginfo_t structure", d_siginfo, NULL },
1144c9a6ea2eSBryan Cantrill { "stacks", "?[-afiv] [-c func] [-C func] [-m module] [-M module] ",
1145c9a6ea2eSBryan Cantrill "print unique thread stacks", stacks_dcmd, stacks_help },
1146c9a6ea2eSBryan Cantrill { "tid2ulwp", "?", "convert TID to ulwp_t address", tid2ulwp },
11477c478bd9Sstevel@tonic-gate { "ucontext", ":", "print ucontext_t structure", d_ucontext, NULL },
11487c478bd9Sstevel@tonic-gate { "ulwp", ":", "print ulwp_t structure", d_ulwp, NULL },
11497c478bd9Sstevel@tonic-gate { "uberdata", ":", "print uberdata_t structure", d_uberdata, NULL },
115028e4da25SMatthew Ahrens { "tsd", ":-k key", "print tsd for this thread", d_tsd, NULL },
11517c478bd9Sstevel@tonic-gate { NULL }
11527c478bd9Sstevel@tonic-gate };
11537c478bd9Sstevel@tonic-gate
11547c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
11557c478bd9Sstevel@tonic-gate { "ucontext", "walk ucontext_t uc_link list",
11567c478bd9Sstevel@tonic-gate NULL, uc_walk_step, NULL, NULL },
11577c478bd9Sstevel@tonic-gate { "oldcontext", "walk per-lwp oldcontext pointers",
11587c478bd9Sstevel@tonic-gate oldc_walk_init, oldc_walk_step, oldc_walk_fini, NULL },
11597c478bd9Sstevel@tonic-gate { "ulwps", "walk list of ulwp_t pointers",
11607c478bd9Sstevel@tonic-gate ulwp_walk_init, ulwp_walk_step, NULL, NULL },
1161c9a6ea2eSBryan Cantrill { "ulwp", "walk list of ulwp_t pointers",
1162c9a6ea2eSBryan Cantrill ulwp_walk_init, ulwp_walk_step, NULL, NULL },
11637c478bd9Sstevel@tonic-gate { NULL }
11647c478bd9Sstevel@tonic-gate };
11657c478bd9Sstevel@tonic-gate
11667c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
11677c478bd9Sstevel@tonic-gate
11687c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)11697c478bd9Sstevel@tonic-gate _mdb_init(void)
11707c478bd9Sstevel@tonic-gate {
11714a1c2431SJonathan Adams mdb_whatis_register("threads", whatis_run_ulwps, NULL,
11724a1c2431SJonathan Adams WHATIS_PRIO_EARLY, WHATIS_REG_NO_ID);
11734a1c2431SJonathan Adams
11747c478bd9Sstevel@tonic-gate return (&modinfo);
11757c478bd9Sstevel@tonic-gate }
1176