xref: /titanic_50/usr/src/cmd/sgs/include/dwarf.h (revision 82d33c01b078ed404a986a369750cdb4743773fb)
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) 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef _DWARF_H
32 #define	_DWARF_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/types.h>
37 
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 
44 
45 /* dwarf.h - manifest constants used in the .debug section of ELF files */
46 
47 
48 /* the "tag" - the first short of any legal record */
49 
50 #define	TAG_padding			0x0000
51 #define	TAG_array_type			0x0001
52 #define	TAG_class_type			0x0002
53 #define	TAG_entry_point			0x0003
54 #define	TAG_enumeration_type		0x0004
55 #define	TAG_formal_parameter		0x0005
56 #define	TAG_global_subroutine		0x0006
57 #define	TAG_global_variable		0x0007
58 #define	TAG_imported_declaration	0x0008
59 #define	TAG_inline_subroutine		0x0009
60 #define	TAG_label			0x000a
61 #define	TAG_lexical_block		0x000b
62 #define	TAG_local_variable		0x000c
63 #define	TAG_member			0x000d
64 #define	TAG_member_function		0x000e
65 #define	TAG_pointer_type		0x000f
66 #define	TAG_reference_type		0x0010
67 #define	TAG_source_file			0x0011
68 #define	TAG_string_type			0x0012
69 #define	TAG_structure_type		0x0013
70 #define	TAG_subroutine			0x0014
71 #define	TAG_subroutine_type		0x0015
72 #define	TAG_typedef			0x0016
73 #define	TAG_union_type			0x0017
74 #define	TAG_unspecified_parameters	0x0018
75 #define	TAG_variant			0x0019
76 
77 
78 /* attribute forms are encoded as part */
79 /* of the attribute name and must fit */
80 /* into 4 bits */
81 
82 #define	FORM_MASK	0xf
83 
84 #define	FORM_NONE	0x0	/* error */
85 #define	FORM_ADDR	0x1	/* relocated address */
86 #define	FORM_REF	0x2	/* reference to another .debug entry */
87 #define	FORM_BLOCK2	0x3	/* block with 2-byte length */
88 #define	FORM_BLOCK4	0x4	/* block with 4-byte length (unused) */
89 #define	FORM_DATA2	0x5	/* 2 bytes */
90 #define	FORM_DATA4	0x6	/* 4 bytes */
91 #define	FORM_DATA8	0x7	/* 8 bytes (two 4-byte values) */
92 #define	FORM_STRING	0x8	/* NUL-terminated string */
93 
94 
95 /* attribute names, halfwords with low 4 bits indicating the form */
96 
97 #define	AT_padding	 (0x0000|FORM_NONE)	/* just padding */
98 #define	AT_sibling	 (0x0010|FORM_REF)	/* next owned declaration */
99 #define	AT_location	 (0x0020|FORM_BLOCK2)	/* location description */
100 #define	AT_name		 (0x0030|FORM_STRING)	/* symbol name */
101 #define	AT_dimensions	 (0x0040|FORM_DATA2)	/* array dimensions */
102 #define	AT_fund_type	 (0x0050|FORM_DATA2)	/* fund type enum */
103 #define	AT_mod_fund_type (0x0060|FORM_BLOCK2)	/* modifiers & fund type enum */
104 #define	AT_user_def_type (0x0070|FORM_REF)	/* type entry */
105 #define	AT_mod_u_d_type  (0x0080|FORM_BLOCK2)	/* modifiers & type entry ref */
106 #define	AT_ordering	 (0x0090|FORM_DATA2)	/* array row/column major */
107 #define	AT_subscr_data	 (0x00a0|FORM_BLOCK2)	/* list of array dim info */
108 #define	AT_byte_size	 (0x00b0|FORM_DATA4)	/* number bytes per instance */
109 #define	AT_bit_offset	 (0x00c0|FORM_DATA2)	/* number bits padding */
110 #define	AT_bit_size	 (0x00d0|FORM_DATA4)	/* number bits per instance */
111 #define	AT_deriv_list	 (0x00e0|FORM_BLOCK2)	/* list of base class refs */
112 #define	AT_element_list	 (0x00f0|FORM_BLOCK4)	/* list of enum data elements */
113 #define	AT_stmt_list	 (0x0100|FORM_DATA4)	/* offset in .line sect */
114 #define	AT_low_pc	 (0x0110|FORM_ADDR)	/* first machine instr */
115 #define	AT_high_pc	 (0x0120|FORM_ADDR)	/* beyond last machine instr */
116 #define	AT_language	 (0x0130|FORM_DATA4)	/* compiler enumeration */
117 #define	AT_member	 (0x0140|FORM_REF)	/* class description */
118 #define	AT_discr	 (0x0150|FORM_REF)	/* discriminant entry */
119 #define	AT_discr_value	 (0x0160|FORM_BLOCK2)	/* value of discr */
120 #define	AT_visibility	 (0x0170|FORM_DATA2)	/* visibility enumeration */
121 #define	AT_import	 (0x0180|FORM_REF)	/* imported declaration */
122 #define	AT_string_length (0x0190|FORM_BLOCK2)	/* runtime string size */
123 
124 
125 /* atoms which compose a location description; must fit in a byte */
126 
127 #define	OP_UNK		0x00	/* error */
128 #define	OP_REG		0x01	/* push register (number) */
129 #define	OP_BASEREG	0x02	/* push value of register (number) */
130 #define	OP_ADDR		0x03	/* push address (relocated address) */
131 #define	OP_CONST	0x04	/* push constant (number) */
132 #define	OP_DEREF2	0x05	/* pop, deref and push 2 bytes (as a long) */
133 #define	OP_DEREF4	0x06	/* pop, deref and push 4 bytes (as a long) */
134 #define	OP_ADD		0x07	/* pop top 2 items, add, push result */
135 
136 /* fundamental types; must fit in two bytes */
137 
138 #define	FT_none			0x0000	/* error */
139 #define	FT_char			0x0001	/* "plain" char */
140 #define	FT_signed_char		0x0002
141 #define	FT_unsigned_char	0x0003
142 #define	FT_short		0x0004	/* "plain" short */
143 #define	FT_signed_short		0x0005
144 #define	FT_unsigned_short	0x0006
145 #define	FT_integer		0x0007	/* "plain" integer */
146 #define	FT_signed_integer	0x0008
147 #define	FT_unsigned_integer	0x0009
148 #define	FT_long			0x000a	/* "plain" long */
149 #define	FT_signed_long		0x000b
150 #define	FT_unsigned_long	0x000c
151 #define	FT_pointer		0x000d	/* (void *) */
152 #define	FT_float		0x000e
153 #define	FT_dbl_prec_float	0x000f
154 #define	FT_ext_prec_float	0x0010
155 #define	FT_complex		0x0011
156 #define	FT_dbl_prec_complex	0x0012
157 #define	FT_set			0x0013
158 #define	FT_void			0x0014
159 
160 
161 /* type modifiers; must fit in a byte */
162 
163 #define	MOD_none		0x00	/* error */
164 #define	MOD_pointer_to		0x01
165 #define	MOD_reference_to	0x02
166 
167 
168 /* the "format" byte for array descriptions; formed from three */
169 /* one-bit fields */
170 
171 #define	FMT_FT	0		/* fundamental type */
172 #define	FMT_UDT	1		/* user-defined type */
173 
174 #define	FMT_CONST	0	/* 4-byte constant */
175 #define	FMT_EXPR	1	/* block with 2-byte length (loc descr) */
176 
177 #define	FMT_FT_C_C	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_CONST))
178 #define	FMT_FT_C_X	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_EXPR))
179 #define	FMT_FT_X_C	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_CONST))
180 #define	FMT_FT_X_X	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_EXPR))
181 #define	FMT_UT_C_C	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_CONST))
182 #define	FMT_UT_C_X	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_EXPR))
183 #define	FMT_UT_X_C	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_CONST))
184 #define	FMT_UT_X_X	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_EXPR))
185 
186 #define	FMT_ET		8	/* element type */
187 
188 
189 /* ordering of arrays */
190 
191 #define	ORD_row_major	0
192 #define	ORD_col_major	1
193 
194 
195 /* visibility values */
196 
197 #define	VIS_local	0	/* for static functions in C */
198 #define	VIS_exported	1	/* for Modula */
199 
200 /*
201  * DWARF Exception Header Encoding
202  *
203  * The DWARF Exception Header Encoding is used to describe the type of data
204  * used in the .eh_frame_hdr section. The upper 4 bits indicate how the value
205  * is to be applied. The lower 4 bits indicate the format of the data.
206  */
207 
208 /*
209  * Dwarf Exception Header Value format
210  */
211 #define	DW_EH_PE_omit		0xff    /* No value is present. */
212 #define	DW_EH_PE_absptr		0x00    /* Value is a void* */
213 #define	DW_EH_PE_uleb128	0x01    /* Unsigned value is encoded using */
214 					/*   the Little Endian */
215 					/*   Base 128 (LEB128) */
216 #define	DW_EH_PE_udata2		0x02    /* A 2 bytes unsigned value. */
217 #define	DW_EH_PE_udata4		0x03    /* A 4 bytes unsigned value. */
218 #define	DW_EH_PE_udata8		0x04    /* An 8 bytes unsigned value. */
219 #define	DW_EH_PE_signed		0x08	/* bit on for all signed encodings */
220 #define	DW_EH_PE_sleb128	0x09	/* Signed value is encoded using */
221 					/*   the Little Endian */
222 					/*   Base 128 (LEB128) */
223 #define	DW_EH_PE_sdata2		0x0a	/* A 2 bytes signed value. */
224 #define	DW_EH_PE_sdata4		0x0b	/* A 4 bytes signed value. */
225 #define	DW_EH_PE_sdata8		0x0c	/* An 8 bytes signed value. */
226 
227 /*
228  * Dwarf Exception Header application
229  */
230 #define	DW_EH_PE_absptr		0x00	/* Value is used with no */
231 					/*  modification. */
232 #define	DW_EH_PE_pcrel		0x10	/* Value is reletive to the location */
233 					/*  of itself */
234 #define	DW_EH_PE_textrel	0x20
235 #define	DW_EH_PE_datarel	0x30	/* Value is reletive to the beginning */
236 					/*  of the eh_frame_hdr segment */
237 					/*  ( segment type PT_AMD64_UNWIND ) */
238 #define	DW_EH_PE_funcrel	0x40
239 #define	DW_EH_PE_aligned	0x50	/* value is an aligned void* */
240 #define	DW_EH_PE_indirect	0x80	/* bit to signal indirection after */
241 					/*  relocation */
242 
243 
244 /* language/compiler enumeration */
245 
246 typedef enum _LANG {
247 	LANG_UNK = 0,
248 	LANG_ANSI_C_V1 = 1
249 } LANG;
250 
251 /*
252  * Little Endian Base 128 (leb128) encoding/decoding routines
253  */
254 extern	uint64_t	uleb_extract(unsigned char *, uint64_t *);
255 extern	int64_t		sleb_extract(unsigned char *, uint64_t *);
256 extern	uint64_t	dwarf_ehe_extract(unsigned char *, uint64_t *,
257 				uint_t, unsigned char *, uint64_t);
258 
259 /*
260  * LSB32EXTRACT()
261  *
262  * Extract a LSB encoded int which may or may not be
263  * aligned on a 4 byte boundary.  This macro will work
264  * on either a MSB or LSB based system.
265  */
266 #define	LSB32EXTRACT(lsbptr)	((unsigned int)(\
267 				((unsigned const char *)(lsbptr))[0] + \
268 				(((unsigned const char *)(lsbptr))[1] << 8) + \
269 				(((unsigned const char *)(lsbptr))[2] << 16) + \
270 				(((unsigned const char *)(lsbptr))[3] << 24)))
271 
272 #ifdef	__cplusplus
273 }
274 #endif
275 
276 
277 #endif /* _DWARF_H */
278