1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2022 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;
835 partial_die_info (const partial_die_info
&) = default;
837 /* Adjust the partial die before generating a symbol for it. This
838 function may set the is_external flag or change the DIE's
840 void fixup (struct dwarf2_cu
*cu
);
842 /* Read a minimal amount of information into the minimal die
844 const gdb_byte
*read (const struct die_reader_specs
*reader
,
845 const struct abbrev_info
&abbrev
,
846 const gdb_byte
*info_ptr
);
848 /* Compute the name of this partial DIE. This memoizes the
849 result, so it is safe to call multiple times. */
850 const char *name (dwarf2_cu
*cu
);
852 /* Offset of this DIE. */
853 const sect_offset sect_off
;
855 /* DWARF-2 tag for this DIE. */
856 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
858 /* Assorted flags describing the data found in this DIE. */
859 const unsigned int has_children
: 1;
861 unsigned int is_external
: 1;
862 unsigned int is_declaration
: 1;
863 unsigned int has_type
: 1;
864 unsigned int has_specification
: 1;
865 unsigned int has_pc_info
: 1;
866 unsigned int has_range_info
: 1;
867 unsigned int may_be_inlined
: 1;
869 /* This DIE has been marked DW_AT_main_subprogram. */
870 unsigned int main_subprogram
: 1;
872 /* Flag set if the SCOPE field of this structure has been
874 unsigned int scope_set
: 1;
876 /* Flag set if the DIE has a byte_size attribute. */
877 unsigned int has_byte_size
: 1;
879 /* Flag set if the DIE has a DW_AT_const_value attribute. */
880 unsigned int has_const_value
: 1;
882 /* Flag set if any of the DIE's children are template arguments. */
883 unsigned int has_template_arguments
: 1;
885 /* Flag set if fixup has been called on this die. */
886 unsigned int fixup_called
: 1;
888 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
889 unsigned int is_dwz
: 1;
891 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
892 unsigned int spec_is_dwz
: 1;
894 unsigned int canonical_name
: 1;
896 /* The name of this DIE. Normally the value of DW_AT_name, but
897 sometimes a default name for unnamed DIEs. */
898 const char *raw_name
= nullptr;
900 /* The linkage name, if present. */
901 const char *linkage_name
= nullptr;
903 /* The scope to prepend to our children. This is generally
904 allocated on the comp_unit_obstack, so will disappear
905 when this compilation unit leaves the cache. */
906 const char *scope
= nullptr;
908 /* Some data associated with the partial DIE. The tag determines
909 which field is live. */
912 /* The location description associated with this DIE, if any. */
913 struct dwarf_block
*locdesc
;
914 /* The offset of an import, for DW_TAG_imported_unit. */
915 sect_offset sect_off
;
920 /* If HAS_PC_INFO, the PC range associated with this DIE. */
926 /* If HAS_RANGE_INFO, the ranges offset associated with this DIE. */
927 ULONGEST ranges_offset
;
930 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
931 DW_AT_sibling, if any. */
932 /* NOTE: This member isn't strictly necessary, partial_die_info::read
933 could return DW_AT_sibling values to its caller load_partial_dies. */
934 const gdb_byte
*sibling
= nullptr;
936 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
937 DW_AT_specification (or DW_AT_abstract_origin or
939 sect_offset spec_offset
{};
941 /* Pointers to this DIE's parent, first child, and next sibling,
943 struct partial_die_info
*die_parent
= nullptr;
944 struct partial_die_info
*die_child
= nullptr;
945 struct partial_die_info
*die_sibling
= nullptr;
947 friend struct partial_die_info
*
948 dwarf2_cu::find_partial_die (sect_offset sect_off
);
951 /* Only need to do look up in dwarf2_cu::find_partial_die. */
952 partial_die_info (sect_offset sect_off
)
953 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
957 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
959 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
964 has_specification
= 0;
972 has_template_arguments
= 0;
977 /* Don't set these using NSDMI (Non-static data member initialisation),
978 because g++-4.8 will error out. */
984 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
985 but this would require a corresponding change in unpack_field_as_long
987 static int bits_per_byte
= 8;
989 struct variant_part_builder
;
991 /* When reading a variant, we track a bit more information about the
992 field, and store it in an object of this type. */
996 int first_field
= -1;
999 /* A variant can contain other variant parts. */
1000 std::vector
<variant_part_builder
> variant_parts
;
1002 /* If we see a DW_TAG_variant, then this will be set if this is the
1004 bool default_branch
= false;
1005 /* If we see a DW_AT_discr_value, then this will be the discriminant
1007 ULONGEST discriminant_value
= 0;
1008 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1010 struct dwarf_block
*discr_list_data
= nullptr;
1013 /* This represents a DW_TAG_variant_part. */
1015 struct variant_part_builder
1017 /* The offset of the discriminant field. */
1018 sect_offset discriminant_offset
{};
1020 /* Variants that are direct children of this variant part. */
1021 std::vector
<variant_field
> variants
;
1023 /* True if we're currently reading a variant. */
1024 bool processing_variant
= false;
1029 int accessibility
= 0;
1031 /* Variant parts need to find the discriminant, which is a DIE
1032 reference. We track the section offset of each field to make
1035 struct field field
{};
1040 const char *name
= nullptr;
1041 std::vector
<struct fn_field
> fnfields
;
1044 /* The routines that read and process dies for a C struct or C++ class
1045 pass lists of data member fields and lists of member function fields
1046 in an instance of a field_info structure, as defined below. */
1049 /* List of data member and baseclasses fields. */
1050 std::vector
<struct nextfield
> fields
;
1051 std::vector
<struct nextfield
> baseclasses
;
1053 /* Set if the accessibility of one of the fields is not public. */
1054 bool non_public_fields
= false;
1056 /* Member function fieldlist array, contains name of possibly overloaded
1057 member function, number of overloaded member functions and a pointer
1058 to the head of the member function field chain. */
1059 std::vector
<struct fnfieldlist
> fnfieldlists
;
1061 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1062 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1063 std::vector
<struct decl_field
> typedef_field_list
;
1065 /* Nested types defined by this class and the number of elements in this
1067 std::vector
<struct decl_field
> nested_types_list
;
1069 /* If non-null, this is the variant part we are currently
1071 variant_part_builder
*current_variant_part
= nullptr;
1072 /* This holds all the top-level variant parts attached to the type
1074 std::vector
<variant_part_builder
> variant_parts
;
1076 /* Return the total number of fields (including baseclasses). */
1077 int nfields () const
1079 return fields
.size () + baseclasses
.size ();
1083 /* Loaded secondary compilation units are kept in memory until they
1084 have not been referenced for the processing of this many
1085 compilation units. Set this to zero to disable caching. Cache
1086 sizes of up to at least twenty will improve startup time for
1087 typical inter-CU-reference binaries, at an obvious memory cost. */
1088 static int dwarf_max_cache_age
= 5;
1090 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1091 struct cmd_list_element
*c
, const char *value
)
1093 fprintf_filtered (file
, _("The upper bound on the age of cached "
1094 "DWARF compilation units is %s.\n"),
1098 /* local function prototypes */
1100 static void dwarf2_find_base_address (struct die_info
*die
,
1101 struct dwarf2_cu
*cu
);
1103 static dwarf2_psymtab
*create_partial_symtab
1104 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1107 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1108 const gdb_byte
*info_ptr
,
1109 struct die_info
*type_unit_die
);
1111 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1113 static void scan_partial_symbols (struct partial_die_info
*,
1114 CORE_ADDR
*, CORE_ADDR
*,
1115 int, struct dwarf2_cu
*);
1117 static void add_partial_symbol (struct partial_die_info
*,
1118 struct dwarf2_cu
*);
1120 static void add_partial_namespace (struct partial_die_info
*pdi
,
1121 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1122 int set_addrmap
, struct dwarf2_cu
*cu
);
1124 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1125 CORE_ADDR
*highpc
, int set_addrmap
,
1126 struct dwarf2_cu
*cu
);
1128 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1129 struct dwarf2_cu
*cu
);
1131 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1132 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1133 int need_pc
, struct dwarf2_cu
*cu
);
1135 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1137 static struct partial_die_info
*load_partial_dies
1138 (const struct die_reader_specs
*, const gdb_byte
*, int);
1140 /* A pair of partial_die_info and compilation unit. */
1141 struct cu_partial_die_info
1143 /* The compilation unit of the partial_die_info. */
1144 struct dwarf2_cu
*cu
;
1145 /* A partial_die_info. */
1146 struct partial_die_info
*pdi
;
1148 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1154 cu_partial_die_info () = delete;
1157 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1158 struct dwarf2_cu
*);
1160 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1162 const struct attr_abbrev
*,
1165 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1166 struct attribute
*attr
, dwarf_tag tag
);
1168 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1170 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1171 dwarf2_section_info
*, sect_offset
);
1173 static const char *read_indirect_string
1174 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1175 const struct comp_unit_head
*, unsigned int *);
1177 static const char *read_indirect_string_at_offset
1178 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1180 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1184 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1185 ULONGEST str_index
);
1187 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1188 ULONGEST str_index
);
1190 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1191 struct dwarf2_cu
*);
1193 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1194 struct dwarf2_cu
*cu
);
1196 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1198 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1199 struct dwarf2_cu
*cu
);
1201 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1203 static struct die_info
*die_specification (struct die_info
*die
,
1204 struct dwarf2_cu
**);
1206 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1207 struct dwarf2_cu
*cu
);
1209 static void dwarf_decode_lines (struct line_header
*,
1210 const file_and_directory
&,
1211 struct dwarf2_cu
*, dwarf2_psymtab
*,
1212 CORE_ADDR
, int decode_mapping
);
1214 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1217 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1218 struct dwarf2_cu
*, struct symbol
* = NULL
);
1220 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1221 struct dwarf2_cu
*);
1223 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1226 struct obstack
*obstack
,
1227 struct dwarf2_cu
*cu
, LONGEST
*value
,
1228 const gdb_byte
**bytes
,
1229 struct dwarf2_locexpr_baton
**baton
);
1231 static struct type
*read_subrange_index_type (struct die_info
*die
,
1232 struct dwarf2_cu
*cu
);
1234 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1236 static int need_gnat_info (struct dwarf2_cu
*);
1238 static struct type
*die_descriptive_type (struct die_info
*,
1239 struct dwarf2_cu
*);
1241 static void set_descriptive_type (struct type
*, struct die_info
*,
1242 struct dwarf2_cu
*);
1244 static struct type
*die_containing_type (struct die_info
*,
1245 struct dwarf2_cu
*);
1247 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1248 struct dwarf2_cu
*);
1250 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1252 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1254 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1256 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1257 const char *suffix
, int physname
,
1258 struct dwarf2_cu
*cu
);
1260 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1262 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1264 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1266 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1268 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1270 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1272 /* Return the .debug_loclists section to use for cu. */
1273 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1275 /* Return the .debug_rnglists section to use for cu. */
1276 static struct dwarf2_section_info
*cu_debug_rnglists_section
1277 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1279 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1280 values. Keep the items ordered with increasing constraints compliance. */
1283 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1284 PC_BOUNDS_NOT_PRESENT
,
1286 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1287 were present but they do not form a valid range of PC addresses. */
1290 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1293 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1297 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1298 CORE_ADDR
*, CORE_ADDR
*,
1302 static void get_scope_pc_bounds (struct die_info
*,
1303 CORE_ADDR
*, CORE_ADDR
*,
1304 struct dwarf2_cu
*);
1306 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1307 CORE_ADDR
, struct dwarf2_cu
*);
1309 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1310 struct dwarf2_cu
*);
1312 static void dwarf2_attach_fields_to_type (struct field_info
*,
1313 struct type
*, struct dwarf2_cu
*);
1315 static void dwarf2_add_member_fn (struct field_info
*,
1316 struct die_info
*, struct type
*,
1317 struct dwarf2_cu
*);
1319 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1321 struct dwarf2_cu
*);
1323 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1325 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1327 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1329 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1331 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1333 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1335 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1337 static struct type
*read_module_type (struct die_info
*die
,
1338 struct dwarf2_cu
*cu
);
1340 static const char *namespace_name (struct die_info
*die
,
1341 int *is_anonymous
, struct dwarf2_cu
*);
1343 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1345 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1348 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1349 struct dwarf2_cu
*);
1351 static struct die_info
*read_die_and_siblings_1
1352 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1355 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1356 const gdb_byte
*info_ptr
,
1357 const gdb_byte
**new_info_ptr
,
1358 struct die_info
*parent
);
1360 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1361 struct die_info
**, const gdb_byte
*,
1364 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1365 struct die_info
**, const gdb_byte
*);
1367 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1369 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1372 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1374 static const char *dwarf2_full_name (const char *name
,
1375 struct die_info
*die
,
1376 struct dwarf2_cu
*cu
);
1378 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1379 struct dwarf2_cu
*cu
);
1381 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1382 struct dwarf2_cu
**);
1384 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1386 static void dump_die_for_error (struct die_info
*);
1388 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1391 /*static*/ void dump_die (struct die_info
*, int max_level
);
1393 static void store_in_ref_table (struct die_info
*,
1394 struct dwarf2_cu
*);
1396 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1397 const struct attribute
*,
1398 struct dwarf2_cu
**);
1400 static struct die_info
*follow_die_ref (struct die_info
*,
1401 const struct attribute
*,
1402 struct dwarf2_cu
**);
1404 static struct die_info
*follow_die_sig (struct die_info
*,
1405 const struct attribute
*,
1406 struct dwarf2_cu
**);
1408 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1409 struct dwarf2_cu
*);
1411 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1412 const struct attribute
*,
1413 struct dwarf2_cu
*);
1415 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1416 dwarf2_per_objfile
*per_objfile
);
1418 static void read_signatured_type (signatured_type
*sig_type
,
1419 dwarf2_per_objfile
*per_objfile
);
1421 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1422 struct die_info
*die
, struct dwarf2_cu
*cu
,
1423 struct dynamic_prop
*prop
, struct type
*type
);
1425 /* memory allocation interface */
1427 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1429 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1431 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1433 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1434 struct dwarf2_loclist_baton
*baton
,
1435 const struct attribute
*attr
);
1437 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1439 struct dwarf2_cu
*cu
,
1442 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1443 const gdb_byte
*info_ptr
,
1444 const struct abbrev_info
*abbrev
);
1446 static hashval_t
partial_die_hash (const void *item
);
1448 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1450 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1451 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1452 dwarf2_per_bfd
*per_bfd
);
1454 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1455 struct die_info
*comp_unit_die
,
1456 enum language pretend_language
);
1458 static struct type
*set_die_type (struct die_info
*, struct type
*,
1459 struct dwarf2_cu
*, bool = false);
1461 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1463 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1464 dwarf2_per_objfile
*per_objfile
,
1465 dwarf2_cu
*existing_cu
,
1467 enum language pretend_language
);
1469 static void process_full_comp_unit (dwarf2_cu
*cu
,
1470 enum language pretend_language
);
1472 static void process_full_type_unit (dwarf2_cu
*cu
,
1473 enum language pretend_language
);
1475 static struct type
*get_die_type_at_offset (sect_offset
,
1476 dwarf2_per_cu_data
*per_cu
,
1477 dwarf2_per_objfile
*per_objfile
);
1479 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1481 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1482 dwarf2_per_objfile
*per_objfile
,
1483 enum language pretend_language
);
1485 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1487 /* Class, the destructor of which frees all allocated queue entries. This
1488 will only have work to do if an error was thrown while processing the
1489 dwarf. If no error was thrown then the queue entries should have all
1490 been processed, and freed, as we went along. */
1492 class dwarf2_queue_guard
1495 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1496 : m_per_objfile (per_objfile
)
1498 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1500 m_per_objfile
->per_bfd
->queue
.emplace ();
1503 /* Free any entries remaining on the queue. There should only be
1504 entries left if we hit an error while processing the dwarf. */
1505 ~dwarf2_queue_guard ()
1507 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1509 m_per_objfile
->per_bfd
->queue
.reset ();
1512 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1515 dwarf2_per_objfile
*m_per_objfile
;
1518 dwarf2_queue_item::~dwarf2_queue_item ()
1520 /* Anything still marked queued is likely to be in an
1521 inconsistent state, so discard it. */
1524 per_objfile
->remove_cu (per_cu
);
1529 /* See dwarf2/read.h. */
1532 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1534 if (data
->is_debug_types
)
1535 delete static_cast<signatured_type
*> (data
);
1540 static file_and_directory
&find_file_and_directory
1541 (struct die_info
*die
, struct dwarf2_cu
*cu
);
1543 static const char *compute_include_file_name
1544 (const struct line_header
*lh
,
1545 const file_entry
&fe
,
1546 const file_and_directory
&cu_info
,
1547 gdb::unique_xmalloc_ptr
<char> *name_holder
);
1549 static htab_up
allocate_signatured_type_table ();
1551 static htab_up
allocate_dwo_unit_table ();
1553 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1554 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1555 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1557 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1559 static struct dwo_unit
*lookup_dwo_comp_unit
1560 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1561 ULONGEST signature
);
1563 static struct dwo_unit
*lookup_dwo_type_unit
1564 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1566 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1568 /* A unique pointer to a dwo_file. */
1570 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1572 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1574 static void check_producer (struct dwarf2_cu
*cu
);
1576 /* Various complaints about symbol reading that don't abort the process. */
1579 dwarf2_debug_line_missing_file_complaint (void)
1581 complaint (_(".debug_line section has line data without a file"));
1585 dwarf2_debug_line_missing_end_sequence_complaint (void)
1587 complaint (_(".debug_line section has line "
1588 "program sequence without an end"));
1592 dwarf2_complex_location_expr_complaint (void)
1594 complaint (_("location expression too complex"));
1598 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1601 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1606 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1608 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1612 /* Hash function for line_header_hash. */
1615 line_header_hash (const struct line_header
*ofs
)
1617 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1620 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1623 line_header_hash_voidp (const void *item
)
1625 const struct line_header
*ofs
= (const struct line_header
*) item
;
1627 return line_header_hash (ofs
);
1630 /* Equality function for line_header_hash. */
1633 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1635 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1636 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1638 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1639 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1644 /* An iterator for all_comp_units that is based on index. This
1645 approach makes it possible to iterate over all_comp_units safely,
1646 when some caller in the loop may add new units. */
1648 class all_comp_units_iterator
1652 all_comp_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1653 : m_per_bfd (per_bfd
),
1654 m_index (start
? 0 : per_bfd
->all_comp_units
.size ())
1658 all_comp_units_iterator
&operator++ ()
1664 dwarf2_per_cu_data
*operator* () const
1666 return m_per_bfd
->get_cu (m_index
);
1669 bool operator== (const all_comp_units_iterator
&other
) const
1671 return m_index
== other
.m_index
;
1675 bool operator!= (const all_comp_units_iterator
&other
) const
1677 return m_index
!= other
.m_index
;
1682 dwarf2_per_bfd
*m_per_bfd
;
1686 /* A range adapter for the all_comp_units_iterator. */
1687 class all_comp_units_range
1691 all_comp_units_range (dwarf2_per_bfd
*per_bfd
)
1692 : m_per_bfd (per_bfd
)
1696 all_comp_units_iterator
begin ()
1698 return all_comp_units_iterator (m_per_bfd
, true);
1701 all_comp_units_iterator
end ()
1703 return all_comp_units_iterator (m_per_bfd
, false);
1708 dwarf2_per_bfd
*m_per_bfd
;
1711 /* See declaration. */
1713 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1716 can_copy (can_copy_
)
1719 names
= &dwarf2_elf_names
;
1721 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1722 locate_sections (obfd
, sec
, *names
);
1725 dwarf2_per_bfd::~dwarf2_per_bfd ()
1727 for (auto &per_cu
: all_comp_units
)
1729 per_cu
->imported_symtabs_free ();
1730 per_cu
->free_cached_file_names ();
1733 /* Everything else should be on this->obstack. */
1739 dwarf2_per_objfile::remove_all_cus ()
1741 gdb_assert (!this->per_bfd
->queue
.has_value ());
1743 for (auto pair
: m_dwarf2_cus
)
1746 m_dwarf2_cus
.clear ();
1749 /* A helper class that calls free_cached_comp_units on
1752 class free_cached_comp_units
1756 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1757 : m_per_objfile (per_objfile
)
1761 ~free_cached_comp_units ()
1763 m_per_objfile
->remove_all_cus ();
1766 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1770 dwarf2_per_objfile
*m_per_objfile
;
1776 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1778 if (per_cu
->index
< this->m_symtabs
.size ())
1779 return this->m_symtabs
[per_cu
->index
] != nullptr;
1786 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1788 if (per_cu
->index
< this->m_symtabs
.size ())
1789 return this->m_symtabs
[per_cu
->index
];
1796 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1797 compunit_symtab
*symtab
)
1799 if (per_cu
->index
>= this->m_symtabs
.size ())
1800 this->m_symtabs
.resize (per_cu
->index
+ 1);
1801 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1802 this->m_symtabs
[per_cu
->index
] = symtab
;
1805 /* Try to locate the sections we need for DWARF 2 debugging
1806 information and return true if we have enough to do something.
1807 NAMES points to the dwarf2 section names, or is NULL if the standard
1808 ELF names are used. CAN_COPY is true for formats where symbol
1809 interposition is possible and so symbol values must follow copy
1810 relocation rules. */
1813 dwarf2_has_info (struct objfile
*objfile
,
1814 const struct dwarf2_debug_sections
*names
,
1817 if (objfile
->flags
& OBJF_READNEVER
)
1820 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1822 if (per_objfile
== NULL
)
1824 dwarf2_per_bfd
*per_bfd
;
1826 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1827 BFD doesn't require relocations.
1829 We don't share with objfiles for which -readnow was requested,
1830 because it would complicate things when loading the same BFD with
1831 -readnow and then without -readnow. */
1832 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1833 && (objfile
->flags
& OBJF_READNOW
) == 0)
1835 /* See if one has been created for this BFD yet. */
1836 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1838 if (per_bfd
== nullptr)
1840 /* No, create it now. */
1841 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1842 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1847 /* No sharing possible, create one specifically for this objfile. */
1848 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1849 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1852 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1855 return (!per_objfile
->per_bfd
->info
.is_virtual
1856 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1857 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1858 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1861 /* See declaration. */
1864 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1865 const dwarf2_debug_sections
&names
)
1867 flagword aflag
= bfd_section_flags (sectp
);
1869 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1872 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1873 > bfd_get_file_size (abfd
))
1875 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1876 warning (_("Discarding section %s which has a section size (%s"
1877 ") larger than the file size [in module %s]"),
1878 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1879 bfd_get_filename (abfd
));
1881 else if (names
.info
.matches (sectp
->name
))
1883 this->info
.s
.section
= sectp
;
1884 this->info
.size
= bfd_section_size (sectp
);
1886 else if (names
.abbrev
.matches (sectp
->name
))
1888 this->abbrev
.s
.section
= sectp
;
1889 this->abbrev
.size
= bfd_section_size (sectp
);
1891 else if (names
.line
.matches (sectp
->name
))
1893 this->line
.s
.section
= sectp
;
1894 this->line
.size
= bfd_section_size (sectp
);
1896 else if (names
.loc
.matches (sectp
->name
))
1898 this->loc
.s
.section
= sectp
;
1899 this->loc
.size
= bfd_section_size (sectp
);
1901 else if (names
.loclists
.matches (sectp
->name
))
1903 this->loclists
.s
.section
= sectp
;
1904 this->loclists
.size
= bfd_section_size (sectp
);
1906 else if (names
.macinfo
.matches (sectp
->name
))
1908 this->macinfo
.s
.section
= sectp
;
1909 this->macinfo
.size
= bfd_section_size (sectp
);
1911 else if (names
.macro
.matches (sectp
->name
))
1913 this->macro
.s
.section
= sectp
;
1914 this->macro
.size
= bfd_section_size (sectp
);
1916 else if (names
.str
.matches (sectp
->name
))
1918 this->str
.s
.section
= sectp
;
1919 this->str
.size
= bfd_section_size (sectp
);
1921 else if (names
.str_offsets
.matches (sectp
->name
))
1923 this->str_offsets
.s
.section
= sectp
;
1924 this->str_offsets
.size
= bfd_section_size (sectp
);
1926 else if (names
.line_str
.matches (sectp
->name
))
1928 this->line_str
.s
.section
= sectp
;
1929 this->line_str
.size
= bfd_section_size (sectp
);
1931 else if (names
.addr
.matches (sectp
->name
))
1933 this->addr
.s
.section
= sectp
;
1934 this->addr
.size
= bfd_section_size (sectp
);
1936 else if (names
.frame
.matches (sectp
->name
))
1938 this->frame
.s
.section
= sectp
;
1939 this->frame
.size
= bfd_section_size (sectp
);
1941 else if (names
.eh_frame
.matches (sectp
->name
))
1943 this->eh_frame
.s
.section
= sectp
;
1944 this->eh_frame
.size
= bfd_section_size (sectp
);
1946 else if (names
.ranges
.matches (sectp
->name
))
1948 this->ranges
.s
.section
= sectp
;
1949 this->ranges
.size
= bfd_section_size (sectp
);
1951 else if (names
.rnglists
.matches (sectp
->name
))
1953 this->rnglists
.s
.section
= sectp
;
1954 this->rnglists
.size
= bfd_section_size (sectp
);
1956 else if (names
.types
.matches (sectp
->name
))
1958 struct dwarf2_section_info type_section
;
1960 memset (&type_section
, 0, sizeof (type_section
));
1961 type_section
.s
.section
= sectp
;
1962 type_section
.size
= bfd_section_size (sectp
);
1964 this->types
.push_back (type_section
);
1966 else if (names
.gdb_index
.matches (sectp
->name
))
1968 this->gdb_index
.s
.section
= sectp
;
1969 this->gdb_index
.size
= bfd_section_size (sectp
);
1971 else if (names
.debug_names
.matches (sectp
->name
))
1973 this->debug_names
.s
.section
= sectp
;
1974 this->debug_names
.size
= bfd_section_size (sectp
);
1976 else if (names
.debug_aranges
.matches (sectp
->name
))
1978 this->debug_aranges
.s
.section
= sectp
;
1979 this->debug_aranges
.size
= bfd_section_size (sectp
);
1982 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1983 && bfd_section_vma (sectp
) == 0)
1984 this->has_section_at_zero
= true;
1987 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1991 dwarf2_get_section_info (struct objfile
*objfile
,
1992 enum dwarf2_section_enum sect
,
1993 asection
**sectp
, const gdb_byte
**bufp
,
1994 bfd_size_type
*sizep
)
1996 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1997 struct dwarf2_section_info
*info
;
1999 /* We may see an objfile without any DWARF, in which case we just
2001 if (per_objfile
== NULL
)
2010 case DWARF2_DEBUG_FRAME
:
2011 info
= &per_objfile
->per_bfd
->frame
;
2013 case DWARF2_EH_FRAME
:
2014 info
= &per_objfile
->per_bfd
->eh_frame
;
2017 gdb_assert_not_reached ("unexpected section");
2020 info
->read (objfile
);
2022 *sectp
= info
->get_bfd_section ();
2023 *bufp
= info
->buffer
;
2024 *sizep
= info
->size
;
2028 /* DWARF quick_symbol_functions support. */
2030 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2031 unique line tables, so we maintain a separate table of all .debug_line
2032 derived entries to support the sharing.
2033 All the quick functions need is the list of file names. We discard the
2034 line_header when we're done and don't need to record it here. */
2035 struct quick_file_names
2037 /* The data used to construct the hash key. */
2038 struct stmt_list_hash hash
;
2040 /* The number of entries in file_names, real_names. */
2041 unsigned int num_file_names
;
2043 /* The CU directory, as given by DW_AT_comp_dir. May be
2045 const char *comp_dir
;
2047 /* The file names from the line table, after being run through
2049 const char **file_names
;
2051 /* The file names from the line table after being run through
2052 gdb_realpath. These are computed lazily. */
2053 const char **real_names
;
2056 /* When using the index (and thus not using psymtabs), each CU has an
2057 object of this type. This is used to hold information needed by
2058 the various "quick" methods. */
2059 struct dwarf2_per_cu_quick_data
2061 /* The file table. This can be NULL if there was no file table
2062 or it's currently not read in.
2063 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2064 struct quick_file_names
*file_names
;
2066 /* A temporary mark bit used when iterating over all CUs in
2067 expand_symtabs_matching. */
2068 unsigned int mark
: 1;
2070 /* True if we've tried to read the file table. There will be no
2071 point in trying to read it again next time. */
2072 bool files_read
: 1;
2075 /* A subclass of psymbol_functions that arranges to read the DWARF
2076 partial symbols when needed. */
2077 struct lazy_dwarf_reader
: public psymbol_functions
2079 using psymbol_functions::psymbol_functions
;
2081 bool can_lazily_read_symbols () override
2086 void read_partial_symbols (struct objfile
*objfile
) override
2088 if (dwarf2_has_info (objfile
, nullptr))
2089 dwarf2_build_psymtabs (objfile
, this);
2093 static quick_symbol_functions_up
2094 make_lazy_dwarf_reader ()
2096 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2099 struct dwarf2_base_index_functions
: public quick_symbol_functions
2101 bool has_symbols (struct objfile
*objfile
) override
;
2103 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2105 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2107 void forget_cached_source_info (struct objfile
*objfile
) override
;
2109 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2112 bool *symbol_found_p
) override
2114 *symbol_found_p
= false;
2115 return language_unknown
;
2118 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2120 void expand_all_symtabs (struct objfile
*objfile
) override
;
2122 struct compunit_symtab
*find_pc_sect_compunit_symtab
2123 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2124 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2126 struct compunit_symtab
*find_compunit_symtab_by_address
2127 (struct objfile
*objfile
, CORE_ADDR address
) override
2132 void map_symbol_filenames (struct objfile
*objfile
,
2133 gdb::function_view
<symbol_filename_ftype
> fun
,
2134 bool need_fullname
) override
;
2137 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2139 void dump (struct objfile
*objfile
) override
;
2141 void expand_matching_symbols
2143 const lookup_name_info
&lookup_name
,
2146 symbol_compare_ftype
*ordered_compare
) override
;
2148 bool expand_symtabs_matching
2149 (struct objfile
*objfile
,
2150 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2151 const lookup_name_info
*lookup_name
,
2152 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2153 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2154 block_search_flags search_flags
,
2156 enum search_domain kind
) override
;
2159 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2161 void dump (struct objfile
*objfile
) override
;
2163 void expand_matching_symbols
2165 const lookup_name_info
&lookup_name
,
2168 symbol_compare_ftype
*ordered_compare
) override
;
2170 bool expand_symtabs_matching
2171 (struct objfile
*objfile
,
2172 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2173 const lookup_name_info
*lookup_name
,
2174 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2175 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2176 block_search_flags search_flags
,
2178 enum search_domain kind
) override
;
2181 static quick_symbol_functions_up
2182 make_dwarf_gdb_index ()
2184 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2187 static quick_symbol_functions_up
2188 make_dwarf_debug_names ()
2190 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2193 /* Utility hash function for a stmt_list_hash. */
2196 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2200 if (stmt_list_hash
->dwo_unit
!= NULL
)
2201 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2202 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2206 /* Utility equality function for a stmt_list_hash. */
2209 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2210 const struct stmt_list_hash
*rhs
)
2212 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2214 if (lhs
->dwo_unit
!= NULL
2215 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2218 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2221 /* Hash function for a quick_file_names. */
2224 hash_file_name_entry (const void *e
)
2226 const struct quick_file_names
*file_data
2227 = (const struct quick_file_names
*) e
;
2229 return hash_stmt_list_entry (&file_data
->hash
);
2232 /* Equality function for a quick_file_names. */
2235 eq_file_name_entry (const void *a
, const void *b
)
2237 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2238 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2240 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2243 /* Create a quick_file_names hash table. */
2246 create_quick_file_names_table (unsigned int nr_initial_entries
)
2248 return htab_up (htab_create_alloc (nr_initial_entries
,
2249 hash_file_name_entry
, eq_file_name_entry
,
2250 nullptr, xcalloc
, xfree
));
2253 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2254 function is unrelated to symtabs, symtab would have to be created afterwards.
2255 You should call age_cached_comp_units after processing the CU. */
2258 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2261 if (per_cu
->is_debug_types
)
2262 load_full_type_unit (per_cu
, per_objfile
);
2264 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2265 skip_partial
, language_minimal
);
2267 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2269 return nullptr; /* Dummy CU. */
2271 dwarf2_find_base_address (cu
->dies
, cu
);
2276 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2279 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2280 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2282 /* Skip type_unit_groups, reading the type units they contain
2283 is handled elsewhere. */
2284 if (per_cu
->type_unit_group_p ())
2288 /* The destructor of dwarf2_queue_guard frees any entries left on
2289 the queue. After this point we're guaranteed to leave this function
2290 with the dwarf queue empty. */
2291 dwarf2_queue_guard
q_guard (per_objfile
);
2293 if (!per_objfile
->symtab_set_p (per_cu
))
2295 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2296 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2298 /* If we just loaded a CU from a DWO, and we're working with an index
2299 that may badly handle TUs, load all the TUs in that DWO as well.
2300 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2301 if (!per_cu
->is_debug_types
2303 && cu
->dwo_unit
!= NULL
2304 && per_objfile
->per_bfd
->index_table
!= NULL
2305 && per_objfile
->per_bfd
->index_table
->version
<= 7
2306 /* DWP files aren't supported yet. */
2307 && get_dwp_file (per_objfile
) == NULL
)
2308 queue_and_load_all_dwo_tus (cu
);
2311 process_queue (per_objfile
);
2314 /* Age the cache, releasing compilation units that have not
2315 been used recently. */
2316 per_objfile
->age_comp_units ();
2319 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2320 the per-objfile for which this symtab is instantiated.
2322 Returns the resulting symbol table. */
2324 static struct compunit_symtab
*
2325 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2326 dwarf2_per_objfile
*per_objfile
,
2329 gdb_assert (per_objfile
->per_bfd
->using_index
);
2331 if (!per_objfile
->symtab_set_p (per_cu
))
2333 free_cached_comp_units
freer (per_objfile
);
2334 scoped_restore decrementer
= increment_reading_symtab ();
2335 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2336 process_cu_includes (per_objfile
);
2339 return per_objfile
->get_symtab (per_cu
);
2344 dwarf2_per_cu_data_up
2345 dwarf2_per_bfd::allocate_per_cu ()
2347 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2348 result
->per_bfd
= this;
2349 result
->index
= all_comp_units
.size ();
2356 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2358 signatured_type_up
result (new signatured_type (signature
));
2359 result
->per_bfd
= this;
2360 result
->index
= all_comp_units
.size ();
2361 result
->is_debug_types
= true;
2366 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2367 obstack, and constructed with the specified field values. */
2369 static dwarf2_per_cu_data_up
2370 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2371 struct dwarf2_section_info
*section
,
2373 sect_offset sect_off
, ULONGEST length
)
2375 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2376 the_cu
->sect_off
= sect_off
;
2377 the_cu
->length
= length
;
2378 the_cu
->section
= section
;
2379 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2380 struct dwarf2_per_cu_quick_data
);
2381 the_cu
->is_dwz
= is_dwz
;
2385 /* A helper for create_cus_from_index that handles a given list of
2389 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2390 const gdb_byte
*cu_list
, offset_type n_elements
,
2391 struct dwarf2_section_info
*section
,
2394 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2396 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2398 sect_offset sect_off
2399 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2400 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2403 dwarf2_per_cu_data_up per_cu
2404 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2406 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2410 /* Read the CU list from the mapped index, and use it to create all
2411 the CU objects for PER_BFD. */
2414 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2415 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2416 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2418 gdb_assert (per_bfd
->all_comp_units
.empty ());
2419 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2421 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2424 if (dwz_elements
== 0)
2427 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2428 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2432 /* Create the signatured type hash table from the index. */
2435 create_signatured_type_table_from_index
2436 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2437 const gdb_byte
*bytes
, offset_type elements
)
2439 htab_up sig_types_hash
= allocate_signatured_type_table ();
2441 for (offset_type i
= 0; i
< elements
; i
+= 3)
2443 signatured_type_up sig_type
;
2446 cu_offset type_offset_in_tu
;
2448 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2449 sect_offset sect_off
2450 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2452 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2454 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2457 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2458 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2459 sig_type
->section
= section
;
2460 sig_type
->sect_off
= sect_off
;
2462 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2463 struct dwarf2_per_cu_quick_data
);
2465 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2466 *slot
= sig_type
.get ();
2468 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2471 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2474 /* Create the signatured type hash table from .debug_names. */
2477 create_signatured_type_table_from_debug_names
2478 (dwarf2_per_objfile
*per_objfile
,
2479 const mapped_debug_names
&map
,
2480 struct dwarf2_section_info
*section
,
2481 struct dwarf2_section_info
*abbrev_section
)
2483 struct objfile
*objfile
= per_objfile
->objfile
;
2485 section
->read (objfile
);
2486 abbrev_section
->read (objfile
);
2488 htab_up sig_types_hash
= allocate_signatured_type_table ();
2490 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2492 signatured_type_up sig_type
;
2495 sect_offset sect_off
2496 = (sect_offset
) (extract_unsigned_integer
2497 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2499 map
.dwarf5_byte_order
));
2501 comp_unit_head cu_header
;
2502 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2504 section
->buffer
+ to_underlying (sect_off
),
2507 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2508 (cu_header
.signature
);
2509 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2510 sig_type
->section
= section
;
2511 sig_type
->sect_off
= sect_off
;
2513 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2514 struct dwarf2_per_cu_quick_data
);
2516 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2517 *slot
= sig_type
.get ();
2519 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2522 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2525 /* Read the address map data from the mapped index, and use it to
2526 populate the psymtabs_addrmap. */
2529 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2530 struct mapped_index
*index
)
2532 struct objfile
*objfile
= per_objfile
->objfile
;
2533 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2534 struct gdbarch
*gdbarch
= objfile
->arch ();
2535 const gdb_byte
*iter
, *end
;
2536 struct addrmap
*mutable_map
;
2539 auto_obstack temp_obstack
;
2541 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2543 iter
= index
->address_table
.data ();
2544 end
= iter
+ index
->address_table
.size ();
2546 baseaddr
= objfile
->text_section_offset ();
2550 ULONGEST hi
, lo
, cu_index
;
2551 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2553 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2555 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2560 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2561 hex_string (lo
), hex_string (hi
));
2565 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2567 complaint (_(".gdb_index address table has invalid CU number %u"),
2568 (unsigned) cu_index
);
2572 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2573 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2574 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2575 per_bfd
->get_cu (cu_index
));
2578 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2582 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2583 populate the psymtabs_addrmap. */
2586 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2587 struct dwarf2_section_info
*section
)
2589 struct objfile
*objfile
= per_objfile
->objfile
;
2590 bfd
*abfd
= objfile
->obfd
;
2591 struct gdbarch
*gdbarch
= objfile
->arch ();
2592 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2593 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2595 auto_obstack temp_obstack
;
2596 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2598 std::unordered_map
<sect_offset
,
2599 dwarf2_per_cu_data
*,
2600 gdb::hash_enum
<sect_offset
>>
2601 debug_info_offset_to_per_cu
;
2602 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2604 /* A TU will not need aranges, and skipping them here is an easy
2605 way of ignoring .debug_types -- and possibly seeing a
2606 duplicate section offset -- entirely. */
2607 if (per_cu
->is_debug_types
)
2610 const auto insertpair
2611 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2613 if (!insertpair
.second
)
2615 warning (_("Section .debug_aranges in %s has duplicate "
2616 "debug_info_offset %s, ignoring .debug_aranges."),
2617 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2622 section
->read (objfile
);
2624 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2626 const gdb_byte
*addr
= section
->buffer
;
2628 while (addr
< section
->buffer
+ section
->size
)
2630 const gdb_byte
*const entry_addr
= addr
;
2631 unsigned int bytes_read
;
2633 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2637 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2638 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2639 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2640 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2642 warning (_("Section .debug_aranges in %s entry at offset %s "
2643 "length %s exceeds section length %s, "
2644 "ignoring .debug_aranges."),
2645 objfile_name (objfile
),
2646 plongest (entry_addr
- section
->buffer
),
2647 plongest (bytes_read
+ entry_length
),
2648 pulongest (section
->size
));
2652 /* The version number. */
2653 const uint16_t version
= read_2_bytes (abfd
, addr
);
2657 warning (_("Section .debug_aranges in %s entry at offset %s "
2658 "has unsupported version %d, ignoring .debug_aranges."),
2659 objfile_name (objfile
),
2660 plongest (entry_addr
- section
->buffer
), version
);
2664 const uint64_t debug_info_offset
2665 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2666 addr
+= offset_size
;
2667 const auto per_cu_it
2668 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2669 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2671 warning (_("Section .debug_aranges in %s entry at offset %s "
2672 "debug_info_offset %s does not exists, "
2673 "ignoring .debug_aranges."),
2674 objfile_name (objfile
),
2675 plongest (entry_addr
- section
->buffer
),
2676 pulongest (debug_info_offset
));
2679 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2681 const uint8_t address_size
= *addr
++;
2682 if (address_size
< 1 || address_size
> 8)
2684 warning (_("Section .debug_aranges in %s entry at offset %s "
2685 "address_size %u is invalid, ignoring .debug_aranges."),
2686 objfile_name (objfile
),
2687 plongest (entry_addr
- section
->buffer
), address_size
);
2691 const uint8_t segment_selector_size
= *addr
++;
2692 if (segment_selector_size
!= 0)
2694 warning (_("Section .debug_aranges in %s entry at offset %s "
2695 "segment_selector_size %u is not supported, "
2696 "ignoring .debug_aranges."),
2697 objfile_name (objfile
),
2698 plongest (entry_addr
- section
->buffer
),
2699 segment_selector_size
);
2703 /* Must pad to an alignment boundary that is twice the address
2704 size. It is undocumented by the DWARF standard but GCC does
2705 use it. However, not every compiler does this. We can see
2706 whether it has happened by looking at the total length of the
2707 contents of the aranges for this CU -- it if isn't a multiple
2708 of twice the address size, then we skip any leftover
2710 addr
+= (entry_end
- addr
) % (2 * address_size
);
2714 if (addr
+ 2 * address_size
> entry_end
)
2716 warning (_("Section .debug_aranges in %s entry at offset %s "
2717 "address list is not properly terminated, "
2718 "ignoring .debug_aranges."),
2719 objfile_name (objfile
),
2720 plongest (entry_addr
- section
->buffer
));
2723 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2725 addr
+= address_size
;
2726 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2728 addr
+= address_size
;
2729 if (start
== 0 && length
== 0)
2731 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2733 /* Symbol was eliminated due to a COMDAT group. */
2736 ULONGEST end
= start
+ length
;
2737 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2739 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2741 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2745 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2749 /* A helper function that reads the .gdb_index from BUFFER and fills
2750 in MAP. FILENAME is the name of the file containing the data;
2751 it is used for error reporting. DEPRECATED_OK is true if it is
2752 ok to use deprecated sections.
2754 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2755 out parameters that are filled in with information about the CU and
2756 TU lists in the section.
2758 Returns true if all went well, false otherwise. */
2761 read_gdb_index_from_buffer (const char *filename
,
2763 gdb::array_view
<const gdb_byte
> buffer
,
2764 struct mapped_index
*map
,
2765 const gdb_byte
**cu_list
,
2766 offset_type
*cu_list_elements
,
2767 const gdb_byte
**types_list
,
2768 offset_type
*types_list_elements
)
2770 const gdb_byte
*addr
= &buffer
[0];
2771 offset_view
metadata (buffer
);
2773 /* Version check. */
2774 offset_type version
= metadata
[0];
2775 /* Versions earlier than 3 emitted every copy of a psymbol. This
2776 causes the index to behave very poorly for certain requests. Version 3
2777 contained incomplete addrmap. So, it seems better to just ignore such
2781 static int warning_printed
= 0;
2782 if (!warning_printed
)
2784 warning (_("Skipping obsolete .gdb_index section in %s."),
2786 warning_printed
= 1;
2790 /* Index version 4 uses a different hash function than index version
2793 Versions earlier than 6 did not emit psymbols for inlined
2794 functions. Using these files will cause GDB not to be able to
2795 set breakpoints on inlined functions by name, so we ignore these
2796 indices unless the user has done
2797 "set use-deprecated-index-sections on". */
2798 if (version
< 6 && !deprecated_ok
)
2800 static int warning_printed
= 0;
2801 if (!warning_printed
)
2804 Skipping deprecated .gdb_index section in %s.\n\
2805 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2806 to use the section anyway."),
2808 warning_printed
= 1;
2812 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2813 of the TU (for symbols coming from TUs),
2814 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2815 Plus gold-generated indices can have duplicate entries for global symbols,
2816 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2817 These are just performance bugs, and we can't distinguish gdb-generated
2818 indices from gold-generated ones, so issue no warning here. */
2820 /* Indexes with higher version than the one supported by GDB may be no
2821 longer backward compatible. */
2825 map
->version
= version
;
2828 *cu_list
= addr
+ metadata
[i
];
2829 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2832 *types_list
= addr
+ metadata
[i
];
2833 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2836 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2837 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2839 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2842 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2843 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2845 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2849 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2851 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
2853 /* An empty constant pool implies that all symbol table entries are
2854 empty. Make map->symbol_table.empty () == true. */
2856 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2863 /* Callback types for dwarf2_read_gdb_index. */
2865 typedef gdb::function_view
2866 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2867 get_gdb_index_contents_ftype
;
2868 typedef gdb::function_view
2869 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2870 get_gdb_index_contents_dwz_ftype
;
2872 /* Read .gdb_index. If everything went ok, initialize the "quick"
2873 elements of all the CUs and return 1. Otherwise, return 0. */
2876 dwarf2_read_gdb_index
2877 (dwarf2_per_objfile
*per_objfile
,
2878 get_gdb_index_contents_ftype get_gdb_index_contents
,
2879 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2881 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2882 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2883 struct dwz_file
*dwz
;
2884 struct objfile
*objfile
= per_objfile
->objfile
;
2885 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2887 gdb::array_view
<const gdb_byte
> main_index_contents
2888 = get_gdb_index_contents (objfile
, per_bfd
);
2890 if (main_index_contents
.empty ())
2893 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2894 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2895 use_deprecated_index_sections
,
2896 main_index_contents
, map
.get (), &cu_list
,
2897 &cu_list_elements
, &types_list
,
2898 &types_list_elements
))
2901 /* Don't use the index if it's empty. */
2902 if (map
->symbol_table
.empty ())
2905 /* If there is a .dwz file, read it so we can get its CU list as
2907 dwz
= dwarf2_get_dwz_file (per_bfd
);
2910 struct mapped_index dwz_map
;
2911 const gdb_byte
*dwz_types_ignore
;
2912 offset_type dwz_types_elements_ignore
;
2914 gdb::array_view
<const gdb_byte
> dwz_index_content
2915 = get_gdb_index_contents_dwz (objfile
, dwz
);
2917 if (dwz_index_content
.empty ())
2920 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2921 1, dwz_index_content
, &dwz_map
,
2922 &dwz_list
, &dwz_list_elements
,
2924 &dwz_types_elements_ignore
))
2926 warning (_("could not read '.gdb_index' section from %s; skipping"),
2927 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2932 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2935 if (types_list_elements
)
2937 /* We can only handle a single .debug_types when we have an
2939 if (per_bfd
->types
.size () != 1)
2942 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2944 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2945 types_list_elements
);
2948 create_addrmap_from_index (per_objfile
, map
.get ());
2950 per_bfd
->index_table
= std::move (map
);
2951 per_bfd
->using_index
= 1;
2952 per_bfd
->quick_file_names_table
=
2953 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2958 /* die_reader_func for dw2_get_file_names. */
2961 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2962 struct die_info
*comp_unit_die
)
2964 struct dwarf2_cu
*cu
= reader
->cu
;
2965 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2966 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2967 struct dwarf2_per_cu_data
*lh_cu
;
2968 struct attribute
*attr
;
2970 struct quick_file_names
*qfn
;
2972 gdb_assert (! this_cu
->is_debug_types
);
2974 this_cu
->v
.quick
->files_read
= true;
2975 /* Our callers never want to match partial units -- instead they
2976 will match the enclosing full CU. */
2977 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2984 sect_offset line_offset
{};
2986 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2987 if (attr
!= nullptr && attr
->form_is_unsigned ())
2989 struct quick_file_names find_entry
;
2991 line_offset
= (sect_offset
) attr
->as_unsigned ();
2993 /* We may have already read in this line header (TU line header sharing).
2994 If we have we're done. */
2995 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2996 find_entry
.hash
.line_sect_off
= line_offset
;
2997 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2998 &find_entry
, INSERT
);
3001 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3005 lh
= dwarf_decode_line_header (line_offset
, cu
);
3008 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
3011 if (!fnd
.is_unknown ())
3013 else if (lh
== nullptr)
3016 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3017 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3018 qfn
->hash
.line_sect_off
= line_offset
;
3019 /* There may not be a DW_AT_stmt_list. */
3020 if (slot
!= nullptr)
3023 std::vector
<const char *> include_names
;
3026 for (const auto &entry
: lh
->file_names ())
3028 gdb::unique_xmalloc_ptr
<char> name_holder
;
3029 const char *include_name
=
3030 compute_include_file_name (lh
.get (), entry
, fnd
, &name_holder
);
3031 if (include_name
!= nullptr)
3033 include_name
= per_objfile
->objfile
->intern (include_name
);
3034 include_names
.push_back (include_name
);
3039 qfn
->num_file_names
= offset
+ include_names
.size ();
3040 qfn
->comp_dir
= fnd
.intern_comp_dir (per_objfile
->objfile
);
3042 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3043 qfn
->num_file_names
);
3045 qfn
->file_names
[0] = xstrdup (fnd
.get_name ());
3047 if (!include_names
.empty ())
3048 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
3049 include_names
.size () * sizeof (const char *));
3051 qfn
->real_names
= NULL
;
3053 lh_cu
->v
.quick
->file_names
= qfn
;
3056 /* A helper for the "quick" functions which attempts to read the line
3057 table for THIS_CU. */
3059 static struct quick_file_names
*
3060 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3061 dwarf2_per_objfile
*per_objfile
)
3063 /* This should never be called for TUs. */
3064 gdb_assert (! this_cu
->is_debug_types
);
3065 /* Nor type unit groups. */
3066 gdb_assert (! this_cu
->type_unit_group_p ());
3068 if (this_cu
->v
.quick
->files_read
)
3069 return this_cu
->v
.quick
->file_names
;
3071 cutu_reader
reader (this_cu
, per_objfile
);
3072 if (!reader
.dummy_p
)
3073 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3075 return this_cu
->v
.quick
->file_names
;
3078 /* A helper for the "quick" functions which computes and caches the
3079 real path for a given file name from the line table. */
3082 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3083 struct quick_file_names
*qfn
, int index
)
3085 if (qfn
->real_names
== NULL
)
3086 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3087 qfn
->num_file_names
, const char *);
3089 if (qfn
->real_names
[index
] == NULL
)
3091 const char *dirname
= nullptr;
3093 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
3094 dirname
= qfn
->comp_dir
;
3096 gdb::unique_xmalloc_ptr
<char> fullname
;
3097 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
3099 qfn
->real_names
[index
] = fullname
.release ();
3102 return qfn
->real_names
[index
];
3106 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3108 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3109 dwarf2_per_cu_data
*dwarf_cu
3110 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3111 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3116 return compunit_primary_filetab (cust
);
3122 dwarf2_per_cu_data::free_cached_file_names ()
3124 if (per_bfd
== nullptr || !per_bfd
->using_index
|| v
.quick
== nullptr)
3127 struct quick_file_names
*file_data
= v
.quick
->file_names
;
3128 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
3130 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
3132 xfree ((void *) file_data
->real_names
[i
]);
3133 file_data
->real_names
[i
] = nullptr;
3139 dwarf2_base_index_functions::forget_cached_source_info
3140 (struct objfile
*objfile
)
3142 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3144 for (auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3145 per_cu
->free_cached_file_names ();
3148 /* Struct used to manage iterating over all CUs looking for a symbol. */
3150 struct dw2_symtab_iterator
3152 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3153 dwarf2_per_objfile
*per_objfile
;
3154 /* If set, only look for symbols that match that block. Valid values are
3155 GLOBAL_BLOCK and STATIC_BLOCK. */
3156 gdb::optional
<block_enum
> block_index
;
3157 /* The kind of symbol we're looking for. */
3159 /* The list of CUs from the index entry of the symbol,
3160 or NULL if not found. */
3162 /* The next element in VEC to look at. */
3164 /* The number of elements in VEC, or zero if there is no match. */
3166 /* Have we seen a global version of the symbol?
3167 If so we can ignore all further global instances.
3168 This is to work around gold/15646, inefficient gold-generated
3173 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3176 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3177 dwarf2_per_objfile
*per_objfile
,
3178 gdb::optional
<block_enum
> block_index
,
3179 domain_enum domain
, offset_type namei
)
3181 iter
->per_objfile
= per_objfile
;
3182 iter
->block_index
= block_index
;
3183 iter
->domain
= domain
;
3185 iter
->global_seen
= 0;
3189 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3190 /* index is NULL if OBJF_READNOW. */
3194 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3195 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3197 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3198 iter
->length
= iter
->vec
[0];
3201 /* Return the next matching CU or NULL if there are no more. */
3203 static struct dwarf2_per_cu_data
*
3204 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3206 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3208 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3210 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3211 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3212 gdb_index_symbol_kind symbol_kind
=
3213 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3214 /* Only check the symbol attributes if they're present.
3215 Indices prior to version 7 don't record them,
3216 and indices >= 7 may elide them for certain symbols
3217 (gold does this). */
3219 (per_objfile
->per_bfd
->index_table
->version
>= 7
3220 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3222 /* Don't crash on bad data. */
3223 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3225 complaint (_(".gdb_index entry has bad CU index"
3226 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3230 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3232 /* Skip if already read in. */
3233 if (per_objfile
->symtab_set_p (per_cu
))
3236 /* Check static vs global. */
3239 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3241 if (iter
->block_index
.has_value ())
3243 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3245 if (is_static
!= want_static
)
3249 /* Work around gold/15646. */
3251 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3253 if (iter
->global_seen
)
3256 iter
->global_seen
= 1;
3260 /* Only check the symbol's kind if it has one. */
3263 switch (iter
->domain
)
3266 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3267 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3268 /* Some types are also in VAR_DOMAIN. */
3269 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3273 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3277 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3281 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3297 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3303 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3304 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3307 for (int i
= 0; i
< total
; ++i
)
3309 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3311 if (!per_objfile
->symtab_set_p (per_cu
))
3314 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3315 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3318 /* This dumps minimal information about the index.
3319 It is called via "mt print objfiles".
3320 One use is to verify .gdb_index has been loaded by the
3321 gdb.dwarf2/gdb-index.exp testcase. */
3324 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3326 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3328 gdb_assert (per_objfile
->per_bfd
->using_index
);
3329 printf_filtered (".gdb_index:");
3330 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3332 printf_filtered (" version %d\n",
3333 per_objfile
->per_bfd
->index_table
->version
);
3336 printf_filtered (" faked for \"readnow\"\n");
3337 printf_filtered ("\n");
3341 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3343 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3344 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3346 for (int i
= 0; i
< total_units
; ++i
)
3348 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3350 /* We don't want to directly expand a partial CU, because if we
3351 read it with the wrong language, then assertion failures can
3352 be triggered later on. See PR symtab/23010. So, tell
3353 dw2_instantiate_symtab to skip partial CUs -- any important
3354 partial CU will be read via DW_TAG_imported_unit anyway. */
3355 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3360 dw2_expand_symtabs_matching_symbol
3361 (mapped_index_base
&index
,
3362 const lookup_name_info
&lookup_name_in
,
3363 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3364 gdb::function_view
<bool (offset_type
)> match_callback
,
3365 dwarf2_per_objfile
*per_objfile
);
3368 dw2_expand_symtabs_matching_one
3369 (dwarf2_per_cu_data
*per_cu
,
3370 dwarf2_per_objfile
*per_objfile
,
3371 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3372 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3375 dwarf2_gdb_index::expand_matching_symbols
3376 (struct objfile
*objfile
,
3377 const lookup_name_info
&name
, domain_enum domain
,
3379 symbol_compare_ftype
*ordered_compare
)
3382 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3384 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3386 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3388 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3390 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3391 auto matcher
= [&] (const char *symname
)
3393 if (ordered_compare
== nullptr)
3395 return ordered_compare (symname
, match_name
) == 0;
3398 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3399 [&] (offset_type namei
)
3401 struct dw2_symtab_iterator iter
;
3402 struct dwarf2_per_cu_data
*per_cu
;
3404 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3406 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3407 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3414 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3415 proceed assuming all symtabs have been read in. */
3419 /* Starting from a search name, return the string that finds the upper
3420 bound of all strings that start with SEARCH_NAME in a sorted name
3421 list. Returns the empty string to indicate that the upper bound is
3422 the end of the list. */
3425 make_sort_after_prefix_name (const char *search_name
)
3427 /* When looking to complete "func", we find the upper bound of all
3428 symbols that start with "func" by looking for where we'd insert
3429 the closest string that would follow "func" in lexicographical
3430 order. Usually, that's "func"-with-last-character-incremented,
3431 i.e. "fund". Mind non-ASCII characters, though. Usually those
3432 will be UTF-8 multi-byte sequences, but we can't be certain.
3433 Especially mind the 0xff character, which is a valid character in
3434 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3435 rule out compilers allowing it in identifiers. Note that
3436 conveniently, strcmp/strcasecmp are specified to compare
3437 characters interpreted as unsigned char. So what we do is treat
3438 the whole string as a base 256 number composed of a sequence of
3439 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3440 to 0, and carries 1 to the following more-significant position.
3441 If the very first character in SEARCH_NAME ends up incremented
3442 and carries/overflows, then the upper bound is the end of the
3443 list. The string after the empty string is also the empty
3446 Some examples of this operation:
3448 SEARCH_NAME => "+1" RESULT
3452 "\xff" "a" "\xff" => "\xff" "b"
3457 Then, with these symbols for example:
3463 completing "func" looks for symbols between "func" and
3464 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3465 which finds "func" and "func1", but not "fund".
3469 funcÿ (Latin1 'ÿ' [0xff])
3473 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3474 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3478 ÿÿ (Latin1 'ÿ' [0xff])
3481 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3482 the end of the list.
3484 std::string after
= search_name
;
3485 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3487 if (!after
.empty ())
3488 after
.back () = (unsigned char) after
.back () + 1;
3492 /* See declaration. */
3494 std::pair
<std::vector
<name_component
>::const_iterator
,
3495 std::vector
<name_component
>::const_iterator
>
3496 mapped_index_base::find_name_components_bounds
3497 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3498 dwarf2_per_objfile
*per_objfile
) const
3501 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3503 const char *lang_name
3504 = lookup_name_without_params
.language_lookup_name (lang
);
3506 /* Comparison function object for lower_bound that matches against a
3507 given symbol name. */
3508 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3511 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3512 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3513 return name_cmp (elem_name
, name
) < 0;
3516 /* Comparison function object for upper_bound that matches against a
3517 given symbol name. */
3518 auto lookup_compare_upper
= [&] (const char *name
,
3519 const name_component
&elem
)
3521 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3522 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3523 return name_cmp (name
, elem_name
) < 0;
3526 auto begin
= this->name_components
.begin ();
3527 auto end
= this->name_components
.end ();
3529 /* Find the lower bound. */
3532 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3535 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3538 /* Find the upper bound. */
3541 if (lookup_name_without_params
.completion_mode ())
3543 /* In completion mode, we want UPPER to point past all
3544 symbols names that have the same prefix. I.e., with
3545 these symbols, and completing "func":
3547 function << lower bound
3549 other_function << upper bound
3551 We find the upper bound by looking for the insertion
3552 point of "func"-with-last-character-incremented,
3554 std::string after
= make_sort_after_prefix_name (lang_name
);
3557 return std::lower_bound (lower
, end
, after
.c_str (),
3558 lookup_compare_lower
);
3561 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3564 return {lower
, upper
};
3567 /* See declaration. */
3570 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3572 if (!this->name_components
.empty ())
3575 this->name_components_casing
= case_sensitivity
;
3577 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3579 /* The code below only knows how to break apart components of C++
3580 symbol names (and other languages that use '::' as
3581 namespace/module separator) and Ada symbol names. */
3582 auto count
= this->symbol_name_count ();
3583 for (offset_type idx
= 0; idx
< count
; idx
++)
3585 if (this->symbol_name_slot_invalid (idx
))
3588 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3590 /* Add each name component to the name component table. */
3591 unsigned int previous_len
= 0;
3593 if (strstr (name
, "::") != nullptr)
3595 for (unsigned int current_len
= cp_find_first_component (name
);
3596 name
[current_len
] != '\0';
3597 current_len
+= cp_find_first_component (name
+ current_len
))
3599 gdb_assert (name
[current_len
] == ':');
3600 this->name_components
.push_back ({previous_len
, idx
});
3601 /* Skip the '::'. */
3603 previous_len
= current_len
;
3608 /* Handle the Ada encoded (aka mangled) form here. */
3609 for (const char *iter
= strstr (name
, "__");
3611 iter
= strstr (iter
, "__"))
3613 this->name_components
.push_back ({previous_len
, idx
});
3615 previous_len
= iter
- name
;
3619 this->name_components
.push_back ({previous_len
, idx
});
3622 /* Sort name_components elements by name. */
3623 auto name_comp_compare
= [&] (const name_component
&left
,
3624 const name_component
&right
)
3626 const char *left_qualified
3627 = this->symbol_name_at (left
.idx
, per_objfile
);
3628 const char *right_qualified
3629 = this->symbol_name_at (right
.idx
, per_objfile
);
3631 const char *left_name
= left_qualified
+ left
.name_offset
;
3632 const char *right_name
= right_qualified
+ right
.name_offset
;
3634 return name_cmp (left_name
, right_name
) < 0;
3637 std::sort (this->name_components
.begin (),
3638 this->name_components
.end (),
3642 /* Helper for dw2_expand_symtabs_matching that works with a
3643 mapped_index_base instead of the containing objfile. This is split
3644 to a separate function in order to be able to unit test the
3645 name_components matching using a mock mapped_index_base. For each
3646 symbol name that matches, calls MATCH_CALLBACK, passing it the
3647 symbol's index in the mapped_index_base symbol table. */
3650 dw2_expand_symtabs_matching_symbol
3651 (mapped_index_base
&index
,
3652 const lookup_name_info
&lookup_name_in
,
3653 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3654 gdb::function_view
<bool (offset_type
)> match_callback
,
3655 dwarf2_per_objfile
*per_objfile
)
3657 lookup_name_info lookup_name_without_params
3658 = lookup_name_in
.make_ignore_params ();
3660 /* Build the symbol name component sorted vector, if we haven't
3662 index
.build_name_components (per_objfile
);
3664 /* The same symbol may appear more than once in the range though.
3665 E.g., if we're looking for symbols that complete "w", and we have
3666 a symbol named "w1::w2", we'll find the two name components for
3667 that same symbol in the range. To be sure we only call the
3668 callback once per symbol, we first collect the symbol name
3669 indexes that matched in a temporary vector and ignore
3671 std::vector
<offset_type
> matches
;
3673 struct name_and_matcher
3675 symbol_name_matcher_ftype
*matcher
;
3678 bool operator== (const name_and_matcher
&other
) const
3680 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3684 /* A vector holding all the different symbol name matchers, for all
3686 std::vector
<name_and_matcher
> matchers
;
3688 for (int i
= 0; i
< nr_languages
; i
++)
3690 enum language lang_e
= (enum language
) i
;
3692 const language_defn
*lang
= language_def (lang_e
);
3693 symbol_name_matcher_ftype
*name_matcher
3694 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3696 name_and_matcher key
{
3698 lookup_name_without_params
.language_lookup_name (lang_e
)
3701 /* Don't insert the same comparison routine more than once.
3702 Note that we do this linear walk. This is not a problem in
3703 practice because the number of supported languages is
3705 if (std::find (matchers
.begin (), matchers
.end (), key
)
3708 matchers
.push_back (std::move (key
));
3711 = index
.find_name_components_bounds (lookup_name_without_params
,
3712 lang_e
, per_objfile
);
3714 /* Now for each symbol name in range, check to see if we have a name
3715 match, and if so, call the MATCH_CALLBACK callback. */
3717 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3719 const char *qualified
3720 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3722 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3723 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3726 matches
.push_back (bounds
.first
->idx
);
3730 std::sort (matches
.begin (), matches
.end ());
3732 /* Finally call the callback, once per match. */
3735 for (offset_type idx
: matches
)
3739 if (!match_callback (idx
))
3748 /* Above we use a type wider than idx's for 'prev', since 0 and
3749 (offset_type)-1 are both possible values. */
3750 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3757 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3759 /* A mock .gdb_index/.debug_names-like name index table, enough to
3760 exercise dw2_expand_symtabs_matching_symbol, which works with the
3761 mapped_index_base interface. Builds an index from the symbol list
3762 passed as parameter to the constructor. */
3763 class mock_mapped_index
: public mapped_index_base
3766 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3767 : m_symbol_table (symbols
)
3770 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3772 /* Return the number of names in the symbol table. */
3773 size_t symbol_name_count () const override
3775 return m_symbol_table
.size ();
3778 /* Get the name of the symbol at IDX in the symbol table. */
3779 const char *symbol_name_at
3780 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3782 return m_symbol_table
[idx
];
3786 gdb::array_view
<const char *> m_symbol_table
;
3789 /* Convenience function that converts a NULL pointer to a "<null>"
3790 string, to pass to print routines. */
3793 string_or_null (const char *str
)
3795 return str
!= NULL
? str
: "<null>";
3798 /* Check if a lookup_name_info built from
3799 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3800 index. EXPECTED_LIST is the list of expected matches, in expected
3801 matching order. If no match expected, then an empty list is
3802 specified. Returns true on success. On failure prints a warning
3803 indicating the file:line that failed, and returns false. */
3806 check_match (const char *file
, int line
,
3807 mock_mapped_index
&mock_index
,
3808 const char *name
, symbol_name_match_type match_type
,
3809 bool completion_mode
,
3810 std::initializer_list
<const char *> expected_list
,
3811 dwarf2_per_objfile
*per_objfile
)
3813 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3815 bool matched
= true;
3817 auto mismatch
= [&] (const char *expected_str
,
3820 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3821 "expected=\"%s\", got=\"%s\"\n"),
3823 (match_type
== symbol_name_match_type::FULL
3825 name
, string_or_null (expected_str
), string_or_null (got
));
3829 auto expected_it
= expected_list
.begin ();
3830 auto expected_end
= expected_list
.end ();
3832 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3834 [&] (offset_type idx
)
3836 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3837 const char *expected_str
3838 = expected_it
== expected_end
? NULL
: *expected_it
++;
3840 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3841 mismatch (expected_str
, matched_name
);
3845 const char *expected_str
3846 = expected_it
== expected_end
? NULL
: *expected_it
++;
3847 if (expected_str
!= NULL
)
3848 mismatch (expected_str
, NULL
);
3853 /* The symbols added to the mock mapped_index for testing (in
3855 static const char *test_symbols
[] = {
3864 "ns2::tmpl<int>::foo2",
3865 "(anonymous namespace)::A::B::C",
3867 /* These are used to check that the increment-last-char in the
3868 matching algorithm for completion doesn't match "t1_fund" when
3869 completing "t1_func". */
3875 /* A UTF-8 name with multi-byte sequences to make sure that
3876 cp-name-parser understands this as a single identifier ("função"
3877 is "function" in PT). */
3880 /* \377 (0xff) is Latin1 'ÿ'. */
3883 /* \377 (0xff) is Latin1 'ÿ'. */
3887 /* A name with all sorts of complications. Starts with "z" to make
3888 it easier for the completion tests below. */
3889 #define Z_SYM_NAME \
3890 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3891 "::tuple<(anonymous namespace)::ui*, " \
3892 "std::default_delete<(anonymous namespace)::ui>, void>"
3897 /* Returns true if the mapped_index_base::find_name_component_bounds
3898 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3899 in completion mode. */
3902 check_find_bounds_finds (mapped_index_base
&index
,
3903 const char *search_name
,
3904 gdb::array_view
<const char *> expected_syms
,
3905 dwarf2_per_objfile
*per_objfile
)
3907 lookup_name_info
lookup_name (search_name
,
3908 symbol_name_match_type::FULL
, true);
3910 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3914 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3915 if (distance
!= expected_syms
.size ())
3918 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3920 auto nc_elem
= bounds
.first
+ exp_elem
;
3921 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3922 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3929 /* Test the lower-level mapped_index::find_name_component_bounds
3933 test_mapped_index_find_name_component_bounds ()
3935 mock_mapped_index
mock_index (test_symbols
);
3937 mock_index
.build_name_components (NULL
/* per_objfile */);
3939 /* Test the lower-level mapped_index::find_name_component_bounds
3940 method in completion mode. */
3942 static const char *expected_syms
[] = {
3947 SELF_CHECK (check_find_bounds_finds
3948 (mock_index
, "t1_func", expected_syms
,
3949 NULL
/* per_objfile */));
3952 /* Check that the increment-last-char in the name matching algorithm
3953 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3955 static const char *expected_syms1
[] = {
3959 SELF_CHECK (check_find_bounds_finds
3960 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3962 static const char *expected_syms2
[] = {
3965 SELF_CHECK (check_find_bounds_finds
3966 (mock_index
, "\377\377", expected_syms2
,
3967 NULL
/* per_objfile */));
3971 /* Test dw2_expand_symtabs_matching_symbol. */
3974 test_dw2_expand_symtabs_matching_symbol ()
3976 mock_mapped_index
mock_index (test_symbols
);
3978 /* We let all tests run until the end even if some fails, for debug
3980 bool any_mismatch
= false;
3982 /* Create the expected symbols list (an initializer_list). Needed
3983 because lists have commas, and we need to pass them to CHECK,
3984 which is a macro. */
3985 #define EXPECT(...) { __VA_ARGS__ }
3987 /* Wrapper for check_match that passes down the current
3988 __FILE__/__LINE__. */
3989 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3990 any_mismatch |= !check_match (__FILE__, __LINE__, \
3992 NAME, MATCH_TYPE, COMPLETION_MODE, \
3993 EXPECTED_LIST, NULL)
3995 /* Identity checks. */
3996 for (const char *sym
: test_symbols
)
3998 /* Should be able to match all existing symbols. */
3999 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4002 /* Should be able to match all existing symbols with
4004 std::string with_params
= std::string (sym
) + "(int)";
4005 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4008 /* Should be able to match all existing symbols with
4009 parameters and qualifiers. */
4010 with_params
= std::string (sym
) + " ( int ) const";
4011 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4014 /* This should really find sym, but cp-name-parser.y doesn't
4015 know about lvalue/rvalue qualifiers yet. */
4016 with_params
= std::string (sym
) + " ( int ) &&";
4017 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4021 /* Check that the name matching algorithm for completion doesn't get
4022 confused with Latin1 'ÿ' / 0xff. */
4024 static const char str
[] = "\377";
4025 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4026 EXPECT ("\377", "\377\377123"));
4029 /* Check that the increment-last-char in the matching algorithm for
4030 completion doesn't match "t1_fund" when completing "t1_func". */
4032 static const char str
[] = "t1_func";
4033 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4034 EXPECT ("t1_func", "t1_func1"));
4037 /* Check that completion mode works at each prefix of the expected
4040 static const char str
[] = "function(int)";
4041 size_t len
= strlen (str
);
4044 for (size_t i
= 1; i
< len
; i
++)
4046 lookup
.assign (str
, i
);
4047 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4048 EXPECT ("function"));
4052 /* While "w" is a prefix of both components, the match function
4053 should still only be called once. */
4055 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4057 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4061 /* Same, with a "complicated" symbol. */
4063 static const char str
[] = Z_SYM_NAME
;
4064 size_t len
= strlen (str
);
4067 for (size_t i
= 1; i
< len
; i
++)
4069 lookup
.assign (str
, i
);
4070 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4071 EXPECT (Z_SYM_NAME
));
4075 /* In FULL mode, an incomplete symbol doesn't match. */
4077 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4081 /* A complete symbol with parameters matches any overload, since the
4082 index has no overload info. */
4084 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4085 EXPECT ("std::zfunction", "std::zfunction2"));
4086 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4087 EXPECT ("std::zfunction", "std::zfunction2"));
4088 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4089 EXPECT ("std::zfunction", "std::zfunction2"));
4092 /* Check that whitespace is ignored appropriately. A symbol with a
4093 template argument list. */
4095 static const char expected
[] = "ns::foo<int>";
4096 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4098 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4102 /* Check that whitespace is ignored appropriately. A symbol with a
4103 template argument list that includes a pointer. */
4105 static const char expected
[] = "ns::foo<char*>";
4106 /* Try both completion and non-completion modes. */
4107 static const bool completion_mode
[2] = {false, true};
4108 for (size_t i
= 0; i
< 2; i
++)
4110 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4111 completion_mode
[i
], EXPECT (expected
));
4112 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4113 completion_mode
[i
], EXPECT (expected
));
4115 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4116 completion_mode
[i
], EXPECT (expected
));
4117 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4118 completion_mode
[i
], EXPECT (expected
));
4123 /* Check method qualifiers are ignored. */
4124 static const char expected
[] = "ns::foo<char*>";
4125 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4126 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4127 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4128 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4129 CHECK_MATCH ("foo < char * > ( int ) const",
4130 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4131 CHECK_MATCH ("foo < char * > ( int ) &&",
4132 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4135 /* Test lookup names that don't match anything. */
4137 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4140 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4144 /* Some wild matching tests, exercising "(anonymous namespace)",
4145 which should not be confused with a parameter list. */
4147 static const char *syms
[] = {
4151 "A :: B :: C ( int )",
4156 for (const char *s
: syms
)
4158 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4159 EXPECT ("(anonymous namespace)::A::B::C"));
4164 static const char expected
[] = "ns2::tmpl<int>::foo2";
4165 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4167 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4171 SELF_CHECK (!any_mismatch
);
4180 test_mapped_index_find_name_component_bounds ();
4181 test_dw2_expand_symtabs_matching_symbol ();
4184 }} // namespace selftests::dw2_expand_symtabs_matching
4186 #endif /* GDB_SELF_TEST */
4188 /* If FILE_MATCHER is NULL or if PER_CU has
4189 dwarf2_per_cu_quick_data::MARK set (see
4190 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4191 EXPANSION_NOTIFY on it. */
4194 dw2_expand_symtabs_matching_one
4195 (dwarf2_per_cu_data
*per_cu
,
4196 dwarf2_per_objfile
*per_objfile
,
4197 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4198 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4200 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4202 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4204 compunit_symtab
*symtab
4205 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4206 gdb_assert (symtab
!= nullptr);
4208 if (expansion_notify
!= NULL
&& symtab_was_null
)
4209 return expansion_notify (symtab
);
4214 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4215 matched, to expand corresponding CUs that were marked. IDX is the
4216 index of the symbol name that matched. */
4219 dw2_expand_marked_cus
4220 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4221 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4222 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4223 block_search_flags search_flags
,
4226 offset_type vec_len
, vec_idx
;
4227 bool global_seen
= false;
4228 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4230 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4232 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4234 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4235 /* This value is only valid for index versions >= 7. */
4236 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4237 gdb_index_symbol_kind symbol_kind
=
4238 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4239 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4240 /* Only check the symbol attributes if they're present.
4241 Indices prior to version 7 don't record them,
4242 and indices >= 7 may elide them for certain symbols
4243 (gold does this). */
4246 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4248 /* Work around gold/15646. */
4251 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4259 /* Only check the symbol's kind if it has one. */
4264 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4269 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4275 case VARIABLES_DOMAIN
:
4276 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4279 case FUNCTIONS_DOMAIN
:
4280 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4284 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4287 case MODULES_DOMAIN
:
4288 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4296 /* Don't crash on bad data. */
4297 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4299 complaint (_(".gdb_index entry has bad CU index"
4300 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4304 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4305 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4313 /* If FILE_MATCHER is non-NULL, set all the
4314 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4315 that match FILE_MATCHER. */
4318 dw_expand_symtabs_matching_file_matcher
4319 (dwarf2_per_objfile
*per_objfile
,
4320 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4322 if (file_matcher
== NULL
)
4325 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4327 NULL
, xcalloc
, xfree
));
4328 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4330 NULL
, xcalloc
, xfree
));
4332 /* The rule is CUs specify all the files, including those used by
4333 any TU, so there's no need to scan TUs here. */
4335 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4339 if (per_cu
->is_debug_types
)
4341 per_cu
->v
.quick
->mark
= 0;
4343 /* We only need to look at symtabs not already expanded. */
4344 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4347 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4349 if (file_data
== NULL
)
4352 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4354 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4356 per_cu
->v
.quick
->mark
= 1;
4360 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4362 const char *this_real_name
;
4364 if (file_matcher (file_data
->file_names
[j
], false))
4366 per_cu
->v
.quick
->mark
= 1;
4370 /* Before we invoke realpath, which can get expensive when many
4371 files are involved, do a quick comparison of the basenames. */
4372 if (!basenames_may_differ
4373 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4377 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4378 if (file_matcher (this_real_name
, false))
4380 per_cu
->v
.quick
->mark
= 1;
4385 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4386 ? visited_found
.get ()
4387 : visited_not_found
.get (),
4394 dwarf2_gdb_index::expand_symtabs_matching
4395 (struct objfile
*objfile
,
4396 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4397 const lookup_name_info
*lookup_name
,
4398 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4399 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4400 block_search_flags search_flags
,
4402 enum search_domain kind
)
4404 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4406 /* index_table is NULL if OBJF_READNOW. */
4407 if (!per_objfile
->per_bfd
->index_table
)
4410 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4412 /* This invariant is documented in quick-functions.h. */
4413 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
4414 if (lookup_name
== nullptr)
4416 for (dwarf2_per_cu_data
*per_cu
4417 : all_comp_units_range (per_objfile
->per_bfd
))
4421 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4429 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4432 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4434 [&] (offset_type idx
)
4436 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4437 expansion_notify
, search_flags
, kind
))
4445 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4448 static struct compunit_symtab
*
4449 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4454 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4455 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4458 if (cust
->includes
== NULL
)
4461 for (i
= 0; cust
->includes
[i
]; ++i
)
4463 struct compunit_symtab
*s
= cust
->includes
[i
];
4465 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4473 struct compunit_symtab
*
4474 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4475 (struct objfile
*objfile
,
4476 struct bound_minimal_symbol msymbol
,
4478 struct obj_section
*section
,
4481 struct dwarf2_per_cu_data
*data
;
4482 struct compunit_symtab
*result
;
4484 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4485 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4488 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4489 data
= ((struct dwarf2_per_cu_data
*)
4490 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4495 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4496 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4497 paddress (objfile
->arch (), pc
));
4499 result
= recursively_find_pc_sect_compunit_symtab
4500 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4502 gdb_assert (result
!= NULL
);
4507 dwarf2_base_index_functions::map_symbol_filenames
4508 (struct objfile
*objfile
,
4509 gdb::function_view
<symbol_filename_ftype
> fun
,
4512 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4514 /* Use caches to ensure we only call FUN once for each filename. */
4515 filename_seen_cache filenames_cache
;
4516 std::unordered_set
<quick_file_names
*> qfn_cache
;
4518 /* The rule is CUs specify all the files, including those used by any TU,
4519 so there's no need to scan TUs here. We can ignore file names coming
4520 from already-expanded CUs. It is possible that an expanded CU might
4521 reuse the file names data from a currently unexpanded CU, in this
4522 case we don't want to report the files from the unexpanded CU. */
4524 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4526 if (!per_cu
->is_debug_types
4527 && per_objfile
->symtab_set_p (per_cu
.get ()))
4529 if (per_cu
->v
.quick
->file_names
!= nullptr)
4530 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4534 for (dwarf2_per_cu_data
*per_cu
4535 : all_comp_units_range (per_objfile
->per_bfd
))
4537 /* We only need to look at symtabs not already expanded. */
4538 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
4541 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4542 if (file_data
== nullptr
4543 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4546 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4548 const char *filename
= file_data
->file_names
[j
];
4549 const char *key
= filename
;
4550 const char *fullname
= nullptr;
4554 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
4558 if (!filenames_cache
.seen (key
))
4559 fun (filename
, fullname
);
4565 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4570 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4573 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4575 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4577 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4579 /* Is this already expanded? */
4580 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4583 /* It has not yet been expanded. */
4590 /* DWARF-5 debug_names reader. */
4592 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4593 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4595 /* A helper function that reads the .debug_names section in SECTION
4596 and fills in MAP. FILENAME is the name of the file containing the
4597 section; it is used for error reporting.
4599 Returns true if all went well, false otherwise. */
4602 read_debug_names_from_section (struct objfile
*objfile
,
4603 const char *filename
,
4604 struct dwarf2_section_info
*section
,
4605 mapped_debug_names
&map
)
4607 if (section
->empty ())
4610 /* Older elfutils strip versions could keep the section in the main
4611 executable while splitting it for the separate debug info file. */
4612 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4615 section
->read (objfile
);
4617 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4619 const gdb_byte
*addr
= section
->buffer
;
4621 bfd
*const abfd
= section
->get_bfd_owner ();
4623 unsigned int bytes_read
;
4624 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4627 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4628 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4629 if (bytes_read
+ length
!= section
->size
)
4631 /* There may be multiple per-CU indices. */
4632 warning (_("Section .debug_names in %s length %s does not match "
4633 "section length %s, ignoring .debug_names."),
4634 filename
, plongest (bytes_read
+ length
),
4635 pulongest (section
->size
));
4639 /* The version number. */
4640 uint16_t version
= read_2_bytes (abfd
, addr
);
4644 warning (_("Section .debug_names in %s has unsupported version %d, "
4645 "ignoring .debug_names."),
4651 uint16_t padding
= read_2_bytes (abfd
, addr
);
4655 warning (_("Section .debug_names in %s has unsupported padding %d, "
4656 "ignoring .debug_names."),
4661 /* comp_unit_count - The number of CUs in the CU list. */
4662 map
.cu_count
= read_4_bytes (abfd
, addr
);
4665 /* local_type_unit_count - The number of TUs in the local TU
4667 map
.tu_count
= read_4_bytes (abfd
, addr
);
4670 /* foreign_type_unit_count - The number of TUs in the foreign TU
4672 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4674 if (foreign_tu_count
!= 0)
4676 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4677 "ignoring .debug_names."),
4678 filename
, static_cast<unsigned long> (foreign_tu_count
));
4682 /* bucket_count - The number of hash buckets in the hash lookup
4684 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4687 /* name_count - The number of unique names in the index. */
4688 map
.name_count
= read_4_bytes (abfd
, addr
);
4691 /* abbrev_table_size - The size in bytes of the abbreviations
4693 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4696 /* augmentation_string_size - The size in bytes of the augmentation
4697 string. This value is rounded up to a multiple of 4. */
4698 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4700 map
.augmentation_is_gdb
= ((augmentation_string_size
4701 == sizeof (dwarf5_augmentation
))
4702 && memcmp (addr
, dwarf5_augmentation
,
4703 sizeof (dwarf5_augmentation
)) == 0);
4704 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4705 addr
+= augmentation_string_size
;
4708 map
.cu_table_reordered
= addr
;
4709 addr
+= map
.cu_count
* map
.offset_size
;
4711 /* List of Local TUs */
4712 map
.tu_table_reordered
= addr
;
4713 addr
+= map
.tu_count
* map
.offset_size
;
4715 /* Hash Lookup Table */
4716 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4717 addr
+= map
.bucket_count
* 4;
4718 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4719 addr
+= map
.name_count
* 4;
4722 map
.name_table_string_offs_reordered
= addr
;
4723 addr
+= map
.name_count
* map
.offset_size
;
4724 map
.name_table_entry_offs_reordered
= addr
;
4725 addr
+= map
.name_count
* map
.offset_size
;
4727 const gdb_byte
*abbrev_table_start
= addr
;
4730 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4735 const auto insertpair
4736 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4737 if (!insertpair
.second
)
4739 warning (_("Section .debug_names in %s has duplicate index %s, "
4740 "ignoring .debug_names."),
4741 filename
, pulongest (index_num
));
4744 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4745 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4750 mapped_debug_names::index_val::attr attr
;
4751 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4753 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4755 if (attr
.form
== DW_FORM_implicit_const
)
4757 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4761 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4763 indexval
.attr_vec
.push_back (std::move (attr
));
4766 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4768 warning (_("Section .debug_names in %s has abbreviation_table "
4769 "of size %s vs. written as %u, ignoring .debug_names."),
4770 filename
, plongest (addr
- abbrev_table_start
),
4774 map
.entry_pool
= addr
;
4779 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4783 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4784 const mapped_debug_names
&map
,
4785 dwarf2_section_info
§ion
,
4788 if (!map
.augmentation_is_gdb
)
4790 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4792 sect_offset sect_off
4793 = (sect_offset
) (extract_unsigned_integer
4794 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4796 map
.dwarf5_byte_order
));
4797 /* We don't know the length of the CU, because the CU list in a
4798 .debug_names index can be incomplete, so we can't use the start
4799 of the next CU as end of this CU. We create the CUs here with
4800 length 0, and in cutu_reader::cutu_reader we'll fill in the
4802 dwarf2_per_cu_data_up per_cu
4803 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4805 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4810 sect_offset sect_off_prev
;
4811 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4813 sect_offset sect_off_next
;
4814 if (i
< map
.cu_count
)
4817 = (sect_offset
) (extract_unsigned_integer
4818 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4820 map
.dwarf5_byte_order
));
4823 sect_off_next
= (sect_offset
) section
.size
;
4826 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4827 dwarf2_per_cu_data_up per_cu
4828 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4829 sect_off_prev
, length
);
4830 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4832 sect_off_prev
= sect_off_next
;
4836 /* Read the CU list from the mapped index, and use it to create all
4837 the CU objects for this dwarf2_per_objfile. */
4840 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4841 const mapped_debug_names
&map
,
4842 const mapped_debug_names
&dwz_map
)
4844 gdb_assert (per_bfd
->all_comp_units
.empty ());
4845 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4847 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4848 false /* is_dwz */);
4850 if (dwz_map
.cu_count
== 0)
4853 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4854 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4858 /* Read .debug_names. If everything went ok, initialize the "quick"
4859 elements of all the CUs and return true. Otherwise, return false. */
4862 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4864 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4865 mapped_debug_names dwz_map
;
4866 struct objfile
*objfile
= per_objfile
->objfile
;
4867 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4869 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4870 &per_bfd
->debug_names
, *map
))
4873 /* Don't use the index if it's empty. */
4874 if (map
->name_count
== 0)
4877 /* If there is a .dwz file, read it so we can get its CU list as
4879 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4882 if (!read_debug_names_from_section (objfile
,
4883 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4884 &dwz
->debug_names
, dwz_map
))
4886 warning (_("could not read '.debug_names' section from %s; skipping"),
4887 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4892 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4894 if (map
->tu_count
!= 0)
4896 /* We can only handle a single .debug_types when we have an
4898 if (per_bfd
->types
.size () != 1)
4901 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4903 create_signatured_type_table_from_debug_names
4904 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4907 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4909 per_bfd
->debug_names_table
= std::move (map
);
4910 per_bfd
->using_index
= 1;
4911 per_bfd
->quick_file_names_table
=
4912 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4917 /* Type used to manage iterating over all CUs looking for a symbol for
4920 class dw2_debug_names_iterator
4923 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4924 block_search_flags block_index
,
4926 const char *name
, dwarf2_per_objfile
*per_objfile
)
4927 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4928 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4929 m_per_objfile (per_objfile
)
4932 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4933 search_domain search
, uint32_t namei
,
4934 dwarf2_per_objfile
*per_objfile
,
4935 domain_enum domain
= UNDEF_DOMAIN
)
4939 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4940 m_per_objfile (per_objfile
)
4943 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4944 block_search_flags block_index
, domain_enum domain
,
4945 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4946 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4947 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4948 m_per_objfile (per_objfile
)
4951 /* Return the next matching CU or NULL if there are no more. */
4952 dwarf2_per_cu_data
*next ();
4955 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4957 dwarf2_per_objfile
*per_objfile
);
4958 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4960 dwarf2_per_objfile
*per_objfile
);
4962 /* The internalized form of .debug_names. */
4963 const mapped_debug_names
&m_map
;
4965 /* Restrict the search to these blocks. */
4966 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4967 | SEARCH_STATIC_BLOCK
);
4969 /* The kind of symbol we're looking for. */
4970 const domain_enum m_domain
= UNDEF_DOMAIN
;
4971 const search_domain m_search
= ALL_DOMAIN
;
4973 /* The list of CUs from the index entry of the symbol, or NULL if
4975 const gdb_byte
*m_addr
;
4977 dwarf2_per_objfile
*m_per_objfile
;
4981 mapped_debug_names::namei_to_name
4982 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4984 const ULONGEST namei_string_offs
4985 = extract_unsigned_integer ((name_table_string_offs_reordered
4986 + namei
* offset_size
),
4989 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4992 /* Find a slot in .debug_names for the object named NAME. If NAME is
4993 found, return pointer to its pool data. If NAME cannot be found,
4997 dw2_debug_names_iterator::find_vec_in_debug_names
4998 (const mapped_debug_names
&map
, const char *name
,
4999 dwarf2_per_objfile
*per_objfile
)
5001 int (*cmp
) (const char *, const char *);
5003 gdb::unique_xmalloc_ptr
<char> without_params
;
5004 if (current_language
->la_language
== language_cplus
5005 || current_language
->la_language
== language_fortran
5006 || current_language
->la_language
== language_d
)
5008 /* NAME is already canonical. Drop any qualifiers as
5009 .debug_names does not contain any. */
5011 if (strchr (name
, '(') != NULL
)
5013 without_params
= cp_remove_params (name
);
5014 if (without_params
!= NULL
)
5015 name
= without_params
.get ();
5019 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5021 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5023 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5024 (map
.bucket_table_reordered
5025 + (full_hash
% map
.bucket_count
)), 4,
5026 map
.dwarf5_byte_order
);
5030 if (namei
>= map
.name_count
)
5032 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5034 namei
, map
.name_count
,
5035 objfile_name (per_objfile
->objfile
));
5041 const uint32_t namei_full_hash
5042 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5043 (map
.hash_table_reordered
+ namei
), 4,
5044 map
.dwarf5_byte_order
);
5045 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5048 if (full_hash
== namei_full_hash
)
5050 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5052 #if 0 /* An expensive sanity check. */
5053 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5055 complaint (_("Wrong .debug_names hash for string at index %u "
5057 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5062 if (cmp (namei_string
, name
) == 0)
5064 const ULONGEST namei_entry_offs
5065 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5066 + namei
* map
.offset_size
),
5067 map
.offset_size
, map
.dwarf5_byte_order
);
5068 return map
.entry_pool
+ namei_entry_offs
;
5073 if (namei
>= map
.name_count
)
5079 dw2_debug_names_iterator::find_vec_in_debug_names
5080 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5082 if (namei
>= map
.name_count
)
5084 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5086 namei
, map
.name_count
,
5087 objfile_name (per_objfile
->objfile
));
5091 const ULONGEST namei_entry_offs
5092 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5093 + namei
* map
.offset_size
),
5094 map
.offset_size
, map
.dwarf5_byte_order
);
5095 return map
.entry_pool
+ namei_entry_offs
;
5098 /* See dw2_debug_names_iterator. */
5100 dwarf2_per_cu_data
*
5101 dw2_debug_names_iterator::next ()
5106 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5107 struct objfile
*objfile
= m_per_objfile
->objfile
;
5108 bfd
*const abfd
= objfile
->obfd
;
5112 unsigned int bytes_read
;
5113 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5114 m_addr
+= bytes_read
;
5118 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5119 if (indexval_it
== m_map
.abbrev_map
.cend ())
5121 complaint (_("Wrong .debug_names undefined abbrev code %s "
5123 pulongest (abbrev
), objfile_name (objfile
));
5126 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5127 enum class symbol_linkage
{
5131 } symbol_linkage_
= symbol_linkage::unknown
;
5132 dwarf2_per_cu_data
*per_cu
= NULL
;
5133 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5138 case DW_FORM_implicit_const
:
5139 ull
= attr
.implicit_const
;
5141 case DW_FORM_flag_present
:
5145 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5146 m_addr
+= bytes_read
;
5149 ull
= read_4_bytes (abfd
, m_addr
);
5153 ull
= read_8_bytes (abfd
, m_addr
);
5156 case DW_FORM_ref_sig8
:
5157 ull
= read_8_bytes (abfd
, m_addr
);
5161 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5162 dwarf_form_name (attr
.form
),
5163 objfile_name (objfile
));
5166 switch (attr
.dw_idx
)
5168 case DW_IDX_compile_unit
:
5169 /* Don't crash on bad data. */
5170 if (ull
>= per_bfd
->all_comp_units
.size ())
5172 complaint (_(".debug_names entry has bad CU index %s"
5175 objfile_name (objfile
));
5178 per_cu
= per_bfd
->get_cu (ull
);
5180 case DW_IDX_type_unit
:
5181 /* Don't crash on bad data. */
5182 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5184 complaint (_(".debug_names entry has bad TU index %s"
5187 objfile_name (objfile
));
5190 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5192 case DW_IDX_die_offset
:
5193 /* In a per-CU index (as opposed to a per-module index), index
5194 entries without CU attribute implicitly refer to the single CU. */
5196 per_cu
= per_bfd
->get_cu (0);
5198 case DW_IDX_GNU_internal
:
5199 if (!m_map
.augmentation_is_gdb
)
5201 symbol_linkage_
= symbol_linkage::static_
;
5203 case DW_IDX_GNU_external
:
5204 if (!m_map
.augmentation_is_gdb
)
5206 symbol_linkage_
= symbol_linkage::extern_
;
5211 /* Skip if already read in. */
5212 if (m_per_objfile
->symtab_set_p (per_cu
))
5215 /* Check static vs global. */
5216 if (symbol_linkage_
!= symbol_linkage::unknown
)
5218 if (symbol_linkage_
== symbol_linkage::static_
)
5220 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5225 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5230 /* Match dw2_symtab_iter_next, symbol_kind
5231 and debug_names::psymbol_tag. */
5235 switch (indexval
.dwarf_tag
)
5237 case DW_TAG_variable
:
5238 case DW_TAG_subprogram
:
5239 /* Some types are also in VAR_DOMAIN. */
5240 case DW_TAG_typedef
:
5241 case DW_TAG_structure_type
:
5248 switch (indexval
.dwarf_tag
)
5250 case DW_TAG_typedef
:
5251 case DW_TAG_structure_type
:
5258 switch (indexval
.dwarf_tag
)
5261 case DW_TAG_variable
:
5268 switch (indexval
.dwarf_tag
)
5280 /* Match dw2_expand_symtabs_matching, symbol_kind and
5281 debug_names::psymbol_tag. */
5284 case VARIABLES_DOMAIN
:
5285 switch (indexval
.dwarf_tag
)
5287 case DW_TAG_variable
:
5293 case FUNCTIONS_DOMAIN
:
5294 switch (indexval
.dwarf_tag
)
5296 case DW_TAG_subprogram
:
5303 switch (indexval
.dwarf_tag
)
5305 case DW_TAG_typedef
:
5306 case DW_TAG_structure_type
:
5312 case MODULES_DOMAIN
:
5313 switch (indexval
.dwarf_tag
)
5327 /* This dumps minimal information about .debug_names. It is called
5328 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5329 uses this to verify that .debug_names has been loaded. */
5332 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5334 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5336 gdb_assert (per_objfile
->per_bfd
->using_index
);
5337 printf_filtered (".debug_names:");
5338 if (per_objfile
->per_bfd
->debug_names_table
)
5339 printf_filtered (" exists\n");
5341 printf_filtered (" faked for \"readnow\"\n");
5342 printf_filtered ("\n");
5346 dwarf2_debug_names_index::expand_matching_symbols
5347 (struct objfile
*objfile
,
5348 const lookup_name_info
&name
, domain_enum domain
,
5350 symbol_compare_ftype
*ordered_compare
)
5352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5354 /* debug_names_table is NULL if OBJF_READNOW. */
5355 if (!per_objfile
->per_bfd
->debug_names_table
)
5358 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5359 const block_search_flags block_flags
5360 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5362 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5363 auto matcher
= [&] (const char *symname
)
5365 if (ordered_compare
== nullptr)
5367 return ordered_compare (symname
, match_name
) == 0;
5370 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5371 [&] (offset_type namei
)
5373 /* The name was matched, now expand corresponding CUs that were
5375 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5378 struct dwarf2_per_cu_data
*per_cu
;
5379 while ((per_cu
= iter
.next ()) != NULL
)
5380 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5387 dwarf2_debug_names_index::expand_symtabs_matching
5388 (struct objfile
*objfile
,
5389 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5390 const lookup_name_info
*lookup_name
,
5391 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5392 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5393 block_search_flags search_flags
,
5395 enum search_domain kind
)
5397 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5399 /* debug_names_table is NULL if OBJF_READNOW. */
5400 if (!per_objfile
->per_bfd
->debug_names_table
)
5403 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5405 /* This invariant is documented in quick-functions.h. */
5406 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
5407 if (lookup_name
== nullptr)
5409 for (dwarf2_per_cu_data
*per_cu
5410 : all_comp_units_range (per_objfile
->per_bfd
))
5414 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5422 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5425 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5427 [&] (offset_type namei
)
5429 /* The name was matched, now expand corresponding CUs that were
5431 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5433 struct dwarf2_per_cu_data
*per_cu
;
5434 while ((per_cu
= iter
.next ()) != NULL
)
5435 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5445 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5446 to either a dwarf2_per_bfd or dwz_file object. */
5448 template <typename T
>
5449 static gdb::array_view
<const gdb_byte
>
5450 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5452 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5454 if (section
->empty ())
5457 /* Older elfutils strip versions could keep the section in the main
5458 executable while splitting it for the separate debug info file. */
5459 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5462 section
->read (obj
);
5464 /* dwarf2_section_info::size is a bfd_size_type, while
5465 gdb::array_view works with size_t. On 32-bit hosts, with
5466 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5467 is 32-bit. So we need an explicit narrowing conversion here.
5468 This is fine, because it's impossible to allocate or mmap an
5469 array/buffer larger than what size_t can represent. */
5470 return gdb::make_array_view (section
->buffer
, section
->size
);
5473 /* Lookup the index cache for the contents of the index associated to
5476 static gdb::array_view
<const gdb_byte
>
5477 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5479 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5480 if (build_id
== nullptr)
5483 return global_index_cache
.lookup_gdb_index (build_id
,
5484 &dwarf2_per_bfd
->index_cache_res
);
5487 /* Same as the above, but for DWZ. */
5489 static gdb::array_view
<const gdb_byte
>
5490 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5492 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5493 if (build_id
== nullptr)
5496 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5499 /* See dwarf2/public.h. */
5502 dwarf2_initialize_objfile (struct objfile
*objfile
)
5504 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5505 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5507 dwarf_read_debug_printf ("called");
5509 /* If we're about to read full symbols, don't bother with the
5510 indices. In this case we also don't care if some other debug
5511 format is making psymtabs, because they are all about to be
5513 if ((objfile
->flags
& OBJF_READNOW
))
5515 dwarf_read_debug_printf ("readnow requested");
5517 /* When using READNOW, the using_index flag (set below) indicates that
5518 PER_BFD was already initialized, when we loaded some other objfile. */
5519 if (per_bfd
->using_index
)
5521 dwarf_read_debug_printf ("using_index already set");
5522 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5526 per_bfd
->using_index
= 1;
5527 create_all_comp_units (per_objfile
);
5528 per_bfd
->quick_file_names_table
5529 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5531 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5533 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5535 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5536 struct dwarf2_per_cu_quick_data
);
5539 /* Arrange for gdb to see the "quick" functions. However, these
5540 functions will be no-ops because we will have expanded all
5542 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5546 /* Was a debug names index already read when we processed an objfile sharing
5548 if (per_bfd
->debug_names_table
!= nullptr)
5550 dwarf_read_debug_printf ("re-using shared debug names table");
5551 objfile
->qf
.push_front (make_dwarf_debug_names ());
5555 /* Was a GDB index already read when we processed an objfile sharing
5557 if (per_bfd
->index_table
!= nullptr)
5559 dwarf_read_debug_printf ("re-using shared index table");
5560 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5564 /* There might already be partial symtabs built for this BFD. This happens
5565 when loading the same binary twice with the index-cache enabled. If so,
5566 don't try to read an index. The objfile / per_objfile initialization will
5567 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5569 if (per_bfd
->partial_symtabs
!= nullptr)
5571 dwarf_read_debug_printf ("re-using shared partial symtabs");
5572 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5576 if (dwarf2_read_debug_names (per_objfile
))
5578 dwarf_read_debug_printf ("found debug names");
5579 objfile
->qf
.push_front (make_dwarf_debug_names ());
5583 if (dwarf2_read_gdb_index (per_objfile
,
5584 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5585 get_gdb_index_contents_from_section
<dwz_file
>))
5587 dwarf_read_debug_printf ("found gdb index from file");
5588 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5592 /* ... otherwise, try to find the index in the index cache. */
5593 if (dwarf2_read_gdb_index (per_objfile
,
5594 get_gdb_index_contents_from_cache
,
5595 get_gdb_index_contents_from_cache_dwz
))
5597 dwarf_read_debug_printf ("found gdb index from cache");
5598 global_index_cache
.hit ();
5599 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5603 global_index_cache
.miss ();
5604 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5609 /* Build a partial symbol table. */
5612 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5614 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5615 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5617 if (per_bfd
->partial_symtabs
!= nullptr)
5619 /* Partial symbols were already read, so now we can simply
5623 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5624 objfile
->qf
.emplace_front (psf
);
5627 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5633 psf
= new psymbol_functions
;
5634 objfile
->qf
.emplace_front (psf
);
5636 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5637 = psf
->get_partial_symtabs ();
5639 /* Set the local reference to partial symtabs, so that we don't try
5640 to read them again if reading another objfile with the same BFD.
5641 If we can't in fact share, this won't make a difference anyway as
5642 the dwarf2_per_bfd object won't be shared. */
5643 per_bfd
->partial_symtabs
= partial_symtabs
;
5647 /* This isn't really ideal: all the data we allocate on the
5648 objfile's obstack is still uselessly kept around. However,
5649 freeing it seems unsafe. */
5650 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5651 dwarf2_build_psymtabs_hard (per_objfile
);
5654 /* (maybe) store an index in the cache. */
5655 global_index_cache
.store (per_objfile
);
5657 catch (const gdb_exception_error
&except
)
5659 exception_print (gdb_stderr
, except
);
5663 /* Find the base address of the compilation unit for range lists and
5664 location lists. It will normally be specified by DW_AT_low_pc.
5665 In DWARF-3 draft 4, the base address could be overridden by
5666 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5667 compilation units with discontinuous ranges. */
5670 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5672 struct attribute
*attr
;
5674 cu
->base_address
.reset ();
5676 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5677 if (attr
!= nullptr)
5678 cu
->base_address
= attr
->as_address ();
5681 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5682 if (attr
!= nullptr)
5683 cu
->base_address
= attr
->as_address ();
5687 /* Helper function that returns the proper abbrev section for
5690 static struct dwarf2_section_info
*
5691 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5693 struct dwarf2_section_info
*abbrev
;
5694 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5696 if (this_cu
->is_dwz
)
5697 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5699 abbrev
= &per_bfd
->abbrev
;
5704 /* Fetch the abbreviation table offset from a comp or type unit header. */
5707 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5708 struct dwarf2_section_info
*section
,
5709 sect_offset sect_off
)
5711 bfd
*abfd
= section
->get_bfd_owner ();
5712 const gdb_byte
*info_ptr
;
5713 unsigned int initial_length_size
, offset_size
;
5716 section
->read (per_objfile
->objfile
);
5717 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5718 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5719 offset_size
= initial_length_size
== 4 ? 4 : 8;
5720 info_ptr
+= initial_length_size
;
5722 version
= read_2_bytes (abfd
, info_ptr
);
5726 /* Skip unit type and address size. */
5730 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5733 /* A partial symtab that is used only for include files. */
5734 struct dwarf2_include_psymtab
: public partial_symtab
5736 dwarf2_include_psymtab (const char *filename
,
5737 psymtab_storage
*partial_symtabs
,
5738 objfile_per_bfd_storage
*objfile_per_bfd
)
5739 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5743 void read_symtab (struct objfile
*objfile
) override
5745 /* It's an include file, no symbols to read for it.
5746 Everything is in the includer symtab. */
5748 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5749 expansion of the includer psymtab. We use the dependencies[0] field to
5750 model the includer. But if we go the regular route of calling
5751 expand_psymtab here, and having expand_psymtab call expand_dependencies
5752 to expand the includer, we'll only use expand_psymtab on the includer
5753 (making it a non-toplevel psymtab), while if we expand the includer via
5754 another path, we'll use read_symtab (making it a toplevel psymtab).
5755 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5756 psymtab, and trigger read_symtab on the includer here directly. */
5757 includer ()->read_symtab (objfile
);
5760 void expand_psymtab (struct objfile
*objfile
) override
5762 /* This is not called by read_symtab, and should not be called by any
5763 expand_dependencies. */
5767 bool readin_p (struct objfile
*objfile
) const override
5769 return includer ()->readin_p (objfile
);
5772 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5774 compunit_symtab
*cust
= includer ()->get_compunit_symtab (objfile
);
5775 while (cust
!= nullptr && cust
->user
!= nullptr)
5781 partial_symtab
*includer () const
5783 /* An include psymtab has exactly one dependency: the psymtab that
5785 gdb_assert (this->number_of_dependencies
== 1);
5786 return this->dependencies
[0];
5790 /* Allocate a new partial symtab for file named NAME and mark this new
5791 partial symtab as being an include of PST. */
5794 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5796 dwarf2_psymtab
*pst
,
5797 psymtab_storage
*partial_symtabs
,
5798 objfile_per_bfd_storage
*objfile_per_bfd
)
5800 dwarf2_include_psymtab
*subpst
5801 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5803 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5804 subpst
->dirname
= pst
->dirname
;
5806 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5807 subpst
->dependencies
[0] = pst
;
5808 subpst
->number_of_dependencies
= 1;
5811 /* Read the Line Number Program data and extract the list of files
5812 included by the source file represented by PST. Build an include
5813 partial symtab for each of these included files. */
5816 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5817 struct die_info
*die
,
5818 const file_and_directory
&fnd
,
5819 dwarf2_psymtab
*pst
)
5822 struct attribute
*attr
;
5824 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5825 if (attr
!= nullptr && attr
->form_is_unsigned ())
5826 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5828 return; /* No linetable, so no includes. */
5830 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5831 that we pass in the raw text_low here; that is ok because we're
5832 only decoding the line table to make include partial symtabs, and
5833 so the addresses aren't really used. */
5834 dwarf_decode_lines (lh
.get (), fnd
, cu
, pst
,
5835 pst
->raw_text_low (), 1);
5839 hash_signatured_type (const void *item
)
5841 const struct signatured_type
*sig_type
5842 = (const struct signatured_type
*) item
;
5844 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5845 return sig_type
->signature
;
5849 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5851 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5852 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5854 return lhs
->signature
== rhs
->signature
;
5857 /* Allocate a hash table for signatured types. */
5860 allocate_signatured_type_table ()
5862 return htab_up (htab_create_alloc (41,
5863 hash_signatured_type
,
5865 NULL
, xcalloc
, xfree
));
5868 /* A helper for create_debug_types_hash_table. Read types from SECTION
5869 and fill them into TYPES_HTAB. It will process only type units,
5870 therefore DW_UT_type. */
5873 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5874 struct dwo_file
*dwo_file
,
5875 dwarf2_section_info
*section
, htab_up
&types_htab
,
5876 rcuh_kind section_kind
)
5878 struct objfile
*objfile
= per_objfile
->objfile
;
5879 struct dwarf2_section_info
*abbrev_section
;
5881 const gdb_byte
*info_ptr
, *end_ptr
;
5883 abbrev_section
= &dwo_file
->sections
.abbrev
;
5885 dwarf_read_debug_printf ("Reading %s for %s",
5886 section
->get_name (),
5887 abbrev_section
->get_file_name ());
5889 section
->read (objfile
);
5890 info_ptr
= section
->buffer
;
5892 if (info_ptr
== NULL
)
5895 /* We can't set abfd until now because the section may be empty or
5896 not present, in which case the bfd is unknown. */
5897 abfd
= section
->get_bfd_owner ();
5899 /* We don't use cutu_reader here because we don't need to read
5900 any dies: the signature is in the header. */
5902 end_ptr
= info_ptr
+ section
->size
;
5903 while (info_ptr
< end_ptr
)
5905 signatured_type_up sig_type
;
5906 struct dwo_unit
*dwo_tu
;
5908 const gdb_byte
*ptr
= info_ptr
;
5909 struct comp_unit_head header
;
5910 unsigned int length
;
5912 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5914 /* Initialize it due to a false compiler warning. */
5915 header
.signature
= -1;
5916 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5918 /* We need to read the type's signature in order to build the hash
5919 table, but we don't need anything else just yet. */
5921 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5922 abbrev_section
, ptr
, section_kind
);
5924 length
= header
.get_length ();
5926 /* Skip dummy type units. */
5927 if (ptr
>= info_ptr
+ length
5928 || peek_abbrev_code (abfd
, ptr
) == 0
5929 || (header
.unit_type
!= DW_UT_type
5930 && header
.unit_type
!= DW_UT_split_type
))
5936 if (types_htab
== NULL
)
5937 types_htab
= allocate_dwo_unit_table ();
5939 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5940 dwo_tu
->dwo_file
= dwo_file
;
5941 dwo_tu
->signature
= header
.signature
;
5942 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5943 dwo_tu
->section
= section
;
5944 dwo_tu
->sect_off
= sect_off
;
5945 dwo_tu
->length
= length
;
5947 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5948 gdb_assert (slot
!= NULL
);
5950 complaint (_("debug type entry at offset %s is duplicate to"
5951 " the entry at offset %s, signature %s"),
5952 sect_offset_str (sect_off
),
5953 sect_offset_str (dwo_tu
->sect_off
),
5954 hex_string (header
.signature
));
5957 dwarf_read_debug_printf_v (" offset %s, signature %s",
5958 sect_offset_str (sect_off
),
5959 hex_string (header
.signature
));
5965 /* Create the hash table of all entries in the .debug_types
5966 (or .debug_types.dwo) section(s).
5967 DWO_FILE is a pointer to the DWO file object.
5969 The result is a pointer to the hash table or NULL if there are no types.
5971 Note: This function processes DWO files only, not DWP files. */
5974 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5975 struct dwo_file
*dwo_file
,
5976 gdb::array_view
<dwarf2_section_info
> type_sections
,
5977 htab_up
&types_htab
)
5979 for (dwarf2_section_info
§ion
: type_sections
)
5980 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5984 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5985 If SLOT is non-NULL, it is the entry to use in the hash table.
5986 Otherwise we find one. */
5988 static struct signatured_type
*
5989 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5991 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5992 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5993 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5995 signatured_type_up sig_type_holder
5996 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
5997 signatured_type
*sig_type
= sig_type_holder
.get ();
5999 per_objfile
->per_bfd
->all_comp_units
.emplace_back
6000 (sig_type_holder
.release ());
6001 if (per_objfile
->per_bfd
->using_index
)
6004 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6005 struct dwarf2_per_cu_quick_data
);
6010 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6013 gdb_assert (*slot
== NULL
);
6015 /* The rest of sig_type must be filled in by the caller. */
6019 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6020 Fill in SIG_ENTRY with DWO_ENTRY. */
6023 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6024 struct signatured_type
*sig_entry
,
6025 struct dwo_unit
*dwo_entry
)
6027 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6029 /* Make sure we're not clobbering something we don't expect to. */
6030 gdb_assert (! sig_entry
->queued
);
6031 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6032 if (per_bfd
->using_index
)
6034 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6035 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6038 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6039 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6040 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6041 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6042 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6044 sig_entry
->section
= dwo_entry
->section
;
6045 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6046 sig_entry
->length
= dwo_entry
->length
;
6047 sig_entry
->reading_dwo_directly
= 1;
6048 sig_entry
->per_bfd
= per_bfd
;
6049 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6050 sig_entry
->dwo_unit
= dwo_entry
;
6053 /* Subroutine of lookup_signatured_type.
6054 If we haven't read the TU yet, create the signatured_type data structure
6055 for a TU to be read in directly from a DWO file, bypassing the stub.
6056 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6057 using .gdb_index, then when reading a CU we want to stay in the DWO file
6058 containing that CU. Otherwise we could end up reading several other DWO
6059 files (due to comdat folding) to process the transitive closure of all the
6060 mentioned TUs, and that can be slow. The current DWO file will have every
6061 type signature that it needs.
6062 We only do this for .gdb_index because in the psymtab case we already have
6063 to read all the DWOs to build the type unit groups. */
6065 static struct signatured_type
*
6066 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6068 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6069 struct dwo_file
*dwo_file
;
6070 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6073 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6075 /* If TU skeletons have been removed then we may not have read in any
6077 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6078 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6080 /* We only ever need to read in one copy of a signatured type.
6081 Use the global signatured_types array to do our own comdat-folding
6082 of types. If this is the first time we're reading this TU, and
6083 the TU has an entry in .gdb_index, replace the recorded data from
6084 .gdb_index with this TU. */
6086 signatured_type
find_sig_entry (sig
);
6087 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6088 &find_sig_entry
, INSERT
);
6089 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6091 /* We can get here with the TU already read, *or* in the process of being
6092 read. Don't reassign the global entry to point to this DWO if that's
6093 the case. Also note that if the TU is already being read, it may not
6094 have come from a DWO, the program may be a mix of Fission-compiled
6095 code and non-Fission-compiled code. */
6097 /* Have we already tried to read this TU?
6098 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6099 needn't exist in the global table yet). */
6100 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6103 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6104 dwo_unit of the TU itself. */
6105 dwo_file
= cu
->dwo_unit
->dwo_file
;
6107 /* Ok, this is the first time we're reading this TU. */
6108 if (dwo_file
->tus
== NULL
)
6110 find_dwo_entry
.signature
= sig
;
6111 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6113 if (dwo_entry
== NULL
)
6116 /* If the global table doesn't have an entry for this TU, add one. */
6117 if (sig_entry
== NULL
)
6118 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6120 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6121 sig_entry
->tu_read
= 1;
6125 /* Subroutine of lookup_signatured_type.
6126 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6127 then try the DWP file. If the TU stub (skeleton) has been removed then
6128 it won't be in .gdb_index. */
6130 static struct signatured_type
*
6131 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6133 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6134 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6135 struct dwo_unit
*dwo_entry
;
6138 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6139 gdb_assert (dwp_file
!= NULL
);
6141 /* If TU skeletons have been removed then we may not have read in any
6143 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6144 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6146 signatured_type
find_sig_entry (sig
);
6147 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6148 &find_sig_entry
, INSERT
);
6149 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6151 /* Have we already tried to read this TU?
6152 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6153 needn't exist in the global table yet). */
6154 if (sig_entry
!= NULL
)
6157 if (dwp_file
->tus
== NULL
)
6159 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6160 1 /* is_debug_types */);
6161 if (dwo_entry
== NULL
)
6164 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6165 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6170 /* Lookup a signature based type for DW_FORM_ref_sig8.
6171 Returns NULL if signature SIG is not present in the table.
6172 It is up to the caller to complain about this. */
6174 static struct signatured_type
*
6175 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6177 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6179 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6181 /* We're in a DWO/DWP file, and we're using .gdb_index.
6182 These cases require special processing. */
6183 if (get_dwp_file (per_objfile
) == NULL
)
6184 return lookup_dwo_signatured_type (cu
, sig
);
6186 return lookup_dwp_signatured_type (cu
, sig
);
6190 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6192 signatured_type
find_entry (sig
);
6193 return ((struct signatured_type
*)
6194 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6199 /* Low level DIE reading support. */
6201 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6204 init_cu_die_reader (struct die_reader_specs
*reader
,
6205 struct dwarf2_cu
*cu
,
6206 struct dwarf2_section_info
*section
,
6207 struct dwo_file
*dwo_file
,
6208 struct abbrev_table
*abbrev_table
)
6210 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6211 reader
->abfd
= section
->get_bfd_owner ();
6213 reader
->dwo_file
= dwo_file
;
6214 reader
->die_section
= section
;
6215 reader
->buffer
= section
->buffer
;
6216 reader
->buffer_end
= section
->buffer
+ section
->size
;
6217 reader
->abbrev_table
= abbrev_table
;
6220 /* Subroutine of cutu_reader to simplify it.
6221 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6222 There's just a lot of work to do, and cutu_reader is big enough
6225 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6226 from it to the DIE in the DWO. If NULL we are skipping the stub.
6227 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6228 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6229 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6230 STUB_COMP_DIR may be non-NULL.
6231 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6232 are filled in with the info of the DIE from the DWO file.
6233 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6234 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6235 kept around for at least as long as *RESULT_READER.
6237 The result is non-zero if a valid (non-dummy) DIE was found. */
6240 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6241 struct dwo_unit
*dwo_unit
,
6242 struct die_info
*stub_comp_unit_die
,
6243 const char *stub_comp_dir
,
6244 struct die_reader_specs
*result_reader
,
6245 const gdb_byte
**result_info_ptr
,
6246 struct die_info
**result_comp_unit_die
,
6247 abbrev_table_up
*result_dwo_abbrev_table
)
6249 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6250 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6251 struct objfile
*objfile
= per_objfile
->objfile
;
6253 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6254 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6255 int i
,num_extra_attrs
;
6256 struct dwarf2_section_info
*dwo_abbrev_section
;
6257 struct die_info
*comp_unit_die
;
6259 /* At most one of these may be provided. */
6260 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6262 /* These attributes aren't processed until later:
6263 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6264 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6265 referenced later. However, these attributes are found in the stub
6266 which we won't have later. In order to not impose this complication
6267 on the rest of the code, we read them here and copy them to the
6276 if (stub_comp_unit_die
!= NULL
)
6278 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6280 if (!per_cu
->is_debug_types
)
6281 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6282 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6283 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6284 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6285 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6287 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6289 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6290 We need the value before we can process DW_AT_ranges values from the
6292 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6294 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6295 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6296 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6297 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6299 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6301 else if (stub_comp_dir
!= NULL
)
6303 /* Reconstruct the comp_dir attribute to simplify the code below. */
6304 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6305 comp_dir
->name
= DW_AT_comp_dir
;
6306 comp_dir
->form
= DW_FORM_string
;
6307 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6310 /* Set up for reading the DWO CU/TU. */
6311 cu
->dwo_unit
= dwo_unit
;
6312 dwarf2_section_info
*section
= dwo_unit
->section
;
6313 section
->read (objfile
);
6314 abfd
= section
->get_bfd_owner ();
6315 begin_info_ptr
= info_ptr
= (section
->buffer
6316 + to_underlying (dwo_unit
->sect_off
));
6317 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6319 if (per_cu
->is_debug_types
)
6321 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6323 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6324 section
, dwo_abbrev_section
,
6325 info_ptr
, rcuh_kind::TYPE
);
6326 /* This is not an assert because it can be caused by bad debug info. */
6327 if (sig_type
->signature
!= cu
->header
.signature
)
6329 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6330 " TU at offset %s [in module %s]"),
6331 hex_string (sig_type
->signature
),
6332 hex_string (cu
->header
.signature
),
6333 sect_offset_str (dwo_unit
->sect_off
),
6334 bfd_get_filename (abfd
));
6336 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6337 /* For DWOs coming from DWP files, we don't know the CU length
6338 nor the type's offset in the TU until now. */
6339 dwo_unit
->length
= cu
->header
.get_length ();
6340 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6342 /* Establish the type offset that can be used to lookup the type.
6343 For DWO files, we don't know it until now. */
6344 sig_type
->type_offset_in_section
6345 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6349 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6350 section
, dwo_abbrev_section
,
6351 info_ptr
, rcuh_kind::COMPILE
);
6352 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6353 /* For DWOs coming from DWP files, we don't know the CU length
6355 dwo_unit
->length
= cu
->header
.get_length ();
6358 dwo_abbrev_section
->read (objfile
);
6359 *result_dwo_abbrev_table
6360 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6361 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6362 result_dwo_abbrev_table
->get ());
6364 /* Read in the die, but leave space to copy over the attributes
6365 from the stub. This has the benefit of simplifying the rest of
6366 the code - all the work to maintain the illusion of a single
6367 DW_TAG_{compile,type}_unit DIE is done here. */
6368 num_extra_attrs
= ((stmt_list
!= NULL
)
6372 + (comp_dir
!= NULL
));
6373 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6376 /* Copy over the attributes from the stub to the DIE we just read in. */
6377 comp_unit_die
= *result_comp_unit_die
;
6378 i
= comp_unit_die
->num_attrs
;
6379 if (stmt_list
!= NULL
)
6380 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6382 comp_unit_die
->attrs
[i
++] = *low_pc
;
6383 if (high_pc
!= NULL
)
6384 comp_unit_die
->attrs
[i
++] = *high_pc
;
6386 comp_unit_die
->attrs
[i
++] = *ranges
;
6387 if (comp_dir
!= NULL
)
6388 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6389 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6391 if (dwarf_die_debug
)
6393 fprintf_unfiltered (gdb_stdlog
,
6394 "Read die from %s@0x%x of %s:\n",
6395 section
->get_name (),
6396 (unsigned) (begin_info_ptr
- section
->buffer
),
6397 bfd_get_filename (abfd
));
6398 dump_die (comp_unit_die
, dwarf_die_debug
);
6401 /* Skip dummy compilation units. */
6402 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6403 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6406 *result_info_ptr
= info_ptr
;
6410 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6411 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6412 signature is part of the header. */
6413 static gdb::optional
<ULONGEST
>
6414 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6416 if (cu
->header
.version
>= 5)
6417 return cu
->header
.signature
;
6418 struct attribute
*attr
;
6419 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6420 if (attr
== nullptr || !attr
->form_is_unsigned ())
6421 return gdb::optional
<ULONGEST
> ();
6422 return attr
->as_unsigned ();
6425 /* Subroutine of cutu_reader to simplify it.
6426 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6427 Returns NULL if the specified DWO unit cannot be found. */
6429 static struct dwo_unit
*
6430 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6432 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6433 struct dwo_unit
*dwo_unit
;
6434 const char *comp_dir
;
6436 gdb_assert (cu
!= NULL
);
6438 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6439 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6440 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6442 if (per_cu
->is_debug_types
)
6443 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6446 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6448 if (!signature
.has_value ())
6449 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6451 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6453 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6459 /* Subroutine of cutu_reader to simplify it.
6460 See it for a description of the parameters.
6461 Read a TU directly from a DWO file, bypassing the stub. */
6464 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6465 dwarf2_per_objfile
*per_objfile
,
6466 dwarf2_cu
*existing_cu
)
6468 struct signatured_type
*sig_type
;
6470 /* Verify we can do the following downcast, and that we have the
6472 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6473 sig_type
= (struct signatured_type
*) this_cu
;
6474 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6478 if (existing_cu
!= nullptr)
6481 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6482 /* There's no need to do the rereading_dwo_cu handling that
6483 cutu_reader does since we don't read the stub. */
6487 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6488 in per_objfile yet. */
6489 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6490 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6491 cu
= m_new_cu
.get ();
6494 /* A future optimization, if needed, would be to use an existing
6495 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6496 could share abbrev tables. */
6498 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6499 NULL
/* stub_comp_unit_die */,
6500 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6503 &m_dwo_abbrev_table
) == 0)
6510 /* Initialize a CU (or TU) and read its DIEs.
6511 If the CU defers to a DWO file, read the DWO file as well.
6513 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6514 Otherwise the table specified in the comp unit header is read in and used.
6515 This is an optimization for when we already have the abbrev table.
6517 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6520 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6521 dwarf2_per_objfile
*per_objfile
,
6522 struct abbrev_table
*abbrev_table
,
6523 dwarf2_cu
*existing_cu
,
6525 : die_reader_specs
{},
6528 struct objfile
*objfile
= per_objfile
->objfile
;
6529 struct dwarf2_section_info
*section
= this_cu
->section
;
6530 bfd
*abfd
= section
->get_bfd_owner ();
6531 const gdb_byte
*begin_info_ptr
;
6532 struct signatured_type
*sig_type
= NULL
;
6533 struct dwarf2_section_info
*abbrev_section
;
6534 /* Non-zero if CU currently points to a DWO file and we need to
6535 reread it. When this happens we need to reread the skeleton die
6536 before we can reread the DWO file (this only applies to CUs, not TUs). */
6537 int rereading_dwo_cu
= 0;
6539 if (dwarf_die_debug
)
6540 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6541 this_cu
->is_debug_types
? "type" : "comp",
6542 sect_offset_str (this_cu
->sect_off
));
6544 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6545 file (instead of going through the stub), short-circuit all of this. */
6546 if (this_cu
->reading_dwo_directly
)
6548 /* Narrow down the scope of possibilities to have to understand. */
6549 gdb_assert (this_cu
->is_debug_types
);
6550 gdb_assert (abbrev_table
== NULL
);
6551 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6555 /* This is cheap if the section is already read in. */
6556 section
->read (objfile
);
6558 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6560 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6564 if (existing_cu
!= nullptr)
6567 /* If this CU is from a DWO file we need to start over, we need to
6568 refetch the attributes from the skeleton CU.
6569 This could be optimized by retrieving those attributes from when we
6570 were here the first time: the previous comp_unit_die was stored in
6571 comp_unit_obstack. But there's no data yet that we need this
6573 if (cu
->dwo_unit
!= NULL
)
6574 rereading_dwo_cu
= 1;
6578 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6579 in per_objfile yet. */
6580 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6581 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6582 cu
= m_new_cu
.get ();
6585 /* Get the header. */
6586 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6588 /* We already have the header, there's no need to read it in again. */
6589 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6593 if (this_cu
->is_debug_types
)
6595 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6596 section
, abbrev_section
,
6597 info_ptr
, rcuh_kind::TYPE
);
6599 /* Since per_cu is the first member of struct signatured_type,
6600 we can go from a pointer to one to a pointer to the other. */
6601 sig_type
= (struct signatured_type
*) this_cu
;
6602 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6603 gdb_assert (sig_type
->type_offset_in_tu
6604 == cu
->header
.type_cu_offset_in_tu
);
6605 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6607 /* LENGTH has not been set yet for type units if we're
6608 using .gdb_index. */
6609 this_cu
->length
= cu
->header
.get_length ();
6611 /* Establish the type offset that can be used to lookup the type. */
6612 sig_type
->type_offset_in_section
=
6613 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6615 this_cu
->dwarf_version
= cu
->header
.version
;
6619 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6620 section
, abbrev_section
,
6622 rcuh_kind::COMPILE
);
6624 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6625 if (this_cu
->length
== 0)
6626 this_cu
->length
= cu
->header
.get_length ();
6628 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6629 this_cu
->dwarf_version
= cu
->header
.version
;
6633 /* Skip dummy compilation units. */
6634 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6635 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6641 /* If we don't have them yet, read the abbrevs for this compilation unit.
6642 And if we need to read them now, make sure they're freed when we're
6644 if (abbrev_table
!= NULL
)
6645 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6648 abbrev_section
->read (objfile
);
6649 m_abbrev_table_holder
6650 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6651 abbrev_table
= m_abbrev_table_holder
.get ();
6654 /* Read the top level CU/TU die. */
6655 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6656 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6658 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6664 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6665 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6666 table from the DWO file and pass the ownership over to us. It will be
6667 referenced from READER, so we must make sure to free it after we're done
6670 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6671 DWO CU, that this test will fail (the attribute will not be present). */
6672 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6673 if (dwo_name
!= nullptr)
6675 struct dwo_unit
*dwo_unit
;
6676 struct die_info
*dwo_comp_unit_die
;
6678 if (comp_unit_die
->has_children
)
6680 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6681 " has children (offset %s) [in module %s]"),
6682 sect_offset_str (this_cu
->sect_off
),
6683 bfd_get_filename (abfd
));
6685 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6686 if (dwo_unit
!= NULL
)
6688 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6689 comp_unit_die
, NULL
,
6692 &m_dwo_abbrev_table
) == 0)
6698 comp_unit_die
= dwo_comp_unit_die
;
6702 /* Yikes, we couldn't find the rest of the DIE, we only have
6703 the stub. A complaint has already been logged. There's
6704 not much more we can do except pass on the stub DIE to
6705 die_reader_func. We don't want to throw an error on bad
6712 cutu_reader::keep ()
6714 /* Done, clean up. */
6715 gdb_assert (!dummy_p
);
6716 if (m_new_cu
!= NULL
)
6718 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6720 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6721 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6725 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6726 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6727 assumed to have already done the lookup to find the DWO file).
6729 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6730 THIS_CU->is_debug_types, but nothing else.
6732 We fill in THIS_CU->length.
6734 THIS_CU->cu is always freed when done.
6735 This is done in order to not leave THIS_CU->cu in a state where we have
6736 to care whether it refers to the "main" CU or the DWO CU.
6738 When parent_cu is passed, it is used to provide a default value for
6739 str_offsets_base and addr_base from the parent. */
6741 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6742 dwarf2_per_objfile
*per_objfile
,
6743 struct dwarf2_cu
*parent_cu
,
6744 struct dwo_file
*dwo_file
)
6745 : die_reader_specs
{},
6748 struct objfile
*objfile
= per_objfile
->objfile
;
6749 struct dwarf2_section_info
*section
= this_cu
->section
;
6750 bfd
*abfd
= section
->get_bfd_owner ();
6751 struct dwarf2_section_info
*abbrev_section
;
6752 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6754 if (dwarf_die_debug
)
6755 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6756 this_cu
->is_debug_types
? "type" : "comp",
6757 sect_offset_str (this_cu
->sect_off
));
6759 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6761 abbrev_section
= (dwo_file
!= NULL
6762 ? &dwo_file
->sections
.abbrev
6763 : get_abbrev_section_for_cu (this_cu
));
6765 /* This is cheap if the section is already read in. */
6766 section
->read (objfile
);
6768 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6770 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6771 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6772 section
, abbrev_section
, info_ptr
,
6773 (this_cu
->is_debug_types
6775 : rcuh_kind::COMPILE
));
6777 if (parent_cu
!= nullptr)
6779 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6780 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6782 this_cu
->length
= m_new_cu
->header
.get_length ();
6784 /* Skip dummy compilation units. */
6785 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6786 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6792 abbrev_section
->read (objfile
);
6793 m_abbrev_table_holder
6794 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6796 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6797 m_abbrev_table_holder
.get ());
6798 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6802 /* Type Unit Groups.
6804 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6805 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6806 so that all types coming from the same compilation (.o file) are grouped
6807 together. A future step could be to put the types in the same symtab as
6808 the CU the types ultimately came from. */
6811 hash_type_unit_group (const void *item
)
6813 const struct type_unit_group
*tu_group
6814 = (const struct type_unit_group
*) item
;
6816 return hash_stmt_list_entry (&tu_group
->hash
);
6820 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6822 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6823 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6825 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6828 /* Allocate a hash table for type unit groups. */
6831 allocate_type_unit_groups_table ()
6833 return htab_up (htab_create_alloc (3,
6834 hash_type_unit_group
,
6836 htab_delete_entry
<type_unit_group
>,
6840 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6841 partial symtabs. We combine several TUs per psymtab to not let the size
6842 of any one psymtab grow too big. */
6843 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6844 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6846 /* Helper routine for get_type_unit_group.
6847 Create the type_unit_group object used to hold one or more TUs. */
6849 static std::unique_ptr
<type_unit_group
>
6850 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6852 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6853 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6855 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6856 tu_group
->per_bfd
= per_bfd
;
6858 if (per_bfd
->using_index
)
6860 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6861 struct dwarf2_per_cu_quick_data
);
6865 unsigned int line_offset
= to_underlying (line_offset_struct
);
6866 dwarf2_psymtab
*pst
;
6869 /* Give the symtab a useful name for debug purposes. */
6870 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6871 name
= string_printf ("<type_units_%d>",
6872 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6874 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6876 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6878 pst
->anonymous
= true;
6881 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6882 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6887 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6888 STMT_LIST is a DW_AT_stmt_list attribute. */
6890 static struct type_unit_group
*
6891 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6893 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6894 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6895 struct type_unit_group
*tu_group
;
6897 unsigned int line_offset
;
6898 struct type_unit_group type_unit_group_for_lookup
;
6900 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6901 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6903 /* Do we need to create a new group, or can we use an existing one? */
6905 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6907 line_offset
= stmt_list
->as_unsigned ();
6908 ++tu_stats
->nr_symtab_sharers
;
6912 /* Ugh, no stmt_list. Rare, but we have to handle it.
6913 We can do various things here like create one group per TU or
6914 spread them over multiple groups to split up the expansion work.
6915 To avoid worst case scenarios (too many groups or too large groups)
6916 we, umm, group them in bunches. */
6917 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6918 | (tu_stats
->nr_stmt_less_type_units
6919 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6920 ++tu_stats
->nr_stmt_less_type_units
;
6923 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6924 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6925 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6926 &type_unit_group_for_lookup
, INSERT
);
6927 if (*slot
== nullptr)
6929 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6930 std::unique_ptr
<type_unit_group
> grp
6931 = create_type_unit_group (cu
, line_offset_struct
);
6932 *slot
= grp
.release ();
6933 ++tu_stats
->nr_symtabs
;
6936 tu_group
= (struct type_unit_group
*) *slot
;
6937 gdb_assert (tu_group
!= nullptr);
6941 /* Partial symbol tables. */
6943 /* Create a psymtab named NAME and assign it to PER_CU.
6945 The caller must fill in the following details:
6946 dirname, textlow, texthigh. */
6948 static dwarf2_psymtab
*
6949 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6950 dwarf2_per_objfile
*per_objfile
,
6954 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6955 per_objfile
->objfile
->per_bfd
, per_cu
);
6957 pst
->psymtabs_addrmap_supported
= true;
6959 /* This is the glue that links PST into GDB's symbol API. */
6960 per_cu
->v
.psymtab
= pst
;
6965 /* DIE reader function for process_psymtab_comp_unit. */
6968 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6969 const gdb_byte
*info_ptr
,
6970 struct die_info
*comp_unit_die
,
6971 enum language pretend_language
)
6973 struct dwarf2_cu
*cu
= reader
->cu
;
6974 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6975 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6976 struct objfile
*objfile
= per_objfile
->objfile
;
6977 struct gdbarch
*gdbarch
= objfile
->arch ();
6978 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6980 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6981 dwarf2_psymtab
*pst
;
6982 enum pc_bounds_kind cu_bounds_kind
;
6984 gdb_assert (! per_cu
->is_debug_types
);
6986 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6988 /* Allocate a new partial symbol table structure. */
6989 static const char artificial
[] = "<artificial>";
6990 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
6991 if (strcmp (fnd
.get_name (), artificial
) == 0)
6993 gdb::unique_xmalloc_ptr
<char> debug_filename
6994 (concat (artificial
, "@",
6995 sect_offset_str (per_cu
->sect_off
),
6997 fnd
.set_name (std::move (debug_filename
));
7000 pst
= create_partial_symtab (per_cu
, per_objfile
, fnd
.get_name ());
7002 /* This must be done before calling dwarf2_build_include_psymtabs. */
7003 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7005 baseaddr
= objfile
->text_section_offset ();
7007 dwarf2_find_base_address (comp_unit_die
, cu
);
7009 /* Possibly set the default values of LOWPC and HIGHPC from
7011 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7012 &best_highpc
, cu
, pst
);
7013 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7016 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7019 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7021 /* Store the contiguous range if it is not empty; it can be
7022 empty for CUs with no code. */
7023 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7027 /* Check if comp unit has_children.
7028 If so, read the rest of the partial symbols from this comp unit.
7029 If not, there's no more debug_info for this comp unit. */
7030 if (comp_unit_die
->has_children
)
7032 struct partial_die_info
*first_die
;
7033 CORE_ADDR lowpc
, highpc
;
7035 lowpc
= ((CORE_ADDR
) -1);
7036 highpc
= ((CORE_ADDR
) 0);
7038 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7040 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7041 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7043 /* If we didn't find a lowpc, set it to highpc to avoid
7044 complaints from `maint check'. */
7045 if (lowpc
== ((CORE_ADDR
) -1))
7048 /* If the compilation unit didn't have an explicit address range,
7049 then use the information extracted from its child dies. */
7050 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7053 best_highpc
= highpc
;
7056 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7057 best_lowpc
+ baseaddr
)
7059 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7060 best_highpc
+ baseaddr
)
7065 if (!cu
->per_cu
->imported_symtabs_empty ())
7068 int len
= cu
->per_cu
->imported_symtabs_size ();
7070 /* Fill in 'dependencies' here; we fill in 'users' in a
7072 pst
->number_of_dependencies
= len
;
7074 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7075 for (i
= 0; i
< len
; ++i
)
7077 pst
->dependencies
[i
]
7078 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7081 cu
->per_cu
->imported_symtabs_free ();
7084 /* Get the list of files included in the current compilation unit,
7085 and build a psymtab for each of them. */
7086 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, fnd
, pst
);
7088 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7089 ", %d global, %d static syms",
7090 per_cu
->is_debug_types
? "type" : "comp",
7091 sect_offset_str (per_cu
->sect_off
),
7092 paddress (gdbarch
, pst
->text_low (objfile
)),
7093 paddress (gdbarch
, pst
->text_high (objfile
)),
7094 (int) pst
->global_psymbols
.size (),
7095 (int) pst
->static_psymbols
.size ());
7098 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7099 Process compilation unit THIS_CU for a psymtab. */
7102 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7103 dwarf2_per_objfile
*per_objfile
,
7104 bool want_partial_unit
,
7105 enum language pretend_language
)
7107 /* If this compilation unit was already read in, free the
7108 cached copy in order to read it in again. This is
7109 necessary because we skipped some symbols when we first
7110 read in the compilation unit (see load_partial_dies).
7111 This problem could be avoided, but the benefit is unclear. */
7112 per_objfile
->remove_cu (this_cu
);
7114 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7116 if (reader
.comp_unit_die
== nullptr)
7119 switch (reader
.comp_unit_die
->tag
)
7121 case DW_TAG_compile_unit
:
7122 this_cu
->unit_type
= DW_UT_compile
;
7124 case DW_TAG_partial_unit
:
7125 this_cu
->unit_type
= DW_UT_partial
;
7127 case DW_TAG_type_unit
:
7128 this_cu
->unit_type
= DW_UT_type
;
7131 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7132 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7133 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7134 objfile_name (per_objfile
->objfile
));
7141 else if (this_cu
->is_debug_types
)
7142 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7143 reader
.comp_unit_die
);
7144 else if (want_partial_unit
7145 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7146 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7147 reader
.comp_unit_die
,
7150 /* Age out any secondary CUs. */
7151 per_objfile
->age_comp_units ();
7154 /* Reader function for build_type_psymtabs. */
7157 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7158 const gdb_byte
*info_ptr
,
7159 struct die_info
*type_unit_die
)
7161 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7162 struct dwarf2_cu
*cu
= reader
->cu
;
7163 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7164 struct signatured_type
*sig_type
;
7165 struct type_unit_group
*tu_group
;
7166 struct attribute
*attr
;
7167 struct partial_die_info
*first_die
;
7168 CORE_ADDR lowpc
, highpc
;
7169 dwarf2_psymtab
*pst
;
7171 gdb_assert (per_cu
->is_debug_types
);
7172 sig_type
= (struct signatured_type
*) per_cu
;
7174 if (! type_unit_die
->has_children
)
7177 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7178 tu_group
= get_type_unit_group (cu
, attr
);
7180 if (tu_group
->tus
== nullptr)
7181 tu_group
->tus
= new std::vector
<signatured_type
*>;
7182 tu_group
->tus
->push_back (sig_type
);
7184 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7185 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7186 pst
->anonymous
= true;
7188 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7190 lowpc
= (CORE_ADDR
) -1;
7191 highpc
= (CORE_ADDR
) 0;
7192 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7197 /* Struct used to sort TUs by their abbreviation table offset. */
7199 struct tu_abbrev_offset
7201 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7202 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7205 /* This is used when sorting. */
7206 bool operator< (const tu_abbrev_offset
&other
) const
7208 return abbrev_offset
< other
.abbrev_offset
;
7211 signatured_type
*sig_type
;
7212 sect_offset abbrev_offset
;
7215 /* Efficiently read all the type units.
7217 The efficiency is because we sort TUs by the abbrev table they use and
7218 only read each abbrev table once. In one program there are 200K TUs
7219 sharing 8K abbrev tables.
7221 The main purpose of this function is to support building the
7222 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7223 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7224 can collapse the search space by grouping them by stmt_list.
7225 The savings can be significant, in the same program from above the 200K TUs
7226 share 8K stmt_list tables.
7228 FUNC is expected to call get_type_unit_group, which will create the
7229 struct type_unit_group if necessary and add it to
7230 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7233 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7235 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7236 abbrev_table_up abbrev_table
;
7237 sect_offset abbrev_offset
;
7239 /* It's up to the caller to not call us multiple times. */
7240 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7242 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7245 /* TUs typically share abbrev tables, and there can be way more TUs than
7246 abbrev tables. Sort by abbrev table to reduce the number of times we
7247 read each abbrev table in.
7248 Alternatives are to punt or to maintain a cache of abbrev tables.
7249 This is simpler and efficient enough for now.
7251 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7252 symtab to use). Typically TUs with the same abbrev offset have the same
7253 stmt_list value too so in practice this should work well.
7255 The basic algorithm here is:
7257 sort TUs by abbrev table
7258 for each TU with same abbrev table:
7259 read abbrev table if first user
7260 read TU top level DIE
7261 [IWBN if DWO skeletons had DW_AT_stmt_list]
7264 dwarf_read_debug_printf ("Building type unit groups ...");
7266 /* Sort in a separate table to maintain the order of all_comp_units
7267 for .gdb_index: TU indices directly index all_type_units. */
7268 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7269 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7271 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7273 if (cu
->is_debug_types
)
7275 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7276 sorted_by_abbrev
.emplace_back
7277 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7278 sig_type
->sect_off
));
7282 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7284 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7286 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7288 /* Switch to the next abbrev table if necessary. */
7289 if (abbrev_table
== NULL
7290 || tu
.abbrev_offset
!= abbrev_offset
)
7292 abbrev_offset
= tu
.abbrev_offset
;
7293 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7295 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7296 ++tu_stats
->nr_uniq_abbrev_tables
;
7299 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7300 abbrev_table
.get (), nullptr, false);
7301 if (!reader
.dummy_p
)
7302 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7303 reader
.comp_unit_die
);
7307 /* Print collected type unit statistics. */
7310 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7312 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7314 dwarf_read_debug_printf ("Type unit statistics:");
7315 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7316 dwarf_read_debug_printf (" %d uniq abbrev tables",
7317 tu_stats
->nr_uniq_abbrev_tables
);
7318 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7319 tu_stats
->nr_symtabs
);
7320 dwarf_read_debug_printf (" %d symtab sharers",
7321 tu_stats
->nr_symtab_sharers
);
7322 dwarf_read_debug_printf (" %d type units without a stmt_list",
7323 tu_stats
->nr_stmt_less_type_units
);
7324 dwarf_read_debug_printf (" %d all_type_units reallocs",
7325 tu_stats
->nr_all_type_units_reallocs
);
7328 /* Traversal function for build_type_psymtabs. */
7331 build_type_psymtab_dependencies (void **slot
, void *info
)
7333 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7334 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7335 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7336 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7337 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7340 gdb_assert (len
> 0);
7341 gdb_assert (tu_group
->type_unit_group_p ());
7343 pst
->number_of_dependencies
= len
;
7344 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7345 for (i
= 0; i
< len
; ++i
)
7347 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7348 gdb_assert (iter
->is_debug_types
);
7349 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7350 iter
->type_unit_group
= tu_group
;
7353 delete tu_group
->tus
;
7354 tu_group
->tus
= nullptr;
7359 /* Traversal function for process_skeletonless_type_unit.
7360 Read a TU in a DWO file and build partial symbols for it. */
7363 process_skeletonless_type_unit (void **slot
, void *info
)
7365 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7366 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7368 /* If this TU doesn't exist in the global table, add it and read it in. */
7370 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7371 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7373 signatured_type
find_entry (dwo_unit
->signature
);
7374 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7375 &find_entry
, INSERT
);
7376 /* If we've already seen this type there's nothing to do. What's happening
7377 is we're doing our own version of comdat-folding here. */
7381 /* This does the job that create_all_comp_units would have done for
7383 signatured_type
*entry
7384 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7385 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7388 /* This does the job that build_type_psymtabs would have done. */
7389 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7390 if (!reader
.dummy_p
)
7391 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7392 reader
.comp_unit_die
);
7397 /* Traversal function for process_skeletonless_type_units. */
7400 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7402 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7404 if (dwo_file
->tus
!= NULL
)
7405 htab_traverse_noresize (dwo_file
->tus
.get (),
7406 process_skeletonless_type_unit
, info
);
7411 /* Scan all TUs of DWO files, verifying we've processed them.
7412 This is needed in case a TU was emitted without its skeleton.
7413 Note: This can't be done until we know what all the DWO files are. */
7416 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7418 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7419 if (get_dwp_file (per_objfile
) == NULL
7420 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7422 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7423 process_dwo_file_for_skeletonless_type_units
,
7428 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7431 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7433 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7435 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7440 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7442 /* Set the 'user' field only if it is not already set. */
7443 if (pst
->dependencies
[j
]->user
== NULL
)
7444 pst
->dependencies
[j
]->user
= pst
;
7449 /* Build the partial symbol table by doing a quick pass through the
7450 .debug_info and .debug_abbrev sections. */
7453 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7455 struct objfile
*objfile
= per_objfile
->objfile
;
7456 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7458 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7459 objfile_name (objfile
));
7461 scoped_restore restore_reading_psyms
7462 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7464 per_bfd
->info
.read (objfile
);
7466 /* Any cached compilation units will be linked by the per-objfile
7467 read_in_chain. Make sure to free them when we're done. */
7468 free_cached_comp_units
freer (per_objfile
);
7470 create_all_comp_units (per_objfile
);
7471 build_type_psymtabs (per_objfile
);
7473 /* Create a temporary address map on a temporary obstack. We later
7474 copy this to the final obstack. */
7475 auto_obstack temp_obstack
;
7477 scoped_restore save_psymtabs_addrmap
7478 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7479 addrmap_create_mutable (&temp_obstack
));
7481 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7483 if (per_cu
->v
.psymtab
!= NULL
)
7484 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7486 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7490 /* This has to wait until we read the CUs, we need the list of DWOs. */
7491 process_skeletonless_type_units (per_objfile
);
7493 /* Now that all TUs have been processed we can fill in the dependencies. */
7494 if (per_bfd
->type_unit_groups
!= NULL
)
7496 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7497 build_type_psymtab_dependencies
, per_objfile
);
7500 if (dwarf_read_debug
> 0)
7501 print_tu_stats (per_objfile
);
7503 set_partial_user (per_objfile
);
7505 per_bfd
->partial_symtabs
->psymtabs_addrmap
7506 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7507 per_bfd
->partial_symtabs
->obstack ());
7508 /* At this point we want to keep the address map. */
7509 save_psymtabs_addrmap
.release ();
7511 dwarf_read_debug_printf ("Done building psymtabs of %s",
7512 objfile_name (objfile
));
7515 /* Load the partial DIEs for a secondary CU into memory.
7516 This is also used when rereading a primary CU with load_all_dies. */
7519 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7520 dwarf2_per_objfile
*per_objfile
,
7521 dwarf2_cu
*existing_cu
)
7523 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7525 if (!reader
.dummy_p
)
7527 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7530 /* Check if comp unit has_children.
7531 If so, read the rest of the partial symbols from this comp unit.
7532 If not, there's no more debug_info for this comp unit. */
7533 if (reader
.comp_unit_die
->has_children
)
7534 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7541 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7542 struct dwarf2_section_info
*section
,
7543 struct dwarf2_section_info
*abbrev_section
,
7544 unsigned int is_dwz
,
7545 htab_up
&types_htab
,
7546 rcuh_kind section_kind
)
7548 const gdb_byte
*info_ptr
;
7549 struct objfile
*objfile
= per_objfile
->objfile
;
7551 dwarf_read_debug_printf ("Reading %s for %s",
7552 section
->get_name (),
7553 section
->get_file_name ());
7555 section
->read (objfile
);
7557 info_ptr
= section
->buffer
;
7559 while (info_ptr
< section
->buffer
+ section
->size
)
7561 dwarf2_per_cu_data_up this_cu
;
7563 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7565 comp_unit_head cu_header
;
7566 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7567 abbrev_section
, info_ptr
,
7570 /* Save the compilation unit for later lookup. */
7571 if (cu_header
.unit_type
!= DW_UT_type
)
7572 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7575 if (types_htab
== nullptr)
7576 types_htab
= allocate_signatured_type_table ();
7578 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7579 (cu_header
.signature
);
7580 signatured_type
*sig_ptr
= sig_type
.get ();
7581 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7582 this_cu
.reset (sig_type
.release ());
7584 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7585 gdb_assert (slot
!= nullptr);
7586 if (*slot
!= nullptr)
7587 complaint (_("debug type entry at offset %s is duplicate to"
7588 " the entry at offset %s, signature %s"),
7589 sect_offset_str (sect_off
),
7590 sect_offset_str (sig_ptr
->sect_off
),
7591 hex_string (sig_ptr
->signature
));
7594 this_cu
->sect_off
= sect_off
;
7595 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7596 this_cu
->is_dwz
= is_dwz
;
7597 this_cu
->section
= section
;
7599 info_ptr
= info_ptr
+ this_cu
->length
;
7600 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7604 /* Create a list of all compilation units in OBJFILE.
7605 This is only done for -readnow and building partial symtabs. */
7608 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7612 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7613 &per_objfile
->per_bfd
->abbrev
, 0,
7614 types_htab
, rcuh_kind::COMPILE
);
7615 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7616 read_comp_units_from_section (per_objfile
, §ion
,
7617 &per_objfile
->per_bfd
->abbrev
, 0,
7618 types_htab
, rcuh_kind::TYPE
);
7620 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7622 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7623 types_htab
, rcuh_kind::COMPILE
);
7625 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7628 /* Process all loaded DIEs for compilation unit CU, starting at
7629 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7630 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7631 DW_AT_ranges). See the comments of add_partial_subprogram on how
7632 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7635 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7636 CORE_ADDR
*highpc
, int set_addrmap
,
7637 struct dwarf2_cu
*cu
)
7639 struct partial_die_info
*pdi
;
7641 /* Now, march along the PDI's, descending into ones which have
7642 interesting children but skipping the children of the other ones,
7643 until we reach the end of the compilation unit. */
7651 /* Anonymous namespaces or modules have no name but have interesting
7652 children, so we need to look at them. Ditto for anonymous
7655 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7656 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7657 || pdi
->tag
== DW_TAG_imported_unit
7658 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7662 case DW_TAG_subprogram
:
7663 case DW_TAG_inlined_subroutine
:
7664 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7665 if (cu
->per_cu
->lang
== language_cplus
)
7666 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7669 case DW_TAG_constant
:
7670 case DW_TAG_variable
:
7671 case DW_TAG_typedef
:
7672 case DW_TAG_union_type
:
7673 if (!pdi
->is_declaration
7674 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7676 add_partial_symbol (pdi
, cu
);
7679 case DW_TAG_class_type
:
7680 case DW_TAG_interface_type
:
7681 case DW_TAG_structure_type
:
7682 if (!pdi
->is_declaration
)
7684 add_partial_symbol (pdi
, cu
);
7686 if ((cu
->per_cu
->lang
== language_rust
7687 || cu
->per_cu
->lang
== language_cplus
)
7688 && pdi
->has_children
)
7689 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7692 case DW_TAG_enumeration_type
:
7693 if (!pdi
->is_declaration
)
7694 add_partial_enumeration (pdi
, cu
);
7696 case DW_TAG_base_type
:
7697 case DW_TAG_subrange_type
:
7698 /* File scope base type definitions are added to the partial
7700 add_partial_symbol (pdi
, cu
);
7702 case DW_TAG_namespace
:
7703 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7706 if (!pdi
->is_declaration
)
7707 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7709 case DW_TAG_imported_unit
:
7711 struct dwarf2_per_cu_data
*per_cu
;
7713 /* For now we don't handle imported units in type units. */
7714 if (cu
->per_cu
->is_debug_types
)
7716 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7717 " supported in type units [in module %s]"),
7718 objfile_name (cu
->per_objfile
->objfile
));
7721 per_cu
= dwarf2_find_containing_comp_unit
7722 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7723 cu
->per_objfile
->per_bfd
);
7725 /* Go read the partial unit, if needed. */
7726 if (per_cu
->v
.psymtab
== NULL
)
7727 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7730 if (pdi
->die_parent
== nullptr
7731 && per_cu
->unit_type
== DW_UT_compile
7732 && per_cu
->lang
== language_cplus
)
7733 /* Regard import as hint. See corresponding code in
7734 process_imported_unit_die. */
7737 cu
->per_cu
->imported_symtabs_push (per_cu
);
7740 case DW_TAG_imported_declaration
:
7741 add_partial_symbol (pdi
, cu
);
7748 /* If the die has a sibling, skip to the sibling. */
7750 pdi
= pdi
->die_sibling
;
7754 /* Functions used to compute the fully scoped name of a partial DIE.
7756 Normally, this is simple. For C++, the parent DIE's fully scoped
7757 name is concatenated with "::" and the partial DIE's name.
7758 Enumerators are an exception; they use the scope of their parent
7759 enumeration type, i.e. the name of the enumeration type is not
7760 prepended to the enumerator.
7762 There are two complexities. One is DW_AT_specification; in this
7763 case "parent" means the parent of the target of the specification,
7764 instead of the direct parent of the DIE. The other is compilers
7765 which do not emit DW_TAG_namespace; in this case we try to guess
7766 the fully qualified name of structure types from their members'
7767 linkage names. This must be done using the DIE's children rather
7768 than the children of any DW_AT_specification target. We only need
7769 to do this for structures at the top level, i.e. if the target of
7770 any DW_AT_specification (if any; otherwise the DIE itself) does not
7773 /* Compute the scope prefix associated with PDI's parent, in
7774 compilation unit CU. The result will be allocated on CU's
7775 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7776 field. NULL is returned if no prefix is necessary. */
7778 partial_die_parent_scope (struct partial_die_info
*pdi
,
7779 struct dwarf2_cu
*cu
)
7781 const char *grandparent_scope
;
7782 struct partial_die_info
*parent
, *real_pdi
;
7784 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7785 then this means the parent of the specification DIE. */
7788 while (real_pdi
->has_specification
)
7790 auto res
= find_partial_die (real_pdi
->spec_offset
,
7791 real_pdi
->spec_is_dwz
, cu
);
7796 parent
= real_pdi
->die_parent
;
7800 if (parent
->scope_set
)
7801 return parent
->scope
;
7805 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7807 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7808 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7809 Work around this problem here. */
7810 if (cu
->per_cu
->lang
== language_cplus
7811 && parent
->tag
== DW_TAG_namespace
7812 && strcmp (parent
->name (cu
), "::") == 0
7813 && grandparent_scope
== NULL
)
7815 parent
->scope
= NULL
;
7816 parent
->scope_set
= 1;
7820 /* Nested subroutines in Fortran get a prefix. */
7821 if (pdi
->tag
== DW_TAG_enumerator
)
7822 /* Enumerators should not get the name of the enumeration as a prefix. */
7823 parent
->scope
= grandparent_scope
;
7824 else if (parent
->tag
== DW_TAG_namespace
7825 || parent
->tag
== DW_TAG_module
7826 || parent
->tag
== DW_TAG_structure_type
7827 || parent
->tag
== DW_TAG_class_type
7828 || parent
->tag
== DW_TAG_interface_type
7829 || parent
->tag
== DW_TAG_union_type
7830 || parent
->tag
== DW_TAG_enumeration_type
7831 || (cu
->per_cu
->lang
== language_fortran
7832 && parent
->tag
== DW_TAG_subprogram
7833 && pdi
->tag
== DW_TAG_subprogram
))
7835 if (grandparent_scope
== NULL
)
7836 parent
->scope
= parent
->name (cu
);
7838 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7840 parent
->name (cu
), 0, cu
);
7844 /* FIXME drow/2004-04-01: What should we be doing with
7845 function-local names? For partial symbols, we should probably be
7847 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7848 dwarf_tag_name (parent
->tag
),
7849 sect_offset_str (pdi
->sect_off
));
7850 parent
->scope
= grandparent_scope
;
7853 parent
->scope_set
= 1;
7854 return parent
->scope
;
7857 /* Return the fully scoped name associated with PDI, from compilation unit
7858 CU. The result will be allocated with malloc. */
7860 static gdb::unique_xmalloc_ptr
<char>
7861 partial_die_full_name (struct partial_die_info
*pdi
,
7862 struct dwarf2_cu
*cu
)
7864 const char *parent_scope
;
7866 /* If this is a template instantiation, we can not work out the
7867 template arguments from partial DIEs. So, unfortunately, we have
7868 to go through the full DIEs. At least any work we do building
7869 types here will be reused if full symbols are loaded later. */
7870 if (pdi
->has_template_arguments
)
7874 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7876 struct die_info
*die
;
7877 struct attribute attr
;
7878 struct dwarf2_cu
*ref_cu
= cu
;
7880 /* DW_FORM_ref_addr is using section offset. */
7881 attr
.name
= (enum dwarf_attribute
) 0;
7882 attr
.form
= DW_FORM_ref_addr
;
7883 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7884 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7886 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7890 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7891 if (parent_scope
== NULL
)
7894 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7900 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7902 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7903 struct objfile
*objfile
= per_objfile
->objfile
;
7904 struct gdbarch
*gdbarch
= objfile
->arch ();
7906 const char *actual_name
= NULL
;
7909 baseaddr
= objfile
->text_section_offset ();
7911 gdb::unique_xmalloc_ptr
<char> built_actual_name
7912 = partial_die_full_name (pdi
, cu
);
7913 if (built_actual_name
!= NULL
)
7914 actual_name
= built_actual_name
.get ();
7916 if (actual_name
== NULL
)
7917 actual_name
= pdi
->name (cu
);
7919 partial_symbol psymbol
;
7920 memset (&psymbol
, 0, sizeof (psymbol
));
7921 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7922 &objfile
->objfile_obstack
);
7923 psymbol
.ginfo
.set_section_index (-1);
7925 /* The code below indicates that the psymbol should be installed by
7927 gdb::optional
<psymbol_placement
> where
;
7931 case DW_TAG_inlined_subroutine
:
7932 case DW_TAG_subprogram
:
7933 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7935 if (pdi
->is_external
7936 || cu
->per_cu
->lang
== language_ada
7937 || (cu
->per_cu
->lang
== language_fortran
7938 && pdi
->die_parent
!= NULL
7939 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7941 /* Normally, only "external" DIEs are part of the global scope.
7942 But in Ada and Fortran, we want to be able to access nested
7943 procedures globally. So all Ada and Fortran subprograms are
7944 stored in the global scope. */
7945 where
= psymbol_placement::GLOBAL
;
7948 where
= psymbol_placement::STATIC
;
7950 psymbol
.domain
= VAR_DOMAIN
;
7951 psymbol
.aclass
= LOC_BLOCK
;
7952 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7953 psymbol
.ginfo
.value
.address
= addr
;
7955 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7956 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7958 case DW_TAG_constant
:
7959 psymbol
.domain
= VAR_DOMAIN
;
7960 psymbol
.aclass
= LOC_STATIC
;
7961 where
= (pdi
->is_external
7962 ? psymbol_placement::GLOBAL
7963 : psymbol_placement::STATIC
);
7965 case DW_TAG_variable
:
7967 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7971 && !per_objfile
->per_bfd
->has_section_at_zero
)
7973 /* A global or static variable may also have been stripped
7974 out by the linker if unused, in which case its address
7975 will be nullified; do not add such variables into partial
7976 symbol table then. */
7978 else if (pdi
->is_external
)
7981 Don't enter into the minimal symbol tables as there is
7982 a minimal symbol table entry from the ELF symbols already.
7983 Enter into partial symbol table if it has a location
7984 descriptor or a type.
7985 If the location descriptor is missing, new_symbol will create
7986 a LOC_UNRESOLVED symbol, the address of the variable will then
7987 be determined from the minimal symbol table whenever the variable
7989 The address for the partial symbol table entry is not
7990 used by GDB, but it comes in handy for debugging partial symbol
7993 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7995 psymbol
.domain
= VAR_DOMAIN
;
7996 psymbol
.aclass
= LOC_STATIC
;
7997 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7998 psymbol
.ginfo
.value
.address
= addr
;
7999 where
= psymbol_placement::GLOBAL
;
8004 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8006 /* Static Variable. Skip symbols whose value we cannot know (those
8007 without location descriptors or constant values). */
8008 if (!has_loc
&& !pdi
->has_const_value
)
8011 psymbol
.domain
= VAR_DOMAIN
;
8012 psymbol
.aclass
= LOC_STATIC
;
8013 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8015 psymbol
.ginfo
.value
.address
= addr
;
8016 where
= psymbol_placement::STATIC
;
8019 case DW_TAG_array_type
:
8020 case DW_TAG_typedef
:
8021 case DW_TAG_base_type
:
8022 case DW_TAG_subrange_type
:
8023 psymbol
.domain
= VAR_DOMAIN
;
8024 psymbol
.aclass
= LOC_TYPEDEF
;
8025 where
= psymbol_placement::STATIC
;
8027 case DW_TAG_imported_declaration
:
8028 case DW_TAG_namespace
:
8029 psymbol
.domain
= VAR_DOMAIN
;
8030 psymbol
.aclass
= LOC_TYPEDEF
;
8031 where
= psymbol_placement::GLOBAL
;
8034 /* With Fortran 77 there might be a "BLOCK DATA" module
8035 available without any name. If so, we skip the module as it
8036 doesn't bring any value. */
8037 if (actual_name
!= nullptr)
8039 psymbol
.domain
= MODULE_DOMAIN
;
8040 psymbol
.aclass
= LOC_TYPEDEF
;
8041 where
= psymbol_placement::GLOBAL
;
8044 case DW_TAG_class_type
:
8045 case DW_TAG_interface_type
:
8046 case DW_TAG_structure_type
:
8047 case DW_TAG_union_type
:
8048 case DW_TAG_enumeration_type
:
8049 /* Skip external references. The DWARF standard says in the section
8050 about "Structure, Union, and Class Type Entries": "An incomplete
8051 structure, union or class type is represented by a structure,
8052 union or class entry that does not have a byte size attribute
8053 and that has a DW_AT_declaration attribute." */
8054 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8057 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8058 static vs. global. */
8059 psymbol
.domain
= STRUCT_DOMAIN
;
8060 psymbol
.aclass
= LOC_TYPEDEF
;
8061 where
= (cu
->per_cu
->lang
== language_cplus
8062 ? psymbol_placement::GLOBAL
8063 : psymbol_placement::STATIC
);
8065 case DW_TAG_enumerator
:
8066 psymbol
.domain
= VAR_DOMAIN
;
8067 psymbol
.aclass
= LOC_CONST
;
8068 where
= (cu
->per_cu
->lang
== language_cplus
8069 ? psymbol_placement::GLOBAL
8070 : psymbol_placement::STATIC
);
8076 if (where
.has_value ())
8078 if (built_actual_name
!= nullptr)
8079 actual_name
= objfile
->intern (actual_name
);
8080 if (pdi
->linkage_name
== nullptr
8081 || cu
->per_cu
->lang
== language_ada
)
8082 psymbol
.ginfo
.set_linkage_name (actual_name
);
8085 psymbol
.ginfo
.set_demangled_name (actual_name
,
8086 &objfile
->objfile_obstack
);
8087 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8089 cu
->per_cu
->v
.psymtab
->add_psymbol
8090 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8095 /* Read a partial die corresponding to a namespace; also, add a symbol
8096 corresponding to that namespace to the symbol table. NAMESPACE is
8097 the name of the enclosing namespace. */
8100 add_partial_namespace (struct partial_die_info
*pdi
,
8101 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8102 int set_addrmap
, struct dwarf2_cu
*cu
)
8104 /* Add a symbol for the namespace. */
8106 add_partial_symbol (pdi
, cu
);
8108 /* Now scan partial symbols in that namespace. */
8110 if (pdi
->has_children
)
8111 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8114 /* Read a partial die corresponding to a Fortran module. */
8117 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8118 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8120 /* Add a symbol for the namespace. */
8122 add_partial_symbol (pdi
, cu
);
8124 /* Now scan partial symbols in that module. */
8126 if (pdi
->has_children
)
8127 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8131 dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
8132 dwarf2_psymtab
*, dwarf_tag
);
8134 /* Read a partial die corresponding to a subprogram or an inlined
8135 subprogram and create a partial symbol for that subprogram.
8136 When the CU language allows it, this routine also defines a partial
8137 symbol for each nested subprogram that this subprogram contains.
8138 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8139 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8141 PDI may also be a lexical block, in which case we simply search
8142 recursively for subprograms defined inside that lexical block.
8143 Again, this is only performed when the CU language allows this
8144 type of definitions. */
8147 add_partial_subprogram (struct partial_die_info
*pdi
,
8148 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8149 int set_addrmap
, struct dwarf2_cu
*cu
)
8151 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8153 if (pdi
->has_pc_info
)
8155 if (pdi
->lowpc
< *lowpc
)
8156 *lowpc
= pdi
->lowpc
;
8157 if (pdi
->highpc
> *highpc
)
8158 *highpc
= pdi
->highpc
;
8161 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8162 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8163 struct gdbarch
*gdbarch
= objfile
->arch ();
8165 CORE_ADDR this_highpc
;
8166 CORE_ADDR this_lowpc
;
8168 baseaddr
= objfile
->text_section_offset ();
8170 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8171 pdi
->lowpc
+ baseaddr
)
8174 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8175 pdi
->highpc
+ baseaddr
)
8177 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8178 this_lowpc
, this_highpc
- 1,
8179 cu
->per_cu
->v
.psymtab
);
8183 if (pdi
->has_range_info
8184 && dwarf2_ranges_read (pdi
->ranges_offset
, &pdi
->lowpc
, &pdi
->highpc
,
8186 set_addrmap
? cu
->per_cu
->v
.psymtab
: nullptr,
8189 if (pdi
->lowpc
< *lowpc
)
8190 *lowpc
= pdi
->lowpc
;
8191 if (pdi
->highpc
> *highpc
)
8192 *highpc
= pdi
->highpc
;
8195 if (pdi
->has_pc_info
|| pdi
->has_range_info
8196 || (!pdi
->is_external
&& pdi
->may_be_inlined
))
8198 if (!pdi
->is_declaration
)
8199 /* Ignore subprogram DIEs that do not have a name, they are
8200 illegal. Do not emit a complaint at this point, we will
8201 do so when we convert this psymtab into a symtab. */
8203 add_partial_symbol (pdi
, cu
);
8207 if (! pdi
->has_children
)
8210 if (cu
->per_cu
->lang
== language_ada
8211 || cu
->per_cu
->lang
== language_fortran
)
8213 pdi
= pdi
->die_child
;
8217 if (pdi
->tag
== DW_TAG_subprogram
8218 || pdi
->tag
== DW_TAG_inlined_subroutine
8219 || pdi
->tag
== DW_TAG_lexical_block
)
8220 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8221 pdi
= pdi
->die_sibling
;
8226 /* Read a partial die corresponding to an enumeration type. */
8229 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8230 struct dwarf2_cu
*cu
)
8232 struct partial_die_info
*pdi
;
8234 if (enum_pdi
->name (cu
) != NULL
)
8235 add_partial_symbol (enum_pdi
, cu
);
8237 pdi
= enum_pdi
->die_child
;
8240 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8241 complaint (_("malformed enumerator DIE ignored"));
8243 add_partial_symbol (pdi
, cu
);
8244 pdi
= pdi
->die_sibling
;
8248 /* Return the initial uleb128 in the die at INFO_PTR. */
8251 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8253 unsigned int bytes_read
;
8255 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8258 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8259 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8261 Return the corresponding abbrev, or NULL if the number is zero (indicating
8262 an empty DIE). In either case *BYTES_READ will be set to the length of
8263 the initial number. */
8265 static const struct abbrev_info
*
8266 peek_die_abbrev (const die_reader_specs
&reader
,
8267 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8269 dwarf2_cu
*cu
= reader
.cu
;
8270 bfd
*abfd
= reader
.abfd
;
8271 unsigned int abbrev_number
8272 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8274 if (abbrev_number
== 0)
8277 const abbrev_info
*abbrev
8278 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8281 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8282 " at offset %s [in module %s]"),
8283 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8284 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8290 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8291 Returns a pointer to the end of a series of DIEs, terminated by an empty
8292 DIE. Any children of the skipped DIEs will also be skipped. */
8294 static const gdb_byte
*
8295 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8299 unsigned int bytes_read
;
8300 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8304 return info_ptr
+ bytes_read
;
8306 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8310 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8311 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8312 abbrev corresponding to that skipped uleb128 should be passed in
8313 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8316 static const gdb_byte
*
8317 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8318 const struct abbrev_info
*abbrev
)
8320 unsigned int bytes_read
;
8321 struct attribute attr
;
8322 bfd
*abfd
= reader
->abfd
;
8323 struct dwarf2_cu
*cu
= reader
->cu
;
8324 const gdb_byte
*buffer
= reader
->buffer
;
8325 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8326 unsigned int form
, i
;
8328 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8330 /* The only abbrev we care about is DW_AT_sibling. */
8331 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8333 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8334 if (attr
.form
== DW_FORM_ref_addr
)
8335 complaint (_("ignoring absolute DW_AT_sibling"));
8338 sect_offset off
= attr
.get_ref_die_offset ();
8339 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8341 if (sibling_ptr
< info_ptr
)
8342 complaint (_("DW_AT_sibling points backwards"));
8343 else if (sibling_ptr
> reader
->buffer_end
)
8344 reader
->die_section
->overflow_complaint ();
8350 /* If it isn't DW_AT_sibling, skip this attribute. */
8351 form
= abbrev
->attrs
[i
].form
;
8355 case DW_FORM_ref_addr
:
8356 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8357 and later it is offset sized. */
8358 if (cu
->header
.version
== 2)
8359 info_ptr
+= cu
->header
.addr_size
;
8361 info_ptr
+= cu
->header
.offset_size
;
8363 case DW_FORM_GNU_ref_alt
:
8364 info_ptr
+= cu
->header
.offset_size
;
8367 info_ptr
+= cu
->header
.addr_size
;
8375 case DW_FORM_flag_present
:
8376 case DW_FORM_implicit_const
:
8393 case DW_FORM_ref_sig8
:
8396 case DW_FORM_data16
:
8399 case DW_FORM_string
:
8400 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8401 info_ptr
+= bytes_read
;
8403 case DW_FORM_sec_offset
:
8405 case DW_FORM_GNU_strp_alt
:
8406 info_ptr
+= cu
->header
.offset_size
;
8408 case DW_FORM_exprloc
:
8410 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8411 info_ptr
+= bytes_read
;
8413 case DW_FORM_block1
:
8414 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8416 case DW_FORM_block2
:
8417 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8419 case DW_FORM_block4
:
8420 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8426 case DW_FORM_ref_udata
:
8427 case DW_FORM_GNU_addr_index
:
8428 case DW_FORM_GNU_str_index
:
8429 case DW_FORM_rnglistx
:
8430 case DW_FORM_loclistx
:
8431 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8433 case DW_FORM_indirect
:
8434 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8435 info_ptr
+= bytes_read
;
8436 /* We need to continue parsing from here, so just go back to
8438 goto skip_attribute
;
8441 error (_("Dwarf Error: Cannot handle %s "
8442 "in DWARF reader [in module %s]"),
8443 dwarf_form_name (form
),
8444 bfd_get_filename (abfd
));
8448 if (abbrev
->has_children
)
8449 return skip_children (reader
, info_ptr
);
8454 /* Locate ORIG_PDI's sibling.
8455 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8457 static const gdb_byte
*
8458 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8459 struct partial_die_info
*orig_pdi
,
8460 const gdb_byte
*info_ptr
)
8462 /* Do we know the sibling already? */
8464 if (orig_pdi
->sibling
)
8465 return orig_pdi
->sibling
;
8467 /* Are there any children to deal with? */
8469 if (!orig_pdi
->has_children
)
8472 /* Skip the children the long way. */
8474 return skip_children (reader
, info_ptr
);
8477 /* Expand this partial symbol table into a full symbol table. SELF is
8481 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8483 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8485 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8487 /* If this psymtab is constructed from a debug-only objfile, the
8488 has_section_at_zero flag will not necessarily be correct. We
8489 can get the correct value for this flag by looking at the data
8490 associated with the (presumably stripped) associated objfile. */
8491 if (objfile
->separate_debug_objfile_backlink
)
8493 dwarf2_per_objfile
*per_objfile_backlink
8494 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8496 per_objfile
->per_bfd
->has_section_at_zero
8497 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8500 expand_psymtab (objfile
);
8502 process_cu_includes (per_objfile
);
8505 /* Reading in full CUs. */
8507 /* Add PER_CU to the queue. */
8510 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8511 dwarf2_per_objfile
*per_objfile
,
8512 enum language pretend_language
)
8516 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8517 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8520 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8522 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8525 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8526 DIEs, false otherwise.
8528 Explanation: there is an invariant that if a CU is queued for expansion
8529 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8530 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8531 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8532 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8533 invariant is respected.
8535 The caller is therefore not required to load the CU's DIEs (we return false)
8538 - the CU is already expanded, and therefore does not get enqueued
8539 - the CU gets enqueued for expansion, but its DIEs are already loaded
8541 Note that the caller should not use this function's return value as an
8542 indicator of whether the CU's DIEs are loaded right now, it should check
8543 that by calling `dwarf2_per_objfile::get_cu` instead. */
8546 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8547 dwarf2_per_cu_data
*per_cu
,
8548 dwarf2_per_objfile
*per_objfile
,
8549 enum language pretend_language
)
8551 /* We may arrive here during partial symbol reading, if we need full
8552 DIEs to process an unusual case (e.g. template arguments). Do
8553 not queue PER_CU, just tell our caller to load its DIEs. */
8554 if (per_cu
->per_bfd
->reading_partial_symbols
)
8556 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8558 if (cu
== NULL
|| cu
->dies
== NULL
)
8563 /* Mark the dependence relation so that we don't flush PER_CU
8565 if (dependent_cu
!= NULL
)
8566 dependent_cu
->add_dependence (per_cu
);
8568 /* If it's already on the queue, we have nothing to do. */
8571 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8573 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8575 /* If the CU is queued for expansion, it should not already be
8577 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8579 /* The DIEs are already loaded, the caller doesn't need to do it. */
8583 bool queued
= false;
8584 if (!per_objfile
->symtab_set_p (per_cu
))
8586 /* Add it to the queue. */
8587 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8591 /* If the compilation unit is already loaded, just mark it as
8593 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8597 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8598 and the DIEs are not already loaded. */
8599 return queued
&& cu
== nullptr;
8602 /* Process the queue. */
8605 process_queue (dwarf2_per_objfile
*per_objfile
)
8607 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8608 objfile_name (per_objfile
->objfile
));
8610 /* The queue starts out with one item, but following a DIE reference
8611 may load a new CU, adding it to the end of the queue. */
8612 while (!per_objfile
->per_bfd
->queue
->empty ())
8614 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8615 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8617 if (!per_objfile
->symtab_set_p (per_cu
))
8619 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8621 /* Skip dummy CUs. */
8624 unsigned int debug_print_threshold
;
8627 if (per_cu
->is_debug_types
)
8629 struct signatured_type
*sig_type
=
8630 (struct signatured_type
*) per_cu
;
8632 sprintf (buf
, "TU %s at offset %s",
8633 hex_string (sig_type
->signature
),
8634 sect_offset_str (per_cu
->sect_off
));
8635 /* There can be 100s of TUs.
8636 Only print them in verbose mode. */
8637 debug_print_threshold
= 2;
8641 sprintf (buf
, "CU at offset %s",
8642 sect_offset_str (per_cu
->sect_off
));
8643 debug_print_threshold
= 1;
8646 if (dwarf_read_debug
>= debug_print_threshold
)
8647 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8649 if (per_cu
->is_debug_types
)
8650 process_full_type_unit (cu
, item
.pretend_language
);
8652 process_full_comp_unit (cu
, item
.pretend_language
);
8654 if (dwarf_read_debug
>= debug_print_threshold
)
8655 dwarf_read_debug_printf ("Done expanding %s", buf
);
8660 per_objfile
->per_bfd
->queue
->pop ();
8663 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8664 objfile_name (per_objfile
->objfile
));
8667 /* Read in full symbols for PST, and anything it depends on. */
8670 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8672 gdb_assert (!readin_p (objfile
));
8674 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8675 free_cached_comp_units
freer (per_objfile
);
8676 expand_dependencies (objfile
);
8678 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8679 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8682 /* See psympriv.h. */
8685 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8687 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8688 return per_objfile
->symtab_set_p (per_cu_data
);
8691 /* See psympriv.h. */
8694 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8696 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8697 return per_objfile
->get_symtab (per_cu_data
);
8700 /* Trivial hash function for die_info: the hash value of a DIE
8701 is its offset in .debug_info for this objfile. */
8704 die_hash (const void *item
)
8706 const struct die_info
*die
= (const struct die_info
*) item
;
8708 return to_underlying (die
->sect_off
);
8711 /* Trivial comparison function for die_info structures: two DIEs
8712 are equal if they have the same offset. */
8715 die_eq (const void *item_lhs
, const void *item_rhs
)
8717 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8718 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8720 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8723 /* Load the DIEs associated with PER_CU into memory.
8725 In some cases, the caller, while reading partial symbols, will need to load
8726 the full symbols for the CU for some reason. It will already have a
8727 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8728 rather than creating a new one. */
8731 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8732 dwarf2_per_objfile
*per_objfile
,
8733 dwarf2_cu
*existing_cu
,
8735 enum language pretend_language
)
8737 gdb_assert (! this_cu
->is_debug_types
);
8739 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8743 struct dwarf2_cu
*cu
= reader
.cu
;
8744 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8746 gdb_assert (cu
->die_hash
== NULL
);
8748 htab_create_alloc_ex (cu
->header
.length
/ 12,
8752 &cu
->comp_unit_obstack
,
8753 hashtab_obstack_allocate
,
8754 dummy_obstack_deallocate
);
8756 if (reader
.comp_unit_die
->has_children
)
8757 reader
.comp_unit_die
->child
8758 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8759 &info_ptr
, reader
.comp_unit_die
);
8760 cu
->dies
= reader
.comp_unit_die
;
8761 /* comp_unit_die is not stored in die_hash, no need. */
8763 /* We try not to read any attributes in this function, because not
8764 all CUs needed for references have been loaded yet, and symbol
8765 table processing isn't initialized. But we have to set the CU language,
8766 or we won't be able to build types correctly.
8767 Similarly, if we do not read the producer, we can not apply
8768 producer-specific interpretation. */
8769 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8774 /* Add a DIE to the delayed physname list. */
8777 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8778 const char *name
, struct die_info
*die
,
8779 struct dwarf2_cu
*cu
)
8781 struct delayed_method_info mi
;
8783 mi
.fnfield_index
= fnfield_index
;
8787 cu
->method_list
.push_back (mi
);
8790 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8791 "const" / "volatile". If so, decrements LEN by the length of the
8792 modifier and return true. Otherwise return false. */
8796 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8798 size_t mod_len
= sizeof (mod
) - 1;
8799 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8807 /* Compute the physnames of any methods on the CU's method list.
8809 The computation of method physnames is delayed in order to avoid the
8810 (bad) condition that one of the method's formal parameters is of an as yet
8814 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8816 /* Only C++ delays computing physnames. */
8817 if (cu
->method_list
.empty ())
8819 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8821 for (const delayed_method_info
&mi
: cu
->method_list
)
8823 const char *physname
;
8824 struct fn_fieldlist
*fn_flp
8825 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8826 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8827 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8828 = physname
? physname
: "";
8830 /* Since there's no tag to indicate whether a method is a
8831 const/volatile overload, extract that information out of the
8833 if (physname
!= NULL
)
8835 size_t len
= strlen (physname
);
8839 if (physname
[len
] == ')') /* shortcut */
8841 else if (check_modifier (physname
, len
, " const"))
8842 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8843 else if (check_modifier (physname
, len
, " volatile"))
8844 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8851 /* The list is no longer needed. */
8852 cu
->method_list
.clear ();
8855 /* Go objects should be embedded in a DW_TAG_module DIE,
8856 and it's not clear if/how imported objects will appear.
8857 To keep Go support simple until that's worked out,
8858 go back through what we've read and create something usable.
8859 We could do this while processing each DIE, and feels kinda cleaner,
8860 but that way is more invasive.
8861 This is to, for example, allow the user to type "p var" or "b main"
8862 without having to specify the package name, and allow lookups
8863 of module.object to work in contexts that use the expression
8867 fixup_go_packaging (struct dwarf2_cu
*cu
)
8869 gdb::unique_xmalloc_ptr
<char> package_name
;
8870 struct pending
*list
;
8873 for (list
= *cu
->get_builder ()->get_global_symbols ();
8877 for (i
= 0; i
< list
->nsyms
; ++i
)
8879 struct symbol
*sym
= list
->symbol
[i
];
8881 if (sym
->language () == language_go
8882 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8884 gdb::unique_xmalloc_ptr
<char> this_package_name
8885 (go_symbol_package_name (sym
));
8887 if (this_package_name
== NULL
)
8889 if (package_name
== NULL
)
8890 package_name
= std::move (this_package_name
);
8893 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8894 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8895 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8896 (symbol_symtab (sym
) != NULL
8897 ? symtab_to_filename_for_display
8898 (symbol_symtab (sym
))
8899 : objfile_name (objfile
)),
8900 this_package_name
.get (), package_name
.get ());
8906 if (package_name
!= NULL
)
8908 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8909 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8910 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8911 saved_package_name
);
8914 sym
= new (&objfile
->objfile_obstack
) symbol
;
8915 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8916 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8917 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8918 e.g., "main" finds the "main" module and not C's main(). */
8919 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8920 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8921 SYMBOL_TYPE (sym
) = type
;
8923 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8927 /* Allocate a fully-qualified name consisting of the two parts on the
8931 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8933 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8936 /* A helper that allocates a variant part to attach to a Rust enum
8937 type. OBSTACK is where the results should be allocated. TYPE is
8938 the type we're processing. DISCRIMINANT_INDEX is the index of the
8939 discriminant. It must be the index of one of the fields of TYPE,
8940 or -1 to mean there is no discriminant (univariant enum).
8941 DEFAULT_INDEX is the index of the default field; or -1 if there is
8942 no default. RANGES is indexed by "effective" field number (the
8943 field index, but omitting the discriminant and default fields) and
8944 must hold the discriminant values used by the variants. Note that
8945 RANGES must have a lifetime at least as long as OBSTACK -- either
8946 already allocated on it, or static. */
8949 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8950 int discriminant_index
, int default_index
,
8951 gdb::array_view
<discriminant_range
> ranges
)
8953 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8954 gdb_assert (discriminant_index
== -1
8955 || (discriminant_index
>= 0
8956 && discriminant_index
< type
->num_fields ()));
8957 gdb_assert (default_index
== -1
8958 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8960 /* We have one variant for each non-discriminant field. */
8961 int n_variants
= type
->num_fields ();
8962 if (discriminant_index
!= -1)
8965 variant
*variants
= new (obstack
) variant
[n_variants
];
8968 for (int i
= 0; i
< type
->num_fields (); ++i
)
8970 if (i
== discriminant_index
)
8973 variants
[var_idx
].first_field
= i
;
8974 variants
[var_idx
].last_field
= i
+ 1;
8976 /* The default field does not need a range, but other fields do.
8977 We skipped the discriminant above. */
8978 if (i
!= default_index
)
8980 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8987 gdb_assert (range_idx
== ranges
.size ());
8988 gdb_assert (var_idx
== n_variants
);
8990 variant_part
*part
= new (obstack
) variant_part
;
8991 part
->discriminant_index
= discriminant_index
;
8992 /* If there is no discriminant, then whether it is signed is of no
8995 = (discriminant_index
== -1
8997 : type
->field (discriminant_index
).type ()->is_unsigned ());
8998 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9000 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9001 gdb::array_view
<variant_part
> *prop_value
9002 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9004 struct dynamic_prop prop
;
9005 prop
.set_variant_parts (prop_value
);
9007 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9010 /* Some versions of rustc emitted enums in an unusual way.
9012 Ordinary enums were emitted as unions. The first element of each
9013 structure in the union was named "RUST$ENUM$DISR". This element
9014 held the discriminant.
9016 These versions of Rust also implemented the "non-zero"
9017 optimization. When the enum had two values, and one is empty and
9018 the other holds a pointer that cannot be zero, the pointer is used
9019 as the discriminant, with a zero value meaning the empty variant.
9020 Here, the union's first member is of the form
9021 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9022 where the fieldnos are the indices of the fields that should be
9023 traversed in order to find the field (which may be several fields deep)
9024 and the variantname is the name of the variant of the case when the
9027 This function recognizes whether TYPE is of one of these forms,
9028 and, if so, smashes it to be a variant type. */
9031 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9033 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9035 /* We don't need to deal with empty enums. */
9036 if (type
->num_fields () == 0)
9039 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9040 if (type
->num_fields () == 1
9041 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
9043 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
9045 /* Decode the field name to find the offset of the
9047 ULONGEST bit_offset
= 0;
9048 struct type
*field_type
= type
->field (0).type ();
9049 while (name
[0] >= '0' && name
[0] <= '9')
9052 unsigned long index
= strtoul (name
, &tail
, 10);
9055 || index
>= field_type
->num_fields ()
9056 || (field_type
->field (index
).loc_kind ()
9057 != FIELD_LOC_KIND_BITPOS
))
9059 complaint (_("Could not parse Rust enum encoding string \"%s\""
9061 type
->field (0).name (),
9062 objfile_name (objfile
));
9067 bit_offset
+= field_type
->field (index
).loc_bitpos ();
9068 field_type
= field_type
->field (index
).type ();
9071 /* Smash this type to be a structure type. We have to do this
9072 because the type has already been recorded. */
9073 type
->set_code (TYPE_CODE_STRUCT
);
9074 type
->set_num_fields (3);
9075 /* Save the field we care about. */
9076 struct field saved_field
= type
->field (0);
9078 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9080 /* Put the discriminant at index 0. */
9081 type
->field (0).set_type (field_type
);
9082 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9083 type
->field (0).set_name ("<<discriminant>>");
9084 type
->field (0).set_loc_bitpos (bit_offset
);
9086 /* The order of fields doesn't really matter, so put the real
9087 field at index 1 and the data-less field at index 2. */
9088 type
->field (1) = saved_field
;
9089 type
->field (1).set_name
9090 (rust_last_path_segment (type
->field (1).type ()->name ()));
9091 type
->field (1).type ()->set_name
9092 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9093 type
->field (1).name ()));
9095 const char *dataless_name
9096 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9098 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9100 type
->field (2).set_type (dataless_type
);
9101 /* NAME points into the original discriminant name, which
9102 already has the correct lifetime. */
9103 type
->field (2).set_name (name
);
9104 type
->field (2).set_loc_bitpos (0);
9106 /* Indicate that this is a variant type. */
9107 static discriminant_range ranges
[1] = { { 0, 0 } };
9108 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9110 /* A union with a single anonymous field is probably an old-style
9112 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
9114 /* Smash this type to be a structure type. We have to do this
9115 because the type has already been recorded. */
9116 type
->set_code (TYPE_CODE_STRUCT
);
9118 struct type
*field_type
= type
->field (0).type ();
9119 const char *variant_name
9120 = rust_last_path_segment (field_type
->name ());
9121 type
->field (0).set_name (variant_name
);
9122 field_type
->set_name
9123 (rust_fully_qualify (&objfile
->objfile_obstack
,
9124 type
->name (), variant_name
));
9126 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9130 struct type
*disr_type
= nullptr;
9131 for (int i
= 0; i
< type
->num_fields (); ++i
)
9133 disr_type
= type
->field (i
).type ();
9135 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9137 /* All fields of a true enum will be structs. */
9140 else if (disr_type
->num_fields () == 0)
9142 /* Could be data-less variant, so keep going. */
9143 disr_type
= nullptr;
9145 else if (strcmp (disr_type
->field (0).name (),
9146 "RUST$ENUM$DISR") != 0)
9148 /* Not a Rust enum. */
9158 /* If we got here without a discriminant, then it's probably
9160 if (disr_type
== nullptr)
9163 /* Smash this type to be a structure type. We have to do this
9164 because the type has already been recorded. */
9165 type
->set_code (TYPE_CODE_STRUCT
);
9167 /* Make space for the discriminant field. */
9168 struct field
*disr_field
= &disr_type
->field (0);
9170 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9171 * sizeof (struct field
)));
9172 memcpy (new_fields
+ 1, type
->fields (),
9173 type
->num_fields () * sizeof (struct field
));
9174 type
->set_fields (new_fields
);
9175 type
->set_num_fields (type
->num_fields () + 1);
9177 /* Install the discriminant at index 0 in the union. */
9178 type
->field (0) = *disr_field
;
9179 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9180 type
->field (0).set_name ("<<discriminant>>");
9182 /* We need a way to find the correct discriminant given a
9183 variant name. For convenience we build a map here. */
9184 struct type
*enum_type
= disr_field
->type ();
9185 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9186 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9188 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
9191 = rust_last_path_segment (enum_type
->field (i
).name ());
9192 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
9196 int n_fields
= type
->num_fields ();
9197 /* We don't need a range entry for the discriminant, but we do
9198 need one for every other field, as there is no default
9200 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9203 /* Skip the discriminant here. */
9204 for (int i
= 1; i
< n_fields
; ++i
)
9206 /* Find the final word in the name of this variant's type.
9207 That name can be used to look up the correct
9209 const char *variant_name
9210 = rust_last_path_segment (type
->field (i
).type ()->name ());
9212 auto iter
= discriminant_map
.find (variant_name
);
9213 if (iter
!= discriminant_map
.end ())
9215 ranges
[i
- 1].low
= iter
->second
;
9216 ranges
[i
- 1].high
= iter
->second
;
9219 /* In Rust, each element should have the size of the
9221 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9223 /* Remove the discriminant field, if it exists. */
9224 struct type
*sub_type
= type
->field (i
).type ();
9225 if (sub_type
->num_fields () > 0)
9227 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9228 sub_type
->set_fields (sub_type
->fields () + 1);
9230 type
->field (i
).set_name (variant_name
);
9232 (rust_fully_qualify (&objfile
->objfile_obstack
,
9233 type
->name (), variant_name
));
9236 /* Indicate that this is a variant type. */
9237 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9238 gdb::array_view
<discriminant_range
> (ranges
,
9243 /* Rewrite some Rust unions to be structures with variants parts. */
9246 rust_union_quirks (struct dwarf2_cu
*cu
)
9248 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9249 for (type
*type_
: cu
->rust_unions
)
9250 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9251 /* We don't need this any more. */
9252 cu
->rust_unions
.clear ();
9257 type_unit_group_unshareable
*
9258 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9260 auto iter
= this->m_type_units
.find (tu_group
);
9261 if (iter
!= this->m_type_units
.end ())
9262 return iter
->second
.get ();
9264 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9265 type_unit_group_unshareable
*result
= uniq
.get ();
9266 this->m_type_units
[tu_group
] = std::move (uniq
);
9271 dwarf2_per_objfile::get_type_for_signatured_type
9272 (signatured_type
*sig_type
) const
9274 auto iter
= this->m_type_map
.find (sig_type
);
9275 if (iter
== this->m_type_map
.end ())
9278 return iter
->second
;
9281 void dwarf2_per_objfile::set_type_for_signatured_type
9282 (signatured_type
*sig_type
, struct type
*type
)
9284 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9286 this->m_type_map
[sig_type
] = type
;
9289 /* A helper function for computing the list of all symbol tables
9290 included by PER_CU. */
9293 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9294 htab_t all_children
, htab_t all_type_symtabs
,
9295 dwarf2_per_cu_data
*per_cu
,
9296 dwarf2_per_objfile
*per_objfile
,
9297 struct compunit_symtab
*immediate_parent
)
9299 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9302 /* This inclusion and its children have been processed. */
9308 /* Only add a CU if it has a symbol table. */
9309 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9312 /* If this is a type unit only add its symbol table if we haven't
9313 seen it yet (type unit per_cu's can share symtabs). */
9314 if (per_cu
->is_debug_types
)
9316 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9320 result
->push_back (cust
);
9321 if (cust
->user
== NULL
)
9322 cust
->user
= immediate_parent
;
9327 result
->push_back (cust
);
9328 if (cust
->user
== NULL
)
9329 cust
->user
= immediate_parent
;
9333 if (!per_cu
->imported_symtabs_empty ())
9334 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9336 recursively_compute_inclusions (result
, all_children
,
9337 all_type_symtabs
, ptr
, per_objfile
,
9342 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9346 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9347 dwarf2_per_objfile
*per_objfile
)
9349 gdb_assert (! per_cu
->is_debug_types
);
9351 if (!per_cu
->imported_symtabs_empty ())
9354 std::vector
<compunit_symtab
*> result_symtabs
;
9355 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9357 /* If we don't have a symtab, we can just skip this case. */
9361 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9363 NULL
, xcalloc
, xfree
));
9364 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9366 NULL
, xcalloc
, xfree
));
9368 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9370 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9371 all_type_symtabs
.get (), ptr
,
9375 /* Now we have a transitive closure of all the included symtabs. */
9376 len
= result_symtabs
.size ();
9378 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9379 struct compunit_symtab
*, len
+ 1);
9380 memcpy (cust
->includes
, result_symtabs
.data (),
9381 len
* sizeof (compunit_symtab
*));
9382 cust
->includes
[len
] = NULL
;
9386 /* Compute the 'includes' field for the symtabs of all the CUs we just
9390 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9392 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9394 if (! iter
->is_debug_types
)
9395 compute_compunit_symtab_includes (iter
, per_objfile
);
9398 per_objfile
->per_bfd
->just_read_cus
.clear ();
9401 /* Generate full symbol information for CU, whose DIEs have
9402 already been loaded into memory. */
9405 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9407 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9408 struct objfile
*objfile
= per_objfile
->objfile
;
9409 struct gdbarch
*gdbarch
= objfile
->arch ();
9410 CORE_ADDR lowpc
, highpc
;
9411 struct compunit_symtab
*cust
;
9413 struct block
*static_block
;
9416 baseaddr
= objfile
->text_section_offset ();
9418 /* Clear the list here in case something was left over. */
9419 cu
->method_list
.clear ();
9421 dwarf2_find_base_address (cu
->dies
, cu
);
9423 /* Before we start reading the top-level DIE, ensure it has a valid tag
9425 switch (cu
->dies
->tag
)
9427 case DW_TAG_compile_unit
:
9428 case DW_TAG_partial_unit
:
9429 case DW_TAG_type_unit
:
9432 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9433 dwarf_tag_name (cu
->dies
->tag
),
9434 sect_offset_str (cu
->per_cu
->sect_off
),
9435 objfile_name (per_objfile
->objfile
));
9438 /* Do line number decoding in read_file_scope () */
9439 process_die (cu
->dies
, cu
);
9441 /* For now fudge the Go package. */
9442 if (cu
->per_cu
->lang
== language_go
)
9443 fixup_go_packaging (cu
);
9445 /* Now that we have processed all the DIEs in the CU, all the types
9446 should be complete, and it should now be safe to compute all of the
9448 compute_delayed_physnames (cu
);
9450 if (cu
->per_cu
->lang
== language_rust
)
9451 rust_union_quirks (cu
);
9453 /* Some compilers don't define a DW_AT_high_pc attribute for the
9454 compilation unit. If the DW_AT_high_pc is missing, synthesize
9455 it, by scanning the DIE's below the compilation unit. */
9456 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9458 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9459 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9461 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9462 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9463 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9464 addrmap to help ensure it has an accurate map of pc values belonging to
9466 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9468 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9469 SECT_OFF_TEXT (objfile
),
9474 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9476 /* Set symtab language to language from DW_AT_language. If the
9477 compilation is from a C file generated by language preprocessors, do
9478 not set the language if it was already deduced by start_subfile. */
9479 if (!(cu
->per_cu
->lang
== language_c
9480 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9481 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9483 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9484 produce DW_AT_location with location lists but it can be possibly
9485 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9486 there were bugs in prologue debug info, fixed later in GCC-4.5
9487 by "unwind info for epilogues" patch (which is not directly related).
9489 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9490 needed, it would be wrong due to missing DW_AT_producer there.
9492 Still one can confuse GDB by using non-standard GCC compilation
9493 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9495 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9496 cust
->locations_valid
= 1;
9498 if (gcc_4_minor
>= 5)
9499 cust
->epilogue_unwind_valid
= 1;
9501 cust
->set_call_site_htab (cu
->call_site_htab
);
9504 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9506 /* Push it for inclusion processing later. */
9507 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9509 /* Not needed any more. */
9510 cu
->reset_builder ();
9513 /* Generate full symbol information for type unit CU, whose DIEs have
9514 already been loaded into memory. */
9517 process_full_type_unit (dwarf2_cu
*cu
,
9518 enum language pretend_language
)
9520 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9521 struct objfile
*objfile
= per_objfile
->objfile
;
9522 struct compunit_symtab
*cust
;
9523 struct signatured_type
*sig_type
;
9525 gdb_assert (cu
->per_cu
->is_debug_types
);
9526 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9528 /* Clear the list here in case something was left over. */
9529 cu
->method_list
.clear ();
9531 /* The symbol tables are set up in read_type_unit_scope. */
9532 process_die (cu
->dies
, cu
);
9534 /* For now fudge the Go package. */
9535 if (cu
->per_cu
->lang
== language_go
)
9536 fixup_go_packaging (cu
);
9538 /* Now that we have processed all the DIEs in the CU, all the types
9539 should be complete, and it should now be safe to compute all of the
9541 compute_delayed_physnames (cu
);
9543 if (cu
->per_cu
->lang
== language_rust
)
9544 rust_union_quirks (cu
);
9546 /* TUs share symbol tables.
9547 If this is the first TU to use this symtab, complete the construction
9548 of it with end_expandable_symtab. Otherwise, complete the addition of
9549 this TU's symbols to the existing symtab. */
9550 type_unit_group_unshareable
*tug_unshare
=
9551 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9552 if (tug_unshare
->compunit_symtab
== NULL
)
9554 buildsym_compunit
*builder
= cu
->get_builder ();
9555 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9556 tug_unshare
->compunit_symtab
= cust
;
9560 /* Set symtab language to language from DW_AT_language. If the
9561 compilation is from a C file generated by language preprocessors,
9562 do not set the language if it was already deduced by
9564 if (!(cu
->per_cu
->lang
== language_c
9565 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9566 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9571 cu
->get_builder ()->augment_type_symtab ();
9572 cust
= tug_unshare
->compunit_symtab
;
9575 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9577 /* Not needed any more. */
9578 cu
->reset_builder ();
9581 /* Process an imported unit DIE. */
9584 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9586 struct attribute
*attr
;
9588 /* For now we don't handle imported units in type units. */
9589 if (cu
->per_cu
->is_debug_types
)
9591 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9592 " supported in type units [in module %s]"),
9593 objfile_name (cu
->per_objfile
->objfile
));
9596 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9599 sect_offset sect_off
= attr
->get_ref_die_offset ();
9600 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9601 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9602 dwarf2_per_cu_data
*per_cu
9603 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9604 per_objfile
->per_bfd
);
9606 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9607 into another compilation unit, at root level. Regard this as a hint,
9609 if (die
->parent
&& die
->parent
->parent
== NULL
9610 && per_cu
->unit_type
== DW_UT_compile
9611 && per_cu
->lang
== language_cplus
)
9614 /* If necessary, add it to the queue and load its DIEs. */
9615 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9617 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9618 false, cu
->per_cu
->lang
);
9620 cu
->per_cu
->imported_symtabs_push (per_cu
);
9624 /* RAII object that represents a process_die scope: i.e.,
9625 starts/finishes processing a DIE. */
9626 class process_die_scope
9629 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9630 : m_die (die
), m_cu (cu
)
9632 /* We should only be processing DIEs not already in process. */
9633 gdb_assert (!m_die
->in_process
);
9634 m_die
->in_process
= true;
9637 ~process_die_scope ()
9639 m_die
->in_process
= false;
9641 /* If we're done processing the DIE for the CU that owns the line
9642 header, we don't need the line header anymore. */
9643 if (m_cu
->line_header_die_owner
== m_die
)
9645 delete m_cu
->line_header
;
9646 m_cu
->line_header
= NULL
;
9647 m_cu
->line_header_die_owner
= NULL
;
9656 /* Process a die and its children. */
9659 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9661 process_die_scope
scope (die
, cu
);
9665 case DW_TAG_padding
:
9667 case DW_TAG_compile_unit
:
9668 case DW_TAG_partial_unit
:
9669 read_file_scope (die
, cu
);
9671 case DW_TAG_type_unit
:
9672 read_type_unit_scope (die
, cu
);
9674 case DW_TAG_subprogram
:
9675 /* Nested subprograms in Fortran get a prefix. */
9676 if (cu
->per_cu
->lang
== language_fortran
9677 && die
->parent
!= NULL
9678 && die
->parent
->tag
== DW_TAG_subprogram
)
9679 cu
->processing_has_namespace_info
= true;
9681 case DW_TAG_inlined_subroutine
:
9682 read_func_scope (die
, cu
);
9684 case DW_TAG_lexical_block
:
9685 case DW_TAG_try_block
:
9686 case DW_TAG_catch_block
:
9687 read_lexical_block_scope (die
, cu
);
9689 case DW_TAG_call_site
:
9690 case DW_TAG_GNU_call_site
:
9691 read_call_site_scope (die
, cu
);
9693 case DW_TAG_class_type
:
9694 case DW_TAG_interface_type
:
9695 case DW_TAG_structure_type
:
9696 case DW_TAG_union_type
:
9697 process_structure_scope (die
, cu
);
9699 case DW_TAG_enumeration_type
:
9700 process_enumeration_scope (die
, cu
);
9703 /* These dies have a type, but processing them does not create
9704 a symbol or recurse to process the children. Therefore we can
9705 read them on-demand through read_type_die. */
9706 case DW_TAG_subroutine_type
:
9707 case DW_TAG_set_type
:
9708 case DW_TAG_pointer_type
:
9709 case DW_TAG_ptr_to_member_type
:
9710 case DW_TAG_reference_type
:
9711 case DW_TAG_rvalue_reference_type
:
9712 case DW_TAG_string_type
:
9715 case DW_TAG_array_type
:
9716 /* We only need to handle this case for Ada -- in other
9717 languages, it's normal for the compiler to emit a typedef
9719 if (cu
->per_cu
->lang
!= language_ada
)
9722 case DW_TAG_base_type
:
9723 case DW_TAG_subrange_type
:
9724 case DW_TAG_typedef
:
9725 /* Add a typedef symbol for the type definition, if it has a
9727 new_symbol (die
, read_type_die (die
, cu
), cu
);
9729 case DW_TAG_common_block
:
9730 read_common_block (die
, cu
);
9732 case DW_TAG_common_inclusion
:
9734 case DW_TAG_namespace
:
9735 cu
->processing_has_namespace_info
= true;
9736 read_namespace (die
, cu
);
9739 cu
->processing_has_namespace_info
= true;
9740 read_module (die
, cu
);
9742 case DW_TAG_imported_declaration
:
9743 cu
->processing_has_namespace_info
= true;
9744 if (read_namespace_alias (die
, cu
))
9746 /* The declaration is not a global namespace alias. */
9748 case DW_TAG_imported_module
:
9749 cu
->processing_has_namespace_info
= true;
9750 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9751 || cu
->per_cu
->lang
!= language_fortran
))
9752 complaint (_("Tag '%s' has unexpected children"),
9753 dwarf_tag_name (die
->tag
));
9754 read_import_statement (die
, cu
);
9757 case DW_TAG_imported_unit
:
9758 process_imported_unit_die (die
, cu
);
9761 case DW_TAG_variable
:
9762 read_variable (die
, cu
);
9766 new_symbol (die
, NULL
, cu
);
9771 /* DWARF name computation. */
9773 /* A helper function for dwarf2_compute_name which determines whether DIE
9774 needs to have the name of the scope prepended to the name listed in the
9778 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9780 struct attribute
*attr
;
9784 case DW_TAG_namespace
:
9785 case DW_TAG_typedef
:
9786 case DW_TAG_class_type
:
9787 case DW_TAG_interface_type
:
9788 case DW_TAG_structure_type
:
9789 case DW_TAG_union_type
:
9790 case DW_TAG_enumeration_type
:
9791 case DW_TAG_enumerator
:
9792 case DW_TAG_subprogram
:
9793 case DW_TAG_inlined_subroutine
:
9795 case DW_TAG_imported_declaration
:
9798 case DW_TAG_variable
:
9799 case DW_TAG_constant
:
9800 /* We only need to prefix "globally" visible variables. These include
9801 any variable marked with DW_AT_external or any variable that
9802 lives in a namespace. [Variables in anonymous namespaces
9803 require prefixing, but they are not DW_AT_external.] */
9805 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9807 struct dwarf2_cu
*spec_cu
= cu
;
9809 return die_needs_namespace (die_specification (die
, &spec_cu
),
9813 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9814 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9815 && die
->parent
->tag
!= DW_TAG_module
)
9817 /* A variable in a lexical block of some kind does not need a
9818 namespace, even though in C++ such variables may be external
9819 and have a mangled name. */
9820 if (die
->parent
->tag
== DW_TAG_lexical_block
9821 || die
->parent
->tag
== DW_TAG_try_block
9822 || die
->parent
->tag
== DW_TAG_catch_block
9823 || die
->parent
->tag
== DW_TAG_subprogram
)
9832 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9833 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9834 defined for the given DIE. */
9836 static struct attribute
*
9837 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9839 struct attribute
*attr
;
9841 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9843 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9848 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9849 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9850 defined for the given DIE. */
9853 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9855 const char *linkage_name
;
9857 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9858 if (linkage_name
== NULL
)
9859 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9861 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9862 See https://github.com/rust-lang/rust/issues/32925. */
9863 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9864 && strchr (linkage_name
, '{') != NULL
)
9865 linkage_name
= NULL
;
9867 return linkage_name
;
9870 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9871 compute the physname for the object, which include a method's:
9872 - formal parameters (C++),
9873 - receiver type (Go),
9875 The term "physname" is a bit confusing.
9876 For C++, for example, it is the demangled name.
9877 For Go, for example, it's the mangled name.
9879 For Ada, return the DIE's linkage name rather than the fully qualified
9880 name. PHYSNAME is ignored..
9882 The result is allocated on the objfile->per_bfd's obstack and
9886 dwarf2_compute_name (const char *name
,
9887 struct die_info
*die
, struct dwarf2_cu
*cu
,
9890 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9893 name
= dwarf2_name (die
, cu
);
9895 enum language lang
= cu
->per_cu
->lang
;
9897 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9898 but otherwise compute it by typename_concat inside GDB.
9899 FIXME: Actually this is not really true, or at least not always true.
9900 It's all very confusing. compute_and_set_names doesn't try to demangle
9901 Fortran names because there is no mangling standard. So new_symbol
9902 will set the demangled name to the result of dwarf2_full_name, and it is
9903 the demangled name that GDB uses if it exists. */
9904 if (lang
== language_ada
9905 || (lang
== language_fortran
&& physname
))
9907 /* For Ada unit, we prefer the linkage name over the name, as
9908 the former contains the exported name, which the user expects
9909 to be able to reference. Ideally, we want the user to be able
9910 to reference this entity using either natural or linkage name,
9911 but we haven't started looking at this enhancement yet. */
9912 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9914 if (linkage_name
!= NULL
)
9915 return linkage_name
;
9918 /* These are the only languages we know how to qualify names in. */
9920 && (lang
== language_cplus
9921 || lang
== language_fortran
|| lang
== language_d
9922 || lang
== language_rust
))
9924 if (die_needs_namespace (die
, cu
))
9927 const char *canonical_name
= NULL
;
9931 prefix
= determine_prefix (die
, cu
);
9932 if (*prefix
!= '\0')
9934 gdb::unique_xmalloc_ptr
<char> prefixed_name
9935 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9937 buf
.puts (prefixed_name
.get ());
9942 /* Template parameters may be specified in the DIE's DW_AT_name, or
9943 as children with DW_TAG_template_type_param or
9944 DW_TAG_value_type_param. If the latter, add them to the name
9945 here. If the name already has template parameters, then
9946 skip this step; some versions of GCC emit both, and
9947 it is more efficient to use the pre-computed name.
9949 Something to keep in mind about this process: it is very
9950 unlikely, or in some cases downright impossible, to produce
9951 something that will match the mangled name of a function.
9952 If the definition of the function has the same debug info,
9953 we should be able to match up with it anyway. But fallbacks
9954 using the minimal symbol, for instance to find a method
9955 implemented in a stripped copy of libstdc++, will not work.
9956 If we do not have debug info for the definition, we will have to
9957 match them up some other way.
9959 When we do name matching there is a related problem with function
9960 templates; two instantiated function templates are allowed to
9961 differ only by their return types, which we do not add here. */
9963 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9965 struct attribute
*attr
;
9966 struct die_info
*child
;
9969 die
->building_fullname
= 1;
9971 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9975 const gdb_byte
*bytes
;
9976 struct dwarf2_locexpr_baton
*baton
;
9979 if (child
->tag
!= DW_TAG_template_type_param
9980 && child
->tag
!= DW_TAG_template_value_param
)
9991 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9994 complaint (_("template parameter missing DW_AT_type"));
9995 buf
.puts ("UNKNOWN_TYPE");
9998 type
= die_type (child
, cu
);
10000 if (child
->tag
== DW_TAG_template_type_param
)
10002 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
10003 &type_print_raw_options
);
10007 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10010 complaint (_("template parameter missing "
10011 "DW_AT_const_value"));
10012 buf
.puts ("UNKNOWN_VALUE");
10016 dwarf2_const_value_attr (attr
, type
, name
,
10017 &cu
->comp_unit_obstack
, cu
,
10018 &value
, &bytes
, &baton
);
10020 if (type
->has_no_signedness ())
10021 /* GDB prints characters as NUMBER 'CHAR'. If that's
10022 changed, this can use value_print instead. */
10023 cu
->language_defn
->printchar (value
, type
, &buf
);
10026 struct value_print_options opts
;
10029 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10033 baton
->per_objfile
);
10034 else if (bytes
!= NULL
)
10036 v
= allocate_value (type
);
10037 memcpy (value_contents_writeable (v
).data (), bytes
,
10038 TYPE_LENGTH (type
));
10041 v
= value_from_longest (type
, value
);
10043 /* Specify decimal so that we do not depend on
10045 get_formatted_print_options (&opts
, 'd');
10047 value_print (v
, &buf
, &opts
);
10052 die
->building_fullname
= 0;
10056 /* Close the argument list, with a space if necessary
10057 (nested templates). */
10058 if (!buf
.empty () && buf
.string ().back () == '>')
10065 /* For C++ methods, append formal parameter type
10066 information, if PHYSNAME. */
10068 if (physname
&& die
->tag
== DW_TAG_subprogram
10069 && lang
== language_cplus
)
10071 struct type
*type
= read_type_die (die
, cu
);
10073 c_type_print_args (type
, &buf
, 1, lang
,
10074 &type_print_raw_options
);
10076 if (lang
== language_cplus
)
10078 /* Assume that an artificial first parameter is
10079 "this", but do not crash if it is not. RealView
10080 marks unnamed (and thus unused) parameters as
10081 artificial; there is no way to differentiate
10083 if (type
->num_fields () > 0
10084 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10085 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10086 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10087 buf
.puts (" const");
10091 const std::string
&intermediate_name
= buf
.string ();
10093 if (lang
== language_cplus
)
10095 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10098 /* If we only computed INTERMEDIATE_NAME, or if
10099 INTERMEDIATE_NAME is already canonical, then we need to
10101 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10102 name
= objfile
->intern (intermediate_name
);
10104 name
= canonical_name
;
10111 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10112 If scope qualifiers are appropriate they will be added. The result
10113 will be allocated on the storage_obstack, or NULL if the DIE does
10114 not have a name. NAME may either be from a previous call to
10115 dwarf2_name or NULL.
10117 The output string will be canonicalized (if C++). */
10119 static const char *
10120 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10122 return dwarf2_compute_name (name
, die
, cu
, 0);
10125 /* Construct a physname for the given DIE in CU. NAME may either be
10126 from a previous call to dwarf2_name or NULL. The result will be
10127 allocated on the objfile_objstack or NULL if the DIE does not have a
10130 The output string will be canonicalized (if C++). */
10132 static const char *
10133 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10135 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10136 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10139 /* In this case dwarf2_compute_name is just a shortcut not building anything
10141 if (!die_needs_namespace (die
, cu
))
10142 return dwarf2_compute_name (name
, die
, cu
, 1);
10144 if (cu
->per_cu
->lang
!= language_rust
)
10145 mangled
= dw2_linkage_name (die
, cu
);
10147 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10149 gdb::unique_xmalloc_ptr
<char> demangled
;
10150 if (mangled
!= NULL
)
10152 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10154 /* Do nothing (do not demangle the symbol name). */
10158 /* Use DMGL_RET_DROP for C++ template functions to suppress
10159 their return type. It is easier for GDB users to search
10160 for such functions as `name(params)' than `long name(params)'.
10161 In such case the minimal symbol names do not match the full
10162 symbol names but for template functions there is never a need
10163 to look up their definition from their declaration so
10164 the only disadvantage remains the minimal symbol variant
10165 `long name(params)' does not have the proper inferior type. */
10166 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
10170 canon
= demangled
.get ();
10178 if (canon
== NULL
|| check_physname
)
10180 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10182 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10184 /* It may not mean a bug in GDB. The compiler could also
10185 compute DW_AT_linkage_name incorrectly. But in such case
10186 GDB would need to be bug-to-bug compatible. */
10188 complaint (_("Computed physname <%s> does not match demangled <%s> "
10189 "(from linkage <%s>) - DIE at %s [in module %s]"),
10190 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10191 objfile_name (objfile
));
10193 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10194 is available here - over computed PHYSNAME. It is safer
10195 against both buggy GDB and buggy compilers. */
10209 retval
= objfile
->intern (retval
);
10214 /* Inspect DIE in CU for a namespace alias. If one exists, record
10215 a new symbol for it.
10217 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10220 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10222 struct attribute
*attr
;
10224 /* If the die does not have a name, this is not a namespace
10226 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10230 struct die_info
*d
= die
;
10231 struct dwarf2_cu
*imported_cu
= cu
;
10233 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10234 keep inspecting DIEs until we hit the underlying import. */
10235 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10236 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10238 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10242 d
= follow_die_ref (d
, attr
, &imported_cu
);
10243 if (d
->tag
!= DW_TAG_imported_declaration
)
10247 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10249 complaint (_("DIE at %s has too many recursively imported "
10250 "declarations"), sect_offset_str (d
->sect_off
));
10257 sect_offset sect_off
= attr
->get_ref_die_offset ();
10259 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10260 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10262 /* This declaration is a global namespace alias. Add
10263 a symbol for it whose type is the aliased namespace. */
10264 new_symbol (die
, type
, cu
);
10273 /* Return the using directives repository (global or local?) to use in the
10274 current context for CU.
10276 For Ada, imported declarations can materialize renamings, which *may* be
10277 global. However it is impossible (for now?) in DWARF to distinguish
10278 "external" imported declarations and "static" ones. As all imported
10279 declarations seem to be static in all other languages, make them all CU-wide
10280 global only in Ada. */
10282 static struct using_direct
**
10283 using_directives (struct dwarf2_cu
*cu
)
10285 if (cu
->per_cu
->lang
== language_ada
10286 && cu
->get_builder ()->outermost_context_p ())
10287 return cu
->get_builder ()->get_global_using_directives ();
10289 return cu
->get_builder ()->get_local_using_directives ();
10292 /* Read the import statement specified by the given die and record it. */
10295 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10297 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10298 struct attribute
*import_attr
;
10299 struct die_info
*imported_die
, *child_die
;
10300 struct dwarf2_cu
*imported_cu
;
10301 const char *imported_name
;
10302 const char *imported_name_prefix
;
10303 const char *canonical_name
;
10304 const char *import_alias
;
10305 const char *imported_declaration
= NULL
;
10306 const char *import_prefix
;
10307 std::vector
<const char *> excludes
;
10309 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10310 if (import_attr
== NULL
)
10312 complaint (_("Tag '%s' has no DW_AT_import"),
10313 dwarf_tag_name (die
->tag
));
10318 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10319 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10320 if (imported_name
== NULL
)
10322 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10324 The import in the following code:
10338 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10339 <52> DW_AT_decl_file : 1
10340 <53> DW_AT_decl_line : 6
10341 <54> DW_AT_import : <0x75>
10342 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10343 <59> DW_AT_name : B
10344 <5b> DW_AT_decl_file : 1
10345 <5c> DW_AT_decl_line : 2
10346 <5d> DW_AT_type : <0x6e>
10348 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10349 <76> DW_AT_byte_size : 4
10350 <77> DW_AT_encoding : 5 (signed)
10352 imports the wrong die ( 0x75 instead of 0x58 ).
10353 This case will be ignored until the gcc bug is fixed. */
10357 /* Figure out the local name after import. */
10358 import_alias
= dwarf2_name (die
, cu
);
10360 /* Figure out where the statement is being imported to. */
10361 import_prefix
= determine_prefix (die
, cu
);
10363 /* Figure out what the scope of the imported die is and prepend it
10364 to the name of the imported die. */
10365 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10367 if (imported_die
->tag
!= DW_TAG_namespace
10368 && imported_die
->tag
!= DW_TAG_module
)
10370 imported_declaration
= imported_name
;
10371 canonical_name
= imported_name_prefix
;
10373 else if (strlen (imported_name_prefix
) > 0)
10374 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10375 imported_name_prefix
,
10376 (cu
->per_cu
->lang
== language_d
10379 imported_name
, (char *) NULL
);
10381 canonical_name
= imported_name
;
10383 if (die
->tag
== DW_TAG_imported_module
10384 && cu
->per_cu
->lang
== language_fortran
)
10385 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10386 child_die
= child_die
->sibling
)
10388 /* DWARF-4: A Fortran use statement with a “rename list” may be
10389 represented by an imported module entry with an import attribute
10390 referring to the module and owned entries corresponding to those
10391 entities that are renamed as part of being imported. */
10393 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10395 complaint (_("child DW_TAG_imported_declaration expected "
10396 "- DIE at %s [in module %s]"),
10397 sect_offset_str (child_die
->sect_off
),
10398 objfile_name (objfile
));
10402 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10403 if (import_attr
== NULL
)
10405 complaint (_("Tag '%s' has no DW_AT_import"),
10406 dwarf_tag_name (child_die
->tag
));
10411 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10413 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10414 if (imported_name
== NULL
)
10416 complaint (_("child DW_TAG_imported_declaration has unknown "
10417 "imported name - DIE at %s [in module %s]"),
10418 sect_offset_str (child_die
->sect_off
),
10419 objfile_name (objfile
));
10423 excludes
.push_back (imported_name
);
10425 process_die (child_die
, cu
);
10428 add_using_directive (using_directives (cu
),
10432 imported_declaration
,
10435 &objfile
->objfile_obstack
);
10438 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10439 types, but gives them a size of zero. Starting with version 14,
10440 ICC is compatible with GCC. */
10443 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10445 if (!cu
->checked_producer
)
10446 check_producer (cu
);
10448 return cu
->producer_is_icc_lt_14
;
10451 /* ICC generates a DW_AT_type for C void functions. This was observed on
10452 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10453 which says that void functions should not have a DW_AT_type. */
10456 producer_is_icc (struct dwarf2_cu
*cu
)
10458 if (!cu
->checked_producer
)
10459 check_producer (cu
);
10461 return cu
->producer_is_icc
;
10464 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10465 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10466 this, it was first present in GCC release 4.3.0. */
10469 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10471 if (!cu
->checked_producer
)
10472 check_producer (cu
);
10474 return cu
->producer_is_gcc_lt_4_3
;
10477 static file_and_directory
&
10478 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10480 if (cu
->per_cu
->fnd
!= nullptr)
10481 return *cu
->per_cu
->fnd
;
10483 /* Find the filename. Do not use dwarf2_name here, since the filename
10484 is not a source language identifier. */
10485 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
10486 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
10488 if (res
.get_comp_dir () == nullptr
10489 && producer_is_gcc_lt_4_3 (cu
)
10490 && res
.get_name () != nullptr
10491 && IS_ABSOLUTE_PATH (res
.get_name ()))
10492 res
.set_comp_dir (ldirname (res
.get_name ()));
10494 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
10495 return *cu
->per_cu
->fnd
;
10498 /* Handle DW_AT_stmt_list for a compilation unit.
10499 DIE is the DW_TAG_compile_unit die for CU.
10500 COMP_DIR is the compilation directory. LOWPC is passed to
10501 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10504 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10505 const file_and_directory
&fnd
, CORE_ADDR lowpc
) /* ARI: editCase function */
10507 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10508 struct attribute
*attr
;
10509 struct line_header line_header_local
;
10510 hashval_t line_header_local_hash
;
10512 int decode_mapping
;
10514 gdb_assert (! cu
->per_cu
->is_debug_types
);
10516 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10517 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10520 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10522 /* The line header hash table is only created if needed (it exists to
10523 prevent redundant reading of the line table for partial_units).
10524 If we're given a partial_unit, we'll need it. If we're given a
10525 compile_unit, then use the line header hash table if it's already
10526 created, but don't create one just yet. */
10528 if (per_objfile
->line_header_hash
== NULL
10529 && die
->tag
== DW_TAG_partial_unit
)
10531 per_objfile
->line_header_hash
10532 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10533 line_header_eq_voidp
,
10534 htab_delete_entry
<line_header
>,
10538 line_header_local
.sect_off
= line_offset
;
10539 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10540 line_header_local_hash
= line_header_hash (&line_header_local
);
10541 if (per_objfile
->line_header_hash
!= NULL
)
10543 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10544 &line_header_local
,
10545 line_header_local_hash
, NO_INSERT
);
10547 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10548 is not present in *SLOT (since if there is something in *SLOT then
10549 it will be for a partial_unit). */
10550 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10552 gdb_assert (*slot
!= NULL
);
10553 cu
->line_header
= (struct line_header
*) *slot
;
10558 /* dwarf_decode_line_header does not yet provide sufficient information.
10559 We always have to call also dwarf_decode_lines for it. */
10560 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10564 cu
->line_header
= lh
.release ();
10565 cu
->line_header_die_owner
= die
;
10567 if (per_objfile
->line_header_hash
== NULL
)
10571 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10572 &line_header_local
,
10573 line_header_local_hash
, INSERT
);
10574 gdb_assert (slot
!= NULL
);
10576 if (slot
!= NULL
&& *slot
== NULL
)
10578 /* This newly decoded line number information unit will be owned
10579 by line_header_hash hash table. */
10580 *slot
= cu
->line_header
;
10581 cu
->line_header_die_owner
= NULL
;
10585 /* We cannot free any current entry in (*slot) as that struct line_header
10586 may be already used by multiple CUs. Create only temporary decoded
10587 line_header for this CU - it may happen at most once for each line
10588 number information unit. And if we're not using line_header_hash
10589 then this is what we want as well. */
10590 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10592 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10593 dwarf_decode_lines (cu
->line_header
, fnd
, cu
, nullptr, lowpc
,
10598 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10601 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10603 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10604 struct objfile
*objfile
= per_objfile
->objfile
;
10605 struct gdbarch
*gdbarch
= objfile
->arch ();
10606 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10607 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10608 struct attribute
*attr
;
10609 struct die_info
*child_die
;
10610 CORE_ADDR baseaddr
;
10612 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10613 baseaddr
= objfile
->text_section_offset ();
10615 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10617 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10618 from finish_block. */
10619 if (lowpc
== ((CORE_ADDR
) -1))
10621 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10623 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
10625 cu
->start_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
), lowpc
);
10627 gdb_assert (per_objfile
->sym_cu
== nullptr);
10628 scoped_restore restore_sym_cu
10629 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10631 /* Decode line number information if present. We do this before
10632 processing child DIEs, so that the line header table is available
10633 for DW_AT_decl_file. */
10634 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
);
10636 /* Process all dies in compilation unit. */
10637 if (die
->child
!= NULL
)
10639 child_die
= die
->child
;
10640 while (child_die
&& child_die
->tag
)
10642 process_die (child_die
, cu
);
10643 child_die
= child_die
->sibling
;
10646 per_objfile
->sym_cu
= nullptr;
10648 /* Decode macro information, if present. Dwarf 2 macro information
10649 refers to information in the line number info statement program
10650 header, so we can only read it if we've read the header
10652 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10654 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10655 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10657 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10658 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10660 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10664 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10665 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10667 unsigned int macro_offset
= attr
->as_unsigned ();
10669 dwarf_decode_macros (cu
, macro_offset
, 0);
10675 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10677 struct type_unit_group
*tu_group
;
10679 struct attribute
*attr
;
10681 struct signatured_type
*sig_type
;
10683 gdb_assert (per_cu
->is_debug_types
);
10684 sig_type
= (struct signatured_type
*) per_cu
;
10686 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10688 /* If we're using .gdb_index (includes -readnow) then
10689 per_cu->type_unit_group may not have been set up yet. */
10690 if (sig_type
->type_unit_group
== NULL
)
10691 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10692 tu_group
= sig_type
->type_unit_group
;
10694 /* If we've already processed this stmt_list there's no real need to
10695 do it again, we could fake it and just recreate the part we need
10696 (file name,index -> symtab mapping). If data shows this optimization
10697 is useful we can do it then. */
10698 type_unit_group_unshareable
*tug_unshare
10699 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10700 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10702 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10705 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10707 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10708 lh
= dwarf_decode_line_header (line_offset
, this);
10713 start_symtab ("", NULL
, 0);
10716 gdb_assert (tug_unshare
->symtabs
== NULL
);
10717 gdb_assert (m_builder
== nullptr);
10718 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10719 m_builder
.reset (new struct buildsym_compunit
10720 (COMPUNIT_OBJFILE (cust
), "",
10721 COMPUNIT_DIRNAME (cust
),
10722 compunit_language (cust
),
10724 list_in_scope
= get_builder ()->get_file_symbols ();
10729 line_header
= lh
.release ();
10730 line_header_die_owner
= die
;
10734 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10736 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10737 still initializing it, and our caller (a few levels up)
10738 process_full_type_unit still needs to know if this is the first
10741 tug_unshare
->symtabs
10742 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10743 struct symtab
*, line_header
->file_names_size ());
10745 auto &file_names
= line_header
->file_names ();
10746 for (i
= 0; i
< file_names
.size (); ++i
)
10748 file_entry
&fe
= file_names
[i
];
10749 dwarf2_start_subfile (this, fe
.name
,
10750 fe
.include_dir (line_header
));
10751 buildsym_compunit
*b
= get_builder ();
10752 if (b
->get_current_subfile ()->symtab
== NULL
)
10754 /* NOTE: start_subfile will recognize when it's been
10755 passed a file it has already seen. So we can't
10756 assume there's a simple mapping from
10757 cu->line_header->file_names to subfiles, plus
10758 cu->line_header->file_names may contain dups. */
10759 b
->get_current_subfile ()->symtab
10760 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10763 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10764 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10769 gdb_assert (m_builder
== nullptr);
10770 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10771 m_builder
.reset (new struct buildsym_compunit
10772 (COMPUNIT_OBJFILE (cust
), "",
10773 COMPUNIT_DIRNAME (cust
),
10774 compunit_language (cust
),
10776 list_in_scope
= get_builder ()->get_file_symbols ();
10778 auto &file_names
= line_header
->file_names ();
10779 for (i
= 0; i
< file_names
.size (); ++i
)
10781 file_entry
&fe
= file_names
[i
];
10782 fe
.symtab
= tug_unshare
->symtabs
[i
];
10786 /* The main symtab is allocated last. Type units don't have DW_AT_name
10787 so they don't have a "real" (so to speak) symtab anyway.
10788 There is later code that will assign the main symtab to all symbols
10789 that don't have one. We need to handle the case of a symbol with a
10790 missing symtab (DW_AT_decl_file) anyway. */
10793 /* Process DW_TAG_type_unit.
10794 For TUs we want to skip the first top level sibling if it's not the
10795 actual type being defined by this TU. In this case the first top
10796 level sibling is there to provide context only. */
10799 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10801 struct die_info
*child_die
;
10803 prepare_one_comp_unit (cu
, die
, language_minimal
);
10805 /* Initialize (or reinitialize) the machinery for building symtabs.
10806 We do this before processing child DIEs, so that the line header table
10807 is available for DW_AT_decl_file. */
10808 cu
->setup_type_unit_groups (die
);
10810 if (die
->child
!= NULL
)
10812 child_die
= die
->child
;
10813 while (child_die
&& child_die
->tag
)
10815 process_die (child_die
, cu
);
10816 child_die
= child_die
->sibling
;
10823 http://gcc.gnu.org/wiki/DebugFission
10824 http://gcc.gnu.org/wiki/DebugFissionDWP
10826 To simplify handling of both DWO files ("object" files with the DWARF info)
10827 and DWP files (a file with the DWOs packaged up into one file), we treat
10828 DWP files as having a collection of virtual DWO files. */
10831 hash_dwo_file (const void *item
)
10833 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10836 hash
= htab_hash_string (dwo_file
->dwo_name
);
10837 if (dwo_file
->comp_dir
!= NULL
)
10838 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10843 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10845 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10846 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10848 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10850 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10851 return lhs
->comp_dir
== rhs
->comp_dir
;
10852 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10855 /* Allocate a hash table for DWO files. */
10858 allocate_dwo_file_hash_table ()
10860 return htab_up (htab_create_alloc (41,
10863 htab_delete_entry
<dwo_file
>,
10867 /* Lookup DWO file DWO_NAME. */
10870 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10871 const char *dwo_name
,
10872 const char *comp_dir
)
10874 struct dwo_file find_entry
;
10877 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10878 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10880 find_entry
.dwo_name
= dwo_name
;
10881 find_entry
.comp_dir
= comp_dir
;
10882 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10889 hash_dwo_unit (const void *item
)
10891 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10893 /* This drops the top 32 bits of the id, but is ok for a hash. */
10894 return dwo_unit
->signature
;
10898 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10900 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10901 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10903 /* The signature is assumed to be unique within the DWO file.
10904 So while object file CU dwo_id's always have the value zero,
10905 that's OK, assuming each object file DWO file has only one CU,
10906 and that's the rule for now. */
10907 return lhs
->signature
== rhs
->signature
;
10910 /* Allocate a hash table for DWO CUs,TUs.
10911 There is one of these tables for each of CUs,TUs for each DWO file. */
10914 allocate_dwo_unit_table ()
10916 /* Start out with a pretty small number.
10917 Generally DWO files contain only one CU and maybe some TUs. */
10918 return htab_up (htab_create_alloc (3,
10921 NULL
, xcalloc
, xfree
));
10924 /* die_reader_func for create_dwo_cu. */
10927 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10928 const gdb_byte
*info_ptr
,
10929 struct die_info
*comp_unit_die
,
10930 struct dwo_file
*dwo_file
,
10931 struct dwo_unit
*dwo_unit
)
10933 struct dwarf2_cu
*cu
= reader
->cu
;
10934 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10935 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10937 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10938 if (!signature
.has_value ())
10940 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10941 " its dwo_id [in module %s]"),
10942 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10946 dwo_unit
->dwo_file
= dwo_file
;
10947 dwo_unit
->signature
= *signature
;
10948 dwo_unit
->section
= section
;
10949 dwo_unit
->sect_off
= sect_off
;
10950 dwo_unit
->length
= cu
->per_cu
->length
;
10952 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10953 sect_offset_str (sect_off
),
10954 hex_string (dwo_unit
->signature
));
10957 /* Create the dwo_units for the CUs in a DWO_FILE.
10958 Note: This function processes DWO files only, not DWP files. */
10961 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10962 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10963 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10965 struct objfile
*objfile
= per_objfile
->objfile
;
10966 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10967 const gdb_byte
*info_ptr
, *end_ptr
;
10969 section
.read (objfile
);
10970 info_ptr
= section
.buffer
;
10972 if (info_ptr
== NULL
)
10975 dwarf_read_debug_printf ("Reading %s for %s:",
10976 section
.get_name (),
10977 section
.get_file_name ());
10979 end_ptr
= info_ptr
+ section
.size
;
10980 while (info_ptr
< end_ptr
)
10982 struct dwarf2_per_cu_data per_cu
;
10983 struct dwo_unit read_unit
{};
10984 struct dwo_unit
*dwo_unit
;
10986 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10988 per_cu
.per_bfd
= per_bfd
;
10989 per_cu
.is_debug_types
= 0;
10990 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10991 per_cu
.section
= §ion
;
10993 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10994 if (!reader
.dummy_p
)
10995 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10996 &dwo_file
, &read_unit
);
10997 info_ptr
+= per_cu
.length
;
10999 // If the unit could not be parsed, skip it.
11000 if (read_unit
.dwo_file
== NULL
)
11003 if (cus_htab
== NULL
)
11004 cus_htab
= allocate_dwo_unit_table ();
11006 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11008 *dwo_unit
= read_unit
;
11009 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11010 gdb_assert (slot
!= NULL
);
11013 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11014 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11016 complaint (_("debug cu entry at offset %s is duplicate to"
11017 " the entry at offset %s, signature %s"),
11018 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11019 hex_string (dwo_unit
->signature
));
11021 *slot
= (void *)dwo_unit
;
11025 /* DWP file .debug_{cu,tu}_index section format:
11026 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11027 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11029 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11030 officially standard DWP format was published with DWARF v5 and is called
11031 Version 5. There are no versions 3 or 4.
11035 Both index sections have the same format, and serve to map a 64-bit
11036 signature to a set of section numbers. Each section begins with a header,
11037 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11038 indexes, and a pool of 32-bit section numbers. The index sections will be
11039 aligned at 8-byte boundaries in the file.
11041 The index section header consists of:
11043 V, 32 bit version number
11045 N, 32 bit number of compilation units or type units in the index
11046 M, 32 bit number of slots in the hash table
11048 Numbers are recorded using the byte order of the application binary.
11050 The hash table begins at offset 16 in the section, and consists of an array
11051 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11052 order of the application binary). Unused slots in the hash table are 0.
11053 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11055 The parallel table begins immediately after the hash table
11056 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11057 array of 32-bit indexes (using the byte order of the application binary),
11058 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11059 table contains a 32-bit index into the pool of section numbers. For unused
11060 hash table slots, the corresponding entry in the parallel table will be 0.
11062 The pool of section numbers begins immediately following the hash table
11063 (at offset 16 + 12 * M from the beginning of the section). The pool of
11064 section numbers consists of an array of 32-bit words (using the byte order
11065 of the application binary). Each item in the array is indexed starting
11066 from 0. The hash table entry provides the index of the first section
11067 number in the set. Additional section numbers in the set follow, and the
11068 set is terminated by a 0 entry (section number 0 is not used in ELF).
11070 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11071 section must be the first entry in the set, and the .debug_abbrev.dwo must
11072 be the second entry. Other members of the set may follow in any order.
11076 DWP Versions 2 and 5:
11078 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11079 and the entries in the index tables are now offsets into these sections.
11080 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11083 Index Section Contents:
11085 Hash Table of Signatures dwp_hash_table.hash_table
11086 Parallel Table of Indices dwp_hash_table.unit_table
11087 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11088 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11090 The index section header consists of:
11092 V, 32 bit version number
11093 L, 32 bit number of columns in the table of section offsets
11094 N, 32 bit number of compilation units or type units in the index
11095 M, 32 bit number of slots in the hash table
11097 Numbers are recorded using the byte order of the application binary.
11099 The hash table has the same format as version 1.
11100 The parallel table of indices has the same format as version 1,
11101 except that the entries are origin-1 indices into the table of sections
11102 offsets and the table of section sizes.
11104 The table of offsets begins immediately following the parallel table
11105 (at offset 16 + 12 * M from the beginning of the section). The table is
11106 a two-dimensional array of 32-bit words (using the byte order of the
11107 application binary), with L columns and N+1 rows, in row-major order.
11108 Each row in the array is indexed starting from 0. The first row provides
11109 a key to the remaining rows: each column in this row provides an identifier
11110 for a debug section, and the offsets in the same column of subsequent rows
11111 refer to that section. The section identifiers for Version 2 are:
11113 DW_SECT_INFO 1 .debug_info.dwo
11114 DW_SECT_TYPES 2 .debug_types.dwo
11115 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11116 DW_SECT_LINE 4 .debug_line.dwo
11117 DW_SECT_LOC 5 .debug_loc.dwo
11118 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11119 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11120 DW_SECT_MACRO 8 .debug_macro.dwo
11122 The section identifiers for Version 5 are:
11124 DW_SECT_INFO_V5 1 .debug_info.dwo
11125 DW_SECT_RESERVED_V5 2 --
11126 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11127 DW_SECT_LINE_V5 4 .debug_line.dwo
11128 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11129 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11130 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11131 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11133 The offsets provided by the CU and TU index sections are the base offsets
11134 for the contributions made by each CU or TU to the corresponding section
11135 in the package file. Each CU and TU header contains an abbrev_offset
11136 field, used to find the abbreviations table for that CU or TU within the
11137 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11138 be interpreted as relative to the base offset given in the index section.
11139 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11140 should be interpreted as relative to the base offset for .debug_line.dwo,
11141 and offsets into other debug sections obtained from DWARF attributes should
11142 also be interpreted as relative to the corresponding base offset.
11144 The table of sizes begins immediately following the table of offsets.
11145 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11146 with L columns and N rows, in row-major order. Each row in the array is
11147 indexed starting from 1 (row 0 is shared by the two tables).
11151 Hash table lookup is handled the same in version 1 and 2:
11153 We assume that N and M will not exceed 2^32 - 1.
11154 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11156 Given a 64-bit compilation unit signature or a type signature S, an entry
11157 in the hash table is located as follows:
11159 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11160 the low-order k bits all set to 1.
11162 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11164 3) If the hash table entry at index H matches the signature, use that
11165 entry. If the hash table entry at index H is unused (all zeroes),
11166 terminate the search: the signature is not present in the table.
11168 4) Let H = (H + H') modulo M. Repeat at Step 3.
11170 Because M > N and H' and M are relatively prime, the search is guaranteed
11171 to stop at an unused slot or find the match. */
11173 /* Create a hash table to map DWO IDs to their CU/TU entry in
11174 .debug_{info,types}.dwo in DWP_FILE.
11175 Returns NULL if there isn't one.
11176 Note: This function processes DWP files only, not DWO files. */
11178 static struct dwp_hash_table
*
11179 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11180 struct dwp_file
*dwp_file
, int is_debug_types
)
11182 struct objfile
*objfile
= per_objfile
->objfile
;
11183 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11184 const gdb_byte
*index_ptr
, *index_end
;
11185 struct dwarf2_section_info
*index
;
11186 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11187 struct dwp_hash_table
*htab
;
11189 if (is_debug_types
)
11190 index
= &dwp_file
->sections
.tu_index
;
11192 index
= &dwp_file
->sections
.cu_index
;
11194 if (index
->empty ())
11196 index
->read (objfile
);
11198 index_ptr
= index
->buffer
;
11199 index_end
= index_ptr
+ index
->size
;
11201 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11202 For now it's safe to just read 4 bytes (particularly as it's difficult to
11203 tell if you're dealing with Version 5 before you've read the version). */
11204 version
= read_4_bytes (dbfd
, index_ptr
);
11206 if (version
== 2 || version
== 5)
11207 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11211 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11213 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11216 if (version
!= 1 && version
!= 2 && version
!= 5)
11218 error (_("Dwarf Error: unsupported DWP file version (%s)"
11219 " [in module %s]"),
11220 pulongest (version
), dwp_file
->name
);
11222 if (nr_slots
!= (nr_slots
& -nr_slots
))
11224 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11225 " is not power of 2 [in module %s]"),
11226 pulongest (nr_slots
), dwp_file
->name
);
11229 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11230 htab
->version
= version
;
11231 htab
->nr_columns
= nr_columns
;
11232 htab
->nr_units
= nr_units
;
11233 htab
->nr_slots
= nr_slots
;
11234 htab
->hash_table
= index_ptr
;
11235 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11237 /* Exit early if the table is empty. */
11238 if (nr_slots
== 0 || nr_units
== 0
11239 || (version
== 2 && nr_columns
== 0)
11240 || (version
== 5 && nr_columns
== 0))
11242 /* All must be zero. */
11243 if (nr_slots
!= 0 || nr_units
!= 0
11244 || (version
== 2 && nr_columns
!= 0)
11245 || (version
== 5 && nr_columns
!= 0))
11247 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11248 " all zero [in modules %s]"),
11256 htab
->section_pool
.v1
.indices
=
11257 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11258 /* It's harder to decide whether the section is too small in v1.
11259 V1 is deprecated anyway so we punt. */
11261 else if (version
== 2)
11263 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11264 int *ids
= htab
->section_pool
.v2
.section_ids
;
11265 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11266 /* Reverse map for error checking. */
11267 int ids_seen
[DW_SECT_MAX
+ 1];
11270 if (nr_columns
< 2)
11272 error (_("Dwarf Error: bad DWP hash table, too few columns"
11273 " in section table [in module %s]"),
11276 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11278 error (_("Dwarf Error: bad DWP hash table, too many columns"
11279 " in section table [in module %s]"),
11282 memset (ids
, 255, sizeof_ids
);
11283 memset (ids_seen
, 255, sizeof (ids_seen
));
11284 for (i
= 0; i
< nr_columns
; ++i
)
11286 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11288 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11290 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11291 " in section table [in module %s]"),
11292 id
, dwp_file
->name
);
11294 if (ids_seen
[id
] != -1)
11296 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11297 " id %d in section table [in module %s]"),
11298 id
, dwp_file
->name
);
11303 /* Must have exactly one info or types section. */
11304 if (((ids_seen
[DW_SECT_INFO
] != -1)
11305 + (ids_seen
[DW_SECT_TYPES
] != -1))
11308 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11309 " DWO info/types section [in module %s]"),
11312 /* Must have an abbrev section. */
11313 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11315 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11316 " section [in module %s]"),
11319 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11320 htab
->section_pool
.v2
.sizes
=
11321 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11322 * nr_units
* nr_columns
);
11323 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11324 * nr_units
* nr_columns
))
11327 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11328 " [in module %s]"),
11332 else /* version == 5 */
11334 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11335 int *ids
= htab
->section_pool
.v5
.section_ids
;
11336 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11337 /* Reverse map for error checking. */
11338 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11340 if (nr_columns
< 2)
11342 error (_("Dwarf Error: bad DWP hash table, too few columns"
11343 " in section table [in module %s]"),
11346 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11348 error (_("Dwarf Error: bad DWP hash table, too many columns"
11349 " in section table [in module %s]"),
11352 memset (ids
, 255, sizeof_ids
);
11353 memset (ids_seen
, 255, sizeof (ids_seen
));
11354 for (int i
= 0; i
< nr_columns
; ++i
)
11356 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11358 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11360 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11361 " in section table [in module %s]"),
11362 id
, dwp_file
->name
);
11364 if (ids_seen
[id
] != -1)
11366 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11367 " id %d in section table [in module %s]"),
11368 id
, dwp_file
->name
);
11373 /* Must have seen an info section. */
11374 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11376 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11377 " DWO info/types section [in module %s]"),
11380 /* Must have an abbrev section. */
11381 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11383 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11384 " section [in module %s]"),
11387 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11388 htab
->section_pool
.v5
.sizes
11389 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11390 * nr_units
* nr_columns
);
11391 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11392 * nr_units
* nr_columns
))
11395 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11396 " [in module %s]"),
11404 /* Update SECTIONS with the data from SECTP.
11406 This function is like the other "locate" section routines, but in
11407 this context the sections to read comes from the DWP V1 hash table,
11408 not the full ELF section table.
11410 The result is non-zero for success, or zero if an error was found. */
11413 locate_v1_virtual_dwo_sections (asection
*sectp
,
11414 struct virtual_v1_dwo_sections
*sections
)
11416 const struct dwop_section_names
*names
= &dwop_section_names
;
11418 if (names
->abbrev_dwo
.matches (sectp
->name
))
11420 /* There can be only one. */
11421 if (sections
->abbrev
.s
.section
!= NULL
)
11423 sections
->abbrev
.s
.section
= sectp
;
11424 sections
->abbrev
.size
= bfd_section_size (sectp
);
11426 else if (names
->info_dwo
.matches (sectp
->name
)
11427 || names
->types_dwo
.matches (sectp
->name
))
11429 /* There can be only one. */
11430 if (sections
->info_or_types
.s
.section
!= NULL
)
11432 sections
->info_or_types
.s
.section
= sectp
;
11433 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11435 else if (names
->line_dwo
.matches (sectp
->name
))
11437 /* There can be only one. */
11438 if (sections
->line
.s
.section
!= NULL
)
11440 sections
->line
.s
.section
= sectp
;
11441 sections
->line
.size
= bfd_section_size (sectp
);
11443 else if (names
->loc_dwo
.matches (sectp
->name
))
11445 /* There can be only one. */
11446 if (sections
->loc
.s
.section
!= NULL
)
11448 sections
->loc
.s
.section
= sectp
;
11449 sections
->loc
.size
= bfd_section_size (sectp
);
11451 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11453 /* There can be only one. */
11454 if (sections
->macinfo
.s
.section
!= NULL
)
11456 sections
->macinfo
.s
.section
= sectp
;
11457 sections
->macinfo
.size
= bfd_section_size (sectp
);
11459 else if (names
->macro_dwo
.matches (sectp
->name
))
11461 /* There can be only one. */
11462 if (sections
->macro
.s
.section
!= NULL
)
11464 sections
->macro
.s
.section
= sectp
;
11465 sections
->macro
.size
= bfd_section_size (sectp
);
11467 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11469 /* There can be only one. */
11470 if (sections
->str_offsets
.s
.section
!= NULL
)
11472 sections
->str_offsets
.s
.section
= sectp
;
11473 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11477 /* No other kind of section is valid. */
11484 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11485 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11486 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11487 This is for DWP version 1 files. */
11489 static struct dwo_unit
*
11490 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11491 struct dwp_file
*dwp_file
,
11492 uint32_t unit_index
,
11493 const char *comp_dir
,
11494 ULONGEST signature
, int is_debug_types
)
11496 const struct dwp_hash_table
*dwp_htab
=
11497 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11498 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11499 const char *kind
= is_debug_types
? "TU" : "CU";
11500 struct dwo_file
*dwo_file
;
11501 struct dwo_unit
*dwo_unit
;
11502 struct virtual_v1_dwo_sections sections
;
11503 void **dwo_file_slot
;
11506 gdb_assert (dwp_file
->version
== 1);
11508 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11509 kind
, pulongest (unit_index
), hex_string (signature
),
11512 /* Fetch the sections of this DWO unit.
11513 Put a limit on the number of sections we look for so that bad data
11514 doesn't cause us to loop forever. */
11516 #define MAX_NR_V1_DWO_SECTIONS \
11517 (1 /* .debug_info or .debug_types */ \
11518 + 1 /* .debug_abbrev */ \
11519 + 1 /* .debug_line */ \
11520 + 1 /* .debug_loc */ \
11521 + 1 /* .debug_str_offsets */ \
11522 + 1 /* .debug_macro or .debug_macinfo */ \
11523 + 1 /* trailing zero */)
11525 memset (§ions
, 0, sizeof (sections
));
11527 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11530 uint32_t section_nr
=
11531 read_4_bytes (dbfd
,
11532 dwp_htab
->section_pool
.v1
.indices
11533 + (unit_index
+ i
) * sizeof (uint32_t));
11535 if (section_nr
== 0)
11537 if (section_nr
>= dwp_file
->num_sections
)
11539 error (_("Dwarf Error: bad DWP hash table, section number too large"
11540 " [in module %s]"),
11544 sectp
= dwp_file
->elf_sections
[section_nr
];
11545 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11547 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11548 " [in module %s]"),
11554 || sections
.info_or_types
.empty ()
11555 || sections
.abbrev
.empty ())
11557 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11558 " [in module %s]"),
11561 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11563 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11564 " [in module %s]"),
11568 /* It's easier for the rest of the code if we fake a struct dwo_file and
11569 have dwo_unit "live" in that. At least for now.
11571 The DWP file can be made up of a random collection of CUs and TUs.
11572 However, for each CU + set of TUs that came from the same original DWO
11573 file, we can combine them back into a virtual DWO file to save space
11574 (fewer struct dwo_file objects to allocate). Remember that for really
11575 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11577 std::string virtual_dwo_name
=
11578 string_printf ("virtual-dwo/%d-%d-%d-%d",
11579 sections
.abbrev
.get_id (),
11580 sections
.line
.get_id (),
11581 sections
.loc
.get_id (),
11582 sections
.str_offsets
.get_id ());
11583 /* Can we use an existing virtual DWO file? */
11584 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11586 /* Create one if necessary. */
11587 if (*dwo_file_slot
== NULL
)
11589 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11590 virtual_dwo_name
.c_str ());
11592 dwo_file
= new struct dwo_file
;
11593 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11594 dwo_file
->comp_dir
= comp_dir
;
11595 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11596 dwo_file
->sections
.line
= sections
.line
;
11597 dwo_file
->sections
.loc
= sections
.loc
;
11598 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11599 dwo_file
->sections
.macro
= sections
.macro
;
11600 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11601 /* The "str" section is global to the entire DWP file. */
11602 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11603 /* The info or types section is assigned below to dwo_unit,
11604 there's no need to record it in dwo_file.
11605 Also, we can't simply record type sections in dwo_file because
11606 we record a pointer into the vector in dwo_unit. As we collect more
11607 types we'll grow the vector and eventually have to reallocate space
11608 for it, invalidating all copies of pointers into the previous
11610 *dwo_file_slot
= dwo_file
;
11614 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11615 virtual_dwo_name
.c_str ());
11617 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11620 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11621 dwo_unit
->dwo_file
= dwo_file
;
11622 dwo_unit
->signature
= signature
;
11623 dwo_unit
->section
=
11624 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11625 *dwo_unit
->section
= sections
.info_or_types
;
11626 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11631 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11632 simplify them. Given a pointer to the containing section SECTION, and
11633 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11634 virtual section of just that piece. */
11636 static struct dwarf2_section_info
11637 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11638 struct dwarf2_section_info
*section
,
11639 bfd_size_type offset
, bfd_size_type size
)
11641 struct dwarf2_section_info result
;
11644 gdb_assert (section
!= NULL
);
11645 gdb_assert (!section
->is_virtual
);
11647 memset (&result
, 0, sizeof (result
));
11648 result
.s
.containing_section
= section
;
11649 result
.is_virtual
= true;
11654 sectp
= section
->get_bfd_section ();
11656 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11657 bounds of the real section. This is a pretty-rare event, so just
11658 flag an error (easier) instead of a warning and trying to cope. */
11660 || offset
+ size
> bfd_section_size (sectp
))
11662 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11663 " in section %s [in module %s]"),
11664 sectp
? bfd_section_name (sectp
) : "<unknown>",
11665 objfile_name (per_objfile
->objfile
));
11668 result
.virtual_offset
= offset
;
11669 result
.size
= size
;
11673 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11674 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11675 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11676 This is for DWP version 2 files. */
11678 static struct dwo_unit
*
11679 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11680 struct dwp_file
*dwp_file
,
11681 uint32_t unit_index
,
11682 const char *comp_dir
,
11683 ULONGEST signature
, int is_debug_types
)
11685 const struct dwp_hash_table
*dwp_htab
=
11686 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11687 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11688 const char *kind
= is_debug_types
? "TU" : "CU";
11689 struct dwo_file
*dwo_file
;
11690 struct dwo_unit
*dwo_unit
;
11691 struct virtual_v2_or_v5_dwo_sections sections
;
11692 void **dwo_file_slot
;
11695 gdb_assert (dwp_file
->version
== 2);
11697 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11698 kind
, pulongest (unit_index
), hex_string (signature
),
11701 /* Fetch the section offsets of this DWO unit. */
11703 memset (§ions
, 0, sizeof (sections
));
11705 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11707 uint32_t offset
= read_4_bytes (dbfd
,
11708 dwp_htab
->section_pool
.v2
.offsets
11709 + (((unit_index
- 1) * dwp_htab
->nr_columns
11711 * sizeof (uint32_t)));
11712 uint32_t size
= read_4_bytes (dbfd
,
11713 dwp_htab
->section_pool
.v2
.sizes
11714 + (((unit_index
- 1) * dwp_htab
->nr_columns
11716 * sizeof (uint32_t)));
11718 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11721 case DW_SECT_TYPES
:
11722 sections
.info_or_types_offset
= offset
;
11723 sections
.info_or_types_size
= size
;
11725 case DW_SECT_ABBREV
:
11726 sections
.abbrev_offset
= offset
;
11727 sections
.abbrev_size
= size
;
11730 sections
.line_offset
= offset
;
11731 sections
.line_size
= size
;
11734 sections
.loc_offset
= offset
;
11735 sections
.loc_size
= size
;
11737 case DW_SECT_STR_OFFSETS
:
11738 sections
.str_offsets_offset
= offset
;
11739 sections
.str_offsets_size
= size
;
11741 case DW_SECT_MACINFO
:
11742 sections
.macinfo_offset
= offset
;
11743 sections
.macinfo_size
= size
;
11745 case DW_SECT_MACRO
:
11746 sections
.macro_offset
= offset
;
11747 sections
.macro_size
= size
;
11752 /* It's easier for the rest of the code if we fake a struct dwo_file and
11753 have dwo_unit "live" in that. At least for now.
11755 The DWP file can be made up of a random collection of CUs and TUs.
11756 However, for each CU + set of TUs that came from the same original DWO
11757 file, we can combine them back into a virtual DWO file to save space
11758 (fewer struct dwo_file objects to allocate). Remember that for really
11759 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11761 std::string virtual_dwo_name
=
11762 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11763 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11764 (long) (sections
.line_size
? sections
.line_offset
: 0),
11765 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11766 (long) (sections
.str_offsets_size
11767 ? sections
.str_offsets_offset
: 0));
11768 /* Can we use an existing virtual DWO file? */
11769 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11771 /* Create one if necessary. */
11772 if (*dwo_file_slot
== NULL
)
11774 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11775 virtual_dwo_name
.c_str ());
11777 dwo_file
= new struct dwo_file
;
11778 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11779 dwo_file
->comp_dir
= comp_dir
;
11780 dwo_file
->sections
.abbrev
=
11781 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11782 sections
.abbrev_offset
,
11783 sections
.abbrev_size
);
11784 dwo_file
->sections
.line
=
11785 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11786 sections
.line_offset
,
11787 sections
.line_size
);
11788 dwo_file
->sections
.loc
=
11789 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11790 sections
.loc_offset
, sections
.loc_size
);
11791 dwo_file
->sections
.macinfo
=
11792 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11793 sections
.macinfo_offset
,
11794 sections
.macinfo_size
);
11795 dwo_file
->sections
.macro
=
11796 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11797 sections
.macro_offset
,
11798 sections
.macro_size
);
11799 dwo_file
->sections
.str_offsets
=
11800 create_dwp_v2_or_v5_section (per_objfile
,
11801 &dwp_file
->sections
.str_offsets
,
11802 sections
.str_offsets_offset
,
11803 sections
.str_offsets_size
);
11804 /* The "str" section is global to the entire DWP file. */
11805 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11806 /* The info or types section is assigned below to dwo_unit,
11807 there's no need to record it in dwo_file.
11808 Also, we can't simply record type sections in dwo_file because
11809 we record a pointer into the vector in dwo_unit. As we collect more
11810 types we'll grow the vector and eventually have to reallocate space
11811 for it, invalidating all copies of pointers into the previous
11813 *dwo_file_slot
= dwo_file
;
11817 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11818 virtual_dwo_name
.c_str ());
11820 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11823 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11824 dwo_unit
->dwo_file
= dwo_file
;
11825 dwo_unit
->signature
= signature
;
11826 dwo_unit
->section
=
11827 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11828 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11831 ? &dwp_file
->sections
.types
11832 : &dwp_file
->sections
.info
,
11833 sections
.info_or_types_offset
,
11834 sections
.info_or_types_size
);
11835 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11840 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11841 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11842 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11843 This is for DWP version 5 files. */
11845 static struct dwo_unit
*
11846 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11847 struct dwp_file
*dwp_file
,
11848 uint32_t unit_index
,
11849 const char *comp_dir
,
11850 ULONGEST signature
, int is_debug_types
)
11852 const struct dwp_hash_table
*dwp_htab
11853 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11854 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11855 const char *kind
= is_debug_types
? "TU" : "CU";
11856 struct dwo_file
*dwo_file
;
11857 struct dwo_unit
*dwo_unit
;
11858 struct virtual_v2_or_v5_dwo_sections sections
{};
11859 void **dwo_file_slot
;
11861 gdb_assert (dwp_file
->version
== 5);
11863 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11864 kind
, pulongest (unit_index
), hex_string (signature
),
11867 /* Fetch the section offsets of this DWO unit. */
11869 /* memset (§ions, 0, sizeof (sections)); */
11871 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11873 uint32_t offset
= read_4_bytes (dbfd
,
11874 dwp_htab
->section_pool
.v5
.offsets
11875 + (((unit_index
- 1)
11876 * dwp_htab
->nr_columns
11878 * sizeof (uint32_t)));
11879 uint32_t size
= read_4_bytes (dbfd
,
11880 dwp_htab
->section_pool
.v5
.sizes
11881 + (((unit_index
- 1) * dwp_htab
->nr_columns
11883 * sizeof (uint32_t)));
11885 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11887 case DW_SECT_ABBREV_V5
:
11888 sections
.abbrev_offset
= offset
;
11889 sections
.abbrev_size
= size
;
11891 case DW_SECT_INFO_V5
:
11892 sections
.info_or_types_offset
= offset
;
11893 sections
.info_or_types_size
= size
;
11895 case DW_SECT_LINE_V5
:
11896 sections
.line_offset
= offset
;
11897 sections
.line_size
= size
;
11899 case DW_SECT_LOCLISTS_V5
:
11900 sections
.loclists_offset
= offset
;
11901 sections
.loclists_size
= size
;
11903 case DW_SECT_MACRO_V5
:
11904 sections
.macro_offset
= offset
;
11905 sections
.macro_size
= size
;
11907 case DW_SECT_RNGLISTS_V5
:
11908 sections
.rnglists_offset
= offset
;
11909 sections
.rnglists_size
= size
;
11911 case DW_SECT_STR_OFFSETS_V5
:
11912 sections
.str_offsets_offset
= offset
;
11913 sections
.str_offsets_size
= size
;
11915 case DW_SECT_RESERVED_V5
:
11921 /* It's easier for the rest of the code if we fake a struct dwo_file and
11922 have dwo_unit "live" in that. At least for now.
11924 The DWP file can be made up of a random collection of CUs and TUs.
11925 However, for each CU + set of TUs that came from the same original DWO
11926 file, we can combine them back into a virtual DWO file to save space
11927 (fewer struct dwo_file objects to allocate). Remember that for really
11928 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11930 std::string virtual_dwo_name
=
11931 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11932 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11933 (long) (sections
.line_size
? sections
.line_offset
: 0),
11934 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11935 (long) (sections
.str_offsets_size
11936 ? sections
.str_offsets_offset
: 0),
11937 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11938 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11939 /* Can we use an existing virtual DWO file? */
11940 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11941 virtual_dwo_name
.c_str (),
11943 /* Create one if necessary. */
11944 if (*dwo_file_slot
== NULL
)
11946 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11947 virtual_dwo_name
.c_str ());
11949 dwo_file
= new struct dwo_file
;
11950 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11951 dwo_file
->comp_dir
= comp_dir
;
11952 dwo_file
->sections
.abbrev
=
11953 create_dwp_v2_or_v5_section (per_objfile
,
11954 &dwp_file
->sections
.abbrev
,
11955 sections
.abbrev_offset
,
11956 sections
.abbrev_size
);
11957 dwo_file
->sections
.line
=
11958 create_dwp_v2_or_v5_section (per_objfile
,
11959 &dwp_file
->sections
.line
,
11960 sections
.line_offset
, sections
.line_size
);
11961 dwo_file
->sections
.macro
=
11962 create_dwp_v2_or_v5_section (per_objfile
,
11963 &dwp_file
->sections
.macro
,
11964 sections
.macro_offset
,
11965 sections
.macro_size
);
11966 dwo_file
->sections
.loclists
=
11967 create_dwp_v2_or_v5_section (per_objfile
,
11968 &dwp_file
->sections
.loclists
,
11969 sections
.loclists_offset
,
11970 sections
.loclists_size
);
11971 dwo_file
->sections
.rnglists
=
11972 create_dwp_v2_or_v5_section (per_objfile
,
11973 &dwp_file
->sections
.rnglists
,
11974 sections
.rnglists_offset
,
11975 sections
.rnglists_size
);
11976 dwo_file
->sections
.str_offsets
=
11977 create_dwp_v2_or_v5_section (per_objfile
,
11978 &dwp_file
->sections
.str_offsets
,
11979 sections
.str_offsets_offset
,
11980 sections
.str_offsets_size
);
11981 /* The "str" section is global to the entire DWP file. */
11982 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11983 /* The info or types section is assigned below to dwo_unit,
11984 there's no need to record it in dwo_file.
11985 Also, we can't simply record type sections in dwo_file because
11986 we record a pointer into the vector in dwo_unit. As we collect more
11987 types we'll grow the vector and eventually have to reallocate space
11988 for it, invalidating all copies of pointers into the previous
11990 *dwo_file_slot
= dwo_file
;
11994 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11995 virtual_dwo_name
.c_str ());
11997 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12000 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12001 dwo_unit
->dwo_file
= dwo_file
;
12002 dwo_unit
->signature
= signature
;
12004 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12005 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12006 &dwp_file
->sections
.info
,
12007 sections
.info_or_types_offset
,
12008 sections
.info_or_types_size
);
12009 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12014 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12015 Returns NULL if the signature isn't found. */
12017 static struct dwo_unit
*
12018 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12019 struct dwp_file
*dwp_file
, const char *comp_dir
,
12020 ULONGEST signature
, int is_debug_types
)
12022 const struct dwp_hash_table
*dwp_htab
=
12023 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12024 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12025 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12026 uint32_t hash
= signature
& mask
;
12027 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12030 struct dwo_unit find_dwo_cu
;
12032 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12033 find_dwo_cu
.signature
= signature
;
12034 slot
= htab_find_slot (is_debug_types
12035 ? dwp_file
->loaded_tus
.get ()
12036 : dwp_file
->loaded_cus
.get (),
12037 &find_dwo_cu
, INSERT
);
12040 return (struct dwo_unit
*) *slot
;
12042 /* Use a for loop so that we don't loop forever on bad debug info. */
12043 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12045 ULONGEST signature_in_table
;
12047 signature_in_table
=
12048 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12049 if (signature_in_table
== signature
)
12051 uint32_t unit_index
=
12052 read_4_bytes (dbfd
,
12053 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12055 if (dwp_file
->version
== 1)
12057 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12058 unit_index
, comp_dir
,
12059 signature
, is_debug_types
);
12061 else if (dwp_file
->version
== 2)
12063 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12064 unit_index
, comp_dir
,
12065 signature
, is_debug_types
);
12067 else /* version == 5 */
12069 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12070 unit_index
, comp_dir
,
12071 signature
, is_debug_types
);
12073 return (struct dwo_unit
*) *slot
;
12075 if (signature_in_table
== 0)
12077 hash
= (hash
+ hash2
) & mask
;
12080 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12081 " [in module %s]"),
12085 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12086 Open the file specified by FILE_NAME and hand it off to BFD for
12087 preliminary analysis. Return a newly initialized bfd *, which
12088 includes a canonicalized copy of FILE_NAME.
12089 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12090 SEARCH_CWD is true if the current directory is to be searched.
12091 It will be searched before debug-file-directory.
12092 If successful, the file is added to the bfd include table of the
12093 objfile's bfd (see gdb_bfd_record_inclusion).
12094 If unable to find/open the file, return NULL.
12095 NOTE: This function is derived from symfile_bfd_open. */
12097 static gdb_bfd_ref_ptr
12098 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12099 const char *file_name
, int is_dwp
, int search_cwd
)
12102 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12103 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12104 to debug_file_directory. */
12105 const char *search_path
;
12106 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12108 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12111 if (!debug_file_directory
.empty ())
12113 search_path_holder
.reset (concat (".", dirname_separator_string
,
12114 debug_file_directory
.c_str (),
12116 search_path
= search_path_holder
.get ();
12122 search_path
= debug_file_directory
.c_str ();
12124 /* Add the path for the executable binary to the list of search paths. */
12125 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12126 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12127 dirname_separator_string
,
12128 search_path
, nullptr));
12129 search_path
= search_path_holder
.get ();
12131 openp_flags flags
= OPF_RETURN_REALPATH
;
12133 flags
|= OPF_SEARCH_IN_PATH
;
12135 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12136 desc
= openp (search_path
, flags
, file_name
,
12137 O_RDONLY
| O_BINARY
, &absolute_name
);
12141 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12143 if (sym_bfd
== NULL
)
12145 bfd_set_cacheable (sym_bfd
.get (), 1);
12147 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12150 /* Success. Record the bfd as having been included by the objfile's bfd.
12151 This is important because things like demangled_names_hash lives in the
12152 objfile's per_bfd space and may have references to things like symbol
12153 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12154 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12159 /* Try to open DWO file FILE_NAME.
12160 COMP_DIR is the DW_AT_comp_dir attribute.
12161 The result is the bfd handle of the file.
12162 If there is a problem finding or opening the file, return NULL.
12163 Upon success, the canonicalized path of the file is stored in the bfd,
12164 same as symfile_bfd_open. */
12166 static gdb_bfd_ref_ptr
12167 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12168 const char *file_name
, const char *comp_dir
)
12170 if (IS_ABSOLUTE_PATH (file_name
))
12171 return try_open_dwop_file (per_objfile
, file_name
,
12172 0 /*is_dwp*/, 0 /*search_cwd*/);
12174 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12176 if (comp_dir
!= NULL
)
12178 gdb::unique_xmalloc_ptr
<char> path_to_try
12179 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12181 /* NOTE: If comp_dir is a relative path, this will also try the
12182 search path, which seems useful. */
12183 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12185 1 /*search_cwd*/));
12190 /* That didn't work, try debug-file-directory, which, despite its name,
12191 is a list of paths. */
12193 if (debug_file_directory
.empty ())
12196 return try_open_dwop_file (per_objfile
, file_name
,
12197 0 /*is_dwp*/, 1 /*search_cwd*/);
12200 /* This function is mapped across the sections and remembers the offset and
12201 size of each of the DWO debugging sections we are interested in. */
12204 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12205 dwo_sections
*dwo_sections
)
12207 const struct dwop_section_names
*names
= &dwop_section_names
;
12209 if (names
->abbrev_dwo
.matches (sectp
->name
))
12211 dwo_sections
->abbrev
.s
.section
= sectp
;
12212 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12214 else if (names
->info_dwo
.matches (sectp
->name
))
12216 dwo_sections
->info
.s
.section
= sectp
;
12217 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12219 else if (names
->line_dwo
.matches (sectp
->name
))
12221 dwo_sections
->line
.s
.section
= sectp
;
12222 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12224 else if (names
->loc_dwo
.matches (sectp
->name
))
12226 dwo_sections
->loc
.s
.section
= sectp
;
12227 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12229 else if (names
->loclists_dwo
.matches (sectp
->name
))
12231 dwo_sections
->loclists
.s
.section
= sectp
;
12232 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12234 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12236 dwo_sections
->macinfo
.s
.section
= sectp
;
12237 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12239 else if (names
->macro_dwo
.matches (sectp
->name
))
12241 dwo_sections
->macro
.s
.section
= sectp
;
12242 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12244 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12246 dwo_sections
->rnglists
.s
.section
= sectp
;
12247 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12249 else if (names
->str_dwo
.matches (sectp
->name
))
12251 dwo_sections
->str
.s
.section
= sectp
;
12252 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12254 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12256 dwo_sections
->str_offsets
.s
.section
= sectp
;
12257 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12259 else if (names
->types_dwo
.matches (sectp
->name
))
12261 struct dwarf2_section_info type_section
;
12263 memset (&type_section
, 0, sizeof (type_section
));
12264 type_section
.s
.section
= sectp
;
12265 type_section
.size
= bfd_section_size (sectp
);
12266 dwo_sections
->types
.push_back (type_section
);
12270 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12271 by PER_CU. This is for the non-DWP case.
12272 The result is NULL if DWO_NAME can't be found. */
12274 static struct dwo_file
*
12275 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12276 const char *comp_dir
)
12278 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12280 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12283 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12288 dwo_file_up
dwo_file (new struct dwo_file
);
12289 dwo_file
->dwo_name
= dwo_name
;
12290 dwo_file
->comp_dir
= comp_dir
;
12291 dwo_file
->dbfd
= std::move (dbfd
);
12293 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12294 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12295 &dwo_file
->sections
);
12297 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12300 if (cu
->per_cu
->dwarf_version
< 5)
12302 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12303 dwo_file
->sections
.types
, dwo_file
->tus
);
12307 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12308 &dwo_file
->sections
.info
, dwo_file
->tus
,
12309 rcuh_kind::COMPILE
);
12312 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12314 return dwo_file
.release ();
12317 /* This function is mapped across the sections and remembers the offset and
12318 size of each of the DWP debugging sections common to version 1 and 2 that
12319 we are interested in. */
12322 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12323 dwp_file
*dwp_file
)
12325 const struct dwop_section_names
*names
= &dwop_section_names
;
12326 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12328 /* Record the ELF section number for later lookup: this is what the
12329 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12330 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12331 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12333 /* Look for specific sections that we need. */
12334 if (names
->str_dwo
.matches (sectp
->name
))
12336 dwp_file
->sections
.str
.s
.section
= sectp
;
12337 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12339 else if (names
->cu_index
.matches (sectp
->name
))
12341 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12342 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12344 else if (names
->tu_index
.matches (sectp
->name
))
12346 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12347 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12351 /* This function is mapped across the sections and remembers the offset and
12352 size of each of the DWP version 2 debugging sections that we are interested
12353 in. This is split into a separate function because we don't know if we
12354 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12357 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12359 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12360 const struct dwop_section_names
*names
= &dwop_section_names
;
12361 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12363 /* Record the ELF section number for later lookup: this is what the
12364 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12365 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12366 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12368 /* Look for specific sections that we need. */
12369 if (names
->abbrev_dwo
.matches (sectp
->name
))
12371 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12372 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12374 else if (names
->info_dwo
.matches (sectp
->name
))
12376 dwp_file
->sections
.info
.s
.section
= sectp
;
12377 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12379 else if (names
->line_dwo
.matches (sectp
->name
))
12381 dwp_file
->sections
.line
.s
.section
= sectp
;
12382 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12384 else if (names
->loc_dwo
.matches (sectp
->name
))
12386 dwp_file
->sections
.loc
.s
.section
= sectp
;
12387 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12389 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12391 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12392 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12394 else if (names
->macro_dwo
.matches (sectp
->name
))
12396 dwp_file
->sections
.macro
.s
.section
= sectp
;
12397 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12399 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12401 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12402 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12404 else if (names
->types_dwo
.matches (sectp
->name
))
12406 dwp_file
->sections
.types
.s
.section
= sectp
;
12407 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12411 /* This function is mapped across the sections and remembers the offset and
12412 size of each of the DWP version 5 debugging sections that we are interested
12413 in. This is split into a separate function because we don't know if we
12414 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12417 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12419 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12420 const struct dwop_section_names
*names
= &dwop_section_names
;
12421 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12423 /* Record the ELF section number for later lookup: this is what the
12424 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12425 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12426 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12428 /* Look for specific sections that we need. */
12429 if (names
->abbrev_dwo
.matches (sectp
->name
))
12431 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12432 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12434 else if (names
->info_dwo
.matches (sectp
->name
))
12436 dwp_file
->sections
.info
.s
.section
= sectp
;
12437 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12439 else if (names
->line_dwo
.matches (sectp
->name
))
12441 dwp_file
->sections
.line
.s
.section
= sectp
;
12442 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12444 else if (names
->loclists_dwo
.matches (sectp
->name
))
12446 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12447 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12449 else if (names
->macro_dwo
.matches (sectp
->name
))
12451 dwp_file
->sections
.macro
.s
.section
= sectp
;
12452 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12454 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12456 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12457 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12459 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12461 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12462 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12466 /* Hash function for dwp_file loaded CUs/TUs. */
12469 hash_dwp_loaded_cutus (const void *item
)
12471 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12473 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12474 return dwo_unit
->signature
;
12477 /* Equality function for dwp_file loaded CUs/TUs. */
12480 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12482 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12483 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12485 return dua
->signature
== dub
->signature
;
12488 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12491 allocate_dwp_loaded_cutus_table ()
12493 return htab_up (htab_create_alloc (3,
12494 hash_dwp_loaded_cutus
,
12495 eq_dwp_loaded_cutus
,
12496 NULL
, xcalloc
, xfree
));
12499 /* Try to open DWP file FILE_NAME.
12500 The result is the bfd handle of the file.
12501 If there is a problem finding or opening the file, return NULL.
12502 Upon success, the canonicalized path of the file is stored in the bfd,
12503 same as symfile_bfd_open. */
12505 static gdb_bfd_ref_ptr
12506 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12508 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12510 1 /*search_cwd*/));
12514 /* Work around upstream bug 15652.
12515 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12516 [Whether that's a "bug" is debatable, but it is getting in our way.]
12517 We have no real idea where the dwp file is, because gdb's realpath-ing
12518 of the executable's path may have discarded the needed info.
12519 [IWBN if the dwp file name was recorded in the executable, akin to
12520 .gnu_debuglink, but that doesn't exist yet.]
12521 Strip the directory from FILE_NAME and search again. */
12522 if (!debug_file_directory
.empty ())
12524 /* Don't implicitly search the current directory here.
12525 If the user wants to search "." to handle this case,
12526 it must be added to debug-file-directory. */
12527 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12535 /* Initialize the use of the DWP file for the current objfile.
12536 By convention the name of the DWP file is ${objfile}.dwp.
12537 The result is NULL if it can't be found. */
12539 static std::unique_ptr
<struct dwp_file
>
12540 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12542 struct objfile
*objfile
= per_objfile
->objfile
;
12544 /* Try to find first .dwp for the binary file before any symbolic links
12547 /* If the objfile is a debug file, find the name of the real binary
12548 file and get the name of dwp file from there. */
12549 std::string dwp_name
;
12550 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12552 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12553 const char *backlink_basename
= lbasename (backlink
->original_name
);
12555 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12558 dwp_name
= objfile
->original_name
;
12560 dwp_name
+= ".dwp";
12562 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12564 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12566 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12567 dwp_name
= objfile_name (objfile
);
12568 dwp_name
+= ".dwp";
12569 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12574 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12576 return std::unique_ptr
<dwp_file
> ();
12579 const char *name
= bfd_get_filename (dbfd
.get ());
12580 std::unique_ptr
<struct dwp_file
> dwp_file
12581 (new struct dwp_file (name
, std::move (dbfd
)));
12583 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12584 dwp_file
->elf_sections
=
12585 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12586 dwp_file
->num_sections
, asection
*);
12588 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12589 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12592 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12594 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12596 /* The DWP file version is stored in the hash table. Oh well. */
12597 if (dwp_file
->cus
&& dwp_file
->tus
12598 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12600 /* Technically speaking, we should try to limp along, but this is
12601 pretty bizarre. We use pulongest here because that's the established
12602 portability solution (e.g, we cannot use %u for uint32_t). */
12603 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12604 " TU version %s [in DWP file %s]"),
12605 pulongest (dwp_file
->cus
->version
),
12606 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12610 dwp_file
->version
= dwp_file
->cus
->version
;
12611 else if (dwp_file
->tus
)
12612 dwp_file
->version
= dwp_file
->tus
->version
;
12614 dwp_file
->version
= 2;
12616 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12618 if (dwp_file
->version
== 2)
12619 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12622 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12626 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12627 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12629 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12630 dwarf_read_debug_printf (" %s CUs, %s TUs",
12631 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12632 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12637 /* Wrapper around open_and_init_dwp_file, only open it once. */
12639 static struct dwp_file
*
12640 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12642 if (!per_objfile
->per_bfd
->dwp_checked
)
12644 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12645 per_objfile
->per_bfd
->dwp_checked
= 1;
12647 return per_objfile
->per_bfd
->dwp_file
.get ();
12650 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12651 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12652 or in the DWP file for the objfile, referenced by THIS_UNIT.
12653 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12654 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12656 This is called, for example, when wanting to read a variable with a
12657 complex location. Therefore we don't want to do file i/o for every call.
12658 Therefore we don't want to look for a DWO file on every call.
12659 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12660 then we check if we've already seen DWO_NAME, and only THEN do we check
12663 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12664 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12666 static struct dwo_unit
*
12667 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12668 ULONGEST signature
, int is_debug_types
)
12670 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12671 struct objfile
*objfile
= per_objfile
->objfile
;
12672 const char *kind
= is_debug_types
? "TU" : "CU";
12673 void **dwo_file_slot
;
12674 struct dwo_file
*dwo_file
;
12675 struct dwp_file
*dwp_file
;
12677 /* First see if there's a DWP file.
12678 If we have a DWP file but didn't find the DWO inside it, don't
12679 look for the original DWO file. It makes gdb behave differently
12680 depending on whether one is debugging in the build tree. */
12682 dwp_file
= get_dwp_file (per_objfile
);
12683 if (dwp_file
!= NULL
)
12685 const struct dwp_hash_table
*dwp_htab
=
12686 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12688 if (dwp_htab
!= NULL
)
12690 struct dwo_unit
*dwo_cutu
=
12691 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12694 if (dwo_cutu
!= NULL
)
12696 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12697 kind
, hex_string (signature
),
12698 host_address_to_string (dwo_cutu
));
12706 /* No DWP file, look for the DWO file. */
12708 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12709 if (*dwo_file_slot
== NULL
)
12711 /* Read in the file and build a table of the CUs/TUs it contains. */
12712 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12714 /* NOTE: This will be NULL if unable to open the file. */
12715 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12717 if (dwo_file
!= NULL
)
12719 struct dwo_unit
*dwo_cutu
= NULL
;
12721 if (is_debug_types
&& dwo_file
->tus
)
12723 struct dwo_unit find_dwo_cutu
;
12725 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12726 find_dwo_cutu
.signature
= signature
;
12728 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12731 else if (!is_debug_types
&& dwo_file
->cus
)
12733 struct dwo_unit find_dwo_cutu
;
12735 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12736 find_dwo_cutu
.signature
= signature
;
12737 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12741 if (dwo_cutu
!= NULL
)
12743 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12744 kind
, dwo_name
, hex_string (signature
),
12745 host_address_to_string (dwo_cutu
));
12752 /* We didn't find it. This could mean a dwo_id mismatch, or
12753 someone deleted the DWO/DWP file, or the search path isn't set up
12754 correctly to find the file. */
12756 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12757 kind
, dwo_name
, hex_string (signature
));
12759 /* This is a warning and not a complaint because it can be caused by
12760 pilot error (e.g., user accidentally deleting the DWO). */
12762 /* Print the name of the DWP file if we looked there, helps the user
12763 better diagnose the problem. */
12764 std::string dwp_text
;
12766 if (dwp_file
!= NULL
)
12767 dwp_text
= string_printf (" [in DWP file %s]",
12768 lbasename (dwp_file
->name
));
12770 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12771 " [in module %s]"),
12772 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12773 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12778 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12779 See lookup_dwo_cutu_unit for details. */
12781 static struct dwo_unit
*
12782 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12783 ULONGEST signature
)
12785 gdb_assert (!cu
->per_cu
->is_debug_types
);
12787 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12790 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12791 See lookup_dwo_cutu_unit for details. */
12793 static struct dwo_unit
*
12794 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12796 gdb_assert (cu
->per_cu
->is_debug_types
);
12798 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12800 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12803 /* Traversal function for queue_and_load_all_dwo_tus. */
12806 queue_and_load_dwo_tu (void **slot
, void *info
)
12808 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12809 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12810 ULONGEST signature
= dwo_unit
->signature
;
12811 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12813 if (sig_type
!= NULL
)
12815 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12816 a real dependency of PER_CU on SIG_TYPE. That is detected later
12817 while processing PER_CU. */
12818 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12820 load_full_type_unit (sig_type
, cu
->per_objfile
);
12821 cu
->per_cu
->imported_symtabs_push (sig_type
);
12827 /* Queue all TUs contained in the DWO of CU to be read in.
12828 The DWO may have the only definition of the type, though it may not be
12829 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12830 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12833 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12835 struct dwo_unit
*dwo_unit
;
12836 struct dwo_file
*dwo_file
;
12838 gdb_assert (cu
!= nullptr);
12839 gdb_assert (!cu
->per_cu
->is_debug_types
);
12840 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12842 dwo_unit
= cu
->dwo_unit
;
12843 gdb_assert (dwo_unit
!= NULL
);
12845 dwo_file
= dwo_unit
->dwo_file
;
12846 if (dwo_file
->tus
!= NULL
)
12847 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12850 /* Read in various DIEs. */
12852 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12853 Inherit only the children of the DW_AT_abstract_origin DIE not being
12854 already referenced by DW_AT_abstract_origin from the children of the
12858 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12860 struct die_info
*child_die
;
12861 sect_offset
*offsetp
;
12862 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12863 struct die_info
*origin_die
;
12864 /* Iterator of the ORIGIN_DIE children. */
12865 struct die_info
*origin_child_die
;
12866 struct attribute
*attr
;
12867 struct dwarf2_cu
*origin_cu
;
12868 struct pending
**origin_previous_list_in_scope
;
12870 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12874 /* Note that following die references may follow to a die in a
12878 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12880 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12882 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12883 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12885 if (die
->tag
!= origin_die
->tag
12886 && !(die
->tag
== DW_TAG_inlined_subroutine
12887 && origin_die
->tag
== DW_TAG_subprogram
))
12888 complaint (_("DIE %s and its abstract origin %s have different tags"),
12889 sect_offset_str (die
->sect_off
),
12890 sect_offset_str (origin_die
->sect_off
));
12892 /* Find if the concrete and abstract trees are structurally the
12893 same. This is a shallow traversal and it is not bullet-proof;
12894 the compiler can trick the debugger into believing that the trees
12895 are isomorphic, whereas they actually are not. However, the
12896 likelyhood of this happening is pretty low, and a full-fledged
12897 check would be an overkill. */
12898 bool are_isomorphic
= true;
12899 die_info
*concrete_child
= die
->child
;
12900 die_info
*abstract_child
= origin_die
->child
;
12901 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12903 if (concrete_child
== nullptr
12904 || abstract_child
== nullptr
12905 || concrete_child
->tag
!= abstract_child
->tag
)
12907 are_isomorphic
= false;
12911 concrete_child
= concrete_child
->sibling
;
12912 abstract_child
= abstract_child
->sibling
;
12915 /* Walk the origin's children in parallel to the concrete children.
12916 This helps match an origin child in case the debug info misses
12917 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12918 origin tree may not have the same tree structure as the concrete
12920 die_info
*corresponding_abstract_child
12921 = are_isomorphic
? origin_die
->child
: nullptr;
12923 std::vector
<sect_offset
> offsets
;
12925 for (child_die
= die
->child
;
12926 child_die
&& child_die
->tag
;
12927 child_die
= child_die
->sibling
)
12929 struct die_info
*child_origin_die
;
12930 struct dwarf2_cu
*child_origin_cu
;
12932 /* We are trying to process concrete instance entries:
12933 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12934 it's not relevant to our analysis here. i.e. detecting DIEs that are
12935 present in the abstract instance but not referenced in the concrete
12937 if (child_die
->tag
== DW_TAG_call_site
12938 || child_die
->tag
== DW_TAG_GNU_call_site
)
12940 if (are_isomorphic
)
12941 corresponding_abstract_child
12942 = corresponding_abstract_child
->sibling
;
12946 /* For each CHILD_DIE, find the corresponding child of
12947 ORIGIN_DIE. If there is more than one layer of
12948 DW_AT_abstract_origin, follow them all; there shouldn't be,
12949 but GCC versions at least through 4.4 generate this (GCC PR
12951 child_origin_die
= child_die
;
12952 child_origin_cu
= cu
;
12955 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12959 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12963 /* If missing DW_AT_abstract_origin, try the corresponding child
12964 of the origin. Clang emits such lexical scopes. */
12965 if (child_origin_die
== child_die
12966 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12968 && child_die
->tag
== DW_TAG_lexical_block
)
12969 child_origin_die
= corresponding_abstract_child
;
12971 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12972 counterpart may exist. */
12973 if (child_origin_die
!= child_die
)
12975 if (child_die
->tag
!= child_origin_die
->tag
12976 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12977 && child_origin_die
->tag
== DW_TAG_subprogram
))
12978 complaint (_("Child DIE %s and its abstract origin %s have "
12980 sect_offset_str (child_die
->sect_off
),
12981 sect_offset_str (child_origin_die
->sect_off
));
12982 if (child_origin_die
->parent
!= origin_die
)
12983 complaint (_("Child DIE %s and its abstract origin %s have "
12984 "different parents"),
12985 sect_offset_str (child_die
->sect_off
),
12986 sect_offset_str (child_origin_die
->sect_off
));
12988 offsets
.push_back (child_origin_die
->sect_off
);
12991 if (are_isomorphic
)
12992 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12994 std::sort (offsets
.begin (), offsets
.end ());
12995 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12996 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12997 if (offsetp
[-1] == *offsetp
)
12998 complaint (_("Multiple children of DIE %s refer "
12999 "to DIE %s as their abstract origin"),
13000 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13002 offsetp
= offsets
.data ();
13003 origin_child_die
= origin_die
->child
;
13004 while (origin_child_die
&& origin_child_die
->tag
)
13006 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13007 while (offsetp
< offsets_end
13008 && *offsetp
< origin_child_die
->sect_off
)
13010 if (offsetp
>= offsets_end
13011 || *offsetp
> origin_child_die
->sect_off
)
13013 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13014 Check whether we're already processing ORIGIN_CHILD_DIE.
13015 This can happen with mutually referenced abstract_origins.
13017 if (!origin_child_die
->in_process
)
13018 process_die (origin_child_die
, origin_cu
);
13020 origin_child_die
= origin_child_die
->sibling
;
13022 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13024 if (cu
!= origin_cu
)
13025 compute_delayed_physnames (origin_cu
);
13029 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13031 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13032 struct gdbarch
*gdbarch
= objfile
->arch ();
13033 struct context_stack
*newobj
;
13036 struct die_info
*child_die
;
13037 struct attribute
*attr
, *call_line
, *call_file
;
13039 CORE_ADDR baseaddr
;
13040 struct block
*block
;
13041 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13042 std::vector
<struct symbol
*> template_args
;
13043 struct template_symbol
*templ_func
= NULL
;
13047 /* If we do not have call site information, we can't show the
13048 caller of this inlined function. That's too confusing, so
13049 only use the scope for local variables. */
13050 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13051 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13052 if (call_line
== NULL
|| call_file
== NULL
)
13054 read_lexical_block_scope (die
, cu
);
13059 baseaddr
= objfile
->text_section_offset ();
13061 name
= dwarf2_name (die
, cu
);
13063 /* Ignore functions with missing or empty names. These are actually
13064 illegal according to the DWARF standard. */
13067 complaint (_("missing name for subprogram DIE at %s"),
13068 sect_offset_str (die
->sect_off
));
13072 /* Ignore functions with missing or invalid low and high pc attributes. */
13073 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13074 <= PC_BOUNDS_INVALID
)
13076 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13077 if (attr
== nullptr || !attr
->as_boolean ())
13078 complaint (_("cannot get low and high bounds "
13079 "for subprogram DIE at %s"),
13080 sect_offset_str (die
->sect_off
));
13084 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13085 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13087 /* If we have any template arguments, then we must allocate a
13088 different sort of symbol. */
13089 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13091 if (child_die
->tag
== DW_TAG_template_type_param
13092 || child_die
->tag
== DW_TAG_template_value_param
)
13094 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13095 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13100 gdb_assert (cu
->get_builder () != nullptr);
13101 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13102 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13103 (struct symbol
*) templ_func
);
13105 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13106 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13109 /* If there is a location expression for DW_AT_frame_base, record
13111 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13112 if (attr
!= nullptr)
13113 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13115 /* If there is a location for the static link, record it. */
13116 newobj
->static_link
= NULL
;
13117 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13118 if (attr
!= nullptr)
13120 newobj
->static_link
13121 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13122 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13126 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13128 if (die
->child
!= NULL
)
13130 child_die
= die
->child
;
13131 while (child_die
&& child_die
->tag
)
13133 if (child_die
->tag
== DW_TAG_template_type_param
13134 || child_die
->tag
== DW_TAG_template_value_param
)
13136 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13139 template_args
.push_back (arg
);
13142 process_die (child_die
, cu
);
13143 child_die
= child_die
->sibling
;
13147 inherit_abstract_dies (die
, cu
);
13149 /* If we have a DW_AT_specification, we might need to import using
13150 directives from the context of the specification DIE. See the
13151 comment in determine_prefix. */
13152 if (cu
->per_cu
->lang
== language_cplus
13153 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13155 struct dwarf2_cu
*spec_cu
= cu
;
13156 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13160 child_die
= spec_die
->child
;
13161 while (child_die
&& child_die
->tag
)
13163 if (child_die
->tag
== DW_TAG_imported_module
)
13164 process_die (child_die
, spec_cu
);
13165 child_die
= child_die
->sibling
;
13168 /* In some cases, GCC generates specification DIEs that
13169 themselves contain DW_AT_specification attributes. */
13170 spec_die
= die_specification (spec_die
, &spec_cu
);
13174 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13175 /* Make a block for the local symbols within. */
13176 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13177 cstk
.static_link
, lowpc
, highpc
);
13179 /* For C++, set the block's scope. */
13180 if ((cu
->per_cu
->lang
== language_cplus
13181 || cu
->per_cu
->lang
== language_fortran
13182 || cu
->per_cu
->lang
== language_d
13183 || cu
->per_cu
->lang
== language_rust
)
13184 && cu
->processing_has_namespace_info
)
13185 block_set_scope (block
, determine_prefix (die
, cu
),
13186 &objfile
->objfile_obstack
);
13188 /* If we have address ranges, record them. */
13189 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13191 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13193 /* Attach template arguments to function. */
13194 if (!template_args
.empty ())
13196 gdb_assert (templ_func
!= NULL
);
13198 templ_func
->n_template_arguments
= template_args
.size ();
13199 templ_func
->template_arguments
13200 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13201 templ_func
->n_template_arguments
);
13202 memcpy (templ_func
->template_arguments
,
13203 template_args
.data (),
13204 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13206 /* Make sure that the symtab is set on the new symbols. Even
13207 though they don't appear in this symtab directly, other parts
13208 of gdb assume that symbols do, and this is reasonably
13210 for (symbol
*sym
: template_args
)
13211 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13214 /* In C++, we can have functions nested inside functions (e.g., when
13215 a function declares a class that has methods). This means that
13216 when we finish processing a function scope, we may need to go
13217 back to building a containing block's symbol lists. */
13218 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13219 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13221 /* If we've finished processing a top-level function, subsequent
13222 symbols go in the file symbol list. */
13223 if (cu
->get_builder ()->outermost_context_p ())
13224 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13227 /* Process all the DIES contained within a lexical block scope. Start
13228 a new scope, process the dies, and then close the scope. */
13231 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13233 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13234 struct gdbarch
*gdbarch
= objfile
->arch ();
13235 CORE_ADDR lowpc
, highpc
;
13236 struct die_info
*child_die
;
13237 CORE_ADDR baseaddr
;
13239 baseaddr
= objfile
->text_section_offset ();
13241 /* Ignore blocks with missing or invalid low and high pc attributes. */
13242 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13243 as multiple lexical blocks? Handling children in a sane way would
13244 be nasty. Might be easier to properly extend generic blocks to
13245 describe ranges. */
13246 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13248 case PC_BOUNDS_NOT_PRESENT
:
13249 /* DW_TAG_lexical_block has no attributes, process its children as if
13250 there was no wrapping by that DW_TAG_lexical_block.
13251 GCC does no longer produces such DWARF since GCC r224161. */
13252 for (child_die
= die
->child
;
13253 child_die
!= NULL
&& child_die
->tag
;
13254 child_die
= child_die
->sibling
)
13256 /* We might already be processing this DIE. This can happen
13257 in an unusual circumstance -- where a subroutine A
13258 appears lexically in another subroutine B, but A actually
13259 inlines B. The recursion is broken here, rather than in
13260 inherit_abstract_dies, because it seems better to simply
13261 drop concrete children here. */
13262 if (!child_die
->in_process
)
13263 process_die (child_die
, cu
);
13266 case PC_BOUNDS_INVALID
:
13269 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13270 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13272 cu
->get_builder ()->push_context (0, lowpc
);
13273 if (die
->child
!= NULL
)
13275 child_die
= die
->child
;
13276 while (child_die
&& child_die
->tag
)
13278 process_die (child_die
, cu
);
13279 child_die
= child_die
->sibling
;
13282 inherit_abstract_dies (die
, cu
);
13283 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13285 if (*cu
->get_builder ()->get_local_symbols () != NULL
13286 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13288 struct block
*block
13289 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13290 cstk
.start_addr
, highpc
);
13292 /* Note that recording ranges after traversing children, as we
13293 do here, means that recording a parent's ranges entails
13294 walking across all its children's ranges as they appear in
13295 the address map, which is quadratic behavior.
13297 It would be nicer to record the parent's ranges before
13298 traversing its children, simply overriding whatever you find
13299 there. But since we don't even decide whether to create a
13300 block until after we've traversed its children, that's hard
13302 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13304 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13305 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13308 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13311 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13313 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13314 struct objfile
*objfile
= per_objfile
->objfile
;
13315 struct gdbarch
*gdbarch
= objfile
->arch ();
13316 CORE_ADDR pc
, baseaddr
;
13317 struct attribute
*attr
;
13320 struct die_info
*child_die
;
13322 baseaddr
= objfile
->text_section_offset ();
13324 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13327 /* This was a pre-DWARF-5 GNU extension alias
13328 for DW_AT_call_return_pc. */
13329 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13333 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13334 "DIE %s [in module %s]"),
13335 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13338 pc
= attr
->as_address () + baseaddr
;
13339 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13342 if (cu
->call_site_htab
== NULL
)
13343 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
13344 call_site::eq
, NULL
,
13345 &objfile
->objfile_obstack
,
13346 hashtab_obstack_allocate
, NULL
);
13347 struct call_site
call_site_local (pc
, nullptr, nullptr);
13348 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13351 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13352 "DIE %s [in module %s]"),
13353 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13354 objfile_name (objfile
));
13358 /* Count parameters at the caller. */
13361 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13362 child_die
= child_die
->sibling
)
13364 if (child_die
->tag
!= DW_TAG_call_site_parameter
13365 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13367 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13368 "DW_TAG_call_site child DIE %s [in module %s]"),
13369 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13370 objfile_name (objfile
));
13377 struct call_site
*call_site
13378 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
13380 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
13381 struct call_site (pc
, cu
->per_cu
, per_objfile
);
13384 /* We never call the destructor of call_site, so we must ensure it is
13385 trivially destructible. */
13386 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
13388 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13389 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13391 struct die_info
*func_die
;
13393 /* Skip also over DW_TAG_inlined_subroutine. */
13394 for (func_die
= die
->parent
;
13395 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13396 && func_die
->tag
!= DW_TAG_subroutine_type
;
13397 func_die
= func_die
->parent
);
13399 /* DW_AT_call_all_calls is a superset
13400 of DW_AT_call_all_tail_calls. */
13402 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13403 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13404 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13405 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13407 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13408 not complete. But keep CALL_SITE for look ups via call_site_htab,
13409 both the initial caller containing the real return address PC and
13410 the final callee containing the current PC of a chain of tail
13411 calls do not need to have the tail call list complete. But any
13412 function candidate for a virtual tail call frame searched via
13413 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13414 determined unambiguously. */
13418 struct type
*func_type
= NULL
;
13421 func_type
= get_die_type (func_die
, cu
);
13422 if (func_type
!= NULL
)
13424 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13426 /* Enlist this call site to the function. */
13427 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13428 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13431 complaint (_("Cannot find function owning DW_TAG_call_site "
13432 "DIE %s [in module %s]"),
13433 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13437 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13439 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13441 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13444 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13445 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13448 call_site
->target
.set_loc_dwarf_block (nullptr);
13449 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13450 /* Keep NULL DWARF_BLOCK. */;
13451 else if (attr
->form_is_block ())
13453 struct dwarf2_locexpr_baton
*dlbaton
;
13454 struct dwarf_block
*block
= attr
->as_block ();
13456 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13457 dlbaton
->data
= block
->data
;
13458 dlbaton
->size
= block
->size
;
13459 dlbaton
->per_objfile
= per_objfile
;
13460 dlbaton
->per_cu
= cu
->per_cu
;
13462 call_site
->target
.set_loc_dwarf_block (dlbaton
);
13464 else if (attr
->form_is_ref ())
13466 struct dwarf2_cu
*target_cu
= cu
;
13467 struct die_info
*target_die
;
13469 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13470 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13471 if (die_is_declaration (target_die
, target_cu
))
13473 const char *target_physname
;
13475 /* Prefer the mangled name; otherwise compute the demangled one. */
13476 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13477 if (target_physname
== NULL
)
13478 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13479 if (target_physname
== NULL
)
13480 complaint (_("DW_AT_call_target target DIE has invalid "
13481 "physname, for referencing DIE %s [in module %s]"),
13482 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13484 call_site
->target
.set_loc_physname (target_physname
);
13490 /* DW_AT_entry_pc should be preferred. */
13491 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13492 <= PC_BOUNDS_INVALID
)
13493 complaint (_("DW_AT_call_target target DIE has invalid "
13494 "low pc, for referencing DIE %s [in module %s]"),
13495 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13498 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
13500 call_site
->target
.set_loc_physaddr (lowpc
);
13505 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13506 "block nor reference, for DIE %s [in module %s]"),
13507 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13509 for (child_die
= die
->child
;
13510 child_die
&& child_die
->tag
;
13511 child_die
= child_die
->sibling
)
13513 struct call_site_parameter
*parameter
;
13514 struct attribute
*loc
, *origin
;
13516 if (child_die
->tag
!= DW_TAG_call_site_parameter
13517 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13519 /* Already printed the complaint above. */
13523 gdb_assert (call_site
->parameter_count
< nparams
);
13524 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13526 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13527 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13528 register is contained in DW_AT_call_value. */
13530 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13531 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13532 if (origin
== NULL
)
13534 /* This was a pre-DWARF-5 GNU extension alias
13535 for DW_AT_call_parameter. */
13536 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13538 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13540 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13542 sect_offset sect_off
= origin
->get_ref_die_offset ();
13543 if (!cu
->header
.offset_in_cu_p (sect_off
))
13545 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13546 binding can be done only inside one CU. Such referenced DIE
13547 therefore cannot be even moved to DW_TAG_partial_unit. */
13548 complaint (_("DW_AT_call_parameter offset is not in CU for "
13549 "DW_TAG_call_site child DIE %s [in module %s]"),
13550 sect_offset_str (child_die
->sect_off
),
13551 objfile_name (objfile
));
13554 parameter
->u
.param_cu_off
13555 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13557 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13559 complaint (_("No DW_FORM_block* DW_AT_location for "
13560 "DW_TAG_call_site child DIE %s [in module %s]"),
13561 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13566 struct dwarf_block
*block
= loc
->as_block ();
13568 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13569 (block
->data
, &block
->data
[block
->size
]);
13570 if (parameter
->u
.dwarf_reg
!= -1)
13571 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13572 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13573 &block
->data
[block
->size
],
13574 ¶meter
->u
.fb_offset
))
13575 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13578 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13579 "for DW_FORM_block* DW_AT_location is supported for "
13580 "DW_TAG_call_site child DIE %s "
13582 sect_offset_str (child_die
->sect_off
),
13583 objfile_name (objfile
));
13588 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13590 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13591 if (attr
== NULL
|| !attr
->form_is_block ())
13593 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13594 "DW_TAG_call_site child DIE %s [in module %s]"),
13595 sect_offset_str (child_die
->sect_off
),
13596 objfile_name (objfile
));
13600 struct dwarf_block
*block
= attr
->as_block ();
13601 parameter
->value
= block
->data
;
13602 parameter
->value_size
= block
->size
;
13604 /* Parameters are not pre-cleared by memset above. */
13605 parameter
->data_value
= NULL
;
13606 parameter
->data_value_size
= 0;
13607 call_site
->parameter_count
++;
13609 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13611 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13612 if (attr
!= nullptr)
13614 if (!attr
->form_is_block ())
13615 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13616 "DW_TAG_call_site child DIE %s [in module %s]"),
13617 sect_offset_str (child_die
->sect_off
),
13618 objfile_name (objfile
));
13621 block
= attr
->as_block ();
13622 parameter
->data_value
= block
->data
;
13623 parameter
->data_value_size
= block
->size
;
13629 /* Helper function for read_variable. If DIE represents a virtual
13630 table, then return the type of the concrete object that is
13631 associated with the virtual table. Otherwise, return NULL. */
13633 static struct type
*
13634 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13636 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13640 /* Find the type DIE. */
13641 struct die_info
*type_die
= NULL
;
13642 struct dwarf2_cu
*type_cu
= cu
;
13644 if (attr
->form_is_ref ())
13645 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13646 if (type_die
== NULL
)
13649 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13651 return die_containing_type (type_die
, type_cu
);
13654 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13657 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13659 struct rust_vtable_symbol
*storage
= NULL
;
13661 if (cu
->per_cu
->lang
== language_rust
)
13663 struct type
*containing_type
= rust_containing_type (die
, cu
);
13665 if (containing_type
!= NULL
)
13667 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13669 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13670 storage
->concrete_type
= containing_type
;
13671 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13675 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13676 struct attribute
*abstract_origin
13677 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13678 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13679 if (res
== NULL
&& loc
&& abstract_origin
)
13681 /* We have a variable without a name, but with a location and an abstract
13682 origin. This may be a concrete instance of an abstract variable
13683 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13685 struct dwarf2_cu
*origin_cu
= cu
;
13686 struct die_info
*origin_die
13687 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13688 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13689 per_objfile
->per_bfd
->abstract_to_concrete
13690 [origin_die
->sect_off
].push_back (die
->sect_off
);
13694 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13695 reading .debug_rnglists.
13696 Callback's type should be:
13697 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13698 Return true if the attributes are present and valid, otherwise,
13701 template <typename Callback
>
13703 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13704 dwarf_tag tag
, Callback
&&callback
)
13706 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13707 struct objfile
*objfile
= per_objfile
->objfile
;
13708 bfd
*obfd
= objfile
->obfd
;
13709 /* Base address selection entry. */
13710 gdb::optional
<CORE_ADDR
> base
;
13711 const gdb_byte
*buffer
;
13712 bool overflow
= false;
13713 ULONGEST addr_index
;
13714 struct dwarf2_section_info
*rnglists_section
;
13716 base
= cu
->base_address
;
13717 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13718 rnglists_section
->read (objfile
);
13720 if (offset
>= rnglists_section
->size
)
13722 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13726 buffer
= rnglists_section
->buffer
+ offset
;
13730 /* Initialize it due to a false compiler warning. */
13731 CORE_ADDR range_beginning
= 0, range_end
= 0;
13732 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13733 + rnglists_section
->size
);
13734 unsigned int bytes_read
;
13736 if (buffer
== buf_end
)
13741 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13744 case DW_RLE_end_of_list
:
13746 case DW_RLE_base_address
:
13747 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13752 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13753 buffer
+= bytes_read
;
13755 case DW_RLE_base_addressx
:
13756 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13757 buffer
+= bytes_read
;
13758 base
= read_addr_index (cu
, addr_index
);
13760 case DW_RLE_start_length
:
13761 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13766 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13768 buffer
+= bytes_read
;
13769 range_end
= (range_beginning
13770 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13771 buffer
+= bytes_read
;
13772 if (buffer
> buf_end
)
13778 case DW_RLE_startx_length
:
13779 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13780 buffer
+= bytes_read
;
13781 range_beginning
= read_addr_index (cu
, addr_index
);
13782 if (buffer
> buf_end
)
13787 range_end
= (range_beginning
13788 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13789 buffer
+= bytes_read
;
13791 case DW_RLE_offset_pair
:
13792 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13793 buffer
+= bytes_read
;
13794 if (buffer
> buf_end
)
13799 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13800 buffer
+= bytes_read
;
13801 if (buffer
> buf_end
)
13807 case DW_RLE_start_end
:
13808 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13813 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13815 buffer
+= bytes_read
;
13816 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13817 buffer
+= bytes_read
;
13819 case DW_RLE_startx_endx
:
13820 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13821 buffer
+= bytes_read
;
13822 range_beginning
= read_addr_index (cu
, addr_index
);
13823 if (buffer
> buf_end
)
13828 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13829 buffer
+= bytes_read
;
13830 range_end
= read_addr_index (cu
, addr_index
);
13833 complaint (_("Invalid .debug_rnglists data (no base address)"));
13836 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13838 if (rlet
== DW_RLE_base_address
)
13841 if (range_beginning
> range_end
)
13843 /* Inverted range entries are invalid. */
13844 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13848 /* Empty range entries have no effect. */
13849 if (range_beginning
== range_end
)
13852 /* Only DW_RLE_offset_pair needs the base address added. */
13853 if (rlet
== DW_RLE_offset_pair
)
13855 if (!base
.has_value ())
13857 /* We have no valid base address for the DW_RLE_offset_pair. */
13858 complaint (_("Invalid .debug_rnglists data (no base address for "
13859 "DW_RLE_offset_pair)"));
13863 range_beginning
+= *base
;
13864 range_end
+= *base
;
13867 /* A not-uncommon case of bad debug info.
13868 Don't pollute the addrmap with bad data. */
13869 if (range_beginning
== 0
13870 && !per_objfile
->per_bfd
->has_section_at_zero
)
13872 complaint (_(".debug_rnglists entry has start address of zero"
13873 " [in module %s]"), objfile_name (objfile
));
13877 callback (range_beginning
, range_end
);
13882 complaint (_("Offset %d is not terminated "
13883 "for DW_AT_ranges attribute"),
13891 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13892 Callback's type should be:
13893 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13894 Return 1 if the attributes are present and valid, otherwise, return 0. */
13896 template <typename Callback
>
13898 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13899 Callback
&&callback
)
13901 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13902 struct objfile
*objfile
= per_objfile
->objfile
;
13903 struct comp_unit_head
*cu_header
= &cu
->header
;
13904 bfd
*obfd
= objfile
->obfd
;
13905 unsigned int addr_size
= cu_header
->addr_size
;
13906 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13907 /* Base address selection entry. */
13908 gdb::optional
<CORE_ADDR
> base
;
13909 unsigned int dummy
;
13910 const gdb_byte
*buffer
;
13912 if (cu_header
->version
>= 5)
13913 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13915 base
= cu
->base_address
;
13917 per_objfile
->per_bfd
->ranges
.read (objfile
);
13918 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13920 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13924 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13928 CORE_ADDR range_beginning
, range_end
;
13930 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13931 buffer
+= addr_size
;
13932 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13933 buffer
+= addr_size
;
13934 offset
+= 2 * addr_size
;
13936 /* An end of list marker is a pair of zero addresses. */
13937 if (range_beginning
== 0 && range_end
== 0)
13938 /* Found the end of list entry. */
13941 /* Each base address selection entry is a pair of 2 values.
13942 The first is the largest possible address, the second is
13943 the base address. Check for a base address here. */
13944 if ((range_beginning
& mask
) == mask
)
13946 /* If we found the largest possible address, then we already
13947 have the base address in range_end. */
13952 if (!base
.has_value ())
13954 /* We have no valid base address for the ranges
13956 complaint (_("Invalid .debug_ranges data (no base address)"));
13960 if (range_beginning
> range_end
)
13962 /* Inverted range entries are invalid. */
13963 complaint (_("Invalid .debug_ranges data (inverted range)"));
13967 /* Empty range entries have no effect. */
13968 if (range_beginning
== range_end
)
13971 range_beginning
+= *base
;
13972 range_end
+= *base
;
13974 /* A not-uncommon case of bad debug info.
13975 Don't pollute the addrmap with bad data. */
13976 if (range_beginning
== 0
13977 && !per_objfile
->per_bfd
->has_section_at_zero
)
13979 complaint (_(".debug_ranges entry has start address of zero"
13980 " [in module %s]"), objfile_name (objfile
));
13984 callback (range_beginning
, range_end
);
13990 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13991 Return 1 if the attributes are present and valid, otherwise, return 0.
13992 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
13995 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13996 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13997 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
13999 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14000 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14001 struct gdbarch
*gdbarch
= objfile
->arch ();
14002 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14005 CORE_ADDR high
= 0;
14008 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14009 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14011 if (ranges_pst
!= NULL
)
14016 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14017 range_beginning
+ baseaddr
)
14019 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14020 range_end
+ baseaddr
)
14022 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14023 lowpc
, highpc
- 1, ranges_pst
);
14026 /* FIXME: This is recording everything as a low-high
14027 segment of consecutive addresses. We should have a
14028 data structure for discontiguous block ranges
14032 low
= range_beginning
;
14038 if (range_beginning
< low
)
14039 low
= range_beginning
;
14040 if (range_end
> high
)
14048 /* If the first entry is an end-of-list marker, the range
14049 describes an empty scope, i.e. no instructions. */
14055 *high_return
= high
;
14059 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14060 definition for the return value. *LOWPC and *HIGHPC are set iff
14061 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14063 static enum pc_bounds_kind
14064 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14065 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14066 dwarf2_psymtab
*pst
)
14068 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14069 struct attribute
*attr
;
14070 struct attribute
*attr_high
;
14072 CORE_ADDR high
= 0;
14073 enum pc_bounds_kind ret
;
14075 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14078 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14079 if (attr
!= nullptr)
14081 low
= attr
->as_address ();
14082 high
= attr_high
->as_address ();
14083 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14087 /* Found high w/o low attribute. */
14088 return PC_BOUNDS_INVALID
;
14090 /* Found consecutive range of addresses. */
14091 ret
= PC_BOUNDS_HIGH_LOW
;
14095 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14096 if (attr
!= nullptr && attr
->form_is_unsigned ())
14098 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14099 on DWARF version). */
14100 ULONGEST ranges_offset
= attr
->as_unsigned ();
14102 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14104 if (die
->tag
!= DW_TAG_compile_unit
)
14105 ranges_offset
+= cu
->gnu_ranges_base
;
14107 /* Value of the DW_AT_ranges attribute is the offset in the
14108 .debug_ranges section. */
14109 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14111 return PC_BOUNDS_INVALID
;
14112 /* Found discontinuous range of addresses. */
14113 ret
= PC_BOUNDS_RANGES
;
14116 return PC_BOUNDS_NOT_PRESENT
;
14119 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14121 return PC_BOUNDS_INVALID
;
14123 /* When using the GNU linker, .gnu.linkonce. sections are used to
14124 eliminate duplicate copies of functions and vtables and such.
14125 The linker will arbitrarily choose one and discard the others.
14126 The AT_*_pc values for such functions refer to local labels in
14127 these sections. If the section from that file was discarded, the
14128 labels are not in the output, so the relocs get a value of 0.
14129 If this is a discarded function, mark the pc bounds as invalid,
14130 so that GDB will ignore it. */
14131 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14132 return PC_BOUNDS_INVALID
;
14140 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14141 its low and high PC addresses. Do nothing if these addresses could not
14142 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14143 and HIGHPC to the high address if greater than HIGHPC. */
14146 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14147 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14148 struct dwarf2_cu
*cu
)
14150 CORE_ADDR low
, high
;
14151 struct die_info
*child
= die
->child
;
14153 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14155 *lowpc
= std::min (*lowpc
, low
);
14156 *highpc
= std::max (*highpc
, high
);
14159 /* If the language does not allow nested subprograms (either inside
14160 subprograms or lexical blocks), we're done. */
14161 if (cu
->per_cu
->lang
!= language_ada
)
14164 /* Check all the children of the given DIE. If it contains nested
14165 subprograms, then check their pc bounds. Likewise, we need to
14166 check lexical blocks as well, as they may also contain subprogram
14168 while (child
&& child
->tag
)
14170 if (child
->tag
== DW_TAG_subprogram
14171 || child
->tag
== DW_TAG_lexical_block
)
14172 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14173 child
= child
->sibling
;
14177 /* Get the low and high pc's represented by the scope DIE, and store
14178 them in *LOWPC and *HIGHPC. If the correct values can't be
14179 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14182 get_scope_pc_bounds (struct die_info
*die
,
14183 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14184 struct dwarf2_cu
*cu
)
14186 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14187 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14188 CORE_ADDR current_low
, current_high
;
14190 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14191 >= PC_BOUNDS_RANGES
)
14193 best_low
= current_low
;
14194 best_high
= current_high
;
14198 struct die_info
*child
= die
->child
;
14200 while (child
&& child
->tag
)
14202 switch (child
->tag
) {
14203 case DW_TAG_subprogram
:
14204 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14206 case DW_TAG_namespace
:
14207 case DW_TAG_module
:
14208 /* FIXME: carlton/2004-01-16: Should we do this for
14209 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14210 that current GCC's always emit the DIEs corresponding
14211 to definitions of methods of classes as children of a
14212 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14213 the DIEs giving the declarations, which could be
14214 anywhere). But I don't see any reason why the
14215 standards says that they have to be there. */
14216 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14218 if (current_low
!= ((CORE_ADDR
) -1))
14220 best_low
= std::min (best_low
, current_low
);
14221 best_high
= std::max (best_high
, current_high
);
14229 child
= child
->sibling
;
14234 *highpc
= best_high
;
14237 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14241 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14242 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14244 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14245 struct gdbarch
*gdbarch
= objfile
->arch ();
14246 struct attribute
*attr
;
14247 struct attribute
*attr_high
;
14249 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14252 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14253 if (attr
!= nullptr)
14255 CORE_ADDR low
= attr
->as_address ();
14256 CORE_ADDR high
= attr_high
->as_address ();
14258 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14261 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14262 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14263 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14267 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14268 if (attr
!= nullptr && attr
->form_is_unsigned ())
14270 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14271 on DWARF version). */
14272 ULONGEST ranges_offset
= attr
->as_unsigned ();
14274 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14276 if (die
->tag
!= DW_TAG_compile_unit
)
14277 ranges_offset
+= cu
->gnu_ranges_base
;
14279 std::vector
<blockrange
> blockvec
;
14280 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14281 [&] (CORE_ADDR start
, CORE_ADDR end
)
14285 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14286 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14287 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14288 blockvec
.emplace_back (start
, end
);
14291 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14295 /* Check whether the producer field indicates either of GCC < 4.6, or the
14296 Intel C/C++ compiler, and cache the result in CU. */
14299 check_producer (struct dwarf2_cu
*cu
)
14303 if (cu
->producer
== NULL
)
14305 /* For unknown compilers expect their behavior is DWARF version
14308 GCC started to support .debug_types sections by -gdwarf-4 since
14309 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14310 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14311 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14312 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14314 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14316 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14317 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14319 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14321 cu
->producer_is_icc
= true;
14322 cu
->producer_is_icc_lt_14
= major
< 14;
14324 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14325 cu
->producer_is_codewarrior
= true;
14328 /* For other non-GCC compilers, expect their behavior is DWARF version
14332 cu
->checked_producer
= true;
14335 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14336 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14337 during 4.6.0 experimental. */
14340 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14342 if (!cu
->checked_producer
)
14343 check_producer (cu
);
14345 return cu
->producer_is_gxx_lt_4_6
;
14349 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14350 with incorrect is_stmt attributes. */
14353 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14355 if (!cu
->checked_producer
)
14356 check_producer (cu
);
14358 return cu
->producer_is_codewarrior
;
14361 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14362 If that attribute is not available, return the appropriate
14365 static enum dwarf_access_attribute
14366 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14368 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14369 if (attr
!= nullptr)
14371 LONGEST value
= attr
->constant_value (-1);
14372 if (value
== DW_ACCESS_public
14373 || value
== DW_ACCESS_protected
14374 || value
== DW_ACCESS_private
)
14375 return (dwarf_access_attribute
) value
;
14376 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14380 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14382 /* The default DWARF 2 accessibility for members is public, the default
14383 accessibility for inheritance is private. */
14385 if (die
->tag
!= DW_TAG_inheritance
)
14386 return DW_ACCESS_public
;
14388 return DW_ACCESS_private
;
14392 /* DWARF 3+ defines the default accessibility a different way. The same
14393 rules apply now for DW_TAG_inheritance as for the members and it only
14394 depends on the container kind. */
14396 if (die
->parent
->tag
== DW_TAG_class_type
)
14397 return DW_ACCESS_private
;
14399 return DW_ACCESS_public
;
14403 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
14404 *OFFSET to the byte offset. If the attribute was not found return
14405 0, otherwise return 1. If it was found but could not properly be
14406 handled, set *OFFSET to 0. */
14409 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14412 struct attribute
*attr
;
14414 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14419 /* Note that we do not check for a section offset first here.
14420 This is because DW_AT_data_member_location is new in DWARF 4,
14421 so if we see it, we can assume that a constant form is really
14422 a constant and not a section offset. */
14423 if (attr
->form_is_constant ())
14424 *offset
= attr
->constant_value (0);
14425 else if (attr
->form_is_section_offset ())
14426 dwarf2_complex_location_expr_complaint ();
14427 else if (attr
->form_is_block ())
14428 *offset
= decode_locdesc (attr
->as_block (), cu
);
14430 dwarf2_complex_location_expr_complaint ();
14436 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14437 if (attr
!= nullptr)
14439 *offset
= attr
->constant_value (0);
14447 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
14448 store the results in FIELD. */
14451 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14452 struct field
*field
)
14454 struct attribute
*attr
;
14456 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14459 if (attr
->form_is_constant ())
14461 LONGEST offset
= attr
->constant_value (0);
14462 field
->set_loc_bitpos (offset
* bits_per_byte
);
14464 else if (attr
->form_is_section_offset ())
14465 dwarf2_complex_location_expr_complaint ();
14466 else if (attr
->form_is_block ())
14469 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14471 field
->set_loc_bitpos (offset
* bits_per_byte
);
14474 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14475 struct objfile
*objfile
= per_objfile
->objfile
;
14476 struct dwarf2_locexpr_baton
*dlbaton
14477 = XOBNEW (&objfile
->objfile_obstack
,
14478 struct dwarf2_locexpr_baton
);
14479 dlbaton
->data
= attr
->as_block ()->data
;
14480 dlbaton
->size
= attr
->as_block ()->size
;
14481 /* When using this baton, we want to compute the address
14482 of the field, not the value. This is why
14483 is_reference is set to false here. */
14484 dlbaton
->is_reference
= false;
14485 dlbaton
->per_objfile
= per_objfile
;
14486 dlbaton
->per_cu
= cu
->per_cu
;
14488 field
->set_loc_dwarf_block (dlbaton
);
14492 dwarf2_complex_location_expr_complaint ();
14496 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14497 if (attr
!= nullptr)
14498 field
->set_loc_bitpos (attr
->constant_value (0));
14502 /* Add an aggregate field to the field list. */
14505 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14506 struct dwarf2_cu
*cu
)
14508 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14509 struct gdbarch
*gdbarch
= objfile
->arch ();
14510 struct nextfield
*new_field
;
14511 struct attribute
*attr
;
14513 const char *fieldname
= "";
14515 if (die
->tag
== DW_TAG_inheritance
)
14517 fip
->baseclasses
.emplace_back ();
14518 new_field
= &fip
->baseclasses
.back ();
14522 fip
->fields
.emplace_back ();
14523 new_field
= &fip
->fields
.back ();
14526 new_field
->offset
= die
->sect_off
;
14528 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14529 if (new_field
->accessibility
!= DW_ACCESS_public
)
14530 fip
->non_public_fields
= true;
14532 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14533 if (attr
!= nullptr)
14534 new_field
->virtuality
= attr
->as_virtuality ();
14536 new_field
->virtuality
= DW_VIRTUALITY_none
;
14538 fp
= &new_field
->field
;
14540 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14542 /* Data member other than a C++ static data member. */
14544 /* Get type of field. */
14545 fp
->set_type (die_type (die
, cu
));
14547 fp
->set_loc_bitpos (0);
14549 /* Get bit size of field (zero if none). */
14550 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14551 if (attr
!= nullptr)
14553 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14557 FIELD_BITSIZE (*fp
) = 0;
14560 /* Get bit offset of field. */
14561 handle_member_location (die
, cu
, fp
);
14562 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14563 if (attr
!= nullptr && attr
->form_is_constant ())
14565 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14567 /* For big endian bits, the DW_AT_bit_offset gives the
14568 additional bit offset from the MSB of the containing
14569 anonymous object to the MSB of the field. We don't
14570 have to do anything special since we don't need to
14571 know the size of the anonymous object. */
14572 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
14576 /* For little endian bits, compute the bit offset to the
14577 MSB of the anonymous object, subtract off the number of
14578 bits from the MSB of the field to the MSB of the
14579 object, and then subtract off the number of bits of
14580 the field itself. The result is the bit offset of
14581 the LSB of the field. */
14582 int anonymous_size
;
14583 int bit_offset
= attr
->constant_value (0);
14585 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14586 if (attr
!= nullptr && attr
->form_is_constant ())
14588 /* The size of the anonymous object containing
14589 the bit field is explicit, so use the
14590 indicated size (in bytes). */
14591 anonymous_size
= attr
->constant_value (0);
14595 /* The size of the anonymous object containing
14596 the bit field must be inferred from the type
14597 attribute of the data member containing the
14599 anonymous_size
= TYPE_LENGTH (fp
->type ());
14601 fp
->set_loc_bitpos (fp
->loc_bitpos ()
14602 + anonymous_size
* bits_per_byte
14603 - bit_offset
- FIELD_BITSIZE (*fp
));
14607 /* Get name of field. */
14608 fieldname
= dwarf2_name (die
, cu
);
14609 if (fieldname
== NULL
)
14612 /* The name is already allocated along with this objfile, so we don't
14613 need to duplicate it for the type. */
14614 fp
->set_name (fieldname
);
14616 /* Change accessibility for artificial fields (e.g. virtual table
14617 pointer or virtual base class pointer) to private. */
14618 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14620 FIELD_ARTIFICIAL (*fp
) = 1;
14621 new_field
->accessibility
= DW_ACCESS_private
;
14622 fip
->non_public_fields
= true;
14625 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14627 /* C++ static member. */
14629 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14630 is a declaration, but all versions of G++ as of this writing
14631 (so through at least 3.2.1) incorrectly generate
14632 DW_TAG_variable tags. */
14634 const char *physname
;
14636 /* Get name of field. */
14637 fieldname
= dwarf2_name (die
, cu
);
14638 if (fieldname
== NULL
)
14641 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14643 /* Only create a symbol if this is an external value.
14644 new_symbol checks this and puts the value in the global symbol
14645 table, which we want. If it is not external, new_symbol
14646 will try to put the value in cu->list_in_scope which is wrong. */
14647 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14649 /* A static const member, not much different than an enum as far as
14650 we're concerned, except that we can support more types. */
14651 new_symbol (die
, NULL
, cu
);
14654 /* Get physical name. */
14655 physname
= dwarf2_physname (fieldname
, die
, cu
);
14657 /* The name is already allocated along with this objfile, so we don't
14658 need to duplicate it for the type. */
14659 fp
->set_loc_physname (physname
? physname
: "");
14660 fp
->set_type (die_type (die
, cu
));
14661 fp
->set_name (fieldname
);
14663 else if (die
->tag
== DW_TAG_inheritance
)
14665 /* C++ base class field. */
14666 handle_member_location (die
, cu
, fp
);
14667 FIELD_BITSIZE (*fp
) = 0;
14668 fp
->set_type (die_type (die
, cu
));
14669 fp
->set_name (fp
->type ()->name ());
14672 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14675 /* Can the type given by DIE define another type? */
14678 type_can_define_types (const struct die_info
*die
)
14682 case DW_TAG_typedef
:
14683 case DW_TAG_class_type
:
14684 case DW_TAG_structure_type
:
14685 case DW_TAG_union_type
:
14686 case DW_TAG_enumeration_type
:
14694 /* Add a type definition defined in the scope of the FIP's class. */
14697 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14698 struct dwarf2_cu
*cu
)
14700 struct decl_field fp
;
14701 memset (&fp
, 0, sizeof (fp
));
14703 gdb_assert (type_can_define_types (die
));
14705 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14706 fp
.name
= dwarf2_name (die
, cu
);
14707 fp
.type
= read_type_die (die
, cu
);
14709 /* Save accessibility. */
14710 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14711 switch (accessibility
)
14713 case DW_ACCESS_public
:
14714 /* The assumed value if neither private nor protected. */
14716 case DW_ACCESS_private
:
14719 case DW_ACCESS_protected
:
14720 fp
.is_protected
= 1;
14724 if (die
->tag
== DW_TAG_typedef
)
14725 fip
->typedef_field_list
.push_back (fp
);
14727 fip
->nested_types_list
.push_back (fp
);
14730 /* A convenience typedef that's used when finding the discriminant
14731 field for a variant part. */
14732 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14735 /* Compute the discriminant range for a given variant. OBSTACK is
14736 where the results will be stored. VARIANT is the variant to
14737 process. IS_UNSIGNED indicates whether the discriminant is signed
14740 static const gdb::array_view
<discriminant_range
>
14741 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14744 std::vector
<discriminant_range
> ranges
;
14746 if (variant
.default_branch
)
14749 if (variant
.discr_list_data
== nullptr)
14751 discriminant_range r
14752 = {variant
.discriminant_value
, variant
.discriminant_value
};
14753 ranges
.push_back (r
);
14757 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14758 variant
.discr_list_data
->size
);
14759 while (!data
.empty ())
14761 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14763 complaint (_("invalid discriminant marker: %d"), data
[0]);
14766 bool is_range
= data
[0] == DW_DSC_range
;
14767 data
= data
.slice (1);
14769 ULONGEST low
, high
;
14770 unsigned int bytes_read
;
14774 complaint (_("DW_AT_discr_list missing low value"));
14778 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14780 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14782 data
= data
.slice (bytes_read
);
14788 complaint (_("DW_AT_discr_list missing high value"));
14792 high
= read_unsigned_leb128 (nullptr, data
.data (),
14795 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14797 data
= data
.slice (bytes_read
);
14802 ranges
.push_back ({ low
, high
});
14806 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14808 std::copy (ranges
.begin (), ranges
.end (), result
);
14809 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14812 static const gdb::array_view
<variant_part
> create_variant_parts
14813 (struct obstack
*obstack
,
14814 const offset_map_type
&offset_map
,
14815 struct field_info
*fi
,
14816 const std::vector
<variant_part_builder
> &variant_parts
);
14818 /* Fill in a "struct variant" for a given variant field. RESULT is
14819 the variant to fill in. OBSTACK is where any needed allocations
14820 will be done. OFFSET_MAP holds the mapping from section offsets to
14821 fields for the type. FI describes the fields of the type we're
14822 processing. FIELD is the variant field we're converting. */
14825 create_one_variant (variant
&result
, struct obstack
*obstack
,
14826 const offset_map_type
&offset_map
,
14827 struct field_info
*fi
, const variant_field
&field
)
14829 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14830 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14831 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14832 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14833 field
.variant_parts
);
14836 /* Fill in a "struct variant_part" for a given variant part. RESULT
14837 is the variant part to fill in. OBSTACK is where any needed
14838 allocations will be done. OFFSET_MAP holds the mapping from
14839 section offsets to fields for the type. FI describes the fields of
14840 the type we're processing. BUILDER is the variant part to be
14844 create_one_variant_part (variant_part
&result
,
14845 struct obstack
*obstack
,
14846 const offset_map_type
&offset_map
,
14847 struct field_info
*fi
,
14848 const variant_part_builder
&builder
)
14850 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14851 if (iter
== offset_map
.end ())
14853 result
.discriminant_index
= -1;
14854 /* Doesn't matter. */
14855 result
.is_unsigned
= false;
14859 result
.discriminant_index
= iter
->second
;
14861 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14864 size_t n
= builder
.variants
.size ();
14865 variant
*output
= new (obstack
) variant
[n
];
14866 for (size_t i
= 0; i
< n
; ++i
)
14867 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14868 builder
.variants
[i
]);
14870 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14873 /* Create a vector of variant parts that can be attached to a type.
14874 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14875 holds the mapping from section offsets to fields for the type. FI
14876 describes the fields of the type we're processing. VARIANT_PARTS
14877 is the vector to convert. */
14879 static const gdb::array_view
<variant_part
>
14880 create_variant_parts (struct obstack
*obstack
,
14881 const offset_map_type
&offset_map
,
14882 struct field_info
*fi
,
14883 const std::vector
<variant_part_builder
> &variant_parts
)
14885 if (variant_parts
.empty ())
14888 size_t n
= variant_parts
.size ();
14889 variant_part
*result
= new (obstack
) variant_part
[n
];
14890 for (size_t i
= 0; i
< n
; ++i
)
14891 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14894 return gdb::array_view
<variant_part
> (result
, n
);
14897 /* Compute the variant part vector for FIP, attaching it to TYPE when
14901 add_variant_property (struct field_info
*fip
, struct type
*type
,
14902 struct dwarf2_cu
*cu
)
14904 /* Map section offsets of fields to their field index. Note the
14905 field index here does not take the number of baseclasses into
14907 offset_map_type offset_map
;
14908 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14909 offset_map
[fip
->fields
[i
].offset
] = i
;
14911 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14912 gdb::array_view
<const variant_part
> parts
14913 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14914 fip
->variant_parts
);
14916 struct dynamic_prop prop
;
14917 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14918 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14921 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14924 /* Create the vector of fields, and attach it to the type. */
14927 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14928 struct dwarf2_cu
*cu
)
14930 int nfields
= fip
->nfields ();
14932 /* Record the field count, allocate space for the array of fields,
14933 and create blank accessibility bitfields if necessary. */
14934 type
->set_num_fields (nfields
);
14936 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14938 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
14940 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14942 TYPE_FIELD_PRIVATE_BITS (type
) =
14943 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14944 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14946 TYPE_FIELD_PROTECTED_BITS (type
) =
14947 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14948 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14950 TYPE_FIELD_IGNORE_BITS (type
) =
14951 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14952 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14955 /* If the type has baseclasses, allocate and clear a bit vector for
14956 TYPE_FIELD_VIRTUAL_BITS. */
14957 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
14959 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14960 unsigned char *pointer
;
14962 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14963 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14964 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14965 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14966 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14969 if (!fip
->variant_parts
.empty ())
14970 add_variant_property (fip
, type
, cu
);
14972 /* Copy the saved-up fields into the field vector. */
14973 for (int i
= 0; i
< nfields
; ++i
)
14975 struct nextfield
&field
14976 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14977 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14979 type
->field (i
) = field
.field
;
14980 switch (field
.accessibility
)
14982 case DW_ACCESS_private
:
14983 if (cu
->per_cu
->lang
!= language_ada
)
14984 SET_TYPE_FIELD_PRIVATE (type
, i
);
14987 case DW_ACCESS_protected
:
14988 if (cu
->per_cu
->lang
!= language_ada
)
14989 SET_TYPE_FIELD_PROTECTED (type
, i
);
14992 case DW_ACCESS_public
:
14996 /* Unknown accessibility. Complain and treat it as public. */
14998 complaint (_("unsupported accessibility %d"),
14999 field
.accessibility
);
15003 if (i
< fip
->baseclasses
.size ())
15005 switch (field
.virtuality
)
15007 case DW_VIRTUALITY_virtual
:
15008 case DW_VIRTUALITY_pure_virtual
:
15009 if (cu
->per_cu
->lang
== language_ada
)
15010 error (_("unexpected virtuality in component of Ada type"));
15011 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15018 /* Return true if this member function is a constructor, false
15022 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15024 const char *fieldname
;
15025 const char *type_name
;
15028 if (die
->parent
== NULL
)
15031 if (die
->parent
->tag
!= DW_TAG_structure_type
15032 && die
->parent
->tag
!= DW_TAG_union_type
15033 && die
->parent
->tag
!= DW_TAG_class_type
)
15036 fieldname
= dwarf2_name (die
, cu
);
15037 type_name
= dwarf2_name (die
->parent
, cu
);
15038 if (fieldname
== NULL
|| type_name
== NULL
)
15041 len
= strlen (fieldname
);
15042 return (strncmp (fieldname
, type_name
, len
) == 0
15043 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15046 /* Add a member function to the proper fieldlist. */
15049 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15050 struct type
*type
, struct dwarf2_cu
*cu
)
15052 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15053 struct attribute
*attr
;
15055 struct fnfieldlist
*flp
= nullptr;
15056 struct fn_field
*fnp
;
15057 const char *fieldname
;
15058 struct type
*this_type
;
15060 if (cu
->per_cu
->lang
== language_ada
)
15061 error (_("unexpected member function in Ada type"));
15063 /* Get name of member function. */
15064 fieldname
= dwarf2_name (die
, cu
);
15065 if (fieldname
== NULL
)
15068 /* Look up member function name in fieldlist. */
15069 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15071 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15073 flp
= &fip
->fnfieldlists
[i
];
15078 /* Create a new fnfieldlist if necessary. */
15079 if (flp
== nullptr)
15081 fip
->fnfieldlists
.emplace_back ();
15082 flp
= &fip
->fnfieldlists
.back ();
15083 flp
->name
= fieldname
;
15084 i
= fip
->fnfieldlists
.size () - 1;
15087 /* Create a new member function field and add it to the vector of
15089 flp
->fnfields
.emplace_back ();
15090 fnp
= &flp
->fnfields
.back ();
15092 /* Delay processing of the physname until later. */
15093 if (cu
->per_cu
->lang
== language_cplus
)
15094 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15098 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15099 fnp
->physname
= physname
? physname
: "";
15102 fnp
->type
= alloc_type (objfile
);
15103 this_type
= read_type_die (die
, cu
);
15104 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15106 int nparams
= this_type
->num_fields ();
15108 /* TYPE is the domain of this method, and THIS_TYPE is the type
15109 of the method itself (TYPE_CODE_METHOD). */
15110 smash_to_method_type (fnp
->type
, type
,
15111 TYPE_TARGET_TYPE (this_type
),
15112 this_type
->fields (),
15113 this_type
->num_fields (),
15114 this_type
->has_varargs ());
15116 /* Handle static member functions.
15117 Dwarf2 has no clean way to discern C++ static and non-static
15118 member functions. G++ helps GDB by marking the first
15119 parameter for non-static member functions (which is the this
15120 pointer) as artificial. We obtain this information from
15121 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15122 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15123 fnp
->voffset
= VOFFSET_STATIC
;
15126 complaint (_("member function type missing for '%s'"),
15127 dwarf2_full_name (fieldname
, die
, cu
));
15129 /* Get fcontext from DW_AT_containing_type if present. */
15130 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15131 fnp
->fcontext
= die_containing_type (die
, cu
);
15133 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15134 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15136 /* Get accessibility. */
15137 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15138 switch (accessibility
)
15140 case DW_ACCESS_private
:
15141 fnp
->is_private
= 1;
15143 case DW_ACCESS_protected
:
15144 fnp
->is_protected
= 1;
15148 /* Check for artificial methods. */
15149 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15150 if (attr
&& attr
->as_boolean ())
15151 fnp
->is_artificial
= 1;
15153 /* Check for defaulted methods. */
15154 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15155 if (attr
!= nullptr)
15156 fnp
->defaulted
= attr
->defaulted ();
15158 /* Check for deleted methods. */
15159 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15160 if (attr
!= nullptr && attr
->as_boolean ())
15161 fnp
->is_deleted
= 1;
15163 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15165 /* Get index in virtual function table if it is a virtual member
15166 function. For older versions of GCC, this is an offset in the
15167 appropriate virtual table, as specified by DW_AT_containing_type.
15168 For everyone else, it is an expression to be evaluated relative
15169 to the object address. */
15171 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15172 if (attr
!= nullptr)
15174 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15176 struct dwarf_block
*block
= attr
->as_block ();
15178 if (block
->data
[0] == DW_OP_constu
)
15180 /* Old-style GCC. */
15181 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15183 else if (block
->data
[0] == DW_OP_deref
15184 || (block
->size
> 1
15185 && block
->data
[0] == DW_OP_deref_size
15186 && block
->data
[1] == cu
->header
.addr_size
))
15188 fnp
->voffset
= decode_locdesc (block
, cu
);
15189 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15190 dwarf2_complex_location_expr_complaint ();
15192 fnp
->voffset
/= cu
->header
.addr_size
;
15196 dwarf2_complex_location_expr_complaint ();
15198 if (!fnp
->fcontext
)
15200 /* If there is no `this' field and no DW_AT_containing_type,
15201 we cannot actually find a base class context for the
15203 if (this_type
->num_fields () == 0
15204 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15206 complaint (_("cannot determine context for virtual member "
15207 "function \"%s\" (offset %s)"),
15208 fieldname
, sect_offset_str (die
->sect_off
));
15213 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15217 else if (attr
->form_is_section_offset ())
15219 dwarf2_complex_location_expr_complaint ();
15223 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15229 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15230 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15232 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15233 complaint (_("Member function \"%s\" (offset %s) is virtual "
15234 "but the vtable offset is not specified"),
15235 fieldname
, sect_offset_str (die
->sect_off
));
15236 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15237 TYPE_CPLUS_DYNAMIC (type
) = 1;
15242 /* Create the vector of member function fields, and attach it to the type. */
15245 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15246 struct dwarf2_cu
*cu
)
15248 if (cu
->per_cu
->lang
== language_ada
)
15249 error (_("unexpected member functions in Ada type"));
15251 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15252 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15254 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15256 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15258 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15259 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15261 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15262 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15263 fn_flp
->fn_fields
= (struct fn_field
*)
15264 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15266 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15267 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15270 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15273 /* Returns non-zero if NAME is the name of a vtable member in CU's
15274 language, zero otherwise. */
15276 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15278 static const char vptr
[] = "_vptr";
15280 /* Look for the C++ form of the vtable. */
15281 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15287 /* GCC outputs unnamed structures that are really pointers to member
15288 functions, with the ABI-specified layout. If TYPE describes
15289 such a structure, smash it into a member function type.
15291 GCC shouldn't do this; it should just output pointer to member DIEs.
15292 This is GCC PR debug/28767. */
15295 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15297 struct type
*pfn_type
, *self_type
, *new_type
;
15299 /* Check for a structure with no name and two children. */
15300 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15303 /* Check for __pfn and __delta members. */
15304 if (type
->field (0).name () == NULL
15305 || strcmp (type
->field (0).name (), "__pfn") != 0
15306 || type
->field (1).name () == NULL
15307 || strcmp (type
->field (1).name (), "__delta") != 0)
15310 /* Find the type of the method. */
15311 pfn_type
= type
->field (0).type ();
15312 if (pfn_type
== NULL
15313 || pfn_type
->code () != TYPE_CODE_PTR
15314 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15317 /* Look for the "this" argument. */
15318 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15319 if (pfn_type
->num_fields () == 0
15320 /* || pfn_type->field (0).type () == NULL */
15321 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15324 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15325 new_type
= alloc_type (objfile
);
15326 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15327 pfn_type
->fields (), pfn_type
->num_fields (),
15328 pfn_type
->has_varargs ());
15329 smash_to_methodptr_type (type
, new_type
);
15332 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15333 requires rewriting, then copy it and return the updated copy.
15334 Otherwise return nullptr. */
15336 static struct type
*
15337 rewrite_array_type (struct type
*type
)
15339 if (type
->code () != TYPE_CODE_ARRAY
)
15342 struct type
*index_type
= type
->index_type ();
15343 range_bounds
*current_bounds
= index_type
->bounds ();
15345 /* Handle multi-dimensional arrays. */
15346 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15347 if (new_target
== nullptr)
15349 /* Maybe we don't need to rewrite this array. */
15350 if (current_bounds
->low
.kind () == PROP_CONST
15351 && current_bounds
->high
.kind () == PROP_CONST
)
15355 /* Either the target type was rewritten, or the bounds have to be
15356 updated. Either way we want to copy the type and update
15358 struct type
*copy
= copy_type (type
);
15359 int nfields
= copy
->num_fields ();
15361 = ((struct field
*) TYPE_ZALLOC (copy
,
15362 nfields
* sizeof (struct field
)));
15363 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15364 copy
->set_fields (new_fields
);
15365 if (new_target
!= nullptr)
15366 TYPE_TARGET_TYPE (copy
) = new_target
;
15368 struct type
*index_copy
= copy_type (index_type
);
15369 range_bounds
*bounds
15370 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15371 sizeof (range_bounds
));
15372 *bounds
= *current_bounds
;
15373 bounds
->low
.set_const_val (1);
15374 bounds
->high
.set_const_val (0);
15375 index_copy
->set_bounds (bounds
);
15376 copy
->set_index_type (index_copy
);
15381 /* While some versions of GCC will generate complicated DWARF for an
15382 array (see quirk_ada_thick_pointer), more recent versions were
15383 modified to emit an explicit thick pointer structure. However, in
15384 this case, the array still has DWARF expressions for its ranges,
15385 and these must be ignored. */
15388 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15391 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15393 /* Check for a structure with two children. */
15394 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15397 /* Check for P_ARRAY and P_BOUNDS members. */
15398 if (type
->field (0).name () == NULL
15399 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
15400 || type
->field (1).name () == NULL
15401 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
15404 /* Make sure we're looking at a pointer to an array. */
15405 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15408 /* The Ada code already knows how to handle these types, so all that
15409 we need to do is turn the bounds into static bounds. However, we
15410 don't want to rewrite existing array or index types in-place,
15411 because those may be referenced in other contexts where this
15412 rewriting is undesirable. */
15413 struct type
*new_ary_type
15414 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15415 if (new_ary_type
!= nullptr)
15416 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15419 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15420 appropriate error checking and issuing complaints if there is a
15424 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15426 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15428 if (attr
== nullptr)
15431 if (!attr
->form_is_constant ())
15433 complaint (_("DW_AT_alignment must have constant form"
15434 " - DIE at %s [in module %s]"),
15435 sect_offset_str (die
->sect_off
),
15436 objfile_name (cu
->per_objfile
->objfile
));
15440 LONGEST val
= attr
->constant_value (0);
15443 complaint (_("DW_AT_alignment value must not be negative"
15444 " - DIE at %s [in module %s]"),
15445 sect_offset_str (die
->sect_off
),
15446 objfile_name (cu
->per_objfile
->objfile
));
15449 ULONGEST align
= val
;
15453 complaint (_("DW_AT_alignment value must not be zero"
15454 " - DIE at %s [in module %s]"),
15455 sect_offset_str (die
->sect_off
),
15456 objfile_name (cu
->per_objfile
->objfile
));
15459 if ((align
& (align
- 1)) != 0)
15461 complaint (_("DW_AT_alignment value must be a power of 2"
15462 " - DIE at %s [in module %s]"),
15463 sect_offset_str (die
->sect_off
),
15464 objfile_name (cu
->per_objfile
->objfile
));
15471 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15472 the alignment for TYPE. */
15475 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15478 if (!set_type_align (type
, get_alignment (cu
, die
)))
15479 complaint (_("DW_AT_alignment value too large"
15480 " - DIE at %s [in module %s]"),
15481 sect_offset_str (die
->sect_off
),
15482 objfile_name (cu
->per_objfile
->objfile
));
15485 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15486 constant for a type, according to DWARF5 spec, Table 5.5. */
15489 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15494 case DW_CC_pass_by_reference
:
15495 case DW_CC_pass_by_value
:
15499 complaint (_("unrecognized DW_AT_calling_convention value "
15500 "(%s) for a type"), pulongest (value
));
15505 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15506 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15507 also according to GNU-specific values (see include/dwarf2.h). */
15510 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15515 case DW_CC_program
:
15519 case DW_CC_GNU_renesas_sh
:
15520 case DW_CC_GNU_borland_fastcall_i386
:
15521 case DW_CC_GDB_IBM_OpenCL
:
15525 complaint (_("unrecognized DW_AT_calling_convention value "
15526 "(%s) for a subroutine"), pulongest (value
));
15531 /* Called when we find the DIE that starts a structure or union scope
15532 (definition) to create a type for the structure or union. Fill in
15533 the type's name and general properties; the members will not be
15534 processed until process_structure_scope. A symbol table entry for
15535 the type will also not be done until process_structure_scope (assuming
15536 the type has a name).
15538 NOTE: we need to call these functions regardless of whether or not the
15539 DIE has a DW_AT_name attribute, since it might be an anonymous
15540 structure or union. This gets the type entered into our set of
15541 user defined types. */
15543 static struct type
*
15544 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15546 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15548 struct attribute
*attr
;
15551 /* If the definition of this type lives in .debug_types, read that type.
15552 Don't follow DW_AT_specification though, that will take us back up
15553 the chain and we want to go down. */
15554 attr
= die
->attr (DW_AT_signature
);
15555 if (attr
!= nullptr)
15557 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15559 /* The type's CU may not be the same as CU.
15560 Ensure TYPE is recorded with CU in die_type_hash. */
15561 return set_die_type (die
, type
, cu
);
15564 type
= alloc_type (objfile
);
15565 INIT_CPLUS_SPECIFIC (type
);
15567 name
= dwarf2_name (die
, cu
);
15570 if (cu
->per_cu
->lang
== language_cplus
15571 || cu
->per_cu
->lang
== language_d
15572 || cu
->per_cu
->lang
== language_rust
)
15574 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15576 /* dwarf2_full_name might have already finished building the DIE's
15577 type. If so, there is no need to continue. */
15578 if (get_die_type (die
, cu
) != NULL
)
15579 return get_die_type (die
, cu
);
15581 type
->set_name (full_name
);
15585 /* The name is already allocated along with this objfile, so
15586 we don't need to duplicate it for the type. */
15587 type
->set_name (name
);
15591 if (die
->tag
== DW_TAG_structure_type
)
15593 type
->set_code (TYPE_CODE_STRUCT
);
15595 else if (die
->tag
== DW_TAG_union_type
)
15597 type
->set_code (TYPE_CODE_UNION
);
15601 type
->set_code (TYPE_CODE_STRUCT
);
15604 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15605 type
->set_is_declared_class (true);
15607 /* Store the calling convention in the type if it's available in
15608 the die. Otherwise the calling convention remains set to
15609 the default value DW_CC_normal. */
15610 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15611 if (attr
!= nullptr
15612 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15614 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15615 TYPE_CPLUS_CALLING_CONVENTION (type
)
15616 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15619 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15620 if (attr
!= nullptr)
15622 if (attr
->form_is_constant ())
15623 TYPE_LENGTH (type
) = attr
->constant_value (0);
15626 struct dynamic_prop prop
;
15627 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15628 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15629 TYPE_LENGTH (type
) = 0;
15634 TYPE_LENGTH (type
) = 0;
15637 maybe_set_alignment (cu
, die
, type
);
15639 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15641 /* ICC<14 does not output the required DW_AT_declaration on
15642 incomplete types, but gives them a size of zero. */
15643 type
->set_is_stub (true);
15646 type
->set_stub_is_supported (true);
15648 if (die_is_declaration (die
, cu
))
15649 type
->set_is_stub (true);
15650 else if (attr
== NULL
&& die
->child
== NULL
15651 && producer_is_realview (cu
->producer
))
15652 /* RealView does not output the required DW_AT_declaration
15653 on incomplete types. */
15654 type
->set_is_stub (true);
15656 /* We need to add the type field to the die immediately so we don't
15657 infinitely recurse when dealing with pointers to the structure
15658 type within the structure itself. */
15659 set_die_type (die
, type
, cu
);
15661 /* set_die_type should be already done. */
15662 set_descriptive_type (type
, die
, cu
);
15667 static void handle_struct_member_die
15668 (struct die_info
*child_die
,
15670 struct field_info
*fi
,
15671 std::vector
<struct symbol
*> *template_args
,
15672 struct dwarf2_cu
*cu
);
15674 /* A helper for handle_struct_member_die that handles
15675 DW_TAG_variant_part. */
15678 handle_variant_part (struct die_info
*die
, struct type
*type
,
15679 struct field_info
*fi
,
15680 std::vector
<struct symbol
*> *template_args
,
15681 struct dwarf2_cu
*cu
)
15683 variant_part_builder
*new_part
;
15684 if (fi
->current_variant_part
== nullptr)
15686 fi
->variant_parts
.emplace_back ();
15687 new_part
= &fi
->variant_parts
.back ();
15689 else if (!fi
->current_variant_part
->processing_variant
)
15691 complaint (_("nested DW_TAG_variant_part seen "
15692 "- DIE at %s [in module %s]"),
15693 sect_offset_str (die
->sect_off
),
15694 objfile_name (cu
->per_objfile
->objfile
));
15699 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15700 current
.variant_parts
.emplace_back ();
15701 new_part
= ¤t
.variant_parts
.back ();
15704 /* When we recurse, we want callees to add to this new variant
15706 scoped_restore save_current_variant_part
15707 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15709 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15712 /* It's a univariant form, an extension we support. */
15714 else if (discr
->form_is_ref ())
15716 struct dwarf2_cu
*target_cu
= cu
;
15717 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15719 new_part
->discriminant_offset
= target_die
->sect_off
;
15723 complaint (_("DW_AT_discr does not have DIE reference form"
15724 " - DIE at %s [in module %s]"),
15725 sect_offset_str (die
->sect_off
),
15726 objfile_name (cu
->per_objfile
->objfile
));
15729 for (die_info
*child_die
= die
->child
;
15731 child_die
= child_die
->sibling
)
15732 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15735 /* A helper for handle_struct_member_die that handles
15739 handle_variant (struct die_info
*die
, struct type
*type
,
15740 struct field_info
*fi
,
15741 std::vector
<struct symbol
*> *template_args
,
15742 struct dwarf2_cu
*cu
)
15744 if (fi
->current_variant_part
== nullptr)
15746 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15747 "- DIE at %s [in module %s]"),
15748 sect_offset_str (die
->sect_off
),
15749 objfile_name (cu
->per_objfile
->objfile
));
15752 if (fi
->current_variant_part
->processing_variant
)
15754 complaint (_("nested DW_TAG_variant seen "
15755 "- DIE at %s [in module %s]"),
15756 sect_offset_str (die
->sect_off
),
15757 objfile_name (cu
->per_objfile
->objfile
));
15761 scoped_restore save_processing_variant
15762 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15765 fi
->current_variant_part
->variants
.emplace_back ();
15766 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15767 variant
.first_field
= fi
->fields
.size ();
15769 /* In a variant we want to get the discriminant and also add a
15770 field for our sole member child. */
15771 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15772 if (discr
== nullptr || !discr
->form_is_constant ())
15774 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15775 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15776 variant
.default_branch
= true;
15778 variant
.discr_list_data
= discr
->as_block ();
15781 variant
.discriminant_value
= discr
->constant_value (0);
15783 for (die_info
*variant_child
= die
->child
;
15784 variant_child
!= NULL
;
15785 variant_child
= variant_child
->sibling
)
15786 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15788 variant
.last_field
= fi
->fields
.size ();
15791 /* A helper for process_structure_scope that handles a single member
15795 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15796 struct field_info
*fi
,
15797 std::vector
<struct symbol
*> *template_args
,
15798 struct dwarf2_cu
*cu
)
15800 if (child_die
->tag
== DW_TAG_member
15801 || child_die
->tag
== DW_TAG_variable
)
15803 /* NOTE: carlton/2002-11-05: A C++ static data member
15804 should be a DW_TAG_member that is a declaration, but
15805 all versions of G++ as of this writing (so through at
15806 least 3.2.1) incorrectly generate DW_TAG_variable
15807 tags for them instead. */
15808 dwarf2_add_field (fi
, child_die
, cu
);
15810 else if (child_die
->tag
== DW_TAG_subprogram
)
15812 /* Rust doesn't have member functions in the C++ sense.
15813 However, it does emit ordinary functions as children
15814 of a struct DIE. */
15815 if (cu
->per_cu
->lang
== language_rust
)
15816 read_func_scope (child_die
, cu
);
15819 /* C++ member function. */
15820 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15823 else if (child_die
->tag
== DW_TAG_inheritance
)
15825 /* C++ base class field. */
15826 dwarf2_add_field (fi
, child_die
, cu
);
15828 else if (type_can_define_types (child_die
))
15829 dwarf2_add_type_defn (fi
, child_die
, cu
);
15830 else if (child_die
->tag
== DW_TAG_template_type_param
15831 || child_die
->tag
== DW_TAG_template_value_param
)
15833 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15836 template_args
->push_back (arg
);
15838 else if (child_die
->tag
== DW_TAG_variant_part
)
15839 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15840 else if (child_die
->tag
== DW_TAG_variant
)
15841 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15844 /* Finish creating a structure or union type, including filling in
15845 its members and creating a symbol for it. */
15848 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15850 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15851 struct die_info
*child_die
;
15854 type
= get_die_type (die
, cu
);
15856 type
= read_structure_type (die
, cu
);
15858 bool has_template_parameters
= false;
15859 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15861 struct field_info fi
;
15862 std::vector
<struct symbol
*> template_args
;
15864 child_die
= die
->child
;
15866 while (child_die
&& child_die
->tag
)
15868 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15869 child_die
= child_die
->sibling
;
15872 /* Attach template arguments to type. */
15873 if (!template_args
.empty ())
15875 has_template_parameters
= true;
15876 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15877 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15878 TYPE_TEMPLATE_ARGUMENTS (type
)
15879 = XOBNEWVEC (&objfile
->objfile_obstack
,
15881 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15882 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15883 template_args
.data (),
15884 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15885 * sizeof (struct symbol
*)));
15888 /* Attach fields and member functions to the type. */
15889 if (fi
.nfields () > 0)
15890 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15891 if (!fi
.fnfieldlists
.empty ())
15893 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15895 /* Get the type which refers to the base class (possibly this
15896 class itself) which contains the vtable pointer for the current
15897 class from the DW_AT_containing_type attribute. This use of
15898 DW_AT_containing_type is a GNU extension. */
15900 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15902 struct type
*t
= die_containing_type (die
, cu
);
15904 set_type_vptr_basetype (type
, t
);
15909 /* Our own class provides vtbl ptr. */
15910 for (i
= t
->num_fields () - 1;
15911 i
>= TYPE_N_BASECLASSES (t
);
15914 const char *fieldname
= t
->field (i
).name ();
15916 if (is_vtable_name (fieldname
, cu
))
15918 set_type_vptr_fieldno (type
, i
);
15923 /* Complain if virtual function table field not found. */
15924 if (i
< TYPE_N_BASECLASSES (t
))
15925 complaint (_("virtual function table pointer "
15926 "not found when defining class '%s'"),
15927 type
->name () ? type
->name () : "");
15931 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15934 else if (cu
->producer
15935 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15937 /* The IBM XLC compiler does not provide direct indication
15938 of the containing type, but the vtable pointer is
15939 always named __vfp. */
15943 for (i
= type
->num_fields () - 1;
15944 i
>= TYPE_N_BASECLASSES (type
);
15947 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
15949 set_type_vptr_fieldno (type
, i
);
15950 set_type_vptr_basetype (type
, type
);
15957 /* Copy fi.typedef_field_list linked list elements content into the
15958 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15959 if (!fi
.typedef_field_list
.empty ())
15961 int count
= fi
.typedef_field_list
.size ();
15963 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15964 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15965 = ((struct decl_field
*)
15967 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15968 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15970 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15971 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15974 /* Copy fi.nested_types_list linked list elements content into the
15975 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15976 if (!fi
.nested_types_list
.empty ()
15977 && cu
->per_cu
->lang
!= language_ada
)
15979 int count
= fi
.nested_types_list
.size ();
15981 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15982 TYPE_NESTED_TYPES_ARRAY (type
)
15983 = ((struct decl_field
*)
15984 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15985 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15987 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15988 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15992 quirk_gcc_member_function_pointer (type
, objfile
);
15993 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15994 cu
->rust_unions
.push_back (type
);
15995 else if (cu
->per_cu
->lang
== language_ada
)
15996 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15998 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15999 snapshots) has been known to create a die giving a declaration
16000 for a class that has, as a child, a die giving a definition for a
16001 nested class. So we have to process our children even if the
16002 current die is a declaration. Normally, of course, a declaration
16003 won't have any children at all. */
16005 child_die
= die
->child
;
16007 while (child_die
!= NULL
&& child_die
->tag
)
16009 if (child_die
->tag
== DW_TAG_member
16010 || child_die
->tag
== DW_TAG_variable
16011 || child_die
->tag
== DW_TAG_inheritance
16012 || child_die
->tag
== DW_TAG_template_value_param
16013 || child_die
->tag
== DW_TAG_template_type_param
)
16018 process_die (child_die
, cu
);
16020 child_die
= child_die
->sibling
;
16023 /* Do not consider external references. According to the DWARF standard,
16024 these DIEs are identified by the fact that they have no byte_size
16025 attribute, and a declaration attribute. */
16026 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16027 || !die_is_declaration (die
, cu
)
16028 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16030 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16032 if (has_template_parameters
)
16034 struct symtab
*symtab
;
16035 if (sym
!= nullptr)
16036 symtab
= symbol_symtab (sym
);
16037 else if (cu
->line_header
!= nullptr)
16039 /* Any related symtab will do. */
16041 = cu
->line_header
->file_names ()[0].symtab
;
16046 complaint (_("could not find suitable "
16047 "symtab for template parameter"
16048 " - DIE at %s [in module %s]"),
16049 sect_offset_str (die
->sect_off
),
16050 objfile_name (objfile
));
16053 if (symtab
!= nullptr)
16055 /* Make sure that the symtab is set on the new symbols.
16056 Even though they don't appear in this symtab directly,
16057 other parts of gdb assume that symbols do, and this is
16058 reasonably true. */
16059 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16060 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16066 /* Assuming DIE is an enumeration type, and TYPE is its associated
16067 type, update TYPE using some information only available in DIE's
16068 children. In particular, the fields are computed. */
16071 update_enumeration_type_from_children (struct die_info
*die
,
16073 struct dwarf2_cu
*cu
)
16075 struct die_info
*child_die
;
16076 int unsigned_enum
= 1;
16079 auto_obstack obstack
;
16080 std::vector
<struct field
> fields
;
16082 for (child_die
= die
->child
;
16083 child_die
!= NULL
&& child_die
->tag
;
16084 child_die
= child_die
->sibling
)
16086 struct attribute
*attr
;
16088 const gdb_byte
*bytes
;
16089 struct dwarf2_locexpr_baton
*baton
;
16092 if (child_die
->tag
!= DW_TAG_enumerator
)
16095 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16099 name
= dwarf2_name (child_die
, cu
);
16101 name
= "<anonymous enumerator>";
16103 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16104 &value
, &bytes
, &baton
);
16112 if (count_one_bits_ll (value
) >= 2)
16116 fields
.emplace_back ();
16117 struct field
&field
= fields
.back ();
16118 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
16119 field
.set_loc_enumval (value
);
16122 if (!fields
.empty ())
16124 type
->set_num_fields (fields
.size ());
16127 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16128 memcpy (type
->fields (), fields
.data (),
16129 sizeof (struct field
) * fields
.size ());
16133 type
->set_is_unsigned (true);
16136 type
->set_is_flag_enum (true);
16139 /* Given a DW_AT_enumeration_type die, set its type. We do not
16140 complete the type's fields yet, or create any symbols. */
16142 static struct type
*
16143 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16145 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16147 struct attribute
*attr
;
16150 /* If the definition of this type lives in .debug_types, read that type.
16151 Don't follow DW_AT_specification though, that will take us back up
16152 the chain and we want to go down. */
16153 attr
= die
->attr (DW_AT_signature
);
16154 if (attr
!= nullptr)
16156 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16158 /* The type's CU may not be the same as CU.
16159 Ensure TYPE is recorded with CU in die_type_hash. */
16160 return set_die_type (die
, type
, cu
);
16163 type
= alloc_type (objfile
);
16165 type
->set_code (TYPE_CODE_ENUM
);
16166 name
= dwarf2_full_name (NULL
, die
, cu
);
16168 type
->set_name (name
);
16170 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16173 struct type
*underlying_type
= die_type (die
, cu
);
16175 TYPE_TARGET_TYPE (type
) = underlying_type
;
16178 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16179 if (attr
!= nullptr)
16181 TYPE_LENGTH (type
) = attr
->constant_value (0);
16185 TYPE_LENGTH (type
) = 0;
16188 maybe_set_alignment (cu
, die
, type
);
16190 /* The enumeration DIE can be incomplete. In Ada, any type can be
16191 declared as private in the package spec, and then defined only
16192 inside the package body. Such types are known as Taft Amendment
16193 Types. When another package uses such a type, an incomplete DIE
16194 may be generated by the compiler. */
16195 if (die_is_declaration (die
, cu
))
16196 type
->set_is_stub (true);
16198 /* If this type has an underlying type that is not a stub, then we
16199 may use its attributes. We always use the "unsigned" attribute
16200 in this situation, because ordinarily we guess whether the type
16201 is unsigned -- but the guess can be wrong and the underlying type
16202 can tell us the reality. However, we defer to a local size
16203 attribute if one exists, because this lets the compiler override
16204 the underlying type if needed. */
16205 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16207 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16208 underlying_type
= check_typedef (underlying_type
);
16210 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16212 if (TYPE_LENGTH (type
) == 0)
16213 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16215 if (TYPE_RAW_ALIGN (type
) == 0
16216 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16217 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16220 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16222 set_die_type (die
, type
, cu
);
16224 /* Finish the creation of this type by using the enum's children.
16225 Note that, as usual, this must come after set_die_type to avoid
16226 infinite recursion when trying to compute the names of the
16228 update_enumeration_type_from_children (die
, type
, cu
);
16233 /* Given a pointer to a die which begins an enumeration, process all
16234 the dies that define the members of the enumeration, and create the
16235 symbol for the enumeration type.
16237 NOTE: We reverse the order of the element list. */
16240 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16242 struct type
*this_type
;
16244 this_type
= get_die_type (die
, cu
);
16245 if (this_type
== NULL
)
16246 this_type
= read_enumeration_type (die
, cu
);
16248 if (die
->child
!= NULL
)
16250 struct die_info
*child_die
;
16253 child_die
= die
->child
;
16254 while (child_die
&& child_die
->tag
)
16256 if (child_die
->tag
!= DW_TAG_enumerator
)
16258 process_die (child_die
, cu
);
16262 name
= dwarf2_name (child_die
, cu
);
16264 new_symbol (child_die
, this_type
, cu
);
16267 child_die
= child_die
->sibling
;
16271 /* If we are reading an enum from a .debug_types unit, and the enum
16272 is a declaration, and the enum is not the signatured type in the
16273 unit, then we do not want to add a symbol for it. Adding a
16274 symbol would in some cases obscure the true definition of the
16275 enum, giving users an incomplete type when the definition is
16276 actually available. Note that we do not want to do this for all
16277 enums which are just declarations, because C++0x allows forward
16278 enum declarations. */
16279 if (cu
->per_cu
->is_debug_types
16280 && die_is_declaration (die
, cu
))
16282 struct signatured_type
*sig_type
;
16284 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16285 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16286 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16290 new_symbol (die
, this_type
, cu
);
16293 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16294 expression for an index type and finds the corresponding field
16295 offset in the hidden "P_BOUNDS" structure. Returns true on success
16296 and updates *FIELD, false if it fails to recognize an
16300 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16301 int *bounds_offset
, struct field
*field
,
16302 struct dwarf2_cu
*cu
)
16304 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16305 if (attr
== nullptr || !attr
->form_is_block ())
16308 const struct dwarf_block
*block
= attr
->as_block ();
16309 const gdb_byte
*start
= block
->data
;
16310 const gdb_byte
*end
= block
->data
+ block
->size
;
16312 /* The expression to recognize generally looks like:
16314 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16315 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16317 However, the second "plus_uconst" may be missing:
16319 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16320 DW_OP_deref_size: 4)
16322 This happens when the field is at the start of the structure.
16324 Also, the final deref may not be sized:
16326 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16329 This happens when the size of the index type happens to be the
16330 same as the architecture's word size. This can occur with or
16331 without the second plus_uconst. */
16333 if (end
- start
< 2)
16335 if (*start
++ != DW_OP_push_object_address
)
16337 if (*start
++ != DW_OP_plus_uconst
)
16340 uint64_t this_bound_off
;
16341 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16342 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16344 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16345 is consistent among all bounds. */
16346 if (*bounds_offset
== -1)
16347 *bounds_offset
= this_bound_off
;
16348 else if (*bounds_offset
!= this_bound_off
)
16351 if (start
== end
|| *start
++ != DW_OP_deref
)
16357 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16359 /* This means an offset of 0. */
16361 else if (*start
++ != DW_OP_plus_uconst
)
16365 /* The size is the parameter to DW_OP_plus_uconst. */
16367 start
= gdb_read_uleb128 (start
, end
, &val
);
16368 if (start
== nullptr)
16370 if ((int) val
!= val
)
16379 if (*start
== DW_OP_deref_size
)
16381 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16382 if (start
== nullptr)
16385 else if (*start
== DW_OP_deref
)
16387 size
= cu
->header
.addr_size
;
16393 field
->set_loc_bitpos (8 * offset
);
16394 if (size
!= TYPE_LENGTH (field
->type ()))
16395 FIELD_BITSIZE (*field
) = 8 * size
;
16400 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16401 some kinds of Ada arrays:
16403 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16404 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16405 <11e0> DW_AT_data_location: 2 byte block: 97 6
16406 (DW_OP_push_object_address; DW_OP_deref)
16407 <11e3> DW_AT_type : <0x1173>
16408 <11e7> DW_AT_sibling : <0x1201>
16409 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16410 <11ec> DW_AT_type : <0x1206>
16411 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16412 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16413 DW_OP_deref_size: 4)
16414 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16415 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16416 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16418 This actually represents a "thick pointer", which is a structure
16419 with two elements: one that is a pointer to the array data, and one
16420 that is a pointer to another structure; this second structure holds
16423 This returns a new type on success, or nullptr if this didn't
16424 recognize the type. */
16426 static struct type
*
16427 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16430 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16431 /* So far we've only seen this with block form. */
16432 if (attr
== nullptr || !attr
->form_is_block ())
16435 /* Note that this will fail if the structure layout is changed by
16436 the compiler. However, we have no good way to recognize some
16437 other layout, because we don't know what expression the compiler
16438 might choose to emit should this happen. */
16439 struct dwarf_block
*blk
= attr
->as_block ();
16441 || blk
->data
[0] != DW_OP_push_object_address
16442 || blk
->data
[1] != DW_OP_deref
)
16445 int bounds_offset
= -1;
16446 int max_align
= -1;
16447 std::vector
<struct field
> range_fields
;
16448 for (struct die_info
*child_die
= die
->child
;
16450 child_die
= child_die
->sibling
)
16452 if (child_die
->tag
== DW_TAG_subrange_type
)
16454 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16456 int this_align
= type_align (underlying
);
16457 if (this_align
> max_align
)
16458 max_align
= this_align
;
16460 range_fields
.emplace_back ();
16461 range_fields
.emplace_back ();
16463 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16464 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16466 lower
.set_type (underlying
);
16467 FIELD_ARTIFICIAL (lower
) = 1;
16469 upper
.set_type (underlying
);
16470 FIELD_ARTIFICIAL (upper
) = 1;
16472 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16473 &bounds_offset
, &lower
, cu
)
16474 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16475 &bounds_offset
, &upper
, cu
))
16480 /* This shouldn't really happen, but double-check that we found
16481 where the bounds are stored. */
16482 if (bounds_offset
== -1)
16485 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16486 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16490 /* Set the name of each field in the bounds. */
16491 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16492 range_fields
[i
].set_name (objfile
->intern (name
));
16493 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16494 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
16497 struct type
*bounds
= alloc_type (objfile
);
16498 bounds
->set_code (TYPE_CODE_STRUCT
);
16500 bounds
->set_num_fields (range_fields
.size ());
16502 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16503 * sizeof (struct field
))));
16504 memcpy (bounds
->fields (), range_fields
.data (),
16505 bounds
->num_fields () * sizeof (struct field
));
16507 int last_fieldno
= range_fields
.size () - 1;
16508 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
16509 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16510 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16512 /* Rewrite the existing array type in place. Specifically, we
16513 remove any dynamic properties we might have read, and we replace
16514 the index types. */
16515 struct type
*iter
= type
;
16516 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16518 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16519 iter
->main_type
->dyn_prop_list
= nullptr;
16520 iter
->set_index_type
16521 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16522 iter
= TYPE_TARGET_TYPE (iter
);
16525 struct type
*result
= alloc_type (objfile
);
16526 result
->set_code (TYPE_CODE_STRUCT
);
16528 result
->set_num_fields (2);
16530 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16531 * sizeof (struct field
))));
16533 /* The names are chosen to coincide with what the compiler does with
16534 -fgnat-encodings=all, which the Ada code in gdb already
16536 result
->field (0).set_name ("P_ARRAY");
16537 result
->field (0).set_type (lookup_pointer_type (type
));
16539 result
->field (1).set_name ("P_BOUNDS");
16540 result
->field (1).set_type (lookup_pointer_type (bounds
));
16541 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
16543 result
->set_name (type
->name ());
16544 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16545 + TYPE_LENGTH (result
->field (1).type ()));
16550 /* Extract all information from a DW_TAG_array_type DIE and put it in
16551 the DIE's type field. For now, this only handles one dimensional
16554 static struct type
*
16555 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16557 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16558 struct die_info
*child_die
;
16560 struct type
*element_type
, *range_type
, *index_type
;
16561 struct attribute
*attr
;
16563 struct dynamic_prop
*byte_stride_prop
= NULL
;
16564 unsigned int bit_stride
= 0;
16566 element_type
= die_type (die
, cu
);
16568 /* The die_type call above may have already set the type for this DIE. */
16569 type
= get_die_type (die
, cu
);
16573 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16577 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16580 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16581 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16585 complaint (_("unable to read array DW_AT_byte_stride "
16586 " - DIE at %s [in module %s]"),
16587 sect_offset_str (die
->sect_off
),
16588 objfile_name (cu
->per_objfile
->objfile
));
16589 /* Ignore this attribute. We will likely not be able to print
16590 arrays of this type correctly, but there is little we can do
16591 to help if we cannot read the attribute's value. */
16592 byte_stride_prop
= NULL
;
16596 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16598 bit_stride
= attr
->constant_value (0);
16600 /* Irix 6.2 native cc creates array types without children for
16601 arrays with unspecified length. */
16602 if (die
->child
== NULL
)
16604 index_type
= objfile_type (objfile
)->builtin_int
;
16605 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16606 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16607 byte_stride_prop
, bit_stride
);
16608 return set_die_type (die
, type
, cu
);
16611 std::vector
<struct type
*> range_types
;
16612 child_die
= die
->child
;
16613 while (child_die
&& child_die
->tag
)
16615 if (child_die
->tag
== DW_TAG_subrange_type
)
16617 struct type
*child_type
= read_type_die (child_die
, cu
);
16619 if (child_type
!= NULL
)
16621 /* The range type was succesfully read. Save it for the
16622 array type creation. */
16623 range_types
.push_back (child_type
);
16626 child_die
= child_die
->sibling
;
16629 if (range_types
.empty ())
16631 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16632 sect_offset_str (die
->sect_off
),
16633 objfile_name (cu
->per_objfile
->objfile
));
16637 /* Dwarf2 dimensions are output from left to right, create the
16638 necessary array types in backwards order. */
16640 type
= element_type
;
16642 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16646 while (i
< range_types
.size ())
16648 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16649 byte_stride_prop
, bit_stride
);
16651 byte_stride_prop
= nullptr;
16656 size_t ndim
= range_types
.size ();
16659 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16660 byte_stride_prop
, bit_stride
);
16662 byte_stride_prop
= nullptr;
16666 gdb_assert (type
!= element_type
);
16668 /* Understand Dwarf2 support for vector types (like they occur on
16669 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16670 array type. This is not part of the Dwarf2/3 standard yet, but a
16671 custom vendor extension. The main difference between a regular
16672 array and the vector variant is that vectors are passed by value
16674 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16675 if (attr
!= nullptr)
16676 make_vector_type (type
);
16678 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16679 implementation may choose to implement triple vectors using this
16681 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16682 if (attr
!= nullptr && attr
->form_is_unsigned ())
16684 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16685 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16687 complaint (_("DW_AT_byte_size for array type smaller "
16688 "than the total size of elements"));
16691 name
= dwarf2_name (die
, cu
);
16693 type
->set_name (name
);
16695 maybe_set_alignment (cu
, die
, type
);
16697 struct type
*replacement_type
= nullptr;
16698 if (cu
->per_cu
->lang
== language_ada
)
16700 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16701 if (replacement_type
!= nullptr)
16702 type
= replacement_type
;
16705 /* Install the type in the die. */
16706 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16708 /* set_die_type should be already done. */
16709 set_descriptive_type (type
, die
, cu
);
16714 static enum dwarf_array_dim_ordering
16715 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16717 struct attribute
*attr
;
16719 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16721 if (attr
!= nullptr)
16723 LONGEST val
= attr
->constant_value (-1);
16724 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16725 return (enum dwarf_array_dim_ordering
) val
;
16728 /* GNU F77 is a special case, as at 08/2004 array type info is the
16729 opposite order to the dwarf2 specification, but data is still
16730 laid out as per normal fortran.
16732 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16733 version checking. */
16735 if (cu
->per_cu
->lang
== language_fortran
16736 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16738 return DW_ORD_row_major
;
16741 switch (cu
->language_defn
->array_ordering ())
16743 case array_column_major
:
16744 return DW_ORD_col_major
;
16745 case array_row_major
:
16747 return DW_ORD_row_major
;
16751 /* Extract all information from a DW_TAG_set_type DIE and put it in
16752 the DIE's type field. */
16754 static struct type
*
16755 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16757 struct type
*domain_type
, *set_type
;
16758 struct attribute
*attr
;
16760 domain_type
= die_type (die
, cu
);
16762 /* The die_type call above may have already set the type for this DIE. */
16763 set_type
= get_die_type (die
, cu
);
16767 set_type
= create_set_type (NULL
, domain_type
);
16769 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16770 if (attr
!= nullptr && attr
->form_is_unsigned ())
16771 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16773 maybe_set_alignment (cu
, die
, set_type
);
16775 return set_die_type (die
, set_type
, cu
);
16778 /* A helper for read_common_block that creates a locexpr baton.
16779 SYM is the symbol which we are marking as computed.
16780 COMMON_DIE is the DIE for the common block.
16781 COMMON_LOC is the location expression attribute for the common
16783 MEMBER_LOC is the location expression attribute for the particular
16784 member of the common block that we are processing.
16785 CU is the CU from which the above come. */
16788 mark_common_block_symbol_computed (struct symbol
*sym
,
16789 struct die_info
*common_die
,
16790 struct attribute
*common_loc
,
16791 struct attribute
*member_loc
,
16792 struct dwarf2_cu
*cu
)
16794 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16795 struct objfile
*objfile
= per_objfile
->objfile
;
16796 struct dwarf2_locexpr_baton
*baton
;
16798 unsigned int cu_off
;
16799 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16800 LONGEST offset
= 0;
16802 gdb_assert (common_loc
&& member_loc
);
16803 gdb_assert (common_loc
->form_is_block ());
16804 gdb_assert (member_loc
->form_is_block ()
16805 || member_loc
->form_is_constant ());
16807 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16808 baton
->per_objfile
= per_objfile
;
16809 baton
->per_cu
= cu
->per_cu
;
16810 gdb_assert (baton
->per_cu
);
16812 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16814 if (member_loc
->form_is_constant ())
16816 offset
= member_loc
->constant_value (0);
16817 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16820 baton
->size
+= member_loc
->as_block ()->size
;
16822 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16825 *ptr
++ = DW_OP_call4
;
16826 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16827 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16830 if (member_loc
->form_is_constant ())
16832 *ptr
++ = DW_OP_addr
;
16833 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16834 ptr
+= cu
->header
.addr_size
;
16838 /* We have to copy the data here, because DW_OP_call4 will only
16839 use a DW_AT_location attribute. */
16840 struct dwarf_block
*block
= member_loc
->as_block ();
16841 memcpy (ptr
, block
->data
, block
->size
);
16842 ptr
+= block
->size
;
16845 *ptr
++ = DW_OP_plus
;
16846 gdb_assert (ptr
- baton
->data
== baton
->size
);
16848 SYMBOL_LOCATION_BATON (sym
) = baton
;
16849 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16852 /* Create appropriate locally-scoped variables for all the
16853 DW_TAG_common_block entries. Also create a struct common_block
16854 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16855 is used to separate the common blocks name namespace from regular
16859 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16861 struct attribute
*attr
;
16863 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16864 if (attr
!= nullptr)
16866 /* Support the .debug_loc offsets. */
16867 if (attr
->form_is_block ())
16871 else if (attr
->form_is_section_offset ())
16873 dwarf2_complex_location_expr_complaint ();
16878 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16879 "common block member");
16884 if (die
->child
!= NULL
)
16886 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16887 struct die_info
*child_die
;
16888 size_t n_entries
= 0, size
;
16889 struct common_block
*common_block
;
16890 struct symbol
*sym
;
16892 for (child_die
= die
->child
;
16893 child_die
&& child_die
->tag
;
16894 child_die
= child_die
->sibling
)
16897 size
= (sizeof (struct common_block
)
16898 + (n_entries
- 1) * sizeof (struct symbol
*));
16900 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16902 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16903 common_block
->n_entries
= 0;
16905 for (child_die
= die
->child
;
16906 child_die
&& child_die
->tag
;
16907 child_die
= child_die
->sibling
)
16909 /* Create the symbol in the DW_TAG_common_block block in the current
16911 sym
= new_symbol (child_die
, NULL
, cu
);
16914 struct attribute
*member_loc
;
16916 common_block
->contents
[common_block
->n_entries
++] = sym
;
16918 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16922 /* GDB has handled this for a long time, but it is
16923 not specified by DWARF. It seems to have been
16924 emitted by gfortran at least as recently as:
16925 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16926 complaint (_("Variable in common block has "
16927 "DW_AT_data_member_location "
16928 "- DIE at %s [in module %s]"),
16929 sect_offset_str (child_die
->sect_off
),
16930 objfile_name (objfile
));
16932 if (member_loc
->form_is_section_offset ())
16933 dwarf2_complex_location_expr_complaint ();
16934 else if (member_loc
->form_is_constant ()
16935 || member_loc
->form_is_block ())
16937 if (attr
!= nullptr)
16938 mark_common_block_symbol_computed (sym
, die
, attr
,
16942 dwarf2_complex_location_expr_complaint ();
16947 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16948 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16952 /* Create a type for a C++ namespace. */
16954 static struct type
*
16955 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16957 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16958 const char *previous_prefix
, *name
;
16962 /* For extensions, reuse the type of the original namespace. */
16963 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16965 struct die_info
*ext_die
;
16966 struct dwarf2_cu
*ext_cu
= cu
;
16968 ext_die
= dwarf2_extension (die
, &ext_cu
);
16969 type
= read_type_die (ext_die
, ext_cu
);
16971 /* EXT_CU may not be the same as CU.
16972 Ensure TYPE is recorded with CU in die_type_hash. */
16973 return set_die_type (die
, type
, cu
);
16976 name
= namespace_name (die
, &is_anonymous
, cu
);
16978 /* Now build the name of the current namespace. */
16980 previous_prefix
= determine_prefix (die
, cu
);
16981 if (previous_prefix
[0] != '\0')
16982 name
= typename_concat (&objfile
->objfile_obstack
,
16983 previous_prefix
, name
, 0, cu
);
16985 /* Create the type. */
16986 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16988 return set_die_type (die
, type
, cu
);
16991 /* Read a namespace scope. */
16994 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16996 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16999 /* Add a symbol associated to this if we haven't seen the namespace
17000 before. Also, add a using directive if it's an anonymous
17003 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17007 type
= read_type_die (die
, cu
);
17008 new_symbol (die
, type
, cu
);
17010 namespace_name (die
, &is_anonymous
, cu
);
17013 const char *previous_prefix
= determine_prefix (die
, cu
);
17015 std::vector
<const char *> excludes
;
17016 add_using_directive (using_directives (cu
),
17017 previous_prefix
, type
->name (), NULL
,
17018 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17022 if (die
->child
!= NULL
)
17024 struct die_info
*child_die
= die
->child
;
17026 while (child_die
&& child_die
->tag
)
17028 process_die (child_die
, cu
);
17029 child_die
= child_die
->sibling
;
17034 /* Read a Fortran module as type. This DIE can be only a declaration used for
17035 imported module. Still we need that type as local Fortran "use ... only"
17036 declaration imports depend on the created type in determine_prefix. */
17038 static struct type
*
17039 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17041 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17042 const char *module_name
;
17045 module_name
= dwarf2_name (die
, cu
);
17046 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17048 return set_die_type (die
, type
, cu
);
17051 /* Read a Fortran module. */
17054 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17056 struct die_info
*child_die
= die
->child
;
17059 type
= read_type_die (die
, cu
);
17060 new_symbol (die
, type
, cu
);
17062 while (child_die
&& child_die
->tag
)
17064 process_die (child_die
, cu
);
17065 child_die
= child_die
->sibling
;
17069 /* Return the name of the namespace represented by DIE. Set
17070 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17073 static const char *
17074 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17076 struct die_info
*current_die
;
17077 const char *name
= NULL
;
17079 /* Loop through the extensions until we find a name. */
17081 for (current_die
= die
;
17082 current_die
!= NULL
;
17083 current_die
= dwarf2_extension (die
, &cu
))
17085 /* We don't use dwarf2_name here so that we can detect the absence
17086 of a name -> anonymous namespace. */
17087 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17093 /* Is it an anonymous namespace? */
17095 *is_anonymous
= (name
== NULL
);
17097 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17102 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17103 the user defined type vector. */
17105 static struct type
*
17106 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17108 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17109 struct comp_unit_head
*cu_header
= &cu
->header
;
17111 struct attribute
*attr_byte_size
;
17112 struct attribute
*attr_address_class
;
17113 int byte_size
, addr_class
;
17114 struct type
*target_type
;
17116 target_type
= die_type (die
, cu
);
17118 /* The die_type call above may have already set the type for this DIE. */
17119 type
= get_die_type (die
, cu
);
17123 type
= lookup_pointer_type (target_type
);
17125 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17126 if (attr_byte_size
)
17127 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17129 byte_size
= cu_header
->addr_size
;
17131 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17132 if (attr_address_class
)
17133 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17135 addr_class
= DW_ADDR_none
;
17137 ULONGEST alignment
= get_alignment (cu
, die
);
17139 /* If the pointer size, alignment, or address class is different
17140 than the default, create a type variant marked as such and set
17141 the length accordingly. */
17142 if (TYPE_LENGTH (type
) != byte_size
17143 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17144 && alignment
!= TYPE_RAW_ALIGN (type
))
17145 || addr_class
!= DW_ADDR_none
)
17147 if (gdbarch_address_class_type_flags_p (gdbarch
))
17149 type_instance_flags type_flags
17150 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17152 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17154 type
= make_type_with_address_space (type
, type_flags
);
17156 else if (TYPE_LENGTH (type
) != byte_size
)
17158 complaint (_("invalid pointer size %d"), byte_size
);
17160 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17162 complaint (_("Invalid DW_AT_alignment"
17163 " - DIE at %s [in module %s]"),
17164 sect_offset_str (die
->sect_off
),
17165 objfile_name (cu
->per_objfile
->objfile
));
17169 /* Should we also complain about unhandled address classes? */
17173 TYPE_LENGTH (type
) = byte_size
;
17174 set_type_align (type
, alignment
);
17175 return set_die_type (die
, type
, cu
);
17178 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17179 the user defined type vector. */
17181 static struct type
*
17182 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17185 struct type
*to_type
;
17186 struct type
*domain
;
17188 to_type
= die_type (die
, cu
);
17189 domain
= die_containing_type (die
, cu
);
17191 /* The calls above may have already set the type for this DIE. */
17192 type
= get_die_type (die
, cu
);
17196 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17197 type
= lookup_methodptr_type (to_type
);
17198 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17200 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17202 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17203 to_type
->fields (), to_type
->num_fields (),
17204 to_type
->has_varargs ());
17205 type
= lookup_methodptr_type (new_type
);
17208 type
= lookup_memberptr_type (to_type
, domain
);
17210 return set_die_type (die
, type
, cu
);
17213 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17214 the user defined type vector. */
17216 static struct type
*
17217 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17218 enum type_code refcode
)
17220 struct comp_unit_head
*cu_header
= &cu
->header
;
17221 struct type
*type
, *target_type
;
17222 struct attribute
*attr
;
17224 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17226 target_type
= die_type (die
, cu
);
17228 /* The die_type call above may have already set the type for this DIE. */
17229 type
= get_die_type (die
, cu
);
17233 type
= lookup_reference_type (target_type
, refcode
);
17234 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17235 if (attr
!= nullptr)
17237 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17241 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17243 maybe_set_alignment (cu
, die
, type
);
17244 return set_die_type (die
, type
, cu
);
17247 /* Add the given cv-qualifiers to the element type of the array. GCC
17248 outputs DWARF type qualifiers that apply to an array, not the
17249 element type. But GDB relies on the array element type to carry
17250 the cv-qualifiers. This mimics section 6.7.3 of the C99
17253 static struct type
*
17254 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17255 struct type
*base_type
, int cnst
, int voltl
)
17257 struct type
*el_type
, *inner_array
;
17259 base_type
= copy_type (base_type
);
17260 inner_array
= base_type
;
17262 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17264 TYPE_TARGET_TYPE (inner_array
) =
17265 copy_type (TYPE_TARGET_TYPE (inner_array
));
17266 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17269 el_type
= TYPE_TARGET_TYPE (inner_array
);
17270 cnst
|= TYPE_CONST (el_type
);
17271 voltl
|= TYPE_VOLATILE (el_type
);
17272 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17274 return set_die_type (die
, base_type
, cu
);
17277 static struct type
*
17278 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17280 struct type
*base_type
, *cv_type
;
17282 base_type
= die_type (die
, cu
);
17284 /* The die_type call above may have already set the type for this DIE. */
17285 cv_type
= get_die_type (die
, cu
);
17289 /* In case the const qualifier is applied to an array type, the element type
17290 is so qualified, not the array type (section 6.7.3 of C99). */
17291 if (base_type
->code () == TYPE_CODE_ARRAY
)
17292 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17294 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17295 return set_die_type (die
, cv_type
, cu
);
17298 static struct type
*
17299 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17301 struct type
*base_type
, *cv_type
;
17303 base_type
= die_type (die
, cu
);
17305 /* The die_type call above may have already set the type for this DIE. */
17306 cv_type
= get_die_type (die
, cu
);
17310 /* In case the volatile qualifier is applied to an array type, the
17311 element type is so qualified, not the array type (section 6.7.3
17313 if (base_type
->code () == TYPE_CODE_ARRAY
)
17314 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17316 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17317 return set_die_type (die
, cv_type
, cu
);
17320 /* Handle DW_TAG_restrict_type. */
17322 static struct type
*
17323 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17325 struct type
*base_type
, *cv_type
;
17327 base_type
= die_type (die
, cu
);
17329 /* The die_type call above may have already set the type for this DIE. */
17330 cv_type
= get_die_type (die
, cu
);
17334 cv_type
= make_restrict_type (base_type
);
17335 return set_die_type (die
, cv_type
, cu
);
17338 /* Handle DW_TAG_atomic_type. */
17340 static struct type
*
17341 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17343 struct type
*base_type
, *cv_type
;
17345 base_type
= die_type (die
, cu
);
17347 /* The die_type call above may have already set the type for this DIE. */
17348 cv_type
= get_die_type (die
, cu
);
17352 cv_type
= make_atomic_type (base_type
);
17353 return set_die_type (die
, cv_type
, cu
);
17356 /* Extract all information from a DW_TAG_string_type DIE and add to
17357 the user defined type vector. It isn't really a user defined type,
17358 but it behaves like one, with other DIE's using an AT_user_def_type
17359 attribute to reference it. */
17361 static struct type
*
17362 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17364 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17365 struct gdbarch
*gdbarch
= objfile
->arch ();
17366 struct type
*type
, *range_type
, *index_type
, *char_type
;
17367 struct attribute
*attr
;
17368 struct dynamic_prop prop
;
17369 bool length_is_constant
= true;
17372 /* There are a couple of places where bit sizes might be made use of
17373 when parsing a DW_TAG_string_type, however, no producer that we know
17374 of make use of these. Handling bit sizes that are a multiple of the
17375 byte size is easy enough, but what about other bit sizes? Lets deal
17376 with that problem when we have to. Warn about these attributes being
17377 unsupported, then parse the type and ignore them like we always
17379 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17380 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17382 static bool warning_printed
= false;
17383 if (!warning_printed
)
17385 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17386 "currently supported on DW_TAG_string_type."));
17387 warning_printed
= true;
17391 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17392 if (attr
!= nullptr && !attr
->form_is_constant ())
17394 /* The string length describes the location at which the length of
17395 the string can be found. The size of the length field can be
17396 specified with one of the attributes below. */
17397 struct type
*prop_type
;
17398 struct attribute
*len
17399 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17400 if (len
== nullptr)
17401 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17402 if (len
!= nullptr && len
->form_is_constant ())
17404 /* Pass 0 as the default as we know this attribute is constant
17405 and the default value will not be returned. */
17406 LONGEST sz
= len
->constant_value (0);
17407 prop_type
= objfile_int_type (objfile
, sz
, true);
17411 /* If the size is not specified then we assume it is the size of
17412 an address on this target. */
17413 prop_type
= cu
->addr_sized_int_type (true);
17416 /* Convert the attribute into a dynamic property. */
17417 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17420 length_is_constant
= false;
17422 else if (attr
!= nullptr)
17424 /* This DW_AT_string_length just contains the length with no
17425 indirection. There's no need to create a dynamic property in this
17426 case. Pass 0 for the default value as we know it will not be
17427 returned in this case. */
17428 length
= attr
->constant_value (0);
17430 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17432 /* We don't currently support non-constant byte sizes for strings. */
17433 length
= attr
->constant_value (1);
17437 /* Use 1 as a fallback length if we have nothing else. */
17441 index_type
= objfile_type (objfile
)->builtin_int
;
17442 if (length_is_constant
)
17443 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17446 struct dynamic_prop low_bound
;
17448 low_bound
.set_const_val (1);
17449 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17451 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17452 type
= create_string_type (NULL
, char_type
, range_type
);
17454 return set_die_type (die
, type
, cu
);
17457 /* Assuming that DIE corresponds to a function, returns nonzero
17458 if the function is prototyped. */
17461 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17463 struct attribute
*attr
;
17465 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17466 if (attr
&& attr
->as_boolean ())
17469 /* The DWARF standard implies that the DW_AT_prototyped attribute
17470 is only meaningful for C, but the concept also extends to other
17471 languages that allow unprototyped functions (Eg: Objective C).
17472 For all other languages, assume that functions are always
17474 if (cu
->per_cu
->lang
!= language_c
17475 && cu
->per_cu
->lang
!= language_objc
17476 && cu
->per_cu
->lang
!= language_opencl
)
17479 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17480 prototyped and unprototyped functions; default to prototyped,
17481 since that is more common in modern code (and RealView warns
17482 about unprototyped functions). */
17483 if (producer_is_realview (cu
->producer
))
17489 /* Handle DIES due to C code like:
17493 int (*funcp)(int a, long l);
17497 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17499 static struct type
*
17500 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17502 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17503 struct type
*type
; /* Type that this function returns. */
17504 struct type
*ftype
; /* Function that returns above type. */
17505 struct attribute
*attr
;
17507 type
= die_type (die
, cu
);
17509 /* The die_type call above may have already set the type for this DIE. */
17510 ftype
= get_die_type (die
, cu
);
17514 ftype
= lookup_function_type (type
);
17516 if (prototyped_function_p (die
, cu
))
17517 ftype
->set_is_prototyped (true);
17519 /* Store the calling convention in the type if it's available in
17520 the subroutine die. Otherwise set the calling convention to
17521 the default value DW_CC_normal. */
17522 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17523 if (attr
!= nullptr
17524 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17525 TYPE_CALLING_CONVENTION (ftype
)
17526 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17527 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17528 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17530 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17532 /* Record whether the function returns normally to its caller or not
17533 if the DWARF producer set that information. */
17534 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17535 if (attr
&& attr
->as_boolean ())
17536 TYPE_NO_RETURN (ftype
) = 1;
17538 /* We need to add the subroutine type to the die immediately so
17539 we don't infinitely recurse when dealing with parameters
17540 declared as the same subroutine type. */
17541 set_die_type (die
, ftype
, cu
);
17543 if (die
->child
!= NULL
)
17545 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17546 struct die_info
*child_die
;
17547 int nparams
, iparams
;
17549 /* Count the number of parameters.
17550 FIXME: GDB currently ignores vararg functions, but knows about
17551 vararg member functions. */
17553 child_die
= die
->child
;
17554 while (child_die
&& child_die
->tag
)
17556 if (child_die
->tag
== DW_TAG_formal_parameter
)
17558 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17559 ftype
->set_has_varargs (true);
17561 child_die
= child_die
->sibling
;
17564 /* Allocate storage for parameters and fill them in. */
17565 ftype
->set_num_fields (nparams
);
17567 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17569 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17570 even if we error out during the parameters reading below. */
17571 for (iparams
= 0; iparams
< nparams
; iparams
++)
17572 ftype
->field (iparams
).set_type (void_type
);
17575 child_die
= die
->child
;
17576 while (child_die
&& child_die
->tag
)
17578 if (child_die
->tag
== DW_TAG_formal_parameter
)
17580 struct type
*arg_type
;
17582 /* DWARF version 2 has no clean way to discern C++
17583 static and non-static member functions. G++ helps
17584 GDB by marking the first parameter for non-static
17585 member functions (which is the this pointer) as
17586 artificial. We pass this information to
17587 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17589 DWARF version 3 added DW_AT_object_pointer, which GCC
17590 4.5 does not yet generate. */
17591 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17592 if (attr
!= nullptr)
17593 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17595 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17596 arg_type
= die_type (child_die
, cu
);
17598 /* RealView does not mark THIS as const, which the testsuite
17599 expects. GCC marks THIS as const in method definitions,
17600 but not in the class specifications (GCC PR 43053). */
17601 if (cu
->per_cu
->lang
== language_cplus
17602 && !TYPE_CONST (arg_type
)
17603 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17606 struct dwarf2_cu
*arg_cu
= cu
;
17607 const char *name
= dwarf2_name (child_die
, cu
);
17609 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17610 if (attr
!= nullptr)
17612 /* If the compiler emits this, use it. */
17613 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17616 else if (name
&& strcmp (name
, "this") == 0)
17617 /* Function definitions will have the argument names. */
17619 else if (name
== NULL
&& iparams
== 0)
17620 /* Declarations may not have the names, so like
17621 elsewhere in GDB, assume an artificial first
17622 argument is "this". */
17626 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17630 ftype
->field (iparams
).set_type (arg_type
);
17633 child_die
= child_die
->sibling
;
17640 static struct type
*
17641 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17643 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17644 const char *name
= NULL
;
17645 struct type
*this_type
, *target_type
;
17647 name
= dwarf2_full_name (NULL
, die
, cu
);
17648 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17649 this_type
->set_target_is_stub (true);
17650 set_die_type (die
, this_type
, cu
);
17651 target_type
= die_type (die
, cu
);
17652 if (target_type
!= this_type
)
17653 TYPE_TARGET_TYPE (this_type
) = target_type
;
17656 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17657 spec and cause infinite loops in GDB. */
17658 complaint (_("Self-referential DW_TAG_typedef "
17659 "- DIE at %s [in module %s]"),
17660 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17661 TYPE_TARGET_TYPE (this_type
) = NULL
;
17665 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17666 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17667 Handle these by just returning the target type, rather than
17668 constructing an anonymous typedef type and trying to handle this
17670 set_die_type (die
, target_type
, cu
);
17671 return target_type
;
17676 /* Helper for get_dwarf2_rational_constant that computes the value of
17677 a given gmp_mpz given an attribute. */
17680 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17682 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17683 location expression that pushes an implicit value. */
17684 if (attr
->form
== DW_FORM_exprloc
)
17686 dwarf_block
*blk
= attr
->as_block ();
17687 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17690 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17691 blk
->data
+ blk
->size
,
17693 if (ptr
- blk
->data
+ len
<= blk
->size
)
17695 mpz_import (value
->val
, len
,
17696 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17702 /* On failure set it to 1. */
17703 *value
= gdb_mpz (1);
17705 else if (attr
->form_is_block ())
17707 dwarf_block
*blk
= attr
->as_block ();
17708 mpz_import (value
->val
, blk
->size
,
17709 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17710 1, 0, 0, blk
->data
);
17713 *value
= gdb_mpz (attr
->constant_value (1));
17716 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17717 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17719 If the numerator and/or numerator attribute is missing,
17720 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17724 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17725 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17727 struct attribute
*num_attr
, *denom_attr
;
17729 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17730 if (num_attr
== nullptr)
17731 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17732 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17734 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17735 if (denom_attr
== nullptr)
17736 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17737 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17739 if (num_attr
== nullptr || denom_attr
== nullptr)
17742 get_mpz (cu
, numerator
, num_attr
);
17743 get_mpz (cu
, denominator
, denom_attr
);
17746 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17747 rational constant, rather than a signed one.
17749 If the rational constant has a negative value, a complaint
17750 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17753 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17754 struct dwarf2_cu
*cu
,
17755 gdb_mpz
*numerator
,
17756 gdb_mpz
*denominator
)
17761 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17762 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17764 mpz_neg (num
.val
, num
.val
);
17765 mpz_neg (denom
.val
, denom
.val
);
17767 else if (mpz_sgn (num
.val
) == -1)
17769 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17771 sect_offset_str (die
->sect_off
));
17774 else if (mpz_sgn (denom
.val
) == -1)
17776 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17778 sect_offset_str (die
->sect_off
));
17782 *numerator
= std::move (num
);
17783 *denominator
= std::move (denom
);
17786 /* Assuming that ENCODING is a string whose contents starting at the
17787 K'th character is "_nn" where "nn" is a decimal number, scan that
17788 number and set RESULT to the value. K is updated to point to the
17789 character immediately following the number.
17791 If the string does not conform to the format described above, false
17792 is returned, and K may or may not be changed. */
17795 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17797 /* The next character should be an underscore ('_') followed
17799 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17802 /* Skip the underscore. */
17806 /* Determine the number of digits for our number. */
17807 while (isdigit (encoding
[k
]))
17812 std::string
copy (&encoding
[start
], k
- start
);
17813 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17819 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17820 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17821 DENOM, update OFFSET, and return true on success. Return false on
17825 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17826 gdb_mpz
*num
, gdb_mpz
*denom
)
17828 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17830 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17833 /* Assuming DIE corresponds to a fixed point type, finish the creation
17834 of the corresponding TYPE by setting its type-specific data. CU is
17835 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17836 encodings. It is nullptr if the GNAT encoding should be
17840 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17841 struct die_info
*die
, struct dwarf2_cu
*cu
)
17843 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17844 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17846 /* If GNAT encodings are preferred, don't examine the
17848 struct attribute
*attr
= nullptr;
17849 if (suffix
== nullptr)
17851 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17852 if (attr
== nullptr)
17853 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17854 if (attr
== nullptr)
17855 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17858 /* Numerator and denominator of our fixed-point type's scaling factor.
17859 The default is a scaling factor of 1, which we use as a fallback
17860 when we are not able to decode it (problem with the debugging info,
17861 unsupported forms, bug in GDB, etc...). Using that as the default
17862 allows us to at least print the unscaled value, which might still
17863 be useful to a user. */
17864 gdb_mpz
scale_num (1);
17865 gdb_mpz
scale_denom (1);
17867 if (attr
== nullptr)
17870 if (suffix
!= nullptr
17871 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17873 /* The number might be encoded as _nn_dd_nn_dd, where the
17874 second ratio is the 'small value. In this situation, we
17875 want the second value. */
17876 && (suffix
[offset
] != '_'
17877 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17884 /* Scaling factor not found. Assume a scaling factor of 1,
17885 and hope for the best. At least the user will be able to
17886 see the encoded value. */
17889 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17890 sect_offset_str (die
->sect_off
));
17893 else if (attr
->name
== DW_AT_binary_scale
)
17895 LONGEST scale_exp
= attr
->constant_value (0);
17896 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17898 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17900 else if (attr
->name
== DW_AT_decimal_scale
)
17902 LONGEST scale_exp
= attr
->constant_value (0);
17903 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17905 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17907 else if (attr
->name
== DW_AT_small
)
17909 struct die_info
*scale_die
;
17910 struct dwarf2_cu
*scale_cu
= cu
;
17912 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17913 if (scale_die
->tag
== DW_TAG_constant
)
17914 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17915 &scale_num
, &scale_denom
);
17917 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17919 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17923 complaint (_("unsupported scale attribute %s for fixed-point type"
17925 dwarf_attr_name (attr
->name
),
17926 sect_offset_str (die
->sect_off
));
17929 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17930 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17931 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17932 mpq_canonicalize (scaling_factor
.val
);
17935 /* The gnat-encoding suffix for fixed point. */
17937 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17939 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17940 "XF" suffix of the name. The text after this is what encodes the
17941 'small and 'delta information. Otherwise, return nullptr. */
17943 static const char *
17944 gnat_encoded_fixed_point_type_info (const char *name
)
17946 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17949 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17950 (which may be different from NAME) to the architecture back-end to allow
17951 it to guess the correct format if necessary. */
17953 static struct type
*
17954 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17955 const char *name_hint
, enum bfd_endian byte_order
)
17957 struct gdbarch
*gdbarch
= objfile
->arch ();
17958 const struct floatformat
**format
;
17961 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17963 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17965 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17970 /* Allocate an integer type of size BITS and name NAME. */
17972 static struct type
*
17973 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17974 int bits
, int unsigned_p
, const char *name
)
17978 /* Versions of Intel's C Compiler generate an integer type called "void"
17979 instead of using DW_TAG_unspecified_type. This has been seen on
17980 at least versions 14, 17, and 18. */
17981 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17982 && strcmp (name
, "void") == 0)
17983 type
= objfile_type (objfile
)->builtin_void
;
17985 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17990 /* Return true if DIE has a DW_AT_small attribute whose value is
17991 a constant rational, where both the numerator and denominator
17994 CU is the DIE's Compilation Unit. */
17997 has_zero_over_zero_small_attribute (struct die_info
*die
,
17998 struct dwarf2_cu
*cu
)
18000 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18001 if (attr
== nullptr)
18004 struct dwarf2_cu
*scale_cu
= cu
;
18005 struct die_info
*scale_die
18006 = follow_die_ref (die
, attr
, &scale_cu
);
18008 if (scale_die
->tag
!= DW_TAG_constant
)
18011 gdb_mpz
num (1), denom (1);
18012 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18013 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18016 /* Initialise and return a floating point type of size BITS suitable for
18017 use as a component of a complex number. The NAME_HINT is passed through
18018 when initialising the floating point type and is the name of the complex
18021 As DWARF doesn't currently provide an explicit name for the components
18022 of a complex number, but it can be helpful to have these components
18023 named, we try to select a suitable name based on the size of the
18025 static struct type
*
18026 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18027 struct objfile
*objfile
,
18028 int bits
, const char *name_hint
,
18029 enum bfd_endian byte_order
)
18031 gdbarch
*gdbarch
= objfile
->arch ();
18032 struct type
*tt
= nullptr;
18034 /* Try to find a suitable floating point builtin type of size BITS.
18035 We're going to use the name of this type as the name for the complex
18036 target type that we are about to create. */
18037 switch (cu
->per_cu
->lang
)
18039 case language_fortran
:
18043 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18046 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18048 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18050 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18058 tt
= builtin_type (gdbarch
)->builtin_float
;
18061 tt
= builtin_type (gdbarch
)->builtin_double
;
18063 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18065 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18071 /* If the type we found doesn't match the size we were looking for, then
18072 pretend we didn't find a type at all, the complex target type we
18073 create will then be nameless. */
18074 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18077 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18078 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18081 /* Find a representation of a given base type and install
18082 it in the TYPE field of the die. */
18084 static struct type
*
18085 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18087 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18089 struct attribute
*attr
;
18090 int encoding
= 0, bits
= 0;
18094 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18095 if (attr
!= nullptr && attr
->form_is_constant ())
18096 encoding
= attr
->constant_value (0);
18097 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18098 if (attr
!= nullptr)
18099 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18100 name
= dwarf2_name (die
, cu
);
18102 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18104 arch
= objfile
->arch ();
18105 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18107 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18108 if (attr
!= nullptr && attr
->form_is_constant ())
18110 int endianity
= attr
->constant_value (0);
18115 byte_order
= BFD_ENDIAN_BIG
;
18117 case DW_END_little
:
18118 byte_order
= BFD_ENDIAN_LITTLE
;
18121 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18126 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18127 && cu
->per_cu
->lang
== language_ada
18128 && has_zero_over_zero_small_attribute (die
, cu
))
18130 /* brobecker/2018-02-24: This is a fixed point type for which
18131 the scaling factor is represented as fraction whose value
18132 does not make sense (zero divided by zero), so we should
18133 normally never see these. However, there is a small category
18134 of fixed point types for which GNAT is unable to provide
18135 the scaling factor via the standard DWARF mechanisms, and
18136 for which the info is provided via the GNAT encodings instead.
18137 This is likely what this DIE is about. */
18138 encoding
= (encoding
== DW_ATE_signed_fixed
18140 : DW_ATE_unsigned
);
18143 /* With GNAT encodings, fixed-point information will be encoded in
18144 the type name. Note that this can also occur with the above
18145 zero-over-zero case, which is why this is a separate "if" rather
18146 than an "else if". */
18147 const char *gnat_encoding_suffix
= nullptr;
18148 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18149 && cu
->per_cu
->lang
== language_ada
18150 && name
!= nullptr)
18152 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18153 if (gnat_encoding_suffix
!= nullptr)
18155 gdb_assert (startswith (gnat_encoding_suffix
,
18156 GNAT_FIXED_POINT_SUFFIX
));
18157 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18158 name
, gnat_encoding_suffix
- name
);
18159 /* Use -1 here so that SUFFIX points at the "_" after the
18161 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18163 encoding
= (encoding
== DW_ATE_signed
18164 ? DW_ATE_signed_fixed
18165 : DW_ATE_unsigned_fixed
);
18171 case DW_ATE_address
:
18172 /* Turn DW_ATE_address into a void * pointer. */
18173 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18174 type
= init_pointer_type (objfile
, bits
, name
, type
);
18176 case DW_ATE_boolean
:
18177 type
= init_boolean_type (objfile
, bits
, 1, name
);
18179 case DW_ATE_complex_float
:
18180 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18182 if (type
->code () == TYPE_CODE_ERROR
)
18184 if (name
== nullptr)
18186 struct obstack
*obstack
18187 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18188 name
= obconcat (obstack
, "_Complex ", type
->name (),
18191 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18194 type
= init_complex_type (name
, type
);
18196 case DW_ATE_decimal_float
:
18197 type
= init_decfloat_type (objfile
, bits
, name
);
18200 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18202 case DW_ATE_signed
:
18203 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18205 case DW_ATE_unsigned
:
18206 if (cu
->per_cu
->lang
== language_fortran
18208 && startswith (name
, "character("))
18209 type
= init_character_type (objfile
, bits
, 1, name
);
18211 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18213 case DW_ATE_signed_char
:
18214 if (cu
->per_cu
->lang
== language_ada
18215 || cu
->per_cu
->lang
== language_m2
18216 || cu
->per_cu
->lang
== language_pascal
18217 || cu
->per_cu
->lang
== language_fortran
)
18218 type
= init_character_type (objfile
, bits
, 0, name
);
18220 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18222 case DW_ATE_unsigned_char
:
18223 if (cu
->per_cu
->lang
== language_ada
18224 || cu
->per_cu
->lang
== language_m2
18225 || cu
->per_cu
->lang
== language_pascal
18226 || cu
->per_cu
->lang
== language_fortran
18227 || cu
->per_cu
->lang
== language_rust
)
18228 type
= init_character_type (objfile
, bits
, 1, name
);
18230 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18234 type
= init_character_type (objfile
, bits
, 1, name
);
18235 return set_die_type (die
, type
, cu
);
18238 case DW_ATE_signed_fixed
:
18239 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18240 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18242 case DW_ATE_unsigned_fixed
:
18243 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18244 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18248 complaint (_("unsupported DW_AT_encoding: '%s'"),
18249 dwarf_type_encoding_name (encoding
));
18250 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18254 if (type
->code () == TYPE_CODE_INT
18256 && strcmp (name
, "char") == 0)
18257 type
->set_has_no_signedness (true);
18259 maybe_set_alignment (cu
, die
, type
);
18261 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18263 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18265 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18266 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18268 unsigned real_bit_size
= attr
->as_unsigned ();
18269 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18270 /* Only use the attributes if they make sense together. */
18271 if (attr
== nullptr
18272 || (attr
->as_unsigned () + real_bit_size
18273 <= 8 * TYPE_LENGTH (type
)))
18275 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18277 if (attr
!= nullptr)
18278 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18279 = attr
->as_unsigned ();
18284 return set_die_type (die
, type
, cu
);
18287 /* A helper function that returns the name of DIE, if it refers to a
18288 variable declaration. */
18290 static const char *
18291 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18293 if (die
->tag
!= DW_TAG_variable
)
18296 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18297 if (attr
== nullptr || !attr
->as_boolean ())
18300 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18301 if (attr
== nullptr)
18303 return attr
->as_string ();
18306 /* Parse dwarf attribute if it's a block, reference or constant and put the
18307 resulting value of the attribute into struct bound_prop.
18308 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18311 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18312 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18313 struct type
*default_type
)
18315 struct dwarf2_property_baton
*baton
;
18316 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18317 struct objfile
*objfile
= per_objfile
->objfile
;
18318 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18320 gdb_assert (default_type
!= NULL
);
18322 if (attr
== NULL
|| prop
== NULL
)
18325 if (attr
->form_is_block ())
18327 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18328 baton
->property_type
= default_type
;
18329 baton
->locexpr
.per_cu
= cu
->per_cu
;
18330 baton
->locexpr
.per_objfile
= per_objfile
;
18332 struct dwarf_block
*block
;
18333 if (attr
->form
== DW_FORM_data16
)
18335 size_t data_size
= 16;
18336 block
= XOBNEW (obstack
, struct dwarf_block
);
18337 block
->size
= (data_size
18338 + 2 /* Extra bytes for DW_OP and arg. */);
18339 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18340 data
[0] = DW_OP_implicit_value
;
18341 data
[1] = data_size
;
18342 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18343 block
->data
= data
;
18346 block
= attr
->as_block ();
18348 baton
->locexpr
.size
= block
->size
;
18349 baton
->locexpr
.data
= block
->data
;
18350 switch (attr
->name
)
18352 case DW_AT_string_length
:
18353 baton
->locexpr
.is_reference
= true;
18356 baton
->locexpr
.is_reference
= false;
18360 prop
->set_locexpr (baton
);
18361 gdb_assert (prop
->baton () != NULL
);
18363 else if (attr
->form_is_ref ())
18365 struct dwarf2_cu
*target_cu
= cu
;
18366 struct die_info
*target_die
;
18367 struct attribute
*target_attr
;
18369 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18370 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18371 if (target_attr
== NULL
)
18372 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18374 if (target_attr
== nullptr)
18375 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
18377 if (target_attr
== NULL
)
18379 const char *name
= var_decl_name (target_die
, target_cu
);
18380 if (name
!= nullptr)
18382 prop
->set_variable_name (name
);
18388 switch (target_attr
->name
)
18390 case DW_AT_location
:
18391 if (target_attr
->form_is_section_offset ())
18393 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18394 baton
->property_type
= die_type (target_die
, target_cu
);
18395 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18396 prop
->set_loclist (baton
);
18397 gdb_assert (prop
->baton () != NULL
);
18399 else if (target_attr
->form_is_block ())
18401 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18402 baton
->property_type
= die_type (target_die
, target_cu
);
18403 baton
->locexpr
.per_cu
= cu
->per_cu
;
18404 baton
->locexpr
.per_objfile
= per_objfile
;
18405 struct dwarf_block
*block
= target_attr
->as_block ();
18406 baton
->locexpr
.size
= block
->size
;
18407 baton
->locexpr
.data
= block
->data
;
18408 baton
->locexpr
.is_reference
= true;
18409 prop
->set_locexpr (baton
);
18410 gdb_assert (prop
->baton () != NULL
);
18414 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18415 "dynamic property");
18419 case DW_AT_data_member_location
:
18420 case DW_AT_data_bit_offset
:
18424 if (!handle_member_location (target_die
, target_cu
, &offset
))
18427 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18428 baton
->property_type
= read_type_die (target_die
->parent
,
18430 baton
->offset_info
.offset
= offset
;
18431 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18432 prop
->set_addr_offset (baton
);
18437 else if (attr
->form_is_constant ())
18438 prop
->set_const_val (attr
->constant_value (0));
18439 else if (attr
->form_is_section_offset ())
18441 switch (attr
->name
)
18443 case DW_AT_string_length
:
18444 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18445 baton
->property_type
= default_type
;
18446 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
18447 prop
->set_loclist (baton
);
18448 gdb_assert (prop
->baton () != NULL
);
18460 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18461 dwarf2_name (die
, cu
));
18467 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18468 present (which is valid) then compute the default type based on the
18469 compilation units address size. */
18471 static struct type
*
18472 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18474 struct type
*index_type
= die_type (die
, cu
);
18476 /* Dwarf-2 specifications explicitly allows to create subrange types
18477 without specifying a base type.
18478 In that case, the base type must be set to the type of
18479 the lower bound, upper bound or count, in that order, if any of these
18480 three attributes references an object that has a type.
18481 If no base type is found, the Dwarf-2 specifications say that
18482 a signed integer type of size equal to the size of an address should
18484 For the following C code: `extern char gdb_int [];'
18485 GCC produces an empty range DIE.
18486 FIXME: muller/2010-05-28: Possible references to object for low bound,
18487 high bound or count are not yet handled by this code. */
18488 if (index_type
->code () == TYPE_CODE_VOID
)
18489 index_type
= cu
->addr_sized_int_type (false);
18494 /* Read the given DW_AT_subrange DIE. */
18496 static struct type
*
18497 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18499 struct type
*base_type
, *orig_base_type
;
18500 struct type
*range_type
;
18501 struct attribute
*attr
;
18502 struct dynamic_prop low
, high
;
18503 int low_default_is_valid
;
18504 int high_bound_is_count
= 0;
18506 ULONGEST negative_mask
;
18508 orig_base_type
= read_subrange_index_type (die
, cu
);
18510 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18511 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18512 creating the range type, but we use the result of check_typedef
18513 when examining properties of the type. */
18514 base_type
= check_typedef (orig_base_type
);
18516 /* The die_type call above may have already set the type for this DIE. */
18517 range_type
= get_die_type (die
, cu
);
18521 high
.set_const_val (0);
18523 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18524 omitting DW_AT_lower_bound. */
18525 switch (cu
->per_cu
->lang
)
18528 case language_cplus
:
18529 low
.set_const_val (0);
18530 low_default_is_valid
= 1;
18532 case language_fortran
:
18533 low
.set_const_val (1);
18534 low_default_is_valid
= 1;
18537 case language_objc
:
18538 case language_rust
:
18539 low
.set_const_val (0);
18540 low_default_is_valid
= (cu
->header
.version
>= 4);
18544 case language_pascal
:
18545 low
.set_const_val (1);
18546 low_default_is_valid
= (cu
->header
.version
>= 4);
18549 low
.set_const_val (0);
18550 low_default_is_valid
= 0;
18554 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18555 if (attr
!= nullptr)
18556 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18557 else if (!low_default_is_valid
)
18558 complaint (_("Missing DW_AT_lower_bound "
18559 "- DIE at %s [in module %s]"),
18560 sect_offset_str (die
->sect_off
),
18561 objfile_name (cu
->per_objfile
->objfile
));
18563 struct attribute
*attr_ub
, *attr_count
;
18564 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18565 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18567 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18568 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18570 /* If bounds are constant do the final calculation here. */
18571 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18572 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18574 high_bound_is_count
= 1;
18578 if (attr_ub
!= NULL
)
18579 complaint (_("Unresolved DW_AT_upper_bound "
18580 "- DIE at %s [in module %s]"),
18581 sect_offset_str (die
->sect_off
),
18582 objfile_name (cu
->per_objfile
->objfile
));
18583 if (attr_count
!= NULL
)
18584 complaint (_("Unresolved DW_AT_count "
18585 "- DIE at %s [in module %s]"),
18586 sect_offset_str (die
->sect_off
),
18587 objfile_name (cu
->per_objfile
->objfile
));
18592 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18593 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18594 bias
= bias_attr
->constant_value (0);
18596 /* Normally, the DWARF producers are expected to use a signed
18597 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18598 But this is unfortunately not always the case, as witnessed
18599 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18600 is used instead. To work around that ambiguity, we treat
18601 the bounds as signed, and thus sign-extend their values, when
18602 the base type is signed. */
18604 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18605 if (low
.kind () == PROP_CONST
18606 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18607 low
.set_const_val (low
.const_val () | negative_mask
);
18608 if (high
.kind () == PROP_CONST
18609 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18610 high
.set_const_val (high
.const_val () | negative_mask
);
18612 /* Check for bit and byte strides. */
18613 struct dynamic_prop byte_stride_prop
;
18614 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18615 if (attr_byte_stride
!= nullptr)
18617 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18618 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18622 struct dynamic_prop bit_stride_prop
;
18623 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18624 if (attr_bit_stride
!= nullptr)
18626 /* It only makes sense to have either a bit or byte stride. */
18627 if (attr_byte_stride
!= nullptr)
18629 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18630 "- DIE at %s [in module %s]"),
18631 sect_offset_str (die
->sect_off
),
18632 objfile_name (cu
->per_objfile
->objfile
));
18633 attr_bit_stride
= nullptr;
18637 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18638 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18643 if (attr_byte_stride
!= nullptr
18644 || attr_bit_stride
!= nullptr)
18646 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18647 struct dynamic_prop
*stride
18648 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18651 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18652 &high
, bias
, stride
, byte_stride_p
);
18655 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18657 if (high_bound_is_count
)
18658 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18660 /* Ada expects an empty array on no boundary attributes. */
18661 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18662 range_type
->bounds ()->high
.set_undefined ();
18664 name
= dwarf2_name (die
, cu
);
18666 range_type
->set_name (name
);
18668 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18669 if (attr
!= nullptr)
18670 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18672 maybe_set_alignment (cu
, die
, range_type
);
18674 set_die_type (die
, range_type
, cu
);
18676 /* set_die_type should be already done. */
18677 set_descriptive_type (range_type
, die
, cu
);
18682 static struct type
*
18683 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18687 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18688 type
->set_name (dwarf2_name (die
, cu
));
18690 /* In Ada, an unspecified type is typically used when the description
18691 of the type is deferred to a different unit. When encountering
18692 such a type, we treat it as a stub, and try to resolve it later on,
18694 if (cu
->per_cu
->lang
== language_ada
)
18695 type
->set_is_stub (true);
18697 return set_die_type (die
, type
, cu
);
18700 /* Read a single die and all its descendents. Set the die's sibling
18701 field to NULL; set other fields in the die correctly, and set all
18702 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18703 location of the info_ptr after reading all of those dies. PARENT
18704 is the parent of the die in question. */
18706 static struct die_info
*
18707 read_die_and_children (const struct die_reader_specs
*reader
,
18708 const gdb_byte
*info_ptr
,
18709 const gdb_byte
**new_info_ptr
,
18710 struct die_info
*parent
)
18712 struct die_info
*die
;
18713 const gdb_byte
*cur_ptr
;
18715 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18718 *new_info_ptr
= cur_ptr
;
18721 store_in_ref_table (die
, reader
->cu
);
18723 if (die
->has_children
)
18724 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18728 *new_info_ptr
= cur_ptr
;
18731 die
->sibling
= NULL
;
18732 die
->parent
= parent
;
18736 /* Read a die, all of its descendents, and all of its siblings; set
18737 all of the fields of all of the dies correctly. Arguments are as
18738 in read_die_and_children. */
18740 static struct die_info
*
18741 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18742 const gdb_byte
*info_ptr
,
18743 const gdb_byte
**new_info_ptr
,
18744 struct die_info
*parent
)
18746 struct die_info
*first_die
, *last_sibling
;
18747 const gdb_byte
*cur_ptr
;
18749 cur_ptr
= info_ptr
;
18750 first_die
= last_sibling
= NULL
;
18754 struct die_info
*die
18755 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18759 *new_info_ptr
= cur_ptr
;
18766 last_sibling
->sibling
= die
;
18768 last_sibling
= die
;
18772 /* Read a die, all of its descendents, and all of its siblings; set
18773 all of the fields of all of the dies correctly. Arguments are as
18774 in read_die_and_children.
18775 This the main entry point for reading a DIE and all its children. */
18777 static struct die_info
*
18778 read_die_and_siblings (const struct die_reader_specs
*reader
,
18779 const gdb_byte
*info_ptr
,
18780 const gdb_byte
**new_info_ptr
,
18781 struct die_info
*parent
)
18783 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18784 new_info_ptr
, parent
);
18786 if (dwarf_die_debug
)
18788 fprintf_unfiltered (gdb_stdlog
,
18789 "Read die from %s@0x%x of %s:\n",
18790 reader
->die_section
->get_name (),
18791 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18792 bfd_get_filename (reader
->abfd
));
18793 dump_die (die
, dwarf_die_debug
);
18799 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18801 The caller is responsible for filling in the extra attributes
18802 and updating (*DIEP)->num_attrs.
18803 Set DIEP to point to a newly allocated die with its information,
18804 except for its child, sibling, and parent fields. */
18806 static const gdb_byte
*
18807 read_full_die_1 (const struct die_reader_specs
*reader
,
18808 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18809 int num_extra_attrs
)
18811 unsigned int abbrev_number
, bytes_read
, i
;
18812 const struct abbrev_info
*abbrev
;
18813 struct die_info
*die
;
18814 struct dwarf2_cu
*cu
= reader
->cu
;
18815 bfd
*abfd
= reader
->abfd
;
18817 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18818 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18819 info_ptr
+= bytes_read
;
18820 if (!abbrev_number
)
18826 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18828 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18830 bfd_get_filename (abfd
));
18832 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18833 die
->sect_off
= sect_off
;
18834 die
->tag
= abbrev
->tag
;
18835 die
->abbrev
= abbrev_number
;
18836 die
->has_children
= abbrev
->has_children
;
18838 /* Make the result usable.
18839 The caller needs to update num_attrs after adding the extra
18841 die
->num_attrs
= abbrev
->num_attrs
;
18843 bool any_need_reprocess
= false;
18844 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18846 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18848 if (die
->attrs
[i
].requires_reprocessing_p ())
18849 any_need_reprocess
= true;
18852 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18853 if (attr
!= nullptr && attr
->form_is_unsigned ())
18854 cu
->str_offsets_base
= attr
->as_unsigned ();
18856 attr
= die
->attr (DW_AT_loclists_base
);
18857 if (attr
!= nullptr)
18858 cu
->loclist_base
= attr
->as_unsigned ();
18860 auto maybe_addr_base
= die
->addr_base ();
18861 if (maybe_addr_base
.has_value ())
18862 cu
->addr_base
= *maybe_addr_base
;
18864 attr
= die
->attr (DW_AT_rnglists_base
);
18865 if (attr
!= nullptr)
18866 cu
->rnglists_base
= attr
->as_unsigned ();
18868 if (any_need_reprocess
)
18870 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18872 if (die
->attrs
[i
].requires_reprocessing_p ())
18873 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18880 /* Read a die and all its attributes.
18881 Set DIEP to point to a newly allocated die with its information,
18882 except for its child, sibling, and parent fields. */
18884 static const gdb_byte
*
18885 read_full_die (const struct die_reader_specs
*reader
,
18886 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18888 const gdb_byte
*result
;
18890 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18892 if (dwarf_die_debug
)
18894 fprintf_unfiltered (gdb_stdlog
,
18895 "Read die from %s@0x%x of %s:\n",
18896 reader
->die_section
->get_name (),
18897 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18898 bfd_get_filename (reader
->abfd
));
18899 dump_die (*diep
, dwarf_die_debug
);
18906 /* Returns nonzero if TAG represents a type that we might generate a partial
18910 is_type_tag_for_partial (int tag
, enum language lang
)
18915 /* Some types that would be reasonable to generate partial symbols for,
18916 that we don't at present. Note that normally this does not
18917 matter, mainly because C compilers don't give names to these
18918 types, but instead emit DW_TAG_typedef. */
18919 case DW_TAG_file_type
:
18920 case DW_TAG_ptr_to_member_type
:
18921 case DW_TAG_set_type
:
18922 case DW_TAG_string_type
:
18923 case DW_TAG_subroutine_type
:
18926 /* GNAT may emit an array with a name, but no typedef, so we
18927 need to make a symbol in this case. */
18928 case DW_TAG_array_type
:
18929 return lang
== language_ada
;
18931 case DW_TAG_base_type
:
18932 case DW_TAG_class_type
:
18933 case DW_TAG_interface_type
:
18934 case DW_TAG_enumeration_type
:
18935 case DW_TAG_structure_type
:
18936 case DW_TAG_subrange_type
:
18937 case DW_TAG_typedef
:
18938 case DW_TAG_union_type
:
18945 /* Load all DIEs that are interesting for partial symbols into memory. */
18947 static struct partial_die_info
*
18948 load_partial_dies (const struct die_reader_specs
*reader
,
18949 const gdb_byte
*info_ptr
, int building_psymtab
)
18951 struct dwarf2_cu
*cu
= reader
->cu
;
18952 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18953 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18954 unsigned int bytes_read
;
18955 unsigned int load_all
= 0;
18956 int nesting_level
= 1;
18961 gdb_assert (cu
->per_cu
!= NULL
);
18962 if (cu
->load_all_dies
)
18966 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18970 &cu
->comp_unit_obstack
,
18971 hashtab_obstack_allocate
,
18972 dummy_obstack_deallocate
);
18976 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18979 /* A NULL abbrev means the end of a series of children. */
18980 if (abbrev
== NULL
)
18982 if (--nesting_level
== 0)
18985 info_ptr
+= bytes_read
;
18986 last_die
= parent_die
;
18987 parent_die
= parent_die
->die_parent
;
18991 /* Check for template arguments. We never save these; if
18992 they're seen, we just mark the parent, and go on our way. */
18993 if (parent_die
!= NULL
18994 && cu
->per_cu
->lang
== language_cplus
18995 && (abbrev
->tag
== DW_TAG_template_type_param
18996 || abbrev
->tag
== DW_TAG_template_value_param
))
18998 parent_die
->has_template_arguments
= 1;
19002 /* We don't need a partial DIE for the template argument. */
19003 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19008 /* We only recurse into c++ subprograms looking for template arguments.
19009 Skip their other children. */
19011 && cu
->per_cu
->lang
== language_cplus
19012 && parent_die
!= NULL
19013 && parent_die
->tag
== DW_TAG_subprogram
19014 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19016 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19020 /* Check whether this DIE is interesting enough to save. Normally
19021 we would not be interested in members here, but there may be
19022 later variables referencing them via DW_AT_specification (for
19023 static members). */
19025 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
19026 && abbrev
->tag
!= DW_TAG_constant
19027 && abbrev
->tag
!= DW_TAG_enumerator
19028 && abbrev
->tag
!= DW_TAG_subprogram
19029 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19030 && abbrev
->tag
!= DW_TAG_lexical_block
19031 && abbrev
->tag
!= DW_TAG_variable
19032 && abbrev
->tag
!= DW_TAG_namespace
19033 && abbrev
->tag
!= DW_TAG_module
19034 && abbrev
->tag
!= DW_TAG_member
19035 && abbrev
->tag
!= DW_TAG_imported_unit
19036 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19038 /* Otherwise we skip to the next sibling, if any. */
19039 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19043 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19046 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19048 /* This two-pass algorithm for processing partial symbols has a
19049 high cost in cache pressure. Thus, handle some simple cases
19050 here which cover the majority of C partial symbols. DIEs
19051 which neither have specification tags in them, nor could have
19052 specification tags elsewhere pointing at them, can simply be
19053 processed and discarded.
19055 This segment is also optional; scan_partial_symbols and
19056 add_partial_symbol will handle these DIEs if we chain
19057 them in normally. When compilers which do not emit large
19058 quantities of duplicate debug information are more common,
19059 this code can probably be removed. */
19061 /* Any complete simple types at the top level (pretty much all
19062 of them, for a language without namespaces), can be processed
19064 if (parent_die
== NULL
19065 && pdi
.has_specification
== 0
19066 && pdi
.is_declaration
== 0
19067 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19068 || pdi
.tag
== DW_TAG_base_type
19069 || pdi
.tag
== DW_TAG_array_type
19070 || pdi
.tag
== DW_TAG_subrange_type
))
19072 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19073 add_partial_symbol (&pdi
, cu
);
19075 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19079 /* The exception for DW_TAG_typedef with has_children above is
19080 a workaround of GCC PR debug/47510. In the case of this complaint
19081 type_name_or_error will error on such types later.
19083 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19084 it could not find the child DIEs referenced later, this is checked
19085 above. In correct DWARF DW_TAG_typedef should have no children. */
19087 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19088 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19089 "- DIE at %s [in module %s]"),
19090 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19092 /* If we're at the second level, and we're an enumerator, and
19093 our parent has no specification (meaning possibly lives in a
19094 namespace elsewhere), then we can add the partial symbol now
19095 instead of queueing it. */
19096 if (pdi
.tag
== DW_TAG_enumerator
19097 && parent_die
!= NULL
19098 && parent_die
->die_parent
== NULL
19099 && parent_die
->tag
== DW_TAG_enumeration_type
19100 && parent_die
->has_specification
== 0)
19102 if (pdi
.raw_name
== NULL
)
19103 complaint (_("malformed enumerator DIE ignored"));
19104 else if (building_psymtab
)
19105 add_partial_symbol (&pdi
, cu
);
19107 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19111 struct partial_die_info
*part_die
19112 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19114 /* We'll save this DIE so link it in. */
19115 part_die
->die_parent
= parent_die
;
19116 part_die
->die_sibling
= NULL
;
19117 part_die
->die_child
= NULL
;
19119 if (last_die
&& last_die
== parent_die
)
19120 last_die
->die_child
= part_die
;
19122 last_die
->die_sibling
= part_die
;
19124 last_die
= part_die
;
19126 if (first_die
== NULL
)
19127 first_die
= part_die
;
19129 /* Maybe add the DIE to the hash table. Not all DIEs that we
19130 find interesting need to be in the hash table, because we
19131 also have the parent/sibling/child chains; only those that we
19132 might refer to by offset later during partial symbol reading.
19134 For now this means things that might have be the target of a
19135 DW_AT_specification, DW_AT_abstract_origin, or
19136 DW_AT_extension. DW_AT_extension will refer only to
19137 namespaces; DW_AT_abstract_origin refers to functions (and
19138 many things under the function DIE, but we do not recurse
19139 into function DIEs during partial symbol reading) and
19140 possibly variables as well; DW_AT_specification refers to
19141 declarations. Declarations ought to have the DW_AT_declaration
19142 flag. It happens that GCC forgets to put it in sometimes, but
19143 only for functions, not for types.
19145 Adding more things than necessary to the hash table is harmless
19146 except for the performance cost. Adding too few will result in
19147 wasted time in find_partial_die, when we reread the compilation
19148 unit with load_all_dies set. */
19151 || abbrev
->tag
== DW_TAG_constant
19152 || abbrev
->tag
== DW_TAG_subprogram
19153 || abbrev
->tag
== DW_TAG_variable
19154 || abbrev
->tag
== DW_TAG_namespace
19155 || part_die
->is_declaration
)
19159 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19160 to_underlying (part_die
->sect_off
),
19165 /* For some DIEs we want to follow their children (if any). For C
19166 we have no reason to follow the children of structures; for other
19167 languages we have to, so that we can get at method physnames
19168 to infer fully qualified class names, for DW_AT_specification,
19169 and for C++ template arguments. For C++, we also look one level
19170 inside functions to find template arguments (if the name of the
19171 function does not already contain the template arguments).
19173 For Ada and Fortran, we need to scan the children of subprograms
19174 and lexical blocks as well because these languages allow the
19175 definition of nested entities that could be interesting for the
19176 debugger, such as nested subprograms for instance. */
19177 if (last_die
->has_children
19179 || last_die
->tag
== DW_TAG_namespace
19180 || last_die
->tag
== DW_TAG_module
19181 || last_die
->tag
== DW_TAG_enumeration_type
19182 || (cu
->per_cu
->lang
== language_cplus
19183 && last_die
->tag
== DW_TAG_subprogram
19184 && (last_die
->raw_name
== NULL
19185 || strchr (last_die
->raw_name
, '<') == NULL
))
19186 || (cu
->per_cu
->lang
!= language_c
19187 && (last_die
->tag
== DW_TAG_class_type
19188 || last_die
->tag
== DW_TAG_interface_type
19189 || last_die
->tag
== DW_TAG_structure_type
19190 || last_die
->tag
== DW_TAG_union_type
))
19191 || ((cu
->per_cu
->lang
== language_ada
19192 || cu
->per_cu
->lang
== language_fortran
)
19193 && (last_die
->tag
== DW_TAG_subprogram
19194 || last_die
->tag
== DW_TAG_lexical_block
))))
19197 parent_die
= last_die
;
19201 /* Otherwise we skip to the next sibling, if any. */
19202 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19204 /* Back to the top, do it again. */
19208 partial_die_info::partial_die_info (sect_offset sect_off_
,
19209 const struct abbrev_info
*abbrev
)
19210 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19214 /* See class definition. */
19217 partial_die_info::name (dwarf2_cu
*cu
)
19219 if (!canonical_name
&& raw_name
!= nullptr)
19221 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19222 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19223 canonical_name
= 1;
19229 /* Read a minimal amount of information into the minimal die structure.
19230 INFO_PTR should point just after the initial uleb128 of a DIE. */
19233 partial_die_info::read (const struct die_reader_specs
*reader
,
19234 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19236 struct dwarf2_cu
*cu
= reader
->cu
;
19237 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19239 int has_low_pc_attr
= 0;
19240 int has_high_pc_attr
= 0;
19241 int high_pc_relative
= 0;
19243 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19246 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19247 /* String and address offsets that need to do the reprocessing have
19248 already been read at this point, so there is no need to wait until
19249 the loop terminates to do the reprocessing. */
19250 if (attr
.requires_reprocessing_p ())
19251 read_attribute_reprocess (reader
, &attr
, tag
);
19252 /* Store the data if it is of an attribute we want to keep in a
19253 partial symbol table. */
19259 case DW_TAG_compile_unit
:
19260 case DW_TAG_partial_unit
:
19261 case DW_TAG_type_unit
:
19262 /* Compilation units have a DW_AT_name that is a filename, not
19263 a source language identifier. */
19264 case DW_TAG_enumeration_type
:
19265 case DW_TAG_enumerator
:
19266 /* These tags always have simple identifiers already; no need
19267 to canonicalize them. */
19268 canonical_name
= 1;
19269 raw_name
= attr
.as_string ();
19272 canonical_name
= 0;
19273 raw_name
= attr
.as_string ();
19277 case DW_AT_linkage_name
:
19278 case DW_AT_MIPS_linkage_name
:
19279 /* Note that both forms of linkage name might appear. We
19280 assume they will be the same, and we only store the last
19282 linkage_name
= attr
.as_string ();
19285 has_low_pc_attr
= 1;
19286 lowpc
= attr
.as_address ();
19288 case DW_AT_high_pc
:
19289 has_high_pc_attr
= 1;
19290 highpc
= attr
.as_address ();
19291 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19292 high_pc_relative
= 1;
19294 case DW_AT_location
:
19295 /* Support the .debug_loc offsets. */
19296 if (attr
.form_is_block ())
19298 d
.locdesc
= attr
.as_block ();
19300 else if (attr
.form_is_section_offset ())
19302 dwarf2_complex_location_expr_complaint ();
19306 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19307 "partial symbol information");
19310 case DW_AT_external
:
19311 is_external
= attr
.as_boolean ();
19313 case DW_AT_declaration
:
19314 is_declaration
= attr
.as_boolean ();
19319 case DW_AT_abstract_origin
:
19320 case DW_AT_specification
:
19321 case DW_AT_extension
:
19322 has_specification
= 1;
19323 spec_offset
= attr
.get_ref_die_offset ();
19324 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19325 || cu
->per_cu
->is_dwz
);
19327 case DW_AT_sibling
:
19328 /* Ignore absolute siblings, they might point outside of
19329 the current compile unit. */
19330 if (attr
.form
== DW_FORM_ref_addr
)
19331 complaint (_("ignoring absolute DW_AT_sibling"));
19334 const gdb_byte
*buffer
= reader
->buffer
;
19335 sect_offset off
= attr
.get_ref_die_offset ();
19336 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19338 if (sibling_ptr
< info_ptr
)
19339 complaint (_("DW_AT_sibling points backwards"));
19340 else if (sibling_ptr
> reader
->buffer_end
)
19341 reader
->die_section
->overflow_complaint ();
19343 sibling
= sibling_ptr
;
19346 case DW_AT_byte_size
:
19349 case DW_AT_const_value
:
19350 has_const_value
= 1;
19352 case DW_AT_calling_convention
:
19353 /* DWARF doesn't provide a way to identify a program's source-level
19354 entry point. DW_AT_calling_convention attributes are only meant
19355 to describe functions' calling conventions.
19357 However, because it's a necessary piece of information in
19358 Fortran, and before DWARF 4 DW_CC_program was the only
19359 piece of debugging information whose definition refers to
19360 a 'main program' at all, several compilers marked Fortran
19361 main programs with DW_CC_program --- even when those
19362 functions use the standard calling conventions.
19364 Although DWARF now specifies a way to provide this
19365 information, we support this practice for backward
19367 if (attr
.constant_value (0) == DW_CC_program
19368 && cu
->per_cu
->lang
== language_fortran
)
19369 main_subprogram
= 1;
19373 LONGEST value
= attr
.constant_value (-1);
19374 if (value
== DW_INL_inlined
19375 || value
== DW_INL_declared_inlined
)
19376 may_be_inlined
= 1;
19381 if (tag
== DW_TAG_imported_unit
)
19383 d
.sect_off
= attr
.get_ref_die_offset ();
19384 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19385 || cu
->per_cu
->is_dwz
);
19389 case DW_AT_main_subprogram
:
19390 main_subprogram
= attr
.as_boolean ();
19395 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19396 on DWARF version). */
19397 ranges_offset
= attr
.as_unsigned ();
19399 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19401 if (tag
!= DW_TAG_compile_unit
)
19402 ranges_offset
+= cu
->gnu_ranges_base
;
19404 has_range_info
= 1;
19413 /* For Ada, if both the name and the linkage name appear, we prefer
19414 the latter. This lets "catch exception" work better, regardless
19415 of the order in which the name and linkage name were emitted.
19416 Really, though, this is just a workaround for the fact that gdb
19417 doesn't store both the name and the linkage name. */
19418 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19419 raw_name
= linkage_name
;
19421 if (high_pc_relative
)
19424 if (has_low_pc_attr
&& has_high_pc_attr
)
19426 /* When using the GNU linker, .gnu.linkonce. sections are used to
19427 eliminate duplicate copies of functions and vtables and such.
19428 The linker will arbitrarily choose one and discard the others.
19429 The AT_*_pc values for such functions refer to local labels in
19430 these sections. If the section from that file was discarded, the
19431 labels are not in the output, so the relocs get a value of 0.
19432 If this is a discarded function, mark the pc bounds as invalid,
19433 so that GDB will ignore it. */
19434 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19436 struct objfile
*objfile
= per_objfile
->objfile
;
19437 struct gdbarch
*gdbarch
= objfile
->arch ();
19439 complaint (_("DW_AT_low_pc %s is zero "
19440 "for DIE at %s [in module %s]"),
19441 paddress (gdbarch
, lowpc
),
19442 sect_offset_str (sect_off
),
19443 objfile_name (objfile
));
19445 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19446 else if (lowpc
>= highpc
)
19448 struct objfile
*objfile
= per_objfile
->objfile
;
19449 struct gdbarch
*gdbarch
= objfile
->arch ();
19451 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19452 "for DIE at %s [in module %s]"),
19453 paddress (gdbarch
, lowpc
),
19454 paddress (gdbarch
, highpc
),
19455 sect_offset_str (sect_off
),
19456 objfile_name (objfile
));
19465 /* Find a cached partial DIE at OFFSET in CU. */
19467 struct partial_die_info
*
19468 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19470 struct partial_die_info
*lookup_die
= NULL
;
19471 struct partial_die_info
part_die (sect_off
);
19473 lookup_die
= ((struct partial_die_info
*)
19474 htab_find_with_hash (partial_dies
, &part_die
,
19475 to_underlying (sect_off
)));
19480 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19481 except in the case of .debug_types DIEs which do not reference
19482 outside their CU (they do however referencing other types via
19483 DW_FORM_ref_sig8). */
19485 static const struct cu_partial_die_info
19486 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19488 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19489 struct objfile
*objfile
= per_objfile
->objfile
;
19490 struct partial_die_info
*pd
= NULL
;
19492 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19493 && cu
->header
.offset_in_cu_p (sect_off
))
19495 pd
= cu
->find_partial_die (sect_off
);
19498 /* We missed recording what we needed.
19499 Load all dies and try again. */
19503 /* TUs don't reference other CUs/TUs (except via type signatures). */
19504 if (cu
->per_cu
->is_debug_types
)
19506 error (_("Dwarf Error: Type Unit at offset %s contains"
19507 " external reference to offset %s [in module %s].\n"),
19508 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19509 bfd_get_filename (objfile
->obfd
));
19511 dwarf2_per_cu_data
*per_cu
19512 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19513 per_objfile
->per_bfd
);
19515 cu
= per_objfile
->get_cu (per_cu
);
19516 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19517 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19519 cu
= per_objfile
->get_cu (per_cu
);
19522 pd
= cu
->find_partial_die (sect_off
);
19525 /* If we didn't find it, and not all dies have been loaded,
19526 load them all and try again. */
19528 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19530 cu
->load_all_dies
= 1;
19532 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19533 THIS_CU->cu may already be in use. So we can't just free it and
19534 replace its DIEs with the ones we read in. Instead, we leave those
19535 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19536 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19538 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19540 pd
= cu
->find_partial_die (sect_off
);
19544 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19545 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19549 /* See if we can figure out if the class lives in a namespace. We do
19550 this by looking for a member function; its demangled name will
19551 contain namespace info, if there is any. */
19554 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19555 struct dwarf2_cu
*cu
)
19557 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19558 what template types look like, because the demangler
19559 frequently doesn't give the same name as the debug info. We
19560 could fix this by only using the demangled name to get the
19561 prefix (but see comment in read_structure_type). */
19563 struct partial_die_info
*real_pdi
;
19564 struct partial_die_info
*child_pdi
;
19566 /* If this DIE (this DIE's specification, if any) has a parent, then
19567 we should not do this. We'll prepend the parent's fully qualified
19568 name when we create the partial symbol. */
19570 real_pdi
= struct_pdi
;
19571 while (real_pdi
->has_specification
)
19573 auto res
= find_partial_die (real_pdi
->spec_offset
,
19574 real_pdi
->spec_is_dwz
, cu
);
19575 real_pdi
= res
.pdi
;
19579 if (real_pdi
->die_parent
!= NULL
)
19582 for (child_pdi
= struct_pdi
->die_child
;
19584 child_pdi
= child_pdi
->die_sibling
)
19586 if (child_pdi
->tag
== DW_TAG_subprogram
19587 && child_pdi
->linkage_name
!= NULL
)
19589 gdb::unique_xmalloc_ptr
<char> actual_class_name
19590 (cu
->language_defn
->class_name_from_physname
19591 (child_pdi
->linkage_name
));
19592 if (actual_class_name
!= NULL
)
19594 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19595 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19596 struct_pdi
->canonical_name
= 1;
19603 /* Return true if a DIE with TAG may have the DW_AT_const_value
19607 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19611 case DW_TAG_constant
:
19612 case DW_TAG_enumerator
:
19613 case DW_TAG_formal_parameter
:
19614 case DW_TAG_template_value_param
:
19615 case DW_TAG_variable
:
19623 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19625 /* Once we've fixed up a die, there's no point in doing so again.
19626 This also avoids a memory leak if we were to call
19627 guess_partial_die_structure_name multiple times. */
19631 /* If we found a reference attribute and the DIE has no name, try
19632 to find a name in the referred to DIE. */
19634 if (raw_name
== NULL
&& has_specification
)
19636 struct partial_die_info
*spec_die
;
19638 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19639 spec_die
= res
.pdi
;
19642 spec_die
->fixup (cu
);
19644 if (spec_die
->raw_name
)
19646 raw_name
= spec_die
->raw_name
;
19647 canonical_name
= spec_die
->canonical_name
;
19649 /* Copy DW_AT_external attribute if it is set. */
19650 if (spec_die
->is_external
)
19651 is_external
= spec_die
->is_external
;
19655 if (!has_const_value
&& has_specification
19656 && can_have_DW_AT_const_value_p (tag
))
19658 struct partial_die_info
*spec_die
;
19660 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19661 spec_die
= res
.pdi
;
19664 spec_die
->fixup (cu
);
19666 if (spec_die
->has_const_value
)
19668 /* Copy DW_AT_const_value attribute if it is set. */
19669 has_const_value
= spec_die
->has_const_value
;
19673 /* Set default names for some unnamed DIEs. */
19675 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19677 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19678 canonical_name
= 1;
19681 /* If there is no parent die to provide a namespace, and there are
19682 children, see if we can determine the namespace from their linkage
19684 if (cu
->per_cu
->lang
== language_cplus
19685 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19686 && die_parent
== NULL
19688 && (tag
== DW_TAG_class_type
19689 || tag
== DW_TAG_structure_type
19690 || tag
== DW_TAG_union_type
))
19691 guess_partial_die_structure_name (this, cu
);
19693 /* GCC might emit a nameless struct or union that has a linkage
19694 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19695 if (raw_name
== NULL
19696 && (tag
== DW_TAG_class_type
19697 || tag
== DW_TAG_interface_type
19698 || tag
== DW_TAG_structure_type
19699 || tag
== DW_TAG_union_type
)
19700 && linkage_name
!= NULL
)
19702 gdb::unique_xmalloc_ptr
<char> demangled
19703 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19704 if (demangled
!= nullptr)
19708 /* Strip any leading namespaces/classes, keep only the base name.
19709 DW_AT_name for named DIEs does not contain the prefixes. */
19710 base
= strrchr (demangled
.get (), ':');
19711 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19714 base
= demangled
.get ();
19716 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19717 raw_name
= objfile
->intern (base
);
19718 canonical_name
= 1;
19725 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19726 contents from the given SECTION in the HEADER.
19728 HEADER_OFFSET is the offset of the header in the section. */
19730 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19731 struct dwarf2_section_info
*section
,
19732 sect_offset header_offset
)
19734 unsigned int bytes_read
;
19735 bfd
*abfd
= section
->get_bfd_owner ();
19736 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19738 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19739 info_ptr
+= bytes_read
;
19741 header
->version
= read_2_bytes (abfd
, info_ptr
);
19744 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19747 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19750 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19753 /* Return the DW_AT_loclists_base value for the CU. */
19755 lookup_loclist_base (struct dwarf2_cu
*cu
)
19757 /* For the .dwo unit, the loclist_base points to the first offset following
19758 the header. The header consists of the following entities-
19759 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19761 2. version (2 bytes)
19762 3. address size (1 byte)
19763 4. segment selector size (1 byte)
19764 5. offset entry count (4 bytes)
19765 These sizes are derived as per the DWARFv5 standard. */
19766 if (cu
->dwo_unit
!= nullptr)
19768 if (cu
->header
.initial_length_size
== 4)
19769 return LOCLIST_HEADER_SIZE32
;
19770 return LOCLIST_HEADER_SIZE64
;
19772 return cu
->loclist_base
;
19775 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19776 array of offsets in the .debug_loclists section. */
19779 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19781 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19782 struct objfile
*objfile
= per_objfile
->objfile
;
19783 bfd
*abfd
= objfile
->obfd
;
19784 ULONGEST loclist_header_size
=
19785 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19786 : LOCLIST_HEADER_SIZE64
);
19787 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19789 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19790 ULONGEST start_offset
=
19791 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19793 /* Get loclists section. */
19794 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19796 /* Read the loclists section content. */
19797 section
->read (objfile
);
19798 if (section
->buffer
== NULL
)
19799 error (_("DW_FORM_loclistx used without .debug_loclists "
19800 "section [in module %s]"), objfile_name (objfile
));
19802 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19803 so if loclist_base is smaller than the header size, we have a problem. */
19804 if (loclist_base
< loclist_header_size
)
19805 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19806 objfile_name (objfile
));
19808 /* Read the header of the loclists contribution. */
19809 struct loclists_rnglists_header header
;
19810 read_loclists_rnglists_header (&header
, section
,
19811 (sect_offset
) (loclist_base
- loclist_header_size
));
19813 /* Verify the loclist index is valid. */
19814 if (loclist_index
>= header
.offset_entry_count
)
19815 error (_("DW_FORM_loclistx pointing outside of "
19816 ".debug_loclists offset array [in module %s]"),
19817 objfile_name (objfile
));
19819 /* Validate that reading won't go beyond the end of the section. */
19820 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19821 error (_("Reading DW_FORM_loclistx index beyond end of"
19822 ".debug_loclists section [in module %s]"),
19823 objfile_name (objfile
));
19825 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19827 if (cu
->header
.offset_size
== 4)
19828 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19830 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19833 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19834 array of offsets in the .debug_rnglists section. */
19837 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19840 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19841 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19842 bfd
*abfd
= objfile
->obfd
;
19843 ULONGEST rnglist_header_size
=
19844 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19845 : RNGLIST_HEADER_SIZE64
);
19847 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19848 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19850 ULONGEST rnglist_base
=
19851 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19853 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19854 ULONGEST start_offset
=
19855 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19857 /* Get rnglists section. */
19858 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19860 /* Read the rnglists section content. */
19861 section
->read (objfile
);
19862 if (section
->buffer
== nullptr)
19863 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19865 objfile_name (objfile
));
19867 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19868 so if rnglist_base is smaller than the header size, we have a problem. */
19869 if (rnglist_base
< rnglist_header_size
)
19870 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19871 objfile_name (objfile
));
19873 /* Read the header of the rnglists contribution. */
19874 struct loclists_rnglists_header header
;
19875 read_loclists_rnglists_header (&header
, section
,
19876 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19878 /* Verify the rnglist index is valid. */
19879 if (rnglist_index
>= header
.offset_entry_count
)
19880 error (_("DW_FORM_rnglistx index pointing outside of "
19881 ".debug_rnglists offset array [in module %s]"),
19882 objfile_name (objfile
));
19884 /* Validate that reading won't go beyond the end of the section. */
19885 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19886 error (_("Reading DW_FORM_rnglistx index beyond end of"
19887 ".debug_rnglists section [in module %s]"),
19888 objfile_name (objfile
));
19890 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19892 if (cu
->header
.offset_size
== 4)
19893 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19895 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19898 /* Process the attributes that had to be skipped in the first round. These
19899 attributes are the ones that need str_offsets_base or addr_base attributes.
19900 They could not have been processed in the first round, because at the time
19901 the values of str_offsets_base or addr_base may not have been known. */
19903 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19904 struct attribute
*attr
, dwarf_tag tag
)
19906 struct dwarf2_cu
*cu
= reader
->cu
;
19907 switch (attr
->form
)
19909 case DW_FORM_addrx
:
19910 case DW_FORM_GNU_addr_index
:
19911 attr
->set_address (read_addr_index (cu
,
19912 attr
->as_unsigned_reprocess ()));
19914 case DW_FORM_loclistx
:
19916 sect_offset loclists_sect_off
19917 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19919 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19922 case DW_FORM_rnglistx
:
19924 sect_offset rnglists_sect_off
19925 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19927 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19931 case DW_FORM_strx1
:
19932 case DW_FORM_strx2
:
19933 case DW_FORM_strx3
:
19934 case DW_FORM_strx4
:
19935 case DW_FORM_GNU_str_index
:
19937 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19938 gdb_assert (!attr
->canonical_string_p ());
19939 if (reader
->dwo_file
!= NULL
)
19940 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19943 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19948 gdb_assert_not_reached ("Unexpected DWARF form.");
19952 /* Read an attribute value described by an attribute form. */
19954 static const gdb_byte
*
19955 read_attribute_value (const struct die_reader_specs
*reader
,
19956 struct attribute
*attr
, unsigned form
,
19957 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19959 struct dwarf2_cu
*cu
= reader
->cu
;
19960 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19961 struct objfile
*objfile
= per_objfile
->objfile
;
19962 bfd
*abfd
= reader
->abfd
;
19963 struct comp_unit_head
*cu_header
= &cu
->header
;
19964 unsigned int bytes_read
;
19965 struct dwarf_block
*blk
;
19967 attr
->form
= (enum dwarf_form
) form
;
19970 case DW_FORM_ref_addr
:
19971 if (cu_header
->version
== 2)
19972 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19975 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19977 info_ptr
+= bytes_read
;
19979 case DW_FORM_GNU_ref_alt
:
19980 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19982 info_ptr
+= bytes_read
;
19986 struct gdbarch
*gdbarch
= objfile
->arch ();
19987 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19988 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19989 attr
->set_address (addr
);
19990 info_ptr
+= bytes_read
;
19993 case DW_FORM_block2
:
19994 blk
= dwarf_alloc_block (cu
);
19995 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19997 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19998 info_ptr
+= blk
->size
;
19999 attr
->set_block (blk
);
20001 case DW_FORM_block4
:
20002 blk
= dwarf_alloc_block (cu
);
20003 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20005 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20006 info_ptr
+= blk
->size
;
20007 attr
->set_block (blk
);
20009 case DW_FORM_data2
:
20010 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20013 case DW_FORM_data4
:
20014 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20017 case DW_FORM_data8
:
20018 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20021 case DW_FORM_data16
:
20022 blk
= dwarf_alloc_block (cu
);
20024 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20026 attr
->set_block (blk
);
20028 case DW_FORM_sec_offset
:
20029 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20031 info_ptr
+= bytes_read
;
20033 case DW_FORM_loclistx
:
20035 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20037 info_ptr
+= bytes_read
;
20040 case DW_FORM_string
:
20041 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20043 info_ptr
+= bytes_read
;
20046 if (!cu
->per_cu
->is_dwz
)
20048 attr
->set_string_noncanonical
20049 (read_indirect_string (per_objfile
,
20050 abfd
, info_ptr
, cu_header
,
20052 info_ptr
+= bytes_read
;
20056 case DW_FORM_line_strp
:
20057 if (!cu
->per_cu
->is_dwz
)
20059 attr
->set_string_noncanonical
20060 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20062 info_ptr
+= bytes_read
;
20066 case DW_FORM_GNU_strp_alt
:
20068 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20069 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20072 attr
->set_string_noncanonical
20073 (dwz
->read_string (objfile
, str_offset
));
20074 info_ptr
+= bytes_read
;
20077 case DW_FORM_exprloc
:
20078 case DW_FORM_block
:
20079 blk
= dwarf_alloc_block (cu
);
20080 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20081 info_ptr
+= bytes_read
;
20082 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20083 info_ptr
+= blk
->size
;
20084 attr
->set_block (blk
);
20086 case DW_FORM_block1
:
20087 blk
= dwarf_alloc_block (cu
);
20088 blk
->size
= read_1_byte (abfd
, info_ptr
);
20090 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20091 info_ptr
+= blk
->size
;
20092 attr
->set_block (blk
);
20094 case DW_FORM_data1
:
20096 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20099 case DW_FORM_flag_present
:
20100 attr
->set_unsigned (1);
20102 case DW_FORM_sdata
:
20103 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20104 info_ptr
+= bytes_read
;
20106 case DW_FORM_rnglistx
:
20108 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20110 info_ptr
+= bytes_read
;
20113 case DW_FORM_udata
:
20114 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20115 info_ptr
+= bytes_read
;
20118 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20119 + read_1_byte (abfd
, info_ptr
)));
20123 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20124 + read_2_bytes (abfd
, info_ptr
)));
20128 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20129 + read_4_bytes (abfd
, info_ptr
)));
20133 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20134 + read_8_bytes (abfd
, info_ptr
)));
20137 case DW_FORM_ref_sig8
:
20138 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20141 case DW_FORM_ref_udata
:
20142 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20143 + read_unsigned_leb128 (abfd
, info_ptr
,
20145 info_ptr
+= bytes_read
;
20147 case DW_FORM_indirect
:
20148 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20149 info_ptr
+= bytes_read
;
20150 if (form
== DW_FORM_implicit_const
)
20152 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20153 info_ptr
+= bytes_read
;
20155 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20158 case DW_FORM_implicit_const
:
20159 attr
->set_signed (implicit_const
);
20161 case DW_FORM_addrx
:
20162 case DW_FORM_GNU_addr_index
:
20163 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20165 info_ptr
+= bytes_read
;
20168 case DW_FORM_strx1
:
20169 case DW_FORM_strx2
:
20170 case DW_FORM_strx3
:
20171 case DW_FORM_strx4
:
20172 case DW_FORM_GNU_str_index
:
20174 ULONGEST str_index
;
20175 if (form
== DW_FORM_strx1
)
20177 str_index
= read_1_byte (abfd
, info_ptr
);
20180 else if (form
== DW_FORM_strx2
)
20182 str_index
= read_2_bytes (abfd
, info_ptr
);
20185 else if (form
== DW_FORM_strx3
)
20187 str_index
= read_3_bytes (abfd
, info_ptr
);
20190 else if (form
== DW_FORM_strx4
)
20192 str_index
= read_4_bytes (abfd
, info_ptr
);
20197 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20198 info_ptr
+= bytes_read
;
20200 attr
->set_unsigned_reprocess (str_index
);
20204 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20205 dwarf_form_name (form
),
20206 bfd_get_filename (abfd
));
20210 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20211 attr
->form
= DW_FORM_GNU_ref_alt
;
20213 /* We have seen instances where the compiler tried to emit a byte
20214 size attribute of -1 which ended up being encoded as an unsigned
20215 0xffffffff. Although 0xffffffff is technically a valid size value,
20216 an object of this size seems pretty unlikely so we can relatively
20217 safely treat these cases as if the size attribute was invalid and
20218 treat them as zero by default. */
20219 if (attr
->name
== DW_AT_byte_size
20220 && form
== DW_FORM_data4
20221 && attr
->as_unsigned () >= 0xffffffff)
20224 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20225 hex_string (attr
->as_unsigned ()));
20226 attr
->set_unsigned (0);
20232 /* Read an attribute described by an abbreviated attribute. */
20234 static const gdb_byte
*
20235 read_attribute (const struct die_reader_specs
*reader
,
20236 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20237 const gdb_byte
*info_ptr
)
20239 attr
->name
= abbrev
->name
;
20240 attr
->string_is_canonical
= 0;
20241 attr
->requires_reprocessing
= 0;
20242 return read_attribute_value (reader
, attr
, abbrev
->form
,
20243 abbrev
->implicit_const
, info_ptr
);
20246 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20248 static const char *
20249 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20250 LONGEST str_offset
)
20252 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20253 str_offset
, "DW_FORM_strp");
20256 /* Return pointer to string at .debug_str offset as read from BUF.
20257 BUF is assumed to be in a compilation unit described by CU_HEADER.
20258 Return *BYTES_READ_PTR count of bytes read from BUF. */
20260 static const char *
20261 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20262 const gdb_byte
*buf
,
20263 const struct comp_unit_head
*cu_header
,
20264 unsigned int *bytes_read_ptr
)
20266 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20268 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20274 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20275 unsigned int offset_size
)
20277 bfd
*abfd
= objfile
->obfd
;
20278 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
20280 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20286 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20287 const struct comp_unit_head
*cu_header
,
20288 unsigned int *bytes_read_ptr
)
20290 bfd
*abfd
= objfile
->obfd
;
20291 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20293 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20296 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20297 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20298 ADDR_SIZE is the size of addresses from the CU header. */
20301 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20302 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20304 struct objfile
*objfile
= per_objfile
->objfile
;
20305 bfd
*abfd
= objfile
->obfd
;
20306 const gdb_byte
*info_ptr
;
20307 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20309 per_objfile
->per_bfd
->addr
.read (objfile
);
20310 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20311 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20312 objfile_name (objfile
));
20313 if (addr_base_or_zero
+ addr_index
* addr_size
20314 >= per_objfile
->per_bfd
->addr
.size
)
20315 error (_("DW_FORM_addr_index pointing outside of "
20316 ".debug_addr section [in module %s]"),
20317 objfile_name (objfile
));
20318 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20319 + addr_index
* addr_size
);
20320 if (addr_size
== 4)
20321 return bfd_get_32 (abfd
, info_ptr
);
20323 return bfd_get_64 (abfd
, info_ptr
);
20326 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20329 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20331 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20332 cu
->addr_base
, cu
->header
.addr_size
);
20335 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20338 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20339 unsigned int *bytes_read
)
20341 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20342 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20344 return read_addr_index (cu
, addr_index
);
20350 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20351 dwarf2_per_objfile
*per_objfile
,
20352 unsigned int addr_index
)
20354 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20355 gdb::optional
<ULONGEST
> addr_base
;
20358 /* We need addr_base and addr_size.
20359 If we don't have PER_CU->cu, we have to get it.
20360 Nasty, but the alternative is storing the needed info in PER_CU,
20361 which at this point doesn't seem justified: it's not clear how frequently
20362 it would get used and it would increase the size of every PER_CU.
20363 Entry points like dwarf2_per_cu_addr_size do a similar thing
20364 so we're not in uncharted territory here.
20365 Alas we need to be a bit more complicated as addr_base is contained
20368 We don't need to read the entire CU(/TU).
20369 We just need the header and top level die.
20371 IWBN to use the aging mechanism to let us lazily later discard the CU.
20372 For now we skip this optimization. */
20376 addr_base
= cu
->addr_base
;
20377 addr_size
= cu
->header
.addr_size
;
20381 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20382 addr_base
= reader
.cu
->addr_base
;
20383 addr_size
= reader
.cu
->header
.addr_size
;
20386 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20389 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20390 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20393 static const char *
20394 read_str_index (struct dwarf2_cu
*cu
,
20395 struct dwarf2_section_info
*str_section
,
20396 struct dwarf2_section_info
*str_offsets_section
,
20397 ULONGEST str_offsets_base
, ULONGEST str_index
)
20399 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20400 struct objfile
*objfile
= per_objfile
->objfile
;
20401 const char *objf_name
= objfile_name (objfile
);
20402 bfd
*abfd
= objfile
->obfd
;
20403 const gdb_byte
*info_ptr
;
20404 ULONGEST str_offset
;
20405 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20407 str_section
->read (objfile
);
20408 str_offsets_section
->read (objfile
);
20409 if (str_section
->buffer
== NULL
)
20410 error (_("%s used without %s section"
20411 " in CU at offset %s [in module %s]"),
20412 form_name
, str_section
->get_name (),
20413 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20414 if (str_offsets_section
->buffer
== NULL
)
20415 error (_("%s used without %s section"
20416 " in CU at offset %s [in module %s]"),
20417 form_name
, str_section
->get_name (),
20418 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20419 info_ptr
= (str_offsets_section
->buffer
20421 + str_index
* cu
->header
.offset_size
);
20422 if (cu
->header
.offset_size
== 4)
20423 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20425 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20426 if (str_offset
>= str_section
->size
)
20427 error (_("Offset from %s pointing outside of"
20428 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20429 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20430 return (const char *) (str_section
->buffer
+ str_offset
);
20433 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20435 static const char *
20436 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20438 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20439 ? reader
->cu
->header
.addr_size
: 0;
20440 return read_str_index (reader
->cu
,
20441 &reader
->dwo_file
->sections
.str
,
20442 &reader
->dwo_file
->sections
.str_offsets
,
20443 str_offsets_base
, str_index
);
20446 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20448 static const char *
20449 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20451 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20452 const char *objf_name
= objfile_name (objfile
);
20453 static const char form_name
[] = "DW_FORM_GNU_str_index";
20454 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20456 if (!cu
->str_offsets_base
.has_value ())
20457 error (_("%s used in Fission stub without %s"
20458 " in CU at offset 0x%lx [in module %s]"),
20459 form_name
, str_offsets_attr_name
,
20460 (long) cu
->header
.offset_size
, objf_name
);
20462 return read_str_index (cu
,
20463 &cu
->per_objfile
->per_bfd
->str
,
20464 &cu
->per_objfile
->per_bfd
->str_offsets
,
20465 *cu
->str_offsets_base
, str_index
);
20468 /* Return the length of an LEB128 number in BUF. */
20471 leb128_size (const gdb_byte
*buf
)
20473 const gdb_byte
*begin
= buf
;
20479 if ((byte
& 128) == 0)
20480 return buf
- begin
;
20484 static enum language
20485 dwarf_lang_to_enum_language (unsigned int lang
)
20487 enum language language
;
20496 language
= language_c
;
20499 case DW_LANG_C_plus_plus
:
20500 case DW_LANG_C_plus_plus_11
:
20501 case DW_LANG_C_plus_plus_14
:
20502 language
= language_cplus
;
20505 language
= language_d
;
20507 case DW_LANG_Fortran77
:
20508 case DW_LANG_Fortran90
:
20509 case DW_LANG_Fortran95
:
20510 case DW_LANG_Fortran03
:
20511 case DW_LANG_Fortran08
:
20512 language
= language_fortran
;
20515 language
= language_go
;
20517 case DW_LANG_Mips_Assembler
:
20518 language
= language_asm
;
20520 case DW_LANG_Ada83
:
20521 case DW_LANG_Ada95
:
20522 language
= language_ada
;
20524 case DW_LANG_Modula2
:
20525 language
= language_m2
;
20527 case DW_LANG_Pascal83
:
20528 language
= language_pascal
;
20531 language
= language_objc
;
20534 case DW_LANG_Rust_old
:
20535 language
= language_rust
;
20537 case DW_LANG_OpenCL
:
20538 language
= language_opencl
;
20540 case DW_LANG_Cobol74
:
20541 case DW_LANG_Cobol85
:
20543 language
= language_minimal
;
20550 /* Return the named attribute or NULL if not there. */
20552 static struct attribute
*
20553 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20558 struct attribute
*spec
= NULL
;
20560 for (i
= 0; i
< die
->num_attrs
; ++i
)
20562 if (die
->attrs
[i
].name
== name
)
20563 return &die
->attrs
[i
];
20564 if (die
->attrs
[i
].name
== DW_AT_specification
20565 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20566 spec
= &die
->attrs
[i
];
20572 die
= follow_die_ref (die
, spec
, &cu
);
20578 /* Return the string associated with a string-typed attribute, or NULL if it
20579 is either not found or is of an incorrect type. */
20581 static const char *
20582 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20584 struct attribute
*attr
;
20585 const char *str
= NULL
;
20587 attr
= dwarf2_attr (die
, name
, cu
);
20591 str
= attr
->as_string ();
20592 if (str
== nullptr)
20593 complaint (_("string type expected for attribute %s for "
20594 "DIE at %s in module %s"),
20595 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20596 objfile_name (cu
->per_objfile
->objfile
));
20602 /* Return the dwo name or NULL if not present. If present, it is in either
20603 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20604 static const char *
20605 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20607 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20608 if (dwo_name
== nullptr)
20609 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20613 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20614 and holds a non-zero value. This function should only be used for
20615 DW_FORM_flag or DW_FORM_flag_present attributes. */
20618 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20620 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20622 return attr
!= nullptr && attr
->as_boolean ();
20626 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20628 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20629 which value is non-zero. However, we have to be careful with
20630 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20631 (via dwarf2_flag_true_p) follows this attribute. So we may
20632 end up accidently finding a declaration attribute that belongs
20633 to a different DIE referenced by the specification attribute,
20634 even though the given DIE does not have a declaration attribute. */
20635 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20636 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20639 /* Return the die giving the specification for DIE, if there is
20640 one. *SPEC_CU is the CU containing DIE on input, and the CU
20641 containing the return value on output. If there is no
20642 specification, but there is an abstract origin, that is
20645 static struct die_info
*
20646 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20648 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20651 if (spec_attr
== NULL
)
20652 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20654 if (spec_attr
== NULL
)
20657 return follow_die_ref (die
, spec_attr
, spec_cu
);
20660 /* A convenience function to find the proper .debug_line section for a CU. */
20662 static struct dwarf2_section_info
*
20663 get_debug_line_section (struct dwarf2_cu
*cu
)
20665 struct dwarf2_section_info
*section
;
20666 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20668 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20670 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20671 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20672 else if (cu
->per_cu
->is_dwz
)
20674 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20676 section
= &dwz
->line
;
20679 section
= &per_objfile
->per_bfd
->line
;
20684 /* Read the statement program header starting at OFFSET in
20685 .debug_line, or .debug_line.dwo. Return a pointer
20686 to a struct line_header, allocated using xmalloc.
20687 Returns NULL if there is a problem reading the header, e.g., if it
20688 has a version we don't understand.
20690 NOTE: the strings in the include directory and file name tables of
20691 the returned object point into the dwarf line section buffer,
20692 and must not be freed. */
20694 static line_header_up
20695 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20697 struct dwarf2_section_info
*section
;
20698 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20700 section
= get_debug_line_section (cu
);
20701 section
->read (per_objfile
->objfile
);
20702 if (section
->buffer
== NULL
)
20704 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20705 complaint (_("missing .debug_line.dwo section"));
20707 complaint (_("missing .debug_line section"));
20711 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20712 per_objfile
, section
, &cu
->header
);
20715 /* Subroutine of dwarf_decode_lines to simplify it.
20716 Return the file name for the given file_entry.
20717 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
20718 If space for the result is malloc'd, *NAME_HOLDER will be set.
20719 Returns NULL if FILE_INDEX should be ignored, i.e., it is
20720 equivalent to CU_INFO. */
20722 static const char *
20723 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20724 const file_and_directory
&cu_info
,
20725 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20727 const char *include_name
= fe
.name
;
20728 const char *include_name_to_compare
= include_name
;
20730 const char *dir_name
= fe
.include_dir (lh
);
20732 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20733 if (!IS_ABSOLUTE_PATH (include_name
)
20734 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
20736 /* Avoid creating a duplicate name for CU_INFO.
20737 We do this by comparing INCLUDE_NAME and CU_INFO.
20738 Before we do the comparison, however, we need to account
20739 for DIR_NAME and COMP_DIR.
20740 First prepend dir_name (if non-NULL). If we still don't
20741 have an absolute path prepend comp_dir (if non-NULL).
20742 However, the directory we record in the include-file's
20743 psymtab does not contain COMP_DIR (to match the
20744 corresponding symtab(s)).
20749 bash$ gcc -g ./hello.c
20750 include_name = "hello.c"
20752 DW_AT_comp_dir = comp_dir = "/tmp"
20753 DW_AT_name = "./hello.c"
20757 if (dir_name
!= NULL
)
20759 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20760 include_name
, (char *) NULL
));
20761 include_name
= name_holder
->get ();
20762 include_name_to_compare
= include_name
;
20764 if (!IS_ABSOLUTE_PATH (include_name
)
20765 && cu_info
.get_comp_dir () != nullptr)
20767 hold_compare
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20768 include_name
, (char *) NULL
));
20769 include_name_to_compare
= hold_compare
.get ();
20773 gdb::unique_xmalloc_ptr
<char> copied_name
;
20774 const char *cu_filename
= cu_info
.get_name ();
20775 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
20777 copied_name
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20778 cu_filename
, (char *) NULL
));
20779 cu_filename
= copied_name
.get ();
20782 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
20784 return include_name
;
20787 /* State machine to track the state of the line number program. */
20789 class lnp_state_machine
20792 /* Initialize a machine state for the start of a line number
20794 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20795 bool record_lines_p
);
20797 file_entry
*current_file ()
20799 /* lh->file_names is 0-based, but the file name numbers in the
20800 statement program are 1-based. */
20801 return m_line_header
->file_name_at (m_file
);
20804 /* Record the line in the state machine. END_SEQUENCE is true if
20805 we're processing the end of a sequence. */
20806 void record_line (bool end_sequence
);
20808 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20809 nop-out rest of the lines in this sequence. */
20810 void check_line_address (struct dwarf2_cu
*cu
,
20811 const gdb_byte
*line_ptr
,
20812 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20814 void handle_set_discriminator (unsigned int discriminator
)
20816 m_discriminator
= discriminator
;
20817 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20820 /* Handle DW_LNE_set_address. */
20821 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20824 address
+= baseaddr
;
20825 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20828 /* Handle DW_LNS_advance_pc. */
20829 void handle_advance_pc (CORE_ADDR adjust
);
20831 /* Handle a special opcode. */
20832 void handle_special_opcode (unsigned char op_code
);
20834 /* Handle DW_LNS_advance_line. */
20835 void handle_advance_line (int line_delta
)
20837 advance_line (line_delta
);
20840 /* Handle DW_LNS_set_file. */
20841 void handle_set_file (file_name_index file
);
20843 /* Handle DW_LNS_negate_stmt. */
20844 void handle_negate_stmt ()
20846 m_is_stmt
= !m_is_stmt
;
20849 /* Handle DW_LNS_const_add_pc. */
20850 void handle_const_add_pc ();
20852 /* Handle DW_LNS_fixed_advance_pc. */
20853 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20855 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20859 /* Handle DW_LNS_copy. */
20860 void handle_copy ()
20862 record_line (false);
20863 m_discriminator
= 0;
20866 /* Handle DW_LNE_end_sequence. */
20867 void handle_end_sequence ()
20869 m_currently_recording_lines
= true;
20873 /* Advance the line by LINE_DELTA. */
20874 void advance_line (int line_delta
)
20876 m_line
+= line_delta
;
20878 if (line_delta
!= 0)
20879 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20882 struct dwarf2_cu
*m_cu
;
20884 gdbarch
*m_gdbarch
;
20886 /* True if we're recording lines.
20887 Otherwise we're building partial symtabs and are just interested in
20888 finding include files mentioned by the line number program. */
20889 bool m_record_lines_p
;
20891 /* The line number header. */
20892 line_header
*m_line_header
;
20894 /* These are part of the standard DWARF line number state machine,
20895 and initialized according to the DWARF spec. */
20897 unsigned char m_op_index
= 0;
20898 /* The line table index of the current file. */
20899 file_name_index m_file
= 1;
20900 unsigned int m_line
= 1;
20902 /* These are initialized in the constructor. */
20904 CORE_ADDR m_address
;
20906 unsigned int m_discriminator
;
20908 /* Additional bits of state we need to track. */
20910 /* The last file that we called dwarf2_start_subfile for.
20911 This is only used for TLLs. */
20912 unsigned int m_last_file
= 0;
20913 /* The last file a line number was recorded for. */
20914 struct subfile
*m_last_subfile
= NULL
;
20916 /* The address of the last line entry. */
20917 CORE_ADDR m_last_address
;
20919 /* Set to true when a previous line at the same address (using
20920 m_last_address) had m_is_stmt true. This is reset to false when a
20921 line entry at a new address (m_address different to m_last_address) is
20923 bool m_stmt_at_address
= false;
20925 /* When true, record the lines we decode. */
20926 bool m_currently_recording_lines
= false;
20928 /* The last line number that was recorded, used to coalesce
20929 consecutive entries for the same line. This can happen, for
20930 example, when discriminators are present. PR 17276. */
20931 unsigned int m_last_line
= 0;
20932 bool m_line_has_non_zero_discriminator
= false;
20936 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20938 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20939 / m_line_header
->maximum_ops_per_instruction
)
20940 * m_line_header
->minimum_instruction_length
);
20941 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20942 m_op_index
= ((m_op_index
+ adjust
)
20943 % m_line_header
->maximum_ops_per_instruction
);
20947 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20949 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20950 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20951 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20952 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20953 / m_line_header
->maximum_ops_per_instruction
)
20954 * m_line_header
->minimum_instruction_length
);
20955 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20956 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20957 % m_line_header
->maximum_ops_per_instruction
);
20959 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20960 advance_line (line_delta
);
20961 record_line (false);
20962 m_discriminator
= 0;
20966 lnp_state_machine::handle_set_file (file_name_index file
)
20970 const file_entry
*fe
= current_file ();
20972 dwarf2_debug_line_missing_file_complaint ();
20973 else if (m_record_lines_p
)
20975 const char *dir
= fe
->include_dir (m_line_header
);
20977 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20978 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20979 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20984 lnp_state_machine::handle_const_add_pc ()
20987 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20990 = (((m_op_index
+ adjust
)
20991 / m_line_header
->maximum_ops_per_instruction
)
20992 * m_line_header
->minimum_instruction_length
);
20994 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20995 m_op_index
= ((m_op_index
+ adjust
)
20996 % m_line_header
->maximum_ops_per_instruction
);
20999 /* Return non-zero if we should add LINE to the line number table.
21000 LINE is the line to add, LAST_LINE is the last line that was added,
21001 LAST_SUBFILE is the subfile for LAST_LINE.
21002 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21003 had a non-zero discriminator.
21005 We have to be careful in the presence of discriminators.
21006 E.g., for this line:
21008 for (i = 0; i < 100000; i++);
21010 clang can emit four line number entries for that one line,
21011 each with a different discriminator.
21012 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21014 However, we want gdb to coalesce all four entries into one.
21015 Otherwise the user could stepi into the middle of the line and
21016 gdb would get confused about whether the pc really was in the
21017 middle of the line.
21019 Things are further complicated by the fact that two consecutive
21020 line number entries for the same line is a heuristic used by gcc
21021 to denote the end of the prologue. So we can't just discard duplicate
21022 entries, we have to be selective about it. The heuristic we use is
21023 that we only collapse consecutive entries for the same line if at least
21024 one of those entries has a non-zero discriminator. PR 17276.
21026 Note: Addresses in the line number state machine can never go backwards
21027 within one sequence, thus this coalescing is ok. */
21030 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21031 unsigned int line
, unsigned int last_line
,
21032 int line_has_non_zero_discriminator
,
21033 struct subfile
*last_subfile
)
21035 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21037 if (line
!= last_line
)
21039 /* Same line for the same file that we've seen already.
21040 As a last check, for pr 17276, only record the line if the line
21041 has never had a non-zero discriminator. */
21042 if (!line_has_non_zero_discriminator
)
21047 /* Use the CU's builder to record line number LINE beginning at
21048 address ADDRESS in the line table of subfile SUBFILE. */
21051 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21052 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21053 struct dwarf2_cu
*cu
)
21055 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21057 if (dwarf_line_debug
)
21059 fprintf_unfiltered (gdb_stdlog
,
21060 "Recording line %u, file %s, address %s\n",
21061 line
, lbasename (subfile
->name
),
21062 paddress (gdbarch
, address
));
21066 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21069 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21070 Mark the end of a set of line number records.
21071 The arguments are the same as for dwarf_record_line_1.
21072 If SUBFILE is NULL the request is ignored. */
21075 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21076 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21078 if (subfile
== NULL
)
21081 if (dwarf_line_debug
)
21083 fprintf_unfiltered (gdb_stdlog
,
21084 "Finishing current line, file %s, address %s\n",
21085 lbasename (subfile
->name
),
21086 paddress (gdbarch
, address
));
21089 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21093 lnp_state_machine::record_line (bool end_sequence
)
21095 if (dwarf_line_debug
)
21097 fprintf_unfiltered (gdb_stdlog
,
21098 "Processing actual line %u: file %u,"
21099 " address %s, is_stmt %u, discrim %u%s\n",
21101 paddress (m_gdbarch
, m_address
),
21102 m_is_stmt
, m_discriminator
,
21103 (end_sequence
? "\t(end sequence)" : ""));
21106 file_entry
*fe
= current_file ();
21109 dwarf2_debug_line_missing_file_complaint ();
21110 /* For now we ignore lines not starting on an instruction boundary.
21111 But not when processing end_sequence for compatibility with the
21112 previous version of the code. */
21113 else if (m_op_index
== 0 || end_sequence
)
21115 fe
->included_p
= true;
21116 if (m_record_lines_p
)
21118 /* When we switch files we insert an end maker in the first file,
21119 switch to the second file and add a new line entry. The
21120 problem is that the end marker inserted in the first file will
21121 discard any previous line entries at the same address. If the
21122 line entries in the first file are marked as is-stmt, while
21123 the new line in the second file is non-stmt, then this means
21124 the end marker will discard is-stmt lines so we can have a
21125 non-stmt line. This means that there are less addresses at
21126 which the user can insert a breakpoint.
21128 To improve this we track the last address in m_last_address,
21129 and whether we have seen an is-stmt at this address. Then
21130 when switching files, if we have seen a stmt at the current
21131 address, and we are switching to create a non-stmt line, then
21132 discard the new line. */
21134 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21135 bool ignore_this_line
21136 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21137 && !m_is_stmt
&& m_stmt_at_address
)
21138 || (!end_sequence
&& m_line
== 0));
21140 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21142 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21143 m_currently_recording_lines
? m_cu
: nullptr);
21146 if (!end_sequence
&& !ignore_this_line
)
21148 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21150 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21151 m_line_has_non_zero_discriminator
,
21154 buildsym_compunit
*builder
= m_cu
->get_builder ();
21155 dwarf_record_line_1 (m_gdbarch
,
21156 builder
->get_current_subfile (),
21157 m_line
, m_address
, is_stmt
,
21158 m_currently_recording_lines
? m_cu
: nullptr);
21160 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21161 m_last_line
= m_line
;
21166 /* Track whether we have seen any m_is_stmt true at m_address in case we
21167 have multiple line table entries all at m_address. */
21168 if (m_last_address
!= m_address
)
21170 m_stmt_at_address
= false;
21171 m_last_address
= m_address
;
21173 m_stmt_at_address
|= m_is_stmt
;
21176 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21177 line_header
*lh
, bool record_lines_p
)
21181 m_record_lines_p
= record_lines_p
;
21182 m_line_header
= lh
;
21184 m_currently_recording_lines
= true;
21186 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21187 was a line entry for it so that the backend has a chance to adjust it
21188 and also record it in case it needs it. This is currently used by MIPS
21189 code, cf. `mips_adjust_dwarf2_line'. */
21190 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21191 m_is_stmt
= lh
->default_is_stmt
;
21192 m_discriminator
= 0;
21194 m_last_address
= m_address
;
21195 m_stmt_at_address
= false;
21199 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21200 const gdb_byte
*line_ptr
,
21201 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21203 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21204 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21205 located at 0x0. In this case, additionally check that if
21206 ADDRESS < UNRELOCATED_LOWPC. */
21208 if ((address
== 0 && address
< unrelocated_lowpc
)
21209 || address
== (CORE_ADDR
) -1)
21211 /* This line table is for a function which has been
21212 GCd by the linker. Ignore it. PR gdb/12528 */
21214 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21215 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21217 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21218 line_offset
, objfile_name (objfile
));
21219 m_currently_recording_lines
= false;
21220 /* Note: m_currently_recording_lines is left as false until we see
21221 DW_LNE_end_sequence. */
21225 /* Subroutine of dwarf_decode_lines to simplify it.
21226 Process the line number information in LH.
21227 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21228 program in order to set included_p for every referenced header. */
21231 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21232 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21234 const gdb_byte
*line_ptr
, *extended_end
;
21235 const gdb_byte
*line_end
;
21236 unsigned int bytes_read
, extended_len
;
21237 unsigned char op_code
, extended_op
;
21238 CORE_ADDR baseaddr
;
21239 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21240 bfd
*abfd
= objfile
->obfd
;
21241 struct gdbarch
*gdbarch
= objfile
->arch ();
21242 /* True if we're recording line info (as opposed to building partial
21243 symtabs and just interested in finding include files mentioned by
21244 the line number program). */
21245 bool record_lines_p
= !decode_for_pst_p
;
21247 baseaddr
= objfile
->text_section_offset ();
21249 line_ptr
= lh
->statement_program_start
;
21250 line_end
= lh
->statement_program_end
;
21252 /* Read the statement sequences until there's nothing left. */
21253 while (line_ptr
< line_end
)
21255 /* The DWARF line number program state machine. Reset the state
21256 machine at the start of each sequence. */
21257 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21258 bool end_sequence
= false;
21260 if (record_lines_p
)
21262 /* Start a subfile for the current file of the state
21264 const file_entry
*fe
= state_machine
.current_file ();
21267 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21270 /* Decode the table. */
21271 while (line_ptr
< line_end
&& !end_sequence
)
21273 op_code
= read_1_byte (abfd
, line_ptr
);
21276 if (op_code
>= lh
->opcode_base
)
21278 /* Special opcode. */
21279 state_machine
.handle_special_opcode (op_code
);
21281 else switch (op_code
)
21283 case DW_LNS_extended_op
:
21284 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21286 line_ptr
+= bytes_read
;
21287 extended_end
= line_ptr
+ extended_len
;
21288 extended_op
= read_1_byte (abfd
, line_ptr
);
21290 if (DW_LNE_lo_user
<= extended_op
21291 && extended_op
<= DW_LNE_hi_user
)
21293 /* Vendor extension, ignore. */
21294 line_ptr
= extended_end
;
21297 switch (extended_op
)
21299 case DW_LNE_end_sequence
:
21300 state_machine
.handle_end_sequence ();
21301 end_sequence
= true;
21303 case DW_LNE_set_address
:
21306 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21307 line_ptr
+= bytes_read
;
21309 state_machine
.check_line_address (cu
, line_ptr
,
21310 lowpc
- baseaddr
, address
);
21311 state_machine
.handle_set_address (baseaddr
, address
);
21314 case DW_LNE_define_file
:
21316 const char *cur_file
;
21317 unsigned int mod_time
, length
;
21320 cur_file
= read_direct_string (abfd
, line_ptr
,
21322 line_ptr
+= bytes_read
;
21323 dindex
= (dir_index
)
21324 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21325 line_ptr
+= bytes_read
;
21327 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21328 line_ptr
+= bytes_read
;
21330 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21331 line_ptr
+= bytes_read
;
21332 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21335 case DW_LNE_set_discriminator
:
21337 /* The discriminator is not interesting to the
21338 debugger; just ignore it. We still need to
21339 check its value though:
21340 if there are consecutive entries for the same
21341 (non-prologue) line we want to coalesce them.
21344 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21345 line_ptr
+= bytes_read
;
21347 state_machine
.handle_set_discriminator (discr
);
21351 complaint (_("mangled .debug_line section"));
21354 /* Make sure that we parsed the extended op correctly. If e.g.
21355 we expected a different address size than the producer used,
21356 we may have read the wrong number of bytes. */
21357 if (line_ptr
!= extended_end
)
21359 complaint (_("mangled .debug_line section"));
21364 state_machine
.handle_copy ();
21366 case DW_LNS_advance_pc
:
21369 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21370 line_ptr
+= bytes_read
;
21372 state_machine
.handle_advance_pc (adjust
);
21375 case DW_LNS_advance_line
:
21378 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21379 line_ptr
+= bytes_read
;
21381 state_machine
.handle_advance_line (line_delta
);
21384 case DW_LNS_set_file
:
21386 file_name_index file
21387 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21389 line_ptr
+= bytes_read
;
21391 state_machine
.handle_set_file (file
);
21394 case DW_LNS_set_column
:
21395 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21396 line_ptr
+= bytes_read
;
21398 case DW_LNS_negate_stmt
:
21399 state_machine
.handle_negate_stmt ();
21401 case DW_LNS_set_basic_block
:
21403 /* Add to the address register of the state machine the
21404 address increment value corresponding to special opcode
21405 255. I.e., this value is scaled by the minimum
21406 instruction length since special opcode 255 would have
21407 scaled the increment. */
21408 case DW_LNS_const_add_pc
:
21409 state_machine
.handle_const_add_pc ();
21411 case DW_LNS_fixed_advance_pc
:
21413 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21416 state_machine
.handle_fixed_advance_pc (addr_adj
);
21421 /* Unknown standard opcode, ignore it. */
21424 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21426 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21427 line_ptr
+= bytes_read
;
21434 dwarf2_debug_line_missing_end_sequence_complaint ();
21436 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21437 in which case we still finish recording the last line). */
21438 state_machine
.record_line (true);
21442 /* Decode the Line Number Program (LNP) for the given line_header
21443 structure and CU. The actual information extracted and the type
21444 of structures created from the LNP depends on the value of PST.
21446 1. If PST is NULL, then this procedure uses the data from the program
21447 to create all necessary symbol tables, and their linetables.
21449 2. If PST is not NULL, this procedure reads the program to determine
21450 the list of files included by the unit represented by PST, and
21451 builds all the associated partial symbol tables.
21453 FND holds the CU file name and directory, if known.
21454 It is used for relative paths in the line table.
21456 NOTE: It is important that psymtabs have the same file name (via
21457 strcmp) as the corresponding symtab. Since the directory is not
21458 used in the name of the symtab we don't use it in the name of the
21459 psymtabs we create. E.g. expand_line_sal requires this when
21460 finding psymtabs to expand. A good testcase for this is
21463 LOWPC is the lowest address in CU (or 0 if not known).
21465 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21466 for its PC<->lines mapping information. Otherwise only the filename
21467 table is read in. */
21470 dwarf_decode_lines (struct line_header
*lh
, const file_and_directory
&fnd
,
21471 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21472 CORE_ADDR lowpc
, int decode_mapping
)
21474 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21475 const int decode_for_pst_p
= (pst
!= NULL
);
21477 if (decode_mapping
)
21478 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21480 if (decode_for_pst_p
)
21482 /* Now that we're done scanning the Line Header Program, we can
21483 create the psymtab of each included file. */
21484 for (auto &file_entry
: lh
->file_names ())
21485 if (file_entry
.included_p
)
21487 gdb::unique_xmalloc_ptr
<char> name_holder
;
21488 const char *include_name
=
21489 compute_include_file_name (lh
, file_entry
, fnd
, &name_holder
);
21490 if (include_name
!= NULL
)
21491 dwarf2_create_include_psymtab
21492 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21493 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21499 /* Make sure a symtab is created for every file, even files
21500 which contain only variables (i.e. no code with associated
21502 buildsym_compunit
*builder
= cu
->get_builder ();
21503 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21505 for (auto &fe
: lh
->file_names ())
21507 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21508 if (builder
->get_current_subfile ()->symtab
== NULL
)
21510 builder
->get_current_subfile ()->symtab
21511 = allocate_symtab (cust
,
21512 builder
->get_current_subfile ()->name
);
21514 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21519 /* Start a subfile for DWARF. FILENAME is the name of the file and
21520 DIRNAME the name of the source directory which contains FILENAME
21521 or NULL if not known.
21522 This routine tries to keep line numbers from identical absolute and
21523 relative file names in a common subfile.
21525 Using the `list' example from the GDB testsuite, which resides in
21526 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21527 of /srcdir/list0.c yields the following debugging information for list0.c:
21529 DW_AT_name: /srcdir/list0.c
21530 DW_AT_comp_dir: /compdir
21531 files.files[0].name: list0.h
21532 files.files[0].dir: /srcdir
21533 files.files[1].name: list0.c
21534 files.files[1].dir: /srcdir
21536 The line number information for list0.c has to end up in a single
21537 subfile, so that `break /srcdir/list0.c:1' works as expected.
21538 start_subfile will ensure that this happens provided that we pass the
21539 concatenation of files.files[1].dir and files.files[1].name as the
21543 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21544 const char *dirname
)
21546 gdb::unique_xmalloc_ptr
<char> copy
;
21548 /* In order not to lose the line information directory,
21549 we concatenate it to the filename when it makes sense.
21550 Note that the Dwarf3 standard says (speaking of filenames in line
21551 information): ``The directory index is ignored for file names
21552 that represent full path names''. Thus ignoring dirname in the
21553 `else' branch below isn't an issue. */
21555 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21557 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21558 filename
= copy
.get ();
21561 cu
->get_builder ()->start_subfile (filename
);
21565 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21566 struct dwarf2_cu
*cu
)
21568 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21569 struct comp_unit_head
*cu_header
= &cu
->header
;
21571 /* NOTE drow/2003-01-30: There used to be a comment and some special
21572 code here to turn a symbol with DW_AT_external and a
21573 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21574 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21575 with some versions of binutils) where shared libraries could have
21576 relocations against symbols in their debug information - the
21577 minimal symbol would have the right address, but the debug info
21578 would not. It's no longer necessary, because we will explicitly
21579 apply relocations when we read in the debug information now. */
21581 /* A DW_AT_location attribute with no contents indicates that a
21582 variable has been optimized away. */
21583 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21585 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21589 /* Handle one degenerate form of location expression specially, to
21590 preserve GDB's previous behavior when section offsets are
21591 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21592 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21594 if (attr
->form_is_block ())
21596 struct dwarf_block
*block
= attr
->as_block ();
21598 if ((block
->data
[0] == DW_OP_addr
21599 && block
->size
== 1 + cu_header
->addr_size
)
21600 || ((block
->data
[0] == DW_OP_GNU_addr_index
21601 || block
->data
[0] == DW_OP_addrx
)
21603 == 1 + leb128_size (&block
->data
[1]))))
21605 unsigned int dummy
;
21607 if (block
->data
[0] == DW_OP_addr
)
21608 SET_SYMBOL_VALUE_ADDRESS
21609 (sym
, cu
->header
.read_address (objfile
->obfd
,
21613 SET_SYMBOL_VALUE_ADDRESS
21614 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21616 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21617 fixup_symbol_section (sym
, objfile
);
21618 SET_SYMBOL_VALUE_ADDRESS
21620 SYMBOL_VALUE_ADDRESS (sym
)
21621 + objfile
->section_offsets
[sym
->section_index ()]);
21626 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21627 expression evaluator, and use LOC_COMPUTED only when necessary
21628 (i.e. when the value of a register or memory location is
21629 referenced, or a thread-local block, etc.). Then again, it might
21630 not be worthwhile. I'm assuming that it isn't unless performance
21631 or memory numbers show me otherwise. */
21633 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21635 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21636 cu
->has_loclist
= true;
21639 /* Given a pointer to a DWARF information entry, figure out if we need
21640 to make a symbol table entry for it, and if so, create a new entry
21641 and return a pointer to it.
21642 If TYPE is NULL, determine symbol type from the die, otherwise
21643 used the passed type.
21644 If SPACE is not NULL, use it to hold the new symbol. If it is
21645 NULL, allocate a new symbol on the objfile's obstack. */
21647 static struct symbol
*
21648 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21649 struct symbol
*space
)
21651 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21652 struct objfile
*objfile
= per_objfile
->objfile
;
21653 struct gdbarch
*gdbarch
= objfile
->arch ();
21654 struct symbol
*sym
= NULL
;
21656 struct attribute
*attr
= NULL
;
21657 struct attribute
*attr2
= NULL
;
21658 CORE_ADDR baseaddr
;
21659 struct pending
**list_to_add
= NULL
;
21661 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21663 baseaddr
= objfile
->text_section_offset ();
21665 name
= dwarf2_name (die
, cu
);
21668 int suppress_add
= 0;
21673 sym
= new (&objfile
->objfile_obstack
) symbol
;
21674 OBJSTAT (objfile
, n_syms
++);
21676 /* Cache this symbol's name and the name's demangled form (if any). */
21677 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21678 /* Fortran does not have mangling standard and the mangling does differ
21679 between gfortran, iFort etc. */
21680 const char *physname
21681 = (cu
->per_cu
->lang
== language_fortran
21682 ? dwarf2_full_name (name
, die
, cu
)
21683 : dwarf2_physname (name
, die
, cu
));
21684 const char *linkagename
= dw2_linkage_name (die
, cu
);
21686 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21687 sym
->set_linkage_name (physname
);
21690 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21691 sym
->set_linkage_name (linkagename
);
21694 /* Handle DW_AT_artificial. */
21695 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
21696 if (attr
!= nullptr)
21697 sym
->artificial
= attr
->as_boolean ();
21699 /* Default assumptions.
21700 Use the passed type or decode it from the die. */
21701 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21702 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21704 SYMBOL_TYPE (sym
) = type
;
21706 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21707 attr
= dwarf2_attr (die
,
21708 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21710 if (attr
!= nullptr)
21711 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21713 attr
= dwarf2_attr (die
,
21714 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21716 if (attr
!= nullptr && attr
->is_nonnegative ())
21718 file_name_index file_index
21719 = (file_name_index
) attr
->as_nonnegative ();
21720 struct file_entry
*fe
;
21722 if (cu
->line_header
!= NULL
)
21723 fe
= cu
->line_header
->file_name_at (file_index
);
21728 complaint (_("file index out of range"));
21730 symbol_set_symtab (sym
, fe
->symtab
);
21736 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21737 if (attr
!= nullptr)
21741 addr
= attr
->as_address ();
21742 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21743 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21744 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21747 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21748 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21749 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21750 add_symbol_to_list (sym
, cu
->list_in_scope
);
21752 case DW_TAG_subprogram
:
21753 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21755 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21756 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21757 if ((attr2
!= nullptr && attr2
->as_boolean ())
21758 || cu
->per_cu
->lang
== language_ada
21759 || cu
->per_cu
->lang
== language_fortran
)
21761 /* Subprograms marked external are stored as a global symbol.
21762 Ada and Fortran subprograms, whether marked external or
21763 not, are always stored as a global symbol, because we want
21764 to be able to access them globally. For instance, we want
21765 to be able to break on a nested subprogram without having
21766 to specify the context. */
21767 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21771 list_to_add
= cu
->list_in_scope
;
21774 case DW_TAG_inlined_subroutine
:
21775 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21777 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21778 SYMBOL_INLINED (sym
) = 1;
21779 list_to_add
= cu
->list_in_scope
;
21781 case DW_TAG_template_value_param
:
21783 /* Fall through. */
21784 case DW_TAG_constant
:
21785 case DW_TAG_variable
:
21786 case DW_TAG_member
:
21787 /* Compilation with minimal debug info may result in
21788 variables with missing type entries. Change the
21789 misleading `void' type to something sensible. */
21790 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21791 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21793 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21794 /* In the case of DW_TAG_member, we should only be called for
21795 static const members. */
21796 if (die
->tag
== DW_TAG_member
)
21798 /* dwarf2_add_field uses die_is_declaration,
21799 so we do the same. */
21800 gdb_assert (die_is_declaration (die
, cu
));
21803 if (attr
!= nullptr)
21805 dwarf2_const_value (attr
, sym
, cu
);
21806 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21809 if (attr2
!= nullptr && attr2
->as_boolean ())
21810 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21812 list_to_add
= cu
->list_in_scope
;
21816 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21817 if (attr
!= nullptr)
21819 var_decode_location (attr
, sym
, cu
);
21820 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21822 /* Fortran explicitly imports any global symbols to the local
21823 scope by DW_TAG_common_block. */
21824 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21825 && die
->parent
->tag
== DW_TAG_common_block
)
21828 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21829 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21830 && !per_objfile
->per_bfd
->has_section_at_zero
)
21832 /* When a static variable is eliminated by the linker,
21833 the corresponding debug information is not stripped
21834 out, but the variable address is set to null;
21835 do not add such variables into symbol table. */
21837 else if (attr2
!= nullptr && attr2
->as_boolean ())
21839 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21840 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21841 && per_objfile
->per_bfd
->can_copy
)
21843 /* A global static variable might be subject to
21844 copy relocation. We first check for a local
21845 minsym, though, because maybe the symbol was
21846 marked hidden, in which case this would not
21848 bound_minimal_symbol found
21849 = (lookup_minimal_symbol_linkage
21850 (sym
->linkage_name (), objfile
));
21851 if (found
.minsym
!= nullptr)
21852 sym
->maybe_copied
= 1;
21855 /* A variable with DW_AT_external is never static,
21856 but it may be block-scoped. */
21858 = ((cu
->list_in_scope
21859 == cu
->get_builder ()->get_file_symbols ())
21860 ? cu
->get_builder ()->get_global_symbols ()
21861 : cu
->list_in_scope
);
21864 list_to_add
= cu
->list_in_scope
;
21868 /* We do not know the address of this symbol.
21869 If it is an external symbol and we have type information
21870 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21871 The address of the variable will then be determined from
21872 the minimal symbol table whenever the variable is
21874 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21876 /* Fortran explicitly imports any global symbols to the local
21877 scope by DW_TAG_common_block. */
21878 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21879 && die
->parent
->tag
== DW_TAG_common_block
)
21881 /* SYMBOL_CLASS doesn't matter here because
21882 read_common_block is going to reset it. */
21884 list_to_add
= cu
->list_in_scope
;
21886 else if (attr2
!= nullptr && attr2
->as_boolean ()
21887 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21889 /* A variable with DW_AT_external is never static, but it
21890 may be block-scoped. */
21892 = ((cu
->list_in_scope
21893 == cu
->get_builder ()->get_file_symbols ())
21894 ? cu
->get_builder ()->get_global_symbols ()
21895 : cu
->list_in_scope
);
21897 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21899 else if (!die_is_declaration (die
, cu
))
21901 /* Use the default LOC_OPTIMIZED_OUT class. */
21902 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21904 list_to_add
= cu
->list_in_scope
;
21908 case DW_TAG_formal_parameter
:
21910 /* If we are inside a function, mark this as an argument. If
21911 not, we might be looking at an argument to an inlined function
21912 when we do not have enough information to show inlined frames;
21913 pretend it's a local variable in that case so that the user can
21915 struct context_stack
*curr
21916 = cu
->get_builder ()->get_current_context_stack ();
21917 if (curr
!= nullptr && curr
->name
!= nullptr)
21918 SYMBOL_IS_ARGUMENT (sym
) = 1;
21919 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21920 if (attr
!= nullptr)
21922 var_decode_location (attr
, sym
, cu
);
21924 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21925 if (attr
!= nullptr)
21927 dwarf2_const_value (attr
, sym
, cu
);
21930 list_to_add
= cu
->list_in_scope
;
21933 case DW_TAG_unspecified_parameters
:
21934 /* From varargs functions; gdb doesn't seem to have any
21935 interest in this information, so just ignore it for now.
21938 case DW_TAG_template_type_param
:
21940 /* Fall through. */
21941 case DW_TAG_class_type
:
21942 case DW_TAG_interface_type
:
21943 case DW_TAG_structure_type
:
21944 case DW_TAG_union_type
:
21945 case DW_TAG_set_type
:
21946 case DW_TAG_enumeration_type
:
21947 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21948 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21951 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21952 really ever be static objects: otherwise, if you try
21953 to, say, break of a class's method and you're in a file
21954 which doesn't mention that class, it won't work unless
21955 the check for all static symbols in lookup_symbol_aux
21956 saves you. See the OtherFileClass tests in
21957 gdb.c++/namespace.exp. */
21961 buildsym_compunit
*builder
= cu
->get_builder ();
21963 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21964 && cu
->per_cu
->lang
== language_cplus
21965 ? builder
->get_global_symbols ()
21966 : cu
->list_in_scope
);
21968 /* The semantics of C++ state that "struct foo {
21969 ... }" also defines a typedef for "foo". */
21970 if (cu
->per_cu
->lang
== language_cplus
21971 || cu
->per_cu
->lang
== language_ada
21972 || cu
->per_cu
->lang
== language_d
21973 || cu
->per_cu
->lang
== language_rust
)
21975 /* The symbol's name is already allocated along
21976 with this objfile, so we don't need to
21977 duplicate it for the type. */
21978 if (SYMBOL_TYPE (sym
)->name () == 0)
21979 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21984 case DW_TAG_typedef
:
21985 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21986 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21987 list_to_add
= cu
->list_in_scope
;
21989 case DW_TAG_array_type
:
21990 case DW_TAG_base_type
:
21991 case DW_TAG_subrange_type
:
21992 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21993 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21994 list_to_add
= cu
->list_in_scope
;
21996 case DW_TAG_enumerator
:
21997 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21998 if (attr
!= nullptr)
22000 dwarf2_const_value (attr
, sym
, cu
);
22003 /* NOTE: carlton/2003-11-10: See comment above in the
22004 DW_TAG_class_type, etc. block. */
22007 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22008 && cu
->per_cu
->lang
== language_cplus
22009 ? cu
->get_builder ()->get_global_symbols ()
22010 : cu
->list_in_scope
);
22013 case DW_TAG_imported_declaration
:
22014 case DW_TAG_namespace
:
22015 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22016 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22018 case DW_TAG_module
:
22019 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22020 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22021 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22023 case DW_TAG_common_block
:
22024 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22025 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22026 add_symbol_to_list (sym
, cu
->list_in_scope
);
22029 /* Not a tag we recognize. Hopefully we aren't processing
22030 trash data, but since we must specifically ignore things
22031 we don't recognize, there is nothing else we should do at
22033 complaint (_("unsupported tag: '%s'"),
22034 dwarf_tag_name (die
->tag
));
22040 sym
->hash_next
= objfile
->template_symbols
;
22041 objfile
->template_symbols
= sym
;
22042 list_to_add
= NULL
;
22045 if (list_to_add
!= NULL
)
22046 add_symbol_to_list (sym
, list_to_add
);
22048 /* For the benefit of old versions of GCC, check for anonymous
22049 namespaces based on the demangled name. */
22050 if (!cu
->processing_has_namespace_info
22051 && cu
->per_cu
->lang
== language_cplus
)
22052 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22057 /* Given an attr with a DW_FORM_dataN value in host byte order,
22058 zero-extend it as appropriate for the symbol's type. The DWARF
22059 standard (v4) is not entirely clear about the meaning of using
22060 DW_FORM_dataN for a constant with a signed type, where the type is
22061 wider than the data. The conclusion of a discussion on the DWARF
22062 list was that this is unspecified. We choose to always zero-extend
22063 because that is the interpretation long in use by GCC. */
22066 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22067 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22069 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22070 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22071 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22072 LONGEST l
= attr
->constant_value (0);
22074 if (bits
< sizeof (*value
) * 8)
22076 l
&= ((LONGEST
) 1 << bits
) - 1;
22079 else if (bits
== sizeof (*value
) * 8)
22083 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22084 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22091 /* Read a constant value from an attribute. Either set *VALUE, or if
22092 the value does not fit in *VALUE, set *BYTES - either already
22093 allocated on the objfile obstack, or newly allocated on OBSTACK,
22094 or, set *BATON, if we translated the constant to a location
22098 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22099 const char *name
, struct obstack
*obstack
,
22100 struct dwarf2_cu
*cu
,
22101 LONGEST
*value
, const gdb_byte
**bytes
,
22102 struct dwarf2_locexpr_baton
**baton
)
22104 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22105 struct objfile
*objfile
= per_objfile
->objfile
;
22106 struct comp_unit_head
*cu_header
= &cu
->header
;
22107 struct dwarf_block
*blk
;
22108 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22109 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22115 switch (attr
->form
)
22118 case DW_FORM_addrx
:
22119 case DW_FORM_GNU_addr_index
:
22123 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22124 dwarf2_const_value_length_mismatch_complaint (name
,
22125 cu_header
->addr_size
,
22126 TYPE_LENGTH (type
));
22127 /* Symbols of this form are reasonably rare, so we just
22128 piggyback on the existing location code rather than writing
22129 a new implementation of symbol_computed_ops. */
22130 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22131 (*baton
)->per_objfile
= per_objfile
;
22132 (*baton
)->per_cu
= cu
->per_cu
;
22133 gdb_assert ((*baton
)->per_cu
);
22135 (*baton
)->size
= 2 + cu_header
->addr_size
;
22136 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22137 (*baton
)->data
= data
;
22139 data
[0] = DW_OP_addr
;
22140 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22141 byte_order
, attr
->as_address ());
22142 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22145 case DW_FORM_string
:
22148 case DW_FORM_GNU_str_index
:
22149 case DW_FORM_GNU_strp_alt
:
22150 /* The string is already allocated on the objfile obstack, point
22152 *bytes
= (const gdb_byte
*) attr
->as_string ();
22154 case DW_FORM_block1
:
22155 case DW_FORM_block2
:
22156 case DW_FORM_block4
:
22157 case DW_FORM_block
:
22158 case DW_FORM_exprloc
:
22159 case DW_FORM_data16
:
22160 blk
= attr
->as_block ();
22161 if (TYPE_LENGTH (type
) != blk
->size
)
22162 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22163 TYPE_LENGTH (type
));
22164 *bytes
= blk
->data
;
22167 /* The DW_AT_const_value attributes are supposed to carry the
22168 symbol's value "represented as it would be on the target
22169 architecture." By the time we get here, it's already been
22170 converted to host endianness, so we just need to sign- or
22171 zero-extend it as appropriate. */
22172 case DW_FORM_data1
:
22173 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22175 case DW_FORM_data2
:
22176 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22178 case DW_FORM_data4
:
22179 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22181 case DW_FORM_data8
:
22182 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22185 case DW_FORM_sdata
:
22186 case DW_FORM_implicit_const
:
22187 *value
= attr
->as_signed ();
22190 case DW_FORM_udata
:
22191 *value
= attr
->as_unsigned ();
22195 complaint (_("unsupported const value attribute form: '%s'"),
22196 dwarf_form_name (attr
->form
));
22203 /* Copy constant value from an attribute to a symbol. */
22206 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22207 struct dwarf2_cu
*cu
)
22209 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22211 const gdb_byte
*bytes
;
22212 struct dwarf2_locexpr_baton
*baton
;
22214 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22215 sym
->print_name (),
22216 &objfile
->objfile_obstack
, cu
,
22217 &value
, &bytes
, &baton
);
22221 SYMBOL_LOCATION_BATON (sym
) = baton
;
22222 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22224 else if (bytes
!= NULL
)
22226 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22227 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22231 SYMBOL_VALUE (sym
) = value
;
22232 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22236 /* Return the type of the die in question using its DW_AT_type attribute. */
22238 static struct type
*
22239 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22241 struct attribute
*type_attr
;
22243 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22246 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22247 /* A missing DW_AT_type represents a void type. */
22248 return objfile_type (objfile
)->builtin_void
;
22251 return lookup_die_type (die
, type_attr
, cu
);
22254 /* True iff CU's producer generates GNAT Ada auxiliary information
22255 that allows to find parallel types through that information instead
22256 of having to do expensive parallel lookups by type name. */
22259 need_gnat_info (struct dwarf2_cu
*cu
)
22261 /* Assume that the Ada compiler was GNAT, which always produces
22262 the auxiliary information. */
22263 return (cu
->per_cu
->lang
== language_ada
);
22266 /* Return the auxiliary type of the die in question using its
22267 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22268 attribute is not present. */
22270 static struct type
*
22271 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22273 struct attribute
*type_attr
;
22275 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22279 return lookup_die_type (die
, type_attr
, cu
);
22282 /* If DIE has a descriptive_type attribute, then set the TYPE's
22283 descriptive type accordingly. */
22286 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22287 struct dwarf2_cu
*cu
)
22289 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22291 if (descriptive_type
)
22293 ALLOCATE_GNAT_AUX_TYPE (type
);
22294 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22298 /* Return the containing type of the die in question using its
22299 DW_AT_containing_type attribute. */
22301 static struct type
*
22302 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22304 struct attribute
*type_attr
;
22305 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22307 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22309 error (_("Dwarf Error: Problem turning containing type into gdb type "
22310 "[in module %s]"), objfile_name (objfile
));
22312 return lookup_die_type (die
, type_attr
, cu
);
22315 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22317 static struct type
*
22318 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22320 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22321 struct objfile
*objfile
= per_objfile
->objfile
;
22324 std::string message
22325 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22326 objfile_name (objfile
),
22327 sect_offset_str (cu
->header
.sect_off
),
22328 sect_offset_str (die
->sect_off
));
22329 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22331 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22334 /* Look up the type of DIE in CU using its type attribute ATTR.
22335 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22336 DW_AT_containing_type.
22337 If there is no type substitute an error marker. */
22339 static struct type
*
22340 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22341 struct dwarf2_cu
*cu
)
22343 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22344 struct objfile
*objfile
= per_objfile
->objfile
;
22345 struct type
*this_type
;
22347 gdb_assert (attr
->name
== DW_AT_type
22348 || attr
->name
== DW_AT_GNAT_descriptive_type
22349 || attr
->name
== DW_AT_containing_type
);
22351 /* First see if we have it cached. */
22353 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22355 struct dwarf2_per_cu_data
*per_cu
;
22356 sect_offset sect_off
= attr
->get_ref_die_offset ();
22358 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22359 per_objfile
->per_bfd
);
22360 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22362 else if (attr
->form_is_ref ())
22364 sect_offset sect_off
= attr
->get_ref_die_offset ();
22366 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22368 else if (attr
->form
== DW_FORM_ref_sig8
)
22370 ULONGEST signature
= attr
->as_signature ();
22372 return get_signatured_type (die
, signature
, cu
);
22376 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22377 " at %s [in module %s]"),
22378 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22379 objfile_name (objfile
));
22380 return build_error_marker_type (cu
, die
);
22383 /* If not cached we need to read it in. */
22385 if (this_type
== NULL
)
22387 struct die_info
*type_die
= NULL
;
22388 struct dwarf2_cu
*type_cu
= cu
;
22390 if (attr
->form_is_ref ())
22391 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22392 if (type_die
== NULL
)
22393 return build_error_marker_type (cu
, die
);
22394 /* If we find the type now, it's probably because the type came
22395 from an inter-CU reference and the type's CU got expanded before
22397 this_type
= read_type_die (type_die
, type_cu
);
22400 /* If we still don't have a type use an error marker. */
22402 if (this_type
== NULL
)
22403 return build_error_marker_type (cu
, die
);
22408 /* Return the type in DIE, CU.
22409 Returns NULL for invalid types.
22411 This first does a lookup in die_type_hash,
22412 and only reads the die in if necessary.
22414 NOTE: This can be called when reading in partial or full symbols. */
22416 static struct type
*
22417 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22419 struct type
*this_type
;
22421 this_type
= get_die_type (die
, cu
);
22425 return read_type_die_1 (die
, cu
);
22428 /* Read the type in DIE, CU.
22429 Returns NULL for invalid types. */
22431 static struct type
*
22432 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22434 struct type
*this_type
= NULL
;
22438 case DW_TAG_class_type
:
22439 case DW_TAG_interface_type
:
22440 case DW_TAG_structure_type
:
22441 case DW_TAG_union_type
:
22442 this_type
= read_structure_type (die
, cu
);
22444 case DW_TAG_enumeration_type
:
22445 this_type
= read_enumeration_type (die
, cu
);
22447 case DW_TAG_subprogram
:
22448 case DW_TAG_subroutine_type
:
22449 case DW_TAG_inlined_subroutine
:
22450 this_type
= read_subroutine_type (die
, cu
);
22452 case DW_TAG_array_type
:
22453 this_type
= read_array_type (die
, cu
);
22455 case DW_TAG_set_type
:
22456 this_type
= read_set_type (die
, cu
);
22458 case DW_TAG_pointer_type
:
22459 this_type
= read_tag_pointer_type (die
, cu
);
22461 case DW_TAG_ptr_to_member_type
:
22462 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22464 case DW_TAG_reference_type
:
22465 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22467 case DW_TAG_rvalue_reference_type
:
22468 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22470 case DW_TAG_const_type
:
22471 this_type
= read_tag_const_type (die
, cu
);
22473 case DW_TAG_volatile_type
:
22474 this_type
= read_tag_volatile_type (die
, cu
);
22476 case DW_TAG_restrict_type
:
22477 this_type
= read_tag_restrict_type (die
, cu
);
22479 case DW_TAG_string_type
:
22480 this_type
= read_tag_string_type (die
, cu
);
22482 case DW_TAG_typedef
:
22483 this_type
= read_typedef (die
, cu
);
22485 case DW_TAG_subrange_type
:
22486 this_type
= read_subrange_type (die
, cu
);
22488 case DW_TAG_base_type
:
22489 this_type
= read_base_type (die
, cu
);
22491 case DW_TAG_unspecified_type
:
22492 this_type
= read_unspecified_type (die
, cu
);
22494 case DW_TAG_namespace
:
22495 this_type
= read_namespace_type (die
, cu
);
22497 case DW_TAG_module
:
22498 this_type
= read_module_type (die
, cu
);
22500 case DW_TAG_atomic_type
:
22501 this_type
= read_tag_atomic_type (die
, cu
);
22504 complaint (_("unexpected tag in read_type_die: '%s'"),
22505 dwarf_tag_name (die
->tag
));
22512 /* See if we can figure out if the class lives in a namespace. We do
22513 this by looking for a member function; its demangled name will
22514 contain namespace info, if there is any.
22515 Return the computed name or NULL.
22516 Space for the result is allocated on the objfile's obstack.
22517 This is the full-die version of guess_partial_die_structure_name.
22518 In this case we know DIE has no useful parent. */
22520 static const char *
22521 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22523 struct die_info
*spec_die
;
22524 struct dwarf2_cu
*spec_cu
;
22525 struct die_info
*child
;
22526 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22529 spec_die
= die_specification (die
, &spec_cu
);
22530 if (spec_die
!= NULL
)
22536 for (child
= die
->child
;
22538 child
= child
->sibling
)
22540 if (child
->tag
== DW_TAG_subprogram
)
22542 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22544 if (linkage_name
!= NULL
)
22546 gdb::unique_xmalloc_ptr
<char> actual_name
22547 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22548 const char *name
= NULL
;
22550 if (actual_name
!= NULL
)
22552 const char *die_name
= dwarf2_name (die
, cu
);
22554 if (die_name
!= NULL
22555 && strcmp (die_name
, actual_name
.get ()) != 0)
22557 /* Strip off the class name from the full name.
22558 We want the prefix. */
22559 int die_name_len
= strlen (die_name
);
22560 int actual_name_len
= strlen (actual_name
.get ());
22561 const char *ptr
= actual_name
.get ();
22563 /* Test for '::' as a sanity check. */
22564 if (actual_name_len
> die_name_len
+ 2
22565 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22566 name
= obstack_strndup (
22567 &objfile
->per_bfd
->storage_obstack
,
22568 ptr
, actual_name_len
- die_name_len
- 2);
22579 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22580 prefix part in such case. See
22581 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22583 static const char *
22584 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22586 struct attribute
*attr
;
22589 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22590 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22593 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22596 attr
= dw2_linkage_name_attr (die
, cu
);
22597 const char *attr_name
= attr
->as_string ();
22598 if (attr
== NULL
|| attr_name
== NULL
)
22601 /* dwarf2_name had to be already called. */
22602 gdb_assert (attr
->canonical_string_p ());
22604 /* Strip the base name, keep any leading namespaces/classes. */
22605 base
= strrchr (attr_name
, ':');
22606 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22609 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22610 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22612 &base
[-1] - attr_name
);
22615 /* Return the name of the namespace/class that DIE is defined within,
22616 or "" if we can't tell. The caller should not xfree the result.
22618 For example, if we're within the method foo() in the following
22628 then determine_prefix on foo's die will return "N::C". */
22630 static const char *
22631 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22633 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22634 struct die_info
*parent
, *spec_die
;
22635 struct dwarf2_cu
*spec_cu
;
22636 struct type
*parent_type
;
22637 const char *retval
;
22639 if (cu
->per_cu
->lang
!= language_cplus
22640 && cu
->per_cu
->lang
!= language_fortran
22641 && cu
->per_cu
->lang
!= language_d
22642 && cu
->per_cu
->lang
!= language_rust
)
22645 retval
= anonymous_struct_prefix (die
, cu
);
22649 /* We have to be careful in the presence of DW_AT_specification.
22650 For example, with GCC 3.4, given the code
22654 // Definition of N::foo.
22658 then we'll have a tree of DIEs like this:
22660 1: DW_TAG_compile_unit
22661 2: DW_TAG_namespace // N
22662 3: DW_TAG_subprogram // declaration of N::foo
22663 4: DW_TAG_subprogram // definition of N::foo
22664 DW_AT_specification // refers to die #3
22666 Thus, when processing die #4, we have to pretend that we're in
22667 the context of its DW_AT_specification, namely the contex of die
22670 spec_die
= die_specification (die
, &spec_cu
);
22671 if (spec_die
== NULL
)
22672 parent
= die
->parent
;
22675 parent
= spec_die
->parent
;
22679 if (parent
== NULL
)
22681 else if (parent
->building_fullname
)
22684 const char *parent_name
;
22686 /* It has been seen on RealView 2.2 built binaries,
22687 DW_TAG_template_type_param types actually _defined_ as
22688 children of the parent class:
22691 template class <class Enum> Class{};
22692 Class<enum E> class_e;
22694 1: DW_TAG_class_type (Class)
22695 2: DW_TAG_enumeration_type (E)
22696 3: DW_TAG_enumerator (enum1:0)
22697 3: DW_TAG_enumerator (enum2:1)
22699 2: DW_TAG_template_type_param
22700 DW_AT_type DW_FORM_ref_udata (E)
22702 Besides being broken debug info, it can put GDB into an
22703 infinite loop. Consider:
22705 When we're building the full name for Class<E>, we'll start
22706 at Class, and go look over its template type parameters,
22707 finding E. We'll then try to build the full name of E, and
22708 reach here. We're now trying to build the full name of E,
22709 and look over the parent DIE for containing scope. In the
22710 broken case, if we followed the parent DIE of E, we'd again
22711 find Class, and once again go look at its template type
22712 arguments, etc., etc. Simply don't consider such parent die
22713 as source-level parent of this die (it can't be, the language
22714 doesn't allow it), and break the loop here. */
22715 name
= dwarf2_name (die
, cu
);
22716 parent_name
= dwarf2_name (parent
, cu
);
22717 complaint (_("template param type '%s' defined within parent '%s'"),
22718 name
? name
: "<unknown>",
22719 parent_name
? parent_name
: "<unknown>");
22723 switch (parent
->tag
)
22725 case DW_TAG_namespace
:
22726 parent_type
= read_type_die (parent
, cu
);
22727 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22728 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22729 Work around this problem here. */
22730 if (cu
->per_cu
->lang
== language_cplus
22731 && strcmp (parent_type
->name (), "::") == 0)
22733 /* We give a name to even anonymous namespaces. */
22734 return parent_type
->name ();
22735 case DW_TAG_class_type
:
22736 case DW_TAG_interface_type
:
22737 case DW_TAG_structure_type
:
22738 case DW_TAG_union_type
:
22739 case DW_TAG_module
:
22740 parent_type
= read_type_die (parent
, cu
);
22741 if (parent_type
->name () != NULL
)
22742 return parent_type
->name ();
22744 /* An anonymous structure is only allowed non-static data
22745 members; no typedefs, no member functions, et cetera.
22746 So it does not need a prefix. */
22748 case DW_TAG_compile_unit
:
22749 case DW_TAG_partial_unit
:
22750 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22751 if (cu
->per_cu
->lang
== language_cplus
22752 && !per_objfile
->per_bfd
->types
.empty ()
22753 && die
->child
!= NULL
22754 && (die
->tag
== DW_TAG_class_type
22755 || die
->tag
== DW_TAG_structure_type
22756 || die
->tag
== DW_TAG_union_type
))
22758 const char *name
= guess_full_die_structure_name (die
, cu
);
22763 case DW_TAG_subprogram
:
22764 /* Nested subroutines in Fortran get a prefix with the name
22765 of the parent's subroutine. */
22766 if (cu
->per_cu
->lang
== language_fortran
)
22768 if ((die
->tag
== DW_TAG_subprogram
)
22769 && (dwarf2_name (parent
, cu
) != NULL
))
22770 return dwarf2_name (parent
, cu
);
22773 case DW_TAG_enumeration_type
:
22774 parent_type
= read_type_die (parent
, cu
);
22775 if (parent_type
->is_declared_class ())
22777 if (parent_type
->name () != NULL
)
22778 return parent_type
->name ();
22781 /* Fall through. */
22783 return determine_prefix (parent
, cu
);
22787 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22788 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22789 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22790 an obconcat, otherwise allocate storage for the result. The CU argument is
22791 used to determine the language and hence, the appropriate separator. */
22793 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22796 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22797 int physname
, struct dwarf2_cu
*cu
)
22799 const char *lead
= "";
22802 if (suffix
== NULL
|| suffix
[0] == '\0'
22803 || prefix
== NULL
|| prefix
[0] == '\0')
22805 else if (cu
->per_cu
->lang
== language_d
)
22807 /* For D, the 'main' function could be defined in any module, but it
22808 should never be prefixed. */
22809 if (strcmp (suffix
, "D main") == 0)
22817 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22819 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22820 DW_AT_MIPS_linkage_name is preferred and used instead. */
22828 if (prefix
== NULL
)
22830 if (suffix
== NULL
)
22837 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22839 strcpy (retval
, lead
);
22840 strcat (retval
, prefix
);
22841 strcat (retval
, sep
);
22842 strcat (retval
, suffix
);
22847 /* We have an obstack. */
22848 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22852 /* Get name of a die, return NULL if not found. */
22854 static const char *
22855 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22856 struct objfile
*objfile
)
22858 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22860 gdb::unique_xmalloc_ptr
<char> canon_name
22861 = cp_canonicalize_string (name
);
22863 if (canon_name
!= nullptr)
22864 name
= objfile
->intern (canon_name
.get ());
22870 /* Get name of a die, return NULL if not found.
22871 Anonymous namespaces are converted to their magic string. */
22873 static const char *
22874 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22876 struct attribute
*attr
;
22877 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22879 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22880 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22881 if (attr_name
== nullptr
22882 && die
->tag
!= DW_TAG_namespace
22883 && die
->tag
!= DW_TAG_class_type
22884 && die
->tag
!= DW_TAG_interface_type
22885 && die
->tag
!= DW_TAG_structure_type
22886 && die
->tag
!= DW_TAG_union_type
)
22891 case DW_TAG_compile_unit
:
22892 case DW_TAG_partial_unit
:
22893 /* Compilation units have a DW_AT_name that is a filename, not
22894 a source language identifier. */
22895 case DW_TAG_enumeration_type
:
22896 case DW_TAG_enumerator
:
22897 /* These tags always have simple identifiers already; no need
22898 to canonicalize them. */
22901 case DW_TAG_namespace
:
22902 if (attr_name
!= nullptr)
22904 return CP_ANONYMOUS_NAMESPACE_STR
;
22906 case DW_TAG_class_type
:
22907 case DW_TAG_interface_type
:
22908 case DW_TAG_structure_type
:
22909 case DW_TAG_union_type
:
22910 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22911 structures or unions. These were of the form "._%d" in GCC 4.1,
22912 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22913 and GCC 4.4. We work around this problem by ignoring these. */
22914 if (attr_name
!= nullptr
22915 && (startswith (attr_name
, "._")
22916 || startswith (attr_name
, "<anonymous")))
22919 /* GCC might emit a nameless typedef that has a linkage name. See
22920 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22921 if (!attr
|| attr_name
== NULL
)
22923 attr
= dw2_linkage_name_attr (die
, cu
);
22924 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22925 if (attr
== NULL
|| attr_name
== NULL
)
22928 /* Avoid demangling attr_name the second time on a second
22929 call for the same DIE. */
22930 if (!attr
->canonical_string_p ())
22932 gdb::unique_xmalloc_ptr
<char> demangled
22933 (gdb_demangle (attr_name
, DMGL_TYPES
));
22934 if (demangled
== nullptr)
22937 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22938 attr_name
= attr
->as_string ();
22941 /* Strip any leading namespaces/classes, keep only the
22942 base name. DW_AT_name for named DIEs does not
22943 contain the prefixes. */
22944 const char *base
= strrchr (attr_name
, ':');
22945 if (base
&& base
> attr_name
&& base
[-1] == ':')
22956 if (!attr
->canonical_string_p ())
22957 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22959 return attr
->as_string ();
22962 /* Return the die that this die in an extension of, or NULL if there
22963 is none. *EXT_CU is the CU containing DIE on input, and the CU
22964 containing the return value on output. */
22966 static struct die_info
*
22967 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22969 struct attribute
*attr
;
22971 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22975 return follow_die_ref (die
, attr
, ext_cu
);
22979 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22983 fprintf_unfiltered (f
, "%*sDie: %s (abbrev %d, offset %s)\n",
22985 dwarf_tag_name (die
->tag
), die
->abbrev
,
22986 sect_offset_str (die
->sect_off
));
22988 if (die
->parent
!= NULL
)
22989 fprintf_unfiltered (f
, "%*s parent at offset: %s\n",
22991 sect_offset_str (die
->parent
->sect_off
));
22993 fprintf_unfiltered (f
, "%*s has children: %s\n",
22995 dwarf_bool_name (die
->child
!= NULL
));
22997 fprintf_unfiltered (f
, "%*s attributes:\n", indent
, "");
22999 for (i
= 0; i
< die
->num_attrs
; ++i
)
23001 fprintf_unfiltered (f
, "%*s %s (%s) ",
23003 dwarf_attr_name (die
->attrs
[i
].name
),
23004 dwarf_form_name (die
->attrs
[i
].form
));
23006 switch (die
->attrs
[i
].form
)
23009 case DW_FORM_addrx
:
23010 case DW_FORM_GNU_addr_index
:
23011 fprintf_unfiltered (f
, "address: ");
23012 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23014 case DW_FORM_block2
:
23015 case DW_FORM_block4
:
23016 case DW_FORM_block
:
23017 case DW_FORM_block1
:
23018 fprintf_unfiltered (f
, "block: size %s",
23019 pulongest (die
->attrs
[i
].as_block ()->size
));
23021 case DW_FORM_exprloc
:
23022 fprintf_unfiltered (f
, "expression: size %s",
23023 pulongest (die
->attrs
[i
].as_block ()->size
));
23025 case DW_FORM_data16
:
23026 fprintf_unfiltered (f
, "constant of 16 bytes");
23028 case DW_FORM_ref_addr
:
23029 fprintf_unfiltered (f
, "ref address: ");
23030 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23032 case DW_FORM_GNU_ref_alt
:
23033 fprintf_unfiltered (f
, "alt ref address: ");
23034 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23040 case DW_FORM_ref_udata
:
23041 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23042 (long) (die
->attrs
[i
].as_unsigned ()));
23044 case DW_FORM_data1
:
23045 case DW_FORM_data2
:
23046 case DW_FORM_data4
:
23047 case DW_FORM_data8
:
23048 case DW_FORM_udata
:
23049 fprintf_unfiltered (f
, "constant: %s",
23050 pulongest (die
->attrs
[i
].as_unsigned ()));
23052 case DW_FORM_sec_offset
:
23053 fprintf_unfiltered (f
, "section offset: %s",
23054 pulongest (die
->attrs
[i
].as_unsigned ()));
23056 case DW_FORM_ref_sig8
:
23057 fprintf_unfiltered (f
, "signature: %s",
23058 hex_string (die
->attrs
[i
].as_signature ()));
23060 case DW_FORM_string
:
23062 case DW_FORM_line_strp
:
23064 case DW_FORM_GNU_str_index
:
23065 case DW_FORM_GNU_strp_alt
:
23066 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23067 die
->attrs
[i
].as_string ()
23068 ? die
->attrs
[i
].as_string () : "",
23069 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23072 if (die
->attrs
[i
].as_boolean ())
23073 fprintf_unfiltered (f
, "flag: TRUE");
23075 fprintf_unfiltered (f
, "flag: FALSE");
23077 case DW_FORM_flag_present
:
23078 fprintf_unfiltered (f
, "flag: TRUE");
23080 case DW_FORM_indirect
:
23081 /* The reader will have reduced the indirect form to
23082 the "base form" so this form should not occur. */
23083 fprintf_unfiltered (f
,
23084 "unexpected attribute form: DW_FORM_indirect");
23086 case DW_FORM_sdata
:
23087 case DW_FORM_implicit_const
:
23088 fprintf_unfiltered (f
, "constant: %s",
23089 plongest (die
->attrs
[i
].as_signed ()));
23092 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23093 die
->attrs
[i
].form
);
23096 fprintf_unfiltered (f
, "\n");
23101 dump_die_for_error (struct die_info
*die
)
23103 dump_die_shallow (gdb_stderr
, 0, die
);
23107 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23109 int indent
= level
* 4;
23111 gdb_assert (die
!= NULL
);
23113 if (level
>= max_level
)
23116 dump_die_shallow (f
, indent
, die
);
23118 if (die
->child
!= NULL
)
23120 fprintf_unfiltered (f
, "%*s Children:", indent
, "");
23121 if (level
+ 1 < max_level
)
23123 fprintf_unfiltered (f
, "\n");
23124 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23128 fprintf_unfiltered (f
,
23129 " [not printed, max nesting level reached]\n");
23133 if (die
->sibling
!= NULL
&& level
> 0)
23135 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23139 /* This is called from the pdie macro in gdbinit.in.
23140 It's not static so gcc will keep a copy callable from gdb. */
23143 dump_die (struct die_info
*die
, int max_level
)
23145 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23149 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23153 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23154 to_underlying (die
->sect_off
),
23160 /* Follow reference or signature attribute ATTR of SRC_DIE.
23161 On entry *REF_CU is the CU of SRC_DIE.
23162 On exit *REF_CU is the CU of the result. */
23164 static struct die_info
*
23165 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23166 struct dwarf2_cu
**ref_cu
)
23168 struct die_info
*die
;
23170 if (attr
->form_is_ref ())
23171 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23172 else if (attr
->form
== DW_FORM_ref_sig8
)
23173 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23176 dump_die_for_error (src_die
);
23177 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23178 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23184 /* Follow reference OFFSET.
23185 On entry *REF_CU is the CU of the source die referencing OFFSET.
23186 On exit *REF_CU is the CU of the result.
23187 Returns NULL if OFFSET is invalid. */
23189 static struct die_info
*
23190 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23191 struct dwarf2_cu
**ref_cu
)
23193 struct die_info temp_die
;
23194 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23195 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23197 gdb_assert (cu
->per_cu
!= NULL
);
23201 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23202 "source CU contains target offset: %d",
23203 sect_offset_str (cu
->per_cu
->sect_off
),
23204 sect_offset_str (sect_off
),
23205 cu
->header
.offset_in_cu_p (sect_off
));
23207 if (cu
->per_cu
->is_debug_types
)
23209 /* .debug_types CUs cannot reference anything outside their CU.
23210 If they need to, they have to reference a signatured type via
23211 DW_FORM_ref_sig8. */
23212 if (!cu
->header
.offset_in_cu_p (sect_off
))
23215 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23216 || !cu
->header
.offset_in_cu_p (sect_off
))
23218 struct dwarf2_per_cu_data
*per_cu
;
23220 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23221 per_objfile
->per_bfd
);
23223 dwarf_read_debug_printf_v ("target CU offset: %s, "
23224 "target CU DIEs loaded: %d",
23225 sect_offset_str (per_cu
->sect_off
),
23226 per_objfile
->get_cu (per_cu
) != nullptr);
23228 /* If necessary, add it to the queue and load its DIEs.
23230 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23231 it doesn't mean they are currently loaded. Since we require them
23232 to be loaded, we must check for ourselves. */
23233 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23234 || per_objfile
->get_cu (per_cu
) == nullptr)
23235 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23236 false, cu
->per_cu
->lang
);
23238 target_cu
= per_objfile
->get_cu (per_cu
);
23239 gdb_assert (target_cu
!= nullptr);
23241 else if (cu
->dies
== NULL
)
23243 /* We're loading full DIEs during partial symbol reading. */
23244 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23245 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23249 *ref_cu
= target_cu
;
23250 temp_die
.sect_off
= sect_off
;
23252 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23254 to_underlying (sect_off
));
23257 /* Follow reference attribute ATTR of SRC_DIE.
23258 On entry *REF_CU is the CU of SRC_DIE.
23259 On exit *REF_CU is the CU of the result. */
23261 static struct die_info
*
23262 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23263 struct dwarf2_cu
**ref_cu
)
23265 sect_offset sect_off
= attr
->get_ref_die_offset ();
23266 struct dwarf2_cu
*cu
= *ref_cu
;
23267 struct die_info
*die
;
23269 die
= follow_die_offset (sect_off
,
23270 (attr
->form
== DW_FORM_GNU_ref_alt
23271 || cu
->per_cu
->is_dwz
),
23274 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23275 "at %s [in module %s]"),
23276 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23277 objfile_name (cu
->per_objfile
->objfile
));
23284 struct dwarf2_locexpr_baton
23285 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23286 dwarf2_per_cu_data
*per_cu
,
23287 dwarf2_per_objfile
*per_objfile
,
23288 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23289 bool resolve_abstract_p
)
23291 struct die_info
*die
;
23292 struct attribute
*attr
;
23293 struct dwarf2_locexpr_baton retval
;
23294 struct objfile
*objfile
= per_objfile
->objfile
;
23296 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23298 cu
= load_cu (per_cu
, per_objfile
, false);
23302 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23303 Instead just throw an error, not much else we can do. */
23304 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23305 sect_offset_str (sect_off
), objfile_name (objfile
));
23308 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23310 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23311 sect_offset_str (sect_off
), objfile_name (objfile
));
23313 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23314 if (!attr
&& resolve_abstract_p
23315 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23316 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23318 CORE_ADDR pc
= get_frame_pc ();
23319 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23320 struct gdbarch
*gdbarch
= objfile
->arch ();
23322 for (const auto &cand_off
23323 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23325 struct dwarf2_cu
*cand_cu
= cu
;
23326 struct die_info
*cand
23327 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23330 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23333 CORE_ADDR pc_low
, pc_high
;
23334 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23335 if (pc_low
== ((CORE_ADDR
) -1))
23337 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23338 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23339 if (!(pc_low
<= pc
&& pc
< pc_high
))
23343 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23350 /* DWARF: "If there is no such attribute, then there is no effect.".
23351 DATA is ignored if SIZE is 0. */
23353 retval
.data
= NULL
;
23356 else if (attr
->form_is_section_offset ())
23358 struct dwarf2_loclist_baton loclist_baton
;
23359 CORE_ADDR pc
= get_frame_pc ();
23362 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23364 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23366 retval
.size
= size
;
23370 if (!attr
->form_is_block ())
23371 error (_("Dwarf Error: DIE at %s referenced in module %s "
23372 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23373 sect_offset_str (sect_off
), objfile_name (objfile
));
23375 struct dwarf_block
*block
= attr
->as_block ();
23376 retval
.data
= block
->data
;
23377 retval
.size
= block
->size
;
23379 retval
.per_objfile
= per_objfile
;
23380 retval
.per_cu
= cu
->per_cu
;
23382 per_objfile
->age_comp_units ();
23389 struct dwarf2_locexpr_baton
23390 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23391 dwarf2_per_cu_data
*per_cu
,
23392 dwarf2_per_objfile
*per_objfile
,
23393 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23395 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23397 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23401 /* Write a constant of a given type as target-ordered bytes into
23404 static const gdb_byte
*
23405 write_constant_as_bytes (struct obstack
*obstack
,
23406 enum bfd_endian byte_order
,
23413 *len
= TYPE_LENGTH (type
);
23414 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23415 store_unsigned_integer (result
, *len
, byte_order
, value
);
23423 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23424 dwarf2_per_cu_data
*per_cu
,
23425 dwarf2_per_objfile
*per_objfile
,
23429 struct die_info
*die
;
23430 struct attribute
*attr
;
23431 const gdb_byte
*result
= NULL
;
23434 enum bfd_endian byte_order
;
23435 struct objfile
*objfile
= per_objfile
->objfile
;
23437 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23439 cu
= load_cu (per_cu
, per_objfile
, false);
23443 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23444 Instead just throw an error, not much else we can do. */
23445 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23446 sect_offset_str (sect_off
), objfile_name (objfile
));
23449 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23451 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23452 sect_offset_str (sect_off
), objfile_name (objfile
));
23454 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23458 byte_order
= (bfd_big_endian (objfile
->obfd
)
23459 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23461 switch (attr
->form
)
23464 case DW_FORM_addrx
:
23465 case DW_FORM_GNU_addr_index
:
23469 *len
= cu
->header
.addr_size
;
23470 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23471 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23475 case DW_FORM_string
:
23478 case DW_FORM_GNU_str_index
:
23479 case DW_FORM_GNU_strp_alt
:
23480 /* The string is already allocated on the objfile obstack, point
23483 const char *attr_name
= attr
->as_string ();
23484 result
= (const gdb_byte
*) attr_name
;
23485 *len
= strlen (attr_name
);
23488 case DW_FORM_block1
:
23489 case DW_FORM_block2
:
23490 case DW_FORM_block4
:
23491 case DW_FORM_block
:
23492 case DW_FORM_exprloc
:
23493 case DW_FORM_data16
:
23495 struct dwarf_block
*block
= attr
->as_block ();
23496 result
= block
->data
;
23497 *len
= block
->size
;
23501 /* The DW_AT_const_value attributes are supposed to carry the
23502 symbol's value "represented as it would be on the target
23503 architecture." By the time we get here, it's already been
23504 converted to host endianness, so we just need to sign- or
23505 zero-extend it as appropriate. */
23506 case DW_FORM_data1
:
23507 type
= die_type (die
, cu
);
23508 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23509 if (result
== NULL
)
23510 result
= write_constant_as_bytes (obstack
, byte_order
,
23513 case DW_FORM_data2
:
23514 type
= die_type (die
, cu
);
23515 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23516 if (result
== NULL
)
23517 result
= write_constant_as_bytes (obstack
, byte_order
,
23520 case DW_FORM_data4
:
23521 type
= die_type (die
, cu
);
23522 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23523 if (result
== NULL
)
23524 result
= write_constant_as_bytes (obstack
, byte_order
,
23527 case DW_FORM_data8
:
23528 type
= die_type (die
, cu
);
23529 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23530 if (result
== NULL
)
23531 result
= write_constant_as_bytes (obstack
, byte_order
,
23535 case DW_FORM_sdata
:
23536 case DW_FORM_implicit_const
:
23537 type
= die_type (die
, cu
);
23538 result
= write_constant_as_bytes (obstack
, byte_order
,
23539 type
, attr
->as_signed (), len
);
23542 case DW_FORM_udata
:
23543 type
= die_type (die
, cu
);
23544 result
= write_constant_as_bytes (obstack
, byte_order
,
23545 type
, attr
->as_unsigned (), len
);
23549 complaint (_("unsupported const value attribute form: '%s'"),
23550 dwarf_form_name (attr
->form
));
23560 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23561 dwarf2_per_cu_data
*per_cu
,
23562 dwarf2_per_objfile
*per_objfile
,
23563 const char **var_name
)
23565 struct die_info
*die
;
23567 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23569 cu
= load_cu (per_cu
, per_objfile
, false);
23574 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23578 if (var_name
!= nullptr)
23579 *var_name
= var_decl_name (die
, cu
);
23580 return die_type (die
, cu
);
23586 dwarf2_get_die_type (cu_offset die_offset
,
23587 dwarf2_per_cu_data
*per_cu
,
23588 dwarf2_per_objfile
*per_objfile
)
23590 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23591 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23594 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23595 On entry *REF_CU is the CU of SRC_DIE.
23596 On exit *REF_CU is the CU of the result.
23597 Returns NULL if the referenced DIE isn't found. */
23599 static struct die_info
*
23600 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23601 struct dwarf2_cu
**ref_cu
)
23603 struct die_info temp_die
;
23604 struct dwarf2_cu
*sig_cu
;
23605 struct die_info
*die
;
23606 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23609 /* While it might be nice to assert sig_type->type == NULL here,
23610 we can get here for DW_AT_imported_declaration where we need
23611 the DIE not the type. */
23613 /* If necessary, add it to the queue and load its DIEs.
23615 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23616 it doesn't mean they are currently loaded. Since we require them
23617 to be loaded, we must check for ourselves. */
23618 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23620 || per_objfile
->get_cu (sig_type
) == nullptr)
23621 read_signatured_type (sig_type
, per_objfile
);
23623 sig_cu
= per_objfile
->get_cu (sig_type
);
23624 gdb_assert (sig_cu
!= NULL
);
23625 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23626 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23627 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23628 to_underlying (temp_die
.sect_off
));
23631 /* For .gdb_index version 7 keep track of included TUs.
23632 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23633 if (per_objfile
->per_bfd
->index_table
!= NULL
23634 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23636 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23646 /* Follow signatured type referenced by ATTR in SRC_DIE.
23647 On entry *REF_CU is the CU of SRC_DIE.
23648 On exit *REF_CU is the CU of the result.
23649 The result is the DIE of the type.
23650 If the referenced type cannot be found an error is thrown. */
23652 static struct die_info
*
23653 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23654 struct dwarf2_cu
**ref_cu
)
23656 ULONGEST signature
= attr
->as_signature ();
23657 struct signatured_type
*sig_type
;
23658 struct die_info
*die
;
23660 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23662 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23663 /* sig_type will be NULL if the signatured type is missing from
23665 if (sig_type
== NULL
)
23667 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23668 " from DIE at %s [in module %s]"),
23669 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23670 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23673 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23676 dump_die_for_error (src_die
);
23677 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23678 " from DIE at %s [in module %s]"),
23679 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23680 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23686 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23687 reading in and processing the type unit if necessary. */
23689 static struct type
*
23690 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23691 struct dwarf2_cu
*cu
)
23693 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23694 struct signatured_type
*sig_type
;
23695 struct dwarf2_cu
*type_cu
;
23696 struct die_info
*type_die
;
23699 sig_type
= lookup_signatured_type (cu
, signature
);
23700 /* sig_type will be NULL if the signatured type is missing from
23702 if (sig_type
== NULL
)
23704 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23705 " from DIE at %s [in module %s]"),
23706 hex_string (signature
), sect_offset_str (die
->sect_off
),
23707 objfile_name (per_objfile
->objfile
));
23708 return build_error_marker_type (cu
, die
);
23711 /* If we already know the type we're done. */
23712 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23713 if (type
!= nullptr)
23717 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23718 if (type_die
!= NULL
)
23720 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23721 is created. This is important, for example, because for c++ classes
23722 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23723 type
= read_type_die (type_die
, type_cu
);
23726 complaint (_("Dwarf Error: Cannot build signatured type %s"
23727 " referenced from DIE at %s [in module %s]"),
23728 hex_string (signature
), sect_offset_str (die
->sect_off
),
23729 objfile_name (per_objfile
->objfile
));
23730 type
= build_error_marker_type (cu
, die
);
23735 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23736 " from DIE at %s [in module %s]"),
23737 hex_string (signature
), sect_offset_str (die
->sect_off
),
23738 objfile_name (per_objfile
->objfile
));
23739 type
= build_error_marker_type (cu
, die
);
23742 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23747 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23748 reading in and processing the type unit if necessary. */
23750 static struct type
*
23751 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23752 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23754 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23755 if (attr
->form_is_ref ())
23757 struct dwarf2_cu
*type_cu
= cu
;
23758 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23760 return read_type_die (type_die
, type_cu
);
23762 else if (attr
->form
== DW_FORM_ref_sig8
)
23764 return get_signatured_type (die
, attr
->as_signature (), cu
);
23768 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23770 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23771 " at %s [in module %s]"),
23772 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23773 objfile_name (per_objfile
->objfile
));
23774 return build_error_marker_type (cu
, die
);
23778 /* Load the DIEs associated with type unit PER_CU into memory. */
23781 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23782 dwarf2_per_objfile
*per_objfile
)
23784 struct signatured_type
*sig_type
;
23786 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23787 gdb_assert (! per_cu
->type_unit_group_p ());
23789 /* We have the per_cu, but we need the signatured_type.
23790 Fortunately this is an easy translation. */
23791 gdb_assert (per_cu
->is_debug_types
);
23792 sig_type
= (struct signatured_type
*) per_cu
;
23794 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23796 read_signatured_type (sig_type
, per_objfile
);
23798 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23801 /* Read in a signatured type and build its CU and DIEs.
23802 If the type is a stub for the real type in a DWO file,
23803 read in the real type from the DWO file as well. */
23806 read_signatured_type (signatured_type
*sig_type
,
23807 dwarf2_per_objfile
*per_objfile
)
23809 gdb_assert (sig_type
->is_debug_types
);
23810 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23812 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23814 if (!reader
.dummy_p
)
23816 struct dwarf2_cu
*cu
= reader
.cu
;
23817 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23819 gdb_assert (cu
->die_hash
== NULL
);
23821 htab_create_alloc_ex (cu
->header
.length
/ 12,
23825 &cu
->comp_unit_obstack
,
23826 hashtab_obstack_allocate
,
23827 dummy_obstack_deallocate
);
23829 if (reader
.comp_unit_die
->has_children
)
23830 reader
.comp_unit_die
->child
23831 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23832 reader
.comp_unit_die
);
23833 cu
->dies
= reader
.comp_unit_die
;
23834 /* comp_unit_die is not stored in die_hash, no need. */
23836 /* We try not to read any attributes in this function, because
23837 not all CUs needed for references have been loaded yet, and
23838 symbol table processing isn't initialized. But we have to
23839 set the CU language, or we won't be able to build types
23840 correctly. Similarly, if we do not read the producer, we can
23841 not apply producer-specific interpretation. */
23842 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23847 sig_type
->tu_read
= 1;
23850 /* Decode simple location descriptions.
23851 Given a pointer to a dwarf block that defines a location, compute
23852 the location and return the value. If COMPUTED is non-null, it is
23853 set to true to indicate that decoding was successful, and false
23854 otherwise. If COMPUTED is null, then this function may emit a
23858 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23860 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23862 size_t size
= blk
->size
;
23863 const gdb_byte
*data
= blk
->data
;
23864 CORE_ADDR stack
[64];
23866 unsigned int bytes_read
, unsnd
;
23869 if (computed
!= nullptr)
23875 stack
[++stacki
] = 0;
23914 stack
[++stacki
] = op
- DW_OP_lit0
;
23949 stack
[++stacki
] = op
- DW_OP_reg0
;
23952 if (computed
== nullptr)
23953 dwarf2_complex_location_expr_complaint ();
23960 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23962 stack
[++stacki
] = unsnd
;
23965 if (computed
== nullptr)
23966 dwarf2_complex_location_expr_complaint ();
23973 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23978 case DW_OP_const1u
:
23979 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23983 case DW_OP_const1s
:
23984 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23988 case DW_OP_const2u
:
23989 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23993 case DW_OP_const2s
:
23994 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23998 case DW_OP_const4u
:
23999 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24003 case DW_OP_const4s
:
24004 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24008 case DW_OP_const8u
:
24009 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24014 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24020 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24025 stack
[stacki
+ 1] = stack
[stacki
];
24030 stack
[stacki
- 1] += stack
[stacki
];
24034 case DW_OP_plus_uconst
:
24035 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24041 stack
[stacki
- 1] -= stack
[stacki
];
24046 /* If we're not the last op, then we definitely can't encode
24047 this using GDB's address_class enum. This is valid for partial
24048 global symbols, although the variable's address will be bogus
24052 if (computed
== nullptr)
24053 dwarf2_complex_location_expr_complaint ();
24059 case DW_OP_GNU_push_tls_address
:
24060 case DW_OP_form_tls_address
:
24061 /* The top of the stack has the offset from the beginning
24062 of the thread control block at which the variable is located. */
24063 /* Nothing should follow this operator, so the top of stack would
24065 /* This is valid for partial global symbols, but the variable's
24066 address will be bogus in the psymtab. Make it always at least
24067 non-zero to not look as a variable garbage collected by linker
24068 which have DW_OP_addr 0. */
24071 if (computed
== nullptr)
24072 dwarf2_complex_location_expr_complaint ();
24079 case DW_OP_GNU_uninit
:
24080 if (computed
!= nullptr)
24085 case DW_OP_GNU_addr_index
:
24086 case DW_OP_GNU_const_index
:
24087 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24093 if (computed
== nullptr)
24095 const char *name
= get_DW_OP_name (op
);
24098 complaint (_("unsupported stack op: '%s'"),
24101 complaint (_("unsupported stack op: '%02x'"),
24105 return (stack
[stacki
]);
24108 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24109 outside of the allocated space. Also enforce minimum>0. */
24110 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24112 if (computed
== nullptr)
24113 complaint (_("location description stack overflow"));
24119 if (computed
== nullptr)
24120 complaint (_("location description stack underflow"));
24125 if (computed
!= nullptr)
24127 return (stack
[stacki
]);
24130 /* memory allocation interface */
24132 static struct dwarf_block
*
24133 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24135 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24138 static struct die_info
*
24139 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24141 struct die_info
*die
;
24142 size_t size
= sizeof (struct die_info
);
24145 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24147 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24148 memset (die
, 0, sizeof (struct die_info
));
24154 /* Macro support. */
24156 /* An overload of dwarf_decode_macros that finds the correct section
24157 and ensures it is read in before calling the other overload. */
24160 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24161 int section_is_gnu
)
24163 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24164 struct objfile
*objfile
= per_objfile
->objfile
;
24165 const struct line_header
*lh
= cu
->line_header
;
24166 unsigned int offset_size
= cu
->header
.offset_size
;
24167 struct dwarf2_section_info
*section
;
24168 const char *section_name
;
24170 if (cu
->dwo_unit
!= nullptr)
24172 if (section_is_gnu
)
24174 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24175 section_name
= ".debug_macro.dwo";
24179 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24180 section_name
= ".debug_macinfo.dwo";
24185 if (section_is_gnu
)
24187 section
= &per_objfile
->per_bfd
->macro
;
24188 section_name
= ".debug_macro";
24192 section
= &per_objfile
->per_bfd
->macinfo
;
24193 section_name
= ".debug_macinfo";
24197 section
->read (objfile
);
24198 if (section
->buffer
== nullptr)
24200 complaint (_("missing %s section"), section_name
);
24204 buildsym_compunit
*builder
= cu
->get_builder ();
24206 struct dwarf2_section_info
*str_offsets_section
;
24207 struct dwarf2_section_info
*str_section
;
24208 gdb::optional
<ULONGEST
> str_offsets_base
;
24210 if (cu
->dwo_unit
!= nullptr)
24212 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24213 ->sections
.str_offsets
;
24214 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24215 str_offsets_base
= cu
->header
.addr_size
;
24219 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24220 str_section
= &per_objfile
->per_bfd
->str
;
24221 str_offsets_base
= cu
->str_offsets_base
;
24224 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24225 offset_size
, offset
, str_section
, str_offsets_section
,
24226 str_offsets_base
, section_is_gnu
);
24229 /* Return the .debug_loc section to use for CU.
24230 For DWO files use .debug_loc.dwo. */
24232 static struct dwarf2_section_info
*
24233 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24235 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24239 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24241 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24243 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24244 : &per_objfile
->per_bfd
->loc
);
24247 /* Return the .debug_rnglists section to use for CU. */
24248 static struct dwarf2_section_info
*
24249 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24251 if (cu
->header
.version
< 5)
24252 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24253 cu
->header
.version
);
24254 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24256 /* Make sure we read the .debug_rnglists section from the file that
24257 contains the DW_AT_ranges attribute we are reading. Normally that
24258 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24259 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24261 if (cu
->dwo_unit
!= nullptr
24262 && tag
!= DW_TAG_compile_unit
24263 && tag
!= DW_TAG_skeleton_unit
)
24265 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24267 if (sections
->rnglists
.size
> 0)
24268 return §ions
->rnglists
;
24270 error (_(".debug_rnglists section is missing from .dwo file."));
24272 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24275 /* A helper function that fills in a dwarf2_loclist_baton. */
24278 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24279 struct dwarf2_loclist_baton
*baton
,
24280 const struct attribute
*attr
)
24282 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24283 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24285 section
->read (per_objfile
->objfile
);
24287 baton
->per_objfile
= per_objfile
;
24288 baton
->per_cu
= cu
->per_cu
;
24289 gdb_assert (baton
->per_cu
);
24290 /* We don't know how long the location list is, but make sure we
24291 don't run off the edge of the section. */
24292 baton
->size
= section
->size
- attr
->as_unsigned ();
24293 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24294 if (cu
->base_address
.has_value ())
24295 baton
->base_address
= *cu
->base_address
;
24297 baton
->base_address
= 0;
24298 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24302 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24303 struct dwarf2_cu
*cu
, int is_block
)
24305 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24306 struct objfile
*objfile
= per_objfile
->objfile
;
24307 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24309 if (attr
->form_is_section_offset ()
24310 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24311 the section. If so, fall through to the complaint in the
24313 && attr
->as_unsigned () < section
->get_size (objfile
))
24315 struct dwarf2_loclist_baton
*baton
;
24317 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24319 fill_in_loclist_baton (cu
, baton
, attr
);
24321 if (!cu
->base_address
.has_value ())
24322 complaint (_("Location list used without "
24323 "specifying the CU base address."));
24325 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24326 ? dwarf2_loclist_block_index
24327 : dwarf2_loclist_index
);
24328 SYMBOL_LOCATION_BATON (sym
) = baton
;
24332 struct dwarf2_locexpr_baton
*baton
;
24334 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24335 baton
->per_objfile
= per_objfile
;
24336 baton
->per_cu
= cu
->per_cu
;
24337 gdb_assert (baton
->per_cu
);
24339 if (attr
->form_is_block ())
24341 /* Note that we're just copying the block's data pointer
24342 here, not the actual data. We're still pointing into the
24343 info_buffer for SYM's objfile; right now we never release
24344 that buffer, but when we do clean up properly this may
24346 struct dwarf_block
*block
= attr
->as_block ();
24347 baton
->size
= block
->size
;
24348 baton
->data
= block
->data
;
24352 dwarf2_invalid_attrib_class_complaint ("location description",
24353 sym
->natural_name ());
24357 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24358 ? dwarf2_locexpr_block_index
24359 : dwarf2_locexpr_index
);
24360 SYMBOL_LOCATION_BATON (sym
) = baton
;
24366 const comp_unit_head
*
24367 dwarf2_per_cu_data::get_header () const
24369 if (!m_header_read_in
)
24371 const gdb_byte
*info_ptr
24372 = this->section
->buffer
+ to_underlying (this->sect_off
);
24374 memset (&m_header
, 0, sizeof (m_header
));
24376 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24377 rcuh_kind::COMPILE
);
24379 m_header_read_in
= true;
24388 dwarf2_per_cu_data::addr_size () const
24390 return this->get_header ()->addr_size
;
24396 dwarf2_per_cu_data::offset_size () const
24398 return this->get_header ()->offset_size
;
24404 dwarf2_per_cu_data::ref_addr_size () const
24406 const comp_unit_head
*header
= this->get_header ();
24408 if (header
->version
== 2)
24409 return header
->addr_size
;
24411 return header
->offset_size
;
24414 /* A helper function for dwarf2_find_containing_comp_unit that returns
24415 the index of the result, and that searches a vector. It will
24416 return a result even if the offset in question does not actually
24417 occur in any CU. This is separate so that it can be unit
24421 dwarf2_find_containing_comp_unit
24422 (sect_offset sect_off
,
24423 unsigned int offset_in_dwz
,
24424 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24429 high
= all_comp_units
.size () - 1;
24432 struct dwarf2_per_cu_data
*mid_cu
;
24433 int mid
= low
+ (high
- low
) / 2;
24435 mid_cu
= all_comp_units
[mid
].get ();
24436 if (mid_cu
->is_dwz
> offset_in_dwz
24437 || (mid_cu
->is_dwz
== offset_in_dwz
24438 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24443 gdb_assert (low
== high
);
24447 /* Locate the .debug_info compilation unit from CU's objfile which contains
24448 the DIE at OFFSET. Raises an error on failure. */
24450 static struct dwarf2_per_cu_data
*
24451 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24452 unsigned int offset_in_dwz
,
24453 dwarf2_per_bfd
*per_bfd
)
24455 int low
= dwarf2_find_containing_comp_unit
24456 (sect_off
, offset_in_dwz
, per_bfd
->all_comp_units
);
24457 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_comp_units
[low
].get ();
24459 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24461 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24462 error (_("Dwarf Error: could not find partial DIE containing "
24463 "offset %s [in module %s]"),
24464 sect_offset_str (sect_off
),
24465 bfd_get_filename (per_bfd
->obfd
));
24467 gdb_assert (per_bfd
->all_comp_units
[low
-1]->sect_off
24469 return per_bfd
->all_comp_units
[low
- 1].get ();
24473 if (low
== per_bfd
->all_comp_units
.size () - 1
24474 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24475 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24476 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24483 namespace selftests
{
24484 namespace find_containing_comp_unit
{
24489 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24490 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24491 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24492 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24493 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24494 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24495 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24496 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24499 two
->sect_off
= sect_offset (one
->length
);
24504 four
->sect_off
= sect_offset (three
->length
);
24508 std::vector
<dwarf2_per_cu_data_up
> units
;
24509 units
.push_back (std::move (one
));
24510 units
.push_back (std::move (two
));
24511 units
.push_back (std::move (three
));
24512 units
.push_back (std::move (four
));
24516 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24517 SELF_CHECK (units
[result
].get () == one_ptr
);
24518 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24519 SELF_CHECK (units
[result
].get () == one_ptr
);
24520 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24521 SELF_CHECK (units
[result
].get () == two_ptr
);
24523 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24524 SELF_CHECK (units
[result
].get () == three_ptr
);
24525 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24526 SELF_CHECK (units
[result
].get () == three_ptr
);
24527 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24528 SELF_CHECK (units
[result
].get () == four_ptr
);
24534 #endif /* GDB_SELF_TEST */
24536 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24539 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24540 enum language pretend_language
)
24542 struct attribute
*attr
;
24544 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24546 /* Set the language we're debugging. */
24547 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24548 if (cu
->producer
!= nullptr
24549 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24551 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24552 attribute is not standardised yet. As a workaround for the
24553 language detection we fall back to the DW_AT_producer
24555 cu
->per_cu
->lang
= language_opencl
;
24557 else if (cu
->producer
!= nullptr
24558 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24560 /* Similar hack for Go. */
24561 cu
->per_cu
->lang
= language_go
;
24563 else if (attr
!= nullptr)
24564 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24566 cu
->per_cu
->lang
= pretend_language
;
24567 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24573 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24575 auto it
= m_dwarf2_cus
.find (per_cu
);
24576 if (it
== m_dwarf2_cus
.end ())
24585 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24587 gdb_assert (this->get_cu (per_cu
) == nullptr);
24589 m_dwarf2_cus
[per_cu
] = cu
;
24595 dwarf2_per_objfile::age_comp_units ()
24597 dwarf_read_debug_printf_v ("running");
24599 /* This is not expected to be called in the middle of CU expansion. There is
24600 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24601 loaded in memory. Calling age_comp_units while the queue is in use could
24602 make us free the DIEs for a CU that is in the queue and therefore break
24604 gdb_assert (!this->per_bfd
->queue
.has_value ());
24606 /* Start by clearing all marks. */
24607 for (auto pair
: m_dwarf2_cus
)
24608 pair
.second
->clear_mark ();
24610 /* Traverse all CUs, mark them and their dependencies if used recently
24612 for (auto pair
: m_dwarf2_cus
)
24614 dwarf2_cu
*cu
= pair
.second
;
24617 if (cu
->last_used
<= dwarf_max_cache_age
)
24621 /* Delete all CUs still not marked. */
24622 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24624 dwarf2_cu
*cu
= it
->second
;
24626 if (!cu
->is_marked ())
24628 dwarf_read_debug_printf_v ("deleting old CU %s",
24629 sect_offset_str (cu
->per_cu
->sect_off
));
24631 it
= m_dwarf2_cus
.erase (it
);
24641 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24643 auto it
= m_dwarf2_cus
.find (per_cu
);
24644 if (it
== m_dwarf2_cus
.end ())
24649 m_dwarf2_cus
.erase (it
);
24652 dwarf2_per_objfile::~dwarf2_per_objfile ()
24657 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24658 We store these in a hash table separate from the DIEs, and preserve them
24659 when the DIEs are flushed out of cache.
24661 The CU "per_cu" pointer is needed because offset alone is not enough to
24662 uniquely identify the type. A file may have multiple .debug_types sections,
24663 or the type may come from a DWO file. Furthermore, while it's more logical
24664 to use per_cu->section+offset, with Fission the section with the data is in
24665 the DWO file but we don't know that section at the point we need it.
24666 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24667 because we can enter the lookup routine, get_die_type_at_offset, from
24668 outside this file, and thus won't necessarily have PER_CU->cu.
24669 Fortunately, PER_CU is stable for the life of the objfile. */
24671 struct dwarf2_per_cu_offset_and_type
24673 const struct dwarf2_per_cu_data
*per_cu
;
24674 sect_offset sect_off
;
24678 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24681 per_cu_offset_and_type_hash (const void *item
)
24683 const struct dwarf2_per_cu_offset_and_type
*ofs
24684 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24686 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24689 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24692 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24694 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24695 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24696 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24697 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24699 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24700 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24703 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24704 table if necessary. For convenience, return TYPE.
24706 The DIEs reading must have careful ordering to:
24707 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24708 reading current DIE.
24709 * Not trying to dereference contents of still incompletely read in types
24710 while reading in other DIEs.
24711 * Enable referencing still incompletely read in types just by a pointer to
24712 the type without accessing its fields.
24714 Therefore caller should follow these rules:
24715 * Try to fetch any prerequisite types we may need to build this DIE type
24716 before building the type and calling set_die_type.
24717 * After building type call set_die_type for current DIE as soon as
24718 possible before fetching more types to complete the current type.
24719 * Make the type as complete as possible before fetching more types. */
24721 static struct type
*
24722 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24723 bool skip_data_location
)
24725 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24726 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24727 struct objfile
*objfile
= per_objfile
->objfile
;
24728 struct attribute
*attr
;
24729 struct dynamic_prop prop
;
24731 /* For Ada types, make sure that the gnat-specific data is always
24732 initialized (if not already set). There are a few types where
24733 we should not be doing so, because the type-specific area is
24734 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24735 where the type-specific area is used to store the floatformat).
24736 But this is not a problem, because the gnat-specific information
24737 is actually not needed for these types. */
24738 if (need_gnat_info (cu
)
24739 && type
->code () != TYPE_CODE_FUNC
24740 && type
->code () != TYPE_CODE_FLT
24741 && type
->code () != TYPE_CODE_METHODPTR
24742 && type
->code () != TYPE_CODE_MEMBERPTR
24743 && type
->code () != TYPE_CODE_METHOD
24744 && type
->code () != TYPE_CODE_FIXED_POINT
24745 && !HAVE_GNAT_AUX_INFO (type
))
24746 INIT_GNAT_SPECIFIC (type
);
24748 /* Read DW_AT_allocated and set in type. */
24749 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24752 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24753 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24754 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24757 /* Read DW_AT_associated and set in type. */
24758 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24761 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24762 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24763 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24766 /* Read DW_AT_data_location and set in type. */
24767 if (!skip_data_location
)
24769 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24770 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24771 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24774 if (per_objfile
->die_type_hash
== NULL
)
24775 per_objfile
->die_type_hash
24776 = htab_up (htab_create_alloc (127,
24777 per_cu_offset_and_type_hash
,
24778 per_cu_offset_and_type_eq
,
24779 NULL
, xcalloc
, xfree
));
24781 ofs
.per_cu
= cu
->per_cu
;
24782 ofs
.sect_off
= die
->sect_off
;
24784 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24785 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24787 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24788 sect_offset_str (die
->sect_off
));
24789 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24790 struct dwarf2_per_cu_offset_and_type
);
24795 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24796 or return NULL if the die does not have a saved type. */
24798 static struct type
*
24799 get_die_type_at_offset (sect_offset sect_off
,
24800 dwarf2_per_cu_data
*per_cu
,
24801 dwarf2_per_objfile
*per_objfile
)
24803 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24805 if (per_objfile
->die_type_hash
== NULL
)
24808 ofs
.per_cu
= per_cu
;
24809 ofs
.sect_off
= sect_off
;
24810 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24811 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24818 /* Look up the type for DIE in CU in die_type_hash,
24819 or return NULL if DIE does not have a saved type. */
24821 static struct type
*
24822 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24824 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24827 /* Trivial hash function for partial_die_info: the hash value of a DIE
24828 is its offset in .debug_info for this objfile. */
24831 partial_die_hash (const void *item
)
24833 const struct partial_die_info
*part_die
24834 = (const struct partial_die_info
*) item
;
24836 return to_underlying (part_die
->sect_off
);
24839 /* Trivial comparison function for partial_die_info structures: two DIEs
24840 are equal if they have the same offset. */
24843 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24845 const struct partial_die_info
*part_die_lhs
24846 = (const struct partial_die_info
*) item_lhs
;
24847 const struct partial_die_info
*part_die_rhs
24848 = (const struct partial_die_info
*) item_rhs
;
24850 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24853 struct cmd_list_element
*set_dwarf_cmdlist
;
24854 struct cmd_list_element
*show_dwarf_cmdlist
;
24857 show_check_physname (struct ui_file
*file
, int from_tty
,
24858 struct cmd_list_element
*c
, const char *value
)
24860 fprintf_filtered (file
,
24861 _("Whether to check \"physname\" is %s.\n"),
24865 void _initialize_dwarf2_read ();
24867 _initialize_dwarf2_read ()
24869 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
24871 Set DWARF specific variables.\n\
24872 Configure DWARF variables such as the cache size."),
24874 Show DWARF specific variables.\n\
24875 Show DWARF variables such as the cache size."),
24876 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
24877 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
24879 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24880 &dwarf_max_cache_age
, _("\
24881 Set the upper bound on the age of cached DWARF compilation units."), _("\
24882 Show the upper bound on the age of cached DWARF compilation units."), _("\
24883 A higher limit means that cached compilation units will be stored\n\
24884 in memory longer, and more total memory will be used. Zero disables\n\
24885 caching, which can slow down startup."),
24887 show_dwarf_max_cache_age
,
24888 &set_dwarf_cmdlist
,
24889 &show_dwarf_cmdlist
);
24891 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24892 Set debugging of the DWARF reader."), _("\
24893 Show debugging of the DWARF reader."), _("\
24894 When enabled (non-zero), debugging messages are printed during DWARF\n\
24895 reading and symtab expansion. A value of 1 (one) provides basic\n\
24896 information. A value greater than 1 provides more verbose information."),
24899 &setdebuglist
, &showdebuglist
);
24901 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24902 Set debugging of the DWARF DIE reader."), _("\
24903 Show debugging of the DWARF DIE reader."), _("\
24904 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24905 The value is the maximum depth to print."),
24908 &setdebuglist
, &showdebuglist
);
24910 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24911 Set debugging of the dwarf line reader."), _("\
24912 Show debugging of the dwarf line reader."), _("\
24913 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24914 A value of 1 (one) provides basic information.\n\
24915 A value greater than 1 provides more verbose information."),
24918 &setdebuglist
, &showdebuglist
);
24920 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24921 Set cross-checking of \"physname\" code against demangler."), _("\
24922 Show cross-checking of \"physname\" code against demangler."), _("\
24923 When enabled, GDB's internal \"physname\" code is checked against\n\
24925 NULL
, show_check_physname
,
24926 &setdebuglist
, &showdebuglist
);
24928 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24929 no_class
, &use_deprecated_index_sections
, _("\
24930 Set whether to use deprecated gdb_index sections."), _("\
24931 Show whether to use deprecated gdb_index sections."), _("\
24932 When enabled, deprecated .gdb_index sections are used anyway.\n\
24933 Normally they are ignored either because of a missing feature or\n\
24934 performance issue.\n\
24935 Warning: This option must be enabled before gdb reads the file."),
24938 &setlist
, &showlist
);
24940 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24941 &dwarf2_locexpr_funcs
);
24942 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24943 &dwarf2_loclist_funcs
);
24945 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24946 &dwarf2_block_frame_base_locexpr_funcs
);
24947 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24948 &dwarf2_block_frame_base_loclist_funcs
);
24951 selftests::register_test ("dw2_expand_symtabs_matching",
24952 selftests::dw2_expand_symtabs_matching::run_test
);
24953 selftests::register_test ("dwarf2_find_containing_comp_unit",
24954 selftests::find_containing_comp_unit::run_test
);