xref: /titanic_41/usr/src/cmd/sgs/liblddbg/common/segments.c (revision 2449e17f82f6097fd2c665b64723e31ceecbeca6)
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	"msg.h"
29 #include	"_debug.h"
30 #include	"libld.h"
31 
32 
33 /*
34  * Print out a single `segment descriptor' entry.
35  */
36 void
37 Dbg_seg_desc_entry(Lm_list *lml, Half mach, int ndx, Sg_desc *sgp)
38 {
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, 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));
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		off;
61 		Sec_order	**scopp;
62 
63 		dbg_print(lml, MSG_ORIG(MSG_SEG_ORDER));
64 		for (ALIST_TRAVERSE(sgp->sg_secorder, off, scopp)) {
65 			Sec_order	*scop = *scopp;
66 
67 			dbg_print(lml, MSG_ORIG(MSG_SEG_SECTION),
68 			    scop->sco_secname, EC_WORD(scop->sco_index));
69 		}
70 	}
71 	Dbg_util_nl(lml, DBG_NL_STD);
72 }
73 
74 void
75 Dbg_seg_title(Lm_list *lml)
76 {
77 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
78 		return;
79 
80 	Dbg_util_nl(lml, DBG_NL_STD);
81 	dbg_print(lml, MSG_INTL(MSG_SEG_DESC_INUSE));
82 }
83 
84 void
85 Dbg_seg_entry(Ofl_desc *ofl, int ndx, Sg_desc *sgp)
86 {
87 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
88 		return;
89 
90 	Dbg_seg_desc_entry(ofl->ofl_lml, ofl->ofl_dehdr->e_machine, ndx, sgp);
91 }
92 
93 /*
94  * Print out the available segment descriptors.
95  */
96 void
97 Dbg_seg_list(Lm_list *lml, Half mach, List *lsg)
98 {
99 	Listnode	*lnp;
100 	Sg_desc		*sgp;
101 	int		ndx = 0;
102 
103 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
104 		return;
105 
106 	Dbg_util_nl(lml, DBG_NL_STD);
107 	dbg_print(lml, MSG_INTL(MSG_SEG_DESC_AVAIL));
108 	for (LIST_TRAVERSE(lsg, lnp, sgp))
109 		Dbg_seg_desc_entry(lml, mach, ndx++, sgp);
110 }
111 
112 /*
113  * Print the output section information.  This includes the section header
114  * information and the output elf buffer information.  If the detail flag is
115  * set, traverse the input sections displaying all the input buffers that
116  * have been concatenated to form this output buffer.
117  */
118 void
119 Dbg_seg_os(Ofl_desc *ofl, Os_desc *osp, int ndx)
120 {
121 	Lm_list		*lml = ofl->ofl_lml;
122 	Listnode	*lnp;
123 	Is_desc		*isp;
124 	Elf_Data	*data;
125 	Shdr		*shdr;
126 
127 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
128 		return;
129 
130 	dbg_print(lml, MSG_ORIG(MSG_SEC_NAME), ndx, osp->os_name);
131 	Elf_shdr(lml, ofl->ofl_dehdr->e_machine, osp->os_shdr);
132 	dbg_print(lml, MSG_INTL(MSG_EDATA_TITLE));
133 
134 	shdr = osp->os_shdr;
135 	data = osp->os_outdata;
136 	dbg_print(lml, MSG_INTL(MSG_EDATA_ENTRY), MSG_INTL(MSG_STR_OUT),
137 	    EC_ADDR(shdr->sh_addr), conv_elfdata_type(data->d_type),
138 	    EC_XWORD(data->d_size), EC_OFF(data->d_off),
139 	    EC_XWORD(data->d_align), MSG_ORIG(MSG_STR_EMPTY),
140 	    MSG_ORIG(MSG_STR_EMPTY));
141 
142 	if (DBG_NOTDETAIL())
143 		return;
144 
145 	for (LIST_TRAVERSE(&(osp->os_isdescs), lnp, isp)) {
146 		const char	*file, *str;
147 		Addr		addr;
148 
149 		data = isp->is_indata;
150 
151 		if (isp->is_flags & FLG_IS_DISCARD) {
152 			str = MSG_INTL(MSG_EDATA_IGNSCN);
153 			addr = 0;
154 		} else {
155 			str = MSG_ORIG(MSG_STR_EMPTY);
156 			addr = (Addr)(shdr->sh_addr + data->d_off);
157 		}
158 
159 		if (isp->is_file && isp->is_file->ifl_name)
160 			file = isp->is_file->ifl_name;
161 		else
162 			file = MSG_ORIG(MSG_STR_EMPTY);
163 
164 		dbg_print(lml, MSG_INTL(MSG_EDATA_ENTRY), MSG_INTL(MSG_STR_IN),
165 		    EC_ADDR(addr), conv_elfdata_type(data->d_type),
166 		    EC_XWORD(data->d_size), EC_OFF(data->d_off),
167 		    EC_XWORD(data->d_align), file, str);
168 	}
169 }
170