gold: don't invoke IA32 syscall in x86_64 assembly testcase
[binutils-gdb.git] / binutils / dwarf.h
blobccce2461c811e34a0ce457ac8bb9d6778d205e01
1 /* dwarf.h - DWARF support header file
2 Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
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.
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.
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. */
21 #include "dwarf2.h" /* for enum dwarf_unit_type */
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;
27 /* Structure found in the .debug_line section. */
28 typedef struct
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;
43 DWARF2_Internal_LineInfo;
45 /* Structure found in .debug_pubnames section. */
46 typedef struct
48 dwarf_vma pn_length;
49 unsigned short pn_version;
50 dwarf_vma pn_offset;
51 dwarf_vma pn_size;
53 DWARF2_Internal_PubNames;
55 /* Structure found in .debug_info section. */
56 typedef struct
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;
64 DWARF2_Internal_CompUnit;
66 /* Structure found in .debug_aranges section. */
67 typedef struct
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;
75 DWARF2_Internal_ARange;
77 /* N.B. The order here must match the order in debug_displays. */
79 enum dwarf_section_display_enum
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 note_gnu_build_id,
129 struct dwarf_section
131 /* A debug section has a different name when it's stored compressed
132 or not. XCOFF DWARF section also have a special name.
133 COMPRESSED_NAME, UNCOMPRESSED_NAME and XCOFF_NAME are the three
134 possibilities. NAME is set to whichever one is used for this
135 input file, as determined by load_debug_section(). */
136 const char * uncompressed_name;
137 const char * compressed_name;
138 const char * xcoff_name;
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;
144 dwarf_vma address;
145 dwarf_size_type size;
146 enum dwarf_section_display_enum abbrev_sec;
147 /* Used by clients to help them implement the reloc_at callback. */
148 void * reloc_info;
149 unsigned long num_relocs;
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
156 struct dwarf_section section;
157 int (*display) (struct dwarf_section *, void *);
158 int *enabled;
159 bool relocate;
162 extern struct dwarf_section_display debug_displays [];
164 /* This structure records the information that
165 we extract from the.debug_info section. */
166 typedef struct
168 unsigned int pointer_size;
169 unsigned int offset_size;
170 int dwarf_version;
171 dwarf_vma cu_offset;
172 dwarf_vma base_address;
173 /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and
174 is used with the form DW_FORM_GNU_addr_index. */
175 dwarf_vma addr_base;
176 /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and
177 is used when calculating ranges. */
178 dwarf_vma ranges_base;
179 /* This is an array of offsets to the location list table. */
180 dwarf_vma * loc_offsets;
181 /* This is an array of offsets to the location view table. */
182 dwarf_vma * loc_views;
183 int * have_frame_base;
185 /* Information for associating location lists with CUs. */
186 unsigned int num_loc_offsets;
187 unsigned int max_loc_offsets;
188 unsigned int num_loc_views;
189 dwarf_vma loclists_base;
191 /* List of .debug_ranges offsets seen in this .debug_info. */
192 dwarf_vma * range_lists;
193 unsigned int num_range_lists;
194 unsigned int max_range_lists;
196 debug_info;
198 typedef struct separate_info
200 void * handle; /* The pointer returned by open_debug_file(). */
201 const char * filename;
202 struct separate_info * next;
203 } separate_info;
205 extern separate_info * first_separate_info;
207 extern unsigned int eh_addr_size;
209 extern int do_debug_info;
210 extern int do_debug_abbrevs;
211 extern int do_debug_lines;
212 extern int do_debug_pubnames;
213 extern int do_debug_pubtypes;
214 extern int do_debug_aranges;
215 extern int do_debug_ranges;
216 extern int do_debug_frames;
217 extern int do_debug_frames_interp;
218 extern int do_debug_macinfo;
219 extern int do_debug_str;
220 extern int do_debug_str_offsets;
221 extern int do_debug_loc;
222 extern int do_gdb_index;
223 extern int do_trace_info;
224 extern int do_trace_abbrevs;
225 extern int do_trace_aranges;
226 extern int do_debug_addr;
227 extern int do_debug_cu_index;
228 extern int do_wide;
229 extern int do_debug_links;
230 extern int do_follow_links;
231 #ifdef HAVE_LIBDEBUGINFOD
232 extern int use_debuginfod;
233 #endif
234 extern bool do_checks;
236 extern int dwarf_cutoff_level;
237 extern unsigned long dwarf_start_die;
239 extern int dwarf_check;
241 extern void init_dwarf_regnames_by_elf_machine_code (unsigned int);
242 extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
243 unsigned long mach);
245 extern bool load_debug_section (enum dwarf_section_display_enum, void *);
246 extern void free_debug_section (enum dwarf_section_display_enum);
247 extern bool load_separate_debug_files (void *, const char *);
248 extern void close_debug_file (void *);
249 extern void *open_debug_file (const char *);
251 extern void free_debug_memory (void);
253 extern void dwarf_select_sections_by_names (const char *);
254 extern void dwarf_select_sections_by_letters (const char *);
255 extern void dwarf_select_sections_all (void);
257 extern unsigned int * find_cu_tu_set (void *, unsigned int);
259 extern void * cmalloc (size_t, size_t);
260 extern void * xcalloc2 (size_t, size_t);
261 extern void * xcmalloc (size_t, size_t);
262 extern void * xcrealloc (void *, size_t, size_t);
264 /* A callback into the client. Returns TRUE if there is a
265 relocation against the given debug section at the given
266 offset. */
267 extern bool reloc_at (struct dwarf_section *, dwarf_vma);
269 extern dwarf_vma read_leb128 (unsigned char *, const unsigned char *const,
270 bool, unsigned int *, int *);
272 #if HAVE_LIBDEBUGINFOD
273 extern unsigned char * get_build_id (void *);
274 #endif
276 static inline void
277 report_leb_status (int status)
279 if ((status & 1) != 0)
280 error (_("end of data encountered whilst reading LEB\n"));
281 else if ((status & 2) != 0)
282 error (_("read LEB value is too large to store in destination variable\n"));
285 #define SKIP_ULEB(start, end) \
286 do \
288 unsigned int _len; \
289 read_leb128 (start, end, false, &_len, NULL); \
290 start += _len; \
292 while (0)
294 #define SKIP_SLEB(start, end) \
295 do \
297 unsigned int _len; \
298 read_leb128 (start, end, true, &_len, NULL); \
299 start += _len; \
301 while (0)
303 #define READ_ULEB(var, start, end) \
304 do \
306 dwarf_vma _val; \
307 unsigned int _len; \
308 int _status; \
310 _val = read_leb128 (start, end, false, &_len, &_status); \
311 start += _len; \
312 (var) = _val; \
313 if ((var) != _val) \
314 _status |= 2; \
315 report_leb_status (_status); \
317 while (0)
319 #define READ_SLEB(var, start, end) \
320 do \
322 dwarf_signed_vma _val; \
323 unsigned int _len; \
324 int _status; \
326 _val = read_leb128 (start, end, true, &_len, &_status); \
327 start += _len; \
328 (var) = _val; \
329 if ((var) != _val) \
330 _status |= 2; \
331 report_leb_status (_status); \
333 while (0)