xref: /titanic_51/usr/src/cmd/sgs/prof/common/symintHdr.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 
29 /* * * * * *
30  * symintHdr.h -- symbol information interface, Header file.
31  *
32  * these headers are the definitions used by the set of
33  * routines which provide an interface to access symbol
34  * information stored in the object file.
35  *
36  */
37 	/* protect against multiple inclusion */
38 #ifndef SYMINT_HDR
39 #define SYMINT_HDR
40 
41 
42 
43 #include "libelf.h"
44 #include "sys/elf.h"
45 #include "dwarf.h"
46 
47 
48 
49 /* * * * * *
50  * PROF_DEBUG - compilation-time debug flag
51  *
52  * if this is defined, we include debugging code.
53  *
54  * there are three levels: none, 1, and 2.
55  *
56  * none --	(PROF_DEBUG is undefined.)
57  * 		no debugging code is generated.
58  *
59  * 1 --		(PROF_DEBUG == 1.)
60  * 		assertion code is generated, only.
61  *
62  * 2 --		(PROF_DEBUG == anything else.)
63  * 		both assertion code and debug() code
64  * 		are generated.
65  */
66 
67 #ifndef PROF_DEBUG
68 #	define NDEBUG
69 #	define debug(s)
70 #	define debugsd(s1,d1)
71 #	define debugp1(s)
72 #	define debugp2(s,t)
73 #	define debugp3(s,t,u)
74 #	define debugsn(s,t,u)
75 
76 #elif  PROF_DEBUG == 1
77 #	undef  NDEBUG
78 #	define debug(s1)
79 #	define debugsd(s1,d1)
80 #	define debugp1(s1)
81 #	define debugp2(s1,s2)
82 #	define debugp3(s1,s2,s3)
83 
84 #else	/* == 2, anything else */
85 #	undef  NDEBUG
86 #	define debug(s1)		s1
87 #	define debugsd(s1,d1)		fprintf(stderr,"%s%d",s1,d1);
88 #	define debugp1(s1)		fprintf(stderr,"%s",s1);
89 #	define debugp2(s1,s2)		fprintf(stderr,"%s%s",s1,s2);
90 #	define debugp3(s1,s2,s3)	fprintf(stderr,"%s%s%s",s1,s2,s3);
91 
92 #endif
93 
94 #include "assert.h"
95 
96 
97 
98 /* * * * * *
99  * TARGETPROFILER - #define symbol to indicate whether
100  * the target profiler is ``prof'' or ``lprof''.
101  *
102  * values:
103  * 	2 => prof
104  * 	1 => lprof
105  */
106 
107 
108 	/* default: prof. */
109 #ifndef TARGETPROFILER
110 # define TARGETPROFILER	2
111 #endif
112 
113 #if  TARGETPROFILER == 2
114 #  define isPROF	1
115 #  define whenPROF(s)	s
116 #  undef  isLPROF
117 #  define whenLPROF(s)
118 #else
119 #  define isLPROF	1
120 #  define whenLPROF(s)	s
121 #  undef  isPROF
122 #  define whenPROF(s)
123 #endif
124 
125 
126 
127 
128 /*
129 *	Types
130 *
131 *	- caCOVWORD is used for all entries in the coverage structure.  This
132 *	includes the number of basic blocks, each line number in the line
133 *	number array, and each execution count in the count array.  The size
134 *	(number of bytes) of the coverage structure may be found in the symbol
135 *	table.
136 */
137 typedef unsigned char	BYTES_1;
138 typedef unsigned short	BYTES_2;
139 typedef unsigned int	BYTES_4;
140 typedef unsigned long	BYTES_LONG;		/* ``long'' is 4 bytes, too */
141 typedef BYTES_LONG	caCOVWORD;
142 typedef unsigned char	BOOLEAN;
143 /*
144 *	Type of base address - used in dump.c and soqueue.c.
145 */
146 typedef unsigned long   TYPE_BASEAD;
147 
148 /*
149 *	Macros
150 */
151 
152 #define SYMBOL_IS_FUNC(sym_p)	\
153 	(((sym_p)->ps_dbg.pd_symtag == TAG_subroutine)		\
154 	|| ((sym_p)->ps_dbg.pd_symtag == TAG_global_subroutine))
155 #define SYMBOL_NAME(sym_p)	(sym_p)->ps_dbg.pd_name
156 #define SYMBOL_LINES_P(sym_p)	(sym_p)->ps_dbg.pd_line_p
157 #define SYMBOL_LASTLN_P(sym_p)	(sym_p)->ps_dbg.pd_lali_p
158 
159 #define ISYMBOL_IS_FUNC(sym_p, index)	SYMBOL_IS_FUNC(&((sym_p)[(index)]))
160 #define ISYMBOL_NAME(sym_p, index)	SYMBOL_NAME(&((sym_p)[(index)]))
161 #define ISYMBOL_LINES(sym_p, index)	SYMBOL_LINES(&((sym_p)[(index)]))
162 #define ISYMBOL_LASTLN(sym_p, index)	SYMBOL_LASTLN(&((sym_p)[(index)]))
163 
164 typedef struct {
165 	unsigned char   pe_ident[EI_NIDENT];
166 	Elf32_Half      pe_type;
167 } PROF_MAGIC;
168 
169 #define PROF_MAGIC_FAKE_STRING	"fake prof magic"
170 
171 
172 #define COV_PREFIX	"__coverage."
173 
174 
175 
176 
177 /* * * * * *
178  * ``primitive'' definitions used in
179  * subsequent structures.
180  */
181 
182 typedef	unsigned char		LEN1;
183 
184 typedef	unsigned short		LEN2;
185 
186 typedef	unsigned long int	LEN4;
187 
188 typedef	unsigned long int	ADDR;
189 
190 typedef	LEN2			DBG_TAG;
191 
192 
193 
194 #ifdef isLPROF
195 
196 /* * * * * *
197  * structure recording debug info for a symbol - PROF_DEBUGE.
198  * (PROFiling DEBUG data Entry.)
199  * (also, definitions related to PROF_DEBUGE..)
200  *
201  * DEBUGE - this structure records debugging information
202  * relevant to profiling - specifically to Lprof.
203  * This information is distilled from the debug section
204  * and line section entries.
205  *
206  * LINE - this structure captures line information for
207  * the symbol.  it is incorporated into DEBUGE.
208  */
209 typedef LEN4	PROF_LINE;
210 
211 typedef struct symint_prof_debuge
212 	PROF_DEBUGE;
213 
214 /* ***> ** Hm.. i don't think many of these fields are needed.
215 	** pdname, pd_size are available from symtab entry;
216 	** pd_lowpc, pd_highpc would be used merely to get pd_line/lali_p.
217 	** Hence, we'll go with less and see what happens! rjp Nov-23-1988
218 
219 struct symint_prof_debuge {
220 	char		*pd_name;	?* symbol name or file name *?
221 	DBG_TAG		pd_symtag;	?* symbol tag *?
222 	union {
223 		ADDR	pd_lowpc;	?* entry address or NULL (inline) *?
224 		LEN4	pd_size;	?* struct size (coverage structure) *?
225 	} u;
226 	ADDR		pd_highpc;	?* exit address or NULL *?
227 	PROF_LINE	*pd_line_p;	?* pointer into line section for this
228 					   symbol (null if debug level < 2)*?
229 	PROF_LINE	*pd_lali_p;	?* pointer to last line for function
230 					   symbol (null if debug level < 2)*?
231 	PROF_DEBUGE	*pd_file_p;	?* pointer to next file symbol,
232 					   for files, OR pointer to owner
233 					   file (otherwise) *?
234 };
235 ** ***> */
236 
237 struct symint_prof_debuge {
238 	char		*pd_name;	/* symbol name or file name */
239 
240 	DBG_TAG		pd_symtag;	/* symbol tag */
241 
242 	PROF_LINE	*pd_line_p;	/* pointer to copy of line section
243 					for this symbol - actual line number
244 					section is not aligned.
245 					(null if debug level < 2) */
246 	PROF_LINE	*pd_lali_p;	/* pointer to last line for function
247 					   symbol (null if debug level < 2)*/
248 	PROF_DEBUGE	*pd_file_p;	/* pointer to next file symbol,
249 					   for files, OR pointer to owner
250 					   file (otherwise) */
251 };
252 
253 #endif
254 
255 /* * * * * *
256  * object ``replacing'' a symbol table entry - PROF_SYMBOL.
257  *
258  * a PROF_SYMBOL will contain or direct us to all the information
259  * needed by the profilers, for a given symbol.
260  */
261 typedef struct symint_prof_symbol
262 	PROF_SYMBOL;
263 
264 struct symint_prof_symbol {
265 #ifdef isLPROF
266 		PROF_DEBUGE	ps_dbg;		/* symbol debug entry */
267 #endif
268 		Elf32_Sym	ps_sym;		/* normal symbol entry */
269 };
270 
271 
272 
273 
274 /* * * * * *
275  * structure to replace LDFILE - PROF_FILE.
276  */
277 typedef struct symint_prof_file
278 	PROF_FILE;
279 
280 struct symint_prof_file {
281 	int		pf_fildes;	/* file descriptor */
282 	Elf		*pf_elf_p;	/* elf descriptor */
283 	Elf32_Ehdr	*pf_elfhd_p;	/* elf header */
284 	Elf32_Shdr	*pf_snmshd_p;	/* section names header */
285 	Elf_Data	*pf_snmdat_p;	/* section names data */
286 	Elf32_Shdr	*pf_symshd_p;	/* symbol table header */
287 	Elf_Data	*pf_symdat_p;	/* symbol table data */
288 	Elf32_Shdr	*pf_strshd_p;	/* symbol strings header */
289 	Elf_Data	*pf_strdat_p;	/* symbol strings data */
290 	char		*pf_symstr_p;	/* symbol table strings */
291 	int		pf_nstsyms;	/* number of symbols in symbol table */
292 	Elf32_Shdr	*pf_debugshd_p;	/* debug header */
293 	Elf_Data	*pf_debugdat_p;	/* debug data */
294 	Elf32_Shdr	*pf_lineshd_p;	/* line header */
295 	Elf_Data	*pf_linedat_p;	/* line data */
296 
297 	Elf32_Shdr	*pf_shdarr_p;	/* complete array of section hdrs */
298 
299 	PROF_SYMBOL	*pf_symarr_p;	/* P_S array w/symbols of interest */
300 	int		pf_nsyms;	/* number of symbols of interest */
301 };
302 
303 
304 
305 
306 
307 
308 #endif
309