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 2001-2002 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 <sys/time.h>
30*7c478bd9Sstevel@tonic-gate #include <ipp/ipp.h>
31*7c478bd9Sstevel@tonic-gate #include <ipp/ipp_impl.h>
32*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate static uintptr_t ipp_mod_byid;
35*7c478bd9Sstevel@tonic-gate static uintptr_t ipp_action_byid;
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate static int byid_walk_init(mdb_walk_state_t *);
38*7c478bd9Sstevel@tonic-gate static int byid_walk_step(mdb_walk_state_t *);
39*7c478bd9Sstevel@tonic-gate static void byid_walk_fini(mdb_walk_state_t *);
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate static int action(uintptr_t, uint_t, int, const mdb_arg_t *);
42*7c478bd9Sstevel@tonic-gate static int action_format(uintptr_t, const void *, void *);
43*7c478bd9Sstevel@tonic-gate static int action_dump(uintptr_t, ipp_action_t *, boolean_t);
44*7c478bd9Sstevel@tonic-gate static int action_summary(uintptr_t, ipp_action_t *, boolean_t);
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate static int cfglock(uintptr_t, uint_t, int, const mdb_arg_t *);
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate static int mod(uintptr_t, uint_t, int, const mdb_arg_t *);
49*7c478bd9Sstevel@tonic-gate static int mod_format(uintptr_t, const void *, void *);
50*7c478bd9Sstevel@tonic-gate static int mod_dump(uintptr_t, ipp_mod_t *, boolean_t);
51*7c478bd9Sstevel@tonic-gate static int mod_summary(uintptr_t, ipp_mod_t *, boolean_t);
52*7c478bd9Sstevel@tonic-gate static int cfglock(uintptr_t, uint_t, int, const mdb_arg_t *);
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate static int ippops(uintptr_t, uint_t, int, const mdb_arg_t *);
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate static int packet(uintptr_t, uint_t, int, const mdb_arg_t *);
57*7c478bd9Sstevel@tonic-gate static void dump_classes(uintptr_t, uint_t);
58*7c478bd9Sstevel@tonic-gate static void dump_log(uintptr_t, uint_t);
59*7c478bd9Sstevel@tonic-gate static void aid2aname(ipp_action_id_t, char *);
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate static int ref_walk_init(mdb_walk_state_t *);
62*7c478bd9Sstevel@tonic-gate static int ref_walk_step(mdb_walk_state_t *);
63*7c478bd9Sstevel@tonic-gate static void ref_walk_fini(mdb_walk_state_t *);
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate typedef struct afdata {
66*7c478bd9Sstevel@tonic-gate boolean_t af_banner;
67*7c478bd9Sstevel@tonic-gate uint_t af_flags;
68*7c478bd9Sstevel@tonic-gate } afdata_t;
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate #define AF_VERBOSE 1
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate typedef struct mfdata {
73*7c478bd9Sstevel@tonic-gate boolean_t mf_banner;
74*7c478bd9Sstevel@tonic-gate uint_t mf_flags;
75*7c478bd9Sstevel@tonic-gate } mfdata_t;
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate #define MF_VERBOSE 1
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate * walker. Skips entries that are NULL.
81*7c478bd9Sstevel@tonic-gate */
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate static int
byid_walk_init(mdb_walk_state_t * wsp)84*7c478bd9Sstevel@tonic-gate byid_walk_init(
85*7c478bd9Sstevel@tonic-gate mdb_walk_state_t *wsp)
86*7c478bd9Sstevel@tonic-gate {
87*7c478bd9Sstevel@tonic-gate uintptr_t start;
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate if (mdb_vread(&start, sizeof (uintptr_t), wsp->walk_addr) == -1) {
90*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read from address %p", wsp->walk_addr);
91*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate wsp->walk_addr = start;
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate static int
byid_walk_step(mdb_walk_state_t * wsp)100*7c478bd9Sstevel@tonic-gate byid_walk_step(
101*7c478bd9Sstevel@tonic-gate mdb_walk_state_t *wsp)
102*7c478bd9Sstevel@tonic-gate {
103*7c478bd9Sstevel@tonic-gate int status;
104*7c478bd9Sstevel@tonic-gate void *ptr;
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate if (mdb_vread(&ptr, sizeof (void *), wsp->walk_addr) == -1) {
107*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read from address %p", wsp->walk_addr);
108*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate if (ptr == (void *)-1) {
112*7c478bd9Sstevel@tonic-gate status = WALK_DONE;
113*7c478bd9Sstevel@tonic-gate } else if (ptr == NULL) {
114*7c478bd9Sstevel@tonic-gate status = WALK_NEXT;
115*7c478bd9Sstevel@tonic-gate } else {
116*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback((uintptr_t)ptr, NULL,
117*7c478bd9Sstevel@tonic-gate wsp->walk_cbdata);
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate wsp->walk_addr += sizeof (void *);
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate return (status);
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
126*7c478bd9Sstevel@tonic-gate static void
byid_walk_fini(mdb_walk_state_t * wsp)127*7c478bd9Sstevel@tonic-gate byid_walk_fini(
128*7c478bd9Sstevel@tonic-gate mdb_walk_state_t *wsp)
129*7c478bd9Sstevel@tonic-gate {
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
134*7c478bd9Sstevel@tonic-gate static int
action(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)135*7c478bd9Sstevel@tonic-gate action(
136*7c478bd9Sstevel@tonic-gate uintptr_t addr,
137*7c478bd9Sstevel@tonic-gate uint_t flags,
138*7c478bd9Sstevel@tonic-gate int argc,
139*7c478bd9Sstevel@tonic-gate const mdb_arg_t *argv)
140*7c478bd9Sstevel@tonic-gate {
141*7c478bd9Sstevel@tonic-gate int status;
142*7c478bd9Sstevel@tonic-gate int rc = DCMD_OK;
143*7c478bd9Sstevel@tonic-gate afdata_t *afp;
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate afp = mdb_zalloc(sizeof (afdata_t), UM_SLEEP);
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
148*7c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, AF_VERBOSE, &afp->af_flags,
149*7c478bd9Sstevel@tonic-gate NULL) != argc)
150*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP))
153*7c478bd9Sstevel@tonic-gate afp->af_banner = B_TRUE;
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
156*7c478bd9Sstevel@tonic-gate status = action_format(addr, NULL, afp);
157*7c478bd9Sstevel@tonic-gate rc = (status == WALK_NEXT) ? DCMD_OK : DCMD_ERR;
158*7c478bd9Sstevel@tonic-gate goto cleanup;
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("ipp_byid", action_format, afp,
162*7c478bd9Sstevel@tonic-gate ipp_action_byid) == -1) {
163*7c478bd9Sstevel@tonic-gate mdb_warn("failed to execute ipp_byid walk");
164*7c478bd9Sstevel@tonic-gate rc = DCMD_ERR;
165*7c478bd9Sstevel@tonic-gate }
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gate cleanup:
168*7c478bd9Sstevel@tonic-gate mdb_free(afp, sizeof (afdata_t));
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate return (rc);
171*7c478bd9Sstevel@tonic-gate }
172*7c478bd9Sstevel@tonic-gate
173*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
174*7c478bd9Sstevel@tonic-gate static int
action_format(uintptr_t addr,const void * data,void * arg)175*7c478bd9Sstevel@tonic-gate action_format(
176*7c478bd9Sstevel@tonic-gate uintptr_t addr,
177*7c478bd9Sstevel@tonic-gate const void *data,
178*7c478bd9Sstevel@tonic-gate void *arg)
179*7c478bd9Sstevel@tonic-gate {
180*7c478bd9Sstevel@tonic-gate afdata_t *afp = (afdata_t *)arg;
181*7c478bd9Sstevel@tonic-gate ipp_action_t *ap;
182*7c478bd9Sstevel@tonic-gate int rc;
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gate ap = mdb_alloc(sizeof (ipp_action_t), UM_SLEEP);
185*7c478bd9Sstevel@tonic-gate if (mdb_vread(ap, sizeof (ipp_action_t), addr) == -1) {
186*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_action_t at %p", addr);
187*7c478bd9Sstevel@tonic-gate rc = WALK_ERR;
188*7c478bd9Sstevel@tonic-gate goto done;
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate
191*7c478bd9Sstevel@tonic-gate if (afp->af_flags & AF_VERBOSE)
192*7c478bd9Sstevel@tonic-gate rc = action_dump(addr, ap, afp->af_banner);
193*7c478bd9Sstevel@tonic-gate else
194*7c478bd9Sstevel@tonic-gate rc = action_summary(addr, ap, afp->af_banner);
195*7c478bd9Sstevel@tonic-gate
196*7c478bd9Sstevel@tonic-gate afp->af_banner = B_FALSE;
197*7c478bd9Sstevel@tonic-gate done:
198*7c478bd9Sstevel@tonic-gate mdb_free(ap, sizeof (ipp_action_t));
199*7c478bd9Sstevel@tonic-gate return (rc);
200*7c478bd9Sstevel@tonic-gate }
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
203*7c478bd9Sstevel@tonic-gate static int
action_dump(uintptr_t addr,ipp_action_t * ap,boolean_t banner)204*7c478bd9Sstevel@tonic-gate action_dump(
205*7c478bd9Sstevel@tonic-gate uintptr_t addr,
206*7c478bd9Sstevel@tonic-gate ipp_action_t *ap,
207*7c478bd9Sstevel@tonic-gate boolean_t banner)
208*7c478bd9Sstevel@tonic-gate {
209*7c478bd9Sstevel@tonic-gate mdb_printf("%?p: %20s = %d\n", addr, "id", ap->ippa_id);
210*7c478bd9Sstevel@tonic-gate if (!ap->ippa_nameless) {
211*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "name", ap->ippa_name);
212*7c478bd9Sstevel@tonic-gate }
213*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "mod", ap->ippa_mod);
214*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "ref", ap->ippa_ref);
215*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "refby", ap->ippa_refby);
216*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "ptr", ap->ippa_ptr);
217*7c478bd9Sstevel@tonic-gate
218*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = ", "", "state");
219*7c478bd9Sstevel@tonic-gate switch (ap->ippa_state) {
220*7c478bd9Sstevel@tonic-gate case IPP_ASTATE_PROTO:
221*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", "PROTO");
222*7c478bd9Sstevel@tonic-gate break;
223*7c478bd9Sstevel@tonic-gate case IPP_ASTATE_CONFIG_PENDING:
224*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", "CONFIG_PENDING");
225*7c478bd9Sstevel@tonic-gate break;
226*7c478bd9Sstevel@tonic-gate case IPP_ASTATE_AVAILABLE:
227*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", "AVAILABLE");
228*7c478bd9Sstevel@tonic-gate break;
229*7c478bd9Sstevel@tonic-gate default:
230*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", "<unknown>");
231*7c478bd9Sstevel@tonic-gate break;
232*7c478bd9Sstevel@tonic-gate }
233*7c478bd9Sstevel@tonic-gate
234*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %d\n", "", "packets", ap->ippa_packets);
235*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %d\n", "", "hold_count", ap->ippa_hold_count);
236*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "destruct_pending",
237*7c478bd9Sstevel@tonic-gate (ap->ippa_destruct_pending) ? "TRUE" : "FALSE");
238*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "lock",
239*7c478bd9Sstevel@tonic-gate addr + ((uintptr_t)ap->ippa_lock - (uintptr_t)ap));
240*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "config_lock",
241*7c478bd9Sstevel@tonic-gate addr + ((uintptr_t)ap->ippa_config_lock - (uintptr_t)ap));
242*7c478bd9Sstevel@tonic-gate mdb_printf("\n");
243*7c478bd9Sstevel@tonic-gate
244*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
245*7c478bd9Sstevel@tonic-gate }
246*7c478bd9Sstevel@tonic-gate
247*7c478bd9Sstevel@tonic-gate static int
action_summary(uintptr_t addr,ipp_action_t * ap,boolean_t banner)248*7c478bd9Sstevel@tonic-gate action_summary(
249*7c478bd9Sstevel@tonic-gate uintptr_t addr,
250*7c478bd9Sstevel@tonic-gate ipp_action_t *ap,
251*7c478bd9Sstevel@tonic-gate boolean_t banner)
252*7c478bd9Sstevel@tonic-gate {
253*7c478bd9Sstevel@tonic-gate ipp_mod_t *imp;
254*7c478bd9Sstevel@tonic-gate uintptr_t ptr;
255*7c478bd9Sstevel@tonic-gate
256*7c478bd9Sstevel@tonic-gate if (banner)
257*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %<u>%20s %5s %20s%</u>\n",
258*7c478bd9Sstevel@tonic-gate "", "NAME", "ID", "MODNAME");
259*7c478bd9Sstevel@tonic-gate
260*7c478bd9Sstevel@tonic-gate imp = mdb_alloc(sizeof (ipp_mod_t), UM_SLEEP);
261*7c478bd9Sstevel@tonic-gate ptr = (uintptr_t)ap->ippa_mod;
262*7c478bd9Sstevel@tonic-gate if (mdb_vread(imp, sizeof (ipp_mod_t), ptr) == -1) {
263*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_mod_t at %p", ptr);
264*7c478bd9Sstevel@tonic-gate mdb_free(imp, sizeof (ipp_mod_t));
265*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
266*7c478bd9Sstevel@tonic-gate }
267*7c478bd9Sstevel@tonic-gate
268*7c478bd9Sstevel@tonic-gate mdb_printf("%?p:%20s %5d %20s\n", addr, ap->ippa_name, ap->ippa_id,
269*7c478bd9Sstevel@tonic-gate imp->ippm_name);
270*7c478bd9Sstevel@tonic-gate
271*7c478bd9Sstevel@tonic-gate mdb_free(imp, sizeof (ipp_mod_t));
272*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
273*7c478bd9Sstevel@tonic-gate }
274*7c478bd9Sstevel@tonic-gate
275*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
276*7c478bd9Sstevel@tonic-gate static int
cfglock(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)277*7c478bd9Sstevel@tonic-gate cfglock(
278*7c478bd9Sstevel@tonic-gate uintptr_t addr,
279*7c478bd9Sstevel@tonic-gate uint_t flags,
280*7c478bd9Sstevel@tonic-gate int argc,
281*7c478bd9Sstevel@tonic-gate const mdb_arg_t *argv)
282*7c478bd9Sstevel@tonic-gate {
283*7c478bd9Sstevel@tonic-gate cfglock_t *clp;
284*7c478bd9Sstevel@tonic-gate
285*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0)
286*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
287*7c478bd9Sstevel@tonic-gate
288*7c478bd9Sstevel@tonic-gate clp = mdb_alloc(sizeof (cfglock_t), UM_SLEEP);
289*7c478bd9Sstevel@tonic-gate if (mdb_vread(clp, sizeof (cfglock_t), addr) == -1) {
290*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read cfglock_t at %p", addr);
291*7c478bd9Sstevel@tonic-gate mdb_free(clp, sizeof (cfglock_t));
292*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
293*7c478bd9Sstevel@tonic-gate }
294*7c478bd9Sstevel@tonic-gate
295*7c478bd9Sstevel@tonic-gate mdb_printf("%?p: %20s = %p\n", addr, "owner", clp->cl_owner);
296*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "reader",
297*7c478bd9Sstevel@tonic-gate clp->cl_reader ? "TRUE" : "FALSE");
298*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %d\n", "", "writers", clp->cl_writers);
299*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "mutex",
300*7c478bd9Sstevel@tonic-gate addr + ((uintptr_t)clp->cl_mutex - (uintptr_t)clp));
301*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "cv",
302*7c478bd9Sstevel@tonic-gate addr + ((uintptr_t)clp->cl_cv - (uintptr_t)clp));
303*7c478bd9Sstevel@tonic-gate mdb_printf("\n");
304*7c478bd9Sstevel@tonic-gate
305*7c478bd9Sstevel@tonic-gate mdb_free(clp, sizeof (cfglock_t));
306*7c478bd9Sstevel@tonic-gate
307*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
308*7c478bd9Sstevel@tonic-gate }
309*7c478bd9Sstevel@tonic-gate
310*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
311*7c478bd9Sstevel@tonic-gate static int
mod(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)312*7c478bd9Sstevel@tonic-gate mod(
313*7c478bd9Sstevel@tonic-gate uintptr_t addr,
314*7c478bd9Sstevel@tonic-gate uint_t flags,
315*7c478bd9Sstevel@tonic-gate int argc,
316*7c478bd9Sstevel@tonic-gate const mdb_arg_t *argv)
317*7c478bd9Sstevel@tonic-gate {
318*7c478bd9Sstevel@tonic-gate int status;
319*7c478bd9Sstevel@tonic-gate int rc = DCMD_OK;
320*7c478bd9Sstevel@tonic-gate mfdata_t *mfp;
321*7c478bd9Sstevel@tonic-gate
322*7c478bd9Sstevel@tonic-gate mfp = mdb_zalloc(sizeof (mfdata_t), UM_SLEEP);
323*7c478bd9Sstevel@tonic-gate
324*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
325*7c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, MF_VERBOSE, &mfp->mf_flags,
326*7c478bd9Sstevel@tonic-gate NULL) != argc)
327*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
328*7c478bd9Sstevel@tonic-gate
329*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP))
330*7c478bd9Sstevel@tonic-gate mfp->mf_banner = B_TRUE;
331*7c478bd9Sstevel@tonic-gate
332*7c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
333*7c478bd9Sstevel@tonic-gate status = mod_format(addr, NULL, mfp);
334*7c478bd9Sstevel@tonic-gate rc = (status == WALK_NEXT) ? DCMD_OK : DCMD_ERR;
335*7c478bd9Sstevel@tonic-gate goto cleanup;
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate
338*7c478bd9Sstevel@tonic-gate if (mdb_pwalk("ipp_byid", mod_format, mfp,
339*7c478bd9Sstevel@tonic-gate ipp_mod_byid) == -1) {
340*7c478bd9Sstevel@tonic-gate mdb_warn("failed to execute ipp_byid walk");
341*7c478bd9Sstevel@tonic-gate rc = DCMD_ERR;
342*7c478bd9Sstevel@tonic-gate }
343*7c478bd9Sstevel@tonic-gate
344*7c478bd9Sstevel@tonic-gate cleanup:
345*7c478bd9Sstevel@tonic-gate mdb_free(mfp, sizeof (mfdata_t));
346*7c478bd9Sstevel@tonic-gate
347*7c478bd9Sstevel@tonic-gate return (rc);
348*7c478bd9Sstevel@tonic-gate }
349*7c478bd9Sstevel@tonic-gate
350*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
351*7c478bd9Sstevel@tonic-gate static int
mod_format(uintptr_t addr,const void * data,void * arg)352*7c478bd9Sstevel@tonic-gate mod_format(
353*7c478bd9Sstevel@tonic-gate uintptr_t addr,
354*7c478bd9Sstevel@tonic-gate const void *data,
355*7c478bd9Sstevel@tonic-gate void *arg)
356*7c478bd9Sstevel@tonic-gate {
357*7c478bd9Sstevel@tonic-gate mfdata_t *mfp = (mfdata_t *)arg;
358*7c478bd9Sstevel@tonic-gate ipp_mod_t *imp;
359*7c478bd9Sstevel@tonic-gate int rc;
360*7c478bd9Sstevel@tonic-gate
361*7c478bd9Sstevel@tonic-gate imp = mdb_alloc(sizeof (ipp_mod_t), UM_SLEEP);
362*7c478bd9Sstevel@tonic-gate if (mdb_vread(imp, sizeof (ipp_mod_t), addr) == -1) {
363*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_mod_t at %p", addr);
364*7c478bd9Sstevel@tonic-gate rc = WALK_ERR;
365*7c478bd9Sstevel@tonic-gate goto done;
366*7c478bd9Sstevel@tonic-gate }
367*7c478bd9Sstevel@tonic-gate
368*7c478bd9Sstevel@tonic-gate if (mfp->mf_flags & MF_VERBOSE)
369*7c478bd9Sstevel@tonic-gate rc = mod_dump(addr, imp, mfp->mf_banner);
370*7c478bd9Sstevel@tonic-gate else
371*7c478bd9Sstevel@tonic-gate rc = mod_summary(addr, imp, mfp->mf_banner);
372*7c478bd9Sstevel@tonic-gate
373*7c478bd9Sstevel@tonic-gate mfp->mf_banner = B_FALSE;
374*7c478bd9Sstevel@tonic-gate done:
375*7c478bd9Sstevel@tonic-gate mdb_free(imp, sizeof (ipp_mod_t));
376*7c478bd9Sstevel@tonic-gate return (rc);
377*7c478bd9Sstevel@tonic-gate }
378*7c478bd9Sstevel@tonic-gate
379*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
380*7c478bd9Sstevel@tonic-gate static int
mod_dump(uintptr_t addr,ipp_mod_t * imp,boolean_t banner)381*7c478bd9Sstevel@tonic-gate mod_dump(
382*7c478bd9Sstevel@tonic-gate uintptr_t addr,
383*7c478bd9Sstevel@tonic-gate ipp_mod_t *imp,
384*7c478bd9Sstevel@tonic-gate boolean_t banner)
385*7c478bd9Sstevel@tonic-gate {
386*7c478bd9Sstevel@tonic-gate mdb_printf("%?p: %20s = %d\n", addr, "id", imp->ippm_id);
387*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "name", imp->ippm_name);
388*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "ops", imp->ippm_ops);
389*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "action", imp->ippm_action);
390*7c478bd9Sstevel@tonic-gate
391*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = ", "", "state");
392*7c478bd9Sstevel@tonic-gate switch (imp->ippm_state) {
393*7c478bd9Sstevel@tonic-gate case IPP_MODSTATE_PROTO:
394*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", "PROTO");
395*7c478bd9Sstevel@tonic-gate break;
396*7c478bd9Sstevel@tonic-gate case IPP_MODSTATE_AVAILABLE:
397*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", "AVAILABLE");
398*7c478bd9Sstevel@tonic-gate break;
399*7c478bd9Sstevel@tonic-gate default:
400*7c478bd9Sstevel@tonic-gate mdb_printf("%s\n", "<unknown>");
401*7c478bd9Sstevel@tonic-gate break;
402*7c478bd9Sstevel@tonic-gate }
403*7c478bd9Sstevel@tonic-gate
404*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %d\n", "", "hold_count", imp->ippm_hold_count);
405*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "destruct_pending",
406*7c478bd9Sstevel@tonic-gate (imp->ippm_destruct_pending) ? "TRUE" : "FALSE");
407*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "lock",
408*7c478bd9Sstevel@tonic-gate addr + ((uintptr_t)imp->ippm_lock - (uintptr_t)imp));
409*7c478bd9Sstevel@tonic-gate mdb_printf("\n");
410*7c478bd9Sstevel@tonic-gate
411*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
412*7c478bd9Sstevel@tonic-gate }
413*7c478bd9Sstevel@tonic-gate
414*7c478bd9Sstevel@tonic-gate static int
mod_summary(uintptr_t addr,ipp_mod_t * imp,boolean_t banner)415*7c478bd9Sstevel@tonic-gate mod_summary(
416*7c478bd9Sstevel@tonic-gate uintptr_t addr,
417*7c478bd9Sstevel@tonic-gate ipp_mod_t *imp,
418*7c478bd9Sstevel@tonic-gate boolean_t banner)
419*7c478bd9Sstevel@tonic-gate {
420*7c478bd9Sstevel@tonic-gate if (banner)
421*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %<u>%20s %5s%</u>\n",
422*7c478bd9Sstevel@tonic-gate "", "NAME", "ID");
423*7c478bd9Sstevel@tonic-gate
424*7c478bd9Sstevel@tonic-gate mdb_printf("%?p:%20s %5d\n", addr, imp->ippm_name, imp->ippm_id);
425*7c478bd9Sstevel@tonic-gate
426*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
427*7c478bd9Sstevel@tonic-gate }
428*7c478bd9Sstevel@tonic-gate
429*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
430*7c478bd9Sstevel@tonic-gate static int
ippops(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)431*7c478bd9Sstevel@tonic-gate ippops(
432*7c478bd9Sstevel@tonic-gate uintptr_t addr,
433*7c478bd9Sstevel@tonic-gate uint_t flags,
434*7c478bd9Sstevel@tonic-gate int argc,
435*7c478bd9Sstevel@tonic-gate const mdb_arg_t *argv)
436*7c478bd9Sstevel@tonic-gate {
437*7c478bd9Sstevel@tonic-gate ipp_ops_t *ippo;
438*7c478bd9Sstevel@tonic-gate GElf_Sym sym;
439*7c478bd9Sstevel@tonic-gate char buf[MDB_SYM_NAMLEN];
440*7c478bd9Sstevel@tonic-gate
441*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0)
442*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
443*7c478bd9Sstevel@tonic-gate
444*7c478bd9Sstevel@tonic-gate ippo = mdb_alloc(sizeof (ipp_ops_t), UM_SLEEP);
445*7c478bd9Sstevel@tonic-gate if (mdb_vread(ippo, sizeof (ipp_ops_t), addr) == -1) {
446*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_ops_t at %p", addr);
447*7c478bd9Sstevel@tonic-gate mdb_free(ippo, sizeof (ipp_ops_t));
448*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
449*7c478bd9Sstevel@tonic-gate }
450*7c478bd9Sstevel@tonic-gate
451*7c478bd9Sstevel@tonic-gate mdb_printf("%?p: %20s = %d\n", addr, "rev", ippo->ippo_rev);
452*7c478bd9Sstevel@tonic-gate
453*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_create,
454*7c478bd9Sstevel@tonic-gate MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
455*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "action_create", buf);
456*7c478bd9Sstevel@tonic-gate else
457*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "action_create",
458*7c478bd9Sstevel@tonic-gate ippo->ippo_action_create);
459*7c478bd9Sstevel@tonic-gate
460*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_modify,
461*7c478bd9Sstevel@tonic-gate MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
462*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "action_modify", buf);
463*7c478bd9Sstevel@tonic-gate else
464*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "action_modify",
465*7c478bd9Sstevel@tonic-gate ippo->ippo_action_modify);
466*7c478bd9Sstevel@tonic-gate
467*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_destroy,
468*7c478bd9Sstevel@tonic-gate MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
469*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "action_destroy", buf);
470*7c478bd9Sstevel@tonic-gate else
471*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "action_destroy",
472*7c478bd9Sstevel@tonic-gate ippo->ippo_action_destroy);
473*7c478bd9Sstevel@tonic-gate
474*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_info,
475*7c478bd9Sstevel@tonic-gate MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
476*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "action_info", buf);
477*7c478bd9Sstevel@tonic-gate else
478*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "action_info",
479*7c478bd9Sstevel@tonic-gate ippo->ippo_action_info);
480*7c478bd9Sstevel@tonic-gate
481*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_invoke,
482*7c478bd9Sstevel@tonic-gate MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
483*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = %s\n", "", "action_invoke", buf);
484*7c478bd9Sstevel@tonic-gate else
485*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "action_invoke",
486*7c478bd9Sstevel@tonic-gate ippo->ippo_action_invoke);
487*7c478bd9Sstevel@tonic-gate
488*7c478bd9Sstevel@tonic-gate mdb_printf("\n");
489*7c478bd9Sstevel@tonic-gate
490*7c478bd9Sstevel@tonic-gate mdb_free(ippo, sizeof (ipp_ops_t));
491*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
492*7c478bd9Sstevel@tonic-gate }
493*7c478bd9Sstevel@tonic-gate
494*7c478bd9Sstevel@tonic-gate static int
ref_walk_init(mdb_walk_state_t * wsp)495*7c478bd9Sstevel@tonic-gate ref_walk_init(
496*7c478bd9Sstevel@tonic-gate mdb_walk_state_t *wsp)
497*7c478bd9Sstevel@tonic-gate {
498*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL)
499*7c478bd9Sstevel@tonic-gate return (WALK_DONE);
500*7c478bd9Sstevel@tonic-gate
501*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
502*7c478bd9Sstevel@tonic-gate }
503*7c478bd9Sstevel@tonic-gate
504*7c478bd9Sstevel@tonic-gate static int
ref_walk_step(mdb_walk_state_t * wsp)505*7c478bd9Sstevel@tonic-gate ref_walk_step(
506*7c478bd9Sstevel@tonic-gate mdb_walk_state_t *wsp)
507*7c478bd9Sstevel@tonic-gate {
508*7c478bd9Sstevel@tonic-gate ipp_ref_t *rp;
509*7c478bd9Sstevel@tonic-gate int status;
510*7c478bd9Sstevel@tonic-gate
511*7c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL)
512*7c478bd9Sstevel@tonic-gate return (WALK_DONE);
513*7c478bd9Sstevel@tonic-gate
514*7c478bd9Sstevel@tonic-gate rp = mdb_alloc(sizeof (ipp_ref_t), UM_SLEEP);
515*7c478bd9Sstevel@tonic-gate
516*7c478bd9Sstevel@tonic-gate if (mdb_vread(rp, sizeof (ipp_ref_t), wsp->walk_addr) == -1) {
517*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_ref_t at %p", wsp->walk_addr);
518*7c478bd9Sstevel@tonic-gate mdb_free(rp, sizeof (ipp_ref_t));
519*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
520*7c478bd9Sstevel@tonic-gate }
521*7c478bd9Sstevel@tonic-gate
522*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback((uintptr_t)rp->ippr_ptr, NULL,
523*7c478bd9Sstevel@tonic-gate wsp->walk_cbdata);
524*7c478bd9Sstevel@tonic-gate
525*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)(rp->ippr_nextp);
526*7c478bd9Sstevel@tonic-gate
527*7c478bd9Sstevel@tonic-gate mdb_free(rp, sizeof (ipp_ref_t));
528*7c478bd9Sstevel@tonic-gate return (status);
529*7c478bd9Sstevel@tonic-gate }
530*7c478bd9Sstevel@tonic-gate
531*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
532*7c478bd9Sstevel@tonic-gate static void
ref_walk_fini(mdb_walk_state_t * wsp)533*7c478bd9Sstevel@tonic-gate ref_walk_fini(
534*7c478bd9Sstevel@tonic-gate mdb_walk_state_t *wsp)
535*7c478bd9Sstevel@tonic-gate {
536*7c478bd9Sstevel@tonic-gate }
537*7c478bd9Sstevel@tonic-gate
538*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
539*7c478bd9Sstevel@tonic-gate static int
packet(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)540*7c478bd9Sstevel@tonic-gate packet(
541*7c478bd9Sstevel@tonic-gate uintptr_t addr,
542*7c478bd9Sstevel@tonic-gate uint_t flags,
543*7c478bd9Sstevel@tonic-gate int argc,
544*7c478bd9Sstevel@tonic-gate const mdb_arg_t *argv)
545*7c478bd9Sstevel@tonic-gate {
546*7c478bd9Sstevel@tonic-gate ipp_packet_t *pp;
547*7c478bd9Sstevel@tonic-gate
548*7c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0)
549*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
550*7c478bd9Sstevel@tonic-gate
551*7c478bd9Sstevel@tonic-gate pp = mdb_alloc(sizeof (ipp_packet_t), UM_SLEEP);
552*7c478bd9Sstevel@tonic-gate if (mdb_vread(pp, sizeof (ipp_packet_t), addr) == -1) {
553*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_packet_t at %p", addr);
554*7c478bd9Sstevel@tonic-gate mdb_free(pp, sizeof (ipp_packet_t));
555*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
556*7c478bd9Sstevel@tonic-gate }
557*7c478bd9Sstevel@tonic-gate
558*7c478bd9Sstevel@tonic-gate mdb_printf("%?p: %20s = 0x%p\n", addr, "data", pp->ippp_data);
559*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %20s = 0x%p\n", "", "private", pp->ippp_private);
560*7c478bd9Sstevel@tonic-gate dump_classes((uintptr_t)pp->ippp_class_array, pp->ippp_class_windex);
561*7c478bd9Sstevel@tonic-gate dump_log((uintptr_t)pp->ippp_log, pp->ippp_log_windex);
562*7c478bd9Sstevel@tonic-gate
563*7c478bd9Sstevel@tonic-gate mdb_free(pp, sizeof (ipp_packet_t));
564*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
565*7c478bd9Sstevel@tonic-gate }
566*7c478bd9Sstevel@tonic-gate
567*7c478bd9Sstevel@tonic-gate static void
dump_classes(uintptr_t ptr,uint_t nelt)568*7c478bd9Sstevel@tonic-gate dump_classes(
569*7c478bd9Sstevel@tonic-gate uintptr_t ptr,
570*7c478bd9Sstevel@tonic-gate uint_t nelt)
571*7c478bd9Sstevel@tonic-gate {
572*7c478bd9Sstevel@tonic-gate ipp_class_t *array;
573*7c478bd9Sstevel@tonic-gate ipp_class_t *cp;
574*7c478bd9Sstevel@tonic-gate uint_t i;
575*7c478bd9Sstevel@tonic-gate boolean_t first_time = B_TRUE;
576*7c478bd9Sstevel@tonic-gate char buf[MAXNAMELEN];
577*7c478bd9Sstevel@tonic-gate
578*7c478bd9Sstevel@tonic-gate array = mdb_alloc(sizeof (ipp_class_t) * nelt, UM_SLEEP);
579*7c478bd9Sstevel@tonic-gate if (mdb_vread(array, sizeof (ipp_class_t) * nelt, ptr) == -1) {
580*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_class_t array at %p", ptr);
581*7c478bd9Sstevel@tonic-gate return;
582*7c478bd9Sstevel@tonic-gate }
583*7c478bd9Sstevel@tonic-gate
584*7c478bd9Sstevel@tonic-gate for (i = 0; i < nelt; i++) {
585*7c478bd9Sstevel@tonic-gate if (first_time) {
586*7c478bd9Sstevel@tonic-gate mdb_printf("%20s %?s %<u>%15s %15s%</u>\n", "",
587*7c478bd9Sstevel@tonic-gate "classes", "NAME", "ACTION");
588*7c478bd9Sstevel@tonic-gate first_time = B_FALSE;
589*7c478bd9Sstevel@tonic-gate }
590*7c478bd9Sstevel@tonic-gate
591*7c478bd9Sstevel@tonic-gate cp = &(array[i]);
592*7c478bd9Sstevel@tonic-gate aid2aname(cp->ippc_aid, buf);
593*7c478bd9Sstevel@tonic-gate mdb_printf("%20s %?p: %15s %15s%\n", "",
594*7c478bd9Sstevel@tonic-gate ptr + (i * sizeof (ipp_class_t)), cp->ippc_name, buf);
595*7c478bd9Sstevel@tonic-gate }
596*7c478bd9Sstevel@tonic-gate
597*7c478bd9Sstevel@tonic-gate mdb_free(cp, sizeof (ipp_class_t) * nelt);
598*7c478bd9Sstevel@tonic-gate }
599*7c478bd9Sstevel@tonic-gate
600*7c478bd9Sstevel@tonic-gate static void
dump_log(uintptr_t ptr,uint_t nelt)601*7c478bd9Sstevel@tonic-gate dump_log(
602*7c478bd9Sstevel@tonic-gate uintptr_t ptr,
603*7c478bd9Sstevel@tonic-gate uint_t nelt)
604*7c478bd9Sstevel@tonic-gate {
605*7c478bd9Sstevel@tonic-gate ipp_log_t *array;
606*7c478bd9Sstevel@tonic-gate ipp_log_t *lp;
607*7c478bd9Sstevel@tonic-gate uint_t i;
608*7c478bd9Sstevel@tonic-gate boolean_t first_time = B_TRUE;
609*7c478bd9Sstevel@tonic-gate char buf[MAXNAMELEN];
610*7c478bd9Sstevel@tonic-gate
611*7c478bd9Sstevel@tonic-gate array = mdb_alloc(sizeof (ipp_log_t) * nelt, UM_SLEEP);
612*7c478bd9Sstevel@tonic-gate if (mdb_vread(array, sizeof (ipp_log_t) * nelt, ptr) == -1) {
613*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_log_t array at %p", ptr);
614*7c478bd9Sstevel@tonic-gate return;
615*7c478bd9Sstevel@tonic-gate }
616*7c478bd9Sstevel@tonic-gate
617*7c478bd9Sstevel@tonic-gate for (i = 0; i < nelt; i++) {
618*7c478bd9Sstevel@tonic-gate if (first_time) {
619*7c478bd9Sstevel@tonic-gate mdb_printf("%20s %?s %<u>%15s %15s%</u>\n", "",
620*7c478bd9Sstevel@tonic-gate "log", "CLASS NAME", "ACTION");
621*7c478bd9Sstevel@tonic-gate first_time = B_FALSE;
622*7c478bd9Sstevel@tonic-gate }
623*7c478bd9Sstevel@tonic-gate
624*7c478bd9Sstevel@tonic-gate lp = &(array[i]);
625*7c478bd9Sstevel@tonic-gate aid2aname(lp->ippl_aid, buf);
626*7c478bd9Sstevel@tonic-gate mdb_printf("%20s %?p: %15s %15s\n", "",
627*7c478bd9Sstevel@tonic-gate ptr + (i * sizeof (ipp_class_t)), lp->ippl_name, buf);
628*7c478bd9Sstevel@tonic-gate }
629*7c478bd9Sstevel@tonic-gate
630*7c478bd9Sstevel@tonic-gate mdb_free(lp, sizeof (ipp_log_t) * nelt);
631*7c478bd9Sstevel@tonic-gate }
632*7c478bd9Sstevel@tonic-gate
633*7c478bd9Sstevel@tonic-gate static void
aid2aname(ipp_action_id_t aid,char * buf)634*7c478bd9Sstevel@tonic-gate aid2aname(
635*7c478bd9Sstevel@tonic-gate ipp_action_id_t aid,
636*7c478bd9Sstevel@tonic-gate char *buf)
637*7c478bd9Sstevel@tonic-gate {
638*7c478bd9Sstevel@tonic-gate uintptr_t addr;
639*7c478bd9Sstevel@tonic-gate uintptr_t ptr;
640*7c478bd9Sstevel@tonic-gate ipp_action_t *ap;
641*7c478bd9Sstevel@tonic-gate
642*7c478bd9Sstevel@tonic-gate switch (aid) {
643*7c478bd9Sstevel@tonic-gate case IPP_ACTION_INVAL:
644*7c478bd9Sstevel@tonic-gate strcpy(buf, "invalid");
645*7c478bd9Sstevel@tonic-gate break;
646*7c478bd9Sstevel@tonic-gate case IPP_ACTION_CONT:
647*7c478bd9Sstevel@tonic-gate strcpy(buf, "continue");
648*7c478bd9Sstevel@tonic-gate break;
649*7c478bd9Sstevel@tonic-gate case IPP_ACTION_DEFER:
650*7c478bd9Sstevel@tonic-gate strcpy(buf, "defer");
651*7c478bd9Sstevel@tonic-gate break;
652*7c478bd9Sstevel@tonic-gate case IPP_ACTION_DROP:
653*7c478bd9Sstevel@tonic-gate strcpy(buf, "drop");
654*7c478bd9Sstevel@tonic-gate break;
655*7c478bd9Sstevel@tonic-gate default:
656*7c478bd9Sstevel@tonic-gate if (mdb_vread(&addr, sizeof (uintptr_t),
657*7c478bd9Sstevel@tonic-gate ipp_action_byid) == -1) {
658*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read from address %p",
659*7c478bd9Sstevel@tonic-gate ipp_action_byid);
660*7c478bd9Sstevel@tonic-gate strcpy(buf, "???");
661*7c478bd9Sstevel@tonic-gate break;
662*7c478bd9Sstevel@tonic-gate }
663*7c478bd9Sstevel@tonic-gate
664*7c478bd9Sstevel@tonic-gate addr += ((int32_t)aid * sizeof (void *));
665*7c478bd9Sstevel@tonic-gate if (mdb_vread(&ptr, sizeof (uintptr_t), addr) == -1) {
666*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read from address %p", addr);
667*7c478bd9Sstevel@tonic-gate strcpy(buf, "???");
668*7c478bd9Sstevel@tonic-gate break;
669*7c478bd9Sstevel@tonic-gate }
670*7c478bd9Sstevel@tonic-gate
671*7c478bd9Sstevel@tonic-gate ap = mdb_alloc(sizeof (ipp_action_t), UM_SLEEP);
672*7c478bd9Sstevel@tonic-gate if (mdb_vread(ap, sizeof (ipp_action_t), ptr) == -1) {
673*7c478bd9Sstevel@tonic-gate mdb_warn("failed to read ipp_action_t at %p", ptr);
674*7c478bd9Sstevel@tonic-gate mdb_free(ap, sizeof (ipp_action_t));
675*7c478bd9Sstevel@tonic-gate strcpy(buf, "???");
676*7c478bd9Sstevel@tonic-gate break;
677*7c478bd9Sstevel@tonic-gate }
678*7c478bd9Sstevel@tonic-gate
679*7c478bd9Sstevel@tonic-gate if (ap->ippa_id != aid) {
680*7c478bd9Sstevel@tonic-gate mdb_warn("corrupt action at %p", ptr);
681*7c478bd9Sstevel@tonic-gate mdb_free(ap, sizeof (ipp_action_t));
682*7c478bd9Sstevel@tonic-gate strcpy(buf, "???");
683*7c478bd9Sstevel@tonic-gate break;
684*7c478bd9Sstevel@tonic-gate }
685*7c478bd9Sstevel@tonic-gate
686*7c478bd9Sstevel@tonic-gate strcpy(buf, ap->ippa_name);
687*7c478bd9Sstevel@tonic-gate }
688*7c478bd9Sstevel@tonic-gate }
689*7c478bd9Sstevel@tonic-gate
690*7c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
691*7c478bd9Sstevel@tonic-gate { "ipp_action", "?[-v]",
692*7c478bd9Sstevel@tonic-gate "display ipp_action structure", action },
693*7c478bd9Sstevel@tonic-gate { "ipp_mod", "?[-v]",
694*7c478bd9Sstevel@tonic-gate "display ipp_mod structure", mod },
695*7c478bd9Sstevel@tonic-gate { "cfglock", ":",
696*7c478bd9Sstevel@tonic-gate "display cfglock structure", cfglock },
697*7c478bd9Sstevel@tonic-gate { "ippops", ":",
698*7c478bd9Sstevel@tonic-gate "display ipp_ops structure", ippops },
699*7c478bd9Sstevel@tonic-gate { "ipp_packet", ":",
700*7c478bd9Sstevel@tonic-gate "display ipp_packet structure", packet },
701*7c478bd9Sstevel@tonic-gate { NULL }
702*7c478bd9Sstevel@tonic-gate };
703*7c478bd9Sstevel@tonic-gate
704*7c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
705*7c478bd9Sstevel@tonic-gate { "ipp_byid", "walk byid array", byid_walk_init, byid_walk_step,
706*7c478bd9Sstevel@tonic-gate byid_walk_fini },
707*7c478bd9Sstevel@tonic-gate { "ipp_ref", "walk reference list", ref_walk_init, ref_walk_step,
708*7c478bd9Sstevel@tonic-gate ref_walk_fini },
709*7c478bd9Sstevel@tonic-gate { NULL }
710*7c478bd9Sstevel@tonic-gate };
711*7c478bd9Sstevel@tonic-gate
712*7c478bd9Sstevel@tonic-gate static const mdb_modinfo_t ipp_modinfo = { MDB_API_VERSION, dcmds, walkers };
713*7c478bd9Sstevel@tonic-gate
714*7c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)715*7c478bd9Sstevel@tonic-gate _mdb_init(void)
716*7c478bd9Sstevel@tonic-gate {
717*7c478bd9Sstevel@tonic-gate GElf_Sym sym;
718*7c478bd9Sstevel@tonic-gate
719*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("ipp_action_byid", &sym) == -1) {
720*7c478bd9Sstevel@tonic-gate mdb_warn("failed to lookup 'ipp_action_byid'");
721*7c478bd9Sstevel@tonic-gate return (NULL);
722*7c478bd9Sstevel@tonic-gate }
723*7c478bd9Sstevel@tonic-gate
724*7c478bd9Sstevel@tonic-gate ipp_action_byid = (uintptr_t)sym.st_value;
725*7c478bd9Sstevel@tonic-gate
726*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("ipp_mod_byid", &sym) == -1) {
727*7c478bd9Sstevel@tonic-gate mdb_warn("failed to lookup 'ipp_mod_byid'");
728*7c478bd9Sstevel@tonic-gate return (NULL);
729*7c478bd9Sstevel@tonic-gate }
730*7c478bd9Sstevel@tonic-gate
731*7c478bd9Sstevel@tonic-gate ipp_mod_byid = (uintptr_t)sym.st_value;
732*7c478bd9Sstevel@tonic-gate
733*7c478bd9Sstevel@tonic-gate return (&ipp_modinfo);
734*7c478bd9Sstevel@tonic-gate }
735