xref: /titanic_44/usr/src/cmd/sgs/liblddbg/common/segments.c (revision 69112edd987c28fa551d4f8d9362a84a45365f17)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
23*69112eddSAli Bahrami  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
245aefb655Srie  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*69112eddSAli Bahrami #include	<stdio.h>
287c478bd9Sstevel@tonic-gate #include	"msg.h"
297c478bd9Sstevel@tonic-gate #include	"_debug.h"
307c478bd9Sstevel@tonic-gate #include	"libld.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * Print out a single `segment descriptor' entry.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate void
Dbg_seg_desc_entry(Lm_list * lml,uchar_t osabi,Half mach,int ndx,Sg_desc * sgp,Boolean space_nl)364f680cc6SAli Bahrami Dbg_seg_desc_entry(Lm_list *lml, uchar_t osabi, Half mach, int ndx,
37*69112eddSAli Bahrami     Sg_desc *sgp, Boolean space_nl)
387c478bd9Sstevel@tonic-gate {
39de777a60Sab196087 	Conv_seg_flags_buf_t	seg_flags_buf;
40*69112eddSAli Bahrami 	Aliste			idx;
41*69112eddSAli Bahrami 	Sym_desc		*sdp;
427c478bd9Sstevel@tonic-gate 
43*69112eddSAli Bahrami 	if (space_nl)
445aefb655Srie 		Dbg_util_nl(lml, DBG_NL_STD);
45*69112eddSAli Bahrami 	dbg_print(lml, MSG_ORIG(MSG_SEG_DESC), ndx);
46*69112eddSAli Bahrami 	if (sgp->sg_name)
47*69112eddSAli Bahrami 		dbg_print(lml, MSG_ORIG(MSG_SEG_NAME), sgp->sg_name);
487c478bd9Sstevel@tonic-gate 
495aefb655Srie 	dbg_print(lml, MSG_ORIG(MSG_SEG_FLAGS),
50de777a60Sab196087 	    conv_seg_flags(sgp->sg_flags, &seg_flags_buf));
515aefb655Srie 
52*69112eddSAli Bahrami 	Elf_phdr(lml, osabi, mach, &sgp->sg_phdr);
535aefb655Srie 
54*69112eddSAli Bahrami 	if (sgp->sg_flags & FLG_SG_P_ALIGN)
55*69112eddSAli Bahrami 		dbg_print(lml, MSG_ORIG(MSG_SEG_ALIGN),
56*69112eddSAli Bahrami 		    EC_ADDR(sgp->sg_align));
57*69112eddSAli Bahrami 
58*69112eddSAli Bahrami 	if (sgp->sg_flags & FLG_SG_LENGTH)
59*69112eddSAli Bahrami 		dbg_print(lml, MSG_ORIG(MSG_SEG_LENGTH),
60*69112eddSAli Bahrami 		    EC_ADDR(sgp->sg_length));
61*69112eddSAli Bahrami 
62*69112eddSAli Bahrami 	if (sgp->sg_flags & FLG_SG_ROUND)
63*69112eddSAli Bahrami 		dbg_print(lml, MSG_ORIG(MSG_SEG_ROUND),
64*69112eddSAli Bahrami 		    EC_ADDR(sgp->sg_round));
65*69112eddSAli Bahrami 
66*69112eddSAli Bahrami 	if (aplist_nitems(sgp->sg_sizesym) > 0) {
67*69112eddSAli Bahrami 		dbg_print(lml, MSG_ORIG(MSG_SEG_SIZESYM_TITLE));
68*69112eddSAli Bahrami 		for (APLIST_TRAVERSE(sgp->sg_sizesym, idx, sdp))
69*69112eddSAli Bahrami 			if (sdp->sd_name)
70*69112eddSAli Bahrami 				dbg_print(lml, MSG_ORIG(MSG_SEG_SIZESYM),
71*69112eddSAli Bahrami 				    Dbg_demangle_name(sdp->sd_name));
72*69112eddSAli Bahrami 	}
73*69112eddSAli Bahrami 	if (aplist_nitems(sgp->sg_is_order) > 0) {
74*69112eddSAli Bahrami 		Aliste		idx;
75*69112eddSAli Bahrami 		Ent_desc	*enp;
76*69112eddSAli Bahrami 
77*69112eddSAli Bahrami 		dbg_print(lml, MSG_ORIG(MSG_SEG_IS_ORDER_TITLE));
78*69112eddSAli Bahrami 		for (APLIST_TRAVERSE(sgp->sg_is_order, idx, enp))
79*69112eddSAli Bahrami 			dbg_print(lml, MSG_ORIG(MSG_SEG_LIST_ITEM),
80*69112eddSAli Bahrami 			    enp->ec_name);
81*69112eddSAli Bahrami 	}
82*69112eddSAli Bahrami 	if (alist_nitems(sgp->sg_os_order) > 0) {
83cce0e03bSab196087 		Aliste		idx;
84cce0e03bSab196087 		Sec_order	*scop;
857c478bd9Sstevel@tonic-gate 
86*69112eddSAli Bahrami 		dbg_print(lml, MSG_ORIG(MSG_SEG_OS_ORDER_TITLE));
87*69112eddSAli Bahrami 		for (ALIST_TRAVERSE(sgp->sg_os_order, idx, scop))
88*69112eddSAli Bahrami 			dbg_print(lml, MSG_ORIG(MSG_SEG_LIST_ITEM),
89*69112eddSAli Bahrami 			    scop->sco_secname);
907c478bd9Sstevel@tonic-gate 	}
91*69112eddSAli Bahrami 	if (space_nl)
927010c12aSrie 		Dbg_util_nl(lml, DBG_NL_STD);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate void
Dbg_seg_title(Lm_list * lml)965aefb655Srie Dbg_seg_title(Lm_list *lml)
977c478bd9Sstevel@tonic-gate {
985aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
997c478bd9Sstevel@tonic-gate 		return;
1007c478bd9Sstevel@tonic-gate 
1015aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1025aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_SEG_DESC_INUSE));
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate void
Dbg_seg_entry(Ofl_desc * ofl,int ndx,Sg_desc * sgp)1065aefb655Srie Dbg_seg_entry(Ofl_desc *ofl, int ndx, Sg_desc *sgp)
1077c478bd9Sstevel@tonic-gate {
1085aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
1097c478bd9Sstevel@tonic-gate 		return;
1107c478bd9Sstevel@tonic-gate 
1114f680cc6SAli Bahrami 	Dbg_seg_desc_entry(ofl->ofl_lml, ofl->ofl_dehdr->e_ident[EI_OSABI],
112*69112eddSAli Bahrami 	    ofl->ofl_dehdr->e_machine, ndx, sgp, TRUE);
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * Print out the available segment descriptors.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate void
Dbg_seg_list(Lm_list * lml,uchar_t osabi,Half mach,APlist * apl)1194f680cc6SAli Bahrami Dbg_seg_list(Lm_list *lml, uchar_t osabi, Half mach, APlist *apl)
1207c478bd9Sstevel@tonic-gate {
12157ef7aa9SRod Evans 	Aliste		idx;
1227c478bd9Sstevel@tonic-gate 	Sg_desc		*sgp;
1237c478bd9Sstevel@tonic-gate 	int		ndx = 0;
1247c478bd9Sstevel@tonic-gate 
1255aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
1267c478bd9Sstevel@tonic-gate 		return;
1277c478bd9Sstevel@tonic-gate 
1285aefb655Srie 	Dbg_util_nl(lml, DBG_NL_STD);
1295aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_SEG_DESC_AVAIL));
13057ef7aa9SRod Evans 	for (APLIST_TRAVERSE(apl, idx, sgp))
131*69112eddSAli Bahrami 		Dbg_seg_desc_entry(lml, osabi, mach, ndx++, sgp, TRUE);
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * Print the output section information.  This includes the section header
1367c478bd9Sstevel@tonic-gate  * information and the output elf buffer information.  If the detail flag is
1377c478bd9Sstevel@tonic-gate  * set, traverse the input sections displaying all the input buffers that
1387c478bd9Sstevel@tonic-gate  * have been concatenated to form this output buffer.
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate void
Dbg_seg_os(Ofl_desc * ofl,Os_desc * osp,int ndx)1417c478bd9Sstevel@tonic-gate Dbg_seg_os(Ofl_desc *ofl, Os_desc *osp, int ndx)
1427c478bd9Sstevel@tonic-gate {
143de777a60Sab196087 	Conv_inv_buf_t	inv_buf;
1445aefb655Srie 	Lm_list		*lml = ofl->ofl_lml;
14557ef7aa9SRod Evans 	Aliste		idx;
1467c478bd9Sstevel@tonic-gate 	Is_desc		*isp;
1475aefb655Srie 	Elf_Data	*data;
1485aefb655Srie 	Shdr		*shdr;
149e23c41c9SAli Bahrami 	const char	*empty = MSG_ORIG(MSG_STR_EMPTY);
1501dd9d86fSAli Bahrami 	int		os_isdescs_idx;
1517c478bd9Sstevel@tonic-gate 
1525aefb655Srie 	if (DBG_NOTCLASS(DBG_C_SEGMENTS))
1537c478bd9Sstevel@tonic-gate 		return;
1547c478bd9Sstevel@tonic-gate 
1555aefb655Srie 	dbg_print(lml, MSG_ORIG(MSG_SEC_NAME), ndx, osp->os_name);
1564f680cc6SAli Bahrami 	Elf_shdr(lml, ofl->ofl_dehdr->e_ident[EI_OSABI],
1574f680cc6SAli Bahrami 	    ofl->ofl_dehdr->e_machine, osp->os_shdr);
1585aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_EDATA_TITLE));
1595aefb655Srie 
1605aefb655Srie 	shdr = osp->os_shdr;
1615aefb655Srie 	data = osp->os_outdata;
1625aefb655Srie 	dbg_print(lml, MSG_INTL(MSG_EDATA_ENTRY), MSG_INTL(MSG_STR_OUT),
163de777a60Sab196087 	    EC_ADDR(shdr->sh_addr), conv_elfdata_type(data->d_type, &inv_buf),
1645aefb655Srie 	    EC_XWORD(data->d_size), EC_OFF(data->d_off),
165e23c41c9SAli Bahrami 	    EC_XWORD(data->d_align), empty, empty, empty);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	if (DBG_NOTDETAIL())
1687c478bd9Sstevel@tonic-gate 		return;
1697c478bd9Sstevel@tonic-gate 
1701dd9d86fSAli Bahrami 	OS_ISDESCS_TRAVERSE(os_isdescs_idx, osp, idx, isp) {
171e23c41c9SAli Bahrami 		dbg_isec_name_buf_t	buf;
172e23c41c9SAli Bahrami 		char			*alloc_mem;
1735aefb655Srie 		const char		*file, *str;
1745aefb655Srie 		Addr			addr;
1755aefb655Srie 
1765aefb655Srie 		data = isp->is_indata;
1775aefb655Srie 
1785aefb655Srie 		if (isp->is_flags & FLG_IS_DISCARD) {
1795aefb655Srie 			str = MSG_INTL(MSG_EDATA_IGNSCN);
1805aefb655Srie 			addr = 0;
1815aefb655Srie 		} else {
182e23c41c9SAli Bahrami 			str = empty;
1835aefb655Srie 			addr = (Addr)(shdr->sh_addr + data->d_off);
1845aefb655Srie 		}
1855aefb655Srie 
1865aefb655Srie 		if (isp->is_file && isp->is_file->ifl_name)
1875aefb655Srie 			file = isp->is_file->ifl_name;
1885aefb655Srie 		else
189e23c41c9SAli Bahrami 			file = empty;
1905aefb655Srie 
1915aefb655Srie 		dbg_print(lml, MSG_INTL(MSG_EDATA_ENTRY), MSG_INTL(MSG_STR_IN),
192de777a60Sab196087 		    EC_ADDR(addr), conv_elfdata_type(data->d_type, &inv_buf),
1935aefb655Srie 		    EC_XWORD(data->d_size), EC_OFF(data->d_off),
194e23c41c9SAli Bahrami 		    EC_XWORD(data->d_align), file,
195e23c41c9SAli Bahrami 		    dbg_fmt_isec_name(isp, buf, &alloc_mem), str);
196e23c41c9SAli Bahrami 		if (alloc_mem != NULL)
197e23c41c9SAli Bahrami 			free(alloc_mem);
1985aefb655Srie 	}
1997c478bd9Sstevel@tonic-gate }
200