]>
Commit | Line | Data |
---|---|---|
1b315056 | 1 | /* dwarf.h - DWARF support header file |
fd67aa11 | 2 | Copyright (C) 2005-2024 Free Software Foundation, Inc. |
19e6b90e | 3 | |
32866df7 | 4 | This file is part of GNU Binutils. |
19e6b90e | 5 | |
32866df7 NC |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3 of the License, or | |
9 | (at your option) any later version. | |
19e6b90e | 10 | |
32866df7 NC |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
19e6b90e | 15 | |
32866df7 NC |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
19 | MA 02110-1301, USA. */ | |
19e6b90e | 20 | |
77145576 JK |
21 | #include "dwarf2.h" /* for enum dwarf_unit_type */ |
22 | ||
47704ddf | 23 | /* Structure found in the .debug_line section. */ |
47704ddf KT |
24 | typedef struct |
25 | { | |
329dd2b6 AM |
26 | uint64_t li_length; |
27 | uint16_t li_version; | |
28 | uint8_t li_address_size; | |
29 | uint8_t li_segment_size; | |
30 | uint64_t li_prologue_length; | |
31 | uint8_t li_min_insn_length; | |
32 | uint8_t li_max_ops_per_insn; | |
33 | uint8_t li_default_is_stmt; | |
34 | int8_t li_line_base; | |
35 | uint8_t li_line_range; | |
36 | uint8_t li_opcode_base; | |
37 | /* Not part of the header. 4 for 32-bit dwarf, 8 for 64-bit. */ | |
38 | unsigned int li_offset_size; | |
47704ddf KT |
39 | } |
40 | DWARF2_Internal_LineInfo; | |
41 | ||
42 | /* Structure found in .debug_pubnames section. */ | |
47704ddf KT |
43 | typedef struct |
44 | { | |
31e5a3a3 | 45 | uint64_t pn_length; |
47704ddf | 46 | unsigned short pn_version; |
31e5a3a3 AM |
47 | uint64_t pn_offset; |
48 | uint64_t pn_size; | |
47704ddf KT |
49 | } |
50 | DWARF2_Internal_PubNames; | |
51 | ||
52 | /* Structure found in .debug_info section. */ | |
47704ddf KT |
53 | typedef struct |
54 | { | |
31e5a3a3 | 55 | uint64_t cu_length; |
47704ddf | 56 | unsigned short cu_version; |
31e5a3a3 | 57 | uint64_t cu_abbrev_offset; |
47704ddf | 58 | unsigned char cu_pointer_size; |
77145576 | 59 | enum dwarf_unit_type cu_unit_type; |
47704ddf KT |
60 | } |
61 | DWARF2_Internal_CompUnit; | |
62 | ||
77ef8654 | 63 | /* Structure found in .debug_aranges section. */ |
47704ddf KT |
64 | typedef struct |
65 | { | |
31e5a3a3 | 66 | uint64_t ar_length; |
47704ddf | 67 | unsigned short ar_version; |
31e5a3a3 | 68 | uint64_t ar_info_offset; |
47704ddf KT |
69 | unsigned char ar_pointer_size; |
70 | unsigned char ar_segment_size; | |
71 | } | |
72 | DWARF2_Internal_ARange; | |
73 | ||
459d52c8 DE |
74 | /* N.B. The order here must match the order in debug_displays. */ |
75 | ||
c34f4fc6 NC |
76 | enum dwarf_section_display_enum |
77 | { | |
19e6b90e L |
78 | abbrev = 0, |
79 | aranges, | |
80 | frame, | |
81 | info, | |
82 | line, | |
83 | pubnames, | |
459d52c8 | 84 | gnu_pubnames, |
19e6b90e | 85 | eh_frame, |
1878f44b | 86 | eh_frame_hdr, |
19e6b90e | 87 | macinfo, |
4ccf1e31 | 88 | macro, |
19e6b90e | 89 | str, |
77145576 | 90 | line_str, |
19e6b90e | 91 | loc, |
d4620bee | 92 | loclists, |
4694a0e5 | 93 | loclists_dwo, |
19e6b90e | 94 | pubtypes, |
459d52c8 | 95 | gnu_pubtypes, |
19e6b90e | 96 | ranges, |
d4620bee | 97 | rnglists, |
4694a0e5 | 98 | rnglists_dwo, |
19e6b90e L |
99 | static_func, |
100 | static_vars, | |
101 | types, | |
102 | weaknames, | |
48049d1e | 103 | gdb_index, |
61364358 | 104 | debug_names, |
6f875884 TG |
105 | trace_info, |
106 | trace_abbrev, | |
107 | trace_aranges, | |
4723351a CC |
108 | info_dwo, |
109 | abbrev_dwo, | |
110 | types_dwo, | |
111 | line_dwo, | |
112 | loc_dwo, | |
113 | macro_dwo, | |
114 | macinfo_dwo, | |
115 | str_dwo, | |
116 | str_index, | |
117 | str_index_dwo, | |
118 | debug_addr, | |
657d0d47 CC |
119 | dwp_cu_index, |
120 | dwp_tu_index, | |
dda8d76d NC |
121 | gnu_debuglink, |
122 | gnu_debugaltlink, | |
e38332c2 | 123 | debug_sup, |
dda8d76d | 124 | separate_debug_str, |
61ab1364 | 125 | note_gnu_build_id, |
19e6b90e L |
126 | max |
127 | }; | |
128 | ||
4723351a CC |
129 | struct dwarf_section |
130 | { | |
131 | /* A debug section has a different name when it's stored compressed | |
51d29b8c CC |
132 | or not. XCOFF DWARF section also have a special name. |
133 | COMPRESSED_NAME, UNCOMPRESSED_NAME and XCOFF_NAME are the three | |
4723351a CC |
134 | possibilities. NAME is set to whichever one is used for this |
135 | input file, as determined by load_debug_section(). */ | |
dda8d76d NC |
136 | const char * uncompressed_name; |
137 | const char * compressed_name; | |
51d29b8c | 138 | const char * xcoff_name; |
dda8d76d NC |
139 | const char * name; |
140 | /* If non-NULL then FILENAME is the name of the separate debug info | |
141 | file containing the section. */ | |
142 | const char * filename; | |
143 | unsigned char * start; | |
31e5a3a3 AM |
144 | uint64_t address; |
145 | uint64_t size; | |
dda8d76d | 146 | enum dwarf_section_display_enum abbrev_sec; |
d1c4b12b | 147 | /* Used by clients to help them implement the reloc_at callback. */ |
dda8d76d | 148 | void * reloc_info; |
26c527e6 | 149 | uint64_t num_relocs; |
4723351a CC |
150 | }; |
151 | ||
152 | /* A structure containing the name of a debug section | |
153 | and a pointer to a function that can decode it. */ | |
154 | struct dwarf_section_display | |
155 | { | |
015dc7e1 AM |
156 | struct dwarf_section section; |
157 | int (*display) (struct dwarf_section *, void *); | |
158 | int *enabled; | |
159 | bool relocate; | |
4723351a CC |
160 | }; |
161 | ||
19e6b90e L |
162 | extern struct dwarf_section_display debug_displays []; |
163 | ||
164 | /* This structure records the information that | |
165 | we extract from the.debug_info section. */ | |
166 | typedef struct | |
167 | { | |
168 | unsigned int pointer_size; | |
b7807392 JJ |
169 | unsigned int offset_size; |
170 | int dwarf_version; | |
31e5a3a3 AM |
171 | uint64_t cu_offset; |
172 | uint64_t base_address; | |
4723351a | 173 | /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and |
528a4f87 | 174 | is used with the form DW_FORM_GNU_addr_index. */ |
31e5a3a3 | 175 | uint64_t addr_base; |
4723351a CC |
176 | /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and |
177 | is used when calculating ranges. */ | |
31e5a3a3 | 178 | uint64_t ranges_base; |
19e6b90e | 179 | /* This is an array of offsets to the location list table. */ |
31e5a3a3 | 180 | uint64_t * loc_offsets; |
9f272209 | 181 | /* This is an array of offsets to the location view table. */ |
31e5a3a3 | 182 | uint64_t * loc_views; |
467c65bc | 183 | int * have_frame_base; |
19c26da6 NC |
184 | |
185 | /* Information for associating location lists with CUs. */ | |
19e6b90e L |
186 | unsigned int num_loc_offsets; |
187 | unsigned int max_loc_offsets; | |
9f272209 | 188 | unsigned int num_loc_views; |
31e5a3a3 | 189 | uint64_t loclists_base; |
19c26da6 | 190 | |
01a8f077 | 191 | /* List of .debug_ranges offsets seen in this .debug_info. */ |
31e5a3a3 | 192 | uint64_t * range_lists; |
19e6b90e L |
193 | unsigned int num_range_lists; |
194 | unsigned int max_range_lists; | |
31e5a3a3 AM |
195 | uint64_t rnglists_base; |
196 | uint64_t str_offsets_base; | |
19e6b90e L |
197 | } |
198 | debug_info; | |
199 | ||
24841daa NC |
200 | typedef struct separate_info |
201 | { | |
202 | void * handle; /* The pointer returned by open_debug_file(). */ | |
203 | const char * filename; | |
204 | struct separate_info * next; | |
205 | } separate_info; | |
206 | ||
207 | extern separate_info * first_separate_info; | |
208 | ||
77ef8654 | 209 | extern unsigned int eh_addr_size; |
19e6b90e L |
210 | |
211 | extern int do_debug_info; | |
212 | extern int do_debug_abbrevs; | |
213 | extern int do_debug_lines; | |
214 | extern int do_debug_pubnames; | |
f9f0e732 | 215 | extern int do_debug_pubtypes; |
19e6b90e L |
216 | extern int do_debug_aranges; |
217 | extern int do_debug_ranges; | |
218 | extern int do_debug_frames; | |
219 | extern int do_debug_frames_interp; | |
220 | extern int do_debug_macinfo; | |
221 | extern int do_debug_str; | |
e4b7104b | 222 | extern int do_debug_str_offsets; |
19e6b90e | 223 | extern int do_debug_loc; |
5bbdf3d5 | 224 | extern int do_gdb_index; |
6f875884 TG |
225 | extern int do_trace_info; |
226 | extern int do_trace_abbrevs; | |
227 | extern int do_trace_aranges; | |
657d0d47 CC |
228 | extern int do_debug_addr; |
229 | extern int do_debug_cu_index; | |
c34f4fc6 | 230 | extern int do_wide; |
dda8d76d | 231 | extern int do_debug_links; |
39f0547e | 232 | extern int do_follow_links; |
bed566bb NC |
233 | #ifdef HAVE_LIBDEBUGINFOD |
234 | extern int use_debuginfod; | |
235 | #endif | |
015dc7e1 | 236 | extern bool do_checks; |
19e6b90e | 237 | |
fd2f0033 TT |
238 | extern int dwarf_cutoff_level; |
239 | extern unsigned long dwarf_start_die; | |
240 | ||
4723351a CC |
241 | extern int dwarf_check; |
242 | ||
955ff7fc | 243 | extern void init_dwarf_regnames_by_elf_machine_code (unsigned int); |
229a22cf AB |
244 | extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, |
245 | unsigned long mach); | |
2dc4cec1 | 246 | |
015dc7e1 AM |
247 | extern bool load_debug_section (enum dwarf_section_display_enum, void *); |
248 | extern void free_debug_section (enum dwarf_section_display_enum); | |
249 | extern bool load_separate_debug_files (void *, const char *); | |
250 | extern void close_debug_file (void *); | |
251 | extern void *open_debug_file (const char *); | |
19e6b90e L |
252 | |
253 | extern void free_debug_memory (void); | |
254 | ||
94585d6d NC |
255 | extern int dwarf_select_sections_by_names (const char *); |
256 | extern int dwarf_select_sections_by_letters (const char *); | |
4cb93e3b TG |
257 | extern void dwarf_select_sections_all (void); |
258 | ||
82b1b41b | 259 | extern unsigned int * find_cu_tu_set (void *, unsigned int); |
657d0d47 | 260 | |
26c527e6 AM |
261 | extern void * cmalloc (uint64_t, size_t); |
262 | extern void * xcalloc2 (uint64_t, size_t); | |
263 | extern void * xcmalloc (uint64_t, size_t); | |
264 | extern void * xcrealloc (void *, uint64_t, size_t); | |
19e6b90e | 265 | |
222c2bf0 | 266 | /* A callback into the client. Returns TRUE if there is a |
d1c4b12b NC |
267 | relocation against the given debug section at the given |
268 | offset. */ | |
31e5a3a3 | 269 | extern bool reloc_at (struct dwarf_section *, uint64_t); |
cd30bcef | 270 | |
31e5a3a3 AM |
271 | extern uint64_t read_leb128 (unsigned char *, const unsigned char *const, |
272 | bool, unsigned int *, int *); | |
cd30bcef | 273 | |
301a9420 AM |
274 | #if HAVE_LIBDEBUGINFOD |
275 | extern unsigned char * get_build_id (void *); | |
276 | #endif | |
277 | ||
cd30bcef | 278 | static inline void |
9039747f | 279 | report_leb_status (int status) |
cd30bcef AM |
280 | { |
281 | if ((status & 1) != 0) | |
9039747f | 282 | error (_("end of data encountered whilst reading LEB\n")); |
cd30bcef | 283 | else if ((status & 2) != 0) |
9039747f | 284 | error (_("read LEB value is too large to store in destination variable\n")); |
cd30bcef AM |
285 | } |
286 | ||
287 | #define SKIP_ULEB(start, end) \ | |
288 | do \ | |
289 | { \ | |
290 | unsigned int _len; \ | |
015dc7e1 | 291 | read_leb128 (start, end, false, &_len, NULL); \ |
cd30bcef | 292 | start += _len; \ |
1b513401 NC |
293 | } \ |
294 | while (0) | |
cd30bcef AM |
295 | |
296 | #define SKIP_SLEB(start, end) \ | |
297 | do \ | |
298 | { \ | |
299 | unsigned int _len; \ | |
015dc7e1 | 300 | read_leb128 (start, end, true, &_len, NULL); \ |
cd30bcef | 301 | start += _len; \ |
1b513401 NC |
302 | } \ |
303 | while (0) | |
cd30bcef AM |
304 | |
305 | #define READ_ULEB(var, start, end) \ | |
306 | do \ | |
307 | { \ | |
31e5a3a3 | 308 | uint64_t _val; \ |
cd30bcef AM |
309 | unsigned int _len; \ |
310 | int _status; \ | |
311 | \ | |
015dc7e1 | 312 | _val = read_leb128 (start, end, false, &_len, &_status); \ |
cd30bcef AM |
313 | start += _len; \ |
314 | (var) = _val; \ | |
315 | if ((var) != _val) \ | |
316 | _status |= 2; \ | |
9039747f | 317 | report_leb_status (_status); \ |
1b513401 NC |
318 | } \ |
319 | while (0) | |
cd30bcef AM |
320 | |
321 | #define READ_SLEB(var, start, end) \ | |
322 | do \ | |
323 | { \ | |
31e5a3a3 | 324 | int64_t _val; \ |
cd30bcef AM |
325 | unsigned int _len; \ |
326 | int _status; \ | |
327 | \ | |
015dc7e1 | 328 | _val = read_leb128 (start, end, true, &_len, &_status); \ |
cd30bcef AM |
329 | start += _len; \ |
330 | (var) = _val; \ | |
331 | if ((var) != _val) \ | |
332 | _status |= 2; \ | |
9039747f | 333 | report_leb_status (_status); \ |
1b513401 NC |
334 | } \ |
335 | while (0) |