gdbtypes.c: Add the case for FIELD_LOC_KIND_DWARF_BLOCK
[binutils-gdb.git] / binutils / dwarf.h
1 /* dwarf.h - DWARF support header file
2 Copyright (C) 2005-2021 Free Software Foundation, Inc.
3
4 This file is part of GNU Binutils.
5
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.
10
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.
15
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. */
20
21 #include "dwarf2.h" /* for enum dwarf_unit_type */
22
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;
26
27 /* Structure found in the .debug_line section. */
28 typedef struct
29 {
30 dwarf_vma li_length;
31 unsigned short li_version;
32 unsigned char li_address_size;
33 unsigned char li_segment_size;
34 dwarf_vma li_prologue_length;
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;
41 unsigned int li_offset_size;
42 }
43 DWARF2_Internal_LineInfo;
44
45 /* Structure found in .debug_pubnames section. */
46 typedef struct
47 {
48 dwarf_vma pn_length;
49 unsigned short pn_version;
50 dwarf_vma pn_offset;
51 dwarf_vma pn_size;
52 }
53 DWARF2_Internal_PubNames;
54
55 /* Structure found in .debug_info section. */
56 typedef struct
57 {
58 dwarf_vma cu_length;
59 unsigned short cu_version;
60 dwarf_vma cu_abbrev_offset;
61 unsigned char cu_pointer_size;
62 enum dwarf_unit_type cu_unit_type;
63 }
64 DWARF2_Internal_CompUnit;
65
66 /* Structure found in .debug_aranges section. */
67 typedef struct
68 {
69 dwarf_vma ar_length;
70 unsigned short ar_version;
71 dwarf_vma ar_info_offset;
72 unsigned char ar_pointer_size;
73 unsigned char ar_segment_size;
74 }
75 DWARF2_Internal_ARange;
76
77 /* N.B. The order here must match the order in debug_displays. */
78
79 enum dwarf_section_display_enum
80 {
81 abbrev = 0,
82 aranges,
83 frame,
84 info,
85 line,
86 pubnames,
87 gnu_pubnames,
88 eh_frame,
89 macinfo,
90 macro,
91 str,
92 line_str,
93 loc,
94 loclists,
95 pubtypes,
96 gnu_pubtypes,
97 ranges,
98 rnglists,
99 static_func,
100 static_vars,
101 types,
102 weaknames,
103 gdb_index,
104 debug_names,
105 trace_info,
106 trace_abbrev,
107 trace_aranges,
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,
119 dwp_cu_index,
120 dwp_tu_index,
121 gnu_debuglink,
122 gnu_debugaltlink,
123 debug_sup,
124 separate_debug_str,
125 max
126 };
127
128 struct dwarf_section
129 {
130 /* A debug section has a different name when it's stored compressed
131 or not. XCOFF DWARF section also have a special name.
132 COMPRESSED_NAME, UNCOMPRESSED_NAME and XCOFF_NAME are the three
133 possibilities. NAME is set to whichever one is used for this
134 input file, as determined by load_debug_section(). */
135 const char * uncompressed_name;
136 const char * compressed_name;
137 const char * xcoff_name;
138 const char * name;
139 /* If non-NULL then FILENAME is the name of the separate debug info
140 file containing the section. */
141 const char * filename;
142 unsigned char * start;
143 dwarf_vma address;
144 dwarf_size_type size;
145 enum dwarf_section_display_enum abbrev_sec;
146 /* Used by clients to help them implement the reloc_at callback. */
147 void * reloc_info;
148 unsigned long num_relocs;
149 };
150
151 /* A structure containing the name of a debug section
152 and a pointer to a function that can decode it. */
153 struct dwarf_section_display
154 {
155 struct dwarf_section section;
156 int (*display) (struct dwarf_section *, void *);
157 int *enabled;
158 bool relocate;
159 };
160
161 extern struct dwarf_section_display debug_displays [];
162
163 /* This structure records the information that
164 we extract from the.debug_info section. */
165 typedef struct
166 {
167 unsigned int pointer_size;
168 unsigned int offset_size;
169 int dwarf_version;
170 dwarf_vma cu_offset;
171 dwarf_vma base_address;
172 /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and
173 is used with the form DW_FORM_GNU_addr_index. */
174 dwarf_vma addr_base;
175 /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and
176 is used when calculating ranges. */
177 dwarf_vma ranges_base;
178 /* This is an array of offsets to the location list table. */
179 dwarf_vma * loc_offsets;
180 /* This is an array of offsets to the location view table. */
181 dwarf_vma * loc_views;
182 int * have_frame_base;
183 unsigned int num_loc_offsets;
184 unsigned int max_loc_offsets;
185 unsigned int num_loc_views;
186 /* List of .debug_ranges offsets seen in this .debug_info. */
187 dwarf_vma * range_lists;
188 unsigned int num_range_lists;
189 unsigned int max_range_lists;
190 }
191 debug_info;
192
193 typedef struct separate_info
194 {
195 void * handle; /* The pointer returned by open_debug_file(). */
196 const char * filename;
197 struct separate_info * next;
198 } separate_info;
199
200 extern separate_info * first_separate_info;
201
202 extern unsigned int eh_addr_size;
203
204 extern int do_debug_info;
205 extern int do_debug_abbrevs;
206 extern int do_debug_lines;
207 extern int do_debug_pubnames;
208 extern int do_debug_pubtypes;
209 extern int do_debug_aranges;
210 extern int do_debug_ranges;
211 extern int do_debug_frames;
212 extern int do_debug_frames_interp;
213 extern int do_debug_macinfo;
214 extern int do_debug_str;
215 extern int do_debug_str_offsets;
216 extern int do_debug_loc;
217 extern int do_gdb_index;
218 extern int do_trace_info;
219 extern int do_trace_abbrevs;
220 extern int do_trace_aranges;
221 extern int do_debug_addr;
222 extern int do_debug_cu_index;
223 extern int do_wide;
224 extern int do_debug_links;
225 extern int do_follow_links;
226 extern bool do_checks;
227
228 extern int dwarf_cutoff_level;
229 extern unsigned long dwarf_start_die;
230
231 extern int dwarf_check;
232
233 extern void init_dwarf_regnames_by_elf_machine_code (unsigned int);
234 extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
235 unsigned long mach);
236
237 extern bool load_debug_section (enum dwarf_section_display_enum, void *);
238 extern void free_debug_section (enum dwarf_section_display_enum);
239 extern bool load_separate_debug_files (void *, const char *);
240 extern void close_debug_file (void *);
241 extern void *open_debug_file (const char *);
242
243 extern void free_debug_memory (void);
244
245 extern void dwarf_select_sections_by_names (const char *);
246 extern void dwarf_select_sections_by_letters (const char *);
247 extern void dwarf_select_sections_all (void);
248
249 extern unsigned int * find_cu_tu_set (void *, unsigned int);
250
251 extern void * cmalloc (size_t, size_t);
252 extern void * xcalloc2 (size_t, size_t);
253 extern void * xcmalloc (size_t, size_t);
254 extern void * xcrealloc (void *, size_t, size_t);
255
256 /* A callback into the client. Returns TRUE if there is a
257 relocation against the given debug section at the given
258 offset. */
259 extern bool reloc_at (struct dwarf_section *, dwarf_vma);
260
261 extern dwarf_vma read_leb128 (unsigned char *, const unsigned char *const,
262 bool, unsigned int *, int *);
263
264 #if HAVE_LIBDEBUGINFOD
265 extern unsigned char * get_build_id (void *);
266 #endif
267
268 static inline void
269 report_leb_status (int status)
270 {
271 if ((status & 1) != 0)
272 error (_("end of data encountered whilst reading LEB\n"));
273 else if ((status & 2) != 0)
274 error (_("read LEB value is too large to store in destination variable\n"));
275 }
276
277 #define SKIP_ULEB(start, end) \
278 do \
279 { \
280 unsigned int _len; \
281 read_leb128 (start, end, false, &_len, NULL); \
282 start += _len; \
283 } \
284 while (0)
285
286 #define SKIP_SLEB(start, end) \
287 do \
288 { \
289 unsigned int _len; \
290 read_leb128 (start, end, true, &_len, NULL); \
291 start += _len; \
292 } \
293 while (0)
294
295 #define READ_ULEB(var, start, end) \
296 do \
297 { \
298 dwarf_vma _val; \
299 unsigned int _len; \
300 int _status; \
301 \
302 _val = read_leb128 (start, end, false, &_len, &_status); \
303 start += _len; \
304 (var) = _val; \
305 if ((var) != _val) \
306 _status |= 2; \
307 report_leb_status (_status); \
308 } \
309 while (0)
310
311 #define READ_SLEB(var, start, end) \
312 do \
313 { \
314 dwarf_signed_vma _val; \
315 unsigned int _len; \
316 int _status; \
317 \
318 _val = read_leb128 (start, end, true, &_len, &_status); \
319 start += _len; \
320 (var) = _val; \
321 if ((var) != _val) \
322 _status |= 2; \
323 report_leb_status (_status); \
324 } \
325 while (0)