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  */
21685Srie 
220Sstevel@tonic-gate /*
2312254SAli.Bahrami@Oracle.COM  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
266Srie #include	<sys/auxv.h>
270Sstevel@tonic-gate #include	<string.h>
280Sstevel@tonic-gate #include	<unistd.h>
290Sstevel@tonic-gate #include	<fcntl.h>
300Sstevel@tonic-gate #include	<limits.h>
310Sstevel@tonic-gate #include	<stdio.h>
321618Srie #include	<libld.h>
331618Srie #include	<rtld.h>
341618Srie #include	<conv.h>
350Sstevel@tonic-gate #include	"msg.h"
360Sstevel@tonic-gate #include	"_debug.h"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate void
391618Srie Dbg_file_analyze(Rt_map *lmp)
400Sstevel@tonic-gate {
414734Sab196087 	Conv_dl_mode_buf_t	dl_mode_buf;
424734Sab196087 	Lm_list			*lml = LIST(lmp);
431618Srie 
441618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
450Sstevel@tonic-gate 		return;
460Sstevel@tonic-gate 
471618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
481618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ANALYZE), NAME(lmp),
494734Sab196087 	    conv_dl_mode(MODE(lmp), 1, &dl_mode_buf));
500Sstevel@tonic-gate }
510Sstevel@tonic-gate 
520Sstevel@tonic-gate void
538598SRod.Evans@Sun.COM Dbg_file_mmapobj(Lm_list *lml, const char *name, mmapobj_result_t *ompp,
548598SRod.Evans@Sun.COM     uint_t onum)
558598SRod.Evans@Sun.COM {
568598SRod.Evans@Sun.COM 	mmapobj_result_t	*mpp;
578598SRod.Evans@Sun.COM 	uint_t			mnum;
588598SRod.Evans@Sun.COM 
598598SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_FILES))
608598SRod.Evans@Sun.COM 		return;
618598SRod.Evans@Sun.COM 	if (DBG_NOTDETAIL())
628598SRod.Evans@Sun.COM 		return;
638598SRod.Evans@Sun.COM 
648598SRod.Evans@Sun.COM 	Dbg_util_nl(lml, DBG_NL_STD);
658598SRod.Evans@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_FIL_MMAPOBJ), name, onum);
668598SRod.Evans@Sun.COM 
678598SRod.Evans@Sun.COM 	for (mnum = 0, mpp = ompp; mnum < onum; mnum++, mpp++) {
688598SRod.Evans@Sun.COM 		const char	*str;
698598SRod.Evans@Sun.COM 		uint_t		type = MR_GET_TYPE(mpp->mr_flags);
708598SRod.Evans@Sun.COM 
718598SRod.Evans@Sun.COM 		if (type == MR_PADDING)
728598SRod.Evans@Sun.COM 			str = MSG_ORIG(MSG_MR_PADDING);
738598SRod.Evans@Sun.COM 		else if (type == MR_HDR_ELF)
748598SRod.Evans@Sun.COM 			str = MSG_ORIG(MSG_MR_HDR_ELF);
758598SRod.Evans@Sun.COM 		else if (type == MR_HDR_AOUT)
768598SRod.Evans@Sun.COM 			str = MSG_ORIG(MSG_MR_HDR_AOUT);
778598SRod.Evans@Sun.COM 		else
788598SRod.Evans@Sun.COM 			str = MSG_ORIG(MSG_STR_EMPTY);
798598SRod.Evans@Sun.COM 
808598SRod.Evans@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_FIL_MMAPOBJ_1), mnum,
818598SRod.Evans@Sun.COM 		    EC_NATPTR(mpp->mr_addr), EC_OFF(mpp->mr_fsize), str);
828598SRod.Evans@Sun.COM 		dbg_print(lml, MSG_INTL(MSG_FIL_MMAPOBJ_2),
838598SRod.Evans@Sun.COM 		    EC_OFF(mpp->mr_offset), EC_OFF(mpp->mr_msize));
848598SRod.Evans@Sun.COM 	}
858598SRod.Evans@Sun.COM 	Dbg_util_nl(lml, DBG_NL_STD);
868598SRod.Evans@Sun.COM }
878598SRod.Evans@Sun.COM 
888598SRod.Evans@Sun.COM void
898598SRod.Evans@Sun.COM Dbg_file_aout(Lm_list *lml, const char *name, Addr addr, size_t size,
908598SRod.Evans@Sun.COM     const char *lmid, Aliste lmco)
910Sstevel@tonic-gate {
921618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
930Sstevel@tonic-gate 		return;
940Sstevel@tonic-gate 
951618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_AOUT), name);
968598SRod.Evans@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_AS), EC_ADDR(addr), EC_OFF(size));
971618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
980Sstevel@tonic-gate }
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate void
1018598SRod.Evans@Sun.COM Dbg_file_elf(Lm_list *lml, const char *name, Addr addr, size_t size,
1028598SRod.Evans@Sun.COM     const char *lmid, Aliste lmco)
1030Sstevel@tonic-gate {
1040Sstevel@tonic-gate 	const char	*str;
1050Sstevel@tonic-gate 
1061618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1070Sstevel@tonic-gate 		return;
1080Sstevel@tonic-gate 
1098598SRod.Evans@Sun.COM 	if (addr == 0)
1100Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_TEMPORARY);
1110Sstevel@tonic-gate 	else
1120Sstevel@tonic-gate 		str = MSG_ORIG(MSG_STR_EMPTY);
1130Sstevel@tonic-gate 
1141618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ELF), name, str);
1158598SRod.Evans@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_AS), EC_ADDR(addr), EC_OFF(size));
1161618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate void
1201618Srie Dbg_file_ldso(Rt_map *lmp, char **envp, auxv_t *auxv, const char *lmid,
1211618Srie     Aliste lmco)
1220Sstevel@tonic-gate {
1231618Srie 	Lm_list	*lml = LIST(lmp);
1241618Srie 
1251618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1260Sstevel@tonic-gate 		return;
1270Sstevel@tonic-gate 
1281618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1291618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_LDSO), PATHNAME(lmp));
1308598SRod.Evans@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_AS), EC_ADDR(ADDR(lmp)),
1318598SRod.Evans@Sun.COM 	    EC_OFF(MSIZE(lmp)));
1321618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_EA), EC_NATPTR(envp),
1331618Srie 	    EC_NATPTR(auxv));
1341618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
1351618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1361618Srie }
1371618Srie 
1381618Srie 
1391618Srie void
1401618Srie Dbg_file_prot(Rt_map *lmp, int prot)
1411618Srie {
1421618Srie 	Lm_list	*lml = LIST(lmp);
1431618Srie 
1441618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1451618Srie 		return;
1461618Srie 
1471618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1481618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PROT), NAME(lmp), (prot ? '+' : '-'));
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate void
1521618Srie Dbg_file_delete(Rt_map *lmp)
1530Sstevel@tonic-gate {
1541618Srie 	Lm_list	*lml = LIST(lmp);
1551618Srie 
1561618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1570Sstevel@tonic-gate 		return;
1580Sstevel@tonic-gate 
1591618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1601618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DELETE), NAME(lmp));
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate static int	hdl_title = 0;
1640Sstevel@tonic-gate static Msg	hdl_str = 0;
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate void
1670Sstevel@tonic-gate Dbg_file_hdl_title(int type)
1680Sstevel@tonic-gate {
1695067Srie 	static const Msg titles[] = {
1705067Srie 		MSG_FIL_HDL_CREATE,	/* MSG_INTL(MSG_FIL_HDL_CREATE) */
1715067Srie 		MSG_FIL_HDL_ADD,	/* MSG_INTL(MSG_FIL_HDL_ADD) */
1725067Srie 		MSG_FIL_HDL_DELETE,	/* MSG_INTL(MSG_FIL_HDL_DELETE) */
1735067Srie 		MSG_FIL_HDL_ORPHAN,	/* MSG_INTL(MSG_FIL_HDL_ORPHAN) */
1745067Srie 		MSG_FIL_HDL_REINST,	/* MSG_INTL(MSG_FIL_HDL_REINST) */
1755067Srie 	};
1765067Srie 
1771618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1780Sstevel@tonic-gate 		return;
1790Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1800Sstevel@tonic-gate 		return;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 	/*
1835067Srie 	 * Establish a binding title for later use in Dbg_file_hdl_action.
1840Sstevel@tonic-gate 	 */
1855067Srie 	if (type <= DBG_HDL_REINST) {
1865067Srie 		hdl_str = titles[type];
1875067Srie 		hdl_title = 1;
1885067Srie 	} else {
1894734Sab196087 		hdl_str = 0;
1905067Srie 		hdl_title = 0;
1913731Srie 	}
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate void
1951618Srie Dbg_file_hdl_collect(Grp_hdl *ghp, const char *name)
1960Sstevel@tonic-gate {
1974734Sab196087 	Conv_grphdl_flags_buf_t	grphdl_flags_buf;
1981618Srie 	Lm_list		*lml = ghp->gh_ownlml;
1991618Srie 	const char	*str;
2000Sstevel@tonic-gate 
2011618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
2020Sstevel@tonic-gate 		return;
2030Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
2040Sstevel@tonic-gate 		return;
2050Sstevel@tonic-gate 
2061618Srie 	if (ghp->gh_ownlmp)
2071618Srie 		str = NAME(ghp->gh_ownlmp);
2080Sstevel@tonic-gate 	else
2090Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_ORPHAN);
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate 	if (hdl_title) {
2120Sstevel@tonic-gate 		hdl_title = 0;
2131618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
2140Sstevel@tonic-gate 	}
2150Sstevel@tonic-gate 	if (name)
2161618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_RETAIN), str, name);
2170Sstevel@tonic-gate 	else
2181618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_COLLECT), str,
2194734Sab196087 		    conv_grphdl_flags(ghp->gh_flags, &grphdl_flags_buf));
2200Sstevel@tonic-gate }
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate void
2233731Srie Dbg_file_hdl_action(Grp_hdl *ghp, Rt_map *lmp, int type, uint_t flags)
2240Sstevel@tonic-gate {
2254734Sab196087 	Conv_grpdesc_flags_buf_t grpdesc_flags_buf;
2263731Srie 	const char	*mode, *group;
2273731Srie 	Lm_list		*lml = LIST(lmp);
2283731Srie 	Msg		str;
2290Sstevel@tonic-gate 
2305067Srie 	static const Msg fmt[] = {
2315067Srie 		MSG_FIL_DEP_ADD,	/* MSG_INTL(MSG_FIL_DEP_ADD) */
2325067Srie 		MSG_FIL_DEP_UPDATE,	/* MSG_INTL(MSG_FIL_DEP_UPDATE) */
2335067Srie 		MSG_FIL_DEP_DELETE,	/* MSG_INTL(MSG_FIL_DEP_DELETE) */
2345067Srie 		MSG_FIL_DEP_REMOVE,	/* MSG_INTL(MSG_FIL_DEP_REMOVE) */
2355067Srie 		MSG_FIL_DEP_REMAIN,	/* MSG_INTL(MSG_FIL_DEP_REMAIN) */
2365067Srie 		MSG_FIL_DEP_ORPHAN,	/* MSG_INTL(MSG_FIL_DEP_ORPHAN) */
2375067Srie 		MSG_FIL_DEP_REINST,	/* MSG_INTL(MSG_FIL_DEP_REINST) */
2385067Srie 	};
2391618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
2400Sstevel@tonic-gate 		return;
2410Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
2420Sstevel@tonic-gate 		return;
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	if (hdl_title) {
2451618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
2460Sstevel@tonic-gate 		if (hdl_str) {
2479577SRod.Evans@Sun.COM 			Conv_grphdl_flags_buf_t grphdl_flags_buf;
2480Sstevel@tonic-gate 			const char	*name;
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 			/*
2510Sstevel@tonic-gate 			 * Protect ourselves in case this handle has no
2520Sstevel@tonic-gate 			 * originating owner.
2530Sstevel@tonic-gate 			 */
2541618Srie 			if (ghp->gh_ownlmp)
2551618Srie 				name = NAME(ghp->gh_ownlmp);
2560Sstevel@tonic-gate 			else
2570Sstevel@tonic-gate 				name = MSG_INTL(MSG_STR_UNKNOWN);
2580Sstevel@tonic-gate 
2599577SRod.Evans@Sun.COM 			dbg_print(lml, MSG_INTL(hdl_str), name,
2609577SRod.Evans@Sun.COM 			    conv_grphdl_flags(ghp->gh_flags, &grphdl_flags_buf),
2619577SRod.Evans@Sun.COM 			    EC_NATPTR(ghp));
2620Sstevel@tonic-gate 		}
2630Sstevel@tonic-gate 		hdl_title = 0;
2640Sstevel@tonic-gate 	}
2650Sstevel@tonic-gate 
2664734Sab196087 	/*
2675067Srie 	 * Establish a binding descriptor format string.
2684734Sab196087 	 */
2695067Srie 	if (type > DBG_DEP_REINST)
2704734Sab196087 		return;
2710Sstevel@tonic-gate 
2725067Srie 	str = fmt[type];
2735067Srie 
2745067Srie 	if (((type == DBG_DEP_ADD) || (type == DBG_DEP_UPDATE)) && flags)
2754734Sab196087 		group = conv_grpdesc_flags(flags, &grpdesc_flags_buf);
2763731Srie 	else
2773731Srie 		group = MSG_ORIG(MSG_STR_EMPTY);
2780Sstevel@tonic-gate 
2793731Srie 	if ((MODE(lmp) & (RTLD_GLOBAL | RTLD_NODELETE)) ==
2803731Srie 	    (RTLD_GLOBAL | RTLD_NODELETE))
2813731Srie 		mode = MSG_ORIG(MSG_MODE_GLOBNODEL);
2823731Srie 	else if (MODE(lmp) & RTLD_GLOBAL)
2833731Srie 		mode = MSG_ORIG(MSG_MODE_GLOB);
2843731Srie 	else if (MODE(lmp) & RTLD_NODELETE)
2853731Srie 		mode = MSG_ORIG(MSG_MODE_NODEL);
2863731Srie 	else
2873731Srie 		mode = MSG_ORIG(MSG_STR_EMPTY);
2883731Srie 
2893731Srie 	dbg_print(lml, MSG_INTL(str), NAME(lmp), mode, group);
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate void
2931618Srie Dbg_file_bind_entry(Lm_list *lml, Bnd_desc *bdp)
2940Sstevel@tonic-gate {
2954734Sab196087 	Conv_bnd_type_buf_t bnd_type_buf;
2964734Sab196087 
2971618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
2980Sstevel@tonic-gate 		return;
2990Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
3000Sstevel@tonic-gate 		return;
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	/*
3030Sstevel@tonic-gate 	 * Print the dependency together with the modes of the binding.
3040Sstevel@tonic-gate 	 */
3051618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3061618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_ADD), NAME(bdp->b_caller));
3071618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE), NAME(bdp->b_depend),
3084734Sab196087 	    conv_bnd_type(bdp->b_flags, &bnd_type_buf));
309280Srie }
310280Srie 
311280Srie void
3121618Srie Dbg_file_bindings(Rt_map *lmp, int flag)
313280Srie {
3144734Sab196087 	Conv_bnd_obj_buf_t	bnd_obj_buf;
3154734Sab196087 	Conv_bnd_type_buf_t	bnd_type_buf;
316280Srie 	const char	*str;
317280Srie 	Rt_map		*tlmp;
3181618Srie 	Lm_list		*lml = LIST(lmp);
319280Srie 	int		next = 0;
320280Srie 
3211618Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
322280Srie 		return;
323280Srie 	if (DBG_NOTDETAIL())
324280Srie 		return;
325280Srie 
326280Srie 	if (flag & RT_SORT_REV)
327280Srie 		str = MSG_ORIG(MSG_SCN_INIT);
328280Srie 	else
329280Srie 		str = MSG_ORIG(MSG_SCN_FINI);
330280Srie 
3311618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3321618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DEP_TITLE), str,
3334734Sab196087 	    conv_bnd_obj(lml->lm_flags, &bnd_obj_buf));
334280Srie 
335280Srie 	/* LINTED */
336280Srie 	for (tlmp = lmp; tlmp; tlmp = (Rt_map *)NEXT(tlmp)) {
3375892Sab196087 		Bnd_desc	*bdp;
3385892Sab196087 		Aliste		idx;
339280Srie 
340280Srie 		/*
341280Srie 		 * For .init processing, only collect objects that have been
342280Srie 		 * relocated and haven't already been collected.
343280Srie 		 * For .fini processing, only collect objects that have had
344280Srie 		 * their .init collected, and haven't already been .fini
345280Srie 		 * collected.
346280Srie 		 */
347280Srie 		if (flag & RT_SORT_REV) {
348280Srie 			if ((FLAGS(tlmp) & (FLG_RT_RELOCED |
349280Srie 			    FLG_RT_INITCLCT)) != FLG_RT_RELOCED)
350280Srie 				continue;
351280Srie 
352280Srie 		} else {
353280Srie 			if ((flag & RT_SORT_DELETE) &&
354280Srie 			    ((FLAGS(tlmp) & FLG_RT_DELETE) == 0))
355280Srie 				continue;
356280Srie 			if (((FLAGS(tlmp) &
357280Srie 			    (FLG_RT_INITCLCT | FLG_RT_FINICLCT)) ==
358280Srie 			    FLG_RT_INITCLCT) == 0)
359280Srie 				continue;
360280Srie 		}
361280Srie 
362280Srie 		if (next++)
3631618Srie 			Dbg_util_nl(lml, DBG_NL_STD);
364280Srie 
3655892Sab196087 		if (DEPENDS(tlmp) == NULL)
3661618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_NONE), NAME(tlmp));
367280Srie 		else {
3681618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_ENT), NAME(tlmp));
369280Srie 
3705892Sab196087 			for (APLIST_TRAVERSE(DEPENDS(tlmp), idx, bdp)) {
3711618Srie 				dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE),
3725892Sab196087 				    NAME(bdp->b_depend),
3735892Sab196087 				    conv_bnd_type(bdp->b_flags,
3744734Sab196087 				    &bnd_type_buf));
375280Srie 			}
376280Srie 		}
377280Srie 	}
3781618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate 
3810Sstevel@tonic-gate void
38211690SAli.Bahrami@Sun.COM Dbg_file_bindings_done(Lm_list *lml)
38311690SAli.Bahrami@Sun.COM {
38411690SAli.Bahrami@Sun.COM 	if (DBG_NOTCLASS(DBG_C_INIT))
38511690SAli.Bahrami@Sun.COM 		return;
38611690SAli.Bahrami@Sun.COM 	if (DBG_NOTDETAIL())
38711690SAli.Bahrami@Sun.COM 		return;
38811690SAli.Bahrami@Sun.COM 
38911690SAli.Bahrami@Sun.COM 	DBG_CALL(Dbg_util_nl(lml, DBG_NL_STD));
39011690SAli.Bahrami@Sun.COM }
39111690SAli.Bahrami@Sun.COM 
39211690SAli.Bahrami@Sun.COM void
3931618Srie Dbg_file_lazyload(Rt_map *clmp, const char *fname, const char *sname)
3940Sstevel@tonic-gate {
3951618Srie 	Lm_list	*lml = LIST(clmp);
3961618Srie 
3971618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3980Sstevel@tonic-gate 		return;
3990Sstevel@tonic-gate 
4001618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4011618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_LAZYLOAD), fname, NAME(clmp),
4021618Srie 	    Dbg_demangle_name(sname));
4030Sstevel@tonic-gate }
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate void
4061618Srie Dbg_file_preload(Lm_list *lml, const char *name)
4070Sstevel@tonic-gate {
4081618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4090Sstevel@tonic-gate 		return;
4100Sstevel@tonic-gate 
4111618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4121618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PRELOAD), name);
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate void
4161618Srie Dbg_file_needed(Rt_map *lmp, const char *name)
4170Sstevel@tonic-gate {
4181618Srie 	Lm_list	*lml = LIST(lmp);
4191618Srie 
4201618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4210Sstevel@tonic-gate 		return;
4220Sstevel@tonic-gate 
4231618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4241618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_NEEDED), name, NAME(lmp));
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate void
4281618Srie Dbg_file_filter(Lm_list *lml, const char *filter, const char *filtee,
4291618Srie     int config)
4300Sstevel@tonic-gate {
4311618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4320Sstevel@tonic-gate 		return;
4330Sstevel@tonic-gate 
4341618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4350Sstevel@tonic-gate 	if (config)
4361618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_1), filter, filtee);
4370Sstevel@tonic-gate 	else
4381618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_2), filter, filtee);
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate void
4421618Srie Dbg_file_filtee(Lm_list *lml, const char *filter, const char *filtee, int audit)
4430Sstevel@tonic-gate {
4440Sstevel@tonic-gate 	if (audit) {
4451618Srie 		if (DBG_NOTCLASS(DBG_C_AUDITING | DBG_C_FILES))
4460Sstevel@tonic-gate 			return;
4470Sstevel@tonic-gate 
4481618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
4491618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_3), filtee);
4500Sstevel@tonic-gate 	} else {
4511618Srie 		if (DBG_NOTCLASS(DBG_C_FILES))
4520Sstevel@tonic-gate 			return;
4530Sstevel@tonic-gate 
4541618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
4550Sstevel@tonic-gate 		if (filter)
4561618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_1), filtee,
4571618Srie 			    filter);
4580Sstevel@tonic-gate 		else
4591618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_2), filtee);
4600Sstevel@tonic-gate 	}
4610Sstevel@tonic-gate }
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate void
4641618Srie Dbg_file_fixname(Lm_list *lml, const char *oname, const char *nname)
4650Sstevel@tonic-gate {
4661618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4670Sstevel@tonic-gate 		return;
4680Sstevel@tonic-gate 
4691618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4701618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_FIXNAME), oname, nname);
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate void
4740Sstevel@tonic-gate Dbg_file_output(Ofl_desc *ofl)
4750Sstevel@tonic-gate {
4760Sstevel@tonic-gate 	const char	*prefix = MSG_ORIG(MSG_PTH_OBJECT);
4770Sstevel@tonic-gate 	char		*oname, *nname, *ofile;
4780Sstevel@tonic-gate 	int		fd;
4790Sstevel@tonic-gate 
4801618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4810Sstevel@tonic-gate 		return;
4820Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
4830Sstevel@tonic-gate 		return;
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 	/*
4860Sstevel@tonic-gate 	 * Obtain the present input object filename for concatenation to the
4870Sstevel@tonic-gate 	 * prefix name.
4880Sstevel@tonic-gate 	 */
4890Sstevel@tonic-gate 	oname = (char *)ofl->ofl_name;
4900Sstevel@tonic-gate 	if ((ofile = strrchr(oname, '/')) == NULL)
4910Sstevel@tonic-gate 		ofile = oname;
4920Sstevel@tonic-gate 	else
4930Sstevel@tonic-gate 		ofile++;
4940Sstevel@tonic-gate 
4950Sstevel@tonic-gate 	/*
4960Sstevel@tonic-gate 	 * Concatenate the prefix with the object filename, open the file and
4970Sstevel@tonic-gate 	 * write out the present Elf memory image.  As this is debugging we
4980Sstevel@tonic-gate 	 * ignore all errors.
4990Sstevel@tonic-gate 	 */
5001618Srie 	if ((nname = malloc(strlen(prefix) + strlen(ofile) + 1)) != 0) {
5010Sstevel@tonic-gate 		(void) strcpy(nname, prefix);
5020Sstevel@tonic-gate 		(void) strcat(nname, ofile);
5030Sstevel@tonic-gate 		if ((fd = open(nname, O_RDWR | O_CREAT | O_TRUNC,
5040Sstevel@tonic-gate 		    0666)) != -1) {
5051618Srie 			(void) write(fd, ofl->ofl_nehdr, ofl->ofl_size);
5061618Srie 			(void) close(fd);
5070Sstevel@tonic-gate 		}
5080Sstevel@tonic-gate 		free(nname);
5090Sstevel@tonic-gate 	}
5100Sstevel@tonic-gate }
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate void
5131618Srie Dbg_file_config_dis(Lm_list *lml, const char *config, int features)
5140Sstevel@tonic-gate {
5154734Sab196087 	Conv_config_feat_buf_t	config_feat_buf;
5164734Sab196087 	const char		*str;
5170Sstevel@tonic-gate 
51811827SRod.Evans@Sun.COM 	if (features == 0)
51911827SRod.Evans@Sun.COM 		return;
52011827SRod.Evans@Sun.COM 
5211976Sab196087 	switch (features & ~CONF_FEATMSK) {
5221976Sab196087 	case DBG_CONF_IGNORE:
5230Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_1);
5241976Sab196087 		break;
5251976Sab196087 	case DBG_CONF_VERSION:
5260Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_2);
5271976Sab196087 		break;
5281976Sab196087 	case DBG_CONF_PRCFAIL:
5290Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_3);
5301976Sab196087 		break;
5311976Sab196087 	case DBG_CONF_CORRUPT:
5320Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_4);
5331976Sab196087 		break;
5341976Sab196087 	case DBG_CONF_ABIMISMATCH:
5351976Sab196087 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_5);
5361976Sab196087 		break;
5371976Sab196087 	default:
5384734Sab196087 		str = conv_config_feat(features, &config_feat_buf);
5391976Sab196087 		break;
5401976Sab196087 	}
5410Sstevel@tonic-gate 
5421618Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
5431618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG_ERR), config, str);
5441618Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate void
5481618Srie Dbg_file_config_obj(Lm_list *lml, const char *dir, const char *file,
5491618Srie     const char *config)
5500Sstevel@tonic-gate {
5510Sstevel@tonic-gate 	char	*name, _name[PATH_MAX];
5520Sstevel@tonic-gate 
5531618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5540Sstevel@tonic-gate 		return;
5550Sstevel@tonic-gate 
5560Sstevel@tonic-gate 	if (file) {
5570Sstevel@tonic-gate 		(void) snprintf(_name, PATH_MAX, MSG_ORIG(MSG_FMT_PATH),
5580Sstevel@tonic-gate 		    dir, file);
5590Sstevel@tonic-gate 		name = _name;
5600Sstevel@tonic-gate 	} else
5610Sstevel@tonic-gate 		name = (char *)dir;
5620Sstevel@tonic-gate 
5631618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG), name, config);
5641618Srie }
5651618Srie 
5661618Srie void
5671618Srie Dbg_file_del_rescan(Lm_list *lml)
5681618Srie {
5691618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5701618Srie 		return;
5711618Srie 
5721618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5731618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DEL_RESCAN));
5741618Srie }
5751618Srie 
5761618Srie void
5771618Srie Dbg_file_mode_promote(Rt_map *lmp, int mode)
5781618Srie {
5794734Sab196087 	Conv_dl_mode_buf_t	dl_mode_buf;
5804734Sab196087 	Lm_list			*lml = LIST(lmp);
5811618Srie 
5821618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5831618Srie 		return;
5841618Srie 
5851618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5861618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PROMOTE), NAME(lmp),
5874734Sab196087 	    conv_dl_mode(mode, 0, &dl_mode_buf));
5881618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5890Sstevel@tonic-gate }
5900Sstevel@tonic-gate 
5911618Srie void
592*12449SRod.Evans@Sun.COM Dbg_file_deferred(Lm_list *lml, const char *oname, const char *nname)
593*12449SRod.Evans@Sun.COM {
594*12449SRod.Evans@Sun.COM 	if (DBG_NOTCLASS(DBG_C_FILES))
595*12449SRod.Evans@Sun.COM 		return;
596*12449SRod.Evans@Sun.COM 
597*12449SRod.Evans@Sun.COM 	Dbg_util_nl(lml, DBG_NL_STD);
598*12449SRod.Evans@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_FIL_DEFERRED), oname, nname);
599*12449SRod.Evans@Sun.COM }
600*12449SRod.Evans@Sun.COM 
601*12449SRod.Evans@Sun.COM void
6021618Srie Dbg_file_cntl(Lm_list *lml, Aliste flmco, Aliste tlmco)
6031618Srie {
6041618Srie 	Lm_cntl	*lmc;
6051618Srie 	Aliste	off;
6061618Srie 
6071618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6081618Srie 		return;
6091618Srie 	if (DBG_NOTDETAIL())
6101618Srie 		return;
6111618Srie 
6121618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6131618Srie 	dbg_print(lml, MSG_INTL(MSG_CNTL_TITLE), EC_XWORD(flmco),
6141618Srie 	    EC_XWORD(tlmco));
6151618Srie 
6165892Sab196087 	for (ALIST_TRAVERSE_BY_OFFSET(lml->lm_lists, off, lmc)) {
6171618Srie 		Rt_map	*lmp;
6181618Srie 
6191618Srie 		/* LINTED */
6201618Srie 		for (lmp = lmc->lc_head; lmp; lmp = (Rt_map *)NEXT(lmp))
6211618Srie 			dbg_print(lml, MSG_ORIG(MSG_CNTL_ENTRY), EC_XWORD(off),
6221618Srie 			    NAME(lmp));
6231618Srie 	}
6241618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6251618Srie }
6261618Srie 
6277983SAli.Bahrami@Sun.COM /*
6287983SAli.Bahrami@Sun.COM  * Report archive rescan operation.
6297983SAli.Bahrami@Sun.COM  *	argv_start_ndx, argv_end_ndx - Index range of command line arguments
6307983SAli.Bahrami@Sun.COM  *		from which archives are to be reprocessed.
6317983SAli.Bahrami@Sun.COM  */
6321618Srie void
6337983SAli.Bahrami@Sun.COM Dbg_file_ar_rescan(Lm_list *lml, int argv_start_ndx, int argv_end_ndx)
6341618Srie {
6351618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6361618Srie 		return;
6370Sstevel@tonic-gate 
6381618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6397983SAli.Bahrami@Sun.COM 	dbg_print(lml, MSG_INTL(MSG_FIL_AR_RESCAN),
6407983SAli.Bahrami@Sun.COM 	    argv_start_ndx, argv_end_ndx);
6411618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6421618Srie }
6431618Srie 
6441618Srie void
64512254SAli.Bahrami@Oracle.COM Dbg_file_ar(Lm_list *lml, const char *name, Boolean again)
6461618Srie {
6471618Srie 	const char	*str;
6481618Srie 
6491618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6501618Srie 		return;
6511618Srie 
6521618Srie 	if (again)
6531618Srie 		str = MSG_INTL(MSG_STR_AGAIN);
6541618Srie 	else
6551618Srie 		str = MSG_ORIG(MSG_STR_EMPTY);
6561618Srie 
6571618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6581618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ARCHIVE), name, str);
6591618Srie }
6601618Srie 
6611618Srie void
6621618Srie Dbg_file_generic(Lm_list *lml, Ifl_desc *ifl)
6631618Srie {
6644734Sab196087 	Conv_inv_buf_t inv_buf;
6654734Sab196087 
6661618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6671618Srie 		return;
6681618Srie 
6691618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6701618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BASIC), ifl->ifl_name,
6719273SAli.Bahrami@Sun.COM 	    conv_ehdr_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
6729273SAli.Bahrami@Sun.COM 	    ifl->ifl_ehdr->e_type, 0, &inv_buf));
6731618Srie }
6741618Srie 
6751618Srie static const Msg
6760Sstevel@tonic-gate reject[] = {
6770Sstevel@tonic-gate 	MSG_STR_EMPTY,
6780Sstevel@tonic-gate 	MSG_REJ_MACH,		/* MSG_INTL(MSG_REJ_MACH) */
6790Sstevel@tonic-gate 	MSG_REJ_CLASS,		/* MSG_INTL(MSG_REJ_CLASS) */
6800Sstevel@tonic-gate 	MSG_REJ_DATA,		/* MSG_INTL(MSG_REJ_DATA) */
6810Sstevel@tonic-gate 	MSG_REJ_TYPE,		/* MSG_INTL(MSG_REJ_TYPE) */
6820Sstevel@tonic-gate 	MSG_REJ_BADFLAG,	/* MSG_INTL(MSG_REJ_BADFLAG) */
6830Sstevel@tonic-gate 	MSG_REJ_MISFLAG,	/* MSG_INTL(MSG_REJ_MISFLAG) */
6840Sstevel@tonic-gate 	MSG_REJ_VERSION,	/* MSG_INTL(MSG_REJ_VERSION) */
6850Sstevel@tonic-gate 	MSG_REJ_HAL,		/* MSG_INTL(MSG_REJ_HAL) */
6860Sstevel@tonic-gate 	MSG_REJ_US3,		/* MSG_INTL(MSG_REJ_US3) */
6870Sstevel@tonic-gate 	MSG_REJ_STR,		/* MSG_INTL(MSG_REJ_STR) */
6880Sstevel@tonic-gate 	MSG_REJ_UNKFILE,	/* MSG_INTL(MSG_REJ_UNKFILE) */
68911827SRod.Evans@Sun.COM 	MSG_REJ_UNKCAP,		/* MSG_INTL(MSG_REJ_UNKCAP) */
6900Sstevel@tonic-gate 	MSG_REJ_HWCAP_1,	/* MSG_INTL(MSG_REJ_HWCAP_1) */
69111827SRod.Evans@Sun.COM 	MSG_REJ_SFCAP_1,	/* MSG_INTL(MSG_REJ_SFCAP_1) */
69211827SRod.Evans@Sun.COM 	MSG_REJ_MACHCAP,	/* MSG_INTL(MSG_REJ_MACHCAP) */
69311827SRod.Evans@Sun.COM 	MSG_REJ_PLATCAP,	/* MSG_INTL(MSG_REJ_PLATCAP) */
69411827SRod.Evans@Sun.COM 	MSG_REJ_HWCAP_2		/* MSG_INTL(MSG_REJ_HWCAP_2) */
6950Sstevel@tonic-gate };
6960Sstevel@tonic-gate 
6970Sstevel@tonic-gate void
6986206Sab196087 Dbg_file_rejected(Lm_list *lml, Rej_desc *rej, Half mach)
6990Sstevel@tonic-gate {
7004734Sab196087 	Conv_reject_desc_buf_t rej_buf;
7014734Sab196087 
7021618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
7030Sstevel@tonic-gate 		return;
7040Sstevel@tonic-gate 
7051618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7061618Srie 	dbg_print(lml, MSG_INTL(reject[rej->rej_type]), rej->rej_name ?
7074734Sab196087 	    rej->rej_name : MSG_INTL(MSG_STR_UNKNOWN),
7086206Sab196087 	    conv_reject_desc(rej, &rej_buf, mach));
7091618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7100Sstevel@tonic-gate }
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate void
7131618Srie Dbg_file_reuse(Lm_list *lml, const char *nname, const char *oname)
7140Sstevel@tonic-gate {
7151618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
7160Sstevel@tonic-gate 		return;
7170Sstevel@tonic-gate 
71812254SAli.Bahrami@Oracle.COM 	Dbg_util_nl(lml, DBG_NL_STD);
7191618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_REUSE), nname, oname);
7200Sstevel@tonic-gate }
7210Sstevel@tonic-gate 
7220Sstevel@tonic-gate void
7231618Srie Dbg_file_skip(Lm_list *lml, const char *oname, const char *nname)
7240Sstevel@tonic-gate {
7251618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
7260Sstevel@tonic-gate 		return;
7270Sstevel@tonic-gate 
7281618Srie 	if (oname && strcmp(nname, oname))
7291618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_1), nname, oname);
7301618Srie 	else
7311618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_2), nname);
7320Sstevel@tonic-gate }
7332978Srie 
7342978Srie void
7352978Srie Dbg_file_modified(Lm_list *lml, const char *obj, const char *oname,
7362978Srie     const char *nname, int ofd, int nfd, Elf *oelf, Elf *nelf)
7372978Srie {
7382978Srie 	const char	*str;
7392978Srie 
7402978Srie 	if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_SUPPORT))
7412978Srie 		return;
7422978Srie 	if (DBG_NOTDETAIL())
7432978Srie 		return;
7442978Srie 
7452978Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7462978Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_MODIFIED), oname, obj);
7472978Srie 
7482978Srie 	if (nname != oname)
7492978Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_NAMECHANGE), nname);
7502978Srie 	if (nfd != ofd) {
7512978Srie 		if (nfd == -1)
7522978Srie 			str = MSG_INTL(MSG_FIL_IGNORE);
7532978Srie 		else
7542978Srie 			str = MSG_ORIG(MSG_STR_EMPTY);
7552978Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FDCHANGE), ofd, nfd, str);
7562978Srie 	}
7572978Srie 	if (nelf != oelf) {
7582978Srie 		if (nelf == 0)
7592978Srie 			str = MSG_INTL(MSG_FIL_IGNORE);
7602978Srie 		else
7612978Srie 			str = MSG_ORIG(MSG_STR_EMPTY);
7622978Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_ELFCHANGE), EC_NATPTR(oelf),
7632978Srie 		    EC_NATPTR(nelf), str);
7642978Srie 	}
7652978Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7662978Srie }
7673731Srie 
7683731Srie void
7693731Srie Dbg_file_cleanup(Lm_list *lml, const char *name, Aliste lmco)
7703731Srie {
7713731Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
7723731Srie 		return;
7733731Srie 
7743731Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7753731Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CLEANUP), name, EC_XWORD(lmco));
7763731Srie }
777