Commit | Line | Data |
---|---|---|
cd4fb1b2 SM |
1 | /* DWARF 2 debugging format support for GDB. |
2 | ||
3 | Copyright (C) 1994-2018 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef DWARF2READ_H | |
21 | #define DWARF2READ_H | |
22 | ||
87d6a7aa | 23 | #include "dwarf-index-cache.h" |
cd4fb1b2 SM |
24 | #include "filename-seen-cache.h" |
25 | #include "gdb_obstack.h" | |
26 | ||
3c3bb058 AB |
27 | /* Hold 'maintenance (set|show) dwarf' commands. */ |
28 | extern struct cmd_list_element *set_dwarf_cmdlist; | |
29 | extern struct cmd_list_element *show_dwarf_cmdlist; | |
30 | ||
cd4fb1b2 SM |
31 | typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr; |
32 | DEF_VEC_P (dwarf2_per_cu_ptr); | |
33 | ||
34 | /* A descriptor for dwarf sections. | |
35 | ||
36 | S.ASECTION, SIZE are typically initialized when the objfile is first | |
37 | scanned. BUFFER, READIN are filled in later when the section is read. | |
38 | If the section contained compressed data then SIZE is updated to record | |
39 | the uncompressed size of the section. | |
40 | ||
41 | DWP file format V2 introduces a wrinkle that is easiest to handle by | |
42 | creating the concept of virtual sections contained within a real section. | |
43 | In DWP V2 the sections of the input DWO files are concatenated together | |
44 | into one section, but section offsets are kept relative to the original | |
45 | input section. | |
46 | If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to | |
47 | the real section this "virtual" section is contained in, and BUFFER,SIZE | |
48 | describe the virtual section. */ | |
49 | ||
50 | struct dwarf2_section_info | |
51 | { | |
52 | union | |
53 | { | |
54 | /* If this is a real section, the bfd section. */ | |
55 | asection *section; | |
56 | /* If this is a virtual section, pointer to the containing ("real") | |
57 | section. */ | |
58 | struct dwarf2_section_info *containing_section; | |
59 | } s; | |
60 | /* Pointer to section data, only valid if readin. */ | |
61 | const gdb_byte *buffer; | |
62 | /* The size of the section, real or virtual. */ | |
63 | bfd_size_type size; | |
64 | /* If this is a virtual section, the offset in the real section. | |
65 | Only valid if is_virtual. */ | |
66 | bfd_size_type virtual_offset; | |
67 | /* True if we have tried to read this section. */ | |
68 | char readin; | |
69 | /* True if this is a virtual section, False otherwise. | |
70 | This specifies which of s.section and s.containing_section to use. */ | |
71 | char is_virtual; | |
72 | }; | |
73 | ||
74 | typedef struct dwarf2_section_info dwarf2_section_info_def; | |
75 | DEF_VEC_O (dwarf2_section_info_def); | |
76 | ||
77 | /* Read the contents of the section INFO. | |
78 | OBJFILE is the main object file, but not necessarily the file where | |
79 | the section comes from. E.g., for DWO files the bfd of INFO is the bfd | |
80 | of the DWO file. | |
81 | If the section is compressed, uncompress it before returning. */ | |
82 | ||
83 | void dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info); | |
84 | ||
85 | struct tu_stats | |
86 | { | |
87 | int nr_uniq_abbrev_tables; | |
88 | int nr_symtabs; | |
89 | int nr_symtab_sharers; | |
90 | int nr_stmt_less_type_units; | |
91 | int nr_all_type_units_reallocs; | |
92 | }; | |
93 | ||
94 | struct dwarf2_debug_sections; | |
95 | struct mapped_index; | |
96 | struct mapped_debug_names; | |
ff4c9fec | 97 | struct signatured_type; |
cd4fb1b2 SM |
98 | |
99 | /* Collection of data recorded per objfile. | |
100 | This hangs off of dwarf2_objfile_data_key. */ | |
101 | ||
102 | struct dwarf2_per_objfile : public allocate_on_obstack | |
103 | { | |
104 | /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the | |
105 | dwarf2 section names, or is NULL if the standard ELF names are | |
106 | used. */ | |
107 | dwarf2_per_objfile (struct objfile *objfile, | |
108 | const dwarf2_debug_sections *names); | |
109 | ||
110 | ~dwarf2_per_objfile (); | |
111 | ||
112 | DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile); | |
113 | ||
ff4c9fec SM |
114 | /* Return the CU/TU given its index. |
115 | ||
116 | This is intended for loops like: | |
117 | ||
118 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
119 | + dwarf2_per_objfile->n_type_units); ++i) | |
120 | { | |
121 | dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i); | |
122 | ||
123 | ...; | |
124 | } | |
125 | */ | |
126 | dwarf2_per_cu_data *get_cutu (int index); | |
127 | ||
128 | /* Return the CU given its index. | |
129 | This differs from get_cutu in that it's for when you know INDEX refers to a | |
130 | CU. */ | |
131 | dwarf2_per_cu_data *get_cu (int index); | |
132 | ||
133 | /* Return the TU given its index. | |
134 | This differs from get_cutu in that it's for when you know INDEX refers to a | |
135 | TU. */ | |
136 | signatured_type *get_tu (int index); | |
137 | ||
cd4fb1b2 SM |
138 | /* Free all cached compilation units. */ |
139 | void free_cached_comp_units (); | |
140 | private: | |
141 | /* This function is mapped across the sections and remembers the | |
142 | offset and size of each of the debugging sections we are | |
143 | interested in. */ | |
144 | void locate_sections (bfd *abfd, asection *sectp, | |
145 | const dwarf2_debug_sections &names); | |
146 | ||
147 | public: | |
148 | dwarf2_section_info info {}; | |
149 | dwarf2_section_info abbrev {}; | |
150 | dwarf2_section_info line {}; | |
151 | dwarf2_section_info loc {}; | |
152 | dwarf2_section_info loclists {}; | |
153 | dwarf2_section_info macinfo {}; | |
154 | dwarf2_section_info macro {}; | |
155 | dwarf2_section_info str {}; | |
156 | dwarf2_section_info line_str {}; | |
157 | dwarf2_section_info ranges {}; | |
158 | dwarf2_section_info rnglists {}; | |
159 | dwarf2_section_info addr {}; | |
160 | dwarf2_section_info frame {}; | |
161 | dwarf2_section_info eh_frame {}; | |
162 | dwarf2_section_info gdb_index {}; | |
163 | dwarf2_section_info debug_names {}; | |
164 | dwarf2_section_info debug_aranges {}; | |
165 | ||
166 | VEC (dwarf2_section_info_def) *types = NULL; | |
167 | ||
168 | /* Back link. */ | |
169 | struct objfile *objfile = NULL; | |
170 | ||
171 | /* Table of all the compilation units. This is used to locate | |
172 | the target compilation unit of a particular reference. */ | |
b76e467d | 173 | std::vector<dwarf2_per_cu_data *> all_comp_units; |
cd4fb1b2 | 174 | |
b2bdb8cf SM |
175 | /* The .debug_types-related CUs (TUs). */ |
176 | std::vector<signatured_type *> all_type_units; | |
cd4fb1b2 SM |
177 | |
178 | /* Table of struct type_unit_group objects. | |
179 | The hash key is the DW_AT_stmt_list value. */ | |
180 | htab_t type_unit_groups {}; | |
181 | ||
182 | /* A table mapping .debug_types signatures to its signatured_type entry. | |
183 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
184 | htab_t signatured_types {}; | |
185 | ||
186 | /* Type unit statistics, to see how well the scaling improvements | |
187 | are doing. */ | |
188 | struct tu_stats tu_stats {}; | |
189 | ||
190 | /* A chain of compilation units that are currently read in, so that | |
191 | they can be freed later. */ | |
192 | dwarf2_per_cu_data *read_in_chain = NULL; | |
193 | ||
194 | /* A table mapping DW_AT_dwo_name values to struct dwo_file objects. | |
195 | This is NULL if the table hasn't been allocated yet. */ | |
196 | htab_t dwo_files {}; | |
197 | ||
198 | /* True if we've checked for whether there is a DWP file. */ | |
199 | bool dwp_checked = false; | |
200 | ||
201 | /* The DWP file if there is one, or NULL. */ | |
400174b1 | 202 | std::unique_ptr<struct dwp_file> dwp_file; |
cd4fb1b2 SM |
203 | |
204 | /* The shared '.dwz' file, if one exists. This is used when the | |
205 | original data was compressed using 'dwz -m'. */ | |
7ff8cb8c | 206 | std::unique_ptr<struct dwz_file> dwz_file; |
cd4fb1b2 SM |
207 | |
208 | /* A flag indicating whether this objfile has a section loaded at a | |
209 | VMA of 0. */ | |
210 | bool has_section_at_zero = false; | |
211 | ||
212 | /* True if we are using the mapped index, | |
213 | or we are faking it for OBJF_READNOW's sake. */ | |
214 | bool using_index = false; | |
215 | ||
216 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ | |
3063847f | 217 | std::unique_ptr<mapped_index> index_table; |
cd4fb1b2 SM |
218 | |
219 | /* The mapped index, or NULL if .debug_names is missing or not being used. */ | |
220 | std::unique_ptr<mapped_debug_names> debug_names_table; | |
221 | ||
222 | /* When using index_table, this keeps track of all quick_file_names entries. | |
223 | TUs typically share line table entries with a CU, so we maintain a | |
224 | separate table of all line table entries to support the sharing. | |
225 | Note that while there can be way more TUs than CUs, we've already | |
226 | sorted all the TUs into "type unit groups", grouped by their | |
227 | DW_AT_stmt_list value. Therefore the only sharing done here is with a | |
228 | CU and its associated TU group if there is one. */ | |
229 | htab_t quick_file_names_table {}; | |
230 | ||
231 | /* Set during partial symbol reading, to prevent queueing of full | |
232 | symbols. */ | |
233 | bool reading_partial_symbols = false; | |
234 | ||
235 | /* Table mapping type DIEs to their struct type *. | |
236 | This is NULL if not allocated yet. | |
237 | The mapping is done via (CU/TU + DIE offset) -> type. */ | |
238 | htab_t die_type_hash {}; | |
239 | ||
240 | /* The CUs we recently read. */ | |
c5d0225d | 241 | std::vector<dwarf2_per_cu_data *> just_read_cus; |
cd4fb1b2 SM |
242 | |
243 | /* Table containing line_header indexed by offset and offset_in_dwz. */ | |
244 | htab_t line_header_hash {}; | |
245 | ||
246 | /* Table containing all filenames. This is an optional because the | |
247 | table is lazily constructed on first access. */ | |
248 | gdb::optional<filename_seen_cache> filenames_cache; | |
87d6a7aa SM |
249 | |
250 | /* If we loaded the index from an external file, this contains the | |
251 | resources associated to the open file, memory mapping, etc. */ | |
252 | std::unique_ptr<index_cache_resource> index_cache_res; | |
cd4fb1b2 SM |
253 | }; |
254 | ||
255 | /* Get the dwarf2_per_objfile associated to OBJFILE. */ | |
256 | ||
257 | dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile); | |
258 | ||
259 | /* Persistent data held for a compilation unit, even when not | |
260 | processing it. We put a pointer to this structure in the | |
261 | read_symtab_private field of the psymtab. */ | |
262 | ||
263 | struct dwarf2_per_cu_data | |
264 | { | |
265 | /* The start offset and length of this compilation unit. | |
266 | NOTE: Unlike comp_unit_head.length, this length includes | |
267 | initial_length_size. | |
268 | If the DIE refers to a DWO file, this is always of the original die, | |
269 | not the DWO file. */ | |
270 | sect_offset sect_off; | |
271 | unsigned int length; | |
272 | ||
273 | /* DWARF standard version this data has been read from (such as 4 or 5). */ | |
274 | short dwarf_version; | |
275 | ||
276 | /* Flag indicating this compilation unit will be read in before | |
277 | any of the current compilation units are processed. */ | |
278 | unsigned int queued : 1; | |
279 | ||
280 | /* This flag will be set when reading partial DIEs if we need to load | |
281 | absolutely all DIEs for this compilation unit, instead of just the ones | |
282 | we think are interesting. It gets set if we look for a DIE in the | |
283 | hash table and don't find it. */ | |
284 | unsigned int load_all_dies : 1; | |
285 | ||
286 | /* Non-zero if this CU is from .debug_types. | |
287 | Struct dwarf2_per_cu_data is contained in struct signatured_type iff | |
288 | this is non-zero. */ | |
289 | unsigned int is_debug_types : 1; | |
290 | ||
291 | /* Non-zero if this CU is from the .dwz file. */ | |
292 | unsigned int is_dwz : 1; | |
293 | ||
294 | /* Non-zero if reading a TU directly from a DWO file, bypassing the stub. | |
295 | This flag is only valid if is_debug_types is true. | |
296 | We can't read a CU directly from a DWO file: There are required | |
297 | attributes in the stub. */ | |
298 | unsigned int reading_dwo_directly : 1; | |
299 | ||
300 | /* Non-zero if the TU has been read. | |
301 | This is used to assist the "Stay in DWO Optimization" for Fission: | |
302 | When reading a DWO, it's faster to read TUs from the DWO instead of | |
303 | fetching them from random other DWOs (due to comdat folding). | |
304 | If the TU has already been read, the optimization is unnecessary | |
305 | (and unwise - we don't want to change where gdb thinks the TU lives | |
306 | "midflight"). | |
307 | This flag is only valid if is_debug_types is true. */ | |
308 | unsigned int tu_read : 1; | |
309 | ||
310 | /* The section this CU/TU lives in. | |
311 | If the DIE refers to a DWO file, this is always the original die, | |
312 | not the DWO file. */ | |
313 | struct dwarf2_section_info *section; | |
314 | ||
315 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out | |
316 | of the CU cache it gets reset to NULL again. This is left as NULL for | |
317 | dummy CUs (a CU header, but nothing else). */ | |
318 | struct dwarf2_cu *cu; | |
319 | ||
320 | /* The corresponding dwarf2_per_objfile. */ | |
321 | struct dwarf2_per_objfile *dwarf2_per_objfile; | |
322 | ||
323 | /* When dwarf2_per_objfile->using_index is true, the 'quick' field | |
324 | is active. Otherwise, the 'psymtab' field is active. */ | |
325 | union | |
326 | { | |
327 | /* The partial symbol table associated with this compilation unit, | |
328 | or NULL for unread partial units. */ | |
329 | struct partial_symtab *psymtab; | |
330 | ||
331 | /* Data needed by the "quick" functions. */ | |
332 | struct dwarf2_per_cu_quick_data *quick; | |
333 | } v; | |
334 | ||
335 | /* The CUs we import using DW_TAG_imported_unit. This is filled in | |
336 | while reading psymtabs, used to compute the psymtab dependencies, | |
337 | and then cleared. Then it is filled in again while reading full | |
338 | symbols, and only deleted when the objfile is destroyed. | |
339 | ||
340 | This is also used to work around a difference between the way gold | |
341 | generates .gdb_index version <=7 and the way gdb does. Arguably this | |
342 | is a gold bug. For symbols coming from TUs, gold records in the index | |
343 | the CU that includes the TU instead of the TU itself. This breaks | |
344 | dw2_lookup_symbol: It assumes that if the index says symbol X lives | |
345 | in CU/TU Y, then one need only expand Y and a subsequent lookup in Y | |
346 | will find X. Alas TUs live in their own symtab, so after expanding CU Y | |
347 | we need to look in TU Z to find X. Fortunately, this is akin to | |
348 | DW_TAG_imported_unit, so we just use the same mechanism: For | |
349 | .gdb_index version <=7 this also records the TUs that the CU referred | |
350 | to. Concurrently with this change gdb was modified to emit version 8 | |
351 | indices so we only pay a price for gold generated indices. | |
352 | http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */ | |
353 | VEC (dwarf2_per_cu_ptr) *imported_symtabs; | |
354 | }; | |
355 | ||
356 | /* Entry in the signatured_types hash table. */ | |
357 | ||
358 | struct signatured_type | |
359 | { | |
360 | /* The "per_cu" object of this type. | |
361 | This struct is used iff per_cu.is_debug_types. | |
362 | N.B.: This is the first member so that it's easy to convert pointers | |
363 | between them. */ | |
364 | struct dwarf2_per_cu_data per_cu; | |
365 | ||
366 | /* The type's signature. */ | |
367 | ULONGEST signature; | |
368 | ||
369 | /* Offset in the TU of the type's DIE, as read from the TU header. | |
370 | If this TU is a DWO stub and the definition lives in a DWO file | |
371 | (specified by DW_AT_GNU_dwo_name), this value is unusable. */ | |
372 | cu_offset type_offset_in_tu; | |
373 | ||
374 | /* Offset in the section of the type's DIE. | |
375 | If the definition lives in a DWO file, this is the offset in the | |
376 | .debug_types.dwo section. | |
377 | The value is zero until the actual value is known. | |
378 | Zero is otherwise not a valid section offset. */ | |
379 | sect_offset type_offset_in_section; | |
380 | ||
381 | /* Type units are grouped by their DW_AT_stmt_list entry so that they | |
382 | can share them. This points to the containing symtab. */ | |
383 | struct type_unit_group *type_unit_group; | |
384 | ||
385 | /* The type. | |
386 | The first time we encounter this type we fully read it in and install it | |
387 | in the symbol tables. Subsequent times we only need the type. */ | |
388 | struct type *type; | |
389 | ||
390 | /* Containing DWO unit. | |
391 | This field is valid iff per_cu.reading_dwo_directly. */ | |
392 | struct dwo_unit *dwo_unit; | |
393 | }; | |
394 | ||
395 | typedef struct signatured_type *sig_type_ptr; | |
396 | DEF_VEC_P (sig_type_ptr); | |
397 | ||
398 | #endif /* DWARF2READ_H */ |