xref: /titanic_41/usr/src/cmd/sgs/liblddbg/common/segments.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 2000 by Sun Microsystems, Inc.
24  *	All rights reserved.
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(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_print(MSG_ORIG(MSG_STR_EMPTY));
47 	dbg_print(MSG_ORIG(MSG_SEG_NAME), ndx, str);
48 
49 	Elf_phdr_entry(mach, &sgp->sg_phdr);
50 
51 	dbg_print(MSG_ORIG(MSG_SEG_LENGTH), EC_ADDR(sgp->sg_length));
52 	dbg_print(MSG_ORIG(MSG_SEG_FLAGS), conv_segaflg_str(sgp->sg_flags));
53 	if (sgp->sg_sizesym && sgp->sg_sizesym->sd_name)
54 		dbg_print(MSG_ORIG(MSG_SEG_SIZESYM),
55 		    _Dbg_sym_dem(sgp->sg_sizesym->sd_name));
56 	if (sgp->sg_secorder.head) {
57 		Listnode *	lnp;
58 		Sec_order *	scop;
59 
60 		dbg_print(MSG_ORIG(MSG_SEG_ORDER));
61 		for (LIST_TRAVERSE(&sgp->sg_secorder, lnp, scop)) {
62 			dbg_print(MSG_ORIG(MSG_SEG_SECTION), scop->sco_secname,
63 			    EC_WORD(scop->sco_index));
64 		}
65 	}
66 }
67 
68 void
69 Dbg_seg_title()
70 {
71 	if (DBG_NOTCLASS(DBG_SEGMENTS))
72 		return;
73 
74 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
75 	dbg_print(MSG_INTL(MSG_SEG_DESC_INUSE));
76 }
77 
78 void
79 Dbg_seg_entry(Half mach, int ndx, Sg_desc *sgp)
80 {
81 	if (DBG_NOTCLASS(DBG_SEGMENTS))
82 		return;
83 
84 	_Dbg_seg_desc_entry(mach, ndx, sgp);
85 }
86 
87 /*
88  * Print out the available segment descriptors.
89  */
90 void
91 Dbg_seg_list(Half mach, List *lsg)
92 {
93 	Listnode	*lnp;
94 	Sg_desc		*sgp;
95 	int		ndx = 0;
96 
97 	if (DBG_NOTCLASS(DBG_SEGMENTS))
98 		return;
99 
100 	dbg_print(MSG_ORIG(MSG_STR_EMPTY));
101 	dbg_print(MSG_INTL(MSG_SEG_DESC_AVAIL));
102 	for (LIST_TRAVERSE(lsg, lnp, sgp))
103 		_Dbg_seg_desc_entry(mach, ndx++, sgp);
104 }
105 
106 /*
107  * Print the output section information.  This includes the section header
108  * information and the output elf buffer information.  If the detail flag is
109  * set, traverse the input sections displaying all the input buffers that
110  * have been concatenated to form this output buffer.
111  */
112 void
113 Dbg_seg_os(Ofl_desc *ofl, Os_desc *osp, int ndx)
114 {
115 	Listnode	*lnp;
116 	Is_desc		*isp;
117 
118 	if (DBG_NOTCLASS(DBG_SEGMENTS))
119 		return;
120 
121 	dbg_print(MSG_ORIG(MSG_SEC_NAME), ndx, osp->os_name);
122 	Elf_shdr_entry(ofl->ofl_e_machine, osp->os_shdr);
123 	Gelf_elf_data_title();
124 	_Dbg_elf_data_out(osp);
125 
126 	if (DBG_NOTDETAIL())
127 		return;
128 
129 	for (LIST_TRAVERSE(&(osp->os_isdescs), lnp, isp))
130 		_Dbg_elf_data_in(osp, isp);
131 }
132