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