xref: /onnv-gate/usr/src/cmd/sgs/rtld/mdbmod/common/rtld.c (revision 12877:69001e4756ae)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
23*12877SRod.Evans@Sun.COM  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <msg.h>
270Sstevel@tonic-gate #include <_rtld.h>
280Sstevel@tonic-gate #include <conv.h>
290Sstevel@tonic-gate #include <sys/mdb_modapi.h>
300Sstevel@tonic-gate #include <sys/param.h>
310Sstevel@tonic-gate #include <stdlib.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate  * Data structure for walkers.
350Sstevel@tonic-gate  */
360Sstevel@tonic-gate typedef struct {
370Sstevel@tonic-gate 	uint_t	w_flags;
380Sstevel@tonic-gate } W_desc;
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate  * Flags values for dcmds
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	RTLD_FLG_VERBOSE	0x0001		/* verbose output */
450Sstevel@tonic-gate 
460Sstevel@tonic-gate static const mdb_bitmask_t rtflags_bits[] = {
470Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ISMAIN), FLG_RT_ISMAIN, FLG_RT_ISMAIN},
480Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_IMGALLOC), FLG_RT_IMGALLOC, FLG_RT_IMGALLOC},
490Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_RELOCED), FLG_RT_RELOCED, FLG_RT_RELOCED},
500Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_SETGROUP), FLG_RT_SETGROUP, FLG_RT_SETGROUP},
5111827SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FLG_CAP), FLG_RT_CAP, FLG_RT_CAP},
520Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_OBJECT), FLG_RT_OBJECT, FLG_RT_OBJECT},
539340SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FLG_NEWLOAD), FLG_RT_NEWLOAD, FLG_RT_NEWLOAD},
540Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_NODUMP), FLG_RT_NODUMP, FLG_RT_NODUMP},
550Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_DELETE), FLG_RT_DELETE, FLG_RT_DELETE},
560Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ANALYZED), FLG_RT_ANALYZED, FLG_RT_ANALYZED},
570Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITDONE), FLG_RT_INITDONE, FLG_RT_INITDONE},
580Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_TRANS), FLG_RT_TRANS, FLG_RT_TRANS},
590Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_FIXED), FLG_RT_FIXED, FLG_RT_FIXED},
600Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_PRELOAD), FLG_RT_PRELOAD, FLG_RT_PRELOAD},
610Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ALTER), FLG_RT_ALTER, FLG_RT_ALTER},
620Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_LOADFLTR), FLG_RT_LOADFLTR, FLG_RT_LOADFLTR},
630Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_AUDIT), FLG_RT_AUDIT, FLG_RT_AUDIT},
640Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_MODESET), FLG_RT_MODESET, FLG_RT_MODESET},
650Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_ANALZING), FLG_RT_ANALZING, FLG_RT_ANALZING},
660Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITFRST), FLG_RT_INITFRST, FLG_RT_INITFRST},
670Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_NOOPEN), FLG_RT_NOOPEN, FLG_RT_NOOPEN},
680Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_FINICLCT), FLG_RT_FINICLCT, FLG_RT_FINICLCT},
690Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITCALL), FLG_RT_INITCALL, FLG_RT_INITCALL},
703466Srie 	{ MSG_ORIG(MSG_FLG_OBJINTPO), FLG_RT_OBJINTPO, FLG_RT_OBJINTPO},
713466Srie 	{ MSG_ORIG(MSG_FLG_SYMINTPO), FLG_RT_SYMINTPO, FLG_RT_SYMINTPO},
720Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_MOVE), FLG_RT_MOVE, FLG_RT_MOVE},
739577SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FLG_RELOCING), FLG_RT_RELOCING, FLG_RT_RELOCING},
740Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_REGSYMS), FLG_RT_REGSYMS, FLG_RT_REGSYMS},
750Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FLG_INITCLCT), FLG_RT_INITCLCT, FLG_RT_INITCLCT},
769577SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FLG_PUBHDL), FLG_RT_PUBHDL, FLG_RT_PUBHDL},
779577SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FLG_PRIHDL), FLG_RT_PRIHDL, FLG_RT_PRIHDL},
780Sstevel@tonic-gate 	{ NULL, 0, 0}
790Sstevel@tonic-gate };
800Sstevel@tonic-gate 
810Sstevel@tonic-gate static const mdb_bitmask_t rtflags1_bits[] = {
820Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_COPYTOOK), FL1_RT_COPYTOOK, FL1_RT_COPYTOOK},
8311827SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FL1_ALTCHECK), FL1_RT_ALTCHECK, FL1_RT_ALTCHECK},
8411827SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FL1_ALTCAP), FL1_RT_ALTCAP, FL1_RT_ALTCAP},
850Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_CONFSET), FL1_RT_CONFSET, FL1_RT_CONFSET },
860Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_NODEFLIB), FL1_RT_NODEFLIB, FL1_RT_NODEFLIB },
870Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_ENDFILTE), FL1_RT_ENDFILTE, FL1_RT_ENDFILTE },
880Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_DISPREL), FL1_RT_DISPREL, FL1_RT_DISPREL },
898598SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_FL1_DTFLAGS), FL1_RT_DTFLAGS, FL1_RT_DTFLAGS},
900Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_LDDSTUB), FL1_RT_LDDSTUB, FL1_RT_LDDSTUB},
910Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_NOINIFIN), FL1_RT_NOINIFIN, FL1_RT_NOINIFIN },
920Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_USED), FL1_RT_USED, FL1_RT_USED },
930Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_SYMBOLIC), FL1_RT_SYMBOLIC, FL1_RT_SYMBOLIC },
940Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_OBJSFLTR), FL1_RT_OBJSFLTR, FL1_RT_OBJSFLTR },
950Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_OBJAFLTR), FL1_RT_OBJAFLTR, FL1_RT_OBJAFLTR },
960Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_SYMSFLTR), FL1_RT_SYMSFLTR, FL1_RT_SYMSFLTR },
970Sstevel@tonic-gate 	{ MSG_ORIG(MSG_FL1_SYMAFLTR), FL1_RT_SYMAFLTR, FL1_RT_SYMAFLTR },
983466Srie 	{ MSG_ORIG(MSG_FL1_TLSADD), FL1_RT_TLSADD, FL1_RT_TLSADD },
993466Srie 	{ MSG_ORIG(MSG_FL1_TLSSTAT), FL1_RT_TLSSTAT, FL1_RT_TLSSTAT },
1003466Srie 	{ MSG_ORIG(MSG_FL1_DIRECT), FL1_RT_DIRECT, FL1_RT_DIRECT},
1014679Srie 	{ MSG_ORIG(MSG_FL1_GLOBAUD), FL1_RT_GLOBAUD, FL1_RT_GLOBAUD},
1028598SRod.Evans@Sun.COM 	{ NULL, 0, 0}
1038598SRod.Evans@Sun.COM };
1040Sstevel@tonic-gate 
1058598SRod.Evans@Sun.COM static const mdb_bitmask_t rtaflags_bits[] = {
1060Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PREINIT), LML_TFLG_AUD_PREINIT,
1070Sstevel@tonic-gate 	    LML_TFLG_AUD_PREINIT },
1080Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJSEARCH), LML_TFLG_AUD_OBJSEARCH,
1090Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJSEARCH },
1100Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJOPEN), LML_TFLG_AUD_OBJOPEN,
1110Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJOPEN },
1120Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJFILTER), LML_TFLG_AUD_OBJFILTER,
1130Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJFILTER },
1140Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJCLOSE), LML_TFLG_AUD_OBJCLOSE,
1150Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJCLOSE },
1160Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_SYMBIND), LML_TFLG_AUD_SYMBIND,
1170Sstevel@tonic-gate 	    LML_TFLG_AUD_SYMBIND },
1180Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTENTER), LML_TFLG_AUD_PLTENTER,
1190Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTENTER },
1200Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTEXIT), LML_TFLG_AUD_PLTEXIT,
1210Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTEXIT },
1220Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_ACTIVITY), LML_TFLG_AUD_ACTIVITY,
1230Sstevel@tonic-gate 	    LML_TFLG_AUD_ACTIVITY },
1240Sstevel@tonic-gate 	{ NULL, 0, 0}
1250Sstevel@tonic-gate };
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate static const mdb_bitmask_t rtmode_bits[] = {
1280Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_LAZY), RTLD_LAZY, RTLD_LAZY },
1290Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_NOW), RTLD_NOW, RTLD_NOW },
1300Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_NOLOAD), RTLD_NOLOAD, RTLD_NOLOAD },
1310Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_GLOBAL), RTLD_GLOBAL, RTLD_GLOBAL },
1320Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_PARENT), RTLD_PARENT, RTLD_PARENT },
1330Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_GROUP), RTLD_GROUP, RTLD_GROUP },
1340Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_WORLD), RTLD_WORLD, RTLD_WORLD },
1350Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_NODELETE), RTLD_NODELETE, RTLD_NODELETE },
1360Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_FIRST), RTLD_FIRST, RTLD_FIRST },
1370Sstevel@tonic-gate 	{ MSG_ORIG(MSG_MODE_CONFGEN), RTLD_CONFGEN, RTLD_CONFGEN },
1380Sstevel@tonic-gate 	{ NULL, 0, 0}
1390Sstevel@tonic-gate };
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate static const mdb_bitmask_t bndflags_bits[] = {
1420Sstevel@tonic-gate 	{ MSG_ORIG(MSG_BFL_NEEDED), BND_NEEDED, BND_NEEDED },
1430Sstevel@tonic-gate 	{ MSG_ORIG(MSG_BFL_REFER), BND_REFER, BND_REFER },
144280Srie 	{ MSG_ORIG(MSG_BFL_FILTER), BND_FILTER, BND_FILTER },
1450Sstevel@tonic-gate 	{ NULL, 0, 0}
1460Sstevel@tonic-gate };
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate static const mdb_bitmask_t grhflags_bits[] = {
1499577SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_GPH_PUBLIC), GPH_PUBLIC, GPH_PUBLIC },
1509577SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_GPH_PRIVATE), GPH_PRIVATE, GPH_PRIVATE },
1510Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_ZERO), GPH_ZERO, GPH_ZERO },
1520Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_LDSO), GPH_LDSO, GPH_LDSO },
1530Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_FIRST), GPH_FIRST, GPH_FIRST },
1540Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_FILTEE), GPH_FILTEE, GPH_FILTEE },
1550Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPH_INITIAL), GPH_INITIAL, GPH_INITIAL },
1560Sstevel@tonic-gate 	{ NULL, 0, 0}
1570Sstevel@tonic-gate };
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate static const mdb_bitmask_t grdflags_bits[] = {
1604699Srie 	{ MSG_ORIG(MSG_GPD_DLSYM), GPD_DLSYM, GPD_DLSYM },
1614699Srie 	{ MSG_ORIG(MSG_GPD_RELOC), GPD_RELOC, GPD_RELOC },
1620Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_ADDEPS), GPD_ADDEPS, GPD_ADDEPS },
1630Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_PARENT), GPD_PARENT, GPD_PARENT },
1640Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_FILTER), GPD_FILTER, GPD_FILTER },
1650Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GPD_REMOVE), GPD_REMOVE, GPD_REMOVE },
1660Sstevel@tonic-gate 	{ NULL, 0, 0}
1670Sstevel@tonic-gate };
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate static const mdb_bitmask_t lmc_bits[] = {
1700Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMC_ANALYZING), LMC_FLG_ANALYZING, LMC_FLG_ANALYZING},
1710Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMC_RELOCATING), LMC_FLG_RELOCATING, LMC_FLG_RELOCATING},
1720Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMC_REANALYZE), LMC_FLG_REANALYZE, LMC_FLG_REANALYZE},
1730Sstevel@tonic-gate 	{ NULL, 0, 0}
1740Sstevel@tonic-gate };
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate /*
1770Sstevel@tonic-gate  * Obtain a string - typically a link-map name.
1780Sstevel@tonic-gate  */
1790Sstevel@tonic-gate static char *
String(uintptr_t addr,const char * name)1800Sstevel@tonic-gate String(uintptr_t addr, const char *name)
1810Sstevel@tonic-gate {
1820Sstevel@tonic-gate 	static char	str[MAXPATHLEN];
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	if (addr) {
1850Sstevel@tonic-gate 		if (mdb_readstr(str, MAXPATHLEN, addr) == -1) {
1860Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ), name, addr);
1870Sstevel@tonic-gate 			return (0);
1880Sstevel@tonic-gate 		}
1890Sstevel@tonic-gate 		return (str);
1900Sstevel@tonic-gate 	}
1910Sstevel@tonic-gate 	return ((char *)MSG_ORIG(MSG_STR_EMPTY));
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate /*
1950Sstevel@tonic-gate  * Obtain a link-map name.
1960Sstevel@tonic-gate  */
1970Sstevel@tonic-gate static char *
Rtmap_Name(uintptr_t addr)1980Sstevel@tonic-gate Rtmap_Name(uintptr_t addr)
1990Sstevel@tonic-gate {
2000Sstevel@tonic-gate 	Rt_map	rtmap;
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 	if (addr) {
2030Sstevel@tonic-gate 		if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
2040Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
2050Sstevel@tonic-gate 			    MSG_ORIG(MSG_RTMAP_STR), addr);
2060Sstevel@tonic-gate 			return (0);
2070Sstevel@tonic-gate 		}
2080Sstevel@tonic-gate 		return (String((uintptr_t)NAME(&rtmap),
2090Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_NAME)));
2100Sstevel@tonic-gate 	}
2110Sstevel@tonic-gate 	return ((char *)MSG_ORIG(MSG_STR_EMPTY));
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate void
dcmd_Bind_help(void)2150Sstevel@tonic-gate dcmd_Bind_help(void)
2160Sstevel@tonic-gate {
2170Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_HELP));
2180Sstevel@tonic-gate }
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate static int
2210Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_Bind(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2220Sstevel@tonic-gate dcmd_Bind(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2230Sstevel@tonic-gate {
2240Sstevel@tonic-gate 	Bnd_desc	bnd;
2250Sstevel@tonic-gate 	char		*str;
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate 	/*
2280Sstevel@tonic-gate 	 * Insure we have a valid address.
2290Sstevel@tonic-gate 	 */
2300Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
2310Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_BND_STR));
2320Sstevel@tonic-gate 		return (DCMD_USAGE);
2330Sstevel@tonic-gate 	}
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate 	/*
2360Sstevel@tonic-gate 	 * Obtain the binding descriptor.
2370Sstevel@tonic-gate 	 */
2380Sstevel@tonic-gate 	if (mdb_vread(&bnd, sizeof (Bnd_desc), addr) == -1) {
2390Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_BND_STR), addr);
2400Sstevel@tonic-gate 		return (DCMD_ERR);
2410Sstevel@tonic-gate 	}
2420Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_TITLE), addr);
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	/*
2450Sstevel@tonic-gate 	 * Establish the identity of the caller.
2460Sstevel@tonic-gate 	 */
2470Sstevel@tonic-gate 	if ((str = Rtmap_Name((uintptr_t)bnd.b_caller)) == 0)
2480Sstevel@tonic-gate 		return (DCMD_ERR);
2490Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_LINE1), bnd.b_caller, str);
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * Establish the identity of the dependency.
2530Sstevel@tonic-gate 	 */
2540Sstevel@tonic-gate 	if ((str = Rtmap_Name((uintptr_t)bnd.b_depend)) == 0)
2550Sstevel@tonic-gate 		return (DCMD_ERR);
2560Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_LINE2), bnd.b_depend, str);
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 	/*
2590Sstevel@tonic-gate 	 * Display any flags.
2600Sstevel@tonic-gate 	 */
2610Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_BND_LINE3), bnd.b_flags, bnd.b_flags,
2620Sstevel@tonic-gate 	    bndflags_bits);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	return (DCMD_OK);
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate static void
dcmd_Depends_help(void)2680Sstevel@tonic-gate dcmd_Depends_help(void)
2690Sstevel@tonic-gate {
2700Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_DEPENDS_HELP));
2710Sstevel@tonic-gate }
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate static int
Depends(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv,uint_t flg,const char * msg)2740Sstevel@tonic-gate Depends(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv,
2750Sstevel@tonic-gate     uint_t flg, const char *msg)
2760Sstevel@tonic-gate {
2775892Sab196087 	APlist		apl;
2789131SRod.Evans@Sun.COM 	uintptr_t	datap, nitems;
2798598SRod.Evans@Sun.COM 	Bnd_desc	*bdp;
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	/*
2825892Sab196087 	 * Obtain the APlist and determine its number of elements and those
2830Sstevel@tonic-gate 	 * that are in use.
2840Sstevel@tonic-gate 	 */
2855892Sab196087 	if (mdb_vread(&apl, sizeof (APlist), addr) == -1) {
2865892Sab196087 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_APLIST),
2875892Sab196087 		    addr);
2884679Srie 		return (DCMD_ERR);
2890Sstevel@tonic-gate 	}
2900Sstevel@tonic-gate 
2915892Sab196087 	mdb_printf(msg, addr, (size_t)apl.apl_nitems,
2925892Sab196087 	    (size_t)apl.apl_arritems);
2930Sstevel@tonic-gate 
2945892Sab196087 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (apl.apl_nitems == 0))
2950Sstevel@tonic-gate 		return (DCMD_OK);
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate 	/*
2985892Sab196087 	 * Under verbose mode print the name of each dependency.  An APlist can
2990Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
3000Sstevel@tonic-gate 	 */
3019131SRod.Evans@Sun.COM 	datap = APLIST_OFF_DATA + (uintptr_t)addr;
3029131SRod.Evans@Sun.COM 	if (mdb_vread(&bdp, sizeof (Bnd_desc *), datap) == -1) {
3030Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
3049131SRod.Evans@Sun.COM 		    MSG_ORIG(MSG_BNDDESC_STR), datap);
3050Sstevel@tonic-gate 		return (DCMD_ERR);
3060Sstevel@tonic-gate 	}
3070Sstevel@tonic-gate 
30811053SSurya.Prakki@Sun.COM 	(void) mdb_inc_indent(4);
3090Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 	if (dcmd_Bind((uintptr_t)bdp, flags, argc, argv) == DCMD_ERR) {
31211053SSurya.Prakki@Sun.COM 		(void) mdb_dec_indent(4);
3130Sstevel@tonic-gate 		return (DCMD_ERR);
3140Sstevel@tonic-gate 	}
3150Sstevel@tonic-gate 
3169131SRod.Evans@Sun.COM 	for (nitems = 1; nitems < apl.apl_nitems; nitems++) {
3179131SRod.Evans@Sun.COM 		datap += sizeof (void *);
3189131SRod.Evans@Sun.COM 		if (mdb_vread(&bdp, sizeof (Bnd_desc *), datap) == -1) {
3190Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
3209131SRod.Evans@Sun.COM 			    MSG_ORIG(MSG_BNDDESC_STR), datap);
3210Sstevel@tonic-gate 			return (DCMD_ERR);
3220Sstevel@tonic-gate 		}
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
3250Sstevel@tonic-gate 		if (dcmd_Bind((uintptr_t)bdp, flags, argc, argv) == DCMD_ERR) {
32611053SSurya.Prakki@Sun.COM 			(void) mdb_dec_indent(4);
3270Sstevel@tonic-gate 			return (DCMD_ERR);
3280Sstevel@tonic-gate 		}
3290Sstevel@tonic-gate 	}
33011053SSurya.Prakki@Sun.COM 	(void) mdb_dec_indent(4);
3310Sstevel@tonic-gate 	return (DCMD_OK);
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate static int
dcmd_Depends(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3350Sstevel@tonic-gate dcmd_Depends(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3360Sstevel@tonic-gate {
3370Sstevel@tonic-gate 	Rt_map		rtmap;
3380Sstevel@tonic-gate 	char		*str;
3390Sstevel@tonic-gate 	uint_t		flg = 0;
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 	/*
3420Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
3430Sstevel@tonic-gate 	 */
3440Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
3450Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_DEPENDS_STR));
3460Sstevel@tonic-gate 		return (DCMD_USAGE);
3470Sstevel@tonic-gate 	}
3480Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
3490Sstevel@tonic-gate 	    &flg, NULL) != argc)
3500Sstevel@tonic-gate 		return (DCMD_USAGE);
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 	/*
3530Sstevel@tonic-gate 	 * Read the Rt_map contents.
3540Sstevel@tonic-gate 	 */
3550Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
3560Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
3570Sstevel@tonic-gate 		return (DCMD_ERR);
3580Sstevel@tonic-gate 	}
3590Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
3600Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
3610Sstevel@tonic-gate 		return (DCMD_ERR);
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_DEPENDS_LINE1), str);
3640Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
3650Sstevel@tonic-gate 
3665892Sab196087 	if (DEPENDS(&rtmap) == NULL)
3670Sstevel@tonic-gate 		return (DCMD_OK);
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 	return (Depends((uintptr_t)DEPENDS(&rtmap), flags, argc, argv, flg,
3700Sstevel@tonic-gate 	    MSG_ORIG(MSG_DEPENDS_LINE2)));
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate static void
dcmd_Callers_help(void)3740Sstevel@tonic-gate dcmd_Callers_help(void)
3750Sstevel@tonic-gate {
3760Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_CALLERS_HELP));
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate static int
dcmd_Callers(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3800Sstevel@tonic-gate dcmd_Callers(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3810Sstevel@tonic-gate {
3820Sstevel@tonic-gate 	Rt_map		rtmap;
3830Sstevel@tonic-gate 	char		*str;
3840Sstevel@tonic-gate 	uint_t		flg = 0;
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	/*
3870Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
3880Sstevel@tonic-gate 	 */
3890Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
3900Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_DEPENDS_STR));
3910Sstevel@tonic-gate 		return (DCMD_USAGE);
3920Sstevel@tonic-gate 	}
3930Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
3940Sstevel@tonic-gate 	    &flg, NULL) != argc)
3950Sstevel@tonic-gate 		return (DCMD_USAGE);
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate 	/*
3980Sstevel@tonic-gate 	 * Read the Rt_map contents.
3990Sstevel@tonic-gate 	 */
4000Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
4010Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
4020Sstevel@tonic-gate 		return (DCMD_ERR);
4030Sstevel@tonic-gate 	}
4040Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
4050Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
4060Sstevel@tonic-gate 		return (DCMD_ERR);
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_CALLERS_LINE1), str);
4090Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
4100Sstevel@tonic-gate 
4115892Sab196087 	if (CALLERS(&rtmap) == NULL)
4120Sstevel@tonic-gate 		return (DCMD_OK);
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate 	return (Depends((uintptr_t)CALLERS(&rtmap), flags, argc, argv, flg,
4150Sstevel@tonic-gate 	    MSG_ORIG(MSG_CALLERS_LINE2)));
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate void
dcmd_rtmap_help(void)4190Sstevel@tonic-gate dcmd_rtmap_help(void)
4200Sstevel@tonic-gate {
4210Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_HELP));
4220Sstevel@tonic-gate }
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate static int
4250Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_rtmap(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4260Sstevel@tonic-gate dcmd_rtmap(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4270Sstevel@tonic-gate {
4280Sstevel@tonic-gate 	Rt_map		rtmap;
4290Sstevel@tonic-gate 	char		*str;
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
4320Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_RTMAP_STR));
4330Sstevel@tonic-gate 		return (DCMD_USAGE);
4340Sstevel@tonic-gate 	}
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
4370Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
4380Sstevel@tonic-gate 		return (DCMD_ERR);
4390Sstevel@tonic-gate 	}
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_TITLE), addr);
4420Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
4430Sstevel@tonic-gate 
4440Sstevel@tonic-gate 	/*
4450Sstevel@tonic-gate 	 * Determine the objects name.  NAME() is the name by which the object
4460Sstevel@tonic-gate 	 * has been opened, typically from adding a search path to a file name.
4470Sstevel@tonic-gate 	 * PATHNAME() is the fully resolve name, which is displayed by the proc
4480Sstevel@tonic-gate 	 * tools and debuggers.  If the two names differ, print the PATHNAME().
4490Sstevel@tonic-gate 	 */
4500Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
4510Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
4520Sstevel@tonic-gate 		return (DCMD_ERR);
4530Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE1), str);
4540Sstevel@tonic-gate 	if (NAME(&rtmap) != PATHNAME(&rtmap)) {
4550Sstevel@tonic-gate 		if ((str = String((uintptr_t)PATHNAME(&rtmap),
4560Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_PATHNAME))) == 0)
4570Sstevel@tonic-gate 			return (DCMD_ERR);
4580Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_RTMAP_LINE2), str);
4590Sstevel@tonic-gate 	}
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE3), ADDR(&rtmap), DYN(&rtmap));
4620Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE4), NEXT(&rtmap), PREV(&rtmap));
4630Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE5), rtmap.rt_fct, TLSMODID(&rtmap));
4640Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE6), INIT(&rtmap), FINI(&rtmap));
4650Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE7), GROUPS(&rtmap), HANDLES(&rtmap));
4660Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE8), DEPENDS(&rtmap), CALLERS(&rtmap));
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	if ((str = String((uintptr_t)REFNAME(&rtmap),
4690Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_REFNAME))) == 0)
4700Sstevel@tonic-gate 		return (DCMD_ERR);
4710Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE9), DYNINFO(&rtmap), str);
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate 	if ((str = String((uintptr_t)RPATH(&rtmap),
4740Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_RPATH))) == 0)
4750Sstevel@tonic-gate 		return (DCMD_ERR);
4760Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE10), RLIST(&rtmap), str);
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE11), LIST(&rtmap), LIST(&rtmap));
4790Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE12), FLAGS(&rtmap));
4800Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), FLAGS(&rtmap), rtflags_bits);
4810Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE13), FLAGS1(&rtmap));
4820Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), FLAGS1(&rtmap), rtflags1_bits);
4838598SRod.Evans@Sun.COM 	if (AFLAGS(&rtmap)) {
4848598SRod.Evans@Sun.COM 		mdb_printf(MSG_ORIG(MSG_RTMAP_LINE14), AFLAGS(&rtmap));
4858598SRod.Evans@Sun.COM 		mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), AFLAGS(&rtmap),
4868598SRod.Evans@Sun.COM 		    rtaflags_bits);
4878598SRod.Evans@Sun.COM 	}
4888598SRod.Evans@Sun.COM 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE15), MODE(&rtmap));
4890Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAP_LINE20), MODE(&rtmap), rtmode_bits);
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate 	return (DCMD_OK);
4920Sstevel@tonic-gate }
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate static int
rtmap_format(uintptr_t addr,const void * data,void * private)4958598SRod.Evans@Sun.COM rtmap_format(uintptr_t addr, const void *data, void *private)
4960Sstevel@tonic-gate {
4970Sstevel@tonic-gate 	const Rt_map	*lmp = (const Rt_map *)data;
4980Sstevel@tonic-gate 	W_desc		*wdp = (W_desc *)private;
4990Sstevel@tonic-gate 	char		*str;
5000Sstevel@tonic-gate 
5010Sstevel@tonic-gate 	if (wdp && (wdp->w_flags & RTLD_FLG_VERBOSE)) {
5020Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
50311053SSurya.Prakki@Sun.COM 		(void) mdb_call_dcmd(
50411053SSurya.Prakki@Sun.COM 		    MSG_ORIG(MSG_RTMAP_STR), addr, DCMD_ADDRSPEC, NULL, NULL);
5050Sstevel@tonic-gate 		return (0);
5060Sstevel@tonic-gate 	}
5070Sstevel@tonic-gate 
5080Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(lmp),
5090Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
5100Sstevel@tonic-gate 		return (DCMD_ERR);
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_FMT_RT), CNTL(lmp), addr, ADDR(lmp), str);
5130Sstevel@tonic-gate 	return (0);
5140Sstevel@tonic-gate }
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate void
dcmd_Rtmaps_help(void)5170Sstevel@tonic-gate dcmd_Rtmaps_help(void)
5180Sstevel@tonic-gate {
5190Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_RTMAPS_HELP));
5200Sstevel@tonic-gate }
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate static int
dcmd_Rtmaps(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5230Sstevel@tonic-gate dcmd_Rtmaps(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5240Sstevel@tonic-gate {
5250Sstevel@tonic-gate 	uint_t		flg = 0;
5260Sstevel@tonic-gate 	GElf_Sym	gsym;
5279131SRod.Evans@Sun.COM 	APlist		*aplp, apl;
5289131SRod.Evans@Sun.COM 	uintptr_t	datap, nitems;
5290Sstevel@tonic-gate 	const char	*str;
5300Sstevel@tonic-gate 	W_desc		wdesc;
5310Sstevel@tonic-gate 
5320Sstevel@tonic-gate 	/*
5330Sstevel@tonic-gate 	 * '-v' - Verbose output of rtmap
5340Sstevel@tonic-gate 	 */
5350Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
5360Sstevel@tonic-gate 	    &flg, NULL) != argc)
5370Sstevel@tonic-gate 		return (DCMD_USAGE);
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate 	/*
5400Sstevel@tonic-gate 	 * If an address was provided use it.
5410Sstevel@tonic-gate 	 */
5420Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC) {
5430Sstevel@tonic-gate 		if (((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) &&
5440Sstevel@tonic-gate 		    !(flg & RTLD_FLG_VERBOSE)) {
5450Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
5460Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
5470Sstevel@tonic-gate 		}
5480Sstevel@tonic-gate 
5490Sstevel@tonic-gate 		wdesc.w_flags = flg;
5500Sstevel@tonic-gate 		if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), rtmap_format,
5510Sstevel@tonic-gate 		    (void *)&wdesc, addr) == -1)
5520Sstevel@tonic-gate 			return (DCMD_ERR);
5530Sstevel@tonic-gate 		return (DCMD_OK);
5540Sstevel@tonic-gate 	}
5550Sstevel@tonic-gate 
5560Sstevel@tonic-gate 	/*
5570Sstevel@tonic-gate 	 * Otherwise traverse the dynlm_list and display each link-map.
5580Sstevel@tonic-gate 	 */
5590Sstevel@tonic-gate 	if (mdb_lookup_by_obj(MSG_ORIG(MSG_STR_LDSO1),
5600Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_DYNLMLIST), &gsym) == -1) {
5610Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_SYMFAILED), MSG_ORIG(MSG_STR_LDSO1),
5620Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_DYNLMLIST));
5630Sstevel@tonic-gate 		return (DCMD_ERR);
5640Sstevel@tonic-gate 	}
5659131SRod.Evans@Sun.COM 	if (mdb_vread(&aplp, sizeof (APlist *),
5669131SRod.Evans@Sun.COM 	    (uintptr_t)gsym.st_value) == -1) {
5679131SRod.Evans@Sun.COM 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_APLIST),
5680Sstevel@tonic-gate 		    gsym.st_value);
5690Sstevel@tonic-gate 		return (DCMD_ERR);
5700Sstevel@tonic-gate 	}
5710Sstevel@tonic-gate 
5729131SRod.Evans@Sun.COM 	if (aplp == NULL) {
5739131SRod.Evans@Sun.COM 		mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE0),
5749131SRod.Evans@Sun.COM 		    MSG_ORIG(MSG_STR_DYNLMLIST));
5759131SRod.Evans@Sun.COM 		return (DCMD_OK);
5769131SRod.Evans@Sun.COM 	}
5779131SRod.Evans@Sun.COM 
5789131SRod.Evans@Sun.COM 	if (mdb_vread(&apl, sizeof (APlist), (uintptr_t)aplp) == -1) {
5799131SRod.Evans@Sun.COM 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_APLIST),
5809131SRod.Evans@Sun.COM 		    aplp);
5819131SRod.Evans@Sun.COM 	}
5820Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE1), MSG_ORIG(MSG_STR_DYNLMLIST),
5839131SRod.Evans@Sun.COM 	    aplp, (size_t)apl.apl_nitems, (size_t)apl.apl_arritems);
5840Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate 	flags |= (DCMD_LOOP | DCMD_LOOPFIRST);
5879131SRod.Evans@Sun.COM 	for (datap = (uintptr_t)aplp + APLIST_OFF_DATA, nitems = 0;
5889131SRod.Evans@Sun.COM 	    nitems < apl.apl_nitems; nitems++, datap += sizeof (void *)) {
5899131SRod.Evans@Sun.COM 		Lm_list	*lml, lm;
5900Sstevel@tonic-gate 
5919131SRod.Evans@Sun.COM 		if (mdb_vread(&lml, sizeof (Lm_list *), datap) == -1) {
5920Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
5939131SRod.Evans@Sun.COM 			    MSG_ORIG(MSG_LMLIST_STR), datap);
5940Sstevel@tonic-gate 			return (DCMD_ERR);
5950Sstevel@tonic-gate 		}
5969131SRod.Evans@Sun.COM 		if (mdb_vread(&lm, sizeof (Lm_list), (uintptr_t)lml) == -1) {
5970Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
5989131SRod.Evans@Sun.COM 			    MSG_ORIG(MSG_LMLIST_STR), lml);
5990Sstevel@tonic-gate 			return (DCMD_ERR);
6000Sstevel@tonic-gate 		}
6010Sstevel@tonic-gate 
60211053SSurya.Prakki@Sun.COM 		(void) mdb_inc_indent(2);
6039131SRod.Evans@Sun.COM 		if (lm.lm_flags & LML_FLG_BASELM)
6040Sstevel@tonic-gate 			str = MSG_ORIG(MSG_LMLIST_BASE);
6059131SRod.Evans@Sun.COM 		else if (lm.lm_flags & LML_FLG_RTLDLM)
6060Sstevel@tonic-gate 			str = MSG_ORIG(MSG_LMLIST_LDSO);
6070Sstevel@tonic-gate 		else
6080Sstevel@tonic-gate 			str = MSG_ORIG(MSG_LMLIST_NEWLM);
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 		if ((flags & DCMD_LOOP) && ((flags & DCMD_LOOPFIRST) == 0))
6110Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
6120Sstevel@tonic-gate 
6139131SRod.Evans@Sun.COM 		mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE2), datap, str);
6140Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
6150Sstevel@tonic-gate 
61611053SSurya.Prakki@Sun.COM 		(void) mdb_inc_indent(2);
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate 		if (((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP)) &&
6190Sstevel@tonic-gate 		    !(flg & RTLD_FLG_VERBOSE)) {
6200Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
6210Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
6220Sstevel@tonic-gate 		}
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate 		wdesc.w_flags = flg;
6250Sstevel@tonic-gate 		if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR), rtmap_format,
6269131SRod.Evans@Sun.COM 		    (void *)&wdesc, (uintptr_t)lm.lm_head) == -1) {
62711053SSurya.Prakki@Sun.COM 			(void) mdb_dec_indent(4);
6280Sstevel@tonic-gate 			return (DCMD_ERR);
6290Sstevel@tonic-gate 		}
63011053SSurya.Prakki@Sun.COM 		(void) mdb_dec_indent(4);
6310Sstevel@tonic-gate 		flags &= ~DCMD_LOOPFIRST;
6320Sstevel@tonic-gate 	}
6330Sstevel@tonic-gate 	return (DCMD_OK);
6340Sstevel@tonic-gate }
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate void
dcmd_Setenv_help(void)6370Sstevel@tonic-gate dcmd_Setenv_help(void)
6380Sstevel@tonic-gate {
6390Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_SETENV_HELP));
6400Sstevel@tonic-gate }
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate /*
6430Sstevel@tonic-gate  * As of s10, mdb provides its own setenv command.  This command allows the
6440Sstevel@tonic-gate  * environment of the process being controlled to be changed at any time.
6450Sstevel@tonic-gate  * Prior to this, ld.so.1 provided it's own, more primitive implementation.
6460Sstevel@tonic-gate  * This allowed for changing mdb's environment only, which if it was changed
6470Sstevel@tonic-gate  * before the application ws executed, would be copied to the applications
6480Sstevel@tonic-gate  * environment.  Thus, we could start mdb, set an LD_ variable within its
6490Sstevel@tonic-gate  * environment (which it's own ld.so.1 had already finished processing), and
6500Sstevel@tonic-gate  * have this setting be inherited by the application.
6510Sstevel@tonic-gate  */
6520Sstevel@tonic-gate static int
6530Sstevel@tonic-gate /* ARGSUSED */
dcmd_Setenv(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)6540Sstevel@tonic-gate dcmd_Setenv(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
6550Sstevel@tonic-gate {
6560Sstevel@tonic-gate 	char	*str;
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate 	if (mdb_call_dcmd(MSG_ORIG(MSG_STR_SETENV), addr, flags, argc,
6590Sstevel@tonic-gate 	    argv) == 0)
6600Sstevel@tonic-gate 		return (DCMD_OK);
6610Sstevel@tonic-gate 
6620Sstevel@tonic-gate 	if (((flags & DCMD_ADDRSPEC) != 0) || (argc == 0) || (argc > 1) ||
6630Sstevel@tonic-gate 	    (argv->a_type != MDB_TYPE_STRING))
6640Sstevel@tonic-gate 		return (DCMD_USAGE);
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 	str = mdb_alloc((strlen(argv->a_un.a_str) + 1), UM_NOSLEEP);
6670Sstevel@tonic-gate 	if (str == NULL)
6680Sstevel@tonic-gate 		return (DCMD_ERR);
6690Sstevel@tonic-gate 
6700Sstevel@tonic-gate 	(void) strcpy(str, argv->a_un.a_str);
6710Sstevel@tonic-gate 	(void) putenv(str);
6720Sstevel@tonic-gate 	return (DCMD_OK);
6730Sstevel@tonic-gate }
6740Sstevel@tonic-gate 
6750Sstevel@tonic-gate /*
6760Sstevel@tonic-gate  * Walk Rt_map lists
6770Sstevel@tonic-gate  */
6780Sstevel@tonic-gate static int
walk_rtmap_init(mdb_walk_state_t * wsp)6790Sstevel@tonic-gate walk_rtmap_init(mdb_walk_state_t *wsp)
6800Sstevel@tonic-gate {
6810Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
6820Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_RTMAP_STR));
6830Sstevel@tonic-gate 		return (WALK_ERR);
6840Sstevel@tonic-gate 	}
6850Sstevel@tonic-gate 	return (WALK_NEXT);
6860Sstevel@tonic-gate }
6870Sstevel@tonic-gate 
6880Sstevel@tonic-gate static int
walk_rtmap_step(mdb_walk_state_t * wsp)6890Sstevel@tonic-gate walk_rtmap_step(mdb_walk_state_t *wsp)
6900Sstevel@tonic-gate {
6910Sstevel@tonic-gate 	int	status;
6920Sstevel@tonic-gate 	Rt_map	lmp;
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate 	if (wsp->walk_addr == NULL)
6950Sstevel@tonic-gate 		return (WALK_DONE);
6960Sstevel@tonic-gate 	if (mdb_vread(&lmp, sizeof (Rt_map), wsp->walk_addr) == -1) {
6970Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
6980Sstevel@tonic-gate 		    MSG_ORIG(MSG_RTMAP_STR), wsp->walk_addr);
6990Sstevel@tonic-gate 		return (WALK_DONE);
7000Sstevel@tonic-gate 	}
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &lmp, wsp->walk_cbdata);
7030Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)(NEXT(&lmp));
7040Sstevel@tonic-gate 	return (status);
7050Sstevel@tonic-gate }
7060Sstevel@tonic-gate 
7070Sstevel@tonic-gate static const mdb_bitmask_t lml_flags_bit[] = {
7080Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_BASELM), LML_FLG_BASELM, LML_FLG_BASELM },
7090Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_RTLDLM), LML_FLG_RTLDLM, LML_FLG_RTLDLM },
7100Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_PLTREL), LML_FLG_PLTREL, LML_FLG_PLTREL },
7110Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_HOLDLOCK), LML_FLG_HOLDLOCK, LML_FLG_HOLDLOCK },
7120Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_ENVIRON), LML_FLG_ENVIRON, LML_FLG_ENVIRON },
7130Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_INTRPOSE), LML_FLG_INTRPOSE, LML_FLG_INTRPOSE },
7140Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_LOCAUDIT), LML_FLG_LOCAUDIT, LML_FLG_LOCAUDIT },
7150Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_LOADAVAIL), LML_FLG_LOADAVAIL, LML_FLG_LOADAVAIL },
7160Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_IGNRELERR), LML_FLG_IGNRELERR, LML_FLG_IGNRELERR },
7170Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_STARTREL), LML_FLG_STARTREL, LML_FLG_STARTREL },
718280Srie 	{ MSG_ORIG(MSG_LFL_ATEXIT), LML_FLG_ATEXIT, LML_FLG_ATEXIT },
719280Srie 	{ MSG_ORIG(MSG_LFL_OBJADDED), LML_FLG_OBJADDED, LML_FLG_OBJADDED },
720280Srie 	{ MSG_ORIG(MSG_LFL_OBJDELETED), LML_FLG_OBJDELETED,
721280Srie 	    LML_FLG_OBJDELETED },
722280Srie 	{ MSG_ORIG(MSG_LFL_OBJREEVAL), LML_FLG_OBJREEVAL, LML_FLG_OBJREEVAL },
7238598SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_LFL_INTRPOSETSORT), LML_FLG_INTRPOSETSORT,
7248598SRod.Evans@Sun.COM 	    LML_FLG_INTRPOSETSORT },
7258598SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_LFL_AUDITNOTIFY), LML_FLG_AUDITNOTIFY,
7268598SRod.Evans@Sun.COM 	    LML_FLG_AUDITNOTIFY },
7278598SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_LFL_GROUPSEXIST), LML_FLG_GROUPSEXIST,
7288598SRod.Evans@Sun.COM 	    LML_FLG_GROUPSEXIST },
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_LDDSTUB), LML_FLG_TRC_LDDSTUB,
7310Sstevel@tonic-gate 	    LML_FLG_TRC_LDDSTUB },
7320Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_ENABLE), LML_FLG_TRC_ENABLE,
7330Sstevel@tonic-gate 	    LML_FLG_TRC_ENABLE },
7340Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_WARN), LML_FLG_TRC_WARN, LML_FLG_TRC_WARN },
7350Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_VERBOSE), LML_FLG_TRC_VERBOSE,
7360Sstevel@tonic-gate 	    LML_FLG_TRC_VERBOSE },
7370Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_SEARCH), LML_FLG_TRC_SEARCH,
7380Sstevel@tonic-gate 	    LML_FLG_TRC_SEARCH },
7390Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_UNREF), LML_FLG_TRC_UNREF, LML_FLG_TRC_UNREF },
7400Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_UNUSED), LML_FLG_TRC_UNUSED,
7410Sstevel@tonic-gate 	    LML_FLG_TRC_UNUSED },
7420Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LFL_TRC_INIT), LML_FLG_TRC_INIT, LML_FLG_TRC_INIT },
7438598SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_LFL_TRC_NOUNRESWEAK), LML_FLG_TRC_NOUNRESWEAK,
7448598SRod.Evans@Sun.COM 	    LML_FLG_TRC_NOUNRESWEAK },
7458598SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_LFL_TRC_NOPAREXT), LML_FLG_TRC_NOPAREXT,
7468598SRod.Evans@Sun.COM 	    LML_FLG_TRC_NOPAREXT },
7470Sstevel@tonic-gate 	{ NULL, 0, 0}
7480Sstevel@tonic-gate };
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate static const mdb_bitmask_t lml_tflags_bit[] = {
7510Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_NOLAZYLD), LML_TFLG_NOLAZYLD, LML_TFLG_NOLAZYLD },
7520Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_NODIRECT), LML_TFLG_NODIRECT, LML_TFLG_NODIRECT },
753*12877SRod.Evans@Sun.COM 	{ MSG_ORIG(MSG_LTFL_NOAUDIT), LML_TFLG_NOAUDIT, LML_TFLG_NOAUDIT },
7540Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_LOADFLTR), LML_TFLG_LOADFLTR, LML_TFLG_LOADFLTR },
7550Sstevel@tonic-gate 
7560Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PREINIT), LML_TFLG_AUD_PREINIT,
7570Sstevel@tonic-gate 	    LML_TFLG_AUD_PREINIT },
7580Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJSEARCH), LML_TFLG_AUD_OBJSEARCH,
7590Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJSEARCH },
7600Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJOPEN), LML_TFLG_AUD_OBJOPEN,
7610Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJOPEN },
7620Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJFILTER), LML_TFLG_AUD_OBJFILTER,
7630Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJFILTER },
7640Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_OBJCLOSE), LML_TFLG_AUD_OBJCLOSE,
7650Sstevel@tonic-gate 	    LML_TFLG_AUD_OBJCLOSE },
7660Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_SYMBIND), LML_TFLG_AUD_SYMBIND,
7670Sstevel@tonic-gate 	    LML_TFLG_AUD_SYMBIND },
7680Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTENTER), LML_TFLG_AUD_PLTENTER,
7690Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTENTER },
7700Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_PLTEXIT), LML_TFLG_AUD_PLTEXIT,
7710Sstevel@tonic-gate 	    LML_TFLG_AUD_PLTEXIT },
7720Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LTFL_AUD_ACTIVITY), LML_TFLG_AUD_ACTIVITY,
7730Sstevel@tonic-gate 	    LML_TFLG_AUD_ACTIVITY },
7740Sstevel@tonic-gate 	{ NULL, 0, 0}
7750Sstevel@tonic-gate };
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate void
dcmd_Lm_list_help(void)7780Sstevel@tonic-gate dcmd_Lm_list_help(void)
7790Sstevel@tonic-gate {
7800Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_HELP));
7810Sstevel@tonic-gate }
7820Sstevel@tonic-gate 
7830Sstevel@tonic-gate static int
7840Sstevel@tonic-gate /* ARGSUSED1 */
_dcmd_Lm_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)7850Sstevel@tonic-gate _dcmd_Lm_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7860Sstevel@tonic-gate {
7870Sstevel@tonic-gate 	Lm_list		lml;
7880Sstevel@tonic-gate 	const char	*str;
7890Sstevel@tonic-gate 	uint_t		flg = 0;
7900Sstevel@tonic-gate 
7910Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
7920Sstevel@tonic-gate 	    &flg, NULL) != argc)
7930Sstevel@tonic-gate 		return (DCMD_USAGE);
7940Sstevel@tonic-gate 
7950Sstevel@tonic-gate 	if (mdb_vread(&lml, sizeof (lml), addr) == -1) {
7960Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_LMLIST_STR),
7970Sstevel@tonic-gate 		    addr);
7980Sstevel@tonic-gate 		return (DCMD_ERR);
7990Sstevel@tonic-gate 	}
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate 	if (lml.lm_flags & LML_FLG_BASELM)
8020Sstevel@tonic-gate 		str = MSG_ORIG(MSG_LMLIST_BASE);
8030Sstevel@tonic-gate 	else if (lml.lm_flags & LML_FLG_RTLDLM)
8040Sstevel@tonic-gate 		str = MSG_ORIG(MSG_LMLIST_LDSO);
8050Sstevel@tonic-gate 	else
8060Sstevel@tonic-gate 		str = MSG_ORIG(MSG_LMLIST_NEWLM);
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate 	if ((flags & DCMD_LOOP) && ((flags & DCMD_LOOPFIRST) == 0))
8090Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8100Sstevel@tonic-gate 
8110Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE2), addr, str);
8120Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 	if (lml.lm_lists) {
8150Sstevel@tonic-gate 		Alist		al;
8160Sstevel@tonic-gate 		Lm_cntl		lmc;
8179131SRod.Evans@Sun.COM 		uintptr_t	datap;
8180Sstevel@tonic-gate 
8190Sstevel@tonic-gate 		addr = (uintptr_t)lml.lm_lists;
8200Sstevel@tonic-gate 		if (mdb_vread(&al, sizeof (Alist), addr) == -1) {
8210Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
8220Sstevel@tonic-gate 			    MSG_ORIG(MSG_STR_ALIST), addr);
8230Sstevel@tonic-gate 			return (DCMD_ERR);
8240Sstevel@tonic-gate 		}
8250Sstevel@tonic-gate 
8260Sstevel@tonic-gate 		/*
8270Sstevel@tonic-gate 		 * Determine whether the Alist has been populated.  Note, the
8280Sstevel@tonic-gate 		 * implementation first reserves an alist entry, and initializes
8290Sstevel@tonic-gate 		 * this element when the first link-map is processed.  Thus,
8305892Sab196087 		 * there's a window when nitems is updated, but before the next
8310Sstevel@tonic-gate 		 * element has been initialized.
8320Sstevel@tonic-gate 		 */
8335892Sab196087 		if (al.al_nitems && (flg & RTLD_FLG_VERBOSE)) {
8349131SRod.Evans@Sun.COM 			datap = ALIST_OFF_DATA + (uintptr_t)addr;
8350Sstevel@tonic-gate 
8360Sstevel@tonic-gate 			if (mdb_vread(&lmc, sizeof (Lm_cntl),
8379131SRod.Evans@Sun.COM 			    datap) == -1) {
8380Sstevel@tonic-gate 				mdb_warn(MSG_ORIG(MSG_ERR_READ),
8399131SRod.Evans@Sun.COM 				    MSG_ORIG(MSG_LMLIST_STR), datap);
8400Sstevel@tonic-gate 				return (DCMD_ERR);
8410Sstevel@tonic-gate 			}
8420Sstevel@tonic-gate 		}
8430Sstevel@tonic-gate 
8445892Sab196087 		mdb_printf(MSG_ORIG(MSG_LMLIST_LINE0), addr,
8455892Sab196087 		    (size_t)al.al_nitems, (size_t)al.al_arritems);
84611053SSurya.Prakki@Sun.COM 		(void) mdb_inc_indent(2);
8470Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8480Sstevel@tonic-gate 
8495892Sab196087 		if (al.al_nitems && (flg & RTLD_FLG_VERBOSE)) {
8509131SRod.Evans@Sun.COM 			uintptr_t	nitems;
8510Sstevel@tonic-gate 
85211053SSurya.Prakki@Sun.COM 			(void) mdb_inc_indent(2);
8539131SRod.Evans@Sun.COM 			mdb_printf(MSG_ORIG(MSG_LMC_LINE1), datap);
8540Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_LMC_LINE2), lmc.lc_head,
8550Sstevel@tonic-gate 			    lmc.lc_tail);
8560Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_LMC_LINE3), lmc.lc_flags,
8570Sstevel@tonic-gate 			    lmc.lc_now);
8580Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_LMC_LINE4), lmc.lc_flags,
8590Sstevel@tonic-gate 			    lmc_bits);
8600Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8610Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
8620Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8630Sstevel@tonic-gate 
8640Sstevel@tonic-gate 			if (lmc.lc_head) {
8650Sstevel@tonic-gate 				if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR),
8660Sstevel@tonic-gate 				    rtmap_format, (void *)0,
8670Sstevel@tonic-gate 				    (uintptr_t)lmc.lc_head) == -1) {
86811053SSurya.Prakki@Sun.COM 					(void) mdb_dec_indent(4);
8690Sstevel@tonic-gate 					return (DCMD_ERR);
8700Sstevel@tonic-gate 				}
8710Sstevel@tonic-gate 			} else
8720Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_FMT_RT), 0, 0, 0,
8730Sstevel@tonic-gate 				    MSG_ORIG(MSG_STR_EMPTY));
8740Sstevel@tonic-gate 
8750Sstevel@tonic-gate 			mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8760Sstevel@tonic-gate 
8779131SRod.Evans@Sun.COM 			for (nitems = 1; nitems < al.al_nitems; nitems++) {
8789131SRod.Evans@Sun.COM 				datap += al.al_size;
8790Sstevel@tonic-gate 				if (mdb_vread(&lmc, sizeof (Lm_cntl),
8809131SRod.Evans@Sun.COM 				    datap) == -1) {
8810Sstevel@tonic-gate 					mdb_warn(MSG_ORIG(MSG_ERR_READ),
8829131SRod.Evans@Sun.COM 					    MSG_ORIG(MSG_LMLIST_STR), datap);
88311053SSurya.Prakki@Sun.COM 					(void) mdb_dec_indent(4);
8840Sstevel@tonic-gate 					return (DCMD_ERR);
8850Sstevel@tonic-gate 				}
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8889131SRod.Evans@Sun.COM 				mdb_printf(MSG_ORIG(MSG_LMC_LINE1), datap);
8890Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_LMC_LINE2),
8900Sstevel@tonic-gate 				    lmc.lc_head, lmc.lc_tail);
8910Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_LMC_LINE3),
8920Sstevel@tonic-gate 				    lmc.lc_flags, lmc.lc_now);
8930Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_LMC_LINE4),
8940Sstevel@tonic-gate 				    lmc.lc_flags, lmc_bits);
8950Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8960Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_RTMAPS_TITLE0));
8970Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
8980Sstevel@tonic-gate 
8990Sstevel@tonic-gate 				if (lmc.lc_head) {
9000Sstevel@tonic-gate 					if (mdb_pwalk(MSG_ORIG(MSG_RTMAPS_STR),
9010Sstevel@tonic-gate 					    rtmap_format, (void *)0,
9020Sstevel@tonic-gate 					    (uintptr_t)lmc.lc_head) == -1) {
90311053SSurya.Prakki@Sun.COM 						(void) mdb_dec_indent(4);
9040Sstevel@tonic-gate 						return (DCMD_ERR);
9050Sstevel@tonic-gate 					}
9060Sstevel@tonic-gate 				} else
9070Sstevel@tonic-gate 					mdb_printf(MSG_ORIG(MSG_FMT_RT), 0, 0,
9080Sstevel@tonic-gate 					    0, MSG_ORIG(MSG_STR_EMPTY));
9090Sstevel@tonic-gate 
9100Sstevel@tonic-gate 				mdb_printf(MSG_ORIG(MSG_STR_DASHES));
9110Sstevel@tonic-gate 			}
91211053SSurya.Prakki@Sun.COM 			(void) mdb_dec_indent(2);
9130Sstevel@tonic-gate 		}
91411053SSurya.Prakki@Sun.COM 		(void) mdb_dec_indent(2);
9150Sstevel@tonic-gate 	}
9160Sstevel@tonic-gate 
9170Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE1), lml.lm_head, lml.lm_tail);
9181824Srie 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE2), lml.lm_alp, lml.lm_rti);
9190Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE3), lml.lm_handle, lml.lm_obj,
9200Sstevel@tonic-gate 	    lml.lm_init, lml.lm_lazy);
9210Sstevel@tonic-gate 
9220Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE4), lml.lm_flags);
9230Sstevel@tonic-gate 	if (lml.lm_flags)
9240Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_LMLIST_LINE6), lml.lm_flags,
9250Sstevel@tonic-gate 		    lml_flags_bit);
9260Sstevel@tonic-gate 
9270Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_LINE5), lml.lm_tflags);
9280Sstevel@tonic-gate 	if (lml.lm_tflags)
9290Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_LMLIST_LINE6), lml.lm_tflags,
9300Sstevel@tonic-gate 		    lml_tflags_bit);
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate 	return (DCMD_OK);
9330Sstevel@tonic-gate }
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate static int
9360Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_Lm_list(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)9370Sstevel@tonic-gate dcmd_Lm_list(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
9380Sstevel@tonic-gate {
9390Sstevel@tonic-gate 	GElf_Sym	gsym;
9409131SRod.Evans@Sun.COM 	APlist		*aplp, apl;
9419131SRod.Evans@Sun.COM 	uintptr_t	datap, nitems;
9420Sstevel@tonic-gate 
9430Sstevel@tonic-gate 	/*
9440Sstevel@tonic-gate 	 * If an address was provided us it.
9450Sstevel@tonic-gate 	 */
9460Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC)
9470Sstevel@tonic-gate 		return (_dcmd_Lm_list(addr, flags, argc, argv));
9480Sstevel@tonic-gate 
9490Sstevel@tonic-gate 	/*
9500Sstevel@tonic-gate 	 * Otherwise traverse the dynlm_list and display each link-map list.
9510Sstevel@tonic-gate 	 */
9520Sstevel@tonic-gate 	if (mdb_lookup_by_obj(MSG_ORIG(MSG_STR_LDSO1),
9530Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_DYNLMLIST), &gsym) == -1) {
9540Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_SYMFAILED), MSG_ORIG(MSG_STR_LDSO1),
9554679Srie 		    MSG_ORIG(MSG_STR_DYNLMLIST));
9560Sstevel@tonic-gate 		return (DCMD_ERR);
9570Sstevel@tonic-gate 	}
9589131SRod.Evans@Sun.COM 	if (mdb_vread(&aplp, sizeof (APlist *),
9599131SRod.Evans@Sun.COM 	    (uintptr_t)gsym.st_value) == -1) {
9609131SRod.Evans@Sun.COM 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_APLIST),
9610Sstevel@tonic-gate 		    gsym.st_value);
9620Sstevel@tonic-gate 		return (DCMD_ERR);
9630Sstevel@tonic-gate 	}
9649131SRod.Evans@Sun.COM 	if (aplp == NULL) {
9659131SRod.Evans@Sun.COM 		mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE0),
9669131SRod.Evans@Sun.COM 		    MSG_ORIG(MSG_STR_DYNLMLIST));
9679131SRod.Evans@Sun.COM 		return (DCMD_OK);
9689131SRod.Evans@Sun.COM 	}
9699131SRod.Evans@Sun.COM 
9709131SRod.Evans@Sun.COM 	if (mdb_vread(&apl, sizeof (APlist), (uintptr_t)aplp) == -1) {
9719131SRod.Evans@Sun.COM 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_APLIST),
9729131SRod.Evans@Sun.COM 		    aplp);
9739131SRod.Evans@Sun.COM 		return (DCMD_ERR);
9749131SRod.Evans@Sun.COM 	}
9750Sstevel@tonic-gate 
9760Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_LMLIST_TITLE1), MSG_ORIG(MSG_STR_DYNLMLIST),
9779131SRod.Evans@Sun.COM 	    aplp, (size_t)apl.apl_nitems, (size_t)apl.apl_arritems);
9780Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
9790Sstevel@tonic-gate 
9800Sstevel@tonic-gate 	flags |= (DCMD_LOOP | DCMD_LOOPFIRST);
9819131SRod.Evans@Sun.COM 	for (datap = (uintptr_t)aplp + APLIST_OFF_DATA, nitems = 0;
9829131SRod.Evans@Sun.COM 	    nitems < apl.apl_nitems; nitems++, datap += sizeof (void *)) {
9839131SRod.Evans@Sun.COM 		Lm_list	*lml;
9849131SRod.Evans@Sun.COM 
9859131SRod.Evans@Sun.COM 		if (mdb_vread(&lml, sizeof (Lm_list *), datap) == -1) {
9860Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
9879131SRod.Evans@Sun.COM 			    MSG_ORIG(MSG_LMLIST_STR), datap);
9880Sstevel@tonic-gate 			return (DCMD_ERR);
9890Sstevel@tonic-gate 		}
9900Sstevel@tonic-gate 
99111053SSurya.Prakki@Sun.COM 		(void) mdb_inc_indent(2);
9929131SRod.Evans@Sun.COM 		if (_dcmd_Lm_list((uintptr_t)lml, flags, argc,
9939131SRod.Evans@Sun.COM 		    argv) == DCMD_ERR) {
99411053SSurya.Prakki@Sun.COM 			(void) mdb_dec_indent(2);
9950Sstevel@tonic-gate 			return (DCMD_ERR);
9960Sstevel@tonic-gate 		}
99711053SSurya.Prakki@Sun.COM 		(void) mdb_dec_indent(2);
9980Sstevel@tonic-gate 		flags &= ~DCMD_LOOPFIRST;
9990Sstevel@tonic-gate 	}
10000Sstevel@tonic-gate 	return (DCMD_OK);
10010Sstevel@tonic-gate }
10020Sstevel@tonic-gate 
10030Sstevel@tonic-gate void
dcmd_GrpDesc_help(void)10040Sstevel@tonic-gate dcmd_GrpDesc_help(void)
10050Sstevel@tonic-gate {
10060Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_HELP));
10070Sstevel@tonic-gate }
10080Sstevel@tonic-gate 
10090Sstevel@tonic-gate static int
10100Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_GrpDesc(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)10110Sstevel@tonic-gate dcmd_GrpDesc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
10120Sstevel@tonic-gate {
10130Sstevel@tonic-gate 	Grp_desc	gd;
10140Sstevel@tonic-gate 	char		*str;
10150Sstevel@tonic-gate 
10160Sstevel@tonic-gate 	/*
10170Sstevel@tonic-gate 	 * Insure we have a valid address.
10180Sstevel@tonic-gate 	 */
10190Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
10200Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GRPDESC_STR));
10210Sstevel@tonic-gate 		return (DCMD_USAGE);
10220Sstevel@tonic-gate 	}
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE1), addr);
10250Sstevel@tonic-gate 	if (mdb_vread(&gd, sizeof (Grp_desc), addr) == -1) {
10260Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_GRPDESC_STR),
10270Sstevel@tonic-gate 		    addr);
10280Sstevel@tonic-gate 		return (DCMD_ERR);
10290Sstevel@tonic-gate 	}
10300Sstevel@tonic-gate 
10310Sstevel@tonic-gate 	if ((str = Rtmap_Name((uintptr_t)gd.gd_depend)) == 0)
10320Sstevel@tonic-gate 		return (DCMD_ERR);
10330Sstevel@tonic-gate 
10340Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE2), gd.gd_depend, str);
10350Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPDESC_LINE3), gd.gd_flags, gd.gd_flags,
10360Sstevel@tonic-gate 	    grdflags_bits);
10370Sstevel@tonic-gate 
10380Sstevel@tonic-gate 	return (DCMD_OK);
10390Sstevel@tonic-gate }
10400Sstevel@tonic-gate 
10410Sstevel@tonic-gate void
dcmd_GrpHdl_help(void)10420Sstevel@tonic-gate dcmd_GrpHdl_help(void)
10430Sstevel@tonic-gate {
10440Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_HELP));
10450Sstevel@tonic-gate }
10460Sstevel@tonic-gate 
10470Sstevel@tonic-gate static int
10480Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_GrpHdl(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)10490Sstevel@tonic-gate dcmd_GrpHdl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
10500Sstevel@tonic-gate {
10510Sstevel@tonic-gate 	Grp_hdl		gh;
10520Sstevel@tonic-gate 	Alist		al;
10539131SRod.Evans@Sun.COM 	uintptr_t	datap, listidx;
10540Sstevel@tonic-gate 	char		*str;
10550Sstevel@tonic-gate 	uint_t		flg = 0;
10560Sstevel@tonic-gate 
10570Sstevel@tonic-gate 	/*
10580Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
10590Sstevel@tonic-gate 	 */
10600Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
10610Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GRPHDL_STR));
10620Sstevel@tonic-gate 		return (DCMD_USAGE);
10630Sstevel@tonic-gate 	}
10640Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
10650Sstevel@tonic-gate 	    &flg, NULL) != argc)
10660Sstevel@tonic-gate 		return (DCMD_USAGE);
10670Sstevel@tonic-gate 
10680Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE1), addr);
10690Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
10700Sstevel@tonic-gate 
10710Sstevel@tonic-gate 	if (mdb_vread(&gh, sizeof (Grp_hdl), addr) == -1) {
10720Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_GRPHDL_STR),
10730Sstevel@tonic-gate 		    addr);
10740Sstevel@tonic-gate 		return (DCMD_ERR);
10750Sstevel@tonic-gate 	}
10760Sstevel@tonic-gate 
10770Sstevel@tonic-gate 	/*
10780Sstevel@tonic-gate 	 * Determine the handles owner.  Note that an orphaned handle may no
10790Sstevel@tonic-gate 	 * longer contain its originating owner.
10800Sstevel@tonic-gate 	 */
10811618Srie 	if (gh.gh_ownlmp) {
10821618Srie 		if ((str = Rtmap_Name((uintptr_t)gh.gh_ownlmp)) == 0)
10830Sstevel@tonic-gate 			return (DCMD_ERR);
10840Sstevel@tonic-gate 	} else
10850Sstevel@tonic-gate 		str = (char *)MSG_ORIG(MSG_STR_ORPHANED);
10860Sstevel@tonic-gate 
10870Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE2), str);
10880Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE3), gh.gh_flags, gh.gh_flags,
10890Sstevel@tonic-gate 	    grhflags_bits);
10900Sstevel@tonic-gate 
10910Sstevel@tonic-gate 	if (gh.gh_depends == 0) {
10920Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE4), gh.gh_refcnt);
10930Sstevel@tonic-gate 		return (DCMD_OK);
10940Sstevel@tonic-gate 	}
10950Sstevel@tonic-gate 
10960Sstevel@tonic-gate 	addr = (uintptr_t)gh.gh_depends;
10970Sstevel@tonic-gate 	if (mdb_vread(&al, sizeof (Alist), addr) == -1) {
10984679Srie 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_ALIST), addr);
10994679Srie 		return (DCMD_ERR);
11000Sstevel@tonic-gate 	}
11010Sstevel@tonic-gate 
11025892Sab196087 	mdb_printf(MSG_ORIG(MSG_GRPHDL_LINE5), gh.gh_refcnt, addr,
11035892Sab196087 	    (size_t)al.al_nitems, (size_t)al.al_arritems);
11040Sstevel@tonic-gate 
11055892Sab196087 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (al.al_nitems == 0))
11060Sstevel@tonic-gate 		return (DCMD_OK);
11070Sstevel@tonic-gate 
110811053SSurya.Prakki@Sun.COM 	(void) mdb_inc_indent(4);
11090Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
11100Sstevel@tonic-gate 
11110Sstevel@tonic-gate 	/*
11120Sstevel@tonic-gate 	 * Under verbose mode print the name of each dependency.  An Alist can
11130Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
11140Sstevel@tonic-gate 	 */
11159131SRod.Evans@Sun.COM 	datap = ALIST_OFF_DATA + (uintptr_t)addr;
11169131SRod.Evans@Sun.COM 	if (dcmd_GrpDesc(datap, flags, argc, argv) == DCMD_ERR) {
111711053SSurya.Prakki@Sun.COM 		(void) mdb_dec_indent(4);
11180Sstevel@tonic-gate 		return (DCMD_ERR);
11190Sstevel@tonic-gate 	}
11200Sstevel@tonic-gate 
11215892Sab196087 	for (listidx = 1; listidx < al.al_nitems; listidx++) {
11229131SRod.Evans@Sun.COM 		datap += al.al_size;
11230Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
11249131SRod.Evans@Sun.COM 		if (dcmd_GrpDesc(datap, flags, argc, argv) == DCMD_ERR) {
112511053SSurya.Prakki@Sun.COM 			(void) mdb_dec_indent(4);
11260Sstevel@tonic-gate 			return (DCMD_ERR);
11270Sstevel@tonic-gate 		}
11280Sstevel@tonic-gate 	}
11290Sstevel@tonic-gate 
113011053SSurya.Prakki@Sun.COM 	(void) mdb_dec_indent(4);
11310Sstevel@tonic-gate 	return (DCMD_OK);
11320Sstevel@tonic-gate }
11330Sstevel@tonic-gate 
11340Sstevel@tonic-gate static void
dcmd_Handles_help(void)11350Sstevel@tonic-gate dcmd_Handles_help(void)
11360Sstevel@tonic-gate {
11370Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_HANDLES_HELP));
11380Sstevel@tonic-gate }
11390Sstevel@tonic-gate 
11400Sstevel@tonic-gate static int
dcmd_Handles(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)11410Sstevel@tonic-gate dcmd_Handles(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
11420Sstevel@tonic-gate {
11430Sstevel@tonic-gate 	Rt_map		rtmap;
11440Sstevel@tonic-gate 	char		*str;
11450Sstevel@tonic-gate 	uint_t		flg = 0;
11465892Sab196087 	APlist		apl;
11479131SRod.Evans@Sun.COM 	uintptr_t	datap, nitems;
11488598SRod.Evans@Sun.COM 	Grp_hdl		*ghp;
11490Sstevel@tonic-gate 
11500Sstevel@tonic-gate 	/*
11510Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
11520Sstevel@tonic-gate 	 */
11530Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
11540Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_HANDLES_STR));
11550Sstevel@tonic-gate 		return (DCMD_USAGE);
11560Sstevel@tonic-gate 	}
11570Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
11580Sstevel@tonic-gate 	    &flg, NULL) != argc)
11590Sstevel@tonic-gate 		return (DCMD_USAGE);
11600Sstevel@tonic-gate 
11610Sstevel@tonic-gate 	/*
11620Sstevel@tonic-gate 	 * Read the Rt_map contents.
11630Sstevel@tonic-gate 	 */
11640Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
11650Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
11660Sstevel@tonic-gate 		return (DCMD_ERR);
11670Sstevel@tonic-gate 	}
11680Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
11690Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
11700Sstevel@tonic-gate 		return (DCMD_ERR);
11710Sstevel@tonic-gate 
11720Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_HANDLES_LINE1), str);
11730Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
11740Sstevel@tonic-gate 
11750Sstevel@tonic-gate 	if (HANDLES(&rtmap) == 0)
11760Sstevel@tonic-gate 		return (DCMD_OK);
11770Sstevel@tonic-gate 
11780Sstevel@tonic-gate 	addr = (uintptr_t)HANDLES(&rtmap);
11795892Sab196087 	if (mdb_vread(&apl, sizeof (APlist), addr) == -1) {
11805892Sab196087 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_APLIST),
11815892Sab196087 		    addr);
11820Sstevel@tonic-gate 		return (DCMD_ERR);
11830Sstevel@tonic-gate 	}
11840Sstevel@tonic-gate 
11855892Sab196087 	mdb_printf(MSG_ORIG(MSG_HANDLES_LINE2), addr, (size_t)apl.apl_nitems,
11865892Sab196087 	    (size_t)apl.apl_arritems);
11870Sstevel@tonic-gate 
11885892Sab196087 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (apl.apl_nitems == 0))
11890Sstevel@tonic-gate 		return (DCMD_OK);
11900Sstevel@tonic-gate 
11910Sstevel@tonic-gate 	/*
11925892Sab196087 	 * Under verbose mode print the name of each dependency.  An APlist can
11930Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
11940Sstevel@tonic-gate 	 */
11959131SRod.Evans@Sun.COM 	datap = addr + APLIST_OFF_DATA;
11969131SRod.Evans@Sun.COM 	if (mdb_vread(&ghp, sizeof (Grp_hdl *), datap) == -1) {
11970Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
11989131SRod.Evans@Sun.COM 		    MSG_ORIG(MSG_GRPHDL_STR), datap);
11990Sstevel@tonic-gate 		return (DCMD_ERR);
12000Sstevel@tonic-gate 	}
12010Sstevel@tonic-gate 
120211053SSurya.Prakki@Sun.COM 	(void) mdb_inc_indent(4);
12030Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
12040Sstevel@tonic-gate 
12050Sstevel@tonic-gate 	if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, argv) == DCMD_ERR) {
120611053SSurya.Prakki@Sun.COM 		(void) mdb_dec_indent(4);
12070Sstevel@tonic-gate 		return (DCMD_ERR);
12080Sstevel@tonic-gate 	}
12090Sstevel@tonic-gate 
12109131SRod.Evans@Sun.COM 	nitems = 1;
12119131SRod.Evans@Sun.COM 	for (nitems = 1; nitems < apl.apl_nitems; nitems++) {
12129131SRod.Evans@Sun.COM 		datap += sizeof (void *);
12139131SRod.Evans@Sun.COM 		if (mdb_vread(&ghp, sizeof (Grp_hdl *), datap) == -1) {
12140Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
12159131SRod.Evans@Sun.COM 			    MSG_ORIG(MSG_GRPHDL_STR), datap);
12160Sstevel@tonic-gate 			return (DCMD_ERR);
12170Sstevel@tonic-gate 		}
12180Sstevel@tonic-gate 
12190Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
12200Sstevel@tonic-gate 		if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc,
12210Sstevel@tonic-gate 		    argv) == DCMD_ERR) {
122211053SSurya.Prakki@Sun.COM 			(void) mdb_dec_indent(4);
12230Sstevel@tonic-gate 			return (DCMD_ERR);
12240Sstevel@tonic-gate 		}
12250Sstevel@tonic-gate 	}
122611053SSurya.Prakki@Sun.COM 	(void) mdb_dec_indent(4);
12270Sstevel@tonic-gate 	return (DCMD_OK);
12280Sstevel@tonic-gate }
12290Sstevel@tonic-gate 
12300Sstevel@tonic-gate static void
dcmd_Groups_help(void)12310Sstevel@tonic-gate dcmd_Groups_help(void)
12320Sstevel@tonic-gate {
12330Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GROUPS_HELP));
12340Sstevel@tonic-gate }
12350Sstevel@tonic-gate 
12360Sstevel@tonic-gate 
12370Sstevel@tonic-gate static int
dcmd_Groups(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)12380Sstevel@tonic-gate dcmd_Groups(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
12390Sstevel@tonic-gate {
12400Sstevel@tonic-gate 	Rt_map		rtmap;
12410Sstevel@tonic-gate 	char		*str;
12425892Sab196087 	APlist		apl;
12430Sstevel@tonic-gate 	uint_t		flg = 0;
12449131SRod.Evans@Sun.COM 	uintptr_t	datap, nitems;
12458598SRod.Evans@Sun.COM 	Grp_hdl		*ghp;
12460Sstevel@tonic-gate 
12470Sstevel@tonic-gate 	/*
12480Sstevel@tonic-gate 	 * Insure we have a valid address, and provide for a -v option.
12490Sstevel@tonic-gate 	 */
12500Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0) {
12510Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_NAS), MSG_ORIG(MSG_GROUPS_STR));
12520Sstevel@tonic-gate 		return (DCMD_USAGE);
12530Sstevel@tonic-gate 	}
12540Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, RTLD_FLG_VERBOSE,
12550Sstevel@tonic-gate 	    &flg, NULL) != argc)
12560Sstevel@tonic-gate 		return (DCMD_USAGE);
12570Sstevel@tonic-gate 
12580Sstevel@tonic-gate 	/*
12590Sstevel@tonic-gate 	 * Read the Rt_map contents.
12600Sstevel@tonic-gate 	 */
12610Sstevel@tonic-gate 	if (mdb_vread(&rtmap, sizeof (Rt_map), addr) == -1) {
12620Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_RTMAP_STR), addr);
12630Sstevel@tonic-gate 		return (DCMD_ERR);
12640Sstevel@tonic-gate 	}
12650Sstevel@tonic-gate 	if ((str = String((uintptr_t)NAME(&rtmap),
12660Sstevel@tonic-gate 	    MSG_ORIG(MSG_STR_NAME))) == 0)
12670Sstevel@tonic-gate 		return (DCMD_ERR);
12680Sstevel@tonic-gate 
12690Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_GROUPS_LINE1), str);
12700Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
12710Sstevel@tonic-gate 
12720Sstevel@tonic-gate 	if (GROUPS(&rtmap) == 0)
12730Sstevel@tonic-gate 		return (DCMD_OK);
12740Sstevel@tonic-gate 
12750Sstevel@tonic-gate 	addr = (uintptr_t)GROUPS(&rtmap);
12765892Sab196087 	if (mdb_vread(&apl, sizeof (APlist), addr) == -1) {
12775892Sab196087 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_STR_APLIST),
12785892Sab196087 		    addr);
12794679Srie 		return (DCMD_ERR);
12800Sstevel@tonic-gate 	}
12810Sstevel@tonic-gate 
12825892Sab196087 	mdb_printf(MSG_ORIG(MSG_GROUPS_LINE2), addr, (size_t)apl.apl_nitems,
12835892Sab196087 	    (size_t)apl.apl_arritems);
12840Sstevel@tonic-gate 
12855892Sab196087 	if (((flg & RTLD_FLG_VERBOSE) == 0) || (apl.apl_nitems == 0))
12860Sstevel@tonic-gate 		return (DCMD_OK);
12870Sstevel@tonic-gate 
12880Sstevel@tonic-gate 	/*
12895892Sab196087 	 * Under verbose mode print the name of each dependency.  An APlist can
12900Sstevel@tonic-gate 	 * have a variable number of data items, so read each individual entry.
12910Sstevel@tonic-gate 	 */
12929131SRod.Evans@Sun.COM 	datap = addr + APLIST_OFF_DATA;
12939131SRod.Evans@Sun.COM 	if (mdb_vread(&ghp, sizeof (Grp_hdl *), datap) == -1) {
12940Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ),
12959131SRod.Evans@Sun.COM 		    MSG_ORIG(MSG_GRPHDL_STR), datap);
12960Sstevel@tonic-gate 		return (DCMD_ERR);
12970Sstevel@tonic-gate 	}
12980Sstevel@tonic-gate 
129911053SSurya.Prakki@Sun.COM 	(void) mdb_inc_indent(4);
13000Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_STR_DASHES));
13010Sstevel@tonic-gate 
13020Sstevel@tonic-gate 	if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc, argv) == DCMD_ERR) {
130311053SSurya.Prakki@Sun.COM 		(void) mdb_dec_indent(4);
13040Sstevel@tonic-gate 		return (DCMD_ERR);
13050Sstevel@tonic-gate 	}
13060Sstevel@tonic-gate 
13079131SRod.Evans@Sun.COM 	for (nitems = 1; nitems < apl.apl_nitems; nitems++) {
13089131SRod.Evans@Sun.COM 		datap += sizeof (void *);
13099131SRod.Evans@Sun.COM 		if (mdb_vread(&ghp, sizeof (Grp_hdl *), datap) == -1) {
13100Sstevel@tonic-gate 			mdb_warn(MSG_ORIG(MSG_ERR_READ),
13119131SRod.Evans@Sun.COM 			    MSG_ORIG(MSG_GRPHDL_STR), datap);
13120Sstevel@tonic-gate 			return (DCMD_ERR);
13130Sstevel@tonic-gate 		}
13140Sstevel@tonic-gate 
13150Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_STR_DASHES));
13160Sstevel@tonic-gate 		if (dcmd_GrpHdl((uintptr_t)ghp, flags, argc,
13170Sstevel@tonic-gate 		    argv) == DCMD_ERR) {
131811053SSurya.Prakki@Sun.COM 			(void) mdb_dec_indent(4);
13190Sstevel@tonic-gate 			return (DCMD_ERR);
13200Sstevel@tonic-gate 		}
13210Sstevel@tonic-gate 	}
132211053SSurya.Prakki@Sun.COM 	(void) mdb_dec_indent(4);
13230Sstevel@tonic-gate 	return (DCMD_OK);
13240Sstevel@tonic-gate }
13250Sstevel@tonic-gate static void
dcmd_ElfDyn_help(void)13260Sstevel@tonic-gate dcmd_ElfDyn_help(void)
13270Sstevel@tonic-gate {
13280Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_ELFDYN_HELP));
13290Sstevel@tonic-gate }
13300Sstevel@tonic-gate 
13310Sstevel@tonic-gate static int
13320Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_ElfDyn(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)13330Sstevel@tonic-gate dcmd_ElfDyn(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13340Sstevel@tonic-gate {
13350Sstevel@tonic-gate 	Dyn		dyn;
13360Sstevel@tonic-gate 	const char	*dynstr;
13374734Sab196087 	Conv_inv_buf_t	inv_buf;
13380Sstevel@tonic-gate 
13390Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
13400Sstevel@tonic-gate 		return (DCMD_USAGE);
13410Sstevel@tonic-gate 	if (mdb_vread(&dyn, sizeof (dyn), addr) == -1) {
13420Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_ELFDYN_STR),
13434679Srie 		    addr);
13440Sstevel@tonic-gate 		return (DCMD_ERR);
13450Sstevel@tonic-gate 	}
13460Sstevel@tonic-gate 
13470Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_ELFDYN_TITLE), addr);
13489273SAli.Bahrami@Sun.COM 	dynstr = conv_dyn_tag(dyn.d_tag, ELFOSABI_SOLARIS, M_MACH, 0, &inv_buf);
13490Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_ELFDYN_LINE1), addr, dynstr, dyn.d_un.d_ptr);
13500Sstevel@tonic-gate 
13510Sstevel@tonic-gate 	mdb_set_dot(addr + sizeof (Dyn));
13520Sstevel@tonic-gate 
13530Sstevel@tonic-gate 	return (DCMD_OK);
13540Sstevel@tonic-gate }
13550Sstevel@tonic-gate 
13560Sstevel@tonic-gate static void
dcmd_ElfEhdr_help(void)13570Sstevel@tonic-gate dcmd_ElfEhdr_help(void)
13580Sstevel@tonic-gate {
13590Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_HELP));
13600Sstevel@tonic-gate }
13610Sstevel@tonic-gate 
13620Sstevel@tonic-gate static int
13630Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_ElfEhdr(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)13640Sstevel@tonic-gate dcmd_ElfEhdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13650Sstevel@tonic-gate {
13664734Sab196087 	Ehdr			ehdr;
13674734Sab196087 	Byte			*byte;
13684734Sab196087 	const char		*flgs;
13694734Sab196087 	Conv_inv_buf_t		inv_buf1, inv_buf2;
13704734Sab196087 	Conv_ehdr_flags_buf_t	ehdr_flags_buf;
13714734Sab196087 
13720Sstevel@tonic-gate 
13730Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
13740Sstevel@tonic-gate 		return (DCMD_USAGE);
13750Sstevel@tonic-gate 
13760Sstevel@tonic-gate 	if (mdb_vread(&ehdr, sizeof (ehdr), addr) == -1) {
13770Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_EHDR_STR),
13784679Srie 		    addr);
13790Sstevel@tonic-gate 		return (DCMD_ERR);
13800Sstevel@tonic-gate 	}
13810Sstevel@tonic-gate 
13820Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_TITLE), addr);
13830Sstevel@tonic-gate 	byte = &ehdr.e_ident[0];
13840Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE1), byte[EI_MAG0],
13850Sstevel@tonic-gate 	    (byte[EI_MAG1] ? byte[EI_MAG1] : '0'),
13860Sstevel@tonic-gate 	    (byte[EI_MAG2] ? byte[EI_MAG2] : '0'),
13870Sstevel@tonic-gate 	    (byte[EI_MAG3] ? byte[EI_MAG3] : '0'));
13880Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE2),
13894734Sab196087 	    conv_ehdr_class(ehdr.e_ident[EI_CLASS], 0, &inv_buf1),
13904734Sab196087 	    conv_ehdr_data(ehdr.e_ident[EI_DATA], 0, &inv_buf2));
13910Sstevel@tonic-gate 
13920Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE3),
13934734Sab196087 	    conv_ehdr_mach(ehdr.e_machine, 0, &inv_buf1),
13944734Sab196087 	    conv_ehdr_vers(ehdr.e_version, 0, &inv_buf2));
13954734Sab196087 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE4),
13969273SAli.Bahrami@Sun.COM 	    conv_ehdr_type(ehdr.e_ident[EI_OSABI], ehdr.e_type, 0, &inv_buf1));
13970Sstevel@tonic-gate 
13980Sstevel@tonic-gate 	/*
13991976Sab196087 	 * Line up the flags differently depending on whether we
14001976Sab196087 	 * received a numeric (e.g. "0x200") or text representation
14011976Sab196087 	 * (e.g. "[ EF_SPARC_SUN_US1 ]").
14020Sstevel@tonic-gate 	 */
14035088Sab196087 	flgs = conv_ehdr_flags(ehdr.e_machine, ehdr.e_flags,
14045088Sab196087 	    0, &ehdr_flags_buf);
14050Sstevel@tonic-gate 	if (flgs[0] == '[')
14060Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_EHDR_LINE5), flgs);
14070Sstevel@tonic-gate 	else
14080Sstevel@tonic-gate 		mdb_printf(MSG_ORIG(MSG_EHDR_LINE6), flgs);
14090Sstevel@tonic-gate 
14100Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE7), ehdr.e_entry, ehdr.e_ehsize,
14110Sstevel@tonic-gate 	    ehdr.e_shstrndx);
14120Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE8), ehdr.e_shoff, ehdr.e_shentsize,
14130Sstevel@tonic-gate 	    ehdr.e_shnum);
14140Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EHDR_LINE9), ehdr.e_phoff, ehdr.e_phentsize,
14150Sstevel@tonic-gate 	    ehdr.e_phnum);
14160Sstevel@tonic-gate 
14170Sstevel@tonic-gate 	mdb_set_dot(addr + sizeof (Ehdr));
14180Sstevel@tonic-gate 
14190Sstevel@tonic-gate 	return (DCMD_OK);
14200Sstevel@tonic-gate }
14210Sstevel@tonic-gate 
14220Sstevel@tonic-gate static void
dcmd_ElfPhdr_help(void)14230Sstevel@tonic-gate dcmd_ElfPhdr_help(void)
14240Sstevel@tonic-gate {
14250Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_HELP));
14260Sstevel@tonic-gate }
14270Sstevel@tonic-gate 
14280Sstevel@tonic-gate static int
14290Sstevel@tonic-gate /* ARGSUSED2 */
dcmd_ElfPhdr(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)14300Sstevel@tonic-gate dcmd_ElfPhdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
14310Sstevel@tonic-gate {
14324734Sab196087 	Phdr			phdr;
14334734Sab196087 	Conv_inv_buf_t		inv_buf;
14344734Sab196087 	Conv_phdr_flags_buf_t	phdr_flags_buf;
14350Sstevel@tonic-gate 
14360Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
14370Sstevel@tonic-gate 		return (DCMD_USAGE);
14380Sstevel@tonic-gate 
14390Sstevel@tonic-gate 	if (mdb_vread(&phdr, sizeof (phdr), addr) == -1) {
14400Sstevel@tonic-gate 		mdb_warn(MSG_ORIG(MSG_ERR_READ), MSG_ORIG(MSG_EPHDR_STR),
14414679Srie 		    addr);
14420Sstevel@tonic-gate 		return (DCMD_ERR);
14430Sstevel@tonic-gate 	}
14440Sstevel@tonic-gate 
14450Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_TITLE), addr);
14460Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE1), phdr.p_vaddr,
14479273SAli.Bahrami@Sun.COM 	    conv_phdr_flags(ELFOSABI_SOLARIS, phdr.p_flags, 0,
14489273SAli.Bahrami@Sun.COM 	    &phdr_flags_buf));
14490Sstevel@tonic-gate 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE2), phdr.p_paddr,
14509273SAli.Bahrami@Sun.COM 	    conv_phdr_type(ELFOSABI_SOLARIS, M_MACH, phdr.p_type, 0, &inv_buf));
14511618Srie 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE3), phdr.p_filesz, phdr.p_memsz);
14521618Srie 	mdb_printf(MSG_ORIG(MSG_EPHDR_LINE4), phdr.p_offset, phdr.p_align);
14530Sstevel@tonic-gate 
14540Sstevel@tonic-gate 	mdb_set_dot(addr + sizeof (Phdr));
14550Sstevel@tonic-gate 
14560Sstevel@tonic-gate 	return (DCMD_OK);
14570Sstevel@tonic-gate }
14580Sstevel@tonic-gate 
14590Sstevel@tonic-gate 
14600Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
14610Sstevel@tonic-gate 	{ MSG_ORIG(MSG_BND_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14620Sstevel@tonic-gate 		MSG_ORIG(MSG_BND_DCD),
14630Sstevel@tonic-gate 		dcmd_Bind, dcmd_Bind_help},
14640Sstevel@tonic-gate 	{ MSG_ORIG(MSG_DEPENDS_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14650Sstevel@tonic-gate 		MSG_ORIG(MSG_DEPENDS_DCD),
14660Sstevel@tonic-gate 		dcmd_Depends, dcmd_Depends_help},
14670Sstevel@tonic-gate 	{ MSG_ORIG(MSG_CALLERS_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14680Sstevel@tonic-gate 		MSG_ORIG(MSG_CALLERS_DCD),
14690Sstevel@tonic-gate 		dcmd_Callers, dcmd_Callers_help},
14700Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GRPHDL_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14710Sstevel@tonic-gate 		MSG_ORIG(MSG_GRPHDL_DCD),
14720Sstevel@tonic-gate 		dcmd_GrpHdl, dcmd_GrpHdl_help},
14730Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GRPDESC_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14740Sstevel@tonic-gate 		MSG_ORIG(MSG_GRPDESC_DCD),
14750Sstevel@tonic-gate 		dcmd_GrpDesc, dcmd_GrpDesc_help},
14760Sstevel@tonic-gate 	{ MSG_ORIG(MSG_HANDLES_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14770Sstevel@tonic-gate 		MSG_ORIG(MSG_HANDLES_DCD),
14780Sstevel@tonic-gate 		dcmd_Handles, dcmd_Handles_help},
14790Sstevel@tonic-gate 	{ MSG_ORIG(MSG_GROUPS_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14800Sstevel@tonic-gate 		MSG_ORIG(MSG_GROUPS_DCD),
14810Sstevel@tonic-gate 		dcmd_Groups, dcmd_Groups_help},
14820Sstevel@tonic-gate 	{ MSG_ORIG(MSG_ELFDYN_STR), MSG_ORIG(MSG_USG_ADDREQ),
14830Sstevel@tonic-gate 		MSG_ORIG(MSG_ELFDYN_DCD),
14840Sstevel@tonic-gate 		dcmd_ElfDyn, dcmd_ElfDyn_help},
14850Sstevel@tonic-gate 	{ MSG_ORIG(MSG_EHDR_STR), MSG_ORIG(MSG_USG_ADDREQ),
14860Sstevel@tonic-gate 		MSG_ORIG(MSG_EHDR_DCD),
14870Sstevel@tonic-gate 		dcmd_ElfEhdr, dcmd_ElfEhdr_help},
14880Sstevel@tonic-gate 	{ MSG_ORIG(MSG_EPHDR_STR), MSG_ORIG(MSG_USG_ADDREQ),
14890Sstevel@tonic-gate 		MSG_ORIG(MSG_EPHDR_DCD),
14900Sstevel@tonic-gate 		dcmd_ElfPhdr, dcmd_ElfPhdr_help},
14910Sstevel@tonic-gate 	{ MSG_ORIG(MSG_LMLIST_STR), MSG_ORIG(MSG_USG_ADDREQ_V),
14920Sstevel@tonic-gate 		MSG_ORIG(MSG_LMLIST_DCD),
14930Sstevel@tonic-gate 		dcmd_Lm_list, dcmd_Lm_list_help},
14940Sstevel@tonic-gate 	{ MSG_ORIG(MSG_RTMAPS_STR), MSG_ORIG(MSG_USG_ADDOPT_V),
14950Sstevel@tonic-gate 		MSG_ORIG(MSG_RTMAPS_DCD),
14960Sstevel@tonic-gate 		dcmd_Rtmaps, dcmd_Rtmaps_help},
14970Sstevel@tonic-gate 	{ MSG_ORIG(MSG_RTMAP_STR), MSG_ORIG(MSG_USG_ADDREQ),
14980Sstevel@tonic-gate 		MSG_ORIG(MSG_RTMAP_DCD),
14990Sstevel@tonic-gate 		dcmd_rtmap, dcmd_rtmap_help},
15000Sstevel@tonic-gate 	{ MSG_ORIG(MSG_SETENV_STR), MSG_ORIG(MSG_USG_SETENV),
15010Sstevel@tonic-gate 		MSG_ORIG(MSG_SETENV_DCD),
15020Sstevel@tonic-gate 		dcmd_Setenv, dcmd_Setenv_help},
15030Sstevel@tonic-gate 	{ NULL }
15040Sstevel@tonic-gate };
15050Sstevel@tonic-gate 
15060Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
15070Sstevel@tonic-gate 	{ MSG_ORIG(MSG_RTMAPS_STR), MSG_ORIG(MSG_WWD_RTMAP),
15080Sstevel@tonic-gate 		walk_rtmap_init, walk_rtmap_step, NULL, NULL },
15090Sstevel@tonic-gate 	{ NULL }
15100Sstevel@tonic-gate };
15110Sstevel@tonic-gate 
15120Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
15130Sstevel@tonic-gate 	MDB_API_VERSION, dcmds, walkers
15140Sstevel@tonic-gate };
15150Sstevel@tonic-gate 
15160Sstevel@tonic-gate const	mdb_modinfo_t *
_mdb_init(void)15170Sstevel@tonic-gate _mdb_init(void)
15180Sstevel@tonic-gate {
15190Sstevel@tonic-gate 	return (&modinfo);
15200Sstevel@tonic-gate }
1521