1 /* $NetBSD: _libdwarf.h,v 1.1.1.1 2009/12/23 00:03:27 darran Exp $ */
4 * Copyright (c) 2007 John Birrell (jb@freebsd.org)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $FreeBSD: src/lib/libdwarf/_libdwarf.h,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
34 #include <sys/param.h>
35 #include <sys/queue.h>
41 #define DWARF_debug_abbrev 0
42 #define DWARF_debug_aranges 1
43 #define DWARF_debug_frame 2
44 #define DWARF_debug_info 3
45 #define DWARF_debug_line 4
46 #define DWARF_debug_pubnames 5
47 #define DWARF_eh_frame 6
48 #define DWARF_debug_macinfo 7
49 #define DWARF_debug_str 8
50 #define DWARF_debug_loc 9
51 #define DWARF_debug_pubtypes 10
52 #define DWARF_debug_ranges 11
53 #define DWARF_debug_static_func 12
54 #define DWARF_debug_static_vars 13
55 #define DWARF_debug_types 14
56 #define DWARF_debug_weaknames 15
57 #define DWARF_symtab 16
58 #define DWARF_strtab 17
59 #define DWARF_DEBUG_SNAMES 18
61 #define DWARF_DIE_HASH_SIZE 8191
63 #define DWARF_SET_ERROR(_e, _err) do { \
64 _e->err_error = _err; \
66 _e->err_func = __func__; \
67 _e->err_line = __LINE__; \
68 _e->err_msg[0] = '\0'; \
69 } while (/*CONSTCOND*/0)
71 #define DWARF_SET_ELF_ERROR(_e, _err) do { \
72 _e->err_error = DWARF_E_ELF; \
73 _e->elf_error = _err; \
74 _e->err_func = __func__; \
75 _e->err_line = __LINE__; \
76 _e->err_msg[0] = '\0'; \
77 } while (/*CONSTCOND*/0)
79 struct _Dwarf_AttrValue
{
80 uint64_t av_attrib
; /* DW_AT_ */
81 uint64_t av_form
; /* DW_FORM_ */
88 STAILQ_ENTRY(_Dwarf_AttrValue
)
89 av_next
; /* Next attribute value. */
93 int die_level
; /* Parent-child level. */
94 uint64_t die_offset
; /* DIE offset in section. */
95 uint64_t die_abnum
; /* Abbrev number. */
96 Dwarf_Abbrev die_a
; /* Abbrev pointer. */
97 Dwarf_CU die_cu
; /* Compilation unit pointer. */
98 const char *die_name
; /* Ptr to the name string. */
99 STAILQ_HEAD(, _Dwarf_AttrValue
)
100 die_attrval
; /* List of attribute values. */
101 STAILQ_ENTRY(_Dwarf_Die
)
102 die_next
; /* Next die in list. */
103 STAILQ_ENTRY(_Dwarf_Die
)
104 die_hash
; /* Next die in hash table. */
107 struct _Dwarf_Attribute
{
108 uint64_t at_attrib
; /* DW_AT_ */
109 uint64_t at_form
; /* DW_FORM_ */
110 STAILQ_ENTRY(_Dwarf_Attribute
)
111 at_next
; /* Next attribute. */
114 struct _Dwarf_Abbrev
{
115 uint64_t a_entry
; /* Abbrev entry. */
116 uint64_t a_tag
; /* Tag: DW_TAG_ */
117 uint8_t a_children
; /* DW_CHILDREN_no or DW_CHILDREN_yes */
118 STAILQ_HEAD(, _Dwarf_Attribute
)
119 a_attrib
; /* List of attributes. */
120 STAILQ_ENTRY(_Dwarf_Abbrev
)
121 a_next
; /* Next abbrev. */
125 uint64_t cu_offset
; /* Offset to the this compilation unit. */
126 uint32_t cu_length
; /* Length of CU data. */
127 uint32_t cu_header_length
;
128 /* Length of the CU header. */
129 uint16_t cu_version
; /* DWARF version. */
130 uint64_t cu_abbrev_offset
;
131 /* Offset into .debug_abbrev. */
132 uint8_t cu_pointer_size
;
133 /* Number of bytes in pointer. */
134 uint64_t cu_next_offset
;
135 /* Offset to the next compilation unit. */
136 STAILQ_HEAD(, _Dwarf_Abbrev
)
137 cu_abbrev
; /* List of abbrevs. */
138 STAILQ_HEAD(, _Dwarf_Die
)
139 cu_die
; /* List of dies. */
140 STAILQ_HEAD(, _Dwarf_Die
)
141 cu_die_hash
[DWARF_DIE_HASH_SIZE
];
143 STAILQ_ENTRY(_Dwarf_CU
)
144 cu_next
; /* Next compilation unit. */
147 typedef struct _Dwarf_section
{
148 Elf_Scn
*s_scn
; /* Section pointer. */
149 GElf_Shdr s_shdr
; /* Copy of the section header. */
150 char *s_sname
; /* Ptr to the section name. */
151 uint32_t s_shnum
; /* Section number. */
152 Elf_Data
*s_data
; /* Section data. */
155 struct _Dwarf_Debug
{
156 Elf
*dbg_elf
; /* Ptr to the ELF handle. */
157 GElf_Ehdr dbg_ehdr
; /* Copy of the ELF header. */
158 int dbg_elf_close
; /* True if elf_end() required. */
159 int dbg_mode
; /* Access mode. */
160 size_t dbg_stnum
; /* Section header string table section number. */
161 int dbg_offsize
; /* DWARF offset size. */
162 Dwarf_section dbg_s
[DWARF_DEBUG_SNAMES
];
163 /* Array of section information. */
164 STAILQ_HEAD(, _Dwarf_CU
)
165 dbg_cu
; /* List of compilation units. */
166 Dwarf_CU dbg_cu_current
;
167 /* Ptr to the current compilation unit. */
170 #endif /* !__LIBDWARF_H_ */