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 /*
231618Srie  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
286Srie #include	<sys/auxv.h>
290Sstevel@tonic-gate #include	<string.h>
300Sstevel@tonic-gate #include	<unistd.h>
310Sstevel@tonic-gate #include	<fcntl.h>
320Sstevel@tonic-gate #include	<limits.h>
330Sstevel@tonic-gate #include	<stdio.h>
341618Srie #include	<libld.h>
351618Srie #include	<rtld.h>
361618Srie #include	<conv.h>
370Sstevel@tonic-gate #include	"msg.h"
380Sstevel@tonic-gate #include	"_debug.h"
390Sstevel@tonic-gate 
400Sstevel@tonic-gate void
411618Srie Dbg_file_analyze(Rt_map *lmp)
420Sstevel@tonic-gate {
431618Srie 	Lm_list	*lml = LIST(lmp);
441618Srie 
451618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
460Sstevel@tonic-gate 		return;
470Sstevel@tonic-gate 
481618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
491618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ANALYZE), NAME(lmp),
501618Srie 	    conv_dl_mode(MODE(lmp), 1));
510Sstevel@tonic-gate }
520Sstevel@tonic-gate 
530Sstevel@tonic-gate void
541618Srie Dbg_file_aout(Lm_list *lml, const char *name, ulong_t dynamic, ulong_t base,
551618Srie     ulong_t size, const char *lmid, Aliste lmco)
560Sstevel@tonic-gate {
571618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
580Sstevel@tonic-gate 		return;
590Sstevel@tonic-gate 
601618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_AOUT), name);
611618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_DB), EC_XWORD(dynamic),
621618Srie 	    EC_ADDR(base));
631618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_S), EC_XWORD(size));
641618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
650Sstevel@tonic-gate }
660Sstevel@tonic-gate 
670Sstevel@tonic-gate void
681618Srie Dbg_file_elf(Lm_list *lml, const char *name, ulong_t dynamic, ulong_t base,
691618Srie     ulong_t size, ulong_t entry, const char *lmid, Aliste lmco)
700Sstevel@tonic-gate {
710Sstevel@tonic-gate 	const char	*str;
720Sstevel@tonic-gate 
731618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
740Sstevel@tonic-gate 		return;
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	if (base == 0)
770Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_TEMPORARY);
780Sstevel@tonic-gate 	else
790Sstevel@tonic-gate 		str = MSG_ORIG(MSG_STR_EMPTY);
800Sstevel@tonic-gate 
811618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ELF), name, str);
821618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_DB), EC_XWORD(dynamic),
831618Srie 	    EC_ADDR(base));
841618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_SE), EC_XWORD(size),
851618Srie 	    EC_XWORD(entry));
861618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
870Sstevel@tonic-gate }
880Sstevel@tonic-gate 
890Sstevel@tonic-gate void
901618Srie Dbg_file_ldso(Rt_map *lmp, char **envp, auxv_t *auxv, const char *lmid,
911618Srie     Aliste lmco)
920Sstevel@tonic-gate {
931618Srie 	Lm_list	*lml = LIST(lmp);
941618Srie 
951618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
960Sstevel@tonic-gate 		return;
970Sstevel@tonic-gate 
981618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
991618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_LDSO), PATHNAME(lmp));
1001618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_DB), EC_NATPTR(DYN(lmp)),
1011618Srie 	    EC_ADDR(ADDR(lmp)));
1021618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_EA), EC_NATPTR(envp),
1031618Srie 	    EC_NATPTR(auxv));
1041618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
1051618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1061618Srie }
1071618Srie 
1081618Srie 
1091618Srie void
1101618Srie Dbg_file_prot(Rt_map *lmp, int prot)
1111618Srie {
1121618Srie 	Lm_list	*lml = LIST(lmp);
1131618Srie 
1141618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1151618Srie 		return;
1161618Srie 
1171618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1181618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PROT), NAME(lmp), (prot ? '+' : '-'));
1190Sstevel@tonic-gate }
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate void
1221618Srie Dbg_file_delete(Rt_map *lmp)
1230Sstevel@tonic-gate {
1241618Srie 	Lm_list	*lml = LIST(lmp);
1251618Srie 
1261618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1270Sstevel@tonic-gate 		return;
1280Sstevel@tonic-gate 
1291618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1301618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DELETE), NAME(lmp));
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate static int	hdl_title = 0;
1340Sstevel@tonic-gate static Msg	hdl_str = 0;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate void
1370Sstevel@tonic-gate Dbg_file_hdl_title(int type)
1380Sstevel@tonic-gate {
1391618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1400Sstevel@tonic-gate 		return;
1410Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1420Sstevel@tonic-gate 		return;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	hdl_title = 1;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	/*
1470Sstevel@tonic-gate 	 * Establish a binding title for later use in Dbg_file_bind_entry.
1480Sstevel@tonic-gate 	 */
1490Sstevel@tonic-gate 	if (type == DBG_DEP_CREATE)
1500Sstevel@tonic-gate 	    hdl_str = MSG_FIL_HDL_CREATE;  /* MSG_INTL(MSG_FIL_HDL_CREATE) */
1510Sstevel@tonic-gate 	else if (type == DBG_DEP_ADD)
1520Sstevel@tonic-gate 	    hdl_str = MSG_FIL_HDL_ADD;	   /* MSG_INTL(MSG_FIL_HDL_ADD) */
1530Sstevel@tonic-gate 	else if (type == DBG_DEP_DELETE)
1540Sstevel@tonic-gate 	    hdl_str = MSG_FIL_HDL_DELETE;  /* MSG_INTL(MSG_FIL_HDL_DELETE) */
1550Sstevel@tonic-gate 	else if (type == DBG_DEP_ORPHAN)
1560Sstevel@tonic-gate 	    hdl_str = MSG_FIL_HDL_ORPHAN;  /* MSG_INTL(MSG_FIL_HDL_ORPHAN) */
1570Sstevel@tonic-gate 	else if (type == DBG_DEP_REINST)
1580Sstevel@tonic-gate 	    hdl_str = MSG_FIL_HDL_REINST;  /* MSG_INTL(MSG_FIL_HDL_REINST) */
1590Sstevel@tonic-gate 	else
1600Sstevel@tonic-gate 	    hdl_str = 0;
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate void
1641618Srie Dbg_file_hdl_collect(Grp_hdl *ghp, const char *name)
1650Sstevel@tonic-gate {
1661618Srie 	Lm_list		*lml = ghp->gh_ownlml;
1671618Srie 	const char	*str;
1680Sstevel@tonic-gate 
1691618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1700Sstevel@tonic-gate 		return;
1710Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1720Sstevel@tonic-gate 		return;
1730Sstevel@tonic-gate 
1741618Srie 	if (ghp->gh_ownlmp)
1751618Srie 		str = NAME(ghp->gh_ownlmp);
1760Sstevel@tonic-gate 	else
1770Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_ORPHAN);
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 	if (hdl_title) {
1800Sstevel@tonic-gate 		hdl_title = 0;
1811618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
1820Sstevel@tonic-gate 	}
1830Sstevel@tonic-gate 	if (name)
1841618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_RETAIN), str, name);
1850Sstevel@tonic-gate 	else
1861618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_COLLECT), str,
1871618Srie 		    conv_grphdl_flags(ghp->gh_flags));
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate void
1911618Srie Dbg_file_hdl_action(Grp_hdl *ghp, Rt_map *lmp, int type)
1920Sstevel@tonic-gate {
1931618Srie 	Lm_list	*lml = LIST(lmp);
1940Sstevel@tonic-gate 	Msg	str;
1950Sstevel@tonic-gate 
1961618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1970Sstevel@tonic-gate 		return;
1980Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1990Sstevel@tonic-gate 		return;
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	if (hdl_title) {
2021618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
2030Sstevel@tonic-gate 		if (hdl_str) {
2040Sstevel@tonic-gate 			const char	*name;
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 			/*
2070Sstevel@tonic-gate 			 * Protect ourselves in case this handle has no
2080Sstevel@tonic-gate 			 * originating owner.
2090Sstevel@tonic-gate 			 */
2101618Srie 			if (ghp->gh_ownlmp)
2111618Srie 				name = NAME(ghp->gh_ownlmp);
2120Sstevel@tonic-gate 			else
2130Sstevel@tonic-gate 				name = MSG_INTL(MSG_STR_UNKNOWN);
2140Sstevel@tonic-gate 
2151618Srie 			dbg_print(lml, MSG_INTL(hdl_str), name);
2160Sstevel@tonic-gate 		}
2170Sstevel@tonic-gate 		hdl_title = 0;
2180Sstevel@tonic-gate 	}
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	if (type == DBG_DEP_ADD)
2210Sstevel@tonic-gate 	    str = MSG_FIL_DEP_ADD;	/* MSG_INTL(MSG_FIL_DEP_ADD) */
2220Sstevel@tonic-gate 	else if (type == DBG_DEP_DELETE)
2230Sstevel@tonic-gate 	    str = MSG_FIL_DEP_DELETE;	/* MSG_INTL(MSG_FIL_DEP_DELETE) */
2240Sstevel@tonic-gate 	else if (type == DBG_DEP_REMOVE)
2250Sstevel@tonic-gate 	    str = MSG_FIL_DEP_REMOVE;	/* MSG_INTL(MSG_FIL_DEP_REMOVE) */
2260Sstevel@tonic-gate 	else if (type == DBG_DEP_REMAIN)
2270Sstevel@tonic-gate 	    str = MSG_FIL_DEP_REMAIN;	/* MSG_INTL(MSG_FIL_DEP_REMAIN) */
2280Sstevel@tonic-gate 	else
2290Sstevel@tonic-gate 	    str = 0;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 	if (str) {
2320Sstevel@tonic-gate 		const char *mode;
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 		if ((MODE(lmp) & (RTLD_GLOBAL | RTLD_NODELETE)) ==
2350Sstevel@tonic-gate 		    (RTLD_GLOBAL | RTLD_NODELETE))
2360Sstevel@tonic-gate 			mode = MSG_ORIG(MSG_MODE_GLOBNODEL);
2370Sstevel@tonic-gate 		else if (MODE(lmp) & RTLD_GLOBAL)
2380Sstevel@tonic-gate 			mode = MSG_ORIG(MSG_MODE_GLOB);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 		else if (MODE(lmp) & RTLD_NODELETE)
2410Sstevel@tonic-gate 			mode = MSG_ORIG(MSG_MODE_NODEL);
2420Sstevel@tonic-gate 		else
2430Sstevel@tonic-gate 			mode = MSG_ORIG(MSG_STR_EMPTY);
2440Sstevel@tonic-gate 
2451618Srie 		dbg_print(lml, MSG_INTL(str), NAME(lmp), mode);
2460Sstevel@tonic-gate 	}
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate void
2501618Srie Dbg_file_bind_entry(Lm_list *lml, Bnd_desc *bdp)
2510Sstevel@tonic-gate {
2521618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
2530Sstevel@tonic-gate 		return;
2540Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
2550Sstevel@tonic-gate 		return;
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/*
2580Sstevel@tonic-gate 	 * Print the dependency together with the modes of the binding.
2590Sstevel@tonic-gate 	 */
2601618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
2611618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_ADD), NAME(bdp->b_caller));
2621618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE), NAME(bdp->b_depend),
2631618Srie 	    conv_bnd_type(bdp->b_flags));
264280Srie }
265280Srie 
266280Srie void
2671618Srie Dbg_file_bindings(Rt_map *lmp, int flag)
268280Srie {
269280Srie 	const char	*str;
270280Srie 	Rt_map		*tlmp;
2711618Srie 	Lm_list		*lml = LIST(lmp);
272280Srie 	int		next = 0;
273280Srie 
2741618Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
275280Srie 		return;
276280Srie 	if (DBG_NOTDETAIL())
277280Srie 		return;
278280Srie 
279280Srie 	if (flag & RT_SORT_REV)
280280Srie 		str = MSG_ORIG(MSG_SCN_INIT);
281280Srie 	else
282280Srie 		str = MSG_ORIG(MSG_SCN_FINI);
283280Srie 
2841618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
2851618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DEP_TITLE), str,
2861618Srie 	    conv_bnd_obj(lml->lm_flags));
287280Srie 
288280Srie 	/* LINTED */
289280Srie 	for (tlmp = lmp; tlmp; tlmp = (Rt_map *)NEXT(tlmp)) {
2901618Srie 		Bnd_desc	**bdpp;
291280Srie 		Aliste		off;
292280Srie 
293280Srie 		/*
294280Srie 		 * For .init processing, only collect objects that have been
295280Srie 		 * relocated and haven't already been collected.
296280Srie 		 * For .fini processing, only collect objects that have had
297280Srie 		 * their .init collected, and haven't already been .fini
298280Srie 		 * collected.
299280Srie 		 */
300280Srie 		if (flag & RT_SORT_REV) {
301280Srie 			if ((FLAGS(tlmp) & (FLG_RT_RELOCED |
302280Srie 			    FLG_RT_INITCLCT)) != FLG_RT_RELOCED)
303280Srie 				continue;
304280Srie 
305280Srie 		} else {
306280Srie 			if ((flag & RT_SORT_DELETE) &&
307280Srie 			    ((FLAGS(tlmp) & FLG_RT_DELETE) == 0))
308280Srie 				continue;
309280Srie 			if (((FLAGS(tlmp) &
310280Srie 			    (FLG_RT_INITCLCT | FLG_RT_FINICLCT)) ==
311280Srie 			    FLG_RT_INITCLCT) == 0)
312280Srie 				continue;
313280Srie 		}
314280Srie 
315280Srie 		if (next++)
3161618Srie 			Dbg_util_nl(lml, DBG_NL_STD);
317280Srie 
318280Srie 		if (DEPENDS(tlmp) == 0)
3191618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_NONE), NAME(tlmp));
320280Srie 		else {
3211618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_ENT), NAME(tlmp));
322280Srie 
323280Srie 			for (ALIST_TRAVERSE(DEPENDS(tlmp), off, bdpp)) {
3241618Srie 				dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE),
325280Srie 				    NAME((*bdpp)->b_depend),
3261618Srie 				    conv_bnd_type((*bdpp)->b_flags));
327280Srie 			}
328280Srie 		}
329280Srie 	}
3301618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate void
3341618Srie Dbg_file_dlopen(Rt_map *clmp, const char *name, int mode)
3350Sstevel@tonic-gate {
3361618Srie 	Lm_list	*lml = LIST(clmp);
3371618Srie 
3381618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3390Sstevel@tonic-gate 		return;
3400Sstevel@tonic-gate 
3411618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3421618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DLOPEN), name, NAME(clmp),
3431618Srie 	    conv_dl_mode(mode, 1));
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate void
3471618Srie Dbg_file_dlclose(Lm_list *lml, const char *name, int flag)
3480Sstevel@tonic-gate {
3490Sstevel@tonic-gate 	const char	*str;
3500Sstevel@tonic-gate 
3511618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3520Sstevel@tonic-gate 		return;
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate 	if (flag == DBG_DLCLOSE_IGNORE)
3550Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_IGNORE);
3560Sstevel@tonic-gate 	else
3570Sstevel@tonic-gate 		str = MSG_ORIG(MSG_STR_EMPTY);
3580Sstevel@tonic-gate 
3591618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3601618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DLCLOSE), name, str);
3610Sstevel@tonic-gate }
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate void
3641618Srie Dbg_file_dldump(Rt_map *lmp, const char *path, int flags)
3650Sstevel@tonic-gate {
3661618Srie 	Lm_list	*lml = LIST(lmp);
3671618Srie 
3681618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3690Sstevel@tonic-gate 		return;
3700Sstevel@tonic-gate 
3711618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3721618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DLDUMP), NAME(lmp), path,
3731618Srie 		conv_dl_flag(flags, 0));
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate void
3771618Srie Dbg_file_lazyload(Rt_map *clmp, const char *fname, const char *sname)
3780Sstevel@tonic-gate {
3791618Srie 	Lm_list	*lml = LIST(clmp);
3801618Srie 
3811618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3820Sstevel@tonic-gate 		return;
3830Sstevel@tonic-gate 
3841618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3851618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_LAZYLOAD), fname, NAME(clmp),
3861618Srie 	    Dbg_demangle_name(sname));
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate void
3901618Srie Dbg_file_preload(Lm_list *lml, const char *name)
3910Sstevel@tonic-gate {
3921618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3930Sstevel@tonic-gate 		return;
3940Sstevel@tonic-gate 
3951618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3961618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PRELOAD), name);
3970Sstevel@tonic-gate }
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate void
4001618Srie Dbg_file_needed(Rt_map *lmp, const char *name)
4010Sstevel@tonic-gate {
4021618Srie 	Lm_list	*lml = LIST(lmp);
4031618Srie 
4041618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4050Sstevel@tonic-gate 		return;
4060Sstevel@tonic-gate 
4071618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4081618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_NEEDED), name, NAME(lmp));
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate void
4121618Srie Dbg_file_filter(Lm_list *lml, const char *filter, const char *filtee,
4131618Srie     int config)
4140Sstevel@tonic-gate {
4151618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4160Sstevel@tonic-gate 		return;
4170Sstevel@tonic-gate 
4181618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4190Sstevel@tonic-gate 	if (config)
4201618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_1), filter, filtee);
4210Sstevel@tonic-gate 	else
4221618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_2), filter, filtee);
4230Sstevel@tonic-gate }
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate void
4261618Srie Dbg_file_filtee(Lm_list *lml, const char *filter, const char *filtee, int audit)
4270Sstevel@tonic-gate {
4280Sstevel@tonic-gate 	if (audit) {
4291618Srie 		if (DBG_NOTCLASS(DBG_C_AUDITING | DBG_C_FILES))
4300Sstevel@tonic-gate 			return;
4310Sstevel@tonic-gate 
4321618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
4331618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_3), filtee);
4340Sstevel@tonic-gate 	} else {
4351618Srie 		if (DBG_NOTCLASS(DBG_C_FILES))
4360Sstevel@tonic-gate 			return;
4370Sstevel@tonic-gate 
4381618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
4390Sstevel@tonic-gate 		if (filter)
4401618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_1), filtee,
4411618Srie 			    filter);
4420Sstevel@tonic-gate 		else
4431618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_2), filtee);
4440Sstevel@tonic-gate 	}
4450Sstevel@tonic-gate }
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate void
4481618Srie Dbg_file_fixname(Lm_list *lml, const char *oname, const char *nname)
4490Sstevel@tonic-gate {
4501618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4510Sstevel@tonic-gate 		return;
4520Sstevel@tonic-gate 
4531618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4541618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_FIXNAME), oname, nname);
4550Sstevel@tonic-gate }
4560Sstevel@tonic-gate 
4570Sstevel@tonic-gate void
4580Sstevel@tonic-gate Dbg_file_output(Ofl_desc *ofl)
4590Sstevel@tonic-gate {
4600Sstevel@tonic-gate 	const char	*prefix = MSG_ORIG(MSG_PTH_OBJECT);
4610Sstevel@tonic-gate 	char		*oname, *nname, *ofile;
4620Sstevel@tonic-gate 	int		fd;
4630Sstevel@tonic-gate 
4641618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4650Sstevel@tonic-gate 		return;
4660Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
4670Sstevel@tonic-gate 		return;
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate 	/*
4700Sstevel@tonic-gate 	 * Obtain the present input object filename for concatenation to the
4710Sstevel@tonic-gate 	 * prefix name.
4720Sstevel@tonic-gate 	 */
4730Sstevel@tonic-gate 	oname = (char *)ofl->ofl_name;
4740Sstevel@tonic-gate 	if ((ofile = strrchr(oname, '/')) == NULL)
4750Sstevel@tonic-gate 		ofile = oname;
4760Sstevel@tonic-gate 	else
4770Sstevel@tonic-gate 		ofile++;
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	/*
4800Sstevel@tonic-gate 	 * Concatenate the prefix with the object filename, open the file and
4810Sstevel@tonic-gate 	 * write out the present Elf memory image.  As this is debugging we
4820Sstevel@tonic-gate 	 * ignore all errors.
4830Sstevel@tonic-gate 	 */
4841618Srie 	if ((nname = malloc(strlen(prefix) + strlen(ofile) + 1)) != 0) {
4850Sstevel@tonic-gate 		(void) strcpy(nname, prefix);
4860Sstevel@tonic-gate 		(void) strcat(nname, ofile);
4870Sstevel@tonic-gate 		if ((fd = open(nname, O_RDWR | O_CREAT | O_TRUNC,
4880Sstevel@tonic-gate 		    0666)) != -1) {
4891618Srie 			(void) write(fd, ofl->ofl_nehdr, ofl->ofl_size);
4901618Srie 			(void) close(fd);
4910Sstevel@tonic-gate 		}
4920Sstevel@tonic-gate 		free(nname);
4930Sstevel@tonic-gate 	}
4940Sstevel@tonic-gate }
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate void
4971618Srie Dbg_file_config_dis(Lm_list *lml, const char *config, int features)
4980Sstevel@tonic-gate {
4990Sstevel@tonic-gate 	const char	*str;
5000Sstevel@tonic-gate 
501*1976Sab196087 	switch (features & ~CONF_FEATMSK) {
502*1976Sab196087 	case DBG_CONF_IGNORE:
5030Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_1);
504*1976Sab196087 		break;
505*1976Sab196087 	case DBG_CONF_VERSION:
5060Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_2);
507*1976Sab196087 		break;
508*1976Sab196087 	case DBG_CONF_PRCFAIL:
5090Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_3);
510*1976Sab196087 		break;
511*1976Sab196087 	case DBG_CONF_CORRUPT:
5120Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_4);
513*1976Sab196087 		break;
514*1976Sab196087 	case DBG_CONF_ABIMISMATCH:
515*1976Sab196087 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_5);
516*1976Sab196087 		break;
517*1976Sab196087 	default:
5181618Srie 		str = conv_config_feat(features);
519*1976Sab196087 		break;
520*1976Sab196087 	}
5210Sstevel@tonic-gate 
5221618Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
5231618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG_ERR), config, str);
5241618Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
5250Sstevel@tonic-gate }
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate void
5281618Srie Dbg_file_config_obj(Lm_list *lml, const char *dir, const char *file,
5291618Srie     const char *config)
5300Sstevel@tonic-gate {
5310Sstevel@tonic-gate 	char	*name, _name[PATH_MAX];
5320Sstevel@tonic-gate 
5331618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5340Sstevel@tonic-gate 		return;
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 	if (file) {
5370Sstevel@tonic-gate 		(void) snprintf(_name, PATH_MAX, MSG_ORIG(MSG_FMT_PATH),
5380Sstevel@tonic-gate 		    dir, file);
5390Sstevel@tonic-gate 		name = _name;
5400Sstevel@tonic-gate 	} else
5410Sstevel@tonic-gate 		name = (char *)dir;
5420Sstevel@tonic-gate 
5431618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG), name, config);
5441618Srie }
5451618Srie 
5461618Srie void
5471618Srie Dbg_file_del_rescan(Lm_list *lml)
5481618Srie {
5491618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5501618Srie 		return;
5511618Srie 
5521618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5531618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DEL_RESCAN));
5541618Srie }
5551618Srie 
5561618Srie void
5571618Srie Dbg_file_mode_promote(Rt_map *lmp, int mode)
5581618Srie {
5591618Srie 	Lm_list	*lml = LIST(lmp);
5601618Srie 
5611618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5621618Srie 		return;
5631618Srie 
5641618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5651618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PROMOTE), NAME(lmp),
5661618Srie 	    conv_dl_mode(mode, 0));
5671618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5680Sstevel@tonic-gate }
5690Sstevel@tonic-gate 
5701618Srie void
5711618Srie Dbg_file_cntl(Lm_list *lml, Aliste flmco, Aliste tlmco)
5721618Srie {
5731618Srie 	Lm_cntl	*lmc;
5741618Srie 	Aliste	off;
5751618Srie 
5761618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5771618Srie 		return;
5781618Srie 	if (DBG_NOTDETAIL())
5791618Srie 		return;
5801618Srie 
5811618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5821618Srie 	dbg_print(lml, MSG_INTL(MSG_CNTL_TITLE), EC_XWORD(flmco),
5831618Srie 	    EC_XWORD(tlmco));
5841618Srie 
5851618Srie 	for (ALIST_TRAVERSE(lml->lm_lists, off, lmc)) {
5861618Srie 		Rt_map	*lmp;
5871618Srie 
5881618Srie 		/* LINTED */
5891618Srie 		for (lmp = lmc->lc_head; lmp; lmp = (Rt_map *)NEXT(lmp))
5901618Srie 			dbg_print(lml, MSG_ORIG(MSG_CNTL_ENTRY), EC_XWORD(off),
5911618Srie 			    NAME(lmp));
5921618Srie 	}
5931618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5941618Srie }
5951618Srie 
5961618Srie void
5971618Srie Dbg_file_ar_rescan(Lm_list *lml)
5981618Srie {
5991618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6001618Srie 		return;
6010Sstevel@tonic-gate 
6021618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6031618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_AR_RESCAN));
6041618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6051618Srie }
6061618Srie 
6071618Srie void
6081618Srie Dbg_file_ar(Lm_list *lml, const char *name, int again)
6091618Srie {
6101618Srie 	const char	*str;
6111618Srie 
6121618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6131618Srie 		return;
6141618Srie 
6151618Srie 	if (again)
6161618Srie 		str = MSG_INTL(MSG_STR_AGAIN);
6171618Srie 	else
6181618Srie 		str = MSG_ORIG(MSG_STR_EMPTY);
6191618Srie 
6201618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6211618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ARCHIVE), name, str);
6221618Srie }
6231618Srie 
6241618Srie void
6251618Srie Dbg_file_generic(Lm_list *lml, Ifl_desc *ifl)
6261618Srie {
6271618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6281618Srie 		return;
6291618Srie 
6301618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6311618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BASIC), ifl->ifl_name,
632*1976Sab196087 		conv_ehdr_type(ifl->ifl_ehdr->e_type, 0));
6331618Srie }
6341618Srie 
6351618Srie static const Msg
6360Sstevel@tonic-gate reject[] = {
6370Sstevel@tonic-gate 	MSG_STR_EMPTY,
6380Sstevel@tonic-gate 	MSG_REJ_MACH,		/* MSG_INTL(MSG_REJ_MACH) */
6390Sstevel@tonic-gate 	MSG_REJ_CLASS,		/* MSG_INTL(MSG_REJ_CLASS) */
6400Sstevel@tonic-gate 	MSG_REJ_DATA,		/* MSG_INTL(MSG_REJ_DATA) */
6410Sstevel@tonic-gate 	MSG_REJ_TYPE,		/* MSG_INTL(MSG_REJ_TYPE) */
6420Sstevel@tonic-gate 	MSG_REJ_BADFLAG,	/* MSG_INTL(MSG_REJ_BADFLAG) */
6430Sstevel@tonic-gate 	MSG_REJ_MISFLAG,	/* MSG_INTL(MSG_REJ_MISFLAG) */
6440Sstevel@tonic-gate 	MSG_REJ_VERSION,	/* MSG_INTL(MSG_REJ_VERSION) */
6450Sstevel@tonic-gate 	MSG_REJ_HAL,		/* MSG_INTL(MSG_REJ_HAL) */
6460Sstevel@tonic-gate 	MSG_REJ_US3,		/* MSG_INTL(MSG_REJ_US3) */
6470Sstevel@tonic-gate 	MSG_REJ_STR,		/* MSG_INTL(MSG_REJ_STR) */
6480Sstevel@tonic-gate 	MSG_REJ_UNKFILE,	/* MSG_INTL(MSG_REJ_UNKFILE) */
6490Sstevel@tonic-gate 	MSG_REJ_HWCAP_1,	/* MSG_INTL(MSG_REJ_HWCAP_1) */
6500Sstevel@tonic-gate };
6510Sstevel@tonic-gate 
6520Sstevel@tonic-gate void
6531618Srie Dbg_file_rejected(Lm_list *lml, Rej_desc *rej)
6540Sstevel@tonic-gate {
6551618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6560Sstevel@tonic-gate 		return;
6570Sstevel@tonic-gate 
6581618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6591618Srie 	dbg_print(lml, MSG_INTL(reject[rej->rej_type]), rej->rej_name ?
6601618Srie 	    rej->rej_name : MSG_INTL(MSG_STR_UNKNOWN), conv_reject_desc(rej));
6611618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6620Sstevel@tonic-gate }
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate void
6651618Srie Dbg_file_reuse(Lm_list *lml, const char *nname, const char *oname)
6660Sstevel@tonic-gate {
6671618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6680Sstevel@tonic-gate 		return;
6690Sstevel@tonic-gate 
6701618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_REUSE), nname, oname);
6710Sstevel@tonic-gate }
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate void
6741618Srie Dbg_file_skip(Lm_list *lml, const char *oname, const char *nname)
6750Sstevel@tonic-gate {
6761618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6770Sstevel@tonic-gate 		return;
6780Sstevel@tonic-gate 
6791618Srie 	if (oname && strcmp(nname, oname))
6801618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_1), nname, oname);
6811618Srie 	else
6821618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_2), nname);
6830Sstevel@tonic-gate }
684