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 /*
233731Srie  * Copyright 2007 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 {
434734Sab196087 	Conv_dl_mode_buf_t	dl_mode_buf;
444734Sab196087 	Lm_list			*lml = LIST(lmp);
451618Srie 
461618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
470Sstevel@tonic-gate 		return;
480Sstevel@tonic-gate 
491618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
501618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ANALYZE), NAME(lmp),
514734Sab196087 	    conv_dl_mode(MODE(lmp), 1, &dl_mode_buf));
520Sstevel@tonic-gate }
530Sstevel@tonic-gate 
540Sstevel@tonic-gate void
551618Srie Dbg_file_aout(Lm_list *lml, const char *name, ulong_t dynamic, ulong_t base,
561618Srie     ulong_t size, const char *lmid, Aliste lmco)
570Sstevel@tonic-gate {
581618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
590Sstevel@tonic-gate 		return;
600Sstevel@tonic-gate 
611618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_AOUT), name);
621618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_DB), EC_XWORD(dynamic),
631618Srie 	    EC_ADDR(base));
641618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_S), EC_XWORD(size));
651618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
660Sstevel@tonic-gate }
670Sstevel@tonic-gate 
680Sstevel@tonic-gate void
691618Srie Dbg_file_elf(Lm_list *lml, const char *name, ulong_t dynamic, ulong_t base,
701618Srie     ulong_t size, ulong_t entry, const char *lmid, Aliste lmco)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate 	const char	*str;
730Sstevel@tonic-gate 
741618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
750Sstevel@tonic-gate 		return;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	if (base == 0)
780Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_TEMPORARY);
790Sstevel@tonic-gate 	else
800Sstevel@tonic-gate 		str = MSG_ORIG(MSG_STR_EMPTY);
810Sstevel@tonic-gate 
821618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ELF), name, str);
831618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_DB), EC_XWORD(dynamic),
841618Srie 	    EC_ADDR(base));
851618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_SE), EC_XWORD(size),
861618Srie 	    EC_XWORD(entry));
871618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
900Sstevel@tonic-gate void
911618Srie Dbg_file_ldso(Rt_map *lmp, char **envp, auxv_t *auxv, const char *lmid,
921618Srie     Aliste lmco)
930Sstevel@tonic-gate {
941618Srie 	Lm_list	*lml = LIST(lmp);
951618Srie 
961618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
970Sstevel@tonic-gate 		return;
980Sstevel@tonic-gate 
991618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1001618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_LDSO), PATHNAME(lmp));
1011618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_DB), EC_NATPTR(DYN(lmp)),
1021618Srie 	    EC_ADDR(ADDR(lmp)));
1031618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_EA), EC_NATPTR(envp),
1041618Srie 	    EC_NATPTR(auxv));
1051618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
1061618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1071618Srie }
1081618Srie 
1091618Srie 
1101618Srie void
1111618Srie Dbg_file_prot(Rt_map *lmp, int prot)
1121618Srie {
1131618Srie 	Lm_list	*lml = LIST(lmp);
1141618Srie 
1151618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1161618Srie 		return;
1171618Srie 
1181618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1191618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PROT), NAME(lmp), (prot ? '+' : '-'));
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate void
1231618Srie Dbg_file_delete(Rt_map *lmp)
1240Sstevel@tonic-gate {
1251618Srie 	Lm_list	*lml = LIST(lmp);
1261618Srie 
1271618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1280Sstevel@tonic-gate 		return;
1290Sstevel@tonic-gate 
1301618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1311618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DELETE), NAME(lmp));
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate static int	hdl_title = 0;
1350Sstevel@tonic-gate static Msg	hdl_str = 0;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate void
1380Sstevel@tonic-gate Dbg_file_hdl_title(int type)
1390Sstevel@tonic-gate {
140*5067Srie 	static const Msg titles[] = {
141*5067Srie 		MSG_FIL_HDL_CREATE,	/* MSG_INTL(MSG_FIL_HDL_CREATE) */
142*5067Srie 		MSG_FIL_HDL_ADD,	/* MSG_INTL(MSG_FIL_HDL_ADD) */
143*5067Srie 		MSG_FIL_HDL_DELETE,	/* MSG_INTL(MSG_FIL_HDL_DELETE) */
144*5067Srie 		MSG_FIL_HDL_ORPHAN,	/* MSG_INTL(MSG_FIL_HDL_ORPHAN) */
145*5067Srie 		MSG_FIL_HDL_REINST,	/* MSG_INTL(MSG_FIL_HDL_REINST) */
146*5067Srie 	};
147*5067Srie 
1481618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1490Sstevel@tonic-gate 		return;
1500Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1510Sstevel@tonic-gate 		return;
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	/*
154*5067Srie 	 * Establish a binding title for later use in Dbg_file_hdl_action.
1550Sstevel@tonic-gate 	 */
156*5067Srie 	if (type <= DBG_HDL_REINST) {
157*5067Srie 		hdl_str = titles[type];
158*5067Srie 		hdl_title = 1;
159*5067Srie 	} else {
1604734Sab196087 		hdl_str = 0;
161*5067Srie 		hdl_title = 0;
1623731Srie 	}
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate void
1661618Srie Dbg_file_hdl_collect(Grp_hdl *ghp, const char *name)
1670Sstevel@tonic-gate {
1684734Sab196087 	Conv_grphdl_flags_buf_t	grphdl_flags_buf;
1691618Srie 	Lm_list		*lml = ghp->gh_ownlml;
1701618Srie 	const char	*str;
1710Sstevel@tonic-gate 
1721618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
1730Sstevel@tonic-gate 		return;
1740Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1750Sstevel@tonic-gate 		return;
1760Sstevel@tonic-gate 
1771618Srie 	if (ghp->gh_ownlmp)
1781618Srie 		str = NAME(ghp->gh_ownlmp);
1790Sstevel@tonic-gate 	else
1800Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_ORPHAN);
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 	if (hdl_title) {
1830Sstevel@tonic-gate 		hdl_title = 0;
1841618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
1850Sstevel@tonic-gate 	}
1860Sstevel@tonic-gate 	if (name)
1871618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_RETAIN), str, name);
1880Sstevel@tonic-gate 	else
1891618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_COLLECT), str,
1904734Sab196087 		    conv_grphdl_flags(ghp->gh_flags, &grphdl_flags_buf));
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate void
1943731Srie Dbg_file_hdl_action(Grp_hdl *ghp, Rt_map *lmp, int type, uint_t flags)
1950Sstevel@tonic-gate {
1964734Sab196087 	Conv_grpdesc_flags_buf_t grpdesc_flags_buf;
1973731Srie 	const char	*mode, *group;
1983731Srie 	Lm_list		*lml = LIST(lmp);
1993731Srie 	Msg		str;
2000Sstevel@tonic-gate 
201*5067Srie 	static const Msg fmt[] = {
202*5067Srie 		MSG_FIL_DEP_ADD,	/* MSG_INTL(MSG_FIL_DEP_ADD) */
203*5067Srie 		MSG_FIL_DEP_UPDATE,	/* MSG_INTL(MSG_FIL_DEP_UPDATE) */
204*5067Srie 		MSG_FIL_DEP_DELETE,	/* MSG_INTL(MSG_FIL_DEP_DELETE) */
205*5067Srie 		MSG_FIL_DEP_REMOVE,	/* MSG_INTL(MSG_FIL_DEP_REMOVE) */
206*5067Srie 		MSG_FIL_DEP_REMAIN,	/* MSG_INTL(MSG_FIL_DEP_REMAIN) */
207*5067Srie 		MSG_FIL_DEP_ORPHAN,	/* MSG_INTL(MSG_FIL_DEP_ORPHAN) */
208*5067Srie 		MSG_FIL_DEP_REINST,	/* MSG_INTL(MSG_FIL_DEP_REINST) */
209*5067Srie 	};
2101618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
2110Sstevel@tonic-gate 		return;
2120Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
2130Sstevel@tonic-gate 		return;
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 	if (hdl_title) {
2161618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
2170Sstevel@tonic-gate 		if (hdl_str) {
2180Sstevel@tonic-gate 			const char	*name;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 			/*
2210Sstevel@tonic-gate 			 * Protect ourselves in case this handle has no
2220Sstevel@tonic-gate 			 * originating owner.
2230Sstevel@tonic-gate 			 */
2241618Srie 			if (ghp->gh_ownlmp)
2251618Srie 				name = NAME(ghp->gh_ownlmp);
2260Sstevel@tonic-gate 			else
2270Sstevel@tonic-gate 				name = MSG_INTL(MSG_STR_UNKNOWN);
2280Sstevel@tonic-gate 
2291618Srie 			dbg_print(lml, MSG_INTL(hdl_str), name);
2300Sstevel@tonic-gate 		}
2310Sstevel@tonic-gate 		hdl_title = 0;
2320Sstevel@tonic-gate 	}
2330Sstevel@tonic-gate 
2344734Sab196087 	/*
235*5067Srie 	 * Establish a binding descriptor format string.
2364734Sab196087 	 */
237*5067Srie 	if (type > DBG_DEP_REINST)
2384734Sab196087 		return;
2390Sstevel@tonic-gate 
240*5067Srie 	str = fmt[type];
241*5067Srie 
242*5067Srie 	if (((type == DBG_DEP_ADD) || (type == DBG_DEP_UPDATE)) && flags)
2434734Sab196087 		group = conv_grpdesc_flags(flags, &grpdesc_flags_buf);
2443731Srie 	else
2453731Srie 		group = MSG_ORIG(MSG_STR_EMPTY);
2460Sstevel@tonic-gate 
2473731Srie 	if ((MODE(lmp) & (RTLD_GLOBAL | RTLD_NODELETE)) ==
2483731Srie 	    (RTLD_GLOBAL | RTLD_NODELETE))
2493731Srie 		mode = MSG_ORIG(MSG_MODE_GLOBNODEL);
2503731Srie 	else if (MODE(lmp) & RTLD_GLOBAL)
2513731Srie 		mode = MSG_ORIG(MSG_MODE_GLOB);
2523731Srie 	else if (MODE(lmp) & RTLD_NODELETE)
2533731Srie 		mode = MSG_ORIG(MSG_MODE_NODEL);
2543731Srie 	else
2553731Srie 		mode = MSG_ORIG(MSG_STR_EMPTY);
2563731Srie 
2573731Srie 	dbg_print(lml, MSG_INTL(str), NAME(lmp), mode, group);
2580Sstevel@tonic-gate }
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate void
2611618Srie Dbg_file_bind_entry(Lm_list *lml, Bnd_desc *bdp)
2620Sstevel@tonic-gate {
2634734Sab196087 	Conv_bnd_type_buf_t bnd_type_buf;
2644734Sab196087 
2651618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
2660Sstevel@tonic-gate 		return;
2670Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
2680Sstevel@tonic-gate 		return;
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	/*
2710Sstevel@tonic-gate 	 * Print the dependency together with the modes of the binding.
2720Sstevel@tonic-gate 	 */
2731618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
2741618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_ADD), NAME(bdp->b_caller));
2751618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE), NAME(bdp->b_depend),
2764734Sab196087 	    conv_bnd_type(bdp->b_flags, &bnd_type_buf));
277280Srie }
278280Srie 
279280Srie void
2801618Srie Dbg_file_bindings(Rt_map *lmp, int flag)
281280Srie {
2824734Sab196087 	Conv_bnd_obj_buf_t	bnd_obj_buf;
2834734Sab196087 	Conv_bnd_type_buf_t	bnd_type_buf;
284280Srie 	const char	*str;
285280Srie 	Rt_map		*tlmp;
2861618Srie 	Lm_list		*lml = LIST(lmp);
287280Srie 	int		next = 0;
288280Srie 
2891618Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
290280Srie 		return;
291280Srie 	if (DBG_NOTDETAIL())
292280Srie 		return;
293280Srie 
294280Srie 	if (flag & RT_SORT_REV)
295280Srie 		str = MSG_ORIG(MSG_SCN_INIT);
296280Srie 	else
297280Srie 		str = MSG_ORIG(MSG_SCN_FINI);
298280Srie 
2991618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3001618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DEP_TITLE), str,
3014734Sab196087 	    conv_bnd_obj(lml->lm_flags, &bnd_obj_buf));
302280Srie 
303280Srie 	/* LINTED */
304280Srie 	for (tlmp = lmp; tlmp; tlmp = (Rt_map *)NEXT(tlmp)) {
3051618Srie 		Bnd_desc	**bdpp;
306280Srie 		Aliste		off;
307280Srie 
308280Srie 		/*
309280Srie 		 * For .init processing, only collect objects that have been
310280Srie 		 * relocated and haven't already been collected.
311280Srie 		 * For .fini processing, only collect objects that have had
312280Srie 		 * their .init collected, and haven't already been .fini
313280Srie 		 * collected.
314280Srie 		 */
315280Srie 		if (flag & RT_SORT_REV) {
316280Srie 			if ((FLAGS(tlmp) & (FLG_RT_RELOCED |
317280Srie 			    FLG_RT_INITCLCT)) != FLG_RT_RELOCED)
318280Srie 				continue;
319280Srie 
320280Srie 		} else {
321280Srie 			if ((flag & RT_SORT_DELETE) &&
322280Srie 			    ((FLAGS(tlmp) & FLG_RT_DELETE) == 0))
323280Srie 				continue;
324280Srie 			if (((FLAGS(tlmp) &
325280Srie 			    (FLG_RT_INITCLCT | FLG_RT_FINICLCT)) ==
326280Srie 			    FLG_RT_INITCLCT) == 0)
327280Srie 				continue;
328280Srie 		}
329280Srie 
330280Srie 		if (next++)
3311618Srie 			Dbg_util_nl(lml, DBG_NL_STD);
332280Srie 
333280Srie 		if (DEPENDS(tlmp) == 0)
3341618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_NONE), NAME(tlmp));
335280Srie 		else {
3361618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_ENT), NAME(tlmp));
337280Srie 
338280Srie 			for (ALIST_TRAVERSE(DEPENDS(tlmp), off, bdpp)) {
3391618Srie 				dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE),
340280Srie 				    NAME((*bdpp)->b_depend),
3414734Sab196087 				    conv_bnd_type((*bdpp)->b_flags,
3424734Sab196087 				    &bnd_type_buf));
343280Srie 			}
344280Srie 		}
345280Srie 	}
3461618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate void
3501618Srie Dbg_file_dlopen(Rt_map *clmp, const char *name, int mode)
3510Sstevel@tonic-gate {
3524734Sab196087 	Conv_dl_mode_buf_t	dl_mode_buf;
3534734Sab196087 	Lm_list			*lml = LIST(clmp);
3541618Srie 
3551618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3560Sstevel@tonic-gate 		return;
3570Sstevel@tonic-gate 
3581618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3591618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DLOPEN), name, NAME(clmp),
3604734Sab196087 	    conv_dl_mode(mode, 1, &dl_mode_buf));
3610Sstevel@tonic-gate }
3620Sstevel@tonic-gate 
3630Sstevel@tonic-gate void
3641618Srie Dbg_file_dlclose(Lm_list *lml, const char *name, int flag)
3650Sstevel@tonic-gate {
3660Sstevel@tonic-gate 	const char	*str;
3670Sstevel@tonic-gate 
3681618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3690Sstevel@tonic-gate 		return;
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	if (flag == DBG_DLCLOSE_IGNORE)
3720Sstevel@tonic-gate 		str = MSG_INTL(MSG_STR_IGNORE);
3730Sstevel@tonic-gate 	else
3740Sstevel@tonic-gate 		str = MSG_ORIG(MSG_STR_EMPTY);
3750Sstevel@tonic-gate 
3761618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3771618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DLCLOSE), name, str);
3780Sstevel@tonic-gate }
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate void
3811618Srie Dbg_file_dldump(Rt_map *lmp, const char *path, int flags)
3820Sstevel@tonic-gate {
3834734Sab196087 	Conv_dl_flag_buf_t	dl_flag_buf;
3844734Sab196087 	Lm_list			*lml = LIST(lmp);
3851618Srie 
3861618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
3870Sstevel@tonic-gate 		return;
3880Sstevel@tonic-gate 
3891618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
3901618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DLDUMP), NAME(lmp), path,
3914734Sab196087 	    conv_dl_flag(flags, 0, &dl_flag_buf));
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate void
3951618Srie Dbg_file_lazyload(Rt_map *clmp, const char *fname, const char *sname)
3960Sstevel@tonic-gate {
3971618Srie 	Lm_list	*lml = LIST(clmp);
3981618Srie 
3991618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4000Sstevel@tonic-gate 		return;
4010Sstevel@tonic-gate 
4021618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4031618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_LAZYLOAD), fname, NAME(clmp),
4041618Srie 	    Dbg_demangle_name(sname));
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate void
4081618Srie Dbg_file_preload(Lm_list *lml, const char *name)
4090Sstevel@tonic-gate {
4101618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4110Sstevel@tonic-gate 		return;
4120Sstevel@tonic-gate 
4131618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4141618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PRELOAD), name);
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate 
4170Sstevel@tonic-gate void
4181618Srie Dbg_file_needed(Rt_map *lmp, const char *name)
4190Sstevel@tonic-gate {
4201618Srie 	Lm_list	*lml = LIST(lmp);
4211618Srie 
4221618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4230Sstevel@tonic-gate 		return;
4240Sstevel@tonic-gate 
4251618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4261618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_NEEDED), name, NAME(lmp));
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate void
4301618Srie Dbg_file_filter(Lm_list *lml, const char *filter, const char *filtee,
4311618Srie     int config)
4320Sstevel@tonic-gate {
4331618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4340Sstevel@tonic-gate 		return;
4350Sstevel@tonic-gate 
4361618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4370Sstevel@tonic-gate 	if (config)
4381618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_1), filter, filtee);
4390Sstevel@tonic-gate 	else
4401618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_2), filter, filtee);
4410Sstevel@tonic-gate }
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate void
4441618Srie Dbg_file_filtee(Lm_list *lml, const char *filter, const char *filtee, int audit)
4450Sstevel@tonic-gate {
4460Sstevel@tonic-gate 	if (audit) {
4471618Srie 		if (DBG_NOTCLASS(DBG_C_AUDITING | DBG_C_FILES))
4480Sstevel@tonic-gate 			return;
4490Sstevel@tonic-gate 
4501618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
4511618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_3), filtee);
4520Sstevel@tonic-gate 	} else {
4531618Srie 		if (DBG_NOTCLASS(DBG_C_FILES))
4540Sstevel@tonic-gate 			return;
4550Sstevel@tonic-gate 
4561618Srie 		Dbg_util_nl(lml, DBG_NL_STD);
4570Sstevel@tonic-gate 		if (filter)
4581618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_1), filtee,
4591618Srie 			    filter);
4600Sstevel@tonic-gate 		else
4611618Srie 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_2), filtee);
4620Sstevel@tonic-gate 	}
4630Sstevel@tonic-gate }
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate void
4661618Srie Dbg_file_fixname(Lm_list *lml, const char *oname, const char *nname)
4670Sstevel@tonic-gate {
4681618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4690Sstevel@tonic-gate 		return;
4700Sstevel@tonic-gate 
4711618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
4721618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_FIXNAME), oname, nname);
4730Sstevel@tonic-gate }
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate void
4760Sstevel@tonic-gate Dbg_file_output(Ofl_desc *ofl)
4770Sstevel@tonic-gate {
4780Sstevel@tonic-gate 	const char	*prefix = MSG_ORIG(MSG_PTH_OBJECT);
4790Sstevel@tonic-gate 	char		*oname, *nname, *ofile;
4800Sstevel@tonic-gate 	int		fd;
4810Sstevel@tonic-gate 
4821618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
4830Sstevel@tonic-gate 		return;
4840Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
4850Sstevel@tonic-gate 		return;
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate 	/*
4880Sstevel@tonic-gate 	 * Obtain the present input object filename for concatenation to the
4890Sstevel@tonic-gate 	 * prefix name.
4900Sstevel@tonic-gate 	 */
4910Sstevel@tonic-gate 	oname = (char *)ofl->ofl_name;
4920Sstevel@tonic-gate 	if ((ofile = strrchr(oname, '/')) == NULL)
4930Sstevel@tonic-gate 		ofile = oname;
4940Sstevel@tonic-gate 	else
4950Sstevel@tonic-gate 		ofile++;
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 	/*
4980Sstevel@tonic-gate 	 * Concatenate the prefix with the object filename, open the file and
4990Sstevel@tonic-gate 	 * write out the present Elf memory image.  As this is debugging we
5000Sstevel@tonic-gate 	 * ignore all errors.
5010Sstevel@tonic-gate 	 */
5021618Srie 	if ((nname = malloc(strlen(prefix) + strlen(ofile) + 1)) != 0) {
5030Sstevel@tonic-gate 		(void) strcpy(nname, prefix);
5040Sstevel@tonic-gate 		(void) strcat(nname, ofile);
5050Sstevel@tonic-gate 		if ((fd = open(nname, O_RDWR | O_CREAT | O_TRUNC,
5060Sstevel@tonic-gate 		    0666)) != -1) {
5071618Srie 			(void) write(fd, ofl->ofl_nehdr, ofl->ofl_size);
5081618Srie 			(void) close(fd);
5090Sstevel@tonic-gate 		}
5100Sstevel@tonic-gate 		free(nname);
5110Sstevel@tonic-gate 	}
5120Sstevel@tonic-gate }
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate void
5151618Srie Dbg_file_config_dis(Lm_list *lml, const char *config, int features)
5160Sstevel@tonic-gate {
5174734Sab196087 	Conv_config_feat_buf_t	config_feat_buf;
5184734Sab196087 	const char		*str;
5190Sstevel@tonic-gate 
5201976Sab196087 	switch (features & ~CONF_FEATMSK) {
5211976Sab196087 	case DBG_CONF_IGNORE:
5220Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_1);
5231976Sab196087 		break;
5241976Sab196087 	case DBG_CONF_VERSION:
5250Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_2);
5261976Sab196087 		break;
5271976Sab196087 	case DBG_CONF_PRCFAIL:
5280Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_3);
5291976Sab196087 		break;
5301976Sab196087 	case DBG_CONF_CORRUPT:
5310Sstevel@tonic-gate 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_4);
5321976Sab196087 		break;
5331976Sab196087 	case DBG_CONF_ABIMISMATCH:
5341976Sab196087 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_5);
5351976Sab196087 		break;
5361976Sab196087 	default:
5374734Sab196087 		str = conv_config_feat(features, &config_feat_buf);
5381976Sab196087 		break;
5391976Sab196087 	}
5400Sstevel@tonic-gate 
5411618Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
5421618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG_ERR), config, str);
5431618Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate void
5471618Srie Dbg_file_config_obj(Lm_list *lml, const char *dir, const char *file,
5481618Srie     const char *config)
5490Sstevel@tonic-gate {
5500Sstevel@tonic-gate 	char	*name, _name[PATH_MAX];
5510Sstevel@tonic-gate 
5521618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5530Sstevel@tonic-gate 		return;
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate 	if (file) {
5560Sstevel@tonic-gate 		(void) snprintf(_name, PATH_MAX, MSG_ORIG(MSG_FMT_PATH),
5570Sstevel@tonic-gate 		    dir, file);
5580Sstevel@tonic-gate 		name = _name;
5590Sstevel@tonic-gate 	} else
5600Sstevel@tonic-gate 		name = (char *)dir;
5610Sstevel@tonic-gate 
5621618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG), name, config);
5631618Srie }
5641618Srie 
5651618Srie void
5661618Srie Dbg_file_del_rescan(Lm_list *lml)
5671618Srie {
5681618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5691618Srie 		return;
5701618Srie 
5711618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5721618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_DEL_RESCAN));
5731618Srie }
5741618Srie 
5751618Srie void
5761618Srie Dbg_file_mode_promote(Rt_map *lmp, int mode)
5771618Srie {
5784734Sab196087 	Conv_dl_mode_buf_t	dl_mode_buf;
5794734Sab196087 	Lm_list			*lml = LIST(lmp);
5801618Srie 
5811618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5821618Srie 		return;
5831618Srie 
5841618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5851618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_PROMOTE), NAME(lmp),
5864734Sab196087 	    conv_dl_mode(mode, 0, &dl_mode_buf));
5871618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
5880Sstevel@tonic-gate }
5890Sstevel@tonic-gate 
5901618Srie void
5911618Srie Dbg_file_cntl(Lm_list *lml, Aliste flmco, Aliste tlmco)
5921618Srie {
5931618Srie 	Lm_cntl	*lmc;
5941618Srie 	Aliste	off;
5951618Srie 
5961618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
5971618Srie 		return;
5981618Srie 	if (DBG_NOTDETAIL())
5991618Srie 		return;
6001618Srie 
6011618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6021618Srie 	dbg_print(lml, MSG_INTL(MSG_CNTL_TITLE), EC_XWORD(flmco),
6031618Srie 	    EC_XWORD(tlmco));
6041618Srie 
6051618Srie 	for (ALIST_TRAVERSE(lml->lm_lists, off, lmc)) {
6061618Srie 		Rt_map	*lmp;
6071618Srie 
6081618Srie 		/* LINTED */
6091618Srie 		for (lmp = lmc->lc_head; lmp; lmp = (Rt_map *)NEXT(lmp))
6101618Srie 			dbg_print(lml, MSG_ORIG(MSG_CNTL_ENTRY), EC_XWORD(off),
6111618Srie 			    NAME(lmp));
6121618Srie 	}
6131618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6141618Srie }
6151618Srie 
6161618Srie void
6171618Srie Dbg_file_ar_rescan(Lm_list *lml)
6181618Srie {
6191618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6201618Srie 		return;
6210Sstevel@tonic-gate 
6221618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6231618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_AR_RESCAN));
6241618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6251618Srie }
6261618Srie 
6271618Srie void
6281618Srie Dbg_file_ar(Lm_list *lml, const char *name, int again)
6291618Srie {
6301618Srie 	const char	*str;
6311618Srie 
6321618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6331618Srie 		return;
6341618Srie 
6351618Srie 	if (again)
6361618Srie 		str = MSG_INTL(MSG_STR_AGAIN);
6371618Srie 	else
6381618Srie 		str = MSG_ORIG(MSG_STR_EMPTY);
6391618Srie 
6401618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6411618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_ARCHIVE), name, str);
6421618Srie }
6431618Srie 
6441618Srie void
6451618Srie Dbg_file_generic(Lm_list *lml, Ifl_desc *ifl)
6461618Srie {
6474734Sab196087 	Conv_inv_buf_t inv_buf;
6484734Sab196087 
6491618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6501618Srie 		return;
6511618Srie 
6521618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6531618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_BASIC), ifl->ifl_name,
6544734Sab196087 	    conv_ehdr_type(ifl->ifl_ehdr->e_type, 0, &inv_buf));
6551618Srie }
6561618Srie 
6571618Srie static const Msg
6580Sstevel@tonic-gate reject[] = {
6590Sstevel@tonic-gate 	MSG_STR_EMPTY,
6600Sstevel@tonic-gate 	MSG_REJ_MACH,		/* MSG_INTL(MSG_REJ_MACH) */
6610Sstevel@tonic-gate 	MSG_REJ_CLASS,		/* MSG_INTL(MSG_REJ_CLASS) */
6620Sstevel@tonic-gate 	MSG_REJ_DATA,		/* MSG_INTL(MSG_REJ_DATA) */
6630Sstevel@tonic-gate 	MSG_REJ_TYPE,		/* MSG_INTL(MSG_REJ_TYPE) */
6640Sstevel@tonic-gate 	MSG_REJ_BADFLAG,	/* MSG_INTL(MSG_REJ_BADFLAG) */
6650Sstevel@tonic-gate 	MSG_REJ_MISFLAG,	/* MSG_INTL(MSG_REJ_MISFLAG) */
6660Sstevel@tonic-gate 	MSG_REJ_VERSION,	/* MSG_INTL(MSG_REJ_VERSION) */
6670Sstevel@tonic-gate 	MSG_REJ_HAL,		/* MSG_INTL(MSG_REJ_HAL) */
6680Sstevel@tonic-gate 	MSG_REJ_US3,		/* MSG_INTL(MSG_REJ_US3) */
6690Sstevel@tonic-gate 	MSG_REJ_STR,		/* MSG_INTL(MSG_REJ_STR) */
6700Sstevel@tonic-gate 	MSG_REJ_UNKFILE,	/* MSG_INTL(MSG_REJ_UNKFILE) */
6710Sstevel@tonic-gate 	MSG_REJ_HWCAP_1,	/* MSG_INTL(MSG_REJ_HWCAP_1) */
6720Sstevel@tonic-gate };
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate void
6751618Srie Dbg_file_rejected(Lm_list *lml, Rej_desc *rej)
6760Sstevel@tonic-gate {
6774734Sab196087 	Conv_reject_desc_buf_t rej_buf;
6784734Sab196087 
6791618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6800Sstevel@tonic-gate 		return;
6810Sstevel@tonic-gate 
6821618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6831618Srie 	dbg_print(lml, MSG_INTL(reject[rej->rej_type]), rej->rej_name ?
6844734Sab196087 	    rej->rej_name : MSG_INTL(MSG_STR_UNKNOWN),
6854734Sab196087 	    conv_reject_desc(rej, &rej_buf));
6861618Srie 	Dbg_util_nl(lml, DBG_NL_STD);
6870Sstevel@tonic-gate }
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate void
6901618Srie Dbg_file_reuse(Lm_list *lml, const char *nname, const char *oname)
6910Sstevel@tonic-gate {
6921618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
6930Sstevel@tonic-gate 		return;
6940Sstevel@tonic-gate 
6951618Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_REUSE), nname, oname);
6960Sstevel@tonic-gate }
6970Sstevel@tonic-gate 
6980Sstevel@tonic-gate void
6991618Srie Dbg_file_skip(Lm_list *lml, const char *oname, const char *nname)
7000Sstevel@tonic-gate {
7011618Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
7020Sstevel@tonic-gate 		return;
7030Sstevel@tonic-gate 
7041618Srie 	if (oname && strcmp(nname, oname))
7051618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_1), nname, oname);
7061618Srie 	else
7071618Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_2), nname);
7080Sstevel@tonic-gate }
7092978Srie 
7102978Srie void
7112978Srie Dbg_file_modified(Lm_list *lml, const char *obj, const char *oname,
7122978Srie     const char *nname, int ofd, int nfd, Elf *oelf, Elf *nelf)
7132978Srie {
7142978Srie 	const char	*str;
7152978Srie 
7162978Srie 	if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_SUPPORT))
7172978Srie 		return;
7182978Srie 	if (DBG_NOTDETAIL())
7192978Srie 		return;
7202978Srie 
7212978Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7222978Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_MODIFIED), oname, obj);
7232978Srie 
7242978Srie 	if (nname != oname)
7252978Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_NAMECHANGE), nname);
7262978Srie 	if (nfd != ofd) {
7272978Srie 		if (nfd == -1)
7282978Srie 			str = MSG_INTL(MSG_FIL_IGNORE);
7292978Srie 		else
7302978Srie 			str = MSG_ORIG(MSG_STR_EMPTY);
7312978Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_FDCHANGE), ofd, nfd, str);
7322978Srie 	}
7332978Srie 	if (nelf != oelf) {
7342978Srie 		if (nelf == 0)
7352978Srie 			str = MSG_INTL(MSG_FIL_IGNORE);
7362978Srie 		else
7372978Srie 			str = MSG_ORIG(MSG_STR_EMPTY);
7382978Srie 		dbg_print(lml, MSG_INTL(MSG_FIL_ELFCHANGE), EC_NATPTR(oelf),
7392978Srie 		    EC_NATPTR(nelf), str);
7402978Srie 	}
7412978Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7422978Srie }
7433731Srie 
7443731Srie void
7453731Srie Dbg_file_cleanup(Lm_list *lml, const char *name, Aliste lmco)
7463731Srie {
7473731Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
7483731Srie 		return;
7493731Srie 
7503731Srie 	Dbg_util_nl(lml, DBG_NL_STD);
7513731Srie 	dbg_print(lml, MSG_INTL(MSG_FIL_CLEANUP), name, EC_XWORD(lmco));
7523731Srie }
753