xref: /onnv-gate/usr/src/cmd/sgs/prof/common/symintHdr.h (revision 3621:2cbc0f92c696)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3621Sab196087  * Common Development and Distribution License (the "License").
6*3621Sab196087  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
220Sstevel@tonic-gate /*	  All Rights Reserved  	*/
230Sstevel@tonic-gate 
24211Smike_s /*
25*3621Sab196087  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
26211Smike_s  * Use is subject to license terms.
27211Smike_s  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate 
32211Smike_s /*
330Sstevel@tonic-gate  * symintHdr.h -- symbol information interface, Header file.
34211Smike_s  *
350Sstevel@tonic-gate  * these headers are the definitions used by the set of
360Sstevel@tonic-gate  * routines which provide an interface to access symbol
370Sstevel@tonic-gate  * information stored in the object file.
38211Smike_s  *
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 	/* protect against multiple inclusion */
41211Smike_s #ifndef _SYMINTHDR_H
42211Smike_s #define	_SYMINTHDR_H
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 
450Sstevel@tonic-gate 
46211Smike_s #include <libelf.h>
47211Smike_s #include <sys/elf.h>
480Sstevel@tonic-gate #include "dwarf.h"
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 
51211Smike_s /*
520Sstevel@tonic-gate  * PROF_DEBUG - compilation-time debug flag
53211Smike_s  *
540Sstevel@tonic-gate  * if this is defined, we include debugging code.
55211Smike_s  *
560Sstevel@tonic-gate  * there are three levels: none, 1, and 2.
57211Smike_s  *
580Sstevel@tonic-gate  * none --	(PROF_DEBUG is undefined.)
590Sstevel@tonic-gate  * 		no debugging code is generated.
60211Smike_s  *
610Sstevel@tonic-gate  * 1 --		(PROF_DEBUG == 1.)
620Sstevel@tonic-gate  * 		assertion code is generated, only.
63211Smike_s  *
640Sstevel@tonic-gate  * 2 --		(PROF_DEBUG == anything else.)
650Sstevel@tonic-gate  * 		both assertion code and debug() code
660Sstevel@tonic-gate  * 		are generated.
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #ifndef PROF_DEBUG
70211Smike_s #define	NDEBUG
71211Smike_s #elif  PROF_DEBUG == 1
72211Smike_s #undef NDEBUG
730Sstevel@tonic-gate #else	/* == 2, anything else */
74211Smike_s #undef NDEBUG
750Sstevel@tonic-gate #endif
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #include "assert.h"
780Sstevel@tonic-gate 
79211Smike_s /*
80211Smike_s  * Types
81211Smike_s  *
82211Smike_s  * - caCOVWORD is used for all entries in the coverage structure.  This
83211Smike_s  *   includes the number of basic blocks, each line number in the line
84211Smike_s  *   number array, and each execution count in the count array.  The size
85211Smike_s  *   (number of bytes) of the coverage structure may be found in the symbol
86211Smike_s  *   table.
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate typedef unsigned char	BYTES_1;
890Sstevel@tonic-gate typedef unsigned short	BYTES_2;
900Sstevel@tonic-gate typedef unsigned int	BYTES_4;
910Sstevel@tonic-gate typedef unsigned long	BYTES_LONG;		/* ``long'' is 4 bytes, too */
920Sstevel@tonic-gate typedef BYTES_LONG	caCOVWORD;
930Sstevel@tonic-gate typedef unsigned char	BOOLEAN;
94211Smike_s 
950Sstevel@tonic-gate /*
96211Smike_s  *	Type of base address - used in dump.c and soqueue.c.
97211Smike_s  */
980Sstevel@tonic-gate typedef unsigned long   TYPE_BASEAD;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate /*
101211Smike_s  *	Macros
102211Smike_s  */
103211Smike_s #define	SYMBOL_IS_FUNC(sym_p)	\
104211Smike_s 	(((sym_p)->ps_dbg.pd_symtag == TAG_subroutine) || \
105211Smike_s 	((sym_p)->ps_dbg.pd_symtag == TAG_global_subroutine))
106211Smike_s #define	SYMBOL_NAME(sym_p)	(sym_p)->ps_dbg.pd_name
107211Smike_s #define	SYMBOL_LINES_P(sym_p)	(sym_p)->ps_dbg.pd_line_p
108211Smike_s #define	SYMBOL_LASTLN_P(sym_p)	(sym_p)->ps_dbg.pd_lali_p
1090Sstevel@tonic-gate 
110211Smike_s #define	ISYMBOL_IS_FUNC(sym_p, index)	SYMBOL_IS_FUNC(&((sym_p)[(index)]))
111211Smike_s #define	ISYMBOL_NAME(sym_p, index)	SYMBOL_NAME(&((sym_p)[(index)]))
112211Smike_s #define	ISYMBOL_LINES(sym_p, index)	SYMBOL_LINES(&((sym_p)[(index)]))
113211Smike_s #define	ISYMBOL_LASTLN(sym_p, index)	SYMBOL_LASTLN(&((sym_p)[(index)]))
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate typedef struct {
116211Smike_s 	unsigned char	pe_ident[EI_NIDENT];
117211Smike_s 	Elf32_Half	pe_type;
1180Sstevel@tonic-gate } PROF_MAGIC;
1190Sstevel@tonic-gate 
120211Smike_s #define	PROF_MAGIC_FAKE_STRING	"fake prof magic"
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 
123211Smike_s #define	COV_PREFIX	"__coverage."
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 
126211Smike_s /*
1270Sstevel@tonic-gate  * ``primitive'' definitions used in
1280Sstevel@tonic-gate  * subsequent structures.
1290Sstevel@tonic-gate  */
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate typedef	unsigned char		LEN1;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate typedef	unsigned short		LEN2;
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate typedef	unsigned long int	LEN4;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate typedef	unsigned long int	ADDR;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate typedef	LEN2			DBG_TAG;
1400Sstevel@tonic-gate 
141211Smike_s /*
1420Sstevel@tonic-gate  * object ``replacing'' a symbol table entry - PROF_SYMBOL.
143211Smike_s  *
1440Sstevel@tonic-gate  * a PROF_SYMBOL will contain or direct us to all the information
1450Sstevel@tonic-gate  * needed by the profilers, for a given symbol.
1460Sstevel@tonic-gate  */
1470Sstevel@tonic-gate typedef struct symint_prof_symbol
1480Sstevel@tonic-gate 	PROF_SYMBOL;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate struct symint_prof_symbol {
151211Smike_s 	Elf32_Sym	ps_sym;		/* normal symbol entry */
1520Sstevel@tonic-gate };
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 
155211Smike_s /*
1560Sstevel@tonic-gate  * structure to replace LDFILE - PROF_FILE.
1570Sstevel@tonic-gate  */
1580Sstevel@tonic-gate typedef struct symint_prof_file
1590Sstevel@tonic-gate 	PROF_FILE;
1600Sstevel@tonic-gate 
161*3621Sab196087 
162*3621Sab196087 /*
163*3621Sab196087  * symint_prof_file contains a primary and an (optional) auxiliary
164*3621Sab196087  * symbol table, which we wish to treat as a single logical symbol table.
165*3621Sab196087  * In this logical table, the data from the auxiliary table preceeds that
166*3621Sab196087  * from the primary. Symbol indices start at [0], which is the first item
167*3621Sab196087  * in the auxiliary table if there is one. The sole purpose for this is so
168*3621Sab196087  * that we can treat the combination of .SUNW_ldynsym and .dynsym sections
169*3621Sab196087  * as a logically single entity.
170*3621Sab196087  *
171*3621Sab196087  * Both tables must share the same string table section.
172*3621Sab196087  */
1730Sstevel@tonic-gate struct symint_prof_file {
1740Sstevel@tonic-gate 	int		pf_fildes;	/* file descriptor */
1750Sstevel@tonic-gate 	Elf		*pf_elf_p;	/* elf descriptor */
1760Sstevel@tonic-gate 	Elf32_Ehdr	*pf_elfhd_p;	/* elf header */
1770Sstevel@tonic-gate 	Elf_Data	*pf_snmdat_p;	/* section names data */
178*3621Sab196087 	Elf_Data	*pf_symdat_pri_p; /* primary symbol table data */
179*3621Sab196087 	Elf_Data	*pf_symdat_aux_p; /* auxiliary symbol table data */
180*3621Sab196087 	Elf32_Word	pf_symstr_ndx;	 /* Section index of string table */
181*3621Sab196087 	int		pf_nstsyms;	/* total # symbols in both tables */
182*3621Sab196087 	int		pf_nstsyms_aux;	/* # symbols in auxiliary table */
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	Elf32_Shdr	*pf_shdarr_p;	/* complete array of section hdrs */
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	PROF_SYMBOL	*pf_symarr_p;	/* P_S array w/symbols of interest */
1870Sstevel@tonic-gate 	int		pf_nsyms;	/* number of symbols of interest */
1880Sstevel@tonic-gate };
1890Sstevel@tonic-gate 
190211Smike_s #endif /* _SYMINTHDR_H */
191