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 2004 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/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/ddipropdefs.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/file.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/sunldi_impl.h>
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
39*7c478bd9Sstevel@tonic-gate #include <mdb/mdb_ks.h>
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate #include "ldi.h"
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate * ldi handle walker structure
45*7c478bd9Sstevel@tonic-gate */
46*7c478bd9Sstevel@tonic-gate typedef struct lh_walk {
47*7c478bd9Sstevel@tonic-gate struct ldi_handle **hash; /* current bucket pointer */
48*7c478bd9Sstevel@tonic-gate struct ldi_handle *lhp; /* ldi handle pointer */
49*7c478bd9Sstevel@tonic-gate size_t index; /* hash table index */
50*7c478bd9Sstevel@tonic-gate struct ldi_handle buf; /* buffer used for handle reads */
51*7c478bd9Sstevel@tonic-gate } lh_walk_t;
52*7c478bd9Sstevel@tonic-gate
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate * ldi identifier walker structure
55*7c478bd9Sstevel@tonic-gate */
56*7c478bd9Sstevel@tonic-gate typedef struct li_walk {
57*7c478bd9Sstevel@tonic-gate struct ldi_ident **hash; /* current bucket pointer */
58*7c478bd9Sstevel@tonic-gate struct ldi_ident *lip; /* ldi handle pointer */
59*7c478bd9Sstevel@tonic-gate size_t index; /* hash table index */
60*7c478bd9Sstevel@tonic-gate struct ldi_ident buf; /* buffer used for ident reads */
61*7c478bd9Sstevel@tonic-gate } li_walk_t;
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate * Options for ldi_handles dcmd
65*7c478bd9Sstevel@tonic-gate */
66*7c478bd9Sstevel@tonic-gate #define LH_IDENTINFO 0x1
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate * LDI walkers
70*7c478bd9Sstevel@tonic-gate */
71*7c478bd9Sstevel@tonic-gate int
ldi_handle_walk_init(mdb_walk_state_t * wsp)72*7c478bd9Sstevel@tonic-gate ldi_handle_walk_init(mdb_walk_state_t *wsp)
73*7c478bd9Sstevel@tonic-gate {
74*7c478bd9Sstevel@tonic-gate lh_walk_t *lhwp;
75*7c478bd9Sstevel@tonic-gate GElf_Sym sym;
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate /* get the address of the hash table */
78*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("ldi_handle_hash", &sym) == -1) {
79*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't find ldi_handle_hash");
80*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate lhwp = mdb_alloc(sizeof (lh_walk_t), UM_SLEEP|UM_GC);
84*7c478bd9Sstevel@tonic-gate lhwp->hash = (struct ldi_handle **)(uintptr_t)sym.st_value;
85*7c478bd9Sstevel@tonic-gate lhwp->index = 0;
86*7c478bd9Sstevel@tonic-gate
87*7c478bd9Sstevel@tonic-gate /* get the address of the first element in the first hash bucket */
88*7c478bd9Sstevel@tonic-gate if ((mdb_vread(&lhwp->lhp, sizeof (struct ldi_handle *),
89*7c478bd9Sstevel@tonic-gate (uintptr_t)lhwp->hash)) == -1) {
90*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi handle hash at %p", lhwp->hash);
91*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate
94*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)lhwp->lhp;
95*7c478bd9Sstevel@tonic-gate wsp->walk_data = lhwp;
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
98*7c478bd9Sstevel@tonic-gate }
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate int
ldi_handle_walk_step(mdb_walk_state_t * wsp)101*7c478bd9Sstevel@tonic-gate ldi_handle_walk_step(mdb_walk_state_t *wsp)
102*7c478bd9Sstevel@tonic-gate {
103*7c478bd9Sstevel@tonic-gate lh_walk_t *lhwp = (lh_walk_t *)wsp->walk_data;
104*7c478bd9Sstevel@tonic-gate int status;
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate /* check if we need to go to the next hash bucket */
107*7c478bd9Sstevel@tonic-gate while (wsp->walk_addr == NULL) {
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate /* advance to the next bucket */
110*7c478bd9Sstevel@tonic-gate if (++(lhwp->index) >= LH_HASH_SZ)
111*7c478bd9Sstevel@tonic-gate return (WALK_DONE);
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate /* get handle address from the hash bucket */
114*7c478bd9Sstevel@tonic-gate if ((mdb_vread(&lhwp->lhp, sizeof (struct ldi_handle *),
115*7c478bd9Sstevel@tonic-gate (uintptr_t)(lhwp->hash + lhwp->index))) == -1) {
116*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi handle hash at %p",
117*7c478bd9Sstevel@tonic-gate (uintptr_t)lhwp->hash + lhwp->index);
118*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
119*7c478bd9Sstevel@tonic-gate }
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)lhwp->lhp;
122*7c478bd9Sstevel@tonic-gate }
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate /* invoke the walker callback for this hash element */
125*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
126*7c478bd9Sstevel@tonic-gate if (status != WALK_NEXT)
127*7c478bd9Sstevel@tonic-gate return (status);
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate /* get a pointer to the next hash element */
130*7c478bd9Sstevel@tonic-gate if (mdb_vread(&lhwp->buf, sizeof (struct ldi_handle),
131*7c478bd9Sstevel@tonic-gate wsp->walk_addr) == -1) {
132*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi handle at %p", wsp->walk_addr);
133*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
134*7c478bd9Sstevel@tonic-gate }
135*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)lhwp->buf.lh_next;
136*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate int
ldi_ident_walk_init(mdb_walk_state_t * wsp)140*7c478bd9Sstevel@tonic-gate ldi_ident_walk_init(mdb_walk_state_t *wsp)
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate li_walk_t *liwp;
143*7c478bd9Sstevel@tonic-gate GElf_Sym sym;
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate /* get the address of the hash table */
146*7c478bd9Sstevel@tonic-gate if (mdb_lookup_by_name("ldi_ident_hash", &sym) == -1) {
147*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't find ldi_ident_hash");
148*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
149*7c478bd9Sstevel@tonic-gate }
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate liwp = mdb_alloc(sizeof (li_walk_t), UM_SLEEP|UM_GC);
152*7c478bd9Sstevel@tonic-gate liwp->hash = (struct ldi_ident **)(uintptr_t)sym.st_value;
153*7c478bd9Sstevel@tonic-gate liwp->index = 0;
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate /* get the address of the first element in the first hash bucket */
156*7c478bd9Sstevel@tonic-gate if ((mdb_vread(&liwp->lip, sizeof (struct ldi_ident *),
157*7c478bd9Sstevel@tonic-gate (uintptr_t)liwp->hash)) == -1) {
158*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi ident hash at %p", liwp->hash);
159*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
160*7c478bd9Sstevel@tonic-gate }
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)liwp->lip;
163*7c478bd9Sstevel@tonic-gate wsp->walk_data = liwp;
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
166*7c478bd9Sstevel@tonic-gate }
167*7c478bd9Sstevel@tonic-gate
168*7c478bd9Sstevel@tonic-gate int
ldi_ident_walk_step(mdb_walk_state_t * wsp)169*7c478bd9Sstevel@tonic-gate ldi_ident_walk_step(mdb_walk_state_t *wsp)
170*7c478bd9Sstevel@tonic-gate {
171*7c478bd9Sstevel@tonic-gate li_walk_t *liwp = (li_walk_t *)wsp->walk_data;
172*7c478bd9Sstevel@tonic-gate int status;
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate /* check if we need to go to the next hash bucket */
175*7c478bd9Sstevel@tonic-gate while (wsp->walk_addr == NULL) {
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate /* advance to the next bucket */
178*7c478bd9Sstevel@tonic-gate if (++(liwp->index) >= LI_HASH_SZ)
179*7c478bd9Sstevel@tonic-gate return (WALK_DONE);
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gate /* get handle address from the hash bucket */
182*7c478bd9Sstevel@tonic-gate if ((mdb_vread(&liwp->lip, sizeof (struct ldi_ident *),
183*7c478bd9Sstevel@tonic-gate (uintptr_t)(liwp->hash + liwp->index))) == -1) {
184*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi ident hash at %p",
185*7c478bd9Sstevel@tonic-gate (uintptr_t)liwp->hash + liwp->index);
186*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
187*7c478bd9Sstevel@tonic-gate }
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)liwp->lip;
190*7c478bd9Sstevel@tonic-gate }
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate /* invoke the walker callback for this hash element */
193*7c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata);
194*7c478bd9Sstevel@tonic-gate if (status != WALK_NEXT)
195*7c478bd9Sstevel@tonic-gate return (status);
196*7c478bd9Sstevel@tonic-gate
197*7c478bd9Sstevel@tonic-gate /* get a pointer to the next hash element */
198*7c478bd9Sstevel@tonic-gate if (mdb_vread(&liwp->buf, sizeof (struct ldi_ident),
199*7c478bd9Sstevel@tonic-gate wsp->walk_addr) == -1) {
200*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi ident at %p", wsp->walk_addr);
201*7c478bd9Sstevel@tonic-gate return (WALK_ERR);
202*7c478bd9Sstevel@tonic-gate }
203*7c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)liwp->buf.li_next;
204*7c478bd9Sstevel@tonic-gate return (WALK_NEXT);
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gate /*
208*7c478bd9Sstevel@tonic-gate * LDI dcmds
209*7c478bd9Sstevel@tonic-gate */
210*7c478bd9Sstevel@tonic-gate static void
ldi_ident_header(int start,int refs)211*7c478bd9Sstevel@tonic-gate ldi_ident_header(int start, int refs)
212*7c478bd9Sstevel@tonic-gate {
213*7c478bd9Sstevel@tonic-gate if (start) {
214*7c478bd9Sstevel@tonic-gate mdb_printf("%-?s ", "IDENT");
215*7c478bd9Sstevel@tonic-gate } else {
216*7c478bd9Sstevel@tonic-gate mdb_printf("%?s ", "IDENT");
217*7c478bd9Sstevel@tonic-gate }
218*7c478bd9Sstevel@tonic-gate
219*7c478bd9Sstevel@tonic-gate if (refs)
220*7c478bd9Sstevel@tonic-gate mdb_printf("%4s ", "REFS");
221*7c478bd9Sstevel@tonic-gate
222*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %5s %5s %s\n", "DIP", "MINOR", "MODID", "MODULE NAME");
223*7c478bd9Sstevel@tonic-gate }
224*7c478bd9Sstevel@tonic-gate
225*7c478bd9Sstevel@tonic-gate static int
ldi_ident_print(uintptr_t addr,int refs)226*7c478bd9Sstevel@tonic-gate ldi_ident_print(uintptr_t addr, int refs)
227*7c478bd9Sstevel@tonic-gate {
228*7c478bd9Sstevel@tonic-gate struct ldi_ident li;
229*7c478bd9Sstevel@tonic-gate
230*7c478bd9Sstevel@tonic-gate /* read the ldi ident */
231*7c478bd9Sstevel@tonic-gate if (mdb_vread(&li, sizeof (struct ldi_ident), addr) == -1) {
232*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi ident at %p", addr);
233*7c478bd9Sstevel@tonic-gate return (1);
234*7c478bd9Sstevel@tonic-gate }
235*7c478bd9Sstevel@tonic-gate
236*7c478bd9Sstevel@tonic-gate /* display the ident address */
237*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p ", addr);
238*7c478bd9Sstevel@tonic-gate
239*7c478bd9Sstevel@tonic-gate /* display the ref count */
240*7c478bd9Sstevel@tonic-gate if (refs)
241*7c478bd9Sstevel@tonic-gate mdb_printf("%4u ", li.li_ref);
242*7c478bd9Sstevel@tonic-gate
243*7c478bd9Sstevel@tonic-gate /* display the dip (if any) */
244*7c478bd9Sstevel@tonic-gate if (li.li_dip != NULL) {
245*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p ", li.li_dip);
246*7c478bd9Sstevel@tonic-gate } else {
247*7c478bd9Sstevel@tonic-gate mdb_printf("%?s ", "-");
248*7c478bd9Sstevel@tonic-gate }
249*7c478bd9Sstevel@tonic-gate
250*7c478bd9Sstevel@tonic-gate /* display the minor node (if any) */
251*7c478bd9Sstevel@tonic-gate if (li.li_dev != DDI_DEV_T_NONE) {
252*7c478bd9Sstevel@tonic-gate mdb_printf("%5u ", getminor(li.li_dev));
253*7c478bd9Sstevel@tonic-gate } else {
254*7c478bd9Sstevel@tonic-gate mdb_printf("%5s ", "-");
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate
257*7c478bd9Sstevel@tonic-gate /* display the module info */
258*7c478bd9Sstevel@tonic-gate mdb_printf("%5d %s\n", li.li_modid, li.li_modname);
259*7c478bd9Sstevel@tonic-gate
260*7c478bd9Sstevel@tonic-gate return (0);
261*7c478bd9Sstevel@tonic-gate }
262*7c478bd9Sstevel@tonic-gate
263*7c478bd9Sstevel@tonic-gate int
ldi_ident(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)264*7c478bd9Sstevel@tonic-gate ldi_ident(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
265*7c478bd9Sstevel@tonic-gate {
266*7c478bd9Sstevel@tonic-gate int start = 1;
267*7c478bd9Sstevel@tonic-gate int refs = 1;
268*7c478bd9Sstevel@tonic-gate
269*7c478bd9Sstevel@tonic-gate /* Determine if there is an ldi identifier address */
270*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
271*7c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("ldi_ident", "ldi_ident",
272*7c478bd9Sstevel@tonic-gate argc, argv) == -1) {
273*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk ldi idents");
274*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
275*7c478bd9Sstevel@tonic-gate }
276*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate
279*7c478bd9Sstevel@tonic-gate /* display the header line */
280*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
281*7c478bd9Sstevel@tonic-gate ldi_ident_header(start, refs);
282*7c478bd9Sstevel@tonic-gate
283*7c478bd9Sstevel@tonic-gate /* display the ldi ident */
284*7c478bd9Sstevel@tonic-gate if (ldi_ident_print(addr, refs))
285*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
286*7c478bd9Sstevel@tonic-gate
287*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
288*7c478bd9Sstevel@tonic-gate }
289*7c478bd9Sstevel@tonic-gate
290*7c478bd9Sstevel@tonic-gate static void
ldi_handle_header(int refs,int ident)291*7c478bd9Sstevel@tonic-gate ldi_handle_header(int refs, int ident) {
292*7c478bd9Sstevel@tonic-gate mdb_printf("%-?s ", "HANDLE");
293*7c478bd9Sstevel@tonic-gate
294*7c478bd9Sstevel@tonic-gate if (refs)
295*7c478bd9Sstevel@tonic-gate mdb_printf("%4s ", "REFS");
296*7c478bd9Sstevel@tonic-gate
297*7c478bd9Sstevel@tonic-gate mdb_printf("%?s %10s %5s %?s ", "VNODE", "DRV", "MINOR", "EVENTS");
298*7c478bd9Sstevel@tonic-gate
299*7c478bd9Sstevel@tonic-gate if (!ident) {
300*7c478bd9Sstevel@tonic-gate mdb_printf("%?s\n", "IDENT");
301*7c478bd9Sstevel@tonic-gate } else {
302*7c478bd9Sstevel@tonic-gate ldi_ident_header(0, 0);
303*7c478bd9Sstevel@tonic-gate }
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate
306*7c478bd9Sstevel@tonic-gate static int
ldi_handle_print(uintptr_t addr,int ident,int refs)307*7c478bd9Sstevel@tonic-gate ldi_handle_print(uintptr_t addr, int ident, int refs)
308*7c478bd9Sstevel@tonic-gate {
309*7c478bd9Sstevel@tonic-gate vnode_t vnode;
310*7c478bd9Sstevel@tonic-gate struct ldi_handle lh;
311*7c478bd9Sstevel@tonic-gate const char *name;
312*7c478bd9Sstevel@tonic-gate
313*7c478bd9Sstevel@tonic-gate /* read in the ldi handle */
314*7c478bd9Sstevel@tonic-gate if (mdb_vread(&lh, sizeof (struct ldi_handle), addr) == -1) {
315*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read ldi handle at %p", addr);
316*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
317*7c478bd9Sstevel@tonic-gate }
318*7c478bd9Sstevel@tonic-gate
319*7c478bd9Sstevel@tonic-gate /* display the handle address */
320*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p ", addr);
321*7c478bd9Sstevel@tonic-gate
322*7c478bd9Sstevel@tonic-gate /* display the ref count */
323*7c478bd9Sstevel@tonic-gate if (refs)
324*7c478bd9Sstevel@tonic-gate mdb_printf("%4u ", lh.lh_ref);
325*7c478bd9Sstevel@tonic-gate
326*7c478bd9Sstevel@tonic-gate /* display the vnode */
327*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p ", lh.lh_vp);
328*7c478bd9Sstevel@tonic-gate
329*7c478bd9Sstevel@tonic-gate /* read in the vnode associated with the handle */
330*7c478bd9Sstevel@tonic-gate addr = (uintptr_t)lh.lh_vp;
331*7c478bd9Sstevel@tonic-gate if (mdb_vread(&vnode, sizeof (vnode_t), addr) == -1) {
332*7c478bd9Sstevel@tonic-gate mdb_warn("couldn't read vnode at %p", addr);
333*7c478bd9Sstevel@tonic-gate return (1);
334*7c478bd9Sstevel@tonic-gate }
335*7c478bd9Sstevel@tonic-gate
336*7c478bd9Sstevel@tonic-gate /* display the driver name */
337*7c478bd9Sstevel@tonic-gate if ((name = mdb_major_to_name(getmajor(vnode.v_rdev))) == NULL) {
338*7c478bd9Sstevel@tonic-gate mdb_warn("failed to convert major number to name\n");
339*7c478bd9Sstevel@tonic-gate return (1);
340*7c478bd9Sstevel@tonic-gate }
341*7c478bd9Sstevel@tonic-gate mdb_printf("%10s ", name);
342*7c478bd9Sstevel@tonic-gate
343*7c478bd9Sstevel@tonic-gate /* display the minor number */
344*7c478bd9Sstevel@tonic-gate mdb_printf("%5d ", getminor(vnode.v_rdev));
345*7c478bd9Sstevel@tonic-gate
346*7c478bd9Sstevel@tonic-gate /* display the event pointer (if any) */
347*7c478bd9Sstevel@tonic-gate if (lh.lh_events != NULL) {
348*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p ", lh.lh_events);
349*7c478bd9Sstevel@tonic-gate } else {
350*7c478bd9Sstevel@tonic-gate mdb_printf("%?s ", "-");
351*7c478bd9Sstevel@tonic-gate }
352*7c478bd9Sstevel@tonic-gate
353*7c478bd9Sstevel@tonic-gate if (!ident) {
354*7c478bd9Sstevel@tonic-gate /* display the ident address */
355*7c478bd9Sstevel@tonic-gate mdb_printf("%0?p\n", lh.lh_ident);
356*7c478bd9Sstevel@tonic-gate return (0);
357*7c478bd9Sstevel@tonic-gate }
358*7c478bd9Sstevel@tonic-gate
359*7c478bd9Sstevel@tonic-gate /* display the entire ident */
360*7c478bd9Sstevel@tonic-gate return (ldi_ident_print((uintptr_t)lh.lh_ident, refs));
361*7c478bd9Sstevel@tonic-gate }
362*7c478bd9Sstevel@tonic-gate
363*7c478bd9Sstevel@tonic-gate int
ldi_handle(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)364*7c478bd9Sstevel@tonic-gate ldi_handle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
365*7c478bd9Sstevel@tonic-gate {
366*7c478bd9Sstevel@tonic-gate int ident = 0;
367*7c478bd9Sstevel@tonic-gate int refs = 1;
368*7c478bd9Sstevel@tonic-gate
369*7c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
370*7c478bd9Sstevel@tonic-gate 'i', MDB_OPT_SETBITS, TRUE, &ident) != argc)
371*7c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
372*7c478bd9Sstevel@tonic-gate
373*7c478bd9Sstevel@tonic-gate if (ident)
374*7c478bd9Sstevel@tonic-gate refs = 0;
375*7c478bd9Sstevel@tonic-gate
376*7c478bd9Sstevel@tonic-gate /* Determine if there is an ldi handle address */
377*7c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
378*7c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("ldi_handle", "ldi_handle",
379*7c478bd9Sstevel@tonic-gate argc, argv) == -1) {
380*7c478bd9Sstevel@tonic-gate mdb_warn("can't walk ldi handles");
381*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
382*7c478bd9Sstevel@tonic-gate } return (DCMD_OK);
383*7c478bd9Sstevel@tonic-gate }
384*7c478bd9Sstevel@tonic-gate
385*7c478bd9Sstevel@tonic-gate /* display the header line */
386*7c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
387*7c478bd9Sstevel@tonic-gate ldi_handle_header(refs, ident);
388*7c478bd9Sstevel@tonic-gate
389*7c478bd9Sstevel@tonic-gate /* display the ldi handle */
390*7c478bd9Sstevel@tonic-gate if (ldi_handle_print(addr, ident, refs))
391*7c478bd9Sstevel@tonic-gate return (DCMD_ERR);
392*7c478bd9Sstevel@tonic-gate
393*7c478bd9Sstevel@tonic-gate return (DCMD_OK);
394*7c478bd9Sstevel@tonic-gate }
395*7c478bd9Sstevel@tonic-gate
396*7c478bd9Sstevel@tonic-gate void
ldi_ident_help(void)397*7c478bd9Sstevel@tonic-gate ldi_ident_help(void)
398*7c478bd9Sstevel@tonic-gate {
399*7c478bd9Sstevel@tonic-gate mdb_printf("Displays an ldi identifier.\n"
400*7c478bd9Sstevel@tonic-gate "Without the address of an \"ldi_ident_t\", "
401*7c478bd9Sstevel@tonic-gate "print all identifiers.\n"
402*7c478bd9Sstevel@tonic-gate "With an address, print the specified identifier.\n");
403*7c478bd9Sstevel@tonic-gate }
404*7c478bd9Sstevel@tonic-gate
405*7c478bd9Sstevel@tonic-gate void
ldi_handle_help(void)406*7c478bd9Sstevel@tonic-gate ldi_handle_help(void)
407*7c478bd9Sstevel@tonic-gate {
408*7c478bd9Sstevel@tonic-gate mdb_printf("Displays an ldi handle.\n"
409*7c478bd9Sstevel@tonic-gate "Without the address of an \"ldi_handle_t\", "
410*7c478bd9Sstevel@tonic-gate "print all handles.\n"
411*7c478bd9Sstevel@tonic-gate "With an address, print the specified handle.\n\n"
412*7c478bd9Sstevel@tonic-gate "Switches:\n"
413*7c478bd9Sstevel@tonic-gate " -i print the module identifier information\n");
414*7c478bd9Sstevel@tonic-gate }
415