17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 215aefb655Srie 227c478bd9Sstevel@tonic-gate /* 2356deab07SRod Evans * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include "msg.h" 287c478bd9Sstevel@tonic-gate #include "_debug.h" 297c478bd9Sstevel@tonic-gate #include "libld.h" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * If any run-time linker debugging is being carried out always indicate the 337c478bd9Sstevel@tonic-gate * fact and specify the point at which we transfer control to the main program. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate void 365aefb655Srie Dbg_util_call_main(Rt_map *lmp) 377c478bd9Sstevel@tonic-gate { 385aefb655Srie Lm_list *lml = LIST(lmp); 395aefb655Srie 405aefb655Srie Dbg_util_nl(lml, DBG_NL_FRC); 415aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_TRANS), NAME(lmp)); 425aefb655Srie Dbg_util_nl(lml, DBG_NL_FRC); 437c478bd9Sstevel@tonic-gate } 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate void 465aefb655Srie Dbg_util_call_init(Rt_map *lmp, int flag) 477c478bd9Sstevel@tonic-gate { 485aefb655Srie Lm_list *lml = LIST(lmp); 497c478bd9Sstevel@tonic-gate const char *str; 507c478bd9Sstevel@tonic-gate 515aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 52dffec89cSrie return; 53dffec89cSrie 547c478bd9Sstevel@tonic-gate if (flag == DBG_INIT_SORT) 557c478bd9Sstevel@tonic-gate str = MSG_INTL(MSG_UTL_SORT); 567c478bd9Sstevel@tonic-gate else if (flag == DBG_INIT_PEND) 577c478bd9Sstevel@tonic-gate str = MSG_INTL(MSG_UTL_PEND); 587c478bd9Sstevel@tonic-gate else if (flag == DBG_INIT_DYN) 597c478bd9Sstevel@tonic-gate str = MSG_INTL(MSG_UTL_DYN); 607c478bd9Sstevel@tonic-gate else 617c478bd9Sstevel@tonic-gate str = MSG_INTL(MSG_UTL_DONE); 627c478bd9Sstevel@tonic-gate 635aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 645aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_INIT), str, NAME(lmp)); 655aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 667c478bd9Sstevel@tonic-gate } 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate void 695aefb655Srie Dbg_util_intoolate(Rt_map *lmp) 707c478bd9Sstevel@tonic-gate { 715aefb655Srie Lm_list *lml = LIST(lmp); 725aefb655Srie 735aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 745aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_INTOOLATE), NAME(lmp)); 755aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 767c478bd9Sstevel@tonic-gate } 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate void 795aefb655Srie Dbg_util_dbnotify(Lm_list *lml, rd_event_e event, r_state_e state) 807c478bd9Sstevel@tonic-gate { 817c478bd9Sstevel@tonic-gate const char *estr; 827c478bd9Sstevel@tonic-gate const char *sstr; 837c478bd9Sstevel@tonic-gate 845aefb655Srie if (DBG_NOTCLASS(DBG_C_FILES)) 857c478bd9Sstevel@tonic-gate return; 867c478bd9Sstevel@tonic-gate if (DBG_NOTDETAIL()) 877c478bd9Sstevel@tonic-gate return; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate switch (event) { 907c478bd9Sstevel@tonic-gate case RD_PREINIT: 917c478bd9Sstevel@tonic-gate estr = MSG_ORIG(MSG_UTL_EVNT_PREINIT); 927c478bd9Sstevel@tonic-gate sstr = MSG_INTL(MSG_STR_NULL); 937c478bd9Sstevel@tonic-gate break; 947c478bd9Sstevel@tonic-gate case RD_POSTINIT: 957c478bd9Sstevel@tonic-gate estr = MSG_ORIG(MSG_UTL_EVNT_POSTINIT); 967c478bd9Sstevel@tonic-gate sstr = MSG_INTL(MSG_STR_NULL); 977c478bd9Sstevel@tonic-gate break; 987c478bd9Sstevel@tonic-gate case RD_DLACTIVITY: 997c478bd9Sstevel@tonic-gate estr = MSG_ORIG(MSG_UTL_EVNT_DLACT); 1007c478bd9Sstevel@tonic-gate switch (state) { 1017c478bd9Sstevel@tonic-gate case RT_CONSISTENT: 1027c478bd9Sstevel@tonic-gate sstr = MSG_ORIG(MSG_UTL_STA_CONSIST); 1037c478bd9Sstevel@tonic-gate break; 1047c478bd9Sstevel@tonic-gate case RT_ADD: 1057c478bd9Sstevel@tonic-gate sstr = MSG_ORIG(MSG_UTL_STA_ADD); 1067c478bd9Sstevel@tonic-gate break; 1077c478bd9Sstevel@tonic-gate case RT_DELETE: 1087c478bd9Sstevel@tonic-gate sstr = MSG_ORIG(MSG_UTL_STA_DELETE); 1097c478bd9Sstevel@tonic-gate break; 1107c478bd9Sstevel@tonic-gate default: 1117c478bd9Sstevel@tonic-gate sstr = MSG_INTL(MSG_STR_NULL); 1127c478bd9Sstevel@tonic-gate break; 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate break; 1157c478bd9Sstevel@tonic-gate default: 1167c478bd9Sstevel@tonic-gate sstr = MSG_INTL(MSG_STR_NULL); 1177c478bd9Sstevel@tonic-gate estr = MSG_INTL(MSG_STR_UNKNOWN); 1187c478bd9Sstevel@tonic-gate break; 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate 1215aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 1225aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_DBNOTIFY), estr, sstr); 1235aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate void 1275aefb655Srie Dbg_util_call_array(Rt_map *lmp, void *addr, int ndx, Word shtype) 1287c478bd9Sstevel@tonic-gate { 1295aefb655Srie Lm_list *lml = LIST(lmp); 1307c478bd9Sstevel@tonic-gate const char *str; 1317c478bd9Sstevel@tonic-gate 1325aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 1337c478bd9Sstevel@tonic-gate return; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate if (shtype == SHT_INIT_ARRAY) 1367c478bd9Sstevel@tonic-gate str = MSG_ORIG(MSG_SCN_INITARRAY); 1377c478bd9Sstevel@tonic-gate else if (shtype == SHT_FINI_ARRAY) 1387c478bd9Sstevel@tonic-gate str = MSG_ORIG(MSG_SCN_FINIARRAY); 1397c478bd9Sstevel@tonic-gate else 1407c478bd9Sstevel@tonic-gate str = MSG_ORIG(MSG_SCN_PREINITARRAY); 1415aefb655Srie 1425aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_ARRAY), str, ndx, EC_NATPTR(addr), 1435aefb655Srie NAME(lmp)); 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate void 1475aefb655Srie Dbg_util_call_fini(Rt_map *lmp) 1487c478bd9Sstevel@tonic-gate { 1495aefb655Srie Lm_list *lml = LIST(lmp); 1505aefb655Srie 1515aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 152dffec89cSrie return; 153dffec89cSrie 1545aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 1555aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_FINI), NAME(lmp)); 1565aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate void 1605aefb655Srie Dbg_util_str(Lm_list *lml, const char *str) 1617c478bd9Sstevel@tonic-gate { 1625aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 1635aefb655Srie Dbg_util_nl(lml, DBG_NL_FRC); 1645aefb655Srie dbg_print(lml, MSG_ORIG(MSG_FMT_STR), str); 1655aefb655Srie Dbg_util_nl(lml, DBG_NL_FRC); 1665aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate void 1705aefb655Srie Dbg_util_scc_title(Lm_list *lml, int sec) 1717c478bd9Sstevel@tonic-gate { 1727c478bd9Sstevel@tonic-gate const char *_sec; 1737c478bd9Sstevel@tonic-gate 1745aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 175dffec89cSrie return; 176dffec89cSrie if (DBG_NOTDETAIL()) 177dffec89cSrie return; 178dffec89cSrie 1797c478bd9Sstevel@tonic-gate if (sec) 180dffec89cSrie _sec = MSG_INTL(MSG_UTL_SCC_SUBI); 1817c478bd9Sstevel@tonic-gate else 182dffec89cSrie _sec = MSG_INTL(MSG_UTL_SCC_SUBF); 1837c478bd9Sstevel@tonic-gate 1845aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 1855aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_SCC_TITLE), _sec); 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate void 1895aefb655Srie Dbg_util_scc_entry(Rt_map *lmp, uint_t idx) 1907c478bd9Sstevel@tonic-gate { 1915aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 192dffec89cSrie return; 193dffec89cSrie if (DBG_NOTDETAIL()) 194dffec89cSrie return; 195dffec89cSrie 1965aefb655Srie dbg_print(LIST(lmp), MSG_ORIG(MSG_UTL_SCC_ENTRY), idx, NAME(lmp)); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 199dffec89cSrie static int ectoggle = 0; 200dffec89cSrie 201dffec89cSrie void 2025aefb655Srie Dbg_util_edge_in(Lm_list *lml, Rt_map *clmp, uint_t flags, Rt_map *dlmp, 2035aefb655Srie int ndx, int flag) 204dffec89cSrie { 205de777a60Sab196087 Conv_bnd_type_buf_t bnd_type_buf; 206dffec89cSrie const char *str; 207dffec89cSrie 2085aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 209dffec89cSrie return; 210dffec89cSrie if (DBG_NOTDETAIL()) 211dffec89cSrie return; 212dffec89cSrie 213dffec89cSrie if (flag & RT_SORT_REV) 214dffec89cSrie str = MSG_ORIG(MSG_SCN_INIT); 215dffec89cSrie else 216dffec89cSrie str = MSG_ORIG(MSG_SCN_FINI); 217dffec89cSrie 218dffec89cSrie if ((clmp == 0) || (ectoggle == 0)) 2195aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 220dffec89cSrie if (clmp == 0) { 221883c6d49Srie if (flag & RT_SORT_INTPOSE) 222883c6d49Srie dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_TITLE_I), str); 223883c6d49Srie else 224883c6d49Srie dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_TITLE_S), str); 225883c6d49Srie 2265aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_START), ndx, NAME(dlmp)); 227dffec89cSrie } else 2285aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_IN), ndx, NAME(dlmp), 229de777a60Sab196087 NAME(clmp), conv_bnd_type(flags, &bnd_type_buf)); 230dffec89cSrie 231dffec89cSrie ectoggle = 1; 232dffec89cSrie } 233dffec89cSrie 234dffec89cSrie void 2355aefb655Srie Dbg_util_edge_out(Rt_map *clmp, Rt_map *dlmp) 236dffec89cSrie { 2375aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 238dffec89cSrie return; 239dffec89cSrie if (DBG_NOTDETAIL()) 240dffec89cSrie return; 241dffec89cSrie 2425aefb655Srie dbg_print(LIST(clmp), MSG_INTL(MSG_UTL_EDGE_OUT), SORTVAL(clmp), 2435aefb655Srie NAME(clmp), NAME(dlmp)); 244dffec89cSrie } 245dffec89cSrie 246dffec89cSrie void 2475aefb655Srie Dbg_util_collect(Rt_map *lmp, int ndx, int flag) 248dffec89cSrie { 2495aefb655Srie Lm_list *lml = LIST(lmp); 250dffec89cSrie const char *str; 251dffec89cSrie 2525aefb655Srie if (DBG_NOTCLASS(DBG_C_INIT)) 253dffec89cSrie return; 254dffec89cSrie if (DBG_NOTDETAIL()) 255dffec89cSrie return; 256dffec89cSrie 257dffec89cSrie if (flag & RT_SORT_REV) 258dffec89cSrie str = MSG_ORIG(MSG_SCN_INIT); 259dffec89cSrie else 260dffec89cSrie str = MSG_ORIG(MSG_SCN_FINI); 261dffec89cSrie 262dffec89cSrie if (ectoggle == 1) { 2635aefb655Srie Dbg_util_nl(lml, DBG_NL_STD); 264dffec89cSrie ectoggle = 0; 265dffec89cSrie } 2665aefb655Srie dbg_print(lml, MSG_INTL(MSG_UTL_COLLECT), ndx, NAME(lmp), str); 2675aefb655Srie } 2685aefb655Srie 26910a4fa49Srie static const Msg tags[] = { 27010a4fa49Srie MSG_CI_NULL, /* MSG_ORIG(MSG_CI_NULL) */ 27110a4fa49Srie MSG_CI_VERSION, /* MSG_ORIG(MSG_CI_VERSION) */ 27210a4fa49Srie MSG_CI_ATEXIT, /* MSG_ORIG(MSG_CI_ATEXIT) */ 27310a4fa49Srie MSG_CI_LCMESSAGES, /* MSG_ORIG(MSG_CI_LCMESSAGES) */ 27410a4fa49Srie MSG_CI_BIND_GUARD, /* MSG_ORIG(MSG_CI_BIND_GUARD) */ 27510a4fa49Srie MSG_CI_BIND_CLEAR, /* MSG_ORIG(MSG_CI_BIND_CLEAR) */ 27610a4fa49Srie MSG_CI_THR_SELF, /* MSG_ORIG(MSG_CI_THR_SELF) */ 27710a4fa49Srie MSG_CI_TLS_MODADD, /* MSG_ORIG(MSG_CI_TLS_MODADD) */ 27810a4fa49Srie MSG_CI_TLS_MODREM, /* MSG_ORIG(MSG_CI_TLS_MODREM) */ 27910a4fa49Srie MSG_CI_TLS_STATMOD, /* MSG_ORIG(MSG_CI_TLS_STATMOD) */ 280*2a8d6ebaSRod Evans MSG_CI_THRINIT, /* MSG_ORIG(MSG_CI_THRINIT) */ 281*2a8d6ebaSRod Evans MSG_CI_CRITICAL /* MSG_ORIG(MSG_CI_CRITICAL) */ 28210a4fa49Srie }; 28310a4fa49Srie 28410a4fa49Srie void 28510a4fa49Srie Dbg_util_lcinterface(Rt_map *lmp, int tag, char *val) 28610a4fa49Srie { 28710a4fa49Srie const char *str; 288de777a60Sab196087 Conv_inv_buf_t inv_buf; 28910a4fa49Srie 29010a4fa49Srie if (DBG_NOTDETAIL()) 29110a4fa49Srie return; 29210a4fa49Srie 29310a4fa49Srie if (tag < CI_MAX) 29410a4fa49Srie str = MSG_ORIG(tags[tag]); 29510a4fa49Srie else 296de777a60Sab196087 str = conv_invalid_val(&inv_buf, tag, 0); 29710a4fa49Srie 29810a4fa49Srie dbg_print(LIST(lmp), MSG_INTL(MSG_UTL_LCINTERFACE), NAME(lmp), str, 29910a4fa49Srie EC_NATPTR(val)); 30010a4fa49Srie } 30110a4fa49Srie 30210a4fa49Srie void 30310a4fa49Srie Dbg_unused_lcinterface(Rt_map *nlmp, Rt_map *olmp, int tag) 30410a4fa49Srie { 30510a4fa49Srie const char *str; 306de777a60Sab196087 Conv_inv_buf_t inv_buf; 30710a4fa49Srie 30810a4fa49Srie if (DBG_NOTCLASS(DBG_C_UNUSED)) 30910a4fa49Srie return; 31010a4fa49Srie 31110a4fa49Srie if (tag < CI_MAX) 31210a4fa49Srie str = MSG_ORIG(tags[tag]); 31310a4fa49Srie else 314de777a60Sab196087 str = conv_invalid_val(&inv_buf, tag, 0); 31510a4fa49Srie 31610a4fa49Srie dbg_print(LIST(nlmp), MSG_INTL(MSG_USD_LCINTERFACE), NAME(nlmp), str, 31710a4fa49Srie NAME(olmp)); 31810a4fa49Srie } 31910a4fa49Srie 3205aefb655Srie /* 3215aefb655Srie * Generic new line generator. To prevent multiple newlines from being 3225aefb655Srie * generated, a flag is maintained in the global debug descriptor. This flag 3235aefb655Srie * is cleared by the callers dbg_print() function to indicate that a newline 3245aefb655Srie * (actually, any line) has been printed. Multiple newlines can be generated 3255aefb655Srie * using the DBG_NL_FRC flag. 3265aefb655Srie */ 3275aefb655Srie void 3285aefb655Srie Dbg_util_nl(Lm_list *lml, int flag) 3295aefb655Srie { 3305aefb655Srie if ((flag == DBG_NL_STD) && (dbg_desc->d_extra & DBG_E_STDNL)) 3315aefb655Srie return; 3325aefb655Srie 3335aefb655Srie dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY)); 3345aefb655Srie 3355aefb655Srie if (flag == DBG_NL_STD) 3365aefb655Srie dbg_desc->d_extra |= DBG_E_STDNL; 3375aefb655Srie } 3385aefb655Srie 3395aefb655Srie /* 3405aefb655Srie * Define name demanglers. 3415aefb655Srie */ 3425aefb655Srie const char * 3435aefb655Srie Dbg_demangle_name(const char *name) 3445aefb655Srie { 3455aefb655Srie if (DBG_NOTCLASS(DBG_C_DEMANGLE)) 3465aefb655Srie return (name); 3475aefb655Srie 3485aefb655Srie return (conv_demangle_name(name)); 3495aefb655Srie } 3505aefb655Srie 3515aefb655Srie const char * 3525aefb655Srie Elf_demangle_name(const char *name) 3535aefb655Srie { 3545aefb655Srie if (DBG_ISDEMANGLE()) 3555aefb655Srie return (conv_demangle_name(name)); 3565aefb655Srie return (name); 357dffec89cSrie } 358