xref: /titanic_50/usr/src/cmd/sgs/liblddbg/common/segments.c (revision 24fe0b3bf671e123467ce1df0b67cadd3614c8e4)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include	"msg.h"
28 #include	"_debug.h"
29 #include	"libld.h"
30 
31 /*
32  * Print out a single `segment descriptor' entry.
33  */
34 void
35 Dbg_seg_desc_entry(Lm_list *lml, uchar_t osabi, Half mach, int ndx,
36     Sg_desc *sgp)
37 {
38 	Conv_seg_flags_buf_t	seg_flags_buf;
39 	const char		*str;
40 
41 	if (sgp->sg_name && *sgp->sg_name)
42 		str = sgp->sg_name;
43 	else
44 		str = MSG_INTL(MSG_STR_NULL);
45 
46 	Dbg_util_nl(lml, DBG_NL_STD);
47 	dbg_print(lml, MSG_ORIG(MSG_SEG_NAME), ndx, str);
48 
49 	Elf_phdr(lml, osabi, mach, &sgp->sg_phdr);
50 
51 	dbg_print(lml, MSG_ORIG(MSG_SEG_LENGTH), EC_ADDR(sgp->sg_length));
52 	dbg_print(lml, MSG_ORIG(MSG_SEG_FLAGS),
53 	    conv_seg_flags(sgp->sg_flags, &seg_flags_buf));
54 
55 	if (sgp->sg_sizesym && sgp->sg_sizesym->sd_name)
56 		dbg_print(lml, MSG_ORIG(MSG_SEG_SIZESYM),
57 		    Dbg_demangle_name(sgp->sg_sizesym->sd_name));
58 
59 	if (sgp->sg_secorder) {
60 		Aliste		idx;
61 		Sec_order	*scop;
62 
63 		dbg_print(lml, MSG_ORIG(MSG_SEG_ORDER));
64 		for (APLIST_TRAVERSE(sgp->sg_secorder, idx, scop))
65 			dbg_print(lml, MSG_ORIG(MSG_SEG_SECTION),
66 			    scop->sco_secname, EC_WORD(scop->sco_index));
67 	}
68 	Dbg_util_nl(lml, DBG_NL_STD);
69 }
70 
71 void
72 Dbg_seg_title(Lm_list *lml)
73 {
74 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
75 		return;
76 
77 	Dbg_util_nl(lml, DBG_NL_STD);
78 	dbg_print(lml, MSG_INTL(MSG_SEG_DESC_INUSE));
79 }
80 
81 void
82 Dbg_seg_entry(Ofl_desc *ofl, int ndx, Sg_desc *sgp)
83 {
84 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
85 		return;
86 
87 	Dbg_seg_desc_entry(ofl->ofl_lml, ofl->ofl_dehdr->e_ident[EI_OSABI],
88 	    ofl->ofl_dehdr->e_machine, ndx, sgp);
89 }
90 
91 /*
92  * Print out the available segment descriptors.
93  */
94 void
95 Dbg_seg_list(Lm_list *lml, uchar_t osabi, Half mach, APlist *apl)
96 {
97 	Aliste		idx;
98 	Sg_desc		*sgp;
99 	int		ndx = 0;
100 
101 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
102 		return;
103 
104 	Dbg_util_nl(lml, DBG_NL_STD);
105 	dbg_print(lml, MSG_INTL(MSG_SEG_DESC_AVAIL));
106 	for (APLIST_TRAVERSE(apl, idx, sgp))
107 		Dbg_seg_desc_entry(lml, osabi, mach, ndx++, sgp);
108 }
109 
110 /*
111  * Print the output section information.  This includes the section header
112  * information and the output elf buffer information.  If the detail flag is
113  * set, traverse the input sections displaying all the input buffers that
114  * have been concatenated to form this output buffer.
115  */
116 void
117 Dbg_seg_os(Ofl_desc *ofl, Os_desc *osp, int ndx)
118 {
119 	Conv_inv_buf_t	inv_buf;
120 	Lm_list		*lml = ofl->ofl_lml;
121 	Aliste		idx;
122 	Is_desc		*isp;
123 	Elf_Data	*data;
124 	Shdr		*shdr;
125 	const char	*empty = MSG_ORIG(MSG_STR_EMPTY);
126 	int		os_isdescs_idx;
127 
128 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
129 		return;
130 
131 	dbg_print(lml, MSG_ORIG(MSG_SEC_NAME), ndx, osp->os_name);
132 	Elf_shdr(lml, ofl->ofl_dehdr->e_ident[EI_OSABI],
133 	    ofl->ofl_dehdr->e_machine, osp->os_shdr);
134 	dbg_print(lml, MSG_INTL(MSG_EDATA_TITLE));
135 
136 	shdr = osp->os_shdr;
137 	data = osp->os_outdata;
138 	dbg_print(lml, MSG_INTL(MSG_EDATA_ENTRY), MSG_INTL(MSG_STR_OUT),
139 	    EC_ADDR(shdr->sh_addr), conv_elfdata_type(data->d_type, &inv_buf),
140 	    EC_XWORD(data->d_size), EC_OFF(data->d_off),
141 	    EC_XWORD(data->d_align), empty, empty, empty);
142 
143 	if (DBG_NOTDETAIL())
144 		return;
145 
146 	OS_ISDESCS_TRAVERSE(os_isdescs_idx, osp, idx, isp) {
147 		dbg_isec_name_buf_t	buf;
148 		char			*alloc_mem;
149 		const char		*file, *str;
150 		Addr			addr;
151 
152 		data = isp->is_indata;
153 
154 		if (isp->is_flags & FLG_IS_DISCARD) {
155 			str = MSG_INTL(MSG_EDATA_IGNSCN);
156 			addr = 0;
157 		} else {
158 			str = empty;
159 			addr = (Addr)(shdr->sh_addr + data->d_off);
160 		}
161 
162 		if (isp->is_file && isp->is_file->ifl_name)
163 			file = isp->is_file->ifl_name;
164 		else
165 			file = empty;
166 
167 		dbg_print(lml, MSG_INTL(MSG_EDATA_ENTRY), MSG_INTL(MSG_STR_IN),
168 		    EC_ADDR(addr), conv_elfdata_type(data->d_type, &inv_buf),
169 		    EC_XWORD(data->d_size), EC_OFF(data->d_off),
170 		    EC_XWORD(data->d_align), file,
171 		    dbg_fmt_isec_name(isp, buf, &alloc_mem), str);
172 		if (alloc_mem != NULL)
173 			free(alloc_mem);
174 	}
175 }
176