xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/util.c (revision 4226f635)
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.
25*4226f635SJason King  *
26*4226f635SJason King  * Copyright 2018 Jason King
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include	"msg.h"
307c478bd9Sstevel@tonic-gate #include	"_debug.h"
317c478bd9Sstevel@tonic-gate #include	"libld.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * If any run-time linker debugging is being carried out always indicate the
357c478bd9Sstevel@tonic-gate  * fact and specify the point at which we transfer control to the main program.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate void
Dbg_util_call_main(Rt_map * lmp)385aefb655Srie Dbg_util_call_main(Rt_map *lmp)
397c478bd9Sstevel@tonic-gate {
405aefb655Srie 	Lm_list	*lml = LIST(lmp);
415aefb655Srie 
425aefb655Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
435aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_TRANS), NAME(lmp));
445aefb655Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
457c478bd9Sstevel@tonic-gate }
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate void
Dbg_util_call_init(Rt_map * lmp,int flag)485aefb655Srie Dbg_util_call_init(Rt_map *lmp, int flag)
497c478bd9Sstevel@tonic-gate {
505aefb655Srie 	Lm_list		*lml = LIST(lmp);
515aefb655Srie 	const char	*str;
527c478bd9Sstevel@tonic-gate 
535aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
54dffec89cSrie 		return;
55dffec89cSrie 
567c478bd9Sstevel@tonic-gate 	if (flag == DBG_INIT_SORT)
577c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_UTL_SORT);
587c478bd9Sstevel@tonic-gate 	else if (flag == DBG_INIT_PEND)
597c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_UTL_PEND);
607c478bd9Sstevel@tonic-gate 	else if (flag == DBG_INIT_DYN)
617c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_UTL_DYN);
627c478bd9Sstevel@tonic-gate 	else
637c478bd9Sstevel@tonic-gate 		str = MSG_INTL(MSG_UTL_DONE);
647c478bd9Sstevel@tonic-gate 
655aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
665aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_INIT), str, NAME(lmp));
675aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate void
Dbg_util_intoolate(Rt_map * lmp)715aefb655Srie Dbg_util_intoolate(Rt_map *lmp)
727c478bd9Sstevel@tonic-gate {
735aefb655Srie 	Lm_list	*lml = LIST(lmp);
745aefb655Srie 
755aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
765aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_INTOOLATE), NAME(lmp));
775aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate void
Dbg_util_dbnotify(Lm_list * lml,rd_event_e event,r_state_e state)815aefb655Srie Dbg_util_dbnotify(Lm_list *lml, rd_event_e event, r_state_e state)
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate 	const char	*estr;
847c478bd9Sstevel@tonic-gate 	const char	*sstr;
857c478bd9Sstevel@tonic-gate 
865aefb655Srie 	if (DBG_NOTCLASS(DBG_C_FILES))
877c478bd9Sstevel@tonic-gate 		return;
887c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
897c478bd9Sstevel@tonic-gate 		return;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	switch (event) {
927c478bd9Sstevel@tonic-gate 	case RD_PREINIT:
937c478bd9Sstevel@tonic-gate 		estr = MSG_ORIG(MSG_UTL_EVNT_PREINIT);
947c478bd9Sstevel@tonic-gate 		sstr = MSG_INTL(MSG_STR_NULL);
957c478bd9Sstevel@tonic-gate 		break;
967c478bd9Sstevel@tonic-gate 	case RD_POSTINIT:
977c478bd9Sstevel@tonic-gate 		estr = MSG_ORIG(MSG_UTL_EVNT_POSTINIT);
987c478bd9Sstevel@tonic-gate 		sstr = MSG_INTL(MSG_STR_NULL);
997c478bd9Sstevel@tonic-gate 		break;
1007c478bd9Sstevel@tonic-gate 	case RD_DLACTIVITY:
1017c478bd9Sstevel@tonic-gate 		estr = MSG_ORIG(MSG_UTL_EVNT_DLACT);
1027c478bd9Sstevel@tonic-gate 		switch (state) {
1037c478bd9Sstevel@tonic-gate 		case RT_CONSISTENT:
1047c478bd9Sstevel@tonic-gate 			sstr = MSG_ORIG(MSG_UTL_STA_CONSIST);
1057c478bd9Sstevel@tonic-gate 			break;
1067c478bd9Sstevel@tonic-gate 		case RT_ADD:
1077c478bd9Sstevel@tonic-gate 			sstr = MSG_ORIG(MSG_UTL_STA_ADD);
1087c478bd9Sstevel@tonic-gate 			break;
1097c478bd9Sstevel@tonic-gate 		case RT_DELETE:
1107c478bd9Sstevel@tonic-gate 			sstr = MSG_ORIG(MSG_UTL_STA_DELETE);
1117c478bd9Sstevel@tonic-gate 			break;
1127c478bd9Sstevel@tonic-gate 		default:
1137c478bd9Sstevel@tonic-gate 			sstr = MSG_INTL(MSG_STR_NULL);
1147c478bd9Sstevel@tonic-gate 			break;
1157c478bd9Sstevel@tonic-gate 		}
1167c478bd9Sstevel@tonic-gate 		break;
1177c478bd9Sstevel@tonic-gate 	default:
1187c478bd9Sstevel@tonic-gate 		sstr = MSG_INTL(MSG_STR_NULL);
1197c478bd9Sstevel@tonic-gate 		estr = MSG_INTL(MSG_STR_UNKNOWN);
1207c478bd9Sstevel@tonic-gate 		break;
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 
1235aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1245aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_DBNOTIFY), estr, sstr);
1255aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate void
Dbg_util_call_array(Rt_map * lmp,void * addr,int ndx,Word shtype)1295aefb655Srie Dbg_util_call_array(Rt_map *lmp, void *addr, int ndx, Word shtype)
1307c478bd9Sstevel@tonic-gate {
1315aefb655Srie 	Lm_list		*lml = LIST(lmp);
1327c478bd9Sstevel@tonic-gate 	const char	*str;
1337c478bd9Sstevel@tonic-gate 
1345aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
1357c478bd9Sstevel@tonic-gate 		return;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	if (shtype == SHT_INIT_ARRAY)
1387c478bd9Sstevel@tonic-gate 		str = MSG_ORIG(MSG_SCN_INITARRAY);
1397c478bd9Sstevel@tonic-gate 	else if (shtype == SHT_FINI_ARRAY)
1407c478bd9Sstevel@tonic-gate 		str = MSG_ORIG(MSG_SCN_FINIARRAY);
1417c478bd9Sstevel@tonic-gate 	else
1427c478bd9Sstevel@tonic-gate 		str = MSG_ORIG(MSG_SCN_PREINITARRAY);
1435aefb655Srie 
1445aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_ARRAY), str, ndx, EC_NATPTR(addr),
1455aefb655Srie 	    NAME(lmp));
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate void
Dbg_util_call_fini(Rt_map * lmp)1495aefb655Srie Dbg_util_call_fini(Rt_map *lmp)
1507c478bd9Sstevel@tonic-gate {
1515aefb655Srie 	Lm_list	*lml = LIST(lmp);
1525aefb655Srie 
1535aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
154dffec89cSrie 		return;
155dffec89cSrie 
1565aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1575aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_FINI), NAME(lmp));
1585aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate void
Dbg_util_str(Lm_list * lml,const char * str)1625aefb655Srie Dbg_util_str(Lm_list *lml, const char *str)
1637c478bd9Sstevel@tonic-gate {
1645aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1655aefb655Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
1665aefb655Srie 	dbg_print(lml, MSG_ORIG(MSG_FMT_STR), str);
1675aefb655Srie 	Dbg_util_nl(lml, DBG_NL_FRC);
1685aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate void
Dbg_util_scc_title(Lm_list * lml,int sec)1725aefb655Srie Dbg_util_scc_title(Lm_list *lml, int sec)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate 	const char	*_sec;
1757c478bd9Sstevel@tonic-gate 
1765aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
177dffec89cSrie 		return;
178dffec89cSrie 	if (DBG_NOTDETAIL())
179dffec89cSrie 		return;
180dffec89cSrie 
1817c478bd9Sstevel@tonic-gate 	if (sec)
182dffec89cSrie 		_sec = MSG_INTL(MSG_UTL_SCC_SUBI);
1837c478bd9Sstevel@tonic-gate 	else
184dffec89cSrie 		_sec = MSG_INTL(MSG_UTL_SCC_SUBF);
1857c478bd9Sstevel@tonic-gate 
1865aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1875aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_SCC_TITLE), _sec);
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate void
Dbg_util_scc_entry(Rt_map * lmp,uint_t idx)1915aefb655Srie Dbg_util_scc_entry(Rt_map *lmp, uint_t idx)
1927c478bd9Sstevel@tonic-gate {
1935aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
194dffec89cSrie 		return;
195dffec89cSrie 	if (DBG_NOTDETAIL())
196dffec89cSrie 		return;
197dffec89cSrie 
1985aefb655Srie 	dbg_print(LIST(lmp), MSG_ORIG(MSG_UTL_SCC_ENTRY), idx, NAME(lmp));
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate 
201dffec89cSrie static	int ectoggle = 0;
202dffec89cSrie 
203dffec89cSrie void
Dbg_util_edge_in(Lm_list * lml,Rt_map * clmp,uint_t flags,Rt_map * dlmp,int ndx,int flag)2045aefb655Srie Dbg_util_edge_in(Lm_list *lml, Rt_map *clmp, uint_t flags, Rt_map *dlmp,
2055aefb655Srie     int ndx, int flag)
206dffec89cSrie {
207de777a60Sab 	Conv_bnd_type_buf_t	bnd_type_buf;
208de777a60Sab 	const char		*str;
209dffec89cSrie 
2105aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
211dffec89cSrie 		return;
212dffec89cSrie 	if (DBG_NOTDETAIL())
213dffec89cSrie 		return;
214dffec89cSrie 
215dffec89cSrie 	if (flag & RT_SORT_REV)
216dffec89cSrie 		str = MSG_ORIG(MSG_SCN_INIT);
217dffec89cSrie 	else
218dffec89cSrie 		str = MSG_ORIG(MSG_SCN_FINI);
219dffec89cSrie 
220dffec89cSrie 	if ((clmp == 0) || (ectoggle == 0))
2215aefb655Srie 		Dbg_util_nl(lml, DBG_NL_STD);
222dffec89cSrie 	if (clmp == 0) {
223883c6d49Srie 		if (flag & RT_SORT_INTPOSE)
224883c6d49Srie 			dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_TITLE_I), str);
225883c6d49Srie 		else
226883c6d49Srie 			dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_TITLE_S), str);
227883c6d49Srie 
2285aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_START), ndx, NAME(dlmp));
229dffec89cSrie 	} else
2305aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_IN), ndx, NAME(dlmp),
231de777a60Sab 		    NAME(clmp), conv_bnd_type(flags, &bnd_type_buf));
232dffec89cSrie 
233dffec89cSrie 	ectoggle = 1;
234dffec89cSrie }
235dffec89cSrie 
236dffec89cSrie void
Dbg_util_edge_out(Rt_map * clmp,Rt_map * dlmp)2375aefb655Srie Dbg_util_edge_out(Rt_map *clmp, Rt_map *dlmp)
238dffec89cSrie {
2395aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
240dffec89cSrie 		return;
241dffec89cSrie 	if (DBG_NOTDETAIL())
242dffec89cSrie 		return;
243dffec89cSrie 
2445aefb655Srie 	dbg_print(LIST(clmp), MSG_INTL(MSG_UTL_EDGE_OUT), SORTVAL(clmp),
2455aefb655Srie 	    NAME(clmp), NAME(dlmp));
246dffec89cSrie }
247dffec89cSrie 
248dffec89cSrie void
Dbg_util_collect(Rt_map * lmp,int ndx,int flag)2495aefb655Srie Dbg_util_collect(Rt_map *lmp, int ndx, int flag)
250dffec89cSrie {
2515aefb655Srie 	Lm_list		*lml = LIST(lmp);
252dffec89cSrie 	const char	*str;
253dffec89cSrie 
2545aefb655Srie 	if (DBG_NOTCLASS(DBG_C_INIT))
255dffec89cSrie 		return;
256dffec89cSrie 	if (DBG_NOTDETAIL())
257dffec89cSrie 		return;
258dffec89cSrie 
259dffec89cSrie 	if (flag & RT_SORT_REV)
260dffec89cSrie 		str = MSG_ORIG(MSG_SCN_INIT);
261dffec89cSrie 	else
262dffec89cSrie 		str = MSG_ORIG(MSG_SCN_FINI);
263dffec89cSrie 
264dffec89cSrie 	if (ectoggle == 1) {
2655aefb655Srie 		Dbg_util_nl(lml, DBG_NL_STD);
266dffec89cSrie 		ectoggle = 0;
267dffec89cSrie 	}
2685aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_UTL_COLLECT), ndx, NAME(lmp), str);
2695aefb655Srie }
2705aefb655Srie 
27110a4fa49Srie static const Msg	tags[] = {
27210a4fa49Srie 	MSG_CI_NULL,		/* MSG_ORIG(MSG_CI_NULL) */
27310a4fa49Srie 	MSG_CI_VERSION,		/* MSG_ORIG(MSG_CI_VERSION) */
27410a4fa49Srie 	MSG_CI_ATEXIT,		/* MSG_ORIG(MSG_CI_ATEXIT) */
27510a4fa49Srie 	MSG_CI_LCMESSAGES,	/* MSG_ORIG(MSG_CI_LCMESSAGES) */
27610a4fa49Srie 	MSG_CI_BIND_GUARD,	/* MSG_ORIG(MSG_CI_BIND_GUARD) */
27710a4fa49Srie 	MSG_CI_BIND_CLEAR,	/* MSG_ORIG(MSG_CI_BIND_CLEAR) */
27810a4fa49Srie 	MSG_CI_THR_SELF,	/* MSG_ORIG(MSG_CI_THR_SELF) */
27910a4fa49Srie 	MSG_CI_TLS_MODADD,	/* MSG_ORIG(MSG_CI_TLS_MODADD) */
28010a4fa49Srie 	MSG_CI_TLS_MODREM,	/* MSG_ORIG(MSG_CI_TLS_MODREM) */
28110a4fa49Srie 	MSG_CI_TLS_STATMOD,	/* MSG_ORIG(MSG_CI_TLS_STATMOD) */
2822a8d6ebaSRod Evans 	MSG_CI_THRINIT,		/* MSG_ORIG(MSG_CI_THRINIT) */
2832a8d6ebaSRod Evans 	MSG_CI_CRITICAL		/* MSG_ORIG(MSG_CI_CRITICAL) */
28410a4fa49Srie };
28510a4fa49Srie 
28610a4fa49Srie void
Dbg_util_lcinterface(Rt_map * lmp,int tag,char * val)28710a4fa49Srie Dbg_util_lcinterface(Rt_map *lmp, int tag, char *val)
28810a4fa49Srie {
289de777a60Sab 	const char	*str;
290de777a60Sab 	Conv_inv_buf_t	inv_buf;
29110a4fa49Srie 
29210a4fa49Srie 	if (DBG_NOTDETAIL())
29310a4fa49Srie 		return;
29410a4fa49Srie 
29510a4fa49Srie 	if (tag < CI_MAX)
29610a4fa49Srie 		str = MSG_ORIG(tags[tag]);
29710a4fa49Srie 	else
298de777a60Sab 		str = conv_invalid_val(&inv_buf, tag, 0);
29910a4fa49Srie 
30010a4fa49Srie 	dbg_print(LIST(lmp), MSG_INTL(MSG_UTL_LCINTERFACE), NAME(lmp), str,
30110a4fa49Srie 	    EC_NATPTR(val));
30210a4fa49Srie }
30310a4fa49Srie 
30410a4fa49Srie void
Dbg_unused_lcinterface(Rt_map * nlmp,Rt_map * olmp,int tag)30510a4fa49Srie Dbg_unused_lcinterface(Rt_map *nlmp, Rt_map *olmp, int tag)
30610a4fa49Srie {
307de777a60Sab 	const char	*str;
308de777a60Sab 	Conv_inv_buf_t	inv_buf;
30910a4fa49Srie 
31010a4fa49Srie 	if (DBG_NOTCLASS(DBG_C_UNUSED))
31110a4fa49Srie 		return;
31210a4fa49Srie 
31310a4fa49Srie 	if (tag < CI_MAX)
31410a4fa49Srie 		str = MSG_ORIG(tags[tag]);
31510a4fa49Srie 	else
316de777a60Sab 		str = conv_invalid_val(&inv_buf, tag, 0);
31710a4fa49Srie 
31810a4fa49Srie 	dbg_print(LIST(nlmp), MSG_INTL(MSG_USD_LCINTERFACE), NAME(nlmp), str,
31910a4fa49Srie 	    NAME(olmp));
32010a4fa49Srie }
32110a4fa49Srie 
3225aefb655Srie /*
3235aefb655Srie  * Generic new line generator.  To prevent multiple newlines from being
3245aefb655Srie  * generated, a flag is maintained in the global debug descriptor.  This flag
3255aefb655Srie  * is cleared by the callers dbg_print() function to indicate that a newline
3265aefb655Srie  * (actually, any line) has been printed.  Multiple newlines can be generated
3275aefb655Srie  * using the DBG_NL_FRC flag.
3285aefb655Srie  */
3295aefb655Srie void
Dbg_util_nl(Lm_list * lml,int flag)3305aefb655Srie Dbg_util_nl(Lm_list *lml, int flag)
3315aefb655Srie {
3325aefb655Srie 	if ((flag == DBG_NL_STD) && (dbg_desc->d_extra & DBG_E_STDNL))
3335aefb655Srie 		return;
3345aefb655Srie 
3355aefb655Srie 	dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
3365aefb655Srie 
3375aefb655Srie 	if (flag == DBG_NL_STD)
3385aefb655Srie 		dbg_desc->d_extra |= DBG_E_STDNL;
3395aefb655Srie }
3405aefb655Srie 
3415aefb655Srie /*
3425aefb655Srie  * Define name demanglers.
3435aefb655Srie  */
3445aefb655Srie const char *
Dbg_demangle_name(const char * name)3455aefb655Srie Dbg_demangle_name(const char *name)
3465aefb655Srie {
347*4226f635SJason King 	static char *buf = NULL;
348*4226f635SJason King 
3495aefb655Srie 	if (DBG_NOTCLASS(DBG_C_DEMANGLE))
3505aefb655Srie 		return (name);
3515aefb655Srie 
352*4226f635SJason King 	free(buf);
353*4226f635SJason King 	buf = (char *)conv_demangle_name(name);
354*4226f635SJason King 	if (buf == name) {
355*4226f635SJason King 		buf = NULL;
356*4226f635SJason King 		return (name);
357*4226f635SJason King 	}
358*4226f635SJason King 
359*4226f635SJason King 	return (buf);
3605aefb655Srie }
3615aefb655Srie 
3625aefb655Srie const char *
Elf_demangle_name(const char * name)3635aefb655Srie Elf_demangle_name(const char *name)
3645aefb655Srie {
365*4226f635SJason King 	static char *buf = NULL;
366*4226f635SJason King 
367*4226f635SJason King 	if (!DBG_ISDEMANGLE())
368*4226f635SJason King 		return (name);
369*4226f635SJason King 
370*4226f635SJason King 	free(buf);
371*4226f635SJason King 	buf = (char *)conv_demangle_name(name);
372*4226f635SJason King 	if (buf == name) {
373*4226f635SJason King 		buf = NULL;
374*4226f635SJason King 		return (name);
375*4226f635SJason King 	}
376*4226f635SJason King 
377*4226f635SJason King 	return (buf);
378dffec89cSrie }
379