xref: /titanic_50/usr/src/cmd/sgs/liblddbg/common/map.c (revision c9a6ea2e938727c95af7108c5e00eee4c890c7ae)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include	"msg.h"
28 #include	"_debug.h"
29 #include	"libld.h"
30 
31 
32 /*
33  * Report change in input enable status caused by evaluating
34  * $if/$elif control directives.
35  */
36 void
37 Dbg_map_pass(Lm_list *lml, Boolean enable, const char *file,
38     Lineno lineno, const char *directive)
39 {
40 	const char *fmt;
41 
42 	if (DBG_NOTCLASS(DBG_C_MAP))
43 		return;
44 
45 	fmt = enable ? MSG_INTL(MSG_MAP_PASS) : MSG_INTL(MSG_MAP_NOPASS);
46 	dbg_print(lml, fmt, file, EC_LINENO(lineno), directive);
47 }
48 
49 /*
50  * Report entry/removal of boolean identifier from conditional expression
51  * known values.
52  */
53 void
54 Dbg_map_cexp_id(Lm_list *lml, Boolean add, const char *file,
55     Lineno lineno, const char *id)
56 {
57 	const char *fmt;
58 
59 	if (DBG_NOTCLASS(DBG_C_MAP))
60 		return;
61 
62 	fmt = add ? MSG_INTL(MSG_MAP_ID_ADD) : MSG_INTL(MSG_MAP_ID_CLEAR);
63 	dbg_print(lml, fmt, file, EC_LINENO(lineno), id);
64 }
65 
66 void
67 Dbg_map_version(Lm_list *lml, const char *version, const char *name, int scope)
68 {
69 	const char	*str, *scp;
70 
71 	if (DBG_NOTCLASS(DBG_C_MAP | DBG_C_SYMBOLS))
72 		return;
73 
74 	str = MSG_INTL(MSG_MAP_SYM_SCOPE);
75 	if (scope)
76 		scp = MSG_ORIG(MSG_SYM_GLOBAL);
77 	else
78 		scp = MSG_ORIG(MSG_SYM_LOCAL);
79 
80 	if (version)
81 		dbg_print(lml, MSG_INTL(MSG_MAP_SYM_VER_1), str, version,
82 		    Dbg_demangle_name(name), scp);
83 	else
84 		dbg_print(lml, MSG_INTL(MSG_MAP_SYM_VER_2), str,
85 		    Dbg_demangle_name(name), scp);
86 }
87 
88 void
89 Dbg_map_size_new(Lm_list *lml, const char *symname, const char *segname,
90     Lineno lineno)
91 {
92 	if (DBG_NOTCLASS(DBG_C_MAP))
93 		return;
94 
95 	Dbg_util_nl(lml, DBG_NL_STD);
96 	dbg_print(lml, MSG_INTL(MSG_MAP_SYM_SIZE), EC_LINENO(lineno), segname,
97 	    Dbg_demangle_name(symname), MSG_INTL(MSG_STR_ADDING));
98 }
99 
100 void
101 Dbg_map_size_old(Ofl_desc *ofl, Sym_desc *sdp, const char *segname,
102     Lineno lineno)
103 {
104 	Conv_inv_buf_t	inv_buf;
105 	Lm_list		*lml = ofl->ofl_lml;
106 
107 	if (DBG_NOTCLASS(DBG_C_MAP))
108 		return;
109 
110 	Dbg_util_nl(lml, DBG_NL_STD);
111 	dbg_print(lml, MSG_INTL(MSG_MAP_SYM_SIZE), EC_LINENO(lineno), segname,
112 	    sdp->sd_name, MSG_INTL(MSG_STR_UP_1));
113 
114 	if (DBG_NOTDETAIL())
115 		return;
116 
117 	Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_INTL(MSG_STR_UP_2),
118 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine,
119 	    sdp->sd_sym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
120 	    conv_def_tag(sdp->sd_ref, &inv_buf));
121 }
122 
123 void
124 Dbg_map_symbol(Ofl_desc *ofl, Sym_desc *sdp)
125 {
126 	Conv_inv_buf_t	inv_buf;
127 	Lm_list		*lml = ofl->ofl_lml;
128 
129 	if (DBG_NOTCLASS(DBG_C_MAP | DBG_C_SYMBOLS))
130 		return;
131 	if (DBG_NOTDETAIL())
132 		return;
133 
134 	Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_INTL(MSG_STR_ENTERED),
135 	    ofl->ofl_dehdr->e_ident[EI_OSABI],  ofl->ofl_dehdr->e_machine,
136 	    sdp->sd_sym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
137 	    conv_def_tag(sdp->sd_ref, &inv_buf));
138 }
139 
140 /*
141  * Object version dependency. In the v1 syntax, this is the 'dash' operator.
142  * In the v2 syntax, the DEPEND_VERSIONS directive.
143  */
144 void
145 Dbg_map_dv(Lm_list *lml, const char *obj_name, Lineno lineno)
146 {
147 	if (DBG_NOTCLASS(DBG_C_MAP))
148 		return;
149 
150 	dbg_print(lml, MSG_INTL(MSG_MAP_DV), EC_LINENO(lineno), obj_name);
151 }
152 
153 /*
154  * Add a version to an object dependency
155  */
156 void
157 Dbg_map_dv_entry(Lm_list *lml, Lineno lineno, int require, const char *version)
158 {
159 	const char *attr;
160 
161 	if (DBG_NOTCLASS(DBG_C_MAP))
162 		return;
163 
164 	attr = require ? MSG_INTL(MSG_STR_REQUIRE) : MSG_INTL(MSG_STR_ALLOW);
165 	dbg_print(lml, MSG_INTL(MSG_MAP_DV_ENTRY), attr, version,
166 	    EC_LINENO(lineno));
167 }
168 
169 void
170 Dbg_map_sort_title(Lm_list *lml, Boolean orig)
171 {
172 	if (DBG_NOTCLASS(DBG_C_MAP))
173 		return;
174 	if (DBG_NOTDETAIL())
175 		return;
176 
177 	if (orig) {
178 		Dbg_util_nl(lml, DBG_NL_STD);
179 		dbg_print(lml, MSG_INTL(MSG_MAP_SORT_TITLE));
180 		dbg_print(lml, MSG_INTL(MSG_MAP_SORT_TITLE_O));
181 	} else {
182 		dbg_print(lml, MSG_INTL(MSG_MAP_SORT_TITLE_S));
183 	}
184 }
185 
186 void
187 Dbg_map_sort_seg(Lm_list *lml, uchar_t osabi, Half mach, Sg_desc *sgp)
188 {
189 	const char	*type_str;
190 	Conv_inv_buf_t	inv_buf;
191 
192 	if (DBG_NOTCLASS(DBG_C_MAP))
193 		return;
194 	if (DBG_NOTDETAIL())
195 		return;
196 
197 	type_str = conv_phdr_type(osabi, mach, sgp->sg_phdr.p_type,
198 	    0, &inv_buf);
199 
200 	if (sgp->sg_name) {
201 		if (sgp->sg_flags & FLG_SG_P_VADDR) {
202 			dbg_print(lml, MSG_ORIG(MSG_MAP_SORT_SEG_V),
203 			    type_str, sgp->sg_name,
204 			    EC_ADDR(sgp->sg_phdr.p_vaddr));
205 		} else if (sgp->sg_flags & FLG_SG_ORDERED) {
206 			/*
207 			 * All FLG_SG_ORDERED have adjacent sg_id values
208 			 * that start at SGID_TEXT. Subtract out the base
209 			 * in order to present the order values based at 0.
210 			 */
211 			dbg_print(lml, MSG_ORIG(MSG_MAP_SORT_SEG_O),
212 			    type_str, sgp->sg_name,
213 			    EC_WORD(sgp->sg_id - SGID_TEXT));
214 		} else {
215 			dbg_print(lml, MSG_ORIG(MSG_MAP_SORT_SEG_NAME),
216 			    type_str, sgp->sg_name);
217 		}
218 	} else {
219 		dbg_print(lml, MSG_ORIG(MSG_MAP_SORT_SEG), type_str);
220 	}
221 }
222 
223 void
224 Dbg_map_parse(Lm_list *lml, const char *file, int version)
225 {
226 	Conv_inv_buf_t	inv_buf;
227 
228 	if (DBG_NOTCLASS(DBG_C_MAP))
229 		return;
230 
231 	Dbg_util_nl(lml, DBG_NL_STD);
232 	dbg_print(lml, MSG_INTL(MSG_MAP_MAPFILE), file, EC_WORD(version),
233 	    conv_mapfile_version(version, 0, &inv_buf));
234 }
235 
236 void
237 Dbg_map_ent(Lm_list *lml, Ent_desc *enp, Ofl_desc *ofl, Lineno lineno)
238 {
239 	if (DBG_NOTCLASS(DBG_C_MAP))
240 		return;
241 
242 	Dbg_util_nl(lml, DBG_NL_STD);
243 	dbg_print(lml, MSG_INTL(MSG_MAP_EC), EC_LINENO(lineno));
244 	Dbg_ent_entry(lml, ofl->ofl_dehdr->e_ident[EI_OSABI],
245 	    ofl->ofl_dehdr->e_machine, enp);
246 }
247 
248 void
249 Dbg_map_ent_ord_title(Lm_list *lml, const char *segname)
250 {
251 	if (DBG_NOTCLASS(DBG_C_MAP))
252 		return;
253 
254 	Dbg_util_nl(lml, DBG_NL_STD);
255 	dbg_print(lml, MSG_INTL(MSG_MAP_ENT_ORD_TITLE), segname);
256 }
257 
258 void
259 Dbg_map_seg_os_order(Lm_list *lml, Sg_desc *sgp, const char *sec_name,
260     Word ndx, Lineno lineno)
261 {
262 	if (DBG_NOTCLASS(DBG_C_MAP))
263 		return;
264 
265 	dbg_print(lml, MSG_INTL(MSG_MAP_OS_ORDER), EC_LINENO(lineno),
266 	    sgp->sg_name, sec_name, EC_WORD(ndx));
267 }
268 
269 void
270 Dbg_map_seg(Ofl_desc *ofl, dbg_state_t dbg_state, int ndx, Sg_desc *sgp,
271     Lineno lineno)
272 {
273 	Lm_list	*lml = ofl->ofl_lml;
274 
275 	if (DBG_NOTCLASS(DBG_C_MAP))
276 		return;
277 
278 	Dbg_util_nl(lml, DBG_NL_STD);
279 	dbg_print(lml, MSG_INTL(MSG_MAP_SEG), EC_LINENO(lineno),
280 	    Dbg_state_str(dbg_state));
281 	Dbg_seg_desc_entry(ofl->ofl_lml, ofl->ofl_dehdr->e_ident[EI_OSABI],
282 	    ofl->ofl_dehdr->e_machine, ndx, sgp, FALSE);
283 	Dbg_util_nl(lml, DBG_NL_STD);
284 }
285 
286 void
287 Dbg_map_seg_order(Ofl_desc *ofl, uchar_t osabi, Half mach,
288     dbg_state_t dbg_state, Lineno lineno)
289 {
290 	Lm_list	*lml = ofl->ofl_lml;
291 	Aliste		idx;
292 	Sg_desc		*sgp;
293 	Conv_inv_buf_t	inv_buf;
294 	const char	*type_str;
295 
296 	if (DBG_NOTCLASS(DBG_C_MAP))
297 		return;
298 
299 	Dbg_util_nl(lml, DBG_NL_STD);
300 	dbg_print(lml, MSG_INTL(MSG_MAP_SEG_ORDER), EC_LINENO(lineno),
301 	    EC_XWORD(aplist_nitems(ofl->ofl_segs_order)),
302 	    Dbg_state_str(dbg_state));
303 	for (APLIST_TRAVERSE(ofl->ofl_segs_order, idx, sgp)) {
304 		type_str = conv_phdr_type(osabi, mach, sgp->sg_phdr.p_type,
305 		    0, &inv_buf);
306 		dbg_print(lml, MSG_ORIG(MSG_MAP_SORT_SEG_NAME), type_str,
307 		    sgp->sg_name);
308 	}
309 	Dbg_util_nl(lml, DBG_NL_STD);
310 }
311 
312 void
313 Dbg_map_post_title(Lm_list *lml)
314 {
315 	if (DBG_NOTCLASS(DBG_C_MAP))
316 		return;
317 
318 	Dbg_util_nl(lml, DBG_NL_STD);
319 	dbg_print(lml, MSG_INTL(MSG_MAP_POST_TITLE));
320 }
321 
322 void
323 Dbg_map_hdr_noalloc(Lm_list *lml, Lineno lineno)
324 {
325 	if (DBG_NOTCLASS(DBG_C_MAP))
326 		return;
327 
328 	Dbg_util_nl(lml, DBG_NL_STD);
329 	dbg_print(lml, MSG_INTL(MSG_MAP_HDR_NOALLOC), EC_LINENO(lineno));
330 }
331