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
5*7a5d89c4Sab  * Common Development and Distribution License (the "License").
6*7a5d89c4Sab  * 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  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
2492ed1782Smike_s /*
25*7a5d89c4Sab  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
2692ed1782Smike_s  * Use is subject to license terms.
2792ed1782Smike_s  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate 
3292ed1782Smike_s /*
337c478bd9Sstevel@tonic-gate  * symintHdr.h -- symbol information interface, Header file.
3492ed1782Smike_s  *
357c478bd9Sstevel@tonic-gate  * these headers are the definitions used by the set of
367c478bd9Sstevel@tonic-gate  * routines which provide an interface to access symbol
377c478bd9Sstevel@tonic-gate  * information stored in the object file.
3892ed1782Smike_s  *
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 	/* protect against multiple inclusion */
4192ed1782Smike_s #ifndef _SYMINTHDR_H
4292ed1782Smike_s #define	_SYMINTHDR_H
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 
4692ed1782Smike_s #include <libelf.h>
4792ed1782Smike_s #include <sys/elf.h>
487c478bd9Sstevel@tonic-gate #include "dwarf.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 
5192ed1782Smike_s /*
527c478bd9Sstevel@tonic-gate  * PROF_DEBUG - compilation-time debug flag
5392ed1782Smike_s  *
547c478bd9Sstevel@tonic-gate  * if this is defined, we include debugging code.
5592ed1782Smike_s  *
567c478bd9Sstevel@tonic-gate  * there are three levels: none, 1, and 2.
5792ed1782Smike_s  *
587c478bd9Sstevel@tonic-gate  * none --	(PROF_DEBUG is undefined.)
597c478bd9Sstevel@tonic-gate  * 		no debugging code is generated.
6092ed1782Smike_s  *
617c478bd9Sstevel@tonic-gate  * 1 --		(PROF_DEBUG == 1.)
627c478bd9Sstevel@tonic-gate  * 		assertion code is generated, only.
6392ed1782Smike_s  *
647c478bd9Sstevel@tonic-gate  * 2 --		(PROF_DEBUG == anything else.)
657c478bd9Sstevel@tonic-gate  * 		both assertion code and debug() code
667c478bd9Sstevel@tonic-gate  * 		are generated.
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #ifndef PROF_DEBUG
7092ed1782Smike_s #define	NDEBUG
7192ed1782Smike_s #elif  PROF_DEBUG == 1
7292ed1782Smike_s #undef NDEBUG
737c478bd9Sstevel@tonic-gate #else	/* == 2, anything else */
7492ed1782Smike_s #undef NDEBUG
757c478bd9Sstevel@tonic-gate #endif
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #include "assert.h"
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
8092ed1782Smike_s  * Types
8192ed1782Smike_s  *
8292ed1782Smike_s  * - caCOVWORD is used for all entries in the coverage structure.  This
8392ed1782Smike_s  *   includes the number of basic blocks, each line number in the line
8492ed1782Smike_s  *   number array, and each execution count in the count array.  The size
8592ed1782Smike_s  *   (number of bytes) of the coverage structure may be found in the symbol
8692ed1782Smike_s  *   table.
8792ed1782Smike_s  */
887c478bd9Sstevel@tonic-gate typedef unsigned char	BYTES_1;
897c478bd9Sstevel@tonic-gate typedef unsigned short	BYTES_2;
907c478bd9Sstevel@tonic-gate typedef unsigned int	BYTES_4;
917c478bd9Sstevel@tonic-gate typedef unsigned long	BYTES_LONG;		/* ``long'' is 4 bytes, too */
927c478bd9Sstevel@tonic-gate typedef BYTES_LONG	caCOVWORD;
937c478bd9Sstevel@tonic-gate typedef unsigned char	BOOLEAN;
9492ed1782Smike_s 
957c478bd9Sstevel@tonic-gate /*
9692ed1782Smike_s  *	Type of base address - used in dump.c and soqueue.c.
9792ed1782Smike_s  */
987c478bd9Sstevel@tonic-gate typedef unsigned long   TYPE_BASEAD;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
10192ed1782Smike_s  *	Macros
10292ed1782Smike_s  */
10392ed1782Smike_s #define	SYMBOL_IS_FUNC(sym_p)	\
10492ed1782Smike_s 	(((sym_p)->ps_dbg.pd_symtag == TAG_subroutine) || \
10592ed1782Smike_s 	((sym_p)->ps_dbg.pd_symtag == TAG_global_subroutine))
10692ed1782Smike_s #define	SYMBOL_NAME(sym_p)	(sym_p)->ps_dbg.pd_name
10792ed1782Smike_s #define	SYMBOL_LINES_P(sym_p)	(sym_p)->ps_dbg.pd_line_p
10892ed1782Smike_s #define	SYMBOL_LASTLN_P(sym_p)	(sym_p)->ps_dbg.pd_lali_p
10992ed1782Smike_s 
11092ed1782Smike_s #define	ISYMBOL_IS_FUNC(sym_p, index)	SYMBOL_IS_FUNC(&((sym_p)[(index)]))
11192ed1782Smike_s #define	ISYMBOL_NAME(sym_p, index)	SYMBOL_NAME(&((sym_p)[(index)]))
11292ed1782Smike_s #define	ISYMBOL_LINES(sym_p, index)	SYMBOL_LINES(&((sym_p)[(index)]))
11392ed1782Smike_s #define	ISYMBOL_LASTLN(sym_p, index)	SYMBOL_LASTLN(&((sym_p)[(index)]))
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate typedef struct {
11692ed1782Smike_s 	unsigned char	pe_ident[EI_NIDENT];
11792ed1782Smike_s 	Elf32_Half	pe_type;
1187c478bd9Sstevel@tonic-gate } PROF_MAGIC;
1197c478bd9Sstevel@tonic-gate 
12092ed1782Smike_s #define	PROF_MAGIC_FAKE_STRING	"fake prof magic"
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 
12392ed1782Smike_s #define	COV_PREFIX	"__coverage."
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 
12692ed1782Smike_s /*
1277c478bd9Sstevel@tonic-gate  * ``primitive'' definitions used in
1287c478bd9Sstevel@tonic-gate  * subsequent structures.
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate typedef	unsigned char		LEN1;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate typedef	unsigned short		LEN2;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate typedef	unsigned long int	LEN4;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate typedef	unsigned long int	ADDR;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate typedef	LEN2			DBG_TAG;
1407c478bd9Sstevel@tonic-gate 
14192ed1782Smike_s /*
1427c478bd9Sstevel@tonic-gate  * object ``replacing'' a symbol table entry - PROF_SYMBOL.
14392ed1782Smike_s  *
1447c478bd9Sstevel@tonic-gate  * a PROF_SYMBOL will contain or direct us to all the information
1457c478bd9Sstevel@tonic-gate  * needed by the profilers, for a given symbol.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate typedef struct symint_prof_symbol
1487c478bd9Sstevel@tonic-gate 	PROF_SYMBOL;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate struct symint_prof_symbol {
15192ed1782Smike_s 	Elf32_Sym	ps_sym;		/* normal symbol entry */
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 
15592ed1782Smike_s /*
1567c478bd9Sstevel@tonic-gate  * structure to replace LDFILE - PROF_FILE.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate typedef struct symint_prof_file
1597c478bd9Sstevel@tonic-gate 	PROF_FILE;
1607c478bd9Sstevel@tonic-gate 
161*7a5d89c4Sab 
162*7a5d89c4Sab /*
163*7a5d89c4Sab  * symint_prof_file contains a primary and an (optional) auxiliary
164*7a5d89c4Sab  * symbol table, which we wish to treat as a single logical symbol table.
165*7a5d89c4Sab  * In this logical table, the data from the auxiliary table preceeds that
166*7a5d89c4Sab  * from the primary. Symbol indices start at [0], which is the first item
167*7a5d89c4Sab  * in the auxiliary table if there is one. The sole purpose for this is so
168*7a5d89c4Sab  * that we can treat the combination of .SUNW_ldynsym and .dynsym sections
169*7a5d89c4Sab  * as a logically single entity.
170*7a5d89c4Sab  *
171*7a5d89c4Sab  * Both tables must share the same string table section.
172*7a5d89c4Sab  */
1737c478bd9Sstevel@tonic-gate struct symint_prof_file {
1747c478bd9Sstevel@tonic-gate 	int		pf_fildes;	/* file descriptor */
1757c478bd9Sstevel@tonic-gate 	Elf		*pf_elf_p;	/* elf descriptor */
1767c478bd9Sstevel@tonic-gate 	Elf32_Ehdr	*pf_elfhd_p;	/* elf header */
1777c478bd9Sstevel@tonic-gate 	Elf_Data	*pf_snmdat_p;	/* section names data */
178*7a5d89c4Sab 	Elf_Data	*pf_symdat_pri_p; /* primary symbol table data */
179*7a5d89c4Sab 	Elf_Data	*pf_symdat_aux_p; /* auxiliary symbol table data */
180*7a5d89c4Sab 	Elf32_Word	pf_symstr_ndx;	 /* Section index of string table */
181*7a5d89c4Sab 	int		pf_nstsyms;	/* total # symbols in both tables */
182*7a5d89c4Sab 	int		pf_nstsyms_aux;	/* # symbols in auxiliary table */
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	Elf32_Shdr	*pf_shdarr_p;	/* complete array of section hdrs */
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	PROF_SYMBOL	*pf_symarr_p;	/* P_S array w/symbols of interest */
1877c478bd9Sstevel@tonic-gate 	int		pf_nsyms;	/* number of symbols of interest */
1887c478bd9Sstevel@tonic-gate };
1897c478bd9Sstevel@tonic-gate 
19092ed1782Smike_s #endif /* _SYMINTHDR_H */
191