1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit-head.h"
36 #include "dwarf2/cu.h"
37 #include "dwarf2/index-cache.h"
38 #include "dwarf2/index-common.h"
39 #include "dwarf2/leb.h"
40 #include "dwarf2/line-header.h"
41 #include "dwarf2/dwz.h"
42 #include "dwarf2/macro.h"
43 #include "dwarf2/die.h"
44 #include "dwarf2/sect-names.h"
45 #include "dwarf2/stringify.h"
46 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
91 #include <unordered_set>
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
100 #define dwarf_read_debug_printf(fmt, ...) \
101 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
106 #define dwarf_read_debug_printf_v(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
110 /* When non-zero, dump DIEs after they are read in. */
111 static unsigned int dwarf_die_debug
= 0;
113 /* When non-zero, dump line number entries as they are read in. */
114 unsigned int dwarf_line_debug
= 0;
116 /* When true, cross-check physname against demangler. */
117 static bool check_physname
= false;
119 /* When true, do not reject deprecated .gdb_index sections. */
120 static bool use_deprecated_index_sections
= false;
122 /* This is used to store the data that is always per objfile. */
123 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
125 /* These are used to store the dwarf2_per_bfd objects.
127 objfiles having the same BFD, which doesn't require relocations, are going to
128 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
130 Other objfiles are not going to share a dwarf2_per_bfd with any other
131 objfiles, so they'll have their own version kept in the _objfile_data_key
133 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
134 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
136 /* The "aclass" indices for various kinds of computed DWARF symbols. */
138 static int dwarf2_locexpr_index
;
139 static int dwarf2_loclist_index
;
140 static int dwarf2_locexpr_block_index
;
141 static int dwarf2_loclist_block_index
;
143 /* Size of .debug_loclists section header for 32-bit DWARF format. */
144 #define LOCLIST_HEADER_SIZE32 12
146 /* Size of .debug_loclists section header for 64-bit DWARF format. */
147 #define LOCLIST_HEADER_SIZE64 20
149 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
150 #define RNGLIST_HEADER_SIZE32 12
152 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
153 #define RNGLIST_HEADER_SIZE64 20
155 /* An index into a (C++) symbol name component in a symbol name as
156 recorded in the mapped_index's symbol table. For each C++ symbol
157 in the symbol table, we record one entry for the start of each
158 component in the symbol in a table of name components, and then
159 sort the table, in order to be able to binary search symbol names,
160 ignoring leading namespaces, both completion and regular look up.
161 For example, for symbol "A::B::C", we'll have an entry that points
162 to "A::B::C", another that points to "B::C", and another for "C".
163 Note that function symbols in GDB index have no parameter
164 information, just the function/method names. You can convert a
165 name_component to a "const char *" using the
166 'mapped_index::symbol_name_at(offset_type)' method. */
168 struct name_component
170 /* Offset in the symbol name where the component starts. Stored as
171 a (32-bit) offset instead of a pointer to save memory and improve
172 locality on 64-bit architectures. */
173 offset_type name_offset
;
175 /* The symbol's index in the symbol and constant pool tables of a
180 /* Base class containing bits shared by both .gdb_index and
181 .debug_name indexes. */
183 struct mapped_index_base
185 mapped_index_base () = default;
186 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
188 /* The name_component table (a sorted vector). See name_component's
189 description above. */
190 std::vector
<name_component
> name_components
;
192 /* How NAME_COMPONENTS is sorted. */
193 enum case_sensitivity name_components_casing
;
195 /* Return the number of names in the symbol table. */
196 virtual size_t symbol_name_count () const = 0;
198 /* Get the name of the symbol at IDX in the symbol table. */
199 virtual const char *symbol_name_at
200 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
202 /* Return whether the name at IDX in the symbol table should be
204 virtual bool symbol_name_slot_invalid (offset_type idx
) const
209 /* Build the symbol name component sorted vector, if we haven't
211 void build_name_components (dwarf2_per_objfile
*per_objfile
);
213 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
214 possible matches for LN_NO_PARAMS in the name component
216 std::pair
<std::vector
<name_component
>::const_iterator
,
217 std::vector
<name_component
>::const_iterator
>
218 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
220 dwarf2_per_objfile
*per_objfile
) const;
222 /* Prevent deleting/destroying via a base class pointer. */
224 ~mapped_index_base() = default;
227 /* This is a view into the index that converts from bytes to an
228 offset_type, and allows indexing. Unaligned bytes are specifically
229 allowed here, and handled via unpacking. */
234 offset_view () = default;
236 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
241 /* Extract the INDEXth offset_type from the array. */
242 offset_type
operator[] (size_t index
) const
244 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
245 return (offset_type
) extract_unsigned_integer (bytes
,
246 sizeof (offset_type
),
250 /* Return the number of offset_types in this array. */
253 return m_bytes
.size () / sizeof (offset_type
);
256 /* Return true if this view is empty. */
259 return m_bytes
.empty ();
263 /* The underlying bytes. */
264 gdb::array_view
<const gdb_byte
> m_bytes
;
267 /* A description of the mapped index. The file format is described in
268 a comment by the code that writes the index. */
269 struct mapped_index final
: public mapped_index_base
271 /* Index data format version. */
274 /* The address table data. */
275 gdb::array_view
<const gdb_byte
> address_table
;
277 /* The symbol table, implemented as a hash table. */
278 offset_view symbol_table
;
280 /* A pointer to the constant pool. */
281 gdb::array_view
<const gdb_byte
> constant_pool
;
283 /* Return the index into the constant pool of the name of the IDXth
284 symbol in the symbol table. */
285 offset_type
symbol_name_index (offset_type idx
) const
287 return symbol_table
[2 * idx
];
290 /* Return the index into the constant pool of the CU vector of the
291 IDXth symbol in the symbol table. */
292 offset_type
symbol_vec_index (offset_type idx
) const
294 return symbol_table
[2 * idx
+ 1];
297 bool symbol_name_slot_invalid (offset_type idx
) const override
299 return (symbol_name_index (idx
) == 0
300 && symbol_vec_index (idx
) == 0);
303 /* Convenience method to get at the name of the symbol at IDX in the
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 return (const char *) (this->constant_pool
.data ()
309 + symbol_name_index (idx
));
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size () / 2; }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 bfd_endian dwarf5_byte_order
;
321 bool dwarf5_is_dwarf64
;
322 bool augmentation_is_gdb
;
324 uint32_t cu_count
= 0;
325 uint32_t tu_count
, bucket_count
, name_count
;
326 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
327 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
328 const gdb_byte
*name_table_string_offs_reordered
;
329 const gdb_byte
*name_table_entry_offs_reordered
;
330 const gdb_byte
*entry_pool
;
337 /* Attribute name DW_IDX_*. */
340 /* Attribute form DW_FORM_*. */
343 /* Value if FORM is DW_FORM_implicit_const. */
344 LONGEST implicit_const
;
346 std::vector
<attr
> attr_vec
;
349 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
351 const char *namei_to_name
352 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
354 /* Implementation of the mapped_index_base virtual interface, for
355 the name_components cache. */
357 const char *symbol_name_at
358 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
359 { return namei_to_name (idx
, per_objfile
); }
361 size_t symbol_name_count () const override
362 { return this->name_count
; }
365 /* See dwarf2read.h. */
368 get_dwarf2_per_objfile (struct objfile
*objfile
)
370 return dwarf2_objfile_data_key
.get (objfile
);
373 /* Default names of the debugging sections. */
375 /* Note that if the debugging section has been compressed, it might
376 have a name like .zdebug_info. */
378 const struct dwarf2_debug_sections dwarf2_elf_names
=
380 { ".debug_info", ".zdebug_info" },
381 { ".debug_abbrev", ".zdebug_abbrev" },
382 { ".debug_line", ".zdebug_line" },
383 { ".debug_loc", ".zdebug_loc" },
384 { ".debug_loclists", ".zdebug_loclists" },
385 { ".debug_macinfo", ".zdebug_macinfo" },
386 { ".debug_macro", ".zdebug_macro" },
387 { ".debug_str", ".zdebug_str" },
388 { ".debug_str_offsets", ".zdebug_str_offsets" },
389 { ".debug_line_str", ".zdebug_line_str" },
390 { ".debug_ranges", ".zdebug_ranges" },
391 { ".debug_rnglists", ".zdebug_rnglists" },
392 { ".debug_types", ".zdebug_types" },
393 { ".debug_addr", ".zdebug_addr" },
394 { ".debug_frame", ".zdebug_frame" },
395 { ".eh_frame", NULL
},
396 { ".gdb_index", ".zgdb_index" },
397 { ".debug_names", ".zdebug_names" },
398 { ".debug_aranges", ".zdebug_aranges" },
402 /* List of DWO/DWP sections. */
404 static const struct dwop_section_names
406 struct dwarf2_section_names abbrev_dwo
;
407 struct dwarf2_section_names info_dwo
;
408 struct dwarf2_section_names line_dwo
;
409 struct dwarf2_section_names loc_dwo
;
410 struct dwarf2_section_names loclists_dwo
;
411 struct dwarf2_section_names macinfo_dwo
;
412 struct dwarf2_section_names macro_dwo
;
413 struct dwarf2_section_names rnglists_dwo
;
414 struct dwarf2_section_names str_dwo
;
415 struct dwarf2_section_names str_offsets_dwo
;
416 struct dwarf2_section_names types_dwo
;
417 struct dwarf2_section_names cu_index
;
418 struct dwarf2_section_names tu_index
;
422 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
423 { ".debug_info.dwo", ".zdebug_info.dwo" },
424 { ".debug_line.dwo", ".zdebug_line.dwo" },
425 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
426 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
427 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
428 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
429 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
430 { ".debug_str.dwo", ".zdebug_str.dwo" },
431 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
432 { ".debug_types.dwo", ".zdebug_types.dwo" },
433 { ".debug_cu_index", ".zdebug_cu_index" },
434 { ".debug_tu_index", ".zdebug_tu_index" },
437 /* local data types */
439 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
440 begin with a header, which contains the following information. */
441 struct loclists_rnglists_header
443 /* A 4-byte or 12-byte length containing the length of the
444 set of entries for this compilation unit, not including the
445 length field itself. */
448 /* A 2-byte version identifier. */
451 /* A 1-byte unsigned integer containing the size in bytes of an address on
452 the target system. */
453 unsigned char addr_size
;
455 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
456 on the target system. */
457 unsigned char segment_collector_size
;
459 /* A 4-byte count of the number of offsets that follow the header. */
460 unsigned int offset_entry_count
;
463 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
464 This includes type_unit_group and quick_file_names. */
466 struct stmt_list_hash
468 /* The DWO unit this table is from or NULL if there is none. */
469 struct dwo_unit
*dwo_unit
;
471 /* Offset in .debug_line or .debug_line.dwo. */
472 sect_offset line_sect_off
;
475 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
476 an object of this type. This contains elements of type unit groups
477 that can be shared across objfiles. The non-shareable parts are in
478 type_unit_group_unshareable. */
480 struct type_unit_group
: public dwarf2_per_cu_data
482 /* The TUs that share this DW_AT_stmt_list entry.
483 This is added to while parsing type units to build partial symtabs,
484 and is deleted afterwards and not used again. */
485 std::vector
<signatured_type
*> *tus
= nullptr;
487 /* The data used to construct the hash key. */
488 struct stmt_list_hash hash
{};
491 /* These sections are what may appear in a (real or virtual) DWO file. */
495 struct dwarf2_section_info abbrev
;
496 struct dwarf2_section_info line
;
497 struct dwarf2_section_info loc
;
498 struct dwarf2_section_info loclists
;
499 struct dwarf2_section_info macinfo
;
500 struct dwarf2_section_info macro
;
501 struct dwarf2_section_info rnglists
;
502 struct dwarf2_section_info str
;
503 struct dwarf2_section_info str_offsets
;
504 /* In the case of a virtual DWO file, these two are unused. */
505 struct dwarf2_section_info info
;
506 std::vector
<dwarf2_section_info
> types
;
509 /* CUs/TUs in DWP/DWO files. */
513 /* Backlink to the containing struct dwo_file. */
514 struct dwo_file
*dwo_file
;
516 /* The "id" that distinguishes this CU/TU.
517 .debug_info calls this "dwo_id", .debug_types calls this "signature".
518 Since signatures came first, we stick with it for consistency. */
521 /* The section this CU/TU lives in, in the DWO file. */
522 struct dwarf2_section_info
*section
;
524 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
525 sect_offset sect_off
;
528 /* For types, offset in the type's DIE of the type defined by this TU. */
529 cu_offset type_offset_in_tu
;
532 /* include/dwarf2.h defines the DWP section codes.
533 It defines a max value but it doesn't define a min value, which we
534 use for error checking, so provide one. */
536 enum dwp_v2_section_ids
541 /* Data for one DWO file.
543 This includes virtual DWO files (a virtual DWO file is a DWO file as it
544 appears in a DWP file). DWP files don't really have DWO files per se -
545 comdat folding of types "loses" the DWO file they came from, and from
546 a high level view DWP files appear to contain a mass of random types.
547 However, to maintain consistency with the non-DWP case we pretend DWP
548 files contain virtual DWO files, and we assign each TU with one virtual
549 DWO file (generally based on the line and abbrev section offsets -
550 a heuristic that seems to work in practice). */
554 dwo_file () = default;
555 DISABLE_COPY_AND_ASSIGN (dwo_file
);
557 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
558 For virtual DWO files the name is constructed from the section offsets
559 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
560 from related CU+TUs. */
561 const char *dwo_name
= nullptr;
563 /* The DW_AT_comp_dir attribute. */
564 const char *comp_dir
= nullptr;
566 /* The bfd, when the file is open. Otherwise this is NULL.
567 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
568 gdb_bfd_ref_ptr dbfd
;
570 /* The sections that make up this DWO file.
571 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
572 sections (for lack of a better name). */
573 struct dwo_sections sections
{};
575 /* The CUs in the file.
576 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
577 an extension to handle LLVM's Link Time Optimization output (where
578 multiple source files may be compiled into a single object/dwo pair). */
581 /* Table of TUs in the file.
582 Each element is a struct dwo_unit. */
586 /* These sections are what may appear in a DWP file. */
590 /* These are used by all DWP versions (1, 2 and 5). */
591 struct dwarf2_section_info str
;
592 struct dwarf2_section_info cu_index
;
593 struct dwarf2_section_info tu_index
;
595 /* These are only used by DWP version 2 and version 5 files.
596 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
597 sections are referenced by section number, and are not recorded here.
598 In DWP version 2 or 5 there is at most one copy of all these sections,
599 each section being (effectively) comprised of the concatenation of all of
600 the individual sections that exist in the version 1 format.
601 To keep the code simple we treat each of these concatenated pieces as a
602 section itself (a virtual section?). */
603 struct dwarf2_section_info abbrev
;
604 struct dwarf2_section_info info
;
605 struct dwarf2_section_info line
;
606 struct dwarf2_section_info loc
;
607 struct dwarf2_section_info loclists
;
608 struct dwarf2_section_info macinfo
;
609 struct dwarf2_section_info macro
;
610 struct dwarf2_section_info rnglists
;
611 struct dwarf2_section_info str_offsets
;
612 struct dwarf2_section_info types
;
615 /* These sections are what may appear in a virtual DWO file in DWP version 1.
616 A virtual DWO file is a DWO file as it appears in a DWP file. */
618 struct virtual_v1_dwo_sections
620 struct dwarf2_section_info abbrev
;
621 struct dwarf2_section_info line
;
622 struct dwarf2_section_info loc
;
623 struct dwarf2_section_info macinfo
;
624 struct dwarf2_section_info macro
;
625 struct dwarf2_section_info str_offsets
;
626 /* Each DWP hash table entry records one CU or one TU.
627 That is recorded here, and copied to dwo_unit.section. */
628 struct dwarf2_section_info info_or_types
;
631 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
632 In version 2, the sections of the DWO files are concatenated together
633 and stored in one section of that name. Thus each ELF section contains
634 several "virtual" sections. */
636 struct virtual_v2_or_v5_dwo_sections
638 bfd_size_type abbrev_offset
;
639 bfd_size_type abbrev_size
;
641 bfd_size_type line_offset
;
642 bfd_size_type line_size
;
644 bfd_size_type loc_offset
;
645 bfd_size_type loc_size
;
647 bfd_size_type loclists_offset
;
648 bfd_size_type loclists_size
;
650 bfd_size_type macinfo_offset
;
651 bfd_size_type macinfo_size
;
653 bfd_size_type macro_offset
;
654 bfd_size_type macro_size
;
656 bfd_size_type rnglists_offset
;
657 bfd_size_type rnglists_size
;
659 bfd_size_type str_offsets_offset
;
660 bfd_size_type str_offsets_size
;
662 /* Each DWP hash table entry records one CU or one TU.
663 That is recorded here, and copied to dwo_unit.section. */
664 bfd_size_type info_or_types_offset
;
665 bfd_size_type info_or_types_size
;
668 /* Contents of DWP hash tables. */
670 struct dwp_hash_table
672 uint32_t version
, nr_columns
;
673 uint32_t nr_units
, nr_slots
;
674 const gdb_byte
*hash_table
, *unit_table
;
679 const gdb_byte
*indices
;
683 /* This is indexed by column number and gives the id of the section
685 #define MAX_NR_V2_DWO_SECTIONS \
686 (1 /* .debug_info or .debug_types */ \
687 + 1 /* .debug_abbrev */ \
688 + 1 /* .debug_line */ \
689 + 1 /* .debug_loc */ \
690 + 1 /* .debug_str_offsets */ \
691 + 1 /* .debug_macro or .debug_macinfo */)
692 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
693 const gdb_byte
*offsets
;
694 const gdb_byte
*sizes
;
698 /* This is indexed by column number and gives the id of the section
700 #define MAX_NR_V5_DWO_SECTIONS \
701 (1 /* .debug_info */ \
702 + 1 /* .debug_abbrev */ \
703 + 1 /* .debug_line */ \
704 + 1 /* .debug_loclists */ \
705 + 1 /* .debug_str_offsets */ \
706 + 1 /* .debug_macro */ \
707 + 1 /* .debug_rnglists */)
708 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
709 const gdb_byte
*offsets
;
710 const gdb_byte
*sizes
;
715 /* Data for one DWP file. */
719 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
721 dbfd (std::move (abfd
))
725 /* Name of the file. */
728 /* File format version. */
732 gdb_bfd_ref_ptr dbfd
;
734 /* Section info for this file. */
735 struct dwp_sections sections
{};
737 /* Table of CUs in the file. */
738 const struct dwp_hash_table
*cus
= nullptr;
740 /* Table of TUs in the file. */
741 const struct dwp_hash_table
*tus
= nullptr;
743 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
747 /* Table to map ELF section numbers to their sections.
748 This is only needed for the DWP V1 file format. */
749 unsigned int num_sections
= 0;
750 asection
**elf_sections
= nullptr;
753 /* Struct used to pass misc. parameters to read_die_and_children, et
754 al. which are used for both .debug_info and .debug_types dies.
755 All parameters here are unchanging for the life of the call. This
756 struct exists to abstract away the constant parameters of die reading. */
758 struct die_reader_specs
760 /* The bfd of die_section. */
763 /* The CU of the DIE we are parsing. */
764 struct dwarf2_cu
*cu
;
766 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
767 struct dwo_file
*dwo_file
;
769 /* The section the die comes from.
770 This is either .debug_info or .debug_types, or the .dwo variants. */
771 struct dwarf2_section_info
*die_section
;
773 /* die_section->buffer. */
774 const gdb_byte
*buffer
;
776 /* The end of the buffer. */
777 const gdb_byte
*buffer_end
;
779 /* The abbreviation table to use when reading the DIEs. */
780 struct abbrev_table
*abbrev_table
;
783 /* A subclass of die_reader_specs that holds storage and has complex
784 constructor and destructor behavior. */
786 class cutu_reader
: public die_reader_specs
790 cutu_reader (dwarf2_per_cu_data
*this_cu
,
791 dwarf2_per_objfile
*per_objfile
,
792 struct abbrev_table
*abbrev_table
,
793 dwarf2_cu
*existing_cu
,
796 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
797 dwarf2_per_objfile
*per_objfile
,
798 struct dwarf2_cu
*parent_cu
= nullptr,
799 struct dwo_file
*dwo_file
= nullptr);
801 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
803 const gdb_byte
*info_ptr
= nullptr;
804 struct die_info
*comp_unit_die
= nullptr;
805 bool dummy_p
= false;
807 /* Release the new CU, putting it on the chain. This cannot be done
812 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
813 dwarf2_per_objfile
*per_objfile
,
814 dwarf2_cu
*existing_cu
);
816 struct dwarf2_per_cu_data
*m_this_cu
;
817 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
819 /* The ordinary abbreviation table. */
820 abbrev_table_up m_abbrev_table_holder
;
822 /* The DWO abbreviation table. */
823 abbrev_table_up m_dwo_abbrev_table
;
826 /* When we construct a partial symbol table entry we only
827 need this much information. */
828 struct partial_die_info
: public allocate_on_obstack
830 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
832 /* Disable assign but still keep copy ctor, which is needed
833 load_partial_dies. */
834 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
836 /* Adjust the partial die before generating a symbol for it. This
837 function may set the is_external flag or change the DIE's
839 void fixup (struct dwarf2_cu
*cu
);
841 /* Read a minimal amount of information into the minimal die
843 const gdb_byte
*read (const struct die_reader_specs
*reader
,
844 const struct abbrev_info
&abbrev
,
845 const gdb_byte
*info_ptr
);
847 /* Compute the name of this partial DIE. This memoizes the
848 result, so it is safe to call multiple times. */
849 const char *name (dwarf2_cu
*cu
);
851 /* Offset of this DIE. */
852 const sect_offset sect_off
;
854 /* DWARF-2 tag for this DIE. */
855 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
857 /* Assorted flags describing the data found in this DIE. */
858 const unsigned int has_children
: 1;
860 unsigned int is_external
: 1;
861 unsigned int is_declaration
: 1;
862 unsigned int has_type
: 1;
863 unsigned int has_specification
: 1;
864 unsigned int has_pc_info
: 1;
865 unsigned int may_be_inlined
: 1;
867 /* This DIE has been marked DW_AT_main_subprogram. */
868 unsigned int main_subprogram
: 1;
870 /* Flag set if the SCOPE field of this structure has been
872 unsigned int scope_set
: 1;
874 /* Flag set if the DIE has a byte_size attribute. */
875 unsigned int has_byte_size
: 1;
877 /* Flag set if the DIE has a DW_AT_const_value attribute. */
878 unsigned int has_const_value
: 1;
880 /* Flag set if any of the DIE's children are template arguments. */
881 unsigned int has_template_arguments
: 1;
883 /* Flag set if fixup has been called on this die. */
884 unsigned int fixup_called
: 1;
886 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
887 unsigned int is_dwz
: 1;
889 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
890 unsigned int spec_is_dwz
: 1;
892 unsigned int canonical_name
: 1;
894 /* The name of this DIE. Normally the value of DW_AT_name, but
895 sometimes a default name for unnamed DIEs. */
896 const char *raw_name
= nullptr;
898 /* The linkage name, if present. */
899 const char *linkage_name
= nullptr;
901 /* The scope to prepend to our children. This is generally
902 allocated on the comp_unit_obstack, so will disappear
903 when this compilation unit leaves the cache. */
904 const char *scope
= nullptr;
906 /* Some data associated with the partial DIE. The tag determines
907 which field is live. */
910 /* The location description associated with this DIE, if any. */
911 struct dwarf_block
*locdesc
;
912 /* The offset of an import, for DW_TAG_imported_unit. */
913 sect_offset sect_off
;
916 /* If HAS_PC_INFO, the PC range associated with this DIE. */
918 CORE_ADDR highpc
= 0;
920 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
921 DW_AT_sibling, if any. */
922 /* NOTE: This member isn't strictly necessary, partial_die_info::read
923 could return DW_AT_sibling values to its caller load_partial_dies. */
924 const gdb_byte
*sibling
= nullptr;
926 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
927 DW_AT_specification (or DW_AT_abstract_origin or
929 sect_offset spec_offset
{};
931 /* Pointers to this DIE's parent, first child, and next sibling,
933 struct partial_die_info
*die_parent
= nullptr;
934 struct partial_die_info
*die_child
= nullptr;
935 struct partial_die_info
*die_sibling
= nullptr;
937 friend struct partial_die_info
*
938 dwarf2_cu::find_partial_die (sect_offset sect_off
);
941 /* Only need to do look up in dwarf2_cu::find_partial_die. */
942 partial_die_info (sect_offset sect_off
)
943 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
947 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
949 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
954 has_specification
= 0;
961 has_template_arguments
= 0;
969 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
970 but this would require a corresponding change in unpack_field_as_long
972 static int bits_per_byte
= 8;
974 struct variant_part_builder
;
976 /* When reading a variant, we track a bit more information about the
977 field, and store it in an object of this type. */
981 int first_field
= -1;
984 /* A variant can contain other variant parts. */
985 std::vector
<variant_part_builder
> variant_parts
;
987 /* If we see a DW_TAG_variant, then this will be set if this is the
989 bool default_branch
= false;
990 /* If we see a DW_AT_discr_value, then this will be the discriminant
992 ULONGEST discriminant_value
= 0;
993 /* If we see a DW_AT_discr_list, then this is a pointer to the list
995 struct dwarf_block
*discr_list_data
= nullptr;
998 /* This represents a DW_TAG_variant_part. */
1000 struct variant_part_builder
1002 /* The offset of the discriminant field. */
1003 sect_offset discriminant_offset
{};
1005 /* Variants that are direct children of this variant part. */
1006 std::vector
<variant_field
> variants
;
1008 /* True if we're currently reading a variant. */
1009 bool processing_variant
= false;
1014 int accessibility
= 0;
1016 /* Variant parts need to find the discriminant, which is a DIE
1017 reference. We track the section offset of each field to make
1020 struct field field
{};
1025 const char *name
= nullptr;
1026 std::vector
<struct fn_field
> fnfields
;
1029 /* The routines that read and process dies for a C struct or C++ class
1030 pass lists of data member fields and lists of member function fields
1031 in an instance of a field_info structure, as defined below. */
1034 /* List of data member and baseclasses fields. */
1035 std::vector
<struct nextfield
> fields
;
1036 std::vector
<struct nextfield
> baseclasses
;
1038 /* Set if the accessibility of one of the fields is not public. */
1039 bool non_public_fields
= false;
1041 /* Member function fieldlist array, contains name of possibly overloaded
1042 member function, number of overloaded member functions and a pointer
1043 to the head of the member function field chain. */
1044 std::vector
<struct fnfieldlist
> fnfieldlists
;
1046 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1047 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1048 std::vector
<struct decl_field
> typedef_field_list
;
1050 /* Nested types defined by this class and the number of elements in this
1052 std::vector
<struct decl_field
> nested_types_list
;
1054 /* If non-null, this is the variant part we are currently
1056 variant_part_builder
*current_variant_part
= nullptr;
1057 /* This holds all the top-level variant parts attached to the type
1059 std::vector
<variant_part_builder
> variant_parts
;
1061 /* Return the total number of fields (including baseclasses). */
1062 int nfields () const
1064 return fields
.size () + baseclasses
.size ();
1068 /* Loaded secondary compilation units are kept in memory until they
1069 have not been referenced for the processing of this many
1070 compilation units. Set this to zero to disable caching. Cache
1071 sizes of up to at least twenty will improve startup time for
1072 typical inter-CU-reference binaries, at an obvious memory cost. */
1073 static int dwarf_max_cache_age
= 5;
1075 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1076 struct cmd_list_element
*c
, const char *value
)
1078 fprintf_filtered (file
, _("The upper bound on the age of cached "
1079 "DWARF compilation units is %s.\n"),
1083 /* local function prototypes */
1085 static void dwarf2_find_base_address (struct die_info
*die
,
1086 struct dwarf2_cu
*cu
);
1088 static dwarf2_psymtab
*create_partial_symtab
1089 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1092 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1093 const gdb_byte
*info_ptr
,
1094 struct die_info
*type_unit_die
);
1096 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1098 static void scan_partial_symbols (struct partial_die_info
*,
1099 CORE_ADDR
*, CORE_ADDR
*,
1100 int, struct dwarf2_cu
*);
1102 static void add_partial_symbol (struct partial_die_info
*,
1103 struct dwarf2_cu
*);
1105 static void add_partial_namespace (struct partial_die_info
*pdi
,
1106 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1107 int set_addrmap
, struct dwarf2_cu
*cu
);
1109 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1110 CORE_ADDR
*highpc
, int set_addrmap
,
1111 struct dwarf2_cu
*cu
);
1113 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1114 struct dwarf2_cu
*cu
);
1116 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1117 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1118 int need_pc
, struct dwarf2_cu
*cu
);
1120 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1122 static struct partial_die_info
*load_partial_dies
1123 (const struct die_reader_specs
*, const gdb_byte
*, int);
1125 /* A pair of partial_die_info and compilation unit. */
1126 struct cu_partial_die_info
1128 /* The compilation unit of the partial_die_info. */
1129 struct dwarf2_cu
*cu
;
1130 /* A partial_die_info. */
1131 struct partial_die_info
*pdi
;
1133 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1139 cu_partial_die_info () = delete;
1142 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1143 struct dwarf2_cu
*);
1145 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1147 const struct attr_abbrev
*,
1150 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1151 struct attribute
*attr
, dwarf_tag tag
);
1153 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1155 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1156 dwarf2_section_info
*, sect_offset
);
1158 static const char *read_indirect_string
1159 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1160 const struct comp_unit_head
*, unsigned int *);
1162 static const char *read_indirect_string_at_offset
1163 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1165 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1169 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1170 ULONGEST str_index
);
1172 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1173 ULONGEST str_index
);
1175 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1177 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1178 struct dwarf2_cu
*);
1180 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1181 struct dwarf2_cu
*cu
);
1183 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1185 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1186 struct dwarf2_cu
*cu
);
1188 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1190 static struct die_info
*die_specification (struct die_info
*die
,
1191 struct dwarf2_cu
**);
1193 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1194 struct dwarf2_cu
*cu
);
1196 static void dwarf_decode_lines (struct line_header
*, const char *,
1197 struct dwarf2_cu
*, dwarf2_psymtab
*,
1198 CORE_ADDR
, int decode_mapping
);
1200 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1203 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1204 struct dwarf2_cu
*, struct symbol
* = NULL
);
1206 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1207 struct dwarf2_cu
*);
1209 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1212 struct obstack
*obstack
,
1213 struct dwarf2_cu
*cu
, LONGEST
*value
,
1214 const gdb_byte
**bytes
,
1215 struct dwarf2_locexpr_baton
**baton
);
1217 static struct type
*read_subrange_index_type (struct die_info
*die
,
1218 struct dwarf2_cu
*cu
);
1220 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1222 static int need_gnat_info (struct dwarf2_cu
*);
1224 static struct type
*die_descriptive_type (struct die_info
*,
1225 struct dwarf2_cu
*);
1227 static void set_descriptive_type (struct type
*, struct die_info
*,
1228 struct dwarf2_cu
*);
1230 static struct type
*die_containing_type (struct die_info
*,
1231 struct dwarf2_cu
*);
1233 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1234 struct dwarf2_cu
*);
1236 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1238 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1240 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1242 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1243 const char *suffix
, int physname
,
1244 struct dwarf2_cu
*cu
);
1246 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1248 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1250 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1252 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1254 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1256 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1258 /* Return the .debug_loclists section to use for cu. */
1259 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1261 /* Return the .debug_rnglists section to use for cu. */
1262 static struct dwarf2_section_info
*cu_debug_rnglists_section
1263 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1265 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1266 values. Keep the items ordered with increasing constraints compliance. */
1269 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1270 PC_BOUNDS_NOT_PRESENT
,
1272 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1273 were present but they do not form a valid range of PC addresses. */
1276 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1279 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1283 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1284 CORE_ADDR
*, CORE_ADDR
*,
1288 static void get_scope_pc_bounds (struct die_info
*,
1289 CORE_ADDR
*, CORE_ADDR
*,
1290 struct dwarf2_cu
*);
1292 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1293 CORE_ADDR
, struct dwarf2_cu
*);
1295 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1296 struct dwarf2_cu
*);
1298 static void dwarf2_attach_fields_to_type (struct field_info
*,
1299 struct type
*, struct dwarf2_cu
*);
1301 static void dwarf2_add_member_fn (struct field_info
*,
1302 struct die_info
*, struct type
*,
1303 struct dwarf2_cu
*);
1305 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1307 struct dwarf2_cu
*);
1309 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1311 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1313 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1315 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1317 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1319 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1321 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1323 static struct type
*read_module_type (struct die_info
*die
,
1324 struct dwarf2_cu
*cu
);
1326 static const char *namespace_name (struct die_info
*die
,
1327 int *is_anonymous
, struct dwarf2_cu
*);
1329 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1331 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1334 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1335 struct dwarf2_cu
*);
1337 static struct die_info
*read_die_and_siblings_1
1338 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1341 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1342 const gdb_byte
*info_ptr
,
1343 const gdb_byte
**new_info_ptr
,
1344 struct die_info
*parent
);
1346 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1347 struct die_info
**, const gdb_byte
*,
1350 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1351 struct die_info
**, const gdb_byte
*);
1353 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1355 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1358 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1360 static const char *dwarf2_full_name (const char *name
,
1361 struct die_info
*die
,
1362 struct dwarf2_cu
*cu
);
1364 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1365 struct dwarf2_cu
*cu
);
1367 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1368 struct dwarf2_cu
**);
1370 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1372 static void dump_die_for_error (struct die_info
*);
1374 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1377 /*static*/ void dump_die (struct die_info
*, int max_level
);
1379 static void store_in_ref_table (struct die_info
*,
1380 struct dwarf2_cu
*);
1382 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1383 const struct attribute
*,
1384 struct dwarf2_cu
**);
1386 static struct die_info
*follow_die_ref (struct die_info
*,
1387 const struct attribute
*,
1388 struct dwarf2_cu
**);
1390 static struct die_info
*follow_die_sig (struct die_info
*,
1391 const struct attribute
*,
1392 struct dwarf2_cu
**);
1394 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1395 struct dwarf2_cu
*);
1397 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1398 const struct attribute
*,
1399 struct dwarf2_cu
*);
1401 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1402 dwarf2_per_objfile
*per_objfile
);
1404 static void read_signatured_type (signatured_type
*sig_type
,
1405 dwarf2_per_objfile
*per_objfile
);
1407 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1408 struct die_info
*die
, struct dwarf2_cu
*cu
,
1409 struct dynamic_prop
*prop
, struct type
*type
);
1411 /* memory allocation interface */
1413 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1415 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1417 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1419 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1420 struct dwarf2_loclist_baton
*baton
,
1421 const struct attribute
*attr
);
1423 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1425 struct dwarf2_cu
*cu
,
1428 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1429 const gdb_byte
*info_ptr
,
1430 const struct abbrev_info
*abbrev
);
1432 static hashval_t
partial_die_hash (const void *item
);
1434 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1436 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1437 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1438 dwarf2_per_objfile
*per_objfile
);
1440 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1441 struct die_info
*comp_unit_die
,
1442 enum language pretend_language
);
1444 static struct type
*set_die_type (struct die_info
*, struct type
*,
1445 struct dwarf2_cu
*, bool = false);
1447 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1449 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1450 dwarf2_per_objfile
*per_objfile
,
1451 dwarf2_cu
*existing_cu
,
1453 enum language pretend_language
);
1455 static void process_full_comp_unit (dwarf2_cu
*cu
,
1456 enum language pretend_language
);
1458 static void process_full_type_unit (dwarf2_cu
*cu
,
1459 enum language pretend_language
);
1461 static struct type
*get_die_type_at_offset (sect_offset
,
1462 dwarf2_per_cu_data
*per_cu
,
1463 dwarf2_per_objfile
*per_objfile
);
1465 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1467 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1468 dwarf2_per_objfile
*per_objfile
,
1469 enum language pretend_language
);
1471 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1473 /* Class, the destructor of which frees all allocated queue entries. This
1474 will only have work to do if an error was thrown while processing the
1475 dwarf. If no error was thrown then the queue entries should have all
1476 been processed, and freed, as we went along. */
1478 class dwarf2_queue_guard
1481 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1482 : m_per_objfile (per_objfile
)
1484 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1486 m_per_objfile
->per_bfd
->queue
.emplace ();
1489 /* Free any entries remaining on the queue. There should only be
1490 entries left if we hit an error while processing the dwarf. */
1491 ~dwarf2_queue_guard ()
1493 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1495 m_per_objfile
->per_bfd
->queue
.reset ();
1498 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1501 dwarf2_per_objfile
*m_per_objfile
;
1504 dwarf2_queue_item::~dwarf2_queue_item ()
1506 /* Anything still marked queued is likely to be in an
1507 inconsistent state, so discard it. */
1510 per_objfile
->remove_cu (per_cu
);
1515 /* See dwarf2/read.h. */
1518 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1520 if (data
->is_debug_types
)
1521 delete static_cast<signatured_type
*> (data
);
1526 /* The return type of find_file_and_directory. Note, the enclosed
1527 string pointers are only valid while this object is valid. */
1529 struct file_and_directory
1531 /* The filename. This is never NULL. */
1534 /* The compilation directory. NULL if not known. If we needed to
1535 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1536 points directly to the DW_AT_comp_dir string attribute owned by
1537 the obstack that owns the DIE. */
1538 const char *comp_dir
;
1540 /* If we needed to build a new string for comp_dir, this is what
1541 owns the storage. */
1542 std::string comp_dir_storage
;
1545 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1546 struct dwarf2_cu
*cu
);
1548 static htab_up
allocate_signatured_type_table ();
1550 static htab_up
allocate_dwo_unit_table ();
1552 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1553 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1554 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1556 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1558 static struct dwo_unit
*lookup_dwo_comp_unit
1559 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1560 ULONGEST signature
);
1562 static struct dwo_unit
*lookup_dwo_type_unit
1563 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1565 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1567 /* A unique pointer to a dwo_file. */
1569 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1571 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1573 static void check_producer (struct dwarf2_cu
*cu
);
1575 /* Various complaints about symbol reading that don't abort the process. */
1578 dwarf2_debug_line_missing_file_complaint (void)
1580 complaint (_(".debug_line section has line data without a file"));
1584 dwarf2_debug_line_missing_end_sequence_complaint (void)
1586 complaint (_(".debug_line section has line "
1587 "program sequence without an end"));
1591 dwarf2_complex_location_expr_complaint (void)
1593 complaint (_("location expression too complex"));
1597 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1600 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1605 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1607 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1611 /* Hash function for line_header_hash. */
1614 line_header_hash (const struct line_header
*ofs
)
1616 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1619 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1622 line_header_hash_voidp (const void *item
)
1624 const struct line_header
*ofs
= (const struct line_header
*) item
;
1626 return line_header_hash (ofs
);
1629 /* Equality function for line_header_hash. */
1632 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1634 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1635 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1637 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1638 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1643 /* See declaration. */
1645 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1648 can_copy (can_copy_
)
1651 names
= &dwarf2_elf_names
;
1653 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1654 locate_sections (obfd
, sec
, *names
);
1657 dwarf2_per_bfd::~dwarf2_per_bfd ()
1659 for (auto &per_cu
: all_comp_units
)
1660 per_cu
->imported_symtabs_free ();
1662 /* Everything else should be on this->obstack. */
1668 dwarf2_per_objfile::remove_all_cus ()
1670 gdb_assert (!this->per_bfd
->queue
.has_value ());
1672 for (auto pair
: m_dwarf2_cus
)
1675 m_dwarf2_cus
.clear ();
1678 /* A helper class that calls free_cached_comp_units on
1681 class free_cached_comp_units
1685 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1686 : m_per_objfile (per_objfile
)
1690 ~free_cached_comp_units ()
1692 m_per_objfile
->remove_all_cus ();
1695 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1699 dwarf2_per_objfile
*m_per_objfile
;
1705 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1707 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1709 return this->m_symtabs
[per_cu
->index
] != nullptr;
1715 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1717 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1719 return this->m_symtabs
[per_cu
->index
];
1725 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1726 compunit_symtab
*symtab
)
1728 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1729 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1731 this->m_symtabs
[per_cu
->index
] = symtab
;
1734 /* Try to locate the sections we need for DWARF 2 debugging
1735 information and return true if we have enough to do something.
1736 NAMES points to the dwarf2 section names, or is NULL if the standard
1737 ELF names are used. CAN_COPY is true for formats where symbol
1738 interposition is possible and so symbol values must follow copy
1739 relocation rules. */
1742 dwarf2_has_info (struct objfile
*objfile
,
1743 const struct dwarf2_debug_sections
*names
,
1746 if (objfile
->flags
& OBJF_READNEVER
)
1749 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1751 if (per_objfile
== NULL
)
1753 dwarf2_per_bfd
*per_bfd
;
1755 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1756 BFD doesn't require relocations.
1758 We don't share with objfiles for which -readnow was requested,
1759 because it would complicate things when loading the same BFD with
1760 -readnow and then without -readnow. */
1761 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1762 && (objfile
->flags
& OBJF_READNOW
) == 0)
1764 /* See if one has been created for this BFD yet. */
1765 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1767 if (per_bfd
== nullptr)
1769 /* No, create it now. */
1770 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1771 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1776 /* No sharing possible, create one specifically for this objfile. */
1777 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1778 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1781 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1784 return (!per_objfile
->per_bfd
->info
.is_virtual
1785 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1786 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1787 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1790 /* See declaration. */
1793 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1794 const dwarf2_debug_sections
&names
)
1796 flagword aflag
= bfd_section_flags (sectp
);
1798 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1801 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1802 > bfd_get_file_size (abfd
))
1804 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1805 warning (_("Discarding section %s which has a section size (%s"
1806 ") larger than the file size [in module %s]"),
1807 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1808 bfd_get_filename (abfd
));
1810 else if (names
.info
.matches (sectp
->name
))
1812 this->info
.s
.section
= sectp
;
1813 this->info
.size
= bfd_section_size (sectp
);
1815 else if (names
.abbrev
.matches (sectp
->name
))
1817 this->abbrev
.s
.section
= sectp
;
1818 this->abbrev
.size
= bfd_section_size (sectp
);
1820 else if (names
.line
.matches (sectp
->name
))
1822 this->line
.s
.section
= sectp
;
1823 this->line
.size
= bfd_section_size (sectp
);
1825 else if (names
.loc
.matches (sectp
->name
))
1827 this->loc
.s
.section
= sectp
;
1828 this->loc
.size
= bfd_section_size (sectp
);
1830 else if (names
.loclists
.matches (sectp
->name
))
1832 this->loclists
.s
.section
= sectp
;
1833 this->loclists
.size
= bfd_section_size (sectp
);
1835 else if (names
.macinfo
.matches (sectp
->name
))
1837 this->macinfo
.s
.section
= sectp
;
1838 this->macinfo
.size
= bfd_section_size (sectp
);
1840 else if (names
.macro
.matches (sectp
->name
))
1842 this->macro
.s
.section
= sectp
;
1843 this->macro
.size
= bfd_section_size (sectp
);
1845 else if (names
.str
.matches (sectp
->name
))
1847 this->str
.s
.section
= sectp
;
1848 this->str
.size
= bfd_section_size (sectp
);
1850 else if (names
.str_offsets
.matches (sectp
->name
))
1852 this->str_offsets
.s
.section
= sectp
;
1853 this->str_offsets
.size
= bfd_section_size (sectp
);
1855 else if (names
.line_str
.matches (sectp
->name
))
1857 this->line_str
.s
.section
= sectp
;
1858 this->line_str
.size
= bfd_section_size (sectp
);
1860 else if (names
.addr
.matches (sectp
->name
))
1862 this->addr
.s
.section
= sectp
;
1863 this->addr
.size
= bfd_section_size (sectp
);
1865 else if (names
.frame
.matches (sectp
->name
))
1867 this->frame
.s
.section
= sectp
;
1868 this->frame
.size
= bfd_section_size (sectp
);
1870 else if (names
.eh_frame
.matches (sectp
->name
))
1872 this->eh_frame
.s
.section
= sectp
;
1873 this->eh_frame
.size
= bfd_section_size (sectp
);
1875 else if (names
.ranges
.matches (sectp
->name
))
1877 this->ranges
.s
.section
= sectp
;
1878 this->ranges
.size
= bfd_section_size (sectp
);
1880 else if (names
.rnglists
.matches (sectp
->name
))
1882 this->rnglists
.s
.section
= sectp
;
1883 this->rnglists
.size
= bfd_section_size (sectp
);
1885 else if (names
.types
.matches (sectp
->name
))
1887 struct dwarf2_section_info type_section
;
1889 memset (&type_section
, 0, sizeof (type_section
));
1890 type_section
.s
.section
= sectp
;
1891 type_section
.size
= bfd_section_size (sectp
);
1893 this->types
.push_back (type_section
);
1895 else if (names
.gdb_index
.matches (sectp
->name
))
1897 this->gdb_index
.s
.section
= sectp
;
1898 this->gdb_index
.size
= bfd_section_size (sectp
);
1900 else if (names
.debug_names
.matches (sectp
->name
))
1902 this->debug_names
.s
.section
= sectp
;
1903 this->debug_names
.size
= bfd_section_size (sectp
);
1905 else if (names
.debug_aranges
.matches (sectp
->name
))
1907 this->debug_aranges
.s
.section
= sectp
;
1908 this->debug_aranges
.size
= bfd_section_size (sectp
);
1911 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1912 && bfd_section_vma (sectp
) == 0)
1913 this->has_section_at_zero
= true;
1916 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1920 dwarf2_get_section_info (struct objfile
*objfile
,
1921 enum dwarf2_section_enum sect
,
1922 asection
**sectp
, const gdb_byte
**bufp
,
1923 bfd_size_type
*sizep
)
1925 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1926 struct dwarf2_section_info
*info
;
1928 /* We may see an objfile without any DWARF, in which case we just
1930 if (per_objfile
== NULL
)
1939 case DWARF2_DEBUG_FRAME
:
1940 info
= &per_objfile
->per_bfd
->frame
;
1942 case DWARF2_EH_FRAME
:
1943 info
= &per_objfile
->per_bfd
->eh_frame
;
1946 gdb_assert_not_reached ("unexpected section");
1949 info
->read (objfile
);
1951 *sectp
= info
->get_bfd_section ();
1952 *bufp
= info
->buffer
;
1953 *sizep
= info
->size
;
1957 /* DWARF quick_symbol_functions support. */
1959 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1960 unique line tables, so we maintain a separate table of all .debug_line
1961 derived entries to support the sharing.
1962 All the quick functions need is the list of file names. We discard the
1963 line_header when we're done and don't need to record it here. */
1964 struct quick_file_names
1966 /* The data used to construct the hash key. */
1967 struct stmt_list_hash hash
;
1969 /* The number of entries in file_names, real_names. */
1970 unsigned int num_file_names
;
1972 /* The file names from the line table, after being run through
1974 const char **file_names
;
1976 /* The file names from the line table after being run through
1977 gdb_realpath. These are computed lazily. */
1978 const char **real_names
;
1981 /* When using the index (and thus not using psymtabs), each CU has an
1982 object of this type. This is used to hold information needed by
1983 the various "quick" methods. */
1984 struct dwarf2_per_cu_quick_data
1986 /* The file table. This can be NULL if there was no file table
1987 or it's currently not read in.
1988 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
1989 struct quick_file_names
*file_names
;
1991 /* A temporary mark bit used when iterating over all CUs in
1992 expand_symtabs_matching. */
1993 unsigned int mark
: 1;
1995 /* True if we've tried to read the file table and found there isn't one.
1996 There will be no point in trying to read it again next time. */
1997 unsigned int no_file_data
: 1;
2000 /* A subclass of psymbol_functions that arranges to read the DWARF
2001 partial symbols when needed. */
2002 struct lazy_dwarf_reader
: public psymbol_functions
2004 using psymbol_functions::psymbol_functions
;
2006 bool can_lazily_read_symbols () override
2011 void read_partial_symbols (struct objfile
*objfile
) override
2013 if (dwarf2_has_info (objfile
, nullptr))
2014 dwarf2_build_psymtabs (objfile
, this);
2018 static quick_symbol_functions_up
2019 make_lazy_dwarf_reader ()
2021 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2024 struct dwarf2_base_index_functions
: public quick_symbol_functions
2026 bool has_symbols (struct objfile
*objfile
) override
;
2028 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2030 void forget_cached_source_info (struct objfile
*objfile
) override
;
2032 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2035 bool *symbol_found_p
) override
2037 *symbol_found_p
= false;
2038 return language_unknown
;
2041 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2043 void expand_all_symtabs (struct objfile
*objfile
) override
;
2045 struct compunit_symtab
*find_pc_sect_compunit_symtab
2046 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2047 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2049 struct compunit_symtab
*find_compunit_symtab_by_address
2050 (struct objfile
*objfile
, CORE_ADDR address
) override
2055 void map_symbol_filenames (struct objfile
*objfile
,
2056 gdb::function_view
<symbol_filename_ftype
> fun
,
2057 bool need_fullname
) override
;
2060 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2062 void dump (struct objfile
*objfile
) override
;
2064 void expand_matching_symbols
2066 const lookup_name_info
&lookup_name
,
2069 symbol_compare_ftype
*ordered_compare
) override
;
2071 bool expand_symtabs_matching
2072 (struct objfile
*objfile
,
2073 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2074 const lookup_name_info
*lookup_name
,
2075 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2076 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2077 block_search_flags search_flags
,
2079 enum search_domain kind
) override
;
2082 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2084 void dump (struct objfile
*objfile
) override
;
2086 void expand_matching_symbols
2088 const lookup_name_info
&lookup_name
,
2091 symbol_compare_ftype
*ordered_compare
) override
;
2093 bool expand_symtabs_matching
2094 (struct objfile
*objfile
,
2095 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2096 const lookup_name_info
*lookup_name
,
2097 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2098 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2099 block_search_flags search_flags
,
2101 enum search_domain kind
) override
;
2104 static quick_symbol_functions_up
2105 make_dwarf_gdb_index ()
2107 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2110 static quick_symbol_functions_up
2111 make_dwarf_debug_names ()
2113 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2116 /* Utility hash function for a stmt_list_hash. */
2119 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2123 if (stmt_list_hash
->dwo_unit
!= NULL
)
2124 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2125 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2129 /* Utility equality function for a stmt_list_hash. */
2132 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2133 const struct stmt_list_hash
*rhs
)
2135 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2137 if (lhs
->dwo_unit
!= NULL
2138 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2141 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2144 /* Hash function for a quick_file_names. */
2147 hash_file_name_entry (const void *e
)
2149 const struct quick_file_names
*file_data
2150 = (const struct quick_file_names
*) e
;
2152 return hash_stmt_list_entry (&file_data
->hash
);
2155 /* Equality function for a quick_file_names. */
2158 eq_file_name_entry (const void *a
, const void *b
)
2160 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2161 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2163 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2166 /* Delete function for a quick_file_names. */
2169 delete_file_name_entry (void *e
)
2171 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2174 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2176 xfree ((void*) file_data
->file_names
[i
]);
2177 if (file_data
->real_names
)
2178 xfree ((void*) file_data
->real_names
[i
]);
2181 /* The space for the struct itself lives on the obstack, so we don't
2185 /* Create a quick_file_names hash table. */
2188 create_quick_file_names_table (unsigned int nr_initial_entries
)
2190 return htab_up (htab_create_alloc (nr_initial_entries
,
2191 hash_file_name_entry
, eq_file_name_entry
,
2192 delete_file_name_entry
, xcalloc
, xfree
));
2195 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2196 function is unrelated to symtabs, symtab would have to be created afterwards.
2197 You should call age_cached_comp_units after processing the CU. */
2200 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2203 if (per_cu
->is_debug_types
)
2204 load_full_type_unit (per_cu
, per_objfile
);
2206 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2207 skip_partial
, language_minimal
);
2209 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2211 return nullptr; /* Dummy CU. */
2213 dwarf2_find_base_address (cu
->dies
, cu
);
2218 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2221 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2222 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2224 /* Skip type_unit_groups, reading the type units they contain
2225 is handled elsewhere. */
2226 if (per_cu
->type_unit_group_p ())
2230 /* The destructor of dwarf2_queue_guard frees any entries left on
2231 the queue. After this point we're guaranteed to leave this function
2232 with the dwarf queue empty. */
2233 dwarf2_queue_guard
q_guard (per_objfile
);
2235 if (!per_objfile
->symtab_set_p (per_cu
))
2237 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2238 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2240 /* If we just loaded a CU from a DWO, and we're working with an index
2241 that may badly handle TUs, load all the TUs in that DWO as well.
2242 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2243 if (!per_cu
->is_debug_types
2245 && cu
->dwo_unit
!= NULL
2246 && per_objfile
->per_bfd
->index_table
!= NULL
2247 && per_objfile
->per_bfd
->index_table
->version
<= 7
2248 /* DWP files aren't supported yet. */
2249 && get_dwp_file (per_objfile
) == NULL
)
2250 queue_and_load_all_dwo_tus (cu
);
2253 process_queue (per_objfile
);
2256 /* Age the cache, releasing compilation units that have not
2257 been used recently. */
2258 per_objfile
->age_comp_units ();
2261 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2262 the per-objfile for which this symtab is instantiated.
2264 Returns the resulting symbol table. */
2266 static struct compunit_symtab
*
2267 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2268 dwarf2_per_objfile
*per_objfile
,
2271 gdb_assert (per_objfile
->per_bfd
->using_index
);
2273 if (!per_objfile
->symtab_set_p (per_cu
))
2275 free_cached_comp_units
freer (per_objfile
);
2276 scoped_restore decrementer
= increment_reading_symtab ();
2277 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2278 process_cu_includes (per_objfile
);
2281 return per_objfile
->get_symtab (per_cu
);
2286 dwarf2_per_cu_data_up
2287 dwarf2_per_bfd::allocate_per_cu ()
2289 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2290 result
->per_bfd
= this;
2291 result
->index
= m_num_psymtabs
++;
2297 std::unique_ptr
<signatured_type
>
2298 dwarf2_per_bfd::allocate_signatured_type ()
2300 std::unique_ptr
<signatured_type
> result (new signatured_type
);
2301 result
->per_bfd
= this;
2302 result
->index
= m_num_psymtabs
++;
2307 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2308 obstack, and constructed with the specified field values. */
2310 static dwarf2_per_cu_data_up
2311 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2312 struct dwarf2_section_info
*section
,
2314 sect_offset sect_off
, ULONGEST length
)
2316 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2317 the_cu
->sect_off
= sect_off
;
2318 the_cu
->length
= length
;
2319 the_cu
->section
= section
;
2320 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2321 struct dwarf2_per_cu_quick_data
);
2322 the_cu
->is_dwz
= is_dwz
;
2326 /* A helper for create_cus_from_index that handles a given list of
2330 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2331 const gdb_byte
*cu_list
, offset_type n_elements
,
2332 struct dwarf2_section_info
*section
,
2335 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2337 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2339 sect_offset sect_off
2340 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2341 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2344 dwarf2_per_cu_data_up per_cu
2345 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2347 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2351 /* Read the CU list from the mapped index, and use it to create all
2352 the CU objects for PER_BFD. */
2355 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2356 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2357 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2359 gdb_assert (per_bfd
->all_comp_units
.empty ());
2360 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2362 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2365 if (dwz_elements
== 0)
2368 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2369 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2373 /* Create the signatured type hash table from the index. */
2376 create_signatured_type_table_from_index
2377 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2378 const gdb_byte
*bytes
, offset_type elements
)
2380 htab_up sig_types_hash
= allocate_signatured_type_table ();
2382 for (offset_type i
= 0; i
< elements
; i
+= 3)
2384 std::unique_ptr
<signatured_type
> sig_type
;
2387 cu_offset type_offset_in_tu
;
2389 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2390 sect_offset sect_off
2391 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2393 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2395 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2398 sig_type
= per_bfd
->allocate_signatured_type ();
2399 sig_type
->signature
= signature
;
2400 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2401 sig_type
->is_debug_types
= 1;
2402 sig_type
->section
= section
;
2403 sig_type
->sect_off
= sect_off
;
2405 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2406 struct dwarf2_per_cu_quick_data
);
2408 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2409 *slot
= sig_type
.get ();
2411 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2414 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2417 /* Create the signatured type hash table from .debug_names. */
2420 create_signatured_type_table_from_debug_names
2421 (dwarf2_per_objfile
*per_objfile
,
2422 const mapped_debug_names
&map
,
2423 struct dwarf2_section_info
*section
,
2424 struct dwarf2_section_info
*abbrev_section
)
2426 struct objfile
*objfile
= per_objfile
->objfile
;
2428 section
->read (objfile
);
2429 abbrev_section
->read (objfile
);
2431 htab_up sig_types_hash
= allocate_signatured_type_table ();
2433 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2435 std::unique_ptr
<signatured_type
> sig_type
;
2438 sect_offset sect_off
2439 = (sect_offset
) (extract_unsigned_integer
2440 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2442 map
.dwarf5_byte_order
));
2444 comp_unit_head cu_header
;
2445 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2447 section
->buffer
+ to_underlying (sect_off
),
2450 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2451 sig_type
->signature
= cu_header
.signature
;
2452 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2453 sig_type
->is_debug_types
= 1;
2454 sig_type
->section
= section
;
2455 sig_type
->sect_off
= sect_off
;
2457 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2458 struct dwarf2_per_cu_quick_data
);
2460 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2461 *slot
= sig_type
.get ();
2463 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2466 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2469 /* Read the address map data from the mapped index, and use it to
2470 populate the psymtabs_addrmap. */
2473 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2474 struct mapped_index
*index
)
2476 struct objfile
*objfile
= per_objfile
->objfile
;
2477 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2478 struct gdbarch
*gdbarch
= objfile
->arch ();
2479 const gdb_byte
*iter
, *end
;
2480 struct addrmap
*mutable_map
;
2483 auto_obstack temp_obstack
;
2485 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2487 iter
= index
->address_table
.data ();
2488 end
= iter
+ index
->address_table
.size ();
2490 baseaddr
= objfile
->text_section_offset ();
2494 ULONGEST hi
, lo
, cu_index
;
2495 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2497 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2499 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2504 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2505 hex_string (lo
), hex_string (hi
));
2509 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2511 complaint (_(".gdb_index address table has invalid CU number %u"),
2512 (unsigned) cu_index
);
2516 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2517 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2518 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2519 per_bfd
->get_cu (cu_index
));
2522 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2526 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2527 populate the psymtabs_addrmap. */
2530 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2531 struct dwarf2_section_info
*section
)
2533 struct objfile
*objfile
= per_objfile
->objfile
;
2534 bfd
*abfd
= objfile
->obfd
;
2535 struct gdbarch
*gdbarch
= objfile
->arch ();
2536 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2537 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2539 auto_obstack temp_obstack
;
2540 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2542 std::unordered_map
<sect_offset
,
2543 dwarf2_per_cu_data
*,
2544 gdb::hash_enum
<sect_offset
>>
2545 debug_info_offset_to_per_cu
;
2546 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2548 const auto insertpair
2549 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2551 if (!insertpair
.second
)
2553 warning (_("Section .debug_aranges in %s has duplicate "
2554 "debug_info_offset %s, ignoring .debug_aranges."),
2555 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2560 section
->read (objfile
);
2562 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2564 const gdb_byte
*addr
= section
->buffer
;
2566 while (addr
< section
->buffer
+ section
->size
)
2568 const gdb_byte
*const entry_addr
= addr
;
2569 unsigned int bytes_read
;
2571 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2575 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2576 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2577 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2578 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2580 warning (_("Section .debug_aranges in %s entry at offset %s "
2581 "length %s exceeds section length %s, "
2582 "ignoring .debug_aranges."),
2583 objfile_name (objfile
),
2584 plongest (entry_addr
- section
->buffer
),
2585 plongest (bytes_read
+ entry_length
),
2586 pulongest (section
->size
));
2590 /* The version number. */
2591 const uint16_t version
= read_2_bytes (abfd
, addr
);
2595 warning (_("Section .debug_aranges in %s entry at offset %s "
2596 "has unsupported version %d, ignoring .debug_aranges."),
2597 objfile_name (objfile
),
2598 plongest (entry_addr
- section
->buffer
), version
);
2602 const uint64_t debug_info_offset
2603 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2604 addr
+= offset_size
;
2605 const auto per_cu_it
2606 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2607 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2609 warning (_("Section .debug_aranges in %s entry at offset %s "
2610 "debug_info_offset %s does not exists, "
2611 "ignoring .debug_aranges."),
2612 objfile_name (objfile
),
2613 plongest (entry_addr
- section
->buffer
),
2614 pulongest (debug_info_offset
));
2617 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2619 const uint8_t address_size
= *addr
++;
2620 if (address_size
< 1 || address_size
> 8)
2622 warning (_("Section .debug_aranges in %s entry at offset %s "
2623 "address_size %u is invalid, ignoring .debug_aranges."),
2624 objfile_name (objfile
),
2625 plongest (entry_addr
- section
->buffer
), address_size
);
2629 const uint8_t segment_selector_size
= *addr
++;
2630 if (segment_selector_size
!= 0)
2632 warning (_("Section .debug_aranges in %s entry at offset %s "
2633 "segment_selector_size %u is not supported, "
2634 "ignoring .debug_aranges."),
2635 objfile_name (objfile
),
2636 plongest (entry_addr
- section
->buffer
),
2637 segment_selector_size
);
2641 /* Must pad to an alignment boundary that is twice the address
2642 size. It is undocumented by the DWARF standard but GCC does
2644 for (size_t padding
= ((-(addr
- section
->buffer
))
2645 & (2 * address_size
- 1));
2646 padding
> 0; padding
--)
2649 warning (_("Section .debug_aranges in %s entry at offset %s "
2650 "padding is not zero, ignoring .debug_aranges."),
2651 objfile_name (objfile
),
2652 plongest (entry_addr
- section
->buffer
));
2658 if (addr
+ 2 * address_size
> entry_end
)
2660 warning (_("Section .debug_aranges in %s entry at offset %s "
2661 "address list is not properly terminated, "
2662 "ignoring .debug_aranges."),
2663 objfile_name (objfile
),
2664 plongest (entry_addr
- section
->buffer
));
2667 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2669 addr
+= address_size
;
2670 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2672 addr
+= address_size
;
2673 if (start
== 0 && length
== 0)
2675 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2677 /* Symbol was eliminated due to a COMDAT group. */
2680 ULONGEST end
= start
+ length
;
2681 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2683 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2685 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2689 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2693 /* A helper function that reads the .gdb_index from BUFFER and fills
2694 in MAP. FILENAME is the name of the file containing the data;
2695 it is used for error reporting. DEPRECATED_OK is true if it is
2696 ok to use deprecated sections.
2698 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2699 out parameters that are filled in with information about the CU and
2700 TU lists in the section.
2702 Returns true if all went well, false otherwise. */
2705 read_gdb_index_from_buffer (const char *filename
,
2707 gdb::array_view
<const gdb_byte
> buffer
,
2708 struct mapped_index
*map
,
2709 const gdb_byte
**cu_list
,
2710 offset_type
*cu_list_elements
,
2711 const gdb_byte
**types_list
,
2712 offset_type
*types_list_elements
)
2714 const gdb_byte
*addr
= &buffer
[0];
2715 offset_view
metadata (buffer
);
2717 /* Version check. */
2718 offset_type version
= metadata
[0];
2719 /* Versions earlier than 3 emitted every copy of a psymbol. This
2720 causes the index to behave very poorly for certain requests. Version 3
2721 contained incomplete addrmap. So, it seems better to just ignore such
2725 static int warning_printed
= 0;
2726 if (!warning_printed
)
2728 warning (_("Skipping obsolete .gdb_index section in %s."),
2730 warning_printed
= 1;
2734 /* Index version 4 uses a different hash function than index version
2737 Versions earlier than 6 did not emit psymbols for inlined
2738 functions. Using these files will cause GDB not to be able to
2739 set breakpoints on inlined functions by name, so we ignore these
2740 indices unless the user has done
2741 "set use-deprecated-index-sections on". */
2742 if (version
< 6 && !deprecated_ok
)
2744 static int warning_printed
= 0;
2745 if (!warning_printed
)
2748 Skipping deprecated .gdb_index section in %s.\n\
2749 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2750 to use the section anyway."),
2752 warning_printed
= 1;
2756 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2757 of the TU (for symbols coming from TUs),
2758 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2759 Plus gold-generated indices can have duplicate entries for global symbols,
2760 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2761 These are just performance bugs, and we can't distinguish gdb-generated
2762 indices from gold-generated ones, so issue no warning here. */
2764 /* Indexes with higher version than the one supported by GDB may be no
2765 longer backward compatible. */
2769 map
->version
= version
;
2772 *cu_list
= addr
+ metadata
[i
];
2773 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2776 *types_list
= addr
+ metadata
[i
];
2777 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2780 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2781 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2783 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2786 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2787 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2789 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2793 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2798 /* Callback types for dwarf2_read_gdb_index. */
2800 typedef gdb::function_view
2801 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2802 get_gdb_index_contents_ftype
;
2803 typedef gdb::function_view
2804 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2805 get_gdb_index_contents_dwz_ftype
;
2807 /* Read .gdb_index. If everything went ok, initialize the "quick"
2808 elements of all the CUs and return 1. Otherwise, return 0. */
2811 dwarf2_read_gdb_index
2812 (dwarf2_per_objfile
*per_objfile
,
2813 get_gdb_index_contents_ftype get_gdb_index_contents
,
2814 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2816 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2817 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2818 struct dwz_file
*dwz
;
2819 struct objfile
*objfile
= per_objfile
->objfile
;
2820 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2822 gdb::array_view
<const gdb_byte
> main_index_contents
2823 = get_gdb_index_contents (objfile
, per_bfd
);
2825 if (main_index_contents
.empty ())
2828 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2829 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2830 use_deprecated_index_sections
,
2831 main_index_contents
, map
.get (), &cu_list
,
2832 &cu_list_elements
, &types_list
,
2833 &types_list_elements
))
2836 /* Don't use the index if it's empty. */
2837 if (map
->symbol_table
.empty ())
2840 /* If there is a .dwz file, read it so we can get its CU list as
2842 dwz
= dwarf2_get_dwz_file (per_bfd
);
2845 struct mapped_index dwz_map
;
2846 const gdb_byte
*dwz_types_ignore
;
2847 offset_type dwz_types_elements_ignore
;
2849 gdb::array_view
<const gdb_byte
> dwz_index_content
2850 = get_gdb_index_contents_dwz (objfile
, dwz
);
2852 if (dwz_index_content
.empty ())
2855 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2856 1, dwz_index_content
, &dwz_map
,
2857 &dwz_list
, &dwz_list_elements
,
2859 &dwz_types_elements_ignore
))
2861 warning (_("could not read '.gdb_index' section from %s; skipping"),
2862 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2867 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2870 if (types_list_elements
)
2872 /* We can only handle a single .debug_types when we have an
2874 if (per_bfd
->types
.size () != 1)
2877 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2879 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2880 types_list_elements
);
2883 create_addrmap_from_index (per_objfile
, map
.get ());
2885 per_bfd
->index_table
= std::move (map
);
2886 per_bfd
->using_index
= 1;
2887 per_bfd
->quick_file_names_table
=
2888 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2893 /* die_reader_func for dw2_get_file_names. */
2896 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2897 struct die_info
*comp_unit_die
)
2899 struct dwarf2_cu
*cu
= reader
->cu
;
2900 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2901 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2902 struct dwarf2_per_cu_data
*lh_cu
;
2903 struct attribute
*attr
;
2905 struct quick_file_names
*qfn
;
2907 gdb_assert (! this_cu
->is_debug_types
);
2909 /* Our callers never want to match partial units -- instead they
2910 will match the enclosing full CU. */
2911 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2913 this_cu
->v
.quick
->no_file_data
= 1;
2921 sect_offset line_offset
{};
2923 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2924 if (attr
!= nullptr && attr
->form_is_unsigned ())
2926 struct quick_file_names find_entry
;
2928 line_offset
= (sect_offset
) attr
->as_unsigned ();
2930 /* We may have already read in this line header (TU line header sharing).
2931 If we have we're done. */
2932 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2933 find_entry
.hash
.line_sect_off
= line_offset
;
2934 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2935 &find_entry
, INSERT
);
2938 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
2942 lh
= dwarf_decode_line_header (line_offset
, cu
);
2946 lh_cu
->v
.quick
->no_file_data
= 1;
2950 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2951 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2952 qfn
->hash
.line_sect_off
= line_offset
;
2953 gdb_assert (slot
!= NULL
);
2956 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
2959 if (strcmp (fnd
.name
, "<unknown>") != 0)
2962 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
2964 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2965 qfn
->num_file_names
);
2967 qfn
->file_names
[0] = xstrdup (fnd
.name
);
2968 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
2969 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
2970 fnd
.comp_dir
).release ();
2971 qfn
->real_names
= NULL
;
2973 lh_cu
->v
.quick
->file_names
= qfn
;
2976 /* A helper for the "quick" functions which attempts to read the line
2977 table for THIS_CU. */
2979 static struct quick_file_names
*
2980 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2981 dwarf2_per_objfile
*per_objfile
)
2983 /* This should never be called for TUs. */
2984 gdb_assert (! this_cu
->is_debug_types
);
2985 /* Nor type unit groups. */
2986 gdb_assert (! this_cu
->type_unit_group_p ());
2988 if (this_cu
->v
.quick
->file_names
!= NULL
)
2989 return this_cu
->v
.quick
->file_names
;
2990 /* If we know there is no line data, no point in looking again. */
2991 if (this_cu
->v
.quick
->no_file_data
)
2994 cutu_reader
reader (this_cu
, per_objfile
);
2995 if (!reader
.dummy_p
)
2996 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
2998 if (this_cu
->v
.quick
->no_file_data
)
3000 return this_cu
->v
.quick
->file_names
;
3003 /* A helper for the "quick" functions which computes and caches the
3004 real path for a given file name from the line table. */
3007 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3008 struct quick_file_names
*qfn
, int index
)
3010 if (qfn
->real_names
== NULL
)
3011 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3012 qfn
->num_file_names
, const char *);
3014 if (qfn
->real_names
[index
] == NULL
)
3015 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3017 return qfn
->real_names
[index
];
3021 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3023 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3024 dwarf2_per_cu_data
*dwarf_cu
3025 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3026 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3031 return compunit_primary_filetab (cust
);
3034 /* Traversal function for dw2_forget_cached_source_info. */
3037 dw2_free_cached_file_names (void **slot
, void *info
)
3039 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3041 if (file_data
->real_names
)
3045 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3047 xfree ((void*) file_data
->real_names
[i
]);
3048 file_data
->real_names
[i
] = NULL
;
3056 dwarf2_base_index_functions::forget_cached_source_info
3057 (struct objfile
*objfile
)
3059 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3061 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3062 dw2_free_cached_file_names
, NULL
);
3065 /* Struct used to manage iterating over all CUs looking for a symbol. */
3067 struct dw2_symtab_iterator
3069 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3070 dwarf2_per_objfile
*per_objfile
;
3071 /* If set, only look for symbols that match that block. Valid values are
3072 GLOBAL_BLOCK and STATIC_BLOCK. */
3073 gdb::optional
<block_enum
> block_index
;
3074 /* The kind of symbol we're looking for. */
3076 /* The list of CUs from the index entry of the symbol,
3077 or NULL if not found. */
3079 /* The next element in VEC to look at. */
3081 /* The number of elements in VEC, or zero if there is no match. */
3083 /* Have we seen a global version of the symbol?
3084 If so we can ignore all further global instances.
3085 This is to work around gold/15646, inefficient gold-generated
3090 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3093 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3094 dwarf2_per_objfile
*per_objfile
,
3095 gdb::optional
<block_enum
> block_index
,
3096 domain_enum domain
, offset_type namei
)
3098 iter
->per_objfile
= per_objfile
;
3099 iter
->block_index
= block_index
;
3100 iter
->domain
= domain
;
3102 iter
->global_seen
= 0;
3106 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3107 /* index is NULL if OBJF_READNOW. */
3111 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3112 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3114 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3115 iter
->length
= iter
->vec
[0];
3118 /* Return the next matching CU or NULL if there are no more. */
3120 static struct dwarf2_per_cu_data
*
3121 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3123 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3125 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3127 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3128 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3129 gdb_index_symbol_kind symbol_kind
=
3130 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3131 /* Only check the symbol attributes if they're present.
3132 Indices prior to version 7 don't record them,
3133 and indices >= 7 may elide them for certain symbols
3134 (gold does this). */
3136 (per_objfile
->per_bfd
->index_table
->version
>= 7
3137 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3139 /* Don't crash on bad data. */
3140 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3142 complaint (_(".gdb_index entry has bad CU index"
3143 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3147 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3149 /* Skip if already read in. */
3150 if (per_objfile
->symtab_set_p (per_cu
))
3153 /* Check static vs global. */
3156 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3158 if (iter
->block_index
.has_value ())
3160 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3162 if (is_static
!= want_static
)
3166 /* Work around gold/15646. */
3168 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3170 if (iter
->global_seen
)
3173 iter
->global_seen
= 1;
3177 /* Only check the symbol's kind if it has one. */
3180 switch (iter
->domain
)
3183 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3184 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3185 /* Some types are also in VAR_DOMAIN. */
3186 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3190 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3194 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3198 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3214 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3220 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3221 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3224 for (int i
= 0; i
< total
; ++i
)
3226 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3228 if (!per_objfile
->symtab_set_p (per_cu
))
3231 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3232 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3235 /* This dumps minimal information about the index.
3236 It is called via "mt print objfiles".
3237 One use is to verify .gdb_index has been loaded by the
3238 gdb.dwarf2/gdb-index.exp testcase. */
3241 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3243 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3245 gdb_assert (per_objfile
->per_bfd
->using_index
);
3246 printf_filtered (".gdb_index:");
3247 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3249 printf_filtered (" version %d\n",
3250 per_objfile
->per_bfd
->index_table
->version
);
3253 printf_filtered (" faked for \"readnow\"\n");
3254 printf_filtered ("\n");
3258 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3260 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3261 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3263 for (int i
= 0; i
< total_units
; ++i
)
3265 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3267 /* We don't want to directly expand a partial CU, because if we
3268 read it with the wrong language, then assertion failures can
3269 be triggered later on. See PR symtab/23010. So, tell
3270 dw2_instantiate_symtab to skip partial CUs -- any important
3271 partial CU will be read via DW_TAG_imported_unit anyway. */
3272 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3277 dw2_expand_symtabs_matching_symbol
3278 (mapped_index_base
&index
,
3279 const lookup_name_info
&lookup_name_in
,
3280 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3281 gdb::function_view
<bool (offset_type
)> match_callback
,
3282 dwarf2_per_objfile
*per_objfile
);
3285 dw2_expand_symtabs_matching_one
3286 (dwarf2_per_cu_data
*per_cu
,
3287 dwarf2_per_objfile
*per_objfile
,
3288 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3289 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3292 dwarf2_gdb_index::expand_matching_symbols
3293 (struct objfile
*objfile
,
3294 const lookup_name_info
&name
, domain_enum domain
,
3296 symbol_compare_ftype
*ordered_compare
)
3299 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3301 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3303 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3305 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3307 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3308 auto matcher
= [&] (const char *symname
)
3310 if (ordered_compare
== nullptr)
3312 return ordered_compare (symname
, match_name
) == 0;
3315 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3316 [&] (offset_type namei
)
3318 struct dw2_symtab_iterator iter
;
3319 struct dwarf2_per_cu_data
*per_cu
;
3321 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3323 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3324 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3331 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3332 proceed assuming all symtabs have been read in. */
3336 /* Starting from a search name, return the string that finds the upper
3337 bound of all strings that start with SEARCH_NAME in a sorted name
3338 list. Returns the empty string to indicate that the upper bound is
3339 the end of the list. */
3342 make_sort_after_prefix_name (const char *search_name
)
3344 /* When looking to complete "func", we find the upper bound of all
3345 symbols that start with "func" by looking for where we'd insert
3346 the closest string that would follow "func" in lexicographical
3347 order. Usually, that's "func"-with-last-character-incremented,
3348 i.e. "fund". Mind non-ASCII characters, though. Usually those
3349 will be UTF-8 multi-byte sequences, but we can't be certain.
3350 Especially mind the 0xff character, which is a valid character in
3351 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3352 rule out compilers allowing it in identifiers. Note that
3353 conveniently, strcmp/strcasecmp are specified to compare
3354 characters interpreted as unsigned char. So what we do is treat
3355 the whole string as a base 256 number composed of a sequence of
3356 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3357 to 0, and carries 1 to the following more-significant position.
3358 If the very first character in SEARCH_NAME ends up incremented
3359 and carries/overflows, then the upper bound is the end of the
3360 list. The string after the empty string is also the empty
3363 Some examples of this operation:
3365 SEARCH_NAME => "+1" RESULT
3369 "\xff" "a" "\xff" => "\xff" "b"
3374 Then, with these symbols for example:
3380 completing "func" looks for symbols between "func" and
3381 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3382 which finds "func" and "func1", but not "fund".
3386 funcÿ (Latin1 'ÿ' [0xff])
3390 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3391 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3395 ÿÿ (Latin1 'ÿ' [0xff])
3398 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3399 the end of the list.
3401 std::string after
= search_name
;
3402 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3404 if (!after
.empty ())
3405 after
.back () = (unsigned char) after
.back () + 1;
3409 /* See declaration. */
3411 std::pair
<std::vector
<name_component
>::const_iterator
,
3412 std::vector
<name_component
>::const_iterator
>
3413 mapped_index_base::find_name_components_bounds
3414 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3415 dwarf2_per_objfile
*per_objfile
) const
3418 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3420 const char *lang_name
3421 = lookup_name_without_params
.language_lookup_name (lang
);
3423 /* Comparison function object for lower_bound that matches against a
3424 given symbol name. */
3425 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3428 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3429 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3430 return name_cmp (elem_name
, name
) < 0;
3433 /* Comparison function object for upper_bound that matches against a
3434 given symbol name. */
3435 auto lookup_compare_upper
= [&] (const char *name
,
3436 const name_component
&elem
)
3438 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3439 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3440 return name_cmp (name
, elem_name
) < 0;
3443 auto begin
= this->name_components
.begin ();
3444 auto end
= this->name_components
.end ();
3446 /* Find the lower bound. */
3449 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3452 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3455 /* Find the upper bound. */
3458 if (lookup_name_without_params
.completion_mode ())
3460 /* In completion mode, we want UPPER to point past all
3461 symbols names that have the same prefix. I.e., with
3462 these symbols, and completing "func":
3464 function << lower bound
3466 other_function << upper bound
3468 We find the upper bound by looking for the insertion
3469 point of "func"-with-last-character-incremented,
3471 std::string after
= make_sort_after_prefix_name (lang_name
);
3474 return std::lower_bound (lower
, end
, after
.c_str (),
3475 lookup_compare_lower
);
3478 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3481 return {lower
, upper
};
3484 /* See declaration. */
3487 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3489 if (!this->name_components
.empty ())
3492 this->name_components_casing
= case_sensitivity
;
3494 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3496 /* The code below only knows how to break apart components of C++
3497 symbol names (and other languages that use '::' as
3498 namespace/module separator) and Ada symbol names. */
3499 auto count
= this->symbol_name_count ();
3500 for (offset_type idx
= 0; idx
< count
; idx
++)
3502 if (this->symbol_name_slot_invalid (idx
))
3505 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3507 /* Add each name component to the name component table. */
3508 unsigned int previous_len
= 0;
3510 if (strstr (name
, "::") != nullptr)
3512 for (unsigned int current_len
= cp_find_first_component (name
);
3513 name
[current_len
] != '\0';
3514 current_len
+= cp_find_first_component (name
+ current_len
))
3516 gdb_assert (name
[current_len
] == ':');
3517 this->name_components
.push_back ({previous_len
, idx
});
3518 /* Skip the '::'. */
3520 previous_len
= current_len
;
3525 /* Handle the Ada encoded (aka mangled) form here. */
3526 for (const char *iter
= strstr (name
, "__");
3528 iter
= strstr (iter
, "__"))
3530 this->name_components
.push_back ({previous_len
, idx
});
3532 previous_len
= iter
- name
;
3536 this->name_components
.push_back ({previous_len
, idx
});
3539 /* Sort name_components elements by name. */
3540 auto name_comp_compare
= [&] (const name_component
&left
,
3541 const name_component
&right
)
3543 const char *left_qualified
3544 = this->symbol_name_at (left
.idx
, per_objfile
);
3545 const char *right_qualified
3546 = this->symbol_name_at (right
.idx
, per_objfile
);
3548 const char *left_name
= left_qualified
+ left
.name_offset
;
3549 const char *right_name
= right_qualified
+ right
.name_offset
;
3551 return name_cmp (left_name
, right_name
) < 0;
3554 std::sort (this->name_components
.begin (),
3555 this->name_components
.end (),
3559 /* Helper for dw2_expand_symtabs_matching that works with a
3560 mapped_index_base instead of the containing objfile. This is split
3561 to a separate function in order to be able to unit test the
3562 name_components matching using a mock mapped_index_base. For each
3563 symbol name that matches, calls MATCH_CALLBACK, passing it the
3564 symbol's index in the mapped_index_base symbol table. */
3567 dw2_expand_symtabs_matching_symbol
3568 (mapped_index_base
&index
,
3569 const lookup_name_info
&lookup_name_in
,
3570 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3571 gdb::function_view
<bool (offset_type
)> match_callback
,
3572 dwarf2_per_objfile
*per_objfile
)
3574 lookup_name_info lookup_name_without_params
3575 = lookup_name_in
.make_ignore_params ();
3577 /* Build the symbol name component sorted vector, if we haven't
3579 index
.build_name_components (per_objfile
);
3581 /* The same symbol may appear more than once in the range though.
3582 E.g., if we're looking for symbols that complete "w", and we have
3583 a symbol named "w1::w2", we'll find the two name components for
3584 that same symbol in the range. To be sure we only call the
3585 callback once per symbol, we first collect the symbol name
3586 indexes that matched in a temporary vector and ignore
3588 std::vector
<offset_type
> matches
;
3590 struct name_and_matcher
3592 symbol_name_matcher_ftype
*matcher
;
3595 bool operator== (const name_and_matcher
&other
) const
3597 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3601 /* A vector holding all the different symbol name matchers, for all
3603 std::vector
<name_and_matcher
> matchers
;
3605 for (int i
= 0; i
< nr_languages
; i
++)
3607 enum language lang_e
= (enum language
) i
;
3609 const language_defn
*lang
= language_def (lang_e
);
3610 symbol_name_matcher_ftype
*name_matcher
3611 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3613 name_and_matcher key
{
3615 lookup_name_without_params
.language_lookup_name (lang_e
)
3618 /* Don't insert the same comparison routine more than once.
3619 Note that we do this linear walk. This is not a problem in
3620 practice because the number of supported languages is
3622 if (std::find (matchers
.begin (), matchers
.end (), key
)
3625 matchers
.push_back (std::move (key
));
3628 = index
.find_name_components_bounds (lookup_name_without_params
,
3629 lang_e
, per_objfile
);
3631 /* Now for each symbol name in range, check to see if we have a name
3632 match, and if so, call the MATCH_CALLBACK callback. */
3634 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3636 const char *qualified
3637 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3639 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3640 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3643 matches
.push_back (bounds
.first
->idx
);
3647 std::sort (matches
.begin (), matches
.end ());
3649 /* Finally call the callback, once per match. */
3652 for (offset_type idx
: matches
)
3656 if (!match_callback (idx
))
3665 /* Above we use a type wider than idx's for 'prev', since 0 and
3666 (offset_type)-1 are both possible values. */
3667 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3674 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3676 /* A mock .gdb_index/.debug_names-like name index table, enough to
3677 exercise dw2_expand_symtabs_matching_symbol, which works with the
3678 mapped_index_base interface. Builds an index from the symbol list
3679 passed as parameter to the constructor. */
3680 class mock_mapped_index
: public mapped_index_base
3683 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3684 : m_symbol_table (symbols
)
3687 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3689 /* Return the number of names in the symbol table. */
3690 size_t symbol_name_count () const override
3692 return m_symbol_table
.size ();
3695 /* Get the name of the symbol at IDX in the symbol table. */
3696 const char *symbol_name_at
3697 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3699 return m_symbol_table
[idx
];
3703 gdb::array_view
<const char *> m_symbol_table
;
3706 /* Convenience function that converts a NULL pointer to a "<null>"
3707 string, to pass to print routines. */
3710 string_or_null (const char *str
)
3712 return str
!= NULL
? str
: "<null>";
3715 /* Check if a lookup_name_info built from
3716 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3717 index. EXPECTED_LIST is the list of expected matches, in expected
3718 matching order. If no match expected, then an empty list is
3719 specified. Returns true on success. On failure prints a warning
3720 indicating the file:line that failed, and returns false. */
3723 check_match (const char *file
, int line
,
3724 mock_mapped_index
&mock_index
,
3725 const char *name
, symbol_name_match_type match_type
,
3726 bool completion_mode
,
3727 std::initializer_list
<const char *> expected_list
,
3728 dwarf2_per_objfile
*per_objfile
)
3730 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3732 bool matched
= true;
3734 auto mismatch
= [&] (const char *expected_str
,
3737 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3738 "expected=\"%s\", got=\"%s\"\n"),
3740 (match_type
== symbol_name_match_type::FULL
3742 name
, string_or_null (expected_str
), string_or_null (got
));
3746 auto expected_it
= expected_list
.begin ();
3747 auto expected_end
= expected_list
.end ();
3749 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3751 [&] (offset_type idx
)
3753 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3754 const char *expected_str
3755 = expected_it
== expected_end
? NULL
: *expected_it
++;
3757 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3758 mismatch (expected_str
, matched_name
);
3762 const char *expected_str
3763 = expected_it
== expected_end
? NULL
: *expected_it
++;
3764 if (expected_str
!= NULL
)
3765 mismatch (expected_str
, NULL
);
3770 /* The symbols added to the mock mapped_index for testing (in
3772 static const char *test_symbols
[] = {
3781 "ns2::tmpl<int>::foo2",
3782 "(anonymous namespace)::A::B::C",
3784 /* These are used to check that the increment-last-char in the
3785 matching algorithm for completion doesn't match "t1_fund" when
3786 completing "t1_func". */
3792 /* A UTF-8 name with multi-byte sequences to make sure that
3793 cp-name-parser understands this as a single identifier ("função"
3794 is "function" in PT). */
3797 /* \377 (0xff) is Latin1 'ÿ'. */
3800 /* \377 (0xff) is Latin1 'ÿ'. */
3804 /* A name with all sorts of complications. Starts with "z" to make
3805 it easier for the completion tests below. */
3806 #define Z_SYM_NAME \
3807 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3808 "::tuple<(anonymous namespace)::ui*, " \
3809 "std::default_delete<(anonymous namespace)::ui>, void>"
3814 /* Returns true if the mapped_index_base::find_name_component_bounds
3815 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3816 in completion mode. */
3819 check_find_bounds_finds (mapped_index_base
&index
,
3820 const char *search_name
,
3821 gdb::array_view
<const char *> expected_syms
,
3822 dwarf2_per_objfile
*per_objfile
)
3824 lookup_name_info
lookup_name (search_name
,
3825 symbol_name_match_type::FULL
, true);
3827 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3831 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3832 if (distance
!= expected_syms
.size ())
3835 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3837 auto nc_elem
= bounds
.first
+ exp_elem
;
3838 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3839 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3846 /* Test the lower-level mapped_index::find_name_component_bounds
3850 test_mapped_index_find_name_component_bounds ()
3852 mock_mapped_index
mock_index (test_symbols
);
3854 mock_index
.build_name_components (NULL
/* per_objfile */);
3856 /* Test the lower-level mapped_index::find_name_component_bounds
3857 method in completion mode. */
3859 static const char *expected_syms
[] = {
3864 SELF_CHECK (check_find_bounds_finds
3865 (mock_index
, "t1_func", expected_syms
,
3866 NULL
/* per_objfile */));
3869 /* Check that the increment-last-char in the name matching algorithm
3870 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3872 static const char *expected_syms1
[] = {
3876 SELF_CHECK (check_find_bounds_finds
3877 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3879 static const char *expected_syms2
[] = {
3882 SELF_CHECK (check_find_bounds_finds
3883 (mock_index
, "\377\377", expected_syms2
,
3884 NULL
/* per_objfile */));
3888 /* Test dw2_expand_symtabs_matching_symbol. */
3891 test_dw2_expand_symtabs_matching_symbol ()
3893 mock_mapped_index
mock_index (test_symbols
);
3895 /* We let all tests run until the end even if some fails, for debug
3897 bool any_mismatch
= false;
3899 /* Create the expected symbols list (an initializer_list). Needed
3900 because lists have commas, and we need to pass them to CHECK,
3901 which is a macro. */
3902 #define EXPECT(...) { __VA_ARGS__ }
3904 /* Wrapper for check_match that passes down the current
3905 __FILE__/__LINE__. */
3906 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3907 any_mismatch |= !check_match (__FILE__, __LINE__, \
3909 NAME, MATCH_TYPE, COMPLETION_MODE, \
3910 EXPECTED_LIST, NULL)
3912 /* Identity checks. */
3913 for (const char *sym
: test_symbols
)
3915 /* Should be able to match all existing symbols. */
3916 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
3919 /* Should be able to match all existing symbols with
3921 std::string with_params
= std::string (sym
) + "(int)";
3922 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3925 /* Should be able to match all existing symbols with
3926 parameters and qualifiers. */
3927 with_params
= std::string (sym
) + " ( int ) const";
3928 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3931 /* This should really find sym, but cp-name-parser.y doesn't
3932 know about lvalue/rvalue qualifiers yet. */
3933 with_params
= std::string (sym
) + " ( int ) &&";
3934 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3938 /* Check that the name matching algorithm for completion doesn't get
3939 confused with Latin1 'ÿ' / 0xff. */
3941 static const char str
[] = "\377";
3942 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3943 EXPECT ("\377", "\377\377123"));
3946 /* Check that the increment-last-char in the matching algorithm for
3947 completion doesn't match "t1_fund" when completing "t1_func". */
3949 static const char str
[] = "t1_func";
3950 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3951 EXPECT ("t1_func", "t1_func1"));
3954 /* Check that completion mode works at each prefix of the expected
3957 static const char str
[] = "function(int)";
3958 size_t len
= strlen (str
);
3961 for (size_t i
= 1; i
< len
; i
++)
3963 lookup
.assign (str
, i
);
3964 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3965 EXPECT ("function"));
3969 /* While "w" is a prefix of both components, the match function
3970 should still only be called once. */
3972 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
3974 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
3978 /* Same, with a "complicated" symbol. */
3980 static const char str
[] = Z_SYM_NAME
;
3981 size_t len
= strlen (str
);
3984 for (size_t i
= 1; i
< len
; i
++)
3986 lookup
.assign (str
, i
);
3987 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3988 EXPECT (Z_SYM_NAME
));
3992 /* In FULL mode, an incomplete symbol doesn't match. */
3994 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
3998 /* A complete symbol with parameters matches any overload, since the
3999 index has no overload info. */
4001 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4002 EXPECT ("std::zfunction", "std::zfunction2"));
4003 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4004 EXPECT ("std::zfunction", "std::zfunction2"));
4005 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4006 EXPECT ("std::zfunction", "std::zfunction2"));
4009 /* Check that whitespace is ignored appropriately. A symbol with a
4010 template argument list. */
4012 static const char expected
[] = "ns::foo<int>";
4013 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4015 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4019 /* Check that whitespace is ignored appropriately. A symbol with a
4020 template argument list that includes a pointer. */
4022 static const char expected
[] = "ns::foo<char*>";
4023 /* Try both completion and non-completion modes. */
4024 static const bool completion_mode
[2] = {false, true};
4025 for (size_t i
= 0; i
< 2; i
++)
4027 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4028 completion_mode
[i
], EXPECT (expected
));
4029 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4030 completion_mode
[i
], EXPECT (expected
));
4032 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4033 completion_mode
[i
], EXPECT (expected
));
4034 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4035 completion_mode
[i
], EXPECT (expected
));
4040 /* Check method qualifiers are ignored. */
4041 static const char expected
[] = "ns::foo<char*>";
4042 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4043 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4044 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4045 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4046 CHECK_MATCH ("foo < char * > ( int ) const",
4047 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4048 CHECK_MATCH ("foo < char * > ( int ) &&",
4049 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4052 /* Test lookup names that don't match anything. */
4054 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4057 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4061 /* Some wild matching tests, exercising "(anonymous namespace)",
4062 which should not be confused with a parameter list. */
4064 static const char *syms
[] = {
4068 "A :: B :: C ( int )",
4073 for (const char *s
: syms
)
4075 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4076 EXPECT ("(anonymous namespace)::A::B::C"));
4081 static const char expected
[] = "ns2::tmpl<int>::foo2";
4082 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4084 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4088 SELF_CHECK (!any_mismatch
);
4097 test_mapped_index_find_name_component_bounds ();
4098 test_dw2_expand_symtabs_matching_symbol ();
4101 }} // namespace selftests::dw2_expand_symtabs_matching
4103 #endif /* GDB_SELF_TEST */
4105 /* If FILE_MATCHER is NULL or if PER_CU has
4106 dwarf2_per_cu_quick_data::MARK set (see
4107 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4108 EXPANSION_NOTIFY on it. */
4111 dw2_expand_symtabs_matching_one
4112 (dwarf2_per_cu_data
*per_cu
,
4113 dwarf2_per_objfile
*per_objfile
,
4114 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4115 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4117 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4119 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4121 compunit_symtab
*symtab
4122 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4123 gdb_assert (symtab
!= nullptr);
4125 if (expansion_notify
!= NULL
&& symtab_was_null
)
4126 return expansion_notify (symtab
);
4131 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4132 matched, to expand corresponding CUs that were marked. IDX is the
4133 index of the symbol name that matched. */
4136 dw2_expand_marked_cus
4137 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4138 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4139 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4140 block_search_flags search_flags
,
4143 offset_type vec_len
, vec_idx
;
4144 bool global_seen
= false;
4145 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4147 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4149 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4151 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4152 /* This value is only valid for index versions >= 7. */
4153 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4154 gdb_index_symbol_kind symbol_kind
=
4155 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4156 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4157 /* Only check the symbol attributes if they're present.
4158 Indices prior to version 7 don't record them,
4159 and indices >= 7 may elide them for certain symbols
4160 (gold does this). */
4163 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4165 /* Work around gold/15646. */
4168 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4176 /* Only check the symbol's kind if it has one. */
4181 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4186 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4192 case VARIABLES_DOMAIN
:
4193 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4196 case FUNCTIONS_DOMAIN
:
4197 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4201 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4204 case MODULES_DOMAIN
:
4205 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4213 /* Don't crash on bad data. */
4214 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4216 complaint (_(".gdb_index entry has bad CU index"
4217 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4221 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4222 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4230 /* If FILE_MATCHER is non-NULL, set all the
4231 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4232 that match FILE_MATCHER. */
4235 dw_expand_symtabs_matching_file_matcher
4236 (dwarf2_per_objfile
*per_objfile
,
4237 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4239 if (file_matcher
== NULL
)
4242 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4244 NULL
, xcalloc
, xfree
));
4245 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4247 NULL
, xcalloc
, xfree
));
4249 /* The rule is CUs specify all the files, including those used by
4250 any TU, so there's no need to scan TUs here. */
4252 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4256 if (per_cu
->is_debug_types
)
4258 per_cu
->v
.quick
->mark
= 0;
4260 /* We only need to look at symtabs not already expanded. */
4261 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4264 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4266 if (file_data
== NULL
)
4269 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4271 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4273 per_cu
->v
.quick
->mark
= 1;
4277 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4279 const char *this_real_name
;
4281 if (file_matcher (file_data
->file_names
[j
], false))
4283 per_cu
->v
.quick
->mark
= 1;
4287 /* Before we invoke realpath, which can get expensive when many
4288 files are involved, do a quick comparison of the basenames. */
4289 if (!basenames_may_differ
4290 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4294 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4295 if (file_matcher (this_real_name
, false))
4297 per_cu
->v
.quick
->mark
= 1;
4302 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4303 ? visited_found
.get ()
4304 : visited_not_found
.get (),
4311 dwarf2_gdb_index::expand_symtabs_matching
4312 (struct objfile
*objfile
,
4313 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4314 const lookup_name_info
*lookup_name
,
4315 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4316 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4317 block_search_flags search_flags
,
4319 enum search_domain kind
)
4321 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4323 /* index_table is NULL if OBJF_READNOW. */
4324 if (!per_objfile
->per_bfd
->index_table
)
4327 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4329 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4331 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4335 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
4343 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4346 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4348 [&] (offset_type idx
)
4350 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4351 expansion_notify
, search_flags
, kind
))
4359 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4362 static struct compunit_symtab
*
4363 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4368 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4369 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4372 if (cust
->includes
== NULL
)
4375 for (i
= 0; cust
->includes
[i
]; ++i
)
4377 struct compunit_symtab
*s
= cust
->includes
[i
];
4379 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4387 struct compunit_symtab
*
4388 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4389 (struct objfile
*objfile
,
4390 struct bound_minimal_symbol msymbol
,
4392 struct obj_section
*section
,
4395 struct dwarf2_per_cu_data
*data
;
4396 struct compunit_symtab
*result
;
4398 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4399 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4402 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4403 data
= ((struct dwarf2_per_cu_data
*)
4404 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4409 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4410 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4411 paddress (objfile
->arch (), pc
));
4413 result
= recursively_find_pc_sect_compunit_symtab
4414 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4416 gdb_assert (result
!= NULL
);
4421 dwarf2_base_index_functions::map_symbol_filenames
4422 (struct objfile
*objfile
,
4423 gdb::function_view
<symbol_filename_ftype
> fun
,
4426 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4428 /* Use caches to ensure we only call FUN once for each filename. */
4429 filename_seen_cache filenames_cache
;
4430 std::unordered_set
<quick_file_names
*> qfn_cache
;
4432 /* The rule is CUs specify all the files, including those used by any TU,
4433 so there's no need to scan TUs here. We can ignore file names coming
4434 from already-expanded CUs. It is possible that an expanded CU might
4435 reuse the file names data from a currently unexpanded CU, in this
4436 case we don't want to report the files from the unexpanded CU. */
4438 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4440 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4442 if (per_cu
->v
.quick
->file_names
!= nullptr)
4443 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4447 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4449 /* We only need to look at symtabs not already expanded. */
4450 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4453 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4455 if (file_data
== nullptr
4456 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4459 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4461 const char *filename
= file_data
->file_names
[j
];
4462 filenames_cache
.seen (filename
);
4466 filenames_cache
.traverse ([&] (const char *filename
)
4468 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4471 this_real_name
= gdb_realpath (filename
);
4472 fun (filename
, this_real_name
.get ());
4477 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4482 /* DWARF-5 debug_names reader. */
4484 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4485 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4487 /* A helper function that reads the .debug_names section in SECTION
4488 and fills in MAP. FILENAME is the name of the file containing the
4489 section; it is used for error reporting.
4491 Returns true if all went well, false otherwise. */
4494 read_debug_names_from_section (struct objfile
*objfile
,
4495 const char *filename
,
4496 struct dwarf2_section_info
*section
,
4497 mapped_debug_names
&map
)
4499 if (section
->empty ())
4502 /* Older elfutils strip versions could keep the section in the main
4503 executable while splitting it for the separate debug info file. */
4504 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4507 section
->read (objfile
);
4509 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4511 const gdb_byte
*addr
= section
->buffer
;
4513 bfd
*const abfd
= section
->get_bfd_owner ();
4515 unsigned int bytes_read
;
4516 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4519 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4520 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4521 if (bytes_read
+ length
!= section
->size
)
4523 /* There may be multiple per-CU indices. */
4524 warning (_("Section .debug_names in %s length %s does not match "
4525 "section length %s, ignoring .debug_names."),
4526 filename
, plongest (bytes_read
+ length
),
4527 pulongest (section
->size
));
4531 /* The version number. */
4532 uint16_t version
= read_2_bytes (abfd
, addr
);
4536 warning (_("Section .debug_names in %s has unsupported version %d, "
4537 "ignoring .debug_names."),
4543 uint16_t padding
= read_2_bytes (abfd
, addr
);
4547 warning (_("Section .debug_names in %s has unsupported padding %d, "
4548 "ignoring .debug_names."),
4553 /* comp_unit_count - The number of CUs in the CU list. */
4554 map
.cu_count
= read_4_bytes (abfd
, addr
);
4557 /* local_type_unit_count - The number of TUs in the local TU
4559 map
.tu_count
= read_4_bytes (abfd
, addr
);
4562 /* foreign_type_unit_count - The number of TUs in the foreign TU
4564 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4566 if (foreign_tu_count
!= 0)
4568 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4569 "ignoring .debug_names."),
4570 filename
, static_cast<unsigned long> (foreign_tu_count
));
4574 /* bucket_count - The number of hash buckets in the hash lookup
4576 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4579 /* name_count - The number of unique names in the index. */
4580 map
.name_count
= read_4_bytes (abfd
, addr
);
4583 /* abbrev_table_size - The size in bytes of the abbreviations
4585 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4588 /* augmentation_string_size - The size in bytes of the augmentation
4589 string. This value is rounded up to a multiple of 4. */
4590 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4592 map
.augmentation_is_gdb
= ((augmentation_string_size
4593 == sizeof (dwarf5_augmentation
))
4594 && memcmp (addr
, dwarf5_augmentation
,
4595 sizeof (dwarf5_augmentation
)) == 0);
4596 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4597 addr
+= augmentation_string_size
;
4600 map
.cu_table_reordered
= addr
;
4601 addr
+= map
.cu_count
* map
.offset_size
;
4603 /* List of Local TUs */
4604 map
.tu_table_reordered
= addr
;
4605 addr
+= map
.tu_count
* map
.offset_size
;
4607 /* Hash Lookup Table */
4608 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4609 addr
+= map
.bucket_count
* 4;
4610 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4611 addr
+= map
.name_count
* 4;
4614 map
.name_table_string_offs_reordered
= addr
;
4615 addr
+= map
.name_count
* map
.offset_size
;
4616 map
.name_table_entry_offs_reordered
= addr
;
4617 addr
+= map
.name_count
* map
.offset_size
;
4619 const gdb_byte
*abbrev_table_start
= addr
;
4622 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4627 const auto insertpair
4628 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4629 if (!insertpair
.second
)
4631 warning (_("Section .debug_names in %s has duplicate index %s, "
4632 "ignoring .debug_names."),
4633 filename
, pulongest (index_num
));
4636 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4637 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4642 mapped_debug_names::index_val::attr attr
;
4643 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4645 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4647 if (attr
.form
== DW_FORM_implicit_const
)
4649 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4653 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4655 indexval
.attr_vec
.push_back (std::move (attr
));
4658 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4660 warning (_("Section .debug_names in %s has abbreviation_table "
4661 "of size %s vs. written as %u, ignoring .debug_names."),
4662 filename
, plongest (addr
- abbrev_table_start
),
4666 map
.entry_pool
= addr
;
4671 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4675 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4676 const mapped_debug_names
&map
,
4677 dwarf2_section_info
§ion
,
4680 if (!map
.augmentation_is_gdb
)
4682 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4684 sect_offset sect_off
4685 = (sect_offset
) (extract_unsigned_integer
4686 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4688 map
.dwarf5_byte_order
));
4689 /* We don't know the length of the CU, because the CU list in a
4690 .debug_names index can be incomplete, so we can't use the start
4691 of the next CU as end of this CU. We create the CUs here with
4692 length 0, and in cutu_reader::cutu_reader we'll fill in the
4694 dwarf2_per_cu_data_up per_cu
4695 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4697 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4702 sect_offset sect_off_prev
;
4703 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4705 sect_offset sect_off_next
;
4706 if (i
< map
.cu_count
)
4709 = (sect_offset
) (extract_unsigned_integer
4710 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4712 map
.dwarf5_byte_order
));
4715 sect_off_next
= (sect_offset
) section
.size
;
4718 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4719 dwarf2_per_cu_data_up per_cu
4720 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4721 sect_off_prev
, length
);
4722 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4724 sect_off_prev
= sect_off_next
;
4728 /* Read the CU list from the mapped index, and use it to create all
4729 the CU objects for this dwarf2_per_objfile. */
4732 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4733 const mapped_debug_names
&map
,
4734 const mapped_debug_names
&dwz_map
)
4736 gdb_assert (per_bfd
->all_comp_units
.empty ());
4737 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4739 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4740 false /* is_dwz */);
4742 if (dwz_map
.cu_count
== 0)
4745 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4746 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4750 /* Read .debug_names. If everything went ok, initialize the "quick"
4751 elements of all the CUs and return true. Otherwise, return false. */
4754 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4756 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4757 mapped_debug_names dwz_map
;
4758 struct objfile
*objfile
= per_objfile
->objfile
;
4759 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4761 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4762 &per_bfd
->debug_names
, *map
))
4765 /* Don't use the index if it's empty. */
4766 if (map
->name_count
== 0)
4769 /* If there is a .dwz file, read it so we can get its CU list as
4771 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4774 if (!read_debug_names_from_section (objfile
,
4775 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4776 &dwz
->debug_names
, dwz_map
))
4778 warning (_("could not read '.debug_names' section from %s; skipping"),
4779 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4784 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4786 if (map
->tu_count
!= 0)
4788 /* We can only handle a single .debug_types when we have an
4790 if (per_bfd
->types
.size () != 1)
4793 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4795 create_signatured_type_table_from_debug_names
4796 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4799 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4801 per_bfd
->debug_names_table
= std::move (map
);
4802 per_bfd
->using_index
= 1;
4803 per_bfd
->quick_file_names_table
=
4804 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4809 /* Type used to manage iterating over all CUs looking for a symbol for
4812 class dw2_debug_names_iterator
4815 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4816 block_search_flags block_index
,
4818 const char *name
, dwarf2_per_objfile
*per_objfile
)
4819 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4820 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4821 m_per_objfile (per_objfile
)
4824 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4825 search_domain search
, uint32_t namei
,
4826 dwarf2_per_objfile
*per_objfile
,
4827 domain_enum domain
= UNDEF_DOMAIN
)
4831 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4832 m_per_objfile (per_objfile
)
4835 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4836 block_search_flags block_index
, domain_enum domain
,
4837 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4838 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4839 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4840 m_per_objfile (per_objfile
)
4843 /* Return the next matching CU or NULL if there are no more. */
4844 dwarf2_per_cu_data
*next ();
4847 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4849 dwarf2_per_objfile
*per_objfile
);
4850 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4852 dwarf2_per_objfile
*per_objfile
);
4854 /* The internalized form of .debug_names. */
4855 const mapped_debug_names
&m_map
;
4857 /* Restrict the search to these blocks. */
4858 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4859 | SEARCH_STATIC_BLOCK
);
4861 /* The kind of symbol we're looking for. */
4862 const domain_enum m_domain
= UNDEF_DOMAIN
;
4863 const search_domain m_search
= ALL_DOMAIN
;
4865 /* The list of CUs from the index entry of the symbol, or NULL if
4867 const gdb_byte
*m_addr
;
4869 dwarf2_per_objfile
*m_per_objfile
;
4873 mapped_debug_names::namei_to_name
4874 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4876 const ULONGEST namei_string_offs
4877 = extract_unsigned_integer ((name_table_string_offs_reordered
4878 + namei
* offset_size
),
4881 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4884 /* Find a slot in .debug_names for the object named NAME. If NAME is
4885 found, return pointer to its pool data. If NAME cannot be found,
4889 dw2_debug_names_iterator::find_vec_in_debug_names
4890 (const mapped_debug_names
&map
, const char *name
,
4891 dwarf2_per_objfile
*per_objfile
)
4893 int (*cmp
) (const char *, const char *);
4895 gdb::unique_xmalloc_ptr
<char> without_params
;
4896 if (current_language
->la_language
== language_cplus
4897 || current_language
->la_language
== language_fortran
4898 || current_language
->la_language
== language_d
)
4900 /* NAME is already canonical. Drop any qualifiers as
4901 .debug_names does not contain any. */
4903 if (strchr (name
, '(') != NULL
)
4905 without_params
= cp_remove_params (name
);
4906 if (without_params
!= NULL
)
4907 name
= without_params
.get ();
4911 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
4913 const uint32_t full_hash
= dwarf5_djb_hash (name
);
4915 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4916 (map
.bucket_table_reordered
4917 + (full_hash
% map
.bucket_count
)), 4,
4918 map
.dwarf5_byte_order
);
4922 if (namei
>= map
.name_count
)
4924 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4926 namei
, map
.name_count
,
4927 objfile_name (per_objfile
->objfile
));
4933 const uint32_t namei_full_hash
4934 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4935 (map
.hash_table_reordered
+ namei
), 4,
4936 map
.dwarf5_byte_order
);
4937 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
4940 if (full_hash
== namei_full_hash
)
4942 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
4944 #if 0 /* An expensive sanity check. */
4945 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
4947 complaint (_("Wrong .debug_names hash for string at index %u "
4949 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
4954 if (cmp (namei_string
, name
) == 0)
4956 const ULONGEST namei_entry_offs
4957 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4958 + namei
* map
.offset_size
),
4959 map
.offset_size
, map
.dwarf5_byte_order
);
4960 return map
.entry_pool
+ namei_entry_offs
;
4965 if (namei
>= map
.name_count
)
4971 dw2_debug_names_iterator::find_vec_in_debug_names
4972 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4974 if (namei
>= map
.name_count
)
4976 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4978 namei
, map
.name_count
,
4979 objfile_name (per_objfile
->objfile
));
4983 const ULONGEST namei_entry_offs
4984 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4985 + namei
* map
.offset_size
),
4986 map
.offset_size
, map
.dwarf5_byte_order
);
4987 return map
.entry_pool
+ namei_entry_offs
;
4990 /* See dw2_debug_names_iterator. */
4992 dwarf2_per_cu_data
*
4993 dw2_debug_names_iterator::next ()
4998 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
4999 struct objfile
*objfile
= m_per_objfile
->objfile
;
5000 bfd
*const abfd
= objfile
->obfd
;
5004 unsigned int bytes_read
;
5005 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5006 m_addr
+= bytes_read
;
5010 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5011 if (indexval_it
== m_map
.abbrev_map
.cend ())
5013 complaint (_("Wrong .debug_names undefined abbrev code %s "
5015 pulongest (abbrev
), objfile_name (objfile
));
5018 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5019 enum class symbol_linkage
{
5023 } symbol_linkage_
= symbol_linkage::unknown
;
5024 dwarf2_per_cu_data
*per_cu
= NULL
;
5025 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5030 case DW_FORM_implicit_const
:
5031 ull
= attr
.implicit_const
;
5033 case DW_FORM_flag_present
:
5037 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5038 m_addr
+= bytes_read
;
5041 ull
= read_4_bytes (abfd
, m_addr
);
5045 ull
= read_8_bytes (abfd
, m_addr
);
5048 case DW_FORM_ref_sig8
:
5049 ull
= read_8_bytes (abfd
, m_addr
);
5053 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5054 dwarf_form_name (attr
.form
),
5055 objfile_name (objfile
));
5058 switch (attr
.dw_idx
)
5060 case DW_IDX_compile_unit
:
5061 /* Don't crash on bad data. */
5062 if (ull
>= per_bfd
->all_comp_units
.size ())
5064 complaint (_(".debug_names entry has bad CU index %s"
5067 objfile_name (objfile
));
5070 per_cu
= per_bfd
->get_cu (ull
);
5072 case DW_IDX_type_unit
:
5073 /* Don't crash on bad data. */
5074 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5076 complaint (_(".debug_names entry has bad TU index %s"
5079 objfile_name (objfile
));
5082 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5084 case DW_IDX_die_offset
:
5085 /* In a per-CU index (as opposed to a per-module index), index
5086 entries without CU attribute implicitly refer to the single CU. */
5088 per_cu
= per_bfd
->get_cu (0);
5090 case DW_IDX_GNU_internal
:
5091 if (!m_map
.augmentation_is_gdb
)
5093 symbol_linkage_
= symbol_linkage::static_
;
5095 case DW_IDX_GNU_external
:
5096 if (!m_map
.augmentation_is_gdb
)
5098 symbol_linkage_
= symbol_linkage::extern_
;
5103 /* Skip if already read in. */
5104 if (m_per_objfile
->symtab_set_p (per_cu
))
5107 /* Check static vs global. */
5108 if (symbol_linkage_
!= symbol_linkage::unknown
)
5110 if (symbol_linkage_
== symbol_linkage::static_
)
5112 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5117 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5122 /* Match dw2_symtab_iter_next, symbol_kind
5123 and debug_names::psymbol_tag. */
5127 switch (indexval
.dwarf_tag
)
5129 case DW_TAG_variable
:
5130 case DW_TAG_subprogram
:
5131 /* Some types are also in VAR_DOMAIN. */
5132 case DW_TAG_typedef
:
5133 case DW_TAG_structure_type
:
5140 switch (indexval
.dwarf_tag
)
5142 case DW_TAG_typedef
:
5143 case DW_TAG_structure_type
:
5150 switch (indexval
.dwarf_tag
)
5153 case DW_TAG_variable
:
5160 switch (indexval
.dwarf_tag
)
5172 /* Match dw2_expand_symtabs_matching, symbol_kind and
5173 debug_names::psymbol_tag. */
5176 case VARIABLES_DOMAIN
:
5177 switch (indexval
.dwarf_tag
)
5179 case DW_TAG_variable
:
5185 case FUNCTIONS_DOMAIN
:
5186 switch (indexval
.dwarf_tag
)
5188 case DW_TAG_subprogram
:
5195 switch (indexval
.dwarf_tag
)
5197 case DW_TAG_typedef
:
5198 case DW_TAG_structure_type
:
5204 case MODULES_DOMAIN
:
5205 switch (indexval
.dwarf_tag
)
5219 /* This dumps minimal information about .debug_names. It is called
5220 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5221 uses this to verify that .debug_names has been loaded. */
5224 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5226 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5228 gdb_assert (per_objfile
->per_bfd
->using_index
);
5229 printf_filtered (".debug_names:");
5230 if (per_objfile
->per_bfd
->debug_names_table
)
5231 printf_filtered (" exists\n");
5233 printf_filtered (" faked for \"readnow\"\n");
5234 printf_filtered ("\n");
5238 dwarf2_debug_names_index::expand_matching_symbols
5239 (struct objfile
*objfile
,
5240 const lookup_name_info
&name
, domain_enum domain
,
5242 symbol_compare_ftype
*ordered_compare
)
5244 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5246 /* debug_names_table is NULL if OBJF_READNOW. */
5247 if (!per_objfile
->per_bfd
->debug_names_table
)
5250 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5251 const block_search_flags block_flags
5252 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5254 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5255 auto matcher
= [&] (const char *symname
)
5257 if (ordered_compare
== nullptr)
5259 return ordered_compare (symname
, match_name
) == 0;
5262 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5263 [&] (offset_type namei
)
5265 /* The name was matched, now expand corresponding CUs that were
5267 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5270 struct dwarf2_per_cu_data
*per_cu
;
5271 while ((per_cu
= iter
.next ()) != NULL
)
5272 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5279 dwarf2_debug_names_index::expand_symtabs_matching
5280 (struct objfile
*objfile
,
5281 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5282 const lookup_name_info
*lookup_name
,
5283 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5284 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5285 block_search_flags search_flags
,
5287 enum search_domain kind
)
5289 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5291 /* debug_names_table is NULL if OBJF_READNOW. */
5292 if (!per_objfile
->per_bfd
->debug_names_table
)
5295 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5297 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5299 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5303 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
5311 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5314 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5316 [&] (offset_type namei
)
5318 /* The name was matched, now expand corresponding CUs that were
5320 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5322 struct dwarf2_per_cu_data
*per_cu
;
5323 while ((per_cu
= iter
.next ()) != NULL
)
5324 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5334 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5335 to either a dwarf2_per_bfd or dwz_file object. */
5337 template <typename T
>
5338 static gdb::array_view
<const gdb_byte
>
5339 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5341 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5343 if (section
->empty ())
5346 /* Older elfutils strip versions could keep the section in the main
5347 executable while splitting it for the separate debug info file. */
5348 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5351 section
->read (obj
);
5353 /* dwarf2_section_info::size is a bfd_size_type, while
5354 gdb::array_view works with size_t. On 32-bit hosts, with
5355 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5356 is 32-bit. So we need an explicit narrowing conversion here.
5357 This is fine, because it's impossible to allocate or mmap an
5358 array/buffer larger than what size_t can represent. */
5359 return gdb::make_array_view (section
->buffer
, section
->size
);
5362 /* Lookup the index cache for the contents of the index associated to
5365 static gdb::array_view
<const gdb_byte
>
5366 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5368 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5369 if (build_id
== nullptr)
5372 return global_index_cache
.lookup_gdb_index (build_id
,
5373 &dwarf2_per_bfd
->index_cache_res
);
5376 /* Same as the above, but for DWZ. */
5378 static gdb::array_view
<const gdb_byte
>
5379 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5381 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5382 if (build_id
== nullptr)
5385 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5388 /* See dwarf2/public.h. */
5391 dwarf2_initialize_objfile (struct objfile
*objfile
)
5393 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5394 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5396 dwarf_read_debug_printf ("called");
5398 /* If we're about to read full symbols, don't bother with the
5399 indices. In this case we also don't care if some other debug
5400 format is making psymtabs, because they are all about to be
5402 if ((objfile
->flags
& OBJF_READNOW
))
5404 dwarf_read_debug_printf ("readnow requested");
5406 /* When using READNOW, the using_index flag (set below) indicates that
5407 PER_BFD was already initialized, when we loaded some other objfile. */
5408 if (per_bfd
->using_index
)
5410 dwarf_read_debug_printf ("using_index already set");
5411 per_objfile
->resize_symtabs ();
5412 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5416 per_bfd
->using_index
= 1;
5417 create_all_comp_units (per_objfile
);
5418 per_bfd
->quick_file_names_table
5419 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5420 per_objfile
->resize_symtabs ();
5422 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5424 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5426 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5427 struct dwarf2_per_cu_quick_data
);
5430 /* Arrange for gdb to see the "quick" functions. However, these
5431 functions will be no-ops because we will have expanded all
5433 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5437 /* Was a debug names index already read when we processed an objfile sharing
5439 if (per_bfd
->debug_names_table
!= nullptr)
5441 dwarf_read_debug_printf ("re-using shared debug names table");
5442 per_objfile
->resize_symtabs ();
5443 objfile
->qf
.push_front (make_dwarf_debug_names ());
5447 /* Was a GDB index already read when we processed an objfile sharing
5449 if (per_bfd
->index_table
!= nullptr)
5451 dwarf_read_debug_printf ("re-using shared index table");
5452 per_objfile
->resize_symtabs ();
5453 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5457 /* There might already be partial symtabs built for this BFD. This happens
5458 when loading the same binary twice with the index-cache enabled. If so,
5459 don't try to read an index. The objfile / per_objfile initialization will
5460 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5462 if (per_bfd
->partial_symtabs
!= nullptr)
5464 dwarf_read_debug_printf ("re-using shared partial symtabs");
5465 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5469 if (dwarf2_read_debug_names (per_objfile
))
5471 dwarf_read_debug_printf ("found debug names");
5472 per_objfile
->resize_symtabs ();
5473 objfile
->qf
.push_front (make_dwarf_debug_names ());
5477 if (dwarf2_read_gdb_index (per_objfile
,
5478 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5479 get_gdb_index_contents_from_section
<dwz_file
>))
5481 dwarf_read_debug_printf ("found gdb index from file");
5482 per_objfile
->resize_symtabs ();
5483 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5487 /* ... otherwise, try to find the index in the index cache. */
5488 if (dwarf2_read_gdb_index (per_objfile
,
5489 get_gdb_index_contents_from_cache
,
5490 get_gdb_index_contents_from_cache_dwz
))
5492 dwarf_read_debug_printf ("found gdb index from cache");
5493 global_index_cache
.hit ();
5494 per_objfile
->resize_symtabs ();
5495 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5499 global_index_cache
.miss ();
5500 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5505 /* Build a partial symbol table. */
5508 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5510 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5511 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5513 if (per_bfd
->partial_symtabs
!= nullptr)
5515 /* Partial symbols were already read, so now we can simply
5519 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5520 objfile
->qf
.emplace_front (psf
);
5523 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5524 per_objfile
->resize_symtabs ();
5530 psf
= new psymbol_functions
;
5531 objfile
->qf
.emplace_front (psf
);
5533 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5534 = psf
->get_partial_symtabs ();
5536 /* Set the local reference to partial symtabs, so that we don't try
5537 to read them again if reading another objfile with the same BFD.
5538 If we can't in fact share, this won't make a difference anyway as
5539 the dwarf2_per_bfd object won't be shared. */
5540 per_bfd
->partial_symtabs
= partial_symtabs
;
5544 /* This isn't really ideal: all the data we allocate on the
5545 objfile's obstack is still uselessly kept around. However,
5546 freeing it seems unsafe. */
5547 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5548 dwarf2_build_psymtabs_hard (per_objfile
);
5551 per_objfile
->resize_symtabs ();
5553 /* (maybe) store an index in the cache. */
5554 global_index_cache
.store (per_objfile
);
5556 catch (const gdb_exception_error
&except
)
5558 exception_print (gdb_stderr
, except
);
5562 /* Find the base address of the compilation unit for range lists and
5563 location lists. It will normally be specified by DW_AT_low_pc.
5564 In DWARF-3 draft 4, the base address could be overridden by
5565 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5566 compilation units with discontinuous ranges. */
5569 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5571 struct attribute
*attr
;
5573 cu
->base_address
.reset ();
5575 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5576 if (attr
!= nullptr)
5577 cu
->base_address
= attr
->as_address ();
5580 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5581 if (attr
!= nullptr)
5582 cu
->base_address
= attr
->as_address ();
5586 /* Helper function that returns the proper abbrev section for
5589 static struct dwarf2_section_info
*
5590 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5592 struct dwarf2_section_info
*abbrev
;
5593 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5595 if (this_cu
->is_dwz
)
5596 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5598 abbrev
= &per_bfd
->abbrev
;
5603 /* Fetch the abbreviation table offset from a comp or type unit header. */
5606 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5607 struct dwarf2_section_info
*section
,
5608 sect_offset sect_off
)
5610 bfd
*abfd
= section
->get_bfd_owner ();
5611 const gdb_byte
*info_ptr
;
5612 unsigned int initial_length_size
, offset_size
;
5615 section
->read (per_objfile
->objfile
);
5616 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5617 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5618 offset_size
= initial_length_size
== 4 ? 4 : 8;
5619 info_ptr
+= initial_length_size
;
5621 version
= read_2_bytes (abfd
, info_ptr
);
5625 /* Skip unit type and address size. */
5629 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5632 /* A partial symtab that is used only for include files. */
5633 struct dwarf2_include_psymtab
: public partial_symtab
5635 dwarf2_include_psymtab (const char *filename
,
5636 psymtab_storage
*partial_symtabs
,
5637 objfile_per_bfd_storage
*objfile_per_bfd
)
5638 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5642 void read_symtab (struct objfile
*objfile
) override
5644 /* It's an include file, no symbols to read for it.
5645 Everything is in the includer symtab. */
5647 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5648 expansion of the includer psymtab. We use the dependencies[0] field to
5649 model the includer. But if we go the regular route of calling
5650 expand_psymtab here, and having expand_psymtab call expand_dependencies
5651 to expand the includer, we'll only use expand_psymtab on the includer
5652 (making it a non-toplevel psymtab), while if we expand the includer via
5653 another path, we'll use read_symtab (making it a toplevel psymtab).
5654 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5655 psymtab, and trigger read_symtab on the includer here directly. */
5656 includer ()->read_symtab (objfile
);
5659 void expand_psymtab (struct objfile
*objfile
) override
5661 /* This is not called by read_symtab, and should not be called by any
5662 expand_dependencies. */
5666 bool readin_p (struct objfile
*objfile
) const override
5668 return includer ()->readin_p (objfile
);
5671 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5677 partial_symtab
*includer () const
5679 /* An include psymtab has exactly one dependency: the psymtab that
5681 gdb_assert (this->number_of_dependencies
== 1);
5682 return this->dependencies
[0];
5686 /* Allocate a new partial symtab for file named NAME and mark this new
5687 partial symtab as being an include of PST. */
5690 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5692 dwarf2_psymtab
*pst
,
5693 psymtab_storage
*partial_symtabs
,
5694 objfile_per_bfd_storage
*objfile_per_bfd
)
5696 dwarf2_include_psymtab
*subpst
5697 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5699 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5700 subpst
->dirname
= pst
->dirname
;
5702 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5703 subpst
->dependencies
[0] = pst
;
5704 subpst
->number_of_dependencies
= 1;
5707 /* Read the Line Number Program data and extract the list of files
5708 included by the source file represented by PST. Build an include
5709 partial symtab for each of these included files. */
5712 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5713 struct die_info
*die
,
5714 dwarf2_psymtab
*pst
)
5717 struct attribute
*attr
;
5719 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5720 if (attr
!= nullptr && attr
->form_is_unsigned ())
5721 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5723 return; /* No linetable, so no includes. */
5725 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5726 that we pass in the raw text_low here; that is ok because we're
5727 only decoding the line table to make include partial symtabs, and
5728 so the addresses aren't really used. */
5729 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5730 pst
->raw_text_low (), 1);
5734 hash_signatured_type (const void *item
)
5736 const struct signatured_type
*sig_type
5737 = (const struct signatured_type
*) item
;
5739 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5740 return sig_type
->signature
;
5744 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5746 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5747 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5749 return lhs
->signature
== rhs
->signature
;
5752 /* Allocate a hash table for signatured types. */
5755 allocate_signatured_type_table ()
5757 return htab_up (htab_create_alloc (41,
5758 hash_signatured_type
,
5760 NULL
, xcalloc
, xfree
));
5763 /* A helper for create_debug_types_hash_table. Read types from SECTION
5764 and fill them into TYPES_HTAB. It will process only type units,
5765 therefore DW_UT_type. */
5768 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5769 struct dwo_file
*dwo_file
,
5770 dwarf2_section_info
*section
, htab_up
&types_htab
,
5771 rcuh_kind section_kind
)
5773 struct objfile
*objfile
= per_objfile
->objfile
;
5774 struct dwarf2_section_info
*abbrev_section
;
5776 const gdb_byte
*info_ptr
, *end_ptr
;
5778 abbrev_section
= &dwo_file
->sections
.abbrev
;
5780 dwarf_read_debug_printf ("Reading %s for %s",
5781 section
->get_name (),
5782 abbrev_section
->get_file_name ());
5784 section
->read (objfile
);
5785 info_ptr
= section
->buffer
;
5787 if (info_ptr
== NULL
)
5790 /* We can't set abfd until now because the section may be empty or
5791 not present, in which case the bfd is unknown. */
5792 abfd
= section
->get_bfd_owner ();
5794 /* We don't use cutu_reader here because we don't need to read
5795 any dies: the signature is in the header. */
5797 end_ptr
= info_ptr
+ section
->size
;
5798 while (info_ptr
< end_ptr
)
5800 std::unique_ptr
<signatured_type
> sig_type
;
5801 struct dwo_unit
*dwo_tu
;
5803 const gdb_byte
*ptr
= info_ptr
;
5804 struct comp_unit_head header
;
5805 unsigned int length
;
5807 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5809 /* Initialize it due to a false compiler warning. */
5810 header
.signature
= -1;
5811 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5813 /* We need to read the type's signature in order to build the hash
5814 table, but we don't need anything else just yet. */
5816 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5817 abbrev_section
, ptr
, section_kind
);
5819 length
= header
.get_length ();
5821 /* Skip dummy type units. */
5822 if (ptr
>= info_ptr
+ length
5823 || peek_abbrev_code (abfd
, ptr
) == 0
5824 || (header
.unit_type
!= DW_UT_type
5825 && header
.unit_type
!= DW_UT_split_type
))
5831 if (types_htab
== NULL
)
5832 types_htab
= allocate_dwo_unit_table ();
5834 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5835 dwo_tu
->dwo_file
= dwo_file
;
5836 dwo_tu
->signature
= header
.signature
;
5837 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5838 dwo_tu
->section
= section
;
5839 dwo_tu
->sect_off
= sect_off
;
5840 dwo_tu
->length
= length
;
5842 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5843 gdb_assert (slot
!= NULL
);
5845 complaint (_("debug type entry at offset %s is duplicate to"
5846 " the entry at offset %s, signature %s"),
5847 sect_offset_str (sect_off
),
5848 sect_offset_str (dwo_tu
->sect_off
),
5849 hex_string (header
.signature
));
5852 dwarf_read_debug_printf_v (" offset %s, signature %s",
5853 sect_offset_str (sect_off
),
5854 hex_string (header
.signature
));
5860 /* Create the hash table of all entries in the .debug_types
5861 (or .debug_types.dwo) section(s).
5862 DWO_FILE is a pointer to the DWO file object.
5864 The result is a pointer to the hash table or NULL if there are no types.
5866 Note: This function processes DWO files only, not DWP files. */
5869 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5870 struct dwo_file
*dwo_file
,
5871 gdb::array_view
<dwarf2_section_info
> type_sections
,
5872 htab_up
&types_htab
)
5874 for (dwarf2_section_info
§ion
: type_sections
)
5875 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5879 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5880 If SLOT is non-NULL, it is the entry to use in the hash table.
5881 Otherwise we find one. */
5883 static struct signatured_type
*
5884 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5886 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5887 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5888 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5890 std::unique_ptr
<signatured_type
> sig_type_holder
5891 = per_objfile
->per_bfd
->allocate_signatured_type ();
5892 signatured_type
*sig_type
= sig_type_holder
.get ();
5894 per_objfile
->resize_symtabs ();
5896 per_objfile
->per_bfd
->all_comp_units
.emplace_back
5897 (sig_type_holder
.release ());
5898 sig_type
->signature
= sig
;
5899 sig_type
->is_debug_types
= 1;
5900 if (per_objfile
->per_bfd
->using_index
)
5903 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
5904 struct dwarf2_per_cu_quick_data
);
5909 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5912 gdb_assert (*slot
== NULL
);
5914 /* The rest of sig_type must be filled in by the caller. */
5918 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5919 Fill in SIG_ENTRY with DWO_ENTRY. */
5922 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
5923 struct signatured_type
*sig_entry
,
5924 struct dwo_unit
*dwo_entry
)
5926 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5928 /* Make sure we're not clobbering something we don't expect to. */
5929 gdb_assert (! sig_entry
->queued
);
5930 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
5931 if (per_bfd
->using_index
)
5933 gdb_assert (sig_entry
->v
.quick
!= NULL
);
5934 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
5937 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
5938 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5939 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5940 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5941 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5943 sig_entry
->section
= dwo_entry
->section
;
5944 sig_entry
->sect_off
= dwo_entry
->sect_off
;
5945 sig_entry
->length
= dwo_entry
->length
;
5946 sig_entry
->reading_dwo_directly
= 1;
5947 sig_entry
->per_bfd
= per_bfd
;
5948 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5949 sig_entry
->dwo_unit
= dwo_entry
;
5952 /* Subroutine of lookup_signatured_type.
5953 If we haven't read the TU yet, create the signatured_type data structure
5954 for a TU to be read in directly from a DWO file, bypassing the stub.
5955 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5956 using .gdb_index, then when reading a CU we want to stay in the DWO file
5957 containing that CU. Otherwise we could end up reading several other DWO
5958 files (due to comdat folding) to process the transitive closure of all the
5959 mentioned TUs, and that can be slow. The current DWO file will have every
5960 type signature that it needs.
5961 We only do this for .gdb_index because in the psymtab case we already have
5962 to read all the DWOs to build the type unit groups. */
5964 static struct signatured_type
*
5965 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5967 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5968 struct dwo_file
*dwo_file
;
5969 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5970 struct signatured_type find_sig_entry
, *sig_entry
;
5973 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
5975 /* If TU skeletons have been removed then we may not have read in any
5977 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5978 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
5980 /* We only ever need to read in one copy of a signatured type.
5981 Use the global signatured_types array to do our own comdat-folding
5982 of types. If this is the first time we're reading this TU, and
5983 the TU has an entry in .gdb_index, replace the recorded data from
5984 .gdb_index with this TU. */
5986 find_sig_entry
.signature
= sig
;
5987 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5988 &find_sig_entry
, INSERT
);
5989 sig_entry
= (struct signatured_type
*) *slot
;
5991 /* We can get here with the TU already read, *or* in the process of being
5992 read. Don't reassign the global entry to point to this DWO if that's
5993 the case. Also note that if the TU is already being read, it may not
5994 have come from a DWO, the program may be a mix of Fission-compiled
5995 code and non-Fission-compiled code. */
5997 /* Have we already tried to read this TU?
5998 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5999 needn't exist in the global table yet). */
6000 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6003 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6004 dwo_unit of the TU itself. */
6005 dwo_file
= cu
->dwo_unit
->dwo_file
;
6007 /* Ok, this is the first time we're reading this TU. */
6008 if (dwo_file
->tus
== NULL
)
6010 find_dwo_entry
.signature
= sig
;
6011 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6013 if (dwo_entry
== NULL
)
6016 /* If the global table doesn't have an entry for this TU, add one. */
6017 if (sig_entry
== NULL
)
6018 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6020 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6021 sig_entry
->tu_read
= 1;
6025 /* Subroutine of lookup_signatured_type.
6026 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6027 then try the DWP file. If the TU stub (skeleton) has been removed then
6028 it won't be in .gdb_index. */
6030 static struct signatured_type
*
6031 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6033 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6034 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6035 struct dwo_unit
*dwo_entry
;
6036 struct signatured_type find_sig_entry
, *sig_entry
;
6039 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6040 gdb_assert (dwp_file
!= NULL
);
6042 /* If TU skeletons have been removed then we may not have read in any
6044 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6045 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6047 find_sig_entry
.signature
= sig
;
6048 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6049 &find_sig_entry
, INSERT
);
6050 sig_entry
= (struct signatured_type
*) *slot
;
6052 /* Have we already tried to read this TU?
6053 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6054 needn't exist in the global table yet). */
6055 if (sig_entry
!= NULL
)
6058 if (dwp_file
->tus
== NULL
)
6060 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6061 1 /* is_debug_types */);
6062 if (dwo_entry
== NULL
)
6065 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6066 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6071 /* Lookup a signature based type for DW_FORM_ref_sig8.
6072 Returns NULL if signature SIG is not present in the table.
6073 It is up to the caller to complain about this. */
6075 static struct signatured_type
*
6076 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6078 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6080 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6082 /* We're in a DWO/DWP file, and we're using .gdb_index.
6083 These cases require special processing. */
6084 if (get_dwp_file (per_objfile
) == NULL
)
6085 return lookup_dwo_signatured_type (cu
, sig
);
6087 return lookup_dwp_signatured_type (cu
, sig
);
6091 struct signatured_type find_entry
, *entry
;
6093 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6095 find_entry
.signature
= sig
;
6096 entry
= ((struct signatured_type
*)
6097 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6103 /* Low level DIE reading support. */
6105 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6108 init_cu_die_reader (struct die_reader_specs
*reader
,
6109 struct dwarf2_cu
*cu
,
6110 struct dwarf2_section_info
*section
,
6111 struct dwo_file
*dwo_file
,
6112 struct abbrev_table
*abbrev_table
)
6114 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6115 reader
->abfd
= section
->get_bfd_owner ();
6117 reader
->dwo_file
= dwo_file
;
6118 reader
->die_section
= section
;
6119 reader
->buffer
= section
->buffer
;
6120 reader
->buffer_end
= section
->buffer
+ section
->size
;
6121 reader
->abbrev_table
= abbrev_table
;
6124 /* Subroutine of cutu_reader to simplify it.
6125 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6126 There's just a lot of work to do, and cutu_reader is big enough
6129 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6130 from it to the DIE in the DWO. If NULL we are skipping the stub.
6131 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6132 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6133 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6134 STUB_COMP_DIR may be non-NULL.
6135 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6136 are filled in with the info of the DIE from the DWO file.
6137 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6138 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6139 kept around for at least as long as *RESULT_READER.
6141 The result is non-zero if a valid (non-dummy) DIE was found. */
6144 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6145 struct dwo_unit
*dwo_unit
,
6146 struct die_info
*stub_comp_unit_die
,
6147 const char *stub_comp_dir
,
6148 struct die_reader_specs
*result_reader
,
6149 const gdb_byte
**result_info_ptr
,
6150 struct die_info
**result_comp_unit_die
,
6151 abbrev_table_up
*result_dwo_abbrev_table
)
6153 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6154 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6155 struct objfile
*objfile
= per_objfile
->objfile
;
6157 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6158 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6159 int i
,num_extra_attrs
;
6160 struct dwarf2_section_info
*dwo_abbrev_section
;
6161 struct die_info
*comp_unit_die
;
6163 /* At most one of these may be provided. */
6164 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6166 /* These attributes aren't processed until later:
6167 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6168 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6169 referenced later. However, these attributes are found in the stub
6170 which we won't have later. In order to not impose this complication
6171 on the rest of the code, we read them here and copy them to the
6180 if (stub_comp_unit_die
!= NULL
)
6182 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6184 if (!per_cu
->is_debug_types
)
6185 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6186 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6187 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6188 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6189 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6191 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6193 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6194 We need the value before we can process DW_AT_ranges values from the
6196 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6198 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6199 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6200 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6201 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6203 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6205 else if (stub_comp_dir
!= NULL
)
6207 /* Reconstruct the comp_dir attribute to simplify the code below. */
6208 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6209 comp_dir
->name
= DW_AT_comp_dir
;
6210 comp_dir
->form
= DW_FORM_string
;
6211 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6214 /* Set up for reading the DWO CU/TU. */
6215 cu
->dwo_unit
= dwo_unit
;
6216 dwarf2_section_info
*section
= dwo_unit
->section
;
6217 section
->read (objfile
);
6218 abfd
= section
->get_bfd_owner ();
6219 begin_info_ptr
= info_ptr
= (section
->buffer
6220 + to_underlying (dwo_unit
->sect_off
));
6221 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6223 if (per_cu
->is_debug_types
)
6225 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6227 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6228 section
, dwo_abbrev_section
,
6229 info_ptr
, rcuh_kind::TYPE
);
6230 /* This is not an assert because it can be caused by bad debug info. */
6231 if (sig_type
->signature
!= cu
->header
.signature
)
6233 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6234 " TU at offset %s [in module %s]"),
6235 hex_string (sig_type
->signature
),
6236 hex_string (cu
->header
.signature
),
6237 sect_offset_str (dwo_unit
->sect_off
),
6238 bfd_get_filename (abfd
));
6240 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6241 /* For DWOs coming from DWP files, we don't know the CU length
6242 nor the type's offset in the TU until now. */
6243 dwo_unit
->length
= cu
->header
.get_length ();
6244 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6246 /* Establish the type offset that can be used to lookup the type.
6247 For DWO files, we don't know it until now. */
6248 sig_type
->type_offset_in_section
6249 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6253 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6254 section
, dwo_abbrev_section
,
6255 info_ptr
, rcuh_kind::COMPILE
);
6256 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6257 /* For DWOs coming from DWP files, we don't know the CU length
6259 dwo_unit
->length
= cu
->header
.get_length ();
6262 dwo_abbrev_section
->read (objfile
);
6263 *result_dwo_abbrev_table
6264 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6265 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6266 result_dwo_abbrev_table
->get ());
6268 /* Read in the die, but leave space to copy over the attributes
6269 from the stub. This has the benefit of simplifying the rest of
6270 the code - all the work to maintain the illusion of a single
6271 DW_TAG_{compile,type}_unit DIE is done here. */
6272 num_extra_attrs
= ((stmt_list
!= NULL
)
6276 + (comp_dir
!= NULL
));
6277 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6280 /* Copy over the attributes from the stub to the DIE we just read in. */
6281 comp_unit_die
= *result_comp_unit_die
;
6282 i
= comp_unit_die
->num_attrs
;
6283 if (stmt_list
!= NULL
)
6284 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6286 comp_unit_die
->attrs
[i
++] = *low_pc
;
6287 if (high_pc
!= NULL
)
6288 comp_unit_die
->attrs
[i
++] = *high_pc
;
6290 comp_unit_die
->attrs
[i
++] = *ranges
;
6291 if (comp_dir
!= NULL
)
6292 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6293 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6295 if (dwarf_die_debug
)
6297 fprintf_unfiltered (gdb_stdlog
,
6298 "Read die from %s@0x%x of %s:\n",
6299 section
->get_name (),
6300 (unsigned) (begin_info_ptr
- section
->buffer
),
6301 bfd_get_filename (abfd
));
6302 dump_die (comp_unit_die
, dwarf_die_debug
);
6305 /* Skip dummy compilation units. */
6306 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6307 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6310 *result_info_ptr
= info_ptr
;
6314 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6315 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6316 signature is part of the header. */
6317 static gdb::optional
<ULONGEST
>
6318 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6320 if (cu
->header
.version
>= 5)
6321 return cu
->header
.signature
;
6322 struct attribute
*attr
;
6323 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6324 if (attr
== nullptr || !attr
->form_is_unsigned ())
6325 return gdb::optional
<ULONGEST
> ();
6326 return attr
->as_unsigned ();
6329 /* Subroutine of cutu_reader to simplify it.
6330 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6331 Returns NULL if the specified DWO unit cannot be found. */
6333 static struct dwo_unit
*
6334 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6336 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6337 struct dwo_unit
*dwo_unit
;
6338 const char *comp_dir
;
6340 gdb_assert (cu
!= NULL
);
6342 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6343 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6344 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6346 if (per_cu
->is_debug_types
)
6347 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6350 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6352 if (!signature
.has_value ())
6353 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6355 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6357 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6363 /* Subroutine of cutu_reader to simplify it.
6364 See it for a description of the parameters.
6365 Read a TU directly from a DWO file, bypassing the stub. */
6368 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6369 dwarf2_per_objfile
*per_objfile
,
6370 dwarf2_cu
*existing_cu
)
6372 struct signatured_type
*sig_type
;
6374 /* Verify we can do the following downcast, and that we have the
6376 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6377 sig_type
= (struct signatured_type
*) this_cu
;
6378 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6382 if (existing_cu
!= nullptr)
6385 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6386 /* There's no need to do the rereading_dwo_cu handling that
6387 cutu_reader does since we don't read the stub. */
6391 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6392 in per_objfile yet. */
6393 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6394 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6395 cu
= m_new_cu
.get ();
6398 /* A future optimization, if needed, would be to use an existing
6399 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6400 could share abbrev tables. */
6402 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6403 NULL
/* stub_comp_unit_die */,
6404 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6407 &m_dwo_abbrev_table
) == 0)
6414 /* Initialize a CU (or TU) and read its DIEs.
6415 If the CU defers to a DWO file, read the DWO file as well.
6417 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6418 Otherwise the table specified in the comp unit header is read in and used.
6419 This is an optimization for when we already have the abbrev table.
6421 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6424 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6425 dwarf2_per_objfile
*per_objfile
,
6426 struct abbrev_table
*abbrev_table
,
6427 dwarf2_cu
*existing_cu
,
6429 : die_reader_specs
{},
6432 struct objfile
*objfile
= per_objfile
->objfile
;
6433 struct dwarf2_section_info
*section
= this_cu
->section
;
6434 bfd
*abfd
= section
->get_bfd_owner ();
6435 const gdb_byte
*begin_info_ptr
;
6436 struct signatured_type
*sig_type
= NULL
;
6437 struct dwarf2_section_info
*abbrev_section
;
6438 /* Non-zero if CU currently points to a DWO file and we need to
6439 reread it. When this happens we need to reread the skeleton die
6440 before we can reread the DWO file (this only applies to CUs, not TUs). */
6441 int rereading_dwo_cu
= 0;
6443 if (dwarf_die_debug
)
6444 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6445 this_cu
->is_debug_types
? "type" : "comp",
6446 sect_offset_str (this_cu
->sect_off
));
6448 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6449 file (instead of going through the stub), short-circuit all of this. */
6450 if (this_cu
->reading_dwo_directly
)
6452 /* Narrow down the scope of possibilities to have to understand. */
6453 gdb_assert (this_cu
->is_debug_types
);
6454 gdb_assert (abbrev_table
== NULL
);
6455 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6459 /* This is cheap if the section is already read in. */
6460 section
->read (objfile
);
6462 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6464 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6468 if (existing_cu
!= nullptr)
6471 /* If this CU is from a DWO file we need to start over, we need to
6472 refetch the attributes from the skeleton CU.
6473 This could be optimized by retrieving those attributes from when we
6474 were here the first time: the previous comp_unit_die was stored in
6475 comp_unit_obstack. But there's no data yet that we need this
6477 if (cu
->dwo_unit
!= NULL
)
6478 rereading_dwo_cu
= 1;
6482 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6483 in per_objfile yet. */
6484 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6485 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6486 cu
= m_new_cu
.get ();
6489 /* Get the header. */
6490 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6492 /* We already have the header, there's no need to read it in again. */
6493 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6497 if (this_cu
->is_debug_types
)
6499 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6500 section
, abbrev_section
,
6501 info_ptr
, rcuh_kind::TYPE
);
6503 /* Since per_cu is the first member of struct signatured_type,
6504 we can go from a pointer to one to a pointer to the other. */
6505 sig_type
= (struct signatured_type
*) this_cu
;
6506 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6507 gdb_assert (sig_type
->type_offset_in_tu
6508 == cu
->header
.type_cu_offset_in_tu
);
6509 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6511 /* LENGTH has not been set yet for type units if we're
6512 using .gdb_index. */
6513 this_cu
->length
= cu
->header
.get_length ();
6515 /* Establish the type offset that can be used to lookup the type. */
6516 sig_type
->type_offset_in_section
=
6517 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6519 this_cu
->dwarf_version
= cu
->header
.version
;
6523 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6524 section
, abbrev_section
,
6526 rcuh_kind::COMPILE
);
6528 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6529 if (this_cu
->length
== 0)
6530 this_cu
->length
= cu
->header
.get_length ();
6532 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6533 this_cu
->dwarf_version
= cu
->header
.version
;
6537 /* Skip dummy compilation units. */
6538 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6539 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6545 /* If we don't have them yet, read the abbrevs for this compilation unit.
6546 And if we need to read them now, make sure they're freed when we're
6548 if (abbrev_table
!= NULL
)
6549 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6552 abbrev_section
->read (objfile
);
6553 m_abbrev_table_holder
6554 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6555 abbrev_table
= m_abbrev_table_holder
.get ();
6558 /* Read the top level CU/TU die. */
6559 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6560 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6562 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6568 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6569 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6570 table from the DWO file and pass the ownership over to us. It will be
6571 referenced from READER, so we must make sure to free it after we're done
6574 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6575 DWO CU, that this test will fail (the attribute will not be present). */
6576 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6577 if (dwo_name
!= nullptr)
6579 struct dwo_unit
*dwo_unit
;
6580 struct die_info
*dwo_comp_unit_die
;
6582 if (comp_unit_die
->has_children
)
6584 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6585 " has children (offset %s) [in module %s]"),
6586 sect_offset_str (this_cu
->sect_off
),
6587 bfd_get_filename (abfd
));
6589 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6590 if (dwo_unit
!= NULL
)
6592 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6593 comp_unit_die
, NULL
,
6596 &m_dwo_abbrev_table
) == 0)
6602 comp_unit_die
= dwo_comp_unit_die
;
6606 /* Yikes, we couldn't find the rest of the DIE, we only have
6607 the stub. A complaint has already been logged. There's
6608 not much more we can do except pass on the stub DIE to
6609 die_reader_func. We don't want to throw an error on bad
6616 cutu_reader::keep ()
6618 /* Done, clean up. */
6619 gdb_assert (!dummy_p
);
6620 if (m_new_cu
!= NULL
)
6622 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6624 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6625 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6629 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6630 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6631 assumed to have already done the lookup to find the DWO file).
6633 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6634 THIS_CU->is_debug_types, but nothing else.
6636 We fill in THIS_CU->length.
6638 THIS_CU->cu is always freed when done.
6639 This is done in order to not leave THIS_CU->cu in a state where we have
6640 to care whether it refers to the "main" CU or the DWO CU.
6642 When parent_cu is passed, it is used to provide a default value for
6643 str_offsets_base and addr_base from the parent. */
6645 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6646 dwarf2_per_objfile
*per_objfile
,
6647 struct dwarf2_cu
*parent_cu
,
6648 struct dwo_file
*dwo_file
)
6649 : die_reader_specs
{},
6652 struct objfile
*objfile
= per_objfile
->objfile
;
6653 struct dwarf2_section_info
*section
= this_cu
->section
;
6654 bfd
*abfd
= section
->get_bfd_owner ();
6655 struct dwarf2_section_info
*abbrev_section
;
6656 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6658 if (dwarf_die_debug
)
6659 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6660 this_cu
->is_debug_types
? "type" : "comp",
6661 sect_offset_str (this_cu
->sect_off
));
6663 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6665 abbrev_section
= (dwo_file
!= NULL
6666 ? &dwo_file
->sections
.abbrev
6667 : get_abbrev_section_for_cu (this_cu
));
6669 /* This is cheap if the section is already read in. */
6670 section
->read (objfile
);
6672 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6674 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6675 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6676 section
, abbrev_section
, info_ptr
,
6677 (this_cu
->is_debug_types
6679 : rcuh_kind::COMPILE
));
6681 if (parent_cu
!= nullptr)
6683 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6684 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6686 this_cu
->length
= m_new_cu
->header
.get_length ();
6688 /* Skip dummy compilation units. */
6689 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6690 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6696 abbrev_section
->read (objfile
);
6697 m_abbrev_table_holder
6698 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6700 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6701 m_abbrev_table_holder
.get ());
6702 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6706 /* Type Unit Groups.
6708 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6709 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6710 so that all types coming from the same compilation (.o file) are grouped
6711 together. A future step could be to put the types in the same symtab as
6712 the CU the types ultimately came from. */
6715 hash_type_unit_group (const void *item
)
6717 const struct type_unit_group
*tu_group
6718 = (const struct type_unit_group
*) item
;
6720 return hash_stmt_list_entry (&tu_group
->hash
);
6724 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6726 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6727 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6729 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6732 /* Allocate a hash table for type unit groups. */
6735 allocate_type_unit_groups_table ()
6737 return htab_up (htab_create_alloc (3,
6738 hash_type_unit_group
,
6740 htab_delete_entry
<type_unit_group
>,
6744 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6745 partial symtabs. We combine several TUs per psymtab to not let the size
6746 of any one psymtab grow too big. */
6747 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6748 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6750 /* Helper routine for get_type_unit_group.
6751 Create the type_unit_group object used to hold one or more TUs. */
6753 static std::unique_ptr
<type_unit_group
>
6754 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6756 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6757 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6759 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6760 tu_group
->per_bfd
= per_bfd
;
6762 if (per_bfd
->using_index
)
6764 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6765 struct dwarf2_per_cu_quick_data
);
6769 unsigned int line_offset
= to_underlying (line_offset_struct
);
6770 dwarf2_psymtab
*pst
;
6773 /* Give the symtab a useful name for debug purposes. */
6774 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6775 name
= string_printf ("<type_units_%d>",
6776 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6778 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6780 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6782 pst
->anonymous
= true;
6785 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6786 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6791 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6792 STMT_LIST is a DW_AT_stmt_list attribute. */
6794 static struct type_unit_group
*
6795 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6797 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6798 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6799 struct type_unit_group
*tu_group
;
6801 unsigned int line_offset
;
6802 struct type_unit_group type_unit_group_for_lookup
;
6804 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6805 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6807 /* Do we need to create a new group, or can we use an existing one? */
6809 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6811 line_offset
= stmt_list
->as_unsigned ();
6812 ++tu_stats
->nr_symtab_sharers
;
6816 /* Ugh, no stmt_list. Rare, but we have to handle it.
6817 We can do various things here like create one group per TU or
6818 spread them over multiple groups to split up the expansion work.
6819 To avoid worst case scenarios (too many groups or too large groups)
6820 we, umm, group them in bunches. */
6821 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6822 | (tu_stats
->nr_stmt_less_type_units
6823 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6824 ++tu_stats
->nr_stmt_less_type_units
;
6827 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6828 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6829 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6830 &type_unit_group_for_lookup
, INSERT
);
6831 if (*slot
== nullptr)
6833 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6834 std::unique_ptr
<type_unit_group
> grp
6835 = create_type_unit_group (cu
, line_offset_struct
);
6836 *slot
= grp
.release ();
6837 ++tu_stats
->nr_symtabs
;
6840 tu_group
= (struct type_unit_group
*) *slot
;
6841 gdb_assert (tu_group
!= nullptr);
6845 /* Partial symbol tables. */
6847 /* Create a psymtab named NAME and assign it to PER_CU.
6849 The caller must fill in the following details:
6850 dirname, textlow, texthigh. */
6852 static dwarf2_psymtab
*
6853 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6854 dwarf2_per_objfile
*per_objfile
,
6858 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6859 per_objfile
->objfile
->per_bfd
, per_cu
);
6861 pst
->psymtabs_addrmap_supported
= true;
6863 /* This is the glue that links PST into GDB's symbol API. */
6864 per_cu
->v
.psymtab
= pst
;
6869 /* DIE reader function for process_psymtab_comp_unit. */
6872 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6873 const gdb_byte
*info_ptr
,
6874 struct die_info
*comp_unit_die
,
6875 enum language pretend_language
)
6877 struct dwarf2_cu
*cu
= reader
->cu
;
6878 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6879 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6880 struct objfile
*objfile
= per_objfile
->objfile
;
6881 struct gdbarch
*gdbarch
= objfile
->arch ();
6882 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6884 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6885 dwarf2_psymtab
*pst
;
6886 enum pc_bounds_kind cu_bounds_kind
;
6887 const char *filename
;
6889 gdb_assert (! per_cu
->is_debug_types
);
6891 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6893 /* Allocate a new partial symbol table structure. */
6894 gdb::unique_xmalloc_ptr
<char> debug_filename
;
6895 static const char artificial
[] = "<artificial>";
6896 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6897 if (filename
== NULL
)
6899 else if (strcmp (filename
, artificial
) == 0)
6901 debug_filename
.reset (concat (artificial
, "@",
6902 sect_offset_str (per_cu
->sect_off
),
6904 filename
= debug_filename
.get ();
6907 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
6909 /* This must be done before calling dwarf2_build_include_psymtabs. */
6910 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6912 baseaddr
= objfile
->text_section_offset ();
6914 dwarf2_find_base_address (comp_unit_die
, cu
);
6916 /* Possibly set the default values of LOWPC and HIGHPC from
6918 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6919 &best_highpc
, cu
, pst
);
6920 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6923 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
6926 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
6928 /* Store the contiguous range if it is not empty; it can be
6929 empty for CUs with no code. */
6930 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
6934 /* Check if comp unit has_children.
6935 If so, read the rest of the partial symbols from this comp unit.
6936 If not, there's no more debug_info for this comp unit. */
6937 if (comp_unit_die
->has_children
)
6939 struct partial_die_info
*first_die
;
6940 CORE_ADDR lowpc
, highpc
;
6942 lowpc
= ((CORE_ADDR
) -1);
6943 highpc
= ((CORE_ADDR
) 0);
6945 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6947 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6948 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6950 /* If we didn't find a lowpc, set it to highpc to avoid
6951 complaints from `maint check'. */
6952 if (lowpc
== ((CORE_ADDR
) -1))
6955 /* If the compilation unit didn't have an explicit address range,
6956 then use the information extracted from its child dies. */
6957 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6960 best_highpc
= highpc
;
6963 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
6964 best_lowpc
+ baseaddr
)
6966 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
6967 best_highpc
+ baseaddr
)
6972 if (!cu
->per_cu
->imported_symtabs_empty ())
6975 int len
= cu
->per_cu
->imported_symtabs_size ();
6977 /* Fill in 'dependencies' here; we fill in 'users' in a
6979 pst
->number_of_dependencies
= len
;
6981 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
6982 for (i
= 0; i
< len
; ++i
)
6984 pst
->dependencies
[i
]
6985 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
6988 cu
->per_cu
->imported_symtabs_free ();
6991 /* Get the list of files included in the current compilation unit,
6992 and build a psymtab for each of them. */
6993 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6995 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
6996 ", %d global, %d static syms",
6997 per_cu
->is_debug_types
? "type" : "comp",
6998 sect_offset_str (per_cu
->sect_off
),
6999 paddress (gdbarch
, pst
->text_low (objfile
)),
7000 paddress (gdbarch
, pst
->text_high (objfile
)),
7001 (int) pst
->global_psymbols
.size (),
7002 (int) pst
->static_psymbols
.size ());
7005 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7006 Process compilation unit THIS_CU for a psymtab. */
7009 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7010 dwarf2_per_objfile
*per_objfile
,
7011 bool want_partial_unit
,
7012 enum language pretend_language
)
7014 /* If this compilation unit was already read in, free the
7015 cached copy in order to read it in again. This is
7016 necessary because we skipped some symbols when we first
7017 read in the compilation unit (see load_partial_dies).
7018 This problem could be avoided, but the benefit is unclear. */
7019 per_objfile
->remove_cu (this_cu
);
7021 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7023 switch (reader
.comp_unit_die
->tag
)
7025 case DW_TAG_compile_unit
:
7026 this_cu
->unit_type
= DW_UT_compile
;
7028 case DW_TAG_partial_unit
:
7029 this_cu
->unit_type
= DW_UT_partial
;
7031 case DW_TAG_type_unit
:
7032 this_cu
->unit_type
= DW_UT_type
;
7035 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7036 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7037 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7038 objfile_name (per_objfile
->objfile
));
7045 else if (this_cu
->is_debug_types
)
7046 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7047 reader
.comp_unit_die
);
7048 else if (want_partial_unit
7049 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7050 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7051 reader
.comp_unit_die
,
7054 this_cu
->lang
= reader
.cu
->language
;
7056 /* Age out any secondary CUs. */
7057 per_objfile
->age_comp_units ();
7060 /* Reader function for build_type_psymtabs. */
7063 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7064 const gdb_byte
*info_ptr
,
7065 struct die_info
*type_unit_die
)
7067 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7068 struct dwarf2_cu
*cu
= reader
->cu
;
7069 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7070 struct signatured_type
*sig_type
;
7071 struct type_unit_group
*tu_group
;
7072 struct attribute
*attr
;
7073 struct partial_die_info
*first_die
;
7074 CORE_ADDR lowpc
, highpc
;
7075 dwarf2_psymtab
*pst
;
7077 gdb_assert (per_cu
->is_debug_types
);
7078 sig_type
= (struct signatured_type
*) per_cu
;
7080 if (! type_unit_die
->has_children
)
7083 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7084 tu_group
= get_type_unit_group (cu
, attr
);
7086 if (tu_group
->tus
== nullptr)
7087 tu_group
->tus
= new std::vector
<signatured_type
*>;
7088 tu_group
->tus
->push_back (sig_type
);
7090 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7091 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7092 pst
->anonymous
= true;
7094 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7096 lowpc
= (CORE_ADDR
) -1;
7097 highpc
= (CORE_ADDR
) 0;
7098 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7103 /* Struct used to sort TUs by their abbreviation table offset. */
7105 struct tu_abbrev_offset
7107 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7108 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7111 /* This is used when sorting. */
7112 bool operator< (const tu_abbrev_offset
&other
) const
7114 return abbrev_offset
< other
.abbrev_offset
;
7117 signatured_type
*sig_type
;
7118 sect_offset abbrev_offset
;
7121 /* Efficiently read all the type units.
7123 The efficiency is because we sort TUs by the abbrev table they use and
7124 only read each abbrev table once. In one program there are 200K TUs
7125 sharing 8K abbrev tables.
7127 The main purpose of this function is to support building the
7128 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7129 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7130 can collapse the search space by grouping them by stmt_list.
7131 The savings can be significant, in the same program from above the 200K TUs
7132 share 8K stmt_list tables.
7134 FUNC is expected to call get_type_unit_group, which will create the
7135 struct type_unit_group if necessary and add it to
7136 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7139 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7141 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7142 abbrev_table_up abbrev_table
;
7143 sect_offset abbrev_offset
;
7145 /* It's up to the caller to not call us multiple times. */
7146 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7148 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7151 /* TUs typically share abbrev tables, and there can be way more TUs than
7152 abbrev tables. Sort by abbrev table to reduce the number of times we
7153 read each abbrev table in.
7154 Alternatives are to punt or to maintain a cache of abbrev tables.
7155 This is simpler and efficient enough for now.
7157 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7158 symtab to use). Typically TUs with the same abbrev offset have the same
7159 stmt_list value too so in practice this should work well.
7161 The basic algorithm here is:
7163 sort TUs by abbrev table
7164 for each TU with same abbrev table:
7165 read abbrev table if first user
7166 read TU top level DIE
7167 [IWBN if DWO skeletons had DW_AT_stmt_list]
7170 dwarf_read_debug_printf ("Building type unit groups ...");
7172 /* Sort in a separate table to maintain the order of all_comp_units
7173 for .gdb_index: TU indices directly index all_type_units. */
7174 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7175 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7177 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7179 if (cu
->is_debug_types
)
7181 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7182 sorted_by_abbrev
.emplace_back
7183 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7184 sig_type
->sect_off
));
7188 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7190 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7192 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7194 /* Switch to the next abbrev table if necessary. */
7195 if (abbrev_table
== NULL
7196 || tu
.abbrev_offset
!= abbrev_offset
)
7198 abbrev_offset
= tu
.abbrev_offset
;
7199 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7201 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7202 ++tu_stats
->nr_uniq_abbrev_tables
;
7205 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7206 abbrev_table
.get (), nullptr, false);
7207 if (!reader
.dummy_p
)
7208 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7209 reader
.comp_unit_die
);
7213 /* Print collected type unit statistics. */
7216 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7218 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7220 dwarf_read_debug_printf ("Type unit statistics:");
7221 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7222 dwarf_read_debug_printf (" %d uniq abbrev tables",
7223 tu_stats
->nr_uniq_abbrev_tables
);
7224 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7225 tu_stats
->nr_symtabs
);
7226 dwarf_read_debug_printf (" %d symtab sharers",
7227 tu_stats
->nr_symtab_sharers
);
7228 dwarf_read_debug_printf (" %d type units without a stmt_list",
7229 tu_stats
->nr_stmt_less_type_units
);
7230 dwarf_read_debug_printf (" %d all_type_units reallocs",
7231 tu_stats
->nr_all_type_units_reallocs
);
7234 /* Traversal function for build_type_psymtabs. */
7237 build_type_psymtab_dependencies (void **slot
, void *info
)
7239 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7240 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7241 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7242 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7243 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7246 gdb_assert (len
> 0);
7247 gdb_assert (tu_group
->type_unit_group_p ());
7249 pst
->number_of_dependencies
= len
;
7250 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7251 for (i
= 0; i
< len
; ++i
)
7253 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7254 gdb_assert (iter
->is_debug_types
);
7255 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7256 iter
->type_unit_group
= tu_group
;
7259 delete tu_group
->tus
;
7260 tu_group
->tus
= nullptr;
7265 /* Traversal function for process_skeletonless_type_unit.
7266 Read a TU in a DWO file and build partial symbols for it. */
7269 process_skeletonless_type_unit (void **slot
, void *info
)
7271 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7272 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7273 struct signatured_type find_entry
, *entry
;
7275 /* If this TU doesn't exist in the global table, add it and read it in. */
7277 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7278 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7280 find_entry
.signature
= dwo_unit
->signature
;
7281 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7282 &find_entry
, INSERT
);
7283 /* If we've already seen this type there's nothing to do. What's happening
7284 is we're doing our own version of comdat-folding here. */
7288 /* This does the job that create_all_comp_units would have done for
7290 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7291 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7294 /* This does the job that build_type_psymtabs would have done. */
7295 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7296 if (!reader
.dummy_p
)
7297 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7298 reader
.comp_unit_die
);
7303 /* Traversal function for process_skeletonless_type_units. */
7306 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7308 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7310 if (dwo_file
->tus
!= NULL
)
7311 htab_traverse_noresize (dwo_file
->tus
.get (),
7312 process_skeletonless_type_unit
, info
);
7317 /* Scan all TUs of DWO files, verifying we've processed them.
7318 This is needed in case a TU was emitted without its skeleton.
7319 Note: This can't be done until we know what all the DWO files are. */
7322 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7324 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7325 if (get_dwp_file (per_objfile
) == NULL
7326 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7328 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7329 process_dwo_file_for_skeletonless_type_units
,
7334 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7337 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7339 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7341 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7346 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7348 /* Set the 'user' field only if it is not already set. */
7349 if (pst
->dependencies
[j
]->user
== NULL
)
7350 pst
->dependencies
[j
]->user
= pst
;
7355 /* Build the partial symbol table by doing a quick pass through the
7356 .debug_info and .debug_abbrev sections. */
7359 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7361 struct objfile
*objfile
= per_objfile
->objfile
;
7362 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7364 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7365 objfile_name (objfile
));
7367 scoped_restore restore_reading_psyms
7368 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7370 per_bfd
->info
.read (objfile
);
7372 /* Any cached compilation units will be linked by the per-objfile
7373 read_in_chain. Make sure to free them when we're done. */
7374 free_cached_comp_units
freer (per_objfile
);
7376 create_all_comp_units (per_objfile
);
7377 build_type_psymtabs (per_objfile
);
7379 /* Create a temporary address map on a temporary obstack. We later
7380 copy this to the final obstack. */
7381 auto_obstack temp_obstack
;
7383 scoped_restore save_psymtabs_addrmap
7384 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7385 addrmap_create_mutable (&temp_obstack
));
7387 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7389 if (per_cu
->v
.psymtab
!= NULL
)
7390 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7392 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7396 /* This has to wait until we read the CUs, we need the list of DWOs. */
7397 process_skeletonless_type_units (per_objfile
);
7399 /* Now that all TUs have been processed we can fill in the dependencies. */
7400 if (per_bfd
->type_unit_groups
!= NULL
)
7402 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7403 build_type_psymtab_dependencies
, per_objfile
);
7406 if (dwarf_read_debug
> 0)
7407 print_tu_stats (per_objfile
);
7409 set_partial_user (per_objfile
);
7411 per_bfd
->partial_symtabs
->psymtabs_addrmap
7412 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7413 per_bfd
->partial_symtabs
->obstack ());
7414 /* At this point we want to keep the address map. */
7415 save_psymtabs_addrmap
.release ();
7417 dwarf_read_debug_printf ("Done building psymtabs of %s",
7418 objfile_name (objfile
));
7421 /* Load the partial DIEs for a secondary CU into memory.
7422 This is also used when rereading a primary CU with load_all_dies. */
7425 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7426 dwarf2_per_objfile
*per_objfile
,
7427 dwarf2_cu
*existing_cu
)
7429 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7431 if (!reader
.dummy_p
)
7433 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7436 /* Check if comp unit has_children.
7437 If so, read the rest of the partial symbols from this comp unit.
7438 If not, there's no more debug_info for this comp unit. */
7439 if (reader
.comp_unit_die
->has_children
)
7440 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7447 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7448 struct dwarf2_section_info
*section
,
7449 struct dwarf2_section_info
*abbrev_section
,
7450 unsigned int is_dwz
,
7451 htab_up
&types_htab
,
7452 rcuh_kind section_kind
)
7454 const gdb_byte
*info_ptr
;
7455 struct objfile
*objfile
= per_objfile
->objfile
;
7457 dwarf_read_debug_printf ("Reading %s for %s",
7458 section
->get_name (),
7459 section
->get_file_name ());
7461 section
->read (objfile
);
7463 info_ptr
= section
->buffer
;
7465 while (info_ptr
< section
->buffer
+ section
->size
)
7467 dwarf2_per_cu_data_up this_cu
;
7469 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7471 comp_unit_head cu_header
;
7472 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7473 abbrev_section
, info_ptr
,
7476 /* Save the compilation unit for later lookup. */
7477 if (cu_header
.unit_type
!= DW_UT_type
)
7478 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7481 if (types_htab
== nullptr)
7482 types_htab
= allocate_signatured_type_table ();
7484 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
7485 signatured_type
*sig_ptr
= sig_type
.get ();
7486 sig_type
->signature
= cu_header
.signature
;
7487 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7488 this_cu
.reset (sig_type
.release ());
7490 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7491 gdb_assert (slot
!= nullptr);
7492 if (*slot
!= nullptr)
7493 complaint (_("debug type entry at offset %s is duplicate to"
7494 " the entry at offset %s, signature %s"),
7495 sect_offset_str (sect_off
),
7496 sect_offset_str (sig_ptr
->sect_off
),
7497 hex_string (sig_ptr
->signature
));
7500 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7501 this_cu
->sect_off
= sect_off
;
7502 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7503 this_cu
->is_dwz
= is_dwz
;
7504 this_cu
->section
= section
;
7506 info_ptr
= info_ptr
+ this_cu
->length
;
7507 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7511 /* Create a list of all compilation units in OBJFILE.
7512 This is only done for -readnow and building partial symtabs. */
7515 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7519 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7520 &per_objfile
->per_bfd
->abbrev
, 0,
7521 types_htab
, rcuh_kind::COMPILE
);
7522 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7523 read_comp_units_from_section (per_objfile
, §ion
,
7524 &per_objfile
->per_bfd
->abbrev
, 0,
7525 types_htab
, rcuh_kind::TYPE
);
7527 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7529 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7530 types_htab
, rcuh_kind::COMPILE
);
7532 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7535 /* Process all loaded DIEs for compilation unit CU, starting at
7536 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7537 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7538 DW_AT_ranges). See the comments of add_partial_subprogram on how
7539 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7542 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7543 CORE_ADDR
*highpc
, int set_addrmap
,
7544 struct dwarf2_cu
*cu
)
7546 struct partial_die_info
*pdi
;
7548 /* Now, march along the PDI's, descending into ones which have
7549 interesting children but skipping the children of the other ones,
7550 until we reach the end of the compilation unit. */
7558 /* Anonymous namespaces or modules have no name but have interesting
7559 children, so we need to look at them. Ditto for anonymous
7562 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7563 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7564 || pdi
->tag
== DW_TAG_imported_unit
7565 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7569 case DW_TAG_subprogram
:
7570 case DW_TAG_inlined_subroutine
:
7571 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7572 if (cu
->language
== language_cplus
)
7573 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7576 case DW_TAG_constant
:
7577 case DW_TAG_variable
:
7578 case DW_TAG_typedef
:
7579 case DW_TAG_union_type
:
7580 if (!pdi
->is_declaration
7581 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7583 add_partial_symbol (pdi
, cu
);
7586 case DW_TAG_class_type
:
7587 case DW_TAG_interface_type
:
7588 case DW_TAG_structure_type
:
7589 if (!pdi
->is_declaration
)
7591 add_partial_symbol (pdi
, cu
);
7593 if ((cu
->language
== language_rust
7594 || cu
->language
== language_cplus
) && pdi
->has_children
)
7595 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7598 case DW_TAG_enumeration_type
:
7599 if (!pdi
->is_declaration
)
7600 add_partial_enumeration (pdi
, cu
);
7602 case DW_TAG_base_type
:
7603 case DW_TAG_subrange_type
:
7604 /* File scope base type definitions are added to the partial
7606 add_partial_symbol (pdi
, cu
);
7608 case DW_TAG_namespace
:
7609 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7612 if (!pdi
->is_declaration
)
7613 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7615 case DW_TAG_imported_unit
:
7617 struct dwarf2_per_cu_data
*per_cu
;
7619 /* For now we don't handle imported units in type units. */
7620 if (cu
->per_cu
->is_debug_types
)
7622 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7623 " supported in type units [in module %s]"),
7624 objfile_name (cu
->per_objfile
->objfile
));
7627 per_cu
= dwarf2_find_containing_comp_unit
7628 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7630 /* Go read the partial unit, if needed. */
7631 if (per_cu
->v
.psymtab
== NULL
)
7632 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7635 cu
->per_cu
->imported_symtabs_push (per_cu
);
7638 case DW_TAG_imported_declaration
:
7639 add_partial_symbol (pdi
, cu
);
7646 /* If the die has a sibling, skip to the sibling. */
7648 pdi
= pdi
->die_sibling
;
7652 /* Functions used to compute the fully scoped name of a partial DIE.
7654 Normally, this is simple. For C++, the parent DIE's fully scoped
7655 name is concatenated with "::" and the partial DIE's name.
7656 Enumerators are an exception; they use the scope of their parent
7657 enumeration type, i.e. the name of the enumeration type is not
7658 prepended to the enumerator.
7660 There are two complexities. One is DW_AT_specification; in this
7661 case "parent" means the parent of the target of the specification,
7662 instead of the direct parent of the DIE. The other is compilers
7663 which do not emit DW_TAG_namespace; in this case we try to guess
7664 the fully qualified name of structure types from their members'
7665 linkage names. This must be done using the DIE's children rather
7666 than the children of any DW_AT_specification target. We only need
7667 to do this for structures at the top level, i.e. if the target of
7668 any DW_AT_specification (if any; otherwise the DIE itself) does not
7671 /* Compute the scope prefix associated with PDI's parent, in
7672 compilation unit CU. The result will be allocated on CU's
7673 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7674 field. NULL is returned if no prefix is necessary. */
7676 partial_die_parent_scope (struct partial_die_info
*pdi
,
7677 struct dwarf2_cu
*cu
)
7679 const char *grandparent_scope
;
7680 struct partial_die_info
*parent
, *real_pdi
;
7682 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7683 then this means the parent of the specification DIE. */
7686 while (real_pdi
->has_specification
)
7688 auto res
= find_partial_die (real_pdi
->spec_offset
,
7689 real_pdi
->spec_is_dwz
, cu
);
7694 parent
= real_pdi
->die_parent
;
7698 if (parent
->scope_set
)
7699 return parent
->scope
;
7703 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7705 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7706 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7707 Work around this problem here. */
7708 if (cu
->language
== language_cplus
7709 && parent
->tag
== DW_TAG_namespace
7710 && strcmp (parent
->name (cu
), "::") == 0
7711 && grandparent_scope
== NULL
)
7713 parent
->scope
= NULL
;
7714 parent
->scope_set
= 1;
7718 /* Nested subroutines in Fortran get a prefix. */
7719 if (pdi
->tag
== DW_TAG_enumerator
)
7720 /* Enumerators should not get the name of the enumeration as a prefix. */
7721 parent
->scope
= grandparent_scope
;
7722 else if (parent
->tag
== DW_TAG_namespace
7723 || parent
->tag
== DW_TAG_module
7724 || parent
->tag
== DW_TAG_structure_type
7725 || parent
->tag
== DW_TAG_class_type
7726 || parent
->tag
== DW_TAG_interface_type
7727 || parent
->tag
== DW_TAG_union_type
7728 || parent
->tag
== DW_TAG_enumeration_type
7729 || (cu
->language
== language_fortran
7730 && parent
->tag
== DW_TAG_subprogram
7731 && pdi
->tag
== DW_TAG_subprogram
))
7733 if (grandparent_scope
== NULL
)
7734 parent
->scope
= parent
->name (cu
);
7736 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7738 parent
->name (cu
), 0, cu
);
7742 /* FIXME drow/2004-04-01: What should we be doing with
7743 function-local names? For partial symbols, we should probably be
7745 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7746 dwarf_tag_name (parent
->tag
),
7747 sect_offset_str (pdi
->sect_off
));
7748 parent
->scope
= grandparent_scope
;
7751 parent
->scope_set
= 1;
7752 return parent
->scope
;
7755 /* Return the fully scoped name associated with PDI, from compilation unit
7756 CU. The result will be allocated with malloc. */
7758 static gdb::unique_xmalloc_ptr
<char>
7759 partial_die_full_name (struct partial_die_info
*pdi
,
7760 struct dwarf2_cu
*cu
)
7762 const char *parent_scope
;
7764 /* If this is a template instantiation, we can not work out the
7765 template arguments from partial DIEs. So, unfortunately, we have
7766 to go through the full DIEs. At least any work we do building
7767 types here will be reused if full symbols are loaded later. */
7768 if (pdi
->has_template_arguments
)
7772 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7774 struct die_info
*die
;
7775 struct attribute attr
;
7776 struct dwarf2_cu
*ref_cu
= cu
;
7778 /* DW_FORM_ref_addr is using section offset. */
7779 attr
.name
= (enum dwarf_attribute
) 0;
7780 attr
.form
= DW_FORM_ref_addr
;
7781 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7782 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7784 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7788 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7789 if (parent_scope
== NULL
)
7792 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7798 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7800 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7801 struct objfile
*objfile
= per_objfile
->objfile
;
7802 struct gdbarch
*gdbarch
= objfile
->arch ();
7804 const char *actual_name
= NULL
;
7807 baseaddr
= objfile
->text_section_offset ();
7809 gdb::unique_xmalloc_ptr
<char> built_actual_name
7810 = partial_die_full_name (pdi
, cu
);
7811 if (built_actual_name
!= NULL
)
7812 actual_name
= built_actual_name
.get ();
7814 if (actual_name
== NULL
)
7815 actual_name
= pdi
->name (cu
);
7817 partial_symbol psymbol
;
7818 memset (&psymbol
, 0, sizeof (psymbol
));
7819 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
7820 psymbol
.ginfo
.set_section_index (-1);
7822 /* The code below indicates that the psymbol should be installed by
7824 gdb::optional
<psymbol_placement
> where
;
7828 case DW_TAG_inlined_subroutine
:
7829 case DW_TAG_subprogram
:
7830 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7832 if (pdi
->is_external
7833 || cu
->language
== language_ada
7834 || (cu
->language
== language_fortran
7835 && pdi
->die_parent
!= NULL
7836 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7838 /* Normally, only "external" DIEs are part of the global scope.
7839 But in Ada and Fortran, we want to be able to access nested
7840 procedures globally. So all Ada and Fortran subprograms are
7841 stored in the global scope. */
7842 where
= psymbol_placement::GLOBAL
;
7845 where
= psymbol_placement::STATIC
;
7847 psymbol
.domain
= VAR_DOMAIN
;
7848 psymbol
.aclass
= LOC_BLOCK
;
7849 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7850 psymbol
.ginfo
.value
.address
= addr
;
7852 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7853 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
7855 case DW_TAG_constant
:
7856 psymbol
.domain
= VAR_DOMAIN
;
7857 psymbol
.aclass
= LOC_STATIC
;
7858 where
= (pdi
->is_external
7859 ? psymbol_placement::GLOBAL
7860 : psymbol_placement::STATIC
);
7862 case DW_TAG_variable
:
7864 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7868 && !per_objfile
->per_bfd
->has_section_at_zero
)
7870 /* A global or static variable may also have been stripped
7871 out by the linker if unused, in which case its address
7872 will be nullified; do not add such variables into partial
7873 symbol table then. */
7875 else if (pdi
->is_external
)
7878 Don't enter into the minimal symbol tables as there is
7879 a minimal symbol table entry from the ELF symbols already.
7880 Enter into partial symbol table if it has a location
7881 descriptor or a type.
7882 If the location descriptor is missing, new_symbol will create
7883 a LOC_UNRESOLVED symbol, the address of the variable will then
7884 be determined from the minimal symbol table whenever the variable
7886 The address for the partial symbol table entry is not
7887 used by GDB, but it comes in handy for debugging partial symbol
7890 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7892 psymbol
.domain
= VAR_DOMAIN
;
7893 psymbol
.aclass
= LOC_STATIC
;
7894 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7895 psymbol
.ginfo
.value
.address
= addr
;
7896 where
= psymbol_placement::GLOBAL
;
7901 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7903 /* Static Variable. Skip symbols whose value we cannot know (those
7904 without location descriptors or constant values). */
7905 if (!has_loc
&& !pdi
->has_const_value
)
7908 psymbol
.domain
= VAR_DOMAIN
;
7909 psymbol
.aclass
= LOC_STATIC
;
7910 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7912 psymbol
.ginfo
.value
.address
= addr
;
7913 where
= psymbol_placement::STATIC
;
7916 case DW_TAG_array_type
:
7917 case DW_TAG_typedef
:
7918 case DW_TAG_base_type
:
7919 case DW_TAG_subrange_type
:
7920 psymbol
.domain
= VAR_DOMAIN
;
7921 psymbol
.aclass
= LOC_TYPEDEF
;
7922 where
= psymbol_placement::STATIC
;
7924 case DW_TAG_imported_declaration
:
7925 case DW_TAG_namespace
:
7926 psymbol
.domain
= VAR_DOMAIN
;
7927 psymbol
.aclass
= LOC_TYPEDEF
;
7928 where
= psymbol_placement::GLOBAL
;
7931 /* With Fortran 77 there might be a "BLOCK DATA" module
7932 available without any name. If so, we skip the module as it
7933 doesn't bring any value. */
7934 if (actual_name
!= nullptr)
7936 psymbol
.domain
= MODULE_DOMAIN
;
7937 psymbol
.aclass
= LOC_TYPEDEF
;
7938 where
= psymbol_placement::GLOBAL
;
7941 case DW_TAG_class_type
:
7942 case DW_TAG_interface_type
:
7943 case DW_TAG_structure_type
:
7944 case DW_TAG_union_type
:
7945 case DW_TAG_enumeration_type
:
7946 /* Skip external references. The DWARF standard says in the section
7947 about "Structure, Union, and Class Type Entries": "An incomplete
7948 structure, union or class type is represented by a structure,
7949 union or class entry that does not have a byte size attribute
7950 and that has a DW_AT_declaration attribute." */
7951 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7954 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7955 static vs. global. */
7956 psymbol
.domain
= STRUCT_DOMAIN
;
7957 psymbol
.aclass
= LOC_TYPEDEF
;
7958 where
= (cu
->language
== language_cplus
7959 ? psymbol_placement::GLOBAL
7960 : psymbol_placement::STATIC
);
7962 case DW_TAG_enumerator
:
7963 psymbol
.domain
= VAR_DOMAIN
;
7964 psymbol
.aclass
= LOC_CONST
;
7965 where
= (cu
->language
== language_cplus
7966 ? psymbol_placement::GLOBAL
7967 : psymbol_placement::STATIC
);
7973 if (where
.has_value ())
7975 if (built_actual_name
!= nullptr)
7976 actual_name
= objfile
->intern (actual_name
);
7977 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
7978 psymbol
.ginfo
.set_linkage_name (actual_name
);
7981 psymbol
.ginfo
.set_demangled_name (actual_name
,
7982 &objfile
->objfile_obstack
);
7983 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
7985 cu
->per_cu
->v
.psymtab
->add_psymbol
7986 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7991 /* Read a partial die corresponding to a namespace; also, add a symbol
7992 corresponding to that namespace to the symbol table. NAMESPACE is
7993 the name of the enclosing namespace. */
7996 add_partial_namespace (struct partial_die_info
*pdi
,
7997 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7998 int set_addrmap
, struct dwarf2_cu
*cu
)
8000 /* Add a symbol for the namespace. */
8002 add_partial_symbol (pdi
, cu
);
8004 /* Now scan partial symbols in that namespace. */
8006 if (pdi
->has_children
)
8007 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8010 /* Read a partial die corresponding to a Fortran module. */
8013 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8014 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8016 /* Add a symbol for the namespace. */
8018 add_partial_symbol (pdi
, cu
);
8020 /* Now scan partial symbols in that module. */
8022 if (pdi
->has_children
)
8023 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8026 /* Read a partial die corresponding to a subprogram or an inlined
8027 subprogram and create a partial symbol for that subprogram.
8028 When the CU language allows it, this routine also defines a partial
8029 symbol for each nested subprogram that this subprogram contains.
8030 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8031 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8033 PDI may also be a lexical block, in which case we simply search
8034 recursively for subprograms defined inside that lexical block.
8035 Again, this is only performed when the CU language allows this
8036 type of definitions. */
8039 add_partial_subprogram (struct partial_die_info
*pdi
,
8040 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8041 int set_addrmap
, struct dwarf2_cu
*cu
)
8043 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8045 if (pdi
->has_pc_info
)
8047 if (pdi
->lowpc
< *lowpc
)
8048 *lowpc
= pdi
->lowpc
;
8049 if (pdi
->highpc
> *highpc
)
8050 *highpc
= pdi
->highpc
;
8053 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8054 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8055 struct gdbarch
*gdbarch
= objfile
->arch ();
8057 CORE_ADDR this_highpc
;
8058 CORE_ADDR this_lowpc
;
8060 baseaddr
= objfile
->text_section_offset ();
8062 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8063 pdi
->lowpc
+ baseaddr
)
8066 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8067 pdi
->highpc
+ baseaddr
)
8069 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8070 this_lowpc
, this_highpc
- 1,
8071 cu
->per_cu
->v
.psymtab
);
8075 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8077 if (!pdi
->is_declaration
)
8078 /* Ignore subprogram DIEs that do not have a name, they are
8079 illegal. Do not emit a complaint at this point, we will
8080 do so when we convert this psymtab into a symtab. */
8082 add_partial_symbol (pdi
, cu
);
8086 if (! pdi
->has_children
)
8089 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8091 pdi
= pdi
->die_child
;
8095 if (pdi
->tag
== DW_TAG_subprogram
8096 || pdi
->tag
== DW_TAG_inlined_subroutine
8097 || pdi
->tag
== DW_TAG_lexical_block
)
8098 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8099 pdi
= pdi
->die_sibling
;
8104 /* Read a partial die corresponding to an enumeration type. */
8107 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8108 struct dwarf2_cu
*cu
)
8110 struct partial_die_info
*pdi
;
8112 if (enum_pdi
->name (cu
) != NULL
)
8113 add_partial_symbol (enum_pdi
, cu
);
8115 pdi
= enum_pdi
->die_child
;
8118 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8119 complaint (_("malformed enumerator DIE ignored"));
8121 add_partial_symbol (pdi
, cu
);
8122 pdi
= pdi
->die_sibling
;
8126 /* Return the initial uleb128 in the die at INFO_PTR. */
8129 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8131 unsigned int bytes_read
;
8133 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8136 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8137 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8139 Return the corresponding abbrev, or NULL if the number is zero (indicating
8140 an empty DIE). In either case *BYTES_READ will be set to the length of
8141 the initial number. */
8143 static const struct abbrev_info
*
8144 peek_die_abbrev (const die_reader_specs
&reader
,
8145 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8147 dwarf2_cu
*cu
= reader
.cu
;
8148 bfd
*abfd
= reader
.abfd
;
8149 unsigned int abbrev_number
8150 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8152 if (abbrev_number
== 0)
8155 const abbrev_info
*abbrev
8156 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8159 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8160 " at offset %s [in module %s]"),
8161 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8162 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8168 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8169 Returns a pointer to the end of a series of DIEs, terminated by an empty
8170 DIE. Any children of the skipped DIEs will also be skipped. */
8172 static const gdb_byte
*
8173 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8177 unsigned int bytes_read
;
8178 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8182 return info_ptr
+ bytes_read
;
8184 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8188 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8189 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8190 abbrev corresponding to that skipped uleb128 should be passed in
8191 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8194 static const gdb_byte
*
8195 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8196 const struct abbrev_info
*abbrev
)
8198 unsigned int bytes_read
;
8199 struct attribute attr
;
8200 bfd
*abfd
= reader
->abfd
;
8201 struct dwarf2_cu
*cu
= reader
->cu
;
8202 const gdb_byte
*buffer
= reader
->buffer
;
8203 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8204 unsigned int form
, i
;
8206 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8208 /* The only abbrev we care about is DW_AT_sibling. */
8209 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8211 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8212 if (attr
.form
== DW_FORM_ref_addr
)
8213 complaint (_("ignoring absolute DW_AT_sibling"));
8216 sect_offset off
= attr
.get_ref_die_offset ();
8217 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8219 if (sibling_ptr
< info_ptr
)
8220 complaint (_("DW_AT_sibling points backwards"));
8221 else if (sibling_ptr
> reader
->buffer_end
)
8222 reader
->die_section
->overflow_complaint ();
8228 /* If it isn't DW_AT_sibling, skip this attribute. */
8229 form
= abbrev
->attrs
[i
].form
;
8233 case DW_FORM_ref_addr
:
8234 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8235 and later it is offset sized. */
8236 if (cu
->header
.version
== 2)
8237 info_ptr
+= cu
->header
.addr_size
;
8239 info_ptr
+= cu
->header
.offset_size
;
8241 case DW_FORM_GNU_ref_alt
:
8242 info_ptr
+= cu
->header
.offset_size
;
8245 info_ptr
+= cu
->header
.addr_size
;
8253 case DW_FORM_flag_present
:
8254 case DW_FORM_implicit_const
:
8271 case DW_FORM_ref_sig8
:
8274 case DW_FORM_data16
:
8277 case DW_FORM_string
:
8278 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8279 info_ptr
+= bytes_read
;
8281 case DW_FORM_sec_offset
:
8283 case DW_FORM_GNU_strp_alt
:
8284 info_ptr
+= cu
->header
.offset_size
;
8286 case DW_FORM_exprloc
:
8288 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8289 info_ptr
+= bytes_read
;
8291 case DW_FORM_block1
:
8292 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8294 case DW_FORM_block2
:
8295 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8297 case DW_FORM_block4
:
8298 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8304 case DW_FORM_ref_udata
:
8305 case DW_FORM_GNU_addr_index
:
8306 case DW_FORM_GNU_str_index
:
8307 case DW_FORM_rnglistx
:
8308 case DW_FORM_loclistx
:
8309 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8311 case DW_FORM_indirect
:
8312 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8313 info_ptr
+= bytes_read
;
8314 /* We need to continue parsing from here, so just go back to
8316 goto skip_attribute
;
8319 error (_("Dwarf Error: Cannot handle %s "
8320 "in DWARF reader [in module %s]"),
8321 dwarf_form_name (form
),
8322 bfd_get_filename (abfd
));
8326 if (abbrev
->has_children
)
8327 return skip_children (reader
, info_ptr
);
8332 /* Locate ORIG_PDI's sibling.
8333 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8335 static const gdb_byte
*
8336 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8337 struct partial_die_info
*orig_pdi
,
8338 const gdb_byte
*info_ptr
)
8340 /* Do we know the sibling already? */
8342 if (orig_pdi
->sibling
)
8343 return orig_pdi
->sibling
;
8345 /* Are there any children to deal with? */
8347 if (!orig_pdi
->has_children
)
8350 /* Skip the children the long way. */
8352 return skip_children (reader
, info_ptr
);
8355 /* Expand this partial symbol table into a full symbol table. SELF is
8359 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8361 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8363 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8365 /* If this psymtab is constructed from a debug-only objfile, the
8366 has_section_at_zero flag will not necessarily be correct. We
8367 can get the correct value for this flag by looking at the data
8368 associated with the (presumably stripped) associated objfile. */
8369 if (objfile
->separate_debug_objfile_backlink
)
8371 dwarf2_per_objfile
*per_objfile_backlink
8372 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8374 per_objfile
->per_bfd
->has_section_at_zero
8375 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8378 expand_psymtab (objfile
);
8380 process_cu_includes (per_objfile
);
8383 /* Reading in full CUs. */
8385 /* Add PER_CU to the queue. */
8388 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8389 dwarf2_per_objfile
*per_objfile
,
8390 enum language pretend_language
)
8394 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8395 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8398 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8400 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8403 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8404 DIEs, false otherwise.
8406 Explanation: there is an invariant that if a CU is queued for expansion
8407 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8408 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8409 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8410 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8411 invariant is respected.
8413 The caller is therefore not required to load the CU's DIEs (we return false)
8416 - the CU is already expanded, and therefore does not get enqueued
8417 - the CU gets enqueued for expansion, but its DIEs are already loaded
8419 Note that the caller should not use this function's return value as an
8420 indicator of whether the CU's DIEs are loaded right now, it should check
8421 that by calling `dwarf2_per_objfile::get_cu` instead. */
8424 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8425 dwarf2_per_cu_data
*per_cu
,
8426 dwarf2_per_objfile
*per_objfile
,
8427 enum language pretend_language
)
8429 /* We may arrive here during partial symbol reading, if we need full
8430 DIEs to process an unusual case (e.g. template arguments). Do
8431 not queue PER_CU, just tell our caller to load its DIEs. */
8432 if (per_cu
->per_bfd
->reading_partial_symbols
)
8434 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8436 if (cu
== NULL
|| cu
->dies
== NULL
)
8441 /* Mark the dependence relation so that we don't flush PER_CU
8443 if (dependent_cu
!= NULL
)
8444 dependent_cu
->add_dependence (per_cu
);
8446 /* If it's already on the queue, we have nothing to do. */
8449 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8451 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8453 /* If the CU is queued for expansion, it should not already be
8455 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8457 /* The DIEs are already loaded, the caller doesn't need to do it. */
8461 bool queued
= false;
8462 if (!per_objfile
->symtab_set_p (per_cu
))
8464 /* Add it to the queue. */
8465 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8469 /* If the compilation unit is already loaded, just mark it as
8471 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8475 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8476 and the DIEs are not already loaded. */
8477 return queued
&& cu
== nullptr;
8480 /* Process the queue. */
8483 process_queue (dwarf2_per_objfile
*per_objfile
)
8485 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8486 objfile_name (per_objfile
->objfile
));
8488 /* The queue starts out with one item, but following a DIE reference
8489 may load a new CU, adding it to the end of the queue. */
8490 while (!per_objfile
->per_bfd
->queue
->empty ())
8492 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8493 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8495 if (!per_objfile
->symtab_set_p (per_cu
))
8497 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8499 /* Skip dummy CUs. */
8502 unsigned int debug_print_threshold
;
8505 if (per_cu
->is_debug_types
)
8507 struct signatured_type
*sig_type
=
8508 (struct signatured_type
*) per_cu
;
8510 sprintf (buf
, "TU %s at offset %s",
8511 hex_string (sig_type
->signature
),
8512 sect_offset_str (per_cu
->sect_off
));
8513 /* There can be 100s of TUs.
8514 Only print them in verbose mode. */
8515 debug_print_threshold
= 2;
8519 sprintf (buf
, "CU at offset %s",
8520 sect_offset_str (per_cu
->sect_off
));
8521 debug_print_threshold
= 1;
8524 if (dwarf_read_debug
>= debug_print_threshold
)
8525 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8527 if (per_cu
->is_debug_types
)
8528 process_full_type_unit (cu
, item
.pretend_language
);
8530 process_full_comp_unit (cu
, item
.pretend_language
);
8532 if (dwarf_read_debug
>= debug_print_threshold
)
8533 dwarf_read_debug_printf ("Done expanding %s", buf
);
8538 per_objfile
->per_bfd
->queue
->pop ();
8541 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8542 objfile_name (per_objfile
->objfile
));
8545 /* Read in full symbols for PST, and anything it depends on. */
8548 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8550 gdb_assert (!readin_p (objfile
));
8552 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8553 free_cached_comp_units
freer (per_objfile
);
8554 expand_dependencies (objfile
);
8556 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8557 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8560 /* See psympriv.h. */
8563 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8565 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8566 return per_objfile
->symtab_set_p (per_cu_data
);
8569 /* See psympriv.h. */
8572 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8574 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8575 return per_objfile
->get_symtab (per_cu_data
);
8578 /* Trivial hash function for die_info: the hash value of a DIE
8579 is its offset in .debug_info for this objfile. */
8582 die_hash (const void *item
)
8584 const struct die_info
*die
= (const struct die_info
*) item
;
8586 return to_underlying (die
->sect_off
);
8589 /* Trivial comparison function for die_info structures: two DIEs
8590 are equal if they have the same offset. */
8593 die_eq (const void *item_lhs
, const void *item_rhs
)
8595 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8596 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8598 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8601 /* Load the DIEs associated with PER_CU into memory.
8603 In some cases, the caller, while reading partial symbols, will need to load
8604 the full symbols for the CU for some reason. It will already have a
8605 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8606 rather than creating a new one. */
8609 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8610 dwarf2_per_objfile
*per_objfile
,
8611 dwarf2_cu
*existing_cu
,
8613 enum language pretend_language
)
8615 gdb_assert (! this_cu
->is_debug_types
);
8617 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8621 struct dwarf2_cu
*cu
= reader
.cu
;
8622 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8624 gdb_assert (cu
->die_hash
== NULL
);
8626 htab_create_alloc_ex (cu
->header
.length
/ 12,
8630 &cu
->comp_unit_obstack
,
8631 hashtab_obstack_allocate
,
8632 dummy_obstack_deallocate
);
8634 if (reader
.comp_unit_die
->has_children
)
8635 reader
.comp_unit_die
->child
8636 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8637 &info_ptr
, reader
.comp_unit_die
);
8638 cu
->dies
= reader
.comp_unit_die
;
8639 /* comp_unit_die is not stored in die_hash, no need. */
8641 /* We try not to read any attributes in this function, because not
8642 all CUs needed for references have been loaded yet, and symbol
8643 table processing isn't initialized. But we have to set the CU language,
8644 or we won't be able to build types correctly.
8645 Similarly, if we do not read the producer, we can not apply
8646 producer-specific interpretation. */
8647 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8652 /* Add a DIE to the delayed physname list. */
8655 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8656 const char *name
, struct die_info
*die
,
8657 struct dwarf2_cu
*cu
)
8659 struct delayed_method_info mi
;
8661 mi
.fnfield_index
= fnfield_index
;
8665 cu
->method_list
.push_back (mi
);
8668 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8669 "const" / "volatile". If so, decrements LEN by the length of the
8670 modifier and return true. Otherwise return false. */
8674 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8676 size_t mod_len
= sizeof (mod
) - 1;
8677 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8685 /* Compute the physnames of any methods on the CU's method list.
8687 The computation of method physnames is delayed in order to avoid the
8688 (bad) condition that one of the method's formal parameters is of an as yet
8692 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8694 /* Only C++ delays computing physnames. */
8695 if (cu
->method_list
.empty ())
8697 gdb_assert (cu
->language
== language_cplus
);
8699 for (const delayed_method_info
&mi
: cu
->method_list
)
8701 const char *physname
;
8702 struct fn_fieldlist
*fn_flp
8703 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8704 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8705 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8706 = physname
? physname
: "";
8708 /* Since there's no tag to indicate whether a method is a
8709 const/volatile overload, extract that information out of the
8711 if (physname
!= NULL
)
8713 size_t len
= strlen (physname
);
8717 if (physname
[len
] == ')') /* shortcut */
8719 else if (check_modifier (physname
, len
, " const"))
8720 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8721 else if (check_modifier (physname
, len
, " volatile"))
8722 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8729 /* The list is no longer needed. */
8730 cu
->method_list
.clear ();
8733 /* Go objects should be embedded in a DW_TAG_module DIE,
8734 and it's not clear if/how imported objects will appear.
8735 To keep Go support simple until that's worked out,
8736 go back through what we've read and create something usable.
8737 We could do this while processing each DIE, and feels kinda cleaner,
8738 but that way is more invasive.
8739 This is to, for example, allow the user to type "p var" or "b main"
8740 without having to specify the package name, and allow lookups
8741 of module.object to work in contexts that use the expression
8745 fixup_go_packaging (struct dwarf2_cu
*cu
)
8747 gdb::unique_xmalloc_ptr
<char> package_name
;
8748 struct pending
*list
;
8751 for (list
= *cu
->get_builder ()->get_global_symbols ();
8755 for (i
= 0; i
< list
->nsyms
; ++i
)
8757 struct symbol
*sym
= list
->symbol
[i
];
8759 if (sym
->language () == language_go
8760 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8762 gdb::unique_xmalloc_ptr
<char> this_package_name
8763 (go_symbol_package_name (sym
));
8765 if (this_package_name
== NULL
)
8767 if (package_name
== NULL
)
8768 package_name
= std::move (this_package_name
);
8771 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8772 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8773 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8774 (symbol_symtab (sym
) != NULL
8775 ? symtab_to_filename_for_display
8776 (symbol_symtab (sym
))
8777 : objfile_name (objfile
)),
8778 this_package_name
.get (), package_name
.get ());
8784 if (package_name
!= NULL
)
8786 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8787 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8788 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8789 saved_package_name
);
8792 sym
= new (&objfile
->objfile_obstack
) symbol
;
8793 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8794 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8795 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8796 e.g., "main" finds the "main" module and not C's main(). */
8797 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8798 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8799 SYMBOL_TYPE (sym
) = type
;
8801 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8805 /* Allocate a fully-qualified name consisting of the two parts on the
8809 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8811 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8814 /* A helper that allocates a variant part to attach to a Rust enum
8815 type. OBSTACK is where the results should be allocated. TYPE is
8816 the type we're processing. DISCRIMINANT_INDEX is the index of the
8817 discriminant. It must be the index of one of the fields of TYPE,
8818 or -1 to mean there is no discriminant (univariant enum).
8819 DEFAULT_INDEX is the index of the default field; or -1 if there is
8820 no default. RANGES is indexed by "effective" field number (the
8821 field index, but omitting the discriminant and default fields) and
8822 must hold the discriminant values used by the variants. Note that
8823 RANGES must have a lifetime at least as long as OBSTACK -- either
8824 already allocated on it, or static. */
8827 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8828 int discriminant_index
, int default_index
,
8829 gdb::array_view
<discriminant_range
> ranges
)
8831 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8832 gdb_assert (discriminant_index
== -1
8833 || (discriminant_index
>= 0
8834 && discriminant_index
< type
->num_fields ()));
8835 gdb_assert (default_index
== -1
8836 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8838 /* We have one variant for each non-discriminant field. */
8839 int n_variants
= type
->num_fields ();
8840 if (discriminant_index
!= -1)
8843 variant
*variants
= new (obstack
) variant
[n_variants
];
8846 for (int i
= 0; i
< type
->num_fields (); ++i
)
8848 if (i
== discriminant_index
)
8851 variants
[var_idx
].first_field
= i
;
8852 variants
[var_idx
].last_field
= i
+ 1;
8854 /* The default field does not need a range, but other fields do.
8855 We skipped the discriminant above. */
8856 if (i
!= default_index
)
8858 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8865 gdb_assert (range_idx
== ranges
.size ());
8866 gdb_assert (var_idx
== n_variants
);
8868 variant_part
*part
= new (obstack
) variant_part
;
8869 part
->discriminant_index
= discriminant_index
;
8870 /* If there is no discriminant, then whether it is signed is of no
8873 = (discriminant_index
== -1
8875 : type
->field (discriminant_index
).type ()->is_unsigned ());
8876 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
8878 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
8879 gdb::array_view
<variant_part
> *prop_value
8880 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
8882 struct dynamic_prop prop
;
8883 prop
.set_variant_parts (prop_value
);
8885 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
8888 /* Some versions of rustc emitted enums in an unusual way.
8890 Ordinary enums were emitted as unions. The first element of each
8891 structure in the union was named "RUST$ENUM$DISR". This element
8892 held the discriminant.
8894 These versions of Rust also implemented the "non-zero"
8895 optimization. When the enum had two values, and one is empty and
8896 the other holds a pointer that cannot be zero, the pointer is used
8897 as the discriminant, with a zero value meaning the empty variant.
8898 Here, the union's first member is of the form
8899 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8900 where the fieldnos are the indices of the fields that should be
8901 traversed in order to find the field (which may be several fields deep)
8902 and the variantname is the name of the variant of the case when the
8905 This function recognizes whether TYPE is of one of these forms,
8906 and, if so, smashes it to be a variant type. */
8909 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
8911 gdb_assert (type
->code () == TYPE_CODE_UNION
);
8913 /* We don't need to deal with empty enums. */
8914 if (type
->num_fields () == 0)
8917 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8918 if (type
->num_fields () == 1
8919 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
8921 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
8923 /* Decode the field name to find the offset of the
8925 ULONGEST bit_offset
= 0;
8926 struct type
*field_type
= type
->field (0).type ();
8927 while (name
[0] >= '0' && name
[0] <= '9')
8930 unsigned long index
= strtoul (name
, &tail
, 10);
8933 || index
>= field_type
->num_fields ()
8934 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
8935 != FIELD_LOC_KIND_BITPOS
))
8937 complaint (_("Could not parse Rust enum encoding string \"%s\""
8939 TYPE_FIELD_NAME (type
, 0),
8940 objfile_name (objfile
));
8945 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
8946 field_type
= field_type
->field (index
).type ();
8949 /* Smash this type to be a structure type. We have to do this
8950 because the type has already been recorded. */
8951 type
->set_code (TYPE_CODE_STRUCT
);
8952 type
->set_num_fields (3);
8953 /* Save the field we care about. */
8954 struct field saved_field
= type
->field (0);
8956 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
8958 /* Put the discriminant at index 0. */
8959 type
->field (0).set_type (field_type
);
8960 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
8961 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
8962 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
8964 /* The order of fields doesn't really matter, so put the real
8965 field at index 1 and the data-less field at index 2. */
8966 type
->field (1) = saved_field
;
8967 TYPE_FIELD_NAME (type
, 1)
8968 = rust_last_path_segment (type
->field (1).type ()->name ());
8969 type
->field (1).type ()->set_name
8970 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8971 TYPE_FIELD_NAME (type
, 1)));
8973 const char *dataless_name
8974 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8976 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
8978 type
->field (2).set_type (dataless_type
);
8979 /* NAME points into the original discriminant name, which
8980 already has the correct lifetime. */
8981 TYPE_FIELD_NAME (type
, 2) = name
;
8982 SET_FIELD_BITPOS (type
->field (2), 0);
8984 /* Indicate that this is a variant type. */
8985 static discriminant_range ranges
[1] = { { 0, 0 } };
8986 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
8988 /* A union with a single anonymous field is probably an old-style
8990 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
8992 /* Smash this type to be a structure type. We have to do this
8993 because the type has already been recorded. */
8994 type
->set_code (TYPE_CODE_STRUCT
);
8996 struct type
*field_type
= type
->field (0).type ();
8997 const char *variant_name
8998 = rust_last_path_segment (field_type
->name ());
8999 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9000 field_type
->set_name
9001 (rust_fully_qualify (&objfile
->objfile_obstack
,
9002 type
->name (), variant_name
));
9004 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9008 struct type
*disr_type
= nullptr;
9009 for (int i
= 0; i
< type
->num_fields (); ++i
)
9011 disr_type
= type
->field (i
).type ();
9013 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9015 /* All fields of a true enum will be structs. */
9018 else if (disr_type
->num_fields () == 0)
9020 /* Could be data-less variant, so keep going. */
9021 disr_type
= nullptr;
9023 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9024 "RUST$ENUM$DISR") != 0)
9026 /* Not a Rust enum. */
9036 /* If we got here without a discriminant, then it's probably
9038 if (disr_type
== nullptr)
9041 /* Smash this type to be a structure type. We have to do this
9042 because the type has already been recorded. */
9043 type
->set_code (TYPE_CODE_STRUCT
);
9045 /* Make space for the discriminant field. */
9046 struct field
*disr_field
= &disr_type
->field (0);
9048 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9049 * sizeof (struct field
)));
9050 memcpy (new_fields
+ 1, type
->fields (),
9051 type
->num_fields () * sizeof (struct field
));
9052 type
->set_fields (new_fields
);
9053 type
->set_num_fields (type
->num_fields () + 1);
9055 /* Install the discriminant at index 0 in the union. */
9056 type
->field (0) = *disr_field
;
9057 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9058 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9060 /* We need a way to find the correct discriminant given a
9061 variant name. For convenience we build a map here. */
9062 struct type
*enum_type
= disr_field
->type ();
9063 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9064 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9066 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9069 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9070 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9074 int n_fields
= type
->num_fields ();
9075 /* We don't need a range entry for the discriminant, but we do
9076 need one for every other field, as there is no default
9078 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9081 /* Skip the discriminant here. */
9082 for (int i
= 1; i
< n_fields
; ++i
)
9084 /* Find the final word in the name of this variant's type.
9085 That name can be used to look up the correct
9087 const char *variant_name
9088 = rust_last_path_segment (type
->field (i
).type ()->name ());
9090 auto iter
= discriminant_map
.find (variant_name
);
9091 if (iter
!= discriminant_map
.end ())
9093 ranges
[i
- 1].low
= iter
->second
;
9094 ranges
[i
- 1].high
= iter
->second
;
9097 /* In Rust, each element should have the size of the
9099 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9101 /* Remove the discriminant field, if it exists. */
9102 struct type
*sub_type
= type
->field (i
).type ();
9103 if (sub_type
->num_fields () > 0)
9105 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9106 sub_type
->set_fields (sub_type
->fields () + 1);
9108 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9110 (rust_fully_qualify (&objfile
->objfile_obstack
,
9111 type
->name (), variant_name
));
9114 /* Indicate that this is a variant type. */
9115 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9116 gdb::array_view
<discriminant_range
> (ranges
,
9121 /* Rewrite some Rust unions to be structures with variants parts. */
9124 rust_union_quirks (struct dwarf2_cu
*cu
)
9126 gdb_assert (cu
->language
== language_rust
);
9127 for (type
*type_
: cu
->rust_unions
)
9128 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9129 /* We don't need this any more. */
9130 cu
->rust_unions
.clear ();
9135 type_unit_group_unshareable
*
9136 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9138 auto iter
= this->m_type_units
.find (tu_group
);
9139 if (iter
!= this->m_type_units
.end ())
9140 return iter
->second
.get ();
9142 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9143 type_unit_group_unshareable
*result
= uniq
.get ();
9144 this->m_type_units
[tu_group
] = std::move (uniq
);
9149 dwarf2_per_objfile::get_type_for_signatured_type
9150 (signatured_type
*sig_type
) const
9152 auto iter
= this->m_type_map
.find (sig_type
);
9153 if (iter
== this->m_type_map
.end ())
9156 return iter
->second
;
9159 void dwarf2_per_objfile::set_type_for_signatured_type
9160 (signatured_type
*sig_type
, struct type
*type
)
9162 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9164 this->m_type_map
[sig_type
] = type
;
9167 /* A helper function for computing the list of all symbol tables
9168 included by PER_CU. */
9171 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9172 htab_t all_children
, htab_t all_type_symtabs
,
9173 dwarf2_per_cu_data
*per_cu
,
9174 dwarf2_per_objfile
*per_objfile
,
9175 struct compunit_symtab
*immediate_parent
)
9177 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9180 /* This inclusion and its children have been processed. */
9186 /* Only add a CU if it has a symbol table. */
9187 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9190 /* If this is a type unit only add its symbol table if we haven't
9191 seen it yet (type unit per_cu's can share symtabs). */
9192 if (per_cu
->is_debug_types
)
9194 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9198 result
->push_back (cust
);
9199 if (cust
->user
== NULL
)
9200 cust
->user
= immediate_parent
;
9205 result
->push_back (cust
);
9206 if (cust
->user
== NULL
)
9207 cust
->user
= immediate_parent
;
9211 if (!per_cu
->imported_symtabs_empty ())
9212 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9214 recursively_compute_inclusions (result
, all_children
,
9215 all_type_symtabs
, ptr
, per_objfile
,
9220 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9224 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9225 dwarf2_per_objfile
*per_objfile
)
9227 gdb_assert (! per_cu
->is_debug_types
);
9229 if (!per_cu
->imported_symtabs_empty ())
9232 std::vector
<compunit_symtab
*> result_symtabs
;
9233 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9235 /* If we don't have a symtab, we can just skip this case. */
9239 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9241 NULL
, xcalloc
, xfree
));
9242 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9244 NULL
, xcalloc
, xfree
));
9246 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9248 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9249 all_type_symtabs
.get (), ptr
,
9253 /* Now we have a transitive closure of all the included symtabs. */
9254 len
= result_symtabs
.size ();
9256 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9257 struct compunit_symtab
*, len
+ 1);
9258 memcpy (cust
->includes
, result_symtabs
.data (),
9259 len
* sizeof (compunit_symtab
*));
9260 cust
->includes
[len
] = NULL
;
9264 /* Compute the 'includes' field for the symtabs of all the CUs we just
9268 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9270 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9272 if (! iter
->is_debug_types
)
9273 compute_compunit_symtab_includes (iter
, per_objfile
);
9276 per_objfile
->per_bfd
->just_read_cus
.clear ();
9279 /* Generate full symbol information for CU, whose DIEs have
9280 already been loaded into memory. */
9283 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9285 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9286 struct objfile
*objfile
= per_objfile
->objfile
;
9287 struct gdbarch
*gdbarch
= objfile
->arch ();
9288 CORE_ADDR lowpc
, highpc
;
9289 struct compunit_symtab
*cust
;
9291 struct block
*static_block
;
9294 baseaddr
= objfile
->text_section_offset ();
9296 /* Clear the list here in case something was left over. */
9297 cu
->method_list
.clear ();
9299 cu
->language
= pretend_language
;
9300 cu
->language_defn
= language_def (cu
->language
);
9302 dwarf2_find_base_address (cu
->dies
, cu
);
9304 /* Before we start reading the top-level DIE, ensure it has a valid tag
9306 switch (cu
->dies
->tag
)
9308 case DW_TAG_compile_unit
:
9309 case DW_TAG_partial_unit
:
9310 case DW_TAG_type_unit
:
9313 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9314 dwarf_tag_name (cu
->dies
->tag
),
9315 sect_offset_str (cu
->per_cu
->sect_off
),
9316 objfile_name (per_objfile
->objfile
));
9319 /* Do line number decoding in read_file_scope () */
9320 process_die (cu
->dies
, cu
);
9322 /* For now fudge the Go package. */
9323 if (cu
->language
== language_go
)
9324 fixup_go_packaging (cu
);
9326 /* Now that we have processed all the DIEs in the CU, all the types
9327 should be complete, and it should now be safe to compute all of the
9329 compute_delayed_physnames (cu
);
9331 if (cu
->language
== language_rust
)
9332 rust_union_quirks (cu
);
9334 /* Some compilers don't define a DW_AT_high_pc attribute for the
9335 compilation unit. If the DW_AT_high_pc is missing, synthesize
9336 it, by scanning the DIE's below the compilation unit. */
9337 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9339 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9340 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9342 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9343 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9344 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9345 addrmap to help ensure it has an accurate map of pc values belonging to
9347 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9349 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9350 SECT_OFF_TEXT (objfile
),
9355 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9357 /* Set symtab language to language from DW_AT_language. If the
9358 compilation is from a C file generated by language preprocessors, do
9359 not set the language if it was already deduced by start_subfile. */
9360 if (!(cu
->language
== language_c
9361 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9362 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9364 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9365 produce DW_AT_location with location lists but it can be possibly
9366 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9367 there were bugs in prologue debug info, fixed later in GCC-4.5
9368 by "unwind info for epilogues" patch (which is not directly related).
9370 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9371 needed, it would be wrong due to missing DW_AT_producer there.
9373 Still one can confuse GDB by using non-standard GCC compilation
9374 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9376 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9377 cust
->locations_valid
= 1;
9379 if (gcc_4_minor
>= 5)
9380 cust
->epilogue_unwind_valid
= 1;
9382 cust
->call_site_htab
= cu
->call_site_htab
;
9385 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9387 /* Push it for inclusion processing later. */
9388 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9390 /* Not needed any more. */
9391 cu
->reset_builder ();
9394 /* Generate full symbol information for type unit CU, whose DIEs have
9395 already been loaded into memory. */
9398 process_full_type_unit (dwarf2_cu
*cu
,
9399 enum language pretend_language
)
9401 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9402 struct objfile
*objfile
= per_objfile
->objfile
;
9403 struct compunit_symtab
*cust
;
9404 struct signatured_type
*sig_type
;
9406 gdb_assert (cu
->per_cu
->is_debug_types
);
9407 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9409 /* Clear the list here in case something was left over. */
9410 cu
->method_list
.clear ();
9412 cu
->language
= pretend_language
;
9413 cu
->language_defn
= language_def (cu
->language
);
9415 /* The symbol tables are set up in read_type_unit_scope. */
9416 process_die (cu
->dies
, cu
);
9418 /* For now fudge the Go package. */
9419 if (cu
->language
== language_go
)
9420 fixup_go_packaging (cu
);
9422 /* Now that we have processed all the DIEs in the CU, all the types
9423 should be complete, and it should now be safe to compute all of the
9425 compute_delayed_physnames (cu
);
9427 if (cu
->language
== language_rust
)
9428 rust_union_quirks (cu
);
9430 /* TUs share symbol tables.
9431 If this is the first TU to use this symtab, complete the construction
9432 of it with end_expandable_symtab. Otherwise, complete the addition of
9433 this TU's symbols to the existing symtab. */
9434 type_unit_group_unshareable
*tug_unshare
=
9435 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9436 if (tug_unshare
->compunit_symtab
== NULL
)
9438 buildsym_compunit
*builder
= cu
->get_builder ();
9439 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9440 tug_unshare
->compunit_symtab
= cust
;
9444 /* Set symtab language to language from DW_AT_language. If the
9445 compilation is from a C file generated by language preprocessors,
9446 do not set the language if it was already deduced by
9448 if (!(cu
->language
== language_c
9449 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9450 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9455 cu
->get_builder ()->augment_type_symtab ();
9456 cust
= tug_unshare
->compunit_symtab
;
9459 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9461 /* Not needed any more. */
9462 cu
->reset_builder ();
9465 /* Process an imported unit DIE. */
9468 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9470 struct attribute
*attr
;
9472 /* For now we don't handle imported units in type units. */
9473 if (cu
->per_cu
->is_debug_types
)
9475 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9476 " supported in type units [in module %s]"),
9477 objfile_name (cu
->per_objfile
->objfile
));
9480 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9483 sect_offset sect_off
= attr
->get_ref_die_offset ();
9484 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9485 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9486 dwarf2_per_cu_data
*per_cu
9487 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9489 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9490 into another compilation unit, at root level. Regard this as a hint,
9492 if (die
->parent
&& die
->parent
->parent
== NULL
9493 && per_cu
->unit_type
== DW_UT_compile
9494 && per_cu
->lang
== language_cplus
)
9497 /* If necessary, add it to the queue and load its DIEs. */
9498 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9499 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9500 false, cu
->language
);
9502 cu
->per_cu
->imported_symtabs_push (per_cu
);
9506 /* RAII object that represents a process_die scope: i.e.,
9507 starts/finishes processing a DIE. */
9508 class process_die_scope
9511 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9512 : m_die (die
), m_cu (cu
)
9514 /* We should only be processing DIEs not already in process. */
9515 gdb_assert (!m_die
->in_process
);
9516 m_die
->in_process
= true;
9519 ~process_die_scope ()
9521 m_die
->in_process
= false;
9523 /* If we're done processing the DIE for the CU that owns the line
9524 header, we don't need the line header anymore. */
9525 if (m_cu
->line_header_die_owner
== m_die
)
9527 delete m_cu
->line_header
;
9528 m_cu
->line_header
= NULL
;
9529 m_cu
->line_header_die_owner
= NULL
;
9538 /* Process a die and its children. */
9541 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9543 process_die_scope
scope (die
, cu
);
9547 case DW_TAG_padding
:
9549 case DW_TAG_compile_unit
:
9550 case DW_TAG_partial_unit
:
9551 read_file_scope (die
, cu
);
9553 case DW_TAG_type_unit
:
9554 read_type_unit_scope (die
, cu
);
9556 case DW_TAG_subprogram
:
9557 /* Nested subprograms in Fortran get a prefix. */
9558 if (cu
->language
== language_fortran
9559 && die
->parent
!= NULL
9560 && die
->parent
->tag
== DW_TAG_subprogram
)
9561 cu
->processing_has_namespace_info
= true;
9563 case DW_TAG_inlined_subroutine
:
9564 read_func_scope (die
, cu
);
9566 case DW_TAG_lexical_block
:
9567 case DW_TAG_try_block
:
9568 case DW_TAG_catch_block
:
9569 read_lexical_block_scope (die
, cu
);
9571 case DW_TAG_call_site
:
9572 case DW_TAG_GNU_call_site
:
9573 read_call_site_scope (die
, cu
);
9575 case DW_TAG_class_type
:
9576 case DW_TAG_interface_type
:
9577 case DW_TAG_structure_type
:
9578 case DW_TAG_union_type
:
9579 process_structure_scope (die
, cu
);
9581 case DW_TAG_enumeration_type
:
9582 process_enumeration_scope (die
, cu
);
9585 /* These dies have a type, but processing them does not create
9586 a symbol or recurse to process the children. Therefore we can
9587 read them on-demand through read_type_die. */
9588 case DW_TAG_subroutine_type
:
9589 case DW_TAG_set_type
:
9590 case DW_TAG_pointer_type
:
9591 case DW_TAG_ptr_to_member_type
:
9592 case DW_TAG_reference_type
:
9593 case DW_TAG_rvalue_reference_type
:
9594 case DW_TAG_string_type
:
9597 case DW_TAG_array_type
:
9598 /* We only need to handle this case for Ada -- in other
9599 languages, it's normal for the compiler to emit a typedef
9601 if (cu
->language
!= language_ada
)
9604 case DW_TAG_base_type
:
9605 case DW_TAG_subrange_type
:
9606 case DW_TAG_typedef
:
9607 /* Add a typedef symbol for the type definition, if it has a
9609 new_symbol (die
, read_type_die (die
, cu
), cu
);
9611 case DW_TAG_common_block
:
9612 read_common_block (die
, cu
);
9614 case DW_TAG_common_inclusion
:
9616 case DW_TAG_namespace
:
9617 cu
->processing_has_namespace_info
= true;
9618 read_namespace (die
, cu
);
9621 cu
->processing_has_namespace_info
= true;
9622 read_module (die
, cu
);
9624 case DW_TAG_imported_declaration
:
9625 cu
->processing_has_namespace_info
= true;
9626 if (read_namespace_alias (die
, cu
))
9628 /* The declaration is not a global namespace alias. */
9630 case DW_TAG_imported_module
:
9631 cu
->processing_has_namespace_info
= true;
9632 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9633 || cu
->language
!= language_fortran
))
9634 complaint (_("Tag '%s' has unexpected children"),
9635 dwarf_tag_name (die
->tag
));
9636 read_import_statement (die
, cu
);
9639 case DW_TAG_imported_unit
:
9640 process_imported_unit_die (die
, cu
);
9643 case DW_TAG_variable
:
9644 read_variable (die
, cu
);
9648 new_symbol (die
, NULL
, cu
);
9653 /* DWARF name computation. */
9655 /* A helper function for dwarf2_compute_name which determines whether DIE
9656 needs to have the name of the scope prepended to the name listed in the
9660 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9662 struct attribute
*attr
;
9666 case DW_TAG_namespace
:
9667 case DW_TAG_typedef
:
9668 case DW_TAG_class_type
:
9669 case DW_TAG_interface_type
:
9670 case DW_TAG_structure_type
:
9671 case DW_TAG_union_type
:
9672 case DW_TAG_enumeration_type
:
9673 case DW_TAG_enumerator
:
9674 case DW_TAG_subprogram
:
9675 case DW_TAG_inlined_subroutine
:
9677 case DW_TAG_imported_declaration
:
9680 case DW_TAG_variable
:
9681 case DW_TAG_constant
:
9682 /* We only need to prefix "globally" visible variables. These include
9683 any variable marked with DW_AT_external or any variable that
9684 lives in a namespace. [Variables in anonymous namespaces
9685 require prefixing, but they are not DW_AT_external.] */
9687 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9689 struct dwarf2_cu
*spec_cu
= cu
;
9691 return die_needs_namespace (die_specification (die
, &spec_cu
),
9695 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9696 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9697 && die
->parent
->tag
!= DW_TAG_module
)
9699 /* A variable in a lexical block of some kind does not need a
9700 namespace, even though in C++ such variables may be external
9701 and have a mangled name. */
9702 if (die
->parent
->tag
== DW_TAG_lexical_block
9703 || die
->parent
->tag
== DW_TAG_try_block
9704 || die
->parent
->tag
== DW_TAG_catch_block
9705 || die
->parent
->tag
== DW_TAG_subprogram
)
9714 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9715 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9716 defined for the given DIE. */
9718 static struct attribute
*
9719 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9721 struct attribute
*attr
;
9723 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9725 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9730 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9731 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9732 defined for the given DIE. */
9735 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9737 const char *linkage_name
;
9739 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9740 if (linkage_name
== NULL
)
9741 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9743 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9744 See https://github.com/rust-lang/rust/issues/32925. */
9745 if (cu
->language
== language_rust
&& linkage_name
!= NULL
9746 && strchr (linkage_name
, '{') != NULL
)
9747 linkage_name
= NULL
;
9749 return linkage_name
;
9752 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9753 compute the physname for the object, which include a method's:
9754 - formal parameters (C++),
9755 - receiver type (Go),
9757 The term "physname" is a bit confusing.
9758 For C++, for example, it is the demangled name.
9759 For Go, for example, it's the mangled name.
9761 For Ada, return the DIE's linkage name rather than the fully qualified
9762 name. PHYSNAME is ignored..
9764 The result is allocated on the objfile->per_bfd's obstack and
9768 dwarf2_compute_name (const char *name
,
9769 struct die_info
*die
, struct dwarf2_cu
*cu
,
9772 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9775 name
= dwarf2_name (die
, cu
);
9777 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9778 but otherwise compute it by typename_concat inside GDB.
9779 FIXME: Actually this is not really true, or at least not always true.
9780 It's all very confusing. compute_and_set_names doesn't try to demangle
9781 Fortran names because there is no mangling standard. So new_symbol
9782 will set the demangled name to the result of dwarf2_full_name, and it is
9783 the demangled name that GDB uses if it exists. */
9784 if (cu
->language
== language_ada
9785 || (cu
->language
== language_fortran
&& physname
))
9787 /* For Ada unit, we prefer the linkage name over the name, as
9788 the former contains the exported name, which the user expects
9789 to be able to reference. Ideally, we want the user to be able
9790 to reference this entity using either natural or linkage name,
9791 but we haven't started looking at this enhancement yet. */
9792 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9794 if (linkage_name
!= NULL
)
9795 return linkage_name
;
9798 /* These are the only languages we know how to qualify names in. */
9800 && (cu
->language
== language_cplus
9801 || cu
->language
== language_fortran
|| cu
->language
== language_d
9802 || cu
->language
== language_rust
))
9804 if (die_needs_namespace (die
, cu
))
9807 const char *canonical_name
= NULL
;
9811 prefix
= determine_prefix (die
, cu
);
9812 if (*prefix
!= '\0')
9814 gdb::unique_xmalloc_ptr
<char> prefixed_name
9815 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9817 buf
.puts (prefixed_name
.get ());
9822 /* Template parameters may be specified in the DIE's DW_AT_name, or
9823 as children with DW_TAG_template_type_param or
9824 DW_TAG_value_type_param. If the latter, add them to the name
9825 here. If the name already has template parameters, then
9826 skip this step; some versions of GCC emit both, and
9827 it is more efficient to use the pre-computed name.
9829 Something to keep in mind about this process: it is very
9830 unlikely, or in some cases downright impossible, to produce
9831 something that will match the mangled name of a function.
9832 If the definition of the function has the same debug info,
9833 we should be able to match up with it anyway. But fallbacks
9834 using the minimal symbol, for instance to find a method
9835 implemented in a stripped copy of libstdc++, will not work.
9836 If we do not have debug info for the definition, we will have to
9837 match them up some other way.
9839 When we do name matching there is a related problem with function
9840 templates; two instantiated function templates are allowed to
9841 differ only by their return types, which we do not add here. */
9843 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
9845 struct attribute
*attr
;
9846 struct die_info
*child
;
9848 const language_defn
*cplus_lang
= language_def (cu
->language
);
9850 die
->building_fullname
= 1;
9852 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9856 const gdb_byte
*bytes
;
9857 struct dwarf2_locexpr_baton
*baton
;
9860 if (child
->tag
!= DW_TAG_template_type_param
9861 && child
->tag
!= DW_TAG_template_value_param
)
9872 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9875 complaint (_("template parameter missing DW_AT_type"));
9876 buf
.puts ("UNKNOWN_TYPE");
9879 type
= die_type (child
, cu
);
9881 if (child
->tag
== DW_TAG_template_type_param
)
9883 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
9884 &type_print_raw_options
);
9888 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9891 complaint (_("template parameter missing "
9892 "DW_AT_const_value"));
9893 buf
.puts ("UNKNOWN_VALUE");
9897 dwarf2_const_value_attr (attr
, type
, name
,
9898 &cu
->comp_unit_obstack
, cu
,
9899 &value
, &bytes
, &baton
);
9901 if (type
->has_no_signedness ())
9902 /* GDB prints characters as NUMBER 'CHAR'. If that's
9903 changed, this can use value_print instead. */
9904 cplus_lang
->printchar (value
, type
, &buf
);
9907 struct value_print_options opts
;
9910 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9914 baton
->per_objfile
);
9915 else if (bytes
!= NULL
)
9917 v
= allocate_value (type
);
9918 memcpy (value_contents_writeable (v
), bytes
,
9919 TYPE_LENGTH (type
));
9922 v
= value_from_longest (type
, value
);
9924 /* Specify decimal so that we do not depend on
9926 get_formatted_print_options (&opts
, 'd');
9928 value_print (v
, &buf
, &opts
);
9933 die
->building_fullname
= 0;
9937 /* Close the argument list, with a space if necessary
9938 (nested templates). */
9939 if (!buf
.empty () && buf
.string ().back () == '>')
9946 /* For C++ methods, append formal parameter type
9947 information, if PHYSNAME. */
9949 if (physname
&& die
->tag
== DW_TAG_subprogram
9950 && cu
->language
== language_cplus
)
9952 struct type
*type
= read_type_die (die
, cu
);
9954 c_type_print_args (type
, &buf
, 1, cu
->language
,
9955 &type_print_raw_options
);
9957 if (cu
->language
== language_cplus
)
9959 /* Assume that an artificial first parameter is
9960 "this", but do not crash if it is not. RealView
9961 marks unnamed (and thus unused) parameters as
9962 artificial; there is no way to differentiate
9964 if (type
->num_fields () > 0
9965 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9966 && type
->field (0).type ()->code () == TYPE_CODE_PTR
9967 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
9968 buf
.puts (" const");
9972 const std::string
&intermediate_name
= buf
.string ();
9974 if (cu
->language
== language_cplus
)
9976 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9979 /* If we only computed INTERMEDIATE_NAME, or if
9980 INTERMEDIATE_NAME is already canonical, then we need to
9982 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9983 name
= objfile
->intern (intermediate_name
);
9985 name
= canonical_name
;
9992 /* Return the fully qualified name of DIE, based on its DW_AT_name.
9993 If scope qualifiers are appropriate they will be added. The result
9994 will be allocated on the storage_obstack, or NULL if the DIE does
9995 not have a name. NAME may either be from a previous call to
9996 dwarf2_name or NULL.
9998 The output string will be canonicalized (if C++). */
10000 static const char *
10001 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10003 return dwarf2_compute_name (name
, die
, cu
, 0);
10006 /* Construct a physname for the given DIE in CU. NAME may either be
10007 from a previous call to dwarf2_name or NULL. The result will be
10008 allocated on the objfile_objstack or NULL if the DIE does not have a
10011 The output string will be canonicalized (if C++). */
10013 static const char *
10014 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10016 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10017 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10020 /* In this case dwarf2_compute_name is just a shortcut not building anything
10022 if (!die_needs_namespace (die
, cu
))
10023 return dwarf2_compute_name (name
, die
, cu
, 1);
10025 if (cu
->language
!= language_rust
)
10026 mangled
= dw2_linkage_name (die
, cu
);
10028 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10030 gdb::unique_xmalloc_ptr
<char> demangled
;
10031 if (mangled
!= NULL
)
10034 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10036 /* Do nothing (do not demangle the symbol name). */
10040 /* Use DMGL_RET_DROP for C++ template functions to suppress
10041 their return type. It is easier for GDB users to search
10042 for such functions as `name(params)' than `long name(params)'.
10043 In such case the minimal symbol names do not match the full
10044 symbol names but for template functions there is never a need
10045 to look up their definition from their declaration so
10046 the only disadvantage remains the minimal symbol variant
10047 `long name(params)' does not have the proper inferior type. */
10048 demangled
.reset (gdb_demangle (mangled
,
10049 (DMGL_PARAMS
| DMGL_ANSI
10050 | DMGL_RET_DROP
)));
10053 canon
= demangled
.get ();
10061 if (canon
== NULL
|| check_physname
)
10063 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10065 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10067 /* It may not mean a bug in GDB. The compiler could also
10068 compute DW_AT_linkage_name incorrectly. But in such case
10069 GDB would need to be bug-to-bug compatible. */
10071 complaint (_("Computed physname <%s> does not match demangled <%s> "
10072 "(from linkage <%s>) - DIE at %s [in module %s]"),
10073 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10074 objfile_name (objfile
));
10076 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10077 is available here - over computed PHYSNAME. It is safer
10078 against both buggy GDB and buggy compilers. */
10092 retval
= objfile
->intern (retval
);
10097 /* Inspect DIE in CU for a namespace alias. If one exists, record
10098 a new symbol for it.
10100 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10103 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10105 struct attribute
*attr
;
10107 /* If the die does not have a name, this is not a namespace
10109 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10113 struct die_info
*d
= die
;
10114 struct dwarf2_cu
*imported_cu
= cu
;
10116 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10117 keep inspecting DIEs until we hit the underlying import. */
10118 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10119 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10121 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10125 d
= follow_die_ref (d
, attr
, &imported_cu
);
10126 if (d
->tag
!= DW_TAG_imported_declaration
)
10130 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10132 complaint (_("DIE at %s has too many recursively imported "
10133 "declarations"), sect_offset_str (d
->sect_off
));
10140 sect_offset sect_off
= attr
->get_ref_die_offset ();
10142 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10143 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10145 /* This declaration is a global namespace alias. Add
10146 a symbol for it whose type is the aliased namespace. */
10147 new_symbol (die
, type
, cu
);
10156 /* Return the using directives repository (global or local?) to use in the
10157 current context for CU.
10159 For Ada, imported declarations can materialize renamings, which *may* be
10160 global. However it is impossible (for now?) in DWARF to distinguish
10161 "external" imported declarations and "static" ones. As all imported
10162 declarations seem to be static in all other languages, make them all CU-wide
10163 global only in Ada. */
10165 static struct using_direct
**
10166 using_directives (struct dwarf2_cu
*cu
)
10168 if (cu
->language
== language_ada
10169 && cu
->get_builder ()->outermost_context_p ())
10170 return cu
->get_builder ()->get_global_using_directives ();
10172 return cu
->get_builder ()->get_local_using_directives ();
10175 /* Read the import statement specified by the given die and record it. */
10178 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10180 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10181 struct attribute
*import_attr
;
10182 struct die_info
*imported_die
, *child_die
;
10183 struct dwarf2_cu
*imported_cu
;
10184 const char *imported_name
;
10185 const char *imported_name_prefix
;
10186 const char *canonical_name
;
10187 const char *import_alias
;
10188 const char *imported_declaration
= NULL
;
10189 const char *import_prefix
;
10190 std::vector
<const char *> excludes
;
10192 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10193 if (import_attr
== NULL
)
10195 complaint (_("Tag '%s' has no DW_AT_import"),
10196 dwarf_tag_name (die
->tag
));
10201 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10202 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10203 if (imported_name
== NULL
)
10205 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10207 The import in the following code:
10221 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10222 <52> DW_AT_decl_file : 1
10223 <53> DW_AT_decl_line : 6
10224 <54> DW_AT_import : <0x75>
10225 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10226 <59> DW_AT_name : B
10227 <5b> DW_AT_decl_file : 1
10228 <5c> DW_AT_decl_line : 2
10229 <5d> DW_AT_type : <0x6e>
10231 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10232 <76> DW_AT_byte_size : 4
10233 <77> DW_AT_encoding : 5 (signed)
10235 imports the wrong die ( 0x75 instead of 0x58 ).
10236 This case will be ignored until the gcc bug is fixed. */
10240 /* Figure out the local name after import. */
10241 import_alias
= dwarf2_name (die
, cu
);
10243 /* Figure out where the statement is being imported to. */
10244 import_prefix
= determine_prefix (die
, cu
);
10246 /* Figure out what the scope of the imported die is and prepend it
10247 to the name of the imported die. */
10248 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10250 if (imported_die
->tag
!= DW_TAG_namespace
10251 && imported_die
->tag
!= DW_TAG_module
)
10253 imported_declaration
= imported_name
;
10254 canonical_name
= imported_name_prefix
;
10256 else if (strlen (imported_name_prefix
) > 0)
10257 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10258 imported_name_prefix
,
10259 (cu
->language
== language_d
? "." : "::"),
10260 imported_name
, (char *) NULL
);
10262 canonical_name
= imported_name
;
10264 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10265 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10266 child_die
= child_die
->sibling
)
10268 /* DWARF-4: A Fortran use statement with a “rename list” may be
10269 represented by an imported module entry with an import attribute
10270 referring to the module and owned entries corresponding to those
10271 entities that are renamed as part of being imported. */
10273 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10275 complaint (_("child DW_TAG_imported_declaration expected "
10276 "- DIE at %s [in module %s]"),
10277 sect_offset_str (child_die
->sect_off
),
10278 objfile_name (objfile
));
10282 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10283 if (import_attr
== NULL
)
10285 complaint (_("Tag '%s' has no DW_AT_import"),
10286 dwarf_tag_name (child_die
->tag
));
10291 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10293 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10294 if (imported_name
== NULL
)
10296 complaint (_("child DW_TAG_imported_declaration has unknown "
10297 "imported name - DIE at %s [in module %s]"),
10298 sect_offset_str (child_die
->sect_off
),
10299 objfile_name (objfile
));
10303 excludes
.push_back (imported_name
);
10305 process_die (child_die
, cu
);
10308 add_using_directive (using_directives (cu
),
10312 imported_declaration
,
10315 &objfile
->objfile_obstack
);
10318 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10319 types, but gives them a size of zero. Starting with version 14,
10320 ICC is compatible with GCC. */
10323 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10325 if (!cu
->checked_producer
)
10326 check_producer (cu
);
10328 return cu
->producer_is_icc_lt_14
;
10331 /* ICC generates a DW_AT_type for C void functions. This was observed on
10332 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10333 which says that void functions should not have a DW_AT_type. */
10336 producer_is_icc (struct dwarf2_cu
*cu
)
10338 if (!cu
->checked_producer
)
10339 check_producer (cu
);
10341 return cu
->producer_is_icc
;
10344 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10345 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10346 this, it was first present in GCC release 4.3.0. */
10349 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10351 if (!cu
->checked_producer
)
10352 check_producer (cu
);
10354 return cu
->producer_is_gcc_lt_4_3
;
10357 static file_and_directory
10358 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10360 file_and_directory res
;
10362 /* Find the filename. Do not use dwarf2_name here, since the filename
10363 is not a source language identifier. */
10364 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10365 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10367 if (res
.comp_dir
== NULL
10368 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10369 && IS_ABSOLUTE_PATH (res
.name
))
10371 res
.comp_dir_storage
= ldirname (res
.name
);
10372 if (!res
.comp_dir_storage
.empty ())
10373 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10375 if (res
.comp_dir
!= NULL
)
10377 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10378 directory, get rid of it. */
10379 const char *cp
= strchr (res
.comp_dir
, ':');
10381 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10382 res
.comp_dir
= cp
+ 1;
10385 if (res
.name
== NULL
)
10386 res
.name
= "<unknown>";
10391 /* Handle DW_AT_stmt_list for a compilation unit.
10392 DIE is the DW_TAG_compile_unit die for CU.
10393 COMP_DIR is the compilation directory. LOWPC is passed to
10394 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10397 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10398 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10400 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10401 struct attribute
*attr
;
10402 struct line_header line_header_local
;
10403 hashval_t line_header_local_hash
;
10405 int decode_mapping
;
10407 gdb_assert (! cu
->per_cu
->is_debug_types
);
10409 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10410 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10413 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10415 /* The line header hash table is only created if needed (it exists to
10416 prevent redundant reading of the line table for partial_units).
10417 If we're given a partial_unit, we'll need it. If we're given a
10418 compile_unit, then use the line header hash table if it's already
10419 created, but don't create one just yet. */
10421 if (per_objfile
->line_header_hash
== NULL
10422 && die
->tag
== DW_TAG_partial_unit
)
10424 per_objfile
->line_header_hash
10425 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10426 line_header_eq_voidp
,
10427 htab_delete_entry
<line_header
>,
10431 line_header_local
.sect_off
= line_offset
;
10432 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10433 line_header_local_hash
= line_header_hash (&line_header_local
);
10434 if (per_objfile
->line_header_hash
!= NULL
)
10436 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10437 &line_header_local
,
10438 line_header_local_hash
, NO_INSERT
);
10440 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10441 is not present in *SLOT (since if there is something in *SLOT then
10442 it will be for a partial_unit). */
10443 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10445 gdb_assert (*slot
!= NULL
);
10446 cu
->line_header
= (struct line_header
*) *slot
;
10451 /* dwarf_decode_line_header does not yet provide sufficient information.
10452 We always have to call also dwarf_decode_lines for it. */
10453 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10457 cu
->line_header
= lh
.release ();
10458 cu
->line_header_die_owner
= die
;
10460 if (per_objfile
->line_header_hash
== NULL
)
10464 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10465 &line_header_local
,
10466 line_header_local_hash
, INSERT
);
10467 gdb_assert (slot
!= NULL
);
10469 if (slot
!= NULL
&& *slot
== NULL
)
10471 /* This newly decoded line number information unit will be owned
10472 by line_header_hash hash table. */
10473 *slot
= cu
->line_header
;
10474 cu
->line_header_die_owner
= NULL
;
10478 /* We cannot free any current entry in (*slot) as that struct line_header
10479 may be already used by multiple CUs. Create only temporary decoded
10480 line_header for this CU - it may happen at most once for each line
10481 number information unit. And if we're not using line_header_hash
10482 then this is what we want as well. */
10483 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10485 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10486 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10491 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10494 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10496 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10497 struct objfile
*objfile
= per_objfile
->objfile
;
10498 struct gdbarch
*gdbarch
= objfile
->arch ();
10499 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10500 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10501 struct attribute
*attr
;
10502 struct die_info
*child_die
;
10503 CORE_ADDR baseaddr
;
10505 prepare_one_comp_unit (cu
, die
, cu
->language
);
10506 baseaddr
= objfile
->text_section_offset ();
10508 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10510 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10511 from finish_block. */
10512 if (lowpc
== ((CORE_ADDR
) -1))
10514 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10516 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10518 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10519 standardised yet. As a workaround for the language detection we fall
10520 back to the DW_AT_producer string. */
10521 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10522 cu
->language
= language_opencl
;
10524 /* Similar hack for Go. */
10525 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10526 set_cu_language (DW_LANG_Go
, cu
);
10528 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10530 /* Decode line number information if present. We do this before
10531 processing child DIEs, so that the line header table is available
10532 for DW_AT_decl_file. */
10533 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10535 /* Process all dies in compilation unit. */
10536 if (die
->child
!= NULL
)
10538 child_die
= die
->child
;
10539 while (child_die
&& child_die
->tag
)
10541 process_die (child_die
, cu
);
10542 child_die
= child_die
->sibling
;
10546 /* Decode macro information, if present. Dwarf 2 macro information
10547 refers to information in the line number info statement program
10548 header, so we can only read it if we've read the header
10550 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10552 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10553 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10555 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10556 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10558 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10562 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10563 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10565 unsigned int macro_offset
= attr
->as_unsigned ();
10567 dwarf_decode_macros (cu
, macro_offset
, 0);
10573 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10575 struct type_unit_group
*tu_group
;
10577 struct attribute
*attr
;
10579 struct signatured_type
*sig_type
;
10581 gdb_assert (per_cu
->is_debug_types
);
10582 sig_type
= (struct signatured_type
*) per_cu
;
10584 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10586 /* If we're using .gdb_index (includes -readnow) then
10587 per_cu->type_unit_group may not have been set up yet. */
10588 if (sig_type
->type_unit_group
== NULL
)
10589 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10590 tu_group
= sig_type
->type_unit_group
;
10592 /* If we've already processed this stmt_list there's no real need to
10593 do it again, we could fake it and just recreate the part we need
10594 (file name,index -> symtab mapping). If data shows this optimization
10595 is useful we can do it then. */
10596 type_unit_group_unshareable
*tug_unshare
10597 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10598 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10600 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10603 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10605 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10606 lh
= dwarf_decode_line_header (line_offset
, this);
10611 start_symtab ("", NULL
, 0);
10614 gdb_assert (tug_unshare
->symtabs
== NULL
);
10615 gdb_assert (m_builder
== nullptr);
10616 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10617 m_builder
.reset (new struct buildsym_compunit
10618 (COMPUNIT_OBJFILE (cust
), "",
10619 COMPUNIT_DIRNAME (cust
),
10620 compunit_language (cust
),
10622 list_in_scope
= get_builder ()->get_file_symbols ();
10627 line_header
= lh
.release ();
10628 line_header_die_owner
= die
;
10632 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10634 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10635 still initializing it, and our caller (a few levels up)
10636 process_full_type_unit still needs to know if this is the first
10639 tug_unshare
->symtabs
10640 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10641 struct symtab
*, line_header
->file_names_size ());
10643 auto &file_names
= line_header
->file_names ();
10644 for (i
= 0; i
< file_names
.size (); ++i
)
10646 file_entry
&fe
= file_names
[i
];
10647 dwarf2_start_subfile (this, fe
.name
,
10648 fe
.include_dir (line_header
));
10649 buildsym_compunit
*b
= get_builder ();
10650 if (b
->get_current_subfile ()->symtab
== NULL
)
10652 /* NOTE: start_subfile will recognize when it's been
10653 passed a file it has already seen. So we can't
10654 assume there's a simple mapping from
10655 cu->line_header->file_names to subfiles, plus
10656 cu->line_header->file_names may contain dups. */
10657 b
->get_current_subfile ()->symtab
10658 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10661 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10662 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10667 gdb_assert (m_builder
== nullptr);
10668 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10669 m_builder
.reset (new struct buildsym_compunit
10670 (COMPUNIT_OBJFILE (cust
), "",
10671 COMPUNIT_DIRNAME (cust
),
10672 compunit_language (cust
),
10674 list_in_scope
= get_builder ()->get_file_symbols ();
10676 auto &file_names
= line_header
->file_names ();
10677 for (i
= 0; i
< file_names
.size (); ++i
)
10679 file_entry
&fe
= file_names
[i
];
10680 fe
.symtab
= tug_unshare
->symtabs
[i
];
10684 /* The main symtab is allocated last. Type units don't have DW_AT_name
10685 so they don't have a "real" (so to speak) symtab anyway.
10686 There is later code that will assign the main symtab to all symbols
10687 that don't have one. We need to handle the case of a symbol with a
10688 missing symtab (DW_AT_decl_file) anyway. */
10691 /* Process DW_TAG_type_unit.
10692 For TUs we want to skip the first top level sibling if it's not the
10693 actual type being defined by this TU. In this case the first top
10694 level sibling is there to provide context only. */
10697 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10699 struct die_info
*child_die
;
10701 prepare_one_comp_unit (cu
, die
, language_minimal
);
10703 /* Initialize (or reinitialize) the machinery for building symtabs.
10704 We do this before processing child DIEs, so that the line header table
10705 is available for DW_AT_decl_file. */
10706 cu
->setup_type_unit_groups (die
);
10708 if (die
->child
!= NULL
)
10710 child_die
= die
->child
;
10711 while (child_die
&& child_die
->tag
)
10713 process_die (child_die
, cu
);
10714 child_die
= child_die
->sibling
;
10721 http://gcc.gnu.org/wiki/DebugFission
10722 http://gcc.gnu.org/wiki/DebugFissionDWP
10724 To simplify handling of both DWO files ("object" files with the DWARF info)
10725 and DWP files (a file with the DWOs packaged up into one file), we treat
10726 DWP files as having a collection of virtual DWO files. */
10729 hash_dwo_file (const void *item
)
10731 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10734 hash
= htab_hash_string (dwo_file
->dwo_name
);
10735 if (dwo_file
->comp_dir
!= NULL
)
10736 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10741 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10743 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10744 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10746 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10748 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10749 return lhs
->comp_dir
== rhs
->comp_dir
;
10750 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10753 /* Allocate a hash table for DWO files. */
10756 allocate_dwo_file_hash_table ()
10758 return htab_up (htab_create_alloc (41,
10761 htab_delete_entry
<dwo_file
>,
10765 /* Lookup DWO file DWO_NAME. */
10768 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10769 const char *dwo_name
,
10770 const char *comp_dir
)
10772 struct dwo_file find_entry
;
10775 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10776 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10778 find_entry
.dwo_name
= dwo_name
;
10779 find_entry
.comp_dir
= comp_dir
;
10780 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10787 hash_dwo_unit (const void *item
)
10789 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10791 /* This drops the top 32 bits of the id, but is ok for a hash. */
10792 return dwo_unit
->signature
;
10796 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10798 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10799 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10801 /* The signature is assumed to be unique within the DWO file.
10802 So while object file CU dwo_id's always have the value zero,
10803 that's OK, assuming each object file DWO file has only one CU,
10804 and that's the rule for now. */
10805 return lhs
->signature
== rhs
->signature
;
10808 /* Allocate a hash table for DWO CUs,TUs.
10809 There is one of these tables for each of CUs,TUs for each DWO file. */
10812 allocate_dwo_unit_table ()
10814 /* Start out with a pretty small number.
10815 Generally DWO files contain only one CU and maybe some TUs. */
10816 return htab_up (htab_create_alloc (3,
10819 NULL
, xcalloc
, xfree
));
10822 /* die_reader_func for create_dwo_cu. */
10825 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10826 const gdb_byte
*info_ptr
,
10827 struct die_info
*comp_unit_die
,
10828 struct dwo_file
*dwo_file
,
10829 struct dwo_unit
*dwo_unit
)
10831 struct dwarf2_cu
*cu
= reader
->cu
;
10832 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10833 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10835 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10836 if (!signature
.has_value ())
10838 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10839 " its dwo_id [in module %s]"),
10840 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10844 dwo_unit
->dwo_file
= dwo_file
;
10845 dwo_unit
->signature
= *signature
;
10846 dwo_unit
->section
= section
;
10847 dwo_unit
->sect_off
= sect_off
;
10848 dwo_unit
->length
= cu
->per_cu
->length
;
10850 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10851 sect_offset_str (sect_off
),
10852 hex_string (dwo_unit
->signature
));
10855 /* Create the dwo_units for the CUs in a DWO_FILE.
10856 Note: This function processes DWO files only, not DWP files. */
10859 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10860 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10861 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10863 struct objfile
*objfile
= per_objfile
->objfile
;
10864 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10865 const gdb_byte
*info_ptr
, *end_ptr
;
10867 section
.read (objfile
);
10868 info_ptr
= section
.buffer
;
10870 if (info_ptr
== NULL
)
10873 dwarf_read_debug_printf ("Reading %s for %s:",
10874 section
.get_name (),
10875 section
.get_file_name ());
10877 end_ptr
= info_ptr
+ section
.size
;
10878 while (info_ptr
< end_ptr
)
10880 struct dwarf2_per_cu_data per_cu
;
10881 struct dwo_unit read_unit
{};
10882 struct dwo_unit
*dwo_unit
;
10884 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10886 per_cu
.per_bfd
= per_bfd
;
10887 per_cu
.is_debug_types
= 0;
10888 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10889 per_cu
.section
= §ion
;
10891 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10892 if (!reader
.dummy_p
)
10893 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10894 &dwo_file
, &read_unit
);
10895 info_ptr
+= per_cu
.length
;
10897 // If the unit could not be parsed, skip it.
10898 if (read_unit
.dwo_file
== NULL
)
10901 if (cus_htab
== NULL
)
10902 cus_htab
= allocate_dwo_unit_table ();
10904 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
10906 *dwo_unit
= read_unit
;
10907 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
10908 gdb_assert (slot
!= NULL
);
10911 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10912 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10914 complaint (_("debug cu entry at offset %s is duplicate to"
10915 " the entry at offset %s, signature %s"),
10916 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
10917 hex_string (dwo_unit
->signature
));
10919 *slot
= (void *)dwo_unit
;
10923 /* DWP file .debug_{cu,tu}_index section format:
10924 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10925 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10927 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10928 officially standard DWP format was published with DWARF v5 and is called
10929 Version 5. There are no versions 3 or 4.
10933 Both index sections have the same format, and serve to map a 64-bit
10934 signature to a set of section numbers. Each section begins with a header,
10935 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10936 indexes, and a pool of 32-bit section numbers. The index sections will be
10937 aligned at 8-byte boundaries in the file.
10939 The index section header consists of:
10941 V, 32 bit version number
10943 N, 32 bit number of compilation units or type units in the index
10944 M, 32 bit number of slots in the hash table
10946 Numbers are recorded using the byte order of the application binary.
10948 The hash table begins at offset 16 in the section, and consists of an array
10949 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10950 order of the application binary). Unused slots in the hash table are 0.
10951 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10953 The parallel table begins immediately after the hash table
10954 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10955 array of 32-bit indexes (using the byte order of the application binary),
10956 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10957 table contains a 32-bit index into the pool of section numbers. For unused
10958 hash table slots, the corresponding entry in the parallel table will be 0.
10960 The pool of section numbers begins immediately following the hash table
10961 (at offset 16 + 12 * M from the beginning of the section). The pool of
10962 section numbers consists of an array of 32-bit words (using the byte order
10963 of the application binary). Each item in the array is indexed starting
10964 from 0. The hash table entry provides the index of the first section
10965 number in the set. Additional section numbers in the set follow, and the
10966 set is terminated by a 0 entry (section number 0 is not used in ELF).
10968 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10969 section must be the first entry in the set, and the .debug_abbrev.dwo must
10970 be the second entry. Other members of the set may follow in any order.
10974 DWP Versions 2 and 5:
10976 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
10977 and the entries in the index tables are now offsets into these sections.
10978 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10981 Index Section Contents:
10983 Hash Table of Signatures dwp_hash_table.hash_table
10984 Parallel Table of Indices dwp_hash_table.unit_table
10985 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
10986 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
10988 The index section header consists of:
10990 V, 32 bit version number
10991 L, 32 bit number of columns in the table of section offsets
10992 N, 32 bit number of compilation units or type units in the index
10993 M, 32 bit number of slots in the hash table
10995 Numbers are recorded using the byte order of the application binary.
10997 The hash table has the same format as version 1.
10998 The parallel table of indices has the same format as version 1,
10999 except that the entries are origin-1 indices into the table of sections
11000 offsets and the table of section sizes.
11002 The table of offsets begins immediately following the parallel table
11003 (at offset 16 + 12 * M from the beginning of the section). The table is
11004 a two-dimensional array of 32-bit words (using the byte order of the
11005 application binary), with L columns and N+1 rows, in row-major order.
11006 Each row in the array is indexed starting from 0. The first row provides
11007 a key to the remaining rows: each column in this row provides an identifier
11008 for a debug section, and the offsets in the same column of subsequent rows
11009 refer to that section. The section identifiers for Version 2 are:
11011 DW_SECT_INFO 1 .debug_info.dwo
11012 DW_SECT_TYPES 2 .debug_types.dwo
11013 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11014 DW_SECT_LINE 4 .debug_line.dwo
11015 DW_SECT_LOC 5 .debug_loc.dwo
11016 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11017 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11018 DW_SECT_MACRO 8 .debug_macro.dwo
11020 The section identifiers for Version 5 are:
11022 DW_SECT_INFO_V5 1 .debug_info.dwo
11023 DW_SECT_RESERVED_V5 2 --
11024 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11025 DW_SECT_LINE_V5 4 .debug_line.dwo
11026 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11027 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11028 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11029 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11031 The offsets provided by the CU and TU index sections are the base offsets
11032 for the contributions made by each CU or TU to the corresponding section
11033 in the package file. Each CU and TU header contains an abbrev_offset
11034 field, used to find the abbreviations table for that CU or TU within the
11035 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11036 be interpreted as relative to the base offset given in the index section.
11037 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11038 should be interpreted as relative to the base offset for .debug_line.dwo,
11039 and offsets into other debug sections obtained from DWARF attributes should
11040 also be interpreted as relative to the corresponding base offset.
11042 The table of sizes begins immediately following the table of offsets.
11043 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11044 with L columns and N rows, in row-major order. Each row in the array is
11045 indexed starting from 1 (row 0 is shared by the two tables).
11049 Hash table lookup is handled the same in version 1 and 2:
11051 We assume that N and M will not exceed 2^32 - 1.
11052 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11054 Given a 64-bit compilation unit signature or a type signature S, an entry
11055 in the hash table is located as follows:
11057 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11058 the low-order k bits all set to 1.
11060 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11062 3) If the hash table entry at index H matches the signature, use that
11063 entry. If the hash table entry at index H is unused (all zeroes),
11064 terminate the search: the signature is not present in the table.
11066 4) Let H = (H + H') modulo M. Repeat at Step 3.
11068 Because M > N and H' and M are relatively prime, the search is guaranteed
11069 to stop at an unused slot or find the match. */
11071 /* Create a hash table to map DWO IDs to their CU/TU entry in
11072 .debug_{info,types}.dwo in DWP_FILE.
11073 Returns NULL if there isn't one.
11074 Note: This function processes DWP files only, not DWO files. */
11076 static struct dwp_hash_table
*
11077 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11078 struct dwp_file
*dwp_file
, int is_debug_types
)
11080 struct objfile
*objfile
= per_objfile
->objfile
;
11081 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11082 const gdb_byte
*index_ptr
, *index_end
;
11083 struct dwarf2_section_info
*index
;
11084 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11085 struct dwp_hash_table
*htab
;
11087 if (is_debug_types
)
11088 index
= &dwp_file
->sections
.tu_index
;
11090 index
= &dwp_file
->sections
.cu_index
;
11092 if (index
->empty ())
11094 index
->read (objfile
);
11096 index_ptr
= index
->buffer
;
11097 index_end
= index_ptr
+ index
->size
;
11099 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11100 For now it's safe to just read 4 bytes (particularly as it's difficult to
11101 tell if you're dealing with Version 5 before you've read the version). */
11102 version
= read_4_bytes (dbfd
, index_ptr
);
11104 if (version
== 2 || version
== 5)
11105 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11109 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11111 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11114 if (version
!= 1 && version
!= 2 && version
!= 5)
11116 error (_("Dwarf Error: unsupported DWP file version (%s)"
11117 " [in module %s]"),
11118 pulongest (version
), dwp_file
->name
);
11120 if (nr_slots
!= (nr_slots
& -nr_slots
))
11122 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11123 " is not power of 2 [in module %s]"),
11124 pulongest (nr_slots
), dwp_file
->name
);
11127 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11128 htab
->version
= version
;
11129 htab
->nr_columns
= nr_columns
;
11130 htab
->nr_units
= nr_units
;
11131 htab
->nr_slots
= nr_slots
;
11132 htab
->hash_table
= index_ptr
;
11133 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11135 /* Exit early if the table is empty. */
11136 if (nr_slots
== 0 || nr_units
== 0
11137 || (version
== 2 && nr_columns
== 0)
11138 || (version
== 5 && nr_columns
== 0))
11140 /* All must be zero. */
11141 if (nr_slots
!= 0 || nr_units
!= 0
11142 || (version
== 2 && nr_columns
!= 0)
11143 || (version
== 5 && nr_columns
!= 0))
11145 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11146 " all zero [in modules %s]"),
11154 htab
->section_pool
.v1
.indices
=
11155 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11156 /* It's harder to decide whether the section is too small in v1.
11157 V1 is deprecated anyway so we punt. */
11159 else if (version
== 2)
11161 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11162 int *ids
= htab
->section_pool
.v2
.section_ids
;
11163 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11164 /* Reverse map for error checking. */
11165 int ids_seen
[DW_SECT_MAX
+ 1];
11168 if (nr_columns
< 2)
11170 error (_("Dwarf Error: bad DWP hash table, too few columns"
11171 " in section table [in module %s]"),
11174 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11176 error (_("Dwarf Error: bad DWP hash table, too many columns"
11177 " in section table [in module %s]"),
11180 memset (ids
, 255, sizeof_ids
);
11181 memset (ids_seen
, 255, sizeof (ids_seen
));
11182 for (i
= 0; i
< nr_columns
; ++i
)
11184 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11186 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11188 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11189 " in section table [in module %s]"),
11190 id
, dwp_file
->name
);
11192 if (ids_seen
[id
] != -1)
11194 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11195 " id %d in section table [in module %s]"),
11196 id
, dwp_file
->name
);
11201 /* Must have exactly one info or types section. */
11202 if (((ids_seen
[DW_SECT_INFO
] != -1)
11203 + (ids_seen
[DW_SECT_TYPES
] != -1))
11206 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11207 " DWO info/types section [in module %s]"),
11210 /* Must have an abbrev section. */
11211 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11213 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11214 " section [in module %s]"),
11217 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11218 htab
->section_pool
.v2
.sizes
=
11219 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11220 * nr_units
* nr_columns
);
11221 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11222 * nr_units
* nr_columns
))
11225 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11226 " [in module %s]"),
11230 else /* version == 5 */
11232 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11233 int *ids
= htab
->section_pool
.v5
.section_ids
;
11234 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11235 /* Reverse map for error checking. */
11236 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11238 if (nr_columns
< 2)
11240 error (_("Dwarf Error: bad DWP hash table, too few columns"
11241 " in section table [in module %s]"),
11244 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11246 error (_("Dwarf Error: bad DWP hash table, too many columns"
11247 " in section table [in module %s]"),
11250 memset (ids
, 255, sizeof_ids
);
11251 memset (ids_seen
, 255, sizeof (ids_seen
));
11252 for (int i
= 0; i
< nr_columns
; ++i
)
11254 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11256 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11258 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11259 " in section table [in module %s]"),
11260 id
, dwp_file
->name
);
11262 if (ids_seen
[id
] != -1)
11264 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11265 " id %d in section table [in module %s]"),
11266 id
, dwp_file
->name
);
11271 /* Must have seen an info section. */
11272 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11274 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11275 " DWO info/types section [in module %s]"),
11278 /* Must have an abbrev section. */
11279 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11281 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11282 " section [in module %s]"),
11285 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11286 htab
->section_pool
.v5
.sizes
11287 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11288 * nr_units
* nr_columns
);
11289 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11290 * nr_units
* nr_columns
))
11293 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11294 " [in module %s]"),
11302 /* Update SECTIONS with the data from SECTP.
11304 This function is like the other "locate" section routines, but in
11305 this context the sections to read comes from the DWP V1 hash table,
11306 not the full ELF section table.
11308 The result is non-zero for success, or zero if an error was found. */
11311 locate_v1_virtual_dwo_sections (asection
*sectp
,
11312 struct virtual_v1_dwo_sections
*sections
)
11314 const struct dwop_section_names
*names
= &dwop_section_names
;
11316 if (names
->abbrev_dwo
.matches (sectp
->name
))
11318 /* There can be only one. */
11319 if (sections
->abbrev
.s
.section
!= NULL
)
11321 sections
->abbrev
.s
.section
= sectp
;
11322 sections
->abbrev
.size
= bfd_section_size (sectp
);
11324 else if (names
->info_dwo
.matches (sectp
->name
)
11325 || names
->types_dwo
.matches (sectp
->name
))
11327 /* There can be only one. */
11328 if (sections
->info_or_types
.s
.section
!= NULL
)
11330 sections
->info_or_types
.s
.section
= sectp
;
11331 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11333 else if (names
->line_dwo
.matches (sectp
->name
))
11335 /* There can be only one. */
11336 if (sections
->line
.s
.section
!= NULL
)
11338 sections
->line
.s
.section
= sectp
;
11339 sections
->line
.size
= bfd_section_size (sectp
);
11341 else if (names
->loc_dwo
.matches (sectp
->name
))
11343 /* There can be only one. */
11344 if (sections
->loc
.s
.section
!= NULL
)
11346 sections
->loc
.s
.section
= sectp
;
11347 sections
->loc
.size
= bfd_section_size (sectp
);
11349 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11351 /* There can be only one. */
11352 if (sections
->macinfo
.s
.section
!= NULL
)
11354 sections
->macinfo
.s
.section
= sectp
;
11355 sections
->macinfo
.size
= bfd_section_size (sectp
);
11357 else if (names
->macro_dwo
.matches (sectp
->name
))
11359 /* There can be only one. */
11360 if (sections
->macro
.s
.section
!= NULL
)
11362 sections
->macro
.s
.section
= sectp
;
11363 sections
->macro
.size
= bfd_section_size (sectp
);
11365 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11367 /* There can be only one. */
11368 if (sections
->str_offsets
.s
.section
!= NULL
)
11370 sections
->str_offsets
.s
.section
= sectp
;
11371 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11375 /* No other kind of section is valid. */
11382 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11383 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11384 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11385 This is for DWP version 1 files. */
11387 static struct dwo_unit
*
11388 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11389 struct dwp_file
*dwp_file
,
11390 uint32_t unit_index
,
11391 const char *comp_dir
,
11392 ULONGEST signature
, int is_debug_types
)
11394 const struct dwp_hash_table
*dwp_htab
=
11395 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11396 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11397 const char *kind
= is_debug_types
? "TU" : "CU";
11398 struct dwo_file
*dwo_file
;
11399 struct dwo_unit
*dwo_unit
;
11400 struct virtual_v1_dwo_sections sections
;
11401 void **dwo_file_slot
;
11404 gdb_assert (dwp_file
->version
== 1);
11406 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11407 kind
, pulongest (unit_index
), hex_string (signature
),
11410 /* Fetch the sections of this DWO unit.
11411 Put a limit on the number of sections we look for so that bad data
11412 doesn't cause us to loop forever. */
11414 #define MAX_NR_V1_DWO_SECTIONS \
11415 (1 /* .debug_info or .debug_types */ \
11416 + 1 /* .debug_abbrev */ \
11417 + 1 /* .debug_line */ \
11418 + 1 /* .debug_loc */ \
11419 + 1 /* .debug_str_offsets */ \
11420 + 1 /* .debug_macro or .debug_macinfo */ \
11421 + 1 /* trailing zero */)
11423 memset (§ions
, 0, sizeof (sections
));
11425 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11428 uint32_t section_nr
=
11429 read_4_bytes (dbfd
,
11430 dwp_htab
->section_pool
.v1
.indices
11431 + (unit_index
+ i
) * sizeof (uint32_t));
11433 if (section_nr
== 0)
11435 if (section_nr
>= dwp_file
->num_sections
)
11437 error (_("Dwarf Error: bad DWP hash table, section number too large"
11438 " [in module %s]"),
11442 sectp
= dwp_file
->elf_sections
[section_nr
];
11443 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11445 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11446 " [in module %s]"),
11452 || sections
.info_or_types
.empty ()
11453 || sections
.abbrev
.empty ())
11455 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11456 " [in module %s]"),
11459 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11461 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11462 " [in module %s]"),
11466 /* It's easier for the rest of the code if we fake a struct dwo_file and
11467 have dwo_unit "live" in that. At least for now.
11469 The DWP file can be made up of a random collection of CUs and TUs.
11470 However, for each CU + set of TUs that came from the same original DWO
11471 file, we can combine them back into a virtual DWO file to save space
11472 (fewer struct dwo_file objects to allocate). Remember that for really
11473 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11475 std::string virtual_dwo_name
=
11476 string_printf ("virtual-dwo/%d-%d-%d-%d",
11477 sections
.abbrev
.get_id (),
11478 sections
.line
.get_id (),
11479 sections
.loc
.get_id (),
11480 sections
.str_offsets
.get_id ());
11481 /* Can we use an existing virtual DWO file? */
11482 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11484 /* Create one if necessary. */
11485 if (*dwo_file_slot
== NULL
)
11487 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11488 virtual_dwo_name
.c_str ());
11490 dwo_file
= new struct dwo_file
;
11491 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11492 dwo_file
->comp_dir
= comp_dir
;
11493 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11494 dwo_file
->sections
.line
= sections
.line
;
11495 dwo_file
->sections
.loc
= sections
.loc
;
11496 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11497 dwo_file
->sections
.macro
= sections
.macro
;
11498 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11499 /* The "str" section is global to the entire DWP file. */
11500 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11501 /* The info or types section is assigned below to dwo_unit,
11502 there's no need to record it in dwo_file.
11503 Also, we can't simply record type sections in dwo_file because
11504 we record a pointer into the vector in dwo_unit. As we collect more
11505 types we'll grow the vector and eventually have to reallocate space
11506 for it, invalidating all copies of pointers into the previous
11508 *dwo_file_slot
= dwo_file
;
11512 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11513 virtual_dwo_name
.c_str ());
11515 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11518 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11519 dwo_unit
->dwo_file
= dwo_file
;
11520 dwo_unit
->signature
= signature
;
11521 dwo_unit
->section
=
11522 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11523 *dwo_unit
->section
= sections
.info_or_types
;
11524 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11529 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11530 simplify them. Given a pointer to the containing section SECTION, and
11531 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11532 virtual section of just that piece. */
11534 static struct dwarf2_section_info
11535 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11536 struct dwarf2_section_info
*section
,
11537 bfd_size_type offset
, bfd_size_type size
)
11539 struct dwarf2_section_info result
;
11542 gdb_assert (section
!= NULL
);
11543 gdb_assert (!section
->is_virtual
);
11545 memset (&result
, 0, sizeof (result
));
11546 result
.s
.containing_section
= section
;
11547 result
.is_virtual
= true;
11552 sectp
= section
->get_bfd_section ();
11554 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11555 bounds of the real section. This is a pretty-rare event, so just
11556 flag an error (easier) instead of a warning and trying to cope. */
11558 || offset
+ size
> bfd_section_size (sectp
))
11560 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11561 " in section %s [in module %s]"),
11562 sectp
? bfd_section_name (sectp
) : "<unknown>",
11563 objfile_name (per_objfile
->objfile
));
11566 result
.virtual_offset
= offset
;
11567 result
.size
= size
;
11571 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11572 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11573 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11574 This is for DWP version 2 files. */
11576 static struct dwo_unit
*
11577 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11578 struct dwp_file
*dwp_file
,
11579 uint32_t unit_index
,
11580 const char *comp_dir
,
11581 ULONGEST signature
, int is_debug_types
)
11583 const struct dwp_hash_table
*dwp_htab
=
11584 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11585 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11586 const char *kind
= is_debug_types
? "TU" : "CU";
11587 struct dwo_file
*dwo_file
;
11588 struct dwo_unit
*dwo_unit
;
11589 struct virtual_v2_or_v5_dwo_sections sections
;
11590 void **dwo_file_slot
;
11593 gdb_assert (dwp_file
->version
== 2);
11595 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11596 kind
, pulongest (unit_index
), hex_string (signature
),
11599 /* Fetch the section offsets of this DWO unit. */
11601 memset (§ions
, 0, sizeof (sections
));
11603 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11605 uint32_t offset
= read_4_bytes (dbfd
,
11606 dwp_htab
->section_pool
.v2
.offsets
11607 + (((unit_index
- 1) * dwp_htab
->nr_columns
11609 * sizeof (uint32_t)));
11610 uint32_t size
= read_4_bytes (dbfd
,
11611 dwp_htab
->section_pool
.v2
.sizes
11612 + (((unit_index
- 1) * dwp_htab
->nr_columns
11614 * sizeof (uint32_t)));
11616 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11619 case DW_SECT_TYPES
:
11620 sections
.info_or_types_offset
= offset
;
11621 sections
.info_or_types_size
= size
;
11623 case DW_SECT_ABBREV
:
11624 sections
.abbrev_offset
= offset
;
11625 sections
.abbrev_size
= size
;
11628 sections
.line_offset
= offset
;
11629 sections
.line_size
= size
;
11632 sections
.loc_offset
= offset
;
11633 sections
.loc_size
= size
;
11635 case DW_SECT_STR_OFFSETS
:
11636 sections
.str_offsets_offset
= offset
;
11637 sections
.str_offsets_size
= size
;
11639 case DW_SECT_MACINFO
:
11640 sections
.macinfo_offset
= offset
;
11641 sections
.macinfo_size
= size
;
11643 case DW_SECT_MACRO
:
11644 sections
.macro_offset
= offset
;
11645 sections
.macro_size
= size
;
11650 /* It's easier for the rest of the code if we fake a struct dwo_file and
11651 have dwo_unit "live" in that. At least for now.
11653 The DWP file can be made up of a random collection of CUs and TUs.
11654 However, for each CU + set of TUs that came from the same original DWO
11655 file, we can combine them back into a virtual DWO file to save space
11656 (fewer struct dwo_file objects to allocate). Remember that for really
11657 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11659 std::string virtual_dwo_name
=
11660 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11661 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11662 (long) (sections
.line_size
? sections
.line_offset
: 0),
11663 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11664 (long) (sections
.str_offsets_size
11665 ? sections
.str_offsets_offset
: 0));
11666 /* Can we use an existing virtual DWO file? */
11667 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11669 /* Create one if necessary. */
11670 if (*dwo_file_slot
== NULL
)
11672 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11673 virtual_dwo_name
.c_str ());
11675 dwo_file
= new struct dwo_file
;
11676 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11677 dwo_file
->comp_dir
= comp_dir
;
11678 dwo_file
->sections
.abbrev
=
11679 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11680 sections
.abbrev_offset
,
11681 sections
.abbrev_size
);
11682 dwo_file
->sections
.line
=
11683 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11684 sections
.line_offset
,
11685 sections
.line_size
);
11686 dwo_file
->sections
.loc
=
11687 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11688 sections
.loc_offset
, sections
.loc_size
);
11689 dwo_file
->sections
.macinfo
=
11690 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11691 sections
.macinfo_offset
,
11692 sections
.macinfo_size
);
11693 dwo_file
->sections
.macro
=
11694 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11695 sections
.macro_offset
,
11696 sections
.macro_size
);
11697 dwo_file
->sections
.str_offsets
=
11698 create_dwp_v2_or_v5_section (per_objfile
,
11699 &dwp_file
->sections
.str_offsets
,
11700 sections
.str_offsets_offset
,
11701 sections
.str_offsets_size
);
11702 /* The "str" section is global to the entire DWP file. */
11703 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11704 /* The info or types section is assigned below to dwo_unit,
11705 there's no need to record it in dwo_file.
11706 Also, we can't simply record type sections in dwo_file because
11707 we record a pointer into the vector in dwo_unit. As we collect more
11708 types we'll grow the vector and eventually have to reallocate space
11709 for it, invalidating all copies of pointers into the previous
11711 *dwo_file_slot
= dwo_file
;
11715 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11716 virtual_dwo_name
.c_str ());
11718 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11721 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11722 dwo_unit
->dwo_file
= dwo_file
;
11723 dwo_unit
->signature
= signature
;
11724 dwo_unit
->section
=
11725 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11726 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11729 ? &dwp_file
->sections
.types
11730 : &dwp_file
->sections
.info
,
11731 sections
.info_or_types_offset
,
11732 sections
.info_or_types_size
);
11733 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11738 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11739 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11740 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11741 This is for DWP version 5 files. */
11743 static struct dwo_unit
*
11744 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11745 struct dwp_file
*dwp_file
,
11746 uint32_t unit_index
,
11747 const char *comp_dir
,
11748 ULONGEST signature
, int is_debug_types
)
11750 const struct dwp_hash_table
*dwp_htab
11751 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11752 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11753 const char *kind
= is_debug_types
? "TU" : "CU";
11754 struct dwo_file
*dwo_file
;
11755 struct dwo_unit
*dwo_unit
;
11756 struct virtual_v2_or_v5_dwo_sections sections
{};
11757 void **dwo_file_slot
;
11759 gdb_assert (dwp_file
->version
== 5);
11761 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11762 kind
, pulongest (unit_index
), hex_string (signature
),
11765 /* Fetch the section offsets of this DWO unit. */
11767 /* memset (§ions, 0, sizeof (sections)); */
11769 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11771 uint32_t offset
= read_4_bytes (dbfd
,
11772 dwp_htab
->section_pool
.v5
.offsets
11773 + (((unit_index
- 1)
11774 * dwp_htab
->nr_columns
11776 * sizeof (uint32_t)));
11777 uint32_t size
= read_4_bytes (dbfd
,
11778 dwp_htab
->section_pool
.v5
.sizes
11779 + (((unit_index
- 1) * dwp_htab
->nr_columns
11781 * sizeof (uint32_t)));
11783 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11785 case DW_SECT_ABBREV_V5
:
11786 sections
.abbrev_offset
= offset
;
11787 sections
.abbrev_size
= size
;
11789 case DW_SECT_INFO_V5
:
11790 sections
.info_or_types_offset
= offset
;
11791 sections
.info_or_types_size
= size
;
11793 case DW_SECT_LINE_V5
:
11794 sections
.line_offset
= offset
;
11795 sections
.line_size
= size
;
11797 case DW_SECT_LOCLISTS_V5
:
11798 sections
.loclists_offset
= offset
;
11799 sections
.loclists_size
= size
;
11801 case DW_SECT_MACRO_V5
:
11802 sections
.macro_offset
= offset
;
11803 sections
.macro_size
= size
;
11805 case DW_SECT_RNGLISTS_V5
:
11806 sections
.rnglists_offset
= offset
;
11807 sections
.rnglists_size
= size
;
11809 case DW_SECT_STR_OFFSETS_V5
:
11810 sections
.str_offsets_offset
= offset
;
11811 sections
.str_offsets_size
= size
;
11813 case DW_SECT_RESERVED_V5
:
11819 /* It's easier for the rest of the code if we fake a struct dwo_file and
11820 have dwo_unit "live" in that. At least for now.
11822 The DWP file can be made up of a random collection of CUs and TUs.
11823 However, for each CU + set of TUs that came from the same original DWO
11824 file, we can combine them back into a virtual DWO file to save space
11825 (fewer struct dwo_file objects to allocate). Remember that for really
11826 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11828 std::string virtual_dwo_name
=
11829 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11830 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11831 (long) (sections
.line_size
? sections
.line_offset
: 0),
11832 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11833 (long) (sections
.str_offsets_size
11834 ? sections
.str_offsets_offset
: 0),
11835 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11836 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11837 /* Can we use an existing virtual DWO file? */
11838 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11839 virtual_dwo_name
.c_str (),
11841 /* Create one if necessary. */
11842 if (*dwo_file_slot
== NULL
)
11844 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11845 virtual_dwo_name
.c_str ());
11847 dwo_file
= new struct dwo_file
;
11848 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11849 dwo_file
->comp_dir
= comp_dir
;
11850 dwo_file
->sections
.abbrev
=
11851 create_dwp_v2_or_v5_section (per_objfile
,
11852 &dwp_file
->sections
.abbrev
,
11853 sections
.abbrev_offset
,
11854 sections
.abbrev_size
);
11855 dwo_file
->sections
.line
=
11856 create_dwp_v2_or_v5_section (per_objfile
,
11857 &dwp_file
->sections
.line
,
11858 sections
.line_offset
, sections
.line_size
);
11859 dwo_file
->sections
.macro
=
11860 create_dwp_v2_or_v5_section (per_objfile
,
11861 &dwp_file
->sections
.macro
,
11862 sections
.macro_offset
,
11863 sections
.macro_size
);
11864 dwo_file
->sections
.loclists
=
11865 create_dwp_v2_or_v5_section (per_objfile
,
11866 &dwp_file
->sections
.loclists
,
11867 sections
.loclists_offset
,
11868 sections
.loclists_size
);
11869 dwo_file
->sections
.rnglists
=
11870 create_dwp_v2_or_v5_section (per_objfile
,
11871 &dwp_file
->sections
.rnglists
,
11872 sections
.rnglists_offset
,
11873 sections
.rnglists_size
);
11874 dwo_file
->sections
.str_offsets
=
11875 create_dwp_v2_or_v5_section (per_objfile
,
11876 &dwp_file
->sections
.str_offsets
,
11877 sections
.str_offsets_offset
,
11878 sections
.str_offsets_size
);
11879 /* The "str" section is global to the entire DWP file. */
11880 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11881 /* The info or types section is assigned below to dwo_unit,
11882 there's no need to record it in dwo_file.
11883 Also, we can't simply record type sections in dwo_file because
11884 we record a pointer into the vector in dwo_unit. As we collect more
11885 types we'll grow the vector and eventually have to reallocate space
11886 for it, invalidating all copies of pointers into the previous
11888 *dwo_file_slot
= dwo_file
;
11892 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11893 virtual_dwo_name
.c_str ());
11895 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11898 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11899 dwo_unit
->dwo_file
= dwo_file
;
11900 dwo_unit
->signature
= signature
;
11902 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11903 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
11904 &dwp_file
->sections
.info
,
11905 sections
.info_or_types_offset
,
11906 sections
.info_or_types_size
);
11907 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11912 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11913 Returns NULL if the signature isn't found. */
11915 static struct dwo_unit
*
11916 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
11917 struct dwp_file
*dwp_file
, const char *comp_dir
,
11918 ULONGEST signature
, int is_debug_types
)
11920 const struct dwp_hash_table
*dwp_htab
=
11921 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11922 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11923 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11924 uint32_t hash
= signature
& mask
;
11925 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11928 struct dwo_unit find_dwo_cu
;
11930 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11931 find_dwo_cu
.signature
= signature
;
11932 slot
= htab_find_slot (is_debug_types
11933 ? dwp_file
->loaded_tus
.get ()
11934 : dwp_file
->loaded_cus
.get (),
11935 &find_dwo_cu
, INSERT
);
11938 return (struct dwo_unit
*) *slot
;
11940 /* Use a for loop so that we don't loop forever on bad debug info. */
11941 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11943 ULONGEST signature_in_table
;
11945 signature_in_table
=
11946 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11947 if (signature_in_table
== signature
)
11949 uint32_t unit_index
=
11950 read_4_bytes (dbfd
,
11951 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11953 if (dwp_file
->version
== 1)
11955 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
11956 unit_index
, comp_dir
,
11957 signature
, is_debug_types
);
11959 else if (dwp_file
->version
== 2)
11961 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
11962 unit_index
, comp_dir
,
11963 signature
, is_debug_types
);
11965 else /* version == 5 */
11967 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
11968 unit_index
, comp_dir
,
11969 signature
, is_debug_types
);
11971 return (struct dwo_unit
*) *slot
;
11973 if (signature_in_table
== 0)
11975 hash
= (hash
+ hash2
) & mask
;
11978 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11979 " [in module %s]"),
11983 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11984 Open the file specified by FILE_NAME and hand it off to BFD for
11985 preliminary analysis. Return a newly initialized bfd *, which
11986 includes a canonicalized copy of FILE_NAME.
11987 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11988 SEARCH_CWD is true if the current directory is to be searched.
11989 It will be searched before debug-file-directory.
11990 If successful, the file is added to the bfd include table of the
11991 objfile's bfd (see gdb_bfd_record_inclusion).
11992 If unable to find/open the file, return NULL.
11993 NOTE: This function is derived from symfile_bfd_open. */
11995 static gdb_bfd_ref_ptr
11996 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
11997 const char *file_name
, int is_dwp
, int search_cwd
)
12000 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12001 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12002 to debug_file_directory. */
12003 const char *search_path
;
12004 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12006 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12009 if (*debug_file_directory
!= '\0')
12011 search_path_holder
.reset (concat (".", dirname_separator_string
,
12012 debug_file_directory
,
12014 search_path
= search_path_holder
.get ();
12020 search_path
= debug_file_directory
;
12022 /* Add the path for the executable binary to the list of search paths. */
12023 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12024 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12025 dirname_separator_string
,
12026 search_path
, nullptr));
12027 search_path
= search_path_holder
.get ();
12029 openp_flags flags
= OPF_RETURN_REALPATH
;
12031 flags
|= OPF_SEARCH_IN_PATH
;
12033 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12034 desc
= openp (search_path
, flags
, file_name
,
12035 O_RDONLY
| O_BINARY
, &absolute_name
);
12039 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12041 if (sym_bfd
== NULL
)
12043 bfd_set_cacheable (sym_bfd
.get (), 1);
12045 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12048 /* Success. Record the bfd as having been included by the objfile's bfd.
12049 This is important because things like demangled_names_hash lives in the
12050 objfile's per_bfd space and may have references to things like symbol
12051 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12052 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12057 /* Try to open DWO file FILE_NAME.
12058 COMP_DIR is the DW_AT_comp_dir attribute.
12059 The result is the bfd handle of the file.
12060 If there is a problem finding or opening the file, return NULL.
12061 Upon success, the canonicalized path of the file is stored in the bfd,
12062 same as symfile_bfd_open. */
12064 static gdb_bfd_ref_ptr
12065 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12066 const char *file_name
, const char *comp_dir
)
12068 if (IS_ABSOLUTE_PATH (file_name
))
12069 return try_open_dwop_file (per_objfile
, file_name
,
12070 0 /*is_dwp*/, 0 /*search_cwd*/);
12072 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12074 if (comp_dir
!= NULL
)
12076 gdb::unique_xmalloc_ptr
<char> path_to_try
12077 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12079 /* NOTE: If comp_dir is a relative path, this will also try the
12080 search path, which seems useful. */
12081 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12083 1 /*search_cwd*/));
12088 /* That didn't work, try debug-file-directory, which, despite its name,
12089 is a list of paths. */
12091 if (*debug_file_directory
== '\0')
12094 return try_open_dwop_file (per_objfile
, file_name
,
12095 0 /*is_dwp*/, 1 /*search_cwd*/);
12098 /* This function is mapped across the sections and remembers the offset and
12099 size of each of the DWO debugging sections we are interested in. */
12102 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12103 dwo_sections
*dwo_sections
)
12105 const struct dwop_section_names
*names
= &dwop_section_names
;
12107 if (names
->abbrev_dwo
.matches (sectp
->name
))
12109 dwo_sections
->abbrev
.s
.section
= sectp
;
12110 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12112 else if (names
->info_dwo
.matches (sectp
->name
))
12114 dwo_sections
->info
.s
.section
= sectp
;
12115 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12117 else if (names
->line_dwo
.matches (sectp
->name
))
12119 dwo_sections
->line
.s
.section
= sectp
;
12120 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12122 else if (names
->loc_dwo
.matches (sectp
->name
))
12124 dwo_sections
->loc
.s
.section
= sectp
;
12125 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12127 else if (names
->loclists_dwo
.matches (sectp
->name
))
12129 dwo_sections
->loclists
.s
.section
= sectp
;
12130 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12132 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12134 dwo_sections
->macinfo
.s
.section
= sectp
;
12135 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12137 else if (names
->macro_dwo
.matches (sectp
->name
))
12139 dwo_sections
->macro
.s
.section
= sectp
;
12140 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12142 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12144 dwo_sections
->rnglists
.s
.section
= sectp
;
12145 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12147 else if (names
->str_dwo
.matches (sectp
->name
))
12149 dwo_sections
->str
.s
.section
= sectp
;
12150 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12152 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12154 dwo_sections
->str_offsets
.s
.section
= sectp
;
12155 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12157 else if (names
->types_dwo
.matches (sectp
->name
))
12159 struct dwarf2_section_info type_section
;
12161 memset (&type_section
, 0, sizeof (type_section
));
12162 type_section
.s
.section
= sectp
;
12163 type_section
.size
= bfd_section_size (sectp
);
12164 dwo_sections
->types
.push_back (type_section
);
12168 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12169 by PER_CU. This is for the non-DWP case.
12170 The result is NULL if DWO_NAME can't be found. */
12172 static struct dwo_file
*
12173 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12174 const char *comp_dir
)
12176 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12178 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12181 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12186 dwo_file_up
dwo_file (new struct dwo_file
);
12187 dwo_file
->dwo_name
= dwo_name
;
12188 dwo_file
->comp_dir
= comp_dir
;
12189 dwo_file
->dbfd
= std::move (dbfd
);
12191 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12192 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12193 &dwo_file
->sections
);
12195 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12198 if (cu
->per_cu
->dwarf_version
< 5)
12200 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12201 dwo_file
->sections
.types
, dwo_file
->tus
);
12205 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12206 &dwo_file
->sections
.info
, dwo_file
->tus
,
12207 rcuh_kind::COMPILE
);
12210 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12212 return dwo_file
.release ();
12215 /* This function is mapped across the sections and remembers the offset and
12216 size of each of the DWP debugging sections common to version 1 and 2 that
12217 we are interested in. */
12220 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12221 dwp_file
*dwp_file
)
12223 const struct dwop_section_names
*names
= &dwop_section_names
;
12224 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12226 /* Record the ELF section number for later lookup: this is what the
12227 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12228 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12229 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12231 /* Look for specific sections that we need. */
12232 if (names
->str_dwo
.matches (sectp
->name
))
12234 dwp_file
->sections
.str
.s
.section
= sectp
;
12235 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12237 else if (names
->cu_index
.matches (sectp
->name
))
12239 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12240 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12242 else if (names
->tu_index
.matches (sectp
->name
))
12244 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12245 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12249 /* This function is mapped across the sections and remembers the offset and
12250 size of each of the DWP version 2 debugging sections that we are interested
12251 in. This is split into a separate function because we don't know if we
12252 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12255 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12257 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12258 const struct dwop_section_names
*names
= &dwop_section_names
;
12259 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12261 /* Record the ELF section number for later lookup: this is what the
12262 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12263 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12264 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12266 /* Look for specific sections that we need. */
12267 if (names
->abbrev_dwo
.matches (sectp
->name
))
12269 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12270 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12272 else if (names
->info_dwo
.matches (sectp
->name
))
12274 dwp_file
->sections
.info
.s
.section
= sectp
;
12275 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12277 else if (names
->line_dwo
.matches (sectp
->name
))
12279 dwp_file
->sections
.line
.s
.section
= sectp
;
12280 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12282 else if (names
->loc_dwo
.matches (sectp
->name
))
12284 dwp_file
->sections
.loc
.s
.section
= sectp
;
12285 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12287 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12289 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12290 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12292 else if (names
->macro_dwo
.matches (sectp
->name
))
12294 dwp_file
->sections
.macro
.s
.section
= sectp
;
12295 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12297 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12299 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12300 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12302 else if (names
->types_dwo
.matches (sectp
->name
))
12304 dwp_file
->sections
.types
.s
.section
= sectp
;
12305 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12309 /* This function is mapped across the sections and remembers the offset and
12310 size of each of the DWP version 5 debugging sections that we are interested
12311 in. This is split into a separate function because we don't know if we
12312 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12315 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12317 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12318 const struct dwop_section_names
*names
= &dwop_section_names
;
12319 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12321 /* Record the ELF section number for later lookup: this is what the
12322 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12323 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12324 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12326 /* Look for specific sections that we need. */
12327 if (names
->abbrev_dwo
.matches (sectp
->name
))
12329 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12330 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12332 else if (names
->info_dwo
.matches (sectp
->name
))
12334 dwp_file
->sections
.info
.s
.section
= sectp
;
12335 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12337 else if (names
->line_dwo
.matches (sectp
->name
))
12339 dwp_file
->sections
.line
.s
.section
= sectp
;
12340 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12342 else if (names
->loclists_dwo
.matches (sectp
->name
))
12344 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12345 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12347 else if (names
->macro_dwo
.matches (sectp
->name
))
12349 dwp_file
->sections
.macro
.s
.section
= sectp
;
12350 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12352 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12354 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12355 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12357 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12359 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12360 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12364 /* Hash function for dwp_file loaded CUs/TUs. */
12367 hash_dwp_loaded_cutus (const void *item
)
12369 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12371 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12372 return dwo_unit
->signature
;
12375 /* Equality function for dwp_file loaded CUs/TUs. */
12378 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12380 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12381 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12383 return dua
->signature
== dub
->signature
;
12386 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12389 allocate_dwp_loaded_cutus_table ()
12391 return htab_up (htab_create_alloc (3,
12392 hash_dwp_loaded_cutus
,
12393 eq_dwp_loaded_cutus
,
12394 NULL
, xcalloc
, xfree
));
12397 /* Try to open DWP file FILE_NAME.
12398 The result is the bfd handle of the file.
12399 If there is a problem finding or opening the file, return NULL.
12400 Upon success, the canonicalized path of the file is stored in the bfd,
12401 same as symfile_bfd_open. */
12403 static gdb_bfd_ref_ptr
12404 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12406 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12408 1 /*search_cwd*/));
12412 /* Work around upstream bug 15652.
12413 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12414 [Whether that's a "bug" is debatable, but it is getting in our way.]
12415 We have no real idea where the dwp file is, because gdb's realpath-ing
12416 of the executable's path may have discarded the needed info.
12417 [IWBN if the dwp file name was recorded in the executable, akin to
12418 .gnu_debuglink, but that doesn't exist yet.]
12419 Strip the directory from FILE_NAME and search again. */
12420 if (*debug_file_directory
!= '\0')
12422 /* Don't implicitly search the current directory here.
12423 If the user wants to search "." to handle this case,
12424 it must be added to debug-file-directory. */
12425 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12433 /* Initialize the use of the DWP file for the current objfile.
12434 By convention the name of the DWP file is ${objfile}.dwp.
12435 The result is NULL if it can't be found. */
12437 static std::unique_ptr
<struct dwp_file
>
12438 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12440 struct objfile
*objfile
= per_objfile
->objfile
;
12442 /* Try to find first .dwp for the binary file before any symbolic links
12445 /* If the objfile is a debug file, find the name of the real binary
12446 file and get the name of dwp file from there. */
12447 std::string dwp_name
;
12448 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12450 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12451 const char *backlink_basename
= lbasename (backlink
->original_name
);
12453 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12456 dwp_name
= objfile
->original_name
;
12458 dwp_name
+= ".dwp";
12460 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12462 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12464 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12465 dwp_name
= objfile_name (objfile
);
12466 dwp_name
+= ".dwp";
12467 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12472 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12474 return std::unique_ptr
<dwp_file
> ();
12477 const char *name
= bfd_get_filename (dbfd
.get ());
12478 std::unique_ptr
<struct dwp_file
> dwp_file
12479 (new struct dwp_file (name
, std::move (dbfd
)));
12481 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12482 dwp_file
->elf_sections
=
12483 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12484 dwp_file
->num_sections
, asection
*);
12486 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12487 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12490 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12492 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12494 /* The DWP file version is stored in the hash table. Oh well. */
12495 if (dwp_file
->cus
&& dwp_file
->tus
12496 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12498 /* Technically speaking, we should try to limp along, but this is
12499 pretty bizarre. We use pulongest here because that's the established
12500 portability solution (e.g, we cannot use %u for uint32_t). */
12501 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12502 " TU version %s [in DWP file %s]"),
12503 pulongest (dwp_file
->cus
->version
),
12504 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12508 dwp_file
->version
= dwp_file
->cus
->version
;
12509 else if (dwp_file
->tus
)
12510 dwp_file
->version
= dwp_file
->tus
->version
;
12512 dwp_file
->version
= 2;
12514 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12516 if (dwp_file
->version
== 2)
12517 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12520 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12524 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12525 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12527 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12528 dwarf_read_debug_printf (" %s CUs, %s TUs",
12529 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12530 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12535 /* Wrapper around open_and_init_dwp_file, only open it once. */
12537 static struct dwp_file
*
12538 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12540 if (!per_objfile
->per_bfd
->dwp_checked
)
12542 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12543 per_objfile
->per_bfd
->dwp_checked
= 1;
12545 return per_objfile
->per_bfd
->dwp_file
.get ();
12548 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12549 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12550 or in the DWP file for the objfile, referenced by THIS_UNIT.
12551 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12552 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12554 This is called, for example, when wanting to read a variable with a
12555 complex location. Therefore we don't want to do file i/o for every call.
12556 Therefore we don't want to look for a DWO file on every call.
12557 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12558 then we check if we've already seen DWO_NAME, and only THEN do we check
12561 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12562 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12564 static struct dwo_unit
*
12565 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12566 ULONGEST signature
, int is_debug_types
)
12568 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12569 struct objfile
*objfile
= per_objfile
->objfile
;
12570 const char *kind
= is_debug_types
? "TU" : "CU";
12571 void **dwo_file_slot
;
12572 struct dwo_file
*dwo_file
;
12573 struct dwp_file
*dwp_file
;
12575 /* First see if there's a DWP file.
12576 If we have a DWP file but didn't find the DWO inside it, don't
12577 look for the original DWO file. It makes gdb behave differently
12578 depending on whether one is debugging in the build tree. */
12580 dwp_file
= get_dwp_file (per_objfile
);
12581 if (dwp_file
!= NULL
)
12583 const struct dwp_hash_table
*dwp_htab
=
12584 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12586 if (dwp_htab
!= NULL
)
12588 struct dwo_unit
*dwo_cutu
=
12589 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12592 if (dwo_cutu
!= NULL
)
12594 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12595 kind
, hex_string (signature
),
12596 host_address_to_string (dwo_cutu
));
12604 /* No DWP file, look for the DWO file. */
12606 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12607 if (*dwo_file_slot
== NULL
)
12609 /* Read in the file and build a table of the CUs/TUs it contains. */
12610 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12612 /* NOTE: This will be NULL if unable to open the file. */
12613 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12615 if (dwo_file
!= NULL
)
12617 struct dwo_unit
*dwo_cutu
= NULL
;
12619 if (is_debug_types
&& dwo_file
->tus
)
12621 struct dwo_unit find_dwo_cutu
;
12623 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12624 find_dwo_cutu
.signature
= signature
;
12626 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12629 else if (!is_debug_types
&& dwo_file
->cus
)
12631 struct dwo_unit find_dwo_cutu
;
12633 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12634 find_dwo_cutu
.signature
= signature
;
12635 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12639 if (dwo_cutu
!= NULL
)
12641 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12642 kind
, dwo_name
, hex_string (signature
),
12643 host_address_to_string (dwo_cutu
));
12650 /* We didn't find it. This could mean a dwo_id mismatch, or
12651 someone deleted the DWO/DWP file, or the search path isn't set up
12652 correctly to find the file. */
12654 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12655 kind
, dwo_name
, hex_string (signature
));
12657 /* This is a warning and not a complaint because it can be caused by
12658 pilot error (e.g., user accidentally deleting the DWO). */
12660 /* Print the name of the DWP file if we looked there, helps the user
12661 better diagnose the problem. */
12662 std::string dwp_text
;
12664 if (dwp_file
!= NULL
)
12665 dwp_text
= string_printf (" [in DWP file %s]",
12666 lbasename (dwp_file
->name
));
12668 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12669 " [in module %s]"),
12670 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12671 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12676 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12677 See lookup_dwo_cutu_unit for details. */
12679 static struct dwo_unit
*
12680 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12681 ULONGEST signature
)
12683 gdb_assert (!cu
->per_cu
->is_debug_types
);
12685 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12688 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12689 See lookup_dwo_cutu_unit for details. */
12691 static struct dwo_unit
*
12692 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12694 gdb_assert (cu
->per_cu
->is_debug_types
);
12696 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12698 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12701 /* Traversal function for queue_and_load_all_dwo_tus. */
12704 queue_and_load_dwo_tu (void **slot
, void *info
)
12706 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12707 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12708 ULONGEST signature
= dwo_unit
->signature
;
12709 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12711 if (sig_type
!= NULL
)
12713 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12714 a real dependency of PER_CU on SIG_TYPE. That is detected later
12715 while processing PER_CU. */
12716 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12718 load_full_type_unit (sig_type
, cu
->per_objfile
);
12719 cu
->per_cu
->imported_symtabs_push (sig_type
);
12725 /* Queue all TUs contained in the DWO of CU to be read in.
12726 The DWO may have the only definition of the type, though it may not be
12727 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12728 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12731 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12733 struct dwo_unit
*dwo_unit
;
12734 struct dwo_file
*dwo_file
;
12736 gdb_assert (cu
!= nullptr);
12737 gdb_assert (!cu
->per_cu
->is_debug_types
);
12738 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12740 dwo_unit
= cu
->dwo_unit
;
12741 gdb_assert (dwo_unit
!= NULL
);
12743 dwo_file
= dwo_unit
->dwo_file
;
12744 if (dwo_file
->tus
!= NULL
)
12745 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12748 /* Read in various DIEs. */
12750 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12751 Inherit only the children of the DW_AT_abstract_origin DIE not being
12752 already referenced by DW_AT_abstract_origin from the children of the
12756 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12758 struct die_info
*child_die
;
12759 sect_offset
*offsetp
;
12760 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12761 struct die_info
*origin_die
;
12762 /* Iterator of the ORIGIN_DIE children. */
12763 struct die_info
*origin_child_die
;
12764 struct attribute
*attr
;
12765 struct dwarf2_cu
*origin_cu
;
12766 struct pending
**origin_previous_list_in_scope
;
12768 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12772 /* Note that following die references may follow to a die in a
12776 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12778 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12780 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12781 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12783 if (die
->tag
!= origin_die
->tag
12784 && !(die
->tag
== DW_TAG_inlined_subroutine
12785 && origin_die
->tag
== DW_TAG_subprogram
))
12786 complaint (_("DIE %s and its abstract origin %s have different tags"),
12787 sect_offset_str (die
->sect_off
),
12788 sect_offset_str (origin_die
->sect_off
));
12790 /* Find if the concrete and abstract trees are structurally the
12791 same. This is a shallow traversal and it is not bullet-proof;
12792 the compiler can trick the debugger into believing that the trees
12793 are isomorphic, whereas they actually are not. However, the
12794 likelyhood of this happening is pretty low, and a full-fledged
12795 check would be an overkill. */
12796 bool are_isomorphic
= true;
12797 die_info
*concrete_child
= die
->child
;
12798 die_info
*abstract_child
= origin_die
->child
;
12799 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12801 if (concrete_child
== nullptr
12802 || abstract_child
== nullptr
12803 || concrete_child
->tag
!= abstract_child
->tag
)
12805 are_isomorphic
= false;
12809 concrete_child
= concrete_child
->sibling
;
12810 abstract_child
= abstract_child
->sibling
;
12813 /* Walk the origin's children in parallel to the concrete children.
12814 This helps match an origin child in case the debug info misses
12815 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12816 origin tree may not have the same tree structure as the concrete
12818 die_info
*corresponding_abstract_child
12819 = are_isomorphic
? origin_die
->child
: nullptr;
12821 std::vector
<sect_offset
> offsets
;
12823 for (child_die
= die
->child
;
12824 child_die
&& child_die
->tag
;
12825 child_die
= child_die
->sibling
)
12827 struct die_info
*child_origin_die
;
12828 struct dwarf2_cu
*child_origin_cu
;
12830 /* We are trying to process concrete instance entries:
12831 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12832 it's not relevant to our analysis here. i.e. detecting DIEs that are
12833 present in the abstract instance but not referenced in the concrete
12835 if (child_die
->tag
== DW_TAG_call_site
12836 || child_die
->tag
== DW_TAG_GNU_call_site
)
12838 if (are_isomorphic
)
12839 corresponding_abstract_child
12840 = corresponding_abstract_child
->sibling
;
12844 /* For each CHILD_DIE, find the corresponding child of
12845 ORIGIN_DIE. If there is more than one layer of
12846 DW_AT_abstract_origin, follow them all; there shouldn't be,
12847 but GCC versions at least through 4.4 generate this (GCC PR
12849 child_origin_die
= child_die
;
12850 child_origin_cu
= cu
;
12853 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12857 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12861 /* If missing DW_AT_abstract_origin, try the corresponding child
12862 of the origin. Clang emits such lexical scopes. */
12863 if (child_origin_die
== child_die
12864 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12866 && child_die
->tag
== DW_TAG_lexical_block
)
12867 child_origin_die
= corresponding_abstract_child
;
12869 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12870 counterpart may exist. */
12871 if (child_origin_die
!= child_die
)
12873 if (child_die
->tag
!= child_origin_die
->tag
12874 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12875 && child_origin_die
->tag
== DW_TAG_subprogram
))
12876 complaint (_("Child DIE %s and its abstract origin %s have "
12878 sect_offset_str (child_die
->sect_off
),
12879 sect_offset_str (child_origin_die
->sect_off
));
12880 if (child_origin_die
->parent
!= origin_die
)
12881 complaint (_("Child DIE %s and its abstract origin %s have "
12882 "different parents"),
12883 sect_offset_str (child_die
->sect_off
),
12884 sect_offset_str (child_origin_die
->sect_off
));
12886 offsets
.push_back (child_origin_die
->sect_off
);
12889 if (are_isomorphic
)
12890 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12892 std::sort (offsets
.begin (), offsets
.end ());
12893 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12894 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12895 if (offsetp
[-1] == *offsetp
)
12896 complaint (_("Multiple children of DIE %s refer "
12897 "to DIE %s as their abstract origin"),
12898 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12900 offsetp
= offsets
.data ();
12901 origin_child_die
= origin_die
->child
;
12902 while (origin_child_die
&& origin_child_die
->tag
)
12904 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12905 while (offsetp
< offsets_end
12906 && *offsetp
< origin_child_die
->sect_off
)
12908 if (offsetp
>= offsets_end
12909 || *offsetp
> origin_child_die
->sect_off
)
12911 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12912 Check whether we're already processing ORIGIN_CHILD_DIE.
12913 This can happen with mutually referenced abstract_origins.
12915 if (!origin_child_die
->in_process
)
12916 process_die (origin_child_die
, origin_cu
);
12918 origin_child_die
= origin_child_die
->sibling
;
12920 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12922 if (cu
!= origin_cu
)
12923 compute_delayed_physnames (origin_cu
);
12927 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12929 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12930 struct gdbarch
*gdbarch
= objfile
->arch ();
12931 struct context_stack
*newobj
;
12934 struct die_info
*child_die
;
12935 struct attribute
*attr
, *call_line
, *call_file
;
12937 CORE_ADDR baseaddr
;
12938 struct block
*block
;
12939 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12940 std::vector
<struct symbol
*> template_args
;
12941 struct template_symbol
*templ_func
= NULL
;
12945 /* If we do not have call site information, we can't show the
12946 caller of this inlined function. That's too confusing, so
12947 only use the scope for local variables. */
12948 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12949 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12950 if (call_line
== NULL
|| call_file
== NULL
)
12952 read_lexical_block_scope (die
, cu
);
12957 baseaddr
= objfile
->text_section_offset ();
12959 name
= dwarf2_name (die
, cu
);
12961 /* Ignore functions with missing or empty names. These are actually
12962 illegal according to the DWARF standard. */
12965 complaint (_("missing name for subprogram DIE at %s"),
12966 sect_offset_str (die
->sect_off
));
12970 /* Ignore functions with missing or invalid low and high pc attributes. */
12971 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12972 <= PC_BOUNDS_INVALID
)
12974 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12975 if (attr
== nullptr || !attr
->as_boolean ())
12976 complaint (_("cannot get low and high bounds "
12977 "for subprogram DIE at %s"),
12978 sect_offset_str (die
->sect_off
));
12982 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12983 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12985 /* If we have any template arguments, then we must allocate a
12986 different sort of symbol. */
12987 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12989 if (child_die
->tag
== DW_TAG_template_type_param
12990 || child_die
->tag
== DW_TAG_template_value_param
)
12992 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
12993 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12998 gdb_assert (cu
->get_builder () != nullptr);
12999 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13000 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13001 (struct symbol
*) templ_func
);
13003 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13004 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13007 /* If there is a location expression for DW_AT_frame_base, record
13009 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13010 if (attr
!= nullptr)
13011 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13013 /* If there is a location for the static link, record it. */
13014 newobj
->static_link
= NULL
;
13015 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13016 if (attr
!= nullptr)
13018 newobj
->static_link
13019 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13020 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13024 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13026 if (die
->child
!= NULL
)
13028 child_die
= die
->child
;
13029 while (child_die
&& child_die
->tag
)
13031 if (child_die
->tag
== DW_TAG_template_type_param
13032 || child_die
->tag
== DW_TAG_template_value_param
)
13034 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13037 template_args
.push_back (arg
);
13040 process_die (child_die
, cu
);
13041 child_die
= child_die
->sibling
;
13045 inherit_abstract_dies (die
, cu
);
13047 /* If we have a DW_AT_specification, we might need to import using
13048 directives from the context of the specification DIE. See the
13049 comment in determine_prefix. */
13050 if (cu
->language
== language_cplus
13051 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13053 struct dwarf2_cu
*spec_cu
= cu
;
13054 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13058 child_die
= spec_die
->child
;
13059 while (child_die
&& child_die
->tag
)
13061 if (child_die
->tag
== DW_TAG_imported_module
)
13062 process_die (child_die
, spec_cu
);
13063 child_die
= child_die
->sibling
;
13066 /* In some cases, GCC generates specification DIEs that
13067 themselves contain DW_AT_specification attributes. */
13068 spec_die
= die_specification (spec_die
, &spec_cu
);
13072 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13073 /* Make a block for the local symbols within. */
13074 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13075 cstk
.static_link
, lowpc
, highpc
);
13077 /* For C++, set the block's scope. */
13078 if ((cu
->language
== language_cplus
13079 || cu
->language
== language_fortran
13080 || cu
->language
== language_d
13081 || cu
->language
== language_rust
)
13082 && cu
->processing_has_namespace_info
)
13083 block_set_scope (block
, determine_prefix (die
, cu
),
13084 &objfile
->objfile_obstack
);
13086 /* If we have address ranges, record them. */
13087 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13089 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13091 /* Attach template arguments to function. */
13092 if (!template_args
.empty ())
13094 gdb_assert (templ_func
!= NULL
);
13096 templ_func
->n_template_arguments
= template_args
.size ();
13097 templ_func
->template_arguments
13098 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13099 templ_func
->n_template_arguments
);
13100 memcpy (templ_func
->template_arguments
,
13101 template_args
.data (),
13102 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13104 /* Make sure that the symtab is set on the new symbols. Even
13105 though they don't appear in this symtab directly, other parts
13106 of gdb assume that symbols do, and this is reasonably
13108 for (symbol
*sym
: template_args
)
13109 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13112 /* In C++, we can have functions nested inside functions (e.g., when
13113 a function declares a class that has methods). This means that
13114 when we finish processing a function scope, we may need to go
13115 back to building a containing block's symbol lists. */
13116 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13117 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13119 /* If we've finished processing a top-level function, subsequent
13120 symbols go in the file symbol list. */
13121 if (cu
->get_builder ()->outermost_context_p ())
13122 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13125 /* Process all the DIES contained within a lexical block scope. Start
13126 a new scope, process the dies, and then close the scope. */
13129 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13131 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13132 struct gdbarch
*gdbarch
= objfile
->arch ();
13133 CORE_ADDR lowpc
, highpc
;
13134 struct die_info
*child_die
;
13135 CORE_ADDR baseaddr
;
13137 baseaddr
= objfile
->text_section_offset ();
13139 /* Ignore blocks with missing or invalid low and high pc attributes. */
13140 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13141 as multiple lexical blocks? Handling children in a sane way would
13142 be nasty. Might be easier to properly extend generic blocks to
13143 describe ranges. */
13144 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13146 case PC_BOUNDS_NOT_PRESENT
:
13147 /* DW_TAG_lexical_block has no attributes, process its children as if
13148 there was no wrapping by that DW_TAG_lexical_block.
13149 GCC does no longer produces such DWARF since GCC r224161. */
13150 for (child_die
= die
->child
;
13151 child_die
!= NULL
&& child_die
->tag
;
13152 child_die
= child_die
->sibling
)
13154 /* We might already be processing this DIE. This can happen
13155 in an unusual circumstance -- where a subroutine A
13156 appears lexically in another subroutine B, but A actually
13157 inlines B. The recursion is broken here, rather than in
13158 inherit_abstract_dies, because it seems better to simply
13159 drop concrete children here. */
13160 if (!child_die
->in_process
)
13161 process_die (child_die
, cu
);
13164 case PC_BOUNDS_INVALID
:
13167 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13168 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13170 cu
->get_builder ()->push_context (0, lowpc
);
13171 if (die
->child
!= NULL
)
13173 child_die
= die
->child
;
13174 while (child_die
&& child_die
->tag
)
13176 process_die (child_die
, cu
);
13177 child_die
= child_die
->sibling
;
13180 inherit_abstract_dies (die
, cu
);
13181 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13183 if (*cu
->get_builder ()->get_local_symbols () != NULL
13184 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13186 struct block
*block
13187 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13188 cstk
.start_addr
, highpc
);
13190 /* Note that recording ranges after traversing children, as we
13191 do here, means that recording a parent's ranges entails
13192 walking across all its children's ranges as they appear in
13193 the address map, which is quadratic behavior.
13195 It would be nicer to record the parent's ranges before
13196 traversing its children, simply overriding whatever you find
13197 there. But since we don't even decide whether to create a
13198 block until after we've traversed its children, that's hard
13200 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13202 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13203 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13206 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13209 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13211 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13212 struct objfile
*objfile
= per_objfile
->objfile
;
13213 struct gdbarch
*gdbarch
= objfile
->arch ();
13214 CORE_ADDR pc
, baseaddr
;
13215 struct attribute
*attr
;
13216 struct call_site
*call_site
, call_site_local
;
13219 struct die_info
*child_die
;
13221 baseaddr
= objfile
->text_section_offset ();
13223 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13226 /* This was a pre-DWARF-5 GNU extension alias
13227 for DW_AT_call_return_pc. */
13228 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13232 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13233 "DIE %s [in module %s]"),
13234 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13237 pc
= attr
->as_address () + baseaddr
;
13238 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13240 if (cu
->call_site_htab
== NULL
)
13241 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13242 NULL
, &objfile
->objfile_obstack
,
13243 hashtab_obstack_allocate
, NULL
);
13244 call_site_local
.pc
= pc
;
13245 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13248 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13249 "DIE %s [in module %s]"),
13250 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13251 objfile_name (objfile
));
13255 /* Count parameters at the caller. */
13258 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13259 child_die
= child_die
->sibling
)
13261 if (child_die
->tag
!= DW_TAG_call_site_parameter
13262 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13264 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13265 "DW_TAG_call_site child DIE %s [in module %s]"),
13266 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13267 objfile_name (objfile
));
13275 = ((struct call_site
*)
13276 obstack_alloc (&objfile
->objfile_obstack
,
13277 sizeof (*call_site
)
13278 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13280 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13281 call_site
->pc
= pc
;
13283 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13284 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13286 struct die_info
*func_die
;
13288 /* Skip also over DW_TAG_inlined_subroutine. */
13289 for (func_die
= die
->parent
;
13290 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13291 && func_die
->tag
!= DW_TAG_subroutine_type
;
13292 func_die
= func_die
->parent
);
13294 /* DW_AT_call_all_calls is a superset
13295 of DW_AT_call_all_tail_calls. */
13297 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13298 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13299 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13300 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13302 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13303 not complete. But keep CALL_SITE for look ups via call_site_htab,
13304 both the initial caller containing the real return address PC and
13305 the final callee containing the current PC of a chain of tail
13306 calls do not need to have the tail call list complete. But any
13307 function candidate for a virtual tail call frame searched via
13308 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13309 determined unambiguously. */
13313 struct type
*func_type
= NULL
;
13316 func_type
= get_die_type (func_die
, cu
);
13317 if (func_type
!= NULL
)
13319 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13321 /* Enlist this call site to the function. */
13322 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13323 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13326 complaint (_("Cannot find function owning DW_TAG_call_site "
13327 "DIE %s [in module %s]"),
13328 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13332 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13334 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13336 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13339 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13340 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13342 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13343 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13344 /* Keep NULL DWARF_BLOCK. */;
13345 else if (attr
->form_is_block ())
13347 struct dwarf2_locexpr_baton
*dlbaton
;
13348 struct dwarf_block
*block
= attr
->as_block ();
13350 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13351 dlbaton
->data
= block
->data
;
13352 dlbaton
->size
= block
->size
;
13353 dlbaton
->per_objfile
= per_objfile
;
13354 dlbaton
->per_cu
= cu
->per_cu
;
13356 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13358 else if (attr
->form_is_ref ())
13360 struct dwarf2_cu
*target_cu
= cu
;
13361 struct die_info
*target_die
;
13363 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13364 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13365 if (die_is_declaration (target_die
, target_cu
))
13367 const char *target_physname
;
13369 /* Prefer the mangled name; otherwise compute the demangled one. */
13370 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13371 if (target_physname
== NULL
)
13372 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13373 if (target_physname
== NULL
)
13374 complaint (_("DW_AT_call_target target DIE has invalid "
13375 "physname, for referencing DIE %s [in module %s]"),
13376 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13378 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13384 /* DW_AT_entry_pc should be preferred. */
13385 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13386 <= PC_BOUNDS_INVALID
)
13387 complaint (_("DW_AT_call_target target DIE has invalid "
13388 "low pc, for referencing DIE %s [in module %s]"),
13389 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13392 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13393 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13398 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13399 "block nor reference, for DIE %s [in module %s]"),
13400 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13402 call_site
->per_cu
= cu
->per_cu
;
13403 call_site
->per_objfile
= per_objfile
;
13405 for (child_die
= die
->child
;
13406 child_die
&& child_die
->tag
;
13407 child_die
= child_die
->sibling
)
13409 struct call_site_parameter
*parameter
;
13410 struct attribute
*loc
, *origin
;
13412 if (child_die
->tag
!= DW_TAG_call_site_parameter
13413 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13415 /* Already printed the complaint above. */
13419 gdb_assert (call_site
->parameter_count
< nparams
);
13420 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13422 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13423 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13424 register is contained in DW_AT_call_value. */
13426 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13427 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13428 if (origin
== NULL
)
13430 /* This was a pre-DWARF-5 GNU extension alias
13431 for DW_AT_call_parameter. */
13432 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13434 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13436 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13438 sect_offset sect_off
= origin
->get_ref_die_offset ();
13439 if (!cu
->header
.offset_in_cu_p (sect_off
))
13441 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13442 binding can be done only inside one CU. Such referenced DIE
13443 therefore cannot be even moved to DW_TAG_partial_unit. */
13444 complaint (_("DW_AT_call_parameter offset is not in CU for "
13445 "DW_TAG_call_site child DIE %s [in module %s]"),
13446 sect_offset_str (child_die
->sect_off
),
13447 objfile_name (objfile
));
13450 parameter
->u
.param_cu_off
13451 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13453 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13455 complaint (_("No DW_FORM_block* DW_AT_location for "
13456 "DW_TAG_call_site child DIE %s [in module %s]"),
13457 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13462 struct dwarf_block
*block
= loc
->as_block ();
13464 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13465 (block
->data
, &block
->data
[block
->size
]);
13466 if (parameter
->u
.dwarf_reg
!= -1)
13467 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13468 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13469 &block
->data
[block
->size
],
13470 ¶meter
->u
.fb_offset
))
13471 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13474 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13475 "for DW_FORM_block* DW_AT_location is supported for "
13476 "DW_TAG_call_site child DIE %s "
13478 sect_offset_str (child_die
->sect_off
),
13479 objfile_name (objfile
));
13484 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13486 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13487 if (attr
== NULL
|| !attr
->form_is_block ())
13489 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13490 "DW_TAG_call_site child DIE %s [in module %s]"),
13491 sect_offset_str (child_die
->sect_off
),
13492 objfile_name (objfile
));
13496 struct dwarf_block
*block
= attr
->as_block ();
13497 parameter
->value
= block
->data
;
13498 parameter
->value_size
= block
->size
;
13500 /* Parameters are not pre-cleared by memset above. */
13501 parameter
->data_value
= NULL
;
13502 parameter
->data_value_size
= 0;
13503 call_site
->parameter_count
++;
13505 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13507 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13508 if (attr
!= nullptr)
13510 if (!attr
->form_is_block ())
13511 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13512 "DW_TAG_call_site child DIE %s [in module %s]"),
13513 sect_offset_str (child_die
->sect_off
),
13514 objfile_name (objfile
));
13517 block
= attr
->as_block ();
13518 parameter
->data_value
= block
->data
;
13519 parameter
->data_value_size
= block
->size
;
13525 /* Helper function for read_variable. If DIE represents a virtual
13526 table, then return the type of the concrete object that is
13527 associated with the virtual table. Otherwise, return NULL. */
13529 static struct type
*
13530 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13532 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13536 /* Find the type DIE. */
13537 struct die_info
*type_die
= NULL
;
13538 struct dwarf2_cu
*type_cu
= cu
;
13540 if (attr
->form_is_ref ())
13541 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13542 if (type_die
== NULL
)
13545 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13547 return die_containing_type (type_die
, type_cu
);
13550 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13553 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13555 struct rust_vtable_symbol
*storage
= NULL
;
13557 if (cu
->language
== language_rust
)
13559 struct type
*containing_type
= rust_containing_type (die
, cu
);
13561 if (containing_type
!= NULL
)
13563 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13565 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13566 storage
->concrete_type
= containing_type
;
13567 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13571 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13572 struct attribute
*abstract_origin
13573 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13574 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13575 if (res
== NULL
&& loc
&& abstract_origin
)
13577 /* We have a variable without a name, but with a location and an abstract
13578 origin. This may be a concrete instance of an abstract variable
13579 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13581 struct dwarf2_cu
*origin_cu
= cu
;
13582 struct die_info
*origin_die
13583 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13584 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13585 per_objfile
->per_bfd
->abstract_to_concrete
13586 [origin_die
->sect_off
].push_back (die
->sect_off
);
13590 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13591 reading .debug_rnglists.
13592 Callback's type should be:
13593 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13594 Return true if the attributes are present and valid, otherwise,
13597 template <typename Callback
>
13599 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13600 dwarf_tag tag
, Callback
&&callback
)
13602 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13603 struct objfile
*objfile
= per_objfile
->objfile
;
13604 bfd
*obfd
= objfile
->obfd
;
13605 /* Base address selection entry. */
13606 gdb::optional
<CORE_ADDR
> base
;
13607 const gdb_byte
*buffer
;
13608 CORE_ADDR baseaddr
;
13609 bool overflow
= false;
13610 ULONGEST addr_index
;
13611 struct dwarf2_section_info
*rnglists_section
;
13613 base
= cu
->base_address
;
13614 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13615 rnglists_section
->read (objfile
);
13617 if (offset
>= rnglists_section
->size
)
13619 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13623 buffer
= rnglists_section
->buffer
+ offset
;
13625 baseaddr
= objfile
->text_section_offset ();
13629 /* Initialize it due to a false compiler warning. */
13630 CORE_ADDR range_beginning
= 0, range_end
= 0;
13631 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13632 + rnglists_section
->size
);
13633 unsigned int bytes_read
;
13635 if (buffer
== buf_end
)
13640 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13643 case DW_RLE_end_of_list
:
13645 case DW_RLE_base_address
:
13646 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13651 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13652 buffer
+= bytes_read
;
13654 case DW_RLE_base_addressx
:
13655 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13656 buffer
+= bytes_read
;
13657 base
= read_addr_index (cu
, addr_index
);
13659 case DW_RLE_start_length
:
13660 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13665 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13667 buffer
+= bytes_read
;
13668 range_end
= (range_beginning
13669 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13670 buffer
+= bytes_read
;
13671 if (buffer
> buf_end
)
13677 case DW_RLE_startx_length
:
13678 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13679 buffer
+= bytes_read
;
13680 range_beginning
= read_addr_index (cu
, addr_index
);
13681 if (buffer
> buf_end
)
13686 range_end
= (range_beginning
13687 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13688 buffer
+= bytes_read
;
13690 case DW_RLE_offset_pair
:
13691 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13692 buffer
+= bytes_read
;
13693 if (buffer
> buf_end
)
13698 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13699 buffer
+= bytes_read
;
13700 if (buffer
> buf_end
)
13706 case DW_RLE_start_end
:
13707 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13712 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13714 buffer
+= bytes_read
;
13715 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13716 buffer
+= bytes_read
;
13718 case DW_RLE_startx_endx
:
13719 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13720 buffer
+= bytes_read
;
13721 range_beginning
= read_addr_index (cu
, addr_index
);
13722 if (buffer
> buf_end
)
13727 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13728 buffer
+= bytes_read
;
13729 range_end
= read_addr_index (cu
, addr_index
);
13732 complaint (_("Invalid .debug_rnglists data (no base address)"));
13735 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13737 if (rlet
== DW_RLE_base_address
)
13740 if (range_beginning
> range_end
)
13742 /* Inverted range entries are invalid. */
13743 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13747 /* Empty range entries have no effect. */
13748 if (range_beginning
== range_end
)
13751 /* Only DW_RLE_offset_pair needs the base address added. */
13752 if (rlet
== DW_RLE_offset_pair
)
13754 if (!base
.has_value ())
13756 /* We have no valid base address for the DW_RLE_offset_pair. */
13757 complaint (_("Invalid .debug_rnglists data (no base address for "
13758 "DW_RLE_offset_pair)"));
13762 range_beginning
+= *base
;
13763 range_end
+= *base
;
13766 /* A not-uncommon case of bad debug info.
13767 Don't pollute the addrmap with bad data. */
13768 if (range_beginning
+ baseaddr
== 0
13769 && !per_objfile
->per_bfd
->has_section_at_zero
)
13771 complaint (_(".debug_rnglists entry has start address of zero"
13772 " [in module %s]"), objfile_name (objfile
));
13776 callback (range_beginning
, range_end
);
13781 complaint (_("Offset %d is not terminated "
13782 "for DW_AT_ranges attribute"),
13790 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13791 Callback's type should be:
13792 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13793 Return 1 if the attributes are present and valid, otherwise, return 0. */
13795 template <typename Callback
>
13797 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13798 Callback
&&callback
)
13800 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13801 struct objfile
*objfile
= per_objfile
->objfile
;
13802 struct comp_unit_head
*cu_header
= &cu
->header
;
13803 bfd
*obfd
= objfile
->obfd
;
13804 unsigned int addr_size
= cu_header
->addr_size
;
13805 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13806 /* Base address selection entry. */
13807 gdb::optional
<CORE_ADDR
> base
;
13808 unsigned int dummy
;
13809 const gdb_byte
*buffer
;
13810 CORE_ADDR baseaddr
;
13812 if (cu_header
->version
>= 5)
13813 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13815 base
= cu
->base_address
;
13817 per_objfile
->per_bfd
->ranges
.read (objfile
);
13818 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13820 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13824 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13826 baseaddr
= objfile
->text_section_offset ();
13830 CORE_ADDR range_beginning
, range_end
;
13832 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13833 buffer
+= addr_size
;
13834 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13835 buffer
+= addr_size
;
13836 offset
+= 2 * addr_size
;
13838 /* An end of list marker is a pair of zero addresses. */
13839 if (range_beginning
== 0 && range_end
== 0)
13840 /* Found the end of list entry. */
13843 /* Each base address selection entry is a pair of 2 values.
13844 The first is the largest possible address, the second is
13845 the base address. Check for a base address here. */
13846 if ((range_beginning
& mask
) == mask
)
13848 /* If we found the largest possible address, then we already
13849 have the base address in range_end. */
13854 if (!base
.has_value ())
13856 /* We have no valid base address for the ranges
13858 complaint (_("Invalid .debug_ranges data (no base address)"));
13862 if (range_beginning
> range_end
)
13864 /* Inverted range entries are invalid. */
13865 complaint (_("Invalid .debug_ranges data (inverted range)"));
13869 /* Empty range entries have no effect. */
13870 if (range_beginning
== range_end
)
13873 range_beginning
+= *base
;
13874 range_end
+= *base
;
13876 /* A not-uncommon case of bad debug info.
13877 Don't pollute the addrmap with bad data. */
13878 if (range_beginning
+ baseaddr
== 0
13879 && !per_objfile
->per_bfd
->has_section_at_zero
)
13881 complaint (_(".debug_ranges entry has start address of zero"
13882 " [in module %s]"), objfile_name (objfile
));
13886 callback (range_beginning
, range_end
);
13892 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13893 Return 1 if the attributes are present and valid, otherwise, return 0.
13894 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
13897 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13898 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13899 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
13901 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13902 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
13903 struct gdbarch
*gdbarch
= objfile
->arch ();
13904 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13907 CORE_ADDR high
= 0;
13910 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
13911 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13913 if (ranges_pst
!= NULL
)
13918 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13919 range_beginning
+ baseaddr
)
13921 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13922 range_end
+ baseaddr
)
13924 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
13925 lowpc
, highpc
- 1, ranges_pst
);
13928 /* FIXME: This is recording everything as a low-high
13929 segment of consecutive addresses. We should have a
13930 data structure for discontiguous block ranges
13934 low
= range_beginning
;
13940 if (range_beginning
< low
)
13941 low
= range_beginning
;
13942 if (range_end
> high
)
13950 /* If the first entry is an end-of-list marker, the range
13951 describes an empty scope, i.e. no instructions. */
13957 *high_return
= high
;
13961 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13962 definition for the return value. *LOWPC and *HIGHPC are set iff
13963 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13965 static enum pc_bounds_kind
13966 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13967 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13968 dwarf2_psymtab
*pst
)
13970 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13971 struct attribute
*attr
;
13972 struct attribute
*attr_high
;
13974 CORE_ADDR high
= 0;
13975 enum pc_bounds_kind ret
;
13977 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13980 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13981 if (attr
!= nullptr)
13983 low
= attr
->as_address ();
13984 high
= attr_high
->as_address ();
13985 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13989 /* Found high w/o low attribute. */
13990 return PC_BOUNDS_INVALID
;
13992 /* Found consecutive range of addresses. */
13993 ret
= PC_BOUNDS_HIGH_LOW
;
13997 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13998 if (attr
!= nullptr && attr
->form_is_unsigned ())
14000 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14001 on DWARF version). */
14002 ULONGEST ranges_offset
= attr
->as_unsigned ();
14004 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14006 if (die
->tag
!= DW_TAG_compile_unit
)
14007 ranges_offset
+= cu
->gnu_ranges_base
;
14009 /* Value of the DW_AT_ranges attribute is the offset in the
14010 .debug_ranges section. */
14011 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14013 return PC_BOUNDS_INVALID
;
14014 /* Found discontinuous range of addresses. */
14015 ret
= PC_BOUNDS_RANGES
;
14018 return PC_BOUNDS_NOT_PRESENT
;
14021 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14023 return PC_BOUNDS_INVALID
;
14025 /* When using the GNU linker, .gnu.linkonce. sections are used to
14026 eliminate duplicate copies of functions and vtables and such.
14027 The linker will arbitrarily choose one and discard the others.
14028 The AT_*_pc values for such functions refer to local labels in
14029 these sections. If the section from that file was discarded, the
14030 labels are not in the output, so the relocs get a value of 0.
14031 If this is a discarded function, mark the pc bounds as invalid,
14032 so that GDB will ignore it. */
14033 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14034 return PC_BOUNDS_INVALID
;
14042 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14043 its low and high PC addresses. Do nothing if these addresses could not
14044 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14045 and HIGHPC to the high address if greater than HIGHPC. */
14048 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14049 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14050 struct dwarf2_cu
*cu
)
14052 CORE_ADDR low
, high
;
14053 struct die_info
*child
= die
->child
;
14055 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14057 *lowpc
= std::min (*lowpc
, low
);
14058 *highpc
= std::max (*highpc
, high
);
14061 /* If the language does not allow nested subprograms (either inside
14062 subprograms or lexical blocks), we're done. */
14063 if (cu
->language
!= language_ada
)
14066 /* Check all the children of the given DIE. If it contains nested
14067 subprograms, then check their pc bounds. Likewise, we need to
14068 check lexical blocks as well, as they may also contain subprogram
14070 while (child
&& child
->tag
)
14072 if (child
->tag
== DW_TAG_subprogram
14073 || child
->tag
== DW_TAG_lexical_block
)
14074 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14075 child
= child
->sibling
;
14079 /* Get the low and high pc's represented by the scope DIE, and store
14080 them in *LOWPC and *HIGHPC. If the correct values can't be
14081 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14084 get_scope_pc_bounds (struct die_info
*die
,
14085 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14086 struct dwarf2_cu
*cu
)
14088 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14089 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14090 CORE_ADDR current_low
, current_high
;
14092 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14093 >= PC_BOUNDS_RANGES
)
14095 best_low
= current_low
;
14096 best_high
= current_high
;
14100 struct die_info
*child
= die
->child
;
14102 while (child
&& child
->tag
)
14104 switch (child
->tag
) {
14105 case DW_TAG_subprogram
:
14106 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14108 case DW_TAG_namespace
:
14109 case DW_TAG_module
:
14110 /* FIXME: carlton/2004-01-16: Should we do this for
14111 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14112 that current GCC's always emit the DIEs corresponding
14113 to definitions of methods of classes as children of a
14114 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14115 the DIEs giving the declarations, which could be
14116 anywhere). But I don't see any reason why the
14117 standards says that they have to be there. */
14118 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14120 if (current_low
!= ((CORE_ADDR
) -1))
14122 best_low
= std::min (best_low
, current_low
);
14123 best_high
= std::max (best_high
, current_high
);
14131 child
= child
->sibling
;
14136 *highpc
= best_high
;
14139 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14143 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14144 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14146 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14147 struct gdbarch
*gdbarch
= objfile
->arch ();
14148 struct attribute
*attr
;
14149 struct attribute
*attr_high
;
14151 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14154 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14155 if (attr
!= nullptr)
14157 CORE_ADDR low
= attr
->as_address ();
14158 CORE_ADDR high
= attr_high
->as_address ();
14160 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14163 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14164 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14165 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14169 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14170 if (attr
!= nullptr && attr
->form_is_unsigned ())
14172 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14173 on DWARF version). */
14174 ULONGEST ranges_offset
= attr
->as_unsigned ();
14176 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14178 if (die
->tag
!= DW_TAG_compile_unit
)
14179 ranges_offset
+= cu
->gnu_ranges_base
;
14181 std::vector
<blockrange
> blockvec
;
14182 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14183 [&] (CORE_ADDR start
, CORE_ADDR end
)
14187 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14188 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14189 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14190 blockvec
.emplace_back (start
, end
);
14193 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14197 /* Check whether the producer field indicates either of GCC < 4.6, or the
14198 Intel C/C++ compiler, and cache the result in CU. */
14201 check_producer (struct dwarf2_cu
*cu
)
14205 if (cu
->producer
== NULL
)
14207 /* For unknown compilers expect their behavior is DWARF version
14210 GCC started to support .debug_types sections by -gdwarf-4 since
14211 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14212 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14213 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14214 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14216 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14218 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14219 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14221 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14223 cu
->producer_is_icc
= true;
14224 cu
->producer_is_icc_lt_14
= major
< 14;
14226 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14227 cu
->producer_is_codewarrior
= true;
14230 /* For other non-GCC compilers, expect their behavior is DWARF version
14234 cu
->checked_producer
= true;
14237 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14238 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14239 during 4.6.0 experimental. */
14242 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14244 if (!cu
->checked_producer
)
14245 check_producer (cu
);
14247 return cu
->producer_is_gxx_lt_4_6
;
14251 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14252 with incorrect is_stmt attributes. */
14255 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14257 if (!cu
->checked_producer
)
14258 check_producer (cu
);
14260 return cu
->producer_is_codewarrior
;
14263 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14264 If that attribute is not available, return the appropriate
14267 static enum dwarf_access_attribute
14268 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14270 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14271 if (attr
!= nullptr)
14273 LONGEST value
= attr
->constant_value (-1);
14274 if (value
== DW_ACCESS_public
14275 || value
== DW_ACCESS_protected
14276 || value
== DW_ACCESS_private
)
14277 return (dwarf_access_attribute
) value
;
14278 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14282 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14284 /* The default DWARF 2 accessibility for members is public, the default
14285 accessibility for inheritance is private. */
14287 if (die
->tag
!= DW_TAG_inheritance
)
14288 return DW_ACCESS_public
;
14290 return DW_ACCESS_private
;
14294 /* DWARF 3+ defines the default accessibility a different way. The same
14295 rules apply now for DW_TAG_inheritance as for the members and it only
14296 depends on the container kind. */
14298 if (die
->parent
->tag
== DW_TAG_class_type
)
14299 return DW_ACCESS_private
;
14301 return DW_ACCESS_public
;
14305 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14306 offset. If the attribute was not found return 0, otherwise return
14307 1. If it was found but could not properly be handled, set *OFFSET
14311 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14314 struct attribute
*attr
;
14316 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14321 /* Note that we do not check for a section offset first here.
14322 This is because DW_AT_data_member_location is new in DWARF 4,
14323 so if we see it, we can assume that a constant form is really
14324 a constant and not a section offset. */
14325 if (attr
->form_is_constant ())
14326 *offset
= attr
->constant_value (0);
14327 else if (attr
->form_is_section_offset ())
14328 dwarf2_complex_location_expr_complaint ();
14329 else if (attr
->form_is_block ())
14330 *offset
= decode_locdesc (attr
->as_block (), cu
);
14332 dwarf2_complex_location_expr_complaint ();
14340 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14343 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14344 struct field
*field
)
14346 struct attribute
*attr
;
14348 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14351 if (attr
->form_is_constant ())
14353 LONGEST offset
= attr
->constant_value (0);
14354 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14356 else if (attr
->form_is_section_offset ())
14357 dwarf2_complex_location_expr_complaint ();
14358 else if (attr
->form_is_block ())
14361 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14363 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14366 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14367 struct objfile
*objfile
= per_objfile
->objfile
;
14368 struct dwarf2_locexpr_baton
*dlbaton
14369 = XOBNEW (&objfile
->objfile_obstack
,
14370 struct dwarf2_locexpr_baton
);
14371 dlbaton
->data
= attr
->as_block ()->data
;
14372 dlbaton
->size
= attr
->as_block ()->size
;
14373 /* When using this baton, we want to compute the address
14374 of the field, not the value. This is why
14375 is_reference is set to false here. */
14376 dlbaton
->is_reference
= false;
14377 dlbaton
->per_objfile
= per_objfile
;
14378 dlbaton
->per_cu
= cu
->per_cu
;
14380 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14384 dwarf2_complex_location_expr_complaint ();
14388 /* Add an aggregate field to the field list. */
14391 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14392 struct dwarf2_cu
*cu
)
14394 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14395 struct gdbarch
*gdbarch
= objfile
->arch ();
14396 struct nextfield
*new_field
;
14397 struct attribute
*attr
;
14399 const char *fieldname
= "";
14401 if (die
->tag
== DW_TAG_inheritance
)
14403 fip
->baseclasses
.emplace_back ();
14404 new_field
= &fip
->baseclasses
.back ();
14408 fip
->fields
.emplace_back ();
14409 new_field
= &fip
->fields
.back ();
14412 new_field
->offset
= die
->sect_off
;
14414 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14415 if (new_field
->accessibility
!= DW_ACCESS_public
)
14416 fip
->non_public_fields
= true;
14418 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14419 if (attr
!= nullptr)
14420 new_field
->virtuality
= attr
->as_virtuality ();
14422 new_field
->virtuality
= DW_VIRTUALITY_none
;
14424 fp
= &new_field
->field
;
14426 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14428 /* Data member other than a C++ static data member. */
14430 /* Get type of field. */
14431 fp
->set_type (die_type (die
, cu
));
14433 SET_FIELD_BITPOS (*fp
, 0);
14435 /* Get bit size of field (zero if none). */
14436 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14437 if (attr
!= nullptr)
14439 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14443 FIELD_BITSIZE (*fp
) = 0;
14446 /* Get bit offset of field. */
14447 handle_data_member_location (die
, cu
, fp
);
14448 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14449 if (attr
!= nullptr && attr
->form_is_constant ())
14451 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14453 /* For big endian bits, the DW_AT_bit_offset gives the
14454 additional bit offset from the MSB of the containing
14455 anonymous object to the MSB of the field. We don't
14456 have to do anything special since we don't need to
14457 know the size of the anonymous object. */
14458 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14459 + attr
->constant_value (0)));
14463 /* For little endian bits, compute the bit offset to the
14464 MSB of the anonymous object, subtract off the number of
14465 bits from the MSB of the field to the MSB of the
14466 object, and then subtract off the number of bits of
14467 the field itself. The result is the bit offset of
14468 the LSB of the field. */
14469 int anonymous_size
;
14470 int bit_offset
= attr
->constant_value (0);
14472 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14473 if (attr
!= nullptr && attr
->form_is_constant ())
14475 /* The size of the anonymous object containing
14476 the bit field is explicit, so use the
14477 indicated size (in bytes). */
14478 anonymous_size
= attr
->constant_value (0);
14482 /* The size of the anonymous object containing
14483 the bit field must be inferred from the type
14484 attribute of the data member containing the
14486 anonymous_size
= TYPE_LENGTH (fp
->type ());
14488 SET_FIELD_BITPOS (*fp
,
14489 (FIELD_BITPOS (*fp
)
14490 + anonymous_size
* bits_per_byte
14491 - bit_offset
- FIELD_BITSIZE (*fp
)));
14494 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14496 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14497 + attr
->constant_value (0)));
14499 /* Get name of field. */
14500 fieldname
= dwarf2_name (die
, cu
);
14501 if (fieldname
== NULL
)
14504 /* The name is already allocated along with this objfile, so we don't
14505 need to duplicate it for the type. */
14506 fp
->name
= fieldname
;
14508 /* Change accessibility for artificial fields (e.g. virtual table
14509 pointer or virtual base class pointer) to private. */
14510 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14512 FIELD_ARTIFICIAL (*fp
) = 1;
14513 new_field
->accessibility
= DW_ACCESS_private
;
14514 fip
->non_public_fields
= true;
14517 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14519 /* C++ static member. */
14521 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14522 is a declaration, but all versions of G++ as of this writing
14523 (so through at least 3.2.1) incorrectly generate
14524 DW_TAG_variable tags. */
14526 const char *physname
;
14528 /* Get name of field. */
14529 fieldname
= dwarf2_name (die
, cu
);
14530 if (fieldname
== NULL
)
14533 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14535 /* Only create a symbol if this is an external value.
14536 new_symbol checks this and puts the value in the global symbol
14537 table, which we want. If it is not external, new_symbol
14538 will try to put the value in cu->list_in_scope which is wrong. */
14539 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14541 /* A static const member, not much different than an enum as far as
14542 we're concerned, except that we can support more types. */
14543 new_symbol (die
, NULL
, cu
);
14546 /* Get physical name. */
14547 physname
= dwarf2_physname (fieldname
, die
, cu
);
14549 /* The name is already allocated along with this objfile, so we don't
14550 need to duplicate it for the type. */
14551 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14552 fp
->set_type (die_type (die
, cu
));
14553 FIELD_NAME (*fp
) = fieldname
;
14555 else if (die
->tag
== DW_TAG_inheritance
)
14557 /* C++ base class field. */
14558 handle_data_member_location (die
, cu
, fp
);
14559 FIELD_BITSIZE (*fp
) = 0;
14560 fp
->set_type (die_type (die
, cu
));
14561 FIELD_NAME (*fp
) = fp
->type ()->name ();
14564 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14567 /* Can the type given by DIE define another type? */
14570 type_can_define_types (const struct die_info
*die
)
14574 case DW_TAG_typedef
:
14575 case DW_TAG_class_type
:
14576 case DW_TAG_structure_type
:
14577 case DW_TAG_union_type
:
14578 case DW_TAG_enumeration_type
:
14586 /* Add a type definition defined in the scope of the FIP's class. */
14589 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14590 struct dwarf2_cu
*cu
)
14592 struct decl_field fp
;
14593 memset (&fp
, 0, sizeof (fp
));
14595 gdb_assert (type_can_define_types (die
));
14597 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14598 fp
.name
= dwarf2_name (die
, cu
);
14599 fp
.type
= read_type_die (die
, cu
);
14601 /* Save accessibility. */
14602 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14603 switch (accessibility
)
14605 case DW_ACCESS_public
:
14606 /* The assumed value if neither private nor protected. */
14608 case DW_ACCESS_private
:
14611 case DW_ACCESS_protected
:
14612 fp
.is_protected
= 1;
14616 if (die
->tag
== DW_TAG_typedef
)
14617 fip
->typedef_field_list
.push_back (fp
);
14619 fip
->nested_types_list
.push_back (fp
);
14622 /* A convenience typedef that's used when finding the discriminant
14623 field for a variant part. */
14624 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14627 /* Compute the discriminant range for a given variant. OBSTACK is
14628 where the results will be stored. VARIANT is the variant to
14629 process. IS_UNSIGNED indicates whether the discriminant is signed
14632 static const gdb::array_view
<discriminant_range
>
14633 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14636 std::vector
<discriminant_range
> ranges
;
14638 if (variant
.default_branch
)
14641 if (variant
.discr_list_data
== nullptr)
14643 discriminant_range r
14644 = {variant
.discriminant_value
, variant
.discriminant_value
};
14645 ranges
.push_back (r
);
14649 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14650 variant
.discr_list_data
->size
);
14651 while (!data
.empty ())
14653 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14655 complaint (_("invalid discriminant marker: %d"), data
[0]);
14658 bool is_range
= data
[0] == DW_DSC_range
;
14659 data
= data
.slice (1);
14661 ULONGEST low
, high
;
14662 unsigned int bytes_read
;
14666 complaint (_("DW_AT_discr_list missing low value"));
14670 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14672 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14674 data
= data
.slice (bytes_read
);
14680 complaint (_("DW_AT_discr_list missing high value"));
14684 high
= read_unsigned_leb128 (nullptr, data
.data (),
14687 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14689 data
= data
.slice (bytes_read
);
14694 ranges
.push_back ({ low
, high
});
14698 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14700 std::copy (ranges
.begin (), ranges
.end (), result
);
14701 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14704 static const gdb::array_view
<variant_part
> create_variant_parts
14705 (struct obstack
*obstack
,
14706 const offset_map_type
&offset_map
,
14707 struct field_info
*fi
,
14708 const std::vector
<variant_part_builder
> &variant_parts
);
14710 /* Fill in a "struct variant" for a given variant field. RESULT is
14711 the variant to fill in. OBSTACK is where any needed allocations
14712 will be done. OFFSET_MAP holds the mapping from section offsets to
14713 fields for the type. FI describes the fields of the type we're
14714 processing. FIELD is the variant field we're converting. */
14717 create_one_variant (variant
&result
, struct obstack
*obstack
,
14718 const offset_map_type
&offset_map
,
14719 struct field_info
*fi
, const variant_field
&field
)
14721 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14722 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14723 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14724 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14725 field
.variant_parts
);
14728 /* Fill in a "struct variant_part" for a given variant part. RESULT
14729 is the variant part to fill in. OBSTACK is where any needed
14730 allocations will be done. OFFSET_MAP holds the mapping from
14731 section offsets to fields for the type. FI describes the fields of
14732 the type we're processing. BUILDER is the variant part to be
14736 create_one_variant_part (variant_part
&result
,
14737 struct obstack
*obstack
,
14738 const offset_map_type
&offset_map
,
14739 struct field_info
*fi
,
14740 const variant_part_builder
&builder
)
14742 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14743 if (iter
== offset_map
.end ())
14745 result
.discriminant_index
= -1;
14746 /* Doesn't matter. */
14747 result
.is_unsigned
= false;
14751 result
.discriminant_index
= iter
->second
;
14753 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14756 size_t n
= builder
.variants
.size ();
14757 variant
*output
= new (obstack
) variant
[n
];
14758 for (size_t i
= 0; i
< n
; ++i
)
14759 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14760 builder
.variants
[i
]);
14762 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14765 /* Create a vector of variant parts that can be attached to a type.
14766 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14767 holds the mapping from section offsets to fields for the type. FI
14768 describes the fields of the type we're processing. VARIANT_PARTS
14769 is the vector to convert. */
14771 static const gdb::array_view
<variant_part
>
14772 create_variant_parts (struct obstack
*obstack
,
14773 const offset_map_type
&offset_map
,
14774 struct field_info
*fi
,
14775 const std::vector
<variant_part_builder
> &variant_parts
)
14777 if (variant_parts
.empty ())
14780 size_t n
= variant_parts
.size ();
14781 variant_part
*result
= new (obstack
) variant_part
[n
];
14782 for (size_t i
= 0; i
< n
; ++i
)
14783 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14786 return gdb::array_view
<variant_part
> (result
, n
);
14789 /* Compute the variant part vector for FIP, attaching it to TYPE when
14793 add_variant_property (struct field_info
*fip
, struct type
*type
,
14794 struct dwarf2_cu
*cu
)
14796 /* Map section offsets of fields to their field index. Note the
14797 field index here does not take the number of baseclasses into
14799 offset_map_type offset_map
;
14800 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14801 offset_map
[fip
->fields
[i
].offset
] = i
;
14803 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14804 gdb::array_view
<variant_part
> parts
14805 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14806 fip
->variant_parts
);
14808 struct dynamic_prop prop
;
14809 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14810 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14813 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14816 /* Create the vector of fields, and attach it to the type. */
14819 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14820 struct dwarf2_cu
*cu
)
14822 int nfields
= fip
->nfields ();
14824 /* Record the field count, allocate space for the array of fields,
14825 and create blank accessibility bitfields if necessary. */
14826 type
->set_num_fields (nfields
);
14828 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14830 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14832 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14834 TYPE_FIELD_PRIVATE_BITS (type
) =
14835 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14836 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14838 TYPE_FIELD_PROTECTED_BITS (type
) =
14839 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14840 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14842 TYPE_FIELD_IGNORE_BITS (type
) =
14843 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14844 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14847 /* If the type has baseclasses, allocate and clear a bit vector for
14848 TYPE_FIELD_VIRTUAL_BITS. */
14849 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14851 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14852 unsigned char *pointer
;
14854 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14855 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14856 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14857 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14858 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14861 if (!fip
->variant_parts
.empty ())
14862 add_variant_property (fip
, type
, cu
);
14864 /* Copy the saved-up fields into the field vector. */
14865 for (int i
= 0; i
< nfields
; ++i
)
14867 struct nextfield
&field
14868 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14869 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14871 type
->field (i
) = field
.field
;
14872 switch (field
.accessibility
)
14874 case DW_ACCESS_private
:
14875 if (cu
->language
!= language_ada
)
14876 SET_TYPE_FIELD_PRIVATE (type
, i
);
14879 case DW_ACCESS_protected
:
14880 if (cu
->language
!= language_ada
)
14881 SET_TYPE_FIELD_PROTECTED (type
, i
);
14884 case DW_ACCESS_public
:
14888 /* Unknown accessibility. Complain and treat it as public. */
14890 complaint (_("unsupported accessibility %d"),
14891 field
.accessibility
);
14895 if (i
< fip
->baseclasses
.size ())
14897 switch (field
.virtuality
)
14899 case DW_VIRTUALITY_virtual
:
14900 case DW_VIRTUALITY_pure_virtual
:
14901 if (cu
->language
== language_ada
)
14902 error (_("unexpected virtuality in component of Ada type"));
14903 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14910 /* Return true if this member function is a constructor, false
14914 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14916 const char *fieldname
;
14917 const char *type_name
;
14920 if (die
->parent
== NULL
)
14923 if (die
->parent
->tag
!= DW_TAG_structure_type
14924 && die
->parent
->tag
!= DW_TAG_union_type
14925 && die
->parent
->tag
!= DW_TAG_class_type
)
14928 fieldname
= dwarf2_name (die
, cu
);
14929 type_name
= dwarf2_name (die
->parent
, cu
);
14930 if (fieldname
== NULL
|| type_name
== NULL
)
14933 len
= strlen (fieldname
);
14934 return (strncmp (fieldname
, type_name
, len
) == 0
14935 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14938 /* Add a member function to the proper fieldlist. */
14941 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14942 struct type
*type
, struct dwarf2_cu
*cu
)
14944 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14945 struct attribute
*attr
;
14947 struct fnfieldlist
*flp
= nullptr;
14948 struct fn_field
*fnp
;
14949 const char *fieldname
;
14950 struct type
*this_type
;
14952 if (cu
->language
== language_ada
)
14953 error (_("unexpected member function in Ada type"));
14955 /* Get name of member function. */
14956 fieldname
= dwarf2_name (die
, cu
);
14957 if (fieldname
== NULL
)
14960 /* Look up member function name in fieldlist. */
14961 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14963 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14965 flp
= &fip
->fnfieldlists
[i
];
14970 /* Create a new fnfieldlist if necessary. */
14971 if (flp
== nullptr)
14973 fip
->fnfieldlists
.emplace_back ();
14974 flp
= &fip
->fnfieldlists
.back ();
14975 flp
->name
= fieldname
;
14976 i
= fip
->fnfieldlists
.size () - 1;
14979 /* Create a new member function field and add it to the vector of
14981 flp
->fnfields
.emplace_back ();
14982 fnp
= &flp
->fnfields
.back ();
14984 /* Delay processing of the physname until later. */
14985 if (cu
->language
== language_cplus
)
14986 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14990 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14991 fnp
->physname
= physname
? physname
: "";
14994 fnp
->type
= alloc_type (objfile
);
14995 this_type
= read_type_die (die
, cu
);
14996 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
14998 int nparams
= this_type
->num_fields ();
15000 /* TYPE is the domain of this method, and THIS_TYPE is the type
15001 of the method itself (TYPE_CODE_METHOD). */
15002 smash_to_method_type (fnp
->type
, type
,
15003 TYPE_TARGET_TYPE (this_type
),
15004 this_type
->fields (),
15005 this_type
->num_fields (),
15006 this_type
->has_varargs ());
15008 /* Handle static member functions.
15009 Dwarf2 has no clean way to discern C++ static and non-static
15010 member functions. G++ helps GDB by marking the first
15011 parameter for non-static member functions (which is the this
15012 pointer) as artificial. We obtain this information from
15013 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15014 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15015 fnp
->voffset
= VOFFSET_STATIC
;
15018 complaint (_("member function type missing for '%s'"),
15019 dwarf2_full_name (fieldname
, die
, cu
));
15021 /* Get fcontext from DW_AT_containing_type if present. */
15022 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15023 fnp
->fcontext
= die_containing_type (die
, cu
);
15025 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15026 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15028 /* Get accessibility. */
15029 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15030 switch (accessibility
)
15032 case DW_ACCESS_private
:
15033 fnp
->is_private
= 1;
15035 case DW_ACCESS_protected
:
15036 fnp
->is_protected
= 1;
15040 /* Check for artificial methods. */
15041 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15042 if (attr
&& attr
->as_boolean ())
15043 fnp
->is_artificial
= 1;
15045 /* Check for defaulted methods. */
15046 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15047 if (attr
!= nullptr)
15048 fnp
->defaulted
= attr
->defaulted ();
15050 /* Check for deleted methods. */
15051 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15052 if (attr
!= nullptr && attr
->as_boolean ())
15053 fnp
->is_deleted
= 1;
15055 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15057 /* Get index in virtual function table if it is a virtual member
15058 function. For older versions of GCC, this is an offset in the
15059 appropriate virtual table, as specified by DW_AT_containing_type.
15060 For everyone else, it is an expression to be evaluated relative
15061 to the object address. */
15063 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15064 if (attr
!= nullptr)
15066 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15068 struct dwarf_block
*block
= attr
->as_block ();
15070 if (block
->data
[0] == DW_OP_constu
)
15072 /* Old-style GCC. */
15073 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15075 else if (block
->data
[0] == DW_OP_deref
15076 || (block
->size
> 1
15077 && block
->data
[0] == DW_OP_deref_size
15078 && block
->data
[1] == cu
->header
.addr_size
))
15080 fnp
->voffset
= decode_locdesc (block
, cu
);
15081 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15082 dwarf2_complex_location_expr_complaint ();
15084 fnp
->voffset
/= cu
->header
.addr_size
;
15088 dwarf2_complex_location_expr_complaint ();
15090 if (!fnp
->fcontext
)
15092 /* If there is no `this' field and no DW_AT_containing_type,
15093 we cannot actually find a base class context for the
15095 if (this_type
->num_fields () == 0
15096 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15098 complaint (_("cannot determine context for virtual member "
15099 "function \"%s\" (offset %s)"),
15100 fieldname
, sect_offset_str (die
->sect_off
));
15105 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15109 else if (attr
->form_is_section_offset ())
15111 dwarf2_complex_location_expr_complaint ();
15115 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15121 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15122 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15124 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15125 complaint (_("Member function \"%s\" (offset %s) is virtual "
15126 "but the vtable offset is not specified"),
15127 fieldname
, sect_offset_str (die
->sect_off
));
15128 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15129 TYPE_CPLUS_DYNAMIC (type
) = 1;
15134 /* Create the vector of member function fields, and attach it to the type. */
15137 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15138 struct dwarf2_cu
*cu
)
15140 if (cu
->language
== language_ada
)
15141 error (_("unexpected member functions in Ada type"));
15143 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15144 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15146 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15148 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15150 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15151 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15153 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15154 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15155 fn_flp
->fn_fields
= (struct fn_field
*)
15156 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15158 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15159 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15162 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15165 /* Returns non-zero if NAME is the name of a vtable member in CU's
15166 language, zero otherwise. */
15168 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15170 static const char vptr
[] = "_vptr";
15172 /* Look for the C++ form of the vtable. */
15173 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15179 /* GCC outputs unnamed structures that are really pointers to member
15180 functions, with the ABI-specified layout. If TYPE describes
15181 such a structure, smash it into a member function type.
15183 GCC shouldn't do this; it should just output pointer to member DIEs.
15184 This is GCC PR debug/28767. */
15187 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15189 struct type
*pfn_type
, *self_type
, *new_type
;
15191 /* Check for a structure with no name and two children. */
15192 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15195 /* Check for __pfn and __delta members. */
15196 if (TYPE_FIELD_NAME (type
, 0) == NULL
15197 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15198 || TYPE_FIELD_NAME (type
, 1) == NULL
15199 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15202 /* Find the type of the method. */
15203 pfn_type
= type
->field (0).type ();
15204 if (pfn_type
== NULL
15205 || pfn_type
->code () != TYPE_CODE_PTR
15206 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15209 /* Look for the "this" argument. */
15210 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15211 if (pfn_type
->num_fields () == 0
15212 /* || pfn_type->field (0).type () == NULL */
15213 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15216 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15217 new_type
= alloc_type (objfile
);
15218 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15219 pfn_type
->fields (), pfn_type
->num_fields (),
15220 pfn_type
->has_varargs ());
15221 smash_to_methodptr_type (type
, new_type
);
15224 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15225 requires rewriting, then copy it and return the updated copy.
15226 Otherwise return nullptr. */
15228 static struct type
*
15229 rewrite_array_type (struct type
*type
)
15231 if (type
->code () != TYPE_CODE_ARRAY
)
15234 struct type
*index_type
= type
->index_type ();
15235 range_bounds
*current_bounds
= index_type
->bounds ();
15237 /* Handle multi-dimensional arrays. */
15238 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15239 if (new_target
== nullptr)
15241 /* Maybe we don't need to rewrite this array. */
15242 if (current_bounds
->low
.kind () == PROP_CONST
15243 && current_bounds
->high
.kind () == PROP_CONST
)
15247 /* Either the target type was rewritten, or the bounds have to be
15248 updated. Either way we want to copy the type and update
15250 struct type
*copy
= copy_type (type
);
15251 int nfields
= copy
->num_fields ();
15253 = ((struct field
*) TYPE_ZALLOC (copy
,
15254 nfields
* sizeof (struct field
)));
15255 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15256 copy
->set_fields (new_fields
);
15257 if (new_target
!= nullptr)
15258 TYPE_TARGET_TYPE (copy
) = new_target
;
15260 struct type
*index_copy
= copy_type (index_type
);
15261 range_bounds
*bounds
15262 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15263 sizeof (range_bounds
));
15264 *bounds
= *current_bounds
;
15265 bounds
->low
.set_const_val (1);
15266 bounds
->high
.set_const_val (0);
15267 index_copy
->set_bounds (bounds
);
15268 copy
->set_index_type (index_copy
);
15273 /* While some versions of GCC will generate complicated DWARF for an
15274 array (see quirk_ada_thick_pointer), more recent versions were
15275 modified to emit an explicit thick pointer structure. However, in
15276 this case, the array still has DWARF expressions for its ranges,
15277 and these must be ignored. */
15280 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15283 gdb_assert (cu
->language
== language_ada
);
15285 /* Check for a structure with two children. */
15286 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15289 /* Check for P_ARRAY and P_BOUNDS members. */
15290 if (TYPE_FIELD_NAME (type
, 0) == NULL
15291 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15292 || TYPE_FIELD_NAME (type
, 1) == NULL
15293 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15296 /* Make sure we're looking at a pointer to an array. */
15297 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15300 /* The Ada code already knows how to handle these types, so all that
15301 we need to do is turn the bounds into static bounds. However, we
15302 don't want to rewrite existing array or index types in-place,
15303 because those may be referenced in other contexts where this
15304 rewriting is undesirable. */
15305 struct type
*new_ary_type
15306 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15307 if (new_ary_type
!= nullptr)
15308 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15311 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15312 appropriate error checking and issuing complaints if there is a
15316 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15318 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15320 if (attr
== nullptr)
15323 if (!attr
->form_is_constant ())
15325 complaint (_("DW_AT_alignment must have constant form"
15326 " - DIE at %s [in module %s]"),
15327 sect_offset_str (die
->sect_off
),
15328 objfile_name (cu
->per_objfile
->objfile
));
15332 LONGEST val
= attr
->constant_value (0);
15335 complaint (_("DW_AT_alignment value must not be negative"
15336 " - DIE at %s [in module %s]"),
15337 sect_offset_str (die
->sect_off
),
15338 objfile_name (cu
->per_objfile
->objfile
));
15341 ULONGEST align
= val
;
15345 complaint (_("DW_AT_alignment value must not be zero"
15346 " - DIE at %s [in module %s]"),
15347 sect_offset_str (die
->sect_off
),
15348 objfile_name (cu
->per_objfile
->objfile
));
15351 if ((align
& (align
- 1)) != 0)
15353 complaint (_("DW_AT_alignment value must be a power of 2"
15354 " - DIE at %s [in module %s]"),
15355 sect_offset_str (die
->sect_off
),
15356 objfile_name (cu
->per_objfile
->objfile
));
15363 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15364 the alignment for TYPE. */
15367 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15370 if (!set_type_align (type
, get_alignment (cu
, die
)))
15371 complaint (_("DW_AT_alignment value too large"
15372 " - DIE at %s [in module %s]"),
15373 sect_offset_str (die
->sect_off
),
15374 objfile_name (cu
->per_objfile
->objfile
));
15377 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15378 constant for a type, according to DWARF5 spec, Table 5.5. */
15381 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15386 case DW_CC_pass_by_reference
:
15387 case DW_CC_pass_by_value
:
15391 complaint (_("unrecognized DW_AT_calling_convention value "
15392 "(%s) for a type"), pulongest (value
));
15397 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15398 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15399 also according to GNU-specific values (see include/dwarf2.h). */
15402 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15407 case DW_CC_program
:
15411 case DW_CC_GNU_renesas_sh
:
15412 case DW_CC_GNU_borland_fastcall_i386
:
15413 case DW_CC_GDB_IBM_OpenCL
:
15417 complaint (_("unrecognized DW_AT_calling_convention value "
15418 "(%s) for a subroutine"), pulongest (value
));
15423 /* Called when we find the DIE that starts a structure or union scope
15424 (definition) to create a type for the structure or union. Fill in
15425 the type's name and general properties; the members will not be
15426 processed until process_structure_scope. A symbol table entry for
15427 the type will also not be done until process_structure_scope (assuming
15428 the type has a name).
15430 NOTE: we need to call these functions regardless of whether or not the
15431 DIE has a DW_AT_name attribute, since it might be an anonymous
15432 structure or union. This gets the type entered into our set of
15433 user defined types. */
15435 static struct type
*
15436 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15438 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15440 struct attribute
*attr
;
15443 /* If the definition of this type lives in .debug_types, read that type.
15444 Don't follow DW_AT_specification though, that will take us back up
15445 the chain and we want to go down. */
15446 attr
= die
->attr (DW_AT_signature
);
15447 if (attr
!= nullptr)
15449 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15451 /* The type's CU may not be the same as CU.
15452 Ensure TYPE is recorded with CU in die_type_hash. */
15453 return set_die_type (die
, type
, cu
);
15456 type
= alloc_type (objfile
);
15457 INIT_CPLUS_SPECIFIC (type
);
15459 name
= dwarf2_name (die
, cu
);
15462 if (cu
->language
== language_cplus
15463 || cu
->language
== language_d
15464 || cu
->language
== language_rust
)
15466 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15468 /* dwarf2_full_name might have already finished building the DIE's
15469 type. If so, there is no need to continue. */
15470 if (get_die_type (die
, cu
) != NULL
)
15471 return get_die_type (die
, cu
);
15473 type
->set_name (full_name
);
15477 /* The name is already allocated along with this objfile, so
15478 we don't need to duplicate it for the type. */
15479 type
->set_name (name
);
15483 if (die
->tag
== DW_TAG_structure_type
)
15485 type
->set_code (TYPE_CODE_STRUCT
);
15487 else if (die
->tag
== DW_TAG_union_type
)
15489 type
->set_code (TYPE_CODE_UNION
);
15493 type
->set_code (TYPE_CODE_STRUCT
);
15496 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15497 type
->set_is_declared_class (true);
15499 /* Store the calling convention in the type if it's available in
15500 the die. Otherwise the calling convention remains set to
15501 the default value DW_CC_normal. */
15502 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15503 if (attr
!= nullptr
15504 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15506 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15507 TYPE_CPLUS_CALLING_CONVENTION (type
)
15508 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15511 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15512 if (attr
!= nullptr)
15514 if (attr
->form_is_constant ())
15515 TYPE_LENGTH (type
) = attr
->constant_value (0);
15518 struct dynamic_prop prop
;
15519 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15520 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15521 TYPE_LENGTH (type
) = 0;
15526 TYPE_LENGTH (type
) = 0;
15529 maybe_set_alignment (cu
, die
, type
);
15531 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15533 /* ICC<14 does not output the required DW_AT_declaration on
15534 incomplete types, but gives them a size of zero. */
15535 type
->set_is_stub (true);
15538 type
->set_stub_is_supported (true);
15540 if (die_is_declaration (die
, cu
))
15541 type
->set_is_stub (true);
15542 else if (attr
== NULL
&& die
->child
== NULL
15543 && producer_is_realview (cu
->producer
))
15544 /* RealView does not output the required DW_AT_declaration
15545 on incomplete types. */
15546 type
->set_is_stub (true);
15548 /* We need to add the type field to the die immediately so we don't
15549 infinitely recurse when dealing with pointers to the structure
15550 type within the structure itself. */
15551 set_die_type (die
, type
, cu
);
15553 /* set_die_type should be already done. */
15554 set_descriptive_type (type
, die
, cu
);
15559 static void handle_struct_member_die
15560 (struct die_info
*child_die
,
15562 struct field_info
*fi
,
15563 std::vector
<struct symbol
*> *template_args
,
15564 struct dwarf2_cu
*cu
);
15566 /* A helper for handle_struct_member_die that handles
15567 DW_TAG_variant_part. */
15570 handle_variant_part (struct die_info
*die
, struct type
*type
,
15571 struct field_info
*fi
,
15572 std::vector
<struct symbol
*> *template_args
,
15573 struct dwarf2_cu
*cu
)
15575 variant_part_builder
*new_part
;
15576 if (fi
->current_variant_part
== nullptr)
15578 fi
->variant_parts
.emplace_back ();
15579 new_part
= &fi
->variant_parts
.back ();
15581 else if (!fi
->current_variant_part
->processing_variant
)
15583 complaint (_("nested DW_TAG_variant_part seen "
15584 "- DIE at %s [in module %s]"),
15585 sect_offset_str (die
->sect_off
),
15586 objfile_name (cu
->per_objfile
->objfile
));
15591 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15592 current
.variant_parts
.emplace_back ();
15593 new_part
= ¤t
.variant_parts
.back ();
15596 /* When we recurse, we want callees to add to this new variant
15598 scoped_restore save_current_variant_part
15599 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15601 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15604 /* It's a univariant form, an extension we support. */
15606 else if (discr
->form_is_ref ())
15608 struct dwarf2_cu
*target_cu
= cu
;
15609 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15611 new_part
->discriminant_offset
= target_die
->sect_off
;
15615 complaint (_("DW_AT_discr does not have DIE reference form"
15616 " - DIE at %s [in module %s]"),
15617 sect_offset_str (die
->sect_off
),
15618 objfile_name (cu
->per_objfile
->objfile
));
15621 for (die_info
*child_die
= die
->child
;
15623 child_die
= child_die
->sibling
)
15624 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15627 /* A helper for handle_struct_member_die that handles
15631 handle_variant (struct die_info
*die
, struct type
*type
,
15632 struct field_info
*fi
,
15633 std::vector
<struct symbol
*> *template_args
,
15634 struct dwarf2_cu
*cu
)
15636 if (fi
->current_variant_part
== nullptr)
15638 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15639 "- DIE at %s [in module %s]"),
15640 sect_offset_str (die
->sect_off
),
15641 objfile_name (cu
->per_objfile
->objfile
));
15644 if (fi
->current_variant_part
->processing_variant
)
15646 complaint (_("nested DW_TAG_variant seen "
15647 "- DIE at %s [in module %s]"),
15648 sect_offset_str (die
->sect_off
),
15649 objfile_name (cu
->per_objfile
->objfile
));
15653 scoped_restore save_processing_variant
15654 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15657 fi
->current_variant_part
->variants
.emplace_back ();
15658 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15659 variant
.first_field
= fi
->fields
.size ();
15661 /* In a variant we want to get the discriminant and also add a
15662 field for our sole member child. */
15663 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15664 if (discr
== nullptr || !discr
->form_is_constant ())
15666 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15667 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15668 variant
.default_branch
= true;
15670 variant
.discr_list_data
= discr
->as_block ();
15673 variant
.discriminant_value
= discr
->constant_value (0);
15675 for (die_info
*variant_child
= die
->child
;
15676 variant_child
!= NULL
;
15677 variant_child
= variant_child
->sibling
)
15678 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15680 variant
.last_field
= fi
->fields
.size ();
15683 /* A helper for process_structure_scope that handles a single member
15687 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15688 struct field_info
*fi
,
15689 std::vector
<struct symbol
*> *template_args
,
15690 struct dwarf2_cu
*cu
)
15692 if (child_die
->tag
== DW_TAG_member
15693 || child_die
->tag
== DW_TAG_variable
)
15695 /* NOTE: carlton/2002-11-05: A C++ static data member
15696 should be a DW_TAG_member that is a declaration, but
15697 all versions of G++ as of this writing (so through at
15698 least 3.2.1) incorrectly generate DW_TAG_variable
15699 tags for them instead. */
15700 dwarf2_add_field (fi
, child_die
, cu
);
15702 else if (child_die
->tag
== DW_TAG_subprogram
)
15704 /* Rust doesn't have member functions in the C++ sense.
15705 However, it does emit ordinary functions as children
15706 of a struct DIE. */
15707 if (cu
->language
== language_rust
)
15708 read_func_scope (child_die
, cu
);
15711 /* C++ member function. */
15712 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15715 else if (child_die
->tag
== DW_TAG_inheritance
)
15717 /* C++ base class field. */
15718 dwarf2_add_field (fi
, child_die
, cu
);
15720 else if (type_can_define_types (child_die
))
15721 dwarf2_add_type_defn (fi
, child_die
, cu
);
15722 else if (child_die
->tag
== DW_TAG_template_type_param
15723 || child_die
->tag
== DW_TAG_template_value_param
)
15725 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15728 template_args
->push_back (arg
);
15730 else if (child_die
->tag
== DW_TAG_variant_part
)
15731 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15732 else if (child_die
->tag
== DW_TAG_variant
)
15733 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15736 /* Finish creating a structure or union type, including filling in
15737 its members and creating a symbol for it. */
15740 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15742 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15743 struct die_info
*child_die
;
15746 type
= get_die_type (die
, cu
);
15748 type
= read_structure_type (die
, cu
);
15750 bool has_template_parameters
= false;
15751 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15753 struct field_info fi
;
15754 std::vector
<struct symbol
*> template_args
;
15756 child_die
= die
->child
;
15758 while (child_die
&& child_die
->tag
)
15760 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15761 child_die
= child_die
->sibling
;
15764 /* Attach template arguments to type. */
15765 if (!template_args
.empty ())
15767 has_template_parameters
= true;
15768 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15769 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15770 TYPE_TEMPLATE_ARGUMENTS (type
)
15771 = XOBNEWVEC (&objfile
->objfile_obstack
,
15773 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15774 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15775 template_args
.data (),
15776 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15777 * sizeof (struct symbol
*)));
15780 /* Attach fields and member functions to the type. */
15781 if (fi
.nfields () > 0)
15782 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15783 if (!fi
.fnfieldlists
.empty ())
15785 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15787 /* Get the type which refers to the base class (possibly this
15788 class itself) which contains the vtable pointer for the current
15789 class from the DW_AT_containing_type attribute. This use of
15790 DW_AT_containing_type is a GNU extension. */
15792 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15794 struct type
*t
= die_containing_type (die
, cu
);
15796 set_type_vptr_basetype (type
, t
);
15801 /* Our own class provides vtbl ptr. */
15802 for (i
= t
->num_fields () - 1;
15803 i
>= TYPE_N_BASECLASSES (t
);
15806 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15808 if (is_vtable_name (fieldname
, cu
))
15810 set_type_vptr_fieldno (type
, i
);
15815 /* Complain if virtual function table field not found. */
15816 if (i
< TYPE_N_BASECLASSES (t
))
15817 complaint (_("virtual function table pointer "
15818 "not found when defining class '%s'"),
15819 type
->name () ? type
->name () : "");
15823 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15826 else if (cu
->producer
15827 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15829 /* The IBM XLC compiler does not provide direct indication
15830 of the containing type, but the vtable pointer is
15831 always named __vfp. */
15835 for (i
= type
->num_fields () - 1;
15836 i
>= TYPE_N_BASECLASSES (type
);
15839 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15841 set_type_vptr_fieldno (type
, i
);
15842 set_type_vptr_basetype (type
, type
);
15849 /* Copy fi.typedef_field_list linked list elements content into the
15850 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15851 if (!fi
.typedef_field_list
.empty ())
15853 int count
= fi
.typedef_field_list
.size ();
15855 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15856 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15857 = ((struct decl_field
*)
15859 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15860 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15862 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15863 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15866 /* Copy fi.nested_types_list linked list elements content into the
15867 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15868 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15870 int count
= fi
.nested_types_list
.size ();
15872 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15873 TYPE_NESTED_TYPES_ARRAY (type
)
15874 = ((struct decl_field
*)
15875 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15876 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15878 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15879 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15883 quirk_gcc_member_function_pointer (type
, objfile
);
15884 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15885 cu
->rust_unions
.push_back (type
);
15886 else if (cu
->language
== language_ada
)
15887 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15889 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15890 snapshots) has been known to create a die giving a declaration
15891 for a class that has, as a child, a die giving a definition for a
15892 nested class. So we have to process our children even if the
15893 current die is a declaration. Normally, of course, a declaration
15894 won't have any children at all. */
15896 child_die
= die
->child
;
15898 while (child_die
!= NULL
&& child_die
->tag
)
15900 if (child_die
->tag
== DW_TAG_member
15901 || child_die
->tag
== DW_TAG_variable
15902 || child_die
->tag
== DW_TAG_inheritance
15903 || child_die
->tag
== DW_TAG_template_value_param
15904 || child_die
->tag
== DW_TAG_template_type_param
)
15909 process_die (child_die
, cu
);
15911 child_die
= child_die
->sibling
;
15914 /* Do not consider external references. According to the DWARF standard,
15915 these DIEs are identified by the fact that they have no byte_size
15916 attribute, and a declaration attribute. */
15917 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15918 || !die_is_declaration (die
, cu
)
15919 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15921 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15923 if (has_template_parameters
)
15925 struct symtab
*symtab
;
15926 if (sym
!= nullptr)
15927 symtab
= symbol_symtab (sym
);
15928 else if (cu
->line_header
!= nullptr)
15930 /* Any related symtab will do. */
15932 = cu
->line_header
->file_names ()[0].symtab
;
15937 complaint (_("could not find suitable "
15938 "symtab for template parameter"
15939 " - DIE at %s [in module %s]"),
15940 sect_offset_str (die
->sect_off
),
15941 objfile_name (objfile
));
15944 if (symtab
!= nullptr)
15946 /* Make sure that the symtab is set on the new symbols.
15947 Even though they don't appear in this symtab directly,
15948 other parts of gdb assume that symbols do, and this is
15949 reasonably true. */
15950 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15951 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15957 /* Assuming DIE is an enumeration type, and TYPE is its associated
15958 type, update TYPE using some information only available in DIE's
15959 children. In particular, the fields are computed. */
15962 update_enumeration_type_from_children (struct die_info
*die
,
15964 struct dwarf2_cu
*cu
)
15966 struct die_info
*child_die
;
15967 int unsigned_enum
= 1;
15970 auto_obstack obstack
;
15971 std::vector
<struct field
> fields
;
15973 for (child_die
= die
->child
;
15974 child_die
!= NULL
&& child_die
->tag
;
15975 child_die
= child_die
->sibling
)
15977 struct attribute
*attr
;
15979 const gdb_byte
*bytes
;
15980 struct dwarf2_locexpr_baton
*baton
;
15983 if (child_die
->tag
!= DW_TAG_enumerator
)
15986 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15990 name
= dwarf2_name (child_die
, cu
);
15992 name
= "<anonymous enumerator>";
15994 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15995 &value
, &bytes
, &baton
);
16003 if (count_one_bits_ll (value
) >= 2)
16007 fields
.emplace_back ();
16008 struct field
&field
= fields
.back ();
16009 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16010 SET_FIELD_ENUMVAL (field
, value
);
16013 if (!fields
.empty ())
16015 type
->set_num_fields (fields
.size ());
16018 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16019 memcpy (type
->fields (), fields
.data (),
16020 sizeof (struct field
) * fields
.size ());
16024 type
->set_is_unsigned (true);
16027 type
->set_is_flag_enum (true);
16030 /* Given a DW_AT_enumeration_type die, set its type. We do not
16031 complete the type's fields yet, or create any symbols. */
16033 static struct type
*
16034 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16036 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16038 struct attribute
*attr
;
16041 /* If the definition of this type lives in .debug_types, read that type.
16042 Don't follow DW_AT_specification though, that will take us back up
16043 the chain and we want to go down. */
16044 attr
= die
->attr (DW_AT_signature
);
16045 if (attr
!= nullptr)
16047 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16049 /* The type's CU may not be the same as CU.
16050 Ensure TYPE is recorded with CU in die_type_hash. */
16051 return set_die_type (die
, type
, cu
);
16054 type
= alloc_type (objfile
);
16056 type
->set_code (TYPE_CODE_ENUM
);
16057 name
= dwarf2_full_name (NULL
, die
, cu
);
16059 type
->set_name (name
);
16061 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16064 struct type
*underlying_type
= die_type (die
, cu
);
16066 TYPE_TARGET_TYPE (type
) = underlying_type
;
16069 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16070 if (attr
!= nullptr)
16072 TYPE_LENGTH (type
) = attr
->constant_value (0);
16076 TYPE_LENGTH (type
) = 0;
16079 maybe_set_alignment (cu
, die
, type
);
16081 /* The enumeration DIE can be incomplete. In Ada, any type can be
16082 declared as private in the package spec, and then defined only
16083 inside the package body. Such types are known as Taft Amendment
16084 Types. When another package uses such a type, an incomplete DIE
16085 may be generated by the compiler. */
16086 if (die_is_declaration (die
, cu
))
16087 type
->set_is_stub (true);
16089 /* If this type has an underlying type that is not a stub, then we
16090 may use its attributes. We always use the "unsigned" attribute
16091 in this situation, because ordinarily we guess whether the type
16092 is unsigned -- but the guess can be wrong and the underlying type
16093 can tell us the reality. However, we defer to a local size
16094 attribute if one exists, because this lets the compiler override
16095 the underlying type if needed. */
16096 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16098 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16099 underlying_type
= check_typedef (underlying_type
);
16101 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16103 if (TYPE_LENGTH (type
) == 0)
16104 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16106 if (TYPE_RAW_ALIGN (type
) == 0
16107 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16108 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16111 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16113 set_die_type (die
, type
, cu
);
16115 /* Finish the creation of this type by using the enum's children.
16116 Note that, as usual, this must come after set_die_type to avoid
16117 infinite recursion when trying to compute the names of the
16119 update_enumeration_type_from_children (die
, type
, cu
);
16124 /* Given a pointer to a die which begins an enumeration, process all
16125 the dies that define the members of the enumeration, and create the
16126 symbol for the enumeration type.
16128 NOTE: We reverse the order of the element list. */
16131 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16133 struct type
*this_type
;
16135 this_type
= get_die_type (die
, cu
);
16136 if (this_type
== NULL
)
16137 this_type
= read_enumeration_type (die
, cu
);
16139 if (die
->child
!= NULL
)
16141 struct die_info
*child_die
;
16144 child_die
= die
->child
;
16145 while (child_die
&& child_die
->tag
)
16147 if (child_die
->tag
!= DW_TAG_enumerator
)
16149 process_die (child_die
, cu
);
16153 name
= dwarf2_name (child_die
, cu
);
16155 new_symbol (child_die
, this_type
, cu
);
16158 child_die
= child_die
->sibling
;
16162 /* If we are reading an enum from a .debug_types unit, and the enum
16163 is a declaration, and the enum is not the signatured type in the
16164 unit, then we do not want to add a symbol for it. Adding a
16165 symbol would in some cases obscure the true definition of the
16166 enum, giving users an incomplete type when the definition is
16167 actually available. Note that we do not want to do this for all
16168 enums which are just declarations, because C++0x allows forward
16169 enum declarations. */
16170 if (cu
->per_cu
->is_debug_types
16171 && die_is_declaration (die
, cu
))
16173 struct signatured_type
*sig_type
;
16175 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16176 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16177 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16181 new_symbol (die
, this_type
, cu
);
16184 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16185 expression for an index type and finds the corresponding field
16186 offset in the hidden "P_BOUNDS" structure. Returns true on success
16187 and updates *FIELD, false if it fails to recognize an
16191 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16192 int *bounds_offset
, struct field
*field
,
16193 struct dwarf2_cu
*cu
)
16195 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16196 if (attr
== nullptr || !attr
->form_is_block ())
16199 const struct dwarf_block
*block
= attr
->as_block ();
16200 const gdb_byte
*start
= block
->data
;
16201 const gdb_byte
*end
= block
->data
+ block
->size
;
16203 /* The expression to recognize generally looks like:
16205 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16206 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16208 However, the second "plus_uconst" may be missing:
16210 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16211 DW_OP_deref_size: 4)
16213 This happens when the field is at the start of the structure.
16215 Also, the final deref may not be sized:
16217 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16220 This happens when the size of the index type happens to be the
16221 same as the architecture's word size. This can occur with or
16222 without the second plus_uconst. */
16224 if (end
- start
< 2)
16226 if (*start
++ != DW_OP_push_object_address
)
16228 if (*start
++ != DW_OP_plus_uconst
)
16231 uint64_t this_bound_off
;
16232 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16233 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16235 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16236 is consistent among all bounds. */
16237 if (*bounds_offset
== -1)
16238 *bounds_offset
= this_bound_off
;
16239 else if (*bounds_offset
!= this_bound_off
)
16242 if (start
== end
|| *start
++ != DW_OP_deref
)
16248 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16250 /* This means an offset of 0. */
16252 else if (*start
++ != DW_OP_plus_uconst
)
16256 /* The size is the parameter to DW_OP_plus_uconst. */
16258 start
= gdb_read_uleb128 (start
, end
, &val
);
16259 if (start
== nullptr)
16261 if ((int) val
!= val
)
16270 if (*start
== DW_OP_deref_size
)
16272 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16273 if (start
== nullptr)
16276 else if (*start
== DW_OP_deref
)
16278 size
= cu
->header
.addr_size
;
16284 SET_FIELD_BITPOS (*field
, 8 * offset
);
16285 if (size
!= TYPE_LENGTH (field
->type ()))
16286 FIELD_BITSIZE (*field
) = 8 * size
;
16291 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16292 some kinds of Ada arrays:
16294 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16295 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16296 <11e0> DW_AT_data_location: 2 byte block: 97 6
16297 (DW_OP_push_object_address; DW_OP_deref)
16298 <11e3> DW_AT_type : <0x1173>
16299 <11e7> DW_AT_sibling : <0x1201>
16300 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16301 <11ec> DW_AT_type : <0x1206>
16302 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16303 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16304 DW_OP_deref_size: 4)
16305 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16306 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16307 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16309 This actually represents a "thick pointer", which is a structure
16310 with two elements: one that is a pointer to the array data, and one
16311 that is a pointer to another structure; this second structure holds
16314 This returns a new type on success, or nullptr if this didn't
16315 recognize the type. */
16317 static struct type
*
16318 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16321 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16322 /* So far we've only seen this with block form. */
16323 if (attr
== nullptr || !attr
->form_is_block ())
16326 /* Note that this will fail if the structure layout is changed by
16327 the compiler. However, we have no good way to recognize some
16328 other layout, because we don't know what expression the compiler
16329 might choose to emit should this happen. */
16330 struct dwarf_block
*blk
= attr
->as_block ();
16332 || blk
->data
[0] != DW_OP_push_object_address
16333 || blk
->data
[1] != DW_OP_deref
)
16336 int bounds_offset
= -1;
16337 int max_align
= -1;
16338 std::vector
<struct field
> range_fields
;
16339 for (struct die_info
*child_die
= die
->child
;
16341 child_die
= child_die
->sibling
)
16343 if (child_die
->tag
== DW_TAG_subrange_type
)
16345 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16347 int this_align
= type_align (underlying
);
16348 if (this_align
> max_align
)
16349 max_align
= this_align
;
16351 range_fields
.emplace_back ();
16352 range_fields
.emplace_back ();
16354 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16355 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16357 lower
.set_type (underlying
);
16358 FIELD_ARTIFICIAL (lower
) = 1;
16360 upper
.set_type (underlying
);
16361 FIELD_ARTIFICIAL (upper
) = 1;
16363 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16364 &bounds_offset
, &lower
, cu
)
16365 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16366 &bounds_offset
, &upper
, cu
))
16371 /* This shouldn't really happen, but double-check that we found
16372 where the bounds are stored. */
16373 if (bounds_offset
== -1)
16376 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16377 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16381 /* Set the name of each field in the bounds. */
16382 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16383 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16384 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16385 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16388 struct type
*bounds
= alloc_type (objfile
);
16389 bounds
->set_code (TYPE_CODE_STRUCT
);
16391 bounds
->set_num_fields (range_fields
.size ());
16393 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16394 * sizeof (struct field
))));
16395 memcpy (bounds
->fields (), range_fields
.data (),
16396 bounds
->num_fields () * sizeof (struct field
));
16398 int last_fieldno
= range_fields
.size () - 1;
16399 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16400 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16401 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16403 /* Rewrite the existing array type in place. Specifically, we
16404 remove any dynamic properties we might have read, and we replace
16405 the index types. */
16406 struct type
*iter
= type
;
16407 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16409 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16410 iter
->main_type
->dyn_prop_list
= nullptr;
16411 iter
->set_index_type
16412 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16413 iter
= TYPE_TARGET_TYPE (iter
);
16416 struct type
*result
= alloc_type (objfile
);
16417 result
->set_code (TYPE_CODE_STRUCT
);
16419 result
->set_num_fields (2);
16421 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16422 * sizeof (struct field
))));
16424 /* The names are chosen to coincide with what the compiler does with
16425 -fgnat-encodings=all, which the Ada code in gdb already
16427 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16428 result
->field (0).set_type (lookup_pointer_type (type
));
16430 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16431 result
->field (1).set_type (lookup_pointer_type (bounds
));
16432 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16434 result
->set_name (type
->name ());
16435 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16436 + TYPE_LENGTH (result
->field (1).type ()));
16441 /* Extract all information from a DW_TAG_array_type DIE and put it in
16442 the DIE's type field. For now, this only handles one dimensional
16445 static struct type
*
16446 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16448 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16449 struct die_info
*child_die
;
16451 struct type
*element_type
, *range_type
, *index_type
;
16452 struct attribute
*attr
;
16454 struct dynamic_prop
*byte_stride_prop
= NULL
;
16455 unsigned int bit_stride
= 0;
16457 element_type
= die_type (die
, cu
);
16459 /* The die_type call above may have already set the type for this DIE. */
16460 type
= get_die_type (die
, cu
);
16464 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16468 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16471 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16472 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16476 complaint (_("unable to read array DW_AT_byte_stride "
16477 " - DIE at %s [in module %s]"),
16478 sect_offset_str (die
->sect_off
),
16479 objfile_name (cu
->per_objfile
->objfile
));
16480 /* Ignore this attribute. We will likely not be able to print
16481 arrays of this type correctly, but there is little we can do
16482 to help if we cannot read the attribute's value. */
16483 byte_stride_prop
= NULL
;
16487 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16489 bit_stride
= attr
->constant_value (0);
16491 /* Irix 6.2 native cc creates array types without children for
16492 arrays with unspecified length. */
16493 if (die
->child
== NULL
)
16495 index_type
= objfile_type (objfile
)->builtin_int
;
16496 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16497 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16498 byte_stride_prop
, bit_stride
);
16499 return set_die_type (die
, type
, cu
);
16502 std::vector
<struct type
*> range_types
;
16503 child_die
= die
->child
;
16504 while (child_die
&& child_die
->tag
)
16506 if (child_die
->tag
== DW_TAG_subrange_type
)
16508 struct type
*child_type
= read_type_die (child_die
, cu
);
16510 if (child_type
!= NULL
)
16512 /* The range type was succesfully read. Save it for the
16513 array type creation. */
16514 range_types
.push_back (child_type
);
16517 child_die
= child_die
->sibling
;
16520 if (range_types
.empty ())
16522 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16523 sect_offset_str (die
->sect_off
),
16524 objfile_name (cu
->per_objfile
->objfile
));
16528 /* Dwarf2 dimensions are output from left to right, create the
16529 necessary array types in backwards order. */
16531 type
= element_type
;
16533 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16537 while (i
< range_types
.size ())
16539 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16540 byte_stride_prop
, bit_stride
);
16542 byte_stride_prop
= nullptr;
16547 size_t ndim
= range_types
.size ();
16550 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16551 byte_stride_prop
, bit_stride
);
16553 byte_stride_prop
= nullptr;
16557 gdb_assert (type
!= element_type
);
16559 /* Understand Dwarf2 support for vector types (like they occur on
16560 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16561 array type. This is not part of the Dwarf2/3 standard yet, but a
16562 custom vendor extension. The main difference between a regular
16563 array and the vector variant is that vectors are passed by value
16565 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16566 if (attr
!= nullptr)
16567 make_vector_type (type
);
16569 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16570 implementation may choose to implement triple vectors using this
16572 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16573 if (attr
!= nullptr && attr
->form_is_unsigned ())
16575 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16576 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16578 complaint (_("DW_AT_byte_size for array type smaller "
16579 "than the total size of elements"));
16582 name
= dwarf2_name (die
, cu
);
16584 type
->set_name (name
);
16586 maybe_set_alignment (cu
, die
, type
);
16588 struct type
*replacement_type
= nullptr;
16589 if (cu
->language
== language_ada
)
16591 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16592 if (replacement_type
!= nullptr)
16593 type
= replacement_type
;
16596 /* Install the type in the die. */
16597 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16599 /* set_die_type should be already done. */
16600 set_descriptive_type (type
, die
, cu
);
16605 static enum dwarf_array_dim_ordering
16606 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16608 struct attribute
*attr
;
16610 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16612 if (attr
!= nullptr)
16614 LONGEST val
= attr
->constant_value (-1);
16615 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16616 return (enum dwarf_array_dim_ordering
) val
;
16619 /* GNU F77 is a special case, as at 08/2004 array type info is the
16620 opposite order to the dwarf2 specification, but data is still
16621 laid out as per normal fortran.
16623 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16624 version checking. */
16626 if (cu
->language
== language_fortran
16627 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16629 return DW_ORD_row_major
;
16632 switch (cu
->language_defn
->array_ordering ())
16634 case array_column_major
:
16635 return DW_ORD_col_major
;
16636 case array_row_major
:
16638 return DW_ORD_row_major
;
16642 /* Extract all information from a DW_TAG_set_type DIE and put it in
16643 the DIE's type field. */
16645 static struct type
*
16646 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16648 struct type
*domain_type
, *set_type
;
16649 struct attribute
*attr
;
16651 domain_type
= die_type (die
, cu
);
16653 /* The die_type call above may have already set the type for this DIE. */
16654 set_type
= get_die_type (die
, cu
);
16658 set_type
= create_set_type (NULL
, domain_type
);
16660 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16661 if (attr
!= nullptr && attr
->form_is_unsigned ())
16662 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16664 maybe_set_alignment (cu
, die
, set_type
);
16666 return set_die_type (die
, set_type
, cu
);
16669 /* A helper for read_common_block that creates a locexpr baton.
16670 SYM is the symbol which we are marking as computed.
16671 COMMON_DIE is the DIE for the common block.
16672 COMMON_LOC is the location expression attribute for the common
16674 MEMBER_LOC is the location expression attribute for the particular
16675 member of the common block that we are processing.
16676 CU is the CU from which the above come. */
16679 mark_common_block_symbol_computed (struct symbol
*sym
,
16680 struct die_info
*common_die
,
16681 struct attribute
*common_loc
,
16682 struct attribute
*member_loc
,
16683 struct dwarf2_cu
*cu
)
16685 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16686 struct objfile
*objfile
= per_objfile
->objfile
;
16687 struct dwarf2_locexpr_baton
*baton
;
16689 unsigned int cu_off
;
16690 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16691 LONGEST offset
= 0;
16693 gdb_assert (common_loc
&& member_loc
);
16694 gdb_assert (common_loc
->form_is_block ());
16695 gdb_assert (member_loc
->form_is_block ()
16696 || member_loc
->form_is_constant ());
16698 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16699 baton
->per_objfile
= per_objfile
;
16700 baton
->per_cu
= cu
->per_cu
;
16701 gdb_assert (baton
->per_cu
);
16703 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16705 if (member_loc
->form_is_constant ())
16707 offset
= member_loc
->constant_value (0);
16708 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16711 baton
->size
+= member_loc
->as_block ()->size
;
16713 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16716 *ptr
++ = DW_OP_call4
;
16717 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16718 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16721 if (member_loc
->form_is_constant ())
16723 *ptr
++ = DW_OP_addr
;
16724 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16725 ptr
+= cu
->header
.addr_size
;
16729 /* We have to copy the data here, because DW_OP_call4 will only
16730 use a DW_AT_location attribute. */
16731 struct dwarf_block
*block
= member_loc
->as_block ();
16732 memcpy (ptr
, block
->data
, block
->size
);
16733 ptr
+= block
->size
;
16736 *ptr
++ = DW_OP_plus
;
16737 gdb_assert (ptr
- baton
->data
== baton
->size
);
16739 SYMBOL_LOCATION_BATON (sym
) = baton
;
16740 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16743 /* Create appropriate locally-scoped variables for all the
16744 DW_TAG_common_block entries. Also create a struct common_block
16745 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16746 is used to separate the common blocks name namespace from regular
16750 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16752 struct attribute
*attr
;
16754 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16755 if (attr
!= nullptr)
16757 /* Support the .debug_loc offsets. */
16758 if (attr
->form_is_block ())
16762 else if (attr
->form_is_section_offset ())
16764 dwarf2_complex_location_expr_complaint ();
16769 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16770 "common block member");
16775 if (die
->child
!= NULL
)
16777 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16778 struct die_info
*child_die
;
16779 size_t n_entries
= 0, size
;
16780 struct common_block
*common_block
;
16781 struct symbol
*sym
;
16783 for (child_die
= die
->child
;
16784 child_die
&& child_die
->tag
;
16785 child_die
= child_die
->sibling
)
16788 size
= (sizeof (struct common_block
)
16789 + (n_entries
- 1) * sizeof (struct symbol
*));
16791 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16793 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16794 common_block
->n_entries
= 0;
16796 for (child_die
= die
->child
;
16797 child_die
&& child_die
->tag
;
16798 child_die
= child_die
->sibling
)
16800 /* Create the symbol in the DW_TAG_common_block block in the current
16802 sym
= new_symbol (child_die
, NULL
, cu
);
16805 struct attribute
*member_loc
;
16807 common_block
->contents
[common_block
->n_entries
++] = sym
;
16809 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16813 /* GDB has handled this for a long time, but it is
16814 not specified by DWARF. It seems to have been
16815 emitted by gfortran at least as recently as:
16816 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16817 complaint (_("Variable in common block has "
16818 "DW_AT_data_member_location "
16819 "- DIE at %s [in module %s]"),
16820 sect_offset_str (child_die
->sect_off
),
16821 objfile_name (objfile
));
16823 if (member_loc
->form_is_section_offset ())
16824 dwarf2_complex_location_expr_complaint ();
16825 else if (member_loc
->form_is_constant ()
16826 || member_loc
->form_is_block ())
16828 if (attr
!= nullptr)
16829 mark_common_block_symbol_computed (sym
, die
, attr
,
16833 dwarf2_complex_location_expr_complaint ();
16838 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16839 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16843 /* Create a type for a C++ namespace. */
16845 static struct type
*
16846 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16848 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16849 const char *previous_prefix
, *name
;
16853 /* For extensions, reuse the type of the original namespace. */
16854 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16856 struct die_info
*ext_die
;
16857 struct dwarf2_cu
*ext_cu
= cu
;
16859 ext_die
= dwarf2_extension (die
, &ext_cu
);
16860 type
= read_type_die (ext_die
, ext_cu
);
16862 /* EXT_CU may not be the same as CU.
16863 Ensure TYPE is recorded with CU in die_type_hash. */
16864 return set_die_type (die
, type
, cu
);
16867 name
= namespace_name (die
, &is_anonymous
, cu
);
16869 /* Now build the name of the current namespace. */
16871 previous_prefix
= determine_prefix (die
, cu
);
16872 if (previous_prefix
[0] != '\0')
16873 name
= typename_concat (&objfile
->objfile_obstack
,
16874 previous_prefix
, name
, 0, cu
);
16876 /* Create the type. */
16877 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16879 return set_die_type (die
, type
, cu
);
16882 /* Read a namespace scope. */
16885 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16887 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16890 /* Add a symbol associated to this if we haven't seen the namespace
16891 before. Also, add a using directive if it's an anonymous
16894 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16898 type
= read_type_die (die
, cu
);
16899 new_symbol (die
, type
, cu
);
16901 namespace_name (die
, &is_anonymous
, cu
);
16904 const char *previous_prefix
= determine_prefix (die
, cu
);
16906 std::vector
<const char *> excludes
;
16907 add_using_directive (using_directives (cu
),
16908 previous_prefix
, type
->name (), NULL
,
16909 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16913 if (die
->child
!= NULL
)
16915 struct die_info
*child_die
= die
->child
;
16917 while (child_die
&& child_die
->tag
)
16919 process_die (child_die
, cu
);
16920 child_die
= child_die
->sibling
;
16925 /* Read a Fortran module as type. This DIE can be only a declaration used for
16926 imported module. Still we need that type as local Fortran "use ... only"
16927 declaration imports depend on the created type in determine_prefix. */
16929 static struct type
*
16930 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16932 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16933 const char *module_name
;
16936 module_name
= dwarf2_name (die
, cu
);
16937 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16939 return set_die_type (die
, type
, cu
);
16942 /* Read a Fortran module. */
16945 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16947 struct die_info
*child_die
= die
->child
;
16950 type
= read_type_die (die
, cu
);
16951 new_symbol (die
, type
, cu
);
16953 while (child_die
&& child_die
->tag
)
16955 process_die (child_die
, cu
);
16956 child_die
= child_die
->sibling
;
16960 /* Return the name of the namespace represented by DIE. Set
16961 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16964 static const char *
16965 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16967 struct die_info
*current_die
;
16968 const char *name
= NULL
;
16970 /* Loop through the extensions until we find a name. */
16972 for (current_die
= die
;
16973 current_die
!= NULL
;
16974 current_die
= dwarf2_extension (die
, &cu
))
16976 /* We don't use dwarf2_name here so that we can detect the absence
16977 of a name -> anonymous namespace. */
16978 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16984 /* Is it an anonymous namespace? */
16986 *is_anonymous
= (name
== NULL
);
16988 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16993 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16994 the user defined type vector. */
16996 static struct type
*
16997 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16999 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17000 struct comp_unit_head
*cu_header
= &cu
->header
;
17002 struct attribute
*attr_byte_size
;
17003 struct attribute
*attr_address_class
;
17004 int byte_size
, addr_class
;
17005 struct type
*target_type
;
17007 target_type
= die_type (die
, cu
);
17009 /* The die_type call above may have already set the type for this DIE. */
17010 type
= get_die_type (die
, cu
);
17014 type
= lookup_pointer_type (target_type
);
17016 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17017 if (attr_byte_size
)
17018 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17020 byte_size
= cu_header
->addr_size
;
17022 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17023 if (attr_address_class
)
17024 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17026 addr_class
= DW_ADDR_none
;
17028 ULONGEST alignment
= get_alignment (cu
, die
);
17030 /* If the pointer size, alignment, or address class is different
17031 than the default, create a type variant marked as such and set
17032 the length accordingly. */
17033 if (TYPE_LENGTH (type
) != byte_size
17034 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17035 && alignment
!= TYPE_RAW_ALIGN (type
))
17036 || addr_class
!= DW_ADDR_none
)
17038 if (gdbarch_address_class_type_flags_p (gdbarch
))
17040 type_instance_flags type_flags
17041 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17043 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17045 type
= make_type_with_address_space (type
, type_flags
);
17047 else if (TYPE_LENGTH (type
) != byte_size
)
17049 complaint (_("invalid pointer size %d"), byte_size
);
17051 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17053 complaint (_("Invalid DW_AT_alignment"
17054 " - DIE at %s [in module %s]"),
17055 sect_offset_str (die
->sect_off
),
17056 objfile_name (cu
->per_objfile
->objfile
));
17060 /* Should we also complain about unhandled address classes? */
17064 TYPE_LENGTH (type
) = byte_size
;
17065 set_type_align (type
, alignment
);
17066 return set_die_type (die
, type
, cu
);
17069 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17070 the user defined type vector. */
17072 static struct type
*
17073 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17076 struct type
*to_type
;
17077 struct type
*domain
;
17079 to_type
= die_type (die
, cu
);
17080 domain
= die_containing_type (die
, cu
);
17082 /* The calls above may have already set the type for this DIE. */
17083 type
= get_die_type (die
, cu
);
17087 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17088 type
= lookup_methodptr_type (to_type
);
17089 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17091 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17093 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17094 to_type
->fields (), to_type
->num_fields (),
17095 to_type
->has_varargs ());
17096 type
= lookup_methodptr_type (new_type
);
17099 type
= lookup_memberptr_type (to_type
, domain
);
17101 return set_die_type (die
, type
, cu
);
17104 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17105 the user defined type vector. */
17107 static struct type
*
17108 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17109 enum type_code refcode
)
17111 struct comp_unit_head
*cu_header
= &cu
->header
;
17112 struct type
*type
, *target_type
;
17113 struct attribute
*attr
;
17115 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17117 target_type
= die_type (die
, cu
);
17119 /* The die_type call above may have already set the type for this DIE. */
17120 type
= get_die_type (die
, cu
);
17124 type
= lookup_reference_type (target_type
, refcode
);
17125 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17126 if (attr
!= nullptr)
17128 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17132 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17134 maybe_set_alignment (cu
, die
, type
);
17135 return set_die_type (die
, type
, cu
);
17138 /* Add the given cv-qualifiers to the element type of the array. GCC
17139 outputs DWARF type qualifiers that apply to an array, not the
17140 element type. But GDB relies on the array element type to carry
17141 the cv-qualifiers. This mimics section 6.7.3 of the C99
17144 static struct type
*
17145 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17146 struct type
*base_type
, int cnst
, int voltl
)
17148 struct type
*el_type
, *inner_array
;
17150 base_type
= copy_type (base_type
);
17151 inner_array
= base_type
;
17153 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17155 TYPE_TARGET_TYPE (inner_array
) =
17156 copy_type (TYPE_TARGET_TYPE (inner_array
));
17157 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17160 el_type
= TYPE_TARGET_TYPE (inner_array
);
17161 cnst
|= TYPE_CONST (el_type
);
17162 voltl
|= TYPE_VOLATILE (el_type
);
17163 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17165 return set_die_type (die
, base_type
, cu
);
17168 static struct type
*
17169 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17171 struct type
*base_type
, *cv_type
;
17173 base_type
= die_type (die
, cu
);
17175 /* The die_type call above may have already set the type for this DIE. */
17176 cv_type
= get_die_type (die
, cu
);
17180 /* In case the const qualifier is applied to an array type, the element type
17181 is so qualified, not the array type (section 6.7.3 of C99). */
17182 if (base_type
->code () == TYPE_CODE_ARRAY
)
17183 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17185 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17186 return set_die_type (die
, cv_type
, cu
);
17189 static struct type
*
17190 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17192 struct type
*base_type
, *cv_type
;
17194 base_type
= die_type (die
, cu
);
17196 /* The die_type call above may have already set the type for this DIE. */
17197 cv_type
= get_die_type (die
, cu
);
17201 /* In case the volatile qualifier is applied to an array type, the
17202 element type is so qualified, not the array type (section 6.7.3
17204 if (base_type
->code () == TYPE_CODE_ARRAY
)
17205 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17207 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17208 return set_die_type (die
, cv_type
, cu
);
17211 /* Handle DW_TAG_restrict_type. */
17213 static struct type
*
17214 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17216 struct type
*base_type
, *cv_type
;
17218 base_type
= die_type (die
, cu
);
17220 /* The die_type call above may have already set the type for this DIE. */
17221 cv_type
= get_die_type (die
, cu
);
17225 cv_type
= make_restrict_type (base_type
);
17226 return set_die_type (die
, cv_type
, cu
);
17229 /* Handle DW_TAG_atomic_type. */
17231 static struct type
*
17232 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17234 struct type
*base_type
, *cv_type
;
17236 base_type
= die_type (die
, cu
);
17238 /* The die_type call above may have already set the type for this DIE. */
17239 cv_type
= get_die_type (die
, cu
);
17243 cv_type
= make_atomic_type (base_type
);
17244 return set_die_type (die
, cv_type
, cu
);
17247 /* Extract all information from a DW_TAG_string_type DIE and add to
17248 the user defined type vector. It isn't really a user defined type,
17249 but it behaves like one, with other DIE's using an AT_user_def_type
17250 attribute to reference it. */
17252 static struct type
*
17253 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17255 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17256 struct gdbarch
*gdbarch
= objfile
->arch ();
17257 struct type
*type
, *range_type
, *index_type
, *char_type
;
17258 struct attribute
*attr
;
17259 struct dynamic_prop prop
;
17260 bool length_is_constant
= true;
17263 /* There are a couple of places where bit sizes might be made use of
17264 when parsing a DW_TAG_string_type, however, no producer that we know
17265 of make use of these. Handling bit sizes that are a multiple of the
17266 byte size is easy enough, but what about other bit sizes? Lets deal
17267 with that problem when we have to. Warn about these attributes being
17268 unsupported, then parse the type and ignore them like we always
17270 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17271 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17273 static bool warning_printed
= false;
17274 if (!warning_printed
)
17276 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17277 "currently supported on DW_TAG_string_type."));
17278 warning_printed
= true;
17282 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17283 if (attr
!= nullptr && !attr
->form_is_constant ())
17285 /* The string length describes the location at which the length of
17286 the string can be found. The size of the length field can be
17287 specified with one of the attributes below. */
17288 struct type
*prop_type
;
17289 struct attribute
*len
17290 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17291 if (len
== nullptr)
17292 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17293 if (len
!= nullptr && len
->form_is_constant ())
17295 /* Pass 0 as the default as we know this attribute is constant
17296 and the default value will not be returned. */
17297 LONGEST sz
= len
->constant_value (0);
17298 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17302 /* If the size is not specified then we assume it is the size of
17303 an address on this target. */
17304 prop_type
= cu
->addr_sized_int_type (true);
17307 /* Convert the attribute into a dynamic property. */
17308 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17311 length_is_constant
= false;
17313 else if (attr
!= nullptr)
17315 /* This DW_AT_string_length just contains the length with no
17316 indirection. There's no need to create a dynamic property in this
17317 case. Pass 0 for the default value as we know it will not be
17318 returned in this case. */
17319 length
= attr
->constant_value (0);
17321 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17323 /* We don't currently support non-constant byte sizes for strings. */
17324 length
= attr
->constant_value (1);
17328 /* Use 1 as a fallback length if we have nothing else. */
17332 index_type
= objfile_type (objfile
)->builtin_int
;
17333 if (length_is_constant
)
17334 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17337 struct dynamic_prop low_bound
;
17339 low_bound
.set_const_val (1);
17340 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17342 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17343 type
= create_string_type (NULL
, char_type
, range_type
);
17345 return set_die_type (die
, type
, cu
);
17348 /* Assuming that DIE corresponds to a function, returns nonzero
17349 if the function is prototyped. */
17352 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17354 struct attribute
*attr
;
17356 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17357 if (attr
&& attr
->as_boolean ())
17360 /* The DWARF standard implies that the DW_AT_prototyped attribute
17361 is only meaningful for C, but the concept also extends to other
17362 languages that allow unprototyped functions (Eg: Objective C).
17363 For all other languages, assume that functions are always
17365 if (cu
->language
!= language_c
17366 && cu
->language
!= language_objc
17367 && cu
->language
!= language_opencl
)
17370 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17371 prototyped and unprototyped functions; default to prototyped,
17372 since that is more common in modern code (and RealView warns
17373 about unprototyped functions). */
17374 if (producer_is_realview (cu
->producer
))
17380 /* Handle DIES due to C code like:
17384 int (*funcp)(int a, long l);
17388 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17390 static struct type
*
17391 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17393 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17394 struct type
*type
; /* Type that this function returns. */
17395 struct type
*ftype
; /* Function that returns above type. */
17396 struct attribute
*attr
;
17398 type
= die_type (die
, cu
);
17400 /* The die_type call above may have already set the type for this DIE. */
17401 ftype
= get_die_type (die
, cu
);
17405 ftype
= lookup_function_type (type
);
17407 if (prototyped_function_p (die
, cu
))
17408 ftype
->set_is_prototyped (true);
17410 /* Store the calling convention in the type if it's available in
17411 the subroutine die. Otherwise set the calling convention to
17412 the default value DW_CC_normal. */
17413 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17414 if (attr
!= nullptr
17415 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17416 TYPE_CALLING_CONVENTION (ftype
)
17417 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17418 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17419 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17421 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17423 /* Record whether the function returns normally to its caller or not
17424 if the DWARF producer set that information. */
17425 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17426 if (attr
&& attr
->as_boolean ())
17427 TYPE_NO_RETURN (ftype
) = 1;
17429 /* We need to add the subroutine type to the die immediately so
17430 we don't infinitely recurse when dealing with parameters
17431 declared as the same subroutine type. */
17432 set_die_type (die
, ftype
, cu
);
17434 if (die
->child
!= NULL
)
17436 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17437 struct die_info
*child_die
;
17438 int nparams
, iparams
;
17440 /* Count the number of parameters.
17441 FIXME: GDB currently ignores vararg functions, but knows about
17442 vararg member functions. */
17444 child_die
= die
->child
;
17445 while (child_die
&& child_die
->tag
)
17447 if (child_die
->tag
== DW_TAG_formal_parameter
)
17449 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17450 ftype
->set_has_varargs (true);
17452 child_die
= child_die
->sibling
;
17455 /* Allocate storage for parameters and fill them in. */
17456 ftype
->set_num_fields (nparams
);
17458 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17460 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17461 even if we error out during the parameters reading below. */
17462 for (iparams
= 0; iparams
< nparams
; iparams
++)
17463 ftype
->field (iparams
).set_type (void_type
);
17466 child_die
= die
->child
;
17467 while (child_die
&& child_die
->tag
)
17469 if (child_die
->tag
== DW_TAG_formal_parameter
)
17471 struct type
*arg_type
;
17473 /* DWARF version 2 has no clean way to discern C++
17474 static and non-static member functions. G++ helps
17475 GDB by marking the first parameter for non-static
17476 member functions (which is the this pointer) as
17477 artificial. We pass this information to
17478 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17480 DWARF version 3 added DW_AT_object_pointer, which GCC
17481 4.5 does not yet generate. */
17482 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17483 if (attr
!= nullptr)
17484 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17486 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17487 arg_type
= die_type (child_die
, cu
);
17489 /* RealView does not mark THIS as const, which the testsuite
17490 expects. GCC marks THIS as const in method definitions,
17491 but not in the class specifications (GCC PR 43053). */
17492 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17493 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17496 struct dwarf2_cu
*arg_cu
= cu
;
17497 const char *name
= dwarf2_name (child_die
, cu
);
17499 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17500 if (attr
!= nullptr)
17502 /* If the compiler emits this, use it. */
17503 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17506 else if (name
&& strcmp (name
, "this") == 0)
17507 /* Function definitions will have the argument names. */
17509 else if (name
== NULL
&& iparams
== 0)
17510 /* Declarations may not have the names, so like
17511 elsewhere in GDB, assume an artificial first
17512 argument is "this". */
17516 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17520 ftype
->field (iparams
).set_type (arg_type
);
17523 child_die
= child_die
->sibling
;
17530 static struct type
*
17531 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17533 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17534 const char *name
= NULL
;
17535 struct type
*this_type
, *target_type
;
17537 name
= dwarf2_full_name (NULL
, die
, cu
);
17538 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17539 this_type
->set_target_is_stub (true);
17540 set_die_type (die
, this_type
, cu
);
17541 target_type
= die_type (die
, cu
);
17542 if (target_type
!= this_type
)
17543 TYPE_TARGET_TYPE (this_type
) = target_type
;
17546 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17547 spec and cause infinite loops in GDB. */
17548 complaint (_("Self-referential DW_TAG_typedef "
17549 "- DIE at %s [in module %s]"),
17550 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17551 TYPE_TARGET_TYPE (this_type
) = NULL
;
17555 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17556 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17557 Handle these by just returning the target type, rather than
17558 constructing an anonymous typedef type and trying to handle this
17560 set_die_type (die
, target_type
, cu
);
17561 return target_type
;
17566 /* Helper for get_dwarf2_rational_constant that computes the value of
17567 a given gmp_mpz given an attribute. */
17570 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17572 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17573 location expression that pushes an implicit value. */
17574 if (attr
->form
== DW_FORM_exprloc
)
17576 dwarf_block
*blk
= attr
->as_block ();
17577 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17580 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17581 blk
->data
+ blk
->size
,
17583 if (ptr
- blk
->data
+ len
<= blk
->size
)
17585 mpz_import (value
->val
, len
,
17586 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17592 /* On failure set it to 1. */
17593 *value
= gdb_mpz (1);
17595 else if (attr
->form_is_block ())
17597 dwarf_block
*blk
= attr
->as_block ();
17598 mpz_import (value
->val
, blk
->size
,
17599 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17600 1, 0, 0, blk
->data
);
17603 *value
= gdb_mpz (attr
->constant_value (1));
17606 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17607 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17609 If the numerator and/or numerator attribute is missing,
17610 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17614 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17615 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17617 struct attribute
*num_attr
, *denom_attr
;
17619 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17620 if (num_attr
== nullptr)
17621 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17622 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17624 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17625 if (denom_attr
== nullptr)
17626 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17627 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17629 if (num_attr
== nullptr || denom_attr
== nullptr)
17632 get_mpz (cu
, numerator
, num_attr
);
17633 get_mpz (cu
, denominator
, denom_attr
);
17636 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17637 rational constant, rather than a signed one.
17639 If the rational constant has a negative value, a complaint
17640 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17643 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17644 struct dwarf2_cu
*cu
,
17645 gdb_mpz
*numerator
,
17646 gdb_mpz
*denominator
)
17651 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17652 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17654 mpz_neg (num
.val
, num
.val
);
17655 mpz_neg (denom
.val
, denom
.val
);
17657 else if (mpz_sgn (num
.val
) == -1)
17659 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17661 sect_offset_str (die
->sect_off
));
17664 else if (mpz_sgn (denom
.val
) == -1)
17666 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17668 sect_offset_str (die
->sect_off
));
17672 *numerator
= std::move (num
);
17673 *denominator
= std::move (denom
);
17676 /* Assuming that ENCODING is a string whose contents starting at the
17677 K'th character is "_nn" where "nn" is a decimal number, scan that
17678 number and set RESULT to the value. K is updated to point to the
17679 character immediately following the number.
17681 If the string does not conform to the format described above, false
17682 is returned, and K may or may not be changed. */
17685 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17687 /* The next character should be an underscore ('_') followed
17689 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17692 /* Skip the underscore. */
17696 /* Determine the number of digits for our number. */
17697 while (isdigit (encoding
[k
]))
17702 std::string
copy (&encoding
[start
], k
- start
);
17703 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17709 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17710 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17711 DENOM, update OFFSET, and return true on success. Return false on
17715 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17716 gdb_mpz
*num
, gdb_mpz
*denom
)
17718 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17720 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17723 /* Assuming DIE corresponds to a fixed point type, finish the creation
17724 of the corresponding TYPE by setting its type-specific data. CU is
17725 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17726 encodings. It is nullptr if the GNAT encoding should be
17730 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17731 struct die_info
*die
, struct dwarf2_cu
*cu
)
17733 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17734 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17736 /* If GNAT encodings are preferred, don't examine the
17738 struct attribute
*attr
= nullptr;
17739 if (suffix
== nullptr)
17741 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17742 if (attr
== nullptr)
17743 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17744 if (attr
== nullptr)
17745 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17748 /* Numerator and denominator of our fixed-point type's scaling factor.
17749 The default is a scaling factor of 1, which we use as a fallback
17750 when we are not able to decode it (problem with the debugging info,
17751 unsupported forms, bug in GDB, etc...). Using that as the default
17752 allows us to at least print the unscaled value, which might still
17753 be useful to a user. */
17754 gdb_mpz
scale_num (1);
17755 gdb_mpz
scale_denom (1);
17757 if (attr
== nullptr)
17760 if (suffix
!= nullptr
17761 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17763 /* The number might be encoded as _nn_dd_nn_dd, where the
17764 second ratio is the 'small value. In this situation, we
17765 want the second value. */
17766 && (suffix
[offset
] != '_'
17767 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17774 /* Scaling factor not found. Assume a scaling factor of 1,
17775 and hope for the best. At least the user will be able to
17776 see the encoded value. */
17779 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17780 sect_offset_str (die
->sect_off
));
17783 else if (attr
->name
== DW_AT_binary_scale
)
17785 LONGEST scale_exp
= attr
->constant_value (0);
17786 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17788 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17790 else if (attr
->name
== DW_AT_decimal_scale
)
17792 LONGEST scale_exp
= attr
->constant_value (0);
17793 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17795 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17797 else if (attr
->name
== DW_AT_small
)
17799 struct die_info
*scale_die
;
17800 struct dwarf2_cu
*scale_cu
= cu
;
17802 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17803 if (scale_die
->tag
== DW_TAG_constant
)
17804 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17805 &scale_num
, &scale_denom
);
17807 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17809 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17813 complaint (_("unsupported scale attribute %s for fixed-point type"
17815 dwarf_attr_name (attr
->name
),
17816 sect_offset_str (die
->sect_off
));
17819 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17820 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17821 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17822 mpq_canonicalize (scaling_factor
.val
);
17825 /* The gnat-encoding suffix for fixed point. */
17827 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17829 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17830 "XF" suffix of the name. The text after this is what encodes the
17831 'small and 'delta information. Otherwise, return nullptr. */
17833 static const char *
17834 gnat_encoded_fixed_point_type_info (const char *name
)
17836 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17839 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17840 (which may be different from NAME) to the architecture back-end to allow
17841 it to guess the correct format if necessary. */
17843 static struct type
*
17844 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17845 const char *name_hint
, enum bfd_endian byte_order
)
17847 struct gdbarch
*gdbarch
= objfile
->arch ();
17848 const struct floatformat
**format
;
17851 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17853 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17855 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17860 /* Allocate an integer type of size BITS and name NAME. */
17862 static struct type
*
17863 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17864 int bits
, int unsigned_p
, const char *name
)
17868 /* Versions of Intel's C Compiler generate an integer type called "void"
17869 instead of using DW_TAG_unspecified_type. This has been seen on
17870 at least versions 14, 17, and 18. */
17871 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17872 && strcmp (name
, "void") == 0)
17873 type
= objfile_type (objfile
)->builtin_void
;
17875 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17880 /* Return true if DIE has a DW_AT_small attribute whose value is
17881 a constant rational, where both the numerator and denominator
17884 CU is the DIE's Compilation Unit. */
17887 has_zero_over_zero_small_attribute (struct die_info
*die
,
17888 struct dwarf2_cu
*cu
)
17890 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17891 if (attr
== nullptr)
17894 struct dwarf2_cu
*scale_cu
= cu
;
17895 struct die_info
*scale_die
17896 = follow_die_ref (die
, attr
, &scale_cu
);
17898 if (scale_die
->tag
!= DW_TAG_constant
)
17901 gdb_mpz
num (1), denom (1);
17902 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
17903 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
17906 /* Initialise and return a floating point type of size BITS suitable for
17907 use as a component of a complex number. The NAME_HINT is passed through
17908 when initialising the floating point type and is the name of the complex
17911 As DWARF doesn't currently provide an explicit name for the components
17912 of a complex number, but it can be helpful to have these components
17913 named, we try to select a suitable name based on the size of the
17915 static struct type
*
17916 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17917 struct objfile
*objfile
,
17918 int bits
, const char *name_hint
,
17919 enum bfd_endian byte_order
)
17921 gdbarch
*gdbarch
= objfile
->arch ();
17922 struct type
*tt
= nullptr;
17924 /* Try to find a suitable floating point builtin type of size BITS.
17925 We're going to use the name of this type as the name for the complex
17926 target type that we are about to create. */
17927 switch (cu
->language
)
17929 case language_fortran
:
17933 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17936 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17938 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17940 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17948 tt
= builtin_type (gdbarch
)->builtin_float
;
17951 tt
= builtin_type (gdbarch
)->builtin_double
;
17953 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17955 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17961 /* If the type we found doesn't match the size we were looking for, then
17962 pretend we didn't find a type at all, the complex target type we
17963 create will then be nameless. */
17964 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17967 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17968 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17971 /* Find a representation of a given base type and install
17972 it in the TYPE field of the die. */
17974 static struct type
*
17975 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17977 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17979 struct attribute
*attr
;
17980 int encoding
= 0, bits
= 0;
17984 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17985 if (attr
!= nullptr && attr
->form_is_constant ())
17986 encoding
= attr
->constant_value (0);
17987 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17988 if (attr
!= nullptr)
17989 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
17990 name
= dwarf2_name (die
, cu
);
17992 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17994 arch
= objfile
->arch ();
17995 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17997 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17998 if (attr
!= nullptr && attr
->form_is_constant ())
18000 int endianity
= attr
->constant_value (0);
18005 byte_order
= BFD_ENDIAN_BIG
;
18007 case DW_END_little
:
18008 byte_order
= BFD_ENDIAN_LITTLE
;
18011 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18016 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18017 && cu
->language
== language_ada
18018 && has_zero_over_zero_small_attribute (die
, cu
))
18020 /* brobecker/2018-02-24: This is a fixed point type for which
18021 the scaling factor is represented as fraction whose value
18022 does not make sense (zero divided by zero), so we should
18023 normally never see these. However, there is a small category
18024 of fixed point types for which GNAT is unable to provide
18025 the scaling factor via the standard DWARF mechanisms, and
18026 for which the info is provided via the GNAT encodings instead.
18027 This is likely what this DIE is about. */
18028 encoding
= (encoding
== DW_ATE_signed_fixed
18030 : DW_ATE_unsigned
);
18033 /* With GNAT encodings, fixed-point information will be encoded in
18034 the type name. Note that this can also occur with the above
18035 zero-over-zero case, which is why this is a separate "if" rather
18036 than an "else if". */
18037 const char *gnat_encoding_suffix
= nullptr;
18038 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18039 && cu
->language
== language_ada
18040 && name
!= nullptr)
18042 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18043 if (gnat_encoding_suffix
!= nullptr)
18045 gdb_assert (startswith (gnat_encoding_suffix
,
18046 GNAT_FIXED_POINT_SUFFIX
));
18047 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18048 name
, gnat_encoding_suffix
- name
);
18049 /* Use -1 here so that SUFFIX points at the "_" after the
18051 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18053 encoding
= (encoding
== DW_ATE_signed
18054 ? DW_ATE_signed_fixed
18055 : DW_ATE_unsigned_fixed
);
18061 case DW_ATE_address
:
18062 /* Turn DW_ATE_address into a void * pointer. */
18063 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18064 type
= init_pointer_type (objfile
, bits
, name
, type
);
18066 case DW_ATE_boolean
:
18067 type
= init_boolean_type (objfile
, bits
, 1, name
);
18069 case DW_ATE_complex_float
:
18070 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18072 if (type
->code () == TYPE_CODE_ERROR
)
18074 if (name
== nullptr)
18076 struct obstack
*obstack
18077 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18078 name
= obconcat (obstack
, "_Complex ", type
->name (),
18081 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18084 type
= init_complex_type (name
, type
);
18086 case DW_ATE_decimal_float
:
18087 type
= init_decfloat_type (objfile
, bits
, name
);
18090 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18092 case DW_ATE_signed
:
18093 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18095 case DW_ATE_unsigned
:
18096 if (cu
->language
== language_fortran
18098 && startswith (name
, "character("))
18099 type
= init_character_type (objfile
, bits
, 1, name
);
18101 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18103 case DW_ATE_signed_char
:
18104 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18105 || cu
->language
== language_pascal
18106 || cu
->language
== language_fortran
)
18107 type
= init_character_type (objfile
, bits
, 0, name
);
18109 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18111 case DW_ATE_unsigned_char
:
18112 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18113 || cu
->language
== language_pascal
18114 || cu
->language
== language_fortran
18115 || cu
->language
== language_rust
)
18116 type
= init_character_type (objfile
, bits
, 1, name
);
18118 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18123 type
= builtin_type (arch
)->builtin_char16
;
18124 else if (bits
== 32)
18125 type
= builtin_type (arch
)->builtin_char32
;
18128 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18130 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18132 return set_die_type (die
, type
, cu
);
18135 case DW_ATE_signed_fixed
:
18136 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18137 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18139 case DW_ATE_unsigned_fixed
:
18140 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18141 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18145 complaint (_("unsupported DW_AT_encoding: '%s'"),
18146 dwarf_type_encoding_name (encoding
));
18147 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18151 if (name
&& strcmp (name
, "char") == 0)
18152 type
->set_has_no_signedness (true);
18154 maybe_set_alignment (cu
, die
, type
);
18156 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18158 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18160 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18161 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18163 unsigned real_bit_size
= attr
->as_unsigned ();
18164 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18165 /* Only use the attributes if they make sense together. */
18166 if (attr
== nullptr
18167 || (attr
->as_unsigned () + real_bit_size
18168 <= 8 * TYPE_LENGTH (type
)))
18170 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18172 if (attr
!= nullptr)
18173 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18174 = attr
->as_unsigned ();
18179 return set_die_type (die
, type
, cu
);
18182 /* Parse dwarf attribute if it's a block, reference or constant and put the
18183 resulting value of the attribute into struct bound_prop.
18184 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18187 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18188 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18189 struct type
*default_type
)
18191 struct dwarf2_property_baton
*baton
;
18192 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18193 struct objfile
*objfile
= per_objfile
->objfile
;
18194 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18196 gdb_assert (default_type
!= NULL
);
18198 if (attr
== NULL
|| prop
== NULL
)
18201 if (attr
->form_is_block ())
18203 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18204 baton
->property_type
= default_type
;
18205 baton
->locexpr
.per_cu
= cu
->per_cu
;
18206 baton
->locexpr
.per_objfile
= per_objfile
;
18208 struct dwarf_block
*block
= attr
->as_block ();
18209 baton
->locexpr
.size
= block
->size
;
18210 baton
->locexpr
.data
= block
->data
;
18211 switch (attr
->name
)
18213 case DW_AT_string_length
:
18214 baton
->locexpr
.is_reference
= true;
18217 baton
->locexpr
.is_reference
= false;
18221 prop
->set_locexpr (baton
);
18222 gdb_assert (prop
->baton () != NULL
);
18224 else if (attr
->form_is_ref ())
18226 struct dwarf2_cu
*target_cu
= cu
;
18227 struct die_info
*target_die
;
18228 struct attribute
*target_attr
;
18230 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18231 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18232 if (target_attr
== NULL
)
18233 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18235 if (target_attr
== NULL
)
18238 switch (target_attr
->name
)
18240 case DW_AT_location
:
18241 if (target_attr
->form_is_section_offset ())
18243 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18244 baton
->property_type
= die_type (target_die
, target_cu
);
18245 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18246 prop
->set_loclist (baton
);
18247 gdb_assert (prop
->baton () != NULL
);
18249 else if (target_attr
->form_is_block ())
18251 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18252 baton
->property_type
= die_type (target_die
, target_cu
);
18253 baton
->locexpr
.per_cu
= cu
->per_cu
;
18254 baton
->locexpr
.per_objfile
= per_objfile
;
18255 struct dwarf_block
*block
= target_attr
->as_block ();
18256 baton
->locexpr
.size
= block
->size
;
18257 baton
->locexpr
.data
= block
->data
;
18258 baton
->locexpr
.is_reference
= true;
18259 prop
->set_locexpr (baton
);
18260 gdb_assert (prop
->baton () != NULL
);
18264 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18265 "dynamic property");
18269 case DW_AT_data_member_location
:
18273 if (!handle_data_member_location (target_die
, target_cu
,
18277 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18278 baton
->property_type
= read_type_die (target_die
->parent
,
18280 baton
->offset_info
.offset
= offset
;
18281 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18282 prop
->set_addr_offset (baton
);
18287 else if (attr
->form_is_constant ())
18288 prop
->set_const_val (attr
->constant_value (0));
18291 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18292 dwarf2_name (die
, cu
));
18302 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18304 struct type
*int_type
;
18306 /* Helper macro to examine the various builtin types. */
18307 #define TRY_TYPE(F) \
18308 int_type = (unsigned_p \
18309 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18310 : objfile_type (objfile)->builtin_ ## F); \
18311 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18318 TRY_TYPE (long_long
);
18322 gdb_assert_not_reached ("unable to find suitable integer type");
18325 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18326 present (which is valid) then compute the default type based on the
18327 compilation units address size. */
18329 static struct type
*
18330 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18332 struct type
*index_type
= die_type (die
, cu
);
18334 /* Dwarf-2 specifications explicitly allows to create subrange types
18335 without specifying a base type.
18336 In that case, the base type must be set to the type of
18337 the lower bound, upper bound or count, in that order, if any of these
18338 three attributes references an object that has a type.
18339 If no base type is found, the Dwarf-2 specifications say that
18340 a signed integer type of size equal to the size of an address should
18342 For the following C code: `extern char gdb_int [];'
18343 GCC produces an empty range DIE.
18344 FIXME: muller/2010-05-28: Possible references to object for low bound,
18345 high bound or count are not yet handled by this code. */
18346 if (index_type
->code () == TYPE_CODE_VOID
)
18347 index_type
= cu
->addr_sized_int_type (false);
18352 /* Read the given DW_AT_subrange DIE. */
18354 static struct type
*
18355 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18357 struct type
*base_type
, *orig_base_type
;
18358 struct type
*range_type
;
18359 struct attribute
*attr
;
18360 struct dynamic_prop low
, high
;
18361 int low_default_is_valid
;
18362 int high_bound_is_count
= 0;
18364 ULONGEST negative_mask
;
18366 orig_base_type
= read_subrange_index_type (die
, cu
);
18368 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18369 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18370 creating the range type, but we use the result of check_typedef
18371 when examining properties of the type. */
18372 base_type
= check_typedef (orig_base_type
);
18374 /* The die_type call above may have already set the type for this DIE. */
18375 range_type
= get_die_type (die
, cu
);
18379 high
.set_const_val (0);
18381 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18382 omitting DW_AT_lower_bound. */
18383 switch (cu
->language
)
18386 case language_cplus
:
18387 low
.set_const_val (0);
18388 low_default_is_valid
= 1;
18390 case language_fortran
:
18391 low
.set_const_val (1);
18392 low_default_is_valid
= 1;
18395 case language_objc
:
18396 case language_rust
:
18397 low
.set_const_val (0);
18398 low_default_is_valid
= (cu
->header
.version
>= 4);
18402 case language_pascal
:
18403 low
.set_const_val (1);
18404 low_default_is_valid
= (cu
->header
.version
>= 4);
18407 low
.set_const_val (0);
18408 low_default_is_valid
= 0;
18412 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18413 if (attr
!= nullptr)
18414 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18415 else if (!low_default_is_valid
)
18416 complaint (_("Missing DW_AT_lower_bound "
18417 "- DIE at %s [in module %s]"),
18418 sect_offset_str (die
->sect_off
),
18419 objfile_name (cu
->per_objfile
->objfile
));
18421 struct attribute
*attr_ub
, *attr_count
;
18422 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18423 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18425 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18426 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18428 /* If bounds are constant do the final calculation here. */
18429 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18430 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18432 high_bound_is_count
= 1;
18436 if (attr_ub
!= NULL
)
18437 complaint (_("Unresolved DW_AT_upper_bound "
18438 "- DIE at %s [in module %s]"),
18439 sect_offset_str (die
->sect_off
),
18440 objfile_name (cu
->per_objfile
->objfile
));
18441 if (attr_count
!= NULL
)
18442 complaint (_("Unresolved DW_AT_count "
18443 "- DIE at %s [in module %s]"),
18444 sect_offset_str (die
->sect_off
),
18445 objfile_name (cu
->per_objfile
->objfile
));
18450 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18451 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18452 bias
= bias_attr
->constant_value (0);
18454 /* Normally, the DWARF producers are expected to use a signed
18455 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18456 But this is unfortunately not always the case, as witnessed
18457 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18458 is used instead. To work around that ambiguity, we treat
18459 the bounds as signed, and thus sign-extend their values, when
18460 the base type is signed. */
18462 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18463 if (low
.kind () == PROP_CONST
18464 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18465 low
.set_const_val (low
.const_val () | negative_mask
);
18466 if (high
.kind () == PROP_CONST
18467 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18468 high
.set_const_val (high
.const_val () | negative_mask
);
18470 /* Check for bit and byte strides. */
18471 struct dynamic_prop byte_stride_prop
;
18472 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18473 if (attr_byte_stride
!= nullptr)
18475 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18476 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18480 struct dynamic_prop bit_stride_prop
;
18481 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18482 if (attr_bit_stride
!= nullptr)
18484 /* It only makes sense to have either a bit or byte stride. */
18485 if (attr_byte_stride
!= nullptr)
18487 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18488 "- DIE at %s [in module %s]"),
18489 sect_offset_str (die
->sect_off
),
18490 objfile_name (cu
->per_objfile
->objfile
));
18491 attr_bit_stride
= nullptr;
18495 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18496 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18501 if (attr_byte_stride
!= nullptr
18502 || attr_bit_stride
!= nullptr)
18504 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18505 struct dynamic_prop
*stride
18506 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18509 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18510 &high
, bias
, stride
, byte_stride_p
);
18513 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18515 if (high_bound_is_count
)
18516 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18518 /* Ada expects an empty array on no boundary attributes. */
18519 if (attr
== NULL
&& cu
->language
!= language_ada
)
18520 range_type
->bounds ()->high
.set_undefined ();
18522 name
= dwarf2_name (die
, cu
);
18524 range_type
->set_name (name
);
18526 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18527 if (attr
!= nullptr)
18528 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18530 maybe_set_alignment (cu
, die
, range_type
);
18532 set_die_type (die
, range_type
, cu
);
18534 /* set_die_type should be already done. */
18535 set_descriptive_type (range_type
, die
, cu
);
18540 static struct type
*
18541 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18545 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18546 type
->set_name (dwarf2_name (die
, cu
));
18548 /* In Ada, an unspecified type is typically used when the description
18549 of the type is deferred to a different unit. When encountering
18550 such a type, we treat it as a stub, and try to resolve it later on,
18552 if (cu
->language
== language_ada
)
18553 type
->set_is_stub (true);
18555 return set_die_type (die
, type
, cu
);
18558 /* Read a single die and all its descendents. Set the die's sibling
18559 field to NULL; set other fields in the die correctly, and set all
18560 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18561 location of the info_ptr after reading all of those dies. PARENT
18562 is the parent of the die in question. */
18564 static struct die_info
*
18565 read_die_and_children (const struct die_reader_specs
*reader
,
18566 const gdb_byte
*info_ptr
,
18567 const gdb_byte
**new_info_ptr
,
18568 struct die_info
*parent
)
18570 struct die_info
*die
;
18571 const gdb_byte
*cur_ptr
;
18573 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18576 *new_info_ptr
= cur_ptr
;
18579 store_in_ref_table (die
, reader
->cu
);
18581 if (die
->has_children
)
18582 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18586 *new_info_ptr
= cur_ptr
;
18589 die
->sibling
= NULL
;
18590 die
->parent
= parent
;
18594 /* Read a die, all of its descendents, and all of its siblings; set
18595 all of the fields of all of the dies correctly. Arguments are as
18596 in read_die_and_children. */
18598 static struct die_info
*
18599 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18600 const gdb_byte
*info_ptr
,
18601 const gdb_byte
**new_info_ptr
,
18602 struct die_info
*parent
)
18604 struct die_info
*first_die
, *last_sibling
;
18605 const gdb_byte
*cur_ptr
;
18607 cur_ptr
= info_ptr
;
18608 first_die
= last_sibling
= NULL
;
18612 struct die_info
*die
18613 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18617 *new_info_ptr
= cur_ptr
;
18624 last_sibling
->sibling
= die
;
18626 last_sibling
= die
;
18630 /* Read a die, all of its descendents, and all of its siblings; set
18631 all of the fields of all of the dies correctly. Arguments are as
18632 in read_die_and_children.
18633 This the main entry point for reading a DIE and all its children. */
18635 static struct die_info
*
18636 read_die_and_siblings (const struct die_reader_specs
*reader
,
18637 const gdb_byte
*info_ptr
,
18638 const gdb_byte
**new_info_ptr
,
18639 struct die_info
*parent
)
18641 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18642 new_info_ptr
, parent
);
18644 if (dwarf_die_debug
)
18646 fprintf_unfiltered (gdb_stdlog
,
18647 "Read die from %s@0x%x of %s:\n",
18648 reader
->die_section
->get_name (),
18649 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18650 bfd_get_filename (reader
->abfd
));
18651 dump_die (die
, dwarf_die_debug
);
18657 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18659 The caller is responsible for filling in the extra attributes
18660 and updating (*DIEP)->num_attrs.
18661 Set DIEP to point to a newly allocated die with its information,
18662 except for its child, sibling, and parent fields. */
18664 static const gdb_byte
*
18665 read_full_die_1 (const struct die_reader_specs
*reader
,
18666 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18667 int num_extra_attrs
)
18669 unsigned int abbrev_number
, bytes_read
, i
;
18670 const struct abbrev_info
*abbrev
;
18671 struct die_info
*die
;
18672 struct dwarf2_cu
*cu
= reader
->cu
;
18673 bfd
*abfd
= reader
->abfd
;
18675 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18676 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18677 info_ptr
+= bytes_read
;
18678 if (!abbrev_number
)
18684 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18686 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18688 bfd_get_filename (abfd
));
18690 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18691 die
->sect_off
= sect_off
;
18692 die
->tag
= abbrev
->tag
;
18693 die
->abbrev
= abbrev_number
;
18694 die
->has_children
= abbrev
->has_children
;
18696 /* Make the result usable.
18697 The caller needs to update num_attrs after adding the extra
18699 die
->num_attrs
= abbrev
->num_attrs
;
18701 bool any_need_reprocess
= false;
18702 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18704 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18706 if (die
->attrs
[i
].requires_reprocessing_p ())
18707 any_need_reprocess
= true;
18710 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18711 if (attr
!= nullptr && attr
->form_is_unsigned ())
18712 cu
->str_offsets_base
= attr
->as_unsigned ();
18714 attr
= die
->attr (DW_AT_loclists_base
);
18715 if (attr
!= nullptr)
18716 cu
->loclist_base
= attr
->as_unsigned ();
18718 auto maybe_addr_base
= die
->addr_base ();
18719 if (maybe_addr_base
.has_value ())
18720 cu
->addr_base
= *maybe_addr_base
;
18722 attr
= die
->attr (DW_AT_rnglists_base
);
18723 if (attr
!= nullptr)
18724 cu
->rnglists_base
= attr
->as_unsigned ();
18726 if (any_need_reprocess
)
18728 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18730 if (die
->attrs
[i
].requires_reprocessing_p ())
18731 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18738 /* Read a die and all its attributes.
18739 Set DIEP to point to a newly allocated die with its information,
18740 except for its child, sibling, and parent fields. */
18742 static const gdb_byte
*
18743 read_full_die (const struct die_reader_specs
*reader
,
18744 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18746 const gdb_byte
*result
;
18748 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18750 if (dwarf_die_debug
)
18752 fprintf_unfiltered (gdb_stdlog
,
18753 "Read die from %s@0x%x of %s:\n",
18754 reader
->die_section
->get_name (),
18755 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18756 bfd_get_filename (reader
->abfd
));
18757 dump_die (*diep
, dwarf_die_debug
);
18764 /* Returns nonzero if TAG represents a type that we might generate a partial
18768 is_type_tag_for_partial (int tag
, enum language lang
)
18773 /* Some types that would be reasonable to generate partial symbols for,
18774 that we don't at present. Note that normally this does not
18775 matter, mainly because C compilers don't give names to these
18776 types, but instead emit DW_TAG_typedef. */
18777 case DW_TAG_file_type
:
18778 case DW_TAG_ptr_to_member_type
:
18779 case DW_TAG_set_type
:
18780 case DW_TAG_string_type
:
18781 case DW_TAG_subroutine_type
:
18784 /* GNAT may emit an array with a name, but no typedef, so we
18785 need to make a symbol in this case. */
18786 case DW_TAG_array_type
:
18787 return lang
== language_ada
;
18789 case DW_TAG_base_type
:
18790 case DW_TAG_class_type
:
18791 case DW_TAG_interface_type
:
18792 case DW_TAG_enumeration_type
:
18793 case DW_TAG_structure_type
:
18794 case DW_TAG_subrange_type
:
18795 case DW_TAG_typedef
:
18796 case DW_TAG_union_type
:
18803 /* Load all DIEs that are interesting for partial symbols into memory. */
18805 static struct partial_die_info
*
18806 load_partial_dies (const struct die_reader_specs
*reader
,
18807 const gdb_byte
*info_ptr
, int building_psymtab
)
18809 struct dwarf2_cu
*cu
= reader
->cu
;
18810 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18811 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18812 unsigned int bytes_read
;
18813 unsigned int load_all
= 0;
18814 int nesting_level
= 1;
18819 gdb_assert (cu
->per_cu
!= NULL
);
18820 if (cu
->per_cu
->load_all_dies
)
18824 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18828 &cu
->comp_unit_obstack
,
18829 hashtab_obstack_allocate
,
18830 dummy_obstack_deallocate
);
18834 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18837 /* A NULL abbrev means the end of a series of children. */
18838 if (abbrev
== NULL
)
18840 if (--nesting_level
== 0)
18843 info_ptr
+= bytes_read
;
18844 last_die
= parent_die
;
18845 parent_die
= parent_die
->die_parent
;
18849 /* Check for template arguments. We never save these; if
18850 they're seen, we just mark the parent, and go on our way. */
18851 if (parent_die
!= NULL
18852 && cu
->language
== language_cplus
18853 && (abbrev
->tag
== DW_TAG_template_type_param
18854 || abbrev
->tag
== DW_TAG_template_value_param
))
18856 parent_die
->has_template_arguments
= 1;
18860 /* We don't need a partial DIE for the template argument. */
18861 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18866 /* We only recurse into c++ subprograms looking for template arguments.
18867 Skip their other children. */
18869 && cu
->language
== language_cplus
18870 && parent_die
!= NULL
18871 && parent_die
->tag
== DW_TAG_subprogram
18872 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18874 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18878 /* Check whether this DIE is interesting enough to save. Normally
18879 we would not be interested in members here, but there may be
18880 later variables referencing them via DW_AT_specification (for
18881 static members). */
18883 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
18884 && abbrev
->tag
!= DW_TAG_constant
18885 && abbrev
->tag
!= DW_TAG_enumerator
18886 && abbrev
->tag
!= DW_TAG_subprogram
18887 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18888 && abbrev
->tag
!= DW_TAG_lexical_block
18889 && abbrev
->tag
!= DW_TAG_variable
18890 && abbrev
->tag
!= DW_TAG_namespace
18891 && abbrev
->tag
!= DW_TAG_module
18892 && abbrev
->tag
!= DW_TAG_member
18893 && abbrev
->tag
!= DW_TAG_imported_unit
18894 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18896 /* Otherwise we skip to the next sibling, if any. */
18897 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18901 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18904 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18906 /* This two-pass algorithm for processing partial symbols has a
18907 high cost in cache pressure. Thus, handle some simple cases
18908 here which cover the majority of C partial symbols. DIEs
18909 which neither have specification tags in them, nor could have
18910 specification tags elsewhere pointing at them, can simply be
18911 processed and discarded.
18913 This segment is also optional; scan_partial_symbols and
18914 add_partial_symbol will handle these DIEs if we chain
18915 them in normally. When compilers which do not emit large
18916 quantities of duplicate debug information are more common,
18917 this code can probably be removed. */
18919 /* Any complete simple types at the top level (pretty much all
18920 of them, for a language without namespaces), can be processed
18922 if (parent_die
== NULL
18923 && pdi
.has_specification
== 0
18924 && pdi
.is_declaration
== 0
18925 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18926 || pdi
.tag
== DW_TAG_base_type
18927 || pdi
.tag
== DW_TAG_array_type
18928 || pdi
.tag
== DW_TAG_subrange_type
))
18930 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18931 add_partial_symbol (&pdi
, cu
);
18933 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18937 /* The exception for DW_TAG_typedef with has_children above is
18938 a workaround of GCC PR debug/47510. In the case of this complaint
18939 type_name_or_error will error on such types later.
18941 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18942 it could not find the child DIEs referenced later, this is checked
18943 above. In correct DWARF DW_TAG_typedef should have no children. */
18945 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18946 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18947 "- DIE at %s [in module %s]"),
18948 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18950 /* If we're at the second level, and we're an enumerator, and
18951 our parent has no specification (meaning possibly lives in a
18952 namespace elsewhere), then we can add the partial symbol now
18953 instead of queueing it. */
18954 if (pdi
.tag
== DW_TAG_enumerator
18955 && parent_die
!= NULL
18956 && parent_die
->die_parent
== NULL
18957 && parent_die
->tag
== DW_TAG_enumeration_type
18958 && parent_die
->has_specification
== 0)
18960 if (pdi
.raw_name
== NULL
)
18961 complaint (_("malformed enumerator DIE ignored"));
18962 else if (building_psymtab
)
18963 add_partial_symbol (&pdi
, cu
);
18965 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18969 struct partial_die_info
*part_die
18970 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18972 /* We'll save this DIE so link it in. */
18973 part_die
->die_parent
= parent_die
;
18974 part_die
->die_sibling
= NULL
;
18975 part_die
->die_child
= NULL
;
18977 if (last_die
&& last_die
== parent_die
)
18978 last_die
->die_child
= part_die
;
18980 last_die
->die_sibling
= part_die
;
18982 last_die
= part_die
;
18984 if (first_die
== NULL
)
18985 first_die
= part_die
;
18987 /* Maybe add the DIE to the hash table. Not all DIEs that we
18988 find interesting need to be in the hash table, because we
18989 also have the parent/sibling/child chains; only those that we
18990 might refer to by offset later during partial symbol reading.
18992 For now this means things that might have be the target of a
18993 DW_AT_specification, DW_AT_abstract_origin, or
18994 DW_AT_extension. DW_AT_extension will refer only to
18995 namespaces; DW_AT_abstract_origin refers to functions (and
18996 many things under the function DIE, but we do not recurse
18997 into function DIEs during partial symbol reading) and
18998 possibly variables as well; DW_AT_specification refers to
18999 declarations. Declarations ought to have the DW_AT_declaration
19000 flag. It happens that GCC forgets to put it in sometimes, but
19001 only for functions, not for types.
19003 Adding more things than necessary to the hash table is harmless
19004 except for the performance cost. Adding too few will result in
19005 wasted time in find_partial_die, when we reread the compilation
19006 unit with load_all_dies set. */
19009 || abbrev
->tag
== DW_TAG_constant
19010 || abbrev
->tag
== DW_TAG_subprogram
19011 || abbrev
->tag
== DW_TAG_variable
19012 || abbrev
->tag
== DW_TAG_namespace
19013 || part_die
->is_declaration
)
19017 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19018 to_underlying (part_die
->sect_off
),
19023 /* For some DIEs we want to follow their children (if any). For C
19024 we have no reason to follow the children of structures; for other
19025 languages we have to, so that we can get at method physnames
19026 to infer fully qualified class names, for DW_AT_specification,
19027 and for C++ template arguments. For C++, we also look one level
19028 inside functions to find template arguments (if the name of the
19029 function does not already contain the template arguments).
19031 For Ada and Fortran, we need to scan the children of subprograms
19032 and lexical blocks as well because these languages allow the
19033 definition of nested entities that could be interesting for the
19034 debugger, such as nested subprograms for instance. */
19035 if (last_die
->has_children
19037 || last_die
->tag
== DW_TAG_namespace
19038 || last_die
->tag
== DW_TAG_module
19039 || last_die
->tag
== DW_TAG_enumeration_type
19040 || (cu
->language
== language_cplus
19041 && last_die
->tag
== DW_TAG_subprogram
19042 && (last_die
->raw_name
== NULL
19043 || strchr (last_die
->raw_name
, '<') == NULL
))
19044 || (cu
->language
!= language_c
19045 && (last_die
->tag
== DW_TAG_class_type
19046 || last_die
->tag
== DW_TAG_interface_type
19047 || last_die
->tag
== DW_TAG_structure_type
19048 || last_die
->tag
== DW_TAG_union_type
))
19049 || ((cu
->language
== language_ada
19050 || cu
->language
== language_fortran
)
19051 && (last_die
->tag
== DW_TAG_subprogram
19052 || last_die
->tag
== DW_TAG_lexical_block
))))
19055 parent_die
= last_die
;
19059 /* Otherwise we skip to the next sibling, if any. */
19060 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19062 /* Back to the top, do it again. */
19066 partial_die_info::partial_die_info (sect_offset sect_off_
,
19067 const struct abbrev_info
*abbrev
)
19068 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19072 /* See class definition. */
19075 partial_die_info::name (dwarf2_cu
*cu
)
19077 if (!canonical_name
&& raw_name
!= nullptr)
19079 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19080 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19081 canonical_name
= 1;
19087 /* Read a minimal amount of information into the minimal die structure.
19088 INFO_PTR should point just after the initial uleb128 of a DIE. */
19091 partial_die_info::read (const struct die_reader_specs
*reader
,
19092 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19094 struct dwarf2_cu
*cu
= reader
->cu
;
19095 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19097 int has_low_pc_attr
= 0;
19098 int has_high_pc_attr
= 0;
19099 int high_pc_relative
= 0;
19101 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19104 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19105 /* String and address offsets that need to do the reprocessing have
19106 already been read at this point, so there is no need to wait until
19107 the loop terminates to do the reprocessing. */
19108 if (attr
.requires_reprocessing_p ())
19109 read_attribute_reprocess (reader
, &attr
, tag
);
19110 /* Store the data if it is of an attribute we want to keep in a
19111 partial symbol table. */
19117 case DW_TAG_compile_unit
:
19118 case DW_TAG_partial_unit
:
19119 case DW_TAG_type_unit
:
19120 /* Compilation units have a DW_AT_name that is a filename, not
19121 a source language identifier. */
19122 case DW_TAG_enumeration_type
:
19123 case DW_TAG_enumerator
:
19124 /* These tags always have simple identifiers already; no need
19125 to canonicalize them. */
19126 canonical_name
= 1;
19127 raw_name
= attr
.as_string ();
19130 canonical_name
= 0;
19131 raw_name
= attr
.as_string ();
19135 case DW_AT_linkage_name
:
19136 case DW_AT_MIPS_linkage_name
:
19137 /* Note that both forms of linkage name might appear. We
19138 assume they will be the same, and we only store the last
19140 linkage_name
= attr
.as_string ();
19143 has_low_pc_attr
= 1;
19144 lowpc
= attr
.as_address ();
19146 case DW_AT_high_pc
:
19147 has_high_pc_attr
= 1;
19148 highpc
= attr
.as_address ();
19149 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19150 high_pc_relative
= 1;
19152 case DW_AT_location
:
19153 /* Support the .debug_loc offsets. */
19154 if (attr
.form_is_block ())
19156 d
.locdesc
= attr
.as_block ();
19158 else if (attr
.form_is_section_offset ())
19160 dwarf2_complex_location_expr_complaint ();
19164 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19165 "partial symbol information");
19168 case DW_AT_external
:
19169 is_external
= attr
.as_boolean ();
19171 case DW_AT_declaration
:
19172 is_declaration
= attr
.as_boolean ();
19177 case DW_AT_abstract_origin
:
19178 case DW_AT_specification
:
19179 case DW_AT_extension
:
19180 has_specification
= 1;
19181 spec_offset
= attr
.get_ref_die_offset ();
19182 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19183 || cu
->per_cu
->is_dwz
);
19185 case DW_AT_sibling
:
19186 /* Ignore absolute siblings, they might point outside of
19187 the current compile unit. */
19188 if (attr
.form
== DW_FORM_ref_addr
)
19189 complaint (_("ignoring absolute DW_AT_sibling"));
19192 const gdb_byte
*buffer
= reader
->buffer
;
19193 sect_offset off
= attr
.get_ref_die_offset ();
19194 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19196 if (sibling_ptr
< info_ptr
)
19197 complaint (_("DW_AT_sibling points backwards"));
19198 else if (sibling_ptr
> reader
->buffer_end
)
19199 reader
->die_section
->overflow_complaint ();
19201 sibling
= sibling_ptr
;
19204 case DW_AT_byte_size
:
19207 case DW_AT_const_value
:
19208 has_const_value
= 1;
19210 case DW_AT_calling_convention
:
19211 /* DWARF doesn't provide a way to identify a program's source-level
19212 entry point. DW_AT_calling_convention attributes are only meant
19213 to describe functions' calling conventions.
19215 However, because it's a necessary piece of information in
19216 Fortran, and before DWARF 4 DW_CC_program was the only
19217 piece of debugging information whose definition refers to
19218 a 'main program' at all, several compilers marked Fortran
19219 main programs with DW_CC_program --- even when those
19220 functions use the standard calling conventions.
19222 Although DWARF now specifies a way to provide this
19223 information, we support this practice for backward
19225 if (attr
.constant_value (0) == DW_CC_program
19226 && cu
->language
== language_fortran
)
19227 main_subprogram
= 1;
19231 LONGEST value
= attr
.constant_value (-1);
19232 if (value
== DW_INL_inlined
19233 || value
== DW_INL_declared_inlined
)
19234 may_be_inlined
= 1;
19239 if (tag
== DW_TAG_imported_unit
)
19241 d
.sect_off
= attr
.get_ref_die_offset ();
19242 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19243 || cu
->per_cu
->is_dwz
);
19247 case DW_AT_main_subprogram
:
19248 main_subprogram
= attr
.as_boolean ();
19253 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19254 on DWARF version). */
19255 ULONGEST ranges_offset
= attr
.as_unsigned ();
19257 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19259 if (tag
!= DW_TAG_compile_unit
)
19260 ranges_offset
+= cu
->gnu_ranges_base
;
19262 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19273 /* For Ada, if both the name and the linkage name appear, we prefer
19274 the latter. This lets "catch exception" work better, regardless
19275 of the order in which the name and linkage name were emitted.
19276 Really, though, this is just a workaround for the fact that gdb
19277 doesn't store both the name and the linkage name. */
19278 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19279 raw_name
= linkage_name
;
19281 if (high_pc_relative
)
19284 if (has_low_pc_attr
&& has_high_pc_attr
)
19286 /* When using the GNU linker, .gnu.linkonce. sections are used to
19287 eliminate duplicate copies of functions and vtables and such.
19288 The linker will arbitrarily choose one and discard the others.
19289 The AT_*_pc values for such functions refer to local labels in
19290 these sections. If the section from that file was discarded, the
19291 labels are not in the output, so the relocs get a value of 0.
19292 If this is a discarded function, mark the pc bounds as invalid,
19293 so that GDB will ignore it. */
19294 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19296 struct objfile
*objfile
= per_objfile
->objfile
;
19297 struct gdbarch
*gdbarch
= objfile
->arch ();
19299 complaint (_("DW_AT_low_pc %s is zero "
19300 "for DIE at %s [in module %s]"),
19301 paddress (gdbarch
, lowpc
),
19302 sect_offset_str (sect_off
),
19303 objfile_name (objfile
));
19305 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19306 else if (lowpc
>= highpc
)
19308 struct objfile
*objfile
= per_objfile
->objfile
;
19309 struct gdbarch
*gdbarch
= objfile
->arch ();
19311 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19312 "for DIE at %s [in module %s]"),
19313 paddress (gdbarch
, lowpc
),
19314 paddress (gdbarch
, highpc
),
19315 sect_offset_str (sect_off
),
19316 objfile_name (objfile
));
19325 /* Find a cached partial DIE at OFFSET in CU. */
19327 struct partial_die_info
*
19328 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19330 struct partial_die_info
*lookup_die
= NULL
;
19331 struct partial_die_info
part_die (sect_off
);
19333 lookup_die
= ((struct partial_die_info
*)
19334 htab_find_with_hash (partial_dies
, &part_die
,
19335 to_underlying (sect_off
)));
19340 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19341 except in the case of .debug_types DIEs which do not reference
19342 outside their CU (they do however referencing other types via
19343 DW_FORM_ref_sig8). */
19345 static const struct cu_partial_die_info
19346 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19348 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19349 struct objfile
*objfile
= per_objfile
->objfile
;
19350 struct partial_die_info
*pd
= NULL
;
19352 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19353 && cu
->header
.offset_in_cu_p (sect_off
))
19355 pd
= cu
->find_partial_die (sect_off
);
19358 /* We missed recording what we needed.
19359 Load all dies and try again. */
19363 /* TUs don't reference other CUs/TUs (except via type signatures). */
19364 if (cu
->per_cu
->is_debug_types
)
19366 error (_("Dwarf Error: Type Unit at offset %s contains"
19367 " external reference to offset %s [in module %s].\n"),
19368 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19369 bfd_get_filename (objfile
->obfd
));
19371 dwarf2_per_cu_data
*per_cu
19372 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19375 cu
= per_objfile
->get_cu (per_cu
);
19376 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19377 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19379 cu
= per_objfile
->get_cu (per_cu
);
19382 pd
= cu
->find_partial_die (sect_off
);
19385 /* If we didn't find it, and not all dies have been loaded,
19386 load them all and try again. */
19388 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19390 cu
->per_cu
->load_all_dies
= 1;
19392 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19393 THIS_CU->cu may already be in use. So we can't just free it and
19394 replace its DIEs with the ones we read in. Instead, we leave those
19395 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19396 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19398 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19400 pd
= cu
->find_partial_die (sect_off
);
19404 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19405 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19409 /* See if we can figure out if the class lives in a namespace. We do
19410 this by looking for a member function; its demangled name will
19411 contain namespace info, if there is any. */
19414 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19415 struct dwarf2_cu
*cu
)
19417 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19418 what template types look like, because the demangler
19419 frequently doesn't give the same name as the debug info. We
19420 could fix this by only using the demangled name to get the
19421 prefix (but see comment in read_structure_type). */
19423 struct partial_die_info
*real_pdi
;
19424 struct partial_die_info
*child_pdi
;
19426 /* If this DIE (this DIE's specification, if any) has a parent, then
19427 we should not do this. We'll prepend the parent's fully qualified
19428 name when we create the partial symbol. */
19430 real_pdi
= struct_pdi
;
19431 while (real_pdi
->has_specification
)
19433 auto res
= find_partial_die (real_pdi
->spec_offset
,
19434 real_pdi
->spec_is_dwz
, cu
);
19435 real_pdi
= res
.pdi
;
19439 if (real_pdi
->die_parent
!= NULL
)
19442 for (child_pdi
= struct_pdi
->die_child
;
19444 child_pdi
= child_pdi
->die_sibling
)
19446 if (child_pdi
->tag
== DW_TAG_subprogram
19447 && child_pdi
->linkage_name
!= NULL
)
19449 gdb::unique_xmalloc_ptr
<char> actual_class_name
19450 (cu
->language_defn
->class_name_from_physname
19451 (child_pdi
->linkage_name
));
19452 if (actual_class_name
!= NULL
)
19454 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19455 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19456 struct_pdi
->canonical_name
= 1;
19463 /* Return true if a DIE with TAG may have the DW_AT_const_value
19467 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19471 case DW_TAG_constant
:
19472 case DW_TAG_enumerator
:
19473 case DW_TAG_formal_parameter
:
19474 case DW_TAG_template_value_param
:
19475 case DW_TAG_variable
:
19483 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19485 /* Once we've fixed up a die, there's no point in doing so again.
19486 This also avoids a memory leak if we were to call
19487 guess_partial_die_structure_name multiple times. */
19491 /* If we found a reference attribute and the DIE has no name, try
19492 to find a name in the referred to DIE. */
19494 if (raw_name
== NULL
&& has_specification
)
19496 struct partial_die_info
*spec_die
;
19498 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19499 spec_die
= res
.pdi
;
19502 spec_die
->fixup (cu
);
19504 if (spec_die
->raw_name
)
19506 raw_name
= spec_die
->raw_name
;
19507 canonical_name
= spec_die
->canonical_name
;
19509 /* Copy DW_AT_external attribute if it is set. */
19510 if (spec_die
->is_external
)
19511 is_external
= spec_die
->is_external
;
19515 if (!has_const_value
&& has_specification
19516 && can_have_DW_AT_const_value_p (tag
))
19518 struct partial_die_info
*spec_die
;
19520 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19521 spec_die
= res
.pdi
;
19524 spec_die
->fixup (cu
);
19526 if (spec_die
->has_const_value
)
19528 /* Copy DW_AT_const_value attribute if it is set. */
19529 has_const_value
= spec_die
->has_const_value
;
19533 /* Set default names for some unnamed DIEs. */
19535 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19537 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19538 canonical_name
= 1;
19541 /* If there is no parent die to provide a namespace, and there are
19542 children, see if we can determine the namespace from their linkage
19544 if (cu
->language
== language_cplus
19545 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19546 && die_parent
== NULL
19548 && (tag
== DW_TAG_class_type
19549 || tag
== DW_TAG_structure_type
19550 || tag
== DW_TAG_union_type
))
19551 guess_partial_die_structure_name (this, cu
);
19553 /* GCC might emit a nameless struct or union that has a linkage
19554 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19555 if (raw_name
== NULL
19556 && (tag
== DW_TAG_class_type
19557 || tag
== DW_TAG_interface_type
19558 || tag
== DW_TAG_structure_type
19559 || tag
== DW_TAG_union_type
)
19560 && linkage_name
!= NULL
)
19562 gdb::unique_xmalloc_ptr
<char> demangled
19563 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19564 if (demangled
!= nullptr)
19568 /* Strip any leading namespaces/classes, keep only the base name.
19569 DW_AT_name for named DIEs does not contain the prefixes. */
19570 base
= strrchr (demangled
.get (), ':');
19571 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19574 base
= demangled
.get ();
19576 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19577 raw_name
= objfile
->intern (base
);
19578 canonical_name
= 1;
19585 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19586 contents from the given SECTION in the HEADER.
19588 HEADER_OFFSET is the offset of the header in the section. */
19590 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19591 struct dwarf2_section_info
*section
,
19592 sect_offset header_offset
)
19594 unsigned int bytes_read
;
19595 bfd
*abfd
= section
->get_bfd_owner ();
19596 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19598 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19599 info_ptr
+= bytes_read
;
19601 header
->version
= read_2_bytes (abfd
, info_ptr
);
19604 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19607 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19610 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19613 /* Return the DW_AT_loclists_base value for the CU. */
19615 lookup_loclist_base (struct dwarf2_cu
*cu
)
19617 /* For the .dwo unit, the loclist_base points to the first offset following
19618 the header. The header consists of the following entities-
19619 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19621 2. version (2 bytes)
19622 3. address size (1 byte)
19623 4. segment selector size (1 byte)
19624 5. offset entry count (4 bytes)
19625 These sizes are derived as per the DWARFv5 standard. */
19626 if (cu
->dwo_unit
!= nullptr)
19628 if (cu
->header
.initial_length_size
== 4)
19629 return LOCLIST_HEADER_SIZE32
;
19630 return LOCLIST_HEADER_SIZE64
;
19632 return cu
->loclist_base
;
19635 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19636 array of offsets in the .debug_loclists section. */
19639 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19641 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19642 struct objfile
*objfile
= per_objfile
->objfile
;
19643 bfd
*abfd
= objfile
->obfd
;
19644 ULONGEST loclist_header_size
=
19645 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19646 : LOCLIST_HEADER_SIZE64
);
19647 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19649 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19650 ULONGEST start_offset
=
19651 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19653 /* Get loclists section. */
19654 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19656 /* Read the loclists section content. */
19657 section
->read (objfile
);
19658 if (section
->buffer
== NULL
)
19659 error (_("DW_FORM_loclistx used without .debug_loclists "
19660 "section [in module %s]"), objfile_name (objfile
));
19662 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19663 so if loclist_base is smaller than the header size, we have a problem. */
19664 if (loclist_base
< loclist_header_size
)
19665 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19666 objfile_name (objfile
));
19668 /* Read the header of the loclists contribution. */
19669 struct loclists_rnglists_header header
;
19670 read_loclists_rnglists_header (&header
, section
,
19671 (sect_offset
) (loclist_base
- loclist_header_size
));
19673 /* Verify the loclist index is valid. */
19674 if (loclist_index
>= header
.offset_entry_count
)
19675 error (_("DW_FORM_loclistx pointing outside of "
19676 ".debug_loclists offset array [in module %s]"),
19677 objfile_name (objfile
));
19679 /* Validate that reading won't go beyond the end of the section. */
19680 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19681 error (_("Reading DW_FORM_loclistx index beyond end of"
19682 ".debug_loclists section [in module %s]"),
19683 objfile_name (objfile
));
19685 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19687 if (cu
->header
.offset_size
== 4)
19688 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19690 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19693 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19694 array of offsets in the .debug_rnglists section. */
19697 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19700 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19701 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19702 bfd
*abfd
= objfile
->obfd
;
19703 ULONGEST rnglist_header_size
=
19704 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19705 : RNGLIST_HEADER_SIZE64
);
19707 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19708 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19710 ULONGEST rnglist_base
=
19711 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19713 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19714 ULONGEST start_offset
=
19715 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19717 /* Get rnglists section. */
19718 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19720 /* Read the rnglists section content. */
19721 section
->read (objfile
);
19722 if (section
->buffer
== nullptr)
19723 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19725 objfile_name (objfile
));
19727 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19728 so if rnglist_base is smaller than the header size, we have a problem. */
19729 if (rnglist_base
< rnglist_header_size
)
19730 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19731 objfile_name (objfile
));
19733 /* Read the header of the rnglists contribution. */
19734 struct loclists_rnglists_header header
;
19735 read_loclists_rnglists_header (&header
, section
,
19736 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19738 /* Verify the rnglist index is valid. */
19739 if (rnglist_index
>= header
.offset_entry_count
)
19740 error (_("DW_FORM_rnglistx index pointing outside of "
19741 ".debug_rnglists offset array [in module %s]"),
19742 objfile_name (objfile
));
19744 /* Validate that reading won't go beyond the end of the section. */
19745 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19746 error (_("Reading DW_FORM_rnglistx index beyond end of"
19747 ".debug_rnglists section [in module %s]"),
19748 objfile_name (objfile
));
19750 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19752 if (cu
->header
.offset_size
== 4)
19753 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19755 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19758 /* Process the attributes that had to be skipped in the first round. These
19759 attributes are the ones that need str_offsets_base or addr_base attributes.
19760 They could not have been processed in the first round, because at the time
19761 the values of str_offsets_base or addr_base may not have been known. */
19763 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19764 struct attribute
*attr
, dwarf_tag tag
)
19766 struct dwarf2_cu
*cu
= reader
->cu
;
19767 switch (attr
->form
)
19769 case DW_FORM_addrx
:
19770 case DW_FORM_GNU_addr_index
:
19771 attr
->set_address (read_addr_index (cu
,
19772 attr
->as_unsigned_reprocess ()));
19774 case DW_FORM_loclistx
:
19776 sect_offset loclists_sect_off
19777 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19779 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19782 case DW_FORM_rnglistx
:
19784 sect_offset rnglists_sect_off
19785 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19787 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19791 case DW_FORM_strx1
:
19792 case DW_FORM_strx2
:
19793 case DW_FORM_strx3
:
19794 case DW_FORM_strx4
:
19795 case DW_FORM_GNU_str_index
:
19797 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19798 gdb_assert (!attr
->canonical_string_p ());
19799 if (reader
->dwo_file
!= NULL
)
19800 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19803 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19808 gdb_assert_not_reached (_("Unexpected DWARF form."));
19812 /* Read an attribute value described by an attribute form. */
19814 static const gdb_byte
*
19815 read_attribute_value (const struct die_reader_specs
*reader
,
19816 struct attribute
*attr
, unsigned form
,
19817 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19819 struct dwarf2_cu
*cu
= reader
->cu
;
19820 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19821 struct objfile
*objfile
= per_objfile
->objfile
;
19822 bfd
*abfd
= reader
->abfd
;
19823 struct comp_unit_head
*cu_header
= &cu
->header
;
19824 unsigned int bytes_read
;
19825 struct dwarf_block
*blk
;
19827 attr
->form
= (enum dwarf_form
) form
;
19830 case DW_FORM_ref_addr
:
19831 if (cu_header
->version
== 2)
19832 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19835 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19837 info_ptr
+= bytes_read
;
19839 case DW_FORM_GNU_ref_alt
:
19840 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19842 info_ptr
+= bytes_read
;
19846 struct gdbarch
*gdbarch
= objfile
->arch ();
19847 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19848 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19849 attr
->set_address (addr
);
19850 info_ptr
+= bytes_read
;
19853 case DW_FORM_block2
:
19854 blk
= dwarf_alloc_block (cu
);
19855 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19857 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19858 info_ptr
+= blk
->size
;
19859 attr
->set_block (blk
);
19861 case DW_FORM_block4
:
19862 blk
= dwarf_alloc_block (cu
);
19863 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19865 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19866 info_ptr
+= blk
->size
;
19867 attr
->set_block (blk
);
19869 case DW_FORM_data2
:
19870 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19873 case DW_FORM_data4
:
19874 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19877 case DW_FORM_data8
:
19878 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19881 case DW_FORM_data16
:
19882 blk
= dwarf_alloc_block (cu
);
19884 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19886 attr
->set_block (blk
);
19888 case DW_FORM_sec_offset
:
19889 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19891 info_ptr
+= bytes_read
;
19893 case DW_FORM_loclistx
:
19895 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19897 info_ptr
+= bytes_read
;
19900 case DW_FORM_string
:
19901 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19903 info_ptr
+= bytes_read
;
19906 if (!cu
->per_cu
->is_dwz
)
19908 attr
->set_string_noncanonical
19909 (read_indirect_string (per_objfile
,
19910 abfd
, info_ptr
, cu_header
,
19912 info_ptr
+= bytes_read
;
19916 case DW_FORM_line_strp
:
19917 if (!cu
->per_cu
->is_dwz
)
19919 attr
->set_string_noncanonical
19920 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19922 info_ptr
+= bytes_read
;
19926 case DW_FORM_GNU_strp_alt
:
19928 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
19929 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19932 attr
->set_string_noncanonical
19933 (dwz
->read_string (objfile
, str_offset
));
19934 info_ptr
+= bytes_read
;
19937 case DW_FORM_exprloc
:
19938 case DW_FORM_block
:
19939 blk
= dwarf_alloc_block (cu
);
19940 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19941 info_ptr
+= bytes_read
;
19942 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19943 info_ptr
+= blk
->size
;
19944 attr
->set_block (blk
);
19946 case DW_FORM_block1
:
19947 blk
= dwarf_alloc_block (cu
);
19948 blk
->size
= read_1_byte (abfd
, info_ptr
);
19950 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19951 info_ptr
+= blk
->size
;
19952 attr
->set_block (blk
);
19954 case DW_FORM_data1
:
19956 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
19959 case DW_FORM_flag_present
:
19960 attr
->set_unsigned (1);
19962 case DW_FORM_sdata
:
19963 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
19964 info_ptr
+= bytes_read
;
19966 case DW_FORM_rnglistx
:
19968 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19970 info_ptr
+= bytes_read
;
19973 case DW_FORM_udata
:
19974 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19975 info_ptr
+= bytes_read
;
19978 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19979 + read_1_byte (abfd
, info_ptr
)));
19983 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19984 + read_2_bytes (abfd
, info_ptr
)));
19988 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19989 + read_4_bytes (abfd
, info_ptr
)));
19993 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19994 + read_8_bytes (abfd
, info_ptr
)));
19997 case DW_FORM_ref_sig8
:
19998 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20001 case DW_FORM_ref_udata
:
20002 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20003 + read_unsigned_leb128 (abfd
, info_ptr
,
20005 info_ptr
+= bytes_read
;
20007 case DW_FORM_indirect
:
20008 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20009 info_ptr
+= bytes_read
;
20010 if (form
== DW_FORM_implicit_const
)
20012 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20013 info_ptr
+= bytes_read
;
20015 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20018 case DW_FORM_implicit_const
:
20019 attr
->set_signed (implicit_const
);
20021 case DW_FORM_addrx
:
20022 case DW_FORM_GNU_addr_index
:
20023 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20025 info_ptr
+= bytes_read
;
20028 case DW_FORM_strx1
:
20029 case DW_FORM_strx2
:
20030 case DW_FORM_strx3
:
20031 case DW_FORM_strx4
:
20032 case DW_FORM_GNU_str_index
:
20034 ULONGEST str_index
;
20035 if (form
== DW_FORM_strx1
)
20037 str_index
= read_1_byte (abfd
, info_ptr
);
20040 else if (form
== DW_FORM_strx2
)
20042 str_index
= read_2_bytes (abfd
, info_ptr
);
20045 else if (form
== DW_FORM_strx3
)
20047 str_index
= read_3_bytes (abfd
, info_ptr
);
20050 else if (form
== DW_FORM_strx4
)
20052 str_index
= read_4_bytes (abfd
, info_ptr
);
20057 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20058 info_ptr
+= bytes_read
;
20060 attr
->set_unsigned_reprocess (str_index
);
20064 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20065 dwarf_form_name (form
),
20066 bfd_get_filename (abfd
));
20070 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20071 attr
->form
= DW_FORM_GNU_ref_alt
;
20073 /* We have seen instances where the compiler tried to emit a byte
20074 size attribute of -1 which ended up being encoded as an unsigned
20075 0xffffffff. Although 0xffffffff is technically a valid size value,
20076 an object of this size seems pretty unlikely so we can relatively
20077 safely treat these cases as if the size attribute was invalid and
20078 treat them as zero by default. */
20079 if (attr
->name
== DW_AT_byte_size
20080 && form
== DW_FORM_data4
20081 && attr
->as_unsigned () >= 0xffffffff)
20084 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20085 hex_string (attr
->as_unsigned ()));
20086 attr
->set_unsigned (0);
20092 /* Read an attribute described by an abbreviated attribute. */
20094 static const gdb_byte
*
20095 read_attribute (const struct die_reader_specs
*reader
,
20096 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20097 const gdb_byte
*info_ptr
)
20099 attr
->name
= abbrev
->name
;
20100 attr
->string_is_canonical
= 0;
20101 attr
->requires_reprocessing
= 0;
20102 return read_attribute_value (reader
, attr
, abbrev
->form
,
20103 abbrev
->implicit_const
, info_ptr
);
20106 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20108 static const char *
20109 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20110 LONGEST str_offset
)
20112 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20113 str_offset
, "DW_FORM_strp");
20116 /* Return pointer to string at .debug_str offset as read from BUF.
20117 BUF is assumed to be in a compilation unit described by CU_HEADER.
20118 Return *BYTES_READ_PTR count of bytes read from BUF. */
20120 static const char *
20121 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20122 const gdb_byte
*buf
,
20123 const struct comp_unit_head
*cu_header
,
20124 unsigned int *bytes_read_ptr
)
20126 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20128 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20134 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20135 const struct comp_unit_head
*cu_header
,
20136 unsigned int *bytes_read_ptr
)
20138 bfd
*abfd
= objfile
->obfd
;
20139 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20141 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20144 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20145 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20146 ADDR_SIZE is the size of addresses from the CU header. */
20149 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20150 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20152 struct objfile
*objfile
= per_objfile
->objfile
;
20153 bfd
*abfd
= objfile
->obfd
;
20154 const gdb_byte
*info_ptr
;
20155 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20157 per_objfile
->per_bfd
->addr
.read (objfile
);
20158 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20159 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20160 objfile_name (objfile
));
20161 if (addr_base_or_zero
+ addr_index
* addr_size
20162 >= per_objfile
->per_bfd
->addr
.size
)
20163 error (_("DW_FORM_addr_index pointing outside of "
20164 ".debug_addr section [in module %s]"),
20165 objfile_name (objfile
));
20166 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20167 + addr_index
* addr_size
);
20168 if (addr_size
== 4)
20169 return bfd_get_32 (abfd
, info_ptr
);
20171 return bfd_get_64 (abfd
, info_ptr
);
20174 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20177 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20179 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20180 cu
->addr_base
, cu
->header
.addr_size
);
20183 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20186 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20187 unsigned int *bytes_read
)
20189 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20190 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20192 return read_addr_index (cu
, addr_index
);
20198 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20199 dwarf2_per_objfile
*per_objfile
,
20200 unsigned int addr_index
)
20202 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20203 gdb::optional
<ULONGEST
> addr_base
;
20206 /* We need addr_base and addr_size.
20207 If we don't have PER_CU->cu, we have to get it.
20208 Nasty, but the alternative is storing the needed info in PER_CU,
20209 which at this point doesn't seem justified: it's not clear how frequently
20210 it would get used and it would increase the size of every PER_CU.
20211 Entry points like dwarf2_per_cu_addr_size do a similar thing
20212 so we're not in uncharted territory here.
20213 Alas we need to be a bit more complicated as addr_base is contained
20216 We don't need to read the entire CU(/TU).
20217 We just need the header and top level die.
20219 IWBN to use the aging mechanism to let us lazily later discard the CU.
20220 For now we skip this optimization. */
20224 addr_base
= cu
->addr_base
;
20225 addr_size
= cu
->header
.addr_size
;
20229 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20230 addr_base
= reader
.cu
->addr_base
;
20231 addr_size
= reader
.cu
->header
.addr_size
;
20234 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20237 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20238 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20241 static const char *
20242 read_str_index (struct dwarf2_cu
*cu
,
20243 struct dwarf2_section_info
*str_section
,
20244 struct dwarf2_section_info
*str_offsets_section
,
20245 ULONGEST str_offsets_base
, ULONGEST str_index
)
20247 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20248 struct objfile
*objfile
= per_objfile
->objfile
;
20249 const char *objf_name
= objfile_name (objfile
);
20250 bfd
*abfd
= objfile
->obfd
;
20251 const gdb_byte
*info_ptr
;
20252 ULONGEST str_offset
;
20253 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20255 str_section
->read (objfile
);
20256 str_offsets_section
->read (objfile
);
20257 if (str_section
->buffer
== NULL
)
20258 error (_("%s used without %s section"
20259 " in CU at offset %s [in module %s]"),
20260 form_name
, str_section
->get_name (),
20261 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20262 if (str_offsets_section
->buffer
== NULL
)
20263 error (_("%s used without %s section"
20264 " in CU at offset %s [in module %s]"),
20265 form_name
, str_section
->get_name (),
20266 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20267 info_ptr
= (str_offsets_section
->buffer
20269 + str_index
* cu
->header
.offset_size
);
20270 if (cu
->header
.offset_size
== 4)
20271 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20273 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20274 if (str_offset
>= str_section
->size
)
20275 error (_("Offset from %s pointing outside of"
20276 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20277 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20278 return (const char *) (str_section
->buffer
+ str_offset
);
20281 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20283 static const char *
20284 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20286 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20287 ? reader
->cu
->header
.addr_size
: 0;
20288 return read_str_index (reader
->cu
,
20289 &reader
->dwo_file
->sections
.str
,
20290 &reader
->dwo_file
->sections
.str_offsets
,
20291 str_offsets_base
, str_index
);
20294 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20296 static const char *
20297 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20299 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20300 const char *objf_name
= objfile_name (objfile
);
20301 static const char form_name
[] = "DW_FORM_GNU_str_index";
20302 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20304 if (!cu
->str_offsets_base
.has_value ())
20305 error (_("%s used in Fission stub without %s"
20306 " in CU at offset 0x%lx [in module %s]"),
20307 form_name
, str_offsets_attr_name
,
20308 (long) cu
->header
.offset_size
, objf_name
);
20310 return read_str_index (cu
,
20311 &cu
->per_objfile
->per_bfd
->str
,
20312 &cu
->per_objfile
->per_bfd
->str_offsets
,
20313 *cu
->str_offsets_base
, str_index
);
20316 /* Return the length of an LEB128 number in BUF. */
20319 leb128_size (const gdb_byte
*buf
)
20321 const gdb_byte
*begin
= buf
;
20327 if ((byte
& 128) == 0)
20328 return buf
- begin
;
20333 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20342 cu
->language
= language_c
;
20345 case DW_LANG_C_plus_plus
:
20346 case DW_LANG_C_plus_plus_11
:
20347 case DW_LANG_C_plus_plus_14
:
20348 cu
->language
= language_cplus
;
20351 cu
->language
= language_d
;
20353 case DW_LANG_Fortran77
:
20354 case DW_LANG_Fortran90
:
20355 case DW_LANG_Fortran95
:
20356 case DW_LANG_Fortran03
:
20357 case DW_LANG_Fortran08
:
20358 cu
->language
= language_fortran
;
20361 cu
->language
= language_go
;
20363 case DW_LANG_Mips_Assembler
:
20364 cu
->language
= language_asm
;
20366 case DW_LANG_Ada83
:
20367 case DW_LANG_Ada95
:
20368 cu
->language
= language_ada
;
20370 case DW_LANG_Modula2
:
20371 cu
->language
= language_m2
;
20373 case DW_LANG_Pascal83
:
20374 cu
->language
= language_pascal
;
20377 cu
->language
= language_objc
;
20380 case DW_LANG_Rust_old
:
20381 cu
->language
= language_rust
;
20383 case DW_LANG_Cobol74
:
20384 case DW_LANG_Cobol85
:
20386 cu
->language
= language_minimal
;
20389 cu
->language_defn
= language_def (cu
->language
);
20392 /* Return the named attribute or NULL if not there. */
20394 static struct attribute
*
20395 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20400 struct attribute
*spec
= NULL
;
20402 for (i
= 0; i
< die
->num_attrs
; ++i
)
20404 if (die
->attrs
[i
].name
== name
)
20405 return &die
->attrs
[i
];
20406 if (die
->attrs
[i
].name
== DW_AT_specification
20407 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20408 spec
= &die
->attrs
[i
];
20414 die
= follow_die_ref (die
, spec
, &cu
);
20420 /* Return the string associated with a string-typed attribute, or NULL if it
20421 is either not found or is of an incorrect type. */
20423 static const char *
20424 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20426 struct attribute
*attr
;
20427 const char *str
= NULL
;
20429 attr
= dwarf2_attr (die
, name
, cu
);
20433 str
= attr
->as_string ();
20434 if (str
== nullptr)
20435 complaint (_("string type expected for attribute %s for "
20436 "DIE at %s in module %s"),
20437 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20438 objfile_name (cu
->per_objfile
->objfile
));
20444 /* Return the dwo name or NULL if not present. If present, it is in either
20445 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20446 static const char *
20447 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20449 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20450 if (dwo_name
== nullptr)
20451 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20455 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20456 and holds a non-zero value. This function should only be used for
20457 DW_FORM_flag or DW_FORM_flag_present attributes. */
20460 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20462 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20464 return attr
!= nullptr && attr
->as_boolean ();
20468 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20470 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20471 which value is non-zero. However, we have to be careful with
20472 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20473 (via dwarf2_flag_true_p) follows this attribute. So we may
20474 end up accidently finding a declaration attribute that belongs
20475 to a different DIE referenced by the specification attribute,
20476 even though the given DIE does not have a declaration attribute. */
20477 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20478 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20481 /* Return the die giving the specification for DIE, if there is
20482 one. *SPEC_CU is the CU containing DIE on input, and the CU
20483 containing the return value on output. If there is no
20484 specification, but there is an abstract origin, that is
20487 static struct die_info
*
20488 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20490 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20493 if (spec_attr
== NULL
)
20494 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20496 if (spec_attr
== NULL
)
20499 return follow_die_ref (die
, spec_attr
, spec_cu
);
20502 /* A convenience function to find the proper .debug_line section for a CU. */
20504 static struct dwarf2_section_info
*
20505 get_debug_line_section (struct dwarf2_cu
*cu
)
20507 struct dwarf2_section_info
*section
;
20508 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20510 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20512 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20513 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20514 else if (cu
->per_cu
->is_dwz
)
20516 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20518 section
= &dwz
->line
;
20521 section
= &per_objfile
->per_bfd
->line
;
20526 /* Read the statement program header starting at OFFSET in
20527 .debug_line, or .debug_line.dwo. Return a pointer
20528 to a struct line_header, allocated using xmalloc.
20529 Returns NULL if there is a problem reading the header, e.g., if it
20530 has a version we don't understand.
20532 NOTE: the strings in the include directory and file name tables of
20533 the returned object point into the dwarf line section buffer,
20534 and must not be freed. */
20536 static line_header_up
20537 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20539 struct dwarf2_section_info
*section
;
20540 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20542 section
= get_debug_line_section (cu
);
20543 section
->read (per_objfile
->objfile
);
20544 if (section
->buffer
== NULL
)
20546 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20547 complaint (_("missing .debug_line.dwo section"));
20549 complaint (_("missing .debug_line section"));
20553 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20554 per_objfile
, section
, &cu
->header
);
20557 /* Subroutine of dwarf_decode_lines to simplify it.
20558 Return the file name of the psymtab for the given file_entry.
20559 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20560 If space for the result is malloc'd, *NAME_HOLDER will be set.
20561 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20563 static const char *
20564 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20565 const dwarf2_psymtab
*pst
,
20566 const char *comp_dir
,
20567 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20569 const char *include_name
= fe
.name
;
20570 const char *include_name_to_compare
= include_name
;
20571 const char *pst_filename
;
20574 const char *dir_name
= fe
.include_dir (lh
);
20576 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20577 if (!IS_ABSOLUTE_PATH (include_name
)
20578 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20580 /* Avoid creating a duplicate psymtab for PST.
20581 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20582 Before we do the comparison, however, we need to account
20583 for DIR_NAME and COMP_DIR.
20584 First prepend dir_name (if non-NULL). If we still don't
20585 have an absolute path prepend comp_dir (if non-NULL).
20586 However, the directory we record in the include-file's
20587 psymtab does not contain COMP_DIR (to match the
20588 corresponding symtab(s)).
20593 bash$ gcc -g ./hello.c
20594 include_name = "hello.c"
20596 DW_AT_comp_dir = comp_dir = "/tmp"
20597 DW_AT_name = "./hello.c"
20601 if (dir_name
!= NULL
)
20603 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20604 include_name
, (char *) NULL
));
20605 include_name
= name_holder
->get ();
20606 include_name_to_compare
= include_name
;
20608 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20610 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20611 include_name
, (char *) NULL
));
20612 include_name_to_compare
= hold_compare
.get ();
20616 pst_filename
= pst
->filename
;
20617 gdb::unique_xmalloc_ptr
<char> copied_name
;
20618 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20620 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20621 pst_filename
, (char *) NULL
));
20622 pst_filename
= copied_name
.get ();
20625 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20629 return include_name
;
20632 /* State machine to track the state of the line number program. */
20634 class lnp_state_machine
20637 /* Initialize a machine state for the start of a line number
20639 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20640 bool record_lines_p
);
20642 file_entry
*current_file ()
20644 /* lh->file_names is 0-based, but the file name numbers in the
20645 statement program are 1-based. */
20646 return m_line_header
->file_name_at (m_file
);
20649 /* Record the line in the state machine. END_SEQUENCE is true if
20650 we're processing the end of a sequence. */
20651 void record_line (bool end_sequence
);
20653 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20654 nop-out rest of the lines in this sequence. */
20655 void check_line_address (struct dwarf2_cu
*cu
,
20656 const gdb_byte
*line_ptr
,
20657 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20659 void handle_set_discriminator (unsigned int discriminator
)
20661 m_discriminator
= discriminator
;
20662 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20665 /* Handle DW_LNE_set_address. */
20666 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20669 address
+= baseaddr
;
20670 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20673 /* Handle DW_LNS_advance_pc. */
20674 void handle_advance_pc (CORE_ADDR adjust
);
20676 /* Handle a special opcode. */
20677 void handle_special_opcode (unsigned char op_code
);
20679 /* Handle DW_LNS_advance_line. */
20680 void handle_advance_line (int line_delta
)
20682 advance_line (line_delta
);
20685 /* Handle DW_LNS_set_file. */
20686 void handle_set_file (file_name_index file
);
20688 /* Handle DW_LNS_negate_stmt. */
20689 void handle_negate_stmt ()
20691 m_is_stmt
= !m_is_stmt
;
20694 /* Handle DW_LNS_const_add_pc. */
20695 void handle_const_add_pc ();
20697 /* Handle DW_LNS_fixed_advance_pc. */
20698 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20700 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20704 /* Handle DW_LNS_copy. */
20705 void handle_copy ()
20707 record_line (false);
20708 m_discriminator
= 0;
20711 /* Handle DW_LNE_end_sequence. */
20712 void handle_end_sequence ()
20714 m_currently_recording_lines
= true;
20718 /* Advance the line by LINE_DELTA. */
20719 void advance_line (int line_delta
)
20721 m_line
+= line_delta
;
20723 if (line_delta
!= 0)
20724 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20727 struct dwarf2_cu
*m_cu
;
20729 gdbarch
*m_gdbarch
;
20731 /* True if we're recording lines.
20732 Otherwise we're building partial symtabs and are just interested in
20733 finding include files mentioned by the line number program. */
20734 bool m_record_lines_p
;
20736 /* The line number header. */
20737 line_header
*m_line_header
;
20739 /* These are part of the standard DWARF line number state machine,
20740 and initialized according to the DWARF spec. */
20742 unsigned char m_op_index
= 0;
20743 /* The line table index of the current file. */
20744 file_name_index m_file
= 1;
20745 unsigned int m_line
= 1;
20747 /* These are initialized in the constructor. */
20749 CORE_ADDR m_address
;
20751 unsigned int m_discriminator
;
20753 /* Additional bits of state we need to track. */
20755 /* The last file that we called dwarf2_start_subfile for.
20756 This is only used for TLLs. */
20757 unsigned int m_last_file
= 0;
20758 /* The last file a line number was recorded for. */
20759 struct subfile
*m_last_subfile
= NULL
;
20761 /* The address of the last line entry. */
20762 CORE_ADDR m_last_address
;
20764 /* Set to true when a previous line at the same address (using
20765 m_last_address) had m_is_stmt true. This is reset to false when a
20766 line entry at a new address (m_address different to m_last_address) is
20768 bool m_stmt_at_address
= false;
20770 /* When true, record the lines we decode. */
20771 bool m_currently_recording_lines
= false;
20773 /* The last line number that was recorded, used to coalesce
20774 consecutive entries for the same line. This can happen, for
20775 example, when discriminators are present. PR 17276. */
20776 unsigned int m_last_line
= 0;
20777 bool m_line_has_non_zero_discriminator
= false;
20781 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20783 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20784 / m_line_header
->maximum_ops_per_instruction
)
20785 * m_line_header
->minimum_instruction_length
);
20786 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20787 m_op_index
= ((m_op_index
+ adjust
)
20788 % m_line_header
->maximum_ops_per_instruction
);
20792 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20794 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20795 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20796 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20797 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20798 / m_line_header
->maximum_ops_per_instruction
)
20799 * m_line_header
->minimum_instruction_length
);
20800 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20801 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20802 % m_line_header
->maximum_ops_per_instruction
);
20804 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20805 advance_line (line_delta
);
20806 record_line (false);
20807 m_discriminator
= 0;
20811 lnp_state_machine::handle_set_file (file_name_index file
)
20815 const file_entry
*fe
= current_file ();
20817 dwarf2_debug_line_missing_file_complaint ();
20818 else if (m_record_lines_p
)
20820 const char *dir
= fe
->include_dir (m_line_header
);
20822 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20823 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20824 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20829 lnp_state_machine::handle_const_add_pc ()
20832 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20835 = (((m_op_index
+ adjust
)
20836 / m_line_header
->maximum_ops_per_instruction
)
20837 * m_line_header
->minimum_instruction_length
);
20839 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20840 m_op_index
= ((m_op_index
+ adjust
)
20841 % m_line_header
->maximum_ops_per_instruction
);
20844 /* Return non-zero if we should add LINE to the line number table.
20845 LINE is the line to add, LAST_LINE is the last line that was added,
20846 LAST_SUBFILE is the subfile for LAST_LINE.
20847 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20848 had a non-zero discriminator.
20850 We have to be careful in the presence of discriminators.
20851 E.g., for this line:
20853 for (i = 0; i < 100000; i++);
20855 clang can emit four line number entries for that one line,
20856 each with a different discriminator.
20857 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20859 However, we want gdb to coalesce all four entries into one.
20860 Otherwise the user could stepi into the middle of the line and
20861 gdb would get confused about whether the pc really was in the
20862 middle of the line.
20864 Things are further complicated by the fact that two consecutive
20865 line number entries for the same line is a heuristic used by gcc
20866 to denote the end of the prologue. So we can't just discard duplicate
20867 entries, we have to be selective about it. The heuristic we use is
20868 that we only collapse consecutive entries for the same line if at least
20869 one of those entries has a non-zero discriminator. PR 17276.
20871 Note: Addresses in the line number state machine can never go backwards
20872 within one sequence, thus this coalescing is ok. */
20875 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20876 unsigned int line
, unsigned int last_line
,
20877 int line_has_non_zero_discriminator
,
20878 struct subfile
*last_subfile
)
20880 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20882 if (line
!= last_line
)
20884 /* Same line for the same file that we've seen already.
20885 As a last check, for pr 17276, only record the line if the line
20886 has never had a non-zero discriminator. */
20887 if (!line_has_non_zero_discriminator
)
20892 /* Use the CU's builder to record line number LINE beginning at
20893 address ADDRESS in the line table of subfile SUBFILE. */
20896 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20897 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20898 struct dwarf2_cu
*cu
)
20900 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20902 if (dwarf_line_debug
)
20904 fprintf_unfiltered (gdb_stdlog
,
20905 "Recording line %u, file %s, address %s\n",
20906 line
, lbasename (subfile
->name
),
20907 paddress (gdbarch
, address
));
20911 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20914 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20915 Mark the end of a set of line number records.
20916 The arguments are the same as for dwarf_record_line_1.
20917 If SUBFILE is NULL the request is ignored. */
20920 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20921 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20923 if (subfile
== NULL
)
20926 if (dwarf_line_debug
)
20928 fprintf_unfiltered (gdb_stdlog
,
20929 "Finishing current line, file %s, address %s\n",
20930 lbasename (subfile
->name
),
20931 paddress (gdbarch
, address
));
20934 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20938 lnp_state_machine::record_line (bool end_sequence
)
20940 if (dwarf_line_debug
)
20942 fprintf_unfiltered (gdb_stdlog
,
20943 "Processing actual line %u: file %u,"
20944 " address %s, is_stmt %u, discrim %u%s\n",
20946 paddress (m_gdbarch
, m_address
),
20947 m_is_stmt
, m_discriminator
,
20948 (end_sequence
? "\t(end sequence)" : ""));
20951 file_entry
*fe
= current_file ();
20954 dwarf2_debug_line_missing_file_complaint ();
20955 /* For now we ignore lines not starting on an instruction boundary.
20956 But not when processing end_sequence for compatibility with the
20957 previous version of the code. */
20958 else if (m_op_index
== 0 || end_sequence
)
20960 fe
->included_p
= 1;
20961 if (m_record_lines_p
)
20963 /* When we switch files we insert an end maker in the first file,
20964 switch to the second file and add a new line entry. The
20965 problem is that the end marker inserted in the first file will
20966 discard any previous line entries at the same address. If the
20967 line entries in the first file are marked as is-stmt, while
20968 the new line in the second file is non-stmt, then this means
20969 the end marker will discard is-stmt lines so we can have a
20970 non-stmt line. This means that there are less addresses at
20971 which the user can insert a breakpoint.
20973 To improve this we track the last address in m_last_address,
20974 and whether we have seen an is-stmt at this address. Then
20975 when switching files, if we have seen a stmt at the current
20976 address, and we are switching to create a non-stmt line, then
20977 discard the new line. */
20979 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
20980 bool ignore_this_line
20981 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
20982 && !m_is_stmt
&& m_stmt_at_address
)
20983 || (!end_sequence
&& m_line
== 0));
20985 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
20987 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20988 m_currently_recording_lines
? m_cu
: nullptr);
20991 if (!end_sequence
&& !ignore_this_line
)
20993 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
20995 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20996 m_line_has_non_zero_discriminator
,
20999 buildsym_compunit
*builder
= m_cu
->get_builder ();
21000 dwarf_record_line_1 (m_gdbarch
,
21001 builder
->get_current_subfile (),
21002 m_line
, m_address
, is_stmt
,
21003 m_currently_recording_lines
? m_cu
: nullptr);
21005 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21006 m_last_line
= m_line
;
21011 /* Track whether we have seen any m_is_stmt true at m_address in case we
21012 have multiple line table entries all at m_address. */
21013 if (m_last_address
!= m_address
)
21015 m_stmt_at_address
= false;
21016 m_last_address
= m_address
;
21018 m_stmt_at_address
|= m_is_stmt
;
21021 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21022 line_header
*lh
, bool record_lines_p
)
21026 m_record_lines_p
= record_lines_p
;
21027 m_line_header
= lh
;
21029 m_currently_recording_lines
= true;
21031 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21032 was a line entry for it so that the backend has a chance to adjust it
21033 and also record it in case it needs it. This is currently used by MIPS
21034 code, cf. `mips_adjust_dwarf2_line'. */
21035 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21036 m_is_stmt
= lh
->default_is_stmt
;
21037 m_discriminator
= 0;
21039 m_last_address
= m_address
;
21040 m_stmt_at_address
= false;
21044 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21045 const gdb_byte
*line_ptr
,
21046 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21048 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21049 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21050 located at 0x0. In this case, additionally check that if
21051 ADDRESS < UNRELOCATED_LOWPC. */
21053 if ((address
== 0 && address
< unrelocated_lowpc
)
21054 || address
== (CORE_ADDR
) -1)
21056 /* This line table is for a function which has been
21057 GCd by the linker. Ignore it. PR gdb/12528 */
21059 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21060 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21062 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21063 line_offset
, objfile_name (objfile
));
21064 m_currently_recording_lines
= false;
21065 /* Note: m_currently_recording_lines is left as false until we see
21066 DW_LNE_end_sequence. */
21070 /* Subroutine of dwarf_decode_lines to simplify it.
21071 Process the line number information in LH.
21072 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21073 program in order to set included_p for every referenced header. */
21076 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21077 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21079 const gdb_byte
*line_ptr
, *extended_end
;
21080 const gdb_byte
*line_end
;
21081 unsigned int bytes_read
, extended_len
;
21082 unsigned char op_code
, extended_op
;
21083 CORE_ADDR baseaddr
;
21084 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21085 bfd
*abfd
= objfile
->obfd
;
21086 struct gdbarch
*gdbarch
= objfile
->arch ();
21087 /* True if we're recording line info (as opposed to building partial
21088 symtabs and just interested in finding include files mentioned by
21089 the line number program). */
21090 bool record_lines_p
= !decode_for_pst_p
;
21092 baseaddr
= objfile
->text_section_offset ();
21094 line_ptr
= lh
->statement_program_start
;
21095 line_end
= lh
->statement_program_end
;
21097 /* Read the statement sequences until there's nothing left. */
21098 while (line_ptr
< line_end
)
21100 /* The DWARF line number program state machine. Reset the state
21101 machine at the start of each sequence. */
21102 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21103 bool end_sequence
= false;
21105 if (record_lines_p
)
21107 /* Start a subfile for the current file of the state
21109 const file_entry
*fe
= state_machine
.current_file ();
21112 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21115 /* Decode the table. */
21116 while (line_ptr
< line_end
&& !end_sequence
)
21118 op_code
= read_1_byte (abfd
, line_ptr
);
21121 if (op_code
>= lh
->opcode_base
)
21123 /* Special opcode. */
21124 state_machine
.handle_special_opcode (op_code
);
21126 else switch (op_code
)
21128 case DW_LNS_extended_op
:
21129 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21131 line_ptr
+= bytes_read
;
21132 extended_end
= line_ptr
+ extended_len
;
21133 extended_op
= read_1_byte (abfd
, line_ptr
);
21135 if (DW_LNE_lo_user
<= extended_op
21136 && extended_op
<= DW_LNE_hi_user
)
21138 /* Vendor extension, ignore. */
21139 line_ptr
= extended_end
;
21142 switch (extended_op
)
21144 case DW_LNE_end_sequence
:
21145 state_machine
.handle_end_sequence ();
21146 end_sequence
= true;
21148 case DW_LNE_set_address
:
21151 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21152 line_ptr
+= bytes_read
;
21154 state_machine
.check_line_address (cu
, line_ptr
,
21155 lowpc
- baseaddr
, address
);
21156 state_machine
.handle_set_address (baseaddr
, address
);
21159 case DW_LNE_define_file
:
21161 const char *cur_file
;
21162 unsigned int mod_time
, length
;
21165 cur_file
= read_direct_string (abfd
, line_ptr
,
21167 line_ptr
+= bytes_read
;
21168 dindex
= (dir_index
)
21169 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21170 line_ptr
+= bytes_read
;
21172 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21173 line_ptr
+= bytes_read
;
21175 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21176 line_ptr
+= bytes_read
;
21177 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21180 case DW_LNE_set_discriminator
:
21182 /* The discriminator is not interesting to the
21183 debugger; just ignore it. We still need to
21184 check its value though:
21185 if there are consecutive entries for the same
21186 (non-prologue) line we want to coalesce them.
21189 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21190 line_ptr
+= bytes_read
;
21192 state_machine
.handle_set_discriminator (discr
);
21196 complaint (_("mangled .debug_line section"));
21199 /* Make sure that we parsed the extended op correctly. If e.g.
21200 we expected a different address size than the producer used,
21201 we may have read the wrong number of bytes. */
21202 if (line_ptr
!= extended_end
)
21204 complaint (_("mangled .debug_line section"));
21209 state_machine
.handle_copy ();
21211 case DW_LNS_advance_pc
:
21214 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21215 line_ptr
+= bytes_read
;
21217 state_machine
.handle_advance_pc (adjust
);
21220 case DW_LNS_advance_line
:
21223 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21224 line_ptr
+= bytes_read
;
21226 state_machine
.handle_advance_line (line_delta
);
21229 case DW_LNS_set_file
:
21231 file_name_index file
21232 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21234 line_ptr
+= bytes_read
;
21236 state_machine
.handle_set_file (file
);
21239 case DW_LNS_set_column
:
21240 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21241 line_ptr
+= bytes_read
;
21243 case DW_LNS_negate_stmt
:
21244 state_machine
.handle_negate_stmt ();
21246 case DW_LNS_set_basic_block
:
21248 /* Add to the address register of the state machine the
21249 address increment value corresponding to special opcode
21250 255. I.e., this value is scaled by the minimum
21251 instruction length since special opcode 255 would have
21252 scaled the increment. */
21253 case DW_LNS_const_add_pc
:
21254 state_machine
.handle_const_add_pc ();
21256 case DW_LNS_fixed_advance_pc
:
21258 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21261 state_machine
.handle_fixed_advance_pc (addr_adj
);
21266 /* Unknown standard opcode, ignore it. */
21269 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21271 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21272 line_ptr
+= bytes_read
;
21279 dwarf2_debug_line_missing_end_sequence_complaint ();
21281 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21282 in which case we still finish recording the last line). */
21283 state_machine
.record_line (true);
21287 /* Decode the Line Number Program (LNP) for the given line_header
21288 structure and CU. The actual information extracted and the type
21289 of structures created from the LNP depends on the value of PST.
21291 1. If PST is NULL, then this procedure uses the data from the program
21292 to create all necessary symbol tables, and their linetables.
21294 2. If PST is not NULL, this procedure reads the program to determine
21295 the list of files included by the unit represented by PST, and
21296 builds all the associated partial symbol tables.
21298 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21299 It is used for relative paths in the line table.
21300 NOTE: When processing partial symtabs (pst != NULL),
21301 comp_dir == pst->dirname.
21303 NOTE: It is important that psymtabs have the same file name (via strcmp)
21304 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21305 symtab we don't use it in the name of the psymtabs we create.
21306 E.g. expand_line_sal requires this when finding psymtabs to expand.
21307 A good testcase for this is mb-inline.exp.
21309 LOWPC is the lowest address in CU (or 0 if not known).
21311 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21312 for its PC<->lines mapping information. Otherwise only the filename
21313 table is read in. */
21316 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21317 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21318 CORE_ADDR lowpc
, int decode_mapping
)
21320 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21321 const int decode_for_pst_p
= (pst
!= NULL
);
21323 if (decode_mapping
)
21324 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21326 if (decode_for_pst_p
)
21328 /* Now that we're done scanning the Line Header Program, we can
21329 create the psymtab of each included file. */
21330 for (auto &file_entry
: lh
->file_names ())
21331 if (file_entry
.included_p
== 1)
21333 gdb::unique_xmalloc_ptr
<char> name_holder
;
21334 const char *include_name
=
21335 psymtab_include_file_name (lh
, file_entry
, pst
,
21336 comp_dir
, &name_holder
);
21337 if (include_name
!= NULL
)
21338 dwarf2_create_include_psymtab
21339 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21340 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21346 /* Make sure a symtab is created for every file, even files
21347 which contain only variables (i.e. no code with associated
21349 buildsym_compunit
*builder
= cu
->get_builder ();
21350 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21352 for (auto &fe
: lh
->file_names ())
21354 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21355 if (builder
->get_current_subfile ()->symtab
== NULL
)
21357 builder
->get_current_subfile ()->symtab
21358 = allocate_symtab (cust
,
21359 builder
->get_current_subfile ()->name
);
21361 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21366 /* Start a subfile for DWARF. FILENAME is the name of the file and
21367 DIRNAME the name of the source directory which contains FILENAME
21368 or NULL if not known.
21369 This routine tries to keep line numbers from identical absolute and
21370 relative file names in a common subfile.
21372 Using the `list' example from the GDB testsuite, which resides in
21373 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21374 of /srcdir/list0.c yields the following debugging information for list0.c:
21376 DW_AT_name: /srcdir/list0.c
21377 DW_AT_comp_dir: /compdir
21378 files.files[0].name: list0.h
21379 files.files[0].dir: /srcdir
21380 files.files[1].name: list0.c
21381 files.files[1].dir: /srcdir
21383 The line number information for list0.c has to end up in a single
21384 subfile, so that `break /srcdir/list0.c:1' works as expected.
21385 start_subfile will ensure that this happens provided that we pass the
21386 concatenation of files.files[1].dir and files.files[1].name as the
21390 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21391 const char *dirname
)
21393 gdb::unique_xmalloc_ptr
<char> copy
;
21395 /* In order not to lose the line information directory,
21396 we concatenate it to the filename when it makes sense.
21397 Note that the Dwarf3 standard says (speaking of filenames in line
21398 information): ``The directory index is ignored for file names
21399 that represent full path names''. Thus ignoring dirname in the
21400 `else' branch below isn't an issue. */
21402 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21404 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21405 filename
= copy
.get ();
21408 cu
->get_builder ()->start_subfile (filename
);
21412 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21413 struct dwarf2_cu
*cu
)
21415 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21416 struct comp_unit_head
*cu_header
= &cu
->header
;
21418 /* NOTE drow/2003-01-30: There used to be a comment and some special
21419 code here to turn a symbol with DW_AT_external and a
21420 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21421 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21422 with some versions of binutils) where shared libraries could have
21423 relocations against symbols in their debug information - the
21424 minimal symbol would have the right address, but the debug info
21425 would not. It's no longer necessary, because we will explicitly
21426 apply relocations when we read in the debug information now. */
21428 /* A DW_AT_location attribute with no contents indicates that a
21429 variable has been optimized away. */
21430 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21432 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21436 /* Handle one degenerate form of location expression specially, to
21437 preserve GDB's previous behavior when section offsets are
21438 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21439 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21441 if (attr
->form_is_block ())
21443 struct dwarf_block
*block
= attr
->as_block ();
21445 if ((block
->data
[0] == DW_OP_addr
21446 && block
->size
== 1 + cu_header
->addr_size
)
21447 || ((block
->data
[0] == DW_OP_GNU_addr_index
21448 || block
->data
[0] == DW_OP_addrx
)
21450 == 1 + leb128_size (&block
->data
[1]))))
21452 unsigned int dummy
;
21454 if (block
->data
[0] == DW_OP_addr
)
21455 SET_SYMBOL_VALUE_ADDRESS
21456 (sym
, cu
->header
.read_address (objfile
->obfd
,
21460 SET_SYMBOL_VALUE_ADDRESS
21461 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21463 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21464 fixup_symbol_section (sym
, objfile
);
21465 SET_SYMBOL_VALUE_ADDRESS
21467 SYMBOL_VALUE_ADDRESS (sym
)
21468 + objfile
->section_offsets
[sym
->section_index ()]);
21473 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21474 expression evaluator, and use LOC_COMPUTED only when necessary
21475 (i.e. when the value of a register or memory location is
21476 referenced, or a thread-local block, etc.). Then again, it might
21477 not be worthwhile. I'm assuming that it isn't unless performance
21478 or memory numbers show me otherwise. */
21480 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21482 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21483 cu
->has_loclist
= true;
21486 /* Given a pointer to a DWARF information entry, figure out if we need
21487 to make a symbol table entry for it, and if so, create a new entry
21488 and return a pointer to it.
21489 If TYPE is NULL, determine symbol type from the die, otherwise
21490 used the passed type.
21491 If SPACE is not NULL, use it to hold the new symbol. If it is
21492 NULL, allocate a new symbol on the objfile's obstack. */
21494 static struct symbol
*
21495 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21496 struct symbol
*space
)
21498 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21499 struct objfile
*objfile
= per_objfile
->objfile
;
21500 struct gdbarch
*gdbarch
= objfile
->arch ();
21501 struct symbol
*sym
= NULL
;
21503 struct attribute
*attr
= NULL
;
21504 struct attribute
*attr2
= NULL
;
21505 CORE_ADDR baseaddr
;
21506 struct pending
**list_to_add
= NULL
;
21508 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21510 baseaddr
= objfile
->text_section_offset ();
21512 name
= dwarf2_name (die
, cu
);
21515 int suppress_add
= 0;
21520 sym
= new (&objfile
->objfile_obstack
) symbol
;
21521 OBJSTAT (objfile
, n_syms
++);
21523 /* Cache this symbol's name and the name's demangled form (if any). */
21524 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21525 /* Fortran does not have mangling standard and the mangling does differ
21526 between gfortran, iFort etc. */
21527 const char *physname
21528 = (cu
->language
== language_fortran
21529 ? dwarf2_full_name (name
, die
, cu
)
21530 : dwarf2_physname (name
, die
, cu
));
21531 const char *linkagename
= dw2_linkage_name (die
, cu
);
21533 if (linkagename
== nullptr || cu
->language
== language_ada
)
21534 sym
->set_linkage_name (physname
);
21537 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21538 sym
->set_linkage_name (linkagename
);
21541 /* Default assumptions.
21542 Use the passed type or decode it from the die. */
21543 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21544 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21546 SYMBOL_TYPE (sym
) = type
;
21548 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21549 attr
= dwarf2_attr (die
,
21550 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21552 if (attr
!= nullptr)
21553 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21555 attr
= dwarf2_attr (die
,
21556 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21558 if (attr
!= nullptr && attr
->is_nonnegative ())
21560 file_name_index file_index
21561 = (file_name_index
) attr
->as_nonnegative ();
21562 struct file_entry
*fe
;
21564 if (cu
->line_header
!= NULL
)
21565 fe
= cu
->line_header
->file_name_at (file_index
);
21570 complaint (_("file index out of range"));
21572 symbol_set_symtab (sym
, fe
->symtab
);
21578 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21579 if (attr
!= nullptr)
21583 addr
= attr
->as_address ();
21584 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21585 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21586 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21589 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21590 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21591 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21592 add_symbol_to_list (sym
, cu
->list_in_scope
);
21594 case DW_TAG_subprogram
:
21595 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21597 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21598 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21599 if ((attr2
!= nullptr && attr2
->as_boolean ())
21600 || cu
->language
== language_ada
21601 || cu
->language
== language_fortran
)
21603 /* Subprograms marked external are stored as a global symbol.
21604 Ada and Fortran subprograms, whether marked external or
21605 not, are always stored as a global symbol, because we want
21606 to be able to access them globally. For instance, we want
21607 to be able to break on a nested subprogram without having
21608 to specify the context. */
21609 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21613 list_to_add
= cu
->list_in_scope
;
21616 case DW_TAG_inlined_subroutine
:
21617 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21619 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21620 SYMBOL_INLINED (sym
) = 1;
21621 list_to_add
= cu
->list_in_scope
;
21623 case DW_TAG_template_value_param
:
21625 /* Fall through. */
21626 case DW_TAG_constant
:
21627 case DW_TAG_variable
:
21628 case DW_TAG_member
:
21629 /* Compilation with minimal debug info may result in
21630 variables with missing type entries. Change the
21631 misleading `void' type to something sensible. */
21632 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21633 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21635 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21636 /* In the case of DW_TAG_member, we should only be called for
21637 static const members. */
21638 if (die
->tag
== DW_TAG_member
)
21640 /* dwarf2_add_field uses die_is_declaration,
21641 so we do the same. */
21642 gdb_assert (die_is_declaration (die
, cu
));
21645 if (attr
!= nullptr)
21647 dwarf2_const_value (attr
, sym
, cu
);
21648 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21651 if (attr2
!= nullptr && attr2
->as_boolean ())
21652 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21654 list_to_add
= cu
->list_in_scope
;
21658 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21659 if (attr
!= nullptr)
21661 var_decode_location (attr
, sym
, cu
);
21662 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21664 /* Fortran explicitly imports any global symbols to the local
21665 scope by DW_TAG_common_block. */
21666 if (cu
->language
== language_fortran
&& die
->parent
21667 && die
->parent
->tag
== DW_TAG_common_block
)
21670 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21671 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21672 && !per_objfile
->per_bfd
->has_section_at_zero
)
21674 /* When a static variable is eliminated by the linker,
21675 the corresponding debug information is not stripped
21676 out, but the variable address is set to null;
21677 do not add such variables into symbol table. */
21679 else if (attr2
!= nullptr && attr2
->as_boolean ())
21681 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21682 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21683 && per_objfile
->per_bfd
->can_copy
)
21685 /* A global static variable might be subject to
21686 copy relocation. We first check for a local
21687 minsym, though, because maybe the symbol was
21688 marked hidden, in which case this would not
21690 bound_minimal_symbol found
21691 = (lookup_minimal_symbol_linkage
21692 (sym
->linkage_name (), objfile
));
21693 if (found
.minsym
!= nullptr)
21694 sym
->maybe_copied
= 1;
21697 /* A variable with DW_AT_external is never static,
21698 but it may be block-scoped. */
21700 = ((cu
->list_in_scope
21701 == cu
->get_builder ()->get_file_symbols ())
21702 ? cu
->get_builder ()->get_global_symbols ()
21703 : cu
->list_in_scope
);
21706 list_to_add
= cu
->list_in_scope
;
21710 /* We do not know the address of this symbol.
21711 If it is an external symbol and we have type information
21712 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21713 The address of the variable will then be determined from
21714 the minimal symbol table whenever the variable is
21716 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21718 /* Fortran explicitly imports any global symbols to the local
21719 scope by DW_TAG_common_block. */
21720 if (cu
->language
== language_fortran
&& die
->parent
21721 && die
->parent
->tag
== DW_TAG_common_block
)
21723 /* SYMBOL_CLASS doesn't matter here because
21724 read_common_block is going to reset it. */
21726 list_to_add
= cu
->list_in_scope
;
21728 else if (attr2
!= nullptr && attr2
->as_boolean ()
21729 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21731 /* A variable with DW_AT_external is never static, but it
21732 may be block-scoped. */
21734 = ((cu
->list_in_scope
21735 == cu
->get_builder ()->get_file_symbols ())
21736 ? cu
->get_builder ()->get_global_symbols ()
21737 : cu
->list_in_scope
);
21739 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21741 else if (!die_is_declaration (die
, cu
))
21743 /* Use the default LOC_OPTIMIZED_OUT class. */
21744 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21746 list_to_add
= cu
->list_in_scope
;
21750 case DW_TAG_formal_parameter
:
21752 /* If we are inside a function, mark this as an argument. If
21753 not, we might be looking at an argument to an inlined function
21754 when we do not have enough information to show inlined frames;
21755 pretend it's a local variable in that case so that the user can
21757 struct context_stack
*curr
21758 = cu
->get_builder ()->get_current_context_stack ();
21759 if (curr
!= nullptr && curr
->name
!= nullptr)
21760 SYMBOL_IS_ARGUMENT (sym
) = 1;
21761 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21762 if (attr
!= nullptr)
21764 var_decode_location (attr
, sym
, cu
);
21766 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21767 if (attr
!= nullptr)
21769 dwarf2_const_value (attr
, sym
, cu
);
21772 list_to_add
= cu
->list_in_scope
;
21775 case DW_TAG_unspecified_parameters
:
21776 /* From varargs functions; gdb doesn't seem to have any
21777 interest in this information, so just ignore it for now.
21780 case DW_TAG_template_type_param
:
21782 /* Fall through. */
21783 case DW_TAG_class_type
:
21784 case DW_TAG_interface_type
:
21785 case DW_TAG_structure_type
:
21786 case DW_TAG_union_type
:
21787 case DW_TAG_set_type
:
21788 case DW_TAG_enumeration_type
:
21789 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21790 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21793 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21794 really ever be static objects: otherwise, if you try
21795 to, say, break of a class's method and you're in a file
21796 which doesn't mention that class, it won't work unless
21797 the check for all static symbols in lookup_symbol_aux
21798 saves you. See the OtherFileClass tests in
21799 gdb.c++/namespace.exp. */
21803 buildsym_compunit
*builder
= cu
->get_builder ();
21805 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21806 && cu
->language
== language_cplus
21807 ? builder
->get_global_symbols ()
21808 : cu
->list_in_scope
);
21810 /* The semantics of C++ state that "struct foo {
21811 ... }" also defines a typedef for "foo". */
21812 if (cu
->language
== language_cplus
21813 || cu
->language
== language_ada
21814 || cu
->language
== language_d
21815 || cu
->language
== language_rust
)
21817 /* The symbol's name is already allocated along
21818 with this objfile, so we don't need to
21819 duplicate it for the type. */
21820 if (SYMBOL_TYPE (sym
)->name () == 0)
21821 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21826 case DW_TAG_typedef
:
21827 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21828 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21829 list_to_add
= cu
->list_in_scope
;
21831 case DW_TAG_array_type
:
21832 case DW_TAG_base_type
:
21833 case DW_TAG_subrange_type
:
21834 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21835 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21836 list_to_add
= cu
->list_in_scope
;
21838 case DW_TAG_enumerator
:
21839 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21840 if (attr
!= nullptr)
21842 dwarf2_const_value (attr
, sym
, cu
);
21845 /* NOTE: carlton/2003-11-10: See comment above in the
21846 DW_TAG_class_type, etc. block. */
21849 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21850 && cu
->language
== language_cplus
21851 ? cu
->get_builder ()->get_global_symbols ()
21852 : cu
->list_in_scope
);
21855 case DW_TAG_imported_declaration
:
21856 case DW_TAG_namespace
:
21857 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21858 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21860 case DW_TAG_module
:
21861 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21862 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21863 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21865 case DW_TAG_common_block
:
21866 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21867 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21868 add_symbol_to_list (sym
, cu
->list_in_scope
);
21871 /* Not a tag we recognize. Hopefully we aren't processing
21872 trash data, but since we must specifically ignore things
21873 we don't recognize, there is nothing else we should do at
21875 complaint (_("unsupported tag: '%s'"),
21876 dwarf_tag_name (die
->tag
));
21882 sym
->hash_next
= objfile
->template_symbols
;
21883 objfile
->template_symbols
= sym
;
21884 list_to_add
= NULL
;
21887 if (list_to_add
!= NULL
)
21888 add_symbol_to_list (sym
, list_to_add
);
21890 /* For the benefit of old versions of GCC, check for anonymous
21891 namespaces based on the demangled name. */
21892 if (!cu
->processing_has_namespace_info
21893 && cu
->language
== language_cplus
)
21894 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21899 /* Given an attr with a DW_FORM_dataN value in host byte order,
21900 zero-extend it as appropriate for the symbol's type. The DWARF
21901 standard (v4) is not entirely clear about the meaning of using
21902 DW_FORM_dataN for a constant with a signed type, where the type is
21903 wider than the data. The conclusion of a discussion on the DWARF
21904 list was that this is unspecified. We choose to always zero-extend
21905 because that is the interpretation long in use by GCC. */
21908 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21909 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21911 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21912 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21913 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21914 LONGEST l
= attr
->constant_value (0);
21916 if (bits
< sizeof (*value
) * 8)
21918 l
&= ((LONGEST
) 1 << bits
) - 1;
21921 else if (bits
== sizeof (*value
) * 8)
21925 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21926 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21933 /* Read a constant value from an attribute. Either set *VALUE, or if
21934 the value does not fit in *VALUE, set *BYTES - either already
21935 allocated on the objfile obstack, or newly allocated on OBSTACK,
21936 or, set *BATON, if we translated the constant to a location
21940 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21941 const char *name
, struct obstack
*obstack
,
21942 struct dwarf2_cu
*cu
,
21943 LONGEST
*value
, const gdb_byte
**bytes
,
21944 struct dwarf2_locexpr_baton
**baton
)
21946 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21947 struct objfile
*objfile
= per_objfile
->objfile
;
21948 struct comp_unit_head
*cu_header
= &cu
->header
;
21949 struct dwarf_block
*blk
;
21950 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21951 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21957 switch (attr
->form
)
21960 case DW_FORM_addrx
:
21961 case DW_FORM_GNU_addr_index
:
21965 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21966 dwarf2_const_value_length_mismatch_complaint (name
,
21967 cu_header
->addr_size
,
21968 TYPE_LENGTH (type
));
21969 /* Symbols of this form are reasonably rare, so we just
21970 piggyback on the existing location code rather than writing
21971 a new implementation of symbol_computed_ops. */
21972 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21973 (*baton
)->per_objfile
= per_objfile
;
21974 (*baton
)->per_cu
= cu
->per_cu
;
21975 gdb_assert ((*baton
)->per_cu
);
21977 (*baton
)->size
= 2 + cu_header
->addr_size
;
21978 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21979 (*baton
)->data
= data
;
21981 data
[0] = DW_OP_addr
;
21982 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21983 byte_order
, attr
->as_address ());
21984 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21987 case DW_FORM_string
:
21990 case DW_FORM_GNU_str_index
:
21991 case DW_FORM_GNU_strp_alt
:
21992 /* The string is already allocated on the objfile obstack, point
21994 *bytes
= (const gdb_byte
*) attr
->as_string ();
21996 case DW_FORM_block1
:
21997 case DW_FORM_block2
:
21998 case DW_FORM_block4
:
21999 case DW_FORM_block
:
22000 case DW_FORM_exprloc
:
22001 case DW_FORM_data16
:
22002 blk
= attr
->as_block ();
22003 if (TYPE_LENGTH (type
) != blk
->size
)
22004 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22005 TYPE_LENGTH (type
));
22006 *bytes
= blk
->data
;
22009 /* The DW_AT_const_value attributes are supposed to carry the
22010 symbol's value "represented as it would be on the target
22011 architecture." By the time we get here, it's already been
22012 converted to host endianness, so we just need to sign- or
22013 zero-extend it as appropriate. */
22014 case DW_FORM_data1
:
22015 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22017 case DW_FORM_data2
:
22018 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22020 case DW_FORM_data4
:
22021 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22023 case DW_FORM_data8
:
22024 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22027 case DW_FORM_sdata
:
22028 case DW_FORM_implicit_const
:
22029 *value
= attr
->as_signed ();
22032 case DW_FORM_udata
:
22033 *value
= attr
->as_unsigned ();
22037 complaint (_("unsupported const value attribute form: '%s'"),
22038 dwarf_form_name (attr
->form
));
22045 /* Copy constant value from an attribute to a symbol. */
22048 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22049 struct dwarf2_cu
*cu
)
22051 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22053 const gdb_byte
*bytes
;
22054 struct dwarf2_locexpr_baton
*baton
;
22056 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22057 sym
->print_name (),
22058 &objfile
->objfile_obstack
, cu
,
22059 &value
, &bytes
, &baton
);
22063 SYMBOL_LOCATION_BATON (sym
) = baton
;
22064 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22066 else if (bytes
!= NULL
)
22068 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22069 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22073 SYMBOL_VALUE (sym
) = value
;
22074 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22078 /* Return the type of the die in question using its DW_AT_type attribute. */
22080 static struct type
*
22081 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22083 struct attribute
*type_attr
;
22085 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22088 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22089 /* A missing DW_AT_type represents a void type. */
22090 return objfile_type (objfile
)->builtin_void
;
22093 return lookup_die_type (die
, type_attr
, cu
);
22096 /* True iff CU's producer generates GNAT Ada auxiliary information
22097 that allows to find parallel types through that information instead
22098 of having to do expensive parallel lookups by type name. */
22101 need_gnat_info (struct dwarf2_cu
*cu
)
22103 /* Assume that the Ada compiler was GNAT, which always produces
22104 the auxiliary information. */
22105 return (cu
->language
== language_ada
);
22108 /* Return the auxiliary type of the die in question using its
22109 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22110 attribute is not present. */
22112 static struct type
*
22113 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22115 struct attribute
*type_attr
;
22117 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22121 return lookup_die_type (die
, type_attr
, cu
);
22124 /* If DIE has a descriptive_type attribute, then set the TYPE's
22125 descriptive type accordingly. */
22128 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22129 struct dwarf2_cu
*cu
)
22131 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22133 if (descriptive_type
)
22135 ALLOCATE_GNAT_AUX_TYPE (type
);
22136 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22140 /* Return the containing type of the die in question using its
22141 DW_AT_containing_type attribute. */
22143 static struct type
*
22144 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22146 struct attribute
*type_attr
;
22147 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22149 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22151 error (_("Dwarf Error: Problem turning containing type into gdb type "
22152 "[in module %s]"), objfile_name (objfile
));
22154 return lookup_die_type (die
, type_attr
, cu
);
22157 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22159 static struct type
*
22160 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22162 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22163 struct objfile
*objfile
= per_objfile
->objfile
;
22166 std::string message
22167 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22168 objfile_name (objfile
),
22169 sect_offset_str (cu
->header
.sect_off
),
22170 sect_offset_str (die
->sect_off
));
22171 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22173 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22176 /* Look up the type of DIE in CU using its type attribute ATTR.
22177 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22178 DW_AT_containing_type.
22179 If there is no type substitute an error marker. */
22181 static struct type
*
22182 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22183 struct dwarf2_cu
*cu
)
22185 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22186 struct objfile
*objfile
= per_objfile
->objfile
;
22187 struct type
*this_type
;
22189 gdb_assert (attr
->name
== DW_AT_type
22190 || attr
->name
== DW_AT_GNAT_descriptive_type
22191 || attr
->name
== DW_AT_containing_type
);
22193 /* First see if we have it cached. */
22195 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22197 struct dwarf2_per_cu_data
*per_cu
;
22198 sect_offset sect_off
= attr
->get_ref_die_offset ();
22200 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22201 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22203 else if (attr
->form_is_ref ())
22205 sect_offset sect_off
= attr
->get_ref_die_offset ();
22207 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22209 else if (attr
->form
== DW_FORM_ref_sig8
)
22211 ULONGEST signature
= attr
->as_signature ();
22213 return get_signatured_type (die
, signature
, cu
);
22217 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22218 " at %s [in module %s]"),
22219 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22220 objfile_name (objfile
));
22221 return build_error_marker_type (cu
, die
);
22224 /* If not cached we need to read it in. */
22226 if (this_type
== NULL
)
22228 struct die_info
*type_die
= NULL
;
22229 struct dwarf2_cu
*type_cu
= cu
;
22231 if (attr
->form_is_ref ())
22232 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22233 if (type_die
== NULL
)
22234 return build_error_marker_type (cu
, die
);
22235 /* If we find the type now, it's probably because the type came
22236 from an inter-CU reference and the type's CU got expanded before
22238 this_type
= read_type_die (type_die
, type_cu
);
22241 /* If we still don't have a type use an error marker. */
22243 if (this_type
== NULL
)
22244 return build_error_marker_type (cu
, die
);
22249 /* Return the type in DIE, CU.
22250 Returns NULL for invalid types.
22252 This first does a lookup in die_type_hash,
22253 and only reads the die in if necessary.
22255 NOTE: This can be called when reading in partial or full symbols. */
22257 static struct type
*
22258 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22260 struct type
*this_type
;
22262 this_type
= get_die_type (die
, cu
);
22266 return read_type_die_1 (die
, cu
);
22269 /* Read the type in DIE, CU.
22270 Returns NULL for invalid types. */
22272 static struct type
*
22273 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22275 struct type
*this_type
= NULL
;
22279 case DW_TAG_class_type
:
22280 case DW_TAG_interface_type
:
22281 case DW_TAG_structure_type
:
22282 case DW_TAG_union_type
:
22283 this_type
= read_structure_type (die
, cu
);
22285 case DW_TAG_enumeration_type
:
22286 this_type
= read_enumeration_type (die
, cu
);
22288 case DW_TAG_subprogram
:
22289 case DW_TAG_subroutine_type
:
22290 case DW_TAG_inlined_subroutine
:
22291 this_type
= read_subroutine_type (die
, cu
);
22293 case DW_TAG_array_type
:
22294 this_type
= read_array_type (die
, cu
);
22296 case DW_TAG_set_type
:
22297 this_type
= read_set_type (die
, cu
);
22299 case DW_TAG_pointer_type
:
22300 this_type
= read_tag_pointer_type (die
, cu
);
22302 case DW_TAG_ptr_to_member_type
:
22303 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22305 case DW_TAG_reference_type
:
22306 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22308 case DW_TAG_rvalue_reference_type
:
22309 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22311 case DW_TAG_const_type
:
22312 this_type
= read_tag_const_type (die
, cu
);
22314 case DW_TAG_volatile_type
:
22315 this_type
= read_tag_volatile_type (die
, cu
);
22317 case DW_TAG_restrict_type
:
22318 this_type
= read_tag_restrict_type (die
, cu
);
22320 case DW_TAG_string_type
:
22321 this_type
= read_tag_string_type (die
, cu
);
22323 case DW_TAG_typedef
:
22324 this_type
= read_typedef (die
, cu
);
22326 case DW_TAG_subrange_type
:
22327 this_type
= read_subrange_type (die
, cu
);
22329 case DW_TAG_base_type
:
22330 this_type
= read_base_type (die
, cu
);
22332 case DW_TAG_unspecified_type
:
22333 this_type
= read_unspecified_type (die
, cu
);
22335 case DW_TAG_namespace
:
22336 this_type
= read_namespace_type (die
, cu
);
22338 case DW_TAG_module
:
22339 this_type
= read_module_type (die
, cu
);
22341 case DW_TAG_atomic_type
:
22342 this_type
= read_tag_atomic_type (die
, cu
);
22345 complaint (_("unexpected tag in read_type_die: '%s'"),
22346 dwarf_tag_name (die
->tag
));
22353 /* See if we can figure out if the class lives in a namespace. We do
22354 this by looking for a member function; its demangled name will
22355 contain namespace info, if there is any.
22356 Return the computed name or NULL.
22357 Space for the result is allocated on the objfile's obstack.
22358 This is the full-die version of guess_partial_die_structure_name.
22359 In this case we know DIE has no useful parent. */
22361 static const char *
22362 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22364 struct die_info
*spec_die
;
22365 struct dwarf2_cu
*spec_cu
;
22366 struct die_info
*child
;
22367 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22370 spec_die
= die_specification (die
, &spec_cu
);
22371 if (spec_die
!= NULL
)
22377 for (child
= die
->child
;
22379 child
= child
->sibling
)
22381 if (child
->tag
== DW_TAG_subprogram
)
22383 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22385 if (linkage_name
!= NULL
)
22387 gdb::unique_xmalloc_ptr
<char> actual_name
22388 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22389 const char *name
= NULL
;
22391 if (actual_name
!= NULL
)
22393 const char *die_name
= dwarf2_name (die
, cu
);
22395 if (die_name
!= NULL
22396 && strcmp (die_name
, actual_name
.get ()) != 0)
22398 /* Strip off the class name from the full name.
22399 We want the prefix. */
22400 int die_name_len
= strlen (die_name
);
22401 int actual_name_len
= strlen (actual_name
.get ());
22402 const char *ptr
= actual_name
.get ();
22404 /* Test for '::' as a sanity check. */
22405 if (actual_name_len
> die_name_len
+ 2
22406 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22407 name
= obstack_strndup (
22408 &objfile
->per_bfd
->storage_obstack
,
22409 ptr
, actual_name_len
- die_name_len
- 2);
22420 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22421 prefix part in such case. See
22422 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22424 static const char *
22425 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22427 struct attribute
*attr
;
22430 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22431 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22434 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22437 attr
= dw2_linkage_name_attr (die
, cu
);
22438 const char *attr_name
= attr
->as_string ();
22439 if (attr
== NULL
|| attr_name
== NULL
)
22442 /* dwarf2_name had to be already called. */
22443 gdb_assert (attr
->canonical_string_p ());
22445 /* Strip the base name, keep any leading namespaces/classes. */
22446 base
= strrchr (attr_name
, ':');
22447 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22450 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22451 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22453 &base
[-1] - attr_name
);
22456 /* Return the name of the namespace/class that DIE is defined within,
22457 or "" if we can't tell. The caller should not xfree the result.
22459 For example, if we're within the method foo() in the following
22469 then determine_prefix on foo's die will return "N::C". */
22471 static const char *
22472 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22474 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22475 struct die_info
*parent
, *spec_die
;
22476 struct dwarf2_cu
*spec_cu
;
22477 struct type
*parent_type
;
22478 const char *retval
;
22480 if (cu
->language
!= language_cplus
22481 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22482 && cu
->language
!= language_rust
)
22485 retval
= anonymous_struct_prefix (die
, cu
);
22489 /* We have to be careful in the presence of DW_AT_specification.
22490 For example, with GCC 3.4, given the code
22494 // Definition of N::foo.
22498 then we'll have a tree of DIEs like this:
22500 1: DW_TAG_compile_unit
22501 2: DW_TAG_namespace // N
22502 3: DW_TAG_subprogram // declaration of N::foo
22503 4: DW_TAG_subprogram // definition of N::foo
22504 DW_AT_specification // refers to die #3
22506 Thus, when processing die #4, we have to pretend that we're in
22507 the context of its DW_AT_specification, namely the contex of die
22510 spec_die
= die_specification (die
, &spec_cu
);
22511 if (spec_die
== NULL
)
22512 parent
= die
->parent
;
22515 parent
= spec_die
->parent
;
22519 if (parent
== NULL
)
22521 else if (parent
->building_fullname
)
22524 const char *parent_name
;
22526 /* It has been seen on RealView 2.2 built binaries,
22527 DW_TAG_template_type_param types actually _defined_ as
22528 children of the parent class:
22531 template class <class Enum> Class{};
22532 Class<enum E> class_e;
22534 1: DW_TAG_class_type (Class)
22535 2: DW_TAG_enumeration_type (E)
22536 3: DW_TAG_enumerator (enum1:0)
22537 3: DW_TAG_enumerator (enum2:1)
22539 2: DW_TAG_template_type_param
22540 DW_AT_type DW_FORM_ref_udata (E)
22542 Besides being broken debug info, it can put GDB into an
22543 infinite loop. Consider:
22545 When we're building the full name for Class<E>, we'll start
22546 at Class, and go look over its template type parameters,
22547 finding E. We'll then try to build the full name of E, and
22548 reach here. We're now trying to build the full name of E,
22549 and look over the parent DIE for containing scope. In the
22550 broken case, if we followed the parent DIE of E, we'd again
22551 find Class, and once again go look at its template type
22552 arguments, etc., etc. Simply don't consider such parent die
22553 as source-level parent of this die (it can't be, the language
22554 doesn't allow it), and break the loop here. */
22555 name
= dwarf2_name (die
, cu
);
22556 parent_name
= dwarf2_name (parent
, cu
);
22557 complaint (_("template param type '%s' defined within parent '%s'"),
22558 name
? name
: "<unknown>",
22559 parent_name
? parent_name
: "<unknown>");
22563 switch (parent
->tag
)
22565 case DW_TAG_namespace
:
22566 parent_type
= read_type_die (parent
, cu
);
22567 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22568 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22569 Work around this problem here. */
22570 if (cu
->language
== language_cplus
22571 && strcmp (parent_type
->name (), "::") == 0)
22573 /* We give a name to even anonymous namespaces. */
22574 return parent_type
->name ();
22575 case DW_TAG_class_type
:
22576 case DW_TAG_interface_type
:
22577 case DW_TAG_structure_type
:
22578 case DW_TAG_union_type
:
22579 case DW_TAG_module
:
22580 parent_type
= read_type_die (parent
, cu
);
22581 if (parent_type
->name () != NULL
)
22582 return parent_type
->name ();
22584 /* An anonymous structure is only allowed non-static data
22585 members; no typedefs, no member functions, et cetera.
22586 So it does not need a prefix. */
22588 case DW_TAG_compile_unit
:
22589 case DW_TAG_partial_unit
:
22590 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22591 if (cu
->language
== language_cplus
22592 && !per_objfile
->per_bfd
->types
.empty ()
22593 && die
->child
!= NULL
22594 && (die
->tag
== DW_TAG_class_type
22595 || die
->tag
== DW_TAG_structure_type
22596 || die
->tag
== DW_TAG_union_type
))
22598 const char *name
= guess_full_die_structure_name (die
, cu
);
22603 case DW_TAG_subprogram
:
22604 /* Nested subroutines in Fortran get a prefix with the name
22605 of the parent's subroutine. */
22606 if (cu
->language
== language_fortran
)
22608 if ((die
->tag
== DW_TAG_subprogram
)
22609 && (dwarf2_name (parent
, cu
) != NULL
))
22610 return dwarf2_name (parent
, cu
);
22612 return determine_prefix (parent
, cu
);
22613 case DW_TAG_enumeration_type
:
22614 parent_type
= read_type_die (parent
, cu
);
22615 if (parent_type
->is_declared_class ())
22617 if (parent_type
->name () != NULL
)
22618 return parent_type
->name ();
22621 /* Fall through. */
22623 return determine_prefix (parent
, cu
);
22627 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22628 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22629 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22630 an obconcat, otherwise allocate storage for the result. The CU argument is
22631 used to determine the language and hence, the appropriate separator. */
22633 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22636 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22637 int physname
, struct dwarf2_cu
*cu
)
22639 const char *lead
= "";
22642 if (suffix
== NULL
|| suffix
[0] == '\0'
22643 || prefix
== NULL
|| prefix
[0] == '\0')
22645 else if (cu
->language
== language_d
)
22647 /* For D, the 'main' function could be defined in any module, but it
22648 should never be prefixed. */
22649 if (strcmp (suffix
, "D main") == 0)
22657 else if (cu
->language
== language_fortran
&& physname
)
22659 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22660 DW_AT_MIPS_linkage_name is preferred and used instead. */
22668 if (prefix
== NULL
)
22670 if (suffix
== NULL
)
22677 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22679 strcpy (retval
, lead
);
22680 strcat (retval
, prefix
);
22681 strcat (retval
, sep
);
22682 strcat (retval
, suffix
);
22687 /* We have an obstack. */
22688 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22692 /* Get name of a die, return NULL if not found. */
22694 static const char *
22695 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22696 struct objfile
*objfile
)
22698 if (name
&& cu
->language
== language_cplus
)
22700 gdb::unique_xmalloc_ptr
<char> canon_name
22701 = cp_canonicalize_string (name
);
22703 if (canon_name
!= nullptr)
22704 name
= objfile
->intern (canon_name
.get ());
22710 /* Get name of a die, return NULL if not found.
22711 Anonymous namespaces are converted to their magic string. */
22713 static const char *
22714 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22716 struct attribute
*attr
;
22717 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22719 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22720 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22721 if (attr_name
== nullptr
22722 && die
->tag
!= DW_TAG_namespace
22723 && die
->tag
!= DW_TAG_class_type
22724 && die
->tag
!= DW_TAG_interface_type
22725 && die
->tag
!= DW_TAG_structure_type
22726 && die
->tag
!= DW_TAG_union_type
)
22731 case DW_TAG_compile_unit
:
22732 case DW_TAG_partial_unit
:
22733 /* Compilation units have a DW_AT_name that is a filename, not
22734 a source language identifier. */
22735 case DW_TAG_enumeration_type
:
22736 case DW_TAG_enumerator
:
22737 /* These tags always have simple identifiers already; no need
22738 to canonicalize them. */
22741 case DW_TAG_namespace
:
22742 if (attr_name
!= nullptr)
22744 return CP_ANONYMOUS_NAMESPACE_STR
;
22746 case DW_TAG_class_type
:
22747 case DW_TAG_interface_type
:
22748 case DW_TAG_structure_type
:
22749 case DW_TAG_union_type
:
22750 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22751 structures or unions. These were of the form "._%d" in GCC 4.1,
22752 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22753 and GCC 4.4. We work around this problem by ignoring these. */
22754 if (attr_name
!= nullptr
22755 && (startswith (attr_name
, "._")
22756 || startswith (attr_name
, "<anonymous")))
22759 /* GCC might emit a nameless typedef that has a linkage name. See
22760 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22761 if (!attr
|| attr_name
== NULL
)
22763 attr
= dw2_linkage_name_attr (die
, cu
);
22764 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22765 if (attr
== NULL
|| attr_name
== NULL
)
22768 /* Avoid demangling attr_name the second time on a second
22769 call for the same DIE. */
22770 if (!attr
->canonical_string_p ())
22772 gdb::unique_xmalloc_ptr
<char> demangled
22773 (gdb_demangle (attr_name
, DMGL_TYPES
));
22774 if (demangled
== nullptr)
22777 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22778 attr_name
= attr
->as_string ();
22781 /* Strip any leading namespaces/classes, keep only the
22782 base name. DW_AT_name for named DIEs does not
22783 contain the prefixes. */
22784 const char *base
= strrchr (attr_name
, ':');
22785 if (base
&& base
> attr_name
&& base
[-1] == ':')
22796 if (!attr
->canonical_string_p ())
22797 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22799 return attr
->as_string ();
22802 /* Return the die that this die in an extension of, or NULL if there
22803 is none. *EXT_CU is the CU containing DIE on input, and the CU
22804 containing the return value on output. */
22806 static struct die_info
*
22807 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22809 struct attribute
*attr
;
22811 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22815 return follow_die_ref (die
, attr
, ext_cu
);
22819 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22823 print_spaces (indent
, f
);
22824 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22825 dwarf_tag_name (die
->tag
), die
->abbrev
,
22826 sect_offset_str (die
->sect_off
));
22828 if (die
->parent
!= NULL
)
22830 print_spaces (indent
, f
);
22831 fprintf_unfiltered (f
, " parent at offset: %s\n",
22832 sect_offset_str (die
->parent
->sect_off
));
22835 print_spaces (indent
, f
);
22836 fprintf_unfiltered (f
, " has children: %s\n",
22837 dwarf_bool_name (die
->child
!= NULL
));
22839 print_spaces (indent
, f
);
22840 fprintf_unfiltered (f
, " attributes:\n");
22842 for (i
= 0; i
< die
->num_attrs
; ++i
)
22844 print_spaces (indent
, f
);
22845 fprintf_unfiltered (f
, " %s (%s) ",
22846 dwarf_attr_name (die
->attrs
[i
].name
),
22847 dwarf_form_name (die
->attrs
[i
].form
));
22849 switch (die
->attrs
[i
].form
)
22852 case DW_FORM_addrx
:
22853 case DW_FORM_GNU_addr_index
:
22854 fprintf_unfiltered (f
, "address: ");
22855 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
22857 case DW_FORM_block2
:
22858 case DW_FORM_block4
:
22859 case DW_FORM_block
:
22860 case DW_FORM_block1
:
22861 fprintf_unfiltered (f
, "block: size %s",
22862 pulongest (die
->attrs
[i
].as_block ()->size
));
22864 case DW_FORM_exprloc
:
22865 fprintf_unfiltered (f
, "expression: size %s",
22866 pulongest (die
->attrs
[i
].as_block ()->size
));
22868 case DW_FORM_data16
:
22869 fprintf_unfiltered (f
, "constant of 16 bytes");
22871 case DW_FORM_ref_addr
:
22872 fprintf_unfiltered (f
, "ref address: ");
22873 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22875 case DW_FORM_GNU_ref_alt
:
22876 fprintf_unfiltered (f
, "alt ref address: ");
22877 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22883 case DW_FORM_ref_udata
:
22884 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22885 (long) (die
->attrs
[i
].as_unsigned ()));
22887 case DW_FORM_data1
:
22888 case DW_FORM_data2
:
22889 case DW_FORM_data4
:
22890 case DW_FORM_data8
:
22891 case DW_FORM_udata
:
22892 fprintf_unfiltered (f
, "constant: %s",
22893 pulongest (die
->attrs
[i
].as_unsigned ()));
22895 case DW_FORM_sec_offset
:
22896 fprintf_unfiltered (f
, "section offset: %s",
22897 pulongest (die
->attrs
[i
].as_unsigned ()));
22899 case DW_FORM_ref_sig8
:
22900 fprintf_unfiltered (f
, "signature: %s",
22901 hex_string (die
->attrs
[i
].as_signature ()));
22903 case DW_FORM_string
:
22905 case DW_FORM_line_strp
:
22907 case DW_FORM_GNU_str_index
:
22908 case DW_FORM_GNU_strp_alt
:
22909 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22910 die
->attrs
[i
].as_string ()
22911 ? die
->attrs
[i
].as_string () : "",
22912 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22915 if (die
->attrs
[i
].as_boolean ())
22916 fprintf_unfiltered (f
, "flag: TRUE");
22918 fprintf_unfiltered (f
, "flag: FALSE");
22920 case DW_FORM_flag_present
:
22921 fprintf_unfiltered (f
, "flag: TRUE");
22923 case DW_FORM_indirect
:
22924 /* The reader will have reduced the indirect form to
22925 the "base form" so this form should not occur. */
22926 fprintf_unfiltered (f
,
22927 "unexpected attribute form: DW_FORM_indirect");
22929 case DW_FORM_sdata
:
22930 case DW_FORM_implicit_const
:
22931 fprintf_unfiltered (f
, "constant: %s",
22932 plongest (die
->attrs
[i
].as_signed ()));
22935 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22936 die
->attrs
[i
].form
);
22939 fprintf_unfiltered (f
, "\n");
22944 dump_die_for_error (struct die_info
*die
)
22946 dump_die_shallow (gdb_stderr
, 0, die
);
22950 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22952 int indent
= level
* 4;
22954 gdb_assert (die
!= NULL
);
22956 if (level
>= max_level
)
22959 dump_die_shallow (f
, indent
, die
);
22961 if (die
->child
!= NULL
)
22963 print_spaces (indent
, f
);
22964 fprintf_unfiltered (f
, " Children:");
22965 if (level
+ 1 < max_level
)
22967 fprintf_unfiltered (f
, "\n");
22968 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22972 fprintf_unfiltered (f
,
22973 " [not printed, max nesting level reached]\n");
22977 if (die
->sibling
!= NULL
&& level
> 0)
22979 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22983 /* This is called from the pdie macro in gdbinit.in.
22984 It's not static so gcc will keep a copy callable from gdb. */
22987 dump_die (struct die_info
*die
, int max_level
)
22989 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22993 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22997 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22998 to_underlying (die
->sect_off
),
23004 /* Follow reference or signature attribute ATTR of SRC_DIE.
23005 On entry *REF_CU is the CU of SRC_DIE.
23006 On exit *REF_CU is the CU of the result. */
23008 static struct die_info
*
23009 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23010 struct dwarf2_cu
**ref_cu
)
23012 struct die_info
*die
;
23014 if (attr
->form_is_ref ())
23015 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23016 else if (attr
->form
== DW_FORM_ref_sig8
)
23017 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23020 dump_die_for_error (src_die
);
23021 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23022 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23028 /* Follow reference OFFSET.
23029 On entry *REF_CU is the CU of the source die referencing OFFSET.
23030 On exit *REF_CU is the CU of the result.
23031 Returns NULL if OFFSET is invalid. */
23033 static struct die_info
*
23034 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23035 struct dwarf2_cu
**ref_cu
)
23037 struct die_info temp_die
;
23038 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23039 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23041 gdb_assert (cu
->per_cu
!= NULL
);
23045 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23046 "source CU contains target offset: %d",
23047 sect_offset_str (cu
->per_cu
->sect_off
),
23048 sect_offset_str (sect_off
),
23049 cu
->header
.offset_in_cu_p (sect_off
));
23051 if (cu
->per_cu
->is_debug_types
)
23053 /* .debug_types CUs cannot reference anything outside their CU.
23054 If they need to, they have to reference a signatured type via
23055 DW_FORM_ref_sig8. */
23056 if (!cu
->header
.offset_in_cu_p (sect_off
))
23059 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23060 || !cu
->header
.offset_in_cu_p (sect_off
))
23062 struct dwarf2_per_cu_data
*per_cu
;
23064 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23067 dwarf_read_debug_printf_v ("target CU offset: %s, "
23068 "target CU DIEs loaded: %d",
23069 sect_offset_str (per_cu
->sect_off
),
23070 per_objfile
->get_cu (per_cu
) != nullptr);
23072 /* If necessary, add it to the queue and load its DIEs.
23074 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23075 it doesn't mean they are currently loaded. Since we require them
23076 to be loaded, we must check for ourselves. */
23077 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23078 || per_objfile
->get_cu (per_cu
) == nullptr)
23079 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23080 false, cu
->language
);
23082 target_cu
= per_objfile
->get_cu (per_cu
);
23083 gdb_assert (target_cu
!= nullptr);
23085 else if (cu
->dies
== NULL
)
23087 /* We're loading full DIEs during partial symbol reading. */
23088 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23089 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23093 *ref_cu
= target_cu
;
23094 temp_die
.sect_off
= sect_off
;
23096 if (target_cu
!= cu
)
23097 target_cu
->ancestor
= cu
;
23099 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23101 to_underlying (sect_off
));
23104 /* Follow reference attribute ATTR of SRC_DIE.
23105 On entry *REF_CU is the CU of SRC_DIE.
23106 On exit *REF_CU is the CU of the result. */
23108 static struct die_info
*
23109 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23110 struct dwarf2_cu
**ref_cu
)
23112 sect_offset sect_off
= attr
->get_ref_die_offset ();
23113 struct dwarf2_cu
*cu
= *ref_cu
;
23114 struct die_info
*die
;
23116 die
= follow_die_offset (sect_off
,
23117 (attr
->form
== DW_FORM_GNU_ref_alt
23118 || cu
->per_cu
->is_dwz
),
23121 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23122 "at %s [in module %s]"),
23123 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23124 objfile_name (cu
->per_objfile
->objfile
));
23131 struct dwarf2_locexpr_baton
23132 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23133 dwarf2_per_cu_data
*per_cu
,
23134 dwarf2_per_objfile
*per_objfile
,
23135 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23136 bool resolve_abstract_p
)
23138 struct die_info
*die
;
23139 struct attribute
*attr
;
23140 struct dwarf2_locexpr_baton retval
;
23141 struct objfile
*objfile
= per_objfile
->objfile
;
23143 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23145 cu
= load_cu (per_cu
, per_objfile
, false);
23149 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23150 Instead just throw an error, not much else we can do. */
23151 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23152 sect_offset_str (sect_off
), objfile_name (objfile
));
23155 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23157 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23158 sect_offset_str (sect_off
), objfile_name (objfile
));
23160 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23161 if (!attr
&& resolve_abstract_p
23162 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23163 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23165 CORE_ADDR pc
= get_frame_pc ();
23166 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23167 struct gdbarch
*gdbarch
= objfile
->arch ();
23169 for (const auto &cand_off
23170 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23172 struct dwarf2_cu
*cand_cu
= cu
;
23173 struct die_info
*cand
23174 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23177 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23180 CORE_ADDR pc_low
, pc_high
;
23181 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23182 if (pc_low
== ((CORE_ADDR
) -1))
23184 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23185 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23186 if (!(pc_low
<= pc
&& pc
< pc_high
))
23190 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23197 /* DWARF: "If there is no such attribute, then there is no effect.".
23198 DATA is ignored if SIZE is 0. */
23200 retval
.data
= NULL
;
23203 else if (attr
->form_is_section_offset ())
23205 struct dwarf2_loclist_baton loclist_baton
;
23206 CORE_ADDR pc
= get_frame_pc ();
23209 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23211 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23213 retval
.size
= size
;
23217 if (!attr
->form_is_block ())
23218 error (_("Dwarf Error: DIE at %s referenced in module %s "
23219 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23220 sect_offset_str (sect_off
), objfile_name (objfile
));
23222 struct dwarf_block
*block
= attr
->as_block ();
23223 retval
.data
= block
->data
;
23224 retval
.size
= block
->size
;
23226 retval
.per_objfile
= per_objfile
;
23227 retval
.per_cu
= cu
->per_cu
;
23229 per_objfile
->age_comp_units ();
23236 struct dwarf2_locexpr_baton
23237 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23238 dwarf2_per_cu_data
*per_cu
,
23239 dwarf2_per_objfile
*per_objfile
,
23240 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23242 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23244 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23248 /* Write a constant of a given type as target-ordered bytes into
23251 static const gdb_byte
*
23252 write_constant_as_bytes (struct obstack
*obstack
,
23253 enum bfd_endian byte_order
,
23260 *len
= TYPE_LENGTH (type
);
23261 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23262 store_unsigned_integer (result
, *len
, byte_order
, value
);
23270 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23271 dwarf2_per_cu_data
*per_cu
,
23272 dwarf2_per_objfile
*per_objfile
,
23276 struct die_info
*die
;
23277 struct attribute
*attr
;
23278 const gdb_byte
*result
= NULL
;
23281 enum bfd_endian byte_order
;
23282 struct objfile
*objfile
= per_objfile
->objfile
;
23284 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23286 cu
= load_cu (per_cu
, per_objfile
, false);
23290 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23291 Instead just throw an error, not much else we can do. */
23292 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23293 sect_offset_str (sect_off
), objfile_name (objfile
));
23296 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23298 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23299 sect_offset_str (sect_off
), objfile_name (objfile
));
23301 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23305 byte_order
= (bfd_big_endian (objfile
->obfd
)
23306 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23308 switch (attr
->form
)
23311 case DW_FORM_addrx
:
23312 case DW_FORM_GNU_addr_index
:
23316 *len
= cu
->header
.addr_size
;
23317 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23318 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23322 case DW_FORM_string
:
23325 case DW_FORM_GNU_str_index
:
23326 case DW_FORM_GNU_strp_alt
:
23327 /* The string is already allocated on the objfile obstack, point
23330 const char *attr_name
= attr
->as_string ();
23331 result
= (const gdb_byte
*) attr_name
;
23332 *len
= strlen (attr_name
);
23335 case DW_FORM_block1
:
23336 case DW_FORM_block2
:
23337 case DW_FORM_block4
:
23338 case DW_FORM_block
:
23339 case DW_FORM_exprloc
:
23340 case DW_FORM_data16
:
23342 struct dwarf_block
*block
= attr
->as_block ();
23343 result
= block
->data
;
23344 *len
= block
->size
;
23348 /* The DW_AT_const_value attributes are supposed to carry the
23349 symbol's value "represented as it would be on the target
23350 architecture." By the time we get here, it's already been
23351 converted to host endianness, so we just need to sign- or
23352 zero-extend it as appropriate. */
23353 case DW_FORM_data1
:
23354 type
= die_type (die
, cu
);
23355 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23356 if (result
== NULL
)
23357 result
= write_constant_as_bytes (obstack
, byte_order
,
23360 case DW_FORM_data2
:
23361 type
= die_type (die
, cu
);
23362 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23363 if (result
== NULL
)
23364 result
= write_constant_as_bytes (obstack
, byte_order
,
23367 case DW_FORM_data4
:
23368 type
= die_type (die
, cu
);
23369 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23370 if (result
== NULL
)
23371 result
= write_constant_as_bytes (obstack
, byte_order
,
23374 case DW_FORM_data8
:
23375 type
= die_type (die
, cu
);
23376 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23377 if (result
== NULL
)
23378 result
= write_constant_as_bytes (obstack
, byte_order
,
23382 case DW_FORM_sdata
:
23383 case DW_FORM_implicit_const
:
23384 type
= die_type (die
, cu
);
23385 result
= write_constant_as_bytes (obstack
, byte_order
,
23386 type
, attr
->as_signed (), len
);
23389 case DW_FORM_udata
:
23390 type
= die_type (die
, cu
);
23391 result
= write_constant_as_bytes (obstack
, byte_order
,
23392 type
, attr
->as_unsigned (), len
);
23396 complaint (_("unsupported const value attribute form: '%s'"),
23397 dwarf_form_name (attr
->form
));
23407 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23408 dwarf2_per_cu_data
*per_cu
,
23409 dwarf2_per_objfile
*per_objfile
)
23411 struct die_info
*die
;
23413 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23415 cu
= load_cu (per_cu
, per_objfile
, false);
23420 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23424 return die_type (die
, cu
);
23430 dwarf2_get_die_type (cu_offset die_offset
,
23431 dwarf2_per_cu_data
*per_cu
,
23432 dwarf2_per_objfile
*per_objfile
)
23434 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23435 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23438 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23439 On entry *REF_CU is the CU of SRC_DIE.
23440 On exit *REF_CU is the CU of the result.
23441 Returns NULL if the referenced DIE isn't found. */
23443 static struct die_info
*
23444 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23445 struct dwarf2_cu
**ref_cu
)
23447 struct die_info temp_die
;
23448 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23449 struct die_info
*die
;
23450 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23453 /* While it might be nice to assert sig_type->type == NULL here,
23454 we can get here for DW_AT_imported_declaration where we need
23455 the DIE not the type. */
23457 /* If necessary, add it to the queue and load its DIEs.
23459 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23460 it doesn't mean they are currently loaded. Since we require them
23461 to be loaded, we must check for ourselves. */
23462 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23464 || per_objfile
->get_cu (sig_type
) == nullptr)
23465 read_signatured_type (sig_type
, per_objfile
);
23467 sig_cu
= per_objfile
->get_cu (sig_type
);
23468 gdb_assert (sig_cu
!= NULL
);
23469 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23470 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23471 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23472 to_underlying (temp_die
.sect_off
));
23475 /* For .gdb_index version 7 keep track of included TUs.
23476 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23477 if (per_objfile
->per_bfd
->index_table
!= NULL
23478 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23480 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23485 sig_cu
->ancestor
= cu
;
23493 /* Follow signatured type referenced by ATTR in SRC_DIE.
23494 On entry *REF_CU is the CU of SRC_DIE.
23495 On exit *REF_CU is the CU of the result.
23496 The result is the DIE of the type.
23497 If the referenced type cannot be found an error is thrown. */
23499 static struct die_info
*
23500 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23501 struct dwarf2_cu
**ref_cu
)
23503 ULONGEST signature
= attr
->as_signature ();
23504 struct signatured_type
*sig_type
;
23505 struct die_info
*die
;
23507 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23509 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23510 /* sig_type will be NULL if the signatured type is missing from
23512 if (sig_type
== NULL
)
23514 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23515 " from DIE at %s [in module %s]"),
23516 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23517 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23520 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23523 dump_die_for_error (src_die
);
23524 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23525 " from DIE at %s [in module %s]"),
23526 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23527 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23533 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23534 reading in and processing the type unit if necessary. */
23536 static struct type
*
23537 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23538 struct dwarf2_cu
*cu
)
23540 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23541 struct signatured_type
*sig_type
;
23542 struct dwarf2_cu
*type_cu
;
23543 struct die_info
*type_die
;
23546 sig_type
= lookup_signatured_type (cu
, signature
);
23547 /* sig_type will be NULL if the signatured type is missing from
23549 if (sig_type
== NULL
)
23551 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23552 " from DIE at %s [in module %s]"),
23553 hex_string (signature
), sect_offset_str (die
->sect_off
),
23554 objfile_name (per_objfile
->objfile
));
23555 return build_error_marker_type (cu
, die
);
23558 /* If we already know the type we're done. */
23559 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23560 if (type
!= nullptr)
23564 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23565 if (type_die
!= NULL
)
23567 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23568 is created. This is important, for example, because for c++ classes
23569 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23570 type
= read_type_die (type_die
, type_cu
);
23573 complaint (_("Dwarf Error: Cannot build signatured type %s"
23574 " referenced from DIE at %s [in module %s]"),
23575 hex_string (signature
), sect_offset_str (die
->sect_off
),
23576 objfile_name (per_objfile
->objfile
));
23577 type
= build_error_marker_type (cu
, die
);
23582 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23583 " from DIE at %s [in module %s]"),
23584 hex_string (signature
), sect_offset_str (die
->sect_off
),
23585 objfile_name (per_objfile
->objfile
));
23586 type
= build_error_marker_type (cu
, die
);
23589 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23594 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23595 reading in and processing the type unit if necessary. */
23597 static struct type
*
23598 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23599 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23601 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23602 if (attr
->form_is_ref ())
23604 struct dwarf2_cu
*type_cu
= cu
;
23605 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23607 return read_type_die (type_die
, type_cu
);
23609 else if (attr
->form
== DW_FORM_ref_sig8
)
23611 return get_signatured_type (die
, attr
->as_signature (), cu
);
23615 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23617 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23618 " at %s [in module %s]"),
23619 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23620 objfile_name (per_objfile
->objfile
));
23621 return build_error_marker_type (cu
, die
);
23625 /* Load the DIEs associated with type unit PER_CU into memory. */
23628 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23629 dwarf2_per_objfile
*per_objfile
)
23631 struct signatured_type
*sig_type
;
23633 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23634 gdb_assert (! per_cu
->type_unit_group_p ());
23636 /* We have the per_cu, but we need the signatured_type.
23637 Fortunately this is an easy translation. */
23638 gdb_assert (per_cu
->is_debug_types
);
23639 sig_type
= (struct signatured_type
*) per_cu
;
23641 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23643 read_signatured_type (sig_type
, per_objfile
);
23645 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23648 /* Read in a signatured type and build its CU and DIEs.
23649 If the type is a stub for the real type in a DWO file,
23650 read in the real type from the DWO file as well. */
23653 read_signatured_type (signatured_type
*sig_type
,
23654 dwarf2_per_objfile
*per_objfile
)
23656 gdb_assert (sig_type
->is_debug_types
);
23657 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23659 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23661 if (!reader
.dummy_p
)
23663 struct dwarf2_cu
*cu
= reader
.cu
;
23664 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23666 gdb_assert (cu
->die_hash
== NULL
);
23668 htab_create_alloc_ex (cu
->header
.length
/ 12,
23672 &cu
->comp_unit_obstack
,
23673 hashtab_obstack_allocate
,
23674 dummy_obstack_deallocate
);
23676 if (reader
.comp_unit_die
->has_children
)
23677 reader
.comp_unit_die
->child
23678 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23679 reader
.comp_unit_die
);
23680 cu
->dies
= reader
.comp_unit_die
;
23681 /* comp_unit_die is not stored in die_hash, no need. */
23683 /* We try not to read any attributes in this function, because
23684 not all CUs needed for references have been loaded yet, and
23685 symbol table processing isn't initialized. But we have to
23686 set the CU language, or we won't be able to build types
23687 correctly. Similarly, if we do not read the producer, we can
23688 not apply producer-specific interpretation. */
23689 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23694 sig_type
->tu_read
= 1;
23697 /* Decode simple location descriptions.
23698 Given a pointer to a dwarf block that defines a location, compute
23699 the location and return the value. If COMPUTED is non-null, it is
23700 set to true to indicate that decoding was successful, and false
23701 otherwise. If COMPUTED is null, then this function may emit a
23705 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23707 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23709 size_t size
= blk
->size
;
23710 const gdb_byte
*data
= blk
->data
;
23711 CORE_ADDR stack
[64];
23713 unsigned int bytes_read
, unsnd
;
23716 if (computed
!= nullptr)
23722 stack
[++stacki
] = 0;
23761 stack
[++stacki
] = op
- DW_OP_lit0
;
23796 stack
[++stacki
] = op
- DW_OP_reg0
;
23799 if (computed
== nullptr)
23800 dwarf2_complex_location_expr_complaint ();
23807 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23809 stack
[++stacki
] = unsnd
;
23812 if (computed
== nullptr)
23813 dwarf2_complex_location_expr_complaint ();
23820 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23825 case DW_OP_const1u
:
23826 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23830 case DW_OP_const1s
:
23831 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23835 case DW_OP_const2u
:
23836 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23840 case DW_OP_const2s
:
23841 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23845 case DW_OP_const4u
:
23846 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23850 case DW_OP_const4s
:
23851 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23855 case DW_OP_const8u
:
23856 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23861 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23867 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23872 stack
[stacki
+ 1] = stack
[stacki
];
23877 stack
[stacki
- 1] += stack
[stacki
];
23881 case DW_OP_plus_uconst
:
23882 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23888 stack
[stacki
- 1] -= stack
[stacki
];
23893 /* If we're not the last op, then we definitely can't encode
23894 this using GDB's address_class enum. This is valid for partial
23895 global symbols, although the variable's address will be bogus
23899 if (computed
== nullptr)
23900 dwarf2_complex_location_expr_complaint ();
23906 case DW_OP_GNU_push_tls_address
:
23907 case DW_OP_form_tls_address
:
23908 /* The top of the stack has the offset from the beginning
23909 of the thread control block at which the variable is located. */
23910 /* Nothing should follow this operator, so the top of stack would
23912 /* This is valid for partial global symbols, but the variable's
23913 address will be bogus in the psymtab. Make it always at least
23914 non-zero to not look as a variable garbage collected by linker
23915 which have DW_OP_addr 0. */
23918 if (computed
== nullptr)
23919 dwarf2_complex_location_expr_complaint ();
23926 case DW_OP_GNU_uninit
:
23927 if (computed
!= nullptr)
23932 case DW_OP_GNU_addr_index
:
23933 case DW_OP_GNU_const_index
:
23934 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23940 if (computed
== nullptr)
23942 const char *name
= get_DW_OP_name (op
);
23945 complaint (_("unsupported stack op: '%s'"),
23948 complaint (_("unsupported stack op: '%02x'"),
23952 return (stack
[stacki
]);
23955 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23956 outside of the allocated space. Also enforce minimum>0. */
23957 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23959 if (computed
== nullptr)
23960 complaint (_("location description stack overflow"));
23966 if (computed
== nullptr)
23967 complaint (_("location description stack underflow"));
23972 if (computed
!= nullptr)
23974 return (stack
[stacki
]);
23977 /* memory allocation interface */
23979 static struct dwarf_block
*
23980 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23982 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23985 static struct die_info
*
23986 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23988 struct die_info
*die
;
23989 size_t size
= sizeof (struct die_info
);
23992 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23994 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23995 memset (die
, 0, sizeof (struct die_info
));
24001 /* Macro support. */
24003 /* An overload of dwarf_decode_macros that finds the correct section
24004 and ensures it is read in before calling the other overload. */
24007 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24008 int section_is_gnu
)
24010 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24011 struct objfile
*objfile
= per_objfile
->objfile
;
24012 const struct line_header
*lh
= cu
->line_header
;
24013 unsigned int offset_size
= cu
->header
.offset_size
;
24014 struct dwarf2_section_info
*section
;
24015 const char *section_name
;
24017 if (cu
->dwo_unit
!= nullptr)
24019 if (section_is_gnu
)
24021 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24022 section_name
= ".debug_macro.dwo";
24026 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24027 section_name
= ".debug_macinfo.dwo";
24032 if (section_is_gnu
)
24034 section
= &per_objfile
->per_bfd
->macro
;
24035 section_name
= ".debug_macro";
24039 section
= &per_objfile
->per_bfd
->macinfo
;
24040 section_name
= ".debug_macinfo";
24044 section
->read (objfile
);
24045 if (section
->buffer
== nullptr)
24047 complaint (_("missing %s section"), section_name
);
24051 buildsym_compunit
*builder
= cu
->get_builder ();
24053 struct dwarf2_section_info
*str_offsets_section
;
24054 struct dwarf2_section_info
*str_section
;
24055 ULONGEST str_offsets_base
;
24057 if (cu
->dwo_unit
!= nullptr)
24059 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24060 ->sections
.str_offsets
;
24061 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24062 str_offsets_base
= cu
->header
.addr_size
;
24066 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24067 str_section
= &per_objfile
->per_bfd
->str
;
24068 str_offsets_base
= *cu
->str_offsets_base
;
24071 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24072 offset_size
, offset
, str_section
, str_offsets_section
,
24073 str_offsets_base
, section_is_gnu
);
24076 /* Return the .debug_loc section to use for CU.
24077 For DWO files use .debug_loc.dwo. */
24079 static struct dwarf2_section_info
*
24080 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24082 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24086 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24088 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24090 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24091 : &per_objfile
->per_bfd
->loc
);
24094 /* Return the .debug_rnglists section to use for CU. */
24095 static struct dwarf2_section_info
*
24096 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24098 if (cu
->header
.version
< 5)
24099 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24100 cu
->header
.version
);
24101 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24103 /* Make sure we read the .debug_rnglists section from the file that
24104 contains the DW_AT_ranges attribute we are reading. Normally that
24105 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24106 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24108 if (cu
->dwo_unit
!= nullptr
24109 && tag
!= DW_TAG_compile_unit
24110 && tag
!= DW_TAG_skeleton_unit
)
24112 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24114 if (sections
->rnglists
.size
> 0)
24115 return §ions
->rnglists
;
24117 error (_(".debug_rnglists section is missing from .dwo file."));
24119 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24122 /* A helper function that fills in a dwarf2_loclist_baton. */
24125 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24126 struct dwarf2_loclist_baton
*baton
,
24127 const struct attribute
*attr
)
24129 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24130 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24132 section
->read (per_objfile
->objfile
);
24134 baton
->per_objfile
= per_objfile
;
24135 baton
->per_cu
= cu
->per_cu
;
24136 gdb_assert (baton
->per_cu
);
24137 /* We don't know how long the location list is, but make sure we
24138 don't run off the edge of the section. */
24139 baton
->size
= section
->size
- attr
->as_unsigned ();
24140 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24141 if (cu
->base_address
.has_value ())
24142 baton
->base_address
= *cu
->base_address
;
24144 baton
->base_address
= 0;
24145 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24149 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24150 struct dwarf2_cu
*cu
, int is_block
)
24152 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24153 struct objfile
*objfile
= per_objfile
->objfile
;
24154 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24156 if (attr
->form_is_section_offset ()
24157 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24158 the section. If so, fall through to the complaint in the
24160 && attr
->as_unsigned () < section
->get_size (objfile
))
24162 struct dwarf2_loclist_baton
*baton
;
24164 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24166 fill_in_loclist_baton (cu
, baton
, attr
);
24168 if (!cu
->base_address
.has_value ())
24169 complaint (_("Location list used without "
24170 "specifying the CU base address."));
24172 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24173 ? dwarf2_loclist_block_index
24174 : dwarf2_loclist_index
);
24175 SYMBOL_LOCATION_BATON (sym
) = baton
;
24179 struct dwarf2_locexpr_baton
*baton
;
24181 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24182 baton
->per_objfile
= per_objfile
;
24183 baton
->per_cu
= cu
->per_cu
;
24184 gdb_assert (baton
->per_cu
);
24186 if (attr
->form_is_block ())
24188 /* Note that we're just copying the block's data pointer
24189 here, not the actual data. We're still pointing into the
24190 info_buffer for SYM's objfile; right now we never release
24191 that buffer, but when we do clean up properly this may
24193 struct dwarf_block
*block
= attr
->as_block ();
24194 baton
->size
= block
->size
;
24195 baton
->data
= block
->data
;
24199 dwarf2_invalid_attrib_class_complaint ("location description",
24200 sym
->natural_name ());
24204 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24205 ? dwarf2_locexpr_block_index
24206 : dwarf2_locexpr_index
);
24207 SYMBOL_LOCATION_BATON (sym
) = baton
;
24213 const comp_unit_head
*
24214 dwarf2_per_cu_data::get_header () const
24216 if (!m_header_read_in
)
24218 const gdb_byte
*info_ptr
24219 = this->section
->buffer
+ to_underlying (this->sect_off
);
24221 memset (&m_header
, 0, sizeof (m_header
));
24223 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24224 rcuh_kind::COMPILE
);
24226 m_header_read_in
= true;
24235 dwarf2_per_cu_data::addr_size () const
24237 return this->get_header ()->addr_size
;
24243 dwarf2_per_cu_data::offset_size () const
24245 return this->get_header ()->offset_size
;
24251 dwarf2_per_cu_data::ref_addr_size () const
24253 const comp_unit_head
*header
= this->get_header ();
24255 if (header
->version
== 2)
24256 return header
->addr_size
;
24258 return header
->offset_size
;
24261 /* A helper function for dwarf2_find_containing_comp_unit that returns
24262 the index of the result, and that searches a vector. It will
24263 return a result even if the offset in question does not actually
24264 occur in any CU. This is separate so that it can be unit
24268 dwarf2_find_containing_comp_unit
24269 (sect_offset sect_off
,
24270 unsigned int offset_in_dwz
,
24271 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24276 high
= all_comp_units
.size () - 1;
24279 struct dwarf2_per_cu_data
*mid_cu
;
24280 int mid
= low
+ (high
- low
) / 2;
24282 mid_cu
= all_comp_units
[mid
].get ();
24283 if (mid_cu
->is_dwz
> offset_in_dwz
24284 || (mid_cu
->is_dwz
== offset_in_dwz
24285 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24290 gdb_assert (low
== high
);
24294 /* Locate the .debug_info compilation unit from CU's objfile which contains
24295 the DIE at OFFSET. Raises an error on failure. */
24297 static struct dwarf2_per_cu_data
*
24298 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24299 unsigned int offset_in_dwz
,
24300 dwarf2_per_objfile
*per_objfile
)
24302 int low
= dwarf2_find_containing_comp_unit
24303 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24304 dwarf2_per_cu_data
*this_cu
24305 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24307 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24309 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24310 error (_("Dwarf Error: could not find partial DIE containing "
24311 "offset %s [in module %s]"),
24312 sect_offset_str (sect_off
),
24313 bfd_get_filename (per_objfile
->objfile
->obfd
));
24315 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24317 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24321 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24322 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24323 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24324 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24331 namespace selftests
{
24332 namespace find_containing_comp_unit
{
24337 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24338 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24339 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24340 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24341 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24342 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24343 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24344 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24347 two
->sect_off
= sect_offset (one
->length
);
24352 four
->sect_off
= sect_offset (three
->length
);
24356 std::vector
<dwarf2_per_cu_data_up
> units
;
24357 units
.push_back (std::move (one
));
24358 units
.push_back (std::move (two
));
24359 units
.push_back (std::move (three
));
24360 units
.push_back (std::move (four
));
24364 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24365 SELF_CHECK (units
[result
].get () == one_ptr
);
24366 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24367 SELF_CHECK (units
[result
].get () == one_ptr
);
24368 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24369 SELF_CHECK (units
[result
].get () == two_ptr
);
24371 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24372 SELF_CHECK (units
[result
].get () == three_ptr
);
24373 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24374 SELF_CHECK (units
[result
].get () == three_ptr
);
24375 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24376 SELF_CHECK (units
[result
].get () == four_ptr
);
24382 #endif /* GDB_SELF_TEST */
24384 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24387 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24388 enum language pretend_language
)
24390 struct attribute
*attr
;
24392 /* Set the language we're debugging. */
24393 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24394 if (attr
!= nullptr)
24395 set_cu_language (attr
->constant_value (0), cu
);
24398 cu
->language
= pretend_language
;
24399 cu
->language_defn
= language_def (cu
->language
);
24402 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24408 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24410 auto it
= m_dwarf2_cus
.find (per_cu
);
24411 if (it
== m_dwarf2_cus
.end ())
24420 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24422 gdb_assert (this->get_cu (per_cu
) == nullptr);
24424 m_dwarf2_cus
[per_cu
] = cu
;
24430 dwarf2_per_objfile::age_comp_units ()
24432 dwarf_read_debug_printf_v ("running");
24434 /* This is not expected to be called in the middle of CU expansion. There is
24435 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24436 loaded in memory. Calling age_comp_units while the queue is in use could
24437 make us free the DIEs for a CU that is in the queue and therefore break
24439 gdb_assert (!this->per_bfd
->queue
.has_value ());
24441 /* Start by clearing all marks. */
24442 for (auto pair
: m_dwarf2_cus
)
24443 pair
.second
->clear_mark ();
24445 /* Traverse all CUs, mark them and their dependencies if used recently
24447 for (auto pair
: m_dwarf2_cus
)
24449 dwarf2_cu
*cu
= pair
.second
;
24452 if (cu
->last_used
<= dwarf_max_cache_age
)
24456 /* Delete all CUs still not marked. */
24457 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24459 dwarf2_cu
*cu
= it
->second
;
24461 if (!cu
->is_marked ())
24463 dwarf_read_debug_printf_v ("deleting old CU %s",
24464 sect_offset_str (cu
->per_cu
->sect_off
));
24466 it
= m_dwarf2_cus
.erase (it
);
24476 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24478 auto it
= m_dwarf2_cus
.find (per_cu
);
24479 if (it
== m_dwarf2_cus
.end ())
24484 m_dwarf2_cus
.erase (it
);
24487 dwarf2_per_objfile::~dwarf2_per_objfile ()
24492 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24493 We store these in a hash table separate from the DIEs, and preserve them
24494 when the DIEs are flushed out of cache.
24496 The CU "per_cu" pointer is needed because offset alone is not enough to
24497 uniquely identify the type. A file may have multiple .debug_types sections,
24498 or the type may come from a DWO file. Furthermore, while it's more logical
24499 to use per_cu->section+offset, with Fission the section with the data is in
24500 the DWO file but we don't know that section at the point we need it.
24501 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24502 because we can enter the lookup routine, get_die_type_at_offset, from
24503 outside this file, and thus won't necessarily have PER_CU->cu.
24504 Fortunately, PER_CU is stable for the life of the objfile. */
24506 struct dwarf2_per_cu_offset_and_type
24508 const struct dwarf2_per_cu_data
*per_cu
;
24509 sect_offset sect_off
;
24513 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24516 per_cu_offset_and_type_hash (const void *item
)
24518 const struct dwarf2_per_cu_offset_and_type
*ofs
24519 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24521 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24524 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24527 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24529 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24530 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24531 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24532 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24534 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24535 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24538 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24539 table if necessary. For convenience, return TYPE.
24541 The DIEs reading must have careful ordering to:
24542 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24543 reading current DIE.
24544 * Not trying to dereference contents of still incompletely read in types
24545 while reading in other DIEs.
24546 * Enable referencing still incompletely read in types just by a pointer to
24547 the type without accessing its fields.
24549 Therefore caller should follow these rules:
24550 * Try to fetch any prerequisite types we may need to build this DIE type
24551 before building the type and calling set_die_type.
24552 * After building type call set_die_type for current DIE as soon as
24553 possible before fetching more types to complete the current type.
24554 * Make the type as complete as possible before fetching more types. */
24556 static struct type
*
24557 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24558 bool skip_data_location
)
24560 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24561 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24562 struct objfile
*objfile
= per_objfile
->objfile
;
24563 struct attribute
*attr
;
24564 struct dynamic_prop prop
;
24566 /* For Ada types, make sure that the gnat-specific data is always
24567 initialized (if not already set). There are a few types where
24568 we should not be doing so, because the type-specific area is
24569 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24570 where the type-specific area is used to store the floatformat).
24571 But this is not a problem, because the gnat-specific information
24572 is actually not needed for these types. */
24573 if (need_gnat_info (cu
)
24574 && type
->code () != TYPE_CODE_FUNC
24575 && type
->code () != TYPE_CODE_FLT
24576 && type
->code () != TYPE_CODE_METHODPTR
24577 && type
->code () != TYPE_CODE_MEMBERPTR
24578 && type
->code () != TYPE_CODE_METHOD
24579 && type
->code () != TYPE_CODE_FIXED_POINT
24580 && !HAVE_GNAT_AUX_INFO (type
))
24581 INIT_GNAT_SPECIFIC (type
);
24583 /* Read DW_AT_allocated and set in type. */
24584 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24587 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24588 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24589 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24592 /* Read DW_AT_associated and set in type. */
24593 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24596 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24597 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24598 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24601 /* Read DW_AT_data_location and set in type. */
24602 if (!skip_data_location
)
24604 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24605 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24606 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24609 if (per_objfile
->die_type_hash
== NULL
)
24610 per_objfile
->die_type_hash
24611 = htab_up (htab_create_alloc (127,
24612 per_cu_offset_and_type_hash
,
24613 per_cu_offset_and_type_eq
,
24614 NULL
, xcalloc
, xfree
));
24616 ofs
.per_cu
= cu
->per_cu
;
24617 ofs
.sect_off
= die
->sect_off
;
24619 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24620 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24622 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24623 sect_offset_str (die
->sect_off
));
24624 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24625 struct dwarf2_per_cu_offset_and_type
);
24630 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24631 or return NULL if the die does not have a saved type. */
24633 static struct type
*
24634 get_die_type_at_offset (sect_offset sect_off
,
24635 dwarf2_per_cu_data
*per_cu
,
24636 dwarf2_per_objfile
*per_objfile
)
24638 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24640 if (per_objfile
->die_type_hash
== NULL
)
24643 ofs
.per_cu
= per_cu
;
24644 ofs
.sect_off
= sect_off
;
24645 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24646 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24653 /* Look up the type for DIE in CU in die_type_hash,
24654 or return NULL if DIE does not have a saved type. */
24656 static struct type
*
24657 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24659 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24662 /* Trivial hash function for partial_die_info: the hash value of a DIE
24663 is its offset in .debug_info for this objfile. */
24666 partial_die_hash (const void *item
)
24668 const struct partial_die_info
*part_die
24669 = (const struct partial_die_info
*) item
;
24671 return to_underlying (part_die
->sect_off
);
24674 /* Trivial comparison function for partial_die_info structures: two DIEs
24675 are equal if they have the same offset. */
24678 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24680 const struct partial_die_info
*part_die_lhs
24681 = (const struct partial_die_info
*) item_lhs
;
24682 const struct partial_die_info
*part_die_rhs
24683 = (const struct partial_die_info
*) item_rhs
;
24685 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24688 struct cmd_list_element
*set_dwarf_cmdlist
;
24689 struct cmd_list_element
*show_dwarf_cmdlist
;
24692 show_check_physname (struct ui_file
*file
, int from_tty
,
24693 struct cmd_list_element
*c
, const char *value
)
24695 fprintf_filtered (file
,
24696 _("Whether to check \"physname\" is %s.\n"),
24700 void _initialize_dwarf2_read ();
24702 _initialize_dwarf2_read ()
24704 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24705 Set DWARF specific variables.\n\
24706 Configure DWARF variables such as the cache size."),
24707 &set_dwarf_cmdlist
,
24708 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24710 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24711 Show DWARF specific variables.\n\
24712 Show DWARF variables such as the cache size."),
24713 &show_dwarf_cmdlist
,
24714 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24716 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24717 &dwarf_max_cache_age
, _("\
24718 Set the upper bound on the age of cached DWARF compilation units."), _("\
24719 Show the upper bound on the age of cached DWARF compilation units."), _("\
24720 A higher limit means that cached compilation units will be stored\n\
24721 in memory longer, and more total memory will be used. Zero disables\n\
24722 caching, which can slow down startup."),
24724 show_dwarf_max_cache_age
,
24725 &set_dwarf_cmdlist
,
24726 &show_dwarf_cmdlist
);
24728 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24729 Set debugging of the DWARF reader."), _("\
24730 Show debugging of the DWARF reader."), _("\
24731 When enabled (non-zero), debugging messages are printed during DWARF\n\
24732 reading and symtab expansion. A value of 1 (one) provides basic\n\
24733 information. A value greater than 1 provides more verbose information."),
24736 &setdebuglist
, &showdebuglist
);
24738 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24739 Set debugging of the DWARF DIE reader."), _("\
24740 Show debugging of the DWARF DIE reader."), _("\
24741 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24742 The value is the maximum depth to print."),
24745 &setdebuglist
, &showdebuglist
);
24747 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24748 Set debugging of the dwarf line reader."), _("\
24749 Show debugging of the dwarf line reader."), _("\
24750 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24751 A value of 1 (one) provides basic information.\n\
24752 A value greater than 1 provides more verbose information."),
24755 &setdebuglist
, &showdebuglist
);
24757 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24758 Set cross-checking of \"physname\" code against demangler."), _("\
24759 Show cross-checking of \"physname\" code against demangler."), _("\
24760 When enabled, GDB's internal \"physname\" code is checked against\n\
24762 NULL
, show_check_physname
,
24763 &setdebuglist
, &showdebuglist
);
24765 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24766 no_class
, &use_deprecated_index_sections
, _("\
24767 Set whether to use deprecated gdb_index sections."), _("\
24768 Show whether to use deprecated gdb_index sections."), _("\
24769 When enabled, deprecated .gdb_index sections are used anyway.\n\
24770 Normally they are ignored either because of a missing feature or\n\
24771 performance issue.\n\
24772 Warning: This option must be enabled before gdb reads the file."),
24775 &setlist
, &showlist
);
24777 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24778 &dwarf2_locexpr_funcs
);
24779 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24780 &dwarf2_loclist_funcs
);
24782 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24783 &dwarf2_block_frame_base_locexpr_funcs
);
24784 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24785 &dwarf2_block_frame_base_loclist_funcs
);
24788 selftests::register_test ("dw2_expand_symtabs_matching",
24789 selftests::dw2_expand_symtabs_matching::run_test
);
24790 selftests::register_test ("dwarf2_find_containing_comp_unit",
24791 selftests::find_containing_comp_unit::run_test
);