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 /* 235892Sab196087 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 276Srie #include <sys/auxv.h> 280Sstevel@tonic-gate #include <string.h> 290Sstevel@tonic-gate #include <unistd.h> 300Sstevel@tonic-gate #include <fcntl.h> 310Sstevel@tonic-gate #include <limits.h> 320Sstevel@tonic-gate #include <stdio.h> 331618Srie #include <libld.h> 341618Srie #include <rtld.h> 351618Srie #include <conv.h> 360Sstevel@tonic-gate #include "msg.h" 370Sstevel@tonic-gate #include "_debug.h" 380Sstevel@tonic-gate 390Sstevel@tonic-gate void 401618Srie Dbg_file_analyze(Rt_map *lmp) 410Sstevel@tonic-gate { 424734Sab196087 Conv_dl_mode_buf_t dl_mode_buf; 434734Sab196087 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), 504734Sab196087 conv_dl_mode(MODE(lmp), 1, &dl_mode_buf)); 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 { 1395067Srie static const Msg titles[] = { 1405067Srie MSG_FIL_HDL_CREATE, /* MSG_INTL(MSG_FIL_HDL_CREATE) */ 1415067Srie MSG_FIL_HDL_ADD, /* MSG_INTL(MSG_FIL_HDL_ADD) */ 1425067Srie MSG_FIL_HDL_DELETE, /* MSG_INTL(MSG_FIL_HDL_DELETE) */ 1435067Srie MSG_FIL_HDL_ORPHAN, /* MSG_INTL(MSG_FIL_HDL_ORPHAN) */ 1445067Srie MSG_FIL_HDL_REINST, /* MSG_INTL(MSG_FIL_HDL_REINST) */ 1455067Srie }; 1465067Srie 1471618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 1480Sstevel@tonic-gate return; 1490Sstevel@tonic-gate if (DBG_NOTDETAIL()) 1500Sstevel@tonic-gate return; 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* 1535067Srie * Establish a binding title for later use in Dbg_file_hdl_action. 1540Sstevel@tonic-gate */ 1555067Srie if (type <= DBG_HDL_REINST) { 1565067Srie hdl_str = titles[type]; 1575067Srie hdl_title = 1; 1585067Srie } else { 1594734Sab196087 hdl_str = 0; 1605067Srie hdl_title = 0; 1613731Srie } 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate void 1651618Srie Dbg_file_hdl_collect(Grp_hdl *ghp, const char *name) 1660Sstevel@tonic-gate { 1674734Sab196087 Conv_grphdl_flags_buf_t grphdl_flags_buf; 1681618Srie Lm_list *lml = ghp->gh_ownlml; 1691618Srie const char *str; 1700Sstevel@tonic-gate 1711618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 1720Sstevel@tonic-gate return; 1730Sstevel@tonic-gate if (DBG_NOTDETAIL()) 1740Sstevel@tonic-gate return; 1750Sstevel@tonic-gate 1761618Srie if (ghp->gh_ownlmp) 1771618Srie str = NAME(ghp->gh_ownlmp); 1780Sstevel@tonic-gate else 1790Sstevel@tonic-gate str = MSG_INTL(MSG_STR_ORPHAN); 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate if (hdl_title) { 1820Sstevel@tonic-gate hdl_title = 0; 1831618Srie Dbg_util_nl(lml, DBG_NL_STD); 1840Sstevel@tonic-gate } 1850Sstevel@tonic-gate if (name) 1861618Srie dbg_print(lml, MSG_INTL(MSG_FIL_HDL_RETAIN), str, name); 1870Sstevel@tonic-gate else 1881618Srie dbg_print(lml, MSG_INTL(MSG_FIL_HDL_COLLECT), str, 1894734Sab196087 conv_grphdl_flags(ghp->gh_flags, &grphdl_flags_buf)); 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate void 1933731Srie Dbg_file_hdl_action(Grp_hdl *ghp, Rt_map *lmp, int type, uint_t flags) 1940Sstevel@tonic-gate { 1954734Sab196087 Conv_grpdesc_flags_buf_t grpdesc_flags_buf; 1963731Srie const char *mode, *group; 1973731Srie Lm_list *lml = LIST(lmp); 1983731Srie Msg str; 1990Sstevel@tonic-gate 2005067Srie static const Msg fmt[] = { 2015067Srie MSG_FIL_DEP_ADD, /* MSG_INTL(MSG_FIL_DEP_ADD) */ 2025067Srie MSG_FIL_DEP_UPDATE, /* MSG_INTL(MSG_FIL_DEP_UPDATE) */ 2035067Srie MSG_FIL_DEP_DELETE, /* MSG_INTL(MSG_FIL_DEP_DELETE) */ 2045067Srie MSG_FIL_DEP_REMOVE, /* MSG_INTL(MSG_FIL_DEP_REMOVE) */ 2055067Srie MSG_FIL_DEP_REMAIN, /* MSG_INTL(MSG_FIL_DEP_REMAIN) */ 2065067Srie MSG_FIL_DEP_ORPHAN, /* MSG_INTL(MSG_FIL_DEP_ORPHAN) */ 2075067Srie MSG_FIL_DEP_REINST, /* MSG_INTL(MSG_FIL_DEP_REINST) */ 2085067Srie }; 2091618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 2100Sstevel@tonic-gate return; 2110Sstevel@tonic-gate if (DBG_NOTDETAIL()) 2120Sstevel@tonic-gate return; 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate if (hdl_title) { 2151618Srie Dbg_util_nl(lml, DBG_NL_STD); 2160Sstevel@tonic-gate if (hdl_str) { 2170Sstevel@tonic-gate const char *name; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /* 2200Sstevel@tonic-gate * Protect ourselves in case this handle has no 2210Sstevel@tonic-gate * originating owner. 2220Sstevel@tonic-gate */ 2231618Srie if (ghp->gh_ownlmp) 2241618Srie name = NAME(ghp->gh_ownlmp); 2250Sstevel@tonic-gate else 2260Sstevel@tonic-gate name = MSG_INTL(MSG_STR_UNKNOWN); 2270Sstevel@tonic-gate 2281618Srie dbg_print(lml, MSG_INTL(hdl_str), name); 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate hdl_title = 0; 2310Sstevel@tonic-gate } 2320Sstevel@tonic-gate 2334734Sab196087 /* 2345067Srie * Establish a binding descriptor format string. 2354734Sab196087 */ 2365067Srie if (type > DBG_DEP_REINST) 2374734Sab196087 return; 2380Sstevel@tonic-gate 2395067Srie str = fmt[type]; 2405067Srie 2415067Srie if (((type == DBG_DEP_ADD) || (type == DBG_DEP_UPDATE)) && flags) 2424734Sab196087 group = conv_grpdesc_flags(flags, &grpdesc_flags_buf); 2433731Srie else 2443731Srie group = MSG_ORIG(MSG_STR_EMPTY); 2450Sstevel@tonic-gate 2463731Srie if ((MODE(lmp) & (RTLD_GLOBAL | RTLD_NODELETE)) == 2473731Srie (RTLD_GLOBAL | RTLD_NODELETE)) 2483731Srie mode = MSG_ORIG(MSG_MODE_GLOBNODEL); 2493731Srie else if (MODE(lmp) & RTLD_GLOBAL) 2503731Srie mode = MSG_ORIG(MSG_MODE_GLOB); 2513731Srie else if (MODE(lmp) & RTLD_NODELETE) 2523731Srie mode = MSG_ORIG(MSG_MODE_NODEL); 2533731Srie else 2543731Srie mode = MSG_ORIG(MSG_STR_EMPTY); 2553731Srie 2563731Srie dbg_print(lml, MSG_INTL(str), NAME(lmp), mode, group); 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate void 2601618Srie Dbg_file_bind_entry(Lm_list *lml, Bnd_desc *bdp) 2610Sstevel@tonic-gate { 2624734Sab196087 Conv_bnd_type_buf_t bnd_type_buf; 2634734Sab196087 2641618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 2650Sstevel@tonic-gate return; 2660Sstevel@tonic-gate if (DBG_NOTDETAIL()) 2670Sstevel@tonic-gate return; 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate /* 2700Sstevel@tonic-gate * Print the dependency together with the modes of the binding. 2710Sstevel@tonic-gate */ 2721618Srie Dbg_util_nl(lml, DBG_NL_STD); 2731618Srie dbg_print(lml, MSG_INTL(MSG_FIL_BND_ADD), NAME(bdp->b_caller)); 2741618Srie dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE), NAME(bdp->b_depend), 2754734Sab196087 conv_bnd_type(bdp->b_flags, &bnd_type_buf)); 276280Srie } 277280Srie 278280Srie void 2791618Srie Dbg_file_bindings(Rt_map *lmp, int flag) 280280Srie { 2814734Sab196087 Conv_bnd_obj_buf_t bnd_obj_buf; 2824734Sab196087 Conv_bnd_type_buf_t bnd_type_buf; 283280Srie const char *str; 284280Srie Rt_map *tlmp; 2851618Srie Lm_list *lml = LIST(lmp); 286280Srie int next = 0; 287280Srie 2881618Srie if (DBG_NOTCLASS(DBG_C_INIT)) 289280Srie return; 290280Srie if (DBG_NOTDETAIL()) 291280Srie return; 292280Srie 293280Srie if (flag & RT_SORT_REV) 294280Srie str = MSG_ORIG(MSG_SCN_INIT); 295280Srie else 296280Srie str = MSG_ORIG(MSG_SCN_FINI); 297280Srie 2981618Srie Dbg_util_nl(lml, DBG_NL_STD); 2991618Srie dbg_print(lml, MSG_INTL(MSG_FIL_DEP_TITLE), str, 3004734Sab196087 conv_bnd_obj(lml->lm_flags, &bnd_obj_buf)); 301280Srie 302280Srie /* LINTED */ 303280Srie for (tlmp = lmp; tlmp; tlmp = (Rt_map *)NEXT(tlmp)) { 3045892Sab196087 Bnd_desc *bdp; 3055892Sab196087 Aliste idx; 306280Srie 307280Srie /* 308280Srie * For .init processing, only collect objects that have been 309280Srie * relocated and haven't already been collected. 310280Srie * For .fini processing, only collect objects that have had 311280Srie * their .init collected, and haven't already been .fini 312280Srie * collected. 313280Srie */ 314280Srie if (flag & RT_SORT_REV) { 315280Srie if ((FLAGS(tlmp) & (FLG_RT_RELOCED | 316280Srie FLG_RT_INITCLCT)) != FLG_RT_RELOCED) 317280Srie continue; 318280Srie 319280Srie } else { 320280Srie if ((flag & RT_SORT_DELETE) && 321280Srie ((FLAGS(tlmp) & FLG_RT_DELETE) == 0)) 322280Srie continue; 323280Srie if (((FLAGS(tlmp) & 324280Srie (FLG_RT_INITCLCT | FLG_RT_FINICLCT)) == 325280Srie FLG_RT_INITCLCT) == 0) 326280Srie continue; 327280Srie } 328280Srie 329280Srie if (next++) 3301618Srie Dbg_util_nl(lml, DBG_NL_STD); 331280Srie 3325892Sab196087 if (DEPENDS(tlmp) == NULL) 3331618Srie dbg_print(lml, MSG_INTL(MSG_FIL_DEP_NONE), NAME(tlmp)); 334280Srie else { 3351618Srie dbg_print(lml, MSG_INTL(MSG_FIL_DEP_ENT), NAME(tlmp)); 336280Srie 3375892Sab196087 for (APLIST_TRAVERSE(DEPENDS(tlmp), idx, bdp)) { 3381618Srie dbg_print(lml, MSG_INTL(MSG_FIL_BND_FILE), 3395892Sab196087 NAME(bdp->b_depend), 3405892Sab196087 conv_bnd_type(bdp->b_flags, 3414734Sab196087 &bnd_type_buf)); 342280Srie } 343280Srie } 344280Srie } 3451618Srie Dbg_util_nl(lml, DBG_NL_STD); 3460Sstevel@tonic-gate } 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate void 3496387Srie Dbg_file_dlopen(Rt_map *clmp, const char *name, int *in_nfavl, int mode) 3500Sstevel@tonic-gate { 3514734Sab196087 Conv_dl_mode_buf_t dl_mode_buf; 3524734Sab196087 Lm_list *lml = LIST(clmp); 3536387Srie const char *retry; 3541618Srie 3551618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 3560Sstevel@tonic-gate return; 3570Sstevel@tonic-gate 3586387Srie /* 3596387Srie * The core functionality of dlopen() can be called twice. The first 3606387Srie * attempt can be affected by path names that exist in the "not-found" 3616387Srie * AVL tree. Should a "not-found" path name be found, a second attempt 3626387Srie * is made to locate the required file (in_nfavl is NULL). This fall- 3636387Srie * back provides for file system changes while a process executes. 3646387Srie */ 3656387Srie if (in_nfavl) 3666387Srie retry = MSG_ORIG(MSG_STR_EMPTY); 3676387Srie else 3686387Srie retry = MSG_INTL(MSG_STR_RETRY); 3696387Srie 3701618Srie Dbg_util_nl(lml, DBG_NL_STD); 3716387Srie dbg_print(lml, MSG_INTL(MSG_FIL_DLOPEN), name, NAME(clmp), retry, 3724734Sab196087 conv_dl_mode(mode, 1, &dl_mode_buf)); 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate void 3761618Srie Dbg_file_dlclose(Lm_list *lml, const char *name, int flag) 3770Sstevel@tonic-gate { 3780Sstevel@tonic-gate const char *str; 3790Sstevel@tonic-gate 3801618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 3810Sstevel@tonic-gate return; 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate if (flag == DBG_DLCLOSE_IGNORE) 3840Sstevel@tonic-gate str = MSG_INTL(MSG_STR_IGNORE); 3850Sstevel@tonic-gate else 3860Sstevel@tonic-gate str = MSG_ORIG(MSG_STR_EMPTY); 3870Sstevel@tonic-gate 3881618Srie Dbg_util_nl(lml, DBG_NL_STD); 3891618Srie dbg_print(lml, MSG_INTL(MSG_FIL_DLCLOSE), name, str); 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate void 3931618Srie Dbg_file_dldump(Rt_map *lmp, const char *path, int flags) 3940Sstevel@tonic-gate { 3954734Sab196087 Conv_dl_flag_buf_t dl_flag_buf; 3964734Sab196087 Lm_list *lml = LIST(lmp); 3971618Srie 3981618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 3990Sstevel@tonic-gate return; 4000Sstevel@tonic-gate 4011618Srie Dbg_util_nl(lml, DBG_NL_STD); 4021618Srie dbg_print(lml, MSG_INTL(MSG_FIL_DLDUMP), NAME(lmp), path, 4034734Sab196087 conv_dl_flag(flags, 0, &dl_flag_buf)); 4040Sstevel@tonic-gate } 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate void 4071618Srie Dbg_file_lazyload(Rt_map *clmp, const char *fname, const char *sname) 4080Sstevel@tonic-gate { 4091618Srie Lm_list *lml = LIST(clmp); 4101618Srie 4111618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 4120Sstevel@tonic-gate return; 4130Sstevel@tonic-gate 4141618Srie Dbg_util_nl(lml, DBG_NL_STD); 4151618Srie dbg_print(lml, MSG_INTL(MSG_FIL_LAZYLOAD), fname, NAME(clmp), 4161618Srie Dbg_demangle_name(sname)); 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate void 4201618Srie Dbg_file_preload(Lm_list *lml, const char *name) 4210Sstevel@tonic-gate { 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_PRELOAD), name); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate void 4301618Srie Dbg_file_needed(Rt_map *lmp, const char *name) 4310Sstevel@tonic-gate { 4321618Srie Lm_list *lml = LIST(lmp); 4331618Srie 4341618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 4350Sstevel@tonic-gate return; 4360Sstevel@tonic-gate 4371618Srie Dbg_util_nl(lml, DBG_NL_STD); 4381618Srie dbg_print(lml, MSG_INTL(MSG_FIL_NEEDED), name, NAME(lmp)); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate void 4421618Srie Dbg_file_filter(Lm_list *lml, const char *filter, const char *filtee, 4431618Srie int config) 4440Sstevel@tonic-gate { 4451618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 4460Sstevel@tonic-gate return; 4470Sstevel@tonic-gate 4481618Srie Dbg_util_nl(lml, DBG_NL_STD); 4490Sstevel@tonic-gate if (config) 4501618Srie dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_1), filter, filtee); 4510Sstevel@tonic-gate else 4521618Srie dbg_print(lml, MSG_INTL(MSG_FIL_FILTER_2), filter, filtee); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate void 4561618Srie Dbg_file_filtee(Lm_list *lml, const char *filter, const char *filtee, int audit) 4570Sstevel@tonic-gate { 4580Sstevel@tonic-gate if (audit) { 4591618Srie if (DBG_NOTCLASS(DBG_C_AUDITING | DBG_C_FILES)) 4600Sstevel@tonic-gate return; 4610Sstevel@tonic-gate 4621618Srie Dbg_util_nl(lml, DBG_NL_STD); 4631618Srie dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_3), filtee); 4640Sstevel@tonic-gate } else { 4651618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 4660Sstevel@tonic-gate return; 4670Sstevel@tonic-gate 4681618Srie Dbg_util_nl(lml, DBG_NL_STD); 4690Sstevel@tonic-gate if (filter) 4701618Srie dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_1), filtee, 4711618Srie filter); 4720Sstevel@tonic-gate else 4731618Srie dbg_print(lml, MSG_INTL(MSG_FIL_FILTEE_2), filtee); 4740Sstevel@tonic-gate } 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate void 4781618Srie Dbg_file_fixname(Lm_list *lml, const char *oname, const char *nname) 4790Sstevel@tonic-gate { 4801618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 4810Sstevel@tonic-gate return; 4820Sstevel@tonic-gate 4831618Srie Dbg_util_nl(lml, DBG_NL_STD); 4841618Srie dbg_print(lml, MSG_INTL(MSG_FIL_FIXNAME), oname, nname); 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate void 4880Sstevel@tonic-gate Dbg_file_output(Ofl_desc *ofl) 4890Sstevel@tonic-gate { 4900Sstevel@tonic-gate const char *prefix = MSG_ORIG(MSG_PTH_OBJECT); 4910Sstevel@tonic-gate char *oname, *nname, *ofile; 4920Sstevel@tonic-gate int fd; 4930Sstevel@tonic-gate 4941618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 4950Sstevel@tonic-gate return; 4960Sstevel@tonic-gate if (DBG_NOTDETAIL()) 4970Sstevel@tonic-gate return; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate /* 5000Sstevel@tonic-gate * Obtain the present input object filename for concatenation to the 5010Sstevel@tonic-gate * prefix name. 5020Sstevel@tonic-gate */ 5030Sstevel@tonic-gate oname = (char *)ofl->ofl_name; 5040Sstevel@tonic-gate if ((ofile = strrchr(oname, '/')) == NULL) 5050Sstevel@tonic-gate ofile = oname; 5060Sstevel@tonic-gate else 5070Sstevel@tonic-gate ofile++; 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate /* 5100Sstevel@tonic-gate * Concatenate the prefix with the object filename, open the file and 5110Sstevel@tonic-gate * write out the present Elf memory image. As this is debugging we 5120Sstevel@tonic-gate * ignore all errors. 5130Sstevel@tonic-gate */ 5141618Srie if ((nname = malloc(strlen(prefix) + strlen(ofile) + 1)) != 0) { 5150Sstevel@tonic-gate (void) strcpy(nname, prefix); 5160Sstevel@tonic-gate (void) strcat(nname, ofile); 5170Sstevel@tonic-gate if ((fd = open(nname, O_RDWR | O_CREAT | O_TRUNC, 5180Sstevel@tonic-gate 0666)) != -1) { 5191618Srie (void) write(fd, ofl->ofl_nehdr, ofl->ofl_size); 5201618Srie (void) close(fd); 5210Sstevel@tonic-gate } 5220Sstevel@tonic-gate free(nname); 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate void 5271618Srie Dbg_file_config_dis(Lm_list *lml, const char *config, int features) 5280Sstevel@tonic-gate { 5294734Sab196087 Conv_config_feat_buf_t config_feat_buf; 5304734Sab196087 const char *str; 5310Sstevel@tonic-gate 5321976Sab196087 switch (features & ~CONF_FEATMSK) { 5331976Sab196087 case DBG_CONF_IGNORE: 5340Sstevel@tonic-gate str = MSG_INTL(MSG_FIL_CONFIG_ERR_1); 5351976Sab196087 break; 5361976Sab196087 case DBG_CONF_VERSION: 5370Sstevel@tonic-gate str = MSG_INTL(MSG_FIL_CONFIG_ERR_2); 5381976Sab196087 break; 5391976Sab196087 case DBG_CONF_PRCFAIL: 5400Sstevel@tonic-gate str = MSG_INTL(MSG_FIL_CONFIG_ERR_3); 5411976Sab196087 break; 5421976Sab196087 case DBG_CONF_CORRUPT: 5430Sstevel@tonic-gate str = MSG_INTL(MSG_FIL_CONFIG_ERR_4); 5441976Sab196087 break; 5451976Sab196087 case DBG_CONF_ABIMISMATCH: 5461976Sab196087 str = MSG_INTL(MSG_FIL_CONFIG_ERR_5); 5471976Sab196087 break; 5481976Sab196087 default: 5494734Sab196087 str = conv_config_feat(features, &config_feat_buf); 5501976Sab196087 break; 5511976Sab196087 } 5520Sstevel@tonic-gate 5531618Srie Dbg_util_nl(lml, DBG_NL_FRC); 5541618Srie dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG_ERR), config, str); 5551618Srie Dbg_util_nl(lml, DBG_NL_FRC); 5560Sstevel@tonic-gate } 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate void 5591618Srie Dbg_file_config_obj(Lm_list *lml, const char *dir, const char *file, 5601618Srie const char *config) 5610Sstevel@tonic-gate { 5620Sstevel@tonic-gate char *name, _name[PATH_MAX]; 5630Sstevel@tonic-gate 5641618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 5650Sstevel@tonic-gate return; 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate if (file) { 5680Sstevel@tonic-gate (void) snprintf(_name, PATH_MAX, MSG_ORIG(MSG_FMT_PATH), 5690Sstevel@tonic-gate dir, file); 5700Sstevel@tonic-gate name = _name; 5710Sstevel@tonic-gate } else 5720Sstevel@tonic-gate name = (char *)dir; 5730Sstevel@tonic-gate 5741618Srie dbg_print(lml, MSG_INTL(MSG_FIL_CONFIG), name, config); 5751618Srie } 5761618Srie 5771618Srie void 5781618Srie Dbg_file_del_rescan(Lm_list *lml) 5791618Srie { 5801618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 5811618Srie return; 5821618Srie 5831618Srie Dbg_util_nl(lml, DBG_NL_STD); 5841618Srie dbg_print(lml, MSG_INTL(MSG_FIL_DEL_RESCAN)); 5851618Srie } 5861618Srie 5871618Srie void 5881618Srie Dbg_file_mode_promote(Rt_map *lmp, int mode) 5891618Srie { 5904734Sab196087 Conv_dl_mode_buf_t dl_mode_buf; 5914734Sab196087 Lm_list *lml = LIST(lmp); 5921618Srie 5931618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 5941618Srie return; 5951618Srie 5961618Srie Dbg_util_nl(lml, DBG_NL_STD); 5971618Srie dbg_print(lml, MSG_INTL(MSG_FIL_PROMOTE), NAME(lmp), 5984734Sab196087 conv_dl_mode(mode, 0, &dl_mode_buf)); 5991618Srie Dbg_util_nl(lml, DBG_NL_STD); 6000Sstevel@tonic-gate } 6010Sstevel@tonic-gate 6021618Srie void 6031618Srie Dbg_file_cntl(Lm_list *lml, Aliste flmco, Aliste tlmco) 6041618Srie { 6051618Srie Lm_cntl *lmc; 6061618Srie Aliste off; 6071618Srie 6081618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 6091618Srie return; 6101618Srie if (DBG_NOTDETAIL()) 6111618Srie return; 6121618Srie 6131618Srie Dbg_util_nl(lml, DBG_NL_STD); 6141618Srie dbg_print(lml, MSG_INTL(MSG_CNTL_TITLE), EC_XWORD(flmco), 6151618Srie EC_XWORD(tlmco)); 6161618Srie 6175892Sab196087 for (ALIST_TRAVERSE_BY_OFFSET(lml->lm_lists, off, lmc)) { 6181618Srie Rt_map *lmp; 6191618Srie 6201618Srie /* LINTED */ 6211618Srie for (lmp = lmc->lc_head; lmp; lmp = (Rt_map *)NEXT(lmp)) 6221618Srie dbg_print(lml, MSG_ORIG(MSG_CNTL_ENTRY), EC_XWORD(off), 6231618Srie NAME(lmp)); 6241618Srie } 6251618Srie Dbg_util_nl(lml, DBG_NL_STD); 6261618Srie } 6271618Srie 628*7983SAli.Bahrami@Sun.COM /* 629*7983SAli.Bahrami@Sun.COM * Report archive rescan operation. 630*7983SAli.Bahrami@Sun.COM * argv_start_ndx, argv_end_ndx - Index range of command line arguments 631*7983SAli.Bahrami@Sun.COM * from which archives are to be reprocessed. 632*7983SAli.Bahrami@Sun.COM */ 6331618Srie void 634*7983SAli.Bahrami@Sun.COM Dbg_file_ar_rescan(Lm_list *lml, int argv_start_ndx, int argv_end_ndx) 6351618Srie { 6361618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 6371618Srie return; 6380Sstevel@tonic-gate 6391618Srie Dbg_util_nl(lml, DBG_NL_STD); 640*7983SAli.Bahrami@Sun.COM dbg_print(lml, MSG_INTL(MSG_FIL_AR_RESCAN), 641*7983SAli.Bahrami@Sun.COM argv_start_ndx, argv_end_ndx); 6421618Srie Dbg_util_nl(lml, DBG_NL_STD); 6431618Srie } 6441618Srie 6451618Srie void 6461618Srie Dbg_file_ar(Lm_list *lml, const char *name, int again) 6471618Srie { 6481618Srie const char *str; 6491618Srie 6501618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 6511618Srie return; 6521618Srie 6531618Srie if (again) 6541618Srie str = MSG_INTL(MSG_STR_AGAIN); 6551618Srie else 6561618Srie str = MSG_ORIG(MSG_STR_EMPTY); 6571618Srie 6581618Srie Dbg_util_nl(lml, DBG_NL_STD); 6591618Srie dbg_print(lml, MSG_INTL(MSG_FIL_ARCHIVE), name, str); 6601618Srie } 6611618Srie 6621618Srie void 6631618Srie Dbg_file_generic(Lm_list *lml, Ifl_desc *ifl) 6641618Srie { 6654734Sab196087 Conv_inv_buf_t inv_buf; 6664734Sab196087 6671618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 6681618Srie return; 6691618Srie 6701618Srie Dbg_util_nl(lml, DBG_NL_STD); 6711618Srie dbg_print(lml, MSG_INTL(MSG_FIL_BASIC), ifl->ifl_name, 6724734Sab196087 conv_ehdr_type(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) */ 6890Sstevel@tonic-gate MSG_REJ_HWCAP_1, /* MSG_INTL(MSG_REJ_HWCAP_1) */ 6900Sstevel@tonic-gate }; 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate void 6936206Sab196087 Dbg_file_rejected(Lm_list *lml, Rej_desc *rej, Half mach) 6940Sstevel@tonic-gate { 6954734Sab196087 Conv_reject_desc_buf_t rej_buf; 6964734Sab196087 6971618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 6980Sstevel@tonic-gate return; 6990Sstevel@tonic-gate 7001618Srie Dbg_util_nl(lml, DBG_NL_STD); 7011618Srie dbg_print(lml, MSG_INTL(reject[rej->rej_type]), rej->rej_name ? 7024734Sab196087 rej->rej_name : MSG_INTL(MSG_STR_UNKNOWN), 7036206Sab196087 conv_reject_desc(rej, &rej_buf, mach)); 7041618Srie Dbg_util_nl(lml, DBG_NL_STD); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate void 7081618Srie Dbg_file_reuse(Lm_list *lml, const char *nname, const char *oname) 7090Sstevel@tonic-gate { 7101618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 7110Sstevel@tonic-gate return; 7120Sstevel@tonic-gate 7131618Srie dbg_print(lml, MSG_INTL(MSG_FIL_REUSE), nname, oname); 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate void 7171618Srie Dbg_file_skip(Lm_list *lml, const char *oname, const char *nname) 7180Sstevel@tonic-gate { 7191618Srie if (DBG_NOTCLASS(DBG_C_FILES)) 7200Sstevel@tonic-gate return; 7210Sstevel@tonic-gate 7221618Srie if (oname && strcmp(nname, oname)) 7231618Srie dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_1), nname, oname); 7241618Srie else 7251618Srie dbg_print(lml, MSG_INTL(MSG_FIL_SKIP_2), nname); 7260Sstevel@tonic-gate } 7272978Srie 7282978Srie void 7292978Srie Dbg_file_modified(Lm_list *lml, const char *obj, const char *oname, 7302978Srie const char *nname, int ofd, int nfd, Elf *oelf, Elf *nelf) 7312978Srie { 7322978Srie const char *str; 7332978Srie 7342978Srie if (DBG_NOTCLASS(DBG_C_FILES | DBG_C_SUPPORT)) 7352978Srie return; 7362978Srie if (DBG_NOTDETAIL()) 7372978Srie return; 7382978Srie 7392978Srie Dbg_util_nl(lml, DBG_NL_STD); 7402978Srie dbg_print(lml, MSG_INTL(MSG_FIL_MODIFIED), oname, obj); 7412978Srie 7422978Srie if (nname != oname) 7432978Srie dbg_print(lml, MSG_INTL(MSG_FIL_NAMECHANGE), nname); 7442978Srie if (nfd != ofd) { 7452978Srie if (nfd == -1) 7462978Srie str = MSG_INTL(MSG_FIL_IGNORE); 7472978Srie else 7482978Srie str = MSG_ORIG(MSG_STR_EMPTY); 7492978Srie dbg_print(lml, MSG_INTL(MSG_FIL_FDCHANGE), ofd, nfd, str); 7502978Srie } 7512978Srie if (nelf != oelf) { 7522978Srie if (nelf == 0) 7532978Srie str = MSG_INTL(MSG_FIL_IGNORE); 7542978Srie else 7552978Srie str = MSG_ORIG(MSG_STR_EMPTY); 7562978Srie dbg_print(lml, MSG_INTL(MSG_FIL_ELFCHANGE), EC_NATPTR(oelf), 7572978Srie EC_NATPTR(nelf), str); 7582978Srie } 7592978Srie Dbg_util_nl(lml, DBG_NL_STD); 7602978Srie } 7613731Srie 7623731Srie void 7633731Srie Dbg_file_cleanup(Lm_list *lml, const char *name, Aliste lmco) 7643731Srie { 7653731Srie if (DBG_NOTCLASS(DBG_C_FILES)) 7663731Srie return; 7673731Srie 7683731Srie Dbg_util_nl(lml, DBG_NL_STD); 7693731Srie dbg_print(lml, MSG_INTL(MSG_FIL_CLEANUP), name, EC_XWORD(lmco)); 7703731Srie } 771