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