1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h> 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate int 34*7c478bd9Sstevel@tonic-gate ct_walk_init(mdb_walk_state_t *wsp) 35*7c478bd9Sstevel@tonic-gate { 36*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr != NULL) { 37*7c478bd9Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr + 38*7c478bd9Sstevel@tonic-gate OFFSETOF(ct_type_t, ct_type_avl); 39*7c478bd9Sstevel@tonic-gate } else { 40*7c478bd9Sstevel@tonic-gate GElf_Sym sym; 41*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("contract_avl", &sym)) { 42*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read contract_avl"); 43*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 44*7c478bd9Sstevel@tonic-gate } 45*7c478bd9Sstevel@tonic-gate wsp->walk_addr = sym.st_value; 46*7c478bd9Sstevel@tonic-gate } 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate if (mdb_layered_walk("avl", wsp) == -1) 49*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 52*7c478bd9Sstevel@tonic-gate } 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate int 55*7c478bd9Sstevel@tonic-gate ct_event_walk_init(mdb_walk_state_t *wsp) 56*7c478bd9Sstevel@tonic-gate { 57*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 58*7c478bd9Sstevel@tonic-gate mdb_warn("ct_event walker requires ct_equeue address\n"); 59*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 60*7c478bd9Sstevel@tonic-gate } 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr + 63*7c478bd9Sstevel@tonic-gate OFFSETOF(ct_equeue_t, ctq_events); 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1) 66*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 69*7c478bd9Sstevel@tonic-gate } 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate int 72*7c478bd9Sstevel@tonic-gate ct_listener_walk_init(mdb_walk_state_t *wsp) 73*7c478bd9Sstevel@tonic-gate { 74*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 75*7c478bd9Sstevel@tonic-gate mdb_warn("ct_listener walker requires ct_equeue address\n"); 76*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 77*7c478bd9Sstevel@tonic-gate } 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr + 80*7c478bd9Sstevel@tonic-gate OFFSETOF(ct_equeue_t, ctq_listeners); 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1) 83*7c478bd9Sstevel@tonic-gate return (WALK_ERR); 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 90*7c478bd9Sstevel@tonic-gate int 91*7c478bd9Sstevel@tonic-gate cmd_contract(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 92*7c478bd9Sstevel@tonic-gate { 93*7c478bd9Sstevel@tonic-gate contract_t ct; 94*7c478bd9Sstevel@tonic-gate ct_type_t ctt; 95*7c478bd9Sstevel@tonic-gate char str[32]; 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 98*7c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("contract", "contract", argc, argv) == -1) { 99*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk 'contract'"); 100*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 101*7c478bd9Sstevel@tonic-gate } 102*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 106*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%?s %8s %8s %8s %?s %?s%</u>\n", 107*7c478bd9Sstevel@tonic-gate "ADDR", "ID", "TYPE", "STATE", "OWNER", "REGENT"); 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate if (mdb_vread(&ct, sizeof (ct), addr) != sizeof (ct)) { 110*7c478bd9Sstevel@tonic-gate mdb_warn("error reading contract_t at %p", addr); 111*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate if (mdb_vread(&ctt, sizeof (ctt), (uintptr_t)ct.ct_type) != 114*7c478bd9Sstevel@tonic-gate sizeof (ctt)) { 115*7c478bd9Sstevel@tonic-gate mdb_warn("error reading ct_type_t at %p", ct.ct_type); 116*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate if (mdb_readstr(str, sizeof (str), (uintptr_t)ctt.ct_type_name) == -1) { 119*7c478bd9Sstevel@tonic-gate mdb_warn("error reading contract type name at %p", 120*7c478bd9Sstevel@tonic-gate ctt.ct_type_name); 121*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p %8d %8s %8s %?p %?p\n", addr, ct.ct_id, str, 125*7c478bd9Sstevel@tonic-gate (ct.ct_state == CTS_OWNED) ? "owned" : 126*7c478bd9Sstevel@tonic-gate (ct.ct_state == CTS_INHERITED) ? "inherit" : 127*7c478bd9Sstevel@tonic-gate (ct.ct_state == CTS_ORPHAN) ? "orphan" : "dead", 128*7c478bd9Sstevel@tonic-gate ct.ct_owner, ct.ct_regent); 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate const mdb_bitmask_t ct_event_flags[] = { 134*7c478bd9Sstevel@tonic-gate { "ACK", CTE_ACK, CTE_ACK }, 135*7c478bd9Sstevel@tonic-gate { "INFO", CTE_INFO, CTE_INFO }, 136*7c478bd9Sstevel@tonic-gate { "NEG", CTE_NEG, CTE_NEG }, 137*7c478bd9Sstevel@tonic-gate { NULL } 138*7c478bd9Sstevel@tonic-gate }; 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 142*7c478bd9Sstevel@tonic-gate int 143*7c478bd9Sstevel@tonic-gate cmd_ctevent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 144*7c478bd9Sstevel@tonic-gate { 145*7c478bd9Sstevel@tonic-gate ct_kevent_t cte; 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 148*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) 151*7c478bd9Sstevel@tonic-gate mdb_printf("%<u>%12s %8s %12s %6s %12s %12s %s%</u>\n", 152*7c478bd9Sstevel@tonic-gate "ADDR", "ID", "CONTRACT", "TYPE", "DATA", "GDATA", "FLAGS"); 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate if (mdb_vread(&cte, sizeof (cte), addr) != sizeof (cte)) { 155*7c478bd9Sstevel@tonic-gate mdb_warn("error reading ct_kevent_t at %p", addr); 156*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate mdb_printf("%12p %8llu %12p %6d %12p %12p %b\n", addr, cte.cte_id, 160*7c478bd9Sstevel@tonic-gate cte.cte_contract, cte.cte_type, cte.cte_data, cte.cte_gdata, 161*7c478bd9Sstevel@tonic-gate cte.cte_flags, ct_event_flags); 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate typedef struct findct_data { 167*7c478bd9Sstevel@tonic-gate uintptr_t fc_ctid; 168*7c478bd9Sstevel@tonic-gate uintptr_t fc_addr; 169*7c478bd9Sstevel@tonic-gate boolean_t fc_found; 170*7c478bd9Sstevel@tonic-gate } findct_data_t; 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate static int 173*7c478bd9Sstevel@tonic-gate findct(uintptr_t addr, contract_t *ct, findct_data_t *arg) 174*7c478bd9Sstevel@tonic-gate { 175*7c478bd9Sstevel@tonic-gate if (ct->ct_id == arg->fc_ctid) { 176*7c478bd9Sstevel@tonic-gate arg->fc_found = B_TRUE; 177*7c478bd9Sstevel@tonic-gate arg->fc_addr = addr; 178*7c478bd9Sstevel@tonic-gate return (WALK_DONE); 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate return (WALK_NEXT); 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 185*7c478bd9Sstevel@tonic-gate int 186*7c478bd9Sstevel@tonic-gate cmd_ctid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 187*7c478bd9Sstevel@tonic-gate { 188*7c478bd9Sstevel@tonic-gate findct_data_t fcdata; 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) 191*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate fcdata.fc_ctid = addr; 194*7c478bd9Sstevel@tonic-gate fcdata.fc_found = B_FALSE; 195*7c478bd9Sstevel@tonic-gate if (mdb_walk("contract", (mdb_walk_cb_t)findct, &fcdata) == -1 || 196*7c478bd9Sstevel@tonic-gate !fcdata.fc_found) 197*7c478bd9Sstevel@tonic-gate return (DCMD_ERR); 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate mdb_printf("%lr", fcdata.fc_addr); 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate return (DCMD_OK); 202*7c478bd9Sstevel@tonic-gate } 203