]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - binutils/dwarf.h
Support for location and range lists for split-dwarf and dwarf-5.
[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,
4694a0e5 95 loclists_dwo,
19e6b90e 96 pubtypes,
459d52c8 97 gnu_pubtypes,
19e6b90e 98 ranges,
d4620bee 99 rnglists,
4694a0e5 100 rnglists_dwo,
19e6b90e
L
101 static_func,
102 static_vars,
103 types,
104 weaknames,
48049d1e 105 gdb_index,
61364358 106 debug_names,
6f875884
TG
107 trace_info,
108 trace_abbrev,
109 trace_aranges,
4723351a
CC
110 info_dwo,
111 abbrev_dwo,
112 types_dwo,
113 line_dwo,
114 loc_dwo,
115 macro_dwo,
116 macinfo_dwo,
117 str_dwo,
118 str_index,
119 str_index_dwo,
120 debug_addr,
657d0d47
CC
121 dwp_cu_index,
122 dwp_tu_index,
dda8d76d
NC
123 gnu_debuglink,
124 gnu_debugaltlink,
e38332c2 125 debug_sup,
dda8d76d 126 separate_debug_str,
61ab1364 127 note_gnu_build_id,
19e6b90e
L
128 max
129};
130
4723351a
CC
131struct dwarf_section
132{
133 /* A debug section has a different name when it's stored compressed
51d29b8c
CC
134 or not. XCOFF DWARF section also have a special name.
135 COMPRESSED_NAME, UNCOMPRESSED_NAME and XCOFF_NAME are the three
4723351a
CC
136 possibilities. NAME is set to whichever one is used for this
137 input file, as determined by load_debug_section(). */
dda8d76d
NC
138 const char * uncompressed_name;
139 const char * compressed_name;
51d29b8c 140 const char * xcoff_name;
dda8d76d
NC
141 const char * name;
142 /* If non-NULL then FILENAME is the name of the separate debug info
143 file containing the section. */
144 const char * filename;
145 unsigned char * start;
146 dwarf_vma address;
147 dwarf_size_type size;
148 enum dwarf_section_display_enum abbrev_sec;
d1c4b12b 149 /* Used by clients to help them implement the reloc_at callback. */
dda8d76d
NC
150 void * reloc_info;
151 unsigned long num_relocs;
4723351a
CC
152};
153
154/* A structure containing the name of a debug section
155 and a pointer to a function that can decode it. */
156struct dwarf_section_display
157{
015dc7e1
AM
158 struct dwarf_section section;
159 int (*display) (struct dwarf_section *, void *);
160 int *enabled;
161 bool relocate;
4723351a
CC
162};
163
19e6b90e
L
164extern struct dwarf_section_display debug_displays [];
165
166/* This structure records the information that
167 we extract from the.debug_info section. */
168typedef struct
169{
170 unsigned int pointer_size;
b7807392
JJ
171 unsigned int offset_size;
172 int dwarf_version;
467c65bc
NC
173 dwarf_vma cu_offset;
174 dwarf_vma base_address;
4723351a 175 /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and
528a4f87 176 is used with the form DW_FORM_GNU_addr_index. */
4723351a
CC
177 dwarf_vma addr_base;
178 /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and
179 is used when calculating ranges. */
180 dwarf_vma ranges_base;
19e6b90e 181 /* This is an array of offsets to the location list table. */
467c65bc 182 dwarf_vma * loc_offsets;
9f272209
AO
183 /* This is an array of offsets to the location view table. */
184 dwarf_vma * loc_views;
467c65bc 185 int * have_frame_base;
19c26da6
NC
186
187 /* Information for associating location lists with CUs. */
19e6b90e
L
188 unsigned int num_loc_offsets;
189 unsigned int max_loc_offsets;
9f272209 190 unsigned int num_loc_views;
19c26da6
NC
191 dwarf_vma loclists_base;
192
01a8f077 193 /* List of .debug_ranges offsets seen in this .debug_info. */
467c65bc 194 dwarf_vma * range_lists;
19e6b90e
L
195 unsigned int num_range_lists;
196 unsigned int max_range_lists;
ec41dd75 197 dwarf_vma rnglists_base;
f18acc9c 198 dwarf_vma str_offsets_base;
19e6b90e
L
199}
200debug_info;
201
24841daa
NC
202typedef struct separate_info
203{
204 void * handle; /* The pointer returned by open_debug_file(). */
205 const char * filename;
206 struct separate_info * next;
207} separate_info;
208
209extern separate_info * first_separate_info;
210
77ef8654 211extern unsigned int eh_addr_size;
19e6b90e
L
212
213extern int do_debug_info;
214extern int do_debug_abbrevs;
215extern int do_debug_lines;
216extern int do_debug_pubnames;
f9f0e732 217extern int do_debug_pubtypes;
19e6b90e
L
218extern int do_debug_aranges;
219extern int do_debug_ranges;
220extern int do_debug_frames;
221extern int do_debug_frames_interp;
222extern int do_debug_macinfo;
223extern int do_debug_str;
e4b7104b 224extern int do_debug_str_offsets;
19e6b90e 225extern int do_debug_loc;
5bbdf3d5 226extern int do_gdb_index;
6f875884
TG
227extern int do_trace_info;
228extern int do_trace_abbrevs;
229extern int do_trace_aranges;
657d0d47
CC
230extern int do_debug_addr;
231extern int do_debug_cu_index;
c34f4fc6 232extern int do_wide;
dda8d76d 233extern int do_debug_links;
39f0547e 234extern int do_follow_links;
bed566bb
NC
235#ifdef HAVE_LIBDEBUGINFOD
236extern int use_debuginfod;
237#endif
015dc7e1 238extern bool do_checks;
19e6b90e 239
fd2f0033
TT
240extern int dwarf_cutoff_level;
241extern unsigned long dwarf_start_die;
242
4723351a
CC
243extern int dwarf_check;
244
955ff7fc 245extern void init_dwarf_regnames_by_elf_machine_code (unsigned int);
229a22cf
AB
246extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
247 unsigned long mach);
2dc4cec1 248
015dc7e1
AM
249extern bool load_debug_section (enum dwarf_section_display_enum, void *);
250extern void free_debug_section (enum dwarf_section_display_enum);
251extern bool load_separate_debug_files (void *, const char *);
252extern void close_debug_file (void *);
253extern void *open_debug_file (const char *);
19e6b90e
L
254
255extern void free_debug_memory (void);
256
94585d6d
NC
257extern int dwarf_select_sections_by_names (const char *);
258extern int dwarf_select_sections_by_letters (const char *);
4cb93e3b
TG
259extern void dwarf_select_sections_all (void);
260
82b1b41b 261extern unsigned int * find_cu_tu_set (void *, unsigned int);
657d0d47 262
82b1b41b 263extern void * cmalloc (size_t, size_t);
72c61a0d 264extern void * xcalloc2 (size_t, size_t);
82b1b41b
NC
265extern void * xcmalloc (size_t, size_t);
266extern void * xcrealloc (void *, size_t, size_t);
19e6b90e 267
222c2bf0 268/* A callback into the client. Returns TRUE if there is a
d1c4b12b
NC
269 relocation against the given debug section at the given
270 offset. */
015dc7e1 271extern bool reloc_at (struct dwarf_section *, dwarf_vma);
cd30bcef
AM
272
273extern dwarf_vma read_leb128 (unsigned char *, const unsigned char *const,
015dc7e1 274 bool, unsigned int *, int *);
cd30bcef 275
301a9420
AM
276#if HAVE_LIBDEBUGINFOD
277extern unsigned char * get_build_id (void *);
278#endif
279
cd30bcef 280static inline void
9039747f 281report_leb_status (int status)
cd30bcef
AM
282{
283 if ((status & 1) != 0)
9039747f 284 error (_("end of data encountered whilst reading LEB\n"));
cd30bcef 285 else if ((status & 2) != 0)
9039747f 286 error (_("read LEB value is too large to store in destination variable\n"));
cd30bcef
AM
287}
288
289#define SKIP_ULEB(start, end) \
290 do \
291 { \
292 unsigned int _len; \
015dc7e1 293 read_leb128 (start, end, false, &_len, NULL); \
cd30bcef 294 start += _len; \
1b513401
NC
295 } \
296 while (0)
cd30bcef
AM
297
298#define SKIP_SLEB(start, end) \
299 do \
300 { \
301 unsigned int _len; \
015dc7e1 302 read_leb128 (start, end, true, &_len, NULL); \
cd30bcef 303 start += _len; \
1b513401
NC
304 } \
305 while (0)
cd30bcef
AM
306
307#define READ_ULEB(var, start, end) \
308 do \
309 { \
310 dwarf_vma _val; \
311 unsigned int _len; \
312 int _status; \
313 \
015dc7e1 314 _val = read_leb128 (start, end, false, &_len, &_status); \
cd30bcef
AM
315 start += _len; \
316 (var) = _val; \
317 if ((var) != _val) \
318 _status |= 2; \
9039747f 319 report_leb_status (_status); \
1b513401
NC
320 } \
321 while (0)
cd30bcef
AM
322
323#define READ_SLEB(var, start, end) \
324 do \
325 { \
326 dwarf_signed_vma _val; \
327 unsigned int _len; \
328 int _status; \
329 \
015dc7e1 330 _val = read_leb128 (start, end, true, &_len, &_status); \
cd30bcef
AM
331 start += _len; \
332 (var) = _val; \
333 if ((var) != _val) \
334 _status |= 2; \
9039747f 335 report_leb_status (_status); \
1b513401
NC
336 } \
337 while (0)