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