xref: /onnv-gate/usr/src/cmd/sgs/include/dwarf.h (revision 9085:ff7eb0bace56)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*9085SAli.Bahrami@Sun.COM  * Common Development and Distribution License (the "License").
6*9085SAli.Bahrami@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*	Copyright (c) 1989 AT&T	*/
220Sstevel@tonic-gate /*	  All Rights Reserved  	*/
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
26*9085SAli.Bahrami@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
270Sstevel@tonic-gate  * Use is subject to license terms.
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifndef _DWARF_H
310Sstevel@tonic-gate #define	_DWARF_H
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /* dwarf.h - manifest constants used in the .debug section of ELF files */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /* the "tag" - the first short of any legal record */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #define	TAG_padding			0x0000
480Sstevel@tonic-gate #define	TAG_array_type			0x0001
490Sstevel@tonic-gate #define	TAG_class_type			0x0002
500Sstevel@tonic-gate #define	TAG_entry_point			0x0003
510Sstevel@tonic-gate #define	TAG_enumeration_type		0x0004
520Sstevel@tonic-gate #define	TAG_formal_parameter		0x0005
530Sstevel@tonic-gate #define	TAG_global_subroutine		0x0006
540Sstevel@tonic-gate #define	TAG_global_variable		0x0007
550Sstevel@tonic-gate #define	TAG_imported_declaration	0x0008
560Sstevel@tonic-gate #define	TAG_inline_subroutine		0x0009
570Sstevel@tonic-gate #define	TAG_label			0x000a
580Sstevel@tonic-gate #define	TAG_lexical_block		0x000b
590Sstevel@tonic-gate #define	TAG_local_variable		0x000c
600Sstevel@tonic-gate #define	TAG_member			0x000d
610Sstevel@tonic-gate #define	TAG_member_function		0x000e
620Sstevel@tonic-gate #define	TAG_pointer_type		0x000f
630Sstevel@tonic-gate #define	TAG_reference_type		0x0010
640Sstevel@tonic-gate #define	TAG_source_file			0x0011
650Sstevel@tonic-gate #define	TAG_string_type			0x0012
660Sstevel@tonic-gate #define	TAG_structure_type		0x0013
670Sstevel@tonic-gate #define	TAG_subroutine			0x0014
680Sstevel@tonic-gate #define	TAG_subroutine_type		0x0015
690Sstevel@tonic-gate #define	TAG_typedef			0x0016
700Sstevel@tonic-gate #define	TAG_union_type			0x0017
710Sstevel@tonic-gate #define	TAG_unspecified_parameters	0x0018
720Sstevel@tonic-gate #define	TAG_variant			0x0019
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /* attribute forms are encoded as part */
760Sstevel@tonic-gate /* of the attribute name and must fit */
770Sstevel@tonic-gate /* into 4 bits */
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	FORM_MASK	0xf
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #define	FORM_NONE	0x0	/* error */
820Sstevel@tonic-gate #define	FORM_ADDR	0x1	/* relocated address */
830Sstevel@tonic-gate #define	FORM_REF	0x2	/* reference to another .debug entry */
840Sstevel@tonic-gate #define	FORM_BLOCK2	0x3	/* block with 2-byte length */
850Sstevel@tonic-gate #define	FORM_BLOCK4	0x4	/* block with 4-byte length (unused) */
860Sstevel@tonic-gate #define	FORM_DATA2	0x5	/* 2 bytes */
870Sstevel@tonic-gate #define	FORM_DATA4	0x6	/* 4 bytes */
880Sstevel@tonic-gate #define	FORM_DATA8	0x7	/* 8 bytes (two 4-byte values) */
890Sstevel@tonic-gate #define	FORM_STRING	0x8	/* NUL-terminated string */
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 
920Sstevel@tonic-gate /* attribute names, halfwords with low 4 bits indicating the form */
930Sstevel@tonic-gate 
940Sstevel@tonic-gate #define	AT_padding	 (0x0000|FORM_NONE)	/* just padding */
950Sstevel@tonic-gate #define	AT_sibling	 (0x0010|FORM_REF)	/* next owned declaration */
960Sstevel@tonic-gate #define	AT_location	 (0x0020|FORM_BLOCK2)	/* location description */
970Sstevel@tonic-gate #define	AT_name		 (0x0030|FORM_STRING)	/* symbol name */
980Sstevel@tonic-gate #define	AT_dimensions	 (0x0040|FORM_DATA2)	/* array dimensions */
990Sstevel@tonic-gate #define	AT_fund_type	 (0x0050|FORM_DATA2)	/* fund type enum */
1000Sstevel@tonic-gate #define	AT_mod_fund_type (0x0060|FORM_BLOCK2)	/* modifiers & fund type enum */
1010Sstevel@tonic-gate #define	AT_user_def_type (0x0070|FORM_REF)	/* type entry */
1020Sstevel@tonic-gate #define	AT_mod_u_d_type  (0x0080|FORM_BLOCK2)	/* modifiers & type entry ref */
1030Sstevel@tonic-gate #define	AT_ordering	 (0x0090|FORM_DATA2)	/* array row/column major */
1040Sstevel@tonic-gate #define	AT_subscr_data	 (0x00a0|FORM_BLOCK2)	/* list of array dim info */
1050Sstevel@tonic-gate #define	AT_byte_size	 (0x00b0|FORM_DATA4)	/* number bytes per instance */
1060Sstevel@tonic-gate #define	AT_bit_offset	 (0x00c0|FORM_DATA2)	/* number bits padding */
1070Sstevel@tonic-gate #define	AT_bit_size	 (0x00d0|FORM_DATA4)	/* number bits per instance */
1080Sstevel@tonic-gate #define	AT_deriv_list	 (0x00e0|FORM_BLOCK2)	/* list of base class refs */
1090Sstevel@tonic-gate #define	AT_element_list	 (0x00f0|FORM_BLOCK4)	/* list of enum data elements */
1100Sstevel@tonic-gate #define	AT_stmt_list	 (0x0100|FORM_DATA4)	/* offset in .line sect */
1110Sstevel@tonic-gate #define	AT_low_pc	 (0x0110|FORM_ADDR)	/* first machine instr */
1120Sstevel@tonic-gate #define	AT_high_pc	 (0x0120|FORM_ADDR)	/* beyond last machine instr */
1130Sstevel@tonic-gate #define	AT_language	 (0x0130|FORM_DATA4)	/* compiler enumeration */
1140Sstevel@tonic-gate #define	AT_member	 (0x0140|FORM_REF)	/* class description */
1150Sstevel@tonic-gate #define	AT_discr	 (0x0150|FORM_REF)	/* discriminant entry */
1160Sstevel@tonic-gate #define	AT_discr_value	 (0x0160|FORM_BLOCK2)	/* value of discr */
1170Sstevel@tonic-gate #define	AT_visibility	 (0x0170|FORM_DATA2)	/* visibility enumeration */
1180Sstevel@tonic-gate #define	AT_import	 (0x0180|FORM_REF)	/* imported declaration */
1190Sstevel@tonic-gate #define	AT_string_length (0x0190|FORM_BLOCK2)	/* runtime string size */
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate /* atoms which compose a location description; must fit in a byte */
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #define	OP_UNK		0x00	/* error */
1250Sstevel@tonic-gate #define	OP_REG		0x01	/* push register (number) */
1260Sstevel@tonic-gate #define	OP_BASEREG	0x02	/* push value of register (number) */
1270Sstevel@tonic-gate #define	OP_ADDR		0x03	/* push address (relocated address) */
1280Sstevel@tonic-gate #define	OP_CONST	0x04	/* push constant (number) */
1290Sstevel@tonic-gate #define	OP_DEREF2	0x05	/* pop, deref and push 2 bytes (as a long) */
1300Sstevel@tonic-gate #define	OP_DEREF4	0x06	/* pop, deref and push 4 bytes (as a long) */
1310Sstevel@tonic-gate #define	OP_ADD		0x07	/* pop top 2 items, add, push result */
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate /* fundamental types; must fit in two bytes */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #define	FT_none			0x0000	/* error */
1360Sstevel@tonic-gate #define	FT_char			0x0001	/* "plain" char */
1370Sstevel@tonic-gate #define	FT_signed_char		0x0002
1380Sstevel@tonic-gate #define	FT_unsigned_char	0x0003
1390Sstevel@tonic-gate #define	FT_short		0x0004	/* "plain" short */
1400Sstevel@tonic-gate #define	FT_signed_short		0x0005
1410Sstevel@tonic-gate #define	FT_unsigned_short	0x0006
1420Sstevel@tonic-gate #define	FT_integer		0x0007	/* "plain" integer */
1430Sstevel@tonic-gate #define	FT_signed_integer	0x0008
1440Sstevel@tonic-gate #define	FT_unsigned_integer	0x0009
1450Sstevel@tonic-gate #define	FT_long			0x000a	/* "plain" long */
1460Sstevel@tonic-gate #define	FT_signed_long		0x000b
1470Sstevel@tonic-gate #define	FT_unsigned_long	0x000c
1480Sstevel@tonic-gate #define	FT_pointer		0x000d	/* (void *) */
1490Sstevel@tonic-gate #define	FT_float		0x000e
1500Sstevel@tonic-gate #define	FT_dbl_prec_float	0x000f
1510Sstevel@tonic-gate #define	FT_ext_prec_float	0x0010
1520Sstevel@tonic-gate #define	FT_complex		0x0011
1530Sstevel@tonic-gate #define	FT_dbl_prec_complex	0x0012
1540Sstevel@tonic-gate #define	FT_set			0x0013
1550Sstevel@tonic-gate #define	FT_void			0x0014
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /* type modifiers; must fit in a byte */
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate #define	MOD_none		0x00	/* error */
1610Sstevel@tonic-gate #define	MOD_pointer_to		0x01
1620Sstevel@tonic-gate #define	MOD_reference_to	0x02
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate /* the "format" byte for array descriptions; formed from three */
1660Sstevel@tonic-gate /* one-bit fields */
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	FMT_FT	0		/* fundamental type */
1690Sstevel@tonic-gate #define	FMT_UDT	1		/* user-defined type */
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate #define	FMT_CONST	0	/* 4-byte constant */
1720Sstevel@tonic-gate #define	FMT_EXPR	1	/* block with 2-byte length (loc descr) */
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #define	FMT_FT_C_C	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_CONST))
1750Sstevel@tonic-gate #define	FMT_FT_C_X	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_EXPR))
1760Sstevel@tonic-gate #define	FMT_FT_X_C	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_CONST))
1770Sstevel@tonic-gate #define	FMT_FT_X_X	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_EXPR))
1780Sstevel@tonic-gate #define	FMT_UT_C_C	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_CONST))
1790Sstevel@tonic-gate #define	FMT_UT_C_X	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_EXPR))
1800Sstevel@tonic-gate #define	FMT_UT_X_C	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_CONST))
1810Sstevel@tonic-gate #define	FMT_UT_X_X	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_EXPR))
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate #define	FMT_ET		8	/* element type */
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate /* ordering of arrays */
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate #define	ORD_row_major	0
1890Sstevel@tonic-gate #define	ORD_col_major	1
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate /* visibility values */
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate #define	VIS_local	0	/* for static functions in C */
1950Sstevel@tonic-gate #define	VIS_exported	1	/* for Modula */
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate /*
1980Sstevel@tonic-gate  * DWARF Exception Header Encoding
1990Sstevel@tonic-gate  *
2000Sstevel@tonic-gate  * The DWARF Exception Header Encoding is used to describe the type of data
2010Sstevel@tonic-gate  * used in the .eh_frame_hdr section. The upper 4 bits indicate how the value
2020Sstevel@tonic-gate  * is to be applied. The lower 4 bits indicate the format of the data.
2030Sstevel@tonic-gate  */
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate /*
2060Sstevel@tonic-gate  * Dwarf Exception Header Value format
2070Sstevel@tonic-gate  */
2080Sstevel@tonic-gate #define	DW_EH_PE_omit		0xff    /* No value is present. */
2090Sstevel@tonic-gate #define	DW_EH_PE_absptr		0x00    /* Value is a void* */
2100Sstevel@tonic-gate #define	DW_EH_PE_uleb128	0x01    /* Unsigned value is encoded using */
2110Sstevel@tonic-gate 					/*   the Little Endian */
2120Sstevel@tonic-gate 					/*   Base 128 (LEB128) */
2130Sstevel@tonic-gate #define	DW_EH_PE_udata2		0x02    /* A 2 bytes unsigned value. */
2140Sstevel@tonic-gate #define	DW_EH_PE_udata4		0x03    /* A 4 bytes unsigned value. */
2150Sstevel@tonic-gate #define	DW_EH_PE_udata8		0x04    /* An 8 bytes unsigned value. */
2160Sstevel@tonic-gate #define	DW_EH_PE_signed		0x08	/* bit on for all signed encodings */
2170Sstevel@tonic-gate #define	DW_EH_PE_sleb128	0x09	/* Signed value is encoded using */
2180Sstevel@tonic-gate 					/*   the Little Endian */
2190Sstevel@tonic-gate 					/*   Base 128 (LEB128) */
2200Sstevel@tonic-gate #define	DW_EH_PE_sdata2		0x0a	/* A 2 bytes signed value. */
2210Sstevel@tonic-gate #define	DW_EH_PE_sdata4		0x0b	/* A 4 bytes signed value. */
2220Sstevel@tonic-gate #define	DW_EH_PE_sdata8		0x0c	/* An 8 bytes signed value. */
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate /*
2250Sstevel@tonic-gate  * Dwarf Exception Header application
2260Sstevel@tonic-gate  */
2270Sstevel@tonic-gate #define	DW_EH_PE_absptr		0x00	/* Value is used with no */
2280Sstevel@tonic-gate 					/*  modification. */
2290Sstevel@tonic-gate #define	DW_EH_PE_pcrel		0x10	/* Value is reletive to the location */
2300Sstevel@tonic-gate 					/*  of itself */
2310Sstevel@tonic-gate #define	DW_EH_PE_textrel	0x20
2320Sstevel@tonic-gate #define	DW_EH_PE_datarel	0x30	/* Value is reletive to the beginning */
2330Sstevel@tonic-gate 					/*  of the eh_frame_hdr segment */
2340Sstevel@tonic-gate 					/*  ( segment type PT_AMD64_UNWIND ) */
2350Sstevel@tonic-gate #define	DW_EH_PE_funcrel	0x40
2360Sstevel@tonic-gate #define	DW_EH_PE_aligned	0x50	/* value is an aligned void* */
2370Sstevel@tonic-gate #define	DW_EH_PE_indirect	0x80	/* bit to signal indirection after */
2380Sstevel@tonic-gate 					/*  relocation */
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate /* language/compiler enumeration */
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate typedef enum _LANG {
2440Sstevel@tonic-gate 	LANG_UNK = 0,
2450Sstevel@tonic-gate 	LANG_ANSI_C_V1 = 1
2460Sstevel@tonic-gate } LANG;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate /*
2490Sstevel@tonic-gate  * Little Endian Base 128 (leb128) encoding/decoding routines
2500Sstevel@tonic-gate  */
2510Sstevel@tonic-gate extern	uint64_t	uleb_extract(unsigned char *, uint64_t *);
2520Sstevel@tonic-gate extern	int64_t		sleb_extract(unsigned char *, uint64_t *);
2530Sstevel@tonic-gate extern	uint64_t	dwarf_ehe_extract(unsigned char *, uint64_t *,
254*9085SAli.Bahrami@Sun.COM 			    uint_t, unsigned char *, uint64_t, uint64_t);
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate #ifdef	__cplusplus
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate #endif
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate #endif /* _DWARF_H */
262