xref: /titanic_50/usr/src/cmd/sgs/liblddbg/common/files.c (revision 33f2fefd46350ca5992567761c46a5b70f864340)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include	<sys/auxv.h>
28 #include	<string.h>
29 #include	<unistd.h>
30 #include	<fcntl.h>
31 #include	<limits.h>
32 #include	<stdio.h>
33 #include	<libld.h>
34 #include	<rtld.h>
35 #include	<conv.h>
36 #include	"msg.h"
37 #include	"_debug.h"
38 
39 void
40 Dbg_file_analyze(Rt_map *lmp)
41 {
42 	Conv_dl_mode_buf_t	dl_mode_buf;
43 	Lm_list			*lml = LIST(lmp);
44 
45 	if (DBG_NOTCLASS(DBG_C_FILES))
46 		return;
47 
48 	Dbg_util_nl(lml, DBG_NL_STD);
49 	dbg_print(lml, MSG_INTL(MSG_FIL_ANALYZE), NAME(lmp),
50 	    conv_dl_mode(MODE(lmp), 1, &dl_mode_buf));
51 }
52 
53 void
54 Dbg_file_mmapobj(Lm_list *lml, const char *name, mmapobj_result_t *ompp,
55     uint_t onum)
56 {
57 	mmapobj_result_t	*mpp;
58 	uint_t			mnum;
59 
60 	if (DBG_NOTCLASS(DBG_C_FILES))
61 		return;
62 	if (DBG_NOTDETAIL())
63 		return;
64 
65 	Dbg_util_nl(lml, DBG_NL_STD);
66 	dbg_print(lml, MSG_INTL(MSG_FIL_MMAPOBJ), name, onum);
67 
68 	for (mnum = 0, mpp = ompp; mnum < onum; mnum++, mpp++) {
69 		const char	*str;
70 		uint_t		type = MR_GET_TYPE(mpp->mr_flags);
71 
72 		if (type == MR_PADDING)
73 			str = MSG_ORIG(MSG_MR_PADDING);
74 		else if (type == MR_HDR_ELF)
75 			str = MSG_ORIG(MSG_MR_HDR_ELF);
76 		else if (type == MR_HDR_AOUT)
77 			str = MSG_ORIG(MSG_MR_HDR_AOUT);
78 		else
79 			str = MSG_ORIG(MSG_STR_EMPTY);
80 
81 		dbg_print(lml, MSG_INTL(MSG_FIL_MMAPOBJ_1), mnum,
82 		    EC_NATPTR(mpp->mr_addr), EC_OFF(mpp->mr_fsize), str);
83 		dbg_print(lml, MSG_INTL(MSG_FIL_MMAPOBJ_2),
84 		    EC_OFF(mpp->mr_offset), EC_OFF(mpp->mr_msize));
85 	}
86 	Dbg_util_nl(lml, DBG_NL_STD);
87 }
88 
89 void
90 Dbg_file_aout(Lm_list *lml, const char *name, Addr addr, size_t size,
91     const char *lmid, Aliste lmco)
92 {
93 	if (DBG_NOTCLASS(DBG_C_FILES))
94 		return;
95 
96 	dbg_print(lml, MSG_INTL(MSG_FIL_AOUT), name);
97 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_AS), EC_ADDR(addr), EC_OFF(size));
98 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
99 }
100 
101 void
102 Dbg_file_elf(Lm_list *lml, const char *name, Addr addr, size_t size,
103     const char *lmid, Aliste lmco)
104 {
105 	const char	*str;
106 
107 	if (DBG_NOTCLASS(DBG_C_FILES))
108 		return;
109 
110 	if (addr == 0)
111 		str = MSG_INTL(MSG_STR_TEMPORARY);
112 	else
113 		str = MSG_ORIG(MSG_STR_EMPTY);
114 
115 	dbg_print(lml, MSG_INTL(MSG_FIL_ELF), name, str);
116 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_AS), EC_ADDR(addr), EC_OFF(size));
117 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
118 }
119 
120 void
121 Dbg_file_ldso(Rt_map *lmp, char **envp, auxv_t *auxv, const char *lmid,
122     Aliste lmco)
123 {
124 	Lm_list	*lml = LIST(lmp);
125 
126 	if (DBG_NOTCLASS(DBG_C_FILES))
127 		return;
128 
129 	Dbg_util_nl(lml, DBG_NL_STD);
130 	dbg_print(lml, MSG_INTL(MSG_FIL_LDSO), PATHNAME(lmp));
131 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_AS), EC_ADDR(ADDR(lmp)),
132 	    EC_OFF(MSIZE(lmp)));
133 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_EA), EC_NATPTR(envp),
134 	    EC_NATPTR(auxv));
135 	dbg_print(lml, MSG_INTL(MSG_FIL_DATA_LL), lmid, EC_XWORD(lmco));
136 	Dbg_util_nl(lml, DBG_NL_STD);
137 }
138 
139 
140 void
141 Dbg_file_prot(Rt_map *lmp, int prot)
142 {
143 	Lm_list	*lml = LIST(lmp);
144 
145 	if (DBG_NOTCLASS(DBG_C_FILES))
146 		return;
147 
148 	Dbg_util_nl(lml, DBG_NL_STD);
149 	dbg_print(lml, MSG_INTL(MSG_FIL_PROT), NAME(lmp), (prot ? '+' : '-'));
150 }
151 
152 void
153 Dbg_file_delete(Rt_map *lmp)
154 {
155 	Lm_list	*lml = LIST(lmp);
156 
157 	if (DBG_NOTCLASS(DBG_C_FILES))
158 		return;
159 
160 	Dbg_util_nl(lml, DBG_NL_STD);
161 	dbg_print(lml, MSG_INTL(MSG_FIL_DELETE), NAME(lmp));
162 }
163 
164 static int	hdl_title = 0;
165 static Msg	hdl_str = 0;
166 
167 void
168 Dbg_file_hdl_title(int type)
169 {
170 	static const Msg titles[] = {
171 		MSG_FIL_HDL_CREATE,	/* MSG_INTL(MSG_FIL_HDL_CREATE) */
172 		MSG_FIL_HDL_ADD,	/* MSG_INTL(MSG_FIL_HDL_ADD) */
173 		MSG_FIL_HDL_DELETE,	/* MSG_INTL(MSG_FIL_HDL_DELETE) */
174 		MSG_FIL_HDL_ORPHAN,	/* MSG_INTL(MSG_FIL_HDL_ORPHAN) */
175 		MSG_FIL_HDL_REINST,	/* MSG_INTL(MSG_FIL_HDL_REINST) */
176 	};
177 
178 	if (DBG_NOTCLASS(DBG_C_FILES))
179 		return;
180 	if (DBG_NOTDETAIL())
181 		return;
182 
183 	/*
184 	 * Establish a binding title for later use in Dbg_file_hdl_action.
185 	 */
186 	if (type <= DBG_HDL_REINST) {
187 		hdl_str = titles[type];
188 		hdl_title = 1;
189 	} else {
190 		hdl_str = 0;
191 		hdl_title = 0;
192 	}
193 }
194 
195 void
196 Dbg_file_hdl_collect(Grp_hdl *ghp, const char *name)
197 {
198 	Conv_grphdl_flags_buf_t	grphdl_flags_buf;
199 	Lm_list		*lml = ghp->gh_ownlml;
200 	const char	*str;
201 
202 	if (DBG_NOTCLASS(DBG_C_FILES))
203 		return;
204 	if (DBG_NOTDETAIL())
205 		return;
206 
207 	if (ghp->gh_ownlmp)
208 		str = NAME(ghp->gh_ownlmp);
209 	else
210 		str = MSG_INTL(MSG_STR_ORPHAN);
211 
212 	if (hdl_title) {
213 		hdl_title = 0;
214 		Dbg_util_nl(lml, DBG_NL_STD);
215 	}
216 	if (name)
217 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_RETAIN), str, name);
218 	else
219 		dbg_print(lml, MSG_INTL(MSG_FIL_HDL_COLLECT), str,
220 		    conv_grphdl_flags(ghp->gh_flags, &grphdl_flags_buf));
221 }
222 
223 void
224 Dbg_file_hdl_action(Grp_hdl *ghp, Rt_map *lmp, int type, uint_t flags)
225 {
226 	Conv_grpdesc_flags_buf_t grpdesc_flags_buf;
227 	const char	*mode, *group;
228 	Lm_list		*lml = LIST(lmp);
229 	Msg		str;
230 
231 	static const Msg fmt[] = {
232 		MSG_FIL_DEP_ADD,	/* MSG_INTL(MSG_FIL_DEP_ADD) */
233 		MSG_FIL_DEP_UPDATE,	/* MSG_INTL(MSG_FIL_DEP_UPDATE) */
234 		MSG_FIL_DEP_DELETE,	/* MSG_INTL(MSG_FIL_DEP_DELETE) */
235 		MSG_FIL_DEP_REMOVE,	/* MSG_INTL(MSG_FIL_DEP_REMOVE) */
236 		MSG_FIL_DEP_REMAIN,	/* MSG_INTL(MSG_FIL_DEP_REMAIN) */
237 		MSG_FIL_DEP_ORPHAN,	/* MSG_INTL(MSG_FIL_DEP_ORPHAN) */
238 		MSG_FIL_DEP_REINST,	/* MSG_INTL(MSG_FIL_DEP_REINST) */
239 	};
240 	if (DBG_NOTCLASS(DBG_C_FILES))
241 		return;
242 	if (DBG_NOTDETAIL())
243 		return;
244 
245 	if (hdl_title) {
246 		Dbg_util_nl(lml, DBG_NL_STD);
247 		if (hdl_str) {
248 			const char	*name;
249 
250 			/*
251 			 * Protect ourselves in case this handle has no
252 			 * originating owner.
253 			 */
254 			if (ghp->gh_ownlmp)
255 				name = NAME(ghp->gh_ownlmp);
256 			else
257 				name = MSG_INTL(MSG_STR_UNKNOWN);
258 
259 			dbg_print(lml, MSG_INTL(hdl_str), name, EC_NATPTR(ghp));
260 		}
261 		hdl_title = 0;
262 	}
263 
264 	/*
265 	 * Establish a binding descriptor format string.
266 	 */
267 	if (type > DBG_DEP_REINST)
268 		return;
269 
270 	str = fmt[type];
271 
272 	if (((type == DBG_DEP_ADD) || (type == DBG_DEP_UPDATE)) && flags)
273 		group = conv_grpdesc_flags(flags, &grpdesc_flags_buf);
274 	else
275 		group = MSG_ORIG(MSG_STR_EMPTY);
276 
277 	if ((MODE(lmp) & (RTLD_GLOBAL | RTLD_NODELETE)) ==
278 	    (RTLD_GLOBAL | RTLD_NODELETE))
279 		mode = MSG_ORIG(MSG_MODE_GLOBNODEL);
280 	else if (MODE(lmp) & RTLD_GLOBAL)
281 		mode = MSG_ORIG(MSG_MODE_GLOB);
282 	else if (MODE(lmp) & RTLD_NODELETE)
283 		mode = MSG_ORIG(MSG_MODE_NODEL);
284 	else
285 		mode = MSG_ORIG(MSG_STR_EMPTY);
286 
287 	dbg_print(lml, MSG_INTL(str), NAME(lmp), mode, group);
288 }
289 
290 void
291 Dbg_file_bind_entry(Lm_list *lml, Bnd_desc *bdp)
292 {
293 	Conv_bnd_type_buf_t bnd_type_buf;
294 
295 	if (DBG_NOTCLASS(DBG_C_FILES))
296 		return;
297 	if (DBG_NOTDETAIL())
298 		return;
299 
300 	/*
301 	 * Print the dependency together with the modes of the binding.
302 	 */
303 	Dbg_util_nl(lml, DBG_NL_STD);
304 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_ADD), NAME(bdp->b_caller));
305 	dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE), NAME(bdp->b_depend),
306 	    conv_bnd_type(bdp->b_flags, &bnd_type_buf));
307 }
308 
309 void
310 Dbg_file_bindings(Rt_map *lmp, int flag)
311 {
312 	Conv_bnd_obj_buf_t	bnd_obj_buf;
313 	Conv_bnd_type_buf_t	bnd_type_buf;
314 	const char	*str;
315 	Rt_map		*tlmp;
316 	Lm_list		*lml = LIST(lmp);
317 	int		next = 0;
318 
319 	if (DBG_NOTCLASS(DBG_C_INIT))
320 		return;
321 	if (DBG_NOTDETAIL())
322 		return;
323 
324 	if (flag & RT_SORT_REV)
325 		str = MSG_ORIG(MSG_SCN_INIT);
326 	else
327 		str = MSG_ORIG(MSG_SCN_FINI);
328 
329 	Dbg_util_nl(lml, DBG_NL_STD);
330 	dbg_print(lml, MSG_INTL(MSG_FIL_DEP_TITLE), str,
331 	    conv_bnd_obj(lml->lm_flags, &bnd_obj_buf));
332 
333 	/* LINTED */
334 	for (tlmp = lmp; tlmp; tlmp = (Rt_map *)NEXT(tlmp)) {
335 		Bnd_desc	*bdp;
336 		Aliste		idx;
337 
338 		/*
339 		 * For .init processing, only collect objects that have been
340 		 * relocated and haven't already been collected.
341 		 * For .fini processing, only collect objects that have had
342 		 * their .init collected, and haven't already been .fini
343 		 * collected.
344 		 */
345 		if (flag & RT_SORT_REV) {
346 			if ((FLAGS(tlmp) & (FLG_RT_RELOCED |
347 			    FLG_RT_INITCLCT)) != FLG_RT_RELOCED)
348 				continue;
349 
350 		} else {
351 			if ((flag & RT_SORT_DELETE) &&
352 			    ((FLAGS(tlmp) & FLG_RT_DELETE) == 0))
353 				continue;
354 			if (((FLAGS(tlmp) &
355 			    (FLG_RT_INITCLCT | FLG_RT_FINICLCT)) ==
356 			    FLG_RT_INITCLCT) == 0)
357 				continue;
358 		}
359 
360 		if (next++)
361 			Dbg_util_nl(lml, DBG_NL_STD);
362 
363 		if (DEPENDS(tlmp) == NULL)
364 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_NONE), NAME(tlmp));
365 		else {
366 			dbg_print(lml, MSG_INTL(MSG_FIL_DEP_ENT), NAME(tlmp));
367 
368 			for (APLIST_TRAVERSE(DEPENDS(tlmp), idx, bdp)) {
369 				dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE),
370 				    NAME(bdp->b_depend),
371 				    conv_bnd_type(bdp->b_flags,
372 				    &bnd_type_buf));
373 			}
374 		}
375 	}
376 	Dbg_util_nl(lml, DBG_NL_STD);
377 }
378 
379 void
380 Dbg_file_dlopen(Rt_map *clmp, const char *name, int *in_nfavl, int mode)
381 {
382 	Conv_dl_mode_buf_t	dl_mode_buf;
383 	Lm_list			*lml = LIST(clmp);
384 	const char		*retry;
385 
386 	if (DBG_NOTCLASS(DBG_C_FILES))
387 		return;
388 
389 	/*
390 	 * The core functionality of dlopen() can be called twice.  The first
391 	 * attempt can be affected by path names that exist in the "not-found"
392 	 * AVL tree.  Should a "not-found" path name be found, a second attempt
393 	 * is made to locate the required file (in_nfavl is NULL).  This fall-
394 	 * back provides for file system changes while a process executes.
395 	 */
396 	if (in_nfavl)
397 		retry = MSG_ORIG(MSG_STR_EMPTY);
398 	else
399 		retry = MSG_INTL(MSG_STR_RETRY);
400 
401 	Dbg_util_nl(lml, DBG_NL_STD);
402 	dbg_print(lml, MSG_INTL(MSG_FIL_DLOPEN), name, NAME(clmp), retry,
403 	    conv_dl_mode(mode, 0, &dl_mode_buf));
404 }
405 
406 void
407 Dbg_file_dlclose(Lm_list *lml, const char *name, int flag)
408 {
409 	const char	*str;
410 
411 	if (DBG_NOTCLASS(DBG_C_FILES))
412 		return;
413 
414 	if (flag == DBG_DLCLOSE_IGNORE)
415 		str = MSG_INTL(MSG_STR_IGNORE);
416 	else
417 		str = MSG_ORIG(MSG_STR_EMPTY);
418 
419 	Dbg_util_nl(lml, DBG_NL_STD);
420 	dbg_print(lml, MSG_INTL(MSG_FIL_DLCLOSE), name, str);
421 }
422 
423 void
424 Dbg_file_dldump(Rt_map *lmp, const char *path, int flags)
425 {
426 	Conv_dl_flag_buf_t	dl_flag_buf;
427 	Lm_list			*lml = LIST(lmp);
428 
429 	if (DBG_NOTCLASS(DBG_C_FILES))
430 		return;
431 
432 	Dbg_util_nl(lml, DBG_NL_STD);
433 	dbg_print(lml, MSG_INTL(MSG_FIL_DLDUMP), NAME(lmp), path,
434 	    conv_dl_flag(flags, 0, &dl_flag_buf));
435 }
436 
437 void
438 Dbg_file_lazyload(Rt_map *clmp, const char *fname, const char *sname)
439 {
440 	Lm_list	*lml = LIST(clmp);
441 
442 	if (DBG_NOTCLASS(DBG_C_FILES))
443 		return;
444 
445 	Dbg_util_nl(lml, DBG_NL_STD);
446 	dbg_print(lml, MSG_INTL(MSG_FIL_LAZYLOAD), fname, NAME(clmp),
447 	    Dbg_demangle_name(sname));
448 }
449 
450 void
451 Dbg_file_preload(Lm_list *lml, const char *name)
452 {
453 	if (DBG_NOTCLASS(DBG_C_FILES))
454 		return;
455 
456 	Dbg_util_nl(lml, DBG_NL_STD);
457 	dbg_print(lml, MSG_INTL(MSG_FIL_PRELOAD), name);
458 }
459 
460 void
461 Dbg_file_needed(Rt_map *lmp, const char *name)
462 {
463 	Lm_list	*lml = LIST(lmp);
464 
465 	if (DBG_NOTCLASS(DBG_C_FILES))
466 		return;
467 
468 	Dbg_util_nl(lml, DBG_NL_STD);
469 	dbg_print(lml, MSG_INTL(MSG_FIL_NEEDED), name, NAME(lmp));
470 }
471 
472 void
473 Dbg_file_filter(Lm_list *lml, const char *filter, const char *filtee,
474     int config)
475 {
476 	if (DBG_NOTCLASS(DBG_C_FILES))
477 		return;
478 
479 	Dbg_util_nl(lml, DBG_NL_STD);
480 	if (config)
481 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_1), filter, filtee);
482 	else
483 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_2), filter, filtee);
484 }
485 
486 void
487 Dbg_file_filtee(Lm_list *lml, const char *filter, const char *filtee, int audit)
488 {
489 	if (audit) {
490 		if (DBG_NOTCLASS(DBG_C_AUDITING | DBG_C_FILES))
491 			return;
492 
493 		Dbg_util_nl(lml, DBG_NL_STD);
494 		dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_3), filtee);
495 	} else {
496 		if (DBG_NOTCLASS(DBG_C_FILES))
497 			return;
498 
499 		Dbg_util_nl(lml, DBG_NL_STD);
500 		if (filter)
501 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_1), filtee,
502 			    filter);
503 		else
504 			dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_2), filtee);
505 	}
506 }
507 
508 void
509 Dbg_file_fixname(Lm_list *lml, const char *oname, const char *nname)
510 {
511 	if (DBG_NOTCLASS(DBG_C_FILES))
512 		return;
513 
514 	Dbg_util_nl(lml, DBG_NL_STD);
515 	dbg_print(lml, MSG_INTL(MSG_FIL_FIXNAME), oname, nname);
516 }
517 
518 void
519 Dbg_file_output(Ofl_desc *ofl)
520 {
521 	const char	*prefix = MSG_ORIG(MSG_PTH_OBJECT);
522 	char		*oname, *nname, *ofile;
523 	int		fd;
524 
525 	if (DBG_NOTCLASS(DBG_C_FILES))
526 		return;
527 	if (DBG_NOTDETAIL())
528 		return;
529 
530 	/*
531 	 * Obtain the present input object filename for concatenation to the
532 	 * prefix name.
533 	 */
534 	oname = (char *)ofl->ofl_name;
535 	if ((ofile = strrchr(oname, '/')) == NULL)
536 		ofile = oname;
537 	else
538 		ofile++;
539 
540 	/*
541 	 * Concatenate the prefix with the object filename, open the file and
542 	 * write out the present Elf memory image.  As this is debugging we
543 	 * ignore all errors.
544 	 */
545 	if ((nname = malloc(strlen(prefix) + strlen(ofile) + 1)) != 0) {
546 		(void) strcpy(nname, prefix);
547 		(void) strcat(nname, ofile);
548 		if ((fd = open(nname, O_RDWR | O_CREAT | O_TRUNC,
549 		    0666)) != -1) {
550 			(void) write(fd, ofl->ofl_nehdr, ofl->ofl_size);
551 			(void) close(fd);
552 		}
553 		free(nname);
554 	}
555 }
556 
557 void
558 Dbg_file_config_dis(Lm_list *lml, const char *config, int features)
559 {
560 	Conv_config_feat_buf_t	config_feat_buf;
561 	const char		*str;
562 
563 	switch (features & ~CONF_FEATMSK) {
564 	case DBG_CONF_IGNORE:
565 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_1);
566 		break;
567 	case DBG_CONF_VERSION:
568 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_2);
569 		break;
570 	case DBG_CONF_PRCFAIL:
571 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_3);
572 		break;
573 	case DBG_CONF_CORRUPT:
574 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_4);
575 		break;
576 	case DBG_CONF_ABIMISMATCH:
577 		str = MSG_INTL(MSG_FIL_CONFIG_ERR_5);
578 		break;
579 	default:
580 		str = conv_config_feat(features, &config_feat_buf);
581 		break;
582 	}
583 
584 	Dbg_util_nl(lml, DBG_NL_FRC);
585 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG_ERR), config, str);
586 	Dbg_util_nl(lml, DBG_NL_FRC);
587 }
588 
589 void
590 Dbg_file_config_obj(Lm_list *lml, const char *dir, const char *file,
591     const char *config)
592 {
593 	char	*name, _name[PATH_MAX];
594 
595 	if (DBG_NOTCLASS(DBG_C_FILES))
596 		return;
597 
598 	if (file) {
599 		(void) snprintf(_name, PATH_MAX, MSG_ORIG(MSG_FMT_PATH),
600 		    dir, file);
601 		name = _name;
602 	} else
603 		name = (char *)dir;
604 
605 	dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG), name, config);
606 }
607 
608 void
609 Dbg_file_del_rescan(Lm_list *lml)
610 {
611 	if (DBG_NOTCLASS(DBG_C_FILES))
612 		return;
613 
614 	Dbg_util_nl(lml, DBG_NL_STD);
615 	dbg_print(lml, MSG_INTL(MSG_FIL_DEL_RESCAN));
616 }
617 
618 void
619 Dbg_file_mode_promote(Rt_map *lmp, int mode)
620 {
621 	Conv_dl_mode_buf_t	dl_mode_buf;
622 	Lm_list			*lml = LIST(lmp);
623 
624 	if (DBG_NOTCLASS(DBG_C_FILES))
625 		return;
626 
627 	Dbg_util_nl(lml, DBG_NL_STD);
628 	dbg_print(lml, MSG_INTL(MSG_FIL_PROMOTE), NAME(lmp),
629 	    conv_dl_mode(mode, 0, &dl_mode_buf));
630 	Dbg_util_nl(lml, DBG_NL_STD);
631 }
632 
633 void
634 Dbg_file_cntl(Lm_list *lml, Aliste flmco, Aliste tlmco)
635 {
636 	Lm_cntl	*lmc;
637 	Aliste	off;
638 
639 	if (DBG_NOTCLASS(DBG_C_FILES))
640 		return;
641 	if (DBG_NOTDETAIL())
642 		return;
643 
644 	Dbg_util_nl(lml, DBG_NL_STD);
645 	dbg_print(lml, MSG_INTL(MSG_CNTL_TITLE), EC_XWORD(flmco),
646 	    EC_XWORD(tlmco));
647 
648 	for (ALIST_TRAVERSE_BY_OFFSET(lml->lm_lists, off, lmc)) {
649 		Rt_map	*lmp;
650 
651 		/* LINTED */
652 		for (lmp = lmc->lc_head; lmp; lmp = (Rt_map *)NEXT(lmp))
653 			dbg_print(lml, MSG_ORIG(MSG_CNTL_ENTRY), EC_XWORD(off),
654 			    NAME(lmp));
655 	}
656 	Dbg_util_nl(lml, DBG_NL_STD);
657 }
658 
659 /*
660  * Report archive rescan operation.
661  *	argv_start_ndx, argv_end_ndx - Index range of command line arguments
662  *		from which archives are to be reprocessed.
663  */
664 void
665 Dbg_file_ar_rescan(Lm_list *lml, int argv_start_ndx, int argv_end_ndx)
666 {
667 	if (DBG_NOTCLASS(DBG_C_FILES))
668 		return;
669 
670 	Dbg_util_nl(lml, DBG_NL_STD);
671 	dbg_print(lml, MSG_INTL(MSG_FIL_AR_RESCAN),
672 	    argv_start_ndx, argv_end_ndx);
673 	Dbg_util_nl(lml, DBG_NL_STD);
674 }
675 
676 void
677 Dbg_file_ar(Lm_list *lml, const char *name, int again)
678 {
679 	const char	*str;
680 
681 	if (DBG_NOTCLASS(DBG_C_FILES))
682 		return;
683 
684 	if (again)
685 		str = MSG_INTL(MSG_STR_AGAIN);
686 	else
687 		str = MSG_ORIG(MSG_STR_EMPTY);
688 
689 	Dbg_util_nl(lml, DBG_NL_STD);
690 	dbg_print(lml, MSG_INTL(MSG_FIL_ARCHIVE), name, str);
691 }
692 
693 void
694 Dbg_file_generic(Lm_list *lml, Ifl_desc *ifl)
695 {
696 	Conv_inv_buf_t inv_buf;
697 
698 	if (DBG_NOTCLASS(DBG_C_FILES))
699 		return;
700 
701 	Dbg_util_nl(lml, DBG_NL_STD);
702 	dbg_print(lml, MSG_INTL(MSG_FIL_BASIC), ifl->ifl_name,
703 	    conv_ehdr_type(ifl->ifl_ehdr->e_type, 0, &inv_buf));
704 }
705 
706 static const Msg
707 reject[] = {
708 	MSG_STR_EMPTY,
709 	MSG_REJ_MACH,		/* MSG_INTL(MSG_REJ_MACH) */
710 	MSG_REJ_CLASS,		/* MSG_INTL(MSG_REJ_CLASS) */
711 	MSG_REJ_DATA,		/* MSG_INTL(MSG_REJ_DATA) */
712 	MSG_REJ_TYPE,		/* MSG_INTL(MSG_REJ_TYPE) */
713 	MSG_REJ_BADFLAG,	/* MSG_INTL(MSG_REJ_BADFLAG) */
714 	MSG_REJ_MISFLAG,	/* MSG_INTL(MSG_REJ_MISFLAG) */
715 	MSG_REJ_VERSION,	/* MSG_INTL(MSG_REJ_VERSION) */
716 	MSG_REJ_HAL,		/* MSG_INTL(MSG_REJ_HAL) */
717 	MSG_REJ_US3,		/* MSG_INTL(MSG_REJ_US3) */
718 	MSG_REJ_STR,		/* MSG_INTL(MSG_REJ_STR) */
719 	MSG_REJ_UNKFILE,	/* MSG_INTL(MSG_REJ_UNKFILE) */
720 	MSG_REJ_HWCAP_1,	/* MSG_INTL(MSG_REJ_HWCAP_1) */
721 };
722 
723 void
724 Dbg_file_rejected(Lm_list *lml, Rej_desc *rej, Half mach)
725 {
726 	Conv_reject_desc_buf_t rej_buf;
727 
728 	if (DBG_NOTCLASS(DBG_C_FILES))
729 		return;
730 
731 	Dbg_util_nl(lml, DBG_NL_STD);
732 	dbg_print(lml, MSG_INTL(reject[rej->rej_type]), rej->rej_name ?
733 	    rej->rej_name : MSG_INTL(MSG_STR_UNKNOWN),
734 	    conv_reject_desc(rej, &rej_buf, mach));
735 	Dbg_util_nl(lml, DBG_NL_STD);
736 }
737 
738 void
739 Dbg_file_reuse(Lm_list *lml, const char *nname, const char *oname)
740 {
741 	if (DBG_NOTCLASS(DBG_C_FILES))
742 		return;
743 
744 	dbg_print(lml, MSG_INTL(MSG_FIL_REUSE), nname, oname);
745 }
746 
747 void
748 Dbg_file_skip(Lm_list *lml, const char *oname, const char *nname)
749 {
750 	if (DBG_NOTCLASS(DBG_C_FILES))
751 		return;
752 
753 	if (oname && strcmp(nname, oname))
754 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_1), nname, oname);
755 	else
756 		dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_2), nname);
757 }
758 
759 void
760 Dbg_file_modified(Lm_list *lml, const char *obj, const char *oname,
761     const char *nname, int ofd, int nfd, Elf *oelf, Elf *nelf)
762 {
763 	const char	*str;
764 
765 	if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_SUPPORT))
766 		return;
767 	if (DBG_NOTDETAIL())
768 		return;
769 
770 	Dbg_util_nl(lml, DBG_NL_STD);
771 	dbg_print(lml, MSG_INTL(MSG_FIL_MODIFIED), oname, obj);
772 
773 	if (nname != oname)
774 		dbg_print(lml, MSG_INTL(MSG_FIL_NAMECHANGE), nname);
775 	if (nfd != ofd) {
776 		if (nfd == -1)
777 			str = MSG_INTL(MSG_FIL_IGNORE);
778 		else
779 			str = MSG_ORIG(MSG_STR_EMPTY);
780 		dbg_print(lml, MSG_INTL(MSG_FIL_FDCHANGE), ofd, nfd, str);
781 	}
782 	if (nelf != oelf) {
783 		if (nelf == 0)
784 			str = MSG_INTL(MSG_FIL_IGNORE);
785 		else
786 			str = MSG_ORIG(MSG_STR_EMPTY);
787 		dbg_print(lml, MSG_INTL(MSG_FIL_ELFCHANGE), EC_NATPTR(oelf),
788 		    EC_NATPTR(nelf), str);
789 	}
790 	Dbg_util_nl(lml, DBG_NL_STD);
791 }
792 
793 void
794 Dbg_file_cleanup(Lm_list *lml, const char *name, Aliste lmco)
795 {
796 	if (DBG_NOTCLASS(DBG_C_FILES))
797 		return;
798 
799 	Dbg_util_nl(lml, DBG_NL_STD);
800 	dbg_print(lml, MSG_INTL(MSG_FIL_CLEANUP), name, EC_XWORD(lmco));
801 }
802