]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - binutils/dwarf.h
Add option to objdump/readelf to disable access to debuginfod servers.
[thirdparty/binutils-gdb.git] / binutils / dwarf.h
CommitLineData
1b315056 1/* dwarf.h - DWARF support header file
a2c58332 2 Copyright (C) 2005-2022 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
23typedef unsigned HOST_WIDEST_INT dwarf_vma;
24typedef HOST_WIDEST_INT dwarf_signed_vma;
25typedef unsigned HOST_WIDEST_INT dwarf_size_type;
19e6b90e 26
47704ddf 27/* Structure found in the .debug_line section. */
47704ddf
KT
28typedef 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}
43DWARF2_Internal_LineInfo;
44
45/* Structure found in .debug_pubnames section. */
47704ddf
KT
46typedef 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}
53DWARF2_Internal_PubNames;
54
55/* Structure found in .debug_info section. */
47704ddf
KT
56typedef 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}
64DWARF2_Internal_CompUnit;
65
77ef8654 66/* Structure found in .debug_aranges section. */
47704ddf
KT
67typedef 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}
75DWARF2_Internal_ARange;
76
459d52c8
DE
77/* N.B. The order here must match the order in debug_displays. */
78
c34f4fc6
NC
79enum 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,
e38332c2 123 debug_sup,
dda8d76d 124 separate_debug_str,
61ab1364 125 note_gnu_build_id,
19e6b90e
L
126 max
127};
128
4723351a
CC
129struct 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;
144 dwarf_vma address;
145 dwarf_size_type size;
146 enum dwarf_section_display_enum abbrev_sec;
d1c4b12b 147 /* Used by clients to help them implement the reloc_at callback. */
dda8d76d
NC
148 void * reloc_info;
149 unsigned long 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. */
154struct 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
162extern struct dwarf_section_display debug_displays [];
163
164/* This structure records the information that
165 we extract from the.debug_info section. */
166typedef struct
167{
168 unsigned int pointer_size;
b7807392
JJ
169 unsigned int offset_size;
170 int dwarf_version;
467c65bc
NC
171 dwarf_vma cu_offset;
172 dwarf_vma 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. */
4723351a
CC
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;
19e6b90e 179 /* This is an array of offsets to the location list table. */
467c65bc 180 dwarf_vma * loc_offsets;
9f272209
AO
181 /* This is an array of offsets to the location view table. */
182 dwarf_vma * loc_views;
467c65bc 183 int * have_frame_base;
19e6b90e
L
184 unsigned int num_loc_offsets;
185 unsigned int max_loc_offsets;
9f272209 186 unsigned int num_loc_views;
01a8f077 187 /* List of .debug_ranges offsets seen in this .debug_info. */
467c65bc 188 dwarf_vma * range_lists;
19e6b90e
L
189 unsigned int num_range_lists;
190 unsigned int max_range_lists;
191}
192debug_info;
193
24841daa
NC
194typedef struct separate_info
195{
196 void * handle; /* The pointer returned by open_debug_file(). */
197 const char * filename;
198 struct separate_info * next;
199} separate_info;
200
201extern separate_info * first_separate_info;
202
77ef8654 203extern unsigned int eh_addr_size;
19e6b90e
L
204
205extern int do_debug_info;
206extern int do_debug_abbrevs;
207extern int do_debug_lines;
208extern int do_debug_pubnames;
f9f0e732 209extern int do_debug_pubtypes;
19e6b90e
L
210extern int do_debug_aranges;
211extern int do_debug_ranges;
212extern int do_debug_frames;
213extern int do_debug_frames_interp;
214extern int do_debug_macinfo;
215extern int do_debug_str;
e4b7104b 216extern int do_debug_str_offsets;
19e6b90e 217extern int do_debug_loc;
5bbdf3d5 218extern int do_gdb_index;
6f875884
TG
219extern int do_trace_info;
220extern int do_trace_abbrevs;
221extern int do_trace_aranges;
657d0d47
CC
222extern int do_debug_addr;
223extern int do_debug_cu_index;
c34f4fc6 224extern int do_wide;
dda8d76d 225extern int do_debug_links;
39f0547e 226extern int do_follow_links;
bed566bb
NC
227#ifdef HAVE_LIBDEBUGINFOD
228extern int use_debuginfod;
229#endif
015dc7e1 230extern bool do_checks;
19e6b90e 231
fd2f0033
TT
232extern int dwarf_cutoff_level;
233extern unsigned long dwarf_start_die;
234
4723351a
CC
235extern int dwarf_check;
236
955ff7fc 237extern void init_dwarf_regnames_by_elf_machine_code (unsigned int);
229a22cf
AB
238extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
239 unsigned long mach);
2dc4cec1 240
015dc7e1
AM
241extern bool load_debug_section (enum dwarf_section_display_enum, void *);
242extern void free_debug_section (enum dwarf_section_display_enum);
243extern bool load_separate_debug_files (void *, const char *);
244extern void close_debug_file (void *);
245extern void *open_debug_file (const char *);
19e6b90e
L
246
247extern void free_debug_memory (void);
248
c34f4fc6
NC
249extern void dwarf_select_sections_by_names (const char *);
250extern void dwarf_select_sections_by_letters (const char *);
4cb93e3b
TG
251extern void dwarf_select_sections_all (void);
252
82b1b41b 253extern unsigned int * find_cu_tu_set (void *, unsigned int);
657d0d47 254
82b1b41b 255extern void * cmalloc (size_t, size_t);
72c61a0d 256extern void * xcalloc2 (size_t, size_t);
82b1b41b
NC
257extern void * xcmalloc (size_t, size_t);
258extern void * xcrealloc (void *, size_t, size_t);
19e6b90e 259
222c2bf0 260/* A callback into the client. Returns TRUE if there is a
d1c4b12b
NC
261 relocation against the given debug section at the given
262 offset. */
015dc7e1 263extern bool reloc_at (struct dwarf_section *, dwarf_vma);
cd30bcef
AM
264
265extern dwarf_vma read_leb128 (unsigned char *, const unsigned char *const,
015dc7e1 266 bool, unsigned int *, int *);
cd30bcef 267
301a9420
AM
268#if HAVE_LIBDEBUGINFOD
269extern unsigned char * get_build_id (void *);
270#endif
271
cd30bcef 272static inline void
9039747f 273report_leb_status (int status)
cd30bcef
AM
274{
275 if ((status & 1) != 0)
9039747f 276 error (_("end of data encountered whilst reading LEB\n"));
cd30bcef 277 else if ((status & 2) != 0)
9039747f 278 error (_("read LEB value is too large to store in destination variable\n"));
cd30bcef
AM
279}
280
281#define SKIP_ULEB(start, end) \
282 do \
283 { \
284 unsigned int _len; \
015dc7e1 285 read_leb128 (start, end, false, &_len, NULL); \
cd30bcef 286 start += _len; \
1b513401
NC
287 } \
288 while (0)
cd30bcef
AM
289
290#define SKIP_SLEB(start, end) \
291 do \
292 { \
293 unsigned int _len; \
015dc7e1 294 read_leb128 (start, end, true, &_len, NULL); \
cd30bcef 295 start += _len; \
1b513401
NC
296 } \
297 while (0)
cd30bcef
AM
298
299#define READ_ULEB(var, start, end) \
300 do \
301 { \
302 dwarf_vma _val; \
303 unsigned int _len; \
304 int _status; \
305 \
015dc7e1 306 _val = read_leb128 (start, end, false, &_len, &_status); \
cd30bcef
AM
307 start += _len; \
308 (var) = _val; \
309 if ((var) != _val) \
310 _status |= 2; \
9039747f 311 report_leb_status (_status); \
1b513401
NC
312 } \
313 while (0)
cd30bcef
AM
314
315#define READ_SLEB(var, start, end) \
316 do \
317 { \
318 dwarf_signed_vma _val; \
319 unsigned int _len; \
320 int _status; \
321 \
015dc7e1 322 _val = read_leb128 (start, end, true, &_len, &_status); \
cd30bcef
AM
323 start += _len; \
324 (var) = _val; \
325 if ((var) != _val) \
326 _status |= 2; \
9039747f 327 report_leb_status (_status); \
1b513401
NC
328 } \
329 while (0)