xref: /titanic_50/usr/src/cmd/sgs/prof/common/symintHdr.h (revision 587032cf0967234b39ccb50adca936a367841063)
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  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 
33 /*
34  * symintHdr.h -- symbol information interface, Header file.
35  *
36  * these headers are the definitions used by the set of
37  * routines which provide an interface to access symbol
38  * information stored in the object file.
39  *
40  */
41 	/* protect against multiple inclusion */
42 #ifndef _SYMINTHDR_H
43 #define	_SYMINTHDR_H
44 
45 
46 
47 #include <libelf.h>
48 #include <sys/elf.h>
49 #include "dwarf.h"
50 
51 
52 /*
53  * PROF_DEBUG - compilation-time debug flag
54  *
55  * if this is defined, we include debugging code.
56  *
57  * there are three levels: none, 1, and 2.
58  *
59  * none --	(PROF_DEBUG is undefined.)
60  * 		no debugging code is generated.
61  *
62  * 1 --		(PROF_DEBUG == 1.)
63  * 		assertion code is generated, only.
64  *
65  * 2 --		(PROF_DEBUG == anything else.)
66  * 		both assertion code and debug() code
67  * 		are generated.
68  */
69 
70 #ifndef PROF_DEBUG
71 #define	NDEBUG
72 #elif  PROF_DEBUG == 1
73 #undef NDEBUG
74 #else	/* == 2, anything else */
75 #undef NDEBUG
76 #endif
77 
78 #include "assert.h"
79 
80 /*
81  * Types
82  *
83  * - caCOVWORD is used for all entries in the coverage structure.  This
84  *   includes the number of basic blocks, each line number in the line
85  *   number array, and each execution count in the count array.  The size
86  *   (number of bytes) of the coverage structure may be found in the symbol
87  *   table.
88  */
89 typedef unsigned char	BYTES_1;
90 typedef unsigned short	BYTES_2;
91 typedef unsigned int	BYTES_4;
92 typedef unsigned long	BYTES_LONG;		/* ``long'' is 4 bytes, too */
93 typedef BYTES_LONG	caCOVWORD;
94 typedef unsigned char	BOOLEAN;
95 
96 /*
97  *	Type of base address - used in dump.c and soqueue.c.
98  */
99 typedef unsigned long   TYPE_BASEAD;
100 
101 /*
102  *	Macros
103  */
104 #define	SYMBOL_IS_FUNC(sym_p)	\
105 	(((sym_p)->ps_dbg.pd_symtag == TAG_subroutine) || \
106 	((sym_p)->ps_dbg.pd_symtag == TAG_global_subroutine))
107 #define	SYMBOL_NAME(sym_p)	(sym_p)->ps_dbg.pd_name
108 #define	SYMBOL_LINES_P(sym_p)	(sym_p)->ps_dbg.pd_line_p
109 #define	SYMBOL_LASTLN_P(sym_p)	(sym_p)->ps_dbg.pd_lali_p
110 
111 #define	ISYMBOL_IS_FUNC(sym_p, index)	SYMBOL_IS_FUNC(&((sym_p)[(index)]))
112 #define	ISYMBOL_NAME(sym_p, index)	SYMBOL_NAME(&((sym_p)[(index)]))
113 #define	ISYMBOL_LINES(sym_p, index)	SYMBOL_LINES(&((sym_p)[(index)]))
114 #define	ISYMBOL_LASTLN(sym_p, index)	SYMBOL_LASTLN(&((sym_p)[(index)]))
115 
116 typedef struct {
117 	unsigned char	pe_ident[EI_NIDENT];
118 	Elf32_Half	pe_type;
119 } PROF_MAGIC;
120 
121 #define	PROF_MAGIC_FAKE_STRING	"fake prof magic"
122 
123 
124 #define	COV_PREFIX	"__coverage."
125 
126 
127 /*
128  * ``primitive'' definitions used in
129  * subsequent structures.
130  */
131 
132 typedef	unsigned char		LEN1;
133 
134 typedef	unsigned short		LEN2;
135 
136 typedef	unsigned long int	LEN4;
137 
138 typedef	unsigned long int	ADDR;
139 
140 typedef	LEN2			DBG_TAG;
141 
142 /*
143  * object ``replacing'' a symbol table entry - PROF_SYMBOL.
144  *
145  * a PROF_SYMBOL will contain or direct us to all the information
146  * needed by the profilers, for a given symbol.
147  */
148 typedef struct symint_prof_symbol
149 	PROF_SYMBOL;
150 
151 struct symint_prof_symbol {
152 	Elf32_Sym	ps_sym;		/* normal symbol entry */
153 };
154 
155 
156 /*
157  * structure to replace LDFILE - PROF_FILE.
158  */
159 typedef struct symint_prof_file
160 	PROF_FILE;
161 
162 struct symint_prof_file {
163 	int		pf_fildes;	/* file descriptor */
164 	Elf		*pf_elf_p;	/* elf descriptor */
165 	Elf32_Ehdr	*pf_elfhd_p;	/* elf header */
166 	Elf32_Shdr	*pf_snmshd_p;	/* section names header */
167 	Elf_Data	*pf_snmdat_p;	/* section names data */
168 	Elf32_Shdr	*pf_symshd_p;	/* symbol table header */
169 	Elf_Data	*pf_symdat_p;	/* symbol table data */
170 	Elf32_Shdr	*pf_strshd_p;	/* symbol strings header */
171 	Elf_Data	*pf_strdat_p;	/* symbol strings data */
172 	char		*pf_symstr_p;	/* symbol table strings */
173 	int		pf_nstsyms;	/* number of symbols in symbol table */
174 	Elf32_Shdr	*pf_debugshd_p;	/* debug header */
175 	Elf_Data	*pf_debugdat_p;	/* debug data */
176 	Elf32_Shdr	*pf_lineshd_p;	/* line header */
177 	Elf_Data	*pf_linedat_p;	/* line data */
178 
179 	Elf32_Shdr	*pf_shdarr_p;	/* complete array of section hdrs */
180 
181 	PROF_SYMBOL	*pf_symarr_p;	/* P_S array w/symbols of interest */
182 	int		pf_nsyms;	/* number of symbols of interest */
183 };
184 
185 #endif /* _SYMINTHDR_H */
186