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