Commit | Line | Data |
---|---|---|
1b315056 | 1 | /* dwarf.h - DWARF support header file |
b3adc24a | 2 | Copyright (C) 2005-2020 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 | ||
467c65bc NC |
23 | typedef unsigned HOST_WIDEST_INT dwarf_vma; |
24 | typedef HOST_WIDEST_INT dwarf_signed_vma; | |
25 | typedef unsigned HOST_WIDEST_INT dwarf_size_type; | |
19e6b90e | 26 | |
47704ddf | 27 | /* Structure found in the .debug_line section. */ |
47704ddf KT |
28 | typedef struct |
29 | { | |
467c65bc | 30 | dwarf_vma li_length; |
47704ddf | 31 | unsigned short li_version; |
5496f3c6 NC |
32 | unsigned char li_address_size; |
33 | unsigned char li_segment_size; | |
77ef8654 | 34 | dwarf_vma li_prologue_length; |
47704ddf KT |
35 | unsigned char li_min_insn_length; |
36 | unsigned char li_max_ops_per_insn; | |
37 | unsigned char li_default_is_stmt; | |
38 | int li_line_base; | |
39 | unsigned char li_line_range; | |
40 | unsigned char li_opcode_base; | |
77145576 | 41 | unsigned int li_offset_size; |
47704ddf KT |
42 | } |
43 | DWARF2_Internal_LineInfo; | |
44 | ||
45 | /* Structure found in .debug_pubnames section. */ | |
47704ddf KT |
46 | typedef struct |
47 | { | |
467c65bc | 48 | dwarf_vma pn_length; |
47704ddf | 49 | unsigned short pn_version; |
467c65bc NC |
50 | dwarf_vma pn_offset; |
51 | dwarf_vma pn_size; | |
47704ddf KT |
52 | } |
53 | DWARF2_Internal_PubNames; | |
54 | ||
55 | /* Structure found in .debug_info section. */ | |
47704ddf KT |
56 | typedef struct |
57 | { | |
467c65bc | 58 | dwarf_vma cu_length; |
47704ddf | 59 | unsigned short cu_version; |
467c65bc | 60 | dwarf_vma cu_abbrev_offset; |
47704ddf | 61 | unsigned char cu_pointer_size; |
77145576 | 62 | enum dwarf_unit_type cu_unit_type; |
47704ddf KT |
63 | } |
64 | DWARF2_Internal_CompUnit; | |
65 | ||
77ef8654 | 66 | /* Structure found in .debug_aranges section. */ |
47704ddf KT |
67 | typedef struct |
68 | { | |
467c65bc | 69 | dwarf_vma ar_length; |
47704ddf | 70 | unsigned short ar_version; |
467c65bc | 71 | dwarf_vma ar_info_offset; |
47704ddf KT |
72 | unsigned char ar_pointer_size; |
73 | unsigned char ar_segment_size; | |
74 | } | |
75 | DWARF2_Internal_ARange; | |
76 | ||
459d52c8 DE |
77 | /* N.B. The order here must match the order in debug_displays. */ |
78 | ||
c34f4fc6 NC |
79 | enum dwarf_section_display_enum |
80 | { | |
19e6b90e L |
81 | abbrev = 0, |
82 | aranges, | |
83 | frame, | |
84 | info, | |
85 | line, | |
86 | pubnames, | |
459d52c8 | 87 | gnu_pubnames, |
19e6b90e L |
88 | eh_frame, |
89 | macinfo, | |
4ccf1e31 | 90 | macro, |
19e6b90e | 91 | str, |
77145576 | 92 | line_str, |
19e6b90e | 93 | loc, |
d4620bee | 94 | loclists, |
19e6b90e | 95 | pubtypes, |
459d52c8 | 96 | gnu_pubtypes, |
19e6b90e | 97 | ranges, |
d4620bee | 98 | rnglists, |
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, | |
123 | separate_debug_str, | |
19e6b90e L |
124 | max |
125 | }; | |
126 | ||
4723351a CC |
127 | struct dwarf_section |
128 | { | |
129 | /* A debug section has a different name when it's stored compressed | |
130 | or not. COMPRESSED_NAME and UNCOMPRESSED_NAME are the two | |
131 | possibilities. NAME is set to whichever one is used for this | |
132 | input file, as determined by load_debug_section(). */ | |
dda8d76d NC |
133 | const char * uncompressed_name; |
134 | const char * compressed_name; | |
135 | const char * name; | |
136 | /* If non-NULL then FILENAME is the name of the separate debug info | |
137 | file containing the section. */ | |
138 | const char * filename; | |
139 | unsigned char * start; | |
140 | dwarf_vma address; | |
141 | dwarf_size_type size; | |
142 | enum dwarf_section_display_enum abbrev_sec; | |
d1c4b12b | 143 | /* Used by clients to help them implement the reloc_at callback. */ |
dda8d76d NC |
144 | void * reloc_info; |
145 | unsigned long num_relocs; | |
06614111 | 146 | /* A spare field for random use. */ |
dda8d76d | 147 | void * user_data; |
4723351a CC |
148 | }; |
149 | ||
150 | /* A structure containing the name of a debug section | |
151 | and a pointer to a function that can decode it. */ | |
152 | struct dwarf_section_display | |
153 | { | |
dda8d76d NC |
154 | struct dwarf_section section; |
155 | int (* display) (struct dwarf_section *, void *); | |
156 | int * enabled; | |
157 | bfd_boolean relocate; | |
4723351a CC |
158 | }; |
159 | ||
19e6b90e L |
160 | extern struct dwarf_section_display debug_displays []; |
161 | ||
162 | /* This structure records the information that | |
163 | we extract from the.debug_info section. */ | |
164 | typedef struct | |
165 | { | |
166 | unsigned int pointer_size; | |
b7807392 JJ |
167 | unsigned int offset_size; |
168 | int dwarf_version; | |
467c65bc NC |
169 | dwarf_vma cu_offset; |
170 | dwarf_vma base_address; | |
4723351a CC |
171 | /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and |
172 | is used with the form DW_AT_GNU_FORM_addr_index. */ | |
173 | dwarf_vma addr_base; | |
174 | /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and | |
175 | is used when calculating ranges. */ | |
176 | dwarf_vma ranges_base; | |
19e6b90e | 177 | /* This is an array of offsets to the location list table. */ |
467c65bc | 178 | dwarf_vma * loc_offsets; |
9f272209 AO |
179 | /* This is an array of offsets to the location view table. */ |
180 | dwarf_vma * loc_views; | |
467c65bc | 181 | int * have_frame_base; |
19e6b90e L |
182 | unsigned int num_loc_offsets; |
183 | unsigned int max_loc_offsets; | |
9f272209 | 184 | unsigned int num_loc_views; |
01a8f077 | 185 | /* List of .debug_ranges offsets seen in this .debug_info. */ |
467c65bc | 186 | dwarf_vma * range_lists; |
19e6b90e L |
187 | unsigned int num_range_lists; |
188 | unsigned int max_range_lists; | |
189 | } | |
190 | debug_info; | |
191 | ||
24841daa NC |
192 | typedef struct separate_info |
193 | { | |
194 | void * handle; /* The pointer returned by open_debug_file(). */ | |
195 | const char * filename; | |
196 | struct separate_info * next; | |
197 | } separate_info; | |
198 | ||
199 | extern separate_info * first_separate_info; | |
200 | ||
77ef8654 | 201 | extern unsigned int eh_addr_size; |
19e6b90e L |
202 | |
203 | extern int do_debug_info; | |
204 | extern int do_debug_abbrevs; | |
205 | extern int do_debug_lines; | |
206 | extern int do_debug_pubnames; | |
f9f0e732 | 207 | extern int do_debug_pubtypes; |
19e6b90e L |
208 | extern int do_debug_aranges; |
209 | extern int do_debug_ranges; | |
210 | extern int do_debug_frames; | |
211 | extern int do_debug_frames_interp; | |
212 | extern int do_debug_macinfo; | |
213 | extern int do_debug_str; | |
214 | extern int do_debug_loc; | |
5bbdf3d5 | 215 | extern int do_gdb_index; |
6f875884 TG |
216 | extern int do_trace_info; |
217 | extern int do_trace_abbrevs; | |
218 | extern int do_trace_aranges; | |
657d0d47 CC |
219 | extern int do_debug_addr; |
220 | extern int do_debug_cu_index; | |
c34f4fc6 | 221 | extern int do_wide; |
dda8d76d | 222 | extern int do_debug_links; |
39f0547e | 223 | extern int do_follow_links; |
546cb2d8 | 224 | extern bfd_boolean do_checks; |
19e6b90e | 225 | |
fd2f0033 TT |
226 | extern int dwarf_cutoff_level; |
227 | extern unsigned long dwarf_start_die; | |
228 | ||
4723351a CC |
229 | extern int dwarf_check; |
230 | ||
955ff7fc | 231 | extern void init_dwarf_regnames_by_elf_machine_code (unsigned int); |
229a22cf AB |
232 | extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, |
233 | unsigned long mach); | |
2dc4cec1 | 234 | |
dda8d76d NC |
235 | extern bfd_boolean load_debug_section (enum dwarf_section_display_enum, void *); |
236 | extern void free_debug_section (enum dwarf_section_display_enum); | |
24841daa | 237 | extern bfd_boolean load_separate_debug_files (void *, const char *); |
dda8d76d NC |
238 | extern void close_debug_file (void *); |
239 | extern void * open_debug_file (const char *); | |
19e6b90e L |
240 | |
241 | extern void free_debug_memory (void); | |
242 | ||
c34f4fc6 NC |
243 | extern void dwarf_select_sections_by_names (const char *); |
244 | extern void dwarf_select_sections_by_letters (const char *); | |
4cb93e3b TG |
245 | extern void dwarf_select_sections_all (void); |
246 | ||
82b1b41b | 247 | extern unsigned int * find_cu_tu_set (void *, unsigned int); |
657d0d47 | 248 | |
82b1b41b | 249 | extern void * cmalloc (size_t, size_t); |
72c61a0d | 250 | extern void * xcalloc2 (size_t, size_t); |
82b1b41b NC |
251 | extern void * xcmalloc (size_t, size_t); |
252 | extern void * xcrealloc (void *, size_t, size_t); | |
19e6b90e | 253 | |
222c2bf0 | 254 | /* A callback into the client. Returns TRUE if there is a |
d1c4b12b NC |
255 | relocation against the given debug section at the given |
256 | offset. */ | |
257 | extern bfd_boolean reloc_at (struct dwarf_section *, dwarf_vma); | |
cd30bcef AM |
258 | |
259 | extern dwarf_vma read_leb128 (unsigned char *, const unsigned char *const, | |
260 | bfd_boolean, unsigned int *, int *); | |
261 | ||
301a9420 AM |
262 | #if HAVE_LIBDEBUGINFOD |
263 | extern unsigned char * get_build_id (void *); | |
264 | #endif | |
265 | ||
cd30bcef | 266 | static inline void |
1b513401 | 267 | report_leb_status (int status, const char *file, unsigned long lnum) |
cd30bcef AM |
268 | { |
269 | if ((status & 1) != 0) | |
1b513401 | 270 | error (_("%s:%lu: end of data encountered whilst reading LEB\n"), file, lnum); |
cd30bcef | 271 | else if ((status & 2) != 0) |
1b513401 | 272 | error (_("%s:%lu: read LEB value is too large to store in destination variable\n"), file, lnum); |
cd30bcef AM |
273 | } |
274 | ||
275 | #define SKIP_ULEB(start, end) \ | |
276 | do \ | |
277 | { \ | |
278 | unsigned int _len; \ | |
279 | read_leb128 (start, end, FALSE, &_len, NULL); \ | |
280 | start += _len; \ | |
1b513401 NC |
281 | } \ |
282 | while (0) | |
cd30bcef AM |
283 | |
284 | #define SKIP_SLEB(start, end) \ | |
285 | do \ | |
286 | { \ | |
287 | unsigned int _len; \ | |
288 | read_leb128 (start, end, TRUE, &_len, NULL); \ | |
289 | start += _len; \ | |
1b513401 NC |
290 | } \ |
291 | while (0) | |
cd30bcef AM |
292 | |
293 | #define READ_ULEB(var, start, end) \ | |
294 | do \ | |
295 | { \ | |
296 | dwarf_vma _val; \ | |
297 | unsigned int _len; \ | |
298 | int _status; \ | |
299 | \ | |
300 | _val = read_leb128 (start, end, FALSE, &_len, &_status); \ | |
301 | start += _len; \ | |
302 | (var) = _val; \ | |
303 | if ((var) != _val) \ | |
304 | _status |= 2; \ | |
1b513401 NC |
305 | report_leb_status (_status, __FILE__, __LINE__); \ |
306 | } \ | |
307 | while (0) | |
cd30bcef AM |
308 | |
309 | #define READ_SLEB(var, start, end) \ | |
310 | do \ | |
311 | { \ | |
312 | dwarf_signed_vma _val; \ | |
313 | unsigned int _len; \ | |
314 | int _status; \ | |
315 | \ | |
316 | _val = read_leb128 (start, end, TRUE, &_len, &_status); \ | |
317 | start += _len; \ | |
318 | (var) = _val; \ | |
319 | if ((var) != _val) \ | |
320 | _status |= 2; \ | |
1b513401 NC |
321 | report_leb_status (_status, __FILE__, __LINE__); \ |
322 | } \ | |
323 | while (0) |