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 2004 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 <mdb/mdb_modapi.h> 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #include <pthread.h> 32*0Sstevel@tonic-gate #include <stddef.h> 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #include <libuutil.h> 35*0Sstevel@tonic-gate #include <libuutil_impl.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate /*ARGSUSED*/ 38*0Sstevel@tonic-gate static int 39*0Sstevel@tonic-gate uutil_status(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 40*0Sstevel@tonic-gate { 41*0Sstevel@tonic-gate pthread_t uu_panic_thread = 0; 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) || argc != 0) 44*0Sstevel@tonic-gate return (DCMD_USAGE); 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate if (mdb_readvar(&uu_panic_thread, "uu_panic_thread") == -1) { 47*0Sstevel@tonic-gate mdb_warn("unable to read uu_panic_thread"); 48*0Sstevel@tonic-gate } 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate if (uu_panic_thread != 0) { 51*0Sstevel@tonic-gate mdb_printf("thread %d uu_panicked\n", uu_panic_thread); 52*0Sstevel@tonic-gate } 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate return (DCMD_OK); 55*0Sstevel@tonic-gate } 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate /*ARGSUSED*/ 58*0Sstevel@tonic-gate static int 59*0Sstevel@tonic-gate uutil_listpool(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 60*0Sstevel@tonic-gate { 61*0Sstevel@tonic-gate uu_list_pool_t ulp; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 64*0Sstevel@tonic-gate if (mdb_walk_dcmd("uu_list_pool", "uu_list_pool", argc, 65*0Sstevel@tonic-gate argv) == -1) { 66*0Sstevel@tonic-gate mdb_warn("can't walk uu_list_pool"); 67*0Sstevel@tonic-gate return (DCMD_ERR); 68*0Sstevel@tonic-gate } 69*0Sstevel@tonic-gate return (DCMD_OK); 70*0Sstevel@tonic-gate } 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate if (argc != 0) 73*0Sstevel@tonic-gate return (DCMD_USAGE); 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 76*0Sstevel@tonic-gate mdb_printf("%-?s %-30s %?s %5s\n", 77*0Sstevel@tonic-gate "ADDR", "NAME", "COMPARE", "FLAGS"); 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate if (mdb_vread(&ulp, sizeof (uu_list_pool_t), addr) == -1) { 80*0Sstevel@tonic-gate mdb_warn("failed to read uu_list_pool\n"); 81*0Sstevel@tonic-gate return (DCMD_ERR); 82*0Sstevel@tonic-gate } 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate mdb_printf("%0?p %-30s %08x %c\n", addr, ulp.ulp_name, ulp.ulp_cmp, 85*0Sstevel@tonic-gate ulp.ulp_debug ? 'D' : ' '); 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate return (DCMD_OK); 88*0Sstevel@tonic-gate } 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate /*ARGSUSED*/ 91*0Sstevel@tonic-gate static int 92*0Sstevel@tonic-gate uutil_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 93*0Sstevel@tonic-gate { 94*0Sstevel@tonic-gate uu_list_t ul; 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC) || argc != 0) 97*0Sstevel@tonic-gate return (DCMD_USAGE); 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate if (mdb_vread(&ul, sizeof (uu_list_t), addr) == -1) { 100*0Sstevel@tonic-gate mdb_warn("failed to read uu_list\n"); 101*0Sstevel@tonic-gate return (DCMD_ERR); 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 105*0Sstevel@tonic-gate mdb_printf("%-?s %-?s %-?s %6s %5s\n", 106*0Sstevel@tonic-gate "ADDR", "POOL", "PARENT", "NODES", "FLAGS"); 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate mdb_printf("%0?p %0?p %0?p %6u %c%c\n", 109*0Sstevel@tonic-gate addr, ul.ul_pool, ul.ul_parent, ul.ul_numnodes, 110*0Sstevel@tonic-gate ul.ul_sorted ? 'S' : ' ', ul.ul_debug? 'D' : ' '); 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate return (DCMD_OK); 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate typedef struct uutil_listpool_walk { 116*0Sstevel@tonic-gate uintptr_t ulpw_final; 117*0Sstevel@tonic-gate uintptr_t ulpw_current; 118*0Sstevel@tonic-gate } uutil_listpool_walk_t; 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate int 121*0Sstevel@tonic-gate uutil_listpool_walk_init(mdb_walk_state_t *wsp) 122*0Sstevel@tonic-gate { 123*0Sstevel@tonic-gate uu_list_pool_t null_lpool; 124*0Sstevel@tonic-gate uutil_listpool_walk_t *ulpw; 125*0Sstevel@tonic-gate GElf_Sym sym; 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate bzero(&null_lpool, sizeof (uu_list_pool_t)); 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate if (mdb_lookup_by_obj("libuutil.so.1", "uu_null_lpool", &sym) == 130*0Sstevel@tonic-gate -1) { 131*0Sstevel@tonic-gate mdb_warn("failed to find 'uu_null_lpool'\n"); 132*0Sstevel@tonic-gate return (WALK_ERR); 133*0Sstevel@tonic-gate } 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate if (mdb_vread(&null_lpool, sym.st_size, (uintptr_t)sym.st_value) == 136*0Sstevel@tonic-gate -1) { 137*0Sstevel@tonic-gate mdb_warn("failed to read data from 'uu_null_lpool' address\n"); 138*0Sstevel@tonic-gate return (WALK_ERR); 139*0Sstevel@tonic-gate } 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate ulpw = mdb_alloc(sizeof (uutil_listpool_walk_t), UM_SLEEP); 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate ulpw->ulpw_final = (uintptr_t)null_lpool.ulp_prev; 144*0Sstevel@tonic-gate ulpw->ulpw_current = (uintptr_t)null_lpool.ulp_next; 145*0Sstevel@tonic-gate wsp->walk_data = ulpw; 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate return (WALK_NEXT); 148*0Sstevel@tonic-gate } 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate int 151*0Sstevel@tonic-gate uutil_listpool_walk_step(mdb_walk_state_t *wsp) 152*0Sstevel@tonic-gate { 153*0Sstevel@tonic-gate uu_list_pool_t ulp; 154*0Sstevel@tonic-gate uutil_listpool_walk_t *ulpw = wsp->walk_data; 155*0Sstevel@tonic-gate int status; 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate if (mdb_vread(&ulp, sizeof (uu_list_pool_t), 158*0Sstevel@tonic-gate ulpw->ulpw_current) == -1) { 159*0Sstevel@tonic-gate mdb_warn("failed to read uu_list_pool %x", ulpw->ulpw_current); 160*0Sstevel@tonic-gate return (WALK_ERR); 161*0Sstevel@tonic-gate } 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate status = wsp->walk_callback(ulpw->ulpw_current, &ulp, wsp->walk_cbdata); 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate if (ulpw->ulpw_current == ulpw->ulpw_final) 166*0Sstevel@tonic-gate return (WALK_DONE); 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate ulpw->ulpw_current = (uintptr_t)ulp.ulp_next; 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate return (status); 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate void 174*0Sstevel@tonic-gate uutil_listpool_walk_fini(mdb_walk_state_t *wsp) 175*0Sstevel@tonic-gate { 176*0Sstevel@tonic-gate uutil_listpool_walk_t *ulpw = wsp->walk_data; 177*0Sstevel@tonic-gate mdb_free(ulpw, sizeof (uutil_listpool_walk_t)); 178*0Sstevel@tonic-gate } 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate typedef struct uutil_list_walk { 181*0Sstevel@tonic-gate uintptr_t ulw_final; 182*0Sstevel@tonic-gate uintptr_t ulw_current; 183*0Sstevel@tonic-gate } uutil_list_walk_t; 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate int 186*0Sstevel@tonic-gate uutil_list_walk_init(mdb_walk_state_t *wsp) 187*0Sstevel@tonic-gate { 188*0Sstevel@tonic-gate uu_list_t null_list; 189*0Sstevel@tonic-gate uutil_list_walk_t *ulw; 190*0Sstevel@tonic-gate uu_list_pool_t ulp; 191*0Sstevel@tonic-gate 192*0Sstevel@tonic-gate bzero(&null_list, sizeof (uu_list_t)); 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate if (mdb_vread(&ulp, sizeof (uu_list_pool_t), wsp->walk_addr) == -1) { 195*0Sstevel@tonic-gate mdb_warn("failed to read uu_list_pool_t at given address\n"); 196*0Sstevel@tonic-gate return (WALK_ERR); 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate ulw = mdb_alloc(sizeof (uutil_list_walk_t), UM_SLEEP); 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate ulw->ulw_final = (uintptr_t)ulp.ulp_null_list.ul_prev; 202*0Sstevel@tonic-gate ulw->ulw_current = (uintptr_t)ulp.ulp_null_list.ul_next; 203*0Sstevel@tonic-gate wsp->walk_data = ulw; 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate return (WALK_NEXT); 206*0Sstevel@tonic-gate } 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate int 209*0Sstevel@tonic-gate uutil_list_walk_step(mdb_walk_state_t *wsp) 210*0Sstevel@tonic-gate { 211*0Sstevel@tonic-gate uu_list_t ul; 212*0Sstevel@tonic-gate uutil_list_walk_t *ulw = wsp->walk_data; 213*0Sstevel@tonic-gate int status; 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gate if (mdb_vread(&ul, sizeof (uu_list_t), ulw->ulw_current) == -1) { 216*0Sstevel@tonic-gate mdb_warn("failed to read uu_list %x", ulw->ulw_current); 217*0Sstevel@tonic-gate return (WALK_ERR); 218*0Sstevel@tonic-gate } 219*0Sstevel@tonic-gate 220*0Sstevel@tonic-gate status = wsp->walk_callback(ulw->ulw_current, &ul, wsp->walk_cbdata); 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate if (ulw->ulw_current == ulw->ulw_final) 223*0Sstevel@tonic-gate return (WALK_DONE); 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate ulw->ulw_current = (uintptr_t)ul.ul_next; 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate return (status); 228*0Sstevel@tonic-gate } 229*0Sstevel@tonic-gate 230*0Sstevel@tonic-gate void 231*0Sstevel@tonic-gate uutil_list_walk_fini(mdb_walk_state_t *wsp) 232*0Sstevel@tonic-gate { 233*0Sstevel@tonic-gate uutil_list_walk_t *ulw = wsp->walk_data; 234*0Sstevel@tonic-gate mdb_free(ulw, sizeof (uutil_list_walk_t)); 235*0Sstevel@tonic-gate } 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate typedef struct uutil_list_node_walk { 238*0Sstevel@tonic-gate size_t ulnw_offset; 239*0Sstevel@tonic-gate uintptr_t ulnw_final; 240*0Sstevel@tonic-gate uintptr_t ulnw_current; 241*0Sstevel@tonic-gate void *ulnw_buf; 242*0Sstevel@tonic-gate size_t ulnw_bufsz; 243*0Sstevel@tonic-gate } uutil_list_node_walk_t; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate int 246*0Sstevel@tonic-gate uutil_list_node_walk_init(mdb_walk_state_t *wsp) 247*0Sstevel@tonic-gate { 248*0Sstevel@tonic-gate uutil_list_node_walk_t *ulnw; 249*0Sstevel@tonic-gate uu_list_t ul; 250*0Sstevel@tonic-gate uu_list_pool_t ulp; 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate if (mdb_vread(&ul, sizeof (uu_list_t), wsp->walk_addr) == -1) { 253*0Sstevel@tonic-gate mdb_warn("failed to read uu_list_t at given address\n"); 254*0Sstevel@tonic-gate return (WALK_ERR); 255*0Sstevel@tonic-gate } 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gate if (mdb_vread(&ulp, sizeof (uu_list_pool_t), (uintptr_t)ul.ul_pool) == 258*0Sstevel@tonic-gate -1) { 259*0Sstevel@tonic-gate mdb_warn("failed to read supporting uu_list_pool_t\n"); 260*0Sstevel@tonic-gate return (WALK_ERR); 261*0Sstevel@tonic-gate } 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate ulnw = mdb_alloc(sizeof (uutil_list_node_walk_t), UM_SLEEP); 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate ulnw->ulnw_offset = ul.ul_offset; 266*0Sstevel@tonic-gate ulnw->ulnw_final = wsp->walk_addr + offsetof(uu_list_t, ul_null_node); 267*0Sstevel@tonic-gate ulnw->ulnw_current = (uintptr_t)ul.ul_null_node.uln_next; 268*0Sstevel@tonic-gate ulnw->ulnw_buf = mdb_alloc(ulp.ulp_objsize, UM_SLEEP); 269*0Sstevel@tonic-gate ulnw->ulnw_bufsz = ulp.ulp_objsize; 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate wsp->walk_data = ulnw; 272*0Sstevel@tonic-gate 273*0Sstevel@tonic-gate return (WALK_NEXT); 274*0Sstevel@tonic-gate } 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate int 277*0Sstevel@tonic-gate uutil_list_node_walk_step(mdb_walk_state_t *wsp) 278*0Sstevel@tonic-gate { 279*0Sstevel@tonic-gate uu_list_node_impl_t uln; 280*0Sstevel@tonic-gate uutil_list_node_walk_t *ulnw = wsp->walk_data; 281*0Sstevel@tonic-gate int status; 282*0Sstevel@tonic-gate uintptr_t diff; 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gate if (ulnw->ulnw_current == ulnw->ulnw_final) 285*0Sstevel@tonic-gate return (WALK_DONE); 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate if (mdb_vread(&uln, sizeof (uu_list_node_impl_t), ulnw->ulnw_current) == 288*0Sstevel@tonic-gate -1) { 289*0Sstevel@tonic-gate mdb_warn("failed to read uu_list_node %x", ulnw->ulnw_current); 290*0Sstevel@tonic-gate return (WALK_ERR); 291*0Sstevel@tonic-gate } 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate diff = ulnw->ulnw_current - ulnw->ulnw_offset; 294*0Sstevel@tonic-gate 295*0Sstevel@tonic-gate if (mdb_vread(ulnw->ulnw_buf, ulnw->ulnw_bufsz, diff) == -1) { 296*0Sstevel@tonic-gate mdb_warn("failed to read enclosing structure %x", diff); 297*0Sstevel@tonic-gate return (WALK_ERR); 298*0Sstevel@tonic-gate } 299*0Sstevel@tonic-gate /* 300*0Sstevel@tonic-gate * Correct for offset; we return the address of the included structure. 301*0Sstevel@tonic-gate */ 302*0Sstevel@tonic-gate status = wsp->walk_callback(diff, ulnw->ulnw_buf, wsp->walk_cbdata); 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate ulnw->ulnw_current = (uintptr_t)uln.uln_next; 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate return (status); 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate void 310*0Sstevel@tonic-gate uutil_list_node_walk_fini(mdb_walk_state_t *wsp) 311*0Sstevel@tonic-gate { 312*0Sstevel@tonic-gate uutil_list_node_walk_t *ulnw = wsp->walk_data; 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate mdb_free(ulnw->ulnw_buf, ulnw->ulnw_bufsz); 315*0Sstevel@tonic-gate mdb_free(ulnw, sizeof (uutil_list_node_walk_t)); 316*0Sstevel@tonic-gate } 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 319*0Sstevel@tonic-gate { "uutil_status", NULL, "libuutil status summary", uutil_status }, 320*0Sstevel@tonic-gate { "uu_list_pool", NULL, "display uu_list_pool information", 321*0Sstevel@tonic-gate uutil_listpool }, 322*0Sstevel@tonic-gate { "uu_list", NULL, "display uu_list information", 323*0Sstevel@tonic-gate uutil_list }, 324*0Sstevel@tonic-gate { NULL } 325*0Sstevel@tonic-gate }; 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 328*0Sstevel@tonic-gate { "uu_list_pool", "walk uu_list_pools", 329*0Sstevel@tonic-gate uutil_listpool_walk_init, uutil_listpool_walk_step, 330*0Sstevel@tonic-gate uutil_listpool_walk_fini }, 331*0Sstevel@tonic-gate { "uu_list", "given a uu_list_pool, walk its uu_lists", 332*0Sstevel@tonic-gate uutil_list_walk_init, uutil_list_walk_step, 333*0Sstevel@tonic-gate uutil_list_walk_fini }, 334*0Sstevel@tonic-gate { "uu_list_node", 335*0Sstevel@tonic-gate "given a uu_list, walk its nodes, returning container addr", 336*0Sstevel@tonic-gate uutil_list_node_walk_init, uutil_list_node_walk_step, 337*0Sstevel@tonic-gate uutil_list_node_walk_fini }, 338*0Sstevel@tonic-gate { NULL } 339*0Sstevel@tonic-gate }; 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { 342*0Sstevel@tonic-gate MDB_API_VERSION, dcmds, walkers 343*0Sstevel@tonic-gate }; 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gate const mdb_modinfo_t * 346*0Sstevel@tonic-gate _mdb_init(void) 347*0Sstevel@tonic-gate { 348*0Sstevel@tonic-gate return (&modinfo); 349*0Sstevel@tonic-gate } 350