1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2023 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/read-debug-names.h"
45 #include "dwarf2/read-gdb-index.h"
46 #include "dwarf2/sect-names.h"
47 #include "dwarf2/stringify.h"
48 #include "dwarf2/public.h"
56 #include "gdb-demangle.h"
57 #include "filenames.h" /* for DOSish file names */
59 #include "complaints.h"
60 #include "dwarf2/expr.h"
61 #include "dwarf2/loc.h"
62 #include "cp-support.h"
68 #include "typeprint.h"
72 #include "gdbcore.h" /* for gnutarget */
73 #include "gdb/gdb-index.h"
78 #include "namespace.h"
79 #include "gdbsupport/function-view.h"
80 #include "gdbsupport/gdb_optional.h"
81 #include "gdbsupport/underlying.h"
82 #include "gdbsupport/hash_enum.h"
83 #include "filename-seen-cache.h"
87 #include <unordered_map>
88 #include "gdbsupport/selftest.h"
89 #include "rust-lang.h"
90 #include "gdbsupport/pathstuff.h"
91 #include "count-one-bits.h"
92 #include <unordered_set>
93 #include "dwarf2/abbrev-cache.h"
94 #include "cooked-index.h"
95 #include "split-name.h"
96 #include "gdbsupport/parallel-for.h"
97 #include "gdbsupport/thread-pool.h"
99 /* When == 1, print basic high level tracing messages.
100 When > 1, be more verbose.
101 This is in contrast to the low level DIE reading of dwarf_die_debug. */
102 static unsigned int dwarf_read_debug
= 0;
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
106 #define dwarf_read_debug_printf(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
110 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
112 #define dwarf_read_debug_printf_v(fmt, ...) \
113 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
116 /* When non-zero, dump DIEs after they are read in. */
117 static unsigned int dwarf_die_debug
= 0;
119 /* When non-zero, dump line number entries as they are read in. */
120 unsigned int dwarf_line_debug
= 0;
122 /* When true, cross-check physname against demangler. */
123 static bool check_physname
= false;
125 /* This is used to store the data that is always per objfile. */
126 static const registry
<objfile
>::key
<dwarf2_per_objfile
>
127 dwarf2_objfile_data_key
;
129 /* These are used to store the dwarf2_per_bfd objects.
131 objfiles having the same BFD, which doesn't require relocations, are going to
132 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
134 Other objfiles are not going to share a dwarf2_per_bfd with any other
135 objfiles, so they'll have their own version kept in the _objfile_data_key
137 static const registry
<bfd
>::key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
138 static const registry
<objfile
>::key
<dwarf2_per_bfd
>
139 dwarf2_per_bfd_objfile_data_key
;
141 /* The "aclass" indices for various kinds of computed DWARF symbols. */
143 static int dwarf2_locexpr_index
;
144 static int dwarf2_loclist_index
;
145 static int dwarf2_locexpr_block_index
;
146 static int dwarf2_loclist_block_index
;
148 /* Size of .debug_loclists section header for 32-bit DWARF format. */
149 #define LOCLIST_HEADER_SIZE32 12
151 /* Size of .debug_loclists section header for 64-bit DWARF format. */
152 #define LOCLIST_HEADER_SIZE64 20
154 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
155 #define RNGLIST_HEADER_SIZE32 12
157 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
158 #define RNGLIST_HEADER_SIZE64 20
160 /* See dwarf2/read.h. */
163 get_dwarf2_per_objfile (struct objfile
*objfile
)
165 return dwarf2_objfile_data_key
.get (objfile
);
168 /* Default names of the debugging sections. */
170 /* Note that if the debugging section has been compressed, it might
171 have a name like .zdebug_info. */
173 const struct dwarf2_debug_sections dwarf2_elf_names
=
175 { ".debug_info", ".zdebug_info" },
176 { ".debug_abbrev", ".zdebug_abbrev" },
177 { ".debug_line", ".zdebug_line" },
178 { ".debug_loc", ".zdebug_loc" },
179 { ".debug_loclists", ".zdebug_loclists" },
180 { ".debug_macinfo", ".zdebug_macinfo" },
181 { ".debug_macro", ".zdebug_macro" },
182 { ".debug_str", ".zdebug_str" },
183 { ".debug_str_offsets", ".zdebug_str_offsets" },
184 { ".debug_line_str", ".zdebug_line_str" },
185 { ".debug_ranges", ".zdebug_ranges" },
186 { ".debug_rnglists", ".zdebug_rnglists" },
187 { ".debug_types", ".zdebug_types" },
188 { ".debug_addr", ".zdebug_addr" },
189 { ".debug_frame", ".zdebug_frame" },
190 { ".eh_frame", NULL
},
191 { ".gdb_index", ".zgdb_index" },
192 { ".debug_names", ".zdebug_names" },
193 { ".debug_aranges", ".zdebug_aranges" },
197 /* List of DWO/DWP sections. */
199 static const struct dwop_section_names
201 struct dwarf2_section_names abbrev_dwo
;
202 struct dwarf2_section_names info_dwo
;
203 struct dwarf2_section_names line_dwo
;
204 struct dwarf2_section_names loc_dwo
;
205 struct dwarf2_section_names loclists_dwo
;
206 struct dwarf2_section_names macinfo_dwo
;
207 struct dwarf2_section_names macro_dwo
;
208 struct dwarf2_section_names rnglists_dwo
;
209 struct dwarf2_section_names str_dwo
;
210 struct dwarf2_section_names str_offsets_dwo
;
211 struct dwarf2_section_names types_dwo
;
212 struct dwarf2_section_names cu_index
;
213 struct dwarf2_section_names tu_index
;
217 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
218 { ".debug_info.dwo", ".zdebug_info.dwo" },
219 { ".debug_line.dwo", ".zdebug_line.dwo" },
220 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
221 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
222 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
223 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
224 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
225 { ".debug_str.dwo", ".zdebug_str.dwo" },
226 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
227 { ".debug_types.dwo", ".zdebug_types.dwo" },
228 { ".debug_cu_index", ".zdebug_cu_index" },
229 { ".debug_tu_index", ".zdebug_tu_index" },
232 /* local data types */
234 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
235 begin with a header, which contains the following information. */
236 struct loclists_rnglists_header
238 /* A 4-byte or 12-byte length containing the length of the
239 set of entries for this compilation unit, not including the
240 length field itself. */
243 /* A 2-byte version identifier. */
246 /* A 1-byte unsigned integer containing the size in bytes of an address on
247 the target system. */
248 unsigned char addr_size
;
250 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
251 on the target system. */
252 unsigned char segment_collector_size
;
254 /* A 4-byte count of the number of offsets that follow the header. */
255 unsigned int offset_entry_count
;
258 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
259 This includes type_unit_group and quick_file_names. */
261 struct stmt_list_hash
263 /* The DWO unit this table is from or NULL if there is none. */
264 struct dwo_unit
*dwo_unit
;
266 /* Offset in .debug_line or .debug_line.dwo. */
267 sect_offset line_sect_off
;
270 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
271 an object of this type. This contains elements of type unit groups
272 that can be shared across objfiles. The non-shareable parts are in
273 type_unit_group_unshareable. */
275 struct type_unit_group
277 /* The data used to construct the hash key. */
278 struct stmt_list_hash hash
{};
281 /* These sections are what may appear in a (real or virtual) DWO file. */
285 struct dwarf2_section_info abbrev
;
286 struct dwarf2_section_info line
;
287 struct dwarf2_section_info loc
;
288 struct dwarf2_section_info loclists
;
289 struct dwarf2_section_info macinfo
;
290 struct dwarf2_section_info macro
;
291 struct dwarf2_section_info rnglists
;
292 struct dwarf2_section_info str
;
293 struct dwarf2_section_info str_offsets
;
294 /* In the case of a virtual DWO file, these two are unused. */
295 struct dwarf2_section_info info
;
296 std::vector
<dwarf2_section_info
> types
;
299 /* CUs/TUs in DWP/DWO files. */
303 /* Backlink to the containing struct dwo_file. */
304 struct dwo_file
*dwo_file
;
306 /* The "id" that distinguishes this CU/TU.
307 .debug_info calls this "dwo_id", .debug_types calls this "signature".
308 Since signatures came first, we stick with it for consistency. */
311 /* The section this CU/TU lives in, in the DWO file. */
312 struct dwarf2_section_info
*section
;
314 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
315 sect_offset sect_off
;
318 /* For types, offset in the type's DIE of the type defined by this TU. */
319 cu_offset type_offset_in_tu
;
322 /* include/dwarf2.h defines the DWP section codes.
323 It defines a max value but it doesn't define a min value, which we
324 use for error checking, so provide one. */
326 enum dwp_v2_section_ids
331 /* Data for one DWO file.
333 This includes virtual DWO files (a virtual DWO file is a DWO file as it
334 appears in a DWP file). DWP files don't really have DWO files per se -
335 comdat folding of types "loses" the DWO file they came from, and from
336 a high level view DWP files appear to contain a mass of random types.
337 However, to maintain consistency with the non-DWP case we pretend DWP
338 files contain virtual DWO files, and we assign each TU with one virtual
339 DWO file (generally based on the line and abbrev section offsets -
340 a heuristic that seems to work in practice). */
344 dwo_file () = default;
345 DISABLE_COPY_AND_ASSIGN (dwo_file
);
347 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
348 For virtual DWO files the name is constructed from the section offsets
349 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
350 from related CU+TUs. */
351 const char *dwo_name
= nullptr;
353 /* The DW_AT_comp_dir attribute. */
354 const char *comp_dir
= nullptr;
356 /* The bfd, when the file is open. Otherwise this is NULL.
357 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
358 gdb_bfd_ref_ptr dbfd
;
360 /* The sections that make up this DWO file.
361 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
362 sections (for lack of a better name). */
363 struct dwo_sections sections
{};
365 /* The CUs in the file.
366 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
367 an extension to handle LLVM's Link Time Optimization output (where
368 multiple source files may be compiled into a single object/dwo pair). */
371 /* Table of TUs in the file.
372 Each element is a struct dwo_unit. */
376 /* These sections are what may appear in a DWP file. */
380 /* These are used by all DWP versions (1, 2 and 5). */
381 struct dwarf2_section_info str
;
382 struct dwarf2_section_info cu_index
;
383 struct dwarf2_section_info tu_index
;
385 /* These are only used by DWP version 2 and version 5 files.
386 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
387 sections are referenced by section number, and are not recorded here.
388 In DWP version 2 or 5 there is at most one copy of all these sections,
389 each section being (effectively) comprised of the concatenation of all of
390 the individual sections that exist in the version 1 format.
391 To keep the code simple we treat each of these concatenated pieces as a
392 section itself (a virtual section?). */
393 struct dwarf2_section_info abbrev
;
394 struct dwarf2_section_info info
;
395 struct dwarf2_section_info line
;
396 struct dwarf2_section_info loc
;
397 struct dwarf2_section_info loclists
;
398 struct dwarf2_section_info macinfo
;
399 struct dwarf2_section_info macro
;
400 struct dwarf2_section_info rnglists
;
401 struct dwarf2_section_info str_offsets
;
402 struct dwarf2_section_info types
;
405 /* These sections are what may appear in a virtual DWO file in DWP version 1.
406 A virtual DWO file is a DWO file as it appears in a DWP file. */
408 struct virtual_v1_dwo_sections
410 struct dwarf2_section_info abbrev
;
411 struct dwarf2_section_info line
;
412 struct dwarf2_section_info loc
;
413 struct dwarf2_section_info macinfo
;
414 struct dwarf2_section_info macro
;
415 struct dwarf2_section_info str_offsets
;
416 /* Each DWP hash table entry records one CU or one TU.
417 That is recorded here, and copied to dwo_unit.section. */
418 struct dwarf2_section_info info_or_types
;
421 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
422 In version 2, the sections of the DWO files are concatenated together
423 and stored in one section of that name. Thus each ELF section contains
424 several "virtual" sections. */
426 struct virtual_v2_or_v5_dwo_sections
428 bfd_size_type abbrev_offset
;
429 bfd_size_type abbrev_size
;
431 bfd_size_type line_offset
;
432 bfd_size_type line_size
;
434 bfd_size_type loc_offset
;
435 bfd_size_type loc_size
;
437 bfd_size_type loclists_offset
;
438 bfd_size_type loclists_size
;
440 bfd_size_type macinfo_offset
;
441 bfd_size_type macinfo_size
;
443 bfd_size_type macro_offset
;
444 bfd_size_type macro_size
;
446 bfd_size_type rnglists_offset
;
447 bfd_size_type rnglists_size
;
449 bfd_size_type str_offsets_offset
;
450 bfd_size_type str_offsets_size
;
452 /* Each DWP hash table entry records one CU or one TU.
453 That is recorded here, and copied to dwo_unit.section. */
454 bfd_size_type info_or_types_offset
;
455 bfd_size_type info_or_types_size
;
458 /* Contents of DWP hash tables. */
460 struct dwp_hash_table
462 uint32_t version
, nr_columns
;
463 uint32_t nr_units
, nr_slots
;
464 const gdb_byte
*hash_table
, *unit_table
;
469 const gdb_byte
*indices
;
473 /* This is indexed by column number and gives the id of the section
475 #define MAX_NR_V2_DWO_SECTIONS \
476 (1 /* .debug_info or .debug_types */ \
477 + 1 /* .debug_abbrev */ \
478 + 1 /* .debug_line */ \
479 + 1 /* .debug_loc */ \
480 + 1 /* .debug_str_offsets */ \
481 + 1 /* .debug_macro or .debug_macinfo */)
482 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
483 const gdb_byte
*offsets
;
484 const gdb_byte
*sizes
;
488 /* This is indexed by column number and gives the id of the section
490 #define MAX_NR_V5_DWO_SECTIONS \
491 (1 /* .debug_info */ \
492 + 1 /* .debug_abbrev */ \
493 + 1 /* .debug_line */ \
494 + 1 /* .debug_loclists */ \
495 + 1 /* .debug_str_offsets */ \
496 + 1 /* .debug_macro */ \
497 + 1 /* .debug_rnglists */)
498 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
499 const gdb_byte
*offsets
;
500 const gdb_byte
*sizes
;
505 /* Data for one DWP file. */
509 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
511 dbfd (std::move (abfd
))
515 /* Name of the file. */
518 /* File format version. */
522 gdb_bfd_ref_ptr dbfd
;
524 /* Section info for this file. */
525 struct dwp_sections sections
{};
527 /* Table of CUs in the file. */
528 const struct dwp_hash_table
*cus
= nullptr;
530 /* Table of TUs in the file. */
531 const struct dwp_hash_table
*tus
= nullptr;
533 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
537 /* Table to map ELF section numbers to their sections.
538 This is only needed for the DWP V1 file format. */
539 unsigned int num_sections
= 0;
540 asection
**elf_sections
= nullptr;
543 /* Struct used to pass misc. parameters to read_die_and_children, et
544 al. which are used for both .debug_info and .debug_types dies.
545 All parameters here are unchanging for the life of the call. This
546 struct exists to abstract away the constant parameters of die reading. */
548 struct die_reader_specs
550 /* The bfd of die_section. */
553 /* The CU of the DIE we are parsing. */
554 struct dwarf2_cu
*cu
;
556 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
557 struct dwo_file
*dwo_file
;
559 /* The section the die comes from.
560 This is either .debug_info or .debug_types, or the .dwo variants. */
561 struct dwarf2_section_info
*die_section
;
563 /* die_section->buffer. */
564 const gdb_byte
*buffer
;
566 /* The end of the buffer. */
567 const gdb_byte
*buffer_end
;
569 /* The abbreviation table to use when reading the DIEs. */
570 struct abbrev_table
*abbrev_table
;
573 /* A subclass of die_reader_specs that holds storage and has complex
574 constructor and destructor behavior. */
576 class cutu_reader
: public die_reader_specs
580 cutu_reader (dwarf2_per_cu_data
*this_cu
,
581 dwarf2_per_objfile
*per_objfile
,
582 struct abbrev_table
*abbrev_table
,
583 dwarf2_cu
*existing_cu
,
585 abbrev_cache
*cache
= nullptr);
587 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
588 dwarf2_per_objfile
*per_objfile
,
589 struct dwarf2_cu
*parent_cu
= nullptr,
590 struct dwo_file
*dwo_file
= nullptr);
592 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
594 cutu_reader (cutu_reader
&&) = default;
596 const gdb_byte
*info_ptr
= nullptr;
597 struct die_info
*comp_unit_die
= nullptr;
598 bool dummy_p
= false;
600 /* Release the new CU, putting it on the chain. This cannot be done
604 /* Release the abbrev table, transferring ownership to the
606 abbrev_table_up
release_abbrev_table ()
608 return std::move (m_abbrev_table_holder
);
612 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
613 dwarf2_per_objfile
*per_objfile
,
614 dwarf2_cu
*existing_cu
);
616 struct dwarf2_per_cu_data
*m_this_cu
;
617 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
619 /* The ordinary abbreviation table. */
620 abbrev_table_up m_abbrev_table_holder
;
622 /* The DWO abbreviation table. */
623 abbrev_table_up m_dwo_abbrev_table
;
626 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
627 but this would require a corresponding change in unpack_field_as_long
629 static int bits_per_byte
= 8;
631 struct variant_part_builder
;
633 /* When reading a variant, we track a bit more information about the
634 field, and store it in an object of this type. */
638 int first_field
= -1;
641 /* A variant can contain other variant parts. */
642 std::vector
<variant_part_builder
> variant_parts
;
644 /* If we see a DW_TAG_variant, then this will be set if this is the
646 bool default_branch
= false;
647 /* If we see a DW_AT_discr_value, then this will be the discriminant
649 ULONGEST discriminant_value
= 0;
650 /* If we see a DW_AT_discr_list, then this is a pointer to the list
652 struct dwarf_block
*discr_list_data
= nullptr;
655 /* This represents a DW_TAG_variant_part. */
657 struct variant_part_builder
659 /* The offset of the discriminant field. */
660 sect_offset discriminant_offset
{};
662 /* Variants that are direct children of this variant part. */
663 std::vector
<variant_field
> variants
;
665 /* True if we're currently reading a variant. */
666 bool processing_variant
= false;
671 int accessibility
= 0;
673 /* Variant parts need to find the discriminant, which is a DIE
674 reference. We track the section offset of each field to make
677 struct field field
{};
682 const char *name
= nullptr;
683 std::vector
<struct fn_field
> fnfields
;
686 /* The routines that read and process dies for a C struct or C++ class
687 pass lists of data member fields and lists of member function fields
688 in an instance of a field_info structure, as defined below. */
691 /* List of data member and baseclasses fields. */
692 std::vector
<struct nextfield
> fields
;
693 std::vector
<struct nextfield
> baseclasses
;
695 /* Set if the accessibility of one of the fields is not public. */
696 bool non_public_fields
= false;
698 /* Member function fieldlist array, contains name of possibly overloaded
699 member function, number of overloaded member functions and a pointer
700 to the head of the member function field chain. */
701 std::vector
<struct fnfieldlist
> fnfieldlists
;
703 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
704 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
705 std::vector
<struct decl_field
> typedef_field_list
;
707 /* Nested types defined by this class and the number of elements in this
709 std::vector
<struct decl_field
> nested_types_list
;
711 /* If non-null, this is the variant part we are currently
713 variant_part_builder
*current_variant_part
= nullptr;
714 /* This holds all the top-level variant parts attached to the type
716 std::vector
<variant_part_builder
> variant_parts
;
718 /* Return the total number of fields (including baseclasses). */
721 return fields
.size () + baseclasses
.size ();
725 /* Loaded secondary compilation units are kept in memory until they
726 have not been referenced for the processing of this many
727 compilation units. Set this to zero to disable caching. Cache
728 sizes of up to at least twenty will improve startup time for
729 typical inter-CU-reference binaries, at an obvious memory cost. */
730 static int dwarf_max_cache_age
= 5;
732 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
733 struct cmd_list_element
*c
, const char *value
)
735 gdb_printf (file
, _("The upper bound on the age of cached "
736 "DWARF compilation units is %s.\n"),
740 /* local function prototypes */
742 static void dwarf2_find_base_address (struct die_info
*die
,
743 struct dwarf2_cu
*cu
);
745 class cooked_index_storage
;
746 static void build_type_psymtabs_reader (cutu_reader
*reader
,
747 cooked_index_storage
*storage
);
749 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
751 static void var_decode_location (struct attribute
*attr
,
753 struct dwarf2_cu
*cu
);
755 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
757 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
759 const struct attr_abbrev
*,
761 bool allow_reprocess
= true);
763 /* Note that the default for TAG is chosen because it only matters
764 when reading the top-level DIE, and that function is careful to
765 pass the correct tag. */
766 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
767 struct attribute
*attr
,
768 dwarf_tag tag
= DW_TAG_padding
);
770 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
772 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
773 dwarf2_section_info
*, sect_offset
);
775 static const char *read_indirect_string
776 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
777 const struct comp_unit_head
*, unsigned int *);
779 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
783 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
786 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
789 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
792 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
793 struct dwarf2_cu
*cu
);
795 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
797 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
798 struct dwarf2_cu
*cu
);
800 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
802 static struct die_info
*die_specification (struct die_info
*die
,
803 struct dwarf2_cu
**);
805 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
806 struct dwarf2_cu
*cu
,
807 const char *comp_dir
);
809 static void dwarf_decode_lines (struct line_header
*,
811 CORE_ADDR
, int decode_mapping
);
813 static void dwarf2_start_subfile (dwarf2_cu
*cu
, const file_entry
&fe
,
814 const line_header
&lh
);
816 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
817 struct dwarf2_cu
*, struct symbol
* = NULL
);
819 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
822 static void dwarf2_const_value_attr (const struct attribute
*attr
,
825 struct obstack
*obstack
,
826 struct dwarf2_cu
*cu
, LONGEST
*value
,
827 const gdb_byte
**bytes
,
828 struct dwarf2_locexpr_baton
**baton
);
830 static struct type
*read_subrange_index_type (struct die_info
*die
,
831 struct dwarf2_cu
*cu
);
833 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
835 static int need_gnat_info (struct dwarf2_cu
*);
837 static struct type
*die_descriptive_type (struct die_info
*,
840 static void set_descriptive_type (struct type
*, struct die_info
*,
843 static struct type
*die_containing_type (struct die_info
*,
846 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
849 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
851 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
853 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
855 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
856 const char *suffix
, int physname
,
857 struct dwarf2_cu
*cu
);
859 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
861 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
863 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
865 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
867 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
869 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
871 /* Return the .debug_loclists section to use for cu. */
872 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
874 /* Return the .debug_rnglists section to use for cu. */
875 static struct dwarf2_section_info
*cu_debug_rnglists_section
876 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
878 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
879 values. Keep the items ordered with increasing constraints compliance. */
882 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
883 PC_BOUNDS_NOT_PRESENT
,
885 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
886 were present but they do not form a valid range of PC addresses. */
889 /* Discontiguous range was found - that is DW_AT_ranges was found. */
892 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
896 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
897 CORE_ADDR
*, CORE_ADDR
*,
902 static void get_scope_pc_bounds (struct die_info
*,
903 CORE_ADDR
*, CORE_ADDR
*,
906 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
907 CORE_ADDR
, struct dwarf2_cu
*);
909 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
912 static void dwarf2_attach_fields_to_type (struct field_info
*,
913 struct type
*, struct dwarf2_cu
*);
915 static void dwarf2_add_member_fn (struct field_info
*,
916 struct die_info
*, struct type
*,
919 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
923 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
925 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
927 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
929 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
931 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
933 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
935 static bool read_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
937 static struct type
*read_module_type (struct die_info
*die
,
938 struct dwarf2_cu
*cu
);
940 static const char *namespace_name (struct die_info
*die
,
941 int *is_anonymous
, struct dwarf2_cu
*);
943 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
945 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
948 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
951 static struct die_info
*read_die_and_siblings_1
952 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
955 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
956 const gdb_byte
*info_ptr
,
957 const gdb_byte
**new_info_ptr
,
958 struct die_info
*parent
);
960 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
961 struct die_info
**, const gdb_byte
*,
964 static const gdb_byte
*read_toplevel_die (const struct die_reader_specs
*,
967 gdb::array_view
<attribute
*> = {});
969 static void process_die (struct die_info
*, struct dwarf2_cu
*);
971 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
974 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
976 static const char *dwarf2_full_name (const char *name
,
977 struct die_info
*die
,
978 struct dwarf2_cu
*cu
);
980 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
981 struct dwarf2_cu
*cu
);
983 static struct die_info
*dwarf2_extension (struct die_info
*die
,
984 struct dwarf2_cu
**);
986 static void store_in_ref_table (struct die_info
*,
989 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
990 const struct attribute
*,
991 struct dwarf2_cu
**);
993 static struct die_info
*follow_die_ref (struct die_info
*,
994 const struct attribute
*,
995 struct dwarf2_cu
**);
997 static struct die_info
*follow_die_sig (struct die_info
*,
998 const struct attribute
*,
999 struct dwarf2_cu
**);
1001 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1002 struct dwarf2_cu
*);
1004 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1005 const struct attribute
*,
1006 struct dwarf2_cu
*);
1008 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1009 dwarf2_per_objfile
*per_objfile
);
1011 static void read_signatured_type (signatured_type
*sig_type
,
1012 dwarf2_per_objfile
*per_objfile
);
1014 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1015 struct die_info
*die
, struct dwarf2_cu
*cu
,
1016 struct dynamic_prop
*prop
, struct type
*type
);
1018 /* memory allocation interface */
1020 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1022 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1024 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1025 struct dwarf2_loclist_baton
*baton
,
1026 const struct attribute
*attr
);
1028 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1030 struct dwarf2_cu
*cu
,
1033 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1034 const gdb_byte
*info_ptr
,
1035 const struct abbrev_info
*abbrev
,
1036 bool do_skip_children
= true);
1038 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1039 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1040 dwarf2_per_bfd
*per_bfd
);
1042 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1043 struct die_info
*comp_unit_die
,
1044 enum language pretend_language
);
1046 static struct type
*set_die_type (struct die_info
*, struct type
*,
1047 struct dwarf2_cu
*, bool = false);
1049 static void create_all_units (dwarf2_per_objfile
*per_objfile
);
1051 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1052 dwarf2_per_objfile
*per_objfile
,
1053 dwarf2_cu
*existing_cu
,
1055 enum language pretend_language
);
1057 static void process_full_comp_unit (dwarf2_cu
*cu
,
1058 enum language pretend_language
);
1060 static void process_full_type_unit (dwarf2_cu
*cu
,
1061 enum language pretend_language
);
1063 static struct type
*get_die_type_at_offset (sect_offset
,
1064 dwarf2_per_cu_data
*per_cu
,
1065 dwarf2_per_objfile
*per_objfile
);
1067 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1069 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1070 dwarf2_per_objfile
*per_objfile
,
1071 enum language pretend_language
);
1073 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1075 /* Class, the destructor of which frees all allocated queue entries. This
1076 will only have work to do if an error was thrown while processing the
1077 dwarf. If no error was thrown then the queue entries should have all
1078 been processed, and freed, as we went along. */
1080 class dwarf2_queue_guard
1083 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1084 : m_per_objfile (per_objfile
)
1086 gdb_assert (!m_per_objfile
->queue
.has_value ());
1088 m_per_objfile
->queue
.emplace ();
1091 /* Free any entries remaining on the queue. There should only be
1092 entries left if we hit an error while processing the dwarf. */
1093 ~dwarf2_queue_guard ()
1095 gdb_assert (m_per_objfile
->queue
.has_value ());
1097 m_per_objfile
->queue
.reset ();
1100 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1103 dwarf2_per_objfile
*m_per_objfile
;
1106 dwarf2_queue_item::~dwarf2_queue_item ()
1108 /* Anything still marked queued is likely to be in an
1109 inconsistent state, so discard it. */
1112 per_objfile
->remove_cu (per_cu
);
1117 /* See dwarf2/read.h. */
1120 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1122 if (data
->is_debug_types
)
1123 delete static_cast<signatured_type
*> (data
);
1128 static file_and_directory
&find_file_and_directory
1129 (struct die_info
*die
, struct dwarf2_cu
*cu
);
1131 static const char *compute_include_file_name
1132 (const struct line_header
*lh
,
1133 const file_entry
&fe
,
1134 const file_and_directory
&cu_info
,
1135 std::string
&name_holder
);
1137 static htab_up
allocate_dwo_unit_table ();
1139 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1140 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1141 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1143 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1145 static struct dwo_unit
*lookup_dwo_comp_unit
1146 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1147 ULONGEST signature
);
1149 static struct dwo_unit
*lookup_dwo_type_unit
1150 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1152 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1154 /* A unique pointer to a dwo_file. */
1156 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1158 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1160 static void check_producer (struct dwarf2_cu
*cu
);
1162 /* Various complaints about symbol reading that don't abort the process. */
1165 dwarf2_debug_line_missing_file_complaint (void)
1167 complaint (_(".debug_line section has line data without a file"));
1171 dwarf2_debug_line_missing_end_sequence_complaint (void)
1173 complaint (_(".debug_line section has line "
1174 "program sequence without an end"));
1178 dwarf2_complex_location_expr_complaint (void)
1180 complaint (_("location expression too complex"));
1184 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1187 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1192 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1194 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1198 /* Hash function for line_header_hash. */
1201 line_header_hash (const struct line_header
*ofs
)
1203 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1206 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1209 line_header_hash_voidp (const void *item
)
1211 const struct line_header
*ofs
= (const struct line_header
*) item
;
1213 return line_header_hash (ofs
);
1216 /* Equality function for line_header_hash. */
1219 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1221 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1222 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1224 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1225 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1228 /* See declaration. */
1230 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1233 can_copy (can_copy_
)
1236 names
= &dwarf2_elf_names
;
1238 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1239 locate_sections (obfd
, sec
, *names
);
1242 dwarf2_per_bfd::~dwarf2_per_bfd ()
1244 /* Data from the per-BFD may be needed when finalizing the cooked
1245 index table, so wait here while this happens. */
1246 if (index_table
!= nullptr)
1247 index_table
->wait_completely ();
1249 for (auto &per_cu
: all_units
)
1251 per_cu
->imported_symtabs_free ();
1252 per_cu
->free_cached_file_names ();
1255 /* Everything else should be on this->obstack. */
1261 dwarf2_per_objfile::remove_all_cus ()
1263 gdb_assert (!queue
.has_value ());
1265 m_dwarf2_cus
.clear ();
1268 /* A helper class that calls free_cached_comp_units on
1271 class free_cached_comp_units
1275 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1276 : m_per_objfile (per_objfile
)
1280 ~free_cached_comp_units ()
1282 m_per_objfile
->remove_all_cus ();
1285 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1289 dwarf2_per_objfile
*m_per_objfile
;
1295 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1297 if (per_cu
->index
< this->m_symtabs
.size ())
1298 return this->m_symtabs
[per_cu
->index
] != nullptr;
1305 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1307 if (per_cu
->index
< this->m_symtabs
.size ())
1308 return this->m_symtabs
[per_cu
->index
];
1315 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1316 compunit_symtab
*symtab
)
1318 if (per_cu
->index
>= this->m_symtabs
.size ())
1319 this->m_symtabs
.resize (per_cu
->index
+ 1);
1320 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1321 this->m_symtabs
[per_cu
->index
] = symtab
;
1324 /* Try to locate the sections we need for DWARF 2 debugging
1325 information and return true if we have enough to do something.
1326 NAMES points to the dwarf2 section names, or is NULL if the standard
1327 ELF names are used. CAN_COPY is true for formats where symbol
1328 interposition is possible and so symbol values must follow copy
1329 relocation rules. */
1332 dwarf2_has_info (struct objfile
*objfile
,
1333 const struct dwarf2_debug_sections
*names
,
1336 if (objfile
->flags
& OBJF_READNEVER
)
1339 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1341 if (per_objfile
== NULL
)
1343 dwarf2_per_bfd
*per_bfd
;
1345 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1346 BFD doesn't require relocations.
1348 We don't share with objfiles for which -readnow was requested,
1349 because it would complicate things when loading the same BFD with
1350 -readnow and then without -readnow. */
1351 if (!gdb_bfd_requires_relocations (objfile
->obfd
.get ())
1352 && (objfile
->flags
& OBJF_READNOW
) == 0)
1354 /* See if one has been created for this BFD yet. */
1355 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
.get ());
1357 if (per_bfd
== nullptr)
1359 /* No, create it now. */
1360 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
.get (), names
,
1362 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
.get (), per_bfd
);
1367 /* No sharing possible, create one specifically for this objfile. */
1368 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
.get (), names
, can_copy
);
1369 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1372 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1375 return (!per_objfile
->per_bfd
->info
.is_virtual
1376 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1377 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1378 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1381 /* See declaration. */
1384 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1385 const dwarf2_debug_sections
&names
)
1387 flagword aflag
= bfd_section_flags (sectp
);
1389 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1392 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1393 > bfd_get_file_size (abfd
))
1395 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1396 warning (_("Discarding section %s which has a section size (%s"
1397 ") larger than the file size [in module %s]"),
1398 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1399 bfd_get_filename (abfd
));
1401 else if (names
.info
.matches (sectp
->name
))
1403 this->info
.s
.section
= sectp
;
1404 this->info
.size
= bfd_section_size (sectp
);
1406 else if (names
.abbrev
.matches (sectp
->name
))
1408 this->abbrev
.s
.section
= sectp
;
1409 this->abbrev
.size
= bfd_section_size (sectp
);
1411 else if (names
.line
.matches (sectp
->name
))
1413 this->line
.s
.section
= sectp
;
1414 this->line
.size
= bfd_section_size (sectp
);
1416 else if (names
.loc
.matches (sectp
->name
))
1418 this->loc
.s
.section
= sectp
;
1419 this->loc
.size
= bfd_section_size (sectp
);
1421 else if (names
.loclists
.matches (sectp
->name
))
1423 this->loclists
.s
.section
= sectp
;
1424 this->loclists
.size
= bfd_section_size (sectp
);
1426 else if (names
.macinfo
.matches (sectp
->name
))
1428 this->macinfo
.s
.section
= sectp
;
1429 this->macinfo
.size
= bfd_section_size (sectp
);
1431 else if (names
.macro
.matches (sectp
->name
))
1433 this->macro
.s
.section
= sectp
;
1434 this->macro
.size
= bfd_section_size (sectp
);
1436 else if (names
.str
.matches (sectp
->name
))
1438 this->str
.s
.section
= sectp
;
1439 this->str
.size
= bfd_section_size (sectp
);
1441 else if (names
.str_offsets
.matches (sectp
->name
))
1443 this->str_offsets
.s
.section
= sectp
;
1444 this->str_offsets
.size
= bfd_section_size (sectp
);
1446 else if (names
.line_str
.matches (sectp
->name
))
1448 this->line_str
.s
.section
= sectp
;
1449 this->line_str
.size
= bfd_section_size (sectp
);
1451 else if (names
.addr
.matches (sectp
->name
))
1453 this->addr
.s
.section
= sectp
;
1454 this->addr
.size
= bfd_section_size (sectp
);
1456 else if (names
.frame
.matches (sectp
->name
))
1458 this->frame
.s
.section
= sectp
;
1459 this->frame
.size
= bfd_section_size (sectp
);
1461 else if (names
.eh_frame
.matches (sectp
->name
))
1463 this->eh_frame
.s
.section
= sectp
;
1464 this->eh_frame
.size
= bfd_section_size (sectp
);
1466 else if (names
.ranges
.matches (sectp
->name
))
1468 this->ranges
.s
.section
= sectp
;
1469 this->ranges
.size
= bfd_section_size (sectp
);
1471 else if (names
.rnglists
.matches (sectp
->name
))
1473 this->rnglists
.s
.section
= sectp
;
1474 this->rnglists
.size
= bfd_section_size (sectp
);
1476 else if (names
.types
.matches (sectp
->name
))
1478 struct dwarf2_section_info type_section
;
1480 memset (&type_section
, 0, sizeof (type_section
));
1481 type_section
.s
.section
= sectp
;
1482 type_section
.size
= bfd_section_size (sectp
);
1484 this->types
.push_back (type_section
);
1486 else if (names
.gdb_index
.matches (sectp
->name
))
1488 this->gdb_index
.s
.section
= sectp
;
1489 this->gdb_index
.size
= bfd_section_size (sectp
);
1491 else if (names
.debug_names
.matches (sectp
->name
))
1493 this->debug_names
.s
.section
= sectp
;
1494 this->debug_names
.size
= bfd_section_size (sectp
);
1496 else if (names
.debug_aranges
.matches (sectp
->name
))
1498 this->debug_aranges
.s
.section
= sectp
;
1499 this->debug_aranges
.size
= bfd_section_size (sectp
);
1502 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1503 && bfd_section_vma (sectp
) == 0)
1504 this->has_section_at_zero
= true;
1507 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1511 dwarf2_get_section_info (struct objfile
*objfile
,
1512 enum dwarf2_section_enum sect
,
1513 asection
**sectp
, const gdb_byte
**bufp
,
1514 bfd_size_type
*sizep
)
1516 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1517 struct dwarf2_section_info
*info
;
1519 /* We may see an objfile without any DWARF, in which case we just
1521 if (per_objfile
== NULL
)
1530 case DWARF2_DEBUG_FRAME
:
1531 info
= &per_objfile
->per_bfd
->frame
;
1533 case DWARF2_EH_FRAME
:
1534 info
= &per_objfile
->per_bfd
->eh_frame
;
1537 gdb_assert_not_reached ("unexpected section");
1540 info
->read (objfile
);
1542 *sectp
= info
->get_bfd_section ();
1543 *bufp
= info
->buffer
;
1544 *sizep
= info
->size
;
1547 /* See dwarf2/read.h. */
1550 dwarf2_per_bfd::map_info_sections (struct objfile
*objfile
)
1552 info
.read (objfile
);
1553 abbrev
.read (objfile
);
1554 line
.read (objfile
);
1556 str_offsets
.read (objfile
);
1557 line_str
.read (objfile
);
1558 ranges
.read (objfile
);
1559 rnglists
.read (objfile
);
1560 addr
.read (objfile
);
1562 for (auto §ion
: types
)
1563 section
.read (objfile
);
1567 /* DWARF quick_symbol_functions support. */
1569 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1570 unique line tables, so we maintain a separate table of all .debug_line
1571 derived entries to support the sharing.
1572 All the quick functions need is the list of file names. We discard the
1573 line_header when we're done and don't need to record it here. */
1574 struct quick_file_names
1576 /* The data used to construct the hash key. */
1577 struct stmt_list_hash hash
;
1579 /* The number of entries in file_names, real_names. */
1580 unsigned int num_file_names
;
1582 /* The CU directory, as given by DW_AT_comp_dir. May be
1584 const char *comp_dir
;
1586 /* The file names from the line table, after being run through
1588 const char **file_names
;
1590 /* The file names from the line table after being run through
1591 gdb_realpath. These are computed lazily. */
1592 const char **real_names
;
1595 /* With OBJF_READNOW, the DWARF reader expands all CUs immediately.
1596 It's handy in this case to have an empty implementation of the
1597 quick symbol functions, to avoid special cases in the rest of the
1600 struct readnow_functions
: public dwarf2_base_index_functions
1602 void dump (struct objfile
*objfile
) override
1606 void expand_matching_symbols
1608 const lookup_name_info
&lookup_name
,
1611 symbol_compare_ftype
*ordered_compare
) override
1615 bool expand_symtabs_matching
1616 (struct objfile
*objfile
,
1617 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1618 const lookup_name_info
*lookup_name
,
1619 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1620 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1621 block_search_flags search_flags
,
1623 enum search_domain kind
) override
1629 /* Utility hash function for a stmt_list_hash. */
1632 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
1636 if (stmt_list_hash
->dwo_unit
!= NULL
)
1637 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
1638 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
1642 /* Utility equality function for a stmt_list_hash. */
1645 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
1646 const struct stmt_list_hash
*rhs
)
1648 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
1650 if (lhs
->dwo_unit
!= NULL
1651 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
1654 return lhs
->line_sect_off
== rhs
->line_sect_off
;
1657 /* Hash function for a quick_file_names. */
1660 hash_file_name_entry (const void *e
)
1662 const struct quick_file_names
*file_data
1663 = (const struct quick_file_names
*) e
;
1665 return hash_stmt_list_entry (&file_data
->hash
);
1668 /* Equality function for a quick_file_names. */
1671 eq_file_name_entry (const void *a
, const void *b
)
1673 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
1674 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
1676 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
1682 create_quick_file_names_table (unsigned int nr_initial_entries
)
1684 return htab_up (htab_create_alloc (nr_initial_entries
,
1685 hash_file_name_entry
, eq_file_name_entry
,
1686 nullptr, xcalloc
, xfree
));
1689 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
1690 function is unrelated to symtabs, symtab would have to be created afterwards.
1691 You should call age_cached_comp_units after processing the CU. */
1694 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1697 if (per_cu
->is_debug_types
)
1698 load_full_type_unit (per_cu
, per_objfile
);
1700 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
1701 skip_partial
, language_minimal
);
1703 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
1705 return nullptr; /* Dummy CU. */
1707 dwarf2_find_base_address (cu
->dies
, cu
);
1712 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
1715 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
1716 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
1719 /* The destructor of dwarf2_queue_guard frees any entries left on
1720 the queue. After this point we're guaranteed to leave this function
1721 with the dwarf queue empty. */
1722 dwarf2_queue_guard
q_guard (per_objfile
);
1724 if (!per_objfile
->symtab_set_p (per_cu
))
1726 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
1727 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
1729 /* If we just loaded a CU from a DWO, and we're working with an index
1730 that may badly handle TUs, load all the TUs in that DWO as well.
1731 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
1732 if (!per_cu
->is_debug_types
1734 && cu
->dwo_unit
!= NULL
1735 && per_objfile
->per_bfd
->index_table
!= NULL
1736 && !per_objfile
->per_bfd
->index_table
->version_check ()
1737 /* DWP files aren't supported yet. */
1738 && get_dwp_file (per_objfile
) == NULL
)
1739 queue_and_load_all_dwo_tus (cu
);
1742 process_queue (per_objfile
);
1745 /* Age the cache, releasing compilation units that have not
1746 been used recently. */
1747 per_objfile
->age_comp_units ();
1750 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
1751 the per-objfile for which this symtab is instantiated.
1753 Returns the resulting symbol table. */
1755 static struct compunit_symtab
*
1756 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
1757 dwarf2_per_objfile
*per_objfile
,
1760 if (!per_objfile
->symtab_set_p (per_cu
))
1762 free_cached_comp_units
freer (per_objfile
);
1763 scoped_restore decrementer
= increment_reading_symtab ();
1764 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
1765 process_cu_includes (per_objfile
);
1768 return per_objfile
->get_symtab (per_cu
);
1773 dwarf2_per_cu_data_up
1774 dwarf2_per_bfd::allocate_per_cu ()
1776 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
1777 result
->per_bfd
= this;
1778 result
->index
= all_units
.size ();
1785 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
1787 signatured_type_up
result (new signatured_type (signature
));
1788 result
->per_bfd
= this;
1789 result
->index
= all_units
.size ();
1790 result
->is_debug_types
= true;
1797 dwarf2_per_cu_data_up
1798 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
1799 struct dwarf2_section_info
*section
,
1801 sect_offset sect_off
, ULONGEST length
)
1803 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
1804 the_cu
->sect_off
= sect_off
;
1805 the_cu
->set_length (length
);
1806 the_cu
->section
= section
;
1807 the_cu
->is_dwz
= is_dwz
;
1814 read_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
1815 dwarf2_section_info
*section
,
1816 addrmap
*mutable_map
)
1818 struct objfile
*objfile
= per_objfile
->objfile
;
1819 bfd
*abfd
= objfile
->obfd
.get ();
1820 struct gdbarch
*gdbarch
= objfile
->arch ();
1821 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
1822 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
1824 std::unordered_map
<sect_offset
,
1825 dwarf2_per_cu_data
*,
1826 gdb::hash_enum
<sect_offset
>>
1827 debug_info_offset_to_per_cu
;
1828 for (const auto &per_cu
: per_bfd
->all_units
)
1830 /* A TU will not need aranges, and skipping them here is an easy
1831 way of ignoring .debug_types -- and possibly seeing a
1832 duplicate section offset -- entirely. The same applies to
1833 units coming from a dwz file. */
1834 if (per_cu
->is_debug_types
|| per_cu
->is_dwz
)
1837 const auto insertpair
1838 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
1841 /* Assume no duplicate offsets in all_units. */
1842 gdb_assert (insertpair
.second
);
1845 std::set
<sect_offset
> debug_info_offset_seen
;
1847 section
->read (objfile
);
1849 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
1851 const gdb_byte
*addr
= section
->buffer
;
1853 while (addr
< section
->buffer
+ section
->size
)
1855 const gdb_byte
*const entry_addr
= addr
;
1856 unsigned int bytes_read
;
1858 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
1862 const gdb_byte
*const entry_end
= addr
+ entry_length
;
1863 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
1864 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
1865 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
1867 warning (_("Section .debug_aranges in %s entry at offset %s "
1868 "length %s exceeds section length %s, "
1869 "ignoring .debug_aranges."),
1870 objfile_name (objfile
),
1871 plongest (entry_addr
- section
->buffer
),
1872 plongest (bytes_read
+ entry_length
),
1873 pulongest (section
->size
));
1877 /* The version number. */
1878 const uint16_t version
= read_2_bytes (abfd
, addr
);
1882 warning (_("Section .debug_aranges in %s entry at offset %s "
1883 "has unsupported version %d, ignoring .debug_aranges."),
1884 objfile_name (objfile
),
1885 plongest (entry_addr
- section
->buffer
), version
);
1889 const uint64_t debug_info_offset
1890 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
1891 addr
+= offset_size
;
1892 const auto per_cu_it
1893 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
1894 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
1896 warning (_("Section .debug_aranges in %s entry at offset %s "
1897 "debug_info_offset %s does not exists, "
1898 "ignoring .debug_aranges."),
1899 objfile_name (objfile
),
1900 plongest (entry_addr
- section
->buffer
),
1901 pulongest (debug_info_offset
));
1904 const auto insertpair
1905 = debug_info_offset_seen
.insert (sect_offset (debug_info_offset
));
1906 if (!insertpair
.second
)
1908 warning (_("Section .debug_aranges in %s has duplicate "
1909 "debug_info_offset %s, ignoring .debug_aranges."),
1910 objfile_name (objfile
),
1911 sect_offset_str (sect_offset (debug_info_offset
)));
1914 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
1916 const uint8_t address_size
= *addr
++;
1917 if (address_size
< 1 || address_size
> 8)
1919 warning (_("Section .debug_aranges in %s entry at offset %s "
1920 "address_size %u is invalid, ignoring .debug_aranges."),
1921 objfile_name (objfile
),
1922 plongest (entry_addr
- section
->buffer
), address_size
);
1926 const uint8_t segment_selector_size
= *addr
++;
1927 if (segment_selector_size
!= 0)
1929 warning (_("Section .debug_aranges in %s entry at offset %s "
1930 "segment_selector_size %u is not supported, "
1931 "ignoring .debug_aranges."),
1932 objfile_name (objfile
),
1933 plongest (entry_addr
- section
->buffer
),
1934 segment_selector_size
);
1938 /* Must pad to an alignment boundary that is twice the address
1939 size. It is undocumented by the DWARF standard but GCC does
1940 use it. However, not every compiler does this. We can see
1941 whether it has happened by looking at the total length of the
1942 contents of the aranges for this CU -- it if isn't a multiple
1943 of twice the address size, then we skip any leftover
1945 addr
+= (entry_end
- addr
) % (2 * address_size
);
1947 while (addr
< entry_end
)
1949 if (addr
+ 2 * address_size
> entry_end
)
1951 warning (_("Section .debug_aranges in %s entry at offset %s "
1952 "address list is not properly terminated, "
1953 "ignoring .debug_aranges."),
1954 objfile_name (objfile
),
1955 plongest (entry_addr
- section
->buffer
));
1958 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
1960 addr
+= address_size
;
1961 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
1963 addr
+= address_size
;
1964 if (start
== 0 && length
== 0)
1966 /* This can happen on some targets with --gc-sections.
1967 This pair of values is also used to mark the end of
1968 the entries for a given CU, but we ignore it and
1969 instead handle termination using the check at the top
1973 if (start
== 0 && !per_bfd
->has_section_at_zero
)
1975 /* Symbol was eliminated due to a COMDAT group. */
1978 ULONGEST end
= start
+ length
;
1979 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
1981 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
1983 mutable_map
->set_empty (start
, end
- 1, per_cu
);
1986 per_cu
->addresses_seen
= true;
1992 /* die_reader_func for dw2_get_file_names. */
1995 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
1996 struct die_info
*comp_unit_die
)
1998 struct dwarf2_cu
*cu
= reader
->cu
;
1999 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2000 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2001 struct dwarf2_per_cu_data
*lh_cu
;
2002 struct attribute
*attr
;
2004 struct quick_file_names
*qfn
;
2006 gdb_assert (! this_cu
->is_debug_types
);
2008 this_cu
->files_read
= true;
2009 /* Our callers never want to match partial units -- instead they
2010 will match the enclosing full CU. */
2011 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2018 sect_offset line_offset
{};
2020 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
2022 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2023 if (attr
!= nullptr && attr
->form_is_unsigned ())
2025 struct quick_file_names find_entry
;
2027 line_offset
= (sect_offset
) attr
->as_unsigned ();
2029 /* We may have already read in this line header (TU line header sharing).
2030 If we have we're done. */
2031 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2032 find_entry
.hash
.line_sect_off
= line_offset
;
2033 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2034 &find_entry
, INSERT
);
2037 lh_cu
->file_names
= (struct quick_file_names
*) *slot
;
2041 lh
= dwarf_decode_line_header (line_offset
, cu
, fnd
.get_comp_dir ());
2045 if (!fnd
.is_unknown ())
2047 else if (lh
== nullptr)
2050 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2051 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2052 qfn
->hash
.line_sect_off
= line_offset
;
2053 /* There may not be a DW_AT_stmt_list. */
2054 if (slot
!= nullptr)
2057 std::vector
<const char *> include_names
;
2060 for (const auto &entry
: lh
->file_names ())
2062 std::string name_holder
;
2063 const char *include_name
=
2064 compute_include_file_name (lh
.get (), entry
, fnd
, name_holder
);
2065 if (include_name
!= nullptr)
2067 include_name
= per_objfile
->objfile
->intern (include_name
);
2068 include_names
.push_back (include_name
);
2073 qfn
->num_file_names
= offset
+ include_names
.size ();
2074 qfn
->comp_dir
= fnd
.intern_comp_dir (per_objfile
->objfile
);
2076 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2077 qfn
->num_file_names
);
2079 qfn
->file_names
[0] = per_objfile
->objfile
->intern (fnd
.get_name ());
2081 if (!include_names
.empty ())
2082 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
2083 include_names
.size () * sizeof (const char *));
2085 qfn
->real_names
= NULL
;
2087 lh_cu
->file_names
= qfn
;
2090 /* A helper for the "quick" functions which attempts to read the line
2091 table for THIS_CU. */
2093 static struct quick_file_names
*
2094 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2095 dwarf2_per_objfile
*per_objfile
)
2097 /* This should never be called for TUs. */
2098 gdb_assert (! this_cu
->is_debug_types
);
2100 if (this_cu
->files_read
)
2101 return this_cu
->file_names
;
2103 cutu_reader
reader (this_cu
, per_objfile
);
2104 if (!reader
.dummy_p
)
2105 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
2107 return this_cu
->file_names
;
2110 /* A helper for the "quick" functions which computes and caches the
2111 real path for a given file name from the line table. */
2114 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
2115 struct quick_file_names
*qfn
, int index
)
2117 if (qfn
->real_names
== NULL
)
2118 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
2119 qfn
->num_file_names
, const char *);
2121 if (qfn
->real_names
[index
] == NULL
)
2123 const char *dirname
= nullptr;
2125 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
2126 dirname
= qfn
->comp_dir
;
2128 gdb::unique_xmalloc_ptr
<char> fullname
;
2129 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
2131 qfn
->real_names
[index
] = fullname
.release ();
2134 return qfn
->real_names
[index
];
2138 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
2140 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2141 dwarf2_per_cu_data
*dwarf_cu
2142 = per_objfile
->per_bfd
->all_units
.back ().get ();
2143 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
2148 return cust
->primary_filetab ();
2154 dwarf2_per_cu_data::free_cached_file_names ()
2157 fnd
->forget_fullname ();
2159 if (per_bfd
== nullptr)
2162 struct quick_file_names
*file_data
= file_names
;
2163 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
2165 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
2167 xfree ((void *) file_data
->real_names
[i
]);
2168 file_data
->real_names
[i
] = nullptr;
2174 dwarf2_base_index_functions::forget_cached_source_info
2175 (struct objfile
*objfile
)
2177 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2179 for (auto &per_cu
: per_objfile
->per_bfd
->all_units
)
2180 per_cu
->free_cached_file_names ();
2184 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
2190 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2191 int total
= per_objfile
->per_bfd
->all_units
.size ();
2194 for (int i
= 0; i
< total
; ++i
)
2196 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
2198 if (!per_objfile
->symtab_set_p (per_cu
))
2201 gdb_printf (_(" Number of read CUs: %d\n"), total
- count
);
2202 gdb_printf (_(" Number of unread CUs: %d\n"), count
);
2206 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
2208 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2209 int total_units
= per_objfile
->per_bfd
->all_units
.size ();
2211 for (int i
= 0; i
< total_units
; ++i
)
2213 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
2215 /* We don't want to directly expand a partial CU, because if we
2216 read it with the wrong language, then assertion failures can
2217 be triggered later on. See PR symtab/23010. So, tell
2218 dw2_instantiate_symtab to skip partial CUs -- any important
2219 partial CU will be read via DW_TAG_imported_unit anyway. */
2220 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
2225 /* Starting from a search name, return the string that finds the upper
2226 bound of all strings that start with SEARCH_NAME in a sorted name
2227 list. Returns the empty string to indicate that the upper bound is
2228 the end of the list. */
2231 make_sort_after_prefix_name (const char *search_name
)
2233 /* When looking to complete "func", we find the upper bound of all
2234 symbols that start with "func" by looking for where we'd insert
2235 the closest string that would follow "func" in lexicographical
2236 order. Usually, that's "func"-with-last-character-incremented,
2237 i.e. "fund". Mind non-ASCII characters, though. Usually those
2238 will be UTF-8 multi-byte sequences, but we can't be certain.
2239 Especially mind the 0xff character, which is a valid character in
2240 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
2241 rule out compilers allowing it in identifiers. Note that
2242 conveniently, strcmp/strcasecmp are specified to compare
2243 characters interpreted as unsigned char. So what we do is treat
2244 the whole string as a base 256 number composed of a sequence of
2245 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
2246 to 0, and carries 1 to the following more-significant position.
2247 If the very first character in SEARCH_NAME ends up incremented
2248 and carries/overflows, then the upper bound is the end of the
2249 list. The string after the empty string is also the empty
2252 Some examples of this operation:
2254 SEARCH_NAME => "+1" RESULT
2258 "\xff" "a" "\xff" => "\xff" "b"
2263 Then, with these symbols for example:
2269 completing "func" looks for symbols between "func" and
2270 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
2271 which finds "func" and "func1", but not "fund".
2275 funcÿ (Latin1 'ÿ' [0xff])
2279 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
2280 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
2284 ÿÿ (Latin1 'ÿ' [0xff])
2287 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
2288 the end of the list.
2290 std::string after
= search_name
;
2291 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
2293 if (!after
.empty ())
2294 after
.back () = (unsigned char) after
.back () + 1;
2298 /* See declaration. */
2300 std::pair
<std::vector
<name_component
>::const_iterator
,
2301 std::vector
<name_component
>::const_iterator
>
2302 mapped_index_base::find_name_components_bounds
2303 (const lookup_name_info
&lookup_name_without_params
, language lang
,
2304 dwarf2_per_objfile
*per_objfile
) const
2307 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
2309 const char *lang_name
2310 = lookup_name_without_params
.language_lookup_name (lang
);
2312 /* Comparison function object for lower_bound that matches against a
2313 given symbol name. */
2314 auto lookup_compare_lower
= [&] (const name_component
&elem
,
2317 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
2318 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
2319 return name_cmp (elem_name
, name
) < 0;
2322 /* Comparison function object for upper_bound that matches against a
2323 given symbol name. */
2324 auto lookup_compare_upper
= [&] (const char *name
,
2325 const name_component
&elem
)
2327 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
2328 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
2329 return name_cmp (name
, elem_name
) < 0;
2332 auto begin
= this->name_components
.begin ();
2333 auto end
= this->name_components
.end ();
2335 /* Find the lower bound. */
2338 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
2341 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
2344 /* Find the upper bound. */
2347 if (lookup_name_without_params
.completion_mode ())
2349 /* In completion mode, we want UPPER to point past all
2350 symbols names that have the same prefix. I.e., with
2351 these symbols, and completing "func":
2353 function << lower bound
2355 other_function << upper bound
2357 We find the upper bound by looking for the insertion
2358 point of "func"-with-last-character-incremented,
2360 std::string after
= make_sort_after_prefix_name (lang_name
);
2363 return std::lower_bound (lower
, end
, after
.c_str (),
2364 lookup_compare_lower
);
2367 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
2370 return {lower
, upper
};
2373 /* See declaration. */
2376 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
2378 if (!this->name_components
.empty ())
2381 this->name_components_casing
= case_sensitivity
;
2383 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
2385 /* The code below only knows how to break apart components of C++
2386 symbol names (and other languages that use '::' as
2387 namespace/module separator) and Ada symbol names. */
2388 auto count
= this->symbol_name_count ();
2389 for (offset_type idx
= 0; idx
< count
; idx
++)
2391 if (this->symbol_name_slot_invalid (idx
))
2394 const char *name
= this->symbol_name_at (idx
, per_objfile
);
2396 /* Add each name component to the name component table. */
2397 unsigned int previous_len
= 0;
2399 if (strstr (name
, "::") != nullptr)
2401 for (unsigned int current_len
= cp_find_first_component (name
);
2402 name
[current_len
] != '\0';
2403 current_len
+= cp_find_first_component (name
+ current_len
))
2405 gdb_assert (name
[current_len
] == ':');
2406 this->name_components
.push_back ({previous_len
, idx
});
2407 /* Skip the '::'. */
2409 previous_len
= current_len
;
2414 /* Handle the Ada encoded (aka mangled) form here. */
2415 for (const char *iter
= strstr (name
, "__");
2417 iter
= strstr (iter
, "__"))
2419 this->name_components
.push_back ({previous_len
, idx
});
2421 previous_len
= iter
- name
;
2425 this->name_components
.push_back ({previous_len
, idx
});
2428 /* Sort name_components elements by name. */
2429 auto name_comp_compare
= [&] (const name_component
&left
,
2430 const name_component
&right
)
2432 const char *left_qualified
2433 = this->symbol_name_at (left
.idx
, per_objfile
);
2434 const char *right_qualified
2435 = this->symbol_name_at (right
.idx
, per_objfile
);
2437 const char *left_name
= left_qualified
+ left
.name_offset
;
2438 const char *right_name
= right_qualified
+ right
.name_offset
;
2440 return name_cmp (left_name
, right_name
) < 0;
2443 std::sort (this->name_components
.begin (),
2444 this->name_components
.end (),
2451 dw2_expand_symtabs_matching_symbol
2452 (mapped_index_base
&index
,
2453 const lookup_name_info
&lookup_name_in
,
2454 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2455 gdb::function_view
<bool (offset_type
)> match_callback
,
2456 dwarf2_per_objfile
*per_objfile
)
2458 lookup_name_info lookup_name_without_params
2459 = lookup_name_in
.make_ignore_params ();
2461 /* Build the symbol name component sorted vector, if we haven't
2463 index
.build_name_components (per_objfile
);
2465 /* The same symbol may appear more than once in the range though.
2466 E.g., if we're looking for symbols that complete "w", and we have
2467 a symbol named "w1::w2", we'll find the two name components for
2468 that same symbol in the range. To be sure we only call the
2469 callback once per symbol, we first collect the symbol name
2470 indexes that matched in a temporary vector and ignore
2472 std::vector
<offset_type
> matches
;
2474 struct name_and_matcher
2476 symbol_name_matcher_ftype
*matcher
;
2479 bool operator== (const name_and_matcher
&other
) const
2481 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
2485 /* A vector holding all the different symbol name matchers, for all
2487 std::vector
<name_and_matcher
> matchers
;
2489 for (int i
= 0; i
< nr_languages
; i
++)
2491 enum language lang_e
= (enum language
) i
;
2493 const language_defn
*lang
= language_def (lang_e
);
2494 symbol_name_matcher_ftype
*name_matcher
2495 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
2497 name_and_matcher key
{
2499 lookup_name_without_params
.language_lookup_name (lang_e
)
2502 /* Don't insert the same comparison routine more than once.
2503 Note that we do this linear walk. This is not a problem in
2504 practice because the number of supported languages is
2506 if (std::find (matchers
.begin (), matchers
.end (), key
)
2509 matchers
.push_back (std::move (key
));
2512 = index
.find_name_components_bounds (lookup_name_without_params
,
2513 lang_e
, per_objfile
);
2515 /* Now for each symbol name in range, check to see if we have a name
2516 match, and if so, call the MATCH_CALLBACK callback. */
2518 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
2520 const char *qualified
2521 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
2523 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
2524 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
2527 matches
.push_back (bounds
.first
->idx
);
2531 std::sort (matches
.begin (), matches
.end ());
2533 /* Finally call the callback, once per match. */
2536 for (offset_type idx
: matches
)
2540 if (!match_callback (idx
))
2549 /* Above we use a type wider than idx's for 'prev', since 0 and
2550 (offset_type)-1 are both possible values. */
2551 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
2558 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
2560 /* A mock .gdb_index/.debug_names-like name index table, enough to
2561 exercise dw2_expand_symtabs_matching_symbol, which works with the
2562 mapped_index_base interface. Builds an index from the symbol list
2563 passed as parameter to the constructor. */
2564 class mock_mapped_index
: public mapped_index_base
2567 mock_mapped_index (gdb::array_view
<const char *> symbols
)
2568 : m_symbol_table (symbols
)
2571 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
2573 /* Return the number of names in the symbol table. */
2574 size_t symbol_name_count () const override
2576 return m_symbol_table
.size ();
2579 /* Get the name of the symbol at IDX in the symbol table. */
2580 const char *symbol_name_at
2581 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
2583 return m_symbol_table
[idx
];
2586 quick_symbol_functions_up
make_quick_functions () const override
2592 gdb::array_view
<const char *> m_symbol_table
;
2595 /* Convenience function that converts a NULL pointer to a "<null>"
2596 string, to pass to print routines. */
2599 string_or_null (const char *str
)
2601 return str
!= NULL
? str
: "<null>";
2604 /* Check if a lookup_name_info built from
2605 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
2606 index. EXPECTED_LIST is the list of expected matches, in expected
2607 matching order. If no match expected, then an empty list is
2608 specified. Returns true on success. On failure prints a warning
2609 indicating the file:line that failed, and returns false. */
2612 check_match (const char *file
, int line
,
2613 mock_mapped_index
&mock_index
,
2614 const char *name
, symbol_name_match_type match_type
,
2615 bool completion_mode
,
2616 std::initializer_list
<const char *> expected_list
,
2617 dwarf2_per_objfile
*per_objfile
)
2619 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
2621 bool matched
= true;
2623 auto mismatch
= [&] (const char *expected_str
,
2626 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
2627 "expected=\"%s\", got=\"%s\"\n"),
2629 (match_type
== symbol_name_match_type::FULL
2631 name
, string_or_null (expected_str
), string_or_null (got
));
2635 auto expected_it
= expected_list
.begin ();
2636 auto expected_end
= expected_list
.end ();
2638 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
2640 [&] (offset_type idx
)
2642 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
2643 const char *expected_str
2644 = expected_it
== expected_end
? NULL
: *expected_it
++;
2646 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
2647 mismatch (expected_str
, matched_name
);
2651 const char *expected_str
2652 = expected_it
== expected_end
? NULL
: *expected_it
++;
2653 if (expected_str
!= NULL
)
2654 mismatch (expected_str
, NULL
);
2659 /* The symbols added to the mock mapped_index for testing (in
2661 static const char *test_symbols
[] = {
2670 "ns2::tmpl<int>::foo2",
2671 "(anonymous namespace)::A::B::C",
2673 /* These are used to check that the increment-last-char in the
2674 matching algorithm for completion doesn't match "t1_fund" when
2675 completing "t1_func". */
2681 /* A UTF-8 name with multi-byte sequences to make sure that
2682 cp-name-parser understands this as a single identifier ("função"
2683 is "function" in PT). */
2686 /* Test a symbol name that ends with a 0xff character, which is a
2687 valid character in non-UTF-8 source character sets (e.g. Latin1
2688 'ÿ'), and we can't rule out compilers allowing it in identifiers.
2689 We test this because the completion algorithm finds the upper
2690 bound of symbols by looking for the insertion point of
2691 "func"-with-last-character-incremented, i.e. "fund", and adding 1
2692 to 0xff should wraparound and carry to the previous character.
2693 See comments in make_sort_after_prefix_name. */
2696 /* Some more symbols with \377 (0xff). See above. */
2700 /* A name with all sorts of complications. Starts with "z" to make
2701 it easier for the completion tests below. */
2702 #define Z_SYM_NAME \
2703 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
2704 "::tuple<(anonymous namespace)::ui*, " \
2705 "std::default_delete<(anonymous namespace)::ui>, void>"
2710 /* Returns true if the mapped_index_base::find_name_component_bounds
2711 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
2712 in completion mode. */
2715 check_find_bounds_finds (mapped_index_base
&index
,
2716 const char *search_name
,
2717 gdb::array_view
<const char *> expected_syms
,
2718 dwarf2_per_objfile
*per_objfile
)
2720 lookup_name_info
lookup_name (search_name
,
2721 symbol_name_match_type::FULL
, true);
2723 auto bounds
= index
.find_name_components_bounds (lookup_name
,
2727 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
2728 if (distance
!= expected_syms
.size ())
2731 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
2733 auto nc_elem
= bounds
.first
+ exp_elem
;
2734 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
2735 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
2742 /* Test the lower-level mapped_index::find_name_component_bounds
2746 test_mapped_index_find_name_component_bounds ()
2748 mock_mapped_index
mock_index (test_symbols
);
2750 mock_index
.build_name_components (NULL
/* per_objfile */);
2752 /* Test the lower-level mapped_index::find_name_component_bounds
2753 method in completion mode. */
2755 static const char *expected_syms
[] = {
2760 SELF_CHECK (check_find_bounds_finds
2761 (mock_index
, "t1_func", expected_syms
,
2762 NULL
/* per_objfile */));
2765 /* Check that the increment-last-char in the name matching algorithm
2766 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. See
2767 make_sort_after_prefix_name. */
2769 static const char *expected_syms1
[] = {
2773 SELF_CHECK (check_find_bounds_finds
2774 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
2776 static const char *expected_syms2
[] = {
2779 SELF_CHECK (check_find_bounds_finds
2780 (mock_index
, "\377\377", expected_syms2
,
2781 NULL
/* per_objfile */));
2785 /* Test dw2_expand_symtabs_matching_symbol. */
2788 test_dw2_expand_symtabs_matching_symbol ()
2790 mock_mapped_index
mock_index (test_symbols
);
2792 /* We let all tests run until the end even if some fails, for debug
2794 bool any_mismatch
= false;
2796 /* Create the expected symbols list (an initializer_list). Needed
2797 because lists have commas, and we need to pass them to CHECK,
2798 which is a macro. */
2799 #define EXPECT(...) { __VA_ARGS__ }
2801 /* Wrapper for check_match that passes down the current
2802 __FILE__/__LINE__. */
2803 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
2804 any_mismatch |= !check_match (__FILE__, __LINE__, \
2806 NAME, MATCH_TYPE, COMPLETION_MODE, \
2807 EXPECTED_LIST, NULL)
2809 /* Identity checks. */
2810 for (const char *sym
: test_symbols
)
2812 /* Should be able to match all existing symbols. */
2813 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
2816 /* Should be able to match all existing symbols with
2818 std::string with_params
= std::string (sym
) + "(int)";
2819 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
2822 /* Should be able to match all existing symbols with
2823 parameters and qualifiers. */
2824 with_params
= std::string (sym
) + " ( int ) const";
2825 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
2828 /* This should really find sym, but cp-name-parser.y doesn't
2829 know about lvalue/rvalue qualifiers yet. */
2830 with_params
= std::string (sym
) + " ( int ) &&";
2831 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
2835 /* Check that the name matching algorithm for completion doesn't get
2836 confused with Latin1 'ÿ' / 0xff. See
2837 make_sort_after_prefix_name. */
2839 static const char str
[] = "\377";
2840 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
2841 EXPECT ("\377", "\377\377123"));
2844 /* Check that the increment-last-char in the matching algorithm for
2845 completion doesn't match "t1_fund" when completing "t1_func". */
2847 static const char str
[] = "t1_func";
2848 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
2849 EXPECT ("t1_func", "t1_func1"));
2852 /* Check that completion mode works at each prefix of the expected
2855 static const char str
[] = "function(int)";
2856 size_t len
= strlen (str
);
2859 for (size_t i
= 1; i
< len
; i
++)
2861 lookup
.assign (str
, i
);
2862 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
2863 EXPECT ("function"));
2867 /* While "w" is a prefix of both components, the match function
2868 should still only be called once. */
2870 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
2872 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
2876 /* Same, with a "complicated" symbol. */
2878 static const char str
[] = Z_SYM_NAME
;
2879 size_t len
= strlen (str
);
2882 for (size_t i
= 1; i
< len
; i
++)
2884 lookup
.assign (str
, i
);
2885 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
2886 EXPECT (Z_SYM_NAME
));
2890 /* In FULL mode, an incomplete symbol doesn't match. */
2892 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
2896 /* A complete symbol with parameters matches any overload, since the
2897 index has no overload info. */
2899 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
2900 EXPECT ("std::zfunction", "std::zfunction2"));
2901 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
2902 EXPECT ("std::zfunction", "std::zfunction2"));
2903 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
2904 EXPECT ("std::zfunction", "std::zfunction2"));
2907 /* Check that whitespace is ignored appropriately. A symbol with a
2908 template argument list. */
2910 static const char expected
[] = "ns::foo<int>";
2911 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
2913 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
2917 /* Check that whitespace is ignored appropriately. A symbol with a
2918 template argument list that includes a pointer. */
2920 static const char expected
[] = "ns::foo<char*>";
2921 /* Try both completion and non-completion modes. */
2922 static const bool completion_mode
[2] = {false, true};
2923 for (size_t i
= 0; i
< 2; i
++)
2925 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
2926 completion_mode
[i
], EXPECT (expected
));
2927 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
2928 completion_mode
[i
], EXPECT (expected
));
2930 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
2931 completion_mode
[i
], EXPECT (expected
));
2932 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
2933 completion_mode
[i
], EXPECT (expected
));
2938 /* Check method qualifiers are ignored. */
2939 static const char expected
[] = "ns::foo<char*>";
2940 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
2941 symbol_name_match_type::FULL
, true, EXPECT (expected
));
2942 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
2943 symbol_name_match_type::FULL
, true, EXPECT (expected
));
2944 CHECK_MATCH ("foo < char * > ( int ) const",
2945 symbol_name_match_type::WILD
, true, EXPECT (expected
));
2946 CHECK_MATCH ("foo < char * > ( int ) &&",
2947 symbol_name_match_type::WILD
, true, EXPECT (expected
));
2950 /* Test lookup names that don't match anything. */
2952 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
2955 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
2959 /* Some wild matching tests, exercising "(anonymous namespace)",
2960 which should not be confused with a parameter list. */
2962 static const char *syms
[] = {
2966 "A :: B :: C ( int )",
2971 for (const char *s
: syms
)
2973 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
2974 EXPECT ("(anonymous namespace)::A::B::C"));
2979 static const char expected
[] = "ns2::tmpl<int>::foo2";
2980 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
2982 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
2986 SELF_CHECK (!any_mismatch
);
2995 test_mapped_index_find_name_component_bounds ();
2996 test_dw2_expand_symtabs_matching_symbol ();
2999 }} // namespace selftests::dw2_expand_symtabs_matching
3001 #endif /* GDB_SELF_TEST */
3006 dw2_expand_symtabs_matching_one
3007 (dwarf2_per_cu_data
*per_cu
,
3008 dwarf2_per_objfile
*per_objfile
,
3009 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3010 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
3012 if (file_matcher
== NULL
|| per_cu
->mark
)
3014 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
3016 compunit_symtab
*symtab
3017 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3018 gdb_assert (symtab
!= nullptr);
3020 if (expansion_notify
!= NULL
&& symtab_was_null
)
3021 return expansion_notify (symtab
);
3029 dw_expand_symtabs_matching_file_matcher
3030 (dwarf2_per_objfile
*per_objfile
,
3031 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
3033 if (file_matcher
== NULL
)
3036 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
3038 NULL
, xcalloc
, xfree
));
3039 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
3041 NULL
, xcalloc
, xfree
));
3043 /* The rule is CUs specify all the files, including those used by
3044 any TU, so there's no need to scan TUs here. */
3046 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
3050 if (per_cu
->is_debug_types
)
3054 /* We only need to look at symtabs not already expanded. */
3055 if (per_objfile
->symtab_set_p (per_cu
.get ()))
3058 if (per_cu
->fnd
!= nullptr)
3060 file_and_directory
*fnd
= per_cu
->fnd
.get ();
3062 if (file_matcher (fnd
->get_name (), false))
3068 /* Before we invoke realpath, which can get expensive when many
3069 files are involved, do a quick comparison of the basenames. */
3070 if ((basenames_may_differ
3071 || file_matcher (lbasename (fnd
->get_name ()), true))
3072 && file_matcher (fnd
->get_fullname (), false))
3079 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
3081 if (file_data
== NULL
)
3084 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
3086 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
3092 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3094 const char *this_real_name
;
3096 if (file_matcher (file_data
->file_names
[j
], false))
3102 /* Before we invoke realpath, which can get expensive when many
3103 files are involved, do a quick comparison of the basenames. */
3104 if (!basenames_may_differ
3105 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3109 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3110 if (file_matcher (this_real_name
, false))
3117 void **slot
= htab_find_slot (per_cu
->mark
3118 ? visited_found
.get ()
3119 : visited_not_found
.get (),
3126 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
3129 static struct compunit_symtab
*
3130 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
3135 if (cust
->blockvector () != nullptr
3136 && blockvector_contains_pc (cust
->blockvector (), pc
))
3139 if (cust
->includes
== NULL
)
3142 for (i
= 0; cust
->includes
[i
]; ++i
)
3144 struct compunit_symtab
*s
= cust
->includes
[i
];
3146 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
3154 dwarf2_per_cu_data
*
3155 dwarf2_base_index_functions::find_per_cu (dwarf2_per_bfd
*per_bfd
,
3156 CORE_ADDR adjusted_pc
)
3158 if (per_bfd
->index_addrmap
== nullptr)
3161 void *obj
= per_bfd
->index_addrmap
->find (adjusted_pc
);
3162 return static_cast<dwarf2_per_cu_data
*> (obj
);
3165 struct compunit_symtab
*
3166 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
3167 (struct objfile
*objfile
,
3168 struct bound_minimal_symbol msymbol
,
3170 struct obj_section
*section
,
3173 struct compunit_symtab
*result
;
3175 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3177 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
3178 struct dwarf2_per_cu_data
*data
= find_per_cu (per_objfile
->per_bfd
,
3180 if (data
== nullptr)
3183 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
3184 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3185 paddress (objfile
->arch (), pc
));
3187 result
= recursively_find_pc_sect_compunit_symtab
3188 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
3190 if (warn_if_readin
&& result
== nullptr)
3191 warning (_("(Error: pc %s in address map, but not in symtab.)"),
3192 paddress (objfile
->arch (), pc
));
3198 dwarf2_base_index_functions::map_symbol_filenames
3199 (struct objfile
*objfile
,
3200 gdb::function_view
<symbol_filename_ftype
> fun
,
3203 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3205 /* Use caches to ensure we only call FUN once for each filename. */
3206 filename_seen_cache filenames_cache
;
3207 std::unordered_set
<quick_file_names
*> qfn_cache
;
3209 /* The rule is CUs specify all the files, including those used by any TU,
3210 so there's no need to scan TUs here. We can ignore file names coming
3211 from already-expanded CUs. It is possible that an expanded CU might
3212 reuse the file names data from a currently unexpanded CU, in this
3213 case we don't want to report the files from the unexpanded CU. */
3215 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
3217 if (!per_cu
->is_debug_types
3218 && per_objfile
->symtab_set_p (per_cu
.get ()))
3220 if (per_cu
->file_names
!= nullptr)
3221 qfn_cache
.insert (per_cu
->file_names
);
3225 for (dwarf2_per_cu_data
*per_cu
3226 : all_units_range (per_objfile
->per_bfd
))
3228 /* We only need to look at symtabs not already expanded. */
3229 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
3232 if (per_cu
->fnd
!= nullptr)
3234 file_and_directory
*fnd
= per_cu
->fnd
.get ();
3236 const char *filename
= fnd
->get_name ();
3237 const char *key
= filename
;
3238 const char *fullname
= nullptr;
3242 fullname
= fnd
->get_fullname ();
3246 if (!filenames_cache
.seen (key
))
3247 fun (filename
, fullname
);
3250 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3251 if (file_data
== nullptr
3252 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
3255 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3257 const char *filename
= file_data
->file_names
[j
];
3258 const char *key
= filename
;
3259 const char *fullname
= nullptr;
3263 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
3267 if (!filenames_cache
.seen (key
))
3268 fun (filename
, fullname
);
3274 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
3279 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
3282 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
3284 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3286 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
3288 /* Is this already expanded? */
3289 if (per_objfile
->symtab_set_p (per_cu
.get ()))
3292 /* It has not yet been expanded. */
3299 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
3300 to either a dwarf2_per_bfd or dwz_file object. */
3302 template <typename T
>
3303 static gdb::array_view
<const gdb_byte
>
3304 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
3306 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
3308 if (section
->empty ())
3311 /* Older elfutils strip versions could keep the section in the main
3312 executable while splitting it for the separate debug info file. */
3313 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
3316 section
->read (obj
);
3318 /* dwarf2_section_info::size is a bfd_size_type, while
3319 gdb::array_view works with size_t. On 32-bit hosts, with
3320 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
3321 is 32-bit. So we need an explicit narrowing conversion here.
3322 This is fine, because it's impossible to allocate or mmap an
3323 array/buffer larger than what size_t can represent. */
3324 return gdb::make_array_view (section
->buffer
, section
->size
);
3327 /* Lookup the index cache for the contents of the index associated to
3330 static gdb::array_view
<const gdb_byte
>
3331 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
3333 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
.get ());
3334 if (build_id
== nullptr)
3337 return global_index_cache
.lookup_gdb_index (build_id
,
3338 &dwarf2_per_bfd
->index_cache_res
);
3341 /* Same as the above, but for DWZ. */
3343 static gdb::array_view
<const gdb_byte
>
3344 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
3346 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
3347 if (build_id
== nullptr)
3350 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
3353 static quick_symbol_functions_up
make_cooked_index_funcs ();
3355 /* See dwarf2/public.h. */
3358 dwarf2_initialize_objfile (struct objfile
*objfile
)
3360 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3361 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3363 dwarf_read_debug_printf ("called");
3365 /* If we're about to read full symbols, don't bother with the
3366 indices. In this case we also don't care if some other debug
3367 format is making psymtabs, because they are all about to be
3369 if ((objfile
->flags
& OBJF_READNOW
))
3371 dwarf_read_debug_printf ("readnow requested");
3373 create_all_units (per_objfile
);
3374 per_bfd
->quick_file_names_table
3375 = create_quick_file_names_table (per_bfd
->all_units
.size ());
3377 objfile
->qf
.emplace_front (new readnow_functions
);
3381 /* Was a GDB index already read when we processed an objfile sharing
3383 if (per_bfd
->index_table
!= nullptr)
3385 dwarf_read_debug_printf ("re-using symbols");
3386 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
3390 if (dwarf2_read_debug_names (per_objfile
))
3392 dwarf_read_debug_printf ("found debug names");
3393 objfile
->qf
.push_front
3394 (per_bfd
->index_table
->make_quick_functions ());
3398 if (dwarf2_read_gdb_index (per_objfile
,
3399 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
3400 get_gdb_index_contents_from_section
<dwz_file
>))
3402 dwarf_read_debug_printf ("found gdb index from file");
3403 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
3407 /* ... otherwise, try to find the index in the index cache. */
3408 if (dwarf2_read_gdb_index (per_objfile
,
3409 get_gdb_index_contents_from_cache
,
3410 get_gdb_index_contents_from_cache_dwz
))
3412 dwarf_read_debug_printf ("found gdb index from cache");
3413 global_index_cache
.hit ();
3414 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
3418 global_index_cache
.miss ();
3419 objfile
->qf
.push_front (make_cooked_index_funcs ());
3424 /* Build a partial symbol table. */
3427 dwarf2_build_psymtabs (struct objfile
*objfile
)
3429 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3431 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3436 dwarf2_build_psymtabs_hard (per_objfile
);
3438 catch (const gdb_exception_error
&except
)
3440 exception_print (gdb_stderr
, except
);
3444 /* Find the base address of the compilation unit for range lists and
3445 location lists. It will normally be specified by DW_AT_low_pc.
3446 In DWARF-3 draft 4, the base address could be overridden by
3447 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3448 compilation units with discontinuous ranges. */
3451 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3453 struct attribute
*attr
;
3455 cu
->base_address
.reset ();
3457 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3458 if (attr
!= nullptr)
3459 cu
->base_address
= attr
->as_address ();
3462 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3463 if (attr
!= nullptr)
3464 cu
->base_address
= attr
->as_address ();
3468 /* Helper function that returns the proper abbrev section for
3471 static struct dwarf2_section_info
*
3472 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3474 struct dwarf2_section_info
*abbrev
;
3475 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
3477 if (this_cu
->is_dwz
)
3478 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
3480 abbrev
= &per_bfd
->abbrev
;
3485 /* Fetch the abbreviation table offset from a comp or type unit header. */
3488 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
3489 struct dwarf2_section_info
*section
,
3490 sect_offset sect_off
)
3492 bfd
*abfd
= section
->get_bfd_owner ();
3493 const gdb_byte
*info_ptr
;
3494 unsigned int initial_length_size
, offset_size
;
3497 section
->read (per_objfile
->objfile
);
3498 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
3499 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3500 offset_size
= initial_length_size
== 4 ? 4 : 8;
3501 info_ptr
+= initial_length_size
;
3503 version
= read_2_bytes (abfd
, info_ptr
);
3507 /* Skip unit type and address size. */
3511 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
3515 hash_signatured_type (const void *item
)
3517 const struct signatured_type
*sig_type
3518 = (const struct signatured_type
*) item
;
3520 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3521 return sig_type
->signature
;
3525 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3527 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
3528 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
3530 return lhs
->signature
== rhs
->signature
;
3536 allocate_signatured_type_table ()
3538 return htab_up (htab_create_alloc (41,
3539 hash_signatured_type
,
3541 NULL
, xcalloc
, xfree
));
3544 /* A helper for create_debug_types_hash_table. Read types from SECTION
3545 and fill them into TYPES_HTAB. It will process only type units,
3546 therefore DW_UT_type. */
3549 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
3550 struct dwo_file
*dwo_file
,
3551 dwarf2_section_info
*section
, htab_up
&types_htab
,
3552 rcuh_kind section_kind
)
3554 struct objfile
*objfile
= per_objfile
->objfile
;
3555 struct dwarf2_section_info
*abbrev_section
;
3557 const gdb_byte
*info_ptr
, *end_ptr
;
3559 abbrev_section
= &dwo_file
->sections
.abbrev
;
3561 dwarf_read_debug_printf ("Reading %s for %s",
3562 section
->get_name (),
3563 abbrev_section
->get_file_name ());
3565 section
->read (objfile
);
3566 info_ptr
= section
->buffer
;
3568 if (info_ptr
== NULL
)
3571 /* We can't set abfd until now because the section may be empty or
3572 not present, in which case the bfd is unknown. */
3573 abfd
= section
->get_bfd_owner ();
3575 /* We don't use cutu_reader here because we don't need to read
3576 any dies: the signature is in the header. */
3578 end_ptr
= info_ptr
+ section
->size
;
3579 while (info_ptr
< end_ptr
)
3581 signatured_type_up sig_type
;
3582 struct dwo_unit
*dwo_tu
;
3584 const gdb_byte
*ptr
= info_ptr
;
3585 struct comp_unit_head header
;
3586 unsigned int length
;
3588 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
3590 /* Initialize it due to a false compiler warning. */
3591 header
.signature
= -1;
3592 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
3594 /* We need to read the type's signature in order to build the hash
3595 table, but we don't need anything else just yet. */
3597 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
3598 abbrev_section
, ptr
, section_kind
);
3600 length
= header
.get_length_with_initial ();
3602 /* Skip dummy type units. */
3603 if (ptr
>= info_ptr
+ length
3604 || peek_abbrev_code (abfd
, ptr
) == 0
3605 || (header
.unit_type
!= DW_UT_type
3606 && header
.unit_type
!= DW_UT_split_type
))
3612 if (types_htab
== NULL
)
3613 types_htab
= allocate_dwo_unit_table ();
3615 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
3616 dwo_tu
->dwo_file
= dwo_file
;
3617 dwo_tu
->signature
= header
.signature
;
3618 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
3619 dwo_tu
->section
= section
;
3620 dwo_tu
->sect_off
= sect_off
;
3621 dwo_tu
->length
= length
;
3623 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
3624 gdb_assert (slot
!= NULL
);
3626 complaint (_("debug type entry at offset %s is duplicate to"
3627 " the entry at offset %s, signature %s"),
3628 sect_offset_str (sect_off
),
3629 sect_offset_str (dwo_tu
->sect_off
),
3630 hex_string (header
.signature
));
3633 dwarf_read_debug_printf_v (" offset %s, signature %s",
3634 sect_offset_str (sect_off
),
3635 hex_string (header
.signature
));
3641 /* Create the hash table of all entries in the .debug_types
3642 (or .debug_types.dwo) section(s).
3643 DWO_FILE is a pointer to the DWO file object.
3645 The result is a pointer to the hash table or NULL if there are no types.
3647 Note: This function processes DWO files only, not DWP files. */
3650 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
3651 struct dwo_file
*dwo_file
,
3652 gdb::array_view
<dwarf2_section_info
> type_sections
,
3653 htab_up
&types_htab
)
3655 for (dwarf2_section_info
§ion
: type_sections
)
3656 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
3660 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
3661 If SLOT is non-NULL, it is the entry to use in the hash table.
3662 Otherwise we find one. */
3664 static struct signatured_type
*
3665 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
3667 if (per_objfile
->per_bfd
->all_units
.size ()
3668 == per_objfile
->per_bfd
->all_units
.capacity ())
3669 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
3671 signatured_type_up sig_type_holder
3672 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
3673 signatured_type
*sig_type
= sig_type_holder
.get ();
3675 per_objfile
->per_bfd
->all_units
.emplace_back
3676 (sig_type_holder
.release ());
3680 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
3683 gdb_assert (*slot
== NULL
);
3685 /* The rest of sig_type must be filled in by the caller. */
3689 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
3690 Fill in SIG_ENTRY with DWO_ENTRY. */
3693 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
3694 struct signatured_type
*sig_entry
,
3695 struct dwo_unit
*dwo_entry
)
3697 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3699 /* Make sure we're not clobbering something we don't expect to. */
3700 gdb_assert (! sig_entry
->queued
);
3701 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
3702 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
3703 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
3704 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0
3705 || (to_underlying (sig_entry
->type_offset_in_section
)
3706 == to_underlying (dwo_entry
->type_offset_in_tu
)));
3707 gdb_assert (sig_entry
->type_unit_group
== NULL
);
3708 gdb_assert (sig_entry
->dwo_unit
== NULL
3709 || sig_entry
->dwo_unit
== dwo_entry
);
3711 sig_entry
->section
= dwo_entry
->section
;
3712 sig_entry
->sect_off
= dwo_entry
->sect_off
;
3713 sig_entry
->set_length (dwo_entry
->length
, false);
3714 sig_entry
->reading_dwo_directly
= 1;
3715 sig_entry
->per_bfd
= per_bfd
;
3716 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
3717 sig_entry
->dwo_unit
= dwo_entry
;
3720 /* Subroutine of lookup_signatured_type.
3721 If we haven't read the TU yet, create the signatured_type data structure
3722 for a TU to be read in directly from a DWO file, bypassing the stub.
3723 This is the "Stay in DWO Optimization": When there is no DWP file and we're
3724 using .gdb_index, then when reading a CU we want to stay in the DWO file
3725 containing that CU. Otherwise we could end up reading several other DWO
3726 files (due to comdat folding) to process the transitive closure of all the
3727 mentioned TUs, and that can be slow. The current DWO file will have every
3728 type signature that it needs.
3729 We only do this for .gdb_index because in the psymtab case we already have
3730 to read all the DWOs to build the type unit groups. */
3732 static struct signatured_type
*
3733 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
3735 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3736 struct dwo_file
*dwo_file
;
3737 struct dwo_unit find_dwo_entry
, *dwo_entry
;
3740 gdb_assert (cu
->dwo_unit
);
3742 /* If TU skeletons have been removed then we may not have read in any
3744 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
3745 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
3747 /* We only ever need to read in one copy of a signatured type.
3748 Use the global signatured_types array to do our own comdat-folding
3749 of types. If this is the first time we're reading this TU, and
3750 the TU has an entry in .gdb_index, replace the recorded data from
3751 .gdb_index with this TU. */
3753 signatured_type
find_sig_entry (sig
);
3754 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
3755 &find_sig_entry
, INSERT
);
3756 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
3758 /* We can get here with the TU already read, *or* in the process of being
3759 read. Don't reassign the global entry to point to this DWO if that's
3760 the case. Also note that if the TU is already being read, it may not
3761 have come from a DWO, the program may be a mix of Fission-compiled
3762 code and non-Fission-compiled code. */
3764 /* Have we already tried to read this TU?
3765 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
3766 needn't exist in the global table yet). */
3767 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
3770 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
3771 dwo_unit of the TU itself. */
3772 dwo_file
= cu
->dwo_unit
->dwo_file
;
3774 /* Ok, this is the first time we're reading this TU. */
3775 if (dwo_file
->tus
== NULL
)
3777 find_dwo_entry
.signature
= sig
;
3778 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
3780 if (dwo_entry
== NULL
)
3783 /* If the global table doesn't have an entry for this TU, add one. */
3784 if (sig_entry
== NULL
)
3785 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
3787 if (sig_entry
->dwo_unit
== nullptr)
3788 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
3789 sig_entry
->tu_read
= 1;
3793 /* Subroutine of lookup_signatured_type.
3794 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
3795 then try the DWP file. If the TU stub (skeleton) has been removed then
3796 it won't be in .gdb_index. */
3798 static struct signatured_type
*
3799 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
3801 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3802 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
3803 struct dwo_unit
*dwo_entry
;
3806 gdb_assert (cu
->dwo_unit
);
3807 gdb_assert (dwp_file
!= NULL
);
3809 /* If TU skeletons have been removed then we may not have read in any
3811 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
3812 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
3814 signatured_type
find_sig_entry (sig
);
3815 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
3816 &find_sig_entry
, INSERT
);
3817 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
3819 /* Have we already tried to read this TU?
3820 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
3821 needn't exist in the global table yet). */
3822 if (sig_entry
!= NULL
)
3825 if (dwp_file
->tus
== NULL
)
3827 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
3828 1 /* is_debug_types */);
3829 if (dwo_entry
== NULL
)
3832 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
3833 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
3838 /* Lookup a signature based type for DW_FORM_ref_sig8.
3839 Returns NULL if signature SIG is not present in the table.
3840 It is up to the caller to complain about this. */
3842 static struct signatured_type
*
3843 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
3845 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3849 /* We're in a DWO/DWP file, and we're using .gdb_index.
3850 These cases require special processing. */
3851 if (get_dwp_file (per_objfile
) == NULL
)
3852 return lookup_dwo_signatured_type (cu
, sig
);
3854 return lookup_dwp_signatured_type (cu
, sig
);
3858 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
3860 signatured_type
find_entry (sig
);
3861 return ((struct signatured_type
*)
3862 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
3867 /* Low level DIE reading support. */
3869 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3872 init_cu_die_reader (struct die_reader_specs
*reader
,
3873 struct dwarf2_cu
*cu
,
3874 struct dwarf2_section_info
*section
,
3875 struct dwo_file
*dwo_file
,
3876 struct abbrev_table
*abbrev_table
)
3878 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3879 reader
->abfd
= section
->get_bfd_owner ();
3881 reader
->dwo_file
= dwo_file
;
3882 reader
->die_section
= section
;
3883 reader
->buffer
= section
->buffer
;
3884 reader
->buffer_end
= section
->buffer
+ section
->size
;
3885 reader
->abbrev_table
= abbrev_table
;
3888 /* Subroutine of cutu_reader to simplify it.
3889 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
3890 There's just a lot of work to do, and cutu_reader is big enough
3893 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
3894 from it to the DIE in the DWO. If NULL we are skipping the stub.
3895 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
3896 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
3897 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
3898 STUB_COMP_DIR may be non-NULL.
3899 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
3900 are filled in with the info of the DIE from the DWO file.
3901 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
3902 from the dwo. Since *RESULT_READER references this abbrev table, it must be
3903 kept around for at least as long as *RESULT_READER.
3905 The result is non-zero if a valid (non-dummy) DIE was found. */
3908 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
3909 struct dwo_unit
*dwo_unit
,
3910 struct die_info
*stub_comp_unit_die
,
3911 const char *stub_comp_dir
,
3912 struct die_reader_specs
*result_reader
,
3913 const gdb_byte
**result_info_ptr
,
3914 struct die_info
**result_comp_unit_die
,
3915 abbrev_table_up
*result_dwo_abbrev_table
)
3917 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3918 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
3919 struct objfile
*objfile
= per_objfile
->objfile
;
3921 const gdb_byte
*begin_info_ptr
, *info_ptr
;
3922 struct dwarf2_section_info
*dwo_abbrev_section
;
3924 /* At most one of these may be provided. */
3925 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
3927 /* These attributes aren't processed until later: DW_AT_stmt_list,
3928 DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_comp_dir.
3929 However, these attributes are found in the stub which we won't
3930 have later. In order to not impose this complication on the rest
3931 of the code, we read them here and copy them to the DWO CU/TU
3934 /* We store them all in an array. */
3935 struct attribute
*attributes
[5] {};
3936 /* Next available element of the attributes array. */
3937 int next_attr_idx
= 0;
3939 /* Push an element into ATTRIBUTES. */
3940 auto push_back
= [&] (struct attribute
*attr
)
3942 gdb_assert (next_attr_idx
< ARRAY_SIZE (attributes
));
3943 if (attr
!= nullptr)
3944 attributes
[next_attr_idx
++] = attr
;
3947 if (stub_comp_unit_die
!= NULL
)
3949 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3951 if (!per_cu
->is_debug_types
)
3952 push_back (dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
));
3953 push_back (dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
));
3954 push_back (dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
));
3955 push_back (dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
));
3956 push_back (dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
));
3958 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
3960 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
3961 We need the value before we can process DW_AT_ranges values from the
3963 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
3965 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
3966 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
3967 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
3968 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
3970 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
3972 else if (stub_comp_dir
!= NULL
)
3974 /* Reconstruct the comp_dir attribute to simplify the code below. */
3975 struct attribute
*comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
,
3977 comp_dir
->name
= DW_AT_comp_dir
;
3978 comp_dir
->form
= DW_FORM_string
;
3979 comp_dir
->set_string_noncanonical (stub_comp_dir
);
3980 push_back (comp_dir
);
3983 /* Set up for reading the DWO CU/TU. */
3984 cu
->dwo_unit
= dwo_unit
;
3985 dwarf2_section_info
*section
= dwo_unit
->section
;
3986 section
->read (objfile
);
3987 abfd
= section
->get_bfd_owner ();
3988 begin_info_ptr
= info_ptr
= (section
->buffer
3989 + to_underlying (dwo_unit
->sect_off
));
3990 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
3992 if (per_cu
->is_debug_types
)
3994 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
3996 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
3997 section
, dwo_abbrev_section
,
3998 info_ptr
, rcuh_kind::TYPE
);
3999 /* This is not an assert because it can be caused by bad debug info. */
4000 if (sig_type
->signature
!= cu
->header
.signature
)
4002 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
4003 " TU at offset %s [in module %s]"),
4004 hex_string (sig_type
->signature
),
4005 hex_string (cu
->header
.signature
),
4006 sect_offset_str (dwo_unit
->sect_off
),
4007 bfd_get_filename (abfd
));
4009 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
4010 /* For DWOs coming from DWP files, we don't know the CU length
4011 nor the type's offset in the TU until now. */
4012 dwo_unit
->length
= cu
->header
.get_length_with_initial ();
4013 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
4015 /* Establish the type offset that can be used to lookup the type.
4016 For DWO files, we don't know it until now. */
4017 sig_type
->type_offset_in_section
4018 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
4022 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
4023 section
, dwo_abbrev_section
,
4024 info_ptr
, rcuh_kind::COMPILE
);
4025 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
4026 /* For DWOs coming from DWP files, we don't know the CU length
4028 dwo_unit
->length
= cu
->header
.get_length_with_initial ();
4031 dwo_abbrev_section
->read (objfile
);
4032 *result_dwo_abbrev_table
4033 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
4034 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
4035 result_dwo_abbrev_table
->get ());
4037 /* Read in the die, filling in the attributes from the stub. This
4038 has the benefit of simplifying the rest of the code - all the
4039 work to maintain the illusion of a single
4040 DW_TAG_{compile,type}_unit DIE is done here. */
4041 info_ptr
= read_toplevel_die (result_reader
, result_comp_unit_die
, info_ptr
,
4042 gdb::make_array_view (attributes
,
4045 /* Skip dummy compilation units. */
4046 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4047 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4050 *result_info_ptr
= info_ptr
;
4054 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
4055 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
4056 signature is part of the header. */
4057 static gdb::optional
<ULONGEST
>
4058 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
4060 if (cu
->header
.version
>= 5)
4061 return cu
->header
.signature
;
4062 struct attribute
*attr
;
4063 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4064 if (attr
== nullptr || !attr
->form_is_unsigned ())
4065 return gdb::optional
<ULONGEST
> ();
4066 return attr
->as_unsigned ();
4069 /* Subroutine of cutu_reader to simplify it.
4070 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
4071 Returns NULL if the specified DWO unit cannot be found. */
4073 static struct dwo_unit
*
4074 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
4077 /* We need a lock here both to handle the DWO hash table, and BFD,
4078 which is not thread-safe. */
4079 static std::mutex dwo_lock
;
4081 std::lock_guard
<std::mutex
> guard (dwo_lock
);
4084 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4085 struct dwo_unit
*dwo_unit
;
4086 const char *comp_dir
;
4088 gdb_assert (cu
!= NULL
);
4090 /* Yeah, we look dwo_name up again, but it simplifies the code. */
4091 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
4092 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4094 if (per_cu
->is_debug_types
)
4095 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
4098 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
4100 if (!signature
.has_value ())
4101 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
4103 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
4105 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
4111 /* Subroutine of cutu_reader to simplify it.
4112 See it for a description of the parameters.
4113 Read a TU directly from a DWO file, bypassing the stub. */
4116 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
4117 dwarf2_per_objfile
*per_objfile
,
4118 dwarf2_cu
*existing_cu
)
4120 struct signatured_type
*sig_type
;
4122 /* Verify we can do the following downcast, and that we have the
4124 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
4125 sig_type
= (struct signatured_type
*) this_cu
;
4126 gdb_assert (sig_type
->dwo_unit
!= NULL
);
4130 if (existing_cu
!= nullptr)
4133 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
4134 /* There's no need to do the rereading_dwo_cu handling that
4135 cutu_reader does since we don't read the stub. */
4139 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
4140 in per_objfile yet. */
4141 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
4142 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
4143 cu
= m_new_cu
.get ();
4146 /* A future optimization, if needed, would be to use an existing
4147 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
4148 could share abbrev tables. */
4150 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
4151 NULL
/* stub_comp_unit_die */,
4152 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
4155 &m_dwo_abbrev_table
) == 0)
4162 /* Initialize a CU (or TU) and read its DIEs.
4163 If the CU defers to a DWO file, read the DWO file as well.
4165 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4166 Otherwise the table specified in the comp unit header is read in and used.
4167 This is an optimization for when we already have the abbrev table.
4169 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
4172 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
4173 dwarf2_per_objfile
*per_objfile
,
4174 struct abbrev_table
*abbrev_table
,
4175 dwarf2_cu
*existing_cu
,
4177 abbrev_cache
*cache
)
4178 : die_reader_specs
{},
4181 struct objfile
*objfile
= per_objfile
->objfile
;
4182 struct dwarf2_section_info
*section
= this_cu
->section
;
4183 bfd
*abfd
= section
->get_bfd_owner ();
4184 const gdb_byte
*begin_info_ptr
;
4185 struct signatured_type
*sig_type
= NULL
;
4186 struct dwarf2_section_info
*abbrev_section
;
4187 /* Non-zero if CU currently points to a DWO file and we need to
4188 reread it. When this happens we need to reread the skeleton die
4189 before we can reread the DWO file (this only applies to CUs, not TUs). */
4190 int rereading_dwo_cu
= 0;
4192 if (dwarf_die_debug
)
4193 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
4194 this_cu
->is_debug_types
? "type" : "comp",
4195 sect_offset_str (this_cu
->sect_off
));
4197 /* If we're reading a TU directly from a DWO file, including a virtual DWO
4198 file (instead of going through the stub), short-circuit all of this. */
4199 if (this_cu
->reading_dwo_directly
)
4201 /* Narrow down the scope of possibilities to have to understand. */
4202 gdb_assert (this_cu
->is_debug_types
);
4203 gdb_assert (abbrev_table
== NULL
);
4204 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
4208 /* This is cheap if the section is already read in. */
4209 section
->read (objfile
);
4211 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
4213 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4217 if (existing_cu
!= nullptr)
4220 /* If this CU is from a DWO file we need to start over, we need to
4221 refetch the attributes from the skeleton CU.
4222 This could be optimized by retrieving those attributes from when we
4223 were here the first time: the previous comp_unit_die was stored in
4224 comp_unit_obstack. But there's no data yet that we need this
4226 if (cu
->dwo_unit
!= NULL
)
4227 rereading_dwo_cu
= 1;
4231 /* If an existing_cu is provided, a dwarf2_cu must not exist for
4232 this_cu in per_objfile yet. Here, CACHE doubles as a flag to
4233 let us know that the CU is being scanned using the parallel
4234 indexer. This assert is avoided in this case because (1) it
4235 is irrelevant, and (2) the get_cu method is not
4237 gdb_assert (cache
!= nullptr
4238 || per_objfile
->get_cu (this_cu
) == nullptr);
4239 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
4240 cu
= m_new_cu
.get ();
4243 /* Get the header. */
4244 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
4246 /* We already have the header, there's no need to read it in again. */
4247 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
4251 if (this_cu
->is_debug_types
)
4253 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
4254 section
, abbrev_section
,
4255 info_ptr
, rcuh_kind::TYPE
);
4257 /* Since per_cu is the first member of struct signatured_type,
4258 we can go from a pointer to one to a pointer to the other. */
4259 sig_type
= (struct signatured_type
*) this_cu
;
4260 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
4261 gdb_assert (sig_type
->type_offset_in_tu
4262 == cu
->header
.type_cu_offset_in_tu
);
4263 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
4265 /* LENGTH has not been set yet for type units if we're
4266 using .gdb_index. */
4267 this_cu
->set_length (cu
->header
.get_length_with_initial ());
4269 /* Establish the type offset that can be used to lookup the type. */
4270 sig_type
->type_offset_in_section
=
4271 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
4273 this_cu
->set_version (cu
->header
.version
);
4277 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
4278 section
, abbrev_section
,
4280 rcuh_kind::COMPILE
);
4282 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
4283 this_cu
->set_length (cu
->header
.get_length_with_initial ());
4284 this_cu
->set_version (cu
->header
.version
);
4288 /* Skip dummy compilation units. */
4289 if (info_ptr
>= begin_info_ptr
+ this_cu
->length ()
4290 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4296 /* If we don't have them yet, read the abbrevs for this compilation unit.
4297 And if we need to read them now, make sure they're freed when we're
4299 if (abbrev_table
!= NULL
)
4300 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
4303 if (cache
!= nullptr)
4304 abbrev_table
= cache
->find (abbrev_section
,
4305 cu
->header
.abbrev_sect_off
);
4306 if (abbrev_table
== nullptr)
4308 abbrev_section
->read (objfile
);
4309 m_abbrev_table_holder
4310 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
4311 abbrev_table
= m_abbrev_table_holder
.get ();
4315 /* Read the top level CU/TU die. */
4316 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
4317 info_ptr
= read_toplevel_die (this, &comp_unit_die
, info_ptr
);
4319 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
4325 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
4326 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
4327 table from the DWO file and pass the ownership over to us. It will be
4328 referenced from READER, so we must make sure to free it after we're done
4331 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
4332 DWO CU, that this test will fail (the attribute will not be present). */
4333 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
4334 if (dwo_name
!= nullptr)
4336 struct dwo_unit
*dwo_unit
;
4337 struct die_info
*dwo_comp_unit_die
;
4339 if (comp_unit_die
->has_children
)
4341 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
4342 " has children (offset %s) [in module %s]"),
4343 sect_offset_str (this_cu
->sect_off
),
4344 bfd_get_filename (abfd
));
4346 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
4347 if (dwo_unit
!= NULL
)
4349 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
4350 comp_unit_die
, NULL
,
4353 &m_dwo_abbrev_table
) == 0)
4359 comp_unit_die
= dwo_comp_unit_die
;
4363 /* Yikes, we couldn't find the rest of the DIE, we only have
4364 the stub. A complaint has already been logged. There's
4365 not much more we can do except pass on the stub DIE to
4366 die_reader_func. We don't want to throw an error on bad
4373 cutu_reader::keep ()
4375 /* Done, clean up. */
4376 gdb_assert (!dummy_p
);
4377 if (m_new_cu
!= NULL
)
4379 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
4381 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
4382 per_objfile
->set_cu (m_this_cu
, std::move (m_new_cu
));
4386 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
4387 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
4388 assumed to have already done the lookup to find the DWO file).
4390 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4391 THIS_CU->is_debug_types, but nothing else.
4393 We fill in THIS_CU->length.
4395 THIS_CU->cu is always freed when done.
4396 This is done in order to not leave THIS_CU->cu in a state where we have
4397 to care whether it refers to the "main" CU or the DWO CU.
4399 When parent_cu is passed, it is used to provide a default value for
4400 str_offsets_base and addr_base from the parent. */
4402 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
4403 dwarf2_per_objfile
*per_objfile
,
4404 struct dwarf2_cu
*parent_cu
,
4405 struct dwo_file
*dwo_file
)
4406 : die_reader_specs
{},
4409 struct objfile
*objfile
= per_objfile
->objfile
;
4410 struct dwarf2_section_info
*section
= this_cu
->section
;
4411 bfd
*abfd
= section
->get_bfd_owner ();
4412 struct dwarf2_section_info
*abbrev_section
;
4413 const gdb_byte
*begin_info_ptr
, *info_ptr
;
4415 if (dwarf_die_debug
)
4416 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
4417 this_cu
->is_debug_types
? "type" : "comp",
4418 sect_offset_str (this_cu
->sect_off
));
4420 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
4422 abbrev_section
= (dwo_file
!= NULL
4423 ? &dwo_file
->sections
.abbrev
4424 : get_abbrev_section_for_cu (this_cu
));
4426 /* This is cheap if the section is already read in. */
4427 section
->read (objfile
);
4429 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
4431 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
4432 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
4433 section
, abbrev_section
, info_ptr
,
4434 (this_cu
->is_debug_types
4436 : rcuh_kind::COMPILE
));
4438 if (parent_cu
!= nullptr)
4440 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
4441 m_new_cu
->addr_base
= parent_cu
->addr_base
;
4443 this_cu
->set_length (m_new_cu
->header
.get_length_with_initial ());
4445 /* Skip dummy compilation units. */
4446 if (info_ptr
>= begin_info_ptr
+ this_cu
->length ()
4447 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4453 abbrev_section
->read (objfile
);
4454 m_abbrev_table_holder
4455 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
4457 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
4458 m_abbrev_table_holder
.get ());
4459 info_ptr
= read_toplevel_die (this, &comp_unit_die
, info_ptr
);
4463 /* Type Unit Groups.
4465 Type Unit Groups are a way to collapse the set of all TUs (type units) into
4466 a more manageable set. The grouping is done by DW_AT_stmt_list entry
4467 so that all types coming from the same compilation (.o file) are grouped
4468 together. A future step could be to put the types in the same symtab as
4469 the CU the types ultimately came from. */
4472 hash_type_unit_group (const void *item
)
4474 const struct type_unit_group
*tu_group
4475 = (const struct type_unit_group
*) item
;
4477 return hash_stmt_list_entry (&tu_group
->hash
);
4481 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4483 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
4484 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
4486 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4489 /* Allocate a hash table for type unit groups. */
4492 allocate_type_unit_groups_table ()
4494 return htab_up (htab_create_alloc (3,
4495 hash_type_unit_group
,
4497 htab_delete_entry
<type_unit_group
>,
4501 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4502 partial symtabs. We combine several TUs per psymtab to not let the size
4503 of any one psymtab grow too big. */
4504 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4505 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4507 /* Helper routine for get_type_unit_group.
4508 Create the type_unit_group object used to hold one or more TUs. */
4510 static std::unique_ptr
<type_unit_group
>
4511 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
4513 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
4515 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
4516 tu_group
->hash
.line_sect_off
= line_offset_struct
;
4521 /* Look up the type_unit_group for type unit CU, and create it if necessary.
4522 STMT_LIST is a DW_AT_stmt_list attribute. */
4524 static struct type_unit_group
*
4525 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
4527 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
4528 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
4529 struct type_unit_group
*tu_group
;
4531 unsigned int line_offset
;
4532 struct type_unit_group type_unit_group_for_lookup
;
4534 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
4535 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
4537 /* Do we need to create a new group, or can we use an existing one? */
4539 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
4541 line_offset
= stmt_list
->as_unsigned ();
4542 ++tu_stats
->nr_symtab_sharers
;
4546 /* Ugh, no stmt_list. Rare, but we have to handle it.
4547 We can do various things here like create one group per TU or
4548 spread them over multiple groups to split up the expansion work.
4549 To avoid worst case scenarios (too many groups or too large groups)
4550 we, umm, group them in bunches. */
4551 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
4552 | (tu_stats
->nr_stmt_less_type_units
4553 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
4554 ++tu_stats
->nr_stmt_less_type_units
;
4557 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
4558 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
4559 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
4560 &type_unit_group_for_lookup
, INSERT
);
4561 if (*slot
== nullptr)
4563 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
4564 std::unique_ptr
<type_unit_group
> grp
4565 = create_type_unit_group (cu
, line_offset_struct
);
4566 *slot
= grp
.release ();
4567 ++tu_stats
->nr_symtabs
;
4570 tu_group
= (struct type_unit_group
*) *slot
;
4571 gdb_assert (tu_group
!= nullptr);
4576 /* An instance of this is created when scanning DWARF to create a
4579 class cooked_index_storage
4583 cooked_index_storage ()
4584 : m_reader_hash (htab_create_alloc (10, hash_cutu_reader
,
4586 htab_delete_entry
<cutu_reader
>,
4588 m_index (new cooked_index_shard
)
4592 DISABLE_COPY_AND_ASSIGN (cooked_index_storage
);
4594 /* Return the current abbrev cache. */
4595 abbrev_cache
*get_abbrev_cache ()
4597 return &m_abbrev_cache
;
4600 /* Return the DIE reader corresponding to PER_CU. If no such reader
4601 has been registered, return NULL. */
4602 cutu_reader
*get_reader (dwarf2_per_cu_data
*per_cu
)
4604 int index
= per_cu
->index
;
4605 return (cutu_reader
*) htab_find_with_hash (m_reader_hash
.get (),
4609 /* Preserve READER by storing it in the local hash table. */
4610 cutu_reader
*preserve (std::unique_ptr
<cutu_reader
> reader
)
4612 m_abbrev_cache
.add (reader
->release_abbrev_table ());
4614 int index
= reader
->cu
->per_cu
->index
;
4615 void **slot
= htab_find_slot_with_hash (m_reader_hash
.get (), &index
,
4617 gdb_assert (*slot
== nullptr);
4618 cutu_reader
*result
= reader
.get ();
4619 *slot
= reader
.release ();
4623 /* Add an entry to the index. The arguments describe the entry; see
4624 cooked-index.h. The new entry is returned. */
4625 const cooked_index_entry
*add (sect_offset die_offset
, enum dwarf_tag tag
,
4626 cooked_index_flag flags
,
4628 const cooked_index_entry
*parent_entry
,
4629 dwarf2_per_cu_data
*per_cu
)
4631 return m_index
->add (die_offset
, tag
, flags
, name
, parent_entry
, per_cu
);
4634 /* Install the current addrmap into the index shard being constructed,
4635 then transfer ownership of the index to the caller. */
4636 std::unique_ptr
<cooked_index_shard
> release ()
4638 m_index
->install_addrmap (&m_addrmap
);
4639 return std::move (m_index
);
4642 /* Return the mutable addrmap that is currently being created. */
4643 addrmap_mutable
*get_addrmap ()
4650 /* Hash function for a cutu_reader. */
4651 static hashval_t
hash_cutu_reader (const void *a
)
4653 const cutu_reader
*reader
= (const cutu_reader
*) a
;
4654 return reader
->cu
->per_cu
->index
;
4657 /* Equality function for cutu_reader. */
4658 static int eq_cutu_reader (const void *a
, const void *b
)
4660 const cutu_reader
*ra
= (const cutu_reader
*) a
;
4661 const int *rb
= (const int *) b
;
4662 return ra
->cu
->per_cu
->index
== *rb
;
4665 /* The abbrev cache used by this indexer. */
4666 abbrev_cache m_abbrev_cache
;
4667 /* A hash table of cutu_reader objects. */
4668 htab_up m_reader_hash
;
4669 /* The index shard that is being constructed. */
4670 std::unique_ptr
<cooked_index_shard
> m_index
;
4672 /* A writeable addrmap being constructed by this scanner. */
4673 addrmap_mutable m_addrmap
;
4676 /* An instance of this is created to index a CU. */
4678 class cooked_indexer
4682 cooked_indexer (cooked_index_storage
*storage
,
4683 dwarf2_per_cu_data
*per_cu
,
4684 enum language language
)
4685 : m_index_storage (storage
),
4687 m_language (language
)
4691 DISABLE_COPY_AND_ASSIGN (cooked_indexer
);
4693 /* Index the given CU. */
4694 void make_index (cutu_reader
*reader
);
4698 /* A helper function to turn a section offset into an address that
4699 can be used in an addrmap. */
4700 CORE_ADDR
form_addr (sect_offset offset
, bool is_dwz
)
4702 CORE_ADDR value
= to_underlying (offset
);
4704 value
|= ((CORE_ADDR
) 1) << (8 * sizeof (CORE_ADDR
) - 1);
4708 /* A helper function to scan the PC bounds of READER and record them
4709 in the storage's addrmap. */
4710 void check_bounds (cutu_reader
*reader
);
4712 /* Ensure that the indicated CU exists. The cutu_reader for it is
4713 returned. FOR_SCANNING is true if the caller intends to scan all
4714 the DIEs in the CU; when false, this use is assumed to be to look
4715 up just a single DIE. */
4716 cutu_reader
*ensure_cu_exists (cutu_reader
*reader
,
4717 dwarf2_per_objfile
*per_objfile
,
4718 sect_offset sect_off
,
4722 /* Index DIEs in the READER starting at INFO_PTR. PARENT_ENTRY is
4723 the entry for the enclosing scope (nullptr at top level). FULLY
4724 is true when a full scan must be done -- in some languages,
4725 function scopes must be fully explored in order to find nested
4726 functions. This returns a pointer to just after the spot where
4728 const gdb_byte
*index_dies (cutu_reader
*reader
,
4729 const gdb_byte
*info_ptr
,
4730 const cooked_index_entry
*parent_entry
,
4733 /* Scan the attributes for a given DIE and update the out
4734 parameters. Returns a pointer to the byte after the DIE. */
4735 const gdb_byte
*scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
4736 cutu_reader
*reader
,
4737 const gdb_byte
*watermark_ptr
,
4738 const gdb_byte
*info_ptr
,
4739 const abbrev_info
*abbrev
,
4741 const char **linkage_name
,
4742 cooked_index_flag
*flags
,
4743 sect_offset
*sibling_offset
,
4744 const cooked_index_entry
**parent_entry
,
4745 CORE_ADDR
*maybe_defer
,
4746 bool for_specification
);
4748 /* Handle DW_TAG_imported_unit, by scanning the DIE to find
4749 DW_AT_import, and then scanning the referenced CU. Returns a
4750 pointer to the byte after the DIE. */
4751 const gdb_byte
*index_imported_unit (cutu_reader
*reader
,
4752 const gdb_byte
*info_ptr
,
4753 const abbrev_info
*abbrev
);
4755 /* Recursively read DIEs, recording the section offsets in
4756 m_die_range_map and then calling index_dies. */
4757 const gdb_byte
*recurse (cutu_reader
*reader
,
4758 const gdb_byte
*info_ptr
,
4759 const cooked_index_entry
*parent_entry
,
4762 /* The storage object, where the results are kept. */
4763 cooked_index_storage
*m_index_storage
;
4764 /* The CU that we are reading on behalf of. This object might be
4765 asked to index one CU but to treat the results as if they come
4766 from some including CU; in this case the including CU would be
4768 dwarf2_per_cu_data
*m_per_cu
;
4769 /* The language that we're assuming when reading. */
4770 enum language m_language
;
4772 /* An addrmap that maps from section offsets (see the form_addr
4773 method) to newly-created entries. See m_deferred_entries to
4775 addrmap_mutable m_die_range_map
;
4777 /* A single deferred entry. */
4778 struct deferred_entry
4780 sect_offset die_offset
;
4782 CORE_ADDR spec_offset
;
4784 cooked_index_flag flags
;
4787 /* The generated DWARF can sometimes have the declaration for a
4788 method in a class (or perhaps namespace) scope, with the
4789 definition appearing outside this scope... just one of the many
4790 bad things about DWARF. In order to handle this situation, we
4791 defer certain entries until the end of scanning, at which point
4792 we'll know the containing context of all the DIEs that we might
4793 have scanned. This vector stores these deferred entries. */
4794 std::vector
<deferred_entry
> m_deferred_entries
;
4797 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4798 Process compilation unit THIS_CU for a psymtab. */
4801 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
4802 dwarf2_per_objfile
*per_objfile
,
4803 cooked_index_storage
*storage
)
4805 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false,
4806 storage
->get_abbrev_cache ());
4808 if (reader
.comp_unit_die
== nullptr)
4815 else if (this_cu
->is_debug_types
)
4816 build_type_psymtabs_reader (&reader
, storage
);
4817 else if (reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
4820 if (this_cu
->scanned
.compare_exchange_strong (nope
, true))
4822 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
4824 gdb_assert (storage
!= nullptr);
4825 cooked_indexer
indexer (storage
, this_cu
, reader
.cu
->lang ());
4826 indexer
.make_index (&reader
);
4831 /* Reader function for build_type_psymtabs. */
4834 build_type_psymtabs_reader (cutu_reader
*reader
,
4835 cooked_index_storage
*storage
)
4837 struct dwarf2_cu
*cu
= reader
->cu
;
4838 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4839 struct die_info
*type_unit_die
= reader
->comp_unit_die
;
4841 gdb_assert (per_cu
->is_debug_types
);
4843 if (! type_unit_die
->has_children
)
4846 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
4848 gdb_assert (storage
!= nullptr);
4849 cooked_indexer
indexer (storage
, per_cu
, cu
->lang ());
4850 indexer
.make_index (reader
);
4853 /* Struct used to sort TUs by their abbreviation table offset. */
4855 struct tu_abbrev_offset
4857 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
4858 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
4861 /* This is used when sorting. */
4862 bool operator< (const tu_abbrev_offset
&other
) const
4864 return abbrev_offset
< other
.abbrev_offset
;
4867 signatured_type
*sig_type
;
4868 sect_offset abbrev_offset
;
4871 /* Efficiently read all the type units.
4873 The efficiency is because we sort TUs by the abbrev table they use and
4874 only read each abbrev table once. In one program there are 200K TUs
4875 sharing 8K abbrev tables.
4877 The main purpose of this function is to support building the
4878 dwarf2_per_objfile->per_bfd->type_unit_groups table.
4879 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
4880 can collapse the search space by grouping them by stmt_list.
4881 The savings can be significant, in the same program from above the 200K TUs
4882 share 8K stmt_list tables.
4884 FUNC is expected to call get_type_unit_group, which will create the
4885 struct type_unit_group if necessary and add it to
4886 dwarf2_per_objfile->per_bfd->type_unit_groups. */
4889 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
,
4890 cooked_index_storage
*storage
)
4892 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
4893 abbrev_table_up abbrev_table
;
4894 sect_offset abbrev_offset
;
4896 /* It's up to the caller to not call us multiple times. */
4897 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
4899 if (per_objfile
->per_bfd
->all_type_units
.size () == 0)
4902 /* TUs typically share abbrev tables, and there can be way more TUs than
4903 abbrev tables. Sort by abbrev table to reduce the number of times we
4904 read each abbrev table in.
4905 Alternatives are to punt or to maintain a cache of abbrev tables.
4906 This is simpler and efficient enough for now.
4908 Later we group TUs by their DW_AT_stmt_list value (as this defines the
4909 symtab to use). Typically TUs with the same abbrev offset have the same
4910 stmt_list value too so in practice this should work well.
4912 The basic algorithm here is:
4914 sort TUs by abbrev table
4915 for each TU with same abbrev table:
4916 read abbrev table if first user
4917 read TU top level DIE
4918 [IWBN if DWO skeletons had DW_AT_stmt_list]
4921 dwarf_read_debug_printf ("Building type unit groups ...");
4923 /* Sort in a separate table to maintain the order of all_units
4924 for .gdb_index: TU indices directly index all_type_units. */
4925 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
4926 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
4928 for (const auto &cu
: per_objfile
->per_bfd
->all_units
)
4930 if (cu
->is_debug_types
)
4932 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
4933 sorted_by_abbrev
.emplace_back
4934 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
4935 sig_type
->sect_off
));
4939 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
4941 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
4943 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
4945 /* Switch to the next abbrev table if necessary. */
4946 if (abbrev_table
== NULL
4947 || tu
.abbrev_offset
!= abbrev_offset
)
4949 abbrev_offset
= tu
.abbrev_offset
;
4950 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
4952 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
4953 ++tu_stats
->nr_uniq_abbrev_tables
;
4956 cutu_reader
reader (tu
.sig_type
, per_objfile
,
4957 abbrev_table
.get (), nullptr, false);
4958 if (!reader
.dummy_p
)
4959 build_type_psymtabs_reader (&reader
, storage
);
4963 /* Print collected type unit statistics. */
4966 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
4968 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
4970 dwarf_read_debug_printf ("Type unit statistics:");
4971 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
4972 dwarf_read_debug_printf (" %d uniq abbrev tables",
4973 tu_stats
->nr_uniq_abbrev_tables
);
4974 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
4975 tu_stats
->nr_symtabs
);
4976 dwarf_read_debug_printf (" %d symtab sharers",
4977 tu_stats
->nr_symtab_sharers
);
4978 dwarf_read_debug_printf (" %d type units without a stmt_list",
4979 tu_stats
->nr_stmt_less_type_units
);
4980 dwarf_read_debug_printf (" %d all_type_units reallocs",
4981 tu_stats
->nr_all_type_units_reallocs
);
4984 struct skeleton_data
4986 dwarf2_per_objfile
*per_objfile
;
4987 cooked_index_storage
*storage
;
4990 /* Traversal function for process_skeletonless_type_unit.
4991 Read a TU in a DWO file and build partial symbols for it. */
4994 process_skeletonless_type_unit (void **slot
, void *info
)
4996 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
4997 skeleton_data
*data
= (skeleton_data
*) info
;
4999 /* If this TU doesn't exist in the global table, add it and read it in. */
5001 if (data
->per_objfile
->per_bfd
->signatured_types
== NULL
)
5002 data
->per_objfile
->per_bfd
->signatured_types
5003 = allocate_signatured_type_table ();
5005 signatured_type
find_entry (dwo_unit
->signature
);
5006 slot
= htab_find_slot (data
->per_objfile
->per_bfd
->signatured_types
.get (),
5007 &find_entry
, INSERT
);
5008 /* If we've already seen this type there's nothing to do. What's happening
5009 is we're doing our own version of comdat-folding here. */
5013 /* This does the job that create_all_units would have done for
5015 signatured_type
*entry
5016 = add_type_unit (data
->per_objfile
, dwo_unit
->signature
, slot
);
5017 fill_in_sig_entry_from_dwo_entry (data
->per_objfile
, entry
, dwo_unit
);
5020 /* This does the job that build_type_psymtabs would have done. */
5021 cutu_reader
reader (entry
, data
->per_objfile
, nullptr, nullptr, false);
5022 if (!reader
.dummy_p
)
5023 build_type_psymtabs_reader (&reader
, data
->storage
);
5028 /* Traversal function for process_skeletonless_type_units. */
5031 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
5033 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
5035 if (dwo_file
->tus
!= NULL
)
5036 htab_traverse_noresize (dwo_file
->tus
.get (),
5037 process_skeletonless_type_unit
, info
);
5042 /* Scan all TUs of DWO files, verifying we've processed them.
5043 This is needed in case a TU was emitted without its skeleton.
5044 Note: This can't be done until we know what all the DWO files are. */
5047 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
,
5048 cooked_index_storage
*storage
)
5050 skeleton_data data
{ per_objfile
, storage
};
5052 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
5053 if (get_dwp_file (per_objfile
) == NULL
5054 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
5056 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
5057 process_dwo_file_for_skeletonless_type_units
,
5062 /* Build the partial symbol table by doing a quick pass through the
5063 .debug_info and .debug_abbrev sections. */
5066 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
5068 struct objfile
*objfile
= per_objfile
->objfile
;
5069 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5071 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
5072 objfile_name (objfile
));
5074 per_bfd
->map_info_sections (objfile
);
5076 cooked_index_storage index_storage
;
5077 create_all_units (per_objfile
);
5078 build_type_psymtabs (per_objfile
, &index_storage
);
5079 std::vector
<std::unique_ptr
<cooked_index_shard
>> indexes
;
5081 per_bfd
->quick_file_names_table
5082 = create_quick_file_names_table (per_bfd
->all_units
.size ());
5083 if (!per_bfd
->debug_aranges
.empty ())
5084 read_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
,
5085 index_storage
.get_addrmap ());
5088 /* Ensure that complaints are handled correctly. */
5089 complaint_interceptor complaint_handler
;
5091 using iter_type
= decltype (per_bfd
->all_units
.begin ());
5093 auto task_size_
= [] (iter_type iter
)
5095 dwarf2_per_cu_data
*per_cu
= iter
->get ();
5096 return (size_t)per_cu
->length ();
5098 auto task_size
= gdb::make_function_view (task_size_
);
5100 /* Each thread returns a pair holding a cooked index, and a vector
5101 of errors that should be printed. The latter is done because
5102 GDB's I/O system is not thread-safe. run_on_main_thread could be
5103 used, but that would mean the messages are printed after the
5104 prompt, which looks weird. */
5105 using result_type
= std::pair
<std::unique_ptr
<cooked_index_shard
>,
5106 std::vector
<gdb_exception
>>;
5107 std::vector
<result_type
> results
5108 = gdb::parallel_for_each (1, per_bfd
->all_units
.begin (),
5109 per_bfd
->all_units
.end (),
5110 [=] (iter_type iter
, iter_type end
)
5112 std::vector
<gdb_exception
> errors
;
5113 cooked_index_storage thread_storage
;
5114 for (; iter
!= end
; ++iter
)
5116 dwarf2_per_cu_data
*per_cu
= iter
->get ();
5119 process_psymtab_comp_unit (per_cu
, per_objfile
,
5122 catch (gdb_exception
&except
)
5124 errors
.push_back (std::move (except
));
5127 return result_type (thread_storage
.release (), std::move (errors
));
5130 /* Only show a given exception a single time. */
5131 std::unordered_set
<gdb_exception
> seen_exceptions
;
5132 for (auto &one_result
: results
)
5134 indexes
.push_back (std::move (one_result
.first
));
5135 for (auto &one_exc
: one_result
.second
)
5136 if (seen_exceptions
.insert (one_exc
).second
)
5137 exception_print (gdb_stderr
, one_exc
);
5141 /* This has to wait until we read the CUs, we need the list of DWOs. */
5142 process_skeletonless_type_units (per_objfile
, &index_storage
);
5144 if (dwarf_read_debug
> 0)
5145 print_tu_stats (per_objfile
);
5147 indexes
.push_back (index_storage
.release ());
5148 indexes
.shrink_to_fit ();
5150 cooked_index
*vec
= new cooked_index (std::move (indexes
), per_bfd
);
5151 per_bfd
->index_table
.reset (vec
);
5153 const cooked_index_entry
*main_entry
= vec
->get_main ();
5154 if (main_entry
!= nullptr)
5156 /* We only do this for names not requiring canonicalization. At
5157 this point in the process names have not been canonicalized.
5158 However, currently, languages that require this step also do
5159 not use DW_AT_main_subprogram. An assert is appropriate here
5160 because this filtering is done in get_main. */
5161 enum language lang
= main_entry
->per_cu
->lang ();
5162 gdb_assert (!language_requires_canonicalization (lang
));
5163 const char *full_name
= main_entry
->full_name (&per_bfd
->obstack
, true);
5164 set_objfile_main_name (objfile
, full_name
, lang
);
5167 dwarf_read_debug_printf ("Done building psymtabs of %s",
5168 objfile_name (objfile
));
5172 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
5173 struct dwarf2_section_info
*section
,
5174 struct dwarf2_section_info
*abbrev_section
,
5175 unsigned int is_dwz
,
5176 htab_up
&types_htab
,
5177 rcuh_kind section_kind
)
5179 const gdb_byte
*info_ptr
;
5180 struct objfile
*objfile
= per_objfile
->objfile
;
5182 dwarf_read_debug_printf ("Reading %s for %s",
5183 section
->get_name (),
5184 section
->get_file_name ());
5186 section
->read (objfile
);
5188 info_ptr
= section
->buffer
;
5190 while (info_ptr
< section
->buffer
+ section
->size
)
5192 dwarf2_per_cu_data_up this_cu
;
5194 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
5196 comp_unit_head cu_header
;
5197 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
5198 abbrev_section
, info_ptr
,
5201 /* Save the compilation unit for later lookup. */
5202 if (cu_header
.unit_type
!= DW_UT_type
)
5203 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
5206 if (types_htab
== nullptr)
5207 types_htab
= allocate_signatured_type_table ();
5209 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
5210 (cu_header
.signature
);
5211 signatured_type
*sig_ptr
= sig_type
.get ();
5212 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
5213 this_cu
.reset (sig_type
.release ());
5215 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
5216 gdb_assert (slot
!= nullptr);
5217 if (*slot
!= nullptr)
5218 complaint (_("debug type entry at offset %s is duplicate to"
5219 " the entry at offset %s, signature %s"),
5220 sect_offset_str (sect_off
),
5221 sect_offset_str (sig_ptr
->sect_off
),
5222 hex_string (sig_ptr
->signature
));
5225 this_cu
->sect_off
= sect_off
;
5226 this_cu
->set_length (cu_header
.get_length_with_initial ());
5227 this_cu
->is_dwz
= is_dwz
;
5228 this_cu
->section
= section
;
5229 /* Init this asap, to avoid a data race in the set_version in
5230 cutu_reader::cutu_reader (which may be run in parallel for the cooked
5232 this_cu
->set_version (cu_header
.version
);
5234 info_ptr
= info_ptr
+ this_cu
->length ();
5235 per_objfile
->per_bfd
->all_units
.push_back (std::move (this_cu
));
5239 /* Initialize the views on all_units. */
5242 finalize_all_units (dwarf2_per_bfd
*per_bfd
)
5244 size_t nr_tus
= per_bfd
->tu_stats
.nr_tus
;
5245 size_t nr_cus
= per_bfd
->all_units
.size () - nr_tus
;
5246 gdb::array_view
<dwarf2_per_cu_data_up
> tmp
= per_bfd
->all_units
;
5247 per_bfd
->all_comp_units
= tmp
.slice (0, nr_cus
);
5248 per_bfd
->all_type_units
= tmp
.slice (nr_cus
, nr_tus
);
5251 /* Create a list of all compilation units in OBJFILE.
5252 This is only done for -readnow and building partial symtabs. */
5255 create_all_units (dwarf2_per_objfile
*per_objfile
)
5258 gdb_assert (per_objfile
->per_bfd
->all_units
.empty ());
5260 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
5261 &per_objfile
->per_bfd
->abbrev
, 0,
5262 types_htab
, rcuh_kind::COMPILE
);
5263 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
5264 read_comp_units_from_section (per_objfile
, §ion
,
5265 &per_objfile
->per_bfd
->abbrev
, 0,
5266 types_htab
, rcuh_kind::TYPE
);
5271 dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
5273 catch (const gdb_exception_error
&)
5275 per_objfile
->per_bfd
->all_units
.clear ();
5280 /* Pre-read the sections we'll need to construct an index. */
5281 struct objfile
*objfile
= per_objfile
->objfile
;
5282 dwz
->abbrev
.read (objfile
);
5283 dwz
->info
.read (objfile
);
5284 dwz
->str
.read (objfile
);
5285 dwz
->line
.read (objfile
);
5286 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
5287 types_htab
, rcuh_kind::COMPILE
);
5290 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
5292 finalize_all_units (per_objfile
->per_bfd
);
5295 /* Return the initial uleb128 in the die at INFO_PTR. */
5298 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
5300 unsigned int bytes_read
;
5302 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5305 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
5306 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
5308 Return the corresponding abbrev, or NULL if the number is zero (indicating
5309 an empty DIE). In either case *BYTES_READ will be set to the length of
5310 the initial number. */
5312 static const struct abbrev_info
*
5313 peek_die_abbrev (const die_reader_specs
&reader
,
5314 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
5316 dwarf2_cu
*cu
= reader
.cu
;
5317 bfd
*abfd
= reader
.abfd
;
5318 unsigned int abbrev_number
5319 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5321 if (abbrev_number
== 0)
5324 const abbrev_info
*abbrev
5325 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
5328 error (_("Dwarf Error: Could not find abbrev number %d in %s"
5329 " at offset %s [in module %s]"),
5330 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
5331 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
5337 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5338 Returns a pointer to the end of a series of DIEs, terminated by an empty
5339 DIE. Any children of the skipped DIEs will also be skipped. */
5341 static const gdb_byte
*
5342 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
5346 unsigned int bytes_read
;
5347 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
5351 return info_ptr
+ bytes_read
;
5353 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5357 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5358 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5359 abbrev corresponding to that skipped uleb128 should be passed in
5362 If DO_SKIP_CHILDREN is true, or if the DIE has no children, this
5363 returns a pointer to this DIE's sibling, skipping any children.
5364 Otherwise, returns a pointer to the DIE's first child. */
5366 static const gdb_byte
*
5367 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
5368 const struct abbrev_info
*abbrev
, bool do_skip_children
)
5370 unsigned int bytes_read
;
5371 struct attribute attr
;
5372 bfd
*abfd
= reader
->abfd
;
5373 struct dwarf2_cu
*cu
= reader
->cu
;
5374 const gdb_byte
*buffer
= reader
->buffer
;
5375 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5376 unsigned int form
, i
;
5378 if (do_skip_children
&& abbrev
->sibling_offset
!= (unsigned short) -1)
5380 /* We only handle DW_FORM_ref4 here. */
5381 const gdb_byte
*sibling_data
= info_ptr
+ abbrev
->sibling_offset
;
5382 unsigned int offset
= read_4_bytes (abfd
, sibling_data
);
5383 const gdb_byte
*sibling_ptr
5384 = buffer
+ to_underlying (cu
->header
.sect_off
) + offset
;
5385 if (sibling_ptr
>= info_ptr
&& sibling_ptr
< reader
->buffer_end
)
5387 /* Fall through to the slow way. */
5389 else if (abbrev
->size_if_constant
!= 0)
5391 info_ptr
+= abbrev
->size_if_constant
;
5392 if (do_skip_children
&& abbrev
->has_children
)
5393 return skip_children (reader
, info_ptr
);
5397 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5399 /* The only abbrev we care about is DW_AT_sibling. */
5400 if (do_skip_children
&& abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5402 /* Note there is no need for the extra work of
5403 "reprocessing" here, so we pass false for that
5405 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
, false);
5406 if (attr
.form
== DW_FORM_ref_addr
)
5407 complaint (_("ignoring absolute DW_AT_sibling"));
5410 sect_offset off
= attr
.get_ref_die_offset ();
5411 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
5413 if (sibling_ptr
< info_ptr
)
5414 complaint (_("DW_AT_sibling points backwards"));
5415 else if (sibling_ptr
> reader
->buffer_end
)
5416 reader
->die_section
->overflow_complaint ();
5422 /* If it isn't DW_AT_sibling, skip this attribute. */
5423 form
= abbrev
->attrs
[i
].form
;
5427 case DW_FORM_ref_addr
:
5428 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5429 and later it is offset sized. */
5430 if (cu
->header
.version
== 2)
5431 info_ptr
+= cu
->header
.addr_size
;
5433 info_ptr
+= cu
->header
.offset_size
;
5435 case DW_FORM_GNU_ref_alt
:
5436 info_ptr
+= cu
->header
.offset_size
;
5439 info_ptr
+= cu
->header
.addr_size
;
5447 case DW_FORM_flag_present
:
5448 case DW_FORM_implicit_const
:
5465 case DW_FORM_ref_sig8
:
5468 case DW_FORM_data16
:
5471 case DW_FORM_string
:
5472 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5473 info_ptr
+= bytes_read
;
5475 case DW_FORM_sec_offset
:
5477 case DW_FORM_GNU_strp_alt
:
5478 info_ptr
+= cu
->header
.offset_size
;
5480 case DW_FORM_exprloc
:
5482 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5483 info_ptr
+= bytes_read
;
5485 case DW_FORM_block1
:
5486 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5488 case DW_FORM_block2
:
5489 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5491 case DW_FORM_block4
:
5492 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5498 case DW_FORM_ref_udata
:
5499 case DW_FORM_GNU_addr_index
:
5500 case DW_FORM_GNU_str_index
:
5501 case DW_FORM_rnglistx
:
5502 case DW_FORM_loclistx
:
5503 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
5505 case DW_FORM_indirect
:
5506 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5507 info_ptr
+= bytes_read
;
5508 /* We need to continue parsing from here, so just go back to
5510 goto skip_attribute
;
5513 error (_("Dwarf Error: Cannot handle %s "
5514 "in DWARF reader [in module %s]"),
5515 dwarf_form_name (form
),
5516 bfd_get_filename (abfd
));
5520 if (do_skip_children
&& abbrev
->has_children
)
5521 return skip_children (reader
, info_ptr
);
5526 /* Reading in full CUs. */
5528 /* Add PER_CU to the queue. */
5531 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
5532 dwarf2_per_objfile
*per_objfile
,
5533 enum language pretend_language
)
5537 gdb_assert (per_objfile
->queue
.has_value ());
5538 per_objfile
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
5541 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
5543 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
5546 Return true if maybe_queue_comp_unit requires the caller to load the CU's
5547 DIEs, false otherwise.
5549 Explanation: there is an invariant that if a CU is queued for expansion
5550 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
5551 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
5552 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
5553 are not yet loaded, the the caller must load the CU's DIEs to ensure the
5554 invariant is respected.
5556 The caller is therefore not required to load the CU's DIEs (we return false)
5559 - the CU is already expanded, and therefore does not get enqueued
5560 - the CU gets enqueued for expansion, but its DIEs are already loaded
5562 Note that the caller should not use this function's return value as an
5563 indicator of whether the CU's DIEs are loaded right now, it should check
5564 that by calling `dwarf2_per_objfile::get_cu` instead. */
5567 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
5568 dwarf2_per_cu_data
*per_cu
,
5569 dwarf2_per_objfile
*per_objfile
,
5570 enum language pretend_language
)
5572 /* Mark the dependence relation so that we don't flush PER_CU
5574 if (dependent_cu
!= NULL
)
5575 dependent_cu
->add_dependence (per_cu
);
5577 /* If it's already on the queue, we have nothing to do. */
5580 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
5582 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
5584 /* If the CU is queued for expansion, it should not already be
5586 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
5588 /* The DIEs are already loaded, the caller doesn't need to do it. */
5592 bool queued
= false;
5593 if (!per_objfile
->symtab_set_p (per_cu
))
5595 /* Add it to the queue. */
5596 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
5600 /* If the compilation unit is already loaded, just mark it as
5602 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
5606 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
5607 and the DIEs are not already loaded. */
5608 return queued
&& cu
== nullptr;
5611 /* Process the queue. */
5614 process_queue (dwarf2_per_objfile
*per_objfile
)
5616 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
5617 objfile_name (per_objfile
->objfile
));
5619 /* The queue starts out with one item, but following a DIE reference
5620 may load a new CU, adding it to the end of the queue. */
5621 while (!per_objfile
->queue
->empty ())
5623 dwarf2_queue_item
&item
= per_objfile
->queue
->front ();
5624 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
5626 if (!per_objfile
->symtab_set_p (per_cu
))
5628 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
5630 /* Skip dummy CUs. */
5633 unsigned int debug_print_threshold
;
5636 if (per_cu
->is_debug_types
)
5638 struct signatured_type
*sig_type
=
5639 (struct signatured_type
*) per_cu
;
5641 sprintf (buf
, "TU %s at offset %s",
5642 hex_string (sig_type
->signature
),
5643 sect_offset_str (per_cu
->sect_off
));
5644 /* There can be 100s of TUs.
5645 Only print them in verbose mode. */
5646 debug_print_threshold
= 2;
5650 sprintf (buf
, "CU at offset %s",
5651 sect_offset_str (per_cu
->sect_off
));
5652 debug_print_threshold
= 1;
5655 if (dwarf_read_debug
>= debug_print_threshold
)
5656 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
5658 if (per_cu
->is_debug_types
)
5659 process_full_type_unit (cu
, item
.pretend_language
);
5661 process_full_comp_unit (cu
, item
.pretend_language
);
5663 if (dwarf_read_debug
>= debug_print_threshold
)
5664 dwarf_read_debug_printf ("Done expanding %s", buf
);
5669 per_objfile
->queue
->pop ();
5672 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
5673 objfile_name (per_objfile
->objfile
));
5676 /* Load the DIEs associated with PER_CU into memory.
5678 In some cases, the caller, while reading partial symbols, will need to load
5679 the full symbols for the CU for some reason. It will already have a
5680 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
5681 rather than creating a new one. */
5684 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
5685 dwarf2_per_objfile
*per_objfile
,
5686 dwarf2_cu
*existing_cu
,
5688 enum language pretend_language
)
5690 gdb_assert (! this_cu
->is_debug_types
);
5692 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
5696 struct dwarf2_cu
*cu
= reader
.cu
;
5697 const gdb_byte
*info_ptr
= reader
.info_ptr
;
5699 gdb_assert (cu
->die_hash
== NULL
);
5701 htab_create_alloc_ex (cu
->header
.get_length_without_initial () / 12,
5705 &cu
->comp_unit_obstack
,
5706 hashtab_obstack_allocate
,
5707 dummy_obstack_deallocate
);
5709 if (reader
.comp_unit_die
->has_children
)
5710 reader
.comp_unit_die
->child
5711 = read_die_and_siblings (&reader
, reader
.info_ptr
,
5712 &info_ptr
, reader
.comp_unit_die
);
5713 cu
->dies
= reader
.comp_unit_die
;
5714 /* comp_unit_die is not stored in die_hash, no need. */
5716 /* We try not to read any attributes in this function, because not
5717 all CUs needed for references have been loaded yet, and symbol
5718 table processing isn't initialized. But we have to set the CU language,
5719 or we won't be able to build types correctly.
5720 Similarly, if we do not read the producer, we can not apply
5721 producer-specific interpretation. */
5722 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
5727 /* Add a DIE to the delayed physname list. */
5730 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5731 const char *name
, struct die_info
*die
,
5732 struct dwarf2_cu
*cu
)
5734 struct delayed_method_info mi
;
5736 mi
.fnfield_index
= fnfield_index
;
5740 cu
->method_list
.push_back (mi
);
5743 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
5744 "const" / "volatile". If so, decrements LEN by the length of the
5745 modifier and return true. Otherwise return false. */
5749 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
5751 size_t mod_len
= sizeof (mod
) - 1;
5752 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
5760 /* Compute the physnames of any methods on the CU's method list.
5762 The computation of method physnames is delayed in order to avoid the
5763 (bad) condition that one of the method's formal parameters is of an as yet
5767 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5769 /* Only C++ delays computing physnames. */
5770 if (cu
->method_list
.empty ())
5772 gdb_assert (cu
->lang () == language_cplus
);
5774 for (const delayed_method_info
&mi
: cu
->method_list
)
5776 const char *physname
;
5777 struct fn_fieldlist
*fn_flp
5778 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
5779 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
5780 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
5781 = physname
? physname
: "";
5783 /* Since there's no tag to indicate whether a method is a
5784 const/volatile overload, extract that information out of the
5786 if (physname
!= NULL
)
5788 size_t len
= strlen (physname
);
5792 if (physname
[len
] == ')') /* shortcut */
5794 else if (check_modifier (physname
, len
, " const"))
5795 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
5796 else if (check_modifier (physname
, len
, " volatile"))
5797 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
5804 /* The list is no longer needed. */
5805 cu
->method_list
.clear ();
5808 /* Go objects should be embedded in a DW_TAG_module DIE,
5809 and it's not clear if/how imported objects will appear.
5810 To keep Go support simple until that's worked out,
5811 go back through what we've read and create something usable.
5812 We could do this while processing each DIE, and feels kinda cleaner,
5813 but that way is more invasive.
5814 This is to, for example, allow the user to type "p var" or "b main"
5815 without having to specify the package name, and allow lookups
5816 of module.object to work in contexts that use the expression
5820 fixup_go_packaging (struct dwarf2_cu
*cu
)
5822 gdb::unique_xmalloc_ptr
<char> package_name
;
5823 struct pending
*list
;
5826 for (list
= *cu
->get_builder ()->get_global_symbols ();
5830 for (i
= 0; i
< list
->nsyms
; ++i
)
5832 struct symbol
*sym
= list
->symbol
[i
];
5834 if (sym
->language () == language_go
5835 && sym
->aclass () == LOC_BLOCK
)
5837 gdb::unique_xmalloc_ptr
<char> this_package_name
5838 = go_symbol_package_name (sym
);
5840 if (this_package_name
== NULL
)
5842 if (package_name
== NULL
)
5843 package_name
= std::move (this_package_name
);
5846 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
5847 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
5848 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
5849 (sym
->symtab () != NULL
5850 ? symtab_to_filename_for_display
5852 : objfile_name (objfile
)),
5853 this_package_name
.get (), package_name
.get ());
5859 if (package_name
!= NULL
)
5861 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
5862 const char *saved_package_name
= objfile
->intern (package_name
.get ());
5863 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
5864 saved_package_name
);
5867 sym
= new (&objfile
->objfile_obstack
) symbol
;
5868 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
5869 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
5870 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5871 e.g., "main" finds the "main" module and not C's main(). */
5872 sym
->set_domain (STRUCT_DOMAIN
);
5873 sym
->set_aclass_index (LOC_TYPEDEF
);
5874 sym
->set_type (type
);
5876 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
5880 /* Allocate a fully-qualified name consisting of the two parts on the
5884 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
5886 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
5889 /* A helper that allocates a variant part to attach to a Rust enum
5890 type. OBSTACK is where the results should be allocated. TYPE is
5891 the type we're processing. DISCRIMINANT_INDEX is the index of the
5892 discriminant. It must be the index of one of the fields of TYPE,
5893 or -1 to mean there is no discriminant (univariant enum).
5894 DEFAULT_INDEX is the index of the default field; or -1 if there is
5895 no default. RANGES is indexed by "effective" field number (the
5896 field index, but omitting the discriminant and default fields) and
5897 must hold the discriminant values used by the variants. Note that
5898 RANGES must have a lifetime at least as long as OBSTACK -- either
5899 already allocated on it, or static. */
5902 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
5903 int discriminant_index
, int default_index
,
5904 gdb::array_view
<discriminant_range
> ranges
)
5906 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
5907 gdb_assert (discriminant_index
== -1
5908 || (discriminant_index
>= 0
5909 && discriminant_index
< type
->num_fields ()));
5910 gdb_assert (default_index
== -1
5911 || (default_index
>= 0 && default_index
< type
->num_fields ()));
5913 /* We have one variant for each non-discriminant field. */
5914 int n_variants
= type
->num_fields ();
5915 if (discriminant_index
!= -1)
5918 variant
*variants
= new (obstack
) variant
[n_variants
];
5921 for (int i
= 0; i
< type
->num_fields (); ++i
)
5923 if (i
== discriminant_index
)
5926 variants
[var_idx
].first_field
= i
;
5927 variants
[var_idx
].last_field
= i
+ 1;
5929 /* The default field does not need a range, but other fields do.
5930 We skipped the discriminant above. */
5931 if (i
!= default_index
)
5933 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
5940 gdb_assert (range_idx
== ranges
.size ());
5941 gdb_assert (var_idx
== n_variants
);
5943 variant_part
*part
= new (obstack
) variant_part
;
5944 part
->discriminant_index
= discriminant_index
;
5945 /* If there is no discriminant, then whether it is signed is of no
5948 = (discriminant_index
== -1
5950 : type
->field (discriminant_index
).type ()->is_unsigned ());
5951 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
5953 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
5954 gdb::array_view
<variant_part
> *prop_value
5955 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
5957 struct dynamic_prop prop
;
5958 prop
.set_variant_parts (prop_value
);
5960 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
5963 /* Some versions of rustc emitted enums in an unusual way.
5965 Ordinary enums were emitted as unions. The first element of each
5966 structure in the union was named "RUST$ENUM$DISR". This element
5967 held the discriminant.
5969 These versions of Rust also implemented the "non-zero"
5970 optimization. When the enum had two values, and one is empty and
5971 the other holds a pointer that cannot be zero, the pointer is used
5972 as the discriminant, with a zero value meaning the empty variant.
5973 Here, the union's first member is of the form
5974 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
5975 where the fieldnos are the indices of the fields that should be
5976 traversed in order to find the field (which may be several fields deep)
5977 and the variantname is the name of the variant of the case when the
5980 This function recognizes whether TYPE is of one of these forms,
5981 and, if so, smashes it to be a variant type. */
5984 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
5986 gdb_assert (type
->code () == TYPE_CODE_UNION
);
5988 /* We don't need to deal with empty enums. */
5989 if (type
->num_fields () == 0)
5992 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
5993 if (type
->num_fields () == 1
5994 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
5996 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
5998 /* Decode the field name to find the offset of the
6000 ULONGEST bit_offset
= 0;
6001 struct type
*field_type
= type
->field (0).type ();
6002 while (name
[0] >= '0' && name
[0] <= '9')
6005 unsigned long index
= strtoul (name
, &tail
, 10);
6008 || index
>= field_type
->num_fields ()
6009 || (field_type
->field (index
).loc_kind ()
6010 != FIELD_LOC_KIND_BITPOS
))
6012 complaint (_("Could not parse Rust enum encoding string \"%s\""
6014 type
->field (0).name (),
6015 objfile_name (objfile
));
6020 bit_offset
+= field_type
->field (index
).loc_bitpos ();
6021 field_type
= field_type
->field (index
).type ();
6024 /* Smash this type to be a structure type. We have to do this
6025 because the type has already been recorded. */
6026 type
->set_code (TYPE_CODE_STRUCT
);
6027 type
->set_num_fields (3);
6028 /* Save the field we care about. */
6029 struct field saved_field
= type
->field (0);
6031 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
6033 /* Put the discriminant at index 0. */
6034 type
->field (0).set_type (field_type
);
6035 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
6036 type
->field (0).set_name ("<<discriminant>>");
6037 type
->field (0).set_loc_bitpos (bit_offset
);
6039 /* The order of fields doesn't really matter, so put the real
6040 field at index 1 and the data-less field at index 2. */
6041 type
->field (1) = saved_field
;
6042 type
->field (1).set_name
6043 (rust_last_path_segment (type
->field (1).type ()->name ()));
6044 type
->field (1).type ()->set_name
6045 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
6046 type
->field (1).name ()));
6048 const char *dataless_name
6049 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
6051 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
6053 type
->field (2).set_type (dataless_type
);
6054 /* NAME points into the original discriminant name, which
6055 already has the correct lifetime. */
6056 type
->field (2).set_name (name
);
6057 type
->field (2).set_loc_bitpos (0);
6059 /* Indicate that this is a variant type. */
6060 static discriminant_range ranges
[1] = { { 0, 0 } };
6061 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
6063 /* A union with a single anonymous field is probably an old-style
6065 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
6067 /* Smash this type to be a structure type. We have to do this
6068 because the type has already been recorded. */
6069 type
->set_code (TYPE_CODE_STRUCT
);
6071 struct type
*field_type
= type
->field (0).type ();
6072 const char *variant_name
6073 = rust_last_path_segment (field_type
->name ());
6074 type
->field (0).set_name (variant_name
);
6075 field_type
->set_name
6076 (rust_fully_qualify (&objfile
->objfile_obstack
,
6077 type
->name (), variant_name
));
6079 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
6083 struct type
*disr_type
= nullptr;
6084 for (int i
= 0; i
< type
->num_fields (); ++i
)
6086 disr_type
= type
->field (i
).type ();
6088 if (disr_type
->code () != TYPE_CODE_STRUCT
)
6090 /* All fields of a true enum will be structs. */
6093 else if (disr_type
->num_fields () == 0)
6095 /* Could be data-less variant, so keep going. */
6096 disr_type
= nullptr;
6098 else if (strcmp (disr_type
->field (0).name (),
6099 "RUST$ENUM$DISR") != 0)
6101 /* Not a Rust enum. */
6111 /* If we got here without a discriminant, then it's probably
6113 if (disr_type
== nullptr)
6116 /* Smash this type to be a structure type. We have to do this
6117 because the type has already been recorded. */
6118 type
->set_code (TYPE_CODE_STRUCT
);
6120 /* Make space for the discriminant field. */
6121 struct field
*disr_field
= &disr_type
->field (0);
6123 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
6124 * sizeof (struct field
)));
6125 memcpy (new_fields
+ 1, type
->fields (),
6126 type
->num_fields () * sizeof (struct field
));
6127 type
->set_fields (new_fields
);
6128 type
->set_num_fields (type
->num_fields () + 1);
6130 /* Install the discriminant at index 0 in the union. */
6131 type
->field (0) = *disr_field
;
6132 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
6133 type
->field (0).set_name ("<<discriminant>>");
6135 /* We need a way to find the correct discriminant given a
6136 variant name. For convenience we build a map here. */
6137 struct type
*enum_type
= disr_field
->type ();
6138 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
6139 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
6141 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
6144 = rust_last_path_segment (enum_type
->field (i
).name ());
6145 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
6149 int n_fields
= type
->num_fields ();
6150 /* We don't need a range entry for the discriminant, but we do
6151 need one for every other field, as there is no default
6153 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
6156 /* Skip the discriminant here. */
6157 for (int i
= 1; i
< n_fields
; ++i
)
6159 /* Find the final word in the name of this variant's type.
6160 That name can be used to look up the correct
6162 const char *variant_name
6163 = rust_last_path_segment (type
->field (i
).type ()->name ());
6165 auto iter
= discriminant_map
.find (variant_name
);
6166 if (iter
!= discriminant_map
.end ())
6168 ranges
[i
- 1].low
= iter
->second
;
6169 ranges
[i
- 1].high
= iter
->second
;
6172 /* In Rust, each element should have the size of the
6174 type
->field (i
).type ()->set_length (type
->length ());
6176 /* Remove the discriminant field, if it exists. */
6177 struct type
*sub_type
= type
->field (i
).type ();
6178 if (sub_type
->num_fields () > 0)
6180 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
6181 sub_type
->set_fields (sub_type
->fields () + 1);
6183 type
->field (i
).set_name (variant_name
);
6185 (rust_fully_qualify (&objfile
->objfile_obstack
,
6186 type
->name (), variant_name
));
6189 /* Indicate that this is a variant type. */
6190 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
6191 gdb::array_view
<discriminant_range
> (ranges
,
6196 /* Rewrite some Rust unions to be structures with variants parts. */
6199 rust_union_quirks (struct dwarf2_cu
*cu
)
6201 gdb_assert (cu
->lang () == language_rust
);
6202 for (type
*type_
: cu
->rust_unions
)
6203 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
6204 /* We don't need this any more. */
6205 cu
->rust_unions
.clear ();
6210 type_unit_group_unshareable
*
6211 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
6213 auto iter
= this->m_type_units
.find (tu_group
);
6214 if (iter
!= this->m_type_units
.end ())
6215 return iter
->second
.get ();
6217 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
6218 type_unit_group_unshareable
*result
= uniq
.get ();
6219 this->m_type_units
[tu_group
] = std::move (uniq
);
6224 dwarf2_per_objfile::get_type_for_signatured_type
6225 (signatured_type
*sig_type
) const
6227 auto iter
= this->m_type_map
.find (sig_type
);
6228 if (iter
== this->m_type_map
.end ())
6231 return iter
->second
;
6234 void dwarf2_per_objfile::set_type_for_signatured_type
6235 (signatured_type
*sig_type
, struct type
*type
)
6237 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
6239 this->m_type_map
[sig_type
] = type
;
6242 /* A helper function for computing the list of all symbol tables
6243 included by PER_CU. */
6246 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
6247 htab_t all_children
, htab_t all_type_symtabs
,
6248 dwarf2_per_cu_data
*per_cu
,
6249 dwarf2_per_objfile
*per_objfile
,
6250 struct compunit_symtab
*immediate_parent
)
6252 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6255 /* This inclusion and its children have been processed. */
6261 /* Only add a CU if it has a symbol table. */
6262 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
6265 /* If this is a type unit only add its symbol table if we haven't
6266 seen it yet (type unit per_cu's can share symtabs). */
6267 if (per_cu
->is_debug_types
)
6269 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
6273 result
->push_back (cust
);
6274 if (cust
->user
== NULL
)
6275 cust
->user
= immediate_parent
;
6280 result
->push_back (cust
);
6281 if (cust
->user
== NULL
)
6282 cust
->user
= immediate_parent
;
6286 if (!per_cu
->imported_symtabs_empty ())
6287 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
6289 recursively_compute_inclusions (result
, all_children
,
6290 all_type_symtabs
, ptr
, per_objfile
,
6295 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
6299 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
6300 dwarf2_per_objfile
*per_objfile
)
6302 gdb_assert (! per_cu
->is_debug_types
);
6304 if (!per_cu
->imported_symtabs_empty ())
6307 std::vector
<compunit_symtab
*> result_symtabs
;
6308 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
6310 /* If we don't have a symtab, we can just skip this case. */
6314 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
6316 NULL
, xcalloc
, xfree
));
6317 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
6319 NULL
, xcalloc
, xfree
));
6321 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
6323 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
6324 all_type_symtabs
.get (), ptr
,
6328 /* Now we have a transitive closure of all the included symtabs. */
6329 len
= result_symtabs
.size ();
6331 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
6332 struct compunit_symtab
*, len
+ 1);
6333 memcpy (cust
->includes
, result_symtabs
.data (),
6334 len
* sizeof (compunit_symtab
*));
6335 cust
->includes
[len
] = NULL
;
6339 /* Compute the 'includes' field for the symtabs of all the CUs we just
6343 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
6345 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
6347 if (! iter
->is_debug_types
)
6348 compute_compunit_symtab_includes (iter
, per_objfile
);
6351 per_objfile
->per_bfd
->just_read_cus
.clear ();
6354 /* Generate full symbol information for CU, whose DIEs have
6355 already been loaded into memory. */
6358 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
6360 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6361 struct objfile
*objfile
= per_objfile
->objfile
;
6362 struct gdbarch
*gdbarch
= objfile
->arch ();
6363 CORE_ADDR lowpc
, highpc
;
6364 struct compunit_symtab
*cust
;
6366 struct block
*static_block
;
6369 baseaddr
= objfile
->text_section_offset ();
6371 /* Clear the list here in case something was left over. */
6372 cu
->method_list
.clear ();
6374 dwarf2_find_base_address (cu
->dies
, cu
);
6376 /* Before we start reading the top-level DIE, ensure it has a valid tag
6378 switch (cu
->dies
->tag
)
6380 case DW_TAG_compile_unit
:
6381 case DW_TAG_partial_unit
:
6382 case DW_TAG_type_unit
:
6385 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
6386 dwarf_tag_name (cu
->dies
->tag
),
6387 sect_offset_str (cu
->per_cu
->sect_off
),
6388 objfile_name (per_objfile
->objfile
));
6391 /* Do line number decoding in read_file_scope () */
6392 process_die (cu
->dies
, cu
);
6394 /* For now fudge the Go package. */
6395 if (cu
->lang () == language_go
)
6396 fixup_go_packaging (cu
);
6398 /* Now that we have processed all the DIEs in the CU, all the types
6399 should be complete, and it should now be safe to compute all of the
6401 compute_delayed_physnames (cu
);
6403 if (cu
->lang () == language_rust
)
6404 rust_union_quirks (cu
);
6406 /* Some compilers don't define a DW_AT_high_pc attribute for the
6407 compilation unit. If the DW_AT_high_pc is missing, synthesize
6408 it, by scanning the DIE's below the compilation unit. */
6409 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6411 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
6413 = cu
->get_builder ()->end_compunit_symtab_get_static_block (addr
, 0, 1);
6415 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6416 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6417 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6418 addrmap to help ensure it has an accurate map of pc values belonging to
6420 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6422 cust
= cu
->get_builder ()->end_compunit_symtab_from_static_block
6427 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6429 /* Set symtab language to language from DW_AT_language. If the
6430 compilation is from a C file generated by language preprocessors, do
6431 not set the language if it was already deduced by start_subfile. */
6432 if (!(cu
->lang () == language_c
6433 && cust
->primary_filetab ()->language () != language_unknown
))
6434 cust
->primary_filetab ()->set_language (cu
->lang ());
6436 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6437 produce DW_AT_location with location lists but it can be possibly
6438 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6439 there were bugs in prologue debug info, fixed later in GCC-4.5
6440 by "unwind info for epilogues" patch (which is not directly related).
6442 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6443 needed, it would be wrong due to missing DW_AT_producer there.
6445 Still one can confuse GDB by using non-standard GCC compilation
6446 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6448 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6449 cust
->set_locations_valid (true);
6452 if (cu
->producer
!= nullptr
6453 && producer_is_gcc (cu
->producer
, &major
, &minor
)
6454 && (major
< 4 || (major
== 4 && minor
< 5)))
6455 /* Don't trust gcc < 4.5.x. */
6456 cust
->set_epilogue_unwind_valid (false);
6458 cust
->set_epilogue_unwind_valid (true);
6460 cust
->set_call_site_htab (cu
->call_site_htab
);
6463 per_objfile
->set_symtab (cu
->per_cu
, cust
);
6465 /* Push it for inclusion processing later. */
6466 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
6468 /* Not needed any more. */
6469 cu
->reset_builder ();
6472 /* Generate full symbol information for type unit CU, whose DIEs have
6473 already been loaded into memory. */
6476 process_full_type_unit (dwarf2_cu
*cu
,
6477 enum language pretend_language
)
6479 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6480 struct compunit_symtab
*cust
;
6481 struct signatured_type
*sig_type
;
6483 gdb_assert (cu
->per_cu
->is_debug_types
);
6484 sig_type
= (struct signatured_type
*) cu
->per_cu
;
6486 /* Clear the list here in case something was left over. */
6487 cu
->method_list
.clear ();
6489 /* The symbol tables are set up in read_type_unit_scope. */
6490 process_die (cu
->dies
, cu
);
6492 /* For now fudge the Go package. */
6493 if (cu
->lang () == language_go
)
6494 fixup_go_packaging (cu
);
6496 /* Now that we have processed all the DIEs in the CU, all the types
6497 should be complete, and it should now be safe to compute all of the
6499 compute_delayed_physnames (cu
);
6501 if (cu
->lang () == language_rust
)
6502 rust_union_quirks (cu
);
6504 /* TUs share symbol tables.
6505 If this is the first TU to use this symtab, complete the construction
6506 of it with end_expandable_symtab. Otherwise, complete the addition of
6507 this TU's symbols to the existing symtab. */
6508 type_unit_group_unshareable
*tug_unshare
=
6509 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
6510 if (tug_unshare
->compunit_symtab
== NULL
)
6512 buildsym_compunit
*builder
= cu
->get_builder ();
6513 cust
= builder
->end_expandable_symtab (0);
6514 tug_unshare
->compunit_symtab
= cust
;
6518 /* Set symtab language to language from DW_AT_language. If the
6519 compilation is from a C file generated by language preprocessors,
6520 do not set the language if it was already deduced by
6522 if (!(cu
->lang () == language_c
6523 && cust
->primary_filetab ()->language () != language_c
))
6524 cust
->primary_filetab ()->set_language (cu
->lang ());
6529 cu
->get_builder ()->augment_type_symtab ();
6530 cust
= tug_unshare
->compunit_symtab
;
6533 per_objfile
->set_symtab (cu
->per_cu
, cust
);
6535 /* Not needed any more. */
6536 cu
->reset_builder ();
6539 /* Process an imported unit DIE. */
6542 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6544 struct attribute
*attr
;
6546 /* For now we don't handle imported units in type units. */
6547 if (cu
->per_cu
->is_debug_types
)
6549 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6550 " supported in type units [in module %s]"),
6551 objfile_name (cu
->per_objfile
->objfile
));
6554 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6557 sect_offset sect_off
= attr
->get_ref_die_offset ();
6558 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
6559 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6560 dwarf2_per_cu_data
*per_cu
6561 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
6562 per_objfile
->per_bfd
);
6564 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
6565 into another compilation unit, at root level. Regard this as a hint,
6566 and ignore it. This is a best effort, it only works if unit_type and
6567 lang are already set. */
6568 if (die
->parent
&& die
->parent
->parent
== NULL
6569 && per_cu
->unit_type (false) == DW_UT_compile
6570 && per_cu
->lang (false) == language_cplus
)
6573 /* If necessary, add it to the queue and load its DIEs. */
6574 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
6576 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
6577 false, cu
->lang ());
6579 cu
->per_cu
->imported_symtabs_push (per_cu
);
6583 /* RAII object that represents a process_die scope: i.e.,
6584 starts/finishes processing a DIE. */
6585 class process_die_scope
6588 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
6589 : m_die (die
), m_cu (cu
)
6591 /* We should only be processing DIEs not already in process. */
6592 gdb_assert (!m_die
->in_process
);
6593 m_die
->in_process
= true;
6596 ~process_die_scope ()
6598 m_die
->in_process
= false;
6600 /* If we're done processing the DIE for the CU that owns the line
6601 header, we don't need the line header anymore. */
6602 if (m_cu
->line_header_die_owner
== m_die
)
6604 delete m_cu
->line_header
;
6605 m_cu
->line_header
= NULL
;
6606 m_cu
->line_header_die_owner
= NULL
;
6615 /* Process a die and its children. */
6618 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6620 process_die_scope
scope (die
, cu
);
6624 case DW_TAG_padding
:
6626 case DW_TAG_compile_unit
:
6627 case DW_TAG_partial_unit
:
6628 read_file_scope (die
, cu
);
6630 case DW_TAG_type_unit
:
6631 read_type_unit_scope (die
, cu
);
6633 case DW_TAG_subprogram
:
6634 /* Nested subprograms in Fortran get a prefix. */
6635 if (cu
->lang () == language_fortran
6636 && die
->parent
!= NULL
6637 && die
->parent
->tag
== DW_TAG_subprogram
)
6638 cu
->processing_has_namespace_info
= true;
6640 case DW_TAG_inlined_subroutine
:
6641 read_func_scope (die
, cu
);
6643 case DW_TAG_lexical_block
:
6644 case DW_TAG_try_block
:
6645 case DW_TAG_catch_block
:
6646 read_lexical_block_scope (die
, cu
);
6648 case DW_TAG_call_site
:
6649 case DW_TAG_GNU_call_site
:
6650 read_call_site_scope (die
, cu
);
6652 case DW_TAG_class_type
:
6653 case DW_TAG_interface_type
:
6654 case DW_TAG_structure_type
:
6655 case DW_TAG_union_type
:
6656 case DW_TAG_namelist
:
6657 process_structure_scope (die
, cu
);
6659 case DW_TAG_enumeration_type
:
6660 process_enumeration_scope (die
, cu
);
6663 /* These dies have a type, but processing them does not create
6664 a symbol or recurse to process the children. Therefore we can
6665 read them on-demand through read_type_die. */
6666 case DW_TAG_subroutine_type
:
6667 case DW_TAG_set_type
:
6668 case DW_TAG_pointer_type
:
6669 case DW_TAG_ptr_to_member_type
:
6670 case DW_TAG_reference_type
:
6671 case DW_TAG_rvalue_reference_type
:
6672 case DW_TAG_string_type
:
6675 case DW_TAG_array_type
:
6676 /* We only need to handle this case for Ada -- in other
6677 languages, it's normal for the compiler to emit a typedef
6679 if (cu
->lang () != language_ada
)
6682 case DW_TAG_base_type
:
6683 case DW_TAG_subrange_type
:
6684 case DW_TAG_generic_subrange
:
6685 case DW_TAG_typedef
:
6686 /* Add a typedef symbol for the type definition, if it has a
6688 new_symbol (die
, read_type_die (die
, cu
), cu
);
6690 case DW_TAG_common_block
:
6691 read_common_block (die
, cu
);
6693 case DW_TAG_common_inclusion
:
6695 case DW_TAG_namespace
:
6696 cu
->processing_has_namespace_info
= true;
6697 read_namespace (die
, cu
);
6700 cu
->processing_has_namespace_info
= true;
6701 read_module (die
, cu
);
6703 case DW_TAG_imported_declaration
:
6704 cu
->processing_has_namespace_info
= true;
6705 if (read_alias (die
, cu
))
6707 /* The declaration is neither a global namespace nor a variable
6710 case DW_TAG_imported_module
:
6711 cu
->processing_has_namespace_info
= true;
6712 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6713 || cu
->lang () != language_fortran
))
6714 complaint (_("Tag '%s' has unexpected children"),
6715 dwarf_tag_name (die
->tag
));
6716 read_import_statement (die
, cu
);
6719 case DW_TAG_imported_unit
:
6720 process_imported_unit_die (die
, cu
);
6723 case DW_TAG_variable
:
6724 read_variable (die
, cu
);
6728 new_symbol (die
, NULL
, cu
);
6733 /* DWARF name computation. */
6735 /* A helper function for dwarf2_compute_name which determines whether DIE
6736 needs to have the name of the scope prepended to the name listed in the
6740 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6742 struct attribute
*attr
;
6746 case DW_TAG_namespace
:
6747 case DW_TAG_typedef
:
6748 case DW_TAG_class_type
:
6749 case DW_TAG_interface_type
:
6750 case DW_TAG_structure_type
:
6751 case DW_TAG_union_type
:
6752 case DW_TAG_enumeration_type
:
6753 case DW_TAG_enumerator
:
6754 case DW_TAG_subprogram
:
6755 case DW_TAG_inlined_subroutine
:
6757 case DW_TAG_imported_declaration
:
6760 case DW_TAG_variable
:
6761 case DW_TAG_constant
:
6762 /* We only need to prefix "globally" visible variables. These include
6763 any variable marked with DW_AT_external or any variable that
6764 lives in a namespace. [Variables in anonymous namespaces
6765 require prefixing, but they are not DW_AT_external.] */
6767 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6769 struct dwarf2_cu
*spec_cu
= cu
;
6771 return die_needs_namespace (die_specification (die
, &spec_cu
),
6775 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6776 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6777 && die
->parent
->tag
!= DW_TAG_module
)
6779 /* A variable in a lexical block of some kind does not need a
6780 namespace, even though in C++ such variables may be external
6781 and have a mangled name. */
6782 if (die
->parent
->tag
== DW_TAG_lexical_block
6783 || die
->parent
->tag
== DW_TAG_try_block
6784 || die
->parent
->tag
== DW_TAG_catch_block
6785 || die
->parent
->tag
== DW_TAG_subprogram
)
6794 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
6795 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
6796 defined for the given DIE. */
6798 static struct attribute
*
6799 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
6801 struct attribute
*attr
;
6803 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6805 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6810 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
6811 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
6812 defined for the given DIE. */
6815 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6817 const char *linkage_name
;
6819 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
6820 if (linkage_name
== NULL
)
6821 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6823 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
6824 See https://github.com/rust-lang/rust/issues/32925. */
6825 if (cu
->lang () == language_rust
&& linkage_name
!= NULL
6826 && strchr (linkage_name
, '{') != NULL
)
6827 linkage_name
= NULL
;
6829 return linkage_name
;
6832 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6833 compute the physname for the object, which include a method's:
6834 - formal parameters (C++),
6835 - receiver type (Go),
6837 The term "physname" is a bit confusing.
6838 For C++, for example, it is the demangled name.
6839 For Go, for example, it's the mangled name.
6841 For Ada, return the DIE's linkage name rather than the fully qualified
6842 name. PHYSNAME is ignored..
6844 The result is allocated on the objfile->per_bfd's obstack and
6848 dwarf2_compute_name (const char *name
,
6849 struct die_info
*die
, struct dwarf2_cu
*cu
,
6852 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
6855 name
= dwarf2_name (die
, cu
);
6857 enum language lang
= cu
->lang ();
6859 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
6860 but otherwise compute it by typename_concat inside GDB.
6861 FIXME: Actually this is not really true, or at least not always true.
6862 It's all very confusing. compute_and_set_names doesn't try to demangle
6863 Fortran names because there is no mangling standard. So new_symbol
6864 will set the demangled name to the result of dwarf2_full_name, and it is
6865 the demangled name that GDB uses if it exists. */
6866 if (lang
== language_ada
6867 || (lang
== language_fortran
&& physname
))
6869 /* For Ada unit, we prefer the linkage name over the name, as
6870 the former contains the exported name, which the user expects
6871 to be able to reference. Ideally, we want the user to be able
6872 to reference this entity using either natural or linkage name,
6873 but we haven't started looking at this enhancement yet. */
6874 const char *linkage_name
= dw2_linkage_name (die
, cu
);
6876 if (linkage_name
!= NULL
)
6877 return linkage_name
;
6880 /* These are the only languages we know how to qualify names in. */
6882 && (lang
== language_cplus
6883 || lang
== language_fortran
|| lang
== language_d
6884 || lang
== language_rust
))
6886 if (die_needs_namespace (die
, cu
))
6892 prefix
= determine_prefix (die
, cu
);
6893 if (*prefix
!= '\0')
6895 gdb::unique_xmalloc_ptr
<char> prefixed_name
6896 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
6898 buf
.puts (prefixed_name
.get ());
6903 /* Template parameters may be specified in the DIE's DW_AT_name, or
6904 as children with DW_TAG_template_type_param or
6905 DW_TAG_value_type_param. If the latter, add them to the name
6906 here. If the name already has template parameters, then
6907 skip this step; some versions of GCC emit both, and
6908 it is more efficient to use the pre-computed name.
6910 Something to keep in mind about this process: it is very
6911 unlikely, or in some cases downright impossible, to produce
6912 something that will match the mangled name of a function.
6913 If the definition of the function has the same debug info,
6914 we should be able to match up with it anyway. But fallbacks
6915 using the minimal symbol, for instance to find a method
6916 implemented in a stripped copy of libstdc++, will not work.
6917 If we do not have debug info for the definition, we will have to
6918 match them up some other way.
6920 When we do name matching there is a related problem with function
6921 templates; two instantiated function templates are allowed to
6922 differ only by their return types, which we do not add here. */
6924 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
6926 struct attribute
*attr
;
6927 struct die_info
*child
;
6930 die
->building_fullname
= 1;
6932 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6936 const gdb_byte
*bytes
;
6937 struct dwarf2_locexpr_baton
*baton
;
6940 if (child
->tag
!= DW_TAG_template_type_param
6941 && child
->tag
!= DW_TAG_template_value_param
)
6952 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6955 complaint (_("template parameter missing DW_AT_type"));
6956 buf
.puts ("UNKNOWN_TYPE");
6959 type
= die_type (child
, cu
);
6961 if (child
->tag
== DW_TAG_template_type_param
)
6963 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
6964 &type_print_raw_options
);
6968 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6971 complaint (_("template parameter missing "
6972 "DW_AT_const_value"));
6973 buf
.puts ("UNKNOWN_VALUE");
6977 dwarf2_const_value_attr (attr
, type
, name
,
6978 &cu
->comp_unit_obstack
, cu
,
6979 &value
, &bytes
, &baton
);
6981 if (type
->has_no_signedness ())
6982 /* GDB prints characters as NUMBER 'CHAR'. If that's
6983 changed, this can use value_print instead. */
6984 cu
->language_defn
->printchar (value
, type
, &buf
);
6987 struct value_print_options opts
;
6990 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6994 baton
->per_objfile
);
6995 else if (bytes
!= NULL
)
6997 v
= value::allocate (type
);
6998 memcpy (v
->contents_writeable ().data (), bytes
,
7002 v
= value_from_longest (type
, value
);
7004 /* Specify decimal so that we do not depend on
7006 get_formatted_print_options (&opts
, 'd');
7008 value_print (v
, &buf
, &opts
);
7013 die
->building_fullname
= 0;
7017 /* Close the argument list, with a space if necessary
7018 (nested templates). */
7019 if (!buf
.empty () && buf
.string ().back () == '>')
7026 /* For C++ methods, append formal parameter type
7027 information, if PHYSNAME. */
7029 if (physname
&& die
->tag
== DW_TAG_subprogram
7030 && lang
== language_cplus
)
7032 struct type
*type
= read_type_die (die
, cu
);
7034 c_type_print_args (type
, &buf
, 1, lang
,
7035 &type_print_raw_options
);
7037 if (lang
== language_cplus
)
7039 /* Assume that an artificial first parameter is
7040 "this", but do not crash if it is not. RealView
7041 marks unnamed (and thus unused) parameters as
7042 artificial; there is no way to differentiate
7044 if (type
->num_fields () > 0
7045 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7046 && type
->field (0).type ()->code () == TYPE_CODE_PTR
7047 && TYPE_CONST (type
->field (0).type ()->target_type ()))
7048 buf
.puts (" const");
7052 const std::string
&intermediate_name
= buf
.string ();
7054 const char *canonical_name
7055 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
7058 /* If we only computed INTERMEDIATE_NAME, or if
7059 INTERMEDIATE_NAME is already canonical, then we need to
7061 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
7062 name
= objfile
->intern (intermediate_name
);
7064 name
= canonical_name
;
7071 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7072 If scope qualifiers are appropriate they will be added. The result
7073 will be allocated on the storage_obstack, or NULL if the DIE does
7074 not have a name. NAME may either be from a previous call to
7075 dwarf2_name or NULL.
7077 The output string will be canonicalized (if C++). */
7080 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7082 return dwarf2_compute_name (name
, die
, cu
, 0);
7085 /* Construct a physname for the given DIE in CU. NAME may either be
7086 from a previous call to dwarf2_name or NULL. The result will be
7087 allocated on the objfile_objstack or NULL if the DIE does not have a
7090 The output string will be canonicalized (if C++). */
7093 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7095 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
7096 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7099 /* In this case dwarf2_compute_name is just a shortcut not building anything
7101 if (!die_needs_namespace (die
, cu
))
7102 return dwarf2_compute_name (name
, die
, cu
, 1);
7104 if (cu
->lang () != language_rust
)
7105 mangled
= dw2_linkage_name (die
, cu
);
7107 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7109 gdb::unique_xmalloc_ptr
<char> demangled
;
7110 if (mangled
!= NULL
)
7112 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
7114 /* Do nothing (do not demangle the symbol name). */
7118 /* Use DMGL_RET_DROP for C++ template functions to suppress
7119 their return type. It is easier for GDB users to search
7120 for such functions as `name(params)' than `long name(params)'.
7121 In such case the minimal symbol names do not match the full
7122 symbol names but for template functions there is never a need
7123 to look up their definition from their declaration so
7124 the only disadvantage remains the minimal symbol variant
7125 `long name(params)' does not have the proper inferior type. */
7126 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
7130 canon
= demangled
.get ();
7138 if (canon
== NULL
|| check_physname
)
7140 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7142 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7144 /* It may not mean a bug in GDB. The compiler could also
7145 compute DW_AT_linkage_name incorrectly. But in such case
7146 GDB would need to be bug-to-bug compatible. */
7148 complaint (_("Computed physname <%s> does not match demangled <%s> "
7149 "(from linkage <%s>) - DIE at %s [in module %s]"),
7150 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
7151 objfile_name (objfile
));
7153 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7154 is available here - over computed PHYSNAME. It is safer
7155 against both buggy GDB and buggy compilers. */
7169 retval
= objfile
->intern (retval
);
7174 /* Inspect DIE in CU for a namespace alias or a variable with alias
7175 attribute. If one exists, record a new symbol for it.
7177 Returns true if an alias was recorded, false otherwise. */
7180 read_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
7182 struct attribute
*attr
;
7184 /* If the die does not have a name, this is neither a namespace
7185 alias nor a variable alias. */
7186 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7190 struct die_info
*d
= die
;
7191 struct dwarf2_cu
*imported_cu
= cu
;
7193 /* If the compiler has nested DW_AT_imported_declaration DIEs,
7194 keep inspecting DIEs until we hit the underlying import. */
7195 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
7196 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
7198 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
7202 d
= follow_die_ref (d
, attr
, &imported_cu
);
7203 if (d
->tag
!= DW_TAG_imported_declaration
)
7207 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
7209 complaint (_("DIE at %s has too many recursively imported "
7210 "declarations"), sect_offset_str (d
->sect_off
));
7217 if (d
->tag
== DW_TAG_variable
)
7219 /* This declaration is a C/C++ global variable alias.
7220 Add a symbol for it whose type is the same as the
7221 aliased variable's. */
7222 type
= die_type (d
, imported_cu
);
7223 struct symbol
*sym
= new_symbol (die
, type
, cu
);
7224 attr
= dwarf2_attr (d
, DW_AT_location
, imported_cu
);
7225 sym
->set_aclass_index (LOC_UNRESOLVED
);
7226 if (attr
!= nullptr)
7227 var_decode_location (attr
, sym
, cu
);
7232 sect_offset sect_off
= attr
->get_ref_die_offset ();
7233 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
,
7235 if (type
!= nullptr && type
->code () == TYPE_CODE_NAMESPACE
)
7237 /* This declaration is a global namespace alias. Add
7238 a symbol for it whose type is the aliased
7240 new_symbol (die
, type
, cu
);
7249 /* Return the using directives repository (global or local?) to use in the
7250 current context for CU.
7252 For Ada, imported declarations can materialize renamings, which *may* be
7253 global. However it is impossible (for now?) in DWARF to distinguish
7254 "external" imported declarations and "static" ones. As all imported
7255 declarations seem to be static in all other languages, make them all CU-wide
7256 global only in Ada. */
7258 static struct using_direct
**
7259 using_directives (struct dwarf2_cu
*cu
)
7261 if (cu
->lang () == language_ada
7262 && cu
->get_builder ()->outermost_context_p ())
7263 return cu
->get_builder ()->get_global_using_directives ();
7265 return cu
->get_builder ()->get_local_using_directives ();
7268 /* Read the DW_ATTR_decl_line attribute for the given DIE in the
7269 given CU. If the format is not recognized or the attribute is
7270 not present, set it to 0. */
7273 read_decl_line (struct die_info
*die
, struct dwarf2_cu
*cu
)
7275 struct attribute
*decl_line
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7276 if (decl_line
== nullptr)
7278 if (decl_line
->form_is_constant ())
7280 LONGEST val
= decl_line
->constant_value (0);
7281 if (0 <= val
&& val
<= UINT_MAX
)
7282 return (unsigned int) val
;
7284 complaint (_("Declared line for using directive is too large"));
7288 complaint (_("Declared line for using directive is of incorrect format"));
7292 /* Read the import statement specified by the given die and record it. */
7295 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7297 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
7298 struct attribute
*import_attr
;
7299 struct die_info
*imported_die
, *child_die
;
7300 struct dwarf2_cu
*imported_cu
;
7301 const char *imported_name
;
7302 const char *imported_name_prefix
;
7303 const char *canonical_name
;
7304 const char *import_alias
;
7305 const char *imported_declaration
= NULL
;
7306 const char *import_prefix
;
7307 std::vector
<const char *> excludes
;
7309 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7310 if (import_attr
== NULL
)
7312 complaint (_("Tag '%s' has no DW_AT_import"),
7313 dwarf_tag_name (die
->tag
));
7318 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7319 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7320 if (imported_name
== NULL
)
7322 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7324 The import in the following code:
7338 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7339 <52> DW_AT_decl_file : 1
7340 <53> DW_AT_decl_line : 6
7341 <54> DW_AT_import : <0x75>
7342 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7344 <5b> DW_AT_decl_file : 1
7345 <5c> DW_AT_decl_line : 2
7346 <5d> DW_AT_type : <0x6e>
7348 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7349 <76> DW_AT_byte_size : 4
7350 <77> DW_AT_encoding : 5 (signed)
7352 imports the wrong die ( 0x75 instead of 0x58 ).
7353 This case will be ignored until the gcc bug is fixed. */
7357 /* Figure out the local name after import. */
7358 import_alias
= dwarf2_name (die
, cu
);
7360 /* Figure out where the statement is being imported to. */
7361 import_prefix
= determine_prefix (die
, cu
);
7363 /* Figure out what the scope of the imported die is and prepend it
7364 to the name of the imported die. */
7365 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7367 if (imported_die
->tag
!= DW_TAG_namespace
7368 && imported_die
->tag
!= DW_TAG_module
)
7370 imported_declaration
= imported_name
;
7371 canonical_name
= imported_name_prefix
;
7373 else if (strlen (imported_name_prefix
) > 0)
7374 canonical_name
= obconcat (&objfile
->objfile_obstack
,
7375 imported_name_prefix
,
7376 (cu
->lang () == language_d
7379 imported_name
, (char *) NULL
);
7381 canonical_name
= imported_name
;
7383 if (die
->tag
== DW_TAG_imported_module
7384 && cu
->lang () == language_fortran
)
7385 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7386 child_die
= child_die
->sibling
)
7388 /* DWARF-4: A Fortran use statement with a “rename list” may be
7389 represented by an imported module entry with an import attribute
7390 referring to the module and owned entries corresponding to those
7391 entities that are renamed as part of being imported. */
7393 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7395 complaint (_("child DW_TAG_imported_declaration expected "
7396 "- DIE at %s [in module %s]"),
7397 sect_offset_str (child_die
->sect_off
),
7398 objfile_name (objfile
));
7402 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7403 if (import_attr
== NULL
)
7405 complaint (_("Tag '%s' has no DW_AT_import"),
7406 dwarf_tag_name (child_die
->tag
));
7411 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7413 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7414 if (imported_name
== NULL
)
7416 complaint (_("child DW_TAG_imported_declaration has unknown "
7417 "imported name - DIE at %s [in module %s]"),
7418 sect_offset_str (child_die
->sect_off
),
7419 objfile_name (objfile
));
7423 excludes
.push_back (imported_name
);
7425 process_die (child_die
, cu
);
7428 add_using_directive (using_directives (cu
),
7432 imported_declaration
,
7434 read_decl_line (die
, cu
),
7436 &objfile
->objfile_obstack
);
7439 /* ICC<14 does not output the required DW_AT_declaration on incomplete
7440 types, but gives them a size of zero. Starting with version 14,
7441 ICC is compatible with GCC. */
7444 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
7446 if (!cu
->checked_producer
)
7447 check_producer (cu
);
7449 return cu
->producer_is_icc_lt_14
;
7452 /* ICC generates a DW_AT_type for C void functions. This was observed on
7453 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
7454 which says that void functions should not have a DW_AT_type. */
7457 producer_is_icc (struct dwarf2_cu
*cu
)
7459 if (!cu
->checked_producer
)
7460 check_producer (cu
);
7462 return cu
->producer_is_icc
;
7465 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7466 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7467 this, it was first present in GCC release 4.3.0. */
7470 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7472 if (!cu
->checked_producer
)
7473 check_producer (cu
);
7475 return cu
->producer_is_gcc_lt_4_3
;
7478 /* See dwarf2/read.h. */
7480 producer_is_clang (struct dwarf2_cu
*cu
)
7482 if (!cu
->checked_producer
)
7483 check_producer (cu
);
7485 return cu
->producer_is_clang
;
7488 static file_and_directory
&
7489 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
7491 if (cu
->per_cu
->fnd
!= nullptr)
7492 return *cu
->per_cu
->fnd
;
7494 /* Find the filename. Do not use dwarf2_name here, since the filename
7495 is not a source language identifier. */
7496 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
7497 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
7499 if (res
.get_comp_dir () == nullptr
7500 && producer_is_gcc_lt_4_3 (cu
)
7501 && res
.get_name () != nullptr
7502 && IS_ABSOLUTE_PATH (res
.get_name ()))
7504 res
.set_comp_dir (ldirname (res
.get_name ()));
7505 res
.set_name (make_unique_xstrdup (lbasename (res
.get_name ())));
7508 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
7509 return *cu
->per_cu
->fnd
;
7512 /* Handle DW_AT_stmt_list for a compilation unit.
7513 DIE is the DW_TAG_compile_unit die for CU.
7514 COMP_DIR is the compilation directory. LOWPC is passed to
7515 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
7518 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7519 const file_and_directory
&fnd
, CORE_ADDR lowpc
,
7520 bool have_code
) /* ARI: editCase function */
7522 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7523 struct attribute
*attr
;
7524 hashval_t line_header_local_hash
;
7528 gdb_assert (! cu
->per_cu
->is_debug_types
);
7530 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7531 if (attr
== NULL
|| !attr
->form_is_unsigned ())
7534 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
7536 /* The line header hash table is only created if needed (it exists to
7537 prevent redundant reading of the line table for partial_units).
7538 If we're given a partial_unit, we'll need it. If we're given a
7539 compile_unit, then use the line header hash table if it's already
7540 created, but don't create one just yet. */
7542 if (per_objfile
->line_header_hash
== NULL
7543 && die
->tag
== DW_TAG_partial_unit
)
7545 per_objfile
->line_header_hash
7546 .reset (htab_create_alloc (127, line_header_hash_voidp
,
7547 line_header_eq_voidp
,
7548 htab_delete_entry
<line_header
>,
7552 line_header
line_header_local (line_offset
, cu
->per_cu
->is_dwz
);
7553 line_header_local_hash
= line_header_hash (&line_header_local
);
7554 if (per_objfile
->line_header_hash
!= NULL
)
7556 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
7558 line_header_local_hash
, NO_INSERT
);
7560 /* For DW_TAG_compile_unit we need info like symtab::linetable which
7561 is not present in *SLOT (since if there is something in *SLOT then
7562 it will be for a partial_unit). */
7563 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
7565 gdb_assert (*slot
!= NULL
);
7566 cu
->line_header
= (struct line_header
*) *slot
;
7571 /* dwarf_decode_line_header does not yet provide sufficient information.
7572 We always have to call also dwarf_decode_lines for it. */
7573 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
,
7574 fnd
.get_comp_dir ());
7578 cu
->line_header
= lh
.release ();
7579 cu
->line_header_die_owner
= die
;
7581 if (per_objfile
->line_header_hash
== NULL
)
7585 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
7587 line_header_local_hash
, INSERT
);
7588 gdb_assert (slot
!= NULL
);
7590 if (slot
!= NULL
&& *slot
== NULL
)
7592 /* This newly decoded line number information unit will be owned
7593 by line_header_hash hash table. */
7594 *slot
= cu
->line_header
;
7595 cu
->line_header_die_owner
= NULL
;
7599 /* We cannot free any current entry in (*slot) as that struct line_header
7600 may be already used by multiple CUs. Create only temporary decoded
7601 line_header for this CU - it may happen at most once for each line
7602 number information unit. And if we're not using line_header_hash
7603 then this is what we want as well. */
7604 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
7606 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
7607 /* The have_code check is here because, if LOWPC and HIGHPC are both 0x0,
7608 then there won't be any interesting code in the CU, but a check later on
7609 (in lnp_state_machine::check_line_address) will fail to properly exclude
7610 an entry that was removed via --gc-sections. */
7612 dwarf_decode_lines (cu
->line_header
, cu
, lowpc
, decode_mapping
);
7615 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7618 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7620 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7621 struct objfile
*objfile
= per_objfile
->objfile
;
7622 struct gdbarch
*gdbarch
= objfile
->arch ();
7623 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7624 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7625 struct attribute
*attr
;
7626 struct die_info
*child_die
;
7629 prepare_one_comp_unit (cu
, die
, cu
->lang ());
7630 baseaddr
= objfile
->text_section_offset ();
7632 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7634 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7635 from finish_block. */
7636 if (lowpc
== ((CORE_ADDR
) -1))
7638 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
7640 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
7642 cu
->start_compunit_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
),
7645 gdb_assert (per_objfile
->sym_cu
== nullptr);
7646 scoped_restore restore_sym_cu
7647 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
7649 /* Decode line number information if present. We do this before
7650 processing child DIEs, so that the line header table is available
7651 for DW_AT_decl_file. */
7652 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
, lowpc
!= highpc
);
7654 /* Process all dies in compilation unit. */
7655 if (die
->child
!= NULL
)
7657 child_die
= die
->child
;
7658 while (child_die
&& child_die
->tag
)
7660 process_die (child_die
, cu
);
7661 child_die
= child_die
->sibling
;
7664 per_objfile
->sym_cu
= nullptr;
7666 /* Decode macro information, if present. Dwarf 2 macro information
7667 refers to information in the line number info statement program
7668 header, so we can only read it if we've read the header
7670 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
7672 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7673 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
7675 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7676 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
7678 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
7682 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7683 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
7685 unsigned int macro_offset
= attr
->as_unsigned ();
7687 dwarf_decode_macros (cu
, macro_offset
, 0);
7693 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
7695 struct type_unit_group
*tu_group
;
7697 struct attribute
*attr
;
7699 struct signatured_type
*sig_type
;
7701 gdb_assert (per_cu
->is_debug_types
);
7702 sig_type
= (struct signatured_type
*) per_cu
;
7704 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
7706 /* If we're using .gdb_index (includes -readnow) then
7707 per_cu->type_unit_group may not have been set up yet. */
7708 if (sig_type
->type_unit_group
== NULL
)
7709 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
7710 tu_group
= sig_type
->type_unit_group
;
7712 /* If we've already processed this stmt_list there's no real need to
7713 do it again, we could fake it and just recreate the part we need
7714 (file name,index -> symtab mapping). If data shows this optimization
7715 is useful we can do it then. */
7716 type_unit_group_unshareable
*tug_unshare
7717 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
7718 first_time
= tug_unshare
->compunit_symtab
== NULL
;
7720 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7723 if (attr
!= NULL
&& attr
->form_is_unsigned ())
7725 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
7726 lh
= dwarf_decode_line_header (line_offset
, this, nullptr);
7731 start_compunit_symtab ("", NULL
, 0);
7734 gdb_assert (tug_unshare
->symtabs
== NULL
);
7735 gdb_assert (m_builder
== nullptr);
7736 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
7737 m_builder
.reset (new struct buildsym_compunit
7738 (cust
->objfile (), "",
7742 list_in_scope
= get_builder ()->get_file_symbols ();
7747 line_header
= lh
.release ();
7748 line_header_die_owner
= die
;
7752 struct compunit_symtab
*cust
= start_compunit_symtab ("", NULL
, 0);
7754 /* Note: We don't assign tu_group->compunit_symtab yet because we're
7755 still initializing it, and our caller (a few levels up)
7756 process_full_type_unit still needs to know if this is the first
7759 tug_unshare
->symtabs
7760 = XOBNEWVEC (&cust
->objfile ()->objfile_obstack
,
7761 struct symtab
*, line_header
->file_names_size ());
7763 auto &file_names
= line_header
->file_names ();
7764 for (i
= 0; i
< file_names
.size (); ++i
)
7766 file_entry
&fe
= file_names
[i
];
7767 dwarf2_start_subfile (this, fe
, *line_header
);
7768 buildsym_compunit
*b
= get_builder ();
7769 subfile
*sf
= b
->get_current_subfile ();
7771 if (sf
->symtab
== nullptr)
7773 /* NOTE: start_subfile will recognize when it's been
7774 passed a file it has already seen. So we can't
7775 assume there's a simple mapping from
7776 cu->line_header->file_names to subfiles, plus
7777 cu->line_header->file_names may contain dups. */
7778 const char *name
= sf
->name
.c_str ();
7779 const char *name_for_id
= sf
->name_for_id
.c_str ();
7780 sf
->symtab
= allocate_symtab (cust
, name
, name_for_id
);
7783 fe
.symtab
= b
->get_current_subfile ()->symtab
;
7784 tug_unshare
->symtabs
[i
] = fe
.symtab
;
7789 gdb_assert (m_builder
== nullptr);
7790 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
7791 m_builder
.reset (new struct buildsym_compunit
7792 (cust
->objfile (), "",
7796 list_in_scope
= get_builder ()->get_file_symbols ();
7798 auto &file_names
= line_header
->file_names ();
7799 for (i
= 0; i
< file_names
.size (); ++i
)
7801 file_entry
&fe
= file_names
[i
];
7802 fe
.symtab
= tug_unshare
->symtabs
[i
];
7806 /* The main symtab is allocated last. Type units don't have DW_AT_name
7807 so they don't have a "real" (so to speak) symtab anyway.
7808 There is later code that will assign the main symtab to all symbols
7809 that don't have one. We need to handle the case of a symbol with a
7810 missing symtab (DW_AT_decl_file) anyway. */
7813 /* Process DW_TAG_type_unit.
7814 For TUs we want to skip the first top level sibling if it's not the
7815 actual type being defined by this TU. In this case the first top
7816 level sibling is there to provide context only. */
7819 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7821 struct die_info
*child_die
;
7823 prepare_one_comp_unit (cu
, die
, language_minimal
);
7825 /* Initialize (or reinitialize) the machinery for building symtabs.
7826 We do this before processing child DIEs, so that the line header table
7827 is available for DW_AT_decl_file. */
7828 cu
->setup_type_unit_groups (die
);
7830 if (die
->child
!= NULL
)
7832 child_die
= die
->child
;
7833 while (child_die
&& child_die
->tag
)
7835 process_die (child_die
, cu
);
7836 child_die
= child_die
->sibling
;
7843 http://gcc.gnu.org/wiki/DebugFission
7844 http://gcc.gnu.org/wiki/DebugFissionDWP
7846 To simplify handling of both DWO files ("object" files with the DWARF info)
7847 and DWP files (a file with the DWOs packaged up into one file), we treat
7848 DWP files as having a collection of virtual DWO files. */
7851 hash_dwo_file (const void *item
)
7853 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
7856 hash
= htab_hash_string (dwo_file
->dwo_name
);
7857 if (dwo_file
->comp_dir
!= NULL
)
7858 hash
+= htab_hash_string (dwo_file
->comp_dir
);
7863 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
7865 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
7866 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
7868 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
7870 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
7871 return lhs
->comp_dir
== rhs
->comp_dir
;
7872 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
7875 /* Allocate a hash table for DWO files. */
7878 allocate_dwo_file_hash_table ()
7880 return htab_up (htab_create_alloc (41,
7883 htab_delete_entry
<dwo_file
>,
7887 /* Lookup DWO file DWO_NAME. */
7890 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
7891 const char *dwo_name
,
7892 const char *comp_dir
)
7894 struct dwo_file find_entry
;
7897 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
7898 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
7900 find_entry
.dwo_name
= dwo_name
;
7901 find_entry
.comp_dir
= comp_dir
;
7902 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
7909 hash_dwo_unit (const void *item
)
7911 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
7913 /* This drops the top 32 bits of the id, but is ok for a hash. */
7914 return dwo_unit
->signature
;
7918 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
7920 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
7921 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
7923 /* The signature is assumed to be unique within the DWO file.
7924 So while object file CU dwo_id's always have the value zero,
7925 that's OK, assuming each object file DWO file has only one CU,
7926 and that's the rule for now. */
7927 return lhs
->signature
== rhs
->signature
;
7930 /* Allocate a hash table for DWO CUs,TUs.
7931 There is one of these tables for each of CUs,TUs for each DWO file. */
7934 allocate_dwo_unit_table ()
7936 /* Start out with a pretty small number.
7937 Generally DWO files contain only one CU and maybe some TUs. */
7938 return htab_up (htab_create_alloc (3,
7941 NULL
, xcalloc
, xfree
));
7944 /* die_reader_func for create_dwo_cu. */
7947 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
7948 const gdb_byte
*info_ptr
,
7949 struct die_info
*comp_unit_die
,
7950 struct dwo_file
*dwo_file
,
7951 struct dwo_unit
*dwo_unit
)
7953 struct dwarf2_cu
*cu
= reader
->cu
;
7954 sect_offset sect_off
= cu
->per_cu
->sect_off
;
7955 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
7957 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7958 if (!signature
.has_value ())
7960 complaint (_("Dwarf Error: debug entry at offset %s is missing"
7961 " its dwo_id [in module %s]"),
7962 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
7966 dwo_unit
->dwo_file
= dwo_file
;
7967 dwo_unit
->signature
= *signature
;
7968 dwo_unit
->section
= section
;
7969 dwo_unit
->sect_off
= sect_off
;
7970 dwo_unit
->length
= cu
->per_cu
->length ();
7972 dwarf_read_debug_printf (" offset %s, dwo_id %s",
7973 sect_offset_str (sect_off
),
7974 hex_string (dwo_unit
->signature
));
7977 /* Create the dwo_units for the CUs in a DWO_FILE.
7978 Note: This function processes DWO files only, not DWP files. */
7981 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
7982 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
7983 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
7985 struct objfile
*objfile
= per_objfile
->objfile
;
7986 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7987 const gdb_byte
*info_ptr
, *end_ptr
;
7989 section
.read (objfile
);
7990 info_ptr
= section
.buffer
;
7992 if (info_ptr
== NULL
)
7995 dwarf_read_debug_printf ("Reading %s for %s:",
7996 section
.get_name (),
7997 section
.get_file_name ());
7999 end_ptr
= info_ptr
+ section
.size
;
8000 while (info_ptr
< end_ptr
)
8002 struct dwarf2_per_cu_data per_cu
;
8003 struct dwo_unit read_unit
{};
8004 struct dwo_unit
*dwo_unit
;
8006 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
8008 per_cu
.per_bfd
= per_bfd
;
8009 per_cu
.is_debug_types
= 0;
8010 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
8011 per_cu
.section
= §ion
;
8013 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
8014 if (!reader
.dummy_p
)
8015 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
8016 &dwo_file
, &read_unit
);
8017 info_ptr
+= per_cu
.length ();
8019 // If the unit could not be parsed, skip it.
8020 if (read_unit
.dwo_file
== NULL
)
8023 if (cus_htab
== NULL
)
8024 cus_htab
= allocate_dwo_unit_table ();
8026 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
8028 *dwo_unit
= read_unit
;
8029 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
8030 gdb_assert (slot
!= NULL
);
8033 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
8034 sect_offset dup_sect_off
= dup_cu
->sect_off
;
8036 complaint (_("debug cu entry at offset %s is duplicate to"
8037 " the entry at offset %s, signature %s"),
8038 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
8039 hex_string (dwo_unit
->signature
));
8041 *slot
= (void *)dwo_unit
;
8045 /* DWP file .debug_{cu,tu}_index section format:
8046 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8047 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
8049 DWP Versions 1 & 2 are older, pre-standard format versions. The first
8050 officially standard DWP format was published with DWARF v5 and is called
8051 Version 5. There are no versions 3 or 4.
8055 Both index sections have the same format, and serve to map a 64-bit
8056 signature to a set of section numbers. Each section begins with a header,
8057 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8058 indexes, and a pool of 32-bit section numbers. The index sections will be
8059 aligned at 8-byte boundaries in the file.
8061 The index section header consists of:
8063 V, 32 bit version number
8065 N, 32 bit number of compilation units or type units in the index
8066 M, 32 bit number of slots in the hash table
8068 Numbers are recorded using the byte order of the application binary.
8070 The hash table begins at offset 16 in the section, and consists of an array
8071 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8072 order of the application binary). Unused slots in the hash table are 0.
8073 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8075 The parallel table begins immediately after the hash table
8076 (at offset 16 + 8 * M from the beginning of the section), and consists of an
8077 array of 32-bit indexes (using the byte order of the application binary),
8078 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8079 table contains a 32-bit index into the pool of section numbers. For unused
8080 hash table slots, the corresponding entry in the parallel table will be 0.
8082 The pool of section numbers begins immediately following the hash table
8083 (at offset 16 + 12 * M from the beginning of the section). The pool of
8084 section numbers consists of an array of 32-bit words (using the byte order
8085 of the application binary). Each item in the array is indexed starting
8086 from 0. The hash table entry provides the index of the first section
8087 number in the set. Additional section numbers in the set follow, and the
8088 set is terminated by a 0 entry (section number 0 is not used in ELF).
8090 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8091 section must be the first entry in the set, and the .debug_abbrev.dwo must
8092 be the second entry. Other members of the set may follow in any order.
8096 DWP Versions 2 and 5:
8098 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
8099 and the entries in the index tables are now offsets into these sections.
8100 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
8103 Index Section Contents:
8105 Hash Table of Signatures dwp_hash_table.hash_table
8106 Parallel Table of Indices dwp_hash_table.unit_table
8107 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
8108 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
8110 The index section header consists of:
8112 V, 32 bit version number
8113 L, 32 bit number of columns in the table of section offsets
8114 N, 32 bit number of compilation units or type units in the index
8115 M, 32 bit number of slots in the hash table
8117 Numbers are recorded using the byte order of the application binary.
8119 The hash table has the same format as version 1.
8120 The parallel table of indices has the same format as version 1,
8121 except that the entries are origin-1 indices into the table of sections
8122 offsets and the table of section sizes.
8124 The table of offsets begins immediately following the parallel table
8125 (at offset 16 + 12 * M from the beginning of the section). The table is
8126 a two-dimensional array of 32-bit words (using the byte order of the
8127 application binary), with L columns and N+1 rows, in row-major order.
8128 Each row in the array is indexed starting from 0. The first row provides
8129 a key to the remaining rows: each column in this row provides an identifier
8130 for a debug section, and the offsets in the same column of subsequent rows
8131 refer to that section. The section identifiers for Version 2 are:
8133 DW_SECT_INFO 1 .debug_info.dwo
8134 DW_SECT_TYPES 2 .debug_types.dwo
8135 DW_SECT_ABBREV 3 .debug_abbrev.dwo
8136 DW_SECT_LINE 4 .debug_line.dwo
8137 DW_SECT_LOC 5 .debug_loc.dwo
8138 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
8139 DW_SECT_MACINFO 7 .debug_macinfo.dwo
8140 DW_SECT_MACRO 8 .debug_macro.dwo
8142 The section identifiers for Version 5 are:
8144 DW_SECT_INFO_V5 1 .debug_info.dwo
8145 DW_SECT_RESERVED_V5 2 --
8146 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
8147 DW_SECT_LINE_V5 4 .debug_line.dwo
8148 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
8149 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
8150 DW_SECT_MACRO_V5 7 .debug_macro.dwo
8151 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
8153 The offsets provided by the CU and TU index sections are the base offsets
8154 for the contributions made by each CU or TU to the corresponding section
8155 in the package file. Each CU and TU header contains an abbrev_offset
8156 field, used to find the abbreviations table for that CU or TU within the
8157 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
8158 be interpreted as relative to the base offset given in the index section.
8159 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
8160 should be interpreted as relative to the base offset for .debug_line.dwo,
8161 and offsets into other debug sections obtained from DWARF attributes should
8162 also be interpreted as relative to the corresponding base offset.
8164 The table of sizes begins immediately following the table of offsets.
8165 Like the table of offsets, it is a two-dimensional array of 32-bit words,
8166 with L columns and N rows, in row-major order. Each row in the array is
8167 indexed starting from 1 (row 0 is shared by the two tables).
8171 Hash table lookup is handled the same in version 1 and 2:
8173 We assume that N and M will not exceed 2^32 - 1.
8174 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8176 Given a 64-bit compilation unit signature or a type signature S, an entry
8177 in the hash table is located as follows:
8179 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8180 the low-order k bits all set to 1.
8182 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8184 3) If the hash table entry at index H matches the signature, use that
8185 entry. If the hash table entry at index H is unused (all zeroes),
8186 terminate the search: the signature is not present in the table.
8188 4) Let H = (H + H') modulo M. Repeat at Step 3.
8190 Because M > N and H' and M are relatively prime, the search is guaranteed
8191 to stop at an unused slot or find the match. */
8193 /* Create a hash table to map DWO IDs to their CU/TU entry in
8194 .debug_{info,types}.dwo in DWP_FILE.
8195 Returns NULL if there isn't one.
8196 Note: This function processes DWP files only, not DWO files. */
8198 static struct dwp_hash_table
*
8199 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
8200 struct dwp_file
*dwp_file
, int is_debug_types
)
8202 struct objfile
*objfile
= per_objfile
->objfile
;
8203 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8204 const gdb_byte
*index_ptr
, *index_end
;
8205 struct dwarf2_section_info
*index
;
8206 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
8207 struct dwp_hash_table
*htab
;
8210 index
= &dwp_file
->sections
.tu_index
;
8212 index
= &dwp_file
->sections
.cu_index
;
8214 if (index
->empty ())
8216 index
->read (objfile
);
8218 index_ptr
= index
->buffer
;
8219 index_end
= index_ptr
+ index
->size
;
8221 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
8222 For now it's safe to just read 4 bytes (particularly as it's difficult to
8223 tell if you're dealing with Version 5 before you've read the version). */
8224 version
= read_4_bytes (dbfd
, index_ptr
);
8226 if (version
== 2 || version
== 5)
8227 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
8231 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8233 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8236 if (version
!= 1 && version
!= 2 && version
!= 5)
8238 error (_("Dwarf Error: unsupported DWP file version (%s)"
8240 pulongest (version
), dwp_file
->name
);
8242 if (nr_slots
!= (nr_slots
& -nr_slots
))
8244 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
8245 " is not power of 2 [in module %s]"),
8246 pulongest (nr_slots
), dwp_file
->name
);
8249 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
8250 htab
->version
= version
;
8251 htab
->nr_columns
= nr_columns
;
8252 htab
->nr_units
= nr_units
;
8253 htab
->nr_slots
= nr_slots
;
8254 htab
->hash_table
= index_ptr
;
8255 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8257 /* Exit early if the table is empty. */
8258 if (nr_slots
== 0 || nr_units
== 0
8259 || (version
== 2 && nr_columns
== 0)
8260 || (version
== 5 && nr_columns
== 0))
8262 /* All must be zero. */
8263 if (nr_slots
!= 0 || nr_units
!= 0
8264 || (version
== 2 && nr_columns
!= 0)
8265 || (version
== 5 && nr_columns
!= 0))
8267 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
8268 " all zero [in modules %s]"),
8276 htab
->section_pool
.v1
.indices
=
8277 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8278 /* It's harder to decide whether the section is too small in v1.
8279 V1 is deprecated anyway so we punt. */
8281 else if (version
== 2)
8283 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8284 int *ids
= htab
->section_pool
.v2
.section_ids
;
8285 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
8286 /* Reverse map for error checking. */
8287 int ids_seen
[DW_SECT_MAX
+ 1];
8292 error (_("Dwarf Error: bad DWP hash table, too few columns"
8293 " in section table [in module %s]"),
8296 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
8298 error (_("Dwarf Error: bad DWP hash table, too many columns"
8299 " in section table [in module %s]"),
8302 memset (ids
, 255, sizeof_ids
);
8303 memset (ids_seen
, 255, sizeof (ids_seen
));
8304 for (i
= 0; i
< nr_columns
; ++i
)
8306 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
8308 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
8310 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
8311 " in section table [in module %s]"),
8312 id
, dwp_file
->name
);
8314 if (ids_seen
[id
] != -1)
8316 error (_("Dwarf Error: bad DWP hash table, duplicate section"
8317 " id %d in section table [in module %s]"),
8318 id
, dwp_file
->name
);
8323 /* Must have exactly one info or types section. */
8324 if (((ids_seen
[DW_SECT_INFO
] != -1)
8325 + (ids_seen
[DW_SECT_TYPES
] != -1))
8328 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
8329 " DWO info/types section [in module %s]"),
8332 /* Must have an abbrev section. */
8333 if (ids_seen
[DW_SECT_ABBREV
] == -1)
8335 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
8336 " section [in module %s]"),
8339 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
8340 htab
->section_pool
.v2
.sizes
=
8341 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
8342 * nr_units
* nr_columns
);
8343 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
8344 * nr_units
* nr_columns
))
8347 error (_("Dwarf Error: DWP index section is corrupt (too small)"
8352 else /* version == 5 */
8354 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8355 int *ids
= htab
->section_pool
.v5
.section_ids
;
8356 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
8357 /* Reverse map for error checking. */
8358 int ids_seen
[DW_SECT_MAX_V5
+ 1];
8362 error (_("Dwarf Error: bad DWP hash table, too few columns"
8363 " in section table [in module %s]"),
8366 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
8368 error (_("Dwarf Error: bad DWP hash table, too many columns"
8369 " in section table [in module %s]"),
8372 memset (ids
, 255, sizeof_ids
);
8373 memset (ids_seen
, 255, sizeof (ids_seen
));
8374 for (int i
= 0; i
< nr_columns
; ++i
)
8376 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
8378 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
8380 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
8381 " in section table [in module %s]"),
8382 id
, dwp_file
->name
);
8384 if (ids_seen
[id
] != -1)
8386 error (_("Dwarf Error: bad DWP hash table, duplicate section"
8387 " id %d in section table [in module %s]"),
8388 id
, dwp_file
->name
);
8393 /* Must have seen an info section. */
8394 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
8396 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
8397 " DWO info/types section [in module %s]"),
8400 /* Must have an abbrev section. */
8401 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
8403 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
8404 " section [in module %s]"),
8407 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
8408 htab
->section_pool
.v5
.sizes
8409 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
8410 * nr_units
* nr_columns
);
8411 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
8412 * nr_units
* nr_columns
))
8415 error (_("Dwarf Error: DWP index section is corrupt (too small)"
8424 /* Update SECTIONS with the data from SECTP.
8426 This function is like the other "locate" section routines, but in
8427 this context the sections to read comes from the DWP V1 hash table,
8428 not the full ELF section table.
8430 The result is non-zero for success, or zero if an error was found. */
8433 locate_v1_virtual_dwo_sections (asection
*sectp
,
8434 struct virtual_v1_dwo_sections
*sections
)
8436 const struct dwop_section_names
*names
= &dwop_section_names
;
8438 if (names
->abbrev_dwo
.matches (sectp
->name
))
8440 /* There can be only one. */
8441 if (sections
->abbrev
.s
.section
!= NULL
)
8443 sections
->abbrev
.s
.section
= sectp
;
8444 sections
->abbrev
.size
= bfd_section_size (sectp
);
8446 else if (names
->info_dwo
.matches (sectp
->name
)
8447 || names
->types_dwo
.matches (sectp
->name
))
8449 /* There can be only one. */
8450 if (sections
->info_or_types
.s
.section
!= NULL
)
8452 sections
->info_or_types
.s
.section
= sectp
;
8453 sections
->info_or_types
.size
= bfd_section_size (sectp
);
8455 else if (names
->line_dwo
.matches (sectp
->name
))
8457 /* There can be only one. */
8458 if (sections
->line
.s
.section
!= NULL
)
8460 sections
->line
.s
.section
= sectp
;
8461 sections
->line
.size
= bfd_section_size (sectp
);
8463 else if (names
->loc_dwo
.matches (sectp
->name
))
8465 /* There can be only one. */
8466 if (sections
->loc
.s
.section
!= NULL
)
8468 sections
->loc
.s
.section
= sectp
;
8469 sections
->loc
.size
= bfd_section_size (sectp
);
8471 else if (names
->macinfo_dwo
.matches (sectp
->name
))
8473 /* There can be only one. */
8474 if (sections
->macinfo
.s
.section
!= NULL
)
8476 sections
->macinfo
.s
.section
= sectp
;
8477 sections
->macinfo
.size
= bfd_section_size (sectp
);
8479 else if (names
->macro_dwo
.matches (sectp
->name
))
8481 /* There can be only one. */
8482 if (sections
->macro
.s
.section
!= NULL
)
8484 sections
->macro
.s
.section
= sectp
;
8485 sections
->macro
.size
= bfd_section_size (sectp
);
8487 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
8489 /* There can be only one. */
8490 if (sections
->str_offsets
.s
.section
!= NULL
)
8492 sections
->str_offsets
.s
.section
= sectp
;
8493 sections
->str_offsets
.size
= bfd_section_size (sectp
);
8497 /* No other kind of section is valid. */
8504 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8505 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8506 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8507 This is for DWP version 1 files. */
8509 static struct dwo_unit
*
8510 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
8511 struct dwp_file
*dwp_file
,
8512 uint32_t unit_index
,
8513 const char *comp_dir
,
8514 ULONGEST signature
, int is_debug_types
)
8516 const struct dwp_hash_table
*dwp_htab
=
8517 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
8518 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8519 const char *kind
= is_debug_types
? "TU" : "CU";
8520 struct dwo_file
*dwo_file
;
8521 struct dwo_unit
*dwo_unit
;
8522 struct virtual_v1_dwo_sections sections
;
8523 void **dwo_file_slot
;
8526 gdb_assert (dwp_file
->version
== 1);
8528 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
8529 kind
, pulongest (unit_index
), hex_string (signature
),
8532 /* Fetch the sections of this DWO unit.
8533 Put a limit on the number of sections we look for so that bad data
8534 doesn't cause us to loop forever. */
8536 #define MAX_NR_V1_DWO_SECTIONS \
8537 (1 /* .debug_info or .debug_types */ \
8538 + 1 /* .debug_abbrev */ \
8539 + 1 /* .debug_line */ \
8540 + 1 /* .debug_loc */ \
8541 + 1 /* .debug_str_offsets */ \
8542 + 1 /* .debug_macro or .debug_macinfo */ \
8543 + 1 /* trailing zero */)
8545 memset (§ions
, 0, sizeof (sections
));
8547 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
8550 uint32_t section_nr
=
8552 dwp_htab
->section_pool
.v1
.indices
8553 + (unit_index
+ i
) * sizeof (uint32_t));
8555 if (section_nr
== 0)
8557 if (section_nr
>= dwp_file
->num_sections
)
8559 error (_("Dwarf Error: bad DWP hash table, section number too large"
8564 sectp
= dwp_file
->elf_sections
[section_nr
];
8565 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
8567 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8574 || sections
.info_or_types
.empty ()
8575 || sections
.abbrev
.empty ())
8577 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8581 if (i
== MAX_NR_V1_DWO_SECTIONS
)
8583 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8588 /* It's easier for the rest of the code if we fake a struct dwo_file and
8589 have dwo_unit "live" in that. At least for now.
8591 The DWP file can be made up of a random collection of CUs and TUs.
8592 However, for each CU + set of TUs that came from the same original DWO
8593 file, we can combine them back into a virtual DWO file to save space
8594 (fewer struct dwo_file objects to allocate). Remember that for really
8595 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8597 std::string virtual_dwo_name
=
8598 string_printf ("virtual-dwo/%d-%d-%d-%d",
8599 sections
.abbrev
.get_id (),
8600 sections
.line
.get_id (),
8601 sections
.loc
.get_id (),
8602 sections
.str_offsets
.get_id ());
8603 /* Can we use an existing virtual DWO file? */
8604 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
8606 /* Create one if necessary. */
8607 if (*dwo_file_slot
== NULL
)
8609 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8610 virtual_dwo_name
.c_str ());
8612 dwo_file
= new struct dwo_file
;
8613 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
8614 dwo_file
->comp_dir
= comp_dir
;
8615 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8616 dwo_file
->sections
.line
= sections
.line
;
8617 dwo_file
->sections
.loc
= sections
.loc
;
8618 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8619 dwo_file
->sections
.macro
= sections
.macro
;
8620 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8621 /* The "str" section is global to the entire DWP file. */
8622 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8623 /* The info or types section is assigned below to dwo_unit,
8624 there's no need to record it in dwo_file.
8625 Also, we can't simply record type sections in dwo_file because
8626 we record a pointer into the vector in dwo_unit. As we collect more
8627 types we'll grow the vector and eventually have to reallocate space
8628 for it, invalidating all copies of pointers into the previous
8630 *dwo_file_slot
= dwo_file
;
8634 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
8635 virtual_dwo_name
.c_str ());
8637 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
8640 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
8641 dwo_unit
->dwo_file
= dwo_file
;
8642 dwo_unit
->signature
= signature
;
8644 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
8645 *dwo_unit
->section
= sections
.info_or_types
;
8646 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
8651 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
8652 simplify them. Given a pointer to the containing section SECTION, and
8653 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
8654 virtual section of just that piece. */
8656 static struct dwarf2_section_info
8657 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
8658 struct dwarf2_section_info
*section
,
8659 bfd_size_type offset
, bfd_size_type size
)
8661 struct dwarf2_section_info result
;
8664 gdb_assert (section
!= NULL
);
8665 gdb_assert (!section
->is_virtual
);
8667 memset (&result
, 0, sizeof (result
));
8668 result
.s
.containing_section
= section
;
8669 result
.is_virtual
= true;
8674 sectp
= section
->get_bfd_section ();
8676 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
8677 bounds of the real section. This is a pretty-rare event, so just
8678 flag an error (easier) instead of a warning and trying to cope. */
8680 || offset
+ size
> bfd_section_size (sectp
))
8682 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
8683 " in section %s [in module %s]"),
8684 sectp
? bfd_section_name (sectp
) : "<unknown>",
8685 objfile_name (per_objfile
->objfile
));
8688 result
.virtual_offset
= offset
;
8693 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8694 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8695 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8696 This is for DWP version 2 files. */
8698 static struct dwo_unit
*
8699 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
8700 struct dwp_file
*dwp_file
,
8701 uint32_t unit_index
,
8702 const char *comp_dir
,
8703 ULONGEST signature
, int is_debug_types
)
8705 const struct dwp_hash_table
*dwp_htab
=
8706 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
8707 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8708 const char *kind
= is_debug_types
? "TU" : "CU";
8709 struct dwo_file
*dwo_file
;
8710 struct dwo_unit
*dwo_unit
;
8711 struct virtual_v2_or_v5_dwo_sections sections
;
8712 void **dwo_file_slot
;
8715 gdb_assert (dwp_file
->version
== 2);
8717 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
8718 kind
, pulongest (unit_index
), hex_string (signature
),
8721 /* Fetch the section offsets of this DWO unit. */
8723 memset (§ions
, 0, sizeof (sections
));
8725 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
8727 uint32_t offset
= read_4_bytes (dbfd
,
8728 dwp_htab
->section_pool
.v2
.offsets
8729 + (((unit_index
- 1) * dwp_htab
->nr_columns
8731 * sizeof (uint32_t)));
8732 uint32_t size
= read_4_bytes (dbfd
,
8733 dwp_htab
->section_pool
.v2
.sizes
8734 + (((unit_index
- 1) * dwp_htab
->nr_columns
8736 * sizeof (uint32_t)));
8738 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
8742 sections
.info_or_types_offset
= offset
;
8743 sections
.info_or_types_size
= size
;
8745 case DW_SECT_ABBREV
:
8746 sections
.abbrev_offset
= offset
;
8747 sections
.abbrev_size
= size
;
8750 sections
.line_offset
= offset
;
8751 sections
.line_size
= size
;
8754 sections
.loc_offset
= offset
;
8755 sections
.loc_size
= size
;
8757 case DW_SECT_STR_OFFSETS
:
8758 sections
.str_offsets_offset
= offset
;
8759 sections
.str_offsets_size
= size
;
8761 case DW_SECT_MACINFO
:
8762 sections
.macinfo_offset
= offset
;
8763 sections
.macinfo_size
= size
;
8766 sections
.macro_offset
= offset
;
8767 sections
.macro_size
= size
;
8772 /* It's easier for the rest of the code if we fake a struct dwo_file and
8773 have dwo_unit "live" in that. At least for now.
8775 The DWP file can be made up of a random collection of CUs and TUs.
8776 However, for each CU + set of TUs that came from the same original DWO
8777 file, we can combine them back into a virtual DWO file to save space
8778 (fewer struct dwo_file objects to allocate). Remember that for really
8779 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8781 std::string virtual_dwo_name
=
8782 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
8783 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
8784 (long) (sections
.line_size
? sections
.line_offset
: 0),
8785 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
8786 (long) (sections
.str_offsets_size
8787 ? sections
.str_offsets_offset
: 0));
8788 /* Can we use an existing virtual DWO file? */
8789 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
8791 /* Create one if necessary. */
8792 if (*dwo_file_slot
== NULL
)
8794 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8795 virtual_dwo_name
.c_str ());
8797 dwo_file
= new struct dwo_file
;
8798 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
8799 dwo_file
->comp_dir
= comp_dir
;
8800 dwo_file
->sections
.abbrev
=
8801 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
8802 sections
.abbrev_offset
,
8803 sections
.abbrev_size
);
8804 dwo_file
->sections
.line
=
8805 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
8806 sections
.line_offset
,
8807 sections
.line_size
);
8808 dwo_file
->sections
.loc
=
8809 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
8810 sections
.loc_offset
, sections
.loc_size
);
8811 dwo_file
->sections
.macinfo
=
8812 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
8813 sections
.macinfo_offset
,
8814 sections
.macinfo_size
);
8815 dwo_file
->sections
.macro
=
8816 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
8817 sections
.macro_offset
,
8818 sections
.macro_size
);
8819 dwo_file
->sections
.str_offsets
=
8820 create_dwp_v2_or_v5_section (per_objfile
,
8821 &dwp_file
->sections
.str_offsets
,
8822 sections
.str_offsets_offset
,
8823 sections
.str_offsets_size
);
8824 /* The "str" section is global to the entire DWP file. */
8825 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8826 /* The info or types section is assigned below to dwo_unit,
8827 there's no need to record it in dwo_file.
8828 Also, we can't simply record type sections in dwo_file because
8829 we record a pointer into the vector in dwo_unit. As we collect more
8830 types we'll grow the vector and eventually have to reallocate space
8831 for it, invalidating all copies of pointers into the previous
8833 *dwo_file_slot
= dwo_file
;
8837 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
8838 virtual_dwo_name
.c_str ());
8840 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
8843 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
8844 dwo_unit
->dwo_file
= dwo_file
;
8845 dwo_unit
->signature
= signature
;
8847 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
8848 *dwo_unit
->section
= create_dwp_v2_or_v5_section
8851 ? &dwp_file
->sections
.types
8852 : &dwp_file
->sections
.info
,
8853 sections
.info_or_types_offset
,
8854 sections
.info_or_types_size
);
8855 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
8860 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8861 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8862 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8863 This is for DWP version 5 files. */
8865 static struct dwo_unit
*
8866 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
8867 struct dwp_file
*dwp_file
,
8868 uint32_t unit_index
,
8869 const char *comp_dir
,
8870 ULONGEST signature
, int is_debug_types
)
8872 const struct dwp_hash_table
*dwp_htab
8873 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
8874 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8875 const char *kind
= is_debug_types
? "TU" : "CU";
8876 struct dwo_file
*dwo_file
;
8877 struct dwo_unit
*dwo_unit
;
8878 struct virtual_v2_or_v5_dwo_sections sections
{};
8879 void **dwo_file_slot
;
8881 gdb_assert (dwp_file
->version
== 5);
8883 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
8884 kind
, pulongest (unit_index
), hex_string (signature
),
8887 /* Fetch the section offsets of this DWO unit. */
8889 /* memset (§ions, 0, sizeof (sections)); */
8891 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
8893 uint32_t offset
= read_4_bytes (dbfd
,
8894 dwp_htab
->section_pool
.v5
.offsets
8895 + (((unit_index
- 1)
8896 * dwp_htab
->nr_columns
8898 * sizeof (uint32_t)));
8899 uint32_t size
= read_4_bytes (dbfd
,
8900 dwp_htab
->section_pool
.v5
.sizes
8901 + (((unit_index
- 1) * dwp_htab
->nr_columns
8903 * sizeof (uint32_t)));
8905 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
8907 case DW_SECT_ABBREV_V5
:
8908 sections
.abbrev_offset
= offset
;
8909 sections
.abbrev_size
= size
;
8911 case DW_SECT_INFO_V5
:
8912 sections
.info_or_types_offset
= offset
;
8913 sections
.info_or_types_size
= size
;
8915 case DW_SECT_LINE_V5
:
8916 sections
.line_offset
= offset
;
8917 sections
.line_size
= size
;
8919 case DW_SECT_LOCLISTS_V5
:
8920 sections
.loclists_offset
= offset
;
8921 sections
.loclists_size
= size
;
8923 case DW_SECT_MACRO_V5
:
8924 sections
.macro_offset
= offset
;
8925 sections
.macro_size
= size
;
8927 case DW_SECT_RNGLISTS_V5
:
8928 sections
.rnglists_offset
= offset
;
8929 sections
.rnglists_size
= size
;
8931 case DW_SECT_STR_OFFSETS_V5
:
8932 sections
.str_offsets_offset
= offset
;
8933 sections
.str_offsets_size
= size
;
8935 case DW_SECT_RESERVED_V5
:
8941 /* It's easier for the rest of the code if we fake a struct dwo_file and
8942 have dwo_unit "live" in that. At least for now.
8944 The DWP file can be made up of a random collection of CUs and TUs.
8945 However, for each CU + set of TUs that came from the same original DWO
8946 file, we can combine them back into a virtual DWO file to save space
8947 (fewer struct dwo_file objects to allocate). Remember that for really
8948 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8950 std::string virtual_dwo_name
=
8951 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
8952 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
8953 (long) (sections
.line_size
? sections
.line_offset
: 0),
8954 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
8955 (long) (sections
.str_offsets_size
8956 ? sections
.str_offsets_offset
: 0),
8957 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
8958 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
8959 /* Can we use an existing virtual DWO file? */
8960 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
8961 virtual_dwo_name
.c_str (),
8963 /* Create one if necessary. */
8964 if (*dwo_file_slot
== NULL
)
8966 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8967 virtual_dwo_name
.c_str ());
8969 dwo_file
= new struct dwo_file
;
8970 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
8971 dwo_file
->comp_dir
= comp_dir
;
8972 dwo_file
->sections
.abbrev
=
8973 create_dwp_v2_or_v5_section (per_objfile
,
8974 &dwp_file
->sections
.abbrev
,
8975 sections
.abbrev_offset
,
8976 sections
.abbrev_size
);
8977 dwo_file
->sections
.line
=
8978 create_dwp_v2_or_v5_section (per_objfile
,
8979 &dwp_file
->sections
.line
,
8980 sections
.line_offset
, sections
.line_size
);
8981 dwo_file
->sections
.macro
=
8982 create_dwp_v2_or_v5_section (per_objfile
,
8983 &dwp_file
->sections
.macro
,
8984 sections
.macro_offset
,
8985 sections
.macro_size
);
8986 dwo_file
->sections
.loclists
=
8987 create_dwp_v2_or_v5_section (per_objfile
,
8988 &dwp_file
->sections
.loclists
,
8989 sections
.loclists_offset
,
8990 sections
.loclists_size
);
8991 dwo_file
->sections
.rnglists
=
8992 create_dwp_v2_or_v5_section (per_objfile
,
8993 &dwp_file
->sections
.rnglists
,
8994 sections
.rnglists_offset
,
8995 sections
.rnglists_size
);
8996 dwo_file
->sections
.str_offsets
=
8997 create_dwp_v2_or_v5_section (per_objfile
,
8998 &dwp_file
->sections
.str_offsets
,
8999 sections
.str_offsets_offset
,
9000 sections
.str_offsets_size
);
9001 /* The "str" section is global to the entire DWP file. */
9002 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
9003 /* The info or types section is assigned below to dwo_unit,
9004 there's no need to record it in dwo_file.
9005 Also, we can't simply record type sections in dwo_file because
9006 we record a pointer into the vector in dwo_unit. As we collect more
9007 types we'll grow the vector and eventually have to reallocate space
9008 for it, invalidating all copies of pointers into the previous
9010 *dwo_file_slot
= dwo_file
;
9014 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
9015 virtual_dwo_name
.c_str ());
9017 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
9020 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
9021 dwo_unit
->dwo_file
= dwo_file
;
9022 dwo_unit
->signature
= signature
;
9024 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
9025 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
9026 &dwp_file
->sections
.info
,
9027 sections
.info_or_types_offset
,
9028 sections
.info_or_types_size
);
9029 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
9034 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
9035 Returns NULL if the signature isn't found. */
9037 static struct dwo_unit
*
9038 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
9039 struct dwp_file
*dwp_file
, const char *comp_dir
,
9040 ULONGEST signature
, int is_debug_types
)
9042 const struct dwp_hash_table
*dwp_htab
=
9043 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9044 bfd
*dbfd
= dwp_file
->dbfd
.get ();
9045 uint32_t mask
= dwp_htab
->nr_slots
- 1;
9046 uint32_t hash
= signature
& mask
;
9047 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
9050 struct dwo_unit find_dwo_cu
;
9052 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
9053 find_dwo_cu
.signature
= signature
;
9054 slot
= htab_find_slot (is_debug_types
9055 ? dwp_file
->loaded_tus
.get ()
9056 : dwp_file
->loaded_cus
.get (),
9057 &find_dwo_cu
, INSERT
);
9060 return (struct dwo_unit
*) *slot
;
9062 /* Use a for loop so that we don't loop forever on bad debug info. */
9063 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
9065 ULONGEST signature_in_table
;
9067 signature_in_table
=
9068 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
9069 if (signature_in_table
== signature
)
9071 uint32_t unit_index
=
9073 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
9075 if (dwp_file
->version
== 1)
9077 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
9078 unit_index
, comp_dir
,
9079 signature
, is_debug_types
);
9081 else if (dwp_file
->version
== 2)
9083 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
9084 unit_index
, comp_dir
,
9085 signature
, is_debug_types
);
9087 else /* version == 5 */
9089 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
9090 unit_index
, comp_dir
,
9091 signature
, is_debug_types
);
9093 return (struct dwo_unit
*) *slot
;
9095 if (signature_in_table
== 0)
9097 hash
= (hash
+ hash2
) & mask
;
9100 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
9105 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
9106 Open the file specified by FILE_NAME and hand it off to BFD for
9107 preliminary analysis. Return a newly initialized bfd *, which
9108 includes a canonicalized copy of FILE_NAME.
9109 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
9110 SEARCH_CWD is true if the current directory is to be searched.
9111 It will be searched before debug-file-directory.
9112 If successful, the file is added to the bfd include table of the
9113 objfile's bfd (see gdb_bfd_record_inclusion).
9114 If unable to find/open the file, return NULL.
9115 NOTE: This function is derived from symfile_bfd_open. */
9117 static gdb_bfd_ref_ptr
9118 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
9119 const char *file_name
, int is_dwp
, int search_cwd
)
9122 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
9123 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
9124 to debug_file_directory. */
9125 const char *search_path
;
9126 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
9128 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
9131 if (!debug_file_directory
.empty ())
9133 search_path_holder
.reset (concat (".", dirname_separator_string
,
9134 debug_file_directory
.c_str (),
9136 search_path
= search_path_holder
.get ();
9142 search_path
= debug_file_directory
.c_str ();
9144 /* Add the path for the executable binary to the list of search paths. */
9145 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
9146 search_path_holder
.reset (concat (objfile_dir
.c_str (),
9147 dirname_separator_string
,
9148 search_path
, nullptr));
9149 search_path
= search_path_holder
.get ();
9151 openp_flags flags
= OPF_RETURN_REALPATH
;
9153 flags
|= OPF_SEARCH_IN_PATH
;
9155 gdb::unique_xmalloc_ptr
<char> absolute_name
;
9156 desc
= openp (search_path
, flags
, file_name
,
9157 O_RDONLY
| O_BINARY
, &absolute_name
);
9161 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
9163 if (sym_bfd
== NULL
)
9165 bfd_set_cacheable (sym_bfd
.get (), 1);
9167 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
9170 /* Success. Record the bfd as having been included by the objfile's bfd.
9171 This is important because things like demangled_names_hash lives in the
9172 objfile's per_bfd space and may have references to things like symbol
9173 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
9174 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
.get (), sym_bfd
.get ());
9179 /* Try to open DWO file FILE_NAME.
9180 COMP_DIR is the DW_AT_comp_dir attribute.
9181 The result is the bfd handle of the file.
9182 If there is a problem finding or opening the file, return NULL.
9183 Upon success, the canonicalized path of the file is stored in the bfd,
9184 same as symfile_bfd_open. */
9186 static gdb_bfd_ref_ptr
9187 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
9188 const char *file_name
, const char *comp_dir
)
9190 if (IS_ABSOLUTE_PATH (file_name
))
9191 return try_open_dwop_file (per_objfile
, file_name
,
9192 0 /*is_dwp*/, 0 /*search_cwd*/);
9194 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
9196 if (comp_dir
!= NULL
)
9198 std::string path_to_try
= path_join (comp_dir
, file_name
);
9200 /* NOTE: If comp_dir is a relative path, this will also try the
9201 search path, which seems useful. */
9202 gdb_bfd_ref_ptr
abfd (try_open_dwop_file
9203 (per_objfile
, path_to_try
.c_str (), 0 /*is_dwp*/, 1 /*search_cwd*/));
9209 /* That didn't work, try debug-file-directory, which, despite its name,
9210 is a list of paths. */
9212 if (debug_file_directory
.empty ())
9215 return try_open_dwop_file (per_objfile
, file_name
,
9216 0 /*is_dwp*/, 1 /*search_cwd*/);
9219 /* This function is mapped across the sections and remembers the offset and
9220 size of each of the DWO debugging sections we are interested in. */
9223 dwarf2_locate_dwo_sections (struct objfile
*objfile
, bfd
*abfd
,
9224 asection
*sectp
, dwo_sections
*dwo_sections
)
9226 const struct dwop_section_names
*names
= &dwop_section_names
;
9228 struct dwarf2_section_info
*dw_sect
= nullptr;
9230 if (names
->abbrev_dwo
.matches (sectp
->name
))
9231 dw_sect
= &dwo_sections
->abbrev
;
9232 else if (names
->info_dwo
.matches (sectp
->name
))
9233 dw_sect
= &dwo_sections
->info
;
9234 else if (names
->line_dwo
.matches (sectp
->name
))
9235 dw_sect
= &dwo_sections
->line
;
9236 else if (names
->loc_dwo
.matches (sectp
->name
))
9237 dw_sect
= &dwo_sections
->loc
;
9238 else if (names
->loclists_dwo
.matches (sectp
->name
))
9239 dw_sect
= &dwo_sections
->loclists
;
9240 else if (names
->macinfo_dwo
.matches (sectp
->name
))
9241 dw_sect
= &dwo_sections
->macinfo
;
9242 else if (names
->macro_dwo
.matches (sectp
->name
))
9243 dw_sect
= &dwo_sections
->macro
;
9244 else if (names
->rnglists_dwo
.matches (sectp
->name
))
9245 dw_sect
= &dwo_sections
->rnglists
;
9246 else if (names
->str_dwo
.matches (sectp
->name
))
9247 dw_sect
= &dwo_sections
->str
;
9248 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
9249 dw_sect
= &dwo_sections
->str_offsets
;
9250 else if (names
->types_dwo
.matches (sectp
->name
))
9252 struct dwarf2_section_info type_section
;
9254 memset (&type_section
, 0, sizeof (type_section
));
9255 dwo_sections
->types
.push_back (type_section
);
9256 dw_sect
= &dwo_sections
->types
.back ();
9259 if (dw_sect
!= nullptr)
9261 dw_sect
->s
.section
= sectp
;
9262 dw_sect
->size
= bfd_section_size (sectp
);
9263 dw_sect
->read (objfile
);
9267 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
9268 by PER_CU. This is for the non-DWP case.
9269 The result is NULL if DWO_NAME can't be found. */
9271 static struct dwo_file
*
9272 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
9273 const char *comp_dir
)
9275 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9277 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
9280 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
9285 dwo_file_up
dwo_file (new struct dwo_file
);
9286 dwo_file
->dwo_name
= dwo_name
;
9287 dwo_file
->comp_dir
= comp_dir
;
9288 dwo_file
->dbfd
= std::move (dbfd
);
9290 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
9291 dwarf2_locate_dwo_sections (per_objfile
->objfile
, dwo_file
->dbfd
.get (),
9292 sec
, &dwo_file
->sections
);
9294 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
9297 if (cu
->per_cu
->version () < 5)
9299 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
9300 dwo_file
->sections
.types
, dwo_file
->tus
);
9304 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
9305 &dwo_file
->sections
.info
, dwo_file
->tus
,
9306 rcuh_kind::COMPILE
);
9309 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
9311 return dwo_file
.release ();
9314 /* This function is mapped across the sections and remembers the offset and
9315 size of each of the DWP debugging sections common to version 1 and 2 that
9316 we are interested in. */
9319 dwarf2_locate_common_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
9320 asection
*sectp
, dwp_file
*dwp_file
)
9322 const struct dwop_section_names
*names
= &dwop_section_names
;
9323 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9325 /* Record the ELF section number for later lookup: this is what the
9326 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9327 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9328 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9330 /* Look for specific sections that we need. */
9331 struct dwarf2_section_info
*dw_sect
= nullptr;
9332 if (names
->str_dwo
.matches (sectp
->name
))
9333 dw_sect
= &dwp_file
->sections
.str
;
9334 else if (names
->cu_index
.matches (sectp
->name
))
9335 dw_sect
= &dwp_file
->sections
.cu_index
;
9336 else if (names
->tu_index
.matches (sectp
->name
))
9337 dw_sect
= &dwp_file
->sections
.tu_index
;
9339 if (dw_sect
!= nullptr)
9341 dw_sect
->s
.section
= sectp
;
9342 dw_sect
->size
= bfd_section_size (sectp
);
9343 dw_sect
->read (objfile
);
9347 /* This function is mapped across the sections and remembers the offset and
9348 size of each of the DWP version 2 debugging sections that we are interested
9349 in. This is split into a separate function because we don't know if we
9350 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
9353 dwarf2_locate_v2_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
9354 asection
*sectp
, void *dwp_file_ptr
)
9356 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
9357 const struct dwop_section_names
*names
= &dwop_section_names
;
9358 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9360 /* Record the ELF section number for later lookup: this is what the
9361 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9362 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9363 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9365 /* Look for specific sections that we need. */
9366 struct dwarf2_section_info
*dw_sect
= nullptr;
9367 if (names
->abbrev_dwo
.matches (sectp
->name
))
9368 dw_sect
= &dwp_file
->sections
.abbrev
;
9369 else if (names
->info_dwo
.matches (sectp
->name
))
9370 dw_sect
= &dwp_file
->sections
.info
;
9371 else if (names
->line_dwo
.matches (sectp
->name
))
9372 dw_sect
= &dwp_file
->sections
.line
;
9373 else if (names
->loc_dwo
.matches (sectp
->name
))
9374 dw_sect
= &dwp_file
->sections
.loc
;
9375 else if (names
->macinfo_dwo
.matches (sectp
->name
))
9376 dw_sect
= &dwp_file
->sections
.macinfo
;
9377 else if (names
->macro_dwo
.matches (sectp
->name
))
9378 dw_sect
= &dwp_file
->sections
.macro
;
9379 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
9380 dw_sect
= &dwp_file
->sections
.str_offsets
;
9381 else if (names
->types_dwo
.matches (sectp
->name
))
9382 dw_sect
= &dwp_file
->sections
.types
;
9384 if (dw_sect
!= nullptr)
9386 dw_sect
->s
.section
= sectp
;
9387 dw_sect
->size
= bfd_section_size (sectp
);
9388 dw_sect
->read (objfile
);
9392 /* This function is mapped across the sections and remembers the offset and
9393 size of each of the DWP version 5 debugging sections that we are interested
9394 in. This is split into a separate function because we don't know if we
9395 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
9398 dwarf2_locate_v5_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
9399 asection
*sectp
, void *dwp_file_ptr
)
9401 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
9402 const struct dwop_section_names
*names
= &dwop_section_names
;
9403 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9405 /* Record the ELF section number for later lookup: this is what the
9406 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9407 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9408 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9410 /* Look for specific sections that we need. */
9411 struct dwarf2_section_info
*dw_sect
= nullptr;
9412 if (names
->abbrev_dwo
.matches (sectp
->name
))
9413 dw_sect
= &dwp_file
->sections
.abbrev
;
9414 else if (names
->info_dwo
.matches (sectp
->name
))
9415 dw_sect
= &dwp_file
->sections
.info
;
9416 else if (names
->line_dwo
.matches (sectp
->name
))
9417 dw_sect
= &dwp_file
->sections
.line
;
9418 else if (names
->loclists_dwo
.matches (sectp
->name
))
9419 dw_sect
= &dwp_file
->sections
.loclists
;
9420 else if (names
->macro_dwo
.matches (sectp
->name
))
9421 dw_sect
= &dwp_file
->sections
.macro
;
9422 else if (names
->rnglists_dwo
.matches (sectp
->name
))
9423 dw_sect
= &dwp_file
->sections
.rnglists
;
9424 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
9425 dw_sect
= &dwp_file
->sections
.str_offsets
;
9427 if (dw_sect
!= nullptr)
9429 dw_sect
->s
.section
= sectp
;
9430 dw_sect
->size
= bfd_section_size (sectp
);
9431 dw_sect
->read (objfile
);
9435 /* Hash function for dwp_file loaded CUs/TUs. */
9438 hash_dwp_loaded_cutus (const void *item
)
9440 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9442 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9443 return dwo_unit
->signature
;
9446 /* Equality function for dwp_file loaded CUs/TUs. */
9449 eq_dwp_loaded_cutus (const void *a
, const void *b
)
9451 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
9452 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
9454 return dua
->signature
== dub
->signature
;
9457 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9460 allocate_dwp_loaded_cutus_table ()
9462 return htab_up (htab_create_alloc (3,
9463 hash_dwp_loaded_cutus
,
9464 eq_dwp_loaded_cutus
,
9465 NULL
, xcalloc
, xfree
));
9468 /* Try to open DWP file FILE_NAME.
9469 The result is the bfd handle of the file.
9470 If there is a problem finding or opening the file, return NULL.
9471 Upon success, the canonicalized path of the file is stored in the bfd,
9472 same as symfile_bfd_open. */
9474 static gdb_bfd_ref_ptr
9475 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
9477 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
9483 /* Work around upstream bug 15652.
9484 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
9485 [Whether that's a "bug" is debatable, but it is getting in our way.]
9486 We have no real idea where the dwp file is, because gdb's realpath-ing
9487 of the executable's path may have discarded the needed info.
9488 [IWBN if the dwp file name was recorded in the executable, akin to
9489 .gnu_debuglink, but that doesn't exist yet.]
9490 Strip the directory from FILE_NAME and search again. */
9491 if (!debug_file_directory
.empty ())
9493 /* Don't implicitly search the current directory here.
9494 If the user wants to search "." to handle this case,
9495 it must be added to debug-file-directory. */
9496 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
9504 /* Initialize the use of the DWP file for the current objfile.
9505 By convention the name of the DWP file is ${objfile}.dwp.
9506 The result is NULL if it can't be found. */
9508 static std::unique_ptr
<struct dwp_file
>
9509 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
9511 struct objfile
*objfile
= per_objfile
->objfile
;
9513 /* Try to find first .dwp for the binary file before any symbolic links
9516 /* If the objfile is a debug file, find the name of the real binary
9517 file and get the name of dwp file from there. */
9518 std::string dwp_name
;
9519 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
9521 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
9522 const char *backlink_basename
= lbasename (backlink
->original_name
);
9524 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
9527 dwp_name
= objfile
->original_name
;
9531 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
9533 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
9535 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
9536 dwp_name
= objfile_name (objfile
);
9538 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
9543 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
9545 return std::unique_ptr
<dwp_file
> ();
9548 const char *name
= bfd_get_filename (dbfd
.get ());
9549 std::unique_ptr
<struct dwp_file
> dwp_file
9550 (new struct dwp_file (name
, std::move (dbfd
)));
9552 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
9553 dwp_file
->elf_sections
=
9554 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
9555 dwp_file
->num_sections
, asection
*);
9557 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
9558 dwarf2_locate_common_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
9561 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
9563 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
9565 /* The DWP file version is stored in the hash table. Oh well. */
9566 if (dwp_file
->cus
&& dwp_file
->tus
9567 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
9569 /* Technically speaking, we should try to limp along, but this is
9570 pretty bizarre. We use pulongest here because that's the established
9571 portability solution (e.g, we cannot use %u for uint32_t). */
9572 error (_("Dwarf Error: DWP file CU version %s doesn't match"
9573 " TU version %s [in DWP file %s]"),
9574 pulongest (dwp_file
->cus
->version
),
9575 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
9579 dwp_file
->version
= dwp_file
->cus
->version
;
9580 else if (dwp_file
->tus
)
9581 dwp_file
->version
= dwp_file
->tus
->version
;
9583 dwp_file
->version
= 2;
9585 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
9587 if (dwp_file
->version
== 2)
9588 dwarf2_locate_v2_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
9591 dwarf2_locate_v5_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
9595 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
9596 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
9598 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
9599 dwarf_read_debug_printf (" %s CUs, %s TUs",
9600 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
9601 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
9606 /* Wrapper around open_and_init_dwp_file, only open it once. */
9608 static struct dwp_file
*
9609 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
9611 if (!per_objfile
->per_bfd
->dwp_checked
)
9613 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
9614 per_objfile
->per_bfd
->dwp_checked
= 1;
9616 return per_objfile
->per_bfd
->dwp_file
.get ();
9619 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9620 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9621 or in the DWP file for the objfile, referenced by THIS_UNIT.
9622 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9623 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9625 This is called, for example, when wanting to read a variable with a
9626 complex location. Therefore we don't want to do file i/o for every call.
9627 Therefore we don't want to look for a DWO file on every call.
9628 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9629 then we check if we've already seen DWO_NAME, and only THEN do we check
9632 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9633 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9635 static struct dwo_unit
*
9636 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
9637 ULONGEST signature
, int is_debug_types
)
9639 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9640 struct objfile
*objfile
= per_objfile
->objfile
;
9641 const char *kind
= is_debug_types
? "TU" : "CU";
9642 void **dwo_file_slot
;
9643 struct dwo_file
*dwo_file
;
9644 struct dwp_file
*dwp_file
;
9646 /* First see if there's a DWP file.
9647 If we have a DWP file but didn't find the DWO inside it, don't
9648 look for the original DWO file. It makes gdb behave differently
9649 depending on whether one is debugging in the build tree. */
9651 dwp_file
= get_dwp_file (per_objfile
);
9652 if (dwp_file
!= NULL
)
9654 const struct dwp_hash_table
*dwp_htab
=
9655 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9657 if (dwp_htab
!= NULL
)
9659 struct dwo_unit
*dwo_cutu
=
9660 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
9663 if (dwo_cutu
!= NULL
)
9665 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
9666 kind
, hex_string (signature
),
9667 host_address_to_string (dwo_cutu
));
9675 /* No DWP file, look for the DWO file. */
9677 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
9678 if (*dwo_file_slot
== NULL
)
9680 /* Read in the file and build a table of the CUs/TUs it contains. */
9681 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
9683 /* NOTE: This will be NULL if unable to open the file. */
9684 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
9686 if (dwo_file
!= NULL
)
9688 struct dwo_unit
*dwo_cutu
= NULL
;
9690 if (is_debug_types
&& dwo_file
->tus
)
9692 struct dwo_unit find_dwo_cutu
;
9694 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9695 find_dwo_cutu
.signature
= signature
;
9697 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
9700 else if (!is_debug_types
&& dwo_file
->cus
)
9702 struct dwo_unit find_dwo_cutu
;
9704 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9705 find_dwo_cutu
.signature
= signature
;
9706 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
9710 if (dwo_cutu
!= NULL
)
9712 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
9713 kind
, dwo_name
, hex_string (signature
),
9714 host_address_to_string (dwo_cutu
));
9721 /* We didn't find it. This could mean a dwo_id mismatch, or
9722 someone deleted the DWO/DWP file, or the search path isn't set up
9723 correctly to find the file. */
9725 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
9726 kind
, dwo_name
, hex_string (signature
));
9728 /* This is a warning and not a complaint because it can be caused by
9729 pilot error (e.g., user accidentally deleting the DWO). */
9731 /* Print the name of the DWP file if we looked there, helps the user
9732 better diagnose the problem. */
9733 std::string dwp_text
;
9735 if (dwp_file
!= NULL
)
9736 dwp_text
= string_printf (" [in DWP file %s]",
9737 lbasename (dwp_file
->name
));
9739 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
9741 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
9742 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
9747 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9748 See lookup_dwo_cutu_unit for details. */
9750 static struct dwo_unit
*
9751 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
9754 gdb_assert (!cu
->per_cu
->is_debug_types
);
9756 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
9759 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9760 See lookup_dwo_cutu_unit for details. */
9762 static struct dwo_unit
*
9763 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
9765 gdb_assert (cu
->per_cu
->is_debug_types
);
9767 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
9769 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
9772 /* Traversal function for queue_and_load_all_dwo_tus. */
9775 queue_and_load_dwo_tu (void **slot
, void *info
)
9777 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
9778 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
9779 ULONGEST signature
= dwo_unit
->signature
;
9780 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
9782 if (sig_type
!= NULL
)
9784 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
9785 a real dependency of PER_CU on SIG_TYPE. That is detected later
9786 while processing PER_CU. */
9787 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
9789 load_full_type_unit (sig_type
, cu
->per_objfile
);
9790 cu
->per_cu
->imported_symtabs_push (sig_type
);
9796 /* Queue all TUs contained in the DWO of CU to be read in.
9797 The DWO may have the only definition of the type, though it may not be
9798 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
9799 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
9802 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
9804 struct dwo_unit
*dwo_unit
;
9805 struct dwo_file
*dwo_file
;
9807 gdb_assert (cu
!= nullptr);
9808 gdb_assert (!cu
->per_cu
->is_debug_types
);
9809 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
9811 dwo_unit
= cu
->dwo_unit
;
9812 gdb_assert (dwo_unit
!= NULL
);
9814 dwo_file
= dwo_unit
->dwo_file
;
9815 if (dwo_file
->tus
!= NULL
)
9816 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
9819 /* Read in various DIEs. */
9821 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9822 Inherit only the children of the DW_AT_abstract_origin DIE not being
9823 already referenced by DW_AT_abstract_origin from the children of the
9827 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9829 attribute
*attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9830 if (attr
== nullptr)
9833 /* Note that following die references may follow to a die in a
9835 dwarf2_cu
*origin_cu
= cu
;
9837 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9838 die_info
*origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9840 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9842 struct pending
**origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9843 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9845 if (die
->tag
!= origin_die
->tag
9846 && !(die
->tag
== DW_TAG_inlined_subroutine
9847 && origin_die
->tag
== DW_TAG_subprogram
))
9848 complaint (_("DIE %s and its abstract origin %s have different tags"),
9849 sect_offset_str (die
->sect_off
),
9850 sect_offset_str (origin_die
->sect_off
));
9852 /* Find if the concrete and abstract trees are structurally the
9853 same. This is a shallow traversal and it is not bullet-proof;
9854 the compiler can trick the debugger into believing that the trees
9855 are isomorphic, whereas they actually are not. However, the
9856 likelyhood of this happening is pretty low, and a full-fledged
9857 check would be an overkill. */
9858 bool are_isomorphic
= true;
9859 die_info
*concrete_child
= die
->child
;
9860 die_info
*abstract_child
= origin_die
->child
;
9861 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
9863 if (concrete_child
== nullptr
9864 || abstract_child
== nullptr
9865 || concrete_child
->tag
!= abstract_child
->tag
)
9867 are_isomorphic
= false;
9871 concrete_child
= concrete_child
->sibling
;
9872 abstract_child
= abstract_child
->sibling
;
9875 /* Walk the origin's children in parallel to the concrete children.
9876 This helps match an origin child in case the debug info misses
9877 DW_AT_abstract_origin attributes. Keep in mind that the abstract
9878 origin tree may not have the same tree structure as the concrete
9880 die_info
*corresponding_abstract_child
9881 = are_isomorphic
? origin_die
->child
: nullptr;
9883 std::vector
<sect_offset
> offsets
;
9885 for (die_info
*child_die
= die
->child
;
9886 child_die
&& child_die
->tag
;
9887 child_die
= child_die
->sibling
)
9889 /* We are trying to process concrete instance entries:
9890 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
9891 it's not relevant to our analysis here. i.e. detecting DIEs that are
9892 present in the abstract instance but not referenced in the concrete
9894 if (child_die
->tag
== DW_TAG_call_site
9895 || child_die
->tag
== DW_TAG_GNU_call_site
)
9898 corresponding_abstract_child
9899 = corresponding_abstract_child
->sibling
;
9903 /* For each CHILD_DIE, find the corresponding child of
9904 ORIGIN_DIE. If there is more than one layer of
9905 DW_AT_abstract_origin, follow them all; there shouldn't be,
9906 but GCC versions at least through 4.4 generate this (GCC PR
9908 die_info
*child_origin_die
= child_die
;
9909 dwarf2_cu
*child_origin_cu
= cu
;
9912 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9914 if (attr
== nullptr)
9917 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9921 /* If missing DW_AT_abstract_origin, try the corresponding child
9922 of the origin. Clang emits such lexical scopes. */
9923 if (child_origin_die
== child_die
9924 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
9926 && child_die
->tag
== DW_TAG_lexical_block
)
9927 child_origin_die
= corresponding_abstract_child
;
9929 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9930 counterpart may exist. */
9931 if (child_origin_die
!= child_die
)
9933 if (child_die
->tag
!= child_origin_die
->tag
9934 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9935 && child_origin_die
->tag
== DW_TAG_subprogram
))
9936 complaint (_("Child DIE %s and its abstract origin %s have "
9938 sect_offset_str (child_die
->sect_off
),
9939 sect_offset_str (child_origin_die
->sect_off
));
9940 if (child_origin_die
->parent
!= origin_die
)
9941 complaint (_("Child DIE %s and its abstract origin %s have "
9942 "different parents"),
9943 sect_offset_str (child_die
->sect_off
),
9944 sect_offset_str (child_origin_die
->sect_off
));
9946 offsets
.push_back (child_origin_die
->sect_off
);
9950 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
9953 if (!offsets
.empty ())
9955 std::sort (offsets
.begin (), offsets
.end ());
9957 for (auto offsets_it
= offsets
.begin () + 1;
9958 offsets_it
< offsets
.end ();
9960 if (*(offsets_it
- 1) == *offsets_it
)
9961 complaint (_("Multiple children of DIE %s refer "
9962 "to DIE %s as their abstract origin"),
9963 sect_offset_str (die
->sect_off
),
9964 sect_offset_str (*offsets_it
));
9967 auto offsets_it
= offsets
.begin ();
9968 die_info
*origin_child_die
= origin_die
->child
;
9969 while (origin_child_die
!= nullptr && origin_child_die
->tag
!= 0)
9971 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9972 while (offsets_it
< offsets
.end ()
9973 && *offsets_it
< origin_child_die
->sect_off
)
9976 if (offsets_it
== offsets
.end ()
9977 || *offsets_it
> origin_child_die
->sect_off
)
9979 /* Found that ORIGIN_CHILD_DIE is really not referenced.
9980 Check whether we're already processing ORIGIN_CHILD_DIE.
9981 This can happen with mutually referenced abstract_origins.
9983 if (!origin_child_die
->in_process
)
9984 process_die (origin_child_die
, origin_cu
);
9987 origin_child_die
= origin_child_die
->sibling
;
9990 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9992 if (cu
!= origin_cu
)
9993 compute_delayed_physnames (origin_cu
);
9997 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9999 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10000 struct gdbarch
*gdbarch
= objfile
->arch ();
10001 struct context_stack
*newobj
;
10004 struct die_info
*child_die
;
10005 struct attribute
*attr
, *call_line
, *call_file
;
10007 CORE_ADDR baseaddr
;
10008 struct block
*block
;
10009 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10010 std::vector
<struct symbol
*> template_args
;
10011 struct template_symbol
*templ_func
= NULL
;
10015 /* If we do not have call site information, we can't show the
10016 caller of this inlined function. That's too confusing, so
10017 only use the scope for local variables. */
10018 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
10019 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
10020 if (call_line
== NULL
|| call_file
== NULL
)
10022 read_lexical_block_scope (die
, cu
);
10027 baseaddr
= objfile
->text_section_offset ();
10029 name
= dwarf2_name (die
, cu
);
10030 if (name
== nullptr)
10031 name
= dw2_linkage_name (die
, cu
);
10033 /* Ignore functions with missing or empty names. These are actually
10034 illegal according to the DWARF standard. */
10037 complaint (_("missing name for subprogram DIE at %s"),
10038 sect_offset_str (die
->sect_off
));
10042 /* Ignore functions with missing or invalid low and high pc attributes. */
10043 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr)
10044 <= PC_BOUNDS_INVALID
)
10046 if (have_complaint ())
10048 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10049 bool external_p
= attr
!= nullptr && attr
->as_boolean ();
10050 attr
= dwarf2_attr (die
, DW_AT_inline
, cu
);
10053 && attr
->is_nonnegative ()
10054 && (attr
->as_nonnegative () == DW_INL_inlined
10055 || attr
->as_nonnegative () == DW_INL_declared_inlined
));
10056 attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
10057 bool decl_p
= attr
!= nullptr && attr
->as_boolean ();
10058 if (!external_p
&& !inlined_p
&& !decl_p
)
10059 complaint (_("cannot get low and high bounds "
10060 "for subprogram DIE at %s"),
10061 sect_offset_str (die
->sect_off
));
10066 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10067 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10069 /* If we have any template arguments, then we must allocate a
10070 different sort of symbol. */
10071 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
10073 if (child_die
->tag
== DW_TAG_template_type_param
10074 || child_die
->tag
== DW_TAG_template_value_param
)
10076 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
10077 templ_func
->subclass
= SYMBOL_TEMPLATE
;
10082 gdb_assert (cu
->get_builder () != nullptr);
10083 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
10084 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
10085 (struct symbol
*) templ_func
);
10087 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
10088 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
10091 /* If there is a location expression for DW_AT_frame_base, record
10093 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
10094 if (attr
!= nullptr)
10095 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
10097 /* If there is a location for the static link, record it. */
10098 newobj
->static_link
= NULL
;
10099 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
10100 if (attr
!= nullptr)
10102 newobj
->static_link
10103 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
10104 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
10108 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
10110 if (die
->child
!= NULL
)
10112 child_die
= die
->child
;
10113 while (child_die
&& child_die
->tag
)
10115 if (child_die
->tag
== DW_TAG_template_type_param
10116 || child_die
->tag
== DW_TAG_template_value_param
)
10118 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10121 template_args
.push_back (arg
);
10124 process_die (child_die
, cu
);
10125 child_die
= child_die
->sibling
;
10129 inherit_abstract_dies (die
, cu
);
10131 /* If we have a DW_AT_specification, we might need to import using
10132 directives from the context of the specification DIE. See the
10133 comment in determine_prefix. */
10134 if (cu
->lang () == language_cplus
10135 && dwarf2_attr (die
, DW_AT_specification
, cu
))
10137 struct dwarf2_cu
*spec_cu
= cu
;
10138 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
10142 child_die
= spec_die
->child
;
10143 while (child_die
&& child_die
->tag
)
10145 if (child_die
->tag
== DW_TAG_imported_module
)
10146 process_die (child_die
, spec_cu
);
10147 child_die
= child_die
->sibling
;
10150 /* In some cases, GCC generates specification DIEs that
10151 themselves contain DW_AT_specification attributes. */
10152 spec_die
= die_specification (spec_die
, &spec_cu
);
10156 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
10157 /* Make a block for the local symbols within. */
10158 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
10159 cstk
.static_link
, lowpc
, highpc
);
10161 /* For C++, set the block's scope. */
10162 if ((cu
->lang () == language_cplus
10163 || cu
->lang () == language_fortran
10164 || cu
->lang () == language_d
10165 || cu
->lang () == language_rust
)
10166 && cu
->processing_has_namespace_info
)
10167 block
->set_scope (determine_prefix (die
, cu
),
10168 &objfile
->objfile_obstack
);
10170 /* If we have address ranges, record them. */
10171 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10173 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
10175 /* Attach template arguments to function. */
10176 if (!template_args
.empty ())
10178 gdb_assert (templ_func
!= NULL
);
10180 templ_func
->n_template_arguments
= template_args
.size ();
10181 templ_func
->template_arguments
10182 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
10183 templ_func
->n_template_arguments
);
10184 memcpy (templ_func
->template_arguments
,
10185 template_args
.data (),
10186 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
10188 /* Make sure that the symtab is set on the new symbols. Even
10189 though they don't appear in this symtab directly, other parts
10190 of gdb assume that symbols do, and this is reasonably
10192 for (symbol
*sym
: template_args
)
10193 sym
->set_symtab (templ_func
->symtab ());
10196 /* In C++, we can have functions nested inside functions (e.g., when
10197 a function declares a class that has methods). This means that
10198 when we finish processing a function scope, we may need to go
10199 back to building a containing block's symbol lists. */
10200 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
10201 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
10203 /* If we've finished processing a top-level function, subsequent
10204 symbols go in the file symbol list. */
10205 if (cu
->get_builder ()->outermost_context_p ())
10206 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
10209 /* Process all the DIES contained within a lexical block scope. Start
10210 a new scope, process the dies, and then close the scope. */
10213 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10215 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10216 struct gdbarch
*gdbarch
= objfile
->arch ();
10217 CORE_ADDR lowpc
, highpc
;
10218 struct die_info
*child_die
;
10219 CORE_ADDR baseaddr
;
10221 baseaddr
= objfile
->text_section_offset ();
10223 /* Ignore blocks with missing or invalid low and high pc attributes. */
10224 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
10225 as multiple lexical blocks? Handling children in a sane way would
10226 be nasty. Might be easier to properly extend generic blocks to
10227 describe ranges. */
10228 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr))
10230 case PC_BOUNDS_NOT_PRESENT
:
10231 /* DW_TAG_lexical_block has no attributes, process its children as if
10232 there was no wrapping by that DW_TAG_lexical_block.
10233 GCC does no longer produces such DWARF since GCC r224161. */
10234 for (child_die
= die
->child
;
10235 child_die
!= NULL
&& child_die
->tag
;
10236 child_die
= child_die
->sibling
)
10238 /* We might already be processing this DIE. This can happen
10239 in an unusual circumstance -- where a subroutine A
10240 appears lexically in another subroutine B, but A actually
10241 inlines B. The recursion is broken here, rather than in
10242 inherit_abstract_dies, because it seems better to simply
10243 drop concrete children here. */
10244 if (!child_die
->in_process
)
10245 process_die (child_die
, cu
);
10248 case PC_BOUNDS_INVALID
:
10251 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10252 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10254 cu
->get_builder ()->push_context (0, lowpc
);
10255 if (die
->child
!= NULL
)
10257 child_die
= die
->child
;
10258 while (child_die
&& child_die
->tag
)
10260 process_die (child_die
, cu
);
10261 child_die
= child_die
->sibling
;
10264 inherit_abstract_dies (die
, cu
);
10265 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
10267 if (*cu
->get_builder ()->get_local_symbols () != NULL
10268 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
10270 struct block
*block
10271 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
10272 cstk
.start_addr
, highpc
);
10274 /* Note that recording ranges after traversing children, as we
10275 do here, means that recording a parent's ranges entails
10276 walking across all its children's ranges as they appear in
10277 the address map, which is quadratic behavior.
10279 It would be nicer to record the parent's ranges before
10280 traversing its children, simply overriding whatever you find
10281 there. But since we don't even decide whether to create a
10282 block until after we've traversed its children, that's hard
10284 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10286 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
10287 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
10290 static void dwarf2_ranges_read_low_addrs (unsigned offset
,
10291 struct dwarf2_cu
*cu
,
10293 std::vector
<CORE_ADDR
> &result
);
10295 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
10298 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10300 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10301 struct objfile
*objfile
= per_objfile
->objfile
;
10302 struct gdbarch
*gdbarch
= objfile
->arch ();
10303 CORE_ADDR pc
, baseaddr
;
10304 struct attribute
*attr
;
10307 struct die_info
*child_die
;
10309 baseaddr
= objfile
->text_section_offset ();
10311 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
10314 /* This was a pre-DWARF-5 GNU extension alias
10315 for DW_AT_call_return_pc. */
10316 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10320 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
10321 "DIE %s [in module %s]"),
10322 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10325 pc
= attr
->as_address () + baseaddr
;
10326 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
10329 if (cu
->call_site_htab
== NULL
)
10330 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
10331 call_site::eq
, NULL
,
10332 &objfile
->objfile_obstack
,
10333 hashtab_obstack_allocate
, NULL
);
10334 struct call_site
call_site_local (pc
, nullptr, nullptr);
10335 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
10338 complaint (_("Duplicate PC %s for DW_TAG_call_site "
10339 "DIE %s [in module %s]"),
10340 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
10341 objfile_name (objfile
));
10345 /* Count parameters at the caller. */
10348 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10349 child_die
= child_die
->sibling
)
10351 if (child_die
->tag
!= DW_TAG_call_site_parameter
10352 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
10354 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
10355 "DW_TAG_call_site child DIE %s [in module %s]"),
10356 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
10357 objfile_name (objfile
));
10364 struct call_site
*call_site
10365 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
10367 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
10368 struct call_site (pc
, cu
->per_cu
, per_objfile
);
10371 /* We never call the destructor of call_site, so we must ensure it is
10372 trivially destructible. */
10373 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
10375 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
10376 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
10378 struct die_info
*func_die
;
10380 /* Skip also over DW_TAG_inlined_subroutine. */
10381 for (func_die
= die
->parent
;
10382 func_die
&& func_die
->tag
!= DW_TAG_subprogram
10383 && func_die
->tag
!= DW_TAG_subroutine_type
;
10384 func_die
= func_die
->parent
);
10386 /* DW_AT_call_all_calls is a superset
10387 of DW_AT_call_all_tail_calls. */
10389 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
10390 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
10391 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
10392 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
10394 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
10395 not complete. But keep CALL_SITE for look ups via call_site_htab,
10396 both the initial caller containing the real return address PC and
10397 the final callee containing the current PC of a chain of tail
10398 calls do not need to have the tail call list complete. But any
10399 function candidate for a virtual tail call frame searched via
10400 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
10401 determined unambiguously. */
10405 struct type
*func_type
= NULL
;
10408 func_type
= get_die_type (func_die
, cu
);
10409 if (func_type
!= NULL
)
10411 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
10413 /* Enlist this call site to the function. */
10414 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
10415 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
10418 complaint (_("Cannot find function owning DW_TAG_call_site "
10419 "DIE %s [in module %s]"),
10420 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10424 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
10426 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
10428 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
10431 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
10432 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
10435 call_site
->target
.set_loc_dwarf_block (nullptr);
10436 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
10437 /* Keep NULL DWARF_BLOCK. */;
10438 else if (attr
->form_is_block ())
10440 struct dwarf2_locexpr_baton
*dlbaton
;
10441 struct dwarf_block
*block
= attr
->as_block ();
10443 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
10444 dlbaton
->data
= block
->data
;
10445 dlbaton
->size
= block
->size
;
10446 dlbaton
->per_objfile
= per_objfile
;
10447 dlbaton
->per_cu
= cu
->per_cu
;
10449 call_site
->target
.set_loc_dwarf_block (dlbaton
);
10451 else if (attr
->form_is_ref ())
10453 struct dwarf2_cu
*target_cu
= cu
;
10454 struct die_info
*target_die
;
10456 target_die
= follow_die_ref (die
, attr
, &target_cu
);
10457 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
10459 struct attribute
*ranges_attr
10460 = dwarf2_attr (target_die
, DW_AT_ranges
, target_cu
);
10462 if (die_is_declaration (target_die
, target_cu
))
10464 const char *target_physname
;
10466 /* Prefer the mangled name; otherwise compute the demangled one. */
10467 target_physname
= dw2_linkage_name (target_die
, target_cu
);
10468 if (target_physname
== NULL
)
10469 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
10470 if (target_physname
== NULL
)
10471 complaint (_("DW_AT_call_target target DIE has invalid "
10472 "physname, for referencing DIE %s [in module %s]"),
10473 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10475 call_site
->target
.set_loc_physname (target_physname
);
10477 else if (ranges_attr
!= nullptr && ranges_attr
->form_is_unsigned ())
10479 ULONGEST ranges_offset
= (ranges_attr
->as_unsigned ()
10480 + target_cu
->gnu_ranges_base
);
10481 std::vector
<CORE_ADDR
> addresses
;
10482 dwarf2_ranges_read_low_addrs (ranges_offset
, target_cu
,
10483 target_die
->tag
, addresses
);
10484 CORE_ADDR
*saved
= XOBNEWVAR (&objfile
->objfile_obstack
, CORE_ADDR
,
10485 addresses
.size ());
10486 std::copy (addresses
.begin (), addresses
.end (), saved
);
10487 call_site
->target
.set_loc_array (addresses
.size (), saved
);
10493 /* DW_AT_entry_pc should be preferred. */
10494 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
,
10496 <= PC_BOUNDS_INVALID
)
10497 complaint (_("DW_AT_call_target target DIE has invalid "
10498 "low pc, for referencing DIE %s [in module %s]"),
10499 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10502 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
10504 call_site
->target
.set_loc_physaddr (lowpc
);
10509 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
10510 "block nor reference, for DIE %s [in module %s]"),
10511 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10513 for (child_die
= die
->child
;
10514 child_die
&& child_die
->tag
;
10515 child_die
= child_die
->sibling
)
10517 struct call_site_parameter
*parameter
;
10518 struct attribute
*loc
, *origin
;
10520 if (child_die
->tag
!= DW_TAG_call_site_parameter
10521 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
10523 /* Already printed the complaint above. */
10527 gdb_assert (call_site
->parameter_count
< nparams
);
10528 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
10530 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
10531 specifies DW_TAG_formal_parameter. Value of the data assumed for the
10532 register is contained in DW_AT_call_value. */
10534 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
10535 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
10536 if (origin
== NULL
)
10538 /* This was a pre-DWARF-5 GNU extension alias
10539 for DW_AT_call_parameter. */
10540 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
10542 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
10544 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
10546 sect_offset sect_off
= origin
->get_ref_die_offset ();
10547 if (!cu
->header
.offset_in_cu_p (sect_off
))
10549 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
10550 binding can be done only inside one CU. Such referenced DIE
10551 therefore cannot be even moved to DW_TAG_partial_unit. */
10552 complaint (_("DW_AT_call_parameter offset is not in CU for "
10553 "DW_TAG_call_site child DIE %s [in module %s]"),
10554 sect_offset_str (child_die
->sect_off
),
10555 objfile_name (objfile
));
10558 parameter
->u
.param_cu_off
10559 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
10561 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
10563 complaint (_("No DW_FORM_block* DW_AT_location for "
10564 "DW_TAG_call_site child DIE %s [in module %s]"),
10565 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
10570 struct dwarf_block
*block
= loc
->as_block ();
10572 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
10573 (block
->data
, &block
->data
[block
->size
]);
10574 if (parameter
->u
.dwarf_reg
!= -1)
10575 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
10576 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
10577 &block
->data
[block
->size
],
10578 ¶meter
->u
.fb_offset
))
10579 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
10582 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
10583 "for DW_FORM_block* DW_AT_location is supported for "
10584 "DW_TAG_call_site child DIE %s "
10586 sect_offset_str (child_die
->sect_off
),
10587 objfile_name (objfile
));
10592 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
10594 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
10595 if (attr
== NULL
|| !attr
->form_is_block ())
10597 complaint (_("No DW_FORM_block* DW_AT_call_value for "
10598 "DW_TAG_call_site child DIE %s [in module %s]"),
10599 sect_offset_str (child_die
->sect_off
),
10600 objfile_name (objfile
));
10604 struct dwarf_block
*block
= attr
->as_block ();
10605 parameter
->value
= block
->data
;
10606 parameter
->value_size
= block
->size
;
10608 /* Parameters are not pre-cleared by memset above. */
10609 parameter
->data_value
= NULL
;
10610 parameter
->data_value_size
= 0;
10611 call_site
->parameter_count
++;
10613 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
10615 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
10616 if (attr
!= nullptr)
10618 if (!attr
->form_is_block ())
10619 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
10620 "DW_TAG_call_site child DIE %s [in module %s]"),
10621 sect_offset_str (child_die
->sect_off
),
10622 objfile_name (objfile
));
10625 block
= attr
->as_block ();
10626 parameter
->data_value
= block
->data
;
10627 parameter
->data_value_size
= block
->size
;
10633 /* Helper function for read_variable. If DIE represents a virtual
10634 table, then return the type of the concrete object that is
10635 associated with the virtual table. Otherwise, return NULL. */
10637 static struct type
*
10638 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10640 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
10644 /* Find the type DIE. */
10645 struct die_info
*type_die
= NULL
;
10646 struct dwarf2_cu
*type_cu
= cu
;
10648 if (attr
->form_is_ref ())
10649 type_die
= follow_die_ref (die
, attr
, &type_cu
);
10650 if (type_die
== NULL
)
10653 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
10655 return die_containing_type (type_die
, type_cu
);
10658 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
10661 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
10663 struct rust_vtable_symbol
*storage
= NULL
;
10665 if (cu
->lang () == language_rust
)
10667 struct type
*containing_type
= rust_containing_type (die
, cu
);
10669 if (containing_type
!= NULL
)
10671 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10673 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
10674 storage
->concrete_type
= containing_type
;
10675 storage
->subclass
= SYMBOL_RUST_VTABLE
;
10679 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
10680 struct attribute
*abstract_origin
10681 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
10682 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
10683 if (res
== NULL
&& loc
&& abstract_origin
)
10685 /* We have a variable without a name, but with a location and an abstract
10686 origin. This may be a concrete instance of an abstract variable
10687 referenced from an DW_OP_GNU_variable_value, so save it to find it back
10689 struct dwarf2_cu
*origin_cu
= cu
;
10690 struct die_info
*origin_die
10691 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
10692 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10693 per_objfile
->per_bfd
->abstract_to_concrete
10694 [origin_die
->sect_off
].push_back (die
->sect_off
);
10698 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
10699 reading .debug_rnglists.
10700 Callback's type should be:
10701 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
10702 Return true if the attributes are present and valid, otherwise,
10705 template <typename Callback
>
10707 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
10708 dwarf_tag tag
, Callback
&&callback
)
10710 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10711 struct objfile
*objfile
= per_objfile
->objfile
;
10712 bfd
*obfd
= objfile
->obfd
.get ();
10713 /* Base address selection entry. */
10714 gdb::optional
<CORE_ADDR
> base
;
10715 const gdb_byte
*buffer
;
10716 bool overflow
= false;
10717 ULONGEST addr_index
;
10718 struct dwarf2_section_info
*rnglists_section
;
10720 base
= cu
->base_address
;
10721 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
10722 rnglists_section
->read (objfile
);
10724 if (offset
>= rnglists_section
->size
)
10726 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
10730 buffer
= rnglists_section
->buffer
+ offset
;
10734 /* Initialize it due to a false compiler warning. */
10735 CORE_ADDR range_beginning
= 0, range_end
= 0;
10736 const gdb_byte
*buf_end
= (rnglists_section
->buffer
10737 + rnglists_section
->size
);
10738 unsigned int bytes_read
;
10740 if (buffer
== buf_end
)
10745 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
10748 case DW_RLE_end_of_list
:
10750 case DW_RLE_base_address
:
10751 if (buffer
+ cu
->header
.addr_size
> buf_end
)
10756 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
10757 buffer
+= bytes_read
;
10759 case DW_RLE_base_addressx
:
10760 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10761 buffer
+= bytes_read
;
10762 base
= read_addr_index (cu
, addr_index
);
10764 case DW_RLE_start_length
:
10765 if (buffer
+ cu
->header
.addr_size
> buf_end
)
10770 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
10772 buffer
+= bytes_read
;
10773 range_end
= (range_beginning
10774 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
10775 buffer
+= bytes_read
;
10776 if (buffer
> buf_end
)
10782 case DW_RLE_startx_length
:
10783 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10784 buffer
+= bytes_read
;
10785 range_beginning
= read_addr_index (cu
, addr_index
);
10786 if (buffer
> buf_end
)
10791 range_end
= (range_beginning
10792 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
10793 buffer
+= bytes_read
;
10795 case DW_RLE_offset_pair
:
10796 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10797 buffer
+= bytes_read
;
10798 if (buffer
> buf_end
)
10803 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10804 buffer
+= bytes_read
;
10805 if (buffer
> buf_end
)
10811 case DW_RLE_start_end
:
10812 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
10817 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
10819 buffer
+= bytes_read
;
10820 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
10821 buffer
+= bytes_read
;
10823 case DW_RLE_startx_endx
:
10824 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10825 buffer
+= bytes_read
;
10826 range_beginning
= read_addr_index (cu
, addr_index
);
10827 if (buffer
> buf_end
)
10832 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10833 buffer
+= bytes_read
;
10834 range_end
= read_addr_index (cu
, addr_index
);
10837 complaint (_("Invalid .debug_rnglists data (no base address)"));
10840 if (rlet
== DW_RLE_end_of_list
|| overflow
)
10842 if (rlet
== DW_RLE_base_address
)
10845 if (range_beginning
> range_end
)
10847 /* Inverted range entries are invalid. */
10848 complaint (_("Invalid .debug_rnglists data (inverted range)"));
10852 /* Empty range entries have no effect. */
10853 if (range_beginning
== range_end
)
10856 /* Only DW_RLE_offset_pair needs the base address added. */
10857 if (rlet
== DW_RLE_offset_pair
)
10859 if (!base
.has_value ())
10861 /* We have no valid base address for the DW_RLE_offset_pair. */
10862 complaint (_("Invalid .debug_rnglists data (no base address for "
10863 "DW_RLE_offset_pair)"));
10867 range_beginning
+= *base
;
10868 range_end
+= *base
;
10871 /* A not-uncommon case of bad debug info.
10872 Don't pollute the addrmap with bad data. */
10873 if (range_beginning
== 0
10874 && !per_objfile
->per_bfd
->has_section_at_zero
)
10876 complaint (_(".debug_rnglists entry has start address of zero"
10877 " [in module %s]"), objfile_name (objfile
));
10881 callback (range_beginning
, range_end
);
10886 complaint (_("Offset %d is not terminated "
10887 "for DW_AT_ranges attribute"),
10895 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
10896 Callback's type should be:
10897 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
10898 Return 1 if the attributes are present and valid, otherwise, return 0. */
10900 template <typename Callback
>
10902 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
10903 Callback
&&callback
)
10905 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10906 struct objfile
*objfile
= per_objfile
->objfile
;
10907 struct comp_unit_head
*cu_header
= &cu
->header
;
10908 bfd
*obfd
= objfile
->obfd
.get ();
10909 unsigned int addr_size
= cu_header
->addr_size
;
10910 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10911 /* Base address selection entry. */
10912 gdb::optional
<CORE_ADDR
> base
;
10913 unsigned int dummy
;
10914 const gdb_byte
*buffer
;
10916 if (cu_header
->version
>= 5)
10917 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
10919 base
= cu
->base_address
;
10921 per_objfile
->per_bfd
->ranges
.read (objfile
);
10922 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
10924 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
10928 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
10932 CORE_ADDR range_beginning
, range_end
;
10934 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
10935 buffer
+= addr_size
;
10936 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
10937 buffer
+= addr_size
;
10938 offset
+= 2 * addr_size
;
10940 /* An end of list marker is a pair of zero addresses. */
10941 if (range_beginning
== 0 && range_end
== 0)
10942 /* Found the end of list entry. */
10945 /* Each base address selection entry is a pair of 2 values.
10946 The first is the largest possible address, the second is
10947 the base address. Check for a base address here. */
10948 if ((range_beginning
& mask
) == mask
)
10950 /* If we found the largest possible address, then we already
10951 have the base address in range_end. */
10956 if (!base
.has_value ())
10958 /* We have no valid base address for the ranges
10960 complaint (_("Invalid .debug_ranges data (no base address)"));
10964 if (range_beginning
> range_end
)
10966 /* Inverted range entries are invalid. */
10967 complaint (_("Invalid .debug_ranges data (inverted range)"));
10971 /* Empty range entries have no effect. */
10972 if (range_beginning
== range_end
)
10975 range_beginning
+= *base
;
10976 range_end
+= *base
;
10978 /* A not-uncommon case of bad debug info.
10979 Don't pollute the addrmap with bad data. */
10980 if (range_beginning
== 0
10981 && !per_objfile
->per_bfd
->has_section_at_zero
)
10983 complaint (_(".debug_ranges entry has start address of zero"
10984 " [in module %s]"), objfile_name (objfile
));
10988 callback (range_beginning
, range_end
);
10994 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
10995 Return 1 if the attributes are present and valid, otherwise, return 0.
10996 TAG is passed to dwarf2_ranges_process. If MAP is not NULL, then
10997 ranges in MAP are set, using DATUM as the value. */
11000 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
11001 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
11002 addrmap
*map
, void *datum
, dwarf_tag tag
)
11004 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11005 struct gdbarch
*gdbarch
= objfile
->arch ();
11006 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
11009 CORE_ADDR high
= 0;
11012 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
11013 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
11015 if (map
!= nullptr)
11020 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
11021 range_beginning
+ baseaddr
)
11023 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
11024 range_end
+ baseaddr
)
11026 map
->set_empty (lowpc
, highpc
- 1, datum
);
11029 /* FIXME: This is recording everything as a low-high
11030 segment of consecutive addresses. We should have a
11031 data structure for discontiguous block ranges
11035 low
= range_beginning
;
11041 if (range_beginning
< low
)
11042 low
= range_beginning
;
11043 if (range_end
> high
)
11051 /* If the first entry is an end-of-list marker, the range
11052 describes an empty scope, i.e. no instructions. */
11058 *high_return
= high
;
11062 /* Process ranges and fill in a vector of the low PC values only. */
11065 dwarf2_ranges_read_low_addrs (unsigned offset
, struct dwarf2_cu
*cu
,
11067 std::vector
<CORE_ADDR
> &result
)
11069 dwarf2_ranges_process (offset
, cu
, tag
,
11070 [&] (CORE_ADDR start
, CORE_ADDR end
)
11072 result
.push_back (start
);
11076 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
11077 definition for the return value. *LOWPC and *HIGHPC are set iff
11078 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
11080 static enum pc_bounds_kind
11081 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
11082 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
11083 addrmap
*map
, void *datum
)
11085 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11086 struct attribute
*attr
;
11087 struct attribute
*attr_high
;
11089 CORE_ADDR high
= 0;
11090 enum pc_bounds_kind ret
;
11092 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11095 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11096 if (attr
!= nullptr)
11098 low
= attr
->as_address ();
11099 high
= attr_high
->as_address ();
11100 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
11104 /* Found high w/o low attribute. */
11105 return PC_BOUNDS_INVALID
;
11107 /* Found consecutive range of addresses. */
11108 ret
= PC_BOUNDS_HIGH_LOW
;
11112 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11113 if (attr
!= nullptr && attr
->form_is_unsigned ())
11115 /* Offset in the .debug_ranges or .debug_rnglist section (depending
11116 on DWARF version). */
11117 ULONGEST ranges_offset
= attr
->as_unsigned ();
11119 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
11121 if (die
->tag
!= DW_TAG_compile_unit
)
11122 ranges_offset
+= cu
->gnu_ranges_base
;
11124 /* Value of the DW_AT_ranges attribute is the offset in the
11125 .debug_ranges section. */
11126 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
,
11127 map
, datum
, die
->tag
))
11128 return PC_BOUNDS_INVALID
;
11129 /* Found discontinuous range of addresses. */
11130 ret
= PC_BOUNDS_RANGES
;
11133 return PC_BOUNDS_NOT_PRESENT
;
11136 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
11138 return PC_BOUNDS_INVALID
;
11140 /* When using the GNU linker, .gnu.linkonce. sections are used to
11141 eliminate duplicate copies of functions and vtables and such.
11142 The linker will arbitrarily choose one and discard the others.
11143 The AT_*_pc values for such functions refer to local labels in
11144 these sections. If the section from that file was discarded, the
11145 labels are not in the output, so the relocs get a value of 0.
11146 If this is a discarded function, mark the pc bounds as invalid,
11147 so that GDB will ignore it. */
11148 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
11149 return PC_BOUNDS_INVALID
;
11157 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
11158 its low and high PC addresses. Do nothing if these addresses could not
11159 be determined. Otherwise, set LOWPC to the low address if it is smaller,
11160 and HIGHPC to the high address if greater than HIGHPC. */
11163 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
11164 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11165 struct dwarf2_cu
*cu
)
11167 CORE_ADDR low
, high
;
11168 struct die_info
*child
= die
->child
;
11170 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, nullptr, nullptr)
11171 >= PC_BOUNDS_RANGES
)
11173 *lowpc
= std::min (*lowpc
, low
);
11174 *highpc
= std::max (*highpc
, high
);
11177 /* If the language does not allow nested subprograms (either inside
11178 subprograms or lexical blocks), we're done. */
11179 if (cu
->lang () != language_ada
)
11182 /* Check all the children of the given DIE. If it contains nested
11183 subprograms, then check their pc bounds. Likewise, we need to
11184 check lexical blocks as well, as they may also contain subprogram
11186 while (child
&& child
->tag
)
11188 if (child
->tag
== DW_TAG_subprogram
11189 || child
->tag
== DW_TAG_lexical_block
)
11190 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
11191 child
= child
->sibling
;
11195 /* Get the low and high pc's represented by the scope DIE, and store
11196 them in *LOWPC and *HIGHPC. If the correct values can't be
11197 determined, set *LOWPC to -1 and *HIGHPC to 0. */
11200 get_scope_pc_bounds (struct die_info
*die
,
11201 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11202 struct dwarf2_cu
*cu
)
11204 CORE_ADDR best_low
= (CORE_ADDR
) -1;
11205 CORE_ADDR best_high
= (CORE_ADDR
) 0;
11206 CORE_ADDR current_low
, current_high
;
11208 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
,
11210 >= PC_BOUNDS_RANGES
)
11212 best_low
= current_low
;
11213 best_high
= current_high
;
11217 struct die_info
*child
= die
->child
;
11219 while (child
&& child
->tag
)
11221 switch (child
->tag
) {
11222 case DW_TAG_subprogram
:
11223 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
11225 case DW_TAG_namespace
:
11226 case DW_TAG_module
:
11227 /* FIXME: carlton/2004-01-16: Should we do this for
11228 DW_TAG_class_type/DW_TAG_structure_type, too? I think
11229 that current GCC's always emit the DIEs corresponding
11230 to definitions of methods of classes as children of a
11231 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
11232 the DIEs giving the declarations, which could be
11233 anywhere). But I don't see any reason why the
11234 standards says that they have to be there. */
11235 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
11237 if (current_low
!= ((CORE_ADDR
) -1))
11239 best_low
= std::min (best_low
, current_low
);
11240 best_high
= std::max (best_high
, current_high
);
11248 child
= child
->sibling
;
11253 *highpc
= best_high
;
11256 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
11260 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
11261 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
11263 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11264 struct gdbarch
*gdbarch
= objfile
->arch ();
11265 struct attribute
*attr
;
11266 struct attribute
*attr_high
;
11268 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11271 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11272 if (attr
!= nullptr)
11274 CORE_ADDR low
= attr
->as_address ();
11275 CORE_ADDR high
= attr_high
->as_address ();
11277 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
11280 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
11281 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
11282 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
11286 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11287 if (attr
!= nullptr && attr
->form_is_unsigned ())
11289 /* Offset in the .debug_ranges or .debug_rnglist section (depending
11290 on DWARF version). */
11291 ULONGEST ranges_offset
= attr
->as_unsigned ();
11293 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
11295 if (die
->tag
!= DW_TAG_compile_unit
)
11296 ranges_offset
+= cu
->gnu_ranges_base
;
11298 std::vector
<blockrange
> blockvec
;
11299 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
11300 [&] (CORE_ADDR start
, CORE_ADDR end
)
11304 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
11305 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
11306 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
11307 blockvec
.emplace_back (start
, end
);
11310 block
->set_ranges (make_blockranges (objfile
, blockvec
));
11314 /* Check whether the producer field indicates either of GCC < 4.6, or the
11315 Intel C/C++ compiler, and cache the result in CU. */
11318 check_producer (struct dwarf2_cu
*cu
)
11322 if (cu
->producer
== NULL
)
11324 /* For unknown compilers expect their behavior is DWARF version
11327 GCC started to support .debug_types sections by -gdwarf-4 since
11328 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
11329 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
11330 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
11331 interpreted incorrectly by GDB now - GCC PR debug/48229. */
11333 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
11335 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
11336 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
11337 cu
->producer_is_gcc_11
= major
== 11;
11339 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
11341 cu
->producer_is_icc
= true;
11342 cu
->producer_is_icc_lt_14
= major
< 14;
11344 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
11345 cu
->producer_is_codewarrior
= true;
11346 else if (producer_is_clang (cu
->producer
, &major
, &minor
))
11347 cu
->producer_is_clang
= true;
11350 /* For other non-GCC compilers, expect their behavior is DWARF version
11354 cu
->checked_producer
= true;
11357 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
11358 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
11359 during 4.6.0 experimental. */
11362 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
11364 if (!cu
->checked_producer
)
11365 check_producer (cu
);
11367 return cu
->producer_is_gxx_lt_4_6
;
11371 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
11372 with incorrect is_stmt attributes. */
11375 producer_is_codewarrior (struct dwarf2_cu
*cu
)
11377 if (!cu
->checked_producer
)
11378 check_producer (cu
);
11380 return cu
->producer_is_codewarrior
;
11383 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
11384 If that attribute is not available, return the appropriate
11387 static enum dwarf_access_attribute
11388 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
11390 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11391 if (attr
!= nullptr)
11393 LONGEST value
= attr
->constant_value (-1);
11394 if (value
== DW_ACCESS_public
11395 || value
== DW_ACCESS_protected
11396 || value
== DW_ACCESS_private
)
11397 return (dwarf_access_attribute
) value
;
11398 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
11402 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
11404 /* The default DWARF 2 accessibility for members is public, the default
11405 accessibility for inheritance is private. */
11407 if (die
->tag
!= DW_TAG_inheritance
)
11408 return DW_ACCESS_public
;
11410 return DW_ACCESS_private
;
11414 /* DWARF 3+ defines the default accessibility a different way. The same
11415 rules apply now for DW_TAG_inheritance as for the members and it only
11416 depends on the container kind. */
11418 if (die
->parent
->tag
== DW_TAG_class_type
)
11419 return DW_ACCESS_private
;
11421 return DW_ACCESS_public
;
11425 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
11426 *OFFSET to the byte offset. If the attribute was not found return
11427 0, otherwise return 1. If it was found but could not properly be
11428 handled, set *OFFSET to 0. */
11431 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
11434 struct attribute
*attr
;
11436 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
11441 /* Note that we do not check for a section offset first here.
11442 This is because DW_AT_data_member_location is new in DWARF 4,
11443 so if we see it, we can assume that a constant form is really
11444 a constant and not a section offset. */
11445 if (attr
->form_is_constant ())
11446 *offset
= attr
->constant_value (0);
11447 else if (attr
->form_is_section_offset ())
11448 dwarf2_complex_location_expr_complaint ();
11449 else if (attr
->form_is_block ())
11450 *offset
= decode_locdesc (attr
->as_block (), cu
);
11452 dwarf2_complex_location_expr_complaint ();
11458 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
11459 if (attr
!= nullptr)
11461 *offset
= attr
->constant_value (0);
11469 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
11470 store the results in FIELD. */
11473 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
11474 struct field
*field
)
11476 struct attribute
*attr
;
11478 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
11481 if (attr
->form_is_constant ())
11483 LONGEST offset
= attr
->constant_value (0);
11485 /* Work around this GCC 11 bug, where it would erroneously use -1
11486 data member locations, instead of 0:
11488 Negative DW_AT_data_member_location
11489 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
11491 if (offset
== -1 && cu
->producer_is_gcc_11
)
11493 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
11497 field
->set_loc_bitpos (offset
* bits_per_byte
);
11499 else if (attr
->form_is_section_offset ())
11500 dwarf2_complex_location_expr_complaint ();
11501 else if (attr
->form_is_block ())
11504 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
11506 field
->set_loc_bitpos (offset
* bits_per_byte
);
11509 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11510 struct objfile
*objfile
= per_objfile
->objfile
;
11511 struct dwarf2_locexpr_baton
*dlbaton
11512 = XOBNEW (&objfile
->objfile_obstack
,
11513 struct dwarf2_locexpr_baton
);
11514 dlbaton
->data
= attr
->as_block ()->data
;
11515 dlbaton
->size
= attr
->as_block ()->size
;
11516 /* When using this baton, we want to compute the address
11517 of the field, not the value. This is why
11518 is_reference is set to false here. */
11519 dlbaton
->is_reference
= false;
11520 dlbaton
->per_objfile
= per_objfile
;
11521 dlbaton
->per_cu
= cu
->per_cu
;
11523 field
->set_loc_dwarf_block (dlbaton
);
11527 dwarf2_complex_location_expr_complaint ();
11531 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
11532 if (attr
!= nullptr)
11533 field
->set_loc_bitpos (attr
->constant_value (0));
11537 /* Add an aggregate field to the field list. */
11540 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
11541 struct dwarf2_cu
*cu
)
11543 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11544 struct gdbarch
*gdbarch
= objfile
->arch ();
11545 struct nextfield
*new_field
;
11546 struct attribute
*attr
;
11548 const char *fieldname
= "";
11550 if (die
->tag
== DW_TAG_inheritance
)
11552 fip
->baseclasses
.emplace_back ();
11553 new_field
= &fip
->baseclasses
.back ();
11557 fip
->fields
.emplace_back ();
11558 new_field
= &fip
->fields
.back ();
11561 new_field
->offset
= die
->sect_off
;
11563 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
11564 if (new_field
->accessibility
!= DW_ACCESS_public
)
11565 fip
->non_public_fields
= true;
11567 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11568 if (attr
!= nullptr)
11569 new_field
->virtuality
= attr
->as_virtuality ();
11571 new_field
->virtuality
= DW_VIRTUALITY_none
;
11573 fp
= &new_field
->field
;
11575 if ((die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_namelist_item
)
11576 && !die_is_declaration (die
, cu
))
11578 if (die
->tag
== DW_TAG_namelist_item
)
11580 /* Typically, DW_TAG_namelist_item are references to namelist items.
11581 If so, follow that reference. */
11582 struct attribute
*attr1
= dwarf2_attr (die
, DW_AT_namelist_item
, cu
);
11583 struct die_info
*item_die
= nullptr;
11584 struct dwarf2_cu
*item_cu
= cu
;
11585 if (attr1
->form_is_ref ())
11586 item_die
= follow_die_ref (die
, attr1
, &item_cu
);
11587 if (item_die
!= nullptr)
11590 /* Data member other than a C++ static data member. */
11592 /* Get type of field. */
11593 fp
->set_type (die_type (die
, cu
));
11595 fp
->set_loc_bitpos (0);
11597 /* Get bit size of field (zero if none). */
11598 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
11599 if (attr
!= nullptr)
11601 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
11605 FIELD_BITSIZE (*fp
) = 0;
11608 /* Get bit offset of field. */
11609 handle_member_location (die
, cu
, fp
);
11610 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
11611 if (attr
!= nullptr && attr
->form_is_constant ())
11613 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
11615 /* For big endian bits, the DW_AT_bit_offset gives the
11616 additional bit offset from the MSB of the containing
11617 anonymous object to the MSB of the field. We don't
11618 have to do anything special since we don't need to
11619 know the size of the anonymous object. */
11620 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
11624 /* For little endian bits, compute the bit offset to the
11625 MSB of the anonymous object, subtract off the number of
11626 bits from the MSB of the field to the MSB of the
11627 object, and then subtract off the number of bits of
11628 the field itself. The result is the bit offset of
11629 the LSB of the field. */
11630 int anonymous_size
;
11631 int bit_offset
= attr
->constant_value (0);
11633 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11634 if (attr
!= nullptr && attr
->form_is_constant ())
11636 /* The size of the anonymous object containing
11637 the bit field is explicit, so use the
11638 indicated size (in bytes). */
11639 anonymous_size
= attr
->constant_value (0);
11643 /* The size of the anonymous object containing
11644 the bit field must be inferred from the type
11645 attribute of the data member containing the
11647 anonymous_size
= fp
->type ()->length ();
11649 fp
->set_loc_bitpos (fp
->loc_bitpos ()
11650 + anonymous_size
* bits_per_byte
11651 - bit_offset
- FIELD_BITSIZE (*fp
));
11655 /* Get name of field. */
11656 fieldname
= dwarf2_name (die
, cu
);
11657 if (fieldname
== NULL
)
11660 /* The name is already allocated along with this objfile, so we don't
11661 need to duplicate it for the type. */
11662 fp
->set_name (fieldname
);
11664 /* Change accessibility for artificial fields (e.g. virtual table
11665 pointer or virtual base class pointer) to private. */
11666 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
11668 FIELD_ARTIFICIAL (*fp
) = 1;
11669 new_field
->accessibility
= DW_ACCESS_private
;
11670 fip
->non_public_fields
= true;
11673 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
11675 /* C++ static member. */
11677 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
11678 is a declaration, but all versions of G++ as of this writing
11679 (so through at least 3.2.1) incorrectly generate
11680 DW_TAG_variable tags. */
11682 const char *physname
;
11684 /* Get name of field. */
11685 fieldname
= dwarf2_name (die
, cu
);
11686 if (fieldname
== NULL
)
11689 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11691 /* Only create a symbol if this is an external value.
11692 new_symbol checks this and puts the value in the global symbol
11693 table, which we want. If it is not external, new_symbol
11694 will try to put the value in cu->list_in_scope which is wrong. */
11695 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
11697 /* A static const member, not much different than an enum as far as
11698 we're concerned, except that we can support more types. */
11699 new_symbol (die
, NULL
, cu
);
11702 /* Get physical name. */
11703 physname
= dwarf2_physname (fieldname
, die
, cu
);
11705 /* The name is already allocated along with this objfile, so we don't
11706 need to duplicate it for the type. */
11707 fp
->set_loc_physname (physname
? physname
: "");
11708 fp
->set_type (die_type (die
, cu
));
11709 fp
->set_name (fieldname
);
11711 else if (die
->tag
== DW_TAG_inheritance
)
11713 /* C++ base class field. */
11714 handle_member_location (die
, cu
, fp
);
11715 FIELD_BITSIZE (*fp
) = 0;
11716 fp
->set_type (die_type (die
, cu
));
11717 fp
->set_name (fp
->type ()->name ());
11720 gdb_assert_not_reached ("missing case in dwarf2_add_field");
11723 /* Can the type given by DIE define another type? */
11726 type_can_define_types (const struct die_info
*die
)
11730 case DW_TAG_typedef
:
11731 case DW_TAG_class_type
:
11732 case DW_TAG_structure_type
:
11733 case DW_TAG_union_type
:
11734 case DW_TAG_enumeration_type
:
11742 /* Add a type definition defined in the scope of the FIP's class. */
11745 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
11746 struct dwarf2_cu
*cu
)
11748 struct decl_field fp
;
11749 memset (&fp
, 0, sizeof (fp
));
11751 gdb_assert (type_can_define_types (die
));
11753 /* Get name of field. NULL is okay here, meaning an anonymous type. */
11754 fp
.name
= dwarf2_name (die
, cu
);
11755 fp
.type
= read_type_die (die
, cu
);
11757 /* Save accessibility. */
11758 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
11759 switch (accessibility
)
11761 case DW_ACCESS_public
:
11762 /* The assumed value if neither private nor protected. */
11764 case DW_ACCESS_private
:
11767 case DW_ACCESS_protected
:
11768 fp
.is_protected
= 1;
11772 if (die
->tag
== DW_TAG_typedef
)
11773 fip
->typedef_field_list
.push_back (fp
);
11775 fip
->nested_types_list
.push_back (fp
);
11778 /* A convenience typedef that's used when finding the discriminant
11779 field for a variant part. */
11780 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
11783 /* Compute the discriminant range for a given variant. OBSTACK is
11784 where the results will be stored. VARIANT is the variant to
11785 process. IS_UNSIGNED indicates whether the discriminant is signed
11788 static const gdb::array_view
<discriminant_range
>
11789 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
11792 std::vector
<discriminant_range
> ranges
;
11794 if (variant
.default_branch
)
11797 if (variant
.discr_list_data
== nullptr)
11799 discriminant_range r
11800 = {variant
.discriminant_value
, variant
.discriminant_value
};
11801 ranges
.push_back (r
);
11805 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
11806 variant
.discr_list_data
->size
);
11807 while (!data
.empty ())
11809 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
11811 complaint (_("invalid discriminant marker: %d"), data
[0]);
11814 bool is_range
= data
[0] == DW_DSC_range
;
11815 data
= data
.slice (1);
11817 ULONGEST low
, high
;
11818 unsigned int bytes_read
;
11822 complaint (_("DW_AT_discr_list missing low value"));
11826 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
11828 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
11830 data
= data
.slice (bytes_read
);
11836 complaint (_("DW_AT_discr_list missing high value"));
11840 high
= read_unsigned_leb128 (nullptr, data
.data (),
11843 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
11845 data
= data
.slice (bytes_read
);
11850 ranges
.push_back ({ low
, high
});
11854 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
11856 std::copy (ranges
.begin (), ranges
.end (), result
);
11857 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
11860 static const gdb::array_view
<variant_part
> create_variant_parts
11861 (struct obstack
*obstack
,
11862 const offset_map_type
&offset_map
,
11863 struct field_info
*fi
,
11864 const std::vector
<variant_part_builder
> &variant_parts
);
11866 /* Fill in a "struct variant" for a given variant field. RESULT is
11867 the variant to fill in. OBSTACK is where any needed allocations
11868 will be done. OFFSET_MAP holds the mapping from section offsets to
11869 fields for the type. FI describes the fields of the type we're
11870 processing. FIELD is the variant field we're converting. */
11873 create_one_variant (variant
&result
, struct obstack
*obstack
,
11874 const offset_map_type
&offset_map
,
11875 struct field_info
*fi
, const variant_field
&field
)
11877 result
.discriminants
= convert_variant_range (obstack
, field
, false);
11878 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
11879 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
11880 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
11881 field
.variant_parts
);
11884 /* Fill in a "struct variant_part" for a given variant part. RESULT
11885 is the variant part to fill in. OBSTACK is where any needed
11886 allocations will be done. OFFSET_MAP holds the mapping from
11887 section offsets to fields for the type. FI describes the fields of
11888 the type we're processing. BUILDER is the variant part to be
11892 create_one_variant_part (variant_part
&result
,
11893 struct obstack
*obstack
,
11894 const offset_map_type
&offset_map
,
11895 struct field_info
*fi
,
11896 const variant_part_builder
&builder
)
11898 auto iter
= offset_map
.find (builder
.discriminant_offset
);
11899 if (iter
== offset_map
.end ())
11901 result
.discriminant_index
= -1;
11902 /* Doesn't matter. */
11903 result
.is_unsigned
= false;
11907 result
.discriminant_index
= iter
->second
;
11909 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
11912 size_t n
= builder
.variants
.size ();
11913 variant
*output
= new (obstack
) variant
[n
];
11914 for (size_t i
= 0; i
< n
; ++i
)
11915 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
11916 builder
.variants
[i
]);
11918 result
.variants
= gdb::array_view
<variant
> (output
, n
);
11921 /* Create a vector of variant parts that can be attached to a type.
11922 OBSTACK is where any needed allocations will be done. OFFSET_MAP
11923 holds the mapping from section offsets to fields for the type. FI
11924 describes the fields of the type we're processing. VARIANT_PARTS
11925 is the vector to convert. */
11927 static const gdb::array_view
<variant_part
>
11928 create_variant_parts (struct obstack
*obstack
,
11929 const offset_map_type
&offset_map
,
11930 struct field_info
*fi
,
11931 const std::vector
<variant_part_builder
> &variant_parts
)
11933 if (variant_parts
.empty ())
11936 size_t n
= variant_parts
.size ();
11937 variant_part
*result
= new (obstack
) variant_part
[n
];
11938 for (size_t i
= 0; i
< n
; ++i
)
11939 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
11942 return gdb::array_view
<variant_part
> (result
, n
);
11945 /* Compute the variant part vector for FIP, attaching it to TYPE when
11949 add_variant_property (struct field_info
*fip
, struct type
*type
,
11950 struct dwarf2_cu
*cu
)
11952 /* Map section offsets of fields to their field index. Note the
11953 field index here does not take the number of baseclasses into
11955 offset_map_type offset_map
;
11956 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
11957 offset_map
[fip
->fields
[i
].offset
] = i
;
11959 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11960 gdb::array_view
<const variant_part
> parts
11961 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
11962 fip
->variant_parts
);
11964 struct dynamic_prop prop
;
11965 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
11966 obstack_copy (&objfile
->objfile_obstack
, &parts
,
11969 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
11972 /* Create the vector of fields, and attach it to the type. */
11975 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
11976 struct dwarf2_cu
*cu
)
11978 int nfields
= fip
->nfields ();
11980 /* Record the field count, allocate space for the array of fields,
11981 and create blank accessibility bitfields if necessary. */
11982 type
->set_num_fields (nfields
);
11984 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
11986 if (fip
->non_public_fields
&& cu
->lang () != language_ada
)
11988 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11990 TYPE_FIELD_PRIVATE_BITS (type
) =
11991 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
11992 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
11994 TYPE_FIELD_PROTECTED_BITS (type
) =
11995 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
11996 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
11998 TYPE_FIELD_IGNORE_BITS (type
) =
11999 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12000 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12003 /* If the type has baseclasses, allocate and clear a bit vector for
12004 TYPE_FIELD_VIRTUAL_BITS. */
12005 if (!fip
->baseclasses
.empty () && cu
->lang () != language_ada
)
12007 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
12008 unsigned char *pointer
;
12010 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12011 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
12012 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12013 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
12014 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
12017 if (!fip
->variant_parts
.empty ())
12018 add_variant_property (fip
, type
, cu
);
12020 /* Copy the saved-up fields into the field vector. */
12021 for (int i
= 0; i
< nfields
; ++i
)
12023 struct nextfield
&field
12024 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
12025 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
12027 type
->field (i
) = field
.field
;
12028 switch (field
.accessibility
)
12030 case DW_ACCESS_private
:
12031 if (cu
->lang () != language_ada
)
12032 SET_TYPE_FIELD_PRIVATE (type
, i
);
12035 case DW_ACCESS_protected
:
12036 if (cu
->lang () != language_ada
)
12037 SET_TYPE_FIELD_PROTECTED (type
, i
);
12040 case DW_ACCESS_public
:
12044 /* Unknown accessibility. Complain and treat it as public. */
12046 complaint (_("unsupported accessibility %d"),
12047 field
.accessibility
);
12051 if (i
< fip
->baseclasses
.size ())
12053 switch (field
.virtuality
)
12055 case DW_VIRTUALITY_virtual
:
12056 case DW_VIRTUALITY_pure_virtual
:
12057 if (cu
->lang () == language_ada
)
12058 error (_("unexpected virtuality in component of Ada type"));
12059 SET_TYPE_FIELD_VIRTUAL (type
, i
);
12066 /* Return true if this member function is a constructor, false
12070 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12072 const char *fieldname
;
12073 const char *type_name
;
12076 if (die
->parent
== NULL
)
12079 if (die
->parent
->tag
!= DW_TAG_structure_type
12080 && die
->parent
->tag
!= DW_TAG_union_type
12081 && die
->parent
->tag
!= DW_TAG_class_type
)
12084 fieldname
= dwarf2_name (die
, cu
);
12085 type_name
= dwarf2_name (die
->parent
, cu
);
12086 if (fieldname
== NULL
|| type_name
== NULL
)
12089 len
= strlen (fieldname
);
12090 return (strncmp (fieldname
, type_name
, len
) == 0
12091 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
12094 /* Add a member function to the proper fieldlist. */
12097 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
12098 struct type
*type
, struct dwarf2_cu
*cu
)
12100 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12101 struct attribute
*attr
;
12103 struct fnfieldlist
*flp
= nullptr;
12104 struct fn_field
*fnp
;
12105 const char *fieldname
;
12106 struct type
*this_type
;
12108 if (cu
->lang () == language_ada
)
12109 error (_("unexpected member function in Ada type"));
12111 /* Get name of member function. */
12112 fieldname
= dwarf2_name (die
, cu
);
12113 if (fieldname
== NULL
)
12116 /* Look up member function name in fieldlist. */
12117 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
12119 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
12121 flp
= &fip
->fnfieldlists
[i
];
12126 /* Create a new fnfieldlist if necessary. */
12127 if (flp
== nullptr)
12129 fip
->fnfieldlists
.emplace_back ();
12130 flp
= &fip
->fnfieldlists
.back ();
12131 flp
->name
= fieldname
;
12132 i
= fip
->fnfieldlists
.size () - 1;
12135 /* Create a new member function field and add it to the vector of
12137 flp
->fnfields
.emplace_back ();
12138 fnp
= &flp
->fnfields
.back ();
12140 /* Delay processing of the physname until later. */
12141 if (cu
->lang () == language_cplus
)
12142 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
12146 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
12147 fnp
->physname
= physname
? physname
: "";
12150 fnp
->type
= alloc_type (objfile
);
12151 this_type
= read_type_die (die
, cu
);
12152 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
12154 int nparams
= this_type
->num_fields ();
12156 /* TYPE is the domain of this method, and THIS_TYPE is the type
12157 of the method itself (TYPE_CODE_METHOD). */
12158 smash_to_method_type (fnp
->type
, type
,
12159 this_type
->target_type (),
12160 this_type
->fields (),
12161 this_type
->num_fields (),
12162 this_type
->has_varargs ());
12164 /* Handle static member functions.
12165 Dwarf2 has no clean way to discern C++ static and non-static
12166 member functions. G++ helps GDB by marking the first
12167 parameter for non-static member functions (which is the this
12168 pointer) as artificial. We obtain this information from
12169 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12170 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
12171 fnp
->voffset
= VOFFSET_STATIC
;
12174 complaint (_("member function type missing for '%s'"),
12175 dwarf2_full_name (fieldname
, die
, cu
));
12177 /* Get fcontext from DW_AT_containing_type if present. */
12178 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12179 fnp
->fcontext
= die_containing_type (die
, cu
);
12181 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12182 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12184 /* Get accessibility. */
12185 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
12186 switch (accessibility
)
12188 case DW_ACCESS_private
:
12189 fnp
->is_private
= 1;
12191 case DW_ACCESS_protected
:
12192 fnp
->is_protected
= 1;
12196 /* Check for artificial methods. */
12197 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
12198 if (attr
&& attr
->as_boolean ())
12199 fnp
->is_artificial
= 1;
12201 /* Check for defaulted methods. */
12202 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
12203 if (attr
!= nullptr)
12204 fnp
->defaulted
= attr
->defaulted ();
12206 /* Check for deleted methods. */
12207 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
12208 if (attr
!= nullptr && attr
->as_boolean ())
12209 fnp
->is_deleted
= 1;
12211 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
12213 /* Get index in virtual function table if it is a virtual member
12214 function. For older versions of GCC, this is an offset in the
12215 appropriate virtual table, as specified by DW_AT_containing_type.
12216 For everyone else, it is an expression to be evaluated relative
12217 to the object address. */
12219 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
12220 if (attr
!= nullptr)
12222 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
12224 struct dwarf_block
*block
= attr
->as_block ();
12226 if (block
->data
[0] == DW_OP_constu
)
12228 /* Old-style GCC. */
12229 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
12231 else if (block
->data
[0] == DW_OP_deref
12232 || (block
->size
> 1
12233 && block
->data
[0] == DW_OP_deref_size
12234 && block
->data
[1] == cu
->header
.addr_size
))
12236 fnp
->voffset
= decode_locdesc (block
, cu
);
12237 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
12238 dwarf2_complex_location_expr_complaint ();
12240 fnp
->voffset
/= cu
->header
.addr_size
;
12244 dwarf2_complex_location_expr_complaint ();
12246 if (!fnp
->fcontext
)
12248 /* If there is no `this' field and no DW_AT_containing_type,
12249 we cannot actually find a base class context for the
12251 if (this_type
->num_fields () == 0
12252 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
12254 complaint (_("cannot determine context for virtual member "
12255 "function \"%s\" (offset %s)"),
12256 fieldname
, sect_offset_str (die
->sect_off
));
12260 fnp
->fcontext
= this_type
->field (0).type ()->target_type ();
12264 else if (attr
->form_is_section_offset ())
12266 dwarf2_complex_location_expr_complaint ();
12270 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
12276 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12277 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
12279 /* GCC does this, as of 2008-08-25; PR debug/37237. */
12280 complaint (_("Member function \"%s\" (offset %s) is virtual "
12281 "but the vtable offset is not specified"),
12282 fieldname
, sect_offset_str (die
->sect_off
));
12283 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12284 TYPE_CPLUS_DYNAMIC (type
) = 1;
12289 /* Create the vector of member function fields, and attach it to the type. */
12292 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
12293 struct dwarf2_cu
*cu
)
12295 if (cu
->lang () == language_ada
)
12296 error (_("unexpected member functions in Ada type"));
12298 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12299 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
12301 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
12303 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
12305 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
12306 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
12308 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
12309 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
12310 fn_flp
->fn_fields
= (struct fn_field
*)
12311 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
12313 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
12314 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
12317 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
12320 /* Returns non-zero if NAME is the name of a vtable member in CU's
12321 language, zero otherwise. */
12323 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
12325 static const char vptr
[] = "_vptr";
12327 /* Look for the C++ form of the vtable. */
12328 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
12334 /* GCC outputs unnamed structures that are really pointers to member
12335 functions, with the ABI-specified layout. If TYPE describes
12336 such a structure, smash it into a member function type.
12338 GCC shouldn't do this; it should just output pointer to member DIEs.
12339 This is GCC PR debug/28767. */
12342 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
12344 struct type
*pfn_type
, *self_type
, *new_type
;
12346 /* Check for a structure with no name and two children. */
12347 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
12350 /* Check for __pfn and __delta members. */
12351 if (type
->field (0).name () == NULL
12352 || strcmp (type
->field (0).name (), "__pfn") != 0
12353 || type
->field (1).name () == NULL
12354 || strcmp (type
->field (1).name (), "__delta") != 0)
12357 /* Find the type of the method. */
12358 pfn_type
= type
->field (0).type ();
12359 if (pfn_type
== NULL
12360 || pfn_type
->code () != TYPE_CODE_PTR
12361 || pfn_type
->target_type ()->code () != TYPE_CODE_FUNC
)
12364 /* Look for the "this" argument. */
12365 pfn_type
= pfn_type
->target_type ();
12366 if (pfn_type
->num_fields () == 0
12367 /* || pfn_type->field (0).type () == NULL */
12368 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
12371 self_type
= pfn_type
->field (0).type ()->target_type ();
12372 new_type
= alloc_type (objfile
);
12373 smash_to_method_type (new_type
, self_type
, pfn_type
->target_type (),
12374 pfn_type
->fields (), pfn_type
->num_fields (),
12375 pfn_type
->has_varargs ());
12376 smash_to_methodptr_type (type
, new_type
);
12379 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
12380 requires rewriting, then copy it and return the updated copy.
12381 Otherwise return nullptr. */
12383 static struct type
*
12384 rewrite_array_type (struct type
*type
)
12386 if (type
->code () != TYPE_CODE_ARRAY
)
12389 struct type
*index_type
= type
->index_type ();
12390 range_bounds
*current_bounds
= index_type
->bounds ();
12392 /* Handle multi-dimensional arrays. */
12393 struct type
*new_target
= rewrite_array_type (type
->target_type ());
12394 if (new_target
== nullptr)
12396 /* Maybe we don't need to rewrite this array. */
12397 if (current_bounds
->low
.kind () == PROP_CONST
12398 && current_bounds
->high
.kind () == PROP_CONST
)
12402 /* Either the target type was rewritten, or the bounds have to be
12403 updated. Either way we want to copy the type and update
12405 struct type
*copy
= copy_type (type
);
12406 int nfields
= copy
->num_fields ();
12408 = ((struct field
*) TYPE_ZALLOC (copy
,
12409 nfields
* sizeof (struct field
)));
12410 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
12411 copy
->set_fields (new_fields
);
12412 if (new_target
!= nullptr)
12413 copy
->set_target_type (new_target
);
12415 struct type
*index_copy
= copy_type (index_type
);
12416 range_bounds
*bounds
12417 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
12418 sizeof (range_bounds
));
12419 *bounds
= *current_bounds
;
12420 bounds
->low
.set_const_val (1);
12421 bounds
->high
.set_const_val (0);
12422 index_copy
->set_bounds (bounds
);
12423 copy
->set_index_type (index_copy
);
12428 /* While some versions of GCC will generate complicated DWARF for an
12429 array (see quirk_ada_thick_pointer), more recent versions were
12430 modified to emit an explicit thick pointer structure. However, in
12431 this case, the array still has DWARF expressions for its ranges,
12432 and these must be ignored. */
12435 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
12438 gdb_assert (cu
->lang () == language_ada
);
12440 /* Check for a structure with two children. */
12441 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
12444 /* Check for P_ARRAY and P_BOUNDS members. */
12445 if (type
->field (0).name () == NULL
12446 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
12447 || type
->field (1).name () == NULL
12448 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
12451 /* Make sure we're looking at a pointer to an array. */
12452 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
12455 /* The Ada code already knows how to handle these types, so all that
12456 we need to do is turn the bounds into static bounds. However, we
12457 don't want to rewrite existing array or index types in-place,
12458 because those may be referenced in other contexts where this
12459 rewriting is undesirable. */
12460 struct type
*new_ary_type
12461 = rewrite_array_type (type
->field (0).type ()->target_type ());
12462 if (new_ary_type
!= nullptr)
12463 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
12466 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
12467 appropriate error checking and issuing complaints if there is a
12471 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
12473 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
12475 if (attr
== nullptr)
12478 if (!attr
->form_is_constant ())
12480 complaint (_("DW_AT_alignment must have constant form"
12481 " - DIE at %s [in module %s]"),
12482 sect_offset_str (die
->sect_off
),
12483 objfile_name (cu
->per_objfile
->objfile
));
12487 LONGEST val
= attr
->constant_value (0);
12490 complaint (_("DW_AT_alignment value must not be negative"
12491 " - DIE at %s [in module %s]"),
12492 sect_offset_str (die
->sect_off
),
12493 objfile_name (cu
->per_objfile
->objfile
));
12496 ULONGEST align
= val
;
12500 complaint (_("DW_AT_alignment value must not be zero"
12501 " - DIE at %s [in module %s]"),
12502 sect_offset_str (die
->sect_off
),
12503 objfile_name (cu
->per_objfile
->objfile
));
12506 if ((align
& (align
- 1)) != 0)
12508 complaint (_("DW_AT_alignment value must be a power of 2"
12509 " - DIE at %s [in module %s]"),
12510 sect_offset_str (die
->sect_off
),
12511 objfile_name (cu
->per_objfile
->objfile
));
12518 /* If the DIE has a DW_AT_alignment attribute, use its value to set
12519 the alignment for TYPE. */
12522 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
12525 if (!set_type_align (type
, get_alignment (cu
, die
)))
12526 complaint (_("DW_AT_alignment value too large"
12527 " - DIE at %s [in module %s]"),
12528 sect_offset_str (die
->sect_off
),
12529 objfile_name (cu
->per_objfile
->objfile
));
12532 /* Check if the given VALUE is a valid enum dwarf_calling_convention
12533 constant for a type, according to DWARF5 spec, Table 5.5. */
12536 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
12541 case DW_CC_pass_by_reference
:
12542 case DW_CC_pass_by_value
:
12546 complaint (_("unrecognized DW_AT_calling_convention value "
12547 "(%s) for a type"), pulongest (value
));
12552 /* Check if the given VALUE is a valid enum dwarf_calling_convention
12553 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
12554 also according to GNU-specific values (see include/dwarf2.h). */
12557 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
12562 case DW_CC_program
:
12566 case DW_CC_GNU_renesas_sh
:
12567 case DW_CC_GNU_borland_fastcall_i386
:
12568 case DW_CC_GDB_IBM_OpenCL
:
12572 complaint (_("unrecognized DW_AT_calling_convention value "
12573 "(%s) for a subroutine"), pulongest (value
));
12578 /* Called when we find the DIE that starts a structure or union scope
12579 (definition) to create a type for the structure or union. Fill in
12580 the type's name and general properties; the members will not be
12581 processed until process_structure_scope. A symbol table entry for
12582 the type will also not be done until process_structure_scope (assuming
12583 the type has a name).
12585 NOTE: we need to call these functions regardless of whether or not the
12586 DIE has a DW_AT_name attribute, since it might be an anonymous
12587 structure or union. This gets the type entered into our set of
12588 user defined types. */
12590 static struct type
*
12591 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12593 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12595 struct attribute
*attr
;
12598 /* If the definition of this type lives in .debug_types, read that type.
12599 Don't follow DW_AT_specification though, that will take us back up
12600 the chain and we want to go down. */
12601 attr
= die
->attr (DW_AT_signature
);
12602 if (attr
!= nullptr)
12604 type
= get_DW_AT_signature_type (die
, attr
, cu
);
12606 /* The type's CU may not be the same as CU.
12607 Ensure TYPE is recorded with CU in die_type_hash. */
12608 return set_die_type (die
, type
, cu
);
12611 type
= alloc_type (objfile
);
12612 INIT_CPLUS_SPECIFIC (type
);
12614 name
= dwarf2_name (die
, cu
);
12617 if (cu
->lang () == language_cplus
12618 || cu
->lang () == language_d
12619 || cu
->lang () == language_rust
)
12621 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
12623 /* dwarf2_full_name might have already finished building the DIE's
12624 type. If so, there is no need to continue. */
12625 if (get_die_type (die
, cu
) != NULL
)
12626 return get_die_type (die
, cu
);
12628 type
->set_name (full_name
);
12632 /* The name is already allocated along with this objfile, so
12633 we don't need to duplicate it for the type. */
12634 type
->set_name (name
);
12638 if (die
->tag
== DW_TAG_structure_type
)
12640 type
->set_code (TYPE_CODE_STRUCT
);
12642 else if (die
->tag
== DW_TAG_union_type
)
12644 type
->set_code (TYPE_CODE_UNION
);
12646 else if (die
->tag
== DW_TAG_namelist
)
12648 type
->set_code (TYPE_CODE_NAMELIST
);
12652 type
->set_code (TYPE_CODE_STRUCT
);
12655 if (cu
->lang () == language_cplus
&& die
->tag
== DW_TAG_class_type
)
12656 type
->set_is_declared_class (true);
12658 /* Store the calling convention in the type if it's available in
12659 the die. Otherwise the calling convention remains set to
12660 the default value DW_CC_normal. */
12661 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12662 if (attr
!= nullptr
12663 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
12665 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12666 TYPE_CPLUS_CALLING_CONVENTION (type
)
12667 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
12670 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12671 if (attr
!= nullptr)
12673 if (attr
->form_is_constant ())
12674 type
->set_length (attr
->constant_value (0));
12677 struct dynamic_prop prop
;
12678 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
12679 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
12681 type
->set_length (0);
12685 type
->set_length (0);
12687 maybe_set_alignment (cu
, die
, type
);
12689 if (producer_is_icc_lt_14 (cu
) && (type
->length () == 0))
12691 /* ICC<14 does not output the required DW_AT_declaration on
12692 incomplete types, but gives them a size of zero. */
12693 type
->set_is_stub (true);
12696 type
->set_stub_is_supported (true);
12698 if (die_is_declaration (die
, cu
))
12699 type
->set_is_stub (true);
12700 else if (attr
== NULL
&& die
->child
== NULL
12701 && producer_is_realview (cu
->producer
))
12702 /* RealView does not output the required DW_AT_declaration
12703 on incomplete types. */
12704 type
->set_is_stub (true);
12706 /* We need to add the type field to the die immediately so we don't
12707 infinitely recurse when dealing with pointers to the structure
12708 type within the structure itself. */
12709 set_die_type (die
, type
, cu
);
12711 /* set_die_type should be already done. */
12712 set_descriptive_type (type
, die
, cu
);
12717 static void handle_struct_member_die
12718 (struct die_info
*child_die
,
12720 struct field_info
*fi
,
12721 std::vector
<struct symbol
*> *template_args
,
12722 struct dwarf2_cu
*cu
);
12724 /* A helper for handle_struct_member_die that handles
12725 DW_TAG_variant_part. */
12728 handle_variant_part (struct die_info
*die
, struct type
*type
,
12729 struct field_info
*fi
,
12730 std::vector
<struct symbol
*> *template_args
,
12731 struct dwarf2_cu
*cu
)
12733 variant_part_builder
*new_part
;
12734 if (fi
->current_variant_part
== nullptr)
12736 fi
->variant_parts
.emplace_back ();
12737 new_part
= &fi
->variant_parts
.back ();
12739 else if (!fi
->current_variant_part
->processing_variant
)
12741 complaint (_("nested DW_TAG_variant_part seen "
12742 "- DIE at %s [in module %s]"),
12743 sect_offset_str (die
->sect_off
),
12744 objfile_name (cu
->per_objfile
->objfile
));
12749 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
12750 current
.variant_parts
.emplace_back ();
12751 new_part
= ¤t
.variant_parts
.back ();
12754 /* When we recurse, we want callees to add to this new variant
12756 scoped_restore save_current_variant_part
12757 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
12759 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
12762 /* It's a univariant form, an extension we support. */
12764 else if (discr
->form_is_ref ())
12766 struct dwarf2_cu
*target_cu
= cu
;
12767 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
12769 new_part
->discriminant_offset
= target_die
->sect_off
;
12773 complaint (_("DW_AT_discr does not have DIE reference form"
12774 " - DIE at %s [in module %s]"),
12775 sect_offset_str (die
->sect_off
),
12776 objfile_name (cu
->per_objfile
->objfile
));
12779 for (die_info
*child_die
= die
->child
;
12781 child_die
= child_die
->sibling
)
12782 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
12785 /* A helper for handle_struct_member_die that handles
12789 handle_variant (struct die_info
*die
, struct type
*type
,
12790 struct field_info
*fi
,
12791 std::vector
<struct symbol
*> *template_args
,
12792 struct dwarf2_cu
*cu
)
12794 if (fi
->current_variant_part
== nullptr)
12796 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
12797 "- DIE at %s [in module %s]"),
12798 sect_offset_str (die
->sect_off
),
12799 objfile_name (cu
->per_objfile
->objfile
));
12802 if (fi
->current_variant_part
->processing_variant
)
12804 complaint (_("nested DW_TAG_variant seen "
12805 "- DIE at %s [in module %s]"),
12806 sect_offset_str (die
->sect_off
),
12807 objfile_name (cu
->per_objfile
->objfile
));
12811 scoped_restore save_processing_variant
12812 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
12815 fi
->current_variant_part
->variants
.emplace_back ();
12816 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
12817 variant
.first_field
= fi
->fields
.size ();
12819 /* In a variant we want to get the discriminant and also add a
12820 field for our sole member child. */
12821 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
12822 if (discr
== nullptr || !discr
->form_is_constant ())
12824 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
12825 if (discr
== nullptr || discr
->as_block ()->size
== 0)
12826 variant
.default_branch
= true;
12828 variant
.discr_list_data
= discr
->as_block ();
12831 variant
.discriminant_value
= discr
->constant_value (0);
12833 for (die_info
*variant_child
= die
->child
;
12834 variant_child
!= NULL
;
12835 variant_child
= variant_child
->sibling
)
12836 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
12838 variant
.last_field
= fi
->fields
.size ();
12841 /* A helper for process_structure_scope that handles a single member
12845 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
12846 struct field_info
*fi
,
12847 std::vector
<struct symbol
*> *template_args
,
12848 struct dwarf2_cu
*cu
)
12850 if (child_die
->tag
== DW_TAG_member
12851 || child_die
->tag
== DW_TAG_variable
12852 || child_die
->tag
== DW_TAG_namelist_item
)
12854 /* NOTE: carlton/2002-11-05: A C++ static data member
12855 should be a DW_TAG_member that is a declaration, but
12856 all versions of G++ as of this writing (so through at
12857 least 3.2.1) incorrectly generate DW_TAG_variable
12858 tags for them instead. */
12859 dwarf2_add_field (fi
, child_die
, cu
);
12861 else if (child_die
->tag
== DW_TAG_subprogram
)
12863 /* Rust doesn't have member functions in the C++ sense.
12864 However, it does emit ordinary functions as children
12865 of a struct DIE. */
12866 if (cu
->lang () == language_rust
)
12867 read_func_scope (child_die
, cu
);
12870 /* C++ member function. */
12871 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
12874 else if (child_die
->tag
== DW_TAG_inheritance
)
12876 /* C++ base class field. */
12877 dwarf2_add_field (fi
, child_die
, cu
);
12879 else if (type_can_define_types (child_die
))
12880 dwarf2_add_type_defn (fi
, child_die
, cu
);
12881 else if (child_die
->tag
== DW_TAG_template_type_param
12882 || child_die
->tag
== DW_TAG_template_value_param
)
12884 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12887 template_args
->push_back (arg
);
12889 else if (child_die
->tag
== DW_TAG_variant_part
)
12890 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
12891 else if (child_die
->tag
== DW_TAG_variant
)
12892 handle_variant (child_die
, type
, fi
, template_args
, cu
);
12895 /* Finish creating a structure or union type, including filling in its
12896 members and creating a symbol for it. This function also handles Fortran
12897 namelist variables, their items or members and creating a symbol for
12901 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12903 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12904 struct die_info
*child_die
;
12907 type
= get_die_type (die
, cu
);
12909 type
= read_structure_type (die
, cu
);
12911 bool has_template_parameters
= false;
12912 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
12914 struct field_info fi
;
12915 std::vector
<struct symbol
*> template_args
;
12917 child_die
= die
->child
;
12919 while (child_die
&& child_die
->tag
)
12921 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
12922 child_die
= child_die
->sibling
;
12925 /* Attach template arguments to type. */
12926 if (!template_args
.empty ())
12928 has_template_parameters
= true;
12929 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12930 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
12931 TYPE_TEMPLATE_ARGUMENTS (type
)
12932 = XOBNEWVEC (&objfile
->objfile_obstack
,
12934 TYPE_N_TEMPLATE_ARGUMENTS (type
));
12935 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
12936 template_args
.data (),
12937 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
12938 * sizeof (struct symbol
*)));
12941 /* Attach fields and member functions to the type. */
12942 if (fi
.nfields () > 0)
12943 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
12944 if (!fi
.fnfieldlists
.empty ())
12946 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
12948 /* Get the type which refers to the base class (possibly this
12949 class itself) which contains the vtable pointer for the current
12950 class from the DW_AT_containing_type attribute. This use of
12951 DW_AT_containing_type is a GNU extension. */
12953 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12955 struct type
*t
= die_containing_type (die
, cu
);
12957 set_type_vptr_basetype (type
, t
);
12962 /* Our own class provides vtbl ptr. */
12963 for (i
= t
->num_fields () - 1;
12964 i
>= TYPE_N_BASECLASSES (t
);
12967 const char *fieldname
= t
->field (i
).name ();
12969 if (is_vtable_name (fieldname
, cu
))
12971 set_type_vptr_fieldno (type
, i
);
12976 /* Complain if virtual function table field not found. */
12977 if (i
< TYPE_N_BASECLASSES (t
))
12978 complaint (_("virtual function table pointer "
12979 "not found when defining class '%s'"),
12980 type
->name () ? type
->name () : "");
12984 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
12987 else if (cu
->producer
12988 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
12990 /* The IBM XLC compiler does not provide direct indication
12991 of the containing type, but the vtable pointer is
12992 always named __vfp. */
12996 for (i
= type
->num_fields () - 1;
12997 i
>= TYPE_N_BASECLASSES (type
);
13000 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
13002 set_type_vptr_fieldno (type
, i
);
13003 set_type_vptr_basetype (type
, type
);
13010 /* Copy fi.typedef_field_list linked list elements content into the
13011 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13012 if (!fi
.typedef_field_list
.empty ())
13014 int count
= fi
.typedef_field_list
.size ();
13016 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13017 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13018 = ((struct decl_field
*)
13020 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
13021 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
13023 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
13024 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
13027 /* Copy fi.nested_types_list linked list elements content into the
13028 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
13029 if (!fi
.nested_types_list
.empty ()
13030 && cu
->lang () != language_ada
)
13032 int count
= fi
.nested_types_list
.size ();
13034 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13035 TYPE_NESTED_TYPES_ARRAY (type
)
13036 = ((struct decl_field
*)
13037 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
13038 TYPE_NESTED_TYPES_COUNT (type
) = count
;
13040 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
13041 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
13045 quirk_gcc_member_function_pointer (type
, objfile
);
13046 if (cu
->lang () == language_rust
&& die
->tag
== DW_TAG_union_type
)
13047 cu
->rust_unions
.push_back (type
);
13048 else if (cu
->lang () == language_ada
)
13049 quirk_ada_thick_pointer_struct (die
, cu
, type
);
13051 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13052 snapshots) has been known to create a die giving a declaration
13053 for a class that has, as a child, a die giving a definition for a
13054 nested class. So we have to process our children even if the
13055 current die is a declaration. Normally, of course, a declaration
13056 won't have any children at all. */
13058 child_die
= die
->child
;
13060 while (child_die
!= NULL
&& child_die
->tag
)
13062 if (child_die
->tag
== DW_TAG_member
13063 || child_die
->tag
== DW_TAG_variable
13064 || child_die
->tag
== DW_TAG_inheritance
13065 || child_die
->tag
== DW_TAG_template_value_param
13066 || child_die
->tag
== DW_TAG_template_type_param
)
13071 process_die (child_die
, cu
);
13073 child_die
= child_die
->sibling
;
13076 /* Do not consider external references. According to the DWARF standard,
13077 these DIEs are identified by the fact that they have no byte_size
13078 attribute, and a declaration attribute. */
13079 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13080 || !die_is_declaration (die
, cu
)
13081 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
13083 struct symbol
*sym
= new_symbol (die
, type
, cu
);
13085 if (has_template_parameters
)
13087 struct symtab
*symtab
;
13088 if (sym
!= nullptr)
13089 symtab
= sym
->symtab ();
13090 else if (cu
->line_header
!= nullptr)
13092 /* Any related symtab will do. */
13094 = cu
->line_header
->file_names ()[0].symtab
;
13099 complaint (_("could not find suitable "
13100 "symtab for template parameter"
13101 " - DIE at %s [in module %s]"),
13102 sect_offset_str (die
->sect_off
),
13103 objfile_name (objfile
));
13106 if (symtab
!= nullptr)
13108 /* Make sure that the symtab is set on the new symbols.
13109 Even though they don't appear in this symtab directly,
13110 other parts of gdb assume that symbols do, and this is
13111 reasonably true. */
13112 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
13113 TYPE_TEMPLATE_ARGUMENT (type
, i
)->set_symtab (symtab
);
13119 /* Assuming DIE is an enumeration type, and TYPE is its associated
13120 type, update TYPE using some information only available in DIE's
13121 children. In particular, the fields are computed. */
13124 update_enumeration_type_from_children (struct die_info
*die
,
13126 struct dwarf2_cu
*cu
)
13128 struct die_info
*child_die
;
13129 int unsigned_enum
= 1;
13132 auto_obstack obstack
;
13133 std::vector
<struct field
> fields
;
13135 for (child_die
= die
->child
;
13136 child_die
!= NULL
&& child_die
->tag
;
13137 child_die
= child_die
->sibling
)
13139 struct attribute
*attr
;
13141 const gdb_byte
*bytes
;
13142 struct dwarf2_locexpr_baton
*baton
;
13145 if (child_die
->tag
!= DW_TAG_enumerator
)
13148 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13152 name
= dwarf2_name (child_die
, cu
);
13154 name
= "<anonymous enumerator>";
13156 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13157 &value
, &bytes
, &baton
);
13165 if (count_one_bits_ll (value
) >= 2)
13169 fields
.emplace_back ();
13170 struct field
&field
= fields
.back ();
13171 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
13172 field
.set_loc_enumval (value
);
13175 if (!fields
.empty ())
13177 type
->set_num_fields (fields
.size ());
13180 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
13181 memcpy (type
->fields (), fields
.data (),
13182 sizeof (struct field
) * fields
.size ());
13188 type
->set_is_unsigned (true);
13191 type
->set_is_flag_enum (true);
13194 /* Given a DW_AT_enumeration_type die, set its type. We do not
13195 complete the type's fields yet, or create any symbols. */
13197 static struct type
*
13198 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13200 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13202 struct attribute
*attr
;
13205 /* If the definition of this type lives in .debug_types, read that type.
13206 Don't follow DW_AT_specification though, that will take us back up
13207 the chain and we want to go down. */
13208 attr
= die
->attr (DW_AT_signature
);
13209 if (attr
!= nullptr)
13211 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13213 /* The type's CU may not be the same as CU.
13214 Ensure TYPE is recorded with CU in die_type_hash. */
13215 return set_die_type (die
, type
, cu
);
13218 type
= alloc_type (objfile
);
13220 type
->set_code (TYPE_CODE_ENUM
);
13221 name
= dwarf2_full_name (NULL
, die
, cu
);
13223 type
->set_name (name
);
13225 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13228 struct type
*underlying_type
= die_type (die
, cu
);
13230 type
->set_target_type (underlying_type
);
13233 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13234 if (attr
!= nullptr)
13235 type
->set_length (attr
->constant_value (0));
13237 type
->set_length (0);
13239 maybe_set_alignment (cu
, die
, type
);
13241 /* The enumeration DIE can be incomplete. In Ada, any type can be
13242 declared as private in the package spec, and then defined only
13243 inside the package body. Such types are known as Taft Amendment
13244 Types. When another package uses such a type, an incomplete DIE
13245 may be generated by the compiler. */
13246 if (die_is_declaration (die
, cu
))
13247 type
->set_is_stub (true);
13249 /* If this type has an underlying type that is not a stub, then we
13250 may use its attributes. We always use the "unsigned" attribute
13251 in this situation, because ordinarily we guess whether the type
13252 is unsigned -- but the guess can be wrong and the underlying type
13253 can tell us the reality. However, we defer to a local size
13254 attribute if one exists, because this lets the compiler override
13255 the underlying type if needed. */
13256 if (type
->target_type () != NULL
&& !type
->target_type ()->is_stub ())
13258 struct type
*underlying_type
= type
->target_type ();
13259 underlying_type
= check_typedef (underlying_type
);
13261 type
->set_is_unsigned (underlying_type
->is_unsigned ());
13263 if (type
->length () == 0)
13264 type
->set_length (underlying_type
->length ());
13266 if (TYPE_RAW_ALIGN (type
) == 0
13267 && TYPE_RAW_ALIGN (underlying_type
) != 0)
13268 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
13271 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
13273 set_die_type (die
, type
, cu
);
13275 /* Finish the creation of this type by using the enum's children.
13276 Note that, as usual, this must come after set_die_type to avoid
13277 infinite recursion when trying to compute the names of the
13279 update_enumeration_type_from_children (die
, type
, cu
);
13284 /* Given a pointer to a die which begins an enumeration, process all
13285 the dies that define the members of the enumeration, and create the
13286 symbol for the enumeration type.
13288 NOTE: We reverse the order of the element list. */
13291 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13293 struct type
*this_type
;
13295 this_type
= get_die_type (die
, cu
);
13296 if (this_type
== NULL
)
13297 this_type
= read_enumeration_type (die
, cu
);
13299 if (die
->child
!= NULL
)
13301 struct die_info
*child_die
;
13304 child_die
= die
->child
;
13305 while (child_die
&& child_die
->tag
)
13307 if (child_die
->tag
!= DW_TAG_enumerator
)
13309 process_die (child_die
, cu
);
13313 name
= dwarf2_name (child_die
, cu
);
13315 new_symbol (child_die
, this_type
, cu
);
13318 child_die
= child_die
->sibling
;
13322 /* If we are reading an enum from a .debug_types unit, and the enum
13323 is a declaration, and the enum is not the signatured type in the
13324 unit, then we do not want to add a symbol for it. Adding a
13325 symbol would in some cases obscure the true definition of the
13326 enum, giving users an incomplete type when the definition is
13327 actually available. Note that we do not want to do this for all
13328 enums which are just declarations, because C++0x allows forward
13329 enum declarations. */
13330 if (cu
->per_cu
->is_debug_types
13331 && die_is_declaration (die
, cu
))
13333 struct signatured_type
*sig_type
;
13335 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13336 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
13337 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
13341 new_symbol (die
, this_type
, cu
);
13344 /* Helper function for quirk_ada_thick_pointer that examines a bounds
13345 expression for an index type and finds the corresponding field
13346 offset in the hidden "P_BOUNDS" structure. Returns true on success
13347 and updates *FIELD, false if it fails to recognize an
13351 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
13352 int *bounds_offset
, struct field
*field
,
13353 struct dwarf2_cu
*cu
)
13355 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13356 if (attr
== nullptr || !attr
->form_is_block ())
13359 const struct dwarf_block
*block
= attr
->as_block ();
13360 const gdb_byte
*start
= block
->data
;
13361 const gdb_byte
*end
= block
->data
+ block
->size
;
13363 /* The expression to recognize generally looks like:
13365 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13366 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
13368 However, the second "plus_uconst" may be missing:
13370 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13371 DW_OP_deref_size: 4)
13373 This happens when the field is at the start of the structure.
13375 Also, the final deref may not be sized:
13377 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
13380 This happens when the size of the index type happens to be the
13381 same as the architecture's word size. This can occur with or
13382 without the second plus_uconst. */
13384 if (end
- start
< 2)
13386 if (*start
++ != DW_OP_push_object_address
)
13388 if (*start
++ != DW_OP_plus_uconst
)
13391 uint64_t this_bound_off
;
13392 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
13393 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
13395 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
13396 is consistent among all bounds. */
13397 if (*bounds_offset
== -1)
13398 *bounds_offset
= this_bound_off
;
13399 else if (*bounds_offset
!= this_bound_off
)
13402 if (start
== end
|| *start
++ != DW_OP_deref
)
13408 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
13410 /* This means an offset of 0. */
13412 else if (*start
++ != DW_OP_plus_uconst
)
13416 /* The size is the parameter to DW_OP_plus_uconst. */
13418 start
= gdb_read_uleb128 (start
, end
, &val
);
13419 if (start
== nullptr)
13421 if ((int) val
!= val
)
13430 if (*start
== DW_OP_deref_size
)
13432 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
13433 if (start
== nullptr)
13436 else if (*start
== DW_OP_deref
)
13438 size
= cu
->header
.addr_size
;
13444 field
->set_loc_bitpos (8 * offset
);
13445 if (size
!= field
->type ()->length ())
13446 FIELD_BITSIZE (*field
) = 8 * size
;
13451 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
13452 some kinds of Ada arrays:
13454 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
13455 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
13456 <11e0> DW_AT_data_location: 2 byte block: 97 6
13457 (DW_OP_push_object_address; DW_OP_deref)
13458 <11e3> DW_AT_type : <0x1173>
13459 <11e7> DW_AT_sibling : <0x1201>
13460 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
13461 <11ec> DW_AT_type : <0x1206>
13462 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
13463 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13464 DW_OP_deref_size: 4)
13465 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
13466 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13467 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
13469 This actually represents a "thick pointer", which is a structure
13470 with two elements: one that is a pointer to the array data, and one
13471 that is a pointer to another structure; this second structure holds
13474 This returns a new type on success, or nullptr if this didn't
13475 recognize the type. */
13477 static struct type
*
13478 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
13481 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
13482 /* So far we've only seen this with block form. */
13483 if (attr
== nullptr || !attr
->form_is_block ())
13486 /* Note that this will fail if the structure layout is changed by
13487 the compiler. However, we have no good way to recognize some
13488 other layout, because we don't know what expression the compiler
13489 might choose to emit should this happen. */
13490 struct dwarf_block
*blk
= attr
->as_block ();
13492 || blk
->data
[0] != DW_OP_push_object_address
13493 || blk
->data
[1] != DW_OP_deref
)
13496 int bounds_offset
= -1;
13497 int max_align
= -1;
13498 std::vector
<struct field
> range_fields
;
13499 for (struct die_info
*child_die
= die
->child
;
13501 child_die
= child_die
->sibling
)
13503 if (child_die
->tag
== DW_TAG_subrange_type
)
13505 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
13507 int this_align
= type_align (underlying
);
13508 if (this_align
> max_align
)
13509 max_align
= this_align
;
13511 range_fields
.emplace_back ();
13512 range_fields
.emplace_back ();
13514 struct field
&lower
= range_fields
[range_fields
.size () - 2];
13515 struct field
&upper
= range_fields
[range_fields
.size () - 1];
13517 lower
.set_type (underlying
);
13518 FIELD_ARTIFICIAL (lower
) = 1;
13520 upper
.set_type (underlying
);
13521 FIELD_ARTIFICIAL (upper
) = 1;
13523 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
13524 &bounds_offset
, &lower
, cu
)
13525 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
13526 &bounds_offset
, &upper
, cu
))
13531 /* This shouldn't really happen, but double-check that we found
13532 where the bounds are stored. */
13533 if (bounds_offset
== -1)
13536 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13537 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
13541 /* Set the name of each field in the bounds. */
13542 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
13543 range_fields
[i
].set_name (objfile
->intern (name
));
13544 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
13545 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
13548 struct type
*bounds
= alloc_type (objfile
);
13549 bounds
->set_code (TYPE_CODE_STRUCT
);
13551 bounds
->set_num_fields (range_fields
.size ());
13553 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
13554 * sizeof (struct field
))));
13555 memcpy (bounds
->fields (), range_fields
.data (),
13556 bounds
->num_fields () * sizeof (struct field
));
13558 int last_fieldno
= range_fields
.size () - 1;
13559 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
13560 + bounds
->field (last_fieldno
).type ()->length ());
13561 bounds
->set_length (align_up (bounds_size
, max_align
));
13563 /* Rewrite the existing array type in place. Specifically, we
13564 remove any dynamic properties we might have read, and we replace
13565 the index types. */
13566 struct type
*iter
= type
;
13567 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
13569 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
13570 iter
->main_type
->dyn_prop_list
= nullptr;
13571 iter
->set_index_type
13572 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
13573 iter
= iter
->target_type ();
13576 struct type
*result
= alloc_type (objfile
);
13577 result
->set_code (TYPE_CODE_STRUCT
);
13579 result
->set_num_fields (2);
13581 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
13582 * sizeof (struct field
))));
13584 /* The names are chosen to coincide with what the compiler does with
13585 -fgnat-encodings=all, which the Ada code in gdb already
13587 result
->field (0).set_name ("P_ARRAY");
13588 result
->field (0).set_type (lookup_pointer_type (type
));
13590 result
->field (1).set_name ("P_BOUNDS");
13591 result
->field (1).set_type (lookup_pointer_type (bounds
));
13592 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
13594 result
->set_name (type
->name ());
13595 result
->set_length (result
->field (0).type ()->length ()
13596 + result
->field (1).type ()->length ());
13601 /* Extract all information from a DW_TAG_array_type DIE and put it in
13602 the DIE's type field. For now, this only handles one dimensional
13605 static struct type
*
13606 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13608 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13609 struct die_info
*child_die
;
13611 struct type
*element_type
, *range_type
, *index_type
;
13612 struct attribute
*attr
;
13614 struct dynamic_prop
*byte_stride_prop
= NULL
;
13615 unsigned int bit_stride
= 0;
13617 element_type
= die_type (die
, cu
);
13619 /* The die_type call above may have already set the type for this DIE. */
13620 type
= get_die_type (die
, cu
);
13624 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
13628 struct type
*prop_type
= cu
->addr_sized_int_type (false);
13631 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
13632 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
13636 complaint (_("unable to read array DW_AT_byte_stride "
13637 " - DIE at %s [in module %s]"),
13638 sect_offset_str (die
->sect_off
),
13639 objfile_name (cu
->per_objfile
->objfile
));
13640 /* Ignore this attribute. We will likely not be able to print
13641 arrays of this type correctly, but there is little we can do
13642 to help if we cannot read the attribute's value. */
13643 byte_stride_prop
= NULL
;
13647 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
13649 bit_stride
= attr
->constant_value (0);
13651 /* Irix 6.2 native cc creates array types without children for
13652 arrays with unspecified length. */
13653 if (die
->child
== NULL
)
13655 index_type
= objfile_type (objfile
)->builtin_int
;
13656 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
13657 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
13658 byte_stride_prop
, bit_stride
);
13659 return set_die_type (die
, type
, cu
);
13662 std::vector
<struct type
*> range_types
;
13663 child_die
= die
->child
;
13664 while (child_die
&& child_die
->tag
)
13666 if (child_die
->tag
== DW_TAG_subrange_type
13667 || child_die
->tag
== DW_TAG_generic_subrange
)
13669 struct type
*child_type
= read_type_die (child_die
, cu
);
13671 if (child_type
!= NULL
)
13673 /* The range type was succesfully read. Save it for the
13674 array type creation. */
13675 range_types
.push_back (child_type
);
13678 child_die
= child_die
->sibling
;
13681 if (range_types
.empty ())
13683 complaint (_("unable to find array range - DIE at %s [in module %s]"),
13684 sect_offset_str (die
->sect_off
),
13685 objfile_name (cu
->per_objfile
->objfile
));
13689 /* Dwarf2 dimensions are output from left to right, create the
13690 necessary array types in backwards order. */
13692 type
= element_type
;
13694 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13698 while (i
< range_types
.size ())
13700 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
13701 byte_stride_prop
, bit_stride
);
13702 type
->set_is_multi_dimensional (true);
13704 byte_stride_prop
= nullptr;
13709 size_t ndim
= range_types
.size ();
13712 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
13713 byte_stride_prop
, bit_stride
);
13714 type
->set_is_multi_dimensional (true);
13716 byte_stride_prop
= nullptr;
13720 /* Clear the flag on the outermost array type. */
13721 type
->set_is_multi_dimensional (false);
13722 gdb_assert (type
!= element_type
);
13724 /* Understand Dwarf2 support for vector types (like they occur on
13725 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13726 array type. This is not part of the Dwarf2/3 standard yet, but a
13727 custom vendor extension. The main difference between a regular
13728 array and the vector variant is that vectors are passed by value
13730 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
13731 if (attr
!= nullptr)
13732 make_vector_type (type
);
13734 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13735 implementation may choose to implement triple vectors using this
13737 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13738 if (attr
!= nullptr && attr
->form_is_unsigned ())
13740 if (attr
->as_unsigned () >= type
->length ())
13741 type
->set_length (attr
->as_unsigned ());
13743 complaint (_("DW_AT_byte_size for array type smaller "
13744 "than the total size of elements"));
13747 name
= dwarf2_name (die
, cu
);
13749 type
->set_name (name
);
13751 maybe_set_alignment (cu
, die
, type
);
13753 struct type
*replacement_type
= nullptr;
13754 if (cu
->lang () == language_ada
)
13756 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
13757 if (replacement_type
!= nullptr)
13758 type
= replacement_type
;
13761 /* Install the type in the die. */
13762 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
13764 /* set_die_type should be already done. */
13765 set_descriptive_type (type
, die
, cu
);
13770 static enum dwarf_array_dim_ordering
13771 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
13773 struct attribute
*attr
;
13775 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
13777 if (attr
!= nullptr)
13779 LONGEST val
= attr
->constant_value (-1);
13780 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
13781 return (enum dwarf_array_dim_ordering
) val
;
13784 /* GNU F77 is a special case, as at 08/2004 array type info is the
13785 opposite order to the dwarf2 specification, but data is still
13786 laid out as per normal fortran.
13788 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13789 version checking. */
13791 if (cu
->lang () == language_fortran
13792 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
13794 return DW_ORD_row_major
;
13797 switch (cu
->language_defn
->array_ordering ())
13799 case array_column_major
:
13800 return DW_ORD_col_major
;
13801 case array_row_major
:
13803 return DW_ORD_row_major
;
13807 /* Extract all information from a DW_TAG_set_type DIE and put it in
13808 the DIE's type field. */
13810 static struct type
*
13811 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13813 struct type
*domain_type
, *set_type
;
13814 struct attribute
*attr
;
13816 domain_type
= die_type (die
, cu
);
13818 /* The die_type call above may have already set the type for this DIE. */
13819 set_type
= get_die_type (die
, cu
);
13823 set_type
= create_set_type (NULL
, domain_type
);
13825 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13826 if (attr
!= nullptr && attr
->form_is_unsigned ())
13827 set_type
->set_length (attr
->as_unsigned ());
13829 maybe_set_alignment (cu
, die
, set_type
);
13831 return set_die_type (die
, set_type
, cu
);
13834 /* A helper for read_common_block that creates a locexpr baton.
13835 SYM is the symbol which we are marking as computed.
13836 COMMON_DIE is the DIE for the common block.
13837 COMMON_LOC is the location expression attribute for the common
13839 MEMBER_LOC is the location expression attribute for the particular
13840 member of the common block that we are processing.
13841 CU is the CU from which the above come. */
13844 mark_common_block_symbol_computed (struct symbol
*sym
,
13845 struct die_info
*common_die
,
13846 struct attribute
*common_loc
,
13847 struct attribute
*member_loc
,
13848 struct dwarf2_cu
*cu
)
13850 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13851 struct objfile
*objfile
= per_objfile
->objfile
;
13852 struct dwarf2_locexpr_baton
*baton
;
13854 unsigned int cu_off
;
13855 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
13856 LONGEST offset
= 0;
13858 gdb_assert (common_loc
&& member_loc
);
13859 gdb_assert (common_loc
->form_is_block ());
13860 gdb_assert (member_loc
->form_is_block ()
13861 || member_loc
->form_is_constant ());
13863 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13864 baton
->per_objfile
= per_objfile
;
13865 baton
->per_cu
= cu
->per_cu
;
13866 gdb_assert (baton
->per_cu
);
13868 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13870 if (member_loc
->form_is_constant ())
13872 offset
= member_loc
->constant_value (0);
13873 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
13876 baton
->size
+= member_loc
->as_block ()->size
;
13878 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
13881 *ptr
++ = DW_OP_call4
;
13882 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
13883 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
13886 if (member_loc
->form_is_constant ())
13888 *ptr
++ = DW_OP_addr
;
13889 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
13890 ptr
+= cu
->header
.addr_size
;
13894 /* We have to copy the data here, because DW_OP_call4 will only
13895 use a DW_AT_location attribute. */
13896 struct dwarf_block
*block
= member_loc
->as_block ();
13897 memcpy (ptr
, block
->data
, block
->size
);
13898 ptr
+= block
->size
;
13901 *ptr
++ = DW_OP_plus
;
13902 gdb_assert (ptr
- baton
->data
== baton
->size
);
13904 SYMBOL_LOCATION_BATON (sym
) = baton
;
13905 sym
->set_aclass_index (dwarf2_locexpr_index
);
13908 /* Create appropriate locally-scoped variables for all the
13909 DW_TAG_common_block entries. Also create a struct common_block
13910 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
13911 is used to separate the common blocks name namespace from regular
13915 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
13917 struct attribute
*attr
;
13919 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13920 if (attr
!= nullptr)
13922 /* Support the .debug_loc offsets. */
13923 if (attr
->form_is_block ())
13927 else if (attr
->form_is_section_offset ())
13929 dwarf2_complex_location_expr_complaint ();
13934 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13935 "common block member");
13940 if (die
->child
!= NULL
)
13942 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13943 struct die_info
*child_die
;
13944 size_t n_entries
= 0, size
;
13945 struct common_block
*common_block
;
13946 struct symbol
*sym
;
13948 for (child_die
= die
->child
;
13949 child_die
&& child_die
->tag
;
13950 child_die
= child_die
->sibling
)
13953 size
= (sizeof (struct common_block
)
13954 + (n_entries
- 1) * sizeof (struct symbol
*));
13956 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
13958 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
13959 common_block
->n_entries
= 0;
13961 for (child_die
= die
->child
;
13962 child_die
&& child_die
->tag
;
13963 child_die
= child_die
->sibling
)
13965 /* Create the symbol in the DW_TAG_common_block block in the current
13967 sym
= new_symbol (child_die
, NULL
, cu
);
13970 struct attribute
*member_loc
;
13972 common_block
->contents
[common_block
->n_entries
++] = sym
;
13974 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
13978 /* GDB has handled this for a long time, but it is
13979 not specified by DWARF. It seems to have been
13980 emitted by gfortran at least as recently as:
13981 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
13982 complaint (_("Variable in common block has "
13983 "DW_AT_data_member_location "
13984 "- DIE at %s [in module %s]"),
13985 sect_offset_str (child_die
->sect_off
),
13986 objfile_name (objfile
));
13988 if (member_loc
->form_is_section_offset ())
13989 dwarf2_complex_location_expr_complaint ();
13990 else if (member_loc
->form_is_constant ()
13991 || member_loc
->form_is_block ())
13993 if (attr
!= nullptr)
13994 mark_common_block_symbol_computed (sym
, die
, attr
,
13998 dwarf2_complex_location_expr_complaint ();
14003 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14004 sym
->set_value_common_block (common_block
);
14008 /* Create a type for a C++ namespace. */
14010 static struct type
*
14011 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14013 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14014 const char *previous_prefix
, *name
;
14018 /* For extensions, reuse the type of the original namespace. */
14019 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14021 struct die_info
*ext_die
;
14022 struct dwarf2_cu
*ext_cu
= cu
;
14024 ext_die
= dwarf2_extension (die
, &ext_cu
);
14025 type
= read_type_die (ext_die
, ext_cu
);
14027 /* EXT_CU may not be the same as CU.
14028 Ensure TYPE is recorded with CU in die_type_hash. */
14029 return set_die_type (die
, type
, cu
);
14032 name
= namespace_name (die
, &is_anonymous
, cu
);
14034 /* Now build the name of the current namespace. */
14036 previous_prefix
= determine_prefix (die
, cu
);
14037 if (previous_prefix
[0] != '\0')
14038 name
= typename_concat (&objfile
->objfile_obstack
,
14039 previous_prefix
, name
, 0, cu
);
14041 /* Create the type. */
14042 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14044 return set_die_type (die
, type
, cu
);
14047 /* Read a namespace scope. */
14050 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14052 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14055 /* Add a symbol associated to this if we haven't seen the namespace
14056 before. Also, add a using directive if it's an anonymous
14059 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14063 type
= read_type_die (die
, cu
);
14064 new_symbol (die
, type
, cu
);
14066 namespace_name (die
, &is_anonymous
, cu
);
14069 const char *previous_prefix
= determine_prefix (die
, cu
);
14071 std::vector
<const char *> excludes
;
14072 add_using_directive (using_directives (cu
),
14073 previous_prefix
, type
->name (), NULL
,
14075 read_decl_line (die
, cu
),
14076 0, &objfile
->objfile_obstack
);
14080 if (die
->child
!= NULL
)
14082 struct die_info
*child_die
= die
->child
;
14084 while (child_die
&& child_die
->tag
)
14086 process_die (child_die
, cu
);
14087 child_die
= child_die
->sibling
;
14092 /* Read a Fortran module as type. This DIE can be only a declaration used for
14093 imported module. Still we need that type as local Fortran "use ... only"
14094 declaration imports depend on the created type in determine_prefix. */
14096 static struct type
*
14097 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14099 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14100 const char *module_name
;
14103 module_name
= dwarf2_name (die
, cu
);
14104 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14106 return set_die_type (die
, type
, cu
);
14109 /* Read a Fortran module. */
14112 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14114 struct die_info
*child_die
= die
->child
;
14117 type
= read_type_die (die
, cu
);
14118 new_symbol (die
, type
, cu
);
14120 while (child_die
&& child_die
->tag
)
14122 process_die (child_die
, cu
);
14123 child_die
= child_die
->sibling
;
14127 /* Return the name of the namespace represented by DIE. Set
14128 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14131 static const char *
14132 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14134 struct die_info
*current_die
;
14135 const char *name
= NULL
;
14137 /* Loop through the extensions until we find a name. */
14139 for (current_die
= die
;
14140 current_die
!= NULL
;
14141 current_die
= dwarf2_extension (die
, &cu
))
14143 /* We don't use dwarf2_name here so that we can detect the absence
14144 of a name -> anonymous namespace. */
14145 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14151 /* Is it an anonymous namespace? */
14153 *is_anonymous
= (name
== NULL
);
14155 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14160 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14161 the user defined type vector. */
14163 static struct type
*
14164 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14166 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
14167 struct comp_unit_head
*cu_header
= &cu
->header
;
14169 struct attribute
*attr_byte_size
;
14170 struct attribute
*attr_address_class
;
14171 int byte_size
, addr_class
;
14172 struct type
*target_type
;
14174 target_type
= die_type (die
, cu
);
14176 /* The die_type call above may have already set the type for this DIE. */
14177 type
= get_die_type (die
, cu
);
14181 type
= lookup_pointer_type (target_type
);
14183 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14184 if (attr_byte_size
)
14185 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
14187 byte_size
= cu_header
->addr_size
;
14189 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14190 if (attr_address_class
)
14191 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
14193 addr_class
= DW_ADDR_none
;
14195 ULONGEST alignment
= get_alignment (cu
, die
);
14197 /* If the pointer size, alignment, or address class is different
14198 than the default, create a type variant marked as such and set
14199 the length accordingly. */
14200 if (type
->length () != byte_size
14201 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
14202 && alignment
!= TYPE_RAW_ALIGN (type
))
14203 || addr_class
!= DW_ADDR_none
)
14205 if (gdbarch_address_class_type_flags_p (gdbarch
))
14207 type_instance_flags type_flags
14208 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
14210 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14212 type
= make_type_with_address_space (type
, type_flags
);
14214 else if (type
->length () != byte_size
)
14216 complaint (_("invalid pointer size %d"), byte_size
);
14218 else if (TYPE_RAW_ALIGN (type
) != alignment
)
14220 complaint (_("Invalid DW_AT_alignment"
14221 " - DIE at %s [in module %s]"),
14222 sect_offset_str (die
->sect_off
),
14223 objfile_name (cu
->per_objfile
->objfile
));
14227 /* Should we also complain about unhandled address classes? */
14231 type
->set_length (byte_size
);
14232 set_type_align (type
, alignment
);
14233 return set_die_type (die
, type
, cu
);
14236 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14237 the user defined type vector. */
14239 static struct type
*
14240 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14243 struct type
*to_type
;
14244 struct type
*domain
;
14246 to_type
= die_type (die
, cu
);
14247 domain
= die_containing_type (die
, cu
);
14249 /* The calls above may have already set the type for this DIE. */
14250 type
= get_die_type (die
, cu
);
14254 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
14255 type
= lookup_methodptr_type (to_type
);
14256 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
14258 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
14260 smash_to_method_type (new_type
, domain
, to_type
->target_type (),
14261 to_type
->fields (), to_type
->num_fields (),
14262 to_type
->has_varargs ());
14263 type
= lookup_methodptr_type (new_type
);
14266 type
= lookup_memberptr_type (to_type
, domain
);
14268 return set_die_type (die
, type
, cu
);
14271 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
14272 the user defined type vector. */
14274 static struct type
*
14275 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14276 enum type_code refcode
)
14278 struct comp_unit_head
*cu_header
= &cu
->header
;
14279 struct type
*type
, *target_type
;
14280 struct attribute
*attr
;
14282 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
14284 target_type
= die_type (die
, cu
);
14286 /* The die_type call above may have already set the type for this DIE. */
14287 type
= get_die_type (die
, cu
);
14291 type
= lookup_reference_type (target_type
, refcode
);
14292 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14293 if (attr
!= nullptr)
14294 type
->set_length (attr
->constant_value (cu_header
->addr_size
));
14296 type
->set_length (cu_header
->addr_size
);
14298 maybe_set_alignment (cu
, die
, type
);
14299 return set_die_type (die
, type
, cu
);
14302 /* Add the given cv-qualifiers to the element type of the array. GCC
14303 outputs DWARF type qualifiers that apply to an array, not the
14304 element type. But GDB relies on the array element type to carry
14305 the cv-qualifiers. This mimics section 6.7.3 of the C99
14308 static struct type
*
14309 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14310 struct type
*base_type
, int cnst
, int voltl
)
14312 struct type
*el_type
, *inner_array
;
14314 base_type
= copy_type (base_type
);
14315 inner_array
= base_type
;
14317 while (inner_array
->target_type ()->code () == TYPE_CODE_ARRAY
)
14319 inner_array
->set_target_type (copy_type (inner_array
->target_type ()));
14320 inner_array
= inner_array
->target_type ();
14323 el_type
= inner_array
->target_type ();
14324 cnst
|= TYPE_CONST (el_type
);
14325 voltl
|= TYPE_VOLATILE (el_type
);
14326 inner_array
->set_target_type (make_cv_type (cnst
, voltl
, el_type
, NULL
));
14328 return set_die_type (die
, base_type
, cu
);
14331 static struct type
*
14332 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14334 struct type
*base_type
, *cv_type
;
14336 base_type
= die_type (die
, cu
);
14338 /* The die_type call above may have already set the type for this DIE. */
14339 cv_type
= get_die_type (die
, cu
);
14343 /* In case the const qualifier is applied to an array type, the element type
14344 is so qualified, not the array type (section 6.7.3 of C99). */
14345 if (base_type
->code () == TYPE_CODE_ARRAY
)
14346 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14348 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14349 return set_die_type (die
, cv_type
, cu
);
14352 static struct type
*
14353 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14355 struct type
*base_type
, *cv_type
;
14357 base_type
= die_type (die
, cu
);
14359 /* The die_type call above may have already set the type for this DIE. */
14360 cv_type
= get_die_type (die
, cu
);
14364 /* In case the volatile qualifier is applied to an array type, the
14365 element type is so qualified, not the array type (section 6.7.3
14367 if (base_type
->code () == TYPE_CODE_ARRAY
)
14368 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14370 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14371 return set_die_type (die
, cv_type
, cu
);
14374 /* Handle DW_TAG_restrict_type. */
14376 static struct type
*
14377 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14379 struct type
*base_type
, *cv_type
;
14381 base_type
= die_type (die
, cu
);
14383 /* The die_type call above may have already set the type for this DIE. */
14384 cv_type
= get_die_type (die
, cu
);
14388 cv_type
= make_restrict_type (base_type
);
14389 return set_die_type (die
, cv_type
, cu
);
14392 /* Handle DW_TAG_atomic_type. */
14394 static struct type
*
14395 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14397 struct type
*base_type
, *cv_type
;
14399 base_type
= die_type (die
, cu
);
14401 /* The die_type call above may have already set the type for this DIE. */
14402 cv_type
= get_die_type (die
, cu
);
14406 cv_type
= make_atomic_type (base_type
);
14407 return set_die_type (die
, cv_type
, cu
);
14410 /* Extract all information from a DW_TAG_string_type DIE and add to
14411 the user defined type vector. It isn't really a user defined type,
14412 but it behaves like one, with other DIE's using an AT_user_def_type
14413 attribute to reference it. */
14415 static struct type
*
14416 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14418 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14419 struct gdbarch
*gdbarch
= objfile
->arch ();
14420 struct type
*type
, *range_type
, *index_type
, *char_type
;
14421 struct attribute
*attr
;
14422 struct dynamic_prop prop
;
14423 bool length_is_constant
= true;
14426 /* There are a couple of places where bit sizes might be made use of
14427 when parsing a DW_TAG_string_type, however, no producer that we know
14428 of make use of these. Handling bit sizes that are a multiple of the
14429 byte size is easy enough, but what about other bit sizes? Lets deal
14430 with that problem when we have to. Warn about these attributes being
14431 unsupported, then parse the type and ignore them like we always
14433 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
14434 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
14436 static bool warning_printed
= false;
14437 if (!warning_printed
)
14439 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
14440 "currently supported on DW_TAG_string_type."));
14441 warning_printed
= true;
14445 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14446 if (attr
!= nullptr && !attr
->form_is_constant ())
14448 /* The string length describes the location at which the length of
14449 the string can be found. The size of the length field can be
14450 specified with one of the attributes below. */
14451 struct type
*prop_type
;
14452 struct attribute
*len
14453 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
14454 if (len
== nullptr)
14455 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14456 if (len
!= nullptr && len
->form_is_constant ())
14458 /* Pass 0 as the default as we know this attribute is constant
14459 and the default value will not be returned. */
14460 LONGEST sz
= len
->constant_value (0);
14461 prop_type
= objfile_int_type (objfile
, sz
, true);
14465 /* If the size is not specified then we assume it is the size of
14466 an address on this target. */
14467 prop_type
= cu
->addr_sized_int_type (true);
14470 /* Convert the attribute into a dynamic property. */
14471 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
14474 length_is_constant
= false;
14476 else if (attr
!= nullptr)
14478 /* This DW_AT_string_length just contains the length with no
14479 indirection. There's no need to create a dynamic property in this
14480 case. Pass 0 for the default value as we know it will not be
14481 returned in this case. */
14482 length
= attr
->constant_value (0);
14484 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
14486 /* We don't currently support non-constant byte sizes for strings. */
14487 length
= attr
->constant_value (1);
14491 /* Use 1 as a fallback length if we have nothing else. */
14495 index_type
= objfile_type (objfile
)->builtin_int
;
14496 if (length_is_constant
)
14497 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14500 struct dynamic_prop low_bound
;
14502 low_bound
.set_const_val (1);
14503 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
14505 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14506 type
= create_string_type (NULL
, char_type
, range_type
);
14508 return set_die_type (die
, type
, cu
);
14511 /* Assuming that DIE corresponds to a function, returns nonzero
14512 if the function is prototyped. */
14515 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14517 struct attribute
*attr
;
14519 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14520 if (attr
&& attr
->as_boolean ())
14523 /* The DWARF standard implies that the DW_AT_prototyped attribute
14524 is only meaningful for C, but the concept also extends to other
14525 languages that allow unprototyped functions (Eg: Objective C).
14526 For all other languages, assume that functions are always
14528 if (cu
->lang () != language_c
14529 && cu
->lang () != language_objc
14530 && cu
->lang () != language_opencl
)
14533 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14534 prototyped and unprototyped functions; default to prototyped,
14535 since that is more common in modern code (and RealView warns
14536 about unprototyped functions). */
14537 if (producer_is_realview (cu
->producer
))
14543 /* Handle DIES due to C code like:
14547 int (*funcp)(int a, long l);
14551 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14553 static struct type
*
14554 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14556 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14557 struct type
*type
; /* Type that this function returns. */
14558 struct type
*ftype
; /* Function that returns above type. */
14559 struct attribute
*attr
;
14561 type
= die_type (die
, cu
);
14563 /* The die_type call above may have already set the type for this DIE. */
14564 ftype
= get_die_type (die
, cu
);
14568 ftype
= lookup_function_type (type
);
14570 if (prototyped_function_p (die
, cu
))
14571 ftype
->set_is_prototyped (true);
14573 /* Store the calling convention in the type if it's available in
14574 the subroutine die. Otherwise set the calling convention to
14575 the default value DW_CC_normal. */
14576 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14577 if (attr
!= nullptr
14578 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
14579 TYPE_CALLING_CONVENTION (ftype
)
14580 = (enum dwarf_calling_convention
) attr
->constant_value (0);
14581 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14582 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14584 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14586 /* Record whether the function returns normally to its caller or not
14587 if the DWARF producer set that information. */
14588 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14589 if (attr
&& attr
->as_boolean ())
14590 TYPE_NO_RETURN (ftype
) = 1;
14592 /* We need to add the subroutine type to the die immediately so
14593 we don't infinitely recurse when dealing with parameters
14594 declared as the same subroutine type. */
14595 set_die_type (die
, ftype
, cu
);
14597 if (die
->child
!= NULL
)
14599 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14600 struct die_info
*child_die
;
14601 int nparams
, iparams
;
14603 /* Count the number of parameters.
14604 FIXME: GDB currently ignores vararg functions, but knows about
14605 vararg member functions. */
14607 child_die
= die
->child
;
14608 while (child_die
&& child_die
->tag
)
14610 if (child_die
->tag
== DW_TAG_formal_parameter
)
14612 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14613 ftype
->set_has_varargs (true);
14615 child_die
= child_die
->sibling
;
14618 /* Allocate storage for parameters and fill them in. */
14619 ftype
->set_num_fields (nparams
);
14621 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
14623 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14624 even if we error out during the parameters reading below. */
14625 for (iparams
= 0; iparams
< nparams
; iparams
++)
14626 ftype
->field (iparams
).set_type (void_type
);
14629 child_die
= die
->child
;
14630 while (child_die
&& child_die
->tag
)
14632 if (child_die
->tag
== DW_TAG_formal_parameter
)
14634 struct type
*arg_type
;
14636 /* DWARF version 2 has no clean way to discern C++
14637 static and non-static member functions. G++ helps
14638 GDB by marking the first parameter for non-static
14639 member functions (which is the this pointer) as
14640 artificial. We pass this information to
14641 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14643 DWARF version 3 added DW_AT_object_pointer, which GCC
14644 4.5 does not yet generate. */
14645 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14646 if (attr
!= nullptr)
14647 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
14649 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14650 arg_type
= die_type (child_die
, cu
);
14652 /* RealView does not mark THIS as const, which the testsuite
14653 expects. GCC marks THIS as const in method definitions,
14654 but not in the class specifications (GCC PR 43053). */
14655 if (cu
->lang () == language_cplus
14656 && !TYPE_CONST (arg_type
)
14657 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14660 struct dwarf2_cu
*arg_cu
= cu
;
14661 const char *name
= dwarf2_name (child_die
, cu
);
14663 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14664 if (attr
!= nullptr)
14666 /* If the compiler emits this, use it. */
14667 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14670 else if (name
&& strcmp (name
, "this") == 0)
14671 /* Function definitions will have the argument names. */
14673 else if (name
== NULL
&& iparams
== 0)
14674 /* Declarations may not have the names, so like
14675 elsewhere in GDB, assume an artificial first
14676 argument is "this". */
14680 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14684 ftype
->field (iparams
).set_type (arg_type
);
14687 child_die
= child_die
->sibling
;
14694 static struct type
*
14695 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14697 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14698 const char *name
= NULL
;
14699 struct type
*this_type
, *target_type
;
14701 name
= dwarf2_full_name (NULL
, die
, cu
);
14702 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
14703 this_type
->set_target_is_stub (true);
14704 set_die_type (die
, this_type
, cu
);
14705 target_type
= die_type (die
, cu
);
14706 if (target_type
!= this_type
)
14707 this_type
->set_target_type (target_type
);
14710 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14711 spec and cause infinite loops in GDB. */
14712 complaint (_("Self-referential DW_TAG_typedef "
14713 "- DIE at %s [in module %s]"),
14714 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14715 this_type
->set_target_type (nullptr);
14719 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
14720 anonymous typedefs, which is, strictly speaking, invalid DWARF.
14721 Handle these by just returning the target type, rather than
14722 constructing an anonymous typedef type and trying to handle this
14724 set_die_type (die
, target_type
, cu
);
14725 return target_type
;
14730 /* Helper for get_dwarf2_rational_constant that computes the value of
14731 a given gmp_mpz given an attribute. */
14734 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
14736 /* GCC will sometimes emit a 16-byte constant value as a DWARF
14737 location expression that pushes an implicit value. */
14738 if (attr
->form
== DW_FORM_exprloc
)
14740 dwarf_block
*blk
= attr
->as_block ();
14741 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
14744 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
14745 blk
->data
+ blk
->size
,
14747 if (ptr
- blk
->data
+ len
<= blk
->size
)
14749 mpz_import (value
->val
, len
,
14750 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
.get ())
14757 /* On failure set it to 1. */
14758 *value
= gdb_mpz (1);
14760 else if (attr
->form_is_block ())
14762 dwarf_block
*blk
= attr
->as_block ();
14763 mpz_import (value
->val
, blk
->size
,
14764 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
.get ())
14766 1, 0, 0, blk
->data
);
14769 *value
= gdb_mpz (attr
->constant_value (1));
14772 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
14773 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
14775 If the numerator and/or numerator attribute is missing,
14776 a complaint is filed, and NUMERATOR and DENOMINATOR are left
14780 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
14781 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
14783 struct attribute
*num_attr
, *denom_attr
;
14785 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
14786 if (num_attr
== nullptr)
14787 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
14788 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
14790 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
14791 if (denom_attr
== nullptr)
14792 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
14793 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
14795 if (num_attr
== nullptr || denom_attr
== nullptr)
14798 get_mpz (cu
, numerator
, num_attr
);
14799 get_mpz (cu
, denominator
, denom_attr
);
14802 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
14803 rational constant, rather than a signed one.
14805 If the rational constant has a negative value, a complaint
14806 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
14809 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
14810 struct dwarf2_cu
*cu
,
14811 gdb_mpz
*numerator
,
14812 gdb_mpz
*denominator
)
14817 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
14818 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
14820 mpz_neg (num
.val
, num
.val
);
14821 mpz_neg (denom
.val
, denom
.val
);
14823 else if (mpz_sgn (num
.val
) == -1)
14825 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
14827 sect_offset_str (die
->sect_off
));
14830 else if (mpz_sgn (denom
.val
) == -1)
14832 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
14834 sect_offset_str (die
->sect_off
));
14838 *numerator
= std::move (num
);
14839 *denominator
= std::move (denom
);
14842 /* Assuming that ENCODING is a string whose contents starting at the
14843 K'th character is "_nn" where "nn" is a decimal number, scan that
14844 number and set RESULT to the value. K is updated to point to the
14845 character immediately following the number.
14847 If the string does not conform to the format described above, false
14848 is returned, and K may or may not be changed. */
14851 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
14853 /* The next character should be an underscore ('_') followed
14855 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
14858 /* Skip the underscore. */
14862 /* Determine the number of digits for our number. */
14863 while (isdigit (encoding
[k
]))
14868 std::string
copy (&encoding
[start
], k
- start
);
14869 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
14875 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
14876 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
14877 DENOM, update OFFSET, and return true on success. Return false on
14881 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
14882 gdb_mpz
*num
, gdb_mpz
*denom
)
14884 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
14886 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
14889 /* Assuming DIE corresponds to a fixed point type, finish the creation
14890 of the corresponding TYPE by setting its type-specific data. CU is
14891 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
14892 encodings. It is nullptr if the GNAT encoding should be
14896 finish_fixed_point_type (struct type
*type
, const char *suffix
,
14897 struct die_info
*die
, struct dwarf2_cu
*cu
)
14899 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
14900 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
14902 /* If GNAT encodings are preferred, don't examine the
14904 struct attribute
*attr
= nullptr;
14905 if (suffix
== nullptr)
14907 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
14908 if (attr
== nullptr)
14909 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
14910 if (attr
== nullptr)
14911 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
14914 /* Numerator and denominator of our fixed-point type's scaling factor.
14915 The default is a scaling factor of 1, which we use as a fallback
14916 when we are not able to decode it (problem with the debugging info,
14917 unsupported forms, bug in GDB, etc...). Using that as the default
14918 allows us to at least print the unscaled value, which might still
14919 be useful to a user. */
14920 gdb_mpz
scale_num (1);
14921 gdb_mpz
scale_denom (1);
14923 if (attr
== nullptr)
14926 if (suffix
!= nullptr
14927 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
14929 /* The number might be encoded as _nn_dd_nn_dd, where the
14930 second ratio is the 'small value. In this situation, we
14931 want the second value. */
14932 && (suffix
[offset
] != '_'
14933 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
14940 /* Scaling factor not found. Assume a scaling factor of 1,
14941 and hope for the best. At least the user will be able to
14942 see the encoded value. */
14945 complaint (_("no scale found for fixed-point type (DIE at %s)"),
14946 sect_offset_str (die
->sect_off
));
14949 else if (attr
->name
== DW_AT_binary_scale
)
14951 LONGEST scale_exp
= attr
->constant_value (0);
14952 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
14954 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
14956 else if (attr
->name
== DW_AT_decimal_scale
)
14958 LONGEST scale_exp
= attr
->constant_value (0);
14959 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
14961 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
14963 else if (attr
->name
== DW_AT_small
)
14965 struct die_info
*scale_die
;
14966 struct dwarf2_cu
*scale_cu
= cu
;
14968 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
14969 if (scale_die
->tag
== DW_TAG_constant
)
14970 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
14971 &scale_num
, &scale_denom
);
14973 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
14975 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
14979 complaint (_("unsupported scale attribute %s for fixed-point type"
14981 dwarf_attr_name (attr
->name
),
14982 sect_offset_str (die
->sect_off
));
14985 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
14986 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
14987 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
14988 mpq_canonicalize (scaling_factor
.val
);
14991 /* The gnat-encoding suffix for fixed point. */
14993 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
14995 /* If NAME encodes an Ada fixed-point type, return a pointer to the
14996 "XF" suffix of the name. The text after this is what encodes the
14997 'small and 'delta information. Otherwise, return nullptr. */
14999 static const char *
15000 gnat_encoded_fixed_point_type_info (const char *name
)
15002 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
15005 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15006 (which may be different from NAME) to the architecture back-end to allow
15007 it to guess the correct format if necessary. */
15009 static struct type
*
15010 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
15011 const char *name_hint
, enum bfd_endian byte_order
)
15013 struct gdbarch
*gdbarch
= objfile
->arch ();
15014 const struct floatformat
**format
;
15017 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
15019 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
15021 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15026 /* Allocate an integer type of size BITS and name NAME. */
15028 static struct type
*
15029 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
15030 int bits
, int unsigned_p
, const char *name
)
15034 /* Versions of Intel's C Compiler generate an integer type called "void"
15035 instead of using DW_TAG_unspecified_type. This has been seen on
15036 at least versions 14, 17, and 18. */
15037 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
15038 && strcmp (name
, "void") == 0)
15039 type
= objfile_type (objfile
)->builtin_void
;
15041 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
15046 /* Return true if DIE has a DW_AT_small attribute whose value is
15047 a constant rational, where both the numerator and denominator
15050 CU is the DIE's Compilation Unit. */
15053 has_zero_over_zero_small_attribute (struct die_info
*die
,
15054 struct dwarf2_cu
*cu
)
15056 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
15057 if (attr
== nullptr)
15060 struct dwarf2_cu
*scale_cu
= cu
;
15061 struct die_info
*scale_die
15062 = follow_die_ref (die
, attr
, &scale_cu
);
15064 if (scale_die
->tag
!= DW_TAG_constant
)
15067 gdb_mpz
num (1), denom (1);
15068 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
15069 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
15072 /* Initialise and return a floating point type of size BITS suitable for
15073 use as a component of a complex number. The NAME_HINT is passed through
15074 when initialising the floating point type and is the name of the complex
15077 As DWARF doesn't currently provide an explicit name for the components
15078 of a complex number, but it can be helpful to have these components
15079 named, we try to select a suitable name based on the size of the
15081 static struct type
*
15082 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
15083 struct objfile
*objfile
,
15084 int bits
, const char *name_hint
,
15085 enum bfd_endian byte_order
)
15087 gdbarch
*gdbarch
= objfile
->arch ();
15088 struct type
*tt
= nullptr;
15090 /* Try to find a suitable floating point builtin type of size BITS.
15091 We're going to use the name of this type as the name for the complex
15092 target type that we are about to create. */
15093 switch (cu
->lang ())
15095 case language_fortran
:
15099 tt
= builtin_f_type (gdbarch
)->builtin_real
;
15102 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
15104 case 96: /* The x86-32 ABI specifies 96-bit long double. */
15106 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
15114 tt
= builtin_type (gdbarch
)->builtin_float
;
15117 tt
= builtin_type (gdbarch
)->builtin_double
;
15119 case 96: /* The x86-32 ABI specifies 96-bit long double. */
15121 tt
= builtin_type (gdbarch
)->builtin_long_double
;
15127 /* If the type we found doesn't match the size we were looking for, then
15128 pretend we didn't find a type at all, the complex target type we
15129 create will then be nameless. */
15130 if (tt
!= nullptr && tt
->length () * TARGET_CHAR_BIT
!= bits
)
15133 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
15134 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
15137 /* Find a representation of a given base type and install
15138 it in the TYPE field of the die. */
15140 static struct type
*
15141 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15143 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15145 struct attribute
*attr
;
15146 int encoding
= 0, bits
= 0;
15150 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
15151 if (attr
!= nullptr && attr
->form_is_constant ())
15152 encoding
= attr
->constant_value (0);
15153 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15154 if (attr
!= nullptr)
15155 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
15156 name
= dwarf2_name (die
, cu
);
15158 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
15160 arch
= objfile
->arch ();
15161 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
15163 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
15164 if (attr
!= nullptr && attr
->form_is_constant ())
15166 int endianity
= attr
->constant_value (0);
15171 byte_order
= BFD_ENDIAN_BIG
;
15173 case DW_END_little
:
15174 byte_order
= BFD_ENDIAN_LITTLE
;
15177 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
15182 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
15183 && cu
->lang () == language_ada
15184 && has_zero_over_zero_small_attribute (die
, cu
))
15186 /* brobecker/2018-02-24: This is a fixed point type for which
15187 the scaling factor is represented as fraction whose value
15188 does not make sense (zero divided by zero), so we should
15189 normally never see these. However, there is a small category
15190 of fixed point types for which GNAT is unable to provide
15191 the scaling factor via the standard DWARF mechanisms, and
15192 for which the info is provided via the GNAT encodings instead.
15193 This is likely what this DIE is about. */
15194 encoding
= (encoding
== DW_ATE_signed_fixed
15196 : DW_ATE_unsigned
);
15199 /* With GNAT encodings, fixed-point information will be encoded in
15200 the type name. Note that this can also occur with the above
15201 zero-over-zero case, which is why this is a separate "if" rather
15202 than an "else if". */
15203 const char *gnat_encoding_suffix
= nullptr;
15204 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
15205 && cu
->lang () == language_ada
15206 && name
!= nullptr)
15208 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
15209 if (gnat_encoding_suffix
!= nullptr)
15211 gdb_assert (startswith (gnat_encoding_suffix
,
15212 GNAT_FIXED_POINT_SUFFIX
));
15213 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
15214 name
, gnat_encoding_suffix
- name
);
15215 /* Use -1 here so that SUFFIX points at the "_" after the
15217 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
15219 encoding
= (encoding
== DW_ATE_signed
15220 ? DW_ATE_signed_fixed
15221 : DW_ATE_unsigned_fixed
);
15227 case DW_ATE_address
:
15228 /* Turn DW_ATE_address into a void * pointer. */
15229 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
15230 type
= init_pointer_type (objfile
, bits
, name
, type
);
15232 case DW_ATE_boolean
:
15233 type
= init_boolean_type (objfile
, bits
, 1, name
);
15235 case DW_ATE_complex_float
:
15236 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
15238 if (type
->code () == TYPE_CODE_ERROR
)
15240 if (name
== nullptr)
15242 struct obstack
*obstack
15243 = &cu
->per_objfile
->objfile
->objfile_obstack
;
15244 name
= obconcat (obstack
, "_Complex ", type
->name (),
15247 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15250 type
= init_complex_type (name
, type
);
15252 case DW_ATE_decimal_float
:
15253 type
= init_decfloat_type (objfile
, bits
, name
);
15256 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
15258 case DW_ATE_signed
:
15259 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
15261 case DW_ATE_unsigned
:
15262 if (cu
->lang () == language_fortran
15264 && startswith (name
, "character("))
15265 type
= init_character_type (objfile
, bits
, 1, name
);
15267 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
15269 case DW_ATE_signed_char
:
15270 if (cu
->lang () == language_ada
15271 || cu
->lang () == language_m2
15272 || cu
->lang () == language_pascal
15273 || cu
->lang () == language_fortran
)
15274 type
= init_character_type (objfile
, bits
, 0, name
);
15276 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
15278 case DW_ATE_unsigned_char
:
15279 if (cu
->lang () == language_ada
15280 || cu
->lang () == language_m2
15281 || cu
->lang () == language_pascal
15282 || cu
->lang () == language_fortran
15283 || cu
->lang () == language_rust
)
15284 type
= init_character_type (objfile
, bits
, 1, name
);
15286 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
15290 type
= init_character_type (objfile
, bits
, 1, name
);
15291 return set_die_type (die
, type
, cu
);
15294 case DW_ATE_signed_fixed
:
15295 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
15296 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
15298 case DW_ATE_unsigned_fixed
:
15299 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
15300 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
15304 complaint (_("unsupported DW_AT_encoding: '%s'"),
15305 dwarf_type_encoding_name (encoding
));
15306 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15310 if (type
->code () == TYPE_CODE_INT
15312 && strcmp (name
, "char") == 0)
15313 type
->set_has_no_signedness (true);
15315 maybe_set_alignment (cu
, die
, type
);
15317 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
15319 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
15321 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15322 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * type
->length ())
15324 unsigned real_bit_size
= attr
->as_unsigned ();
15325 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15326 /* Only use the attributes if they make sense together. */
15327 if (attr
== nullptr
15328 || (attr
->as_unsigned () + real_bit_size
15329 <= 8 * type
->length ()))
15331 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
15333 if (attr
!= nullptr)
15334 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
15335 = attr
->as_unsigned ();
15340 return set_die_type (die
, type
, cu
);
15343 /* A helper function that returns the name of DIE, if it refers to a
15344 variable declaration. */
15346 static const char *
15347 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15349 if (die
->tag
!= DW_TAG_variable
)
15352 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
15353 if (attr
== nullptr || !attr
->as_boolean ())
15356 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15357 if (attr
== nullptr)
15359 return attr
->as_string ();
15362 /* Parse dwarf attribute if it's a block, reference or constant and put the
15363 resulting value of the attribute into struct bound_prop.
15364 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15367 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15368 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
15369 struct type
*default_type
)
15371 struct dwarf2_property_baton
*baton
;
15372 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
15373 struct objfile
*objfile
= per_objfile
->objfile
;
15374 struct obstack
*obstack
= &objfile
->objfile_obstack
;
15376 gdb_assert (default_type
!= NULL
);
15378 if (attr
== NULL
|| prop
== NULL
)
15381 if (attr
->form_is_block ())
15383 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15384 baton
->property_type
= default_type
;
15385 baton
->locexpr
.per_cu
= cu
->per_cu
;
15386 baton
->locexpr
.per_objfile
= per_objfile
;
15388 struct dwarf_block
*block
;
15389 if (attr
->form
== DW_FORM_data16
)
15391 size_t data_size
= 16;
15392 block
= XOBNEW (obstack
, struct dwarf_block
);
15393 block
->size
= (data_size
15394 + 2 /* Extra bytes for DW_OP and arg. */);
15395 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
15396 data
[0] = DW_OP_implicit_value
;
15397 data
[1] = data_size
;
15398 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
15399 block
->data
= data
;
15402 block
= attr
->as_block ();
15404 baton
->locexpr
.size
= block
->size
;
15405 baton
->locexpr
.data
= block
->data
;
15406 switch (attr
->name
)
15408 case DW_AT_string_length
:
15409 baton
->locexpr
.is_reference
= true;
15412 baton
->locexpr
.is_reference
= false;
15416 prop
->set_locexpr (baton
);
15417 gdb_assert (prop
->baton () != NULL
);
15419 else if (attr
->form_is_ref ())
15421 struct dwarf2_cu
*target_cu
= cu
;
15422 struct die_info
*target_die
;
15423 struct attribute
*target_attr
;
15425 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15426 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15427 if (target_attr
== NULL
)
15428 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15430 if (target_attr
== nullptr)
15431 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
15433 if (target_attr
== NULL
)
15435 const char *name
= var_decl_name (target_die
, target_cu
);
15436 if (name
!= nullptr)
15438 prop
->set_variable_name (name
);
15444 switch (target_attr
->name
)
15446 case DW_AT_location
:
15447 if (target_attr
->form_is_section_offset ())
15449 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15450 baton
->property_type
= die_type (target_die
, target_cu
);
15451 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15452 prop
->set_loclist (baton
);
15453 gdb_assert (prop
->baton () != NULL
);
15455 else if (target_attr
->form_is_block ())
15457 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15458 baton
->property_type
= die_type (target_die
, target_cu
);
15459 baton
->locexpr
.per_cu
= cu
->per_cu
;
15460 baton
->locexpr
.per_objfile
= per_objfile
;
15461 struct dwarf_block
*block
= target_attr
->as_block ();
15462 baton
->locexpr
.size
= block
->size
;
15463 baton
->locexpr
.data
= block
->data
;
15464 baton
->locexpr
.is_reference
= true;
15465 prop
->set_locexpr (baton
);
15466 gdb_assert (prop
->baton () != NULL
);
15470 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15471 "dynamic property");
15475 case DW_AT_data_member_location
:
15476 case DW_AT_data_bit_offset
:
15480 if (!handle_member_location (target_die
, target_cu
, &offset
))
15483 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15484 baton
->property_type
= read_type_die (target_die
->parent
,
15486 baton
->offset_info
.offset
= offset
;
15487 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15488 prop
->set_addr_offset (baton
);
15493 else if (attr
->form_is_constant ())
15494 prop
->set_const_val (attr
->constant_value (0));
15495 else if (attr
->form_is_section_offset ())
15497 switch (attr
->name
)
15499 case DW_AT_string_length
:
15500 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15501 baton
->property_type
= default_type
;
15502 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
15503 prop
->set_loclist (baton
);
15504 gdb_assert (prop
->baton () != NULL
);
15516 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15517 dwarf2_name (die
, cu
));
15523 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
15524 present (which is valid) then compute the default type based on the
15525 compilation units address size. */
15527 static struct type
*
15528 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15530 struct type
*index_type
= die_type (die
, cu
);
15532 /* Dwarf-2 specifications explicitly allows to create subrange types
15533 without specifying a base type.
15534 In that case, the base type must be set to the type of
15535 the lower bound, upper bound or count, in that order, if any of these
15536 three attributes references an object that has a type.
15537 If no base type is found, the Dwarf-2 specifications say that
15538 a signed integer type of size equal to the size of an address should
15540 For the following C code: `extern char gdb_int [];'
15541 GCC produces an empty range DIE.
15542 FIXME: muller/2010-05-28: Possible references to object for low bound,
15543 high bound or count are not yet handled by this code. */
15544 if (index_type
->code () == TYPE_CODE_VOID
)
15545 index_type
= cu
->addr_sized_int_type (false);
15550 /* Read the given DW_AT_subrange DIE. */
15552 static struct type
*
15553 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15555 struct type
*base_type
, *orig_base_type
;
15556 struct type
*range_type
;
15557 struct attribute
*attr
;
15558 struct dynamic_prop low
, high
;
15559 int low_default_is_valid
;
15560 int high_bound_is_count
= 0;
15563 orig_base_type
= read_subrange_index_type (die
, cu
);
15565 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15566 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15567 creating the range type, but we use the result of check_typedef
15568 when examining properties of the type. */
15569 base_type
= check_typedef (orig_base_type
);
15571 /* The die_type call above may have already set the type for this DIE. */
15572 range_type
= get_die_type (die
, cu
);
15576 high
.set_const_val (0);
15578 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15579 omitting DW_AT_lower_bound. */
15580 switch (cu
->lang ())
15583 case language_cplus
:
15584 low
.set_const_val (0);
15585 low_default_is_valid
= 1;
15587 case language_fortran
:
15588 low
.set_const_val (1);
15589 low_default_is_valid
= 1;
15592 case language_objc
:
15593 case language_rust
:
15594 low
.set_const_val (0);
15595 low_default_is_valid
= (cu
->header
.version
>= 4);
15599 case language_pascal
:
15600 low
.set_const_val (1);
15601 low_default_is_valid
= (cu
->header
.version
>= 4);
15604 low
.set_const_val (0);
15605 low_default_is_valid
= 0;
15609 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15610 if (attr
!= nullptr)
15611 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
15612 else if (!low_default_is_valid
)
15613 complaint (_("Missing DW_AT_lower_bound "
15614 "- DIE at %s [in module %s]"),
15615 sect_offset_str (die
->sect_off
),
15616 objfile_name (cu
->per_objfile
->objfile
));
15618 struct attribute
*attr_ub
, *attr_count
;
15619 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15620 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
15622 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
15623 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
15625 /* If bounds are constant do the final calculation here. */
15626 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
15627 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
15629 high_bound_is_count
= 1;
15633 if (attr_ub
!= NULL
)
15634 complaint (_("Unresolved DW_AT_upper_bound "
15635 "- DIE at %s [in module %s]"),
15636 sect_offset_str (die
->sect_off
),
15637 objfile_name (cu
->per_objfile
->objfile
));
15638 if (attr_count
!= NULL
)
15639 complaint (_("Unresolved DW_AT_count "
15640 "- DIE at %s [in module %s]"),
15641 sect_offset_str (die
->sect_off
),
15642 objfile_name (cu
->per_objfile
->objfile
));
15647 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
15648 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
15649 bias
= bias_attr
->constant_value (0);
15651 /* Normally, the DWARF producers are expected to use a signed
15652 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15653 But this is unfortunately not always the case, as witnessed
15654 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15655 is used instead. To work around that ambiguity, we treat
15656 the bounds as signed, and thus sign-extend their values, when
15657 the base type is signed.
15659 Skip it if the base type's length is larger than ULONGEST, to avoid
15660 the undefined behavior of a too large left shift. We don't really handle
15661 constants larger than 8 bytes anyway, at the moment. */
15663 if (base_type
->length () <= sizeof (ULONGEST
))
15665 ULONGEST negative_mask
15666 = -((ULONGEST
) 1 << (base_type
->length () * TARGET_CHAR_BIT
- 1));
15668 if (low
.kind () == PROP_CONST
15669 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
15670 low
.set_const_val (low
.const_val () | negative_mask
);
15672 if (high
.kind () == PROP_CONST
15673 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
15674 high
.set_const_val (high
.const_val () | negative_mask
);
15677 /* Check for bit and byte strides. */
15678 struct dynamic_prop byte_stride_prop
;
15679 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15680 if (attr_byte_stride
!= nullptr)
15682 struct type
*prop_type
= cu
->addr_sized_int_type (false);
15683 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
15687 struct dynamic_prop bit_stride_prop
;
15688 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15689 if (attr_bit_stride
!= nullptr)
15691 /* It only makes sense to have either a bit or byte stride. */
15692 if (attr_byte_stride
!= nullptr)
15694 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
15695 "- DIE at %s [in module %s]"),
15696 sect_offset_str (die
->sect_off
),
15697 objfile_name (cu
->per_objfile
->objfile
));
15698 attr_bit_stride
= nullptr;
15702 struct type
*prop_type
= cu
->addr_sized_int_type (false);
15703 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
15708 if (attr_byte_stride
!= nullptr
15709 || attr_bit_stride
!= nullptr)
15711 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
15712 struct dynamic_prop
*stride
15713 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
15716 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
15717 &high
, bias
, stride
, byte_stride_p
);
15720 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
15722 if (high_bound_is_count
)
15723 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
15725 /* Ada expects an empty array on no boundary attributes. */
15726 if (attr
== NULL
&& cu
->lang () != language_ada
)
15727 range_type
->bounds ()->high
.set_undefined ();
15729 name
= dwarf2_name (die
, cu
);
15731 range_type
->set_name (name
);
15733 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15734 if (attr
!= nullptr)
15735 range_type
->set_length (attr
->constant_value (0));
15737 maybe_set_alignment (cu
, die
, range_type
);
15739 set_die_type (die
, range_type
, cu
);
15741 /* set_die_type should be already done. */
15742 set_descriptive_type (range_type
, die
, cu
);
15747 static struct type
*
15748 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15752 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15753 type
->set_name (dwarf2_name (die
, cu
));
15755 /* In Ada, an unspecified type is typically used when the description
15756 of the type is deferred to a different unit. When encountering
15757 such a type, we treat it as a stub, and try to resolve it later on,
15759 Mark this as a stub type for all languages though. */
15760 type
->set_is_stub (true);
15762 return set_die_type (die
, type
, cu
);
15765 /* Read a single die and all its descendents. Set the die's sibling
15766 field to NULL; set other fields in the die correctly, and set all
15767 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15768 location of the info_ptr after reading all of those dies. PARENT
15769 is the parent of the die in question. */
15771 static struct die_info
*
15772 read_die_and_children (const struct die_reader_specs
*reader
,
15773 const gdb_byte
*info_ptr
,
15774 const gdb_byte
**new_info_ptr
,
15775 struct die_info
*parent
)
15777 struct die_info
*die
;
15778 const gdb_byte
*cur_ptr
;
15780 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0, true);
15783 *new_info_ptr
= cur_ptr
;
15786 store_in_ref_table (die
, reader
->cu
);
15788 if (die
->has_children
)
15789 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15793 *new_info_ptr
= cur_ptr
;
15796 die
->sibling
= NULL
;
15797 die
->parent
= parent
;
15801 /* Read a die, all of its descendents, and all of its siblings; set
15802 all of the fields of all of the dies correctly. Arguments are as
15803 in read_die_and_children. */
15805 static struct die_info
*
15806 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15807 const gdb_byte
*info_ptr
,
15808 const gdb_byte
**new_info_ptr
,
15809 struct die_info
*parent
)
15811 struct die_info
*first_die
, *last_sibling
;
15812 const gdb_byte
*cur_ptr
;
15814 cur_ptr
= info_ptr
;
15815 first_die
= last_sibling
= NULL
;
15819 struct die_info
*die
15820 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15824 *new_info_ptr
= cur_ptr
;
15831 last_sibling
->sibling
= die
;
15833 last_sibling
= die
;
15837 /* Read a die, all of its descendents, and all of its siblings; set
15838 all of the fields of all of the dies correctly. Arguments are as
15839 in read_die_and_children.
15840 This the main entry point for reading a DIE and all its children. */
15842 static struct die_info
*
15843 read_die_and_siblings (const struct die_reader_specs
*reader
,
15844 const gdb_byte
*info_ptr
,
15845 const gdb_byte
**new_info_ptr
,
15846 struct die_info
*parent
)
15848 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15849 new_info_ptr
, parent
);
15851 if (dwarf_die_debug
)
15853 gdb_printf (gdb_stdlog
,
15854 "Read die from %s@0x%x of %s:\n",
15855 reader
->die_section
->get_name (),
15856 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15857 bfd_get_filename (reader
->abfd
));
15858 die
->dump (dwarf_die_debug
);
15864 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15866 The caller is responsible for filling in the extra attributes
15867 and updating (*DIEP)->num_attrs.
15868 Set DIEP to point to a newly allocated die with its information,
15869 except for its child, sibling, and parent fields. */
15871 static const gdb_byte
*
15872 read_full_die_1 (const struct die_reader_specs
*reader
,
15873 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15874 int num_extra_attrs
, bool allow_reprocess
)
15876 unsigned int abbrev_number
, bytes_read
, i
;
15877 const struct abbrev_info
*abbrev
;
15878 struct die_info
*die
;
15879 struct dwarf2_cu
*cu
= reader
->cu
;
15880 bfd
*abfd
= reader
->abfd
;
15882 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
15883 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15884 info_ptr
+= bytes_read
;
15885 if (!abbrev_number
)
15891 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
15893 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15895 bfd_get_filename (abfd
));
15897 die
= die_info::allocate (&cu
->comp_unit_obstack
,
15898 abbrev
->num_attrs
+ num_extra_attrs
);
15899 die
->sect_off
= sect_off
;
15900 die
->tag
= abbrev
->tag
;
15901 die
->abbrev
= abbrev_number
;
15902 die
->has_children
= abbrev
->has_children
;
15904 /* Make the result usable.
15905 The caller needs to update num_attrs after adding the extra
15907 die
->num_attrs
= abbrev
->num_attrs
;
15909 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15910 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15911 info_ptr
, allow_reprocess
);
15917 /* Read a die and all its attributes.
15918 Set DIEP to point to a newly allocated die with its information,
15919 except for its child, sibling, and parent fields. */
15921 static const gdb_byte
*
15922 read_toplevel_die (const struct die_reader_specs
*reader
,
15923 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15924 gdb::array_view
<attribute
*> extra_attrs
)
15926 const gdb_byte
*result
;
15927 struct dwarf2_cu
*cu
= reader
->cu
;
15929 result
= read_full_die_1 (reader
, diep
, info_ptr
, extra_attrs
.size (),
15932 /* Copy in the extra attributes, if any. */
15933 attribute
*next
= &(*diep
)->attrs
[(*diep
)->num_attrs
];
15934 for (attribute
*extra
: extra_attrs
)
15937 struct attribute
*attr
= (*diep
)->attr (DW_AT_str_offsets_base
);
15938 if (attr
!= nullptr && attr
->form_is_unsigned ())
15939 cu
->str_offsets_base
= attr
->as_unsigned ();
15941 attr
= (*diep
)->attr (DW_AT_loclists_base
);
15942 if (attr
!= nullptr)
15943 cu
->loclist_base
= attr
->as_unsigned ();
15945 auto maybe_addr_base
= (*diep
)->addr_base ();
15946 if (maybe_addr_base
.has_value ())
15947 cu
->addr_base
= *maybe_addr_base
;
15949 attr
= (*diep
)->attr (DW_AT_rnglists_base
);
15950 if (attr
!= nullptr)
15951 cu
->rnglists_base
= attr
->as_unsigned ();
15953 for (int i
= 0; i
< (*diep
)->num_attrs
; ++i
)
15955 if ((*diep
)->attrs
[i
].form_requires_reprocessing ())
15956 read_attribute_reprocess (reader
, &(*diep
)->attrs
[i
], (*diep
)->tag
);
15959 (*diep
)->num_attrs
+= extra_attrs
.size ();
15961 if (dwarf_die_debug
)
15963 gdb_printf (gdb_stdlog
,
15964 "Read die from %s@0x%x of %s:\n",
15965 reader
->die_section
->get_name (),
15966 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15967 bfd_get_filename (reader
->abfd
));
15968 (*diep
)->dump (dwarf_die_debug
);
15976 cooked_indexer::check_bounds (cutu_reader
*reader
)
15978 if (reader
->cu
->per_cu
->addresses_seen
)
15981 dwarf2_cu
*cu
= reader
->cu
;
15983 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
15984 /* Possibly set the default values of LOWPC and HIGHPC from
15986 dwarf2_find_base_address (reader
->comp_unit_die
, cu
);
15987 enum pc_bounds_kind cu_bounds_kind
15988 = dwarf2_get_pc_bounds (reader
->comp_unit_die
, &best_lowpc
, &best_highpc
,
15989 cu
, m_index_storage
->get_addrmap (), cu
->per_cu
);
15990 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
15992 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15993 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
15994 struct gdbarch
*gdbarch
= objfile
->arch ();
15996 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
15999 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
16001 /* Store the contiguous range if it is not empty; it can be
16002 empty for CUs with no code. */
16003 m_index_storage
->get_addrmap ()->set_empty (low
, high
, cu
->per_cu
);
16005 cu
->per_cu
->addresses_seen
= true;
16009 /* Helper function that returns true if TAG can have a linkage
16013 tag_can_have_linkage_name (enum dwarf_tag tag
)
16017 case DW_TAG_variable
:
16018 case DW_TAG_subprogram
:
16027 cooked_indexer::ensure_cu_exists (cutu_reader
*reader
,
16028 dwarf2_per_objfile
*per_objfile
,
16029 sect_offset sect_off
, bool is_dwz
,
16032 /* Lookups for type unit references are always in the CU, and
16033 cross-CU references will crash. */
16034 if (reader
->cu
->per_cu
->is_dwz
== is_dwz
16035 && reader
->cu
->header
.offset_in_cu_p (sect_off
))
16038 dwarf2_per_cu_data
*per_cu
16039 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
16040 per_objfile
->per_bfd
);
16042 /* When scanning, we only want to visit a given CU a single time.
16043 Doing this check here avoids self-imports as well. */
16047 if (!per_cu
->scanned
.compare_exchange_strong (nope
, true))
16050 if (per_cu
== m_per_cu
)
16053 cutu_reader
*result
= m_index_storage
->get_reader (per_cu
);
16054 if (result
== nullptr)
16056 cutu_reader
new_reader (per_cu
, per_objfile
, nullptr, nullptr, false,
16057 m_index_storage
->get_abbrev_cache ());
16059 prepare_one_comp_unit (new_reader
.cu
, new_reader
.comp_unit_die
,
16061 std::unique_ptr
<cutu_reader
> copy
16062 (new cutu_reader (std::move (new_reader
)));
16063 result
= m_index_storage
->preserve (std::move (copy
));
16066 if (result
->dummy_p
|| !result
->comp_unit_die
->has_children
)
16070 check_bounds (result
);
16076 cooked_indexer::scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
16077 cutu_reader
*reader
,
16078 const gdb_byte
*watermark_ptr
,
16079 const gdb_byte
*info_ptr
,
16080 const abbrev_info
*abbrev
,
16082 const char **linkage_name
,
16083 cooked_index_flag
*flags
,
16084 sect_offset
*sibling_offset
,
16085 const cooked_index_entry
**parent_entry
,
16086 CORE_ADDR
*maybe_defer
,
16087 bool for_specification
)
16089 bool origin_is_dwz
= false;
16090 bool is_declaration
= false;
16091 sect_offset origin_offset
{};
16093 gdb::optional
<CORE_ADDR
> low_pc
;
16094 gdb::optional
<CORE_ADDR
> high_pc
;
16095 bool high_pc_relative
= false;
16097 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
16100 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16102 /* Store the data if it is of an attribute we want to keep in a
16103 partial symbol table. */
16107 switch (abbrev
->tag
)
16109 case DW_TAG_compile_unit
:
16110 case DW_TAG_partial_unit
:
16111 case DW_TAG_type_unit
:
16112 /* Compilation units have a DW_AT_name that is a filename, not
16113 a source language identifier. */
16117 if (*name
== nullptr)
16118 *name
= attr
.as_string ();
16123 case DW_AT_linkage_name
:
16124 case DW_AT_MIPS_linkage_name
:
16125 /* Note that both forms of linkage name might appear. We
16126 assume they will be the same, and we only store the last
16128 if (*linkage_name
== nullptr)
16129 *linkage_name
= attr
.as_string ();
16132 case DW_AT_main_subprogram
:
16133 if (attr
.as_boolean ())
16137 case DW_AT_declaration
:
16138 is_declaration
= attr
.as_boolean ();
16141 case DW_AT_sibling
:
16142 if (sibling_offset
!= nullptr)
16143 *sibling_offset
= attr
.get_ref_die_offset ();
16146 case DW_AT_specification
:
16147 case DW_AT_abstract_origin
:
16148 case DW_AT_extension
:
16149 origin_offset
= attr
.get_ref_die_offset ();
16150 origin_is_dwz
= attr
.form
== DW_FORM_GNU_ref_alt
;
16153 case DW_AT_external
:
16154 if (attr
.as_boolean ())
16155 *flags
&= ~IS_STATIC
;
16158 case DW_AT_enum_class
:
16159 if (attr
.as_boolean ())
16160 *flags
|= IS_ENUM_CLASS
;
16164 low_pc
= attr
.as_address ();
16167 case DW_AT_high_pc
:
16168 high_pc
= attr
.as_address ();
16169 if (reader
->cu
->header
.version
>= 4 && attr
.form_is_constant ())
16170 high_pc_relative
= true;
16173 case DW_AT_location
:
16174 if (!scanning_per_cu
->addresses_seen
&& attr
.form_is_block ())
16176 struct dwarf_block
*locdesc
= attr
.as_block ();
16177 CORE_ADDR addr
= decode_locdesc (locdesc
, reader
->cu
);
16179 || reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
)
16182 /* For variables, we don't want to try decoding the
16183 type just to find the size -- for gdb's purposes
16184 we only need the address of a variable. */
16185 high_pc
= addr
+ 1;
16186 high_pc_relative
= false;
16192 if (!scanning_per_cu
->addresses_seen
)
16194 /* Offset in the .debug_ranges or .debug_rnglist section
16195 (depending on DWARF version). */
16196 ULONGEST ranges_offset
= attr
.as_unsigned ();
16198 /* See dwarf2_cu::gnu_ranges_base's doc for why we might
16199 want to add this value. */
16200 ranges_offset
+= reader
->cu
->gnu_ranges_base
;
16202 CORE_ADDR lowpc
, highpc
;
16203 dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, reader
->cu
,
16204 m_index_storage
->get_addrmap (),
16205 scanning_per_cu
, abbrev
->tag
);
16211 /* We don't want to examine declarations, but if we found a
16212 declaration when handling DW_AT_specification or the like, then
16213 that is ok. Similarly, we allow an external variable without a
16214 location; those are resolved via minimal symbols. */
16215 if (is_declaration
&& !for_specification
16216 && !(abbrev
->tag
== DW_TAG_variable
&& (*flags
& IS_STATIC
) == 0))
16218 /* We always want to recurse into some types, but we may not
16219 want to treat them as definitions. */
16220 if ((abbrev
->tag
== DW_TAG_class_type
16221 || abbrev
->tag
== DW_TAG_structure_type
16222 || abbrev
->tag
== DW_TAG_union_type
)
16223 && abbrev
->has_children
)
16224 *flags
|= IS_TYPE_DECLARATION
;
16227 *linkage_name
= nullptr;
16231 else if ((*name
== nullptr
16232 || (*linkage_name
== nullptr
16233 && tag_can_have_linkage_name (abbrev
->tag
))
16234 || (*parent_entry
== nullptr && m_language
!= language_c
))
16235 && origin_offset
!= sect_offset (0))
16237 cutu_reader
*new_reader
16238 = ensure_cu_exists (reader
, reader
->cu
->per_objfile
, origin_offset
,
16239 origin_is_dwz
, false);
16240 if (new_reader
!= nullptr)
16242 const gdb_byte
*new_info_ptr
= (new_reader
->buffer
16243 + to_underlying (origin_offset
));
16245 if (new_reader
->cu
== reader
->cu
16246 && new_info_ptr
> watermark_ptr
16247 && *parent_entry
== nullptr)
16248 *maybe_defer
= form_addr (origin_offset
, origin_is_dwz
);
16249 else if (*parent_entry
== nullptr)
16251 CORE_ADDR lookup
= form_addr (origin_offset
, origin_is_dwz
);
16252 void *obj
= m_die_range_map
.find (lookup
);
16253 *parent_entry
= static_cast <cooked_index_entry
*> (obj
);
16256 unsigned int bytes_read
;
16257 const abbrev_info
*new_abbrev
= peek_die_abbrev (*new_reader
,
16260 new_info_ptr
+= bytes_read
;
16261 scan_attributes (scanning_per_cu
, new_reader
, new_info_ptr
, new_info_ptr
,
16262 new_abbrev
, name
, linkage_name
, flags
, nullptr,
16263 parent_entry
, maybe_defer
, true);
16267 if (!for_specification
)
16269 if (m_language
== language_ada
16270 && *linkage_name
== nullptr)
16271 *linkage_name
= *name
;
16273 if (!scanning_per_cu
->addresses_seen
16274 && low_pc
.has_value ()
16275 && (reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
16277 && high_pc
.has_value ())
16279 if (high_pc_relative
)
16280 high_pc
= *high_pc
+ *low_pc
;
16282 if (*high_pc
> *low_pc
)
16284 struct objfile
*objfile
= reader
->cu
->per_objfile
->objfile
;
16285 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
16286 struct gdbarch
*gdbarch
= objfile
->arch ();
16288 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *low_pc
+ baseaddr
)
16291 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *high_pc
+ baseaddr
)
16293 m_index_storage
->get_addrmap ()->set_empty (lo
, hi
- 1,
16298 if (abbrev
->tag
== DW_TAG_module
|| abbrev
->tag
== DW_TAG_namespace
)
16299 *flags
&= ~IS_STATIC
;
16301 if (abbrev
->tag
== DW_TAG_namespace
&& *name
== nullptr)
16302 *name
= "(anonymous namespace)";
16304 if (m_language
== language_cplus
16305 && (abbrev
->tag
== DW_TAG_class_type
16306 || abbrev
->tag
== DW_TAG_interface_type
16307 || abbrev
->tag
== DW_TAG_structure_type
16308 || abbrev
->tag
== DW_TAG_union_type
16309 || abbrev
->tag
== DW_TAG_enumeration_type
16310 || abbrev
->tag
== DW_TAG_enumerator
))
16311 *flags
&= ~IS_STATIC
;
16318 cooked_indexer::index_imported_unit (cutu_reader
*reader
,
16319 const gdb_byte
*info_ptr
,
16320 const abbrev_info
*abbrev
)
16322 sect_offset sect_off
{};
16323 bool is_dwz
= false;
16325 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
16327 /* Note that we never need to reprocess attributes here. */
16329 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16331 if (attr
.name
== DW_AT_import
)
16333 sect_off
= attr
.get_ref_die_offset ();
16334 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16335 || reader
->cu
->per_cu
->is_dwz
);
16339 /* Did not find DW_AT_import. */
16340 if (sect_off
== sect_offset (0))
16343 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
16344 cutu_reader
*new_reader
= ensure_cu_exists (reader
, per_objfile
, sect_off
,
16346 if (new_reader
!= nullptr)
16348 index_dies (new_reader
, new_reader
->info_ptr
, nullptr, false);
16350 reader
->cu
->add_dependence (new_reader
->cu
->per_cu
);
16357 cooked_indexer::recurse (cutu_reader
*reader
,
16358 const gdb_byte
*info_ptr
,
16359 const cooked_index_entry
*parent_entry
,
16362 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
16364 if (parent_entry
!= nullptr)
16366 CORE_ADDR start
= form_addr (parent_entry
->die_offset
,
16367 reader
->cu
->per_cu
->is_dwz
);
16368 CORE_ADDR end
= form_addr (sect_offset (info_ptr
- 1 - reader
->buffer
),
16369 reader
->cu
->per_cu
->is_dwz
);
16370 m_die_range_map
.set_empty (start
, end
, (void *) parent_entry
);
16377 cooked_indexer::index_dies (cutu_reader
*reader
,
16378 const gdb_byte
*info_ptr
,
16379 const cooked_index_entry
*parent_entry
,
16382 const gdb_byte
*end_ptr
= (reader
->buffer
16383 + to_underlying (reader
->cu
->header
.sect_off
)
16384 + reader
->cu
->header
.get_length_with_initial ());
16386 while (info_ptr
< end_ptr
)
16388 sect_offset this_die
= (sect_offset
) (info_ptr
- reader
->buffer
);
16389 unsigned int bytes_read
;
16390 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
16392 info_ptr
+= bytes_read
;
16393 if (abbrev
== nullptr)
16396 if (abbrev
->tag
== DW_TAG_imported_unit
)
16398 info_ptr
= index_imported_unit (reader
, info_ptr
, abbrev
);
16402 if (!abbrev
->interesting
)
16404 info_ptr
= skip_one_die (reader
, info_ptr
, abbrev
, !fully
);
16405 if (fully
&& abbrev
->has_children
)
16406 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
16410 const char *name
= nullptr;
16411 const char *linkage_name
= nullptr;
16412 CORE_ADDR defer
= 0;
16413 cooked_index_flag flags
= IS_STATIC
;
16414 sect_offset sibling
{};
16415 const cooked_index_entry
*this_parent_entry
= parent_entry
;
16416 info_ptr
= scan_attributes (reader
->cu
->per_cu
, reader
, info_ptr
,
16417 info_ptr
, abbrev
, &name
, &linkage_name
,
16418 &flags
, &sibling
, &this_parent_entry
,
16421 if (abbrev
->tag
== DW_TAG_namespace
16422 && m_language
== language_cplus
16423 && strcmp (name
, "::") == 0)
16425 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they
16426 generated bogus DW_TAG_namespace DIEs with a name of "::"
16427 for the global namespace. Work around this problem
16432 const cooked_index_entry
*this_entry
= nullptr;
16433 if (name
!= nullptr)
16436 m_deferred_entries
.push_back ({
16437 this_die
, name
, defer
, abbrev
->tag
, flags
16440 this_entry
= m_index_storage
->add (this_die
, abbrev
->tag
, flags
,
16441 name
, this_parent_entry
,
16445 if (linkage_name
!= nullptr)
16447 /* We only want this to be "main" if it has a linkage name
16448 but not an ordinary name. */
16449 if (name
!= nullptr)
16450 flags
= flags
& ~IS_MAIN
;
16451 /* Set the IS_LINKAGE on for everything except when functions
16452 have linkage name present but name is absent. */
16453 if (name
!= nullptr
16454 || (abbrev
->tag
!= DW_TAG_subprogram
16455 && abbrev
->tag
!= DW_TAG_inlined_subroutine
16456 && abbrev
->tag
!= DW_TAG_entry_point
))
16457 flags
= flags
| IS_LINKAGE
;
16458 m_index_storage
->add (this_die
, abbrev
->tag
, flags
,
16459 linkage_name
, nullptr, m_per_cu
);
16462 if (abbrev
->has_children
)
16464 switch (abbrev
->tag
)
16466 case DW_TAG_class_type
:
16467 case DW_TAG_interface_type
:
16468 case DW_TAG_structure_type
:
16469 case DW_TAG_union_type
:
16470 if (m_language
!= language_c
&& this_entry
!= nullptr)
16472 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
16477 case DW_TAG_enumeration_type
:
16478 /* We need to recurse even for an anonymous enumeration.
16479 Which scope we record as the parent scope depends on
16480 whether we're reading an "enum class". If so, we use
16481 the enum itself as the parent, yielding names like
16482 "enum_class::enumerator"; otherwise we inject the
16483 names into our own parent scope. */
16484 info_ptr
= recurse (reader
, info_ptr
,
16485 ((flags
& IS_ENUM_CLASS
) == 0)
16491 case DW_TAG_module
:
16492 if (this_entry
== nullptr)
16495 case DW_TAG_namespace
:
16496 /* We don't check THIS_ENTRY for a namespace, to handle
16497 the ancient G++ workaround pointed out above. */
16498 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
16501 case DW_TAG_subprogram
:
16502 if ((m_language
== language_fortran
16503 || m_language
== language_ada
)
16504 && this_entry
!= nullptr)
16506 info_ptr
= recurse (reader
, info_ptr
, this_entry
, true);
16512 if (sibling
!= sect_offset (0))
16514 const gdb_byte
*sibling_ptr
16515 = reader
->buffer
+ to_underlying (sibling
);
16517 if (sibling_ptr
< info_ptr
)
16518 complaint (_("DW_AT_sibling points backwards"));
16519 else if (sibling_ptr
> reader
->buffer_end
)
16520 reader
->die_section
->overflow_complaint ();
16522 info_ptr
= sibling_ptr
;
16525 info_ptr
= skip_children (reader
, info_ptr
);
16533 cooked_indexer::make_index (cutu_reader
*reader
)
16535 check_bounds (reader
);
16536 find_file_and_directory (reader
->comp_unit_die
, reader
->cu
);
16537 if (!reader
->comp_unit_die
->has_children
)
16539 index_dies (reader
, reader
->info_ptr
, nullptr, false);
16541 for (const auto &entry
: m_deferred_entries
)
16543 CORE_ADDR key
= form_addr (entry
.die_offset
, m_per_cu
->is_dwz
);
16544 void *obj
= m_die_range_map
.find (key
);
16545 cooked_index_entry
*parent
= static_cast <cooked_index_entry
*> (obj
);
16546 m_index_storage
->add (entry
.die_offset
, entry
.tag
, entry
.flags
,
16547 entry
.name
, parent
, m_per_cu
);
16551 /* An implementation of quick_symbol_functions for the cooked DWARF
16554 struct cooked_index_functions
: public dwarf2_base_index_functions
16556 dwarf2_per_cu_data
*find_per_cu (dwarf2_per_bfd
*per_bfd
,
16557 CORE_ADDR adjusted_pc
) override
;
16559 struct compunit_symtab
*find_compunit_symtab_by_address
16560 (struct objfile
*objfile
, CORE_ADDR address
) override
;
16562 void dump (struct objfile
*objfile
) override
16564 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16565 cooked_index
*index
16566 = (gdb::checked_static_cast
<cooked_index
*>
16567 (per_objfile
->per_bfd
->index_table
.get ()));
16568 if (index
== nullptr)
16571 gdb_printf ("Cooked index in use:\n");
16573 index
->dump (objfile
->arch ());
16576 void expand_matching_symbols
16578 const lookup_name_info
&lookup_name
,
16579 domain_enum domain
,
16581 symbol_compare_ftype
*ordered_compare
) override
;
16583 bool expand_symtabs_matching
16584 (struct objfile
*objfile
,
16585 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
16586 const lookup_name_info
*lookup_name
,
16587 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
16588 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
16589 block_search_flags search_flags
,
16590 domain_enum domain
,
16591 enum search_domain kind
) override
;
16593 bool can_lazily_read_symbols () override
16598 void read_partial_symbols (struct objfile
*objfile
) override
16600 if (dwarf2_has_info (objfile
, nullptr))
16601 dwarf2_build_psymtabs (objfile
);
16605 dwarf2_per_cu_data
*
16606 cooked_index_functions::find_per_cu (dwarf2_per_bfd
*per_bfd
,
16607 CORE_ADDR adjusted_pc
)
16609 cooked_index
*table
16610 = (gdb::checked_static_cast
<cooked_index
*>
16611 (per_bfd
->index_table
.get ()));
16612 if (table
== nullptr)
16614 return table
->lookup (adjusted_pc
);
16617 struct compunit_symtab
*
16618 cooked_index_functions::find_compunit_symtab_by_address
16619 (struct objfile
*objfile
, CORE_ADDR address
)
16621 if (objfile
->sect_index_data
== -1)
16624 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16625 cooked_index
*table
16626 = (gdb::checked_static_cast
<cooked_index
*>
16627 (per_objfile
->per_bfd
->index_table
.get ()));
16628 if (table
== nullptr)
16631 CORE_ADDR baseaddr
= objfile
->data_section_offset ();
16632 dwarf2_per_cu_data
*per_cu
= table
->lookup (address
- baseaddr
);
16633 if (per_cu
== nullptr)
16636 return dw2_instantiate_symtab (per_cu
, per_objfile
, false);
16640 cooked_index_functions::expand_matching_symbols
16641 (struct objfile
*objfile
,
16642 const lookup_name_info
&lookup_name
,
16643 domain_enum domain
,
16645 symbol_compare_ftype
*ordered_compare
)
16647 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16648 cooked_index
*table
16649 = (gdb::checked_static_cast
<cooked_index
*>
16650 (per_objfile
->per_bfd
->index_table
.get ()));
16651 if (table
== nullptr)
16654 const block_search_flags search_flags
= (global
16655 ? SEARCH_GLOBAL_BLOCK
16656 : SEARCH_STATIC_BLOCK
);
16657 const language_defn
*lang
= language_def (language_ada
);
16658 symbol_name_matcher_ftype
*name_match
16659 = lang
->get_symbol_name_matcher (lookup_name
);
16661 for (const cooked_index_entry
*entry
: table
->all_entries ())
16665 if (entry
->parent_entry
!= nullptr)
16668 if (!entry
->matches (search_flags
)
16669 || !entry
->matches (domain
))
16672 if (name_match (entry
->canonical
, lookup_name
, nullptr))
16673 dw2_instantiate_symtab (entry
->per_cu
, per_objfile
, false);
16678 cooked_index_functions::expand_symtabs_matching
16679 (struct objfile
*objfile
,
16680 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
16681 const lookup_name_info
*lookup_name
,
16682 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
16683 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
16684 block_search_flags search_flags
,
16685 domain_enum domain
,
16686 enum search_domain kind
)
16688 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16690 cooked_index
*table
16691 = (gdb::checked_static_cast
<cooked_index
*>
16692 (per_objfile
->per_bfd
->index_table
.get ()));
16693 if (table
== nullptr)
16698 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
16700 /* This invariant is documented in quick-functions.h. */
16701 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
16702 if (lookup_name
== nullptr)
16704 for (dwarf2_per_cu_data
*per_cu
16705 : all_units_range (per_objfile
->per_bfd
))
16709 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
16717 lookup_name_info lookup_name_without_params
16718 = lookup_name
->make_ignore_params ();
16719 bool completing
= lookup_name
->completion_mode ();
16721 /* Unique styles of language splitting. */
16722 static const enum language unique_styles
[] =
16724 /* No splitting is also a style. */
16726 /* This includes Rust. */
16728 /* This includes Go. */
16733 for (enum language lang
: unique_styles
)
16735 std::vector
<gdb::string_view
> name_vec
16736 = lookup_name_without_params
.split_name (lang
);
16737 std::string last_name
= gdb::to_string (name_vec
.back ());
16739 for (const cooked_index_entry
*entry
: table
->find (last_name
,
16744 /* No need to consider symbols from expanded CUs. */
16745 if (per_objfile
->symtab_set_p (entry
->per_cu
))
16748 /* If file-matching was done, we don't need to consider
16749 symbols from unmarked CUs. */
16750 if (file_matcher
!= nullptr && !entry
->per_cu
->mark
)
16753 /* See if the symbol matches the type filter. */
16754 if (!entry
->matches (search_flags
)
16755 || !entry
->matches (domain
)
16756 || !entry
->matches (kind
))
16759 /* We've found the base name of the symbol; now walk its
16760 parentage chain, ensuring that each component
16764 const cooked_index_entry
*parent
= entry
->parent_entry
;
16765 for (int i
= name_vec
.size () - 1; i
> 0; --i
)
16767 /* If we ran out of entries, or if this segment doesn't
16768 match, this did not match. */
16769 if (parent
== nullptr
16770 || strncmp (parent
->name
, name_vec
[i
- 1].data (),
16771 name_vec
[i
- 1].length ()) != 0)
16777 parent
= parent
->parent_entry
;
16783 /* Might have been looking for "a::b" and found
16785 if (symbol_matcher
== nullptr)
16787 symbol_name_match_type match_type
16788 = lookup_name_without_params
.match_type ();
16789 if ((match_type
== symbol_name_match_type::FULL
16790 || (lang
!= language_ada
16791 && match_type
== symbol_name_match_type::EXPRESSION
))
16792 && parent
!= nullptr)
16797 auto_obstack temp_storage
;
16798 const char *full_name
= entry
->full_name (&temp_storage
);
16799 if (!symbol_matcher (full_name
))
16803 if (!dw2_expand_symtabs_matching_one (entry
->per_cu
, per_objfile
,
16813 /* Return a new cooked_index_functions object. */
16815 static quick_symbol_functions_up
16816 make_cooked_index_funcs ()
16818 return quick_symbol_functions_up (new cooked_index_functions
);
16821 quick_symbol_functions_up
16822 cooked_index::make_quick_functions () const
16824 return make_cooked_index_funcs ();
16829 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
16830 contents from the given SECTION in the HEADER.
16832 HEADER_OFFSET is the offset of the header in the section. */
16834 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
16835 struct dwarf2_section_info
*section
,
16836 sect_offset header_offset
)
16838 unsigned int bytes_read
;
16839 bfd
*abfd
= section
->get_bfd_owner ();
16840 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
16842 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
16843 info_ptr
+= bytes_read
;
16845 header
->version
= read_2_bytes (abfd
, info_ptr
);
16848 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
16851 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
16854 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
16857 /* Return the DW_AT_loclists_base value for the CU. */
16859 lookup_loclist_base (struct dwarf2_cu
*cu
)
16861 /* For the .dwo unit, the loclist_base points to the first offset following
16862 the header. The header consists of the following entities-
16863 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
16865 2. version (2 bytes)
16866 3. address size (1 byte)
16867 4. segment selector size (1 byte)
16868 5. offset entry count (4 bytes)
16869 These sizes are derived as per the DWARFv5 standard. */
16870 if (cu
->dwo_unit
!= nullptr)
16872 if (cu
->header
.initial_length_size
== 4)
16873 return LOCLIST_HEADER_SIZE32
;
16874 return LOCLIST_HEADER_SIZE64
;
16876 return cu
->loclist_base
;
16879 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
16880 array of offsets in the .debug_loclists section. */
16883 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
16885 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16886 struct objfile
*objfile
= per_objfile
->objfile
;
16887 bfd
*abfd
= objfile
->obfd
.get ();
16888 ULONGEST loclist_header_size
=
16889 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
16890 : LOCLIST_HEADER_SIZE64
);
16891 ULONGEST loclist_base
= lookup_loclist_base (cu
);
16893 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
16894 ULONGEST start_offset
=
16895 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
16897 /* Get loclists section. */
16898 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16900 /* Read the loclists section content. */
16901 section
->read (objfile
);
16902 if (section
->buffer
== NULL
)
16903 error (_("DW_FORM_loclistx used without .debug_loclists "
16904 "section [in module %s]"), objfile_name (objfile
));
16906 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
16907 so if loclist_base is smaller than the header size, we have a problem. */
16908 if (loclist_base
< loclist_header_size
)
16909 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
16910 objfile_name (objfile
));
16912 /* Read the header of the loclists contribution. */
16913 struct loclists_rnglists_header header
;
16914 read_loclists_rnglists_header (&header
, section
,
16915 (sect_offset
) (loclist_base
- loclist_header_size
));
16917 /* Verify the loclist index is valid. */
16918 if (loclist_index
>= header
.offset_entry_count
)
16919 error (_("DW_FORM_loclistx pointing outside of "
16920 ".debug_loclists offset array [in module %s]"),
16921 objfile_name (objfile
));
16923 /* Validate that reading won't go beyond the end of the section. */
16924 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
16925 error (_("Reading DW_FORM_loclistx index beyond end of"
16926 ".debug_loclists section [in module %s]"),
16927 objfile_name (objfile
));
16929 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
16931 if (cu
->header
.offset_size
== 4)
16932 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
16934 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
16937 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
16938 array of offsets in the .debug_rnglists section. */
16941 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
16944 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
16945 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16946 bfd
*abfd
= objfile
->obfd
.get ();
16947 ULONGEST rnglist_header_size
=
16948 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
16949 : RNGLIST_HEADER_SIZE64
);
16951 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
16952 .debug_rnglists.dwo section. The rnglists base given in the skeleton
16954 ULONGEST rnglist_base
=
16955 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
16957 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
16958 ULONGEST start_offset
=
16959 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
16961 /* Get rnglists section. */
16962 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
16964 /* Read the rnglists section content. */
16965 section
->read (objfile
);
16966 if (section
->buffer
== nullptr)
16967 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
16969 objfile_name (objfile
));
16971 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
16972 so if rnglist_base is smaller than the header size, we have a problem. */
16973 if (rnglist_base
< rnglist_header_size
)
16974 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
16975 objfile_name (objfile
));
16977 /* Read the header of the rnglists contribution. */
16978 struct loclists_rnglists_header header
;
16979 read_loclists_rnglists_header (&header
, section
,
16980 (sect_offset
) (rnglist_base
- rnglist_header_size
));
16982 /* Verify the rnglist index is valid. */
16983 if (rnglist_index
>= header
.offset_entry_count
)
16984 error (_("DW_FORM_rnglistx index pointing outside of "
16985 ".debug_rnglists offset array [in module %s]"),
16986 objfile_name (objfile
));
16988 /* Validate that reading won't go beyond the end of the section. */
16989 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
16990 error (_("Reading DW_FORM_rnglistx index beyond end of"
16991 ".debug_rnglists section [in module %s]"),
16992 objfile_name (objfile
));
16994 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
16996 if (cu
->header
.offset_size
== 4)
16997 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
16999 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
17002 /* Process the attributes that had to be skipped in the first round. These
17003 attributes are the ones that need str_offsets_base or addr_base attributes.
17004 They could not have been processed in the first round, because at the time
17005 the values of str_offsets_base or addr_base may not have been known. */
17007 read_attribute_reprocess (const struct die_reader_specs
*reader
,
17008 struct attribute
*attr
, dwarf_tag tag
)
17010 struct dwarf2_cu
*cu
= reader
->cu
;
17011 switch (attr
->form
)
17013 case DW_FORM_addrx
:
17014 case DW_FORM_GNU_addr_index
:
17015 attr
->set_address (read_addr_index (cu
,
17016 attr
->as_unsigned_reprocess ()));
17018 case DW_FORM_loclistx
:
17020 sect_offset loclists_sect_off
17021 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
17023 attr
->set_unsigned (to_underlying (loclists_sect_off
));
17026 case DW_FORM_rnglistx
:
17028 sect_offset rnglists_sect_off
17029 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
17031 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
17035 case DW_FORM_strx1
:
17036 case DW_FORM_strx2
:
17037 case DW_FORM_strx3
:
17038 case DW_FORM_strx4
:
17039 case DW_FORM_GNU_str_index
:
17041 unsigned int str_index
= attr
->as_unsigned_reprocess ();
17042 gdb_assert (!attr
->canonical_string_p ());
17043 if (reader
->dwo_file
!= NULL
)
17044 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
17047 attr
->set_string_noncanonical (read_stub_str_index (cu
,
17052 gdb_assert_not_reached ("Unexpected DWARF form.");
17056 /* Read an attribute value described by an attribute form. */
17058 static const gdb_byte
*
17059 read_attribute_value (const struct die_reader_specs
*reader
,
17060 struct attribute
*attr
, unsigned form
,
17061 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
17062 bool allow_reprocess
)
17064 struct dwarf2_cu
*cu
= reader
->cu
;
17065 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17066 struct objfile
*objfile
= per_objfile
->objfile
;
17067 bfd
*abfd
= reader
->abfd
;
17068 struct comp_unit_head
*cu_header
= &cu
->header
;
17069 unsigned int bytes_read
;
17070 struct dwarf_block
*blk
;
17072 attr
->form
= (enum dwarf_form
) form
;
17075 case DW_FORM_ref_addr
:
17076 if (cu_header
->version
== 2)
17077 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
17080 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
17082 info_ptr
+= bytes_read
;
17084 case DW_FORM_GNU_ref_alt
:
17085 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
17087 info_ptr
+= bytes_read
;
17091 struct gdbarch
*gdbarch
= objfile
->arch ();
17092 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
17093 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
17094 attr
->set_address (addr
);
17095 info_ptr
+= bytes_read
;
17098 case DW_FORM_block2
:
17099 blk
= dwarf_alloc_block (cu
);
17100 blk
->size
= read_2_bytes (abfd
, info_ptr
);
17102 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17103 info_ptr
+= blk
->size
;
17104 attr
->set_block (blk
);
17106 case DW_FORM_block4
:
17107 blk
= dwarf_alloc_block (cu
);
17108 blk
->size
= read_4_bytes (abfd
, info_ptr
);
17110 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17111 info_ptr
+= blk
->size
;
17112 attr
->set_block (blk
);
17114 case DW_FORM_data2
:
17115 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
17118 case DW_FORM_data4
:
17119 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
17122 case DW_FORM_data8
:
17123 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
17126 case DW_FORM_data16
:
17127 blk
= dwarf_alloc_block (cu
);
17129 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
17131 attr
->set_block (blk
);
17133 case DW_FORM_sec_offset
:
17134 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
17136 info_ptr
+= bytes_read
;
17138 case DW_FORM_loclistx
:
17140 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
17142 info_ptr
+= bytes_read
;
17143 if (allow_reprocess
)
17144 read_attribute_reprocess (reader
, attr
);
17147 case DW_FORM_string
:
17148 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
17150 info_ptr
+= bytes_read
;
17153 if (!cu
->per_cu
->is_dwz
)
17155 attr
->set_string_noncanonical
17156 (read_indirect_string (per_objfile
,
17157 abfd
, info_ptr
, cu_header
,
17159 info_ptr
+= bytes_read
;
17163 case DW_FORM_line_strp
:
17164 if (!cu
->per_cu
->is_dwz
)
17166 attr
->set_string_noncanonical
17167 (per_objfile
->read_line_string (info_ptr
, cu_header
,
17169 info_ptr
+= bytes_read
;
17173 case DW_FORM_GNU_strp_alt
:
17175 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
17176 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
17179 attr
->set_string_noncanonical
17180 (dwz
->read_string (objfile
, str_offset
));
17181 info_ptr
+= bytes_read
;
17184 case DW_FORM_exprloc
:
17185 case DW_FORM_block
:
17186 blk
= dwarf_alloc_block (cu
);
17187 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17188 info_ptr
+= bytes_read
;
17189 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17190 info_ptr
+= blk
->size
;
17191 attr
->set_block (blk
);
17193 case DW_FORM_block1
:
17194 blk
= dwarf_alloc_block (cu
);
17195 blk
->size
= read_1_byte (abfd
, info_ptr
);
17197 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17198 info_ptr
+= blk
->size
;
17199 attr
->set_block (blk
);
17201 case DW_FORM_data1
:
17203 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
17206 case DW_FORM_flag_present
:
17207 attr
->set_unsigned (1);
17209 case DW_FORM_sdata
:
17210 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
17211 info_ptr
+= bytes_read
;
17213 case DW_FORM_rnglistx
:
17215 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
17217 info_ptr
+= bytes_read
;
17218 if (allow_reprocess
)
17219 read_attribute_reprocess (reader
, attr
);
17222 case DW_FORM_udata
:
17223 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
17224 info_ptr
+= bytes_read
;
17227 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17228 + read_1_byte (abfd
, info_ptr
)));
17232 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17233 + read_2_bytes (abfd
, info_ptr
)));
17237 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17238 + read_4_bytes (abfd
, info_ptr
)));
17242 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17243 + read_8_bytes (abfd
, info_ptr
)));
17246 case DW_FORM_ref_sig8
:
17247 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
17250 case DW_FORM_ref_udata
:
17251 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17252 + read_unsigned_leb128 (abfd
, info_ptr
,
17254 info_ptr
+= bytes_read
;
17256 case DW_FORM_indirect
:
17257 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17258 info_ptr
+= bytes_read
;
17259 if (form
== DW_FORM_implicit_const
)
17261 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
17262 info_ptr
+= bytes_read
;
17264 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
17265 info_ptr
, allow_reprocess
);
17267 case DW_FORM_implicit_const
:
17268 attr
->set_signed (implicit_const
);
17270 case DW_FORM_addrx
:
17271 case DW_FORM_GNU_addr_index
:
17272 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
17274 info_ptr
+= bytes_read
;
17275 if (allow_reprocess
)
17276 read_attribute_reprocess (reader
, attr
);
17279 case DW_FORM_strx1
:
17280 case DW_FORM_strx2
:
17281 case DW_FORM_strx3
:
17282 case DW_FORM_strx4
:
17283 case DW_FORM_GNU_str_index
:
17285 ULONGEST str_index
;
17286 if (form
== DW_FORM_strx1
)
17288 str_index
= read_1_byte (abfd
, info_ptr
);
17291 else if (form
== DW_FORM_strx2
)
17293 str_index
= read_2_bytes (abfd
, info_ptr
);
17296 else if (form
== DW_FORM_strx3
)
17298 str_index
= read_3_bytes (abfd
, info_ptr
);
17301 else if (form
== DW_FORM_strx4
)
17303 str_index
= read_4_bytes (abfd
, info_ptr
);
17308 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17309 info_ptr
+= bytes_read
;
17311 attr
->set_unsigned_reprocess (str_index
);
17312 if (allow_reprocess
)
17313 read_attribute_reprocess (reader
, attr
);
17317 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
17318 dwarf_form_name (form
),
17319 bfd_get_filename (abfd
));
17323 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
17324 attr
->form
= DW_FORM_GNU_ref_alt
;
17326 /* We have seen instances where the compiler tried to emit a byte
17327 size attribute of -1 which ended up being encoded as an unsigned
17328 0xffffffff. Although 0xffffffff is technically a valid size value,
17329 an object of this size seems pretty unlikely so we can relatively
17330 safely treat these cases as if the size attribute was invalid and
17331 treat them as zero by default. */
17332 if (attr
->name
== DW_AT_byte_size
17333 && form
== DW_FORM_data4
17334 && attr
->as_unsigned () >= 0xffffffff)
17337 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
17338 hex_string (attr
->as_unsigned ()));
17339 attr
->set_unsigned (0);
17345 /* Read an attribute described by an abbreviated attribute. */
17347 static const gdb_byte
*
17348 read_attribute (const struct die_reader_specs
*reader
,
17349 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
17350 const gdb_byte
*info_ptr
,
17351 bool allow_reprocess
)
17353 attr
->name
= abbrev
->name
;
17354 attr
->string_is_canonical
= 0;
17355 return read_attribute_value (reader
, attr
, abbrev
->form
,
17356 abbrev
->implicit_const
, info_ptr
,
17363 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
17364 LONGEST str_offset
)
17366 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
17367 str_offset
, "DW_FORM_strp");
17370 /* Return pointer to string at .debug_str offset as read from BUF.
17371 BUF is assumed to be in a compilation unit described by CU_HEADER.
17372 Return *BYTES_READ_PTR count of bytes read from BUF. */
17374 static const char *
17375 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
17376 const gdb_byte
*buf
,
17377 const struct comp_unit_head
*cu_header
,
17378 unsigned int *bytes_read_ptr
)
17380 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
17382 return read_indirect_string_at_offset (per_objfile
, str_offset
);
17388 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
17389 unsigned int offset_size
)
17391 bfd
*abfd
= objfile
->obfd
.get ();
17392 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
17394 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
17400 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
17401 const struct comp_unit_head
*cu_header
,
17402 unsigned int *bytes_read_ptr
)
17404 bfd
*abfd
= objfile
->obfd
.get ();
17405 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
17407 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
17410 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17411 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
17412 ADDR_SIZE is the size of addresses from the CU header. */
17415 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
17416 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
17418 struct objfile
*objfile
= per_objfile
->objfile
;
17419 bfd
*abfd
= objfile
->obfd
.get ();
17420 const gdb_byte
*info_ptr
;
17421 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
17423 per_objfile
->per_bfd
->addr
.read (objfile
);
17424 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
17425 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17426 objfile_name (objfile
));
17427 if (addr_base_or_zero
+ addr_index
* addr_size
17428 >= per_objfile
->per_bfd
->addr
.size
)
17429 error (_("DW_FORM_addr_index pointing outside of "
17430 ".debug_addr section [in module %s]"),
17431 objfile_name (objfile
));
17432 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
17433 + addr_index
* addr_size
);
17434 if (addr_size
== 4)
17435 return bfd_get_32 (abfd
, info_ptr
);
17437 return bfd_get_64 (abfd
, info_ptr
);
17440 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17443 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17445 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
17446 cu
->addr_base
, cu
->header
.addr_size
);
17449 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17452 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17453 unsigned int *bytes_read
)
17455 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
.get ();
17456 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17458 return read_addr_index (cu
, addr_index
);
17464 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
17465 dwarf2_per_objfile
*per_objfile
,
17466 unsigned int addr_index
)
17468 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
17469 gdb::optional
<ULONGEST
> addr_base
;
17472 /* We need addr_base and addr_size.
17473 If we don't have PER_CU->cu, we have to get it.
17474 Nasty, but the alternative is storing the needed info in PER_CU,
17475 which at this point doesn't seem justified: it's not clear how frequently
17476 it would get used and it would increase the size of every PER_CU.
17477 Entry points like dwarf2_per_cu_addr_size do a similar thing
17478 so we're not in uncharted territory here.
17479 Alas we need to be a bit more complicated as addr_base is contained
17482 We don't need to read the entire CU(/TU).
17483 We just need the header and top level die.
17485 IWBN to use the aging mechanism to let us lazily later discard the CU.
17486 For now we skip this optimization. */
17490 addr_base
= cu
->addr_base
;
17491 addr_size
= cu
->header
.addr_size
;
17495 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
17496 addr_base
= reader
.cu
->addr_base
;
17497 addr_size
= reader
.cu
->header
.addr_size
;
17500 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
17503 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
17504 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
17507 static const char *
17508 read_str_index (struct dwarf2_cu
*cu
,
17509 struct dwarf2_section_info
*str_section
,
17510 struct dwarf2_section_info
*str_offsets_section
,
17511 ULONGEST str_offsets_base
, ULONGEST str_index
,
17512 unsigned offset_size
)
17514 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17515 struct objfile
*objfile
= per_objfile
->objfile
;
17516 const char *objf_name
= objfile_name (objfile
);
17517 bfd
*abfd
= objfile
->obfd
.get ();
17518 const gdb_byte
*info_ptr
;
17519 ULONGEST str_offset
;
17520 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
17522 str_section
->read (objfile
);
17523 str_offsets_section
->read (objfile
);
17524 if (str_section
->buffer
== NULL
)
17525 error (_("%s used without %s section"
17526 " in CU at offset %s [in module %s]"),
17527 form_name
, str_section
->get_name (),
17528 sect_offset_str (cu
->header
.sect_off
), objf_name
);
17529 if (str_offsets_section
->buffer
== NULL
)
17530 error (_("%s used without %s section"
17531 " in CU at offset %s [in module %s]"),
17532 form_name
, str_section
->get_name (),
17533 sect_offset_str (cu
->header
.sect_off
), objf_name
);
17534 info_ptr
= (str_offsets_section
->buffer
17536 + str_index
* offset_size
);
17537 if (offset_size
== 4)
17538 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17540 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17541 if (str_offset
>= str_section
->size
)
17542 error (_("Offset from %s pointing outside of"
17543 " .debug_str.dwo section in CU at offset %s [in module %s]"),
17544 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
17545 return (const char *) (str_section
->buffer
+ str_offset
);
17548 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
17550 static const char *
17551 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17553 unsigned offset_size
;
17554 ULONGEST str_offsets_base
;
17555 if (reader
->cu
->header
.version
>= 5)
17557 /* We have a DWARF5 CU with a reference to a .debug_str_offsets section,
17558 so assume the .debug_str_offsets section is DWARF5 as well, and
17559 parse the header. FIXME: Parse the header only once. */
17560 unsigned int bytes_read
= 0;
17561 bfd
*abfd
= reader
->dwo_file
->sections
.str_offsets
.get_bfd_owner ();
17562 const gdb_byte
*p
= reader
->dwo_file
->sections
.str_offsets
.buffer
;
17564 /* Header: Initial length. */
17565 read_initial_length (abfd
, p
+ bytes_read
, &bytes_read
);
17567 /* Determine offset_size based on the .debug_str_offsets header. */
17568 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
17569 offset_size
= dwarf5_is_dwarf64
? 8 : 4;
17571 /* Header: Version. */
17572 unsigned version
= read_2_bytes (abfd
, p
+ bytes_read
);
17577 /* We'd like one warning here about ignoring the section, but
17578 because we parse the header more than once (see FIXME above)
17579 we'd have many warnings, so use a complaint instead, which at
17580 least has a limit. */
17581 complaint (_("Section .debug_str_offsets in %s has unsupported"
17582 " version %d, use empty string."),
17583 reader
->dwo_file
->dwo_name
, version
);
17587 /* Header: Padding. */
17590 str_offsets_base
= bytes_read
;
17594 /* We have a pre-DWARF5 CU with a reference to a .debug_str_offsets
17595 section, assume the .debug_str_offsets section is pre-DWARF5 as
17596 well, which doesn't have a header. */
17597 str_offsets_base
= 0;
17599 /* Determine offset_size based on the .debug_info header. */
17600 offset_size
= reader
->cu
->header
.offset_size
;
17603 return read_str_index (reader
->cu
,
17604 &reader
->dwo_file
->sections
.str
,
17605 &reader
->dwo_file
->sections
.str_offsets
,
17606 str_offsets_base
, str_index
, offset_size
);
17609 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
17611 static const char *
17612 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
17614 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17615 const char *objf_name
= objfile_name (objfile
);
17616 static const char form_name
[] = "DW_FORM_GNU_str_index";
17617 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
17619 if (!cu
->str_offsets_base
.has_value ())
17620 error (_("%s used in Fission stub without %s"
17621 " in CU at offset 0x%lx [in module %s]"),
17622 form_name
, str_offsets_attr_name
,
17623 (long) cu
->header
.offset_size
, objf_name
);
17625 return read_str_index (cu
,
17626 &cu
->per_objfile
->per_bfd
->str
,
17627 &cu
->per_objfile
->per_bfd
->str_offsets
,
17628 *cu
->str_offsets_base
, str_index
,
17629 cu
->header
.offset_size
);
17632 /* Return the length of an LEB128 number in BUF. */
17635 leb128_size (const gdb_byte
*buf
)
17637 const gdb_byte
*begin
= buf
;
17643 if ((byte
& 128) == 0)
17644 return buf
- begin
;
17648 static enum language
17649 dwarf_lang_to_enum_language (unsigned int lang
)
17651 enum language language
;
17660 language
= language_c
;
17663 case DW_LANG_C_plus_plus
:
17664 case DW_LANG_C_plus_plus_11
:
17665 case DW_LANG_C_plus_plus_14
:
17666 language
= language_cplus
;
17669 language
= language_d
;
17671 case DW_LANG_Fortran77
:
17672 case DW_LANG_Fortran90
:
17673 case DW_LANG_Fortran95
:
17674 case DW_LANG_Fortran03
:
17675 case DW_LANG_Fortran08
:
17676 language
= language_fortran
;
17679 language
= language_go
;
17681 case DW_LANG_Mips_Assembler
:
17682 language
= language_asm
;
17684 case DW_LANG_Ada83
:
17685 case DW_LANG_Ada95
:
17686 language
= language_ada
;
17688 case DW_LANG_Modula2
:
17689 language
= language_m2
;
17691 case DW_LANG_Pascal83
:
17692 language
= language_pascal
;
17695 language
= language_objc
;
17698 case DW_LANG_Rust_old
:
17699 language
= language_rust
;
17701 case DW_LANG_OpenCL
:
17702 language
= language_opencl
;
17704 case DW_LANG_Cobol74
:
17705 case DW_LANG_Cobol85
:
17707 language
= language_minimal
;
17714 /* Return the named attribute or NULL if not there. */
17716 static struct attribute
*
17717 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17722 struct attribute
*spec
= NULL
;
17724 for (i
= 0; i
< die
->num_attrs
; ++i
)
17726 if (die
->attrs
[i
].name
== name
)
17727 return &die
->attrs
[i
];
17728 if (die
->attrs
[i
].name
== DW_AT_specification
17729 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17730 spec
= &die
->attrs
[i
];
17736 die
= follow_die_ref (die
, spec
, &cu
);
17742 /* Return the string associated with a string-typed attribute, or NULL if it
17743 is either not found or is of an incorrect type. */
17745 static const char *
17746 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17748 struct attribute
*attr
;
17749 const char *str
= NULL
;
17751 attr
= dwarf2_attr (die
, name
, cu
);
17755 str
= attr
->as_string ();
17756 if (str
== nullptr)
17757 complaint (_("string type expected for attribute %s for "
17758 "DIE at %s in module %s"),
17759 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
17760 objfile_name (cu
->per_objfile
->objfile
));
17766 /* Return the dwo name or NULL if not present. If present, it is in either
17767 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
17768 static const char *
17769 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
17771 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
17772 if (dwo_name
== nullptr)
17773 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
17777 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17778 and holds a non-zero value. This function should only be used for
17779 DW_FORM_flag or DW_FORM_flag_present attributes. */
17782 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17784 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17786 return attr
!= nullptr && attr
->as_boolean ();
17790 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17792 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17793 which value is non-zero. However, we have to be careful with
17794 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17795 (via dwarf2_flag_true_p) follows this attribute. So we may
17796 end up accidently finding a declaration attribute that belongs
17797 to a different DIE referenced by the specification attribute,
17798 even though the given DIE does not have a declaration attribute. */
17799 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17800 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17803 /* Return the die giving the specification for DIE, if there is
17804 one. *SPEC_CU is the CU containing DIE on input, and the CU
17805 containing the return value on output. If there is no
17806 specification, but there is an abstract origin, that is
17809 static struct die_info
*
17810 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17812 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17815 if (spec_attr
== NULL
)
17816 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17818 if (spec_attr
== NULL
)
17821 return follow_die_ref (die
, spec_attr
, spec_cu
);
17824 /* A convenience function to find the proper .debug_line section for a CU. */
17826 static struct dwarf2_section_info
*
17827 get_debug_line_section (struct dwarf2_cu
*cu
)
17829 struct dwarf2_section_info
*section
;
17830 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17832 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17834 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17835 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17836 else if (cu
->per_cu
->is_dwz
)
17838 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
17840 section
= &dwz
->line
;
17843 section
= &per_objfile
->per_bfd
->line
;
17848 /* Read the statement program header starting at OFFSET in
17849 .debug_line, or .debug_line.dwo. Return a pointer
17850 to a struct line_header, allocated using xmalloc.
17851 Returns NULL if there is a problem reading the header, e.g., if it
17852 has a version we don't understand.
17854 NOTE: the strings in the include directory and file name tables of
17855 the returned object point into the dwarf line section buffer,
17856 and must not be freed. */
17858 static line_header_up
17859 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
,
17860 const char *comp_dir
)
17862 struct dwarf2_section_info
*section
;
17863 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17865 section
= get_debug_line_section (cu
);
17866 section
->read (per_objfile
->objfile
);
17867 if (section
->buffer
== NULL
)
17869 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17870 complaint (_("missing .debug_line.dwo section"));
17872 complaint (_("missing .debug_line section"));
17876 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
17877 per_objfile
, section
, &cu
->header
,
17881 /* Subroutine of dwarf_decode_lines to simplify it.
17882 Return the file name for the given file_entry.
17883 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
17884 If space for the result is malloc'd, *NAME_HOLDER will be set.
17885 Returns NULL if FILE_INDEX should be ignored, i.e., it is
17886 equivalent to CU_INFO. */
17888 static const char *
17889 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
17890 const file_and_directory
&cu_info
,
17891 std::string
&name_holder
)
17893 const char *include_name
= fe
.name
;
17894 const char *include_name_to_compare
= include_name
;
17896 const char *dir_name
= fe
.include_dir (lh
);
17898 std::string hold_compare
;
17899 if (!IS_ABSOLUTE_PATH (include_name
)
17900 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
17902 /* Avoid creating a duplicate name for CU_INFO.
17903 We do this by comparing INCLUDE_NAME and CU_INFO.
17904 Before we do the comparison, however, we need to account
17905 for DIR_NAME and COMP_DIR.
17906 First prepend dir_name (if non-NULL). If we still don't
17907 have an absolute path prepend comp_dir (if non-NULL).
17908 However, the directory we record in the include-file's
17909 psymtab does not contain COMP_DIR (to match the
17910 corresponding symtab(s)).
17915 bash$ gcc -g ./hello.c
17916 include_name = "hello.c"
17918 DW_AT_comp_dir = comp_dir = "/tmp"
17919 DW_AT_name = "./hello.c"
17923 if (dir_name
!= NULL
)
17925 name_holder
= path_join (dir_name
, include_name
);
17926 include_name
= name_holder
.c_str ();
17927 include_name_to_compare
= include_name
;
17929 if (!IS_ABSOLUTE_PATH (include_name
)
17930 && cu_info
.get_comp_dir () != nullptr)
17932 hold_compare
= path_join (cu_info
.get_comp_dir (), include_name
);
17933 include_name_to_compare
= hold_compare
.c_str ();
17937 std::string copied_name
;
17938 const char *cu_filename
= cu_info
.get_name ();
17939 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
17941 copied_name
= path_join (cu_info
.get_comp_dir (), cu_filename
);
17942 cu_filename
= copied_name
.c_str ();
17945 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
17947 return include_name
;
17950 /* State machine to track the state of the line number program. */
17952 class lnp_state_machine
17955 /* Initialize a machine state for the start of a line number
17957 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
);
17959 file_entry
*current_file ()
17961 /* lh->file_names is 0-based, but the file name numbers in the
17962 statement program are 1-based. */
17963 return m_line_header
->file_name_at (m_file
);
17966 /* Record the line in the state machine. END_SEQUENCE is true if
17967 we're processing the end of a sequence. */
17968 void record_line (bool end_sequence
);
17970 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
17971 nop-out rest of the lines in this sequence. */
17972 void check_line_address (struct dwarf2_cu
*cu
,
17973 const gdb_byte
*line_ptr
,
17974 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
17976 void handle_set_discriminator (unsigned int discriminator
)
17978 m_discriminator
= discriminator
;
17979 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
17982 /* Handle DW_LNE_set_address. */
17983 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
17986 address
+= baseaddr
;
17987 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
17990 /* Handle DW_LNS_advance_pc. */
17991 void handle_advance_pc (CORE_ADDR adjust
);
17993 /* Handle a special opcode. */
17994 void handle_special_opcode (unsigned char op_code
);
17996 /* Handle DW_LNS_advance_line. */
17997 void handle_advance_line (int line_delta
)
17999 advance_line (line_delta
);
18002 /* Handle DW_LNS_set_file. */
18003 void handle_set_file (file_name_index file
);
18005 /* Handle DW_LNS_negate_stmt. */
18006 void handle_negate_stmt ()
18008 m_flags
^= LEF_IS_STMT
;
18011 /* Handle DW_LNS_const_add_pc. */
18012 void handle_const_add_pc ();
18014 /* Handle DW_LNS_fixed_advance_pc. */
18015 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
18017 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18021 /* Handle DW_LNS_copy. */
18022 void handle_copy ()
18024 record_line (false);
18025 m_discriminator
= 0;
18026 m_flags
&= ~LEF_PROLOGUE_END
;
18029 /* Handle DW_LNE_end_sequence. */
18030 void handle_end_sequence ()
18032 m_currently_recording_lines
= true;
18035 /* Handle DW_LNS_set_prologue_end. */
18036 void handle_set_prologue_end ()
18038 m_flags
|= LEF_PROLOGUE_END
;
18042 /* Advance the line by LINE_DELTA. */
18043 void advance_line (int line_delta
)
18045 m_line
+= line_delta
;
18047 if (line_delta
!= 0)
18048 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18051 struct dwarf2_cu
*m_cu
;
18053 gdbarch
*m_gdbarch
;
18055 /* The line number header. */
18056 line_header
*m_line_header
;
18058 /* These are part of the standard DWARF line number state machine,
18059 and initialized according to the DWARF spec. */
18061 unsigned char m_op_index
= 0;
18062 /* The line table index of the current file. */
18063 file_name_index m_file
= 1;
18064 unsigned int m_line
= 1;
18066 /* These are initialized in the constructor. */
18068 CORE_ADDR m_address
;
18069 linetable_entry_flags m_flags
;
18070 unsigned int m_discriminator
= 0;
18072 /* Additional bits of state we need to track. */
18074 /* The last file that we called dwarf2_start_subfile for.
18075 This is only used for TLLs. */
18076 unsigned int m_last_file
= 0;
18077 /* The last file a line number was recorded for. */
18078 struct subfile
*m_last_subfile
= NULL
;
18080 /* The address of the last line entry. */
18081 CORE_ADDR m_last_address
;
18083 /* Set to true when a previous line at the same address (using
18084 m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
18085 when a line entry at a new address (m_address different to
18086 m_last_address) is processed. */
18087 bool m_stmt_at_address
= false;
18089 /* When true, record the lines we decode. */
18090 bool m_currently_recording_lines
= true;
18092 /* The last line number that was recorded, used to coalesce
18093 consecutive entries for the same line. This can happen, for
18094 example, when discriminators are present. PR 17276. */
18095 unsigned int m_last_line
= 0;
18096 bool m_line_has_non_zero_discriminator
= false;
18100 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
18102 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
18103 / m_line_header
->maximum_ops_per_instruction
)
18104 * m_line_header
->minimum_instruction_length
);
18105 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18106 m_op_index
= ((m_op_index
+ adjust
)
18107 % m_line_header
->maximum_ops_per_instruction
);
18111 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
18113 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
18114 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
18115 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
18116 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
18117 / m_line_header
->maximum_ops_per_instruction
)
18118 * m_line_header
->minimum_instruction_length
);
18119 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18120 m_op_index
= ((m_op_index
+ adj_opcode_d
)
18121 % m_line_header
->maximum_ops_per_instruction
);
18123 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
18124 advance_line (line_delta
);
18125 record_line (false);
18126 m_discriminator
= 0;
18127 m_flags
&= ~LEF_PROLOGUE_END
;
18131 lnp_state_machine::handle_set_file (file_name_index file
)
18135 const file_entry
*fe
= current_file ();
18137 dwarf2_debug_line_missing_file_complaint ();
18140 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
18141 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18142 dwarf2_start_subfile (m_cu
, *fe
, *m_line_header
);
18147 lnp_state_machine::handle_const_add_pc ()
18150 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
18153 = (((m_op_index
+ adjust
)
18154 / m_line_header
->maximum_ops_per_instruction
)
18155 * m_line_header
->minimum_instruction_length
);
18157 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18158 m_op_index
= ((m_op_index
+ adjust
)
18159 % m_line_header
->maximum_ops_per_instruction
);
18162 /* Return non-zero if we should add LINE to the line number table.
18163 LINE is the line to add, LAST_LINE is the last line that was added,
18164 LAST_SUBFILE is the subfile for LAST_LINE.
18165 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18166 had a non-zero discriminator.
18168 We have to be careful in the presence of discriminators.
18169 E.g., for this line:
18171 for (i = 0; i < 100000; i++);
18173 clang can emit four line number entries for that one line,
18174 each with a different discriminator.
18175 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18177 However, we want gdb to coalesce all four entries into one.
18178 Otherwise the user could stepi into the middle of the line and
18179 gdb would get confused about whether the pc really was in the
18180 middle of the line.
18182 Things are further complicated by the fact that two consecutive
18183 line number entries for the same line is a heuristic used by gcc
18184 to denote the end of the prologue. So we can't just discard duplicate
18185 entries, we have to be selective about it. The heuristic we use is
18186 that we only collapse consecutive entries for the same line if at least
18187 one of those entries has a non-zero discriminator. PR 17276.
18189 Note: Addresses in the line number state machine can never go backwards
18190 within one sequence, thus this coalescing is ok. */
18193 dwarf_record_line_p (struct dwarf2_cu
*cu
,
18194 unsigned int line
, unsigned int last_line
,
18195 int line_has_non_zero_discriminator
,
18196 struct subfile
*last_subfile
)
18198 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
18200 if (line
!= last_line
)
18202 /* Same line for the same file that we've seen already.
18203 As a last check, for pr 17276, only record the line if the line
18204 has never had a non-zero discriminator. */
18205 if (!line_has_non_zero_discriminator
)
18210 /* Use the CU's builder to record line number LINE beginning at
18211 address ADDRESS in the line table of subfile SUBFILE. */
18214 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18215 unsigned int line
, CORE_ADDR address
,
18216 linetable_entry_flags flags
,
18217 struct dwarf2_cu
*cu
)
18219 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18221 if (dwarf_line_debug
)
18223 gdb_printf (gdb_stdlog
,
18224 "Recording line %u, file %s, address %s\n",
18225 line
, lbasename (subfile
->name
.c_str ()),
18226 paddress (gdbarch
, address
));
18230 cu
->get_builder ()->record_line (subfile
, line
, addr
, flags
);
18233 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18234 Mark the end of a set of line number records.
18235 The arguments are the same as for dwarf_record_line_1.
18236 If SUBFILE is NULL the request is ignored. */
18239 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18240 CORE_ADDR address
, struct dwarf2_cu
*cu
)
18242 if (subfile
== NULL
)
18245 if (dwarf_line_debug
)
18247 gdb_printf (gdb_stdlog
,
18248 "Finishing current line, file %s, address %s\n",
18249 lbasename (subfile
->name
.c_str ()),
18250 paddress (gdbarch
, address
));
18253 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, LEF_IS_STMT
, cu
);
18257 lnp_state_machine::record_line (bool end_sequence
)
18259 if (dwarf_line_debug
)
18261 gdb_printf (gdb_stdlog
,
18262 "Processing actual line %u: file %u,"
18263 " address %s, is_stmt %u, prologue_end %u, discrim %u%s\n",
18265 paddress (m_gdbarch
, m_address
),
18266 (m_flags
& LEF_IS_STMT
) != 0,
18267 (m_flags
& LEF_PROLOGUE_END
) != 0,
18269 (end_sequence
? "\t(end sequence)" : ""));
18272 file_entry
*fe
= current_file ();
18275 dwarf2_debug_line_missing_file_complaint ();
18276 /* For now we ignore lines not starting on an instruction boundary.
18277 But not when processing end_sequence for compatibility with the
18278 previous version of the code. */
18279 else if (m_op_index
== 0 || end_sequence
)
18281 /* When we switch files we insert an end maker in the first file,
18282 switch to the second file and add a new line entry. The
18283 problem is that the end marker inserted in the first file will
18284 discard any previous line entries at the same address. If the
18285 line entries in the first file are marked as is-stmt, while
18286 the new line in the second file is non-stmt, then this means
18287 the end marker will discard is-stmt lines so we can have a
18288 non-stmt line. This means that there are less addresses at
18289 which the user can insert a breakpoint.
18291 To improve this we track the last address in m_last_address,
18292 and whether we have seen an is-stmt at this address. Then
18293 when switching files, if we have seen a stmt at the current
18294 address, and we are switching to create a non-stmt line, then
18295 discard the new line. */
18297 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
18298 bool ignore_this_line
18299 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
18300 && ((m_flags
& LEF_IS_STMT
) == 0)
18301 && m_stmt_at_address
)
18302 || (!end_sequence
&& m_line
== 0));
18304 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
18306 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
18307 m_currently_recording_lines
? m_cu
: nullptr);
18310 if (!end_sequence
&& !ignore_this_line
)
18312 linetable_entry_flags lte_flags
= m_flags
;
18313 if (producer_is_codewarrior (m_cu
))
18314 lte_flags
|= LEF_IS_STMT
;
18316 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
18317 m_line_has_non_zero_discriminator
,
18320 buildsym_compunit
*builder
= m_cu
->get_builder ();
18321 dwarf_record_line_1 (m_gdbarch
,
18322 builder
->get_current_subfile (),
18323 m_line
, m_address
, lte_flags
,
18324 m_currently_recording_lines
? m_cu
: nullptr);
18326 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
18327 m_last_line
= m_line
;
18331 /* Track whether we have seen any IS_STMT true at m_address in case we
18332 have multiple line table entries all at m_address. */
18333 if (m_last_address
!= m_address
)
18335 m_stmt_at_address
= false;
18336 m_last_address
= m_address
;
18338 m_stmt_at_address
|= (m_flags
& LEF_IS_STMT
) != 0;
18341 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
18345 m_line_header (lh
),
18346 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as
18347 if there was a line entry for it so that the backend has a
18348 chance to adjust it and also record it in case it needs it.
18349 This is currently used by MIPS code,
18350 cf. `mips_adjust_dwarf2_line'. */
18351 m_address (gdbarch_adjust_dwarf2_line (arch
, 0, 0)),
18352 m_flags (lh
->default_is_stmt
? LEF_IS_STMT
: (linetable_entry_flags
) 0),
18353 m_last_address (m_address
)
18358 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
18359 const gdb_byte
*line_ptr
,
18360 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
18362 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
18363 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
18364 located at 0x0. In this case, additionally check that if
18365 ADDRESS < UNRELOCATED_LOWPC. */
18367 if ((address
== 0 && address
< unrelocated_lowpc
)
18368 || address
== (CORE_ADDR
) -1)
18370 /* This line table is for a function which has been
18371 GCd by the linker. Ignore it. PR gdb/12528 */
18373 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18374 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18376 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18377 line_offset
, objfile_name (objfile
));
18378 m_currently_recording_lines
= false;
18379 /* Note: m_currently_recording_lines is left as false until we see
18380 DW_LNE_end_sequence. */
18384 /* Subroutine of dwarf_decode_lines to simplify it.
18385 Process the line number information in LH. */
18388 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18391 const gdb_byte
*line_ptr
, *extended_end
;
18392 const gdb_byte
*line_end
;
18393 unsigned int bytes_read
, extended_len
;
18394 unsigned char op_code
, extended_op
;
18395 CORE_ADDR baseaddr
;
18396 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18397 bfd
*abfd
= objfile
->obfd
.get ();
18398 struct gdbarch
*gdbarch
= objfile
->arch ();
18400 baseaddr
= objfile
->text_section_offset ();
18402 line_ptr
= lh
->statement_program_start
;
18403 line_end
= lh
->statement_program_end
;
18405 /* Read the statement sequences until there's nothing left. */
18406 while (line_ptr
< line_end
)
18408 /* The DWARF line number program state machine. Reset the state
18409 machine at the start of each sequence. */
18410 lnp_state_machine
state_machine (cu
, gdbarch
, lh
);
18411 bool end_sequence
= false;
18413 /* Start a subfile for the current file of the state
18415 const file_entry
*fe
= state_machine
.current_file ();
18418 dwarf2_start_subfile (cu
, *fe
, *lh
);
18420 /* Decode the table. */
18421 while (line_ptr
< line_end
&& !end_sequence
)
18423 op_code
= read_1_byte (abfd
, line_ptr
);
18426 if (op_code
>= lh
->opcode_base
)
18428 /* Special opcode. */
18429 state_machine
.handle_special_opcode (op_code
);
18431 else switch (op_code
)
18433 case DW_LNS_extended_op
:
18434 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18436 line_ptr
+= bytes_read
;
18437 extended_end
= line_ptr
+ extended_len
;
18438 extended_op
= read_1_byte (abfd
, line_ptr
);
18440 if (DW_LNE_lo_user
<= extended_op
18441 && extended_op
<= DW_LNE_hi_user
)
18443 /* Vendor extension, ignore. */
18444 line_ptr
= extended_end
;
18447 switch (extended_op
)
18449 case DW_LNE_end_sequence
:
18450 state_machine
.handle_end_sequence ();
18451 end_sequence
= true;
18453 case DW_LNE_set_address
:
18456 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
18457 line_ptr
+= bytes_read
;
18459 state_machine
.check_line_address (cu
, line_ptr
,
18460 lowpc
- baseaddr
, address
);
18461 state_machine
.handle_set_address (baseaddr
, address
);
18464 case DW_LNE_define_file
:
18466 const char *cur_file
;
18467 unsigned int mod_time
, length
;
18470 cur_file
= read_direct_string (abfd
, line_ptr
,
18472 line_ptr
+= bytes_read
;
18473 dindex
= (dir_index
)
18474 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18475 line_ptr
+= bytes_read
;
18477 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18478 line_ptr
+= bytes_read
;
18480 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18481 line_ptr
+= bytes_read
;
18482 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
18485 case DW_LNE_set_discriminator
:
18487 /* The discriminator is not interesting to the
18488 debugger; just ignore it. We still need to
18489 check its value though:
18490 if there are consecutive entries for the same
18491 (non-prologue) line we want to coalesce them.
18494 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18495 line_ptr
+= bytes_read
;
18497 state_machine
.handle_set_discriminator (discr
);
18501 complaint (_("mangled .debug_line section"));
18504 /* Make sure that we parsed the extended op correctly. If e.g.
18505 we expected a different address size than the producer used,
18506 we may have read the wrong number of bytes. */
18507 if (line_ptr
!= extended_end
)
18509 complaint (_("mangled .debug_line section"));
18514 state_machine
.handle_copy ();
18516 case DW_LNS_advance_pc
:
18519 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18520 line_ptr
+= bytes_read
;
18522 state_machine
.handle_advance_pc (adjust
);
18525 case DW_LNS_advance_line
:
18528 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18529 line_ptr
+= bytes_read
;
18531 state_machine
.handle_advance_line (line_delta
);
18534 case DW_LNS_set_file
:
18536 file_name_index file
18537 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
18539 line_ptr
+= bytes_read
;
18541 state_machine
.handle_set_file (file
);
18544 case DW_LNS_set_column
:
18545 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18546 line_ptr
+= bytes_read
;
18548 case DW_LNS_negate_stmt
:
18549 state_machine
.handle_negate_stmt ();
18551 case DW_LNS_set_basic_block
:
18553 /* Add to the address register of the state machine the
18554 address increment value corresponding to special opcode
18555 255. I.e., this value is scaled by the minimum
18556 instruction length since special opcode 255 would have
18557 scaled the increment. */
18558 case DW_LNS_const_add_pc
:
18559 state_machine
.handle_const_add_pc ();
18561 case DW_LNS_fixed_advance_pc
:
18563 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
18566 state_machine
.handle_fixed_advance_pc (addr_adj
);
18569 case DW_LNS_set_prologue_end
:
18570 state_machine
.handle_set_prologue_end ();
18574 /* Unknown standard opcode, ignore it. */
18577 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18579 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18580 line_ptr
+= bytes_read
;
18587 dwarf2_debug_line_missing_end_sequence_complaint ();
18589 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18590 in which case we still finish recording the last line). */
18591 state_machine
.record_line (true);
18595 /* Decode the Line Number Program (LNP) for the given line_header
18596 structure and CU. The actual information extracted and the type
18597 of structures created from the LNP depends on the value of PST.
18599 FND holds the CU file name and directory, if known.
18600 It is used for relative paths in the line table.
18602 NOTE: It is important that psymtabs have the same file name (via
18603 strcmp) as the corresponding symtab. Since the directory is not
18604 used in the name of the symtab we don't use it in the name of the
18605 psymtabs we create. E.g. expand_line_sal requires this when
18606 finding psymtabs to expand. A good testcase for this is
18609 LOWPC is the lowest address in CU (or 0 if not known).
18611 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18612 for its PC<->lines mapping information. Otherwise only the filename
18613 table is read in. */
18616 dwarf_decode_lines (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18617 CORE_ADDR lowpc
, int decode_mapping
)
18619 if (decode_mapping
)
18620 dwarf_decode_lines_1 (lh
, cu
, lowpc
);
18622 /* Make sure a symtab is created for every file, even files
18623 which contain only variables (i.e. no code with associated
18625 buildsym_compunit
*builder
= cu
->get_builder ();
18626 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
18628 for (auto &fe
: lh
->file_names ())
18630 dwarf2_start_subfile (cu
, fe
, *lh
);
18631 subfile
*sf
= builder
->get_current_subfile ();
18633 if (sf
->symtab
== nullptr)
18634 sf
->symtab
= allocate_symtab (cust
, sf
->name
.c_str (),
18635 sf
->name_for_id
.c_str ());
18637 fe
.symtab
= sf
->symtab
;
18641 /* Start a subfile for DWARF. FILENAME is the name of the file and
18642 DIRNAME the name of the source directory which contains FILENAME
18643 or NULL if not known.
18644 This routine tries to keep line numbers from identical absolute and
18645 relative file names in a common subfile.
18647 Using the `list' example from the GDB testsuite, which resides in
18648 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18649 of /srcdir/list0.c yields the following debugging information for list0.c:
18651 DW_AT_name: /srcdir/list0.c
18652 DW_AT_comp_dir: /compdir
18653 files.files[0].name: list0.h
18654 files.files[0].dir: /srcdir
18655 files.files[1].name: list0.c
18656 files.files[1].dir: /srcdir
18658 The line number information for list0.c has to end up in a single
18659 subfile, so that `break /srcdir/list0.c:1' works as expected.
18660 start_subfile will ensure that this happens provided that we pass the
18661 concatenation of files.files[1].dir and files.files[1].name as the
18665 dwarf2_start_subfile (dwarf2_cu
*cu
, const file_entry
&fe
,
18666 const line_header
&lh
)
18668 std::string filename_holder
;
18669 const char *filename
= fe
.name
;
18670 const char *dirname
= lh
.include_dir_at (fe
.d_index
);
18672 /* In order not to lose the line information directory,
18673 we concatenate it to the filename when it makes sense.
18674 Note that the Dwarf3 standard says (speaking of filenames in line
18675 information): ``The directory index is ignored for file names
18676 that represent full path names''. Thus ignoring dirname in the
18677 `else' branch below isn't an issue. */
18679 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18681 filename_holder
= path_join (dirname
, filename
);
18682 filename
= filename_holder
.c_str ();
18685 std::string filename_for_id
= lh
.file_file_name (fe
);
18686 cu
->get_builder ()->start_subfile (filename
, filename_for_id
.c_str ());
18690 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18691 struct dwarf2_cu
*cu
)
18693 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18694 struct comp_unit_head
*cu_header
= &cu
->header
;
18696 /* NOTE drow/2003-01-30: There used to be a comment and some special
18697 code here to turn a symbol with DW_AT_external and a
18698 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18699 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18700 with some versions of binutils) where shared libraries could have
18701 relocations against symbols in their debug information - the
18702 minimal symbol would have the right address, but the debug info
18703 would not. It's no longer necessary, because we will explicitly
18704 apply relocations when we read in the debug information now. */
18706 /* A DW_AT_location attribute with no contents indicates that a
18707 variable has been optimized away. */
18708 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
18710 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
18714 /* Handle one degenerate form of location expression specially, to
18715 preserve GDB's previous behavior when section offsets are
18716 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
18717 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
18719 if (attr
->form_is_block ())
18721 struct dwarf_block
*block
= attr
->as_block ();
18723 if ((block
->data
[0] == DW_OP_addr
18724 && block
->size
== 1 + cu_header
->addr_size
)
18725 || ((block
->data
[0] == DW_OP_GNU_addr_index
18726 || block
->data
[0] == DW_OP_addrx
)
18728 == 1 + leb128_size (&block
->data
[1]))))
18730 unsigned int dummy
;
18732 if (block
->data
[0] == DW_OP_addr
)
18733 sym
->set_value_address
18734 (cu
->header
.read_address (objfile
->obfd
.get (), block
->data
+ 1,
18737 sym
->set_value_address
18738 (read_addr_index_from_leb128 (cu
, block
->data
+ 1, &dummy
));
18739 sym
->set_aclass_index (LOC_STATIC
);
18740 fixup_symbol_section (sym
, objfile
);
18741 sym
->set_value_address
18742 (sym
->value_address ()
18743 + objfile
->section_offsets
[sym
->section_index ()]);
18748 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18749 expression evaluator, and use LOC_COMPUTED only when necessary
18750 (i.e. when the value of a register or memory location is
18751 referenced, or a thread-local block, etc.). Then again, it might
18752 not be worthwhile. I'm assuming that it isn't unless performance
18753 or memory numbers show me otherwise. */
18755 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18757 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18758 cu
->has_loclist
= true;
18761 /* Given a pointer to a DWARF information entry, figure out if we need
18762 to make a symbol table entry for it, and if so, create a new entry
18763 and return a pointer to it.
18764 If TYPE is NULL, determine symbol type from the die, otherwise
18765 used the passed type.
18766 If SPACE is not NULL, use it to hold the new symbol. If it is
18767 NULL, allocate a new symbol on the objfile's obstack. */
18769 static struct symbol
*
18770 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18771 struct symbol
*space
)
18773 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18774 struct objfile
*objfile
= per_objfile
->objfile
;
18775 struct gdbarch
*gdbarch
= objfile
->arch ();
18776 struct symbol
*sym
= NULL
;
18778 struct attribute
*attr
= NULL
;
18779 struct attribute
*attr2
= NULL
;
18780 CORE_ADDR baseaddr
;
18781 struct pending
**list_to_add
= NULL
;
18783 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18785 baseaddr
= objfile
->text_section_offset ();
18787 name
= dwarf2_name (die
, cu
);
18788 if (name
== nullptr && (die
->tag
== DW_TAG_subprogram
18789 || die
->tag
== DW_TAG_inlined_subroutine
18790 || die
->tag
== DW_TAG_entry_point
))
18791 name
= dw2_linkage_name (die
, cu
);
18795 int suppress_add
= 0;
18800 sym
= new (&objfile
->objfile_obstack
) symbol
;
18801 OBJSTAT (objfile
, n_syms
++);
18803 /* Cache this symbol's name and the name's demangled form (if any). */
18804 sym
->set_language (cu
->lang (), &objfile
->objfile_obstack
);
18805 /* Fortran does not have mangling standard and the mangling does differ
18806 between gfortran, iFort etc. */
18807 const char *physname
18808 = (cu
->lang () == language_fortran
18809 ? dwarf2_full_name (name
, die
, cu
)
18810 : dwarf2_physname (name
, die
, cu
));
18811 const char *linkagename
= dw2_linkage_name (die
, cu
);
18813 if (linkagename
== nullptr || cu
->lang () == language_ada
)
18814 sym
->set_linkage_name (physname
);
18817 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
18818 sym
->set_linkage_name (linkagename
);
18821 /* Handle DW_AT_artificial. */
18822 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
18823 if (attr
!= nullptr)
18824 sym
->set_is_artificial (attr
->as_boolean ());
18826 /* Default assumptions.
18827 Use the passed type or decode it from the die. */
18828 sym
->set_domain (VAR_DOMAIN
);
18829 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
18831 sym
->set_type (type
);
18833 sym
->set_type (die_type (die
, cu
));
18834 attr
= dwarf2_attr (die
,
18835 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18837 if (attr
!= nullptr)
18838 sym
->set_line (attr
->constant_value (0));
18840 attr
= dwarf2_attr (die
,
18841 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18843 if (attr
!= nullptr && attr
->is_nonnegative ())
18845 file_name_index file_index
18846 = (file_name_index
) attr
->as_nonnegative ();
18847 struct file_entry
*fe
;
18849 if (cu
->line_header
!= NULL
)
18850 fe
= cu
->line_header
->file_name_at (file_index
);
18855 complaint (_("file index out of range"));
18857 sym
->set_symtab (fe
->symtab
);
18863 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18864 if (attr
!= nullptr)
18868 addr
= attr
->as_address ();
18869 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18870 sym
->set_section_index (SECT_OFF_TEXT (objfile
));
18871 sym
->set_value_address (addr
);
18872 sym
->set_aclass_index (LOC_LABEL
);
18875 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
18876 sym
->set_type (objfile_type (objfile
)->builtin_core_addr
);
18877 sym
->set_domain (LABEL_DOMAIN
);
18878 add_symbol_to_list (sym
, cu
->list_in_scope
);
18880 case DW_TAG_subprogram
:
18881 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18883 sym
->set_aclass_index (LOC_BLOCK
);
18884 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18885 if ((attr2
!= nullptr && attr2
->as_boolean ())
18886 || cu
->lang () == language_ada
18887 || cu
->lang () == language_fortran
)
18889 /* Subprograms marked external are stored as a global symbol.
18890 Ada and Fortran subprograms, whether marked external or
18891 not, are always stored as a global symbol, because we want
18892 to be able to access them globally. For instance, we want
18893 to be able to break on a nested subprogram without having
18894 to specify the context. */
18895 list_to_add
= cu
->get_builder ()->get_global_symbols ();
18899 list_to_add
= cu
->list_in_scope
;
18902 case DW_TAG_inlined_subroutine
:
18903 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18905 sym
->set_aclass_index (LOC_BLOCK
);
18906 sym
->set_is_inlined (1);
18907 list_to_add
= cu
->list_in_scope
;
18909 case DW_TAG_template_value_param
:
18911 /* Fall through. */
18912 case DW_TAG_constant
:
18913 case DW_TAG_variable
:
18914 case DW_TAG_member
:
18915 /* Compilation with minimal debug info may result in
18916 variables with missing type entries. Change the
18917 misleading `void' type to something sensible. */
18918 if (sym
->type ()->code () == TYPE_CODE_VOID
)
18919 sym
->set_type (objfile_type (objfile
)->builtin_int
);
18921 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18922 /* In the case of DW_TAG_member, we should only be called for
18923 static const members. */
18924 if (die
->tag
== DW_TAG_member
)
18926 /* dwarf2_add_field uses die_is_declaration,
18927 so we do the same. */
18928 gdb_assert (die_is_declaration (die
, cu
));
18931 if (attr
!= nullptr)
18933 dwarf2_const_value (attr
, sym
, cu
);
18934 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18937 if (attr2
!= nullptr && attr2
->as_boolean ())
18938 list_to_add
= cu
->get_builder ()->get_global_symbols ();
18940 list_to_add
= cu
->list_in_scope
;
18944 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18945 if (attr
!= nullptr)
18947 var_decode_location (attr
, sym
, cu
);
18948 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18950 /* Fortran explicitly imports any global symbols to the local
18951 scope by DW_TAG_common_block. */
18952 if (cu
->lang () == language_fortran
&& die
->parent
18953 && die
->parent
->tag
== DW_TAG_common_block
)
18956 if (sym
->aclass () == LOC_STATIC
18957 && sym
->value_address () == 0
18958 && !per_objfile
->per_bfd
->has_section_at_zero
)
18960 /* When a static variable is eliminated by the linker,
18961 the corresponding debug information is not stripped
18962 out, but the variable address is set to null;
18963 do not add such variables into symbol table. */
18965 else if (attr2
!= nullptr && attr2
->as_boolean ())
18967 if (sym
->aclass () == LOC_STATIC
18968 && (objfile
->flags
& OBJF_MAINLINE
) == 0
18969 && per_objfile
->per_bfd
->can_copy
)
18971 /* A global static variable might be subject to
18972 copy relocation. We first check for a local
18973 minsym, though, because maybe the symbol was
18974 marked hidden, in which case this would not
18976 bound_minimal_symbol found
18977 = (lookup_minimal_symbol_linkage
18978 (sym
->linkage_name (), objfile
));
18979 if (found
.minsym
!= nullptr)
18980 sym
->maybe_copied
= 1;
18983 /* A variable with DW_AT_external is never static,
18984 but it may be block-scoped. */
18986 = ((cu
->list_in_scope
18987 == cu
->get_builder ()->get_file_symbols ())
18988 ? cu
->get_builder ()->get_global_symbols ()
18989 : cu
->list_in_scope
);
18992 list_to_add
= cu
->list_in_scope
;
18996 /* We do not know the address of this symbol.
18997 If it is an external symbol and we have type information
18998 for it, enter the symbol as a LOC_UNRESOLVED symbol.
18999 The address of the variable will then be determined from
19000 the minimal symbol table whenever the variable is
19002 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
19004 /* Fortran explicitly imports any global symbols to the local
19005 scope by DW_TAG_common_block. */
19006 if (cu
->lang () == language_fortran
&& die
->parent
19007 && die
->parent
->tag
== DW_TAG_common_block
)
19009 /* SYMBOL_CLASS doesn't matter here because
19010 read_common_block is going to reset it. */
19012 list_to_add
= cu
->list_in_scope
;
19014 else if (attr2
!= nullptr && attr2
->as_boolean ()
19015 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19017 /* A variable with DW_AT_external is never static, but it
19018 may be block-scoped. */
19020 = ((cu
->list_in_scope
19021 == cu
->get_builder ()->get_file_symbols ())
19022 ? cu
->get_builder ()->get_global_symbols ()
19023 : cu
->list_in_scope
);
19025 sym
->set_aclass_index (LOC_UNRESOLVED
);
19027 else if (!die_is_declaration (die
, cu
))
19029 /* Use the default LOC_OPTIMIZED_OUT class. */
19030 gdb_assert (sym
->aclass () == LOC_OPTIMIZED_OUT
);
19032 list_to_add
= cu
->list_in_scope
;
19036 case DW_TAG_formal_parameter
:
19038 /* If we are inside a function, mark this as an argument. If
19039 not, we might be looking at an argument to an inlined function
19040 when we do not have enough information to show inlined frames;
19041 pretend it's a local variable in that case so that the user can
19043 struct context_stack
*curr
19044 = cu
->get_builder ()->get_current_context_stack ();
19045 if (curr
!= nullptr && curr
->name
!= nullptr)
19046 sym
->set_is_argument (1);
19047 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19048 if (attr
!= nullptr)
19050 var_decode_location (attr
, sym
, cu
);
19052 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19053 if (attr
!= nullptr)
19055 dwarf2_const_value (attr
, sym
, cu
);
19058 list_to_add
= cu
->list_in_scope
;
19061 case DW_TAG_unspecified_parameters
:
19062 /* From varargs functions; gdb doesn't seem to have any
19063 interest in this information, so just ignore it for now.
19066 case DW_TAG_template_type_param
:
19068 /* Fall through. */
19069 case DW_TAG_class_type
:
19070 case DW_TAG_interface_type
:
19071 case DW_TAG_structure_type
:
19072 case DW_TAG_union_type
:
19073 case DW_TAG_set_type
:
19074 case DW_TAG_enumeration_type
:
19075 case DW_TAG_namelist
:
19076 if (die
->tag
== DW_TAG_namelist
)
19078 sym
->set_aclass_index (LOC_STATIC
);
19079 sym
->set_domain (VAR_DOMAIN
);
19083 sym
->set_aclass_index (LOC_TYPEDEF
);
19084 sym
->set_domain (STRUCT_DOMAIN
);
19087 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19088 really ever be static objects: otherwise, if you try
19089 to, say, break of a class's method and you're in a file
19090 which doesn't mention that class, it won't work unless
19091 the check for all static symbols in lookup_symbol_aux
19092 saves you. See the OtherFileClass tests in
19093 gdb.c++/namespace.exp. */
19097 buildsym_compunit
*builder
= cu
->get_builder ();
19099 = (cu
->list_in_scope
== builder
->get_file_symbols ()
19100 && cu
->lang () == language_cplus
19101 ? builder
->get_global_symbols ()
19102 : cu
->list_in_scope
);
19104 /* The semantics of C++ state that "struct foo {
19105 ... }" also defines a typedef for "foo". */
19106 if (cu
->lang () == language_cplus
19107 || cu
->lang () == language_ada
19108 || cu
->lang () == language_d
19109 || cu
->lang () == language_rust
)
19111 /* The symbol's name is already allocated along
19112 with this objfile, so we don't need to
19113 duplicate it for the type. */
19114 if (sym
->type ()->name () == 0)
19115 sym
->type ()->set_name (sym
->search_name ());
19120 case DW_TAG_typedef
:
19121 sym
->set_aclass_index (LOC_TYPEDEF
);
19122 sym
->set_domain (VAR_DOMAIN
);
19123 list_to_add
= cu
->list_in_scope
;
19125 case DW_TAG_array_type
:
19126 case DW_TAG_base_type
:
19127 case DW_TAG_subrange_type
:
19128 case DW_TAG_generic_subrange
:
19129 case DW_TAG_unspecified_type
:
19130 sym
->set_aclass_index (LOC_TYPEDEF
);
19131 sym
->set_domain (VAR_DOMAIN
);
19132 list_to_add
= cu
->list_in_scope
;
19134 case DW_TAG_enumerator
:
19135 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19136 if (attr
!= nullptr)
19138 dwarf2_const_value (attr
, sym
, cu
);
19141 /* NOTE: carlton/2003-11-10: See comment above in the
19142 DW_TAG_class_type, etc. block. */
19145 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
19146 && cu
->lang () == language_cplus
19147 ? cu
->get_builder ()->get_global_symbols ()
19148 : cu
->list_in_scope
);
19151 case DW_TAG_imported_declaration
:
19152 case DW_TAG_namespace
:
19153 sym
->set_aclass_index (LOC_TYPEDEF
);
19154 list_to_add
= cu
->get_builder ()->get_global_symbols ();
19156 case DW_TAG_module
:
19157 sym
->set_aclass_index (LOC_TYPEDEF
);
19158 sym
->set_domain (MODULE_DOMAIN
);
19159 list_to_add
= cu
->get_builder ()->get_global_symbols ();
19161 case DW_TAG_common_block
:
19162 sym
->set_aclass_index (LOC_COMMON_BLOCK
);
19163 sym
->set_domain (COMMON_BLOCK_DOMAIN
);
19164 add_symbol_to_list (sym
, cu
->list_in_scope
);
19167 /* Not a tag we recognize. Hopefully we aren't processing
19168 trash data, but since we must specifically ignore things
19169 we don't recognize, there is nothing else we should do at
19171 complaint (_("unsupported tag: '%s'"),
19172 dwarf_tag_name (die
->tag
));
19178 sym
->hash_next
= objfile
->template_symbols
;
19179 objfile
->template_symbols
= sym
;
19180 list_to_add
= NULL
;
19183 if (list_to_add
!= NULL
)
19184 add_symbol_to_list (sym
, list_to_add
);
19186 /* For the benefit of old versions of GCC, check for anonymous
19187 namespaces based on the demangled name. */
19188 if (!cu
->processing_has_namespace_info
19189 && cu
->lang () == language_cplus
)
19190 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
19195 /* Given an attr with a DW_FORM_dataN value in host byte order,
19196 zero-extend it as appropriate for the symbol's type. The DWARF
19197 standard (v4) is not entirely clear about the meaning of using
19198 DW_FORM_dataN for a constant with a signed type, where the type is
19199 wider than the data. The conclusion of a discussion on the DWARF
19200 list was that this is unspecified. We choose to always zero-extend
19201 because that is the interpretation long in use by GCC. */
19204 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19205 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19207 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19208 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
.get ()) ?
19209 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19210 LONGEST l
= attr
->constant_value (0);
19212 if (bits
< sizeof (*value
) * 8)
19214 l
&= ((LONGEST
) 1 << bits
) - 1;
19217 else if (bits
== sizeof (*value
) * 8)
19221 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19222 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19229 /* Read a constant value from an attribute. Either set *VALUE, or if
19230 the value does not fit in *VALUE, set *BYTES - either already
19231 allocated on the objfile obstack, or newly allocated on OBSTACK,
19232 or, set *BATON, if we translated the constant to a location
19236 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19237 const char *name
, struct obstack
*obstack
,
19238 struct dwarf2_cu
*cu
,
19239 LONGEST
*value
, const gdb_byte
**bytes
,
19240 struct dwarf2_locexpr_baton
**baton
)
19242 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19243 struct objfile
*objfile
= per_objfile
->objfile
;
19244 struct comp_unit_head
*cu_header
= &cu
->header
;
19245 struct dwarf_block
*blk
;
19246 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
.get ()) ?
19247 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19253 switch (attr
->form
)
19256 case DW_FORM_addrx
:
19257 case DW_FORM_GNU_addr_index
:
19261 if (type
->length () != cu_header
->addr_size
)
19262 dwarf2_const_value_length_mismatch_complaint (name
,
19263 cu_header
->addr_size
,
19265 /* Symbols of this form are reasonably rare, so we just
19266 piggyback on the existing location code rather than writing
19267 a new implementation of symbol_computed_ops. */
19268 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19269 (*baton
)->per_objfile
= per_objfile
;
19270 (*baton
)->per_cu
= cu
->per_cu
;
19271 gdb_assert ((*baton
)->per_cu
);
19273 (*baton
)->size
= 2 + cu_header
->addr_size
;
19274 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19275 (*baton
)->data
= data
;
19277 data
[0] = DW_OP_addr
;
19278 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19279 byte_order
, attr
->as_address ());
19280 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19283 case DW_FORM_string
:
19286 case DW_FORM_GNU_str_index
:
19287 case DW_FORM_GNU_strp_alt
:
19288 /* The string is already allocated on the objfile obstack, point
19290 *bytes
= (const gdb_byte
*) attr
->as_string ();
19292 case DW_FORM_block1
:
19293 case DW_FORM_block2
:
19294 case DW_FORM_block4
:
19295 case DW_FORM_block
:
19296 case DW_FORM_exprloc
:
19297 case DW_FORM_data16
:
19298 blk
= attr
->as_block ();
19299 if (type
->length () != blk
->size
)
19300 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19302 *bytes
= blk
->data
;
19305 /* The DW_AT_const_value attributes are supposed to carry the
19306 symbol's value "represented as it would be on the target
19307 architecture." By the time we get here, it's already been
19308 converted to host endianness, so we just need to sign- or
19309 zero-extend it as appropriate. */
19310 case DW_FORM_data1
:
19311 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19313 case DW_FORM_data2
:
19314 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19316 case DW_FORM_data4
:
19317 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19319 case DW_FORM_data8
:
19320 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19323 case DW_FORM_sdata
:
19324 case DW_FORM_implicit_const
:
19325 *value
= attr
->as_signed ();
19328 case DW_FORM_udata
:
19329 *value
= attr
->as_unsigned ();
19333 complaint (_("unsupported const value attribute form: '%s'"),
19334 dwarf_form_name (attr
->form
));
19341 /* Copy constant value from an attribute to a symbol. */
19344 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19345 struct dwarf2_cu
*cu
)
19347 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19349 const gdb_byte
*bytes
;
19350 struct dwarf2_locexpr_baton
*baton
;
19352 dwarf2_const_value_attr (attr
, sym
->type (),
19353 sym
->print_name (),
19354 &objfile
->objfile_obstack
, cu
,
19355 &value
, &bytes
, &baton
);
19359 SYMBOL_LOCATION_BATON (sym
) = baton
;
19360 sym
->set_aclass_index (dwarf2_locexpr_index
);
19362 else if (bytes
!= NULL
)
19364 sym
->set_value_bytes (bytes
);
19365 sym
->set_aclass_index (LOC_CONST_BYTES
);
19369 sym
->set_value_longest (value
);
19370 sym
->set_aclass_index (LOC_CONST
);
19374 /* Return the type of the die in question using its DW_AT_type attribute. */
19376 static struct type
*
19377 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19379 struct attribute
*type_attr
;
19381 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19384 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19385 /* A missing DW_AT_type represents a void type. */
19386 return objfile_type (objfile
)->builtin_void
;
19389 return lookup_die_type (die
, type_attr
, cu
);
19392 /* True iff CU's producer generates GNAT Ada auxiliary information
19393 that allows to find parallel types through that information instead
19394 of having to do expensive parallel lookups by type name. */
19397 need_gnat_info (struct dwarf2_cu
*cu
)
19399 /* Assume that the Ada compiler was GNAT, which always produces
19400 the auxiliary information. */
19401 return (cu
->lang () == language_ada
);
19404 /* Return the auxiliary type of the die in question using its
19405 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19406 attribute is not present. */
19408 static struct type
*
19409 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19411 struct attribute
*type_attr
;
19413 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19417 return lookup_die_type (die
, type_attr
, cu
);
19420 /* If DIE has a descriptive_type attribute, then set the TYPE's
19421 descriptive type accordingly. */
19424 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19425 struct dwarf2_cu
*cu
)
19427 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19429 if (descriptive_type
)
19431 ALLOCATE_GNAT_AUX_TYPE (type
);
19432 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19436 /* Return the containing type of the die in question using its
19437 DW_AT_containing_type attribute. */
19439 static struct type
*
19440 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19442 struct attribute
*type_attr
;
19443 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19445 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19447 error (_("Dwarf Error: Problem turning containing type into gdb type "
19448 "[in module %s]"), objfile_name (objfile
));
19450 return lookup_die_type (die
, type_attr
, cu
);
19453 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19455 static struct type
*
19456 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19458 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19459 struct objfile
*objfile
= per_objfile
->objfile
;
19462 std::string message
19463 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
19464 objfile_name (objfile
),
19465 sect_offset_str (cu
->header
.sect_off
),
19466 sect_offset_str (die
->sect_off
));
19467 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
19469 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19472 /* Look up the type of DIE in CU using its type attribute ATTR.
19473 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19474 DW_AT_containing_type.
19475 If there is no type substitute an error marker. */
19477 static struct type
*
19478 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19479 struct dwarf2_cu
*cu
)
19481 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19482 struct objfile
*objfile
= per_objfile
->objfile
;
19483 struct type
*this_type
;
19485 gdb_assert (attr
->name
== DW_AT_type
19486 || attr
->name
== DW_AT_GNAT_descriptive_type
19487 || attr
->name
== DW_AT_containing_type
);
19489 /* First see if we have it cached. */
19491 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19493 struct dwarf2_per_cu_data
*per_cu
;
19494 sect_offset sect_off
= attr
->get_ref_die_offset ();
19496 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
19497 per_objfile
->per_bfd
);
19498 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
19500 else if (attr
->form_is_ref ())
19502 sect_offset sect_off
= attr
->get_ref_die_offset ();
19504 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
19506 else if (attr
->form
== DW_FORM_ref_sig8
)
19508 ULONGEST signature
= attr
->as_signature ();
19510 return get_signatured_type (die
, signature
, cu
);
19514 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
19515 " at %s [in module %s]"),
19516 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
19517 objfile_name (objfile
));
19518 return build_error_marker_type (cu
, die
);
19521 /* If not cached we need to read it in. */
19523 if (this_type
== NULL
)
19525 struct die_info
*type_die
= NULL
;
19526 struct dwarf2_cu
*type_cu
= cu
;
19528 if (attr
->form_is_ref ())
19529 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19530 if (type_die
== NULL
)
19531 return build_error_marker_type (cu
, die
);
19532 /* If we find the type now, it's probably because the type came
19533 from an inter-CU reference and the type's CU got expanded before
19535 this_type
= read_type_die (type_die
, type_cu
);
19538 /* If we still don't have a type use an error marker. */
19540 if (this_type
== NULL
)
19541 return build_error_marker_type (cu
, die
);
19546 /* Return the type in DIE, CU.
19547 Returns NULL for invalid types.
19549 This first does a lookup in die_type_hash,
19550 and only reads the die in if necessary.
19552 NOTE: This can be called when reading in partial or full symbols. */
19554 static struct type
*
19555 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19557 struct type
*this_type
;
19559 this_type
= get_die_type (die
, cu
);
19563 return read_type_die_1 (die
, cu
);
19566 /* Read the type in DIE, CU.
19567 Returns NULL for invalid types. */
19569 static struct type
*
19570 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19572 struct type
*this_type
= NULL
;
19576 case DW_TAG_class_type
:
19577 case DW_TAG_interface_type
:
19578 case DW_TAG_structure_type
:
19579 case DW_TAG_union_type
:
19580 this_type
= read_structure_type (die
, cu
);
19582 case DW_TAG_enumeration_type
:
19583 this_type
= read_enumeration_type (die
, cu
);
19585 case DW_TAG_subprogram
:
19586 case DW_TAG_subroutine_type
:
19587 case DW_TAG_inlined_subroutine
:
19588 this_type
= read_subroutine_type (die
, cu
);
19590 case DW_TAG_array_type
:
19591 this_type
= read_array_type (die
, cu
);
19593 case DW_TAG_set_type
:
19594 this_type
= read_set_type (die
, cu
);
19596 case DW_TAG_pointer_type
:
19597 this_type
= read_tag_pointer_type (die
, cu
);
19599 case DW_TAG_ptr_to_member_type
:
19600 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19602 case DW_TAG_reference_type
:
19603 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
19605 case DW_TAG_rvalue_reference_type
:
19606 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
19608 case DW_TAG_const_type
:
19609 this_type
= read_tag_const_type (die
, cu
);
19611 case DW_TAG_volatile_type
:
19612 this_type
= read_tag_volatile_type (die
, cu
);
19614 case DW_TAG_restrict_type
:
19615 this_type
= read_tag_restrict_type (die
, cu
);
19617 case DW_TAG_string_type
:
19618 this_type
= read_tag_string_type (die
, cu
);
19620 case DW_TAG_typedef
:
19621 this_type
= read_typedef (die
, cu
);
19623 case DW_TAG_generic_subrange
:
19624 case DW_TAG_subrange_type
:
19625 this_type
= read_subrange_type (die
, cu
);
19627 case DW_TAG_base_type
:
19628 this_type
= read_base_type (die
, cu
);
19630 case DW_TAG_unspecified_type
:
19631 this_type
= read_unspecified_type (die
, cu
);
19633 case DW_TAG_namespace
:
19634 this_type
= read_namespace_type (die
, cu
);
19636 case DW_TAG_module
:
19637 this_type
= read_module_type (die
, cu
);
19639 case DW_TAG_atomic_type
:
19640 this_type
= read_tag_atomic_type (die
, cu
);
19643 complaint (_("unexpected tag in read_type_die: '%s'"),
19644 dwarf_tag_name (die
->tag
));
19651 /* See if we can figure out if the class lives in a namespace. We do
19652 this by looking for a member function; its demangled name will
19653 contain namespace info, if there is any.
19654 Return the computed name or NULL.
19655 Space for the result is allocated on the objfile's obstack.
19656 This is the full-die version of guess_partial_die_structure_name.
19657 In this case we know DIE has no useful parent. */
19659 static const char *
19660 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19662 struct die_info
*spec_die
;
19663 struct dwarf2_cu
*spec_cu
;
19664 struct die_info
*child
;
19665 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19668 spec_die
= die_specification (die
, &spec_cu
);
19669 if (spec_die
!= NULL
)
19675 for (child
= die
->child
;
19677 child
= child
->sibling
)
19679 if (child
->tag
== DW_TAG_subprogram
)
19681 const char *linkage_name
= dw2_linkage_name (child
, cu
);
19683 if (linkage_name
!= NULL
)
19685 gdb::unique_xmalloc_ptr
<char> actual_name
19686 (cu
->language_defn
->class_name_from_physname (linkage_name
));
19687 const char *name
= NULL
;
19689 if (actual_name
!= NULL
)
19691 const char *die_name
= dwarf2_name (die
, cu
);
19693 if (die_name
!= NULL
19694 && strcmp (die_name
, actual_name
.get ()) != 0)
19696 /* Strip off the class name from the full name.
19697 We want the prefix. */
19698 int die_name_len
= strlen (die_name
);
19699 int actual_name_len
= strlen (actual_name
.get ());
19700 const char *ptr
= actual_name
.get ();
19702 /* Test for '::' as a sanity check. */
19703 if (actual_name_len
> die_name_len
+ 2
19704 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
19705 name
= obstack_strndup (
19706 &objfile
->per_bfd
->storage_obstack
,
19707 ptr
, actual_name_len
- die_name_len
- 2);
19718 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19719 prefix part in such case. See
19720 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19722 static const char *
19723 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19725 struct attribute
*attr
;
19728 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19729 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19732 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19735 attr
= dw2_linkage_name_attr (die
, cu
);
19736 const char *attr_name
= attr
->as_string ();
19737 if (attr
== NULL
|| attr_name
== NULL
)
19740 /* dwarf2_name had to be already called. */
19741 gdb_assert (attr
->canonical_string_p ());
19743 /* Strip the base name, keep any leading namespaces/classes. */
19744 base
= strrchr (attr_name
, ':');
19745 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
19748 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19749 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
19751 &base
[-1] - attr_name
);
19754 /* Return the name of the namespace/class that DIE is defined within,
19755 or "" if we can't tell. The caller should not xfree the result.
19757 For example, if we're within the method foo() in the following
19767 then determine_prefix on foo's die will return "N::C". */
19769 static const char *
19770 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19772 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19773 struct die_info
*parent
, *spec_die
;
19774 struct dwarf2_cu
*spec_cu
;
19775 struct type
*parent_type
;
19776 const char *retval
;
19778 if (cu
->lang () != language_cplus
19779 && cu
->lang () != language_fortran
19780 && cu
->lang () != language_d
19781 && cu
->lang () != language_rust
)
19784 retval
= anonymous_struct_prefix (die
, cu
);
19788 /* We have to be careful in the presence of DW_AT_specification.
19789 For example, with GCC 3.4, given the code
19793 // Definition of N::foo.
19797 then we'll have a tree of DIEs like this:
19799 1: DW_TAG_compile_unit
19800 2: DW_TAG_namespace // N
19801 3: DW_TAG_subprogram // declaration of N::foo
19802 4: DW_TAG_subprogram // definition of N::foo
19803 DW_AT_specification // refers to die #3
19805 Thus, when processing die #4, we have to pretend that we're in
19806 the context of its DW_AT_specification, namely the contex of die
19809 spec_die
= die_specification (die
, &spec_cu
);
19810 if (spec_die
== NULL
)
19811 parent
= die
->parent
;
19814 parent
= spec_die
->parent
;
19818 if (parent
== NULL
)
19820 else if (parent
->building_fullname
)
19823 const char *parent_name
;
19825 /* It has been seen on RealView 2.2 built binaries,
19826 DW_TAG_template_type_param types actually _defined_ as
19827 children of the parent class:
19830 template class <class Enum> Class{};
19831 Class<enum E> class_e;
19833 1: DW_TAG_class_type (Class)
19834 2: DW_TAG_enumeration_type (E)
19835 3: DW_TAG_enumerator (enum1:0)
19836 3: DW_TAG_enumerator (enum2:1)
19838 2: DW_TAG_template_type_param
19839 DW_AT_type DW_FORM_ref_udata (E)
19841 Besides being broken debug info, it can put GDB into an
19842 infinite loop. Consider:
19844 When we're building the full name for Class<E>, we'll start
19845 at Class, and go look over its template type parameters,
19846 finding E. We'll then try to build the full name of E, and
19847 reach here. We're now trying to build the full name of E,
19848 and look over the parent DIE for containing scope. In the
19849 broken case, if we followed the parent DIE of E, we'd again
19850 find Class, and once again go look at its template type
19851 arguments, etc., etc. Simply don't consider such parent die
19852 as source-level parent of this die (it can't be, the language
19853 doesn't allow it), and break the loop here. */
19854 name
= dwarf2_name (die
, cu
);
19855 parent_name
= dwarf2_name (parent
, cu
);
19856 complaint (_("template param type '%s' defined within parent '%s'"),
19857 name
? name
: "<unknown>",
19858 parent_name
? parent_name
: "<unknown>");
19862 switch (parent
->tag
)
19864 case DW_TAG_namespace
:
19865 parent_type
= read_type_die (parent
, cu
);
19866 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19867 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19868 Work around this problem here. */
19869 if (cu
->lang () == language_cplus
19870 && strcmp (parent_type
->name (), "::") == 0)
19872 /* We give a name to even anonymous namespaces. */
19873 return parent_type
->name ();
19874 case DW_TAG_class_type
:
19875 case DW_TAG_interface_type
:
19876 case DW_TAG_structure_type
:
19877 case DW_TAG_union_type
:
19878 case DW_TAG_module
:
19879 parent_type
= read_type_die (parent
, cu
);
19880 if (parent_type
->name () != NULL
)
19881 return parent_type
->name ();
19883 /* An anonymous structure is only allowed non-static data
19884 members; no typedefs, no member functions, et cetera.
19885 So it does not need a prefix. */
19887 case DW_TAG_compile_unit
:
19888 case DW_TAG_partial_unit
:
19889 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19890 if (cu
->lang () == language_cplus
19891 && !per_objfile
->per_bfd
->types
.empty ()
19892 && die
->child
!= NULL
19893 && (die
->tag
== DW_TAG_class_type
19894 || die
->tag
== DW_TAG_structure_type
19895 || die
->tag
== DW_TAG_union_type
))
19897 const char *name
= guess_full_die_structure_name (die
, cu
);
19902 case DW_TAG_subprogram
:
19903 /* Nested subroutines in Fortran get a prefix with the name
19904 of the parent's subroutine. */
19905 if (cu
->lang () == language_fortran
)
19907 if ((die
->tag
== DW_TAG_subprogram
)
19908 && (dwarf2_name (parent
, cu
) != NULL
))
19909 return dwarf2_name (parent
, cu
);
19912 case DW_TAG_enumeration_type
:
19913 parent_type
= read_type_die (parent
, cu
);
19914 if (parent_type
->is_declared_class ())
19916 if (parent_type
->name () != NULL
)
19917 return parent_type
->name ();
19920 /* Fall through. */
19922 return determine_prefix (parent
, cu
);
19926 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19927 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19928 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19929 an obconcat, otherwise allocate storage for the result. The CU argument is
19930 used to determine the language and hence, the appropriate separator. */
19932 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
19935 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
19936 int physname
, struct dwarf2_cu
*cu
)
19938 const char *lead
= "";
19941 if (suffix
== NULL
|| suffix
[0] == '\0'
19942 || prefix
== NULL
|| prefix
[0] == '\0')
19944 else if (cu
->lang () == language_d
)
19946 /* For D, the 'main' function could be defined in any module, but it
19947 should never be prefixed. */
19948 if (strcmp (suffix
, "D main") == 0)
19956 else if (cu
->lang () == language_fortran
&& physname
)
19958 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
19959 DW_AT_MIPS_linkage_name is preferred and used instead. */
19967 if (prefix
== NULL
)
19969 if (suffix
== NULL
)
19976 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
19978 strcpy (retval
, lead
);
19979 strcat (retval
, prefix
);
19980 strcat (retval
, sep
);
19981 strcat (retval
, suffix
);
19986 /* We have an obstack. */
19987 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
19991 /* Return a generic name for a DW_TAG_template_type_param or
19992 DW_TAG_template_value_param tag, missing a DW_AT_name attribute. We do this
19993 per parent, so each function/class/struct template will have their own set
19994 of template parameters named <unnnamed0>, <unnamed1>, ... where the
19995 enumeration starts at 0 and represents the position of the template tag in
19996 the list of unnamed template tags for this parent, counting both, type and
19999 static const char *
20000 unnamed_template_tag_name (die_info
*die
, dwarf2_cu
*cu
)
20002 if (die
->parent
== nullptr)
20005 /* Count the parent types unnamed template type and value children until, we
20006 arrive at our entry. */
20007 size_t nth_unnamed
= 0;
20009 die_info
*child
= die
->parent
->child
;
20010 while (child
!= die
)
20012 gdb_assert (child
!= nullptr);
20013 if (child
->tag
== DW_TAG_template_type_param
20014 || child
->tag
== DW_TAG_template_value_param
)
20016 if (dwarf2_attr (child
, DW_AT_name
, cu
) == nullptr)
20019 child
= child
->sibling
;
20022 const std::string name_str
= "<unnamed" + std::to_string (nth_unnamed
) + ">";
20023 return cu
->per_objfile
->objfile
->intern (name_str
.c_str ());
20026 /* Get name of a die, return NULL if not found. */
20028 static const char *
20029 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20030 struct objfile
*objfile
)
20032 if (name
== nullptr)
20035 if (cu
->lang () == language_cplus
)
20037 gdb::unique_xmalloc_ptr
<char> canon_name
20038 = cp_canonicalize_string (name
);
20040 if (canon_name
!= nullptr)
20041 name
= objfile
->intern (canon_name
.get ());
20043 else if (cu
->lang () == language_c
)
20045 gdb::unique_xmalloc_ptr
<char> canon_name
20046 = c_canonicalize_name (name
);
20048 if (canon_name
!= nullptr)
20049 name
= objfile
->intern (canon_name
.get ());
20055 /* Get name of a die, return NULL if not found.
20056 Anonymous namespaces are converted to their magic string. */
20058 static const char *
20059 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20061 struct attribute
*attr
;
20062 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20064 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20065 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
20066 if (attr_name
== nullptr
20067 && die
->tag
!= DW_TAG_namespace
20068 && die
->tag
!= DW_TAG_class_type
20069 && die
->tag
!= DW_TAG_interface_type
20070 && die
->tag
!= DW_TAG_structure_type
20071 && die
->tag
!= DW_TAG_namelist
20072 && die
->tag
!= DW_TAG_union_type
20073 && die
->tag
!= DW_TAG_template_type_param
20074 && die
->tag
!= DW_TAG_template_value_param
)
20079 /* A member's name should not be canonicalized. This is a bit
20080 of a hack, in that normally it should not be possible to run
20081 into this situation; however, the dw2-unusual-field-names.exp
20082 test creates custom DWARF that does. */
20083 case DW_TAG_member
:
20084 case DW_TAG_compile_unit
:
20085 case DW_TAG_partial_unit
:
20086 /* Compilation units have a DW_AT_name that is a filename, not
20087 a source language identifier. */
20088 case DW_TAG_enumeration_type
:
20089 case DW_TAG_enumerator
:
20090 /* These tags always have simple identifiers already; no need
20091 to canonicalize them. */
20094 case DW_TAG_namespace
:
20095 if (attr_name
!= nullptr)
20097 return CP_ANONYMOUS_NAMESPACE_STR
;
20099 /* DWARF does not actually require template tags to have a name. */
20100 case DW_TAG_template_type_param
:
20101 case DW_TAG_template_value_param
:
20102 if (attr_name
== nullptr)
20103 return unnamed_template_tag_name (die
, cu
);
20105 case DW_TAG_class_type
:
20106 case DW_TAG_interface_type
:
20107 case DW_TAG_structure_type
:
20108 case DW_TAG_union_type
:
20109 case DW_TAG_namelist
:
20110 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20111 structures or unions. These were of the form "._%d" in GCC 4.1,
20112 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20113 and GCC 4.4. We work around this problem by ignoring these. */
20114 if (attr_name
!= nullptr
20115 && (startswith (attr_name
, "._")
20116 || startswith (attr_name
, "<anonymous")))
20119 /* GCC might emit a nameless typedef that has a linkage name. See
20120 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20121 if (!attr
|| attr_name
== NULL
)
20123 attr
= dw2_linkage_name_attr (die
, cu
);
20124 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
20125 if (attr
== NULL
|| attr_name
== NULL
)
20128 /* Avoid demangling attr_name the second time on a second
20129 call for the same DIE. */
20130 if (!attr
->canonical_string_p ())
20132 gdb::unique_xmalloc_ptr
<char> demangled
20133 (gdb_demangle (attr_name
, DMGL_TYPES
));
20134 if (demangled
== nullptr)
20137 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
20138 attr_name
= attr
->as_string ();
20141 /* Strip any leading namespaces/classes, keep only the
20142 base name. DW_AT_name for named DIEs does not
20143 contain the prefixes. */
20144 const char *base
= strrchr (attr_name
, ':');
20145 if (base
&& base
> attr_name
&& base
[-1] == ':')
20156 if (!attr
->canonical_string_p ())
20157 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
20159 return attr
->as_string ();
20162 /* Return the die that this die in an extension of, or NULL if there
20163 is none. *EXT_CU is the CU containing DIE on input, and the CU
20164 containing the return value on output. */
20166 static struct die_info
*
20167 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20169 struct attribute
*attr
;
20171 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20175 return follow_die_ref (die
, attr
, ext_cu
);
20179 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20183 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
20184 to_underlying (die
->sect_off
),
20190 /* Follow reference or signature attribute ATTR of SRC_DIE.
20191 On entry *REF_CU is the CU of SRC_DIE.
20192 On exit *REF_CU is the CU of the result. */
20194 static struct die_info
*
20195 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20196 struct dwarf2_cu
**ref_cu
)
20198 struct die_info
*die
;
20200 if (attr
->form_is_ref ())
20201 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20202 else if (attr
->form
== DW_FORM_ref_sig8
)
20203 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20206 src_die
->error_dump ();
20207 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20208 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
20214 /* Follow reference OFFSET.
20215 On entry *REF_CU is the CU of the source die referencing OFFSET.
20216 On exit *REF_CU is the CU of the result.
20217 Returns NULL if OFFSET is invalid. */
20219 static struct die_info
*
20220 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
20221 struct dwarf2_cu
**ref_cu
)
20223 struct die_info temp_die
;
20224 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20225 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20227 gdb_assert (cu
->per_cu
!= NULL
);
20231 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
20232 "source CU contains target offset: %d",
20233 sect_offset_str (cu
->per_cu
->sect_off
),
20234 sect_offset_str (sect_off
),
20235 cu
->header
.offset_in_cu_p (sect_off
));
20237 if (cu
->per_cu
->is_debug_types
)
20239 /* .debug_types CUs cannot reference anything outside their CU.
20240 If they need to, they have to reference a signatured type via
20241 DW_FORM_ref_sig8. */
20242 if (!cu
->header
.offset_in_cu_p (sect_off
))
20245 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20246 || !cu
->header
.offset_in_cu_p (sect_off
))
20248 struct dwarf2_per_cu_data
*per_cu
;
20250 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20251 per_objfile
->per_bfd
);
20253 dwarf_read_debug_printf_v ("target CU offset: %s, "
20254 "target CU DIEs loaded: %d",
20255 sect_offset_str (per_cu
->sect_off
),
20256 per_objfile
->get_cu (per_cu
) != nullptr);
20258 /* If necessary, add it to the queue and load its DIEs.
20260 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
20261 it doesn't mean they are currently loaded. Since we require them
20262 to be loaded, we must check for ourselves. */
20263 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->lang ())
20264 || per_objfile
->get_cu (per_cu
) == nullptr)
20265 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
20266 false, cu
->lang ());
20268 target_cu
= per_objfile
->get_cu (per_cu
);
20269 gdb_assert (target_cu
!= nullptr);
20271 else if (cu
->dies
== NULL
)
20273 /* We're loading full DIEs during partial symbol reading. */
20274 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
20278 *ref_cu
= target_cu
;
20279 temp_die
.sect_off
= sect_off
;
20281 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20283 to_underlying (sect_off
));
20286 /* Follow reference attribute ATTR of SRC_DIE.
20287 On entry *REF_CU is the CU of SRC_DIE.
20288 On exit *REF_CU is the CU of the result. */
20290 static struct die_info
*
20291 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20292 struct dwarf2_cu
**ref_cu
)
20294 sect_offset sect_off
= attr
->get_ref_die_offset ();
20295 struct dwarf2_cu
*cu
= *ref_cu
;
20296 struct die_info
*die
;
20298 die
= follow_die_offset (sect_off
,
20299 (attr
->form
== DW_FORM_GNU_ref_alt
20300 || cu
->per_cu
->is_dwz
),
20303 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
20304 "at %s [in module %s]"),
20305 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
20306 objfile_name (cu
->per_objfile
->objfile
));
20313 struct dwarf2_locexpr_baton
20314 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
20315 dwarf2_per_cu_data
*per_cu
,
20316 dwarf2_per_objfile
*per_objfile
,
20317 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
20318 bool resolve_abstract_p
)
20320 struct die_info
*die
;
20321 struct attribute
*attr
;
20322 struct dwarf2_locexpr_baton retval
;
20323 struct objfile
*objfile
= per_objfile
->objfile
;
20325 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20327 cu
= load_cu (per_cu
, per_objfile
, false);
20331 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20332 Instead just throw an error, not much else we can do. */
20333 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
20334 sect_offset_str (sect_off
), objfile_name (objfile
));
20337 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20339 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
20340 sect_offset_str (sect_off
), objfile_name (objfile
));
20342 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20343 if (!attr
&& resolve_abstract_p
20344 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
20345 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
20347 CORE_ADDR pc
= get_frame_pc ();
20348 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
20349 struct gdbarch
*gdbarch
= objfile
->arch ();
20351 for (const auto &cand_off
20352 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
20354 struct dwarf2_cu
*cand_cu
= cu
;
20355 struct die_info
*cand
20356 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
20359 || cand
->parent
->tag
!= DW_TAG_subprogram
)
20362 CORE_ADDR pc_low
, pc_high
;
20363 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
20364 if (pc_low
== ((CORE_ADDR
) -1))
20366 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
20367 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
20368 if (!(pc_low
<= pc
&& pc
< pc_high
))
20372 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20379 /* DWARF: "If there is no such attribute, then there is no effect.".
20380 DATA is ignored if SIZE is 0. */
20382 retval
.data
= NULL
;
20385 else if (attr
->form_is_section_offset ())
20387 struct dwarf2_loclist_baton loclist_baton
;
20388 CORE_ADDR pc
= get_frame_pc ();
20391 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20393 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20395 retval
.size
= size
;
20399 if (!attr
->form_is_block ())
20400 error (_("Dwarf Error: DIE at %s referenced in module %s "
20401 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20402 sect_offset_str (sect_off
), objfile_name (objfile
));
20404 struct dwarf_block
*block
= attr
->as_block ();
20405 retval
.data
= block
->data
;
20406 retval
.size
= block
->size
;
20408 retval
.per_objfile
= per_objfile
;
20409 retval
.per_cu
= cu
->per_cu
;
20411 per_objfile
->age_comp_units ();
20418 struct dwarf2_locexpr_baton
20419 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20420 dwarf2_per_cu_data
*per_cu
,
20421 dwarf2_per_objfile
*per_objfile
,
20422 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
20424 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
20426 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
20430 /* Write a constant of a given type as target-ordered bytes into
20433 static const gdb_byte
*
20434 write_constant_as_bytes (struct obstack
*obstack
,
20435 enum bfd_endian byte_order
,
20442 *len
= type
->length ();
20443 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20444 store_unsigned_integer (result
, *len
, byte_order
, value
);
20452 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
20453 dwarf2_per_cu_data
*per_cu
,
20454 dwarf2_per_objfile
*per_objfile
,
20458 struct die_info
*die
;
20459 struct attribute
*attr
;
20460 const gdb_byte
*result
= NULL
;
20463 enum bfd_endian byte_order
;
20464 struct objfile
*objfile
= per_objfile
->objfile
;
20466 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20468 cu
= load_cu (per_cu
, per_objfile
, false);
20472 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20473 Instead just throw an error, not much else we can do. */
20474 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
20475 sect_offset_str (sect_off
), objfile_name (objfile
));
20478 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20480 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
20481 sect_offset_str (sect_off
), objfile_name (objfile
));
20483 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20487 byte_order
= (bfd_big_endian (objfile
->obfd
.get ())
20488 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20490 switch (attr
->form
)
20493 case DW_FORM_addrx
:
20494 case DW_FORM_GNU_addr_index
:
20498 *len
= cu
->header
.addr_size
;
20499 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20500 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
20504 case DW_FORM_string
:
20507 case DW_FORM_GNU_str_index
:
20508 case DW_FORM_GNU_strp_alt
:
20509 /* The string is already allocated on the objfile obstack, point
20512 const char *attr_name
= attr
->as_string ();
20513 result
= (const gdb_byte
*) attr_name
;
20514 *len
= strlen (attr_name
);
20517 case DW_FORM_block1
:
20518 case DW_FORM_block2
:
20519 case DW_FORM_block4
:
20520 case DW_FORM_block
:
20521 case DW_FORM_exprloc
:
20522 case DW_FORM_data16
:
20524 struct dwarf_block
*block
= attr
->as_block ();
20525 result
= block
->data
;
20526 *len
= block
->size
;
20530 /* The DW_AT_const_value attributes are supposed to carry the
20531 symbol's value "represented as it would be on the target
20532 architecture." By the time we get here, it's already been
20533 converted to host endianness, so we just need to sign- or
20534 zero-extend it as appropriate. */
20535 case DW_FORM_data1
:
20536 type
= die_type (die
, cu
);
20537 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20538 if (result
== NULL
)
20539 result
= write_constant_as_bytes (obstack
, byte_order
,
20542 case DW_FORM_data2
:
20543 type
= die_type (die
, cu
);
20544 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20545 if (result
== NULL
)
20546 result
= write_constant_as_bytes (obstack
, byte_order
,
20549 case DW_FORM_data4
:
20550 type
= die_type (die
, cu
);
20551 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20552 if (result
== NULL
)
20553 result
= write_constant_as_bytes (obstack
, byte_order
,
20556 case DW_FORM_data8
:
20557 type
= die_type (die
, cu
);
20558 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20559 if (result
== NULL
)
20560 result
= write_constant_as_bytes (obstack
, byte_order
,
20564 case DW_FORM_sdata
:
20565 case DW_FORM_implicit_const
:
20566 type
= die_type (die
, cu
);
20567 result
= write_constant_as_bytes (obstack
, byte_order
,
20568 type
, attr
->as_signed (), len
);
20571 case DW_FORM_udata
:
20572 type
= die_type (die
, cu
);
20573 result
= write_constant_as_bytes (obstack
, byte_order
,
20574 type
, attr
->as_unsigned (), len
);
20578 complaint (_("unsupported const value attribute form: '%s'"),
20579 dwarf_form_name (attr
->form
));
20589 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
20590 dwarf2_per_cu_data
*per_cu
,
20591 dwarf2_per_objfile
*per_objfile
,
20592 const char **var_name
)
20594 struct die_info
*die
;
20596 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20598 cu
= load_cu (per_cu
, per_objfile
, false);
20603 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20607 if (var_name
!= nullptr)
20608 *var_name
= var_decl_name (die
, cu
);
20609 return die_type (die
, cu
);
20615 dwarf2_get_die_type (cu_offset die_offset
,
20616 dwarf2_per_cu_data
*per_cu
,
20617 dwarf2_per_objfile
*per_objfile
)
20619 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
20620 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
20623 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20624 On entry *REF_CU is the CU of SRC_DIE.
20625 On exit *REF_CU is the CU of the result.
20626 Returns NULL if the referenced DIE isn't found. */
20628 static struct die_info
*
20629 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20630 struct dwarf2_cu
**ref_cu
)
20632 struct die_info temp_die
;
20633 struct dwarf2_cu
*sig_cu
;
20634 struct die_info
*die
;
20635 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
20638 /* While it might be nice to assert sig_type->type == NULL here,
20639 we can get here for DW_AT_imported_declaration where we need
20640 the DIE not the type. */
20642 /* If necessary, add it to the queue and load its DIEs.
20644 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
20645 it doesn't mean they are currently loaded. Since we require them
20646 to be loaded, we must check for ourselves. */
20647 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
20649 || per_objfile
->get_cu (sig_type
) == nullptr)
20650 read_signatured_type (sig_type
, per_objfile
);
20652 sig_cu
= per_objfile
->get_cu (sig_type
);
20653 gdb_assert (sig_cu
!= NULL
);
20654 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
20655 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
20656 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20657 to_underlying (temp_die
.sect_off
));
20660 /* For .gdb_index version 7 keep track of included TUs.
20661 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20662 if (per_objfile
->per_bfd
->index_table
!= NULL
20663 && !per_objfile
->per_bfd
->index_table
->version_check ())
20665 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
20675 /* Follow signatured type referenced by ATTR in SRC_DIE.
20676 On entry *REF_CU is the CU of SRC_DIE.
20677 On exit *REF_CU is the CU of the result.
20678 The result is the DIE of the type.
20679 If the referenced type cannot be found an error is thrown. */
20681 static struct die_info
*
20682 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20683 struct dwarf2_cu
**ref_cu
)
20685 ULONGEST signature
= attr
->as_signature ();
20686 struct signatured_type
*sig_type
;
20687 struct die_info
*die
;
20689 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20691 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20692 /* sig_type will be NULL if the signatured type is missing from
20694 if (sig_type
== NULL
)
20696 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20697 " from DIE at %s [in module %s]"),
20698 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
20699 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
20702 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20705 src_die
->error_dump ();
20706 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20707 " from DIE at %s [in module %s]"),
20708 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
20709 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
20715 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20716 reading in and processing the type unit if necessary. */
20718 static struct type
*
20719 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20720 struct dwarf2_cu
*cu
)
20722 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20723 struct signatured_type
*sig_type
;
20724 struct dwarf2_cu
*type_cu
;
20725 struct die_info
*type_die
;
20728 sig_type
= lookup_signatured_type (cu
, signature
);
20729 /* sig_type will be NULL if the signatured type is missing from
20731 if (sig_type
== NULL
)
20733 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20734 " from DIE at %s [in module %s]"),
20735 hex_string (signature
), sect_offset_str (die
->sect_off
),
20736 objfile_name (per_objfile
->objfile
));
20737 return build_error_marker_type (cu
, die
);
20740 /* If we already know the type we're done. */
20741 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
20742 if (type
!= nullptr)
20746 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20747 if (type_die
!= NULL
)
20749 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20750 is created. This is important, for example, because for c++ classes
20751 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20752 type
= read_type_die (type_die
, type_cu
);
20755 complaint (_("Dwarf Error: Cannot build signatured type %s"
20756 " referenced from DIE at %s [in module %s]"),
20757 hex_string (signature
), sect_offset_str (die
->sect_off
),
20758 objfile_name (per_objfile
->objfile
));
20759 type
= build_error_marker_type (cu
, die
);
20764 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20765 " from DIE at %s [in module %s]"),
20766 hex_string (signature
), sect_offset_str (die
->sect_off
),
20767 objfile_name (per_objfile
->objfile
));
20768 type
= build_error_marker_type (cu
, die
);
20771 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
20776 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
20777 reading in and processing the type unit if necessary. */
20779 static struct type
*
20780 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
20781 struct dwarf2_cu
*cu
) /* ARI: editCase function */
20783 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
20784 if (attr
->form_is_ref ())
20786 struct dwarf2_cu
*type_cu
= cu
;
20787 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
20789 return read_type_die (type_die
, type_cu
);
20791 else if (attr
->form
== DW_FORM_ref_sig8
)
20793 return get_signatured_type (die
, attr
->as_signature (), cu
);
20797 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20799 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
20800 " at %s [in module %s]"),
20801 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
20802 objfile_name (per_objfile
->objfile
));
20803 return build_error_marker_type (cu
, die
);
20807 /* Load the DIEs associated with type unit PER_CU into memory. */
20810 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
20811 dwarf2_per_objfile
*per_objfile
)
20813 struct signatured_type
*sig_type
;
20815 /* We have the per_cu, but we need the signatured_type.
20816 Fortunately this is an easy translation. */
20817 gdb_assert (per_cu
->is_debug_types
);
20818 sig_type
= (struct signatured_type
*) per_cu
;
20820 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
20822 read_signatured_type (sig_type
, per_objfile
);
20824 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
20827 /* Read in a signatured type and build its CU and DIEs.
20828 If the type is a stub for the real type in a DWO file,
20829 read in the real type from the DWO file as well. */
20832 read_signatured_type (signatured_type
*sig_type
,
20833 dwarf2_per_objfile
*per_objfile
)
20835 gdb_assert (sig_type
->is_debug_types
);
20836 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
20838 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
20840 if (!reader
.dummy_p
)
20842 struct dwarf2_cu
*cu
= reader
.cu
;
20843 const gdb_byte
*info_ptr
= reader
.info_ptr
;
20845 gdb_assert (cu
->die_hash
== NULL
);
20847 htab_create_alloc_ex (cu
->header
.get_length_without_initial () / 12,
20851 &cu
->comp_unit_obstack
,
20852 hashtab_obstack_allocate
,
20853 dummy_obstack_deallocate
);
20855 if (reader
.comp_unit_die
->has_children
)
20856 reader
.comp_unit_die
->child
20857 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
20858 reader
.comp_unit_die
);
20859 cu
->dies
= reader
.comp_unit_die
;
20860 /* comp_unit_die is not stored in die_hash, no need. */
20862 /* We try not to read any attributes in this function, because
20863 not all CUs needed for references have been loaded yet, and
20864 symbol table processing isn't initialized. But we have to
20865 set the CU language, or we won't be able to build types
20866 correctly. Similarly, if we do not read the producer, we can
20867 not apply producer-specific interpretation. */
20868 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
20873 sig_type
->tu_read
= 1;
20876 /* Decode simple location descriptions.
20877 Given a pointer to a dwarf block that defines a location, compute
20878 the location and return the value. If COMPUTED is non-null, it is
20879 set to true to indicate that decoding was successful, and false
20880 otherwise. If COMPUTED is null, then this function may emit a
20884 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
20886 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20888 size_t size
= blk
->size
;
20889 const gdb_byte
*data
= blk
->data
;
20890 CORE_ADDR stack
[64];
20892 unsigned int bytes_read
, unsnd
;
20895 if (computed
!= nullptr)
20901 stack
[++stacki
] = 0;
20940 stack
[++stacki
] = op
- DW_OP_lit0
;
20975 stack
[++stacki
] = op
- DW_OP_reg0
;
20978 if (computed
== nullptr)
20979 dwarf2_complex_location_expr_complaint ();
20986 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
20988 stack
[++stacki
] = unsnd
;
20991 if (computed
== nullptr)
20992 dwarf2_complex_location_expr_complaint ();
20999 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
.get (),
21005 case DW_OP_const1u
:
21006 stack
[++stacki
] = read_1_byte (objfile
->obfd
.get (), &data
[i
]);
21010 case DW_OP_const1s
:
21011 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
.get (), &data
[i
]);
21015 case DW_OP_const2u
:
21016 stack
[++stacki
] = read_2_bytes (objfile
->obfd
.get (), &data
[i
]);
21020 case DW_OP_const2s
:
21021 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
.get (), &data
[i
]);
21025 case DW_OP_const4u
:
21026 stack
[++stacki
] = read_4_bytes (objfile
->obfd
.get (), &data
[i
]);
21030 case DW_OP_const4s
:
21031 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
.get (), &data
[i
]);
21035 case DW_OP_const8u
:
21036 stack
[++stacki
] = read_8_bytes (objfile
->obfd
.get (), &data
[i
]);
21041 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21047 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21052 stack
[stacki
+ 1] = stack
[stacki
];
21057 stack
[stacki
- 1] += stack
[stacki
];
21061 case DW_OP_plus_uconst
:
21062 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21068 stack
[stacki
- 1] -= stack
[stacki
];
21073 /* If we're not the last op, then we definitely can't encode
21074 this using GDB's address_class enum. This is valid for partial
21075 global symbols, although the variable's address will be bogus
21079 if (computed
== nullptr)
21080 dwarf2_complex_location_expr_complaint ();
21086 case DW_OP_GNU_push_tls_address
:
21087 case DW_OP_form_tls_address
:
21088 /* The top of the stack has the offset from the beginning
21089 of the thread control block at which the variable is located. */
21090 /* Nothing should follow this operator, so the top of stack would
21092 /* This is valid for partial global symbols, but the variable's
21093 address will be bogus in the psymtab. Make it always at least
21094 non-zero to not look as a variable garbage collected by linker
21095 which have DW_OP_addr 0. */
21098 if (computed
== nullptr)
21099 dwarf2_complex_location_expr_complaint ();
21106 case DW_OP_GNU_uninit
:
21107 if (computed
!= nullptr)
21112 case DW_OP_GNU_addr_index
:
21113 case DW_OP_GNU_const_index
:
21114 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21120 if (computed
== nullptr)
21122 const char *name
= get_DW_OP_name (op
);
21125 complaint (_("unsupported stack op: '%s'"),
21128 complaint (_("unsupported stack op: '%02x'"),
21132 return (stack
[stacki
]);
21135 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21136 outside of the allocated space. Also enforce minimum>0. */
21137 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21139 if (computed
== nullptr)
21140 complaint (_("location description stack overflow"));
21146 if (computed
== nullptr)
21147 complaint (_("location description stack underflow"));
21152 if (computed
!= nullptr)
21154 return (stack
[stacki
]);
21157 /* memory allocation interface */
21159 static struct dwarf_block
*
21160 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21162 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21167 /* Macro support. */
21169 /* An overload of dwarf_decode_macros that finds the correct section
21170 and ensures it is read in before calling the other overload. */
21173 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
21174 int section_is_gnu
)
21176 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21177 struct objfile
*objfile
= per_objfile
->objfile
;
21178 const struct line_header
*lh
= cu
->line_header
;
21179 unsigned int offset_size
= cu
->header
.offset_size
;
21180 struct dwarf2_section_info
*section
;
21181 const char *section_name
;
21183 if (cu
->dwo_unit
!= nullptr)
21185 if (section_is_gnu
)
21187 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
21188 section_name
= ".debug_macro.dwo";
21192 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
21193 section_name
= ".debug_macinfo.dwo";
21198 if (section_is_gnu
)
21200 section
= &per_objfile
->per_bfd
->macro
;
21201 section_name
= ".debug_macro";
21205 section
= &per_objfile
->per_bfd
->macinfo
;
21206 section_name
= ".debug_macinfo";
21210 section
->read (objfile
);
21211 if (section
->buffer
== nullptr)
21213 complaint (_("missing %s section"), section_name
);
21217 buildsym_compunit
*builder
= cu
->get_builder ();
21219 struct dwarf2_section_info
*str_offsets_section
;
21220 struct dwarf2_section_info
*str_section
;
21221 gdb::optional
<ULONGEST
> str_offsets_base
;
21223 if (cu
->dwo_unit
!= nullptr)
21225 str_offsets_section
= &cu
->dwo_unit
->dwo_file
21226 ->sections
.str_offsets
;
21227 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
21228 str_offsets_base
= cu
->header
.addr_size
;
21232 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
21233 str_section
= &per_objfile
->per_bfd
->str
;
21234 str_offsets_base
= cu
->str_offsets_base
;
21237 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
21238 offset_size
, offset
, str_section
, str_offsets_section
,
21239 str_offsets_base
, section_is_gnu
, cu
);
21242 /* Return the .debug_loc section to use for CU.
21243 For DWO files use .debug_loc.dwo. */
21245 static struct dwarf2_section_info
*
21246 cu_debug_loc_section (struct dwarf2_cu
*cu
)
21248 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21252 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
21254 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
21256 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
21257 : &per_objfile
->per_bfd
->loc
);
21260 /* Return the .debug_rnglists section to use for CU. */
21261 static struct dwarf2_section_info
*
21262 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
21264 if (cu
->header
.version
< 5)
21265 error (_(".debug_rnglists section cannot be used in DWARF %d"),
21266 cu
->header
.version
);
21267 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21269 /* Make sure we read the .debug_rnglists section from the file that
21270 contains the DW_AT_ranges attribute we are reading. Normally that
21271 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
21272 or DW_TAG_skeleton unit, we always want to read from objfile/linked
21274 if (cu
->dwo_unit
!= nullptr
21275 && tag
!= DW_TAG_compile_unit
21276 && tag
!= DW_TAG_skeleton_unit
)
21278 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
21280 if (sections
->rnglists
.size
> 0)
21281 return §ions
->rnglists
;
21283 error (_(".debug_rnglists section is missing from .dwo file."));
21285 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
21288 /* A helper function that fills in a dwarf2_loclist_baton. */
21291 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
21292 struct dwarf2_loclist_baton
*baton
,
21293 const struct attribute
*attr
)
21295 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21296 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21298 section
->read (per_objfile
->objfile
);
21300 baton
->per_objfile
= per_objfile
;
21301 baton
->per_cu
= cu
->per_cu
;
21302 gdb_assert (baton
->per_cu
);
21303 /* We don't know how long the location list is, but make sure we
21304 don't run off the edge of the section. */
21305 baton
->size
= section
->size
- attr
->as_unsigned ();
21306 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
21307 if (cu
->base_address
.has_value ())
21308 baton
->base_address
= *cu
->base_address
;
21310 baton
->base_address
= 0;
21311 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
21315 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
21316 struct dwarf2_cu
*cu
, int is_block
)
21318 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21319 struct objfile
*objfile
= per_objfile
->objfile
;
21320 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21322 if (attr
->form_is_section_offset ()
21323 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
21324 the section. If so, fall through to the complaint in the
21326 && attr
->as_unsigned () < section
->get_size (objfile
))
21328 struct dwarf2_loclist_baton
*baton
;
21330 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
21332 fill_in_loclist_baton (cu
, baton
, attr
);
21334 if (!cu
->base_address
.has_value ())
21335 complaint (_("Location list used without "
21336 "specifying the CU base address."));
21338 sym
->set_aclass_index ((is_block
21339 ? dwarf2_loclist_block_index
21340 : dwarf2_loclist_index
));
21341 SYMBOL_LOCATION_BATON (sym
) = baton
;
21345 struct dwarf2_locexpr_baton
*baton
;
21347 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
21348 baton
->per_objfile
= per_objfile
;
21349 baton
->per_cu
= cu
->per_cu
;
21350 gdb_assert (baton
->per_cu
);
21352 if (attr
->form_is_block ())
21354 /* Note that we're just copying the block's data pointer
21355 here, not the actual data. We're still pointing into the
21356 info_buffer for SYM's objfile; right now we never release
21357 that buffer, but when we do clean up properly this may
21359 struct dwarf_block
*block
= attr
->as_block ();
21360 baton
->size
= block
->size
;
21361 baton
->data
= block
->data
;
21365 dwarf2_invalid_attrib_class_complaint ("location description",
21366 sym
->natural_name ());
21370 sym
->set_aclass_index ((is_block
21371 ? dwarf2_locexpr_block_index
21372 : dwarf2_locexpr_index
));
21373 SYMBOL_LOCATION_BATON (sym
) = baton
;
21379 const comp_unit_head
*
21380 dwarf2_per_cu_data::get_header () const
21382 if (!m_header_read_in
)
21384 const gdb_byte
*info_ptr
21385 = this->section
->buffer
+ to_underlying (this->sect_off
);
21387 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
21388 rcuh_kind::COMPILE
);
21390 m_header_read_in
= true;
21399 dwarf2_per_cu_data::addr_size () const
21401 return this->get_header ()->addr_size
;
21407 dwarf2_per_cu_data::offset_size () const
21409 return this->get_header ()->offset_size
;
21415 dwarf2_per_cu_data::ref_addr_size () const
21417 const comp_unit_head
*header
= this->get_header ();
21419 if (header
->version
== 2)
21420 return header
->addr_size
;
21422 return header
->offset_size
;
21425 /* A helper function for dwarf2_find_containing_comp_unit that returns
21426 the index of the result, and that searches a vector. It will
21427 return a result even if the offset in question does not actually
21428 occur in any CU. This is separate so that it can be unit
21432 dwarf2_find_containing_comp_unit
21433 (sect_offset sect_off
,
21434 unsigned int offset_in_dwz
,
21435 const std::vector
<dwarf2_per_cu_data_up
> &all_units
)
21440 high
= all_units
.size () - 1;
21443 struct dwarf2_per_cu_data
*mid_cu
;
21444 int mid
= low
+ (high
- low
) / 2;
21446 mid_cu
= all_units
[mid
].get ();
21447 if (mid_cu
->is_dwz
> offset_in_dwz
21448 || (mid_cu
->is_dwz
== offset_in_dwz
21449 && mid_cu
->sect_off
+ mid_cu
->length () > sect_off
))
21454 gdb_assert (low
== high
);
21458 /* Locate the .debug_info compilation unit from CU's objfile which contains
21459 the DIE at OFFSET. Raises an error on failure. */
21461 static struct dwarf2_per_cu_data
*
21462 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
21463 unsigned int offset_in_dwz
,
21464 dwarf2_per_bfd
*per_bfd
)
21466 int low
= dwarf2_find_containing_comp_unit
21467 (sect_off
, offset_in_dwz
, per_bfd
->all_units
);
21468 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_units
[low
].get ();
21470 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
21472 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
21473 error (_("Dwarf Error: could not find partial DIE containing "
21474 "offset %s [in module %s]"),
21475 sect_offset_str (sect_off
),
21476 bfd_get_filename (per_bfd
->obfd
));
21478 gdb_assert (per_bfd
->all_units
[low
-1]->sect_off
21480 return per_bfd
->all_units
[low
- 1].get ();
21484 if (low
== per_bfd
->all_units
.size () - 1
21485 && sect_off
>= this_cu
->sect_off
+ this_cu
->length ())
21486 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
21487 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length ());
21494 namespace selftests
{
21495 namespace find_containing_comp_unit
{
21500 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
21501 dwarf2_per_cu_data
*one_ptr
= one
.get ();
21502 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
21503 dwarf2_per_cu_data
*two_ptr
= two
.get ();
21504 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
21505 dwarf2_per_cu_data
*three_ptr
= three
.get ();
21506 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
21507 dwarf2_per_cu_data
*four_ptr
= four
.get ();
21509 one
->set_length (5);
21510 two
->sect_off
= sect_offset (one
->length ());
21511 two
->set_length (7);
21513 three
->set_length (5);
21515 four
->sect_off
= sect_offset (three
->length ());
21516 four
->set_length (7);
21519 std::vector
<dwarf2_per_cu_data_up
> units
;
21520 units
.push_back (std::move (one
));
21521 units
.push_back (std::move (two
));
21522 units
.push_back (std::move (three
));
21523 units
.push_back (std::move (four
));
21527 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
21528 SELF_CHECK (units
[result
].get () == one_ptr
);
21529 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
21530 SELF_CHECK (units
[result
].get () == one_ptr
);
21531 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
21532 SELF_CHECK (units
[result
].get () == two_ptr
);
21534 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
21535 SELF_CHECK (units
[result
].get () == three_ptr
);
21536 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
21537 SELF_CHECK (units
[result
].get () == three_ptr
);
21538 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
21539 SELF_CHECK (units
[result
].get () == four_ptr
);
21545 #endif /* GDB_SELF_TEST */
21547 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
21550 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
21551 enum language pretend_language
)
21553 struct attribute
*attr
;
21555 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
21557 /* Set the language we're debugging. */
21558 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
21559 enum language lang
;
21560 if (cu
->producer
!= nullptr
21561 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
21563 /* The XLCL doesn't generate DW_LANG_OpenCL because this
21564 attribute is not standardised yet. As a workaround for the
21565 language detection we fall back to the DW_AT_producer
21567 lang
= language_opencl
;
21569 else if (cu
->producer
!= nullptr
21570 && strstr (cu
->producer
, "GNU Go ") != NULL
)
21572 /* Similar hack for Go. */
21573 lang
= language_go
;
21575 else if (attr
!= nullptr)
21576 lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
21578 lang
= pretend_language
;
21580 cu
->language_defn
= language_def (lang
);
21582 switch (comp_unit_die
->tag
)
21584 case DW_TAG_compile_unit
:
21585 cu
->per_cu
->set_unit_type (DW_UT_compile
);
21587 case DW_TAG_partial_unit
:
21588 cu
->per_cu
->set_unit_type (DW_UT_partial
);
21590 case DW_TAG_type_unit
:
21591 cu
->per_cu
->set_unit_type (DW_UT_type
);
21594 error (_("Dwarf Error: unexpected tag '%s' at offset %s"),
21595 dwarf_tag_name (comp_unit_die
->tag
),
21596 sect_offset_str (cu
->per_cu
->sect_off
));
21599 cu
->per_cu
->set_lang (lang
);
21605 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
21607 auto it
= m_dwarf2_cus
.find (per_cu
);
21608 if (it
== m_dwarf2_cus
.end ())
21611 return it
->second
.get ();
21617 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
,
21618 std::unique_ptr
<dwarf2_cu
> cu
)
21620 gdb_assert (this->get_cu (per_cu
) == nullptr);
21622 m_dwarf2_cus
[per_cu
] = std::move (cu
);
21628 dwarf2_per_objfile::age_comp_units ()
21630 dwarf_read_debug_printf_v ("running");
21632 /* This is not expected to be called in the middle of CU expansion. There is
21633 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
21634 loaded in memory. Calling age_comp_units while the queue is in use could
21635 make us free the DIEs for a CU that is in the queue and therefore break
21637 gdb_assert (!queue
.has_value ());
21639 /* Start by clearing all marks. */
21640 for (const auto &pair
: m_dwarf2_cus
)
21641 pair
.second
->clear_mark ();
21643 /* Traverse all CUs, mark them and their dependencies if used recently
21645 for (const auto &pair
: m_dwarf2_cus
)
21647 dwarf2_cu
*cu
= pair
.second
.get ();
21650 if (cu
->last_used
<= dwarf_max_cache_age
)
21654 /* Delete all CUs still not marked. */
21655 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
21657 dwarf2_cu
*cu
= it
->second
.get ();
21659 if (!cu
->is_marked ())
21661 dwarf_read_debug_printf_v ("deleting old CU %s",
21662 sect_offset_str (cu
->per_cu
->sect_off
));
21663 it
= m_dwarf2_cus
.erase (it
);
21673 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
21675 auto it
= m_dwarf2_cus
.find (per_cu
);
21676 if (it
== m_dwarf2_cus
.end ())
21679 m_dwarf2_cus
.erase (it
);
21682 dwarf2_per_objfile::~dwarf2_per_objfile ()
21687 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
21688 We store these in a hash table separate from the DIEs, and preserve them
21689 when the DIEs are flushed out of cache.
21691 The CU "per_cu" pointer is needed because offset alone is not enough to
21692 uniquely identify the type. A file may have multiple .debug_types sections,
21693 or the type may come from a DWO file. Furthermore, while it's more logical
21694 to use per_cu->section+offset, with Fission the section with the data is in
21695 the DWO file but we don't know that section at the point we need it.
21696 We have to use something in dwarf2_per_cu_data (or the pointer to it)
21697 because we can enter the lookup routine, get_die_type_at_offset, from
21698 outside this file, and thus won't necessarily have PER_CU->cu.
21699 Fortunately, PER_CU is stable for the life of the objfile. */
21701 struct dwarf2_per_cu_offset_and_type
21703 const struct dwarf2_per_cu_data
*per_cu
;
21704 sect_offset sect_off
;
21708 /* Hash function for a dwarf2_per_cu_offset_and_type. */
21711 per_cu_offset_and_type_hash (const void *item
)
21713 const struct dwarf2_per_cu_offset_and_type
*ofs
21714 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
21716 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
21719 /* Equality function for a dwarf2_per_cu_offset_and_type. */
21722 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
21724 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
21725 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
21726 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
21727 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
21729 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
21730 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
21733 /* Set the type associated with DIE to TYPE. Save it in CU's hash
21734 table if necessary. For convenience, return TYPE.
21736 The DIEs reading must have careful ordering to:
21737 * Not cause infinite loops trying to read in DIEs as a prerequisite for
21738 reading current DIE.
21739 * Not trying to dereference contents of still incompletely read in types
21740 while reading in other DIEs.
21741 * Enable referencing still incompletely read in types just by a pointer to
21742 the type without accessing its fields.
21744 Therefore caller should follow these rules:
21745 * Try to fetch any prerequisite types we may need to build this DIE type
21746 before building the type and calling set_die_type.
21747 * After building type call set_die_type for current DIE as soon as
21748 possible before fetching more types to complete the current type.
21749 * Make the type as complete as possible before fetching more types. */
21751 static struct type
*
21752 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21753 bool skip_data_location
)
21755 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21756 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
21757 struct objfile
*objfile
= per_objfile
->objfile
;
21758 struct attribute
*attr
;
21759 struct dynamic_prop prop
;
21761 /* For Ada types, make sure that the gnat-specific data is always
21762 initialized (if not already set). There are a few types where
21763 we should not be doing so, because the type-specific area is
21764 already used to hold some other piece of info (eg: TYPE_CODE_FLT
21765 where the type-specific area is used to store the floatformat).
21766 But this is not a problem, because the gnat-specific information
21767 is actually not needed for these types. */
21768 if (need_gnat_info (cu
)
21769 && type
->code () != TYPE_CODE_FUNC
21770 && type
->code () != TYPE_CODE_FLT
21771 && type
->code () != TYPE_CODE_METHODPTR
21772 && type
->code () != TYPE_CODE_MEMBERPTR
21773 && type
->code () != TYPE_CODE_METHOD
21774 && type
->code () != TYPE_CODE_FIXED_POINT
21775 && !HAVE_GNAT_AUX_INFO (type
))
21776 INIT_GNAT_SPECIFIC (type
);
21778 /* Read DW_AT_allocated and set in type. */
21779 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
21782 struct type
*prop_type
= cu
->addr_sized_int_type (false);
21783 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
21784 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
21787 /* Read DW_AT_associated and set in type. */
21788 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
21791 struct type
*prop_type
= cu
->addr_sized_int_type (false);
21792 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
21793 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
21796 /* Read DW_AT_rank and set in type. */
21797 attr
= dwarf2_attr (die
, DW_AT_rank
, cu
);
21800 struct type
*prop_type
= cu
->addr_sized_int_type (false);
21801 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
21802 type
->add_dyn_prop (DYN_PROP_RANK
, prop
);
21805 /* Read DW_AT_data_location and set in type. */
21806 if (!skip_data_location
)
21808 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
21809 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
21810 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
21813 if (per_objfile
->die_type_hash
== NULL
)
21814 per_objfile
->die_type_hash
21815 = htab_up (htab_create_alloc (127,
21816 per_cu_offset_and_type_hash
,
21817 per_cu_offset_and_type_eq
,
21818 NULL
, xcalloc
, xfree
));
21820 ofs
.per_cu
= cu
->per_cu
;
21821 ofs
.sect_off
= die
->sect_off
;
21823 slot
= (struct dwarf2_per_cu_offset_and_type
**)
21824 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
21826 complaint (_("A problem internal to GDB: DIE %s has type already set"),
21827 sect_offset_str (die
->sect_off
));
21828 *slot
= XOBNEW (&objfile
->objfile_obstack
,
21829 struct dwarf2_per_cu_offset_and_type
);
21834 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
21835 or return NULL if the die does not have a saved type. */
21837 static struct type
*
21838 get_die_type_at_offset (sect_offset sect_off
,
21839 dwarf2_per_cu_data
*per_cu
,
21840 dwarf2_per_objfile
*per_objfile
)
21842 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
21844 if (per_objfile
->die_type_hash
== NULL
)
21847 ofs
.per_cu
= per_cu
;
21848 ofs
.sect_off
= sect_off
;
21849 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
21850 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
21857 /* Look up the type for DIE in CU in die_type_hash,
21858 or return NULL if DIE does not have a saved type. */
21860 static struct type
*
21861 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21863 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
21866 struct cmd_list_element
*set_dwarf_cmdlist
;
21867 struct cmd_list_element
*show_dwarf_cmdlist
;
21870 show_check_physname (struct ui_file
*file
, int from_tty
,
21871 struct cmd_list_element
*c
, const char *value
)
21874 _("Whether to check \"physname\" is %s.\n"),
21878 void _initialize_dwarf2_read ();
21880 _initialize_dwarf2_read ()
21882 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
21884 Set DWARF specific variables.\n\
21885 Configure DWARF variables such as the cache size."),
21887 Show DWARF specific variables.\n\
21888 Show DWARF variables such as the cache size."),
21889 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
21890 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
21892 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
21893 &dwarf_max_cache_age
, _("\
21894 Set the upper bound on the age of cached DWARF compilation units."), _("\
21895 Show the upper bound on the age of cached DWARF compilation units."), _("\
21896 A higher limit means that cached compilation units will be stored\n\
21897 in memory longer, and more total memory will be used. Zero disables\n\
21898 caching, which can slow down startup."),
21900 show_dwarf_max_cache_age
,
21901 &set_dwarf_cmdlist
,
21902 &show_dwarf_cmdlist
);
21904 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
21905 Set debugging of the DWARF reader."), _("\
21906 Show debugging of the DWARF reader."), _("\
21907 When enabled (non-zero), debugging messages are printed during DWARF\n\
21908 reading and symtab expansion. A value of 1 (one) provides basic\n\
21909 information. A value greater than 1 provides more verbose information."),
21912 &setdebuglist
, &showdebuglist
);
21914 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
21915 Set debugging of the DWARF DIE reader."), _("\
21916 Show debugging of the DWARF DIE reader."), _("\
21917 When enabled (non-zero), DIEs are dumped after they are read in.\n\
21918 The value is the maximum depth to print."),
21921 &setdebuglist
, &showdebuglist
);
21923 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
21924 Set debugging of the dwarf line reader."), _("\
21925 Show debugging of the dwarf line reader."), _("\
21926 When enabled (non-zero), line number entries are dumped as they are read in.\n\
21927 A value of 1 (one) provides basic information.\n\
21928 A value greater than 1 provides more verbose information."),
21931 &setdebuglist
, &showdebuglist
);
21933 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
21934 Set cross-checking of \"physname\" code against demangler."), _("\
21935 Show cross-checking of \"physname\" code against demangler."), _("\
21936 When enabled, GDB's internal \"physname\" code is checked against\n\
21938 NULL
, show_check_physname
,
21939 &setdebuglist
, &showdebuglist
);
21941 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
21942 &dwarf2_locexpr_funcs
);
21943 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
21944 &dwarf2_loclist_funcs
);
21946 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
21947 &dwarf2_block_frame_base_locexpr_funcs
);
21948 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
21949 &dwarf2_block_frame_base_loclist_funcs
);
21952 selftests::register_test ("dw2_expand_symtabs_matching",
21953 selftests::dw2_expand_symtabs_matching::run_test
);
21954 selftests::register_test ("dwarf2_find_containing_comp_unit",
21955 selftests::find_containing_comp_unit::run_test
);