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