]> Git Repo - binutils.git/blob - binutils/dwarf.h
Automatic date update in version.in
[binutils.git] / binutils / dwarf.h
1 /* dwarf.h - DWARF support header file
2    Copyright (C) 2005-2022 Free Software Foundation, Inc.
3
4    This file is part of GNU Binutils.
5
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.
10
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.
15
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.  */
20
21 #include "dwarf2.h" /* for enum dwarf_unit_type */
22
23 /* Structure found in the .debug_line section.  */
24 typedef struct
25 {
26   uint64_t       li_length;
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;
34   int            li_line_base;
35   unsigned char  li_line_range;
36   unsigned char  li_opcode_base;
37   unsigned int   li_offset_size;
38 }
39 DWARF2_Internal_LineInfo;
40
41 /* Structure found in .debug_pubnames section.  */
42 typedef struct
43 {
44   uint64_t       pn_length;
45   unsigned short pn_version;
46   uint64_t       pn_offset;
47   uint64_t       pn_size;
48 }
49 DWARF2_Internal_PubNames;
50
51 /* Structure found in .debug_info section.  */
52 typedef struct
53 {
54   uint64_t       cu_length;
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;
59 }
60 DWARF2_Internal_CompUnit;
61
62 /* Structure found in .debug_aranges section.  */
63 typedef struct
64 {
65   uint64_t       ar_length;
66   unsigned short ar_version;
67   uint64_t       ar_info_offset;
68   unsigned char  ar_pointer_size;
69   unsigned char  ar_segment_size;
70 }
71 DWARF2_Internal_ARange;
72
73 /* N.B. The order here must match the order in debug_displays.  */
74
75 enum dwarf_section_display_enum
76 {
77   abbrev = 0,
78   aranges,
79   frame,
80   info,
81   line,
82   pubnames,
83   gnu_pubnames,
84   eh_frame,
85   macinfo,
86   macro,
87   str,
88   line_str,
89   loc,
90   loclists,
91   loclists_dwo,
92   pubtypes,
93   gnu_pubtypes,
94   ranges,
95   rnglists,
96   rnglists_dwo,
97   static_func,
98   static_vars,
99   types,
100   weaknames,
101   gdb_index,
102   debug_names,
103   trace_info,
104   trace_abbrev,
105   trace_aranges,
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,
117   dwp_cu_index,
118   dwp_tu_index,
119   gnu_debuglink,
120   gnu_debugaltlink,
121   debug_sup,
122   separate_debug_str,
123   note_gnu_build_id,
124   max
125 };
126
127 struct dwarf_section
128 {
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;
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;
142   uint64_t                         address;
143   uint64_t                         size;
144   enum dwarf_section_display_enum  abbrev_sec;
145   /* Used by clients to help them implement the reloc_at callback.  */
146   void *                           reloc_info;
147   uint64_t                         num_relocs;
148 };
149
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
153 {
154   struct dwarf_section section;
155   int (*display) (struct dwarf_section *, void *);
156   int *enabled;
157   bool relocate;
158 };
159
160 extern struct dwarf_section_display debug_displays [];
161
162 /* This structure records the information that
163    we extract from the.debug_info section.  */
164 typedef struct
165 {
166   unsigned int   pointer_size;
167   unsigned int   offset_size;
168   int            dwarf_version;
169   uint64_t       cu_offset;
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.  */
173   uint64_t       addr_base;
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;
182
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;
188
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;
195 }
196 debug_info;
197
198 typedef 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
205 extern separate_info * first_separate_info;
206
207 extern unsigned int eh_addr_size;
208
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;
235
236 extern int dwarf_cutoff_level;
237 extern unsigned long dwarf_start_die;
238
239 extern int dwarf_check;
240
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);
244
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 *);
250
251 extern void free_debug_memory (void);
252
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);
256
257 extern unsigned int * find_cu_tu_set (void *, unsigned int);
258
259 extern void * cmalloc (uint64_t, size_t);
260 extern void * xcalloc2 (uint64_t, size_t);
261 extern void * xcmalloc (uint64_t, size_t);
262 extern void * xcrealloc (void *, uint64_t, size_t);
263
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 *, uint64_t);
268
269 extern uint64_t read_leb128 (unsigned char *, const unsigned char *const,
270                              bool, unsigned int *, int *);
271
272 #if HAVE_LIBDEBUGINFOD
273 extern unsigned char * get_build_id (void *);
274 #endif
275
276 static inline void
277 report_leb_status (int status)
278 {
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"));
283 }
284
285 #define SKIP_ULEB(start, end)                                   \
286   do                                                            \
287     {                                                           \
288       unsigned int _len;                                        \
289       read_leb128 (start, end, false, &_len, NULL);             \
290       start += _len;                                            \
291     }                                                           \
292   while (0)
293
294 #define SKIP_SLEB(start, end)                                   \
295   do                                                            \
296     {                                                           \
297       unsigned int _len;                                        \
298       read_leb128 (start, end, true, &_len, NULL);              \
299       start += _len;                                            \
300     }                                                           \
301   while (0)
302
303 #define READ_ULEB(var, start, end)                              \
304   do                                                            \
305     {                                                           \
306       uint64_t _val;                                            \
307       unsigned int _len;                                        \
308       int _status;                                              \
309                                                                 \
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);                              \
316     }                                                           \
317   while (0)
318
319 #define READ_SLEB(var, start, end)                              \
320   do                                                            \
321     {                                                           \
322       int64_t _val;                                             \
323       unsigned int _len;                                        \
324       int _status;                                              \
325                                                                 \
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);                              \
332     }                                                           \
333   while (0)
This page took 0.041897 seconds and 4 git commands to generate.