xref: /illumos-gate/usr/src/cmd/sgs/include/dwarf.h (revision 37915d86)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57e16fca0SAli Bahrami  * Common Development and Distribution License (the "License").
67e16fca0SAli Bahrami  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1989 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267e16fca0SAli Bahrami  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _DWARF_H
317c478bd9Sstevel@tonic-gate #define	_DWARF_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /* dwarf.h - manifest constants used in the .debug section of ELF files */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /* the "tag" - the first short of any legal record */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	TAG_padding			0x0000
487c478bd9Sstevel@tonic-gate #define	TAG_array_type			0x0001
497c478bd9Sstevel@tonic-gate #define	TAG_class_type			0x0002
507c478bd9Sstevel@tonic-gate #define	TAG_entry_point			0x0003
517c478bd9Sstevel@tonic-gate #define	TAG_enumeration_type		0x0004
527c478bd9Sstevel@tonic-gate #define	TAG_formal_parameter		0x0005
537c478bd9Sstevel@tonic-gate #define	TAG_global_subroutine		0x0006
547c478bd9Sstevel@tonic-gate #define	TAG_global_variable		0x0007
557c478bd9Sstevel@tonic-gate #define	TAG_imported_declaration	0x0008
567c478bd9Sstevel@tonic-gate #define	TAG_inline_subroutine		0x0009
577c478bd9Sstevel@tonic-gate #define	TAG_label			0x000a
587c478bd9Sstevel@tonic-gate #define	TAG_lexical_block		0x000b
597c478bd9Sstevel@tonic-gate #define	TAG_local_variable		0x000c
607c478bd9Sstevel@tonic-gate #define	TAG_member			0x000d
617c478bd9Sstevel@tonic-gate #define	TAG_member_function		0x000e
627c478bd9Sstevel@tonic-gate #define	TAG_pointer_type		0x000f
637c478bd9Sstevel@tonic-gate #define	TAG_reference_type		0x0010
647c478bd9Sstevel@tonic-gate #define	TAG_source_file			0x0011
657c478bd9Sstevel@tonic-gate #define	TAG_string_type			0x0012
667c478bd9Sstevel@tonic-gate #define	TAG_structure_type		0x0013
677c478bd9Sstevel@tonic-gate #define	TAG_subroutine			0x0014
687c478bd9Sstevel@tonic-gate #define	TAG_subroutine_type		0x0015
697c478bd9Sstevel@tonic-gate #define	TAG_typedef			0x0016
707c478bd9Sstevel@tonic-gate #define	TAG_union_type			0x0017
717c478bd9Sstevel@tonic-gate #define	TAG_unspecified_parameters	0x0018
727c478bd9Sstevel@tonic-gate #define	TAG_variant			0x0019
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /* attribute forms are encoded as part */
767c478bd9Sstevel@tonic-gate /* of the attribute name and must fit */
777c478bd9Sstevel@tonic-gate /* into 4 bits */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	FORM_MASK	0xf
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	FORM_NONE	0x0	/* error */
827c478bd9Sstevel@tonic-gate #define	FORM_ADDR	0x1	/* relocated address */
837c478bd9Sstevel@tonic-gate #define	FORM_REF	0x2	/* reference to another .debug entry */
847c478bd9Sstevel@tonic-gate #define	FORM_BLOCK2	0x3	/* block with 2-byte length */
857c478bd9Sstevel@tonic-gate #define	FORM_BLOCK4	0x4	/* block with 4-byte length (unused) */
867c478bd9Sstevel@tonic-gate #define	FORM_DATA2	0x5	/* 2 bytes */
877c478bd9Sstevel@tonic-gate #define	FORM_DATA4	0x6	/* 4 bytes */
887c478bd9Sstevel@tonic-gate #define	FORM_DATA8	0x7	/* 8 bytes (two 4-byte values) */
897c478bd9Sstevel@tonic-gate #define	FORM_STRING	0x8	/* NUL-terminated string */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /* attribute names, halfwords with low 4 bits indicating the form */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #define	AT_padding	 (0x0000|FORM_NONE)	/* just padding */
957c478bd9Sstevel@tonic-gate #define	AT_sibling	 (0x0010|FORM_REF)	/* next owned declaration */
967c478bd9Sstevel@tonic-gate #define	AT_location	 (0x0020|FORM_BLOCK2)	/* location description */
977c478bd9Sstevel@tonic-gate #define	AT_name		 (0x0030|FORM_STRING)	/* symbol name */
987c478bd9Sstevel@tonic-gate #define	AT_dimensions	 (0x0040|FORM_DATA2)	/* array dimensions */
997c478bd9Sstevel@tonic-gate #define	AT_fund_type	 (0x0050|FORM_DATA2)	/* fund type enum */
1007c478bd9Sstevel@tonic-gate #define	AT_mod_fund_type (0x0060|FORM_BLOCK2)	/* modifiers & fund type enum */
1017c478bd9Sstevel@tonic-gate #define	AT_user_def_type (0x0070|FORM_REF)	/* type entry */
1027c478bd9Sstevel@tonic-gate #define	AT_mod_u_d_type  (0x0080|FORM_BLOCK2)	/* modifiers & type entry ref */
1037c478bd9Sstevel@tonic-gate #define	AT_ordering	 (0x0090|FORM_DATA2)	/* array row/column major */
1047c478bd9Sstevel@tonic-gate #define	AT_subscr_data	 (0x00a0|FORM_BLOCK2)	/* list of array dim info */
1057c478bd9Sstevel@tonic-gate #define	AT_byte_size	 (0x00b0|FORM_DATA4)	/* number bytes per instance */
1067c478bd9Sstevel@tonic-gate #define	AT_bit_offset	 (0x00c0|FORM_DATA2)	/* number bits padding */
1077c478bd9Sstevel@tonic-gate #define	AT_bit_size	 (0x00d0|FORM_DATA4)	/* number bits per instance */
1087c478bd9Sstevel@tonic-gate #define	AT_deriv_list	 (0x00e0|FORM_BLOCK2)	/* list of base class refs */
1097c478bd9Sstevel@tonic-gate #define	AT_element_list	 (0x00f0|FORM_BLOCK4)	/* list of enum data elements */
1107c478bd9Sstevel@tonic-gate #define	AT_stmt_list	 (0x0100|FORM_DATA4)	/* offset in .line sect */
1117c478bd9Sstevel@tonic-gate #define	AT_low_pc	 (0x0110|FORM_ADDR)	/* first machine instr */
1127c478bd9Sstevel@tonic-gate #define	AT_high_pc	 (0x0120|FORM_ADDR)	/* beyond last machine instr */
1137c478bd9Sstevel@tonic-gate #define	AT_language	 (0x0130|FORM_DATA4)	/* compiler enumeration */
1147c478bd9Sstevel@tonic-gate #define	AT_member	 (0x0140|FORM_REF)	/* class description */
1157c478bd9Sstevel@tonic-gate #define	AT_discr	 (0x0150|FORM_REF)	/* discriminant entry */
1167c478bd9Sstevel@tonic-gate #define	AT_discr_value	 (0x0160|FORM_BLOCK2)	/* value of discr */
1177c478bd9Sstevel@tonic-gate #define	AT_visibility	 (0x0170|FORM_DATA2)	/* visibility enumeration */
1187c478bd9Sstevel@tonic-gate #define	AT_import	 (0x0180|FORM_REF)	/* imported declaration */
1197c478bd9Sstevel@tonic-gate #define	AT_string_length (0x0190|FORM_BLOCK2)	/* runtime string size */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /* atoms which compose a location description; must fit in a byte */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #define	OP_UNK		0x00	/* error */
1257c478bd9Sstevel@tonic-gate #define	OP_REG		0x01	/* push register (number) */
1267c478bd9Sstevel@tonic-gate #define	OP_BASEREG	0x02	/* push value of register (number) */
1277c478bd9Sstevel@tonic-gate #define	OP_ADDR		0x03	/* push address (relocated address) */
1287c478bd9Sstevel@tonic-gate #define	OP_CONST	0x04	/* push constant (number) */
1297c478bd9Sstevel@tonic-gate #define	OP_DEREF2	0x05	/* pop, deref and push 2 bytes (as a long) */
1307c478bd9Sstevel@tonic-gate #define	OP_DEREF4	0x06	/* pop, deref and push 4 bytes (as a long) */
1317c478bd9Sstevel@tonic-gate #define	OP_ADD		0x07	/* pop top 2 items, add, push result */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /* fundamental types; must fit in two bytes */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #define	FT_none			0x0000	/* error */
1367c478bd9Sstevel@tonic-gate #define	FT_char			0x0001	/* "plain" char */
1377c478bd9Sstevel@tonic-gate #define	FT_signed_char		0x0002
1387c478bd9Sstevel@tonic-gate #define	FT_unsigned_char	0x0003
1397c478bd9Sstevel@tonic-gate #define	FT_short		0x0004	/* "plain" short */
1407c478bd9Sstevel@tonic-gate #define	FT_signed_short		0x0005
1417c478bd9Sstevel@tonic-gate #define	FT_unsigned_short	0x0006
1427c478bd9Sstevel@tonic-gate #define	FT_integer		0x0007	/* "plain" integer */
1437c478bd9Sstevel@tonic-gate #define	FT_signed_integer	0x0008
1447c478bd9Sstevel@tonic-gate #define	FT_unsigned_integer	0x0009
1457c478bd9Sstevel@tonic-gate #define	FT_long			0x000a	/* "plain" long */
1467c478bd9Sstevel@tonic-gate #define	FT_signed_long		0x000b
1477c478bd9Sstevel@tonic-gate #define	FT_unsigned_long	0x000c
1487c478bd9Sstevel@tonic-gate #define	FT_pointer		0x000d	/* (void *) */
1497c478bd9Sstevel@tonic-gate #define	FT_float		0x000e
1507c478bd9Sstevel@tonic-gate #define	FT_dbl_prec_float	0x000f
1517c478bd9Sstevel@tonic-gate #define	FT_ext_prec_float	0x0010
1527c478bd9Sstevel@tonic-gate #define	FT_complex		0x0011
1537c478bd9Sstevel@tonic-gate #define	FT_dbl_prec_complex	0x0012
1547c478bd9Sstevel@tonic-gate #define	FT_set			0x0013
1557c478bd9Sstevel@tonic-gate #define	FT_void			0x0014
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /* type modifiers; must fit in a byte */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define	MOD_none		0x00	/* error */
1617c478bd9Sstevel@tonic-gate #define	MOD_pointer_to		0x01
1627c478bd9Sstevel@tonic-gate #define	MOD_reference_to	0x02
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /* the "format" byte for array descriptions; formed from three */
1667c478bd9Sstevel@tonic-gate /* one-bit fields */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #define	FMT_FT	0		/* fundamental type */
1697c478bd9Sstevel@tonic-gate #define	FMT_UDT	1		/* user-defined type */
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #define	FMT_CONST	0	/* 4-byte constant */
1727c478bd9Sstevel@tonic-gate #define	FMT_EXPR	1	/* block with 2-byte length (loc descr) */
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #define	FMT_FT_C_C	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_CONST))
1757c478bd9Sstevel@tonic-gate #define	FMT_FT_C_X	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_EXPR))
1767c478bd9Sstevel@tonic-gate #define	FMT_FT_X_C	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_CONST))
1777c478bd9Sstevel@tonic-gate #define	FMT_FT_X_X	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_EXPR))
1787c478bd9Sstevel@tonic-gate #define	FMT_UT_C_C	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_CONST))
1797c478bd9Sstevel@tonic-gate #define	FMT_UT_C_X	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_EXPR))
1807c478bd9Sstevel@tonic-gate #define	FMT_UT_X_C	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_CONST))
1817c478bd9Sstevel@tonic-gate #define	FMT_UT_X_X	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_EXPR))
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate #define	FMT_ET		8	/* element type */
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /* ordering of arrays */
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate #define	ORD_row_major	0
1897c478bd9Sstevel@tonic-gate #define	ORD_col_major	1
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate /* visibility values */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #define	VIS_local	0	/* for static functions in C */
1957c478bd9Sstevel@tonic-gate #define	VIS_exported	1	/* for Modula */
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * DWARF Exception Header Encoding
1997c478bd9Sstevel@tonic-gate  *
2007c478bd9Sstevel@tonic-gate  * The DWARF Exception Header Encoding is used to describe the type of data
2017c478bd9Sstevel@tonic-gate  * used in the .eh_frame_hdr section. The upper 4 bits indicate how the value
2027c478bd9Sstevel@tonic-gate  * is to be applied. The lower 4 bits indicate the format of the data.
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate  * Dwarf Exception Header Value format
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate #define	DW_EH_PE_omit		0xff    /* No value is present. */
2097c478bd9Sstevel@tonic-gate #define	DW_EH_PE_absptr		0x00    /* Value is a void* */
2107c478bd9Sstevel@tonic-gate #define	DW_EH_PE_uleb128	0x01    /* Unsigned value is encoded using */
2117c478bd9Sstevel@tonic-gate 					/*   the Little Endian */
2127c478bd9Sstevel@tonic-gate 					/*   Base 128 (LEB128) */
2137c478bd9Sstevel@tonic-gate #define	DW_EH_PE_udata2		0x02    /* A 2 bytes unsigned value. */
2147c478bd9Sstevel@tonic-gate #define	DW_EH_PE_udata4		0x03    /* A 4 bytes unsigned value. */
2157c478bd9Sstevel@tonic-gate #define	DW_EH_PE_udata8		0x04    /* An 8 bytes unsigned value. */
2167c478bd9Sstevel@tonic-gate #define	DW_EH_PE_signed		0x08	/* bit on for all signed encodings */
2177c478bd9Sstevel@tonic-gate #define	DW_EH_PE_sleb128	0x09	/* Signed value is encoded using */
2187c478bd9Sstevel@tonic-gate 					/*   the Little Endian */
2197c478bd9Sstevel@tonic-gate 					/*   Base 128 (LEB128) */
2207c478bd9Sstevel@tonic-gate #define	DW_EH_PE_sdata2		0x0a	/* A 2 bytes signed value. */
2217c478bd9Sstevel@tonic-gate #define	DW_EH_PE_sdata4		0x0b	/* A 4 bytes signed value. */
2227c478bd9Sstevel@tonic-gate #define	DW_EH_PE_sdata8		0x0c	/* An 8 bytes signed value. */
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * Dwarf Exception Header application
2267c478bd9Sstevel@tonic-gate  */
2277c478bd9Sstevel@tonic-gate #define	DW_EH_PE_absptr		0x00	/* Value is used with no */
2287c478bd9Sstevel@tonic-gate 					/*  modification. */
2297c478bd9Sstevel@tonic-gate #define	DW_EH_PE_pcrel		0x10	/* Value is reletive to the location */
2307c478bd9Sstevel@tonic-gate 					/*  of itself */
2317c478bd9Sstevel@tonic-gate #define	DW_EH_PE_textrel	0x20
2327c478bd9Sstevel@tonic-gate #define	DW_EH_PE_datarel	0x30	/* Value is reletive to the beginning */
2337c478bd9Sstevel@tonic-gate 					/*  of the eh_frame_hdr segment */
2347c478bd9Sstevel@tonic-gate 					/*  ( segment type PT_AMD64_UNWIND ) */
235965630c1SRichard Lowe 					/*  when within that segment, or to */
236965630c1SRichard Lowe 					/*  the GOT when without. */
2377c478bd9Sstevel@tonic-gate #define	DW_EH_PE_funcrel	0x40
2387c478bd9Sstevel@tonic-gate #define	DW_EH_PE_aligned	0x50	/* value is an aligned void* */
2397c478bd9Sstevel@tonic-gate #define	DW_EH_PE_indirect	0x80	/* bit to signal indirection after */
2407c478bd9Sstevel@tonic-gate 					/*  relocation */
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /* language/compiler enumeration */
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate typedef enum _LANG {
2467c478bd9Sstevel@tonic-gate 	LANG_UNK = 0,
2477c478bd9Sstevel@tonic-gate 	LANG_ANSI_C_V1 = 1
2487c478bd9Sstevel@tonic-gate } LANG;
2497c478bd9Sstevel@tonic-gate 
250*37915d86SRichard Lowe typedef enum {
251*37915d86SRichard Lowe 	DW_SUCCESS = 0,
252*37915d86SRichard Lowe 	DW_BAD_ENCODING,
253*37915d86SRichard Lowe 	DW_OVERFLOW,
254*37915d86SRichard Lowe } dwarf_error_t;
255*37915d86SRichard Lowe 
2567c478bd9Sstevel@tonic-gate /*
2577c478bd9Sstevel@tonic-gate  * Little Endian Base 128 (leb128) encoding/decoding routines
2587c478bd9Sstevel@tonic-gate  */
259*37915d86SRichard Lowe extern	dwarf_error_t	uleb_extract(unsigned char *, uint64_t *, size_t,
260*37915d86SRichard Lowe 			    uint64_t *);
261*37915d86SRichard Lowe extern	dwarf_error_t	sleb_extract(unsigned char *, uint64_t *, size_t,
262*37915d86SRichard Lowe 			    int64_t *);
263*37915d86SRichard Lowe extern	dwarf_error_t	dwarf_ehe_extract(unsigned char *, size_t, uint64_t *,
264*37915d86SRichard Lowe 			    uint64_t *, uint_t, unsigned char *, boolean_t,
265*37915d86SRichard Lowe 			    uint64_t, uint64_t, uint64_t);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate #endif
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate #endif /* _DWARF_H */
273