Fix dwarf_section_display_enum regression by DWARF-5
[external/binutils.git] / binutils / dwarf.h
1 /* dwarf.h - DWARF support header file
2    Copyright (C) 2005-2017 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 typedef unsigned HOST_WIDEST_INT  dwarf_vma;
24 typedef HOST_WIDEST_INT           dwarf_signed_vma;
25 typedef unsigned HOST_WIDEST_INT  dwarf_size_type;
26
27 /* Structure found in the .debug_line section.  */
28 typedef struct
29 {
30   dwarf_vma      li_length;
31   unsigned short li_version;
32   dwarf_vma      li_prologue_length;
33   unsigned char  li_min_insn_length;
34   unsigned char  li_max_ops_per_insn;
35   unsigned char  li_default_is_stmt;
36   int            li_line_base;
37   unsigned char  li_line_range;
38   unsigned char  li_opcode_base;
39   unsigned int   li_offset_size;
40 }
41 DWARF2_Internal_LineInfo;
42
43 /* Structure found in .debug_pubnames section.  */
44 typedef struct
45 {
46   dwarf_vma      pn_length;
47   unsigned short pn_version;
48   dwarf_vma      pn_offset;
49   dwarf_vma      pn_size;
50 }
51 DWARF2_Internal_PubNames;
52
53 /* Structure found in .debug_info section.  */
54 typedef struct
55 {
56   dwarf_vma      cu_length;
57   unsigned short cu_version;
58   dwarf_vma      cu_abbrev_offset;
59   unsigned char  cu_pointer_size;
60   enum dwarf_unit_type cu_unit_type;
61 }
62 DWARF2_Internal_CompUnit;
63
64 /* Structure found in .debug_aranges section.  */
65 typedef struct
66 {
67   dwarf_vma      ar_length;
68   unsigned short ar_version;
69   dwarf_vma      ar_info_offset;
70   unsigned char  ar_pointer_size;
71   unsigned char  ar_segment_size;
72 }
73 DWARF2_Internal_ARange;
74
75 /* N.B. The order here must match the order in debug_displays.  */
76
77 enum dwarf_section_display_enum
78 {
79   abbrev = 0,
80   aranges,
81   frame,
82   info,
83   line,
84   pubnames,
85   gnu_pubnames,
86   eh_frame,
87   macinfo,
88   macro,
89   str,
90   line_str,
91   loc,
92   loclists,
93   pubtypes,
94   gnu_pubtypes,
95   ranges,
96   rnglists,
97   static_func,
98   static_vars,
99   types,
100   weaknames,
101   gdb_index,
102   trace_info,
103   trace_abbrev,
104   trace_aranges,
105   info_dwo,
106   abbrev_dwo,
107   types_dwo,
108   line_dwo,
109   loc_dwo,
110   macro_dwo,
111   macinfo_dwo,
112   str_dwo,
113   str_index,
114   str_index_dwo,
115   debug_addr,
116   dwp_cu_index,
117   dwp_tu_index,
118   max
119 };
120
121 struct dwarf_section
122 {
123   /* A debug section has a different name when it's stored compressed
124      or not.  COMPRESSED_NAME and UNCOMPRESSED_NAME are the two
125      possibilities.  NAME is set to whichever one is used for this
126      input file, as determined by load_debug_section().  */
127   const char *uncompressed_name;
128   const char *compressed_name;
129   const char *name;
130   unsigned char *start;
131   dwarf_vma address;
132   dwarf_size_type size;
133   enum dwarf_section_display_enum abbrev_sec;
134
135   /* Used by clients to help them implement the reloc_at callback.  */
136   void * reloc_info;
137   unsigned long num_relocs;
138
139   /* A spare field for random use.  */
140   void *user_data;
141 };
142
143 /* A structure containing the name of a debug section
144    and a pointer to a function that can decode it.  */
145 struct dwarf_section_display
146 {
147   struct dwarf_section section;
148   int (*display) (struct dwarf_section *, void *);
149   int *enabled;
150   bfd_boolean relocate;
151 };
152
153 extern struct dwarf_section_display debug_displays [];
154
155 /* This structure records the information that
156    we extract from the.debug_info section.  */
157 typedef struct
158 {
159   unsigned int   pointer_size;
160   unsigned int   offset_size;
161   int            dwarf_version;
162   dwarf_vma      cu_offset;
163   dwarf_vma      base_address;
164   /* This field is filled in when reading the attribute DW_AT_GNU_addr_base and
165      is used with the form DW_AT_GNU_FORM_addr_index.  */
166   dwarf_vma      addr_base;
167   /* This field is filled in when reading the attribute DW_AT_GNU_ranges_base and
168      is used when calculating ranges.  */
169   dwarf_vma      ranges_base;
170   /* This is an array of offsets to the location list table.  */
171   dwarf_vma *    loc_offsets;
172   int *          have_frame_base;
173   unsigned int   num_loc_offsets;
174   unsigned int   max_loc_offsets;
175   /* List of .debug_ranges offsets seen in this .debug_info.  */
176   dwarf_vma *    range_lists;
177   unsigned int   num_range_lists;
178   unsigned int   max_range_lists;
179 }
180 debug_info;
181
182 extern unsigned int eh_addr_size;
183
184 extern int do_debug_info;
185 extern int do_debug_abbrevs;
186 extern int do_debug_lines;
187 extern int do_debug_pubnames;
188 extern int do_debug_pubtypes;
189 extern int do_debug_aranges;
190 extern int do_debug_ranges;
191 extern int do_debug_frames;
192 extern int do_debug_frames_interp;
193 extern int do_debug_macinfo;
194 extern int do_debug_str;
195 extern int do_debug_loc;
196 extern int do_gdb_index;
197 extern int do_trace_info;
198 extern int do_trace_abbrevs;
199 extern int do_trace_aranges;
200 extern int do_debug_addr;
201 extern int do_debug_cu_index;
202 extern int do_wide;
203
204 extern int dwarf_cutoff_level;
205 extern unsigned long dwarf_start_die;
206
207 extern int dwarf_check;
208
209 extern void init_dwarf_regnames (unsigned int);
210 extern void init_dwarf_regnames_i386 (void);
211 extern void init_dwarf_regnames_iamcu (void);
212 extern void init_dwarf_regnames_x86_64 (void);
213 extern void init_dwarf_regnames_aarch64 (void);
214 extern void init_dwarf_regnames_s390 (void);
215
216 extern int load_debug_section (enum dwarf_section_display_enum, void *);
217 extern void free_debug_section (enum dwarf_section_display_enum);
218
219 extern void free_debug_memory (void);
220
221 extern void dwarf_select_sections_by_names (const char *);
222 extern void dwarf_select_sections_by_letters (const char *);
223 extern void dwarf_select_sections_all (void);
224
225 extern unsigned int * find_cu_tu_set (void *, unsigned int);
226
227 extern void * cmalloc (size_t, size_t);
228 extern void * xcalloc2 (size_t, size_t);
229 extern void * xcmalloc (size_t, size_t);
230 extern void * xcrealloc (void *, size_t, size_t);
231
232 extern dwarf_vma read_leb128 (unsigned char *, unsigned int *, bfd_boolean, const unsigned char * const);
233
234 /* A callback into the client.  Returns TRUE if there is a
235    relocation against the given debug section at the given
236    offset.  */
237 extern bfd_boolean reloc_at (struct dwarf_section *, dwarf_vma);