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 <mdb/mdb_modapi.h>
30*0Sstevel@tonic-gate #include <sys/types.h>
31*0Sstevel@tonic-gate #include <sys/contract_impl.h>
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate int
ct_walk_init(mdb_walk_state_t * wsp)34*0Sstevel@tonic-gate ct_walk_init(mdb_walk_state_t *wsp)
35*0Sstevel@tonic-gate {
36*0Sstevel@tonic-gate if (wsp->walk_addr != NULL) {
37*0Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr +
38*0Sstevel@tonic-gate OFFSETOF(ct_type_t, ct_type_avl);
39*0Sstevel@tonic-gate } else {
40*0Sstevel@tonic-gate GElf_Sym sym;
41*0Sstevel@tonic-gate if (mdb_lookup_by_name("contract_avl", &sym)) {
42*0Sstevel@tonic-gate mdb_warn("failed to read contract_avl");
43*0Sstevel@tonic-gate return (WALK_ERR);
44*0Sstevel@tonic-gate }
45*0Sstevel@tonic-gate wsp->walk_addr = sym.st_value;
46*0Sstevel@tonic-gate }
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate if (mdb_layered_walk("avl", wsp) == -1)
49*0Sstevel@tonic-gate return (WALK_ERR);
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate return (WALK_NEXT);
52*0Sstevel@tonic-gate }
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate int
ct_event_walk_init(mdb_walk_state_t * wsp)55*0Sstevel@tonic-gate ct_event_walk_init(mdb_walk_state_t *wsp)
56*0Sstevel@tonic-gate {
57*0Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
58*0Sstevel@tonic-gate mdb_warn("ct_event walker requires ct_equeue address\n");
59*0Sstevel@tonic-gate return (WALK_ERR);
60*0Sstevel@tonic-gate }
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr +
63*0Sstevel@tonic-gate OFFSETOF(ct_equeue_t, ctq_events);
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1)
66*0Sstevel@tonic-gate return (WALK_ERR);
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate return (WALK_NEXT);
69*0Sstevel@tonic-gate }
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate int
ct_listener_walk_init(mdb_walk_state_t * wsp)72*0Sstevel@tonic-gate ct_listener_walk_init(mdb_walk_state_t *wsp)
73*0Sstevel@tonic-gate {
74*0Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
75*0Sstevel@tonic-gate mdb_warn("ct_listener walker requires ct_equeue address\n");
76*0Sstevel@tonic-gate return (WALK_ERR);
77*0Sstevel@tonic-gate }
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate wsp->walk_addr = wsp->walk_addr +
80*0Sstevel@tonic-gate OFFSETOF(ct_equeue_t, ctq_listeners);
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate if (mdb_layered_walk("list", wsp) == -1)
83*0Sstevel@tonic-gate return (WALK_ERR);
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate return (WALK_NEXT);
86*0Sstevel@tonic-gate }
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate /* ARGSUSED */
90*0Sstevel@tonic-gate int
cmd_contract(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)91*0Sstevel@tonic-gate cmd_contract(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
92*0Sstevel@tonic-gate {
93*0Sstevel@tonic-gate contract_t ct;
94*0Sstevel@tonic-gate ct_type_t ctt;
95*0Sstevel@tonic-gate char str[32];
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
98*0Sstevel@tonic-gate if (mdb_walk_dcmd("contract", "contract", argc, argv) == -1) {
99*0Sstevel@tonic-gate mdb_warn("can't walk 'contract'");
100*0Sstevel@tonic-gate return (DCMD_ERR);
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate return (DCMD_OK);
103*0Sstevel@tonic-gate }
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
106*0Sstevel@tonic-gate mdb_printf("%<u>%?s %8s %8s %8s %?s %?s%</u>\n",
107*0Sstevel@tonic-gate "ADDR", "ID", "TYPE", "STATE", "OWNER", "REGENT");
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate if (mdb_vread(&ct, sizeof (ct), addr) != sizeof (ct)) {
110*0Sstevel@tonic-gate mdb_warn("error reading contract_t at %p", addr);
111*0Sstevel@tonic-gate return (DCMD_ERR);
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate if (mdb_vread(&ctt, sizeof (ctt), (uintptr_t)ct.ct_type) !=
114*0Sstevel@tonic-gate sizeof (ctt)) {
115*0Sstevel@tonic-gate mdb_warn("error reading ct_type_t at %p", ct.ct_type);
116*0Sstevel@tonic-gate return (DCMD_ERR);
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate if (mdb_readstr(str, sizeof (str), (uintptr_t)ctt.ct_type_name) == -1) {
119*0Sstevel@tonic-gate mdb_warn("error reading contract type name at %p",
120*0Sstevel@tonic-gate ctt.ct_type_name);
121*0Sstevel@tonic-gate return (DCMD_ERR);
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate mdb_printf("%0?p %8d %8s %8s %?p %?p\n", addr, ct.ct_id, str,
125*0Sstevel@tonic-gate (ct.ct_state == CTS_OWNED) ? "owned" :
126*0Sstevel@tonic-gate (ct.ct_state == CTS_INHERITED) ? "inherit" :
127*0Sstevel@tonic-gate (ct.ct_state == CTS_ORPHAN) ? "orphan" : "dead",
128*0Sstevel@tonic-gate ct.ct_owner, ct.ct_regent);
129*0Sstevel@tonic-gate
130*0Sstevel@tonic-gate return (DCMD_OK);
131*0Sstevel@tonic-gate }
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate const mdb_bitmask_t ct_event_flags[] = {
134*0Sstevel@tonic-gate { "ACK", CTE_ACK, CTE_ACK },
135*0Sstevel@tonic-gate { "INFO", CTE_INFO, CTE_INFO },
136*0Sstevel@tonic-gate { "NEG", CTE_NEG, CTE_NEG },
137*0Sstevel@tonic-gate { NULL }
138*0Sstevel@tonic-gate };
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate /* ARGSUSED */
142*0Sstevel@tonic-gate int
cmd_ctevent(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)143*0Sstevel@tonic-gate cmd_ctevent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
144*0Sstevel@tonic-gate {
145*0Sstevel@tonic-gate ct_kevent_t cte;
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
148*0Sstevel@tonic-gate return (DCMD_USAGE);
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
151*0Sstevel@tonic-gate mdb_printf("%<u>%12s %8s %12s %6s %12s %12s %s%</u>\n",
152*0Sstevel@tonic-gate "ADDR", "ID", "CONTRACT", "TYPE", "DATA", "GDATA", "FLAGS");
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate if (mdb_vread(&cte, sizeof (cte), addr) != sizeof (cte)) {
155*0Sstevel@tonic-gate mdb_warn("error reading ct_kevent_t at %p", addr);
156*0Sstevel@tonic-gate return (DCMD_ERR);
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate mdb_printf("%12p %8llu %12p %6d %12p %12p %b\n", addr, cte.cte_id,
160*0Sstevel@tonic-gate cte.cte_contract, cte.cte_type, cte.cte_data, cte.cte_gdata,
161*0Sstevel@tonic-gate cte.cte_flags, ct_event_flags);
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate return (DCMD_OK);
164*0Sstevel@tonic-gate }
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate typedef struct findct_data {
167*0Sstevel@tonic-gate uintptr_t fc_ctid;
168*0Sstevel@tonic-gate uintptr_t fc_addr;
169*0Sstevel@tonic-gate boolean_t fc_found;
170*0Sstevel@tonic-gate } findct_data_t;
171*0Sstevel@tonic-gate
172*0Sstevel@tonic-gate static int
findct(uintptr_t addr,contract_t * ct,findct_data_t * arg)173*0Sstevel@tonic-gate findct(uintptr_t addr, contract_t *ct, findct_data_t *arg)
174*0Sstevel@tonic-gate {
175*0Sstevel@tonic-gate if (ct->ct_id == arg->fc_ctid) {
176*0Sstevel@tonic-gate arg->fc_found = B_TRUE;
177*0Sstevel@tonic-gate arg->fc_addr = addr;
178*0Sstevel@tonic-gate return (WALK_DONE);
179*0Sstevel@tonic-gate }
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate return (WALK_NEXT);
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate /* ARGSUSED */
185*0Sstevel@tonic-gate int
cmd_ctid(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)186*0Sstevel@tonic-gate cmd_ctid(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
187*0Sstevel@tonic-gate {
188*0Sstevel@tonic-gate findct_data_t fcdata;
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC))
191*0Sstevel@tonic-gate return (DCMD_USAGE);
192*0Sstevel@tonic-gate
193*0Sstevel@tonic-gate fcdata.fc_ctid = addr;
194*0Sstevel@tonic-gate fcdata.fc_found = B_FALSE;
195*0Sstevel@tonic-gate if (mdb_walk("contract", (mdb_walk_cb_t)findct, &fcdata) == -1 ||
196*0Sstevel@tonic-gate !fcdata.fc_found)
197*0Sstevel@tonic-gate return (DCMD_ERR);
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate mdb_printf("%lr", fcdata.fc_addr);
200*0Sstevel@tonic-gate
201*0Sstevel@tonic-gate return (DCMD_OK);
202*0Sstevel@tonic-gate }
203