xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/map.c (revision 89a7715a55deca73d03076f5c24463717f0aaa91)
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 2007 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 static const char
33 	*Dbg_decl =	NULL;
34 
35 void
36 Dbg_map_set_atsign(Boolean new)
37 {
38 	if (DBG_NOTCLASS(DBG_C_MAP))
39 		return;
40 
41 	if (new)
42 		Dbg_decl = MSG_INTL(MSG_MAP_SEG_DECL_4);
43 	else
44 		Dbg_decl = MSG_INTL(MSG_MAP_SEG_DECL_5);
45 }
46 
47 void
48 Dbg_map_set_equal(Boolean new)
49 {
50 	if (DBG_NOTCLASS(DBG_C_MAP))
51 		return;
52 
53 	if (new)
54 		Dbg_decl = MSG_INTL(MSG_MAP_SEG_DECL_1);
55 	else
56 		Dbg_decl = MSG_INTL(MSG_MAP_SEG_DECL_2);
57 }
58 
59 void
60 Dbg_map_version(Lm_list *lml, const char *version, const char *name, int scope)
61 {
62 	const char	*str, *scp;
63 
64 	if (DBG_NOTCLASS(DBG_C_MAP | DBG_C_SYMBOLS))
65 		return;
66 
67 	str = MSG_INTL(MSG_MAP_SYM_SCOPE);
68 	if (scope)
69 		scp = MSG_ORIG(MSG_SYM_GLOBAL);
70 	else
71 		scp = MSG_ORIG(MSG_SYM_LOCAL);
72 
73 	if (version)
74 		dbg_print(lml, MSG_INTL(MSG_MAP_SYM_VER_1), str, version,
75 		    Dbg_demangle_name(name), scp);
76 	else
77 		dbg_print(lml, MSG_INTL(MSG_MAP_SYM_VER_2), str,
78 		    Dbg_demangle_name(name), scp);
79 }
80 
81 void
82 Dbg_map_size_new(Lm_list *lml, const char *name)
83 {
84 	if (DBG_NOTCLASS(DBG_C_MAP))
85 		return;
86 
87 	dbg_print(lml, MSG_INTL(MSG_MAP_SYM_SIZE), Dbg_demangle_name(name),
88 	    MSG_INTL(MSG_STR_ADD));
89 }
90 
91 void
92 Dbg_map_size_old(Ofl_desc *ofl, Sym_desc *sdp)
93 {
94 	Conv_inv_buf_t	inv_buf;
95 	Lm_list		*lml = ofl->ofl_lml;
96 
97 	if (DBG_NOTCLASS(DBG_C_MAP))
98 		return;
99 
100 	dbg_print(lml, MSG_INTL(MSG_MAP_SYM_SIZE), sdp->sd_name,
101 	    MSG_INTL(MSG_STR_UP_1));
102 
103 	if (DBG_NOTDETAIL())
104 		return;
105 
106 	Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_INTL(MSG_STR_UP_2),
107 	    ofl->ofl_dehdr->e_machine, sdp->sd_sym,
108 	    sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
109 	    conv_def_tag(sdp->sd_ref, &inv_buf));
110 }
111 
112 void
113 Dbg_map_symbol(Ofl_desc *ofl, Sym_desc *sdp)
114 {
115 	Conv_inv_buf_t	inv_buf;
116 	Lm_list		*lml = ofl->ofl_lml;
117 
118 	if (DBG_NOTCLASS(DBG_C_MAP | DBG_C_SYMBOLS))
119 		return;
120 	if (DBG_NOTDETAIL())
121 		return;
122 
123 	Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_INTL(MSG_STR_ENTERED),
124 	    ofl->ofl_dehdr->e_machine, sdp->sd_sym, sdp->sd_aux ?
125 	    sdp->sd_aux->sa_overndx : 0, 0, NULL,
126 	    conv_def_tag(sdp->sd_ref, &inv_buf));
127 }
128 
129 void
130 Dbg_map_dash(Lm_list *lml, const char *name, Sdf_desc *sdf)
131 {
132 	const char	*str;
133 
134 	if (DBG_NOTCLASS(DBG_C_MAP))
135 		return;
136 
137 	if (sdf->sdf_flags & FLG_SDF_SONAME)
138 		str = MSG_INTL(MSG_MAP_CNT_DEF_1);
139 	else
140 		str = MSG_INTL(MSG_MAP_CNT_DEF_2);
141 
142 	dbg_print(lml, str, name, sdf->sdf_soname);
143 }
144 
145 void
146 Dbg_map_sort_orig(Lm_list *lml, Sg_desc *sgp)
147 {
148 	const char	*str;
149 
150 	if (DBG_NOTCLASS(DBG_C_MAP))
151 		return;
152 	if (DBG_NOTDETAIL())
153 		return;
154 
155 	if (sgp->sg_name && *sgp->sg_name)
156 		str = sgp->sg_name;
157 	else
158 		str = MSG_INTL(MSG_STR_NULL);
159 
160 	dbg_print(lml, MSG_INTL(MSG_MAP_SORTSEG), str);
161 }
162 
163 void
164 Dbg_map_sort_fini(Lm_list *lml, Sg_desc *sgp)
165 {
166 	const char	*str;
167 
168 	if (DBG_NOTCLASS(DBG_C_MAP))
169 		return;
170 	if (DBG_NOTDETAIL())
171 		return;
172 
173 	if (sgp->sg_name && *sgp->sg_name)
174 		str = sgp->sg_name;
175 	else
176 		str = MSG_INTL(MSG_STR_NULL);
177 
178 	dbg_print(lml, MSG_INTL(MSG_MAP_SEGSORT), str);
179 }
180 
181 void
182 Dbg_map_parse(Lm_list *lml, const char *file)
183 {
184 	if (DBG_NOTCLASS(DBG_C_MAP))
185 		return;
186 
187 	Dbg_util_nl(lml, DBG_NL_STD);
188 	dbg_print(lml, MSG_INTL(MSG_MAP_MAPFILE), file);
189 }
190 
191 void
192 Dbg_map_ent(Lm_list *lml, Boolean new, Ent_desc *enp, Ofl_desc *ofl)
193 {
194 	if (DBG_NOTCLASS(DBG_C_MAP))
195 		return;
196 
197 	dbg_print(lml, MSG_INTL(MSG_MAP_MAP_DIR));
198 	Dbg_ent_entry(lml, ofl->ofl_dehdr->e_machine, enp);
199 	if (new)
200 		Dbg_decl = MSG_INTL(MSG_MAP_SEG_DECL_3);
201 }
202 
203 void
204 Dbg_map_pipe(Lm_list *lml, Sg_desc *sgp, const char *sec_name, const Word ndx)
205 {
206 	if (DBG_NOTCLASS(DBG_C_MAP))
207 		return;
208 
209 	dbg_print(lml, MSG_INTL(MSG_MAP_SEC_ORDER), sgp->sg_name, sec_name,
210 	    EC_WORD(ndx));
211 }
212 
213 void
214 Dbg_map_seg(Ofl_desc *ofl, int ndx, Sg_desc *sgp)
215 {
216 	Lm_list	*lml = ofl->ofl_lml;
217 
218 	if (DBG_NOTCLASS(DBG_C_MAP))
219 		return;
220 
221 	if (Dbg_decl) {
222 		dbg_print(lml, MSG_ORIG(MSG_FMT_STR), Dbg_decl);
223 		Dbg_seg_desc_entry(ofl->ofl_lml,
224 		    ofl->ofl_dehdr->e_machine, ndx, sgp);
225 		Dbg_util_nl(lml, DBG_NL_STD);
226 		Dbg_decl = NULL;
227 	}
228 }
229