1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit-head.h"
36 #include "dwarf2/cu.h"
37 #include "dwarf2/index-cache.h"
38 #include "dwarf2/index-common.h"
39 #include "dwarf2/leb.h"
40 #include "dwarf2/line-header.h"
41 #include "dwarf2/dwz.h"
42 #include "dwarf2/macro.h"
43 #include "dwarf2/die.h"
44 #include "dwarf2/sect-names.h"
45 #include "dwarf2/stringify.h"
46 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
91 #include <unordered_set>
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
100 #define dwarf_read_debug_printf(fmt, ...) \
101 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
106 #define dwarf_read_debug_printf_v(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
110 /* When non-zero, dump DIEs after they are read in. */
111 static unsigned int dwarf_die_debug
= 0;
113 /* When non-zero, dump line number entries as they are read in. */
114 unsigned int dwarf_line_debug
= 0;
116 /* When true, cross-check physname against demangler. */
117 static bool check_physname
= false;
119 /* When true, do not reject deprecated .gdb_index sections. */
120 static bool use_deprecated_index_sections
= false;
122 /* This is used to store the data that is always per objfile. */
123 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
125 /* These are used to store the dwarf2_per_bfd objects.
127 objfiles having the same BFD, which doesn't require relocations, are going to
128 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
130 Other objfiles are not going to share a dwarf2_per_bfd with any other
131 objfiles, so they'll have their own version kept in the _objfile_data_key
133 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
134 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
136 /* The "aclass" indices for various kinds of computed DWARF symbols. */
138 static int dwarf2_locexpr_index
;
139 static int dwarf2_loclist_index
;
140 static int dwarf2_locexpr_block_index
;
141 static int dwarf2_loclist_block_index
;
143 /* Size of .debug_loclists section header for 32-bit DWARF format. */
144 #define LOCLIST_HEADER_SIZE32 12
146 /* Size of .debug_loclists section header for 64-bit DWARF format. */
147 #define LOCLIST_HEADER_SIZE64 20
149 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
150 #define RNGLIST_HEADER_SIZE32 12
152 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
153 #define RNGLIST_HEADER_SIZE64 20
155 /* An index into a (C++) symbol name component in a symbol name as
156 recorded in the mapped_index's symbol table. For each C++ symbol
157 in the symbol table, we record one entry for the start of each
158 component in the symbol in a table of name components, and then
159 sort the table, in order to be able to binary search symbol names,
160 ignoring leading namespaces, both completion and regular look up.
161 For example, for symbol "A::B::C", we'll have an entry that points
162 to "A::B::C", another that points to "B::C", and another for "C".
163 Note that function symbols in GDB index have no parameter
164 information, just the function/method names. You can convert a
165 name_component to a "const char *" using the
166 'mapped_index::symbol_name_at(offset_type)' method. */
168 struct name_component
170 /* Offset in the symbol name where the component starts. Stored as
171 a (32-bit) offset instead of a pointer to save memory and improve
172 locality on 64-bit architectures. */
173 offset_type name_offset
;
175 /* The symbol's index in the symbol and constant pool tables of a
180 /* Base class containing bits shared by both .gdb_index and
181 .debug_name indexes. */
183 struct mapped_index_base
185 mapped_index_base () = default;
186 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
188 /* The name_component table (a sorted vector). See name_component's
189 description above. */
190 std::vector
<name_component
> name_components
;
192 /* How NAME_COMPONENTS is sorted. */
193 enum case_sensitivity name_components_casing
;
195 /* Return the number of names in the symbol table. */
196 virtual size_t symbol_name_count () const = 0;
198 /* Get the name of the symbol at IDX in the symbol table. */
199 virtual const char *symbol_name_at
200 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
202 /* Return whether the name at IDX in the symbol table should be
204 virtual bool symbol_name_slot_invalid (offset_type idx
) const
209 /* Build the symbol name component sorted vector, if we haven't
211 void build_name_components (dwarf2_per_objfile
*per_objfile
);
213 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
214 possible matches for LN_NO_PARAMS in the name component
216 std::pair
<std::vector
<name_component
>::const_iterator
,
217 std::vector
<name_component
>::const_iterator
>
218 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
220 dwarf2_per_objfile
*per_objfile
) const;
222 /* Prevent deleting/destroying via a base class pointer. */
224 ~mapped_index_base() = default;
227 /* This is a view into the index that converts from bytes to an
228 offset_type, and allows indexing. Unaligned bytes are specifically
229 allowed here, and handled via unpacking. */
234 offset_view () = default;
236 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
241 /* Extract the INDEXth offset_type from the array. */
242 offset_type
operator[] (size_t index
) const
244 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
245 return (offset_type
) extract_unsigned_integer (bytes
,
246 sizeof (offset_type
),
250 /* Return the number of offset_types in this array. */
253 return m_bytes
.size () / sizeof (offset_type
);
256 /* Return true if this view is empty. */
259 return m_bytes
.empty ();
263 /* The underlying bytes. */
264 gdb::array_view
<const gdb_byte
> m_bytes
;
267 /* A description of the mapped index. The file format is described in
268 a comment by the code that writes the index. */
269 struct mapped_index final
: public mapped_index_base
271 /* Index data format version. */
274 /* The address table data. */
275 gdb::array_view
<const gdb_byte
> address_table
;
277 /* The symbol table, implemented as a hash table. */
278 offset_view symbol_table
;
280 /* A pointer to the constant pool. */
281 gdb::array_view
<const gdb_byte
> constant_pool
;
283 /* Return the index into the constant pool of the name of the IDXth
284 symbol in the symbol table. */
285 offset_type
symbol_name_index (offset_type idx
) const
287 return symbol_table
[2 * idx
];
290 /* Return the index into the constant pool of the CU vector of the
291 IDXth symbol in the symbol table. */
292 offset_type
symbol_vec_index (offset_type idx
) const
294 return symbol_table
[2 * idx
+ 1];
297 bool symbol_name_slot_invalid (offset_type idx
) const override
299 return (symbol_name_index (idx
) == 0
300 && symbol_vec_index (idx
) == 0);
303 /* Convenience method to get at the name of the symbol at IDX in the
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 return (const char *) (this->constant_pool
.data ()
309 + symbol_name_index (idx
));
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size () / 2; }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 bfd_endian dwarf5_byte_order
;
321 bool dwarf5_is_dwarf64
;
322 bool augmentation_is_gdb
;
324 uint32_t cu_count
= 0;
325 uint32_t tu_count
, bucket_count
, name_count
;
326 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
327 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
328 const gdb_byte
*name_table_string_offs_reordered
;
329 const gdb_byte
*name_table_entry_offs_reordered
;
330 const gdb_byte
*entry_pool
;
337 /* Attribute name DW_IDX_*. */
340 /* Attribute form DW_FORM_*. */
343 /* Value if FORM is DW_FORM_implicit_const. */
344 LONGEST implicit_const
;
346 std::vector
<attr
> attr_vec
;
349 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
351 const char *namei_to_name
352 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
354 /* Implementation of the mapped_index_base virtual interface, for
355 the name_components cache. */
357 const char *symbol_name_at
358 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
359 { return namei_to_name (idx
, per_objfile
); }
361 size_t symbol_name_count () const override
362 { return this->name_count
; }
365 /* See dwarf2read.h. */
368 get_dwarf2_per_objfile (struct objfile
*objfile
)
370 return dwarf2_objfile_data_key
.get (objfile
);
373 /* Default names of the debugging sections. */
375 /* Note that if the debugging section has been compressed, it might
376 have a name like .zdebug_info. */
378 const struct dwarf2_debug_sections dwarf2_elf_names
=
380 { ".debug_info", ".zdebug_info" },
381 { ".debug_abbrev", ".zdebug_abbrev" },
382 { ".debug_line", ".zdebug_line" },
383 { ".debug_loc", ".zdebug_loc" },
384 { ".debug_loclists", ".zdebug_loclists" },
385 { ".debug_macinfo", ".zdebug_macinfo" },
386 { ".debug_macro", ".zdebug_macro" },
387 { ".debug_str", ".zdebug_str" },
388 { ".debug_str_offsets", ".zdebug_str_offsets" },
389 { ".debug_line_str", ".zdebug_line_str" },
390 { ".debug_ranges", ".zdebug_ranges" },
391 { ".debug_rnglists", ".zdebug_rnglists" },
392 { ".debug_types", ".zdebug_types" },
393 { ".debug_addr", ".zdebug_addr" },
394 { ".debug_frame", ".zdebug_frame" },
395 { ".eh_frame", NULL
},
396 { ".gdb_index", ".zgdb_index" },
397 { ".debug_names", ".zdebug_names" },
398 { ".debug_aranges", ".zdebug_aranges" },
402 /* List of DWO/DWP sections. */
404 static const struct dwop_section_names
406 struct dwarf2_section_names abbrev_dwo
;
407 struct dwarf2_section_names info_dwo
;
408 struct dwarf2_section_names line_dwo
;
409 struct dwarf2_section_names loc_dwo
;
410 struct dwarf2_section_names loclists_dwo
;
411 struct dwarf2_section_names macinfo_dwo
;
412 struct dwarf2_section_names macro_dwo
;
413 struct dwarf2_section_names rnglists_dwo
;
414 struct dwarf2_section_names str_dwo
;
415 struct dwarf2_section_names str_offsets_dwo
;
416 struct dwarf2_section_names types_dwo
;
417 struct dwarf2_section_names cu_index
;
418 struct dwarf2_section_names tu_index
;
422 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
423 { ".debug_info.dwo", ".zdebug_info.dwo" },
424 { ".debug_line.dwo", ".zdebug_line.dwo" },
425 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
426 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
427 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
428 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
429 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
430 { ".debug_str.dwo", ".zdebug_str.dwo" },
431 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
432 { ".debug_types.dwo", ".zdebug_types.dwo" },
433 { ".debug_cu_index", ".zdebug_cu_index" },
434 { ".debug_tu_index", ".zdebug_tu_index" },
437 /* local data types */
439 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
440 begin with a header, which contains the following information. */
441 struct loclists_rnglists_header
443 /* A 4-byte or 12-byte length containing the length of the
444 set of entries for this compilation unit, not including the
445 length field itself. */
448 /* A 2-byte version identifier. */
451 /* A 1-byte unsigned integer containing the size in bytes of an address on
452 the target system. */
453 unsigned char addr_size
;
455 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
456 on the target system. */
457 unsigned char segment_collector_size
;
459 /* A 4-byte count of the number of offsets that follow the header. */
460 unsigned int offset_entry_count
;
463 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
464 This includes type_unit_group and quick_file_names. */
466 struct stmt_list_hash
468 /* The DWO unit this table is from or NULL if there is none. */
469 struct dwo_unit
*dwo_unit
;
471 /* Offset in .debug_line or .debug_line.dwo. */
472 sect_offset line_sect_off
;
475 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
476 an object of this type. This contains elements of type unit groups
477 that can be shared across objfiles. The non-shareable parts are in
478 type_unit_group_unshareable. */
480 struct type_unit_group
: public dwarf2_per_cu_data
482 /* The TUs that share this DW_AT_stmt_list entry.
483 This is added to while parsing type units to build partial symtabs,
484 and is deleted afterwards and not used again. */
485 std::vector
<signatured_type
*> *tus
= nullptr;
487 /* The data used to construct the hash key. */
488 struct stmt_list_hash hash
{};
491 /* These sections are what may appear in a (real or virtual) DWO file. */
495 struct dwarf2_section_info abbrev
;
496 struct dwarf2_section_info line
;
497 struct dwarf2_section_info loc
;
498 struct dwarf2_section_info loclists
;
499 struct dwarf2_section_info macinfo
;
500 struct dwarf2_section_info macro
;
501 struct dwarf2_section_info rnglists
;
502 struct dwarf2_section_info str
;
503 struct dwarf2_section_info str_offsets
;
504 /* In the case of a virtual DWO file, these two are unused. */
505 struct dwarf2_section_info info
;
506 std::vector
<dwarf2_section_info
> types
;
509 /* CUs/TUs in DWP/DWO files. */
513 /* Backlink to the containing struct dwo_file. */
514 struct dwo_file
*dwo_file
;
516 /* The "id" that distinguishes this CU/TU.
517 .debug_info calls this "dwo_id", .debug_types calls this "signature".
518 Since signatures came first, we stick with it for consistency. */
521 /* The section this CU/TU lives in, in the DWO file. */
522 struct dwarf2_section_info
*section
;
524 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
525 sect_offset sect_off
;
528 /* For types, offset in the type's DIE of the type defined by this TU. */
529 cu_offset type_offset_in_tu
;
532 /* include/dwarf2.h defines the DWP section codes.
533 It defines a max value but it doesn't define a min value, which we
534 use for error checking, so provide one. */
536 enum dwp_v2_section_ids
541 /* Data for one DWO file.
543 This includes virtual DWO files (a virtual DWO file is a DWO file as it
544 appears in a DWP file). DWP files don't really have DWO files per se -
545 comdat folding of types "loses" the DWO file they came from, and from
546 a high level view DWP files appear to contain a mass of random types.
547 However, to maintain consistency with the non-DWP case we pretend DWP
548 files contain virtual DWO files, and we assign each TU with one virtual
549 DWO file (generally based on the line and abbrev section offsets -
550 a heuristic that seems to work in practice). */
554 dwo_file () = default;
555 DISABLE_COPY_AND_ASSIGN (dwo_file
);
557 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
558 For virtual DWO files the name is constructed from the section offsets
559 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
560 from related CU+TUs. */
561 const char *dwo_name
= nullptr;
563 /* The DW_AT_comp_dir attribute. */
564 const char *comp_dir
= nullptr;
566 /* The bfd, when the file is open. Otherwise this is NULL.
567 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
568 gdb_bfd_ref_ptr dbfd
;
570 /* The sections that make up this DWO file.
571 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
572 sections (for lack of a better name). */
573 struct dwo_sections sections
{};
575 /* The CUs in the file.
576 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
577 an extension to handle LLVM's Link Time Optimization output (where
578 multiple source files may be compiled into a single object/dwo pair). */
581 /* Table of TUs in the file.
582 Each element is a struct dwo_unit. */
586 /* These sections are what may appear in a DWP file. */
590 /* These are used by all DWP versions (1, 2 and 5). */
591 struct dwarf2_section_info str
;
592 struct dwarf2_section_info cu_index
;
593 struct dwarf2_section_info tu_index
;
595 /* These are only used by DWP version 2 and version 5 files.
596 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
597 sections are referenced by section number, and are not recorded here.
598 In DWP version 2 or 5 there is at most one copy of all these sections,
599 each section being (effectively) comprised of the concatenation of all of
600 the individual sections that exist in the version 1 format.
601 To keep the code simple we treat each of these concatenated pieces as a
602 section itself (a virtual section?). */
603 struct dwarf2_section_info abbrev
;
604 struct dwarf2_section_info info
;
605 struct dwarf2_section_info line
;
606 struct dwarf2_section_info loc
;
607 struct dwarf2_section_info loclists
;
608 struct dwarf2_section_info macinfo
;
609 struct dwarf2_section_info macro
;
610 struct dwarf2_section_info rnglists
;
611 struct dwarf2_section_info str_offsets
;
612 struct dwarf2_section_info types
;
615 /* These sections are what may appear in a virtual DWO file in DWP version 1.
616 A virtual DWO file is a DWO file as it appears in a DWP file. */
618 struct virtual_v1_dwo_sections
620 struct dwarf2_section_info abbrev
;
621 struct dwarf2_section_info line
;
622 struct dwarf2_section_info loc
;
623 struct dwarf2_section_info macinfo
;
624 struct dwarf2_section_info macro
;
625 struct dwarf2_section_info str_offsets
;
626 /* Each DWP hash table entry records one CU or one TU.
627 That is recorded here, and copied to dwo_unit.section. */
628 struct dwarf2_section_info info_or_types
;
631 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
632 In version 2, the sections of the DWO files are concatenated together
633 and stored in one section of that name. Thus each ELF section contains
634 several "virtual" sections. */
636 struct virtual_v2_or_v5_dwo_sections
638 bfd_size_type abbrev_offset
;
639 bfd_size_type abbrev_size
;
641 bfd_size_type line_offset
;
642 bfd_size_type line_size
;
644 bfd_size_type loc_offset
;
645 bfd_size_type loc_size
;
647 bfd_size_type loclists_offset
;
648 bfd_size_type loclists_size
;
650 bfd_size_type macinfo_offset
;
651 bfd_size_type macinfo_size
;
653 bfd_size_type macro_offset
;
654 bfd_size_type macro_size
;
656 bfd_size_type rnglists_offset
;
657 bfd_size_type rnglists_size
;
659 bfd_size_type str_offsets_offset
;
660 bfd_size_type str_offsets_size
;
662 /* Each DWP hash table entry records one CU or one TU.
663 That is recorded here, and copied to dwo_unit.section. */
664 bfd_size_type info_or_types_offset
;
665 bfd_size_type info_or_types_size
;
668 /* Contents of DWP hash tables. */
670 struct dwp_hash_table
672 uint32_t version
, nr_columns
;
673 uint32_t nr_units
, nr_slots
;
674 const gdb_byte
*hash_table
, *unit_table
;
679 const gdb_byte
*indices
;
683 /* This is indexed by column number and gives the id of the section
685 #define MAX_NR_V2_DWO_SECTIONS \
686 (1 /* .debug_info or .debug_types */ \
687 + 1 /* .debug_abbrev */ \
688 + 1 /* .debug_line */ \
689 + 1 /* .debug_loc */ \
690 + 1 /* .debug_str_offsets */ \
691 + 1 /* .debug_macro or .debug_macinfo */)
692 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
693 const gdb_byte
*offsets
;
694 const gdb_byte
*sizes
;
698 /* This is indexed by column number and gives the id of the section
700 #define MAX_NR_V5_DWO_SECTIONS \
701 (1 /* .debug_info */ \
702 + 1 /* .debug_abbrev */ \
703 + 1 /* .debug_line */ \
704 + 1 /* .debug_loclists */ \
705 + 1 /* .debug_str_offsets */ \
706 + 1 /* .debug_macro */ \
707 + 1 /* .debug_rnglists */)
708 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
709 const gdb_byte
*offsets
;
710 const gdb_byte
*sizes
;
715 /* Data for one DWP file. */
719 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
721 dbfd (std::move (abfd
))
725 /* Name of the file. */
728 /* File format version. */
732 gdb_bfd_ref_ptr dbfd
;
734 /* Section info for this file. */
735 struct dwp_sections sections
{};
737 /* Table of CUs in the file. */
738 const struct dwp_hash_table
*cus
= nullptr;
740 /* Table of TUs in the file. */
741 const struct dwp_hash_table
*tus
= nullptr;
743 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
747 /* Table to map ELF section numbers to their sections.
748 This is only needed for the DWP V1 file format. */
749 unsigned int num_sections
= 0;
750 asection
**elf_sections
= nullptr;
753 /* Struct used to pass misc. parameters to read_die_and_children, et
754 al. which are used for both .debug_info and .debug_types dies.
755 All parameters here are unchanging for the life of the call. This
756 struct exists to abstract away the constant parameters of die reading. */
758 struct die_reader_specs
760 /* The bfd of die_section. */
763 /* The CU of the DIE we are parsing. */
764 struct dwarf2_cu
*cu
;
766 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
767 struct dwo_file
*dwo_file
;
769 /* The section the die comes from.
770 This is either .debug_info or .debug_types, or the .dwo variants. */
771 struct dwarf2_section_info
*die_section
;
773 /* die_section->buffer. */
774 const gdb_byte
*buffer
;
776 /* The end of the buffer. */
777 const gdb_byte
*buffer_end
;
779 /* The abbreviation table to use when reading the DIEs. */
780 struct abbrev_table
*abbrev_table
;
783 /* A subclass of die_reader_specs that holds storage and has complex
784 constructor and destructor behavior. */
786 class cutu_reader
: public die_reader_specs
790 cutu_reader (dwarf2_per_cu_data
*this_cu
,
791 dwarf2_per_objfile
*per_objfile
,
792 struct abbrev_table
*abbrev_table
,
793 dwarf2_cu
*existing_cu
,
796 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
797 dwarf2_per_objfile
*per_objfile
,
798 struct dwarf2_cu
*parent_cu
= nullptr,
799 struct dwo_file
*dwo_file
= nullptr);
801 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
803 const gdb_byte
*info_ptr
= nullptr;
804 struct die_info
*comp_unit_die
= nullptr;
805 bool dummy_p
= false;
807 /* Release the new CU, putting it on the chain. This cannot be done
812 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
813 dwarf2_per_objfile
*per_objfile
,
814 dwarf2_cu
*existing_cu
);
816 struct dwarf2_per_cu_data
*m_this_cu
;
817 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
819 /* The ordinary abbreviation table. */
820 abbrev_table_up m_abbrev_table_holder
;
822 /* The DWO abbreviation table. */
823 abbrev_table_up m_dwo_abbrev_table
;
826 /* When we construct a partial symbol table entry we only
827 need this much information. */
828 struct partial_die_info
: public allocate_on_obstack
830 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
832 /* Disable assign but still keep copy ctor, which is needed
833 load_partial_dies. */
834 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
836 /* Adjust the partial die before generating a symbol for it. This
837 function may set the is_external flag or change the DIE's
839 void fixup (struct dwarf2_cu
*cu
);
841 /* Read a minimal amount of information into the minimal die
843 const gdb_byte
*read (const struct die_reader_specs
*reader
,
844 const struct abbrev_info
&abbrev
,
845 const gdb_byte
*info_ptr
);
847 /* Compute the name of this partial DIE. This memoizes the
848 result, so it is safe to call multiple times. */
849 const char *name (dwarf2_cu
*cu
);
851 /* Offset of this DIE. */
852 const sect_offset sect_off
;
854 /* DWARF-2 tag for this DIE. */
855 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
857 /* Assorted flags describing the data found in this DIE. */
858 const unsigned int has_children
: 1;
860 unsigned int is_external
: 1;
861 unsigned int is_declaration
: 1;
862 unsigned int has_type
: 1;
863 unsigned int has_specification
: 1;
864 unsigned int has_pc_info
: 1;
865 unsigned int may_be_inlined
: 1;
867 /* This DIE has been marked DW_AT_main_subprogram. */
868 unsigned int main_subprogram
: 1;
870 /* Flag set if the SCOPE field of this structure has been
872 unsigned int scope_set
: 1;
874 /* Flag set if the DIE has a byte_size attribute. */
875 unsigned int has_byte_size
: 1;
877 /* Flag set if the DIE has a DW_AT_const_value attribute. */
878 unsigned int has_const_value
: 1;
880 /* Flag set if any of the DIE's children are template arguments. */
881 unsigned int has_template_arguments
: 1;
883 /* Flag set if fixup has been called on this die. */
884 unsigned int fixup_called
: 1;
886 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
887 unsigned int is_dwz
: 1;
889 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
890 unsigned int spec_is_dwz
: 1;
892 unsigned int canonical_name
: 1;
894 /* The name of this DIE. Normally the value of DW_AT_name, but
895 sometimes a default name for unnamed DIEs. */
896 const char *raw_name
= nullptr;
898 /* The linkage name, if present. */
899 const char *linkage_name
= nullptr;
901 /* The scope to prepend to our children. This is generally
902 allocated on the comp_unit_obstack, so will disappear
903 when this compilation unit leaves the cache. */
904 const char *scope
= nullptr;
906 /* Some data associated with the partial DIE. The tag determines
907 which field is live. */
910 /* The location description associated with this DIE, if any. */
911 struct dwarf_block
*locdesc
;
912 /* The offset of an import, for DW_TAG_imported_unit. */
913 sect_offset sect_off
;
916 /* If HAS_PC_INFO, the PC range associated with this DIE. */
918 CORE_ADDR highpc
= 0;
920 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
921 DW_AT_sibling, if any. */
922 /* NOTE: This member isn't strictly necessary, partial_die_info::read
923 could return DW_AT_sibling values to its caller load_partial_dies. */
924 const gdb_byte
*sibling
= nullptr;
926 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
927 DW_AT_specification (or DW_AT_abstract_origin or
929 sect_offset spec_offset
{};
931 /* Pointers to this DIE's parent, first child, and next sibling,
933 struct partial_die_info
*die_parent
= nullptr;
934 struct partial_die_info
*die_child
= nullptr;
935 struct partial_die_info
*die_sibling
= nullptr;
937 friend struct partial_die_info
*
938 dwarf2_cu::find_partial_die (sect_offset sect_off
);
941 /* Only need to do look up in dwarf2_cu::find_partial_die. */
942 partial_die_info (sect_offset sect_off
)
943 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
947 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
949 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
954 has_specification
= 0;
961 has_template_arguments
= 0;
969 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
970 but this would require a corresponding change in unpack_field_as_long
972 static int bits_per_byte
= 8;
974 struct variant_part_builder
;
976 /* When reading a variant, we track a bit more information about the
977 field, and store it in an object of this type. */
981 int first_field
= -1;
984 /* A variant can contain other variant parts. */
985 std::vector
<variant_part_builder
> variant_parts
;
987 /* If we see a DW_TAG_variant, then this will be set if this is the
989 bool default_branch
= false;
990 /* If we see a DW_AT_discr_value, then this will be the discriminant
992 ULONGEST discriminant_value
= 0;
993 /* If we see a DW_AT_discr_list, then this is a pointer to the list
995 struct dwarf_block
*discr_list_data
= nullptr;
998 /* This represents a DW_TAG_variant_part. */
1000 struct variant_part_builder
1002 /* The offset of the discriminant field. */
1003 sect_offset discriminant_offset
{};
1005 /* Variants that are direct children of this variant part. */
1006 std::vector
<variant_field
> variants
;
1008 /* True if we're currently reading a variant. */
1009 bool processing_variant
= false;
1014 int accessibility
= 0;
1016 /* Variant parts need to find the discriminant, which is a DIE
1017 reference. We track the section offset of each field to make
1020 struct field field
{};
1025 const char *name
= nullptr;
1026 std::vector
<struct fn_field
> fnfields
;
1029 /* The routines that read and process dies for a C struct or C++ class
1030 pass lists of data member fields and lists of member function fields
1031 in an instance of a field_info structure, as defined below. */
1034 /* List of data member and baseclasses fields. */
1035 std::vector
<struct nextfield
> fields
;
1036 std::vector
<struct nextfield
> baseclasses
;
1038 /* Set if the accessibility of one of the fields is not public. */
1039 bool non_public_fields
= false;
1041 /* Member function fieldlist array, contains name of possibly overloaded
1042 member function, number of overloaded member functions and a pointer
1043 to the head of the member function field chain. */
1044 std::vector
<struct fnfieldlist
> fnfieldlists
;
1046 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1047 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1048 std::vector
<struct decl_field
> typedef_field_list
;
1050 /* Nested types defined by this class and the number of elements in this
1052 std::vector
<struct decl_field
> nested_types_list
;
1054 /* If non-null, this is the variant part we are currently
1056 variant_part_builder
*current_variant_part
= nullptr;
1057 /* This holds all the top-level variant parts attached to the type
1059 std::vector
<variant_part_builder
> variant_parts
;
1061 /* Return the total number of fields (including baseclasses). */
1062 int nfields () const
1064 return fields
.size () + baseclasses
.size ();
1068 /* Loaded secondary compilation units are kept in memory until they
1069 have not been referenced for the processing of this many
1070 compilation units. Set this to zero to disable caching. Cache
1071 sizes of up to at least twenty will improve startup time for
1072 typical inter-CU-reference binaries, at an obvious memory cost. */
1073 static int dwarf_max_cache_age
= 5;
1075 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1076 struct cmd_list_element
*c
, const char *value
)
1078 fprintf_filtered (file
, _("The upper bound on the age of cached "
1079 "DWARF compilation units is %s.\n"),
1083 /* local function prototypes */
1085 static void dwarf2_find_base_address (struct die_info
*die
,
1086 struct dwarf2_cu
*cu
);
1088 static dwarf2_psymtab
*create_partial_symtab
1089 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1092 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1093 const gdb_byte
*info_ptr
,
1094 struct die_info
*type_unit_die
);
1096 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1098 static void scan_partial_symbols (struct partial_die_info
*,
1099 CORE_ADDR
*, CORE_ADDR
*,
1100 int, struct dwarf2_cu
*);
1102 static void add_partial_symbol (struct partial_die_info
*,
1103 struct dwarf2_cu
*);
1105 static void add_partial_namespace (struct partial_die_info
*pdi
,
1106 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1107 int set_addrmap
, struct dwarf2_cu
*cu
);
1109 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1110 CORE_ADDR
*highpc
, int set_addrmap
,
1111 struct dwarf2_cu
*cu
);
1113 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1114 struct dwarf2_cu
*cu
);
1116 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1117 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1118 int need_pc
, struct dwarf2_cu
*cu
);
1120 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1122 static struct partial_die_info
*load_partial_dies
1123 (const struct die_reader_specs
*, const gdb_byte
*, int);
1125 /* A pair of partial_die_info and compilation unit. */
1126 struct cu_partial_die_info
1128 /* The compilation unit of the partial_die_info. */
1129 struct dwarf2_cu
*cu
;
1130 /* A partial_die_info. */
1131 struct partial_die_info
*pdi
;
1133 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1139 cu_partial_die_info () = delete;
1142 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1143 struct dwarf2_cu
*);
1145 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1147 const struct attr_abbrev
*,
1150 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1151 struct attribute
*attr
, dwarf_tag tag
);
1153 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1155 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1156 dwarf2_section_info
*, sect_offset
);
1158 static const char *read_indirect_string
1159 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1160 const struct comp_unit_head
*, unsigned int *);
1162 static const char *read_indirect_string_at_offset
1163 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1165 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1169 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1170 ULONGEST str_index
);
1172 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1173 ULONGEST str_index
);
1175 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1177 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1178 struct dwarf2_cu
*);
1180 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1181 struct dwarf2_cu
*cu
);
1183 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1185 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1186 struct dwarf2_cu
*cu
);
1188 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1190 static struct die_info
*die_specification (struct die_info
*die
,
1191 struct dwarf2_cu
**);
1193 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1194 struct dwarf2_cu
*cu
);
1196 static void dwarf_decode_lines (struct line_header
*, const char *,
1197 struct dwarf2_cu
*, dwarf2_psymtab
*,
1198 CORE_ADDR
, int decode_mapping
);
1200 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1203 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1204 struct dwarf2_cu
*, struct symbol
* = NULL
);
1206 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1207 struct dwarf2_cu
*);
1209 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1212 struct obstack
*obstack
,
1213 struct dwarf2_cu
*cu
, LONGEST
*value
,
1214 const gdb_byte
**bytes
,
1215 struct dwarf2_locexpr_baton
**baton
);
1217 static struct type
*read_subrange_index_type (struct die_info
*die
,
1218 struct dwarf2_cu
*cu
);
1220 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1222 static int need_gnat_info (struct dwarf2_cu
*);
1224 static struct type
*die_descriptive_type (struct die_info
*,
1225 struct dwarf2_cu
*);
1227 static void set_descriptive_type (struct type
*, struct die_info
*,
1228 struct dwarf2_cu
*);
1230 static struct type
*die_containing_type (struct die_info
*,
1231 struct dwarf2_cu
*);
1233 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1234 struct dwarf2_cu
*);
1236 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1238 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1240 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1242 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1243 const char *suffix
, int physname
,
1244 struct dwarf2_cu
*cu
);
1246 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1248 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1250 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1252 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1254 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1256 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1258 /* Return the .debug_loclists section to use for cu. */
1259 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1261 /* Return the .debug_rnglists section to use for cu. */
1262 static struct dwarf2_section_info
*cu_debug_rnglists_section
1263 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1265 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1266 values. Keep the items ordered with increasing constraints compliance. */
1269 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1270 PC_BOUNDS_NOT_PRESENT
,
1272 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1273 were present but they do not form a valid range of PC addresses. */
1276 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1279 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1283 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1284 CORE_ADDR
*, CORE_ADDR
*,
1288 static void get_scope_pc_bounds (struct die_info
*,
1289 CORE_ADDR
*, CORE_ADDR
*,
1290 struct dwarf2_cu
*);
1292 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1293 CORE_ADDR
, struct dwarf2_cu
*);
1295 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1296 struct dwarf2_cu
*);
1298 static void dwarf2_attach_fields_to_type (struct field_info
*,
1299 struct type
*, struct dwarf2_cu
*);
1301 static void dwarf2_add_member_fn (struct field_info
*,
1302 struct die_info
*, struct type
*,
1303 struct dwarf2_cu
*);
1305 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1307 struct dwarf2_cu
*);
1309 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1311 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1313 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1315 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1317 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1319 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1321 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1323 static struct type
*read_module_type (struct die_info
*die
,
1324 struct dwarf2_cu
*cu
);
1326 static const char *namespace_name (struct die_info
*die
,
1327 int *is_anonymous
, struct dwarf2_cu
*);
1329 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1331 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1334 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1335 struct dwarf2_cu
*);
1337 static struct die_info
*read_die_and_siblings_1
1338 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1341 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1342 const gdb_byte
*info_ptr
,
1343 const gdb_byte
**new_info_ptr
,
1344 struct die_info
*parent
);
1346 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1347 struct die_info
**, const gdb_byte
*,
1350 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1351 struct die_info
**, const gdb_byte
*);
1353 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1355 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1358 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1360 static const char *dwarf2_full_name (const char *name
,
1361 struct die_info
*die
,
1362 struct dwarf2_cu
*cu
);
1364 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1365 struct dwarf2_cu
*cu
);
1367 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1368 struct dwarf2_cu
**);
1370 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1372 static void dump_die_for_error (struct die_info
*);
1374 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1377 /*static*/ void dump_die (struct die_info
*, int max_level
);
1379 static void store_in_ref_table (struct die_info
*,
1380 struct dwarf2_cu
*);
1382 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1383 const struct attribute
*,
1384 struct dwarf2_cu
**);
1386 static struct die_info
*follow_die_ref (struct die_info
*,
1387 const struct attribute
*,
1388 struct dwarf2_cu
**);
1390 static struct die_info
*follow_die_sig (struct die_info
*,
1391 const struct attribute
*,
1392 struct dwarf2_cu
**);
1394 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1395 struct dwarf2_cu
*);
1397 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1398 const struct attribute
*,
1399 struct dwarf2_cu
*);
1401 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1402 dwarf2_per_objfile
*per_objfile
);
1404 static void read_signatured_type (signatured_type
*sig_type
,
1405 dwarf2_per_objfile
*per_objfile
);
1407 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1408 struct die_info
*die
, struct dwarf2_cu
*cu
,
1409 struct dynamic_prop
*prop
, struct type
*type
);
1411 /* memory allocation interface */
1413 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1415 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1417 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1419 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1420 struct dwarf2_loclist_baton
*baton
,
1421 const struct attribute
*attr
);
1423 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1425 struct dwarf2_cu
*cu
,
1428 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1429 const gdb_byte
*info_ptr
,
1430 const struct abbrev_info
*abbrev
);
1432 static hashval_t
partial_die_hash (const void *item
);
1434 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1436 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1437 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1438 dwarf2_per_objfile
*per_objfile
);
1440 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1441 struct die_info
*comp_unit_die
,
1442 enum language pretend_language
);
1444 static struct type
*set_die_type (struct die_info
*, struct type
*,
1445 struct dwarf2_cu
*, bool = false);
1447 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1449 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1450 dwarf2_per_objfile
*per_objfile
,
1451 dwarf2_cu
*existing_cu
,
1453 enum language pretend_language
);
1455 static void process_full_comp_unit (dwarf2_cu
*cu
,
1456 enum language pretend_language
);
1458 static void process_full_type_unit (dwarf2_cu
*cu
,
1459 enum language pretend_language
);
1461 static struct type
*get_die_type_at_offset (sect_offset
,
1462 dwarf2_per_cu_data
*per_cu
,
1463 dwarf2_per_objfile
*per_objfile
);
1465 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1467 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1468 dwarf2_per_objfile
*per_objfile
,
1469 enum language pretend_language
);
1471 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1473 /* Class, the destructor of which frees all allocated queue entries. This
1474 will only have work to do if an error was thrown while processing the
1475 dwarf. If no error was thrown then the queue entries should have all
1476 been processed, and freed, as we went along. */
1478 class dwarf2_queue_guard
1481 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1482 : m_per_objfile (per_objfile
)
1484 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1486 m_per_objfile
->per_bfd
->queue
.emplace ();
1489 /* Free any entries remaining on the queue. There should only be
1490 entries left if we hit an error while processing the dwarf. */
1491 ~dwarf2_queue_guard ()
1493 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1495 m_per_objfile
->per_bfd
->queue
.reset ();
1498 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1501 dwarf2_per_objfile
*m_per_objfile
;
1504 dwarf2_queue_item::~dwarf2_queue_item ()
1506 /* Anything still marked queued is likely to be in an
1507 inconsistent state, so discard it. */
1510 per_objfile
->remove_cu (per_cu
);
1515 /* See dwarf2/read.h. */
1518 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1520 if (data
->is_debug_types
)
1521 delete static_cast<signatured_type
*> (data
);
1526 /* The return type of find_file_and_directory. Note, the enclosed
1527 string pointers are only valid while this object is valid. */
1529 struct file_and_directory
1531 /* The filename. This is never NULL. */
1534 /* The compilation directory. NULL if not known. If we needed to
1535 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1536 points directly to the DW_AT_comp_dir string attribute owned by
1537 the obstack that owns the DIE. */
1538 const char *comp_dir
;
1540 /* If we needed to build a new string for comp_dir, this is what
1541 owns the storage. */
1542 std::string comp_dir_storage
;
1545 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1546 struct dwarf2_cu
*cu
);
1548 static htab_up
allocate_signatured_type_table ();
1550 static htab_up
allocate_dwo_unit_table ();
1552 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1553 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1554 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1556 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1558 static struct dwo_unit
*lookup_dwo_comp_unit
1559 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1560 ULONGEST signature
);
1562 static struct dwo_unit
*lookup_dwo_type_unit
1563 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1565 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1567 /* A unique pointer to a dwo_file. */
1569 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1571 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1573 static void check_producer (struct dwarf2_cu
*cu
);
1575 static void free_line_header_voidp (void *arg
);
1577 /* Various complaints about symbol reading that don't abort the process. */
1580 dwarf2_debug_line_missing_file_complaint (void)
1582 complaint (_(".debug_line section has line data without a file"));
1586 dwarf2_debug_line_missing_end_sequence_complaint (void)
1588 complaint (_(".debug_line section has line "
1589 "program sequence without an end"));
1593 dwarf2_complex_location_expr_complaint (void)
1595 complaint (_("location expression too complex"));
1599 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1602 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1607 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1609 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1613 /* Hash function for line_header_hash. */
1616 line_header_hash (const struct line_header
*ofs
)
1618 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1621 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1624 line_header_hash_voidp (const void *item
)
1626 const struct line_header
*ofs
= (const struct line_header
*) item
;
1628 return line_header_hash (ofs
);
1631 /* Equality function for line_header_hash. */
1634 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1636 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1637 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1639 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1640 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1645 /* See declaration. */
1647 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1650 can_copy (can_copy_
)
1653 names
= &dwarf2_elf_names
;
1655 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1656 locate_sections (obfd
, sec
, *names
);
1659 dwarf2_per_bfd::~dwarf2_per_bfd ()
1661 for (auto &per_cu
: all_comp_units
)
1662 per_cu
->imported_symtabs_free ();
1664 /* Everything else should be on this->obstack. */
1670 dwarf2_per_objfile::remove_all_cus ()
1672 gdb_assert (!this->per_bfd
->queue
.has_value ());
1674 for (auto pair
: m_dwarf2_cus
)
1677 m_dwarf2_cus
.clear ();
1680 /* A helper class that calls free_cached_comp_units on
1683 class free_cached_comp_units
1687 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1688 : m_per_objfile (per_objfile
)
1692 ~free_cached_comp_units ()
1694 m_per_objfile
->remove_all_cus ();
1697 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1701 dwarf2_per_objfile
*m_per_objfile
;
1707 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1709 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1711 return this->m_symtabs
[per_cu
->index
] != nullptr;
1717 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1719 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1721 return this->m_symtabs
[per_cu
->index
];
1727 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1728 compunit_symtab
*symtab
)
1730 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1731 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1733 this->m_symtabs
[per_cu
->index
] = symtab
;
1736 /* Try to locate the sections we need for DWARF 2 debugging
1737 information and return true if we have enough to do something.
1738 NAMES points to the dwarf2 section names, or is NULL if the standard
1739 ELF names are used. CAN_COPY is true for formats where symbol
1740 interposition is possible and so symbol values must follow copy
1741 relocation rules. */
1744 dwarf2_has_info (struct objfile
*objfile
,
1745 const struct dwarf2_debug_sections
*names
,
1748 if (objfile
->flags
& OBJF_READNEVER
)
1751 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1753 if (per_objfile
== NULL
)
1755 dwarf2_per_bfd
*per_bfd
;
1757 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1758 BFD doesn't require relocations.
1760 We don't share with objfiles for which -readnow was requested,
1761 because it would complicate things when loading the same BFD with
1762 -readnow and then without -readnow. */
1763 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1764 && (objfile
->flags
& OBJF_READNOW
) == 0)
1766 /* See if one has been created for this BFD yet. */
1767 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1769 if (per_bfd
== nullptr)
1771 /* No, create it now. */
1772 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1773 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1778 /* No sharing possible, create one specifically for this objfile. */
1779 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1780 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1783 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1786 return (!per_objfile
->per_bfd
->info
.is_virtual
1787 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1788 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1789 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1792 /* See declaration. */
1795 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1796 const dwarf2_debug_sections
&names
)
1798 flagword aflag
= bfd_section_flags (sectp
);
1800 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1803 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1804 > bfd_get_file_size (abfd
))
1806 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1807 warning (_("Discarding section %s which has a section size (%s"
1808 ") larger than the file size [in module %s]"),
1809 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1810 bfd_get_filename (abfd
));
1812 else if (names
.info
.matches (sectp
->name
))
1814 this->info
.s
.section
= sectp
;
1815 this->info
.size
= bfd_section_size (sectp
);
1817 else if (names
.abbrev
.matches (sectp
->name
))
1819 this->abbrev
.s
.section
= sectp
;
1820 this->abbrev
.size
= bfd_section_size (sectp
);
1822 else if (names
.line
.matches (sectp
->name
))
1824 this->line
.s
.section
= sectp
;
1825 this->line
.size
= bfd_section_size (sectp
);
1827 else if (names
.loc
.matches (sectp
->name
))
1829 this->loc
.s
.section
= sectp
;
1830 this->loc
.size
= bfd_section_size (sectp
);
1832 else if (names
.loclists
.matches (sectp
->name
))
1834 this->loclists
.s
.section
= sectp
;
1835 this->loclists
.size
= bfd_section_size (sectp
);
1837 else if (names
.macinfo
.matches (sectp
->name
))
1839 this->macinfo
.s
.section
= sectp
;
1840 this->macinfo
.size
= bfd_section_size (sectp
);
1842 else if (names
.macro
.matches (sectp
->name
))
1844 this->macro
.s
.section
= sectp
;
1845 this->macro
.size
= bfd_section_size (sectp
);
1847 else if (names
.str
.matches (sectp
->name
))
1849 this->str
.s
.section
= sectp
;
1850 this->str
.size
= bfd_section_size (sectp
);
1852 else if (names
.str_offsets
.matches (sectp
->name
))
1854 this->str_offsets
.s
.section
= sectp
;
1855 this->str_offsets
.size
= bfd_section_size (sectp
);
1857 else if (names
.line_str
.matches (sectp
->name
))
1859 this->line_str
.s
.section
= sectp
;
1860 this->line_str
.size
= bfd_section_size (sectp
);
1862 else if (names
.addr
.matches (sectp
->name
))
1864 this->addr
.s
.section
= sectp
;
1865 this->addr
.size
= bfd_section_size (sectp
);
1867 else if (names
.frame
.matches (sectp
->name
))
1869 this->frame
.s
.section
= sectp
;
1870 this->frame
.size
= bfd_section_size (sectp
);
1872 else if (names
.eh_frame
.matches (sectp
->name
))
1874 this->eh_frame
.s
.section
= sectp
;
1875 this->eh_frame
.size
= bfd_section_size (sectp
);
1877 else if (names
.ranges
.matches (sectp
->name
))
1879 this->ranges
.s
.section
= sectp
;
1880 this->ranges
.size
= bfd_section_size (sectp
);
1882 else if (names
.rnglists
.matches (sectp
->name
))
1884 this->rnglists
.s
.section
= sectp
;
1885 this->rnglists
.size
= bfd_section_size (sectp
);
1887 else if (names
.types
.matches (sectp
->name
))
1889 struct dwarf2_section_info type_section
;
1891 memset (&type_section
, 0, sizeof (type_section
));
1892 type_section
.s
.section
= sectp
;
1893 type_section
.size
= bfd_section_size (sectp
);
1895 this->types
.push_back (type_section
);
1897 else if (names
.gdb_index
.matches (sectp
->name
))
1899 this->gdb_index
.s
.section
= sectp
;
1900 this->gdb_index
.size
= bfd_section_size (sectp
);
1902 else if (names
.debug_names
.matches (sectp
->name
))
1904 this->debug_names
.s
.section
= sectp
;
1905 this->debug_names
.size
= bfd_section_size (sectp
);
1907 else if (names
.debug_aranges
.matches (sectp
->name
))
1909 this->debug_aranges
.s
.section
= sectp
;
1910 this->debug_aranges
.size
= bfd_section_size (sectp
);
1913 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1914 && bfd_section_vma (sectp
) == 0)
1915 this->has_section_at_zero
= true;
1918 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1922 dwarf2_get_section_info (struct objfile
*objfile
,
1923 enum dwarf2_section_enum sect
,
1924 asection
**sectp
, const gdb_byte
**bufp
,
1925 bfd_size_type
*sizep
)
1927 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1928 struct dwarf2_section_info
*info
;
1930 /* We may see an objfile without any DWARF, in which case we just
1932 if (per_objfile
== NULL
)
1941 case DWARF2_DEBUG_FRAME
:
1942 info
= &per_objfile
->per_bfd
->frame
;
1944 case DWARF2_EH_FRAME
:
1945 info
= &per_objfile
->per_bfd
->eh_frame
;
1948 gdb_assert_not_reached ("unexpected section");
1951 info
->read (objfile
);
1953 *sectp
= info
->get_bfd_section ();
1954 *bufp
= info
->buffer
;
1955 *sizep
= info
->size
;
1959 /* DWARF quick_symbol_functions support. */
1961 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1962 unique line tables, so we maintain a separate table of all .debug_line
1963 derived entries to support the sharing.
1964 All the quick functions need is the list of file names. We discard the
1965 line_header when we're done and don't need to record it here. */
1966 struct quick_file_names
1968 /* The data used to construct the hash key. */
1969 struct stmt_list_hash hash
;
1971 /* The number of entries in file_names, real_names. */
1972 unsigned int num_file_names
;
1974 /* The file names from the line table, after being run through
1976 const char **file_names
;
1978 /* The file names from the line table after being run through
1979 gdb_realpath. These are computed lazily. */
1980 const char **real_names
;
1983 /* When using the index (and thus not using psymtabs), each CU has an
1984 object of this type. This is used to hold information needed by
1985 the various "quick" methods. */
1986 struct dwarf2_per_cu_quick_data
1988 /* The file table. This can be NULL if there was no file table
1989 or it's currently not read in.
1990 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
1991 struct quick_file_names
*file_names
;
1993 /* A temporary mark bit used when iterating over all CUs in
1994 expand_symtabs_matching. */
1995 unsigned int mark
: 1;
1997 /* True if we've tried to read the file table and found there isn't one.
1998 There will be no point in trying to read it again next time. */
1999 unsigned int no_file_data
: 1;
2002 /* A subclass of psymbol_functions that arranges to read the DWARF
2003 partial symbols when needed. */
2004 struct lazy_dwarf_reader
: public psymbol_functions
2006 using psymbol_functions::psymbol_functions
;
2008 bool can_lazily_read_symbols () override
2013 void read_partial_symbols (struct objfile
*objfile
) override
2015 if (dwarf2_has_info (objfile
, nullptr))
2016 dwarf2_build_psymtabs (objfile
, this);
2020 static quick_symbol_functions_up
2021 make_lazy_dwarf_reader ()
2023 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2026 struct dwarf2_base_index_functions
: public quick_symbol_functions
2028 bool has_symbols (struct objfile
*objfile
) override
;
2030 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2032 void forget_cached_source_info (struct objfile
*objfile
) override
;
2034 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2037 bool *symbol_found_p
) override
2039 *symbol_found_p
= false;
2040 return language_unknown
;
2043 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2045 void expand_all_symtabs (struct objfile
*objfile
) override
;
2047 struct compunit_symtab
*find_pc_sect_compunit_symtab
2048 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2049 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2051 struct compunit_symtab
*find_compunit_symtab_by_address
2052 (struct objfile
*objfile
, CORE_ADDR address
) override
2057 void map_symbol_filenames (struct objfile
*objfile
,
2058 gdb::function_view
<symbol_filename_ftype
> fun
,
2059 bool need_fullname
) override
;
2062 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2064 void dump (struct objfile
*objfile
) override
;
2066 void expand_matching_symbols
2068 const lookup_name_info
&lookup_name
,
2071 symbol_compare_ftype
*ordered_compare
) override
;
2073 bool expand_symtabs_matching
2074 (struct objfile
*objfile
,
2075 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2076 const lookup_name_info
*lookup_name
,
2077 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2078 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2079 block_search_flags search_flags
,
2081 enum search_domain kind
) override
;
2084 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2086 void dump (struct objfile
*objfile
) override
;
2088 void expand_matching_symbols
2090 const lookup_name_info
&lookup_name
,
2093 symbol_compare_ftype
*ordered_compare
) override
;
2095 bool expand_symtabs_matching
2096 (struct objfile
*objfile
,
2097 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2098 const lookup_name_info
*lookup_name
,
2099 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2100 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2101 block_search_flags search_flags
,
2103 enum search_domain kind
) override
;
2106 static quick_symbol_functions_up
2107 make_dwarf_gdb_index ()
2109 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2112 static quick_symbol_functions_up
2113 make_dwarf_debug_names ()
2115 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2118 /* Utility hash function for a stmt_list_hash. */
2121 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2125 if (stmt_list_hash
->dwo_unit
!= NULL
)
2126 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2127 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2131 /* Utility equality function for a stmt_list_hash. */
2134 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2135 const struct stmt_list_hash
*rhs
)
2137 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2139 if (lhs
->dwo_unit
!= NULL
2140 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2143 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2146 /* Hash function for a quick_file_names. */
2149 hash_file_name_entry (const void *e
)
2151 const struct quick_file_names
*file_data
2152 = (const struct quick_file_names
*) e
;
2154 return hash_stmt_list_entry (&file_data
->hash
);
2157 /* Equality function for a quick_file_names. */
2160 eq_file_name_entry (const void *a
, const void *b
)
2162 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2163 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2165 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2168 /* Delete function for a quick_file_names. */
2171 delete_file_name_entry (void *e
)
2173 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2176 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2178 xfree ((void*) file_data
->file_names
[i
]);
2179 if (file_data
->real_names
)
2180 xfree ((void*) file_data
->real_names
[i
]);
2183 /* The space for the struct itself lives on the obstack, so we don't
2187 /* Create a quick_file_names hash table. */
2190 create_quick_file_names_table (unsigned int nr_initial_entries
)
2192 return htab_up (htab_create_alloc (nr_initial_entries
,
2193 hash_file_name_entry
, eq_file_name_entry
,
2194 delete_file_name_entry
, xcalloc
, xfree
));
2197 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2198 function is unrelated to symtabs, symtab would have to be created afterwards.
2199 You should call age_cached_comp_units after processing the CU. */
2202 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2205 if (per_cu
->is_debug_types
)
2206 load_full_type_unit (per_cu
, per_objfile
);
2208 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2209 skip_partial
, language_minimal
);
2211 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2213 return nullptr; /* Dummy CU. */
2215 dwarf2_find_base_address (cu
->dies
, cu
);
2220 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2223 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2224 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2226 /* Skip type_unit_groups, reading the type units they contain
2227 is handled elsewhere. */
2228 if (per_cu
->type_unit_group_p ())
2232 /* The destructor of dwarf2_queue_guard frees any entries left on
2233 the queue. After this point we're guaranteed to leave this function
2234 with the dwarf queue empty. */
2235 dwarf2_queue_guard
q_guard (per_objfile
);
2237 if (!per_objfile
->symtab_set_p (per_cu
))
2239 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2240 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2242 /* If we just loaded a CU from a DWO, and we're working with an index
2243 that may badly handle TUs, load all the TUs in that DWO as well.
2244 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2245 if (!per_cu
->is_debug_types
2247 && cu
->dwo_unit
!= NULL
2248 && per_objfile
->per_bfd
->index_table
!= NULL
2249 && per_objfile
->per_bfd
->index_table
->version
<= 7
2250 /* DWP files aren't supported yet. */
2251 && get_dwp_file (per_objfile
) == NULL
)
2252 queue_and_load_all_dwo_tus (cu
);
2255 process_queue (per_objfile
);
2258 /* Age the cache, releasing compilation units that have not
2259 been used recently. */
2260 per_objfile
->age_comp_units ();
2263 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2264 the per-objfile for which this symtab is instantiated.
2266 Returns the resulting symbol table. */
2268 static struct compunit_symtab
*
2269 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2270 dwarf2_per_objfile
*per_objfile
,
2273 gdb_assert (per_objfile
->per_bfd
->using_index
);
2275 if (!per_objfile
->symtab_set_p (per_cu
))
2277 free_cached_comp_units
freer (per_objfile
);
2278 scoped_restore decrementer
= increment_reading_symtab ();
2279 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2280 process_cu_includes (per_objfile
);
2283 return per_objfile
->get_symtab (per_cu
);
2288 dwarf2_per_cu_data_up
2289 dwarf2_per_bfd::allocate_per_cu ()
2291 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2292 result
->per_bfd
= this;
2293 result
->index
= m_num_psymtabs
++;
2299 std::unique_ptr
<signatured_type
>
2300 dwarf2_per_bfd::allocate_signatured_type ()
2302 std::unique_ptr
<signatured_type
> result (new signatured_type
);
2303 result
->per_bfd
= this;
2304 result
->index
= m_num_psymtabs
++;
2309 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2310 obstack, and constructed with the specified field values. */
2312 static dwarf2_per_cu_data_up
2313 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2314 struct dwarf2_section_info
*section
,
2316 sect_offset sect_off
, ULONGEST length
)
2318 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2319 the_cu
->sect_off
= sect_off
;
2320 the_cu
->length
= length
;
2321 the_cu
->section
= section
;
2322 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2323 struct dwarf2_per_cu_quick_data
);
2324 the_cu
->is_dwz
= is_dwz
;
2328 /* A helper for create_cus_from_index that handles a given list of
2332 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2333 const gdb_byte
*cu_list
, offset_type n_elements
,
2334 struct dwarf2_section_info
*section
,
2337 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2339 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2341 sect_offset sect_off
2342 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2343 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2346 dwarf2_per_cu_data_up per_cu
2347 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2349 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2353 /* Read the CU list from the mapped index, and use it to create all
2354 the CU objects for PER_BFD. */
2357 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2358 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2359 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2361 gdb_assert (per_bfd
->all_comp_units
.empty ());
2362 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2364 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2367 if (dwz_elements
== 0)
2370 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2371 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2375 /* Create the signatured type hash table from the index. */
2378 create_signatured_type_table_from_index
2379 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2380 const gdb_byte
*bytes
, offset_type elements
)
2382 htab_up sig_types_hash
= allocate_signatured_type_table ();
2384 for (offset_type i
= 0; i
< elements
; i
+= 3)
2386 std::unique_ptr
<signatured_type
> sig_type
;
2389 cu_offset type_offset_in_tu
;
2391 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2392 sect_offset sect_off
2393 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2395 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2397 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2400 sig_type
= per_bfd
->allocate_signatured_type ();
2401 sig_type
->signature
= signature
;
2402 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2403 sig_type
->is_debug_types
= 1;
2404 sig_type
->section
= section
;
2405 sig_type
->sect_off
= sect_off
;
2407 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2408 struct dwarf2_per_cu_quick_data
);
2410 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2411 *slot
= sig_type
.get ();
2413 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2416 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2419 /* Create the signatured type hash table from .debug_names. */
2422 create_signatured_type_table_from_debug_names
2423 (dwarf2_per_objfile
*per_objfile
,
2424 const mapped_debug_names
&map
,
2425 struct dwarf2_section_info
*section
,
2426 struct dwarf2_section_info
*abbrev_section
)
2428 struct objfile
*objfile
= per_objfile
->objfile
;
2430 section
->read (objfile
);
2431 abbrev_section
->read (objfile
);
2433 htab_up sig_types_hash
= allocate_signatured_type_table ();
2435 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2437 std::unique_ptr
<signatured_type
> sig_type
;
2440 sect_offset sect_off
2441 = (sect_offset
) (extract_unsigned_integer
2442 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2444 map
.dwarf5_byte_order
));
2446 comp_unit_head cu_header
;
2447 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2449 section
->buffer
+ to_underlying (sect_off
),
2452 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2453 sig_type
->signature
= cu_header
.signature
;
2454 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2455 sig_type
->is_debug_types
= 1;
2456 sig_type
->section
= section
;
2457 sig_type
->sect_off
= sect_off
;
2459 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2460 struct dwarf2_per_cu_quick_data
);
2462 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2463 *slot
= sig_type
.get ();
2465 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2468 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2471 /* Read the address map data from the mapped index, and use it to
2472 populate the psymtabs_addrmap. */
2475 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2476 struct mapped_index
*index
)
2478 struct objfile
*objfile
= per_objfile
->objfile
;
2479 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2480 struct gdbarch
*gdbarch
= objfile
->arch ();
2481 const gdb_byte
*iter
, *end
;
2482 struct addrmap
*mutable_map
;
2485 auto_obstack temp_obstack
;
2487 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2489 iter
= index
->address_table
.data ();
2490 end
= iter
+ index
->address_table
.size ();
2492 baseaddr
= objfile
->text_section_offset ();
2496 ULONGEST hi
, lo
, cu_index
;
2497 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2499 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2501 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2506 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2507 hex_string (lo
), hex_string (hi
));
2511 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2513 complaint (_(".gdb_index address table has invalid CU number %u"),
2514 (unsigned) cu_index
);
2518 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2519 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2520 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2521 per_bfd
->get_cu (cu_index
));
2524 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2528 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2529 populate the psymtabs_addrmap. */
2532 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2533 struct dwarf2_section_info
*section
)
2535 struct objfile
*objfile
= per_objfile
->objfile
;
2536 bfd
*abfd
= objfile
->obfd
;
2537 struct gdbarch
*gdbarch
= objfile
->arch ();
2538 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2539 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2541 auto_obstack temp_obstack
;
2542 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2544 std::unordered_map
<sect_offset
,
2545 dwarf2_per_cu_data
*,
2546 gdb::hash_enum
<sect_offset
>>
2547 debug_info_offset_to_per_cu
;
2548 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2550 const auto insertpair
2551 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2553 if (!insertpair
.second
)
2555 warning (_("Section .debug_aranges in %s has duplicate "
2556 "debug_info_offset %s, ignoring .debug_aranges."),
2557 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2562 section
->read (objfile
);
2564 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2566 const gdb_byte
*addr
= section
->buffer
;
2568 while (addr
< section
->buffer
+ section
->size
)
2570 const gdb_byte
*const entry_addr
= addr
;
2571 unsigned int bytes_read
;
2573 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2577 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2578 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2579 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2580 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2582 warning (_("Section .debug_aranges in %s entry at offset %s "
2583 "length %s exceeds section length %s, "
2584 "ignoring .debug_aranges."),
2585 objfile_name (objfile
),
2586 plongest (entry_addr
- section
->buffer
),
2587 plongest (bytes_read
+ entry_length
),
2588 pulongest (section
->size
));
2592 /* The version number. */
2593 const uint16_t version
= read_2_bytes (abfd
, addr
);
2597 warning (_("Section .debug_aranges in %s entry at offset %s "
2598 "has unsupported version %d, ignoring .debug_aranges."),
2599 objfile_name (objfile
),
2600 plongest (entry_addr
- section
->buffer
), version
);
2604 const uint64_t debug_info_offset
2605 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2606 addr
+= offset_size
;
2607 const auto per_cu_it
2608 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2609 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2611 warning (_("Section .debug_aranges in %s entry at offset %s "
2612 "debug_info_offset %s does not exists, "
2613 "ignoring .debug_aranges."),
2614 objfile_name (objfile
),
2615 plongest (entry_addr
- section
->buffer
),
2616 pulongest (debug_info_offset
));
2619 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2621 const uint8_t address_size
= *addr
++;
2622 if (address_size
< 1 || address_size
> 8)
2624 warning (_("Section .debug_aranges in %s entry at offset %s "
2625 "address_size %u is invalid, ignoring .debug_aranges."),
2626 objfile_name (objfile
),
2627 plongest (entry_addr
- section
->buffer
), address_size
);
2631 const uint8_t segment_selector_size
= *addr
++;
2632 if (segment_selector_size
!= 0)
2634 warning (_("Section .debug_aranges in %s entry at offset %s "
2635 "segment_selector_size %u is not supported, "
2636 "ignoring .debug_aranges."),
2637 objfile_name (objfile
),
2638 plongest (entry_addr
- section
->buffer
),
2639 segment_selector_size
);
2643 /* Must pad to an alignment boundary that is twice the address
2644 size. It is undocumented by the DWARF standard but GCC does
2646 for (size_t padding
= ((-(addr
- section
->buffer
))
2647 & (2 * address_size
- 1));
2648 padding
> 0; padding
--)
2651 warning (_("Section .debug_aranges in %s entry at offset %s "
2652 "padding is not zero, ignoring .debug_aranges."),
2653 objfile_name (objfile
),
2654 plongest (entry_addr
- section
->buffer
));
2660 if (addr
+ 2 * address_size
> entry_end
)
2662 warning (_("Section .debug_aranges in %s entry at offset %s "
2663 "address list is not properly terminated, "
2664 "ignoring .debug_aranges."),
2665 objfile_name (objfile
),
2666 plongest (entry_addr
- section
->buffer
));
2669 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2671 addr
+= address_size
;
2672 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2674 addr
+= address_size
;
2675 if (start
== 0 && length
== 0)
2677 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2679 /* Symbol was eliminated due to a COMDAT group. */
2682 ULONGEST end
= start
+ length
;
2683 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2685 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2687 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2691 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2695 /* A helper function that reads the .gdb_index from BUFFER and fills
2696 in MAP. FILENAME is the name of the file containing the data;
2697 it is used for error reporting. DEPRECATED_OK is true if it is
2698 ok to use deprecated sections.
2700 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2701 out parameters that are filled in with information about the CU and
2702 TU lists in the section.
2704 Returns true if all went well, false otherwise. */
2707 read_gdb_index_from_buffer (const char *filename
,
2709 gdb::array_view
<const gdb_byte
> buffer
,
2710 struct mapped_index
*map
,
2711 const gdb_byte
**cu_list
,
2712 offset_type
*cu_list_elements
,
2713 const gdb_byte
**types_list
,
2714 offset_type
*types_list_elements
)
2716 const gdb_byte
*addr
= &buffer
[0];
2717 offset_view
metadata (buffer
);
2719 /* Version check. */
2720 offset_type version
= metadata
[0];
2721 /* Versions earlier than 3 emitted every copy of a psymbol. This
2722 causes the index to behave very poorly for certain requests. Version 3
2723 contained incomplete addrmap. So, it seems better to just ignore such
2727 static int warning_printed
= 0;
2728 if (!warning_printed
)
2730 warning (_("Skipping obsolete .gdb_index section in %s."),
2732 warning_printed
= 1;
2736 /* Index version 4 uses a different hash function than index version
2739 Versions earlier than 6 did not emit psymbols for inlined
2740 functions. Using these files will cause GDB not to be able to
2741 set breakpoints on inlined functions by name, so we ignore these
2742 indices unless the user has done
2743 "set use-deprecated-index-sections on". */
2744 if (version
< 6 && !deprecated_ok
)
2746 static int warning_printed
= 0;
2747 if (!warning_printed
)
2750 Skipping deprecated .gdb_index section in %s.\n\
2751 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2752 to use the section anyway."),
2754 warning_printed
= 1;
2758 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2759 of the TU (for symbols coming from TUs),
2760 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2761 Plus gold-generated indices can have duplicate entries for global symbols,
2762 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2763 These are just performance bugs, and we can't distinguish gdb-generated
2764 indices from gold-generated ones, so issue no warning here. */
2766 /* Indexes with higher version than the one supported by GDB may be no
2767 longer backward compatible. */
2771 map
->version
= version
;
2774 *cu_list
= addr
+ metadata
[i
];
2775 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2778 *types_list
= addr
+ metadata
[i
];
2779 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2782 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2783 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2785 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2788 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2789 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2791 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2795 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2800 /* Callback types for dwarf2_read_gdb_index. */
2802 typedef gdb::function_view
2803 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2804 get_gdb_index_contents_ftype
;
2805 typedef gdb::function_view
2806 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2807 get_gdb_index_contents_dwz_ftype
;
2809 /* Read .gdb_index. If everything went ok, initialize the "quick"
2810 elements of all the CUs and return 1. Otherwise, return 0. */
2813 dwarf2_read_gdb_index
2814 (dwarf2_per_objfile
*per_objfile
,
2815 get_gdb_index_contents_ftype get_gdb_index_contents
,
2816 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2818 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2819 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2820 struct dwz_file
*dwz
;
2821 struct objfile
*objfile
= per_objfile
->objfile
;
2822 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2824 gdb::array_view
<const gdb_byte
> main_index_contents
2825 = get_gdb_index_contents (objfile
, per_bfd
);
2827 if (main_index_contents
.empty ())
2830 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2831 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2832 use_deprecated_index_sections
,
2833 main_index_contents
, map
.get (), &cu_list
,
2834 &cu_list_elements
, &types_list
,
2835 &types_list_elements
))
2838 /* Don't use the index if it's empty. */
2839 if (map
->symbol_table
.empty ())
2842 /* If there is a .dwz file, read it so we can get its CU list as
2844 dwz
= dwarf2_get_dwz_file (per_bfd
);
2847 struct mapped_index dwz_map
;
2848 const gdb_byte
*dwz_types_ignore
;
2849 offset_type dwz_types_elements_ignore
;
2851 gdb::array_view
<const gdb_byte
> dwz_index_content
2852 = get_gdb_index_contents_dwz (objfile
, dwz
);
2854 if (dwz_index_content
.empty ())
2857 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2858 1, dwz_index_content
, &dwz_map
,
2859 &dwz_list
, &dwz_list_elements
,
2861 &dwz_types_elements_ignore
))
2863 warning (_("could not read '.gdb_index' section from %s; skipping"),
2864 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2869 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2872 if (types_list_elements
)
2874 /* We can only handle a single .debug_types when we have an
2876 if (per_bfd
->types
.size () != 1)
2879 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2881 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2882 types_list_elements
);
2885 create_addrmap_from_index (per_objfile
, map
.get ());
2887 per_bfd
->index_table
= std::move (map
);
2888 per_bfd
->using_index
= 1;
2889 per_bfd
->quick_file_names_table
=
2890 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2895 /* die_reader_func for dw2_get_file_names. */
2898 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2899 struct die_info
*comp_unit_die
)
2901 struct dwarf2_cu
*cu
= reader
->cu
;
2902 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2903 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2904 struct dwarf2_per_cu_data
*lh_cu
;
2905 struct attribute
*attr
;
2907 struct quick_file_names
*qfn
;
2909 gdb_assert (! this_cu
->is_debug_types
);
2911 /* Our callers never want to match partial units -- instead they
2912 will match the enclosing full CU. */
2913 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2915 this_cu
->v
.quick
->no_file_data
= 1;
2923 sect_offset line_offset
{};
2925 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2926 if (attr
!= nullptr && attr
->form_is_unsigned ())
2928 struct quick_file_names find_entry
;
2930 line_offset
= (sect_offset
) attr
->as_unsigned ();
2932 /* We may have already read in this line header (TU line header sharing).
2933 If we have we're done. */
2934 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2935 find_entry
.hash
.line_sect_off
= line_offset
;
2936 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2937 &find_entry
, INSERT
);
2940 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
2944 lh
= dwarf_decode_line_header (line_offset
, cu
);
2948 lh_cu
->v
.quick
->no_file_data
= 1;
2952 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2953 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2954 qfn
->hash
.line_sect_off
= line_offset
;
2955 gdb_assert (slot
!= NULL
);
2958 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
2961 if (strcmp (fnd
.name
, "<unknown>") != 0)
2964 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
2966 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2967 qfn
->num_file_names
);
2969 qfn
->file_names
[0] = xstrdup (fnd
.name
);
2970 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
2971 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
2972 fnd
.comp_dir
).release ();
2973 qfn
->real_names
= NULL
;
2975 lh_cu
->v
.quick
->file_names
= qfn
;
2978 /* A helper for the "quick" functions which attempts to read the line
2979 table for THIS_CU. */
2981 static struct quick_file_names
*
2982 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2983 dwarf2_per_objfile
*per_objfile
)
2985 /* This should never be called for TUs. */
2986 gdb_assert (! this_cu
->is_debug_types
);
2987 /* Nor type unit groups. */
2988 gdb_assert (! this_cu
->type_unit_group_p ());
2990 if (this_cu
->v
.quick
->file_names
!= NULL
)
2991 return this_cu
->v
.quick
->file_names
;
2992 /* If we know there is no line data, no point in looking again. */
2993 if (this_cu
->v
.quick
->no_file_data
)
2996 cutu_reader
reader (this_cu
, per_objfile
);
2997 if (!reader
.dummy_p
)
2998 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3000 if (this_cu
->v
.quick
->no_file_data
)
3002 return this_cu
->v
.quick
->file_names
;
3005 /* A helper for the "quick" functions which computes and caches the
3006 real path for a given file name from the line table. */
3009 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3010 struct quick_file_names
*qfn
, int index
)
3012 if (qfn
->real_names
== NULL
)
3013 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3014 qfn
->num_file_names
, const char *);
3016 if (qfn
->real_names
[index
] == NULL
)
3017 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3019 return qfn
->real_names
[index
];
3023 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3025 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3026 dwarf2_per_cu_data
*dwarf_cu
3027 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3028 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3033 return compunit_primary_filetab (cust
);
3036 /* Traversal function for dw2_forget_cached_source_info. */
3039 dw2_free_cached_file_names (void **slot
, void *info
)
3041 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3043 if (file_data
->real_names
)
3047 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3049 xfree ((void*) file_data
->real_names
[i
]);
3050 file_data
->real_names
[i
] = NULL
;
3058 dwarf2_base_index_functions::forget_cached_source_info
3059 (struct objfile
*objfile
)
3061 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3063 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3064 dw2_free_cached_file_names
, NULL
);
3067 /* Struct used to manage iterating over all CUs looking for a symbol. */
3069 struct dw2_symtab_iterator
3071 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3072 dwarf2_per_objfile
*per_objfile
;
3073 /* If set, only look for symbols that match that block. Valid values are
3074 GLOBAL_BLOCK and STATIC_BLOCK. */
3075 gdb::optional
<block_enum
> block_index
;
3076 /* The kind of symbol we're looking for. */
3078 /* The list of CUs from the index entry of the symbol,
3079 or NULL if not found. */
3081 /* The next element in VEC to look at. */
3083 /* The number of elements in VEC, or zero if there is no match. */
3085 /* Have we seen a global version of the symbol?
3086 If so we can ignore all further global instances.
3087 This is to work around gold/15646, inefficient gold-generated
3092 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3095 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3096 dwarf2_per_objfile
*per_objfile
,
3097 gdb::optional
<block_enum
> block_index
,
3098 domain_enum domain
, offset_type namei
)
3100 iter
->per_objfile
= per_objfile
;
3101 iter
->block_index
= block_index
;
3102 iter
->domain
= domain
;
3104 iter
->global_seen
= 0;
3108 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3109 /* index is NULL if OBJF_READNOW. */
3113 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3114 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3116 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3117 iter
->length
= iter
->vec
[0];
3120 /* Return the next matching CU or NULL if there are no more. */
3122 static struct dwarf2_per_cu_data
*
3123 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3125 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3127 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3129 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3130 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3131 gdb_index_symbol_kind symbol_kind
=
3132 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3133 /* Only check the symbol attributes if they're present.
3134 Indices prior to version 7 don't record them,
3135 and indices >= 7 may elide them for certain symbols
3136 (gold does this). */
3138 (per_objfile
->per_bfd
->index_table
->version
>= 7
3139 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3141 /* Don't crash on bad data. */
3142 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3144 complaint (_(".gdb_index entry has bad CU index"
3145 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3149 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3151 /* Skip if already read in. */
3152 if (per_objfile
->symtab_set_p (per_cu
))
3155 /* Check static vs global. */
3158 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3160 if (iter
->block_index
.has_value ())
3162 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3164 if (is_static
!= want_static
)
3168 /* Work around gold/15646. */
3170 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3172 if (iter
->global_seen
)
3175 iter
->global_seen
= 1;
3179 /* Only check the symbol's kind if it has one. */
3182 switch (iter
->domain
)
3185 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3186 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3187 /* Some types are also in VAR_DOMAIN. */
3188 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3192 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3196 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3200 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3216 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3222 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3223 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3226 for (int i
= 0; i
< total
; ++i
)
3228 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3230 if (!per_objfile
->symtab_set_p (per_cu
))
3233 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3234 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3237 /* This dumps minimal information about the index.
3238 It is called via "mt print objfiles".
3239 One use is to verify .gdb_index has been loaded by the
3240 gdb.dwarf2/gdb-index.exp testcase. */
3243 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3245 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3247 gdb_assert (per_objfile
->per_bfd
->using_index
);
3248 printf_filtered (".gdb_index:");
3249 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3251 printf_filtered (" version %d\n",
3252 per_objfile
->per_bfd
->index_table
->version
);
3255 printf_filtered (" faked for \"readnow\"\n");
3256 printf_filtered ("\n");
3260 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3262 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3263 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3265 for (int i
= 0; i
< total_units
; ++i
)
3267 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3269 /* We don't want to directly expand a partial CU, because if we
3270 read it with the wrong language, then assertion failures can
3271 be triggered later on. See PR symtab/23010. So, tell
3272 dw2_instantiate_symtab to skip partial CUs -- any important
3273 partial CU will be read via DW_TAG_imported_unit anyway. */
3274 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3279 dw2_expand_symtabs_matching_symbol
3280 (mapped_index_base
&index
,
3281 const lookup_name_info
&lookup_name_in
,
3282 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3283 gdb::function_view
<bool (offset_type
)> match_callback
,
3284 dwarf2_per_objfile
*per_objfile
);
3287 dw2_expand_symtabs_matching_one
3288 (dwarf2_per_cu_data
*per_cu
,
3289 dwarf2_per_objfile
*per_objfile
,
3290 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3291 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3294 dwarf2_gdb_index::expand_matching_symbols
3295 (struct objfile
*objfile
,
3296 const lookup_name_info
&name
, domain_enum domain
,
3298 symbol_compare_ftype
*ordered_compare
)
3301 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3303 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3305 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3307 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3309 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3310 auto matcher
= [&] (const char *symname
)
3312 if (ordered_compare
== nullptr)
3314 return ordered_compare (symname
, match_name
) == 0;
3317 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3318 [&] (offset_type namei
)
3320 struct dw2_symtab_iterator iter
;
3321 struct dwarf2_per_cu_data
*per_cu
;
3323 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3325 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3326 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3333 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3334 proceed assuming all symtabs have been read in. */
3338 /* Starting from a search name, return the string that finds the upper
3339 bound of all strings that start with SEARCH_NAME in a sorted name
3340 list. Returns the empty string to indicate that the upper bound is
3341 the end of the list. */
3344 make_sort_after_prefix_name (const char *search_name
)
3346 /* When looking to complete "func", we find the upper bound of all
3347 symbols that start with "func" by looking for where we'd insert
3348 the closest string that would follow "func" in lexicographical
3349 order. Usually, that's "func"-with-last-character-incremented,
3350 i.e. "fund". Mind non-ASCII characters, though. Usually those
3351 will be UTF-8 multi-byte sequences, but we can't be certain.
3352 Especially mind the 0xff character, which is a valid character in
3353 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3354 rule out compilers allowing it in identifiers. Note that
3355 conveniently, strcmp/strcasecmp are specified to compare
3356 characters interpreted as unsigned char. So what we do is treat
3357 the whole string as a base 256 number composed of a sequence of
3358 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3359 to 0, and carries 1 to the following more-significant position.
3360 If the very first character in SEARCH_NAME ends up incremented
3361 and carries/overflows, then the upper bound is the end of the
3362 list. The string after the empty string is also the empty
3365 Some examples of this operation:
3367 SEARCH_NAME => "+1" RESULT
3371 "\xff" "a" "\xff" => "\xff" "b"
3376 Then, with these symbols for example:
3382 completing "func" looks for symbols between "func" and
3383 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3384 which finds "func" and "func1", but not "fund".
3388 funcÿ (Latin1 'ÿ' [0xff])
3392 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3393 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3397 ÿÿ (Latin1 'ÿ' [0xff])
3400 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3401 the end of the list.
3403 std::string after
= search_name
;
3404 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3406 if (!after
.empty ())
3407 after
.back () = (unsigned char) after
.back () + 1;
3411 /* See declaration. */
3413 std::pair
<std::vector
<name_component
>::const_iterator
,
3414 std::vector
<name_component
>::const_iterator
>
3415 mapped_index_base::find_name_components_bounds
3416 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3417 dwarf2_per_objfile
*per_objfile
) const
3420 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3422 const char *lang_name
3423 = lookup_name_without_params
.language_lookup_name (lang
);
3425 /* Comparison function object for lower_bound that matches against a
3426 given symbol name. */
3427 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3430 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3431 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3432 return name_cmp (elem_name
, name
) < 0;
3435 /* Comparison function object for upper_bound that matches against a
3436 given symbol name. */
3437 auto lookup_compare_upper
= [&] (const char *name
,
3438 const name_component
&elem
)
3440 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3441 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3442 return name_cmp (name
, elem_name
) < 0;
3445 auto begin
= this->name_components
.begin ();
3446 auto end
= this->name_components
.end ();
3448 /* Find the lower bound. */
3451 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3454 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3457 /* Find the upper bound. */
3460 if (lookup_name_without_params
.completion_mode ())
3462 /* In completion mode, we want UPPER to point past all
3463 symbols names that have the same prefix. I.e., with
3464 these symbols, and completing "func":
3466 function << lower bound
3468 other_function << upper bound
3470 We find the upper bound by looking for the insertion
3471 point of "func"-with-last-character-incremented,
3473 std::string after
= make_sort_after_prefix_name (lang_name
);
3476 return std::lower_bound (lower
, end
, after
.c_str (),
3477 lookup_compare_lower
);
3480 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3483 return {lower
, upper
};
3486 /* See declaration. */
3489 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3491 if (!this->name_components
.empty ())
3494 this->name_components_casing
= case_sensitivity
;
3496 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3498 /* The code below only knows how to break apart components of C++
3499 symbol names (and other languages that use '::' as
3500 namespace/module separator) and Ada symbol names. */
3501 auto count
= this->symbol_name_count ();
3502 for (offset_type idx
= 0; idx
< count
; idx
++)
3504 if (this->symbol_name_slot_invalid (idx
))
3507 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3509 /* Add each name component to the name component table. */
3510 unsigned int previous_len
= 0;
3512 if (strstr (name
, "::") != nullptr)
3514 for (unsigned int current_len
= cp_find_first_component (name
);
3515 name
[current_len
] != '\0';
3516 current_len
+= cp_find_first_component (name
+ current_len
))
3518 gdb_assert (name
[current_len
] == ':');
3519 this->name_components
.push_back ({previous_len
, idx
});
3520 /* Skip the '::'. */
3522 previous_len
= current_len
;
3527 /* Handle the Ada encoded (aka mangled) form here. */
3528 for (const char *iter
= strstr (name
, "__");
3530 iter
= strstr (iter
, "__"))
3532 this->name_components
.push_back ({previous_len
, idx
});
3534 previous_len
= iter
- name
;
3538 this->name_components
.push_back ({previous_len
, idx
});
3541 /* Sort name_components elements by name. */
3542 auto name_comp_compare
= [&] (const name_component
&left
,
3543 const name_component
&right
)
3545 const char *left_qualified
3546 = this->symbol_name_at (left
.idx
, per_objfile
);
3547 const char *right_qualified
3548 = this->symbol_name_at (right
.idx
, per_objfile
);
3550 const char *left_name
= left_qualified
+ left
.name_offset
;
3551 const char *right_name
= right_qualified
+ right
.name_offset
;
3553 return name_cmp (left_name
, right_name
) < 0;
3556 std::sort (this->name_components
.begin (),
3557 this->name_components
.end (),
3561 /* Helper for dw2_expand_symtabs_matching that works with a
3562 mapped_index_base instead of the containing objfile. This is split
3563 to a separate function in order to be able to unit test the
3564 name_components matching using a mock mapped_index_base. For each
3565 symbol name that matches, calls MATCH_CALLBACK, passing it the
3566 symbol's index in the mapped_index_base symbol table. */
3569 dw2_expand_symtabs_matching_symbol
3570 (mapped_index_base
&index
,
3571 const lookup_name_info
&lookup_name_in
,
3572 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3573 gdb::function_view
<bool (offset_type
)> match_callback
,
3574 dwarf2_per_objfile
*per_objfile
)
3576 lookup_name_info lookup_name_without_params
3577 = lookup_name_in
.make_ignore_params ();
3579 /* Build the symbol name component sorted vector, if we haven't
3581 index
.build_name_components (per_objfile
);
3583 /* The same symbol may appear more than once in the range though.
3584 E.g., if we're looking for symbols that complete "w", and we have
3585 a symbol named "w1::w2", we'll find the two name components for
3586 that same symbol in the range. To be sure we only call the
3587 callback once per symbol, we first collect the symbol name
3588 indexes that matched in a temporary vector and ignore
3590 std::vector
<offset_type
> matches
;
3592 struct name_and_matcher
3594 symbol_name_matcher_ftype
*matcher
;
3597 bool operator== (const name_and_matcher
&other
) const
3599 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3603 /* A vector holding all the different symbol name matchers, for all
3605 std::vector
<name_and_matcher
> matchers
;
3607 for (int i
= 0; i
< nr_languages
; i
++)
3609 enum language lang_e
= (enum language
) i
;
3611 const language_defn
*lang
= language_def (lang_e
);
3612 symbol_name_matcher_ftype
*name_matcher
3613 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3615 name_and_matcher key
{
3617 lookup_name_without_params
.language_lookup_name (lang_e
)
3620 /* Don't insert the same comparison routine more than once.
3621 Note that we do this linear walk. This is not a problem in
3622 practice because the number of supported languages is
3624 if (std::find (matchers
.begin (), matchers
.end (), key
)
3627 matchers
.push_back (std::move (key
));
3630 = index
.find_name_components_bounds (lookup_name_without_params
,
3631 lang_e
, per_objfile
);
3633 /* Now for each symbol name in range, check to see if we have a name
3634 match, and if so, call the MATCH_CALLBACK callback. */
3636 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3638 const char *qualified
3639 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3641 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3642 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3645 matches
.push_back (bounds
.first
->idx
);
3649 std::sort (matches
.begin (), matches
.end ());
3651 /* Finally call the callback, once per match. */
3654 for (offset_type idx
: matches
)
3658 if (!match_callback (idx
))
3667 /* Above we use a type wider than idx's for 'prev', since 0 and
3668 (offset_type)-1 are both possible values. */
3669 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3676 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3678 /* A mock .gdb_index/.debug_names-like name index table, enough to
3679 exercise dw2_expand_symtabs_matching_symbol, which works with the
3680 mapped_index_base interface. Builds an index from the symbol list
3681 passed as parameter to the constructor. */
3682 class mock_mapped_index
: public mapped_index_base
3685 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3686 : m_symbol_table (symbols
)
3689 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3691 /* Return the number of names in the symbol table. */
3692 size_t symbol_name_count () const override
3694 return m_symbol_table
.size ();
3697 /* Get the name of the symbol at IDX in the symbol table. */
3698 const char *symbol_name_at
3699 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3701 return m_symbol_table
[idx
];
3705 gdb::array_view
<const char *> m_symbol_table
;
3708 /* Convenience function that converts a NULL pointer to a "<null>"
3709 string, to pass to print routines. */
3712 string_or_null (const char *str
)
3714 return str
!= NULL
? str
: "<null>";
3717 /* Check if a lookup_name_info built from
3718 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3719 index. EXPECTED_LIST is the list of expected matches, in expected
3720 matching order. If no match expected, then an empty list is
3721 specified. Returns true on success. On failure prints a warning
3722 indicating the file:line that failed, and returns false. */
3725 check_match (const char *file
, int line
,
3726 mock_mapped_index
&mock_index
,
3727 const char *name
, symbol_name_match_type match_type
,
3728 bool completion_mode
,
3729 std::initializer_list
<const char *> expected_list
,
3730 dwarf2_per_objfile
*per_objfile
)
3732 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3734 bool matched
= true;
3736 auto mismatch
= [&] (const char *expected_str
,
3739 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3740 "expected=\"%s\", got=\"%s\"\n"),
3742 (match_type
== symbol_name_match_type::FULL
3744 name
, string_or_null (expected_str
), string_or_null (got
));
3748 auto expected_it
= expected_list
.begin ();
3749 auto expected_end
= expected_list
.end ();
3751 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3753 [&] (offset_type idx
)
3755 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3756 const char *expected_str
3757 = expected_it
== expected_end
? NULL
: *expected_it
++;
3759 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3760 mismatch (expected_str
, matched_name
);
3764 const char *expected_str
3765 = expected_it
== expected_end
? NULL
: *expected_it
++;
3766 if (expected_str
!= NULL
)
3767 mismatch (expected_str
, NULL
);
3772 /* The symbols added to the mock mapped_index for testing (in
3774 static const char *test_symbols
[] = {
3783 "ns2::tmpl<int>::foo2",
3784 "(anonymous namespace)::A::B::C",
3786 /* These are used to check that the increment-last-char in the
3787 matching algorithm for completion doesn't match "t1_fund" when
3788 completing "t1_func". */
3794 /* A UTF-8 name with multi-byte sequences to make sure that
3795 cp-name-parser understands this as a single identifier ("função"
3796 is "function" in PT). */
3799 /* \377 (0xff) is Latin1 'ÿ'. */
3802 /* \377 (0xff) is Latin1 'ÿ'. */
3806 /* A name with all sorts of complications. Starts with "z" to make
3807 it easier for the completion tests below. */
3808 #define Z_SYM_NAME \
3809 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3810 "::tuple<(anonymous namespace)::ui*, " \
3811 "std::default_delete<(anonymous namespace)::ui>, void>"
3816 /* Returns true if the mapped_index_base::find_name_component_bounds
3817 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3818 in completion mode. */
3821 check_find_bounds_finds (mapped_index_base
&index
,
3822 const char *search_name
,
3823 gdb::array_view
<const char *> expected_syms
,
3824 dwarf2_per_objfile
*per_objfile
)
3826 lookup_name_info
lookup_name (search_name
,
3827 symbol_name_match_type::FULL
, true);
3829 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3833 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3834 if (distance
!= expected_syms
.size ())
3837 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3839 auto nc_elem
= bounds
.first
+ exp_elem
;
3840 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3841 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3848 /* Test the lower-level mapped_index::find_name_component_bounds
3852 test_mapped_index_find_name_component_bounds ()
3854 mock_mapped_index
mock_index (test_symbols
);
3856 mock_index
.build_name_components (NULL
/* per_objfile */);
3858 /* Test the lower-level mapped_index::find_name_component_bounds
3859 method in completion mode. */
3861 static const char *expected_syms
[] = {
3866 SELF_CHECK (check_find_bounds_finds
3867 (mock_index
, "t1_func", expected_syms
,
3868 NULL
/* per_objfile */));
3871 /* Check that the increment-last-char in the name matching algorithm
3872 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3874 static const char *expected_syms1
[] = {
3878 SELF_CHECK (check_find_bounds_finds
3879 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3881 static const char *expected_syms2
[] = {
3884 SELF_CHECK (check_find_bounds_finds
3885 (mock_index
, "\377\377", expected_syms2
,
3886 NULL
/* per_objfile */));
3890 /* Test dw2_expand_symtabs_matching_symbol. */
3893 test_dw2_expand_symtabs_matching_symbol ()
3895 mock_mapped_index
mock_index (test_symbols
);
3897 /* We let all tests run until the end even if some fails, for debug
3899 bool any_mismatch
= false;
3901 /* Create the expected symbols list (an initializer_list). Needed
3902 because lists have commas, and we need to pass them to CHECK,
3903 which is a macro. */
3904 #define EXPECT(...) { __VA_ARGS__ }
3906 /* Wrapper for check_match that passes down the current
3907 __FILE__/__LINE__. */
3908 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3909 any_mismatch |= !check_match (__FILE__, __LINE__, \
3911 NAME, MATCH_TYPE, COMPLETION_MODE, \
3912 EXPECTED_LIST, NULL)
3914 /* Identity checks. */
3915 for (const char *sym
: test_symbols
)
3917 /* Should be able to match all existing symbols. */
3918 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
3921 /* Should be able to match all existing symbols with
3923 std::string with_params
= std::string (sym
) + "(int)";
3924 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3927 /* Should be able to match all existing symbols with
3928 parameters and qualifiers. */
3929 with_params
= std::string (sym
) + " ( int ) const";
3930 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3933 /* This should really find sym, but cp-name-parser.y doesn't
3934 know about lvalue/rvalue qualifiers yet. */
3935 with_params
= std::string (sym
) + " ( int ) &&";
3936 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3940 /* Check that the name matching algorithm for completion doesn't get
3941 confused with Latin1 'ÿ' / 0xff. */
3943 static const char str
[] = "\377";
3944 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3945 EXPECT ("\377", "\377\377123"));
3948 /* Check that the increment-last-char in the matching algorithm for
3949 completion doesn't match "t1_fund" when completing "t1_func". */
3951 static const char str
[] = "t1_func";
3952 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3953 EXPECT ("t1_func", "t1_func1"));
3956 /* Check that completion mode works at each prefix of the expected
3959 static const char str
[] = "function(int)";
3960 size_t len
= strlen (str
);
3963 for (size_t i
= 1; i
< len
; i
++)
3965 lookup
.assign (str
, i
);
3966 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3967 EXPECT ("function"));
3971 /* While "w" is a prefix of both components, the match function
3972 should still only be called once. */
3974 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
3976 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
3980 /* Same, with a "complicated" symbol. */
3982 static const char str
[] = Z_SYM_NAME
;
3983 size_t len
= strlen (str
);
3986 for (size_t i
= 1; i
< len
; i
++)
3988 lookup
.assign (str
, i
);
3989 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3990 EXPECT (Z_SYM_NAME
));
3994 /* In FULL mode, an incomplete symbol doesn't match. */
3996 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4000 /* A complete symbol with parameters matches any overload, since the
4001 index has no overload info. */
4003 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4004 EXPECT ("std::zfunction", "std::zfunction2"));
4005 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4006 EXPECT ("std::zfunction", "std::zfunction2"));
4007 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4008 EXPECT ("std::zfunction", "std::zfunction2"));
4011 /* Check that whitespace is ignored appropriately. A symbol with a
4012 template argument list. */
4014 static const char expected
[] = "ns::foo<int>";
4015 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4017 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4021 /* Check that whitespace is ignored appropriately. A symbol with a
4022 template argument list that includes a pointer. */
4024 static const char expected
[] = "ns::foo<char*>";
4025 /* Try both completion and non-completion modes. */
4026 static const bool completion_mode
[2] = {false, true};
4027 for (size_t i
= 0; i
< 2; i
++)
4029 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4030 completion_mode
[i
], EXPECT (expected
));
4031 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4032 completion_mode
[i
], EXPECT (expected
));
4034 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4035 completion_mode
[i
], EXPECT (expected
));
4036 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4037 completion_mode
[i
], EXPECT (expected
));
4042 /* Check method qualifiers are ignored. */
4043 static const char expected
[] = "ns::foo<char*>";
4044 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4045 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4046 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4047 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4048 CHECK_MATCH ("foo < char * > ( int ) const",
4049 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4050 CHECK_MATCH ("foo < char * > ( int ) &&",
4051 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4054 /* Test lookup names that don't match anything. */
4056 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4059 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4063 /* Some wild matching tests, exercising "(anonymous namespace)",
4064 which should not be confused with a parameter list. */
4066 static const char *syms
[] = {
4070 "A :: B :: C ( int )",
4075 for (const char *s
: syms
)
4077 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4078 EXPECT ("(anonymous namespace)::A::B::C"));
4083 static const char expected
[] = "ns2::tmpl<int>::foo2";
4084 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4086 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4090 SELF_CHECK (!any_mismatch
);
4099 test_mapped_index_find_name_component_bounds ();
4100 test_dw2_expand_symtabs_matching_symbol ();
4103 }} // namespace selftests::dw2_expand_symtabs_matching
4105 #endif /* GDB_SELF_TEST */
4107 /* If FILE_MATCHER is NULL or if PER_CU has
4108 dwarf2_per_cu_quick_data::MARK set (see
4109 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4110 EXPANSION_NOTIFY on it. */
4113 dw2_expand_symtabs_matching_one
4114 (dwarf2_per_cu_data
*per_cu
,
4115 dwarf2_per_objfile
*per_objfile
,
4116 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4117 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4119 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4121 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4123 compunit_symtab
*symtab
4124 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4125 gdb_assert (symtab
!= nullptr);
4127 if (expansion_notify
!= NULL
&& symtab_was_null
)
4128 return expansion_notify (symtab
);
4133 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4134 matched, to expand corresponding CUs that were marked. IDX is the
4135 index of the symbol name that matched. */
4138 dw2_expand_marked_cus
4139 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4140 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4141 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4142 block_search_flags search_flags
,
4145 offset_type vec_len
, vec_idx
;
4146 bool global_seen
= false;
4147 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4149 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4151 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4153 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4154 /* This value is only valid for index versions >= 7. */
4155 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4156 gdb_index_symbol_kind symbol_kind
=
4157 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4158 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4159 /* Only check the symbol attributes if they're present.
4160 Indices prior to version 7 don't record them,
4161 and indices >= 7 may elide them for certain symbols
4162 (gold does this). */
4165 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4167 /* Work around gold/15646. */
4170 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4178 /* Only check the symbol's kind if it has one. */
4183 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4188 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4194 case VARIABLES_DOMAIN
:
4195 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4198 case FUNCTIONS_DOMAIN
:
4199 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4203 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4206 case MODULES_DOMAIN
:
4207 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4215 /* Don't crash on bad data. */
4216 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4218 complaint (_(".gdb_index entry has bad CU index"
4219 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4223 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4224 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4232 /* If FILE_MATCHER is non-NULL, set all the
4233 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4234 that match FILE_MATCHER. */
4237 dw_expand_symtabs_matching_file_matcher
4238 (dwarf2_per_objfile
*per_objfile
,
4239 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4241 if (file_matcher
== NULL
)
4244 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4246 NULL
, xcalloc
, xfree
));
4247 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4249 NULL
, xcalloc
, xfree
));
4251 /* The rule is CUs specify all the files, including those used by
4252 any TU, so there's no need to scan TUs here. */
4254 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4258 if (per_cu
->is_debug_types
)
4260 per_cu
->v
.quick
->mark
= 0;
4262 /* We only need to look at symtabs not already expanded. */
4263 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4266 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4268 if (file_data
== NULL
)
4271 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4273 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4275 per_cu
->v
.quick
->mark
= 1;
4279 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4281 const char *this_real_name
;
4283 if (file_matcher (file_data
->file_names
[j
], false))
4285 per_cu
->v
.quick
->mark
= 1;
4289 /* Before we invoke realpath, which can get expensive when many
4290 files are involved, do a quick comparison of the basenames. */
4291 if (!basenames_may_differ
4292 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4296 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4297 if (file_matcher (this_real_name
, false))
4299 per_cu
->v
.quick
->mark
= 1;
4304 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4305 ? visited_found
.get ()
4306 : visited_not_found
.get (),
4313 dwarf2_gdb_index::expand_symtabs_matching
4314 (struct objfile
*objfile
,
4315 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4316 const lookup_name_info
*lookup_name
,
4317 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4318 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4319 block_search_flags search_flags
,
4321 enum search_domain kind
)
4323 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4325 /* index_table is NULL if OBJF_READNOW. */
4326 if (!per_objfile
->per_bfd
->index_table
)
4329 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4331 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4333 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4337 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
4345 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4348 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4350 [&] (offset_type idx
)
4352 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4353 expansion_notify
, search_flags
, kind
))
4361 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4364 static struct compunit_symtab
*
4365 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4370 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4371 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4374 if (cust
->includes
== NULL
)
4377 for (i
= 0; cust
->includes
[i
]; ++i
)
4379 struct compunit_symtab
*s
= cust
->includes
[i
];
4381 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4389 struct compunit_symtab
*
4390 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4391 (struct objfile
*objfile
,
4392 struct bound_minimal_symbol msymbol
,
4394 struct obj_section
*section
,
4397 struct dwarf2_per_cu_data
*data
;
4398 struct compunit_symtab
*result
;
4400 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4401 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4404 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4405 data
= ((struct dwarf2_per_cu_data
*)
4406 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4411 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4412 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4413 paddress (objfile
->arch (), pc
));
4415 result
= recursively_find_pc_sect_compunit_symtab
4416 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4418 gdb_assert (result
!= NULL
);
4423 dwarf2_base_index_functions::map_symbol_filenames
4424 (struct objfile
*objfile
,
4425 gdb::function_view
<symbol_filename_ftype
> fun
,
4428 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4430 /* Use caches to ensure we only call FUN once for each filename. */
4431 filename_seen_cache filenames_cache
;
4432 std::unordered_set
<quick_file_names
*> qfn_cache
;
4434 /* The rule is CUs specify all the files, including those used by any TU,
4435 so there's no need to scan TUs here. We can ignore file names coming
4436 from already-expanded CUs. It is possible that an expanded CU might
4437 reuse the file names data from a currently unexpanded CU, in this
4438 case we don't want to report the files from the unexpanded CU. */
4440 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4442 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4444 if (per_cu
->v
.quick
->file_names
!= nullptr)
4445 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4449 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4451 /* We only need to look at symtabs not already expanded. */
4452 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4455 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4457 if (file_data
== nullptr
4458 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4461 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4463 const char *filename
= file_data
->file_names
[j
];
4464 filenames_cache
.seen (filename
);
4468 filenames_cache
.traverse ([&] (const char *filename
)
4470 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4473 this_real_name
= gdb_realpath (filename
);
4474 fun (filename
, this_real_name
.get ());
4479 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4484 /* DWARF-5 debug_names reader. */
4486 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4487 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4489 /* A helper function that reads the .debug_names section in SECTION
4490 and fills in MAP. FILENAME is the name of the file containing the
4491 section; it is used for error reporting.
4493 Returns true if all went well, false otherwise. */
4496 read_debug_names_from_section (struct objfile
*objfile
,
4497 const char *filename
,
4498 struct dwarf2_section_info
*section
,
4499 mapped_debug_names
&map
)
4501 if (section
->empty ())
4504 /* Older elfutils strip versions could keep the section in the main
4505 executable while splitting it for the separate debug info file. */
4506 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4509 section
->read (objfile
);
4511 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4513 const gdb_byte
*addr
= section
->buffer
;
4515 bfd
*const abfd
= section
->get_bfd_owner ();
4517 unsigned int bytes_read
;
4518 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4521 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4522 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4523 if (bytes_read
+ length
!= section
->size
)
4525 /* There may be multiple per-CU indices. */
4526 warning (_("Section .debug_names in %s length %s does not match "
4527 "section length %s, ignoring .debug_names."),
4528 filename
, plongest (bytes_read
+ length
),
4529 pulongest (section
->size
));
4533 /* The version number. */
4534 uint16_t version
= read_2_bytes (abfd
, addr
);
4538 warning (_("Section .debug_names in %s has unsupported version %d, "
4539 "ignoring .debug_names."),
4545 uint16_t padding
= read_2_bytes (abfd
, addr
);
4549 warning (_("Section .debug_names in %s has unsupported padding %d, "
4550 "ignoring .debug_names."),
4555 /* comp_unit_count - The number of CUs in the CU list. */
4556 map
.cu_count
= read_4_bytes (abfd
, addr
);
4559 /* local_type_unit_count - The number of TUs in the local TU
4561 map
.tu_count
= read_4_bytes (abfd
, addr
);
4564 /* foreign_type_unit_count - The number of TUs in the foreign TU
4566 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4568 if (foreign_tu_count
!= 0)
4570 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4571 "ignoring .debug_names."),
4572 filename
, static_cast<unsigned long> (foreign_tu_count
));
4576 /* bucket_count - The number of hash buckets in the hash lookup
4578 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4581 /* name_count - The number of unique names in the index. */
4582 map
.name_count
= read_4_bytes (abfd
, addr
);
4585 /* abbrev_table_size - The size in bytes of the abbreviations
4587 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4590 /* augmentation_string_size - The size in bytes of the augmentation
4591 string. This value is rounded up to a multiple of 4. */
4592 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4594 map
.augmentation_is_gdb
= ((augmentation_string_size
4595 == sizeof (dwarf5_augmentation
))
4596 && memcmp (addr
, dwarf5_augmentation
,
4597 sizeof (dwarf5_augmentation
)) == 0);
4598 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4599 addr
+= augmentation_string_size
;
4602 map
.cu_table_reordered
= addr
;
4603 addr
+= map
.cu_count
* map
.offset_size
;
4605 /* List of Local TUs */
4606 map
.tu_table_reordered
= addr
;
4607 addr
+= map
.tu_count
* map
.offset_size
;
4609 /* Hash Lookup Table */
4610 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4611 addr
+= map
.bucket_count
* 4;
4612 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4613 addr
+= map
.name_count
* 4;
4616 map
.name_table_string_offs_reordered
= addr
;
4617 addr
+= map
.name_count
* map
.offset_size
;
4618 map
.name_table_entry_offs_reordered
= addr
;
4619 addr
+= map
.name_count
* map
.offset_size
;
4621 const gdb_byte
*abbrev_table_start
= addr
;
4624 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4629 const auto insertpair
4630 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4631 if (!insertpair
.second
)
4633 warning (_("Section .debug_names in %s has duplicate index %s, "
4634 "ignoring .debug_names."),
4635 filename
, pulongest (index_num
));
4638 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4639 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4644 mapped_debug_names::index_val::attr attr
;
4645 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4647 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4649 if (attr
.form
== DW_FORM_implicit_const
)
4651 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4655 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4657 indexval
.attr_vec
.push_back (std::move (attr
));
4660 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4662 warning (_("Section .debug_names in %s has abbreviation_table "
4663 "of size %s vs. written as %u, ignoring .debug_names."),
4664 filename
, plongest (addr
- abbrev_table_start
),
4668 map
.entry_pool
= addr
;
4673 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4677 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4678 const mapped_debug_names
&map
,
4679 dwarf2_section_info
§ion
,
4682 if (!map
.augmentation_is_gdb
)
4684 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4686 sect_offset sect_off
4687 = (sect_offset
) (extract_unsigned_integer
4688 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4690 map
.dwarf5_byte_order
));
4691 /* We don't know the length of the CU, because the CU list in a
4692 .debug_names index can be incomplete, so we can't use the start
4693 of the next CU as end of this CU. We create the CUs here with
4694 length 0, and in cutu_reader::cutu_reader we'll fill in the
4696 dwarf2_per_cu_data_up per_cu
4697 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4699 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4704 sect_offset sect_off_prev
;
4705 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4707 sect_offset sect_off_next
;
4708 if (i
< map
.cu_count
)
4711 = (sect_offset
) (extract_unsigned_integer
4712 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4714 map
.dwarf5_byte_order
));
4717 sect_off_next
= (sect_offset
) section
.size
;
4720 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4721 dwarf2_per_cu_data_up per_cu
4722 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4723 sect_off_prev
, length
);
4724 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4726 sect_off_prev
= sect_off_next
;
4730 /* Read the CU list from the mapped index, and use it to create all
4731 the CU objects for this dwarf2_per_objfile. */
4734 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4735 const mapped_debug_names
&map
,
4736 const mapped_debug_names
&dwz_map
)
4738 gdb_assert (per_bfd
->all_comp_units
.empty ());
4739 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4741 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4742 false /* is_dwz */);
4744 if (dwz_map
.cu_count
== 0)
4747 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4748 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4752 /* Read .debug_names. If everything went ok, initialize the "quick"
4753 elements of all the CUs and return true. Otherwise, return false. */
4756 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4758 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4759 mapped_debug_names dwz_map
;
4760 struct objfile
*objfile
= per_objfile
->objfile
;
4761 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4763 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4764 &per_bfd
->debug_names
, *map
))
4767 /* Don't use the index if it's empty. */
4768 if (map
->name_count
== 0)
4771 /* If there is a .dwz file, read it so we can get its CU list as
4773 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4776 if (!read_debug_names_from_section (objfile
,
4777 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4778 &dwz
->debug_names
, dwz_map
))
4780 warning (_("could not read '.debug_names' section from %s; skipping"),
4781 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4786 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4788 if (map
->tu_count
!= 0)
4790 /* We can only handle a single .debug_types when we have an
4792 if (per_bfd
->types
.size () != 1)
4795 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4797 create_signatured_type_table_from_debug_names
4798 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4801 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4803 per_bfd
->debug_names_table
= std::move (map
);
4804 per_bfd
->using_index
= 1;
4805 per_bfd
->quick_file_names_table
=
4806 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4811 /* Type used to manage iterating over all CUs looking for a symbol for
4814 class dw2_debug_names_iterator
4817 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4818 block_search_flags block_index
,
4820 const char *name
, dwarf2_per_objfile
*per_objfile
)
4821 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4822 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4823 m_per_objfile (per_objfile
)
4826 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4827 search_domain search
, uint32_t namei
,
4828 dwarf2_per_objfile
*per_objfile
,
4829 domain_enum domain
= UNDEF_DOMAIN
)
4833 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4834 m_per_objfile (per_objfile
)
4837 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4838 block_search_flags block_index
, domain_enum domain
,
4839 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4840 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4841 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4842 m_per_objfile (per_objfile
)
4845 /* Return the next matching CU or NULL if there are no more. */
4846 dwarf2_per_cu_data
*next ();
4849 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4851 dwarf2_per_objfile
*per_objfile
);
4852 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4854 dwarf2_per_objfile
*per_objfile
);
4856 /* The internalized form of .debug_names. */
4857 const mapped_debug_names
&m_map
;
4859 /* Restrict the search to these blocks. */
4860 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4861 | SEARCH_STATIC_BLOCK
);
4863 /* The kind of symbol we're looking for. */
4864 const domain_enum m_domain
= UNDEF_DOMAIN
;
4865 const search_domain m_search
= ALL_DOMAIN
;
4867 /* The list of CUs from the index entry of the symbol, or NULL if
4869 const gdb_byte
*m_addr
;
4871 dwarf2_per_objfile
*m_per_objfile
;
4875 mapped_debug_names::namei_to_name
4876 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4878 const ULONGEST namei_string_offs
4879 = extract_unsigned_integer ((name_table_string_offs_reordered
4880 + namei
* offset_size
),
4883 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4886 /* Find a slot in .debug_names for the object named NAME. If NAME is
4887 found, return pointer to its pool data. If NAME cannot be found,
4891 dw2_debug_names_iterator::find_vec_in_debug_names
4892 (const mapped_debug_names
&map
, const char *name
,
4893 dwarf2_per_objfile
*per_objfile
)
4895 int (*cmp
) (const char *, const char *);
4897 gdb::unique_xmalloc_ptr
<char> without_params
;
4898 if (current_language
->la_language
== language_cplus
4899 || current_language
->la_language
== language_fortran
4900 || current_language
->la_language
== language_d
)
4902 /* NAME is already canonical. Drop any qualifiers as
4903 .debug_names does not contain any. */
4905 if (strchr (name
, '(') != NULL
)
4907 without_params
= cp_remove_params (name
);
4908 if (without_params
!= NULL
)
4909 name
= without_params
.get ();
4913 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
4915 const uint32_t full_hash
= dwarf5_djb_hash (name
);
4917 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4918 (map
.bucket_table_reordered
4919 + (full_hash
% map
.bucket_count
)), 4,
4920 map
.dwarf5_byte_order
);
4924 if (namei
>= map
.name_count
)
4926 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4928 namei
, map
.name_count
,
4929 objfile_name (per_objfile
->objfile
));
4935 const uint32_t namei_full_hash
4936 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4937 (map
.hash_table_reordered
+ namei
), 4,
4938 map
.dwarf5_byte_order
);
4939 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
4942 if (full_hash
== namei_full_hash
)
4944 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
4946 #if 0 /* An expensive sanity check. */
4947 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
4949 complaint (_("Wrong .debug_names hash for string at index %u "
4951 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
4956 if (cmp (namei_string
, name
) == 0)
4958 const ULONGEST namei_entry_offs
4959 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4960 + namei
* map
.offset_size
),
4961 map
.offset_size
, map
.dwarf5_byte_order
);
4962 return map
.entry_pool
+ namei_entry_offs
;
4967 if (namei
>= map
.name_count
)
4973 dw2_debug_names_iterator::find_vec_in_debug_names
4974 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4976 if (namei
>= map
.name_count
)
4978 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4980 namei
, map
.name_count
,
4981 objfile_name (per_objfile
->objfile
));
4985 const ULONGEST namei_entry_offs
4986 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4987 + namei
* map
.offset_size
),
4988 map
.offset_size
, map
.dwarf5_byte_order
);
4989 return map
.entry_pool
+ namei_entry_offs
;
4992 /* See dw2_debug_names_iterator. */
4994 dwarf2_per_cu_data
*
4995 dw2_debug_names_iterator::next ()
5000 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5001 struct objfile
*objfile
= m_per_objfile
->objfile
;
5002 bfd
*const abfd
= objfile
->obfd
;
5006 unsigned int bytes_read
;
5007 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5008 m_addr
+= bytes_read
;
5012 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5013 if (indexval_it
== m_map
.abbrev_map
.cend ())
5015 complaint (_("Wrong .debug_names undefined abbrev code %s "
5017 pulongest (abbrev
), objfile_name (objfile
));
5020 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5021 enum class symbol_linkage
{
5025 } symbol_linkage_
= symbol_linkage::unknown
;
5026 dwarf2_per_cu_data
*per_cu
= NULL
;
5027 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5032 case DW_FORM_implicit_const
:
5033 ull
= attr
.implicit_const
;
5035 case DW_FORM_flag_present
:
5039 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5040 m_addr
+= bytes_read
;
5043 ull
= read_4_bytes (abfd
, m_addr
);
5047 ull
= read_8_bytes (abfd
, m_addr
);
5050 case DW_FORM_ref_sig8
:
5051 ull
= read_8_bytes (abfd
, m_addr
);
5055 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5056 dwarf_form_name (attr
.form
),
5057 objfile_name (objfile
));
5060 switch (attr
.dw_idx
)
5062 case DW_IDX_compile_unit
:
5063 /* Don't crash on bad data. */
5064 if (ull
>= per_bfd
->all_comp_units
.size ())
5066 complaint (_(".debug_names entry has bad CU index %s"
5069 objfile_name (objfile
));
5072 per_cu
= per_bfd
->get_cu (ull
);
5074 case DW_IDX_type_unit
:
5075 /* Don't crash on bad data. */
5076 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5078 complaint (_(".debug_names entry has bad TU index %s"
5081 objfile_name (objfile
));
5084 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5086 case DW_IDX_die_offset
:
5087 /* In a per-CU index (as opposed to a per-module index), index
5088 entries without CU attribute implicitly refer to the single CU. */
5090 per_cu
= per_bfd
->get_cu (0);
5092 case DW_IDX_GNU_internal
:
5093 if (!m_map
.augmentation_is_gdb
)
5095 symbol_linkage_
= symbol_linkage::static_
;
5097 case DW_IDX_GNU_external
:
5098 if (!m_map
.augmentation_is_gdb
)
5100 symbol_linkage_
= symbol_linkage::extern_
;
5105 /* Skip if already read in. */
5106 if (m_per_objfile
->symtab_set_p (per_cu
))
5109 /* Check static vs global. */
5110 if (symbol_linkage_
!= symbol_linkage::unknown
)
5112 if (symbol_linkage_
== symbol_linkage::static_
)
5114 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5119 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5124 /* Match dw2_symtab_iter_next, symbol_kind
5125 and debug_names::psymbol_tag. */
5129 switch (indexval
.dwarf_tag
)
5131 case DW_TAG_variable
:
5132 case DW_TAG_subprogram
:
5133 /* Some types are also in VAR_DOMAIN. */
5134 case DW_TAG_typedef
:
5135 case DW_TAG_structure_type
:
5142 switch (indexval
.dwarf_tag
)
5144 case DW_TAG_typedef
:
5145 case DW_TAG_structure_type
:
5152 switch (indexval
.dwarf_tag
)
5155 case DW_TAG_variable
:
5162 switch (indexval
.dwarf_tag
)
5174 /* Match dw2_expand_symtabs_matching, symbol_kind and
5175 debug_names::psymbol_tag. */
5178 case VARIABLES_DOMAIN
:
5179 switch (indexval
.dwarf_tag
)
5181 case DW_TAG_variable
:
5187 case FUNCTIONS_DOMAIN
:
5188 switch (indexval
.dwarf_tag
)
5190 case DW_TAG_subprogram
:
5197 switch (indexval
.dwarf_tag
)
5199 case DW_TAG_typedef
:
5200 case DW_TAG_structure_type
:
5206 case MODULES_DOMAIN
:
5207 switch (indexval
.dwarf_tag
)
5221 /* This dumps minimal information about .debug_names. It is called
5222 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5223 uses this to verify that .debug_names has been loaded. */
5226 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5228 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5230 gdb_assert (per_objfile
->per_bfd
->using_index
);
5231 printf_filtered (".debug_names:");
5232 if (per_objfile
->per_bfd
->debug_names_table
)
5233 printf_filtered (" exists\n");
5235 printf_filtered (" faked for \"readnow\"\n");
5236 printf_filtered ("\n");
5240 dwarf2_debug_names_index::expand_matching_symbols
5241 (struct objfile
*objfile
,
5242 const lookup_name_info
&name
, domain_enum domain
,
5244 symbol_compare_ftype
*ordered_compare
)
5246 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5248 /* debug_names_table is NULL if OBJF_READNOW. */
5249 if (!per_objfile
->per_bfd
->debug_names_table
)
5252 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5253 const block_search_flags block_flags
5254 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5256 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5257 auto matcher
= [&] (const char *symname
)
5259 if (ordered_compare
== nullptr)
5261 return ordered_compare (symname
, match_name
) == 0;
5264 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5265 [&] (offset_type namei
)
5267 /* The name was matched, now expand corresponding CUs that were
5269 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5272 struct dwarf2_per_cu_data
*per_cu
;
5273 while ((per_cu
= iter
.next ()) != NULL
)
5274 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5281 dwarf2_debug_names_index::expand_symtabs_matching
5282 (struct objfile
*objfile
,
5283 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5284 const lookup_name_info
*lookup_name
,
5285 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5286 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5287 block_search_flags search_flags
,
5289 enum search_domain kind
)
5291 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5293 /* debug_names_table is NULL if OBJF_READNOW. */
5294 if (!per_objfile
->per_bfd
->debug_names_table
)
5297 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5299 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5301 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5305 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
5313 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5316 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5318 [&] (offset_type namei
)
5320 /* The name was matched, now expand corresponding CUs that were
5322 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5324 struct dwarf2_per_cu_data
*per_cu
;
5325 while ((per_cu
= iter
.next ()) != NULL
)
5326 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5336 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5337 to either a dwarf2_per_bfd or dwz_file object. */
5339 template <typename T
>
5340 static gdb::array_view
<const gdb_byte
>
5341 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5343 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5345 if (section
->empty ())
5348 /* Older elfutils strip versions could keep the section in the main
5349 executable while splitting it for the separate debug info file. */
5350 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5353 section
->read (obj
);
5355 /* dwarf2_section_info::size is a bfd_size_type, while
5356 gdb::array_view works with size_t. On 32-bit hosts, with
5357 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5358 is 32-bit. So we need an explicit narrowing conversion here.
5359 This is fine, because it's impossible to allocate or mmap an
5360 array/buffer larger than what size_t can represent. */
5361 return gdb::make_array_view (section
->buffer
, section
->size
);
5364 /* Lookup the index cache for the contents of the index associated to
5367 static gdb::array_view
<const gdb_byte
>
5368 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5370 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5371 if (build_id
== nullptr)
5374 return global_index_cache
.lookup_gdb_index (build_id
,
5375 &dwarf2_per_bfd
->index_cache_res
);
5378 /* Same as the above, but for DWZ. */
5380 static gdb::array_view
<const gdb_byte
>
5381 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5383 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5384 if (build_id
== nullptr)
5387 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5390 /* See dwarf2/public.h. */
5393 dwarf2_initialize_objfile (struct objfile
*objfile
)
5395 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5396 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5398 dwarf_read_debug_printf ("called");
5400 /* If we're about to read full symbols, don't bother with the
5401 indices. In this case we also don't care if some other debug
5402 format is making psymtabs, because they are all about to be
5404 if ((objfile
->flags
& OBJF_READNOW
))
5406 dwarf_read_debug_printf ("readnow requested");
5408 /* When using READNOW, the using_index flag (set below) indicates that
5409 PER_BFD was already initialized, when we loaded some other objfile. */
5410 if (per_bfd
->using_index
)
5412 dwarf_read_debug_printf ("using_index already set");
5413 per_objfile
->resize_symtabs ();
5414 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5418 per_bfd
->using_index
= 1;
5419 create_all_comp_units (per_objfile
);
5420 per_bfd
->quick_file_names_table
5421 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5422 per_objfile
->resize_symtabs ();
5424 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5426 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5428 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5429 struct dwarf2_per_cu_quick_data
);
5432 /* Arrange for gdb to see the "quick" functions. However, these
5433 functions will be no-ops because we will have expanded all
5435 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5439 /* Was a debug names index already read when we processed an objfile sharing
5441 if (per_bfd
->debug_names_table
!= nullptr)
5443 dwarf_read_debug_printf ("re-using shared debug names table");
5444 per_objfile
->resize_symtabs ();
5445 objfile
->qf
.push_front (make_dwarf_debug_names ());
5449 /* Was a GDB index already read when we processed an objfile sharing
5451 if (per_bfd
->index_table
!= nullptr)
5453 dwarf_read_debug_printf ("re-using shared index table");
5454 per_objfile
->resize_symtabs ();
5455 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5459 /* There might already be partial symtabs built for this BFD. This happens
5460 when loading the same binary twice with the index-cache enabled. If so,
5461 don't try to read an index. The objfile / per_objfile initialization will
5462 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5464 if (per_bfd
->partial_symtabs
!= nullptr)
5466 dwarf_read_debug_printf ("re-using shared partial symtabs");
5467 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5471 if (dwarf2_read_debug_names (per_objfile
))
5473 dwarf_read_debug_printf ("found debug names");
5474 per_objfile
->resize_symtabs ();
5475 objfile
->qf
.push_front (make_dwarf_debug_names ());
5479 if (dwarf2_read_gdb_index (per_objfile
,
5480 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5481 get_gdb_index_contents_from_section
<dwz_file
>))
5483 dwarf_read_debug_printf ("found gdb index from file");
5484 per_objfile
->resize_symtabs ();
5485 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5489 /* ... otherwise, try to find the index in the index cache. */
5490 if (dwarf2_read_gdb_index (per_objfile
,
5491 get_gdb_index_contents_from_cache
,
5492 get_gdb_index_contents_from_cache_dwz
))
5494 dwarf_read_debug_printf ("found gdb index from cache");
5495 global_index_cache
.hit ();
5496 per_objfile
->resize_symtabs ();
5497 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5501 global_index_cache
.miss ();
5502 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5507 /* Build a partial symbol table. */
5510 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5512 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5513 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5515 if (per_bfd
->partial_symtabs
!= nullptr)
5517 /* Partial symbols were already read, so now we can simply
5521 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5522 objfile
->qf
.emplace_front (psf
);
5525 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5526 per_objfile
->resize_symtabs ();
5532 psf
= new psymbol_functions
;
5533 objfile
->qf
.emplace_front (psf
);
5535 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5536 = psf
->get_partial_symtabs ();
5538 /* Set the local reference to partial symtabs, so that we don't try
5539 to read them again if reading another objfile with the same BFD.
5540 If we can't in fact share, this won't make a difference anyway as
5541 the dwarf2_per_bfd object won't be shared. */
5542 per_bfd
->partial_symtabs
= partial_symtabs
;
5546 /* This isn't really ideal: all the data we allocate on the
5547 objfile's obstack is still uselessly kept around. However,
5548 freeing it seems unsafe. */
5549 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5550 dwarf2_build_psymtabs_hard (per_objfile
);
5553 per_objfile
->resize_symtabs ();
5555 /* (maybe) store an index in the cache. */
5556 global_index_cache
.store (per_objfile
);
5558 catch (const gdb_exception_error
&except
)
5560 exception_print (gdb_stderr
, except
);
5564 /* Find the base address of the compilation unit for range lists and
5565 location lists. It will normally be specified by DW_AT_low_pc.
5566 In DWARF-3 draft 4, the base address could be overridden by
5567 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5568 compilation units with discontinuous ranges. */
5571 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5573 struct attribute
*attr
;
5575 cu
->base_address
.reset ();
5577 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5578 if (attr
!= nullptr)
5579 cu
->base_address
= attr
->as_address ();
5582 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5583 if (attr
!= nullptr)
5584 cu
->base_address
= attr
->as_address ();
5588 /* Helper function that returns the proper abbrev section for
5591 static struct dwarf2_section_info
*
5592 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5594 struct dwarf2_section_info
*abbrev
;
5595 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5597 if (this_cu
->is_dwz
)
5598 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5600 abbrev
= &per_bfd
->abbrev
;
5605 /* Fetch the abbreviation table offset from a comp or type unit header. */
5608 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5609 struct dwarf2_section_info
*section
,
5610 sect_offset sect_off
)
5612 bfd
*abfd
= section
->get_bfd_owner ();
5613 const gdb_byte
*info_ptr
;
5614 unsigned int initial_length_size
, offset_size
;
5617 section
->read (per_objfile
->objfile
);
5618 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5619 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5620 offset_size
= initial_length_size
== 4 ? 4 : 8;
5621 info_ptr
+= initial_length_size
;
5623 version
= read_2_bytes (abfd
, info_ptr
);
5627 /* Skip unit type and address size. */
5631 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5634 /* A partial symtab that is used only for include files. */
5635 struct dwarf2_include_psymtab
: public partial_symtab
5637 dwarf2_include_psymtab (const char *filename
,
5638 psymtab_storage
*partial_symtabs
,
5639 objfile_per_bfd_storage
*objfile_per_bfd
)
5640 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5644 void read_symtab (struct objfile
*objfile
) override
5646 /* It's an include file, no symbols to read for it.
5647 Everything is in the includer symtab. */
5649 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5650 expansion of the includer psymtab. We use the dependencies[0] field to
5651 model the includer. But if we go the regular route of calling
5652 expand_psymtab here, and having expand_psymtab call expand_dependencies
5653 to expand the includer, we'll only use expand_psymtab on the includer
5654 (making it a non-toplevel psymtab), while if we expand the includer via
5655 another path, we'll use read_symtab (making it a toplevel psymtab).
5656 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5657 psymtab, and trigger read_symtab on the includer here directly. */
5658 includer ()->read_symtab (objfile
);
5661 void expand_psymtab (struct objfile
*objfile
) override
5663 /* This is not called by read_symtab, and should not be called by any
5664 expand_dependencies. */
5668 bool readin_p (struct objfile
*objfile
) const override
5670 return includer ()->readin_p (objfile
);
5673 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5679 partial_symtab
*includer () const
5681 /* An include psymtab has exactly one dependency: the psymtab that
5683 gdb_assert (this->number_of_dependencies
== 1);
5684 return this->dependencies
[0];
5688 /* Allocate a new partial symtab for file named NAME and mark this new
5689 partial symtab as being an include of PST. */
5692 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5694 dwarf2_psymtab
*pst
,
5695 psymtab_storage
*partial_symtabs
,
5696 objfile_per_bfd_storage
*objfile_per_bfd
)
5698 dwarf2_include_psymtab
*subpst
5699 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5701 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5702 subpst
->dirname
= pst
->dirname
;
5704 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5705 subpst
->dependencies
[0] = pst
;
5706 subpst
->number_of_dependencies
= 1;
5709 /* Read the Line Number Program data and extract the list of files
5710 included by the source file represented by PST. Build an include
5711 partial symtab for each of these included files. */
5714 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5715 struct die_info
*die
,
5716 dwarf2_psymtab
*pst
)
5719 struct attribute
*attr
;
5721 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5722 if (attr
!= nullptr && attr
->form_is_unsigned ())
5723 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5725 return; /* No linetable, so no includes. */
5727 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5728 that we pass in the raw text_low here; that is ok because we're
5729 only decoding the line table to make include partial symtabs, and
5730 so the addresses aren't really used. */
5731 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5732 pst
->raw_text_low (), 1);
5736 hash_signatured_type (const void *item
)
5738 const struct signatured_type
*sig_type
5739 = (const struct signatured_type
*) item
;
5741 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5742 return sig_type
->signature
;
5746 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5748 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5749 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5751 return lhs
->signature
== rhs
->signature
;
5754 /* Allocate a hash table for signatured types. */
5757 allocate_signatured_type_table ()
5759 return htab_up (htab_create_alloc (41,
5760 hash_signatured_type
,
5762 NULL
, xcalloc
, xfree
));
5765 /* A helper for create_debug_types_hash_table. Read types from SECTION
5766 and fill them into TYPES_HTAB. It will process only type units,
5767 therefore DW_UT_type. */
5770 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5771 struct dwo_file
*dwo_file
,
5772 dwarf2_section_info
*section
, htab_up
&types_htab
,
5773 rcuh_kind section_kind
)
5775 struct objfile
*objfile
= per_objfile
->objfile
;
5776 struct dwarf2_section_info
*abbrev_section
;
5778 const gdb_byte
*info_ptr
, *end_ptr
;
5780 abbrev_section
= &dwo_file
->sections
.abbrev
;
5782 dwarf_read_debug_printf ("Reading %s for %s",
5783 section
->get_name (),
5784 abbrev_section
->get_file_name ());
5786 section
->read (objfile
);
5787 info_ptr
= section
->buffer
;
5789 if (info_ptr
== NULL
)
5792 /* We can't set abfd until now because the section may be empty or
5793 not present, in which case the bfd is unknown. */
5794 abfd
= section
->get_bfd_owner ();
5796 /* We don't use cutu_reader here because we don't need to read
5797 any dies: the signature is in the header. */
5799 end_ptr
= info_ptr
+ section
->size
;
5800 while (info_ptr
< end_ptr
)
5802 std::unique_ptr
<signatured_type
> sig_type
;
5803 struct dwo_unit
*dwo_tu
;
5805 const gdb_byte
*ptr
= info_ptr
;
5806 struct comp_unit_head header
;
5807 unsigned int length
;
5809 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5811 /* Initialize it due to a false compiler warning. */
5812 header
.signature
= -1;
5813 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5815 /* We need to read the type's signature in order to build the hash
5816 table, but we don't need anything else just yet. */
5818 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5819 abbrev_section
, ptr
, section_kind
);
5821 length
= header
.get_length ();
5823 /* Skip dummy type units. */
5824 if (ptr
>= info_ptr
+ length
5825 || peek_abbrev_code (abfd
, ptr
) == 0
5826 || (header
.unit_type
!= DW_UT_type
5827 && header
.unit_type
!= DW_UT_split_type
))
5833 if (types_htab
== NULL
)
5834 types_htab
= allocate_dwo_unit_table ();
5836 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5837 dwo_tu
->dwo_file
= dwo_file
;
5838 dwo_tu
->signature
= header
.signature
;
5839 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5840 dwo_tu
->section
= section
;
5841 dwo_tu
->sect_off
= sect_off
;
5842 dwo_tu
->length
= length
;
5844 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5845 gdb_assert (slot
!= NULL
);
5847 complaint (_("debug type entry at offset %s is duplicate to"
5848 " the entry at offset %s, signature %s"),
5849 sect_offset_str (sect_off
),
5850 sect_offset_str (dwo_tu
->sect_off
),
5851 hex_string (header
.signature
));
5854 dwarf_read_debug_printf_v (" offset %s, signature %s",
5855 sect_offset_str (sect_off
),
5856 hex_string (header
.signature
));
5862 /* Create the hash table of all entries in the .debug_types
5863 (or .debug_types.dwo) section(s).
5864 DWO_FILE is a pointer to the DWO file object.
5866 The result is a pointer to the hash table or NULL if there are no types.
5868 Note: This function processes DWO files only, not DWP files. */
5871 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5872 struct dwo_file
*dwo_file
,
5873 gdb::array_view
<dwarf2_section_info
> type_sections
,
5874 htab_up
&types_htab
)
5876 for (dwarf2_section_info
§ion
: type_sections
)
5877 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5881 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5882 If SLOT is non-NULL, it is the entry to use in the hash table.
5883 Otherwise we find one. */
5885 static struct signatured_type
*
5886 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5888 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5889 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5890 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5892 std::unique_ptr
<signatured_type
> sig_type_holder
5893 = per_objfile
->per_bfd
->allocate_signatured_type ();
5894 signatured_type
*sig_type
= sig_type_holder
.get ();
5896 per_objfile
->resize_symtabs ();
5898 per_objfile
->per_bfd
->all_comp_units
.emplace_back
5899 (sig_type_holder
.release ());
5900 sig_type
->signature
= sig
;
5901 sig_type
->is_debug_types
= 1;
5902 if (per_objfile
->per_bfd
->using_index
)
5905 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
5906 struct dwarf2_per_cu_quick_data
);
5911 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5914 gdb_assert (*slot
== NULL
);
5916 /* The rest of sig_type must be filled in by the caller. */
5920 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5921 Fill in SIG_ENTRY with DWO_ENTRY. */
5924 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
5925 struct signatured_type
*sig_entry
,
5926 struct dwo_unit
*dwo_entry
)
5928 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5930 /* Make sure we're not clobbering something we don't expect to. */
5931 gdb_assert (! sig_entry
->queued
);
5932 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
5933 if (per_bfd
->using_index
)
5935 gdb_assert (sig_entry
->v
.quick
!= NULL
);
5936 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
5939 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
5940 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5941 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5942 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5943 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5945 sig_entry
->section
= dwo_entry
->section
;
5946 sig_entry
->sect_off
= dwo_entry
->sect_off
;
5947 sig_entry
->length
= dwo_entry
->length
;
5948 sig_entry
->reading_dwo_directly
= 1;
5949 sig_entry
->per_bfd
= per_bfd
;
5950 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5951 sig_entry
->dwo_unit
= dwo_entry
;
5954 /* Subroutine of lookup_signatured_type.
5955 If we haven't read the TU yet, create the signatured_type data structure
5956 for a TU to be read in directly from a DWO file, bypassing the stub.
5957 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5958 using .gdb_index, then when reading a CU we want to stay in the DWO file
5959 containing that CU. Otherwise we could end up reading several other DWO
5960 files (due to comdat folding) to process the transitive closure of all the
5961 mentioned TUs, and that can be slow. The current DWO file will have every
5962 type signature that it needs.
5963 We only do this for .gdb_index because in the psymtab case we already have
5964 to read all the DWOs to build the type unit groups. */
5966 static struct signatured_type
*
5967 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5969 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5970 struct dwo_file
*dwo_file
;
5971 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5972 struct signatured_type find_sig_entry
, *sig_entry
;
5975 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
5977 /* If TU skeletons have been removed then we may not have read in any
5979 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5980 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
5982 /* We only ever need to read in one copy of a signatured type.
5983 Use the global signatured_types array to do our own comdat-folding
5984 of types. If this is the first time we're reading this TU, and
5985 the TU has an entry in .gdb_index, replace the recorded data from
5986 .gdb_index with this TU. */
5988 find_sig_entry
.signature
= sig
;
5989 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5990 &find_sig_entry
, INSERT
);
5991 sig_entry
= (struct signatured_type
*) *slot
;
5993 /* We can get here with the TU already read, *or* in the process of being
5994 read. Don't reassign the global entry to point to this DWO if that's
5995 the case. Also note that if the TU is already being read, it may not
5996 have come from a DWO, the program may be a mix of Fission-compiled
5997 code and non-Fission-compiled code. */
5999 /* Have we already tried to read this TU?
6000 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6001 needn't exist in the global table yet). */
6002 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6005 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6006 dwo_unit of the TU itself. */
6007 dwo_file
= cu
->dwo_unit
->dwo_file
;
6009 /* Ok, this is the first time we're reading this TU. */
6010 if (dwo_file
->tus
== NULL
)
6012 find_dwo_entry
.signature
= sig
;
6013 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6015 if (dwo_entry
== NULL
)
6018 /* If the global table doesn't have an entry for this TU, add one. */
6019 if (sig_entry
== NULL
)
6020 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6022 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6023 sig_entry
->tu_read
= 1;
6027 /* Subroutine of lookup_signatured_type.
6028 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6029 then try the DWP file. If the TU stub (skeleton) has been removed then
6030 it won't be in .gdb_index. */
6032 static struct signatured_type
*
6033 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6035 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6036 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6037 struct dwo_unit
*dwo_entry
;
6038 struct signatured_type find_sig_entry
, *sig_entry
;
6041 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6042 gdb_assert (dwp_file
!= NULL
);
6044 /* If TU skeletons have been removed then we may not have read in any
6046 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6047 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6049 find_sig_entry
.signature
= sig
;
6050 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6051 &find_sig_entry
, INSERT
);
6052 sig_entry
= (struct signatured_type
*) *slot
;
6054 /* Have we already tried to read this TU?
6055 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6056 needn't exist in the global table yet). */
6057 if (sig_entry
!= NULL
)
6060 if (dwp_file
->tus
== NULL
)
6062 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6063 1 /* is_debug_types */);
6064 if (dwo_entry
== NULL
)
6067 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6068 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6073 /* Lookup a signature based type for DW_FORM_ref_sig8.
6074 Returns NULL if signature SIG is not present in the table.
6075 It is up to the caller to complain about this. */
6077 static struct signatured_type
*
6078 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6080 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6082 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6084 /* We're in a DWO/DWP file, and we're using .gdb_index.
6085 These cases require special processing. */
6086 if (get_dwp_file (per_objfile
) == NULL
)
6087 return lookup_dwo_signatured_type (cu
, sig
);
6089 return lookup_dwp_signatured_type (cu
, sig
);
6093 struct signatured_type find_entry
, *entry
;
6095 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6097 find_entry
.signature
= sig
;
6098 entry
= ((struct signatured_type
*)
6099 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6105 /* Low level DIE reading support. */
6107 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6110 init_cu_die_reader (struct die_reader_specs
*reader
,
6111 struct dwarf2_cu
*cu
,
6112 struct dwarf2_section_info
*section
,
6113 struct dwo_file
*dwo_file
,
6114 struct abbrev_table
*abbrev_table
)
6116 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6117 reader
->abfd
= section
->get_bfd_owner ();
6119 reader
->dwo_file
= dwo_file
;
6120 reader
->die_section
= section
;
6121 reader
->buffer
= section
->buffer
;
6122 reader
->buffer_end
= section
->buffer
+ section
->size
;
6123 reader
->abbrev_table
= abbrev_table
;
6126 /* Subroutine of cutu_reader to simplify it.
6127 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6128 There's just a lot of work to do, and cutu_reader is big enough
6131 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6132 from it to the DIE in the DWO. If NULL we are skipping the stub.
6133 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6134 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6135 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6136 STUB_COMP_DIR may be non-NULL.
6137 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6138 are filled in with the info of the DIE from the DWO file.
6139 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6140 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6141 kept around for at least as long as *RESULT_READER.
6143 The result is non-zero if a valid (non-dummy) DIE was found. */
6146 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6147 struct dwo_unit
*dwo_unit
,
6148 struct die_info
*stub_comp_unit_die
,
6149 const char *stub_comp_dir
,
6150 struct die_reader_specs
*result_reader
,
6151 const gdb_byte
**result_info_ptr
,
6152 struct die_info
**result_comp_unit_die
,
6153 abbrev_table_up
*result_dwo_abbrev_table
)
6155 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6156 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6157 struct objfile
*objfile
= per_objfile
->objfile
;
6159 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6160 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6161 int i
,num_extra_attrs
;
6162 struct dwarf2_section_info
*dwo_abbrev_section
;
6163 struct die_info
*comp_unit_die
;
6165 /* At most one of these may be provided. */
6166 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6168 /* These attributes aren't processed until later:
6169 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6170 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6171 referenced later. However, these attributes are found in the stub
6172 which we won't have later. In order to not impose this complication
6173 on the rest of the code, we read them here and copy them to the
6182 if (stub_comp_unit_die
!= NULL
)
6184 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6186 if (!per_cu
->is_debug_types
)
6187 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6188 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6189 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6190 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6191 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6193 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6195 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6196 We need the value before we can process DW_AT_ranges values from the
6198 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6200 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6201 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6202 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6203 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6205 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6207 else if (stub_comp_dir
!= NULL
)
6209 /* Reconstruct the comp_dir attribute to simplify the code below. */
6210 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6211 comp_dir
->name
= DW_AT_comp_dir
;
6212 comp_dir
->form
= DW_FORM_string
;
6213 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6216 /* Set up for reading the DWO CU/TU. */
6217 cu
->dwo_unit
= dwo_unit
;
6218 dwarf2_section_info
*section
= dwo_unit
->section
;
6219 section
->read (objfile
);
6220 abfd
= section
->get_bfd_owner ();
6221 begin_info_ptr
= info_ptr
= (section
->buffer
6222 + to_underlying (dwo_unit
->sect_off
));
6223 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6225 if (per_cu
->is_debug_types
)
6227 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6229 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6230 section
, dwo_abbrev_section
,
6231 info_ptr
, rcuh_kind::TYPE
);
6232 /* This is not an assert because it can be caused by bad debug info. */
6233 if (sig_type
->signature
!= cu
->header
.signature
)
6235 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6236 " TU at offset %s [in module %s]"),
6237 hex_string (sig_type
->signature
),
6238 hex_string (cu
->header
.signature
),
6239 sect_offset_str (dwo_unit
->sect_off
),
6240 bfd_get_filename (abfd
));
6242 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6243 /* For DWOs coming from DWP files, we don't know the CU length
6244 nor the type's offset in the TU until now. */
6245 dwo_unit
->length
= cu
->header
.get_length ();
6246 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6248 /* Establish the type offset that can be used to lookup the type.
6249 For DWO files, we don't know it until now. */
6250 sig_type
->type_offset_in_section
6251 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6255 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6256 section
, dwo_abbrev_section
,
6257 info_ptr
, rcuh_kind::COMPILE
);
6258 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6259 /* For DWOs coming from DWP files, we don't know the CU length
6261 dwo_unit
->length
= cu
->header
.get_length ();
6264 dwo_abbrev_section
->read (objfile
);
6265 *result_dwo_abbrev_table
6266 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6267 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6268 result_dwo_abbrev_table
->get ());
6270 /* Read in the die, but leave space to copy over the attributes
6271 from the stub. This has the benefit of simplifying the rest of
6272 the code - all the work to maintain the illusion of a single
6273 DW_TAG_{compile,type}_unit DIE is done here. */
6274 num_extra_attrs
= ((stmt_list
!= NULL
)
6278 + (comp_dir
!= NULL
));
6279 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6282 /* Copy over the attributes from the stub to the DIE we just read in. */
6283 comp_unit_die
= *result_comp_unit_die
;
6284 i
= comp_unit_die
->num_attrs
;
6285 if (stmt_list
!= NULL
)
6286 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6288 comp_unit_die
->attrs
[i
++] = *low_pc
;
6289 if (high_pc
!= NULL
)
6290 comp_unit_die
->attrs
[i
++] = *high_pc
;
6292 comp_unit_die
->attrs
[i
++] = *ranges
;
6293 if (comp_dir
!= NULL
)
6294 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6295 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6297 if (dwarf_die_debug
)
6299 fprintf_unfiltered (gdb_stdlog
,
6300 "Read die from %s@0x%x of %s:\n",
6301 section
->get_name (),
6302 (unsigned) (begin_info_ptr
- section
->buffer
),
6303 bfd_get_filename (abfd
));
6304 dump_die (comp_unit_die
, dwarf_die_debug
);
6307 /* Skip dummy compilation units. */
6308 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6309 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6312 *result_info_ptr
= info_ptr
;
6316 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6317 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6318 signature is part of the header. */
6319 static gdb::optional
<ULONGEST
>
6320 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6322 if (cu
->header
.version
>= 5)
6323 return cu
->header
.signature
;
6324 struct attribute
*attr
;
6325 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6326 if (attr
== nullptr || !attr
->form_is_unsigned ())
6327 return gdb::optional
<ULONGEST
> ();
6328 return attr
->as_unsigned ();
6331 /* Subroutine of cutu_reader to simplify it.
6332 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6333 Returns NULL if the specified DWO unit cannot be found. */
6335 static struct dwo_unit
*
6336 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6338 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6339 struct dwo_unit
*dwo_unit
;
6340 const char *comp_dir
;
6342 gdb_assert (cu
!= NULL
);
6344 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6345 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6346 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6348 if (per_cu
->is_debug_types
)
6349 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6352 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6354 if (!signature
.has_value ())
6355 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6357 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6359 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6365 /* Subroutine of cutu_reader to simplify it.
6366 See it for a description of the parameters.
6367 Read a TU directly from a DWO file, bypassing the stub. */
6370 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6371 dwarf2_per_objfile
*per_objfile
,
6372 dwarf2_cu
*existing_cu
)
6374 struct signatured_type
*sig_type
;
6376 /* Verify we can do the following downcast, and that we have the
6378 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6379 sig_type
= (struct signatured_type
*) this_cu
;
6380 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6384 if (existing_cu
!= nullptr)
6387 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6388 /* There's no need to do the rereading_dwo_cu handling that
6389 cutu_reader does since we don't read the stub. */
6393 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6394 in per_objfile yet. */
6395 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6396 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6397 cu
= m_new_cu
.get ();
6400 /* A future optimization, if needed, would be to use an existing
6401 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6402 could share abbrev tables. */
6404 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6405 NULL
/* stub_comp_unit_die */,
6406 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6409 &m_dwo_abbrev_table
) == 0)
6416 /* Initialize a CU (or TU) and read its DIEs.
6417 If the CU defers to a DWO file, read the DWO file as well.
6419 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6420 Otherwise the table specified in the comp unit header is read in and used.
6421 This is an optimization for when we already have the abbrev table.
6423 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6426 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6427 dwarf2_per_objfile
*per_objfile
,
6428 struct abbrev_table
*abbrev_table
,
6429 dwarf2_cu
*existing_cu
,
6431 : die_reader_specs
{},
6434 struct objfile
*objfile
= per_objfile
->objfile
;
6435 struct dwarf2_section_info
*section
= this_cu
->section
;
6436 bfd
*abfd
= section
->get_bfd_owner ();
6437 const gdb_byte
*begin_info_ptr
;
6438 struct signatured_type
*sig_type
= NULL
;
6439 struct dwarf2_section_info
*abbrev_section
;
6440 /* Non-zero if CU currently points to a DWO file and we need to
6441 reread it. When this happens we need to reread the skeleton die
6442 before we can reread the DWO file (this only applies to CUs, not TUs). */
6443 int rereading_dwo_cu
= 0;
6445 if (dwarf_die_debug
)
6446 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6447 this_cu
->is_debug_types
? "type" : "comp",
6448 sect_offset_str (this_cu
->sect_off
));
6450 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6451 file (instead of going through the stub), short-circuit all of this. */
6452 if (this_cu
->reading_dwo_directly
)
6454 /* Narrow down the scope of possibilities to have to understand. */
6455 gdb_assert (this_cu
->is_debug_types
);
6456 gdb_assert (abbrev_table
== NULL
);
6457 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6461 /* This is cheap if the section is already read in. */
6462 section
->read (objfile
);
6464 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6466 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6470 if (existing_cu
!= nullptr)
6473 /* If this CU is from a DWO file we need to start over, we need to
6474 refetch the attributes from the skeleton CU.
6475 This could be optimized by retrieving those attributes from when we
6476 were here the first time: the previous comp_unit_die was stored in
6477 comp_unit_obstack. But there's no data yet that we need this
6479 if (cu
->dwo_unit
!= NULL
)
6480 rereading_dwo_cu
= 1;
6484 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6485 in per_objfile yet. */
6486 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6487 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6488 cu
= m_new_cu
.get ();
6491 /* Get the header. */
6492 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6494 /* We already have the header, there's no need to read it in again. */
6495 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6499 if (this_cu
->is_debug_types
)
6501 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6502 section
, abbrev_section
,
6503 info_ptr
, rcuh_kind::TYPE
);
6505 /* Since per_cu is the first member of struct signatured_type,
6506 we can go from a pointer to one to a pointer to the other. */
6507 sig_type
= (struct signatured_type
*) this_cu
;
6508 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6509 gdb_assert (sig_type
->type_offset_in_tu
6510 == cu
->header
.type_cu_offset_in_tu
);
6511 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6513 /* LENGTH has not been set yet for type units if we're
6514 using .gdb_index. */
6515 this_cu
->length
= cu
->header
.get_length ();
6517 /* Establish the type offset that can be used to lookup the type. */
6518 sig_type
->type_offset_in_section
=
6519 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6521 this_cu
->dwarf_version
= cu
->header
.version
;
6525 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6526 section
, abbrev_section
,
6528 rcuh_kind::COMPILE
);
6530 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6531 if (this_cu
->length
== 0)
6532 this_cu
->length
= cu
->header
.get_length ();
6534 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6535 this_cu
->dwarf_version
= cu
->header
.version
;
6539 /* Skip dummy compilation units. */
6540 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6541 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6547 /* If we don't have them yet, read the abbrevs for this compilation unit.
6548 And if we need to read them now, make sure they're freed when we're
6550 if (abbrev_table
!= NULL
)
6551 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6554 abbrev_section
->read (objfile
);
6555 m_abbrev_table_holder
6556 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6557 abbrev_table
= m_abbrev_table_holder
.get ();
6560 /* Read the top level CU/TU die. */
6561 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6562 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6564 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6570 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6571 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6572 table from the DWO file and pass the ownership over to us. It will be
6573 referenced from READER, so we must make sure to free it after we're done
6576 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6577 DWO CU, that this test will fail (the attribute will not be present). */
6578 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6579 if (dwo_name
!= nullptr)
6581 struct dwo_unit
*dwo_unit
;
6582 struct die_info
*dwo_comp_unit_die
;
6584 if (comp_unit_die
->has_children
)
6586 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6587 " has children (offset %s) [in module %s]"),
6588 sect_offset_str (this_cu
->sect_off
),
6589 bfd_get_filename (abfd
));
6591 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6592 if (dwo_unit
!= NULL
)
6594 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6595 comp_unit_die
, NULL
,
6598 &m_dwo_abbrev_table
) == 0)
6604 comp_unit_die
= dwo_comp_unit_die
;
6608 /* Yikes, we couldn't find the rest of the DIE, we only have
6609 the stub. A complaint has already been logged. There's
6610 not much more we can do except pass on the stub DIE to
6611 die_reader_func. We don't want to throw an error on bad
6618 cutu_reader::keep ()
6620 /* Done, clean up. */
6621 gdb_assert (!dummy_p
);
6622 if (m_new_cu
!= NULL
)
6624 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6626 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6627 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6631 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6632 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6633 assumed to have already done the lookup to find the DWO file).
6635 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6636 THIS_CU->is_debug_types, but nothing else.
6638 We fill in THIS_CU->length.
6640 THIS_CU->cu is always freed when done.
6641 This is done in order to not leave THIS_CU->cu in a state where we have
6642 to care whether it refers to the "main" CU or the DWO CU.
6644 When parent_cu is passed, it is used to provide a default value for
6645 str_offsets_base and addr_base from the parent. */
6647 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6648 dwarf2_per_objfile
*per_objfile
,
6649 struct dwarf2_cu
*parent_cu
,
6650 struct dwo_file
*dwo_file
)
6651 : die_reader_specs
{},
6654 struct objfile
*objfile
= per_objfile
->objfile
;
6655 struct dwarf2_section_info
*section
= this_cu
->section
;
6656 bfd
*abfd
= section
->get_bfd_owner ();
6657 struct dwarf2_section_info
*abbrev_section
;
6658 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6660 if (dwarf_die_debug
)
6661 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6662 this_cu
->is_debug_types
? "type" : "comp",
6663 sect_offset_str (this_cu
->sect_off
));
6665 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6667 abbrev_section
= (dwo_file
!= NULL
6668 ? &dwo_file
->sections
.abbrev
6669 : get_abbrev_section_for_cu (this_cu
));
6671 /* This is cheap if the section is already read in. */
6672 section
->read (objfile
);
6674 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6676 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6677 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6678 section
, abbrev_section
, info_ptr
,
6679 (this_cu
->is_debug_types
6681 : rcuh_kind::COMPILE
));
6683 if (parent_cu
!= nullptr)
6685 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6686 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6688 this_cu
->length
= m_new_cu
->header
.get_length ();
6690 /* Skip dummy compilation units. */
6691 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6692 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6698 abbrev_section
->read (objfile
);
6699 m_abbrev_table_holder
6700 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6702 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6703 m_abbrev_table_holder
.get ());
6704 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6708 /* Type Unit Groups.
6710 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6711 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6712 so that all types coming from the same compilation (.o file) are grouped
6713 together. A future step could be to put the types in the same symtab as
6714 the CU the types ultimately came from. */
6717 hash_type_unit_group (const void *item
)
6719 const struct type_unit_group
*tu_group
6720 = (const struct type_unit_group
*) item
;
6722 return hash_stmt_list_entry (&tu_group
->hash
);
6726 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6728 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6729 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6731 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6734 /* Allocate a hash table for type unit groups. */
6737 allocate_type_unit_groups_table ()
6739 return htab_up (htab_create_alloc (3,
6740 hash_type_unit_group
,
6744 type_unit_group
*grp
6745 = (type_unit_group
*) arg
;
6751 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6752 partial symtabs. We combine several TUs per psymtab to not let the size
6753 of any one psymtab grow too big. */
6754 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6755 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6757 /* Helper routine for get_type_unit_group.
6758 Create the type_unit_group object used to hold one or more TUs. */
6760 static std::unique_ptr
<type_unit_group
>
6761 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6763 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6764 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6766 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6767 tu_group
->per_bfd
= per_bfd
;
6769 if (per_bfd
->using_index
)
6771 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6772 struct dwarf2_per_cu_quick_data
);
6776 unsigned int line_offset
= to_underlying (line_offset_struct
);
6777 dwarf2_psymtab
*pst
;
6780 /* Give the symtab a useful name for debug purposes. */
6781 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6782 name
= string_printf ("<type_units_%d>",
6783 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6785 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6787 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6789 pst
->anonymous
= true;
6792 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6793 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6798 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6799 STMT_LIST is a DW_AT_stmt_list attribute. */
6801 static struct type_unit_group
*
6802 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6804 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6805 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6806 struct type_unit_group
*tu_group
;
6808 unsigned int line_offset
;
6809 struct type_unit_group type_unit_group_for_lookup
;
6811 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6812 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6814 /* Do we need to create a new group, or can we use an existing one? */
6816 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6818 line_offset
= stmt_list
->as_unsigned ();
6819 ++tu_stats
->nr_symtab_sharers
;
6823 /* Ugh, no stmt_list. Rare, but we have to handle it.
6824 We can do various things here like create one group per TU or
6825 spread them over multiple groups to split up the expansion work.
6826 To avoid worst case scenarios (too many groups or too large groups)
6827 we, umm, group them in bunches. */
6828 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6829 | (tu_stats
->nr_stmt_less_type_units
6830 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6831 ++tu_stats
->nr_stmt_less_type_units
;
6834 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6835 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6836 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6837 &type_unit_group_for_lookup
, INSERT
);
6838 if (*slot
== nullptr)
6840 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6841 std::unique_ptr
<type_unit_group
> grp
6842 = create_type_unit_group (cu
, line_offset_struct
);
6843 *slot
= grp
.release ();
6844 ++tu_stats
->nr_symtabs
;
6847 tu_group
= (struct type_unit_group
*) *slot
;
6848 gdb_assert (tu_group
!= nullptr);
6852 /* Partial symbol tables. */
6854 /* Create a psymtab named NAME and assign it to PER_CU.
6856 The caller must fill in the following details:
6857 dirname, textlow, texthigh. */
6859 static dwarf2_psymtab
*
6860 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6861 dwarf2_per_objfile
*per_objfile
,
6865 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6866 per_objfile
->objfile
->per_bfd
, per_cu
);
6868 pst
->psymtabs_addrmap_supported
= true;
6870 /* This is the glue that links PST into GDB's symbol API. */
6871 per_cu
->v
.psymtab
= pst
;
6876 /* DIE reader function for process_psymtab_comp_unit. */
6879 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6880 const gdb_byte
*info_ptr
,
6881 struct die_info
*comp_unit_die
,
6882 enum language pretend_language
)
6884 struct dwarf2_cu
*cu
= reader
->cu
;
6885 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6886 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6887 struct objfile
*objfile
= per_objfile
->objfile
;
6888 struct gdbarch
*gdbarch
= objfile
->arch ();
6889 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6891 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6892 dwarf2_psymtab
*pst
;
6893 enum pc_bounds_kind cu_bounds_kind
;
6894 const char *filename
;
6896 gdb_assert (! per_cu
->is_debug_types
);
6898 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6900 /* Allocate a new partial symbol table structure. */
6901 gdb::unique_xmalloc_ptr
<char> debug_filename
;
6902 static const char artificial
[] = "<artificial>";
6903 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6904 if (filename
== NULL
)
6906 else if (strcmp (filename
, artificial
) == 0)
6908 debug_filename
.reset (concat (artificial
, "@",
6909 sect_offset_str (per_cu
->sect_off
),
6911 filename
= debug_filename
.get ();
6914 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
6916 /* This must be done before calling dwarf2_build_include_psymtabs. */
6917 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6919 baseaddr
= objfile
->text_section_offset ();
6921 dwarf2_find_base_address (comp_unit_die
, cu
);
6923 /* Possibly set the default values of LOWPC and HIGHPC from
6925 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6926 &best_highpc
, cu
, pst
);
6927 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6930 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
6933 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
6935 /* Store the contiguous range if it is not empty; it can be
6936 empty for CUs with no code. */
6937 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
6941 /* Check if comp unit has_children.
6942 If so, read the rest of the partial symbols from this comp unit.
6943 If not, there's no more debug_info for this comp unit. */
6944 if (comp_unit_die
->has_children
)
6946 struct partial_die_info
*first_die
;
6947 CORE_ADDR lowpc
, highpc
;
6949 lowpc
= ((CORE_ADDR
) -1);
6950 highpc
= ((CORE_ADDR
) 0);
6952 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6954 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6955 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6957 /* If we didn't find a lowpc, set it to highpc to avoid
6958 complaints from `maint check'. */
6959 if (lowpc
== ((CORE_ADDR
) -1))
6962 /* If the compilation unit didn't have an explicit address range,
6963 then use the information extracted from its child dies. */
6964 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6967 best_highpc
= highpc
;
6970 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
6971 best_lowpc
+ baseaddr
)
6973 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
6974 best_highpc
+ baseaddr
)
6979 if (!cu
->per_cu
->imported_symtabs_empty ())
6982 int len
= cu
->per_cu
->imported_symtabs_size ();
6984 /* Fill in 'dependencies' here; we fill in 'users' in a
6986 pst
->number_of_dependencies
= len
;
6988 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
6989 for (i
= 0; i
< len
; ++i
)
6991 pst
->dependencies
[i
]
6992 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
6995 cu
->per_cu
->imported_symtabs_free ();
6998 /* Get the list of files included in the current compilation unit,
6999 and build a psymtab for each of them. */
7000 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7002 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7003 ", %d global, %d static syms",
7004 per_cu
->is_debug_types
? "type" : "comp",
7005 sect_offset_str (per_cu
->sect_off
),
7006 paddress (gdbarch
, pst
->text_low (objfile
)),
7007 paddress (gdbarch
, pst
->text_high (objfile
)),
7008 (int) pst
->global_psymbols
.size (),
7009 (int) pst
->static_psymbols
.size ());
7012 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7013 Process compilation unit THIS_CU for a psymtab. */
7016 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7017 dwarf2_per_objfile
*per_objfile
,
7018 bool want_partial_unit
,
7019 enum language pretend_language
)
7021 /* If this compilation unit was already read in, free the
7022 cached copy in order to read it in again. This is
7023 necessary because we skipped some symbols when we first
7024 read in the compilation unit (see load_partial_dies).
7025 This problem could be avoided, but the benefit is unclear. */
7026 per_objfile
->remove_cu (this_cu
);
7028 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7030 switch (reader
.comp_unit_die
->tag
)
7032 case DW_TAG_compile_unit
:
7033 this_cu
->unit_type
= DW_UT_compile
;
7035 case DW_TAG_partial_unit
:
7036 this_cu
->unit_type
= DW_UT_partial
;
7038 case DW_TAG_type_unit
:
7039 this_cu
->unit_type
= DW_UT_type
;
7042 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7043 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7044 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7045 objfile_name (per_objfile
->objfile
));
7052 else if (this_cu
->is_debug_types
)
7053 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7054 reader
.comp_unit_die
);
7055 else if (want_partial_unit
7056 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7057 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7058 reader
.comp_unit_die
,
7061 this_cu
->lang
= reader
.cu
->language
;
7063 /* Age out any secondary CUs. */
7064 per_objfile
->age_comp_units ();
7067 /* Reader function for build_type_psymtabs. */
7070 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7071 const gdb_byte
*info_ptr
,
7072 struct die_info
*type_unit_die
)
7074 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7075 struct dwarf2_cu
*cu
= reader
->cu
;
7076 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7077 struct signatured_type
*sig_type
;
7078 struct type_unit_group
*tu_group
;
7079 struct attribute
*attr
;
7080 struct partial_die_info
*first_die
;
7081 CORE_ADDR lowpc
, highpc
;
7082 dwarf2_psymtab
*pst
;
7084 gdb_assert (per_cu
->is_debug_types
);
7085 sig_type
= (struct signatured_type
*) per_cu
;
7087 if (! type_unit_die
->has_children
)
7090 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7091 tu_group
= get_type_unit_group (cu
, attr
);
7093 if (tu_group
->tus
== nullptr)
7094 tu_group
->tus
= new std::vector
<signatured_type
*>;
7095 tu_group
->tus
->push_back (sig_type
);
7097 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7098 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7099 pst
->anonymous
= true;
7101 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7103 lowpc
= (CORE_ADDR
) -1;
7104 highpc
= (CORE_ADDR
) 0;
7105 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7110 /* Struct used to sort TUs by their abbreviation table offset. */
7112 struct tu_abbrev_offset
7114 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7115 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7118 /* This is used when sorting. */
7119 bool operator< (const tu_abbrev_offset
&other
)
7121 return abbrev_offset
< other
.abbrev_offset
;
7124 signatured_type
*sig_type
;
7125 sect_offset abbrev_offset
;
7128 /* Efficiently read all the type units.
7130 The efficiency is because we sort TUs by the abbrev table they use and
7131 only read each abbrev table once. In one program there are 200K TUs
7132 sharing 8K abbrev tables.
7134 The main purpose of this function is to support building the
7135 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7136 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7137 can collapse the search space by grouping them by stmt_list.
7138 The savings can be significant, in the same program from above the 200K TUs
7139 share 8K stmt_list tables.
7141 FUNC is expected to call get_type_unit_group, which will create the
7142 struct type_unit_group if necessary and add it to
7143 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7146 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7148 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7149 abbrev_table_up abbrev_table
;
7150 sect_offset abbrev_offset
;
7152 /* It's up to the caller to not call us multiple times. */
7153 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7155 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7158 /* TUs typically share abbrev tables, and there can be way more TUs than
7159 abbrev tables. Sort by abbrev table to reduce the number of times we
7160 read each abbrev table in.
7161 Alternatives are to punt or to maintain a cache of abbrev tables.
7162 This is simpler and efficient enough for now.
7164 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7165 symtab to use). Typically TUs with the same abbrev offset have the same
7166 stmt_list value too so in practice this should work well.
7168 The basic algorithm here is:
7170 sort TUs by abbrev table
7171 for each TU with same abbrev table:
7172 read abbrev table if first user
7173 read TU top level DIE
7174 [IWBN if DWO skeletons had DW_AT_stmt_list]
7177 dwarf_read_debug_printf ("Building type unit groups ...");
7179 /* Sort in a separate table to maintain the order of all_comp_units
7180 for .gdb_index: TU indices directly index all_type_units. */
7181 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7182 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7184 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7186 if (cu
->is_debug_types
)
7188 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7189 sorted_by_abbrev
.emplace_back
7190 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7191 sig_type
->sect_off
));
7195 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7197 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7199 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7201 /* Switch to the next abbrev table if necessary. */
7202 if (abbrev_table
== NULL
7203 || tu
.abbrev_offset
!= abbrev_offset
)
7205 abbrev_offset
= tu
.abbrev_offset
;
7206 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7208 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7209 ++tu_stats
->nr_uniq_abbrev_tables
;
7212 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7213 abbrev_table
.get (), nullptr, false);
7214 if (!reader
.dummy_p
)
7215 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7216 reader
.comp_unit_die
);
7220 /* Print collected type unit statistics. */
7223 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7225 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7227 dwarf_read_debug_printf ("Type unit statistics:");
7228 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7229 dwarf_read_debug_printf (" %d uniq abbrev tables",
7230 tu_stats
->nr_uniq_abbrev_tables
);
7231 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7232 tu_stats
->nr_symtabs
);
7233 dwarf_read_debug_printf (" %d symtab sharers",
7234 tu_stats
->nr_symtab_sharers
);
7235 dwarf_read_debug_printf (" %d type units without a stmt_list",
7236 tu_stats
->nr_stmt_less_type_units
);
7237 dwarf_read_debug_printf (" %d all_type_units reallocs",
7238 tu_stats
->nr_all_type_units_reallocs
);
7241 /* Traversal function for build_type_psymtabs. */
7244 build_type_psymtab_dependencies (void **slot
, void *info
)
7246 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7247 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7248 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7249 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7250 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7253 gdb_assert (len
> 0);
7254 gdb_assert (tu_group
->type_unit_group_p ());
7256 pst
->number_of_dependencies
= len
;
7257 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7258 for (i
= 0; i
< len
; ++i
)
7260 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7261 gdb_assert (iter
->is_debug_types
);
7262 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7263 iter
->type_unit_group
= tu_group
;
7266 delete tu_group
->tus
;
7267 tu_group
->tus
= nullptr;
7272 /* Traversal function for process_skeletonless_type_unit.
7273 Read a TU in a DWO file and build partial symbols for it. */
7276 process_skeletonless_type_unit (void **slot
, void *info
)
7278 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7279 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7280 struct signatured_type find_entry
, *entry
;
7282 /* If this TU doesn't exist in the global table, add it and read it in. */
7284 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7285 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7287 find_entry
.signature
= dwo_unit
->signature
;
7288 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7289 &find_entry
, INSERT
);
7290 /* If we've already seen this type there's nothing to do. What's happening
7291 is we're doing our own version of comdat-folding here. */
7295 /* This does the job that create_all_comp_units would have done for
7297 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7298 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7301 /* This does the job that build_type_psymtabs would have done. */
7302 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7303 if (!reader
.dummy_p
)
7304 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7305 reader
.comp_unit_die
);
7310 /* Traversal function for process_skeletonless_type_units. */
7313 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7315 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7317 if (dwo_file
->tus
!= NULL
)
7318 htab_traverse_noresize (dwo_file
->tus
.get (),
7319 process_skeletonless_type_unit
, info
);
7324 /* Scan all TUs of DWO files, verifying we've processed them.
7325 This is needed in case a TU was emitted without its skeleton.
7326 Note: This can't be done until we know what all the DWO files are. */
7329 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7331 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7332 if (get_dwp_file (per_objfile
) == NULL
7333 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7335 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7336 process_dwo_file_for_skeletonless_type_units
,
7341 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7344 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7346 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7348 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7353 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7355 /* Set the 'user' field only if it is not already set. */
7356 if (pst
->dependencies
[j
]->user
== NULL
)
7357 pst
->dependencies
[j
]->user
= pst
;
7362 /* Build the partial symbol table by doing a quick pass through the
7363 .debug_info and .debug_abbrev sections. */
7366 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7368 struct objfile
*objfile
= per_objfile
->objfile
;
7369 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7371 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7372 objfile_name (objfile
));
7374 scoped_restore restore_reading_psyms
7375 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7377 per_bfd
->info
.read (objfile
);
7379 /* Any cached compilation units will be linked by the per-objfile
7380 read_in_chain. Make sure to free them when we're done. */
7381 free_cached_comp_units
freer (per_objfile
);
7383 create_all_comp_units (per_objfile
);
7384 build_type_psymtabs (per_objfile
);
7386 /* Create a temporary address map on a temporary obstack. We later
7387 copy this to the final obstack. */
7388 auto_obstack temp_obstack
;
7390 scoped_restore save_psymtabs_addrmap
7391 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7392 addrmap_create_mutable (&temp_obstack
));
7394 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7396 if (per_cu
->v
.psymtab
!= NULL
)
7397 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7399 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7403 /* This has to wait until we read the CUs, we need the list of DWOs. */
7404 process_skeletonless_type_units (per_objfile
);
7406 /* Now that all TUs have been processed we can fill in the dependencies. */
7407 if (per_bfd
->type_unit_groups
!= NULL
)
7409 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7410 build_type_psymtab_dependencies
, per_objfile
);
7413 if (dwarf_read_debug
> 0)
7414 print_tu_stats (per_objfile
);
7416 set_partial_user (per_objfile
);
7418 per_bfd
->partial_symtabs
->psymtabs_addrmap
7419 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7420 per_bfd
->partial_symtabs
->obstack ());
7421 /* At this point we want to keep the address map. */
7422 save_psymtabs_addrmap
.release ();
7424 dwarf_read_debug_printf ("Done building psymtabs of %s",
7425 objfile_name (objfile
));
7428 /* Load the partial DIEs for a secondary CU into memory.
7429 This is also used when rereading a primary CU with load_all_dies. */
7432 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7433 dwarf2_per_objfile
*per_objfile
,
7434 dwarf2_cu
*existing_cu
)
7436 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7438 if (!reader
.dummy_p
)
7440 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7443 /* Check if comp unit has_children.
7444 If so, read the rest of the partial symbols from this comp unit.
7445 If not, there's no more debug_info for this comp unit. */
7446 if (reader
.comp_unit_die
->has_children
)
7447 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7454 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7455 struct dwarf2_section_info
*section
,
7456 struct dwarf2_section_info
*abbrev_section
,
7457 unsigned int is_dwz
,
7458 htab_up
&types_htab
,
7459 rcuh_kind section_kind
)
7461 const gdb_byte
*info_ptr
;
7462 struct objfile
*objfile
= per_objfile
->objfile
;
7464 dwarf_read_debug_printf ("Reading %s for %s",
7465 section
->get_name (),
7466 section
->get_file_name ());
7468 section
->read (objfile
);
7470 info_ptr
= section
->buffer
;
7472 while (info_ptr
< section
->buffer
+ section
->size
)
7474 dwarf2_per_cu_data_up this_cu
;
7476 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7478 comp_unit_head cu_header
;
7479 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7480 abbrev_section
, info_ptr
,
7483 /* Save the compilation unit for later lookup. */
7484 if (cu_header
.unit_type
!= DW_UT_type
)
7485 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7488 if (types_htab
== nullptr)
7489 types_htab
= allocate_signatured_type_table ();
7491 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
7492 signatured_type
*sig_ptr
= sig_type
.get ();
7493 sig_type
->signature
= cu_header
.signature
;
7494 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7495 this_cu
.reset (sig_type
.release ());
7497 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7498 gdb_assert (slot
!= nullptr);
7499 if (*slot
!= nullptr)
7500 complaint (_("debug type entry at offset %s is duplicate to"
7501 " the entry at offset %s, signature %s"),
7502 sect_offset_str (sect_off
),
7503 sect_offset_str (sig_ptr
->sect_off
),
7504 hex_string (sig_ptr
->signature
));
7507 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7508 this_cu
->sect_off
= sect_off
;
7509 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7510 this_cu
->is_dwz
= is_dwz
;
7511 this_cu
->section
= section
;
7513 info_ptr
= info_ptr
+ this_cu
->length
;
7514 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7518 /* Create a list of all compilation units in OBJFILE.
7519 This is only done for -readnow and building partial symtabs. */
7522 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7526 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7527 &per_objfile
->per_bfd
->abbrev
, 0,
7528 types_htab
, rcuh_kind::COMPILE
);
7529 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7530 read_comp_units_from_section (per_objfile
, §ion
,
7531 &per_objfile
->per_bfd
->abbrev
, 0,
7532 types_htab
, rcuh_kind::TYPE
);
7534 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7536 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7537 types_htab
, rcuh_kind::COMPILE
);
7539 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7542 /* Process all loaded DIEs for compilation unit CU, starting at
7543 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7544 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7545 DW_AT_ranges). See the comments of add_partial_subprogram on how
7546 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7549 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7550 CORE_ADDR
*highpc
, int set_addrmap
,
7551 struct dwarf2_cu
*cu
)
7553 struct partial_die_info
*pdi
;
7555 /* Now, march along the PDI's, descending into ones which have
7556 interesting children but skipping the children of the other ones,
7557 until we reach the end of the compilation unit. */
7565 /* Anonymous namespaces or modules have no name but have interesting
7566 children, so we need to look at them. Ditto for anonymous
7569 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7570 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7571 || pdi
->tag
== DW_TAG_imported_unit
7572 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7576 case DW_TAG_subprogram
:
7577 case DW_TAG_inlined_subroutine
:
7578 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7579 if (cu
->language
== language_cplus
)
7580 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7583 case DW_TAG_constant
:
7584 case DW_TAG_variable
:
7585 case DW_TAG_typedef
:
7586 case DW_TAG_union_type
:
7587 if (!pdi
->is_declaration
7588 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7590 add_partial_symbol (pdi
, cu
);
7593 case DW_TAG_class_type
:
7594 case DW_TAG_interface_type
:
7595 case DW_TAG_structure_type
:
7596 if (!pdi
->is_declaration
)
7598 add_partial_symbol (pdi
, cu
);
7600 if ((cu
->language
== language_rust
7601 || cu
->language
== language_cplus
) && pdi
->has_children
)
7602 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7605 case DW_TAG_enumeration_type
:
7606 if (!pdi
->is_declaration
)
7607 add_partial_enumeration (pdi
, cu
);
7609 case DW_TAG_base_type
:
7610 case DW_TAG_subrange_type
:
7611 /* File scope base type definitions are added to the partial
7613 add_partial_symbol (pdi
, cu
);
7615 case DW_TAG_namespace
:
7616 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7619 if (!pdi
->is_declaration
)
7620 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7622 case DW_TAG_imported_unit
:
7624 struct dwarf2_per_cu_data
*per_cu
;
7626 /* For now we don't handle imported units in type units. */
7627 if (cu
->per_cu
->is_debug_types
)
7629 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7630 " supported in type units [in module %s]"),
7631 objfile_name (cu
->per_objfile
->objfile
));
7634 per_cu
= dwarf2_find_containing_comp_unit
7635 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7637 /* Go read the partial unit, if needed. */
7638 if (per_cu
->v
.psymtab
== NULL
)
7639 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7642 cu
->per_cu
->imported_symtabs_push (per_cu
);
7645 case DW_TAG_imported_declaration
:
7646 add_partial_symbol (pdi
, cu
);
7653 /* If the die has a sibling, skip to the sibling. */
7655 pdi
= pdi
->die_sibling
;
7659 /* Functions used to compute the fully scoped name of a partial DIE.
7661 Normally, this is simple. For C++, the parent DIE's fully scoped
7662 name is concatenated with "::" and the partial DIE's name.
7663 Enumerators are an exception; they use the scope of their parent
7664 enumeration type, i.e. the name of the enumeration type is not
7665 prepended to the enumerator.
7667 There are two complexities. One is DW_AT_specification; in this
7668 case "parent" means the parent of the target of the specification,
7669 instead of the direct parent of the DIE. The other is compilers
7670 which do not emit DW_TAG_namespace; in this case we try to guess
7671 the fully qualified name of structure types from their members'
7672 linkage names. This must be done using the DIE's children rather
7673 than the children of any DW_AT_specification target. We only need
7674 to do this for structures at the top level, i.e. if the target of
7675 any DW_AT_specification (if any; otherwise the DIE itself) does not
7678 /* Compute the scope prefix associated with PDI's parent, in
7679 compilation unit CU. The result will be allocated on CU's
7680 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7681 field. NULL is returned if no prefix is necessary. */
7683 partial_die_parent_scope (struct partial_die_info
*pdi
,
7684 struct dwarf2_cu
*cu
)
7686 const char *grandparent_scope
;
7687 struct partial_die_info
*parent
, *real_pdi
;
7689 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7690 then this means the parent of the specification DIE. */
7693 while (real_pdi
->has_specification
)
7695 auto res
= find_partial_die (real_pdi
->spec_offset
,
7696 real_pdi
->spec_is_dwz
, cu
);
7701 parent
= real_pdi
->die_parent
;
7705 if (parent
->scope_set
)
7706 return parent
->scope
;
7710 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7712 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7713 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7714 Work around this problem here. */
7715 if (cu
->language
== language_cplus
7716 && parent
->tag
== DW_TAG_namespace
7717 && strcmp (parent
->name (cu
), "::") == 0
7718 && grandparent_scope
== NULL
)
7720 parent
->scope
= NULL
;
7721 parent
->scope_set
= 1;
7725 /* Nested subroutines in Fortran get a prefix. */
7726 if (pdi
->tag
== DW_TAG_enumerator
)
7727 /* Enumerators should not get the name of the enumeration as a prefix. */
7728 parent
->scope
= grandparent_scope
;
7729 else if (parent
->tag
== DW_TAG_namespace
7730 || parent
->tag
== DW_TAG_module
7731 || parent
->tag
== DW_TAG_structure_type
7732 || parent
->tag
== DW_TAG_class_type
7733 || parent
->tag
== DW_TAG_interface_type
7734 || parent
->tag
== DW_TAG_union_type
7735 || parent
->tag
== DW_TAG_enumeration_type
7736 || (cu
->language
== language_fortran
7737 && parent
->tag
== DW_TAG_subprogram
7738 && pdi
->tag
== DW_TAG_subprogram
))
7740 if (grandparent_scope
== NULL
)
7741 parent
->scope
= parent
->name (cu
);
7743 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7745 parent
->name (cu
), 0, cu
);
7749 /* FIXME drow/2004-04-01: What should we be doing with
7750 function-local names? For partial symbols, we should probably be
7752 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7753 dwarf_tag_name (parent
->tag
),
7754 sect_offset_str (pdi
->sect_off
));
7755 parent
->scope
= grandparent_scope
;
7758 parent
->scope_set
= 1;
7759 return parent
->scope
;
7762 /* Return the fully scoped name associated with PDI, from compilation unit
7763 CU. The result will be allocated with malloc. */
7765 static gdb::unique_xmalloc_ptr
<char>
7766 partial_die_full_name (struct partial_die_info
*pdi
,
7767 struct dwarf2_cu
*cu
)
7769 const char *parent_scope
;
7771 /* If this is a template instantiation, we can not work out the
7772 template arguments from partial DIEs. So, unfortunately, we have
7773 to go through the full DIEs. At least any work we do building
7774 types here will be reused if full symbols are loaded later. */
7775 if (pdi
->has_template_arguments
)
7779 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7781 struct die_info
*die
;
7782 struct attribute attr
;
7783 struct dwarf2_cu
*ref_cu
= cu
;
7785 /* DW_FORM_ref_addr is using section offset. */
7786 attr
.name
= (enum dwarf_attribute
) 0;
7787 attr
.form
= DW_FORM_ref_addr
;
7788 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7789 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7791 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7795 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7796 if (parent_scope
== NULL
)
7799 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7805 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7807 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7808 struct objfile
*objfile
= per_objfile
->objfile
;
7809 struct gdbarch
*gdbarch
= objfile
->arch ();
7811 const char *actual_name
= NULL
;
7814 baseaddr
= objfile
->text_section_offset ();
7816 gdb::unique_xmalloc_ptr
<char> built_actual_name
7817 = partial_die_full_name (pdi
, cu
);
7818 if (built_actual_name
!= NULL
)
7819 actual_name
= built_actual_name
.get ();
7821 if (actual_name
== NULL
)
7822 actual_name
= pdi
->name (cu
);
7824 partial_symbol psymbol
;
7825 memset (&psymbol
, 0, sizeof (psymbol
));
7826 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
7827 psymbol
.ginfo
.set_section_index (-1);
7829 /* The code below indicates that the psymbol should be installed by
7831 gdb::optional
<psymbol_placement
> where
;
7835 case DW_TAG_inlined_subroutine
:
7836 case DW_TAG_subprogram
:
7837 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7839 if (pdi
->is_external
7840 || cu
->language
== language_ada
7841 || (cu
->language
== language_fortran
7842 && pdi
->die_parent
!= NULL
7843 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7845 /* Normally, only "external" DIEs are part of the global scope.
7846 But in Ada and Fortran, we want to be able to access nested
7847 procedures globally. So all Ada and Fortran subprograms are
7848 stored in the global scope. */
7849 where
= psymbol_placement::GLOBAL
;
7852 where
= psymbol_placement::STATIC
;
7854 psymbol
.domain
= VAR_DOMAIN
;
7855 psymbol
.aclass
= LOC_BLOCK
;
7856 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7857 psymbol
.ginfo
.value
.address
= addr
;
7859 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7860 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7862 case DW_TAG_constant
:
7863 psymbol
.domain
= VAR_DOMAIN
;
7864 psymbol
.aclass
= LOC_STATIC
;
7865 where
= (pdi
->is_external
7866 ? psymbol_placement::GLOBAL
7867 : psymbol_placement::STATIC
);
7869 case DW_TAG_variable
:
7871 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7875 && !per_objfile
->per_bfd
->has_section_at_zero
)
7877 /* A global or static variable may also have been stripped
7878 out by the linker if unused, in which case its address
7879 will be nullified; do not add such variables into partial
7880 symbol table then. */
7882 else if (pdi
->is_external
)
7885 Don't enter into the minimal symbol tables as there is
7886 a minimal symbol table entry from the ELF symbols already.
7887 Enter into partial symbol table if it has a location
7888 descriptor or a type.
7889 If the location descriptor is missing, new_symbol will create
7890 a LOC_UNRESOLVED symbol, the address of the variable will then
7891 be determined from the minimal symbol table whenever the variable
7893 The address for the partial symbol table entry is not
7894 used by GDB, but it comes in handy for debugging partial symbol
7897 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7899 psymbol
.domain
= VAR_DOMAIN
;
7900 psymbol
.aclass
= LOC_STATIC
;
7901 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7902 psymbol
.ginfo
.value
.address
= addr
;
7903 where
= psymbol_placement::GLOBAL
;
7908 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7910 /* Static Variable. Skip symbols whose value we cannot know (those
7911 without location descriptors or constant values). */
7912 if (!has_loc
&& !pdi
->has_const_value
)
7915 psymbol
.domain
= VAR_DOMAIN
;
7916 psymbol
.aclass
= LOC_STATIC
;
7917 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7919 psymbol
.ginfo
.value
.address
= addr
;
7920 where
= psymbol_placement::STATIC
;
7923 case DW_TAG_array_type
:
7924 case DW_TAG_typedef
:
7925 case DW_TAG_base_type
:
7926 case DW_TAG_subrange_type
:
7927 psymbol
.domain
= VAR_DOMAIN
;
7928 psymbol
.aclass
= LOC_TYPEDEF
;
7929 where
= psymbol_placement::STATIC
;
7931 case DW_TAG_imported_declaration
:
7932 case DW_TAG_namespace
:
7933 psymbol
.domain
= VAR_DOMAIN
;
7934 psymbol
.aclass
= LOC_TYPEDEF
;
7935 where
= psymbol_placement::GLOBAL
;
7938 /* With Fortran 77 there might be a "BLOCK DATA" module
7939 available without any name. If so, we skip the module as it
7940 doesn't bring any value. */
7941 if (actual_name
!= nullptr)
7943 psymbol
.domain
= MODULE_DOMAIN
;
7944 psymbol
.aclass
= LOC_TYPEDEF
;
7945 where
= psymbol_placement::GLOBAL
;
7948 case DW_TAG_class_type
:
7949 case DW_TAG_interface_type
:
7950 case DW_TAG_structure_type
:
7951 case DW_TAG_union_type
:
7952 case DW_TAG_enumeration_type
:
7953 /* Skip external references. The DWARF standard says in the section
7954 about "Structure, Union, and Class Type Entries": "An incomplete
7955 structure, union or class type is represented by a structure,
7956 union or class entry that does not have a byte size attribute
7957 and that has a DW_AT_declaration attribute." */
7958 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7961 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7962 static vs. global. */
7963 psymbol
.domain
= STRUCT_DOMAIN
;
7964 psymbol
.aclass
= LOC_TYPEDEF
;
7965 where
= (cu
->language
== language_cplus
7966 ? psymbol_placement::GLOBAL
7967 : psymbol_placement::STATIC
);
7969 case DW_TAG_enumerator
:
7970 psymbol
.domain
= VAR_DOMAIN
;
7971 psymbol
.aclass
= LOC_CONST
;
7972 where
= (cu
->language
== language_cplus
7973 ? psymbol_placement::GLOBAL
7974 : psymbol_placement::STATIC
);
7980 if (where
.has_value ())
7982 if (built_actual_name
!= nullptr)
7983 actual_name
= objfile
->intern (actual_name
);
7984 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
7985 psymbol
.ginfo
.set_linkage_name (actual_name
);
7988 psymbol
.ginfo
.set_demangled_name (actual_name
,
7989 &objfile
->objfile_obstack
);
7990 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
7992 cu
->per_cu
->v
.psymtab
->add_psymbol
7993 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7998 /* Read a partial die corresponding to a namespace; also, add a symbol
7999 corresponding to that namespace to the symbol table. NAMESPACE is
8000 the name of the enclosing namespace. */
8003 add_partial_namespace (struct partial_die_info
*pdi
,
8004 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8005 int set_addrmap
, struct dwarf2_cu
*cu
)
8007 /* Add a symbol for the namespace. */
8009 add_partial_symbol (pdi
, cu
);
8011 /* Now scan partial symbols in that namespace. */
8013 if (pdi
->has_children
)
8014 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8017 /* Read a partial die corresponding to a Fortran module. */
8020 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8021 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8023 /* Add a symbol for the namespace. */
8025 add_partial_symbol (pdi
, cu
);
8027 /* Now scan partial symbols in that module. */
8029 if (pdi
->has_children
)
8030 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8033 /* Read a partial die corresponding to a subprogram or an inlined
8034 subprogram and create a partial symbol for that subprogram.
8035 When the CU language allows it, this routine also defines a partial
8036 symbol for each nested subprogram that this subprogram contains.
8037 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8038 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8040 PDI may also be a lexical block, in which case we simply search
8041 recursively for subprograms defined inside that lexical block.
8042 Again, this is only performed when the CU language allows this
8043 type of definitions. */
8046 add_partial_subprogram (struct partial_die_info
*pdi
,
8047 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8048 int set_addrmap
, struct dwarf2_cu
*cu
)
8050 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8052 if (pdi
->has_pc_info
)
8054 if (pdi
->lowpc
< *lowpc
)
8055 *lowpc
= pdi
->lowpc
;
8056 if (pdi
->highpc
> *highpc
)
8057 *highpc
= pdi
->highpc
;
8060 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8061 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8062 struct gdbarch
*gdbarch
= objfile
->arch ();
8064 CORE_ADDR this_highpc
;
8065 CORE_ADDR this_lowpc
;
8067 baseaddr
= objfile
->text_section_offset ();
8069 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8070 pdi
->lowpc
+ baseaddr
)
8073 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8074 pdi
->highpc
+ baseaddr
)
8076 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8077 this_lowpc
, this_highpc
- 1,
8078 cu
->per_cu
->v
.psymtab
);
8082 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8084 if (!pdi
->is_declaration
)
8085 /* Ignore subprogram DIEs that do not have a name, they are
8086 illegal. Do not emit a complaint at this point, we will
8087 do so when we convert this psymtab into a symtab. */
8089 add_partial_symbol (pdi
, cu
);
8093 if (! pdi
->has_children
)
8096 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8098 pdi
= pdi
->die_child
;
8102 if (pdi
->tag
== DW_TAG_subprogram
8103 || pdi
->tag
== DW_TAG_inlined_subroutine
8104 || pdi
->tag
== DW_TAG_lexical_block
)
8105 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8106 pdi
= pdi
->die_sibling
;
8111 /* Read a partial die corresponding to an enumeration type. */
8114 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8115 struct dwarf2_cu
*cu
)
8117 struct partial_die_info
*pdi
;
8119 if (enum_pdi
->name (cu
) != NULL
)
8120 add_partial_symbol (enum_pdi
, cu
);
8122 pdi
= enum_pdi
->die_child
;
8125 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8126 complaint (_("malformed enumerator DIE ignored"));
8128 add_partial_symbol (pdi
, cu
);
8129 pdi
= pdi
->die_sibling
;
8133 /* Return the initial uleb128 in the die at INFO_PTR. */
8136 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8138 unsigned int bytes_read
;
8140 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8143 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8144 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8146 Return the corresponding abbrev, or NULL if the number is zero (indicating
8147 an empty DIE). In either case *BYTES_READ will be set to the length of
8148 the initial number. */
8150 static const struct abbrev_info
*
8151 peek_die_abbrev (const die_reader_specs
&reader
,
8152 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8154 dwarf2_cu
*cu
= reader
.cu
;
8155 bfd
*abfd
= reader
.abfd
;
8156 unsigned int abbrev_number
8157 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8159 if (abbrev_number
== 0)
8162 const abbrev_info
*abbrev
8163 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8166 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8167 " at offset %s [in module %s]"),
8168 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8169 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8175 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8176 Returns a pointer to the end of a series of DIEs, terminated by an empty
8177 DIE. Any children of the skipped DIEs will also be skipped. */
8179 static const gdb_byte
*
8180 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8184 unsigned int bytes_read
;
8185 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8189 return info_ptr
+ bytes_read
;
8191 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8195 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8196 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8197 abbrev corresponding to that skipped uleb128 should be passed in
8198 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8201 static const gdb_byte
*
8202 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8203 const struct abbrev_info
*abbrev
)
8205 unsigned int bytes_read
;
8206 struct attribute attr
;
8207 bfd
*abfd
= reader
->abfd
;
8208 struct dwarf2_cu
*cu
= reader
->cu
;
8209 const gdb_byte
*buffer
= reader
->buffer
;
8210 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8211 unsigned int form
, i
;
8213 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8215 /* The only abbrev we care about is DW_AT_sibling. */
8216 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8218 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8219 if (attr
.form
== DW_FORM_ref_addr
)
8220 complaint (_("ignoring absolute DW_AT_sibling"));
8223 sect_offset off
= attr
.get_ref_die_offset ();
8224 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8226 if (sibling_ptr
< info_ptr
)
8227 complaint (_("DW_AT_sibling points backwards"));
8228 else if (sibling_ptr
> reader
->buffer_end
)
8229 reader
->die_section
->overflow_complaint ();
8235 /* If it isn't DW_AT_sibling, skip this attribute. */
8236 form
= abbrev
->attrs
[i
].form
;
8240 case DW_FORM_ref_addr
:
8241 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8242 and later it is offset sized. */
8243 if (cu
->header
.version
== 2)
8244 info_ptr
+= cu
->header
.addr_size
;
8246 info_ptr
+= cu
->header
.offset_size
;
8248 case DW_FORM_GNU_ref_alt
:
8249 info_ptr
+= cu
->header
.offset_size
;
8252 info_ptr
+= cu
->header
.addr_size
;
8260 case DW_FORM_flag_present
:
8261 case DW_FORM_implicit_const
:
8278 case DW_FORM_ref_sig8
:
8281 case DW_FORM_data16
:
8284 case DW_FORM_string
:
8285 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8286 info_ptr
+= bytes_read
;
8288 case DW_FORM_sec_offset
:
8290 case DW_FORM_GNU_strp_alt
:
8291 info_ptr
+= cu
->header
.offset_size
;
8293 case DW_FORM_exprloc
:
8295 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8296 info_ptr
+= bytes_read
;
8298 case DW_FORM_block1
:
8299 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8301 case DW_FORM_block2
:
8302 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8304 case DW_FORM_block4
:
8305 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8311 case DW_FORM_ref_udata
:
8312 case DW_FORM_GNU_addr_index
:
8313 case DW_FORM_GNU_str_index
:
8314 case DW_FORM_rnglistx
:
8315 case DW_FORM_loclistx
:
8316 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8318 case DW_FORM_indirect
:
8319 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8320 info_ptr
+= bytes_read
;
8321 /* We need to continue parsing from here, so just go back to
8323 goto skip_attribute
;
8326 error (_("Dwarf Error: Cannot handle %s "
8327 "in DWARF reader [in module %s]"),
8328 dwarf_form_name (form
),
8329 bfd_get_filename (abfd
));
8333 if (abbrev
->has_children
)
8334 return skip_children (reader
, info_ptr
);
8339 /* Locate ORIG_PDI's sibling.
8340 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8342 static const gdb_byte
*
8343 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8344 struct partial_die_info
*orig_pdi
,
8345 const gdb_byte
*info_ptr
)
8347 /* Do we know the sibling already? */
8349 if (orig_pdi
->sibling
)
8350 return orig_pdi
->sibling
;
8352 /* Are there any children to deal with? */
8354 if (!orig_pdi
->has_children
)
8357 /* Skip the children the long way. */
8359 return skip_children (reader
, info_ptr
);
8362 /* Expand this partial symbol table into a full symbol table. SELF is
8366 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8368 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8370 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8372 /* If this psymtab is constructed from a debug-only objfile, the
8373 has_section_at_zero flag will not necessarily be correct. We
8374 can get the correct value for this flag by looking at the data
8375 associated with the (presumably stripped) associated objfile. */
8376 if (objfile
->separate_debug_objfile_backlink
)
8378 dwarf2_per_objfile
*per_objfile_backlink
8379 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8381 per_objfile
->per_bfd
->has_section_at_zero
8382 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8385 expand_psymtab (objfile
);
8387 process_cu_includes (per_objfile
);
8390 /* Reading in full CUs. */
8392 /* Add PER_CU to the queue. */
8395 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8396 dwarf2_per_objfile
*per_objfile
,
8397 enum language pretend_language
)
8401 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8402 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8405 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8407 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8410 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8411 DIEs, false otherwise.
8413 Explanation: there is an invariant that if a CU is queued for expansion
8414 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8415 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8416 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8417 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8418 invariant is respected.
8420 The caller is therefore not required to load the CU's DIEs (we return false)
8423 - the CU is already expanded, and therefore does not get enqueued
8424 - the CU gets enqueued for expansion, but its DIEs are already loaded
8426 Note that the caller should not use this function's return value as an
8427 indicator of whether the CU's DIEs are loaded right now, it should check
8428 that by calling `dwarf2_per_objfile::get_cu` instead. */
8431 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8432 dwarf2_per_cu_data
*per_cu
,
8433 dwarf2_per_objfile
*per_objfile
,
8434 enum language pretend_language
)
8436 /* We may arrive here during partial symbol reading, if we need full
8437 DIEs to process an unusual case (e.g. template arguments). Do
8438 not queue PER_CU, just tell our caller to load its DIEs. */
8439 if (per_cu
->per_bfd
->reading_partial_symbols
)
8441 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8443 if (cu
== NULL
|| cu
->dies
== NULL
)
8448 /* Mark the dependence relation so that we don't flush PER_CU
8450 if (dependent_cu
!= NULL
)
8451 dependent_cu
->add_dependence (per_cu
);
8453 /* If it's already on the queue, we have nothing to do. */
8456 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8458 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8460 /* If the CU is queued for expansion, it should not already be
8462 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8464 /* The DIEs are already loaded, the caller doesn't need to do it. */
8468 bool queued
= false;
8469 if (!per_objfile
->symtab_set_p (per_cu
))
8471 /* Add it to the queue. */
8472 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8476 /* If the compilation unit is already loaded, just mark it as
8478 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8482 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8483 and the DIEs are not already loaded. */
8484 return queued
&& cu
== nullptr;
8487 /* Process the queue. */
8490 process_queue (dwarf2_per_objfile
*per_objfile
)
8492 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8493 objfile_name (per_objfile
->objfile
));
8495 /* The queue starts out with one item, but following a DIE reference
8496 may load a new CU, adding it to the end of the queue. */
8497 while (!per_objfile
->per_bfd
->queue
->empty ())
8499 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8500 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8502 if (!per_objfile
->symtab_set_p (per_cu
))
8504 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8506 /* Skip dummy CUs. */
8509 unsigned int debug_print_threshold
;
8512 if (per_cu
->is_debug_types
)
8514 struct signatured_type
*sig_type
=
8515 (struct signatured_type
*) per_cu
;
8517 sprintf (buf
, "TU %s at offset %s",
8518 hex_string (sig_type
->signature
),
8519 sect_offset_str (per_cu
->sect_off
));
8520 /* There can be 100s of TUs.
8521 Only print them in verbose mode. */
8522 debug_print_threshold
= 2;
8526 sprintf (buf
, "CU at offset %s",
8527 sect_offset_str (per_cu
->sect_off
));
8528 debug_print_threshold
= 1;
8531 if (dwarf_read_debug
>= debug_print_threshold
)
8532 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8534 if (per_cu
->is_debug_types
)
8535 process_full_type_unit (cu
, item
.pretend_language
);
8537 process_full_comp_unit (cu
, item
.pretend_language
);
8539 if (dwarf_read_debug
>= debug_print_threshold
)
8540 dwarf_read_debug_printf ("Done expanding %s", buf
);
8545 per_objfile
->per_bfd
->queue
->pop ();
8548 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8549 objfile_name (per_objfile
->objfile
));
8552 /* Read in full symbols for PST, and anything it depends on. */
8555 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8557 gdb_assert (!readin_p (objfile
));
8559 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8560 free_cached_comp_units
freer (per_objfile
);
8561 expand_dependencies (objfile
);
8563 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8564 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8567 /* See psympriv.h. */
8570 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8572 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8573 return per_objfile
->symtab_set_p (per_cu_data
);
8576 /* See psympriv.h. */
8579 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8581 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8582 return per_objfile
->get_symtab (per_cu_data
);
8585 /* Trivial hash function for die_info: the hash value of a DIE
8586 is its offset in .debug_info for this objfile. */
8589 die_hash (const void *item
)
8591 const struct die_info
*die
= (const struct die_info
*) item
;
8593 return to_underlying (die
->sect_off
);
8596 /* Trivial comparison function for die_info structures: two DIEs
8597 are equal if they have the same offset. */
8600 die_eq (const void *item_lhs
, const void *item_rhs
)
8602 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8603 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8605 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8608 /* Load the DIEs associated with PER_CU into memory.
8610 In some cases, the caller, while reading partial symbols, will need to load
8611 the full symbols for the CU for some reason. It will already have a
8612 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8613 rather than creating a new one. */
8616 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8617 dwarf2_per_objfile
*per_objfile
,
8618 dwarf2_cu
*existing_cu
,
8620 enum language pretend_language
)
8622 gdb_assert (! this_cu
->is_debug_types
);
8624 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8628 struct dwarf2_cu
*cu
= reader
.cu
;
8629 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8631 gdb_assert (cu
->die_hash
== NULL
);
8633 htab_create_alloc_ex (cu
->header
.length
/ 12,
8637 &cu
->comp_unit_obstack
,
8638 hashtab_obstack_allocate
,
8639 dummy_obstack_deallocate
);
8641 if (reader
.comp_unit_die
->has_children
)
8642 reader
.comp_unit_die
->child
8643 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8644 &info_ptr
, reader
.comp_unit_die
);
8645 cu
->dies
= reader
.comp_unit_die
;
8646 /* comp_unit_die is not stored in die_hash, no need. */
8648 /* We try not to read any attributes in this function, because not
8649 all CUs needed for references have been loaded yet, and symbol
8650 table processing isn't initialized. But we have to set the CU language,
8651 or we won't be able to build types correctly.
8652 Similarly, if we do not read the producer, we can not apply
8653 producer-specific interpretation. */
8654 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8659 /* Add a DIE to the delayed physname list. */
8662 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8663 const char *name
, struct die_info
*die
,
8664 struct dwarf2_cu
*cu
)
8666 struct delayed_method_info mi
;
8668 mi
.fnfield_index
= fnfield_index
;
8672 cu
->method_list
.push_back (mi
);
8675 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8676 "const" / "volatile". If so, decrements LEN by the length of the
8677 modifier and return true. Otherwise return false. */
8681 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8683 size_t mod_len
= sizeof (mod
) - 1;
8684 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8692 /* Compute the physnames of any methods on the CU's method list.
8694 The computation of method physnames is delayed in order to avoid the
8695 (bad) condition that one of the method's formal parameters is of an as yet
8699 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8701 /* Only C++ delays computing physnames. */
8702 if (cu
->method_list
.empty ())
8704 gdb_assert (cu
->language
== language_cplus
);
8706 for (const delayed_method_info
&mi
: cu
->method_list
)
8708 const char *physname
;
8709 struct fn_fieldlist
*fn_flp
8710 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8711 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8712 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8713 = physname
? physname
: "";
8715 /* Since there's no tag to indicate whether a method is a
8716 const/volatile overload, extract that information out of the
8718 if (physname
!= NULL
)
8720 size_t len
= strlen (physname
);
8724 if (physname
[len
] == ')') /* shortcut */
8726 else if (check_modifier (physname
, len
, " const"))
8727 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8728 else if (check_modifier (physname
, len
, " volatile"))
8729 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8736 /* The list is no longer needed. */
8737 cu
->method_list
.clear ();
8740 /* Go objects should be embedded in a DW_TAG_module DIE,
8741 and it's not clear if/how imported objects will appear.
8742 To keep Go support simple until that's worked out,
8743 go back through what we've read and create something usable.
8744 We could do this while processing each DIE, and feels kinda cleaner,
8745 but that way is more invasive.
8746 This is to, for example, allow the user to type "p var" or "b main"
8747 without having to specify the package name, and allow lookups
8748 of module.object to work in contexts that use the expression
8752 fixup_go_packaging (struct dwarf2_cu
*cu
)
8754 gdb::unique_xmalloc_ptr
<char> package_name
;
8755 struct pending
*list
;
8758 for (list
= *cu
->get_builder ()->get_global_symbols ();
8762 for (i
= 0; i
< list
->nsyms
; ++i
)
8764 struct symbol
*sym
= list
->symbol
[i
];
8766 if (sym
->language () == language_go
8767 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8769 gdb::unique_xmalloc_ptr
<char> this_package_name
8770 (go_symbol_package_name (sym
));
8772 if (this_package_name
== NULL
)
8774 if (package_name
== NULL
)
8775 package_name
= std::move (this_package_name
);
8778 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8779 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8780 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8781 (symbol_symtab (sym
) != NULL
8782 ? symtab_to_filename_for_display
8783 (symbol_symtab (sym
))
8784 : objfile_name (objfile
)),
8785 this_package_name
.get (), package_name
.get ());
8791 if (package_name
!= NULL
)
8793 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8794 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8795 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8796 saved_package_name
);
8799 sym
= new (&objfile
->objfile_obstack
) symbol
;
8800 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8801 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8802 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8803 e.g., "main" finds the "main" module and not C's main(). */
8804 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8805 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8806 SYMBOL_TYPE (sym
) = type
;
8808 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8812 /* Allocate a fully-qualified name consisting of the two parts on the
8816 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8818 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8821 /* A helper that allocates a variant part to attach to a Rust enum
8822 type. OBSTACK is where the results should be allocated. TYPE is
8823 the type we're processing. DISCRIMINANT_INDEX is the index of the
8824 discriminant. It must be the index of one of the fields of TYPE,
8825 or -1 to mean there is no discriminant (univariant enum).
8826 DEFAULT_INDEX is the index of the default field; or -1 if there is
8827 no default. RANGES is indexed by "effective" field number (the
8828 field index, but omitting the discriminant and default fields) and
8829 must hold the discriminant values used by the variants. Note that
8830 RANGES must have a lifetime at least as long as OBSTACK -- either
8831 already allocated on it, or static. */
8834 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8835 int discriminant_index
, int default_index
,
8836 gdb::array_view
<discriminant_range
> ranges
)
8838 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8839 gdb_assert (discriminant_index
== -1
8840 || (discriminant_index
>= 0
8841 && discriminant_index
< type
->num_fields ()));
8842 gdb_assert (default_index
== -1
8843 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8845 /* We have one variant for each non-discriminant field. */
8846 int n_variants
= type
->num_fields ();
8847 if (discriminant_index
!= -1)
8850 variant
*variants
= new (obstack
) variant
[n_variants
];
8853 for (int i
= 0; i
< type
->num_fields (); ++i
)
8855 if (i
== discriminant_index
)
8858 variants
[var_idx
].first_field
= i
;
8859 variants
[var_idx
].last_field
= i
+ 1;
8861 /* The default field does not need a range, but other fields do.
8862 We skipped the discriminant above. */
8863 if (i
!= default_index
)
8865 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8872 gdb_assert (range_idx
== ranges
.size ());
8873 gdb_assert (var_idx
== n_variants
);
8875 variant_part
*part
= new (obstack
) variant_part
;
8876 part
->discriminant_index
= discriminant_index
;
8877 /* If there is no discriminant, then whether it is signed is of no
8880 = (discriminant_index
== -1
8882 : type
->field (discriminant_index
).type ()->is_unsigned ());
8883 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
8885 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
8886 gdb::array_view
<variant_part
> *prop_value
8887 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
8889 struct dynamic_prop prop
;
8890 prop
.set_variant_parts (prop_value
);
8892 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
8895 /* Some versions of rustc emitted enums in an unusual way.
8897 Ordinary enums were emitted as unions. The first element of each
8898 structure in the union was named "RUST$ENUM$DISR". This element
8899 held the discriminant.
8901 These versions of Rust also implemented the "non-zero"
8902 optimization. When the enum had two values, and one is empty and
8903 the other holds a pointer that cannot be zero, the pointer is used
8904 as the discriminant, with a zero value meaning the empty variant.
8905 Here, the union's first member is of the form
8906 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8907 where the fieldnos are the indices of the fields that should be
8908 traversed in order to find the field (which may be several fields deep)
8909 and the variantname is the name of the variant of the case when the
8912 This function recognizes whether TYPE is of one of these forms,
8913 and, if so, smashes it to be a variant type. */
8916 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
8918 gdb_assert (type
->code () == TYPE_CODE_UNION
);
8920 /* We don't need to deal with empty enums. */
8921 if (type
->num_fields () == 0)
8924 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8925 if (type
->num_fields () == 1
8926 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
8928 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
8930 /* Decode the field name to find the offset of the
8932 ULONGEST bit_offset
= 0;
8933 struct type
*field_type
= type
->field (0).type ();
8934 while (name
[0] >= '0' && name
[0] <= '9')
8937 unsigned long index
= strtoul (name
, &tail
, 10);
8940 || index
>= field_type
->num_fields ()
8941 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
8942 != FIELD_LOC_KIND_BITPOS
))
8944 complaint (_("Could not parse Rust enum encoding string \"%s\""
8946 TYPE_FIELD_NAME (type
, 0),
8947 objfile_name (objfile
));
8952 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
8953 field_type
= field_type
->field (index
).type ();
8956 /* Smash this type to be a structure type. We have to do this
8957 because the type has already been recorded. */
8958 type
->set_code (TYPE_CODE_STRUCT
);
8959 type
->set_num_fields (3);
8960 /* Save the field we care about. */
8961 struct field saved_field
= type
->field (0);
8963 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
8965 /* Put the discriminant at index 0. */
8966 type
->field (0).set_type (field_type
);
8967 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
8968 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
8969 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
8971 /* The order of fields doesn't really matter, so put the real
8972 field at index 1 and the data-less field at index 2. */
8973 type
->field (1) = saved_field
;
8974 TYPE_FIELD_NAME (type
, 1)
8975 = rust_last_path_segment (type
->field (1).type ()->name ());
8976 type
->field (1).type ()->set_name
8977 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8978 TYPE_FIELD_NAME (type
, 1)));
8980 const char *dataless_name
8981 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8983 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
8985 type
->field (2).set_type (dataless_type
);
8986 /* NAME points into the original discriminant name, which
8987 already has the correct lifetime. */
8988 TYPE_FIELD_NAME (type
, 2) = name
;
8989 SET_FIELD_BITPOS (type
->field (2), 0);
8991 /* Indicate that this is a variant type. */
8992 static discriminant_range ranges
[1] = { { 0, 0 } };
8993 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
8995 /* A union with a single anonymous field is probably an old-style
8997 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
8999 /* Smash this type to be a structure type. We have to do this
9000 because the type has already been recorded. */
9001 type
->set_code (TYPE_CODE_STRUCT
);
9003 struct type
*field_type
= type
->field (0).type ();
9004 const char *variant_name
9005 = rust_last_path_segment (field_type
->name ());
9006 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9007 field_type
->set_name
9008 (rust_fully_qualify (&objfile
->objfile_obstack
,
9009 type
->name (), variant_name
));
9011 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9015 struct type
*disr_type
= nullptr;
9016 for (int i
= 0; i
< type
->num_fields (); ++i
)
9018 disr_type
= type
->field (i
).type ();
9020 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9022 /* All fields of a true enum will be structs. */
9025 else if (disr_type
->num_fields () == 0)
9027 /* Could be data-less variant, so keep going. */
9028 disr_type
= nullptr;
9030 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9031 "RUST$ENUM$DISR") != 0)
9033 /* Not a Rust enum. */
9043 /* If we got here without a discriminant, then it's probably
9045 if (disr_type
== nullptr)
9048 /* Smash this type to be a structure type. We have to do this
9049 because the type has already been recorded. */
9050 type
->set_code (TYPE_CODE_STRUCT
);
9052 /* Make space for the discriminant field. */
9053 struct field
*disr_field
= &disr_type
->field (0);
9055 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9056 * sizeof (struct field
)));
9057 memcpy (new_fields
+ 1, type
->fields (),
9058 type
->num_fields () * sizeof (struct field
));
9059 type
->set_fields (new_fields
);
9060 type
->set_num_fields (type
->num_fields () + 1);
9062 /* Install the discriminant at index 0 in the union. */
9063 type
->field (0) = *disr_field
;
9064 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9065 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9067 /* We need a way to find the correct discriminant given a
9068 variant name. For convenience we build a map here. */
9069 struct type
*enum_type
= disr_field
->type ();
9070 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9071 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9073 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9076 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9077 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9081 int n_fields
= type
->num_fields ();
9082 /* We don't need a range entry for the discriminant, but we do
9083 need one for every other field, as there is no default
9085 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9088 /* Skip the discriminant here. */
9089 for (int i
= 1; i
< n_fields
; ++i
)
9091 /* Find the final word in the name of this variant's type.
9092 That name can be used to look up the correct
9094 const char *variant_name
9095 = rust_last_path_segment (type
->field (i
).type ()->name ());
9097 auto iter
= discriminant_map
.find (variant_name
);
9098 if (iter
!= discriminant_map
.end ())
9100 ranges
[i
- 1].low
= iter
->second
;
9101 ranges
[i
- 1].high
= iter
->second
;
9104 /* In Rust, each element should have the size of the
9106 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9108 /* Remove the discriminant field, if it exists. */
9109 struct type
*sub_type
= type
->field (i
).type ();
9110 if (sub_type
->num_fields () > 0)
9112 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9113 sub_type
->set_fields (sub_type
->fields () + 1);
9115 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9117 (rust_fully_qualify (&objfile
->objfile_obstack
,
9118 type
->name (), variant_name
));
9121 /* Indicate that this is a variant type. */
9122 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9123 gdb::array_view
<discriminant_range
> (ranges
,
9128 /* Rewrite some Rust unions to be structures with variants parts. */
9131 rust_union_quirks (struct dwarf2_cu
*cu
)
9133 gdb_assert (cu
->language
== language_rust
);
9134 for (type
*type_
: cu
->rust_unions
)
9135 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9136 /* We don't need this any more. */
9137 cu
->rust_unions
.clear ();
9142 type_unit_group_unshareable
*
9143 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9145 auto iter
= this->m_type_units
.find (tu_group
);
9146 if (iter
!= this->m_type_units
.end ())
9147 return iter
->second
.get ();
9149 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9150 type_unit_group_unshareable
*result
= uniq
.get ();
9151 this->m_type_units
[tu_group
] = std::move (uniq
);
9156 dwarf2_per_objfile::get_type_for_signatured_type
9157 (signatured_type
*sig_type
) const
9159 auto iter
= this->m_type_map
.find (sig_type
);
9160 if (iter
== this->m_type_map
.end ())
9163 return iter
->second
;
9166 void dwarf2_per_objfile::set_type_for_signatured_type
9167 (signatured_type
*sig_type
, struct type
*type
)
9169 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9171 this->m_type_map
[sig_type
] = type
;
9174 /* A helper function for computing the list of all symbol tables
9175 included by PER_CU. */
9178 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9179 htab_t all_children
, htab_t all_type_symtabs
,
9180 dwarf2_per_cu_data
*per_cu
,
9181 dwarf2_per_objfile
*per_objfile
,
9182 struct compunit_symtab
*immediate_parent
)
9184 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9187 /* This inclusion and its children have been processed. */
9193 /* Only add a CU if it has a symbol table. */
9194 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9197 /* If this is a type unit only add its symbol table if we haven't
9198 seen it yet (type unit per_cu's can share symtabs). */
9199 if (per_cu
->is_debug_types
)
9201 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9205 result
->push_back (cust
);
9206 if (cust
->user
== NULL
)
9207 cust
->user
= immediate_parent
;
9212 result
->push_back (cust
);
9213 if (cust
->user
== NULL
)
9214 cust
->user
= immediate_parent
;
9218 if (!per_cu
->imported_symtabs_empty ())
9219 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9221 recursively_compute_inclusions (result
, all_children
,
9222 all_type_symtabs
, ptr
, per_objfile
,
9227 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9231 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9232 dwarf2_per_objfile
*per_objfile
)
9234 gdb_assert (! per_cu
->is_debug_types
);
9236 if (!per_cu
->imported_symtabs_empty ())
9239 std::vector
<compunit_symtab
*> result_symtabs
;
9240 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9242 /* If we don't have a symtab, we can just skip this case. */
9246 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9248 NULL
, xcalloc
, xfree
));
9249 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9251 NULL
, xcalloc
, xfree
));
9253 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9255 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9256 all_type_symtabs
.get (), ptr
,
9260 /* Now we have a transitive closure of all the included symtabs. */
9261 len
= result_symtabs
.size ();
9263 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9264 struct compunit_symtab
*, len
+ 1);
9265 memcpy (cust
->includes
, result_symtabs
.data (),
9266 len
* sizeof (compunit_symtab
*));
9267 cust
->includes
[len
] = NULL
;
9271 /* Compute the 'includes' field for the symtabs of all the CUs we just
9275 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9277 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9279 if (! iter
->is_debug_types
)
9280 compute_compunit_symtab_includes (iter
, per_objfile
);
9283 per_objfile
->per_bfd
->just_read_cus
.clear ();
9286 /* Generate full symbol information for CU, whose DIEs have
9287 already been loaded into memory. */
9290 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9292 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9293 struct objfile
*objfile
= per_objfile
->objfile
;
9294 struct gdbarch
*gdbarch
= objfile
->arch ();
9295 CORE_ADDR lowpc
, highpc
;
9296 struct compunit_symtab
*cust
;
9298 struct block
*static_block
;
9301 baseaddr
= objfile
->text_section_offset ();
9303 /* Clear the list here in case something was left over. */
9304 cu
->method_list
.clear ();
9306 cu
->language
= pretend_language
;
9307 cu
->language_defn
= language_def (cu
->language
);
9309 dwarf2_find_base_address (cu
->dies
, cu
);
9311 /* Before we start reading the top-level DIE, ensure it has a valid tag
9313 switch (cu
->dies
->tag
)
9315 case DW_TAG_compile_unit
:
9316 case DW_TAG_partial_unit
:
9317 case DW_TAG_type_unit
:
9320 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9321 dwarf_tag_name (cu
->dies
->tag
),
9322 sect_offset_str (cu
->per_cu
->sect_off
),
9323 objfile_name (per_objfile
->objfile
));
9326 /* Do line number decoding in read_file_scope () */
9327 process_die (cu
->dies
, cu
);
9329 /* For now fudge the Go package. */
9330 if (cu
->language
== language_go
)
9331 fixup_go_packaging (cu
);
9333 /* Now that we have processed all the DIEs in the CU, all the types
9334 should be complete, and it should now be safe to compute all of the
9336 compute_delayed_physnames (cu
);
9338 if (cu
->language
== language_rust
)
9339 rust_union_quirks (cu
);
9341 /* Some compilers don't define a DW_AT_high_pc attribute for the
9342 compilation unit. If the DW_AT_high_pc is missing, synthesize
9343 it, by scanning the DIE's below the compilation unit. */
9344 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9346 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9347 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9349 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9350 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9351 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9352 addrmap to help ensure it has an accurate map of pc values belonging to
9354 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9356 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9357 SECT_OFF_TEXT (objfile
),
9362 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9364 /* Set symtab language to language from DW_AT_language. If the
9365 compilation is from a C file generated by language preprocessors, do
9366 not set the language if it was already deduced by start_subfile. */
9367 if (!(cu
->language
== language_c
9368 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9369 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9371 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9372 produce DW_AT_location with location lists but it can be possibly
9373 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9374 there were bugs in prologue debug info, fixed later in GCC-4.5
9375 by "unwind info for epilogues" patch (which is not directly related).
9377 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9378 needed, it would be wrong due to missing DW_AT_producer there.
9380 Still one can confuse GDB by using non-standard GCC compilation
9381 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9383 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9384 cust
->locations_valid
= 1;
9386 if (gcc_4_minor
>= 5)
9387 cust
->epilogue_unwind_valid
= 1;
9389 cust
->call_site_htab
= cu
->call_site_htab
;
9392 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9394 /* Push it for inclusion processing later. */
9395 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9397 /* Not needed any more. */
9398 cu
->reset_builder ();
9401 /* Generate full symbol information for type unit CU, whose DIEs have
9402 already been loaded into memory. */
9405 process_full_type_unit (dwarf2_cu
*cu
,
9406 enum language pretend_language
)
9408 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9409 struct objfile
*objfile
= per_objfile
->objfile
;
9410 struct compunit_symtab
*cust
;
9411 struct signatured_type
*sig_type
;
9413 gdb_assert (cu
->per_cu
->is_debug_types
);
9414 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9416 /* Clear the list here in case something was left over. */
9417 cu
->method_list
.clear ();
9419 cu
->language
= pretend_language
;
9420 cu
->language_defn
= language_def (cu
->language
);
9422 /* The symbol tables are set up in read_type_unit_scope. */
9423 process_die (cu
->dies
, cu
);
9425 /* For now fudge the Go package. */
9426 if (cu
->language
== language_go
)
9427 fixup_go_packaging (cu
);
9429 /* Now that we have processed all the DIEs in the CU, all the types
9430 should be complete, and it should now be safe to compute all of the
9432 compute_delayed_physnames (cu
);
9434 if (cu
->language
== language_rust
)
9435 rust_union_quirks (cu
);
9437 /* TUs share symbol tables.
9438 If this is the first TU to use this symtab, complete the construction
9439 of it with end_expandable_symtab. Otherwise, complete the addition of
9440 this TU's symbols to the existing symtab. */
9441 type_unit_group_unshareable
*tug_unshare
=
9442 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9443 if (tug_unshare
->compunit_symtab
== NULL
)
9445 buildsym_compunit
*builder
= cu
->get_builder ();
9446 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9447 tug_unshare
->compunit_symtab
= cust
;
9451 /* Set symtab language to language from DW_AT_language. If the
9452 compilation is from a C file generated by language preprocessors,
9453 do not set the language if it was already deduced by
9455 if (!(cu
->language
== language_c
9456 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9457 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9462 cu
->get_builder ()->augment_type_symtab ();
9463 cust
= tug_unshare
->compunit_symtab
;
9466 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9468 /* Not needed any more. */
9469 cu
->reset_builder ();
9472 /* Process an imported unit DIE. */
9475 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9477 struct attribute
*attr
;
9479 /* For now we don't handle imported units in type units. */
9480 if (cu
->per_cu
->is_debug_types
)
9482 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9483 " supported in type units [in module %s]"),
9484 objfile_name (cu
->per_objfile
->objfile
));
9487 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9490 sect_offset sect_off
= attr
->get_ref_die_offset ();
9491 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9492 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9493 dwarf2_per_cu_data
*per_cu
9494 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9496 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9497 into another compilation unit, at root level. Regard this as a hint,
9499 if (die
->parent
&& die
->parent
->parent
== NULL
9500 && per_cu
->unit_type
== DW_UT_compile
9501 && per_cu
->lang
== language_cplus
)
9504 /* If necessary, add it to the queue and load its DIEs. */
9505 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9506 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9507 false, cu
->language
);
9509 cu
->per_cu
->imported_symtabs_push (per_cu
);
9513 /* RAII object that represents a process_die scope: i.e.,
9514 starts/finishes processing a DIE. */
9515 class process_die_scope
9518 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9519 : m_die (die
), m_cu (cu
)
9521 /* We should only be processing DIEs not already in process. */
9522 gdb_assert (!m_die
->in_process
);
9523 m_die
->in_process
= true;
9526 ~process_die_scope ()
9528 m_die
->in_process
= false;
9530 /* If we're done processing the DIE for the CU that owns the line
9531 header, we don't need the line header anymore. */
9532 if (m_cu
->line_header_die_owner
== m_die
)
9534 delete m_cu
->line_header
;
9535 m_cu
->line_header
= NULL
;
9536 m_cu
->line_header_die_owner
= NULL
;
9545 /* Process a die and its children. */
9548 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9550 process_die_scope
scope (die
, cu
);
9554 case DW_TAG_padding
:
9556 case DW_TAG_compile_unit
:
9557 case DW_TAG_partial_unit
:
9558 read_file_scope (die
, cu
);
9560 case DW_TAG_type_unit
:
9561 read_type_unit_scope (die
, cu
);
9563 case DW_TAG_subprogram
:
9564 /* Nested subprograms in Fortran get a prefix. */
9565 if (cu
->language
== language_fortran
9566 && die
->parent
!= NULL
9567 && die
->parent
->tag
== DW_TAG_subprogram
)
9568 cu
->processing_has_namespace_info
= true;
9570 case DW_TAG_inlined_subroutine
:
9571 read_func_scope (die
, cu
);
9573 case DW_TAG_lexical_block
:
9574 case DW_TAG_try_block
:
9575 case DW_TAG_catch_block
:
9576 read_lexical_block_scope (die
, cu
);
9578 case DW_TAG_call_site
:
9579 case DW_TAG_GNU_call_site
:
9580 read_call_site_scope (die
, cu
);
9582 case DW_TAG_class_type
:
9583 case DW_TAG_interface_type
:
9584 case DW_TAG_structure_type
:
9585 case DW_TAG_union_type
:
9586 process_structure_scope (die
, cu
);
9588 case DW_TAG_enumeration_type
:
9589 process_enumeration_scope (die
, cu
);
9592 /* These dies have a type, but processing them does not create
9593 a symbol or recurse to process the children. Therefore we can
9594 read them on-demand through read_type_die. */
9595 case DW_TAG_subroutine_type
:
9596 case DW_TAG_set_type
:
9597 case DW_TAG_pointer_type
:
9598 case DW_TAG_ptr_to_member_type
:
9599 case DW_TAG_reference_type
:
9600 case DW_TAG_rvalue_reference_type
:
9601 case DW_TAG_string_type
:
9604 case DW_TAG_array_type
:
9605 /* We only need to handle this case for Ada -- in other
9606 languages, it's normal for the compiler to emit a typedef
9608 if (cu
->language
!= language_ada
)
9611 case DW_TAG_base_type
:
9612 case DW_TAG_subrange_type
:
9613 case DW_TAG_typedef
:
9614 /* Add a typedef symbol for the type definition, if it has a
9616 new_symbol (die
, read_type_die (die
, cu
), cu
);
9618 case DW_TAG_common_block
:
9619 read_common_block (die
, cu
);
9621 case DW_TAG_common_inclusion
:
9623 case DW_TAG_namespace
:
9624 cu
->processing_has_namespace_info
= true;
9625 read_namespace (die
, cu
);
9628 cu
->processing_has_namespace_info
= true;
9629 read_module (die
, cu
);
9631 case DW_TAG_imported_declaration
:
9632 cu
->processing_has_namespace_info
= true;
9633 if (read_namespace_alias (die
, cu
))
9635 /* The declaration is not a global namespace alias. */
9637 case DW_TAG_imported_module
:
9638 cu
->processing_has_namespace_info
= true;
9639 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9640 || cu
->language
!= language_fortran
))
9641 complaint (_("Tag '%s' has unexpected children"),
9642 dwarf_tag_name (die
->tag
));
9643 read_import_statement (die
, cu
);
9646 case DW_TAG_imported_unit
:
9647 process_imported_unit_die (die
, cu
);
9650 case DW_TAG_variable
:
9651 read_variable (die
, cu
);
9655 new_symbol (die
, NULL
, cu
);
9660 /* DWARF name computation. */
9662 /* A helper function for dwarf2_compute_name which determines whether DIE
9663 needs to have the name of the scope prepended to the name listed in the
9667 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9669 struct attribute
*attr
;
9673 case DW_TAG_namespace
:
9674 case DW_TAG_typedef
:
9675 case DW_TAG_class_type
:
9676 case DW_TAG_interface_type
:
9677 case DW_TAG_structure_type
:
9678 case DW_TAG_union_type
:
9679 case DW_TAG_enumeration_type
:
9680 case DW_TAG_enumerator
:
9681 case DW_TAG_subprogram
:
9682 case DW_TAG_inlined_subroutine
:
9684 case DW_TAG_imported_declaration
:
9687 case DW_TAG_variable
:
9688 case DW_TAG_constant
:
9689 /* We only need to prefix "globally" visible variables. These include
9690 any variable marked with DW_AT_external or any variable that
9691 lives in a namespace. [Variables in anonymous namespaces
9692 require prefixing, but they are not DW_AT_external.] */
9694 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9696 struct dwarf2_cu
*spec_cu
= cu
;
9698 return die_needs_namespace (die_specification (die
, &spec_cu
),
9702 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9703 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9704 && die
->parent
->tag
!= DW_TAG_module
)
9706 /* A variable in a lexical block of some kind does not need a
9707 namespace, even though in C++ such variables may be external
9708 and have a mangled name. */
9709 if (die
->parent
->tag
== DW_TAG_lexical_block
9710 || die
->parent
->tag
== DW_TAG_try_block
9711 || die
->parent
->tag
== DW_TAG_catch_block
9712 || die
->parent
->tag
== DW_TAG_subprogram
)
9721 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9722 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9723 defined for the given DIE. */
9725 static struct attribute
*
9726 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9728 struct attribute
*attr
;
9730 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9732 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9737 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9738 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9739 defined for the given DIE. */
9742 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9744 const char *linkage_name
;
9746 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9747 if (linkage_name
== NULL
)
9748 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9750 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9751 See https://github.com/rust-lang/rust/issues/32925. */
9752 if (cu
->language
== language_rust
&& linkage_name
!= NULL
9753 && strchr (linkage_name
, '{') != NULL
)
9754 linkage_name
= NULL
;
9756 return linkage_name
;
9759 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9760 compute the physname for the object, which include a method's:
9761 - formal parameters (C++),
9762 - receiver type (Go),
9764 The term "physname" is a bit confusing.
9765 For C++, for example, it is the demangled name.
9766 For Go, for example, it's the mangled name.
9768 For Ada, return the DIE's linkage name rather than the fully qualified
9769 name. PHYSNAME is ignored..
9771 The result is allocated on the objfile->per_bfd's obstack and
9775 dwarf2_compute_name (const char *name
,
9776 struct die_info
*die
, struct dwarf2_cu
*cu
,
9779 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9782 name
= dwarf2_name (die
, cu
);
9784 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9785 but otherwise compute it by typename_concat inside GDB.
9786 FIXME: Actually this is not really true, or at least not always true.
9787 It's all very confusing. compute_and_set_names doesn't try to demangle
9788 Fortran names because there is no mangling standard. So new_symbol
9789 will set the demangled name to the result of dwarf2_full_name, and it is
9790 the demangled name that GDB uses if it exists. */
9791 if (cu
->language
== language_ada
9792 || (cu
->language
== language_fortran
&& physname
))
9794 /* For Ada unit, we prefer the linkage name over the name, as
9795 the former contains the exported name, which the user expects
9796 to be able to reference. Ideally, we want the user to be able
9797 to reference this entity using either natural or linkage name,
9798 but we haven't started looking at this enhancement yet. */
9799 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9801 if (linkage_name
!= NULL
)
9802 return linkage_name
;
9805 /* These are the only languages we know how to qualify names in. */
9807 && (cu
->language
== language_cplus
9808 || cu
->language
== language_fortran
|| cu
->language
== language_d
9809 || cu
->language
== language_rust
))
9811 if (die_needs_namespace (die
, cu
))
9814 const char *canonical_name
= NULL
;
9818 prefix
= determine_prefix (die
, cu
);
9819 if (*prefix
!= '\0')
9821 gdb::unique_xmalloc_ptr
<char> prefixed_name
9822 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9824 buf
.puts (prefixed_name
.get ());
9829 /* Template parameters may be specified in the DIE's DW_AT_name, or
9830 as children with DW_TAG_template_type_param or
9831 DW_TAG_value_type_param. If the latter, add them to the name
9832 here. If the name already has template parameters, then
9833 skip this step; some versions of GCC emit both, and
9834 it is more efficient to use the pre-computed name.
9836 Something to keep in mind about this process: it is very
9837 unlikely, or in some cases downright impossible, to produce
9838 something that will match the mangled name of a function.
9839 If the definition of the function has the same debug info,
9840 we should be able to match up with it anyway. But fallbacks
9841 using the minimal symbol, for instance to find a method
9842 implemented in a stripped copy of libstdc++, will not work.
9843 If we do not have debug info for the definition, we will have to
9844 match them up some other way.
9846 When we do name matching there is a related problem with function
9847 templates; two instantiated function templates are allowed to
9848 differ only by their return types, which we do not add here. */
9850 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
9852 struct attribute
*attr
;
9853 struct die_info
*child
;
9855 const language_defn
*cplus_lang
= language_def (cu
->language
);
9857 die
->building_fullname
= 1;
9859 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9863 const gdb_byte
*bytes
;
9864 struct dwarf2_locexpr_baton
*baton
;
9867 if (child
->tag
!= DW_TAG_template_type_param
9868 && child
->tag
!= DW_TAG_template_value_param
)
9879 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9882 complaint (_("template parameter missing DW_AT_type"));
9883 buf
.puts ("UNKNOWN_TYPE");
9886 type
= die_type (child
, cu
);
9888 if (child
->tag
== DW_TAG_template_type_param
)
9890 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
9891 &type_print_raw_options
);
9895 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9898 complaint (_("template parameter missing "
9899 "DW_AT_const_value"));
9900 buf
.puts ("UNKNOWN_VALUE");
9904 dwarf2_const_value_attr (attr
, type
, name
,
9905 &cu
->comp_unit_obstack
, cu
,
9906 &value
, &bytes
, &baton
);
9908 if (type
->has_no_signedness ())
9909 /* GDB prints characters as NUMBER 'CHAR'. If that's
9910 changed, this can use value_print instead. */
9911 cplus_lang
->printchar (value
, type
, &buf
);
9914 struct value_print_options opts
;
9917 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9921 baton
->per_objfile
);
9922 else if (bytes
!= NULL
)
9924 v
= allocate_value (type
);
9925 memcpy (value_contents_writeable (v
), bytes
,
9926 TYPE_LENGTH (type
));
9929 v
= value_from_longest (type
, value
);
9931 /* Specify decimal so that we do not depend on
9933 get_formatted_print_options (&opts
, 'd');
9935 value_print (v
, &buf
, &opts
);
9940 die
->building_fullname
= 0;
9944 /* Close the argument list, with a space if necessary
9945 (nested templates). */
9946 if (!buf
.empty () && buf
.string ().back () == '>')
9953 /* For C++ methods, append formal parameter type
9954 information, if PHYSNAME. */
9956 if (physname
&& die
->tag
== DW_TAG_subprogram
9957 && cu
->language
== language_cplus
)
9959 struct type
*type
= read_type_die (die
, cu
);
9961 c_type_print_args (type
, &buf
, 1, cu
->language
,
9962 &type_print_raw_options
);
9964 if (cu
->language
== language_cplus
)
9966 /* Assume that an artificial first parameter is
9967 "this", but do not crash if it is not. RealView
9968 marks unnamed (and thus unused) parameters as
9969 artificial; there is no way to differentiate
9971 if (type
->num_fields () > 0
9972 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9973 && type
->field (0).type ()->code () == TYPE_CODE_PTR
9974 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
9975 buf
.puts (" const");
9979 const std::string
&intermediate_name
= buf
.string ();
9981 if (cu
->language
== language_cplus
)
9983 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9986 /* If we only computed INTERMEDIATE_NAME, or if
9987 INTERMEDIATE_NAME is already canonical, then we need to
9989 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9990 name
= objfile
->intern (intermediate_name
);
9992 name
= canonical_name
;
9999 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10000 If scope qualifiers are appropriate they will be added. The result
10001 will be allocated on the storage_obstack, or NULL if the DIE does
10002 not have a name. NAME may either be from a previous call to
10003 dwarf2_name or NULL.
10005 The output string will be canonicalized (if C++). */
10007 static const char *
10008 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10010 return dwarf2_compute_name (name
, die
, cu
, 0);
10013 /* Construct a physname for the given DIE in CU. NAME may either be
10014 from a previous call to dwarf2_name or NULL. The result will be
10015 allocated on the objfile_objstack or NULL if the DIE does not have a
10018 The output string will be canonicalized (if C++). */
10020 static const char *
10021 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10023 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10024 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10027 /* In this case dwarf2_compute_name is just a shortcut not building anything
10029 if (!die_needs_namespace (die
, cu
))
10030 return dwarf2_compute_name (name
, die
, cu
, 1);
10032 if (cu
->language
!= language_rust
)
10033 mangled
= dw2_linkage_name (die
, cu
);
10035 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10037 gdb::unique_xmalloc_ptr
<char> demangled
;
10038 if (mangled
!= NULL
)
10041 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10043 /* Do nothing (do not demangle the symbol name). */
10047 /* Use DMGL_RET_DROP for C++ template functions to suppress
10048 their return type. It is easier for GDB users to search
10049 for such functions as `name(params)' than `long name(params)'.
10050 In such case the minimal symbol names do not match the full
10051 symbol names but for template functions there is never a need
10052 to look up their definition from their declaration so
10053 the only disadvantage remains the minimal symbol variant
10054 `long name(params)' does not have the proper inferior type. */
10055 demangled
.reset (gdb_demangle (mangled
,
10056 (DMGL_PARAMS
| DMGL_ANSI
10057 | DMGL_RET_DROP
)));
10060 canon
= demangled
.get ();
10068 if (canon
== NULL
|| check_physname
)
10070 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10072 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10074 /* It may not mean a bug in GDB. The compiler could also
10075 compute DW_AT_linkage_name incorrectly. But in such case
10076 GDB would need to be bug-to-bug compatible. */
10078 complaint (_("Computed physname <%s> does not match demangled <%s> "
10079 "(from linkage <%s>) - DIE at %s [in module %s]"),
10080 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10081 objfile_name (objfile
));
10083 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10084 is available here - over computed PHYSNAME. It is safer
10085 against both buggy GDB and buggy compilers. */
10099 retval
= objfile
->intern (retval
);
10104 /* Inspect DIE in CU for a namespace alias. If one exists, record
10105 a new symbol for it.
10107 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10110 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10112 struct attribute
*attr
;
10114 /* If the die does not have a name, this is not a namespace
10116 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10120 struct die_info
*d
= die
;
10121 struct dwarf2_cu
*imported_cu
= cu
;
10123 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10124 keep inspecting DIEs until we hit the underlying import. */
10125 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10126 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10128 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10132 d
= follow_die_ref (d
, attr
, &imported_cu
);
10133 if (d
->tag
!= DW_TAG_imported_declaration
)
10137 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10139 complaint (_("DIE at %s has too many recursively imported "
10140 "declarations"), sect_offset_str (d
->sect_off
));
10147 sect_offset sect_off
= attr
->get_ref_die_offset ();
10149 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10150 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10152 /* This declaration is a global namespace alias. Add
10153 a symbol for it whose type is the aliased namespace. */
10154 new_symbol (die
, type
, cu
);
10163 /* Return the using directives repository (global or local?) to use in the
10164 current context for CU.
10166 For Ada, imported declarations can materialize renamings, which *may* be
10167 global. However it is impossible (for now?) in DWARF to distinguish
10168 "external" imported declarations and "static" ones. As all imported
10169 declarations seem to be static in all other languages, make them all CU-wide
10170 global only in Ada. */
10172 static struct using_direct
**
10173 using_directives (struct dwarf2_cu
*cu
)
10175 if (cu
->language
== language_ada
10176 && cu
->get_builder ()->outermost_context_p ())
10177 return cu
->get_builder ()->get_global_using_directives ();
10179 return cu
->get_builder ()->get_local_using_directives ();
10182 /* Read the import statement specified by the given die and record it. */
10185 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10187 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10188 struct attribute
*import_attr
;
10189 struct die_info
*imported_die
, *child_die
;
10190 struct dwarf2_cu
*imported_cu
;
10191 const char *imported_name
;
10192 const char *imported_name_prefix
;
10193 const char *canonical_name
;
10194 const char *import_alias
;
10195 const char *imported_declaration
= NULL
;
10196 const char *import_prefix
;
10197 std::vector
<const char *> excludes
;
10199 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10200 if (import_attr
== NULL
)
10202 complaint (_("Tag '%s' has no DW_AT_import"),
10203 dwarf_tag_name (die
->tag
));
10208 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10209 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10210 if (imported_name
== NULL
)
10212 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10214 The import in the following code:
10228 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10229 <52> DW_AT_decl_file : 1
10230 <53> DW_AT_decl_line : 6
10231 <54> DW_AT_import : <0x75>
10232 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10233 <59> DW_AT_name : B
10234 <5b> DW_AT_decl_file : 1
10235 <5c> DW_AT_decl_line : 2
10236 <5d> DW_AT_type : <0x6e>
10238 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10239 <76> DW_AT_byte_size : 4
10240 <77> DW_AT_encoding : 5 (signed)
10242 imports the wrong die ( 0x75 instead of 0x58 ).
10243 This case will be ignored until the gcc bug is fixed. */
10247 /* Figure out the local name after import. */
10248 import_alias
= dwarf2_name (die
, cu
);
10250 /* Figure out where the statement is being imported to. */
10251 import_prefix
= determine_prefix (die
, cu
);
10253 /* Figure out what the scope of the imported die is and prepend it
10254 to the name of the imported die. */
10255 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10257 if (imported_die
->tag
!= DW_TAG_namespace
10258 && imported_die
->tag
!= DW_TAG_module
)
10260 imported_declaration
= imported_name
;
10261 canonical_name
= imported_name_prefix
;
10263 else if (strlen (imported_name_prefix
) > 0)
10264 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10265 imported_name_prefix
,
10266 (cu
->language
== language_d
? "." : "::"),
10267 imported_name
, (char *) NULL
);
10269 canonical_name
= imported_name
;
10271 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10272 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10273 child_die
= child_die
->sibling
)
10275 /* DWARF-4: A Fortran use statement with a “rename list” may be
10276 represented by an imported module entry with an import attribute
10277 referring to the module and owned entries corresponding to those
10278 entities that are renamed as part of being imported. */
10280 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10282 complaint (_("child DW_TAG_imported_declaration expected "
10283 "- DIE at %s [in module %s]"),
10284 sect_offset_str (child_die
->sect_off
),
10285 objfile_name (objfile
));
10289 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10290 if (import_attr
== NULL
)
10292 complaint (_("Tag '%s' has no DW_AT_import"),
10293 dwarf_tag_name (child_die
->tag
));
10298 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10300 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10301 if (imported_name
== NULL
)
10303 complaint (_("child DW_TAG_imported_declaration has unknown "
10304 "imported name - DIE at %s [in module %s]"),
10305 sect_offset_str (child_die
->sect_off
),
10306 objfile_name (objfile
));
10310 excludes
.push_back (imported_name
);
10312 process_die (child_die
, cu
);
10315 add_using_directive (using_directives (cu
),
10319 imported_declaration
,
10322 &objfile
->objfile_obstack
);
10325 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10326 types, but gives them a size of zero. Starting with version 14,
10327 ICC is compatible with GCC. */
10330 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10332 if (!cu
->checked_producer
)
10333 check_producer (cu
);
10335 return cu
->producer_is_icc_lt_14
;
10338 /* ICC generates a DW_AT_type for C void functions. This was observed on
10339 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10340 which says that void functions should not have a DW_AT_type. */
10343 producer_is_icc (struct dwarf2_cu
*cu
)
10345 if (!cu
->checked_producer
)
10346 check_producer (cu
);
10348 return cu
->producer_is_icc
;
10351 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10352 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10353 this, it was first present in GCC release 4.3.0. */
10356 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10358 if (!cu
->checked_producer
)
10359 check_producer (cu
);
10361 return cu
->producer_is_gcc_lt_4_3
;
10364 static file_and_directory
10365 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10367 file_and_directory res
;
10369 /* Find the filename. Do not use dwarf2_name here, since the filename
10370 is not a source language identifier. */
10371 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10372 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10374 if (res
.comp_dir
== NULL
10375 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10376 && IS_ABSOLUTE_PATH (res
.name
))
10378 res
.comp_dir_storage
= ldirname (res
.name
);
10379 if (!res
.comp_dir_storage
.empty ())
10380 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10382 if (res
.comp_dir
!= NULL
)
10384 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10385 directory, get rid of it. */
10386 const char *cp
= strchr (res
.comp_dir
, ':');
10388 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10389 res
.comp_dir
= cp
+ 1;
10392 if (res
.name
== NULL
)
10393 res
.name
= "<unknown>";
10398 /* Handle DW_AT_stmt_list for a compilation unit.
10399 DIE is the DW_TAG_compile_unit die for CU.
10400 COMP_DIR is the compilation directory. LOWPC is passed to
10401 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10404 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10405 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10407 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10408 struct attribute
*attr
;
10409 struct line_header line_header_local
;
10410 hashval_t line_header_local_hash
;
10412 int decode_mapping
;
10414 gdb_assert (! cu
->per_cu
->is_debug_types
);
10416 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10417 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10420 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10422 /* The line header hash table is only created if needed (it exists to
10423 prevent redundant reading of the line table for partial_units).
10424 If we're given a partial_unit, we'll need it. If we're given a
10425 compile_unit, then use the line header hash table if it's already
10426 created, but don't create one just yet. */
10428 if (per_objfile
->line_header_hash
== NULL
10429 && die
->tag
== DW_TAG_partial_unit
)
10431 per_objfile
->line_header_hash
10432 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10433 line_header_eq_voidp
,
10434 free_line_header_voidp
,
10438 line_header_local
.sect_off
= line_offset
;
10439 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10440 line_header_local_hash
= line_header_hash (&line_header_local
);
10441 if (per_objfile
->line_header_hash
!= NULL
)
10443 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10444 &line_header_local
,
10445 line_header_local_hash
, NO_INSERT
);
10447 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10448 is not present in *SLOT (since if there is something in *SLOT then
10449 it will be for a partial_unit). */
10450 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10452 gdb_assert (*slot
!= NULL
);
10453 cu
->line_header
= (struct line_header
*) *slot
;
10458 /* dwarf_decode_line_header does not yet provide sufficient information.
10459 We always have to call also dwarf_decode_lines for it. */
10460 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10464 cu
->line_header
= lh
.release ();
10465 cu
->line_header_die_owner
= die
;
10467 if (per_objfile
->line_header_hash
== NULL
)
10471 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10472 &line_header_local
,
10473 line_header_local_hash
, INSERT
);
10474 gdb_assert (slot
!= NULL
);
10476 if (slot
!= NULL
&& *slot
== NULL
)
10478 /* This newly decoded line number information unit will be owned
10479 by line_header_hash hash table. */
10480 *slot
= cu
->line_header
;
10481 cu
->line_header_die_owner
= NULL
;
10485 /* We cannot free any current entry in (*slot) as that struct line_header
10486 may be already used by multiple CUs. Create only temporary decoded
10487 line_header for this CU - it may happen at most once for each line
10488 number information unit. And if we're not using line_header_hash
10489 then this is what we want as well. */
10490 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10492 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10493 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10498 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10501 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10503 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10504 struct objfile
*objfile
= per_objfile
->objfile
;
10505 struct gdbarch
*gdbarch
= objfile
->arch ();
10506 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10507 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10508 struct attribute
*attr
;
10509 struct die_info
*child_die
;
10510 CORE_ADDR baseaddr
;
10512 prepare_one_comp_unit (cu
, die
, cu
->language
);
10513 baseaddr
= objfile
->text_section_offset ();
10515 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10517 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10518 from finish_block. */
10519 if (lowpc
== ((CORE_ADDR
) -1))
10521 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10523 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10525 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10526 standardised yet. As a workaround for the language detection we fall
10527 back to the DW_AT_producer string. */
10528 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10529 cu
->language
= language_opencl
;
10531 /* Similar hack for Go. */
10532 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10533 set_cu_language (DW_LANG_Go
, cu
);
10535 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10537 /* Decode line number information if present. We do this before
10538 processing child DIEs, so that the line header table is available
10539 for DW_AT_decl_file. */
10540 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10542 /* Process all dies in compilation unit. */
10543 if (die
->child
!= NULL
)
10545 child_die
= die
->child
;
10546 while (child_die
&& child_die
->tag
)
10548 process_die (child_die
, cu
);
10549 child_die
= child_die
->sibling
;
10553 /* Decode macro information, if present. Dwarf 2 macro information
10554 refers to information in the line number info statement program
10555 header, so we can only read it if we've read the header
10557 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10559 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10560 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10562 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10563 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10565 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10569 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10570 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10572 unsigned int macro_offset
= attr
->as_unsigned ();
10574 dwarf_decode_macros (cu
, macro_offset
, 0);
10580 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10582 struct type_unit_group
*tu_group
;
10584 struct attribute
*attr
;
10586 struct signatured_type
*sig_type
;
10588 gdb_assert (per_cu
->is_debug_types
);
10589 sig_type
= (struct signatured_type
*) per_cu
;
10591 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10593 /* If we're using .gdb_index (includes -readnow) then
10594 per_cu->type_unit_group may not have been set up yet. */
10595 if (sig_type
->type_unit_group
== NULL
)
10596 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10597 tu_group
= sig_type
->type_unit_group
;
10599 /* If we've already processed this stmt_list there's no real need to
10600 do it again, we could fake it and just recreate the part we need
10601 (file name,index -> symtab mapping). If data shows this optimization
10602 is useful we can do it then. */
10603 type_unit_group_unshareable
*tug_unshare
10604 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10605 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10607 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10610 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10612 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10613 lh
= dwarf_decode_line_header (line_offset
, this);
10618 start_symtab ("", NULL
, 0);
10621 gdb_assert (tug_unshare
->symtabs
== NULL
);
10622 gdb_assert (m_builder
== nullptr);
10623 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10624 m_builder
.reset (new struct buildsym_compunit
10625 (COMPUNIT_OBJFILE (cust
), "",
10626 COMPUNIT_DIRNAME (cust
),
10627 compunit_language (cust
),
10629 list_in_scope
= get_builder ()->get_file_symbols ();
10634 line_header
= lh
.release ();
10635 line_header_die_owner
= die
;
10639 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10641 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10642 still initializing it, and our caller (a few levels up)
10643 process_full_type_unit still needs to know if this is the first
10646 tug_unshare
->symtabs
10647 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10648 struct symtab
*, line_header
->file_names_size ());
10650 auto &file_names
= line_header
->file_names ();
10651 for (i
= 0; i
< file_names
.size (); ++i
)
10653 file_entry
&fe
= file_names
[i
];
10654 dwarf2_start_subfile (this, fe
.name
,
10655 fe
.include_dir (line_header
));
10656 buildsym_compunit
*b
= get_builder ();
10657 if (b
->get_current_subfile ()->symtab
== NULL
)
10659 /* NOTE: start_subfile will recognize when it's been
10660 passed a file it has already seen. So we can't
10661 assume there's a simple mapping from
10662 cu->line_header->file_names to subfiles, plus
10663 cu->line_header->file_names may contain dups. */
10664 b
->get_current_subfile ()->symtab
10665 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10668 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10669 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10674 gdb_assert (m_builder
== nullptr);
10675 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10676 m_builder
.reset (new struct buildsym_compunit
10677 (COMPUNIT_OBJFILE (cust
), "",
10678 COMPUNIT_DIRNAME (cust
),
10679 compunit_language (cust
),
10681 list_in_scope
= get_builder ()->get_file_symbols ();
10683 auto &file_names
= line_header
->file_names ();
10684 for (i
= 0; i
< file_names
.size (); ++i
)
10686 file_entry
&fe
= file_names
[i
];
10687 fe
.symtab
= tug_unshare
->symtabs
[i
];
10691 /* The main symtab is allocated last. Type units don't have DW_AT_name
10692 so they don't have a "real" (so to speak) symtab anyway.
10693 There is later code that will assign the main symtab to all symbols
10694 that don't have one. We need to handle the case of a symbol with a
10695 missing symtab (DW_AT_decl_file) anyway. */
10698 /* Process DW_TAG_type_unit.
10699 For TUs we want to skip the first top level sibling if it's not the
10700 actual type being defined by this TU. In this case the first top
10701 level sibling is there to provide context only. */
10704 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10706 struct die_info
*child_die
;
10708 prepare_one_comp_unit (cu
, die
, language_minimal
);
10710 /* Initialize (or reinitialize) the machinery for building symtabs.
10711 We do this before processing child DIEs, so that the line header table
10712 is available for DW_AT_decl_file. */
10713 cu
->setup_type_unit_groups (die
);
10715 if (die
->child
!= NULL
)
10717 child_die
= die
->child
;
10718 while (child_die
&& child_die
->tag
)
10720 process_die (child_die
, cu
);
10721 child_die
= child_die
->sibling
;
10728 http://gcc.gnu.org/wiki/DebugFission
10729 http://gcc.gnu.org/wiki/DebugFissionDWP
10731 To simplify handling of both DWO files ("object" files with the DWARF info)
10732 and DWP files (a file with the DWOs packaged up into one file), we treat
10733 DWP files as having a collection of virtual DWO files. */
10736 hash_dwo_file (const void *item
)
10738 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10741 hash
= htab_hash_string (dwo_file
->dwo_name
);
10742 if (dwo_file
->comp_dir
!= NULL
)
10743 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10748 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10750 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10751 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10753 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10755 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10756 return lhs
->comp_dir
== rhs
->comp_dir
;
10757 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10760 /* Allocate a hash table for DWO files. */
10763 allocate_dwo_file_hash_table ()
10765 auto delete_dwo_file
= [] (void *item
)
10767 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10772 return htab_up (htab_create_alloc (41,
10779 /* Lookup DWO file DWO_NAME. */
10782 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10783 const char *dwo_name
,
10784 const char *comp_dir
)
10786 struct dwo_file find_entry
;
10789 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10790 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10792 find_entry
.dwo_name
= dwo_name
;
10793 find_entry
.comp_dir
= comp_dir
;
10794 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10801 hash_dwo_unit (const void *item
)
10803 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10805 /* This drops the top 32 bits of the id, but is ok for a hash. */
10806 return dwo_unit
->signature
;
10810 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10812 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10813 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10815 /* The signature is assumed to be unique within the DWO file.
10816 So while object file CU dwo_id's always have the value zero,
10817 that's OK, assuming each object file DWO file has only one CU,
10818 and that's the rule for now. */
10819 return lhs
->signature
== rhs
->signature
;
10822 /* Allocate a hash table for DWO CUs,TUs.
10823 There is one of these tables for each of CUs,TUs for each DWO file. */
10826 allocate_dwo_unit_table ()
10828 /* Start out with a pretty small number.
10829 Generally DWO files contain only one CU and maybe some TUs. */
10830 return htab_up (htab_create_alloc (3,
10833 NULL
, xcalloc
, xfree
));
10836 /* die_reader_func for create_dwo_cu. */
10839 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10840 const gdb_byte
*info_ptr
,
10841 struct die_info
*comp_unit_die
,
10842 struct dwo_file
*dwo_file
,
10843 struct dwo_unit
*dwo_unit
)
10845 struct dwarf2_cu
*cu
= reader
->cu
;
10846 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10847 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10849 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10850 if (!signature
.has_value ())
10852 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10853 " its dwo_id [in module %s]"),
10854 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10858 dwo_unit
->dwo_file
= dwo_file
;
10859 dwo_unit
->signature
= *signature
;
10860 dwo_unit
->section
= section
;
10861 dwo_unit
->sect_off
= sect_off
;
10862 dwo_unit
->length
= cu
->per_cu
->length
;
10864 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10865 sect_offset_str (sect_off
),
10866 hex_string (dwo_unit
->signature
));
10869 /* Create the dwo_units for the CUs in a DWO_FILE.
10870 Note: This function processes DWO files only, not DWP files. */
10873 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10874 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10875 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10877 struct objfile
*objfile
= per_objfile
->objfile
;
10878 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10879 const gdb_byte
*info_ptr
, *end_ptr
;
10881 section
.read (objfile
);
10882 info_ptr
= section
.buffer
;
10884 if (info_ptr
== NULL
)
10887 dwarf_read_debug_printf ("Reading %s for %s:",
10888 section
.get_name (),
10889 section
.get_file_name ());
10891 end_ptr
= info_ptr
+ section
.size
;
10892 while (info_ptr
< end_ptr
)
10894 struct dwarf2_per_cu_data per_cu
;
10895 struct dwo_unit read_unit
{};
10896 struct dwo_unit
*dwo_unit
;
10898 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10900 per_cu
.per_bfd
= per_bfd
;
10901 per_cu
.is_debug_types
= 0;
10902 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10903 per_cu
.section
= §ion
;
10905 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10906 if (!reader
.dummy_p
)
10907 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10908 &dwo_file
, &read_unit
);
10909 info_ptr
+= per_cu
.length
;
10911 // If the unit could not be parsed, skip it.
10912 if (read_unit
.dwo_file
== NULL
)
10915 if (cus_htab
== NULL
)
10916 cus_htab
= allocate_dwo_unit_table ();
10918 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
10920 *dwo_unit
= read_unit
;
10921 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
10922 gdb_assert (slot
!= NULL
);
10925 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10926 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10928 complaint (_("debug cu entry at offset %s is duplicate to"
10929 " the entry at offset %s, signature %s"),
10930 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
10931 hex_string (dwo_unit
->signature
));
10933 *slot
= (void *)dwo_unit
;
10937 /* DWP file .debug_{cu,tu}_index section format:
10938 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10939 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10941 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10942 officially standard DWP format was published with DWARF v5 and is called
10943 Version 5. There are no versions 3 or 4.
10947 Both index sections have the same format, and serve to map a 64-bit
10948 signature to a set of section numbers. Each section begins with a header,
10949 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10950 indexes, and a pool of 32-bit section numbers. The index sections will be
10951 aligned at 8-byte boundaries in the file.
10953 The index section header consists of:
10955 V, 32 bit version number
10957 N, 32 bit number of compilation units or type units in the index
10958 M, 32 bit number of slots in the hash table
10960 Numbers are recorded using the byte order of the application binary.
10962 The hash table begins at offset 16 in the section, and consists of an array
10963 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10964 order of the application binary). Unused slots in the hash table are 0.
10965 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10967 The parallel table begins immediately after the hash table
10968 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10969 array of 32-bit indexes (using the byte order of the application binary),
10970 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10971 table contains a 32-bit index into the pool of section numbers. For unused
10972 hash table slots, the corresponding entry in the parallel table will be 0.
10974 The pool of section numbers begins immediately following the hash table
10975 (at offset 16 + 12 * M from the beginning of the section). The pool of
10976 section numbers consists of an array of 32-bit words (using the byte order
10977 of the application binary). Each item in the array is indexed starting
10978 from 0. The hash table entry provides the index of the first section
10979 number in the set. Additional section numbers in the set follow, and the
10980 set is terminated by a 0 entry (section number 0 is not used in ELF).
10982 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10983 section must be the first entry in the set, and the .debug_abbrev.dwo must
10984 be the second entry. Other members of the set may follow in any order.
10988 DWP Versions 2 and 5:
10990 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
10991 and the entries in the index tables are now offsets into these sections.
10992 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10995 Index Section Contents:
10997 Hash Table of Signatures dwp_hash_table.hash_table
10998 Parallel Table of Indices dwp_hash_table.unit_table
10999 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11000 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11002 The index section header consists of:
11004 V, 32 bit version number
11005 L, 32 bit number of columns in the table of section offsets
11006 N, 32 bit number of compilation units or type units in the index
11007 M, 32 bit number of slots in the hash table
11009 Numbers are recorded using the byte order of the application binary.
11011 The hash table has the same format as version 1.
11012 The parallel table of indices has the same format as version 1,
11013 except that the entries are origin-1 indices into the table of sections
11014 offsets and the table of section sizes.
11016 The table of offsets begins immediately following the parallel table
11017 (at offset 16 + 12 * M from the beginning of the section). The table is
11018 a two-dimensional array of 32-bit words (using the byte order of the
11019 application binary), with L columns and N+1 rows, in row-major order.
11020 Each row in the array is indexed starting from 0. The first row provides
11021 a key to the remaining rows: each column in this row provides an identifier
11022 for a debug section, and the offsets in the same column of subsequent rows
11023 refer to that section. The section identifiers for Version 2 are:
11025 DW_SECT_INFO 1 .debug_info.dwo
11026 DW_SECT_TYPES 2 .debug_types.dwo
11027 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11028 DW_SECT_LINE 4 .debug_line.dwo
11029 DW_SECT_LOC 5 .debug_loc.dwo
11030 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11031 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11032 DW_SECT_MACRO 8 .debug_macro.dwo
11034 The section identifiers for Version 5 are:
11036 DW_SECT_INFO_V5 1 .debug_info.dwo
11037 DW_SECT_RESERVED_V5 2 --
11038 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11039 DW_SECT_LINE_V5 4 .debug_line.dwo
11040 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11041 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11042 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11043 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11045 The offsets provided by the CU and TU index sections are the base offsets
11046 for the contributions made by each CU or TU to the corresponding section
11047 in the package file. Each CU and TU header contains an abbrev_offset
11048 field, used to find the abbreviations table for that CU or TU within the
11049 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11050 be interpreted as relative to the base offset given in the index section.
11051 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11052 should be interpreted as relative to the base offset for .debug_line.dwo,
11053 and offsets into other debug sections obtained from DWARF attributes should
11054 also be interpreted as relative to the corresponding base offset.
11056 The table of sizes begins immediately following the table of offsets.
11057 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11058 with L columns and N rows, in row-major order. Each row in the array is
11059 indexed starting from 1 (row 0 is shared by the two tables).
11063 Hash table lookup is handled the same in version 1 and 2:
11065 We assume that N and M will not exceed 2^32 - 1.
11066 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11068 Given a 64-bit compilation unit signature or a type signature S, an entry
11069 in the hash table is located as follows:
11071 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11072 the low-order k bits all set to 1.
11074 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11076 3) If the hash table entry at index H matches the signature, use that
11077 entry. If the hash table entry at index H is unused (all zeroes),
11078 terminate the search: the signature is not present in the table.
11080 4) Let H = (H + H') modulo M. Repeat at Step 3.
11082 Because M > N and H' and M are relatively prime, the search is guaranteed
11083 to stop at an unused slot or find the match. */
11085 /* Create a hash table to map DWO IDs to their CU/TU entry in
11086 .debug_{info,types}.dwo in DWP_FILE.
11087 Returns NULL if there isn't one.
11088 Note: This function processes DWP files only, not DWO files. */
11090 static struct dwp_hash_table
*
11091 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11092 struct dwp_file
*dwp_file
, int is_debug_types
)
11094 struct objfile
*objfile
= per_objfile
->objfile
;
11095 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11096 const gdb_byte
*index_ptr
, *index_end
;
11097 struct dwarf2_section_info
*index
;
11098 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11099 struct dwp_hash_table
*htab
;
11101 if (is_debug_types
)
11102 index
= &dwp_file
->sections
.tu_index
;
11104 index
= &dwp_file
->sections
.cu_index
;
11106 if (index
->empty ())
11108 index
->read (objfile
);
11110 index_ptr
= index
->buffer
;
11111 index_end
= index_ptr
+ index
->size
;
11113 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11114 For now it's safe to just read 4 bytes (particularly as it's difficult to
11115 tell if you're dealing with Version 5 before you've read the version). */
11116 version
= read_4_bytes (dbfd
, index_ptr
);
11118 if (version
== 2 || version
== 5)
11119 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11123 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11125 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11128 if (version
!= 1 && version
!= 2 && version
!= 5)
11130 error (_("Dwarf Error: unsupported DWP file version (%s)"
11131 " [in module %s]"),
11132 pulongest (version
), dwp_file
->name
);
11134 if (nr_slots
!= (nr_slots
& -nr_slots
))
11136 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11137 " is not power of 2 [in module %s]"),
11138 pulongest (nr_slots
), dwp_file
->name
);
11141 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11142 htab
->version
= version
;
11143 htab
->nr_columns
= nr_columns
;
11144 htab
->nr_units
= nr_units
;
11145 htab
->nr_slots
= nr_slots
;
11146 htab
->hash_table
= index_ptr
;
11147 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11149 /* Exit early if the table is empty. */
11150 if (nr_slots
== 0 || nr_units
== 0
11151 || (version
== 2 && nr_columns
== 0)
11152 || (version
== 5 && nr_columns
== 0))
11154 /* All must be zero. */
11155 if (nr_slots
!= 0 || nr_units
!= 0
11156 || (version
== 2 && nr_columns
!= 0)
11157 || (version
== 5 && nr_columns
!= 0))
11159 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11160 " all zero [in modules %s]"),
11168 htab
->section_pool
.v1
.indices
=
11169 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11170 /* It's harder to decide whether the section is too small in v1.
11171 V1 is deprecated anyway so we punt. */
11173 else if (version
== 2)
11175 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11176 int *ids
= htab
->section_pool
.v2
.section_ids
;
11177 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11178 /* Reverse map for error checking. */
11179 int ids_seen
[DW_SECT_MAX
+ 1];
11182 if (nr_columns
< 2)
11184 error (_("Dwarf Error: bad DWP hash table, too few columns"
11185 " in section table [in module %s]"),
11188 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11190 error (_("Dwarf Error: bad DWP hash table, too many columns"
11191 " in section table [in module %s]"),
11194 memset (ids
, 255, sizeof_ids
);
11195 memset (ids_seen
, 255, sizeof (ids_seen
));
11196 for (i
= 0; i
< nr_columns
; ++i
)
11198 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11200 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11202 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11203 " in section table [in module %s]"),
11204 id
, dwp_file
->name
);
11206 if (ids_seen
[id
] != -1)
11208 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11209 " id %d in section table [in module %s]"),
11210 id
, dwp_file
->name
);
11215 /* Must have exactly one info or types section. */
11216 if (((ids_seen
[DW_SECT_INFO
] != -1)
11217 + (ids_seen
[DW_SECT_TYPES
] != -1))
11220 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11221 " DWO info/types section [in module %s]"),
11224 /* Must have an abbrev section. */
11225 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11227 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11228 " section [in module %s]"),
11231 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11232 htab
->section_pool
.v2
.sizes
=
11233 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11234 * nr_units
* nr_columns
);
11235 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11236 * nr_units
* nr_columns
))
11239 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11240 " [in module %s]"),
11244 else /* version == 5 */
11246 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11247 int *ids
= htab
->section_pool
.v5
.section_ids
;
11248 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11249 /* Reverse map for error checking. */
11250 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11252 if (nr_columns
< 2)
11254 error (_("Dwarf Error: bad DWP hash table, too few columns"
11255 " in section table [in module %s]"),
11258 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11260 error (_("Dwarf Error: bad DWP hash table, too many columns"
11261 " in section table [in module %s]"),
11264 memset (ids
, 255, sizeof_ids
);
11265 memset (ids_seen
, 255, sizeof (ids_seen
));
11266 for (int i
= 0; i
< nr_columns
; ++i
)
11268 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11270 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11272 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11273 " in section table [in module %s]"),
11274 id
, dwp_file
->name
);
11276 if (ids_seen
[id
] != -1)
11278 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11279 " id %d in section table [in module %s]"),
11280 id
, dwp_file
->name
);
11285 /* Must have seen an info section. */
11286 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11288 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11289 " DWO info/types section [in module %s]"),
11292 /* Must have an abbrev section. */
11293 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11295 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11296 " section [in module %s]"),
11299 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11300 htab
->section_pool
.v5
.sizes
11301 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11302 * nr_units
* nr_columns
);
11303 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11304 * nr_units
* nr_columns
))
11307 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11308 " [in module %s]"),
11316 /* Update SECTIONS with the data from SECTP.
11318 This function is like the other "locate" section routines, but in
11319 this context the sections to read comes from the DWP V1 hash table,
11320 not the full ELF section table.
11322 The result is non-zero for success, or zero if an error was found. */
11325 locate_v1_virtual_dwo_sections (asection
*sectp
,
11326 struct virtual_v1_dwo_sections
*sections
)
11328 const struct dwop_section_names
*names
= &dwop_section_names
;
11330 if (names
->abbrev_dwo
.matches (sectp
->name
))
11332 /* There can be only one. */
11333 if (sections
->abbrev
.s
.section
!= NULL
)
11335 sections
->abbrev
.s
.section
= sectp
;
11336 sections
->abbrev
.size
= bfd_section_size (sectp
);
11338 else if (names
->info_dwo
.matches (sectp
->name
)
11339 || names
->types_dwo
.matches (sectp
->name
))
11341 /* There can be only one. */
11342 if (sections
->info_or_types
.s
.section
!= NULL
)
11344 sections
->info_or_types
.s
.section
= sectp
;
11345 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11347 else if (names
->line_dwo
.matches (sectp
->name
))
11349 /* There can be only one. */
11350 if (sections
->line
.s
.section
!= NULL
)
11352 sections
->line
.s
.section
= sectp
;
11353 sections
->line
.size
= bfd_section_size (sectp
);
11355 else if (names
->loc_dwo
.matches (sectp
->name
))
11357 /* There can be only one. */
11358 if (sections
->loc
.s
.section
!= NULL
)
11360 sections
->loc
.s
.section
= sectp
;
11361 sections
->loc
.size
= bfd_section_size (sectp
);
11363 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11365 /* There can be only one. */
11366 if (sections
->macinfo
.s
.section
!= NULL
)
11368 sections
->macinfo
.s
.section
= sectp
;
11369 sections
->macinfo
.size
= bfd_section_size (sectp
);
11371 else if (names
->macro_dwo
.matches (sectp
->name
))
11373 /* There can be only one. */
11374 if (sections
->macro
.s
.section
!= NULL
)
11376 sections
->macro
.s
.section
= sectp
;
11377 sections
->macro
.size
= bfd_section_size (sectp
);
11379 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11381 /* There can be only one. */
11382 if (sections
->str_offsets
.s
.section
!= NULL
)
11384 sections
->str_offsets
.s
.section
= sectp
;
11385 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11389 /* No other kind of section is valid. */
11396 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11397 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11398 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11399 This is for DWP version 1 files. */
11401 static struct dwo_unit
*
11402 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11403 struct dwp_file
*dwp_file
,
11404 uint32_t unit_index
,
11405 const char *comp_dir
,
11406 ULONGEST signature
, int is_debug_types
)
11408 const struct dwp_hash_table
*dwp_htab
=
11409 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11410 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11411 const char *kind
= is_debug_types
? "TU" : "CU";
11412 struct dwo_file
*dwo_file
;
11413 struct dwo_unit
*dwo_unit
;
11414 struct virtual_v1_dwo_sections sections
;
11415 void **dwo_file_slot
;
11418 gdb_assert (dwp_file
->version
== 1);
11420 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11421 kind
, pulongest (unit_index
), hex_string (signature
),
11424 /* Fetch the sections of this DWO unit.
11425 Put a limit on the number of sections we look for so that bad data
11426 doesn't cause us to loop forever. */
11428 #define MAX_NR_V1_DWO_SECTIONS \
11429 (1 /* .debug_info or .debug_types */ \
11430 + 1 /* .debug_abbrev */ \
11431 + 1 /* .debug_line */ \
11432 + 1 /* .debug_loc */ \
11433 + 1 /* .debug_str_offsets */ \
11434 + 1 /* .debug_macro or .debug_macinfo */ \
11435 + 1 /* trailing zero */)
11437 memset (§ions
, 0, sizeof (sections
));
11439 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11442 uint32_t section_nr
=
11443 read_4_bytes (dbfd
,
11444 dwp_htab
->section_pool
.v1
.indices
11445 + (unit_index
+ i
) * sizeof (uint32_t));
11447 if (section_nr
== 0)
11449 if (section_nr
>= dwp_file
->num_sections
)
11451 error (_("Dwarf Error: bad DWP hash table, section number too large"
11452 " [in module %s]"),
11456 sectp
= dwp_file
->elf_sections
[section_nr
];
11457 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11459 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11460 " [in module %s]"),
11466 || sections
.info_or_types
.empty ()
11467 || sections
.abbrev
.empty ())
11469 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11470 " [in module %s]"),
11473 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11475 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11476 " [in module %s]"),
11480 /* It's easier for the rest of the code if we fake a struct dwo_file and
11481 have dwo_unit "live" in that. At least for now.
11483 The DWP file can be made up of a random collection of CUs and TUs.
11484 However, for each CU + set of TUs that came from the same original DWO
11485 file, we can combine them back into a virtual DWO file to save space
11486 (fewer struct dwo_file objects to allocate). Remember that for really
11487 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11489 std::string virtual_dwo_name
=
11490 string_printf ("virtual-dwo/%d-%d-%d-%d",
11491 sections
.abbrev
.get_id (),
11492 sections
.line
.get_id (),
11493 sections
.loc
.get_id (),
11494 sections
.str_offsets
.get_id ());
11495 /* Can we use an existing virtual DWO file? */
11496 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11498 /* Create one if necessary. */
11499 if (*dwo_file_slot
== NULL
)
11501 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11502 virtual_dwo_name
.c_str ());
11504 dwo_file
= new struct dwo_file
;
11505 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11506 dwo_file
->comp_dir
= comp_dir
;
11507 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11508 dwo_file
->sections
.line
= sections
.line
;
11509 dwo_file
->sections
.loc
= sections
.loc
;
11510 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11511 dwo_file
->sections
.macro
= sections
.macro
;
11512 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11513 /* The "str" section is global to the entire DWP file. */
11514 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11515 /* The info or types section is assigned below to dwo_unit,
11516 there's no need to record it in dwo_file.
11517 Also, we can't simply record type sections in dwo_file because
11518 we record a pointer into the vector in dwo_unit. As we collect more
11519 types we'll grow the vector and eventually have to reallocate space
11520 for it, invalidating all copies of pointers into the previous
11522 *dwo_file_slot
= dwo_file
;
11526 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11527 virtual_dwo_name
.c_str ());
11529 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11532 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11533 dwo_unit
->dwo_file
= dwo_file
;
11534 dwo_unit
->signature
= signature
;
11535 dwo_unit
->section
=
11536 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11537 *dwo_unit
->section
= sections
.info_or_types
;
11538 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11543 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11544 simplify them. Given a pointer to the containing section SECTION, and
11545 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11546 virtual section of just that piece. */
11548 static struct dwarf2_section_info
11549 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11550 struct dwarf2_section_info
*section
,
11551 bfd_size_type offset
, bfd_size_type size
)
11553 struct dwarf2_section_info result
;
11556 gdb_assert (section
!= NULL
);
11557 gdb_assert (!section
->is_virtual
);
11559 memset (&result
, 0, sizeof (result
));
11560 result
.s
.containing_section
= section
;
11561 result
.is_virtual
= true;
11566 sectp
= section
->get_bfd_section ();
11568 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11569 bounds of the real section. This is a pretty-rare event, so just
11570 flag an error (easier) instead of a warning and trying to cope. */
11572 || offset
+ size
> bfd_section_size (sectp
))
11574 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11575 " in section %s [in module %s]"),
11576 sectp
? bfd_section_name (sectp
) : "<unknown>",
11577 objfile_name (per_objfile
->objfile
));
11580 result
.virtual_offset
= offset
;
11581 result
.size
= size
;
11585 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11586 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11587 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11588 This is for DWP version 2 files. */
11590 static struct dwo_unit
*
11591 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11592 struct dwp_file
*dwp_file
,
11593 uint32_t unit_index
,
11594 const char *comp_dir
,
11595 ULONGEST signature
, int is_debug_types
)
11597 const struct dwp_hash_table
*dwp_htab
=
11598 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11599 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11600 const char *kind
= is_debug_types
? "TU" : "CU";
11601 struct dwo_file
*dwo_file
;
11602 struct dwo_unit
*dwo_unit
;
11603 struct virtual_v2_or_v5_dwo_sections sections
;
11604 void **dwo_file_slot
;
11607 gdb_assert (dwp_file
->version
== 2);
11609 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11610 kind
, pulongest (unit_index
), hex_string (signature
),
11613 /* Fetch the section offsets of this DWO unit. */
11615 memset (§ions
, 0, sizeof (sections
));
11617 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11619 uint32_t offset
= read_4_bytes (dbfd
,
11620 dwp_htab
->section_pool
.v2
.offsets
11621 + (((unit_index
- 1) * dwp_htab
->nr_columns
11623 * sizeof (uint32_t)));
11624 uint32_t size
= read_4_bytes (dbfd
,
11625 dwp_htab
->section_pool
.v2
.sizes
11626 + (((unit_index
- 1) * dwp_htab
->nr_columns
11628 * sizeof (uint32_t)));
11630 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11633 case DW_SECT_TYPES
:
11634 sections
.info_or_types_offset
= offset
;
11635 sections
.info_or_types_size
= size
;
11637 case DW_SECT_ABBREV
:
11638 sections
.abbrev_offset
= offset
;
11639 sections
.abbrev_size
= size
;
11642 sections
.line_offset
= offset
;
11643 sections
.line_size
= size
;
11646 sections
.loc_offset
= offset
;
11647 sections
.loc_size
= size
;
11649 case DW_SECT_STR_OFFSETS
:
11650 sections
.str_offsets_offset
= offset
;
11651 sections
.str_offsets_size
= size
;
11653 case DW_SECT_MACINFO
:
11654 sections
.macinfo_offset
= offset
;
11655 sections
.macinfo_size
= size
;
11657 case DW_SECT_MACRO
:
11658 sections
.macro_offset
= offset
;
11659 sections
.macro_size
= size
;
11664 /* It's easier for the rest of the code if we fake a struct dwo_file and
11665 have dwo_unit "live" in that. At least for now.
11667 The DWP file can be made up of a random collection of CUs and TUs.
11668 However, for each CU + set of TUs that came from the same original DWO
11669 file, we can combine them back into a virtual DWO file to save space
11670 (fewer struct dwo_file objects to allocate). Remember that for really
11671 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11673 std::string virtual_dwo_name
=
11674 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11675 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11676 (long) (sections
.line_size
? sections
.line_offset
: 0),
11677 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11678 (long) (sections
.str_offsets_size
11679 ? sections
.str_offsets_offset
: 0));
11680 /* Can we use an existing virtual DWO file? */
11681 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11683 /* Create one if necessary. */
11684 if (*dwo_file_slot
== NULL
)
11686 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11687 virtual_dwo_name
.c_str ());
11689 dwo_file
= new struct dwo_file
;
11690 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11691 dwo_file
->comp_dir
= comp_dir
;
11692 dwo_file
->sections
.abbrev
=
11693 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11694 sections
.abbrev_offset
,
11695 sections
.abbrev_size
);
11696 dwo_file
->sections
.line
=
11697 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11698 sections
.line_offset
,
11699 sections
.line_size
);
11700 dwo_file
->sections
.loc
=
11701 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11702 sections
.loc_offset
, sections
.loc_size
);
11703 dwo_file
->sections
.macinfo
=
11704 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11705 sections
.macinfo_offset
,
11706 sections
.macinfo_size
);
11707 dwo_file
->sections
.macro
=
11708 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11709 sections
.macro_offset
,
11710 sections
.macro_size
);
11711 dwo_file
->sections
.str_offsets
=
11712 create_dwp_v2_or_v5_section (per_objfile
,
11713 &dwp_file
->sections
.str_offsets
,
11714 sections
.str_offsets_offset
,
11715 sections
.str_offsets_size
);
11716 /* The "str" section is global to the entire DWP file. */
11717 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11718 /* The info or types section is assigned below to dwo_unit,
11719 there's no need to record it in dwo_file.
11720 Also, we can't simply record type sections in dwo_file because
11721 we record a pointer into the vector in dwo_unit. As we collect more
11722 types we'll grow the vector and eventually have to reallocate space
11723 for it, invalidating all copies of pointers into the previous
11725 *dwo_file_slot
= dwo_file
;
11729 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11730 virtual_dwo_name
.c_str ());
11732 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11735 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11736 dwo_unit
->dwo_file
= dwo_file
;
11737 dwo_unit
->signature
= signature
;
11738 dwo_unit
->section
=
11739 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11740 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11743 ? &dwp_file
->sections
.types
11744 : &dwp_file
->sections
.info
,
11745 sections
.info_or_types_offset
,
11746 sections
.info_or_types_size
);
11747 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11752 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11753 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11754 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11755 This is for DWP version 5 files. */
11757 static struct dwo_unit
*
11758 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11759 struct dwp_file
*dwp_file
,
11760 uint32_t unit_index
,
11761 const char *comp_dir
,
11762 ULONGEST signature
, int is_debug_types
)
11764 const struct dwp_hash_table
*dwp_htab
11765 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11766 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11767 const char *kind
= is_debug_types
? "TU" : "CU";
11768 struct dwo_file
*dwo_file
;
11769 struct dwo_unit
*dwo_unit
;
11770 struct virtual_v2_or_v5_dwo_sections sections
{};
11771 void **dwo_file_slot
;
11773 gdb_assert (dwp_file
->version
== 5);
11775 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11776 kind
, pulongest (unit_index
), hex_string (signature
),
11779 /* Fetch the section offsets of this DWO unit. */
11781 /* memset (§ions, 0, sizeof (sections)); */
11783 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11785 uint32_t offset
= read_4_bytes (dbfd
,
11786 dwp_htab
->section_pool
.v5
.offsets
11787 + (((unit_index
- 1)
11788 * dwp_htab
->nr_columns
11790 * sizeof (uint32_t)));
11791 uint32_t size
= read_4_bytes (dbfd
,
11792 dwp_htab
->section_pool
.v5
.sizes
11793 + (((unit_index
- 1) * dwp_htab
->nr_columns
11795 * sizeof (uint32_t)));
11797 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11799 case DW_SECT_ABBREV_V5
:
11800 sections
.abbrev_offset
= offset
;
11801 sections
.abbrev_size
= size
;
11803 case DW_SECT_INFO_V5
:
11804 sections
.info_or_types_offset
= offset
;
11805 sections
.info_or_types_size
= size
;
11807 case DW_SECT_LINE_V5
:
11808 sections
.line_offset
= offset
;
11809 sections
.line_size
= size
;
11811 case DW_SECT_LOCLISTS_V5
:
11812 sections
.loclists_offset
= offset
;
11813 sections
.loclists_size
= size
;
11815 case DW_SECT_MACRO_V5
:
11816 sections
.macro_offset
= offset
;
11817 sections
.macro_size
= size
;
11819 case DW_SECT_RNGLISTS_V5
:
11820 sections
.rnglists_offset
= offset
;
11821 sections
.rnglists_size
= size
;
11823 case DW_SECT_STR_OFFSETS_V5
:
11824 sections
.str_offsets_offset
= offset
;
11825 sections
.str_offsets_size
= size
;
11827 case DW_SECT_RESERVED_V5
:
11833 /* It's easier for the rest of the code if we fake a struct dwo_file and
11834 have dwo_unit "live" in that. At least for now.
11836 The DWP file can be made up of a random collection of CUs and TUs.
11837 However, for each CU + set of TUs that came from the same original DWO
11838 file, we can combine them back into a virtual DWO file to save space
11839 (fewer struct dwo_file objects to allocate). Remember that for really
11840 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11842 std::string virtual_dwo_name
=
11843 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11844 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11845 (long) (sections
.line_size
? sections
.line_offset
: 0),
11846 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11847 (long) (sections
.str_offsets_size
11848 ? sections
.str_offsets_offset
: 0),
11849 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11850 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11851 /* Can we use an existing virtual DWO file? */
11852 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11853 virtual_dwo_name
.c_str (),
11855 /* Create one if necessary. */
11856 if (*dwo_file_slot
== NULL
)
11858 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11859 virtual_dwo_name
.c_str ());
11861 dwo_file
= new struct dwo_file
;
11862 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11863 dwo_file
->comp_dir
= comp_dir
;
11864 dwo_file
->sections
.abbrev
=
11865 create_dwp_v2_or_v5_section (per_objfile
,
11866 &dwp_file
->sections
.abbrev
,
11867 sections
.abbrev_offset
,
11868 sections
.abbrev_size
);
11869 dwo_file
->sections
.line
=
11870 create_dwp_v2_or_v5_section (per_objfile
,
11871 &dwp_file
->sections
.line
,
11872 sections
.line_offset
, sections
.line_size
);
11873 dwo_file
->sections
.macro
=
11874 create_dwp_v2_or_v5_section (per_objfile
,
11875 &dwp_file
->sections
.macro
,
11876 sections
.macro_offset
,
11877 sections
.macro_size
);
11878 dwo_file
->sections
.loclists
=
11879 create_dwp_v2_or_v5_section (per_objfile
,
11880 &dwp_file
->sections
.loclists
,
11881 sections
.loclists_offset
,
11882 sections
.loclists_size
);
11883 dwo_file
->sections
.rnglists
=
11884 create_dwp_v2_or_v5_section (per_objfile
,
11885 &dwp_file
->sections
.rnglists
,
11886 sections
.rnglists_offset
,
11887 sections
.rnglists_size
);
11888 dwo_file
->sections
.str_offsets
=
11889 create_dwp_v2_or_v5_section (per_objfile
,
11890 &dwp_file
->sections
.str_offsets
,
11891 sections
.str_offsets_offset
,
11892 sections
.str_offsets_size
);
11893 /* The "str" section is global to the entire DWP file. */
11894 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11895 /* The info or types section is assigned below to dwo_unit,
11896 there's no need to record it in dwo_file.
11897 Also, we can't simply record type sections in dwo_file because
11898 we record a pointer into the vector in dwo_unit. As we collect more
11899 types we'll grow the vector and eventually have to reallocate space
11900 for it, invalidating all copies of pointers into the previous
11902 *dwo_file_slot
= dwo_file
;
11906 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11907 virtual_dwo_name
.c_str ());
11909 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11912 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11913 dwo_unit
->dwo_file
= dwo_file
;
11914 dwo_unit
->signature
= signature
;
11916 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11917 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
11918 &dwp_file
->sections
.info
,
11919 sections
.info_or_types_offset
,
11920 sections
.info_or_types_size
);
11921 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11926 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11927 Returns NULL if the signature isn't found. */
11929 static struct dwo_unit
*
11930 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
11931 struct dwp_file
*dwp_file
, const char *comp_dir
,
11932 ULONGEST signature
, int is_debug_types
)
11934 const struct dwp_hash_table
*dwp_htab
=
11935 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11936 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11937 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11938 uint32_t hash
= signature
& mask
;
11939 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11942 struct dwo_unit find_dwo_cu
;
11944 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11945 find_dwo_cu
.signature
= signature
;
11946 slot
= htab_find_slot (is_debug_types
11947 ? dwp_file
->loaded_tus
.get ()
11948 : dwp_file
->loaded_cus
.get (),
11949 &find_dwo_cu
, INSERT
);
11952 return (struct dwo_unit
*) *slot
;
11954 /* Use a for loop so that we don't loop forever on bad debug info. */
11955 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11957 ULONGEST signature_in_table
;
11959 signature_in_table
=
11960 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11961 if (signature_in_table
== signature
)
11963 uint32_t unit_index
=
11964 read_4_bytes (dbfd
,
11965 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11967 if (dwp_file
->version
== 1)
11969 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
11970 unit_index
, comp_dir
,
11971 signature
, is_debug_types
);
11973 else if (dwp_file
->version
== 2)
11975 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
11976 unit_index
, comp_dir
,
11977 signature
, is_debug_types
);
11979 else /* version == 5 */
11981 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
11982 unit_index
, comp_dir
,
11983 signature
, is_debug_types
);
11985 return (struct dwo_unit
*) *slot
;
11987 if (signature_in_table
== 0)
11989 hash
= (hash
+ hash2
) & mask
;
11992 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11993 " [in module %s]"),
11997 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11998 Open the file specified by FILE_NAME and hand it off to BFD for
11999 preliminary analysis. Return a newly initialized bfd *, which
12000 includes a canonicalized copy of FILE_NAME.
12001 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12002 SEARCH_CWD is true if the current directory is to be searched.
12003 It will be searched before debug-file-directory.
12004 If successful, the file is added to the bfd include table of the
12005 objfile's bfd (see gdb_bfd_record_inclusion).
12006 If unable to find/open the file, return NULL.
12007 NOTE: This function is derived from symfile_bfd_open. */
12009 static gdb_bfd_ref_ptr
12010 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12011 const char *file_name
, int is_dwp
, int search_cwd
)
12014 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12015 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12016 to debug_file_directory. */
12017 const char *search_path
;
12018 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12020 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12023 if (*debug_file_directory
!= '\0')
12025 search_path_holder
.reset (concat (".", dirname_separator_string
,
12026 debug_file_directory
,
12028 search_path
= search_path_holder
.get ();
12034 search_path
= debug_file_directory
;
12036 /* Add the path for the executable binary to the list of search paths. */
12037 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12038 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12039 dirname_separator_string
,
12040 search_path
, nullptr));
12041 search_path
= search_path_holder
.get ();
12043 openp_flags flags
= OPF_RETURN_REALPATH
;
12045 flags
|= OPF_SEARCH_IN_PATH
;
12047 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12048 desc
= openp (search_path
, flags
, file_name
,
12049 O_RDONLY
| O_BINARY
, &absolute_name
);
12053 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12055 if (sym_bfd
== NULL
)
12057 bfd_set_cacheable (sym_bfd
.get (), 1);
12059 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12062 /* Success. Record the bfd as having been included by the objfile's bfd.
12063 This is important because things like demangled_names_hash lives in the
12064 objfile's per_bfd space and may have references to things like symbol
12065 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12066 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12071 /* Try to open DWO file FILE_NAME.
12072 COMP_DIR is the DW_AT_comp_dir attribute.
12073 The result is the bfd handle of the file.
12074 If there is a problem finding or opening the file, return NULL.
12075 Upon success, the canonicalized path of the file is stored in the bfd,
12076 same as symfile_bfd_open. */
12078 static gdb_bfd_ref_ptr
12079 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12080 const char *file_name
, const char *comp_dir
)
12082 if (IS_ABSOLUTE_PATH (file_name
))
12083 return try_open_dwop_file (per_objfile
, file_name
,
12084 0 /*is_dwp*/, 0 /*search_cwd*/);
12086 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12088 if (comp_dir
!= NULL
)
12090 gdb::unique_xmalloc_ptr
<char> path_to_try
12091 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12093 /* NOTE: If comp_dir is a relative path, this will also try the
12094 search path, which seems useful. */
12095 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12097 1 /*search_cwd*/));
12102 /* That didn't work, try debug-file-directory, which, despite its name,
12103 is a list of paths. */
12105 if (*debug_file_directory
== '\0')
12108 return try_open_dwop_file (per_objfile
, file_name
,
12109 0 /*is_dwp*/, 1 /*search_cwd*/);
12112 /* This function is mapped across the sections and remembers the offset and
12113 size of each of the DWO debugging sections we are interested in. */
12116 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12117 dwo_sections
*dwo_sections
)
12119 const struct dwop_section_names
*names
= &dwop_section_names
;
12121 if (names
->abbrev_dwo
.matches (sectp
->name
))
12123 dwo_sections
->abbrev
.s
.section
= sectp
;
12124 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12126 else if (names
->info_dwo
.matches (sectp
->name
))
12128 dwo_sections
->info
.s
.section
= sectp
;
12129 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12131 else if (names
->line_dwo
.matches (sectp
->name
))
12133 dwo_sections
->line
.s
.section
= sectp
;
12134 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12136 else if (names
->loc_dwo
.matches (sectp
->name
))
12138 dwo_sections
->loc
.s
.section
= sectp
;
12139 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12141 else if (names
->loclists_dwo
.matches (sectp
->name
))
12143 dwo_sections
->loclists
.s
.section
= sectp
;
12144 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12146 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12148 dwo_sections
->macinfo
.s
.section
= sectp
;
12149 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12151 else if (names
->macro_dwo
.matches (sectp
->name
))
12153 dwo_sections
->macro
.s
.section
= sectp
;
12154 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12156 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12158 dwo_sections
->rnglists
.s
.section
= sectp
;
12159 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12161 else if (names
->str_dwo
.matches (sectp
->name
))
12163 dwo_sections
->str
.s
.section
= sectp
;
12164 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12166 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12168 dwo_sections
->str_offsets
.s
.section
= sectp
;
12169 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12171 else if (names
->types_dwo
.matches (sectp
->name
))
12173 struct dwarf2_section_info type_section
;
12175 memset (&type_section
, 0, sizeof (type_section
));
12176 type_section
.s
.section
= sectp
;
12177 type_section
.size
= bfd_section_size (sectp
);
12178 dwo_sections
->types
.push_back (type_section
);
12182 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12183 by PER_CU. This is for the non-DWP case.
12184 The result is NULL if DWO_NAME can't be found. */
12186 static struct dwo_file
*
12187 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12188 const char *comp_dir
)
12190 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12192 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12195 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12200 dwo_file_up
dwo_file (new struct dwo_file
);
12201 dwo_file
->dwo_name
= dwo_name
;
12202 dwo_file
->comp_dir
= comp_dir
;
12203 dwo_file
->dbfd
= std::move (dbfd
);
12205 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12206 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12207 &dwo_file
->sections
);
12209 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12212 if (cu
->per_cu
->dwarf_version
< 5)
12214 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12215 dwo_file
->sections
.types
, dwo_file
->tus
);
12219 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12220 &dwo_file
->sections
.info
, dwo_file
->tus
,
12221 rcuh_kind::COMPILE
);
12224 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12226 return dwo_file
.release ();
12229 /* This function is mapped across the sections and remembers the offset and
12230 size of each of the DWP debugging sections common to version 1 and 2 that
12231 we are interested in. */
12234 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12235 dwp_file
*dwp_file
)
12237 const struct dwop_section_names
*names
= &dwop_section_names
;
12238 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12240 /* Record the ELF section number for later lookup: this is what the
12241 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12242 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12243 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12245 /* Look for specific sections that we need. */
12246 if (names
->str_dwo
.matches (sectp
->name
))
12248 dwp_file
->sections
.str
.s
.section
= sectp
;
12249 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12251 else if (names
->cu_index
.matches (sectp
->name
))
12253 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12254 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12256 else if (names
->tu_index
.matches (sectp
->name
))
12258 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12259 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12263 /* This function is mapped across the sections and remembers the offset and
12264 size of each of the DWP version 2 debugging sections that we are interested
12265 in. This is split into a separate function because we don't know if we
12266 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12269 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12271 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12272 const struct dwop_section_names
*names
= &dwop_section_names
;
12273 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12275 /* Record the ELF section number for later lookup: this is what the
12276 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12277 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12278 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12280 /* Look for specific sections that we need. */
12281 if (names
->abbrev_dwo
.matches (sectp
->name
))
12283 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12284 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12286 else if (names
->info_dwo
.matches (sectp
->name
))
12288 dwp_file
->sections
.info
.s
.section
= sectp
;
12289 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12291 else if (names
->line_dwo
.matches (sectp
->name
))
12293 dwp_file
->sections
.line
.s
.section
= sectp
;
12294 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12296 else if (names
->loc_dwo
.matches (sectp
->name
))
12298 dwp_file
->sections
.loc
.s
.section
= sectp
;
12299 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12301 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12303 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12304 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12306 else if (names
->macro_dwo
.matches (sectp
->name
))
12308 dwp_file
->sections
.macro
.s
.section
= sectp
;
12309 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12311 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12313 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12314 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12316 else if (names
->types_dwo
.matches (sectp
->name
))
12318 dwp_file
->sections
.types
.s
.section
= sectp
;
12319 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12323 /* This function is mapped across the sections and remembers the offset and
12324 size of each of the DWP version 5 debugging sections that we are interested
12325 in. This is split into a separate function because we don't know if we
12326 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12329 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12331 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12332 const struct dwop_section_names
*names
= &dwop_section_names
;
12333 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12335 /* Record the ELF section number for later lookup: this is what the
12336 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12337 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12338 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12340 /* Look for specific sections that we need. */
12341 if (names
->abbrev_dwo
.matches (sectp
->name
))
12343 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12344 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12346 else if (names
->info_dwo
.matches (sectp
->name
))
12348 dwp_file
->sections
.info
.s
.section
= sectp
;
12349 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12351 else if (names
->line_dwo
.matches (sectp
->name
))
12353 dwp_file
->sections
.line
.s
.section
= sectp
;
12354 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12356 else if (names
->loclists_dwo
.matches (sectp
->name
))
12358 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12359 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12361 else if (names
->macro_dwo
.matches (sectp
->name
))
12363 dwp_file
->sections
.macro
.s
.section
= sectp
;
12364 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12366 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12368 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12369 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12371 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12373 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12374 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12378 /* Hash function for dwp_file loaded CUs/TUs. */
12381 hash_dwp_loaded_cutus (const void *item
)
12383 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12385 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12386 return dwo_unit
->signature
;
12389 /* Equality function for dwp_file loaded CUs/TUs. */
12392 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12394 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12395 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12397 return dua
->signature
== dub
->signature
;
12400 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12403 allocate_dwp_loaded_cutus_table ()
12405 return htab_up (htab_create_alloc (3,
12406 hash_dwp_loaded_cutus
,
12407 eq_dwp_loaded_cutus
,
12408 NULL
, xcalloc
, xfree
));
12411 /* Try to open DWP file FILE_NAME.
12412 The result is the bfd handle of the file.
12413 If there is a problem finding or opening the file, return NULL.
12414 Upon success, the canonicalized path of the file is stored in the bfd,
12415 same as symfile_bfd_open. */
12417 static gdb_bfd_ref_ptr
12418 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12420 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12422 1 /*search_cwd*/));
12426 /* Work around upstream bug 15652.
12427 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12428 [Whether that's a "bug" is debatable, but it is getting in our way.]
12429 We have no real idea where the dwp file is, because gdb's realpath-ing
12430 of the executable's path may have discarded the needed info.
12431 [IWBN if the dwp file name was recorded in the executable, akin to
12432 .gnu_debuglink, but that doesn't exist yet.]
12433 Strip the directory from FILE_NAME and search again. */
12434 if (*debug_file_directory
!= '\0')
12436 /* Don't implicitly search the current directory here.
12437 If the user wants to search "." to handle this case,
12438 it must be added to debug-file-directory. */
12439 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12447 /* Initialize the use of the DWP file for the current objfile.
12448 By convention the name of the DWP file is ${objfile}.dwp.
12449 The result is NULL if it can't be found. */
12451 static std::unique_ptr
<struct dwp_file
>
12452 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12454 struct objfile
*objfile
= per_objfile
->objfile
;
12456 /* Try to find first .dwp for the binary file before any symbolic links
12459 /* If the objfile is a debug file, find the name of the real binary
12460 file and get the name of dwp file from there. */
12461 std::string dwp_name
;
12462 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12464 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12465 const char *backlink_basename
= lbasename (backlink
->original_name
);
12467 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12470 dwp_name
= objfile
->original_name
;
12472 dwp_name
+= ".dwp";
12474 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12476 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12478 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12479 dwp_name
= objfile_name (objfile
);
12480 dwp_name
+= ".dwp";
12481 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12486 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12488 return std::unique_ptr
<dwp_file
> ();
12491 const char *name
= bfd_get_filename (dbfd
.get ());
12492 std::unique_ptr
<struct dwp_file
> dwp_file
12493 (new struct dwp_file (name
, std::move (dbfd
)));
12495 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12496 dwp_file
->elf_sections
=
12497 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12498 dwp_file
->num_sections
, asection
*);
12500 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12501 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12504 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12506 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12508 /* The DWP file version is stored in the hash table. Oh well. */
12509 if (dwp_file
->cus
&& dwp_file
->tus
12510 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12512 /* Technically speaking, we should try to limp along, but this is
12513 pretty bizarre. We use pulongest here because that's the established
12514 portability solution (e.g, we cannot use %u for uint32_t). */
12515 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12516 " TU version %s [in DWP file %s]"),
12517 pulongest (dwp_file
->cus
->version
),
12518 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12522 dwp_file
->version
= dwp_file
->cus
->version
;
12523 else if (dwp_file
->tus
)
12524 dwp_file
->version
= dwp_file
->tus
->version
;
12526 dwp_file
->version
= 2;
12528 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12530 if (dwp_file
->version
== 2)
12531 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12534 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12538 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12539 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12541 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12542 dwarf_read_debug_printf (" %s CUs, %s TUs",
12543 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12544 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12549 /* Wrapper around open_and_init_dwp_file, only open it once. */
12551 static struct dwp_file
*
12552 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12554 if (!per_objfile
->per_bfd
->dwp_checked
)
12556 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12557 per_objfile
->per_bfd
->dwp_checked
= 1;
12559 return per_objfile
->per_bfd
->dwp_file
.get ();
12562 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12563 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12564 or in the DWP file for the objfile, referenced by THIS_UNIT.
12565 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12566 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12568 This is called, for example, when wanting to read a variable with a
12569 complex location. Therefore we don't want to do file i/o for every call.
12570 Therefore we don't want to look for a DWO file on every call.
12571 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12572 then we check if we've already seen DWO_NAME, and only THEN do we check
12575 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12576 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12578 static struct dwo_unit
*
12579 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12580 ULONGEST signature
, int is_debug_types
)
12582 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12583 struct objfile
*objfile
= per_objfile
->objfile
;
12584 const char *kind
= is_debug_types
? "TU" : "CU";
12585 void **dwo_file_slot
;
12586 struct dwo_file
*dwo_file
;
12587 struct dwp_file
*dwp_file
;
12589 /* First see if there's a DWP file.
12590 If we have a DWP file but didn't find the DWO inside it, don't
12591 look for the original DWO file. It makes gdb behave differently
12592 depending on whether one is debugging in the build tree. */
12594 dwp_file
= get_dwp_file (per_objfile
);
12595 if (dwp_file
!= NULL
)
12597 const struct dwp_hash_table
*dwp_htab
=
12598 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12600 if (dwp_htab
!= NULL
)
12602 struct dwo_unit
*dwo_cutu
=
12603 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12606 if (dwo_cutu
!= NULL
)
12608 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12609 kind
, hex_string (signature
),
12610 host_address_to_string (dwo_cutu
));
12618 /* No DWP file, look for the DWO file. */
12620 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12621 if (*dwo_file_slot
== NULL
)
12623 /* Read in the file and build a table of the CUs/TUs it contains. */
12624 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12626 /* NOTE: This will be NULL if unable to open the file. */
12627 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12629 if (dwo_file
!= NULL
)
12631 struct dwo_unit
*dwo_cutu
= NULL
;
12633 if (is_debug_types
&& dwo_file
->tus
)
12635 struct dwo_unit find_dwo_cutu
;
12637 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12638 find_dwo_cutu
.signature
= signature
;
12640 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12643 else if (!is_debug_types
&& dwo_file
->cus
)
12645 struct dwo_unit find_dwo_cutu
;
12647 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12648 find_dwo_cutu
.signature
= signature
;
12649 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12653 if (dwo_cutu
!= NULL
)
12655 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12656 kind
, dwo_name
, hex_string (signature
),
12657 host_address_to_string (dwo_cutu
));
12664 /* We didn't find it. This could mean a dwo_id mismatch, or
12665 someone deleted the DWO/DWP file, or the search path isn't set up
12666 correctly to find the file. */
12668 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12669 kind
, dwo_name
, hex_string (signature
));
12671 /* This is a warning and not a complaint because it can be caused by
12672 pilot error (e.g., user accidentally deleting the DWO). */
12674 /* Print the name of the DWP file if we looked there, helps the user
12675 better diagnose the problem. */
12676 std::string dwp_text
;
12678 if (dwp_file
!= NULL
)
12679 dwp_text
= string_printf (" [in DWP file %s]",
12680 lbasename (dwp_file
->name
));
12682 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12683 " [in module %s]"),
12684 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12685 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12690 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12691 See lookup_dwo_cutu_unit for details. */
12693 static struct dwo_unit
*
12694 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12695 ULONGEST signature
)
12697 gdb_assert (!cu
->per_cu
->is_debug_types
);
12699 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12702 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12703 See lookup_dwo_cutu_unit for details. */
12705 static struct dwo_unit
*
12706 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12708 gdb_assert (cu
->per_cu
->is_debug_types
);
12710 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12712 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12715 /* Traversal function for queue_and_load_all_dwo_tus. */
12718 queue_and_load_dwo_tu (void **slot
, void *info
)
12720 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12721 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12722 ULONGEST signature
= dwo_unit
->signature
;
12723 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12725 if (sig_type
!= NULL
)
12727 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12728 a real dependency of PER_CU on SIG_TYPE. That is detected later
12729 while processing PER_CU. */
12730 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12732 load_full_type_unit (sig_type
, cu
->per_objfile
);
12733 cu
->per_cu
->imported_symtabs_push (sig_type
);
12739 /* Queue all TUs contained in the DWO of CU to be read in.
12740 The DWO may have the only definition of the type, though it may not be
12741 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12742 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12745 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12747 struct dwo_unit
*dwo_unit
;
12748 struct dwo_file
*dwo_file
;
12750 gdb_assert (cu
!= nullptr);
12751 gdb_assert (!cu
->per_cu
->is_debug_types
);
12752 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12754 dwo_unit
= cu
->dwo_unit
;
12755 gdb_assert (dwo_unit
!= NULL
);
12757 dwo_file
= dwo_unit
->dwo_file
;
12758 if (dwo_file
->tus
!= NULL
)
12759 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12762 /* Read in various DIEs. */
12764 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12765 Inherit only the children of the DW_AT_abstract_origin DIE not being
12766 already referenced by DW_AT_abstract_origin from the children of the
12770 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12772 struct die_info
*child_die
;
12773 sect_offset
*offsetp
;
12774 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12775 struct die_info
*origin_die
;
12776 /* Iterator of the ORIGIN_DIE children. */
12777 struct die_info
*origin_child_die
;
12778 struct attribute
*attr
;
12779 struct dwarf2_cu
*origin_cu
;
12780 struct pending
**origin_previous_list_in_scope
;
12782 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12786 /* Note that following die references may follow to a die in a
12790 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12792 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12794 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12795 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12797 if (die
->tag
!= origin_die
->tag
12798 && !(die
->tag
== DW_TAG_inlined_subroutine
12799 && origin_die
->tag
== DW_TAG_subprogram
))
12800 complaint (_("DIE %s and its abstract origin %s have different tags"),
12801 sect_offset_str (die
->sect_off
),
12802 sect_offset_str (origin_die
->sect_off
));
12804 /* Find if the concrete and abstract trees are structurally the
12805 same. This is a shallow traversal and it is not bullet-proof;
12806 the compiler can trick the debugger into believing that the trees
12807 are isomorphic, whereas they actually are not. However, the
12808 likelyhood of this happening is pretty low, and a full-fledged
12809 check would be an overkill. */
12810 bool are_isomorphic
= true;
12811 die_info
*concrete_child
= die
->child
;
12812 die_info
*abstract_child
= origin_die
->child
;
12813 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12815 if (concrete_child
== nullptr
12816 || abstract_child
== nullptr
12817 || concrete_child
->tag
!= abstract_child
->tag
)
12819 are_isomorphic
= false;
12823 concrete_child
= concrete_child
->sibling
;
12824 abstract_child
= abstract_child
->sibling
;
12827 /* Walk the origin's children in parallel to the concrete children.
12828 This helps match an origin child in case the debug info misses
12829 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12830 origin tree may not have the same tree structure as the concrete
12832 die_info
*corresponding_abstract_child
12833 = are_isomorphic
? origin_die
->child
: nullptr;
12835 std::vector
<sect_offset
> offsets
;
12837 for (child_die
= die
->child
;
12838 child_die
&& child_die
->tag
;
12839 child_die
= child_die
->sibling
)
12841 struct die_info
*child_origin_die
;
12842 struct dwarf2_cu
*child_origin_cu
;
12844 /* We are trying to process concrete instance entries:
12845 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12846 it's not relevant to our analysis here. i.e. detecting DIEs that are
12847 present in the abstract instance but not referenced in the concrete
12849 if (child_die
->tag
== DW_TAG_call_site
12850 || child_die
->tag
== DW_TAG_GNU_call_site
)
12852 if (are_isomorphic
)
12853 corresponding_abstract_child
12854 = corresponding_abstract_child
->sibling
;
12858 /* For each CHILD_DIE, find the corresponding child of
12859 ORIGIN_DIE. If there is more than one layer of
12860 DW_AT_abstract_origin, follow them all; there shouldn't be,
12861 but GCC versions at least through 4.4 generate this (GCC PR
12863 child_origin_die
= child_die
;
12864 child_origin_cu
= cu
;
12867 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12871 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12875 /* If missing DW_AT_abstract_origin, try the corresponding child
12876 of the origin. Clang emits such lexical scopes. */
12877 if (child_origin_die
== child_die
12878 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12880 && child_die
->tag
== DW_TAG_lexical_block
)
12881 child_origin_die
= corresponding_abstract_child
;
12883 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12884 counterpart may exist. */
12885 if (child_origin_die
!= child_die
)
12887 if (child_die
->tag
!= child_origin_die
->tag
12888 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12889 && child_origin_die
->tag
== DW_TAG_subprogram
))
12890 complaint (_("Child DIE %s and its abstract origin %s have "
12892 sect_offset_str (child_die
->sect_off
),
12893 sect_offset_str (child_origin_die
->sect_off
));
12894 if (child_origin_die
->parent
!= origin_die
)
12895 complaint (_("Child DIE %s and its abstract origin %s have "
12896 "different parents"),
12897 sect_offset_str (child_die
->sect_off
),
12898 sect_offset_str (child_origin_die
->sect_off
));
12900 offsets
.push_back (child_origin_die
->sect_off
);
12903 if (are_isomorphic
)
12904 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12906 std::sort (offsets
.begin (), offsets
.end ());
12907 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12908 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12909 if (offsetp
[-1] == *offsetp
)
12910 complaint (_("Multiple children of DIE %s refer "
12911 "to DIE %s as their abstract origin"),
12912 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12914 offsetp
= offsets
.data ();
12915 origin_child_die
= origin_die
->child
;
12916 while (origin_child_die
&& origin_child_die
->tag
)
12918 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12919 while (offsetp
< offsets_end
12920 && *offsetp
< origin_child_die
->sect_off
)
12922 if (offsetp
>= offsets_end
12923 || *offsetp
> origin_child_die
->sect_off
)
12925 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12926 Check whether we're already processing ORIGIN_CHILD_DIE.
12927 This can happen with mutually referenced abstract_origins.
12929 if (!origin_child_die
->in_process
)
12930 process_die (origin_child_die
, origin_cu
);
12932 origin_child_die
= origin_child_die
->sibling
;
12934 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12936 if (cu
!= origin_cu
)
12937 compute_delayed_physnames (origin_cu
);
12941 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12943 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12944 struct gdbarch
*gdbarch
= objfile
->arch ();
12945 struct context_stack
*newobj
;
12948 struct die_info
*child_die
;
12949 struct attribute
*attr
, *call_line
, *call_file
;
12951 CORE_ADDR baseaddr
;
12952 struct block
*block
;
12953 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12954 std::vector
<struct symbol
*> template_args
;
12955 struct template_symbol
*templ_func
= NULL
;
12959 /* If we do not have call site information, we can't show the
12960 caller of this inlined function. That's too confusing, so
12961 only use the scope for local variables. */
12962 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12963 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12964 if (call_line
== NULL
|| call_file
== NULL
)
12966 read_lexical_block_scope (die
, cu
);
12971 baseaddr
= objfile
->text_section_offset ();
12973 name
= dwarf2_name (die
, cu
);
12975 /* Ignore functions with missing or empty names. These are actually
12976 illegal according to the DWARF standard. */
12979 complaint (_("missing name for subprogram DIE at %s"),
12980 sect_offset_str (die
->sect_off
));
12984 /* Ignore functions with missing or invalid low and high pc attributes. */
12985 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12986 <= PC_BOUNDS_INVALID
)
12988 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12989 if (attr
== nullptr || !attr
->as_boolean ())
12990 complaint (_("cannot get low and high bounds "
12991 "for subprogram DIE at %s"),
12992 sect_offset_str (die
->sect_off
));
12996 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12997 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12999 /* If we have any template arguments, then we must allocate a
13000 different sort of symbol. */
13001 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13003 if (child_die
->tag
== DW_TAG_template_type_param
13004 || child_die
->tag
== DW_TAG_template_value_param
)
13006 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13007 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13012 gdb_assert (cu
->get_builder () != nullptr);
13013 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13014 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13015 (struct symbol
*) templ_func
);
13017 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13018 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13021 /* If there is a location expression for DW_AT_frame_base, record
13023 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13024 if (attr
!= nullptr)
13025 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13027 /* If there is a location for the static link, record it. */
13028 newobj
->static_link
= NULL
;
13029 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13030 if (attr
!= nullptr)
13032 newobj
->static_link
13033 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13034 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13038 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13040 if (die
->child
!= NULL
)
13042 child_die
= die
->child
;
13043 while (child_die
&& child_die
->tag
)
13045 if (child_die
->tag
== DW_TAG_template_type_param
13046 || child_die
->tag
== DW_TAG_template_value_param
)
13048 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13051 template_args
.push_back (arg
);
13054 process_die (child_die
, cu
);
13055 child_die
= child_die
->sibling
;
13059 inherit_abstract_dies (die
, cu
);
13061 /* If we have a DW_AT_specification, we might need to import using
13062 directives from the context of the specification DIE. See the
13063 comment in determine_prefix. */
13064 if (cu
->language
== language_cplus
13065 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13067 struct dwarf2_cu
*spec_cu
= cu
;
13068 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13072 child_die
= spec_die
->child
;
13073 while (child_die
&& child_die
->tag
)
13075 if (child_die
->tag
== DW_TAG_imported_module
)
13076 process_die (child_die
, spec_cu
);
13077 child_die
= child_die
->sibling
;
13080 /* In some cases, GCC generates specification DIEs that
13081 themselves contain DW_AT_specification attributes. */
13082 spec_die
= die_specification (spec_die
, &spec_cu
);
13086 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13087 /* Make a block for the local symbols within. */
13088 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13089 cstk
.static_link
, lowpc
, highpc
);
13091 /* For C++, set the block's scope. */
13092 if ((cu
->language
== language_cplus
13093 || cu
->language
== language_fortran
13094 || cu
->language
== language_d
13095 || cu
->language
== language_rust
)
13096 && cu
->processing_has_namespace_info
)
13097 block_set_scope (block
, determine_prefix (die
, cu
),
13098 &objfile
->objfile_obstack
);
13100 /* If we have address ranges, record them. */
13101 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13103 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13105 /* Attach template arguments to function. */
13106 if (!template_args
.empty ())
13108 gdb_assert (templ_func
!= NULL
);
13110 templ_func
->n_template_arguments
= template_args
.size ();
13111 templ_func
->template_arguments
13112 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13113 templ_func
->n_template_arguments
);
13114 memcpy (templ_func
->template_arguments
,
13115 template_args
.data (),
13116 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13118 /* Make sure that the symtab is set on the new symbols. Even
13119 though they don't appear in this symtab directly, other parts
13120 of gdb assume that symbols do, and this is reasonably
13122 for (symbol
*sym
: template_args
)
13123 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13126 /* In C++, we can have functions nested inside functions (e.g., when
13127 a function declares a class that has methods). This means that
13128 when we finish processing a function scope, we may need to go
13129 back to building a containing block's symbol lists. */
13130 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13131 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13133 /* If we've finished processing a top-level function, subsequent
13134 symbols go in the file symbol list. */
13135 if (cu
->get_builder ()->outermost_context_p ())
13136 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13139 /* Process all the DIES contained within a lexical block scope. Start
13140 a new scope, process the dies, and then close the scope. */
13143 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13145 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13146 struct gdbarch
*gdbarch
= objfile
->arch ();
13147 CORE_ADDR lowpc
, highpc
;
13148 struct die_info
*child_die
;
13149 CORE_ADDR baseaddr
;
13151 baseaddr
= objfile
->text_section_offset ();
13153 /* Ignore blocks with missing or invalid low and high pc attributes. */
13154 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13155 as multiple lexical blocks? Handling children in a sane way would
13156 be nasty. Might be easier to properly extend generic blocks to
13157 describe ranges. */
13158 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13160 case PC_BOUNDS_NOT_PRESENT
:
13161 /* DW_TAG_lexical_block has no attributes, process its children as if
13162 there was no wrapping by that DW_TAG_lexical_block.
13163 GCC does no longer produces such DWARF since GCC r224161. */
13164 for (child_die
= die
->child
;
13165 child_die
!= NULL
&& child_die
->tag
;
13166 child_die
= child_die
->sibling
)
13168 /* We might already be processing this DIE. This can happen
13169 in an unusual circumstance -- where a subroutine A
13170 appears lexically in another subroutine B, but A actually
13171 inlines B. The recursion is broken here, rather than in
13172 inherit_abstract_dies, because it seems better to simply
13173 drop concrete children here. */
13174 if (!child_die
->in_process
)
13175 process_die (child_die
, cu
);
13178 case PC_BOUNDS_INVALID
:
13181 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13182 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13184 cu
->get_builder ()->push_context (0, lowpc
);
13185 if (die
->child
!= NULL
)
13187 child_die
= die
->child
;
13188 while (child_die
&& child_die
->tag
)
13190 process_die (child_die
, cu
);
13191 child_die
= child_die
->sibling
;
13194 inherit_abstract_dies (die
, cu
);
13195 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13197 if (*cu
->get_builder ()->get_local_symbols () != NULL
13198 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13200 struct block
*block
13201 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13202 cstk
.start_addr
, highpc
);
13204 /* Note that recording ranges after traversing children, as we
13205 do here, means that recording a parent's ranges entails
13206 walking across all its children's ranges as they appear in
13207 the address map, which is quadratic behavior.
13209 It would be nicer to record the parent's ranges before
13210 traversing its children, simply overriding whatever you find
13211 there. But since we don't even decide whether to create a
13212 block until after we've traversed its children, that's hard
13214 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13216 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13217 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13220 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13223 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13225 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13226 struct objfile
*objfile
= per_objfile
->objfile
;
13227 struct gdbarch
*gdbarch
= objfile
->arch ();
13228 CORE_ADDR pc
, baseaddr
;
13229 struct attribute
*attr
;
13230 struct call_site
*call_site
, call_site_local
;
13233 struct die_info
*child_die
;
13235 baseaddr
= objfile
->text_section_offset ();
13237 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13240 /* This was a pre-DWARF-5 GNU extension alias
13241 for DW_AT_call_return_pc. */
13242 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13246 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13247 "DIE %s [in module %s]"),
13248 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13251 pc
= attr
->as_address () + baseaddr
;
13252 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13254 if (cu
->call_site_htab
== NULL
)
13255 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13256 NULL
, &objfile
->objfile_obstack
,
13257 hashtab_obstack_allocate
, NULL
);
13258 call_site_local
.pc
= pc
;
13259 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13262 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13263 "DIE %s [in module %s]"),
13264 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13265 objfile_name (objfile
));
13269 /* Count parameters at the caller. */
13272 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13273 child_die
= child_die
->sibling
)
13275 if (child_die
->tag
!= DW_TAG_call_site_parameter
13276 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13278 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13279 "DW_TAG_call_site child DIE %s [in module %s]"),
13280 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13281 objfile_name (objfile
));
13289 = ((struct call_site
*)
13290 obstack_alloc (&objfile
->objfile_obstack
,
13291 sizeof (*call_site
)
13292 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13294 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13295 call_site
->pc
= pc
;
13297 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13298 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13300 struct die_info
*func_die
;
13302 /* Skip also over DW_TAG_inlined_subroutine. */
13303 for (func_die
= die
->parent
;
13304 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13305 && func_die
->tag
!= DW_TAG_subroutine_type
;
13306 func_die
= func_die
->parent
);
13308 /* DW_AT_call_all_calls is a superset
13309 of DW_AT_call_all_tail_calls. */
13311 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13312 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13313 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13314 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13316 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13317 not complete. But keep CALL_SITE for look ups via call_site_htab,
13318 both the initial caller containing the real return address PC and
13319 the final callee containing the current PC of a chain of tail
13320 calls do not need to have the tail call list complete. But any
13321 function candidate for a virtual tail call frame searched via
13322 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13323 determined unambiguously. */
13327 struct type
*func_type
= NULL
;
13330 func_type
= get_die_type (func_die
, cu
);
13331 if (func_type
!= NULL
)
13333 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13335 /* Enlist this call site to the function. */
13336 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13337 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13340 complaint (_("Cannot find function owning DW_TAG_call_site "
13341 "DIE %s [in module %s]"),
13342 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13346 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13348 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13350 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13353 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13354 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13356 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13357 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13358 /* Keep NULL DWARF_BLOCK. */;
13359 else if (attr
->form_is_block ())
13361 struct dwarf2_locexpr_baton
*dlbaton
;
13362 struct dwarf_block
*block
= attr
->as_block ();
13364 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13365 dlbaton
->data
= block
->data
;
13366 dlbaton
->size
= block
->size
;
13367 dlbaton
->per_objfile
= per_objfile
;
13368 dlbaton
->per_cu
= cu
->per_cu
;
13370 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13372 else if (attr
->form_is_ref ())
13374 struct dwarf2_cu
*target_cu
= cu
;
13375 struct die_info
*target_die
;
13377 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13378 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13379 if (die_is_declaration (target_die
, target_cu
))
13381 const char *target_physname
;
13383 /* Prefer the mangled name; otherwise compute the demangled one. */
13384 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13385 if (target_physname
== NULL
)
13386 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13387 if (target_physname
== NULL
)
13388 complaint (_("DW_AT_call_target target DIE has invalid "
13389 "physname, for referencing DIE %s [in module %s]"),
13390 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13392 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13398 /* DW_AT_entry_pc should be preferred. */
13399 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13400 <= PC_BOUNDS_INVALID
)
13401 complaint (_("DW_AT_call_target target DIE has invalid "
13402 "low pc, for referencing DIE %s [in module %s]"),
13403 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13406 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13407 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13412 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13413 "block nor reference, for DIE %s [in module %s]"),
13414 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13416 call_site
->per_cu
= cu
->per_cu
;
13417 call_site
->per_objfile
= per_objfile
;
13419 for (child_die
= die
->child
;
13420 child_die
&& child_die
->tag
;
13421 child_die
= child_die
->sibling
)
13423 struct call_site_parameter
*parameter
;
13424 struct attribute
*loc
, *origin
;
13426 if (child_die
->tag
!= DW_TAG_call_site_parameter
13427 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13429 /* Already printed the complaint above. */
13433 gdb_assert (call_site
->parameter_count
< nparams
);
13434 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13436 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13437 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13438 register is contained in DW_AT_call_value. */
13440 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13441 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13442 if (origin
== NULL
)
13444 /* This was a pre-DWARF-5 GNU extension alias
13445 for DW_AT_call_parameter. */
13446 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13448 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13450 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13452 sect_offset sect_off
= origin
->get_ref_die_offset ();
13453 if (!cu
->header
.offset_in_cu_p (sect_off
))
13455 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13456 binding can be done only inside one CU. Such referenced DIE
13457 therefore cannot be even moved to DW_TAG_partial_unit. */
13458 complaint (_("DW_AT_call_parameter offset is not in CU for "
13459 "DW_TAG_call_site child DIE %s [in module %s]"),
13460 sect_offset_str (child_die
->sect_off
),
13461 objfile_name (objfile
));
13464 parameter
->u
.param_cu_off
13465 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13467 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13469 complaint (_("No DW_FORM_block* DW_AT_location for "
13470 "DW_TAG_call_site child DIE %s [in module %s]"),
13471 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13476 struct dwarf_block
*block
= loc
->as_block ();
13478 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13479 (block
->data
, &block
->data
[block
->size
]);
13480 if (parameter
->u
.dwarf_reg
!= -1)
13481 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13482 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13483 &block
->data
[block
->size
],
13484 ¶meter
->u
.fb_offset
))
13485 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13488 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13489 "for DW_FORM_block* DW_AT_location is supported for "
13490 "DW_TAG_call_site child DIE %s "
13492 sect_offset_str (child_die
->sect_off
),
13493 objfile_name (objfile
));
13498 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13500 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13501 if (attr
== NULL
|| !attr
->form_is_block ())
13503 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13504 "DW_TAG_call_site child DIE %s [in module %s]"),
13505 sect_offset_str (child_die
->sect_off
),
13506 objfile_name (objfile
));
13510 struct dwarf_block
*block
= attr
->as_block ();
13511 parameter
->value
= block
->data
;
13512 parameter
->value_size
= block
->size
;
13514 /* Parameters are not pre-cleared by memset above. */
13515 parameter
->data_value
= NULL
;
13516 parameter
->data_value_size
= 0;
13517 call_site
->parameter_count
++;
13519 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13521 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13522 if (attr
!= nullptr)
13524 if (!attr
->form_is_block ())
13525 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13526 "DW_TAG_call_site child DIE %s [in module %s]"),
13527 sect_offset_str (child_die
->sect_off
),
13528 objfile_name (objfile
));
13531 block
= attr
->as_block ();
13532 parameter
->data_value
= block
->data
;
13533 parameter
->data_value_size
= block
->size
;
13539 /* Helper function for read_variable. If DIE represents a virtual
13540 table, then return the type of the concrete object that is
13541 associated with the virtual table. Otherwise, return NULL. */
13543 static struct type
*
13544 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13546 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13550 /* Find the type DIE. */
13551 struct die_info
*type_die
= NULL
;
13552 struct dwarf2_cu
*type_cu
= cu
;
13554 if (attr
->form_is_ref ())
13555 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13556 if (type_die
== NULL
)
13559 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13561 return die_containing_type (type_die
, type_cu
);
13564 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13567 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13569 struct rust_vtable_symbol
*storage
= NULL
;
13571 if (cu
->language
== language_rust
)
13573 struct type
*containing_type
= rust_containing_type (die
, cu
);
13575 if (containing_type
!= NULL
)
13577 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13579 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13580 storage
->concrete_type
= containing_type
;
13581 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13585 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13586 struct attribute
*abstract_origin
13587 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13588 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13589 if (res
== NULL
&& loc
&& abstract_origin
)
13591 /* We have a variable without a name, but with a location and an abstract
13592 origin. This may be a concrete instance of an abstract variable
13593 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13595 struct dwarf2_cu
*origin_cu
= cu
;
13596 struct die_info
*origin_die
13597 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13598 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13599 per_objfile
->per_bfd
->abstract_to_concrete
13600 [origin_die
->sect_off
].push_back (die
->sect_off
);
13604 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13605 reading .debug_rnglists.
13606 Callback's type should be:
13607 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13608 Return true if the attributes are present and valid, otherwise,
13611 template <typename Callback
>
13613 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13614 dwarf_tag tag
, Callback
&&callback
)
13616 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13617 struct objfile
*objfile
= per_objfile
->objfile
;
13618 bfd
*obfd
= objfile
->obfd
;
13619 /* Base address selection entry. */
13620 gdb::optional
<CORE_ADDR
> base
;
13621 const gdb_byte
*buffer
;
13622 CORE_ADDR baseaddr
;
13623 bool overflow
= false;
13624 ULONGEST addr_index
;
13625 struct dwarf2_section_info
*rnglists_section
;
13627 base
= cu
->base_address
;
13628 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13629 rnglists_section
->read (objfile
);
13631 if (offset
>= rnglists_section
->size
)
13633 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13637 buffer
= rnglists_section
->buffer
+ offset
;
13639 baseaddr
= objfile
->text_section_offset ();
13643 /* Initialize it due to a false compiler warning. */
13644 CORE_ADDR range_beginning
= 0, range_end
= 0;
13645 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13646 + rnglists_section
->size
);
13647 unsigned int bytes_read
;
13649 if (buffer
== buf_end
)
13654 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13657 case DW_RLE_end_of_list
:
13659 case DW_RLE_base_address
:
13660 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13665 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13666 buffer
+= bytes_read
;
13668 case DW_RLE_base_addressx
:
13669 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13670 buffer
+= bytes_read
;
13671 base
= read_addr_index (cu
, addr_index
);
13673 case DW_RLE_start_length
:
13674 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13679 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13681 buffer
+= bytes_read
;
13682 range_end
= (range_beginning
13683 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13684 buffer
+= bytes_read
;
13685 if (buffer
> buf_end
)
13691 case DW_RLE_startx_length
:
13692 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13693 buffer
+= bytes_read
;
13694 range_beginning
= read_addr_index (cu
, addr_index
);
13695 if (buffer
> buf_end
)
13700 range_end
= (range_beginning
13701 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13702 buffer
+= bytes_read
;
13704 case DW_RLE_offset_pair
:
13705 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13706 buffer
+= bytes_read
;
13707 if (buffer
> buf_end
)
13712 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13713 buffer
+= bytes_read
;
13714 if (buffer
> buf_end
)
13720 case DW_RLE_start_end
:
13721 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13726 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13728 buffer
+= bytes_read
;
13729 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13730 buffer
+= bytes_read
;
13732 case DW_RLE_startx_endx
:
13733 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13734 buffer
+= bytes_read
;
13735 range_beginning
= read_addr_index (cu
, addr_index
);
13736 if (buffer
> buf_end
)
13741 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13742 buffer
+= bytes_read
;
13743 range_end
= read_addr_index (cu
, addr_index
);
13746 complaint (_("Invalid .debug_rnglists data (no base address)"));
13749 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13751 if (rlet
== DW_RLE_base_address
)
13754 if (range_beginning
> range_end
)
13756 /* Inverted range entries are invalid. */
13757 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13761 /* Empty range entries have no effect. */
13762 if (range_beginning
== range_end
)
13765 /* Only DW_RLE_offset_pair needs the base address added. */
13766 if (rlet
== DW_RLE_offset_pair
)
13768 if (!base
.has_value ())
13770 /* We have no valid base address for the DW_RLE_offset_pair. */
13771 complaint (_("Invalid .debug_rnglists data (no base address for "
13772 "DW_RLE_offset_pair)"));
13776 range_beginning
+= *base
;
13777 range_end
+= *base
;
13780 /* A not-uncommon case of bad debug info.
13781 Don't pollute the addrmap with bad data. */
13782 if (range_beginning
+ baseaddr
== 0
13783 && !per_objfile
->per_bfd
->has_section_at_zero
)
13785 complaint (_(".debug_rnglists entry has start address of zero"
13786 " [in module %s]"), objfile_name (objfile
));
13790 callback (range_beginning
, range_end
);
13795 complaint (_("Offset %d is not terminated "
13796 "for DW_AT_ranges attribute"),
13804 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13805 Callback's type should be:
13806 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13807 Return 1 if the attributes are present and valid, otherwise, return 0. */
13809 template <typename Callback
>
13811 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13812 Callback
&&callback
)
13814 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13815 struct objfile
*objfile
= per_objfile
->objfile
;
13816 struct comp_unit_head
*cu_header
= &cu
->header
;
13817 bfd
*obfd
= objfile
->obfd
;
13818 unsigned int addr_size
= cu_header
->addr_size
;
13819 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13820 /* Base address selection entry. */
13821 gdb::optional
<CORE_ADDR
> base
;
13822 unsigned int dummy
;
13823 const gdb_byte
*buffer
;
13824 CORE_ADDR baseaddr
;
13826 if (cu_header
->version
>= 5)
13827 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13829 base
= cu
->base_address
;
13831 per_objfile
->per_bfd
->ranges
.read (objfile
);
13832 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13834 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13838 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13840 baseaddr
= objfile
->text_section_offset ();
13844 CORE_ADDR range_beginning
, range_end
;
13846 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13847 buffer
+= addr_size
;
13848 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13849 buffer
+= addr_size
;
13850 offset
+= 2 * addr_size
;
13852 /* An end of list marker is a pair of zero addresses. */
13853 if (range_beginning
== 0 && range_end
== 0)
13854 /* Found the end of list entry. */
13857 /* Each base address selection entry is a pair of 2 values.
13858 The first is the largest possible address, the second is
13859 the base address. Check for a base address here. */
13860 if ((range_beginning
& mask
) == mask
)
13862 /* If we found the largest possible address, then we already
13863 have the base address in range_end. */
13868 if (!base
.has_value ())
13870 /* We have no valid base address for the ranges
13872 complaint (_("Invalid .debug_ranges data (no base address)"));
13876 if (range_beginning
> range_end
)
13878 /* Inverted range entries are invalid. */
13879 complaint (_("Invalid .debug_ranges data (inverted range)"));
13883 /* Empty range entries have no effect. */
13884 if (range_beginning
== range_end
)
13887 range_beginning
+= *base
;
13888 range_end
+= *base
;
13890 /* A not-uncommon case of bad debug info.
13891 Don't pollute the addrmap with bad data. */
13892 if (range_beginning
+ baseaddr
== 0
13893 && !per_objfile
->per_bfd
->has_section_at_zero
)
13895 complaint (_(".debug_ranges entry has start address of zero"
13896 " [in module %s]"), objfile_name (objfile
));
13900 callback (range_beginning
, range_end
);
13906 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13907 Return 1 if the attributes are present and valid, otherwise, return 0.
13908 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
13911 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13912 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13913 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
13915 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13916 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
13917 struct gdbarch
*gdbarch
= objfile
->arch ();
13918 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13921 CORE_ADDR high
= 0;
13924 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
13925 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13927 if (ranges_pst
!= NULL
)
13932 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13933 range_beginning
+ baseaddr
)
13935 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13936 range_end
+ baseaddr
)
13938 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
13939 lowpc
, highpc
- 1, ranges_pst
);
13942 /* FIXME: This is recording everything as a low-high
13943 segment of consecutive addresses. We should have a
13944 data structure for discontiguous block ranges
13948 low
= range_beginning
;
13954 if (range_beginning
< low
)
13955 low
= range_beginning
;
13956 if (range_end
> high
)
13964 /* If the first entry is an end-of-list marker, the range
13965 describes an empty scope, i.e. no instructions. */
13971 *high_return
= high
;
13975 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13976 definition for the return value. *LOWPC and *HIGHPC are set iff
13977 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13979 static enum pc_bounds_kind
13980 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13981 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13982 dwarf2_psymtab
*pst
)
13984 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13985 struct attribute
*attr
;
13986 struct attribute
*attr_high
;
13988 CORE_ADDR high
= 0;
13989 enum pc_bounds_kind ret
;
13991 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13994 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13995 if (attr
!= nullptr)
13997 low
= attr
->as_address ();
13998 high
= attr_high
->as_address ();
13999 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14003 /* Found high w/o low attribute. */
14004 return PC_BOUNDS_INVALID
;
14006 /* Found consecutive range of addresses. */
14007 ret
= PC_BOUNDS_HIGH_LOW
;
14011 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14012 if (attr
!= nullptr && attr
->form_is_unsigned ())
14014 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14015 on DWARF version). */
14016 ULONGEST ranges_offset
= attr
->as_unsigned ();
14018 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14020 if (die
->tag
!= DW_TAG_compile_unit
)
14021 ranges_offset
+= cu
->gnu_ranges_base
;
14023 /* Value of the DW_AT_ranges attribute is the offset in the
14024 .debug_ranges section. */
14025 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14027 return PC_BOUNDS_INVALID
;
14028 /* Found discontinuous range of addresses. */
14029 ret
= PC_BOUNDS_RANGES
;
14032 return PC_BOUNDS_NOT_PRESENT
;
14035 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14037 return PC_BOUNDS_INVALID
;
14039 /* When using the GNU linker, .gnu.linkonce. sections are used to
14040 eliminate duplicate copies of functions and vtables and such.
14041 The linker will arbitrarily choose one and discard the others.
14042 The AT_*_pc values for such functions refer to local labels in
14043 these sections. If the section from that file was discarded, the
14044 labels are not in the output, so the relocs get a value of 0.
14045 If this is a discarded function, mark the pc bounds as invalid,
14046 so that GDB will ignore it. */
14047 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14048 return PC_BOUNDS_INVALID
;
14056 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14057 its low and high PC addresses. Do nothing if these addresses could not
14058 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14059 and HIGHPC to the high address if greater than HIGHPC. */
14062 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14063 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14064 struct dwarf2_cu
*cu
)
14066 CORE_ADDR low
, high
;
14067 struct die_info
*child
= die
->child
;
14069 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14071 *lowpc
= std::min (*lowpc
, low
);
14072 *highpc
= std::max (*highpc
, high
);
14075 /* If the language does not allow nested subprograms (either inside
14076 subprograms or lexical blocks), we're done. */
14077 if (cu
->language
!= language_ada
)
14080 /* Check all the children of the given DIE. If it contains nested
14081 subprograms, then check their pc bounds. Likewise, we need to
14082 check lexical blocks as well, as they may also contain subprogram
14084 while (child
&& child
->tag
)
14086 if (child
->tag
== DW_TAG_subprogram
14087 || child
->tag
== DW_TAG_lexical_block
)
14088 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14089 child
= child
->sibling
;
14093 /* Get the low and high pc's represented by the scope DIE, and store
14094 them in *LOWPC and *HIGHPC. If the correct values can't be
14095 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14098 get_scope_pc_bounds (struct die_info
*die
,
14099 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14100 struct dwarf2_cu
*cu
)
14102 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14103 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14104 CORE_ADDR current_low
, current_high
;
14106 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14107 >= PC_BOUNDS_RANGES
)
14109 best_low
= current_low
;
14110 best_high
= current_high
;
14114 struct die_info
*child
= die
->child
;
14116 while (child
&& child
->tag
)
14118 switch (child
->tag
) {
14119 case DW_TAG_subprogram
:
14120 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14122 case DW_TAG_namespace
:
14123 case DW_TAG_module
:
14124 /* FIXME: carlton/2004-01-16: Should we do this for
14125 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14126 that current GCC's always emit the DIEs corresponding
14127 to definitions of methods of classes as children of a
14128 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14129 the DIEs giving the declarations, which could be
14130 anywhere). But I don't see any reason why the
14131 standards says that they have to be there. */
14132 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14134 if (current_low
!= ((CORE_ADDR
) -1))
14136 best_low
= std::min (best_low
, current_low
);
14137 best_high
= std::max (best_high
, current_high
);
14145 child
= child
->sibling
;
14150 *highpc
= best_high
;
14153 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14157 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14158 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14160 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14161 struct gdbarch
*gdbarch
= objfile
->arch ();
14162 struct attribute
*attr
;
14163 struct attribute
*attr_high
;
14165 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14168 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14169 if (attr
!= nullptr)
14171 CORE_ADDR low
= attr
->as_address ();
14172 CORE_ADDR high
= attr_high
->as_address ();
14174 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14177 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14178 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14179 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14183 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14184 if (attr
!= nullptr && attr
->form_is_unsigned ())
14186 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14187 on DWARF version). */
14188 ULONGEST ranges_offset
= attr
->as_unsigned ();
14190 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14192 if (die
->tag
!= DW_TAG_compile_unit
)
14193 ranges_offset
+= cu
->gnu_ranges_base
;
14195 std::vector
<blockrange
> blockvec
;
14196 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14197 [&] (CORE_ADDR start
, CORE_ADDR end
)
14201 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14202 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14203 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14204 blockvec
.emplace_back (start
, end
);
14207 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14211 /* Check whether the producer field indicates either of GCC < 4.6, or the
14212 Intel C/C++ compiler, and cache the result in CU. */
14215 check_producer (struct dwarf2_cu
*cu
)
14219 if (cu
->producer
== NULL
)
14221 /* For unknown compilers expect their behavior is DWARF version
14224 GCC started to support .debug_types sections by -gdwarf-4 since
14225 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14226 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14227 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14228 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14230 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14232 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14233 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14235 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14237 cu
->producer_is_icc
= true;
14238 cu
->producer_is_icc_lt_14
= major
< 14;
14240 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14241 cu
->producer_is_codewarrior
= true;
14244 /* For other non-GCC compilers, expect their behavior is DWARF version
14248 cu
->checked_producer
= true;
14251 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14252 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14253 during 4.6.0 experimental. */
14256 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14258 if (!cu
->checked_producer
)
14259 check_producer (cu
);
14261 return cu
->producer_is_gxx_lt_4_6
;
14265 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14266 with incorrect is_stmt attributes. */
14269 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14271 if (!cu
->checked_producer
)
14272 check_producer (cu
);
14274 return cu
->producer_is_codewarrior
;
14277 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14278 If that attribute is not available, return the appropriate
14281 static enum dwarf_access_attribute
14282 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14284 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14285 if (attr
!= nullptr)
14287 LONGEST value
= attr
->constant_value (-1);
14288 if (value
== DW_ACCESS_public
14289 || value
== DW_ACCESS_protected
14290 || value
== DW_ACCESS_private
)
14291 return (dwarf_access_attribute
) value
;
14292 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14296 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14298 /* The default DWARF 2 accessibility for members is public, the default
14299 accessibility for inheritance is private. */
14301 if (die
->tag
!= DW_TAG_inheritance
)
14302 return DW_ACCESS_public
;
14304 return DW_ACCESS_private
;
14308 /* DWARF 3+ defines the default accessibility a different way. The same
14309 rules apply now for DW_TAG_inheritance as for the members and it only
14310 depends on the container kind. */
14312 if (die
->parent
->tag
== DW_TAG_class_type
)
14313 return DW_ACCESS_private
;
14315 return DW_ACCESS_public
;
14319 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14320 offset. If the attribute was not found return 0, otherwise return
14321 1. If it was found but could not properly be handled, set *OFFSET
14325 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14328 struct attribute
*attr
;
14330 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14335 /* Note that we do not check for a section offset first here.
14336 This is because DW_AT_data_member_location is new in DWARF 4,
14337 so if we see it, we can assume that a constant form is really
14338 a constant and not a section offset. */
14339 if (attr
->form_is_constant ())
14340 *offset
= attr
->constant_value (0);
14341 else if (attr
->form_is_section_offset ())
14342 dwarf2_complex_location_expr_complaint ();
14343 else if (attr
->form_is_block ())
14344 *offset
= decode_locdesc (attr
->as_block (), cu
);
14346 dwarf2_complex_location_expr_complaint ();
14354 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14357 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14358 struct field
*field
)
14360 struct attribute
*attr
;
14362 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14365 if (attr
->form_is_constant ())
14367 LONGEST offset
= attr
->constant_value (0);
14368 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14370 else if (attr
->form_is_section_offset ())
14371 dwarf2_complex_location_expr_complaint ();
14372 else if (attr
->form_is_block ())
14375 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14377 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14380 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14381 struct objfile
*objfile
= per_objfile
->objfile
;
14382 struct dwarf2_locexpr_baton
*dlbaton
14383 = XOBNEW (&objfile
->objfile_obstack
,
14384 struct dwarf2_locexpr_baton
);
14385 dlbaton
->data
= attr
->as_block ()->data
;
14386 dlbaton
->size
= attr
->as_block ()->size
;
14387 /* When using this baton, we want to compute the address
14388 of the field, not the value. This is why
14389 is_reference is set to false here. */
14390 dlbaton
->is_reference
= false;
14391 dlbaton
->per_objfile
= per_objfile
;
14392 dlbaton
->per_cu
= cu
->per_cu
;
14394 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14398 dwarf2_complex_location_expr_complaint ();
14402 /* Add an aggregate field to the field list. */
14405 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14406 struct dwarf2_cu
*cu
)
14408 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14409 struct gdbarch
*gdbarch
= objfile
->arch ();
14410 struct nextfield
*new_field
;
14411 struct attribute
*attr
;
14413 const char *fieldname
= "";
14415 if (die
->tag
== DW_TAG_inheritance
)
14417 fip
->baseclasses
.emplace_back ();
14418 new_field
= &fip
->baseclasses
.back ();
14422 fip
->fields
.emplace_back ();
14423 new_field
= &fip
->fields
.back ();
14426 new_field
->offset
= die
->sect_off
;
14428 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14429 if (new_field
->accessibility
!= DW_ACCESS_public
)
14430 fip
->non_public_fields
= true;
14432 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14433 if (attr
!= nullptr)
14434 new_field
->virtuality
= attr
->as_virtuality ();
14436 new_field
->virtuality
= DW_VIRTUALITY_none
;
14438 fp
= &new_field
->field
;
14440 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14442 /* Data member other than a C++ static data member. */
14444 /* Get type of field. */
14445 fp
->set_type (die_type (die
, cu
));
14447 SET_FIELD_BITPOS (*fp
, 0);
14449 /* Get bit size of field (zero if none). */
14450 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14451 if (attr
!= nullptr)
14453 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14457 FIELD_BITSIZE (*fp
) = 0;
14460 /* Get bit offset of field. */
14461 handle_data_member_location (die
, cu
, fp
);
14462 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14463 if (attr
!= nullptr && attr
->form_is_constant ())
14465 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14467 /* For big endian bits, the DW_AT_bit_offset gives the
14468 additional bit offset from the MSB of the containing
14469 anonymous object to the MSB of the field. We don't
14470 have to do anything special since we don't need to
14471 know the size of the anonymous object. */
14472 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14473 + attr
->constant_value (0)));
14477 /* For little endian bits, compute the bit offset to the
14478 MSB of the anonymous object, subtract off the number of
14479 bits from the MSB of the field to the MSB of the
14480 object, and then subtract off the number of bits of
14481 the field itself. The result is the bit offset of
14482 the LSB of the field. */
14483 int anonymous_size
;
14484 int bit_offset
= attr
->constant_value (0);
14486 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14487 if (attr
!= nullptr && attr
->form_is_constant ())
14489 /* The size of the anonymous object containing
14490 the bit field is explicit, so use the
14491 indicated size (in bytes). */
14492 anonymous_size
= attr
->constant_value (0);
14496 /* The size of the anonymous object containing
14497 the bit field must be inferred from the type
14498 attribute of the data member containing the
14500 anonymous_size
= TYPE_LENGTH (fp
->type ());
14502 SET_FIELD_BITPOS (*fp
,
14503 (FIELD_BITPOS (*fp
)
14504 + anonymous_size
* bits_per_byte
14505 - bit_offset
- FIELD_BITSIZE (*fp
)));
14508 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14510 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14511 + attr
->constant_value (0)));
14513 /* Get name of field. */
14514 fieldname
= dwarf2_name (die
, cu
);
14515 if (fieldname
== NULL
)
14518 /* The name is already allocated along with this objfile, so we don't
14519 need to duplicate it for the type. */
14520 fp
->name
= fieldname
;
14522 /* Change accessibility for artificial fields (e.g. virtual table
14523 pointer or virtual base class pointer) to private. */
14524 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14526 FIELD_ARTIFICIAL (*fp
) = 1;
14527 new_field
->accessibility
= DW_ACCESS_private
;
14528 fip
->non_public_fields
= true;
14531 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14533 /* C++ static member. */
14535 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14536 is a declaration, but all versions of G++ as of this writing
14537 (so through at least 3.2.1) incorrectly generate
14538 DW_TAG_variable tags. */
14540 const char *physname
;
14542 /* Get name of field. */
14543 fieldname
= dwarf2_name (die
, cu
);
14544 if (fieldname
== NULL
)
14547 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14549 /* Only create a symbol if this is an external value.
14550 new_symbol checks this and puts the value in the global symbol
14551 table, which we want. If it is not external, new_symbol
14552 will try to put the value in cu->list_in_scope which is wrong. */
14553 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14555 /* A static const member, not much different than an enum as far as
14556 we're concerned, except that we can support more types. */
14557 new_symbol (die
, NULL
, cu
);
14560 /* Get physical name. */
14561 physname
= dwarf2_physname (fieldname
, die
, cu
);
14563 /* The name is already allocated along with this objfile, so we don't
14564 need to duplicate it for the type. */
14565 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14566 fp
->set_type (die_type (die
, cu
));
14567 FIELD_NAME (*fp
) = fieldname
;
14569 else if (die
->tag
== DW_TAG_inheritance
)
14571 /* C++ base class field. */
14572 handle_data_member_location (die
, cu
, fp
);
14573 FIELD_BITSIZE (*fp
) = 0;
14574 fp
->set_type (die_type (die
, cu
));
14575 FIELD_NAME (*fp
) = fp
->type ()->name ();
14578 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14581 /* Can the type given by DIE define another type? */
14584 type_can_define_types (const struct die_info
*die
)
14588 case DW_TAG_typedef
:
14589 case DW_TAG_class_type
:
14590 case DW_TAG_structure_type
:
14591 case DW_TAG_union_type
:
14592 case DW_TAG_enumeration_type
:
14600 /* Add a type definition defined in the scope of the FIP's class. */
14603 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14604 struct dwarf2_cu
*cu
)
14606 struct decl_field fp
;
14607 memset (&fp
, 0, sizeof (fp
));
14609 gdb_assert (type_can_define_types (die
));
14611 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14612 fp
.name
= dwarf2_name (die
, cu
);
14613 fp
.type
= read_type_die (die
, cu
);
14615 /* Save accessibility. */
14616 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14617 switch (accessibility
)
14619 case DW_ACCESS_public
:
14620 /* The assumed value if neither private nor protected. */
14622 case DW_ACCESS_private
:
14625 case DW_ACCESS_protected
:
14626 fp
.is_protected
= 1;
14630 if (die
->tag
== DW_TAG_typedef
)
14631 fip
->typedef_field_list
.push_back (fp
);
14633 fip
->nested_types_list
.push_back (fp
);
14636 /* A convenience typedef that's used when finding the discriminant
14637 field for a variant part. */
14638 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14641 /* Compute the discriminant range for a given variant. OBSTACK is
14642 where the results will be stored. VARIANT is the variant to
14643 process. IS_UNSIGNED indicates whether the discriminant is signed
14646 static const gdb::array_view
<discriminant_range
>
14647 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14650 std::vector
<discriminant_range
> ranges
;
14652 if (variant
.default_branch
)
14655 if (variant
.discr_list_data
== nullptr)
14657 discriminant_range r
14658 = {variant
.discriminant_value
, variant
.discriminant_value
};
14659 ranges
.push_back (r
);
14663 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14664 variant
.discr_list_data
->size
);
14665 while (!data
.empty ())
14667 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14669 complaint (_("invalid discriminant marker: %d"), data
[0]);
14672 bool is_range
= data
[0] == DW_DSC_range
;
14673 data
= data
.slice (1);
14675 ULONGEST low
, high
;
14676 unsigned int bytes_read
;
14680 complaint (_("DW_AT_discr_list missing low value"));
14684 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14686 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14688 data
= data
.slice (bytes_read
);
14694 complaint (_("DW_AT_discr_list missing high value"));
14698 high
= read_unsigned_leb128 (nullptr, data
.data (),
14701 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14703 data
= data
.slice (bytes_read
);
14708 ranges
.push_back ({ low
, high
});
14712 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14714 std::copy (ranges
.begin (), ranges
.end (), result
);
14715 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14718 static const gdb::array_view
<variant_part
> create_variant_parts
14719 (struct obstack
*obstack
,
14720 const offset_map_type
&offset_map
,
14721 struct field_info
*fi
,
14722 const std::vector
<variant_part_builder
> &variant_parts
);
14724 /* Fill in a "struct variant" for a given variant field. RESULT is
14725 the variant to fill in. OBSTACK is where any needed allocations
14726 will be done. OFFSET_MAP holds the mapping from section offsets to
14727 fields for the type. FI describes the fields of the type we're
14728 processing. FIELD is the variant field we're converting. */
14731 create_one_variant (variant
&result
, struct obstack
*obstack
,
14732 const offset_map_type
&offset_map
,
14733 struct field_info
*fi
, const variant_field
&field
)
14735 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14736 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14737 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14738 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14739 field
.variant_parts
);
14742 /* Fill in a "struct variant_part" for a given variant part. RESULT
14743 is the variant part to fill in. OBSTACK is where any needed
14744 allocations will be done. OFFSET_MAP holds the mapping from
14745 section offsets to fields for the type. FI describes the fields of
14746 the type we're processing. BUILDER is the variant part to be
14750 create_one_variant_part (variant_part
&result
,
14751 struct obstack
*obstack
,
14752 const offset_map_type
&offset_map
,
14753 struct field_info
*fi
,
14754 const variant_part_builder
&builder
)
14756 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14757 if (iter
== offset_map
.end ())
14759 result
.discriminant_index
= -1;
14760 /* Doesn't matter. */
14761 result
.is_unsigned
= false;
14765 result
.discriminant_index
= iter
->second
;
14767 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14770 size_t n
= builder
.variants
.size ();
14771 variant
*output
= new (obstack
) variant
[n
];
14772 for (size_t i
= 0; i
< n
; ++i
)
14773 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14774 builder
.variants
[i
]);
14776 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14779 /* Create a vector of variant parts that can be attached to a type.
14780 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14781 holds the mapping from section offsets to fields for the type. FI
14782 describes the fields of the type we're processing. VARIANT_PARTS
14783 is the vector to convert. */
14785 static const gdb::array_view
<variant_part
>
14786 create_variant_parts (struct obstack
*obstack
,
14787 const offset_map_type
&offset_map
,
14788 struct field_info
*fi
,
14789 const std::vector
<variant_part_builder
> &variant_parts
)
14791 if (variant_parts
.empty ())
14794 size_t n
= variant_parts
.size ();
14795 variant_part
*result
= new (obstack
) variant_part
[n
];
14796 for (size_t i
= 0; i
< n
; ++i
)
14797 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14800 return gdb::array_view
<variant_part
> (result
, n
);
14803 /* Compute the variant part vector for FIP, attaching it to TYPE when
14807 add_variant_property (struct field_info
*fip
, struct type
*type
,
14808 struct dwarf2_cu
*cu
)
14810 /* Map section offsets of fields to their field index. Note the
14811 field index here does not take the number of baseclasses into
14813 offset_map_type offset_map
;
14814 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14815 offset_map
[fip
->fields
[i
].offset
] = i
;
14817 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14818 gdb::array_view
<variant_part
> parts
14819 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14820 fip
->variant_parts
);
14822 struct dynamic_prop prop
;
14823 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14824 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14827 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14830 /* Create the vector of fields, and attach it to the type. */
14833 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14834 struct dwarf2_cu
*cu
)
14836 int nfields
= fip
->nfields ();
14838 /* Record the field count, allocate space for the array of fields,
14839 and create blank accessibility bitfields if necessary. */
14840 type
->set_num_fields (nfields
);
14842 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14844 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14846 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14848 TYPE_FIELD_PRIVATE_BITS (type
) =
14849 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14850 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14852 TYPE_FIELD_PROTECTED_BITS (type
) =
14853 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14854 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14856 TYPE_FIELD_IGNORE_BITS (type
) =
14857 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14858 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14861 /* If the type has baseclasses, allocate and clear a bit vector for
14862 TYPE_FIELD_VIRTUAL_BITS. */
14863 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14865 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14866 unsigned char *pointer
;
14868 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14869 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14870 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14871 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14872 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14875 if (!fip
->variant_parts
.empty ())
14876 add_variant_property (fip
, type
, cu
);
14878 /* Copy the saved-up fields into the field vector. */
14879 for (int i
= 0; i
< nfields
; ++i
)
14881 struct nextfield
&field
14882 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14883 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14885 type
->field (i
) = field
.field
;
14886 switch (field
.accessibility
)
14888 case DW_ACCESS_private
:
14889 if (cu
->language
!= language_ada
)
14890 SET_TYPE_FIELD_PRIVATE (type
, i
);
14893 case DW_ACCESS_protected
:
14894 if (cu
->language
!= language_ada
)
14895 SET_TYPE_FIELD_PROTECTED (type
, i
);
14898 case DW_ACCESS_public
:
14902 /* Unknown accessibility. Complain and treat it as public. */
14904 complaint (_("unsupported accessibility %d"),
14905 field
.accessibility
);
14909 if (i
< fip
->baseclasses
.size ())
14911 switch (field
.virtuality
)
14913 case DW_VIRTUALITY_virtual
:
14914 case DW_VIRTUALITY_pure_virtual
:
14915 if (cu
->language
== language_ada
)
14916 error (_("unexpected virtuality in component of Ada type"));
14917 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14924 /* Return true if this member function is a constructor, false
14928 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14930 const char *fieldname
;
14931 const char *type_name
;
14934 if (die
->parent
== NULL
)
14937 if (die
->parent
->tag
!= DW_TAG_structure_type
14938 && die
->parent
->tag
!= DW_TAG_union_type
14939 && die
->parent
->tag
!= DW_TAG_class_type
)
14942 fieldname
= dwarf2_name (die
, cu
);
14943 type_name
= dwarf2_name (die
->parent
, cu
);
14944 if (fieldname
== NULL
|| type_name
== NULL
)
14947 len
= strlen (fieldname
);
14948 return (strncmp (fieldname
, type_name
, len
) == 0
14949 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14952 /* Add a member function to the proper fieldlist. */
14955 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14956 struct type
*type
, struct dwarf2_cu
*cu
)
14958 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14959 struct attribute
*attr
;
14961 struct fnfieldlist
*flp
= nullptr;
14962 struct fn_field
*fnp
;
14963 const char *fieldname
;
14964 struct type
*this_type
;
14966 if (cu
->language
== language_ada
)
14967 error (_("unexpected member function in Ada type"));
14969 /* Get name of member function. */
14970 fieldname
= dwarf2_name (die
, cu
);
14971 if (fieldname
== NULL
)
14974 /* Look up member function name in fieldlist. */
14975 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14977 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14979 flp
= &fip
->fnfieldlists
[i
];
14984 /* Create a new fnfieldlist if necessary. */
14985 if (flp
== nullptr)
14987 fip
->fnfieldlists
.emplace_back ();
14988 flp
= &fip
->fnfieldlists
.back ();
14989 flp
->name
= fieldname
;
14990 i
= fip
->fnfieldlists
.size () - 1;
14993 /* Create a new member function field and add it to the vector of
14995 flp
->fnfields
.emplace_back ();
14996 fnp
= &flp
->fnfields
.back ();
14998 /* Delay processing of the physname until later. */
14999 if (cu
->language
== language_cplus
)
15000 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15004 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15005 fnp
->physname
= physname
? physname
: "";
15008 fnp
->type
= alloc_type (objfile
);
15009 this_type
= read_type_die (die
, cu
);
15010 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15012 int nparams
= this_type
->num_fields ();
15014 /* TYPE is the domain of this method, and THIS_TYPE is the type
15015 of the method itself (TYPE_CODE_METHOD). */
15016 smash_to_method_type (fnp
->type
, type
,
15017 TYPE_TARGET_TYPE (this_type
),
15018 this_type
->fields (),
15019 this_type
->num_fields (),
15020 this_type
->has_varargs ());
15022 /* Handle static member functions.
15023 Dwarf2 has no clean way to discern C++ static and non-static
15024 member functions. G++ helps GDB by marking the first
15025 parameter for non-static member functions (which is the this
15026 pointer) as artificial. We obtain this information from
15027 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15028 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15029 fnp
->voffset
= VOFFSET_STATIC
;
15032 complaint (_("member function type missing for '%s'"),
15033 dwarf2_full_name (fieldname
, die
, cu
));
15035 /* Get fcontext from DW_AT_containing_type if present. */
15036 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15037 fnp
->fcontext
= die_containing_type (die
, cu
);
15039 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15040 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15042 /* Get accessibility. */
15043 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15044 switch (accessibility
)
15046 case DW_ACCESS_private
:
15047 fnp
->is_private
= 1;
15049 case DW_ACCESS_protected
:
15050 fnp
->is_protected
= 1;
15054 /* Check for artificial methods. */
15055 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15056 if (attr
&& attr
->as_boolean ())
15057 fnp
->is_artificial
= 1;
15059 /* Check for defaulted methods. */
15060 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15061 if (attr
!= nullptr)
15062 fnp
->defaulted
= attr
->defaulted ();
15064 /* Check for deleted methods. */
15065 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15066 if (attr
!= nullptr && attr
->as_boolean ())
15067 fnp
->is_deleted
= 1;
15069 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15071 /* Get index in virtual function table if it is a virtual member
15072 function. For older versions of GCC, this is an offset in the
15073 appropriate virtual table, as specified by DW_AT_containing_type.
15074 For everyone else, it is an expression to be evaluated relative
15075 to the object address. */
15077 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15078 if (attr
!= nullptr)
15080 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15082 struct dwarf_block
*block
= attr
->as_block ();
15084 if (block
->data
[0] == DW_OP_constu
)
15086 /* Old-style GCC. */
15087 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15089 else if (block
->data
[0] == DW_OP_deref
15090 || (block
->size
> 1
15091 && block
->data
[0] == DW_OP_deref_size
15092 && block
->data
[1] == cu
->header
.addr_size
))
15094 fnp
->voffset
= decode_locdesc (block
, cu
);
15095 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15096 dwarf2_complex_location_expr_complaint ();
15098 fnp
->voffset
/= cu
->header
.addr_size
;
15102 dwarf2_complex_location_expr_complaint ();
15104 if (!fnp
->fcontext
)
15106 /* If there is no `this' field and no DW_AT_containing_type,
15107 we cannot actually find a base class context for the
15109 if (this_type
->num_fields () == 0
15110 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15112 complaint (_("cannot determine context for virtual member "
15113 "function \"%s\" (offset %s)"),
15114 fieldname
, sect_offset_str (die
->sect_off
));
15119 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15123 else if (attr
->form_is_section_offset ())
15125 dwarf2_complex_location_expr_complaint ();
15129 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15135 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15136 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15138 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15139 complaint (_("Member function \"%s\" (offset %s) is virtual "
15140 "but the vtable offset is not specified"),
15141 fieldname
, sect_offset_str (die
->sect_off
));
15142 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15143 TYPE_CPLUS_DYNAMIC (type
) = 1;
15148 /* Create the vector of member function fields, and attach it to the type. */
15151 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15152 struct dwarf2_cu
*cu
)
15154 if (cu
->language
== language_ada
)
15155 error (_("unexpected member functions in Ada type"));
15157 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15158 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15160 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15162 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15164 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15165 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15167 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15168 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15169 fn_flp
->fn_fields
= (struct fn_field
*)
15170 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15172 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15173 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15176 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15179 /* Returns non-zero if NAME is the name of a vtable member in CU's
15180 language, zero otherwise. */
15182 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15184 static const char vptr
[] = "_vptr";
15186 /* Look for the C++ form of the vtable. */
15187 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15193 /* GCC outputs unnamed structures that are really pointers to member
15194 functions, with the ABI-specified layout. If TYPE describes
15195 such a structure, smash it into a member function type.
15197 GCC shouldn't do this; it should just output pointer to member DIEs.
15198 This is GCC PR debug/28767. */
15201 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15203 struct type
*pfn_type
, *self_type
, *new_type
;
15205 /* Check for a structure with no name and two children. */
15206 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15209 /* Check for __pfn and __delta members. */
15210 if (TYPE_FIELD_NAME (type
, 0) == NULL
15211 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15212 || TYPE_FIELD_NAME (type
, 1) == NULL
15213 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15216 /* Find the type of the method. */
15217 pfn_type
= type
->field (0).type ();
15218 if (pfn_type
== NULL
15219 || pfn_type
->code () != TYPE_CODE_PTR
15220 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15223 /* Look for the "this" argument. */
15224 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15225 if (pfn_type
->num_fields () == 0
15226 /* || pfn_type->field (0).type () == NULL */
15227 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15230 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15231 new_type
= alloc_type (objfile
);
15232 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15233 pfn_type
->fields (), pfn_type
->num_fields (),
15234 pfn_type
->has_varargs ());
15235 smash_to_methodptr_type (type
, new_type
);
15238 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15239 requires rewriting, then copy it and return the updated copy.
15240 Otherwise return nullptr. */
15242 static struct type
*
15243 rewrite_array_type (struct type
*type
)
15245 if (type
->code () != TYPE_CODE_ARRAY
)
15248 struct type
*index_type
= type
->index_type ();
15249 range_bounds
*current_bounds
= index_type
->bounds ();
15251 /* Handle multi-dimensional arrays. */
15252 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15253 if (new_target
== nullptr)
15255 /* Maybe we don't need to rewrite this array. */
15256 if (current_bounds
->low
.kind () == PROP_CONST
15257 && current_bounds
->high
.kind () == PROP_CONST
)
15261 /* Either the target type was rewritten, or the bounds have to be
15262 updated. Either way we want to copy the type and update
15264 struct type
*copy
= copy_type (type
);
15265 int nfields
= copy
->num_fields ();
15267 = ((struct field
*) TYPE_ZALLOC (copy
,
15268 nfields
* sizeof (struct field
)));
15269 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15270 copy
->set_fields (new_fields
);
15271 if (new_target
!= nullptr)
15272 TYPE_TARGET_TYPE (copy
) = new_target
;
15274 struct type
*index_copy
= copy_type (index_type
);
15275 range_bounds
*bounds
15276 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15277 sizeof (range_bounds
));
15278 *bounds
= *current_bounds
;
15279 bounds
->low
.set_const_val (1);
15280 bounds
->high
.set_const_val (0);
15281 index_copy
->set_bounds (bounds
);
15282 copy
->set_index_type (index_copy
);
15287 /* While some versions of GCC will generate complicated DWARF for an
15288 array (see quirk_ada_thick_pointer), more recent versions were
15289 modified to emit an explicit thick pointer structure. However, in
15290 this case, the array still has DWARF expressions for its ranges,
15291 and these must be ignored. */
15294 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15297 gdb_assert (cu
->language
== language_ada
);
15299 /* Check for a structure with two children. */
15300 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15303 /* Check for P_ARRAY and P_BOUNDS members. */
15304 if (TYPE_FIELD_NAME (type
, 0) == NULL
15305 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15306 || TYPE_FIELD_NAME (type
, 1) == NULL
15307 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15310 /* Make sure we're looking at a pointer to an array. */
15311 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15314 /* The Ada code already knows how to handle these types, so all that
15315 we need to do is turn the bounds into static bounds. However, we
15316 don't want to rewrite existing array or index types in-place,
15317 because those may be referenced in other contexts where this
15318 rewriting is undesirable. */
15319 struct type
*new_ary_type
15320 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15321 if (new_ary_type
!= nullptr)
15322 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15325 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15326 appropriate error checking and issuing complaints if there is a
15330 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15332 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15334 if (attr
== nullptr)
15337 if (!attr
->form_is_constant ())
15339 complaint (_("DW_AT_alignment must have constant form"
15340 " - DIE at %s [in module %s]"),
15341 sect_offset_str (die
->sect_off
),
15342 objfile_name (cu
->per_objfile
->objfile
));
15346 LONGEST val
= attr
->constant_value (0);
15349 complaint (_("DW_AT_alignment value must not be negative"
15350 " - DIE at %s [in module %s]"),
15351 sect_offset_str (die
->sect_off
),
15352 objfile_name (cu
->per_objfile
->objfile
));
15355 ULONGEST align
= val
;
15359 complaint (_("DW_AT_alignment value must not be zero"
15360 " - DIE at %s [in module %s]"),
15361 sect_offset_str (die
->sect_off
),
15362 objfile_name (cu
->per_objfile
->objfile
));
15365 if ((align
& (align
- 1)) != 0)
15367 complaint (_("DW_AT_alignment value must be a power of 2"
15368 " - DIE at %s [in module %s]"),
15369 sect_offset_str (die
->sect_off
),
15370 objfile_name (cu
->per_objfile
->objfile
));
15377 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15378 the alignment for TYPE. */
15381 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15384 if (!set_type_align (type
, get_alignment (cu
, die
)))
15385 complaint (_("DW_AT_alignment value too large"
15386 " - DIE at %s [in module %s]"),
15387 sect_offset_str (die
->sect_off
),
15388 objfile_name (cu
->per_objfile
->objfile
));
15391 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15392 constant for a type, according to DWARF5 spec, Table 5.5. */
15395 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15400 case DW_CC_pass_by_reference
:
15401 case DW_CC_pass_by_value
:
15405 complaint (_("unrecognized DW_AT_calling_convention value "
15406 "(%s) for a type"), pulongest (value
));
15411 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15412 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15413 also according to GNU-specific values (see include/dwarf2.h). */
15416 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15421 case DW_CC_program
:
15425 case DW_CC_GNU_renesas_sh
:
15426 case DW_CC_GNU_borland_fastcall_i386
:
15427 case DW_CC_GDB_IBM_OpenCL
:
15431 complaint (_("unrecognized DW_AT_calling_convention value "
15432 "(%s) for a subroutine"), pulongest (value
));
15437 /* Called when we find the DIE that starts a structure or union scope
15438 (definition) to create a type for the structure or union. Fill in
15439 the type's name and general properties; the members will not be
15440 processed until process_structure_scope. A symbol table entry for
15441 the type will also not be done until process_structure_scope (assuming
15442 the type has a name).
15444 NOTE: we need to call these functions regardless of whether or not the
15445 DIE has a DW_AT_name attribute, since it might be an anonymous
15446 structure or union. This gets the type entered into our set of
15447 user defined types. */
15449 static struct type
*
15450 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15452 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15454 struct attribute
*attr
;
15457 /* If the definition of this type lives in .debug_types, read that type.
15458 Don't follow DW_AT_specification though, that will take us back up
15459 the chain and we want to go down. */
15460 attr
= die
->attr (DW_AT_signature
);
15461 if (attr
!= nullptr)
15463 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15465 /* The type's CU may not be the same as CU.
15466 Ensure TYPE is recorded with CU in die_type_hash. */
15467 return set_die_type (die
, type
, cu
);
15470 type
= alloc_type (objfile
);
15471 INIT_CPLUS_SPECIFIC (type
);
15473 name
= dwarf2_name (die
, cu
);
15476 if (cu
->language
== language_cplus
15477 || cu
->language
== language_d
15478 || cu
->language
== language_rust
)
15480 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15482 /* dwarf2_full_name might have already finished building the DIE's
15483 type. If so, there is no need to continue. */
15484 if (get_die_type (die
, cu
) != NULL
)
15485 return get_die_type (die
, cu
);
15487 type
->set_name (full_name
);
15491 /* The name is already allocated along with this objfile, so
15492 we don't need to duplicate it for the type. */
15493 type
->set_name (name
);
15497 if (die
->tag
== DW_TAG_structure_type
)
15499 type
->set_code (TYPE_CODE_STRUCT
);
15501 else if (die
->tag
== DW_TAG_union_type
)
15503 type
->set_code (TYPE_CODE_UNION
);
15507 type
->set_code (TYPE_CODE_STRUCT
);
15510 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15511 type
->set_is_declared_class (true);
15513 /* Store the calling convention in the type if it's available in
15514 the die. Otherwise the calling convention remains set to
15515 the default value DW_CC_normal. */
15516 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15517 if (attr
!= nullptr
15518 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15520 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15521 TYPE_CPLUS_CALLING_CONVENTION (type
)
15522 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15525 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15526 if (attr
!= nullptr)
15528 if (attr
->form_is_constant ())
15529 TYPE_LENGTH (type
) = attr
->constant_value (0);
15532 struct dynamic_prop prop
;
15533 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15534 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15535 TYPE_LENGTH (type
) = 0;
15540 TYPE_LENGTH (type
) = 0;
15543 maybe_set_alignment (cu
, die
, type
);
15545 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15547 /* ICC<14 does not output the required DW_AT_declaration on
15548 incomplete types, but gives them a size of zero. */
15549 type
->set_is_stub (true);
15552 type
->set_stub_is_supported (true);
15554 if (die_is_declaration (die
, cu
))
15555 type
->set_is_stub (true);
15556 else if (attr
== NULL
&& die
->child
== NULL
15557 && producer_is_realview (cu
->producer
))
15558 /* RealView does not output the required DW_AT_declaration
15559 on incomplete types. */
15560 type
->set_is_stub (true);
15562 /* We need to add the type field to the die immediately so we don't
15563 infinitely recurse when dealing with pointers to the structure
15564 type within the structure itself. */
15565 set_die_type (die
, type
, cu
);
15567 /* set_die_type should be already done. */
15568 set_descriptive_type (type
, die
, cu
);
15573 static void handle_struct_member_die
15574 (struct die_info
*child_die
,
15576 struct field_info
*fi
,
15577 std::vector
<struct symbol
*> *template_args
,
15578 struct dwarf2_cu
*cu
);
15580 /* A helper for handle_struct_member_die that handles
15581 DW_TAG_variant_part. */
15584 handle_variant_part (struct die_info
*die
, struct type
*type
,
15585 struct field_info
*fi
,
15586 std::vector
<struct symbol
*> *template_args
,
15587 struct dwarf2_cu
*cu
)
15589 variant_part_builder
*new_part
;
15590 if (fi
->current_variant_part
== nullptr)
15592 fi
->variant_parts
.emplace_back ();
15593 new_part
= &fi
->variant_parts
.back ();
15595 else if (!fi
->current_variant_part
->processing_variant
)
15597 complaint (_("nested DW_TAG_variant_part seen "
15598 "- DIE at %s [in module %s]"),
15599 sect_offset_str (die
->sect_off
),
15600 objfile_name (cu
->per_objfile
->objfile
));
15605 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15606 current
.variant_parts
.emplace_back ();
15607 new_part
= ¤t
.variant_parts
.back ();
15610 /* When we recurse, we want callees to add to this new variant
15612 scoped_restore save_current_variant_part
15613 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15615 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15618 /* It's a univariant form, an extension we support. */
15620 else if (discr
->form_is_ref ())
15622 struct dwarf2_cu
*target_cu
= cu
;
15623 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15625 new_part
->discriminant_offset
= target_die
->sect_off
;
15629 complaint (_("DW_AT_discr does not have DIE reference form"
15630 " - DIE at %s [in module %s]"),
15631 sect_offset_str (die
->sect_off
),
15632 objfile_name (cu
->per_objfile
->objfile
));
15635 for (die_info
*child_die
= die
->child
;
15637 child_die
= child_die
->sibling
)
15638 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15641 /* A helper for handle_struct_member_die that handles
15645 handle_variant (struct die_info
*die
, struct type
*type
,
15646 struct field_info
*fi
,
15647 std::vector
<struct symbol
*> *template_args
,
15648 struct dwarf2_cu
*cu
)
15650 if (fi
->current_variant_part
== nullptr)
15652 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15653 "- DIE at %s [in module %s]"),
15654 sect_offset_str (die
->sect_off
),
15655 objfile_name (cu
->per_objfile
->objfile
));
15658 if (fi
->current_variant_part
->processing_variant
)
15660 complaint (_("nested DW_TAG_variant seen "
15661 "- DIE at %s [in module %s]"),
15662 sect_offset_str (die
->sect_off
),
15663 objfile_name (cu
->per_objfile
->objfile
));
15667 scoped_restore save_processing_variant
15668 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15671 fi
->current_variant_part
->variants
.emplace_back ();
15672 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15673 variant
.first_field
= fi
->fields
.size ();
15675 /* In a variant we want to get the discriminant and also add a
15676 field for our sole member child. */
15677 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15678 if (discr
== nullptr || !discr
->form_is_constant ())
15680 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15681 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15682 variant
.default_branch
= true;
15684 variant
.discr_list_data
= discr
->as_block ();
15687 variant
.discriminant_value
= discr
->constant_value (0);
15689 for (die_info
*variant_child
= die
->child
;
15690 variant_child
!= NULL
;
15691 variant_child
= variant_child
->sibling
)
15692 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15694 variant
.last_field
= fi
->fields
.size ();
15697 /* A helper for process_structure_scope that handles a single member
15701 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15702 struct field_info
*fi
,
15703 std::vector
<struct symbol
*> *template_args
,
15704 struct dwarf2_cu
*cu
)
15706 if (child_die
->tag
== DW_TAG_member
15707 || child_die
->tag
== DW_TAG_variable
)
15709 /* NOTE: carlton/2002-11-05: A C++ static data member
15710 should be a DW_TAG_member that is a declaration, but
15711 all versions of G++ as of this writing (so through at
15712 least 3.2.1) incorrectly generate DW_TAG_variable
15713 tags for them instead. */
15714 dwarf2_add_field (fi
, child_die
, cu
);
15716 else if (child_die
->tag
== DW_TAG_subprogram
)
15718 /* Rust doesn't have member functions in the C++ sense.
15719 However, it does emit ordinary functions as children
15720 of a struct DIE. */
15721 if (cu
->language
== language_rust
)
15722 read_func_scope (child_die
, cu
);
15725 /* C++ member function. */
15726 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15729 else if (child_die
->tag
== DW_TAG_inheritance
)
15731 /* C++ base class field. */
15732 dwarf2_add_field (fi
, child_die
, cu
);
15734 else if (type_can_define_types (child_die
))
15735 dwarf2_add_type_defn (fi
, child_die
, cu
);
15736 else if (child_die
->tag
== DW_TAG_template_type_param
15737 || child_die
->tag
== DW_TAG_template_value_param
)
15739 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15742 template_args
->push_back (arg
);
15744 else if (child_die
->tag
== DW_TAG_variant_part
)
15745 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15746 else if (child_die
->tag
== DW_TAG_variant
)
15747 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15750 /* Finish creating a structure or union type, including filling in
15751 its members and creating a symbol for it. */
15754 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15756 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15757 struct die_info
*child_die
;
15760 type
= get_die_type (die
, cu
);
15762 type
= read_structure_type (die
, cu
);
15764 bool has_template_parameters
= false;
15765 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15767 struct field_info fi
;
15768 std::vector
<struct symbol
*> template_args
;
15770 child_die
= die
->child
;
15772 while (child_die
&& child_die
->tag
)
15774 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15775 child_die
= child_die
->sibling
;
15778 /* Attach template arguments to type. */
15779 if (!template_args
.empty ())
15781 has_template_parameters
= true;
15782 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15783 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15784 TYPE_TEMPLATE_ARGUMENTS (type
)
15785 = XOBNEWVEC (&objfile
->objfile_obstack
,
15787 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15788 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15789 template_args
.data (),
15790 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15791 * sizeof (struct symbol
*)));
15794 /* Attach fields and member functions to the type. */
15795 if (fi
.nfields () > 0)
15796 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15797 if (!fi
.fnfieldlists
.empty ())
15799 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15801 /* Get the type which refers to the base class (possibly this
15802 class itself) which contains the vtable pointer for the current
15803 class from the DW_AT_containing_type attribute. This use of
15804 DW_AT_containing_type is a GNU extension. */
15806 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15808 struct type
*t
= die_containing_type (die
, cu
);
15810 set_type_vptr_basetype (type
, t
);
15815 /* Our own class provides vtbl ptr. */
15816 for (i
= t
->num_fields () - 1;
15817 i
>= TYPE_N_BASECLASSES (t
);
15820 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15822 if (is_vtable_name (fieldname
, cu
))
15824 set_type_vptr_fieldno (type
, i
);
15829 /* Complain if virtual function table field not found. */
15830 if (i
< TYPE_N_BASECLASSES (t
))
15831 complaint (_("virtual function table pointer "
15832 "not found when defining class '%s'"),
15833 type
->name () ? type
->name () : "");
15837 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15840 else if (cu
->producer
15841 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15843 /* The IBM XLC compiler does not provide direct indication
15844 of the containing type, but the vtable pointer is
15845 always named __vfp. */
15849 for (i
= type
->num_fields () - 1;
15850 i
>= TYPE_N_BASECLASSES (type
);
15853 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15855 set_type_vptr_fieldno (type
, i
);
15856 set_type_vptr_basetype (type
, type
);
15863 /* Copy fi.typedef_field_list linked list elements content into the
15864 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15865 if (!fi
.typedef_field_list
.empty ())
15867 int count
= fi
.typedef_field_list
.size ();
15869 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15870 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15871 = ((struct decl_field
*)
15873 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15874 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15876 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15877 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15880 /* Copy fi.nested_types_list linked list elements content into the
15881 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15882 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15884 int count
= fi
.nested_types_list
.size ();
15886 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15887 TYPE_NESTED_TYPES_ARRAY (type
)
15888 = ((struct decl_field
*)
15889 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15890 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15892 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15893 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15897 quirk_gcc_member_function_pointer (type
, objfile
);
15898 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15899 cu
->rust_unions
.push_back (type
);
15900 else if (cu
->language
== language_ada
)
15901 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15903 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15904 snapshots) has been known to create a die giving a declaration
15905 for a class that has, as a child, a die giving a definition for a
15906 nested class. So we have to process our children even if the
15907 current die is a declaration. Normally, of course, a declaration
15908 won't have any children at all. */
15910 child_die
= die
->child
;
15912 while (child_die
!= NULL
&& child_die
->tag
)
15914 if (child_die
->tag
== DW_TAG_member
15915 || child_die
->tag
== DW_TAG_variable
15916 || child_die
->tag
== DW_TAG_inheritance
15917 || child_die
->tag
== DW_TAG_template_value_param
15918 || child_die
->tag
== DW_TAG_template_type_param
)
15923 process_die (child_die
, cu
);
15925 child_die
= child_die
->sibling
;
15928 /* Do not consider external references. According to the DWARF standard,
15929 these DIEs are identified by the fact that they have no byte_size
15930 attribute, and a declaration attribute. */
15931 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15932 || !die_is_declaration (die
, cu
)
15933 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15935 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15937 if (has_template_parameters
)
15939 struct symtab
*symtab
;
15940 if (sym
!= nullptr)
15941 symtab
= symbol_symtab (sym
);
15942 else if (cu
->line_header
!= nullptr)
15944 /* Any related symtab will do. */
15946 = cu
->line_header
->file_names ()[0].symtab
;
15951 complaint (_("could not find suitable "
15952 "symtab for template parameter"
15953 " - DIE at %s [in module %s]"),
15954 sect_offset_str (die
->sect_off
),
15955 objfile_name (objfile
));
15958 if (symtab
!= nullptr)
15960 /* Make sure that the symtab is set on the new symbols.
15961 Even though they don't appear in this symtab directly,
15962 other parts of gdb assume that symbols do, and this is
15963 reasonably true. */
15964 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15965 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15971 /* Assuming DIE is an enumeration type, and TYPE is its associated
15972 type, update TYPE using some information only available in DIE's
15973 children. In particular, the fields are computed. */
15976 update_enumeration_type_from_children (struct die_info
*die
,
15978 struct dwarf2_cu
*cu
)
15980 struct die_info
*child_die
;
15981 int unsigned_enum
= 1;
15984 auto_obstack obstack
;
15985 std::vector
<struct field
> fields
;
15987 for (child_die
= die
->child
;
15988 child_die
!= NULL
&& child_die
->tag
;
15989 child_die
= child_die
->sibling
)
15991 struct attribute
*attr
;
15993 const gdb_byte
*bytes
;
15994 struct dwarf2_locexpr_baton
*baton
;
15997 if (child_die
->tag
!= DW_TAG_enumerator
)
16000 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16004 name
= dwarf2_name (child_die
, cu
);
16006 name
= "<anonymous enumerator>";
16008 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16009 &value
, &bytes
, &baton
);
16017 if (count_one_bits_ll (value
) >= 2)
16021 fields
.emplace_back ();
16022 struct field
&field
= fields
.back ();
16023 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16024 SET_FIELD_ENUMVAL (field
, value
);
16027 if (!fields
.empty ())
16029 type
->set_num_fields (fields
.size ());
16032 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16033 memcpy (type
->fields (), fields
.data (),
16034 sizeof (struct field
) * fields
.size ());
16038 type
->set_is_unsigned (true);
16041 type
->set_is_flag_enum (true);
16044 /* Given a DW_AT_enumeration_type die, set its type. We do not
16045 complete the type's fields yet, or create any symbols. */
16047 static struct type
*
16048 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16050 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16052 struct attribute
*attr
;
16055 /* If the definition of this type lives in .debug_types, read that type.
16056 Don't follow DW_AT_specification though, that will take us back up
16057 the chain and we want to go down. */
16058 attr
= die
->attr (DW_AT_signature
);
16059 if (attr
!= nullptr)
16061 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16063 /* The type's CU may not be the same as CU.
16064 Ensure TYPE is recorded with CU in die_type_hash. */
16065 return set_die_type (die
, type
, cu
);
16068 type
= alloc_type (objfile
);
16070 type
->set_code (TYPE_CODE_ENUM
);
16071 name
= dwarf2_full_name (NULL
, die
, cu
);
16073 type
->set_name (name
);
16075 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16078 struct type
*underlying_type
= die_type (die
, cu
);
16080 TYPE_TARGET_TYPE (type
) = underlying_type
;
16083 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16084 if (attr
!= nullptr)
16086 TYPE_LENGTH (type
) = attr
->constant_value (0);
16090 TYPE_LENGTH (type
) = 0;
16093 maybe_set_alignment (cu
, die
, type
);
16095 /* The enumeration DIE can be incomplete. In Ada, any type can be
16096 declared as private in the package spec, and then defined only
16097 inside the package body. Such types are known as Taft Amendment
16098 Types. When another package uses such a type, an incomplete DIE
16099 may be generated by the compiler. */
16100 if (die_is_declaration (die
, cu
))
16101 type
->set_is_stub (true);
16103 /* If this type has an underlying type that is not a stub, then we
16104 may use its attributes. We always use the "unsigned" attribute
16105 in this situation, because ordinarily we guess whether the type
16106 is unsigned -- but the guess can be wrong and the underlying type
16107 can tell us the reality. However, we defer to a local size
16108 attribute if one exists, because this lets the compiler override
16109 the underlying type if needed. */
16110 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16112 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16113 underlying_type
= check_typedef (underlying_type
);
16115 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16117 if (TYPE_LENGTH (type
) == 0)
16118 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16120 if (TYPE_RAW_ALIGN (type
) == 0
16121 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16122 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16125 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16127 set_die_type (die
, type
, cu
);
16129 /* Finish the creation of this type by using the enum's children.
16130 Note that, as usual, this must come after set_die_type to avoid
16131 infinite recursion when trying to compute the names of the
16133 update_enumeration_type_from_children (die
, type
, cu
);
16138 /* Given a pointer to a die which begins an enumeration, process all
16139 the dies that define the members of the enumeration, and create the
16140 symbol for the enumeration type.
16142 NOTE: We reverse the order of the element list. */
16145 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16147 struct type
*this_type
;
16149 this_type
= get_die_type (die
, cu
);
16150 if (this_type
== NULL
)
16151 this_type
= read_enumeration_type (die
, cu
);
16153 if (die
->child
!= NULL
)
16155 struct die_info
*child_die
;
16158 child_die
= die
->child
;
16159 while (child_die
&& child_die
->tag
)
16161 if (child_die
->tag
!= DW_TAG_enumerator
)
16163 process_die (child_die
, cu
);
16167 name
= dwarf2_name (child_die
, cu
);
16169 new_symbol (child_die
, this_type
, cu
);
16172 child_die
= child_die
->sibling
;
16176 /* If we are reading an enum from a .debug_types unit, and the enum
16177 is a declaration, and the enum is not the signatured type in the
16178 unit, then we do not want to add a symbol for it. Adding a
16179 symbol would in some cases obscure the true definition of the
16180 enum, giving users an incomplete type when the definition is
16181 actually available. Note that we do not want to do this for all
16182 enums which are just declarations, because C++0x allows forward
16183 enum declarations. */
16184 if (cu
->per_cu
->is_debug_types
16185 && die_is_declaration (die
, cu
))
16187 struct signatured_type
*sig_type
;
16189 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16190 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16191 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16195 new_symbol (die
, this_type
, cu
);
16198 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16199 expression for an index type and finds the corresponding field
16200 offset in the hidden "P_BOUNDS" structure. Returns true on success
16201 and updates *FIELD, false if it fails to recognize an
16205 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16206 int *bounds_offset
, struct field
*field
,
16207 struct dwarf2_cu
*cu
)
16209 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16210 if (attr
== nullptr || !attr
->form_is_block ())
16213 const struct dwarf_block
*block
= attr
->as_block ();
16214 const gdb_byte
*start
= block
->data
;
16215 const gdb_byte
*end
= block
->data
+ block
->size
;
16217 /* The expression to recognize generally looks like:
16219 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16220 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16222 However, the second "plus_uconst" may be missing:
16224 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16225 DW_OP_deref_size: 4)
16227 This happens when the field is at the start of the structure.
16229 Also, the final deref may not be sized:
16231 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16234 This happens when the size of the index type happens to be the
16235 same as the architecture's word size. This can occur with or
16236 without the second plus_uconst. */
16238 if (end
- start
< 2)
16240 if (*start
++ != DW_OP_push_object_address
)
16242 if (*start
++ != DW_OP_plus_uconst
)
16245 uint64_t this_bound_off
;
16246 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16247 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16249 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16250 is consistent among all bounds. */
16251 if (*bounds_offset
== -1)
16252 *bounds_offset
= this_bound_off
;
16253 else if (*bounds_offset
!= this_bound_off
)
16256 if (start
== end
|| *start
++ != DW_OP_deref
)
16262 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16264 /* This means an offset of 0. */
16266 else if (*start
++ != DW_OP_plus_uconst
)
16270 /* The size is the parameter to DW_OP_plus_uconst. */
16272 start
= gdb_read_uleb128 (start
, end
, &val
);
16273 if (start
== nullptr)
16275 if ((int) val
!= val
)
16284 if (*start
== DW_OP_deref_size
)
16286 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16287 if (start
== nullptr)
16290 else if (*start
== DW_OP_deref
)
16292 size
= cu
->header
.addr_size
;
16298 SET_FIELD_BITPOS (*field
, 8 * offset
);
16299 if (size
!= TYPE_LENGTH (field
->type ()))
16300 FIELD_BITSIZE (*field
) = 8 * size
;
16305 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16306 some kinds of Ada arrays:
16308 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16309 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16310 <11e0> DW_AT_data_location: 2 byte block: 97 6
16311 (DW_OP_push_object_address; DW_OP_deref)
16312 <11e3> DW_AT_type : <0x1173>
16313 <11e7> DW_AT_sibling : <0x1201>
16314 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16315 <11ec> DW_AT_type : <0x1206>
16316 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16317 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16318 DW_OP_deref_size: 4)
16319 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16320 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16321 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16323 This actually represents a "thick pointer", which is a structure
16324 with two elements: one that is a pointer to the array data, and one
16325 that is a pointer to another structure; this second structure holds
16328 This returns a new type on success, or nullptr if this didn't
16329 recognize the type. */
16331 static struct type
*
16332 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16335 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16336 /* So far we've only seen this with block form. */
16337 if (attr
== nullptr || !attr
->form_is_block ())
16340 /* Note that this will fail if the structure layout is changed by
16341 the compiler. However, we have no good way to recognize some
16342 other layout, because we don't know what expression the compiler
16343 might choose to emit should this happen. */
16344 struct dwarf_block
*blk
= attr
->as_block ();
16346 || blk
->data
[0] != DW_OP_push_object_address
16347 || blk
->data
[1] != DW_OP_deref
)
16350 int bounds_offset
= -1;
16351 int max_align
= -1;
16352 std::vector
<struct field
> range_fields
;
16353 for (struct die_info
*child_die
= die
->child
;
16355 child_die
= child_die
->sibling
)
16357 if (child_die
->tag
== DW_TAG_subrange_type
)
16359 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16361 int this_align
= type_align (underlying
);
16362 if (this_align
> max_align
)
16363 max_align
= this_align
;
16365 range_fields
.emplace_back ();
16366 range_fields
.emplace_back ();
16368 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16369 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16371 lower
.set_type (underlying
);
16372 FIELD_ARTIFICIAL (lower
) = 1;
16374 upper
.set_type (underlying
);
16375 FIELD_ARTIFICIAL (upper
) = 1;
16377 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16378 &bounds_offset
, &lower
, cu
)
16379 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16380 &bounds_offset
, &upper
, cu
))
16385 /* This shouldn't really happen, but double-check that we found
16386 where the bounds are stored. */
16387 if (bounds_offset
== -1)
16390 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16391 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16395 /* Set the name of each field in the bounds. */
16396 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16397 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16398 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16399 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16402 struct type
*bounds
= alloc_type (objfile
);
16403 bounds
->set_code (TYPE_CODE_STRUCT
);
16405 bounds
->set_num_fields (range_fields
.size ());
16407 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16408 * sizeof (struct field
))));
16409 memcpy (bounds
->fields (), range_fields
.data (),
16410 bounds
->num_fields () * sizeof (struct field
));
16412 int last_fieldno
= range_fields
.size () - 1;
16413 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16414 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16415 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16417 /* Rewrite the existing array type in place. Specifically, we
16418 remove any dynamic properties we might have read, and we replace
16419 the index types. */
16420 struct type
*iter
= type
;
16421 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16423 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16424 iter
->main_type
->dyn_prop_list
= nullptr;
16425 iter
->set_index_type
16426 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16427 iter
= TYPE_TARGET_TYPE (iter
);
16430 struct type
*result
= alloc_type (objfile
);
16431 result
->set_code (TYPE_CODE_STRUCT
);
16433 result
->set_num_fields (2);
16435 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16436 * sizeof (struct field
))));
16438 /* The names are chosen to coincide with what the compiler does with
16439 -fgnat-encodings=all, which the Ada code in gdb already
16441 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16442 result
->field (0).set_type (lookup_pointer_type (type
));
16444 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16445 result
->field (1).set_type (lookup_pointer_type (bounds
));
16446 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16448 result
->set_name (type
->name ());
16449 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16450 + TYPE_LENGTH (result
->field (1).type ()));
16455 /* Extract all information from a DW_TAG_array_type DIE and put it in
16456 the DIE's type field. For now, this only handles one dimensional
16459 static struct type
*
16460 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16462 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16463 struct die_info
*child_die
;
16465 struct type
*element_type
, *range_type
, *index_type
;
16466 struct attribute
*attr
;
16468 struct dynamic_prop
*byte_stride_prop
= NULL
;
16469 unsigned int bit_stride
= 0;
16471 element_type
= die_type (die
, cu
);
16473 /* The die_type call above may have already set the type for this DIE. */
16474 type
= get_die_type (die
, cu
);
16478 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16482 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16485 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16486 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16490 complaint (_("unable to read array DW_AT_byte_stride "
16491 " - DIE at %s [in module %s]"),
16492 sect_offset_str (die
->sect_off
),
16493 objfile_name (cu
->per_objfile
->objfile
));
16494 /* Ignore this attribute. We will likely not be able to print
16495 arrays of this type correctly, but there is little we can do
16496 to help if we cannot read the attribute's value. */
16497 byte_stride_prop
= NULL
;
16501 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16503 bit_stride
= attr
->constant_value (0);
16505 /* Irix 6.2 native cc creates array types without children for
16506 arrays with unspecified length. */
16507 if (die
->child
== NULL
)
16509 index_type
= objfile_type (objfile
)->builtin_int
;
16510 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16511 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16512 byte_stride_prop
, bit_stride
);
16513 return set_die_type (die
, type
, cu
);
16516 std::vector
<struct type
*> range_types
;
16517 child_die
= die
->child
;
16518 while (child_die
&& child_die
->tag
)
16520 if (child_die
->tag
== DW_TAG_subrange_type
)
16522 struct type
*child_type
= read_type_die (child_die
, cu
);
16524 if (child_type
!= NULL
)
16526 /* The range type was succesfully read. Save it for the
16527 array type creation. */
16528 range_types
.push_back (child_type
);
16531 child_die
= child_die
->sibling
;
16534 if (range_types
.empty ())
16536 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16537 sect_offset_str (die
->sect_off
),
16538 objfile_name (cu
->per_objfile
->objfile
));
16542 /* Dwarf2 dimensions are output from left to right, create the
16543 necessary array types in backwards order. */
16545 type
= element_type
;
16547 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16551 while (i
< range_types
.size ())
16553 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16554 byte_stride_prop
, bit_stride
);
16556 byte_stride_prop
= nullptr;
16561 size_t ndim
= range_types
.size ();
16564 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16565 byte_stride_prop
, bit_stride
);
16567 byte_stride_prop
= nullptr;
16571 gdb_assert (type
!= element_type
);
16573 /* Understand Dwarf2 support for vector types (like they occur on
16574 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16575 array type. This is not part of the Dwarf2/3 standard yet, but a
16576 custom vendor extension. The main difference between a regular
16577 array and the vector variant is that vectors are passed by value
16579 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16580 if (attr
!= nullptr)
16581 make_vector_type (type
);
16583 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16584 implementation may choose to implement triple vectors using this
16586 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16587 if (attr
!= nullptr && attr
->form_is_unsigned ())
16589 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16590 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16592 complaint (_("DW_AT_byte_size for array type smaller "
16593 "than the total size of elements"));
16596 name
= dwarf2_name (die
, cu
);
16598 type
->set_name (name
);
16600 maybe_set_alignment (cu
, die
, type
);
16602 struct type
*replacement_type
= nullptr;
16603 if (cu
->language
== language_ada
)
16605 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16606 if (replacement_type
!= nullptr)
16607 type
= replacement_type
;
16610 /* Install the type in the die. */
16611 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16613 /* set_die_type should be already done. */
16614 set_descriptive_type (type
, die
, cu
);
16619 static enum dwarf_array_dim_ordering
16620 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16622 struct attribute
*attr
;
16624 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16626 if (attr
!= nullptr)
16628 LONGEST val
= attr
->constant_value (-1);
16629 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16630 return (enum dwarf_array_dim_ordering
) val
;
16633 /* GNU F77 is a special case, as at 08/2004 array type info is the
16634 opposite order to the dwarf2 specification, but data is still
16635 laid out as per normal fortran.
16637 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16638 version checking. */
16640 if (cu
->language
== language_fortran
16641 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16643 return DW_ORD_row_major
;
16646 switch (cu
->language_defn
->array_ordering ())
16648 case array_column_major
:
16649 return DW_ORD_col_major
;
16650 case array_row_major
:
16652 return DW_ORD_row_major
;
16656 /* Extract all information from a DW_TAG_set_type DIE and put it in
16657 the DIE's type field. */
16659 static struct type
*
16660 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16662 struct type
*domain_type
, *set_type
;
16663 struct attribute
*attr
;
16665 domain_type
= die_type (die
, cu
);
16667 /* The die_type call above may have already set the type for this DIE. */
16668 set_type
= get_die_type (die
, cu
);
16672 set_type
= create_set_type (NULL
, domain_type
);
16674 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16675 if (attr
!= nullptr && attr
->form_is_unsigned ())
16676 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16678 maybe_set_alignment (cu
, die
, set_type
);
16680 return set_die_type (die
, set_type
, cu
);
16683 /* A helper for read_common_block that creates a locexpr baton.
16684 SYM is the symbol which we are marking as computed.
16685 COMMON_DIE is the DIE for the common block.
16686 COMMON_LOC is the location expression attribute for the common
16688 MEMBER_LOC is the location expression attribute for the particular
16689 member of the common block that we are processing.
16690 CU is the CU from which the above come. */
16693 mark_common_block_symbol_computed (struct symbol
*sym
,
16694 struct die_info
*common_die
,
16695 struct attribute
*common_loc
,
16696 struct attribute
*member_loc
,
16697 struct dwarf2_cu
*cu
)
16699 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16700 struct objfile
*objfile
= per_objfile
->objfile
;
16701 struct dwarf2_locexpr_baton
*baton
;
16703 unsigned int cu_off
;
16704 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16705 LONGEST offset
= 0;
16707 gdb_assert (common_loc
&& member_loc
);
16708 gdb_assert (common_loc
->form_is_block ());
16709 gdb_assert (member_loc
->form_is_block ()
16710 || member_loc
->form_is_constant ());
16712 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16713 baton
->per_objfile
= per_objfile
;
16714 baton
->per_cu
= cu
->per_cu
;
16715 gdb_assert (baton
->per_cu
);
16717 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16719 if (member_loc
->form_is_constant ())
16721 offset
= member_loc
->constant_value (0);
16722 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16725 baton
->size
+= member_loc
->as_block ()->size
;
16727 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16730 *ptr
++ = DW_OP_call4
;
16731 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16732 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16735 if (member_loc
->form_is_constant ())
16737 *ptr
++ = DW_OP_addr
;
16738 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16739 ptr
+= cu
->header
.addr_size
;
16743 /* We have to copy the data here, because DW_OP_call4 will only
16744 use a DW_AT_location attribute. */
16745 struct dwarf_block
*block
= member_loc
->as_block ();
16746 memcpy (ptr
, block
->data
, block
->size
);
16747 ptr
+= block
->size
;
16750 *ptr
++ = DW_OP_plus
;
16751 gdb_assert (ptr
- baton
->data
== baton
->size
);
16753 SYMBOL_LOCATION_BATON (sym
) = baton
;
16754 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16757 /* Create appropriate locally-scoped variables for all the
16758 DW_TAG_common_block entries. Also create a struct common_block
16759 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16760 is used to separate the common blocks name namespace from regular
16764 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16766 struct attribute
*attr
;
16768 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16769 if (attr
!= nullptr)
16771 /* Support the .debug_loc offsets. */
16772 if (attr
->form_is_block ())
16776 else if (attr
->form_is_section_offset ())
16778 dwarf2_complex_location_expr_complaint ();
16783 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16784 "common block member");
16789 if (die
->child
!= NULL
)
16791 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16792 struct die_info
*child_die
;
16793 size_t n_entries
= 0, size
;
16794 struct common_block
*common_block
;
16795 struct symbol
*sym
;
16797 for (child_die
= die
->child
;
16798 child_die
&& child_die
->tag
;
16799 child_die
= child_die
->sibling
)
16802 size
= (sizeof (struct common_block
)
16803 + (n_entries
- 1) * sizeof (struct symbol
*));
16805 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16807 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16808 common_block
->n_entries
= 0;
16810 for (child_die
= die
->child
;
16811 child_die
&& child_die
->tag
;
16812 child_die
= child_die
->sibling
)
16814 /* Create the symbol in the DW_TAG_common_block block in the current
16816 sym
= new_symbol (child_die
, NULL
, cu
);
16819 struct attribute
*member_loc
;
16821 common_block
->contents
[common_block
->n_entries
++] = sym
;
16823 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16827 /* GDB has handled this for a long time, but it is
16828 not specified by DWARF. It seems to have been
16829 emitted by gfortran at least as recently as:
16830 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16831 complaint (_("Variable in common block has "
16832 "DW_AT_data_member_location "
16833 "- DIE at %s [in module %s]"),
16834 sect_offset_str (child_die
->sect_off
),
16835 objfile_name (objfile
));
16837 if (member_loc
->form_is_section_offset ())
16838 dwarf2_complex_location_expr_complaint ();
16839 else if (member_loc
->form_is_constant ()
16840 || member_loc
->form_is_block ())
16842 if (attr
!= nullptr)
16843 mark_common_block_symbol_computed (sym
, die
, attr
,
16847 dwarf2_complex_location_expr_complaint ();
16852 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16853 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16857 /* Create a type for a C++ namespace. */
16859 static struct type
*
16860 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16862 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16863 const char *previous_prefix
, *name
;
16867 /* For extensions, reuse the type of the original namespace. */
16868 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16870 struct die_info
*ext_die
;
16871 struct dwarf2_cu
*ext_cu
= cu
;
16873 ext_die
= dwarf2_extension (die
, &ext_cu
);
16874 type
= read_type_die (ext_die
, ext_cu
);
16876 /* EXT_CU may not be the same as CU.
16877 Ensure TYPE is recorded with CU in die_type_hash. */
16878 return set_die_type (die
, type
, cu
);
16881 name
= namespace_name (die
, &is_anonymous
, cu
);
16883 /* Now build the name of the current namespace. */
16885 previous_prefix
= determine_prefix (die
, cu
);
16886 if (previous_prefix
[0] != '\0')
16887 name
= typename_concat (&objfile
->objfile_obstack
,
16888 previous_prefix
, name
, 0, cu
);
16890 /* Create the type. */
16891 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16893 return set_die_type (die
, type
, cu
);
16896 /* Read a namespace scope. */
16899 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16901 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16904 /* Add a symbol associated to this if we haven't seen the namespace
16905 before. Also, add a using directive if it's an anonymous
16908 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16912 type
= read_type_die (die
, cu
);
16913 new_symbol (die
, type
, cu
);
16915 namespace_name (die
, &is_anonymous
, cu
);
16918 const char *previous_prefix
= determine_prefix (die
, cu
);
16920 std::vector
<const char *> excludes
;
16921 add_using_directive (using_directives (cu
),
16922 previous_prefix
, type
->name (), NULL
,
16923 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16927 if (die
->child
!= NULL
)
16929 struct die_info
*child_die
= die
->child
;
16931 while (child_die
&& child_die
->tag
)
16933 process_die (child_die
, cu
);
16934 child_die
= child_die
->sibling
;
16939 /* Read a Fortran module as type. This DIE can be only a declaration used for
16940 imported module. Still we need that type as local Fortran "use ... only"
16941 declaration imports depend on the created type in determine_prefix. */
16943 static struct type
*
16944 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16946 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16947 const char *module_name
;
16950 module_name
= dwarf2_name (die
, cu
);
16951 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16953 return set_die_type (die
, type
, cu
);
16956 /* Read a Fortran module. */
16959 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16961 struct die_info
*child_die
= die
->child
;
16964 type
= read_type_die (die
, cu
);
16965 new_symbol (die
, type
, cu
);
16967 while (child_die
&& child_die
->tag
)
16969 process_die (child_die
, cu
);
16970 child_die
= child_die
->sibling
;
16974 /* Return the name of the namespace represented by DIE. Set
16975 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16978 static const char *
16979 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16981 struct die_info
*current_die
;
16982 const char *name
= NULL
;
16984 /* Loop through the extensions until we find a name. */
16986 for (current_die
= die
;
16987 current_die
!= NULL
;
16988 current_die
= dwarf2_extension (die
, &cu
))
16990 /* We don't use dwarf2_name here so that we can detect the absence
16991 of a name -> anonymous namespace. */
16992 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16998 /* Is it an anonymous namespace? */
17000 *is_anonymous
= (name
== NULL
);
17002 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17007 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17008 the user defined type vector. */
17010 static struct type
*
17011 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17013 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17014 struct comp_unit_head
*cu_header
= &cu
->header
;
17016 struct attribute
*attr_byte_size
;
17017 struct attribute
*attr_address_class
;
17018 int byte_size
, addr_class
;
17019 struct type
*target_type
;
17021 target_type
= die_type (die
, cu
);
17023 /* The die_type call above may have already set the type for this DIE. */
17024 type
= get_die_type (die
, cu
);
17028 type
= lookup_pointer_type (target_type
);
17030 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17031 if (attr_byte_size
)
17032 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17034 byte_size
= cu_header
->addr_size
;
17036 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17037 if (attr_address_class
)
17038 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17040 addr_class
= DW_ADDR_none
;
17042 ULONGEST alignment
= get_alignment (cu
, die
);
17044 /* If the pointer size, alignment, or address class is different
17045 than the default, create a type variant marked as such and set
17046 the length accordingly. */
17047 if (TYPE_LENGTH (type
) != byte_size
17048 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17049 && alignment
!= TYPE_RAW_ALIGN (type
))
17050 || addr_class
!= DW_ADDR_none
)
17052 if (gdbarch_address_class_type_flags_p (gdbarch
))
17054 type_instance_flags type_flags
17055 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17057 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17059 type
= make_type_with_address_space (type
, type_flags
);
17061 else if (TYPE_LENGTH (type
) != byte_size
)
17063 complaint (_("invalid pointer size %d"), byte_size
);
17065 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17067 complaint (_("Invalid DW_AT_alignment"
17068 " - DIE at %s [in module %s]"),
17069 sect_offset_str (die
->sect_off
),
17070 objfile_name (cu
->per_objfile
->objfile
));
17074 /* Should we also complain about unhandled address classes? */
17078 TYPE_LENGTH (type
) = byte_size
;
17079 set_type_align (type
, alignment
);
17080 return set_die_type (die
, type
, cu
);
17083 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17084 the user defined type vector. */
17086 static struct type
*
17087 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17090 struct type
*to_type
;
17091 struct type
*domain
;
17093 to_type
= die_type (die
, cu
);
17094 domain
= die_containing_type (die
, cu
);
17096 /* The calls above may have already set the type for this DIE. */
17097 type
= get_die_type (die
, cu
);
17101 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17102 type
= lookup_methodptr_type (to_type
);
17103 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17105 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17107 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17108 to_type
->fields (), to_type
->num_fields (),
17109 to_type
->has_varargs ());
17110 type
= lookup_methodptr_type (new_type
);
17113 type
= lookup_memberptr_type (to_type
, domain
);
17115 return set_die_type (die
, type
, cu
);
17118 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17119 the user defined type vector. */
17121 static struct type
*
17122 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17123 enum type_code refcode
)
17125 struct comp_unit_head
*cu_header
= &cu
->header
;
17126 struct type
*type
, *target_type
;
17127 struct attribute
*attr
;
17129 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17131 target_type
= die_type (die
, cu
);
17133 /* The die_type call above may have already set the type for this DIE. */
17134 type
= get_die_type (die
, cu
);
17138 type
= lookup_reference_type (target_type
, refcode
);
17139 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17140 if (attr
!= nullptr)
17142 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17146 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17148 maybe_set_alignment (cu
, die
, type
);
17149 return set_die_type (die
, type
, cu
);
17152 /* Add the given cv-qualifiers to the element type of the array. GCC
17153 outputs DWARF type qualifiers that apply to an array, not the
17154 element type. But GDB relies on the array element type to carry
17155 the cv-qualifiers. This mimics section 6.7.3 of the C99
17158 static struct type
*
17159 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17160 struct type
*base_type
, int cnst
, int voltl
)
17162 struct type
*el_type
, *inner_array
;
17164 base_type
= copy_type (base_type
);
17165 inner_array
= base_type
;
17167 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17169 TYPE_TARGET_TYPE (inner_array
) =
17170 copy_type (TYPE_TARGET_TYPE (inner_array
));
17171 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17174 el_type
= TYPE_TARGET_TYPE (inner_array
);
17175 cnst
|= TYPE_CONST (el_type
);
17176 voltl
|= TYPE_VOLATILE (el_type
);
17177 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17179 return set_die_type (die
, base_type
, cu
);
17182 static struct type
*
17183 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17185 struct type
*base_type
, *cv_type
;
17187 base_type
= die_type (die
, cu
);
17189 /* The die_type call above may have already set the type for this DIE. */
17190 cv_type
= get_die_type (die
, cu
);
17194 /* In case the const qualifier is applied to an array type, the element type
17195 is so qualified, not the array type (section 6.7.3 of C99). */
17196 if (base_type
->code () == TYPE_CODE_ARRAY
)
17197 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17199 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17200 return set_die_type (die
, cv_type
, cu
);
17203 static struct type
*
17204 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17206 struct type
*base_type
, *cv_type
;
17208 base_type
= die_type (die
, cu
);
17210 /* The die_type call above may have already set the type for this DIE. */
17211 cv_type
= get_die_type (die
, cu
);
17215 /* In case the volatile qualifier is applied to an array type, the
17216 element type is so qualified, not the array type (section 6.7.3
17218 if (base_type
->code () == TYPE_CODE_ARRAY
)
17219 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17221 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17222 return set_die_type (die
, cv_type
, cu
);
17225 /* Handle DW_TAG_restrict_type. */
17227 static struct type
*
17228 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17230 struct type
*base_type
, *cv_type
;
17232 base_type
= die_type (die
, cu
);
17234 /* The die_type call above may have already set the type for this DIE. */
17235 cv_type
= get_die_type (die
, cu
);
17239 cv_type
= make_restrict_type (base_type
);
17240 return set_die_type (die
, cv_type
, cu
);
17243 /* Handle DW_TAG_atomic_type. */
17245 static struct type
*
17246 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17248 struct type
*base_type
, *cv_type
;
17250 base_type
= die_type (die
, cu
);
17252 /* The die_type call above may have already set the type for this DIE. */
17253 cv_type
= get_die_type (die
, cu
);
17257 cv_type
= make_atomic_type (base_type
);
17258 return set_die_type (die
, cv_type
, cu
);
17261 /* Extract all information from a DW_TAG_string_type DIE and add to
17262 the user defined type vector. It isn't really a user defined type,
17263 but it behaves like one, with other DIE's using an AT_user_def_type
17264 attribute to reference it. */
17266 static struct type
*
17267 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17269 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17270 struct gdbarch
*gdbarch
= objfile
->arch ();
17271 struct type
*type
, *range_type
, *index_type
, *char_type
;
17272 struct attribute
*attr
;
17273 struct dynamic_prop prop
;
17274 bool length_is_constant
= true;
17277 /* There are a couple of places where bit sizes might be made use of
17278 when parsing a DW_TAG_string_type, however, no producer that we know
17279 of make use of these. Handling bit sizes that are a multiple of the
17280 byte size is easy enough, but what about other bit sizes? Lets deal
17281 with that problem when we have to. Warn about these attributes being
17282 unsupported, then parse the type and ignore them like we always
17284 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17285 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17287 static bool warning_printed
= false;
17288 if (!warning_printed
)
17290 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17291 "currently supported on DW_TAG_string_type."));
17292 warning_printed
= true;
17296 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17297 if (attr
!= nullptr && !attr
->form_is_constant ())
17299 /* The string length describes the location at which the length of
17300 the string can be found. The size of the length field can be
17301 specified with one of the attributes below. */
17302 struct type
*prop_type
;
17303 struct attribute
*len
17304 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17305 if (len
== nullptr)
17306 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17307 if (len
!= nullptr && len
->form_is_constant ())
17309 /* Pass 0 as the default as we know this attribute is constant
17310 and the default value will not be returned. */
17311 LONGEST sz
= len
->constant_value (0);
17312 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17316 /* If the size is not specified then we assume it is the size of
17317 an address on this target. */
17318 prop_type
= cu
->addr_sized_int_type (true);
17321 /* Convert the attribute into a dynamic property. */
17322 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17325 length_is_constant
= false;
17327 else if (attr
!= nullptr)
17329 /* This DW_AT_string_length just contains the length with no
17330 indirection. There's no need to create a dynamic property in this
17331 case. Pass 0 for the default value as we know it will not be
17332 returned in this case. */
17333 length
= attr
->constant_value (0);
17335 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17337 /* We don't currently support non-constant byte sizes for strings. */
17338 length
= attr
->constant_value (1);
17342 /* Use 1 as a fallback length if we have nothing else. */
17346 index_type
= objfile_type (objfile
)->builtin_int
;
17347 if (length_is_constant
)
17348 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17351 struct dynamic_prop low_bound
;
17353 low_bound
.set_const_val (1);
17354 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17356 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17357 type
= create_string_type (NULL
, char_type
, range_type
);
17359 return set_die_type (die
, type
, cu
);
17362 /* Assuming that DIE corresponds to a function, returns nonzero
17363 if the function is prototyped. */
17366 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17368 struct attribute
*attr
;
17370 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17371 if (attr
&& attr
->as_boolean ())
17374 /* The DWARF standard implies that the DW_AT_prototyped attribute
17375 is only meaningful for C, but the concept also extends to other
17376 languages that allow unprototyped functions (Eg: Objective C).
17377 For all other languages, assume that functions are always
17379 if (cu
->language
!= language_c
17380 && cu
->language
!= language_objc
17381 && cu
->language
!= language_opencl
)
17384 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17385 prototyped and unprototyped functions; default to prototyped,
17386 since that is more common in modern code (and RealView warns
17387 about unprototyped functions). */
17388 if (producer_is_realview (cu
->producer
))
17394 /* Handle DIES due to C code like:
17398 int (*funcp)(int a, long l);
17402 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17404 static struct type
*
17405 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17407 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17408 struct type
*type
; /* Type that this function returns. */
17409 struct type
*ftype
; /* Function that returns above type. */
17410 struct attribute
*attr
;
17412 type
= die_type (die
, cu
);
17414 /* The die_type call above may have already set the type for this DIE. */
17415 ftype
= get_die_type (die
, cu
);
17419 ftype
= lookup_function_type (type
);
17421 if (prototyped_function_p (die
, cu
))
17422 ftype
->set_is_prototyped (true);
17424 /* Store the calling convention in the type if it's available in
17425 the subroutine die. Otherwise set the calling convention to
17426 the default value DW_CC_normal. */
17427 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17428 if (attr
!= nullptr
17429 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17430 TYPE_CALLING_CONVENTION (ftype
)
17431 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17432 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17433 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17435 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17437 /* Record whether the function returns normally to its caller or not
17438 if the DWARF producer set that information. */
17439 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17440 if (attr
&& attr
->as_boolean ())
17441 TYPE_NO_RETURN (ftype
) = 1;
17443 /* We need to add the subroutine type to the die immediately so
17444 we don't infinitely recurse when dealing with parameters
17445 declared as the same subroutine type. */
17446 set_die_type (die
, ftype
, cu
);
17448 if (die
->child
!= NULL
)
17450 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17451 struct die_info
*child_die
;
17452 int nparams
, iparams
;
17454 /* Count the number of parameters.
17455 FIXME: GDB currently ignores vararg functions, but knows about
17456 vararg member functions. */
17458 child_die
= die
->child
;
17459 while (child_die
&& child_die
->tag
)
17461 if (child_die
->tag
== DW_TAG_formal_parameter
)
17463 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17464 ftype
->set_has_varargs (true);
17466 child_die
= child_die
->sibling
;
17469 /* Allocate storage for parameters and fill them in. */
17470 ftype
->set_num_fields (nparams
);
17472 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17474 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17475 even if we error out during the parameters reading below. */
17476 for (iparams
= 0; iparams
< nparams
; iparams
++)
17477 ftype
->field (iparams
).set_type (void_type
);
17480 child_die
= die
->child
;
17481 while (child_die
&& child_die
->tag
)
17483 if (child_die
->tag
== DW_TAG_formal_parameter
)
17485 struct type
*arg_type
;
17487 /* DWARF version 2 has no clean way to discern C++
17488 static and non-static member functions. G++ helps
17489 GDB by marking the first parameter for non-static
17490 member functions (which is the this pointer) as
17491 artificial. We pass this information to
17492 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17494 DWARF version 3 added DW_AT_object_pointer, which GCC
17495 4.5 does not yet generate. */
17496 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17497 if (attr
!= nullptr)
17498 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17500 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17501 arg_type
= die_type (child_die
, cu
);
17503 /* RealView does not mark THIS as const, which the testsuite
17504 expects. GCC marks THIS as const in method definitions,
17505 but not in the class specifications (GCC PR 43053). */
17506 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17507 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17510 struct dwarf2_cu
*arg_cu
= cu
;
17511 const char *name
= dwarf2_name (child_die
, cu
);
17513 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17514 if (attr
!= nullptr)
17516 /* If the compiler emits this, use it. */
17517 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17520 else if (name
&& strcmp (name
, "this") == 0)
17521 /* Function definitions will have the argument names. */
17523 else if (name
== NULL
&& iparams
== 0)
17524 /* Declarations may not have the names, so like
17525 elsewhere in GDB, assume an artificial first
17526 argument is "this". */
17530 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17534 ftype
->field (iparams
).set_type (arg_type
);
17537 child_die
= child_die
->sibling
;
17544 static struct type
*
17545 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17547 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17548 const char *name
= NULL
;
17549 struct type
*this_type
, *target_type
;
17551 name
= dwarf2_full_name (NULL
, die
, cu
);
17552 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17553 this_type
->set_target_is_stub (true);
17554 set_die_type (die
, this_type
, cu
);
17555 target_type
= die_type (die
, cu
);
17556 if (target_type
!= this_type
)
17557 TYPE_TARGET_TYPE (this_type
) = target_type
;
17560 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17561 spec and cause infinite loops in GDB. */
17562 complaint (_("Self-referential DW_TAG_typedef "
17563 "- DIE at %s [in module %s]"),
17564 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17565 TYPE_TARGET_TYPE (this_type
) = NULL
;
17569 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17570 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17571 Handle these by just returning the target type, rather than
17572 constructing an anonymous typedef type and trying to handle this
17574 set_die_type (die
, target_type
, cu
);
17575 return target_type
;
17580 /* Helper for get_dwarf2_rational_constant that computes the value of
17581 a given gmp_mpz given an attribute. */
17584 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17586 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17587 location expression that pushes an implicit value. */
17588 if (attr
->form
== DW_FORM_exprloc
)
17590 dwarf_block
*blk
= attr
->as_block ();
17591 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17594 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17595 blk
->data
+ blk
->size
,
17597 if (ptr
- blk
->data
+ len
<= blk
->size
)
17599 mpz_import (value
->val
, len
,
17600 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17606 /* On failure set it to 1. */
17607 *value
= gdb_mpz (1);
17609 else if (attr
->form_is_block ())
17611 dwarf_block
*blk
= attr
->as_block ();
17612 mpz_import (value
->val
, blk
->size
,
17613 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17614 1, 0, 0, blk
->data
);
17617 *value
= gdb_mpz (attr
->constant_value (1));
17620 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17621 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17623 If the numerator and/or numerator attribute is missing,
17624 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17628 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17629 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17631 struct attribute
*num_attr
, *denom_attr
;
17633 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17634 if (num_attr
== nullptr)
17635 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17636 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17638 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17639 if (denom_attr
== nullptr)
17640 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17641 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17643 if (num_attr
== nullptr || denom_attr
== nullptr)
17646 get_mpz (cu
, numerator
, num_attr
);
17647 get_mpz (cu
, denominator
, denom_attr
);
17650 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17651 rational constant, rather than a signed one.
17653 If the rational constant has a negative value, a complaint
17654 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17657 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17658 struct dwarf2_cu
*cu
,
17659 gdb_mpz
*numerator
,
17660 gdb_mpz
*denominator
)
17665 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17666 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17668 mpz_neg (num
.val
, num
.val
);
17669 mpz_neg (denom
.val
, denom
.val
);
17671 else if (mpz_sgn (num
.val
) == -1)
17673 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17675 sect_offset_str (die
->sect_off
));
17678 else if (mpz_sgn (denom
.val
) == -1)
17680 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17682 sect_offset_str (die
->sect_off
));
17686 *numerator
= std::move (num
);
17687 *denominator
= std::move (denom
);
17690 /* Assuming that ENCODING is a string whose contents starting at the
17691 K'th character is "_nn" where "nn" is a decimal number, scan that
17692 number and set RESULT to the value. K is updated to point to the
17693 character immediately following the number.
17695 If the string does not conform to the format described above, false
17696 is returned, and K may or may not be changed. */
17699 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17701 /* The next character should be an underscore ('_') followed
17703 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17706 /* Skip the underscore. */
17710 /* Determine the number of digits for our number. */
17711 while (isdigit (encoding
[k
]))
17716 std::string
copy (&encoding
[start
], k
- start
);
17717 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17723 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17724 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17725 DENOM, update OFFSET, and return true on success. Return false on
17729 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17730 gdb_mpz
*num
, gdb_mpz
*denom
)
17732 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17734 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17737 /* Assuming DIE corresponds to a fixed point type, finish the creation
17738 of the corresponding TYPE by setting its type-specific data. CU is
17739 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17740 encodings. It is nullptr if the GNAT encoding should be
17744 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17745 struct die_info
*die
, struct dwarf2_cu
*cu
)
17747 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17748 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17750 /* If GNAT encodings are preferred, don't examine the
17752 struct attribute
*attr
= nullptr;
17753 if (suffix
== nullptr)
17755 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17756 if (attr
== nullptr)
17757 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17758 if (attr
== nullptr)
17759 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17762 /* Numerator and denominator of our fixed-point type's scaling factor.
17763 The default is a scaling factor of 1, which we use as a fallback
17764 when we are not able to decode it (problem with the debugging info,
17765 unsupported forms, bug in GDB, etc...). Using that as the default
17766 allows us to at least print the unscaled value, which might still
17767 be useful to a user. */
17768 gdb_mpz
scale_num (1);
17769 gdb_mpz
scale_denom (1);
17771 if (attr
== nullptr)
17774 if (suffix
!= nullptr
17775 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17777 /* The number might be encoded as _nn_dd_nn_dd, where the
17778 second ratio is the 'small value. In this situation, we
17779 want the second value. */
17780 && (suffix
[offset
] != '_'
17781 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17788 /* Scaling factor not found. Assume a scaling factor of 1,
17789 and hope for the best. At least the user will be able to
17790 see the encoded value. */
17793 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17794 sect_offset_str (die
->sect_off
));
17797 else if (attr
->name
== DW_AT_binary_scale
)
17799 LONGEST scale_exp
= attr
->constant_value (0);
17800 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17802 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17804 else if (attr
->name
== DW_AT_decimal_scale
)
17806 LONGEST scale_exp
= attr
->constant_value (0);
17807 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17809 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17811 else if (attr
->name
== DW_AT_small
)
17813 struct die_info
*scale_die
;
17814 struct dwarf2_cu
*scale_cu
= cu
;
17816 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17817 if (scale_die
->tag
== DW_TAG_constant
)
17818 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17819 &scale_num
, &scale_denom
);
17821 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17823 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17827 complaint (_("unsupported scale attribute %s for fixed-point type"
17829 dwarf_attr_name (attr
->name
),
17830 sect_offset_str (die
->sect_off
));
17833 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17834 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17835 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17836 mpq_canonicalize (scaling_factor
.val
);
17839 /* The gnat-encoding suffix for fixed point. */
17841 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17843 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17844 "XF" suffix of the name. The text after this is what encodes the
17845 'small and 'delta information. Otherwise, return nullptr. */
17847 static const char *
17848 gnat_encoded_fixed_point_type_info (const char *name
)
17850 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17853 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17854 (which may be different from NAME) to the architecture back-end to allow
17855 it to guess the correct format if necessary. */
17857 static struct type
*
17858 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17859 const char *name_hint
, enum bfd_endian byte_order
)
17861 struct gdbarch
*gdbarch
= objfile
->arch ();
17862 const struct floatformat
**format
;
17865 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17867 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17869 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17874 /* Allocate an integer type of size BITS and name NAME. */
17876 static struct type
*
17877 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17878 int bits
, int unsigned_p
, const char *name
)
17882 /* Versions of Intel's C Compiler generate an integer type called "void"
17883 instead of using DW_TAG_unspecified_type. This has been seen on
17884 at least versions 14, 17, and 18. */
17885 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17886 && strcmp (name
, "void") == 0)
17887 type
= objfile_type (objfile
)->builtin_void
;
17889 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17894 /* Return true if DIE has a DW_AT_small attribute whose value is
17895 a constant rational, where both the numerator and denominator
17898 CU is the DIE's Compilation Unit. */
17901 has_zero_over_zero_small_attribute (struct die_info
*die
,
17902 struct dwarf2_cu
*cu
)
17904 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17905 if (attr
== nullptr)
17908 struct dwarf2_cu
*scale_cu
= cu
;
17909 struct die_info
*scale_die
17910 = follow_die_ref (die
, attr
, &scale_cu
);
17912 if (scale_die
->tag
!= DW_TAG_constant
)
17915 gdb_mpz
num (1), denom (1);
17916 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
17917 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
17920 /* Initialise and return a floating point type of size BITS suitable for
17921 use as a component of a complex number. The NAME_HINT is passed through
17922 when initialising the floating point type and is the name of the complex
17925 As DWARF doesn't currently provide an explicit name for the components
17926 of a complex number, but it can be helpful to have these components
17927 named, we try to select a suitable name based on the size of the
17929 static struct type
*
17930 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17931 struct objfile
*objfile
,
17932 int bits
, const char *name_hint
,
17933 enum bfd_endian byte_order
)
17935 gdbarch
*gdbarch
= objfile
->arch ();
17936 struct type
*tt
= nullptr;
17938 /* Try to find a suitable floating point builtin type of size BITS.
17939 We're going to use the name of this type as the name for the complex
17940 target type that we are about to create. */
17941 switch (cu
->language
)
17943 case language_fortran
:
17947 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17950 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17952 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17954 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17962 tt
= builtin_type (gdbarch
)->builtin_float
;
17965 tt
= builtin_type (gdbarch
)->builtin_double
;
17967 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17969 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17975 /* If the type we found doesn't match the size we were looking for, then
17976 pretend we didn't find a type at all, the complex target type we
17977 create will then be nameless. */
17978 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17981 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17982 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17985 /* Find a representation of a given base type and install
17986 it in the TYPE field of the die. */
17988 static struct type
*
17989 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17991 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17993 struct attribute
*attr
;
17994 int encoding
= 0, bits
= 0;
17998 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17999 if (attr
!= nullptr && attr
->form_is_constant ())
18000 encoding
= attr
->constant_value (0);
18001 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18002 if (attr
!= nullptr)
18003 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18004 name
= dwarf2_name (die
, cu
);
18006 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18008 arch
= objfile
->arch ();
18009 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18011 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18012 if (attr
!= nullptr && attr
->form_is_constant ())
18014 int endianity
= attr
->constant_value (0);
18019 byte_order
= BFD_ENDIAN_BIG
;
18021 case DW_END_little
:
18022 byte_order
= BFD_ENDIAN_LITTLE
;
18025 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18030 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18031 && cu
->language
== language_ada
18032 && has_zero_over_zero_small_attribute (die
, cu
))
18034 /* brobecker/2018-02-24: This is a fixed point type for which
18035 the scaling factor is represented as fraction whose value
18036 does not make sense (zero divided by zero), so we should
18037 normally never see these. However, there is a small category
18038 of fixed point types for which GNAT is unable to provide
18039 the scaling factor via the standard DWARF mechanisms, and
18040 for which the info is provided via the GNAT encodings instead.
18041 This is likely what this DIE is about. */
18042 encoding
= (encoding
== DW_ATE_signed_fixed
18044 : DW_ATE_unsigned
);
18047 /* With GNAT encodings, fixed-point information will be encoded in
18048 the type name. Note that this can also occur with the above
18049 zero-over-zero case, which is why this is a separate "if" rather
18050 than an "else if". */
18051 const char *gnat_encoding_suffix
= nullptr;
18052 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18053 && cu
->language
== language_ada
18054 && name
!= nullptr)
18056 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18057 if (gnat_encoding_suffix
!= nullptr)
18059 gdb_assert (startswith (gnat_encoding_suffix
,
18060 GNAT_FIXED_POINT_SUFFIX
));
18061 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18062 name
, gnat_encoding_suffix
- name
);
18063 /* Use -1 here so that SUFFIX points at the "_" after the
18065 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18067 encoding
= (encoding
== DW_ATE_signed
18068 ? DW_ATE_signed_fixed
18069 : DW_ATE_unsigned_fixed
);
18075 case DW_ATE_address
:
18076 /* Turn DW_ATE_address into a void * pointer. */
18077 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18078 type
= init_pointer_type (objfile
, bits
, name
, type
);
18080 case DW_ATE_boolean
:
18081 type
= init_boolean_type (objfile
, bits
, 1, name
);
18083 case DW_ATE_complex_float
:
18084 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18086 if (type
->code () == TYPE_CODE_ERROR
)
18088 if (name
== nullptr)
18090 struct obstack
*obstack
18091 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18092 name
= obconcat (obstack
, "_Complex ", type
->name (),
18095 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18098 type
= init_complex_type (name
, type
);
18100 case DW_ATE_decimal_float
:
18101 type
= init_decfloat_type (objfile
, bits
, name
);
18104 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18106 case DW_ATE_signed
:
18107 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18109 case DW_ATE_unsigned
:
18110 if (cu
->language
== language_fortran
18112 && startswith (name
, "character("))
18113 type
= init_character_type (objfile
, bits
, 1, name
);
18115 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18117 case DW_ATE_signed_char
:
18118 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18119 || cu
->language
== language_pascal
18120 || cu
->language
== language_fortran
)
18121 type
= init_character_type (objfile
, bits
, 0, name
);
18123 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18125 case DW_ATE_unsigned_char
:
18126 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18127 || cu
->language
== language_pascal
18128 || cu
->language
== language_fortran
18129 || cu
->language
== language_rust
)
18130 type
= init_character_type (objfile
, bits
, 1, name
);
18132 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18137 type
= builtin_type (arch
)->builtin_char16
;
18138 else if (bits
== 32)
18139 type
= builtin_type (arch
)->builtin_char32
;
18142 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18144 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18146 return set_die_type (die
, type
, cu
);
18149 case DW_ATE_signed_fixed
:
18150 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18151 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18153 case DW_ATE_unsigned_fixed
:
18154 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18155 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18159 complaint (_("unsupported DW_AT_encoding: '%s'"),
18160 dwarf_type_encoding_name (encoding
));
18161 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18165 if (name
&& strcmp (name
, "char") == 0)
18166 type
->set_has_no_signedness (true);
18168 maybe_set_alignment (cu
, die
, type
);
18170 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18172 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18174 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18175 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18177 unsigned real_bit_size
= attr
->as_unsigned ();
18178 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18179 /* Only use the attributes if they make sense together. */
18180 if (attr
== nullptr
18181 || (attr
->as_unsigned () + real_bit_size
18182 <= 8 * TYPE_LENGTH (type
)))
18184 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18186 if (attr
!= nullptr)
18187 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18188 = attr
->as_unsigned ();
18193 return set_die_type (die
, type
, cu
);
18196 /* Parse dwarf attribute if it's a block, reference or constant and put the
18197 resulting value of the attribute into struct bound_prop.
18198 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18201 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18202 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18203 struct type
*default_type
)
18205 struct dwarf2_property_baton
*baton
;
18206 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18207 struct objfile
*objfile
= per_objfile
->objfile
;
18208 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18210 gdb_assert (default_type
!= NULL
);
18212 if (attr
== NULL
|| prop
== NULL
)
18215 if (attr
->form_is_block ())
18217 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18218 baton
->property_type
= default_type
;
18219 baton
->locexpr
.per_cu
= cu
->per_cu
;
18220 baton
->locexpr
.per_objfile
= per_objfile
;
18222 struct dwarf_block
*block
= attr
->as_block ();
18223 baton
->locexpr
.size
= block
->size
;
18224 baton
->locexpr
.data
= block
->data
;
18225 switch (attr
->name
)
18227 case DW_AT_string_length
:
18228 baton
->locexpr
.is_reference
= true;
18231 baton
->locexpr
.is_reference
= false;
18235 prop
->set_locexpr (baton
);
18236 gdb_assert (prop
->baton () != NULL
);
18238 else if (attr
->form_is_ref ())
18240 struct dwarf2_cu
*target_cu
= cu
;
18241 struct die_info
*target_die
;
18242 struct attribute
*target_attr
;
18244 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18245 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18246 if (target_attr
== NULL
)
18247 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18249 if (target_attr
== NULL
)
18252 switch (target_attr
->name
)
18254 case DW_AT_location
:
18255 if (target_attr
->form_is_section_offset ())
18257 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18258 baton
->property_type
= die_type (target_die
, target_cu
);
18259 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18260 prop
->set_loclist (baton
);
18261 gdb_assert (prop
->baton () != NULL
);
18263 else if (target_attr
->form_is_block ())
18265 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18266 baton
->property_type
= die_type (target_die
, target_cu
);
18267 baton
->locexpr
.per_cu
= cu
->per_cu
;
18268 baton
->locexpr
.per_objfile
= per_objfile
;
18269 struct dwarf_block
*block
= target_attr
->as_block ();
18270 baton
->locexpr
.size
= block
->size
;
18271 baton
->locexpr
.data
= block
->data
;
18272 baton
->locexpr
.is_reference
= true;
18273 prop
->set_locexpr (baton
);
18274 gdb_assert (prop
->baton () != NULL
);
18278 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18279 "dynamic property");
18283 case DW_AT_data_member_location
:
18287 if (!handle_data_member_location (target_die
, target_cu
,
18291 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18292 baton
->property_type
= read_type_die (target_die
->parent
,
18294 baton
->offset_info
.offset
= offset
;
18295 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18296 prop
->set_addr_offset (baton
);
18301 else if (attr
->form_is_constant ())
18302 prop
->set_const_val (attr
->constant_value (0));
18305 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18306 dwarf2_name (die
, cu
));
18316 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18318 struct type
*int_type
;
18320 /* Helper macro to examine the various builtin types. */
18321 #define TRY_TYPE(F) \
18322 int_type = (unsigned_p \
18323 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18324 : objfile_type (objfile)->builtin_ ## F); \
18325 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18332 TRY_TYPE (long_long
);
18336 gdb_assert_not_reached ("unable to find suitable integer type");
18339 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18340 present (which is valid) then compute the default type based on the
18341 compilation units address size. */
18343 static struct type
*
18344 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18346 struct type
*index_type
= die_type (die
, cu
);
18348 /* Dwarf-2 specifications explicitly allows to create subrange types
18349 without specifying a base type.
18350 In that case, the base type must be set to the type of
18351 the lower bound, upper bound or count, in that order, if any of these
18352 three attributes references an object that has a type.
18353 If no base type is found, the Dwarf-2 specifications say that
18354 a signed integer type of size equal to the size of an address should
18356 For the following C code: `extern char gdb_int [];'
18357 GCC produces an empty range DIE.
18358 FIXME: muller/2010-05-28: Possible references to object for low bound,
18359 high bound or count are not yet handled by this code. */
18360 if (index_type
->code () == TYPE_CODE_VOID
)
18361 index_type
= cu
->addr_sized_int_type (false);
18366 /* Read the given DW_AT_subrange DIE. */
18368 static struct type
*
18369 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18371 struct type
*base_type
, *orig_base_type
;
18372 struct type
*range_type
;
18373 struct attribute
*attr
;
18374 struct dynamic_prop low
, high
;
18375 int low_default_is_valid
;
18376 int high_bound_is_count
= 0;
18378 ULONGEST negative_mask
;
18380 orig_base_type
= read_subrange_index_type (die
, cu
);
18382 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18383 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18384 creating the range type, but we use the result of check_typedef
18385 when examining properties of the type. */
18386 base_type
= check_typedef (orig_base_type
);
18388 /* The die_type call above may have already set the type for this DIE. */
18389 range_type
= get_die_type (die
, cu
);
18393 high
.set_const_val (0);
18395 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18396 omitting DW_AT_lower_bound. */
18397 switch (cu
->language
)
18400 case language_cplus
:
18401 low
.set_const_val (0);
18402 low_default_is_valid
= 1;
18404 case language_fortran
:
18405 low
.set_const_val (1);
18406 low_default_is_valid
= 1;
18409 case language_objc
:
18410 case language_rust
:
18411 low
.set_const_val (0);
18412 low_default_is_valid
= (cu
->header
.version
>= 4);
18416 case language_pascal
:
18417 low
.set_const_val (1);
18418 low_default_is_valid
= (cu
->header
.version
>= 4);
18421 low
.set_const_val (0);
18422 low_default_is_valid
= 0;
18426 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18427 if (attr
!= nullptr)
18428 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18429 else if (!low_default_is_valid
)
18430 complaint (_("Missing DW_AT_lower_bound "
18431 "- DIE at %s [in module %s]"),
18432 sect_offset_str (die
->sect_off
),
18433 objfile_name (cu
->per_objfile
->objfile
));
18435 struct attribute
*attr_ub
, *attr_count
;
18436 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18437 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18439 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18440 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18442 /* If bounds are constant do the final calculation here. */
18443 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18444 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18446 high_bound_is_count
= 1;
18450 if (attr_ub
!= NULL
)
18451 complaint (_("Unresolved DW_AT_upper_bound "
18452 "- DIE at %s [in module %s]"),
18453 sect_offset_str (die
->sect_off
),
18454 objfile_name (cu
->per_objfile
->objfile
));
18455 if (attr_count
!= NULL
)
18456 complaint (_("Unresolved DW_AT_count "
18457 "- DIE at %s [in module %s]"),
18458 sect_offset_str (die
->sect_off
),
18459 objfile_name (cu
->per_objfile
->objfile
));
18464 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18465 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18466 bias
= bias_attr
->constant_value (0);
18468 /* Normally, the DWARF producers are expected to use a signed
18469 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18470 But this is unfortunately not always the case, as witnessed
18471 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18472 is used instead. To work around that ambiguity, we treat
18473 the bounds as signed, and thus sign-extend their values, when
18474 the base type is signed. */
18476 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18477 if (low
.kind () == PROP_CONST
18478 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18479 low
.set_const_val (low
.const_val () | negative_mask
);
18480 if (high
.kind () == PROP_CONST
18481 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18482 high
.set_const_val (high
.const_val () | negative_mask
);
18484 /* Check for bit and byte strides. */
18485 struct dynamic_prop byte_stride_prop
;
18486 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18487 if (attr_byte_stride
!= nullptr)
18489 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18490 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18494 struct dynamic_prop bit_stride_prop
;
18495 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18496 if (attr_bit_stride
!= nullptr)
18498 /* It only makes sense to have either a bit or byte stride. */
18499 if (attr_byte_stride
!= nullptr)
18501 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18502 "- DIE at %s [in module %s]"),
18503 sect_offset_str (die
->sect_off
),
18504 objfile_name (cu
->per_objfile
->objfile
));
18505 attr_bit_stride
= nullptr;
18509 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18510 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18515 if (attr_byte_stride
!= nullptr
18516 || attr_bit_stride
!= nullptr)
18518 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18519 struct dynamic_prop
*stride
18520 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18523 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18524 &high
, bias
, stride
, byte_stride_p
);
18527 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18529 if (high_bound_is_count
)
18530 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18532 /* Ada expects an empty array on no boundary attributes. */
18533 if (attr
== NULL
&& cu
->language
!= language_ada
)
18534 range_type
->bounds ()->high
.set_undefined ();
18536 name
= dwarf2_name (die
, cu
);
18538 range_type
->set_name (name
);
18540 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18541 if (attr
!= nullptr)
18542 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18544 maybe_set_alignment (cu
, die
, range_type
);
18546 set_die_type (die
, range_type
, cu
);
18548 /* set_die_type should be already done. */
18549 set_descriptive_type (range_type
, die
, cu
);
18554 static struct type
*
18555 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18559 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18560 type
->set_name (dwarf2_name (die
, cu
));
18562 /* In Ada, an unspecified type is typically used when the description
18563 of the type is deferred to a different unit. When encountering
18564 such a type, we treat it as a stub, and try to resolve it later on,
18566 if (cu
->language
== language_ada
)
18567 type
->set_is_stub (true);
18569 return set_die_type (die
, type
, cu
);
18572 /* Read a single die and all its descendents. Set the die's sibling
18573 field to NULL; set other fields in the die correctly, and set all
18574 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18575 location of the info_ptr after reading all of those dies. PARENT
18576 is the parent of the die in question. */
18578 static struct die_info
*
18579 read_die_and_children (const struct die_reader_specs
*reader
,
18580 const gdb_byte
*info_ptr
,
18581 const gdb_byte
**new_info_ptr
,
18582 struct die_info
*parent
)
18584 struct die_info
*die
;
18585 const gdb_byte
*cur_ptr
;
18587 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18590 *new_info_ptr
= cur_ptr
;
18593 store_in_ref_table (die
, reader
->cu
);
18595 if (die
->has_children
)
18596 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18600 *new_info_ptr
= cur_ptr
;
18603 die
->sibling
= NULL
;
18604 die
->parent
= parent
;
18608 /* Read a die, all of its descendents, and all of its siblings; set
18609 all of the fields of all of the dies correctly. Arguments are as
18610 in read_die_and_children. */
18612 static struct die_info
*
18613 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18614 const gdb_byte
*info_ptr
,
18615 const gdb_byte
**new_info_ptr
,
18616 struct die_info
*parent
)
18618 struct die_info
*first_die
, *last_sibling
;
18619 const gdb_byte
*cur_ptr
;
18621 cur_ptr
= info_ptr
;
18622 first_die
= last_sibling
= NULL
;
18626 struct die_info
*die
18627 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18631 *new_info_ptr
= cur_ptr
;
18638 last_sibling
->sibling
= die
;
18640 last_sibling
= die
;
18644 /* Read a die, all of its descendents, and all of its siblings; set
18645 all of the fields of all of the dies correctly. Arguments are as
18646 in read_die_and_children.
18647 This the main entry point for reading a DIE and all its children. */
18649 static struct die_info
*
18650 read_die_and_siblings (const struct die_reader_specs
*reader
,
18651 const gdb_byte
*info_ptr
,
18652 const gdb_byte
**new_info_ptr
,
18653 struct die_info
*parent
)
18655 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18656 new_info_ptr
, parent
);
18658 if (dwarf_die_debug
)
18660 fprintf_unfiltered (gdb_stdlog
,
18661 "Read die from %s@0x%x of %s:\n",
18662 reader
->die_section
->get_name (),
18663 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18664 bfd_get_filename (reader
->abfd
));
18665 dump_die (die
, dwarf_die_debug
);
18671 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18673 The caller is responsible for filling in the extra attributes
18674 and updating (*DIEP)->num_attrs.
18675 Set DIEP to point to a newly allocated die with its information,
18676 except for its child, sibling, and parent fields. */
18678 static const gdb_byte
*
18679 read_full_die_1 (const struct die_reader_specs
*reader
,
18680 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18681 int num_extra_attrs
)
18683 unsigned int abbrev_number
, bytes_read
, i
;
18684 const struct abbrev_info
*abbrev
;
18685 struct die_info
*die
;
18686 struct dwarf2_cu
*cu
= reader
->cu
;
18687 bfd
*abfd
= reader
->abfd
;
18689 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18690 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18691 info_ptr
+= bytes_read
;
18692 if (!abbrev_number
)
18698 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18700 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18702 bfd_get_filename (abfd
));
18704 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18705 die
->sect_off
= sect_off
;
18706 die
->tag
= abbrev
->tag
;
18707 die
->abbrev
= abbrev_number
;
18708 die
->has_children
= abbrev
->has_children
;
18710 /* Make the result usable.
18711 The caller needs to update num_attrs after adding the extra
18713 die
->num_attrs
= abbrev
->num_attrs
;
18715 bool any_need_reprocess
= false;
18716 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18718 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18720 if (die
->attrs
[i
].requires_reprocessing_p ())
18721 any_need_reprocess
= true;
18724 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18725 if (attr
!= nullptr && attr
->form_is_unsigned ())
18726 cu
->str_offsets_base
= attr
->as_unsigned ();
18728 attr
= die
->attr (DW_AT_loclists_base
);
18729 if (attr
!= nullptr)
18730 cu
->loclist_base
= attr
->as_unsigned ();
18732 auto maybe_addr_base
= die
->addr_base ();
18733 if (maybe_addr_base
.has_value ())
18734 cu
->addr_base
= *maybe_addr_base
;
18736 attr
= die
->attr (DW_AT_rnglists_base
);
18737 if (attr
!= nullptr)
18738 cu
->rnglists_base
= attr
->as_unsigned ();
18740 if (any_need_reprocess
)
18742 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18744 if (die
->attrs
[i
].requires_reprocessing_p ())
18745 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18752 /* Read a die and all its attributes.
18753 Set DIEP to point to a newly allocated die with its information,
18754 except for its child, sibling, and parent fields. */
18756 static const gdb_byte
*
18757 read_full_die (const struct die_reader_specs
*reader
,
18758 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18760 const gdb_byte
*result
;
18762 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18764 if (dwarf_die_debug
)
18766 fprintf_unfiltered (gdb_stdlog
,
18767 "Read die from %s@0x%x of %s:\n",
18768 reader
->die_section
->get_name (),
18769 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18770 bfd_get_filename (reader
->abfd
));
18771 dump_die (*diep
, dwarf_die_debug
);
18778 /* Returns nonzero if TAG represents a type that we might generate a partial
18782 is_type_tag_for_partial (int tag
, enum language lang
)
18787 /* Some types that would be reasonable to generate partial symbols for,
18788 that we don't at present. Note that normally this does not
18789 matter, mainly because C compilers don't give names to these
18790 types, but instead emit DW_TAG_typedef. */
18791 case DW_TAG_file_type
:
18792 case DW_TAG_ptr_to_member_type
:
18793 case DW_TAG_set_type
:
18794 case DW_TAG_string_type
:
18795 case DW_TAG_subroutine_type
:
18798 /* GNAT may emit an array with a name, but no typedef, so we
18799 need to make a symbol in this case. */
18800 case DW_TAG_array_type
:
18801 return lang
== language_ada
;
18803 case DW_TAG_base_type
:
18804 case DW_TAG_class_type
:
18805 case DW_TAG_interface_type
:
18806 case DW_TAG_enumeration_type
:
18807 case DW_TAG_structure_type
:
18808 case DW_TAG_subrange_type
:
18809 case DW_TAG_typedef
:
18810 case DW_TAG_union_type
:
18817 /* Load all DIEs that are interesting for partial symbols into memory. */
18819 static struct partial_die_info
*
18820 load_partial_dies (const struct die_reader_specs
*reader
,
18821 const gdb_byte
*info_ptr
, int building_psymtab
)
18823 struct dwarf2_cu
*cu
= reader
->cu
;
18824 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18825 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18826 unsigned int bytes_read
;
18827 unsigned int load_all
= 0;
18828 int nesting_level
= 1;
18833 gdb_assert (cu
->per_cu
!= NULL
);
18834 if (cu
->per_cu
->load_all_dies
)
18838 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18842 &cu
->comp_unit_obstack
,
18843 hashtab_obstack_allocate
,
18844 dummy_obstack_deallocate
);
18848 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18851 /* A NULL abbrev means the end of a series of children. */
18852 if (abbrev
== NULL
)
18854 if (--nesting_level
== 0)
18857 info_ptr
+= bytes_read
;
18858 last_die
= parent_die
;
18859 parent_die
= parent_die
->die_parent
;
18863 /* Check for template arguments. We never save these; if
18864 they're seen, we just mark the parent, and go on our way. */
18865 if (parent_die
!= NULL
18866 && cu
->language
== language_cplus
18867 && (abbrev
->tag
== DW_TAG_template_type_param
18868 || abbrev
->tag
== DW_TAG_template_value_param
))
18870 parent_die
->has_template_arguments
= 1;
18874 /* We don't need a partial DIE for the template argument. */
18875 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18880 /* We only recurse into c++ subprograms looking for template arguments.
18881 Skip their other children. */
18883 && cu
->language
== language_cplus
18884 && parent_die
!= NULL
18885 && parent_die
->tag
== DW_TAG_subprogram
18886 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18888 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18892 /* Check whether this DIE is interesting enough to save. Normally
18893 we would not be interested in members here, but there may be
18894 later variables referencing them via DW_AT_specification (for
18895 static members). */
18897 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
18898 && abbrev
->tag
!= DW_TAG_constant
18899 && abbrev
->tag
!= DW_TAG_enumerator
18900 && abbrev
->tag
!= DW_TAG_subprogram
18901 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18902 && abbrev
->tag
!= DW_TAG_lexical_block
18903 && abbrev
->tag
!= DW_TAG_variable
18904 && abbrev
->tag
!= DW_TAG_namespace
18905 && abbrev
->tag
!= DW_TAG_module
18906 && abbrev
->tag
!= DW_TAG_member
18907 && abbrev
->tag
!= DW_TAG_imported_unit
18908 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18910 /* Otherwise we skip to the next sibling, if any. */
18911 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18915 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18918 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18920 /* This two-pass algorithm for processing partial symbols has a
18921 high cost in cache pressure. Thus, handle some simple cases
18922 here which cover the majority of C partial symbols. DIEs
18923 which neither have specification tags in them, nor could have
18924 specification tags elsewhere pointing at them, can simply be
18925 processed and discarded.
18927 This segment is also optional; scan_partial_symbols and
18928 add_partial_symbol will handle these DIEs if we chain
18929 them in normally. When compilers which do not emit large
18930 quantities of duplicate debug information are more common,
18931 this code can probably be removed. */
18933 /* Any complete simple types at the top level (pretty much all
18934 of them, for a language without namespaces), can be processed
18936 if (parent_die
== NULL
18937 && pdi
.has_specification
== 0
18938 && pdi
.is_declaration
== 0
18939 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18940 || pdi
.tag
== DW_TAG_base_type
18941 || pdi
.tag
== DW_TAG_array_type
18942 || pdi
.tag
== DW_TAG_subrange_type
))
18944 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18945 add_partial_symbol (&pdi
, cu
);
18947 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18951 /* The exception for DW_TAG_typedef with has_children above is
18952 a workaround of GCC PR debug/47510. In the case of this complaint
18953 type_name_or_error will error on such types later.
18955 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18956 it could not find the child DIEs referenced later, this is checked
18957 above. In correct DWARF DW_TAG_typedef should have no children. */
18959 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18960 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18961 "- DIE at %s [in module %s]"),
18962 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18964 /* If we're at the second level, and we're an enumerator, and
18965 our parent has no specification (meaning possibly lives in a
18966 namespace elsewhere), then we can add the partial symbol now
18967 instead of queueing it. */
18968 if (pdi
.tag
== DW_TAG_enumerator
18969 && parent_die
!= NULL
18970 && parent_die
->die_parent
== NULL
18971 && parent_die
->tag
== DW_TAG_enumeration_type
18972 && parent_die
->has_specification
== 0)
18974 if (pdi
.raw_name
== NULL
)
18975 complaint (_("malformed enumerator DIE ignored"));
18976 else if (building_psymtab
)
18977 add_partial_symbol (&pdi
, cu
);
18979 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18983 struct partial_die_info
*part_die
18984 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18986 /* We'll save this DIE so link it in. */
18987 part_die
->die_parent
= parent_die
;
18988 part_die
->die_sibling
= NULL
;
18989 part_die
->die_child
= NULL
;
18991 if (last_die
&& last_die
== parent_die
)
18992 last_die
->die_child
= part_die
;
18994 last_die
->die_sibling
= part_die
;
18996 last_die
= part_die
;
18998 if (first_die
== NULL
)
18999 first_die
= part_die
;
19001 /* Maybe add the DIE to the hash table. Not all DIEs that we
19002 find interesting need to be in the hash table, because we
19003 also have the parent/sibling/child chains; only those that we
19004 might refer to by offset later during partial symbol reading.
19006 For now this means things that might have be the target of a
19007 DW_AT_specification, DW_AT_abstract_origin, or
19008 DW_AT_extension. DW_AT_extension will refer only to
19009 namespaces; DW_AT_abstract_origin refers to functions (and
19010 many things under the function DIE, but we do not recurse
19011 into function DIEs during partial symbol reading) and
19012 possibly variables as well; DW_AT_specification refers to
19013 declarations. Declarations ought to have the DW_AT_declaration
19014 flag. It happens that GCC forgets to put it in sometimes, but
19015 only for functions, not for types.
19017 Adding more things than necessary to the hash table is harmless
19018 except for the performance cost. Adding too few will result in
19019 wasted time in find_partial_die, when we reread the compilation
19020 unit with load_all_dies set. */
19023 || abbrev
->tag
== DW_TAG_constant
19024 || abbrev
->tag
== DW_TAG_subprogram
19025 || abbrev
->tag
== DW_TAG_variable
19026 || abbrev
->tag
== DW_TAG_namespace
19027 || part_die
->is_declaration
)
19031 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19032 to_underlying (part_die
->sect_off
),
19037 /* For some DIEs we want to follow their children (if any). For C
19038 we have no reason to follow the children of structures; for other
19039 languages we have to, so that we can get at method physnames
19040 to infer fully qualified class names, for DW_AT_specification,
19041 and for C++ template arguments. For C++, we also look one level
19042 inside functions to find template arguments (if the name of the
19043 function does not already contain the template arguments).
19045 For Ada and Fortran, we need to scan the children of subprograms
19046 and lexical blocks as well because these languages allow the
19047 definition of nested entities that could be interesting for the
19048 debugger, such as nested subprograms for instance. */
19049 if (last_die
->has_children
19051 || last_die
->tag
== DW_TAG_namespace
19052 || last_die
->tag
== DW_TAG_module
19053 || last_die
->tag
== DW_TAG_enumeration_type
19054 || (cu
->language
== language_cplus
19055 && last_die
->tag
== DW_TAG_subprogram
19056 && (last_die
->raw_name
== NULL
19057 || strchr (last_die
->raw_name
, '<') == NULL
))
19058 || (cu
->language
!= language_c
19059 && (last_die
->tag
== DW_TAG_class_type
19060 || last_die
->tag
== DW_TAG_interface_type
19061 || last_die
->tag
== DW_TAG_structure_type
19062 || last_die
->tag
== DW_TAG_union_type
))
19063 || ((cu
->language
== language_ada
19064 || cu
->language
== language_fortran
)
19065 && (last_die
->tag
== DW_TAG_subprogram
19066 || last_die
->tag
== DW_TAG_lexical_block
))))
19069 parent_die
= last_die
;
19073 /* Otherwise we skip to the next sibling, if any. */
19074 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19076 /* Back to the top, do it again. */
19080 partial_die_info::partial_die_info (sect_offset sect_off_
,
19081 const struct abbrev_info
*abbrev
)
19082 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19086 /* See class definition. */
19089 partial_die_info::name (dwarf2_cu
*cu
)
19091 if (!canonical_name
&& raw_name
!= nullptr)
19093 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19094 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19095 canonical_name
= 1;
19101 /* Read a minimal amount of information into the minimal die structure.
19102 INFO_PTR should point just after the initial uleb128 of a DIE. */
19105 partial_die_info::read (const struct die_reader_specs
*reader
,
19106 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19108 struct dwarf2_cu
*cu
= reader
->cu
;
19109 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19111 int has_low_pc_attr
= 0;
19112 int has_high_pc_attr
= 0;
19113 int high_pc_relative
= 0;
19115 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19118 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19119 /* String and address offsets that need to do the reprocessing have
19120 already been read at this point, so there is no need to wait until
19121 the loop terminates to do the reprocessing. */
19122 if (attr
.requires_reprocessing_p ())
19123 read_attribute_reprocess (reader
, &attr
, tag
);
19124 /* Store the data if it is of an attribute we want to keep in a
19125 partial symbol table. */
19131 case DW_TAG_compile_unit
:
19132 case DW_TAG_partial_unit
:
19133 case DW_TAG_type_unit
:
19134 /* Compilation units have a DW_AT_name that is a filename, not
19135 a source language identifier. */
19136 case DW_TAG_enumeration_type
:
19137 case DW_TAG_enumerator
:
19138 /* These tags always have simple identifiers already; no need
19139 to canonicalize them. */
19140 canonical_name
= 1;
19141 raw_name
= attr
.as_string ();
19144 canonical_name
= 0;
19145 raw_name
= attr
.as_string ();
19149 case DW_AT_linkage_name
:
19150 case DW_AT_MIPS_linkage_name
:
19151 /* Note that both forms of linkage name might appear. We
19152 assume they will be the same, and we only store the last
19154 linkage_name
= attr
.as_string ();
19157 has_low_pc_attr
= 1;
19158 lowpc
= attr
.as_address ();
19160 case DW_AT_high_pc
:
19161 has_high_pc_attr
= 1;
19162 highpc
= attr
.as_address ();
19163 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19164 high_pc_relative
= 1;
19166 case DW_AT_location
:
19167 /* Support the .debug_loc offsets. */
19168 if (attr
.form_is_block ())
19170 d
.locdesc
= attr
.as_block ();
19172 else if (attr
.form_is_section_offset ())
19174 dwarf2_complex_location_expr_complaint ();
19178 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19179 "partial symbol information");
19182 case DW_AT_external
:
19183 is_external
= attr
.as_boolean ();
19185 case DW_AT_declaration
:
19186 is_declaration
= attr
.as_boolean ();
19191 case DW_AT_abstract_origin
:
19192 case DW_AT_specification
:
19193 case DW_AT_extension
:
19194 has_specification
= 1;
19195 spec_offset
= attr
.get_ref_die_offset ();
19196 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19197 || cu
->per_cu
->is_dwz
);
19199 case DW_AT_sibling
:
19200 /* Ignore absolute siblings, they might point outside of
19201 the current compile unit. */
19202 if (attr
.form
== DW_FORM_ref_addr
)
19203 complaint (_("ignoring absolute DW_AT_sibling"));
19206 const gdb_byte
*buffer
= reader
->buffer
;
19207 sect_offset off
= attr
.get_ref_die_offset ();
19208 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19210 if (sibling_ptr
< info_ptr
)
19211 complaint (_("DW_AT_sibling points backwards"));
19212 else if (sibling_ptr
> reader
->buffer_end
)
19213 reader
->die_section
->overflow_complaint ();
19215 sibling
= sibling_ptr
;
19218 case DW_AT_byte_size
:
19221 case DW_AT_const_value
:
19222 has_const_value
= 1;
19224 case DW_AT_calling_convention
:
19225 /* DWARF doesn't provide a way to identify a program's source-level
19226 entry point. DW_AT_calling_convention attributes are only meant
19227 to describe functions' calling conventions.
19229 However, because it's a necessary piece of information in
19230 Fortran, and before DWARF 4 DW_CC_program was the only
19231 piece of debugging information whose definition refers to
19232 a 'main program' at all, several compilers marked Fortran
19233 main programs with DW_CC_program --- even when those
19234 functions use the standard calling conventions.
19236 Although DWARF now specifies a way to provide this
19237 information, we support this practice for backward
19239 if (attr
.constant_value (0) == DW_CC_program
19240 && cu
->language
== language_fortran
)
19241 main_subprogram
= 1;
19245 LONGEST value
= attr
.constant_value (-1);
19246 if (value
== DW_INL_inlined
19247 || value
== DW_INL_declared_inlined
)
19248 may_be_inlined
= 1;
19253 if (tag
== DW_TAG_imported_unit
)
19255 d
.sect_off
= attr
.get_ref_die_offset ();
19256 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19257 || cu
->per_cu
->is_dwz
);
19261 case DW_AT_main_subprogram
:
19262 main_subprogram
= attr
.as_boolean ();
19267 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19268 on DWARF version). */
19269 ULONGEST ranges_offset
= attr
.as_unsigned ();
19271 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19273 if (tag
!= DW_TAG_compile_unit
)
19274 ranges_offset
+= cu
->gnu_ranges_base
;
19276 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19287 /* For Ada, if both the name and the linkage name appear, we prefer
19288 the latter. This lets "catch exception" work better, regardless
19289 of the order in which the name and linkage name were emitted.
19290 Really, though, this is just a workaround for the fact that gdb
19291 doesn't store both the name and the linkage name. */
19292 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19293 raw_name
= linkage_name
;
19295 if (high_pc_relative
)
19298 if (has_low_pc_attr
&& has_high_pc_attr
)
19300 /* When using the GNU linker, .gnu.linkonce. sections are used to
19301 eliminate duplicate copies of functions and vtables and such.
19302 The linker will arbitrarily choose one and discard the others.
19303 The AT_*_pc values for such functions refer to local labels in
19304 these sections. If the section from that file was discarded, the
19305 labels are not in the output, so the relocs get a value of 0.
19306 If this is a discarded function, mark the pc bounds as invalid,
19307 so that GDB will ignore it. */
19308 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19310 struct objfile
*objfile
= per_objfile
->objfile
;
19311 struct gdbarch
*gdbarch
= objfile
->arch ();
19313 complaint (_("DW_AT_low_pc %s is zero "
19314 "for DIE at %s [in module %s]"),
19315 paddress (gdbarch
, lowpc
),
19316 sect_offset_str (sect_off
),
19317 objfile_name (objfile
));
19319 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19320 else if (lowpc
>= highpc
)
19322 struct objfile
*objfile
= per_objfile
->objfile
;
19323 struct gdbarch
*gdbarch
= objfile
->arch ();
19325 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19326 "for DIE at %s [in module %s]"),
19327 paddress (gdbarch
, lowpc
),
19328 paddress (gdbarch
, highpc
),
19329 sect_offset_str (sect_off
),
19330 objfile_name (objfile
));
19339 /* Find a cached partial DIE at OFFSET in CU. */
19341 struct partial_die_info
*
19342 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19344 struct partial_die_info
*lookup_die
= NULL
;
19345 struct partial_die_info
part_die (sect_off
);
19347 lookup_die
= ((struct partial_die_info
*)
19348 htab_find_with_hash (partial_dies
, &part_die
,
19349 to_underlying (sect_off
)));
19354 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19355 except in the case of .debug_types DIEs which do not reference
19356 outside their CU (they do however referencing other types via
19357 DW_FORM_ref_sig8). */
19359 static const struct cu_partial_die_info
19360 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19362 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19363 struct objfile
*objfile
= per_objfile
->objfile
;
19364 struct partial_die_info
*pd
= NULL
;
19366 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19367 && cu
->header
.offset_in_cu_p (sect_off
))
19369 pd
= cu
->find_partial_die (sect_off
);
19372 /* We missed recording what we needed.
19373 Load all dies and try again. */
19377 /* TUs don't reference other CUs/TUs (except via type signatures). */
19378 if (cu
->per_cu
->is_debug_types
)
19380 error (_("Dwarf Error: Type Unit at offset %s contains"
19381 " external reference to offset %s [in module %s].\n"),
19382 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19383 bfd_get_filename (objfile
->obfd
));
19385 dwarf2_per_cu_data
*per_cu
19386 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19389 cu
= per_objfile
->get_cu (per_cu
);
19390 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19391 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19393 cu
= per_objfile
->get_cu (per_cu
);
19396 pd
= cu
->find_partial_die (sect_off
);
19399 /* If we didn't find it, and not all dies have been loaded,
19400 load them all and try again. */
19402 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19404 cu
->per_cu
->load_all_dies
= 1;
19406 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19407 THIS_CU->cu may already be in use. So we can't just free it and
19408 replace its DIEs with the ones we read in. Instead, we leave those
19409 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19410 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19412 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19414 pd
= cu
->find_partial_die (sect_off
);
19418 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19419 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19423 /* See if we can figure out if the class lives in a namespace. We do
19424 this by looking for a member function; its demangled name will
19425 contain namespace info, if there is any. */
19428 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19429 struct dwarf2_cu
*cu
)
19431 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19432 what template types look like, because the demangler
19433 frequently doesn't give the same name as the debug info. We
19434 could fix this by only using the demangled name to get the
19435 prefix (but see comment in read_structure_type). */
19437 struct partial_die_info
*real_pdi
;
19438 struct partial_die_info
*child_pdi
;
19440 /* If this DIE (this DIE's specification, if any) has a parent, then
19441 we should not do this. We'll prepend the parent's fully qualified
19442 name when we create the partial symbol. */
19444 real_pdi
= struct_pdi
;
19445 while (real_pdi
->has_specification
)
19447 auto res
= find_partial_die (real_pdi
->spec_offset
,
19448 real_pdi
->spec_is_dwz
, cu
);
19449 real_pdi
= res
.pdi
;
19453 if (real_pdi
->die_parent
!= NULL
)
19456 for (child_pdi
= struct_pdi
->die_child
;
19458 child_pdi
= child_pdi
->die_sibling
)
19460 if (child_pdi
->tag
== DW_TAG_subprogram
19461 && child_pdi
->linkage_name
!= NULL
)
19463 gdb::unique_xmalloc_ptr
<char> actual_class_name
19464 (cu
->language_defn
->class_name_from_physname
19465 (child_pdi
->linkage_name
));
19466 if (actual_class_name
!= NULL
)
19468 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19469 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19470 struct_pdi
->canonical_name
= 1;
19477 /* Return true if a DIE with TAG may have the DW_AT_const_value
19481 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19485 case DW_TAG_constant
:
19486 case DW_TAG_enumerator
:
19487 case DW_TAG_formal_parameter
:
19488 case DW_TAG_template_value_param
:
19489 case DW_TAG_variable
:
19497 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19499 /* Once we've fixed up a die, there's no point in doing so again.
19500 This also avoids a memory leak if we were to call
19501 guess_partial_die_structure_name multiple times. */
19505 /* If we found a reference attribute and the DIE has no name, try
19506 to find a name in the referred to DIE. */
19508 if (raw_name
== NULL
&& has_specification
)
19510 struct partial_die_info
*spec_die
;
19512 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19513 spec_die
= res
.pdi
;
19516 spec_die
->fixup (cu
);
19518 if (spec_die
->raw_name
)
19520 raw_name
= spec_die
->raw_name
;
19521 canonical_name
= spec_die
->canonical_name
;
19523 /* Copy DW_AT_external attribute if it is set. */
19524 if (spec_die
->is_external
)
19525 is_external
= spec_die
->is_external
;
19529 if (!has_const_value
&& has_specification
19530 && can_have_DW_AT_const_value_p (tag
))
19532 struct partial_die_info
*spec_die
;
19534 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19535 spec_die
= res
.pdi
;
19538 spec_die
->fixup (cu
);
19540 if (spec_die
->has_const_value
)
19542 /* Copy DW_AT_const_value attribute if it is set. */
19543 has_const_value
= spec_die
->has_const_value
;
19547 /* Set default names for some unnamed DIEs. */
19549 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19551 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19552 canonical_name
= 1;
19555 /* If there is no parent die to provide a namespace, and there are
19556 children, see if we can determine the namespace from their linkage
19558 if (cu
->language
== language_cplus
19559 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19560 && die_parent
== NULL
19562 && (tag
== DW_TAG_class_type
19563 || tag
== DW_TAG_structure_type
19564 || tag
== DW_TAG_union_type
))
19565 guess_partial_die_structure_name (this, cu
);
19567 /* GCC might emit a nameless struct or union that has a linkage
19568 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19569 if (raw_name
== NULL
19570 && (tag
== DW_TAG_class_type
19571 || tag
== DW_TAG_interface_type
19572 || tag
== DW_TAG_structure_type
19573 || tag
== DW_TAG_union_type
)
19574 && linkage_name
!= NULL
)
19576 gdb::unique_xmalloc_ptr
<char> demangled
19577 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19578 if (demangled
!= nullptr)
19582 /* Strip any leading namespaces/classes, keep only the base name.
19583 DW_AT_name for named DIEs does not contain the prefixes. */
19584 base
= strrchr (demangled
.get (), ':');
19585 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19588 base
= demangled
.get ();
19590 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19591 raw_name
= objfile
->intern (base
);
19592 canonical_name
= 1;
19599 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19600 contents from the given SECTION in the HEADER.
19602 HEADER_OFFSET is the offset of the header in the section. */
19604 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19605 struct dwarf2_section_info
*section
,
19606 sect_offset header_offset
)
19608 unsigned int bytes_read
;
19609 bfd
*abfd
= section
->get_bfd_owner ();
19610 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19612 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19613 info_ptr
+= bytes_read
;
19615 header
->version
= read_2_bytes (abfd
, info_ptr
);
19618 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19621 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19624 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19627 /* Return the DW_AT_loclists_base value for the CU. */
19629 lookup_loclist_base (struct dwarf2_cu
*cu
)
19631 /* For the .dwo unit, the loclist_base points to the first offset following
19632 the header. The header consists of the following entities-
19633 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19635 2. version (2 bytes)
19636 3. address size (1 byte)
19637 4. segment selector size (1 byte)
19638 5. offset entry count (4 bytes)
19639 These sizes are derived as per the DWARFv5 standard. */
19640 if (cu
->dwo_unit
!= nullptr)
19642 if (cu
->header
.initial_length_size
== 4)
19643 return LOCLIST_HEADER_SIZE32
;
19644 return LOCLIST_HEADER_SIZE64
;
19646 return cu
->loclist_base
;
19649 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19650 array of offsets in the .debug_loclists section. */
19653 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19655 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19656 struct objfile
*objfile
= per_objfile
->objfile
;
19657 bfd
*abfd
= objfile
->obfd
;
19658 ULONGEST loclist_header_size
=
19659 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19660 : LOCLIST_HEADER_SIZE64
);
19661 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19663 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19664 ULONGEST start_offset
=
19665 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19667 /* Get loclists section. */
19668 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19670 /* Read the loclists section content. */
19671 section
->read (objfile
);
19672 if (section
->buffer
== NULL
)
19673 error (_("DW_FORM_loclistx used without .debug_loclists "
19674 "section [in module %s]"), objfile_name (objfile
));
19676 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19677 so if loclist_base is smaller than the header size, we have a problem. */
19678 if (loclist_base
< loclist_header_size
)
19679 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19680 objfile_name (objfile
));
19682 /* Read the header of the loclists contribution. */
19683 struct loclists_rnglists_header header
;
19684 read_loclists_rnglists_header (&header
, section
,
19685 (sect_offset
) (loclist_base
- loclist_header_size
));
19687 /* Verify the loclist index is valid. */
19688 if (loclist_index
>= header
.offset_entry_count
)
19689 error (_("DW_FORM_loclistx pointing outside of "
19690 ".debug_loclists offset array [in module %s]"),
19691 objfile_name (objfile
));
19693 /* Validate that reading won't go beyond the end of the section. */
19694 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19695 error (_("Reading DW_FORM_loclistx index beyond end of"
19696 ".debug_loclists section [in module %s]"),
19697 objfile_name (objfile
));
19699 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19701 if (cu
->header
.offset_size
== 4)
19702 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19704 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19707 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19708 array of offsets in the .debug_rnglists section. */
19711 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19714 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19715 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19716 bfd
*abfd
= objfile
->obfd
;
19717 ULONGEST rnglist_header_size
=
19718 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19719 : RNGLIST_HEADER_SIZE64
);
19721 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19722 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19724 ULONGEST rnglist_base
=
19725 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19727 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19728 ULONGEST start_offset
=
19729 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19731 /* Get rnglists section. */
19732 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19734 /* Read the rnglists section content. */
19735 section
->read (objfile
);
19736 if (section
->buffer
== nullptr)
19737 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19739 objfile_name (objfile
));
19741 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19742 so if rnglist_base is smaller than the header size, we have a problem. */
19743 if (rnglist_base
< rnglist_header_size
)
19744 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19745 objfile_name (objfile
));
19747 /* Read the header of the rnglists contribution. */
19748 struct loclists_rnglists_header header
;
19749 read_loclists_rnglists_header (&header
, section
,
19750 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19752 /* Verify the rnglist index is valid. */
19753 if (rnglist_index
>= header
.offset_entry_count
)
19754 error (_("DW_FORM_rnglistx index pointing outside of "
19755 ".debug_rnglists offset array [in module %s]"),
19756 objfile_name (objfile
));
19758 /* Validate that reading won't go beyond the end of the section. */
19759 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19760 error (_("Reading DW_FORM_rnglistx index beyond end of"
19761 ".debug_rnglists section [in module %s]"),
19762 objfile_name (objfile
));
19764 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19766 if (cu
->header
.offset_size
== 4)
19767 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19769 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19772 /* Process the attributes that had to be skipped in the first round. These
19773 attributes are the ones that need str_offsets_base or addr_base attributes.
19774 They could not have been processed in the first round, because at the time
19775 the values of str_offsets_base or addr_base may not have been known. */
19777 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19778 struct attribute
*attr
, dwarf_tag tag
)
19780 struct dwarf2_cu
*cu
= reader
->cu
;
19781 switch (attr
->form
)
19783 case DW_FORM_addrx
:
19784 case DW_FORM_GNU_addr_index
:
19785 attr
->set_address (read_addr_index (cu
,
19786 attr
->as_unsigned_reprocess ()));
19788 case DW_FORM_loclistx
:
19790 sect_offset loclists_sect_off
19791 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19793 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19796 case DW_FORM_rnglistx
:
19798 sect_offset rnglists_sect_off
19799 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19801 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19805 case DW_FORM_strx1
:
19806 case DW_FORM_strx2
:
19807 case DW_FORM_strx3
:
19808 case DW_FORM_strx4
:
19809 case DW_FORM_GNU_str_index
:
19811 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19812 gdb_assert (!attr
->canonical_string_p ());
19813 if (reader
->dwo_file
!= NULL
)
19814 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19817 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19822 gdb_assert_not_reached (_("Unexpected DWARF form."));
19826 /* Read an attribute value described by an attribute form. */
19828 static const gdb_byte
*
19829 read_attribute_value (const struct die_reader_specs
*reader
,
19830 struct attribute
*attr
, unsigned form
,
19831 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19833 struct dwarf2_cu
*cu
= reader
->cu
;
19834 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19835 struct objfile
*objfile
= per_objfile
->objfile
;
19836 bfd
*abfd
= reader
->abfd
;
19837 struct comp_unit_head
*cu_header
= &cu
->header
;
19838 unsigned int bytes_read
;
19839 struct dwarf_block
*blk
;
19841 attr
->form
= (enum dwarf_form
) form
;
19844 case DW_FORM_ref_addr
:
19845 if (cu_header
->version
== 2)
19846 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19849 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19851 info_ptr
+= bytes_read
;
19853 case DW_FORM_GNU_ref_alt
:
19854 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19856 info_ptr
+= bytes_read
;
19860 struct gdbarch
*gdbarch
= objfile
->arch ();
19861 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19862 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19863 attr
->set_address (addr
);
19864 info_ptr
+= bytes_read
;
19867 case DW_FORM_block2
:
19868 blk
= dwarf_alloc_block (cu
);
19869 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19871 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19872 info_ptr
+= blk
->size
;
19873 attr
->set_block (blk
);
19875 case DW_FORM_block4
:
19876 blk
= dwarf_alloc_block (cu
);
19877 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19879 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19880 info_ptr
+= blk
->size
;
19881 attr
->set_block (blk
);
19883 case DW_FORM_data2
:
19884 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19887 case DW_FORM_data4
:
19888 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19891 case DW_FORM_data8
:
19892 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19895 case DW_FORM_data16
:
19896 blk
= dwarf_alloc_block (cu
);
19898 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19900 attr
->set_block (blk
);
19902 case DW_FORM_sec_offset
:
19903 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19905 info_ptr
+= bytes_read
;
19907 case DW_FORM_loclistx
:
19909 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19911 info_ptr
+= bytes_read
;
19914 case DW_FORM_string
:
19915 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19917 info_ptr
+= bytes_read
;
19920 if (!cu
->per_cu
->is_dwz
)
19922 attr
->set_string_noncanonical
19923 (read_indirect_string (per_objfile
,
19924 abfd
, info_ptr
, cu_header
,
19926 info_ptr
+= bytes_read
;
19930 case DW_FORM_line_strp
:
19931 if (!cu
->per_cu
->is_dwz
)
19933 attr
->set_string_noncanonical
19934 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19936 info_ptr
+= bytes_read
;
19940 case DW_FORM_GNU_strp_alt
:
19942 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
19943 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19946 attr
->set_string_noncanonical
19947 (dwz
->read_string (objfile
, str_offset
));
19948 info_ptr
+= bytes_read
;
19951 case DW_FORM_exprloc
:
19952 case DW_FORM_block
:
19953 blk
= dwarf_alloc_block (cu
);
19954 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19955 info_ptr
+= bytes_read
;
19956 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19957 info_ptr
+= blk
->size
;
19958 attr
->set_block (blk
);
19960 case DW_FORM_block1
:
19961 blk
= dwarf_alloc_block (cu
);
19962 blk
->size
= read_1_byte (abfd
, info_ptr
);
19964 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19965 info_ptr
+= blk
->size
;
19966 attr
->set_block (blk
);
19968 case DW_FORM_data1
:
19970 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
19973 case DW_FORM_flag_present
:
19974 attr
->set_unsigned (1);
19976 case DW_FORM_sdata
:
19977 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
19978 info_ptr
+= bytes_read
;
19980 case DW_FORM_rnglistx
:
19982 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19984 info_ptr
+= bytes_read
;
19987 case DW_FORM_udata
:
19988 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19989 info_ptr
+= bytes_read
;
19992 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19993 + read_1_byte (abfd
, info_ptr
)));
19997 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19998 + read_2_bytes (abfd
, info_ptr
)));
20002 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20003 + read_4_bytes (abfd
, info_ptr
)));
20007 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20008 + read_8_bytes (abfd
, info_ptr
)));
20011 case DW_FORM_ref_sig8
:
20012 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20015 case DW_FORM_ref_udata
:
20016 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20017 + read_unsigned_leb128 (abfd
, info_ptr
,
20019 info_ptr
+= bytes_read
;
20021 case DW_FORM_indirect
:
20022 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20023 info_ptr
+= bytes_read
;
20024 if (form
== DW_FORM_implicit_const
)
20026 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20027 info_ptr
+= bytes_read
;
20029 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20032 case DW_FORM_implicit_const
:
20033 attr
->set_signed (implicit_const
);
20035 case DW_FORM_addrx
:
20036 case DW_FORM_GNU_addr_index
:
20037 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20039 info_ptr
+= bytes_read
;
20042 case DW_FORM_strx1
:
20043 case DW_FORM_strx2
:
20044 case DW_FORM_strx3
:
20045 case DW_FORM_strx4
:
20046 case DW_FORM_GNU_str_index
:
20048 ULONGEST str_index
;
20049 if (form
== DW_FORM_strx1
)
20051 str_index
= read_1_byte (abfd
, info_ptr
);
20054 else if (form
== DW_FORM_strx2
)
20056 str_index
= read_2_bytes (abfd
, info_ptr
);
20059 else if (form
== DW_FORM_strx3
)
20061 str_index
= read_3_bytes (abfd
, info_ptr
);
20064 else if (form
== DW_FORM_strx4
)
20066 str_index
= read_4_bytes (abfd
, info_ptr
);
20071 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20072 info_ptr
+= bytes_read
;
20074 attr
->set_unsigned_reprocess (str_index
);
20078 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20079 dwarf_form_name (form
),
20080 bfd_get_filename (abfd
));
20084 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20085 attr
->form
= DW_FORM_GNU_ref_alt
;
20087 /* We have seen instances where the compiler tried to emit a byte
20088 size attribute of -1 which ended up being encoded as an unsigned
20089 0xffffffff. Although 0xffffffff is technically a valid size value,
20090 an object of this size seems pretty unlikely so we can relatively
20091 safely treat these cases as if the size attribute was invalid and
20092 treat them as zero by default. */
20093 if (attr
->name
== DW_AT_byte_size
20094 && form
== DW_FORM_data4
20095 && attr
->as_unsigned () >= 0xffffffff)
20098 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20099 hex_string (attr
->as_unsigned ()));
20100 attr
->set_unsigned (0);
20106 /* Read an attribute described by an abbreviated attribute. */
20108 static const gdb_byte
*
20109 read_attribute (const struct die_reader_specs
*reader
,
20110 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20111 const gdb_byte
*info_ptr
)
20113 attr
->name
= abbrev
->name
;
20114 attr
->string_is_canonical
= 0;
20115 attr
->requires_reprocessing
= 0;
20116 return read_attribute_value (reader
, attr
, abbrev
->form
,
20117 abbrev
->implicit_const
, info_ptr
);
20120 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20122 static const char *
20123 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20124 LONGEST str_offset
)
20126 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20127 str_offset
, "DW_FORM_strp");
20130 /* Return pointer to string at .debug_str offset as read from BUF.
20131 BUF is assumed to be in a compilation unit described by CU_HEADER.
20132 Return *BYTES_READ_PTR count of bytes read from BUF. */
20134 static const char *
20135 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20136 const gdb_byte
*buf
,
20137 const struct comp_unit_head
*cu_header
,
20138 unsigned int *bytes_read_ptr
)
20140 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20142 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20148 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20149 const struct comp_unit_head
*cu_header
,
20150 unsigned int *bytes_read_ptr
)
20152 bfd
*abfd
= objfile
->obfd
;
20153 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20155 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20158 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20159 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20160 ADDR_SIZE is the size of addresses from the CU header. */
20163 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20164 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20166 struct objfile
*objfile
= per_objfile
->objfile
;
20167 bfd
*abfd
= objfile
->obfd
;
20168 const gdb_byte
*info_ptr
;
20169 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20171 per_objfile
->per_bfd
->addr
.read (objfile
);
20172 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20173 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20174 objfile_name (objfile
));
20175 if (addr_base_or_zero
+ addr_index
* addr_size
20176 >= per_objfile
->per_bfd
->addr
.size
)
20177 error (_("DW_FORM_addr_index pointing outside of "
20178 ".debug_addr section [in module %s]"),
20179 objfile_name (objfile
));
20180 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20181 + addr_index
* addr_size
);
20182 if (addr_size
== 4)
20183 return bfd_get_32 (abfd
, info_ptr
);
20185 return bfd_get_64 (abfd
, info_ptr
);
20188 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20191 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20193 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20194 cu
->addr_base
, cu
->header
.addr_size
);
20197 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20200 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20201 unsigned int *bytes_read
)
20203 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20204 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20206 return read_addr_index (cu
, addr_index
);
20212 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20213 dwarf2_per_objfile
*per_objfile
,
20214 unsigned int addr_index
)
20216 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20217 gdb::optional
<ULONGEST
> addr_base
;
20220 /* We need addr_base and addr_size.
20221 If we don't have PER_CU->cu, we have to get it.
20222 Nasty, but the alternative is storing the needed info in PER_CU,
20223 which at this point doesn't seem justified: it's not clear how frequently
20224 it would get used and it would increase the size of every PER_CU.
20225 Entry points like dwarf2_per_cu_addr_size do a similar thing
20226 so we're not in uncharted territory here.
20227 Alas we need to be a bit more complicated as addr_base is contained
20230 We don't need to read the entire CU(/TU).
20231 We just need the header and top level die.
20233 IWBN to use the aging mechanism to let us lazily later discard the CU.
20234 For now we skip this optimization. */
20238 addr_base
= cu
->addr_base
;
20239 addr_size
= cu
->header
.addr_size
;
20243 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20244 addr_base
= reader
.cu
->addr_base
;
20245 addr_size
= reader
.cu
->header
.addr_size
;
20248 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20251 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20252 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20255 static const char *
20256 read_str_index (struct dwarf2_cu
*cu
,
20257 struct dwarf2_section_info
*str_section
,
20258 struct dwarf2_section_info
*str_offsets_section
,
20259 ULONGEST str_offsets_base
, ULONGEST str_index
)
20261 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20262 struct objfile
*objfile
= per_objfile
->objfile
;
20263 const char *objf_name
= objfile_name (objfile
);
20264 bfd
*abfd
= objfile
->obfd
;
20265 const gdb_byte
*info_ptr
;
20266 ULONGEST str_offset
;
20267 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20269 str_section
->read (objfile
);
20270 str_offsets_section
->read (objfile
);
20271 if (str_section
->buffer
== NULL
)
20272 error (_("%s used without %s section"
20273 " in CU at offset %s [in module %s]"),
20274 form_name
, str_section
->get_name (),
20275 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20276 if (str_offsets_section
->buffer
== NULL
)
20277 error (_("%s used without %s section"
20278 " in CU at offset %s [in module %s]"),
20279 form_name
, str_section
->get_name (),
20280 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20281 info_ptr
= (str_offsets_section
->buffer
20283 + str_index
* cu
->header
.offset_size
);
20284 if (cu
->header
.offset_size
== 4)
20285 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20287 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20288 if (str_offset
>= str_section
->size
)
20289 error (_("Offset from %s pointing outside of"
20290 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20291 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20292 return (const char *) (str_section
->buffer
+ str_offset
);
20295 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20297 static const char *
20298 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20300 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20301 ? reader
->cu
->header
.addr_size
: 0;
20302 return read_str_index (reader
->cu
,
20303 &reader
->dwo_file
->sections
.str
,
20304 &reader
->dwo_file
->sections
.str_offsets
,
20305 str_offsets_base
, str_index
);
20308 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20310 static const char *
20311 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20313 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20314 const char *objf_name
= objfile_name (objfile
);
20315 static const char form_name
[] = "DW_FORM_GNU_str_index";
20316 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20318 if (!cu
->str_offsets_base
.has_value ())
20319 error (_("%s used in Fission stub without %s"
20320 " in CU at offset 0x%lx [in module %s]"),
20321 form_name
, str_offsets_attr_name
,
20322 (long) cu
->header
.offset_size
, objf_name
);
20324 return read_str_index (cu
,
20325 &cu
->per_objfile
->per_bfd
->str
,
20326 &cu
->per_objfile
->per_bfd
->str_offsets
,
20327 *cu
->str_offsets_base
, str_index
);
20330 /* Return the length of an LEB128 number in BUF. */
20333 leb128_size (const gdb_byte
*buf
)
20335 const gdb_byte
*begin
= buf
;
20341 if ((byte
& 128) == 0)
20342 return buf
- begin
;
20347 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20356 cu
->language
= language_c
;
20359 case DW_LANG_C_plus_plus
:
20360 case DW_LANG_C_plus_plus_11
:
20361 case DW_LANG_C_plus_plus_14
:
20362 cu
->language
= language_cplus
;
20365 cu
->language
= language_d
;
20367 case DW_LANG_Fortran77
:
20368 case DW_LANG_Fortran90
:
20369 case DW_LANG_Fortran95
:
20370 case DW_LANG_Fortran03
:
20371 case DW_LANG_Fortran08
:
20372 cu
->language
= language_fortran
;
20375 cu
->language
= language_go
;
20377 case DW_LANG_Mips_Assembler
:
20378 cu
->language
= language_asm
;
20380 case DW_LANG_Ada83
:
20381 case DW_LANG_Ada95
:
20382 cu
->language
= language_ada
;
20384 case DW_LANG_Modula2
:
20385 cu
->language
= language_m2
;
20387 case DW_LANG_Pascal83
:
20388 cu
->language
= language_pascal
;
20391 cu
->language
= language_objc
;
20394 case DW_LANG_Rust_old
:
20395 cu
->language
= language_rust
;
20397 case DW_LANG_Cobol74
:
20398 case DW_LANG_Cobol85
:
20400 cu
->language
= language_minimal
;
20403 cu
->language_defn
= language_def (cu
->language
);
20406 /* Return the named attribute or NULL if not there. */
20408 static struct attribute
*
20409 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20414 struct attribute
*spec
= NULL
;
20416 for (i
= 0; i
< die
->num_attrs
; ++i
)
20418 if (die
->attrs
[i
].name
== name
)
20419 return &die
->attrs
[i
];
20420 if (die
->attrs
[i
].name
== DW_AT_specification
20421 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20422 spec
= &die
->attrs
[i
];
20428 die
= follow_die_ref (die
, spec
, &cu
);
20434 /* Return the string associated with a string-typed attribute, or NULL if it
20435 is either not found or is of an incorrect type. */
20437 static const char *
20438 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20440 struct attribute
*attr
;
20441 const char *str
= NULL
;
20443 attr
= dwarf2_attr (die
, name
, cu
);
20447 str
= attr
->as_string ();
20448 if (str
== nullptr)
20449 complaint (_("string type expected for attribute %s for "
20450 "DIE at %s in module %s"),
20451 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20452 objfile_name (cu
->per_objfile
->objfile
));
20458 /* Return the dwo name or NULL if not present. If present, it is in either
20459 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20460 static const char *
20461 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20463 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20464 if (dwo_name
== nullptr)
20465 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20469 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20470 and holds a non-zero value. This function should only be used for
20471 DW_FORM_flag or DW_FORM_flag_present attributes. */
20474 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20476 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20478 return attr
!= nullptr && attr
->as_boolean ();
20482 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20484 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20485 which value is non-zero. However, we have to be careful with
20486 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20487 (via dwarf2_flag_true_p) follows this attribute. So we may
20488 end up accidently finding a declaration attribute that belongs
20489 to a different DIE referenced by the specification attribute,
20490 even though the given DIE does not have a declaration attribute. */
20491 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20492 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20495 /* Return the die giving the specification for DIE, if there is
20496 one. *SPEC_CU is the CU containing DIE on input, and the CU
20497 containing the return value on output. If there is no
20498 specification, but there is an abstract origin, that is
20501 static struct die_info
*
20502 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20504 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20507 if (spec_attr
== NULL
)
20508 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20510 if (spec_attr
== NULL
)
20513 return follow_die_ref (die
, spec_attr
, spec_cu
);
20516 /* Stub for free_line_header to match void * callback types. */
20519 free_line_header_voidp (void *arg
)
20521 struct line_header
*lh
= (struct line_header
*) arg
;
20526 /* A convenience function to find the proper .debug_line section for a CU. */
20528 static struct dwarf2_section_info
*
20529 get_debug_line_section (struct dwarf2_cu
*cu
)
20531 struct dwarf2_section_info
*section
;
20532 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20534 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20536 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20537 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20538 else if (cu
->per_cu
->is_dwz
)
20540 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20542 section
= &dwz
->line
;
20545 section
= &per_objfile
->per_bfd
->line
;
20550 /* Read the statement program header starting at OFFSET in
20551 .debug_line, or .debug_line.dwo. Return a pointer
20552 to a struct line_header, allocated using xmalloc.
20553 Returns NULL if there is a problem reading the header, e.g., if it
20554 has a version we don't understand.
20556 NOTE: the strings in the include directory and file name tables of
20557 the returned object point into the dwarf line section buffer,
20558 and must not be freed. */
20560 static line_header_up
20561 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20563 struct dwarf2_section_info
*section
;
20564 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20566 section
= get_debug_line_section (cu
);
20567 section
->read (per_objfile
->objfile
);
20568 if (section
->buffer
== NULL
)
20570 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20571 complaint (_("missing .debug_line.dwo section"));
20573 complaint (_("missing .debug_line section"));
20577 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20578 per_objfile
, section
, &cu
->header
);
20581 /* Subroutine of dwarf_decode_lines to simplify it.
20582 Return the file name of the psymtab for the given file_entry.
20583 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20584 If space for the result is malloc'd, *NAME_HOLDER will be set.
20585 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20587 static const char *
20588 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20589 const dwarf2_psymtab
*pst
,
20590 const char *comp_dir
,
20591 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20593 const char *include_name
= fe
.name
;
20594 const char *include_name_to_compare
= include_name
;
20595 const char *pst_filename
;
20598 const char *dir_name
= fe
.include_dir (lh
);
20600 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20601 if (!IS_ABSOLUTE_PATH (include_name
)
20602 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20604 /* Avoid creating a duplicate psymtab for PST.
20605 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20606 Before we do the comparison, however, we need to account
20607 for DIR_NAME and COMP_DIR.
20608 First prepend dir_name (if non-NULL). If we still don't
20609 have an absolute path prepend comp_dir (if non-NULL).
20610 However, the directory we record in the include-file's
20611 psymtab does not contain COMP_DIR (to match the
20612 corresponding symtab(s)).
20617 bash$ gcc -g ./hello.c
20618 include_name = "hello.c"
20620 DW_AT_comp_dir = comp_dir = "/tmp"
20621 DW_AT_name = "./hello.c"
20625 if (dir_name
!= NULL
)
20627 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20628 include_name
, (char *) NULL
));
20629 include_name
= name_holder
->get ();
20630 include_name_to_compare
= include_name
;
20632 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20634 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20635 include_name
, (char *) NULL
));
20636 include_name_to_compare
= hold_compare
.get ();
20640 pst_filename
= pst
->filename
;
20641 gdb::unique_xmalloc_ptr
<char> copied_name
;
20642 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20644 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20645 pst_filename
, (char *) NULL
));
20646 pst_filename
= copied_name
.get ();
20649 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20653 return include_name
;
20656 /* State machine to track the state of the line number program. */
20658 class lnp_state_machine
20661 /* Initialize a machine state for the start of a line number
20663 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20664 bool record_lines_p
);
20666 file_entry
*current_file ()
20668 /* lh->file_names is 0-based, but the file name numbers in the
20669 statement program are 1-based. */
20670 return m_line_header
->file_name_at (m_file
);
20673 /* Record the line in the state machine. END_SEQUENCE is true if
20674 we're processing the end of a sequence. */
20675 void record_line (bool end_sequence
);
20677 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20678 nop-out rest of the lines in this sequence. */
20679 void check_line_address (struct dwarf2_cu
*cu
,
20680 const gdb_byte
*line_ptr
,
20681 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20683 void handle_set_discriminator (unsigned int discriminator
)
20685 m_discriminator
= discriminator
;
20686 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20689 /* Handle DW_LNE_set_address. */
20690 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20693 address
+= baseaddr
;
20694 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20697 /* Handle DW_LNS_advance_pc. */
20698 void handle_advance_pc (CORE_ADDR adjust
);
20700 /* Handle a special opcode. */
20701 void handle_special_opcode (unsigned char op_code
);
20703 /* Handle DW_LNS_advance_line. */
20704 void handle_advance_line (int line_delta
)
20706 advance_line (line_delta
);
20709 /* Handle DW_LNS_set_file. */
20710 void handle_set_file (file_name_index file
);
20712 /* Handle DW_LNS_negate_stmt. */
20713 void handle_negate_stmt ()
20715 m_is_stmt
= !m_is_stmt
;
20718 /* Handle DW_LNS_const_add_pc. */
20719 void handle_const_add_pc ();
20721 /* Handle DW_LNS_fixed_advance_pc. */
20722 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20724 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20728 /* Handle DW_LNS_copy. */
20729 void handle_copy ()
20731 record_line (false);
20732 m_discriminator
= 0;
20735 /* Handle DW_LNE_end_sequence. */
20736 void handle_end_sequence ()
20738 m_currently_recording_lines
= true;
20742 /* Advance the line by LINE_DELTA. */
20743 void advance_line (int line_delta
)
20745 m_line
+= line_delta
;
20747 if (line_delta
!= 0)
20748 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20751 struct dwarf2_cu
*m_cu
;
20753 gdbarch
*m_gdbarch
;
20755 /* True if we're recording lines.
20756 Otherwise we're building partial symtabs and are just interested in
20757 finding include files mentioned by the line number program. */
20758 bool m_record_lines_p
;
20760 /* The line number header. */
20761 line_header
*m_line_header
;
20763 /* These are part of the standard DWARF line number state machine,
20764 and initialized according to the DWARF spec. */
20766 unsigned char m_op_index
= 0;
20767 /* The line table index of the current file. */
20768 file_name_index m_file
= 1;
20769 unsigned int m_line
= 1;
20771 /* These are initialized in the constructor. */
20773 CORE_ADDR m_address
;
20775 unsigned int m_discriminator
;
20777 /* Additional bits of state we need to track. */
20779 /* The last file that we called dwarf2_start_subfile for.
20780 This is only used for TLLs. */
20781 unsigned int m_last_file
= 0;
20782 /* The last file a line number was recorded for. */
20783 struct subfile
*m_last_subfile
= NULL
;
20785 /* The address of the last line entry. */
20786 CORE_ADDR m_last_address
;
20788 /* Set to true when a previous line at the same address (using
20789 m_last_address) had m_is_stmt true. This is reset to false when a
20790 line entry at a new address (m_address different to m_last_address) is
20792 bool m_stmt_at_address
= false;
20794 /* When true, record the lines we decode. */
20795 bool m_currently_recording_lines
= false;
20797 /* The last line number that was recorded, used to coalesce
20798 consecutive entries for the same line. This can happen, for
20799 example, when discriminators are present. PR 17276. */
20800 unsigned int m_last_line
= 0;
20801 bool m_line_has_non_zero_discriminator
= false;
20805 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20807 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20808 / m_line_header
->maximum_ops_per_instruction
)
20809 * m_line_header
->minimum_instruction_length
);
20810 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20811 m_op_index
= ((m_op_index
+ adjust
)
20812 % m_line_header
->maximum_ops_per_instruction
);
20816 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20818 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20819 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20820 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20821 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20822 / m_line_header
->maximum_ops_per_instruction
)
20823 * m_line_header
->minimum_instruction_length
);
20824 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20825 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20826 % m_line_header
->maximum_ops_per_instruction
);
20828 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20829 advance_line (line_delta
);
20830 record_line (false);
20831 m_discriminator
= 0;
20835 lnp_state_machine::handle_set_file (file_name_index file
)
20839 const file_entry
*fe
= current_file ();
20841 dwarf2_debug_line_missing_file_complaint ();
20842 else if (m_record_lines_p
)
20844 const char *dir
= fe
->include_dir (m_line_header
);
20846 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20847 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20848 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20853 lnp_state_machine::handle_const_add_pc ()
20856 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20859 = (((m_op_index
+ adjust
)
20860 / m_line_header
->maximum_ops_per_instruction
)
20861 * m_line_header
->minimum_instruction_length
);
20863 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20864 m_op_index
= ((m_op_index
+ adjust
)
20865 % m_line_header
->maximum_ops_per_instruction
);
20868 /* Return non-zero if we should add LINE to the line number table.
20869 LINE is the line to add, LAST_LINE is the last line that was added,
20870 LAST_SUBFILE is the subfile for LAST_LINE.
20871 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20872 had a non-zero discriminator.
20874 We have to be careful in the presence of discriminators.
20875 E.g., for this line:
20877 for (i = 0; i < 100000; i++);
20879 clang can emit four line number entries for that one line,
20880 each with a different discriminator.
20881 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20883 However, we want gdb to coalesce all four entries into one.
20884 Otherwise the user could stepi into the middle of the line and
20885 gdb would get confused about whether the pc really was in the
20886 middle of the line.
20888 Things are further complicated by the fact that two consecutive
20889 line number entries for the same line is a heuristic used by gcc
20890 to denote the end of the prologue. So we can't just discard duplicate
20891 entries, we have to be selective about it. The heuristic we use is
20892 that we only collapse consecutive entries for the same line if at least
20893 one of those entries has a non-zero discriminator. PR 17276.
20895 Note: Addresses in the line number state machine can never go backwards
20896 within one sequence, thus this coalescing is ok. */
20899 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20900 unsigned int line
, unsigned int last_line
,
20901 int line_has_non_zero_discriminator
,
20902 struct subfile
*last_subfile
)
20904 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20906 if (line
!= last_line
)
20908 /* Same line for the same file that we've seen already.
20909 As a last check, for pr 17276, only record the line if the line
20910 has never had a non-zero discriminator. */
20911 if (!line_has_non_zero_discriminator
)
20916 /* Use the CU's builder to record line number LINE beginning at
20917 address ADDRESS in the line table of subfile SUBFILE. */
20920 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20921 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20922 struct dwarf2_cu
*cu
)
20924 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20926 if (dwarf_line_debug
)
20928 fprintf_unfiltered (gdb_stdlog
,
20929 "Recording line %u, file %s, address %s\n",
20930 line
, lbasename (subfile
->name
),
20931 paddress (gdbarch
, address
));
20935 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20938 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20939 Mark the end of a set of line number records.
20940 The arguments are the same as for dwarf_record_line_1.
20941 If SUBFILE is NULL the request is ignored. */
20944 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20945 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20947 if (subfile
== NULL
)
20950 if (dwarf_line_debug
)
20952 fprintf_unfiltered (gdb_stdlog
,
20953 "Finishing current line, file %s, address %s\n",
20954 lbasename (subfile
->name
),
20955 paddress (gdbarch
, address
));
20958 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20962 lnp_state_machine::record_line (bool end_sequence
)
20964 if (dwarf_line_debug
)
20966 fprintf_unfiltered (gdb_stdlog
,
20967 "Processing actual line %u: file %u,"
20968 " address %s, is_stmt %u, discrim %u%s\n",
20970 paddress (m_gdbarch
, m_address
),
20971 m_is_stmt
, m_discriminator
,
20972 (end_sequence
? "\t(end sequence)" : ""));
20975 file_entry
*fe
= current_file ();
20978 dwarf2_debug_line_missing_file_complaint ();
20979 /* For now we ignore lines not starting on an instruction boundary.
20980 But not when processing end_sequence for compatibility with the
20981 previous version of the code. */
20982 else if (m_op_index
== 0 || end_sequence
)
20984 fe
->included_p
= 1;
20985 if (m_record_lines_p
)
20987 /* When we switch files we insert an end maker in the first file,
20988 switch to the second file and add a new line entry. The
20989 problem is that the end marker inserted in the first file will
20990 discard any previous line entries at the same address. If the
20991 line entries in the first file are marked as is-stmt, while
20992 the new line in the second file is non-stmt, then this means
20993 the end marker will discard is-stmt lines so we can have a
20994 non-stmt line. This means that there are less addresses at
20995 which the user can insert a breakpoint.
20997 To improve this we track the last address in m_last_address,
20998 and whether we have seen an is-stmt at this address. Then
20999 when switching files, if we have seen a stmt at the current
21000 address, and we are switching to create a non-stmt line, then
21001 discard the new line. */
21003 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21004 bool ignore_this_line
21005 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21006 && !m_is_stmt
&& m_stmt_at_address
)
21007 || (!end_sequence
&& m_line
== 0));
21009 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21011 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21012 m_currently_recording_lines
? m_cu
: nullptr);
21015 if (!end_sequence
&& !ignore_this_line
)
21017 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21019 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21020 m_line_has_non_zero_discriminator
,
21023 buildsym_compunit
*builder
= m_cu
->get_builder ();
21024 dwarf_record_line_1 (m_gdbarch
,
21025 builder
->get_current_subfile (),
21026 m_line
, m_address
, is_stmt
,
21027 m_currently_recording_lines
? m_cu
: nullptr);
21029 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21030 m_last_line
= m_line
;
21035 /* Track whether we have seen any m_is_stmt true at m_address in case we
21036 have multiple line table entries all at m_address. */
21037 if (m_last_address
!= m_address
)
21039 m_stmt_at_address
= false;
21040 m_last_address
= m_address
;
21042 m_stmt_at_address
|= m_is_stmt
;
21045 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21046 line_header
*lh
, bool record_lines_p
)
21050 m_record_lines_p
= record_lines_p
;
21051 m_line_header
= lh
;
21053 m_currently_recording_lines
= true;
21055 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21056 was a line entry for it so that the backend has a chance to adjust it
21057 and also record it in case it needs it. This is currently used by MIPS
21058 code, cf. `mips_adjust_dwarf2_line'. */
21059 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21060 m_is_stmt
= lh
->default_is_stmt
;
21061 m_discriminator
= 0;
21063 m_last_address
= m_address
;
21064 m_stmt_at_address
= false;
21068 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21069 const gdb_byte
*line_ptr
,
21070 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21072 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21073 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21074 located at 0x0. In this case, additionally check that if
21075 ADDRESS < UNRELOCATED_LOWPC. */
21077 if ((address
== 0 && address
< unrelocated_lowpc
)
21078 || address
== (CORE_ADDR
) -1)
21080 /* This line table is for a function which has been
21081 GCd by the linker. Ignore it. PR gdb/12528 */
21083 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21084 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21086 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21087 line_offset
, objfile_name (objfile
));
21088 m_currently_recording_lines
= false;
21089 /* Note: m_currently_recording_lines is left as false until we see
21090 DW_LNE_end_sequence. */
21094 /* Subroutine of dwarf_decode_lines to simplify it.
21095 Process the line number information in LH.
21096 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21097 program in order to set included_p for every referenced header. */
21100 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21101 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21103 const gdb_byte
*line_ptr
, *extended_end
;
21104 const gdb_byte
*line_end
;
21105 unsigned int bytes_read
, extended_len
;
21106 unsigned char op_code
, extended_op
;
21107 CORE_ADDR baseaddr
;
21108 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21109 bfd
*abfd
= objfile
->obfd
;
21110 struct gdbarch
*gdbarch
= objfile
->arch ();
21111 /* True if we're recording line info (as opposed to building partial
21112 symtabs and just interested in finding include files mentioned by
21113 the line number program). */
21114 bool record_lines_p
= !decode_for_pst_p
;
21116 baseaddr
= objfile
->text_section_offset ();
21118 line_ptr
= lh
->statement_program_start
;
21119 line_end
= lh
->statement_program_end
;
21121 /* Read the statement sequences until there's nothing left. */
21122 while (line_ptr
< line_end
)
21124 /* The DWARF line number program state machine. Reset the state
21125 machine at the start of each sequence. */
21126 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21127 bool end_sequence
= false;
21129 if (record_lines_p
)
21131 /* Start a subfile for the current file of the state
21133 const file_entry
*fe
= state_machine
.current_file ();
21136 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21139 /* Decode the table. */
21140 while (line_ptr
< line_end
&& !end_sequence
)
21142 op_code
= read_1_byte (abfd
, line_ptr
);
21145 if (op_code
>= lh
->opcode_base
)
21147 /* Special opcode. */
21148 state_machine
.handle_special_opcode (op_code
);
21150 else switch (op_code
)
21152 case DW_LNS_extended_op
:
21153 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21155 line_ptr
+= bytes_read
;
21156 extended_end
= line_ptr
+ extended_len
;
21157 extended_op
= read_1_byte (abfd
, line_ptr
);
21159 if (DW_LNE_lo_user
<= extended_op
21160 && extended_op
<= DW_LNE_hi_user
)
21162 /* Vendor extension, ignore. */
21163 line_ptr
= extended_end
;
21166 switch (extended_op
)
21168 case DW_LNE_end_sequence
:
21169 state_machine
.handle_end_sequence ();
21170 end_sequence
= true;
21172 case DW_LNE_set_address
:
21175 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21176 line_ptr
+= bytes_read
;
21178 state_machine
.check_line_address (cu
, line_ptr
,
21179 lowpc
- baseaddr
, address
);
21180 state_machine
.handle_set_address (baseaddr
, address
);
21183 case DW_LNE_define_file
:
21185 const char *cur_file
;
21186 unsigned int mod_time
, length
;
21189 cur_file
= read_direct_string (abfd
, line_ptr
,
21191 line_ptr
+= bytes_read
;
21192 dindex
= (dir_index
)
21193 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21194 line_ptr
+= bytes_read
;
21196 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21197 line_ptr
+= bytes_read
;
21199 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21200 line_ptr
+= bytes_read
;
21201 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21204 case DW_LNE_set_discriminator
:
21206 /* The discriminator is not interesting to the
21207 debugger; just ignore it. We still need to
21208 check its value though:
21209 if there are consecutive entries for the same
21210 (non-prologue) line we want to coalesce them.
21213 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21214 line_ptr
+= bytes_read
;
21216 state_machine
.handle_set_discriminator (discr
);
21220 complaint (_("mangled .debug_line section"));
21223 /* Make sure that we parsed the extended op correctly. If e.g.
21224 we expected a different address size than the producer used,
21225 we may have read the wrong number of bytes. */
21226 if (line_ptr
!= extended_end
)
21228 complaint (_("mangled .debug_line section"));
21233 state_machine
.handle_copy ();
21235 case DW_LNS_advance_pc
:
21238 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21239 line_ptr
+= bytes_read
;
21241 state_machine
.handle_advance_pc (adjust
);
21244 case DW_LNS_advance_line
:
21247 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21248 line_ptr
+= bytes_read
;
21250 state_machine
.handle_advance_line (line_delta
);
21253 case DW_LNS_set_file
:
21255 file_name_index file
21256 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21258 line_ptr
+= bytes_read
;
21260 state_machine
.handle_set_file (file
);
21263 case DW_LNS_set_column
:
21264 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21265 line_ptr
+= bytes_read
;
21267 case DW_LNS_negate_stmt
:
21268 state_machine
.handle_negate_stmt ();
21270 case DW_LNS_set_basic_block
:
21272 /* Add to the address register of the state machine the
21273 address increment value corresponding to special opcode
21274 255. I.e., this value is scaled by the minimum
21275 instruction length since special opcode 255 would have
21276 scaled the increment. */
21277 case DW_LNS_const_add_pc
:
21278 state_machine
.handle_const_add_pc ();
21280 case DW_LNS_fixed_advance_pc
:
21282 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21285 state_machine
.handle_fixed_advance_pc (addr_adj
);
21290 /* Unknown standard opcode, ignore it. */
21293 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21295 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21296 line_ptr
+= bytes_read
;
21303 dwarf2_debug_line_missing_end_sequence_complaint ();
21305 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21306 in which case we still finish recording the last line). */
21307 state_machine
.record_line (true);
21311 /* Decode the Line Number Program (LNP) for the given line_header
21312 structure and CU. The actual information extracted and the type
21313 of structures created from the LNP depends on the value of PST.
21315 1. If PST is NULL, then this procedure uses the data from the program
21316 to create all necessary symbol tables, and their linetables.
21318 2. If PST is not NULL, this procedure reads the program to determine
21319 the list of files included by the unit represented by PST, and
21320 builds all the associated partial symbol tables.
21322 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21323 It is used for relative paths in the line table.
21324 NOTE: When processing partial symtabs (pst != NULL),
21325 comp_dir == pst->dirname.
21327 NOTE: It is important that psymtabs have the same file name (via strcmp)
21328 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21329 symtab we don't use it in the name of the psymtabs we create.
21330 E.g. expand_line_sal requires this when finding psymtabs to expand.
21331 A good testcase for this is mb-inline.exp.
21333 LOWPC is the lowest address in CU (or 0 if not known).
21335 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21336 for its PC<->lines mapping information. Otherwise only the filename
21337 table is read in. */
21340 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21341 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21342 CORE_ADDR lowpc
, int decode_mapping
)
21344 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21345 const int decode_for_pst_p
= (pst
!= NULL
);
21347 if (decode_mapping
)
21348 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21350 if (decode_for_pst_p
)
21352 /* Now that we're done scanning the Line Header Program, we can
21353 create the psymtab of each included file. */
21354 for (auto &file_entry
: lh
->file_names ())
21355 if (file_entry
.included_p
== 1)
21357 gdb::unique_xmalloc_ptr
<char> name_holder
;
21358 const char *include_name
=
21359 psymtab_include_file_name (lh
, file_entry
, pst
,
21360 comp_dir
, &name_holder
);
21361 if (include_name
!= NULL
)
21362 dwarf2_create_include_psymtab
21363 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21364 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21370 /* Make sure a symtab is created for every file, even files
21371 which contain only variables (i.e. no code with associated
21373 buildsym_compunit
*builder
= cu
->get_builder ();
21374 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21376 for (auto &fe
: lh
->file_names ())
21378 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21379 if (builder
->get_current_subfile ()->symtab
== NULL
)
21381 builder
->get_current_subfile ()->symtab
21382 = allocate_symtab (cust
,
21383 builder
->get_current_subfile ()->name
);
21385 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21390 /* Start a subfile for DWARF. FILENAME is the name of the file and
21391 DIRNAME the name of the source directory which contains FILENAME
21392 or NULL if not known.
21393 This routine tries to keep line numbers from identical absolute and
21394 relative file names in a common subfile.
21396 Using the `list' example from the GDB testsuite, which resides in
21397 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21398 of /srcdir/list0.c yields the following debugging information for list0.c:
21400 DW_AT_name: /srcdir/list0.c
21401 DW_AT_comp_dir: /compdir
21402 files.files[0].name: list0.h
21403 files.files[0].dir: /srcdir
21404 files.files[1].name: list0.c
21405 files.files[1].dir: /srcdir
21407 The line number information for list0.c has to end up in a single
21408 subfile, so that `break /srcdir/list0.c:1' works as expected.
21409 start_subfile will ensure that this happens provided that we pass the
21410 concatenation of files.files[1].dir and files.files[1].name as the
21414 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21415 const char *dirname
)
21417 gdb::unique_xmalloc_ptr
<char> copy
;
21419 /* In order not to lose the line information directory,
21420 we concatenate it to the filename when it makes sense.
21421 Note that the Dwarf3 standard says (speaking of filenames in line
21422 information): ``The directory index is ignored for file names
21423 that represent full path names''. Thus ignoring dirname in the
21424 `else' branch below isn't an issue. */
21426 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21428 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21429 filename
= copy
.get ();
21432 cu
->get_builder ()->start_subfile (filename
);
21436 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21437 struct dwarf2_cu
*cu
)
21439 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21440 struct comp_unit_head
*cu_header
= &cu
->header
;
21442 /* NOTE drow/2003-01-30: There used to be a comment and some special
21443 code here to turn a symbol with DW_AT_external and a
21444 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21445 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21446 with some versions of binutils) where shared libraries could have
21447 relocations against symbols in their debug information - the
21448 minimal symbol would have the right address, but the debug info
21449 would not. It's no longer necessary, because we will explicitly
21450 apply relocations when we read in the debug information now. */
21452 /* A DW_AT_location attribute with no contents indicates that a
21453 variable has been optimized away. */
21454 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21456 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21460 /* Handle one degenerate form of location expression specially, to
21461 preserve GDB's previous behavior when section offsets are
21462 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21463 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21465 if (attr
->form_is_block ())
21467 struct dwarf_block
*block
= attr
->as_block ();
21469 if ((block
->data
[0] == DW_OP_addr
21470 && block
->size
== 1 + cu_header
->addr_size
)
21471 || ((block
->data
[0] == DW_OP_GNU_addr_index
21472 || block
->data
[0] == DW_OP_addrx
)
21474 == 1 + leb128_size (&block
->data
[1]))))
21476 unsigned int dummy
;
21478 if (block
->data
[0] == DW_OP_addr
)
21479 SET_SYMBOL_VALUE_ADDRESS
21480 (sym
, cu
->header
.read_address (objfile
->obfd
,
21484 SET_SYMBOL_VALUE_ADDRESS
21485 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21487 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21488 fixup_symbol_section (sym
, objfile
);
21489 SET_SYMBOL_VALUE_ADDRESS
21491 SYMBOL_VALUE_ADDRESS (sym
)
21492 + objfile
->section_offsets
[sym
->section_index ()]);
21497 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21498 expression evaluator, and use LOC_COMPUTED only when necessary
21499 (i.e. when the value of a register or memory location is
21500 referenced, or a thread-local block, etc.). Then again, it might
21501 not be worthwhile. I'm assuming that it isn't unless performance
21502 or memory numbers show me otherwise. */
21504 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21506 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21507 cu
->has_loclist
= true;
21510 /* Given a pointer to a DWARF information entry, figure out if we need
21511 to make a symbol table entry for it, and if so, create a new entry
21512 and return a pointer to it.
21513 If TYPE is NULL, determine symbol type from the die, otherwise
21514 used the passed type.
21515 If SPACE is not NULL, use it to hold the new symbol. If it is
21516 NULL, allocate a new symbol on the objfile's obstack. */
21518 static struct symbol
*
21519 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21520 struct symbol
*space
)
21522 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21523 struct objfile
*objfile
= per_objfile
->objfile
;
21524 struct gdbarch
*gdbarch
= objfile
->arch ();
21525 struct symbol
*sym
= NULL
;
21527 struct attribute
*attr
= NULL
;
21528 struct attribute
*attr2
= NULL
;
21529 CORE_ADDR baseaddr
;
21530 struct pending
**list_to_add
= NULL
;
21532 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21534 baseaddr
= objfile
->text_section_offset ();
21536 name
= dwarf2_name (die
, cu
);
21539 int suppress_add
= 0;
21544 sym
= new (&objfile
->objfile_obstack
) symbol
;
21545 OBJSTAT (objfile
, n_syms
++);
21547 /* Cache this symbol's name and the name's demangled form (if any). */
21548 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21549 /* Fortran does not have mangling standard and the mangling does differ
21550 between gfortran, iFort etc. */
21551 const char *physname
21552 = (cu
->language
== language_fortran
21553 ? dwarf2_full_name (name
, die
, cu
)
21554 : dwarf2_physname (name
, die
, cu
));
21555 const char *linkagename
= dw2_linkage_name (die
, cu
);
21557 if (linkagename
== nullptr || cu
->language
== language_ada
)
21558 sym
->set_linkage_name (physname
);
21561 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21562 sym
->set_linkage_name (linkagename
);
21565 /* Default assumptions.
21566 Use the passed type or decode it from the die. */
21567 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21568 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21570 SYMBOL_TYPE (sym
) = type
;
21572 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21573 attr
= dwarf2_attr (die
,
21574 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21576 if (attr
!= nullptr)
21577 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21579 attr
= dwarf2_attr (die
,
21580 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21582 if (attr
!= nullptr && attr
->is_nonnegative ())
21584 file_name_index file_index
21585 = (file_name_index
) attr
->as_nonnegative ();
21586 struct file_entry
*fe
;
21588 if (cu
->line_header
!= NULL
)
21589 fe
= cu
->line_header
->file_name_at (file_index
);
21594 complaint (_("file index out of range"));
21596 symbol_set_symtab (sym
, fe
->symtab
);
21602 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21603 if (attr
!= nullptr)
21607 addr
= attr
->as_address ();
21608 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21609 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21610 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21613 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21614 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21615 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21616 add_symbol_to_list (sym
, cu
->list_in_scope
);
21618 case DW_TAG_subprogram
:
21619 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21621 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21622 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21623 if ((attr2
!= nullptr && attr2
->as_boolean ())
21624 || cu
->language
== language_ada
21625 || cu
->language
== language_fortran
)
21627 /* Subprograms marked external are stored as a global symbol.
21628 Ada and Fortran subprograms, whether marked external or
21629 not, are always stored as a global symbol, because we want
21630 to be able to access them globally. For instance, we want
21631 to be able to break on a nested subprogram without having
21632 to specify the context. */
21633 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21637 list_to_add
= cu
->list_in_scope
;
21640 case DW_TAG_inlined_subroutine
:
21641 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21643 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21644 SYMBOL_INLINED (sym
) = 1;
21645 list_to_add
= cu
->list_in_scope
;
21647 case DW_TAG_template_value_param
:
21649 /* Fall through. */
21650 case DW_TAG_constant
:
21651 case DW_TAG_variable
:
21652 case DW_TAG_member
:
21653 /* Compilation with minimal debug info may result in
21654 variables with missing type entries. Change the
21655 misleading `void' type to something sensible. */
21656 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21657 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21659 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21660 /* In the case of DW_TAG_member, we should only be called for
21661 static const members. */
21662 if (die
->tag
== DW_TAG_member
)
21664 /* dwarf2_add_field uses die_is_declaration,
21665 so we do the same. */
21666 gdb_assert (die_is_declaration (die
, cu
));
21669 if (attr
!= nullptr)
21671 dwarf2_const_value (attr
, sym
, cu
);
21672 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21675 if (attr2
!= nullptr && attr2
->as_boolean ())
21676 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21678 list_to_add
= cu
->list_in_scope
;
21682 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21683 if (attr
!= nullptr)
21685 var_decode_location (attr
, sym
, cu
);
21686 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21688 /* Fortran explicitly imports any global symbols to the local
21689 scope by DW_TAG_common_block. */
21690 if (cu
->language
== language_fortran
&& die
->parent
21691 && die
->parent
->tag
== DW_TAG_common_block
)
21694 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21695 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21696 && !per_objfile
->per_bfd
->has_section_at_zero
)
21698 /* When a static variable is eliminated by the linker,
21699 the corresponding debug information is not stripped
21700 out, but the variable address is set to null;
21701 do not add such variables into symbol table. */
21703 else if (attr2
!= nullptr && attr2
->as_boolean ())
21705 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21706 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21707 && per_objfile
->per_bfd
->can_copy
)
21709 /* A global static variable might be subject to
21710 copy relocation. We first check for a local
21711 minsym, though, because maybe the symbol was
21712 marked hidden, in which case this would not
21714 bound_minimal_symbol found
21715 = (lookup_minimal_symbol_linkage
21716 (sym
->linkage_name (), objfile
));
21717 if (found
.minsym
!= nullptr)
21718 sym
->maybe_copied
= 1;
21721 /* A variable with DW_AT_external is never static,
21722 but it may be block-scoped. */
21724 = ((cu
->list_in_scope
21725 == cu
->get_builder ()->get_file_symbols ())
21726 ? cu
->get_builder ()->get_global_symbols ()
21727 : cu
->list_in_scope
);
21730 list_to_add
= cu
->list_in_scope
;
21734 /* We do not know the address of this symbol.
21735 If it is an external symbol and we have type information
21736 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21737 The address of the variable will then be determined from
21738 the minimal symbol table whenever the variable is
21740 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21742 /* Fortran explicitly imports any global symbols to the local
21743 scope by DW_TAG_common_block. */
21744 if (cu
->language
== language_fortran
&& die
->parent
21745 && die
->parent
->tag
== DW_TAG_common_block
)
21747 /* SYMBOL_CLASS doesn't matter here because
21748 read_common_block is going to reset it. */
21750 list_to_add
= cu
->list_in_scope
;
21752 else if (attr2
!= nullptr && attr2
->as_boolean ()
21753 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21755 /* A variable with DW_AT_external is never static, but it
21756 may be block-scoped. */
21758 = ((cu
->list_in_scope
21759 == cu
->get_builder ()->get_file_symbols ())
21760 ? cu
->get_builder ()->get_global_symbols ()
21761 : cu
->list_in_scope
);
21763 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21765 else if (!die_is_declaration (die
, cu
))
21767 /* Use the default LOC_OPTIMIZED_OUT class. */
21768 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21770 list_to_add
= cu
->list_in_scope
;
21774 case DW_TAG_formal_parameter
:
21776 /* If we are inside a function, mark this as an argument. If
21777 not, we might be looking at an argument to an inlined function
21778 when we do not have enough information to show inlined frames;
21779 pretend it's a local variable in that case so that the user can
21781 struct context_stack
*curr
21782 = cu
->get_builder ()->get_current_context_stack ();
21783 if (curr
!= nullptr && curr
->name
!= nullptr)
21784 SYMBOL_IS_ARGUMENT (sym
) = 1;
21785 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21786 if (attr
!= nullptr)
21788 var_decode_location (attr
, sym
, cu
);
21790 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21791 if (attr
!= nullptr)
21793 dwarf2_const_value (attr
, sym
, cu
);
21796 list_to_add
= cu
->list_in_scope
;
21799 case DW_TAG_unspecified_parameters
:
21800 /* From varargs functions; gdb doesn't seem to have any
21801 interest in this information, so just ignore it for now.
21804 case DW_TAG_template_type_param
:
21806 /* Fall through. */
21807 case DW_TAG_class_type
:
21808 case DW_TAG_interface_type
:
21809 case DW_TAG_structure_type
:
21810 case DW_TAG_union_type
:
21811 case DW_TAG_set_type
:
21812 case DW_TAG_enumeration_type
:
21813 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21814 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21817 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21818 really ever be static objects: otherwise, if you try
21819 to, say, break of a class's method and you're in a file
21820 which doesn't mention that class, it won't work unless
21821 the check for all static symbols in lookup_symbol_aux
21822 saves you. See the OtherFileClass tests in
21823 gdb.c++/namespace.exp. */
21827 buildsym_compunit
*builder
= cu
->get_builder ();
21829 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21830 && cu
->language
== language_cplus
21831 ? builder
->get_global_symbols ()
21832 : cu
->list_in_scope
);
21834 /* The semantics of C++ state that "struct foo {
21835 ... }" also defines a typedef for "foo". */
21836 if (cu
->language
== language_cplus
21837 || cu
->language
== language_ada
21838 || cu
->language
== language_d
21839 || cu
->language
== language_rust
)
21841 /* The symbol's name is already allocated along
21842 with this objfile, so we don't need to
21843 duplicate it for the type. */
21844 if (SYMBOL_TYPE (sym
)->name () == 0)
21845 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21850 case DW_TAG_typedef
:
21851 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21852 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21853 list_to_add
= cu
->list_in_scope
;
21855 case DW_TAG_array_type
:
21856 case DW_TAG_base_type
:
21857 case DW_TAG_subrange_type
:
21858 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21859 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21860 list_to_add
= cu
->list_in_scope
;
21862 case DW_TAG_enumerator
:
21863 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21864 if (attr
!= nullptr)
21866 dwarf2_const_value (attr
, sym
, cu
);
21869 /* NOTE: carlton/2003-11-10: See comment above in the
21870 DW_TAG_class_type, etc. block. */
21873 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21874 && cu
->language
== language_cplus
21875 ? cu
->get_builder ()->get_global_symbols ()
21876 : cu
->list_in_scope
);
21879 case DW_TAG_imported_declaration
:
21880 case DW_TAG_namespace
:
21881 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21882 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21884 case DW_TAG_module
:
21885 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21886 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21887 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21889 case DW_TAG_common_block
:
21890 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21891 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21892 add_symbol_to_list (sym
, cu
->list_in_scope
);
21895 /* Not a tag we recognize. Hopefully we aren't processing
21896 trash data, but since we must specifically ignore things
21897 we don't recognize, there is nothing else we should do at
21899 complaint (_("unsupported tag: '%s'"),
21900 dwarf_tag_name (die
->tag
));
21906 sym
->hash_next
= objfile
->template_symbols
;
21907 objfile
->template_symbols
= sym
;
21908 list_to_add
= NULL
;
21911 if (list_to_add
!= NULL
)
21912 add_symbol_to_list (sym
, list_to_add
);
21914 /* For the benefit of old versions of GCC, check for anonymous
21915 namespaces based on the demangled name. */
21916 if (!cu
->processing_has_namespace_info
21917 && cu
->language
== language_cplus
)
21918 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21923 /* Given an attr with a DW_FORM_dataN value in host byte order,
21924 zero-extend it as appropriate for the symbol's type. The DWARF
21925 standard (v4) is not entirely clear about the meaning of using
21926 DW_FORM_dataN for a constant with a signed type, where the type is
21927 wider than the data. The conclusion of a discussion on the DWARF
21928 list was that this is unspecified. We choose to always zero-extend
21929 because that is the interpretation long in use by GCC. */
21932 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21933 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21935 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21936 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21937 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21938 LONGEST l
= attr
->constant_value (0);
21940 if (bits
< sizeof (*value
) * 8)
21942 l
&= ((LONGEST
) 1 << bits
) - 1;
21945 else if (bits
== sizeof (*value
) * 8)
21949 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21950 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21957 /* Read a constant value from an attribute. Either set *VALUE, or if
21958 the value does not fit in *VALUE, set *BYTES - either already
21959 allocated on the objfile obstack, or newly allocated on OBSTACK,
21960 or, set *BATON, if we translated the constant to a location
21964 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21965 const char *name
, struct obstack
*obstack
,
21966 struct dwarf2_cu
*cu
,
21967 LONGEST
*value
, const gdb_byte
**bytes
,
21968 struct dwarf2_locexpr_baton
**baton
)
21970 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21971 struct objfile
*objfile
= per_objfile
->objfile
;
21972 struct comp_unit_head
*cu_header
= &cu
->header
;
21973 struct dwarf_block
*blk
;
21974 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21975 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21981 switch (attr
->form
)
21984 case DW_FORM_addrx
:
21985 case DW_FORM_GNU_addr_index
:
21989 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21990 dwarf2_const_value_length_mismatch_complaint (name
,
21991 cu_header
->addr_size
,
21992 TYPE_LENGTH (type
));
21993 /* Symbols of this form are reasonably rare, so we just
21994 piggyback on the existing location code rather than writing
21995 a new implementation of symbol_computed_ops. */
21996 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21997 (*baton
)->per_objfile
= per_objfile
;
21998 (*baton
)->per_cu
= cu
->per_cu
;
21999 gdb_assert ((*baton
)->per_cu
);
22001 (*baton
)->size
= 2 + cu_header
->addr_size
;
22002 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22003 (*baton
)->data
= data
;
22005 data
[0] = DW_OP_addr
;
22006 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22007 byte_order
, attr
->as_address ());
22008 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22011 case DW_FORM_string
:
22014 case DW_FORM_GNU_str_index
:
22015 case DW_FORM_GNU_strp_alt
:
22016 /* The string is already allocated on the objfile obstack, point
22018 *bytes
= (const gdb_byte
*) attr
->as_string ();
22020 case DW_FORM_block1
:
22021 case DW_FORM_block2
:
22022 case DW_FORM_block4
:
22023 case DW_FORM_block
:
22024 case DW_FORM_exprloc
:
22025 case DW_FORM_data16
:
22026 blk
= attr
->as_block ();
22027 if (TYPE_LENGTH (type
) != blk
->size
)
22028 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22029 TYPE_LENGTH (type
));
22030 *bytes
= blk
->data
;
22033 /* The DW_AT_const_value attributes are supposed to carry the
22034 symbol's value "represented as it would be on the target
22035 architecture." By the time we get here, it's already been
22036 converted to host endianness, so we just need to sign- or
22037 zero-extend it as appropriate. */
22038 case DW_FORM_data1
:
22039 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22041 case DW_FORM_data2
:
22042 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22044 case DW_FORM_data4
:
22045 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22047 case DW_FORM_data8
:
22048 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22051 case DW_FORM_sdata
:
22052 case DW_FORM_implicit_const
:
22053 *value
= attr
->as_signed ();
22056 case DW_FORM_udata
:
22057 *value
= attr
->as_unsigned ();
22061 complaint (_("unsupported const value attribute form: '%s'"),
22062 dwarf_form_name (attr
->form
));
22069 /* Copy constant value from an attribute to a symbol. */
22072 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22073 struct dwarf2_cu
*cu
)
22075 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22077 const gdb_byte
*bytes
;
22078 struct dwarf2_locexpr_baton
*baton
;
22080 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22081 sym
->print_name (),
22082 &objfile
->objfile_obstack
, cu
,
22083 &value
, &bytes
, &baton
);
22087 SYMBOL_LOCATION_BATON (sym
) = baton
;
22088 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22090 else if (bytes
!= NULL
)
22092 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22093 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22097 SYMBOL_VALUE (sym
) = value
;
22098 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22102 /* Return the type of the die in question using its DW_AT_type attribute. */
22104 static struct type
*
22105 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22107 struct attribute
*type_attr
;
22109 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22112 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22113 /* A missing DW_AT_type represents a void type. */
22114 return objfile_type (objfile
)->builtin_void
;
22117 return lookup_die_type (die
, type_attr
, cu
);
22120 /* True iff CU's producer generates GNAT Ada auxiliary information
22121 that allows to find parallel types through that information instead
22122 of having to do expensive parallel lookups by type name. */
22125 need_gnat_info (struct dwarf2_cu
*cu
)
22127 /* Assume that the Ada compiler was GNAT, which always produces
22128 the auxiliary information. */
22129 return (cu
->language
== language_ada
);
22132 /* Return the auxiliary type of the die in question using its
22133 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22134 attribute is not present. */
22136 static struct type
*
22137 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22139 struct attribute
*type_attr
;
22141 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22145 return lookup_die_type (die
, type_attr
, cu
);
22148 /* If DIE has a descriptive_type attribute, then set the TYPE's
22149 descriptive type accordingly. */
22152 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22153 struct dwarf2_cu
*cu
)
22155 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22157 if (descriptive_type
)
22159 ALLOCATE_GNAT_AUX_TYPE (type
);
22160 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22164 /* Return the containing type of the die in question using its
22165 DW_AT_containing_type attribute. */
22167 static struct type
*
22168 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22170 struct attribute
*type_attr
;
22171 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22173 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22175 error (_("Dwarf Error: Problem turning containing type into gdb type "
22176 "[in module %s]"), objfile_name (objfile
));
22178 return lookup_die_type (die
, type_attr
, cu
);
22181 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22183 static struct type
*
22184 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22186 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22187 struct objfile
*objfile
= per_objfile
->objfile
;
22190 std::string message
22191 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22192 objfile_name (objfile
),
22193 sect_offset_str (cu
->header
.sect_off
),
22194 sect_offset_str (die
->sect_off
));
22195 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22197 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22200 /* Look up the type of DIE in CU using its type attribute ATTR.
22201 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22202 DW_AT_containing_type.
22203 If there is no type substitute an error marker. */
22205 static struct type
*
22206 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22207 struct dwarf2_cu
*cu
)
22209 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22210 struct objfile
*objfile
= per_objfile
->objfile
;
22211 struct type
*this_type
;
22213 gdb_assert (attr
->name
== DW_AT_type
22214 || attr
->name
== DW_AT_GNAT_descriptive_type
22215 || attr
->name
== DW_AT_containing_type
);
22217 /* First see if we have it cached. */
22219 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22221 struct dwarf2_per_cu_data
*per_cu
;
22222 sect_offset sect_off
= attr
->get_ref_die_offset ();
22224 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22225 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22227 else if (attr
->form_is_ref ())
22229 sect_offset sect_off
= attr
->get_ref_die_offset ();
22231 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22233 else if (attr
->form
== DW_FORM_ref_sig8
)
22235 ULONGEST signature
= attr
->as_signature ();
22237 return get_signatured_type (die
, signature
, cu
);
22241 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22242 " at %s [in module %s]"),
22243 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22244 objfile_name (objfile
));
22245 return build_error_marker_type (cu
, die
);
22248 /* If not cached we need to read it in. */
22250 if (this_type
== NULL
)
22252 struct die_info
*type_die
= NULL
;
22253 struct dwarf2_cu
*type_cu
= cu
;
22255 if (attr
->form_is_ref ())
22256 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22257 if (type_die
== NULL
)
22258 return build_error_marker_type (cu
, die
);
22259 /* If we find the type now, it's probably because the type came
22260 from an inter-CU reference and the type's CU got expanded before
22262 this_type
= read_type_die (type_die
, type_cu
);
22265 /* If we still don't have a type use an error marker. */
22267 if (this_type
== NULL
)
22268 return build_error_marker_type (cu
, die
);
22273 /* Return the type in DIE, CU.
22274 Returns NULL for invalid types.
22276 This first does a lookup in die_type_hash,
22277 and only reads the die in if necessary.
22279 NOTE: This can be called when reading in partial or full symbols. */
22281 static struct type
*
22282 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22284 struct type
*this_type
;
22286 this_type
= get_die_type (die
, cu
);
22290 return read_type_die_1 (die
, cu
);
22293 /* Read the type in DIE, CU.
22294 Returns NULL for invalid types. */
22296 static struct type
*
22297 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22299 struct type
*this_type
= NULL
;
22303 case DW_TAG_class_type
:
22304 case DW_TAG_interface_type
:
22305 case DW_TAG_structure_type
:
22306 case DW_TAG_union_type
:
22307 this_type
= read_structure_type (die
, cu
);
22309 case DW_TAG_enumeration_type
:
22310 this_type
= read_enumeration_type (die
, cu
);
22312 case DW_TAG_subprogram
:
22313 case DW_TAG_subroutine_type
:
22314 case DW_TAG_inlined_subroutine
:
22315 this_type
= read_subroutine_type (die
, cu
);
22317 case DW_TAG_array_type
:
22318 this_type
= read_array_type (die
, cu
);
22320 case DW_TAG_set_type
:
22321 this_type
= read_set_type (die
, cu
);
22323 case DW_TAG_pointer_type
:
22324 this_type
= read_tag_pointer_type (die
, cu
);
22326 case DW_TAG_ptr_to_member_type
:
22327 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22329 case DW_TAG_reference_type
:
22330 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22332 case DW_TAG_rvalue_reference_type
:
22333 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22335 case DW_TAG_const_type
:
22336 this_type
= read_tag_const_type (die
, cu
);
22338 case DW_TAG_volatile_type
:
22339 this_type
= read_tag_volatile_type (die
, cu
);
22341 case DW_TAG_restrict_type
:
22342 this_type
= read_tag_restrict_type (die
, cu
);
22344 case DW_TAG_string_type
:
22345 this_type
= read_tag_string_type (die
, cu
);
22347 case DW_TAG_typedef
:
22348 this_type
= read_typedef (die
, cu
);
22350 case DW_TAG_subrange_type
:
22351 this_type
= read_subrange_type (die
, cu
);
22353 case DW_TAG_base_type
:
22354 this_type
= read_base_type (die
, cu
);
22356 case DW_TAG_unspecified_type
:
22357 this_type
= read_unspecified_type (die
, cu
);
22359 case DW_TAG_namespace
:
22360 this_type
= read_namespace_type (die
, cu
);
22362 case DW_TAG_module
:
22363 this_type
= read_module_type (die
, cu
);
22365 case DW_TAG_atomic_type
:
22366 this_type
= read_tag_atomic_type (die
, cu
);
22369 complaint (_("unexpected tag in read_type_die: '%s'"),
22370 dwarf_tag_name (die
->tag
));
22377 /* See if we can figure out if the class lives in a namespace. We do
22378 this by looking for a member function; its demangled name will
22379 contain namespace info, if there is any.
22380 Return the computed name or NULL.
22381 Space for the result is allocated on the objfile's obstack.
22382 This is the full-die version of guess_partial_die_structure_name.
22383 In this case we know DIE has no useful parent. */
22385 static const char *
22386 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22388 struct die_info
*spec_die
;
22389 struct dwarf2_cu
*spec_cu
;
22390 struct die_info
*child
;
22391 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22394 spec_die
= die_specification (die
, &spec_cu
);
22395 if (spec_die
!= NULL
)
22401 for (child
= die
->child
;
22403 child
= child
->sibling
)
22405 if (child
->tag
== DW_TAG_subprogram
)
22407 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22409 if (linkage_name
!= NULL
)
22411 gdb::unique_xmalloc_ptr
<char> actual_name
22412 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22413 const char *name
= NULL
;
22415 if (actual_name
!= NULL
)
22417 const char *die_name
= dwarf2_name (die
, cu
);
22419 if (die_name
!= NULL
22420 && strcmp (die_name
, actual_name
.get ()) != 0)
22422 /* Strip off the class name from the full name.
22423 We want the prefix. */
22424 int die_name_len
= strlen (die_name
);
22425 int actual_name_len
= strlen (actual_name
.get ());
22426 const char *ptr
= actual_name
.get ();
22428 /* Test for '::' as a sanity check. */
22429 if (actual_name_len
> die_name_len
+ 2
22430 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22431 name
= obstack_strndup (
22432 &objfile
->per_bfd
->storage_obstack
,
22433 ptr
, actual_name_len
- die_name_len
- 2);
22444 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22445 prefix part in such case. See
22446 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22448 static const char *
22449 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22451 struct attribute
*attr
;
22454 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22455 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22458 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22461 attr
= dw2_linkage_name_attr (die
, cu
);
22462 const char *attr_name
= attr
->as_string ();
22463 if (attr
== NULL
|| attr_name
== NULL
)
22466 /* dwarf2_name had to be already called. */
22467 gdb_assert (attr
->canonical_string_p ());
22469 /* Strip the base name, keep any leading namespaces/classes. */
22470 base
= strrchr (attr_name
, ':');
22471 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22474 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22475 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22477 &base
[-1] - attr_name
);
22480 /* Return the name of the namespace/class that DIE is defined within,
22481 or "" if we can't tell. The caller should not xfree the result.
22483 For example, if we're within the method foo() in the following
22493 then determine_prefix on foo's die will return "N::C". */
22495 static const char *
22496 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22498 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22499 struct die_info
*parent
, *spec_die
;
22500 struct dwarf2_cu
*spec_cu
;
22501 struct type
*parent_type
;
22502 const char *retval
;
22504 if (cu
->language
!= language_cplus
22505 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22506 && cu
->language
!= language_rust
)
22509 retval
= anonymous_struct_prefix (die
, cu
);
22513 /* We have to be careful in the presence of DW_AT_specification.
22514 For example, with GCC 3.4, given the code
22518 // Definition of N::foo.
22522 then we'll have a tree of DIEs like this:
22524 1: DW_TAG_compile_unit
22525 2: DW_TAG_namespace // N
22526 3: DW_TAG_subprogram // declaration of N::foo
22527 4: DW_TAG_subprogram // definition of N::foo
22528 DW_AT_specification // refers to die #3
22530 Thus, when processing die #4, we have to pretend that we're in
22531 the context of its DW_AT_specification, namely the contex of die
22534 spec_die
= die_specification (die
, &spec_cu
);
22535 if (spec_die
== NULL
)
22536 parent
= die
->parent
;
22539 parent
= spec_die
->parent
;
22543 if (parent
== NULL
)
22545 else if (parent
->building_fullname
)
22548 const char *parent_name
;
22550 /* It has been seen on RealView 2.2 built binaries,
22551 DW_TAG_template_type_param types actually _defined_ as
22552 children of the parent class:
22555 template class <class Enum> Class{};
22556 Class<enum E> class_e;
22558 1: DW_TAG_class_type (Class)
22559 2: DW_TAG_enumeration_type (E)
22560 3: DW_TAG_enumerator (enum1:0)
22561 3: DW_TAG_enumerator (enum2:1)
22563 2: DW_TAG_template_type_param
22564 DW_AT_type DW_FORM_ref_udata (E)
22566 Besides being broken debug info, it can put GDB into an
22567 infinite loop. Consider:
22569 When we're building the full name for Class<E>, we'll start
22570 at Class, and go look over its template type parameters,
22571 finding E. We'll then try to build the full name of E, and
22572 reach here. We're now trying to build the full name of E,
22573 and look over the parent DIE for containing scope. In the
22574 broken case, if we followed the parent DIE of E, we'd again
22575 find Class, and once again go look at its template type
22576 arguments, etc., etc. Simply don't consider such parent die
22577 as source-level parent of this die (it can't be, the language
22578 doesn't allow it), and break the loop here. */
22579 name
= dwarf2_name (die
, cu
);
22580 parent_name
= dwarf2_name (parent
, cu
);
22581 complaint (_("template param type '%s' defined within parent '%s'"),
22582 name
? name
: "<unknown>",
22583 parent_name
? parent_name
: "<unknown>");
22587 switch (parent
->tag
)
22589 case DW_TAG_namespace
:
22590 parent_type
= read_type_die (parent
, cu
);
22591 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22592 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22593 Work around this problem here. */
22594 if (cu
->language
== language_cplus
22595 && strcmp (parent_type
->name (), "::") == 0)
22597 /* We give a name to even anonymous namespaces. */
22598 return parent_type
->name ();
22599 case DW_TAG_class_type
:
22600 case DW_TAG_interface_type
:
22601 case DW_TAG_structure_type
:
22602 case DW_TAG_union_type
:
22603 case DW_TAG_module
:
22604 parent_type
= read_type_die (parent
, cu
);
22605 if (parent_type
->name () != NULL
)
22606 return parent_type
->name ();
22608 /* An anonymous structure is only allowed non-static data
22609 members; no typedefs, no member functions, et cetera.
22610 So it does not need a prefix. */
22612 case DW_TAG_compile_unit
:
22613 case DW_TAG_partial_unit
:
22614 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22615 if (cu
->language
== language_cplus
22616 && !per_objfile
->per_bfd
->types
.empty ()
22617 && die
->child
!= NULL
22618 && (die
->tag
== DW_TAG_class_type
22619 || die
->tag
== DW_TAG_structure_type
22620 || die
->tag
== DW_TAG_union_type
))
22622 const char *name
= guess_full_die_structure_name (die
, cu
);
22627 case DW_TAG_subprogram
:
22628 /* Nested subroutines in Fortran get a prefix with the name
22629 of the parent's subroutine. */
22630 if (cu
->language
== language_fortran
)
22632 if ((die
->tag
== DW_TAG_subprogram
)
22633 && (dwarf2_name (parent
, cu
) != NULL
))
22634 return dwarf2_name (parent
, cu
);
22636 return determine_prefix (parent
, cu
);
22637 case DW_TAG_enumeration_type
:
22638 parent_type
= read_type_die (parent
, cu
);
22639 if (parent_type
->is_declared_class ())
22641 if (parent_type
->name () != NULL
)
22642 return parent_type
->name ();
22645 /* Fall through. */
22647 return determine_prefix (parent
, cu
);
22651 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22652 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22653 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22654 an obconcat, otherwise allocate storage for the result. The CU argument is
22655 used to determine the language and hence, the appropriate separator. */
22657 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22660 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22661 int physname
, struct dwarf2_cu
*cu
)
22663 const char *lead
= "";
22666 if (suffix
== NULL
|| suffix
[0] == '\0'
22667 || prefix
== NULL
|| prefix
[0] == '\0')
22669 else if (cu
->language
== language_d
)
22671 /* For D, the 'main' function could be defined in any module, but it
22672 should never be prefixed. */
22673 if (strcmp (suffix
, "D main") == 0)
22681 else if (cu
->language
== language_fortran
&& physname
)
22683 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22684 DW_AT_MIPS_linkage_name is preferred and used instead. */
22692 if (prefix
== NULL
)
22694 if (suffix
== NULL
)
22701 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22703 strcpy (retval
, lead
);
22704 strcat (retval
, prefix
);
22705 strcat (retval
, sep
);
22706 strcat (retval
, suffix
);
22711 /* We have an obstack. */
22712 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22716 /* Get name of a die, return NULL if not found. */
22718 static const char *
22719 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22720 struct objfile
*objfile
)
22722 if (name
&& cu
->language
== language_cplus
)
22724 gdb::unique_xmalloc_ptr
<char> canon_name
22725 = cp_canonicalize_string (name
);
22727 if (canon_name
!= nullptr)
22728 name
= objfile
->intern (canon_name
.get ());
22734 /* Get name of a die, return NULL if not found.
22735 Anonymous namespaces are converted to their magic string. */
22737 static const char *
22738 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22740 struct attribute
*attr
;
22741 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22743 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22744 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22745 if (attr_name
== nullptr
22746 && die
->tag
!= DW_TAG_namespace
22747 && die
->tag
!= DW_TAG_class_type
22748 && die
->tag
!= DW_TAG_interface_type
22749 && die
->tag
!= DW_TAG_structure_type
22750 && die
->tag
!= DW_TAG_union_type
)
22755 case DW_TAG_compile_unit
:
22756 case DW_TAG_partial_unit
:
22757 /* Compilation units have a DW_AT_name that is a filename, not
22758 a source language identifier. */
22759 case DW_TAG_enumeration_type
:
22760 case DW_TAG_enumerator
:
22761 /* These tags always have simple identifiers already; no need
22762 to canonicalize them. */
22765 case DW_TAG_namespace
:
22766 if (attr_name
!= nullptr)
22768 return CP_ANONYMOUS_NAMESPACE_STR
;
22770 case DW_TAG_class_type
:
22771 case DW_TAG_interface_type
:
22772 case DW_TAG_structure_type
:
22773 case DW_TAG_union_type
:
22774 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22775 structures or unions. These were of the form "._%d" in GCC 4.1,
22776 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22777 and GCC 4.4. We work around this problem by ignoring these. */
22778 if (attr_name
!= nullptr
22779 && (startswith (attr_name
, "._")
22780 || startswith (attr_name
, "<anonymous")))
22783 /* GCC might emit a nameless typedef that has a linkage name. See
22784 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22785 if (!attr
|| attr_name
== NULL
)
22787 attr
= dw2_linkage_name_attr (die
, cu
);
22788 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22789 if (attr
== NULL
|| attr_name
== NULL
)
22792 /* Avoid demangling attr_name the second time on a second
22793 call for the same DIE. */
22794 if (!attr
->canonical_string_p ())
22796 gdb::unique_xmalloc_ptr
<char> demangled
22797 (gdb_demangle (attr_name
, DMGL_TYPES
));
22798 if (demangled
== nullptr)
22801 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22802 attr_name
= attr
->as_string ();
22805 /* Strip any leading namespaces/classes, keep only the
22806 base name. DW_AT_name for named DIEs does not
22807 contain the prefixes. */
22808 const char *base
= strrchr (attr_name
, ':');
22809 if (base
&& base
> attr_name
&& base
[-1] == ':')
22820 if (!attr
->canonical_string_p ())
22821 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22823 return attr
->as_string ();
22826 /* Return the die that this die in an extension of, or NULL if there
22827 is none. *EXT_CU is the CU containing DIE on input, and the CU
22828 containing the return value on output. */
22830 static struct die_info
*
22831 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22833 struct attribute
*attr
;
22835 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22839 return follow_die_ref (die
, attr
, ext_cu
);
22843 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22847 print_spaces (indent
, f
);
22848 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22849 dwarf_tag_name (die
->tag
), die
->abbrev
,
22850 sect_offset_str (die
->sect_off
));
22852 if (die
->parent
!= NULL
)
22854 print_spaces (indent
, f
);
22855 fprintf_unfiltered (f
, " parent at offset: %s\n",
22856 sect_offset_str (die
->parent
->sect_off
));
22859 print_spaces (indent
, f
);
22860 fprintf_unfiltered (f
, " has children: %s\n",
22861 dwarf_bool_name (die
->child
!= NULL
));
22863 print_spaces (indent
, f
);
22864 fprintf_unfiltered (f
, " attributes:\n");
22866 for (i
= 0; i
< die
->num_attrs
; ++i
)
22868 print_spaces (indent
, f
);
22869 fprintf_unfiltered (f
, " %s (%s) ",
22870 dwarf_attr_name (die
->attrs
[i
].name
),
22871 dwarf_form_name (die
->attrs
[i
].form
));
22873 switch (die
->attrs
[i
].form
)
22876 case DW_FORM_addrx
:
22877 case DW_FORM_GNU_addr_index
:
22878 fprintf_unfiltered (f
, "address: ");
22879 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
22881 case DW_FORM_block2
:
22882 case DW_FORM_block4
:
22883 case DW_FORM_block
:
22884 case DW_FORM_block1
:
22885 fprintf_unfiltered (f
, "block: size %s",
22886 pulongest (die
->attrs
[i
].as_block ()->size
));
22888 case DW_FORM_exprloc
:
22889 fprintf_unfiltered (f
, "expression: size %s",
22890 pulongest (die
->attrs
[i
].as_block ()->size
));
22892 case DW_FORM_data16
:
22893 fprintf_unfiltered (f
, "constant of 16 bytes");
22895 case DW_FORM_ref_addr
:
22896 fprintf_unfiltered (f
, "ref address: ");
22897 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22899 case DW_FORM_GNU_ref_alt
:
22900 fprintf_unfiltered (f
, "alt ref address: ");
22901 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22907 case DW_FORM_ref_udata
:
22908 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22909 (long) (die
->attrs
[i
].as_unsigned ()));
22911 case DW_FORM_data1
:
22912 case DW_FORM_data2
:
22913 case DW_FORM_data4
:
22914 case DW_FORM_data8
:
22915 case DW_FORM_udata
:
22916 fprintf_unfiltered (f
, "constant: %s",
22917 pulongest (die
->attrs
[i
].as_unsigned ()));
22919 case DW_FORM_sec_offset
:
22920 fprintf_unfiltered (f
, "section offset: %s",
22921 pulongest (die
->attrs
[i
].as_unsigned ()));
22923 case DW_FORM_ref_sig8
:
22924 fprintf_unfiltered (f
, "signature: %s",
22925 hex_string (die
->attrs
[i
].as_signature ()));
22927 case DW_FORM_string
:
22929 case DW_FORM_line_strp
:
22931 case DW_FORM_GNU_str_index
:
22932 case DW_FORM_GNU_strp_alt
:
22933 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22934 die
->attrs
[i
].as_string ()
22935 ? die
->attrs
[i
].as_string () : "",
22936 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22939 if (die
->attrs
[i
].as_boolean ())
22940 fprintf_unfiltered (f
, "flag: TRUE");
22942 fprintf_unfiltered (f
, "flag: FALSE");
22944 case DW_FORM_flag_present
:
22945 fprintf_unfiltered (f
, "flag: TRUE");
22947 case DW_FORM_indirect
:
22948 /* The reader will have reduced the indirect form to
22949 the "base form" so this form should not occur. */
22950 fprintf_unfiltered (f
,
22951 "unexpected attribute form: DW_FORM_indirect");
22953 case DW_FORM_sdata
:
22954 case DW_FORM_implicit_const
:
22955 fprintf_unfiltered (f
, "constant: %s",
22956 plongest (die
->attrs
[i
].as_signed ()));
22959 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22960 die
->attrs
[i
].form
);
22963 fprintf_unfiltered (f
, "\n");
22968 dump_die_for_error (struct die_info
*die
)
22970 dump_die_shallow (gdb_stderr
, 0, die
);
22974 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22976 int indent
= level
* 4;
22978 gdb_assert (die
!= NULL
);
22980 if (level
>= max_level
)
22983 dump_die_shallow (f
, indent
, die
);
22985 if (die
->child
!= NULL
)
22987 print_spaces (indent
, f
);
22988 fprintf_unfiltered (f
, " Children:");
22989 if (level
+ 1 < max_level
)
22991 fprintf_unfiltered (f
, "\n");
22992 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22996 fprintf_unfiltered (f
,
22997 " [not printed, max nesting level reached]\n");
23001 if (die
->sibling
!= NULL
&& level
> 0)
23003 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23007 /* This is called from the pdie macro in gdbinit.in.
23008 It's not static so gcc will keep a copy callable from gdb. */
23011 dump_die (struct die_info
*die
, int max_level
)
23013 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23017 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23021 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23022 to_underlying (die
->sect_off
),
23028 /* Follow reference or signature attribute ATTR of SRC_DIE.
23029 On entry *REF_CU is the CU of SRC_DIE.
23030 On exit *REF_CU is the CU of the result. */
23032 static struct die_info
*
23033 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23034 struct dwarf2_cu
**ref_cu
)
23036 struct die_info
*die
;
23038 if (attr
->form_is_ref ())
23039 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23040 else if (attr
->form
== DW_FORM_ref_sig8
)
23041 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23044 dump_die_for_error (src_die
);
23045 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23046 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23052 /* Follow reference OFFSET.
23053 On entry *REF_CU is the CU of the source die referencing OFFSET.
23054 On exit *REF_CU is the CU of the result.
23055 Returns NULL if OFFSET is invalid. */
23057 static struct die_info
*
23058 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23059 struct dwarf2_cu
**ref_cu
)
23061 struct die_info temp_die
;
23062 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23063 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23065 gdb_assert (cu
->per_cu
!= NULL
);
23069 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23070 "source CU contains target offset: %d",
23071 sect_offset_str (cu
->per_cu
->sect_off
),
23072 sect_offset_str (sect_off
),
23073 cu
->header
.offset_in_cu_p (sect_off
));
23075 if (cu
->per_cu
->is_debug_types
)
23077 /* .debug_types CUs cannot reference anything outside their CU.
23078 If they need to, they have to reference a signatured type via
23079 DW_FORM_ref_sig8. */
23080 if (!cu
->header
.offset_in_cu_p (sect_off
))
23083 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23084 || !cu
->header
.offset_in_cu_p (sect_off
))
23086 struct dwarf2_per_cu_data
*per_cu
;
23088 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23091 dwarf_read_debug_printf_v ("target CU offset: %s, "
23092 "target CU DIEs loaded: %d",
23093 sect_offset_str (per_cu
->sect_off
),
23094 per_objfile
->get_cu (per_cu
) != nullptr);
23096 /* If necessary, add it to the queue and load its DIEs.
23098 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23099 it doesn't mean they are currently loaded. Since we require them
23100 to be loaded, we must check for ourselves. */
23101 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23102 || per_objfile
->get_cu (per_cu
) == nullptr)
23103 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23104 false, cu
->language
);
23106 target_cu
= per_objfile
->get_cu (per_cu
);
23107 gdb_assert (target_cu
!= nullptr);
23109 else if (cu
->dies
== NULL
)
23111 /* We're loading full DIEs during partial symbol reading. */
23112 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23113 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23117 *ref_cu
= target_cu
;
23118 temp_die
.sect_off
= sect_off
;
23120 if (target_cu
!= cu
)
23121 target_cu
->ancestor
= cu
;
23123 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23125 to_underlying (sect_off
));
23128 /* Follow reference attribute ATTR of SRC_DIE.
23129 On entry *REF_CU is the CU of SRC_DIE.
23130 On exit *REF_CU is the CU of the result. */
23132 static struct die_info
*
23133 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23134 struct dwarf2_cu
**ref_cu
)
23136 sect_offset sect_off
= attr
->get_ref_die_offset ();
23137 struct dwarf2_cu
*cu
= *ref_cu
;
23138 struct die_info
*die
;
23140 die
= follow_die_offset (sect_off
,
23141 (attr
->form
== DW_FORM_GNU_ref_alt
23142 || cu
->per_cu
->is_dwz
),
23145 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23146 "at %s [in module %s]"),
23147 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23148 objfile_name (cu
->per_objfile
->objfile
));
23155 struct dwarf2_locexpr_baton
23156 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23157 dwarf2_per_cu_data
*per_cu
,
23158 dwarf2_per_objfile
*per_objfile
,
23159 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23160 bool resolve_abstract_p
)
23162 struct die_info
*die
;
23163 struct attribute
*attr
;
23164 struct dwarf2_locexpr_baton retval
;
23165 struct objfile
*objfile
= per_objfile
->objfile
;
23167 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23169 cu
= load_cu (per_cu
, per_objfile
, false);
23173 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23174 Instead just throw an error, not much else we can do. */
23175 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23176 sect_offset_str (sect_off
), objfile_name (objfile
));
23179 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23181 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23182 sect_offset_str (sect_off
), objfile_name (objfile
));
23184 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23185 if (!attr
&& resolve_abstract_p
23186 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23187 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23189 CORE_ADDR pc
= get_frame_pc ();
23190 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23191 struct gdbarch
*gdbarch
= objfile
->arch ();
23193 for (const auto &cand_off
23194 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23196 struct dwarf2_cu
*cand_cu
= cu
;
23197 struct die_info
*cand
23198 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23201 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23204 CORE_ADDR pc_low
, pc_high
;
23205 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23206 if (pc_low
== ((CORE_ADDR
) -1))
23208 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23209 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23210 if (!(pc_low
<= pc
&& pc
< pc_high
))
23214 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23221 /* DWARF: "If there is no such attribute, then there is no effect.".
23222 DATA is ignored if SIZE is 0. */
23224 retval
.data
= NULL
;
23227 else if (attr
->form_is_section_offset ())
23229 struct dwarf2_loclist_baton loclist_baton
;
23230 CORE_ADDR pc
= get_frame_pc ();
23233 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23235 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23237 retval
.size
= size
;
23241 if (!attr
->form_is_block ())
23242 error (_("Dwarf Error: DIE at %s referenced in module %s "
23243 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23244 sect_offset_str (sect_off
), objfile_name (objfile
));
23246 struct dwarf_block
*block
= attr
->as_block ();
23247 retval
.data
= block
->data
;
23248 retval
.size
= block
->size
;
23250 retval
.per_objfile
= per_objfile
;
23251 retval
.per_cu
= cu
->per_cu
;
23253 per_objfile
->age_comp_units ();
23260 struct dwarf2_locexpr_baton
23261 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23262 dwarf2_per_cu_data
*per_cu
,
23263 dwarf2_per_objfile
*per_objfile
,
23264 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23266 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23268 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23272 /* Write a constant of a given type as target-ordered bytes into
23275 static const gdb_byte
*
23276 write_constant_as_bytes (struct obstack
*obstack
,
23277 enum bfd_endian byte_order
,
23284 *len
= TYPE_LENGTH (type
);
23285 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23286 store_unsigned_integer (result
, *len
, byte_order
, value
);
23294 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23295 dwarf2_per_cu_data
*per_cu
,
23296 dwarf2_per_objfile
*per_objfile
,
23300 struct die_info
*die
;
23301 struct attribute
*attr
;
23302 const gdb_byte
*result
= NULL
;
23305 enum bfd_endian byte_order
;
23306 struct objfile
*objfile
= per_objfile
->objfile
;
23308 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23310 cu
= load_cu (per_cu
, per_objfile
, false);
23314 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23315 Instead just throw an error, not much else we can do. */
23316 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23317 sect_offset_str (sect_off
), objfile_name (objfile
));
23320 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23322 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23323 sect_offset_str (sect_off
), objfile_name (objfile
));
23325 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23329 byte_order
= (bfd_big_endian (objfile
->obfd
)
23330 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23332 switch (attr
->form
)
23335 case DW_FORM_addrx
:
23336 case DW_FORM_GNU_addr_index
:
23340 *len
= cu
->header
.addr_size
;
23341 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23342 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23346 case DW_FORM_string
:
23349 case DW_FORM_GNU_str_index
:
23350 case DW_FORM_GNU_strp_alt
:
23351 /* The string is already allocated on the objfile obstack, point
23354 const char *attr_name
= attr
->as_string ();
23355 result
= (const gdb_byte
*) attr_name
;
23356 *len
= strlen (attr_name
);
23359 case DW_FORM_block1
:
23360 case DW_FORM_block2
:
23361 case DW_FORM_block4
:
23362 case DW_FORM_block
:
23363 case DW_FORM_exprloc
:
23364 case DW_FORM_data16
:
23366 struct dwarf_block
*block
= attr
->as_block ();
23367 result
= block
->data
;
23368 *len
= block
->size
;
23372 /* The DW_AT_const_value attributes are supposed to carry the
23373 symbol's value "represented as it would be on the target
23374 architecture." By the time we get here, it's already been
23375 converted to host endianness, so we just need to sign- or
23376 zero-extend it as appropriate. */
23377 case DW_FORM_data1
:
23378 type
= die_type (die
, cu
);
23379 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23380 if (result
== NULL
)
23381 result
= write_constant_as_bytes (obstack
, byte_order
,
23384 case DW_FORM_data2
:
23385 type
= die_type (die
, cu
);
23386 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23387 if (result
== NULL
)
23388 result
= write_constant_as_bytes (obstack
, byte_order
,
23391 case DW_FORM_data4
:
23392 type
= die_type (die
, cu
);
23393 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23394 if (result
== NULL
)
23395 result
= write_constant_as_bytes (obstack
, byte_order
,
23398 case DW_FORM_data8
:
23399 type
= die_type (die
, cu
);
23400 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23401 if (result
== NULL
)
23402 result
= write_constant_as_bytes (obstack
, byte_order
,
23406 case DW_FORM_sdata
:
23407 case DW_FORM_implicit_const
:
23408 type
= die_type (die
, cu
);
23409 result
= write_constant_as_bytes (obstack
, byte_order
,
23410 type
, attr
->as_signed (), len
);
23413 case DW_FORM_udata
:
23414 type
= die_type (die
, cu
);
23415 result
= write_constant_as_bytes (obstack
, byte_order
,
23416 type
, attr
->as_unsigned (), len
);
23420 complaint (_("unsupported const value attribute form: '%s'"),
23421 dwarf_form_name (attr
->form
));
23431 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23432 dwarf2_per_cu_data
*per_cu
,
23433 dwarf2_per_objfile
*per_objfile
)
23435 struct die_info
*die
;
23437 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23439 cu
= load_cu (per_cu
, per_objfile
, false);
23444 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23448 return die_type (die
, cu
);
23454 dwarf2_get_die_type (cu_offset die_offset
,
23455 dwarf2_per_cu_data
*per_cu
,
23456 dwarf2_per_objfile
*per_objfile
)
23458 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23459 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23462 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23463 On entry *REF_CU is the CU of SRC_DIE.
23464 On exit *REF_CU is the CU of the result.
23465 Returns NULL if the referenced DIE isn't found. */
23467 static struct die_info
*
23468 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23469 struct dwarf2_cu
**ref_cu
)
23471 struct die_info temp_die
;
23472 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23473 struct die_info
*die
;
23474 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23477 /* While it might be nice to assert sig_type->type == NULL here,
23478 we can get here for DW_AT_imported_declaration where we need
23479 the DIE not the type. */
23481 /* If necessary, add it to the queue and load its DIEs.
23483 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23484 it doesn't mean they are currently loaded. Since we require them
23485 to be loaded, we must check for ourselves. */
23486 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23488 || per_objfile
->get_cu (sig_type
) == nullptr)
23489 read_signatured_type (sig_type
, per_objfile
);
23491 sig_cu
= per_objfile
->get_cu (sig_type
);
23492 gdb_assert (sig_cu
!= NULL
);
23493 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23494 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23495 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23496 to_underlying (temp_die
.sect_off
));
23499 /* For .gdb_index version 7 keep track of included TUs.
23500 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23501 if (per_objfile
->per_bfd
->index_table
!= NULL
23502 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23504 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23509 sig_cu
->ancestor
= cu
;
23517 /* Follow signatured type referenced by ATTR in SRC_DIE.
23518 On entry *REF_CU is the CU of SRC_DIE.
23519 On exit *REF_CU is the CU of the result.
23520 The result is the DIE of the type.
23521 If the referenced type cannot be found an error is thrown. */
23523 static struct die_info
*
23524 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23525 struct dwarf2_cu
**ref_cu
)
23527 ULONGEST signature
= attr
->as_signature ();
23528 struct signatured_type
*sig_type
;
23529 struct die_info
*die
;
23531 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23533 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23534 /* sig_type will be NULL if the signatured type is missing from
23536 if (sig_type
== NULL
)
23538 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23539 " from DIE at %s [in module %s]"),
23540 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23541 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23544 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23547 dump_die_for_error (src_die
);
23548 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23549 " from DIE at %s [in module %s]"),
23550 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23551 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23557 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23558 reading in and processing the type unit if necessary. */
23560 static struct type
*
23561 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23562 struct dwarf2_cu
*cu
)
23564 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23565 struct signatured_type
*sig_type
;
23566 struct dwarf2_cu
*type_cu
;
23567 struct die_info
*type_die
;
23570 sig_type
= lookup_signatured_type (cu
, signature
);
23571 /* sig_type will be NULL if the signatured type is missing from
23573 if (sig_type
== NULL
)
23575 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23576 " from DIE at %s [in module %s]"),
23577 hex_string (signature
), sect_offset_str (die
->sect_off
),
23578 objfile_name (per_objfile
->objfile
));
23579 return build_error_marker_type (cu
, die
);
23582 /* If we already know the type we're done. */
23583 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23584 if (type
!= nullptr)
23588 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23589 if (type_die
!= NULL
)
23591 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23592 is created. This is important, for example, because for c++ classes
23593 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23594 type
= read_type_die (type_die
, type_cu
);
23597 complaint (_("Dwarf Error: Cannot build signatured type %s"
23598 " referenced from DIE at %s [in module %s]"),
23599 hex_string (signature
), sect_offset_str (die
->sect_off
),
23600 objfile_name (per_objfile
->objfile
));
23601 type
= build_error_marker_type (cu
, die
);
23606 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23607 " from DIE at %s [in module %s]"),
23608 hex_string (signature
), sect_offset_str (die
->sect_off
),
23609 objfile_name (per_objfile
->objfile
));
23610 type
= build_error_marker_type (cu
, die
);
23613 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23618 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23619 reading in and processing the type unit if necessary. */
23621 static struct type
*
23622 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23623 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23625 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23626 if (attr
->form_is_ref ())
23628 struct dwarf2_cu
*type_cu
= cu
;
23629 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23631 return read_type_die (type_die
, type_cu
);
23633 else if (attr
->form
== DW_FORM_ref_sig8
)
23635 return get_signatured_type (die
, attr
->as_signature (), cu
);
23639 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23641 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23642 " at %s [in module %s]"),
23643 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23644 objfile_name (per_objfile
->objfile
));
23645 return build_error_marker_type (cu
, die
);
23649 /* Load the DIEs associated with type unit PER_CU into memory. */
23652 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23653 dwarf2_per_objfile
*per_objfile
)
23655 struct signatured_type
*sig_type
;
23657 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23658 gdb_assert (! per_cu
->type_unit_group_p ());
23660 /* We have the per_cu, but we need the signatured_type.
23661 Fortunately this is an easy translation. */
23662 gdb_assert (per_cu
->is_debug_types
);
23663 sig_type
= (struct signatured_type
*) per_cu
;
23665 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23667 read_signatured_type (sig_type
, per_objfile
);
23669 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23672 /* Read in a signatured type and build its CU and DIEs.
23673 If the type is a stub for the real type in a DWO file,
23674 read in the real type from the DWO file as well. */
23677 read_signatured_type (signatured_type
*sig_type
,
23678 dwarf2_per_objfile
*per_objfile
)
23680 gdb_assert (sig_type
->is_debug_types
);
23681 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23683 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23685 if (!reader
.dummy_p
)
23687 struct dwarf2_cu
*cu
= reader
.cu
;
23688 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23690 gdb_assert (cu
->die_hash
== NULL
);
23692 htab_create_alloc_ex (cu
->header
.length
/ 12,
23696 &cu
->comp_unit_obstack
,
23697 hashtab_obstack_allocate
,
23698 dummy_obstack_deallocate
);
23700 if (reader
.comp_unit_die
->has_children
)
23701 reader
.comp_unit_die
->child
23702 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23703 reader
.comp_unit_die
);
23704 cu
->dies
= reader
.comp_unit_die
;
23705 /* comp_unit_die is not stored in die_hash, no need. */
23707 /* We try not to read any attributes in this function, because
23708 not all CUs needed for references have been loaded yet, and
23709 symbol table processing isn't initialized. But we have to
23710 set the CU language, or we won't be able to build types
23711 correctly. Similarly, if we do not read the producer, we can
23712 not apply producer-specific interpretation. */
23713 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23718 sig_type
->tu_read
= 1;
23721 /* Decode simple location descriptions.
23722 Given a pointer to a dwarf block that defines a location, compute
23723 the location and return the value. If COMPUTED is non-null, it is
23724 set to true to indicate that decoding was successful, and false
23725 otherwise. If COMPUTED is null, then this function may emit a
23729 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23731 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23733 size_t size
= blk
->size
;
23734 const gdb_byte
*data
= blk
->data
;
23735 CORE_ADDR stack
[64];
23737 unsigned int bytes_read
, unsnd
;
23740 if (computed
!= nullptr)
23746 stack
[++stacki
] = 0;
23785 stack
[++stacki
] = op
- DW_OP_lit0
;
23820 stack
[++stacki
] = op
- DW_OP_reg0
;
23823 if (computed
== nullptr)
23824 dwarf2_complex_location_expr_complaint ();
23831 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23833 stack
[++stacki
] = unsnd
;
23836 if (computed
== nullptr)
23837 dwarf2_complex_location_expr_complaint ();
23844 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23849 case DW_OP_const1u
:
23850 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23854 case DW_OP_const1s
:
23855 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23859 case DW_OP_const2u
:
23860 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23864 case DW_OP_const2s
:
23865 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23869 case DW_OP_const4u
:
23870 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23874 case DW_OP_const4s
:
23875 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23879 case DW_OP_const8u
:
23880 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23885 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23891 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23896 stack
[stacki
+ 1] = stack
[stacki
];
23901 stack
[stacki
- 1] += stack
[stacki
];
23905 case DW_OP_plus_uconst
:
23906 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23912 stack
[stacki
- 1] -= stack
[stacki
];
23917 /* If we're not the last op, then we definitely can't encode
23918 this using GDB's address_class enum. This is valid for partial
23919 global symbols, although the variable's address will be bogus
23923 if (computed
== nullptr)
23924 dwarf2_complex_location_expr_complaint ();
23930 case DW_OP_GNU_push_tls_address
:
23931 case DW_OP_form_tls_address
:
23932 /* The top of the stack has the offset from the beginning
23933 of the thread control block at which the variable is located. */
23934 /* Nothing should follow this operator, so the top of stack would
23936 /* This is valid for partial global symbols, but the variable's
23937 address will be bogus in the psymtab. Make it always at least
23938 non-zero to not look as a variable garbage collected by linker
23939 which have DW_OP_addr 0. */
23942 if (computed
== nullptr)
23943 dwarf2_complex_location_expr_complaint ();
23950 case DW_OP_GNU_uninit
:
23951 if (computed
!= nullptr)
23956 case DW_OP_GNU_addr_index
:
23957 case DW_OP_GNU_const_index
:
23958 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23964 if (computed
== nullptr)
23966 const char *name
= get_DW_OP_name (op
);
23969 complaint (_("unsupported stack op: '%s'"),
23972 complaint (_("unsupported stack op: '%02x'"),
23976 return (stack
[stacki
]);
23979 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23980 outside of the allocated space. Also enforce minimum>0. */
23981 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23983 if (computed
== nullptr)
23984 complaint (_("location description stack overflow"));
23990 if (computed
== nullptr)
23991 complaint (_("location description stack underflow"));
23996 if (computed
!= nullptr)
23998 return (stack
[stacki
]);
24001 /* memory allocation interface */
24003 static struct dwarf_block
*
24004 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24006 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24009 static struct die_info
*
24010 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24012 struct die_info
*die
;
24013 size_t size
= sizeof (struct die_info
);
24016 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24018 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24019 memset (die
, 0, sizeof (struct die_info
));
24025 /* Macro support. */
24027 /* An overload of dwarf_decode_macros that finds the correct section
24028 and ensures it is read in before calling the other overload. */
24031 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24032 int section_is_gnu
)
24034 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24035 struct objfile
*objfile
= per_objfile
->objfile
;
24036 const struct line_header
*lh
= cu
->line_header
;
24037 unsigned int offset_size
= cu
->header
.offset_size
;
24038 struct dwarf2_section_info
*section
;
24039 const char *section_name
;
24041 if (cu
->dwo_unit
!= nullptr)
24043 if (section_is_gnu
)
24045 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24046 section_name
= ".debug_macro.dwo";
24050 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24051 section_name
= ".debug_macinfo.dwo";
24056 if (section_is_gnu
)
24058 section
= &per_objfile
->per_bfd
->macro
;
24059 section_name
= ".debug_macro";
24063 section
= &per_objfile
->per_bfd
->macinfo
;
24064 section_name
= ".debug_macinfo";
24068 section
->read (objfile
);
24069 if (section
->buffer
== nullptr)
24071 complaint (_("missing %s section"), section_name
);
24075 buildsym_compunit
*builder
= cu
->get_builder ();
24077 struct dwarf2_section_info
*str_offsets_section
;
24078 struct dwarf2_section_info
*str_section
;
24079 ULONGEST str_offsets_base
;
24081 if (cu
->dwo_unit
!= nullptr)
24083 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24084 ->sections
.str_offsets
;
24085 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24086 str_offsets_base
= cu
->header
.addr_size
;
24090 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24091 str_section
= &per_objfile
->per_bfd
->str
;
24092 str_offsets_base
= *cu
->str_offsets_base
;
24095 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24096 offset_size
, offset
, str_section
, str_offsets_section
,
24097 str_offsets_base
, section_is_gnu
);
24100 /* Return the .debug_loc section to use for CU.
24101 For DWO files use .debug_loc.dwo. */
24103 static struct dwarf2_section_info
*
24104 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24106 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24110 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24112 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24114 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24115 : &per_objfile
->per_bfd
->loc
);
24118 /* Return the .debug_rnglists section to use for CU. */
24119 static struct dwarf2_section_info
*
24120 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24122 if (cu
->header
.version
< 5)
24123 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24124 cu
->header
.version
);
24125 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24127 /* Make sure we read the .debug_rnglists section from the file that
24128 contains the DW_AT_ranges attribute we are reading. Normally that
24129 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24130 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24132 if (cu
->dwo_unit
!= nullptr
24133 && tag
!= DW_TAG_compile_unit
24134 && tag
!= DW_TAG_skeleton_unit
)
24136 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24138 if (sections
->rnglists
.size
> 0)
24139 return §ions
->rnglists
;
24141 error (_(".debug_rnglists section is missing from .dwo file."));
24143 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24146 /* A helper function that fills in a dwarf2_loclist_baton. */
24149 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24150 struct dwarf2_loclist_baton
*baton
,
24151 const struct attribute
*attr
)
24153 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24154 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24156 section
->read (per_objfile
->objfile
);
24158 baton
->per_objfile
= per_objfile
;
24159 baton
->per_cu
= cu
->per_cu
;
24160 gdb_assert (baton
->per_cu
);
24161 /* We don't know how long the location list is, but make sure we
24162 don't run off the edge of the section. */
24163 baton
->size
= section
->size
- attr
->as_unsigned ();
24164 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24165 if (cu
->base_address
.has_value ())
24166 baton
->base_address
= *cu
->base_address
;
24168 baton
->base_address
= 0;
24169 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24173 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24174 struct dwarf2_cu
*cu
, int is_block
)
24176 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24177 struct objfile
*objfile
= per_objfile
->objfile
;
24178 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24180 if (attr
->form_is_section_offset ()
24181 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24182 the section. If so, fall through to the complaint in the
24184 && attr
->as_unsigned () < section
->get_size (objfile
))
24186 struct dwarf2_loclist_baton
*baton
;
24188 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24190 fill_in_loclist_baton (cu
, baton
, attr
);
24192 if (!cu
->base_address
.has_value ())
24193 complaint (_("Location list used without "
24194 "specifying the CU base address."));
24196 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24197 ? dwarf2_loclist_block_index
24198 : dwarf2_loclist_index
);
24199 SYMBOL_LOCATION_BATON (sym
) = baton
;
24203 struct dwarf2_locexpr_baton
*baton
;
24205 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24206 baton
->per_objfile
= per_objfile
;
24207 baton
->per_cu
= cu
->per_cu
;
24208 gdb_assert (baton
->per_cu
);
24210 if (attr
->form_is_block ())
24212 /* Note that we're just copying the block's data pointer
24213 here, not the actual data. We're still pointing into the
24214 info_buffer for SYM's objfile; right now we never release
24215 that buffer, but when we do clean up properly this may
24217 struct dwarf_block
*block
= attr
->as_block ();
24218 baton
->size
= block
->size
;
24219 baton
->data
= block
->data
;
24223 dwarf2_invalid_attrib_class_complaint ("location description",
24224 sym
->natural_name ());
24228 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24229 ? dwarf2_locexpr_block_index
24230 : dwarf2_locexpr_index
);
24231 SYMBOL_LOCATION_BATON (sym
) = baton
;
24237 const comp_unit_head
*
24238 dwarf2_per_cu_data::get_header () const
24240 if (!m_header_read_in
)
24242 const gdb_byte
*info_ptr
24243 = this->section
->buffer
+ to_underlying (this->sect_off
);
24245 memset (&m_header
, 0, sizeof (m_header
));
24247 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24248 rcuh_kind::COMPILE
);
24250 m_header_read_in
= true;
24259 dwarf2_per_cu_data::addr_size () const
24261 return this->get_header ()->addr_size
;
24267 dwarf2_per_cu_data::offset_size () const
24269 return this->get_header ()->offset_size
;
24275 dwarf2_per_cu_data::ref_addr_size () const
24277 const comp_unit_head
*header
= this->get_header ();
24279 if (header
->version
== 2)
24280 return header
->addr_size
;
24282 return header
->offset_size
;
24285 /* A helper function for dwarf2_find_containing_comp_unit that returns
24286 the index of the result, and that searches a vector. It will
24287 return a result even if the offset in question does not actually
24288 occur in any CU. This is separate so that it can be unit
24292 dwarf2_find_containing_comp_unit
24293 (sect_offset sect_off
,
24294 unsigned int offset_in_dwz
,
24295 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24300 high
= all_comp_units
.size () - 1;
24303 struct dwarf2_per_cu_data
*mid_cu
;
24304 int mid
= low
+ (high
- low
) / 2;
24306 mid_cu
= all_comp_units
[mid
].get ();
24307 if (mid_cu
->is_dwz
> offset_in_dwz
24308 || (mid_cu
->is_dwz
== offset_in_dwz
24309 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24314 gdb_assert (low
== high
);
24318 /* Locate the .debug_info compilation unit from CU's objfile which contains
24319 the DIE at OFFSET. Raises an error on failure. */
24321 static struct dwarf2_per_cu_data
*
24322 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24323 unsigned int offset_in_dwz
,
24324 dwarf2_per_objfile
*per_objfile
)
24326 int low
= dwarf2_find_containing_comp_unit
24327 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24328 dwarf2_per_cu_data
*this_cu
24329 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24331 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24333 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24334 error (_("Dwarf Error: could not find partial DIE containing "
24335 "offset %s [in module %s]"),
24336 sect_offset_str (sect_off
),
24337 bfd_get_filename (per_objfile
->objfile
->obfd
));
24339 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24341 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24345 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24346 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24347 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24348 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24355 namespace selftests
{
24356 namespace find_containing_comp_unit
{
24361 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24362 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24363 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24364 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24365 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24366 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24367 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24368 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24371 two
->sect_off
= sect_offset (one
->length
);
24376 four
->sect_off
= sect_offset (three
->length
);
24380 std::vector
<dwarf2_per_cu_data_up
> units
;
24381 units
.push_back (std::move (one
));
24382 units
.push_back (std::move (two
));
24383 units
.push_back (std::move (three
));
24384 units
.push_back (std::move (four
));
24388 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24389 SELF_CHECK (units
[result
].get () == one_ptr
);
24390 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24391 SELF_CHECK (units
[result
].get () == one_ptr
);
24392 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24393 SELF_CHECK (units
[result
].get () == two_ptr
);
24395 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24396 SELF_CHECK (units
[result
].get () == three_ptr
);
24397 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24398 SELF_CHECK (units
[result
].get () == three_ptr
);
24399 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24400 SELF_CHECK (units
[result
].get () == four_ptr
);
24406 #endif /* GDB_SELF_TEST */
24408 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24411 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24412 enum language pretend_language
)
24414 struct attribute
*attr
;
24416 /* Set the language we're debugging. */
24417 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24418 if (attr
!= nullptr)
24419 set_cu_language (attr
->constant_value (0), cu
);
24422 cu
->language
= pretend_language
;
24423 cu
->language_defn
= language_def (cu
->language
);
24426 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24432 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24434 auto it
= m_dwarf2_cus
.find (per_cu
);
24435 if (it
== m_dwarf2_cus
.end ())
24444 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24446 gdb_assert (this->get_cu (per_cu
) == nullptr);
24448 m_dwarf2_cus
[per_cu
] = cu
;
24454 dwarf2_per_objfile::age_comp_units ()
24456 dwarf_read_debug_printf_v ("running");
24458 /* This is not expected to be called in the middle of CU expansion. There is
24459 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24460 loaded in memory. Calling age_comp_units while the queue is in use could
24461 make us free the DIEs for a CU that is in the queue and therefore break
24463 gdb_assert (!this->per_bfd
->queue
.has_value ());
24465 /* Start by clearing all marks. */
24466 for (auto pair
: m_dwarf2_cus
)
24467 pair
.second
->clear_mark ();
24469 /* Traverse all CUs, mark them and their dependencies if used recently
24471 for (auto pair
: m_dwarf2_cus
)
24473 dwarf2_cu
*cu
= pair
.second
;
24476 if (cu
->last_used
<= dwarf_max_cache_age
)
24480 /* Delete all CUs still not marked. */
24481 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24483 dwarf2_cu
*cu
= it
->second
;
24485 if (!cu
->is_marked ())
24487 dwarf_read_debug_printf_v ("deleting old CU %s",
24488 sect_offset_str (cu
->per_cu
->sect_off
));
24490 it
= m_dwarf2_cus
.erase (it
);
24500 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24502 auto it
= m_dwarf2_cus
.find (per_cu
);
24503 if (it
== m_dwarf2_cus
.end ())
24508 m_dwarf2_cus
.erase (it
);
24511 dwarf2_per_objfile::~dwarf2_per_objfile ()
24516 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24517 We store these in a hash table separate from the DIEs, and preserve them
24518 when the DIEs are flushed out of cache.
24520 The CU "per_cu" pointer is needed because offset alone is not enough to
24521 uniquely identify the type. A file may have multiple .debug_types sections,
24522 or the type may come from a DWO file. Furthermore, while it's more logical
24523 to use per_cu->section+offset, with Fission the section with the data is in
24524 the DWO file but we don't know that section at the point we need it.
24525 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24526 because we can enter the lookup routine, get_die_type_at_offset, from
24527 outside this file, and thus won't necessarily have PER_CU->cu.
24528 Fortunately, PER_CU is stable for the life of the objfile. */
24530 struct dwarf2_per_cu_offset_and_type
24532 const struct dwarf2_per_cu_data
*per_cu
;
24533 sect_offset sect_off
;
24537 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24540 per_cu_offset_and_type_hash (const void *item
)
24542 const struct dwarf2_per_cu_offset_and_type
*ofs
24543 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24545 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24548 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24551 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24553 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24554 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24555 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24556 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24558 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24559 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24562 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24563 table if necessary. For convenience, return TYPE.
24565 The DIEs reading must have careful ordering to:
24566 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24567 reading current DIE.
24568 * Not trying to dereference contents of still incompletely read in types
24569 while reading in other DIEs.
24570 * Enable referencing still incompletely read in types just by a pointer to
24571 the type without accessing its fields.
24573 Therefore caller should follow these rules:
24574 * Try to fetch any prerequisite types we may need to build this DIE type
24575 before building the type and calling set_die_type.
24576 * After building type call set_die_type for current DIE as soon as
24577 possible before fetching more types to complete the current type.
24578 * Make the type as complete as possible before fetching more types. */
24580 static struct type
*
24581 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24582 bool skip_data_location
)
24584 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24585 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24586 struct objfile
*objfile
= per_objfile
->objfile
;
24587 struct attribute
*attr
;
24588 struct dynamic_prop prop
;
24590 /* For Ada types, make sure that the gnat-specific data is always
24591 initialized (if not already set). There are a few types where
24592 we should not be doing so, because the type-specific area is
24593 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24594 where the type-specific area is used to store the floatformat).
24595 But this is not a problem, because the gnat-specific information
24596 is actually not needed for these types. */
24597 if (need_gnat_info (cu
)
24598 && type
->code () != TYPE_CODE_FUNC
24599 && type
->code () != TYPE_CODE_FLT
24600 && type
->code () != TYPE_CODE_METHODPTR
24601 && type
->code () != TYPE_CODE_MEMBERPTR
24602 && type
->code () != TYPE_CODE_METHOD
24603 && type
->code () != TYPE_CODE_FIXED_POINT
24604 && !HAVE_GNAT_AUX_INFO (type
))
24605 INIT_GNAT_SPECIFIC (type
);
24607 /* Read DW_AT_allocated and set in type. */
24608 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24611 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24612 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24613 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24616 /* Read DW_AT_associated and set in type. */
24617 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24620 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24621 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24622 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24625 /* Read DW_AT_data_location and set in type. */
24626 if (!skip_data_location
)
24628 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24629 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24630 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24633 if (per_objfile
->die_type_hash
== NULL
)
24634 per_objfile
->die_type_hash
24635 = htab_up (htab_create_alloc (127,
24636 per_cu_offset_and_type_hash
,
24637 per_cu_offset_and_type_eq
,
24638 NULL
, xcalloc
, xfree
));
24640 ofs
.per_cu
= cu
->per_cu
;
24641 ofs
.sect_off
= die
->sect_off
;
24643 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24644 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24646 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24647 sect_offset_str (die
->sect_off
));
24648 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24649 struct dwarf2_per_cu_offset_and_type
);
24654 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24655 or return NULL if the die does not have a saved type. */
24657 static struct type
*
24658 get_die_type_at_offset (sect_offset sect_off
,
24659 dwarf2_per_cu_data
*per_cu
,
24660 dwarf2_per_objfile
*per_objfile
)
24662 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24664 if (per_objfile
->die_type_hash
== NULL
)
24667 ofs
.per_cu
= per_cu
;
24668 ofs
.sect_off
= sect_off
;
24669 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24670 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24677 /* Look up the type for DIE in CU in die_type_hash,
24678 or return NULL if DIE does not have a saved type. */
24680 static struct type
*
24681 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24683 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24686 /* Trivial hash function for partial_die_info: the hash value of a DIE
24687 is its offset in .debug_info for this objfile. */
24690 partial_die_hash (const void *item
)
24692 const struct partial_die_info
*part_die
24693 = (const struct partial_die_info
*) item
;
24695 return to_underlying (part_die
->sect_off
);
24698 /* Trivial comparison function for partial_die_info structures: two DIEs
24699 are equal if they have the same offset. */
24702 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24704 const struct partial_die_info
*part_die_lhs
24705 = (const struct partial_die_info
*) item_lhs
;
24706 const struct partial_die_info
*part_die_rhs
24707 = (const struct partial_die_info
*) item_rhs
;
24709 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24712 struct cmd_list_element
*set_dwarf_cmdlist
;
24713 struct cmd_list_element
*show_dwarf_cmdlist
;
24716 show_check_physname (struct ui_file
*file
, int from_tty
,
24717 struct cmd_list_element
*c
, const char *value
)
24719 fprintf_filtered (file
,
24720 _("Whether to check \"physname\" is %s.\n"),
24724 void _initialize_dwarf2_read ();
24726 _initialize_dwarf2_read ()
24728 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24729 Set DWARF specific variables.\n\
24730 Configure DWARF variables such as the cache size."),
24731 &set_dwarf_cmdlist
,
24732 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24734 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24735 Show DWARF specific variables.\n\
24736 Show DWARF variables such as the cache size."),
24737 &show_dwarf_cmdlist
,
24738 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24740 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24741 &dwarf_max_cache_age
, _("\
24742 Set the upper bound on the age of cached DWARF compilation units."), _("\
24743 Show the upper bound on the age of cached DWARF compilation units."), _("\
24744 A higher limit means that cached compilation units will be stored\n\
24745 in memory longer, and more total memory will be used. Zero disables\n\
24746 caching, which can slow down startup."),
24748 show_dwarf_max_cache_age
,
24749 &set_dwarf_cmdlist
,
24750 &show_dwarf_cmdlist
);
24752 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24753 Set debugging of the DWARF reader."), _("\
24754 Show debugging of the DWARF reader."), _("\
24755 When enabled (non-zero), debugging messages are printed during DWARF\n\
24756 reading and symtab expansion. A value of 1 (one) provides basic\n\
24757 information. A value greater than 1 provides more verbose information."),
24760 &setdebuglist
, &showdebuglist
);
24762 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24763 Set debugging of the DWARF DIE reader."), _("\
24764 Show debugging of the DWARF DIE reader."), _("\
24765 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24766 The value is the maximum depth to print."),
24769 &setdebuglist
, &showdebuglist
);
24771 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24772 Set debugging of the dwarf line reader."), _("\
24773 Show debugging of the dwarf line reader."), _("\
24774 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24775 A value of 1 (one) provides basic information.\n\
24776 A value greater than 1 provides more verbose information."),
24779 &setdebuglist
, &showdebuglist
);
24781 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24782 Set cross-checking of \"physname\" code against demangler."), _("\
24783 Show cross-checking of \"physname\" code against demangler."), _("\
24784 When enabled, GDB's internal \"physname\" code is checked against\n\
24786 NULL
, show_check_physname
,
24787 &setdebuglist
, &showdebuglist
);
24789 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24790 no_class
, &use_deprecated_index_sections
, _("\
24791 Set whether to use deprecated gdb_index sections."), _("\
24792 Show whether to use deprecated gdb_index sections."), _("\
24793 When enabled, deprecated .gdb_index sections are used anyway.\n\
24794 Normally they are ignored either because of a missing feature or\n\
24795 performance issue.\n\
24796 Warning: This option must be enabled before gdb reads the file."),
24799 &setlist
, &showlist
);
24801 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24802 &dwarf2_locexpr_funcs
);
24803 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24804 &dwarf2_loclist_funcs
);
24806 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24807 &dwarf2_block_frame_base_locexpr_funcs
);
24808 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24809 &dwarf2_block_frame_base_loclist_funcs
);
24812 selftests::register_test ("dw2_expand_symtabs_matching",
24813 selftests::dw2_expand_symtabs_matching::run_test
);
24814 selftests::register_test ("dwarf2_find_containing_comp_unit",
24815 selftests::find_containing_comp_unit::run_test
);