xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/cap.c (revision 861a91627796c35220e75654dac61e5707536dcd)
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	<libld.h>
30 #include	<conv.h>
31 #include	"msg.h"
32 #include	"_debug.h"
33 
34 void
35 Dbg_cap_candidate(Lm_list *lml, const char *name)
36 {
37 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_FILES))
38 		return;
39 
40 	dbg_print(lml, MSG_INTL(MSG_CAP_CANDIDATE), name);
41 }
42 
43 void
44 Dbg_cap_filter(Lm_list *lml, const char *dir, Rt_map *flmp)
45 {
46 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_FILES))
47 		return;
48 
49 	Dbg_util_nl(lml, DBG_NL_STD);
50 	if (flmp)
51 		dbg_print(lml, MSG_INTL(MSG_CAP_FILTER_1), dir, NAME(flmp));
52 	else
53 		dbg_print(lml, MSG_INTL(MSG_CAP_FILTER_2), dir);
54 }
55 
56 void
57 Dbg_cap_val(Lm_list *lml, Syscapset *sys, Syscapset *alt, Half mach)
58 {
59 	Conv_cap_val_buf_t	cap_val_buf;
60 
61 	if ((sys->sc_plat == NULL) && (sys->sc_mach == NULL) &&
62 	    (sys->sc_hw_2 == 0) && (sys->sc_hw_1 == 0) &&
63 	    (sys->sc_sf_1 == 0))
64 		return;
65 
66 	Dbg_util_nl(lml, DBG_NL_FRC);
67 
68 	/*
69 	 * Print any capabilities in precedence order.
70 	 */
71 	if (sys->sc_plat) {
72 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_PLAT), sys->sc_plat);
73 	}
74 	if (sys->sc_mach) {
75 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_MACH), sys->sc_mach);
76 	}
77 	if (sys->sc_hw_2) {
78 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_HW_2),
79 		    conv_cap_val_hw2(sys->sc_hw_2, mach, 0,
80 		    &cap_val_buf.cap_val_hw2_buf));
81 	}
82 	if (sys->sc_hw_1) {
83 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_HW_1),
84 		    conv_cap_val_hw1(sys->sc_hw_1, mach, 0,
85 		    &cap_val_buf.cap_val_hw1_buf));
86 	}
87 	if (sys->sc_sf_1) {
88 		dbg_print(lml, MSG_INTL(MSG_CAP_SYS_SF_1),
89 		    conv_cap_val_sf1(sys->sc_sf_1, mach, 0,
90 		    &cap_val_buf.cap_val_sf1_buf));
91 	}
92 
93 	if (alt != sys) {
94 		Dbg_util_nl(lml, DBG_NL_FRC);
95 		if (alt->sc_plat != sys->sc_plat) {
96 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_PLAT),
97 			    alt->sc_plat);
98 		}
99 		if (alt->sc_mach != sys->sc_mach) {
100 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_MACH),
101 			    alt->sc_mach);
102 		}
103 		if (alt->sc_hw_2 != sys->sc_hw_2) {
104 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_HW_2),
105 			    conv_cap_val_hw2(alt->sc_hw_2, mach, 0,
106 			    &cap_val_buf.cap_val_hw2_buf));
107 		}
108 		if (alt->sc_hw_1 != sys->sc_hw_1) {
109 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_HW_1),
110 			    conv_cap_val_hw1(alt->sc_hw_1, mach, 0,
111 			    &cap_val_buf.cap_val_hw1_buf));
112 		}
113 		if (alt->sc_sf_1 != sys->sc_sf_1) {
114 			dbg_print(lml, MSG_INTL(MSG_CAP_ALT_SF_1),
115 			    conv_cap_val_sf1(alt->sc_sf_1, mach, 0,
116 			    &cap_val_buf.cap_val_sf1_buf));
117 		}
118 	}
119 
120 	Dbg_util_nl(lml, DBG_NL_FRC);
121 }
122 
123 /*
124  * This version takes a pointer to a Capmask, and will report the exclusion
125  * bits if they exist.
126  */
127 void
128 Dbg_cap_ptr_entry(Lm_list *lml, dbg_state_t dbg_state, Xword tag,
129     const char *ptr)
130 {
131 	Conv_inv_buf_t		inv_buf;
132 
133 	if (DBG_NOTCLASS(DBG_C_CAP))
134 		return;
135 
136 	dbg_print(lml, MSG_INTL(MSG_CAP_SEC_ENTRY), Dbg_state_str(dbg_state),
137 	    conv_cap_tag(tag, 0, &inv_buf), ptr);
138 }
139 
140 /*
141  * This version takes a pointer to a CapMask, and will report the exclusion
142  * bits if they exist.
143  */
144 void
145 Dbg_cap_val_entry(Lm_list *lml, dbg_state_t dbg_state, Xword tag, Xword val,
146     Half mach)
147 {
148 	Conv_inv_buf_t		inv_buf;
149 	Conv_cap_val_buf_t	cap_val_buf;
150 
151 	if (DBG_NOTCLASS(DBG_C_CAP))
152 		return;
153 
154 	dbg_print(lml, MSG_INTL(MSG_CAP_SEC_ENTRY), Dbg_state_str(dbg_state),
155 	    conv_cap_tag(tag, 0, &inv_buf), conv_cap_val(tag, val, mach, 0,
156 	    &cap_val_buf));
157 }
158 
159 void
160 Dbg_cap_sec_title(Lm_list *lml, const char *name)
161 {
162 	if (DBG_NOTCLASS(DBG_C_CAP))
163 		return;
164 
165 	Dbg_util_nl(lml, DBG_NL_STD);
166 	dbg_print(lml, MSG_INTL(MSG_CAP_SEC_TITLE), name);
167 }
168 
169 void
170 Dbg_cap_mapfile_title(Lm_list *lml, Lineno lineno)
171 {
172 	if (DBG_NOTCLASS(DBG_C_MAP | DBG_C_CAP))
173 		return;
174 
175 	dbg_print(lml, MSG_INTL(MSG_MAP_CAP), EC_LINENO(lineno));
176 }
177 
178 void
179 Dbg_cap_id(Lm_list *lml, Lineno lineno, const char *oid, const char *nid)
180 {
181 	Dbg_cap_mapfile_title(lml, lineno);
182 	Dbg_cap_ptr_entry(lml, DBG_STATE_CURRENT, CA_SUNW_ID, oid);
183 	Dbg_cap_ptr_entry(lml, DBG_STATE_NEW, CA_SUNW_ID, nid);
184 	Dbg_cap_ptr_entry(lml, DBG_STATE_RESOLVED, CA_SUNW_ID, nid);
185 }
186 
187 void
188 Dbg_cap_post_title(Lm_list *lml, int *title)
189 {
190 	if (DBG_NOTCLASS(DBG_C_CAP))
191 		return;
192 
193 	Dbg_util_nl(lml, DBG_NL_STD);
194 	if ((*title)++ == 0)
195 		dbg_print(lml, MSG_INTL(MSG_CAP_POST_TITLE));
196 }
197 
198 void
199 Elf_cap_title(Lm_list *lml)
200 {
201 	dbg_print(lml, MSG_INTL(MSG_CAP_ELF_TITLE));
202 }
203 
204 void
205 Elf_cap_entry(Lm_list *lml, Cap *cap, int ndx, const char *str, size_t str_size,
206     Half mach)
207 {
208 	Conv_inv_buf_t		inv_buf;
209 	Conv_cap_val_buf_t	cap_val_buf;
210 	char			index[INDEX_STR_SIZE];
211 
212 	(void) snprintf(index, INDEX_STR_SIZE, MSG_ORIG(MSG_FMT_INDEX), ndx);
213 
214 	switch (cap->c_tag) {
215 	case CA_SUNW_PLAT:
216 	case CA_SUNW_MACH:
217 	case CA_SUNW_ID:
218 		/* If offset is in range, format as a string */
219 		if (str && (cap->c_un.c_ptr < str_size)) {
220 			str += cap->c_un.c_ptr;
221 			break;
222 		}
223 		/*FALLTHROUGH*/
224 	default:
225 		/* Format numerically */
226 		str = conv_cap_val(cap->c_tag, cap->c_un.c_val, mach, 0,
227 		    &cap_val_buf);
228 	}
229 
230 	dbg_print(lml, MSG_INTL(MSG_CAP_ELF_ENTRY), index,
231 	    conv_cap_tag(cap->c_tag, 0, &inv_buf), str);
232 }
233