Print this page
libconv
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/liblddbg/common/util.c
+++ new/usr/src/cmd/sgs/liblddbg/common/util.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 + *
26 + * Copyright 2018 Jason King
25 27 */
26 28
27 29 #include "msg.h"
28 30 #include "_debug.h"
29 31 #include "libld.h"
30 32
31 33 /*
32 34 * If any run-time linker debugging is being carried out always indicate the
33 35 * fact and specify the point at which we transfer control to the main program.
34 36 */
35 37 void
36 38 Dbg_util_call_main(Rt_map *lmp)
37 39 {
38 40 Lm_list *lml = LIST(lmp);
39 41
40 42 Dbg_util_nl(lml, DBG_NL_FRC);
41 43 dbg_print(lml, MSG_INTL(MSG_UTL_TRANS), NAME(lmp));
42 44 Dbg_util_nl(lml, DBG_NL_FRC);
43 45 }
44 46
45 47 void
46 48 Dbg_util_call_init(Rt_map *lmp, int flag)
47 49 {
48 50 Lm_list *lml = LIST(lmp);
49 51 const char *str;
50 52
51 53 if (DBG_NOTCLASS(DBG_C_INIT))
52 54 return;
53 55
54 56 if (flag == DBG_INIT_SORT)
55 57 str = MSG_INTL(MSG_UTL_SORT);
56 58 else if (flag == DBG_INIT_PEND)
57 59 str = MSG_INTL(MSG_UTL_PEND);
58 60 else if (flag == DBG_INIT_DYN)
59 61 str = MSG_INTL(MSG_UTL_DYN);
60 62 else
61 63 str = MSG_INTL(MSG_UTL_DONE);
62 64
63 65 Dbg_util_nl(lml, DBG_NL_STD);
64 66 dbg_print(lml, MSG_INTL(MSG_UTL_INIT), str, NAME(lmp));
65 67 Dbg_util_nl(lml, DBG_NL_STD);
66 68 }
67 69
68 70 void
69 71 Dbg_util_intoolate(Rt_map *lmp)
70 72 {
71 73 Lm_list *lml = LIST(lmp);
72 74
73 75 Dbg_util_nl(lml, DBG_NL_STD);
74 76 dbg_print(lml, MSG_INTL(MSG_UTL_INTOOLATE), NAME(lmp));
75 77 Dbg_util_nl(lml, DBG_NL_STD);
76 78 }
77 79
78 80 void
79 81 Dbg_util_dbnotify(Lm_list *lml, rd_event_e event, r_state_e state)
80 82 {
81 83 const char *estr;
82 84 const char *sstr;
83 85
84 86 if (DBG_NOTCLASS(DBG_C_FILES))
85 87 return;
86 88 if (DBG_NOTDETAIL())
87 89 return;
88 90
89 91 switch (event) {
90 92 case RD_PREINIT:
91 93 estr = MSG_ORIG(MSG_UTL_EVNT_PREINIT);
92 94 sstr = MSG_INTL(MSG_STR_NULL);
93 95 break;
94 96 case RD_POSTINIT:
95 97 estr = MSG_ORIG(MSG_UTL_EVNT_POSTINIT);
96 98 sstr = MSG_INTL(MSG_STR_NULL);
97 99 break;
98 100 case RD_DLACTIVITY:
99 101 estr = MSG_ORIG(MSG_UTL_EVNT_DLACT);
100 102 switch (state) {
101 103 case RT_CONSISTENT:
102 104 sstr = MSG_ORIG(MSG_UTL_STA_CONSIST);
103 105 break;
104 106 case RT_ADD:
105 107 sstr = MSG_ORIG(MSG_UTL_STA_ADD);
106 108 break;
107 109 case RT_DELETE:
108 110 sstr = MSG_ORIG(MSG_UTL_STA_DELETE);
109 111 break;
110 112 default:
111 113 sstr = MSG_INTL(MSG_STR_NULL);
112 114 break;
113 115 }
114 116 break;
115 117 default:
116 118 sstr = MSG_INTL(MSG_STR_NULL);
117 119 estr = MSG_INTL(MSG_STR_UNKNOWN);
118 120 break;
119 121 }
120 122
121 123 Dbg_util_nl(lml, DBG_NL_STD);
122 124 dbg_print(lml, MSG_INTL(MSG_UTL_DBNOTIFY), estr, sstr);
123 125 Dbg_util_nl(lml, DBG_NL_STD);
124 126 }
125 127
126 128 void
127 129 Dbg_util_call_array(Rt_map *lmp, void *addr, int ndx, Word shtype)
128 130 {
129 131 Lm_list *lml = LIST(lmp);
130 132 const char *str;
131 133
132 134 if (DBG_NOTCLASS(DBG_C_INIT))
133 135 return;
134 136
135 137 if (shtype == SHT_INIT_ARRAY)
136 138 str = MSG_ORIG(MSG_SCN_INITARRAY);
137 139 else if (shtype == SHT_FINI_ARRAY)
138 140 str = MSG_ORIG(MSG_SCN_FINIARRAY);
139 141 else
140 142 str = MSG_ORIG(MSG_SCN_PREINITARRAY);
141 143
142 144 dbg_print(lml, MSG_INTL(MSG_UTL_ARRAY), str, ndx, EC_NATPTR(addr),
143 145 NAME(lmp));
144 146 }
145 147
146 148 void
147 149 Dbg_util_call_fini(Rt_map *lmp)
148 150 {
149 151 Lm_list *lml = LIST(lmp);
150 152
151 153 if (DBG_NOTCLASS(DBG_C_INIT))
152 154 return;
153 155
154 156 Dbg_util_nl(lml, DBG_NL_STD);
155 157 dbg_print(lml, MSG_INTL(MSG_UTL_FINI), NAME(lmp));
156 158 Dbg_util_nl(lml, DBG_NL_STD);
157 159 }
158 160
159 161 void
160 162 Dbg_util_str(Lm_list *lml, const char *str)
161 163 {
162 164 Dbg_util_nl(lml, DBG_NL_STD);
163 165 Dbg_util_nl(lml, DBG_NL_FRC);
164 166 dbg_print(lml, MSG_ORIG(MSG_FMT_STR), str);
165 167 Dbg_util_nl(lml, DBG_NL_FRC);
166 168 Dbg_util_nl(lml, DBG_NL_STD);
167 169 }
168 170
169 171 void
170 172 Dbg_util_scc_title(Lm_list *lml, int sec)
171 173 {
172 174 const char *_sec;
173 175
174 176 if (DBG_NOTCLASS(DBG_C_INIT))
175 177 return;
176 178 if (DBG_NOTDETAIL())
177 179 return;
178 180
179 181 if (sec)
180 182 _sec = MSG_INTL(MSG_UTL_SCC_SUBI);
181 183 else
182 184 _sec = MSG_INTL(MSG_UTL_SCC_SUBF);
183 185
184 186 Dbg_util_nl(lml, DBG_NL_STD);
185 187 dbg_print(lml, MSG_INTL(MSG_UTL_SCC_TITLE), _sec);
186 188 }
187 189
188 190 void
189 191 Dbg_util_scc_entry(Rt_map *lmp, uint_t idx)
190 192 {
191 193 if (DBG_NOTCLASS(DBG_C_INIT))
192 194 return;
193 195 if (DBG_NOTDETAIL())
194 196 return;
195 197
196 198 dbg_print(LIST(lmp), MSG_ORIG(MSG_UTL_SCC_ENTRY), idx, NAME(lmp));
197 199 }
198 200
199 201 static int ectoggle = 0;
200 202
201 203 void
202 204 Dbg_util_edge_in(Lm_list *lml, Rt_map *clmp, uint_t flags, Rt_map *dlmp,
203 205 int ndx, int flag)
204 206 {
205 207 Conv_bnd_type_buf_t bnd_type_buf;
206 208 const char *str;
207 209
208 210 if (DBG_NOTCLASS(DBG_C_INIT))
209 211 return;
210 212 if (DBG_NOTDETAIL())
211 213 return;
212 214
213 215 if (flag & RT_SORT_REV)
214 216 str = MSG_ORIG(MSG_SCN_INIT);
215 217 else
216 218 str = MSG_ORIG(MSG_SCN_FINI);
217 219
218 220 if ((clmp == 0) || (ectoggle == 0))
219 221 Dbg_util_nl(lml, DBG_NL_STD);
220 222 if (clmp == 0) {
221 223 if (flag & RT_SORT_INTPOSE)
222 224 dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_TITLE_I), str);
223 225 else
224 226 dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_TITLE_S), str);
225 227
226 228 dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_START), ndx, NAME(dlmp));
227 229 } else
228 230 dbg_print(lml, MSG_INTL(MSG_UTL_EDGE_IN), ndx, NAME(dlmp),
229 231 NAME(clmp), conv_bnd_type(flags, &bnd_type_buf));
230 232
231 233 ectoggle = 1;
232 234 }
233 235
234 236 void
235 237 Dbg_util_edge_out(Rt_map *clmp, Rt_map *dlmp)
236 238 {
237 239 if (DBG_NOTCLASS(DBG_C_INIT))
238 240 return;
239 241 if (DBG_NOTDETAIL())
240 242 return;
241 243
242 244 dbg_print(LIST(clmp), MSG_INTL(MSG_UTL_EDGE_OUT), SORTVAL(clmp),
243 245 NAME(clmp), NAME(dlmp));
244 246 }
245 247
246 248 void
247 249 Dbg_util_collect(Rt_map *lmp, int ndx, int flag)
248 250 {
249 251 Lm_list *lml = LIST(lmp);
250 252 const char *str;
251 253
252 254 if (DBG_NOTCLASS(DBG_C_INIT))
253 255 return;
254 256 if (DBG_NOTDETAIL())
255 257 return;
256 258
257 259 if (flag & RT_SORT_REV)
258 260 str = MSG_ORIG(MSG_SCN_INIT);
259 261 else
260 262 str = MSG_ORIG(MSG_SCN_FINI);
261 263
262 264 if (ectoggle == 1) {
263 265 Dbg_util_nl(lml, DBG_NL_STD);
264 266 ectoggle = 0;
265 267 }
266 268 dbg_print(lml, MSG_INTL(MSG_UTL_COLLECT), ndx, NAME(lmp), str);
267 269 }
268 270
269 271 static const Msg tags[] = {
270 272 MSG_CI_NULL, /* MSG_ORIG(MSG_CI_NULL) */
271 273 MSG_CI_VERSION, /* MSG_ORIG(MSG_CI_VERSION) */
272 274 MSG_CI_ATEXIT, /* MSG_ORIG(MSG_CI_ATEXIT) */
273 275 MSG_CI_LCMESSAGES, /* MSG_ORIG(MSG_CI_LCMESSAGES) */
274 276 MSG_CI_BIND_GUARD, /* MSG_ORIG(MSG_CI_BIND_GUARD) */
275 277 MSG_CI_BIND_CLEAR, /* MSG_ORIG(MSG_CI_BIND_CLEAR) */
276 278 MSG_CI_THR_SELF, /* MSG_ORIG(MSG_CI_THR_SELF) */
277 279 MSG_CI_TLS_MODADD, /* MSG_ORIG(MSG_CI_TLS_MODADD) */
278 280 MSG_CI_TLS_MODREM, /* MSG_ORIG(MSG_CI_TLS_MODREM) */
279 281 MSG_CI_TLS_STATMOD, /* MSG_ORIG(MSG_CI_TLS_STATMOD) */
280 282 MSG_CI_THRINIT, /* MSG_ORIG(MSG_CI_THRINIT) */
281 283 MSG_CI_CRITICAL /* MSG_ORIG(MSG_CI_CRITICAL) */
282 284 };
283 285
284 286 void
285 287 Dbg_util_lcinterface(Rt_map *lmp, int tag, char *val)
286 288 {
287 289 const char *str;
288 290 Conv_inv_buf_t inv_buf;
289 291
290 292 if (DBG_NOTDETAIL())
291 293 return;
292 294
293 295 if (tag < CI_MAX)
294 296 str = MSG_ORIG(tags[tag]);
295 297 else
296 298 str = conv_invalid_val(&inv_buf, tag, 0);
297 299
298 300 dbg_print(LIST(lmp), MSG_INTL(MSG_UTL_LCINTERFACE), NAME(lmp), str,
299 301 EC_NATPTR(val));
300 302 }
301 303
302 304 void
303 305 Dbg_unused_lcinterface(Rt_map *nlmp, Rt_map *olmp, int tag)
304 306 {
305 307 const char *str;
306 308 Conv_inv_buf_t inv_buf;
307 309
308 310 if (DBG_NOTCLASS(DBG_C_UNUSED))
309 311 return;
310 312
311 313 if (tag < CI_MAX)
312 314 str = MSG_ORIG(tags[tag]);
313 315 else
314 316 str = conv_invalid_val(&inv_buf, tag, 0);
315 317
316 318 dbg_print(LIST(nlmp), MSG_INTL(MSG_USD_LCINTERFACE), NAME(nlmp), str,
317 319 NAME(olmp));
318 320 }
319 321
320 322 /*
321 323 * Generic new line generator. To prevent multiple newlines from being
322 324 * generated, a flag is maintained in the global debug descriptor. This flag
323 325 * is cleared by the callers dbg_print() function to indicate that a newline
324 326 * (actually, any line) has been printed. Multiple newlines can be generated
325 327 * using the DBG_NL_FRC flag.
326 328 */
327 329 void
328 330 Dbg_util_nl(Lm_list *lml, int flag)
329 331 {
330 332 if ((flag == DBG_NL_STD) && (dbg_desc->d_extra & DBG_E_STDNL))
331 333 return;
332 334
333 335 dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
334 336
↓ open down ↓ |
300 lines elided |
↑ open up ↑ |
335 337 if (flag == DBG_NL_STD)
336 338 dbg_desc->d_extra |= DBG_E_STDNL;
337 339 }
338 340
339 341 /*
340 342 * Define name demanglers.
341 343 */
342 344 const char *
343 345 Dbg_demangle_name(const char *name)
344 346 {
347 + static char *buf = NULL;
348 +
345 349 if (DBG_NOTCLASS(DBG_C_DEMANGLE))
346 350 return (name);
347 351
348 - return (conv_demangle_name(name));
352 + free(buf);
353 + buf = (char *)conv_demangle_name(name);
354 + if (buf == name) {
355 + buf = NULL;
356 + return (name);
357 + }
358 +
359 + return (buf);
349 360 }
350 361
351 362 const char *
352 363 Elf_demangle_name(const char *name)
353 364 {
354 - if (DBG_ISDEMANGLE())
355 - return (conv_demangle_name(name));
356 - return (name);
365 + static char *buf = NULL;
366 +
367 + if (!DBG_ISDEMANGLE())
368 + return (name);
369 +
370 + free(buf);
371 + buf = (char *)conv_demangle_name(name);
372 + if (buf == name) {
373 + buf = NULL;
374 + return (name);
375 + }
376 +
377 + return (buf);
357 378 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX