xref: /titanic_41/usr/src/cmd/sgs/liblddbg/common/version.c (revision 5203bc321053fb87d7073c7640548fab73634793)
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	<stdio.h>
28 #include	<debug.h>
29 #include	"msg.h"
30 #include	"_debug.h"
31 
32 void
33 Dbg_ver_avail_title(Lm_list *lml, const char *file)
34 {
35 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
36 		return;
37 
38 	Dbg_util_nl(lml, DBG_NL_STD);
39 	dbg_print(lml, MSG_INTL(MSG_VER_AVAIL_1), file);
40 	dbg_print(lml, MSG_INTL(MSG_VER_AVAIL_2));
41 }
42 
43 void
44 Dbg_ver_def_title(Lm_list *lml, const char *file)
45 {
46 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
47 		return;
48 
49 	Dbg_util_nl(lml, DBG_NL_STD);
50 	dbg_print(lml, MSG_INTL(MSG_VER_DEF_TITLE), file);
51 	Elf_ver_def_title(lml);
52 }
53 
54 void
55 Dbg_ver_need_title(Lm_list *lml, const char *file)
56 {
57 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
58 		return;
59 
60 	Dbg_util_nl(lml, DBG_NL_STD);
61 	dbg_print(lml, MSG_INTL(MSG_VER_NEED_TITLE), file);
62 	Elf_ver_need_title(lml, 0);
63 }
64 
65 void
66 Dbg_ver_need_entry(Lm_list *lml, Half cnt, const char *file,
67     const char *version)
68 {
69 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
70 		return;
71 
72 	if (cnt)
73 		Elf_ver_line_4(lml, version);
74 	else
75 		Elf_ver_line_5(lml, file, version);
76 }
77 
78 void
79 Dbg_ver_symbol(Lm_list *lml, const char *name)
80 {
81 	static Boolean	ver_symbol_title = TRUE;
82 
83 	if (DBG_NOTCLASS(DBG_C_VERSIONS | DBG_C_SYMBOLS))
84 		return;
85 
86 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
87 		if (ver_symbol_title) {
88 			ver_symbol_title = FALSE;
89 			Dbg_util_nl(lml, DBG_NL_STD);
90 			dbg_print(lml, MSG_INTL(MSG_SYM_VERSION));
91 		}
92 
93 	Dbg_syms_created(lml, name);
94 }
95 
96 /*
97  * This function doesn't test for any specific debugging category, thus it will
98  * be generated for any debugging family.
99  */
100 void
101 Dbg_ver_nointerface(Lm_list *lml, const char *name)
102 {
103 	Dbg_util_nl(lml, DBG_NL_STD);
104 	dbg_print(lml, MSG_INTL(MSG_VER_NOINTERFACE), name);
105 	Dbg_util_nl(lml, DBG_NL_STD);
106 }
107 
108 void
109 Dbg_ver_desc_entry(Lm_list *lml, Ver_desc *vdp)
110 {
111 	Conv_ver_flags_buf_t	ver_flags_buf;
112 	const char		*dep;
113 	Ver_desc		*_vdp, *__vdp;
114 	Aliste 			idx;
115 	char			index[10];
116 
117 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
118 		return;
119 
120 	if (vdp->vd_deps) {
121 		_vdp = (Ver_desc *)vdp->vd_deps->apl_data[0];
122 		dep = _vdp->vd_name;
123 	} else {
124 		_vdp = 0;
125 		dep = MSG_ORIG(MSG_STR_EMPTY);
126 	}
127 	(void) sprintf(index, MSG_ORIG(MSG_FMT_INDEX), vdp->vd_ndx);
128 	Elf_ver_line_1(lml, index, vdp->vd_name, dep,
129 	    conv_ver_flags(vdp->vd_flags, 0, &ver_flags_buf));
130 
131 	/*
132 	 * Loop through the dependency list in case there are more that one
133 	 * dependency.
134 	 */
135 	for (APLIST_TRAVERSE(vdp->vd_deps, idx, __vdp)) {
136 		if (_vdp == __vdp)
137 			continue;
138 		Elf_ver_line_4(lml, __vdp->vd_name);
139 	}
140 }
141 
142 void
143 Dbg_ver_avail_entry(Lm_list *lml, Ver_index *vip, const char *select)
144 {
145 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
146 		return;
147 
148 	if (select) {
149 		if (DBG_NOTLONG())
150 			dbg_print(lml, MSG_ORIG(MSG_VER_SELECTED),
151 			    vip->vi_name, select);
152 		else
153 			dbg_print(lml, MSG_ORIG(MSG_VER_L_SELECTED),
154 			    vip->vi_name, select);
155 	} else {
156 		if (DBG_NOTLONG())
157 			dbg_print(lml, MSG_ORIG(MSG_VER_ALL), vip->vi_name);
158 		else
159 			dbg_print(lml, MSG_ORIG(MSG_VER_L_ALL), vip->vi_name);
160 	}
161 }
162 
163 void
164 Elf_ver_def_title(Lm_list *lml)
165 {
166 	dbg_print(lml, MSG_INTL(MSG_VER_DEF));
167 }
168 
169 /*
170  * entry:
171  *	gnuver - If True (non-zero), the version rules used by the
172  *		GNU ld are assumed. If False (0), Solaris ld rules apply.
173  */
174 void
175 Elf_ver_need_title(Lm_list *lml, int gnuver)
176 {
177 	if (gnuver)
178 		dbg_print(lml, MSG_INTL(MSG_VER_NEED_GNUVER));
179 	else
180 		dbg_print(lml, MSG_INTL(MSG_VER_NEED));
181 }
182 
183 void
184 Elf_ver_line_1(Lm_list *lml, const char *index, const char *name,
185     const char *dep, const char *flags)
186 {
187 	if (DBG_NOTLONG())
188 		dbg_print(lml, MSG_INTL(MSG_VER_LINE_1), index, name,
189 		    dep, flags);
190 	else
191 		dbg_print(lml, MSG_INTL(MSG_VER_LLINE_1), index, name,
192 		    dep, flags);
193 }
194 
195 void
196 Elf_ver_line_2(Lm_list *lml, const char *name, const char *dep)
197 {
198 	dbg_print(lml, MSG_INTL(MSG_VER_LINE_2), name, dep);
199 }
200 
201 void
202 Elf_ver_line_3(Lm_list *lml, const char *name, const char *dep,
203     const char *flags)
204 {
205 	dbg_print(lml, MSG_INTL(MSG_VER_LINE_3), name, dep, flags);
206 }
207 
208 void
209 Elf_ver_line_4(Lm_list *lml, const char *version)
210 {
211 	dbg_print(lml, MSG_INTL(MSG_VER_LINE_4), version);
212 }
213 
214 void
215 Elf_ver_line_5(Lm_list *lml, const char *file, const char *version)
216 {
217 	if (DBG_NOTLONG())
218 		dbg_print(lml, MSG_INTL(MSG_VER_LINE_5), file, version);
219 	else
220 		dbg_print(lml, MSG_INTL(MSG_VER_LLINE_5), file, version);
221 }
222 
223 /*
224  * Called after final call to Dbg_ver_need() to inject final newline.
225  */
226 void
227 Dbg_ver_need_done(Lm_list *lml)
228 {
229 	if (DBG_NOTCLASS(DBG_C_VERSIONS))
230 		return;
231 
232 	Dbg_util_nl(lml, DBG_NL_STD);
233 }
234