xref: /onnv-gate/usr/src/cmd/sgs/rtld/mdbmod/common/rtld.c (revision 0:68f95e015346)
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 <msg.h>
30*0Sstevel@tonic-gate #include <_rtld.h>
31*0Sstevel@tonic-gate #include <conv.h>
32*0Sstevel@tonic-gate #include <sys/mdb_modapi.h>
33*0Sstevel@tonic-gate #include <sys/param.h>
34*0Sstevel@tonic-gate #include <stdlib.h>
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * Data structure for walkers.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate typedef struct {
40*0Sstevel@tonic-gate 	uint_t	w_flags;
41*0Sstevel@tonic-gate } W_desc;
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /*
45*0Sstevel@tonic-gate  * Flags values for dcmds
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate #define	RTLD_FLG_VERBOSE	0x0001		/* verbose output */
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate static const mdb_bitmask_t rtflags_bits[] = {
51*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ISMAIN), FLG_RT_ISMAIN, FLG_RT_ISMAIN},
52*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_IMGALLOC), FLG_RT_IMGALLOC, FLG_RT_IMGALLOC},
53*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_RELOCED), FLG_RT_RELOCED, FLG_RT_RELOCED},
54*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_SETGROUP), FLG_RT_SETGROUP, FLG_RT_SETGROUP},
55*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_HWCAP), FLG_RT_HWCAP, FLG_RT_HWCAP},
56*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_OBJECT), FLG_RT_OBJECT, FLG_RT_OBJECT},
57*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_NODUMP), FLG_RT_NODUMP, FLG_RT_NODUMP},
58*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_DELETE), FLG_RT_DELETE, FLG_RT_DELETE},
59*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ANALYZED), FLG_RT_ANALYZED, FLG_RT_ANALYZED},
60*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITDONE), FLG_RT_INITDONE, FLG_RT_INITDONE},
61*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_TRANS), FLG_RT_TRANS, FLG_RT_TRANS},
62*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_FIXED), FLG_RT_FIXED, FLG_RT_FIXED},
63*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_PRELOAD), FLG_RT_PRELOAD, FLG_RT_PRELOAD},
64*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ALTER), FLG_RT_ALTER, FLG_RT_ALTER},
65*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_LOADFLTR), FLG_RT_LOADFLTR, FLG_RT_LOADFLTR},
66*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_AUDIT), FLG_RT_AUDIT, FLG_RT_AUDIT},
67*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_MODESET), FLG_RT_MODESET, FLG_RT_MODESET},
68*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ANALZING), FLG_RT_ANALZING, FLG_RT_ANALZING},
69*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITFRST), FLG_RT_INITFRST, FLG_RT_INITFRST},
70*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_NOOPEN), FLG_RT_NOOPEN, FLG_RT_NOOPEN},
71*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_FINICLCT), FLG_RT_FINICLCT, FLG_RT_FINICLCT},
72*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITCALL), FLG_RT_INITCALL, FLG_RT_INITCALL},
73*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INTRPOSE), FLG_RT_INTRPOSE, FLG_RT_INTRPOSE},
74*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_DIRECT), FLG_RT_DIRECT, FLG_RT_DIRECT},
75*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_SUNWBSS), FLG_RT_SUNWBSS, FLG_RT_SUNWBSS},
76*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_MOVE), FLG_RT_MOVE, FLG_RT_MOVE},
77*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_DLSYM), FLG_RT_DLSYM, FLG_RT_DLSYM},
78*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_REGSYMS), FLG_RT_REGSYMS, FLG_RT_REGSYMS},
79*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITCLCT), FLG_RT_INITCLCT, FLG_RT_INITCLCT},
80*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_HANDLE), FLG_RT_HANDLE, FLG_RT_HANDLE},
81*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_RELOCING), FLG_RT_RELOCING, FLG_RT_RELOCING},
82*0Sstevel@tonic-gate 	{ NULL, 0, 0}
83*0Sstevel@tonic-gate };
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate static const mdb_bitmask_t rtflags1_bits[] = {
86*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_COPYTOOK), FL1_RT_COPYTOOK, FL1_RT_COPYTOOK},
87*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_RELATIVE), FL1_RT_RELATIVE, FL1_RT_RELATIVE },
88*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_CONFSET), FL1_RT_CONFSET, FL1_RT_CONFSET },
89*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_NODEFLIB), FL1_RT_NODEFLIB, FL1_RT_NODEFLIB },
90*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_ENDFILTE), FL1_RT_ENDFILTE, FL1_RT_ENDFILTE },
91*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_DISPREL), FL1_RT_DISPREL, FL1_RT_DISPREL },
92*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_TEXTREL), FL1_RT_TEXTREL, FL1_RT_TEXTREL },
93*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_INITWAIT), FL1_RT_INITWAIT, FL1_RT_INITWAIT },
94*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_LDDSTUB), FL1_RT_LDDSTUB, FL1_RT_LDDSTUB},
95*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_NOINIFIN), FL1_RT_NOINIFIN, FL1_RT_NOINIFIN },
96*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_USED), FL1_RT_USED, FL1_RT_USED },
97*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_SYMBOLIC), FL1_RT_SYMBOLIC, FL1_RT_SYMBOLIC },
98*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_OBJSFLTR), FL1_RT_OBJSFLTR, FL1_RT_OBJSFLTR },
99*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_OBJAFLTR), FL1_RT_OBJAFLTR, FL1_RT_OBJAFLTR },
100*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_SYMSFLTR), FL1_RT_SYMSFLTR, FL1_RT_SYMSFLTR },
101*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_SYMAFLTR), FL1_RT_SYMAFLTR, FL1_RT_SYMAFLTR },
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PREINIT), LML_TFLG_AUD_PREINIT,
104*0Sstevel@tonic-gate 	    LML_TFLG_AUD_PREINIT },
105*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJSEARCH), LML_TFLG_AUD_OBJSEARCH,
106*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJSEARCH },
107*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJOPEN), LML_TFLG_AUD_OBJOPEN,
108*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJOPEN },
109*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJFILTER), LML_TFLG_AUD_OBJFILTER,
110*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJFILTER },
111*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJCLOSE), LML_TFLG_AUD_OBJCLOSE,
112*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJCLOSE },
113*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_SYMBIND), LML_TFLG_AUD_SYMBIND,
114*0Sstevel@tonic-gate 	    LML_TFLG_AUD_SYMBIND },
115*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTENTER), LML_TFLG_AUD_PLTENTER,
116*0Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTENTER },
117*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTEXIT), LML_TFLG_AUD_PLTEXIT,
118*0Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTEXIT },
119*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_ACTIVITY), LML_TFLG_AUD_ACTIVITY,
120*0Sstevel@tonic-gate 	    LML_TFLG_AUD_ACTIVITY },
121*0Sstevel@tonic-gate 	{ NULL, 0, 0}
122*0Sstevel@tonic-gate };
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate static const mdb_bitmask_t rtmode_bits[] = {
125*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_LAZY), RTLD_LAZY, RTLD_LAZY },
126*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_NOW), RTLD_NOW, RTLD_NOW },
127*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_NOLOAD), RTLD_NOLOAD, RTLD_NOLOAD },
128*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_GLOBAL), RTLD_GLOBAL, RTLD_GLOBAL },
129*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_PARENT), RTLD_PARENT, RTLD_PARENT },
130*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_GROUP), RTLD_GROUP, RTLD_GROUP },
131*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_WORLD), RTLD_WORLD, RTLD_WORLD },
132*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_NODELETE), RTLD_NODELETE, RTLD_NODELETE },
133*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_FIRST), RTLD_FIRST, RTLD_FIRST },
134*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_CONFGEN), RTLD_CONFGEN, RTLD_CONFGEN },
135*0Sstevel@tonic-gate 	{ NULL, 0, 0}
136*0Sstevel@tonic-gate };
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate static const mdb_bitmask_t bndflags_bits[] = {
139*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_BFL_NEEDED), BND_NEEDED, BND_NEEDED },
140*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_BFL_REFER), BND_REFER, BND_REFER },
141*0Sstevel@tonic-gate 	{ NULL, 0, 0}
142*0Sstevel@tonic-gate };
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate static const mdb_bitmask_t grhflags_bits[] = {
145*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_ZERO), GPH_ZERO, GPH_ZERO },
146*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_LDSO), GPH_LDSO, GPH_LDSO },
147*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_FIRST), GPH_FIRST, GPH_FIRST },
148*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_PARENT), GPH_PARENT, GPH_PARENT },
149*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_FILTEE), GPH_FILTEE, GPH_FILTEE },
150*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_INITIAL), GPH_INITIAL, GPH_INITIAL },
151*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_STICKY), GPH_STICKY, GPH_STICKY },
152*0Sstevel@tonic-gate 	{ NULL, 0, 0}
153*0Sstevel@tonic-gate };
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate static const mdb_bitmask_t grdflags_bits[] = {
156*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_AVAIL), GPD_AVAIL, GPD_AVAIL },
157*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_ADDEPS), GPD_ADDEPS, GPD_ADDEPS },
158*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_PARENT), GPD_PARENT, GPD_PARENT },
159*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_FILTER), GPD_FILTER, GPD_FILTER },
160*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_REMOVE), GPD_REMOVE, GPD_REMOVE },
161*0Sstevel@tonic-gate 	{ NULL, 0, 0}
162*0Sstevel@tonic-gate };
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate static const mdb_bitmask_t lmc_bits[] = {
165*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMC_ANALYZING), LMC_FLG_ANALYZING, LMC_FLG_ANALYZING},
166*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMC_RELOCATING), LMC_FLG_RELOCATING, LMC_FLG_RELOCATING},
167*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMC_REANALYZE), LMC_FLG_REANALYZE, LMC_FLG_REANALYZE},
168*0Sstevel@tonic-gate 	{ NULL, 0, 0}
169*0Sstevel@tonic-gate };
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate /*
172*0Sstevel@tonic-gate  * Obtain a string - typically a link-map name.
173*0Sstevel@tonic-gate  */
174*0Sstevel@tonic-gate static char *
175*0Sstevel@tonic-gate String(uintptr_t addr, const char *name)
176*0Sstevel@tonic-gate {
177*0Sstevel@tonic-gate 	static char	str[MAXPATHLEN];
178*0Sstevel@tonic-gate 
179*0Sstevel@tonic-gate 	if (addr) {
180*0Sstevel@tonic-gate 		if (mdb_readstr(str, MAXPATHLEN, addr) == -1) {
181*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ), name, addr);
182*0Sstevel@tonic-gate 			return (0);
183*0Sstevel@tonic-gate 		}
184*0Sstevel@tonic-gate 		return (str);
185*0Sstevel@tonic-gate 	}
186*0Sstevel@tonic-gate 	return ((char *)MSG_ORIG(MSG_STR_EMPTY));
187*0Sstevel@tonic-gate }
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate /*
190*0Sstevel@tonic-gate  * Obtain a link-map name.
191*0Sstevel@tonic-gate  */
192*0Sstevel@tonic-gate static char *
193*0Sstevel@tonic-gate Rtmap_Name(uintptr_t addr)
194*0Sstevel@tonic-gate {
195*0Sstevel@tonic-gate 	Rt_map	rtmap;
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate 	if (addr) {
198*0Sstevel@tonic-gate 		if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
199*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
200*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_RTMAP_STR), addr);
201*0Sstevel@tonic-gate 			return (0);
202*0Sstevel@tonic-gate 		}
203*0Sstevel@tonic-gate 		return (String((uintptr_t)NAME(&rtmap),
204*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_NAME)));
205*0Sstevel@tonic-gate 	}
206*0Sstevel@tonic-gate 	return ((char *)MSG_ORIG(MSG_STR_EMPTY));
207*0Sstevel@tonic-gate }
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate void
210*0Sstevel@tonic-gate dcmd_Bind_help(void)
211*0Sstevel@tonic-gate {
212*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_HELP));
213*0Sstevel@tonic-gate }
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate static int
216*0Sstevel@tonic-gate /* ARGSUSED2 */
217*0Sstevel@tonic-gate dcmd_Bind(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
218*0Sstevel@tonic-gate {
219*0Sstevel@tonic-gate 	Bnd_desc	bnd;
220*0Sstevel@tonic-gate 	char		*str;
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate 	/*
223*0Sstevel@tonic-gate 	 * Insure we have a valid address.
224*0Sstevel@tonic-gate 	 */
225*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
226*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_BND_STR));
227*0Sstevel@tonic-gate 		return (DCMD_USAGE);
228*0Sstevel@tonic-gate 	}
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate 	/*
231*0Sstevel@tonic-gate 	 * Obtain the binding descriptor.
232*0Sstevel@tonic-gate 	 */
233*0Sstevel@tonic-gate 	if (mdb_vread(&bnd, sizeof (Bnd_desc), addr) == -1) {
234*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_BND_STR), addr);
235*0Sstevel@tonic-gate 		return (DCMD_ERR);
236*0Sstevel@tonic-gate 	}
237*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_TITLE), addr);
238*0Sstevel@tonic-gate 
239*0Sstevel@tonic-gate 	/*
240*0Sstevel@tonic-gate 	 * Establish the identity of the caller.
241*0Sstevel@tonic-gate 	 */
242*0Sstevel@tonic-gate 	if ((str = Rtmap_Name((uintptr_t)bnd.b_caller)) == 0)
243*0Sstevel@tonic-gate 		return (DCMD_ERR);
244*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_LINE1), bnd.b_caller, str);
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate 	/*
247*0Sstevel@tonic-gate 	 * Establish the identity of the dependency.
248*0Sstevel@tonic-gate 	 */
249*0Sstevel@tonic-gate 	if ((str = Rtmap_Name((uintptr_t)bnd.b_depend)) == 0)
250*0Sstevel@tonic-gate 		return (DCMD_ERR);
251*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_LINE2), bnd.b_depend, str);
252*0Sstevel@tonic-gate 
253*0Sstevel@tonic-gate 	/*
254*0Sstevel@tonic-gate 	 * Display any flags.
255*0Sstevel@tonic-gate 	 */
256*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_LINE3), bnd.b_flags, bnd.b_flags,
257*0Sstevel@tonic-gate 	    bndflags_bits);
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate 	return (DCMD_OK);
260*0Sstevel@tonic-gate }
261*0Sstevel@tonic-gate 
262*0Sstevel@tonic-gate static void
263*0Sstevel@tonic-gate dcmd_Depends_help(void)
264*0Sstevel@tonic-gate {
265*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_DEPENDS_HELP));
266*0Sstevel@tonic-gate }
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate static int
269*0Sstevel@tonic-gate Depends(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv,
270*0Sstevel@tonic-gate     uint_t flg, const char *msg)
271*0Sstevel@tonic-gate {
272*0Sstevel@tonic-gate 	Alist		al;
273*0Sstevel@tonic-gate 	uintptr_t	listcalc, listnext;
274*0Sstevel@tonic-gate 	size_t		ucnt, tcnt;
275*0Sstevel@tonic-gate 	Bnd_desc *	bdp;
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate 	/*
278*0Sstevel@tonic-gate 	 * Obtain the Alist and determine its number of elements and those
279*0Sstevel@tonic-gate 	 * that are in use.
280*0Sstevel@tonic-gate 	 */
281*0Sstevel@tonic-gate 	if (mdb_vread(&al, sizeof (Alist), addr) == -1) {
282*0Sstevel@tonic-gate 	    mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr);
283*0Sstevel@tonic-gate 	    return (DCMD_ERR);
284*0Sstevel@tonic-gate 	}
285*0Sstevel@tonic-gate 
286*0Sstevel@tonic-gate 	ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size;
287*0Sstevel@tonic-gate 	tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size;
288*0Sstevel@tonic-gate 	mdb_printf(msg, addr, ucnt, tcnt);
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0))
291*0Sstevel@tonic-gate 		return (DCMD_OK);
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate 	/*
294*0Sstevel@tonic-gate 	 * Under verbose mode print the name of each dependency.  An Alist can
295*0Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
296*0Sstevel@tonic-gate 	 */
297*0Sstevel@tonic-gate 	listcalc = (uintptr_t)(&(al.al_data[0]));
298*0Sstevel@tonic-gate 	listcalc -= (uintptr_t)(&al);
299*0Sstevel@tonic-gate 	listcalc += addr;
300*0Sstevel@tonic-gate 	if (mdb_vread(&bdp, sizeof (Bnd_desc *), listcalc) == -1) {
301*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
302*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_BNDDESC_STR), listcalc);
303*0Sstevel@tonic-gate 		return (DCMD_ERR);
304*0Sstevel@tonic-gate 	}
305*0Sstevel@tonic-gate 
306*0Sstevel@tonic-gate 	mdb_inc_indent(4);
307*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate 	if (dcmd_Bind((uintptr_t)bdp, flags, argc, argv) == DCMD_ERR) {
310*0Sstevel@tonic-gate 		mdb_dec_indent(4);
311*0Sstevel@tonic-gate 		return (DCMD_ERR);
312*0Sstevel@tonic-gate 	}
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate 	listnext = (uintptr_t)(al.al_next + addr);
315*0Sstevel@tonic-gate 	for (listcalc += al.al_size; listcalc < listnext;
316*0Sstevel@tonic-gate 	    listcalc += al.al_size) {
317*0Sstevel@tonic-gate 		if (mdb_vread(&bdp, sizeof (Bnd_desc *), listcalc) == -1) {
318*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
319*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_BNDDESC_STR), listcalc);
320*0Sstevel@tonic-gate 			return (DCMD_ERR);
321*0Sstevel@tonic-gate 		}
322*0Sstevel@tonic-gate 
323*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
324*0Sstevel@tonic-gate 		if (dcmd_Bind((uintptr_t)bdp, flags, argc, argv) == DCMD_ERR) {
325*0Sstevel@tonic-gate 			mdb_dec_indent(4);
326*0Sstevel@tonic-gate 			return (DCMD_ERR);
327*0Sstevel@tonic-gate 		}
328*0Sstevel@tonic-gate 	}
329*0Sstevel@tonic-gate 	mdb_dec_indent(4);
330*0Sstevel@tonic-gate 	return (DCMD_OK);
331*0Sstevel@tonic-gate }
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate static int
334*0Sstevel@tonic-gate dcmd_Depends(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
335*0Sstevel@tonic-gate {
336*0Sstevel@tonic-gate 	Rt_map		rtmap;
337*0Sstevel@tonic-gate 	char		*str;
338*0Sstevel@tonic-gate 	uint_t		flg = 0;
339*0Sstevel@tonic-gate 
340*0Sstevel@tonic-gate 	/*
341*0Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
342*0Sstevel@tonic-gate 	 */
343*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
344*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_DEPENDS_STR));
345*0Sstevel@tonic-gate 		return (DCMD_USAGE);
346*0Sstevel@tonic-gate 	}
347*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
348*0Sstevel@tonic-gate 	    &flg, NULL) != argc)
349*0Sstevel@tonic-gate 		return (DCMD_USAGE);
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate 	/*
352*0Sstevel@tonic-gate 	 * Read the Rt_map contents.
353*0Sstevel@tonic-gate 	 */
354*0Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
355*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
356*0Sstevel@tonic-gate 		return (DCMD_ERR);
357*0Sstevel@tonic-gate 	}
358*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
359*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
360*0Sstevel@tonic-gate 		return (DCMD_ERR);
361*0Sstevel@tonic-gate 
362*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_DEPENDS_LINE1), str);
363*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
364*0Sstevel@tonic-gate 
365*0Sstevel@tonic-gate 	if (DEPENDS(&rtmap) == 0)
366*0Sstevel@tonic-gate 		return (DCMD_OK);
367*0Sstevel@tonic-gate 
368*0Sstevel@tonic-gate 	return (Depends((uintptr_t)DEPENDS(&rtmap), flags, argc, argv, flg,
369*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_DEPENDS_LINE2)));
370*0Sstevel@tonic-gate }
371*0Sstevel@tonic-gate 
372*0Sstevel@tonic-gate static void
373*0Sstevel@tonic-gate dcmd_Callers_help(void)
374*0Sstevel@tonic-gate {
375*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_CALLERS_HELP));
376*0Sstevel@tonic-gate }
377*0Sstevel@tonic-gate 
378*0Sstevel@tonic-gate static int
379*0Sstevel@tonic-gate dcmd_Callers(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
380*0Sstevel@tonic-gate {
381*0Sstevel@tonic-gate 	Rt_map		rtmap;
382*0Sstevel@tonic-gate 	char		*str;
383*0Sstevel@tonic-gate 	uint_t		flg = 0;
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate 	/*
386*0Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
387*0Sstevel@tonic-gate 	 */
388*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
389*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_DEPENDS_STR));
390*0Sstevel@tonic-gate 		return (DCMD_USAGE);
391*0Sstevel@tonic-gate 	}
392*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
393*0Sstevel@tonic-gate 	    &flg, NULL) != argc)
394*0Sstevel@tonic-gate 		return (DCMD_USAGE);
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate 	/*
397*0Sstevel@tonic-gate 	 * Read the Rt_map contents.
398*0Sstevel@tonic-gate 	 */
399*0Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
400*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
401*0Sstevel@tonic-gate 		return (DCMD_ERR);
402*0Sstevel@tonic-gate 	}
403*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
404*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
405*0Sstevel@tonic-gate 		return (DCMD_ERR);
406*0Sstevel@tonic-gate 
407*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_CALLERS_LINE1), str);
408*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
409*0Sstevel@tonic-gate 
410*0Sstevel@tonic-gate 	if (CALLERS(&rtmap) == 0)
411*0Sstevel@tonic-gate 		return (DCMD_OK);
412*0Sstevel@tonic-gate 
413*0Sstevel@tonic-gate 	return (Depends((uintptr_t)CALLERS(&rtmap), flags, argc, argv, flg,
414*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_CALLERS_LINE2)));
415*0Sstevel@tonic-gate }
416*0Sstevel@tonic-gate 
417*0Sstevel@tonic-gate void
418*0Sstevel@tonic-gate dcmd_rtmap_help(void)
419*0Sstevel@tonic-gate {
420*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_HELP));
421*0Sstevel@tonic-gate }
422*0Sstevel@tonic-gate 
423*0Sstevel@tonic-gate static int
424*0Sstevel@tonic-gate /* ARGSUSED2 */
425*0Sstevel@tonic-gate dcmd_rtmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
426*0Sstevel@tonic-gate {
427*0Sstevel@tonic-gate 	Rt_map		rtmap;
428*0Sstevel@tonic-gate 	char		*str;
429*0Sstevel@tonic-gate 
430*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
431*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_RTMAP_STR));
432*0Sstevel@tonic-gate 		return (DCMD_USAGE);
433*0Sstevel@tonic-gate 	}
434*0Sstevel@tonic-gate 
435*0Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
436*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
437*0Sstevel@tonic-gate 		return (DCMD_ERR);
438*0Sstevel@tonic-gate 	}
439*0Sstevel@tonic-gate 
440*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_TITLE), addr);
441*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
442*0Sstevel@tonic-gate 
443*0Sstevel@tonic-gate 	/*
444*0Sstevel@tonic-gate 	 * Determine the objects name.  NAME() is the name by which the object
445*0Sstevel@tonic-gate 	 * has been opened, typically from adding a search path to a file name.
446*0Sstevel@tonic-gate 	 * PATHNAME() is the fully resolve name, which is displayed by the proc
447*0Sstevel@tonic-gate 	 * tools and debuggers.  If the two names differ, print the PATHNAME().
448*0Sstevel@tonic-gate 	 */
449*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
450*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
451*0Sstevel@tonic-gate 		return (DCMD_ERR);
452*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE1), str);
453*0Sstevel@tonic-gate 	if (NAME(&rtmap) != PATHNAME(&rtmap)) {
454*0Sstevel@tonic-gate 		if ((str = String((uintptr_t)PATHNAME(&rtmap),
455*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_PATHNAME))) == 0)
456*0Sstevel@tonic-gate 			return (DCMD_ERR);
457*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_RTMAP_LINE2), str);
458*0Sstevel@tonic-gate 	}
459*0Sstevel@tonic-gate 
460*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE3), ADDR(&rtmap), DYN(&rtmap));
461*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE4), NEXT(&rtmap), PREV(&rtmap));
462*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE5), rtmap.rt_fct, TLSMODID(&rtmap));
463*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE6), INIT(&rtmap), FINI(&rtmap));
464*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE7), GROUPS(&rtmap), HANDLES(&rtmap));
465*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE8), DEPENDS(&rtmap), CALLERS(&rtmap));
466*0Sstevel@tonic-gate 
467*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)REFNAME(&rtmap),
468*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_REFNAME))) == 0)
469*0Sstevel@tonic-gate 		return (DCMD_ERR);
470*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE9), DYNINFO(&rtmap), str);
471*0Sstevel@tonic-gate 
472*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)RPATH(&rtmap),
473*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_RPATH))) == 0)
474*0Sstevel@tonic-gate 		return (DCMD_ERR);
475*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE10), RLIST(&rtmap), str);
476*0Sstevel@tonic-gate 
477*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE11), LIST(&rtmap), LIST(&rtmap));
478*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE12), FLAGS(&rtmap));
479*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), FLAGS(&rtmap), rtflags_bits);
480*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE13), FLAGS1(&rtmap));
481*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), FLAGS1(&rtmap), rtflags1_bits);
482*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE14), MODE(&rtmap));
483*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), MODE(&rtmap), rtmode_bits);
484*0Sstevel@tonic-gate 
485*0Sstevel@tonic-gate 	return (DCMD_OK);
486*0Sstevel@tonic-gate }
487*0Sstevel@tonic-gate 
488*0Sstevel@tonic-gate 
489*0Sstevel@tonic-gate static int
490*0Sstevel@tonic-gate rtmap_format(uintptr_t addr, const void * data, void * private)
491*0Sstevel@tonic-gate {
492*0Sstevel@tonic-gate 	const Rt_map	*lmp = (const Rt_map *)data;
493*0Sstevel@tonic-gate 	W_desc		*wdp = (W_desc *)private;
494*0Sstevel@tonic-gate 	char		*str;
495*0Sstevel@tonic-gate 
496*0Sstevel@tonic-gate 	if (wdp && (wdp->w_flags & RTLD_FLG_VERBOSE)) {
497*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
498*0Sstevel@tonic-gate 		mdb_call_dcmd(MSG_ORIG(MSG_RTMAP_STR), addr, DCMD_ADDRSPEC,
499*0Sstevel@tonic-gate 		    NULL, NULL);
500*0Sstevel@tonic-gate 		return (0);
501*0Sstevel@tonic-gate 	}
502*0Sstevel@tonic-gate 
503*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(lmp),
504*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
505*0Sstevel@tonic-gate 		return (DCMD_ERR);
506*0Sstevel@tonic-gate 
507*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_FMT_RT), CNTL(lmp), addr, ADDR(lmp), str);
508*0Sstevel@tonic-gate 	return (0);
509*0Sstevel@tonic-gate }
510*0Sstevel@tonic-gate 
511*0Sstevel@tonic-gate void
512*0Sstevel@tonic-gate dcmd_Rtmaps_help(void)
513*0Sstevel@tonic-gate {
514*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAPS_HELP));
515*0Sstevel@tonic-gate }
516*0Sstevel@tonic-gate 
517*0Sstevel@tonic-gate static int
518*0Sstevel@tonic-gate dcmd_Rtmaps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
519*0Sstevel@tonic-gate {
520*0Sstevel@tonic-gate 	uint_t		flg = 0;
521*0Sstevel@tonic-gate 	GElf_Sym	gsym;
522*0Sstevel@tonic-gate 	List		l;
523*0Sstevel@tonic-gate 	Listnode	ln;
524*0Sstevel@tonic-gate 	uintptr_t	naddr;
525*0Sstevel@tonic-gate 	const char	*str;
526*0Sstevel@tonic-gate 	W_desc		wdesc;
527*0Sstevel@tonic-gate 
528*0Sstevel@tonic-gate 	/*
529*0Sstevel@tonic-gate 	 * '-v' - Verbose output of rtmap
530*0Sstevel@tonic-gate 	 */
531*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
532*0Sstevel@tonic-gate 	    &flg, NULL) != argc)
533*0Sstevel@tonic-gate 		return (DCMD_USAGE);
534*0Sstevel@tonic-gate 
535*0Sstevel@tonic-gate 	/*
536*0Sstevel@tonic-gate 	 * If an address was provided use it.
537*0Sstevel@tonic-gate 	 */
538*0Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC) {
539*0Sstevel@tonic-gate 		if (((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) &&
540*0Sstevel@tonic-gate 		    !(flg & RTLD_FLG_VERBOSE)) {
541*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
542*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
543*0Sstevel@tonic-gate 		}
544*0Sstevel@tonic-gate 
545*0Sstevel@tonic-gate 		wdesc.w_flags = flg;
546*0Sstevel@tonic-gate 		if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), rtmap_format,
547*0Sstevel@tonic-gate 		    (void *)&wdesc, addr) == -1)
548*0Sstevel@tonic-gate 			return (DCMD_ERR);
549*0Sstevel@tonic-gate 		return (DCMD_OK);
550*0Sstevel@tonic-gate 	}
551*0Sstevel@tonic-gate 
552*0Sstevel@tonic-gate 	/*
553*0Sstevel@tonic-gate 	 * Otherwise traverse the dynlm_list and display each link-map.
554*0Sstevel@tonic-gate 	 */
555*0Sstevel@tonic-gate 	if (mdb_lookup_by_obj(MSG_ORIG(MSG_STR_LDSO1),
556*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_DYNLMLIST), &gsym) == -1) {
557*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_SYMFAILED), MSG_ORIG(MSG_STR_LDSO1),
558*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_DYNLMLIST));
559*0Sstevel@tonic-gate 		return (DCMD_ERR);
560*0Sstevel@tonic-gate 	}
561*0Sstevel@tonic-gate 	if (mdb_vread((void *)&l, sizeof (l), (uintptr_t)gsym.st_value) == -1) {
562*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_LIST_STR),
563*0Sstevel@tonic-gate 		    gsym.st_value);
564*0Sstevel@tonic-gate 		return (DCMD_ERR);
565*0Sstevel@tonic-gate 	}
566*0Sstevel@tonic-gate 
567*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE1), MSG_ORIG(MSG_STR_DYNLMLIST),
568*0Sstevel@tonic-gate 	    &gsym);
569*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
570*0Sstevel@tonic-gate 
571*0Sstevel@tonic-gate 	flags |= (DCMD_LOOP | DCMD_LOOPFIRST);
572*0Sstevel@tonic-gate 	for (naddr = (uintptr_t)l.head; naddr; naddr = (uintptr_t)ln.next) {
573*0Sstevel@tonic-gate 		Lm_list	lml;
574*0Sstevel@tonic-gate 
575*0Sstevel@tonic-gate 		if (mdb_vread(&ln, sizeof (ln), naddr) == -1) {
576*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
577*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_STR_LISTNODE), naddr);
578*0Sstevel@tonic-gate 			return (DCMD_ERR);
579*0Sstevel@tonic-gate 		}
580*0Sstevel@tonic-gate 		if (mdb_vread(&lml, sizeof (lml), (uintptr_t)ln.data) == -1) {
581*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
582*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_LMLIST_STR), ln.data);
583*0Sstevel@tonic-gate 			return (DCMD_ERR);
584*0Sstevel@tonic-gate 		}
585*0Sstevel@tonic-gate 
586*0Sstevel@tonic-gate 		mdb_inc_indent(2);
587*0Sstevel@tonic-gate 		if (lml.lm_flags & LML_FLG_BASELM)
588*0Sstevel@tonic-gate 			str = MSG_ORIG(MSG_LMLIST_BASE);
589*0Sstevel@tonic-gate 		else if (lml.lm_flags & LML_FLG_RTLDLM)
590*0Sstevel@tonic-gate 			str = MSG_ORIG(MSG_LMLIST_LDSO);
591*0Sstevel@tonic-gate 		else
592*0Sstevel@tonic-gate 			str = MSG_ORIG(MSG_LMLIST_NEWLM);
593*0Sstevel@tonic-gate 
594*0Sstevel@tonic-gate 		if ((flags & DCMD_LOOP) && ((flags & DCMD_LOOPFIRST) == 0))
595*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
596*0Sstevel@tonic-gate 
597*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE2), ln.data, str);
598*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
599*0Sstevel@tonic-gate 
600*0Sstevel@tonic-gate 		mdb_inc_indent(2);
601*0Sstevel@tonic-gate 
602*0Sstevel@tonic-gate 		if (((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) &&
603*0Sstevel@tonic-gate 		    !(flg & RTLD_FLG_VERBOSE)) {
604*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
605*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
606*0Sstevel@tonic-gate 		}
607*0Sstevel@tonic-gate 
608*0Sstevel@tonic-gate 		wdesc.w_flags = flg;
609*0Sstevel@tonic-gate 		if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), rtmap_format,
610*0Sstevel@tonic-gate 		    (void *)&wdesc, (uintptr_t)lml.lm_head) == -1) {
611*0Sstevel@tonic-gate 			mdb_dec_indent(4);
612*0Sstevel@tonic-gate 			return (DCMD_ERR);
613*0Sstevel@tonic-gate 		}
614*0Sstevel@tonic-gate 		mdb_dec_indent(4);
615*0Sstevel@tonic-gate 		flags &= ~DCMD_LOOPFIRST;
616*0Sstevel@tonic-gate 	}
617*0Sstevel@tonic-gate 	return (DCMD_OK);
618*0Sstevel@tonic-gate }
619*0Sstevel@tonic-gate 
620*0Sstevel@tonic-gate static int
621*0Sstevel@tonic-gate /* ARGSUSED2 */
622*0Sstevel@tonic-gate format_listnode(uintptr_t addr, const void * data, void * private)
623*0Sstevel@tonic-gate {
624*0Sstevel@tonic-gate 	Listnode *	lnp = (Listnode *)data;
625*0Sstevel@tonic-gate 
626*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_FMT_LN), addr, lnp->data, lnp->next);
627*0Sstevel@tonic-gate 	return (0);
628*0Sstevel@tonic-gate }
629*0Sstevel@tonic-gate 
630*0Sstevel@tonic-gate void
631*0Sstevel@tonic-gate dcmd_List_help(void)
632*0Sstevel@tonic-gate {
633*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LIST_HELP));
634*0Sstevel@tonic-gate }
635*0Sstevel@tonic-gate 
636*0Sstevel@tonic-gate static int
637*0Sstevel@tonic-gate /* ARGSUSED2 */
638*0Sstevel@tonic-gate dcmd_List(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
639*0Sstevel@tonic-gate {
640*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
641*0Sstevel@tonic-gate 		return (DCMD_USAGE);
642*0Sstevel@tonic-gate 	if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) {
643*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_LIST_TITLE));
644*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
645*0Sstevel@tonic-gate 	}
646*0Sstevel@tonic-gate 	if (mdb_pwalk(MSG_ORIG(MSG_LIST_STR), format_listnode,
647*0Sstevel@tonic-gate 	    (void *)0, addr) == -1)
648*0Sstevel@tonic-gate 		return (DCMD_ERR);
649*0Sstevel@tonic-gate 	return (DCMD_OK);
650*0Sstevel@tonic-gate }
651*0Sstevel@tonic-gate 
652*0Sstevel@tonic-gate void
653*0Sstevel@tonic-gate dcmd_Setenv_help(void)
654*0Sstevel@tonic-gate {
655*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_SETENV_HELP));
656*0Sstevel@tonic-gate }
657*0Sstevel@tonic-gate 
658*0Sstevel@tonic-gate /*
659*0Sstevel@tonic-gate  * As of s10, mdb provides its own setenv command.  This command allows the
660*0Sstevel@tonic-gate  * environment of the process being controlled to be changed at any time.
661*0Sstevel@tonic-gate  * Prior to this, ld.so.1 provided it's own, more primitive implementation.
662*0Sstevel@tonic-gate  * This allowed for changing mdb's environment only, which if it was changed
663*0Sstevel@tonic-gate  * before the application ws executed, would be copied to the applications
664*0Sstevel@tonic-gate  * environment.  Thus, we could start mdb, set an LD_ variable within its
665*0Sstevel@tonic-gate  * environment (which it's own ld.so.1 had already finished processing), and
666*0Sstevel@tonic-gate  * have this setting be inherited by the application.
667*0Sstevel@tonic-gate  */
668*0Sstevel@tonic-gate static int
669*0Sstevel@tonic-gate /* ARGSUSED */
670*0Sstevel@tonic-gate dcmd_Setenv(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
671*0Sstevel@tonic-gate {
672*0Sstevel@tonic-gate 	char	*str;
673*0Sstevel@tonic-gate 
674*0Sstevel@tonic-gate 	if (mdb_call_dcmd(MSG_ORIG(MSG_STR_SETENV), addr, flags, argc,
675*0Sstevel@tonic-gate 	    argv) == 0)
676*0Sstevel@tonic-gate 		return (DCMD_OK);
677*0Sstevel@tonic-gate 
678*0Sstevel@tonic-gate 	if (((flags & DCMD_ADDRSPEC) != 0) || (argc == 0) || (argc > 1) ||
679*0Sstevel@tonic-gate 	    (argv->a_type != MDB_TYPE_STRING))
680*0Sstevel@tonic-gate 		return (DCMD_USAGE);
681*0Sstevel@tonic-gate 
682*0Sstevel@tonic-gate 	str = mdb_alloc((strlen(argv->a_un.a_str) + 1), UM_NOSLEEP);
683*0Sstevel@tonic-gate 	if (str == NULL)
684*0Sstevel@tonic-gate 		return (DCMD_ERR);
685*0Sstevel@tonic-gate 
686*0Sstevel@tonic-gate 	(void) strcpy(str, argv->a_un.a_str);
687*0Sstevel@tonic-gate 	(void) putenv(str);
688*0Sstevel@tonic-gate 	return (DCMD_OK);
689*0Sstevel@tonic-gate }
690*0Sstevel@tonic-gate 
691*0Sstevel@tonic-gate int
692*0Sstevel@tonic-gate walk_List_init(mdb_walk_state_t *wsp)
693*0Sstevel@tonic-gate {
694*0Sstevel@tonic-gate 	List	lst;
695*0Sstevel@tonic-gate 
696*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
697*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_LIST_STR));
698*0Sstevel@tonic-gate 		return (WALK_ERR);
699*0Sstevel@tonic-gate 	}
700*0Sstevel@tonic-gate 
701*0Sstevel@tonic-gate 	if (mdb_vread(&lst, sizeof (List), wsp->walk_addr) == -1) {
702*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
703*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_LIST_STR), wsp->walk_addr);
704*0Sstevel@tonic-gate 		return (WALK_DONE);
705*0Sstevel@tonic-gate 	}
706*0Sstevel@tonic-gate 
707*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)lst.head;
708*0Sstevel@tonic-gate 	return (WALK_NEXT);
709*0Sstevel@tonic-gate }
710*0Sstevel@tonic-gate 
711*0Sstevel@tonic-gate 
712*0Sstevel@tonic-gate static int
713*0Sstevel@tonic-gate walk_List_step(mdb_walk_state_t *wsp)
714*0Sstevel@tonic-gate {
715*0Sstevel@tonic-gate 	Listnode	lnp;
716*0Sstevel@tonic-gate 	int		status;
717*0Sstevel@tonic-gate 
718*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL)
719*0Sstevel@tonic-gate 		return (WALK_DONE);
720*0Sstevel@tonic-gate 
721*0Sstevel@tonic-gate 	if (mdb_vread(&lnp, sizeof (Listnode), wsp->walk_addr) == -1) {
722*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
723*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_LISTNODE), wsp->walk_addr);
724*0Sstevel@tonic-gate 		return (WALK_DONE);
725*0Sstevel@tonic-gate 	}
726*0Sstevel@tonic-gate 
727*0Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &lnp, wsp->walk_cbdata);
728*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)lnp.next;
729*0Sstevel@tonic-gate 	return (status);
730*0Sstevel@tonic-gate }
731*0Sstevel@tonic-gate 
732*0Sstevel@tonic-gate /*
733*0Sstevel@tonic-gate  * Walk Rt_map lists
734*0Sstevel@tonic-gate  */
735*0Sstevel@tonic-gate static int
736*0Sstevel@tonic-gate walk_rtmap_init(mdb_walk_state_t *wsp)
737*0Sstevel@tonic-gate {
738*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
739*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_RTMAP_STR));
740*0Sstevel@tonic-gate 		return (WALK_ERR);
741*0Sstevel@tonic-gate 	}
742*0Sstevel@tonic-gate 	return (WALK_NEXT);
743*0Sstevel@tonic-gate }
744*0Sstevel@tonic-gate 
745*0Sstevel@tonic-gate static int
746*0Sstevel@tonic-gate walk_rtmap_step(mdb_walk_state_t *wsp)
747*0Sstevel@tonic-gate {
748*0Sstevel@tonic-gate 	int	status;
749*0Sstevel@tonic-gate 	Rt_map	lmp;
750*0Sstevel@tonic-gate 
751*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL)
752*0Sstevel@tonic-gate 		return (WALK_DONE);
753*0Sstevel@tonic-gate 	if (mdb_vread(&lmp, sizeof (Rt_map), wsp->walk_addr) == -1) {
754*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
755*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_RTMAP_STR), wsp->walk_addr);
756*0Sstevel@tonic-gate 		return (WALK_DONE);
757*0Sstevel@tonic-gate 	}
758*0Sstevel@tonic-gate 
759*0Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &lmp, wsp->walk_cbdata);
760*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)(NEXT(&lmp));
761*0Sstevel@tonic-gate 	return (status);
762*0Sstevel@tonic-gate }
763*0Sstevel@tonic-gate 
764*0Sstevel@tonic-gate static const mdb_bitmask_t lml_flags_bit[] = {
765*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_BASELM), LML_FLG_BASELM, LML_FLG_BASELM },
766*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_RTLDLM), LML_FLG_RTLDLM, LML_FLG_RTLDLM },
767*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_NOAUDIT), LML_FLG_NOAUDIT, LML_FLG_NOAUDIT },
768*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_PLTREL), LML_FLG_PLTREL, LML_FLG_PLTREL },
769*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_HOLDLOCK), LML_FLG_HOLDLOCK, LML_FLG_HOLDLOCK },
770*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_ENVIRON), LML_FLG_ENVIRON, LML_FLG_ENVIRON },
771*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_INTRPOSE), LML_FLG_INTRPOSE, LML_FLG_INTRPOSE },
772*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_LOCAUDIT), LML_FLG_LOCAUDIT, LML_FLG_LOCAUDIT },
773*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_LOADAVAIL), LML_FLG_LOADAVAIL, LML_FLG_LOADAVAIL },
774*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_IGNRELERR), LML_FLG_IGNRELERR, LML_FLG_IGNRELERR },
775*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_DBNOTIF), LML_FLG_DBNOTIF, LML_FLG_DBNOTIF },
776*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_BNDUNINIT), LML_FLG_BNDUNINIT, LML_FLG_BNDUNINIT },
777*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_STARTREL), LML_FLG_STARTREL, LML_FLG_STARTREL },
778*0Sstevel@tonic-gate 
779*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_LDDSTUB), LML_FLG_TRC_LDDSTUB,
780*0Sstevel@tonic-gate 	    LML_FLG_TRC_LDDSTUB },
781*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_ENABLE), LML_FLG_TRC_ENABLE,
782*0Sstevel@tonic-gate 	    LML_FLG_TRC_ENABLE },
783*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_WARN), LML_FLG_TRC_WARN, LML_FLG_TRC_WARN },
784*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_VERBOSE), LML_FLG_TRC_VERBOSE,
785*0Sstevel@tonic-gate 	    LML_FLG_TRC_VERBOSE },
786*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_SEARCH), LML_FLG_TRC_SEARCH,
787*0Sstevel@tonic-gate 	    LML_FLG_TRC_SEARCH },
788*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_UNREF), LML_FLG_TRC_UNREF, LML_FLG_TRC_UNREF },
789*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_UNUSED), LML_FLG_TRC_UNUSED,
790*0Sstevel@tonic-gate 	    LML_FLG_TRC_UNUSED },
791*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_INIT), LML_FLG_TRC_INIT, LML_FLG_TRC_INIT },
792*0Sstevel@tonic-gate 	{ NULL, 0, 0}
793*0Sstevel@tonic-gate };
794*0Sstevel@tonic-gate 
795*0Sstevel@tonic-gate static const mdb_bitmask_t lml_tflags_bit[] = {
796*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_NOLAZYLD), LML_TFLG_NOLAZYLD, LML_TFLG_NOLAZYLD },
797*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_NODIRECT), LML_TFLG_NODIRECT, LML_TFLG_NODIRECT },
798*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_LOADFLTR), LML_TFLG_LOADFLTR, LML_TFLG_LOADFLTR },
799*0Sstevel@tonic-gate 
800*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PREINIT), LML_TFLG_AUD_PREINIT,
801*0Sstevel@tonic-gate 	    LML_TFLG_AUD_PREINIT },
802*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJSEARCH), LML_TFLG_AUD_OBJSEARCH,
803*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJSEARCH },
804*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJOPEN), LML_TFLG_AUD_OBJOPEN,
805*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJOPEN },
806*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJFILTER), LML_TFLG_AUD_OBJFILTER,
807*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJFILTER },
808*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJCLOSE), LML_TFLG_AUD_OBJCLOSE,
809*0Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJCLOSE },
810*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_SYMBIND), LML_TFLG_AUD_SYMBIND,
811*0Sstevel@tonic-gate 	    LML_TFLG_AUD_SYMBIND },
812*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTENTER), LML_TFLG_AUD_PLTENTER,
813*0Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTENTER },
814*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTEXIT), LML_TFLG_AUD_PLTEXIT,
815*0Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTEXIT },
816*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_ACTIVITY), LML_TFLG_AUD_ACTIVITY,
817*0Sstevel@tonic-gate 	    LML_TFLG_AUD_ACTIVITY },
818*0Sstevel@tonic-gate 	{ NULL, 0, 0}
819*0Sstevel@tonic-gate };
820*0Sstevel@tonic-gate 
821*0Sstevel@tonic-gate void
822*0Sstevel@tonic-gate dcmd_Lm_list_help(void)
823*0Sstevel@tonic-gate {
824*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_HELP));
825*0Sstevel@tonic-gate }
826*0Sstevel@tonic-gate 
827*0Sstevel@tonic-gate static int
828*0Sstevel@tonic-gate /* ARGSUSED1 */
829*0Sstevel@tonic-gate _dcmd_Lm_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
830*0Sstevel@tonic-gate {
831*0Sstevel@tonic-gate 	Lm_list		lml;
832*0Sstevel@tonic-gate 	const char	*str;
833*0Sstevel@tonic-gate 	uint_t		flg = 0;
834*0Sstevel@tonic-gate 
835*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
836*0Sstevel@tonic-gate 	    &flg, NULL) != argc)
837*0Sstevel@tonic-gate 		return (DCMD_USAGE);
838*0Sstevel@tonic-gate 
839*0Sstevel@tonic-gate 	if (mdb_vread(&lml, sizeof (lml), addr) == -1) {
840*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_LMLIST_STR),
841*0Sstevel@tonic-gate 		    addr);
842*0Sstevel@tonic-gate 		return (DCMD_ERR);
843*0Sstevel@tonic-gate 	}
844*0Sstevel@tonic-gate 
845*0Sstevel@tonic-gate 	if (lml.lm_flags & LML_FLG_BASELM)
846*0Sstevel@tonic-gate 		str = MSG_ORIG(MSG_LMLIST_BASE);
847*0Sstevel@tonic-gate 	else if (lml.lm_flags & LML_FLG_RTLDLM)
848*0Sstevel@tonic-gate 		str = MSG_ORIG(MSG_LMLIST_LDSO);
849*0Sstevel@tonic-gate 	else
850*0Sstevel@tonic-gate 		str = MSG_ORIG(MSG_LMLIST_NEWLM);
851*0Sstevel@tonic-gate 
852*0Sstevel@tonic-gate 	if ((flags & DCMD_LOOP) && ((flags & DCMD_LOOPFIRST) == 0))
853*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
854*0Sstevel@tonic-gate 
855*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE2), addr, str);
856*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
857*0Sstevel@tonic-gate 
858*0Sstevel@tonic-gate 	if (lml.lm_lists) {
859*0Sstevel@tonic-gate 		Alist		al;
860*0Sstevel@tonic-gate 		size_t		ucnt, tcnt;
861*0Sstevel@tonic-gate 		Lm_cntl		lmc;
862*0Sstevel@tonic-gate 		uintptr_t	listcalc;
863*0Sstevel@tonic-gate 
864*0Sstevel@tonic-gate 		addr = (uintptr_t)lml.lm_lists;
865*0Sstevel@tonic-gate 		if (mdb_vread(&al, sizeof (Alist), addr) == -1) {
866*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
867*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_STR_ALIST), addr);
868*0Sstevel@tonic-gate 			return (DCMD_ERR);
869*0Sstevel@tonic-gate 		}
870*0Sstevel@tonic-gate 
871*0Sstevel@tonic-gate 		/*
872*0Sstevel@tonic-gate 		 * Determine whether the Alist has been populated.  Note, the
873*0Sstevel@tonic-gate 		 * implementation first reserves an alist entry, and initializes
874*0Sstevel@tonic-gate 		 * this element when the first link-map is processed.  Thus,
875*0Sstevel@tonic-gate 		 * there's a window when ucnt is updated, but before the next
876*0Sstevel@tonic-gate 		 * element has been initialized.
877*0Sstevel@tonic-gate 		 */
878*0Sstevel@tonic-gate 		ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) /
879*0Sstevel@tonic-gate 			al.al_size;
880*0Sstevel@tonic-gate 		tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) /
881*0Sstevel@tonic-gate 			al.al_size;
882*0Sstevel@tonic-gate 
883*0Sstevel@tonic-gate 		if (ucnt && (flg & RTLD_FLG_VERBOSE)) {
884*0Sstevel@tonic-gate 			listcalc = (uintptr_t)(&(al.al_data[0]));
885*0Sstevel@tonic-gate 			listcalc -= (uintptr_t)(&al);
886*0Sstevel@tonic-gate 			listcalc += addr;
887*0Sstevel@tonic-gate 
888*0Sstevel@tonic-gate 			if (mdb_vread(&lmc, sizeof (Lm_cntl),
889*0Sstevel@tonic-gate 			    listcalc) == -1) {
890*0Sstevel@tonic-gate 				mdb_warn(MSG_ORIG(MSG_ERR_READ),
891*0Sstevel@tonic-gate 				    MSG_ORIG(MSG_LMLIST_STR), listcalc);
892*0Sstevel@tonic-gate 				return (DCMD_ERR);
893*0Sstevel@tonic-gate 			}
894*0Sstevel@tonic-gate 		}
895*0Sstevel@tonic-gate 
896*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_LMLIST_LINE0), addr, ucnt, tcnt);
897*0Sstevel@tonic-gate 		mdb_inc_indent(2);
898*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
899*0Sstevel@tonic-gate 
900*0Sstevel@tonic-gate 		if (ucnt && (flg & RTLD_FLG_VERBOSE)) {
901*0Sstevel@tonic-gate 			uintptr_t	listnext;
902*0Sstevel@tonic-gate 
903*0Sstevel@tonic-gate 			mdb_inc_indent(2);
904*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_LMC_LINE1), listcalc);
905*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_LMC_LINE2), lmc.lc_head,
906*0Sstevel@tonic-gate 			    lmc.lc_tail);
907*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_LMC_LINE3), lmc.lc_flags,
908*0Sstevel@tonic-gate 			    lmc.lc_now);
909*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_LMC_LINE4), lmc.lc_flags,
910*0Sstevel@tonic-gate 			    lmc_bits);
911*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
912*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
913*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
914*0Sstevel@tonic-gate 
915*0Sstevel@tonic-gate 			if (lmc.lc_head) {
916*0Sstevel@tonic-gate 				if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR),
917*0Sstevel@tonic-gate 				    rtmap_format, (void *)0,
918*0Sstevel@tonic-gate 				    (uintptr_t)lmc.lc_head) == -1) {
919*0Sstevel@tonic-gate 					mdb_dec_indent(4);
920*0Sstevel@tonic-gate 					return (DCMD_ERR);
921*0Sstevel@tonic-gate 				}
922*0Sstevel@tonic-gate 			} else
923*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_FMT_RT), 0, 0, 0,
924*0Sstevel@tonic-gate 				    MSG_ORIG(MSG_STR_EMPTY));
925*0Sstevel@tonic-gate 
926*0Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
927*0Sstevel@tonic-gate 
928*0Sstevel@tonic-gate 			listnext = (uintptr_t)(al.al_next + addr);
929*0Sstevel@tonic-gate 			for (listcalc += al.al_size; listcalc < listnext;
930*0Sstevel@tonic-gate 			    listcalc += al.al_size) {
931*0Sstevel@tonic-gate 				if (mdb_vread(&lmc, sizeof (Lm_cntl),
932*0Sstevel@tonic-gate 				    listcalc) == -1) {
933*0Sstevel@tonic-gate 					mdb_warn(MSG_ORIG(MSG_ERR_READ),
934*0Sstevel@tonic-gate 					    MSG_ORIG(MSG_LMLIST_STR), listcalc);
935*0Sstevel@tonic-gate 					mdb_dec_indent(4);
936*0Sstevel@tonic-gate 					return (DCMD_ERR);
937*0Sstevel@tonic-gate 				}
938*0Sstevel@tonic-gate 
939*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
940*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_LMC_LINE1), listcalc);
941*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_LMC_LINE2),
942*0Sstevel@tonic-gate 				    lmc.lc_head, lmc.lc_tail);
943*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_LMC_LINE3),
944*0Sstevel@tonic-gate 				    lmc.lc_flags, lmc.lc_now);
945*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_LMC_LINE4),
946*0Sstevel@tonic-gate 				    lmc.lc_flags, lmc_bits);
947*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
948*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
949*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
950*0Sstevel@tonic-gate 
951*0Sstevel@tonic-gate 				if (lmc.lc_head) {
952*0Sstevel@tonic-gate 					if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR),
953*0Sstevel@tonic-gate 					    rtmap_format, (void *)0,
954*0Sstevel@tonic-gate 					    (uintptr_t)lmc.lc_head) == -1) {
955*0Sstevel@tonic-gate 						mdb_dec_indent(4);
956*0Sstevel@tonic-gate 						return (DCMD_ERR);
957*0Sstevel@tonic-gate 					}
958*0Sstevel@tonic-gate 				} else
959*0Sstevel@tonic-gate 					mdb_printf(MSG_ORIG(MSG_FMT_RT), 0, 0,
960*0Sstevel@tonic-gate 					    0, MSG_ORIG(MSG_STR_EMPTY));
961*0Sstevel@tonic-gate 
962*0Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
963*0Sstevel@tonic-gate 			}
964*0Sstevel@tonic-gate 			mdb_dec_indent(2);
965*0Sstevel@tonic-gate 		}
966*0Sstevel@tonic-gate 		mdb_dec_indent(2);
967*0Sstevel@tonic-gate 	}
968*0Sstevel@tonic-gate 
969*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE1), lml.lm_head, lml.lm_tail);
970*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE2), lml.lm_alp, lml.lm_peh_lmp);
971*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE3), lml.lm_handle, lml.lm_obj,
972*0Sstevel@tonic-gate 	    lml.lm_init, lml.lm_lazy);
973*0Sstevel@tonic-gate 
974*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE4), lml.lm_flags);
975*0Sstevel@tonic-gate 	if (lml.lm_flags)
976*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_LMLIST_LINE6), lml.lm_flags,
977*0Sstevel@tonic-gate 		    lml_flags_bit);
978*0Sstevel@tonic-gate 
979*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE5), lml.lm_tflags);
980*0Sstevel@tonic-gate 	if (lml.lm_tflags)
981*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_LMLIST_LINE6), lml.lm_tflags,
982*0Sstevel@tonic-gate 		    lml_tflags_bit);
983*0Sstevel@tonic-gate 
984*0Sstevel@tonic-gate 	return (DCMD_OK);
985*0Sstevel@tonic-gate }
986*0Sstevel@tonic-gate 
987*0Sstevel@tonic-gate static int
988*0Sstevel@tonic-gate /* ARGSUSED2 */
989*0Sstevel@tonic-gate dcmd_Lm_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
990*0Sstevel@tonic-gate {
991*0Sstevel@tonic-gate 	GElf_Sym	gsym;
992*0Sstevel@tonic-gate 	List		l;
993*0Sstevel@tonic-gate 	Listnode	ln;
994*0Sstevel@tonic-gate 	uintptr_t	naddr;
995*0Sstevel@tonic-gate 
996*0Sstevel@tonic-gate 	/*
997*0Sstevel@tonic-gate 	 * If an address was provided us it.
998*0Sstevel@tonic-gate 	 */
999*0Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
1000*0Sstevel@tonic-gate 		return (_dcmd_Lm_list(addr, flags, argc, argv));
1001*0Sstevel@tonic-gate 
1002*0Sstevel@tonic-gate 	/*
1003*0Sstevel@tonic-gate 	 * Otherwise traverse the dynlm_list and display each link-map list.
1004*0Sstevel@tonic-gate 	 */
1005*0Sstevel@tonic-gate 	if (mdb_lookup_by_obj(MSG_ORIG(MSG_STR_LDSO1),
1006*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_DYNLMLIST), &gsym) == -1) {
1007*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_SYMFAILED), MSG_ORIG(MSG_STR_LDSO1),
1008*0Sstevel@tonic-gate 			MSG_ORIG(MSG_STR_DYNLMLIST));
1009*0Sstevel@tonic-gate 		return (DCMD_ERR);
1010*0Sstevel@tonic-gate 	}
1011*0Sstevel@tonic-gate 	if (mdb_vread((void *)&l, sizeof (l), (uintptr_t)gsym.st_value) == -1) {
1012*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_LIST_STR),
1013*0Sstevel@tonic-gate 		    gsym.st_value);
1014*0Sstevel@tonic-gate 		return (DCMD_ERR);
1015*0Sstevel@tonic-gate 	}
1016*0Sstevel@tonic-gate 
1017*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE1), MSG_ORIG(MSG_STR_DYNLMLIST),
1018*0Sstevel@tonic-gate 	    &gsym);
1019*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1020*0Sstevel@tonic-gate 
1021*0Sstevel@tonic-gate 	flags |= (DCMD_LOOP | DCMD_LOOPFIRST);
1022*0Sstevel@tonic-gate 	for (naddr = (uintptr_t)l.head; naddr; naddr = (uintptr_t)ln.next) {
1023*0Sstevel@tonic-gate 		if (mdb_vread(&ln, sizeof (ln), naddr) == -1) {
1024*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
1025*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_STR_LISTNODE), naddr);
1026*0Sstevel@tonic-gate 			return (DCMD_ERR);
1027*0Sstevel@tonic-gate 		}
1028*0Sstevel@tonic-gate 
1029*0Sstevel@tonic-gate 		mdb_inc_indent(2);
1030*0Sstevel@tonic-gate 		if (_dcmd_Lm_list((uintptr_t)ln.data, flags,
1031*0Sstevel@tonic-gate 		    argc, argv) == DCMD_ERR) {
1032*0Sstevel@tonic-gate 			mdb_dec_indent(2);
1033*0Sstevel@tonic-gate 			return (DCMD_ERR);
1034*0Sstevel@tonic-gate 		}
1035*0Sstevel@tonic-gate 		mdb_dec_indent(2);
1036*0Sstevel@tonic-gate 		flags &= ~DCMD_LOOPFIRST;
1037*0Sstevel@tonic-gate 	}
1038*0Sstevel@tonic-gate 	return (DCMD_OK);
1039*0Sstevel@tonic-gate }
1040*0Sstevel@tonic-gate 
1041*0Sstevel@tonic-gate void
1042*0Sstevel@tonic-gate dcmd_GrpDesc_help(void)
1043*0Sstevel@tonic-gate {
1044*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_HELP));
1045*0Sstevel@tonic-gate }
1046*0Sstevel@tonic-gate 
1047*0Sstevel@tonic-gate static int
1048*0Sstevel@tonic-gate /* ARGSUSED2 */
1049*0Sstevel@tonic-gate dcmd_GrpDesc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1050*0Sstevel@tonic-gate {
1051*0Sstevel@tonic-gate 	Grp_desc	gd;
1052*0Sstevel@tonic-gate 	char		*str;
1053*0Sstevel@tonic-gate 
1054*0Sstevel@tonic-gate 	/*
1055*0Sstevel@tonic-gate 	 * Insure we have a valid address.
1056*0Sstevel@tonic-gate 	 */
1057*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
1058*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GRPDESC_STR));
1059*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1060*0Sstevel@tonic-gate 	}
1061*0Sstevel@tonic-gate 
1062*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE1), addr);
1063*0Sstevel@tonic-gate 	if (mdb_vread(&gd, sizeof (Grp_desc), addr) == -1) {
1064*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_GRPDESC_STR),
1065*0Sstevel@tonic-gate 		    addr);
1066*0Sstevel@tonic-gate 		return (DCMD_ERR);
1067*0Sstevel@tonic-gate 	}
1068*0Sstevel@tonic-gate 
1069*0Sstevel@tonic-gate 	if ((str = Rtmap_Name((uintptr_t)gd.gd_depend)) == 0)
1070*0Sstevel@tonic-gate 		return (DCMD_ERR);
1071*0Sstevel@tonic-gate 
1072*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE2), gd.gd_depend, str);
1073*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE3), gd.gd_flags, gd.gd_flags,
1074*0Sstevel@tonic-gate 	    grdflags_bits);
1075*0Sstevel@tonic-gate 
1076*0Sstevel@tonic-gate 	return (DCMD_OK);
1077*0Sstevel@tonic-gate }
1078*0Sstevel@tonic-gate 
1079*0Sstevel@tonic-gate void
1080*0Sstevel@tonic-gate dcmd_GrpHdl_help(void)
1081*0Sstevel@tonic-gate {
1082*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_HELP));
1083*0Sstevel@tonic-gate }
1084*0Sstevel@tonic-gate 
1085*0Sstevel@tonic-gate static int
1086*0Sstevel@tonic-gate /* ARGSUSED2 */
1087*0Sstevel@tonic-gate dcmd_GrpHdl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1088*0Sstevel@tonic-gate {
1089*0Sstevel@tonic-gate 	Grp_hdl		gh;
1090*0Sstevel@tonic-gate 	Alist		al;
1091*0Sstevel@tonic-gate 	uintptr_t	listcalc, listnext;
1092*0Sstevel@tonic-gate 	char		*str;
1093*0Sstevel@tonic-gate 	uint_t		flg = 0;
1094*0Sstevel@tonic-gate 	size_t		ucnt, tcnt;
1095*0Sstevel@tonic-gate 
1096*0Sstevel@tonic-gate 	/*
1097*0Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
1098*0Sstevel@tonic-gate 	 */
1099*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
1100*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GRPHDL_STR));
1101*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1102*0Sstevel@tonic-gate 	}
1103*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
1104*0Sstevel@tonic-gate 	    &flg, NULL) != argc)
1105*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1106*0Sstevel@tonic-gate 
1107*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE1), addr);
1108*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1109*0Sstevel@tonic-gate 
1110*0Sstevel@tonic-gate 	if (mdb_vread(&gh, sizeof (Grp_hdl), addr) == -1) {
1111*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_GRPHDL_STR),
1112*0Sstevel@tonic-gate 		    addr);
1113*0Sstevel@tonic-gate 		return (DCMD_ERR);
1114*0Sstevel@tonic-gate 	}
1115*0Sstevel@tonic-gate 
1116*0Sstevel@tonic-gate 	/*
1117*0Sstevel@tonic-gate 	 * Determine the handles owner.  Note that an orphaned handle may no
1118*0Sstevel@tonic-gate 	 * longer contain its originating owner.
1119*0Sstevel@tonic-gate 	 */
1120*0Sstevel@tonic-gate 	if (gh.gh_owner) {
1121*0Sstevel@tonic-gate 		if ((str = Rtmap_Name((uintptr_t)gh.gh_owner)) == 0)
1122*0Sstevel@tonic-gate 			return (DCMD_ERR);
1123*0Sstevel@tonic-gate 	} else
1124*0Sstevel@tonic-gate 		str = (char *)MSG_ORIG(MSG_STR_ORPHANED);
1125*0Sstevel@tonic-gate 
1126*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE2), str);
1127*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE3), gh.gh_flags, gh.gh_flags,
1128*0Sstevel@tonic-gate 	    grhflags_bits);
1129*0Sstevel@tonic-gate 
1130*0Sstevel@tonic-gate 	if (gh.gh_depends == 0) {
1131*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE4), gh.gh_refcnt);
1132*0Sstevel@tonic-gate 		return (DCMD_OK);
1133*0Sstevel@tonic-gate 	}
1134*0Sstevel@tonic-gate 
1135*0Sstevel@tonic-gate 	addr = (uintptr_t)gh.gh_depends;
1136*0Sstevel@tonic-gate 	if (mdb_vread(&al, sizeof (Alist), addr) == -1) {
1137*0Sstevel@tonic-gate 	    mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr);
1138*0Sstevel@tonic-gate 	    return (DCMD_ERR);
1139*0Sstevel@tonic-gate 	}
1140*0Sstevel@tonic-gate 
1141*0Sstevel@tonic-gate 	ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size;
1142*0Sstevel@tonic-gate 	tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size;
1143*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE5), gh.gh_refcnt, addr, ucnt, tcnt);
1144*0Sstevel@tonic-gate 
1145*0Sstevel@tonic-gate 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0))
1146*0Sstevel@tonic-gate 		return (DCMD_OK);
1147*0Sstevel@tonic-gate 
1148*0Sstevel@tonic-gate 	mdb_inc_indent(4);
1149*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1150*0Sstevel@tonic-gate 
1151*0Sstevel@tonic-gate 	/*
1152*0Sstevel@tonic-gate 	 * Under verbose mode print the name of each dependency.  An Alist can
1153*0Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
1154*0Sstevel@tonic-gate 	 */
1155*0Sstevel@tonic-gate 	listcalc = (uintptr_t)(&(al.al_data[0]));
1156*0Sstevel@tonic-gate 	listcalc -= (uintptr_t)(&al);
1157*0Sstevel@tonic-gate 	listcalc += addr;
1158*0Sstevel@tonic-gate 	if (dcmd_GrpDesc(listcalc, flags, argc, argv) == DCMD_ERR) {
1159*0Sstevel@tonic-gate 		mdb_dec_indent(4);
1160*0Sstevel@tonic-gate 		return (DCMD_ERR);
1161*0Sstevel@tonic-gate 	}
1162*0Sstevel@tonic-gate 
1163*0Sstevel@tonic-gate 	listnext = (uintptr_t)(al.al_next + addr);
1164*0Sstevel@tonic-gate 	for (listcalc += al.al_size; listcalc < listnext;
1165*0Sstevel@tonic-gate 	    listcalc += al.al_size) {
1166*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1167*0Sstevel@tonic-gate 		if (dcmd_GrpDesc(listcalc, flags, argc, argv) == DCMD_ERR) {
1168*0Sstevel@tonic-gate 			mdb_dec_indent(4);
1169*0Sstevel@tonic-gate 			return (DCMD_ERR);
1170*0Sstevel@tonic-gate 		}
1171*0Sstevel@tonic-gate 	}
1172*0Sstevel@tonic-gate 
1173*0Sstevel@tonic-gate 	mdb_dec_indent(4);
1174*0Sstevel@tonic-gate 	return (DCMD_OK);
1175*0Sstevel@tonic-gate }
1176*0Sstevel@tonic-gate 
1177*0Sstevel@tonic-gate static void
1178*0Sstevel@tonic-gate dcmd_Handles_help(void)
1179*0Sstevel@tonic-gate {
1180*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_HANDLES_HELP));
1181*0Sstevel@tonic-gate }
1182*0Sstevel@tonic-gate 
1183*0Sstevel@tonic-gate static int
1184*0Sstevel@tonic-gate dcmd_Handles(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1185*0Sstevel@tonic-gate {
1186*0Sstevel@tonic-gate 	Rt_map		rtmap;
1187*0Sstevel@tonic-gate 	char		*str;
1188*0Sstevel@tonic-gate 	uint_t		flg = 0;
1189*0Sstevel@tonic-gate 	Alist		al;
1190*0Sstevel@tonic-gate 	uintptr_t	listcalc, listnext;
1191*0Sstevel@tonic-gate 	size_t		ucnt, tcnt;
1192*0Sstevel@tonic-gate 	Grp_hdl *	ghp;
1193*0Sstevel@tonic-gate 
1194*0Sstevel@tonic-gate 	/*
1195*0Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
1196*0Sstevel@tonic-gate 	 */
1197*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
1198*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_HANDLES_STR));
1199*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1200*0Sstevel@tonic-gate 	}
1201*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
1202*0Sstevel@tonic-gate 	    &flg, NULL) != argc)
1203*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1204*0Sstevel@tonic-gate 
1205*0Sstevel@tonic-gate 	/*
1206*0Sstevel@tonic-gate 	 * Read the Rt_map contents.
1207*0Sstevel@tonic-gate 	 */
1208*0Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
1209*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
1210*0Sstevel@tonic-gate 		return (DCMD_ERR);
1211*0Sstevel@tonic-gate 	}
1212*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
1213*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
1214*0Sstevel@tonic-gate 		return (DCMD_ERR);
1215*0Sstevel@tonic-gate 
1216*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_HANDLES_LINE1), str);
1217*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1218*0Sstevel@tonic-gate 
1219*0Sstevel@tonic-gate 	if (HANDLES(&rtmap) == 0)
1220*0Sstevel@tonic-gate 		return (DCMD_OK);
1221*0Sstevel@tonic-gate 
1222*0Sstevel@tonic-gate 	addr = (uintptr_t)HANDLES(&rtmap);
1223*0Sstevel@tonic-gate 	if (mdb_vread(&al, sizeof (Alist), addr) == -1) {
1224*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr);
1225*0Sstevel@tonic-gate 		return (DCMD_ERR);
1226*0Sstevel@tonic-gate 	}
1227*0Sstevel@tonic-gate 
1228*0Sstevel@tonic-gate 	ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size;
1229*0Sstevel@tonic-gate 	tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size;
1230*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_HANDLES_LINE2), addr, ucnt, tcnt);
1231*0Sstevel@tonic-gate 
1232*0Sstevel@tonic-gate 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0))
1233*0Sstevel@tonic-gate 		return (DCMD_OK);
1234*0Sstevel@tonic-gate 
1235*0Sstevel@tonic-gate 	/*
1236*0Sstevel@tonic-gate 	 * Under verbose mode print the name of each dependency.  An Alist can
1237*0Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
1238*0Sstevel@tonic-gate 	 */
1239*0Sstevel@tonic-gate 	listcalc = (uintptr_t)(&(al.al_data[0]));
1240*0Sstevel@tonic-gate 	listcalc -= (uintptr_t)(&al);
1241*0Sstevel@tonic-gate 	listcalc += addr;
1242*0Sstevel@tonic-gate 	if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) {
1243*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
1244*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_GRPHDL_STR), listcalc);
1245*0Sstevel@tonic-gate 		return (DCMD_ERR);
1246*0Sstevel@tonic-gate 	}
1247*0Sstevel@tonic-gate 
1248*0Sstevel@tonic-gate 	mdb_inc_indent(4);
1249*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1250*0Sstevel@tonic-gate 
1251*0Sstevel@tonic-gate 	if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, argv) == DCMD_ERR) {
1252*0Sstevel@tonic-gate 		mdb_dec_indent(4);
1253*0Sstevel@tonic-gate 		return (DCMD_ERR);
1254*0Sstevel@tonic-gate 	}
1255*0Sstevel@tonic-gate 
1256*0Sstevel@tonic-gate 	listnext = (uintptr_t)(al.al_next + addr);
1257*0Sstevel@tonic-gate 	for (listcalc += al.al_size; listcalc < listnext;
1258*0Sstevel@tonic-gate 	    listcalc += al.al_size) {
1259*0Sstevel@tonic-gate 		if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) {
1260*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
1261*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_GRPHDL_STR), listcalc);
1262*0Sstevel@tonic-gate 			return (DCMD_ERR);
1263*0Sstevel@tonic-gate 		}
1264*0Sstevel@tonic-gate 
1265*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1266*0Sstevel@tonic-gate 		if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc,
1267*0Sstevel@tonic-gate 		    argv) == DCMD_ERR) {
1268*0Sstevel@tonic-gate 			mdb_dec_indent(4);
1269*0Sstevel@tonic-gate 			return (DCMD_ERR);
1270*0Sstevel@tonic-gate 		}
1271*0Sstevel@tonic-gate 	}
1272*0Sstevel@tonic-gate 	mdb_dec_indent(4);
1273*0Sstevel@tonic-gate 	return (DCMD_OK);
1274*0Sstevel@tonic-gate }
1275*0Sstevel@tonic-gate 
1276*0Sstevel@tonic-gate static void
1277*0Sstevel@tonic-gate dcmd_Groups_help(void)
1278*0Sstevel@tonic-gate {
1279*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GROUPS_HELP));
1280*0Sstevel@tonic-gate }
1281*0Sstevel@tonic-gate 
1282*0Sstevel@tonic-gate 
1283*0Sstevel@tonic-gate static int
1284*0Sstevel@tonic-gate dcmd_Groups(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1285*0Sstevel@tonic-gate {
1286*0Sstevel@tonic-gate 	Rt_map		rtmap;
1287*0Sstevel@tonic-gate 	char		*str;
1288*0Sstevel@tonic-gate 	Alist		al;
1289*0Sstevel@tonic-gate 	uint_t		flg = 0;
1290*0Sstevel@tonic-gate 	uintptr_t	listcalc, listnext;
1291*0Sstevel@tonic-gate 	size_t		ucnt, tcnt;
1292*0Sstevel@tonic-gate 	Grp_hdl *	ghp;
1293*0Sstevel@tonic-gate 
1294*0Sstevel@tonic-gate 	/*
1295*0Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
1296*0Sstevel@tonic-gate 	 */
1297*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
1298*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GROUPS_STR));
1299*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1300*0Sstevel@tonic-gate 	}
1301*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
1302*0Sstevel@tonic-gate 	    &flg, NULL) != argc)
1303*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1304*0Sstevel@tonic-gate 
1305*0Sstevel@tonic-gate 	/*
1306*0Sstevel@tonic-gate 	 * Read the Rt_map contents.
1307*0Sstevel@tonic-gate 	 */
1308*0Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
1309*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
1310*0Sstevel@tonic-gate 		return (DCMD_ERR);
1311*0Sstevel@tonic-gate 	}
1312*0Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
1313*0Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
1314*0Sstevel@tonic-gate 		return (DCMD_ERR);
1315*0Sstevel@tonic-gate 
1316*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GROUPS_LINE1), str);
1317*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1318*0Sstevel@tonic-gate 
1319*0Sstevel@tonic-gate 	if (GROUPS(&rtmap) == 0)
1320*0Sstevel@tonic-gate 		return (DCMD_OK);
1321*0Sstevel@tonic-gate 
1322*0Sstevel@tonic-gate 	addr = (uintptr_t)GROUPS(&rtmap);
1323*0Sstevel@tonic-gate 	if (mdb_vread(&al, sizeof (Alist), addr) == -1) {
1324*0Sstevel@tonic-gate 	    mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr);
1325*0Sstevel@tonic-gate 	    return (DCMD_ERR);
1326*0Sstevel@tonic-gate 	}
1327*0Sstevel@tonic-gate 
1328*0Sstevel@tonic-gate 	ucnt = (al.al_next - sizeof (Alist) + sizeof (void *)) / al.al_size;
1329*0Sstevel@tonic-gate 	tcnt = (al.al_end - sizeof (Alist) + sizeof (void *)) / al.al_size;
1330*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GROUPS_LINE2), addr, ucnt, tcnt);
1331*0Sstevel@tonic-gate 
1332*0Sstevel@tonic-gate 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (ucnt == 0))
1333*0Sstevel@tonic-gate 		return (DCMD_OK);
1334*0Sstevel@tonic-gate 
1335*0Sstevel@tonic-gate 	/*
1336*0Sstevel@tonic-gate 	 * Under verbose mode print the name of each dependency.  An Alist can
1337*0Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
1338*0Sstevel@tonic-gate 	 */
1339*0Sstevel@tonic-gate 	listcalc = (uintptr_t)(&(al.al_data[0]));
1340*0Sstevel@tonic-gate 	listcalc -= (uintptr_t)(&al);
1341*0Sstevel@tonic-gate 	listcalc += addr;
1342*0Sstevel@tonic-gate 	if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) {
1343*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
1344*0Sstevel@tonic-gate 		    MSG_ORIG(MSG_GRPHDL_STR), listcalc);
1345*0Sstevel@tonic-gate 		return (DCMD_ERR);
1346*0Sstevel@tonic-gate 	}
1347*0Sstevel@tonic-gate 
1348*0Sstevel@tonic-gate 	mdb_inc_indent(4);
1349*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1350*0Sstevel@tonic-gate 
1351*0Sstevel@tonic-gate 	if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, argv) == DCMD_ERR) {
1352*0Sstevel@tonic-gate 		mdb_dec_indent(4);
1353*0Sstevel@tonic-gate 		return (DCMD_ERR);
1354*0Sstevel@tonic-gate 	}
1355*0Sstevel@tonic-gate 
1356*0Sstevel@tonic-gate 	listnext = (uintptr_t)(al.al_next + addr);
1357*0Sstevel@tonic-gate 	for (listcalc += al.al_size; listcalc < listnext;
1358*0Sstevel@tonic-gate 	    listcalc += al.al_size) {
1359*0Sstevel@tonic-gate 		if (mdb_vread(&ghp, sizeof (Grp_hdl *), listcalc) == -1) {
1360*0Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
1361*0Sstevel@tonic-gate 			    MSG_ORIG(MSG_GRPHDL_STR), listcalc);
1362*0Sstevel@tonic-gate 			return (DCMD_ERR);
1363*0Sstevel@tonic-gate 		}
1364*0Sstevel@tonic-gate 
1365*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
1366*0Sstevel@tonic-gate 		if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc,
1367*0Sstevel@tonic-gate 		    argv) == DCMD_ERR) {
1368*0Sstevel@tonic-gate 			mdb_dec_indent(4);
1369*0Sstevel@tonic-gate 			return (DCMD_ERR);
1370*0Sstevel@tonic-gate 		}
1371*0Sstevel@tonic-gate 	}
1372*0Sstevel@tonic-gate 	mdb_dec_indent(4);
1373*0Sstevel@tonic-gate 	return (DCMD_OK);
1374*0Sstevel@tonic-gate }
1375*0Sstevel@tonic-gate static void
1376*0Sstevel@tonic-gate dcmd_ElfDyn_help(void)
1377*0Sstevel@tonic-gate {
1378*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_ELFDYN_HELP));
1379*0Sstevel@tonic-gate }
1380*0Sstevel@tonic-gate 
1381*0Sstevel@tonic-gate static int
1382*0Sstevel@tonic-gate /* ARGSUSED2 */
1383*0Sstevel@tonic-gate dcmd_ElfDyn(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1384*0Sstevel@tonic-gate {
1385*0Sstevel@tonic-gate 	Dyn		dyn;
1386*0Sstevel@tonic-gate 	const char	*dynstr;
1387*0Sstevel@tonic-gate 
1388*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
1389*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1390*0Sstevel@tonic-gate 	if (mdb_vread(&dyn, sizeof (dyn), addr) == -1) {
1391*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_ELFDYN_STR),
1392*0Sstevel@tonic-gate 			addr);
1393*0Sstevel@tonic-gate 		return (DCMD_ERR);
1394*0Sstevel@tonic-gate 	}
1395*0Sstevel@tonic-gate 
1396*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_ELFDYN_TITLE), addr);
1397*0Sstevel@tonic-gate 	dynstr = conv_dyntag_str(dyn.d_tag, M_MACH);
1398*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_ELFDYN_LINE1), addr, dynstr, dyn.d_un.d_ptr);
1399*0Sstevel@tonic-gate 
1400*0Sstevel@tonic-gate 	mdb_set_dot(addr + sizeof (Dyn));
1401*0Sstevel@tonic-gate 
1402*0Sstevel@tonic-gate 	return (DCMD_OK);
1403*0Sstevel@tonic-gate }
1404*0Sstevel@tonic-gate 
1405*0Sstevel@tonic-gate static void
1406*0Sstevel@tonic-gate dcmd_ElfEhdr_help(void)
1407*0Sstevel@tonic-gate {
1408*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_HELP));
1409*0Sstevel@tonic-gate }
1410*0Sstevel@tonic-gate 
1411*0Sstevel@tonic-gate static int
1412*0Sstevel@tonic-gate /* ARGSUSED2 */
1413*0Sstevel@tonic-gate dcmd_ElfEhdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1414*0Sstevel@tonic-gate {
1415*0Sstevel@tonic-gate 	Ehdr		ehdr;
1416*0Sstevel@tonic-gate 	Byte		*byte;
1417*0Sstevel@tonic-gate 	const char	*flgs;
1418*0Sstevel@tonic-gate 
1419*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
1420*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1421*0Sstevel@tonic-gate 
1422*0Sstevel@tonic-gate 	if (mdb_vread(&ehdr, sizeof (ehdr), addr) == -1) {
1423*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_EHDR_STR),
1424*0Sstevel@tonic-gate 			addr);
1425*0Sstevel@tonic-gate 		return (DCMD_ERR);
1426*0Sstevel@tonic-gate 	}
1427*0Sstevel@tonic-gate 
1428*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_TITLE), addr);
1429*0Sstevel@tonic-gate 	byte = &ehdr.e_ident[0];
1430*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE1), byte[EI_MAG0],
1431*0Sstevel@tonic-gate 	    (byte[EI_MAG1] ? byte[EI_MAG1] : '0'),
1432*0Sstevel@tonic-gate 	    (byte[EI_MAG2] ? byte[EI_MAG2] : '0'),
1433*0Sstevel@tonic-gate 	    (byte[EI_MAG3] ? byte[EI_MAG3] : '0'));
1434*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE2),
1435*0Sstevel@tonic-gate 	    conv_eclass_str(ehdr.e_ident[EI_CLASS]),
1436*0Sstevel@tonic-gate 	    conv_edata_str(ehdr.e_ident[EI_DATA]));
1437*0Sstevel@tonic-gate 
1438*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE3),
1439*0Sstevel@tonic-gate 	    conv_emach_str(ehdr.e_machine), conv_ever_str(ehdr.e_version));
1440*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE4), conv_etype_str(ehdr.e_type));
1441*0Sstevel@tonic-gate 
1442*0Sstevel@tonic-gate 	/*
1443*0Sstevel@tonic-gate 	 * Line up the flags differently depending on wether we
1444*0Sstevel@tonic-gate 	 * received a numeric (e.g. "0x200") or text represent-
1445*0Sstevel@tonic-gate 	 * ation (e.g. "[ EF_SPARC_SUN_US1 ]").
1446*0Sstevel@tonic-gate 	 */
1447*0Sstevel@tonic-gate 	flgs = conv_eflags_str(ehdr.e_machine, ehdr.e_flags);
1448*0Sstevel@tonic-gate 	if (flgs[0] == '[')
1449*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_EHDR_LINE5), flgs);
1450*0Sstevel@tonic-gate 	else
1451*0Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_EHDR_LINE6), flgs);
1452*0Sstevel@tonic-gate 
1453*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE7), ehdr.e_entry, ehdr.e_ehsize,
1454*0Sstevel@tonic-gate 	    ehdr.e_shstrndx);
1455*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE8), ehdr.e_shoff, ehdr.e_shentsize,
1456*0Sstevel@tonic-gate 	    ehdr.e_shnum);
1457*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE9), ehdr.e_phoff, ehdr.e_phentsize,
1458*0Sstevel@tonic-gate 	    ehdr.e_phnum);
1459*0Sstevel@tonic-gate 
1460*0Sstevel@tonic-gate 	mdb_set_dot(addr + sizeof (Ehdr));
1461*0Sstevel@tonic-gate 
1462*0Sstevel@tonic-gate 	return (DCMD_OK);
1463*0Sstevel@tonic-gate }
1464*0Sstevel@tonic-gate 
1465*0Sstevel@tonic-gate static void
1466*0Sstevel@tonic-gate dcmd_ElfPhdr_help(void)
1467*0Sstevel@tonic-gate {
1468*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_HELP));
1469*0Sstevel@tonic-gate }
1470*0Sstevel@tonic-gate 
1471*0Sstevel@tonic-gate static int
1472*0Sstevel@tonic-gate /* ARGSUSED2 */
1473*0Sstevel@tonic-gate dcmd_ElfPhdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1474*0Sstevel@tonic-gate {
1475*0Sstevel@tonic-gate 	Phdr	phdr;
1476*0Sstevel@tonic-gate 
1477*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
1478*0Sstevel@tonic-gate 		return (DCMD_USAGE);
1479*0Sstevel@tonic-gate 
1480*0Sstevel@tonic-gate 	if (mdb_vread(&phdr, sizeof (phdr), addr) == -1) {
1481*0Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_EPHDR_STR),
1482*0Sstevel@tonic-gate 			addr);
1483*0Sstevel@tonic-gate 		return (DCMD_ERR);
1484*0Sstevel@tonic-gate 	}
1485*0Sstevel@tonic-gate 
1486*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_TITLE), addr);
1487*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE1), phdr.p_vaddr,
1488*0Sstevel@tonic-gate 	    conv_phdrflg_str(phdr.p_flags));
1489*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE2), phdr.p_paddr,
1490*0Sstevel@tonic-gate 	    conv_phdrtyp_str(M_MACH, phdr.p_type));
1491*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE3), phdr.p_filesz,
1492*0Sstevel@tonic-gate 	    phdr.p_memsz);
1493*0Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE4), phdr.p_offset,
1494*0Sstevel@tonic-gate 	    phdr.p_align);
1495*0Sstevel@tonic-gate 
1496*0Sstevel@tonic-gate 	mdb_set_dot(addr + sizeof (Phdr));
1497*0Sstevel@tonic-gate 
1498*0Sstevel@tonic-gate 	return (DCMD_OK);
1499*0Sstevel@tonic-gate }
1500*0Sstevel@tonic-gate 
1501*0Sstevel@tonic-gate 
1502*0Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
1503*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_BND_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1504*0Sstevel@tonic-gate 		MSG_ORIG(MSG_BND_DCD),
1505*0Sstevel@tonic-gate 		dcmd_Bind, dcmd_Bind_help},
1506*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_DEPENDS_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1507*0Sstevel@tonic-gate 		MSG_ORIG(MSG_DEPENDS_DCD),
1508*0Sstevel@tonic-gate 		dcmd_Depends, dcmd_Depends_help},
1509*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_CALLERS_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1510*0Sstevel@tonic-gate 		MSG_ORIG(MSG_CALLERS_DCD),
1511*0Sstevel@tonic-gate 		dcmd_Callers, dcmd_Callers_help},
1512*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GRPHDL_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1513*0Sstevel@tonic-gate 		MSG_ORIG(MSG_GRPHDL_DCD),
1514*0Sstevel@tonic-gate 		dcmd_GrpHdl, dcmd_GrpHdl_help},
1515*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GRPDESC_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1516*0Sstevel@tonic-gate 		MSG_ORIG(MSG_GRPDESC_DCD),
1517*0Sstevel@tonic-gate 		dcmd_GrpDesc, dcmd_GrpDesc_help},
1518*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_HANDLES_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1519*0Sstevel@tonic-gate 		MSG_ORIG(MSG_HANDLES_DCD),
1520*0Sstevel@tonic-gate 		dcmd_Handles, dcmd_Handles_help},
1521*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GROUPS_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1522*0Sstevel@tonic-gate 		MSG_ORIG(MSG_GROUPS_DCD),
1523*0Sstevel@tonic-gate 		dcmd_Groups, dcmd_Groups_help},
1524*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_ELFDYN_STR), MSG_ORIG(MSG_USG_ADDREQ),
1525*0Sstevel@tonic-gate 		MSG_ORIG(MSG_ELFDYN_DCD),
1526*0Sstevel@tonic-gate 		dcmd_ElfDyn, dcmd_ElfDyn_help},
1527*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_EHDR_STR), MSG_ORIG(MSG_USG_ADDREQ),
1528*0Sstevel@tonic-gate 		MSG_ORIG(MSG_EHDR_DCD),
1529*0Sstevel@tonic-gate 		dcmd_ElfEhdr, dcmd_ElfEhdr_help},
1530*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_EPHDR_STR), MSG_ORIG(MSG_USG_ADDREQ),
1531*0Sstevel@tonic-gate 		MSG_ORIG(MSG_EPHDR_DCD),
1532*0Sstevel@tonic-gate 		dcmd_ElfPhdr, dcmd_ElfPhdr_help},
1533*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LIST_STR), MSG_ORIG(MSG_USG_ADDREQ),
1534*0Sstevel@tonic-gate 		MSG_ORIG(MSG_LIST_DCD),
1535*0Sstevel@tonic-gate 		dcmd_List, dcmd_List_help},
1536*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMLIST_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
1537*0Sstevel@tonic-gate 		MSG_ORIG(MSG_LMLIST_DCD),
1538*0Sstevel@tonic-gate 		dcmd_Lm_list, dcmd_Lm_list_help},
1539*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_RTMAPS_STR), MSG_ORIG(MSG_USG_ADDOPT_V),
1540*0Sstevel@tonic-gate 		MSG_ORIG(MSG_RTMAPS_DCD),
1541*0Sstevel@tonic-gate 		dcmd_Rtmaps, dcmd_Rtmaps_help},
1542*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_RTMAP_STR), MSG_ORIG(MSG_USG_ADDREQ),
1543*0Sstevel@tonic-gate 		MSG_ORIG(MSG_RTMAP_DCD),
1544*0Sstevel@tonic-gate 		dcmd_rtmap, dcmd_rtmap_help},
1545*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_SETENV_STR), MSG_ORIG(MSG_USG_SETENV),
1546*0Sstevel@tonic-gate 		MSG_ORIG(MSG_SETENV_DCD),
1547*0Sstevel@tonic-gate 		dcmd_Setenv, dcmd_Setenv_help},
1548*0Sstevel@tonic-gate 	{ NULL }
1549*0Sstevel@tonic-gate };
1550*0Sstevel@tonic-gate 
1551*0Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
1552*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_RTMAPS_STR), MSG_ORIG(MSG_WWD_RTMAP),
1553*0Sstevel@tonic-gate 		walk_rtmap_init, walk_rtmap_step, NULL, NULL },
1554*0Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LIST_STR), MSG_ORIG(MSG_WWD_LIST),
1555*0Sstevel@tonic-gate 		walk_List_init, walk_List_step, NULL, NULL },
1556*0Sstevel@tonic-gate 	{ NULL }
1557*0Sstevel@tonic-gate };
1558*0Sstevel@tonic-gate 
1559*0Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
1560*0Sstevel@tonic-gate 	MDB_API_VERSION, dcmds, walkers
1561*0Sstevel@tonic-gate };
1562*0Sstevel@tonic-gate 
1563*0Sstevel@tonic-gate const	mdb_modinfo_t *
1564*0Sstevel@tonic-gate _mdb_init(void)
1565*0Sstevel@tonic-gate {
1566*0Sstevel@tonic-gate 	return (&modinfo);
1567*0Sstevel@tonic-gate }
1568