1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/mdb_modapi.h> 30*0Sstevel@tonic-gate #include <procfs.h> 31*0Sstevel@tonic-gate #include <ucontext.h> 32*0Sstevel@tonic-gate #include <siginfo.h> 33*0Sstevel@tonic-gate #include <signal.h> 34*0Sstevel@tonic-gate #include <setjmp.h> 35*0Sstevel@tonic-gate #include <string.h> 36*0Sstevel@tonic-gate #include <thr_uberdata.h> 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate static const char * 39*0Sstevel@tonic-gate stack_flags(const stack_t *sp) 40*0Sstevel@tonic-gate { 41*0Sstevel@tonic-gate static char buf[32]; 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate if (sp->ss_flags == 0) 44*0Sstevel@tonic-gate (void) strcpy(buf, " 0"); 45*0Sstevel@tonic-gate else if (sp->ss_flags & ~(SS_ONSTACK | SS_DISABLE)) 46*0Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buf), " 0x%x", sp->ss_flags); 47*0Sstevel@tonic-gate else { 48*0Sstevel@tonic-gate buf[0] = '\0'; 49*0Sstevel@tonic-gate if (sp->ss_flags & SS_ONSTACK) 50*0Sstevel@tonic-gate (void) strcat(buf, "|ONSTACK"); 51*0Sstevel@tonic-gate if (sp->ss_flags & SS_DISABLE) 52*0Sstevel@tonic-gate (void) strcat(buf, "|DISABLE"); 53*0Sstevel@tonic-gate } 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate return (buf + 1); 56*0Sstevel@tonic-gate } 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate /*ARGSUSED*/ 59*0Sstevel@tonic-gate static int 60*0Sstevel@tonic-gate d_jmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 61*0Sstevel@tonic-gate { 62*0Sstevel@tonic-gate jmp_buf jb; 63*0Sstevel@tonic-gate const ulong_t *b = (const ulong_t *)jb; 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate if (argc != 0) 66*0Sstevel@tonic-gate return (DCMD_USAGE); 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate if (mdb_vread(&jb, sizeof (jb), addr) != sizeof (jb)) { 69*0Sstevel@tonic-gate mdb_warn("failed to read jmp_buf at %p", addr); 70*0Sstevel@tonic-gate return (DCMD_ERR); 71*0Sstevel@tonic-gate } 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate #if defined(__sparc) 74*0Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx\n", b[1]); 75*0Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", b[2], b[2]); 76*0Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx\n", b[3]); 77*0Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", b[4], b[4]); 78*0Sstevel@tonic-gate #elif defined(__amd64) 79*0Sstevel@tonic-gate mdb_printf(" %%rbx = 0x%lx\n", b[0]); 80*0Sstevel@tonic-gate mdb_printf(" %%r12 = 0x%lx\n", b[1]); 81*0Sstevel@tonic-gate mdb_printf(" %%r13 = 0x%lx\n", b[2]); 82*0Sstevel@tonic-gate mdb_printf(" %%r14 = 0x%lx\n", b[3]); 83*0Sstevel@tonic-gate mdb_printf(" %%r15 = 0x%lx\n", b[4]); 84*0Sstevel@tonic-gate mdb_printf(" %%rbp = 0x%lx\n", b[5]); 85*0Sstevel@tonic-gate mdb_printf(" %%rsp = 0x%lx\n", b[6]); 86*0Sstevel@tonic-gate mdb_printf(" %%rip = 0x%lx %lA\n", b[7], b[7]); 87*0Sstevel@tonic-gate #elif defined(__i386) 88*0Sstevel@tonic-gate mdb_printf(" %%ebx = 0x%lx\n", b[0]); 89*0Sstevel@tonic-gate mdb_printf(" %%esi = 0x%lx\n", b[1]); 90*0Sstevel@tonic-gate mdb_printf(" %%edi = 0x%lx\n", b[2]); 91*0Sstevel@tonic-gate mdb_printf(" %%ebp = 0x%lx\n", b[3]); 92*0Sstevel@tonic-gate mdb_printf(" %%esp = 0x%lx\n", b[4]); 93*0Sstevel@tonic-gate mdb_printf(" %%eip = 0x%lx %lA\n", b[5], b[5]); 94*0Sstevel@tonic-gate #endif 95*0Sstevel@tonic-gate return (DCMD_OK); 96*0Sstevel@tonic-gate } 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate /*ARGSUSED*/ 99*0Sstevel@tonic-gate static int 100*0Sstevel@tonic-gate d_ucontext(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 101*0Sstevel@tonic-gate { 102*0Sstevel@tonic-gate ucontext_t uc; 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate if (argc != 0) 105*0Sstevel@tonic-gate return (DCMD_USAGE); 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 108*0Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 109*0Sstevel@tonic-gate return (DCMD_ERR); 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate mdb_printf(" flags = 0x%lx\n", uc.uc_flags); 113*0Sstevel@tonic-gate mdb_printf(" link = 0x%p\n", uc.uc_link); 114*0Sstevel@tonic-gate mdb_printf(" sigmask = 0x%08x 0x%08x 0x%08x 0x%08x\n", 115*0Sstevel@tonic-gate uc.uc_sigmask.__sigbits[0], uc.uc_sigmask.__sigbits[1], 116*0Sstevel@tonic-gate uc.uc_sigmask.__sigbits[2], uc.uc_sigmask.__sigbits[3]); 117*0Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n", 118*0Sstevel@tonic-gate uc.uc_stack.ss_sp, uc.uc_stack.ss_size, stack_flags(&uc.uc_stack)); 119*0Sstevel@tonic-gate mdb_printf(" mcontext = 0x%p\n", 120*0Sstevel@tonic-gate addr + OFFSETOF(ucontext_t, uc_mcontext)); 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate return (DCMD_OK); 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate /*ARGSUSED*/ 126*0Sstevel@tonic-gate static int 127*0Sstevel@tonic-gate d_sigjmp_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 128*0Sstevel@tonic-gate { 129*0Sstevel@tonic-gate #if defined(__sparc) 130*0Sstevel@tonic-gate struct { 131*0Sstevel@tonic-gate int sjs_flags; 132*0Sstevel@tonic-gate greg_t sjs_sp; 133*0Sstevel@tonic-gate greg_t sjs_pc; 134*0Sstevel@tonic-gate greg_t sjs_fp; 135*0Sstevel@tonic-gate greg_t sjs_i7; 136*0Sstevel@tonic-gate ucontext_t *sjs_uclink; 137*0Sstevel@tonic-gate ulong_t sjs_pad[_JBLEN - 6]; 138*0Sstevel@tonic-gate sigset_t sjs_sigmask; 139*0Sstevel@tonic-gate #if defined(_LP64) 140*0Sstevel@tonic-gate ulong_t sjs_pad1[2]; 141*0Sstevel@tonic-gate #endif 142*0Sstevel@tonic-gate stack_t sjs_stack; 143*0Sstevel@tonic-gate } s; 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate if (argc != 0) 146*0Sstevel@tonic-gate return (DCMD_USAGE); 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate if (mdb_vread(&s, sizeof (s), addr) != sizeof (s)) { 149*0Sstevel@tonic-gate mdb_warn("failed to read sigjmp_buf at %p", addr); 150*0Sstevel@tonic-gate return (DCMD_ERR); 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate mdb_printf(" flags = 0x%x\n", s.sjs_flags); 154*0Sstevel@tonic-gate mdb_printf(" %%sp = 0x%lx %lA\n", s.sjs_sp, s.sjs_sp); 155*0Sstevel@tonic-gate mdb_printf(" %%pc = 0x%lx %lA\n", s.sjs_pc, s.sjs_pc); 156*0Sstevel@tonic-gate mdb_printf(" %%fp = 0x%lx %lA\n", s.sjs_fp, s.sjs_fp); 157*0Sstevel@tonic-gate mdb_printf(" %%i7 = 0x%lx %lA\n", s.sjs_i7, s.sjs_i7); 158*0Sstevel@tonic-gate mdb_printf(" uclink = %p\n", s.sjs_uclink); 159*0Sstevel@tonic-gate mdb_printf(" sigset = 0x%08x 0x%08x 0x%08x 0x%08x\n", 160*0Sstevel@tonic-gate s.sjs_sigmask.__sigbits[0], s.sjs_sigmask.__sigbits[1], 161*0Sstevel@tonic-gate s.sjs_sigmask.__sigbits[2], s.sjs_sigmask.__sigbits[3]); 162*0Sstevel@tonic-gate mdb_printf(" stack = sp 0x%p size 0x%lx flags %s\n", 163*0Sstevel@tonic-gate s.sjs_stack.ss_sp, s.sjs_stack.ss_size, stack_flags(&s.sjs_stack)); 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate return (DCMD_OK); 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64) 168*0Sstevel@tonic-gate return (d_ucontext(addr, flags, argc, argv)); 169*0Sstevel@tonic-gate #endif 170*0Sstevel@tonic-gate } 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate /*ARGSUSED*/ 173*0Sstevel@tonic-gate static int 174*0Sstevel@tonic-gate d_siginfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 175*0Sstevel@tonic-gate { 176*0Sstevel@tonic-gate static const char *const msname[] = { 177*0Sstevel@tonic-gate "USER", "SYSTEM", "TRAP", "TFAULT", "DFAULT", "KFAULT", 178*0Sstevel@tonic-gate "USER_LOCK", "SLEEP", "WAIT_CPU", "STOPPED" 179*0Sstevel@tonic-gate }; 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate char signame[SIG2STR_MAX]; 182*0Sstevel@tonic-gate siginfo_t si; 183*0Sstevel@tonic-gate int i; 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate if (argc != 0) 186*0Sstevel@tonic-gate return (DCMD_USAGE); 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate if (mdb_vread(&si, sizeof (si), addr) != sizeof (si)) { 189*0Sstevel@tonic-gate mdb_warn("failed to read siginfo at %p", addr); 190*0Sstevel@tonic-gate return (DCMD_ERR); 191*0Sstevel@tonic-gate } 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate if (sig2str(si.si_signo, signame) == -1) 194*0Sstevel@tonic-gate (void) strcpy(signame, "unknown"); 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate mdb_printf(" signal %5d (%s)\n", si.si_signo, signame); 197*0Sstevel@tonic-gate mdb_printf(" code %5d (", si.si_code); 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate switch (si.si_code) { 200*0Sstevel@tonic-gate case SI_NOINFO: 201*0Sstevel@tonic-gate mdb_printf("no info"); 202*0Sstevel@tonic-gate break; 203*0Sstevel@tonic-gate case SI_DTRACE: 204*0Sstevel@tonic-gate mdb_printf("from DTrace raise() action"); 205*0Sstevel@tonic-gate break; 206*0Sstevel@tonic-gate case SI_RCTL: 207*0Sstevel@tonic-gate mdb_printf("from rctl action"); 208*0Sstevel@tonic-gate break; 209*0Sstevel@tonic-gate case SI_USER: 210*0Sstevel@tonic-gate mdb_printf("user generated via kill"); 211*0Sstevel@tonic-gate break; 212*0Sstevel@tonic-gate case SI_LWP: 213*0Sstevel@tonic-gate mdb_printf("user generated via lwp_kill"); 214*0Sstevel@tonic-gate break; 215*0Sstevel@tonic-gate case SI_QUEUE: 216*0Sstevel@tonic-gate mdb_printf("user generated via sigqueue"); 217*0Sstevel@tonic-gate break; 218*0Sstevel@tonic-gate case SI_TIMER: 219*0Sstevel@tonic-gate mdb_printf("from timer expiration"); 220*0Sstevel@tonic-gate break; 221*0Sstevel@tonic-gate case SI_ASYNCIO: 222*0Sstevel@tonic-gate mdb_printf("from async i/o completion"); 223*0Sstevel@tonic-gate break; 224*0Sstevel@tonic-gate case SI_MESGQ: 225*0Sstevel@tonic-gate mdb_printf("from message arrival"); 226*0Sstevel@tonic-gate break; 227*0Sstevel@tonic-gate default: 228*0Sstevel@tonic-gate if (SI_FROMUSER(&si)) 229*0Sstevel@tonic-gate mdb_printf("from user process"); 230*0Sstevel@tonic-gate else 231*0Sstevel@tonic-gate mdb_printf("from kernel"); 232*0Sstevel@tonic-gate } 233*0Sstevel@tonic-gate 234*0Sstevel@tonic-gate mdb_printf(")\n errno %5d (%s)\n", 235*0Sstevel@tonic-gate si.si_errno, strerror(si.si_errno)); 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate if (si.si_code == SI_USER || si.si_code == SI_QUEUE) { 238*0Sstevel@tonic-gate mdb_printf(" signal sent from PID %d (uid %d)\n", 239*0Sstevel@tonic-gate si.si_pid, si.si_uid); 240*0Sstevel@tonic-gate } 241*0Sstevel@tonic-gate 242*0Sstevel@tonic-gate if (si.si_code == SI_QUEUE) { 243*0Sstevel@tonic-gate mdb_printf(" signal value = 0t%d / %p\n", 244*0Sstevel@tonic-gate si.si_value.sival_int, si.si_value.sival_ptr); 245*0Sstevel@tonic-gate } 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate switch (si.si_signo) { 248*0Sstevel@tonic-gate case SIGCLD: 249*0Sstevel@tonic-gate mdb_printf(" signal sent from child PID %d (uid %d)\n", 250*0Sstevel@tonic-gate si.si_pid, si.si_uid); 251*0Sstevel@tonic-gate mdb_printf(" usr time = 0t%ld ticks, sys time = 0t%ld ticks\n", 252*0Sstevel@tonic-gate si.si_utime, si.si_stime); 253*0Sstevel@tonic-gate mdb_printf(" wait status = 0x%x\n", si.si_status); 254*0Sstevel@tonic-gate break; 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate case SIGSEGV: 257*0Sstevel@tonic-gate case SIGBUS: 258*0Sstevel@tonic-gate case SIGILL: 259*0Sstevel@tonic-gate case SIGTRAP: 260*0Sstevel@tonic-gate case SIGFPE: 261*0Sstevel@tonic-gate mdb_printf(" fault address = 0x%p\n trapno = %d\n", 262*0Sstevel@tonic-gate si.si_addr, si.si_trapno); 263*0Sstevel@tonic-gate mdb_printf(" instruction address = 0x%p %lA\n", 264*0Sstevel@tonic-gate si.si_pc, si.si_pc); 265*0Sstevel@tonic-gate break; 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate case SIGPOLL: 268*0Sstevel@tonic-gate case SIGXFSZ: 269*0Sstevel@tonic-gate mdb_printf(" fd = %d band = 0x%lx\n", 270*0Sstevel@tonic-gate si.si_fd, si.si_band); 271*0Sstevel@tonic-gate break; 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gate case SIGPROF: 274*0Sstevel@tonic-gate mdb_printf(" last fault address = 0x%p fault type = %d\n", 275*0Sstevel@tonic-gate si.si_faddr, si.si_fault); 276*0Sstevel@tonic-gate mdb_printf(" timestamp = 0t%ld sec 0t%ld nsec\n", 277*0Sstevel@tonic-gate si.si_tstamp.tv_sec, si.si_tstamp.tv_nsec); 278*0Sstevel@tonic-gate 279*0Sstevel@tonic-gate if (si.__data.__prof.__syscall != 0) { 280*0Sstevel@tonic-gate mdb_printf(" system call %d (", si.si_syscall); 281*0Sstevel@tonic-gate if (si.si_nsysarg > 0) { 282*0Sstevel@tonic-gate mdb_printf("%lx", si.si_sysarg[0]); 283*0Sstevel@tonic-gate for (i = 1; i < si.si_nsysarg; i++) 284*0Sstevel@tonic-gate mdb_printf(", %lx", si.si_sysarg[i]); 285*0Sstevel@tonic-gate } 286*0Sstevel@tonic-gate mdb_printf(" )\n"); 287*0Sstevel@tonic-gate } 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate for (i = 0; i < sizeof (msname) / sizeof (msname[0]); i++) { 290*0Sstevel@tonic-gate mdb_printf(" mstate[\"%s\"] = %d\n", 291*0Sstevel@tonic-gate msname[i], si.si_mstate[i]); 292*0Sstevel@tonic-gate } 293*0Sstevel@tonic-gate break; 294*0Sstevel@tonic-gate } 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gate return (DCMD_OK); 297*0Sstevel@tonic-gate } 298*0Sstevel@tonic-gate 299*0Sstevel@tonic-gate static int 300*0Sstevel@tonic-gate uc_walk_step(mdb_walk_state_t *wsp) 301*0Sstevel@tonic-gate { 302*0Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 303*0Sstevel@tonic-gate ucontext_t uc; 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gate if (addr == NULL) 306*0Sstevel@tonic-gate return (WALK_DONE); 307*0Sstevel@tonic-gate 308*0Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 309*0Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 310*0Sstevel@tonic-gate return (WALK_ERR); 311*0Sstevel@tonic-gate } 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)uc.uc_link; 314*0Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata)); 315*0Sstevel@tonic-gate } 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate static int 318*0Sstevel@tonic-gate oldc_walk_init(mdb_walk_state_t *wsp) 319*0Sstevel@tonic-gate { 320*0Sstevel@tonic-gate ssize_t nbytes = mdb_get_xdata("lwpstatus", NULL, 0); 321*0Sstevel@tonic-gate 322*0Sstevel@tonic-gate if (nbytes <= 0) { 323*0Sstevel@tonic-gate mdb_warn("lwpstatus information not available"); 324*0Sstevel@tonic-gate return (WALK_ERR); 325*0Sstevel@tonic-gate } 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate if (wsp->walk_addr != NULL) { 328*0Sstevel@tonic-gate mdb_warn("walker only supports global walk\n"); 329*0Sstevel@tonic-gate return (WALK_ERR); 330*0Sstevel@tonic-gate } 331*0Sstevel@tonic-gate 332*0Sstevel@tonic-gate wsp->walk_addr = nbytes; /* Use walk_addr to track size */ 333*0Sstevel@tonic-gate wsp->walk_data = mdb_alloc(nbytes, UM_SLEEP); 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate if (mdb_get_xdata("lwpstatus", wsp->walk_data, nbytes) != nbytes) { 336*0Sstevel@tonic-gate mdb_warn("failed to read lwpstatus information"); 337*0Sstevel@tonic-gate mdb_free(wsp->walk_data, nbytes); 338*0Sstevel@tonic-gate return (WALK_ERR); 339*0Sstevel@tonic-gate } 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate wsp->walk_arg = wsp->walk_data; /* Use walk_arg to track pointer */ 342*0Sstevel@tonic-gate return (WALK_NEXT); 343*0Sstevel@tonic-gate } 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gate static int 346*0Sstevel@tonic-gate oldc_walk_step(mdb_walk_state_t *wsp) 347*0Sstevel@tonic-gate { 348*0Sstevel@tonic-gate const lwpstatus_t *lsp, *end; 349*0Sstevel@tonic-gate 350*0Sstevel@tonic-gate end = (const lwpstatus_t *)((uintptr_t)wsp->walk_data + wsp->walk_addr); 351*0Sstevel@tonic-gate lsp = wsp->walk_arg; 352*0Sstevel@tonic-gate 353*0Sstevel@tonic-gate wsp->walk_arg = (void *)(lsp + 1); 354*0Sstevel@tonic-gate 355*0Sstevel@tonic-gate if (lsp < end) { 356*0Sstevel@tonic-gate uintptr_t addr = lsp->pr_oldcontext; 357*0Sstevel@tonic-gate ucontext_t uc; 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate if (addr == NULL) 360*0Sstevel@tonic-gate return (WALK_NEXT); 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate if (mdb_vread(&uc, sizeof (uc), addr) != sizeof (uc)) { 363*0Sstevel@tonic-gate mdb_warn("failed to read ucontext at %p", addr); 364*0Sstevel@tonic-gate return (WALK_NEXT); 365*0Sstevel@tonic-gate } 366*0Sstevel@tonic-gate 367*0Sstevel@tonic-gate return (wsp->walk_callback(addr, &uc, wsp->walk_cbdata)); 368*0Sstevel@tonic-gate } 369*0Sstevel@tonic-gate 370*0Sstevel@tonic-gate return (WALK_DONE); 371*0Sstevel@tonic-gate } 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate static void 374*0Sstevel@tonic-gate oldc_walk_fini(mdb_walk_state_t *wsp) 375*0Sstevel@tonic-gate { 376*0Sstevel@tonic-gate mdb_free(wsp->walk_data, wsp->walk_addr); /* walk_addr has size */ 377*0Sstevel@tonic-gate } 378*0Sstevel@tonic-gate 379*0Sstevel@tonic-gate /* 380*0Sstevel@tonic-gate * ==================== threads ========================== 381*0Sstevel@tonic-gate * These are the interfaces that used to require libthread. 382*0Sstevel@tonic-gate * Now, libthread has been folded into libc. 383*0Sstevel@tonic-gate * ======================================================= 384*0Sstevel@tonic-gate */ 385*0Sstevel@tonic-gate 386*0Sstevel@tonic-gate /* 387*0Sstevel@tonic-gate * prt_addr() is called up to three times to generate arguments for 388*0Sstevel@tonic-gate * one call to mdb_printf(). We must return at least three different 389*0Sstevel@tonic-gate * pointers to static storage for consecutive calls to prt_addr(). 390*0Sstevel@tonic-gate */ 391*0Sstevel@tonic-gate static const char * 392*0Sstevel@tonic-gate prt_addr(void *addr, int pad) 393*0Sstevel@tonic-gate { 394*0Sstevel@tonic-gate static char buffer[4][24]; 395*0Sstevel@tonic-gate static int ix = 0; 396*0Sstevel@tonic-gate char *buf; 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate if (ix == 4) /* use buffers in sequence: 0, 1, 2, 3 */ 399*0Sstevel@tonic-gate ix = 0; 400*0Sstevel@tonic-gate buf = buffer[ix++]; 401*0Sstevel@tonic-gate if (addr == NULL) 402*0Sstevel@tonic-gate return (pad? "<NULL> " : "<NULL>"); 403*0Sstevel@tonic-gate else { 404*0Sstevel@tonic-gate #ifdef _LP64 405*0Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%016lx", addr); 406*0Sstevel@tonic-gate if (pad) 407*0Sstevel@tonic-gate (void) strcpy(buf + 18, " "); 408*0Sstevel@tonic-gate #else 409*0Sstevel@tonic-gate (void) mdb_snprintf(buf, sizeof (buffer[0]), "0x%08lx", addr); 410*0Sstevel@tonic-gate if (pad) 411*0Sstevel@tonic-gate (void) strcpy(buf + 10, " "); 412*0Sstevel@tonic-gate #endif /* _LP64 */ 413*0Sstevel@tonic-gate return (buf); 414*0Sstevel@tonic-gate } 415*0Sstevel@tonic-gate } 416*0Sstevel@tonic-gate 417*0Sstevel@tonic-gate #define HD(str) mdb_printf(" " str "\n") 418*0Sstevel@tonic-gate #define OFFSTR "+0x%-7lx " 419*0Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(ulwp_t, member)) 420*0Sstevel@tonic-gate 421*0Sstevel@tonic-gate /*ARGSUSED*/ 422*0Sstevel@tonic-gate static int 423*0Sstevel@tonic-gate d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 424*0Sstevel@tonic-gate { 425*0Sstevel@tonic-gate ulwp_t ulwp; 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gate if (argc != 0 || !(flags & DCMD_ADDRSPEC)) 428*0Sstevel@tonic-gate return (DCMD_USAGE); 429*0Sstevel@tonic-gate 430*0Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && 431*0Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)), 432*0Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { 433*0Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr); 434*0Sstevel@tonic-gate return (DCMD_ERR); 435*0Sstevel@tonic-gate } 436*0Sstevel@tonic-gate 437*0Sstevel@tonic-gate mdb_printf("%#a\n", addr); 438*0Sstevel@tonic-gate 439*0Sstevel@tonic-gate HD("self uberdata"); 440*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s\n", 441*0Sstevel@tonic-gate OFFSET(ul_self), 442*0Sstevel@tonic-gate prt_addr(ulwp.ul_self, 1), 443*0Sstevel@tonic-gate prt_addr(ulwp.ul_uberdata, 0)); 444*0Sstevel@tonic-gate 445*0Sstevel@tonic-gate HD("tlsent ntlsent"); 446*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %ld\n", 447*0Sstevel@tonic-gate OFFSET(ul_tlsent), 448*0Sstevel@tonic-gate prt_addr(ulwp.ul_tlsent, 1), 449*0Sstevel@tonic-gate ulwp.ul_ntlsent); 450*0Sstevel@tonic-gate 451*0Sstevel@tonic-gate HD("forw back next"); 452*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 453*0Sstevel@tonic-gate OFFSET(ul_forw), 454*0Sstevel@tonic-gate prt_addr(ulwp.ul_forw, 1), 455*0Sstevel@tonic-gate prt_addr(ulwp.ul_back, 1), 456*0Sstevel@tonic-gate prt_addr(ulwp.ul_next, 0)); 457*0Sstevel@tonic-gate 458*0Sstevel@tonic-gate HD("hash rval stk"); 459*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 460*0Sstevel@tonic-gate OFFSET(ul_hash), 461*0Sstevel@tonic-gate prt_addr(ulwp.ul_hash, 1), 462*0Sstevel@tonic-gate prt_addr(ulwp.ul_rval, 1), 463*0Sstevel@tonic-gate prt_addr(ulwp.ul_stk, 0)); 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate HD("mapsiz guardsize stktop stksiz"); 466*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10ld %-10ld %s %ld\n", 467*0Sstevel@tonic-gate OFFSET(ul_mapsiz), 468*0Sstevel@tonic-gate ulwp.ul_mapsiz, 469*0Sstevel@tonic-gate ulwp.ul_guardsize, 470*0Sstevel@tonic-gate prt_addr((void *)ulwp.ul_stktop, 1), 471*0Sstevel@tonic-gate ulwp.ul_stksiz); 472*0Sstevel@tonic-gate 473*0Sstevel@tonic-gate HD("ustack.ss_sp ustack.ss_size ustack.ss_flags"); 474*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-21ld %s\n", 475*0Sstevel@tonic-gate OFFSET(ul_ustack.ss_sp), 476*0Sstevel@tonic-gate prt_addr(ulwp.ul_ustack.ss_sp, 1), 477*0Sstevel@tonic-gate ulwp.ul_ustack.ss_size, 478*0Sstevel@tonic-gate stack_flags(&ulwp.ul_ustack)); 479*0Sstevel@tonic-gate 480*0Sstevel@tonic-gate HD("ix lwpid pri mappedpri policy pri_mapped"); 481*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 482*0Sstevel@tonic-gate OFFSET(ul_ix), 483*0Sstevel@tonic-gate ulwp.ul_ix, 484*0Sstevel@tonic-gate ulwp.ul_lwpid, 485*0Sstevel@tonic-gate ulwp.ul_pri, 486*0Sstevel@tonic-gate ulwp.ul_mappedpri, 487*0Sstevel@tonic-gate ulwp.ul_policy, 488*0Sstevel@tonic-gate ulwp.ul_pri_mapped); 489*0Sstevel@tonic-gate 490*0Sstevel@tonic-gate HD("cursig pleasestop stop signalled dead unwind"); 491*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d ", 492*0Sstevel@tonic-gate OFFSET(ul_cursig), 493*0Sstevel@tonic-gate ulwp.ul_cursig); 494*0Sstevel@tonic-gate mdb_printf(ulwp.ul_pleasestop? "0x%-8x " : "%-10d ", 495*0Sstevel@tonic-gate ulwp.ul_pleasestop); 496*0Sstevel@tonic-gate mdb_printf(ulwp.ul_stop? "0x%-8x " : "%-10d ", 497*0Sstevel@tonic-gate ulwp.ul_stop); 498*0Sstevel@tonic-gate mdb_printf("%-10d %-10d %d\n", 499*0Sstevel@tonic-gate ulwp.ul_signalled, 500*0Sstevel@tonic-gate ulwp.ul_dead, 501*0Sstevel@tonic-gate ulwp.ul_unwind); 502*0Sstevel@tonic-gate 503*0Sstevel@tonic-gate HD("detached writer stopping pad4 preempt savpreempt"); 504*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 505*0Sstevel@tonic-gate OFFSET(ul_detached), 506*0Sstevel@tonic-gate ulwp.ul_detached, 507*0Sstevel@tonic-gate ulwp.ul_writer, 508*0Sstevel@tonic-gate ulwp.ul_stopping, 509*0Sstevel@tonic-gate ulwp.ul_pad4, 510*0Sstevel@tonic-gate ulwp.ul_preempt, 511*0Sstevel@tonic-gate ulwp.ul_savpreempt); 512*0Sstevel@tonic-gate 513*0Sstevel@tonic-gate HD("sigsuspend main fork primarymap m'spinners d'noreserv"); 514*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 515*0Sstevel@tonic-gate OFFSET(ul_sigsuspend), 516*0Sstevel@tonic-gate ulwp.ul_sigsuspend, 517*0Sstevel@tonic-gate ulwp.ul_main, 518*0Sstevel@tonic-gate ulwp.ul_fork, 519*0Sstevel@tonic-gate ulwp.ul_primarymap, 520*0Sstevel@tonic-gate ulwp.ul_max_spinners, 521*0Sstevel@tonic-gate ulwp.ul_door_noreserve); 522*0Sstevel@tonic-gate 523*0Sstevel@tonic-gate HD("queue_fifo c'w'defer e'detect' async_safe pad1[0] pad1[1]"); 524*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 525*0Sstevel@tonic-gate OFFSET(ul_queue_fifo), 526*0Sstevel@tonic-gate ulwp.ul_queue_fifo, 527*0Sstevel@tonic-gate ulwp.ul_cond_wait_defer, 528*0Sstevel@tonic-gate ulwp.ul_error_detection, 529*0Sstevel@tonic-gate ulwp.ul_async_safe, 530*0Sstevel@tonic-gate ulwp.ul_pad1[0], 531*0Sstevel@tonic-gate ulwp.ul_pad1[1]); 532*0Sstevel@tonic-gate 533*0Sstevel@tonic-gate HD("adapt'spin rele'spin queue_spin critical sigdefer vfork"); 534*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 535*0Sstevel@tonic-gate OFFSET(ul_adaptive_spin), 536*0Sstevel@tonic-gate ulwp.ul_adaptive_spin, 537*0Sstevel@tonic-gate ulwp.ul_release_spin, 538*0Sstevel@tonic-gate ulwp.ul_queue_spin, 539*0Sstevel@tonic-gate ulwp.ul_critical, 540*0Sstevel@tonic-gate ulwp.ul_sigdefer, 541*0Sstevel@tonic-gate ulwp.ul_vfork); 542*0Sstevel@tonic-gate 543*0Sstevel@tonic-gate HD("cancelable c'pending c'disabled c'async save_async mutator"); 544*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 545*0Sstevel@tonic-gate OFFSET(ul_cancelable), 546*0Sstevel@tonic-gate ulwp.ul_cancelable, 547*0Sstevel@tonic-gate ulwp.ul_cancel_pending, 548*0Sstevel@tonic-gate ulwp.ul_cancel_disabled, 549*0Sstevel@tonic-gate ulwp.ul_cancel_async, 550*0Sstevel@tonic-gate ulwp.ul_save_async, 551*0Sstevel@tonic-gate ulwp.ul_mutator); 552*0Sstevel@tonic-gate 553*0Sstevel@tonic-gate HD("created replace nocancel errno errnop"); 554*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", 555*0Sstevel@tonic-gate OFFSET(ul_created), 556*0Sstevel@tonic-gate ulwp.ul_created, 557*0Sstevel@tonic-gate ulwp.ul_replace, 558*0Sstevel@tonic-gate ulwp.ul_nocancel, 559*0Sstevel@tonic-gate ulwp.ul_errno, 560*0Sstevel@tonic-gate prt_addr(ulwp.ul_errnop, 0)); 561*0Sstevel@tonic-gate 562*0Sstevel@tonic-gate HD("clnup_hdr schedctl_called schedctl"); 563*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 564*0Sstevel@tonic-gate OFFSET(ul_clnup_hdr), 565*0Sstevel@tonic-gate prt_addr(ulwp.ul_clnup_hdr, 1), 566*0Sstevel@tonic-gate prt_addr(ulwp.ul_schedctl_called, 1), 567*0Sstevel@tonic-gate prt_addr((void *)ulwp.ul_schedctl, 0)); 568*0Sstevel@tonic-gate 569*0Sstevel@tonic-gate HD("bindflags gs stsd &ftsd"); 570*0Sstevel@tonic-gate mdb_printf(OFFSTR, 571*0Sstevel@tonic-gate OFFSET(ul_bindflags)); 572*0Sstevel@tonic-gate mdb_printf(ulwp.ul_bindflags? "0x%-8x " : "%-10d ", 573*0Sstevel@tonic-gate ulwp.ul_bindflags); 574*0Sstevel@tonic-gate mdb_printf(ulwp.ul_gs? "0x%-8x " : "%-10d ", 575*0Sstevel@tonic-gate ulwp.ul_gs); 576*0Sstevel@tonic-gate mdb_printf("%s %s\n", 577*0Sstevel@tonic-gate prt_addr(ulwp.ul_stsd, 1), 578*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_ftsd[0])), 0)); 579*0Sstevel@tonic-gate 580*0Sstevel@tonic-gate HD("eventmask[0..1] eventnum eventdata"); 581*0Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %-21d %s\n", 582*0Sstevel@tonic-gate OFFSET(ul_td_evbuf.eventmask.event_bits[0]), 583*0Sstevel@tonic-gate ulwp.ul_td_evbuf.eventmask.event_bits[0], 584*0Sstevel@tonic-gate ulwp.ul_td_evbuf.eventmask.event_bits[1], 585*0Sstevel@tonic-gate ulwp.ul_td_evbuf.eventnum, 586*0Sstevel@tonic-gate prt_addr(ulwp.ul_td_evbuf.eventdata, 0)); 587*0Sstevel@tonic-gate 588*0Sstevel@tonic-gate HD("td'enable sync'reg qtype cv_wake usropts"); 589*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d ", 590*0Sstevel@tonic-gate OFFSET(ul_td_events_enable), 591*0Sstevel@tonic-gate ulwp.ul_td_events_enable, 592*0Sstevel@tonic-gate ulwp.ul_sync_obj_reg, 593*0Sstevel@tonic-gate ulwp.ul_qtype, 594*0Sstevel@tonic-gate ulwp.ul_cv_wake); 595*0Sstevel@tonic-gate mdb_printf(ulwp.ul_usropts? "0x%x\n" : "%d\n", 596*0Sstevel@tonic-gate ulwp.ul_usropts); 597*0Sstevel@tonic-gate 598*0Sstevel@tonic-gate HD("startpc startarg wchan"); 599*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 600*0Sstevel@tonic-gate OFFSET(ul_startpc), 601*0Sstevel@tonic-gate prt_addr((void *)ulwp.ul_startpc, 1), 602*0Sstevel@tonic-gate prt_addr(ulwp.ul_startarg, 1), 603*0Sstevel@tonic-gate prt_addr(ulwp.ul_wchan, 0)); 604*0Sstevel@tonic-gate 605*0Sstevel@tonic-gate HD("link sleepq cvmutex"); 606*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 607*0Sstevel@tonic-gate OFFSET(ul_link), 608*0Sstevel@tonic-gate prt_addr(ulwp.ul_link, 1), 609*0Sstevel@tonic-gate prt_addr(ulwp.ul_sleepq, 1), 610*0Sstevel@tonic-gate prt_addr(ulwp.ul_cvmutex, 0)); 611*0Sstevel@tonic-gate 612*0Sstevel@tonic-gate HD("mxchain epri emappedpri rdlocks"); 613*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %d\n", 614*0Sstevel@tonic-gate OFFSET(ul_mxchain), 615*0Sstevel@tonic-gate prt_addr(ulwp.ul_mxchain, 1), 616*0Sstevel@tonic-gate ulwp.ul_epri, 617*0Sstevel@tonic-gate ulwp.ul_emappedpri, 618*0Sstevel@tonic-gate ulwp.ul_rdlocks); 619*0Sstevel@tonic-gate 620*0Sstevel@tonic-gate HD("rd_rwlock rd_count tpdp"); 621*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-21ld %s\n", 622*0Sstevel@tonic-gate OFFSET(ul_readlock.single.rd_rwlock), 623*0Sstevel@tonic-gate prt_addr(ulwp.ul_readlock.single.rd_rwlock, 1), 624*0Sstevel@tonic-gate ulwp.ul_readlock.single.rd_count, 625*0Sstevel@tonic-gate prt_addr(ulwp.ul_tpdp, 0)); 626*0Sstevel@tonic-gate 627*0Sstevel@tonic-gate HD("siglink s'l'spin s'l'spin2 s'l'sleep s'l'wakeup"); 628*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %-10d %-10d\n", 629*0Sstevel@tonic-gate OFFSET(ul_siglink), 630*0Sstevel@tonic-gate prt_addr(ulwp.ul_siglink, 1), 631*0Sstevel@tonic-gate ulwp.ul_spin_lock_spin, 632*0Sstevel@tonic-gate ulwp.ul_spin_lock_spin2, 633*0Sstevel@tonic-gate ulwp.ul_spin_lock_sleep, 634*0Sstevel@tonic-gate ulwp.ul_spin_lock_wakeup); 635*0Sstevel@tonic-gate 636*0Sstevel@tonic-gate /* 637*0Sstevel@tonic-gate * The remainder of the ulwp_t structure 638*0Sstevel@tonic-gate * is invalid if this is a replacement. 639*0Sstevel@tonic-gate */ 640*0Sstevel@tonic-gate if (ulwp.ul_replace) 641*0Sstevel@tonic-gate return (DCMD_OK); 642*0Sstevel@tonic-gate 643*0Sstevel@tonic-gate HD("sigmask[0..3]"); 644*0Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 645*0Sstevel@tonic-gate OFFSET(ul_sigmask.__sigbits[0]), 646*0Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[0], 647*0Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[1], 648*0Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[2], 649*0Sstevel@tonic-gate ulwp.ul_sigmask.__sigbits[3]); 650*0Sstevel@tonic-gate 651*0Sstevel@tonic-gate HD("tmpmask[0..3]"); 652*0Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", 653*0Sstevel@tonic-gate OFFSET(ul_tmpmask.__sigbits[0]), 654*0Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[0], 655*0Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[1], 656*0Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[2], 657*0Sstevel@tonic-gate ulwp.ul_tmpmask.__sigbits[3]); 658*0Sstevel@tonic-gate 659*0Sstevel@tonic-gate HD("&siginfo &spinlock &fpuenv"); 660*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 661*0Sstevel@tonic-gate OFFSET(ul_siginfo), 662*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_siginfo)), 1), 663*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_spinlock)), 1), 664*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(ul_fpuenv)), 0)); 665*0Sstevel@tonic-gate 666*0Sstevel@tonic-gate return (DCMD_OK); 667*0Sstevel@tonic-gate } 668*0Sstevel@tonic-gate 669*0Sstevel@tonic-gate /* 670*0Sstevel@tonic-gate * Get the address of the unique uberdata_t structure. 671*0Sstevel@tonic-gate */ 672*0Sstevel@tonic-gate static uintptr_t 673*0Sstevel@tonic-gate uberdata_addr(void) 674*0Sstevel@tonic-gate { 675*0Sstevel@tonic-gate uintptr_t uaddr; 676*0Sstevel@tonic-gate uintptr_t addr; 677*0Sstevel@tonic-gate GElf_Sym sym; 678*0Sstevel@tonic-gate 679*0Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_tdb_bootstrap", &sym) != 0) { 680*0Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_tdb_bootstrap"); 681*0Sstevel@tonic-gate return (NULL); 682*0Sstevel@tonic-gate } 683*0Sstevel@tonic-gate if (mdb_vread(&addr, sizeof (addr), sym.st_value) == sizeof (addr) && 684*0Sstevel@tonic-gate addr != NULL && 685*0Sstevel@tonic-gate mdb_vread(&uaddr, sizeof (uaddr), addr) == sizeof (uaddr) && 686*0Sstevel@tonic-gate uaddr != NULL) { 687*0Sstevel@tonic-gate return (uaddr); 688*0Sstevel@tonic-gate } 689*0Sstevel@tonic-gate if (mdb_lookup_by_obj("libc.so.1", "_uberdata", &sym) != 0) { 690*0Sstevel@tonic-gate mdb_warn("cannot find libc.so.1`_uberdata"); 691*0Sstevel@tonic-gate return (NULL); 692*0Sstevel@tonic-gate } 693*0Sstevel@tonic-gate return ((uintptr_t)sym.st_value); 694*0Sstevel@tonic-gate } 695*0Sstevel@tonic-gate 696*0Sstevel@tonic-gate #undef OFFSET 697*0Sstevel@tonic-gate #define OFFSET(member) ((size_t)OFFSETOF(uberdata_t, member)) 698*0Sstevel@tonic-gate 699*0Sstevel@tonic-gate /*ARGSUSED*/ 700*0Sstevel@tonic-gate static int 701*0Sstevel@tonic-gate d_uberdata(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 702*0Sstevel@tonic-gate { 703*0Sstevel@tonic-gate uberdata_t uberdata; 704*0Sstevel@tonic-gate int i; 705*0Sstevel@tonic-gate 706*0Sstevel@tonic-gate if (argc != 0) 707*0Sstevel@tonic-gate return (DCMD_USAGE); 708*0Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) && (addr = uberdata_addr()) == NULL) 709*0Sstevel@tonic-gate return (DCMD_ERR); 710*0Sstevel@tonic-gate 711*0Sstevel@tonic-gate if (mdb_vread(&uberdata, sizeof (uberdata), addr) != 712*0Sstevel@tonic-gate sizeof (uberdata)) { 713*0Sstevel@tonic-gate mdb_warn("failed to read uberdata at 0x%p", addr); 714*0Sstevel@tonic-gate return (DCMD_ERR); 715*0Sstevel@tonic-gate } 716*0Sstevel@tonic-gate 717*0Sstevel@tonic-gate mdb_printf("%#a\n", addr); 718*0Sstevel@tonic-gate 719*0Sstevel@tonic-gate HD("&link_lock &fork_lock fork_owner"); 720*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 721*0Sstevel@tonic-gate OFFSET(link_lock), 722*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(link_lock)), 1), 723*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(fork_lock)), 1), 724*0Sstevel@tonic-gate prt_addr((void *)uberdata.fork_owner, 0)); 725*0Sstevel@tonic-gate 726*0Sstevel@tonic-gate HD("&tdb_hash_lock &tdb_hash_lock_stats &siguaction[0]"); 727*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 728*0Sstevel@tonic-gate OFFSET(tdb_hash_lock), 729*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tdb_hash_lock)), 1), 730*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tdb_hash_lock_stats)), 1), 731*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(siguaction)), 0)); 732*0Sstevel@tonic-gate 733*0Sstevel@tonic-gate HD("&bucket free_list chunks"); 734*0Sstevel@tonic-gate for (i = 0; i < NBUCKETS; i++) { 735*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 736*0Sstevel@tonic-gate OFFSET(bucket[i]), 737*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(bucket[i])), 1), 738*0Sstevel@tonic-gate prt_addr(uberdata.bucket[i].free_list, 1), 739*0Sstevel@tonic-gate uberdata.bucket[i].chunks); 740*0Sstevel@tonic-gate } 741*0Sstevel@tonic-gate 742*0Sstevel@tonic-gate HD("&atexit_root head exit_frame_monitor"); 743*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 744*0Sstevel@tonic-gate OFFSET(atexit_root), 745*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(atexit_root.exitfns_lock)), 1), 746*0Sstevel@tonic-gate prt_addr(uberdata.atexit_root.head, 1), 747*0Sstevel@tonic-gate prt_addr(uberdata.atexit_root.exit_frame_monitor, 0)); 748*0Sstevel@tonic-gate 749*0Sstevel@tonic-gate HD("&tsd_metadata tsdm_nkeys tsdm_nused tsdm_destro"); 750*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %-10d %-10d %s\n", 751*0Sstevel@tonic-gate OFFSET(tsd_metadata), 752*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tsd_metadata.tsdm_lock)), 1), 753*0Sstevel@tonic-gate uberdata.tsd_metadata.tsdm_nkeys, 754*0Sstevel@tonic-gate uberdata.tsd_metadata.tsdm_nused, 755*0Sstevel@tonic-gate prt_addr((void *)uberdata.tsd_metadata.tsdm_destro, 0)); 756*0Sstevel@tonic-gate 757*0Sstevel@tonic-gate HD("&tls_metadata tls_modinfo.data tls_modinfo.size"); 758*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 759*0Sstevel@tonic-gate OFFSET(tls_metadata), 760*0Sstevel@tonic-gate prt_addr((void *)(addr + OFFSET(tls_metadata.tls_lock)), 1), 761*0Sstevel@tonic-gate prt_addr(uberdata.tls_metadata.tls_modinfo.tls_data, 1), 762*0Sstevel@tonic-gate uberdata.tls_metadata.tls_modinfo.tls_size); 763*0Sstevel@tonic-gate 764*0Sstevel@tonic-gate HD(" static_tls.data static_tls.size"); 765*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 766*0Sstevel@tonic-gate OFFSET(tls_metadata.static_tls), 767*0Sstevel@tonic-gate " ", 768*0Sstevel@tonic-gate prt_addr(uberdata.tls_metadata.static_tls.tls_data, 1), 769*0Sstevel@tonic-gate uberdata.tls_metadata.static_tls.tls_size); 770*0Sstevel@tonic-gate 771*0Sstevel@tonic-gate HD("primary_ma bucket_ini uflags.mt uflags.pad uflags.trs uflags.ted"); 772*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", 773*0Sstevel@tonic-gate OFFSET(primary_map), 774*0Sstevel@tonic-gate uberdata.primary_map, 775*0Sstevel@tonic-gate uberdata.bucket_init, 776*0Sstevel@tonic-gate uberdata.uberflags.uf_x.x_mt, 777*0Sstevel@tonic-gate uberdata.uberflags.uf_x.x_pad, 778*0Sstevel@tonic-gate uberdata.uberflags.uf_x.x_tdb_register_sync, 779*0Sstevel@tonic-gate uberdata.uberflags.uf_x.x_thread_error_detection); 780*0Sstevel@tonic-gate 781*0Sstevel@tonic-gate HD("queue_head thr_hash_table hash_size hash_mask"); 782*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d 0x%x\n", 783*0Sstevel@tonic-gate OFFSET(queue_head), 784*0Sstevel@tonic-gate prt_addr(uberdata.queue_head, 1), 785*0Sstevel@tonic-gate prt_addr(uberdata.thr_hash_table, 1), 786*0Sstevel@tonic-gate uberdata.hash_size, 787*0Sstevel@tonic-gate uberdata.hash_mask); 788*0Sstevel@tonic-gate 789*0Sstevel@tonic-gate HD("ulwp_one all_lwps all_zombies"); 790*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 791*0Sstevel@tonic-gate OFFSET(ulwp_one), 792*0Sstevel@tonic-gate prt_addr(uberdata.ulwp_one, 1), 793*0Sstevel@tonic-gate prt_addr(uberdata.all_lwps, 1), 794*0Sstevel@tonic-gate prt_addr(uberdata.all_zombies, 0)); 795*0Sstevel@tonic-gate 796*0Sstevel@tonic-gate HD("nthreads nzombies ndaemons pid sigacthandler"); 797*0Sstevel@tonic-gate mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", 798*0Sstevel@tonic-gate OFFSET(nthreads), 799*0Sstevel@tonic-gate uberdata.nthreads, 800*0Sstevel@tonic-gate uberdata.nzombies, 801*0Sstevel@tonic-gate uberdata.ndaemons, 802*0Sstevel@tonic-gate (int)uberdata.pid, 803*0Sstevel@tonic-gate prt_addr((void *)uberdata.sigacthandler, 0)); 804*0Sstevel@tonic-gate 805*0Sstevel@tonic-gate HD("lwp_stacks lwp_laststack nfreestack stk_cache"); 806*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 807*0Sstevel@tonic-gate OFFSET(lwp_stacks), 808*0Sstevel@tonic-gate prt_addr(uberdata.lwp_stacks, 1), 809*0Sstevel@tonic-gate prt_addr(uberdata.lwp_laststack, 1), 810*0Sstevel@tonic-gate uberdata.nfreestack, 811*0Sstevel@tonic-gate uberdata.thread_stack_cache); 812*0Sstevel@tonic-gate 813*0Sstevel@tonic-gate HD("ulwp_freelist ulwp_lastfree"); 814*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s\n", 815*0Sstevel@tonic-gate OFFSET(ulwp_freelist), 816*0Sstevel@tonic-gate prt_addr(uberdata.ulwp_freelist, 1), 817*0Sstevel@tonic-gate prt_addr(uberdata.ulwp_lastfree, 0)); 818*0Sstevel@tonic-gate 819*0Sstevel@tonic-gate HD("ulwp_replace_free ulwp_replace_last atforklist"); 820*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %s\n", 821*0Sstevel@tonic-gate OFFSET(ulwp_replace_free), 822*0Sstevel@tonic-gate prt_addr(uberdata.ulwp_replace_free, 1), 823*0Sstevel@tonic-gate prt_addr(uberdata.ulwp_replace_last, 1), 824*0Sstevel@tonic-gate prt_addr(uberdata.atforklist, 0)); 825*0Sstevel@tonic-gate 826*0Sstevel@tonic-gate HD("tdb_bootstrap tdb_sync_addr_hash tdb_'count tdb_'fail"); 827*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %-10d %d\n", 828*0Sstevel@tonic-gate OFFSET(tdb_bootstrap), 829*0Sstevel@tonic-gate prt_addr(uberdata.tdb_bootstrap, 1), 830*0Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_hash, 1), 831*0Sstevel@tonic-gate uberdata.tdb.tdb_register_count, 832*0Sstevel@tonic-gate uberdata.tdb.tdb_hash_alloc_failed); 833*0Sstevel@tonic-gate 834*0Sstevel@tonic-gate HD("tdb_sync_addr_free tdb_sync_addr_last tdb_sync_alloc"); 835*0Sstevel@tonic-gate mdb_printf(OFFSTR "%s %s %ld\n", 836*0Sstevel@tonic-gate OFFSET(tdb.tdb_sync_addr_free), 837*0Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_free, 1), 838*0Sstevel@tonic-gate prt_addr(uberdata.tdb.tdb_sync_addr_last, 1), 839*0Sstevel@tonic-gate uberdata.tdb.tdb_sync_alloc); 840*0Sstevel@tonic-gate 841*0Sstevel@tonic-gate HD("tdb_ev_global_mask tdb_events"); 842*0Sstevel@tonic-gate mdb_printf(OFFSTR "0x%08x 0x%08x %s\n", 843*0Sstevel@tonic-gate OFFSET(tdb.tdb_ev_global_mask), 844*0Sstevel@tonic-gate uberdata.tdb.tdb_ev_global_mask.event_bits[0], 845*0Sstevel@tonic-gate uberdata.tdb.tdb_ev_global_mask.event_bits[1], 846*0Sstevel@tonic-gate prt_addr((void *)uberdata.tdb.tdb_events, 0)); 847*0Sstevel@tonic-gate 848*0Sstevel@tonic-gate return (DCMD_OK); 849*0Sstevel@tonic-gate } 850*0Sstevel@tonic-gate 851*0Sstevel@tonic-gate static int 852*0Sstevel@tonic-gate ulwp_walk_init(mdb_walk_state_t *wsp) 853*0Sstevel@tonic-gate { 854*0Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 855*0Sstevel@tonic-gate uintptr_t uber_addr; 856*0Sstevel@tonic-gate 857*0Sstevel@tonic-gate if (addr == NULL && 858*0Sstevel@tonic-gate ((uber_addr = uberdata_addr()) == NULL || 859*0Sstevel@tonic-gate mdb_vread(&addr, sizeof (addr), 860*0Sstevel@tonic-gate uber_addr + OFFSETOF(uberdata_t, all_lwps)) 861*0Sstevel@tonic-gate != sizeof (addr))) { 862*0Sstevel@tonic-gate mdb_warn("cannot find 'uberdata.all_lwps'"); 863*0Sstevel@tonic-gate return (WALK_ERR); 864*0Sstevel@tonic-gate } 865*0Sstevel@tonic-gate if (addr == NULL) 866*0Sstevel@tonic-gate return (WALK_DONE); 867*0Sstevel@tonic-gate wsp->walk_addr = addr; 868*0Sstevel@tonic-gate wsp->walk_data = (void *)addr; 869*0Sstevel@tonic-gate return (WALK_NEXT); 870*0Sstevel@tonic-gate } 871*0Sstevel@tonic-gate 872*0Sstevel@tonic-gate static int 873*0Sstevel@tonic-gate ulwp_walk_step(mdb_walk_state_t *wsp) 874*0Sstevel@tonic-gate { 875*0Sstevel@tonic-gate uintptr_t addr = wsp->walk_addr; 876*0Sstevel@tonic-gate ulwp_t ulwp; 877*0Sstevel@tonic-gate 878*0Sstevel@tonic-gate if (addr == NULL) 879*0Sstevel@tonic-gate return (WALK_DONE); 880*0Sstevel@tonic-gate if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && 881*0Sstevel@tonic-gate (bzero(&ulwp, sizeof (ulwp)), 882*0Sstevel@tonic-gate mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { 883*0Sstevel@tonic-gate mdb_warn("failed to read ulwp at 0x%p", addr); 884*0Sstevel@tonic-gate return (WALK_ERR); 885*0Sstevel@tonic-gate } 886*0Sstevel@tonic-gate /* 887*0Sstevel@tonic-gate * If we have looped around to the beginning 888*0Sstevel@tonic-gate * of the circular linked list, we are done. 889*0Sstevel@tonic-gate */ 890*0Sstevel@tonic-gate if ((wsp->walk_addr = (uintptr_t)ulwp.ul_forw) 891*0Sstevel@tonic-gate == (uintptr_t)wsp->walk_data) 892*0Sstevel@tonic-gate wsp->walk_addr = NULL; 893*0Sstevel@tonic-gate return (wsp->walk_callback(addr, &ulwp, wsp->walk_cbdata)); 894*0Sstevel@tonic-gate } 895*0Sstevel@tonic-gate 896*0Sstevel@tonic-gate /* 897*0Sstevel@tonic-gate * ======================================================= 898*0Sstevel@tonic-gate * End of thread (previously libthread) interfaces. 899*0Sstevel@tonic-gate * ==================== threads ========================== 900*0Sstevel@tonic-gate */ 901*0Sstevel@tonic-gate 902*0Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 903*0Sstevel@tonic-gate { "jmp_buf", ":", "print jmp_buf contents", d_jmp_buf, NULL }, 904*0Sstevel@tonic-gate { "sigjmp_buf", ":", "print sigjmp_buf contents", d_sigjmp_buf, NULL }, 905*0Sstevel@tonic-gate { "siginfo", ":", "print siginfo_t structure", d_siginfo, NULL }, 906*0Sstevel@tonic-gate { "ucontext", ":", "print ucontext_t structure", d_ucontext, NULL }, 907*0Sstevel@tonic-gate { "ulwp", ":", "print ulwp_t structure", d_ulwp, NULL }, 908*0Sstevel@tonic-gate { "uberdata", ":", "print uberdata_t structure", d_uberdata, NULL }, 909*0Sstevel@tonic-gate { NULL } 910*0Sstevel@tonic-gate }; 911*0Sstevel@tonic-gate 912*0Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 913*0Sstevel@tonic-gate { "ucontext", "walk ucontext_t uc_link list", 914*0Sstevel@tonic-gate NULL, uc_walk_step, NULL, NULL }, 915*0Sstevel@tonic-gate { "oldcontext", "walk per-lwp oldcontext pointers", 916*0Sstevel@tonic-gate oldc_walk_init, oldc_walk_step, oldc_walk_fini, NULL }, 917*0Sstevel@tonic-gate { "ulwps", "walk list of ulwp_t pointers", 918*0Sstevel@tonic-gate ulwp_walk_init, ulwp_walk_step, NULL, NULL }, 919*0Sstevel@tonic-gate { NULL } 920*0Sstevel@tonic-gate }; 921*0Sstevel@tonic-gate 922*0Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers }; 923*0Sstevel@tonic-gate 924*0Sstevel@tonic-gate const mdb_modinfo_t * 925*0Sstevel@tonic-gate _mdb_init(void) 926*0Sstevel@tonic-gate { 927*0Sstevel@tonic-gate return (&modinfo); 928*0Sstevel@tonic-gate } 929