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
*,
762 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
763 struct attribute
*attr
, dwarf_tag tag
);
765 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
767 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
768 dwarf2_section_info
*, sect_offset
);
770 static const char *read_indirect_string
771 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
772 const struct comp_unit_head
*, unsigned int *);
774 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
778 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
781 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
784 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
787 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
788 struct dwarf2_cu
*cu
);
790 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
792 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
793 struct dwarf2_cu
*cu
);
795 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
797 static struct die_info
*die_specification (struct die_info
*die
,
798 struct dwarf2_cu
**);
800 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
801 struct dwarf2_cu
*cu
,
802 const char *comp_dir
);
804 static void dwarf_decode_lines (struct line_header
*,
806 CORE_ADDR
, int decode_mapping
);
808 static void dwarf2_start_subfile (dwarf2_cu
*cu
, const file_entry
&fe
,
809 const line_header
&lh
);
811 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
812 struct dwarf2_cu
*, struct symbol
* = NULL
);
814 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
817 static void dwarf2_const_value_attr (const struct attribute
*attr
,
820 struct obstack
*obstack
,
821 struct dwarf2_cu
*cu
, LONGEST
*value
,
822 const gdb_byte
**bytes
,
823 struct dwarf2_locexpr_baton
**baton
);
825 static struct type
*read_subrange_index_type (struct die_info
*die
,
826 struct dwarf2_cu
*cu
);
828 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
830 static int need_gnat_info (struct dwarf2_cu
*);
832 static struct type
*die_descriptive_type (struct die_info
*,
835 static void set_descriptive_type (struct type
*, struct die_info
*,
838 static struct type
*die_containing_type (struct die_info
*,
841 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
844 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
846 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
848 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
850 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
851 const char *suffix
, int physname
,
852 struct dwarf2_cu
*cu
);
854 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
856 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
858 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
860 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
862 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
864 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
866 /* Return the .debug_loclists section to use for cu. */
867 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
869 /* Return the .debug_rnglists section to use for cu. */
870 static struct dwarf2_section_info
*cu_debug_rnglists_section
871 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
873 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
874 values. Keep the items ordered with increasing constraints compliance. */
877 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
878 PC_BOUNDS_NOT_PRESENT
,
880 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
881 were present but they do not form a valid range of PC addresses. */
884 /* Discontiguous range was found - that is DW_AT_ranges was found. */
887 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
891 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
892 CORE_ADDR
*, CORE_ADDR
*,
897 static void get_scope_pc_bounds (struct die_info
*,
898 CORE_ADDR
*, CORE_ADDR
*,
901 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
902 CORE_ADDR
, struct dwarf2_cu
*);
904 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
907 static void dwarf2_attach_fields_to_type (struct field_info
*,
908 struct type
*, struct dwarf2_cu
*);
910 static void dwarf2_add_member_fn (struct field_info
*,
911 struct die_info
*, struct type
*,
914 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
918 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
920 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
922 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
924 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
926 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
928 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
930 static bool read_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
932 static struct type
*read_module_type (struct die_info
*die
,
933 struct dwarf2_cu
*cu
);
935 static const char *namespace_name (struct die_info
*die
,
936 int *is_anonymous
, struct dwarf2_cu
*);
938 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
940 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
943 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
946 static struct die_info
*read_die_and_siblings_1
947 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
950 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
951 const gdb_byte
*info_ptr
,
952 const gdb_byte
**new_info_ptr
,
953 struct die_info
*parent
);
955 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
956 struct die_info
**, const gdb_byte
*,
959 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
960 struct die_info
**, const gdb_byte
*);
962 static void process_die (struct die_info
*, struct dwarf2_cu
*);
964 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
967 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
969 static const char *dwarf2_full_name (const char *name
,
970 struct die_info
*die
,
971 struct dwarf2_cu
*cu
);
973 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
974 struct dwarf2_cu
*cu
);
976 static struct die_info
*dwarf2_extension (struct die_info
*die
,
977 struct dwarf2_cu
**);
979 static void store_in_ref_table (struct die_info
*,
982 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
983 const struct attribute
*,
984 struct dwarf2_cu
**);
986 static struct die_info
*follow_die_ref (struct die_info
*,
987 const struct attribute
*,
988 struct dwarf2_cu
**);
990 static struct die_info
*follow_die_sig (struct die_info
*,
991 const struct attribute
*,
992 struct dwarf2_cu
**);
994 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
997 static struct type
*get_DW_AT_signature_type (struct die_info
*,
998 const struct attribute
*,
1001 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1002 dwarf2_per_objfile
*per_objfile
);
1004 static void read_signatured_type (signatured_type
*sig_type
,
1005 dwarf2_per_objfile
*per_objfile
);
1007 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1008 struct die_info
*die
, struct dwarf2_cu
*cu
,
1009 struct dynamic_prop
*prop
, struct type
*type
);
1011 /* memory allocation interface */
1013 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1015 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1017 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1018 struct dwarf2_loclist_baton
*baton
,
1019 const struct attribute
*attr
);
1021 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1023 struct dwarf2_cu
*cu
,
1026 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1027 const gdb_byte
*info_ptr
,
1028 const struct abbrev_info
*abbrev
,
1029 bool do_skip_children
= true);
1031 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1032 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1033 dwarf2_per_bfd
*per_bfd
);
1035 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1036 struct die_info
*comp_unit_die
,
1037 enum language pretend_language
);
1039 static struct type
*set_die_type (struct die_info
*, struct type
*,
1040 struct dwarf2_cu
*, bool = false);
1042 static void create_all_units (dwarf2_per_objfile
*per_objfile
);
1044 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1045 dwarf2_per_objfile
*per_objfile
,
1046 dwarf2_cu
*existing_cu
,
1048 enum language pretend_language
);
1050 static void process_full_comp_unit (dwarf2_cu
*cu
,
1051 enum language pretend_language
);
1053 static void process_full_type_unit (dwarf2_cu
*cu
,
1054 enum language pretend_language
);
1056 static struct type
*get_die_type_at_offset (sect_offset
,
1057 dwarf2_per_cu_data
*per_cu
,
1058 dwarf2_per_objfile
*per_objfile
);
1060 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1062 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1063 dwarf2_per_objfile
*per_objfile
,
1064 enum language pretend_language
);
1066 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1068 /* Class, the destructor of which frees all allocated queue entries. This
1069 will only have work to do if an error was thrown while processing the
1070 dwarf. If no error was thrown then the queue entries should have all
1071 been processed, and freed, as we went along. */
1073 class dwarf2_queue_guard
1076 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1077 : m_per_objfile (per_objfile
)
1079 gdb_assert (!m_per_objfile
->queue
.has_value ());
1081 m_per_objfile
->queue
.emplace ();
1084 /* Free any entries remaining on the queue. There should only be
1085 entries left if we hit an error while processing the dwarf. */
1086 ~dwarf2_queue_guard ()
1088 gdb_assert (m_per_objfile
->queue
.has_value ());
1090 m_per_objfile
->queue
.reset ();
1093 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1096 dwarf2_per_objfile
*m_per_objfile
;
1099 dwarf2_queue_item::~dwarf2_queue_item ()
1101 /* Anything still marked queued is likely to be in an
1102 inconsistent state, so discard it. */
1105 per_objfile
->remove_cu (per_cu
);
1110 /* See dwarf2/read.h. */
1113 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1115 if (data
->is_debug_types
)
1116 delete static_cast<signatured_type
*> (data
);
1121 static file_and_directory
&find_file_and_directory
1122 (struct die_info
*die
, struct dwarf2_cu
*cu
);
1124 static const char *compute_include_file_name
1125 (const struct line_header
*lh
,
1126 const file_entry
&fe
,
1127 const file_and_directory
&cu_info
,
1128 std::string
&name_holder
);
1130 static htab_up
allocate_dwo_unit_table ();
1132 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1133 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1134 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1136 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1138 static struct dwo_unit
*lookup_dwo_comp_unit
1139 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1140 ULONGEST signature
);
1142 static struct dwo_unit
*lookup_dwo_type_unit
1143 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1145 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1147 /* A unique pointer to a dwo_file. */
1149 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1151 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1153 static void check_producer (struct dwarf2_cu
*cu
);
1155 /* Various complaints about symbol reading that don't abort the process. */
1158 dwarf2_debug_line_missing_file_complaint (void)
1160 complaint (_(".debug_line section has line data without a file"));
1164 dwarf2_debug_line_missing_end_sequence_complaint (void)
1166 complaint (_(".debug_line section has line "
1167 "program sequence without an end"));
1171 dwarf2_complex_location_expr_complaint (void)
1173 complaint (_("location expression too complex"));
1177 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1180 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1185 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1187 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1191 /* Hash function for line_header_hash. */
1194 line_header_hash (const struct line_header
*ofs
)
1196 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1199 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1202 line_header_hash_voidp (const void *item
)
1204 const struct line_header
*ofs
= (const struct line_header
*) item
;
1206 return line_header_hash (ofs
);
1209 /* Equality function for line_header_hash. */
1212 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1214 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1215 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1217 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1218 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1221 /* See declaration. */
1223 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1226 can_copy (can_copy_
)
1229 names
= &dwarf2_elf_names
;
1231 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1232 locate_sections (obfd
, sec
, *names
);
1235 dwarf2_per_bfd::~dwarf2_per_bfd ()
1237 for (auto &per_cu
: all_units
)
1239 per_cu
->imported_symtabs_free ();
1240 per_cu
->free_cached_file_names ();
1243 /* Everything else should be on this->obstack. */
1249 dwarf2_per_objfile::remove_all_cus ()
1251 gdb_assert (!queue
.has_value ());
1253 m_dwarf2_cus
.clear ();
1256 /* A helper class that calls free_cached_comp_units on
1259 class free_cached_comp_units
1263 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1264 : m_per_objfile (per_objfile
)
1268 ~free_cached_comp_units ()
1270 m_per_objfile
->remove_all_cus ();
1273 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1277 dwarf2_per_objfile
*m_per_objfile
;
1283 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1285 if (per_cu
->index
< this->m_symtabs
.size ())
1286 return this->m_symtabs
[per_cu
->index
] != nullptr;
1293 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1295 if (per_cu
->index
< this->m_symtabs
.size ())
1296 return this->m_symtabs
[per_cu
->index
];
1303 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1304 compunit_symtab
*symtab
)
1306 if (per_cu
->index
>= this->m_symtabs
.size ())
1307 this->m_symtabs
.resize (per_cu
->index
+ 1);
1308 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1309 this->m_symtabs
[per_cu
->index
] = symtab
;
1312 /* Try to locate the sections we need for DWARF 2 debugging
1313 information and return true if we have enough to do something.
1314 NAMES points to the dwarf2 section names, or is NULL if the standard
1315 ELF names are used. CAN_COPY is true for formats where symbol
1316 interposition is possible and so symbol values must follow copy
1317 relocation rules. */
1320 dwarf2_has_info (struct objfile
*objfile
,
1321 const struct dwarf2_debug_sections
*names
,
1324 if (objfile
->flags
& OBJF_READNEVER
)
1327 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1329 if (per_objfile
== NULL
)
1331 dwarf2_per_bfd
*per_bfd
;
1333 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1334 BFD doesn't require relocations.
1336 We don't share with objfiles for which -readnow was requested,
1337 because it would complicate things when loading the same BFD with
1338 -readnow and then without -readnow. */
1339 if (!gdb_bfd_requires_relocations (objfile
->obfd
.get ())
1340 && (objfile
->flags
& OBJF_READNOW
) == 0)
1342 /* See if one has been created for this BFD yet. */
1343 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
.get ());
1345 if (per_bfd
== nullptr)
1347 /* No, create it now. */
1348 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
.get (), names
,
1350 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
.get (), per_bfd
);
1355 /* No sharing possible, create one specifically for this objfile. */
1356 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
.get (), names
, can_copy
);
1357 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1360 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1363 return (!per_objfile
->per_bfd
->info
.is_virtual
1364 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1365 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1366 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1369 /* See declaration. */
1372 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1373 const dwarf2_debug_sections
&names
)
1375 flagword aflag
= bfd_section_flags (sectp
);
1377 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1380 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1381 > bfd_get_file_size (abfd
))
1383 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1384 warning (_("Discarding section %s which has a section size (%s"
1385 ") larger than the file size [in module %s]"),
1386 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1387 bfd_get_filename (abfd
));
1389 else if (names
.info
.matches (sectp
->name
))
1391 this->info
.s
.section
= sectp
;
1392 this->info
.size
= bfd_section_size (sectp
);
1394 else if (names
.abbrev
.matches (sectp
->name
))
1396 this->abbrev
.s
.section
= sectp
;
1397 this->abbrev
.size
= bfd_section_size (sectp
);
1399 else if (names
.line
.matches (sectp
->name
))
1401 this->line
.s
.section
= sectp
;
1402 this->line
.size
= bfd_section_size (sectp
);
1404 else if (names
.loc
.matches (sectp
->name
))
1406 this->loc
.s
.section
= sectp
;
1407 this->loc
.size
= bfd_section_size (sectp
);
1409 else if (names
.loclists
.matches (sectp
->name
))
1411 this->loclists
.s
.section
= sectp
;
1412 this->loclists
.size
= bfd_section_size (sectp
);
1414 else if (names
.macinfo
.matches (sectp
->name
))
1416 this->macinfo
.s
.section
= sectp
;
1417 this->macinfo
.size
= bfd_section_size (sectp
);
1419 else if (names
.macro
.matches (sectp
->name
))
1421 this->macro
.s
.section
= sectp
;
1422 this->macro
.size
= bfd_section_size (sectp
);
1424 else if (names
.str
.matches (sectp
->name
))
1426 this->str
.s
.section
= sectp
;
1427 this->str
.size
= bfd_section_size (sectp
);
1429 else if (names
.str_offsets
.matches (sectp
->name
))
1431 this->str_offsets
.s
.section
= sectp
;
1432 this->str_offsets
.size
= bfd_section_size (sectp
);
1434 else if (names
.line_str
.matches (sectp
->name
))
1436 this->line_str
.s
.section
= sectp
;
1437 this->line_str
.size
= bfd_section_size (sectp
);
1439 else if (names
.addr
.matches (sectp
->name
))
1441 this->addr
.s
.section
= sectp
;
1442 this->addr
.size
= bfd_section_size (sectp
);
1444 else if (names
.frame
.matches (sectp
->name
))
1446 this->frame
.s
.section
= sectp
;
1447 this->frame
.size
= bfd_section_size (sectp
);
1449 else if (names
.eh_frame
.matches (sectp
->name
))
1451 this->eh_frame
.s
.section
= sectp
;
1452 this->eh_frame
.size
= bfd_section_size (sectp
);
1454 else if (names
.ranges
.matches (sectp
->name
))
1456 this->ranges
.s
.section
= sectp
;
1457 this->ranges
.size
= bfd_section_size (sectp
);
1459 else if (names
.rnglists
.matches (sectp
->name
))
1461 this->rnglists
.s
.section
= sectp
;
1462 this->rnglists
.size
= bfd_section_size (sectp
);
1464 else if (names
.types
.matches (sectp
->name
))
1466 struct dwarf2_section_info type_section
;
1468 memset (&type_section
, 0, sizeof (type_section
));
1469 type_section
.s
.section
= sectp
;
1470 type_section
.size
= bfd_section_size (sectp
);
1472 this->types
.push_back (type_section
);
1474 else if (names
.gdb_index
.matches (sectp
->name
))
1476 this->gdb_index
.s
.section
= sectp
;
1477 this->gdb_index
.size
= bfd_section_size (sectp
);
1479 else if (names
.debug_names
.matches (sectp
->name
))
1481 this->debug_names
.s
.section
= sectp
;
1482 this->debug_names
.size
= bfd_section_size (sectp
);
1484 else if (names
.debug_aranges
.matches (sectp
->name
))
1486 this->debug_aranges
.s
.section
= sectp
;
1487 this->debug_aranges
.size
= bfd_section_size (sectp
);
1490 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1491 && bfd_section_vma (sectp
) == 0)
1492 this->has_section_at_zero
= true;
1495 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1499 dwarf2_get_section_info (struct objfile
*objfile
,
1500 enum dwarf2_section_enum sect
,
1501 asection
**sectp
, const gdb_byte
**bufp
,
1502 bfd_size_type
*sizep
)
1504 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1505 struct dwarf2_section_info
*info
;
1507 /* We may see an objfile without any DWARF, in which case we just
1509 if (per_objfile
== NULL
)
1518 case DWARF2_DEBUG_FRAME
:
1519 info
= &per_objfile
->per_bfd
->frame
;
1521 case DWARF2_EH_FRAME
:
1522 info
= &per_objfile
->per_bfd
->eh_frame
;
1525 gdb_assert_not_reached ("unexpected section");
1528 info
->read (objfile
);
1530 *sectp
= info
->get_bfd_section ();
1531 *bufp
= info
->buffer
;
1532 *sizep
= info
->size
;
1535 /* See dwarf2/read.h. */
1538 dwarf2_per_bfd::map_info_sections (struct objfile
*objfile
)
1540 info
.read (objfile
);
1541 abbrev
.read (objfile
);
1542 line
.read (objfile
);
1544 str_offsets
.read (objfile
);
1545 line_str
.read (objfile
);
1546 ranges
.read (objfile
);
1547 rnglists
.read (objfile
);
1548 addr
.read (objfile
);
1550 for (auto §ion
: types
)
1551 section
.read (objfile
);
1555 /* DWARF quick_symbol_functions support. */
1557 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1558 unique line tables, so we maintain a separate table of all .debug_line
1559 derived entries to support the sharing.
1560 All the quick functions need is the list of file names. We discard the
1561 line_header when we're done and don't need to record it here. */
1562 struct quick_file_names
1564 /* The data used to construct the hash key. */
1565 struct stmt_list_hash hash
;
1567 /* The number of entries in file_names, real_names. */
1568 unsigned int num_file_names
;
1570 /* The CU directory, as given by DW_AT_comp_dir. May be
1572 const char *comp_dir
;
1574 /* The file names from the line table, after being run through
1576 const char **file_names
;
1578 /* The file names from the line table after being run through
1579 gdb_realpath. These are computed lazily. */
1580 const char **real_names
;
1583 /* With OBJF_READNOW, the DWARF reader expands all CUs immediately.
1584 It's handy in this case to have an empty implementation of the
1585 quick symbol functions, to avoid special cases in the rest of the
1588 struct readnow_functions
: public dwarf2_base_index_functions
1590 void dump (struct objfile
*objfile
) override
1594 void expand_matching_symbols
1596 const lookup_name_info
&lookup_name
,
1599 symbol_compare_ftype
*ordered_compare
) override
1603 bool expand_symtabs_matching
1604 (struct objfile
*objfile
,
1605 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1606 const lookup_name_info
*lookup_name
,
1607 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1608 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1609 block_search_flags search_flags
,
1611 enum search_domain kind
) override
1617 /* Utility hash function for a stmt_list_hash. */
1620 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
1624 if (stmt_list_hash
->dwo_unit
!= NULL
)
1625 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
1626 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
1630 /* Utility equality function for a stmt_list_hash. */
1633 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
1634 const struct stmt_list_hash
*rhs
)
1636 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
1638 if (lhs
->dwo_unit
!= NULL
1639 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
1642 return lhs
->line_sect_off
== rhs
->line_sect_off
;
1645 /* Hash function for a quick_file_names. */
1648 hash_file_name_entry (const void *e
)
1650 const struct quick_file_names
*file_data
1651 = (const struct quick_file_names
*) e
;
1653 return hash_stmt_list_entry (&file_data
->hash
);
1656 /* Equality function for a quick_file_names. */
1659 eq_file_name_entry (const void *a
, const void *b
)
1661 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
1662 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
1664 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
1670 create_quick_file_names_table (unsigned int nr_initial_entries
)
1672 return htab_up (htab_create_alloc (nr_initial_entries
,
1673 hash_file_name_entry
, eq_file_name_entry
,
1674 nullptr, xcalloc
, xfree
));
1677 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
1678 function is unrelated to symtabs, symtab would have to be created afterwards.
1679 You should call age_cached_comp_units after processing the CU. */
1682 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1685 if (per_cu
->is_debug_types
)
1686 load_full_type_unit (per_cu
, per_objfile
);
1688 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
1689 skip_partial
, language_minimal
);
1691 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
1693 return nullptr; /* Dummy CU. */
1695 dwarf2_find_base_address (cu
->dies
, cu
);
1700 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
1703 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
1704 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
1707 /* The destructor of dwarf2_queue_guard frees any entries left on
1708 the queue. After this point we're guaranteed to leave this function
1709 with the dwarf queue empty. */
1710 dwarf2_queue_guard
q_guard (per_objfile
);
1712 if (!per_objfile
->symtab_set_p (per_cu
))
1714 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
1715 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
1717 /* If we just loaded a CU from a DWO, and we're working with an index
1718 that may badly handle TUs, load all the TUs in that DWO as well.
1719 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
1720 if (!per_cu
->is_debug_types
1722 && cu
->dwo_unit
!= NULL
1723 && per_objfile
->per_bfd
->index_table
!= NULL
1724 && !per_objfile
->per_bfd
->index_table
->version_check ()
1725 /* DWP files aren't supported yet. */
1726 && get_dwp_file (per_objfile
) == NULL
)
1727 queue_and_load_all_dwo_tus (cu
);
1730 process_queue (per_objfile
);
1733 /* Age the cache, releasing compilation units that have not
1734 been used recently. */
1735 per_objfile
->age_comp_units ();
1738 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
1739 the per-objfile for which this symtab is instantiated.
1741 Returns the resulting symbol table. */
1743 static struct compunit_symtab
*
1744 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
1745 dwarf2_per_objfile
*per_objfile
,
1748 if (!per_objfile
->symtab_set_p (per_cu
))
1750 free_cached_comp_units
freer (per_objfile
);
1751 scoped_restore decrementer
= increment_reading_symtab ();
1752 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
1753 process_cu_includes (per_objfile
);
1756 return per_objfile
->get_symtab (per_cu
);
1761 dwarf2_per_cu_data_up
1762 dwarf2_per_bfd::allocate_per_cu ()
1764 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
1765 result
->per_bfd
= this;
1766 result
->index
= all_units
.size ();
1773 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
1775 signatured_type_up
result (new signatured_type (signature
));
1776 result
->per_bfd
= this;
1777 result
->index
= all_units
.size ();
1778 result
->is_debug_types
= true;
1785 dwarf2_per_cu_data_up
1786 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
1787 struct dwarf2_section_info
*section
,
1789 sect_offset sect_off
, ULONGEST length
)
1791 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
1792 the_cu
->sect_off
= sect_off
;
1793 the_cu
->set_length (length
);
1794 the_cu
->section
= section
;
1795 the_cu
->is_dwz
= is_dwz
;
1802 read_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
1803 dwarf2_section_info
*section
,
1804 addrmap
*mutable_map
)
1806 struct objfile
*objfile
= per_objfile
->objfile
;
1807 bfd
*abfd
= objfile
->obfd
.get ();
1808 struct gdbarch
*gdbarch
= objfile
->arch ();
1809 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
1810 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
1812 std::unordered_map
<sect_offset
,
1813 dwarf2_per_cu_data
*,
1814 gdb::hash_enum
<sect_offset
>>
1815 debug_info_offset_to_per_cu
;
1816 for (const auto &per_cu
: per_bfd
->all_units
)
1818 /* A TU will not need aranges, and skipping them here is an easy
1819 way of ignoring .debug_types -- and possibly seeing a
1820 duplicate section offset -- entirely. The same applies to
1821 units coming from a dwz file. */
1822 if (per_cu
->is_debug_types
|| per_cu
->is_dwz
)
1825 const auto insertpair
1826 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
1829 /* Assume no duplicate offsets in all_units. */
1830 gdb_assert (insertpair
.second
);
1833 std::set
<sect_offset
> debug_info_offset_seen
;
1835 section
->read (objfile
);
1837 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
1839 const gdb_byte
*addr
= section
->buffer
;
1841 while (addr
< section
->buffer
+ section
->size
)
1843 const gdb_byte
*const entry_addr
= addr
;
1844 unsigned int bytes_read
;
1846 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
1850 const gdb_byte
*const entry_end
= addr
+ entry_length
;
1851 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
1852 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
1853 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
1855 warning (_("Section .debug_aranges in %s entry at offset %s "
1856 "length %s exceeds section length %s, "
1857 "ignoring .debug_aranges."),
1858 objfile_name (objfile
),
1859 plongest (entry_addr
- section
->buffer
),
1860 plongest (bytes_read
+ entry_length
),
1861 pulongest (section
->size
));
1865 /* The version number. */
1866 const uint16_t version
= read_2_bytes (abfd
, addr
);
1870 warning (_("Section .debug_aranges in %s entry at offset %s "
1871 "has unsupported version %d, ignoring .debug_aranges."),
1872 objfile_name (objfile
),
1873 plongest (entry_addr
- section
->buffer
), version
);
1877 const uint64_t debug_info_offset
1878 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
1879 addr
+= offset_size
;
1880 const auto per_cu_it
1881 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
1882 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
1884 warning (_("Section .debug_aranges in %s entry at offset %s "
1885 "debug_info_offset %s does not exists, "
1886 "ignoring .debug_aranges."),
1887 objfile_name (objfile
),
1888 plongest (entry_addr
- section
->buffer
),
1889 pulongest (debug_info_offset
));
1892 const auto insertpair
1893 = debug_info_offset_seen
.insert (sect_offset (debug_info_offset
));
1894 if (!insertpair
.second
)
1896 warning (_("Section .debug_aranges in %s has duplicate "
1897 "debug_info_offset %s, ignoring .debug_aranges."),
1898 objfile_name (objfile
),
1899 sect_offset_str (sect_offset (debug_info_offset
)));
1902 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
1904 const uint8_t address_size
= *addr
++;
1905 if (address_size
< 1 || address_size
> 8)
1907 warning (_("Section .debug_aranges in %s entry at offset %s "
1908 "address_size %u is invalid, ignoring .debug_aranges."),
1909 objfile_name (objfile
),
1910 plongest (entry_addr
- section
->buffer
), address_size
);
1914 const uint8_t segment_selector_size
= *addr
++;
1915 if (segment_selector_size
!= 0)
1917 warning (_("Section .debug_aranges in %s entry at offset %s "
1918 "segment_selector_size %u is not supported, "
1919 "ignoring .debug_aranges."),
1920 objfile_name (objfile
),
1921 plongest (entry_addr
- section
->buffer
),
1922 segment_selector_size
);
1926 /* Must pad to an alignment boundary that is twice the address
1927 size. It is undocumented by the DWARF standard but GCC does
1928 use it. However, not every compiler does this. We can see
1929 whether it has happened by looking at the total length of the
1930 contents of the aranges for this CU -- it if isn't a multiple
1931 of twice the address size, then we skip any leftover
1933 addr
+= (entry_end
- addr
) % (2 * address_size
);
1935 while (addr
< entry_end
)
1937 if (addr
+ 2 * address_size
> entry_end
)
1939 warning (_("Section .debug_aranges in %s entry at offset %s "
1940 "address list is not properly terminated, "
1941 "ignoring .debug_aranges."),
1942 objfile_name (objfile
),
1943 plongest (entry_addr
- section
->buffer
));
1946 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
1948 addr
+= address_size
;
1949 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
1951 addr
+= address_size
;
1952 if (start
== 0 && length
== 0)
1954 /* This can happen on some targets with --gc-sections.
1955 This pair of values is also used to mark the end of
1956 the entries for a given CU, but we ignore it and
1957 instead handle termination using the check at the top
1961 if (start
== 0 && !per_bfd
->has_section_at_zero
)
1963 /* Symbol was eliminated due to a COMDAT group. */
1966 ULONGEST end
= start
+ length
;
1967 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
1969 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
1971 mutable_map
->set_empty (start
, end
- 1, per_cu
);
1974 per_cu
->addresses_seen
= true;
1980 /* die_reader_func for dw2_get_file_names. */
1983 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
1984 struct die_info
*comp_unit_die
)
1986 struct dwarf2_cu
*cu
= reader
->cu
;
1987 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
1988 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
1989 struct dwarf2_per_cu_data
*lh_cu
;
1990 struct attribute
*attr
;
1992 struct quick_file_names
*qfn
;
1994 gdb_assert (! this_cu
->is_debug_types
);
1996 this_cu
->files_read
= true;
1997 /* Our callers never want to match partial units -- instead they
1998 will match the enclosing full CU. */
1999 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2006 sect_offset line_offset
{};
2008 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
2010 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2011 if (attr
!= nullptr && attr
->form_is_unsigned ())
2013 struct quick_file_names find_entry
;
2015 line_offset
= (sect_offset
) attr
->as_unsigned ();
2017 /* We may have already read in this line header (TU line header sharing).
2018 If we have we're done. */
2019 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2020 find_entry
.hash
.line_sect_off
= line_offset
;
2021 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2022 &find_entry
, INSERT
);
2025 lh_cu
->file_names
= (struct quick_file_names
*) *slot
;
2029 lh
= dwarf_decode_line_header (line_offset
, cu
, fnd
.get_comp_dir ());
2033 if (!fnd
.is_unknown ())
2035 else if (lh
== nullptr)
2038 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2039 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2040 qfn
->hash
.line_sect_off
= line_offset
;
2041 /* There may not be a DW_AT_stmt_list. */
2042 if (slot
!= nullptr)
2045 std::vector
<const char *> include_names
;
2048 for (const auto &entry
: lh
->file_names ())
2050 std::string name_holder
;
2051 const char *include_name
=
2052 compute_include_file_name (lh
.get (), entry
, fnd
, name_holder
);
2053 if (include_name
!= nullptr)
2055 include_name
= per_objfile
->objfile
->intern (include_name
);
2056 include_names
.push_back (include_name
);
2061 qfn
->num_file_names
= offset
+ include_names
.size ();
2062 qfn
->comp_dir
= fnd
.intern_comp_dir (per_objfile
->objfile
);
2064 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2065 qfn
->num_file_names
);
2067 qfn
->file_names
[0] = per_objfile
->objfile
->intern (fnd
.get_name ());
2069 if (!include_names
.empty ())
2070 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
2071 include_names
.size () * sizeof (const char *));
2073 qfn
->real_names
= NULL
;
2075 lh_cu
->file_names
= qfn
;
2078 /* A helper for the "quick" functions which attempts to read the line
2079 table for THIS_CU. */
2081 static struct quick_file_names
*
2082 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2083 dwarf2_per_objfile
*per_objfile
)
2085 /* This should never be called for TUs. */
2086 gdb_assert (! this_cu
->is_debug_types
);
2088 if (this_cu
->files_read
)
2089 return this_cu
->file_names
;
2091 cutu_reader
reader (this_cu
, per_objfile
);
2092 if (!reader
.dummy_p
)
2093 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
2095 return this_cu
->file_names
;
2098 /* A helper for the "quick" functions which computes and caches the
2099 real path for a given file name from the line table. */
2102 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
2103 struct quick_file_names
*qfn
, int index
)
2105 if (qfn
->real_names
== NULL
)
2106 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
2107 qfn
->num_file_names
, const char *);
2109 if (qfn
->real_names
[index
] == NULL
)
2111 const char *dirname
= nullptr;
2113 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
2114 dirname
= qfn
->comp_dir
;
2116 gdb::unique_xmalloc_ptr
<char> fullname
;
2117 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
2119 qfn
->real_names
[index
] = fullname
.release ();
2122 return qfn
->real_names
[index
];
2126 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
2128 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2129 dwarf2_per_cu_data
*dwarf_cu
2130 = per_objfile
->per_bfd
->all_units
.back ().get ();
2131 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
2136 return cust
->primary_filetab ();
2142 dwarf2_per_cu_data::free_cached_file_names ()
2145 fnd
->forget_fullname ();
2147 if (per_bfd
== nullptr)
2150 struct quick_file_names
*file_data
= file_names
;
2151 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
2153 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
2155 xfree ((void *) file_data
->real_names
[i
]);
2156 file_data
->real_names
[i
] = nullptr;
2162 dwarf2_base_index_functions::forget_cached_source_info
2163 (struct objfile
*objfile
)
2165 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2167 for (auto &per_cu
: per_objfile
->per_bfd
->all_units
)
2168 per_cu
->free_cached_file_names ();
2172 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
2178 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2179 int total
= per_objfile
->per_bfd
->all_units
.size ();
2182 for (int i
= 0; i
< total
; ++i
)
2184 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
2186 if (!per_objfile
->symtab_set_p (per_cu
))
2189 gdb_printf (_(" Number of read CUs: %d\n"), total
- count
);
2190 gdb_printf (_(" Number of unread CUs: %d\n"), count
);
2194 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
2196 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2197 int total_units
= per_objfile
->per_bfd
->all_units
.size ();
2199 for (int i
= 0; i
< total_units
; ++i
)
2201 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
2203 /* We don't want to directly expand a partial CU, because if we
2204 read it with the wrong language, then assertion failures can
2205 be triggered later on. See PR symtab/23010. So, tell
2206 dw2_instantiate_symtab to skip partial CUs -- any important
2207 partial CU will be read via DW_TAG_imported_unit anyway. */
2208 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
2213 /* Starting from a search name, return the string that finds the upper
2214 bound of all strings that start with SEARCH_NAME in a sorted name
2215 list. Returns the empty string to indicate that the upper bound is
2216 the end of the list. */
2219 make_sort_after_prefix_name (const char *search_name
)
2221 /* When looking to complete "func", we find the upper bound of all
2222 symbols that start with "func" by looking for where we'd insert
2223 the closest string that would follow "func" in lexicographical
2224 order. Usually, that's "func"-with-last-character-incremented,
2225 i.e. "fund". Mind non-ASCII characters, though. Usually those
2226 will be UTF-8 multi-byte sequences, but we can't be certain.
2227 Especially mind the 0xff character, which is a valid character in
2228 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
2229 rule out compilers allowing it in identifiers. Note that
2230 conveniently, strcmp/strcasecmp are specified to compare
2231 characters interpreted as unsigned char. So what we do is treat
2232 the whole string as a base 256 number composed of a sequence of
2233 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
2234 to 0, and carries 1 to the following more-significant position.
2235 If the very first character in SEARCH_NAME ends up incremented
2236 and carries/overflows, then the upper bound is the end of the
2237 list. The string after the empty string is also the empty
2240 Some examples of this operation:
2242 SEARCH_NAME => "+1" RESULT
2246 "\xff" "a" "\xff" => "\xff" "b"
2251 Then, with these symbols for example:
2257 completing "func" looks for symbols between "func" and
2258 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
2259 which finds "func" and "func1", but not "fund".
2263 funcÿ (Latin1 'ÿ' [0xff])
2267 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
2268 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
2272 ÿÿ (Latin1 'ÿ' [0xff])
2275 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
2276 the end of the list.
2278 std::string after
= search_name
;
2279 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
2281 if (!after
.empty ())
2282 after
.back () = (unsigned char) after
.back () + 1;
2286 /* See declaration. */
2288 std::pair
<std::vector
<name_component
>::const_iterator
,
2289 std::vector
<name_component
>::const_iterator
>
2290 mapped_index_base::find_name_components_bounds
2291 (const lookup_name_info
&lookup_name_without_params
, language lang
,
2292 dwarf2_per_objfile
*per_objfile
) const
2295 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
2297 const char *lang_name
2298 = lookup_name_without_params
.language_lookup_name (lang
);
2300 /* Comparison function object for lower_bound that matches against a
2301 given symbol name. */
2302 auto lookup_compare_lower
= [&] (const name_component
&elem
,
2305 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
2306 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
2307 return name_cmp (elem_name
, name
) < 0;
2310 /* Comparison function object for upper_bound that matches against a
2311 given symbol name. */
2312 auto lookup_compare_upper
= [&] (const char *name
,
2313 const name_component
&elem
)
2315 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
2316 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
2317 return name_cmp (name
, elem_name
) < 0;
2320 auto begin
= this->name_components
.begin ();
2321 auto end
= this->name_components
.end ();
2323 /* Find the lower bound. */
2326 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
2329 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
2332 /* Find the upper bound. */
2335 if (lookup_name_without_params
.completion_mode ())
2337 /* In completion mode, we want UPPER to point past all
2338 symbols names that have the same prefix. I.e., with
2339 these symbols, and completing "func":
2341 function << lower bound
2343 other_function << upper bound
2345 We find the upper bound by looking for the insertion
2346 point of "func"-with-last-character-incremented,
2348 std::string after
= make_sort_after_prefix_name (lang_name
);
2351 return std::lower_bound (lower
, end
, after
.c_str (),
2352 lookup_compare_lower
);
2355 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
2358 return {lower
, upper
};
2361 /* See declaration. */
2364 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
2366 if (!this->name_components
.empty ())
2369 this->name_components_casing
= case_sensitivity
;
2371 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
2373 /* The code below only knows how to break apart components of C++
2374 symbol names (and other languages that use '::' as
2375 namespace/module separator) and Ada symbol names. */
2376 auto count
= this->symbol_name_count ();
2377 for (offset_type idx
= 0; idx
< count
; idx
++)
2379 if (this->symbol_name_slot_invalid (idx
))
2382 const char *name
= this->symbol_name_at (idx
, per_objfile
);
2384 /* Add each name component to the name component table. */
2385 unsigned int previous_len
= 0;
2387 if (strstr (name
, "::") != nullptr)
2389 for (unsigned int current_len
= cp_find_first_component (name
);
2390 name
[current_len
] != '\0';
2391 current_len
+= cp_find_first_component (name
+ current_len
))
2393 gdb_assert (name
[current_len
] == ':');
2394 this->name_components
.push_back ({previous_len
, idx
});
2395 /* Skip the '::'. */
2397 previous_len
= current_len
;
2402 /* Handle the Ada encoded (aka mangled) form here. */
2403 for (const char *iter
= strstr (name
, "__");
2405 iter
= strstr (iter
, "__"))
2407 this->name_components
.push_back ({previous_len
, idx
});
2409 previous_len
= iter
- name
;
2413 this->name_components
.push_back ({previous_len
, idx
});
2416 /* Sort name_components elements by name. */
2417 auto name_comp_compare
= [&] (const name_component
&left
,
2418 const name_component
&right
)
2420 const char *left_qualified
2421 = this->symbol_name_at (left
.idx
, per_objfile
);
2422 const char *right_qualified
2423 = this->symbol_name_at (right
.idx
, per_objfile
);
2425 const char *left_name
= left_qualified
+ left
.name_offset
;
2426 const char *right_name
= right_qualified
+ right
.name_offset
;
2428 return name_cmp (left_name
, right_name
) < 0;
2431 std::sort (this->name_components
.begin (),
2432 this->name_components
.end (),
2439 dw2_expand_symtabs_matching_symbol
2440 (mapped_index_base
&index
,
2441 const lookup_name_info
&lookup_name_in
,
2442 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2443 gdb::function_view
<bool (offset_type
)> match_callback
,
2444 dwarf2_per_objfile
*per_objfile
)
2446 lookup_name_info lookup_name_without_params
2447 = lookup_name_in
.make_ignore_params ();
2449 /* Build the symbol name component sorted vector, if we haven't
2451 index
.build_name_components (per_objfile
);
2453 /* The same symbol may appear more than once in the range though.
2454 E.g., if we're looking for symbols that complete "w", and we have
2455 a symbol named "w1::w2", we'll find the two name components for
2456 that same symbol in the range. To be sure we only call the
2457 callback once per symbol, we first collect the symbol name
2458 indexes that matched in a temporary vector and ignore
2460 std::vector
<offset_type
> matches
;
2462 struct name_and_matcher
2464 symbol_name_matcher_ftype
*matcher
;
2467 bool operator== (const name_and_matcher
&other
) const
2469 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
2473 /* A vector holding all the different symbol name matchers, for all
2475 std::vector
<name_and_matcher
> matchers
;
2477 for (int i
= 0; i
< nr_languages
; i
++)
2479 enum language lang_e
= (enum language
) i
;
2481 const language_defn
*lang
= language_def (lang_e
);
2482 symbol_name_matcher_ftype
*name_matcher
2483 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
2485 name_and_matcher key
{
2487 lookup_name_without_params
.language_lookup_name (lang_e
)
2490 /* Don't insert the same comparison routine more than once.
2491 Note that we do this linear walk. This is not a problem in
2492 practice because the number of supported languages is
2494 if (std::find (matchers
.begin (), matchers
.end (), key
)
2497 matchers
.push_back (std::move (key
));
2500 = index
.find_name_components_bounds (lookup_name_without_params
,
2501 lang_e
, per_objfile
);
2503 /* Now for each symbol name in range, check to see if we have a name
2504 match, and if so, call the MATCH_CALLBACK callback. */
2506 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
2508 const char *qualified
2509 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
2511 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
2512 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
2515 matches
.push_back (bounds
.first
->idx
);
2519 std::sort (matches
.begin (), matches
.end ());
2521 /* Finally call the callback, once per match. */
2524 for (offset_type idx
: matches
)
2528 if (!match_callback (idx
))
2537 /* Above we use a type wider than idx's for 'prev', since 0 and
2538 (offset_type)-1 are both possible values. */
2539 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
2546 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
2548 /* A mock .gdb_index/.debug_names-like name index table, enough to
2549 exercise dw2_expand_symtabs_matching_symbol, which works with the
2550 mapped_index_base interface. Builds an index from the symbol list
2551 passed as parameter to the constructor. */
2552 class mock_mapped_index
: public mapped_index_base
2555 mock_mapped_index (gdb::array_view
<const char *> symbols
)
2556 : m_symbol_table (symbols
)
2559 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
2561 /* Return the number of names in the symbol table. */
2562 size_t symbol_name_count () const override
2564 return m_symbol_table
.size ();
2567 /* Get the name of the symbol at IDX in the symbol table. */
2568 const char *symbol_name_at
2569 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
2571 return m_symbol_table
[idx
];
2574 quick_symbol_functions_up
make_quick_functions () const override
2580 gdb::array_view
<const char *> m_symbol_table
;
2583 /* Convenience function that converts a NULL pointer to a "<null>"
2584 string, to pass to print routines. */
2587 string_or_null (const char *str
)
2589 return str
!= NULL
? str
: "<null>";
2592 /* Check if a lookup_name_info built from
2593 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
2594 index. EXPECTED_LIST is the list of expected matches, in expected
2595 matching order. If no match expected, then an empty list is
2596 specified. Returns true on success. On failure prints a warning
2597 indicating the file:line that failed, and returns false. */
2600 check_match (const char *file
, int line
,
2601 mock_mapped_index
&mock_index
,
2602 const char *name
, symbol_name_match_type match_type
,
2603 bool completion_mode
,
2604 std::initializer_list
<const char *> expected_list
,
2605 dwarf2_per_objfile
*per_objfile
)
2607 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
2609 bool matched
= true;
2611 auto mismatch
= [&] (const char *expected_str
,
2614 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
2615 "expected=\"%s\", got=\"%s\"\n"),
2617 (match_type
== symbol_name_match_type::FULL
2619 name
, string_or_null (expected_str
), string_or_null (got
));
2623 auto expected_it
= expected_list
.begin ();
2624 auto expected_end
= expected_list
.end ();
2626 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
2628 [&] (offset_type idx
)
2630 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
2631 const char *expected_str
2632 = expected_it
== expected_end
? NULL
: *expected_it
++;
2634 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
2635 mismatch (expected_str
, matched_name
);
2639 const char *expected_str
2640 = expected_it
== expected_end
? NULL
: *expected_it
++;
2641 if (expected_str
!= NULL
)
2642 mismatch (expected_str
, NULL
);
2647 /* The symbols added to the mock mapped_index for testing (in
2649 static const char *test_symbols
[] = {
2658 "ns2::tmpl<int>::foo2",
2659 "(anonymous namespace)::A::B::C",
2661 /* These are used to check that the increment-last-char in the
2662 matching algorithm for completion doesn't match "t1_fund" when
2663 completing "t1_func". */
2669 /* A UTF-8 name with multi-byte sequences to make sure that
2670 cp-name-parser understands this as a single identifier ("função"
2671 is "function" in PT). */
2674 /* Test a symbol name that ends with a 0xff character, which is a
2675 valid character in non-UTF-8 source character sets (e.g. Latin1
2676 'ÿ'), and we can't rule out compilers allowing it in identifiers.
2677 We test this because the completion algorithm finds the upper
2678 bound of symbols by looking for the insertion point of
2679 "func"-with-last-character-incremented, i.e. "fund", and adding 1
2680 to 0xff should wraparound and carry to the previous character.
2681 See comments in make_sort_after_prefix_name. */
2684 /* Some more symbols with \377 (0xff). See above. */
2688 /* A name with all sorts of complications. Starts with "z" to make
2689 it easier for the completion tests below. */
2690 #define Z_SYM_NAME \
2691 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
2692 "::tuple<(anonymous namespace)::ui*, " \
2693 "std::default_delete<(anonymous namespace)::ui>, void>"
2698 /* Returns true if the mapped_index_base::find_name_component_bounds
2699 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
2700 in completion mode. */
2703 check_find_bounds_finds (mapped_index_base
&index
,
2704 const char *search_name
,
2705 gdb::array_view
<const char *> expected_syms
,
2706 dwarf2_per_objfile
*per_objfile
)
2708 lookup_name_info
lookup_name (search_name
,
2709 symbol_name_match_type::FULL
, true);
2711 auto bounds
= index
.find_name_components_bounds (lookup_name
,
2715 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
2716 if (distance
!= expected_syms
.size ())
2719 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
2721 auto nc_elem
= bounds
.first
+ exp_elem
;
2722 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
2723 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
2730 /* Test the lower-level mapped_index::find_name_component_bounds
2734 test_mapped_index_find_name_component_bounds ()
2736 mock_mapped_index
mock_index (test_symbols
);
2738 mock_index
.build_name_components (NULL
/* per_objfile */);
2740 /* Test the lower-level mapped_index::find_name_component_bounds
2741 method in completion mode. */
2743 static const char *expected_syms
[] = {
2748 SELF_CHECK (check_find_bounds_finds
2749 (mock_index
, "t1_func", expected_syms
,
2750 NULL
/* per_objfile */));
2753 /* Check that the increment-last-char in the name matching algorithm
2754 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. See
2755 make_sort_after_prefix_name. */
2757 static const char *expected_syms1
[] = {
2761 SELF_CHECK (check_find_bounds_finds
2762 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
2764 static const char *expected_syms2
[] = {
2767 SELF_CHECK (check_find_bounds_finds
2768 (mock_index
, "\377\377", expected_syms2
,
2769 NULL
/* per_objfile */));
2773 /* Test dw2_expand_symtabs_matching_symbol. */
2776 test_dw2_expand_symtabs_matching_symbol ()
2778 mock_mapped_index
mock_index (test_symbols
);
2780 /* We let all tests run until the end even if some fails, for debug
2782 bool any_mismatch
= false;
2784 /* Create the expected symbols list (an initializer_list). Needed
2785 because lists have commas, and we need to pass them to CHECK,
2786 which is a macro. */
2787 #define EXPECT(...) { __VA_ARGS__ }
2789 /* Wrapper for check_match that passes down the current
2790 __FILE__/__LINE__. */
2791 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
2792 any_mismatch |= !check_match (__FILE__, __LINE__, \
2794 NAME, MATCH_TYPE, COMPLETION_MODE, \
2795 EXPECTED_LIST, NULL)
2797 /* Identity checks. */
2798 for (const char *sym
: test_symbols
)
2800 /* Should be able to match all existing symbols. */
2801 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
2804 /* Should be able to match all existing symbols with
2806 std::string with_params
= std::string (sym
) + "(int)";
2807 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
2810 /* Should be able to match all existing symbols with
2811 parameters and qualifiers. */
2812 with_params
= std::string (sym
) + " ( int ) const";
2813 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
2816 /* This should really find sym, but cp-name-parser.y doesn't
2817 know about lvalue/rvalue qualifiers yet. */
2818 with_params
= std::string (sym
) + " ( int ) &&";
2819 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
2823 /* Check that the name matching algorithm for completion doesn't get
2824 confused with Latin1 'ÿ' / 0xff. See
2825 make_sort_after_prefix_name. */
2827 static const char str
[] = "\377";
2828 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
2829 EXPECT ("\377", "\377\377123"));
2832 /* Check that the increment-last-char in the matching algorithm for
2833 completion doesn't match "t1_fund" when completing "t1_func". */
2835 static const char str
[] = "t1_func";
2836 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
2837 EXPECT ("t1_func", "t1_func1"));
2840 /* Check that completion mode works at each prefix of the expected
2843 static const char str
[] = "function(int)";
2844 size_t len
= strlen (str
);
2847 for (size_t i
= 1; i
< len
; i
++)
2849 lookup
.assign (str
, i
);
2850 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
2851 EXPECT ("function"));
2855 /* While "w" is a prefix of both components, the match function
2856 should still only be called once. */
2858 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
2860 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
2864 /* Same, with a "complicated" symbol. */
2866 static const char str
[] = Z_SYM_NAME
;
2867 size_t len
= strlen (str
);
2870 for (size_t i
= 1; i
< len
; i
++)
2872 lookup
.assign (str
, i
);
2873 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
2874 EXPECT (Z_SYM_NAME
));
2878 /* In FULL mode, an incomplete symbol doesn't match. */
2880 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
2884 /* A complete symbol with parameters matches any overload, since the
2885 index has no overload info. */
2887 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
2888 EXPECT ("std::zfunction", "std::zfunction2"));
2889 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
2890 EXPECT ("std::zfunction", "std::zfunction2"));
2891 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
2892 EXPECT ("std::zfunction", "std::zfunction2"));
2895 /* Check that whitespace is ignored appropriately. A symbol with a
2896 template argument list. */
2898 static const char expected
[] = "ns::foo<int>";
2899 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
2901 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
2905 /* Check that whitespace is ignored appropriately. A symbol with a
2906 template argument list that includes a pointer. */
2908 static const char expected
[] = "ns::foo<char*>";
2909 /* Try both completion and non-completion modes. */
2910 static const bool completion_mode
[2] = {false, true};
2911 for (size_t i
= 0; i
< 2; i
++)
2913 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
2914 completion_mode
[i
], EXPECT (expected
));
2915 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
2916 completion_mode
[i
], EXPECT (expected
));
2918 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
2919 completion_mode
[i
], EXPECT (expected
));
2920 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
2921 completion_mode
[i
], EXPECT (expected
));
2926 /* Check method qualifiers are ignored. */
2927 static const char expected
[] = "ns::foo<char*>";
2928 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
2929 symbol_name_match_type::FULL
, true, EXPECT (expected
));
2930 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
2931 symbol_name_match_type::FULL
, true, EXPECT (expected
));
2932 CHECK_MATCH ("foo < char * > ( int ) const",
2933 symbol_name_match_type::WILD
, true, EXPECT (expected
));
2934 CHECK_MATCH ("foo < char * > ( int ) &&",
2935 symbol_name_match_type::WILD
, true, EXPECT (expected
));
2938 /* Test lookup names that don't match anything. */
2940 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
2943 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
2947 /* Some wild matching tests, exercising "(anonymous namespace)",
2948 which should not be confused with a parameter list. */
2950 static const char *syms
[] = {
2954 "A :: B :: C ( int )",
2959 for (const char *s
: syms
)
2961 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
2962 EXPECT ("(anonymous namespace)::A::B::C"));
2967 static const char expected
[] = "ns2::tmpl<int>::foo2";
2968 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
2970 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
2974 SELF_CHECK (!any_mismatch
);
2983 test_mapped_index_find_name_component_bounds ();
2984 test_dw2_expand_symtabs_matching_symbol ();
2987 }} // namespace selftests::dw2_expand_symtabs_matching
2989 #endif /* GDB_SELF_TEST */
2994 dw2_expand_symtabs_matching_one
2995 (dwarf2_per_cu_data
*per_cu
,
2996 dwarf2_per_objfile
*per_objfile
,
2997 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2998 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
3000 if (file_matcher
== NULL
|| per_cu
->mark
)
3002 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
3004 compunit_symtab
*symtab
3005 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3006 gdb_assert (symtab
!= nullptr);
3008 if (expansion_notify
!= NULL
&& symtab_was_null
)
3009 return expansion_notify (symtab
);
3017 dw_expand_symtabs_matching_file_matcher
3018 (dwarf2_per_objfile
*per_objfile
,
3019 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
3021 if (file_matcher
== NULL
)
3024 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
3026 NULL
, xcalloc
, xfree
));
3027 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
3029 NULL
, xcalloc
, xfree
));
3031 /* The rule is CUs specify all the files, including those used by
3032 any TU, so there's no need to scan TUs here. */
3034 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
3038 if (per_cu
->is_debug_types
)
3042 /* We only need to look at symtabs not already expanded. */
3043 if (per_objfile
->symtab_set_p (per_cu
.get ()))
3046 if (per_cu
->fnd
!= nullptr)
3048 file_and_directory
*fnd
= per_cu
->fnd
.get ();
3050 if (file_matcher (fnd
->get_name (), false))
3056 /* Before we invoke realpath, which can get expensive when many
3057 files are involved, do a quick comparison of the basenames. */
3058 if ((basenames_may_differ
3059 || file_matcher (lbasename (fnd
->get_name ()), true))
3060 && file_matcher (fnd
->get_fullname (), false))
3067 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
3069 if (file_data
== NULL
)
3072 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
3074 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
3080 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3082 const char *this_real_name
;
3084 if (file_matcher (file_data
->file_names
[j
], false))
3090 /* Before we invoke realpath, which can get expensive when many
3091 files are involved, do a quick comparison of the basenames. */
3092 if (!basenames_may_differ
3093 && !file_matcher (lbasename (file_data
->file_names
[j
]),
3097 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3098 if (file_matcher (this_real_name
, false))
3105 void **slot
= htab_find_slot (per_cu
->mark
3106 ? visited_found
.get ()
3107 : visited_not_found
.get (),
3114 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
3117 static struct compunit_symtab
*
3118 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
3123 if (cust
->blockvector () != nullptr
3124 && blockvector_contains_pc (cust
->blockvector (), pc
))
3127 if (cust
->includes
== NULL
)
3130 for (i
= 0; cust
->includes
[i
]; ++i
)
3132 struct compunit_symtab
*s
= cust
->includes
[i
];
3134 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
3142 dwarf2_per_cu_data
*
3143 dwarf2_base_index_functions::find_per_cu (dwarf2_per_bfd
*per_bfd
,
3144 CORE_ADDR adjusted_pc
)
3146 if (per_bfd
->index_addrmap
== nullptr)
3149 void *obj
= per_bfd
->index_addrmap
->find (adjusted_pc
);
3150 return static_cast<dwarf2_per_cu_data
*> (obj
);
3153 struct compunit_symtab
*
3154 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
3155 (struct objfile
*objfile
,
3156 struct bound_minimal_symbol msymbol
,
3158 struct obj_section
*section
,
3161 struct compunit_symtab
*result
;
3163 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3165 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
3166 struct dwarf2_per_cu_data
*data
= find_per_cu (per_objfile
->per_bfd
,
3168 if (data
== nullptr)
3171 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
3172 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3173 paddress (objfile
->arch (), pc
));
3175 result
= recursively_find_pc_sect_compunit_symtab
3176 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
3178 if (warn_if_readin
&& result
== nullptr)
3179 warning (_("(Error: pc %s in address map, but not in symtab.)"),
3180 paddress (objfile
->arch (), pc
));
3186 dwarf2_base_index_functions::map_symbol_filenames
3187 (struct objfile
*objfile
,
3188 gdb::function_view
<symbol_filename_ftype
> fun
,
3191 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3193 /* Use caches to ensure we only call FUN once for each filename. */
3194 filename_seen_cache filenames_cache
;
3195 std::unordered_set
<quick_file_names
*> qfn_cache
;
3197 /* The rule is CUs specify all the files, including those used by any TU,
3198 so there's no need to scan TUs here. We can ignore file names coming
3199 from already-expanded CUs. It is possible that an expanded CU might
3200 reuse the file names data from a currently unexpanded CU, in this
3201 case we don't want to report the files from the unexpanded CU. */
3203 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
3205 if (!per_cu
->is_debug_types
3206 && per_objfile
->symtab_set_p (per_cu
.get ()))
3208 if (per_cu
->file_names
!= nullptr)
3209 qfn_cache
.insert (per_cu
->file_names
);
3213 for (dwarf2_per_cu_data
*per_cu
3214 : all_units_range (per_objfile
->per_bfd
))
3216 /* We only need to look at symtabs not already expanded. */
3217 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
3220 if (per_cu
->fnd
!= nullptr)
3222 file_and_directory
*fnd
= per_cu
->fnd
.get ();
3224 const char *filename
= fnd
->get_name ();
3225 const char *key
= filename
;
3226 const char *fullname
= nullptr;
3230 fullname
= fnd
->get_fullname ();
3234 if (!filenames_cache
.seen (key
))
3235 fun (filename
, fullname
);
3238 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3239 if (file_data
== nullptr
3240 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
3243 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3245 const char *filename
= file_data
->file_names
[j
];
3246 const char *key
= filename
;
3247 const char *fullname
= nullptr;
3251 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
3255 if (!filenames_cache
.seen (key
))
3256 fun (filename
, fullname
);
3262 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
3267 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
3270 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
3272 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3274 for (const auto &per_cu
: per_objfile
->per_bfd
->all_units
)
3276 /* Is this already expanded? */
3277 if (per_objfile
->symtab_set_p (per_cu
.get ()))
3280 /* It has not yet been expanded. */
3287 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
3288 to either a dwarf2_per_bfd or dwz_file object. */
3290 template <typename T
>
3291 static gdb::array_view
<const gdb_byte
>
3292 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
3294 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
3296 if (section
->empty ())
3299 /* Older elfutils strip versions could keep the section in the main
3300 executable while splitting it for the separate debug info file. */
3301 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
3304 section
->read (obj
);
3306 /* dwarf2_section_info::size is a bfd_size_type, while
3307 gdb::array_view works with size_t. On 32-bit hosts, with
3308 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
3309 is 32-bit. So we need an explicit narrowing conversion here.
3310 This is fine, because it's impossible to allocate or mmap an
3311 array/buffer larger than what size_t can represent. */
3312 return gdb::make_array_view (section
->buffer
, section
->size
);
3315 /* Lookup the index cache for the contents of the index associated to
3318 static gdb::array_view
<const gdb_byte
>
3319 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
3321 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
.get ());
3322 if (build_id
== nullptr)
3325 return global_index_cache
.lookup_gdb_index (build_id
,
3326 &dwarf2_per_bfd
->index_cache_res
);
3329 /* Same as the above, but for DWZ. */
3331 static gdb::array_view
<const gdb_byte
>
3332 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
3334 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
3335 if (build_id
== nullptr)
3338 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
3341 static quick_symbol_functions_up
make_cooked_index_funcs ();
3343 /* See dwarf2/public.h. */
3346 dwarf2_initialize_objfile (struct objfile
*objfile
)
3348 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3349 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3351 dwarf_read_debug_printf ("called");
3353 /* If we're about to read full symbols, don't bother with the
3354 indices. In this case we also don't care if some other debug
3355 format is making psymtabs, because they are all about to be
3357 if ((objfile
->flags
& OBJF_READNOW
))
3359 dwarf_read_debug_printf ("readnow requested");
3361 create_all_units (per_objfile
);
3362 per_bfd
->quick_file_names_table
3363 = create_quick_file_names_table (per_bfd
->all_units
.size ());
3365 objfile
->qf
.emplace_front (new readnow_functions
);
3369 /* Was a GDB index already read when we processed an objfile sharing
3371 if (per_bfd
->index_table
!= nullptr)
3373 dwarf_read_debug_printf ("re-using symbols");
3374 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
3378 if (dwarf2_read_debug_names (per_objfile
))
3380 dwarf_read_debug_printf ("found debug names");
3381 objfile
->qf
.push_front
3382 (per_bfd
->index_table
->make_quick_functions ());
3386 if (dwarf2_read_gdb_index (per_objfile
,
3387 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
3388 get_gdb_index_contents_from_section
<dwz_file
>))
3390 dwarf_read_debug_printf ("found gdb index from file");
3391 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
3395 /* ... otherwise, try to find the index in the index cache. */
3396 if (dwarf2_read_gdb_index (per_objfile
,
3397 get_gdb_index_contents_from_cache
,
3398 get_gdb_index_contents_from_cache_dwz
))
3400 dwarf_read_debug_printf ("found gdb index from cache");
3401 global_index_cache
.hit ();
3402 objfile
->qf
.push_front (per_bfd
->index_table
->make_quick_functions ());
3406 global_index_cache
.miss ();
3407 objfile
->qf
.push_front (make_cooked_index_funcs ());
3412 /* Build a partial symbol table. */
3415 dwarf2_build_psymtabs (struct objfile
*objfile
)
3417 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3419 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3424 dwarf2_build_psymtabs_hard (per_objfile
);
3426 /* (maybe) store an index in the cache. */
3427 global_index_cache
.store (per_objfile
);
3429 catch (const gdb_exception_error
&except
)
3431 exception_print (gdb_stderr
, except
);
3435 /* Find the base address of the compilation unit for range lists and
3436 location lists. It will normally be specified by DW_AT_low_pc.
3437 In DWARF-3 draft 4, the base address could be overridden by
3438 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3439 compilation units with discontinuous ranges. */
3442 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3444 struct attribute
*attr
;
3446 cu
->base_address
.reset ();
3448 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3449 if (attr
!= nullptr)
3450 cu
->base_address
= attr
->as_address ();
3453 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3454 if (attr
!= nullptr)
3455 cu
->base_address
= attr
->as_address ();
3459 /* Helper function that returns the proper abbrev section for
3462 static struct dwarf2_section_info
*
3463 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3465 struct dwarf2_section_info
*abbrev
;
3466 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
3468 if (this_cu
->is_dwz
)
3469 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
3471 abbrev
= &per_bfd
->abbrev
;
3476 /* Fetch the abbreviation table offset from a comp or type unit header. */
3479 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
3480 struct dwarf2_section_info
*section
,
3481 sect_offset sect_off
)
3483 bfd
*abfd
= section
->get_bfd_owner ();
3484 const gdb_byte
*info_ptr
;
3485 unsigned int initial_length_size
, offset_size
;
3488 section
->read (per_objfile
->objfile
);
3489 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
3490 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3491 offset_size
= initial_length_size
== 4 ? 4 : 8;
3492 info_ptr
+= initial_length_size
;
3494 version
= read_2_bytes (abfd
, info_ptr
);
3498 /* Skip unit type and address size. */
3502 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
3506 hash_signatured_type (const void *item
)
3508 const struct signatured_type
*sig_type
3509 = (const struct signatured_type
*) item
;
3511 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3512 return sig_type
->signature
;
3516 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3518 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
3519 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
3521 return lhs
->signature
== rhs
->signature
;
3527 allocate_signatured_type_table ()
3529 return htab_up (htab_create_alloc (41,
3530 hash_signatured_type
,
3532 NULL
, xcalloc
, xfree
));
3535 /* A helper for create_debug_types_hash_table. Read types from SECTION
3536 and fill them into TYPES_HTAB. It will process only type units,
3537 therefore DW_UT_type. */
3540 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
3541 struct dwo_file
*dwo_file
,
3542 dwarf2_section_info
*section
, htab_up
&types_htab
,
3543 rcuh_kind section_kind
)
3545 struct objfile
*objfile
= per_objfile
->objfile
;
3546 struct dwarf2_section_info
*abbrev_section
;
3548 const gdb_byte
*info_ptr
, *end_ptr
;
3550 abbrev_section
= &dwo_file
->sections
.abbrev
;
3552 dwarf_read_debug_printf ("Reading %s for %s",
3553 section
->get_name (),
3554 abbrev_section
->get_file_name ());
3556 section
->read (objfile
);
3557 info_ptr
= section
->buffer
;
3559 if (info_ptr
== NULL
)
3562 /* We can't set abfd until now because the section may be empty or
3563 not present, in which case the bfd is unknown. */
3564 abfd
= section
->get_bfd_owner ();
3566 /* We don't use cutu_reader here because we don't need to read
3567 any dies: the signature is in the header. */
3569 end_ptr
= info_ptr
+ section
->size
;
3570 while (info_ptr
< end_ptr
)
3572 signatured_type_up sig_type
;
3573 struct dwo_unit
*dwo_tu
;
3575 const gdb_byte
*ptr
= info_ptr
;
3576 struct comp_unit_head header
;
3577 unsigned int length
;
3579 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
3581 /* Initialize it due to a false compiler warning. */
3582 header
.signature
= -1;
3583 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
3585 /* We need to read the type's signature in order to build the hash
3586 table, but we don't need anything else just yet. */
3588 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
3589 abbrev_section
, ptr
, section_kind
);
3591 length
= header
.get_length_with_initial ();
3593 /* Skip dummy type units. */
3594 if (ptr
>= info_ptr
+ length
3595 || peek_abbrev_code (abfd
, ptr
) == 0
3596 || (header
.unit_type
!= DW_UT_type
3597 && header
.unit_type
!= DW_UT_split_type
))
3603 if (types_htab
== NULL
)
3604 types_htab
= allocate_dwo_unit_table ();
3606 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
3607 dwo_tu
->dwo_file
= dwo_file
;
3608 dwo_tu
->signature
= header
.signature
;
3609 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
3610 dwo_tu
->section
= section
;
3611 dwo_tu
->sect_off
= sect_off
;
3612 dwo_tu
->length
= length
;
3614 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
3615 gdb_assert (slot
!= NULL
);
3617 complaint (_("debug type entry at offset %s is duplicate to"
3618 " the entry at offset %s, signature %s"),
3619 sect_offset_str (sect_off
),
3620 sect_offset_str (dwo_tu
->sect_off
),
3621 hex_string (header
.signature
));
3624 dwarf_read_debug_printf_v (" offset %s, signature %s",
3625 sect_offset_str (sect_off
),
3626 hex_string (header
.signature
));
3632 /* Create the hash table of all entries in the .debug_types
3633 (or .debug_types.dwo) section(s).
3634 DWO_FILE is a pointer to the DWO file object.
3636 The result is a pointer to the hash table or NULL if there are no types.
3638 Note: This function processes DWO files only, not DWP files. */
3641 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
3642 struct dwo_file
*dwo_file
,
3643 gdb::array_view
<dwarf2_section_info
> type_sections
,
3644 htab_up
&types_htab
)
3646 for (dwarf2_section_info
§ion
: type_sections
)
3647 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
3651 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
3652 If SLOT is non-NULL, it is the entry to use in the hash table.
3653 Otherwise we find one. */
3655 static struct signatured_type
*
3656 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
3658 if (per_objfile
->per_bfd
->all_units
.size ()
3659 == per_objfile
->per_bfd
->all_units
.capacity ())
3660 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
3662 signatured_type_up sig_type_holder
3663 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
3664 signatured_type
*sig_type
= sig_type_holder
.get ();
3666 per_objfile
->per_bfd
->all_units
.emplace_back
3667 (sig_type_holder
.release ());
3671 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
3674 gdb_assert (*slot
== NULL
);
3676 /* The rest of sig_type must be filled in by the caller. */
3680 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
3681 Fill in SIG_ENTRY with DWO_ENTRY. */
3684 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
3685 struct signatured_type
*sig_entry
,
3686 struct dwo_unit
*dwo_entry
)
3688 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3690 /* Make sure we're not clobbering something we don't expect to. */
3691 gdb_assert (! sig_entry
->queued
);
3692 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
3693 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
3694 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
3695 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0
3696 || (to_underlying (sig_entry
->type_offset_in_section
)
3697 == to_underlying (dwo_entry
->type_offset_in_tu
)));
3698 gdb_assert (sig_entry
->type_unit_group
== NULL
);
3699 gdb_assert (sig_entry
->dwo_unit
== NULL
3700 || sig_entry
->dwo_unit
== dwo_entry
);
3702 sig_entry
->section
= dwo_entry
->section
;
3703 sig_entry
->sect_off
= dwo_entry
->sect_off
;
3704 sig_entry
->set_length (dwo_entry
->length
, false);
3705 sig_entry
->reading_dwo_directly
= 1;
3706 sig_entry
->per_bfd
= per_bfd
;
3707 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
3708 sig_entry
->dwo_unit
= dwo_entry
;
3711 /* Subroutine of lookup_signatured_type.
3712 If we haven't read the TU yet, create the signatured_type data structure
3713 for a TU to be read in directly from a DWO file, bypassing the stub.
3714 This is the "Stay in DWO Optimization": When there is no DWP file and we're
3715 using .gdb_index, then when reading a CU we want to stay in the DWO file
3716 containing that CU. Otherwise we could end up reading several other DWO
3717 files (due to comdat folding) to process the transitive closure of all the
3718 mentioned TUs, and that can be slow. The current DWO file will have every
3719 type signature that it needs.
3720 We only do this for .gdb_index because in the psymtab case we already have
3721 to read all the DWOs to build the type unit groups. */
3723 static struct signatured_type
*
3724 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
3726 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3727 struct dwo_file
*dwo_file
;
3728 struct dwo_unit find_dwo_entry
, *dwo_entry
;
3731 gdb_assert (cu
->dwo_unit
);
3733 /* If TU skeletons have been removed then we may not have read in any
3735 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
3736 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
3738 /* We only ever need to read in one copy of a signatured type.
3739 Use the global signatured_types array to do our own comdat-folding
3740 of types. If this is the first time we're reading this TU, and
3741 the TU has an entry in .gdb_index, replace the recorded data from
3742 .gdb_index with this TU. */
3744 signatured_type
find_sig_entry (sig
);
3745 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
3746 &find_sig_entry
, INSERT
);
3747 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
3749 /* We can get here with the TU already read, *or* in the process of being
3750 read. Don't reassign the global entry to point to this DWO if that's
3751 the case. Also note that if the TU is already being read, it may not
3752 have come from a DWO, the program may be a mix of Fission-compiled
3753 code and non-Fission-compiled code. */
3755 /* Have we already tried to read this TU?
3756 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
3757 needn't exist in the global table yet). */
3758 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
3761 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
3762 dwo_unit of the TU itself. */
3763 dwo_file
= cu
->dwo_unit
->dwo_file
;
3765 /* Ok, this is the first time we're reading this TU. */
3766 if (dwo_file
->tus
== NULL
)
3768 find_dwo_entry
.signature
= sig
;
3769 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
3771 if (dwo_entry
== NULL
)
3774 /* If the global table doesn't have an entry for this TU, add one. */
3775 if (sig_entry
== NULL
)
3776 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
3778 if (sig_entry
->dwo_unit
== nullptr)
3779 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
3780 sig_entry
->tu_read
= 1;
3784 /* Subroutine of lookup_signatured_type.
3785 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
3786 then try the DWP file. If the TU stub (skeleton) has been removed then
3787 it won't be in .gdb_index. */
3789 static struct signatured_type
*
3790 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
3792 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3793 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
3794 struct dwo_unit
*dwo_entry
;
3797 gdb_assert (cu
->dwo_unit
);
3798 gdb_assert (dwp_file
!= NULL
);
3800 /* If TU skeletons have been removed then we may not have read in any
3802 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
3803 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
3805 signatured_type
find_sig_entry (sig
);
3806 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
3807 &find_sig_entry
, INSERT
);
3808 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
3810 /* Have we already tried to read this TU?
3811 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
3812 needn't exist in the global table yet). */
3813 if (sig_entry
!= NULL
)
3816 if (dwp_file
->tus
== NULL
)
3818 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
3819 1 /* is_debug_types */);
3820 if (dwo_entry
== NULL
)
3823 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
3824 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
3829 /* Lookup a signature based type for DW_FORM_ref_sig8.
3830 Returns NULL if signature SIG is not present in the table.
3831 It is up to the caller to complain about this. */
3833 static struct signatured_type
*
3834 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
3836 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3840 /* We're in a DWO/DWP file, and we're using .gdb_index.
3841 These cases require special processing. */
3842 if (get_dwp_file (per_objfile
) == NULL
)
3843 return lookup_dwo_signatured_type (cu
, sig
);
3845 return lookup_dwp_signatured_type (cu
, sig
);
3849 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
3851 signatured_type
find_entry (sig
);
3852 return ((struct signatured_type
*)
3853 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
3858 /* Low level DIE reading support. */
3860 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3863 init_cu_die_reader (struct die_reader_specs
*reader
,
3864 struct dwarf2_cu
*cu
,
3865 struct dwarf2_section_info
*section
,
3866 struct dwo_file
*dwo_file
,
3867 struct abbrev_table
*abbrev_table
)
3869 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3870 reader
->abfd
= section
->get_bfd_owner ();
3872 reader
->dwo_file
= dwo_file
;
3873 reader
->die_section
= section
;
3874 reader
->buffer
= section
->buffer
;
3875 reader
->buffer_end
= section
->buffer
+ section
->size
;
3876 reader
->abbrev_table
= abbrev_table
;
3879 /* Subroutine of cutu_reader to simplify it.
3880 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
3881 There's just a lot of work to do, and cutu_reader is big enough
3884 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
3885 from it to the DIE in the DWO. If NULL we are skipping the stub.
3886 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
3887 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
3888 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
3889 STUB_COMP_DIR may be non-NULL.
3890 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
3891 are filled in with the info of the DIE from the DWO file.
3892 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
3893 from the dwo. Since *RESULT_READER references this abbrev table, it must be
3894 kept around for at least as long as *RESULT_READER.
3896 The result is non-zero if a valid (non-dummy) DIE was found. */
3899 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
3900 struct dwo_unit
*dwo_unit
,
3901 struct die_info
*stub_comp_unit_die
,
3902 const char *stub_comp_dir
,
3903 struct die_reader_specs
*result_reader
,
3904 const gdb_byte
**result_info_ptr
,
3905 struct die_info
**result_comp_unit_die
,
3906 abbrev_table_up
*result_dwo_abbrev_table
)
3908 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3909 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
3910 struct objfile
*objfile
= per_objfile
->objfile
;
3912 const gdb_byte
*begin_info_ptr
, *info_ptr
;
3913 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
3914 int i
,num_extra_attrs
;
3915 struct dwarf2_section_info
*dwo_abbrev_section
;
3916 struct die_info
*comp_unit_die
;
3918 /* At most one of these may be provided. */
3919 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
3921 /* These attributes aren't processed until later:
3922 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3923 DW_AT_comp_dir is used now, to find the DWO file, but it is also
3924 referenced later. However, these attributes are found in the stub
3925 which we won't have later. In order to not impose this complication
3926 on the rest of the code, we read them here and copy them to the
3935 if (stub_comp_unit_die
!= NULL
)
3937 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3939 if (!per_cu
->is_debug_types
)
3940 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
3941 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
3942 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
3943 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
3944 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
3946 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
3948 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
3949 We need the value before we can process DW_AT_ranges values from the
3951 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
3953 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
3954 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
3955 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
3956 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
3958 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
3960 else if (stub_comp_dir
!= NULL
)
3962 /* Reconstruct the comp_dir attribute to simplify the code below. */
3963 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
3964 comp_dir
->name
= DW_AT_comp_dir
;
3965 comp_dir
->form
= DW_FORM_string
;
3966 comp_dir
->set_string_noncanonical (stub_comp_dir
);
3969 /* Set up for reading the DWO CU/TU. */
3970 cu
->dwo_unit
= dwo_unit
;
3971 dwarf2_section_info
*section
= dwo_unit
->section
;
3972 section
->read (objfile
);
3973 abfd
= section
->get_bfd_owner ();
3974 begin_info_ptr
= info_ptr
= (section
->buffer
3975 + to_underlying (dwo_unit
->sect_off
));
3976 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
3978 if (per_cu
->is_debug_types
)
3980 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
3982 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
3983 section
, dwo_abbrev_section
,
3984 info_ptr
, rcuh_kind::TYPE
);
3985 /* This is not an assert because it can be caused by bad debug info. */
3986 if (sig_type
->signature
!= cu
->header
.signature
)
3988 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
3989 " TU at offset %s [in module %s]"),
3990 hex_string (sig_type
->signature
),
3991 hex_string (cu
->header
.signature
),
3992 sect_offset_str (dwo_unit
->sect_off
),
3993 bfd_get_filename (abfd
));
3995 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
3996 /* For DWOs coming from DWP files, we don't know the CU length
3997 nor the type's offset in the TU until now. */
3998 dwo_unit
->length
= cu
->header
.get_length_with_initial ();
3999 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
4001 /* Establish the type offset that can be used to lookup the type.
4002 For DWO files, we don't know it until now. */
4003 sig_type
->type_offset_in_section
4004 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
4008 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
4009 section
, dwo_abbrev_section
,
4010 info_ptr
, rcuh_kind::COMPILE
);
4011 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
4012 /* For DWOs coming from DWP files, we don't know the CU length
4014 dwo_unit
->length
= cu
->header
.get_length_with_initial ();
4017 dwo_abbrev_section
->read (objfile
);
4018 *result_dwo_abbrev_table
4019 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
4020 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
4021 result_dwo_abbrev_table
->get ());
4023 /* Read in the die, but leave space to copy over the attributes
4024 from the stub. This has the benefit of simplifying the rest of
4025 the code - all the work to maintain the illusion of a single
4026 DW_TAG_{compile,type}_unit DIE is done here. */
4027 num_extra_attrs
= ((stmt_list
!= NULL
)
4031 + (comp_dir
!= NULL
));
4032 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
4035 /* Copy over the attributes from the stub to the DIE we just read in. */
4036 comp_unit_die
= *result_comp_unit_die
;
4037 i
= comp_unit_die
->num_attrs
;
4038 if (stmt_list
!= NULL
)
4039 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4041 comp_unit_die
->attrs
[i
++] = *low_pc
;
4042 if (high_pc
!= NULL
)
4043 comp_unit_die
->attrs
[i
++] = *high_pc
;
4045 comp_unit_die
->attrs
[i
++] = *ranges
;
4046 if (comp_dir
!= NULL
)
4047 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4048 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4050 if (dwarf_die_debug
)
4052 gdb_printf (gdb_stdlog
,
4053 "Read die from %s@0x%x of %s:\n",
4054 section
->get_name (),
4055 (unsigned) (begin_info_ptr
- section
->buffer
),
4056 bfd_get_filename (abfd
));
4057 comp_unit_die
->dump (dwarf_die_debug
);
4060 /* Skip dummy compilation units. */
4061 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4062 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4065 *result_info_ptr
= info_ptr
;
4069 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
4070 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
4071 signature is part of the header. */
4072 static gdb::optional
<ULONGEST
>
4073 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
4075 if (cu
->header
.version
>= 5)
4076 return cu
->header
.signature
;
4077 struct attribute
*attr
;
4078 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4079 if (attr
== nullptr || !attr
->form_is_unsigned ())
4080 return gdb::optional
<ULONGEST
> ();
4081 return attr
->as_unsigned ();
4084 /* Subroutine of cutu_reader to simplify it.
4085 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
4086 Returns NULL if the specified DWO unit cannot be found. */
4088 static struct dwo_unit
*
4089 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
4092 /* We need a lock here both to handle the DWO hash table, and BFD,
4093 which is not thread-safe. */
4094 static std::mutex dwo_lock
;
4096 std::lock_guard
<std::mutex
> guard (dwo_lock
);
4099 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4100 struct dwo_unit
*dwo_unit
;
4101 const char *comp_dir
;
4103 gdb_assert (cu
!= NULL
);
4105 /* Yeah, we look dwo_name up again, but it simplifies the code. */
4106 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
4107 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4109 if (per_cu
->is_debug_types
)
4110 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
4113 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
4115 if (!signature
.has_value ())
4116 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
4118 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
4120 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
4126 /* Subroutine of cutu_reader to simplify it.
4127 See it for a description of the parameters.
4128 Read a TU directly from a DWO file, bypassing the stub. */
4131 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
4132 dwarf2_per_objfile
*per_objfile
,
4133 dwarf2_cu
*existing_cu
)
4135 struct signatured_type
*sig_type
;
4137 /* Verify we can do the following downcast, and that we have the
4139 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
4140 sig_type
= (struct signatured_type
*) this_cu
;
4141 gdb_assert (sig_type
->dwo_unit
!= NULL
);
4145 if (existing_cu
!= nullptr)
4148 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
4149 /* There's no need to do the rereading_dwo_cu handling that
4150 cutu_reader does since we don't read the stub. */
4154 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
4155 in per_objfile yet. */
4156 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
4157 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
4158 cu
= m_new_cu
.get ();
4161 /* A future optimization, if needed, would be to use an existing
4162 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
4163 could share abbrev tables. */
4165 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
4166 NULL
/* stub_comp_unit_die */,
4167 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
4170 &m_dwo_abbrev_table
) == 0)
4177 /* Initialize a CU (or TU) and read its DIEs.
4178 If the CU defers to a DWO file, read the DWO file as well.
4180 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4181 Otherwise the table specified in the comp unit header is read in and used.
4182 This is an optimization for when we already have the abbrev table.
4184 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
4187 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
4188 dwarf2_per_objfile
*per_objfile
,
4189 struct abbrev_table
*abbrev_table
,
4190 dwarf2_cu
*existing_cu
,
4192 abbrev_cache
*cache
)
4193 : die_reader_specs
{},
4196 struct objfile
*objfile
= per_objfile
->objfile
;
4197 struct dwarf2_section_info
*section
= this_cu
->section
;
4198 bfd
*abfd
= section
->get_bfd_owner ();
4199 const gdb_byte
*begin_info_ptr
;
4200 struct signatured_type
*sig_type
= NULL
;
4201 struct dwarf2_section_info
*abbrev_section
;
4202 /* Non-zero if CU currently points to a DWO file and we need to
4203 reread it. When this happens we need to reread the skeleton die
4204 before we can reread the DWO file (this only applies to CUs, not TUs). */
4205 int rereading_dwo_cu
= 0;
4207 if (dwarf_die_debug
)
4208 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
4209 this_cu
->is_debug_types
? "type" : "comp",
4210 sect_offset_str (this_cu
->sect_off
));
4212 /* If we're reading a TU directly from a DWO file, including a virtual DWO
4213 file (instead of going through the stub), short-circuit all of this. */
4214 if (this_cu
->reading_dwo_directly
)
4216 /* Narrow down the scope of possibilities to have to understand. */
4217 gdb_assert (this_cu
->is_debug_types
);
4218 gdb_assert (abbrev_table
== NULL
);
4219 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
4223 /* This is cheap if the section is already read in. */
4224 section
->read (objfile
);
4226 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
4228 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4232 if (existing_cu
!= nullptr)
4235 /* If this CU is from a DWO file we need to start over, we need to
4236 refetch the attributes from the skeleton CU.
4237 This could be optimized by retrieving those attributes from when we
4238 were here the first time: the previous comp_unit_die was stored in
4239 comp_unit_obstack. But there's no data yet that we need this
4241 if (cu
->dwo_unit
!= NULL
)
4242 rereading_dwo_cu
= 1;
4246 /* If an existing_cu is provided, a dwarf2_cu must not exist for
4247 this_cu in per_objfile yet. Here, CACHE doubles as a flag to
4248 let us know that the CU is being scanned using the parallel
4249 indexer. This assert is avoided in this case because (1) it
4250 is irrelevant, and (2) the get_cu method is not
4252 gdb_assert (cache
!= nullptr
4253 || per_objfile
->get_cu (this_cu
) == nullptr);
4254 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
4255 cu
= m_new_cu
.get ();
4258 /* Get the header. */
4259 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
4261 /* We already have the header, there's no need to read it in again. */
4262 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
4266 if (this_cu
->is_debug_types
)
4268 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
4269 section
, abbrev_section
,
4270 info_ptr
, rcuh_kind::TYPE
);
4272 /* Since per_cu is the first member of struct signatured_type,
4273 we can go from a pointer to one to a pointer to the other. */
4274 sig_type
= (struct signatured_type
*) this_cu
;
4275 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
4276 gdb_assert (sig_type
->type_offset_in_tu
4277 == cu
->header
.type_cu_offset_in_tu
);
4278 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
4280 /* LENGTH has not been set yet for type units if we're
4281 using .gdb_index. */
4282 this_cu
->set_length (cu
->header
.get_length_with_initial ());
4284 /* Establish the type offset that can be used to lookup the type. */
4285 sig_type
->type_offset_in_section
=
4286 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
4288 this_cu
->set_version (cu
->header
.version
);
4292 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
4293 section
, abbrev_section
,
4295 rcuh_kind::COMPILE
);
4297 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
4298 this_cu
->set_length (cu
->header
.get_length_with_initial ());
4299 this_cu
->set_version (cu
->header
.version
);
4303 /* Skip dummy compilation units. */
4304 if (info_ptr
>= begin_info_ptr
+ this_cu
->length ()
4305 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4311 /* If we don't have them yet, read the abbrevs for this compilation unit.
4312 And if we need to read them now, make sure they're freed when we're
4314 if (abbrev_table
!= NULL
)
4315 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
4318 if (cache
!= nullptr)
4319 abbrev_table
= cache
->find (abbrev_section
,
4320 cu
->header
.abbrev_sect_off
);
4321 if (abbrev_table
== nullptr)
4323 abbrev_section
->read (objfile
);
4324 m_abbrev_table_holder
4325 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
4326 abbrev_table
= m_abbrev_table_holder
.get ();
4330 /* Read the top level CU/TU die. */
4331 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
4332 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
4334 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
4340 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
4341 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
4342 table from the DWO file and pass the ownership over to us. It will be
4343 referenced from READER, so we must make sure to free it after we're done
4346 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
4347 DWO CU, that this test will fail (the attribute will not be present). */
4348 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
4349 if (dwo_name
!= nullptr)
4351 struct dwo_unit
*dwo_unit
;
4352 struct die_info
*dwo_comp_unit_die
;
4354 if (comp_unit_die
->has_children
)
4356 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
4357 " has children (offset %s) [in module %s]"),
4358 sect_offset_str (this_cu
->sect_off
),
4359 bfd_get_filename (abfd
));
4361 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
4362 if (dwo_unit
!= NULL
)
4364 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
4365 comp_unit_die
, NULL
,
4368 &m_dwo_abbrev_table
) == 0)
4374 comp_unit_die
= dwo_comp_unit_die
;
4378 /* Yikes, we couldn't find the rest of the DIE, we only have
4379 the stub. A complaint has already been logged. There's
4380 not much more we can do except pass on the stub DIE to
4381 die_reader_func. We don't want to throw an error on bad
4388 cutu_reader::keep ()
4390 /* Done, clean up. */
4391 gdb_assert (!dummy_p
);
4392 if (m_new_cu
!= NULL
)
4394 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
4396 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
4397 per_objfile
->set_cu (m_this_cu
, std::move (m_new_cu
));
4401 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
4402 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
4403 assumed to have already done the lookup to find the DWO file).
4405 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4406 THIS_CU->is_debug_types, but nothing else.
4408 We fill in THIS_CU->length.
4410 THIS_CU->cu is always freed when done.
4411 This is done in order to not leave THIS_CU->cu in a state where we have
4412 to care whether it refers to the "main" CU or the DWO CU.
4414 When parent_cu is passed, it is used to provide a default value for
4415 str_offsets_base and addr_base from the parent. */
4417 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
4418 dwarf2_per_objfile
*per_objfile
,
4419 struct dwarf2_cu
*parent_cu
,
4420 struct dwo_file
*dwo_file
)
4421 : die_reader_specs
{},
4424 struct objfile
*objfile
= per_objfile
->objfile
;
4425 struct dwarf2_section_info
*section
= this_cu
->section
;
4426 bfd
*abfd
= section
->get_bfd_owner ();
4427 struct dwarf2_section_info
*abbrev_section
;
4428 const gdb_byte
*begin_info_ptr
, *info_ptr
;
4430 if (dwarf_die_debug
)
4431 gdb_printf (gdb_stdlog
, "Reading %s unit at offset %s\n",
4432 this_cu
->is_debug_types
? "type" : "comp",
4433 sect_offset_str (this_cu
->sect_off
));
4435 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
4437 abbrev_section
= (dwo_file
!= NULL
4438 ? &dwo_file
->sections
.abbrev
4439 : get_abbrev_section_for_cu (this_cu
));
4441 /* This is cheap if the section is already read in. */
4442 section
->read (objfile
);
4444 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
4446 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
4447 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
4448 section
, abbrev_section
, info_ptr
,
4449 (this_cu
->is_debug_types
4451 : rcuh_kind::COMPILE
));
4453 if (parent_cu
!= nullptr)
4455 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
4456 m_new_cu
->addr_base
= parent_cu
->addr_base
;
4458 this_cu
->set_length (m_new_cu
->header
.get_length_with_initial ());
4460 /* Skip dummy compilation units. */
4461 if (info_ptr
>= begin_info_ptr
+ this_cu
->length ()
4462 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4468 abbrev_section
->read (objfile
);
4469 m_abbrev_table_holder
4470 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
4472 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
4473 m_abbrev_table_holder
.get ());
4474 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
4478 /* Type Unit Groups.
4480 Type Unit Groups are a way to collapse the set of all TUs (type units) into
4481 a more manageable set. The grouping is done by DW_AT_stmt_list entry
4482 so that all types coming from the same compilation (.o file) are grouped
4483 together. A future step could be to put the types in the same symtab as
4484 the CU the types ultimately came from. */
4487 hash_type_unit_group (const void *item
)
4489 const struct type_unit_group
*tu_group
4490 = (const struct type_unit_group
*) item
;
4492 return hash_stmt_list_entry (&tu_group
->hash
);
4496 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4498 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
4499 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
4501 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4504 /* Allocate a hash table for type unit groups. */
4507 allocate_type_unit_groups_table ()
4509 return htab_up (htab_create_alloc (3,
4510 hash_type_unit_group
,
4512 htab_delete_entry
<type_unit_group
>,
4516 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4517 partial symtabs. We combine several TUs per psymtab to not let the size
4518 of any one psymtab grow too big. */
4519 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4520 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4522 /* Helper routine for get_type_unit_group.
4523 Create the type_unit_group object used to hold one or more TUs. */
4525 static std::unique_ptr
<type_unit_group
>
4526 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
4528 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
4530 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
4531 tu_group
->hash
.line_sect_off
= line_offset_struct
;
4536 /* Look up the type_unit_group for type unit CU, and create it if necessary.
4537 STMT_LIST is a DW_AT_stmt_list attribute. */
4539 static struct type_unit_group
*
4540 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
4542 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
4543 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
4544 struct type_unit_group
*tu_group
;
4546 unsigned int line_offset
;
4547 struct type_unit_group type_unit_group_for_lookup
;
4549 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
4550 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
4552 /* Do we need to create a new group, or can we use an existing one? */
4554 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
4556 line_offset
= stmt_list
->as_unsigned ();
4557 ++tu_stats
->nr_symtab_sharers
;
4561 /* Ugh, no stmt_list. Rare, but we have to handle it.
4562 We can do various things here like create one group per TU or
4563 spread them over multiple groups to split up the expansion work.
4564 To avoid worst case scenarios (too many groups or too large groups)
4565 we, umm, group them in bunches. */
4566 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
4567 | (tu_stats
->nr_stmt_less_type_units
4568 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
4569 ++tu_stats
->nr_stmt_less_type_units
;
4572 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
4573 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
4574 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
4575 &type_unit_group_for_lookup
, INSERT
);
4576 if (*slot
== nullptr)
4578 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
4579 std::unique_ptr
<type_unit_group
> grp
4580 = create_type_unit_group (cu
, line_offset_struct
);
4581 *slot
= grp
.release ();
4582 ++tu_stats
->nr_symtabs
;
4585 tu_group
= (struct type_unit_group
*) *slot
;
4586 gdb_assert (tu_group
!= nullptr);
4591 /* An instance of this is created when scanning DWARF to create a
4594 class cooked_index_storage
4598 cooked_index_storage ()
4599 : m_reader_hash (htab_create_alloc (10, hash_cutu_reader
,
4601 htab_delete_entry
<cutu_reader
>,
4603 m_index (new cooked_index_shard
)
4607 DISABLE_COPY_AND_ASSIGN (cooked_index_storage
);
4609 /* Return the current abbrev cache. */
4610 abbrev_cache
*get_abbrev_cache ()
4612 return &m_abbrev_cache
;
4615 /* Return the DIE reader corresponding to PER_CU. If no such reader
4616 has been registered, return NULL. */
4617 cutu_reader
*get_reader (dwarf2_per_cu_data
*per_cu
)
4619 int index
= per_cu
->index
;
4620 return (cutu_reader
*) htab_find_with_hash (m_reader_hash
.get (),
4624 /* Preserve READER by storing it in the local hash table. */
4625 cutu_reader
*preserve (std::unique_ptr
<cutu_reader
> reader
)
4627 m_abbrev_cache
.add (reader
->release_abbrev_table ());
4629 int index
= reader
->cu
->per_cu
->index
;
4630 void **slot
= htab_find_slot_with_hash (m_reader_hash
.get (), &index
,
4632 gdb_assert (*slot
== nullptr);
4633 cutu_reader
*result
= reader
.get ();
4634 *slot
= reader
.release ();
4638 /* Add an entry to the index. The arguments describe the entry; see
4639 cooked-index.h. The new entry is returned. */
4640 const cooked_index_entry
*add (sect_offset die_offset
, enum dwarf_tag tag
,
4641 cooked_index_flag flags
,
4643 const cooked_index_entry
*parent_entry
,
4644 dwarf2_per_cu_data
*per_cu
)
4646 return m_index
->add (die_offset
, tag
, flags
, name
, parent_entry
, per_cu
);
4649 /* Install the current addrmap into the index shard being constructed,
4650 then transfer ownership of the index to the caller. */
4651 std::unique_ptr
<cooked_index_shard
> release ()
4653 m_index
->install_addrmap (&m_addrmap
);
4654 return std::move (m_index
);
4657 /* Return the mutable addrmap that is currently being created. */
4658 addrmap_mutable
*get_addrmap ()
4665 /* Hash function for a cutu_reader. */
4666 static hashval_t
hash_cutu_reader (const void *a
)
4668 const cutu_reader
*reader
= (const cutu_reader
*) a
;
4669 return reader
->cu
->per_cu
->index
;
4672 /* Equality function for cutu_reader. */
4673 static int eq_cutu_reader (const void *a
, const void *b
)
4675 const cutu_reader
*ra
= (const cutu_reader
*) a
;
4676 const int *rb
= (const int *) b
;
4677 return ra
->cu
->per_cu
->index
== *rb
;
4680 /* The abbrev cache used by this indexer. */
4681 abbrev_cache m_abbrev_cache
;
4682 /* A hash table of cutu_reader objects. */
4683 htab_up m_reader_hash
;
4684 /* The index shard that is being constructed. */
4685 std::unique_ptr
<cooked_index_shard
> m_index
;
4687 /* A writeable addrmap being constructed by this scanner. */
4688 addrmap_mutable m_addrmap
;
4691 /* An instance of this is created to index a CU. */
4693 class cooked_indexer
4697 cooked_indexer (cooked_index_storage
*storage
,
4698 dwarf2_per_cu_data
*per_cu
,
4699 enum language language
)
4700 : m_index_storage (storage
),
4702 m_language (language
)
4706 DISABLE_COPY_AND_ASSIGN (cooked_indexer
);
4708 /* Index the given CU. */
4709 void make_index (cutu_reader
*reader
);
4713 /* A helper function to turn a section offset into an address that
4714 can be used in an addrmap. */
4715 CORE_ADDR
form_addr (sect_offset offset
, bool is_dwz
)
4717 CORE_ADDR value
= to_underlying (offset
);
4719 value
|= ((CORE_ADDR
) 1) << (8 * sizeof (CORE_ADDR
) - 1);
4723 /* A helper function to scan the PC bounds of READER and record them
4724 in the storage's addrmap. */
4725 void check_bounds (cutu_reader
*reader
);
4727 /* Ensure that the indicated CU exists. The cutu_reader for it is
4728 returned. FOR_SCANNING is true if the caller intends to scan all
4729 the DIEs in the CU; when false, this use is assumed to be to look
4730 up just a single DIE. */
4731 cutu_reader
*ensure_cu_exists (cutu_reader
*reader
,
4732 dwarf2_per_objfile
*per_objfile
,
4733 sect_offset sect_off
,
4737 /* Index DIEs in the READER starting at INFO_PTR. PARENT_ENTRY is
4738 the entry for the enclosing scope (nullptr at top level). FULLY
4739 is true when a full scan must be done -- in some languages,
4740 function scopes must be fully explored in order to find nested
4741 functions. This returns a pointer to just after the spot where
4743 const gdb_byte
*index_dies (cutu_reader
*reader
,
4744 const gdb_byte
*info_ptr
,
4745 const cooked_index_entry
*parent_entry
,
4748 /* Scan the attributes for a given DIE and update the out
4749 parameters. Returns a pointer to the byte after the DIE. */
4750 const gdb_byte
*scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
4751 cutu_reader
*reader
,
4752 const gdb_byte
*watermark_ptr
,
4753 const gdb_byte
*info_ptr
,
4754 const abbrev_info
*abbrev
,
4756 const char **linkage_name
,
4757 cooked_index_flag
*flags
,
4758 sect_offset
*sibling_offset
,
4759 const cooked_index_entry
**parent_entry
,
4760 CORE_ADDR
*maybe_defer
,
4761 bool for_specification
);
4763 /* Handle DW_TAG_imported_unit, by scanning the DIE to find
4764 DW_AT_import, and then scanning the referenced CU. Returns a
4765 pointer to the byte after the DIE. */
4766 const gdb_byte
*index_imported_unit (cutu_reader
*reader
,
4767 const gdb_byte
*info_ptr
,
4768 const abbrev_info
*abbrev
);
4770 /* Recursively read DIEs, recording the section offsets in
4771 m_die_range_map and then calling index_dies. */
4772 const gdb_byte
*recurse (cutu_reader
*reader
,
4773 const gdb_byte
*info_ptr
,
4774 const cooked_index_entry
*parent_entry
,
4777 /* The storage object, where the results are kept. */
4778 cooked_index_storage
*m_index_storage
;
4779 /* The CU that we are reading on behalf of. This object might be
4780 asked to index one CU but to treat the results as if they come
4781 from some including CU; in this case the including CU would be
4783 dwarf2_per_cu_data
*m_per_cu
;
4784 /* The language that we're assuming when reading. */
4785 enum language m_language
;
4787 /* An addrmap that maps from section offsets (see the form_addr
4788 method) to newly-created entries. See m_deferred_entries to
4790 addrmap_mutable m_die_range_map
;
4792 /* A single deferred entry. */
4793 struct deferred_entry
4795 sect_offset die_offset
;
4797 CORE_ADDR spec_offset
;
4799 cooked_index_flag flags
;
4802 /* The generated DWARF can sometimes have the declaration for a
4803 method in a class (or perhaps namespace) scope, with the
4804 definition appearing outside this scope... just one of the many
4805 bad things about DWARF. In order to handle this situation, we
4806 defer certain entries until the end of scanning, at which point
4807 we'll know the containing context of all the DIEs that we might
4808 have scanned. This vector stores these deferred entries. */
4809 std::vector
<deferred_entry
> m_deferred_entries
;
4812 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4813 Process compilation unit THIS_CU for a psymtab. */
4816 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
4817 dwarf2_per_objfile
*per_objfile
,
4818 cooked_index_storage
*storage
)
4820 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false,
4821 storage
->get_abbrev_cache ());
4823 if (reader
.comp_unit_die
== nullptr)
4830 else if (this_cu
->is_debug_types
)
4831 build_type_psymtabs_reader (&reader
, storage
);
4832 else if (reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
4835 if (this_cu
->scanned
.compare_exchange_strong (nope
, true))
4837 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
4839 gdb_assert (storage
!= nullptr);
4840 cooked_indexer
indexer (storage
, this_cu
, reader
.cu
->lang ());
4841 indexer
.make_index (&reader
);
4846 /* Reader function for build_type_psymtabs. */
4849 build_type_psymtabs_reader (cutu_reader
*reader
,
4850 cooked_index_storage
*storage
)
4852 struct dwarf2_cu
*cu
= reader
->cu
;
4853 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4854 struct die_info
*type_unit_die
= reader
->comp_unit_die
;
4856 gdb_assert (per_cu
->is_debug_types
);
4858 if (! type_unit_die
->has_children
)
4861 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
4863 gdb_assert (storage
!= nullptr);
4864 cooked_indexer
indexer (storage
, per_cu
, cu
->lang ());
4865 indexer
.make_index (reader
);
4868 /* Struct used to sort TUs by their abbreviation table offset. */
4870 struct tu_abbrev_offset
4872 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
4873 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
4876 /* This is used when sorting. */
4877 bool operator< (const tu_abbrev_offset
&other
) const
4879 return abbrev_offset
< other
.abbrev_offset
;
4882 signatured_type
*sig_type
;
4883 sect_offset abbrev_offset
;
4886 /* Efficiently read all the type units.
4888 The efficiency is because we sort TUs by the abbrev table they use and
4889 only read each abbrev table once. In one program there are 200K TUs
4890 sharing 8K abbrev tables.
4892 The main purpose of this function is to support building the
4893 dwarf2_per_objfile->per_bfd->type_unit_groups table.
4894 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
4895 can collapse the search space by grouping them by stmt_list.
4896 The savings can be significant, in the same program from above the 200K TUs
4897 share 8K stmt_list tables.
4899 FUNC is expected to call get_type_unit_group, which will create the
4900 struct type_unit_group if necessary and add it to
4901 dwarf2_per_objfile->per_bfd->type_unit_groups. */
4904 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
,
4905 cooked_index_storage
*storage
)
4907 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
4908 abbrev_table_up abbrev_table
;
4909 sect_offset abbrev_offset
;
4911 /* It's up to the caller to not call us multiple times. */
4912 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
4914 if (per_objfile
->per_bfd
->all_type_units
.size () == 0)
4917 /* TUs typically share abbrev tables, and there can be way more TUs than
4918 abbrev tables. Sort by abbrev table to reduce the number of times we
4919 read each abbrev table in.
4920 Alternatives are to punt or to maintain a cache of abbrev tables.
4921 This is simpler and efficient enough for now.
4923 Later we group TUs by their DW_AT_stmt_list value (as this defines the
4924 symtab to use). Typically TUs with the same abbrev offset have the same
4925 stmt_list value too so in practice this should work well.
4927 The basic algorithm here is:
4929 sort TUs by abbrev table
4930 for each TU with same abbrev table:
4931 read abbrev table if first user
4932 read TU top level DIE
4933 [IWBN if DWO skeletons had DW_AT_stmt_list]
4936 dwarf_read_debug_printf ("Building type unit groups ...");
4938 /* Sort in a separate table to maintain the order of all_units
4939 for .gdb_index: TU indices directly index all_type_units. */
4940 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
4941 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
4943 for (const auto &cu
: per_objfile
->per_bfd
->all_units
)
4945 if (cu
->is_debug_types
)
4947 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
4948 sorted_by_abbrev
.emplace_back
4949 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
4950 sig_type
->sect_off
));
4954 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
4956 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
4958 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
4960 /* Switch to the next abbrev table if necessary. */
4961 if (abbrev_table
== NULL
4962 || tu
.abbrev_offset
!= abbrev_offset
)
4964 abbrev_offset
= tu
.abbrev_offset
;
4965 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
4967 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
4968 ++tu_stats
->nr_uniq_abbrev_tables
;
4971 cutu_reader
reader (tu
.sig_type
, per_objfile
,
4972 abbrev_table
.get (), nullptr, false);
4973 if (!reader
.dummy_p
)
4974 build_type_psymtabs_reader (&reader
, storage
);
4978 /* Print collected type unit statistics. */
4981 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
4983 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
4985 dwarf_read_debug_printf ("Type unit statistics:");
4986 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
4987 dwarf_read_debug_printf (" %d uniq abbrev tables",
4988 tu_stats
->nr_uniq_abbrev_tables
);
4989 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
4990 tu_stats
->nr_symtabs
);
4991 dwarf_read_debug_printf (" %d symtab sharers",
4992 tu_stats
->nr_symtab_sharers
);
4993 dwarf_read_debug_printf (" %d type units without a stmt_list",
4994 tu_stats
->nr_stmt_less_type_units
);
4995 dwarf_read_debug_printf (" %d all_type_units reallocs",
4996 tu_stats
->nr_all_type_units_reallocs
);
4999 struct skeleton_data
5001 dwarf2_per_objfile
*per_objfile
;
5002 cooked_index_storage
*storage
;
5005 /* Traversal function for process_skeletonless_type_unit.
5006 Read a TU in a DWO file and build partial symbols for it. */
5009 process_skeletonless_type_unit (void **slot
, void *info
)
5011 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
5012 skeleton_data
*data
= (skeleton_data
*) info
;
5014 /* If this TU doesn't exist in the global table, add it and read it in. */
5016 if (data
->per_objfile
->per_bfd
->signatured_types
== NULL
)
5017 data
->per_objfile
->per_bfd
->signatured_types
5018 = allocate_signatured_type_table ();
5020 signatured_type
find_entry (dwo_unit
->signature
);
5021 slot
= htab_find_slot (data
->per_objfile
->per_bfd
->signatured_types
.get (),
5022 &find_entry
, INSERT
);
5023 /* If we've already seen this type there's nothing to do. What's happening
5024 is we're doing our own version of comdat-folding here. */
5028 /* This does the job that create_all_units would have done for
5030 signatured_type
*entry
5031 = add_type_unit (data
->per_objfile
, dwo_unit
->signature
, slot
);
5032 fill_in_sig_entry_from_dwo_entry (data
->per_objfile
, entry
, dwo_unit
);
5035 /* This does the job that build_type_psymtabs would have done. */
5036 cutu_reader
reader (entry
, data
->per_objfile
, nullptr, nullptr, false);
5037 if (!reader
.dummy_p
)
5038 build_type_psymtabs_reader (&reader
, data
->storage
);
5043 /* Traversal function for process_skeletonless_type_units. */
5046 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
5048 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
5050 if (dwo_file
->tus
!= NULL
)
5051 htab_traverse_noresize (dwo_file
->tus
.get (),
5052 process_skeletonless_type_unit
, info
);
5057 /* Scan all TUs of DWO files, verifying we've processed them.
5058 This is needed in case a TU was emitted without its skeleton.
5059 Note: This can't be done until we know what all the DWO files are. */
5062 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
,
5063 cooked_index_storage
*storage
)
5065 skeleton_data data
{ per_objfile
, storage
};
5067 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
5068 if (get_dwp_file (per_objfile
) == NULL
5069 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
5071 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
5072 process_dwo_file_for_skeletonless_type_units
,
5077 /* Build the partial symbol table by doing a quick pass through the
5078 .debug_info and .debug_abbrev sections. */
5081 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
5083 struct objfile
*objfile
= per_objfile
->objfile
;
5084 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5086 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
5087 objfile_name (objfile
));
5089 per_bfd
->map_info_sections (objfile
);
5091 cooked_index_storage index_storage
;
5092 create_all_units (per_objfile
);
5093 build_type_psymtabs (per_objfile
, &index_storage
);
5094 std::vector
<std::unique_ptr
<cooked_index_shard
>> indexes
;
5096 per_bfd
->quick_file_names_table
5097 = create_quick_file_names_table (per_bfd
->all_units
.size ());
5098 if (!per_bfd
->debug_aranges
.empty ())
5099 read_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
,
5100 index_storage
.get_addrmap ());
5103 /* Ensure that complaints are handled correctly. */
5104 complaint_interceptor complaint_handler
;
5106 using iter_type
= decltype (per_bfd
->all_units
.begin ());
5108 auto task_size_
= [] (iter_type iter
)
5110 dwarf2_per_cu_data
*per_cu
= iter
->get ();
5111 return (size_t)per_cu
->length ();
5113 auto task_size
= gdb::make_function_view (task_size_
);
5115 /* Each thread returns a pair holding a cooked index, and a vector
5116 of errors that should be printed. The latter is done because
5117 GDB's I/O system is not thread-safe. run_on_main_thread could be
5118 used, but that would mean the messages are printed after the
5119 prompt, which looks weird. */
5120 using result_type
= std::pair
<std::unique_ptr
<cooked_index_shard
>,
5121 std::vector
<gdb_exception
>>;
5122 std::vector
<result_type
> results
5123 = gdb::parallel_for_each (1, per_bfd
->all_units
.begin (),
5124 per_bfd
->all_units
.end (),
5125 [=] (iter_type iter
, iter_type end
)
5127 std::vector
<gdb_exception
> errors
;
5128 cooked_index_storage thread_storage
;
5129 for (; iter
!= end
; ++iter
)
5131 dwarf2_per_cu_data
*per_cu
= iter
->get ();
5134 process_psymtab_comp_unit (per_cu
, per_objfile
,
5137 catch (gdb_exception
&except
)
5139 errors
.push_back (std::move (except
));
5142 return result_type (thread_storage
.release (), std::move (errors
));
5145 /* Only show a given exception a single time. */
5146 std::unordered_set
<gdb_exception
> seen_exceptions
;
5147 for (auto &one_result
: results
)
5149 indexes
.push_back (std::move (one_result
.first
));
5150 for (auto &one_exc
: one_result
.second
)
5151 if (seen_exceptions
.insert (one_exc
).second
)
5152 exception_print (gdb_stderr
, one_exc
);
5156 /* This has to wait until we read the CUs, we need the list of DWOs. */
5157 process_skeletonless_type_units (per_objfile
, &index_storage
);
5159 if (dwarf_read_debug
> 0)
5160 print_tu_stats (per_objfile
);
5162 indexes
.push_back (index_storage
.release ());
5163 indexes
.shrink_to_fit ();
5165 cooked_index
*vec
= new cooked_index (std::move (indexes
));
5166 per_bfd
->index_table
.reset (vec
);
5168 const cooked_index_entry
*main_entry
= vec
->get_main ();
5169 if (main_entry
!= nullptr)
5171 /* We only do this for names not requiring canonicalization. At
5172 this point in the process names have not been canonicalized.
5173 However, currently, languages that require this step also do
5174 not use DW_AT_main_subprogram. An assert is appropriate here
5175 because this filtering is done in get_main. */
5176 enum language lang
= main_entry
->per_cu
->lang ();
5177 gdb_assert (!language_requires_canonicalization (lang
));
5178 const char *full_name
= main_entry
->full_name (&per_bfd
->obstack
, true);
5179 set_objfile_main_name (objfile
, full_name
, lang
);
5182 dwarf_read_debug_printf ("Done building psymtabs of %s",
5183 objfile_name (objfile
));
5187 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
5188 struct dwarf2_section_info
*section
,
5189 struct dwarf2_section_info
*abbrev_section
,
5190 unsigned int is_dwz
,
5191 htab_up
&types_htab
,
5192 rcuh_kind section_kind
)
5194 const gdb_byte
*info_ptr
;
5195 struct objfile
*objfile
= per_objfile
->objfile
;
5197 dwarf_read_debug_printf ("Reading %s for %s",
5198 section
->get_name (),
5199 section
->get_file_name ());
5201 section
->read (objfile
);
5203 info_ptr
= section
->buffer
;
5205 while (info_ptr
< section
->buffer
+ section
->size
)
5207 dwarf2_per_cu_data_up this_cu
;
5209 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
5211 comp_unit_head cu_header
;
5212 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
5213 abbrev_section
, info_ptr
,
5216 /* Save the compilation unit for later lookup. */
5217 if (cu_header
.unit_type
!= DW_UT_type
)
5218 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
5221 if (types_htab
== nullptr)
5222 types_htab
= allocate_signatured_type_table ();
5224 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
5225 (cu_header
.signature
);
5226 signatured_type
*sig_ptr
= sig_type
.get ();
5227 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
5228 this_cu
.reset (sig_type
.release ());
5230 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
5231 gdb_assert (slot
!= nullptr);
5232 if (*slot
!= nullptr)
5233 complaint (_("debug type entry at offset %s is duplicate to"
5234 " the entry at offset %s, signature %s"),
5235 sect_offset_str (sect_off
),
5236 sect_offset_str (sig_ptr
->sect_off
),
5237 hex_string (sig_ptr
->signature
));
5240 this_cu
->sect_off
= sect_off
;
5241 this_cu
->set_length (cu_header
.get_length_with_initial ());
5242 this_cu
->is_dwz
= is_dwz
;
5243 this_cu
->section
= section
;
5244 /* Init this asap, to avoid a data race in the set_version in
5245 cutu_reader::cutu_reader (which may be run in parallel for the cooked
5247 this_cu
->set_version (cu_header
.version
);
5249 info_ptr
= info_ptr
+ this_cu
->length ();
5250 per_objfile
->per_bfd
->all_units
.push_back (std::move (this_cu
));
5254 /* Initialize the views on all_units. */
5257 finalize_all_units (dwarf2_per_bfd
*per_bfd
)
5259 size_t nr_tus
= per_bfd
->tu_stats
.nr_tus
;
5260 size_t nr_cus
= per_bfd
->all_units
.size () - nr_tus
;
5261 gdb::array_view
<dwarf2_per_cu_data_up
> tmp
= per_bfd
->all_units
;
5262 per_bfd
->all_comp_units
= tmp
.slice (0, nr_cus
);
5263 per_bfd
->all_type_units
= tmp
.slice (nr_cus
, nr_tus
);
5266 /* Create a list of all compilation units in OBJFILE.
5267 This is only done for -readnow and building partial symtabs. */
5270 create_all_units (dwarf2_per_objfile
*per_objfile
)
5273 gdb_assert (per_objfile
->per_bfd
->all_units
.empty ());
5275 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
5276 &per_objfile
->per_bfd
->abbrev
, 0,
5277 types_htab
, rcuh_kind::COMPILE
);
5278 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
5279 read_comp_units_from_section (per_objfile
, §ion
,
5280 &per_objfile
->per_bfd
->abbrev
, 0,
5281 types_htab
, rcuh_kind::TYPE
);
5286 dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
5288 catch (const gdb_exception_error
&)
5290 per_objfile
->per_bfd
->all_units
.clear ();
5295 /* Pre-read the sections we'll need to construct an index. */
5296 struct objfile
*objfile
= per_objfile
->objfile
;
5297 dwz
->abbrev
.read (objfile
);
5298 dwz
->info
.read (objfile
);
5299 dwz
->str
.read (objfile
);
5300 dwz
->line
.read (objfile
);
5301 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
5302 types_htab
, rcuh_kind::COMPILE
);
5305 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
5307 finalize_all_units (per_objfile
->per_bfd
);
5310 /* Return the initial uleb128 in the die at INFO_PTR. */
5313 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
5315 unsigned int bytes_read
;
5317 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5320 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
5321 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
5323 Return the corresponding abbrev, or NULL if the number is zero (indicating
5324 an empty DIE). In either case *BYTES_READ will be set to the length of
5325 the initial number. */
5327 static const struct abbrev_info
*
5328 peek_die_abbrev (const die_reader_specs
&reader
,
5329 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
5331 dwarf2_cu
*cu
= reader
.cu
;
5332 bfd
*abfd
= reader
.abfd
;
5333 unsigned int abbrev_number
5334 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5336 if (abbrev_number
== 0)
5339 const abbrev_info
*abbrev
5340 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
5343 error (_("Dwarf Error: Could not find abbrev number %d in %s"
5344 " at offset %s [in module %s]"),
5345 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
5346 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
5352 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5353 Returns a pointer to the end of a series of DIEs, terminated by an empty
5354 DIE. Any children of the skipped DIEs will also be skipped. */
5356 static const gdb_byte
*
5357 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
5361 unsigned int bytes_read
;
5362 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
5366 return info_ptr
+ bytes_read
;
5368 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5372 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5373 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5374 abbrev corresponding to that skipped uleb128 should be passed in
5377 If DO_SKIP_CHILDREN is true, or if the DIE has no children, this
5378 returns a pointer to this DIE's sibling, skipping any children.
5379 Otherwise, returns a pointer to the DIE's first child. */
5381 static const gdb_byte
*
5382 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
5383 const struct abbrev_info
*abbrev
, bool do_skip_children
)
5385 unsigned int bytes_read
;
5386 struct attribute attr
;
5387 bfd
*abfd
= reader
->abfd
;
5388 struct dwarf2_cu
*cu
= reader
->cu
;
5389 const gdb_byte
*buffer
= reader
->buffer
;
5390 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5391 unsigned int form
, i
;
5393 if (do_skip_children
&& abbrev
->sibling_offset
!= (unsigned short) -1)
5395 /* We only handle DW_FORM_ref4 here. */
5396 const gdb_byte
*sibling_data
= info_ptr
+ abbrev
->sibling_offset
;
5397 unsigned int offset
= read_4_bytes (abfd
, sibling_data
);
5398 const gdb_byte
*sibling_ptr
5399 = buffer
+ to_underlying (cu
->header
.sect_off
) + offset
;
5400 if (sibling_ptr
>= info_ptr
&& sibling_ptr
< reader
->buffer_end
)
5402 /* Fall through to the slow way. */
5404 else if (abbrev
->size_if_constant
!= 0)
5406 info_ptr
+= abbrev
->size_if_constant
;
5407 if (do_skip_children
&& abbrev
->has_children
)
5408 return skip_children (reader
, info_ptr
);
5412 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5414 /* The only abbrev we care about is DW_AT_sibling. */
5415 if (do_skip_children
&& abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5417 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5418 if (attr
.form
== DW_FORM_ref_addr
)
5419 complaint (_("ignoring absolute DW_AT_sibling"));
5422 sect_offset off
= attr
.get_ref_die_offset ();
5423 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
5425 if (sibling_ptr
< info_ptr
)
5426 complaint (_("DW_AT_sibling points backwards"));
5427 else if (sibling_ptr
> reader
->buffer_end
)
5428 reader
->die_section
->overflow_complaint ();
5434 /* If it isn't DW_AT_sibling, skip this attribute. */
5435 form
= abbrev
->attrs
[i
].form
;
5439 case DW_FORM_ref_addr
:
5440 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5441 and later it is offset sized. */
5442 if (cu
->header
.version
== 2)
5443 info_ptr
+= cu
->header
.addr_size
;
5445 info_ptr
+= cu
->header
.offset_size
;
5447 case DW_FORM_GNU_ref_alt
:
5448 info_ptr
+= cu
->header
.offset_size
;
5451 info_ptr
+= cu
->header
.addr_size
;
5459 case DW_FORM_flag_present
:
5460 case DW_FORM_implicit_const
:
5477 case DW_FORM_ref_sig8
:
5480 case DW_FORM_data16
:
5483 case DW_FORM_string
:
5484 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5485 info_ptr
+= bytes_read
;
5487 case DW_FORM_sec_offset
:
5489 case DW_FORM_GNU_strp_alt
:
5490 info_ptr
+= cu
->header
.offset_size
;
5492 case DW_FORM_exprloc
:
5494 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5495 info_ptr
+= bytes_read
;
5497 case DW_FORM_block1
:
5498 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5500 case DW_FORM_block2
:
5501 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5503 case DW_FORM_block4
:
5504 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5510 case DW_FORM_ref_udata
:
5511 case DW_FORM_GNU_addr_index
:
5512 case DW_FORM_GNU_str_index
:
5513 case DW_FORM_rnglistx
:
5514 case DW_FORM_loclistx
:
5515 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
5517 case DW_FORM_indirect
:
5518 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5519 info_ptr
+= bytes_read
;
5520 /* We need to continue parsing from here, so just go back to
5522 goto skip_attribute
;
5525 error (_("Dwarf Error: Cannot handle %s "
5526 "in DWARF reader [in module %s]"),
5527 dwarf_form_name (form
),
5528 bfd_get_filename (abfd
));
5532 if (do_skip_children
&& abbrev
->has_children
)
5533 return skip_children (reader
, info_ptr
);
5538 /* Reading in full CUs. */
5540 /* Add PER_CU to the queue. */
5543 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
5544 dwarf2_per_objfile
*per_objfile
,
5545 enum language pretend_language
)
5549 gdb_assert (per_objfile
->queue
.has_value ());
5550 per_objfile
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
5553 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
5555 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
5558 Return true if maybe_queue_comp_unit requires the caller to load the CU's
5559 DIEs, false otherwise.
5561 Explanation: there is an invariant that if a CU is queued for expansion
5562 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
5563 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
5564 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
5565 are not yet loaded, the the caller must load the CU's DIEs to ensure the
5566 invariant is respected.
5568 The caller is therefore not required to load the CU's DIEs (we return false)
5571 - the CU is already expanded, and therefore does not get enqueued
5572 - the CU gets enqueued for expansion, but its DIEs are already loaded
5574 Note that the caller should not use this function's return value as an
5575 indicator of whether the CU's DIEs are loaded right now, it should check
5576 that by calling `dwarf2_per_objfile::get_cu` instead. */
5579 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
5580 dwarf2_per_cu_data
*per_cu
,
5581 dwarf2_per_objfile
*per_objfile
,
5582 enum language pretend_language
)
5584 /* Mark the dependence relation so that we don't flush PER_CU
5586 if (dependent_cu
!= NULL
)
5587 dependent_cu
->add_dependence (per_cu
);
5589 /* If it's already on the queue, we have nothing to do. */
5592 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
5594 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
5596 /* If the CU is queued for expansion, it should not already be
5598 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
5600 /* The DIEs are already loaded, the caller doesn't need to do it. */
5604 bool queued
= false;
5605 if (!per_objfile
->symtab_set_p (per_cu
))
5607 /* Add it to the queue. */
5608 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
5612 /* If the compilation unit is already loaded, just mark it as
5614 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
5618 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
5619 and the DIEs are not already loaded. */
5620 return queued
&& cu
== nullptr;
5623 /* Process the queue. */
5626 process_queue (dwarf2_per_objfile
*per_objfile
)
5628 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
5629 objfile_name (per_objfile
->objfile
));
5631 /* The queue starts out with one item, but following a DIE reference
5632 may load a new CU, adding it to the end of the queue. */
5633 while (!per_objfile
->queue
->empty ())
5635 dwarf2_queue_item
&item
= per_objfile
->queue
->front ();
5636 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
5638 if (!per_objfile
->symtab_set_p (per_cu
))
5640 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
5642 /* Skip dummy CUs. */
5645 unsigned int debug_print_threshold
;
5648 if (per_cu
->is_debug_types
)
5650 struct signatured_type
*sig_type
=
5651 (struct signatured_type
*) per_cu
;
5653 sprintf (buf
, "TU %s at offset %s",
5654 hex_string (sig_type
->signature
),
5655 sect_offset_str (per_cu
->sect_off
));
5656 /* There can be 100s of TUs.
5657 Only print them in verbose mode. */
5658 debug_print_threshold
= 2;
5662 sprintf (buf
, "CU at offset %s",
5663 sect_offset_str (per_cu
->sect_off
));
5664 debug_print_threshold
= 1;
5667 if (dwarf_read_debug
>= debug_print_threshold
)
5668 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
5670 if (per_cu
->is_debug_types
)
5671 process_full_type_unit (cu
, item
.pretend_language
);
5673 process_full_comp_unit (cu
, item
.pretend_language
);
5675 if (dwarf_read_debug
>= debug_print_threshold
)
5676 dwarf_read_debug_printf ("Done expanding %s", buf
);
5681 per_objfile
->queue
->pop ();
5684 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
5685 objfile_name (per_objfile
->objfile
));
5688 /* Load the DIEs associated with PER_CU into memory.
5690 In some cases, the caller, while reading partial symbols, will need to load
5691 the full symbols for the CU for some reason. It will already have a
5692 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
5693 rather than creating a new one. */
5696 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
5697 dwarf2_per_objfile
*per_objfile
,
5698 dwarf2_cu
*existing_cu
,
5700 enum language pretend_language
)
5702 gdb_assert (! this_cu
->is_debug_types
);
5704 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
5708 struct dwarf2_cu
*cu
= reader
.cu
;
5709 const gdb_byte
*info_ptr
= reader
.info_ptr
;
5711 gdb_assert (cu
->die_hash
== NULL
);
5713 htab_create_alloc_ex (cu
->header
.get_length_without_initial () / 12,
5717 &cu
->comp_unit_obstack
,
5718 hashtab_obstack_allocate
,
5719 dummy_obstack_deallocate
);
5721 if (reader
.comp_unit_die
->has_children
)
5722 reader
.comp_unit_die
->child
5723 = read_die_and_siblings (&reader
, reader
.info_ptr
,
5724 &info_ptr
, reader
.comp_unit_die
);
5725 cu
->dies
= reader
.comp_unit_die
;
5726 /* comp_unit_die is not stored in die_hash, no need. */
5728 /* We try not to read any attributes in this function, because not
5729 all CUs needed for references have been loaded yet, and symbol
5730 table processing isn't initialized. But we have to set the CU language,
5731 or we won't be able to build types correctly.
5732 Similarly, if we do not read the producer, we can not apply
5733 producer-specific interpretation. */
5734 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
5739 /* Add a DIE to the delayed physname list. */
5742 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5743 const char *name
, struct die_info
*die
,
5744 struct dwarf2_cu
*cu
)
5746 struct delayed_method_info mi
;
5748 mi
.fnfield_index
= fnfield_index
;
5752 cu
->method_list
.push_back (mi
);
5755 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
5756 "const" / "volatile". If so, decrements LEN by the length of the
5757 modifier and return true. Otherwise return false. */
5761 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
5763 size_t mod_len
= sizeof (mod
) - 1;
5764 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
5772 /* Compute the physnames of any methods on the CU's method list.
5774 The computation of method physnames is delayed in order to avoid the
5775 (bad) condition that one of the method's formal parameters is of an as yet
5779 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5781 /* Only C++ delays computing physnames. */
5782 if (cu
->method_list
.empty ())
5784 gdb_assert (cu
->lang () == language_cplus
);
5786 for (const delayed_method_info
&mi
: cu
->method_list
)
5788 const char *physname
;
5789 struct fn_fieldlist
*fn_flp
5790 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
5791 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
5792 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
5793 = physname
? physname
: "";
5795 /* Since there's no tag to indicate whether a method is a
5796 const/volatile overload, extract that information out of the
5798 if (physname
!= NULL
)
5800 size_t len
= strlen (physname
);
5804 if (physname
[len
] == ')') /* shortcut */
5806 else if (check_modifier (physname
, len
, " const"))
5807 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
5808 else if (check_modifier (physname
, len
, " volatile"))
5809 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
5816 /* The list is no longer needed. */
5817 cu
->method_list
.clear ();
5820 /* Go objects should be embedded in a DW_TAG_module DIE,
5821 and it's not clear if/how imported objects will appear.
5822 To keep Go support simple until that's worked out,
5823 go back through what we've read and create something usable.
5824 We could do this while processing each DIE, and feels kinda cleaner,
5825 but that way is more invasive.
5826 This is to, for example, allow the user to type "p var" or "b main"
5827 without having to specify the package name, and allow lookups
5828 of module.object to work in contexts that use the expression
5832 fixup_go_packaging (struct dwarf2_cu
*cu
)
5834 gdb::unique_xmalloc_ptr
<char> package_name
;
5835 struct pending
*list
;
5838 for (list
= *cu
->get_builder ()->get_global_symbols ();
5842 for (i
= 0; i
< list
->nsyms
; ++i
)
5844 struct symbol
*sym
= list
->symbol
[i
];
5846 if (sym
->language () == language_go
5847 && sym
->aclass () == LOC_BLOCK
)
5849 gdb::unique_xmalloc_ptr
<char> this_package_name
5850 = go_symbol_package_name (sym
);
5852 if (this_package_name
== NULL
)
5854 if (package_name
== NULL
)
5855 package_name
= std::move (this_package_name
);
5858 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
5859 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
5860 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
5861 (sym
->symtab () != NULL
5862 ? symtab_to_filename_for_display
5864 : objfile_name (objfile
)),
5865 this_package_name
.get (), package_name
.get ());
5871 if (package_name
!= NULL
)
5873 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
5874 const char *saved_package_name
= objfile
->intern (package_name
.get ());
5875 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
5876 saved_package_name
);
5879 sym
= new (&objfile
->objfile_obstack
) symbol
;
5880 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
5881 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
5882 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5883 e.g., "main" finds the "main" module and not C's main(). */
5884 sym
->set_domain (STRUCT_DOMAIN
);
5885 sym
->set_aclass_index (LOC_TYPEDEF
);
5886 sym
->set_type (type
);
5888 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
5892 /* Allocate a fully-qualified name consisting of the two parts on the
5896 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
5898 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
5901 /* A helper that allocates a variant part to attach to a Rust enum
5902 type. OBSTACK is where the results should be allocated. TYPE is
5903 the type we're processing. DISCRIMINANT_INDEX is the index of the
5904 discriminant. It must be the index of one of the fields of TYPE,
5905 or -1 to mean there is no discriminant (univariant enum).
5906 DEFAULT_INDEX is the index of the default field; or -1 if there is
5907 no default. RANGES is indexed by "effective" field number (the
5908 field index, but omitting the discriminant and default fields) and
5909 must hold the discriminant values used by the variants. Note that
5910 RANGES must have a lifetime at least as long as OBSTACK -- either
5911 already allocated on it, or static. */
5914 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
5915 int discriminant_index
, int default_index
,
5916 gdb::array_view
<discriminant_range
> ranges
)
5918 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
5919 gdb_assert (discriminant_index
== -1
5920 || (discriminant_index
>= 0
5921 && discriminant_index
< type
->num_fields ()));
5922 gdb_assert (default_index
== -1
5923 || (default_index
>= 0 && default_index
< type
->num_fields ()));
5925 /* We have one variant for each non-discriminant field. */
5926 int n_variants
= type
->num_fields ();
5927 if (discriminant_index
!= -1)
5930 variant
*variants
= new (obstack
) variant
[n_variants
];
5933 for (int i
= 0; i
< type
->num_fields (); ++i
)
5935 if (i
== discriminant_index
)
5938 variants
[var_idx
].first_field
= i
;
5939 variants
[var_idx
].last_field
= i
+ 1;
5941 /* The default field does not need a range, but other fields do.
5942 We skipped the discriminant above. */
5943 if (i
!= default_index
)
5945 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
5952 gdb_assert (range_idx
== ranges
.size ());
5953 gdb_assert (var_idx
== n_variants
);
5955 variant_part
*part
= new (obstack
) variant_part
;
5956 part
->discriminant_index
= discriminant_index
;
5957 /* If there is no discriminant, then whether it is signed is of no
5960 = (discriminant_index
== -1
5962 : type
->field (discriminant_index
).type ()->is_unsigned ());
5963 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
5965 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
5966 gdb::array_view
<variant_part
> *prop_value
5967 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
5969 struct dynamic_prop prop
;
5970 prop
.set_variant_parts (prop_value
);
5972 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
5975 /* Some versions of rustc emitted enums in an unusual way.
5977 Ordinary enums were emitted as unions. The first element of each
5978 structure in the union was named "RUST$ENUM$DISR". This element
5979 held the discriminant.
5981 These versions of Rust also implemented the "non-zero"
5982 optimization. When the enum had two values, and one is empty and
5983 the other holds a pointer that cannot be zero, the pointer is used
5984 as the discriminant, with a zero value meaning the empty variant.
5985 Here, the union's first member is of the form
5986 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
5987 where the fieldnos are the indices of the fields that should be
5988 traversed in order to find the field (which may be several fields deep)
5989 and the variantname is the name of the variant of the case when the
5992 This function recognizes whether TYPE is of one of these forms,
5993 and, if so, smashes it to be a variant type. */
5996 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
5998 gdb_assert (type
->code () == TYPE_CODE_UNION
);
6000 /* We don't need to deal with empty enums. */
6001 if (type
->num_fields () == 0)
6004 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
6005 if (type
->num_fields () == 1
6006 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
6008 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
6010 /* Decode the field name to find the offset of the
6012 ULONGEST bit_offset
= 0;
6013 struct type
*field_type
= type
->field (0).type ();
6014 while (name
[0] >= '0' && name
[0] <= '9')
6017 unsigned long index
= strtoul (name
, &tail
, 10);
6020 || index
>= field_type
->num_fields ()
6021 || (field_type
->field (index
).loc_kind ()
6022 != FIELD_LOC_KIND_BITPOS
))
6024 complaint (_("Could not parse Rust enum encoding string \"%s\""
6026 type
->field (0).name (),
6027 objfile_name (objfile
));
6032 bit_offset
+= field_type
->field (index
).loc_bitpos ();
6033 field_type
= field_type
->field (index
).type ();
6036 /* Smash this type to be a structure type. We have to do this
6037 because the type has already been recorded. */
6038 type
->set_code (TYPE_CODE_STRUCT
);
6039 type
->set_num_fields (3);
6040 /* Save the field we care about. */
6041 struct field saved_field
= type
->field (0);
6043 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
6045 /* Put the discriminant at index 0. */
6046 type
->field (0).set_type (field_type
);
6047 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
6048 type
->field (0).set_name ("<<discriminant>>");
6049 type
->field (0).set_loc_bitpos (bit_offset
);
6051 /* The order of fields doesn't really matter, so put the real
6052 field at index 1 and the data-less field at index 2. */
6053 type
->field (1) = saved_field
;
6054 type
->field (1).set_name
6055 (rust_last_path_segment (type
->field (1).type ()->name ()));
6056 type
->field (1).type ()->set_name
6057 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
6058 type
->field (1).name ()));
6060 const char *dataless_name
6061 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
6063 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
6065 type
->field (2).set_type (dataless_type
);
6066 /* NAME points into the original discriminant name, which
6067 already has the correct lifetime. */
6068 type
->field (2).set_name (name
);
6069 type
->field (2).set_loc_bitpos (0);
6071 /* Indicate that this is a variant type. */
6072 static discriminant_range ranges
[1] = { { 0, 0 } };
6073 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
6075 /* A union with a single anonymous field is probably an old-style
6077 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
6079 /* Smash this type to be a structure type. We have to do this
6080 because the type has already been recorded. */
6081 type
->set_code (TYPE_CODE_STRUCT
);
6083 struct type
*field_type
= type
->field (0).type ();
6084 const char *variant_name
6085 = rust_last_path_segment (field_type
->name ());
6086 type
->field (0).set_name (variant_name
);
6087 field_type
->set_name
6088 (rust_fully_qualify (&objfile
->objfile_obstack
,
6089 type
->name (), variant_name
));
6091 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
6095 struct type
*disr_type
= nullptr;
6096 for (int i
= 0; i
< type
->num_fields (); ++i
)
6098 disr_type
= type
->field (i
).type ();
6100 if (disr_type
->code () != TYPE_CODE_STRUCT
)
6102 /* All fields of a true enum will be structs. */
6105 else if (disr_type
->num_fields () == 0)
6107 /* Could be data-less variant, so keep going. */
6108 disr_type
= nullptr;
6110 else if (strcmp (disr_type
->field (0).name (),
6111 "RUST$ENUM$DISR") != 0)
6113 /* Not a Rust enum. */
6123 /* If we got here without a discriminant, then it's probably
6125 if (disr_type
== nullptr)
6128 /* Smash this type to be a structure type. We have to do this
6129 because the type has already been recorded. */
6130 type
->set_code (TYPE_CODE_STRUCT
);
6132 /* Make space for the discriminant field. */
6133 struct field
*disr_field
= &disr_type
->field (0);
6135 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
6136 * sizeof (struct field
)));
6137 memcpy (new_fields
+ 1, type
->fields (),
6138 type
->num_fields () * sizeof (struct field
));
6139 type
->set_fields (new_fields
);
6140 type
->set_num_fields (type
->num_fields () + 1);
6142 /* Install the discriminant at index 0 in the union. */
6143 type
->field (0) = *disr_field
;
6144 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
6145 type
->field (0).set_name ("<<discriminant>>");
6147 /* We need a way to find the correct discriminant given a
6148 variant name. For convenience we build a map here. */
6149 struct type
*enum_type
= disr_field
->type ();
6150 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
6151 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
6153 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
6156 = rust_last_path_segment (enum_type
->field (i
).name ());
6157 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
6161 int n_fields
= type
->num_fields ();
6162 /* We don't need a range entry for the discriminant, but we do
6163 need one for every other field, as there is no default
6165 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
6168 /* Skip the discriminant here. */
6169 for (int i
= 1; i
< n_fields
; ++i
)
6171 /* Find the final word in the name of this variant's type.
6172 That name can be used to look up the correct
6174 const char *variant_name
6175 = rust_last_path_segment (type
->field (i
).type ()->name ());
6177 auto iter
= discriminant_map
.find (variant_name
);
6178 if (iter
!= discriminant_map
.end ())
6180 ranges
[i
- 1].low
= iter
->second
;
6181 ranges
[i
- 1].high
= iter
->second
;
6184 /* In Rust, each element should have the size of the
6186 type
->field (i
).type ()->set_length (type
->length ());
6188 /* Remove the discriminant field, if it exists. */
6189 struct type
*sub_type
= type
->field (i
).type ();
6190 if (sub_type
->num_fields () > 0)
6192 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
6193 sub_type
->set_fields (sub_type
->fields () + 1);
6195 type
->field (i
).set_name (variant_name
);
6197 (rust_fully_qualify (&objfile
->objfile_obstack
,
6198 type
->name (), variant_name
));
6201 /* Indicate that this is a variant type. */
6202 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
6203 gdb::array_view
<discriminant_range
> (ranges
,
6208 /* Rewrite some Rust unions to be structures with variants parts. */
6211 rust_union_quirks (struct dwarf2_cu
*cu
)
6213 gdb_assert (cu
->lang () == language_rust
);
6214 for (type
*type_
: cu
->rust_unions
)
6215 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
6216 /* We don't need this any more. */
6217 cu
->rust_unions
.clear ();
6222 type_unit_group_unshareable
*
6223 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
6225 auto iter
= this->m_type_units
.find (tu_group
);
6226 if (iter
!= this->m_type_units
.end ())
6227 return iter
->second
.get ();
6229 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
6230 type_unit_group_unshareable
*result
= uniq
.get ();
6231 this->m_type_units
[tu_group
] = std::move (uniq
);
6236 dwarf2_per_objfile::get_type_for_signatured_type
6237 (signatured_type
*sig_type
) const
6239 auto iter
= this->m_type_map
.find (sig_type
);
6240 if (iter
== this->m_type_map
.end ())
6243 return iter
->second
;
6246 void dwarf2_per_objfile::set_type_for_signatured_type
6247 (signatured_type
*sig_type
, struct type
*type
)
6249 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
6251 this->m_type_map
[sig_type
] = type
;
6254 /* A helper function for computing the list of all symbol tables
6255 included by PER_CU. */
6258 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
6259 htab_t all_children
, htab_t all_type_symtabs
,
6260 dwarf2_per_cu_data
*per_cu
,
6261 dwarf2_per_objfile
*per_objfile
,
6262 struct compunit_symtab
*immediate_parent
)
6264 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6267 /* This inclusion and its children have been processed. */
6273 /* Only add a CU if it has a symbol table. */
6274 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
6277 /* If this is a type unit only add its symbol table if we haven't
6278 seen it yet (type unit per_cu's can share symtabs). */
6279 if (per_cu
->is_debug_types
)
6281 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
6285 result
->push_back (cust
);
6286 if (cust
->user
== NULL
)
6287 cust
->user
= immediate_parent
;
6292 result
->push_back (cust
);
6293 if (cust
->user
== NULL
)
6294 cust
->user
= immediate_parent
;
6298 if (!per_cu
->imported_symtabs_empty ())
6299 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
6301 recursively_compute_inclusions (result
, all_children
,
6302 all_type_symtabs
, ptr
, per_objfile
,
6307 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
6311 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
6312 dwarf2_per_objfile
*per_objfile
)
6314 gdb_assert (! per_cu
->is_debug_types
);
6316 if (!per_cu
->imported_symtabs_empty ())
6319 std::vector
<compunit_symtab
*> result_symtabs
;
6320 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
6322 /* If we don't have a symtab, we can just skip this case. */
6326 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
6328 NULL
, xcalloc
, xfree
));
6329 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
6331 NULL
, xcalloc
, xfree
));
6333 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
6335 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
6336 all_type_symtabs
.get (), ptr
,
6340 /* Now we have a transitive closure of all the included symtabs. */
6341 len
= result_symtabs
.size ();
6343 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
6344 struct compunit_symtab
*, len
+ 1);
6345 memcpy (cust
->includes
, result_symtabs
.data (),
6346 len
* sizeof (compunit_symtab
*));
6347 cust
->includes
[len
] = NULL
;
6351 /* Compute the 'includes' field for the symtabs of all the CUs we just
6355 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
6357 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
6359 if (! iter
->is_debug_types
)
6360 compute_compunit_symtab_includes (iter
, per_objfile
);
6363 per_objfile
->per_bfd
->just_read_cus
.clear ();
6366 /* Generate full symbol information for CU, whose DIEs have
6367 already been loaded into memory. */
6370 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
6372 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6373 struct objfile
*objfile
= per_objfile
->objfile
;
6374 struct gdbarch
*gdbarch
= objfile
->arch ();
6375 CORE_ADDR lowpc
, highpc
;
6376 struct compunit_symtab
*cust
;
6378 struct block
*static_block
;
6381 baseaddr
= objfile
->text_section_offset ();
6383 /* Clear the list here in case something was left over. */
6384 cu
->method_list
.clear ();
6386 dwarf2_find_base_address (cu
->dies
, cu
);
6388 /* Before we start reading the top-level DIE, ensure it has a valid tag
6390 switch (cu
->dies
->tag
)
6392 case DW_TAG_compile_unit
:
6393 case DW_TAG_partial_unit
:
6394 case DW_TAG_type_unit
:
6397 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
6398 dwarf_tag_name (cu
->dies
->tag
),
6399 sect_offset_str (cu
->per_cu
->sect_off
),
6400 objfile_name (per_objfile
->objfile
));
6403 /* Do line number decoding in read_file_scope () */
6404 process_die (cu
->dies
, cu
);
6406 /* For now fudge the Go package. */
6407 if (cu
->lang () == language_go
)
6408 fixup_go_packaging (cu
);
6410 /* Now that we have processed all the DIEs in the CU, all the types
6411 should be complete, and it should now be safe to compute all of the
6413 compute_delayed_physnames (cu
);
6415 if (cu
->lang () == language_rust
)
6416 rust_union_quirks (cu
);
6418 /* Some compilers don't define a DW_AT_high_pc attribute for the
6419 compilation unit. If the DW_AT_high_pc is missing, synthesize
6420 it, by scanning the DIE's below the compilation unit. */
6421 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6423 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
6425 = cu
->get_builder ()->end_compunit_symtab_get_static_block (addr
, 0, 1);
6427 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6428 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6429 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6430 addrmap to help ensure it has an accurate map of pc values belonging to
6432 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6434 cust
= cu
->get_builder ()->end_compunit_symtab_from_static_block
6439 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6441 /* Set symtab language to language from DW_AT_language. If the
6442 compilation is from a C file generated by language preprocessors, do
6443 not set the language if it was already deduced by start_subfile. */
6444 if (!(cu
->lang () == language_c
6445 && cust
->primary_filetab ()->language () != language_unknown
))
6446 cust
->primary_filetab ()->set_language (cu
->lang ());
6448 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6449 produce DW_AT_location with location lists but it can be possibly
6450 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6451 there were bugs in prologue debug info, fixed later in GCC-4.5
6452 by "unwind info for epilogues" patch (which is not directly related).
6454 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6455 needed, it would be wrong due to missing DW_AT_producer there.
6457 Still one can confuse GDB by using non-standard GCC compilation
6458 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6460 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6461 cust
->set_locations_valid (true);
6463 if (gcc_4_minor
>= 5)
6464 cust
->set_epilogue_unwind_valid (true);
6466 cust
->set_call_site_htab (cu
->call_site_htab
);
6469 per_objfile
->set_symtab (cu
->per_cu
, cust
);
6471 /* Push it for inclusion processing later. */
6472 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
6474 /* Not needed any more. */
6475 cu
->reset_builder ();
6478 /* Generate full symbol information for type unit CU, whose DIEs have
6479 already been loaded into memory. */
6482 process_full_type_unit (dwarf2_cu
*cu
,
6483 enum language pretend_language
)
6485 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6486 struct compunit_symtab
*cust
;
6487 struct signatured_type
*sig_type
;
6489 gdb_assert (cu
->per_cu
->is_debug_types
);
6490 sig_type
= (struct signatured_type
*) cu
->per_cu
;
6492 /* Clear the list here in case something was left over. */
6493 cu
->method_list
.clear ();
6495 /* The symbol tables are set up in read_type_unit_scope. */
6496 process_die (cu
->dies
, cu
);
6498 /* For now fudge the Go package. */
6499 if (cu
->lang () == language_go
)
6500 fixup_go_packaging (cu
);
6502 /* Now that we have processed all the DIEs in the CU, all the types
6503 should be complete, and it should now be safe to compute all of the
6505 compute_delayed_physnames (cu
);
6507 if (cu
->lang () == language_rust
)
6508 rust_union_quirks (cu
);
6510 /* TUs share symbol tables.
6511 If this is the first TU to use this symtab, complete the construction
6512 of it with end_expandable_symtab. Otherwise, complete the addition of
6513 this TU's symbols to the existing symtab. */
6514 type_unit_group_unshareable
*tug_unshare
=
6515 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
6516 if (tug_unshare
->compunit_symtab
== NULL
)
6518 buildsym_compunit
*builder
= cu
->get_builder ();
6519 cust
= builder
->end_expandable_symtab (0);
6520 tug_unshare
->compunit_symtab
= cust
;
6524 /* Set symtab language to language from DW_AT_language. If the
6525 compilation is from a C file generated by language preprocessors,
6526 do not set the language if it was already deduced by
6528 if (!(cu
->lang () == language_c
6529 && cust
->primary_filetab ()->language () != language_c
))
6530 cust
->primary_filetab ()->set_language (cu
->lang ());
6535 cu
->get_builder ()->augment_type_symtab ();
6536 cust
= tug_unshare
->compunit_symtab
;
6539 per_objfile
->set_symtab (cu
->per_cu
, cust
);
6541 /* Not needed any more. */
6542 cu
->reset_builder ();
6545 /* Process an imported unit DIE. */
6548 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6550 struct attribute
*attr
;
6552 /* For now we don't handle imported units in type units. */
6553 if (cu
->per_cu
->is_debug_types
)
6555 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6556 " supported in type units [in module %s]"),
6557 objfile_name (cu
->per_objfile
->objfile
));
6560 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6563 sect_offset sect_off
= attr
->get_ref_die_offset ();
6564 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
6565 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6566 dwarf2_per_cu_data
*per_cu
6567 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
6568 per_objfile
->per_bfd
);
6570 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
6571 into another compilation unit, at root level. Regard this as a hint,
6572 and ignore it. This is a best effort, it only works if unit_type and
6573 lang are already set. */
6574 if (die
->parent
&& die
->parent
->parent
== NULL
6575 && per_cu
->unit_type (false) == DW_UT_compile
6576 && per_cu
->lang (false) == language_cplus
)
6579 /* If necessary, add it to the queue and load its DIEs. */
6580 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
6582 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
6583 false, cu
->lang ());
6585 cu
->per_cu
->imported_symtabs_push (per_cu
);
6589 /* RAII object that represents a process_die scope: i.e.,
6590 starts/finishes processing a DIE. */
6591 class process_die_scope
6594 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
6595 : m_die (die
), m_cu (cu
)
6597 /* We should only be processing DIEs not already in process. */
6598 gdb_assert (!m_die
->in_process
);
6599 m_die
->in_process
= true;
6602 ~process_die_scope ()
6604 m_die
->in_process
= false;
6606 /* If we're done processing the DIE for the CU that owns the line
6607 header, we don't need the line header anymore. */
6608 if (m_cu
->line_header_die_owner
== m_die
)
6610 delete m_cu
->line_header
;
6611 m_cu
->line_header
= NULL
;
6612 m_cu
->line_header_die_owner
= NULL
;
6621 /* Process a die and its children. */
6624 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6626 process_die_scope
scope (die
, cu
);
6630 case DW_TAG_padding
:
6632 case DW_TAG_compile_unit
:
6633 case DW_TAG_partial_unit
:
6634 read_file_scope (die
, cu
);
6636 case DW_TAG_type_unit
:
6637 read_type_unit_scope (die
, cu
);
6639 case DW_TAG_subprogram
:
6640 /* Nested subprograms in Fortran get a prefix. */
6641 if (cu
->lang () == language_fortran
6642 && die
->parent
!= NULL
6643 && die
->parent
->tag
== DW_TAG_subprogram
)
6644 cu
->processing_has_namespace_info
= true;
6646 case DW_TAG_inlined_subroutine
:
6647 read_func_scope (die
, cu
);
6649 case DW_TAG_lexical_block
:
6650 case DW_TAG_try_block
:
6651 case DW_TAG_catch_block
:
6652 read_lexical_block_scope (die
, cu
);
6654 case DW_TAG_call_site
:
6655 case DW_TAG_GNU_call_site
:
6656 read_call_site_scope (die
, cu
);
6658 case DW_TAG_class_type
:
6659 case DW_TAG_interface_type
:
6660 case DW_TAG_structure_type
:
6661 case DW_TAG_union_type
:
6662 case DW_TAG_namelist
:
6663 process_structure_scope (die
, cu
);
6665 case DW_TAG_enumeration_type
:
6666 process_enumeration_scope (die
, cu
);
6669 /* These dies have a type, but processing them does not create
6670 a symbol or recurse to process the children. Therefore we can
6671 read them on-demand through read_type_die. */
6672 case DW_TAG_subroutine_type
:
6673 case DW_TAG_set_type
:
6674 case DW_TAG_pointer_type
:
6675 case DW_TAG_ptr_to_member_type
:
6676 case DW_TAG_reference_type
:
6677 case DW_TAG_rvalue_reference_type
:
6678 case DW_TAG_string_type
:
6681 case DW_TAG_array_type
:
6682 /* We only need to handle this case for Ada -- in other
6683 languages, it's normal for the compiler to emit a typedef
6685 if (cu
->lang () != language_ada
)
6688 case DW_TAG_base_type
:
6689 case DW_TAG_subrange_type
:
6690 case DW_TAG_generic_subrange
:
6691 case DW_TAG_typedef
:
6692 /* Add a typedef symbol for the type definition, if it has a
6694 new_symbol (die
, read_type_die (die
, cu
), cu
);
6696 case DW_TAG_common_block
:
6697 read_common_block (die
, cu
);
6699 case DW_TAG_common_inclusion
:
6701 case DW_TAG_namespace
:
6702 cu
->processing_has_namespace_info
= true;
6703 read_namespace (die
, cu
);
6706 cu
->processing_has_namespace_info
= true;
6707 read_module (die
, cu
);
6709 case DW_TAG_imported_declaration
:
6710 cu
->processing_has_namespace_info
= true;
6711 if (read_alias (die
, cu
))
6713 /* The declaration is neither a global namespace nor a variable
6716 case DW_TAG_imported_module
:
6717 cu
->processing_has_namespace_info
= true;
6718 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6719 || cu
->lang () != language_fortran
))
6720 complaint (_("Tag '%s' has unexpected children"),
6721 dwarf_tag_name (die
->tag
));
6722 read_import_statement (die
, cu
);
6725 case DW_TAG_imported_unit
:
6726 process_imported_unit_die (die
, cu
);
6729 case DW_TAG_variable
:
6730 read_variable (die
, cu
);
6734 new_symbol (die
, NULL
, cu
);
6739 /* DWARF name computation. */
6741 /* A helper function for dwarf2_compute_name which determines whether DIE
6742 needs to have the name of the scope prepended to the name listed in the
6746 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6748 struct attribute
*attr
;
6752 case DW_TAG_namespace
:
6753 case DW_TAG_typedef
:
6754 case DW_TAG_class_type
:
6755 case DW_TAG_interface_type
:
6756 case DW_TAG_structure_type
:
6757 case DW_TAG_union_type
:
6758 case DW_TAG_enumeration_type
:
6759 case DW_TAG_enumerator
:
6760 case DW_TAG_subprogram
:
6761 case DW_TAG_inlined_subroutine
:
6763 case DW_TAG_imported_declaration
:
6766 case DW_TAG_variable
:
6767 case DW_TAG_constant
:
6768 /* We only need to prefix "globally" visible variables. These include
6769 any variable marked with DW_AT_external or any variable that
6770 lives in a namespace. [Variables in anonymous namespaces
6771 require prefixing, but they are not DW_AT_external.] */
6773 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6775 struct dwarf2_cu
*spec_cu
= cu
;
6777 return die_needs_namespace (die_specification (die
, &spec_cu
),
6781 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6782 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6783 && die
->parent
->tag
!= DW_TAG_module
)
6785 /* A variable in a lexical block of some kind does not need a
6786 namespace, even though in C++ such variables may be external
6787 and have a mangled name. */
6788 if (die
->parent
->tag
== DW_TAG_lexical_block
6789 || die
->parent
->tag
== DW_TAG_try_block
6790 || die
->parent
->tag
== DW_TAG_catch_block
6791 || die
->parent
->tag
== DW_TAG_subprogram
)
6800 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
6801 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
6802 defined for the given DIE. */
6804 static struct attribute
*
6805 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
6807 struct attribute
*attr
;
6809 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6811 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6816 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
6817 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
6818 defined for the given DIE. */
6821 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
6823 const char *linkage_name
;
6825 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
6826 if (linkage_name
== NULL
)
6827 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6829 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
6830 See https://github.com/rust-lang/rust/issues/32925. */
6831 if (cu
->lang () == language_rust
&& linkage_name
!= NULL
6832 && strchr (linkage_name
, '{') != NULL
)
6833 linkage_name
= NULL
;
6835 return linkage_name
;
6838 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6839 compute the physname for the object, which include a method's:
6840 - formal parameters (C++),
6841 - receiver type (Go),
6843 The term "physname" is a bit confusing.
6844 For C++, for example, it is the demangled name.
6845 For Go, for example, it's the mangled name.
6847 For Ada, return the DIE's linkage name rather than the fully qualified
6848 name. PHYSNAME is ignored..
6850 The result is allocated on the objfile->per_bfd's obstack and
6854 dwarf2_compute_name (const char *name
,
6855 struct die_info
*die
, struct dwarf2_cu
*cu
,
6858 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
6861 name
= dwarf2_name (die
, cu
);
6863 enum language lang
= cu
->lang ();
6865 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
6866 but otherwise compute it by typename_concat inside GDB.
6867 FIXME: Actually this is not really true, or at least not always true.
6868 It's all very confusing. compute_and_set_names doesn't try to demangle
6869 Fortran names because there is no mangling standard. So new_symbol
6870 will set the demangled name to the result of dwarf2_full_name, and it is
6871 the demangled name that GDB uses if it exists. */
6872 if (lang
== language_ada
6873 || (lang
== language_fortran
&& physname
))
6875 /* For Ada unit, we prefer the linkage name over the name, as
6876 the former contains the exported name, which the user expects
6877 to be able to reference. Ideally, we want the user to be able
6878 to reference this entity using either natural or linkage name,
6879 but we haven't started looking at this enhancement yet. */
6880 const char *linkage_name
= dw2_linkage_name (die
, cu
);
6882 if (linkage_name
!= NULL
)
6883 return linkage_name
;
6886 /* These are the only languages we know how to qualify names in. */
6888 && (lang
== language_cplus
6889 || lang
== language_fortran
|| lang
== language_d
6890 || lang
== language_rust
))
6892 if (die_needs_namespace (die
, cu
))
6898 prefix
= determine_prefix (die
, cu
);
6899 if (*prefix
!= '\0')
6901 gdb::unique_xmalloc_ptr
<char> prefixed_name
6902 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
6904 buf
.puts (prefixed_name
.get ());
6909 /* Template parameters may be specified in the DIE's DW_AT_name, or
6910 as children with DW_TAG_template_type_param or
6911 DW_TAG_value_type_param. If the latter, add them to the name
6912 here. If the name already has template parameters, then
6913 skip this step; some versions of GCC emit both, and
6914 it is more efficient to use the pre-computed name.
6916 Something to keep in mind about this process: it is very
6917 unlikely, or in some cases downright impossible, to produce
6918 something that will match the mangled name of a function.
6919 If the definition of the function has the same debug info,
6920 we should be able to match up with it anyway. But fallbacks
6921 using the minimal symbol, for instance to find a method
6922 implemented in a stripped copy of libstdc++, will not work.
6923 If we do not have debug info for the definition, we will have to
6924 match them up some other way.
6926 When we do name matching there is a related problem with function
6927 templates; two instantiated function templates are allowed to
6928 differ only by their return types, which we do not add here. */
6930 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
6932 struct attribute
*attr
;
6933 struct die_info
*child
;
6936 die
->building_fullname
= 1;
6938 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6942 const gdb_byte
*bytes
;
6943 struct dwarf2_locexpr_baton
*baton
;
6946 if (child
->tag
!= DW_TAG_template_type_param
6947 && child
->tag
!= DW_TAG_template_value_param
)
6958 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6961 complaint (_("template parameter missing DW_AT_type"));
6962 buf
.puts ("UNKNOWN_TYPE");
6965 type
= die_type (child
, cu
);
6967 if (child
->tag
== DW_TAG_template_type_param
)
6969 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
6970 &type_print_raw_options
);
6974 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6977 complaint (_("template parameter missing "
6978 "DW_AT_const_value"));
6979 buf
.puts ("UNKNOWN_VALUE");
6983 dwarf2_const_value_attr (attr
, type
, name
,
6984 &cu
->comp_unit_obstack
, cu
,
6985 &value
, &bytes
, &baton
);
6987 if (type
->has_no_signedness ())
6988 /* GDB prints characters as NUMBER 'CHAR'. If that's
6989 changed, this can use value_print instead. */
6990 cu
->language_defn
->printchar (value
, type
, &buf
);
6993 struct value_print_options opts
;
6996 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7000 baton
->per_objfile
);
7001 else if (bytes
!= NULL
)
7003 v
= value::allocate (type
);
7004 memcpy (v
->contents_writeable ().data (), bytes
,
7008 v
= value_from_longest (type
, value
);
7010 /* Specify decimal so that we do not depend on
7012 get_formatted_print_options (&opts
, 'd');
7014 value_print (v
, &buf
, &opts
);
7019 die
->building_fullname
= 0;
7023 /* Close the argument list, with a space if necessary
7024 (nested templates). */
7025 if (!buf
.empty () && buf
.string ().back () == '>')
7032 /* For C++ methods, append formal parameter type
7033 information, if PHYSNAME. */
7035 if (physname
&& die
->tag
== DW_TAG_subprogram
7036 && lang
== language_cplus
)
7038 struct type
*type
= read_type_die (die
, cu
);
7040 c_type_print_args (type
, &buf
, 1, lang
,
7041 &type_print_raw_options
);
7043 if (lang
== language_cplus
)
7045 /* Assume that an artificial first parameter is
7046 "this", but do not crash if it is not. RealView
7047 marks unnamed (and thus unused) parameters as
7048 artificial; there is no way to differentiate
7050 if (type
->num_fields () > 0
7051 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7052 && type
->field (0).type ()->code () == TYPE_CODE_PTR
7053 && TYPE_CONST (type
->field (0).type ()->target_type ()))
7054 buf
.puts (" const");
7058 const std::string
&intermediate_name
= buf
.string ();
7060 const char *canonical_name
7061 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
7064 /* If we only computed INTERMEDIATE_NAME, or if
7065 INTERMEDIATE_NAME is already canonical, then we need to
7067 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
7068 name
= objfile
->intern (intermediate_name
);
7070 name
= canonical_name
;
7077 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7078 If scope qualifiers are appropriate they will be added. The result
7079 will be allocated on the storage_obstack, or NULL if the DIE does
7080 not have a name. NAME may either be from a previous call to
7081 dwarf2_name or NULL.
7083 The output string will be canonicalized (if C++). */
7086 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7088 return dwarf2_compute_name (name
, die
, cu
, 0);
7091 /* Construct a physname for the given DIE in CU. NAME may either be
7092 from a previous call to dwarf2_name or NULL. The result will be
7093 allocated on the objfile_objstack or NULL if the DIE does not have a
7096 The output string will be canonicalized (if C++). */
7099 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7101 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
7102 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7105 /* In this case dwarf2_compute_name is just a shortcut not building anything
7107 if (!die_needs_namespace (die
, cu
))
7108 return dwarf2_compute_name (name
, die
, cu
, 1);
7110 if (cu
->lang () != language_rust
)
7111 mangled
= dw2_linkage_name (die
, cu
);
7113 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7115 gdb::unique_xmalloc_ptr
<char> demangled
;
7116 if (mangled
!= NULL
)
7118 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
7120 /* Do nothing (do not demangle the symbol name). */
7124 /* Use DMGL_RET_DROP for C++ template functions to suppress
7125 their return type. It is easier for GDB users to search
7126 for such functions as `name(params)' than `long name(params)'.
7127 In such case the minimal symbol names do not match the full
7128 symbol names but for template functions there is never a need
7129 to look up their definition from their declaration so
7130 the only disadvantage remains the minimal symbol variant
7131 `long name(params)' does not have the proper inferior type. */
7132 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
7136 canon
= demangled
.get ();
7144 if (canon
== NULL
|| check_physname
)
7146 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7148 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7150 /* It may not mean a bug in GDB. The compiler could also
7151 compute DW_AT_linkage_name incorrectly. But in such case
7152 GDB would need to be bug-to-bug compatible. */
7154 complaint (_("Computed physname <%s> does not match demangled <%s> "
7155 "(from linkage <%s>) - DIE at %s [in module %s]"),
7156 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
7157 objfile_name (objfile
));
7159 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7160 is available here - over computed PHYSNAME. It is safer
7161 against both buggy GDB and buggy compilers. */
7175 retval
= objfile
->intern (retval
);
7180 /* Inspect DIE in CU for a namespace alias or a variable with alias
7181 attribute. If one exists, record a new symbol for it.
7183 Returns true if an alias was recorded, false otherwise. */
7186 read_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
7188 struct attribute
*attr
;
7190 /* If the die does not have a name, this is neither a namespace
7191 alias nor a variable alias. */
7192 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7196 struct die_info
*d
= die
;
7197 struct dwarf2_cu
*imported_cu
= cu
;
7199 /* If the compiler has nested DW_AT_imported_declaration DIEs,
7200 keep inspecting DIEs until we hit the underlying import. */
7201 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
7202 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
7204 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
7208 d
= follow_die_ref (d
, attr
, &imported_cu
);
7209 if (d
->tag
!= DW_TAG_imported_declaration
)
7213 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
7215 complaint (_("DIE at %s has too many recursively imported "
7216 "declarations"), sect_offset_str (d
->sect_off
));
7223 if (d
->tag
== DW_TAG_variable
)
7225 /* This declaration is a C/C++ global variable alias.
7226 Add a symbol for it whose type is the same as the
7227 aliased variable's. */
7228 type
= die_type (d
, imported_cu
);
7229 struct symbol
*sym
= new_symbol (die
, type
, cu
);
7230 attr
= dwarf2_attr (d
, DW_AT_location
, imported_cu
);
7231 sym
->set_aclass_index (LOC_UNRESOLVED
);
7232 if (attr
!= nullptr)
7233 var_decode_location (attr
, sym
, cu
);
7238 sect_offset sect_off
= attr
->get_ref_die_offset ();
7239 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
,
7241 if (type
!= nullptr && type
->code () == TYPE_CODE_NAMESPACE
)
7243 /* This declaration is a global namespace alias. Add
7244 a symbol for it whose type is the aliased
7246 new_symbol (die
, type
, cu
);
7255 /* Return the using directives repository (global or local?) to use in the
7256 current context for CU.
7258 For Ada, imported declarations can materialize renamings, which *may* be
7259 global. However it is impossible (for now?) in DWARF to distinguish
7260 "external" imported declarations and "static" ones. As all imported
7261 declarations seem to be static in all other languages, make them all CU-wide
7262 global only in Ada. */
7264 static struct using_direct
**
7265 using_directives (struct dwarf2_cu
*cu
)
7267 if (cu
->lang () == language_ada
7268 && cu
->get_builder ()->outermost_context_p ())
7269 return cu
->get_builder ()->get_global_using_directives ();
7271 return cu
->get_builder ()->get_local_using_directives ();
7274 /* Read the DW_ATTR_decl_line attribute for the given DIE in the
7275 given CU. If the format is not recognized or the attribute is
7276 not present, set it to 0. */
7279 read_decl_line (struct die_info
*die
, struct dwarf2_cu
*cu
)
7281 struct attribute
*decl_line
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
7282 if (decl_line
== nullptr)
7284 if (decl_line
->form_is_constant ())
7286 LONGEST val
= decl_line
->constant_value (0);
7287 if (0 <= val
&& val
<= UINT_MAX
)
7288 return (unsigned int) val
;
7290 complaint (_("Declared line for using directive is too large"));
7294 complaint (_("Declared line for using directive is of incorrect format"));
7298 /* Read the import statement specified by the given die and record it. */
7301 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7303 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
7304 struct attribute
*import_attr
;
7305 struct die_info
*imported_die
, *child_die
;
7306 struct dwarf2_cu
*imported_cu
;
7307 const char *imported_name
;
7308 const char *imported_name_prefix
;
7309 const char *canonical_name
;
7310 const char *import_alias
;
7311 const char *imported_declaration
= NULL
;
7312 const char *import_prefix
;
7313 std::vector
<const char *> excludes
;
7315 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7316 if (import_attr
== NULL
)
7318 complaint (_("Tag '%s' has no DW_AT_import"),
7319 dwarf_tag_name (die
->tag
));
7324 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7325 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7326 if (imported_name
== NULL
)
7328 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7330 The import in the following code:
7344 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7345 <52> DW_AT_decl_file : 1
7346 <53> DW_AT_decl_line : 6
7347 <54> DW_AT_import : <0x75>
7348 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7350 <5b> DW_AT_decl_file : 1
7351 <5c> DW_AT_decl_line : 2
7352 <5d> DW_AT_type : <0x6e>
7354 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7355 <76> DW_AT_byte_size : 4
7356 <77> DW_AT_encoding : 5 (signed)
7358 imports the wrong die ( 0x75 instead of 0x58 ).
7359 This case will be ignored until the gcc bug is fixed. */
7363 /* Figure out the local name after import. */
7364 import_alias
= dwarf2_name (die
, cu
);
7366 /* Figure out where the statement is being imported to. */
7367 import_prefix
= determine_prefix (die
, cu
);
7369 /* Figure out what the scope of the imported die is and prepend it
7370 to the name of the imported die. */
7371 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7373 if (imported_die
->tag
!= DW_TAG_namespace
7374 && imported_die
->tag
!= DW_TAG_module
)
7376 imported_declaration
= imported_name
;
7377 canonical_name
= imported_name_prefix
;
7379 else if (strlen (imported_name_prefix
) > 0)
7380 canonical_name
= obconcat (&objfile
->objfile_obstack
,
7381 imported_name_prefix
,
7382 (cu
->lang () == language_d
7385 imported_name
, (char *) NULL
);
7387 canonical_name
= imported_name
;
7389 if (die
->tag
== DW_TAG_imported_module
7390 && cu
->lang () == language_fortran
)
7391 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7392 child_die
= child_die
->sibling
)
7394 /* DWARF-4: A Fortran use statement with a “rename list” may be
7395 represented by an imported module entry with an import attribute
7396 referring to the module and owned entries corresponding to those
7397 entities that are renamed as part of being imported. */
7399 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7401 complaint (_("child DW_TAG_imported_declaration expected "
7402 "- DIE at %s [in module %s]"),
7403 sect_offset_str (child_die
->sect_off
),
7404 objfile_name (objfile
));
7408 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7409 if (import_attr
== NULL
)
7411 complaint (_("Tag '%s' has no DW_AT_import"),
7412 dwarf_tag_name (child_die
->tag
));
7417 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7419 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7420 if (imported_name
== NULL
)
7422 complaint (_("child DW_TAG_imported_declaration has unknown "
7423 "imported name - DIE at %s [in module %s]"),
7424 sect_offset_str (child_die
->sect_off
),
7425 objfile_name (objfile
));
7429 excludes
.push_back (imported_name
);
7431 process_die (child_die
, cu
);
7434 add_using_directive (using_directives (cu
),
7438 imported_declaration
,
7440 read_decl_line (die
, cu
),
7442 &objfile
->objfile_obstack
);
7445 /* ICC<14 does not output the required DW_AT_declaration on incomplete
7446 types, but gives them a size of zero. Starting with version 14,
7447 ICC is compatible with GCC. */
7450 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
7452 if (!cu
->checked_producer
)
7453 check_producer (cu
);
7455 return cu
->producer_is_icc_lt_14
;
7458 /* ICC generates a DW_AT_type for C void functions. This was observed on
7459 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
7460 which says that void functions should not have a DW_AT_type. */
7463 producer_is_icc (struct dwarf2_cu
*cu
)
7465 if (!cu
->checked_producer
)
7466 check_producer (cu
);
7468 return cu
->producer_is_icc
;
7471 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7472 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7473 this, it was first present in GCC release 4.3.0. */
7476 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7478 if (!cu
->checked_producer
)
7479 check_producer (cu
);
7481 return cu
->producer_is_gcc_lt_4_3
;
7484 /* See dwarf2/read.h. */
7486 producer_is_clang (struct dwarf2_cu
*cu
)
7488 if (!cu
->checked_producer
)
7489 check_producer (cu
);
7491 return cu
->producer_is_clang
;
7494 static file_and_directory
&
7495 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
7497 if (cu
->per_cu
->fnd
!= nullptr)
7498 return *cu
->per_cu
->fnd
;
7500 /* Find the filename. Do not use dwarf2_name here, since the filename
7501 is not a source language identifier. */
7502 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
7503 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
7505 if (res
.get_comp_dir () == nullptr
7506 && producer_is_gcc_lt_4_3 (cu
)
7507 && res
.get_name () != nullptr
7508 && IS_ABSOLUTE_PATH (res
.get_name ()))
7510 res
.set_comp_dir (ldirname (res
.get_name ()));
7511 res
.set_name (make_unique_xstrdup (lbasename (res
.get_name ())));
7514 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
7515 return *cu
->per_cu
->fnd
;
7518 /* Handle DW_AT_stmt_list for a compilation unit.
7519 DIE is the DW_TAG_compile_unit die for CU.
7520 COMP_DIR is the compilation directory. LOWPC is passed to
7521 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
7524 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7525 const file_and_directory
&fnd
, CORE_ADDR lowpc
,
7526 bool have_code
) /* ARI: editCase function */
7528 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7529 struct attribute
*attr
;
7530 hashval_t line_header_local_hash
;
7534 gdb_assert (! cu
->per_cu
->is_debug_types
);
7536 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7537 if (attr
== NULL
|| !attr
->form_is_unsigned ())
7540 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
7542 /* The line header hash table is only created if needed (it exists to
7543 prevent redundant reading of the line table for partial_units).
7544 If we're given a partial_unit, we'll need it. If we're given a
7545 compile_unit, then use the line header hash table if it's already
7546 created, but don't create one just yet. */
7548 if (per_objfile
->line_header_hash
== NULL
7549 && die
->tag
== DW_TAG_partial_unit
)
7551 per_objfile
->line_header_hash
7552 .reset (htab_create_alloc (127, line_header_hash_voidp
,
7553 line_header_eq_voidp
,
7554 htab_delete_entry
<line_header
>,
7558 line_header
line_header_local (line_offset
, cu
->per_cu
->is_dwz
);
7559 line_header_local_hash
= line_header_hash (&line_header_local
);
7560 if (per_objfile
->line_header_hash
!= NULL
)
7562 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
7564 line_header_local_hash
, NO_INSERT
);
7566 /* For DW_TAG_compile_unit we need info like symtab::linetable which
7567 is not present in *SLOT (since if there is something in *SLOT then
7568 it will be for a partial_unit). */
7569 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
7571 gdb_assert (*slot
!= NULL
);
7572 cu
->line_header
= (struct line_header
*) *slot
;
7577 /* dwarf_decode_line_header does not yet provide sufficient information.
7578 We always have to call also dwarf_decode_lines for it. */
7579 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
,
7580 fnd
.get_comp_dir ());
7584 cu
->line_header
= lh
.release ();
7585 cu
->line_header_die_owner
= die
;
7587 if (per_objfile
->line_header_hash
== NULL
)
7591 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
7593 line_header_local_hash
, INSERT
);
7594 gdb_assert (slot
!= NULL
);
7596 if (slot
!= NULL
&& *slot
== NULL
)
7598 /* This newly decoded line number information unit will be owned
7599 by line_header_hash hash table. */
7600 *slot
= cu
->line_header
;
7601 cu
->line_header_die_owner
= NULL
;
7605 /* We cannot free any current entry in (*slot) as that struct line_header
7606 may be already used by multiple CUs. Create only temporary decoded
7607 line_header for this CU - it may happen at most once for each line
7608 number information unit. And if we're not using line_header_hash
7609 then this is what we want as well. */
7610 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
7612 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
7613 /* The have_code check is here because, if LOWPC and HIGHPC are both 0x0,
7614 then there won't be any interesting code in the CU, but a check later on
7615 (in lnp_state_machine::check_line_address) will fail to properly exclude
7616 an entry that was removed via --gc-sections. */
7618 dwarf_decode_lines (cu
->line_header
, cu
, lowpc
, decode_mapping
);
7621 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7624 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7626 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7627 struct objfile
*objfile
= per_objfile
->objfile
;
7628 struct gdbarch
*gdbarch
= objfile
->arch ();
7629 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7630 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7631 struct attribute
*attr
;
7632 struct die_info
*child_die
;
7635 prepare_one_comp_unit (cu
, die
, cu
->lang ());
7636 baseaddr
= objfile
->text_section_offset ();
7638 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7640 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7641 from finish_block. */
7642 if (lowpc
== ((CORE_ADDR
) -1))
7644 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
7646 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
7648 cu
->start_compunit_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
),
7651 gdb_assert (per_objfile
->sym_cu
== nullptr);
7652 scoped_restore restore_sym_cu
7653 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
7655 /* Decode line number information if present. We do this before
7656 processing child DIEs, so that the line header table is available
7657 for DW_AT_decl_file. */
7658 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
, lowpc
!= highpc
);
7660 /* Process all dies in compilation unit. */
7661 if (die
->child
!= NULL
)
7663 child_die
= die
->child
;
7664 while (child_die
&& child_die
->tag
)
7666 process_die (child_die
, cu
);
7667 child_die
= child_die
->sibling
;
7670 per_objfile
->sym_cu
= nullptr;
7672 /* Decode macro information, if present. Dwarf 2 macro information
7673 refers to information in the line number info statement program
7674 header, so we can only read it if we've read the header
7676 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
7678 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7679 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
7681 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7682 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
7684 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
7688 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7689 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
7691 unsigned int macro_offset
= attr
->as_unsigned ();
7693 dwarf_decode_macros (cu
, macro_offset
, 0);
7699 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
7701 struct type_unit_group
*tu_group
;
7703 struct attribute
*attr
;
7705 struct signatured_type
*sig_type
;
7707 gdb_assert (per_cu
->is_debug_types
);
7708 sig_type
= (struct signatured_type
*) per_cu
;
7710 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
7712 /* If we're using .gdb_index (includes -readnow) then
7713 per_cu->type_unit_group may not have been set up yet. */
7714 if (sig_type
->type_unit_group
== NULL
)
7715 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
7716 tu_group
= sig_type
->type_unit_group
;
7718 /* If we've already processed this stmt_list there's no real need to
7719 do it again, we could fake it and just recreate the part we need
7720 (file name,index -> symtab mapping). If data shows this optimization
7721 is useful we can do it then. */
7722 type_unit_group_unshareable
*tug_unshare
7723 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
7724 first_time
= tug_unshare
->compunit_symtab
== NULL
;
7726 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7729 if (attr
!= NULL
&& attr
->form_is_unsigned ())
7731 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
7732 lh
= dwarf_decode_line_header (line_offset
, this, nullptr);
7737 start_compunit_symtab ("", NULL
, 0);
7740 gdb_assert (tug_unshare
->symtabs
== NULL
);
7741 gdb_assert (m_builder
== nullptr);
7742 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
7743 m_builder
.reset (new struct buildsym_compunit
7744 (cust
->objfile (), "",
7748 list_in_scope
= get_builder ()->get_file_symbols ();
7753 line_header
= lh
.release ();
7754 line_header_die_owner
= die
;
7758 struct compunit_symtab
*cust
= start_compunit_symtab ("", NULL
, 0);
7760 /* Note: We don't assign tu_group->compunit_symtab yet because we're
7761 still initializing it, and our caller (a few levels up)
7762 process_full_type_unit still needs to know if this is the first
7765 tug_unshare
->symtabs
7766 = XOBNEWVEC (&cust
->objfile ()->objfile_obstack
,
7767 struct symtab
*, line_header
->file_names_size ());
7769 auto &file_names
= line_header
->file_names ();
7770 for (i
= 0; i
< file_names
.size (); ++i
)
7772 file_entry
&fe
= file_names
[i
];
7773 dwarf2_start_subfile (this, fe
, *line_header
);
7774 buildsym_compunit
*b
= get_builder ();
7775 subfile
*sf
= b
->get_current_subfile ();
7777 if (sf
->symtab
== nullptr)
7779 /* NOTE: start_subfile will recognize when it's been
7780 passed a file it has already seen. So we can't
7781 assume there's a simple mapping from
7782 cu->line_header->file_names to subfiles, plus
7783 cu->line_header->file_names may contain dups. */
7784 const char *name
= sf
->name
.c_str ();
7785 const char *name_for_id
= sf
->name_for_id
.c_str ();
7786 sf
->symtab
= allocate_symtab (cust
, name
, name_for_id
);
7789 fe
.symtab
= b
->get_current_subfile ()->symtab
;
7790 tug_unshare
->symtabs
[i
] = fe
.symtab
;
7795 gdb_assert (m_builder
== nullptr);
7796 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
7797 m_builder
.reset (new struct buildsym_compunit
7798 (cust
->objfile (), "",
7802 list_in_scope
= get_builder ()->get_file_symbols ();
7804 auto &file_names
= line_header
->file_names ();
7805 for (i
= 0; i
< file_names
.size (); ++i
)
7807 file_entry
&fe
= file_names
[i
];
7808 fe
.symtab
= tug_unshare
->symtabs
[i
];
7812 /* The main symtab is allocated last. Type units don't have DW_AT_name
7813 so they don't have a "real" (so to speak) symtab anyway.
7814 There is later code that will assign the main symtab to all symbols
7815 that don't have one. We need to handle the case of a symbol with a
7816 missing symtab (DW_AT_decl_file) anyway. */
7819 /* Process DW_TAG_type_unit.
7820 For TUs we want to skip the first top level sibling if it's not the
7821 actual type being defined by this TU. In this case the first top
7822 level sibling is there to provide context only. */
7825 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7827 struct die_info
*child_die
;
7829 prepare_one_comp_unit (cu
, die
, language_minimal
);
7831 /* Initialize (or reinitialize) the machinery for building symtabs.
7832 We do this before processing child DIEs, so that the line header table
7833 is available for DW_AT_decl_file. */
7834 cu
->setup_type_unit_groups (die
);
7836 if (die
->child
!= NULL
)
7838 child_die
= die
->child
;
7839 while (child_die
&& child_die
->tag
)
7841 process_die (child_die
, cu
);
7842 child_die
= child_die
->sibling
;
7849 http://gcc.gnu.org/wiki/DebugFission
7850 http://gcc.gnu.org/wiki/DebugFissionDWP
7852 To simplify handling of both DWO files ("object" files with the DWARF info)
7853 and DWP files (a file with the DWOs packaged up into one file), we treat
7854 DWP files as having a collection of virtual DWO files. */
7857 hash_dwo_file (const void *item
)
7859 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
7862 hash
= htab_hash_string (dwo_file
->dwo_name
);
7863 if (dwo_file
->comp_dir
!= NULL
)
7864 hash
+= htab_hash_string (dwo_file
->comp_dir
);
7869 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
7871 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
7872 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
7874 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
7876 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
7877 return lhs
->comp_dir
== rhs
->comp_dir
;
7878 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
7881 /* Allocate a hash table for DWO files. */
7884 allocate_dwo_file_hash_table ()
7886 return htab_up (htab_create_alloc (41,
7889 htab_delete_entry
<dwo_file
>,
7893 /* Lookup DWO file DWO_NAME. */
7896 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
7897 const char *dwo_name
,
7898 const char *comp_dir
)
7900 struct dwo_file find_entry
;
7903 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
7904 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
7906 find_entry
.dwo_name
= dwo_name
;
7907 find_entry
.comp_dir
= comp_dir
;
7908 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
7915 hash_dwo_unit (const void *item
)
7917 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
7919 /* This drops the top 32 bits of the id, but is ok for a hash. */
7920 return dwo_unit
->signature
;
7924 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
7926 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
7927 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
7929 /* The signature is assumed to be unique within the DWO file.
7930 So while object file CU dwo_id's always have the value zero,
7931 that's OK, assuming each object file DWO file has only one CU,
7932 and that's the rule for now. */
7933 return lhs
->signature
== rhs
->signature
;
7936 /* Allocate a hash table for DWO CUs,TUs.
7937 There is one of these tables for each of CUs,TUs for each DWO file. */
7940 allocate_dwo_unit_table ()
7942 /* Start out with a pretty small number.
7943 Generally DWO files contain only one CU and maybe some TUs. */
7944 return htab_up (htab_create_alloc (3,
7947 NULL
, xcalloc
, xfree
));
7950 /* die_reader_func for create_dwo_cu. */
7953 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
7954 const gdb_byte
*info_ptr
,
7955 struct die_info
*comp_unit_die
,
7956 struct dwo_file
*dwo_file
,
7957 struct dwo_unit
*dwo_unit
)
7959 struct dwarf2_cu
*cu
= reader
->cu
;
7960 sect_offset sect_off
= cu
->per_cu
->sect_off
;
7961 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
7963 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7964 if (!signature
.has_value ())
7966 complaint (_("Dwarf Error: debug entry at offset %s is missing"
7967 " its dwo_id [in module %s]"),
7968 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
7972 dwo_unit
->dwo_file
= dwo_file
;
7973 dwo_unit
->signature
= *signature
;
7974 dwo_unit
->section
= section
;
7975 dwo_unit
->sect_off
= sect_off
;
7976 dwo_unit
->length
= cu
->per_cu
->length ();
7978 dwarf_read_debug_printf (" offset %s, dwo_id %s",
7979 sect_offset_str (sect_off
),
7980 hex_string (dwo_unit
->signature
));
7983 /* Create the dwo_units for the CUs in a DWO_FILE.
7984 Note: This function processes DWO files only, not DWP files. */
7987 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
7988 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
7989 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
7991 struct objfile
*objfile
= per_objfile
->objfile
;
7992 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7993 const gdb_byte
*info_ptr
, *end_ptr
;
7995 section
.read (objfile
);
7996 info_ptr
= section
.buffer
;
7998 if (info_ptr
== NULL
)
8001 dwarf_read_debug_printf ("Reading %s for %s:",
8002 section
.get_name (),
8003 section
.get_file_name ());
8005 end_ptr
= info_ptr
+ section
.size
;
8006 while (info_ptr
< end_ptr
)
8008 struct dwarf2_per_cu_data per_cu
;
8009 struct dwo_unit read_unit
{};
8010 struct dwo_unit
*dwo_unit
;
8012 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
8014 per_cu
.per_bfd
= per_bfd
;
8015 per_cu
.is_debug_types
= 0;
8016 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
8017 per_cu
.section
= §ion
;
8019 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
8020 if (!reader
.dummy_p
)
8021 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
8022 &dwo_file
, &read_unit
);
8023 info_ptr
+= per_cu
.length ();
8025 // If the unit could not be parsed, skip it.
8026 if (read_unit
.dwo_file
== NULL
)
8029 if (cus_htab
== NULL
)
8030 cus_htab
= allocate_dwo_unit_table ();
8032 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
8034 *dwo_unit
= read_unit
;
8035 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
8036 gdb_assert (slot
!= NULL
);
8039 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
8040 sect_offset dup_sect_off
= dup_cu
->sect_off
;
8042 complaint (_("debug cu entry at offset %s is duplicate to"
8043 " the entry at offset %s, signature %s"),
8044 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
8045 hex_string (dwo_unit
->signature
));
8047 *slot
= (void *)dwo_unit
;
8051 /* DWP file .debug_{cu,tu}_index section format:
8052 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8053 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
8055 DWP Versions 1 & 2 are older, pre-standard format versions. The first
8056 officially standard DWP format was published with DWARF v5 and is called
8057 Version 5. There are no versions 3 or 4.
8061 Both index sections have the same format, and serve to map a 64-bit
8062 signature to a set of section numbers. Each section begins with a header,
8063 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8064 indexes, and a pool of 32-bit section numbers. The index sections will be
8065 aligned at 8-byte boundaries in the file.
8067 The index section header consists of:
8069 V, 32 bit version number
8071 N, 32 bit number of compilation units or type units in the index
8072 M, 32 bit number of slots in the hash table
8074 Numbers are recorded using the byte order of the application binary.
8076 The hash table begins at offset 16 in the section, and consists of an array
8077 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8078 order of the application binary). Unused slots in the hash table are 0.
8079 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8081 The parallel table begins immediately after the hash table
8082 (at offset 16 + 8 * M from the beginning of the section), and consists of an
8083 array of 32-bit indexes (using the byte order of the application binary),
8084 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8085 table contains a 32-bit index into the pool of section numbers. For unused
8086 hash table slots, the corresponding entry in the parallel table will be 0.
8088 The pool of section numbers begins immediately following the hash table
8089 (at offset 16 + 12 * M from the beginning of the section). The pool of
8090 section numbers consists of an array of 32-bit words (using the byte order
8091 of the application binary). Each item in the array is indexed starting
8092 from 0. The hash table entry provides the index of the first section
8093 number in the set. Additional section numbers in the set follow, and the
8094 set is terminated by a 0 entry (section number 0 is not used in ELF).
8096 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8097 section must be the first entry in the set, and the .debug_abbrev.dwo must
8098 be the second entry. Other members of the set may follow in any order.
8102 DWP Versions 2 and 5:
8104 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
8105 and the entries in the index tables are now offsets into these sections.
8106 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
8109 Index Section Contents:
8111 Hash Table of Signatures dwp_hash_table.hash_table
8112 Parallel Table of Indices dwp_hash_table.unit_table
8113 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
8114 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
8116 The index section header consists of:
8118 V, 32 bit version number
8119 L, 32 bit number of columns in the table of section offsets
8120 N, 32 bit number of compilation units or type units in the index
8121 M, 32 bit number of slots in the hash table
8123 Numbers are recorded using the byte order of the application binary.
8125 The hash table has the same format as version 1.
8126 The parallel table of indices has the same format as version 1,
8127 except that the entries are origin-1 indices into the table of sections
8128 offsets and the table of section sizes.
8130 The table of offsets begins immediately following the parallel table
8131 (at offset 16 + 12 * M from the beginning of the section). The table is
8132 a two-dimensional array of 32-bit words (using the byte order of the
8133 application binary), with L columns and N+1 rows, in row-major order.
8134 Each row in the array is indexed starting from 0. The first row provides
8135 a key to the remaining rows: each column in this row provides an identifier
8136 for a debug section, and the offsets in the same column of subsequent rows
8137 refer to that section. The section identifiers for Version 2 are:
8139 DW_SECT_INFO 1 .debug_info.dwo
8140 DW_SECT_TYPES 2 .debug_types.dwo
8141 DW_SECT_ABBREV 3 .debug_abbrev.dwo
8142 DW_SECT_LINE 4 .debug_line.dwo
8143 DW_SECT_LOC 5 .debug_loc.dwo
8144 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
8145 DW_SECT_MACINFO 7 .debug_macinfo.dwo
8146 DW_SECT_MACRO 8 .debug_macro.dwo
8148 The section identifiers for Version 5 are:
8150 DW_SECT_INFO_V5 1 .debug_info.dwo
8151 DW_SECT_RESERVED_V5 2 --
8152 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
8153 DW_SECT_LINE_V5 4 .debug_line.dwo
8154 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
8155 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
8156 DW_SECT_MACRO_V5 7 .debug_macro.dwo
8157 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
8159 The offsets provided by the CU and TU index sections are the base offsets
8160 for the contributions made by each CU or TU to the corresponding section
8161 in the package file. Each CU and TU header contains an abbrev_offset
8162 field, used to find the abbreviations table for that CU or TU within the
8163 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
8164 be interpreted as relative to the base offset given in the index section.
8165 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
8166 should be interpreted as relative to the base offset for .debug_line.dwo,
8167 and offsets into other debug sections obtained from DWARF attributes should
8168 also be interpreted as relative to the corresponding base offset.
8170 The table of sizes begins immediately following the table of offsets.
8171 Like the table of offsets, it is a two-dimensional array of 32-bit words,
8172 with L columns and N rows, in row-major order. Each row in the array is
8173 indexed starting from 1 (row 0 is shared by the two tables).
8177 Hash table lookup is handled the same in version 1 and 2:
8179 We assume that N and M will not exceed 2^32 - 1.
8180 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8182 Given a 64-bit compilation unit signature or a type signature S, an entry
8183 in the hash table is located as follows:
8185 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8186 the low-order k bits all set to 1.
8188 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8190 3) If the hash table entry at index H matches the signature, use that
8191 entry. If the hash table entry at index H is unused (all zeroes),
8192 terminate the search: the signature is not present in the table.
8194 4) Let H = (H + H') modulo M. Repeat at Step 3.
8196 Because M > N and H' and M are relatively prime, the search is guaranteed
8197 to stop at an unused slot or find the match. */
8199 /* Create a hash table to map DWO IDs to their CU/TU entry in
8200 .debug_{info,types}.dwo in DWP_FILE.
8201 Returns NULL if there isn't one.
8202 Note: This function processes DWP files only, not DWO files. */
8204 static struct dwp_hash_table
*
8205 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
8206 struct dwp_file
*dwp_file
, int is_debug_types
)
8208 struct objfile
*objfile
= per_objfile
->objfile
;
8209 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8210 const gdb_byte
*index_ptr
, *index_end
;
8211 struct dwarf2_section_info
*index
;
8212 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
8213 struct dwp_hash_table
*htab
;
8216 index
= &dwp_file
->sections
.tu_index
;
8218 index
= &dwp_file
->sections
.cu_index
;
8220 if (index
->empty ())
8222 index
->read (objfile
);
8224 index_ptr
= index
->buffer
;
8225 index_end
= index_ptr
+ index
->size
;
8227 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
8228 For now it's safe to just read 4 bytes (particularly as it's difficult to
8229 tell if you're dealing with Version 5 before you've read the version). */
8230 version
= read_4_bytes (dbfd
, index_ptr
);
8232 if (version
== 2 || version
== 5)
8233 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
8237 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8239 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8242 if (version
!= 1 && version
!= 2 && version
!= 5)
8244 error (_("Dwarf Error: unsupported DWP file version (%s)"
8246 pulongest (version
), dwp_file
->name
);
8248 if (nr_slots
!= (nr_slots
& -nr_slots
))
8250 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
8251 " is not power of 2 [in module %s]"),
8252 pulongest (nr_slots
), dwp_file
->name
);
8255 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
8256 htab
->version
= version
;
8257 htab
->nr_columns
= nr_columns
;
8258 htab
->nr_units
= nr_units
;
8259 htab
->nr_slots
= nr_slots
;
8260 htab
->hash_table
= index_ptr
;
8261 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8263 /* Exit early if the table is empty. */
8264 if (nr_slots
== 0 || nr_units
== 0
8265 || (version
== 2 && nr_columns
== 0)
8266 || (version
== 5 && nr_columns
== 0))
8268 /* All must be zero. */
8269 if (nr_slots
!= 0 || nr_units
!= 0
8270 || (version
== 2 && nr_columns
!= 0)
8271 || (version
== 5 && nr_columns
!= 0))
8273 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
8274 " all zero [in modules %s]"),
8282 htab
->section_pool
.v1
.indices
=
8283 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8284 /* It's harder to decide whether the section is too small in v1.
8285 V1 is deprecated anyway so we punt. */
8287 else if (version
== 2)
8289 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8290 int *ids
= htab
->section_pool
.v2
.section_ids
;
8291 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
8292 /* Reverse map for error checking. */
8293 int ids_seen
[DW_SECT_MAX
+ 1];
8298 error (_("Dwarf Error: bad DWP hash table, too few columns"
8299 " in section table [in module %s]"),
8302 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
8304 error (_("Dwarf Error: bad DWP hash table, too many columns"
8305 " in section table [in module %s]"),
8308 memset (ids
, 255, sizeof_ids
);
8309 memset (ids_seen
, 255, sizeof (ids_seen
));
8310 for (i
= 0; i
< nr_columns
; ++i
)
8312 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
8314 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
8316 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
8317 " in section table [in module %s]"),
8318 id
, dwp_file
->name
);
8320 if (ids_seen
[id
] != -1)
8322 error (_("Dwarf Error: bad DWP hash table, duplicate section"
8323 " id %d in section table [in module %s]"),
8324 id
, dwp_file
->name
);
8329 /* Must have exactly one info or types section. */
8330 if (((ids_seen
[DW_SECT_INFO
] != -1)
8331 + (ids_seen
[DW_SECT_TYPES
] != -1))
8334 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
8335 " DWO info/types section [in module %s]"),
8338 /* Must have an abbrev section. */
8339 if (ids_seen
[DW_SECT_ABBREV
] == -1)
8341 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
8342 " section [in module %s]"),
8345 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
8346 htab
->section_pool
.v2
.sizes
=
8347 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
8348 * nr_units
* nr_columns
);
8349 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
8350 * nr_units
* nr_columns
))
8353 error (_("Dwarf Error: DWP index section is corrupt (too small)"
8358 else /* version == 5 */
8360 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8361 int *ids
= htab
->section_pool
.v5
.section_ids
;
8362 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
8363 /* Reverse map for error checking. */
8364 int ids_seen
[DW_SECT_MAX_V5
+ 1];
8368 error (_("Dwarf Error: bad DWP hash table, too few columns"
8369 " in section table [in module %s]"),
8372 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
8374 error (_("Dwarf Error: bad DWP hash table, too many columns"
8375 " in section table [in module %s]"),
8378 memset (ids
, 255, sizeof_ids
);
8379 memset (ids_seen
, 255, sizeof (ids_seen
));
8380 for (int i
= 0; i
< nr_columns
; ++i
)
8382 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
8384 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
8386 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
8387 " in section table [in module %s]"),
8388 id
, dwp_file
->name
);
8390 if (ids_seen
[id
] != -1)
8392 error (_("Dwarf Error: bad DWP hash table, duplicate section"
8393 " id %d in section table [in module %s]"),
8394 id
, dwp_file
->name
);
8399 /* Must have seen an info section. */
8400 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
8402 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
8403 " DWO info/types section [in module %s]"),
8406 /* Must have an abbrev section. */
8407 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
8409 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
8410 " section [in module %s]"),
8413 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
8414 htab
->section_pool
.v5
.sizes
8415 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
8416 * nr_units
* nr_columns
);
8417 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
8418 * nr_units
* nr_columns
))
8421 error (_("Dwarf Error: DWP index section is corrupt (too small)"
8430 /* Update SECTIONS with the data from SECTP.
8432 This function is like the other "locate" section routines, but in
8433 this context the sections to read comes from the DWP V1 hash table,
8434 not the full ELF section table.
8436 The result is non-zero for success, or zero if an error was found. */
8439 locate_v1_virtual_dwo_sections (asection
*sectp
,
8440 struct virtual_v1_dwo_sections
*sections
)
8442 const struct dwop_section_names
*names
= &dwop_section_names
;
8444 if (names
->abbrev_dwo
.matches (sectp
->name
))
8446 /* There can be only one. */
8447 if (sections
->abbrev
.s
.section
!= NULL
)
8449 sections
->abbrev
.s
.section
= sectp
;
8450 sections
->abbrev
.size
= bfd_section_size (sectp
);
8452 else if (names
->info_dwo
.matches (sectp
->name
)
8453 || names
->types_dwo
.matches (sectp
->name
))
8455 /* There can be only one. */
8456 if (sections
->info_or_types
.s
.section
!= NULL
)
8458 sections
->info_or_types
.s
.section
= sectp
;
8459 sections
->info_or_types
.size
= bfd_section_size (sectp
);
8461 else if (names
->line_dwo
.matches (sectp
->name
))
8463 /* There can be only one. */
8464 if (sections
->line
.s
.section
!= NULL
)
8466 sections
->line
.s
.section
= sectp
;
8467 sections
->line
.size
= bfd_section_size (sectp
);
8469 else if (names
->loc_dwo
.matches (sectp
->name
))
8471 /* There can be only one. */
8472 if (sections
->loc
.s
.section
!= NULL
)
8474 sections
->loc
.s
.section
= sectp
;
8475 sections
->loc
.size
= bfd_section_size (sectp
);
8477 else if (names
->macinfo_dwo
.matches (sectp
->name
))
8479 /* There can be only one. */
8480 if (sections
->macinfo
.s
.section
!= NULL
)
8482 sections
->macinfo
.s
.section
= sectp
;
8483 sections
->macinfo
.size
= bfd_section_size (sectp
);
8485 else if (names
->macro_dwo
.matches (sectp
->name
))
8487 /* There can be only one. */
8488 if (sections
->macro
.s
.section
!= NULL
)
8490 sections
->macro
.s
.section
= sectp
;
8491 sections
->macro
.size
= bfd_section_size (sectp
);
8493 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
8495 /* There can be only one. */
8496 if (sections
->str_offsets
.s
.section
!= NULL
)
8498 sections
->str_offsets
.s
.section
= sectp
;
8499 sections
->str_offsets
.size
= bfd_section_size (sectp
);
8503 /* No other kind of section is valid. */
8510 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8511 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8512 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8513 This is for DWP version 1 files. */
8515 static struct dwo_unit
*
8516 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
8517 struct dwp_file
*dwp_file
,
8518 uint32_t unit_index
,
8519 const char *comp_dir
,
8520 ULONGEST signature
, int is_debug_types
)
8522 const struct dwp_hash_table
*dwp_htab
=
8523 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
8524 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8525 const char *kind
= is_debug_types
? "TU" : "CU";
8526 struct dwo_file
*dwo_file
;
8527 struct dwo_unit
*dwo_unit
;
8528 struct virtual_v1_dwo_sections sections
;
8529 void **dwo_file_slot
;
8532 gdb_assert (dwp_file
->version
== 1);
8534 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
8535 kind
, pulongest (unit_index
), hex_string (signature
),
8538 /* Fetch the sections of this DWO unit.
8539 Put a limit on the number of sections we look for so that bad data
8540 doesn't cause us to loop forever. */
8542 #define MAX_NR_V1_DWO_SECTIONS \
8543 (1 /* .debug_info or .debug_types */ \
8544 + 1 /* .debug_abbrev */ \
8545 + 1 /* .debug_line */ \
8546 + 1 /* .debug_loc */ \
8547 + 1 /* .debug_str_offsets */ \
8548 + 1 /* .debug_macro or .debug_macinfo */ \
8549 + 1 /* trailing zero */)
8551 memset (§ions
, 0, sizeof (sections
));
8553 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
8556 uint32_t section_nr
=
8558 dwp_htab
->section_pool
.v1
.indices
8559 + (unit_index
+ i
) * sizeof (uint32_t));
8561 if (section_nr
== 0)
8563 if (section_nr
>= dwp_file
->num_sections
)
8565 error (_("Dwarf Error: bad DWP hash table, section number too large"
8570 sectp
= dwp_file
->elf_sections
[section_nr
];
8571 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
8573 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8580 || sections
.info_or_types
.empty ()
8581 || sections
.abbrev
.empty ())
8583 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8587 if (i
== MAX_NR_V1_DWO_SECTIONS
)
8589 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8594 /* It's easier for the rest of the code if we fake a struct dwo_file and
8595 have dwo_unit "live" in that. At least for now.
8597 The DWP file can be made up of a random collection of CUs and TUs.
8598 However, for each CU + set of TUs that came from the same original DWO
8599 file, we can combine them back into a virtual DWO file to save space
8600 (fewer struct dwo_file objects to allocate). Remember that for really
8601 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8603 std::string virtual_dwo_name
=
8604 string_printf ("virtual-dwo/%d-%d-%d-%d",
8605 sections
.abbrev
.get_id (),
8606 sections
.line
.get_id (),
8607 sections
.loc
.get_id (),
8608 sections
.str_offsets
.get_id ());
8609 /* Can we use an existing virtual DWO file? */
8610 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
8612 /* Create one if necessary. */
8613 if (*dwo_file_slot
== NULL
)
8615 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8616 virtual_dwo_name
.c_str ());
8618 dwo_file
= new struct dwo_file
;
8619 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
8620 dwo_file
->comp_dir
= comp_dir
;
8621 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8622 dwo_file
->sections
.line
= sections
.line
;
8623 dwo_file
->sections
.loc
= sections
.loc
;
8624 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8625 dwo_file
->sections
.macro
= sections
.macro
;
8626 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8627 /* The "str" section is global to the entire DWP file. */
8628 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8629 /* The info or types section is assigned below to dwo_unit,
8630 there's no need to record it in dwo_file.
8631 Also, we can't simply record type sections in dwo_file because
8632 we record a pointer into the vector in dwo_unit. As we collect more
8633 types we'll grow the vector and eventually have to reallocate space
8634 for it, invalidating all copies of pointers into the previous
8636 *dwo_file_slot
= dwo_file
;
8640 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
8641 virtual_dwo_name
.c_str ());
8643 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
8646 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
8647 dwo_unit
->dwo_file
= dwo_file
;
8648 dwo_unit
->signature
= signature
;
8650 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
8651 *dwo_unit
->section
= sections
.info_or_types
;
8652 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
8657 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
8658 simplify them. Given a pointer to the containing section SECTION, and
8659 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
8660 virtual section of just that piece. */
8662 static struct dwarf2_section_info
8663 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
8664 struct dwarf2_section_info
*section
,
8665 bfd_size_type offset
, bfd_size_type size
)
8667 struct dwarf2_section_info result
;
8670 gdb_assert (section
!= NULL
);
8671 gdb_assert (!section
->is_virtual
);
8673 memset (&result
, 0, sizeof (result
));
8674 result
.s
.containing_section
= section
;
8675 result
.is_virtual
= true;
8680 sectp
= section
->get_bfd_section ();
8682 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
8683 bounds of the real section. This is a pretty-rare event, so just
8684 flag an error (easier) instead of a warning and trying to cope. */
8686 || offset
+ size
> bfd_section_size (sectp
))
8688 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
8689 " in section %s [in module %s]"),
8690 sectp
? bfd_section_name (sectp
) : "<unknown>",
8691 objfile_name (per_objfile
->objfile
));
8694 result
.virtual_offset
= offset
;
8699 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8700 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8701 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8702 This is for DWP version 2 files. */
8704 static struct dwo_unit
*
8705 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
8706 struct dwp_file
*dwp_file
,
8707 uint32_t unit_index
,
8708 const char *comp_dir
,
8709 ULONGEST signature
, int is_debug_types
)
8711 const struct dwp_hash_table
*dwp_htab
=
8712 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
8713 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8714 const char *kind
= is_debug_types
? "TU" : "CU";
8715 struct dwo_file
*dwo_file
;
8716 struct dwo_unit
*dwo_unit
;
8717 struct virtual_v2_or_v5_dwo_sections sections
;
8718 void **dwo_file_slot
;
8721 gdb_assert (dwp_file
->version
== 2);
8723 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
8724 kind
, pulongest (unit_index
), hex_string (signature
),
8727 /* Fetch the section offsets of this DWO unit. */
8729 memset (§ions
, 0, sizeof (sections
));
8731 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
8733 uint32_t offset
= read_4_bytes (dbfd
,
8734 dwp_htab
->section_pool
.v2
.offsets
8735 + (((unit_index
- 1) * dwp_htab
->nr_columns
8737 * sizeof (uint32_t)));
8738 uint32_t size
= read_4_bytes (dbfd
,
8739 dwp_htab
->section_pool
.v2
.sizes
8740 + (((unit_index
- 1) * dwp_htab
->nr_columns
8742 * sizeof (uint32_t)));
8744 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
8748 sections
.info_or_types_offset
= offset
;
8749 sections
.info_or_types_size
= size
;
8751 case DW_SECT_ABBREV
:
8752 sections
.abbrev_offset
= offset
;
8753 sections
.abbrev_size
= size
;
8756 sections
.line_offset
= offset
;
8757 sections
.line_size
= size
;
8760 sections
.loc_offset
= offset
;
8761 sections
.loc_size
= size
;
8763 case DW_SECT_STR_OFFSETS
:
8764 sections
.str_offsets_offset
= offset
;
8765 sections
.str_offsets_size
= size
;
8767 case DW_SECT_MACINFO
:
8768 sections
.macinfo_offset
= offset
;
8769 sections
.macinfo_size
= size
;
8772 sections
.macro_offset
= offset
;
8773 sections
.macro_size
= size
;
8778 /* It's easier for the rest of the code if we fake a struct dwo_file and
8779 have dwo_unit "live" in that. At least for now.
8781 The DWP file can be made up of a random collection of CUs and TUs.
8782 However, for each CU + set of TUs that came from the same original DWO
8783 file, we can combine them back into a virtual DWO file to save space
8784 (fewer struct dwo_file objects to allocate). Remember that for really
8785 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8787 std::string virtual_dwo_name
=
8788 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
8789 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
8790 (long) (sections
.line_size
? sections
.line_offset
: 0),
8791 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
8792 (long) (sections
.str_offsets_size
8793 ? sections
.str_offsets_offset
: 0));
8794 /* Can we use an existing virtual DWO file? */
8795 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
8797 /* Create one if necessary. */
8798 if (*dwo_file_slot
== NULL
)
8800 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8801 virtual_dwo_name
.c_str ());
8803 dwo_file
= new struct dwo_file
;
8804 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
8805 dwo_file
->comp_dir
= comp_dir
;
8806 dwo_file
->sections
.abbrev
=
8807 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
8808 sections
.abbrev_offset
,
8809 sections
.abbrev_size
);
8810 dwo_file
->sections
.line
=
8811 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
8812 sections
.line_offset
,
8813 sections
.line_size
);
8814 dwo_file
->sections
.loc
=
8815 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
8816 sections
.loc_offset
, sections
.loc_size
);
8817 dwo_file
->sections
.macinfo
=
8818 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
8819 sections
.macinfo_offset
,
8820 sections
.macinfo_size
);
8821 dwo_file
->sections
.macro
=
8822 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
8823 sections
.macro_offset
,
8824 sections
.macro_size
);
8825 dwo_file
->sections
.str_offsets
=
8826 create_dwp_v2_or_v5_section (per_objfile
,
8827 &dwp_file
->sections
.str_offsets
,
8828 sections
.str_offsets_offset
,
8829 sections
.str_offsets_size
);
8830 /* The "str" section is global to the entire DWP file. */
8831 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8832 /* The info or types section is assigned below to dwo_unit,
8833 there's no need to record it in dwo_file.
8834 Also, we can't simply record type sections in dwo_file because
8835 we record a pointer into the vector in dwo_unit. As we collect more
8836 types we'll grow the vector and eventually have to reallocate space
8837 for it, invalidating all copies of pointers into the previous
8839 *dwo_file_slot
= dwo_file
;
8843 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
8844 virtual_dwo_name
.c_str ());
8846 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
8849 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
8850 dwo_unit
->dwo_file
= dwo_file
;
8851 dwo_unit
->signature
= signature
;
8853 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
8854 *dwo_unit
->section
= create_dwp_v2_or_v5_section
8857 ? &dwp_file
->sections
.types
8858 : &dwp_file
->sections
.info
,
8859 sections
.info_or_types_offset
,
8860 sections
.info_or_types_size
);
8861 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
8866 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
8867 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
8868 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
8869 This is for DWP version 5 files. */
8871 static struct dwo_unit
*
8872 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
8873 struct dwp_file
*dwp_file
,
8874 uint32_t unit_index
,
8875 const char *comp_dir
,
8876 ULONGEST signature
, int is_debug_types
)
8878 const struct dwp_hash_table
*dwp_htab
8879 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
8880 bfd
*dbfd
= dwp_file
->dbfd
.get ();
8881 const char *kind
= is_debug_types
? "TU" : "CU";
8882 struct dwo_file
*dwo_file
;
8883 struct dwo_unit
*dwo_unit
;
8884 struct virtual_v2_or_v5_dwo_sections sections
{};
8885 void **dwo_file_slot
;
8887 gdb_assert (dwp_file
->version
== 5);
8889 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
8890 kind
, pulongest (unit_index
), hex_string (signature
),
8893 /* Fetch the section offsets of this DWO unit. */
8895 /* memset (§ions, 0, sizeof (sections)); */
8897 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
8899 uint32_t offset
= read_4_bytes (dbfd
,
8900 dwp_htab
->section_pool
.v5
.offsets
8901 + (((unit_index
- 1)
8902 * dwp_htab
->nr_columns
8904 * sizeof (uint32_t)));
8905 uint32_t size
= read_4_bytes (dbfd
,
8906 dwp_htab
->section_pool
.v5
.sizes
8907 + (((unit_index
- 1) * dwp_htab
->nr_columns
8909 * sizeof (uint32_t)));
8911 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
8913 case DW_SECT_ABBREV_V5
:
8914 sections
.abbrev_offset
= offset
;
8915 sections
.abbrev_size
= size
;
8917 case DW_SECT_INFO_V5
:
8918 sections
.info_or_types_offset
= offset
;
8919 sections
.info_or_types_size
= size
;
8921 case DW_SECT_LINE_V5
:
8922 sections
.line_offset
= offset
;
8923 sections
.line_size
= size
;
8925 case DW_SECT_LOCLISTS_V5
:
8926 sections
.loclists_offset
= offset
;
8927 sections
.loclists_size
= size
;
8929 case DW_SECT_MACRO_V5
:
8930 sections
.macro_offset
= offset
;
8931 sections
.macro_size
= size
;
8933 case DW_SECT_RNGLISTS_V5
:
8934 sections
.rnglists_offset
= offset
;
8935 sections
.rnglists_size
= size
;
8937 case DW_SECT_STR_OFFSETS_V5
:
8938 sections
.str_offsets_offset
= offset
;
8939 sections
.str_offsets_size
= size
;
8941 case DW_SECT_RESERVED_V5
:
8947 /* It's easier for the rest of the code if we fake a struct dwo_file and
8948 have dwo_unit "live" in that. At least for now.
8950 The DWP file can be made up of a random collection of CUs and TUs.
8951 However, for each CU + set of TUs that came from the same original DWO
8952 file, we can combine them back into a virtual DWO file to save space
8953 (fewer struct dwo_file objects to allocate). Remember that for really
8954 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8956 std::string virtual_dwo_name
=
8957 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
8958 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
8959 (long) (sections
.line_size
? sections
.line_offset
: 0),
8960 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
8961 (long) (sections
.str_offsets_size
8962 ? sections
.str_offsets_offset
: 0),
8963 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
8964 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
8965 /* Can we use an existing virtual DWO file? */
8966 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
8967 virtual_dwo_name
.c_str (),
8969 /* Create one if necessary. */
8970 if (*dwo_file_slot
== NULL
)
8972 dwarf_read_debug_printf ("Creating virtual DWO: %s",
8973 virtual_dwo_name
.c_str ());
8975 dwo_file
= new struct dwo_file
;
8976 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
8977 dwo_file
->comp_dir
= comp_dir
;
8978 dwo_file
->sections
.abbrev
=
8979 create_dwp_v2_or_v5_section (per_objfile
,
8980 &dwp_file
->sections
.abbrev
,
8981 sections
.abbrev_offset
,
8982 sections
.abbrev_size
);
8983 dwo_file
->sections
.line
=
8984 create_dwp_v2_or_v5_section (per_objfile
,
8985 &dwp_file
->sections
.line
,
8986 sections
.line_offset
, sections
.line_size
);
8987 dwo_file
->sections
.macro
=
8988 create_dwp_v2_or_v5_section (per_objfile
,
8989 &dwp_file
->sections
.macro
,
8990 sections
.macro_offset
,
8991 sections
.macro_size
);
8992 dwo_file
->sections
.loclists
=
8993 create_dwp_v2_or_v5_section (per_objfile
,
8994 &dwp_file
->sections
.loclists
,
8995 sections
.loclists_offset
,
8996 sections
.loclists_size
);
8997 dwo_file
->sections
.rnglists
=
8998 create_dwp_v2_or_v5_section (per_objfile
,
8999 &dwp_file
->sections
.rnglists
,
9000 sections
.rnglists_offset
,
9001 sections
.rnglists_size
);
9002 dwo_file
->sections
.str_offsets
=
9003 create_dwp_v2_or_v5_section (per_objfile
,
9004 &dwp_file
->sections
.str_offsets
,
9005 sections
.str_offsets_offset
,
9006 sections
.str_offsets_size
);
9007 /* The "str" section is global to the entire DWP file. */
9008 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
9009 /* The info or types section is assigned below to dwo_unit,
9010 there's no need to record it in dwo_file.
9011 Also, we can't simply record type sections in dwo_file because
9012 we record a pointer into the vector in dwo_unit. As we collect more
9013 types we'll grow the vector and eventually have to reallocate space
9014 for it, invalidating all copies of pointers into the previous
9016 *dwo_file_slot
= dwo_file
;
9020 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
9021 virtual_dwo_name
.c_str ());
9023 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
9026 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
9027 dwo_unit
->dwo_file
= dwo_file
;
9028 dwo_unit
->signature
= signature
;
9030 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
9031 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
9032 &dwp_file
->sections
.info
,
9033 sections
.info_or_types_offset
,
9034 sections
.info_or_types_size
);
9035 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
9040 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
9041 Returns NULL if the signature isn't found. */
9043 static struct dwo_unit
*
9044 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
9045 struct dwp_file
*dwp_file
, const char *comp_dir
,
9046 ULONGEST signature
, int is_debug_types
)
9048 const struct dwp_hash_table
*dwp_htab
=
9049 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9050 bfd
*dbfd
= dwp_file
->dbfd
.get ();
9051 uint32_t mask
= dwp_htab
->nr_slots
- 1;
9052 uint32_t hash
= signature
& mask
;
9053 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
9056 struct dwo_unit find_dwo_cu
;
9058 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
9059 find_dwo_cu
.signature
= signature
;
9060 slot
= htab_find_slot (is_debug_types
9061 ? dwp_file
->loaded_tus
.get ()
9062 : dwp_file
->loaded_cus
.get (),
9063 &find_dwo_cu
, INSERT
);
9066 return (struct dwo_unit
*) *slot
;
9068 /* Use a for loop so that we don't loop forever on bad debug info. */
9069 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
9071 ULONGEST signature_in_table
;
9073 signature_in_table
=
9074 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
9075 if (signature_in_table
== signature
)
9077 uint32_t unit_index
=
9079 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
9081 if (dwp_file
->version
== 1)
9083 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
9084 unit_index
, comp_dir
,
9085 signature
, is_debug_types
);
9087 else if (dwp_file
->version
== 2)
9089 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
9090 unit_index
, comp_dir
,
9091 signature
, is_debug_types
);
9093 else /* version == 5 */
9095 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
9096 unit_index
, comp_dir
,
9097 signature
, is_debug_types
);
9099 return (struct dwo_unit
*) *slot
;
9101 if (signature_in_table
== 0)
9103 hash
= (hash
+ hash2
) & mask
;
9106 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
9111 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
9112 Open the file specified by FILE_NAME and hand it off to BFD for
9113 preliminary analysis. Return a newly initialized bfd *, which
9114 includes a canonicalized copy of FILE_NAME.
9115 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
9116 SEARCH_CWD is true if the current directory is to be searched.
9117 It will be searched before debug-file-directory.
9118 If successful, the file is added to the bfd include table of the
9119 objfile's bfd (see gdb_bfd_record_inclusion).
9120 If unable to find/open the file, return NULL.
9121 NOTE: This function is derived from symfile_bfd_open. */
9123 static gdb_bfd_ref_ptr
9124 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
9125 const char *file_name
, int is_dwp
, int search_cwd
)
9128 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
9129 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
9130 to debug_file_directory. */
9131 const char *search_path
;
9132 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
9134 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
9137 if (!debug_file_directory
.empty ())
9139 search_path_holder
.reset (concat (".", dirname_separator_string
,
9140 debug_file_directory
.c_str (),
9142 search_path
= search_path_holder
.get ();
9148 search_path
= debug_file_directory
.c_str ();
9150 /* Add the path for the executable binary to the list of search paths. */
9151 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
9152 search_path_holder
.reset (concat (objfile_dir
.c_str (),
9153 dirname_separator_string
,
9154 search_path
, nullptr));
9155 search_path
= search_path_holder
.get ();
9157 openp_flags flags
= OPF_RETURN_REALPATH
;
9159 flags
|= OPF_SEARCH_IN_PATH
;
9161 gdb::unique_xmalloc_ptr
<char> absolute_name
;
9162 desc
= openp (search_path
, flags
, file_name
,
9163 O_RDONLY
| O_BINARY
, &absolute_name
);
9167 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
9169 if (sym_bfd
== NULL
)
9171 bfd_set_cacheable (sym_bfd
.get (), 1);
9173 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
9176 /* Success. Record the bfd as having been included by the objfile's bfd.
9177 This is important because things like demangled_names_hash lives in the
9178 objfile's per_bfd space and may have references to things like symbol
9179 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
9180 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
.get (), sym_bfd
.get ());
9185 /* Try to open DWO file FILE_NAME.
9186 COMP_DIR is the DW_AT_comp_dir attribute.
9187 The result is the bfd handle of the file.
9188 If there is a problem finding or opening the file, return NULL.
9189 Upon success, the canonicalized path of the file is stored in the bfd,
9190 same as symfile_bfd_open. */
9192 static gdb_bfd_ref_ptr
9193 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
9194 const char *file_name
, const char *comp_dir
)
9196 if (IS_ABSOLUTE_PATH (file_name
))
9197 return try_open_dwop_file (per_objfile
, file_name
,
9198 0 /*is_dwp*/, 0 /*search_cwd*/);
9200 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
9202 if (comp_dir
!= NULL
)
9204 std::string path_to_try
= path_join (comp_dir
, file_name
);
9206 /* NOTE: If comp_dir is a relative path, this will also try the
9207 search path, which seems useful. */
9208 gdb_bfd_ref_ptr
abfd (try_open_dwop_file
9209 (per_objfile
, path_to_try
.c_str (), 0 /*is_dwp*/, 1 /*search_cwd*/));
9215 /* That didn't work, try debug-file-directory, which, despite its name,
9216 is a list of paths. */
9218 if (debug_file_directory
.empty ())
9221 return try_open_dwop_file (per_objfile
, file_name
,
9222 0 /*is_dwp*/, 1 /*search_cwd*/);
9225 /* This function is mapped across the sections and remembers the offset and
9226 size of each of the DWO debugging sections we are interested in. */
9229 dwarf2_locate_dwo_sections (struct objfile
*objfile
, bfd
*abfd
,
9230 asection
*sectp
, dwo_sections
*dwo_sections
)
9232 const struct dwop_section_names
*names
= &dwop_section_names
;
9234 struct dwarf2_section_info
*dw_sect
= nullptr;
9236 if (names
->abbrev_dwo
.matches (sectp
->name
))
9237 dw_sect
= &dwo_sections
->abbrev
;
9238 else if (names
->info_dwo
.matches (sectp
->name
))
9239 dw_sect
= &dwo_sections
->info
;
9240 else if (names
->line_dwo
.matches (sectp
->name
))
9241 dw_sect
= &dwo_sections
->line
;
9242 else if (names
->loc_dwo
.matches (sectp
->name
))
9243 dw_sect
= &dwo_sections
->loc
;
9244 else if (names
->loclists_dwo
.matches (sectp
->name
))
9245 dw_sect
= &dwo_sections
->loclists
;
9246 else if (names
->macinfo_dwo
.matches (sectp
->name
))
9247 dw_sect
= &dwo_sections
->macinfo
;
9248 else if (names
->macro_dwo
.matches (sectp
->name
))
9249 dw_sect
= &dwo_sections
->macro
;
9250 else if (names
->rnglists_dwo
.matches (sectp
->name
))
9251 dw_sect
= &dwo_sections
->rnglists
;
9252 else if (names
->str_dwo
.matches (sectp
->name
))
9253 dw_sect
= &dwo_sections
->str
;
9254 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
9255 dw_sect
= &dwo_sections
->str_offsets
;
9256 else if (names
->types_dwo
.matches (sectp
->name
))
9258 struct dwarf2_section_info type_section
;
9260 memset (&type_section
, 0, sizeof (type_section
));
9261 dwo_sections
->types
.push_back (type_section
);
9262 dw_sect
= &dwo_sections
->types
.back ();
9265 if (dw_sect
!= nullptr)
9267 dw_sect
->s
.section
= sectp
;
9268 dw_sect
->size
= bfd_section_size (sectp
);
9269 dw_sect
->read (objfile
);
9273 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
9274 by PER_CU. This is for the non-DWP case.
9275 The result is NULL if DWO_NAME can't be found. */
9277 static struct dwo_file
*
9278 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
9279 const char *comp_dir
)
9281 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9283 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
9286 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
9291 dwo_file_up
dwo_file (new struct dwo_file
);
9292 dwo_file
->dwo_name
= dwo_name
;
9293 dwo_file
->comp_dir
= comp_dir
;
9294 dwo_file
->dbfd
= std::move (dbfd
);
9296 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
9297 dwarf2_locate_dwo_sections (per_objfile
->objfile
, dwo_file
->dbfd
.get (),
9298 sec
, &dwo_file
->sections
);
9300 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
9303 if (cu
->per_cu
->version () < 5)
9305 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
9306 dwo_file
->sections
.types
, dwo_file
->tus
);
9310 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
9311 &dwo_file
->sections
.info
, dwo_file
->tus
,
9312 rcuh_kind::COMPILE
);
9315 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
9317 return dwo_file
.release ();
9320 /* This function is mapped across the sections and remembers the offset and
9321 size of each of the DWP debugging sections common to version 1 and 2 that
9322 we are interested in. */
9325 dwarf2_locate_common_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
9326 asection
*sectp
, dwp_file
*dwp_file
)
9328 const struct dwop_section_names
*names
= &dwop_section_names
;
9329 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9331 /* Record the ELF section number for later lookup: this is what the
9332 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9333 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9334 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9336 /* Look for specific sections that we need. */
9337 struct dwarf2_section_info
*dw_sect
= nullptr;
9338 if (names
->str_dwo
.matches (sectp
->name
))
9339 dw_sect
= &dwp_file
->sections
.str
;
9340 else if (names
->cu_index
.matches (sectp
->name
))
9341 dw_sect
= &dwp_file
->sections
.cu_index
;
9342 else if (names
->tu_index
.matches (sectp
->name
))
9343 dw_sect
= &dwp_file
->sections
.tu_index
;
9345 if (dw_sect
!= nullptr)
9347 dw_sect
->s
.section
= sectp
;
9348 dw_sect
->size
= bfd_section_size (sectp
);
9349 dw_sect
->read (objfile
);
9353 /* This function is mapped across the sections and remembers the offset and
9354 size of each of the DWP version 2 debugging sections that we are interested
9355 in. This is split into a separate function because we don't know if we
9356 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
9359 dwarf2_locate_v2_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
9360 asection
*sectp
, void *dwp_file_ptr
)
9362 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
9363 const struct dwop_section_names
*names
= &dwop_section_names
;
9364 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9366 /* Record the ELF section number for later lookup: this is what the
9367 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9368 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9369 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9371 /* Look for specific sections that we need. */
9372 struct dwarf2_section_info
*dw_sect
= nullptr;
9373 if (names
->abbrev_dwo
.matches (sectp
->name
))
9374 dw_sect
= &dwp_file
->sections
.abbrev
;
9375 else if (names
->info_dwo
.matches (sectp
->name
))
9376 dw_sect
= &dwp_file
->sections
.info
;
9377 else if (names
->line_dwo
.matches (sectp
->name
))
9378 dw_sect
= &dwp_file
->sections
.line
;
9379 else if (names
->loc_dwo
.matches (sectp
->name
))
9380 dw_sect
= &dwp_file
->sections
.loc
;
9381 else if (names
->macinfo_dwo
.matches (sectp
->name
))
9382 dw_sect
= &dwp_file
->sections
.macinfo
;
9383 else if (names
->macro_dwo
.matches (sectp
->name
))
9384 dw_sect
= &dwp_file
->sections
.macro
;
9385 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
9386 dw_sect
= &dwp_file
->sections
.str_offsets
;
9387 else if (names
->types_dwo
.matches (sectp
->name
))
9388 dw_sect
= &dwp_file
->sections
.types
;
9390 if (dw_sect
!= nullptr)
9392 dw_sect
->s
.section
= sectp
;
9393 dw_sect
->size
= bfd_section_size (sectp
);
9394 dw_sect
->read (objfile
);
9398 /* This function is mapped across the sections and remembers the offset and
9399 size of each of the DWP version 5 debugging sections that we are interested
9400 in. This is split into a separate function because we don't know if we
9401 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
9404 dwarf2_locate_v5_dwp_sections (struct objfile
*objfile
, bfd
*abfd
,
9405 asection
*sectp
, void *dwp_file_ptr
)
9407 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
9408 const struct dwop_section_names
*names
= &dwop_section_names
;
9409 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
9411 /* Record the ELF section number for later lookup: this is what the
9412 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
9413 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
9414 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
9416 /* Look for specific sections that we need. */
9417 struct dwarf2_section_info
*dw_sect
= nullptr;
9418 if (names
->abbrev_dwo
.matches (sectp
->name
))
9419 dw_sect
= &dwp_file
->sections
.abbrev
;
9420 else if (names
->info_dwo
.matches (sectp
->name
))
9421 dw_sect
= &dwp_file
->sections
.info
;
9422 else if (names
->line_dwo
.matches (sectp
->name
))
9423 dw_sect
= &dwp_file
->sections
.line
;
9424 else if (names
->loclists_dwo
.matches (sectp
->name
))
9425 dw_sect
= &dwp_file
->sections
.loclists
;
9426 else if (names
->macro_dwo
.matches (sectp
->name
))
9427 dw_sect
= &dwp_file
->sections
.macro
;
9428 else if (names
->rnglists_dwo
.matches (sectp
->name
))
9429 dw_sect
= &dwp_file
->sections
.rnglists
;
9430 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
9431 dw_sect
= &dwp_file
->sections
.str_offsets
;
9433 if (dw_sect
!= nullptr)
9435 dw_sect
->s
.section
= sectp
;
9436 dw_sect
->size
= bfd_section_size (sectp
);
9437 dw_sect
->read (objfile
);
9441 /* Hash function for dwp_file loaded CUs/TUs. */
9444 hash_dwp_loaded_cutus (const void *item
)
9446 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
9448 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9449 return dwo_unit
->signature
;
9452 /* Equality function for dwp_file loaded CUs/TUs. */
9455 eq_dwp_loaded_cutus (const void *a
, const void *b
)
9457 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
9458 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
9460 return dua
->signature
== dub
->signature
;
9463 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9466 allocate_dwp_loaded_cutus_table ()
9468 return htab_up (htab_create_alloc (3,
9469 hash_dwp_loaded_cutus
,
9470 eq_dwp_loaded_cutus
,
9471 NULL
, xcalloc
, xfree
));
9474 /* Try to open DWP file FILE_NAME.
9475 The result is the bfd handle of the file.
9476 If there is a problem finding or opening the file, return NULL.
9477 Upon success, the canonicalized path of the file is stored in the bfd,
9478 same as symfile_bfd_open. */
9480 static gdb_bfd_ref_ptr
9481 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
9483 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
9489 /* Work around upstream bug 15652.
9490 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
9491 [Whether that's a "bug" is debatable, but it is getting in our way.]
9492 We have no real idea where the dwp file is, because gdb's realpath-ing
9493 of the executable's path may have discarded the needed info.
9494 [IWBN if the dwp file name was recorded in the executable, akin to
9495 .gnu_debuglink, but that doesn't exist yet.]
9496 Strip the directory from FILE_NAME and search again. */
9497 if (!debug_file_directory
.empty ())
9499 /* Don't implicitly search the current directory here.
9500 If the user wants to search "." to handle this case,
9501 it must be added to debug-file-directory. */
9502 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
9510 /* Initialize the use of the DWP file for the current objfile.
9511 By convention the name of the DWP file is ${objfile}.dwp.
9512 The result is NULL if it can't be found. */
9514 static std::unique_ptr
<struct dwp_file
>
9515 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
9517 struct objfile
*objfile
= per_objfile
->objfile
;
9519 /* Try to find first .dwp for the binary file before any symbolic links
9522 /* If the objfile is a debug file, find the name of the real binary
9523 file and get the name of dwp file from there. */
9524 std::string dwp_name
;
9525 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
9527 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
9528 const char *backlink_basename
= lbasename (backlink
->original_name
);
9530 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
9533 dwp_name
= objfile
->original_name
;
9537 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
9539 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
9541 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
9542 dwp_name
= objfile_name (objfile
);
9544 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
9549 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
9551 return std::unique_ptr
<dwp_file
> ();
9554 const char *name
= bfd_get_filename (dbfd
.get ());
9555 std::unique_ptr
<struct dwp_file
> dwp_file
9556 (new struct dwp_file (name
, std::move (dbfd
)));
9558 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
9559 dwp_file
->elf_sections
=
9560 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
9561 dwp_file
->num_sections
, asection
*);
9563 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
9564 dwarf2_locate_common_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
9567 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
9569 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
9571 /* The DWP file version is stored in the hash table. Oh well. */
9572 if (dwp_file
->cus
&& dwp_file
->tus
9573 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
9575 /* Technically speaking, we should try to limp along, but this is
9576 pretty bizarre. We use pulongest here because that's the established
9577 portability solution (e.g, we cannot use %u for uint32_t). */
9578 error (_("Dwarf Error: DWP file CU version %s doesn't match"
9579 " TU version %s [in DWP file %s]"),
9580 pulongest (dwp_file
->cus
->version
),
9581 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
9585 dwp_file
->version
= dwp_file
->cus
->version
;
9586 else if (dwp_file
->tus
)
9587 dwp_file
->version
= dwp_file
->tus
->version
;
9589 dwp_file
->version
= 2;
9591 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
9593 if (dwp_file
->version
== 2)
9594 dwarf2_locate_v2_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
9597 dwarf2_locate_v5_dwp_sections (objfile
, dwp_file
->dbfd
.get (), sec
,
9601 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
9602 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
9604 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
9605 dwarf_read_debug_printf (" %s CUs, %s TUs",
9606 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
9607 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
9612 /* Wrapper around open_and_init_dwp_file, only open it once. */
9614 static struct dwp_file
*
9615 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
9617 if (!per_objfile
->per_bfd
->dwp_checked
)
9619 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
9620 per_objfile
->per_bfd
->dwp_checked
= 1;
9622 return per_objfile
->per_bfd
->dwp_file
.get ();
9625 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9626 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9627 or in the DWP file for the objfile, referenced by THIS_UNIT.
9628 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9629 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9631 This is called, for example, when wanting to read a variable with a
9632 complex location. Therefore we don't want to do file i/o for every call.
9633 Therefore we don't want to look for a DWO file on every call.
9634 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9635 then we check if we've already seen DWO_NAME, and only THEN do we check
9638 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9639 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9641 static struct dwo_unit
*
9642 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
9643 ULONGEST signature
, int is_debug_types
)
9645 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9646 struct objfile
*objfile
= per_objfile
->objfile
;
9647 const char *kind
= is_debug_types
? "TU" : "CU";
9648 void **dwo_file_slot
;
9649 struct dwo_file
*dwo_file
;
9650 struct dwp_file
*dwp_file
;
9652 /* First see if there's a DWP file.
9653 If we have a DWP file but didn't find the DWO inside it, don't
9654 look for the original DWO file. It makes gdb behave differently
9655 depending on whether one is debugging in the build tree. */
9657 dwp_file
= get_dwp_file (per_objfile
);
9658 if (dwp_file
!= NULL
)
9660 const struct dwp_hash_table
*dwp_htab
=
9661 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9663 if (dwp_htab
!= NULL
)
9665 struct dwo_unit
*dwo_cutu
=
9666 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
9669 if (dwo_cutu
!= NULL
)
9671 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
9672 kind
, hex_string (signature
),
9673 host_address_to_string (dwo_cutu
));
9681 /* No DWP file, look for the DWO file. */
9683 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
9684 if (*dwo_file_slot
== NULL
)
9686 /* Read in the file and build a table of the CUs/TUs it contains. */
9687 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
9689 /* NOTE: This will be NULL if unable to open the file. */
9690 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
9692 if (dwo_file
!= NULL
)
9694 struct dwo_unit
*dwo_cutu
= NULL
;
9696 if (is_debug_types
&& dwo_file
->tus
)
9698 struct dwo_unit find_dwo_cutu
;
9700 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9701 find_dwo_cutu
.signature
= signature
;
9703 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
9706 else if (!is_debug_types
&& dwo_file
->cus
)
9708 struct dwo_unit find_dwo_cutu
;
9710 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9711 find_dwo_cutu
.signature
= signature
;
9712 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
9716 if (dwo_cutu
!= NULL
)
9718 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
9719 kind
, dwo_name
, hex_string (signature
),
9720 host_address_to_string (dwo_cutu
));
9727 /* We didn't find it. This could mean a dwo_id mismatch, or
9728 someone deleted the DWO/DWP file, or the search path isn't set up
9729 correctly to find the file. */
9731 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
9732 kind
, dwo_name
, hex_string (signature
));
9734 /* This is a warning and not a complaint because it can be caused by
9735 pilot error (e.g., user accidentally deleting the DWO). */
9737 /* Print the name of the DWP file if we looked there, helps the user
9738 better diagnose the problem. */
9739 std::string dwp_text
;
9741 if (dwp_file
!= NULL
)
9742 dwp_text
= string_printf (" [in DWP file %s]",
9743 lbasename (dwp_file
->name
));
9745 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
9747 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
9748 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
9753 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9754 See lookup_dwo_cutu_unit for details. */
9756 static struct dwo_unit
*
9757 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
9760 gdb_assert (!cu
->per_cu
->is_debug_types
);
9762 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
9765 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9766 See lookup_dwo_cutu_unit for details. */
9768 static struct dwo_unit
*
9769 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
9771 gdb_assert (cu
->per_cu
->is_debug_types
);
9773 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
9775 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
9778 /* Traversal function for queue_and_load_all_dwo_tus. */
9781 queue_and_load_dwo_tu (void **slot
, void *info
)
9783 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
9784 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
9785 ULONGEST signature
= dwo_unit
->signature
;
9786 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
9788 if (sig_type
!= NULL
)
9790 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
9791 a real dependency of PER_CU on SIG_TYPE. That is detected later
9792 while processing PER_CU. */
9793 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
9795 load_full_type_unit (sig_type
, cu
->per_objfile
);
9796 cu
->per_cu
->imported_symtabs_push (sig_type
);
9802 /* Queue all TUs contained in the DWO of CU to be read in.
9803 The DWO may have the only definition of the type, though it may not be
9804 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
9805 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
9808 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
9810 struct dwo_unit
*dwo_unit
;
9811 struct dwo_file
*dwo_file
;
9813 gdb_assert (cu
!= nullptr);
9814 gdb_assert (!cu
->per_cu
->is_debug_types
);
9815 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
9817 dwo_unit
= cu
->dwo_unit
;
9818 gdb_assert (dwo_unit
!= NULL
);
9820 dwo_file
= dwo_unit
->dwo_file
;
9821 if (dwo_file
->tus
!= NULL
)
9822 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
9825 /* Read in various DIEs. */
9827 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9828 Inherit only the children of the DW_AT_abstract_origin DIE not being
9829 already referenced by DW_AT_abstract_origin from the children of the
9833 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9835 attribute
*attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9836 if (attr
== nullptr)
9839 /* Note that following die references may follow to a die in a
9841 dwarf2_cu
*origin_cu
= cu
;
9843 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9844 die_info
*origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9846 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9848 struct pending
**origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9849 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9851 if (die
->tag
!= origin_die
->tag
9852 && !(die
->tag
== DW_TAG_inlined_subroutine
9853 && origin_die
->tag
== DW_TAG_subprogram
))
9854 complaint (_("DIE %s and its abstract origin %s have different tags"),
9855 sect_offset_str (die
->sect_off
),
9856 sect_offset_str (origin_die
->sect_off
));
9858 /* Find if the concrete and abstract trees are structurally the
9859 same. This is a shallow traversal and it is not bullet-proof;
9860 the compiler can trick the debugger into believing that the trees
9861 are isomorphic, whereas they actually are not. However, the
9862 likelyhood of this happening is pretty low, and a full-fledged
9863 check would be an overkill. */
9864 bool are_isomorphic
= true;
9865 die_info
*concrete_child
= die
->child
;
9866 die_info
*abstract_child
= origin_die
->child
;
9867 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
9869 if (concrete_child
== nullptr
9870 || abstract_child
== nullptr
9871 || concrete_child
->tag
!= abstract_child
->tag
)
9873 are_isomorphic
= false;
9877 concrete_child
= concrete_child
->sibling
;
9878 abstract_child
= abstract_child
->sibling
;
9881 /* Walk the origin's children in parallel to the concrete children.
9882 This helps match an origin child in case the debug info misses
9883 DW_AT_abstract_origin attributes. Keep in mind that the abstract
9884 origin tree may not have the same tree structure as the concrete
9886 die_info
*corresponding_abstract_child
9887 = are_isomorphic
? origin_die
->child
: nullptr;
9889 std::vector
<sect_offset
> offsets
;
9891 for (die_info
*child_die
= die
->child
;
9892 child_die
&& child_die
->tag
;
9893 child_die
= child_die
->sibling
)
9895 /* We are trying to process concrete instance entries:
9896 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
9897 it's not relevant to our analysis here. i.e. detecting DIEs that are
9898 present in the abstract instance but not referenced in the concrete
9900 if (child_die
->tag
== DW_TAG_call_site
9901 || child_die
->tag
== DW_TAG_GNU_call_site
)
9904 corresponding_abstract_child
9905 = corresponding_abstract_child
->sibling
;
9909 /* For each CHILD_DIE, find the corresponding child of
9910 ORIGIN_DIE. If there is more than one layer of
9911 DW_AT_abstract_origin, follow them all; there shouldn't be,
9912 but GCC versions at least through 4.4 generate this (GCC PR
9914 die_info
*child_origin_die
= child_die
;
9915 dwarf2_cu
*child_origin_cu
= cu
;
9918 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9920 if (attr
== nullptr)
9923 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9927 /* If missing DW_AT_abstract_origin, try the corresponding child
9928 of the origin. Clang emits such lexical scopes. */
9929 if (child_origin_die
== child_die
9930 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
9932 && child_die
->tag
== DW_TAG_lexical_block
)
9933 child_origin_die
= corresponding_abstract_child
;
9935 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9936 counterpart may exist. */
9937 if (child_origin_die
!= child_die
)
9939 if (child_die
->tag
!= child_origin_die
->tag
9940 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9941 && child_origin_die
->tag
== DW_TAG_subprogram
))
9942 complaint (_("Child DIE %s and its abstract origin %s have "
9944 sect_offset_str (child_die
->sect_off
),
9945 sect_offset_str (child_origin_die
->sect_off
));
9946 if (child_origin_die
->parent
!= origin_die
)
9947 complaint (_("Child DIE %s and its abstract origin %s have "
9948 "different parents"),
9949 sect_offset_str (child_die
->sect_off
),
9950 sect_offset_str (child_origin_die
->sect_off
));
9952 offsets
.push_back (child_origin_die
->sect_off
);
9956 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
9959 if (!offsets
.empty ())
9961 std::sort (offsets
.begin (), offsets
.end ());
9963 for (auto offsets_it
= offsets
.begin () + 1;
9964 offsets_it
< offsets
.end ();
9966 if (*(offsets_it
- 1) == *offsets_it
)
9967 complaint (_("Multiple children of DIE %s refer "
9968 "to DIE %s as their abstract origin"),
9969 sect_offset_str (die
->sect_off
),
9970 sect_offset_str (*offsets_it
));
9973 auto offsets_it
= offsets
.begin ();
9974 die_info
*origin_child_die
= origin_die
->child
;
9975 while (origin_child_die
!= nullptr && origin_child_die
->tag
!= 0)
9977 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9978 while (offsets_it
< offsets
.end ()
9979 && *offsets_it
< origin_child_die
->sect_off
)
9982 if (offsets_it
== offsets
.end ()
9983 || *offsets_it
> origin_child_die
->sect_off
)
9985 /* Found that ORIGIN_CHILD_DIE is really not referenced.
9986 Check whether we're already processing ORIGIN_CHILD_DIE.
9987 This can happen with mutually referenced abstract_origins.
9989 if (!origin_child_die
->in_process
)
9990 process_die (origin_child_die
, origin_cu
);
9993 origin_child_die
= origin_child_die
->sibling
;
9996 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9998 if (cu
!= origin_cu
)
9999 compute_delayed_physnames (origin_cu
);
10003 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10005 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10006 struct gdbarch
*gdbarch
= objfile
->arch ();
10007 struct context_stack
*newobj
;
10010 struct die_info
*child_die
;
10011 struct attribute
*attr
, *call_line
, *call_file
;
10013 CORE_ADDR baseaddr
;
10014 struct block
*block
;
10015 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10016 std::vector
<struct symbol
*> template_args
;
10017 struct template_symbol
*templ_func
= NULL
;
10021 /* If we do not have call site information, we can't show the
10022 caller of this inlined function. That's too confusing, so
10023 only use the scope for local variables. */
10024 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
10025 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
10026 if (call_line
== NULL
|| call_file
== NULL
)
10028 read_lexical_block_scope (die
, cu
);
10033 baseaddr
= objfile
->text_section_offset ();
10035 name
= dwarf2_name (die
, cu
);
10036 if (name
== nullptr)
10037 name
= dw2_linkage_name (die
, cu
);
10039 /* Ignore functions with missing or empty names. These are actually
10040 illegal according to the DWARF standard. */
10043 complaint (_("missing name for subprogram DIE at %s"),
10044 sect_offset_str (die
->sect_off
));
10048 /* Ignore functions with missing or invalid low and high pc attributes. */
10049 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr)
10050 <= PC_BOUNDS_INVALID
)
10052 if (have_complaint ())
10054 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10055 bool external_p
= attr
!= nullptr && attr
->as_boolean ();
10056 attr
= dwarf2_attr (die
, DW_AT_inline
, cu
);
10059 && attr
->is_nonnegative ()
10060 && (attr
->as_nonnegative () == DW_INL_inlined
10061 || attr
->as_nonnegative () == DW_INL_declared_inlined
));
10062 attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
10063 bool decl_p
= attr
!= nullptr && attr
->as_boolean ();
10064 if (!external_p
&& !inlined_p
&& !decl_p
)
10065 complaint (_("cannot get low and high bounds "
10066 "for subprogram DIE at %s"),
10067 sect_offset_str (die
->sect_off
));
10072 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10073 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10075 /* If we have any template arguments, then we must allocate a
10076 different sort of symbol. */
10077 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
10079 if (child_die
->tag
== DW_TAG_template_type_param
10080 || child_die
->tag
== DW_TAG_template_value_param
)
10082 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
10083 templ_func
->subclass
= SYMBOL_TEMPLATE
;
10088 gdb_assert (cu
->get_builder () != nullptr);
10089 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
10090 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
10091 (struct symbol
*) templ_func
);
10093 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
10094 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
10097 /* If there is a location expression for DW_AT_frame_base, record
10099 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
10100 if (attr
!= nullptr)
10101 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
10103 /* If there is a location for the static link, record it. */
10104 newobj
->static_link
= NULL
;
10105 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
10106 if (attr
!= nullptr)
10108 newobj
->static_link
10109 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
10110 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
10114 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
10116 if (die
->child
!= NULL
)
10118 child_die
= die
->child
;
10119 while (child_die
&& child_die
->tag
)
10121 if (child_die
->tag
== DW_TAG_template_type_param
10122 || child_die
->tag
== DW_TAG_template_value_param
)
10124 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10127 template_args
.push_back (arg
);
10130 process_die (child_die
, cu
);
10131 child_die
= child_die
->sibling
;
10135 inherit_abstract_dies (die
, cu
);
10137 /* If we have a DW_AT_specification, we might need to import using
10138 directives from the context of the specification DIE. See the
10139 comment in determine_prefix. */
10140 if (cu
->lang () == language_cplus
10141 && dwarf2_attr (die
, DW_AT_specification
, cu
))
10143 struct dwarf2_cu
*spec_cu
= cu
;
10144 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
10148 child_die
= spec_die
->child
;
10149 while (child_die
&& child_die
->tag
)
10151 if (child_die
->tag
== DW_TAG_imported_module
)
10152 process_die (child_die
, spec_cu
);
10153 child_die
= child_die
->sibling
;
10156 /* In some cases, GCC generates specification DIEs that
10157 themselves contain DW_AT_specification attributes. */
10158 spec_die
= die_specification (spec_die
, &spec_cu
);
10162 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
10163 /* Make a block for the local symbols within. */
10164 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
10165 cstk
.static_link
, lowpc
, highpc
);
10167 /* For C++, set the block's scope. */
10168 if ((cu
->lang () == language_cplus
10169 || cu
->lang () == language_fortran
10170 || cu
->lang () == language_d
10171 || cu
->lang () == language_rust
)
10172 && cu
->processing_has_namespace_info
)
10173 block
->set_scope (determine_prefix (die
, cu
),
10174 &objfile
->objfile_obstack
);
10176 /* If we have address ranges, record them. */
10177 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10179 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
10181 /* Attach template arguments to function. */
10182 if (!template_args
.empty ())
10184 gdb_assert (templ_func
!= NULL
);
10186 templ_func
->n_template_arguments
= template_args
.size ();
10187 templ_func
->template_arguments
10188 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
10189 templ_func
->n_template_arguments
);
10190 memcpy (templ_func
->template_arguments
,
10191 template_args
.data (),
10192 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
10194 /* Make sure that the symtab is set on the new symbols. Even
10195 though they don't appear in this symtab directly, other parts
10196 of gdb assume that symbols do, and this is reasonably
10198 for (symbol
*sym
: template_args
)
10199 sym
->set_symtab (templ_func
->symtab ());
10202 /* In C++, we can have functions nested inside functions (e.g., when
10203 a function declares a class that has methods). This means that
10204 when we finish processing a function scope, we may need to go
10205 back to building a containing block's symbol lists. */
10206 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
10207 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
10209 /* If we've finished processing a top-level function, subsequent
10210 symbols go in the file symbol list. */
10211 if (cu
->get_builder ()->outermost_context_p ())
10212 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
10215 /* Process all the DIES contained within a lexical block scope. Start
10216 a new scope, process the dies, and then close the scope. */
10219 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10221 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10222 struct gdbarch
*gdbarch
= objfile
->arch ();
10223 CORE_ADDR lowpc
, highpc
;
10224 struct die_info
*child_die
;
10225 CORE_ADDR baseaddr
;
10227 baseaddr
= objfile
->text_section_offset ();
10229 /* Ignore blocks with missing or invalid low and high pc attributes. */
10230 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
10231 as multiple lexical blocks? Handling children in a sane way would
10232 be nasty. Might be easier to properly extend generic blocks to
10233 describe ranges. */
10234 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, nullptr, nullptr))
10236 case PC_BOUNDS_NOT_PRESENT
:
10237 /* DW_TAG_lexical_block has no attributes, process its children as if
10238 there was no wrapping by that DW_TAG_lexical_block.
10239 GCC does no longer produces such DWARF since GCC r224161. */
10240 for (child_die
= die
->child
;
10241 child_die
!= NULL
&& child_die
->tag
;
10242 child_die
= child_die
->sibling
)
10244 /* We might already be processing this DIE. This can happen
10245 in an unusual circumstance -- where a subroutine A
10246 appears lexically in another subroutine B, but A actually
10247 inlines B. The recursion is broken here, rather than in
10248 inherit_abstract_dies, because it seems better to simply
10249 drop concrete children here. */
10250 if (!child_die
->in_process
)
10251 process_die (child_die
, cu
);
10254 case PC_BOUNDS_INVALID
:
10257 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10258 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10260 cu
->get_builder ()->push_context (0, lowpc
);
10261 if (die
->child
!= NULL
)
10263 child_die
= die
->child
;
10264 while (child_die
&& child_die
->tag
)
10266 process_die (child_die
, cu
);
10267 child_die
= child_die
->sibling
;
10270 inherit_abstract_dies (die
, cu
);
10271 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
10273 if (*cu
->get_builder ()->get_local_symbols () != NULL
10274 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
10276 struct block
*block
10277 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
10278 cstk
.start_addr
, highpc
);
10280 /* Note that recording ranges after traversing children, as we
10281 do here, means that recording a parent's ranges entails
10282 walking across all its children's ranges as they appear in
10283 the address map, which is quadratic behavior.
10285 It would be nicer to record the parent's ranges before
10286 traversing its children, simply overriding whatever you find
10287 there. But since we don't even decide whether to create a
10288 block until after we've traversed its children, that's hard
10290 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
10292 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
10293 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
10296 static void dwarf2_ranges_read_low_addrs (unsigned offset
,
10297 struct dwarf2_cu
*cu
,
10299 std::vector
<CORE_ADDR
> &result
);
10301 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
10304 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10306 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10307 struct objfile
*objfile
= per_objfile
->objfile
;
10308 struct gdbarch
*gdbarch
= objfile
->arch ();
10309 CORE_ADDR pc
, baseaddr
;
10310 struct attribute
*attr
;
10313 struct die_info
*child_die
;
10315 baseaddr
= objfile
->text_section_offset ();
10317 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
10320 /* This was a pre-DWARF-5 GNU extension alias
10321 for DW_AT_call_return_pc. */
10322 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10326 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
10327 "DIE %s [in module %s]"),
10328 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10331 pc
= attr
->as_address () + baseaddr
;
10332 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
10335 if (cu
->call_site_htab
== NULL
)
10336 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
10337 call_site::eq
, NULL
,
10338 &objfile
->objfile_obstack
,
10339 hashtab_obstack_allocate
, NULL
);
10340 struct call_site
call_site_local (pc
, nullptr, nullptr);
10341 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
10344 complaint (_("Duplicate PC %s for DW_TAG_call_site "
10345 "DIE %s [in module %s]"),
10346 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
10347 objfile_name (objfile
));
10351 /* Count parameters at the caller. */
10354 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10355 child_die
= child_die
->sibling
)
10357 if (child_die
->tag
!= DW_TAG_call_site_parameter
10358 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
10360 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
10361 "DW_TAG_call_site child DIE %s [in module %s]"),
10362 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
10363 objfile_name (objfile
));
10370 struct call_site
*call_site
10371 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
10373 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
10374 struct call_site (pc
, cu
->per_cu
, per_objfile
);
10377 /* We never call the destructor of call_site, so we must ensure it is
10378 trivially destructible. */
10379 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
10381 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
10382 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
10384 struct die_info
*func_die
;
10386 /* Skip also over DW_TAG_inlined_subroutine. */
10387 for (func_die
= die
->parent
;
10388 func_die
&& func_die
->tag
!= DW_TAG_subprogram
10389 && func_die
->tag
!= DW_TAG_subroutine_type
;
10390 func_die
= func_die
->parent
);
10392 /* DW_AT_call_all_calls is a superset
10393 of DW_AT_call_all_tail_calls. */
10395 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
10396 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
10397 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
10398 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
10400 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
10401 not complete. But keep CALL_SITE for look ups via call_site_htab,
10402 both the initial caller containing the real return address PC and
10403 the final callee containing the current PC of a chain of tail
10404 calls do not need to have the tail call list complete. But any
10405 function candidate for a virtual tail call frame searched via
10406 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
10407 determined unambiguously. */
10411 struct type
*func_type
= NULL
;
10414 func_type
= get_die_type (func_die
, cu
);
10415 if (func_type
!= NULL
)
10417 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
10419 /* Enlist this call site to the function. */
10420 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
10421 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
10424 complaint (_("Cannot find function owning DW_TAG_call_site "
10425 "DIE %s [in module %s]"),
10426 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10430 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
10432 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
10434 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
10437 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
10438 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
10441 call_site
->target
.set_loc_dwarf_block (nullptr);
10442 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
10443 /* Keep NULL DWARF_BLOCK. */;
10444 else if (attr
->form_is_block ())
10446 struct dwarf2_locexpr_baton
*dlbaton
;
10447 struct dwarf_block
*block
= attr
->as_block ();
10449 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
10450 dlbaton
->data
= block
->data
;
10451 dlbaton
->size
= block
->size
;
10452 dlbaton
->per_objfile
= per_objfile
;
10453 dlbaton
->per_cu
= cu
->per_cu
;
10455 call_site
->target
.set_loc_dwarf_block (dlbaton
);
10457 else if (attr
->form_is_ref ())
10459 struct dwarf2_cu
*target_cu
= cu
;
10460 struct die_info
*target_die
;
10462 target_die
= follow_die_ref (die
, attr
, &target_cu
);
10463 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
10465 struct attribute
*ranges_attr
10466 = dwarf2_attr (target_die
, DW_AT_ranges
, target_cu
);
10468 if (die_is_declaration (target_die
, target_cu
))
10470 const char *target_physname
;
10472 /* Prefer the mangled name; otherwise compute the demangled one. */
10473 target_physname
= dw2_linkage_name (target_die
, target_cu
);
10474 if (target_physname
== NULL
)
10475 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
10476 if (target_physname
== NULL
)
10477 complaint (_("DW_AT_call_target target DIE has invalid "
10478 "physname, for referencing DIE %s [in module %s]"),
10479 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10481 call_site
->target
.set_loc_physname (target_physname
);
10483 else if (ranges_attr
!= nullptr && ranges_attr
->form_is_unsigned ())
10485 ULONGEST ranges_offset
= (ranges_attr
->as_unsigned ()
10486 + target_cu
->gnu_ranges_base
);
10487 std::vector
<CORE_ADDR
> addresses
;
10488 dwarf2_ranges_read_low_addrs (ranges_offset
, target_cu
,
10489 target_die
->tag
, addresses
);
10490 CORE_ADDR
*saved
= XOBNEWVAR (&objfile
->objfile_obstack
, CORE_ADDR
,
10491 addresses
.size ());
10492 std::copy (addresses
.begin (), addresses
.end (), saved
);
10493 call_site
->target
.set_loc_array (addresses
.size (), saved
);
10499 /* DW_AT_entry_pc should be preferred. */
10500 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
,
10502 <= PC_BOUNDS_INVALID
)
10503 complaint (_("DW_AT_call_target target DIE has invalid "
10504 "low pc, for referencing DIE %s [in module %s]"),
10505 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10508 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
10510 call_site
->target
.set_loc_physaddr (lowpc
);
10515 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
10516 "block nor reference, for DIE %s [in module %s]"),
10517 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
10519 for (child_die
= die
->child
;
10520 child_die
&& child_die
->tag
;
10521 child_die
= child_die
->sibling
)
10523 struct call_site_parameter
*parameter
;
10524 struct attribute
*loc
, *origin
;
10526 if (child_die
->tag
!= DW_TAG_call_site_parameter
10527 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
10529 /* Already printed the complaint above. */
10533 gdb_assert (call_site
->parameter_count
< nparams
);
10534 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
10536 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
10537 specifies DW_TAG_formal_parameter. Value of the data assumed for the
10538 register is contained in DW_AT_call_value. */
10540 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
10541 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
10542 if (origin
== NULL
)
10544 /* This was a pre-DWARF-5 GNU extension alias
10545 for DW_AT_call_parameter. */
10546 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
10548 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
10550 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
10552 sect_offset sect_off
= origin
->get_ref_die_offset ();
10553 if (!cu
->header
.offset_in_cu_p (sect_off
))
10555 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
10556 binding can be done only inside one CU. Such referenced DIE
10557 therefore cannot be even moved to DW_TAG_partial_unit. */
10558 complaint (_("DW_AT_call_parameter offset is not in CU for "
10559 "DW_TAG_call_site child DIE %s [in module %s]"),
10560 sect_offset_str (child_die
->sect_off
),
10561 objfile_name (objfile
));
10564 parameter
->u
.param_cu_off
10565 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
10567 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
10569 complaint (_("No DW_FORM_block* DW_AT_location for "
10570 "DW_TAG_call_site child DIE %s [in module %s]"),
10571 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
10576 struct dwarf_block
*block
= loc
->as_block ();
10578 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
10579 (block
->data
, &block
->data
[block
->size
]);
10580 if (parameter
->u
.dwarf_reg
!= -1)
10581 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
10582 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
10583 &block
->data
[block
->size
],
10584 ¶meter
->u
.fb_offset
))
10585 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
10588 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
10589 "for DW_FORM_block* DW_AT_location is supported for "
10590 "DW_TAG_call_site child DIE %s "
10592 sect_offset_str (child_die
->sect_off
),
10593 objfile_name (objfile
));
10598 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
10600 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
10601 if (attr
== NULL
|| !attr
->form_is_block ())
10603 complaint (_("No DW_FORM_block* DW_AT_call_value for "
10604 "DW_TAG_call_site child DIE %s [in module %s]"),
10605 sect_offset_str (child_die
->sect_off
),
10606 objfile_name (objfile
));
10610 struct dwarf_block
*block
= attr
->as_block ();
10611 parameter
->value
= block
->data
;
10612 parameter
->value_size
= block
->size
;
10614 /* Parameters are not pre-cleared by memset above. */
10615 parameter
->data_value
= NULL
;
10616 parameter
->data_value_size
= 0;
10617 call_site
->parameter_count
++;
10619 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
10621 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
10622 if (attr
!= nullptr)
10624 if (!attr
->form_is_block ())
10625 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
10626 "DW_TAG_call_site child DIE %s [in module %s]"),
10627 sect_offset_str (child_die
->sect_off
),
10628 objfile_name (objfile
));
10631 block
= attr
->as_block ();
10632 parameter
->data_value
= block
->data
;
10633 parameter
->data_value_size
= block
->size
;
10639 /* Helper function for read_variable. If DIE represents a virtual
10640 table, then return the type of the concrete object that is
10641 associated with the virtual table. Otherwise, return NULL. */
10643 static struct type
*
10644 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10646 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
10650 /* Find the type DIE. */
10651 struct die_info
*type_die
= NULL
;
10652 struct dwarf2_cu
*type_cu
= cu
;
10654 if (attr
->form_is_ref ())
10655 type_die
= follow_die_ref (die
, attr
, &type_cu
);
10656 if (type_die
== NULL
)
10659 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
10661 return die_containing_type (type_die
, type_cu
);
10664 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
10667 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
10669 struct rust_vtable_symbol
*storage
= NULL
;
10671 if (cu
->lang () == language_rust
)
10673 struct type
*containing_type
= rust_containing_type (die
, cu
);
10675 if (containing_type
!= NULL
)
10677 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10679 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
10680 storage
->concrete_type
= containing_type
;
10681 storage
->subclass
= SYMBOL_RUST_VTABLE
;
10685 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
10686 struct attribute
*abstract_origin
10687 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
10688 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
10689 if (res
== NULL
&& loc
&& abstract_origin
)
10691 /* We have a variable without a name, but with a location and an abstract
10692 origin. This may be a concrete instance of an abstract variable
10693 referenced from an DW_OP_GNU_variable_value, so save it to find it back
10695 struct dwarf2_cu
*origin_cu
= cu
;
10696 struct die_info
*origin_die
10697 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
10698 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10699 per_objfile
->per_bfd
->abstract_to_concrete
10700 [origin_die
->sect_off
].push_back (die
->sect_off
);
10704 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
10705 reading .debug_rnglists.
10706 Callback's type should be:
10707 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
10708 Return true if the attributes are present and valid, otherwise,
10711 template <typename Callback
>
10713 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
10714 dwarf_tag tag
, Callback
&&callback
)
10716 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10717 struct objfile
*objfile
= per_objfile
->objfile
;
10718 bfd
*obfd
= objfile
->obfd
.get ();
10719 /* Base address selection entry. */
10720 gdb::optional
<CORE_ADDR
> base
;
10721 const gdb_byte
*buffer
;
10722 bool overflow
= false;
10723 ULONGEST addr_index
;
10724 struct dwarf2_section_info
*rnglists_section
;
10726 base
= cu
->base_address
;
10727 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
10728 rnglists_section
->read (objfile
);
10730 if (offset
>= rnglists_section
->size
)
10732 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
10736 buffer
= rnglists_section
->buffer
+ offset
;
10740 /* Initialize it due to a false compiler warning. */
10741 CORE_ADDR range_beginning
= 0, range_end
= 0;
10742 const gdb_byte
*buf_end
= (rnglists_section
->buffer
10743 + rnglists_section
->size
);
10744 unsigned int bytes_read
;
10746 if (buffer
== buf_end
)
10751 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
10754 case DW_RLE_end_of_list
:
10756 case DW_RLE_base_address
:
10757 if (buffer
+ cu
->header
.addr_size
> buf_end
)
10762 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
10763 buffer
+= bytes_read
;
10765 case DW_RLE_base_addressx
:
10766 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10767 buffer
+= bytes_read
;
10768 base
= read_addr_index (cu
, addr_index
);
10770 case DW_RLE_start_length
:
10771 if (buffer
+ cu
->header
.addr_size
> buf_end
)
10776 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
10778 buffer
+= bytes_read
;
10779 range_end
= (range_beginning
10780 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
10781 buffer
+= bytes_read
;
10782 if (buffer
> buf_end
)
10788 case DW_RLE_startx_length
:
10789 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10790 buffer
+= bytes_read
;
10791 range_beginning
= read_addr_index (cu
, addr_index
);
10792 if (buffer
> buf_end
)
10797 range_end
= (range_beginning
10798 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
10799 buffer
+= bytes_read
;
10801 case DW_RLE_offset_pair
:
10802 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10803 buffer
+= bytes_read
;
10804 if (buffer
> buf_end
)
10809 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10810 buffer
+= bytes_read
;
10811 if (buffer
> buf_end
)
10817 case DW_RLE_start_end
:
10818 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
10823 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
10825 buffer
+= bytes_read
;
10826 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
10827 buffer
+= bytes_read
;
10829 case DW_RLE_startx_endx
:
10830 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10831 buffer
+= bytes_read
;
10832 range_beginning
= read_addr_index (cu
, addr_index
);
10833 if (buffer
> buf_end
)
10838 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
10839 buffer
+= bytes_read
;
10840 range_end
= read_addr_index (cu
, addr_index
);
10843 complaint (_("Invalid .debug_rnglists data (no base address)"));
10846 if (rlet
== DW_RLE_end_of_list
|| overflow
)
10848 if (rlet
== DW_RLE_base_address
)
10851 if (range_beginning
> range_end
)
10853 /* Inverted range entries are invalid. */
10854 complaint (_("Invalid .debug_rnglists data (inverted range)"));
10858 /* Empty range entries have no effect. */
10859 if (range_beginning
== range_end
)
10862 /* Only DW_RLE_offset_pair needs the base address added. */
10863 if (rlet
== DW_RLE_offset_pair
)
10865 if (!base
.has_value ())
10867 /* We have no valid base address for the DW_RLE_offset_pair. */
10868 complaint (_("Invalid .debug_rnglists data (no base address for "
10869 "DW_RLE_offset_pair)"));
10873 range_beginning
+= *base
;
10874 range_end
+= *base
;
10877 /* A not-uncommon case of bad debug info.
10878 Don't pollute the addrmap with bad data. */
10879 if (range_beginning
== 0
10880 && !per_objfile
->per_bfd
->has_section_at_zero
)
10882 complaint (_(".debug_rnglists entry has start address of zero"
10883 " [in module %s]"), objfile_name (objfile
));
10887 callback (range_beginning
, range_end
);
10892 complaint (_("Offset %d is not terminated "
10893 "for DW_AT_ranges attribute"),
10901 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
10902 Callback's type should be:
10903 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
10904 Return 1 if the attributes are present and valid, otherwise, return 0. */
10906 template <typename Callback
>
10908 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
10909 Callback
&&callback
)
10911 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10912 struct objfile
*objfile
= per_objfile
->objfile
;
10913 struct comp_unit_head
*cu_header
= &cu
->header
;
10914 bfd
*obfd
= objfile
->obfd
.get ();
10915 unsigned int addr_size
= cu_header
->addr_size
;
10916 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10917 /* Base address selection entry. */
10918 gdb::optional
<CORE_ADDR
> base
;
10919 unsigned int dummy
;
10920 const gdb_byte
*buffer
;
10922 if (cu_header
->version
>= 5)
10923 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
10925 base
= cu
->base_address
;
10927 per_objfile
->per_bfd
->ranges
.read (objfile
);
10928 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
10930 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
10934 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
10938 CORE_ADDR range_beginning
, range_end
;
10940 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
10941 buffer
+= addr_size
;
10942 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
10943 buffer
+= addr_size
;
10944 offset
+= 2 * addr_size
;
10946 /* An end of list marker is a pair of zero addresses. */
10947 if (range_beginning
== 0 && range_end
== 0)
10948 /* Found the end of list entry. */
10951 /* Each base address selection entry is a pair of 2 values.
10952 The first is the largest possible address, the second is
10953 the base address. Check for a base address here. */
10954 if ((range_beginning
& mask
) == mask
)
10956 /* If we found the largest possible address, then we already
10957 have the base address in range_end. */
10962 if (!base
.has_value ())
10964 /* We have no valid base address for the ranges
10966 complaint (_("Invalid .debug_ranges data (no base address)"));
10970 if (range_beginning
> range_end
)
10972 /* Inverted range entries are invalid. */
10973 complaint (_("Invalid .debug_ranges data (inverted range)"));
10977 /* Empty range entries have no effect. */
10978 if (range_beginning
== range_end
)
10981 range_beginning
+= *base
;
10982 range_end
+= *base
;
10984 /* A not-uncommon case of bad debug info.
10985 Don't pollute the addrmap with bad data. */
10986 if (range_beginning
== 0
10987 && !per_objfile
->per_bfd
->has_section_at_zero
)
10989 complaint (_(".debug_ranges entry has start address of zero"
10990 " [in module %s]"), objfile_name (objfile
));
10994 callback (range_beginning
, range_end
);
11000 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
11001 Return 1 if the attributes are present and valid, otherwise, return 0.
11002 TAG is passed to dwarf2_ranges_process. If MAP is not NULL, then
11003 ranges in MAP are set, using DATUM as the value. */
11006 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
11007 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
11008 addrmap
*map
, void *datum
, dwarf_tag tag
)
11010 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11011 struct gdbarch
*gdbarch
= objfile
->arch ();
11012 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
11015 CORE_ADDR high
= 0;
11018 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
11019 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
11021 if (map
!= nullptr)
11026 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
11027 range_beginning
+ baseaddr
)
11029 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
11030 range_end
+ baseaddr
)
11032 map
->set_empty (lowpc
, highpc
- 1, datum
);
11035 /* FIXME: This is recording everything as a low-high
11036 segment of consecutive addresses. We should have a
11037 data structure for discontiguous block ranges
11041 low
= range_beginning
;
11047 if (range_beginning
< low
)
11048 low
= range_beginning
;
11049 if (range_end
> high
)
11057 /* If the first entry is an end-of-list marker, the range
11058 describes an empty scope, i.e. no instructions. */
11064 *high_return
= high
;
11068 /* Process ranges and fill in a vector of the low PC values only. */
11071 dwarf2_ranges_read_low_addrs (unsigned offset
, struct dwarf2_cu
*cu
,
11073 std::vector
<CORE_ADDR
> &result
)
11075 dwarf2_ranges_process (offset
, cu
, tag
,
11076 [&] (CORE_ADDR start
, CORE_ADDR end
)
11078 result
.push_back (start
);
11082 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
11083 definition for the return value. *LOWPC and *HIGHPC are set iff
11084 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
11086 static enum pc_bounds_kind
11087 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
11088 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
11089 addrmap
*map
, void *datum
)
11091 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11092 struct attribute
*attr
;
11093 struct attribute
*attr_high
;
11095 CORE_ADDR high
= 0;
11096 enum pc_bounds_kind ret
;
11098 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11101 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11102 if (attr
!= nullptr)
11104 low
= attr
->as_address ();
11105 high
= attr_high
->as_address ();
11106 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
11110 /* Found high w/o low attribute. */
11111 return PC_BOUNDS_INVALID
;
11113 /* Found consecutive range of addresses. */
11114 ret
= PC_BOUNDS_HIGH_LOW
;
11118 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11119 if (attr
!= nullptr && attr
->form_is_unsigned ())
11121 /* Offset in the .debug_ranges or .debug_rnglist section (depending
11122 on DWARF version). */
11123 ULONGEST ranges_offset
= attr
->as_unsigned ();
11125 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
11127 if (die
->tag
!= DW_TAG_compile_unit
)
11128 ranges_offset
+= cu
->gnu_ranges_base
;
11130 /* Value of the DW_AT_ranges attribute is the offset in the
11131 .debug_ranges section. */
11132 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
,
11133 map
, datum
, die
->tag
))
11134 return PC_BOUNDS_INVALID
;
11135 /* Found discontinuous range of addresses. */
11136 ret
= PC_BOUNDS_RANGES
;
11139 return PC_BOUNDS_NOT_PRESENT
;
11142 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
11144 return PC_BOUNDS_INVALID
;
11146 /* When using the GNU linker, .gnu.linkonce. sections are used to
11147 eliminate duplicate copies of functions and vtables and such.
11148 The linker will arbitrarily choose one and discard the others.
11149 The AT_*_pc values for such functions refer to local labels in
11150 these sections. If the section from that file was discarded, the
11151 labels are not in the output, so the relocs get a value of 0.
11152 If this is a discarded function, mark the pc bounds as invalid,
11153 so that GDB will ignore it. */
11154 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
11155 return PC_BOUNDS_INVALID
;
11163 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
11164 its low and high PC addresses. Do nothing if these addresses could not
11165 be determined. Otherwise, set LOWPC to the low address if it is smaller,
11166 and HIGHPC to the high address if greater than HIGHPC. */
11169 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
11170 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11171 struct dwarf2_cu
*cu
)
11173 CORE_ADDR low
, high
;
11174 struct die_info
*child
= die
->child
;
11176 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, nullptr, nullptr)
11177 >= PC_BOUNDS_RANGES
)
11179 *lowpc
= std::min (*lowpc
, low
);
11180 *highpc
= std::max (*highpc
, high
);
11183 /* If the language does not allow nested subprograms (either inside
11184 subprograms or lexical blocks), we're done. */
11185 if (cu
->lang () != language_ada
)
11188 /* Check all the children of the given DIE. If it contains nested
11189 subprograms, then check their pc bounds. Likewise, we need to
11190 check lexical blocks as well, as they may also contain subprogram
11192 while (child
&& child
->tag
)
11194 if (child
->tag
== DW_TAG_subprogram
11195 || child
->tag
== DW_TAG_lexical_block
)
11196 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
11197 child
= child
->sibling
;
11201 /* Get the low and high pc's represented by the scope DIE, and store
11202 them in *LOWPC and *HIGHPC. If the correct values can't be
11203 determined, set *LOWPC to -1 and *HIGHPC to 0. */
11206 get_scope_pc_bounds (struct die_info
*die
,
11207 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
11208 struct dwarf2_cu
*cu
)
11210 CORE_ADDR best_low
= (CORE_ADDR
) -1;
11211 CORE_ADDR best_high
= (CORE_ADDR
) 0;
11212 CORE_ADDR current_low
, current_high
;
11214 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
,
11216 >= PC_BOUNDS_RANGES
)
11218 best_low
= current_low
;
11219 best_high
= current_high
;
11223 struct die_info
*child
= die
->child
;
11225 while (child
&& child
->tag
)
11227 switch (child
->tag
) {
11228 case DW_TAG_subprogram
:
11229 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
11231 case DW_TAG_namespace
:
11232 case DW_TAG_module
:
11233 /* FIXME: carlton/2004-01-16: Should we do this for
11234 DW_TAG_class_type/DW_TAG_structure_type, too? I think
11235 that current GCC's always emit the DIEs corresponding
11236 to definitions of methods of classes as children of a
11237 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
11238 the DIEs giving the declarations, which could be
11239 anywhere). But I don't see any reason why the
11240 standards says that they have to be there. */
11241 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
11243 if (current_low
!= ((CORE_ADDR
) -1))
11245 best_low
= std::min (best_low
, current_low
);
11246 best_high
= std::max (best_high
, current_high
);
11254 child
= child
->sibling
;
11259 *highpc
= best_high
;
11262 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
11266 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
11267 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
11269 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11270 struct gdbarch
*gdbarch
= objfile
->arch ();
11271 struct attribute
*attr
;
11272 struct attribute
*attr_high
;
11274 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
11277 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11278 if (attr
!= nullptr)
11280 CORE_ADDR low
= attr
->as_address ();
11281 CORE_ADDR high
= attr_high
->as_address ();
11283 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
11286 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
11287 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
11288 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
11292 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
11293 if (attr
!= nullptr && attr
->form_is_unsigned ())
11295 /* Offset in the .debug_ranges or .debug_rnglist section (depending
11296 on DWARF version). */
11297 ULONGEST ranges_offset
= attr
->as_unsigned ();
11299 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
11301 if (die
->tag
!= DW_TAG_compile_unit
)
11302 ranges_offset
+= cu
->gnu_ranges_base
;
11304 std::vector
<blockrange
> blockvec
;
11305 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
11306 [&] (CORE_ADDR start
, CORE_ADDR end
)
11310 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
11311 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
11312 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
11313 blockvec
.emplace_back (start
, end
);
11316 block
->set_ranges (make_blockranges (objfile
, blockvec
));
11320 /* Check whether the producer field indicates either of GCC < 4.6, or the
11321 Intel C/C++ compiler, and cache the result in CU. */
11324 check_producer (struct dwarf2_cu
*cu
)
11328 if (cu
->producer
== NULL
)
11330 /* For unknown compilers expect their behavior is DWARF version
11333 GCC started to support .debug_types sections by -gdwarf-4 since
11334 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
11335 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
11336 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
11337 interpreted incorrectly by GDB now - GCC PR debug/48229. */
11339 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
11341 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
11342 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
11343 cu
->producer_is_gcc_11
= major
== 11;
11345 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
11347 cu
->producer_is_icc
= true;
11348 cu
->producer_is_icc_lt_14
= major
< 14;
11350 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
11351 cu
->producer_is_codewarrior
= true;
11352 else if (producer_is_clang (cu
->producer
, &major
, &minor
))
11353 cu
->producer_is_clang
= true;
11356 /* For other non-GCC compilers, expect their behavior is DWARF version
11360 cu
->checked_producer
= true;
11363 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
11364 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
11365 during 4.6.0 experimental. */
11368 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
11370 if (!cu
->checked_producer
)
11371 check_producer (cu
);
11373 return cu
->producer_is_gxx_lt_4_6
;
11377 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
11378 with incorrect is_stmt attributes. */
11381 producer_is_codewarrior (struct dwarf2_cu
*cu
)
11383 if (!cu
->checked_producer
)
11384 check_producer (cu
);
11386 return cu
->producer_is_codewarrior
;
11389 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
11390 If that attribute is not available, return the appropriate
11393 static enum dwarf_access_attribute
11394 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
11396 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
11397 if (attr
!= nullptr)
11399 LONGEST value
= attr
->constant_value (-1);
11400 if (value
== DW_ACCESS_public
11401 || value
== DW_ACCESS_protected
11402 || value
== DW_ACCESS_private
)
11403 return (dwarf_access_attribute
) value
;
11404 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
11408 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
11410 /* The default DWARF 2 accessibility for members is public, the default
11411 accessibility for inheritance is private. */
11413 if (die
->tag
!= DW_TAG_inheritance
)
11414 return DW_ACCESS_public
;
11416 return DW_ACCESS_private
;
11420 /* DWARF 3+ defines the default accessibility a different way. The same
11421 rules apply now for DW_TAG_inheritance as for the members and it only
11422 depends on the container kind. */
11424 if (die
->parent
->tag
== DW_TAG_class_type
)
11425 return DW_ACCESS_private
;
11427 return DW_ACCESS_public
;
11431 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
11432 *OFFSET to the byte offset. If the attribute was not found return
11433 0, otherwise return 1. If it was found but could not properly be
11434 handled, set *OFFSET to 0. */
11437 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
11440 struct attribute
*attr
;
11442 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
11447 /* Note that we do not check for a section offset first here.
11448 This is because DW_AT_data_member_location is new in DWARF 4,
11449 so if we see it, we can assume that a constant form is really
11450 a constant and not a section offset. */
11451 if (attr
->form_is_constant ())
11452 *offset
= attr
->constant_value (0);
11453 else if (attr
->form_is_section_offset ())
11454 dwarf2_complex_location_expr_complaint ();
11455 else if (attr
->form_is_block ())
11456 *offset
= decode_locdesc (attr
->as_block (), cu
);
11458 dwarf2_complex_location_expr_complaint ();
11464 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
11465 if (attr
!= nullptr)
11467 *offset
= attr
->constant_value (0);
11475 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
11476 store the results in FIELD. */
11479 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
11480 struct field
*field
)
11482 struct attribute
*attr
;
11484 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
11487 if (attr
->form_is_constant ())
11489 LONGEST offset
= attr
->constant_value (0);
11491 /* Work around this GCC 11 bug, where it would erroneously use -1
11492 data member locations, instead of 0:
11494 Negative DW_AT_data_member_location
11495 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
11497 if (offset
== -1 && cu
->producer_is_gcc_11
)
11499 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
11503 field
->set_loc_bitpos (offset
* bits_per_byte
);
11505 else if (attr
->form_is_section_offset ())
11506 dwarf2_complex_location_expr_complaint ();
11507 else if (attr
->form_is_block ())
11510 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
11512 field
->set_loc_bitpos (offset
* bits_per_byte
);
11515 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11516 struct objfile
*objfile
= per_objfile
->objfile
;
11517 struct dwarf2_locexpr_baton
*dlbaton
11518 = XOBNEW (&objfile
->objfile_obstack
,
11519 struct dwarf2_locexpr_baton
);
11520 dlbaton
->data
= attr
->as_block ()->data
;
11521 dlbaton
->size
= attr
->as_block ()->size
;
11522 /* When using this baton, we want to compute the address
11523 of the field, not the value. This is why
11524 is_reference is set to false here. */
11525 dlbaton
->is_reference
= false;
11526 dlbaton
->per_objfile
= per_objfile
;
11527 dlbaton
->per_cu
= cu
->per_cu
;
11529 field
->set_loc_dwarf_block (dlbaton
);
11533 dwarf2_complex_location_expr_complaint ();
11537 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
11538 if (attr
!= nullptr)
11539 field
->set_loc_bitpos (attr
->constant_value (0));
11543 /* Add an aggregate field to the field list. */
11546 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
11547 struct dwarf2_cu
*cu
)
11549 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11550 struct gdbarch
*gdbarch
= objfile
->arch ();
11551 struct nextfield
*new_field
;
11552 struct attribute
*attr
;
11554 const char *fieldname
= "";
11556 if (die
->tag
== DW_TAG_inheritance
)
11558 fip
->baseclasses
.emplace_back ();
11559 new_field
= &fip
->baseclasses
.back ();
11563 fip
->fields
.emplace_back ();
11564 new_field
= &fip
->fields
.back ();
11567 new_field
->offset
= die
->sect_off
;
11569 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
11570 if (new_field
->accessibility
!= DW_ACCESS_public
)
11571 fip
->non_public_fields
= true;
11573 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11574 if (attr
!= nullptr)
11575 new_field
->virtuality
= attr
->as_virtuality ();
11577 new_field
->virtuality
= DW_VIRTUALITY_none
;
11579 fp
= &new_field
->field
;
11581 if ((die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_namelist_item
)
11582 && !die_is_declaration (die
, cu
))
11584 if (die
->tag
== DW_TAG_namelist_item
)
11586 /* Typically, DW_TAG_namelist_item are references to namelist items.
11587 If so, follow that reference. */
11588 struct attribute
*attr1
= dwarf2_attr (die
, DW_AT_namelist_item
, cu
);
11589 struct die_info
*item_die
= nullptr;
11590 struct dwarf2_cu
*item_cu
= cu
;
11591 if (attr1
->form_is_ref ())
11592 item_die
= follow_die_ref (die
, attr1
, &item_cu
);
11593 if (item_die
!= nullptr)
11596 /* Data member other than a C++ static data member. */
11598 /* Get type of field. */
11599 fp
->set_type (die_type (die
, cu
));
11601 fp
->set_loc_bitpos (0);
11603 /* Get bit size of field (zero if none). */
11604 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
11605 if (attr
!= nullptr)
11607 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
11611 FIELD_BITSIZE (*fp
) = 0;
11614 /* Get bit offset of field. */
11615 handle_member_location (die
, cu
, fp
);
11616 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
11617 if (attr
!= nullptr && attr
->form_is_constant ())
11619 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
11621 /* For big endian bits, the DW_AT_bit_offset gives the
11622 additional bit offset from the MSB of the containing
11623 anonymous object to the MSB of the field. We don't
11624 have to do anything special since we don't need to
11625 know the size of the anonymous object. */
11626 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
11630 /* For little endian bits, compute the bit offset to the
11631 MSB of the anonymous object, subtract off the number of
11632 bits from the MSB of the field to the MSB of the
11633 object, and then subtract off the number of bits of
11634 the field itself. The result is the bit offset of
11635 the LSB of the field. */
11636 int anonymous_size
;
11637 int bit_offset
= attr
->constant_value (0);
11639 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11640 if (attr
!= nullptr && attr
->form_is_constant ())
11642 /* The size of the anonymous object containing
11643 the bit field is explicit, so use the
11644 indicated size (in bytes). */
11645 anonymous_size
= attr
->constant_value (0);
11649 /* The size of the anonymous object containing
11650 the bit field must be inferred from the type
11651 attribute of the data member containing the
11653 anonymous_size
= fp
->type ()->length ();
11655 fp
->set_loc_bitpos (fp
->loc_bitpos ()
11656 + anonymous_size
* bits_per_byte
11657 - bit_offset
- FIELD_BITSIZE (*fp
));
11661 /* Get name of field. */
11662 fieldname
= dwarf2_name (die
, cu
);
11663 if (fieldname
== NULL
)
11666 /* The name is already allocated along with this objfile, so we don't
11667 need to duplicate it for the type. */
11668 fp
->set_name (fieldname
);
11670 /* Change accessibility for artificial fields (e.g. virtual table
11671 pointer or virtual base class pointer) to private. */
11672 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
11674 FIELD_ARTIFICIAL (*fp
) = 1;
11675 new_field
->accessibility
= DW_ACCESS_private
;
11676 fip
->non_public_fields
= true;
11679 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
11681 /* C++ static member. */
11683 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
11684 is a declaration, but all versions of G++ as of this writing
11685 (so through at least 3.2.1) incorrectly generate
11686 DW_TAG_variable tags. */
11688 const char *physname
;
11690 /* Get name of field. */
11691 fieldname
= dwarf2_name (die
, cu
);
11692 if (fieldname
== NULL
)
11695 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11697 /* Only create a symbol if this is an external value.
11698 new_symbol checks this and puts the value in the global symbol
11699 table, which we want. If it is not external, new_symbol
11700 will try to put the value in cu->list_in_scope which is wrong. */
11701 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
11703 /* A static const member, not much different than an enum as far as
11704 we're concerned, except that we can support more types. */
11705 new_symbol (die
, NULL
, cu
);
11708 /* Get physical name. */
11709 physname
= dwarf2_physname (fieldname
, die
, cu
);
11711 /* The name is already allocated along with this objfile, so we don't
11712 need to duplicate it for the type. */
11713 fp
->set_loc_physname (physname
? physname
: "");
11714 fp
->set_type (die_type (die
, cu
));
11715 fp
->set_name (fieldname
);
11717 else if (die
->tag
== DW_TAG_inheritance
)
11719 /* C++ base class field. */
11720 handle_member_location (die
, cu
, fp
);
11721 FIELD_BITSIZE (*fp
) = 0;
11722 fp
->set_type (die_type (die
, cu
));
11723 fp
->set_name (fp
->type ()->name ());
11726 gdb_assert_not_reached ("missing case in dwarf2_add_field");
11729 /* Can the type given by DIE define another type? */
11732 type_can_define_types (const struct die_info
*die
)
11736 case DW_TAG_typedef
:
11737 case DW_TAG_class_type
:
11738 case DW_TAG_structure_type
:
11739 case DW_TAG_union_type
:
11740 case DW_TAG_enumeration_type
:
11748 /* Add a type definition defined in the scope of the FIP's class. */
11751 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
11752 struct dwarf2_cu
*cu
)
11754 struct decl_field fp
;
11755 memset (&fp
, 0, sizeof (fp
));
11757 gdb_assert (type_can_define_types (die
));
11759 /* Get name of field. NULL is okay here, meaning an anonymous type. */
11760 fp
.name
= dwarf2_name (die
, cu
);
11761 fp
.type
= read_type_die (die
, cu
);
11763 /* Save accessibility. */
11764 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
11765 switch (accessibility
)
11767 case DW_ACCESS_public
:
11768 /* The assumed value if neither private nor protected. */
11770 case DW_ACCESS_private
:
11773 case DW_ACCESS_protected
:
11774 fp
.is_protected
= 1;
11778 if (die
->tag
== DW_TAG_typedef
)
11779 fip
->typedef_field_list
.push_back (fp
);
11781 fip
->nested_types_list
.push_back (fp
);
11784 /* A convenience typedef that's used when finding the discriminant
11785 field for a variant part. */
11786 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
11789 /* Compute the discriminant range for a given variant. OBSTACK is
11790 where the results will be stored. VARIANT is the variant to
11791 process. IS_UNSIGNED indicates whether the discriminant is signed
11794 static const gdb::array_view
<discriminant_range
>
11795 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
11798 std::vector
<discriminant_range
> ranges
;
11800 if (variant
.default_branch
)
11803 if (variant
.discr_list_data
== nullptr)
11805 discriminant_range r
11806 = {variant
.discriminant_value
, variant
.discriminant_value
};
11807 ranges
.push_back (r
);
11811 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
11812 variant
.discr_list_data
->size
);
11813 while (!data
.empty ())
11815 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
11817 complaint (_("invalid discriminant marker: %d"), data
[0]);
11820 bool is_range
= data
[0] == DW_DSC_range
;
11821 data
= data
.slice (1);
11823 ULONGEST low
, high
;
11824 unsigned int bytes_read
;
11828 complaint (_("DW_AT_discr_list missing low value"));
11832 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
11834 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
11836 data
= data
.slice (bytes_read
);
11842 complaint (_("DW_AT_discr_list missing high value"));
11846 high
= read_unsigned_leb128 (nullptr, data
.data (),
11849 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
11851 data
= data
.slice (bytes_read
);
11856 ranges
.push_back ({ low
, high
});
11860 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
11862 std::copy (ranges
.begin (), ranges
.end (), result
);
11863 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
11866 static const gdb::array_view
<variant_part
> create_variant_parts
11867 (struct obstack
*obstack
,
11868 const offset_map_type
&offset_map
,
11869 struct field_info
*fi
,
11870 const std::vector
<variant_part_builder
> &variant_parts
);
11872 /* Fill in a "struct variant" for a given variant field. RESULT is
11873 the variant to fill in. OBSTACK is where any needed allocations
11874 will be done. OFFSET_MAP holds the mapping from section offsets to
11875 fields for the type. FI describes the fields of the type we're
11876 processing. FIELD is the variant field we're converting. */
11879 create_one_variant (variant
&result
, struct obstack
*obstack
,
11880 const offset_map_type
&offset_map
,
11881 struct field_info
*fi
, const variant_field
&field
)
11883 result
.discriminants
= convert_variant_range (obstack
, field
, false);
11884 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
11885 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
11886 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
11887 field
.variant_parts
);
11890 /* Fill in a "struct variant_part" for a given variant part. RESULT
11891 is the variant part to fill in. OBSTACK is where any needed
11892 allocations will be done. OFFSET_MAP holds the mapping from
11893 section offsets to fields for the type. FI describes the fields of
11894 the type we're processing. BUILDER is the variant part to be
11898 create_one_variant_part (variant_part
&result
,
11899 struct obstack
*obstack
,
11900 const offset_map_type
&offset_map
,
11901 struct field_info
*fi
,
11902 const variant_part_builder
&builder
)
11904 auto iter
= offset_map
.find (builder
.discriminant_offset
);
11905 if (iter
== offset_map
.end ())
11907 result
.discriminant_index
= -1;
11908 /* Doesn't matter. */
11909 result
.is_unsigned
= false;
11913 result
.discriminant_index
= iter
->second
;
11915 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
11918 size_t n
= builder
.variants
.size ();
11919 variant
*output
= new (obstack
) variant
[n
];
11920 for (size_t i
= 0; i
< n
; ++i
)
11921 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
11922 builder
.variants
[i
]);
11924 result
.variants
= gdb::array_view
<variant
> (output
, n
);
11927 /* Create a vector of variant parts that can be attached to a type.
11928 OBSTACK is where any needed allocations will be done. OFFSET_MAP
11929 holds the mapping from section offsets to fields for the type. FI
11930 describes the fields of the type we're processing. VARIANT_PARTS
11931 is the vector to convert. */
11933 static const gdb::array_view
<variant_part
>
11934 create_variant_parts (struct obstack
*obstack
,
11935 const offset_map_type
&offset_map
,
11936 struct field_info
*fi
,
11937 const std::vector
<variant_part_builder
> &variant_parts
)
11939 if (variant_parts
.empty ())
11942 size_t n
= variant_parts
.size ();
11943 variant_part
*result
= new (obstack
) variant_part
[n
];
11944 for (size_t i
= 0; i
< n
; ++i
)
11945 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
11948 return gdb::array_view
<variant_part
> (result
, n
);
11951 /* Compute the variant part vector for FIP, attaching it to TYPE when
11955 add_variant_property (struct field_info
*fip
, struct type
*type
,
11956 struct dwarf2_cu
*cu
)
11958 /* Map section offsets of fields to their field index. Note the
11959 field index here does not take the number of baseclasses into
11961 offset_map_type offset_map
;
11962 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
11963 offset_map
[fip
->fields
[i
].offset
] = i
;
11965 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
11966 gdb::array_view
<const variant_part
> parts
11967 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
11968 fip
->variant_parts
);
11970 struct dynamic_prop prop
;
11971 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
11972 obstack_copy (&objfile
->objfile_obstack
, &parts
,
11975 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
11978 /* Create the vector of fields, and attach it to the type. */
11981 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
11982 struct dwarf2_cu
*cu
)
11984 int nfields
= fip
->nfields ();
11986 /* Record the field count, allocate space for the array of fields,
11987 and create blank accessibility bitfields if necessary. */
11988 type
->set_num_fields (nfields
);
11990 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
11992 if (fip
->non_public_fields
&& cu
->lang () != language_ada
)
11994 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11996 TYPE_FIELD_PRIVATE_BITS (type
) =
11997 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
11998 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
12000 TYPE_FIELD_PROTECTED_BITS (type
) =
12001 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12002 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
12004 TYPE_FIELD_IGNORE_BITS (type
) =
12005 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
12006 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
12009 /* If the type has baseclasses, allocate and clear a bit vector for
12010 TYPE_FIELD_VIRTUAL_BITS. */
12011 if (!fip
->baseclasses
.empty () && cu
->lang () != language_ada
)
12013 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
12014 unsigned char *pointer
;
12016 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12017 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
12018 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
12019 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
12020 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
12023 if (!fip
->variant_parts
.empty ())
12024 add_variant_property (fip
, type
, cu
);
12026 /* Copy the saved-up fields into the field vector. */
12027 for (int i
= 0; i
< nfields
; ++i
)
12029 struct nextfield
&field
12030 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
12031 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
12033 type
->field (i
) = field
.field
;
12034 switch (field
.accessibility
)
12036 case DW_ACCESS_private
:
12037 if (cu
->lang () != language_ada
)
12038 SET_TYPE_FIELD_PRIVATE (type
, i
);
12041 case DW_ACCESS_protected
:
12042 if (cu
->lang () != language_ada
)
12043 SET_TYPE_FIELD_PROTECTED (type
, i
);
12046 case DW_ACCESS_public
:
12050 /* Unknown accessibility. Complain and treat it as public. */
12052 complaint (_("unsupported accessibility %d"),
12053 field
.accessibility
);
12057 if (i
< fip
->baseclasses
.size ())
12059 switch (field
.virtuality
)
12061 case DW_VIRTUALITY_virtual
:
12062 case DW_VIRTUALITY_pure_virtual
:
12063 if (cu
->lang () == language_ada
)
12064 error (_("unexpected virtuality in component of Ada type"));
12065 SET_TYPE_FIELD_VIRTUAL (type
, i
);
12072 /* Return true if this member function is a constructor, false
12076 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
12078 const char *fieldname
;
12079 const char *type_name
;
12082 if (die
->parent
== NULL
)
12085 if (die
->parent
->tag
!= DW_TAG_structure_type
12086 && die
->parent
->tag
!= DW_TAG_union_type
12087 && die
->parent
->tag
!= DW_TAG_class_type
)
12090 fieldname
= dwarf2_name (die
, cu
);
12091 type_name
= dwarf2_name (die
->parent
, cu
);
12092 if (fieldname
== NULL
|| type_name
== NULL
)
12095 len
= strlen (fieldname
);
12096 return (strncmp (fieldname
, type_name
, len
) == 0
12097 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
12100 /* Add a member function to the proper fieldlist. */
12103 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
12104 struct type
*type
, struct dwarf2_cu
*cu
)
12106 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12107 struct attribute
*attr
;
12109 struct fnfieldlist
*flp
= nullptr;
12110 struct fn_field
*fnp
;
12111 const char *fieldname
;
12112 struct type
*this_type
;
12114 if (cu
->lang () == language_ada
)
12115 error (_("unexpected member function in Ada type"));
12117 /* Get name of member function. */
12118 fieldname
= dwarf2_name (die
, cu
);
12119 if (fieldname
== NULL
)
12122 /* Look up member function name in fieldlist. */
12123 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
12125 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
12127 flp
= &fip
->fnfieldlists
[i
];
12132 /* Create a new fnfieldlist if necessary. */
12133 if (flp
== nullptr)
12135 fip
->fnfieldlists
.emplace_back ();
12136 flp
= &fip
->fnfieldlists
.back ();
12137 flp
->name
= fieldname
;
12138 i
= fip
->fnfieldlists
.size () - 1;
12141 /* Create a new member function field and add it to the vector of
12143 flp
->fnfields
.emplace_back ();
12144 fnp
= &flp
->fnfields
.back ();
12146 /* Delay processing of the physname until later. */
12147 if (cu
->lang () == language_cplus
)
12148 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
12152 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
12153 fnp
->physname
= physname
? physname
: "";
12156 fnp
->type
= alloc_type (objfile
);
12157 this_type
= read_type_die (die
, cu
);
12158 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
12160 int nparams
= this_type
->num_fields ();
12162 /* TYPE is the domain of this method, and THIS_TYPE is the type
12163 of the method itself (TYPE_CODE_METHOD). */
12164 smash_to_method_type (fnp
->type
, type
,
12165 this_type
->target_type (),
12166 this_type
->fields (),
12167 this_type
->num_fields (),
12168 this_type
->has_varargs ());
12170 /* Handle static member functions.
12171 Dwarf2 has no clean way to discern C++ static and non-static
12172 member functions. G++ helps GDB by marking the first
12173 parameter for non-static member functions (which is the this
12174 pointer) as artificial. We obtain this information from
12175 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
12176 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
12177 fnp
->voffset
= VOFFSET_STATIC
;
12180 complaint (_("member function type missing for '%s'"),
12181 dwarf2_full_name (fieldname
, die
, cu
));
12183 /* Get fcontext from DW_AT_containing_type if present. */
12184 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12185 fnp
->fcontext
= die_containing_type (die
, cu
);
12187 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
12188 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
12190 /* Get accessibility. */
12191 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
12192 switch (accessibility
)
12194 case DW_ACCESS_private
:
12195 fnp
->is_private
= 1;
12197 case DW_ACCESS_protected
:
12198 fnp
->is_protected
= 1;
12202 /* Check for artificial methods. */
12203 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
12204 if (attr
&& attr
->as_boolean ())
12205 fnp
->is_artificial
= 1;
12207 /* Check for defaulted methods. */
12208 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
12209 if (attr
!= nullptr)
12210 fnp
->defaulted
= attr
->defaulted ();
12212 /* Check for deleted methods. */
12213 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
12214 if (attr
!= nullptr && attr
->as_boolean ())
12215 fnp
->is_deleted
= 1;
12217 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
12219 /* Get index in virtual function table if it is a virtual member
12220 function. For older versions of GCC, this is an offset in the
12221 appropriate virtual table, as specified by DW_AT_containing_type.
12222 For everyone else, it is an expression to be evaluated relative
12223 to the object address. */
12225 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
12226 if (attr
!= nullptr)
12228 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
12230 struct dwarf_block
*block
= attr
->as_block ();
12232 if (block
->data
[0] == DW_OP_constu
)
12234 /* Old-style GCC. */
12235 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
12237 else if (block
->data
[0] == DW_OP_deref
12238 || (block
->size
> 1
12239 && block
->data
[0] == DW_OP_deref_size
12240 && block
->data
[1] == cu
->header
.addr_size
))
12242 fnp
->voffset
= decode_locdesc (block
, cu
);
12243 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
12244 dwarf2_complex_location_expr_complaint ();
12246 fnp
->voffset
/= cu
->header
.addr_size
;
12250 dwarf2_complex_location_expr_complaint ();
12252 if (!fnp
->fcontext
)
12254 /* If there is no `this' field and no DW_AT_containing_type,
12255 we cannot actually find a base class context for the
12257 if (this_type
->num_fields () == 0
12258 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
12260 complaint (_("cannot determine context for virtual member "
12261 "function \"%s\" (offset %s)"),
12262 fieldname
, sect_offset_str (die
->sect_off
));
12266 fnp
->fcontext
= this_type
->field (0).type ()->target_type ();
12270 else if (attr
->form_is_section_offset ())
12272 dwarf2_complex_location_expr_complaint ();
12276 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
12282 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
12283 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
12285 /* GCC does this, as of 2008-08-25; PR debug/37237. */
12286 complaint (_("Member function \"%s\" (offset %s) is virtual "
12287 "but the vtable offset is not specified"),
12288 fieldname
, sect_offset_str (die
->sect_off
));
12289 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12290 TYPE_CPLUS_DYNAMIC (type
) = 1;
12295 /* Create the vector of member function fields, and attach it to the type. */
12298 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
12299 struct dwarf2_cu
*cu
)
12301 if (cu
->lang () == language_ada
)
12302 error (_("unexpected member functions in Ada type"));
12304 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12305 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
12307 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
12309 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
12311 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
12312 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
12314 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
12315 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
12316 fn_flp
->fn_fields
= (struct fn_field
*)
12317 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
12319 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
12320 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
12323 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
12326 /* Returns non-zero if NAME is the name of a vtable member in CU's
12327 language, zero otherwise. */
12329 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
12331 static const char vptr
[] = "_vptr";
12333 /* Look for the C++ form of the vtable. */
12334 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
12340 /* GCC outputs unnamed structures that are really pointers to member
12341 functions, with the ABI-specified layout. If TYPE describes
12342 such a structure, smash it into a member function type.
12344 GCC shouldn't do this; it should just output pointer to member DIEs.
12345 This is GCC PR debug/28767. */
12348 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
12350 struct type
*pfn_type
, *self_type
, *new_type
;
12352 /* Check for a structure with no name and two children. */
12353 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
12356 /* Check for __pfn and __delta members. */
12357 if (type
->field (0).name () == NULL
12358 || strcmp (type
->field (0).name (), "__pfn") != 0
12359 || type
->field (1).name () == NULL
12360 || strcmp (type
->field (1).name (), "__delta") != 0)
12363 /* Find the type of the method. */
12364 pfn_type
= type
->field (0).type ();
12365 if (pfn_type
== NULL
12366 || pfn_type
->code () != TYPE_CODE_PTR
12367 || pfn_type
->target_type ()->code () != TYPE_CODE_FUNC
)
12370 /* Look for the "this" argument. */
12371 pfn_type
= pfn_type
->target_type ();
12372 if (pfn_type
->num_fields () == 0
12373 /* || pfn_type->field (0).type () == NULL */
12374 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
12377 self_type
= pfn_type
->field (0).type ()->target_type ();
12378 new_type
= alloc_type (objfile
);
12379 smash_to_method_type (new_type
, self_type
, pfn_type
->target_type (),
12380 pfn_type
->fields (), pfn_type
->num_fields (),
12381 pfn_type
->has_varargs ());
12382 smash_to_methodptr_type (type
, new_type
);
12385 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
12386 requires rewriting, then copy it and return the updated copy.
12387 Otherwise return nullptr. */
12389 static struct type
*
12390 rewrite_array_type (struct type
*type
)
12392 if (type
->code () != TYPE_CODE_ARRAY
)
12395 struct type
*index_type
= type
->index_type ();
12396 range_bounds
*current_bounds
= index_type
->bounds ();
12398 /* Handle multi-dimensional arrays. */
12399 struct type
*new_target
= rewrite_array_type (type
->target_type ());
12400 if (new_target
== nullptr)
12402 /* Maybe we don't need to rewrite this array. */
12403 if (current_bounds
->low
.kind () == PROP_CONST
12404 && current_bounds
->high
.kind () == PROP_CONST
)
12408 /* Either the target type was rewritten, or the bounds have to be
12409 updated. Either way we want to copy the type and update
12411 struct type
*copy
= copy_type (type
);
12412 int nfields
= copy
->num_fields ();
12414 = ((struct field
*) TYPE_ZALLOC (copy
,
12415 nfields
* sizeof (struct field
)));
12416 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
12417 copy
->set_fields (new_fields
);
12418 if (new_target
!= nullptr)
12419 copy
->set_target_type (new_target
);
12421 struct type
*index_copy
= copy_type (index_type
);
12422 range_bounds
*bounds
12423 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
12424 sizeof (range_bounds
));
12425 *bounds
= *current_bounds
;
12426 bounds
->low
.set_const_val (1);
12427 bounds
->high
.set_const_val (0);
12428 index_copy
->set_bounds (bounds
);
12429 copy
->set_index_type (index_copy
);
12434 /* While some versions of GCC will generate complicated DWARF for an
12435 array (see quirk_ada_thick_pointer), more recent versions were
12436 modified to emit an explicit thick pointer structure. However, in
12437 this case, the array still has DWARF expressions for its ranges,
12438 and these must be ignored. */
12441 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
12444 gdb_assert (cu
->lang () == language_ada
);
12446 /* Check for a structure with two children. */
12447 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
12450 /* Check for P_ARRAY and P_BOUNDS members. */
12451 if (type
->field (0).name () == NULL
12452 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
12453 || type
->field (1).name () == NULL
12454 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
12457 /* Make sure we're looking at a pointer to an array. */
12458 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
12461 /* The Ada code already knows how to handle these types, so all that
12462 we need to do is turn the bounds into static bounds. However, we
12463 don't want to rewrite existing array or index types in-place,
12464 because those may be referenced in other contexts where this
12465 rewriting is undesirable. */
12466 struct type
*new_ary_type
12467 = rewrite_array_type (type
->field (0).type ()->target_type ());
12468 if (new_ary_type
!= nullptr)
12469 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
12472 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
12473 appropriate error checking and issuing complaints if there is a
12477 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
12479 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
12481 if (attr
== nullptr)
12484 if (!attr
->form_is_constant ())
12486 complaint (_("DW_AT_alignment must have constant form"
12487 " - DIE at %s [in module %s]"),
12488 sect_offset_str (die
->sect_off
),
12489 objfile_name (cu
->per_objfile
->objfile
));
12493 LONGEST val
= attr
->constant_value (0);
12496 complaint (_("DW_AT_alignment value must not be negative"
12497 " - DIE at %s [in module %s]"),
12498 sect_offset_str (die
->sect_off
),
12499 objfile_name (cu
->per_objfile
->objfile
));
12502 ULONGEST align
= val
;
12506 complaint (_("DW_AT_alignment value must not be zero"
12507 " - DIE at %s [in module %s]"),
12508 sect_offset_str (die
->sect_off
),
12509 objfile_name (cu
->per_objfile
->objfile
));
12512 if ((align
& (align
- 1)) != 0)
12514 complaint (_("DW_AT_alignment value must be a power of 2"
12515 " - DIE at %s [in module %s]"),
12516 sect_offset_str (die
->sect_off
),
12517 objfile_name (cu
->per_objfile
->objfile
));
12524 /* If the DIE has a DW_AT_alignment attribute, use its value to set
12525 the alignment for TYPE. */
12528 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
12531 if (!set_type_align (type
, get_alignment (cu
, die
)))
12532 complaint (_("DW_AT_alignment value too large"
12533 " - DIE at %s [in module %s]"),
12534 sect_offset_str (die
->sect_off
),
12535 objfile_name (cu
->per_objfile
->objfile
));
12538 /* Check if the given VALUE is a valid enum dwarf_calling_convention
12539 constant for a type, according to DWARF5 spec, Table 5.5. */
12542 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
12547 case DW_CC_pass_by_reference
:
12548 case DW_CC_pass_by_value
:
12552 complaint (_("unrecognized DW_AT_calling_convention value "
12553 "(%s) for a type"), pulongest (value
));
12558 /* Check if the given VALUE is a valid enum dwarf_calling_convention
12559 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
12560 also according to GNU-specific values (see include/dwarf2.h). */
12563 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
12568 case DW_CC_program
:
12572 case DW_CC_GNU_renesas_sh
:
12573 case DW_CC_GNU_borland_fastcall_i386
:
12574 case DW_CC_GDB_IBM_OpenCL
:
12578 complaint (_("unrecognized DW_AT_calling_convention value "
12579 "(%s) for a subroutine"), pulongest (value
));
12584 /* Called when we find the DIE that starts a structure or union scope
12585 (definition) to create a type for the structure or union. Fill in
12586 the type's name and general properties; the members will not be
12587 processed until process_structure_scope. A symbol table entry for
12588 the type will also not be done until process_structure_scope (assuming
12589 the type has a name).
12591 NOTE: we need to call these functions regardless of whether or not the
12592 DIE has a DW_AT_name attribute, since it might be an anonymous
12593 structure or union. This gets the type entered into our set of
12594 user defined types. */
12596 static struct type
*
12597 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12599 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12601 struct attribute
*attr
;
12604 /* If the definition of this type lives in .debug_types, read that type.
12605 Don't follow DW_AT_specification though, that will take us back up
12606 the chain and we want to go down. */
12607 attr
= die
->attr (DW_AT_signature
);
12608 if (attr
!= nullptr)
12610 type
= get_DW_AT_signature_type (die
, attr
, cu
);
12612 /* The type's CU may not be the same as CU.
12613 Ensure TYPE is recorded with CU in die_type_hash. */
12614 return set_die_type (die
, type
, cu
);
12617 type
= alloc_type (objfile
);
12618 INIT_CPLUS_SPECIFIC (type
);
12620 name
= dwarf2_name (die
, cu
);
12623 if (cu
->lang () == language_cplus
12624 || cu
->lang () == language_d
12625 || cu
->lang () == language_rust
)
12627 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
12629 /* dwarf2_full_name might have already finished building the DIE's
12630 type. If so, there is no need to continue. */
12631 if (get_die_type (die
, cu
) != NULL
)
12632 return get_die_type (die
, cu
);
12634 type
->set_name (full_name
);
12638 /* The name is already allocated along with this objfile, so
12639 we don't need to duplicate it for the type. */
12640 type
->set_name (name
);
12644 if (die
->tag
== DW_TAG_structure_type
)
12646 type
->set_code (TYPE_CODE_STRUCT
);
12648 else if (die
->tag
== DW_TAG_union_type
)
12650 type
->set_code (TYPE_CODE_UNION
);
12652 else if (die
->tag
== DW_TAG_namelist
)
12654 type
->set_code (TYPE_CODE_NAMELIST
);
12658 type
->set_code (TYPE_CODE_STRUCT
);
12661 if (cu
->lang () == language_cplus
&& die
->tag
== DW_TAG_class_type
)
12662 type
->set_is_declared_class (true);
12664 /* Store the calling convention in the type if it's available in
12665 the die. Otherwise the calling convention remains set to
12666 the default value DW_CC_normal. */
12667 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12668 if (attr
!= nullptr
12669 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
12671 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12672 TYPE_CPLUS_CALLING_CONVENTION (type
)
12673 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
12676 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12677 if (attr
!= nullptr)
12679 if (attr
->form_is_constant ())
12680 type
->set_length (attr
->constant_value (0));
12683 struct dynamic_prop prop
;
12684 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
12685 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
12687 type
->set_length (0);
12691 type
->set_length (0);
12693 maybe_set_alignment (cu
, die
, type
);
12695 if (producer_is_icc_lt_14 (cu
) && (type
->length () == 0))
12697 /* ICC<14 does not output the required DW_AT_declaration on
12698 incomplete types, but gives them a size of zero. */
12699 type
->set_is_stub (true);
12702 type
->set_stub_is_supported (true);
12704 if (die_is_declaration (die
, cu
))
12705 type
->set_is_stub (true);
12706 else if (attr
== NULL
&& die
->child
== NULL
12707 && producer_is_realview (cu
->producer
))
12708 /* RealView does not output the required DW_AT_declaration
12709 on incomplete types. */
12710 type
->set_is_stub (true);
12712 /* We need to add the type field to the die immediately so we don't
12713 infinitely recurse when dealing with pointers to the structure
12714 type within the structure itself. */
12715 set_die_type (die
, type
, cu
);
12717 /* set_die_type should be already done. */
12718 set_descriptive_type (type
, die
, cu
);
12723 static void handle_struct_member_die
12724 (struct die_info
*child_die
,
12726 struct field_info
*fi
,
12727 std::vector
<struct symbol
*> *template_args
,
12728 struct dwarf2_cu
*cu
);
12730 /* A helper for handle_struct_member_die that handles
12731 DW_TAG_variant_part. */
12734 handle_variant_part (struct die_info
*die
, struct type
*type
,
12735 struct field_info
*fi
,
12736 std::vector
<struct symbol
*> *template_args
,
12737 struct dwarf2_cu
*cu
)
12739 variant_part_builder
*new_part
;
12740 if (fi
->current_variant_part
== nullptr)
12742 fi
->variant_parts
.emplace_back ();
12743 new_part
= &fi
->variant_parts
.back ();
12745 else if (!fi
->current_variant_part
->processing_variant
)
12747 complaint (_("nested DW_TAG_variant_part seen "
12748 "- DIE at %s [in module %s]"),
12749 sect_offset_str (die
->sect_off
),
12750 objfile_name (cu
->per_objfile
->objfile
));
12755 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
12756 current
.variant_parts
.emplace_back ();
12757 new_part
= ¤t
.variant_parts
.back ();
12760 /* When we recurse, we want callees to add to this new variant
12762 scoped_restore save_current_variant_part
12763 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
12765 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
12768 /* It's a univariant form, an extension we support. */
12770 else if (discr
->form_is_ref ())
12772 struct dwarf2_cu
*target_cu
= cu
;
12773 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
12775 new_part
->discriminant_offset
= target_die
->sect_off
;
12779 complaint (_("DW_AT_discr does not have DIE reference form"
12780 " - DIE at %s [in module %s]"),
12781 sect_offset_str (die
->sect_off
),
12782 objfile_name (cu
->per_objfile
->objfile
));
12785 for (die_info
*child_die
= die
->child
;
12787 child_die
= child_die
->sibling
)
12788 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
12791 /* A helper for handle_struct_member_die that handles
12795 handle_variant (struct die_info
*die
, struct type
*type
,
12796 struct field_info
*fi
,
12797 std::vector
<struct symbol
*> *template_args
,
12798 struct dwarf2_cu
*cu
)
12800 if (fi
->current_variant_part
== nullptr)
12802 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
12803 "- DIE at %s [in module %s]"),
12804 sect_offset_str (die
->sect_off
),
12805 objfile_name (cu
->per_objfile
->objfile
));
12808 if (fi
->current_variant_part
->processing_variant
)
12810 complaint (_("nested DW_TAG_variant seen "
12811 "- DIE at %s [in module %s]"),
12812 sect_offset_str (die
->sect_off
),
12813 objfile_name (cu
->per_objfile
->objfile
));
12817 scoped_restore save_processing_variant
12818 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
12821 fi
->current_variant_part
->variants
.emplace_back ();
12822 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
12823 variant
.first_field
= fi
->fields
.size ();
12825 /* In a variant we want to get the discriminant and also add a
12826 field for our sole member child. */
12827 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
12828 if (discr
== nullptr || !discr
->form_is_constant ())
12830 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
12831 if (discr
== nullptr || discr
->as_block ()->size
== 0)
12832 variant
.default_branch
= true;
12834 variant
.discr_list_data
= discr
->as_block ();
12837 variant
.discriminant_value
= discr
->constant_value (0);
12839 for (die_info
*variant_child
= die
->child
;
12840 variant_child
!= NULL
;
12841 variant_child
= variant_child
->sibling
)
12842 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
12844 variant
.last_field
= fi
->fields
.size ();
12847 /* A helper for process_structure_scope that handles a single member
12851 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
12852 struct field_info
*fi
,
12853 std::vector
<struct symbol
*> *template_args
,
12854 struct dwarf2_cu
*cu
)
12856 if (child_die
->tag
== DW_TAG_member
12857 || child_die
->tag
== DW_TAG_variable
12858 || child_die
->tag
== DW_TAG_namelist_item
)
12860 /* NOTE: carlton/2002-11-05: A C++ static data member
12861 should be a DW_TAG_member that is a declaration, but
12862 all versions of G++ as of this writing (so through at
12863 least 3.2.1) incorrectly generate DW_TAG_variable
12864 tags for them instead. */
12865 dwarf2_add_field (fi
, child_die
, cu
);
12867 else if (child_die
->tag
== DW_TAG_subprogram
)
12869 /* Rust doesn't have member functions in the C++ sense.
12870 However, it does emit ordinary functions as children
12871 of a struct DIE. */
12872 if (cu
->lang () == language_rust
)
12873 read_func_scope (child_die
, cu
);
12876 /* C++ member function. */
12877 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
12880 else if (child_die
->tag
== DW_TAG_inheritance
)
12882 /* C++ base class field. */
12883 dwarf2_add_field (fi
, child_die
, cu
);
12885 else if (type_can_define_types (child_die
))
12886 dwarf2_add_type_defn (fi
, child_die
, cu
);
12887 else if (child_die
->tag
== DW_TAG_template_type_param
12888 || child_die
->tag
== DW_TAG_template_value_param
)
12890 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12893 template_args
->push_back (arg
);
12895 else if (child_die
->tag
== DW_TAG_variant_part
)
12896 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
12897 else if (child_die
->tag
== DW_TAG_variant
)
12898 handle_variant (child_die
, type
, fi
, template_args
, cu
);
12901 /* Finish creating a structure or union type, including filling in its
12902 members and creating a symbol for it. This function also handles Fortran
12903 namelist variables, their items or members and creating a symbol for
12907 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12909 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12910 struct die_info
*child_die
;
12913 type
= get_die_type (die
, cu
);
12915 type
= read_structure_type (die
, cu
);
12917 bool has_template_parameters
= false;
12918 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
12920 struct field_info fi
;
12921 std::vector
<struct symbol
*> template_args
;
12923 child_die
= die
->child
;
12925 while (child_die
&& child_die
->tag
)
12927 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
12928 child_die
= child_die
->sibling
;
12931 /* Attach template arguments to type. */
12932 if (!template_args
.empty ())
12934 has_template_parameters
= true;
12935 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
12936 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
12937 TYPE_TEMPLATE_ARGUMENTS (type
)
12938 = XOBNEWVEC (&objfile
->objfile_obstack
,
12940 TYPE_N_TEMPLATE_ARGUMENTS (type
));
12941 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
12942 template_args
.data (),
12943 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
12944 * sizeof (struct symbol
*)));
12947 /* Attach fields and member functions to the type. */
12948 if (fi
.nfields () > 0)
12949 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
12950 if (!fi
.fnfieldlists
.empty ())
12952 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
12954 /* Get the type which refers to the base class (possibly this
12955 class itself) which contains the vtable pointer for the current
12956 class from the DW_AT_containing_type attribute. This use of
12957 DW_AT_containing_type is a GNU extension. */
12959 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
12961 struct type
*t
= die_containing_type (die
, cu
);
12963 set_type_vptr_basetype (type
, t
);
12968 /* Our own class provides vtbl ptr. */
12969 for (i
= t
->num_fields () - 1;
12970 i
>= TYPE_N_BASECLASSES (t
);
12973 const char *fieldname
= t
->field (i
).name ();
12975 if (is_vtable_name (fieldname
, cu
))
12977 set_type_vptr_fieldno (type
, i
);
12982 /* Complain if virtual function table field not found. */
12983 if (i
< TYPE_N_BASECLASSES (t
))
12984 complaint (_("virtual function table pointer "
12985 "not found when defining class '%s'"),
12986 type
->name () ? type
->name () : "");
12990 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
12993 else if (cu
->producer
12994 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
12996 /* The IBM XLC compiler does not provide direct indication
12997 of the containing type, but the vtable pointer is
12998 always named __vfp. */
13002 for (i
= type
->num_fields () - 1;
13003 i
>= TYPE_N_BASECLASSES (type
);
13006 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
13008 set_type_vptr_fieldno (type
, i
);
13009 set_type_vptr_basetype (type
, type
);
13016 /* Copy fi.typedef_field_list linked list elements content into the
13017 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
13018 if (!fi
.typedef_field_list
.empty ())
13020 int count
= fi
.typedef_field_list
.size ();
13022 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13023 TYPE_TYPEDEF_FIELD_ARRAY (type
)
13024 = ((struct decl_field
*)
13026 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
13027 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
13029 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
13030 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
13033 /* Copy fi.nested_types_list linked list elements content into the
13034 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
13035 if (!fi
.nested_types_list
.empty ()
13036 && cu
->lang () != language_ada
)
13038 int count
= fi
.nested_types_list
.size ();
13040 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
13041 TYPE_NESTED_TYPES_ARRAY (type
)
13042 = ((struct decl_field
*)
13043 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
13044 TYPE_NESTED_TYPES_COUNT (type
) = count
;
13046 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
13047 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
13051 quirk_gcc_member_function_pointer (type
, objfile
);
13052 if (cu
->lang () == language_rust
&& die
->tag
== DW_TAG_union_type
)
13053 cu
->rust_unions
.push_back (type
);
13054 else if (cu
->lang () == language_ada
)
13055 quirk_ada_thick_pointer_struct (die
, cu
, type
);
13057 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
13058 snapshots) has been known to create a die giving a declaration
13059 for a class that has, as a child, a die giving a definition for a
13060 nested class. So we have to process our children even if the
13061 current die is a declaration. Normally, of course, a declaration
13062 won't have any children at all. */
13064 child_die
= die
->child
;
13066 while (child_die
!= NULL
&& child_die
->tag
)
13068 if (child_die
->tag
== DW_TAG_member
13069 || child_die
->tag
== DW_TAG_variable
13070 || child_die
->tag
== DW_TAG_inheritance
13071 || child_die
->tag
== DW_TAG_template_value_param
13072 || child_die
->tag
== DW_TAG_template_type_param
)
13077 process_die (child_die
, cu
);
13079 child_die
= child_die
->sibling
;
13082 /* Do not consider external references. According to the DWARF standard,
13083 these DIEs are identified by the fact that they have no byte_size
13084 attribute, and a declaration attribute. */
13085 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
13086 || !die_is_declaration (die
, cu
)
13087 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
13089 struct symbol
*sym
= new_symbol (die
, type
, cu
);
13091 if (has_template_parameters
)
13093 struct symtab
*symtab
;
13094 if (sym
!= nullptr)
13095 symtab
= sym
->symtab ();
13096 else if (cu
->line_header
!= nullptr)
13098 /* Any related symtab will do. */
13100 = cu
->line_header
->file_names ()[0].symtab
;
13105 complaint (_("could not find suitable "
13106 "symtab for template parameter"
13107 " - DIE at %s [in module %s]"),
13108 sect_offset_str (die
->sect_off
),
13109 objfile_name (objfile
));
13112 if (symtab
!= nullptr)
13114 /* Make sure that the symtab is set on the new symbols.
13115 Even though they don't appear in this symtab directly,
13116 other parts of gdb assume that symbols do, and this is
13117 reasonably true. */
13118 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
13119 TYPE_TEMPLATE_ARGUMENT (type
, i
)->set_symtab (symtab
);
13125 /* Assuming DIE is an enumeration type, and TYPE is its associated
13126 type, update TYPE using some information only available in DIE's
13127 children. In particular, the fields are computed. */
13130 update_enumeration_type_from_children (struct die_info
*die
,
13132 struct dwarf2_cu
*cu
)
13134 struct die_info
*child_die
;
13135 int unsigned_enum
= 1;
13138 auto_obstack obstack
;
13139 std::vector
<struct field
> fields
;
13141 for (child_die
= die
->child
;
13142 child_die
!= NULL
&& child_die
->tag
;
13143 child_die
= child_die
->sibling
)
13145 struct attribute
*attr
;
13147 const gdb_byte
*bytes
;
13148 struct dwarf2_locexpr_baton
*baton
;
13151 if (child_die
->tag
!= DW_TAG_enumerator
)
13154 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
13158 name
= dwarf2_name (child_die
, cu
);
13160 name
= "<anonymous enumerator>";
13162 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
13163 &value
, &bytes
, &baton
);
13171 if (count_one_bits_ll (value
) >= 2)
13175 fields
.emplace_back ();
13176 struct field
&field
= fields
.back ();
13177 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
13178 field
.set_loc_enumval (value
);
13181 if (!fields
.empty ())
13183 type
->set_num_fields (fields
.size ());
13186 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
13187 memcpy (type
->fields (), fields
.data (),
13188 sizeof (struct field
) * fields
.size ());
13192 type
->set_is_unsigned (true);
13195 type
->set_is_flag_enum (true);
13198 /* Given a DW_AT_enumeration_type die, set its type. We do not
13199 complete the type's fields yet, or create any symbols. */
13201 static struct type
*
13202 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13204 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13206 struct attribute
*attr
;
13209 /* If the definition of this type lives in .debug_types, read that type.
13210 Don't follow DW_AT_specification though, that will take us back up
13211 the chain and we want to go down. */
13212 attr
= die
->attr (DW_AT_signature
);
13213 if (attr
!= nullptr)
13215 type
= get_DW_AT_signature_type (die
, attr
, cu
);
13217 /* The type's CU may not be the same as CU.
13218 Ensure TYPE is recorded with CU in die_type_hash. */
13219 return set_die_type (die
, type
, cu
);
13222 type
= alloc_type (objfile
);
13224 type
->set_code (TYPE_CODE_ENUM
);
13225 name
= dwarf2_full_name (NULL
, die
, cu
);
13227 type
->set_name (name
);
13229 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13232 struct type
*underlying_type
= die_type (die
, cu
);
13234 type
->set_target_type (underlying_type
);
13237 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13238 if (attr
!= nullptr)
13239 type
->set_length (attr
->constant_value (0));
13241 type
->set_length (0);
13243 maybe_set_alignment (cu
, die
, type
);
13245 /* The enumeration DIE can be incomplete. In Ada, any type can be
13246 declared as private in the package spec, and then defined only
13247 inside the package body. Such types are known as Taft Amendment
13248 Types. When another package uses such a type, an incomplete DIE
13249 may be generated by the compiler. */
13250 if (die_is_declaration (die
, cu
))
13251 type
->set_is_stub (true);
13253 /* If this type has an underlying type that is not a stub, then we
13254 may use its attributes. We always use the "unsigned" attribute
13255 in this situation, because ordinarily we guess whether the type
13256 is unsigned -- but the guess can be wrong and the underlying type
13257 can tell us the reality. However, we defer to a local size
13258 attribute if one exists, because this lets the compiler override
13259 the underlying type if needed. */
13260 if (type
->target_type () != NULL
&& !type
->target_type ()->is_stub ())
13262 struct type
*underlying_type
= type
->target_type ();
13263 underlying_type
= check_typedef (underlying_type
);
13265 type
->set_is_unsigned (underlying_type
->is_unsigned ());
13267 if (type
->length () == 0)
13268 type
->set_length (underlying_type
->length ());
13270 if (TYPE_RAW_ALIGN (type
) == 0
13271 && TYPE_RAW_ALIGN (underlying_type
) != 0)
13272 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
13275 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
13277 set_die_type (die
, type
, cu
);
13279 /* Finish the creation of this type by using the enum's children.
13280 Note that, as usual, this must come after set_die_type to avoid
13281 infinite recursion when trying to compute the names of the
13283 update_enumeration_type_from_children (die
, type
, cu
);
13288 /* Given a pointer to a die which begins an enumeration, process all
13289 the dies that define the members of the enumeration, and create the
13290 symbol for the enumeration type.
13292 NOTE: We reverse the order of the element list. */
13295 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13297 struct type
*this_type
;
13299 this_type
= get_die_type (die
, cu
);
13300 if (this_type
== NULL
)
13301 this_type
= read_enumeration_type (die
, cu
);
13303 if (die
->child
!= NULL
)
13305 struct die_info
*child_die
;
13308 child_die
= die
->child
;
13309 while (child_die
&& child_die
->tag
)
13311 if (child_die
->tag
!= DW_TAG_enumerator
)
13313 process_die (child_die
, cu
);
13317 name
= dwarf2_name (child_die
, cu
);
13319 new_symbol (child_die
, this_type
, cu
);
13322 child_die
= child_die
->sibling
;
13326 /* If we are reading an enum from a .debug_types unit, and the enum
13327 is a declaration, and the enum is not the signatured type in the
13328 unit, then we do not want to add a symbol for it. Adding a
13329 symbol would in some cases obscure the true definition of the
13330 enum, giving users an incomplete type when the definition is
13331 actually available. Note that we do not want to do this for all
13332 enums which are just declarations, because C++0x allows forward
13333 enum declarations. */
13334 if (cu
->per_cu
->is_debug_types
13335 && die_is_declaration (die
, cu
))
13337 struct signatured_type
*sig_type
;
13339 sig_type
= (struct signatured_type
*) cu
->per_cu
;
13340 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
13341 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
13345 new_symbol (die
, this_type
, cu
);
13348 /* Helper function for quirk_ada_thick_pointer that examines a bounds
13349 expression for an index type and finds the corresponding field
13350 offset in the hidden "P_BOUNDS" structure. Returns true on success
13351 and updates *FIELD, false if it fails to recognize an
13355 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
13356 int *bounds_offset
, struct field
*field
,
13357 struct dwarf2_cu
*cu
)
13359 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13360 if (attr
== nullptr || !attr
->form_is_block ())
13363 const struct dwarf_block
*block
= attr
->as_block ();
13364 const gdb_byte
*start
= block
->data
;
13365 const gdb_byte
*end
= block
->data
+ block
->size
;
13367 /* The expression to recognize generally looks like:
13369 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13370 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
13372 However, the second "plus_uconst" may be missing:
13374 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13375 DW_OP_deref_size: 4)
13377 This happens when the field is at the start of the structure.
13379 Also, the final deref may not be sized:
13381 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
13384 This happens when the size of the index type happens to be the
13385 same as the architecture's word size. This can occur with or
13386 without the second plus_uconst. */
13388 if (end
- start
< 2)
13390 if (*start
++ != DW_OP_push_object_address
)
13392 if (*start
++ != DW_OP_plus_uconst
)
13395 uint64_t this_bound_off
;
13396 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
13397 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
13399 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
13400 is consistent among all bounds. */
13401 if (*bounds_offset
== -1)
13402 *bounds_offset
= this_bound_off
;
13403 else if (*bounds_offset
!= this_bound_off
)
13406 if (start
== end
|| *start
++ != DW_OP_deref
)
13412 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
13414 /* This means an offset of 0. */
13416 else if (*start
++ != DW_OP_plus_uconst
)
13420 /* The size is the parameter to DW_OP_plus_uconst. */
13422 start
= gdb_read_uleb128 (start
, end
, &val
);
13423 if (start
== nullptr)
13425 if ((int) val
!= val
)
13434 if (*start
== DW_OP_deref_size
)
13436 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
13437 if (start
== nullptr)
13440 else if (*start
== DW_OP_deref
)
13442 size
= cu
->header
.addr_size
;
13448 field
->set_loc_bitpos (8 * offset
);
13449 if (size
!= field
->type ()->length ())
13450 FIELD_BITSIZE (*field
) = 8 * size
;
13455 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
13456 some kinds of Ada arrays:
13458 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
13459 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
13460 <11e0> DW_AT_data_location: 2 byte block: 97 6
13461 (DW_OP_push_object_address; DW_OP_deref)
13462 <11e3> DW_AT_type : <0x1173>
13463 <11e7> DW_AT_sibling : <0x1201>
13464 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
13465 <11ec> DW_AT_type : <0x1206>
13466 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
13467 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13468 DW_OP_deref_size: 4)
13469 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
13470 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
13471 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
13473 This actually represents a "thick pointer", which is a structure
13474 with two elements: one that is a pointer to the array data, and one
13475 that is a pointer to another structure; this second structure holds
13478 This returns a new type on success, or nullptr if this didn't
13479 recognize the type. */
13481 static struct type
*
13482 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
13485 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
13486 /* So far we've only seen this with block form. */
13487 if (attr
== nullptr || !attr
->form_is_block ())
13490 /* Note that this will fail if the structure layout is changed by
13491 the compiler. However, we have no good way to recognize some
13492 other layout, because we don't know what expression the compiler
13493 might choose to emit should this happen. */
13494 struct dwarf_block
*blk
= attr
->as_block ();
13496 || blk
->data
[0] != DW_OP_push_object_address
13497 || blk
->data
[1] != DW_OP_deref
)
13500 int bounds_offset
= -1;
13501 int max_align
= -1;
13502 std::vector
<struct field
> range_fields
;
13503 for (struct die_info
*child_die
= die
->child
;
13505 child_die
= child_die
->sibling
)
13507 if (child_die
->tag
== DW_TAG_subrange_type
)
13509 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
13511 int this_align
= type_align (underlying
);
13512 if (this_align
> max_align
)
13513 max_align
= this_align
;
13515 range_fields
.emplace_back ();
13516 range_fields
.emplace_back ();
13518 struct field
&lower
= range_fields
[range_fields
.size () - 2];
13519 struct field
&upper
= range_fields
[range_fields
.size () - 1];
13521 lower
.set_type (underlying
);
13522 FIELD_ARTIFICIAL (lower
) = 1;
13524 upper
.set_type (underlying
);
13525 FIELD_ARTIFICIAL (upper
) = 1;
13527 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
13528 &bounds_offset
, &lower
, cu
)
13529 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
13530 &bounds_offset
, &upper
, cu
))
13535 /* This shouldn't really happen, but double-check that we found
13536 where the bounds are stored. */
13537 if (bounds_offset
== -1)
13540 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13541 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
13545 /* Set the name of each field in the bounds. */
13546 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
13547 range_fields
[i
].set_name (objfile
->intern (name
));
13548 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
13549 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
13552 struct type
*bounds
= alloc_type (objfile
);
13553 bounds
->set_code (TYPE_CODE_STRUCT
);
13555 bounds
->set_num_fields (range_fields
.size ());
13557 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
13558 * sizeof (struct field
))));
13559 memcpy (bounds
->fields (), range_fields
.data (),
13560 bounds
->num_fields () * sizeof (struct field
));
13562 int last_fieldno
= range_fields
.size () - 1;
13563 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
13564 + bounds
->field (last_fieldno
).type ()->length ());
13565 bounds
->set_length (align_up (bounds_size
, max_align
));
13567 /* Rewrite the existing array type in place. Specifically, we
13568 remove any dynamic properties we might have read, and we replace
13569 the index types. */
13570 struct type
*iter
= type
;
13571 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
13573 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
13574 iter
->main_type
->dyn_prop_list
= nullptr;
13575 iter
->set_index_type
13576 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
13577 iter
= iter
->target_type ();
13580 struct type
*result
= alloc_type (objfile
);
13581 result
->set_code (TYPE_CODE_STRUCT
);
13583 result
->set_num_fields (2);
13585 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
13586 * sizeof (struct field
))));
13588 /* The names are chosen to coincide with what the compiler does with
13589 -fgnat-encodings=all, which the Ada code in gdb already
13591 result
->field (0).set_name ("P_ARRAY");
13592 result
->field (0).set_type (lookup_pointer_type (type
));
13594 result
->field (1).set_name ("P_BOUNDS");
13595 result
->field (1).set_type (lookup_pointer_type (bounds
));
13596 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
13598 result
->set_name (type
->name ());
13599 result
->set_length (result
->field (0).type ()->length ()
13600 + result
->field (1).type ()->length ());
13605 /* Extract all information from a DW_TAG_array_type DIE and put it in
13606 the DIE's type field. For now, this only handles one dimensional
13609 static struct type
*
13610 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13612 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13613 struct die_info
*child_die
;
13615 struct type
*element_type
, *range_type
, *index_type
;
13616 struct attribute
*attr
;
13618 struct dynamic_prop
*byte_stride_prop
= NULL
;
13619 unsigned int bit_stride
= 0;
13621 element_type
= die_type (die
, cu
);
13623 /* The die_type call above may have already set the type for this DIE. */
13624 type
= get_die_type (die
, cu
);
13628 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
13632 struct type
*prop_type
= cu
->addr_sized_int_type (false);
13635 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
13636 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
13640 complaint (_("unable to read array DW_AT_byte_stride "
13641 " - DIE at %s [in module %s]"),
13642 sect_offset_str (die
->sect_off
),
13643 objfile_name (cu
->per_objfile
->objfile
));
13644 /* Ignore this attribute. We will likely not be able to print
13645 arrays of this type correctly, but there is little we can do
13646 to help if we cannot read the attribute's value. */
13647 byte_stride_prop
= NULL
;
13651 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
13653 bit_stride
= attr
->constant_value (0);
13655 /* Irix 6.2 native cc creates array types without children for
13656 arrays with unspecified length. */
13657 if (die
->child
== NULL
)
13659 index_type
= objfile_type (objfile
)->builtin_int
;
13660 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
13661 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
13662 byte_stride_prop
, bit_stride
);
13663 return set_die_type (die
, type
, cu
);
13666 std::vector
<struct type
*> range_types
;
13667 child_die
= die
->child
;
13668 while (child_die
&& child_die
->tag
)
13670 if (child_die
->tag
== DW_TAG_subrange_type
13671 || child_die
->tag
== DW_TAG_generic_subrange
)
13673 struct type
*child_type
= read_type_die (child_die
, cu
);
13675 if (child_type
!= NULL
)
13677 /* The range type was succesfully read. Save it for the
13678 array type creation. */
13679 range_types
.push_back (child_type
);
13682 child_die
= child_die
->sibling
;
13685 if (range_types
.empty ())
13687 complaint (_("unable to find array range - DIE at %s [in module %s]"),
13688 sect_offset_str (die
->sect_off
),
13689 objfile_name (cu
->per_objfile
->objfile
));
13693 /* Dwarf2 dimensions are output from left to right, create the
13694 necessary array types in backwards order. */
13696 type
= element_type
;
13698 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
13702 while (i
< range_types
.size ())
13704 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
13705 byte_stride_prop
, bit_stride
);
13706 type
->set_is_multi_dimensional (true);
13708 byte_stride_prop
= nullptr;
13713 size_t ndim
= range_types
.size ();
13716 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
13717 byte_stride_prop
, bit_stride
);
13718 type
->set_is_multi_dimensional (true);
13720 byte_stride_prop
= nullptr;
13724 /* Clear the flag on the outermost array type. */
13725 type
->set_is_multi_dimensional (false);
13726 gdb_assert (type
!= element_type
);
13728 /* Understand Dwarf2 support for vector types (like they occur on
13729 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
13730 array type. This is not part of the Dwarf2/3 standard yet, but a
13731 custom vendor extension. The main difference between a regular
13732 array and the vector variant is that vectors are passed by value
13734 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
13735 if (attr
!= nullptr)
13736 make_vector_type (type
);
13738 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
13739 implementation may choose to implement triple vectors using this
13741 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13742 if (attr
!= nullptr && attr
->form_is_unsigned ())
13744 if (attr
->as_unsigned () >= type
->length ())
13745 type
->set_length (attr
->as_unsigned ());
13747 complaint (_("DW_AT_byte_size for array type smaller "
13748 "than the total size of elements"));
13751 name
= dwarf2_name (die
, cu
);
13753 type
->set_name (name
);
13755 maybe_set_alignment (cu
, die
, type
);
13757 struct type
*replacement_type
= nullptr;
13758 if (cu
->lang () == language_ada
)
13760 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
13761 if (replacement_type
!= nullptr)
13762 type
= replacement_type
;
13765 /* Install the type in the die. */
13766 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
13768 /* set_die_type should be already done. */
13769 set_descriptive_type (type
, die
, cu
);
13774 static enum dwarf_array_dim_ordering
13775 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
13777 struct attribute
*attr
;
13779 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
13781 if (attr
!= nullptr)
13783 LONGEST val
= attr
->constant_value (-1);
13784 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
13785 return (enum dwarf_array_dim_ordering
) val
;
13788 /* GNU F77 is a special case, as at 08/2004 array type info is the
13789 opposite order to the dwarf2 specification, but data is still
13790 laid out as per normal fortran.
13792 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
13793 version checking. */
13795 if (cu
->lang () == language_fortran
13796 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
13798 return DW_ORD_row_major
;
13801 switch (cu
->language_defn
->array_ordering ())
13803 case array_column_major
:
13804 return DW_ORD_col_major
;
13805 case array_row_major
:
13807 return DW_ORD_row_major
;
13811 /* Extract all information from a DW_TAG_set_type DIE and put it in
13812 the DIE's type field. */
13814 static struct type
*
13815 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13817 struct type
*domain_type
, *set_type
;
13818 struct attribute
*attr
;
13820 domain_type
= die_type (die
, cu
);
13822 /* The die_type call above may have already set the type for this DIE. */
13823 set_type
= get_die_type (die
, cu
);
13827 set_type
= create_set_type (NULL
, domain_type
);
13829 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
13830 if (attr
!= nullptr && attr
->form_is_unsigned ())
13831 set_type
->set_length (attr
->as_unsigned ());
13833 maybe_set_alignment (cu
, die
, set_type
);
13835 return set_die_type (die
, set_type
, cu
);
13838 /* A helper for read_common_block that creates a locexpr baton.
13839 SYM is the symbol which we are marking as computed.
13840 COMMON_DIE is the DIE for the common block.
13841 COMMON_LOC is the location expression attribute for the common
13843 MEMBER_LOC is the location expression attribute for the particular
13844 member of the common block that we are processing.
13845 CU is the CU from which the above come. */
13848 mark_common_block_symbol_computed (struct symbol
*sym
,
13849 struct die_info
*common_die
,
13850 struct attribute
*common_loc
,
13851 struct attribute
*member_loc
,
13852 struct dwarf2_cu
*cu
)
13854 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13855 struct objfile
*objfile
= per_objfile
->objfile
;
13856 struct dwarf2_locexpr_baton
*baton
;
13858 unsigned int cu_off
;
13859 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
13860 LONGEST offset
= 0;
13862 gdb_assert (common_loc
&& member_loc
);
13863 gdb_assert (common_loc
->form_is_block ());
13864 gdb_assert (member_loc
->form_is_block ()
13865 || member_loc
->form_is_constant ());
13867 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13868 baton
->per_objfile
= per_objfile
;
13869 baton
->per_cu
= cu
->per_cu
;
13870 gdb_assert (baton
->per_cu
);
13872 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
13874 if (member_loc
->form_is_constant ())
13876 offset
= member_loc
->constant_value (0);
13877 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
13880 baton
->size
+= member_loc
->as_block ()->size
;
13882 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
13885 *ptr
++ = DW_OP_call4
;
13886 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
13887 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
13890 if (member_loc
->form_is_constant ())
13892 *ptr
++ = DW_OP_addr
;
13893 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
13894 ptr
+= cu
->header
.addr_size
;
13898 /* We have to copy the data here, because DW_OP_call4 will only
13899 use a DW_AT_location attribute. */
13900 struct dwarf_block
*block
= member_loc
->as_block ();
13901 memcpy (ptr
, block
->data
, block
->size
);
13902 ptr
+= block
->size
;
13905 *ptr
++ = DW_OP_plus
;
13906 gdb_assert (ptr
- baton
->data
== baton
->size
);
13908 SYMBOL_LOCATION_BATON (sym
) = baton
;
13909 sym
->set_aclass_index (dwarf2_locexpr_index
);
13912 /* Create appropriate locally-scoped variables for all the
13913 DW_TAG_common_block entries. Also create a struct common_block
13914 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
13915 is used to separate the common blocks name namespace from regular
13919 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
13921 struct attribute
*attr
;
13923 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13924 if (attr
!= nullptr)
13926 /* Support the .debug_loc offsets. */
13927 if (attr
->form_is_block ())
13931 else if (attr
->form_is_section_offset ())
13933 dwarf2_complex_location_expr_complaint ();
13938 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13939 "common block member");
13944 if (die
->child
!= NULL
)
13946 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13947 struct die_info
*child_die
;
13948 size_t n_entries
= 0, size
;
13949 struct common_block
*common_block
;
13950 struct symbol
*sym
;
13952 for (child_die
= die
->child
;
13953 child_die
&& child_die
->tag
;
13954 child_die
= child_die
->sibling
)
13957 size
= (sizeof (struct common_block
)
13958 + (n_entries
- 1) * sizeof (struct symbol
*));
13960 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
13962 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
13963 common_block
->n_entries
= 0;
13965 for (child_die
= die
->child
;
13966 child_die
&& child_die
->tag
;
13967 child_die
= child_die
->sibling
)
13969 /* Create the symbol in the DW_TAG_common_block block in the current
13971 sym
= new_symbol (child_die
, NULL
, cu
);
13974 struct attribute
*member_loc
;
13976 common_block
->contents
[common_block
->n_entries
++] = sym
;
13978 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
13982 /* GDB has handled this for a long time, but it is
13983 not specified by DWARF. It seems to have been
13984 emitted by gfortran at least as recently as:
13985 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
13986 complaint (_("Variable in common block has "
13987 "DW_AT_data_member_location "
13988 "- DIE at %s [in module %s]"),
13989 sect_offset_str (child_die
->sect_off
),
13990 objfile_name (objfile
));
13992 if (member_loc
->form_is_section_offset ())
13993 dwarf2_complex_location_expr_complaint ();
13994 else if (member_loc
->form_is_constant ()
13995 || member_loc
->form_is_block ())
13997 if (attr
!= nullptr)
13998 mark_common_block_symbol_computed (sym
, die
, attr
,
14002 dwarf2_complex_location_expr_complaint ();
14007 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
14008 sym
->set_value_common_block (common_block
);
14012 /* Create a type for a C++ namespace. */
14014 static struct type
*
14015 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14017 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14018 const char *previous_prefix
, *name
;
14022 /* For extensions, reuse the type of the original namespace. */
14023 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
14025 struct die_info
*ext_die
;
14026 struct dwarf2_cu
*ext_cu
= cu
;
14028 ext_die
= dwarf2_extension (die
, &ext_cu
);
14029 type
= read_type_die (ext_die
, ext_cu
);
14031 /* EXT_CU may not be the same as CU.
14032 Ensure TYPE is recorded with CU in die_type_hash. */
14033 return set_die_type (die
, type
, cu
);
14036 name
= namespace_name (die
, &is_anonymous
, cu
);
14038 /* Now build the name of the current namespace. */
14040 previous_prefix
= determine_prefix (die
, cu
);
14041 if (previous_prefix
[0] != '\0')
14042 name
= typename_concat (&objfile
->objfile_obstack
,
14043 previous_prefix
, name
, 0, cu
);
14045 /* Create the type. */
14046 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
14048 return set_die_type (die
, type
, cu
);
14051 /* Read a namespace scope. */
14054 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
14056 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14059 /* Add a symbol associated to this if we haven't seen the namespace
14060 before. Also, add a using directive if it's an anonymous
14063 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
14067 type
= read_type_die (die
, cu
);
14068 new_symbol (die
, type
, cu
);
14070 namespace_name (die
, &is_anonymous
, cu
);
14073 const char *previous_prefix
= determine_prefix (die
, cu
);
14075 std::vector
<const char *> excludes
;
14076 add_using_directive (using_directives (cu
),
14077 previous_prefix
, type
->name (), NULL
,
14079 read_decl_line (die
, cu
),
14080 0, &objfile
->objfile_obstack
);
14084 if (die
->child
!= NULL
)
14086 struct die_info
*child_die
= die
->child
;
14088 while (child_die
&& child_die
->tag
)
14090 process_die (child_die
, cu
);
14091 child_die
= child_die
->sibling
;
14096 /* Read a Fortran module as type. This DIE can be only a declaration used for
14097 imported module. Still we need that type as local Fortran "use ... only"
14098 declaration imports depend on the created type in determine_prefix. */
14100 static struct type
*
14101 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14103 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14104 const char *module_name
;
14107 module_name
= dwarf2_name (die
, cu
);
14108 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
14110 return set_die_type (die
, type
, cu
);
14113 /* Read a Fortran module. */
14116 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
14118 struct die_info
*child_die
= die
->child
;
14121 type
= read_type_die (die
, cu
);
14122 new_symbol (die
, type
, cu
);
14124 while (child_die
&& child_die
->tag
)
14126 process_die (child_die
, cu
);
14127 child_die
= child_die
->sibling
;
14131 /* Return the name of the namespace represented by DIE. Set
14132 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
14135 static const char *
14136 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
14138 struct die_info
*current_die
;
14139 const char *name
= NULL
;
14141 /* Loop through the extensions until we find a name. */
14143 for (current_die
= die
;
14144 current_die
!= NULL
;
14145 current_die
= dwarf2_extension (die
, &cu
))
14147 /* We don't use dwarf2_name here so that we can detect the absence
14148 of a name -> anonymous namespace. */
14149 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
14155 /* Is it an anonymous namespace? */
14157 *is_anonymous
= (name
== NULL
);
14159 name
= CP_ANONYMOUS_NAMESPACE_STR
;
14164 /* Extract all information from a DW_TAG_pointer_type DIE and add to
14165 the user defined type vector. */
14167 static struct type
*
14168 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14170 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
14171 struct comp_unit_head
*cu_header
= &cu
->header
;
14173 struct attribute
*attr_byte_size
;
14174 struct attribute
*attr_address_class
;
14175 int byte_size
, addr_class
;
14176 struct type
*target_type
;
14178 target_type
= die_type (die
, cu
);
14180 /* The die_type call above may have already set the type for this DIE. */
14181 type
= get_die_type (die
, cu
);
14185 type
= lookup_pointer_type (target_type
);
14187 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14188 if (attr_byte_size
)
14189 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
14191 byte_size
= cu_header
->addr_size
;
14193 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
14194 if (attr_address_class
)
14195 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
14197 addr_class
= DW_ADDR_none
;
14199 ULONGEST alignment
= get_alignment (cu
, die
);
14201 /* If the pointer size, alignment, or address class is different
14202 than the default, create a type variant marked as such and set
14203 the length accordingly. */
14204 if (type
->length () != byte_size
14205 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
14206 && alignment
!= TYPE_RAW_ALIGN (type
))
14207 || addr_class
!= DW_ADDR_none
)
14209 if (gdbarch_address_class_type_flags_p (gdbarch
))
14211 type_instance_flags type_flags
14212 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
14214 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
14216 type
= make_type_with_address_space (type
, type_flags
);
14218 else if (type
->length () != byte_size
)
14220 complaint (_("invalid pointer size %d"), byte_size
);
14222 else if (TYPE_RAW_ALIGN (type
) != alignment
)
14224 complaint (_("Invalid DW_AT_alignment"
14225 " - DIE at %s [in module %s]"),
14226 sect_offset_str (die
->sect_off
),
14227 objfile_name (cu
->per_objfile
->objfile
));
14231 /* Should we also complain about unhandled address classes? */
14235 type
->set_length (byte_size
);
14236 set_type_align (type
, alignment
);
14237 return set_die_type (die
, type
, cu
);
14240 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
14241 the user defined type vector. */
14243 static struct type
*
14244 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14247 struct type
*to_type
;
14248 struct type
*domain
;
14250 to_type
= die_type (die
, cu
);
14251 domain
= die_containing_type (die
, cu
);
14253 /* The calls above may have already set the type for this DIE. */
14254 type
= get_die_type (die
, cu
);
14258 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
14259 type
= lookup_methodptr_type (to_type
);
14260 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
14262 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
14264 smash_to_method_type (new_type
, domain
, to_type
->target_type (),
14265 to_type
->fields (), to_type
->num_fields (),
14266 to_type
->has_varargs ());
14267 type
= lookup_methodptr_type (new_type
);
14270 type
= lookup_memberptr_type (to_type
, domain
);
14272 return set_die_type (die
, type
, cu
);
14275 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
14276 the user defined type vector. */
14278 static struct type
*
14279 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14280 enum type_code refcode
)
14282 struct comp_unit_head
*cu_header
= &cu
->header
;
14283 struct type
*type
, *target_type
;
14284 struct attribute
*attr
;
14286 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
14288 target_type
= die_type (die
, cu
);
14290 /* The die_type call above may have already set the type for this DIE. */
14291 type
= get_die_type (die
, cu
);
14295 type
= lookup_reference_type (target_type
, refcode
);
14296 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14297 if (attr
!= nullptr)
14298 type
->set_length (attr
->constant_value (cu_header
->addr_size
));
14300 type
->set_length (cu_header
->addr_size
);
14302 maybe_set_alignment (cu
, die
, type
);
14303 return set_die_type (die
, type
, cu
);
14306 /* Add the given cv-qualifiers to the element type of the array. GCC
14307 outputs DWARF type qualifiers that apply to an array, not the
14308 element type. But GDB relies on the array element type to carry
14309 the cv-qualifiers. This mimics section 6.7.3 of the C99
14312 static struct type
*
14313 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
14314 struct type
*base_type
, int cnst
, int voltl
)
14316 struct type
*el_type
, *inner_array
;
14318 base_type
= copy_type (base_type
);
14319 inner_array
= base_type
;
14321 while (inner_array
->target_type ()->code () == TYPE_CODE_ARRAY
)
14323 inner_array
->set_target_type (copy_type (inner_array
->target_type ()));
14324 inner_array
= inner_array
->target_type ();
14327 el_type
= inner_array
->target_type ();
14328 cnst
|= TYPE_CONST (el_type
);
14329 voltl
|= TYPE_VOLATILE (el_type
);
14330 inner_array
->set_target_type (make_cv_type (cnst
, voltl
, el_type
, NULL
));
14332 return set_die_type (die
, base_type
, cu
);
14335 static struct type
*
14336 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14338 struct type
*base_type
, *cv_type
;
14340 base_type
= die_type (die
, cu
);
14342 /* The die_type call above may have already set the type for this DIE. */
14343 cv_type
= get_die_type (die
, cu
);
14347 /* In case the const qualifier is applied to an array type, the element type
14348 is so qualified, not the array type (section 6.7.3 of C99). */
14349 if (base_type
->code () == TYPE_CODE_ARRAY
)
14350 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
14352 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
14353 return set_die_type (die
, cv_type
, cu
);
14356 static struct type
*
14357 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14359 struct type
*base_type
, *cv_type
;
14361 base_type
= die_type (die
, cu
);
14363 /* The die_type call above may have already set the type for this DIE. */
14364 cv_type
= get_die_type (die
, cu
);
14368 /* In case the volatile qualifier is applied to an array type, the
14369 element type is so qualified, not the array type (section 6.7.3
14371 if (base_type
->code () == TYPE_CODE_ARRAY
)
14372 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
14374 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
14375 return set_die_type (die
, cv_type
, cu
);
14378 /* Handle DW_TAG_restrict_type. */
14380 static struct type
*
14381 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14383 struct type
*base_type
, *cv_type
;
14385 base_type
= die_type (die
, cu
);
14387 /* The die_type call above may have already set the type for this DIE. */
14388 cv_type
= get_die_type (die
, cu
);
14392 cv_type
= make_restrict_type (base_type
);
14393 return set_die_type (die
, cv_type
, cu
);
14396 /* Handle DW_TAG_atomic_type. */
14398 static struct type
*
14399 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14401 struct type
*base_type
, *cv_type
;
14403 base_type
= die_type (die
, cu
);
14405 /* The die_type call above may have already set the type for this DIE. */
14406 cv_type
= get_die_type (die
, cu
);
14410 cv_type
= make_atomic_type (base_type
);
14411 return set_die_type (die
, cv_type
, cu
);
14414 /* Extract all information from a DW_TAG_string_type DIE and add to
14415 the user defined type vector. It isn't really a user defined type,
14416 but it behaves like one, with other DIE's using an AT_user_def_type
14417 attribute to reference it. */
14419 static struct type
*
14420 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14422 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14423 struct gdbarch
*gdbarch
= objfile
->arch ();
14424 struct type
*type
, *range_type
, *index_type
, *char_type
;
14425 struct attribute
*attr
;
14426 struct dynamic_prop prop
;
14427 bool length_is_constant
= true;
14430 /* There are a couple of places where bit sizes might be made use of
14431 when parsing a DW_TAG_string_type, however, no producer that we know
14432 of make use of these. Handling bit sizes that are a multiple of the
14433 byte size is easy enough, but what about other bit sizes? Lets deal
14434 with that problem when we have to. Warn about these attributes being
14435 unsupported, then parse the type and ignore them like we always
14437 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
14438 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
14440 static bool warning_printed
= false;
14441 if (!warning_printed
)
14443 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
14444 "currently supported on DW_TAG_string_type."));
14445 warning_printed
= true;
14449 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
14450 if (attr
!= nullptr && !attr
->form_is_constant ())
14452 /* The string length describes the location at which the length of
14453 the string can be found. The size of the length field can be
14454 specified with one of the attributes below. */
14455 struct type
*prop_type
;
14456 struct attribute
*len
14457 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
14458 if (len
== nullptr)
14459 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14460 if (len
!= nullptr && len
->form_is_constant ())
14462 /* Pass 0 as the default as we know this attribute is constant
14463 and the default value will not be returned. */
14464 LONGEST sz
= len
->constant_value (0);
14465 prop_type
= objfile_int_type (objfile
, sz
, true);
14469 /* If the size is not specified then we assume it is the size of
14470 an address on this target. */
14471 prop_type
= cu
->addr_sized_int_type (true);
14474 /* Convert the attribute into a dynamic property. */
14475 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
14478 length_is_constant
= false;
14480 else if (attr
!= nullptr)
14482 /* This DW_AT_string_length just contains the length with no
14483 indirection. There's no need to create a dynamic property in this
14484 case. Pass 0 for the default value as we know it will not be
14485 returned in this case. */
14486 length
= attr
->constant_value (0);
14488 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
14490 /* We don't currently support non-constant byte sizes for strings. */
14491 length
= attr
->constant_value (1);
14495 /* Use 1 as a fallback length if we have nothing else. */
14499 index_type
= objfile_type (objfile
)->builtin_int
;
14500 if (length_is_constant
)
14501 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
14504 struct dynamic_prop low_bound
;
14506 low_bound
.set_const_val (1);
14507 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
14509 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
14510 type
= create_string_type (NULL
, char_type
, range_type
);
14512 return set_die_type (die
, type
, cu
);
14515 /* Assuming that DIE corresponds to a function, returns nonzero
14516 if the function is prototyped. */
14519 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
14521 struct attribute
*attr
;
14523 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
14524 if (attr
&& attr
->as_boolean ())
14527 /* The DWARF standard implies that the DW_AT_prototyped attribute
14528 is only meaningful for C, but the concept also extends to other
14529 languages that allow unprototyped functions (Eg: Objective C).
14530 For all other languages, assume that functions are always
14532 if (cu
->lang () != language_c
14533 && cu
->lang () != language_objc
14534 && cu
->lang () != language_opencl
)
14537 /* RealView does not emit DW_AT_prototyped. We can not distinguish
14538 prototyped and unprototyped functions; default to prototyped,
14539 since that is more common in modern code (and RealView warns
14540 about unprototyped functions). */
14541 if (producer_is_realview (cu
->producer
))
14547 /* Handle DIES due to C code like:
14551 int (*funcp)(int a, long l);
14555 ('funcp' generates a DW_TAG_subroutine_type DIE). */
14557 static struct type
*
14558 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14560 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14561 struct type
*type
; /* Type that this function returns. */
14562 struct type
*ftype
; /* Function that returns above type. */
14563 struct attribute
*attr
;
14565 type
= die_type (die
, cu
);
14567 /* The die_type call above may have already set the type for this DIE. */
14568 ftype
= get_die_type (die
, cu
);
14572 ftype
= lookup_function_type (type
);
14574 if (prototyped_function_p (die
, cu
))
14575 ftype
->set_is_prototyped (true);
14577 /* Store the calling convention in the type if it's available in
14578 the subroutine die. Otherwise set the calling convention to
14579 the default value DW_CC_normal. */
14580 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14581 if (attr
!= nullptr
14582 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
14583 TYPE_CALLING_CONVENTION (ftype
)
14584 = (enum dwarf_calling_convention
) attr
->constant_value (0);
14585 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
14586 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
14588 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
14590 /* Record whether the function returns normally to its caller or not
14591 if the DWARF producer set that information. */
14592 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
14593 if (attr
&& attr
->as_boolean ())
14594 TYPE_NO_RETURN (ftype
) = 1;
14596 /* We need to add the subroutine type to the die immediately so
14597 we don't infinitely recurse when dealing with parameters
14598 declared as the same subroutine type. */
14599 set_die_type (die
, ftype
, cu
);
14601 if (die
->child
!= NULL
)
14603 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
14604 struct die_info
*child_die
;
14605 int nparams
, iparams
;
14607 /* Count the number of parameters.
14608 FIXME: GDB currently ignores vararg functions, but knows about
14609 vararg member functions. */
14611 child_die
= die
->child
;
14612 while (child_die
&& child_die
->tag
)
14614 if (child_die
->tag
== DW_TAG_formal_parameter
)
14616 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
14617 ftype
->set_has_varargs (true);
14619 child_die
= child_die
->sibling
;
14622 /* Allocate storage for parameters and fill them in. */
14623 ftype
->set_num_fields (nparams
);
14625 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
14627 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
14628 even if we error out during the parameters reading below. */
14629 for (iparams
= 0; iparams
< nparams
; iparams
++)
14630 ftype
->field (iparams
).set_type (void_type
);
14633 child_die
= die
->child
;
14634 while (child_die
&& child_die
->tag
)
14636 if (child_die
->tag
== DW_TAG_formal_parameter
)
14638 struct type
*arg_type
;
14640 /* DWARF version 2 has no clean way to discern C++
14641 static and non-static member functions. G++ helps
14642 GDB by marking the first parameter for non-static
14643 member functions (which is the this pointer) as
14644 artificial. We pass this information to
14645 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
14647 DWARF version 3 added DW_AT_object_pointer, which GCC
14648 4.5 does not yet generate. */
14649 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
14650 if (attr
!= nullptr)
14651 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
14653 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
14654 arg_type
= die_type (child_die
, cu
);
14656 /* RealView does not mark THIS as const, which the testsuite
14657 expects. GCC marks THIS as const in method definitions,
14658 but not in the class specifications (GCC PR 43053). */
14659 if (cu
->lang () == language_cplus
14660 && !TYPE_CONST (arg_type
)
14661 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
14664 struct dwarf2_cu
*arg_cu
= cu
;
14665 const char *name
= dwarf2_name (child_die
, cu
);
14667 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
14668 if (attr
!= nullptr)
14670 /* If the compiler emits this, use it. */
14671 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
14674 else if (name
&& strcmp (name
, "this") == 0)
14675 /* Function definitions will have the argument names. */
14677 else if (name
== NULL
&& iparams
== 0)
14678 /* Declarations may not have the names, so like
14679 elsewhere in GDB, assume an artificial first
14680 argument is "this". */
14684 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
14688 ftype
->field (iparams
).set_type (arg_type
);
14691 child_die
= child_die
->sibling
;
14698 static struct type
*
14699 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
14701 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14702 const char *name
= NULL
;
14703 struct type
*this_type
, *target_type
;
14705 name
= dwarf2_full_name (NULL
, die
, cu
);
14706 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
14707 this_type
->set_target_is_stub (true);
14708 set_die_type (die
, this_type
, cu
);
14709 target_type
= die_type (die
, cu
);
14710 if (target_type
!= this_type
)
14711 this_type
->set_target_type (target_type
);
14714 /* Self-referential typedefs are, it seems, not allowed by the DWARF
14715 spec and cause infinite loops in GDB. */
14716 complaint (_("Self-referential DW_TAG_typedef "
14717 "- DIE at %s [in module %s]"),
14718 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14719 this_type
->set_target_type (nullptr);
14723 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
14724 anonymous typedefs, which is, strictly speaking, invalid DWARF.
14725 Handle these by just returning the target type, rather than
14726 constructing an anonymous typedef type and trying to handle this
14728 set_die_type (die
, target_type
, cu
);
14729 return target_type
;
14734 /* Helper for get_dwarf2_rational_constant that computes the value of
14735 a given gmp_mpz given an attribute. */
14738 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
14740 /* GCC will sometimes emit a 16-byte constant value as a DWARF
14741 location expression that pushes an implicit value. */
14742 if (attr
->form
== DW_FORM_exprloc
)
14744 dwarf_block
*blk
= attr
->as_block ();
14745 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
14748 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
14749 blk
->data
+ blk
->size
,
14751 if (ptr
- blk
->data
+ len
<= blk
->size
)
14753 mpz_import (value
->val
, len
,
14754 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
.get ())
14761 /* On failure set it to 1. */
14762 *value
= gdb_mpz (1);
14764 else if (attr
->form_is_block ())
14766 dwarf_block
*blk
= attr
->as_block ();
14767 mpz_import (value
->val
, blk
->size
,
14768 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
.get ())
14770 1, 0, 0, blk
->data
);
14773 *value
= gdb_mpz (attr
->constant_value (1));
14776 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
14777 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
14779 If the numerator and/or numerator attribute is missing,
14780 a complaint is filed, and NUMERATOR and DENOMINATOR are left
14784 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
14785 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
14787 struct attribute
*num_attr
, *denom_attr
;
14789 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
14790 if (num_attr
== nullptr)
14791 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
14792 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
14794 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
14795 if (denom_attr
== nullptr)
14796 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
14797 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
14799 if (num_attr
== nullptr || denom_attr
== nullptr)
14802 get_mpz (cu
, numerator
, num_attr
);
14803 get_mpz (cu
, denominator
, denom_attr
);
14806 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
14807 rational constant, rather than a signed one.
14809 If the rational constant has a negative value, a complaint
14810 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
14813 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
14814 struct dwarf2_cu
*cu
,
14815 gdb_mpz
*numerator
,
14816 gdb_mpz
*denominator
)
14821 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
14822 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
14824 mpz_neg (num
.val
, num
.val
);
14825 mpz_neg (denom
.val
, denom
.val
);
14827 else if (mpz_sgn (num
.val
) == -1)
14829 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
14831 sect_offset_str (die
->sect_off
));
14834 else if (mpz_sgn (denom
.val
) == -1)
14836 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
14838 sect_offset_str (die
->sect_off
));
14842 *numerator
= std::move (num
);
14843 *denominator
= std::move (denom
);
14846 /* Assuming that ENCODING is a string whose contents starting at the
14847 K'th character is "_nn" where "nn" is a decimal number, scan that
14848 number and set RESULT to the value. K is updated to point to the
14849 character immediately following the number.
14851 If the string does not conform to the format described above, false
14852 is returned, and K may or may not be changed. */
14855 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
14857 /* The next character should be an underscore ('_') followed
14859 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
14862 /* Skip the underscore. */
14866 /* Determine the number of digits for our number. */
14867 while (isdigit (encoding
[k
]))
14872 std::string
copy (&encoding
[start
], k
- start
);
14873 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
14879 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
14880 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
14881 DENOM, update OFFSET, and return true on success. Return false on
14885 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
14886 gdb_mpz
*num
, gdb_mpz
*denom
)
14888 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
14890 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
14893 /* Assuming DIE corresponds to a fixed point type, finish the creation
14894 of the corresponding TYPE by setting its type-specific data. CU is
14895 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
14896 encodings. It is nullptr if the GNAT encoding should be
14900 finish_fixed_point_type (struct type
*type
, const char *suffix
,
14901 struct die_info
*die
, struct dwarf2_cu
*cu
)
14903 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
14904 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
14906 /* If GNAT encodings are preferred, don't examine the
14908 struct attribute
*attr
= nullptr;
14909 if (suffix
== nullptr)
14911 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
14912 if (attr
== nullptr)
14913 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
14914 if (attr
== nullptr)
14915 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
14918 /* Numerator and denominator of our fixed-point type's scaling factor.
14919 The default is a scaling factor of 1, which we use as a fallback
14920 when we are not able to decode it (problem with the debugging info,
14921 unsupported forms, bug in GDB, etc...). Using that as the default
14922 allows us to at least print the unscaled value, which might still
14923 be useful to a user. */
14924 gdb_mpz
scale_num (1);
14925 gdb_mpz
scale_denom (1);
14927 if (attr
== nullptr)
14930 if (suffix
!= nullptr
14931 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
14933 /* The number might be encoded as _nn_dd_nn_dd, where the
14934 second ratio is the 'small value. In this situation, we
14935 want the second value. */
14936 && (suffix
[offset
] != '_'
14937 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
14944 /* Scaling factor not found. Assume a scaling factor of 1,
14945 and hope for the best. At least the user will be able to
14946 see the encoded value. */
14949 complaint (_("no scale found for fixed-point type (DIE at %s)"),
14950 sect_offset_str (die
->sect_off
));
14953 else if (attr
->name
== DW_AT_binary_scale
)
14955 LONGEST scale_exp
= attr
->constant_value (0);
14956 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
14958 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
14960 else if (attr
->name
== DW_AT_decimal_scale
)
14962 LONGEST scale_exp
= attr
->constant_value (0);
14963 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
14965 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
14967 else if (attr
->name
== DW_AT_small
)
14969 struct die_info
*scale_die
;
14970 struct dwarf2_cu
*scale_cu
= cu
;
14972 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
14973 if (scale_die
->tag
== DW_TAG_constant
)
14974 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
14975 &scale_num
, &scale_denom
);
14977 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
14979 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
14983 complaint (_("unsupported scale attribute %s for fixed-point type"
14985 dwarf_attr_name (attr
->name
),
14986 sect_offset_str (die
->sect_off
));
14989 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
14990 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
14991 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
14992 mpq_canonicalize (scaling_factor
.val
);
14995 /* The gnat-encoding suffix for fixed point. */
14997 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
14999 /* If NAME encodes an Ada fixed-point type, return a pointer to the
15000 "XF" suffix of the name. The text after this is what encodes the
15001 'small and 'delta information. Otherwise, return nullptr. */
15003 static const char *
15004 gnat_encoded_fixed_point_type_info (const char *name
)
15006 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
15009 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
15010 (which may be different from NAME) to the architecture back-end to allow
15011 it to guess the correct format if necessary. */
15013 static struct type
*
15014 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
15015 const char *name_hint
, enum bfd_endian byte_order
)
15017 struct gdbarch
*gdbarch
= objfile
->arch ();
15018 const struct floatformat
**format
;
15021 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
15023 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
15025 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15030 /* Allocate an integer type of size BITS and name NAME. */
15032 static struct type
*
15033 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
15034 int bits
, int unsigned_p
, const char *name
)
15038 /* Versions of Intel's C Compiler generate an integer type called "void"
15039 instead of using DW_TAG_unspecified_type. This has been seen on
15040 at least versions 14, 17, and 18. */
15041 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
15042 && strcmp (name
, "void") == 0)
15043 type
= objfile_type (objfile
)->builtin_void
;
15045 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
15050 /* Return true if DIE has a DW_AT_small attribute whose value is
15051 a constant rational, where both the numerator and denominator
15054 CU is the DIE's Compilation Unit. */
15057 has_zero_over_zero_small_attribute (struct die_info
*die
,
15058 struct dwarf2_cu
*cu
)
15060 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
15061 if (attr
== nullptr)
15064 struct dwarf2_cu
*scale_cu
= cu
;
15065 struct die_info
*scale_die
15066 = follow_die_ref (die
, attr
, &scale_cu
);
15068 if (scale_die
->tag
!= DW_TAG_constant
)
15071 gdb_mpz
num (1), denom (1);
15072 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
15073 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
15076 /* Initialise and return a floating point type of size BITS suitable for
15077 use as a component of a complex number. The NAME_HINT is passed through
15078 when initialising the floating point type and is the name of the complex
15081 As DWARF doesn't currently provide an explicit name for the components
15082 of a complex number, but it can be helpful to have these components
15083 named, we try to select a suitable name based on the size of the
15085 static struct type
*
15086 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
15087 struct objfile
*objfile
,
15088 int bits
, const char *name_hint
,
15089 enum bfd_endian byte_order
)
15091 gdbarch
*gdbarch
= objfile
->arch ();
15092 struct type
*tt
= nullptr;
15094 /* Try to find a suitable floating point builtin type of size BITS.
15095 We're going to use the name of this type as the name for the complex
15096 target type that we are about to create. */
15097 switch (cu
->lang ())
15099 case language_fortran
:
15103 tt
= builtin_f_type (gdbarch
)->builtin_real
;
15106 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
15108 case 96: /* The x86-32 ABI specifies 96-bit long double. */
15110 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
15118 tt
= builtin_type (gdbarch
)->builtin_float
;
15121 tt
= builtin_type (gdbarch
)->builtin_double
;
15123 case 96: /* The x86-32 ABI specifies 96-bit long double. */
15125 tt
= builtin_type (gdbarch
)->builtin_long_double
;
15131 /* If the type we found doesn't match the size we were looking for, then
15132 pretend we didn't find a type at all, the complex target type we
15133 create will then be nameless. */
15134 if (tt
!= nullptr && tt
->length () * TARGET_CHAR_BIT
!= bits
)
15137 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
15138 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
15141 /* Find a representation of a given base type and install
15142 it in the TYPE field of the die. */
15144 static struct type
*
15145 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15147 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15149 struct attribute
*attr
;
15150 int encoding
= 0, bits
= 0;
15154 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
15155 if (attr
!= nullptr && attr
->form_is_constant ())
15156 encoding
= attr
->constant_value (0);
15157 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15158 if (attr
!= nullptr)
15159 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
15160 name
= dwarf2_name (die
, cu
);
15162 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
15164 arch
= objfile
->arch ();
15165 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
15167 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
15168 if (attr
!= nullptr && attr
->form_is_constant ())
15170 int endianity
= attr
->constant_value (0);
15175 byte_order
= BFD_ENDIAN_BIG
;
15177 case DW_END_little
:
15178 byte_order
= BFD_ENDIAN_LITTLE
;
15181 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
15186 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
15187 && cu
->lang () == language_ada
15188 && has_zero_over_zero_small_attribute (die
, cu
))
15190 /* brobecker/2018-02-24: This is a fixed point type for which
15191 the scaling factor is represented as fraction whose value
15192 does not make sense (zero divided by zero), so we should
15193 normally never see these. However, there is a small category
15194 of fixed point types for which GNAT is unable to provide
15195 the scaling factor via the standard DWARF mechanisms, and
15196 for which the info is provided via the GNAT encodings instead.
15197 This is likely what this DIE is about. */
15198 encoding
= (encoding
== DW_ATE_signed_fixed
15200 : DW_ATE_unsigned
);
15203 /* With GNAT encodings, fixed-point information will be encoded in
15204 the type name. Note that this can also occur with the above
15205 zero-over-zero case, which is why this is a separate "if" rather
15206 than an "else if". */
15207 const char *gnat_encoding_suffix
= nullptr;
15208 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
15209 && cu
->lang () == language_ada
15210 && name
!= nullptr)
15212 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
15213 if (gnat_encoding_suffix
!= nullptr)
15215 gdb_assert (startswith (gnat_encoding_suffix
,
15216 GNAT_FIXED_POINT_SUFFIX
));
15217 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
15218 name
, gnat_encoding_suffix
- name
);
15219 /* Use -1 here so that SUFFIX points at the "_" after the
15221 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
15223 encoding
= (encoding
== DW_ATE_signed
15224 ? DW_ATE_signed_fixed
15225 : DW_ATE_unsigned_fixed
);
15231 case DW_ATE_address
:
15232 /* Turn DW_ATE_address into a void * pointer. */
15233 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
15234 type
= init_pointer_type (objfile
, bits
, name
, type
);
15236 case DW_ATE_boolean
:
15237 type
= init_boolean_type (objfile
, bits
, 1, name
);
15239 case DW_ATE_complex_float
:
15240 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
15242 if (type
->code () == TYPE_CODE_ERROR
)
15244 if (name
== nullptr)
15246 struct obstack
*obstack
15247 = &cu
->per_objfile
->objfile
->objfile_obstack
;
15248 name
= obconcat (obstack
, "_Complex ", type
->name (),
15251 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15254 type
= init_complex_type (name
, type
);
15256 case DW_ATE_decimal_float
:
15257 type
= init_decfloat_type (objfile
, bits
, name
);
15260 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
15262 case DW_ATE_signed
:
15263 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
15265 case DW_ATE_unsigned
:
15266 if (cu
->lang () == language_fortran
15268 && startswith (name
, "character("))
15269 type
= init_character_type (objfile
, bits
, 1, name
);
15271 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
15273 case DW_ATE_signed_char
:
15274 if (cu
->lang () == language_ada
15275 || cu
->lang () == language_m2
15276 || cu
->lang () == language_pascal
15277 || cu
->lang () == language_fortran
)
15278 type
= init_character_type (objfile
, bits
, 0, name
);
15280 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
15282 case DW_ATE_unsigned_char
:
15283 if (cu
->lang () == language_ada
15284 || cu
->lang () == language_m2
15285 || cu
->lang () == language_pascal
15286 || cu
->lang () == language_fortran
15287 || cu
->lang () == language_rust
)
15288 type
= init_character_type (objfile
, bits
, 1, name
);
15290 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
15294 type
= init_character_type (objfile
, bits
, 1, name
);
15295 return set_die_type (die
, type
, cu
);
15298 case DW_ATE_signed_fixed
:
15299 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
15300 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
15302 case DW_ATE_unsigned_fixed
:
15303 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
15304 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
15308 complaint (_("unsupported DW_AT_encoding: '%s'"),
15309 dwarf_type_encoding_name (encoding
));
15310 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
15314 if (type
->code () == TYPE_CODE_INT
15316 && strcmp (name
, "char") == 0)
15317 type
->set_has_no_signedness (true);
15319 maybe_set_alignment (cu
, die
, type
);
15321 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
15323 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
15325 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15326 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * type
->length ())
15328 unsigned real_bit_size
= attr
->as_unsigned ();
15329 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15330 /* Only use the attributes if they make sense together. */
15331 if (attr
== nullptr
15332 || (attr
->as_unsigned () + real_bit_size
15333 <= 8 * type
->length ()))
15335 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
15337 if (attr
!= nullptr)
15338 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
15339 = attr
->as_unsigned ();
15344 return set_die_type (die
, type
, cu
);
15347 /* A helper function that returns the name of DIE, if it refers to a
15348 variable declaration. */
15350 static const char *
15351 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15353 if (die
->tag
!= DW_TAG_variable
)
15356 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
15357 if (attr
== nullptr || !attr
->as_boolean ())
15360 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15361 if (attr
== nullptr)
15363 return attr
->as_string ();
15366 /* Parse dwarf attribute if it's a block, reference or constant and put the
15367 resulting value of the attribute into struct bound_prop.
15368 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
15371 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
15372 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
15373 struct type
*default_type
)
15375 struct dwarf2_property_baton
*baton
;
15376 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
15377 struct objfile
*objfile
= per_objfile
->objfile
;
15378 struct obstack
*obstack
= &objfile
->objfile_obstack
;
15380 gdb_assert (default_type
!= NULL
);
15382 if (attr
== NULL
|| prop
== NULL
)
15385 if (attr
->form_is_block ())
15387 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15388 baton
->property_type
= default_type
;
15389 baton
->locexpr
.per_cu
= cu
->per_cu
;
15390 baton
->locexpr
.per_objfile
= per_objfile
;
15392 struct dwarf_block
*block
;
15393 if (attr
->form
== DW_FORM_data16
)
15395 size_t data_size
= 16;
15396 block
= XOBNEW (obstack
, struct dwarf_block
);
15397 block
->size
= (data_size
15398 + 2 /* Extra bytes for DW_OP and arg. */);
15399 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
15400 data
[0] = DW_OP_implicit_value
;
15401 data
[1] = data_size
;
15402 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
15403 block
->data
= data
;
15406 block
= attr
->as_block ();
15408 baton
->locexpr
.size
= block
->size
;
15409 baton
->locexpr
.data
= block
->data
;
15410 switch (attr
->name
)
15412 case DW_AT_string_length
:
15413 baton
->locexpr
.is_reference
= true;
15416 baton
->locexpr
.is_reference
= false;
15420 prop
->set_locexpr (baton
);
15421 gdb_assert (prop
->baton () != NULL
);
15423 else if (attr
->form_is_ref ())
15425 struct dwarf2_cu
*target_cu
= cu
;
15426 struct die_info
*target_die
;
15427 struct attribute
*target_attr
;
15429 target_die
= follow_die_ref (die
, attr
, &target_cu
);
15430 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
15431 if (target_attr
== NULL
)
15432 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
15434 if (target_attr
== nullptr)
15435 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
15437 if (target_attr
== NULL
)
15439 const char *name
= var_decl_name (target_die
, target_cu
);
15440 if (name
!= nullptr)
15442 prop
->set_variable_name (name
);
15448 switch (target_attr
->name
)
15450 case DW_AT_location
:
15451 if (target_attr
->form_is_section_offset ())
15453 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15454 baton
->property_type
= die_type (target_die
, target_cu
);
15455 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
15456 prop
->set_loclist (baton
);
15457 gdb_assert (prop
->baton () != NULL
);
15459 else if (target_attr
->form_is_block ())
15461 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15462 baton
->property_type
= die_type (target_die
, target_cu
);
15463 baton
->locexpr
.per_cu
= cu
->per_cu
;
15464 baton
->locexpr
.per_objfile
= per_objfile
;
15465 struct dwarf_block
*block
= target_attr
->as_block ();
15466 baton
->locexpr
.size
= block
->size
;
15467 baton
->locexpr
.data
= block
->data
;
15468 baton
->locexpr
.is_reference
= true;
15469 prop
->set_locexpr (baton
);
15470 gdb_assert (prop
->baton () != NULL
);
15474 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15475 "dynamic property");
15479 case DW_AT_data_member_location
:
15480 case DW_AT_data_bit_offset
:
15484 if (!handle_member_location (target_die
, target_cu
, &offset
))
15487 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15488 baton
->property_type
= read_type_die (target_die
->parent
,
15490 baton
->offset_info
.offset
= offset
;
15491 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
15492 prop
->set_addr_offset (baton
);
15497 else if (attr
->form_is_constant ())
15498 prop
->set_const_val (attr
->constant_value (0));
15499 else if (attr
->form_is_section_offset ())
15501 switch (attr
->name
)
15503 case DW_AT_string_length
:
15504 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
15505 baton
->property_type
= default_type
;
15506 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
15507 prop
->set_loclist (baton
);
15508 gdb_assert (prop
->baton () != NULL
);
15520 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
15521 dwarf2_name (die
, cu
));
15527 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
15528 present (which is valid) then compute the default type based on the
15529 compilation units address size. */
15531 static struct type
*
15532 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15534 struct type
*index_type
= die_type (die
, cu
);
15536 /* Dwarf-2 specifications explicitly allows to create subrange types
15537 without specifying a base type.
15538 In that case, the base type must be set to the type of
15539 the lower bound, upper bound or count, in that order, if any of these
15540 three attributes references an object that has a type.
15541 If no base type is found, the Dwarf-2 specifications say that
15542 a signed integer type of size equal to the size of an address should
15544 For the following C code: `extern char gdb_int [];'
15545 GCC produces an empty range DIE.
15546 FIXME: muller/2010-05-28: Possible references to object for low bound,
15547 high bound or count are not yet handled by this code. */
15548 if (index_type
->code () == TYPE_CODE_VOID
)
15549 index_type
= cu
->addr_sized_int_type (false);
15554 /* Read the given DW_AT_subrange DIE. */
15556 static struct type
*
15557 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15559 struct type
*base_type
, *orig_base_type
;
15560 struct type
*range_type
;
15561 struct attribute
*attr
;
15562 struct dynamic_prop low
, high
;
15563 int low_default_is_valid
;
15564 int high_bound_is_count
= 0;
15567 orig_base_type
= read_subrange_index_type (die
, cu
);
15569 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
15570 whereas the real type might be. So, we use ORIG_BASE_TYPE when
15571 creating the range type, but we use the result of check_typedef
15572 when examining properties of the type. */
15573 base_type
= check_typedef (orig_base_type
);
15575 /* The die_type call above may have already set the type for this DIE. */
15576 range_type
= get_die_type (die
, cu
);
15580 high
.set_const_val (0);
15582 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
15583 omitting DW_AT_lower_bound. */
15584 switch (cu
->lang ())
15587 case language_cplus
:
15588 low
.set_const_val (0);
15589 low_default_is_valid
= 1;
15591 case language_fortran
:
15592 low
.set_const_val (1);
15593 low_default_is_valid
= 1;
15596 case language_objc
:
15597 case language_rust
:
15598 low
.set_const_val (0);
15599 low_default_is_valid
= (cu
->header
.version
>= 4);
15603 case language_pascal
:
15604 low
.set_const_val (1);
15605 low_default_is_valid
= (cu
->header
.version
>= 4);
15608 low
.set_const_val (0);
15609 low_default_is_valid
= 0;
15613 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
15614 if (attr
!= nullptr)
15615 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
15616 else if (!low_default_is_valid
)
15617 complaint (_("Missing DW_AT_lower_bound "
15618 "- DIE at %s [in module %s]"),
15619 sect_offset_str (die
->sect_off
),
15620 objfile_name (cu
->per_objfile
->objfile
));
15622 struct attribute
*attr_ub
, *attr_count
;
15623 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
15624 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
15626 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
15627 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
15629 /* If bounds are constant do the final calculation here. */
15630 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
15631 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
15633 high_bound_is_count
= 1;
15637 if (attr_ub
!= NULL
)
15638 complaint (_("Unresolved DW_AT_upper_bound "
15639 "- DIE at %s [in module %s]"),
15640 sect_offset_str (die
->sect_off
),
15641 objfile_name (cu
->per_objfile
->objfile
));
15642 if (attr_count
!= NULL
)
15643 complaint (_("Unresolved DW_AT_count "
15644 "- DIE at %s [in module %s]"),
15645 sect_offset_str (die
->sect_off
),
15646 objfile_name (cu
->per_objfile
->objfile
));
15651 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
15652 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
15653 bias
= bias_attr
->constant_value (0);
15655 /* Normally, the DWARF producers are expected to use a signed
15656 constant form (Eg. DW_FORM_sdata) to express negative bounds.
15657 But this is unfortunately not always the case, as witnessed
15658 with GCC, for instance, where the ambiguous DW_FORM_dataN form
15659 is used instead. To work around that ambiguity, we treat
15660 the bounds as signed, and thus sign-extend their values, when
15661 the base type is signed.
15663 Skip it if the base type's length is larger than ULONGEST, to avoid
15664 the undefined behavior of a too large left shift. We don't really handle
15665 constants larger than 8 bytes anyway, at the moment. */
15667 if (base_type
->length () <= sizeof (ULONGEST
))
15669 ULONGEST negative_mask
15670 = -((ULONGEST
) 1 << (base_type
->length () * TARGET_CHAR_BIT
- 1));
15672 if (low
.kind () == PROP_CONST
15673 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
15674 low
.set_const_val (low
.const_val () | negative_mask
);
15676 if (high
.kind () == PROP_CONST
15677 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
15678 high
.set_const_val (high
.const_val () | negative_mask
);
15681 /* Check for bit and byte strides. */
15682 struct dynamic_prop byte_stride_prop
;
15683 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15684 if (attr_byte_stride
!= nullptr)
15686 struct type
*prop_type
= cu
->addr_sized_int_type (false);
15687 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
15691 struct dynamic_prop bit_stride_prop
;
15692 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15693 if (attr_bit_stride
!= nullptr)
15695 /* It only makes sense to have either a bit or byte stride. */
15696 if (attr_byte_stride
!= nullptr)
15698 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
15699 "- DIE at %s [in module %s]"),
15700 sect_offset_str (die
->sect_off
),
15701 objfile_name (cu
->per_objfile
->objfile
));
15702 attr_bit_stride
= nullptr;
15706 struct type
*prop_type
= cu
->addr_sized_int_type (false);
15707 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
15712 if (attr_byte_stride
!= nullptr
15713 || attr_bit_stride
!= nullptr)
15715 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
15716 struct dynamic_prop
*stride
15717 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
15720 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
15721 &high
, bias
, stride
, byte_stride_p
);
15724 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
15726 if (high_bound_is_count
)
15727 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
15729 /* Ada expects an empty array on no boundary attributes. */
15730 if (attr
== NULL
&& cu
->lang () != language_ada
)
15731 range_type
->bounds ()->high
.set_undefined ();
15733 name
= dwarf2_name (die
, cu
);
15735 range_type
->set_name (name
);
15737 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15738 if (attr
!= nullptr)
15739 range_type
->set_length (attr
->constant_value (0));
15741 maybe_set_alignment (cu
, die
, range_type
);
15743 set_die_type (die
, range_type
, cu
);
15745 /* set_die_type should be already done. */
15746 set_descriptive_type (range_type
, die
, cu
);
15751 static struct type
*
15752 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15756 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
15757 type
->set_name (dwarf2_name (die
, cu
));
15759 /* In Ada, an unspecified type is typically used when the description
15760 of the type is deferred to a different unit. When encountering
15761 such a type, we treat it as a stub, and try to resolve it later on,
15763 Mark this as a stub type for all languages though. */
15764 type
->set_is_stub (true);
15766 return set_die_type (die
, type
, cu
);
15769 /* Read a single die and all its descendents. Set the die's sibling
15770 field to NULL; set other fields in the die correctly, and set all
15771 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
15772 location of the info_ptr after reading all of those dies. PARENT
15773 is the parent of the die in question. */
15775 static struct die_info
*
15776 read_die_and_children (const struct die_reader_specs
*reader
,
15777 const gdb_byte
*info_ptr
,
15778 const gdb_byte
**new_info_ptr
,
15779 struct die_info
*parent
)
15781 struct die_info
*die
;
15782 const gdb_byte
*cur_ptr
;
15784 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
15787 *new_info_ptr
= cur_ptr
;
15790 store_in_ref_table (die
, reader
->cu
);
15792 if (die
->has_children
)
15793 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
15797 *new_info_ptr
= cur_ptr
;
15800 die
->sibling
= NULL
;
15801 die
->parent
= parent
;
15805 /* Read a die, all of its descendents, and all of its siblings; set
15806 all of the fields of all of the dies correctly. Arguments are as
15807 in read_die_and_children. */
15809 static struct die_info
*
15810 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
15811 const gdb_byte
*info_ptr
,
15812 const gdb_byte
**new_info_ptr
,
15813 struct die_info
*parent
)
15815 struct die_info
*first_die
, *last_sibling
;
15816 const gdb_byte
*cur_ptr
;
15818 cur_ptr
= info_ptr
;
15819 first_die
= last_sibling
= NULL
;
15823 struct die_info
*die
15824 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
15828 *new_info_ptr
= cur_ptr
;
15835 last_sibling
->sibling
= die
;
15837 last_sibling
= die
;
15841 /* Read a die, all of its descendents, and all of its siblings; set
15842 all of the fields of all of the dies correctly. Arguments are as
15843 in read_die_and_children.
15844 This the main entry point for reading a DIE and all its children. */
15846 static struct die_info
*
15847 read_die_and_siblings (const struct die_reader_specs
*reader
,
15848 const gdb_byte
*info_ptr
,
15849 const gdb_byte
**new_info_ptr
,
15850 struct die_info
*parent
)
15852 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
15853 new_info_ptr
, parent
);
15855 if (dwarf_die_debug
)
15857 gdb_printf (gdb_stdlog
,
15858 "Read die from %s@0x%x of %s:\n",
15859 reader
->die_section
->get_name (),
15860 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15861 bfd_get_filename (reader
->abfd
));
15862 die
->dump (dwarf_die_debug
);
15868 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
15870 The caller is responsible for filling in the extra attributes
15871 and updating (*DIEP)->num_attrs.
15872 Set DIEP to point to a newly allocated die with its information,
15873 except for its child, sibling, and parent fields. */
15875 static const gdb_byte
*
15876 read_full_die_1 (const struct die_reader_specs
*reader
,
15877 struct die_info
**diep
, const gdb_byte
*info_ptr
,
15878 int num_extra_attrs
)
15880 unsigned int abbrev_number
, bytes_read
, i
;
15881 const struct abbrev_info
*abbrev
;
15882 struct die_info
*die
;
15883 struct dwarf2_cu
*cu
= reader
->cu
;
15884 bfd
*abfd
= reader
->abfd
;
15886 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
15887 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
15888 info_ptr
+= bytes_read
;
15889 if (!abbrev_number
)
15895 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
15897 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
15899 bfd_get_filename (abfd
));
15901 die
= die_info::allocate (&cu
->comp_unit_obstack
,
15902 abbrev
->num_attrs
+ num_extra_attrs
);
15903 die
->sect_off
= sect_off
;
15904 die
->tag
= abbrev
->tag
;
15905 die
->abbrev
= abbrev_number
;
15906 die
->has_children
= abbrev
->has_children
;
15908 /* Make the result usable.
15909 The caller needs to update num_attrs after adding the extra
15911 die
->num_attrs
= abbrev
->num_attrs
;
15913 bool any_need_reprocess
= false;
15914 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15916 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
15918 if (die
->attrs
[i
].requires_reprocessing_p ())
15919 any_need_reprocess
= true;
15922 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
15923 if (attr
!= nullptr && attr
->form_is_unsigned ())
15924 cu
->str_offsets_base
= attr
->as_unsigned ();
15926 attr
= die
->attr (DW_AT_loclists_base
);
15927 if (attr
!= nullptr)
15928 cu
->loclist_base
= attr
->as_unsigned ();
15930 auto maybe_addr_base
= die
->addr_base ();
15931 if (maybe_addr_base
.has_value ())
15932 cu
->addr_base
= *maybe_addr_base
;
15934 attr
= die
->attr (DW_AT_rnglists_base
);
15935 if (attr
!= nullptr)
15936 cu
->rnglists_base
= attr
->as_unsigned ();
15938 if (any_need_reprocess
)
15940 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
15942 if (die
->attrs
[i
].requires_reprocessing_p ())
15943 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
15950 /* Read a die and all its attributes.
15951 Set DIEP to point to a newly allocated die with its information,
15952 except for its child, sibling, and parent fields. */
15954 static const gdb_byte
*
15955 read_full_die (const struct die_reader_specs
*reader
,
15956 struct die_info
**diep
, const gdb_byte
*info_ptr
)
15958 const gdb_byte
*result
;
15960 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
15962 if (dwarf_die_debug
)
15964 gdb_printf (gdb_stdlog
,
15965 "Read die from %s@0x%x of %s:\n",
15966 reader
->die_section
->get_name (),
15967 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
15968 bfd_get_filename (reader
->abfd
));
15969 (*diep
)->dump (dwarf_die_debug
);
15977 cooked_indexer::check_bounds (cutu_reader
*reader
)
15979 if (reader
->cu
->per_cu
->addresses_seen
)
15982 dwarf2_cu
*cu
= reader
->cu
;
15984 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
15985 /* Possibly set the default values of LOWPC and HIGHPC from
15987 dwarf2_find_base_address (reader
->comp_unit_die
, cu
);
15988 enum pc_bounds_kind cu_bounds_kind
15989 = dwarf2_get_pc_bounds (reader
->comp_unit_die
, &best_lowpc
, &best_highpc
,
15990 cu
, m_index_storage
->get_addrmap (), cu
->per_cu
);
15991 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
15993 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15994 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
15995 struct gdbarch
*gdbarch
= objfile
->arch ();
15997 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
16000 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
16002 /* Store the contiguous range if it is not empty; it can be
16003 empty for CUs with no code. */
16004 m_index_storage
->get_addrmap ()->set_empty (low
, high
, cu
->per_cu
);
16006 cu
->per_cu
->addresses_seen
= true;
16010 /* Helper function that returns true if TAG can have a linkage
16014 tag_can_have_linkage_name (enum dwarf_tag tag
)
16018 case DW_TAG_variable
:
16019 case DW_TAG_subprogram
:
16028 cooked_indexer::ensure_cu_exists (cutu_reader
*reader
,
16029 dwarf2_per_objfile
*per_objfile
,
16030 sect_offset sect_off
, bool is_dwz
,
16033 /* Lookups for type unit references are always in the CU, and
16034 cross-CU references will crash. */
16035 if (reader
->cu
->per_cu
->is_dwz
== is_dwz
16036 && reader
->cu
->header
.offset_in_cu_p (sect_off
))
16039 dwarf2_per_cu_data
*per_cu
16040 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
16041 per_objfile
->per_bfd
);
16043 /* When scanning, we only want to visit a given CU a single time.
16044 Doing this check here avoids self-imports as well. */
16048 if (!per_cu
->scanned
.compare_exchange_strong (nope
, true))
16051 if (per_cu
== m_per_cu
)
16054 cutu_reader
*result
= m_index_storage
->get_reader (per_cu
);
16055 if (result
== nullptr)
16057 cutu_reader
new_reader (per_cu
, per_objfile
, nullptr, nullptr, false,
16058 m_index_storage
->get_abbrev_cache ());
16060 prepare_one_comp_unit (new_reader
.cu
, new_reader
.comp_unit_die
,
16062 std::unique_ptr
<cutu_reader
> copy
16063 (new cutu_reader (std::move (new_reader
)));
16064 result
= m_index_storage
->preserve (std::move (copy
));
16067 if (result
->dummy_p
|| !result
->comp_unit_die
->has_children
)
16071 check_bounds (result
);
16077 cooked_indexer::scan_attributes (dwarf2_per_cu_data
*scanning_per_cu
,
16078 cutu_reader
*reader
,
16079 const gdb_byte
*watermark_ptr
,
16080 const gdb_byte
*info_ptr
,
16081 const abbrev_info
*abbrev
,
16083 const char **linkage_name
,
16084 cooked_index_flag
*flags
,
16085 sect_offset
*sibling_offset
,
16086 const cooked_index_entry
**parent_entry
,
16087 CORE_ADDR
*maybe_defer
,
16088 bool for_specification
)
16090 bool origin_is_dwz
= false;
16091 bool is_declaration
= false;
16092 sect_offset origin_offset
{};
16094 gdb::optional
<CORE_ADDR
> low_pc
;
16095 gdb::optional
<CORE_ADDR
> high_pc
;
16096 bool high_pc_relative
= false;
16098 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
16101 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16102 if (attr
.requires_reprocessing_p ())
16103 read_attribute_reprocess (reader
, &attr
, abbrev
->tag
);
16105 /* Store the data if it is of an attribute we want to keep in a
16106 partial symbol table. */
16110 switch (abbrev
->tag
)
16112 case DW_TAG_compile_unit
:
16113 case DW_TAG_partial_unit
:
16114 case DW_TAG_type_unit
:
16115 /* Compilation units have a DW_AT_name that is a filename, not
16116 a source language identifier. */
16120 if (*name
== nullptr)
16121 *name
= attr
.as_string ();
16126 case DW_AT_linkage_name
:
16127 case DW_AT_MIPS_linkage_name
:
16128 /* Note that both forms of linkage name might appear. We
16129 assume they will be the same, and we only store the last
16131 if (*linkage_name
== nullptr)
16132 *linkage_name
= attr
.as_string ();
16135 case DW_AT_main_subprogram
:
16136 if (attr
.as_boolean ())
16140 case DW_AT_declaration
:
16141 is_declaration
= attr
.as_boolean ();
16144 case DW_AT_sibling
:
16145 if (sibling_offset
!= nullptr)
16146 *sibling_offset
= attr
.get_ref_die_offset ();
16149 case DW_AT_specification
:
16150 case DW_AT_abstract_origin
:
16151 case DW_AT_extension
:
16152 origin_offset
= attr
.get_ref_die_offset ();
16153 origin_is_dwz
= attr
.form
== DW_FORM_GNU_ref_alt
;
16156 case DW_AT_external
:
16157 if (attr
.as_boolean ())
16158 *flags
&= ~IS_STATIC
;
16161 case DW_AT_enum_class
:
16162 if (attr
.as_boolean ())
16163 *flags
|= IS_ENUM_CLASS
;
16167 low_pc
= attr
.as_address ();
16170 case DW_AT_high_pc
:
16171 high_pc
= attr
.as_address ();
16172 if (reader
->cu
->header
.version
>= 4 && attr
.form_is_constant ())
16173 high_pc_relative
= true;
16176 case DW_AT_location
:
16177 if (!scanning_per_cu
->addresses_seen
&& attr
.form_is_block ())
16179 struct dwarf_block
*locdesc
= attr
.as_block ();
16180 CORE_ADDR addr
= decode_locdesc (locdesc
, reader
->cu
);
16182 || reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
)
16185 /* For variables, we don't want to try decoding the
16186 type just to find the size -- for gdb's purposes
16187 we only need the address of a variable. */
16188 high_pc
= addr
+ 1;
16189 high_pc_relative
= false;
16195 if (!scanning_per_cu
->addresses_seen
)
16197 /* Offset in the .debug_ranges or .debug_rnglist section
16198 (depending on DWARF version). */
16199 ULONGEST ranges_offset
= attr
.as_unsigned ();
16201 /* See dwarf2_cu::gnu_ranges_base's doc for why we might
16202 want to add this value. */
16203 ranges_offset
+= reader
->cu
->gnu_ranges_base
;
16205 CORE_ADDR lowpc
, highpc
;
16206 dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, reader
->cu
,
16207 m_index_storage
->get_addrmap (),
16208 scanning_per_cu
, abbrev
->tag
);
16214 /* We don't want to examine declarations, but if we found a
16215 declaration when handling DW_AT_specification or the like, then
16216 that is ok. Similarly, we allow an external variable without a
16217 location; those are resolved via minimal symbols. */
16218 if (is_declaration
&& !for_specification
16219 && !(abbrev
->tag
== DW_TAG_variable
&& (*flags
& IS_STATIC
) == 0))
16221 /* We always want to recurse into some types, but we may not
16222 want to treat them as definitions. */
16223 if ((abbrev
->tag
== DW_TAG_class_type
16224 || abbrev
->tag
== DW_TAG_structure_type
16225 || abbrev
->tag
== DW_TAG_union_type
)
16226 && abbrev
->has_children
)
16227 *flags
|= IS_TYPE_DECLARATION
;
16230 *linkage_name
= nullptr;
16234 else if ((*name
== nullptr
16235 || (*linkage_name
== nullptr
16236 && tag_can_have_linkage_name (abbrev
->tag
))
16237 || (*parent_entry
== nullptr && m_language
!= language_c
))
16238 && origin_offset
!= sect_offset (0))
16240 cutu_reader
*new_reader
16241 = ensure_cu_exists (reader
, reader
->cu
->per_objfile
, origin_offset
,
16242 origin_is_dwz
, false);
16243 if (new_reader
!= nullptr)
16245 const gdb_byte
*new_info_ptr
= (new_reader
->buffer
16246 + to_underlying (origin_offset
));
16248 if (new_reader
->cu
== reader
->cu
16249 && new_info_ptr
> watermark_ptr
16250 && *parent_entry
== nullptr)
16251 *maybe_defer
= form_addr (origin_offset
, origin_is_dwz
);
16252 else if (*parent_entry
== nullptr)
16254 CORE_ADDR lookup
= form_addr (origin_offset
, origin_is_dwz
);
16255 void *obj
= m_die_range_map
.find (lookup
);
16256 *parent_entry
= static_cast <cooked_index_entry
*> (obj
);
16259 unsigned int bytes_read
;
16260 const abbrev_info
*new_abbrev
= peek_die_abbrev (*new_reader
,
16263 new_info_ptr
+= bytes_read
;
16264 scan_attributes (scanning_per_cu
, new_reader
, new_info_ptr
, new_info_ptr
,
16265 new_abbrev
, name
, linkage_name
, flags
, nullptr,
16266 parent_entry
, maybe_defer
, true);
16270 if (!for_specification
)
16272 if (m_language
== language_ada
16273 && *linkage_name
== nullptr)
16274 *linkage_name
= *name
;
16276 if (!scanning_per_cu
->addresses_seen
16277 && low_pc
.has_value ()
16278 && (reader
->cu
->per_objfile
->per_bfd
->has_section_at_zero
16280 && high_pc
.has_value ())
16282 if (high_pc_relative
)
16283 high_pc
= *high_pc
+ *low_pc
;
16285 if (*high_pc
> *low_pc
)
16287 struct objfile
*objfile
= reader
->cu
->per_objfile
->objfile
;
16288 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
16289 struct gdbarch
*gdbarch
= objfile
->arch ();
16291 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *low_pc
+ baseaddr
)
16294 = (gdbarch_adjust_dwarf2_addr (gdbarch
, *high_pc
+ baseaddr
)
16296 m_index_storage
->get_addrmap ()->set_empty (lo
, hi
- 1,
16301 if (abbrev
->tag
== DW_TAG_module
|| abbrev
->tag
== DW_TAG_namespace
)
16302 *flags
&= ~IS_STATIC
;
16304 if (abbrev
->tag
== DW_TAG_namespace
&& *name
== nullptr)
16305 *name
= "(anonymous namespace)";
16307 if (m_language
== language_cplus
16308 && (abbrev
->tag
== DW_TAG_class_type
16309 || abbrev
->tag
== DW_TAG_interface_type
16310 || abbrev
->tag
== DW_TAG_structure_type
16311 || abbrev
->tag
== DW_TAG_union_type
16312 || abbrev
->tag
== DW_TAG_enumeration_type
16313 || abbrev
->tag
== DW_TAG_enumerator
))
16314 *flags
&= ~IS_STATIC
;
16321 cooked_indexer::index_imported_unit (cutu_reader
*reader
,
16322 const gdb_byte
*info_ptr
,
16323 const abbrev_info
*abbrev
)
16325 sect_offset sect_off
{};
16326 bool is_dwz
= false;
16328 for (int i
= 0; i
< abbrev
->num_attrs
; ++i
)
16330 /* Note that we never need to reprocess attributes here. */
16332 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
16334 if (attr
.name
== DW_AT_import
)
16336 sect_off
= attr
.get_ref_die_offset ();
16337 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
16338 || reader
->cu
->per_cu
->is_dwz
);
16342 /* Did not find DW_AT_import. */
16343 if (sect_off
== sect_offset (0))
16346 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
16347 cutu_reader
*new_reader
= ensure_cu_exists (reader
, per_objfile
, sect_off
,
16349 if (new_reader
!= nullptr)
16351 index_dies (new_reader
, new_reader
->info_ptr
, nullptr, false);
16353 reader
->cu
->add_dependence (new_reader
->cu
->per_cu
);
16360 cooked_indexer::recurse (cutu_reader
*reader
,
16361 const gdb_byte
*info_ptr
,
16362 const cooked_index_entry
*parent_entry
,
16365 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
16367 if (parent_entry
!= nullptr)
16369 CORE_ADDR start
= form_addr (parent_entry
->die_offset
,
16370 reader
->cu
->per_cu
->is_dwz
);
16371 CORE_ADDR end
= form_addr (sect_offset (info_ptr
- 1 - reader
->buffer
),
16372 reader
->cu
->per_cu
->is_dwz
);
16373 m_die_range_map
.set_empty (start
, end
, (void *) parent_entry
);
16380 cooked_indexer::index_dies (cutu_reader
*reader
,
16381 const gdb_byte
*info_ptr
,
16382 const cooked_index_entry
*parent_entry
,
16385 const gdb_byte
*end_ptr
= (reader
->buffer
16386 + to_underlying (reader
->cu
->header
.sect_off
)
16387 + reader
->cu
->header
.get_length_with_initial ());
16389 while (info_ptr
< end_ptr
)
16391 sect_offset this_die
= (sect_offset
) (info_ptr
- reader
->buffer
);
16392 unsigned int bytes_read
;
16393 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
16395 info_ptr
+= bytes_read
;
16396 if (abbrev
== nullptr)
16399 if (abbrev
->tag
== DW_TAG_imported_unit
)
16401 info_ptr
= index_imported_unit (reader
, info_ptr
, abbrev
);
16405 if (!abbrev
->interesting
)
16407 info_ptr
= skip_one_die (reader
, info_ptr
, abbrev
, !fully
);
16408 if (fully
&& abbrev
->has_children
)
16409 info_ptr
= index_dies (reader
, info_ptr
, parent_entry
, fully
);
16413 const char *name
= nullptr;
16414 const char *linkage_name
= nullptr;
16415 CORE_ADDR defer
= 0;
16416 cooked_index_flag flags
= IS_STATIC
;
16417 sect_offset sibling
{};
16418 const cooked_index_entry
*this_parent_entry
= parent_entry
;
16419 info_ptr
= scan_attributes (reader
->cu
->per_cu
, reader
, info_ptr
,
16420 info_ptr
, abbrev
, &name
, &linkage_name
,
16421 &flags
, &sibling
, &this_parent_entry
,
16424 if (abbrev
->tag
== DW_TAG_namespace
16425 && m_language
== language_cplus
16426 && strcmp (name
, "::") == 0)
16428 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they
16429 generated bogus DW_TAG_namespace DIEs with a name of "::"
16430 for the global namespace. Work around this problem
16435 const cooked_index_entry
*this_entry
= nullptr;
16436 if (name
!= nullptr)
16439 m_deferred_entries
.push_back ({
16440 this_die
, name
, defer
, abbrev
->tag
, flags
16443 this_entry
= m_index_storage
->add (this_die
, abbrev
->tag
, flags
,
16444 name
, this_parent_entry
,
16448 if (linkage_name
!= nullptr)
16450 /* We only want this to be "main" if it has a linkage name
16451 but not an ordinary name. */
16452 if (name
!= nullptr)
16453 flags
= flags
& ~IS_MAIN
;
16454 /* Set the IS_LINKAGE on for everything except when functions
16455 have linkage name present but name is absent. */
16456 if (name
!= nullptr
16457 || (abbrev
->tag
!= DW_TAG_subprogram
16458 && abbrev
->tag
!= DW_TAG_inlined_subroutine
16459 && abbrev
->tag
!= DW_TAG_entry_point
))
16460 flags
= flags
| IS_LINKAGE
;
16461 m_index_storage
->add (this_die
, abbrev
->tag
, flags
,
16462 linkage_name
, nullptr, m_per_cu
);
16465 if (abbrev
->has_children
)
16467 switch (abbrev
->tag
)
16469 case DW_TAG_class_type
:
16470 case DW_TAG_interface_type
:
16471 case DW_TAG_structure_type
:
16472 case DW_TAG_union_type
:
16473 if (m_language
!= language_c
&& this_entry
!= nullptr)
16475 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
16480 case DW_TAG_enumeration_type
:
16481 /* We need to recurse even for an anonymous enumeration.
16482 Which scope we record as the parent scope depends on
16483 whether we're reading an "enum class". If so, we use
16484 the enum itself as the parent, yielding names like
16485 "enum_class::enumerator"; otherwise we inject the
16486 names into our own parent scope. */
16487 info_ptr
= recurse (reader
, info_ptr
,
16488 ((flags
& IS_ENUM_CLASS
) == 0)
16494 case DW_TAG_module
:
16495 if (this_entry
== nullptr)
16498 case DW_TAG_namespace
:
16499 /* We don't check THIS_ENTRY for a namespace, to handle
16500 the ancient G++ workaround pointed out above. */
16501 info_ptr
= recurse (reader
, info_ptr
, this_entry
, fully
);
16504 case DW_TAG_subprogram
:
16505 if ((m_language
== language_fortran
16506 || m_language
== language_ada
)
16507 && this_entry
!= nullptr)
16509 info_ptr
= recurse (reader
, info_ptr
, this_entry
, true);
16515 if (sibling
!= sect_offset (0))
16517 const gdb_byte
*sibling_ptr
16518 = reader
->buffer
+ to_underlying (sibling
);
16520 if (sibling_ptr
< info_ptr
)
16521 complaint (_("DW_AT_sibling points backwards"));
16522 else if (sibling_ptr
> reader
->buffer_end
)
16523 reader
->die_section
->overflow_complaint ();
16525 info_ptr
= sibling_ptr
;
16528 info_ptr
= skip_children (reader
, info_ptr
);
16536 cooked_indexer::make_index (cutu_reader
*reader
)
16538 check_bounds (reader
);
16539 find_file_and_directory (reader
->comp_unit_die
, reader
->cu
);
16540 if (!reader
->comp_unit_die
->has_children
)
16542 index_dies (reader
, reader
->info_ptr
, nullptr, false);
16544 for (const auto &entry
: m_deferred_entries
)
16546 CORE_ADDR key
= form_addr (entry
.die_offset
, m_per_cu
->is_dwz
);
16547 void *obj
= m_die_range_map
.find (key
);
16548 cooked_index_entry
*parent
= static_cast <cooked_index_entry
*> (obj
);
16549 m_index_storage
->add (entry
.die_offset
, entry
.tag
, entry
.flags
,
16550 entry
.name
, parent
, m_per_cu
);
16554 /* An implementation of quick_symbol_functions for the cooked DWARF
16557 struct cooked_index_functions
: public dwarf2_base_index_functions
16559 dwarf2_per_cu_data
*find_per_cu (dwarf2_per_bfd
*per_bfd
,
16560 CORE_ADDR adjusted_pc
) override
;
16562 struct compunit_symtab
*find_compunit_symtab_by_address
16563 (struct objfile
*objfile
, CORE_ADDR address
) override
;
16565 void dump (struct objfile
*objfile
) override
16567 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16568 cooked_index
*index
16569 = (gdb::checked_static_cast
<cooked_index
*>
16570 (per_objfile
->per_bfd
->index_table
.get ()));
16571 if (index
== nullptr)
16574 gdb_printf ("Cooked index in use:\n");
16576 index
->dump (objfile
->arch ());
16579 void expand_matching_symbols
16581 const lookup_name_info
&lookup_name
,
16582 domain_enum domain
,
16584 symbol_compare_ftype
*ordered_compare
) override
;
16586 bool expand_symtabs_matching
16587 (struct objfile
*objfile
,
16588 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
16589 const lookup_name_info
*lookup_name
,
16590 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
16591 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
16592 block_search_flags search_flags
,
16593 domain_enum domain
,
16594 enum search_domain kind
) override
;
16596 bool can_lazily_read_symbols () override
16601 void read_partial_symbols (struct objfile
*objfile
) override
16603 if (dwarf2_has_info (objfile
, nullptr))
16604 dwarf2_build_psymtabs (objfile
);
16608 dwarf2_per_cu_data
*
16609 cooked_index_functions::find_per_cu (dwarf2_per_bfd
*per_bfd
,
16610 CORE_ADDR adjusted_pc
)
16612 cooked_index
*table
16613 = (gdb::checked_static_cast
<cooked_index
*>
16614 (per_bfd
->index_table
.get ()));
16615 if (table
== nullptr)
16617 return table
->lookup (adjusted_pc
);
16620 struct compunit_symtab
*
16621 cooked_index_functions::find_compunit_symtab_by_address
16622 (struct objfile
*objfile
, CORE_ADDR address
)
16624 if (objfile
->sect_index_data
== -1)
16627 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16628 cooked_index
*table
16629 = (gdb::checked_static_cast
<cooked_index
*>
16630 (per_objfile
->per_bfd
->index_table
.get ()));
16631 if (table
== nullptr)
16634 CORE_ADDR baseaddr
= objfile
->data_section_offset ();
16635 dwarf2_per_cu_data
*per_cu
= table
->lookup (address
- baseaddr
);
16636 if (per_cu
== nullptr)
16639 return dw2_instantiate_symtab (per_cu
, per_objfile
, false);
16643 cooked_index_functions::expand_matching_symbols
16644 (struct objfile
*objfile
,
16645 const lookup_name_info
&lookup_name
,
16646 domain_enum domain
,
16648 symbol_compare_ftype
*ordered_compare
)
16650 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16651 cooked_index
*table
16652 = (gdb::checked_static_cast
<cooked_index
*>
16653 (per_objfile
->per_bfd
->index_table
.get ()));
16654 if (table
== nullptr)
16657 const block_search_flags search_flags
= (global
16658 ? SEARCH_GLOBAL_BLOCK
16659 : SEARCH_STATIC_BLOCK
);
16660 const language_defn
*lang
= language_def (language_ada
);
16661 symbol_name_matcher_ftype
*name_match
16662 = lang
->get_symbol_name_matcher (lookup_name
);
16664 for (const cooked_index_entry
*entry
: table
->all_entries ())
16668 if (entry
->parent_entry
!= nullptr)
16671 if (!entry
->matches (search_flags
)
16672 || !entry
->matches (domain
))
16675 if (name_match (entry
->canonical
, lookup_name
, nullptr))
16676 dw2_instantiate_symtab (entry
->per_cu
, per_objfile
, false);
16681 cooked_index_functions::expand_symtabs_matching
16682 (struct objfile
*objfile
,
16683 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
16684 const lookup_name_info
*lookup_name
,
16685 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
16686 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
16687 block_search_flags search_flags
,
16688 domain_enum domain
,
16689 enum search_domain kind
)
16691 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
16693 cooked_index
*table
16694 = (gdb::checked_static_cast
<cooked_index
*>
16695 (per_objfile
->per_bfd
->index_table
.get ()));
16696 if (table
== nullptr)
16701 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
16703 /* This invariant is documented in quick-functions.h. */
16704 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
16705 if (lookup_name
== nullptr)
16707 for (dwarf2_per_cu_data
*per_cu
16708 : all_units_range (per_objfile
->per_bfd
))
16712 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
16720 lookup_name_info lookup_name_without_params
16721 = lookup_name
->make_ignore_params ();
16722 bool completing
= lookup_name
->completion_mode ();
16724 /* Unique styles of language splitting. */
16725 static const enum language unique_styles
[] =
16727 /* No splitting is also a style. */
16729 /* This includes Rust. */
16731 /* This includes Go. */
16736 for (enum language lang
: unique_styles
)
16738 std::vector
<gdb::string_view
> name_vec
16739 = lookup_name_without_params
.split_name (lang
);
16740 std::string last_name
= gdb::to_string (name_vec
.back ());
16742 for (const cooked_index_entry
*entry
: table
->find (last_name
,
16747 /* No need to consider symbols from expanded CUs. */
16748 if (per_objfile
->symtab_set_p (entry
->per_cu
))
16751 /* If file-matching was done, we don't need to consider
16752 symbols from unmarked CUs. */
16753 if (file_matcher
!= nullptr && !entry
->per_cu
->mark
)
16756 /* See if the symbol matches the type filter. */
16757 if (!entry
->matches (search_flags
)
16758 || !entry
->matches (domain
)
16759 || !entry
->matches (kind
))
16762 /* We've found the base name of the symbol; now walk its
16763 parentage chain, ensuring that each component
16767 const cooked_index_entry
*parent
= entry
->parent_entry
;
16768 for (int i
= name_vec
.size () - 1; i
> 0; --i
)
16770 /* If we ran out of entries, or if this segment doesn't
16771 match, this did not match. */
16772 if (parent
== nullptr
16773 || strncmp (parent
->name
, name_vec
[i
- 1].data (),
16774 name_vec
[i
- 1].length ()) != 0)
16780 parent
= parent
->parent_entry
;
16786 /* Might have been looking for "a::b" and found
16788 if (symbol_matcher
== nullptr)
16790 symbol_name_match_type match_type
16791 = lookup_name_without_params
.match_type ();
16792 if ((match_type
== symbol_name_match_type::FULL
16793 || (lang
!= language_ada
16794 && match_type
== symbol_name_match_type::EXPRESSION
))
16795 && parent
!= nullptr)
16800 auto_obstack temp_storage
;
16801 const char *full_name
= entry
->full_name (&temp_storage
);
16802 if (!symbol_matcher (full_name
))
16806 if (!dw2_expand_symtabs_matching_one (entry
->per_cu
, per_objfile
,
16816 /* Return a new cooked_index_functions object. */
16818 static quick_symbol_functions_up
16819 make_cooked_index_funcs ()
16821 return quick_symbol_functions_up (new cooked_index_functions
);
16824 quick_symbol_functions_up
16825 cooked_index::make_quick_functions () const
16827 return make_cooked_index_funcs ();
16832 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
16833 contents from the given SECTION in the HEADER.
16835 HEADER_OFFSET is the offset of the header in the section. */
16837 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
16838 struct dwarf2_section_info
*section
,
16839 sect_offset header_offset
)
16841 unsigned int bytes_read
;
16842 bfd
*abfd
= section
->get_bfd_owner ();
16843 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
16845 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
16846 info_ptr
+= bytes_read
;
16848 header
->version
= read_2_bytes (abfd
, info_ptr
);
16851 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
16854 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
16857 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
16860 /* Return the DW_AT_loclists_base value for the CU. */
16862 lookup_loclist_base (struct dwarf2_cu
*cu
)
16864 /* For the .dwo unit, the loclist_base points to the first offset following
16865 the header. The header consists of the following entities-
16866 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
16868 2. version (2 bytes)
16869 3. address size (1 byte)
16870 4. segment selector size (1 byte)
16871 5. offset entry count (4 bytes)
16872 These sizes are derived as per the DWARFv5 standard. */
16873 if (cu
->dwo_unit
!= nullptr)
16875 if (cu
->header
.initial_length_size
== 4)
16876 return LOCLIST_HEADER_SIZE32
;
16877 return LOCLIST_HEADER_SIZE64
;
16879 return cu
->loclist_base
;
16882 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
16883 array of offsets in the .debug_loclists section. */
16886 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
16888 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16889 struct objfile
*objfile
= per_objfile
->objfile
;
16890 bfd
*abfd
= objfile
->obfd
.get ();
16891 ULONGEST loclist_header_size
=
16892 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
16893 : LOCLIST_HEADER_SIZE64
);
16894 ULONGEST loclist_base
= lookup_loclist_base (cu
);
16896 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
16897 ULONGEST start_offset
=
16898 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
16900 /* Get loclists section. */
16901 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16903 /* Read the loclists section content. */
16904 section
->read (objfile
);
16905 if (section
->buffer
== NULL
)
16906 error (_("DW_FORM_loclistx used without .debug_loclists "
16907 "section [in module %s]"), objfile_name (objfile
));
16909 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
16910 so if loclist_base is smaller than the header size, we have a problem. */
16911 if (loclist_base
< loclist_header_size
)
16912 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
16913 objfile_name (objfile
));
16915 /* Read the header of the loclists contribution. */
16916 struct loclists_rnglists_header header
;
16917 read_loclists_rnglists_header (&header
, section
,
16918 (sect_offset
) (loclist_base
- loclist_header_size
));
16920 /* Verify the loclist index is valid. */
16921 if (loclist_index
>= header
.offset_entry_count
)
16922 error (_("DW_FORM_loclistx pointing outside of "
16923 ".debug_loclists offset array [in module %s]"),
16924 objfile_name (objfile
));
16926 /* Validate that reading won't go beyond the end of the section. */
16927 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
16928 error (_("Reading DW_FORM_loclistx index beyond end of"
16929 ".debug_loclists section [in module %s]"),
16930 objfile_name (objfile
));
16932 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
16934 if (cu
->header
.offset_size
== 4)
16935 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
16937 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
16940 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
16941 array of offsets in the .debug_rnglists section. */
16944 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
16947 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
16948 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16949 bfd
*abfd
= objfile
->obfd
.get ();
16950 ULONGEST rnglist_header_size
=
16951 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
16952 : RNGLIST_HEADER_SIZE64
);
16954 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
16955 .debug_rnglists.dwo section. The rnglists base given in the skeleton
16957 ULONGEST rnglist_base
=
16958 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
16960 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
16961 ULONGEST start_offset
=
16962 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
16964 /* Get rnglists section. */
16965 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
16967 /* Read the rnglists section content. */
16968 section
->read (objfile
);
16969 if (section
->buffer
== nullptr)
16970 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
16972 objfile_name (objfile
));
16974 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
16975 so if rnglist_base is smaller than the header size, we have a problem. */
16976 if (rnglist_base
< rnglist_header_size
)
16977 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
16978 objfile_name (objfile
));
16980 /* Read the header of the rnglists contribution. */
16981 struct loclists_rnglists_header header
;
16982 read_loclists_rnglists_header (&header
, section
,
16983 (sect_offset
) (rnglist_base
- rnglist_header_size
));
16985 /* Verify the rnglist index is valid. */
16986 if (rnglist_index
>= header
.offset_entry_count
)
16987 error (_("DW_FORM_rnglistx index pointing outside of "
16988 ".debug_rnglists offset array [in module %s]"),
16989 objfile_name (objfile
));
16991 /* Validate that reading won't go beyond the end of the section. */
16992 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
16993 error (_("Reading DW_FORM_rnglistx index beyond end of"
16994 ".debug_rnglists section [in module %s]"),
16995 objfile_name (objfile
));
16997 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
16999 if (cu
->header
.offset_size
== 4)
17000 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
17002 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
17005 /* Process the attributes that had to be skipped in the first round. These
17006 attributes are the ones that need str_offsets_base or addr_base attributes.
17007 They could not have been processed in the first round, because at the time
17008 the values of str_offsets_base or addr_base may not have been known. */
17010 read_attribute_reprocess (const struct die_reader_specs
*reader
,
17011 struct attribute
*attr
, dwarf_tag tag
)
17013 struct dwarf2_cu
*cu
= reader
->cu
;
17014 switch (attr
->form
)
17016 case DW_FORM_addrx
:
17017 case DW_FORM_GNU_addr_index
:
17018 attr
->set_address (read_addr_index (cu
,
17019 attr
->as_unsigned_reprocess ()));
17021 case DW_FORM_loclistx
:
17023 sect_offset loclists_sect_off
17024 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
17026 attr
->set_unsigned (to_underlying (loclists_sect_off
));
17029 case DW_FORM_rnglistx
:
17031 sect_offset rnglists_sect_off
17032 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
17034 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
17038 case DW_FORM_strx1
:
17039 case DW_FORM_strx2
:
17040 case DW_FORM_strx3
:
17041 case DW_FORM_strx4
:
17042 case DW_FORM_GNU_str_index
:
17044 unsigned int str_index
= attr
->as_unsigned_reprocess ();
17045 gdb_assert (!attr
->canonical_string_p ());
17046 if (reader
->dwo_file
!= NULL
)
17047 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
17050 attr
->set_string_noncanonical (read_stub_str_index (cu
,
17055 gdb_assert_not_reached ("Unexpected DWARF form.");
17059 /* Read an attribute value described by an attribute form. */
17061 static const gdb_byte
*
17062 read_attribute_value (const struct die_reader_specs
*reader
,
17063 struct attribute
*attr
, unsigned form
,
17064 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
17066 struct dwarf2_cu
*cu
= reader
->cu
;
17067 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17068 struct objfile
*objfile
= per_objfile
->objfile
;
17069 bfd
*abfd
= reader
->abfd
;
17070 struct comp_unit_head
*cu_header
= &cu
->header
;
17071 unsigned int bytes_read
;
17072 struct dwarf_block
*blk
;
17074 attr
->form
= (enum dwarf_form
) form
;
17077 case DW_FORM_ref_addr
:
17078 if (cu_header
->version
== 2)
17079 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
17082 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
17084 info_ptr
+= bytes_read
;
17086 case DW_FORM_GNU_ref_alt
:
17087 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
17089 info_ptr
+= bytes_read
;
17093 struct gdbarch
*gdbarch
= objfile
->arch ();
17094 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
17095 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
17096 attr
->set_address (addr
);
17097 info_ptr
+= bytes_read
;
17100 case DW_FORM_block2
:
17101 blk
= dwarf_alloc_block (cu
);
17102 blk
->size
= read_2_bytes (abfd
, info_ptr
);
17104 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17105 info_ptr
+= blk
->size
;
17106 attr
->set_block (blk
);
17108 case DW_FORM_block4
:
17109 blk
= dwarf_alloc_block (cu
);
17110 blk
->size
= read_4_bytes (abfd
, info_ptr
);
17112 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
17113 info_ptr
+= blk
->size
;
17114 attr
->set_block (blk
);
17116 case DW_FORM_data2
:
17117 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
17120 case DW_FORM_data4
:
17121 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
17124 case DW_FORM_data8
:
17125 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
17128 case DW_FORM_data16
:
17129 blk
= dwarf_alloc_block (cu
);
17131 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
17133 attr
->set_block (blk
);
17135 case DW_FORM_sec_offset
:
17136 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
17138 info_ptr
+= bytes_read
;
17140 case DW_FORM_loclistx
:
17142 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
17144 info_ptr
+= bytes_read
;
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
;
17220 case DW_FORM_udata
:
17221 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
17222 info_ptr
+= bytes_read
;
17225 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17226 + read_1_byte (abfd
, info_ptr
)));
17230 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17231 + read_2_bytes (abfd
, info_ptr
)));
17235 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17236 + read_4_bytes (abfd
, info_ptr
)));
17240 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17241 + read_8_bytes (abfd
, info_ptr
)));
17244 case DW_FORM_ref_sig8
:
17245 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
17248 case DW_FORM_ref_udata
:
17249 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
17250 + read_unsigned_leb128 (abfd
, info_ptr
,
17252 info_ptr
+= bytes_read
;
17254 case DW_FORM_indirect
:
17255 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17256 info_ptr
+= bytes_read
;
17257 if (form
== DW_FORM_implicit_const
)
17259 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
17260 info_ptr
+= bytes_read
;
17262 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
17265 case DW_FORM_implicit_const
:
17266 attr
->set_signed (implicit_const
);
17268 case DW_FORM_addrx
:
17269 case DW_FORM_GNU_addr_index
:
17270 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
17272 info_ptr
+= bytes_read
;
17275 case DW_FORM_strx1
:
17276 case DW_FORM_strx2
:
17277 case DW_FORM_strx3
:
17278 case DW_FORM_strx4
:
17279 case DW_FORM_GNU_str_index
:
17281 ULONGEST str_index
;
17282 if (form
== DW_FORM_strx1
)
17284 str_index
= read_1_byte (abfd
, info_ptr
);
17287 else if (form
== DW_FORM_strx2
)
17289 str_index
= read_2_bytes (abfd
, info_ptr
);
17292 else if (form
== DW_FORM_strx3
)
17294 str_index
= read_3_bytes (abfd
, info_ptr
);
17297 else if (form
== DW_FORM_strx4
)
17299 str_index
= read_4_bytes (abfd
, info_ptr
);
17304 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17305 info_ptr
+= bytes_read
;
17307 attr
->set_unsigned_reprocess (str_index
);
17311 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
17312 dwarf_form_name (form
),
17313 bfd_get_filename (abfd
));
17317 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
17318 attr
->form
= DW_FORM_GNU_ref_alt
;
17320 /* We have seen instances where the compiler tried to emit a byte
17321 size attribute of -1 which ended up being encoded as an unsigned
17322 0xffffffff. Although 0xffffffff is technically a valid size value,
17323 an object of this size seems pretty unlikely so we can relatively
17324 safely treat these cases as if the size attribute was invalid and
17325 treat them as zero by default. */
17326 if (attr
->name
== DW_AT_byte_size
17327 && form
== DW_FORM_data4
17328 && attr
->as_unsigned () >= 0xffffffff)
17331 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
17332 hex_string (attr
->as_unsigned ()));
17333 attr
->set_unsigned (0);
17339 /* Read an attribute described by an abbreviated attribute. */
17341 static const gdb_byte
*
17342 read_attribute (const struct die_reader_specs
*reader
,
17343 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
17344 const gdb_byte
*info_ptr
)
17346 attr
->name
= abbrev
->name
;
17347 attr
->string_is_canonical
= 0;
17348 attr
->requires_reprocessing
= 0;
17349 return read_attribute_value (reader
, attr
, abbrev
->form
,
17350 abbrev
->implicit_const
, info_ptr
);
17356 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
17357 LONGEST str_offset
)
17359 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
17360 str_offset
, "DW_FORM_strp");
17363 /* Return pointer to string at .debug_str offset as read from BUF.
17364 BUF is assumed to be in a compilation unit described by CU_HEADER.
17365 Return *BYTES_READ_PTR count of bytes read from BUF. */
17367 static const char *
17368 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
17369 const gdb_byte
*buf
,
17370 const struct comp_unit_head
*cu_header
,
17371 unsigned int *bytes_read_ptr
)
17373 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
17375 return read_indirect_string_at_offset (per_objfile
, str_offset
);
17381 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
17382 unsigned int offset_size
)
17384 bfd
*abfd
= objfile
->obfd
.get ();
17385 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
17387 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
17393 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
17394 const struct comp_unit_head
*cu_header
,
17395 unsigned int *bytes_read_ptr
)
17397 bfd
*abfd
= objfile
->obfd
.get ();
17398 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
17400 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
17403 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
17404 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
17405 ADDR_SIZE is the size of addresses from the CU header. */
17408 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
17409 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
17411 struct objfile
*objfile
= per_objfile
->objfile
;
17412 bfd
*abfd
= objfile
->obfd
.get ();
17413 const gdb_byte
*info_ptr
;
17414 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
17416 per_objfile
->per_bfd
->addr
.read (objfile
);
17417 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
17418 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
17419 objfile_name (objfile
));
17420 if (addr_base_or_zero
+ addr_index
* addr_size
17421 >= per_objfile
->per_bfd
->addr
.size
)
17422 error (_("DW_FORM_addr_index pointing outside of "
17423 ".debug_addr section [in module %s]"),
17424 objfile_name (objfile
));
17425 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
17426 + addr_index
* addr_size
);
17427 if (addr_size
== 4)
17428 return bfd_get_32 (abfd
, info_ptr
);
17430 return bfd_get_64 (abfd
, info_ptr
);
17433 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
17436 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
17438 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
17439 cu
->addr_base
, cu
->header
.addr_size
);
17442 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
17445 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
17446 unsigned int *bytes_read
)
17448 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
.get ();
17449 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
17451 return read_addr_index (cu
, addr_index
);
17457 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
17458 dwarf2_per_objfile
*per_objfile
,
17459 unsigned int addr_index
)
17461 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
17462 gdb::optional
<ULONGEST
> addr_base
;
17465 /* We need addr_base and addr_size.
17466 If we don't have PER_CU->cu, we have to get it.
17467 Nasty, but the alternative is storing the needed info in PER_CU,
17468 which at this point doesn't seem justified: it's not clear how frequently
17469 it would get used and it would increase the size of every PER_CU.
17470 Entry points like dwarf2_per_cu_addr_size do a similar thing
17471 so we're not in uncharted territory here.
17472 Alas we need to be a bit more complicated as addr_base is contained
17475 We don't need to read the entire CU(/TU).
17476 We just need the header and top level die.
17478 IWBN to use the aging mechanism to let us lazily later discard the CU.
17479 For now we skip this optimization. */
17483 addr_base
= cu
->addr_base
;
17484 addr_size
= cu
->header
.addr_size
;
17488 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
17489 addr_base
= reader
.cu
->addr_base
;
17490 addr_size
= reader
.cu
->header
.addr_size
;
17493 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
17496 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
17497 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
17500 static const char *
17501 read_str_index (struct dwarf2_cu
*cu
,
17502 struct dwarf2_section_info
*str_section
,
17503 struct dwarf2_section_info
*str_offsets_section
,
17504 ULONGEST str_offsets_base
, ULONGEST str_index
,
17505 unsigned offset_size
)
17507 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17508 struct objfile
*objfile
= per_objfile
->objfile
;
17509 const char *objf_name
= objfile_name (objfile
);
17510 bfd
*abfd
= objfile
->obfd
.get ();
17511 const gdb_byte
*info_ptr
;
17512 ULONGEST str_offset
;
17513 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
17515 str_section
->read (objfile
);
17516 str_offsets_section
->read (objfile
);
17517 if (str_section
->buffer
== NULL
)
17518 error (_("%s used without %s section"
17519 " in CU at offset %s [in module %s]"),
17520 form_name
, str_section
->get_name (),
17521 sect_offset_str (cu
->header
.sect_off
), objf_name
);
17522 if (str_offsets_section
->buffer
== NULL
)
17523 error (_("%s used without %s section"
17524 " in CU at offset %s [in module %s]"),
17525 form_name
, str_section
->get_name (),
17526 sect_offset_str (cu
->header
.sect_off
), objf_name
);
17527 info_ptr
= (str_offsets_section
->buffer
17529 + str_index
* offset_size
);
17530 if (offset_size
== 4)
17531 str_offset
= bfd_get_32 (abfd
, info_ptr
);
17533 str_offset
= bfd_get_64 (abfd
, info_ptr
);
17534 if (str_offset
>= str_section
->size
)
17535 error (_("Offset from %s pointing outside of"
17536 " .debug_str.dwo section in CU at offset %s [in module %s]"),
17537 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
17538 return (const char *) (str_section
->buffer
+ str_offset
);
17541 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
17543 static const char *
17544 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
17546 unsigned offset_size
;
17547 ULONGEST str_offsets_base
;
17548 if (reader
->cu
->header
.version
>= 5)
17550 /* We have a DWARF5 CU with a reference to a .debug_str_offsets section,
17551 so assume the .debug_str_offsets section is DWARF5 as well, and
17552 parse the header. FIXME: Parse the header only once. */
17553 unsigned int bytes_read
= 0;
17554 bfd
*abfd
= reader
->dwo_file
->sections
.str_offsets
.get_bfd_owner ();
17555 const gdb_byte
*p
= reader
->dwo_file
->sections
.str_offsets
.buffer
;
17557 /* Header: Initial length. */
17558 read_initial_length (abfd
, p
+ bytes_read
, &bytes_read
);
17560 /* Determine offset_size based on the .debug_str_offsets header. */
17561 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
17562 offset_size
= dwarf5_is_dwarf64
? 8 : 4;
17564 /* Header: Version. */
17565 unsigned version
= read_2_bytes (abfd
, p
+ bytes_read
);
17570 /* We'd like one warning here about ignoring the section, but
17571 because we parse the header more than once (see FIXME above)
17572 we'd have many warnings, so use a complaint instead, which at
17573 least has a limit. */
17574 complaint (_("Section .debug_str_offsets in %s has unsupported"
17575 " version %d, use empty string."),
17576 reader
->dwo_file
->dwo_name
, version
);
17580 /* Header: Padding. */
17583 str_offsets_base
= bytes_read
;
17587 /* We have a pre-DWARF5 CU with a reference to a .debug_str_offsets
17588 section, assume the .debug_str_offsets section is pre-DWARF5 as
17589 well, which doesn't have a header. */
17590 str_offsets_base
= 0;
17592 /* Determine offset_size based on the .debug_info header. */
17593 offset_size
= reader
->cu
->header
.offset_size
;
17596 return read_str_index (reader
->cu
,
17597 &reader
->dwo_file
->sections
.str
,
17598 &reader
->dwo_file
->sections
.str_offsets
,
17599 str_offsets_base
, str_index
, offset_size
);
17602 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
17604 static const char *
17605 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
17607 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17608 const char *objf_name
= objfile_name (objfile
);
17609 static const char form_name
[] = "DW_FORM_GNU_str_index";
17610 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
17612 if (!cu
->str_offsets_base
.has_value ())
17613 error (_("%s used in Fission stub without %s"
17614 " in CU at offset 0x%lx [in module %s]"),
17615 form_name
, str_offsets_attr_name
,
17616 (long) cu
->header
.offset_size
, objf_name
);
17618 return read_str_index (cu
,
17619 &cu
->per_objfile
->per_bfd
->str
,
17620 &cu
->per_objfile
->per_bfd
->str_offsets
,
17621 *cu
->str_offsets_base
, str_index
,
17622 cu
->header
.offset_size
);
17625 /* Return the length of an LEB128 number in BUF. */
17628 leb128_size (const gdb_byte
*buf
)
17630 const gdb_byte
*begin
= buf
;
17636 if ((byte
& 128) == 0)
17637 return buf
- begin
;
17641 static enum language
17642 dwarf_lang_to_enum_language (unsigned int lang
)
17644 enum language language
;
17653 language
= language_c
;
17656 case DW_LANG_C_plus_plus
:
17657 case DW_LANG_C_plus_plus_11
:
17658 case DW_LANG_C_plus_plus_14
:
17659 language
= language_cplus
;
17662 language
= language_d
;
17664 case DW_LANG_Fortran77
:
17665 case DW_LANG_Fortran90
:
17666 case DW_LANG_Fortran95
:
17667 case DW_LANG_Fortran03
:
17668 case DW_LANG_Fortran08
:
17669 language
= language_fortran
;
17672 language
= language_go
;
17674 case DW_LANG_Mips_Assembler
:
17675 language
= language_asm
;
17677 case DW_LANG_Ada83
:
17678 case DW_LANG_Ada95
:
17679 language
= language_ada
;
17681 case DW_LANG_Modula2
:
17682 language
= language_m2
;
17684 case DW_LANG_Pascal83
:
17685 language
= language_pascal
;
17688 language
= language_objc
;
17691 case DW_LANG_Rust_old
:
17692 language
= language_rust
;
17694 case DW_LANG_OpenCL
:
17695 language
= language_opencl
;
17697 case DW_LANG_Cobol74
:
17698 case DW_LANG_Cobol85
:
17700 language
= language_minimal
;
17707 /* Return the named attribute or NULL if not there. */
17709 static struct attribute
*
17710 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17715 struct attribute
*spec
= NULL
;
17717 for (i
= 0; i
< die
->num_attrs
; ++i
)
17719 if (die
->attrs
[i
].name
== name
)
17720 return &die
->attrs
[i
];
17721 if (die
->attrs
[i
].name
== DW_AT_specification
17722 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
17723 spec
= &die
->attrs
[i
];
17729 die
= follow_die_ref (die
, spec
, &cu
);
17735 /* Return the string associated with a string-typed attribute, or NULL if it
17736 is either not found or is of an incorrect type. */
17738 static const char *
17739 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
17741 struct attribute
*attr
;
17742 const char *str
= NULL
;
17744 attr
= dwarf2_attr (die
, name
, cu
);
17748 str
= attr
->as_string ();
17749 if (str
== nullptr)
17750 complaint (_("string type expected for attribute %s for "
17751 "DIE at %s in module %s"),
17752 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
17753 objfile_name (cu
->per_objfile
->objfile
));
17759 /* Return the dwo name or NULL if not present. If present, it is in either
17760 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
17761 static const char *
17762 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
17764 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
17765 if (dwo_name
== nullptr)
17766 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
17770 /* Return non-zero iff the attribute NAME is defined for the given DIE,
17771 and holds a non-zero value. This function should only be used for
17772 DW_FORM_flag or DW_FORM_flag_present attributes. */
17775 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
17777 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
17779 return attr
!= nullptr && attr
->as_boolean ();
17783 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
17785 /* A DIE is a declaration if it has a DW_AT_declaration attribute
17786 which value is non-zero. However, we have to be careful with
17787 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
17788 (via dwarf2_flag_true_p) follows this attribute. So we may
17789 end up accidently finding a declaration attribute that belongs
17790 to a different DIE referenced by the specification attribute,
17791 even though the given DIE does not have a declaration attribute. */
17792 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
17793 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
17796 /* Return the die giving the specification for DIE, if there is
17797 one. *SPEC_CU is the CU containing DIE on input, and the CU
17798 containing the return value on output. If there is no
17799 specification, but there is an abstract origin, that is
17802 static struct die_info
*
17803 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
17805 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
17808 if (spec_attr
== NULL
)
17809 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
17811 if (spec_attr
== NULL
)
17814 return follow_die_ref (die
, spec_attr
, spec_cu
);
17817 /* A convenience function to find the proper .debug_line section for a CU. */
17819 static struct dwarf2_section_info
*
17820 get_debug_line_section (struct dwarf2_cu
*cu
)
17822 struct dwarf2_section_info
*section
;
17823 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17825 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
17827 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17828 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
17829 else if (cu
->per_cu
->is_dwz
)
17831 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
17833 section
= &dwz
->line
;
17836 section
= &per_objfile
->per_bfd
->line
;
17841 /* Read the statement program header starting at OFFSET in
17842 .debug_line, or .debug_line.dwo. Return a pointer
17843 to a struct line_header, allocated using xmalloc.
17844 Returns NULL if there is a problem reading the header, e.g., if it
17845 has a version we don't understand.
17847 NOTE: the strings in the include directory and file name tables of
17848 the returned object point into the dwarf line section buffer,
17849 and must not be freed. */
17851 static line_header_up
17852 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
,
17853 const char *comp_dir
)
17855 struct dwarf2_section_info
*section
;
17856 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17858 section
= get_debug_line_section (cu
);
17859 section
->read (per_objfile
->objfile
);
17860 if (section
->buffer
== NULL
)
17862 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
17863 complaint (_("missing .debug_line.dwo section"));
17865 complaint (_("missing .debug_line section"));
17869 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
17870 per_objfile
, section
, &cu
->header
,
17874 /* Subroutine of dwarf_decode_lines to simplify it.
17875 Return the file name for the given file_entry.
17876 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
17877 If space for the result is malloc'd, *NAME_HOLDER will be set.
17878 Returns NULL if FILE_INDEX should be ignored, i.e., it is
17879 equivalent to CU_INFO. */
17881 static const char *
17882 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
17883 const file_and_directory
&cu_info
,
17884 std::string
&name_holder
)
17886 const char *include_name
= fe
.name
;
17887 const char *include_name_to_compare
= include_name
;
17889 const char *dir_name
= fe
.include_dir (lh
);
17891 std::string hold_compare
;
17892 if (!IS_ABSOLUTE_PATH (include_name
)
17893 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
17895 /* Avoid creating a duplicate name for CU_INFO.
17896 We do this by comparing INCLUDE_NAME and CU_INFO.
17897 Before we do the comparison, however, we need to account
17898 for DIR_NAME and COMP_DIR.
17899 First prepend dir_name (if non-NULL). If we still don't
17900 have an absolute path prepend comp_dir (if non-NULL).
17901 However, the directory we record in the include-file's
17902 psymtab does not contain COMP_DIR (to match the
17903 corresponding symtab(s)).
17908 bash$ gcc -g ./hello.c
17909 include_name = "hello.c"
17911 DW_AT_comp_dir = comp_dir = "/tmp"
17912 DW_AT_name = "./hello.c"
17916 if (dir_name
!= NULL
)
17918 name_holder
= path_join (dir_name
, include_name
);
17919 include_name
= name_holder
.c_str ();
17920 include_name_to_compare
= include_name
;
17922 if (!IS_ABSOLUTE_PATH (include_name
)
17923 && cu_info
.get_comp_dir () != nullptr)
17925 hold_compare
= path_join (cu_info
.get_comp_dir (), include_name
);
17926 include_name_to_compare
= hold_compare
.c_str ();
17930 std::string copied_name
;
17931 const char *cu_filename
= cu_info
.get_name ();
17932 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
17934 copied_name
= path_join (cu_info
.get_comp_dir (), cu_filename
);
17935 cu_filename
= copied_name
.c_str ();
17938 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
17940 return include_name
;
17943 /* State machine to track the state of the line number program. */
17945 class lnp_state_machine
17948 /* Initialize a machine state for the start of a line number
17950 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
);
17952 file_entry
*current_file ()
17954 /* lh->file_names is 0-based, but the file name numbers in the
17955 statement program are 1-based. */
17956 return m_line_header
->file_name_at (m_file
);
17959 /* Record the line in the state machine. END_SEQUENCE is true if
17960 we're processing the end of a sequence. */
17961 void record_line (bool end_sequence
);
17963 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
17964 nop-out rest of the lines in this sequence. */
17965 void check_line_address (struct dwarf2_cu
*cu
,
17966 const gdb_byte
*line_ptr
,
17967 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
17969 void handle_set_discriminator (unsigned int discriminator
)
17971 m_discriminator
= discriminator
;
17972 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
17975 /* Handle DW_LNE_set_address. */
17976 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
17979 address
+= baseaddr
;
17980 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
17983 /* Handle DW_LNS_advance_pc. */
17984 void handle_advance_pc (CORE_ADDR adjust
);
17986 /* Handle a special opcode. */
17987 void handle_special_opcode (unsigned char op_code
);
17989 /* Handle DW_LNS_advance_line. */
17990 void handle_advance_line (int line_delta
)
17992 advance_line (line_delta
);
17995 /* Handle DW_LNS_set_file. */
17996 void handle_set_file (file_name_index file
);
17998 /* Handle DW_LNS_negate_stmt. */
17999 void handle_negate_stmt ()
18001 m_flags
^= LEF_IS_STMT
;
18004 /* Handle DW_LNS_const_add_pc. */
18005 void handle_const_add_pc ();
18007 /* Handle DW_LNS_fixed_advance_pc. */
18008 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
18010 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18014 /* Handle DW_LNS_copy. */
18015 void handle_copy ()
18017 record_line (false);
18018 m_discriminator
= 0;
18019 m_flags
&= ~LEF_PROLOGUE_END
;
18022 /* Handle DW_LNE_end_sequence. */
18023 void handle_end_sequence ()
18025 m_currently_recording_lines
= true;
18028 /* Handle DW_LNS_set_prologue_end. */
18029 void handle_set_prologue_end ()
18031 m_flags
|= LEF_PROLOGUE_END
;
18035 /* Advance the line by LINE_DELTA. */
18036 void advance_line (int line_delta
)
18038 m_line
+= line_delta
;
18040 if (line_delta
!= 0)
18041 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18044 struct dwarf2_cu
*m_cu
;
18046 gdbarch
*m_gdbarch
;
18048 /* The line number header. */
18049 line_header
*m_line_header
;
18051 /* These are part of the standard DWARF line number state machine,
18052 and initialized according to the DWARF spec. */
18054 unsigned char m_op_index
= 0;
18055 /* The line table index of the current file. */
18056 file_name_index m_file
= 1;
18057 unsigned int m_line
= 1;
18059 /* These are initialized in the constructor. */
18061 CORE_ADDR m_address
;
18062 linetable_entry_flags m_flags
;
18063 unsigned int m_discriminator
= 0;
18065 /* Additional bits of state we need to track. */
18067 /* The last file that we called dwarf2_start_subfile for.
18068 This is only used for TLLs. */
18069 unsigned int m_last_file
= 0;
18070 /* The last file a line number was recorded for. */
18071 struct subfile
*m_last_subfile
= NULL
;
18073 /* The address of the last line entry. */
18074 CORE_ADDR m_last_address
;
18076 /* Set to true when a previous line at the same address (using
18077 m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
18078 when a line entry at a new address (m_address different to
18079 m_last_address) is processed. */
18080 bool m_stmt_at_address
= false;
18082 /* When true, record the lines we decode. */
18083 bool m_currently_recording_lines
= true;
18085 /* The last line number that was recorded, used to coalesce
18086 consecutive entries for the same line. This can happen, for
18087 example, when discriminators are present. PR 17276. */
18088 unsigned int m_last_line
= 0;
18089 bool m_line_has_non_zero_discriminator
= false;
18093 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
18095 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
18096 / m_line_header
->maximum_ops_per_instruction
)
18097 * m_line_header
->minimum_instruction_length
);
18098 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18099 m_op_index
= ((m_op_index
+ adjust
)
18100 % m_line_header
->maximum_ops_per_instruction
);
18104 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
18106 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
18107 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
18108 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
18109 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
18110 / m_line_header
->maximum_ops_per_instruction
)
18111 * m_line_header
->minimum_instruction_length
);
18112 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18113 m_op_index
= ((m_op_index
+ adj_opcode_d
)
18114 % m_line_header
->maximum_ops_per_instruction
);
18116 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
18117 advance_line (line_delta
);
18118 record_line (false);
18119 m_discriminator
= 0;
18120 m_flags
&= ~LEF_PROLOGUE_END
;
18124 lnp_state_machine::handle_set_file (file_name_index file
)
18128 const file_entry
*fe
= current_file ();
18130 dwarf2_debug_line_missing_file_complaint ();
18133 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
18134 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
18135 dwarf2_start_subfile (m_cu
, *fe
, *m_line_header
);
18140 lnp_state_machine::handle_const_add_pc ()
18143 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
18146 = (((m_op_index
+ adjust
)
18147 / m_line_header
->maximum_ops_per_instruction
)
18148 * m_line_header
->minimum_instruction_length
);
18150 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
18151 m_op_index
= ((m_op_index
+ adjust
)
18152 % m_line_header
->maximum_ops_per_instruction
);
18155 /* Return non-zero if we should add LINE to the line number table.
18156 LINE is the line to add, LAST_LINE is the last line that was added,
18157 LAST_SUBFILE is the subfile for LAST_LINE.
18158 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
18159 had a non-zero discriminator.
18161 We have to be careful in the presence of discriminators.
18162 E.g., for this line:
18164 for (i = 0; i < 100000; i++);
18166 clang can emit four line number entries for that one line,
18167 each with a different discriminator.
18168 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
18170 However, we want gdb to coalesce all four entries into one.
18171 Otherwise the user could stepi into the middle of the line and
18172 gdb would get confused about whether the pc really was in the
18173 middle of the line.
18175 Things are further complicated by the fact that two consecutive
18176 line number entries for the same line is a heuristic used by gcc
18177 to denote the end of the prologue. So we can't just discard duplicate
18178 entries, we have to be selective about it. The heuristic we use is
18179 that we only collapse consecutive entries for the same line if at least
18180 one of those entries has a non-zero discriminator. PR 17276.
18182 Note: Addresses in the line number state machine can never go backwards
18183 within one sequence, thus this coalescing is ok. */
18186 dwarf_record_line_p (struct dwarf2_cu
*cu
,
18187 unsigned int line
, unsigned int last_line
,
18188 int line_has_non_zero_discriminator
,
18189 struct subfile
*last_subfile
)
18191 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
18193 if (line
!= last_line
)
18195 /* Same line for the same file that we've seen already.
18196 As a last check, for pr 17276, only record the line if the line
18197 has never had a non-zero discriminator. */
18198 if (!line_has_non_zero_discriminator
)
18203 /* Use the CU's builder to record line number LINE beginning at
18204 address ADDRESS in the line table of subfile SUBFILE. */
18207 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18208 unsigned int line
, CORE_ADDR address
,
18209 linetable_entry_flags flags
,
18210 struct dwarf2_cu
*cu
)
18212 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
18214 if (dwarf_line_debug
)
18216 gdb_printf (gdb_stdlog
,
18217 "Recording line %u, file %s, address %s\n",
18218 line
, lbasename (subfile
->name
.c_str ()),
18219 paddress (gdbarch
, address
));
18223 cu
->get_builder ()->record_line (subfile
, line
, addr
, flags
);
18226 /* Subroutine of dwarf_decode_lines_1 to simplify it.
18227 Mark the end of a set of line number records.
18228 The arguments are the same as for dwarf_record_line_1.
18229 If SUBFILE is NULL the request is ignored. */
18232 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
18233 CORE_ADDR address
, struct dwarf2_cu
*cu
)
18235 if (subfile
== NULL
)
18238 if (dwarf_line_debug
)
18240 gdb_printf (gdb_stdlog
,
18241 "Finishing current line, file %s, address %s\n",
18242 lbasename (subfile
->name
.c_str ()),
18243 paddress (gdbarch
, address
));
18246 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, LEF_IS_STMT
, cu
);
18250 lnp_state_machine::record_line (bool end_sequence
)
18252 if (dwarf_line_debug
)
18254 gdb_printf (gdb_stdlog
,
18255 "Processing actual line %u: file %u,"
18256 " address %s, is_stmt %u, prologue_end %u, discrim %u%s\n",
18258 paddress (m_gdbarch
, m_address
),
18259 (m_flags
& LEF_IS_STMT
) != 0,
18260 (m_flags
& LEF_PROLOGUE_END
) != 0,
18262 (end_sequence
? "\t(end sequence)" : ""));
18265 file_entry
*fe
= current_file ();
18268 dwarf2_debug_line_missing_file_complaint ();
18269 /* For now we ignore lines not starting on an instruction boundary.
18270 But not when processing end_sequence for compatibility with the
18271 previous version of the code. */
18272 else if (m_op_index
== 0 || end_sequence
)
18274 /* When we switch files we insert an end maker in the first file,
18275 switch to the second file and add a new line entry. The
18276 problem is that the end marker inserted in the first file will
18277 discard any previous line entries at the same address. If the
18278 line entries in the first file are marked as is-stmt, while
18279 the new line in the second file is non-stmt, then this means
18280 the end marker will discard is-stmt lines so we can have a
18281 non-stmt line. This means that there are less addresses at
18282 which the user can insert a breakpoint.
18284 To improve this we track the last address in m_last_address,
18285 and whether we have seen an is-stmt at this address. Then
18286 when switching files, if we have seen a stmt at the current
18287 address, and we are switching to create a non-stmt line, then
18288 discard the new line. */
18290 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
18291 bool ignore_this_line
18292 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
18293 && ((m_flags
& LEF_IS_STMT
) == 0)
18294 && m_stmt_at_address
)
18295 || (!end_sequence
&& m_line
== 0));
18297 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
18299 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
18300 m_currently_recording_lines
? m_cu
: nullptr);
18303 if (!end_sequence
&& !ignore_this_line
)
18305 linetable_entry_flags lte_flags
= m_flags
;
18306 if (producer_is_codewarrior (m_cu
))
18307 lte_flags
|= LEF_IS_STMT
;
18309 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
18310 m_line_has_non_zero_discriminator
,
18313 buildsym_compunit
*builder
= m_cu
->get_builder ();
18314 dwarf_record_line_1 (m_gdbarch
,
18315 builder
->get_current_subfile (),
18316 m_line
, m_address
, lte_flags
,
18317 m_currently_recording_lines
? m_cu
: nullptr);
18319 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
18320 m_last_line
= m_line
;
18324 /* Track whether we have seen any IS_STMT true at m_address in case we
18325 have multiple line table entries all at m_address. */
18326 if (m_last_address
!= m_address
)
18328 m_stmt_at_address
= false;
18329 m_last_address
= m_address
;
18331 m_stmt_at_address
|= (m_flags
& LEF_IS_STMT
) != 0;
18334 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
18338 m_line_header (lh
),
18339 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as
18340 if there was a line entry for it so that the backend has a
18341 chance to adjust it and also record it in case it needs it.
18342 This is currently used by MIPS code,
18343 cf. `mips_adjust_dwarf2_line'. */
18344 m_address (gdbarch_adjust_dwarf2_line (arch
, 0, 0)),
18345 m_flags (lh
->default_is_stmt
? LEF_IS_STMT
: (linetable_entry_flags
) 0),
18346 m_last_address (m_address
)
18351 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
18352 const gdb_byte
*line_ptr
,
18353 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
18355 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
18356 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
18357 located at 0x0. In this case, additionally check that if
18358 ADDRESS < UNRELOCATED_LOWPC. */
18360 if ((address
== 0 && address
< unrelocated_lowpc
)
18361 || address
== (CORE_ADDR
) -1)
18363 /* This line table is for a function which has been
18364 GCd by the linker. Ignore it. PR gdb/12528 */
18366 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18367 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
18369 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
18370 line_offset
, objfile_name (objfile
));
18371 m_currently_recording_lines
= false;
18372 /* Note: m_currently_recording_lines is left as false until we see
18373 DW_LNE_end_sequence. */
18377 /* Subroutine of dwarf_decode_lines to simplify it.
18378 Process the line number information in LH. */
18381 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18384 const gdb_byte
*line_ptr
, *extended_end
;
18385 const gdb_byte
*line_end
;
18386 unsigned int bytes_read
, extended_len
;
18387 unsigned char op_code
, extended_op
;
18388 CORE_ADDR baseaddr
;
18389 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18390 bfd
*abfd
= objfile
->obfd
.get ();
18391 struct gdbarch
*gdbarch
= objfile
->arch ();
18393 baseaddr
= objfile
->text_section_offset ();
18395 line_ptr
= lh
->statement_program_start
;
18396 line_end
= lh
->statement_program_end
;
18398 /* Read the statement sequences until there's nothing left. */
18399 while (line_ptr
< line_end
)
18401 /* The DWARF line number program state machine. Reset the state
18402 machine at the start of each sequence. */
18403 lnp_state_machine
state_machine (cu
, gdbarch
, lh
);
18404 bool end_sequence
= false;
18406 /* Start a subfile for the current file of the state
18408 const file_entry
*fe
= state_machine
.current_file ();
18411 dwarf2_start_subfile (cu
, *fe
, *lh
);
18413 /* Decode the table. */
18414 while (line_ptr
< line_end
&& !end_sequence
)
18416 op_code
= read_1_byte (abfd
, line_ptr
);
18419 if (op_code
>= lh
->opcode_base
)
18421 /* Special opcode. */
18422 state_machine
.handle_special_opcode (op_code
);
18424 else switch (op_code
)
18426 case DW_LNS_extended_op
:
18427 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
18429 line_ptr
+= bytes_read
;
18430 extended_end
= line_ptr
+ extended_len
;
18431 extended_op
= read_1_byte (abfd
, line_ptr
);
18433 if (DW_LNE_lo_user
<= extended_op
18434 && extended_op
<= DW_LNE_hi_user
)
18436 /* Vendor extension, ignore. */
18437 line_ptr
= extended_end
;
18440 switch (extended_op
)
18442 case DW_LNE_end_sequence
:
18443 state_machine
.handle_end_sequence ();
18444 end_sequence
= true;
18446 case DW_LNE_set_address
:
18449 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
18450 line_ptr
+= bytes_read
;
18452 state_machine
.check_line_address (cu
, line_ptr
,
18453 lowpc
- baseaddr
, address
);
18454 state_machine
.handle_set_address (baseaddr
, address
);
18457 case DW_LNE_define_file
:
18459 const char *cur_file
;
18460 unsigned int mod_time
, length
;
18463 cur_file
= read_direct_string (abfd
, line_ptr
,
18465 line_ptr
+= bytes_read
;
18466 dindex
= (dir_index
)
18467 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18468 line_ptr
+= bytes_read
;
18470 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18471 line_ptr
+= bytes_read
;
18473 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18474 line_ptr
+= bytes_read
;
18475 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
18478 case DW_LNE_set_discriminator
:
18480 /* The discriminator is not interesting to the
18481 debugger; just ignore it. We still need to
18482 check its value though:
18483 if there are consecutive entries for the same
18484 (non-prologue) line we want to coalesce them.
18487 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18488 line_ptr
+= bytes_read
;
18490 state_machine
.handle_set_discriminator (discr
);
18494 complaint (_("mangled .debug_line section"));
18497 /* Make sure that we parsed the extended op correctly. If e.g.
18498 we expected a different address size than the producer used,
18499 we may have read the wrong number of bytes. */
18500 if (line_ptr
!= extended_end
)
18502 complaint (_("mangled .debug_line section"));
18507 state_machine
.handle_copy ();
18509 case DW_LNS_advance_pc
:
18512 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18513 line_ptr
+= bytes_read
;
18515 state_machine
.handle_advance_pc (adjust
);
18518 case DW_LNS_advance_line
:
18521 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
18522 line_ptr
+= bytes_read
;
18524 state_machine
.handle_advance_line (line_delta
);
18527 case DW_LNS_set_file
:
18529 file_name_index file
18530 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
18532 line_ptr
+= bytes_read
;
18534 state_machine
.handle_set_file (file
);
18537 case DW_LNS_set_column
:
18538 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18539 line_ptr
+= bytes_read
;
18541 case DW_LNS_negate_stmt
:
18542 state_machine
.handle_negate_stmt ();
18544 case DW_LNS_set_basic_block
:
18546 /* Add to the address register of the state machine the
18547 address increment value corresponding to special opcode
18548 255. I.e., this value is scaled by the minimum
18549 instruction length since special opcode 255 would have
18550 scaled the increment. */
18551 case DW_LNS_const_add_pc
:
18552 state_machine
.handle_const_add_pc ();
18554 case DW_LNS_fixed_advance_pc
:
18556 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
18559 state_machine
.handle_fixed_advance_pc (addr_adj
);
18562 case DW_LNS_set_prologue_end
:
18563 state_machine
.handle_set_prologue_end ();
18567 /* Unknown standard opcode, ignore it. */
18570 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
18572 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
18573 line_ptr
+= bytes_read
;
18580 dwarf2_debug_line_missing_end_sequence_complaint ();
18582 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
18583 in which case we still finish recording the last line). */
18584 state_machine
.record_line (true);
18588 /* Decode the Line Number Program (LNP) for the given line_header
18589 structure and CU. The actual information extracted and the type
18590 of structures created from the LNP depends on the value of PST.
18592 FND holds the CU file name and directory, if known.
18593 It is used for relative paths in the line table.
18595 NOTE: It is important that psymtabs have the same file name (via
18596 strcmp) as the corresponding symtab. Since the directory is not
18597 used in the name of the symtab we don't use it in the name of the
18598 psymtabs we create. E.g. expand_line_sal requires this when
18599 finding psymtabs to expand. A good testcase for this is
18602 LOWPC is the lowest address in CU (or 0 if not known).
18604 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
18605 for its PC<->lines mapping information. Otherwise only the filename
18606 table is read in. */
18609 dwarf_decode_lines (struct line_header
*lh
, struct dwarf2_cu
*cu
,
18610 CORE_ADDR lowpc
, int decode_mapping
)
18612 if (decode_mapping
)
18613 dwarf_decode_lines_1 (lh
, cu
, lowpc
);
18615 /* Make sure a symtab is created for every file, even files
18616 which contain only variables (i.e. no code with associated
18618 buildsym_compunit
*builder
= cu
->get_builder ();
18619 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
18621 for (auto &fe
: lh
->file_names ())
18623 dwarf2_start_subfile (cu
, fe
, *lh
);
18624 subfile
*sf
= builder
->get_current_subfile ();
18626 if (sf
->symtab
== nullptr)
18627 sf
->symtab
= allocate_symtab (cust
, sf
->name
.c_str (),
18628 sf
->name_for_id
.c_str ());
18630 fe
.symtab
= sf
->symtab
;
18634 /* Start a subfile for DWARF. FILENAME is the name of the file and
18635 DIRNAME the name of the source directory which contains FILENAME
18636 or NULL if not known.
18637 This routine tries to keep line numbers from identical absolute and
18638 relative file names in a common subfile.
18640 Using the `list' example from the GDB testsuite, which resides in
18641 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
18642 of /srcdir/list0.c yields the following debugging information for list0.c:
18644 DW_AT_name: /srcdir/list0.c
18645 DW_AT_comp_dir: /compdir
18646 files.files[0].name: list0.h
18647 files.files[0].dir: /srcdir
18648 files.files[1].name: list0.c
18649 files.files[1].dir: /srcdir
18651 The line number information for list0.c has to end up in a single
18652 subfile, so that `break /srcdir/list0.c:1' works as expected.
18653 start_subfile will ensure that this happens provided that we pass the
18654 concatenation of files.files[1].dir and files.files[1].name as the
18658 dwarf2_start_subfile (dwarf2_cu
*cu
, const file_entry
&fe
,
18659 const line_header
&lh
)
18661 std::string filename_holder
;
18662 const char *filename
= fe
.name
;
18663 const char *dirname
= lh
.include_dir_at (fe
.d_index
);
18665 /* In order not to lose the line information directory,
18666 we concatenate it to the filename when it makes sense.
18667 Note that the Dwarf3 standard says (speaking of filenames in line
18668 information): ``The directory index is ignored for file names
18669 that represent full path names''. Thus ignoring dirname in the
18670 `else' branch below isn't an issue. */
18672 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
18674 filename_holder
= path_join (dirname
, filename
);
18675 filename
= filename_holder
.c_str ();
18678 std::string filename_for_id
= lh
.file_file_name (fe
);
18679 cu
->get_builder ()->start_subfile (filename
, filename_for_id
.c_str ());
18683 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
18684 struct dwarf2_cu
*cu
)
18686 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18687 struct comp_unit_head
*cu_header
= &cu
->header
;
18689 /* NOTE drow/2003-01-30: There used to be a comment and some special
18690 code here to turn a symbol with DW_AT_external and a
18691 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
18692 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
18693 with some versions of binutils) where shared libraries could have
18694 relocations against symbols in their debug information - the
18695 minimal symbol would have the right address, but the debug info
18696 would not. It's no longer necessary, because we will explicitly
18697 apply relocations when we read in the debug information now. */
18699 /* A DW_AT_location attribute with no contents indicates that a
18700 variable has been optimized away. */
18701 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
18703 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
18707 /* Handle one degenerate form of location expression specially, to
18708 preserve GDB's previous behavior when section offsets are
18709 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
18710 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
18712 if (attr
->form_is_block ())
18714 struct dwarf_block
*block
= attr
->as_block ();
18716 if ((block
->data
[0] == DW_OP_addr
18717 && block
->size
== 1 + cu_header
->addr_size
)
18718 || ((block
->data
[0] == DW_OP_GNU_addr_index
18719 || block
->data
[0] == DW_OP_addrx
)
18721 == 1 + leb128_size (&block
->data
[1]))))
18723 unsigned int dummy
;
18725 if (block
->data
[0] == DW_OP_addr
)
18726 sym
->set_value_address
18727 (cu
->header
.read_address (objfile
->obfd
.get (), block
->data
+ 1,
18730 sym
->set_value_address
18731 (read_addr_index_from_leb128 (cu
, block
->data
+ 1, &dummy
));
18732 sym
->set_aclass_index (LOC_STATIC
);
18733 fixup_symbol_section (sym
, objfile
);
18734 sym
->set_value_address
18735 (sym
->value_address ()
18736 + objfile
->section_offsets
[sym
->section_index ()]);
18741 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
18742 expression evaluator, and use LOC_COMPUTED only when necessary
18743 (i.e. when the value of a register or memory location is
18744 referenced, or a thread-local block, etc.). Then again, it might
18745 not be worthwhile. I'm assuming that it isn't unless performance
18746 or memory numbers show me otherwise. */
18748 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
18750 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
18751 cu
->has_loclist
= true;
18754 /* Given a pointer to a DWARF information entry, figure out if we need
18755 to make a symbol table entry for it, and if so, create a new entry
18756 and return a pointer to it.
18757 If TYPE is NULL, determine symbol type from the die, otherwise
18758 used the passed type.
18759 If SPACE is not NULL, use it to hold the new symbol. If it is
18760 NULL, allocate a new symbol on the objfile's obstack. */
18762 static struct symbol
*
18763 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
18764 struct symbol
*space
)
18766 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18767 struct objfile
*objfile
= per_objfile
->objfile
;
18768 struct gdbarch
*gdbarch
= objfile
->arch ();
18769 struct symbol
*sym
= NULL
;
18771 struct attribute
*attr
= NULL
;
18772 struct attribute
*attr2
= NULL
;
18773 CORE_ADDR baseaddr
;
18774 struct pending
**list_to_add
= NULL
;
18776 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
18778 baseaddr
= objfile
->text_section_offset ();
18780 name
= dwarf2_name (die
, cu
);
18781 if (name
== nullptr && (die
->tag
== DW_TAG_subprogram
18782 || die
->tag
== DW_TAG_inlined_subroutine
18783 || die
->tag
== DW_TAG_entry_point
))
18784 name
= dw2_linkage_name (die
, cu
);
18788 int suppress_add
= 0;
18793 sym
= new (&objfile
->objfile_obstack
) symbol
;
18794 OBJSTAT (objfile
, n_syms
++);
18796 /* Cache this symbol's name and the name's demangled form (if any). */
18797 sym
->set_language (cu
->lang (), &objfile
->objfile_obstack
);
18798 /* Fortran does not have mangling standard and the mangling does differ
18799 between gfortran, iFort etc. */
18800 const char *physname
18801 = (cu
->lang () == language_fortran
18802 ? dwarf2_full_name (name
, die
, cu
)
18803 : dwarf2_physname (name
, die
, cu
));
18804 const char *linkagename
= dw2_linkage_name (die
, cu
);
18806 if (linkagename
== nullptr || cu
->lang () == language_ada
)
18807 sym
->set_linkage_name (physname
);
18810 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
18811 sym
->set_linkage_name (linkagename
);
18814 /* Handle DW_AT_artificial. */
18815 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
18816 if (attr
!= nullptr)
18817 sym
->set_is_artificial (attr
->as_boolean ());
18819 /* Default assumptions.
18820 Use the passed type or decode it from the die. */
18821 sym
->set_domain (VAR_DOMAIN
);
18822 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
18824 sym
->set_type (type
);
18826 sym
->set_type (die_type (die
, cu
));
18827 attr
= dwarf2_attr (die
,
18828 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
18830 if (attr
!= nullptr)
18831 sym
->set_line (attr
->constant_value (0));
18833 attr
= dwarf2_attr (die
,
18834 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
18836 if (attr
!= nullptr && attr
->is_nonnegative ())
18838 file_name_index file_index
18839 = (file_name_index
) attr
->as_nonnegative ();
18840 struct file_entry
*fe
;
18842 if (cu
->line_header
!= NULL
)
18843 fe
= cu
->line_header
->file_name_at (file_index
);
18848 complaint (_("file index out of range"));
18850 sym
->set_symtab (fe
->symtab
);
18856 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
18857 if (attr
!= nullptr)
18861 addr
= attr
->as_address ();
18862 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
18863 sym
->set_section_index (SECT_OFF_TEXT (objfile
));
18864 sym
->set_value_address (addr
);
18865 sym
->set_aclass_index (LOC_LABEL
);
18868 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
18869 sym
->set_type (objfile_type (objfile
)->builtin_core_addr
);
18870 sym
->set_domain (LABEL_DOMAIN
);
18871 add_symbol_to_list (sym
, cu
->list_in_scope
);
18873 case DW_TAG_subprogram
:
18874 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18876 sym
->set_aclass_index (LOC_BLOCK
);
18877 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18878 if ((attr2
!= nullptr && attr2
->as_boolean ())
18879 || cu
->lang () == language_ada
18880 || cu
->lang () == language_fortran
)
18882 /* Subprograms marked external are stored as a global symbol.
18883 Ada and Fortran subprograms, whether marked external or
18884 not, are always stored as a global symbol, because we want
18885 to be able to access them globally. For instance, we want
18886 to be able to break on a nested subprogram without having
18887 to specify the context. */
18888 list_to_add
= cu
->get_builder ()->get_global_symbols ();
18892 list_to_add
= cu
->list_in_scope
;
18895 case DW_TAG_inlined_subroutine
:
18896 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
18898 sym
->set_aclass_index (LOC_BLOCK
);
18899 sym
->set_is_inlined (1);
18900 list_to_add
= cu
->list_in_scope
;
18902 case DW_TAG_template_value_param
:
18904 /* Fall through. */
18905 case DW_TAG_constant
:
18906 case DW_TAG_variable
:
18907 case DW_TAG_member
:
18908 /* Compilation with minimal debug info may result in
18909 variables with missing type entries. Change the
18910 misleading `void' type to something sensible. */
18911 if (sym
->type ()->code () == TYPE_CODE_VOID
)
18912 sym
->set_type (objfile_type (objfile
)->builtin_int
);
18914 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
18915 /* In the case of DW_TAG_member, we should only be called for
18916 static const members. */
18917 if (die
->tag
== DW_TAG_member
)
18919 /* dwarf2_add_field uses die_is_declaration,
18920 so we do the same. */
18921 gdb_assert (die_is_declaration (die
, cu
));
18924 if (attr
!= nullptr)
18926 dwarf2_const_value (attr
, sym
, cu
);
18927 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18930 if (attr2
!= nullptr && attr2
->as_boolean ())
18931 list_to_add
= cu
->get_builder ()->get_global_symbols ();
18933 list_to_add
= cu
->list_in_scope
;
18937 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
18938 if (attr
!= nullptr)
18940 var_decode_location (attr
, sym
, cu
);
18941 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18943 /* Fortran explicitly imports any global symbols to the local
18944 scope by DW_TAG_common_block. */
18945 if (cu
->lang () == language_fortran
&& die
->parent
18946 && die
->parent
->tag
== DW_TAG_common_block
)
18949 if (sym
->aclass () == LOC_STATIC
18950 && sym
->value_address () == 0
18951 && !per_objfile
->per_bfd
->has_section_at_zero
)
18953 /* When a static variable is eliminated by the linker,
18954 the corresponding debug information is not stripped
18955 out, but the variable address is set to null;
18956 do not add such variables into symbol table. */
18958 else if (attr2
!= nullptr && attr2
->as_boolean ())
18960 if (sym
->aclass () == LOC_STATIC
18961 && (objfile
->flags
& OBJF_MAINLINE
) == 0
18962 && per_objfile
->per_bfd
->can_copy
)
18964 /* A global static variable might be subject to
18965 copy relocation. We first check for a local
18966 minsym, though, because maybe the symbol was
18967 marked hidden, in which case this would not
18969 bound_minimal_symbol found
18970 = (lookup_minimal_symbol_linkage
18971 (sym
->linkage_name (), objfile
));
18972 if (found
.minsym
!= nullptr)
18973 sym
->maybe_copied
= 1;
18976 /* A variable with DW_AT_external is never static,
18977 but it may be block-scoped. */
18979 = ((cu
->list_in_scope
18980 == cu
->get_builder ()->get_file_symbols ())
18981 ? cu
->get_builder ()->get_global_symbols ()
18982 : cu
->list_in_scope
);
18985 list_to_add
= cu
->list_in_scope
;
18989 /* We do not know the address of this symbol.
18990 If it is an external symbol and we have type information
18991 for it, enter the symbol as a LOC_UNRESOLVED symbol.
18992 The address of the variable will then be determined from
18993 the minimal symbol table whenever the variable is
18995 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
18997 /* Fortran explicitly imports any global symbols to the local
18998 scope by DW_TAG_common_block. */
18999 if (cu
->lang () == language_fortran
&& die
->parent
19000 && die
->parent
->tag
== DW_TAG_common_block
)
19002 /* SYMBOL_CLASS doesn't matter here because
19003 read_common_block is going to reset it. */
19005 list_to_add
= cu
->list_in_scope
;
19007 else if (attr2
!= nullptr && attr2
->as_boolean ()
19008 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
19010 /* A variable with DW_AT_external is never static, but it
19011 may be block-scoped. */
19013 = ((cu
->list_in_scope
19014 == cu
->get_builder ()->get_file_symbols ())
19015 ? cu
->get_builder ()->get_global_symbols ()
19016 : cu
->list_in_scope
);
19018 sym
->set_aclass_index (LOC_UNRESOLVED
);
19020 else if (!die_is_declaration (die
, cu
))
19022 /* Use the default LOC_OPTIMIZED_OUT class. */
19023 gdb_assert (sym
->aclass () == LOC_OPTIMIZED_OUT
);
19025 list_to_add
= cu
->list_in_scope
;
19029 case DW_TAG_formal_parameter
:
19031 /* If we are inside a function, mark this as an argument. If
19032 not, we might be looking at an argument to an inlined function
19033 when we do not have enough information to show inlined frames;
19034 pretend it's a local variable in that case so that the user can
19036 struct context_stack
*curr
19037 = cu
->get_builder ()->get_current_context_stack ();
19038 if (curr
!= nullptr && curr
->name
!= nullptr)
19039 sym
->set_is_argument (1);
19040 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
19041 if (attr
!= nullptr)
19043 var_decode_location (attr
, sym
, cu
);
19045 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19046 if (attr
!= nullptr)
19048 dwarf2_const_value (attr
, sym
, cu
);
19051 list_to_add
= cu
->list_in_scope
;
19054 case DW_TAG_unspecified_parameters
:
19055 /* From varargs functions; gdb doesn't seem to have any
19056 interest in this information, so just ignore it for now.
19059 case DW_TAG_template_type_param
:
19061 /* Fall through. */
19062 case DW_TAG_class_type
:
19063 case DW_TAG_interface_type
:
19064 case DW_TAG_structure_type
:
19065 case DW_TAG_union_type
:
19066 case DW_TAG_set_type
:
19067 case DW_TAG_enumeration_type
:
19068 case DW_TAG_namelist
:
19069 if (die
->tag
== DW_TAG_namelist
)
19071 sym
->set_aclass_index (LOC_STATIC
);
19072 sym
->set_domain (VAR_DOMAIN
);
19076 sym
->set_aclass_index (LOC_TYPEDEF
);
19077 sym
->set_domain (STRUCT_DOMAIN
);
19080 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
19081 really ever be static objects: otherwise, if you try
19082 to, say, break of a class's method and you're in a file
19083 which doesn't mention that class, it won't work unless
19084 the check for all static symbols in lookup_symbol_aux
19085 saves you. See the OtherFileClass tests in
19086 gdb.c++/namespace.exp. */
19090 buildsym_compunit
*builder
= cu
->get_builder ();
19092 = (cu
->list_in_scope
== builder
->get_file_symbols ()
19093 && cu
->lang () == language_cplus
19094 ? builder
->get_global_symbols ()
19095 : cu
->list_in_scope
);
19097 /* The semantics of C++ state that "struct foo {
19098 ... }" also defines a typedef for "foo". */
19099 if (cu
->lang () == language_cplus
19100 || cu
->lang () == language_ada
19101 || cu
->lang () == language_d
19102 || cu
->lang () == language_rust
)
19104 /* The symbol's name is already allocated along
19105 with this objfile, so we don't need to
19106 duplicate it for the type. */
19107 if (sym
->type ()->name () == 0)
19108 sym
->type ()->set_name (sym
->search_name ());
19113 case DW_TAG_typedef
:
19114 sym
->set_aclass_index (LOC_TYPEDEF
);
19115 sym
->set_domain (VAR_DOMAIN
);
19116 list_to_add
= cu
->list_in_scope
;
19118 case DW_TAG_array_type
:
19119 case DW_TAG_base_type
:
19120 case DW_TAG_subrange_type
:
19121 case DW_TAG_generic_subrange
:
19122 case DW_TAG_unspecified_type
:
19123 sym
->set_aclass_index (LOC_TYPEDEF
);
19124 sym
->set_domain (VAR_DOMAIN
);
19125 list_to_add
= cu
->list_in_scope
;
19127 case DW_TAG_enumerator
:
19128 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
19129 if (attr
!= nullptr)
19131 dwarf2_const_value (attr
, sym
, cu
);
19134 /* NOTE: carlton/2003-11-10: See comment above in the
19135 DW_TAG_class_type, etc. block. */
19138 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
19139 && cu
->lang () == language_cplus
19140 ? cu
->get_builder ()->get_global_symbols ()
19141 : cu
->list_in_scope
);
19144 case DW_TAG_imported_declaration
:
19145 case DW_TAG_namespace
:
19146 sym
->set_aclass_index (LOC_TYPEDEF
);
19147 list_to_add
= cu
->get_builder ()->get_global_symbols ();
19149 case DW_TAG_module
:
19150 sym
->set_aclass_index (LOC_TYPEDEF
);
19151 sym
->set_domain (MODULE_DOMAIN
);
19152 list_to_add
= cu
->get_builder ()->get_global_symbols ();
19154 case DW_TAG_common_block
:
19155 sym
->set_aclass_index (LOC_COMMON_BLOCK
);
19156 sym
->set_domain (COMMON_BLOCK_DOMAIN
);
19157 add_symbol_to_list (sym
, cu
->list_in_scope
);
19160 /* Not a tag we recognize. Hopefully we aren't processing
19161 trash data, but since we must specifically ignore things
19162 we don't recognize, there is nothing else we should do at
19164 complaint (_("unsupported tag: '%s'"),
19165 dwarf_tag_name (die
->tag
));
19171 sym
->hash_next
= objfile
->template_symbols
;
19172 objfile
->template_symbols
= sym
;
19173 list_to_add
= NULL
;
19176 if (list_to_add
!= NULL
)
19177 add_symbol_to_list (sym
, list_to_add
);
19179 /* For the benefit of old versions of GCC, check for anonymous
19180 namespaces based on the demangled name. */
19181 if (!cu
->processing_has_namespace_info
19182 && cu
->lang () == language_cplus
)
19183 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
19188 /* Given an attr with a DW_FORM_dataN value in host byte order,
19189 zero-extend it as appropriate for the symbol's type. The DWARF
19190 standard (v4) is not entirely clear about the meaning of using
19191 DW_FORM_dataN for a constant with a signed type, where the type is
19192 wider than the data. The conclusion of a discussion on the DWARF
19193 list was that this is unspecified. We choose to always zero-extend
19194 because that is the interpretation long in use by GCC. */
19197 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
19198 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
19200 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19201 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
.get ()) ?
19202 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
19203 LONGEST l
= attr
->constant_value (0);
19205 if (bits
< sizeof (*value
) * 8)
19207 l
&= ((LONGEST
) 1 << bits
) - 1;
19210 else if (bits
== sizeof (*value
) * 8)
19214 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
19215 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
19222 /* Read a constant value from an attribute. Either set *VALUE, or if
19223 the value does not fit in *VALUE, set *BYTES - either already
19224 allocated on the objfile obstack, or newly allocated on OBSTACK,
19225 or, set *BATON, if we translated the constant to a location
19229 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
19230 const char *name
, struct obstack
*obstack
,
19231 struct dwarf2_cu
*cu
,
19232 LONGEST
*value
, const gdb_byte
**bytes
,
19233 struct dwarf2_locexpr_baton
**baton
)
19235 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19236 struct objfile
*objfile
= per_objfile
->objfile
;
19237 struct comp_unit_head
*cu_header
= &cu
->header
;
19238 struct dwarf_block
*blk
;
19239 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
.get ()) ?
19240 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
19246 switch (attr
->form
)
19249 case DW_FORM_addrx
:
19250 case DW_FORM_GNU_addr_index
:
19254 if (type
->length () != cu_header
->addr_size
)
19255 dwarf2_const_value_length_mismatch_complaint (name
,
19256 cu_header
->addr_size
,
19258 /* Symbols of this form are reasonably rare, so we just
19259 piggyback on the existing location code rather than writing
19260 a new implementation of symbol_computed_ops. */
19261 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
19262 (*baton
)->per_objfile
= per_objfile
;
19263 (*baton
)->per_cu
= cu
->per_cu
;
19264 gdb_assert ((*baton
)->per_cu
);
19266 (*baton
)->size
= 2 + cu_header
->addr_size
;
19267 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
19268 (*baton
)->data
= data
;
19270 data
[0] = DW_OP_addr
;
19271 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
19272 byte_order
, attr
->as_address ());
19273 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
19276 case DW_FORM_string
:
19279 case DW_FORM_GNU_str_index
:
19280 case DW_FORM_GNU_strp_alt
:
19281 /* The string is already allocated on the objfile obstack, point
19283 *bytes
= (const gdb_byte
*) attr
->as_string ();
19285 case DW_FORM_block1
:
19286 case DW_FORM_block2
:
19287 case DW_FORM_block4
:
19288 case DW_FORM_block
:
19289 case DW_FORM_exprloc
:
19290 case DW_FORM_data16
:
19291 blk
= attr
->as_block ();
19292 if (type
->length () != blk
->size
)
19293 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
19295 *bytes
= blk
->data
;
19298 /* The DW_AT_const_value attributes are supposed to carry the
19299 symbol's value "represented as it would be on the target
19300 architecture." By the time we get here, it's already been
19301 converted to host endianness, so we just need to sign- or
19302 zero-extend it as appropriate. */
19303 case DW_FORM_data1
:
19304 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
19306 case DW_FORM_data2
:
19307 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
19309 case DW_FORM_data4
:
19310 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
19312 case DW_FORM_data8
:
19313 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
19316 case DW_FORM_sdata
:
19317 case DW_FORM_implicit_const
:
19318 *value
= attr
->as_signed ();
19321 case DW_FORM_udata
:
19322 *value
= attr
->as_unsigned ();
19326 complaint (_("unsupported const value attribute form: '%s'"),
19327 dwarf_form_name (attr
->form
));
19334 /* Copy constant value from an attribute to a symbol. */
19337 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
19338 struct dwarf2_cu
*cu
)
19340 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19342 const gdb_byte
*bytes
;
19343 struct dwarf2_locexpr_baton
*baton
;
19345 dwarf2_const_value_attr (attr
, sym
->type (),
19346 sym
->print_name (),
19347 &objfile
->objfile_obstack
, cu
,
19348 &value
, &bytes
, &baton
);
19352 SYMBOL_LOCATION_BATON (sym
) = baton
;
19353 sym
->set_aclass_index (dwarf2_locexpr_index
);
19355 else if (bytes
!= NULL
)
19357 sym
->set_value_bytes (bytes
);
19358 sym
->set_aclass_index (LOC_CONST_BYTES
);
19362 sym
->set_value_longest (value
);
19363 sym
->set_aclass_index (LOC_CONST
);
19367 /* Return the type of the die in question using its DW_AT_type attribute. */
19369 static struct type
*
19370 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19372 struct attribute
*type_attr
;
19374 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
19377 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19378 /* A missing DW_AT_type represents a void type. */
19379 return objfile_type (objfile
)->builtin_void
;
19382 return lookup_die_type (die
, type_attr
, cu
);
19385 /* True iff CU's producer generates GNAT Ada auxiliary information
19386 that allows to find parallel types through that information instead
19387 of having to do expensive parallel lookups by type name. */
19390 need_gnat_info (struct dwarf2_cu
*cu
)
19392 /* Assume that the Ada compiler was GNAT, which always produces
19393 the auxiliary information. */
19394 return (cu
->lang () == language_ada
);
19397 /* Return the auxiliary type of the die in question using its
19398 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
19399 attribute is not present. */
19401 static struct type
*
19402 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19404 struct attribute
*type_attr
;
19406 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
19410 return lookup_die_type (die
, type_attr
, cu
);
19413 /* If DIE has a descriptive_type attribute, then set the TYPE's
19414 descriptive type accordingly. */
19417 set_descriptive_type (struct type
*type
, struct die_info
*die
,
19418 struct dwarf2_cu
*cu
)
19420 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
19422 if (descriptive_type
)
19424 ALLOCATE_GNAT_AUX_TYPE (type
);
19425 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
19429 /* Return the containing type of the die in question using its
19430 DW_AT_containing_type attribute. */
19432 static struct type
*
19433 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19435 struct attribute
*type_attr
;
19436 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19438 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
19440 error (_("Dwarf Error: Problem turning containing type into gdb type "
19441 "[in module %s]"), objfile_name (objfile
));
19443 return lookup_die_type (die
, type_attr
, cu
);
19446 /* Return an error marker type to use for the ill formed type in DIE/CU. */
19448 static struct type
*
19449 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
19451 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19452 struct objfile
*objfile
= per_objfile
->objfile
;
19455 std::string message
19456 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
19457 objfile_name (objfile
),
19458 sect_offset_str (cu
->header
.sect_off
),
19459 sect_offset_str (die
->sect_off
));
19460 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
19462 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
19465 /* Look up the type of DIE in CU using its type attribute ATTR.
19466 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
19467 DW_AT_containing_type.
19468 If there is no type substitute an error marker. */
19470 static struct type
*
19471 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
19472 struct dwarf2_cu
*cu
)
19474 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19475 struct objfile
*objfile
= per_objfile
->objfile
;
19476 struct type
*this_type
;
19478 gdb_assert (attr
->name
== DW_AT_type
19479 || attr
->name
== DW_AT_GNAT_descriptive_type
19480 || attr
->name
== DW_AT_containing_type
);
19482 /* First see if we have it cached. */
19484 if (attr
->form
== DW_FORM_GNU_ref_alt
)
19486 struct dwarf2_per_cu_data
*per_cu
;
19487 sect_offset sect_off
= attr
->get_ref_die_offset ();
19489 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
19490 per_objfile
->per_bfd
);
19491 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
19493 else if (attr
->form_is_ref ())
19495 sect_offset sect_off
= attr
->get_ref_die_offset ();
19497 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
19499 else if (attr
->form
== DW_FORM_ref_sig8
)
19501 ULONGEST signature
= attr
->as_signature ();
19503 return get_signatured_type (die
, signature
, cu
);
19507 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
19508 " at %s [in module %s]"),
19509 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
19510 objfile_name (objfile
));
19511 return build_error_marker_type (cu
, die
);
19514 /* If not cached we need to read it in. */
19516 if (this_type
== NULL
)
19518 struct die_info
*type_die
= NULL
;
19519 struct dwarf2_cu
*type_cu
= cu
;
19521 if (attr
->form_is_ref ())
19522 type_die
= follow_die_ref (die
, attr
, &type_cu
);
19523 if (type_die
== NULL
)
19524 return build_error_marker_type (cu
, die
);
19525 /* If we find the type now, it's probably because the type came
19526 from an inter-CU reference and the type's CU got expanded before
19528 this_type
= read_type_die (type_die
, type_cu
);
19531 /* If we still don't have a type use an error marker. */
19533 if (this_type
== NULL
)
19534 return build_error_marker_type (cu
, die
);
19539 /* Return the type in DIE, CU.
19540 Returns NULL for invalid types.
19542 This first does a lookup in die_type_hash,
19543 and only reads the die in if necessary.
19545 NOTE: This can be called when reading in partial or full symbols. */
19547 static struct type
*
19548 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
19550 struct type
*this_type
;
19552 this_type
= get_die_type (die
, cu
);
19556 return read_type_die_1 (die
, cu
);
19559 /* Read the type in DIE, CU.
19560 Returns NULL for invalid types. */
19562 static struct type
*
19563 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
19565 struct type
*this_type
= NULL
;
19569 case DW_TAG_class_type
:
19570 case DW_TAG_interface_type
:
19571 case DW_TAG_structure_type
:
19572 case DW_TAG_union_type
:
19573 this_type
= read_structure_type (die
, cu
);
19575 case DW_TAG_enumeration_type
:
19576 this_type
= read_enumeration_type (die
, cu
);
19578 case DW_TAG_subprogram
:
19579 case DW_TAG_subroutine_type
:
19580 case DW_TAG_inlined_subroutine
:
19581 this_type
= read_subroutine_type (die
, cu
);
19583 case DW_TAG_array_type
:
19584 this_type
= read_array_type (die
, cu
);
19586 case DW_TAG_set_type
:
19587 this_type
= read_set_type (die
, cu
);
19589 case DW_TAG_pointer_type
:
19590 this_type
= read_tag_pointer_type (die
, cu
);
19592 case DW_TAG_ptr_to_member_type
:
19593 this_type
= read_tag_ptr_to_member_type (die
, cu
);
19595 case DW_TAG_reference_type
:
19596 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
19598 case DW_TAG_rvalue_reference_type
:
19599 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
19601 case DW_TAG_const_type
:
19602 this_type
= read_tag_const_type (die
, cu
);
19604 case DW_TAG_volatile_type
:
19605 this_type
= read_tag_volatile_type (die
, cu
);
19607 case DW_TAG_restrict_type
:
19608 this_type
= read_tag_restrict_type (die
, cu
);
19610 case DW_TAG_string_type
:
19611 this_type
= read_tag_string_type (die
, cu
);
19613 case DW_TAG_typedef
:
19614 this_type
= read_typedef (die
, cu
);
19616 case DW_TAG_generic_subrange
:
19617 case DW_TAG_subrange_type
:
19618 this_type
= read_subrange_type (die
, cu
);
19620 case DW_TAG_base_type
:
19621 this_type
= read_base_type (die
, cu
);
19623 case DW_TAG_unspecified_type
:
19624 this_type
= read_unspecified_type (die
, cu
);
19626 case DW_TAG_namespace
:
19627 this_type
= read_namespace_type (die
, cu
);
19629 case DW_TAG_module
:
19630 this_type
= read_module_type (die
, cu
);
19632 case DW_TAG_atomic_type
:
19633 this_type
= read_tag_atomic_type (die
, cu
);
19636 complaint (_("unexpected tag in read_type_die: '%s'"),
19637 dwarf_tag_name (die
->tag
));
19644 /* See if we can figure out if the class lives in a namespace. We do
19645 this by looking for a member function; its demangled name will
19646 contain namespace info, if there is any.
19647 Return the computed name or NULL.
19648 Space for the result is allocated on the objfile's obstack.
19649 This is the full-die version of guess_partial_die_structure_name.
19650 In this case we know DIE has no useful parent. */
19652 static const char *
19653 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19655 struct die_info
*spec_die
;
19656 struct dwarf2_cu
*spec_cu
;
19657 struct die_info
*child
;
19658 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19661 spec_die
= die_specification (die
, &spec_cu
);
19662 if (spec_die
!= NULL
)
19668 for (child
= die
->child
;
19670 child
= child
->sibling
)
19672 if (child
->tag
== DW_TAG_subprogram
)
19674 const char *linkage_name
= dw2_linkage_name (child
, cu
);
19676 if (linkage_name
!= NULL
)
19678 gdb::unique_xmalloc_ptr
<char> actual_name
19679 (cu
->language_defn
->class_name_from_physname (linkage_name
));
19680 const char *name
= NULL
;
19682 if (actual_name
!= NULL
)
19684 const char *die_name
= dwarf2_name (die
, cu
);
19686 if (die_name
!= NULL
19687 && strcmp (die_name
, actual_name
.get ()) != 0)
19689 /* Strip off the class name from the full name.
19690 We want the prefix. */
19691 int die_name_len
= strlen (die_name
);
19692 int actual_name_len
= strlen (actual_name
.get ());
19693 const char *ptr
= actual_name
.get ();
19695 /* Test for '::' as a sanity check. */
19696 if (actual_name_len
> die_name_len
+ 2
19697 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
19698 name
= obstack_strndup (
19699 &objfile
->per_bfd
->storage_obstack
,
19700 ptr
, actual_name_len
- die_name_len
- 2);
19711 /* GCC might emit a nameless typedef that has a linkage name. Determine the
19712 prefix part in such case. See
19713 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19715 static const char *
19716 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19718 struct attribute
*attr
;
19721 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
19722 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
19725 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
19728 attr
= dw2_linkage_name_attr (die
, cu
);
19729 const char *attr_name
= attr
->as_string ();
19730 if (attr
== NULL
|| attr_name
== NULL
)
19733 /* dwarf2_name had to be already called. */
19734 gdb_assert (attr
->canonical_string_p ());
19736 /* Strip the base name, keep any leading namespaces/classes. */
19737 base
= strrchr (attr_name
, ':');
19738 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
19741 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19742 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
19744 &base
[-1] - attr_name
);
19747 /* Return the name of the namespace/class that DIE is defined within,
19748 or "" if we can't tell. The caller should not xfree the result.
19750 For example, if we're within the method foo() in the following
19760 then determine_prefix on foo's die will return "N::C". */
19762 static const char *
19763 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
19765 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19766 struct die_info
*parent
, *spec_die
;
19767 struct dwarf2_cu
*spec_cu
;
19768 struct type
*parent_type
;
19769 const char *retval
;
19771 if (cu
->lang () != language_cplus
19772 && cu
->lang () != language_fortran
19773 && cu
->lang () != language_d
19774 && cu
->lang () != language_rust
)
19777 retval
= anonymous_struct_prefix (die
, cu
);
19781 /* We have to be careful in the presence of DW_AT_specification.
19782 For example, with GCC 3.4, given the code
19786 // Definition of N::foo.
19790 then we'll have a tree of DIEs like this:
19792 1: DW_TAG_compile_unit
19793 2: DW_TAG_namespace // N
19794 3: DW_TAG_subprogram // declaration of N::foo
19795 4: DW_TAG_subprogram // definition of N::foo
19796 DW_AT_specification // refers to die #3
19798 Thus, when processing die #4, we have to pretend that we're in
19799 the context of its DW_AT_specification, namely the contex of die
19802 spec_die
= die_specification (die
, &spec_cu
);
19803 if (spec_die
== NULL
)
19804 parent
= die
->parent
;
19807 parent
= spec_die
->parent
;
19811 if (parent
== NULL
)
19813 else if (parent
->building_fullname
)
19816 const char *parent_name
;
19818 /* It has been seen on RealView 2.2 built binaries,
19819 DW_TAG_template_type_param types actually _defined_ as
19820 children of the parent class:
19823 template class <class Enum> Class{};
19824 Class<enum E> class_e;
19826 1: DW_TAG_class_type (Class)
19827 2: DW_TAG_enumeration_type (E)
19828 3: DW_TAG_enumerator (enum1:0)
19829 3: DW_TAG_enumerator (enum2:1)
19831 2: DW_TAG_template_type_param
19832 DW_AT_type DW_FORM_ref_udata (E)
19834 Besides being broken debug info, it can put GDB into an
19835 infinite loop. Consider:
19837 When we're building the full name for Class<E>, we'll start
19838 at Class, and go look over its template type parameters,
19839 finding E. We'll then try to build the full name of E, and
19840 reach here. We're now trying to build the full name of E,
19841 and look over the parent DIE for containing scope. In the
19842 broken case, if we followed the parent DIE of E, we'd again
19843 find Class, and once again go look at its template type
19844 arguments, etc., etc. Simply don't consider such parent die
19845 as source-level parent of this die (it can't be, the language
19846 doesn't allow it), and break the loop here. */
19847 name
= dwarf2_name (die
, cu
);
19848 parent_name
= dwarf2_name (parent
, cu
);
19849 complaint (_("template param type '%s' defined within parent '%s'"),
19850 name
? name
: "<unknown>",
19851 parent_name
? parent_name
: "<unknown>");
19855 switch (parent
->tag
)
19857 case DW_TAG_namespace
:
19858 parent_type
= read_type_die (parent
, cu
);
19859 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
19860 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
19861 Work around this problem here. */
19862 if (cu
->lang () == language_cplus
19863 && strcmp (parent_type
->name (), "::") == 0)
19865 /* We give a name to even anonymous namespaces. */
19866 return parent_type
->name ();
19867 case DW_TAG_class_type
:
19868 case DW_TAG_interface_type
:
19869 case DW_TAG_structure_type
:
19870 case DW_TAG_union_type
:
19871 case DW_TAG_module
:
19872 parent_type
= read_type_die (parent
, cu
);
19873 if (parent_type
->name () != NULL
)
19874 return parent_type
->name ();
19876 /* An anonymous structure is only allowed non-static data
19877 members; no typedefs, no member functions, et cetera.
19878 So it does not need a prefix. */
19880 case DW_TAG_compile_unit
:
19881 case DW_TAG_partial_unit
:
19882 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
19883 if (cu
->lang () == language_cplus
19884 && !per_objfile
->per_bfd
->types
.empty ()
19885 && die
->child
!= NULL
19886 && (die
->tag
== DW_TAG_class_type
19887 || die
->tag
== DW_TAG_structure_type
19888 || die
->tag
== DW_TAG_union_type
))
19890 const char *name
= guess_full_die_structure_name (die
, cu
);
19895 case DW_TAG_subprogram
:
19896 /* Nested subroutines in Fortran get a prefix with the name
19897 of the parent's subroutine. */
19898 if (cu
->lang () == language_fortran
)
19900 if ((die
->tag
== DW_TAG_subprogram
)
19901 && (dwarf2_name (parent
, cu
) != NULL
))
19902 return dwarf2_name (parent
, cu
);
19905 case DW_TAG_enumeration_type
:
19906 parent_type
= read_type_die (parent
, cu
);
19907 if (parent_type
->is_declared_class ())
19909 if (parent_type
->name () != NULL
)
19910 return parent_type
->name ();
19913 /* Fall through. */
19915 return determine_prefix (parent
, cu
);
19919 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
19920 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
19921 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
19922 an obconcat, otherwise allocate storage for the result. The CU argument is
19923 used to determine the language and hence, the appropriate separator. */
19925 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
19928 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
19929 int physname
, struct dwarf2_cu
*cu
)
19931 const char *lead
= "";
19934 if (suffix
== NULL
|| suffix
[0] == '\0'
19935 || prefix
== NULL
|| prefix
[0] == '\0')
19937 else if (cu
->lang () == language_d
)
19939 /* For D, the 'main' function could be defined in any module, but it
19940 should never be prefixed. */
19941 if (strcmp (suffix
, "D main") == 0)
19949 else if (cu
->lang () == language_fortran
&& physname
)
19951 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
19952 DW_AT_MIPS_linkage_name is preferred and used instead. */
19960 if (prefix
== NULL
)
19962 if (suffix
== NULL
)
19969 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
19971 strcpy (retval
, lead
);
19972 strcat (retval
, prefix
);
19973 strcat (retval
, sep
);
19974 strcat (retval
, suffix
);
19979 /* We have an obstack. */
19980 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
19984 /* Return a generic name for a DW_TAG_template_type_param or
19985 DW_TAG_template_value_param tag, missing a DW_AT_name attribute. We do this
19986 per parent, so each function/class/struct template will have their own set
19987 of template parameters named <unnnamed0>, <unnamed1>, ... where the
19988 enumeration starts at 0 and represents the position of the template tag in
19989 the list of unnamed template tags for this parent, counting both, type and
19992 static const char *
19993 unnamed_template_tag_name (die_info
*die
, dwarf2_cu
*cu
)
19995 if (die
->parent
== nullptr)
19998 /* Count the parent types unnamed template type and value children until, we
19999 arrive at our entry. */
20000 size_t nth_unnamed
= 0;
20002 die_info
*child
= die
->parent
->child
;
20003 while (child
!= die
)
20005 gdb_assert (child
!= nullptr);
20006 if (child
->tag
== DW_TAG_template_type_param
20007 || child
->tag
== DW_TAG_template_value_param
)
20009 if (dwarf2_attr (child
, DW_AT_name
, cu
) == nullptr)
20012 child
= child
->sibling
;
20015 const std::string name_str
= "<unnamed" + std::to_string (nth_unnamed
) + ">";
20016 return cu
->per_objfile
->objfile
->intern (name_str
.c_str ());
20019 /* Get name of a die, return NULL if not found. */
20021 static const char *
20022 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
20023 struct objfile
*objfile
)
20025 if (name
== nullptr)
20028 if (cu
->lang () == language_cplus
)
20030 gdb::unique_xmalloc_ptr
<char> canon_name
20031 = cp_canonicalize_string (name
);
20033 if (canon_name
!= nullptr)
20034 name
= objfile
->intern (canon_name
.get ());
20036 else if (cu
->lang () == language_c
)
20038 gdb::unique_xmalloc_ptr
<char> canon_name
20039 = c_canonicalize_name (name
);
20041 if (canon_name
!= nullptr)
20042 name
= objfile
->intern (canon_name
.get ());
20048 /* Get name of a die, return NULL if not found.
20049 Anonymous namespaces are converted to their magic string. */
20051 static const char *
20052 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20054 struct attribute
*attr
;
20055 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20057 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
20058 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
20059 if (attr_name
== nullptr
20060 && die
->tag
!= DW_TAG_namespace
20061 && die
->tag
!= DW_TAG_class_type
20062 && die
->tag
!= DW_TAG_interface_type
20063 && die
->tag
!= DW_TAG_structure_type
20064 && die
->tag
!= DW_TAG_namelist
20065 && die
->tag
!= DW_TAG_union_type
20066 && die
->tag
!= DW_TAG_template_type_param
20067 && die
->tag
!= DW_TAG_template_value_param
)
20072 /* A member's name should not be canonicalized. This is a bit
20073 of a hack, in that normally it should not be possible to run
20074 into this situation; however, the dw2-unusual-field-names.exp
20075 test creates custom DWARF that does. */
20076 case DW_TAG_member
:
20077 case DW_TAG_compile_unit
:
20078 case DW_TAG_partial_unit
:
20079 /* Compilation units have a DW_AT_name that is a filename, not
20080 a source language identifier. */
20081 case DW_TAG_enumeration_type
:
20082 case DW_TAG_enumerator
:
20083 /* These tags always have simple identifiers already; no need
20084 to canonicalize them. */
20087 case DW_TAG_namespace
:
20088 if (attr_name
!= nullptr)
20090 return CP_ANONYMOUS_NAMESPACE_STR
;
20092 /* DWARF does not actually require template tags to have a name. */
20093 case DW_TAG_template_type_param
:
20094 case DW_TAG_template_value_param
:
20095 if (attr_name
== nullptr)
20096 return unnamed_template_tag_name (die
, cu
);
20098 case DW_TAG_class_type
:
20099 case DW_TAG_interface_type
:
20100 case DW_TAG_structure_type
:
20101 case DW_TAG_union_type
:
20102 case DW_TAG_namelist
:
20103 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
20104 structures or unions. These were of the form "._%d" in GCC 4.1,
20105 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
20106 and GCC 4.4. We work around this problem by ignoring these. */
20107 if (attr_name
!= nullptr
20108 && (startswith (attr_name
, "._")
20109 || startswith (attr_name
, "<anonymous")))
20112 /* GCC might emit a nameless typedef that has a linkage name. See
20113 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20114 if (!attr
|| attr_name
== NULL
)
20116 attr
= dw2_linkage_name_attr (die
, cu
);
20117 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
20118 if (attr
== NULL
|| attr_name
== NULL
)
20121 /* Avoid demangling attr_name the second time on a second
20122 call for the same DIE. */
20123 if (!attr
->canonical_string_p ())
20125 gdb::unique_xmalloc_ptr
<char> demangled
20126 (gdb_demangle (attr_name
, DMGL_TYPES
));
20127 if (demangled
== nullptr)
20130 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
20131 attr_name
= attr
->as_string ();
20134 /* Strip any leading namespaces/classes, keep only the
20135 base name. DW_AT_name for named DIEs does not
20136 contain the prefixes. */
20137 const char *base
= strrchr (attr_name
, ':');
20138 if (base
&& base
> attr_name
&& base
[-1] == ':')
20149 if (!attr
->canonical_string_p ())
20150 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
20152 return attr
->as_string ();
20155 /* Return the die that this die in an extension of, or NULL if there
20156 is none. *EXT_CU is the CU containing DIE on input, and the CU
20157 containing the return value on output. */
20159 static struct die_info
*
20160 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
20162 struct attribute
*attr
;
20164 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
20168 return follow_die_ref (die
, attr
, ext_cu
);
20172 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
20176 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
20177 to_underlying (die
->sect_off
),
20183 /* Follow reference or signature attribute ATTR of SRC_DIE.
20184 On entry *REF_CU is the CU of SRC_DIE.
20185 On exit *REF_CU is the CU of the result. */
20187 static struct die_info
*
20188 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20189 struct dwarf2_cu
**ref_cu
)
20191 struct die_info
*die
;
20193 if (attr
->form_is_ref ())
20194 die
= follow_die_ref (src_die
, attr
, ref_cu
);
20195 else if (attr
->form
== DW_FORM_ref_sig8
)
20196 die
= follow_die_sig (src_die
, attr
, ref_cu
);
20199 src_die
->error_dump ();
20200 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
20201 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
20207 /* Follow reference OFFSET.
20208 On entry *REF_CU is the CU of the source die referencing OFFSET.
20209 On exit *REF_CU is the CU of the result.
20210 Returns NULL if OFFSET is invalid. */
20212 static struct die_info
*
20213 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
20214 struct dwarf2_cu
**ref_cu
)
20216 struct die_info temp_die
;
20217 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
20218 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20220 gdb_assert (cu
->per_cu
!= NULL
);
20224 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
20225 "source CU contains target offset: %d",
20226 sect_offset_str (cu
->per_cu
->sect_off
),
20227 sect_offset_str (sect_off
),
20228 cu
->header
.offset_in_cu_p (sect_off
));
20230 if (cu
->per_cu
->is_debug_types
)
20232 /* .debug_types CUs cannot reference anything outside their CU.
20233 If they need to, they have to reference a signatured type via
20234 DW_FORM_ref_sig8. */
20235 if (!cu
->header
.offset_in_cu_p (sect_off
))
20238 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
20239 || !cu
->header
.offset_in_cu_p (sect_off
))
20241 struct dwarf2_per_cu_data
*per_cu
;
20243 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20244 per_objfile
->per_bfd
);
20246 dwarf_read_debug_printf_v ("target CU offset: %s, "
20247 "target CU DIEs loaded: %d",
20248 sect_offset_str (per_cu
->sect_off
),
20249 per_objfile
->get_cu (per_cu
) != nullptr);
20251 /* If necessary, add it to the queue and load its DIEs.
20253 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
20254 it doesn't mean they are currently loaded. Since we require them
20255 to be loaded, we must check for ourselves. */
20256 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->lang ())
20257 || per_objfile
->get_cu (per_cu
) == nullptr)
20258 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
20259 false, cu
->lang ());
20261 target_cu
= per_objfile
->get_cu (per_cu
);
20262 gdb_assert (target_cu
!= nullptr);
20264 else if (cu
->dies
== NULL
)
20266 /* We're loading full DIEs during partial symbol reading. */
20267 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
20271 *ref_cu
= target_cu
;
20272 temp_die
.sect_off
= sect_off
;
20274 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
20276 to_underlying (sect_off
));
20279 /* Follow reference attribute ATTR of SRC_DIE.
20280 On entry *REF_CU is the CU of SRC_DIE.
20281 On exit *REF_CU is the CU of the result. */
20283 static struct die_info
*
20284 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
20285 struct dwarf2_cu
**ref_cu
)
20287 sect_offset sect_off
= attr
->get_ref_die_offset ();
20288 struct dwarf2_cu
*cu
= *ref_cu
;
20289 struct die_info
*die
;
20291 die
= follow_die_offset (sect_off
,
20292 (attr
->form
== DW_FORM_GNU_ref_alt
20293 || cu
->per_cu
->is_dwz
),
20296 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
20297 "at %s [in module %s]"),
20298 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
20299 objfile_name (cu
->per_objfile
->objfile
));
20306 struct dwarf2_locexpr_baton
20307 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
20308 dwarf2_per_cu_data
*per_cu
,
20309 dwarf2_per_objfile
*per_objfile
,
20310 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
20311 bool resolve_abstract_p
)
20313 struct die_info
*die
;
20314 struct attribute
*attr
;
20315 struct dwarf2_locexpr_baton retval
;
20316 struct objfile
*objfile
= per_objfile
->objfile
;
20318 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20320 cu
= load_cu (per_cu
, per_objfile
, false);
20324 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20325 Instead just throw an error, not much else we can do. */
20326 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
20327 sect_offset_str (sect_off
), objfile_name (objfile
));
20330 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20332 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
20333 sect_offset_str (sect_off
), objfile_name (objfile
));
20335 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20336 if (!attr
&& resolve_abstract_p
20337 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
20338 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
20340 CORE_ADDR pc
= get_frame_pc ();
20341 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
20342 struct gdbarch
*gdbarch
= objfile
->arch ();
20344 for (const auto &cand_off
20345 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
20347 struct dwarf2_cu
*cand_cu
= cu
;
20348 struct die_info
*cand
20349 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
20352 || cand
->parent
->tag
!= DW_TAG_subprogram
)
20355 CORE_ADDR pc_low
, pc_high
;
20356 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
20357 if (pc_low
== ((CORE_ADDR
) -1))
20359 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
20360 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
20361 if (!(pc_low
<= pc
&& pc
< pc_high
))
20365 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20372 /* DWARF: "If there is no such attribute, then there is no effect.".
20373 DATA is ignored if SIZE is 0. */
20375 retval
.data
= NULL
;
20378 else if (attr
->form_is_section_offset ())
20380 struct dwarf2_loclist_baton loclist_baton
;
20381 CORE_ADDR pc
= get_frame_pc ();
20384 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
20386 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
20388 retval
.size
= size
;
20392 if (!attr
->form_is_block ())
20393 error (_("Dwarf Error: DIE at %s referenced in module %s "
20394 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
20395 sect_offset_str (sect_off
), objfile_name (objfile
));
20397 struct dwarf_block
*block
= attr
->as_block ();
20398 retval
.data
= block
->data
;
20399 retval
.size
= block
->size
;
20401 retval
.per_objfile
= per_objfile
;
20402 retval
.per_cu
= cu
->per_cu
;
20404 per_objfile
->age_comp_units ();
20411 struct dwarf2_locexpr_baton
20412 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
20413 dwarf2_per_cu_data
*per_cu
,
20414 dwarf2_per_objfile
*per_objfile
,
20415 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
20417 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
20419 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
20423 /* Write a constant of a given type as target-ordered bytes into
20426 static const gdb_byte
*
20427 write_constant_as_bytes (struct obstack
*obstack
,
20428 enum bfd_endian byte_order
,
20435 *len
= type
->length ();
20436 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20437 store_unsigned_integer (result
, *len
, byte_order
, value
);
20445 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
20446 dwarf2_per_cu_data
*per_cu
,
20447 dwarf2_per_objfile
*per_objfile
,
20451 struct die_info
*die
;
20452 struct attribute
*attr
;
20453 const gdb_byte
*result
= NULL
;
20456 enum bfd_endian byte_order
;
20457 struct objfile
*objfile
= per_objfile
->objfile
;
20459 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20461 cu
= load_cu (per_cu
, per_objfile
, false);
20465 /* We shouldn't get here for a dummy CU, but don't crash on the user.
20466 Instead just throw an error, not much else we can do. */
20467 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
20468 sect_offset_str (sect_off
), objfile_name (objfile
));
20471 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20473 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
20474 sect_offset_str (sect_off
), objfile_name (objfile
));
20476 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20480 byte_order
= (bfd_big_endian (objfile
->obfd
.get ())
20481 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20483 switch (attr
->form
)
20486 case DW_FORM_addrx
:
20487 case DW_FORM_GNU_addr_index
:
20491 *len
= cu
->header
.addr_size
;
20492 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
20493 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
20497 case DW_FORM_string
:
20500 case DW_FORM_GNU_str_index
:
20501 case DW_FORM_GNU_strp_alt
:
20502 /* The string is already allocated on the objfile obstack, point
20505 const char *attr_name
= attr
->as_string ();
20506 result
= (const gdb_byte
*) attr_name
;
20507 *len
= strlen (attr_name
);
20510 case DW_FORM_block1
:
20511 case DW_FORM_block2
:
20512 case DW_FORM_block4
:
20513 case DW_FORM_block
:
20514 case DW_FORM_exprloc
:
20515 case DW_FORM_data16
:
20517 struct dwarf_block
*block
= attr
->as_block ();
20518 result
= block
->data
;
20519 *len
= block
->size
;
20523 /* The DW_AT_const_value attributes are supposed to carry the
20524 symbol's value "represented as it would be on the target
20525 architecture." By the time we get here, it's already been
20526 converted to host endianness, so we just need to sign- or
20527 zero-extend it as appropriate. */
20528 case DW_FORM_data1
:
20529 type
= die_type (die
, cu
);
20530 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
20531 if (result
== NULL
)
20532 result
= write_constant_as_bytes (obstack
, byte_order
,
20535 case DW_FORM_data2
:
20536 type
= die_type (die
, cu
);
20537 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
20538 if (result
== NULL
)
20539 result
= write_constant_as_bytes (obstack
, byte_order
,
20542 case DW_FORM_data4
:
20543 type
= die_type (die
, cu
);
20544 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
20545 if (result
== NULL
)
20546 result
= write_constant_as_bytes (obstack
, byte_order
,
20549 case DW_FORM_data8
:
20550 type
= die_type (die
, cu
);
20551 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
20552 if (result
== NULL
)
20553 result
= write_constant_as_bytes (obstack
, byte_order
,
20557 case DW_FORM_sdata
:
20558 case DW_FORM_implicit_const
:
20559 type
= die_type (die
, cu
);
20560 result
= write_constant_as_bytes (obstack
, byte_order
,
20561 type
, attr
->as_signed (), len
);
20564 case DW_FORM_udata
:
20565 type
= die_type (die
, cu
);
20566 result
= write_constant_as_bytes (obstack
, byte_order
,
20567 type
, attr
->as_unsigned (), len
);
20571 complaint (_("unsupported const value attribute form: '%s'"),
20572 dwarf_form_name (attr
->form
));
20582 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
20583 dwarf2_per_cu_data
*per_cu
,
20584 dwarf2_per_objfile
*per_objfile
,
20585 const char **var_name
)
20587 struct die_info
*die
;
20589 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20591 cu
= load_cu (per_cu
, per_objfile
, false);
20596 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
20600 if (var_name
!= nullptr)
20601 *var_name
= var_decl_name (die
, cu
);
20602 return die_type (die
, cu
);
20608 dwarf2_get_die_type (cu_offset die_offset
,
20609 dwarf2_per_cu_data
*per_cu
,
20610 dwarf2_per_objfile
*per_objfile
)
20612 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
20613 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
20616 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
20617 On entry *REF_CU is the CU of SRC_DIE.
20618 On exit *REF_CU is the CU of the result.
20619 Returns NULL if the referenced DIE isn't found. */
20621 static struct die_info
*
20622 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
20623 struct dwarf2_cu
**ref_cu
)
20625 struct die_info temp_die
;
20626 struct dwarf2_cu
*sig_cu
;
20627 struct die_info
*die
;
20628 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
20631 /* While it might be nice to assert sig_type->type == NULL here,
20632 we can get here for DW_AT_imported_declaration where we need
20633 the DIE not the type. */
20635 /* If necessary, add it to the queue and load its DIEs.
20637 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
20638 it doesn't mean they are currently loaded. Since we require them
20639 to be loaded, we must check for ourselves. */
20640 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
20642 || per_objfile
->get_cu (sig_type
) == nullptr)
20643 read_signatured_type (sig_type
, per_objfile
);
20645 sig_cu
= per_objfile
->get_cu (sig_type
);
20646 gdb_assert (sig_cu
!= NULL
);
20647 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
20648 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
20649 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
20650 to_underlying (temp_die
.sect_off
));
20653 /* For .gdb_index version 7 keep track of included TUs.
20654 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
20655 if (per_objfile
->per_bfd
->index_table
!= NULL
20656 && !per_objfile
->per_bfd
->index_table
->version_check ())
20658 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
20668 /* Follow signatured type referenced by ATTR in SRC_DIE.
20669 On entry *REF_CU is the CU of SRC_DIE.
20670 On exit *REF_CU is the CU of the result.
20671 The result is the DIE of the type.
20672 If the referenced type cannot be found an error is thrown. */
20674 static struct die_info
*
20675 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
20676 struct dwarf2_cu
**ref_cu
)
20678 ULONGEST signature
= attr
->as_signature ();
20679 struct signatured_type
*sig_type
;
20680 struct die_info
*die
;
20682 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
20684 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
20685 /* sig_type will be NULL if the signatured type is missing from
20687 if (sig_type
== NULL
)
20689 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20690 " from DIE at %s [in module %s]"),
20691 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
20692 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
20695 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
20698 src_die
->error_dump ();
20699 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20700 " from DIE at %s [in module %s]"),
20701 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
20702 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
20708 /* Get the type specified by SIGNATURE referenced in DIE/CU,
20709 reading in and processing the type unit if necessary. */
20711 static struct type
*
20712 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
20713 struct dwarf2_cu
*cu
)
20715 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20716 struct signatured_type
*sig_type
;
20717 struct dwarf2_cu
*type_cu
;
20718 struct die_info
*type_die
;
20721 sig_type
= lookup_signatured_type (cu
, signature
);
20722 /* sig_type will be NULL if the signatured type is missing from
20724 if (sig_type
== NULL
)
20726 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
20727 " from DIE at %s [in module %s]"),
20728 hex_string (signature
), sect_offset_str (die
->sect_off
),
20729 objfile_name (per_objfile
->objfile
));
20730 return build_error_marker_type (cu
, die
);
20733 /* If we already know the type we're done. */
20734 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
20735 if (type
!= nullptr)
20739 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
20740 if (type_die
!= NULL
)
20742 /* N.B. We need to call get_die_type to ensure only one type for this DIE
20743 is created. This is important, for example, because for c++ classes
20744 we need TYPE_NAME set which is only done by new_symbol. Blech. */
20745 type
= read_type_die (type_die
, type_cu
);
20748 complaint (_("Dwarf Error: Cannot build signatured type %s"
20749 " referenced from DIE at %s [in module %s]"),
20750 hex_string (signature
), sect_offset_str (die
->sect_off
),
20751 objfile_name (per_objfile
->objfile
));
20752 type
= build_error_marker_type (cu
, die
);
20757 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
20758 " from DIE at %s [in module %s]"),
20759 hex_string (signature
), sect_offset_str (die
->sect_off
),
20760 objfile_name (per_objfile
->objfile
));
20761 type
= build_error_marker_type (cu
, die
);
20764 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
20769 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
20770 reading in and processing the type unit if necessary. */
20772 static struct type
*
20773 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
20774 struct dwarf2_cu
*cu
) /* ARI: editCase function */
20776 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
20777 if (attr
->form_is_ref ())
20779 struct dwarf2_cu
*type_cu
= cu
;
20780 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
20782 return read_type_die (type_die
, type_cu
);
20784 else if (attr
->form
== DW_FORM_ref_sig8
)
20786 return get_signatured_type (die
, attr
->as_signature (), cu
);
20790 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20792 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
20793 " at %s [in module %s]"),
20794 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
20795 objfile_name (per_objfile
->objfile
));
20796 return build_error_marker_type (cu
, die
);
20800 /* Load the DIEs associated with type unit PER_CU into memory. */
20803 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
20804 dwarf2_per_objfile
*per_objfile
)
20806 struct signatured_type
*sig_type
;
20808 /* We have the per_cu, but we need the signatured_type.
20809 Fortunately this is an easy translation. */
20810 gdb_assert (per_cu
->is_debug_types
);
20811 sig_type
= (struct signatured_type
*) per_cu
;
20813 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
20815 read_signatured_type (sig_type
, per_objfile
);
20817 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
20820 /* Read in a signatured type and build its CU and DIEs.
20821 If the type is a stub for the real type in a DWO file,
20822 read in the real type from the DWO file as well. */
20825 read_signatured_type (signatured_type
*sig_type
,
20826 dwarf2_per_objfile
*per_objfile
)
20828 gdb_assert (sig_type
->is_debug_types
);
20829 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
20831 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
20833 if (!reader
.dummy_p
)
20835 struct dwarf2_cu
*cu
= reader
.cu
;
20836 const gdb_byte
*info_ptr
= reader
.info_ptr
;
20838 gdb_assert (cu
->die_hash
== NULL
);
20840 htab_create_alloc_ex (cu
->header
.get_length_without_initial () / 12,
20844 &cu
->comp_unit_obstack
,
20845 hashtab_obstack_allocate
,
20846 dummy_obstack_deallocate
);
20848 if (reader
.comp_unit_die
->has_children
)
20849 reader
.comp_unit_die
->child
20850 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
20851 reader
.comp_unit_die
);
20852 cu
->dies
= reader
.comp_unit_die
;
20853 /* comp_unit_die is not stored in die_hash, no need. */
20855 /* We try not to read any attributes in this function, because
20856 not all CUs needed for references have been loaded yet, and
20857 symbol table processing isn't initialized. But we have to
20858 set the CU language, or we won't be able to build types
20859 correctly. Similarly, if we do not read the producer, we can
20860 not apply producer-specific interpretation. */
20861 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
20866 sig_type
->tu_read
= 1;
20869 /* Decode simple location descriptions.
20870 Given a pointer to a dwarf block that defines a location, compute
20871 the location and return the value. If COMPUTED is non-null, it is
20872 set to true to indicate that decoding was successful, and false
20873 otherwise. If COMPUTED is null, then this function may emit a
20877 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
20879 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20881 size_t size
= blk
->size
;
20882 const gdb_byte
*data
= blk
->data
;
20883 CORE_ADDR stack
[64];
20885 unsigned int bytes_read
, unsnd
;
20888 if (computed
!= nullptr)
20894 stack
[++stacki
] = 0;
20933 stack
[++stacki
] = op
- DW_OP_lit0
;
20968 stack
[++stacki
] = op
- DW_OP_reg0
;
20971 if (computed
== nullptr)
20972 dwarf2_complex_location_expr_complaint ();
20979 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
20981 stack
[++stacki
] = unsnd
;
20984 if (computed
== nullptr)
20985 dwarf2_complex_location_expr_complaint ();
20992 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
.get (),
20998 case DW_OP_const1u
:
20999 stack
[++stacki
] = read_1_byte (objfile
->obfd
.get (), &data
[i
]);
21003 case DW_OP_const1s
:
21004 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
.get (), &data
[i
]);
21008 case DW_OP_const2u
:
21009 stack
[++stacki
] = read_2_bytes (objfile
->obfd
.get (), &data
[i
]);
21013 case DW_OP_const2s
:
21014 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
.get (), &data
[i
]);
21018 case DW_OP_const4u
:
21019 stack
[++stacki
] = read_4_bytes (objfile
->obfd
.get (), &data
[i
]);
21023 case DW_OP_const4s
:
21024 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
.get (), &data
[i
]);
21028 case DW_OP_const8u
:
21029 stack
[++stacki
] = read_8_bytes (objfile
->obfd
.get (), &data
[i
]);
21034 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
21040 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
21045 stack
[stacki
+ 1] = stack
[stacki
];
21050 stack
[stacki
- 1] += stack
[stacki
];
21054 case DW_OP_plus_uconst
:
21055 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
21061 stack
[stacki
- 1] -= stack
[stacki
];
21066 /* If we're not the last op, then we definitely can't encode
21067 this using GDB's address_class enum. This is valid for partial
21068 global symbols, although the variable's address will be bogus
21072 if (computed
== nullptr)
21073 dwarf2_complex_location_expr_complaint ();
21079 case DW_OP_GNU_push_tls_address
:
21080 case DW_OP_form_tls_address
:
21081 /* The top of the stack has the offset from the beginning
21082 of the thread control block at which the variable is located. */
21083 /* Nothing should follow this operator, so the top of stack would
21085 /* This is valid for partial global symbols, but the variable's
21086 address will be bogus in the psymtab. Make it always at least
21087 non-zero to not look as a variable garbage collected by linker
21088 which have DW_OP_addr 0. */
21091 if (computed
== nullptr)
21092 dwarf2_complex_location_expr_complaint ();
21099 case DW_OP_GNU_uninit
:
21100 if (computed
!= nullptr)
21105 case DW_OP_GNU_addr_index
:
21106 case DW_OP_GNU_const_index
:
21107 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
21113 if (computed
== nullptr)
21115 const char *name
= get_DW_OP_name (op
);
21118 complaint (_("unsupported stack op: '%s'"),
21121 complaint (_("unsupported stack op: '%02x'"),
21125 return (stack
[stacki
]);
21128 /* Enforce maximum stack depth of SIZE-1 to avoid writing
21129 outside of the allocated space. Also enforce minimum>0. */
21130 if (stacki
>= ARRAY_SIZE (stack
) - 1)
21132 if (computed
== nullptr)
21133 complaint (_("location description stack overflow"));
21139 if (computed
== nullptr)
21140 complaint (_("location description stack underflow"));
21145 if (computed
!= nullptr)
21147 return (stack
[stacki
]);
21150 /* memory allocation interface */
21152 static struct dwarf_block
*
21153 dwarf_alloc_block (struct dwarf2_cu
*cu
)
21155 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
21160 /* Macro support. */
21162 /* An overload of dwarf_decode_macros that finds the correct section
21163 and ensures it is read in before calling the other overload. */
21166 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
21167 int section_is_gnu
)
21169 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21170 struct objfile
*objfile
= per_objfile
->objfile
;
21171 const struct line_header
*lh
= cu
->line_header
;
21172 unsigned int offset_size
= cu
->header
.offset_size
;
21173 struct dwarf2_section_info
*section
;
21174 const char *section_name
;
21176 if (cu
->dwo_unit
!= nullptr)
21178 if (section_is_gnu
)
21180 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
21181 section_name
= ".debug_macro.dwo";
21185 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
21186 section_name
= ".debug_macinfo.dwo";
21191 if (section_is_gnu
)
21193 section
= &per_objfile
->per_bfd
->macro
;
21194 section_name
= ".debug_macro";
21198 section
= &per_objfile
->per_bfd
->macinfo
;
21199 section_name
= ".debug_macinfo";
21203 section
->read (objfile
);
21204 if (section
->buffer
== nullptr)
21206 complaint (_("missing %s section"), section_name
);
21210 buildsym_compunit
*builder
= cu
->get_builder ();
21212 struct dwarf2_section_info
*str_offsets_section
;
21213 struct dwarf2_section_info
*str_section
;
21214 gdb::optional
<ULONGEST
> str_offsets_base
;
21216 if (cu
->dwo_unit
!= nullptr)
21218 str_offsets_section
= &cu
->dwo_unit
->dwo_file
21219 ->sections
.str_offsets
;
21220 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
21221 str_offsets_base
= cu
->header
.addr_size
;
21225 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
21226 str_section
= &per_objfile
->per_bfd
->str
;
21227 str_offsets_base
= cu
->str_offsets_base
;
21230 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
21231 offset_size
, offset
, str_section
, str_offsets_section
,
21232 str_offsets_base
, section_is_gnu
, cu
);
21235 /* Return the .debug_loc section to use for CU.
21236 For DWO files use .debug_loc.dwo. */
21238 static struct dwarf2_section_info
*
21239 cu_debug_loc_section (struct dwarf2_cu
*cu
)
21241 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21245 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
21247 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
21249 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
21250 : &per_objfile
->per_bfd
->loc
);
21253 /* Return the .debug_rnglists section to use for CU. */
21254 static struct dwarf2_section_info
*
21255 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
21257 if (cu
->header
.version
< 5)
21258 error (_(".debug_rnglists section cannot be used in DWARF %d"),
21259 cu
->header
.version
);
21260 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
21262 /* Make sure we read the .debug_rnglists section from the file that
21263 contains the DW_AT_ranges attribute we are reading. Normally that
21264 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
21265 or DW_TAG_skeleton unit, we always want to read from objfile/linked
21267 if (cu
->dwo_unit
!= nullptr
21268 && tag
!= DW_TAG_compile_unit
21269 && tag
!= DW_TAG_skeleton_unit
)
21271 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
21273 if (sections
->rnglists
.size
> 0)
21274 return §ions
->rnglists
;
21276 error (_(".debug_rnglists section is missing from .dwo file."));
21278 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
21281 /* A helper function that fills in a dwarf2_loclist_baton. */
21284 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
21285 struct dwarf2_loclist_baton
*baton
,
21286 const struct attribute
*attr
)
21288 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21289 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21291 section
->read (per_objfile
->objfile
);
21293 baton
->per_objfile
= per_objfile
;
21294 baton
->per_cu
= cu
->per_cu
;
21295 gdb_assert (baton
->per_cu
);
21296 /* We don't know how long the location list is, but make sure we
21297 don't run off the edge of the section. */
21298 baton
->size
= section
->size
- attr
->as_unsigned ();
21299 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
21300 if (cu
->base_address
.has_value ())
21301 baton
->base_address
= *cu
->base_address
;
21303 baton
->base_address
= 0;
21304 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
21308 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
21309 struct dwarf2_cu
*cu
, int is_block
)
21311 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21312 struct objfile
*objfile
= per_objfile
->objfile
;
21313 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
21315 if (attr
->form_is_section_offset ()
21316 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
21317 the section. If so, fall through to the complaint in the
21319 && attr
->as_unsigned () < section
->get_size (objfile
))
21321 struct dwarf2_loclist_baton
*baton
;
21323 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
21325 fill_in_loclist_baton (cu
, baton
, attr
);
21327 if (!cu
->base_address
.has_value ())
21328 complaint (_("Location list used without "
21329 "specifying the CU base address."));
21331 sym
->set_aclass_index ((is_block
21332 ? dwarf2_loclist_block_index
21333 : dwarf2_loclist_index
));
21334 SYMBOL_LOCATION_BATON (sym
) = baton
;
21338 struct dwarf2_locexpr_baton
*baton
;
21340 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
21341 baton
->per_objfile
= per_objfile
;
21342 baton
->per_cu
= cu
->per_cu
;
21343 gdb_assert (baton
->per_cu
);
21345 if (attr
->form_is_block ())
21347 /* Note that we're just copying the block's data pointer
21348 here, not the actual data. We're still pointing into the
21349 info_buffer for SYM's objfile; right now we never release
21350 that buffer, but when we do clean up properly this may
21352 struct dwarf_block
*block
= attr
->as_block ();
21353 baton
->size
= block
->size
;
21354 baton
->data
= block
->data
;
21358 dwarf2_invalid_attrib_class_complaint ("location description",
21359 sym
->natural_name ());
21363 sym
->set_aclass_index ((is_block
21364 ? dwarf2_locexpr_block_index
21365 : dwarf2_locexpr_index
));
21366 SYMBOL_LOCATION_BATON (sym
) = baton
;
21372 const comp_unit_head
*
21373 dwarf2_per_cu_data::get_header () const
21375 if (!m_header_read_in
)
21377 const gdb_byte
*info_ptr
21378 = this->section
->buffer
+ to_underlying (this->sect_off
);
21380 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
21381 rcuh_kind::COMPILE
);
21383 m_header_read_in
= true;
21392 dwarf2_per_cu_data::addr_size () const
21394 return this->get_header ()->addr_size
;
21400 dwarf2_per_cu_data::offset_size () const
21402 return this->get_header ()->offset_size
;
21408 dwarf2_per_cu_data::ref_addr_size () const
21410 const comp_unit_head
*header
= this->get_header ();
21412 if (header
->version
== 2)
21413 return header
->addr_size
;
21415 return header
->offset_size
;
21418 /* A helper function for dwarf2_find_containing_comp_unit that returns
21419 the index of the result, and that searches a vector. It will
21420 return a result even if the offset in question does not actually
21421 occur in any CU. This is separate so that it can be unit
21425 dwarf2_find_containing_comp_unit
21426 (sect_offset sect_off
,
21427 unsigned int offset_in_dwz
,
21428 const std::vector
<dwarf2_per_cu_data_up
> &all_units
)
21433 high
= all_units
.size () - 1;
21436 struct dwarf2_per_cu_data
*mid_cu
;
21437 int mid
= low
+ (high
- low
) / 2;
21439 mid_cu
= all_units
[mid
].get ();
21440 if (mid_cu
->is_dwz
> offset_in_dwz
21441 || (mid_cu
->is_dwz
== offset_in_dwz
21442 && mid_cu
->sect_off
+ mid_cu
->length () > sect_off
))
21447 gdb_assert (low
== high
);
21451 /* Locate the .debug_info compilation unit from CU's objfile which contains
21452 the DIE at OFFSET. Raises an error on failure. */
21454 static struct dwarf2_per_cu_data
*
21455 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
21456 unsigned int offset_in_dwz
,
21457 dwarf2_per_bfd
*per_bfd
)
21459 int low
= dwarf2_find_containing_comp_unit
21460 (sect_off
, offset_in_dwz
, per_bfd
->all_units
);
21461 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_units
[low
].get ();
21463 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
21465 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
21466 error (_("Dwarf Error: could not find partial DIE containing "
21467 "offset %s [in module %s]"),
21468 sect_offset_str (sect_off
),
21469 bfd_get_filename (per_bfd
->obfd
));
21471 gdb_assert (per_bfd
->all_units
[low
-1]->sect_off
21473 return per_bfd
->all_units
[low
- 1].get ();
21477 if (low
== per_bfd
->all_units
.size () - 1
21478 && sect_off
>= this_cu
->sect_off
+ this_cu
->length ())
21479 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
21480 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length ());
21487 namespace selftests
{
21488 namespace find_containing_comp_unit
{
21493 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
21494 dwarf2_per_cu_data
*one_ptr
= one
.get ();
21495 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
21496 dwarf2_per_cu_data
*two_ptr
= two
.get ();
21497 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
21498 dwarf2_per_cu_data
*three_ptr
= three
.get ();
21499 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
21500 dwarf2_per_cu_data
*four_ptr
= four
.get ();
21502 one
->set_length (5);
21503 two
->sect_off
= sect_offset (one
->length ());
21504 two
->set_length (7);
21506 three
->set_length (5);
21508 four
->sect_off
= sect_offset (three
->length ());
21509 four
->set_length (7);
21512 std::vector
<dwarf2_per_cu_data_up
> units
;
21513 units
.push_back (std::move (one
));
21514 units
.push_back (std::move (two
));
21515 units
.push_back (std::move (three
));
21516 units
.push_back (std::move (four
));
21520 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
21521 SELF_CHECK (units
[result
].get () == one_ptr
);
21522 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
21523 SELF_CHECK (units
[result
].get () == one_ptr
);
21524 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
21525 SELF_CHECK (units
[result
].get () == two_ptr
);
21527 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
21528 SELF_CHECK (units
[result
].get () == three_ptr
);
21529 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
21530 SELF_CHECK (units
[result
].get () == three_ptr
);
21531 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
21532 SELF_CHECK (units
[result
].get () == four_ptr
);
21538 #endif /* GDB_SELF_TEST */
21540 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
21543 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
21544 enum language pretend_language
)
21546 struct attribute
*attr
;
21548 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
21550 /* Set the language we're debugging. */
21551 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
21552 enum language lang
;
21553 if (cu
->producer
!= nullptr
21554 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
21556 /* The XLCL doesn't generate DW_LANG_OpenCL because this
21557 attribute is not standardised yet. As a workaround for the
21558 language detection we fall back to the DW_AT_producer
21560 lang
= language_opencl
;
21562 else if (cu
->producer
!= nullptr
21563 && strstr (cu
->producer
, "GNU Go ") != NULL
)
21565 /* Similar hack for Go. */
21566 lang
= language_go
;
21568 else if (attr
!= nullptr)
21569 lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
21571 lang
= pretend_language
;
21573 cu
->language_defn
= language_def (lang
);
21575 switch (comp_unit_die
->tag
)
21577 case DW_TAG_compile_unit
:
21578 cu
->per_cu
->set_unit_type (DW_UT_compile
);
21580 case DW_TAG_partial_unit
:
21581 cu
->per_cu
->set_unit_type (DW_UT_partial
);
21583 case DW_TAG_type_unit
:
21584 cu
->per_cu
->set_unit_type (DW_UT_type
);
21587 error (_("Dwarf Error: unexpected tag '%s' at offset %s"),
21588 dwarf_tag_name (comp_unit_die
->tag
),
21589 sect_offset_str (cu
->per_cu
->sect_off
));
21592 cu
->per_cu
->set_lang (lang
);
21598 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
21600 auto it
= m_dwarf2_cus
.find (per_cu
);
21601 if (it
== m_dwarf2_cus
.end ())
21604 return it
->second
.get ();
21610 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
,
21611 std::unique_ptr
<dwarf2_cu
> cu
)
21613 gdb_assert (this->get_cu (per_cu
) == nullptr);
21615 m_dwarf2_cus
[per_cu
] = std::move (cu
);
21621 dwarf2_per_objfile::age_comp_units ()
21623 dwarf_read_debug_printf_v ("running");
21625 /* This is not expected to be called in the middle of CU expansion. There is
21626 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
21627 loaded in memory. Calling age_comp_units while the queue is in use could
21628 make us free the DIEs for a CU that is in the queue and therefore break
21630 gdb_assert (!queue
.has_value ());
21632 /* Start by clearing all marks. */
21633 for (const auto &pair
: m_dwarf2_cus
)
21634 pair
.second
->clear_mark ();
21636 /* Traverse all CUs, mark them and their dependencies if used recently
21638 for (const auto &pair
: m_dwarf2_cus
)
21640 dwarf2_cu
*cu
= pair
.second
.get ();
21643 if (cu
->last_used
<= dwarf_max_cache_age
)
21647 /* Delete all CUs still not marked. */
21648 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
21650 dwarf2_cu
*cu
= it
->second
.get ();
21652 if (!cu
->is_marked ())
21654 dwarf_read_debug_printf_v ("deleting old CU %s",
21655 sect_offset_str (cu
->per_cu
->sect_off
));
21656 it
= m_dwarf2_cus
.erase (it
);
21666 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
21668 auto it
= m_dwarf2_cus
.find (per_cu
);
21669 if (it
== m_dwarf2_cus
.end ())
21672 m_dwarf2_cus
.erase (it
);
21675 dwarf2_per_objfile::~dwarf2_per_objfile ()
21680 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
21681 We store these in a hash table separate from the DIEs, and preserve them
21682 when the DIEs are flushed out of cache.
21684 The CU "per_cu" pointer is needed because offset alone is not enough to
21685 uniquely identify the type. A file may have multiple .debug_types sections,
21686 or the type may come from a DWO file. Furthermore, while it's more logical
21687 to use per_cu->section+offset, with Fission the section with the data is in
21688 the DWO file but we don't know that section at the point we need it.
21689 We have to use something in dwarf2_per_cu_data (or the pointer to it)
21690 because we can enter the lookup routine, get_die_type_at_offset, from
21691 outside this file, and thus won't necessarily have PER_CU->cu.
21692 Fortunately, PER_CU is stable for the life of the objfile. */
21694 struct dwarf2_per_cu_offset_and_type
21696 const struct dwarf2_per_cu_data
*per_cu
;
21697 sect_offset sect_off
;
21701 /* Hash function for a dwarf2_per_cu_offset_and_type. */
21704 per_cu_offset_and_type_hash (const void *item
)
21706 const struct dwarf2_per_cu_offset_and_type
*ofs
21707 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
21709 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
21712 /* Equality function for a dwarf2_per_cu_offset_and_type. */
21715 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
21717 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
21718 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
21719 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
21720 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
21722 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
21723 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
21726 /* Set the type associated with DIE to TYPE. Save it in CU's hash
21727 table if necessary. For convenience, return TYPE.
21729 The DIEs reading must have careful ordering to:
21730 * Not cause infinite loops trying to read in DIEs as a prerequisite for
21731 reading current DIE.
21732 * Not trying to dereference contents of still incompletely read in types
21733 while reading in other DIEs.
21734 * Enable referencing still incompletely read in types just by a pointer to
21735 the type without accessing its fields.
21737 Therefore caller should follow these rules:
21738 * Try to fetch any prerequisite types we may need to build this DIE type
21739 before building the type and calling set_die_type.
21740 * After building type call set_die_type for current DIE as soon as
21741 possible before fetching more types to complete the current type.
21742 * Make the type as complete as possible before fetching more types. */
21744 static struct type
*
21745 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21746 bool skip_data_location
)
21748 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21749 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
21750 struct objfile
*objfile
= per_objfile
->objfile
;
21751 struct attribute
*attr
;
21752 struct dynamic_prop prop
;
21754 /* For Ada types, make sure that the gnat-specific data is always
21755 initialized (if not already set). There are a few types where
21756 we should not be doing so, because the type-specific area is
21757 already used to hold some other piece of info (eg: TYPE_CODE_FLT
21758 where the type-specific area is used to store the floatformat).
21759 But this is not a problem, because the gnat-specific information
21760 is actually not needed for these types. */
21761 if (need_gnat_info (cu
)
21762 && type
->code () != TYPE_CODE_FUNC
21763 && type
->code () != TYPE_CODE_FLT
21764 && type
->code () != TYPE_CODE_METHODPTR
21765 && type
->code () != TYPE_CODE_MEMBERPTR
21766 && type
->code () != TYPE_CODE_METHOD
21767 && type
->code () != TYPE_CODE_FIXED_POINT
21768 && !HAVE_GNAT_AUX_INFO (type
))
21769 INIT_GNAT_SPECIFIC (type
);
21771 /* Read DW_AT_allocated and set in type. */
21772 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
21775 struct type
*prop_type
= cu
->addr_sized_int_type (false);
21776 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
21777 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
21780 /* Read DW_AT_associated and set in type. */
21781 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
21784 struct type
*prop_type
= cu
->addr_sized_int_type (false);
21785 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
21786 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
21789 /* Read DW_AT_rank and set in type. */
21790 attr
= dwarf2_attr (die
, DW_AT_rank
, cu
);
21793 struct type
*prop_type
= cu
->addr_sized_int_type (false);
21794 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
21795 type
->add_dyn_prop (DYN_PROP_RANK
, prop
);
21798 /* Read DW_AT_data_location and set in type. */
21799 if (!skip_data_location
)
21801 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
21802 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
21803 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
21806 if (per_objfile
->die_type_hash
== NULL
)
21807 per_objfile
->die_type_hash
21808 = htab_up (htab_create_alloc (127,
21809 per_cu_offset_and_type_hash
,
21810 per_cu_offset_and_type_eq
,
21811 NULL
, xcalloc
, xfree
));
21813 ofs
.per_cu
= cu
->per_cu
;
21814 ofs
.sect_off
= die
->sect_off
;
21816 slot
= (struct dwarf2_per_cu_offset_and_type
**)
21817 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
21819 complaint (_("A problem internal to GDB: DIE %s has type already set"),
21820 sect_offset_str (die
->sect_off
));
21821 *slot
= XOBNEW (&objfile
->objfile_obstack
,
21822 struct dwarf2_per_cu_offset_and_type
);
21827 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
21828 or return NULL if the die does not have a saved type. */
21830 static struct type
*
21831 get_die_type_at_offset (sect_offset sect_off
,
21832 dwarf2_per_cu_data
*per_cu
,
21833 dwarf2_per_objfile
*per_objfile
)
21835 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
21837 if (per_objfile
->die_type_hash
== NULL
)
21840 ofs
.per_cu
= per_cu
;
21841 ofs
.sect_off
= sect_off
;
21842 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
21843 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
21850 /* Look up the type for DIE in CU in die_type_hash,
21851 or return NULL if DIE does not have a saved type. */
21853 static struct type
*
21854 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21856 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
21859 struct cmd_list_element
*set_dwarf_cmdlist
;
21860 struct cmd_list_element
*show_dwarf_cmdlist
;
21863 show_check_physname (struct ui_file
*file
, int from_tty
,
21864 struct cmd_list_element
*c
, const char *value
)
21867 _("Whether to check \"physname\" is %s.\n"),
21871 void _initialize_dwarf2_read ();
21873 _initialize_dwarf2_read ()
21875 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
21877 Set DWARF specific variables.\n\
21878 Configure DWARF variables such as the cache size."),
21880 Show DWARF specific variables.\n\
21881 Show DWARF variables such as the cache size."),
21882 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
21883 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
21885 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
21886 &dwarf_max_cache_age
, _("\
21887 Set the upper bound on the age of cached DWARF compilation units."), _("\
21888 Show the upper bound on the age of cached DWARF compilation units."), _("\
21889 A higher limit means that cached compilation units will be stored\n\
21890 in memory longer, and more total memory will be used. Zero disables\n\
21891 caching, which can slow down startup."),
21893 show_dwarf_max_cache_age
,
21894 &set_dwarf_cmdlist
,
21895 &show_dwarf_cmdlist
);
21897 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
21898 Set debugging of the DWARF reader."), _("\
21899 Show debugging of the DWARF reader."), _("\
21900 When enabled (non-zero), debugging messages are printed during DWARF\n\
21901 reading and symtab expansion. A value of 1 (one) provides basic\n\
21902 information. A value greater than 1 provides more verbose information."),
21905 &setdebuglist
, &showdebuglist
);
21907 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
21908 Set debugging of the DWARF DIE reader."), _("\
21909 Show debugging of the DWARF DIE reader."), _("\
21910 When enabled (non-zero), DIEs are dumped after they are read in.\n\
21911 The value is the maximum depth to print."),
21914 &setdebuglist
, &showdebuglist
);
21916 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
21917 Set debugging of the dwarf line reader."), _("\
21918 Show debugging of the dwarf line reader."), _("\
21919 When enabled (non-zero), line number entries are dumped as they are read in.\n\
21920 A value of 1 (one) provides basic information.\n\
21921 A value greater than 1 provides more verbose information."),
21924 &setdebuglist
, &showdebuglist
);
21926 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
21927 Set cross-checking of \"physname\" code against demangler."), _("\
21928 Show cross-checking of \"physname\" code against demangler."), _("\
21929 When enabled, GDB's internal \"physname\" code is checked against\n\
21931 NULL
, show_check_physname
,
21932 &setdebuglist
, &showdebuglist
);
21934 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
21935 &dwarf2_locexpr_funcs
);
21936 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
21937 &dwarf2_loclist_funcs
);
21939 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
21940 &dwarf2_block_frame_base_locexpr_funcs
);
21941 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
21942 &dwarf2_block_frame_base_loclist_funcs
);
21945 selftests::register_test ("dw2_expand_symtabs_matching",
21946 selftests::dw2_expand_symtabs_matching::run_test
);
21947 selftests::register_test ("dwarf2_find_containing_comp_unit",
21948 selftests::find_containing_comp_unit::run_test
);