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