xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/syminfo.c (revision d0f40dc6a997c84bacf5f9ba83d57a95495c399b)
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 #include	<sgs.h>
27 #include	<stdio.h>
28 #include	<debug.h>
29 #include	<msg.h>
30 
31 void
32 Elf_syminfo_title(Lm_list *lml)
33 {
34 	dbg_print(lml, MSG_INTL(MSG_SYMINFO_TITLE));
35 }
36 
37 #define	FLAGSZ	16
38 #define	NDXSZ	10
39 
40 void
41 Elf_syminfo_entry(Lm_list *lml, Word ndx, Syminfo *sip, const char *name,
42     const char *needed)
43 {
44 	const char	*bndstr = NULL, *str;
45 	char		flagstr[FLAGSZ], sndxstr[NDXSZ], dndxstr[NDXSZ];
46 	int		flgndx = 0;
47 	Half		flags = sip->si_flags;
48 
49 	if (flags & SYMINFO_FLG_CAP) {
50 		bndstr = MSG_INTL(MSG_SYMINFO_CAP);
51 		flagstr[flgndx++] = 'S';
52 		flags &= ~SYMINFO_FLG_CAP;
53 	}
54 
55 	if (flags & SYMINFO_FLG_DIRECT) {
56 		if (bndstr == NULL) {
57 			if (sip->si_boundto == SYMINFO_BT_SELF)
58 				bndstr = MSG_INTL(MSG_SYMINFO_SELF);
59 			else if (sip->si_boundto == SYMINFO_BT_PARENT)
60 				bndstr = MSG_INTL(MSG_SYMINFO_PARENT);
61 			else
62 				bndstr = needed;
63 		}
64 		flagstr[flgndx++] = 'D';
65 		flags &= ~SYMINFO_FLG_DIRECT;
66 
67 	} else if (flags & SYMINFO_FLG_FILTER) {
68 		bndstr = needed;
69 		flagstr[flgndx++] = 'F';
70 		flags &= ~SYMINFO_FLG_FILTER;
71 
72 	} else if (flags & SYMINFO_FLG_AUXILIARY) {
73 		bndstr = needed;
74 		flagstr[flgndx++] = 'A';
75 		flags &= ~SYMINFO_FLG_AUXILIARY;
76 
77 	} else if (sip->si_boundto == SYMINFO_BT_EXTERN)
78 		bndstr = MSG_INTL(MSG_SYMINFO_EXTERN);
79 	else if (bndstr == NULL)
80 		bndstr = MSG_ORIG(MSG_STR_EMPTY);
81 
82 	if (flags & SYMINFO_FLG_DIRECTBIND) {
83 		flagstr[flgndx++] = 'B';
84 		flags &= ~SYMINFO_FLG_DIRECTBIND;
85 	}
86 	if (flags & SYMINFO_FLG_COPY) {
87 		flagstr[flgndx++] = 'C';
88 		flags &= ~SYMINFO_FLG_COPY;
89 	}
90 	if (flags & SYMINFO_FLG_LAZYLOAD) {
91 		flagstr[flgndx++] = 'L';
92 		flags &= ~SYMINFO_FLG_LAZYLOAD;
93 	}
94 	if (flags & SYMINFO_FLG_NOEXTDIRECT) {
95 		flagstr[flgndx++] = 'N';
96 		flags &= ~SYMINFO_FLG_NOEXTDIRECT;
97 	}
98 	if (flags & SYMINFO_FLG_INTERPOSE) {
99 		flagstr[flgndx++] = 'I';
100 		flags &= ~SYMINFO_FLG_INTERPOSE;
101 	}
102 
103 	/*
104 	 * Did we account for all of the flags?
105 	 */
106 	if (flags)
107 		(void) snprintf(&flagstr[flgndx], FLAGSZ - flgndx,
108 		    MSG_ORIG(MSG_SYMINFO_UNKFLAG), flags);
109 	else
110 		flagstr[flgndx] = '\0';
111 
112 	/*
113 	 * If we've bound to a dependency, determine the dynamic entry index.
114 	 */
115 	if (bndstr == needed) {
116 		(void) snprintf(dndxstr, NDXSZ, MSG_ORIG(MSG_FMT_INDEX),
117 		    sip->si_boundto);
118 		str = dndxstr;
119 	} else
120 		str = MSG_ORIG(MSG_STR_EMPTY);
121 
122 	(void) snprintf(sndxstr, NDXSZ, MSG_ORIG(MSG_FMT_INDEX), ndx);
123 
124 	dbg_print(lml, MSG_INTL(MSG_SYMINFO_ENTRY), sndxstr, flagstr, str,
125 	    bndstr, Elf_demangle_name(name));
126 }
127