]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/dwarf2/read.h
Replace dwarf2_per_cu_data::cu backlink with per-objfile map
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / read.h
CommitLineData
cd4fb1b2
SM
1/* DWARF 2 debugging format support for GDB.
2
b811d2c2 3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
cd4fb1b2
SM
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
39856def 23#include <queue>
e4a62c65 24#include <unordered_map>
2e6a9f79 25#include "dwarf2/comp-unit.h"
82ca8957 26#include "dwarf2/index-cache.h"
2c86cff9 27#include "dwarf2/section.h"
cd4fb1b2
SM
28#include "filename-seen-cache.h"
29#include "gdb_obstack.h"
268a13a5 30#include "gdbsupport/hash_enum.h"
891813be 31#include "psympriv.h"
cd4fb1b2 32
3c3bb058
AB
33/* Hold 'maintenance (set|show) dwarf' commands. */
34extern struct cmd_list_element *set_dwarf_cmdlist;
35extern struct cmd_list_element *show_dwarf_cmdlist;
36
cd4fb1b2
SM
37struct tu_stats
38{
39 int nr_uniq_abbrev_tables;
40 int nr_symtabs;
41 int nr_symtab_sharers;
42 int nr_stmt_less_type_units;
43 int nr_all_type_units_reallocs;
44};
45
7188ed02 46struct dwarf2_cu;
cd4fb1b2 47struct dwarf2_debug_sections;
39856def 48struct dwarf2_per_cu_data;
cd4fb1b2
SM
49struct mapped_index;
50struct mapped_debug_names;
ff4c9fec 51struct signatured_type;
8adb8487 52struct type_unit_group;
cd4fb1b2 53
39856def
TT
54/* One item on the queue of compilation units to read in full symbols
55 for. */
56struct dwarf2_queue_item
57{
120ce1b5
SM
58 dwarf2_queue_item (dwarf2_per_cu_data *cu, dwarf2_per_objfile *per_objfile,
59 enum language lang)
39856def 60 : per_cu (cu),
120ce1b5 61 per_objfile (per_objfile),
39856def
TT
62 pretend_language (lang)
63 {
64 }
65
66 ~dwarf2_queue_item ();
67
68 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_item);
69
120ce1b5
SM
70 dwarf2_per_cu_data *per_cu;
71 dwarf2_per_objfile *per_objfile;
39856def
TT
72 enum language pretend_language;
73};
74
5989a64e
SM
75/* Some DWARF data can be shared across objfiles who share the same BFD,
76 this data is stored in this object.
cd4fb1b2 77
5989a64e
SM
78 Two dwarf2_per_objfile objects representing objfiles sharing the same BFD
79 will point to the same instance of dwarf2_per_bfd, unless the BFD requires
80 relocation. */
81
82struct dwarf2_per_bfd
cd4fb1b2 83{
5989a64e 84 /* Construct a dwarf2_per_bfd for OBFD. NAMES points to the
cd4fb1b2 85 dwarf2 section names, or is NULL if the standard ELF names are
4b610737
TT
86 used. CAN_COPY is true for formats where symbol
87 interposition is possible and so symbol values must follow copy
88 relocation rules. */
5989a64e 89 dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names, bool can_copy);
cd4fb1b2 90
5989a64e 91 ~dwarf2_per_bfd ();
cd4fb1b2 92
5989a64e 93 DISABLE_COPY_AND_ASSIGN (dwarf2_per_bfd);
cd4fb1b2 94
ff4c9fec
SM
95 /* Return the CU/TU given its index.
96
97 This is intended for loops like:
98
5989a64e
SM
99 for (i = 0; i < (dwarf2_per_bfd->n_comp_units
100 + dwarf2_per_bfd->n_type_units); ++i)
ff4c9fec 101 {
5989a64e 102 dwarf2_per_cu_data *per_cu = dwarf2_per_bfd->get_cutu (i);
ff4c9fec
SM
103
104 ...;
105 }
106 */
107 dwarf2_per_cu_data *get_cutu (int index);
108
109 /* Return the CU given its index.
110 This differs from get_cutu in that it's for when you know INDEX refers to a
111 CU. */
112 dwarf2_per_cu_data *get_cu (int index);
113
114 /* Return the TU given its index.
115 This differs from get_cutu in that it's for when you know INDEX refers to a
116 TU. */
117 signatured_type *get_tu (int index);
118
d3473f0c
TT
119 /* A convenience function to allocate a dwarf2_per_cu_data. The
120 returned object has its "index" field set properly. The object
5989a64e 121 is allocated on the dwarf2_per_bfd obstack. */
d3473f0c
TT
122 dwarf2_per_cu_data *allocate_per_cu ();
123
124 /* A convenience function to allocate a signatured_type. The
125 returned object has its "index" field set properly. The object
5989a64e 126 is allocated on the dwarf2_per_bfd obstack. */
d3473f0c
TT
127 signatured_type *allocate_signatured_type ();
128
af758d11
SM
129 /* Return the number of partial symtabs allocated with allocate_per_cu
130 and allocate_signatured_type so far. */
131 int num_psymtabs () const
132 { return m_num_psymtabs; }
133
cd4fb1b2
SM
134private:
135 /* This function is mapped across the sections and remembers the
136 offset and size of each of the debugging sections we are
137 interested in. */
138 void locate_sections (bfd *abfd, asection *sectp,
139 const dwarf2_debug_sections &names);
140
141public:
c3699833
SM
142 /* The corresponding BFD. */
143 bfd *obfd;
144
45940949
TT
145 /* Objects that can be shared across objfiles are stored in this
146 obstack or on the psymtab obstack, while objects that are
147 objfile-specific are stored on the objfile obstack. */
148 auto_obstack obstack;
149
cd4fb1b2
SM
150 dwarf2_section_info info {};
151 dwarf2_section_info abbrev {};
152 dwarf2_section_info line {};
153 dwarf2_section_info loc {};
154 dwarf2_section_info loclists {};
155 dwarf2_section_info macinfo {};
156 dwarf2_section_info macro {};
157 dwarf2_section_info str {};
18a8505e 158 dwarf2_section_info str_offsets {};
cd4fb1b2
SM
159 dwarf2_section_info line_str {};
160 dwarf2_section_info ranges {};
161 dwarf2_section_info rnglists {};
162 dwarf2_section_info addr {};
163 dwarf2_section_info frame {};
164 dwarf2_section_info eh_frame {};
165 dwarf2_section_info gdb_index {};
166 dwarf2_section_info debug_names {};
167 dwarf2_section_info debug_aranges {};
168
fd5866f6 169 std::vector<dwarf2_section_info> types;
cd4fb1b2 170
cd4fb1b2
SM
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. */
eaa5fa8b 180 htab_up type_unit_groups;
cd4fb1b2
SM
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. */
b0b6a987 184 htab_up signatured_types;
cd4fb1b2
SM
185
186 /* Type unit statistics, to see how well the scaling improvements
187 are doing. */
188 struct tu_stats tu_stats {};
189
cd4fb1b2
SM
190 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
191 This is NULL if the table hasn't been allocated yet. */
51ac9db5 192 htab_up dwo_files;
cd4fb1b2
SM
193
194 /* True if we've checked for whether there is a DWP file. */
195 bool dwp_checked = false;
196
197 /* The DWP file if there is one, or NULL. */
400174b1 198 std::unique_ptr<struct dwp_file> dwp_file;
cd4fb1b2
SM
199
200 /* The shared '.dwz' file, if one exists. This is used when the
201 original data was compressed using 'dwz -m'. */
7ff8cb8c 202 std::unique_ptr<struct dwz_file> dwz_file;
cd4fb1b2 203
4b610737
TT
204 /* Whether copy relocations are supported by this object format. */
205 bool can_copy;
206
cd4fb1b2
SM
207 /* A flag indicating whether this objfile has a section loaded at a
208 VMA of 0. */
209 bool has_section_at_zero = false;
210
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;
214
215 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
3063847f 216 std::unique_ptr<mapped_index> index_table;
cd4fb1b2
SM
217
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;
220
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. */
5895093f 228 htab_up quick_file_names_table;
cd4fb1b2
SM
229
230 /* Set during partial symbol reading, to prevent queueing of full
231 symbols. */
232 bool reading_partial_symbols = false;
233
cd4fb1b2 234 /* The CUs we recently read. */
c5d0225d 235 std::vector<dwarf2_per_cu_data *> just_read_cus;
cd4fb1b2
SM
236
237 /* Table containing line_header indexed by offset and offset_in_dwz. */
d15acc42 238 htab_up line_header_hash;
cd4fb1b2
SM
239
240 /* Table containing all filenames. This is an optional because the
241 table is lazily constructed on first access. */
242 gdb::optional<filename_seen_cache> filenames_cache;
87d6a7aa
SM
243
244 /* If we loaded the index from an external file, this contains the
245 resources associated to the open file, memory mapping, etc. */
246 std::unique_ptr<index_cache_resource> index_cache_res;
e4a62c65
TV
247
248 /* Mapping from abstract origin DIE to concrete DIEs that reference it as
249 DW_AT_abstract_origin. */
fad03f6e
TT
250 std::unordered_map<sect_offset, std::vector<sect_offset>,
251 gdb::hash_enum<sect_offset>>
e4a62c65 252 abstract_to_concrete;
39856def
TT
253
254 /* CUs that are queued to be read. */
255 std::queue<dwarf2_queue_item> queue;
d3473f0c
TT
256
257private:
258
259 /* The total number of per_cu and signatured_type objects that have
260 been created so far for this reader. */
261 size_t m_num_psymtabs = 0;
cd4fb1b2
SM
262};
263
8adb8487
TT
264/* This is the per-objfile data associated with a type_unit_group. */
265
266struct type_unit_group_unshareable
267{
268 /* The compunit symtab.
269 Type units in a group needn't all be defined in the same source file,
270 so we create an essentially anonymous symtab as the compunit symtab. */
271 struct compunit_symtab *compunit_symtab = nullptr;
272
273 /* The number of symtabs from the line header.
274 The value here must match line_header.num_file_names. */
275 unsigned int num_symtabs = 0;
276
277 /* The symbol tables for this TU (obtained from the files listed in
278 DW_AT_stmt_list).
279 WARNING: The order of entries here must match the order of entries
280 in the line header. After the first TU using this type_unit_group, the
281 line header for the subsequent TUs is recreated from this. This is done
282 because we need to use the same symtabs for each TU using the same
283 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
284 there's no guarantee the line header doesn't have duplicate entries. */
285 struct symtab **symtabs = nullptr;
286};
287
5989a64e
SM
288/* Collection of data recorded per objfile.
289 This hangs off of dwarf2_objfile_data_key.
290
291 Some DWARF data cannot (currently) be shared across objfiles. Such
292 data is stored in this object. */
293
294struct dwarf2_per_objfile
295{
296 dwarf2_per_objfile (struct objfile *objfile, dwarf2_per_bfd *per_bfd)
297 : objfile (objfile), per_bfd (per_bfd)
298 {}
299
7188ed02
SM
300 ~dwarf2_per_objfile ();
301
5989a64e
SM
302 /* Return pointer to string at .debug_line_str offset as read from BUF.
303 BUF is assumed to be in a compilation unit described by CU_HEADER.
304 Return *BYTES_READ_PTR count of bytes read from BUF. */
305 const char *read_line_string (const gdb_byte *buf,
306 const struct comp_unit_head *cu_header,
307 unsigned int *bytes_read_ptr);
308
af758d11
SM
309 /* Resize the M_SYMTABS vector to the needed size (the number of partial
310 symtabs allocated by the per-bfd). */
311 void resize_symtabs ()
312 {
313 /* The symtabs vector should only grow, not shrink. */
314 gdb_assert (per_bfd->num_psymtabs () >= m_symtabs.size ());
315
316 m_symtabs.resize (per_bfd->num_psymtabs ());
317 }
318
319 /* Return true if the symtab corresponding to PER_CU has been set,
320 false otherwise. */
321 bool symtab_set_p (const dwarf2_per_cu_data *per_cu) const;
322
323 /* Return the compunit_symtab associated to PER_CU, if it has been created. */
324 compunit_symtab *get_symtab (const dwarf2_per_cu_data *per_cu) const;
325
326 /* Set the compunit_symtab associated to PER_CU. */
327 void set_symtab (const dwarf2_per_cu_data *per_cu, compunit_symtab *symtab);
328
e286671b
TT
329 /* Get the type_unit_group_unshareable corresponding to TU_GROUP. If one
330 does not exist, create it. */
8adb8487
TT
331 type_unit_group_unshareable *get_type_unit_group_unshareable
332 (type_unit_group *tu_group);
333
e286671b
TT
334 struct type *get_type_for_signatured_type (signatured_type *sig_type) const;
335
336 void set_type_for_signatured_type (signatured_type *sig_type,
337 struct type *type);
338
293e7e51
SM
339 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
340 UNSIGNED_P controls if the integer is unsigned or not. */
341 struct type *int_type (int size_in_bytes, bool unsigned_p) const;
342
7188ed02
SM
343 /* Get the dwarf2_cu matching PER_CU for this objfile. */
344 dwarf2_cu *get_cu (dwarf2_per_cu_data *per_cu);
345
346 /* Set the dwarf2_cu matching PER_CU for this objfile. */
347 void set_cu (dwarf2_per_cu_data *per_cu, dwarf2_cu *cu);
348
349 /* Remove/free the dwarf2_cu matching PER_CU for this objfile. */
350 void remove_cu (dwarf2_per_cu_data *per_cu);
351
352 /* Free all cached compilation units. */
353 void remove_all_cus ();
354
355 /* Increase the age counter on each CU compilation unit and free
356 any that are too old. */
357 void age_comp_units ();
358
5989a64e
SM
359 /* Back link. */
360 struct objfile *objfile;
361
362 /* Pointer to the data that is (possibly) shared between this objfile and
363 other objfiles backed by the same BFD. */
364 struct dwarf2_per_bfd *per_bfd;
af758d11 365
ae090bdb
SM
366 /* Table mapping type DIEs to their struct type *.
367 This is nullptr if not allocated yet.
368 The mapping is done via (CU/TU + DIE offset) -> type. */
369 htab_up die_type_hash;
370
af758d11
SM
371private:
372 /* Hold the corresponding compunit_symtab for each CU or TU. This
373 is indexed by dwarf2_per_cu_data::index. A NULL value means
374 that the CU/TU has not been expanded yet. */
375 std::vector<compunit_symtab *> m_symtabs;
8adb8487
TT
376
377 /* Map from a type unit group to the corresponding unshared
378 structure. */
379 typedef std::unique_ptr<type_unit_group_unshareable>
380 type_unit_group_unshareable_up;
381
382 std::unordered_map<type_unit_group *, type_unit_group_unshareable_up>
383 m_type_units;
e286671b
TT
384
385 /* Map from signatured types to the corresponding struct type. */
386 std::unordered_map<signatured_type *, struct type *> m_type_map;
7188ed02
SM
387
388 /* Map from the objfile-independent dwarf2_per_cu_data instances to the
389 corresponding objfile-dependent dwarf2_cu instances. */
390 std::unordered_map<dwarf2_per_cu_data *, dwarf2_cu *> m_dwarf2_cus;
5989a64e
SM
391};
392
cd4fb1b2
SM
393/* Get the dwarf2_per_objfile associated to OBJFILE. */
394
395dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
396
891813be 397/* A partial symtab specialized for DWARF. */
af758d11 398struct dwarf2_psymtab : public partial_symtab
891813be 399{
891813be 400 dwarf2_psymtab (const char *filename, struct objfile *objfile,
9f4e76a4 401 dwarf2_per_cu_data *per_cu)
af758d11 402 : partial_symtab (filename, objfile, 0),
9f4e76a4 403 per_cu_data (per_cu)
891813be
TT
404 {
405 }
406
407 void read_symtab (struct objfile *) override;
8566b89b 408 void expand_psymtab (struct objfile *) override;
af758d11
SM
409 bool readin_p (struct objfile *) const override;
410 compunit_symtab *get_compunit_symtab (struct objfile *) const override;
891813be
TT
411
412 struct dwarf2_per_cu_data *per_cu_data;
413};
414
cd4fb1b2
SM
415/* Persistent data held for a compilation unit, even when not
416 processing it. We put a pointer to this structure in the
891813be 417 psymtab. */
cd4fb1b2
SM
418
419struct dwarf2_per_cu_data
420{
421 /* The start offset and length of this compilation unit.
422 NOTE: Unlike comp_unit_head.length, this length includes
423 initial_length_size.
424 If the DIE refers to a DWO file, this is always of the original die,
425 not the DWO file. */
426 sect_offset sect_off;
427 unsigned int length;
428
429 /* DWARF standard version this data has been read from (such as 4 or 5). */
430 short dwarf_version;
431
432 /* Flag indicating this compilation unit will be read in before
433 any of the current compilation units are processed. */
434 unsigned int queued : 1;
435
436 /* This flag will be set when reading partial DIEs if we need to load
437 absolutely all DIEs for this compilation unit, instead of just the ones
438 we think are interesting. It gets set if we look for a DIE in the
439 hash table and don't find it. */
440 unsigned int load_all_dies : 1;
441
442 /* Non-zero if this CU is from .debug_types.
443 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
444 this is non-zero. */
445 unsigned int is_debug_types : 1;
446
447 /* Non-zero if this CU is from the .dwz file. */
448 unsigned int is_dwz : 1;
449
450 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
451 This flag is only valid if is_debug_types is true.
452 We can't read a CU directly from a DWO file: There are required
453 attributes in the stub. */
454 unsigned int reading_dwo_directly : 1;
455
456 /* Non-zero if the TU has been read.
457 This is used to assist the "Stay in DWO Optimization" for Fission:
458 When reading a DWO, it's faster to read TUs from the DWO instead of
459 fetching them from random other DWOs (due to comdat folding).
460 If the TU has already been read, the optimization is unnecessary
461 (and unwise - we don't want to change where gdb thinks the TU lives
462 "midflight").
463 This flag is only valid if is_debug_types is true. */
464 unsigned int tu_read : 1;
465
d3473f0c
TT
466 /* Our index in the unshared "symtabs" vector. */
467 unsigned index;
468
cd4fb1b2
SM
469 /* The section this CU/TU lives in.
470 If the DIE refers to a DWO file, this is always the original die,
471 not the DWO file. */
472 struct dwarf2_section_info *section;
473
58990295
TV
474 /* The unit type of this CU. */
475 enum dwarf_unit_type unit_type;
476
477 /* The language of this CU. */
478 enum language lang;
479
1859c670
SM
480 /* Backlink to the owner of this. */
481 dwarf2_per_bfd *per_bfd;
482
2e6a9f79
SM
483 /* DWARF header of this CU. Note that dwarf2_cu reads its own version of the
484 header, which may differ from this one, since it may pass rcuh_kind::TYPE
485 to read_comp_unit_head, whereas for dwarf2_per_cu_data we always pass
486 rcuh_kind::COMPILE.
487
488 Don't access this field directly, use the get_header method instead. It
489 should be private, but we can't make it private at the moment. */
490 mutable comp_unit_head m_header;
491
492 /* True if HEADER has been read in.
493
494 Don't access this field directly. It should be private, but we can't make
495 it private at the moment. */
496 mutable bool m_header_read_in;
497
5989a64e 498 /* When dwarf2_per_bfd::using_index is true, the 'quick' field
cd4fb1b2
SM
499 is active. Otherwise, the 'psymtab' field is active. */
500 union
501 {
502 /* The partial symbol table associated with this compilation unit,
503 or NULL for unread partial units. */
891813be 504 dwarf2_psymtab *psymtab;
cd4fb1b2
SM
505
506 /* Data needed by the "quick" functions. */
507 struct dwarf2_per_cu_quick_data *quick;
508 } v;
509
96c738c0
TT
510 /* The CUs we import using DW_TAG_imported_unit. This is filled in
511 while reading psymtabs, used to compute the psymtab dependencies,
512 and then cleared. Then it is filled in again while reading full
513 symbols, and only deleted when the objfile is destroyed.
514
515 This is also used to work around a difference between the way gold
516 generates .gdb_index version <=7 and the way gdb does. Arguably this
517 is a gold bug. For symbols coming from TUs, gold records in the index
518 the CU that includes the TU instead of the TU itself. This breaks
519 dw2_lookup_symbol: It assumes that if the index says symbol X lives
520 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
521 will find X. Alas TUs live in their own symtab, so after expanding CU Y
522 we need to look in TU Z to find X. Fortunately, this is akin to
523 DW_TAG_imported_unit, so we just use the same mechanism: For
524 .gdb_index version <=7 this also records the TUs that the CU referred
525 to. Concurrently with this change gdb was modified to emit version 8
526 indices so we only pay a price for gold generated indices.
527 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
528
529 This currently needs to be a public member due to how
530 dwarf2_per_cu_data is allocated and used. Ideally in future things
531 could be refactored to make this private. Until then please try to
532 avoid direct access to this member, and instead use the helper
533 functions above. */
534 std::vector <dwarf2_per_cu_data *> *imported_symtabs;
535
ae640021
AB
536 /* Return true of IMPORTED_SYMTABS is empty or not yet allocated. */
537 bool imported_symtabs_empty () const
538 {
539 return (imported_symtabs == nullptr || imported_symtabs->empty ());
540 }
541
542 /* Push P to the back of IMPORTED_SYMTABS, allocated IMPORTED_SYMTABS
543 first if required. */
544 void imported_symtabs_push (dwarf2_per_cu_data *p)
545 {
546 if (imported_symtabs == nullptr)
547 imported_symtabs = new std::vector <dwarf2_per_cu_data *>;
548 imported_symtabs->push_back (p);
549 }
550
551 /* Return the size of IMPORTED_SYMTABS if it is allocated, otherwise
552 return 0. */
553 size_t imported_symtabs_size () const
554 {
555 if (imported_symtabs == nullptr)
556 return 0;
557 return imported_symtabs->size ();
558 }
559
560 /* Delete IMPORTED_SYMTABS and set the pointer back to nullptr. */
561 void imported_symtabs_free ()
562 {
563 delete imported_symtabs;
564 imported_symtabs = nullptr;
565 }
09ba997f 566
2e6a9f79
SM
567 /* Get the header of this per_cu, reading it if necessary. */
568 const comp_unit_head *get_header () const;
569
09ba997f
TT
570 /* Return the address size given in the compilation unit header for
571 this CU. */
572 int addr_size () const;
573
574 /* Return the offset size given in the compilation unit header for
575 this CU. */
576 int offset_size () const;
577
578 /* Return the DW_FORM_ref_addr size given in the compilation unit
579 header for this CU. */
580 int ref_addr_size () const;
581
09ba997f
TT
582 /* Return DWARF version number of this CU. */
583 short version () const
584 {
585 return dwarf_version;
586 }
197400e8
TT
587
588 /* A type unit group has a per_cu object that is recognized by
589 having no section. */
590 bool type_unit_group_p () const
591 {
592 return section == nullptr;
593 }
cd4fb1b2
SM
594};
595
596/* Entry in the signatured_types hash table. */
597
598struct signatured_type
599{
600 /* The "per_cu" object of this type.
601 This struct is used iff per_cu.is_debug_types.
602 N.B.: This is the first member so that it's easy to convert pointers
603 between them. */
604 struct dwarf2_per_cu_data per_cu;
605
606 /* The type's signature. */
607 ULONGEST signature;
608
609 /* Offset in the TU of the type's DIE, as read from the TU header.
610 If this TU is a DWO stub and the definition lives in a DWO file
611 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
612 cu_offset type_offset_in_tu;
613
614 /* Offset in the section of the type's DIE.
615 If the definition lives in a DWO file, this is the offset in the
616 .debug_types.dwo section.
617 The value is zero until the actual value is known.
618 Zero is otherwise not a valid section offset. */
619 sect_offset type_offset_in_section;
620
621 /* Type units are grouped by their DW_AT_stmt_list entry so that they
622 can share them. This points to the containing symtab. */
623 struct type_unit_group *type_unit_group;
624
cd4fb1b2
SM
625 /* Containing DWO unit.
626 This field is valid iff per_cu.reading_dwo_directly. */
627 struct dwo_unit *dwo_unit;
628};
629
c4973306
SM
630/* Open the separate '.dwz' debug file, if needed. Return NULL if
631 there is no .gnu_debugaltlink section in the file. Error if there
632 is such a section but the file cannot be found. */
633
c3699833 634extern dwz_file *dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd);
c4973306 635
8cb5117c
SM
636/* Return the type of the DIE at DIE_OFFSET in the CU named by
637 PER_CU. */
638
639struct type *dwarf2_get_die_type (cu_offset die_offset,
aa66c379
SM
640 dwarf2_per_cu_data *per_cu,
641 dwarf2_per_objfile *per_objfile);
8cb5117c 642
450a1bfc
SM
643/* Given an index in .debug_addr, fetch the value.
644 NOTE: This can be called during dwarf expression evaluation,
645 long after the debug information has been read, and thus per_cu->cu
646 may no longer exist. */
647
648CORE_ADDR dwarf2_read_addr_index (dwarf2_per_cu_data *per_cu,
82ca3f51 649 dwarf2_per_objfile *dwarf2_per_objfile,
450a1bfc
SM
650 unsigned int addr_index);
651
d4c9a4f8
SM
652/* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
653 Returned value is intended for DW_OP_call*. Returned
654 dwarf2_locexpr_baton->data has lifetime of
655 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
656
657struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_sect_off
658 (sect_offset sect_off, dwarf2_per_cu_data *per_cu,
14095eb3 659 dwarf2_per_objfile *per_objfile,
d4c9a4f8
SM
660 CORE_ADDR (*get_frame_pc) (void *baton),
661 void *baton, bool resolve_abstract_p = false);
662
663/* Like dwarf2_fetch_die_loc_sect_off, but take a CU
664 offset. */
665
666struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_cu_off
667 (cu_offset offset_in_cu, dwarf2_per_cu_data *per_cu,
14095eb3 668 dwarf2_per_objfile *per_objfile,
d4c9a4f8
SM
669 CORE_ADDR (*get_frame_pc) (void *baton),
670 void *baton);
671
672/* If the DIE at SECT_OFF in PER_CU has a DW_AT_const_value, return a
673 pointer to the constant bytes and set LEN to the length of the
674 data. If memory is needed, allocate it on OBSTACK. If the DIE
675 does not have a DW_AT_const_value, return NULL. */
676
677extern const gdb_byte *dwarf2_fetch_constant_bytes
14095eb3
SM
678 (sect_offset sect_off, dwarf2_per_cu_data *per_cu,
679 dwarf2_per_objfile *per_objfile, obstack *obstack,
d4c9a4f8
SM
680 LONGEST *len);
681
682/* Return the type of the die at SECT_OFF in PER_CU. Return NULL if no
683 valid type for this die is found. */
684
685struct type *dwarf2_fetch_die_type_sect_off
14095eb3
SM
686 (sect_offset sect_off, dwarf2_per_cu_data *per_cu,
687 dwarf2_per_objfile *per_objfile);
d4c9a4f8 688
8fdd972c
TT
689/* When non-zero, dump line number entries as they are read in. */
690extern unsigned int dwarf_line_debug;
691
cd4fb1b2 692#endif /* DWARF2READ_H */