1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2018 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 #include "filename-seen-cache.h"
24 #include "gdb_obstack.h"
26 /* Hold 'maintenance (set|show) dwarf' commands. */
27 extern struct cmd_list_element
*set_dwarf_cmdlist
;
28 extern struct cmd_list_element
*show_dwarf_cmdlist
;
30 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
31 DEF_VEC_P (dwarf2_per_cu_ptr
);
33 /* A descriptor for dwarf sections.
35 S.ASECTION, SIZE are typically initialized when the objfile is first
36 scanned. BUFFER, READIN are filled in later when the section is read.
37 If the section contained compressed data then SIZE is updated to record
38 the uncompressed size of the section.
40 DWP file format V2 introduces a wrinkle that is easiest to handle by
41 creating the concept of virtual sections contained within a real section.
42 In DWP V2 the sections of the input DWO files are concatenated together
43 into one section, but section offsets are kept relative to the original
45 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
46 the real section this "virtual" section is contained in, and BUFFER,SIZE
47 describe the virtual section. */
49 struct dwarf2_section_info
53 /* If this is a real section, the bfd section. */
55 /* If this is a virtual section, pointer to the containing ("real")
57 struct dwarf2_section_info
*containing_section
;
59 /* Pointer to section data, only valid if readin. */
60 const gdb_byte
*buffer
;
61 /* The size of the section, real or virtual. */
63 /* If this is a virtual section, the offset in the real section.
64 Only valid if is_virtual. */
65 bfd_size_type virtual_offset
;
66 /* True if we have tried to read this section. */
68 /* True if this is a virtual section, False otherwise.
69 This specifies which of s.section and s.containing_section to use. */
73 typedef struct dwarf2_section_info dwarf2_section_info_def
;
74 DEF_VEC_O (dwarf2_section_info_def
);
76 /* Read the contents of the section INFO.
77 OBJFILE is the main object file, but not necessarily the file where
78 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
80 If the section is compressed, uncompress it before returning. */
82 void dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
);
86 int nr_uniq_abbrev_tables
;
88 int nr_symtab_sharers
;
89 int nr_stmt_less_type_units
;
90 int nr_all_type_units_reallocs
;
93 struct dwarf2_debug_sections
;
95 struct mapped_debug_names
;
96 struct signatured_type
;
98 /* Collection of data recorded per objfile.
99 This hangs off of dwarf2_objfile_data_key. */
101 struct dwarf2_per_objfile
: public allocate_on_obstack
103 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
104 dwarf2 section names, or is NULL if the standard ELF names are
106 dwarf2_per_objfile (struct objfile
*objfile
,
107 const dwarf2_debug_sections
*names
);
109 ~dwarf2_per_objfile ();
111 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
113 /* Return the CU/TU given its index.
115 This is intended for loops like:
117 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
118 + dwarf2_per_objfile->n_type_units); ++i)
120 dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
125 dwarf2_per_cu_data
*get_cutu (int index
);
127 /* Return the CU given its index.
128 This differs from get_cutu in that it's for when you know INDEX refers to a
130 dwarf2_per_cu_data
*get_cu (int index
);
132 /* Return the TU given its index.
133 This differs from get_cutu in that it's for when you know INDEX refers to a
135 signatured_type
*get_tu (int index
);
137 /* Free all cached compilation units. */
138 void free_cached_comp_units ();
140 /* This function is mapped across the sections and remembers the
141 offset and size of each of the debugging sections we are
143 void locate_sections (bfd
*abfd
, asection
*sectp
,
144 const dwarf2_debug_sections
&names
);
147 dwarf2_section_info info
{};
148 dwarf2_section_info abbrev
{};
149 dwarf2_section_info line
{};
150 dwarf2_section_info loc
{};
151 dwarf2_section_info loclists
{};
152 dwarf2_section_info macinfo
{};
153 dwarf2_section_info macro
{};
154 dwarf2_section_info str
{};
155 dwarf2_section_info line_str
{};
156 dwarf2_section_info ranges
{};
157 dwarf2_section_info rnglists
{};
158 dwarf2_section_info addr
{};
159 dwarf2_section_info frame
{};
160 dwarf2_section_info eh_frame
{};
161 dwarf2_section_info gdb_index
{};
162 dwarf2_section_info debug_names
{};
163 dwarf2_section_info debug_aranges
{};
165 VEC (dwarf2_section_info_def
) *types
= NULL
;
168 struct objfile
*objfile
= NULL
;
170 /* Table of all the compilation units. This is used to locate
171 the target compilation unit of a particular reference. */
172 std::vector
<dwarf2_per_cu_data
*> all_comp_units
;
174 /* The .debug_types-related CUs (TUs). */
175 std::vector
<signatured_type
*> all_type_units
;
177 /* Table of struct type_unit_group objects.
178 The hash key is the DW_AT_stmt_list value. */
179 htab_t type_unit_groups
{};
181 /* A table mapping .debug_types signatures to its signatured_type entry.
182 This is NULL if the .debug_types section hasn't been read in yet. */
183 htab_t signatured_types
{};
185 /* Type unit statistics, to see how well the scaling improvements
187 struct tu_stats tu_stats
{};
189 /* A chain of compilation units that are currently read in, so that
190 they can be freed later. */
191 dwarf2_per_cu_data
*read_in_chain
= NULL
;
193 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
194 This is NULL if the table hasn't been allocated yet. */
197 /* True if we've checked for whether there is a DWP file. */
198 bool dwp_checked
= false;
200 /* The DWP file if there is one, or NULL. */
201 std::unique_ptr
<struct dwp_file
> dwp_file
;
203 /* The shared '.dwz' file, if one exists. This is used when the
204 original data was compressed using 'dwz -m'. */
205 std::unique_ptr
<struct dwz_file
> dwz_file
;
207 /* A flag indicating whether this objfile has a section loaded at a
209 bool has_section_at_zero
= false;
211 /* True if we are using the mapped index,
212 or we are faking it for OBJF_READNOW's sake. */
213 bool using_index
= false;
215 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
216 std::unique_ptr
<mapped_index
> index_table
;
218 /* The mapped index, or NULL if .debug_names is missing or not being used. */
219 std::unique_ptr
<mapped_debug_names
> debug_names_table
;
221 /* When using index_table, this keeps track of all quick_file_names entries.
222 TUs typically share line table entries with a CU, so we maintain a
223 separate table of all line table entries to support the sharing.
224 Note that while there can be way more TUs than CUs, we've already
225 sorted all the TUs into "type unit groups", grouped by their
226 DW_AT_stmt_list value. Therefore the only sharing done here is with a
227 CU and its associated TU group if there is one. */
228 htab_t quick_file_names_table
{};
230 /* Set during partial symbol reading, to prevent queueing of full
232 bool reading_partial_symbols
= false;
234 /* Table mapping type DIEs to their struct type *.
235 This is NULL if not allocated yet.
236 The mapping is done via (CU/TU + DIE offset) -> type. */
237 htab_t die_type_hash
{};
239 /* The CUs we recently read. */
240 std::vector
<dwarf2_per_cu_data
*> just_read_cus
;
242 /* Table containing line_header indexed by offset and offset_in_dwz. */
243 htab_t line_header_hash
{};
245 /* Table containing all filenames. This is an optional because the
246 table is lazily constructed on first access. */
247 gdb::optional
<filename_seen_cache
> filenames_cache
;
250 /* Get the dwarf2_per_objfile associated to OBJFILE. */
252 dwarf2_per_objfile
*get_dwarf2_per_objfile (struct objfile
*objfile
);
254 /* Persistent data held for a compilation unit, even when not
255 processing it. We put a pointer to this structure in the
256 read_symtab_private field of the psymtab. */
258 struct dwarf2_per_cu_data
260 /* The start offset and length of this compilation unit.
261 NOTE: Unlike comp_unit_head.length, this length includes
263 If the DIE refers to a DWO file, this is always of the original die,
265 sect_offset sect_off
;
268 /* DWARF standard version this data has been read from (such as 4 or 5). */
271 /* Flag indicating this compilation unit will be read in before
272 any of the current compilation units are processed. */
273 unsigned int queued
: 1;
275 /* This flag will be set when reading partial DIEs if we need to load
276 absolutely all DIEs for this compilation unit, instead of just the ones
277 we think are interesting. It gets set if we look for a DIE in the
278 hash table and don't find it. */
279 unsigned int load_all_dies
: 1;
281 /* Non-zero if this CU is from .debug_types.
282 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
284 unsigned int is_debug_types
: 1;
286 /* Non-zero if this CU is from the .dwz file. */
287 unsigned int is_dwz
: 1;
289 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
290 This flag is only valid if is_debug_types is true.
291 We can't read a CU directly from a DWO file: There are required
292 attributes in the stub. */
293 unsigned int reading_dwo_directly
: 1;
295 /* Non-zero if the TU has been read.
296 This is used to assist the "Stay in DWO Optimization" for Fission:
297 When reading a DWO, it's faster to read TUs from the DWO instead of
298 fetching them from random other DWOs (due to comdat folding).
299 If the TU has already been read, the optimization is unnecessary
300 (and unwise - we don't want to change where gdb thinks the TU lives
302 This flag is only valid if is_debug_types is true. */
303 unsigned int tu_read
: 1;
305 /* The section this CU/TU lives in.
306 If the DIE refers to a DWO file, this is always the original die,
308 struct dwarf2_section_info
*section
;
310 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
311 of the CU cache it gets reset to NULL again. This is left as NULL for
312 dummy CUs (a CU header, but nothing else). */
313 struct dwarf2_cu
*cu
;
315 /* The corresponding dwarf2_per_objfile. */
316 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
318 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
319 is active. Otherwise, the 'psymtab' field is active. */
322 /* The partial symbol table associated with this compilation unit,
323 or NULL for unread partial units. */
324 struct partial_symtab
*psymtab
;
326 /* Data needed by the "quick" functions. */
327 struct dwarf2_per_cu_quick_data
*quick
;
330 /* The CUs we import using DW_TAG_imported_unit. This is filled in
331 while reading psymtabs, used to compute the psymtab dependencies,
332 and then cleared. Then it is filled in again while reading full
333 symbols, and only deleted when the objfile is destroyed.
335 This is also used to work around a difference between the way gold
336 generates .gdb_index version <=7 and the way gdb does. Arguably this
337 is a gold bug. For symbols coming from TUs, gold records in the index
338 the CU that includes the TU instead of the TU itself. This breaks
339 dw2_lookup_symbol: It assumes that if the index says symbol X lives
340 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
341 will find X. Alas TUs live in their own symtab, so after expanding CU Y
342 we need to look in TU Z to find X. Fortunately, this is akin to
343 DW_TAG_imported_unit, so we just use the same mechanism: For
344 .gdb_index version <=7 this also records the TUs that the CU referred
345 to. Concurrently with this change gdb was modified to emit version 8
346 indices so we only pay a price for gold generated indices.
347 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
348 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
351 /* Entry in the signatured_types hash table. */
353 struct signatured_type
355 /* The "per_cu" object of this type.
356 This struct is used iff per_cu.is_debug_types.
357 N.B.: This is the first member so that it's easy to convert pointers
359 struct dwarf2_per_cu_data per_cu
;
361 /* The type's signature. */
364 /* Offset in the TU of the type's DIE, as read from the TU header.
365 If this TU is a DWO stub and the definition lives in a DWO file
366 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
367 cu_offset type_offset_in_tu
;
369 /* Offset in the section of the type's DIE.
370 If the definition lives in a DWO file, this is the offset in the
371 .debug_types.dwo section.
372 The value is zero until the actual value is known.
373 Zero is otherwise not a valid section offset. */
374 sect_offset type_offset_in_section
;
376 /* Type units are grouped by their DW_AT_stmt_list entry so that they
377 can share them. This points to the containing symtab. */
378 struct type_unit_group
*type_unit_group
;
381 The first time we encounter this type we fully read it in and install it
382 in the symbol tables. Subsequent times we only need the type. */
385 /* Containing DWO unit.
386 This field is valid iff per_cu.reading_dwo_directly. */
387 struct dwo_unit
*dwo_unit
;
390 typedef struct signatured_type
*sig_type_ptr
;
391 DEF_VEC_P (sig_type_ptr
);
393 #endif /* DWARF2READ_H */