xref: /titanic_51/usr/src/cmd/sgs/liblddbg/common/util.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include	"msg.h"
29 #include	"_debug.h"
30 #include	"libld.h"
31 
32 /*
33  * Generic new line generator.
34  */
35 void
36 Dbg_util_nl()
37 {
38 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
39 }
40 
41 /*
42  * If any run-time linker debugging is being carried out always indicate the
43  * fact and specify the point at which we transfer control to the main program.
44  */
45 void
46 Dbg_util_call_main(const char *name)
47 {
48 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
49 	dbg_print(MSG_INTL(MSG_UTL_TRANS), name);
50 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
51 }
52 
53 void
54 Dbg_util_call_init(const char *name, int flag)
55 {
56 	const char *str;
57 
58 	if (flag == DBG_INIT_SORT)
59 		str = MSG_INTL(MSG_UTL_SORT);
60 	else if (flag == DBG_INIT_PEND)
61 		str = MSG_INTL(MSG_UTL_PEND);
62 	else if (flag == DBG_INIT_DYN)
63 		str = MSG_INTL(MSG_UTL_DYN);
64 	else
65 		str = MSG_INTL(MSG_UTL_DONE);
66 
67 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
68 	dbg_print(MSG_INTL(MSG_UTL_INIT), str, name);
69 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
70 }
71 
72 void
73 Dbg_util_no_init(const char *name)
74 {
75 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
76 	dbg_print(MSG_INTL(MSG_UTL_NOINIT), name);
77 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
78 }
79 
80 void
81 Dbg_util_intoolate(const char *name)
82 {
83 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
84 	dbg_print(MSG_INTL(MSG_UTL_INTOOLATE), name);
85 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
86 }
87 
88 void
89 Dbg_util_dbnotify(rd_event_e event, r_state_e state)
90 {
91 	const char	*estr;
92 	const char	*sstr;
93 
94 	if (DBG_NOTCLASS(DBG_FILES))
95 		return;
96 	if (DBG_NOTDETAIL())
97 		return;
98 
99 	switch (event) {
100 	case RD_PREINIT:
101 		estr = MSG_ORIG(MSG_UTL_EVNT_PREINIT);
102 		sstr = MSG_INTL(MSG_STR_NULL);
103 		break;
104 	case RD_POSTINIT:
105 		estr = MSG_ORIG(MSG_UTL_EVNT_POSTINIT);
106 		sstr = MSG_INTL(MSG_STR_NULL);
107 		break;
108 	case RD_DLACTIVITY:
109 		estr = MSG_ORIG(MSG_UTL_EVNT_DLACT);
110 		switch (state) {
111 		case RT_CONSISTENT:
112 			sstr = MSG_ORIG(MSG_UTL_STA_CONSIST);
113 			break;
114 		case RT_ADD:
115 			sstr = MSG_ORIG(MSG_UTL_STA_ADD);
116 			break;
117 		case RT_DELETE:
118 			sstr = MSG_ORIG(MSG_UTL_STA_DELETE);
119 			break;
120 		default:
121 			sstr = MSG_INTL(MSG_STR_NULL);
122 			break;
123 		}
124 		break;
125 	default:
126 		sstr = MSG_INTL(MSG_STR_NULL);
127 		estr = MSG_INTL(MSG_STR_UNKNOWN);
128 		break;
129 	}
130 
131 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
132 	dbg_print(MSG_INTL(MSG_UTL_DBNOTIFY), estr, sstr);
133 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
134 }
135 
136 void
137 Dbg_util_call_array(const char *libname, void *addr, uint_t ndx,
138 	uint_t shtype)
139 {
140 	const char	*str;
141 
142 	if (DBG_NOTDETAIL())
143 		return;
144 
145 	if (shtype == SHT_INIT_ARRAY)
146 		str = MSG_ORIG(MSG_SCN_INITARRAY);
147 	else if (shtype == SHT_FINI_ARRAY)
148 		str = MSG_ORIG(MSG_SCN_FINIARRAY);
149 	else
150 		str = MSG_ORIG(MSG_SCN_PREINITARRAY);
151 	dbg_print(MSG_INTL(MSG_UTL_ARRAY), libname, str, ndx, EC_ADDR(addr));
152 }
153 
154 void
155 Dbg_util_call_fini(const char *name)
156 {
157 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
158 	dbg_print(MSG_INTL(MSG_UTL_FINI), name);
159 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
160 }
161 
162 void
163 Dbg_util_str(const char *name)
164 {
165 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
166 	dbg_print(MSG_ORIG(MSG_FMT_STR), name);
167 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
168 }
169 
170 void
171 Dbg_scc_title(int sec)
172 {
173 	const char	*_sec;
174 
175 	if (sec)
176 		_sec = MSG_ORIG(MSG_SCN_INIT);
177 	else
178 		_sec = MSG_ORIG(MSG_SCN_FINI);
179 
180 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
181 	dbg_print(MSG_INTL(MSG_SCC_TITLE), _sec);
182 }
183 
184 void
185 Dbg_scc_entry(uint_t idx, const char *name)
186 {
187 	dbg_print(MSG_ORIG(MSG_SCC_ENTRY), idx, name);
188 }
189 
190 void
191 Dbg_util_broadcast(const char *name)
192 {
193 	if (DBG_NOTDETAIL())
194 		return;
195 
196 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
197 	dbg_print(MSG_INTL(MSG_UTL_BROAD), name);
198 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
199 }
200 
201 void
202 Dbg_util_wait(int what, const char *cname, const char *dname)
203 {
204 	const char	*str;
205 
206 	if (DBG_NOTDETAIL())
207 		return;
208 
209 	if (what == DBG_WAIT_INIT)
210 		str = MSG_ORIG(MSG_SCN_INIT);
211 	else if (what == DBG_WAIT_FINI)
212 		str = MSG_ORIG(MSG_SCN_FINI);
213 	else
214 		str = MSG_INTL(MSG_STR_SYMBOL);
215 
216 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
217 	dbg_print(MSG_INTL(MSG_UTL_WAIT), str, cname, dname);
218 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
219 }
220