xref: /titanic_50/usr/src/cmd/sgs/prof/common/symintHdr.h (revision dfb96a4f56fb431b915bc67e5d9d5c8d4f4f6679)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*	Copyright (c) 1988 AT&T	*/
22 /*	  All Rights Reserved  	*/
23 
24 /*
25  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 
32 /*
33  * symintHdr.h -- symbol information interface, Header file.
34  *
35  * these headers are the definitions used by the set of
36  * routines which provide an interface to access symbol
37  * information stored in the object file.
38  *
39  */
40 	/* protect against multiple inclusion */
41 #ifndef _SYMINTHDR_H
42 #define	_SYMINTHDR_H
43 
44 
45 
46 #include <libelf.h>
47 #include <sys/elf.h>
48 #include "dwarf.h"
49 
50 
51 /*
52  * PROF_DEBUG - compilation-time debug flag
53  *
54  * if this is defined, we include debugging code.
55  *
56  * there are three levels: none, 1, and 2.
57  *
58  * none --	(PROF_DEBUG is undefined.)
59  * 		no debugging code is generated.
60  *
61  * 1 --		(PROF_DEBUG == 1.)
62  * 		assertion code is generated, only.
63  *
64  * 2 --		(PROF_DEBUG == anything else.)
65  * 		both assertion code and debug() code
66  * 		are generated.
67  */
68 
69 #ifndef PROF_DEBUG
70 #define	NDEBUG
71 #elif  PROF_DEBUG == 1
72 #undef NDEBUG
73 #else	/* == 2, anything else */
74 #undef NDEBUG
75 #endif
76 
77 #include "assert.h"
78 
79 /*
80  * Types
81  *
82  * - caCOVWORD is used for all entries in the coverage structure.  This
83  *   includes the number of basic blocks, each line number in the line
84  *   number array, and each execution count in the count array.  The size
85  *   (number of bytes) of the coverage structure may be found in the symbol
86  *   table.
87  */
88 typedef unsigned char	BYTES_1;
89 typedef unsigned short	BYTES_2;
90 typedef unsigned int	BYTES_4;
91 typedef unsigned long	BYTES_LONG;		/* ``long'' is 4 bytes, too */
92 typedef BYTES_LONG	caCOVWORD;
93 typedef unsigned char	BOOLEAN;
94 
95 /*
96  *	Type of base address - used in dump.c and soqueue.c.
97  */
98 typedef unsigned long   TYPE_BASEAD;
99 
100 /*
101  *	Macros
102  */
103 #define	SYMBOL_IS_FUNC(sym_p)	\
104 	(((sym_p)->ps_dbg.pd_symtag == TAG_subroutine) || \
105 	((sym_p)->ps_dbg.pd_symtag == TAG_global_subroutine))
106 #define	SYMBOL_NAME(sym_p)	(sym_p)->ps_dbg.pd_name
107 #define	SYMBOL_LINES_P(sym_p)	(sym_p)->ps_dbg.pd_line_p
108 #define	SYMBOL_LASTLN_P(sym_p)	(sym_p)->ps_dbg.pd_lali_p
109 
110 #define	ISYMBOL_IS_FUNC(sym_p, index)	SYMBOL_IS_FUNC(&((sym_p)[(index)]))
111 #define	ISYMBOL_NAME(sym_p, index)	SYMBOL_NAME(&((sym_p)[(index)]))
112 #define	ISYMBOL_LINES(sym_p, index)	SYMBOL_LINES(&((sym_p)[(index)]))
113 #define	ISYMBOL_LASTLN(sym_p, index)	SYMBOL_LASTLN(&((sym_p)[(index)]))
114 
115 typedef struct {
116 	unsigned char	pe_ident[EI_NIDENT];
117 	Elf32_Half	pe_type;
118 } PROF_MAGIC;
119 
120 #define	PROF_MAGIC_FAKE_STRING	"fake prof magic"
121 
122 
123 #define	COV_PREFIX	"__coverage."
124 
125 
126 /*
127  * ``primitive'' definitions used in
128  * subsequent structures.
129  */
130 
131 typedef	unsigned char		LEN1;
132 
133 typedef	unsigned short		LEN2;
134 
135 typedef	unsigned long int	LEN4;
136 
137 typedef	unsigned long int	ADDR;
138 
139 typedef	LEN2			DBG_TAG;
140 
141 /*
142  * object ``replacing'' a symbol table entry - PROF_SYMBOL.
143  *
144  * a PROF_SYMBOL will contain or direct us to all the information
145  * needed by the profilers, for a given symbol.
146  */
147 typedef struct symint_prof_symbol
148 	PROF_SYMBOL;
149 
150 struct symint_prof_symbol {
151 	Elf32_Sym	ps_sym;		/* normal symbol entry */
152 };
153 
154 
155 /*
156  * structure to replace LDFILE - PROF_FILE.
157  */
158 typedef struct symint_prof_file
159 	PROF_FILE;
160 
161 
162 /*
163  * symint_prof_file contains a primary and an (optional) auxiliary
164  * symbol table, which we wish to treat as a single logical symbol table.
165  * In this logical table, the data from the auxiliary table preceeds that
166  * from the primary. Symbol indices start at [0], which is the first item
167  * in the auxiliary table if there is one. The sole purpose for this is so
168  * that we can treat the combination of .SUNW_ldynsym and .dynsym sections
169  * as a logically single entity.
170  *
171  * Both tables must share the same string table section.
172  */
173 struct symint_prof_file {
174 	int		pf_fildes;	/* file descriptor */
175 	Elf		*pf_elf_p;	/* elf descriptor */
176 	Elf32_Ehdr	*pf_elfhd_p;	/* elf header */
177 	Elf_Data	*pf_snmdat_p;	/* section names data */
178 	Elf_Data	*pf_symdat_pri_p; /* primary symbol table data */
179 	Elf_Data	*pf_symdat_aux_p; /* auxiliary symbol table data */
180 	Elf32_Word	pf_symstr_ndx;	 /* Section index of string table */
181 	int		pf_nstsyms;	/* total # symbols in both tables */
182 	int		pf_nstsyms_aux;	/* # symbols in auxiliary table */
183 
184 	Elf32_Shdr	*pf_shdarr_p;	/* complete array of section hdrs */
185 
186 	PROF_SYMBOL	*pf_symarr_p;	/* P_S array w/symbols of interest */
187 	int		pf_nsyms;	/* number of symbols of interest */
188 };
189 
190 #endif /* _SYMINTHDR_H */
191