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