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