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 /* Structure found in the .debug_line section. */
27 unsigned short li_version
;
28 unsigned char li_address_size
;
29 unsigned char li_segment_size
;
30 uint64_t li_prologue_length
;
31 unsigned char li_min_insn_length
;
32 unsigned char li_max_ops_per_insn
;
33 unsigned char li_default_is_stmt
;
35 unsigned char li_line_range
;
36 unsigned char li_opcode_base
;
37 unsigned int li_offset_size
;
39 DWARF2_Internal_LineInfo
;
41 /* Structure found in .debug_pubnames section. */
45 unsigned short pn_version
;
49 DWARF2_Internal_PubNames
;
51 /* Structure found in .debug_info section. */
55 unsigned short cu_version
;
56 uint64_t cu_abbrev_offset
;
57 unsigned char cu_pointer_size
;
58 enum dwarf_unit_type cu_unit_type
;
60 DWARF2_Internal_CompUnit
;
62 /* Structure found in .debug_aranges section. */
66 unsigned short ar_version
;
67 uint64_t ar_info_offset
;
68 unsigned char ar_pointer_size
;
69 unsigned char ar_segment_size
;
71 DWARF2_Internal_ARange
;
73 /* N.B. The order here must match the order in debug_displays. */
75 enum dwarf_section_display_enum
129 /* A debug section has a different name when it's stored compressed
130 or not. XCOFF DWARF section also have a special name.
131 COMPRESSED_NAME, UNCOMPRESSED_NAME and XCOFF_NAME are the three
132 possibilities. NAME is set to whichever one is used for this
133 input file, as determined by load_debug_section(). */
134 const char * uncompressed_name
;
135 const char * compressed_name
;
136 const char * xcoff_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
;
144 enum dwarf_section_display_enum abbrev_sec
;
145 /* Used by clients to help them implement the reloc_at callback. */
147 unsigned long num_relocs
;
150 /* A structure containing the name of a debug section
151 and a pointer to a function that can decode it. */
152 struct dwarf_section_display
154 struct dwarf_section section
;
155 int (*display
) (struct dwarf_section
*, void *);
160 extern struct dwarf_section_display debug_displays
[];
162 /* This structure records the information that
163 we extract from the.debug_info section. */
166 unsigned int pointer_size
;
167 unsigned int offset_size
;
170 uint64_t base_address
;
171 /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and
172 is used with the form DW_FORM_GNU_addr_index. */
174 /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and
175 is used when calculating ranges. */
176 uint64_t ranges_base
;
177 /* This is an array of offsets to the location list table. */
178 uint64_t * loc_offsets
;
179 /* This is an array of offsets to the location view table. */
180 uint64_t * loc_views
;
181 int * have_frame_base
;
183 /* Information for associating location lists with CUs. */
184 unsigned int num_loc_offsets
;
185 unsigned int max_loc_offsets
;
186 unsigned int num_loc_views
;
187 uint64_t loclists_base
;
189 /* List of .debug_ranges offsets seen in this .debug_info. */
190 uint64_t * range_lists
;
191 unsigned int num_range_lists
;
192 unsigned int max_range_lists
;
193 uint64_t rnglists_base
;
194 uint64_t str_offsets_base
;
198 typedef struct separate_info
200 void * handle
; /* The pointer returned by open_debug_file(). */
201 const char * filename
;
202 struct separate_info
* next
;
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
;
229 extern int do_debug_links
;
230 extern int do_follow_links
;
231 #ifdef HAVE_LIBDEBUGINFOD
232 extern int use_debuginfod
;
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
,
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 int dwarf_select_sections_by_names (const char *);
254 extern int 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
267 extern bool reloc_at (struct dwarf_section
*, uint64_t);
269 extern uint64_t 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 *);
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) \
289 read_leb128 (start, end, false, &_len, NULL); \
294 #define SKIP_SLEB(start, end) \
298 read_leb128 (start, end, true, &_len, NULL); \
303 #define READ_ULEB(var, start, end) \
310 _val = read_leb128 (start, end, false, &_len, &_status); \
315 report_leb_status (_status); \
319 #define READ_SLEB(var, start, end) \
326 _val = read_leb128 (start, end, true, &_len, &_status); \
331 report_leb_status (_status); \