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 dwarf2/read.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 gdb_printf (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 cust
->primary_filetab ();
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 gdb_printf (_(" Number of read CUs: %d\n"), total
- count
);
3315 gdb_printf (_(" 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 gdb_printf (".gdb_index:");
3330 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3332 gdb_printf (" version %d\n",
3333 per_objfile
->per_bfd
->index_table
->version
);
3336 gdb_printf (" faked for \"readnow\"\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 (cust
->blockvector () != nullptr
4455 && blockvector_contains_pc (cust
->blockvector (), 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 gdb_printf (".debug_names:");
5338 if (per_objfile
->per_bfd
->debug_names_table
)
5339 gdb_printf (" exists\n");
5341 gdb_printf (" faked for \"readnow\"\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 gdb_printf (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 gdb_printf (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 gdb_printf (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_generic_subrange
:
7698 case DW_TAG_subrange_type
:
7699 /* File scope base type definitions are added to the partial
7701 add_partial_symbol (pdi
, cu
);
7703 case DW_TAG_namespace
:
7704 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7707 if (!pdi
->is_declaration
)
7708 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7710 case DW_TAG_imported_unit
:
7712 struct dwarf2_per_cu_data
*per_cu
;
7714 /* For now we don't handle imported units in type units. */
7715 if (cu
->per_cu
->is_debug_types
)
7717 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7718 " supported in type units [in module %s]"),
7719 objfile_name (cu
->per_objfile
->objfile
));
7722 per_cu
= dwarf2_find_containing_comp_unit
7723 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7724 cu
->per_objfile
->per_bfd
);
7726 /* Go read the partial unit, if needed. */
7727 if (per_cu
->v
.psymtab
== NULL
)
7728 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7731 if (pdi
->die_parent
== nullptr
7732 && per_cu
->unit_type
== DW_UT_compile
7733 && per_cu
->lang
== language_cplus
)
7734 /* Regard import as hint. See corresponding code in
7735 process_imported_unit_die. */
7738 cu
->per_cu
->imported_symtabs_push (per_cu
);
7741 case DW_TAG_imported_declaration
:
7742 add_partial_symbol (pdi
, cu
);
7749 /* If the die has a sibling, skip to the sibling. */
7751 pdi
= pdi
->die_sibling
;
7755 /* Functions used to compute the fully scoped name of a partial DIE.
7757 Normally, this is simple. For C++, the parent DIE's fully scoped
7758 name is concatenated with "::" and the partial DIE's name.
7759 Enumerators are an exception; they use the scope of their parent
7760 enumeration type, i.e. the name of the enumeration type is not
7761 prepended to the enumerator.
7763 There are two complexities. One is DW_AT_specification; in this
7764 case "parent" means the parent of the target of the specification,
7765 instead of the direct parent of the DIE. The other is compilers
7766 which do not emit DW_TAG_namespace; in this case we try to guess
7767 the fully qualified name of structure types from their members'
7768 linkage names. This must be done using the DIE's children rather
7769 than the children of any DW_AT_specification target. We only need
7770 to do this for structures at the top level, i.e. if the target of
7771 any DW_AT_specification (if any; otherwise the DIE itself) does not
7774 /* Compute the scope prefix associated with PDI's parent, in
7775 compilation unit CU. The result will be allocated on CU's
7776 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7777 field. NULL is returned if no prefix is necessary. */
7779 partial_die_parent_scope (struct partial_die_info
*pdi
,
7780 struct dwarf2_cu
*cu
)
7782 const char *grandparent_scope
;
7783 struct partial_die_info
*parent
, *real_pdi
;
7785 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7786 then this means the parent of the specification DIE. */
7789 while (real_pdi
->has_specification
)
7791 auto res
= find_partial_die (real_pdi
->spec_offset
,
7792 real_pdi
->spec_is_dwz
, cu
);
7797 parent
= real_pdi
->die_parent
;
7801 if (parent
->scope_set
)
7802 return parent
->scope
;
7806 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7808 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7809 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7810 Work around this problem here. */
7811 if (cu
->per_cu
->lang
== language_cplus
7812 && parent
->tag
== DW_TAG_namespace
7813 && strcmp (parent
->name (cu
), "::") == 0
7814 && grandparent_scope
== NULL
)
7816 parent
->scope
= NULL
;
7817 parent
->scope_set
= 1;
7821 /* Nested subroutines in Fortran get a prefix. */
7822 if (pdi
->tag
== DW_TAG_enumerator
)
7823 /* Enumerators should not get the name of the enumeration as a prefix. */
7824 parent
->scope
= grandparent_scope
;
7825 else if (parent
->tag
== DW_TAG_namespace
7826 || parent
->tag
== DW_TAG_module
7827 || parent
->tag
== DW_TAG_structure_type
7828 || parent
->tag
== DW_TAG_class_type
7829 || parent
->tag
== DW_TAG_interface_type
7830 || parent
->tag
== DW_TAG_union_type
7831 || parent
->tag
== DW_TAG_enumeration_type
7832 || (cu
->per_cu
->lang
== language_fortran
7833 && parent
->tag
== DW_TAG_subprogram
7834 && pdi
->tag
== DW_TAG_subprogram
))
7836 if (grandparent_scope
== NULL
)
7837 parent
->scope
= parent
->name (cu
);
7839 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7841 parent
->name (cu
), 0, cu
);
7845 /* FIXME drow/2004-04-01: What should we be doing with
7846 function-local names? For partial symbols, we should probably be
7848 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7849 dwarf_tag_name (parent
->tag
),
7850 sect_offset_str (pdi
->sect_off
));
7851 parent
->scope
= grandparent_scope
;
7854 parent
->scope_set
= 1;
7855 return parent
->scope
;
7858 /* Return the fully scoped name associated with PDI, from compilation unit
7859 CU. The result will be allocated with malloc. */
7861 static gdb::unique_xmalloc_ptr
<char>
7862 partial_die_full_name (struct partial_die_info
*pdi
,
7863 struct dwarf2_cu
*cu
)
7865 const char *parent_scope
;
7867 /* If this is a template instantiation, we can not work out the
7868 template arguments from partial DIEs. So, unfortunately, we have
7869 to go through the full DIEs. At least any work we do building
7870 types here will be reused if full symbols are loaded later. */
7871 if (pdi
->has_template_arguments
)
7875 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7877 struct die_info
*die
;
7878 struct attribute attr
;
7879 struct dwarf2_cu
*ref_cu
= cu
;
7881 /* DW_FORM_ref_addr is using section offset. */
7882 attr
.name
= (enum dwarf_attribute
) 0;
7883 attr
.form
= DW_FORM_ref_addr
;
7884 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7885 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7887 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7891 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7892 if (parent_scope
== NULL
)
7895 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7901 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7903 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7904 struct objfile
*objfile
= per_objfile
->objfile
;
7905 struct gdbarch
*gdbarch
= objfile
->arch ();
7907 const char *actual_name
= NULL
;
7910 baseaddr
= objfile
->text_section_offset ();
7912 gdb::unique_xmalloc_ptr
<char> built_actual_name
7913 = partial_die_full_name (pdi
, cu
);
7914 if (built_actual_name
!= NULL
)
7915 actual_name
= built_actual_name
.get ();
7917 if (actual_name
== NULL
)
7918 actual_name
= pdi
->name (cu
);
7920 partial_symbol psymbol
;
7921 memset (&psymbol
, 0, sizeof (psymbol
));
7922 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7923 &objfile
->objfile_obstack
);
7924 psymbol
.ginfo
.set_section_index (-1);
7926 /* The code below indicates that the psymbol should be installed by
7928 gdb::optional
<psymbol_placement
> where
;
7932 case DW_TAG_inlined_subroutine
:
7933 case DW_TAG_subprogram
:
7934 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7936 if (pdi
->is_external
7937 || cu
->per_cu
->lang
== language_ada
7938 || (cu
->per_cu
->lang
== language_fortran
7939 && pdi
->die_parent
!= NULL
7940 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7942 /* Normally, only "external" DIEs are part of the global scope.
7943 But in Ada and Fortran, we want to be able to access nested
7944 procedures globally. So all Ada and Fortran subprograms are
7945 stored in the global scope. */
7946 where
= psymbol_placement::GLOBAL
;
7949 where
= psymbol_placement::STATIC
;
7951 psymbol
.domain
= VAR_DOMAIN
;
7952 psymbol
.aclass
= LOC_BLOCK
;
7953 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7954 psymbol
.ginfo
.value
.address
= addr
;
7956 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7957 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7959 case DW_TAG_constant
:
7960 psymbol
.domain
= VAR_DOMAIN
;
7961 psymbol
.aclass
= LOC_STATIC
;
7962 where
= (pdi
->is_external
7963 ? psymbol_placement::GLOBAL
7964 : psymbol_placement::STATIC
);
7966 case DW_TAG_variable
:
7968 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7972 && !per_objfile
->per_bfd
->has_section_at_zero
)
7974 /* A global or static variable may also have been stripped
7975 out by the linker if unused, in which case its address
7976 will be nullified; do not add such variables into partial
7977 symbol table then. */
7979 else if (pdi
->is_external
)
7982 Don't enter into the minimal symbol tables as there is
7983 a minimal symbol table entry from the ELF symbols already.
7984 Enter into partial symbol table if it has a location
7985 descriptor or a type.
7986 If the location descriptor is missing, new_symbol will create
7987 a LOC_UNRESOLVED symbol, the address of the variable will then
7988 be determined from the minimal symbol table whenever the variable
7990 The address for the partial symbol table entry is not
7991 used by GDB, but it comes in handy for debugging partial symbol
7994 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7996 psymbol
.domain
= VAR_DOMAIN
;
7997 psymbol
.aclass
= LOC_STATIC
;
7998 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7999 psymbol
.ginfo
.value
.address
= addr
;
8000 where
= psymbol_placement::GLOBAL
;
8005 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8007 /* Static Variable. Skip symbols whose value we cannot know (those
8008 without location descriptors or constant values). */
8009 if (!has_loc
&& !pdi
->has_const_value
)
8012 psymbol
.domain
= VAR_DOMAIN
;
8013 psymbol
.aclass
= LOC_STATIC
;
8014 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8016 psymbol
.ginfo
.value
.address
= addr
;
8017 where
= psymbol_placement::STATIC
;
8020 case DW_TAG_array_type
:
8021 case DW_TAG_typedef
:
8022 case DW_TAG_base_type
:
8023 case DW_TAG_subrange_type
:
8024 case DW_TAG_generic_subrange
:
8025 psymbol
.domain
= VAR_DOMAIN
;
8026 psymbol
.aclass
= LOC_TYPEDEF
;
8027 where
= psymbol_placement::STATIC
;
8029 case DW_TAG_imported_declaration
:
8030 case DW_TAG_namespace
:
8031 psymbol
.domain
= VAR_DOMAIN
;
8032 psymbol
.aclass
= LOC_TYPEDEF
;
8033 where
= psymbol_placement::GLOBAL
;
8036 /* With Fortran 77 there might be a "BLOCK DATA" module
8037 available without any name. If so, we skip the module as it
8038 doesn't bring any value. */
8039 if (actual_name
!= nullptr)
8041 psymbol
.domain
= MODULE_DOMAIN
;
8042 psymbol
.aclass
= LOC_TYPEDEF
;
8043 where
= psymbol_placement::GLOBAL
;
8046 case DW_TAG_class_type
:
8047 case DW_TAG_interface_type
:
8048 case DW_TAG_structure_type
:
8049 case DW_TAG_union_type
:
8050 case DW_TAG_enumeration_type
:
8051 /* Skip external references. The DWARF standard says in the section
8052 about "Structure, Union, and Class Type Entries": "An incomplete
8053 structure, union or class type is represented by a structure,
8054 union or class entry that does not have a byte size attribute
8055 and that has a DW_AT_declaration attribute." */
8056 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8059 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8060 static vs. global. */
8061 psymbol
.domain
= STRUCT_DOMAIN
;
8062 psymbol
.aclass
= LOC_TYPEDEF
;
8063 where
= (cu
->per_cu
->lang
== language_cplus
8064 ? psymbol_placement::GLOBAL
8065 : psymbol_placement::STATIC
);
8067 case DW_TAG_enumerator
:
8068 psymbol
.domain
= VAR_DOMAIN
;
8069 psymbol
.aclass
= LOC_CONST
;
8070 where
= (cu
->per_cu
->lang
== language_cplus
8071 ? psymbol_placement::GLOBAL
8072 : psymbol_placement::STATIC
);
8078 if (where
.has_value ())
8080 if (built_actual_name
!= nullptr)
8081 actual_name
= objfile
->intern (actual_name
);
8082 if (pdi
->linkage_name
== nullptr
8083 || cu
->per_cu
->lang
== language_ada
)
8084 psymbol
.ginfo
.set_linkage_name (actual_name
);
8087 psymbol
.ginfo
.set_demangled_name (actual_name
,
8088 &objfile
->objfile_obstack
);
8089 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8091 cu
->per_cu
->v
.psymtab
->add_psymbol
8092 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8097 /* Read a partial die corresponding to a namespace; also, add a symbol
8098 corresponding to that namespace to the symbol table. NAMESPACE is
8099 the name of the enclosing namespace. */
8102 add_partial_namespace (struct partial_die_info
*pdi
,
8103 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8104 int set_addrmap
, struct dwarf2_cu
*cu
)
8106 /* Add a symbol for the namespace. */
8108 add_partial_symbol (pdi
, cu
);
8110 /* Now scan partial symbols in that namespace. */
8112 if (pdi
->has_children
)
8113 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8116 /* Read a partial die corresponding to a Fortran module. */
8119 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8120 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8122 /* Add a symbol for the namespace. */
8124 add_partial_symbol (pdi
, cu
);
8126 /* Now scan partial symbols in that module. */
8128 if (pdi
->has_children
)
8129 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8133 dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
8134 dwarf2_psymtab
*, dwarf_tag
);
8136 /* Read a partial die corresponding to a subprogram or an inlined
8137 subprogram and create a partial symbol for that subprogram.
8138 When the CU language allows it, this routine also defines a partial
8139 symbol for each nested subprogram that this subprogram contains.
8140 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8141 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8143 PDI may also be a lexical block, in which case we simply search
8144 recursively for subprograms defined inside that lexical block.
8145 Again, this is only performed when the CU language allows this
8146 type of definitions. */
8149 add_partial_subprogram (struct partial_die_info
*pdi
,
8150 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8151 int set_addrmap
, struct dwarf2_cu
*cu
)
8153 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8155 if (pdi
->has_pc_info
)
8157 if (pdi
->lowpc
< *lowpc
)
8158 *lowpc
= pdi
->lowpc
;
8159 if (pdi
->highpc
> *highpc
)
8160 *highpc
= pdi
->highpc
;
8163 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8164 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8165 struct gdbarch
*gdbarch
= objfile
->arch ();
8167 CORE_ADDR this_highpc
;
8168 CORE_ADDR this_lowpc
;
8170 baseaddr
= objfile
->text_section_offset ();
8172 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8173 pdi
->lowpc
+ baseaddr
)
8176 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8177 pdi
->highpc
+ baseaddr
)
8179 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8180 this_lowpc
, this_highpc
- 1,
8181 cu
->per_cu
->v
.psymtab
);
8185 if (pdi
->has_range_info
8186 && dwarf2_ranges_read (pdi
->ranges_offset
, &pdi
->lowpc
, &pdi
->highpc
,
8188 set_addrmap
? cu
->per_cu
->v
.psymtab
: nullptr,
8191 if (pdi
->lowpc
< *lowpc
)
8192 *lowpc
= pdi
->lowpc
;
8193 if (pdi
->highpc
> *highpc
)
8194 *highpc
= pdi
->highpc
;
8197 if (pdi
->has_pc_info
|| pdi
->has_range_info
8198 || (!pdi
->is_external
&& pdi
->may_be_inlined
))
8200 if (!pdi
->is_declaration
)
8201 /* Ignore subprogram DIEs that do not have a name, they are
8202 illegal. Do not emit a complaint at this point, we will
8203 do so when we convert this psymtab into a symtab. */
8205 add_partial_symbol (pdi
, cu
);
8209 if (! pdi
->has_children
)
8212 if (cu
->per_cu
->lang
== language_ada
8213 || cu
->per_cu
->lang
== language_fortran
)
8215 pdi
= pdi
->die_child
;
8219 if (pdi
->tag
== DW_TAG_subprogram
8220 || pdi
->tag
== DW_TAG_inlined_subroutine
8221 || pdi
->tag
== DW_TAG_lexical_block
)
8222 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8223 pdi
= pdi
->die_sibling
;
8228 /* Read a partial die corresponding to an enumeration type. */
8231 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8232 struct dwarf2_cu
*cu
)
8234 struct partial_die_info
*pdi
;
8236 if (enum_pdi
->name (cu
) != NULL
)
8237 add_partial_symbol (enum_pdi
, cu
);
8239 pdi
= enum_pdi
->die_child
;
8242 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8243 complaint (_("malformed enumerator DIE ignored"));
8245 add_partial_symbol (pdi
, cu
);
8246 pdi
= pdi
->die_sibling
;
8250 /* Return the initial uleb128 in the die at INFO_PTR. */
8253 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8255 unsigned int bytes_read
;
8257 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8260 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8261 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8263 Return the corresponding abbrev, or NULL if the number is zero (indicating
8264 an empty DIE). In either case *BYTES_READ will be set to the length of
8265 the initial number. */
8267 static const struct abbrev_info
*
8268 peek_die_abbrev (const die_reader_specs
&reader
,
8269 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8271 dwarf2_cu
*cu
= reader
.cu
;
8272 bfd
*abfd
= reader
.abfd
;
8273 unsigned int abbrev_number
8274 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8276 if (abbrev_number
== 0)
8279 const abbrev_info
*abbrev
8280 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8283 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8284 " at offset %s [in module %s]"),
8285 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8286 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8292 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8293 Returns a pointer to the end of a series of DIEs, terminated by an empty
8294 DIE. Any children of the skipped DIEs will also be skipped. */
8296 static const gdb_byte
*
8297 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8301 unsigned int bytes_read
;
8302 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8306 return info_ptr
+ bytes_read
;
8308 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8312 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8313 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8314 abbrev corresponding to that skipped uleb128 should be passed in
8315 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8318 static const gdb_byte
*
8319 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8320 const struct abbrev_info
*abbrev
)
8322 unsigned int bytes_read
;
8323 struct attribute attr
;
8324 bfd
*abfd
= reader
->abfd
;
8325 struct dwarf2_cu
*cu
= reader
->cu
;
8326 const gdb_byte
*buffer
= reader
->buffer
;
8327 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8328 unsigned int form
, i
;
8330 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8332 /* The only abbrev we care about is DW_AT_sibling. */
8333 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8335 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8336 if (attr
.form
== DW_FORM_ref_addr
)
8337 complaint (_("ignoring absolute DW_AT_sibling"));
8340 sect_offset off
= attr
.get_ref_die_offset ();
8341 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8343 if (sibling_ptr
< info_ptr
)
8344 complaint (_("DW_AT_sibling points backwards"));
8345 else if (sibling_ptr
> reader
->buffer_end
)
8346 reader
->die_section
->overflow_complaint ();
8352 /* If it isn't DW_AT_sibling, skip this attribute. */
8353 form
= abbrev
->attrs
[i
].form
;
8357 case DW_FORM_ref_addr
:
8358 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8359 and later it is offset sized. */
8360 if (cu
->header
.version
== 2)
8361 info_ptr
+= cu
->header
.addr_size
;
8363 info_ptr
+= cu
->header
.offset_size
;
8365 case DW_FORM_GNU_ref_alt
:
8366 info_ptr
+= cu
->header
.offset_size
;
8369 info_ptr
+= cu
->header
.addr_size
;
8377 case DW_FORM_flag_present
:
8378 case DW_FORM_implicit_const
:
8395 case DW_FORM_ref_sig8
:
8398 case DW_FORM_data16
:
8401 case DW_FORM_string
:
8402 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8403 info_ptr
+= bytes_read
;
8405 case DW_FORM_sec_offset
:
8407 case DW_FORM_GNU_strp_alt
:
8408 info_ptr
+= cu
->header
.offset_size
;
8410 case DW_FORM_exprloc
:
8412 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8413 info_ptr
+= bytes_read
;
8415 case DW_FORM_block1
:
8416 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8418 case DW_FORM_block2
:
8419 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8421 case DW_FORM_block4
:
8422 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8428 case DW_FORM_ref_udata
:
8429 case DW_FORM_GNU_addr_index
:
8430 case DW_FORM_GNU_str_index
:
8431 case DW_FORM_rnglistx
:
8432 case DW_FORM_loclistx
:
8433 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8435 case DW_FORM_indirect
:
8436 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8437 info_ptr
+= bytes_read
;
8438 /* We need to continue parsing from here, so just go back to
8440 goto skip_attribute
;
8443 error (_("Dwarf Error: Cannot handle %s "
8444 "in DWARF reader [in module %s]"),
8445 dwarf_form_name (form
),
8446 bfd_get_filename (abfd
));
8450 if (abbrev
->has_children
)
8451 return skip_children (reader
, info_ptr
);
8456 /* Locate ORIG_PDI's sibling.
8457 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8459 static const gdb_byte
*
8460 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8461 struct partial_die_info
*orig_pdi
,
8462 const gdb_byte
*info_ptr
)
8464 /* Do we know the sibling already? */
8466 if (orig_pdi
->sibling
)
8467 return orig_pdi
->sibling
;
8469 /* Are there any children to deal with? */
8471 if (!orig_pdi
->has_children
)
8474 /* Skip the children the long way. */
8476 return skip_children (reader
, info_ptr
);
8479 /* Expand this partial symbol table into a full symbol table. SELF is
8483 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8485 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8487 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8489 /* If this psymtab is constructed from a debug-only objfile, the
8490 has_section_at_zero flag will not necessarily be correct. We
8491 can get the correct value for this flag by looking at the data
8492 associated with the (presumably stripped) associated objfile. */
8493 if (objfile
->separate_debug_objfile_backlink
)
8495 dwarf2_per_objfile
*per_objfile_backlink
8496 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8498 per_objfile
->per_bfd
->has_section_at_zero
8499 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8502 expand_psymtab (objfile
);
8504 process_cu_includes (per_objfile
);
8507 /* Reading in full CUs. */
8509 /* Add PER_CU to the queue. */
8512 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8513 dwarf2_per_objfile
*per_objfile
,
8514 enum language pretend_language
)
8518 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8519 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8522 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8524 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8527 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8528 DIEs, false otherwise.
8530 Explanation: there is an invariant that if a CU is queued for expansion
8531 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8532 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8533 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8534 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8535 invariant is respected.
8537 The caller is therefore not required to load the CU's DIEs (we return false)
8540 - the CU is already expanded, and therefore does not get enqueued
8541 - the CU gets enqueued for expansion, but its DIEs are already loaded
8543 Note that the caller should not use this function's return value as an
8544 indicator of whether the CU's DIEs are loaded right now, it should check
8545 that by calling `dwarf2_per_objfile::get_cu` instead. */
8548 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8549 dwarf2_per_cu_data
*per_cu
,
8550 dwarf2_per_objfile
*per_objfile
,
8551 enum language pretend_language
)
8553 /* We may arrive here during partial symbol reading, if we need full
8554 DIEs to process an unusual case (e.g. template arguments). Do
8555 not queue PER_CU, just tell our caller to load its DIEs. */
8556 if (per_cu
->per_bfd
->reading_partial_symbols
)
8558 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8560 if (cu
== NULL
|| cu
->dies
== NULL
)
8565 /* Mark the dependence relation so that we don't flush PER_CU
8567 if (dependent_cu
!= NULL
)
8568 dependent_cu
->add_dependence (per_cu
);
8570 /* If it's already on the queue, we have nothing to do. */
8573 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8575 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8577 /* If the CU is queued for expansion, it should not already be
8579 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8581 /* The DIEs are already loaded, the caller doesn't need to do it. */
8585 bool queued
= false;
8586 if (!per_objfile
->symtab_set_p (per_cu
))
8588 /* Add it to the queue. */
8589 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8593 /* If the compilation unit is already loaded, just mark it as
8595 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8599 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8600 and the DIEs are not already loaded. */
8601 return queued
&& cu
== nullptr;
8604 /* Process the queue. */
8607 process_queue (dwarf2_per_objfile
*per_objfile
)
8609 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8610 objfile_name (per_objfile
->objfile
));
8612 /* The queue starts out with one item, but following a DIE reference
8613 may load a new CU, adding it to the end of the queue. */
8614 while (!per_objfile
->per_bfd
->queue
->empty ())
8616 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8617 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8619 if (!per_objfile
->symtab_set_p (per_cu
))
8621 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8623 /* Skip dummy CUs. */
8626 unsigned int debug_print_threshold
;
8629 if (per_cu
->is_debug_types
)
8631 struct signatured_type
*sig_type
=
8632 (struct signatured_type
*) per_cu
;
8634 sprintf (buf
, "TU %s at offset %s",
8635 hex_string (sig_type
->signature
),
8636 sect_offset_str (per_cu
->sect_off
));
8637 /* There can be 100s of TUs.
8638 Only print them in verbose mode. */
8639 debug_print_threshold
= 2;
8643 sprintf (buf
, "CU at offset %s",
8644 sect_offset_str (per_cu
->sect_off
));
8645 debug_print_threshold
= 1;
8648 if (dwarf_read_debug
>= debug_print_threshold
)
8649 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8651 if (per_cu
->is_debug_types
)
8652 process_full_type_unit (cu
, item
.pretend_language
);
8654 process_full_comp_unit (cu
, item
.pretend_language
);
8656 if (dwarf_read_debug
>= debug_print_threshold
)
8657 dwarf_read_debug_printf ("Done expanding %s", buf
);
8662 per_objfile
->per_bfd
->queue
->pop ();
8665 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8666 objfile_name (per_objfile
->objfile
));
8669 /* Read in full symbols for PST, and anything it depends on. */
8672 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8674 gdb_assert (!readin_p (objfile
));
8676 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8677 free_cached_comp_units
freer (per_objfile
);
8678 expand_dependencies (objfile
);
8680 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8681 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8684 /* See psympriv.h. */
8687 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8689 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8690 return per_objfile
->symtab_set_p (per_cu_data
);
8693 /* See psympriv.h. */
8696 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8698 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8699 return per_objfile
->get_symtab (per_cu_data
);
8702 /* Trivial hash function for die_info: the hash value of a DIE
8703 is its offset in .debug_info for this objfile. */
8706 die_hash (const void *item
)
8708 const struct die_info
*die
= (const struct die_info
*) item
;
8710 return to_underlying (die
->sect_off
);
8713 /* Trivial comparison function for die_info structures: two DIEs
8714 are equal if they have the same offset. */
8717 die_eq (const void *item_lhs
, const void *item_rhs
)
8719 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8720 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8722 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8725 /* Load the DIEs associated with PER_CU into memory.
8727 In some cases, the caller, while reading partial symbols, will need to load
8728 the full symbols for the CU for some reason. It will already have a
8729 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8730 rather than creating a new one. */
8733 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8734 dwarf2_per_objfile
*per_objfile
,
8735 dwarf2_cu
*existing_cu
,
8737 enum language pretend_language
)
8739 gdb_assert (! this_cu
->is_debug_types
);
8741 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8745 struct dwarf2_cu
*cu
= reader
.cu
;
8746 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8748 gdb_assert (cu
->die_hash
== NULL
);
8750 htab_create_alloc_ex (cu
->header
.length
/ 12,
8754 &cu
->comp_unit_obstack
,
8755 hashtab_obstack_allocate
,
8756 dummy_obstack_deallocate
);
8758 if (reader
.comp_unit_die
->has_children
)
8759 reader
.comp_unit_die
->child
8760 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8761 &info_ptr
, reader
.comp_unit_die
);
8762 cu
->dies
= reader
.comp_unit_die
;
8763 /* comp_unit_die is not stored in die_hash, no need. */
8765 /* We try not to read any attributes in this function, because not
8766 all CUs needed for references have been loaded yet, and symbol
8767 table processing isn't initialized. But we have to set the CU language,
8768 or we won't be able to build types correctly.
8769 Similarly, if we do not read the producer, we can not apply
8770 producer-specific interpretation. */
8771 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8776 /* Add a DIE to the delayed physname list. */
8779 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8780 const char *name
, struct die_info
*die
,
8781 struct dwarf2_cu
*cu
)
8783 struct delayed_method_info mi
;
8785 mi
.fnfield_index
= fnfield_index
;
8789 cu
->method_list
.push_back (mi
);
8792 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8793 "const" / "volatile". If so, decrements LEN by the length of the
8794 modifier and return true. Otherwise return false. */
8798 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8800 size_t mod_len
= sizeof (mod
) - 1;
8801 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8809 /* Compute the physnames of any methods on the CU's method list.
8811 The computation of method physnames is delayed in order to avoid the
8812 (bad) condition that one of the method's formal parameters is of an as yet
8816 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8818 /* Only C++ delays computing physnames. */
8819 if (cu
->method_list
.empty ())
8821 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8823 for (const delayed_method_info
&mi
: cu
->method_list
)
8825 const char *physname
;
8826 struct fn_fieldlist
*fn_flp
8827 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8828 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8829 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8830 = physname
? physname
: "";
8832 /* Since there's no tag to indicate whether a method is a
8833 const/volatile overload, extract that information out of the
8835 if (physname
!= NULL
)
8837 size_t len
= strlen (physname
);
8841 if (physname
[len
] == ')') /* shortcut */
8843 else if (check_modifier (physname
, len
, " const"))
8844 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8845 else if (check_modifier (physname
, len
, " volatile"))
8846 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8853 /* The list is no longer needed. */
8854 cu
->method_list
.clear ();
8857 /* Go objects should be embedded in a DW_TAG_module DIE,
8858 and it's not clear if/how imported objects will appear.
8859 To keep Go support simple until that's worked out,
8860 go back through what we've read and create something usable.
8861 We could do this while processing each DIE, and feels kinda cleaner,
8862 but that way is more invasive.
8863 This is to, for example, allow the user to type "p var" or "b main"
8864 without having to specify the package name, and allow lookups
8865 of module.object to work in contexts that use the expression
8869 fixup_go_packaging (struct dwarf2_cu
*cu
)
8871 gdb::unique_xmalloc_ptr
<char> package_name
;
8872 struct pending
*list
;
8875 for (list
= *cu
->get_builder ()->get_global_symbols ();
8879 for (i
= 0; i
< list
->nsyms
; ++i
)
8881 struct symbol
*sym
= list
->symbol
[i
];
8883 if (sym
->language () == language_go
8884 && sym
->aclass () == LOC_BLOCK
)
8886 gdb::unique_xmalloc_ptr
<char> this_package_name
8887 (go_symbol_package_name (sym
));
8889 if (this_package_name
== NULL
)
8891 if (package_name
== NULL
)
8892 package_name
= std::move (this_package_name
);
8895 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8896 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8897 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8898 (symbol_symtab (sym
) != NULL
8899 ? symtab_to_filename_for_display
8900 (symbol_symtab (sym
))
8901 : objfile_name (objfile
)),
8902 this_package_name
.get (), package_name
.get ());
8908 if (package_name
!= NULL
)
8910 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8911 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8912 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8913 saved_package_name
);
8916 sym
= new (&objfile
->objfile_obstack
) symbol
;
8917 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8918 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8919 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8920 e.g., "main" finds the "main" module and not C's main(). */
8921 sym
->set_domain (STRUCT_DOMAIN
);
8922 sym
->set_aclass_index (LOC_TYPEDEF
);
8923 sym
->set_type (type
);
8925 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8929 /* Allocate a fully-qualified name consisting of the two parts on the
8933 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8935 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8938 /* A helper that allocates a variant part to attach to a Rust enum
8939 type. OBSTACK is where the results should be allocated. TYPE is
8940 the type we're processing. DISCRIMINANT_INDEX is the index of the
8941 discriminant. It must be the index of one of the fields of TYPE,
8942 or -1 to mean there is no discriminant (univariant enum).
8943 DEFAULT_INDEX is the index of the default field; or -1 if there is
8944 no default. RANGES is indexed by "effective" field number (the
8945 field index, but omitting the discriminant and default fields) and
8946 must hold the discriminant values used by the variants. Note that
8947 RANGES must have a lifetime at least as long as OBSTACK -- either
8948 already allocated on it, or static. */
8951 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8952 int discriminant_index
, int default_index
,
8953 gdb::array_view
<discriminant_range
> ranges
)
8955 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8956 gdb_assert (discriminant_index
== -1
8957 || (discriminant_index
>= 0
8958 && discriminant_index
< type
->num_fields ()));
8959 gdb_assert (default_index
== -1
8960 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8962 /* We have one variant for each non-discriminant field. */
8963 int n_variants
= type
->num_fields ();
8964 if (discriminant_index
!= -1)
8967 variant
*variants
= new (obstack
) variant
[n_variants
];
8970 for (int i
= 0; i
< type
->num_fields (); ++i
)
8972 if (i
== discriminant_index
)
8975 variants
[var_idx
].first_field
= i
;
8976 variants
[var_idx
].last_field
= i
+ 1;
8978 /* The default field does not need a range, but other fields do.
8979 We skipped the discriminant above. */
8980 if (i
!= default_index
)
8982 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8989 gdb_assert (range_idx
== ranges
.size ());
8990 gdb_assert (var_idx
== n_variants
);
8992 variant_part
*part
= new (obstack
) variant_part
;
8993 part
->discriminant_index
= discriminant_index
;
8994 /* If there is no discriminant, then whether it is signed is of no
8997 = (discriminant_index
== -1
8999 : type
->field (discriminant_index
).type ()->is_unsigned ());
9000 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9002 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9003 gdb::array_view
<variant_part
> *prop_value
9004 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9006 struct dynamic_prop prop
;
9007 prop
.set_variant_parts (prop_value
);
9009 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9012 /* Some versions of rustc emitted enums in an unusual way.
9014 Ordinary enums were emitted as unions. The first element of each
9015 structure in the union was named "RUST$ENUM$DISR". This element
9016 held the discriminant.
9018 These versions of Rust also implemented the "non-zero"
9019 optimization. When the enum had two values, and one is empty and
9020 the other holds a pointer that cannot be zero, the pointer is used
9021 as the discriminant, with a zero value meaning the empty variant.
9022 Here, the union's first member is of the form
9023 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9024 where the fieldnos are the indices of the fields that should be
9025 traversed in order to find the field (which may be several fields deep)
9026 and the variantname is the name of the variant of the case when the
9029 This function recognizes whether TYPE is of one of these forms,
9030 and, if so, smashes it to be a variant type. */
9033 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9035 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9037 /* We don't need to deal with empty enums. */
9038 if (type
->num_fields () == 0)
9041 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9042 if (type
->num_fields () == 1
9043 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
9045 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
9047 /* Decode the field name to find the offset of the
9049 ULONGEST bit_offset
= 0;
9050 struct type
*field_type
= type
->field (0).type ();
9051 while (name
[0] >= '0' && name
[0] <= '9')
9054 unsigned long index
= strtoul (name
, &tail
, 10);
9057 || index
>= field_type
->num_fields ()
9058 || (field_type
->field (index
).loc_kind ()
9059 != FIELD_LOC_KIND_BITPOS
))
9061 complaint (_("Could not parse Rust enum encoding string \"%s\""
9063 type
->field (0).name (),
9064 objfile_name (objfile
));
9069 bit_offset
+= field_type
->field (index
).loc_bitpos ();
9070 field_type
= field_type
->field (index
).type ();
9073 /* Smash this type to be a structure type. We have to do this
9074 because the type has already been recorded. */
9075 type
->set_code (TYPE_CODE_STRUCT
);
9076 type
->set_num_fields (3);
9077 /* Save the field we care about. */
9078 struct field saved_field
= type
->field (0);
9080 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9082 /* Put the discriminant at index 0. */
9083 type
->field (0).set_type (field_type
);
9084 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9085 type
->field (0).set_name ("<<discriminant>>");
9086 type
->field (0).set_loc_bitpos (bit_offset
);
9088 /* The order of fields doesn't really matter, so put the real
9089 field at index 1 and the data-less field at index 2. */
9090 type
->field (1) = saved_field
;
9091 type
->field (1).set_name
9092 (rust_last_path_segment (type
->field (1).type ()->name ()));
9093 type
->field (1).type ()->set_name
9094 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9095 type
->field (1).name ()));
9097 const char *dataless_name
9098 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9100 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9102 type
->field (2).set_type (dataless_type
);
9103 /* NAME points into the original discriminant name, which
9104 already has the correct lifetime. */
9105 type
->field (2).set_name (name
);
9106 type
->field (2).set_loc_bitpos (0);
9108 /* Indicate that this is a variant type. */
9109 static discriminant_range ranges
[1] = { { 0, 0 } };
9110 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9112 /* A union with a single anonymous field is probably an old-style
9114 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
9116 /* Smash this type to be a structure type. We have to do this
9117 because the type has already been recorded. */
9118 type
->set_code (TYPE_CODE_STRUCT
);
9120 struct type
*field_type
= type
->field (0).type ();
9121 const char *variant_name
9122 = rust_last_path_segment (field_type
->name ());
9123 type
->field (0).set_name (variant_name
);
9124 field_type
->set_name
9125 (rust_fully_qualify (&objfile
->objfile_obstack
,
9126 type
->name (), variant_name
));
9128 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9132 struct type
*disr_type
= nullptr;
9133 for (int i
= 0; i
< type
->num_fields (); ++i
)
9135 disr_type
= type
->field (i
).type ();
9137 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9139 /* All fields of a true enum will be structs. */
9142 else if (disr_type
->num_fields () == 0)
9144 /* Could be data-less variant, so keep going. */
9145 disr_type
= nullptr;
9147 else if (strcmp (disr_type
->field (0).name (),
9148 "RUST$ENUM$DISR") != 0)
9150 /* Not a Rust enum. */
9160 /* If we got here without a discriminant, then it's probably
9162 if (disr_type
== nullptr)
9165 /* Smash this type to be a structure type. We have to do this
9166 because the type has already been recorded. */
9167 type
->set_code (TYPE_CODE_STRUCT
);
9169 /* Make space for the discriminant field. */
9170 struct field
*disr_field
= &disr_type
->field (0);
9172 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9173 * sizeof (struct field
)));
9174 memcpy (new_fields
+ 1, type
->fields (),
9175 type
->num_fields () * sizeof (struct field
));
9176 type
->set_fields (new_fields
);
9177 type
->set_num_fields (type
->num_fields () + 1);
9179 /* Install the discriminant at index 0 in the union. */
9180 type
->field (0) = *disr_field
;
9181 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9182 type
->field (0).set_name ("<<discriminant>>");
9184 /* We need a way to find the correct discriminant given a
9185 variant name. For convenience we build a map here. */
9186 struct type
*enum_type
= disr_field
->type ();
9187 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9188 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9190 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
9193 = rust_last_path_segment (enum_type
->field (i
).name ());
9194 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
9198 int n_fields
= type
->num_fields ();
9199 /* We don't need a range entry for the discriminant, but we do
9200 need one for every other field, as there is no default
9202 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9205 /* Skip the discriminant here. */
9206 for (int i
= 1; i
< n_fields
; ++i
)
9208 /* Find the final word in the name of this variant's type.
9209 That name can be used to look up the correct
9211 const char *variant_name
9212 = rust_last_path_segment (type
->field (i
).type ()->name ());
9214 auto iter
= discriminant_map
.find (variant_name
);
9215 if (iter
!= discriminant_map
.end ())
9217 ranges
[i
- 1].low
= iter
->second
;
9218 ranges
[i
- 1].high
= iter
->second
;
9221 /* In Rust, each element should have the size of the
9223 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9225 /* Remove the discriminant field, if it exists. */
9226 struct type
*sub_type
= type
->field (i
).type ();
9227 if (sub_type
->num_fields () > 0)
9229 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9230 sub_type
->set_fields (sub_type
->fields () + 1);
9232 type
->field (i
).set_name (variant_name
);
9234 (rust_fully_qualify (&objfile
->objfile_obstack
,
9235 type
->name (), variant_name
));
9238 /* Indicate that this is a variant type. */
9239 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9240 gdb::array_view
<discriminant_range
> (ranges
,
9245 /* Rewrite some Rust unions to be structures with variants parts. */
9248 rust_union_quirks (struct dwarf2_cu
*cu
)
9250 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9251 for (type
*type_
: cu
->rust_unions
)
9252 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9253 /* We don't need this any more. */
9254 cu
->rust_unions
.clear ();
9259 type_unit_group_unshareable
*
9260 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9262 auto iter
= this->m_type_units
.find (tu_group
);
9263 if (iter
!= this->m_type_units
.end ())
9264 return iter
->second
.get ();
9266 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9267 type_unit_group_unshareable
*result
= uniq
.get ();
9268 this->m_type_units
[tu_group
] = std::move (uniq
);
9273 dwarf2_per_objfile::get_type_for_signatured_type
9274 (signatured_type
*sig_type
) const
9276 auto iter
= this->m_type_map
.find (sig_type
);
9277 if (iter
== this->m_type_map
.end ())
9280 return iter
->second
;
9283 void dwarf2_per_objfile::set_type_for_signatured_type
9284 (signatured_type
*sig_type
, struct type
*type
)
9286 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9288 this->m_type_map
[sig_type
] = type
;
9291 /* A helper function for computing the list of all symbol tables
9292 included by PER_CU. */
9295 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9296 htab_t all_children
, htab_t all_type_symtabs
,
9297 dwarf2_per_cu_data
*per_cu
,
9298 dwarf2_per_objfile
*per_objfile
,
9299 struct compunit_symtab
*immediate_parent
)
9301 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9304 /* This inclusion and its children have been processed. */
9310 /* Only add a CU if it has a symbol table. */
9311 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9314 /* If this is a type unit only add its symbol table if we haven't
9315 seen it yet (type unit per_cu's can share symtabs). */
9316 if (per_cu
->is_debug_types
)
9318 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9322 result
->push_back (cust
);
9323 if (cust
->user
== NULL
)
9324 cust
->user
= immediate_parent
;
9329 result
->push_back (cust
);
9330 if (cust
->user
== NULL
)
9331 cust
->user
= immediate_parent
;
9335 if (!per_cu
->imported_symtabs_empty ())
9336 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9338 recursively_compute_inclusions (result
, all_children
,
9339 all_type_symtabs
, ptr
, per_objfile
,
9344 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9348 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9349 dwarf2_per_objfile
*per_objfile
)
9351 gdb_assert (! per_cu
->is_debug_types
);
9353 if (!per_cu
->imported_symtabs_empty ())
9356 std::vector
<compunit_symtab
*> result_symtabs
;
9357 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9359 /* If we don't have a symtab, we can just skip this case. */
9363 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9365 NULL
, xcalloc
, xfree
));
9366 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9368 NULL
, xcalloc
, xfree
));
9370 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9372 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9373 all_type_symtabs
.get (), ptr
,
9377 /* Now we have a transitive closure of all the included symtabs. */
9378 len
= result_symtabs
.size ();
9380 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9381 struct compunit_symtab
*, len
+ 1);
9382 memcpy (cust
->includes
, result_symtabs
.data (),
9383 len
* sizeof (compunit_symtab
*));
9384 cust
->includes
[len
] = NULL
;
9388 /* Compute the 'includes' field for the symtabs of all the CUs we just
9392 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9394 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9396 if (! iter
->is_debug_types
)
9397 compute_compunit_symtab_includes (iter
, per_objfile
);
9400 per_objfile
->per_bfd
->just_read_cus
.clear ();
9403 /* Generate full symbol information for CU, whose DIEs have
9404 already been loaded into memory. */
9407 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9409 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9410 struct objfile
*objfile
= per_objfile
->objfile
;
9411 struct gdbarch
*gdbarch
= objfile
->arch ();
9412 CORE_ADDR lowpc
, highpc
;
9413 struct compunit_symtab
*cust
;
9415 struct block
*static_block
;
9418 baseaddr
= objfile
->text_section_offset ();
9420 /* Clear the list here in case something was left over. */
9421 cu
->method_list
.clear ();
9423 dwarf2_find_base_address (cu
->dies
, cu
);
9425 /* Before we start reading the top-level DIE, ensure it has a valid tag
9427 switch (cu
->dies
->tag
)
9429 case DW_TAG_compile_unit
:
9430 case DW_TAG_partial_unit
:
9431 case DW_TAG_type_unit
:
9434 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9435 dwarf_tag_name (cu
->dies
->tag
),
9436 sect_offset_str (cu
->per_cu
->sect_off
),
9437 objfile_name (per_objfile
->objfile
));
9440 /* Do line number decoding in read_file_scope () */
9441 process_die (cu
->dies
, cu
);
9443 /* For now fudge the Go package. */
9444 if (cu
->per_cu
->lang
== language_go
)
9445 fixup_go_packaging (cu
);
9447 /* Now that we have processed all the DIEs in the CU, all the types
9448 should be complete, and it should now be safe to compute all of the
9450 compute_delayed_physnames (cu
);
9452 if (cu
->per_cu
->lang
== language_rust
)
9453 rust_union_quirks (cu
);
9455 /* Some compilers don't define a DW_AT_high_pc attribute for the
9456 compilation unit. If the DW_AT_high_pc is missing, synthesize
9457 it, by scanning the DIE's below the compilation unit. */
9458 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9460 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9462 = cu
->get_builder ()->end_compunit_symtab_get_static_block (addr
, 0, 1);
9464 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9465 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9466 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9467 addrmap to help ensure it has an accurate map of pc values belonging to
9469 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9471 cust
= cu
->get_builder ()->end_compunit_symtab_from_static_block
9472 (static_block
, SECT_OFF_TEXT (objfile
), 0);
9476 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9478 /* Set symtab language to language from DW_AT_language. If the
9479 compilation is from a C file generated by language preprocessors, do
9480 not set the language if it was already deduced by start_subfile. */
9481 if (!(cu
->per_cu
->lang
== language_c
9482 && cust
->primary_filetab ()->language () != language_unknown
))
9483 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
9485 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9486 produce DW_AT_location with location lists but it can be possibly
9487 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9488 there were bugs in prologue debug info, fixed later in GCC-4.5
9489 by "unwind info for epilogues" patch (which is not directly related).
9491 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9492 needed, it would be wrong due to missing DW_AT_producer there.
9494 Still one can confuse GDB by using non-standard GCC compilation
9495 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9497 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9498 cust
->set_locations_valid (true);
9500 if (gcc_4_minor
>= 5)
9501 cust
->set_epilogue_unwind_valid (true);
9503 cust
->set_call_site_htab (cu
->call_site_htab
);
9506 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9508 /* Push it for inclusion processing later. */
9509 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9511 /* Not needed any more. */
9512 cu
->reset_builder ();
9515 /* Generate full symbol information for type unit CU, whose DIEs have
9516 already been loaded into memory. */
9519 process_full_type_unit (dwarf2_cu
*cu
,
9520 enum language pretend_language
)
9522 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9523 struct objfile
*objfile
= per_objfile
->objfile
;
9524 struct compunit_symtab
*cust
;
9525 struct signatured_type
*sig_type
;
9527 gdb_assert (cu
->per_cu
->is_debug_types
);
9528 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9530 /* Clear the list here in case something was left over. */
9531 cu
->method_list
.clear ();
9533 /* The symbol tables are set up in read_type_unit_scope. */
9534 process_die (cu
->dies
, cu
);
9536 /* For now fudge the Go package. */
9537 if (cu
->per_cu
->lang
== language_go
)
9538 fixup_go_packaging (cu
);
9540 /* Now that we have processed all the DIEs in the CU, all the types
9541 should be complete, and it should now be safe to compute all of the
9543 compute_delayed_physnames (cu
);
9545 if (cu
->per_cu
->lang
== language_rust
)
9546 rust_union_quirks (cu
);
9548 /* TUs share symbol tables.
9549 If this is the first TU to use this symtab, complete the construction
9550 of it with end_expandable_symtab. Otherwise, complete the addition of
9551 this TU's symbols to the existing symtab. */
9552 type_unit_group_unshareable
*tug_unshare
=
9553 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9554 if (tug_unshare
->compunit_symtab
== NULL
)
9556 buildsym_compunit
*builder
= cu
->get_builder ();
9557 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9558 tug_unshare
->compunit_symtab
= cust
;
9562 /* Set symtab language to language from DW_AT_language. If the
9563 compilation is from a C file generated by language preprocessors,
9564 do not set the language if it was already deduced by
9566 if (!(cu
->per_cu
->lang
== language_c
9567 && cust
->primary_filetab ()->language () != language_c
))
9568 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
9573 cu
->get_builder ()->augment_type_symtab ();
9574 cust
= tug_unshare
->compunit_symtab
;
9577 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9579 /* Not needed any more. */
9580 cu
->reset_builder ();
9583 /* Process an imported unit DIE. */
9586 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9588 struct attribute
*attr
;
9590 /* For now we don't handle imported units in type units. */
9591 if (cu
->per_cu
->is_debug_types
)
9593 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9594 " supported in type units [in module %s]"),
9595 objfile_name (cu
->per_objfile
->objfile
));
9598 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9601 sect_offset sect_off
= attr
->get_ref_die_offset ();
9602 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9603 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9604 dwarf2_per_cu_data
*per_cu
9605 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9606 per_objfile
->per_bfd
);
9608 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9609 into another compilation unit, at root level. Regard this as a hint,
9611 if (die
->parent
&& die
->parent
->parent
== NULL
9612 && per_cu
->unit_type
== DW_UT_compile
9613 && per_cu
->lang
== language_cplus
)
9616 /* If necessary, add it to the queue and load its DIEs. */
9617 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9619 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9620 false, cu
->per_cu
->lang
);
9622 cu
->per_cu
->imported_symtabs_push (per_cu
);
9626 /* RAII object that represents a process_die scope: i.e.,
9627 starts/finishes processing a DIE. */
9628 class process_die_scope
9631 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9632 : m_die (die
), m_cu (cu
)
9634 /* We should only be processing DIEs not already in process. */
9635 gdb_assert (!m_die
->in_process
);
9636 m_die
->in_process
= true;
9639 ~process_die_scope ()
9641 m_die
->in_process
= false;
9643 /* If we're done processing the DIE for the CU that owns the line
9644 header, we don't need the line header anymore. */
9645 if (m_cu
->line_header_die_owner
== m_die
)
9647 delete m_cu
->line_header
;
9648 m_cu
->line_header
= NULL
;
9649 m_cu
->line_header_die_owner
= NULL
;
9658 /* Process a die and its children. */
9661 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9663 process_die_scope
scope (die
, cu
);
9667 case DW_TAG_padding
:
9669 case DW_TAG_compile_unit
:
9670 case DW_TAG_partial_unit
:
9671 read_file_scope (die
, cu
);
9673 case DW_TAG_type_unit
:
9674 read_type_unit_scope (die
, cu
);
9676 case DW_TAG_subprogram
:
9677 /* Nested subprograms in Fortran get a prefix. */
9678 if (cu
->per_cu
->lang
== language_fortran
9679 && die
->parent
!= NULL
9680 && die
->parent
->tag
== DW_TAG_subprogram
)
9681 cu
->processing_has_namespace_info
= true;
9683 case DW_TAG_inlined_subroutine
:
9684 read_func_scope (die
, cu
);
9686 case DW_TAG_lexical_block
:
9687 case DW_TAG_try_block
:
9688 case DW_TAG_catch_block
:
9689 read_lexical_block_scope (die
, cu
);
9691 case DW_TAG_call_site
:
9692 case DW_TAG_GNU_call_site
:
9693 read_call_site_scope (die
, cu
);
9695 case DW_TAG_class_type
:
9696 case DW_TAG_interface_type
:
9697 case DW_TAG_structure_type
:
9698 case DW_TAG_union_type
:
9699 case DW_TAG_namelist
:
9700 process_structure_scope (die
, cu
);
9702 case DW_TAG_enumeration_type
:
9703 process_enumeration_scope (die
, cu
);
9706 /* These dies have a type, but processing them does not create
9707 a symbol or recurse to process the children. Therefore we can
9708 read them on-demand through read_type_die. */
9709 case DW_TAG_subroutine_type
:
9710 case DW_TAG_set_type
:
9711 case DW_TAG_pointer_type
:
9712 case DW_TAG_ptr_to_member_type
:
9713 case DW_TAG_reference_type
:
9714 case DW_TAG_rvalue_reference_type
:
9715 case DW_TAG_string_type
:
9718 case DW_TAG_array_type
:
9719 /* We only need to handle this case for Ada -- in other
9720 languages, it's normal for the compiler to emit a typedef
9722 if (cu
->per_cu
->lang
!= language_ada
)
9725 case DW_TAG_base_type
:
9726 case DW_TAG_subrange_type
:
9727 case DW_TAG_generic_subrange
:
9728 case DW_TAG_typedef
:
9729 /* Add a typedef symbol for the type definition, if it has a
9731 new_symbol (die
, read_type_die (die
, cu
), cu
);
9733 case DW_TAG_common_block
:
9734 read_common_block (die
, cu
);
9736 case DW_TAG_common_inclusion
:
9738 case DW_TAG_namespace
:
9739 cu
->processing_has_namespace_info
= true;
9740 read_namespace (die
, cu
);
9743 cu
->processing_has_namespace_info
= true;
9744 read_module (die
, cu
);
9746 case DW_TAG_imported_declaration
:
9747 cu
->processing_has_namespace_info
= true;
9748 if (read_namespace_alias (die
, cu
))
9750 /* The declaration is not a global namespace alias. */
9752 case DW_TAG_imported_module
:
9753 cu
->processing_has_namespace_info
= true;
9754 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9755 || cu
->per_cu
->lang
!= language_fortran
))
9756 complaint (_("Tag '%s' has unexpected children"),
9757 dwarf_tag_name (die
->tag
));
9758 read_import_statement (die
, cu
);
9761 case DW_TAG_imported_unit
:
9762 process_imported_unit_die (die
, cu
);
9765 case DW_TAG_variable
:
9766 read_variable (die
, cu
);
9770 new_symbol (die
, NULL
, cu
);
9775 /* DWARF name computation. */
9777 /* A helper function for dwarf2_compute_name which determines whether DIE
9778 needs to have the name of the scope prepended to the name listed in the
9782 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9784 struct attribute
*attr
;
9788 case DW_TAG_namespace
:
9789 case DW_TAG_typedef
:
9790 case DW_TAG_class_type
:
9791 case DW_TAG_interface_type
:
9792 case DW_TAG_structure_type
:
9793 case DW_TAG_union_type
:
9794 case DW_TAG_enumeration_type
:
9795 case DW_TAG_enumerator
:
9796 case DW_TAG_subprogram
:
9797 case DW_TAG_inlined_subroutine
:
9799 case DW_TAG_imported_declaration
:
9802 case DW_TAG_variable
:
9803 case DW_TAG_constant
:
9804 /* We only need to prefix "globally" visible variables. These include
9805 any variable marked with DW_AT_external or any variable that
9806 lives in a namespace. [Variables in anonymous namespaces
9807 require prefixing, but they are not DW_AT_external.] */
9809 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9811 struct dwarf2_cu
*spec_cu
= cu
;
9813 return die_needs_namespace (die_specification (die
, &spec_cu
),
9817 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9818 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9819 && die
->parent
->tag
!= DW_TAG_module
)
9821 /* A variable in a lexical block of some kind does not need a
9822 namespace, even though in C++ such variables may be external
9823 and have a mangled name. */
9824 if (die
->parent
->tag
== DW_TAG_lexical_block
9825 || die
->parent
->tag
== DW_TAG_try_block
9826 || die
->parent
->tag
== DW_TAG_catch_block
9827 || die
->parent
->tag
== DW_TAG_subprogram
)
9836 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9837 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9838 defined for the given DIE. */
9840 static struct attribute
*
9841 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9843 struct attribute
*attr
;
9845 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9847 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9852 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9853 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9854 defined for the given DIE. */
9857 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9859 const char *linkage_name
;
9861 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9862 if (linkage_name
== NULL
)
9863 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9865 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9866 See https://github.com/rust-lang/rust/issues/32925. */
9867 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9868 && strchr (linkage_name
, '{') != NULL
)
9869 linkage_name
= NULL
;
9871 return linkage_name
;
9874 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9875 compute the physname for the object, which include a method's:
9876 - formal parameters (C++),
9877 - receiver type (Go),
9879 The term "physname" is a bit confusing.
9880 For C++, for example, it is the demangled name.
9881 For Go, for example, it's the mangled name.
9883 For Ada, return the DIE's linkage name rather than the fully qualified
9884 name. PHYSNAME is ignored..
9886 The result is allocated on the objfile->per_bfd's obstack and
9890 dwarf2_compute_name (const char *name
,
9891 struct die_info
*die
, struct dwarf2_cu
*cu
,
9894 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9897 name
= dwarf2_name (die
, cu
);
9899 enum language lang
= cu
->per_cu
->lang
;
9901 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9902 but otherwise compute it by typename_concat inside GDB.
9903 FIXME: Actually this is not really true, or at least not always true.
9904 It's all very confusing. compute_and_set_names doesn't try to demangle
9905 Fortran names because there is no mangling standard. So new_symbol
9906 will set the demangled name to the result of dwarf2_full_name, and it is
9907 the demangled name that GDB uses if it exists. */
9908 if (lang
== language_ada
9909 || (lang
== language_fortran
&& physname
))
9911 /* For Ada unit, we prefer the linkage name over the name, as
9912 the former contains the exported name, which the user expects
9913 to be able to reference. Ideally, we want the user to be able
9914 to reference this entity using either natural or linkage name,
9915 but we haven't started looking at this enhancement yet. */
9916 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9918 if (linkage_name
!= NULL
)
9919 return linkage_name
;
9922 /* These are the only languages we know how to qualify names in. */
9924 && (lang
== language_cplus
9925 || lang
== language_fortran
|| lang
== language_d
9926 || lang
== language_rust
))
9928 if (die_needs_namespace (die
, cu
))
9931 const char *canonical_name
= NULL
;
9935 prefix
= determine_prefix (die
, cu
);
9936 if (*prefix
!= '\0')
9938 gdb::unique_xmalloc_ptr
<char> prefixed_name
9939 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9941 buf
.puts (prefixed_name
.get ());
9946 /* Template parameters may be specified in the DIE's DW_AT_name, or
9947 as children with DW_TAG_template_type_param or
9948 DW_TAG_value_type_param. If the latter, add them to the name
9949 here. If the name already has template parameters, then
9950 skip this step; some versions of GCC emit both, and
9951 it is more efficient to use the pre-computed name.
9953 Something to keep in mind about this process: it is very
9954 unlikely, or in some cases downright impossible, to produce
9955 something that will match the mangled name of a function.
9956 If the definition of the function has the same debug info,
9957 we should be able to match up with it anyway. But fallbacks
9958 using the minimal symbol, for instance to find a method
9959 implemented in a stripped copy of libstdc++, will not work.
9960 If we do not have debug info for the definition, we will have to
9961 match them up some other way.
9963 When we do name matching there is a related problem with function
9964 templates; two instantiated function templates are allowed to
9965 differ only by their return types, which we do not add here. */
9967 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9969 struct attribute
*attr
;
9970 struct die_info
*child
;
9973 die
->building_fullname
= 1;
9975 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9979 const gdb_byte
*bytes
;
9980 struct dwarf2_locexpr_baton
*baton
;
9983 if (child
->tag
!= DW_TAG_template_type_param
9984 && child
->tag
!= DW_TAG_template_value_param
)
9995 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9998 complaint (_("template parameter missing DW_AT_type"));
9999 buf
.puts ("UNKNOWN_TYPE");
10002 type
= die_type (child
, cu
);
10004 if (child
->tag
== DW_TAG_template_type_param
)
10006 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
10007 &type_print_raw_options
);
10011 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10014 complaint (_("template parameter missing "
10015 "DW_AT_const_value"));
10016 buf
.puts ("UNKNOWN_VALUE");
10020 dwarf2_const_value_attr (attr
, type
, name
,
10021 &cu
->comp_unit_obstack
, cu
,
10022 &value
, &bytes
, &baton
);
10024 if (type
->has_no_signedness ())
10025 /* GDB prints characters as NUMBER 'CHAR'. If that's
10026 changed, this can use value_print instead. */
10027 cu
->language_defn
->printchar (value
, type
, &buf
);
10030 struct value_print_options opts
;
10033 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10037 baton
->per_objfile
);
10038 else if (bytes
!= NULL
)
10040 v
= allocate_value (type
);
10041 memcpy (value_contents_writeable (v
).data (), bytes
,
10042 TYPE_LENGTH (type
));
10045 v
= value_from_longest (type
, value
);
10047 /* Specify decimal so that we do not depend on
10049 get_formatted_print_options (&opts
, 'd');
10051 value_print (v
, &buf
, &opts
);
10056 die
->building_fullname
= 0;
10060 /* Close the argument list, with a space if necessary
10061 (nested templates). */
10062 if (!buf
.empty () && buf
.string ().back () == '>')
10069 /* For C++ methods, append formal parameter type
10070 information, if PHYSNAME. */
10072 if (physname
&& die
->tag
== DW_TAG_subprogram
10073 && lang
== language_cplus
)
10075 struct type
*type
= read_type_die (die
, cu
);
10077 c_type_print_args (type
, &buf
, 1, lang
,
10078 &type_print_raw_options
);
10080 if (lang
== language_cplus
)
10082 /* Assume that an artificial first parameter is
10083 "this", but do not crash if it is not. RealView
10084 marks unnamed (and thus unused) parameters as
10085 artificial; there is no way to differentiate
10087 if (type
->num_fields () > 0
10088 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10089 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10090 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10091 buf
.puts (" const");
10095 const std::string
&intermediate_name
= buf
.string ();
10097 if (lang
== language_cplus
)
10099 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10102 /* If we only computed INTERMEDIATE_NAME, or if
10103 INTERMEDIATE_NAME is already canonical, then we need to
10105 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10106 name
= objfile
->intern (intermediate_name
);
10108 name
= canonical_name
;
10115 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10116 If scope qualifiers are appropriate they will be added. The result
10117 will be allocated on the storage_obstack, or NULL if the DIE does
10118 not have a name. NAME may either be from a previous call to
10119 dwarf2_name or NULL.
10121 The output string will be canonicalized (if C++). */
10123 static const char *
10124 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10126 return dwarf2_compute_name (name
, die
, cu
, 0);
10129 /* Construct a physname for the given DIE in CU. NAME may either be
10130 from a previous call to dwarf2_name or NULL. The result will be
10131 allocated on the objfile_objstack or NULL if the DIE does not have a
10134 The output string will be canonicalized (if C++). */
10136 static const char *
10137 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10139 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10140 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10143 /* In this case dwarf2_compute_name is just a shortcut not building anything
10145 if (!die_needs_namespace (die
, cu
))
10146 return dwarf2_compute_name (name
, die
, cu
, 1);
10148 if (cu
->per_cu
->lang
!= language_rust
)
10149 mangled
= dw2_linkage_name (die
, cu
);
10151 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10153 gdb::unique_xmalloc_ptr
<char> demangled
;
10154 if (mangled
!= NULL
)
10156 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10158 /* Do nothing (do not demangle the symbol name). */
10162 /* Use DMGL_RET_DROP for C++ template functions to suppress
10163 their return type. It is easier for GDB users to search
10164 for such functions as `name(params)' than `long name(params)'.
10165 In such case the minimal symbol names do not match the full
10166 symbol names but for template functions there is never a need
10167 to look up their definition from their declaration so
10168 the only disadvantage remains the minimal symbol variant
10169 `long name(params)' does not have the proper inferior type. */
10170 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
10174 canon
= demangled
.get ();
10182 if (canon
== NULL
|| check_physname
)
10184 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10186 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10188 /* It may not mean a bug in GDB. The compiler could also
10189 compute DW_AT_linkage_name incorrectly. But in such case
10190 GDB would need to be bug-to-bug compatible. */
10192 complaint (_("Computed physname <%s> does not match demangled <%s> "
10193 "(from linkage <%s>) - DIE at %s [in module %s]"),
10194 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10195 objfile_name (objfile
));
10197 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10198 is available here - over computed PHYSNAME. It is safer
10199 against both buggy GDB and buggy compilers. */
10213 retval
= objfile
->intern (retval
);
10218 /* Inspect DIE in CU for a namespace alias. If one exists, record
10219 a new symbol for it.
10221 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10224 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10226 struct attribute
*attr
;
10228 /* If the die does not have a name, this is not a namespace
10230 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10234 struct die_info
*d
= die
;
10235 struct dwarf2_cu
*imported_cu
= cu
;
10237 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10238 keep inspecting DIEs until we hit the underlying import. */
10239 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10240 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10242 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10246 d
= follow_die_ref (d
, attr
, &imported_cu
);
10247 if (d
->tag
!= DW_TAG_imported_declaration
)
10251 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10253 complaint (_("DIE at %s has too many recursively imported "
10254 "declarations"), sect_offset_str (d
->sect_off
));
10261 sect_offset sect_off
= attr
->get_ref_die_offset ();
10263 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10264 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10266 /* This declaration is a global namespace alias. Add
10267 a symbol for it whose type is the aliased namespace. */
10268 new_symbol (die
, type
, cu
);
10277 /* Return the using directives repository (global or local?) to use in the
10278 current context for CU.
10280 For Ada, imported declarations can materialize renamings, which *may* be
10281 global. However it is impossible (for now?) in DWARF to distinguish
10282 "external" imported declarations and "static" ones. As all imported
10283 declarations seem to be static in all other languages, make them all CU-wide
10284 global only in Ada. */
10286 static struct using_direct
**
10287 using_directives (struct dwarf2_cu
*cu
)
10289 if (cu
->per_cu
->lang
== language_ada
10290 && cu
->get_builder ()->outermost_context_p ())
10291 return cu
->get_builder ()->get_global_using_directives ();
10293 return cu
->get_builder ()->get_local_using_directives ();
10296 /* Read the import statement specified by the given die and record it. */
10299 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10301 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10302 struct attribute
*import_attr
;
10303 struct die_info
*imported_die
, *child_die
;
10304 struct dwarf2_cu
*imported_cu
;
10305 const char *imported_name
;
10306 const char *imported_name_prefix
;
10307 const char *canonical_name
;
10308 const char *import_alias
;
10309 const char *imported_declaration
= NULL
;
10310 const char *import_prefix
;
10311 std::vector
<const char *> excludes
;
10313 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10314 if (import_attr
== NULL
)
10316 complaint (_("Tag '%s' has no DW_AT_import"),
10317 dwarf_tag_name (die
->tag
));
10322 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10323 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10324 if (imported_name
== NULL
)
10326 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10328 The import in the following code:
10342 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10343 <52> DW_AT_decl_file : 1
10344 <53> DW_AT_decl_line : 6
10345 <54> DW_AT_import : <0x75>
10346 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10347 <59> DW_AT_name : B
10348 <5b> DW_AT_decl_file : 1
10349 <5c> DW_AT_decl_line : 2
10350 <5d> DW_AT_type : <0x6e>
10352 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10353 <76> DW_AT_byte_size : 4
10354 <77> DW_AT_encoding : 5 (signed)
10356 imports the wrong die ( 0x75 instead of 0x58 ).
10357 This case will be ignored until the gcc bug is fixed. */
10361 /* Figure out the local name after import. */
10362 import_alias
= dwarf2_name (die
, cu
);
10364 /* Figure out where the statement is being imported to. */
10365 import_prefix
= determine_prefix (die
, cu
);
10367 /* Figure out what the scope of the imported die is and prepend it
10368 to the name of the imported die. */
10369 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10371 if (imported_die
->tag
!= DW_TAG_namespace
10372 && imported_die
->tag
!= DW_TAG_module
)
10374 imported_declaration
= imported_name
;
10375 canonical_name
= imported_name_prefix
;
10377 else if (strlen (imported_name_prefix
) > 0)
10378 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10379 imported_name_prefix
,
10380 (cu
->per_cu
->lang
== language_d
10383 imported_name
, (char *) NULL
);
10385 canonical_name
= imported_name
;
10387 if (die
->tag
== DW_TAG_imported_module
10388 && cu
->per_cu
->lang
== language_fortran
)
10389 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10390 child_die
= child_die
->sibling
)
10392 /* DWARF-4: A Fortran use statement with a “rename list” may be
10393 represented by an imported module entry with an import attribute
10394 referring to the module and owned entries corresponding to those
10395 entities that are renamed as part of being imported. */
10397 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10399 complaint (_("child DW_TAG_imported_declaration expected "
10400 "- DIE at %s [in module %s]"),
10401 sect_offset_str (child_die
->sect_off
),
10402 objfile_name (objfile
));
10406 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10407 if (import_attr
== NULL
)
10409 complaint (_("Tag '%s' has no DW_AT_import"),
10410 dwarf_tag_name (child_die
->tag
));
10415 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10417 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10418 if (imported_name
== NULL
)
10420 complaint (_("child DW_TAG_imported_declaration has unknown "
10421 "imported name - DIE at %s [in module %s]"),
10422 sect_offset_str (child_die
->sect_off
),
10423 objfile_name (objfile
));
10427 excludes
.push_back (imported_name
);
10429 process_die (child_die
, cu
);
10432 add_using_directive (using_directives (cu
),
10436 imported_declaration
,
10439 &objfile
->objfile_obstack
);
10442 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10443 types, but gives them a size of zero. Starting with version 14,
10444 ICC is compatible with GCC. */
10447 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10449 if (!cu
->checked_producer
)
10450 check_producer (cu
);
10452 return cu
->producer_is_icc_lt_14
;
10455 /* ICC generates a DW_AT_type for C void functions. This was observed on
10456 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10457 which says that void functions should not have a DW_AT_type. */
10460 producer_is_icc (struct dwarf2_cu
*cu
)
10462 if (!cu
->checked_producer
)
10463 check_producer (cu
);
10465 return cu
->producer_is_icc
;
10468 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10469 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10470 this, it was first present in GCC release 4.3.0. */
10473 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10475 if (!cu
->checked_producer
)
10476 check_producer (cu
);
10478 return cu
->producer_is_gcc_lt_4_3
;
10481 static file_and_directory
&
10482 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10484 if (cu
->per_cu
->fnd
!= nullptr)
10485 return *cu
->per_cu
->fnd
;
10487 /* Find the filename. Do not use dwarf2_name here, since the filename
10488 is not a source language identifier. */
10489 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
10490 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
10492 if (res
.get_comp_dir () == nullptr
10493 && producer_is_gcc_lt_4_3 (cu
)
10494 && res
.get_name () != nullptr
10495 && IS_ABSOLUTE_PATH (res
.get_name ()))
10496 res
.set_comp_dir (ldirname (res
.get_name ()));
10498 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
10499 return *cu
->per_cu
->fnd
;
10502 /* Handle DW_AT_stmt_list for a compilation unit.
10503 DIE is the DW_TAG_compile_unit die for CU.
10504 COMP_DIR is the compilation directory. LOWPC is passed to
10505 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10508 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10509 const file_and_directory
&fnd
, CORE_ADDR lowpc
) /* ARI: editCase function */
10511 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10512 struct attribute
*attr
;
10513 struct line_header line_header_local
;
10514 hashval_t line_header_local_hash
;
10516 int decode_mapping
;
10518 gdb_assert (! cu
->per_cu
->is_debug_types
);
10520 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10521 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10524 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10526 /* The line header hash table is only created if needed (it exists to
10527 prevent redundant reading of the line table for partial_units).
10528 If we're given a partial_unit, we'll need it. If we're given a
10529 compile_unit, then use the line header hash table if it's already
10530 created, but don't create one just yet. */
10532 if (per_objfile
->line_header_hash
== NULL
10533 && die
->tag
== DW_TAG_partial_unit
)
10535 per_objfile
->line_header_hash
10536 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10537 line_header_eq_voidp
,
10538 htab_delete_entry
<line_header
>,
10542 line_header_local
.sect_off
= line_offset
;
10543 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10544 line_header_local_hash
= line_header_hash (&line_header_local
);
10545 if (per_objfile
->line_header_hash
!= NULL
)
10547 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10548 &line_header_local
,
10549 line_header_local_hash
, NO_INSERT
);
10551 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10552 is not present in *SLOT (since if there is something in *SLOT then
10553 it will be for a partial_unit). */
10554 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10556 gdb_assert (*slot
!= NULL
);
10557 cu
->line_header
= (struct line_header
*) *slot
;
10562 /* dwarf_decode_line_header does not yet provide sufficient information.
10563 We always have to call also dwarf_decode_lines for it. */
10564 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10568 cu
->line_header
= lh
.release ();
10569 cu
->line_header_die_owner
= die
;
10571 if (per_objfile
->line_header_hash
== NULL
)
10575 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10576 &line_header_local
,
10577 line_header_local_hash
, INSERT
);
10578 gdb_assert (slot
!= NULL
);
10580 if (slot
!= NULL
&& *slot
== NULL
)
10582 /* This newly decoded line number information unit will be owned
10583 by line_header_hash hash table. */
10584 *slot
= cu
->line_header
;
10585 cu
->line_header_die_owner
= NULL
;
10589 /* We cannot free any current entry in (*slot) as that struct line_header
10590 may be already used by multiple CUs. Create only temporary decoded
10591 line_header for this CU - it may happen at most once for each line
10592 number information unit. And if we're not using line_header_hash
10593 then this is what we want as well. */
10594 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10596 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10597 dwarf_decode_lines (cu
->line_header
, fnd
, cu
, nullptr, lowpc
,
10602 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10605 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10607 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10608 struct objfile
*objfile
= per_objfile
->objfile
;
10609 struct gdbarch
*gdbarch
= objfile
->arch ();
10610 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10611 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10612 struct attribute
*attr
;
10613 struct die_info
*child_die
;
10614 CORE_ADDR baseaddr
;
10616 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10617 baseaddr
= objfile
->text_section_offset ();
10619 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10621 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10622 from finish_block. */
10623 if (lowpc
== ((CORE_ADDR
) -1))
10625 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10627 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
10629 cu
->start_compunit_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
),
10632 gdb_assert (per_objfile
->sym_cu
== nullptr);
10633 scoped_restore restore_sym_cu
10634 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10636 /* Decode line number information if present. We do this before
10637 processing child DIEs, so that the line header table is available
10638 for DW_AT_decl_file. The PC check is here because, if LOWPC and
10639 HIGHPC are both 0x0, then there won't be any interesting code in
10640 the CU, but a check later on (in
10641 lnp_state_machine::check_line_address) will fail to properly
10642 exclude an entry that was removed via --gc-sections. */
10643 if (lowpc
!= highpc
)
10644 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
);
10646 /* Process all dies in compilation unit. */
10647 if (die
->child
!= NULL
)
10649 child_die
= die
->child
;
10650 while (child_die
&& child_die
->tag
)
10652 process_die (child_die
, cu
);
10653 child_die
= child_die
->sibling
;
10656 per_objfile
->sym_cu
= nullptr;
10658 /* Decode macro information, if present. Dwarf 2 macro information
10659 refers to information in the line number info statement program
10660 header, so we can only read it if we've read the header
10662 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10664 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10665 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10667 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10668 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10670 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10674 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10675 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10677 unsigned int macro_offset
= attr
->as_unsigned ();
10679 dwarf_decode_macros (cu
, macro_offset
, 0);
10685 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10687 struct type_unit_group
*tu_group
;
10689 struct attribute
*attr
;
10691 struct signatured_type
*sig_type
;
10693 gdb_assert (per_cu
->is_debug_types
);
10694 sig_type
= (struct signatured_type
*) per_cu
;
10696 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10698 /* If we're using .gdb_index (includes -readnow) then
10699 per_cu->type_unit_group may not have been set up yet. */
10700 if (sig_type
->type_unit_group
== NULL
)
10701 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10702 tu_group
= sig_type
->type_unit_group
;
10704 /* If we've already processed this stmt_list there's no real need to
10705 do it again, we could fake it and just recreate the part we need
10706 (file name,index -> symtab mapping). If data shows this optimization
10707 is useful we can do it then. */
10708 type_unit_group_unshareable
*tug_unshare
10709 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10710 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10712 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10715 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10717 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10718 lh
= dwarf_decode_line_header (line_offset
, this);
10723 start_compunit_symtab ("", NULL
, 0);
10726 gdb_assert (tug_unshare
->symtabs
== NULL
);
10727 gdb_assert (m_builder
== nullptr);
10728 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10729 m_builder
.reset (new struct buildsym_compunit
10730 (cust
->objfile (), "",
10732 compunit_language (cust
),
10734 list_in_scope
= get_builder ()->get_file_symbols ();
10739 line_header
= lh
.release ();
10740 line_header_die_owner
= die
;
10744 struct compunit_symtab
*cust
= start_compunit_symtab ("", NULL
, 0);
10746 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10747 still initializing it, and our caller (a few levels up)
10748 process_full_type_unit still needs to know if this is the first
10751 tug_unshare
->symtabs
10752 = XOBNEWVEC (&cust
->objfile ()->objfile_obstack
,
10753 struct symtab
*, line_header
->file_names_size ());
10755 auto &file_names
= line_header
->file_names ();
10756 for (i
= 0; i
< file_names
.size (); ++i
)
10758 file_entry
&fe
= file_names
[i
];
10759 dwarf2_start_subfile (this, fe
.name
,
10760 fe
.include_dir (line_header
));
10761 buildsym_compunit
*b
= get_builder ();
10762 if (b
->get_current_subfile ()->symtab
== NULL
)
10764 /* NOTE: start_subfile will recognize when it's been
10765 passed a file it has already seen. So we can't
10766 assume there's a simple mapping from
10767 cu->line_header->file_names to subfiles, plus
10768 cu->line_header->file_names may contain dups. */
10769 b
->get_current_subfile ()->symtab
10770 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10773 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10774 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10779 gdb_assert (m_builder
== nullptr);
10780 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10781 m_builder
.reset (new struct buildsym_compunit
10782 (cust
->objfile (), "",
10784 compunit_language (cust
),
10786 list_in_scope
= get_builder ()->get_file_symbols ();
10788 auto &file_names
= line_header
->file_names ();
10789 for (i
= 0; i
< file_names
.size (); ++i
)
10791 file_entry
&fe
= file_names
[i
];
10792 fe
.symtab
= tug_unshare
->symtabs
[i
];
10796 /* The main symtab is allocated last. Type units don't have DW_AT_name
10797 so they don't have a "real" (so to speak) symtab anyway.
10798 There is later code that will assign the main symtab to all symbols
10799 that don't have one. We need to handle the case of a symbol with a
10800 missing symtab (DW_AT_decl_file) anyway. */
10803 /* Process DW_TAG_type_unit.
10804 For TUs we want to skip the first top level sibling if it's not the
10805 actual type being defined by this TU. In this case the first top
10806 level sibling is there to provide context only. */
10809 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10811 struct die_info
*child_die
;
10813 prepare_one_comp_unit (cu
, die
, language_minimal
);
10815 /* Initialize (or reinitialize) the machinery for building symtabs.
10816 We do this before processing child DIEs, so that the line header table
10817 is available for DW_AT_decl_file. */
10818 cu
->setup_type_unit_groups (die
);
10820 if (die
->child
!= NULL
)
10822 child_die
= die
->child
;
10823 while (child_die
&& child_die
->tag
)
10825 process_die (child_die
, cu
);
10826 child_die
= child_die
->sibling
;
10833 http://gcc.gnu.org/wiki/DebugFission
10834 http://gcc.gnu.org/wiki/DebugFissionDWP
10836 To simplify handling of both DWO files ("object" files with the DWARF info)
10837 and DWP files (a file with the DWOs packaged up into one file), we treat
10838 DWP files as having a collection of virtual DWO files. */
10841 hash_dwo_file (const void *item
)
10843 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10846 hash
= htab_hash_string (dwo_file
->dwo_name
);
10847 if (dwo_file
->comp_dir
!= NULL
)
10848 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10853 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10855 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10856 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10858 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10860 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10861 return lhs
->comp_dir
== rhs
->comp_dir
;
10862 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10865 /* Allocate a hash table for DWO files. */
10868 allocate_dwo_file_hash_table ()
10870 return htab_up (htab_create_alloc (41,
10873 htab_delete_entry
<dwo_file
>,
10877 /* Lookup DWO file DWO_NAME. */
10880 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10881 const char *dwo_name
,
10882 const char *comp_dir
)
10884 struct dwo_file find_entry
;
10887 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10888 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10890 find_entry
.dwo_name
= dwo_name
;
10891 find_entry
.comp_dir
= comp_dir
;
10892 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10899 hash_dwo_unit (const void *item
)
10901 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10903 /* This drops the top 32 bits of the id, but is ok for a hash. */
10904 return dwo_unit
->signature
;
10908 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10910 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10911 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10913 /* The signature is assumed to be unique within the DWO file.
10914 So while object file CU dwo_id's always have the value zero,
10915 that's OK, assuming each object file DWO file has only one CU,
10916 and that's the rule for now. */
10917 return lhs
->signature
== rhs
->signature
;
10920 /* Allocate a hash table for DWO CUs,TUs.
10921 There is one of these tables for each of CUs,TUs for each DWO file. */
10924 allocate_dwo_unit_table ()
10926 /* Start out with a pretty small number.
10927 Generally DWO files contain only one CU and maybe some TUs. */
10928 return htab_up (htab_create_alloc (3,
10931 NULL
, xcalloc
, xfree
));
10934 /* die_reader_func for create_dwo_cu. */
10937 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10938 const gdb_byte
*info_ptr
,
10939 struct die_info
*comp_unit_die
,
10940 struct dwo_file
*dwo_file
,
10941 struct dwo_unit
*dwo_unit
)
10943 struct dwarf2_cu
*cu
= reader
->cu
;
10944 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10945 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10947 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10948 if (!signature
.has_value ())
10950 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10951 " its dwo_id [in module %s]"),
10952 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10956 dwo_unit
->dwo_file
= dwo_file
;
10957 dwo_unit
->signature
= *signature
;
10958 dwo_unit
->section
= section
;
10959 dwo_unit
->sect_off
= sect_off
;
10960 dwo_unit
->length
= cu
->per_cu
->length
;
10962 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10963 sect_offset_str (sect_off
),
10964 hex_string (dwo_unit
->signature
));
10967 /* Create the dwo_units for the CUs in a DWO_FILE.
10968 Note: This function processes DWO files only, not DWP files. */
10971 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10972 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10973 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10975 struct objfile
*objfile
= per_objfile
->objfile
;
10976 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10977 const gdb_byte
*info_ptr
, *end_ptr
;
10979 section
.read (objfile
);
10980 info_ptr
= section
.buffer
;
10982 if (info_ptr
== NULL
)
10985 dwarf_read_debug_printf ("Reading %s for %s:",
10986 section
.get_name (),
10987 section
.get_file_name ());
10989 end_ptr
= info_ptr
+ section
.size
;
10990 while (info_ptr
< end_ptr
)
10992 struct dwarf2_per_cu_data per_cu
;
10993 struct dwo_unit read_unit
{};
10994 struct dwo_unit
*dwo_unit
;
10996 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10998 per_cu
.per_bfd
= per_bfd
;
10999 per_cu
.is_debug_types
= 0;
11000 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11001 per_cu
.section
= §ion
;
11003 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11004 if (!reader
.dummy_p
)
11005 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11006 &dwo_file
, &read_unit
);
11007 info_ptr
+= per_cu
.length
;
11009 // If the unit could not be parsed, skip it.
11010 if (read_unit
.dwo_file
== NULL
)
11013 if (cus_htab
== NULL
)
11014 cus_htab
= allocate_dwo_unit_table ();
11016 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11018 *dwo_unit
= read_unit
;
11019 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11020 gdb_assert (slot
!= NULL
);
11023 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11024 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11026 complaint (_("debug cu entry at offset %s is duplicate to"
11027 " the entry at offset %s, signature %s"),
11028 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11029 hex_string (dwo_unit
->signature
));
11031 *slot
= (void *)dwo_unit
;
11035 /* DWP file .debug_{cu,tu}_index section format:
11036 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11037 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11039 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11040 officially standard DWP format was published with DWARF v5 and is called
11041 Version 5. There are no versions 3 or 4.
11045 Both index sections have the same format, and serve to map a 64-bit
11046 signature to a set of section numbers. Each section begins with a header,
11047 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11048 indexes, and a pool of 32-bit section numbers. The index sections will be
11049 aligned at 8-byte boundaries in the file.
11051 The index section header consists of:
11053 V, 32 bit version number
11055 N, 32 bit number of compilation units or type units in the index
11056 M, 32 bit number of slots in the hash table
11058 Numbers are recorded using the byte order of the application binary.
11060 The hash table begins at offset 16 in the section, and consists of an array
11061 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11062 order of the application binary). Unused slots in the hash table are 0.
11063 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11065 The parallel table begins immediately after the hash table
11066 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11067 array of 32-bit indexes (using the byte order of the application binary),
11068 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11069 table contains a 32-bit index into the pool of section numbers. For unused
11070 hash table slots, the corresponding entry in the parallel table will be 0.
11072 The pool of section numbers begins immediately following the hash table
11073 (at offset 16 + 12 * M from the beginning of the section). The pool of
11074 section numbers consists of an array of 32-bit words (using the byte order
11075 of the application binary). Each item in the array is indexed starting
11076 from 0. The hash table entry provides the index of the first section
11077 number in the set. Additional section numbers in the set follow, and the
11078 set is terminated by a 0 entry (section number 0 is not used in ELF).
11080 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11081 section must be the first entry in the set, and the .debug_abbrev.dwo must
11082 be the second entry. Other members of the set may follow in any order.
11086 DWP Versions 2 and 5:
11088 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11089 and the entries in the index tables are now offsets into these sections.
11090 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11093 Index Section Contents:
11095 Hash Table of Signatures dwp_hash_table.hash_table
11096 Parallel Table of Indices dwp_hash_table.unit_table
11097 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11098 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11100 The index section header consists of:
11102 V, 32 bit version number
11103 L, 32 bit number of columns in the table of section offsets
11104 N, 32 bit number of compilation units or type units in the index
11105 M, 32 bit number of slots in the hash table
11107 Numbers are recorded using the byte order of the application binary.
11109 The hash table has the same format as version 1.
11110 The parallel table of indices has the same format as version 1,
11111 except that the entries are origin-1 indices into the table of sections
11112 offsets and the table of section sizes.
11114 The table of offsets begins immediately following the parallel table
11115 (at offset 16 + 12 * M from the beginning of the section). The table is
11116 a two-dimensional array of 32-bit words (using the byte order of the
11117 application binary), with L columns and N+1 rows, in row-major order.
11118 Each row in the array is indexed starting from 0. The first row provides
11119 a key to the remaining rows: each column in this row provides an identifier
11120 for a debug section, and the offsets in the same column of subsequent rows
11121 refer to that section. The section identifiers for Version 2 are:
11123 DW_SECT_INFO 1 .debug_info.dwo
11124 DW_SECT_TYPES 2 .debug_types.dwo
11125 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11126 DW_SECT_LINE 4 .debug_line.dwo
11127 DW_SECT_LOC 5 .debug_loc.dwo
11128 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11129 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11130 DW_SECT_MACRO 8 .debug_macro.dwo
11132 The section identifiers for Version 5 are:
11134 DW_SECT_INFO_V5 1 .debug_info.dwo
11135 DW_SECT_RESERVED_V5 2 --
11136 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11137 DW_SECT_LINE_V5 4 .debug_line.dwo
11138 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11139 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11140 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11141 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11143 The offsets provided by the CU and TU index sections are the base offsets
11144 for the contributions made by each CU or TU to the corresponding section
11145 in the package file. Each CU and TU header contains an abbrev_offset
11146 field, used to find the abbreviations table for that CU or TU within the
11147 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11148 be interpreted as relative to the base offset given in the index section.
11149 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11150 should be interpreted as relative to the base offset for .debug_line.dwo,
11151 and offsets into other debug sections obtained from DWARF attributes should
11152 also be interpreted as relative to the corresponding base offset.
11154 The table of sizes begins immediately following the table of offsets.
11155 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11156 with L columns and N rows, in row-major order. Each row in the array is
11157 indexed starting from 1 (row 0 is shared by the two tables).
11161 Hash table lookup is handled the same in version 1 and 2:
11163 We assume that N and M will not exceed 2^32 - 1.
11164 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11166 Given a 64-bit compilation unit signature or a type signature S, an entry
11167 in the hash table is located as follows:
11169 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11170 the low-order k bits all set to 1.
11172 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11174 3) If the hash table entry at index H matches the signature, use that
11175 entry. If the hash table entry at index H is unused (all zeroes),
11176 terminate the search: the signature is not present in the table.
11178 4) Let H = (H + H') modulo M. Repeat at Step 3.
11180 Because M > N and H' and M are relatively prime, the search is guaranteed
11181 to stop at an unused slot or find the match. */
11183 /* Create a hash table to map DWO IDs to their CU/TU entry in
11184 .debug_{info,types}.dwo in DWP_FILE.
11185 Returns NULL if there isn't one.
11186 Note: This function processes DWP files only, not DWO files. */
11188 static struct dwp_hash_table
*
11189 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11190 struct dwp_file
*dwp_file
, int is_debug_types
)
11192 struct objfile
*objfile
= per_objfile
->objfile
;
11193 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11194 const gdb_byte
*index_ptr
, *index_end
;
11195 struct dwarf2_section_info
*index
;
11196 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11197 struct dwp_hash_table
*htab
;
11199 if (is_debug_types
)
11200 index
= &dwp_file
->sections
.tu_index
;
11202 index
= &dwp_file
->sections
.cu_index
;
11204 if (index
->empty ())
11206 index
->read (objfile
);
11208 index_ptr
= index
->buffer
;
11209 index_end
= index_ptr
+ index
->size
;
11211 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11212 For now it's safe to just read 4 bytes (particularly as it's difficult to
11213 tell if you're dealing with Version 5 before you've read the version). */
11214 version
= read_4_bytes (dbfd
, index_ptr
);
11216 if (version
== 2 || version
== 5)
11217 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11221 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11223 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11226 if (version
!= 1 && version
!= 2 && version
!= 5)
11228 error (_("Dwarf Error: unsupported DWP file version (%s)"
11229 " [in module %s]"),
11230 pulongest (version
), dwp_file
->name
);
11232 if (nr_slots
!= (nr_slots
& -nr_slots
))
11234 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11235 " is not power of 2 [in module %s]"),
11236 pulongest (nr_slots
), dwp_file
->name
);
11239 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11240 htab
->version
= version
;
11241 htab
->nr_columns
= nr_columns
;
11242 htab
->nr_units
= nr_units
;
11243 htab
->nr_slots
= nr_slots
;
11244 htab
->hash_table
= index_ptr
;
11245 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11247 /* Exit early if the table is empty. */
11248 if (nr_slots
== 0 || nr_units
== 0
11249 || (version
== 2 && nr_columns
== 0)
11250 || (version
== 5 && nr_columns
== 0))
11252 /* All must be zero. */
11253 if (nr_slots
!= 0 || nr_units
!= 0
11254 || (version
== 2 && nr_columns
!= 0)
11255 || (version
== 5 && nr_columns
!= 0))
11257 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11258 " all zero [in modules %s]"),
11266 htab
->section_pool
.v1
.indices
=
11267 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11268 /* It's harder to decide whether the section is too small in v1.
11269 V1 is deprecated anyway so we punt. */
11271 else if (version
== 2)
11273 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11274 int *ids
= htab
->section_pool
.v2
.section_ids
;
11275 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11276 /* Reverse map for error checking. */
11277 int ids_seen
[DW_SECT_MAX
+ 1];
11280 if (nr_columns
< 2)
11282 error (_("Dwarf Error: bad DWP hash table, too few columns"
11283 " in section table [in module %s]"),
11286 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11288 error (_("Dwarf Error: bad DWP hash table, too many columns"
11289 " in section table [in module %s]"),
11292 memset (ids
, 255, sizeof_ids
);
11293 memset (ids_seen
, 255, sizeof (ids_seen
));
11294 for (i
= 0; i
< nr_columns
; ++i
)
11296 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11298 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11300 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11301 " in section table [in module %s]"),
11302 id
, dwp_file
->name
);
11304 if (ids_seen
[id
] != -1)
11306 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11307 " id %d in section table [in module %s]"),
11308 id
, dwp_file
->name
);
11313 /* Must have exactly one info or types section. */
11314 if (((ids_seen
[DW_SECT_INFO
] != -1)
11315 + (ids_seen
[DW_SECT_TYPES
] != -1))
11318 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11319 " DWO info/types section [in module %s]"),
11322 /* Must have an abbrev section. */
11323 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11325 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11326 " section [in module %s]"),
11329 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11330 htab
->section_pool
.v2
.sizes
=
11331 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11332 * nr_units
* nr_columns
);
11333 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11334 * nr_units
* nr_columns
))
11337 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11338 " [in module %s]"),
11342 else /* version == 5 */
11344 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11345 int *ids
= htab
->section_pool
.v5
.section_ids
;
11346 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11347 /* Reverse map for error checking. */
11348 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11350 if (nr_columns
< 2)
11352 error (_("Dwarf Error: bad DWP hash table, too few columns"
11353 " in section table [in module %s]"),
11356 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11358 error (_("Dwarf Error: bad DWP hash table, too many columns"
11359 " in section table [in module %s]"),
11362 memset (ids
, 255, sizeof_ids
);
11363 memset (ids_seen
, 255, sizeof (ids_seen
));
11364 for (int i
= 0; i
< nr_columns
; ++i
)
11366 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11368 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11370 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11371 " in section table [in module %s]"),
11372 id
, dwp_file
->name
);
11374 if (ids_seen
[id
] != -1)
11376 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11377 " id %d in section table [in module %s]"),
11378 id
, dwp_file
->name
);
11383 /* Must have seen an info section. */
11384 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11386 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11387 " DWO info/types section [in module %s]"),
11390 /* Must have an abbrev section. */
11391 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11393 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11394 " section [in module %s]"),
11397 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11398 htab
->section_pool
.v5
.sizes
11399 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11400 * nr_units
* nr_columns
);
11401 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11402 * nr_units
* nr_columns
))
11405 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11406 " [in module %s]"),
11414 /* Update SECTIONS with the data from SECTP.
11416 This function is like the other "locate" section routines, but in
11417 this context the sections to read comes from the DWP V1 hash table,
11418 not the full ELF section table.
11420 The result is non-zero for success, or zero if an error was found. */
11423 locate_v1_virtual_dwo_sections (asection
*sectp
,
11424 struct virtual_v1_dwo_sections
*sections
)
11426 const struct dwop_section_names
*names
= &dwop_section_names
;
11428 if (names
->abbrev_dwo
.matches (sectp
->name
))
11430 /* There can be only one. */
11431 if (sections
->abbrev
.s
.section
!= NULL
)
11433 sections
->abbrev
.s
.section
= sectp
;
11434 sections
->abbrev
.size
= bfd_section_size (sectp
);
11436 else if (names
->info_dwo
.matches (sectp
->name
)
11437 || names
->types_dwo
.matches (sectp
->name
))
11439 /* There can be only one. */
11440 if (sections
->info_or_types
.s
.section
!= NULL
)
11442 sections
->info_or_types
.s
.section
= sectp
;
11443 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11445 else if (names
->line_dwo
.matches (sectp
->name
))
11447 /* There can be only one. */
11448 if (sections
->line
.s
.section
!= NULL
)
11450 sections
->line
.s
.section
= sectp
;
11451 sections
->line
.size
= bfd_section_size (sectp
);
11453 else if (names
->loc_dwo
.matches (sectp
->name
))
11455 /* There can be only one. */
11456 if (sections
->loc
.s
.section
!= NULL
)
11458 sections
->loc
.s
.section
= sectp
;
11459 sections
->loc
.size
= bfd_section_size (sectp
);
11461 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11463 /* There can be only one. */
11464 if (sections
->macinfo
.s
.section
!= NULL
)
11466 sections
->macinfo
.s
.section
= sectp
;
11467 sections
->macinfo
.size
= bfd_section_size (sectp
);
11469 else if (names
->macro_dwo
.matches (sectp
->name
))
11471 /* There can be only one. */
11472 if (sections
->macro
.s
.section
!= NULL
)
11474 sections
->macro
.s
.section
= sectp
;
11475 sections
->macro
.size
= bfd_section_size (sectp
);
11477 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11479 /* There can be only one. */
11480 if (sections
->str_offsets
.s
.section
!= NULL
)
11482 sections
->str_offsets
.s
.section
= sectp
;
11483 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11487 /* No other kind of section is valid. */
11494 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11495 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11496 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11497 This is for DWP version 1 files. */
11499 static struct dwo_unit
*
11500 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11501 struct dwp_file
*dwp_file
,
11502 uint32_t unit_index
,
11503 const char *comp_dir
,
11504 ULONGEST signature
, int is_debug_types
)
11506 const struct dwp_hash_table
*dwp_htab
=
11507 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11508 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11509 const char *kind
= is_debug_types
? "TU" : "CU";
11510 struct dwo_file
*dwo_file
;
11511 struct dwo_unit
*dwo_unit
;
11512 struct virtual_v1_dwo_sections sections
;
11513 void **dwo_file_slot
;
11516 gdb_assert (dwp_file
->version
== 1);
11518 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11519 kind
, pulongest (unit_index
), hex_string (signature
),
11522 /* Fetch the sections of this DWO unit.
11523 Put a limit on the number of sections we look for so that bad data
11524 doesn't cause us to loop forever. */
11526 #define MAX_NR_V1_DWO_SECTIONS \
11527 (1 /* .debug_info or .debug_types */ \
11528 + 1 /* .debug_abbrev */ \
11529 + 1 /* .debug_line */ \
11530 + 1 /* .debug_loc */ \
11531 + 1 /* .debug_str_offsets */ \
11532 + 1 /* .debug_macro or .debug_macinfo */ \
11533 + 1 /* trailing zero */)
11535 memset (§ions
, 0, sizeof (sections
));
11537 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11540 uint32_t section_nr
=
11541 read_4_bytes (dbfd
,
11542 dwp_htab
->section_pool
.v1
.indices
11543 + (unit_index
+ i
) * sizeof (uint32_t));
11545 if (section_nr
== 0)
11547 if (section_nr
>= dwp_file
->num_sections
)
11549 error (_("Dwarf Error: bad DWP hash table, section number too large"
11550 " [in module %s]"),
11554 sectp
= dwp_file
->elf_sections
[section_nr
];
11555 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11557 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11558 " [in module %s]"),
11564 || sections
.info_or_types
.empty ()
11565 || sections
.abbrev
.empty ())
11567 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11568 " [in module %s]"),
11571 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11573 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11574 " [in module %s]"),
11578 /* It's easier for the rest of the code if we fake a struct dwo_file and
11579 have dwo_unit "live" in that. At least for now.
11581 The DWP file can be made up of a random collection of CUs and TUs.
11582 However, for each CU + set of TUs that came from the same original DWO
11583 file, we can combine them back into a virtual DWO file to save space
11584 (fewer struct dwo_file objects to allocate). Remember that for really
11585 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11587 std::string virtual_dwo_name
=
11588 string_printf ("virtual-dwo/%d-%d-%d-%d",
11589 sections
.abbrev
.get_id (),
11590 sections
.line
.get_id (),
11591 sections
.loc
.get_id (),
11592 sections
.str_offsets
.get_id ());
11593 /* Can we use an existing virtual DWO file? */
11594 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11596 /* Create one if necessary. */
11597 if (*dwo_file_slot
== NULL
)
11599 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11600 virtual_dwo_name
.c_str ());
11602 dwo_file
= new struct dwo_file
;
11603 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11604 dwo_file
->comp_dir
= comp_dir
;
11605 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11606 dwo_file
->sections
.line
= sections
.line
;
11607 dwo_file
->sections
.loc
= sections
.loc
;
11608 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11609 dwo_file
->sections
.macro
= sections
.macro
;
11610 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11611 /* The "str" section is global to the entire DWP file. */
11612 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11613 /* The info or types section is assigned below to dwo_unit,
11614 there's no need to record it in dwo_file.
11615 Also, we can't simply record type sections in dwo_file because
11616 we record a pointer into the vector in dwo_unit. As we collect more
11617 types we'll grow the vector and eventually have to reallocate space
11618 for it, invalidating all copies of pointers into the previous
11620 *dwo_file_slot
= dwo_file
;
11624 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11625 virtual_dwo_name
.c_str ());
11627 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11630 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11631 dwo_unit
->dwo_file
= dwo_file
;
11632 dwo_unit
->signature
= signature
;
11633 dwo_unit
->section
=
11634 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11635 *dwo_unit
->section
= sections
.info_or_types
;
11636 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11641 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11642 simplify them. Given a pointer to the containing section SECTION, and
11643 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11644 virtual section of just that piece. */
11646 static struct dwarf2_section_info
11647 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11648 struct dwarf2_section_info
*section
,
11649 bfd_size_type offset
, bfd_size_type size
)
11651 struct dwarf2_section_info result
;
11654 gdb_assert (section
!= NULL
);
11655 gdb_assert (!section
->is_virtual
);
11657 memset (&result
, 0, sizeof (result
));
11658 result
.s
.containing_section
= section
;
11659 result
.is_virtual
= true;
11664 sectp
= section
->get_bfd_section ();
11666 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11667 bounds of the real section. This is a pretty-rare event, so just
11668 flag an error (easier) instead of a warning and trying to cope. */
11670 || offset
+ size
> bfd_section_size (sectp
))
11672 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11673 " in section %s [in module %s]"),
11674 sectp
? bfd_section_name (sectp
) : "<unknown>",
11675 objfile_name (per_objfile
->objfile
));
11678 result
.virtual_offset
= offset
;
11679 result
.size
= size
;
11683 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11684 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11685 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11686 This is for DWP version 2 files. */
11688 static struct dwo_unit
*
11689 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11690 struct dwp_file
*dwp_file
,
11691 uint32_t unit_index
,
11692 const char *comp_dir
,
11693 ULONGEST signature
, int is_debug_types
)
11695 const struct dwp_hash_table
*dwp_htab
=
11696 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11697 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11698 const char *kind
= is_debug_types
? "TU" : "CU";
11699 struct dwo_file
*dwo_file
;
11700 struct dwo_unit
*dwo_unit
;
11701 struct virtual_v2_or_v5_dwo_sections sections
;
11702 void **dwo_file_slot
;
11705 gdb_assert (dwp_file
->version
== 2);
11707 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11708 kind
, pulongest (unit_index
), hex_string (signature
),
11711 /* Fetch the section offsets of this DWO unit. */
11713 memset (§ions
, 0, sizeof (sections
));
11715 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11717 uint32_t offset
= read_4_bytes (dbfd
,
11718 dwp_htab
->section_pool
.v2
.offsets
11719 + (((unit_index
- 1) * dwp_htab
->nr_columns
11721 * sizeof (uint32_t)));
11722 uint32_t size
= read_4_bytes (dbfd
,
11723 dwp_htab
->section_pool
.v2
.sizes
11724 + (((unit_index
- 1) * dwp_htab
->nr_columns
11726 * sizeof (uint32_t)));
11728 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11731 case DW_SECT_TYPES
:
11732 sections
.info_or_types_offset
= offset
;
11733 sections
.info_or_types_size
= size
;
11735 case DW_SECT_ABBREV
:
11736 sections
.abbrev_offset
= offset
;
11737 sections
.abbrev_size
= size
;
11740 sections
.line_offset
= offset
;
11741 sections
.line_size
= size
;
11744 sections
.loc_offset
= offset
;
11745 sections
.loc_size
= size
;
11747 case DW_SECT_STR_OFFSETS
:
11748 sections
.str_offsets_offset
= offset
;
11749 sections
.str_offsets_size
= size
;
11751 case DW_SECT_MACINFO
:
11752 sections
.macinfo_offset
= offset
;
11753 sections
.macinfo_size
= size
;
11755 case DW_SECT_MACRO
:
11756 sections
.macro_offset
= offset
;
11757 sections
.macro_size
= size
;
11762 /* It's easier for the rest of the code if we fake a struct dwo_file and
11763 have dwo_unit "live" in that. At least for now.
11765 The DWP file can be made up of a random collection of CUs and TUs.
11766 However, for each CU + set of TUs that came from the same original DWO
11767 file, we can combine them back into a virtual DWO file to save space
11768 (fewer struct dwo_file objects to allocate). Remember that for really
11769 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11771 std::string virtual_dwo_name
=
11772 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11773 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11774 (long) (sections
.line_size
? sections
.line_offset
: 0),
11775 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11776 (long) (sections
.str_offsets_size
11777 ? sections
.str_offsets_offset
: 0));
11778 /* Can we use an existing virtual DWO file? */
11779 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11781 /* Create one if necessary. */
11782 if (*dwo_file_slot
== NULL
)
11784 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11785 virtual_dwo_name
.c_str ());
11787 dwo_file
= new struct dwo_file
;
11788 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11789 dwo_file
->comp_dir
= comp_dir
;
11790 dwo_file
->sections
.abbrev
=
11791 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11792 sections
.abbrev_offset
,
11793 sections
.abbrev_size
);
11794 dwo_file
->sections
.line
=
11795 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11796 sections
.line_offset
,
11797 sections
.line_size
);
11798 dwo_file
->sections
.loc
=
11799 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11800 sections
.loc_offset
, sections
.loc_size
);
11801 dwo_file
->sections
.macinfo
=
11802 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11803 sections
.macinfo_offset
,
11804 sections
.macinfo_size
);
11805 dwo_file
->sections
.macro
=
11806 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11807 sections
.macro_offset
,
11808 sections
.macro_size
);
11809 dwo_file
->sections
.str_offsets
=
11810 create_dwp_v2_or_v5_section (per_objfile
,
11811 &dwp_file
->sections
.str_offsets
,
11812 sections
.str_offsets_offset
,
11813 sections
.str_offsets_size
);
11814 /* The "str" section is global to the entire DWP file. */
11815 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11816 /* The info or types section is assigned below to dwo_unit,
11817 there's no need to record it in dwo_file.
11818 Also, we can't simply record type sections in dwo_file because
11819 we record a pointer into the vector in dwo_unit. As we collect more
11820 types we'll grow the vector and eventually have to reallocate space
11821 for it, invalidating all copies of pointers into the previous
11823 *dwo_file_slot
= dwo_file
;
11827 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11828 virtual_dwo_name
.c_str ());
11830 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11833 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11834 dwo_unit
->dwo_file
= dwo_file
;
11835 dwo_unit
->signature
= signature
;
11836 dwo_unit
->section
=
11837 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11838 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11841 ? &dwp_file
->sections
.types
11842 : &dwp_file
->sections
.info
,
11843 sections
.info_or_types_offset
,
11844 sections
.info_or_types_size
);
11845 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11850 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11851 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11852 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11853 This is for DWP version 5 files. */
11855 static struct dwo_unit
*
11856 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11857 struct dwp_file
*dwp_file
,
11858 uint32_t unit_index
,
11859 const char *comp_dir
,
11860 ULONGEST signature
, int is_debug_types
)
11862 const struct dwp_hash_table
*dwp_htab
11863 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11864 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11865 const char *kind
= is_debug_types
? "TU" : "CU";
11866 struct dwo_file
*dwo_file
;
11867 struct dwo_unit
*dwo_unit
;
11868 struct virtual_v2_or_v5_dwo_sections sections
{};
11869 void **dwo_file_slot
;
11871 gdb_assert (dwp_file
->version
== 5);
11873 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11874 kind
, pulongest (unit_index
), hex_string (signature
),
11877 /* Fetch the section offsets of this DWO unit. */
11879 /* memset (§ions, 0, sizeof (sections)); */
11881 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11883 uint32_t offset
= read_4_bytes (dbfd
,
11884 dwp_htab
->section_pool
.v5
.offsets
11885 + (((unit_index
- 1)
11886 * dwp_htab
->nr_columns
11888 * sizeof (uint32_t)));
11889 uint32_t size
= read_4_bytes (dbfd
,
11890 dwp_htab
->section_pool
.v5
.sizes
11891 + (((unit_index
- 1) * dwp_htab
->nr_columns
11893 * sizeof (uint32_t)));
11895 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11897 case DW_SECT_ABBREV_V5
:
11898 sections
.abbrev_offset
= offset
;
11899 sections
.abbrev_size
= size
;
11901 case DW_SECT_INFO_V5
:
11902 sections
.info_or_types_offset
= offset
;
11903 sections
.info_or_types_size
= size
;
11905 case DW_SECT_LINE_V5
:
11906 sections
.line_offset
= offset
;
11907 sections
.line_size
= size
;
11909 case DW_SECT_LOCLISTS_V5
:
11910 sections
.loclists_offset
= offset
;
11911 sections
.loclists_size
= size
;
11913 case DW_SECT_MACRO_V5
:
11914 sections
.macro_offset
= offset
;
11915 sections
.macro_size
= size
;
11917 case DW_SECT_RNGLISTS_V5
:
11918 sections
.rnglists_offset
= offset
;
11919 sections
.rnglists_size
= size
;
11921 case DW_SECT_STR_OFFSETS_V5
:
11922 sections
.str_offsets_offset
= offset
;
11923 sections
.str_offsets_size
= size
;
11925 case DW_SECT_RESERVED_V5
:
11931 /* It's easier for the rest of the code if we fake a struct dwo_file and
11932 have dwo_unit "live" in that. At least for now.
11934 The DWP file can be made up of a random collection of CUs and TUs.
11935 However, for each CU + set of TUs that came from the same original DWO
11936 file, we can combine them back into a virtual DWO file to save space
11937 (fewer struct dwo_file objects to allocate). Remember that for really
11938 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11940 std::string virtual_dwo_name
=
11941 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11942 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11943 (long) (sections
.line_size
? sections
.line_offset
: 0),
11944 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11945 (long) (sections
.str_offsets_size
11946 ? sections
.str_offsets_offset
: 0),
11947 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11948 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11949 /* Can we use an existing virtual DWO file? */
11950 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11951 virtual_dwo_name
.c_str (),
11953 /* Create one if necessary. */
11954 if (*dwo_file_slot
== NULL
)
11956 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11957 virtual_dwo_name
.c_str ());
11959 dwo_file
= new struct dwo_file
;
11960 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11961 dwo_file
->comp_dir
= comp_dir
;
11962 dwo_file
->sections
.abbrev
=
11963 create_dwp_v2_or_v5_section (per_objfile
,
11964 &dwp_file
->sections
.abbrev
,
11965 sections
.abbrev_offset
,
11966 sections
.abbrev_size
);
11967 dwo_file
->sections
.line
=
11968 create_dwp_v2_or_v5_section (per_objfile
,
11969 &dwp_file
->sections
.line
,
11970 sections
.line_offset
, sections
.line_size
);
11971 dwo_file
->sections
.macro
=
11972 create_dwp_v2_or_v5_section (per_objfile
,
11973 &dwp_file
->sections
.macro
,
11974 sections
.macro_offset
,
11975 sections
.macro_size
);
11976 dwo_file
->sections
.loclists
=
11977 create_dwp_v2_or_v5_section (per_objfile
,
11978 &dwp_file
->sections
.loclists
,
11979 sections
.loclists_offset
,
11980 sections
.loclists_size
);
11981 dwo_file
->sections
.rnglists
=
11982 create_dwp_v2_or_v5_section (per_objfile
,
11983 &dwp_file
->sections
.rnglists
,
11984 sections
.rnglists_offset
,
11985 sections
.rnglists_size
);
11986 dwo_file
->sections
.str_offsets
=
11987 create_dwp_v2_or_v5_section (per_objfile
,
11988 &dwp_file
->sections
.str_offsets
,
11989 sections
.str_offsets_offset
,
11990 sections
.str_offsets_size
);
11991 /* The "str" section is global to the entire DWP file. */
11992 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11993 /* The info or types section is assigned below to dwo_unit,
11994 there's no need to record it in dwo_file.
11995 Also, we can't simply record type sections in dwo_file because
11996 we record a pointer into the vector in dwo_unit. As we collect more
11997 types we'll grow the vector and eventually have to reallocate space
11998 for it, invalidating all copies of pointers into the previous
12000 *dwo_file_slot
= dwo_file
;
12004 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12005 virtual_dwo_name
.c_str ());
12007 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12010 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12011 dwo_unit
->dwo_file
= dwo_file
;
12012 dwo_unit
->signature
= signature
;
12014 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12015 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12016 &dwp_file
->sections
.info
,
12017 sections
.info_or_types_offset
,
12018 sections
.info_or_types_size
);
12019 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12024 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12025 Returns NULL if the signature isn't found. */
12027 static struct dwo_unit
*
12028 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12029 struct dwp_file
*dwp_file
, const char *comp_dir
,
12030 ULONGEST signature
, int is_debug_types
)
12032 const struct dwp_hash_table
*dwp_htab
=
12033 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12034 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12035 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12036 uint32_t hash
= signature
& mask
;
12037 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12040 struct dwo_unit find_dwo_cu
;
12042 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12043 find_dwo_cu
.signature
= signature
;
12044 slot
= htab_find_slot (is_debug_types
12045 ? dwp_file
->loaded_tus
.get ()
12046 : dwp_file
->loaded_cus
.get (),
12047 &find_dwo_cu
, INSERT
);
12050 return (struct dwo_unit
*) *slot
;
12052 /* Use a for loop so that we don't loop forever on bad debug info. */
12053 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12055 ULONGEST signature_in_table
;
12057 signature_in_table
=
12058 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12059 if (signature_in_table
== signature
)
12061 uint32_t unit_index
=
12062 read_4_bytes (dbfd
,
12063 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12065 if (dwp_file
->version
== 1)
12067 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12068 unit_index
, comp_dir
,
12069 signature
, is_debug_types
);
12071 else if (dwp_file
->version
== 2)
12073 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12074 unit_index
, comp_dir
,
12075 signature
, is_debug_types
);
12077 else /* version == 5 */
12079 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12080 unit_index
, comp_dir
,
12081 signature
, is_debug_types
);
12083 return (struct dwo_unit
*) *slot
;
12085 if (signature_in_table
== 0)
12087 hash
= (hash
+ hash2
) & mask
;
12090 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12091 " [in module %s]"),
12095 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12096 Open the file specified by FILE_NAME and hand it off to BFD for
12097 preliminary analysis. Return a newly initialized bfd *, which
12098 includes a canonicalized copy of FILE_NAME.
12099 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12100 SEARCH_CWD is true if the current directory is to be searched.
12101 It will be searched before debug-file-directory.
12102 If successful, the file is added to the bfd include table of the
12103 objfile's bfd (see gdb_bfd_record_inclusion).
12104 If unable to find/open the file, return NULL.
12105 NOTE: This function is derived from symfile_bfd_open. */
12107 static gdb_bfd_ref_ptr
12108 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12109 const char *file_name
, int is_dwp
, int search_cwd
)
12112 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12113 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12114 to debug_file_directory. */
12115 const char *search_path
;
12116 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12118 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12121 if (!debug_file_directory
.empty ())
12123 search_path_holder
.reset (concat (".", dirname_separator_string
,
12124 debug_file_directory
.c_str (),
12126 search_path
= search_path_holder
.get ();
12132 search_path
= debug_file_directory
.c_str ();
12134 /* Add the path for the executable binary to the list of search paths. */
12135 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12136 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12137 dirname_separator_string
,
12138 search_path
, nullptr));
12139 search_path
= search_path_holder
.get ();
12141 openp_flags flags
= OPF_RETURN_REALPATH
;
12143 flags
|= OPF_SEARCH_IN_PATH
;
12145 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12146 desc
= openp (search_path
, flags
, file_name
,
12147 O_RDONLY
| O_BINARY
, &absolute_name
);
12151 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12153 if (sym_bfd
== NULL
)
12155 bfd_set_cacheable (sym_bfd
.get (), 1);
12157 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12160 /* Success. Record the bfd as having been included by the objfile's bfd.
12161 This is important because things like demangled_names_hash lives in the
12162 objfile's per_bfd space and may have references to things like symbol
12163 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12164 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12169 /* Try to open DWO file FILE_NAME.
12170 COMP_DIR is the DW_AT_comp_dir attribute.
12171 The result is the bfd handle of the file.
12172 If there is a problem finding or opening the file, return NULL.
12173 Upon success, the canonicalized path of the file is stored in the bfd,
12174 same as symfile_bfd_open. */
12176 static gdb_bfd_ref_ptr
12177 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12178 const char *file_name
, const char *comp_dir
)
12180 if (IS_ABSOLUTE_PATH (file_name
))
12181 return try_open_dwop_file (per_objfile
, file_name
,
12182 0 /*is_dwp*/, 0 /*search_cwd*/);
12184 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12186 if (comp_dir
!= NULL
)
12188 gdb::unique_xmalloc_ptr
<char> path_to_try
12189 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12191 /* NOTE: If comp_dir is a relative path, this will also try the
12192 search path, which seems useful. */
12193 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12195 1 /*search_cwd*/));
12200 /* That didn't work, try debug-file-directory, which, despite its name,
12201 is a list of paths. */
12203 if (debug_file_directory
.empty ())
12206 return try_open_dwop_file (per_objfile
, file_name
,
12207 0 /*is_dwp*/, 1 /*search_cwd*/);
12210 /* This function is mapped across the sections and remembers the offset and
12211 size of each of the DWO debugging sections we are interested in. */
12214 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12215 dwo_sections
*dwo_sections
)
12217 const struct dwop_section_names
*names
= &dwop_section_names
;
12219 if (names
->abbrev_dwo
.matches (sectp
->name
))
12221 dwo_sections
->abbrev
.s
.section
= sectp
;
12222 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12224 else if (names
->info_dwo
.matches (sectp
->name
))
12226 dwo_sections
->info
.s
.section
= sectp
;
12227 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12229 else if (names
->line_dwo
.matches (sectp
->name
))
12231 dwo_sections
->line
.s
.section
= sectp
;
12232 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12234 else if (names
->loc_dwo
.matches (sectp
->name
))
12236 dwo_sections
->loc
.s
.section
= sectp
;
12237 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12239 else if (names
->loclists_dwo
.matches (sectp
->name
))
12241 dwo_sections
->loclists
.s
.section
= sectp
;
12242 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12244 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12246 dwo_sections
->macinfo
.s
.section
= sectp
;
12247 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12249 else if (names
->macro_dwo
.matches (sectp
->name
))
12251 dwo_sections
->macro
.s
.section
= sectp
;
12252 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12254 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12256 dwo_sections
->rnglists
.s
.section
= sectp
;
12257 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12259 else if (names
->str_dwo
.matches (sectp
->name
))
12261 dwo_sections
->str
.s
.section
= sectp
;
12262 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12264 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12266 dwo_sections
->str_offsets
.s
.section
= sectp
;
12267 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12269 else if (names
->types_dwo
.matches (sectp
->name
))
12271 struct dwarf2_section_info type_section
;
12273 memset (&type_section
, 0, sizeof (type_section
));
12274 type_section
.s
.section
= sectp
;
12275 type_section
.size
= bfd_section_size (sectp
);
12276 dwo_sections
->types
.push_back (type_section
);
12280 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12281 by PER_CU. This is for the non-DWP case.
12282 The result is NULL if DWO_NAME can't be found. */
12284 static struct dwo_file
*
12285 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12286 const char *comp_dir
)
12288 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12290 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12293 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12298 dwo_file_up
dwo_file (new struct dwo_file
);
12299 dwo_file
->dwo_name
= dwo_name
;
12300 dwo_file
->comp_dir
= comp_dir
;
12301 dwo_file
->dbfd
= std::move (dbfd
);
12303 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12304 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12305 &dwo_file
->sections
);
12307 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12310 if (cu
->per_cu
->dwarf_version
< 5)
12312 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12313 dwo_file
->sections
.types
, dwo_file
->tus
);
12317 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12318 &dwo_file
->sections
.info
, dwo_file
->tus
,
12319 rcuh_kind::COMPILE
);
12322 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12324 return dwo_file
.release ();
12327 /* This function is mapped across the sections and remembers the offset and
12328 size of each of the DWP debugging sections common to version 1 and 2 that
12329 we are interested in. */
12332 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12333 dwp_file
*dwp_file
)
12335 const struct dwop_section_names
*names
= &dwop_section_names
;
12336 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12338 /* Record the ELF section number for later lookup: this is what the
12339 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12340 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12341 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12343 /* Look for specific sections that we need. */
12344 if (names
->str_dwo
.matches (sectp
->name
))
12346 dwp_file
->sections
.str
.s
.section
= sectp
;
12347 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12349 else if (names
->cu_index
.matches (sectp
->name
))
12351 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12352 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12354 else if (names
->tu_index
.matches (sectp
->name
))
12356 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12357 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12361 /* This function is mapped across the sections and remembers the offset and
12362 size of each of the DWP version 2 debugging sections that we are interested
12363 in. This is split into a separate function because we don't know if we
12364 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12367 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12369 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12370 const struct dwop_section_names
*names
= &dwop_section_names
;
12371 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12373 /* Record the ELF section number for later lookup: this is what the
12374 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12375 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12376 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12378 /* Look for specific sections that we need. */
12379 if (names
->abbrev_dwo
.matches (sectp
->name
))
12381 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12382 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12384 else if (names
->info_dwo
.matches (sectp
->name
))
12386 dwp_file
->sections
.info
.s
.section
= sectp
;
12387 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12389 else if (names
->line_dwo
.matches (sectp
->name
))
12391 dwp_file
->sections
.line
.s
.section
= sectp
;
12392 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12394 else if (names
->loc_dwo
.matches (sectp
->name
))
12396 dwp_file
->sections
.loc
.s
.section
= sectp
;
12397 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12399 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12401 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12402 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12404 else if (names
->macro_dwo
.matches (sectp
->name
))
12406 dwp_file
->sections
.macro
.s
.section
= sectp
;
12407 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12409 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12411 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12412 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12414 else if (names
->types_dwo
.matches (sectp
->name
))
12416 dwp_file
->sections
.types
.s
.section
= sectp
;
12417 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12421 /* This function is mapped across the sections and remembers the offset and
12422 size of each of the DWP version 5 debugging sections that we are interested
12423 in. This is split into a separate function because we don't know if we
12424 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12427 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12429 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12430 const struct dwop_section_names
*names
= &dwop_section_names
;
12431 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12433 /* Record the ELF section number for later lookup: this is what the
12434 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12435 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12436 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12438 /* Look for specific sections that we need. */
12439 if (names
->abbrev_dwo
.matches (sectp
->name
))
12441 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12442 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12444 else if (names
->info_dwo
.matches (sectp
->name
))
12446 dwp_file
->sections
.info
.s
.section
= sectp
;
12447 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12449 else if (names
->line_dwo
.matches (sectp
->name
))
12451 dwp_file
->sections
.line
.s
.section
= sectp
;
12452 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12454 else if (names
->loclists_dwo
.matches (sectp
->name
))
12456 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12457 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12459 else if (names
->macro_dwo
.matches (sectp
->name
))
12461 dwp_file
->sections
.macro
.s
.section
= sectp
;
12462 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12464 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12466 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12467 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12469 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12471 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12472 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12476 /* Hash function for dwp_file loaded CUs/TUs. */
12479 hash_dwp_loaded_cutus (const void *item
)
12481 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12483 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12484 return dwo_unit
->signature
;
12487 /* Equality function for dwp_file loaded CUs/TUs. */
12490 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12492 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12493 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12495 return dua
->signature
== dub
->signature
;
12498 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12501 allocate_dwp_loaded_cutus_table ()
12503 return htab_up (htab_create_alloc (3,
12504 hash_dwp_loaded_cutus
,
12505 eq_dwp_loaded_cutus
,
12506 NULL
, xcalloc
, xfree
));
12509 /* Try to open DWP file FILE_NAME.
12510 The result is the bfd handle of the file.
12511 If there is a problem finding or opening the file, return NULL.
12512 Upon success, the canonicalized path of the file is stored in the bfd,
12513 same as symfile_bfd_open. */
12515 static gdb_bfd_ref_ptr
12516 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12518 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12520 1 /*search_cwd*/));
12524 /* Work around upstream bug 15652.
12525 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12526 [Whether that's a "bug" is debatable, but it is getting in our way.]
12527 We have no real idea where the dwp file is, because gdb's realpath-ing
12528 of the executable's path may have discarded the needed info.
12529 [IWBN if the dwp file name was recorded in the executable, akin to
12530 .gnu_debuglink, but that doesn't exist yet.]
12531 Strip the directory from FILE_NAME and search again. */
12532 if (!debug_file_directory
.empty ())
12534 /* Don't implicitly search the current directory here.
12535 If the user wants to search "." to handle this case,
12536 it must be added to debug-file-directory. */
12537 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12545 /* Initialize the use of the DWP file for the current objfile.
12546 By convention the name of the DWP file is ${objfile}.dwp.
12547 The result is NULL if it can't be found. */
12549 static std::unique_ptr
<struct dwp_file
>
12550 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12552 struct objfile
*objfile
= per_objfile
->objfile
;
12554 /* Try to find first .dwp for the binary file before any symbolic links
12557 /* If the objfile is a debug file, find the name of the real binary
12558 file and get the name of dwp file from there. */
12559 std::string dwp_name
;
12560 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12562 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12563 const char *backlink_basename
= lbasename (backlink
->original_name
);
12565 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12568 dwp_name
= objfile
->original_name
;
12570 dwp_name
+= ".dwp";
12572 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12574 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12576 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12577 dwp_name
= objfile_name (objfile
);
12578 dwp_name
+= ".dwp";
12579 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12584 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12586 return std::unique_ptr
<dwp_file
> ();
12589 const char *name
= bfd_get_filename (dbfd
.get ());
12590 std::unique_ptr
<struct dwp_file
> dwp_file
12591 (new struct dwp_file (name
, std::move (dbfd
)));
12593 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12594 dwp_file
->elf_sections
=
12595 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12596 dwp_file
->num_sections
, asection
*);
12598 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12599 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12602 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12604 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12606 /* The DWP file version is stored in the hash table. Oh well. */
12607 if (dwp_file
->cus
&& dwp_file
->tus
12608 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12610 /* Technically speaking, we should try to limp along, but this is
12611 pretty bizarre. We use pulongest here because that's the established
12612 portability solution (e.g, we cannot use %u for uint32_t). */
12613 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12614 " TU version %s [in DWP file %s]"),
12615 pulongest (dwp_file
->cus
->version
),
12616 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12620 dwp_file
->version
= dwp_file
->cus
->version
;
12621 else if (dwp_file
->tus
)
12622 dwp_file
->version
= dwp_file
->tus
->version
;
12624 dwp_file
->version
= 2;
12626 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12628 if (dwp_file
->version
== 2)
12629 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12632 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12636 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12637 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12639 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12640 dwarf_read_debug_printf (" %s CUs, %s TUs",
12641 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12642 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12647 /* Wrapper around open_and_init_dwp_file, only open it once. */
12649 static struct dwp_file
*
12650 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12652 if (!per_objfile
->per_bfd
->dwp_checked
)
12654 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12655 per_objfile
->per_bfd
->dwp_checked
= 1;
12657 return per_objfile
->per_bfd
->dwp_file
.get ();
12660 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12661 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12662 or in the DWP file for the objfile, referenced by THIS_UNIT.
12663 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12664 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12666 This is called, for example, when wanting to read a variable with a
12667 complex location. Therefore we don't want to do file i/o for every call.
12668 Therefore we don't want to look for a DWO file on every call.
12669 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12670 then we check if we've already seen DWO_NAME, and only THEN do we check
12673 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12674 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12676 static struct dwo_unit
*
12677 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12678 ULONGEST signature
, int is_debug_types
)
12680 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12681 struct objfile
*objfile
= per_objfile
->objfile
;
12682 const char *kind
= is_debug_types
? "TU" : "CU";
12683 void **dwo_file_slot
;
12684 struct dwo_file
*dwo_file
;
12685 struct dwp_file
*dwp_file
;
12687 /* First see if there's a DWP file.
12688 If we have a DWP file but didn't find the DWO inside it, don't
12689 look for the original DWO file. It makes gdb behave differently
12690 depending on whether one is debugging in the build tree. */
12692 dwp_file
= get_dwp_file (per_objfile
);
12693 if (dwp_file
!= NULL
)
12695 const struct dwp_hash_table
*dwp_htab
=
12696 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12698 if (dwp_htab
!= NULL
)
12700 struct dwo_unit
*dwo_cutu
=
12701 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12704 if (dwo_cutu
!= NULL
)
12706 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12707 kind
, hex_string (signature
),
12708 host_address_to_string (dwo_cutu
));
12716 /* No DWP file, look for the DWO file. */
12718 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12719 if (*dwo_file_slot
== NULL
)
12721 /* Read in the file and build a table of the CUs/TUs it contains. */
12722 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12724 /* NOTE: This will be NULL if unable to open the file. */
12725 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12727 if (dwo_file
!= NULL
)
12729 struct dwo_unit
*dwo_cutu
= NULL
;
12731 if (is_debug_types
&& dwo_file
->tus
)
12733 struct dwo_unit find_dwo_cutu
;
12735 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12736 find_dwo_cutu
.signature
= signature
;
12738 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12741 else if (!is_debug_types
&& dwo_file
->cus
)
12743 struct dwo_unit find_dwo_cutu
;
12745 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12746 find_dwo_cutu
.signature
= signature
;
12747 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12751 if (dwo_cutu
!= NULL
)
12753 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12754 kind
, dwo_name
, hex_string (signature
),
12755 host_address_to_string (dwo_cutu
));
12762 /* We didn't find it. This could mean a dwo_id mismatch, or
12763 someone deleted the DWO/DWP file, or the search path isn't set up
12764 correctly to find the file. */
12766 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12767 kind
, dwo_name
, hex_string (signature
));
12769 /* This is a warning and not a complaint because it can be caused by
12770 pilot error (e.g., user accidentally deleting the DWO). */
12772 /* Print the name of the DWP file if we looked there, helps the user
12773 better diagnose the problem. */
12774 std::string dwp_text
;
12776 if (dwp_file
!= NULL
)
12777 dwp_text
= string_printf (" [in DWP file %s]",
12778 lbasename (dwp_file
->name
));
12780 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12781 " [in module %s]"),
12782 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12783 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12788 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12789 See lookup_dwo_cutu_unit for details. */
12791 static struct dwo_unit
*
12792 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12793 ULONGEST signature
)
12795 gdb_assert (!cu
->per_cu
->is_debug_types
);
12797 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12800 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12801 See lookup_dwo_cutu_unit for details. */
12803 static struct dwo_unit
*
12804 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12806 gdb_assert (cu
->per_cu
->is_debug_types
);
12808 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12810 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12813 /* Traversal function for queue_and_load_all_dwo_tus. */
12816 queue_and_load_dwo_tu (void **slot
, void *info
)
12818 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12819 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12820 ULONGEST signature
= dwo_unit
->signature
;
12821 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12823 if (sig_type
!= NULL
)
12825 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12826 a real dependency of PER_CU on SIG_TYPE. That is detected later
12827 while processing PER_CU. */
12828 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12830 load_full_type_unit (sig_type
, cu
->per_objfile
);
12831 cu
->per_cu
->imported_symtabs_push (sig_type
);
12837 /* Queue all TUs contained in the DWO of CU to be read in.
12838 The DWO may have the only definition of the type, though it may not be
12839 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12840 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12843 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12845 struct dwo_unit
*dwo_unit
;
12846 struct dwo_file
*dwo_file
;
12848 gdb_assert (cu
!= nullptr);
12849 gdb_assert (!cu
->per_cu
->is_debug_types
);
12850 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12852 dwo_unit
= cu
->dwo_unit
;
12853 gdb_assert (dwo_unit
!= NULL
);
12855 dwo_file
= dwo_unit
->dwo_file
;
12856 if (dwo_file
->tus
!= NULL
)
12857 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12860 /* Read in various DIEs. */
12862 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12863 Inherit only the children of the DW_AT_abstract_origin DIE not being
12864 already referenced by DW_AT_abstract_origin from the children of the
12868 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12870 struct die_info
*child_die
;
12871 sect_offset
*offsetp
;
12872 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12873 struct die_info
*origin_die
;
12874 /* Iterator of the ORIGIN_DIE children. */
12875 struct die_info
*origin_child_die
;
12876 struct attribute
*attr
;
12877 struct dwarf2_cu
*origin_cu
;
12878 struct pending
**origin_previous_list_in_scope
;
12880 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12884 /* Note that following die references may follow to a die in a
12888 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12890 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12892 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12893 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12895 if (die
->tag
!= origin_die
->tag
12896 && !(die
->tag
== DW_TAG_inlined_subroutine
12897 && origin_die
->tag
== DW_TAG_subprogram
))
12898 complaint (_("DIE %s and its abstract origin %s have different tags"),
12899 sect_offset_str (die
->sect_off
),
12900 sect_offset_str (origin_die
->sect_off
));
12902 /* Find if the concrete and abstract trees are structurally the
12903 same. This is a shallow traversal and it is not bullet-proof;
12904 the compiler can trick the debugger into believing that the trees
12905 are isomorphic, whereas they actually are not. However, the
12906 likelyhood of this happening is pretty low, and a full-fledged
12907 check would be an overkill. */
12908 bool are_isomorphic
= true;
12909 die_info
*concrete_child
= die
->child
;
12910 die_info
*abstract_child
= origin_die
->child
;
12911 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12913 if (concrete_child
== nullptr
12914 || abstract_child
== nullptr
12915 || concrete_child
->tag
!= abstract_child
->tag
)
12917 are_isomorphic
= false;
12921 concrete_child
= concrete_child
->sibling
;
12922 abstract_child
= abstract_child
->sibling
;
12925 /* Walk the origin's children in parallel to the concrete children.
12926 This helps match an origin child in case the debug info misses
12927 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12928 origin tree may not have the same tree structure as the concrete
12930 die_info
*corresponding_abstract_child
12931 = are_isomorphic
? origin_die
->child
: nullptr;
12933 std::vector
<sect_offset
> offsets
;
12935 for (child_die
= die
->child
;
12936 child_die
&& child_die
->tag
;
12937 child_die
= child_die
->sibling
)
12939 struct die_info
*child_origin_die
;
12940 struct dwarf2_cu
*child_origin_cu
;
12942 /* We are trying to process concrete instance entries:
12943 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12944 it's not relevant to our analysis here. i.e. detecting DIEs that are
12945 present in the abstract instance but not referenced in the concrete
12947 if (child_die
->tag
== DW_TAG_call_site
12948 || child_die
->tag
== DW_TAG_GNU_call_site
)
12950 if (are_isomorphic
)
12951 corresponding_abstract_child
12952 = corresponding_abstract_child
->sibling
;
12956 /* For each CHILD_DIE, find the corresponding child of
12957 ORIGIN_DIE. If there is more than one layer of
12958 DW_AT_abstract_origin, follow them all; there shouldn't be,
12959 but GCC versions at least through 4.4 generate this (GCC PR
12961 child_origin_die
= child_die
;
12962 child_origin_cu
= cu
;
12965 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12969 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12973 /* If missing DW_AT_abstract_origin, try the corresponding child
12974 of the origin. Clang emits such lexical scopes. */
12975 if (child_origin_die
== child_die
12976 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12978 && child_die
->tag
== DW_TAG_lexical_block
)
12979 child_origin_die
= corresponding_abstract_child
;
12981 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12982 counterpart may exist. */
12983 if (child_origin_die
!= child_die
)
12985 if (child_die
->tag
!= child_origin_die
->tag
12986 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12987 && child_origin_die
->tag
== DW_TAG_subprogram
))
12988 complaint (_("Child DIE %s and its abstract origin %s have "
12990 sect_offset_str (child_die
->sect_off
),
12991 sect_offset_str (child_origin_die
->sect_off
));
12992 if (child_origin_die
->parent
!= origin_die
)
12993 complaint (_("Child DIE %s and its abstract origin %s have "
12994 "different parents"),
12995 sect_offset_str (child_die
->sect_off
),
12996 sect_offset_str (child_origin_die
->sect_off
));
12998 offsets
.push_back (child_origin_die
->sect_off
);
13001 if (are_isomorphic
)
13002 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13004 std::sort (offsets
.begin (), offsets
.end ());
13005 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13006 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13007 if (offsetp
[-1] == *offsetp
)
13008 complaint (_("Multiple children of DIE %s refer "
13009 "to DIE %s as their abstract origin"),
13010 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13012 offsetp
= offsets
.data ();
13013 origin_child_die
= origin_die
->child
;
13014 while (origin_child_die
&& origin_child_die
->tag
)
13016 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13017 while (offsetp
< offsets_end
13018 && *offsetp
< origin_child_die
->sect_off
)
13020 if (offsetp
>= offsets_end
13021 || *offsetp
> origin_child_die
->sect_off
)
13023 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13024 Check whether we're already processing ORIGIN_CHILD_DIE.
13025 This can happen with mutually referenced abstract_origins.
13027 if (!origin_child_die
->in_process
)
13028 process_die (origin_child_die
, origin_cu
);
13030 origin_child_die
= origin_child_die
->sibling
;
13032 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13034 if (cu
!= origin_cu
)
13035 compute_delayed_physnames (origin_cu
);
13039 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13041 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13042 struct gdbarch
*gdbarch
= objfile
->arch ();
13043 struct context_stack
*newobj
;
13046 struct die_info
*child_die
;
13047 struct attribute
*attr
, *call_line
, *call_file
;
13049 CORE_ADDR baseaddr
;
13050 struct block
*block
;
13051 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13052 std::vector
<struct symbol
*> template_args
;
13053 struct template_symbol
*templ_func
= NULL
;
13057 /* If we do not have call site information, we can't show the
13058 caller of this inlined function. That's too confusing, so
13059 only use the scope for local variables. */
13060 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13061 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13062 if (call_line
== NULL
|| call_file
== NULL
)
13064 read_lexical_block_scope (die
, cu
);
13069 baseaddr
= objfile
->text_section_offset ();
13071 name
= dwarf2_name (die
, cu
);
13073 /* Ignore functions with missing or empty names. These are actually
13074 illegal according to the DWARF standard. */
13077 complaint (_("missing name for subprogram DIE at %s"),
13078 sect_offset_str (die
->sect_off
));
13082 /* Ignore functions with missing or invalid low and high pc attributes. */
13083 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13084 <= PC_BOUNDS_INVALID
)
13086 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13087 if (attr
== nullptr || !attr
->as_boolean ())
13088 complaint (_("cannot get low and high bounds "
13089 "for subprogram DIE at %s"),
13090 sect_offset_str (die
->sect_off
));
13094 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13095 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13097 /* If we have any template arguments, then we must allocate a
13098 different sort of symbol. */
13099 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13101 if (child_die
->tag
== DW_TAG_template_type_param
13102 || child_die
->tag
== DW_TAG_template_value_param
)
13104 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13105 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13110 gdb_assert (cu
->get_builder () != nullptr);
13111 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13112 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13113 (struct symbol
*) templ_func
);
13115 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13116 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13119 /* If there is a location expression for DW_AT_frame_base, record
13121 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13122 if (attr
!= nullptr)
13123 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13125 /* If there is a location for the static link, record it. */
13126 newobj
->static_link
= NULL
;
13127 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13128 if (attr
!= nullptr)
13130 newobj
->static_link
13131 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13132 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13136 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13138 if (die
->child
!= NULL
)
13140 child_die
= die
->child
;
13141 while (child_die
&& child_die
->tag
)
13143 if (child_die
->tag
== DW_TAG_template_type_param
13144 || child_die
->tag
== DW_TAG_template_value_param
)
13146 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13149 template_args
.push_back (arg
);
13152 process_die (child_die
, cu
);
13153 child_die
= child_die
->sibling
;
13157 inherit_abstract_dies (die
, cu
);
13159 /* If we have a DW_AT_specification, we might need to import using
13160 directives from the context of the specification DIE. See the
13161 comment in determine_prefix. */
13162 if (cu
->per_cu
->lang
== language_cplus
13163 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13165 struct dwarf2_cu
*spec_cu
= cu
;
13166 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13170 child_die
= spec_die
->child
;
13171 while (child_die
&& child_die
->tag
)
13173 if (child_die
->tag
== DW_TAG_imported_module
)
13174 process_die (child_die
, spec_cu
);
13175 child_die
= child_die
->sibling
;
13178 /* In some cases, GCC generates specification DIEs that
13179 themselves contain DW_AT_specification attributes. */
13180 spec_die
= die_specification (spec_die
, &spec_cu
);
13184 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13185 /* Make a block for the local symbols within. */
13186 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13187 cstk
.static_link
, lowpc
, highpc
);
13189 /* For C++, set the block's scope. */
13190 if ((cu
->per_cu
->lang
== language_cplus
13191 || cu
->per_cu
->lang
== language_fortran
13192 || cu
->per_cu
->lang
== language_d
13193 || cu
->per_cu
->lang
== language_rust
)
13194 && cu
->processing_has_namespace_info
)
13195 block_set_scope (block
, determine_prefix (die
, cu
),
13196 &objfile
->objfile_obstack
);
13198 /* If we have address ranges, record them. */
13199 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13201 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13203 /* Attach template arguments to function. */
13204 if (!template_args
.empty ())
13206 gdb_assert (templ_func
!= NULL
);
13208 templ_func
->n_template_arguments
= template_args
.size ();
13209 templ_func
->template_arguments
13210 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13211 templ_func
->n_template_arguments
);
13212 memcpy (templ_func
->template_arguments
,
13213 template_args
.data (),
13214 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13216 /* Make sure that the symtab is set on the new symbols. Even
13217 though they don't appear in this symtab directly, other parts
13218 of gdb assume that symbols do, and this is reasonably
13220 for (symbol
*sym
: template_args
)
13221 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13224 /* In C++, we can have functions nested inside functions (e.g., when
13225 a function declares a class that has methods). This means that
13226 when we finish processing a function scope, we may need to go
13227 back to building a containing block's symbol lists. */
13228 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13229 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13231 /* If we've finished processing a top-level function, subsequent
13232 symbols go in the file symbol list. */
13233 if (cu
->get_builder ()->outermost_context_p ())
13234 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13237 /* Process all the DIES contained within a lexical block scope. Start
13238 a new scope, process the dies, and then close the scope. */
13241 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13243 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13244 struct gdbarch
*gdbarch
= objfile
->arch ();
13245 CORE_ADDR lowpc
, highpc
;
13246 struct die_info
*child_die
;
13247 CORE_ADDR baseaddr
;
13249 baseaddr
= objfile
->text_section_offset ();
13251 /* Ignore blocks with missing or invalid low and high pc attributes. */
13252 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13253 as multiple lexical blocks? Handling children in a sane way would
13254 be nasty. Might be easier to properly extend generic blocks to
13255 describe ranges. */
13256 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13258 case PC_BOUNDS_NOT_PRESENT
:
13259 /* DW_TAG_lexical_block has no attributes, process its children as if
13260 there was no wrapping by that DW_TAG_lexical_block.
13261 GCC does no longer produces such DWARF since GCC r224161. */
13262 for (child_die
= die
->child
;
13263 child_die
!= NULL
&& child_die
->tag
;
13264 child_die
= child_die
->sibling
)
13266 /* We might already be processing this DIE. This can happen
13267 in an unusual circumstance -- where a subroutine A
13268 appears lexically in another subroutine B, but A actually
13269 inlines B. The recursion is broken here, rather than in
13270 inherit_abstract_dies, because it seems better to simply
13271 drop concrete children here. */
13272 if (!child_die
->in_process
)
13273 process_die (child_die
, cu
);
13276 case PC_BOUNDS_INVALID
:
13279 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13280 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13282 cu
->get_builder ()->push_context (0, lowpc
);
13283 if (die
->child
!= NULL
)
13285 child_die
= die
->child
;
13286 while (child_die
&& child_die
->tag
)
13288 process_die (child_die
, cu
);
13289 child_die
= child_die
->sibling
;
13292 inherit_abstract_dies (die
, cu
);
13293 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13295 if (*cu
->get_builder ()->get_local_symbols () != NULL
13296 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13298 struct block
*block
13299 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13300 cstk
.start_addr
, highpc
);
13302 /* Note that recording ranges after traversing children, as we
13303 do here, means that recording a parent's ranges entails
13304 walking across all its children's ranges as they appear in
13305 the address map, which is quadratic behavior.
13307 It would be nicer to record the parent's ranges before
13308 traversing its children, simply overriding whatever you find
13309 there. But since we don't even decide whether to create a
13310 block until after we've traversed its children, that's hard
13312 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13314 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13315 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13318 static void dwarf2_ranges_read_low_addrs (unsigned offset
,
13319 struct dwarf2_cu
*cu
,
13321 std::vector
<CORE_ADDR
> &result
);
13323 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13326 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13328 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13329 struct objfile
*objfile
= per_objfile
->objfile
;
13330 struct gdbarch
*gdbarch
= objfile
->arch ();
13331 CORE_ADDR pc
, baseaddr
;
13332 struct attribute
*attr
;
13335 struct die_info
*child_die
;
13337 baseaddr
= objfile
->text_section_offset ();
13339 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13342 /* This was a pre-DWARF-5 GNU extension alias
13343 for DW_AT_call_return_pc. */
13344 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13348 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13349 "DIE %s [in module %s]"),
13350 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13353 pc
= attr
->as_address () + baseaddr
;
13354 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13357 if (cu
->call_site_htab
== NULL
)
13358 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
13359 call_site::eq
, NULL
,
13360 &objfile
->objfile_obstack
,
13361 hashtab_obstack_allocate
, NULL
);
13362 struct call_site
call_site_local (pc
, nullptr, nullptr);
13363 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13366 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13367 "DIE %s [in module %s]"),
13368 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13369 objfile_name (objfile
));
13373 /* Count parameters at the caller. */
13376 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13377 child_die
= child_die
->sibling
)
13379 if (child_die
->tag
!= DW_TAG_call_site_parameter
13380 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13382 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13383 "DW_TAG_call_site child DIE %s [in module %s]"),
13384 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13385 objfile_name (objfile
));
13392 struct call_site
*call_site
13393 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
13395 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
13396 struct call_site (pc
, cu
->per_cu
, per_objfile
);
13399 /* We never call the destructor of call_site, so we must ensure it is
13400 trivially destructible. */
13401 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
13403 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13404 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13406 struct die_info
*func_die
;
13408 /* Skip also over DW_TAG_inlined_subroutine. */
13409 for (func_die
= die
->parent
;
13410 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13411 && func_die
->tag
!= DW_TAG_subroutine_type
;
13412 func_die
= func_die
->parent
);
13414 /* DW_AT_call_all_calls is a superset
13415 of DW_AT_call_all_tail_calls. */
13417 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13418 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13419 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13420 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13422 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13423 not complete. But keep CALL_SITE for look ups via call_site_htab,
13424 both the initial caller containing the real return address PC and
13425 the final callee containing the current PC of a chain of tail
13426 calls do not need to have the tail call list complete. But any
13427 function candidate for a virtual tail call frame searched via
13428 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13429 determined unambiguously. */
13433 struct type
*func_type
= NULL
;
13436 func_type
= get_die_type (func_die
, cu
);
13437 if (func_type
!= NULL
)
13439 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13441 /* Enlist this call site to the function. */
13442 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13443 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13446 complaint (_("Cannot find function owning DW_TAG_call_site "
13447 "DIE %s [in module %s]"),
13448 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13452 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13454 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13456 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13459 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13460 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13463 call_site
->target
.set_loc_dwarf_block (nullptr);
13464 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13465 /* Keep NULL DWARF_BLOCK. */;
13466 else if (attr
->form_is_block ())
13468 struct dwarf2_locexpr_baton
*dlbaton
;
13469 struct dwarf_block
*block
= attr
->as_block ();
13471 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13472 dlbaton
->data
= block
->data
;
13473 dlbaton
->size
= block
->size
;
13474 dlbaton
->per_objfile
= per_objfile
;
13475 dlbaton
->per_cu
= cu
->per_cu
;
13477 call_site
->target
.set_loc_dwarf_block (dlbaton
);
13479 else if (attr
->form_is_ref ())
13481 struct dwarf2_cu
*target_cu
= cu
;
13482 struct die_info
*target_die
;
13484 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13485 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13487 struct attribute
*ranges_attr
13488 = dwarf2_attr (target_die
, DW_AT_ranges
, target_cu
);
13490 if (die_is_declaration (target_die
, target_cu
))
13492 const char *target_physname
;
13494 /* Prefer the mangled name; otherwise compute the demangled one. */
13495 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13496 if (target_physname
== NULL
)
13497 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13498 if (target_physname
== NULL
)
13499 complaint (_("DW_AT_call_target target DIE has invalid "
13500 "physname, for referencing DIE %s [in module %s]"),
13501 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13503 call_site
->target
.set_loc_physname (target_physname
);
13505 else if (ranges_attr
!= nullptr && ranges_attr
->form_is_unsigned ())
13507 ULONGEST ranges_offset
= (ranges_attr
->as_unsigned ()
13508 + target_cu
->gnu_ranges_base
);
13509 std::vector
<CORE_ADDR
> addresses
;
13510 dwarf2_ranges_read_low_addrs (ranges_offset
, target_cu
,
13511 target_die
->tag
, addresses
);
13512 CORE_ADDR
*saved
= XOBNEWVAR (&objfile
->objfile_obstack
, CORE_ADDR
,
13513 addresses
.size ());
13514 std::copy (addresses
.begin (), addresses
.end (), saved
);
13515 call_site
->target
.set_loc_array (addresses
.size (), saved
);
13521 /* DW_AT_entry_pc should be preferred. */
13522 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13523 <= PC_BOUNDS_INVALID
)
13524 complaint (_("DW_AT_call_target target DIE has invalid "
13525 "low pc, for referencing DIE %s [in module %s]"),
13526 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13529 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
13531 call_site
->target
.set_loc_physaddr (lowpc
);
13536 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13537 "block nor reference, for DIE %s [in module %s]"),
13538 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13540 for (child_die
= die
->child
;
13541 child_die
&& child_die
->tag
;
13542 child_die
= child_die
->sibling
)
13544 struct call_site_parameter
*parameter
;
13545 struct attribute
*loc
, *origin
;
13547 if (child_die
->tag
!= DW_TAG_call_site_parameter
13548 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13550 /* Already printed the complaint above. */
13554 gdb_assert (call_site
->parameter_count
< nparams
);
13555 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13557 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13558 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13559 register is contained in DW_AT_call_value. */
13561 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13562 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13563 if (origin
== NULL
)
13565 /* This was a pre-DWARF-5 GNU extension alias
13566 for DW_AT_call_parameter. */
13567 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13569 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13571 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13573 sect_offset sect_off
= origin
->get_ref_die_offset ();
13574 if (!cu
->header
.offset_in_cu_p (sect_off
))
13576 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13577 binding can be done only inside one CU. Such referenced DIE
13578 therefore cannot be even moved to DW_TAG_partial_unit. */
13579 complaint (_("DW_AT_call_parameter offset is not in CU for "
13580 "DW_TAG_call_site child DIE %s [in module %s]"),
13581 sect_offset_str (child_die
->sect_off
),
13582 objfile_name (objfile
));
13585 parameter
->u
.param_cu_off
13586 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13588 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13590 complaint (_("No DW_FORM_block* DW_AT_location for "
13591 "DW_TAG_call_site child DIE %s [in module %s]"),
13592 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13597 struct dwarf_block
*block
= loc
->as_block ();
13599 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13600 (block
->data
, &block
->data
[block
->size
]);
13601 if (parameter
->u
.dwarf_reg
!= -1)
13602 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13603 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13604 &block
->data
[block
->size
],
13605 ¶meter
->u
.fb_offset
))
13606 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13609 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13610 "for DW_FORM_block* DW_AT_location is supported for "
13611 "DW_TAG_call_site child DIE %s "
13613 sect_offset_str (child_die
->sect_off
),
13614 objfile_name (objfile
));
13619 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13621 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13622 if (attr
== NULL
|| !attr
->form_is_block ())
13624 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13625 "DW_TAG_call_site child DIE %s [in module %s]"),
13626 sect_offset_str (child_die
->sect_off
),
13627 objfile_name (objfile
));
13631 struct dwarf_block
*block
= attr
->as_block ();
13632 parameter
->value
= block
->data
;
13633 parameter
->value_size
= block
->size
;
13635 /* Parameters are not pre-cleared by memset above. */
13636 parameter
->data_value
= NULL
;
13637 parameter
->data_value_size
= 0;
13638 call_site
->parameter_count
++;
13640 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13642 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13643 if (attr
!= nullptr)
13645 if (!attr
->form_is_block ())
13646 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13647 "DW_TAG_call_site child DIE %s [in module %s]"),
13648 sect_offset_str (child_die
->sect_off
),
13649 objfile_name (objfile
));
13652 block
= attr
->as_block ();
13653 parameter
->data_value
= block
->data
;
13654 parameter
->data_value_size
= block
->size
;
13660 /* Helper function for read_variable. If DIE represents a virtual
13661 table, then return the type of the concrete object that is
13662 associated with the virtual table. Otherwise, return NULL. */
13664 static struct type
*
13665 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13667 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13671 /* Find the type DIE. */
13672 struct die_info
*type_die
= NULL
;
13673 struct dwarf2_cu
*type_cu
= cu
;
13675 if (attr
->form_is_ref ())
13676 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13677 if (type_die
== NULL
)
13680 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13682 return die_containing_type (type_die
, type_cu
);
13685 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13688 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13690 struct rust_vtable_symbol
*storage
= NULL
;
13692 if (cu
->per_cu
->lang
== language_rust
)
13694 struct type
*containing_type
= rust_containing_type (die
, cu
);
13696 if (containing_type
!= NULL
)
13698 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13700 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13701 storage
->concrete_type
= containing_type
;
13702 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13706 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13707 struct attribute
*abstract_origin
13708 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13709 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13710 if (res
== NULL
&& loc
&& abstract_origin
)
13712 /* We have a variable without a name, but with a location and an abstract
13713 origin. This may be a concrete instance of an abstract variable
13714 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13716 struct dwarf2_cu
*origin_cu
= cu
;
13717 struct die_info
*origin_die
13718 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13719 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13720 per_objfile
->per_bfd
->abstract_to_concrete
13721 [origin_die
->sect_off
].push_back (die
->sect_off
);
13725 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13726 reading .debug_rnglists.
13727 Callback's type should be:
13728 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13729 Return true if the attributes are present and valid, otherwise,
13732 template <typename Callback
>
13734 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13735 dwarf_tag tag
, Callback
&&callback
)
13737 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13738 struct objfile
*objfile
= per_objfile
->objfile
;
13739 bfd
*obfd
= objfile
->obfd
;
13740 /* Base address selection entry. */
13741 gdb::optional
<CORE_ADDR
> base
;
13742 const gdb_byte
*buffer
;
13743 bool overflow
= false;
13744 ULONGEST addr_index
;
13745 struct dwarf2_section_info
*rnglists_section
;
13747 base
= cu
->base_address
;
13748 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13749 rnglists_section
->read (objfile
);
13751 if (offset
>= rnglists_section
->size
)
13753 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13757 buffer
= rnglists_section
->buffer
+ offset
;
13761 /* Initialize it due to a false compiler warning. */
13762 CORE_ADDR range_beginning
= 0, range_end
= 0;
13763 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13764 + rnglists_section
->size
);
13765 unsigned int bytes_read
;
13767 if (buffer
== buf_end
)
13772 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13775 case DW_RLE_end_of_list
:
13777 case DW_RLE_base_address
:
13778 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13783 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13784 buffer
+= bytes_read
;
13786 case DW_RLE_base_addressx
:
13787 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13788 buffer
+= bytes_read
;
13789 base
= read_addr_index (cu
, addr_index
);
13791 case DW_RLE_start_length
:
13792 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13797 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13799 buffer
+= bytes_read
;
13800 range_end
= (range_beginning
13801 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13802 buffer
+= bytes_read
;
13803 if (buffer
> buf_end
)
13809 case DW_RLE_startx_length
:
13810 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13811 buffer
+= bytes_read
;
13812 range_beginning
= read_addr_index (cu
, addr_index
);
13813 if (buffer
> buf_end
)
13818 range_end
= (range_beginning
13819 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13820 buffer
+= bytes_read
;
13822 case DW_RLE_offset_pair
:
13823 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13824 buffer
+= bytes_read
;
13825 if (buffer
> buf_end
)
13830 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13831 buffer
+= bytes_read
;
13832 if (buffer
> buf_end
)
13838 case DW_RLE_start_end
:
13839 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13844 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13846 buffer
+= bytes_read
;
13847 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13848 buffer
+= bytes_read
;
13850 case DW_RLE_startx_endx
:
13851 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13852 buffer
+= bytes_read
;
13853 range_beginning
= read_addr_index (cu
, addr_index
);
13854 if (buffer
> buf_end
)
13859 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13860 buffer
+= bytes_read
;
13861 range_end
= read_addr_index (cu
, addr_index
);
13864 complaint (_("Invalid .debug_rnglists data (no base address)"));
13867 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13869 if (rlet
== DW_RLE_base_address
)
13872 if (range_beginning
> range_end
)
13874 /* Inverted range entries are invalid. */
13875 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13879 /* Empty range entries have no effect. */
13880 if (range_beginning
== range_end
)
13883 /* Only DW_RLE_offset_pair needs the base address added. */
13884 if (rlet
== DW_RLE_offset_pair
)
13886 if (!base
.has_value ())
13888 /* We have no valid base address for the DW_RLE_offset_pair. */
13889 complaint (_("Invalid .debug_rnglists data (no base address for "
13890 "DW_RLE_offset_pair)"));
13894 range_beginning
+= *base
;
13895 range_end
+= *base
;
13898 /* A not-uncommon case of bad debug info.
13899 Don't pollute the addrmap with bad data. */
13900 if (range_beginning
== 0
13901 && !per_objfile
->per_bfd
->has_section_at_zero
)
13903 complaint (_(".debug_rnglists entry has start address of zero"
13904 " [in module %s]"), objfile_name (objfile
));
13908 callback (range_beginning
, range_end
);
13913 complaint (_("Offset %d is not terminated "
13914 "for DW_AT_ranges attribute"),
13922 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13923 Callback's type should be:
13924 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13925 Return 1 if the attributes are present and valid, otherwise, return 0. */
13927 template <typename Callback
>
13929 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13930 Callback
&&callback
)
13932 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13933 struct objfile
*objfile
= per_objfile
->objfile
;
13934 struct comp_unit_head
*cu_header
= &cu
->header
;
13935 bfd
*obfd
= objfile
->obfd
;
13936 unsigned int addr_size
= cu_header
->addr_size
;
13937 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13938 /* Base address selection entry. */
13939 gdb::optional
<CORE_ADDR
> base
;
13940 unsigned int dummy
;
13941 const gdb_byte
*buffer
;
13943 if (cu_header
->version
>= 5)
13944 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13946 base
= cu
->base_address
;
13948 per_objfile
->per_bfd
->ranges
.read (objfile
);
13949 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13951 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13955 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13959 CORE_ADDR range_beginning
, range_end
;
13961 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13962 buffer
+= addr_size
;
13963 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13964 buffer
+= addr_size
;
13965 offset
+= 2 * addr_size
;
13967 /* An end of list marker is a pair of zero addresses. */
13968 if (range_beginning
== 0 && range_end
== 0)
13969 /* Found the end of list entry. */
13972 /* Each base address selection entry is a pair of 2 values.
13973 The first is the largest possible address, the second is
13974 the base address. Check for a base address here. */
13975 if ((range_beginning
& mask
) == mask
)
13977 /* If we found the largest possible address, then we already
13978 have the base address in range_end. */
13983 if (!base
.has_value ())
13985 /* We have no valid base address for the ranges
13987 complaint (_("Invalid .debug_ranges data (no base address)"));
13991 if (range_beginning
> range_end
)
13993 /* Inverted range entries are invalid. */
13994 complaint (_("Invalid .debug_ranges data (inverted range)"));
13998 /* Empty range entries have no effect. */
13999 if (range_beginning
== range_end
)
14002 range_beginning
+= *base
;
14003 range_end
+= *base
;
14005 /* A not-uncommon case of bad debug info.
14006 Don't pollute the addrmap with bad data. */
14007 if (range_beginning
== 0
14008 && !per_objfile
->per_bfd
->has_section_at_zero
)
14010 complaint (_(".debug_ranges entry has start address of zero"
14011 " [in module %s]"), objfile_name (objfile
));
14015 callback (range_beginning
, range_end
);
14021 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14022 Return 1 if the attributes are present and valid, otherwise, return 0.
14023 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14026 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14027 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14028 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14030 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14031 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14032 struct gdbarch
*gdbarch
= objfile
->arch ();
14033 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14036 CORE_ADDR high
= 0;
14039 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14040 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14042 if (ranges_pst
!= NULL
)
14047 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14048 range_beginning
+ baseaddr
)
14050 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14051 range_end
+ baseaddr
)
14053 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14054 lowpc
, highpc
- 1, ranges_pst
);
14057 /* FIXME: This is recording everything as a low-high
14058 segment of consecutive addresses. We should have a
14059 data structure for discontiguous block ranges
14063 low
= range_beginning
;
14069 if (range_beginning
< low
)
14070 low
= range_beginning
;
14071 if (range_end
> high
)
14079 /* If the first entry is an end-of-list marker, the range
14080 describes an empty scope, i.e. no instructions. */
14086 *high_return
= high
;
14090 /* Process ranges and fill in a vector of the low PC values only. */
14093 dwarf2_ranges_read_low_addrs (unsigned offset
, struct dwarf2_cu
*cu
,
14095 std::vector
<CORE_ADDR
> &result
)
14097 dwarf2_ranges_process (offset
, cu
, tag
,
14098 [&] (CORE_ADDR start
, CORE_ADDR end
)
14100 result
.push_back (start
);
14104 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14105 definition for the return value. *LOWPC and *HIGHPC are set iff
14106 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14108 static enum pc_bounds_kind
14109 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14110 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14111 dwarf2_psymtab
*pst
)
14113 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14114 struct attribute
*attr
;
14115 struct attribute
*attr_high
;
14117 CORE_ADDR high
= 0;
14118 enum pc_bounds_kind ret
;
14120 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14123 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14124 if (attr
!= nullptr)
14126 low
= attr
->as_address ();
14127 high
= attr_high
->as_address ();
14128 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14132 /* Found high w/o low attribute. */
14133 return PC_BOUNDS_INVALID
;
14135 /* Found consecutive range of addresses. */
14136 ret
= PC_BOUNDS_HIGH_LOW
;
14140 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14141 if (attr
!= nullptr && attr
->form_is_unsigned ())
14143 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14144 on DWARF version). */
14145 ULONGEST ranges_offset
= attr
->as_unsigned ();
14147 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14149 if (die
->tag
!= DW_TAG_compile_unit
)
14150 ranges_offset
+= cu
->gnu_ranges_base
;
14152 /* Value of the DW_AT_ranges attribute is the offset in the
14153 .debug_ranges section. */
14154 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14156 return PC_BOUNDS_INVALID
;
14157 /* Found discontinuous range of addresses. */
14158 ret
= PC_BOUNDS_RANGES
;
14161 return PC_BOUNDS_NOT_PRESENT
;
14164 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14166 return PC_BOUNDS_INVALID
;
14168 /* When using the GNU linker, .gnu.linkonce. sections are used to
14169 eliminate duplicate copies of functions and vtables and such.
14170 The linker will arbitrarily choose one and discard the others.
14171 The AT_*_pc values for such functions refer to local labels in
14172 these sections. If the section from that file was discarded, the
14173 labels are not in the output, so the relocs get a value of 0.
14174 If this is a discarded function, mark the pc bounds as invalid,
14175 so that GDB will ignore it. */
14176 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14177 return PC_BOUNDS_INVALID
;
14185 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14186 its low and high PC addresses. Do nothing if these addresses could not
14187 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14188 and HIGHPC to the high address if greater than HIGHPC. */
14191 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14192 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14193 struct dwarf2_cu
*cu
)
14195 CORE_ADDR low
, high
;
14196 struct die_info
*child
= die
->child
;
14198 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14200 *lowpc
= std::min (*lowpc
, low
);
14201 *highpc
= std::max (*highpc
, high
);
14204 /* If the language does not allow nested subprograms (either inside
14205 subprograms or lexical blocks), we're done. */
14206 if (cu
->per_cu
->lang
!= language_ada
)
14209 /* Check all the children of the given DIE. If it contains nested
14210 subprograms, then check their pc bounds. Likewise, we need to
14211 check lexical blocks as well, as they may also contain subprogram
14213 while (child
&& child
->tag
)
14215 if (child
->tag
== DW_TAG_subprogram
14216 || child
->tag
== DW_TAG_lexical_block
)
14217 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14218 child
= child
->sibling
;
14222 /* Get the low and high pc's represented by the scope DIE, and store
14223 them in *LOWPC and *HIGHPC. If the correct values can't be
14224 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14227 get_scope_pc_bounds (struct die_info
*die
,
14228 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14229 struct dwarf2_cu
*cu
)
14231 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14232 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14233 CORE_ADDR current_low
, current_high
;
14235 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14236 >= PC_BOUNDS_RANGES
)
14238 best_low
= current_low
;
14239 best_high
= current_high
;
14243 struct die_info
*child
= die
->child
;
14245 while (child
&& child
->tag
)
14247 switch (child
->tag
) {
14248 case DW_TAG_subprogram
:
14249 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14251 case DW_TAG_namespace
:
14252 case DW_TAG_module
:
14253 /* FIXME: carlton/2004-01-16: Should we do this for
14254 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14255 that current GCC's always emit the DIEs corresponding
14256 to definitions of methods of classes as children of a
14257 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14258 the DIEs giving the declarations, which could be
14259 anywhere). But I don't see any reason why the
14260 standards says that they have to be there. */
14261 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14263 if (current_low
!= ((CORE_ADDR
) -1))
14265 best_low
= std::min (best_low
, current_low
);
14266 best_high
= std::max (best_high
, current_high
);
14274 child
= child
->sibling
;
14279 *highpc
= best_high
;
14282 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14286 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14287 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14289 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14290 struct gdbarch
*gdbarch
= objfile
->arch ();
14291 struct attribute
*attr
;
14292 struct attribute
*attr_high
;
14294 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14297 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14298 if (attr
!= nullptr)
14300 CORE_ADDR low
= attr
->as_address ();
14301 CORE_ADDR high
= attr_high
->as_address ();
14303 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14306 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14307 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14308 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14312 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14313 if (attr
!= nullptr && attr
->form_is_unsigned ())
14315 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14316 on DWARF version). */
14317 ULONGEST ranges_offset
= attr
->as_unsigned ();
14319 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14321 if (die
->tag
!= DW_TAG_compile_unit
)
14322 ranges_offset
+= cu
->gnu_ranges_base
;
14324 std::vector
<blockrange
> blockvec
;
14325 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14326 [&] (CORE_ADDR start
, CORE_ADDR end
)
14330 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14331 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14332 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14333 blockvec
.emplace_back (start
, end
);
14336 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14340 /* Check whether the producer field indicates either of GCC < 4.6, or the
14341 Intel C/C++ compiler, and cache the result in CU. */
14344 check_producer (struct dwarf2_cu
*cu
)
14348 if (cu
->producer
== NULL
)
14350 /* For unknown compilers expect their behavior is DWARF version
14353 GCC started to support .debug_types sections by -gdwarf-4 since
14354 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14355 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14356 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14357 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14359 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14361 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14362 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14363 cu
->producer_is_gcc_11
= major
== 11;
14365 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14367 cu
->producer_is_icc
= true;
14368 cu
->producer_is_icc_lt_14
= major
< 14;
14370 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14371 cu
->producer_is_codewarrior
= true;
14374 /* For other non-GCC compilers, expect their behavior is DWARF version
14378 cu
->checked_producer
= true;
14381 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14382 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14383 during 4.6.0 experimental. */
14386 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14388 if (!cu
->checked_producer
)
14389 check_producer (cu
);
14391 return cu
->producer_is_gxx_lt_4_6
;
14395 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14396 with incorrect is_stmt attributes. */
14399 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14401 if (!cu
->checked_producer
)
14402 check_producer (cu
);
14404 return cu
->producer_is_codewarrior
;
14407 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14408 If that attribute is not available, return the appropriate
14411 static enum dwarf_access_attribute
14412 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14414 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14415 if (attr
!= nullptr)
14417 LONGEST value
= attr
->constant_value (-1);
14418 if (value
== DW_ACCESS_public
14419 || value
== DW_ACCESS_protected
14420 || value
== DW_ACCESS_private
)
14421 return (dwarf_access_attribute
) value
;
14422 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14426 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14428 /* The default DWARF 2 accessibility for members is public, the default
14429 accessibility for inheritance is private. */
14431 if (die
->tag
!= DW_TAG_inheritance
)
14432 return DW_ACCESS_public
;
14434 return DW_ACCESS_private
;
14438 /* DWARF 3+ defines the default accessibility a different way. The same
14439 rules apply now for DW_TAG_inheritance as for the members and it only
14440 depends on the container kind. */
14442 if (die
->parent
->tag
== DW_TAG_class_type
)
14443 return DW_ACCESS_private
;
14445 return DW_ACCESS_public
;
14449 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
14450 *OFFSET to the byte offset. If the attribute was not found return
14451 0, otherwise return 1. If it was found but could not properly be
14452 handled, set *OFFSET to 0. */
14455 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14458 struct attribute
*attr
;
14460 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14465 /* Note that we do not check for a section offset first here.
14466 This is because DW_AT_data_member_location is new in DWARF 4,
14467 so if we see it, we can assume that a constant form is really
14468 a constant and not a section offset. */
14469 if (attr
->form_is_constant ())
14470 *offset
= attr
->constant_value (0);
14471 else if (attr
->form_is_section_offset ())
14472 dwarf2_complex_location_expr_complaint ();
14473 else if (attr
->form_is_block ())
14474 *offset
= decode_locdesc (attr
->as_block (), cu
);
14476 dwarf2_complex_location_expr_complaint ();
14482 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14483 if (attr
!= nullptr)
14485 *offset
= attr
->constant_value (0);
14493 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
14494 store the results in FIELD. */
14497 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14498 struct field
*field
)
14500 struct attribute
*attr
;
14502 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14505 if (attr
->form_is_constant ())
14507 LONGEST offset
= attr
->constant_value (0);
14509 /* Work around this GCC 11 bug, where it would erroneously use -1
14510 data member locations, instead of 0:
14512 Negative DW_AT_data_member_location
14513 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
14515 if (offset
== -1 && cu
->producer_is_gcc_11
)
14517 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
14521 field
->set_loc_bitpos (offset
* bits_per_byte
);
14523 else if (attr
->form_is_section_offset ())
14524 dwarf2_complex_location_expr_complaint ();
14525 else if (attr
->form_is_block ())
14528 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14530 field
->set_loc_bitpos (offset
* bits_per_byte
);
14533 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14534 struct objfile
*objfile
= per_objfile
->objfile
;
14535 struct dwarf2_locexpr_baton
*dlbaton
14536 = XOBNEW (&objfile
->objfile_obstack
,
14537 struct dwarf2_locexpr_baton
);
14538 dlbaton
->data
= attr
->as_block ()->data
;
14539 dlbaton
->size
= attr
->as_block ()->size
;
14540 /* When using this baton, we want to compute the address
14541 of the field, not the value. This is why
14542 is_reference is set to false here. */
14543 dlbaton
->is_reference
= false;
14544 dlbaton
->per_objfile
= per_objfile
;
14545 dlbaton
->per_cu
= cu
->per_cu
;
14547 field
->set_loc_dwarf_block (dlbaton
);
14551 dwarf2_complex_location_expr_complaint ();
14555 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14556 if (attr
!= nullptr)
14557 field
->set_loc_bitpos (attr
->constant_value (0));
14561 /* Add an aggregate field to the field list. */
14564 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14565 struct dwarf2_cu
*cu
)
14567 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14568 struct gdbarch
*gdbarch
= objfile
->arch ();
14569 struct nextfield
*new_field
;
14570 struct attribute
*attr
;
14572 const char *fieldname
= "";
14574 if (die
->tag
== DW_TAG_inheritance
)
14576 fip
->baseclasses
.emplace_back ();
14577 new_field
= &fip
->baseclasses
.back ();
14581 fip
->fields
.emplace_back ();
14582 new_field
= &fip
->fields
.back ();
14585 new_field
->offset
= die
->sect_off
;
14587 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14588 if (new_field
->accessibility
!= DW_ACCESS_public
)
14589 fip
->non_public_fields
= true;
14591 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14592 if (attr
!= nullptr)
14593 new_field
->virtuality
= attr
->as_virtuality ();
14595 new_field
->virtuality
= DW_VIRTUALITY_none
;
14597 fp
= &new_field
->field
;
14599 if ((die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_namelist_item
)
14600 && !die_is_declaration (die
, cu
))
14602 if (die
->tag
== DW_TAG_namelist_item
)
14604 /* Typically, DW_TAG_namelist_item are references to namelist items.
14605 If so, follow that reference. */
14606 struct attribute
*attr1
= dwarf2_attr (die
, DW_AT_namelist_item
, cu
);
14607 struct die_info
*item_die
= nullptr;
14608 struct dwarf2_cu
*item_cu
= cu
;
14609 if (attr1
->form_is_ref ())
14610 item_die
= follow_die_ref (die
, attr1
, &item_cu
);
14611 if (item_die
!= nullptr)
14614 /* Data member other than a C++ static data member. */
14616 /* Get type of field. */
14617 fp
->set_type (die_type (die
, cu
));
14619 fp
->set_loc_bitpos (0);
14621 /* Get bit size of field (zero if none). */
14622 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14623 if (attr
!= nullptr)
14625 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14629 FIELD_BITSIZE (*fp
) = 0;
14632 /* Get bit offset of field. */
14633 handle_member_location (die
, cu
, fp
);
14634 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14635 if (attr
!= nullptr && attr
->form_is_constant ())
14637 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14639 /* For big endian bits, the DW_AT_bit_offset gives the
14640 additional bit offset from the MSB of the containing
14641 anonymous object to the MSB of the field. We don't
14642 have to do anything special since we don't need to
14643 know the size of the anonymous object. */
14644 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
14648 /* For little endian bits, compute the bit offset to the
14649 MSB of the anonymous object, subtract off the number of
14650 bits from the MSB of the field to the MSB of the
14651 object, and then subtract off the number of bits of
14652 the field itself. The result is the bit offset of
14653 the LSB of the field. */
14654 int anonymous_size
;
14655 int bit_offset
= attr
->constant_value (0);
14657 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14658 if (attr
!= nullptr && attr
->form_is_constant ())
14660 /* The size of the anonymous object containing
14661 the bit field is explicit, so use the
14662 indicated size (in bytes). */
14663 anonymous_size
= attr
->constant_value (0);
14667 /* The size of the anonymous object containing
14668 the bit field must be inferred from the type
14669 attribute of the data member containing the
14671 anonymous_size
= TYPE_LENGTH (fp
->type ());
14673 fp
->set_loc_bitpos (fp
->loc_bitpos ()
14674 + anonymous_size
* bits_per_byte
14675 - bit_offset
- FIELD_BITSIZE (*fp
));
14679 /* Get name of field. */
14680 fieldname
= dwarf2_name (die
, cu
);
14681 if (fieldname
== NULL
)
14684 /* The name is already allocated along with this objfile, so we don't
14685 need to duplicate it for the type. */
14686 fp
->set_name (fieldname
);
14688 /* Change accessibility for artificial fields (e.g. virtual table
14689 pointer or virtual base class pointer) to private. */
14690 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14692 FIELD_ARTIFICIAL (*fp
) = 1;
14693 new_field
->accessibility
= DW_ACCESS_private
;
14694 fip
->non_public_fields
= true;
14697 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14699 /* C++ static member. */
14701 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14702 is a declaration, but all versions of G++ as of this writing
14703 (so through at least 3.2.1) incorrectly generate
14704 DW_TAG_variable tags. */
14706 const char *physname
;
14708 /* Get name of field. */
14709 fieldname
= dwarf2_name (die
, cu
);
14710 if (fieldname
== NULL
)
14713 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14715 /* Only create a symbol if this is an external value.
14716 new_symbol checks this and puts the value in the global symbol
14717 table, which we want. If it is not external, new_symbol
14718 will try to put the value in cu->list_in_scope which is wrong. */
14719 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14721 /* A static const member, not much different than an enum as far as
14722 we're concerned, except that we can support more types. */
14723 new_symbol (die
, NULL
, cu
);
14726 /* Get physical name. */
14727 physname
= dwarf2_physname (fieldname
, die
, cu
);
14729 /* The name is already allocated along with this objfile, so we don't
14730 need to duplicate it for the type. */
14731 fp
->set_loc_physname (physname
? physname
: "");
14732 fp
->set_type (die_type (die
, cu
));
14733 fp
->set_name (fieldname
);
14735 else if (die
->tag
== DW_TAG_inheritance
)
14737 /* C++ base class field. */
14738 handle_member_location (die
, cu
, fp
);
14739 FIELD_BITSIZE (*fp
) = 0;
14740 fp
->set_type (die_type (die
, cu
));
14741 fp
->set_name (fp
->type ()->name ());
14744 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14747 /* Can the type given by DIE define another type? */
14750 type_can_define_types (const struct die_info
*die
)
14754 case DW_TAG_typedef
:
14755 case DW_TAG_class_type
:
14756 case DW_TAG_structure_type
:
14757 case DW_TAG_union_type
:
14758 case DW_TAG_enumeration_type
:
14766 /* Add a type definition defined in the scope of the FIP's class. */
14769 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14770 struct dwarf2_cu
*cu
)
14772 struct decl_field fp
;
14773 memset (&fp
, 0, sizeof (fp
));
14775 gdb_assert (type_can_define_types (die
));
14777 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14778 fp
.name
= dwarf2_name (die
, cu
);
14779 fp
.type
= read_type_die (die
, cu
);
14781 /* Save accessibility. */
14782 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14783 switch (accessibility
)
14785 case DW_ACCESS_public
:
14786 /* The assumed value if neither private nor protected. */
14788 case DW_ACCESS_private
:
14791 case DW_ACCESS_protected
:
14792 fp
.is_protected
= 1;
14796 if (die
->tag
== DW_TAG_typedef
)
14797 fip
->typedef_field_list
.push_back (fp
);
14799 fip
->nested_types_list
.push_back (fp
);
14802 /* A convenience typedef that's used when finding the discriminant
14803 field for a variant part. */
14804 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14807 /* Compute the discriminant range for a given variant. OBSTACK is
14808 where the results will be stored. VARIANT is the variant to
14809 process. IS_UNSIGNED indicates whether the discriminant is signed
14812 static const gdb::array_view
<discriminant_range
>
14813 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14816 std::vector
<discriminant_range
> ranges
;
14818 if (variant
.default_branch
)
14821 if (variant
.discr_list_data
== nullptr)
14823 discriminant_range r
14824 = {variant
.discriminant_value
, variant
.discriminant_value
};
14825 ranges
.push_back (r
);
14829 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14830 variant
.discr_list_data
->size
);
14831 while (!data
.empty ())
14833 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14835 complaint (_("invalid discriminant marker: %d"), data
[0]);
14838 bool is_range
= data
[0] == DW_DSC_range
;
14839 data
= data
.slice (1);
14841 ULONGEST low
, high
;
14842 unsigned int bytes_read
;
14846 complaint (_("DW_AT_discr_list missing low value"));
14850 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14852 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14854 data
= data
.slice (bytes_read
);
14860 complaint (_("DW_AT_discr_list missing high value"));
14864 high
= read_unsigned_leb128 (nullptr, data
.data (),
14867 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14869 data
= data
.slice (bytes_read
);
14874 ranges
.push_back ({ low
, high
});
14878 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14880 std::copy (ranges
.begin (), ranges
.end (), result
);
14881 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14884 static const gdb::array_view
<variant_part
> create_variant_parts
14885 (struct obstack
*obstack
,
14886 const offset_map_type
&offset_map
,
14887 struct field_info
*fi
,
14888 const std::vector
<variant_part_builder
> &variant_parts
);
14890 /* Fill in a "struct variant" for a given variant field. RESULT is
14891 the variant to fill in. OBSTACK is where any needed allocations
14892 will be done. OFFSET_MAP holds the mapping from section offsets to
14893 fields for the type. FI describes the fields of the type we're
14894 processing. FIELD is the variant field we're converting. */
14897 create_one_variant (variant
&result
, struct obstack
*obstack
,
14898 const offset_map_type
&offset_map
,
14899 struct field_info
*fi
, const variant_field
&field
)
14901 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14902 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14903 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14904 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14905 field
.variant_parts
);
14908 /* Fill in a "struct variant_part" for a given variant part. RESULT
14909 is the variant part to fill in. OBSTACK is where any needed
14910 allocations will be done. OFFSET_MAP holds the mapping from
14911 section offsets to fields for the type. FI describes the fields of
14912 the type we're processing. BUILDER is the variant part to be
14916 create_one_variant_part (variant_part
&result
,
14917 struct obstack
*obstack
,
14918 const offset_map_type
&offset_map
,
14919 struct field_info
*fi
,
14920 const variant_part_builder
&builder
)
14922 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14923 if (iter
== offset_map
.end ())
14925 result
.discriminant_index
= -1;
14926 /* Doesn't matter. */
14927 result
.is_unsigned
= false;
14931 result
.discriminant_index
= iter
->second
;
14933 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14936 size_t n
= builder
.variants
.size ();
14937 variant
*output
= new (obstack
) variant
[n
];
14938 for (size_t i
= 0; i
< n
; ++i
)
14939 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14940 builder
.variants
[i
]);
14942 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14945 /* Create a vector of variant parts that can be attached to a type.
14946 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14947 holds the mapping from section offsets to fields for the type. FI
14948 describes the fields of the type we're processing. VARIANT_PARTS
14949 is the vector to convert. */
14951 static const gdb::array_view
<variant_part
>
14952 create_variant_parts (struct obstack
*obstack
,
14953 const offset_map_type
&offset_map
,
14954 struct field_info
*fi
,
14955 const std::vector
<variant_part_builder
> &variant_parts
)
14957 if (variant_parts
.empty ())
14960 size_t n
= variant_parts
.size ();
14961 variant_part
*result
= new (obstack
) variant_part
[n
];
14962 for (size_t i
= 0; i
< n
; ++i
)
14963 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14966 return gdb::array_view
<variant_part
> (result
, n
);
14969 /* Compute the variant part vector for FIP, attaching it to TYPE when
14973 add_variant_property (struct field_info
*fip
, struct type
*type
,
14974 struct dwarf2_cu
*cu
)
14976 /* Map section offsets of fields to their field index. Note the
14977 field index here does not take the number of baseclasses into
14979 offset_map_type offset_map
;
14980 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14981 offset_map
[fip
->fields
[i
].offset
] = i
;
14983 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14984 gdb::array_view
<const variant_part
> parts
14985 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14986 fip
->variant_parts
);
14988 struct dynamic_prop prop
;
14989 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14990 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14993 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14996 /* Create the vector of fields, and attach it to the type. */
14999 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15000 struct dwarf2_cu
*cu
)
15002 int nfields
= fip
->nfields ();
15004 /* Record the field count, allocate space for the array of fields,
15005 and create blank accessibility bitfields if necessary. */
15006 type
->set_num_fields (nfields
);
15008 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15010 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
15012 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15014 TYPE_FIELD_PRIVATE_BITS (type
) =
15015 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15016 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15018 TYPE_FIELD_PROTECTED_BITS (type
) =
15019 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15020 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15022 TYPE_FIELD_IGNORE_BITS (type
) =
15023 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15024 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15027 /* If the type has baseclasses, allocate and clear a bit vector for
15028 TYPE_FIELD_VIRTUAL_BITS. */
15029 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
15031 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15032 unsigned char *pointer
;
15034 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15035 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15036 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15037 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15038 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15041 if (!fip
->variant_parts
.empty ())
15042 add_variant_property (fip
, type
, cu
);
15044 /* Copy the saved-up fields into the field vector. */
15045 for (int i
= 0; i
< nfields
; ++i
)
15047 struct nextfield
&field
15048 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15049 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15051 type
->field (i
) = field
.field
;
15052 switch (field
.accessibility
)
15054 case DW_ACCESS_private
:
15055 if (cu
->per_cu
->lang
!= language_ada
)
15056 SET_TYPE_FIELD_PRIVATE (type
, i
);
15059 case DW_ACCESS_protected
:
15060 if (cu
->per_cu
->lang
!= language_ada
)
15061 SET_TYPE_FIELD_PROTECTED (type
, i
);
15064 case DW_ACCESS_public
:
15068 /* Unknown accessibility. Complain and treat it as public. */
15070 complaint (_("unsupported accessibility %d"),
15071 field
.accessibility
);
15075 if (i
< fip
->baseclasses
.size ())
15077 switch (field
.virtuality
)
15079 case DW_VIRTUALITY_virtual
:
15080 case DW_VIRTUALITY_pure_virtual
:
15081 if (cu
->per_cu
->lang
== language_ada
)
15082 error (_("unexpected virtuality in component of Ada type"));
15083 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15090 /* Return true if this member function is a constructor, false
15094 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15096 const char *fieldname
;
15097 const char *type_name
;
15100 if (die
->parent
== NULL
)
15103 if (die
->parent
->tag
!= DW_TAG_structure_type
15104 && die
->parent
->tag
!= DW_TAG_union_type
15105 && die
->parent
->tag
!= DW_TAG_class_type
)
15108 fieldname
= dwarf2_name (die
, cu
);
15109 type_name
= dwarf2_name (die
->parent
, cu
);
15110 if (fieldname
== NULL
|| type_name
== NULL
)
15113 len
= strlen (fieldname
);
15114 return (strncmp (fieldname
, type_name
, len
) == 0
15115 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15118 /* Add a member function to the proper fieldlist. */
15121 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15122 struct type
*type
, struct dwarf2_cu
*cu
)
15124 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15125 struct attribute
*attr
;
15127 struct fnfieldlist
*flp
= nullptr;
15128 struct fn_field
*fnp
;
15129 const char *fieldname
;
15130 struct type
*this_type
;
15132 if (cu
->per_cu
->lang
== language_ada
)
15133 error (_("unexpected member function in Ada type"));
15135 /* Get name of member function. */
15136 fieldname
= dwarf2_name (die
, cu
);
15137 if (fieldname
== NULL
)
15140 /* Look up member function name in fieldlist. */
15141 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15143 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15145 flp
= &fip
->fnfieldlists
[i
];
15150 /* Create a new fnfieldlist if necessary. */
15151 if (flp
== nullptr)
15153 fip
->fnfieldlists
.emplace_back ();
15154 flp
= &fip
->fnfieldlists
.back ();
15155 flp
->name
= fieldname
;
15156 i
= fip
->fnfieldlists
.size () - 1;
15159 /* Create a new member function field and add it to the vector of
15161 flp
->fnfields
.emplace_back ();
15162 fnp
= &flp
->fnfields
.back ();
15164 /* Delay processing of the physname until later. */
15165 if (cu
->per_cu
->lang
== language_cplus
)
15166 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15170 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15171 fnp
->physname
= physname
? physname
: "";
15174 fnp
->type
= alloc_type (objfile
);
15175 this_type
= read_type_die (die
, cu
);
15176 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15178 int nparams
= this_type
->num_fields ();
15180 /* TYPE is the domain of this method, and THIS_TYPE is the type
15181 of the method itself (TYPE_CODE_METHOD). */
15182 smash_to_method_type (fnp
->type
, type
,
15183 TYPE_TARGET_TYPE (this_type
),
15184 this_type
->fields (),
15185 this_type
->num_fields (),
15186 this_type
->has_varargs ());
15188 /* Handle static member functions.
15189 Dwarf2 has no clean way to discern C++ static and non-static
15190 member functions. G++ helps GDB by marking the first
15191 parameter for non-static member functions (which is the this
15192 pointer) as artificial. We obtain this information from
15193 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15194 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15195 fnp
->voffset
= VOFFSET_STATIC
;
15198 complaint (_("member function type missing for '%s'"),
15199 dwarf2_full_name (fieldname
, die
, cu
));
15201 /* Get fcontext from DW_AT_containing_type if present. */
15202 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15203 fnp
->fcontext
= die_containing_type (die
, cu
);
15205 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15206 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15208 /* Get accessibility. */
15209 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15210 switch (accessibility
)
15212 case DW_ACCESS_private
:
15213 fnp
->is_private
= 1;
15215 case DW_ACCESS_protected
:
15216 fnp
->is_protected
= 1;
15220 /* Check for artificial methods. */
15221 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15222 if (attr
&& attr
->as_boolean ())
15223 fnp
->is_artificial
= 1;
15225 /* Check for defaulted methods. */
15226 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15227 if (attr
!= nullptr)
15228 fnp
->defaulted
= attr
->defaulted ();
15230 /* Check for deleted methods. */
15231 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15232 if (attr
!= nullptr && attr
->as_boolean ())
15233 fnp
->is_deleted
= 1;
15235 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15237 /* Get index in virtual function table if it is a virtual member
15238 function. For older versions of GCC, this is an offset in the
15239 appropriate virtual table, as specified by DW_AT_containing_type.
15240 For everyone else, it is an expression to be evaluated relative
15241 to the object address. */
15243 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15244 if (attr
!= nullptr)
15246 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15248 struct dwarf_block
*block
= attr
->as_block ();
15250 if (block
->data
[0] == DW_OP_constu
)
15252 /* Old-style GCC. */
15253 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15255 else if (block
->data
[0] == DW_OP_deref
15256 || (block
->size
> 1
15257 && block
->data
[0] == DW_OP_deref_size
15258 && block
->data
[1] == cu
->header
.addr_size
))
15260 fnp
->voffset
= decode_locdesc (block
, cu
);
15261 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15262 dwarf2_complex_location_expr_complaint ();
15264 fnp
->voffset
/= cu
->header
.addr_size
;
15268 dwarf2_complex_location_expr_complaint ();
15270 if (!fnp
->fcontext
)
15272 /* If there is no `this' field and no DW_AT_containing_type,
15273 we cannot actually find a base class context for the
15275 if (this_type
->num_fields () == 0
15276 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15278 complaint (_("cannot determine context for virtual member "
15279 "function \"%s\" (offset %s)"),
15280 fieldname
, sect_offset_str (die
->sect_off
));
15285 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15289 else if (attr
->form_is_section_offset ())
15291 dwarf2_complex_location_expr_complaint ();
15295 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15301 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15302 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15304 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15305 complaint (_("Member function \"%s\" (offset %s) is virtual "
15306 "but the vtable offset is not specified"),
15307 fieldname
, sect_offset_str (die
->sect_off
));
15308 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15309 TYPE_CPLUS_DYNAMIC (type
) = 1;
15314 /* Create the vector of member function fields, and attach it to the type. */
15317 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15318 struct dwarf2_cu
*cu
)
15320 if (cu
->per_cu
->lang
== language_ada
)
15321 error (_("unexpected member functions in Ada type"));
15323 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15324 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15326 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15328 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15330 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15331 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15333 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15334 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15335 fn_flp
->fn_fields
= (struct fn_field
*)
15336 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15338 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15339 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15342 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15345 /* Returns non-zero if NAME is the name of a vtable member in CU's
15346 language, zero otherwise. */
15348 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15350 static const char vptr
[] = "_vptr";
15352 /* Look for the C++ form of the vtable. */
15353 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15359 /* GCC outputs unnamed structures that are really pointers to member
15360 functions, with the ABI-specified layout. If TYPE describes
15361 such a structure, smash it into a member function type.
15363 GCC shouldn't do this; it should just output pointer to member DIEs.
15364 This is GCC PR debug/28767. */
15367 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15369 struct type
*pfn_type
, *self_type
, *new_type
;
15371 /* Check for a structure with no name and two children. */
15372 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15375 /* Check for __pfn and __delta members. */
15376 if (type
->field (0).name () == NULL
15377 || strcmp (type
->field (0).name (), "__pfn") != 0
15378 || type
->field (1).name () == NULL
15379 || strcmp (type
->field (1).name (), "__delta") != 0)
15382 /* Find the type of the method. */
15383 pfn_type
= type
->field (0).type ();
15384 if (pfn_type
== NULL
15385 || pfn_type
->code () != TYPE_CODE_PTR
15386 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15389 /* Look for the "this" argument. */
15390 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15391 if (pfn_type
->num_fields () == 0
15392 /* || pfn_type->field (0).type () == NULL */
15393 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15396 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15397 new_type
= alloc_type (objfile
);
15398 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15399 pfn_type
->fields (), pfn_type
->num_fields (),
15400 pfn_type
->has_varargs ());
15401 smash_to_methodptr_type (type
, new_type
);
15404 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15405 requires rewriting, then copy it and return the updated copy.
15406 Otherwise return nullptr. */
15408 static struct type
*
15409 rewrite_array_type (struct type
*type
)
15411 if (type
->code () != TYPE_CODE_ARRAY
)
15414 struct type
*index_type
= type
->index_type ();
15415 range_bounds
*current_bounds
= index_type
->bounds ();
15417 /* Handle multi-dimensional arrays. */
15418 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15419 if (new_target
== nullptr)
15421 /* Maybe we don't need to rewrite this array. */
15422 if (current_bounds
->low
.kind () == PROP_CONST
15423 && current_bounds
->high
.kind () == PROP_CONST
)
15427 /* Either the target type was rewritten, or the bounds have to be
15428 updated. Either way we want to copy the type and update
15430 struct type
*copy
= copy_type (type
);
15431 int nfields
= copy
->num_fields ();
15433 = ((struct field
*) TYPE_ZALLOC (copy
,
15434 nfields
* sizeof (struct field
)));
15435 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15436 copy
->set_fields (new_fields
);
15437 if (new_target
!= nullptr)
15438 TYPE_TARGET_TYPE (copy
) = new_target
;
15440 struct type
*index_copy
= copy_type (index_type
);
15441 range_bounds
*bounds
15442 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15443 sizeof (range_bounds
));
15444 *bounds
= *current_bounds
;
15445 bounds
->low
.set_const_val (1);
15446 bounds
->high
.set_const_val (0);
15447 index_copy
->set_bounds (bounds
);
15448 copy
->set_index_type (index_copy
);
15453 /* While some versions of GCC will generate complicated DWARF for an
15454 array (see quirk_ada_thick_pointer), more recent versions were
15455 modified to emit an explicit thick pointer structure. However, in
15456 this case, the array still has DWARF expressions for its ranges,
15457 and these must be ignored. */
15460 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15463 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15465 /* Check for a structure with two children. */
15466 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15469 /* Check for P_ARRAY and P_BOUNDS members. */
15470 if (type
->field (0).name () == NULL
15471 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
15472 || type
->field (1).name () == NULL
15473 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
15476 /* Make sure we're looking at a pointer to an array. */
15477 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15480 /* The Ada code already knows how to handle these types, so all that
15481 we need to do is turn the bounds into static bounds. However, we
15482 don't want to rewrite existing array or index types in-place,
15483 because those may be referenced in other contexts where this
15484 rewriting is undesirable. */
15485 struct type
*new_ary_type
15486 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15487 if (new_ary_type
!= nullptr)
15488 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15491 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15492 appropriate error checking and issuing complaints if there is a
15496 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15498 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15500 if (attr
== nullptr)
15503 if (!attr
->form_is_constant ())
15505 complaint (_("DW_AT_alignment must have constant form"
15506 " - DIE at %s [in module %s]"),
15507 sect_offset_str (die
->sect_off
),
15508 objfile_name (cu
->per_objfile
->objfile
));
15512 LONGEST val
= attr
->constant_value (0);
15515 complaint (_("DW_AT_alignment value must not be negative"
15516 " - DIE at %s [in module %s]"),
15517 sect_offset_str (die
->sect_off
),
15518 objfile_name (cu
->per_objfile
->objfile
));
15521 ULONGEST align
= val
;
15525 complaint (_("DW_AT_alignment value must not be zero"
15526 " - DIE at %s [in module %s]"),
15527 sect_offset_str (die
->sect_off
),
15528 objfile_name (cu
->per_objfile
->objfile
));
15531 if ((align
& (align
- 1)) != 0)
15533 complaint (_("DW_AT_alignment value must be a power of 2"
15534 " - DIE at %s [in module %s]"),
15535 sect_offset_str (die
->sect_off
),
15536 objfile_name (cu
->per_objfile
->objfile
));
15543 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15544 the alignment for TYPE. */
15547 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15550 if (!set_type_align (type
, get_alignment (cu
, die
)))
15551 complaint (_("DW_AT_alignment value too large"
15552 " - DIE at %s [in module %s]"),
15553 sect_offset_str (die
->sect_off
),
15554 objfile_name (cu
->per_objfile
->objfile
));
15557 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15558 constant for a type, according to DWARF5 spec, Table 5.5. */
15561 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15566 case DW_CC_pass_by_reference
:
15567 case DW_CC_pass_by_value
:
15571 complaint (_("unrecognized DW_AT_calling_convention value "
15572 "(%s) for a type"), pulongest (value
));
15577 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15578 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15579 also according to GNU-specific values (see include/dwarf2.h). */
15582 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15587 case DW_CC_program
:
15591 case DW_CC_GNU_renesas_sh
:
15592 case DW_CC_GNU_borland_fastcall_i386
:
15593 case DW_CC_GDB_IBM_OpenCL
:
15597 complaint (_("unrecognized DW_AT_calling_convention value "
15598 "(%s) for a subroutine"), pulongest (value
));
15603 /* Called when we find the DIE that starts a structure or union scope
15604 (definition) to create a type for the structure or union. Fill in
15605 the type's name and general properties; the members will not be
15606 processed until process_structure_scope. A symbol table entry for
15607 the type will also not be done until process_structure_scope (assuming
15608 the type has a name).
15610 NOTE: we need to call these functions regardless of whether or not the
15611 DIE has a DW_AT_name attribute, since it might be an anonymous
15612 structure or union. This gets the type entered into our set of
15613 user defined types. */
15615 static struct type
*
15616 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15618 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15620 struct attribute
*attr
;
15623 /* If the definition of this type lives in .debug_types, read that type.
15624 Don't follow DW_AT_specification though, that will take us back up
15625 the chain and we want to go down. */
15626 attr
= die
->attr (DW_AT_signature
);
15627 if (attr
!= nullptr)
15629 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15631 /* The type's CU may not be the same as CU.
15632 Ensure TYPE is recorded with CU in die_type_hash. */
15633 return set_die_type (die
, type
, cu
);
15636 type
= alloc_type (objfile
);
15637 INIT_CPLUS_SPECIFIC (type
);
15639 name
= dwarf2_name (die
, cu
);
15642 if (cu
->per_cu
->lang
== language_cplus
15643 || cu
->per_cu
->lang
== language_d
15644 || cu
->per_cu
->lang
== language_rust
)
15646 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15648 /* dwarf2_full_name might have already finished building the DIE's
15649 type. If so, there is no need to continue. */
15650 if (get_die_type (die
, cu
) != NULL
)
15651 return get_die_type (die
, cu
);
15653 type
->set_name (full_name
);
15657 /* The name is already allocated along with this objfile, so
15658 we don't need to duplicate it for the type. */
15659 type
->set_name (name
);
15663 if (die
->tag
== DW_TAG_structure_type
)
15665 type
->set_code (TYPE_CODE_STRUCT
);
15667 else if (die
->tag
== DW_TAG_union_type
)
15669 type
->set_code (TYPE_CODE_UNION
);
15671 else if (die
->tag
== DW_TAG_namelist
)
15673 type
->set_code (TYPE_CODE_NAMELIST
);
15677 type
->set_code (TYPE_CODE_STRUCT
);
15680 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15681 type
->set_is_declared_class (true);
15683 /* Store the calling convention in the type if it's available in
15684 the die. Otherwise the calling convention remains set to
15685 the default value DW_CC_normal. */
15686 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15687 if (attr
!= nullptr
15688 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15690 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15691 TYPE_CPLUS_CALLING_CONVENTION (type
)
15692 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15695 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15696 if (attr
!= nullptr)
15698 if (attr
->form_is_constant ())
15699 TYPE_LENGTH (type
) = attr
->constant_value (0);
15702 struct dynamic_prop prop
;
15703 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15704 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15705 TYPE_LENGTH (type
) = 0;
15710 TYPE_LENGTH (type
) = 0;
15713 maybe_set_alignment (cu
, die
, type
);
15715 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15717 /* ICC<14 does not output the required DW_AT_declaration on
15718 incomplete types, but gives them a size of zero. */
15719 type
->set_is_stub (true);
15722 type
->set_stub_is_supported (true);
15724 if (die_is_declaration (die
, cu
))
15725 type
->set_is_stub (true);
15726 else if (attr
== NULL
&& die
->child
== NULL
15727 && producer_is_realview (cu
->producer
))
15728 /* RealView does not output the required DW_AT_declaration
15729 on incomplete types. */
15730 type
->set_is_stub (true);
15732 /* We need to add the type field to the die immediately so we don't
15733 infinitely recurse when dealing with pointers to the structure
15734 type within the structure itself. */
15735 set_die_type (die
, type
, cu
);
15737 /* set_die_type should be already done. */
15738 set_descriptive_type (type
, die
, cu
);
15743 static void handle_struct_member_die
15744 (struct die_info
*child_die
,
15746 struct field_info
*fi
,
15747 std::vector
<struct symbol
*> *template_args
,
15748 struct dwarf2_cu
*cu
);
15750 /* A helper for handle_struct_member_die that handles
15751 DW_TAG_variant_part. */
15754 handle_variant_part (struct die_info
*die
, struct type
*type
,
15755 struct field_info
*fi
,
15756 std::vector
<struct symbol
*> *template_args
,
15757 struct dwarf2_cu
*cu
)
15759 variant_part_builder
*new_part
;
15760 if (fi
->current_variant_part
== nullptr)
15762 fi
->variant_parts
.emplace_back ();
15763 new_part
= &fi
->variant_parts
.back ();
15765 else if (!fi
->current_variant_part
->processing_variant
)
15767 complaint (_("nested DW_TAG_variant_part seen "
15768 "- DIE at %s [in module %s]"),
15769 sect_offset_str (die
->sect_off
),
15770 objfile_name (cu
->per_objfile
->objfile
));
15775 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15776 current
.variant_parts
.emplace_back ();
15777 new_part
= ¤t
.variant_parts
.back ();
15780 /* When we recurse, we want callees to add to this new variant
15782 scoped_restore save_current_variant_part
15783 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15785 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15788 /* It's a univariant form, an extension we support. */
15790 else if (discr
->form_is_ref ())
15792 struct dwarf2_cu
*target_cu
= cu
;
15793 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15795 new_part
->discriminant_offset
= target_die
->sect_off
;
15799 complaint (_("DW_AT_discr does not have DIE reference form"
15800 " - DIE at %s [in module %s]"),
15801 sect_offset_str (die
->sect_off
),
15802 objfile_name (cu
->per_objfile
->objfile
));
15805 for (die_info
*child_die
= die
->child
;
15807 child_die
= child_die
->sibling
)
15808 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15811 /* A helper for handle_struct_member_die that handles
15815 handle_variant (struct die_info
*die
, struct type
*type
,
15816 struct field_info
*fi
,
15817 std::vector
<struct symbol
*> *template_args
,
15818 struct dwarf2_cu
*cu
)
15820 if (fi
->current_variant_part
== nullptr)
15822 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15823 "- DIE at %s [in module %s]"),
15824 sect_offset_str (die
->sect_off
),
15825 objfile_name (cu
->per_objfile
->objfile
));
15828 if (fi
->current_variant_part
->processing_variant
)
15830 complaint (_("nested DW_TAG_variant seen "
15831 "- DIE at %s [in module %s]"),
15832 sect_offset_str (die
->sect_off
),
15833 objfile_name (cu
->per_objfile
->objfile
));
15837 scoped_restore save_processing_variant
15838 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15841 fi
->current_variant_part
->variants
.emplace_back ();
15842 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15843 variant
.first_field
= fi
->fields
.size ();
15845 /* In a variant we want to get the discriminant and also add a
15846 field for our sole member child. */
15847 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15848 if (discr
== nullptr || !discr
->form_is_constant ())
15850 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15851 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15852 variant
.default_branch
= true;
15854 variant
.discr_list_data
= discr
->as_block ();
15857 variant
.discriminant_value
= discr
->constant_value (0);
15859 for (die_info
*variant_child
= die
->child
;
15860 variant_child
!= NULL
;
15861 variant_child
= variant_child
->sibling
)
15862 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15864 variant
.last_field
= fi
->fields
.size ();
15867 /* A helper for process_structure_scope that handles a single member
15871 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15872 struct field_info
*fi
,
15873 std::vector
<struct symbol
*> *template_args
,
15874 struct dwarf2_cu
*cu
)
15876 if (child_die
->tag
== DW_TAG_member
15877 || child_die
->tag
== DW_TAG_variable
15878 || child_die
->tag
== DW_TAG_namelist_item
)
15880 /* NOTE: carlton/2002-11-05: A C++ static data member
15881 should be a DW_TAG_member that is a declaration, but
15882 all versions of G++ as of this writing (so through at
15883 least 3.2.1) incorrectly generate DW_TAG_variable
15884 tags for them instead. */
15885 dwarf2_add_field (fi
, child_die
, cu
);
15887 else if (child_die
->tag
== DW_TAG_subprogram
)
15889 /* Rust doesn't have member functions in the C++ sense.
15890 However, it does emit ordinary functions as children
15891 of a struct DIE. */
15892 if (cu
->per_cu
->lang
== language_rust
)
15893 read_func_scope (child_die
, cu
);
15896 /* C++ member function. */
15897 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15900 else if (child_die
->tag
== DW_TAG_inheritance
)
15902 /* C++ base class field. */
15903 dwarf2_add_field (fi
, child_die
, cu
);
15905 else if (type_can_define_types (child_die
))
15906 dwarf2_add_type_defn (fi
, child_die
, cu
);
15907 else if (child_die
->tag
== DW_TAG_template_type_param
15908 || child_die
->tag
== DW_TAG_template_value_param
)
15910 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15913 template_args
->push_back (arg
);
15915 else if (child_die
->tag
== DW_TAG_variant_part
)
15916 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15917 else if (child_die
->tag
== DW_TAG_variant
)
15918 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15921 /* Finish creating a structure or union type, including filling in its
15922 members and creating a symbol for it. This function also handles Fortran
15923 namelist variables, their items or members and creating a symbol for
15927 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15929 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15930 struct die_info
*child_die
;
15933 type
= get_die_type (die
, cu
);
15935 type
= read_structure_type (die
, cu
);
15937 bool has_template_parameters
= false;
15938 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15940 struct field_info fi
;
15941 std::vector
<struct symbol
*> template_args
;
15943 child_die
= die
->child
;
15945 while (child_die
&& child_die
->tag
)
15947 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15948 child_die
= child_die
->sibling
;
15951 /* Attach template arguments to type. */
15952 if (!template_args
.empty ())
15954 has_template_parameters
= true;
15955 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15956 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15957 TYPE_TEMPLATE_ARGUMENTS (type
)
15958 = XOBNEWVEC (&objfile
->objfile_obstack
,
15960 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15961 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15962 template_args
.data (),
15963 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15964 * sizeof (struct symbol
*)));
15967 /* Attach fields and member functions to the type. */
15968 if (fi
.nfields () > 0)
15969 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15970 if (!fi
.fnfieldlists
.empty ())
15972 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15974 /* Get the type which refers to the base class (possibly this
15975 class itself) which contains the vtable pointer for the current
15976 class from the DW_AT_containing_type attribute. This use of
15977 DW_AT_containing_type is a GNU extension. */
15979 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15981 struct type
*t
= die_containing_type (die
, cu
);
15983 set_type_vptr_basetype (type
, t
);
15988 /* Our own class provides vtbl ptr. */
15989 for (i
= t
->num_fields () - 1;
15990 i
>= TYPE_N_BASECLASSES (t
);
15993 const char *fieldname
= t
->field (i
).name ();
15995 if (is_vtable_name (fieldname
, cu
))
15997 set_type_vptr_fieldno (type
, i
);
16002 /* Complain if virtual function table field not found. */
16003 if (i
< TYPE_N_BASECLASSES (t
))
16004 complaint (_("virtual function table pointer "
16005 "not found when defining class '%s'"),
16006 type
->name () ? type
->name () : "");
16010 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16013 else if (cu
->producer
16014 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16016 /* The IBM XLC compiler does not provide direct indication
16017 of the containing type, but the vtable pointer is
16018 always named __vfp. */
16022 for (i
= type
->num_fields () - 1;
16023 i
>= TYPE_N_BASECLASSES (type
);
16026 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
16028 set_type_vptr_fieldno (type
, i
);
16029 set_type_vptr_basetype (type
, type
);
16036 /* Copy fi.typedef_field_list linked list elements content into the
16037 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16038 if (!fi
.typedef_field_list
.empty ())
16040 int count
= fi
.typedef_field_list
.size ();
16042 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16043 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16044 = ((struct decl_field
*)
16046 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16047 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16049 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16050 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16053 /* Copy fi.nested_types_list linked list elements content into the
16054 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16055 if (!fi
.nested_types_list
.empty ()
16056 && cu
->per_cu
->lang
!= language_ada
)
16058 int count
= fi
.nested_types_list
.size ();
16060 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16061 TYPE_NESTED_TYPES_ARRAY (type
)
16062 = ((struct decl_field
*)
16063 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16064 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16066 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16067 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16071 quirk_gcc_member_function_pointer (type
, objfile
);
16072 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16073 cu
->rust_unions
.push_back (type
);
16074 else if (cu
->per_cu
->lang
== language_ada
)
16075 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16077 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16078 snapshots) has been known to create a die giving a declaration
16079 for a class that has, as a child, a die giving a definition for a
16080 nested class. So we have to process our children even if the
16081 current die is a declaration. Normally, of course, a declaration
16082 won't have any children at all. */
16084 child_die
= die
->child
;
16086 while (child_die
!= NULL
&& child_die
->tag
)
16088 if (child_die
->tag
== DW_TAG_member
16089 || child_die
->tag
== DW_TAG_variable
16090 || child_die
->tag
== DW_TAG_inheritance
16091 || child_die
->tag
== DW_TAG_template_value_param
16092 || child_die
->tag
== DW_TAG_template_type_param
)
16097 process_die (child_die
, cu
);
16099 child_die
= child_die
->sibling
;
16102 /* Do not consider external references. According to the DWARF standard,
16103 these DIEs are identified by the fact that they have no byte_size
16104 attribute, and a declaration attribute. */
16105 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16106 || !die_is_declaration (die
, cu
)
16107 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16109 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16111 if (has_template_parameters
)
16113 struct symtab
*symtab
;
16114 if (sym
!= nullptr)
16115 symtab
= symbol_symtab (sym
);
16116 else if (cu
->line_header
!= nullptr)
16118 /* Any related symtab will do. */
16120 = cu
->line_header
->file_names ()[0].symtab
;
16125 complaint (_("could not find suitable "
16126 "symtab for template parameter"
16127 " - DIE at %s [in module %s]"),
16128 sect_offset_str (die
->sect_off
),
16129 objfile_name (objfile
));
16132 if (symtab
!= nullptr)
16134 /* Make sure that the symtab is set on the new symbols.
16135 Even though they don't appear in this symtab directly,
16136 other parts of gdb assume that symbols do, and this is
16137 reasonably true. */
16138 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16139 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16145 /* Assuming DIE is an enumeration type, and TYPE is its associated
16146 type, update TYPE using some information only available in DIE's
16147 children. In particular, the fields are computed. */
16150 update_enumeration_type_from_children (struct die_info
*die
,
16152 struct dwarf2_cu
*cu
)
16154 struct die_info
*child_die
;
16155 int unsigned_enum
= 1;
16158 auto_obstack obstack
;
16159 std::vector
<struct field
> fields
;
16161 for (child_die
= die
->child
;
16162 child_die
!= NULL
&& child_die
->tag
;
16163 child_die
= child_die
->sibling
)
16165 struct attribute
*attr
;
16167 const gdb_byte
*bytes
;
16168 struct dwarf2_locexpr_baton
*baton
;
16171 if (child_die
->tag
!= DW_TAG_enumerator
)
16174 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16178 name
= dwarf2_name (child_die
, cu
);
16180 name
= "<anonymous enumerator>";
16182 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16183 &value
, &bytes
, &baton
);
16191 if (count_one_bits_ll (value
) >= 2)
16195 fields
.emplace_back ();
16196 struct field
&field
= fields
.back ();
16197 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
16198 field
.set_loc_enumval (value
);
16201 if (!fields
.empty ())
16203 type
->set_num_fields (fields
.size ());
16206 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16207 memcpy (type
->fields (), fields
.data (),
16208 sizeof (struct field
) * fields
.size ());
16212 type
->set_is_unsigned (true);
16215 type
->set_is_flag_enum (true);
16218 /* Given a DW_AT_enumeration_type die, set its type. We do not
16219 complete the type's fields yet, or create any symbols. */
16221 static struct type
*
16222 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16224 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16226 struct attribute
*attr
;
16229 /* If the definition of this type lives in .debug_types, read that type.
16230 Don't follow DW_AT_specification though, that will take us back up
16231 the chain and we want to go down. */
16232 attr
= die
->attr (DW_AT_signature
);
16233 if (attr
!= nullptr)
16235 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16237 /* The type's CU may not be the same as CU.
16238 Ensure TYPE is recorded with CU in die_type_hash. */
16239 return set_die_type (die
, type
, cu
);
16242 type
= alloc_type (objfile
);
16244 type
->set_code (TYPE_CODE_ENUM
);
16245 name
= dwarf2_full_name (NULL
, die
, cu
);
16247 type
->set_name (name
);
16249 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16252 struct type
*underlying_type
= die_type (die
, cu
);
16254 TYPE_TARGET_TYPE (type
) = underlying_type
;
16257 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16258 if (attr
!= nullptr)
16260 TYPE_LENGTH (type
) = attr
->constant_value (0);
16264 TYPE_LENGTH (type
) = 0;
16267 maybe_set_alignment (cu
, die
, type
);
16269 /* The enumeration DIE can be incomplete. In Ada, any type can be
16270 declared as private in the package spec, and then defined only
16271 inside the package body. Such types are known as Taft Amendment
16272 Types. When another package uses such a type, an incomplete DIE
16273 may be generated by the compiler. */
16274 if (die_is_declaration (die
, cu
))
16275 type
->set_is_stub (true);
16277 /* If this type has an underlying type that is not a stub, then we
16278 may use its attributes. We always use the "unsigned" attribute
16279 in this situation, because ordinarily we guess whether the type
16280 is unsigned -- but the guess can be wrong and the underlying type
16281 can tell us the reality. However, we defer to a local size
16282 attribute if one exists, because this lets the compiler override
16283 the underlying type if needed. */
16284 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16286 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16287 underlying_type
= check_typedef (underlying_type
);
16289 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16291 if (TYPE_LENGTH (type
) == 0)
16292 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16294 if (TYPE_RAW_ALIGN (type
) == 0
16295 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16296 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16299 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16301 set_die_type (die
, type
, cu
);
16303 /* Finish the creation of this type by using the enum's children.
16304 Note that, as usual, this must come after set_die_type to avoid
16305 infinite recursion when trying to compute the names of the
16307 update_enumeration_type_from_children (die
, type
, cu
);
16312 /* Given a pointer to a die which begins an enumeration, process all
16313 the dies that define the members of the enumeration, and create the
16314 symbol for the enumeration type.
16316 NOTE: We reverse the order of the element list. */
16319 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16321 struct type
*this_type
;
16323 this_type
= get_die_type (die
, cu
);
16324 if (this_type
== NULL
)
16325 this_type
= read_enumeration_type (die
, cu
);
16327 if (die
->child
!= NULL
)
16329 struct die_info
*child_die
;
16332 child_die
= die
->child
;
16333 while (child_die
&& child_die
->tag
)
16335 if (child_die
->tag
!= DW_TAG_enumerator
)
16337 process_die (child_die
, cu
);
16341 name
= dwarf2_name (child_die
, cu
);
16343 new_symbol (child_die
, this_type
, cu
);
16346 child_die
= child_die
->sibling
;
16350 /* If we are reading an enum from a .debug_types unit, and the enum
16351 is a declaration, and the enum is not the signatured type in the
16352 unit, then we do not want to add a symbol for it. Adding a
16353 symbol would in some cases obscure the true definition of the
16354 enum, giving users an incomplete type when the definition is
16355 actually available. Note that we do not want to do this for all
16356 enums which are just declarations, because C++0x allows forward
16357 enum declarations. */
16358 if (cu
->per_cu
->is_debug_types
16359 && die_is_declaration (die
, cu
))
16361 struct signatured_type
*sig_type
;
16363 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16364 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16365 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16369 new_symbol (die
, this_type
, cu
);
16372 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16373 expression for an index type and finds the corresponding field
16374 offset in the hidden "P_BOUNDS" structure. Returns true on success
16375 and updates *FIELD, false if it fails to recognize an
16379 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16380 int *bounds_offset
, struct field
*field
,
16381 struct dwarf2_cu
*cu
)
16383 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16384 if (attr
== nullptr || !attr
->form_is_block ())
16387 const struct dwarf_block
*block
= attr
->as_block ();
16388 const gdb_byte
*start
= block
->data
;
16389 const gdb_byte
*end
= block
->data
+ block
->size
;
16391 /* The expression to recognize generally looks like:
16393 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16394 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16396 However, the second "plus_uconst" may be missing:
16398 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16399 DW_OP_deref_size: 4)
16401 This happens when the field is at the start of the structure.
16403 Also, the final deref may not be sized:
16405 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16408 This happens when the size of the index type happens to be the
16409 same as the architecture's word size. This can occur with or
16410 without the second plus_uconst. */
16412 if (end
- start
< 2)
16414 if (*start
++ != DW_OP_push_object_address
)
16416 if (*start
++ != DW_OP_plus_uconst
)
16419 uint64_t this_bound_off
;
16420 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16421 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16423 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16424 is consistent among all bounds. */
16425 if (*bounds_offset
== -1)
16426 *bounds_offset
= this_bound_off
;
16427 else if (*bounds_offset
!= this_bound_off
)
16430 if (start
== end
|| *start
++ != DW_OP_deref
)
16436 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16438 /* This means an offset of 0. */
16440 else if (*start
++ != DW_OP_plus_uconst
)
16444 /* The size is the parameter to DW_OP_plus_uconst. */
16446 start
= gdb_read_uleb128 (start
, end
, &val
);
16447 if (start
== nullptr)
16449 if ((int) val
!= val
)
16458 if (*start
== DW_OP_deref_size
)
16460 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16461 if (start
== nullptr)
16464 else if (*start
== DW_OP_deref
)
16466 size
= cu
->header
.addr_size
;
16472 field
->set_loc_bitpos (8 * offset
);
16473 if (size
!= TYPE_LENGTH (field
->type ()))
16474 FIELD_BITSIZE (*field
) = 8 * size
;
16479 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16480 some kinds of Ada arrays:
16482 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16483 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16484 <11e0> DW_AT_data_location: 2 byte block: 97 6
16485 (DW_OP_push_object_address; DW_OP_deref)
16486 <11e3> DW_AT_type : <0x1173>
16487 <11e7> DW_AT_sibling : <0x1201>
16488 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16489 <11ec> DW_AT_type : <0x1206>
16490 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16491 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16492 DW_OP_deref_size: 4)
16493 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16494 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16495 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16497 This actually represents a "thick pointer", which is a structure
16498 with two elements: one that is a pointer to the array data, and one
16499 that is a pointer to another structure; this second structure holds
16502 This returns a new type on success, or nullptr if this didn't
16503 recognize the type. */
16505 static struct type
*
16506 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16509 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16510 /* So far we've only seen this with block form. */
16511 if (attr
== nullptr || !attr
->form_is_block ())
16514 /* Note that this will fail if the structure layout is changed by
16515 the compiler. However, we have no good way to recognize some
16516 other layout, because we don't know what expression the compiler
16517 might choose to emit should this happen. */
16518 struct dwarf_block
*blk
= attr
->as_block ();
16520 || blk
->data
[0] != DW_OP_push_object_address
16521 || blk
->data
[1] != DW_OP_deref
)
16524 int bounds_offset
= -1;
16525 int max_align
= -1;
16526 std::vector
<struct field
> range_fields
;
16527 for (struct die_info
*child_die
= die
->child
;
16529 child_die
= child_die
->sibling
)
16531 if (child_die
->tag
== DW_TAG_subrange_type
)
16533 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16535 int this_align
= type_align (underlying
);
16536 if (this_align
> max_align
)
16537 max_align
= this_align
;
16539 range_fields
.emplace_back ();
16540 range_fields
.emplace_back ();
16542 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16543 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16545 lower
.set_type (underlying
);
16546 FIELD_ARTIFICIAL (lower
) = 1;
16548 upper
.set_type (underlying
);
16549 FIELD_ARTIFICIAL (upper
) = 1;
16551 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16552 &bounds_offset
, &lower
, cu
)
16553 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16554 &bounds_offset
, &upper
, cu
))
16559 /* This shouldn't really happen, but double-check that we found
16560 where the bounds are stored. */
16561 if (bounds_offset
== -1)
16564 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16565 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16569 /* Set the name of each field in the bounds. */
16570 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16571 range_fields
[i
].set_name (objfile
->intern (name
));
16572 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16573 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
16576 struct type
*bounds
= alloc_type (objfile
);
16577 bounds
->set_code (TYPE_CODE_STRUCT
);
16579 bounds
->set_num_fields (range_fields
.size ());
16581 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16582 * sizeof (struct field
))));
16583 memcpy (bounds
->fields (), range_fields
.data (),
16584 bounds
->num_fields () * sizeof (struct field
));
16586 int last_fieldno
= range_fields
.size () - 1;
16587 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
16588 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16589 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16591 /* Rewrite the existing array type in place. Specifically, we
16592 remove any dynamic properties we might have read, and we replace
16593 the index types. */
16594 struct type
*iter
= type
;
16595 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16597 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16598 iter
->main_type
->dyn_prop_list
= nullptr;
16599 iter
->set_index_type
16600 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16601 iter
= TYPE_TARGET_TYPE (iter
);
16604 struct type
*result
= alloc_type (objfile
);
16605 result
->set_code (TYPE_CODE_STRUCT
);
16607 result
->set_num_fields (2);
16609 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16610 * sizeof (struct field
))));
16612 /* The names are chosen to coincide with what the compiler does with
16613 -fgnat-encodings=all, which the Ada code in gdb already
16615 result
->field (0).set_name ("P_ARRAY");
16616 result
->field (0).set_type (lookup_pointer_type (type
));
16618 result
->field (1).set_name ("P_BOUNDS");
16619 result
->field (1).set_type (lookup_pointer_type (bounds
));
16620 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
16622 result
->set_name (type
->name ());
16623 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16624 + TYPE_LENGTH (result
->field (1).type ()));
16629 /* Extract all information from a DW_TAG_array_type DIE and put it in
16630 the DIE's type field. For now, this only handles one dimensional
16633 static struct type
*
16634 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16636 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16637 struct die_info
*child_die
;
16639 struct type
*element_type
, *range_type
, *index_type
;
16640 struct attribute
*attr
;
16642 struct dynamic_prop
*byte_stride_prop
= NULL
;
16643 unsigned int bit_stride
= 0;
16645 element_type
= die_type (die
, cu
);
16647 /* The die_type call above may have already set the type for this DIE. */
16648 type
= get_die_type (die
, cu
);
16652 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16656 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16659 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16660 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16664 complaint (_("unable to read array DW_AT_byte_stride "
16665 " - DIE at %s [in module %s]"),
16666 sect_offset_str (die
->sect_off
),
16667 objfile_name (cu
->per_objfile
->objfile
));
16668 /* Ignore this attribute. We will likely not be able to print
16669 arrays of this type correctly, but there is little we can do
16670 to help if we cannot read the attribute's value. */
16671 byte_stride_prop
= NULL
;
16675 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16677 bit_stride
= attr
->constant_value (0);
16679 /* Irix 6.2 native cc creates array types without children for
16680 arrays with unspecified length. */
16681 if (die
->child
== NULL
)
16683 index_type
= objfile_type (objfile
)->builtin_int
;
16684 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16685 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16686 byte_stride_prop
, bit_stride
);
16687 return set_die_type (die
, type
, cu
);
16690 std::vector
<struct type
*> range_types
;
16691 child_die
= die
->child
;
16692 while (child_die
&& child_die
->tag
)
16694 if (child_die
->tag
== DW_TAG_subrange_type
16695 || child_die
->tag
== DW_TAG_generic_subrange
)
16697 struct type
*child_type
= read_type_die (child_die
, cu
);
16699 if (child_type
!= NULL
)
16701 /* The range type was succesfully read. Save it for the
16702 array type creation. */
16703 range_types
.push_back (child_type
);
16706 child_die
= child_die
->sibling
;
16709 if (range_types
.empty ())
16711 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16712 sect_offset_str (die
->sect_off
),
16713 objfile_name (cu
->per_objfile
->objfile
));
16717 /* Dwarf2 dimensions are output from left to right, create the
16718 necessary array types in backwards order. */
16720 type
= element_type
;
16722 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16726 while (i
< range_types
.size ())
16728 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16729 byte_stride_prop
, bit_stride
);
16731 byte_stride_prop
= nullptr;
16736 size_t ndim
= range_types
.size ();
16739 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16740 byte_stride_prop
, bit_stride
);
16742 byte_stride_prop
= nullptr;
16746 gdb_assert (type
!= element_type
);
16748 /* Understand Dwarf2 support for vector types (like they occur on
16749 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16750 array type. This is not part of the Dwarf2/3 standard yet, but a
16751 custom vendor extension. The main difference between a regular
16752 array and the vector variant is that vectors are passed by value
16754 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16755 if (attr
!= nullptr)
16756 make_vector_type (type
);
16758 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16759 implementation may choose to implement triple vectors using this
16761 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16762 if (attr
!= nullptr && attr
->form_is_unsigned ())
16764 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16765 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16767 complaint (_("DW_AT_byte_size for array type smaller "
16768 "than the total size of elements"));
16771 name
= dwarf2_name (die
, cu
);
16773 type
->set_name (name
);
16775 maybe_set_alignment (cu
, die
, type
);
16777 struct type
*replacement_type
= nullptr;
16778 if (cu
->per_cu
->lang
== language_ada
)
16780 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16781 if (replacement_type
!= nullptr)
16782 type
= replacement_type
;
16785 /* Install the type in the die. */
16786 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16788 /* set_die_type should be already done. */
16789 set_descriptive_type (type
, die
, cu
);
16794 static enum dwarf_array_dim_ordering
16795 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16797 struct attribute
*attr
;
16799 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16801 if (attr
!= nullptr)
16803 LONGEST val
= attr
->constant_value (-1);
16804 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16805 return (enum dwarf_array_dim_ordering
) val
;
16808 /* GNU F77 is a special case, as at 08/2004 array type info is the
16809 opposite order to the dwarf2 specification, but data is still
16810 laid out as per normal fortran.
16812 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16813 version checking. */
16815 if (cu
->per_cu
->lang
== language_fortran
16816 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16818 return DW_ORD_row_major
;
16821 switch (cu
->language_defn
->array_ordering ())
16823 case array_column_major
:
16824 return DW_ORD_col_major
;
16825 case array_row_major
:
16827 return DW_ORD_row_major
;
16831 /* Extract all information from a DW_TAG_set_type DIE and put it in
16832 the DIE's type field. */
16834 static struct type
*
16835 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16837 struct type
*domain_type
, *set_type
;
16838 struct attribute
*attr
;
16840 domain_type
= die_type (die
, cu
);
16842 /* The die_type call above may have already set the type for this DIE. */
16843 set_type
= get_die_type (die
, cu
);
16847 set_type
= create_set_type (NULL
, domain_type
);
16849 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16850 if (attr
!= nullptr && attr
->form_is_unsigned ())
16851 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16853 maybe_set_alignment (cu
, die
, set_type
);
16855 return set_die_type (die
, set_type
, cu
);
16858 /* A helper for read_common_block that creates a locexpr baton.
16859 SYM is the symbol which we are marking as computed.
16860 COMMON_DIE is the DIE for the common block.
16861 COMMON_LOC is the location expression attribute for the common
16863 MEMBER_LOC is the location expression attribute for the particular
16864 member of the common block that we are processing.
16865 CU is the CU from which the above come. */
16868 mark_common_block_symbol_computed (struct symbol
*sym
,
16869 struct die_info
*common_die
,
16870 struct attribute
*common_loc
,
16871 struct attribute
*member_loc
,
16872 struct dwarf2_cu
*cu
)
16874 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16875 struct objfile
*objfile
= per_objfile
->objfile
;
16876 struct dwarf2_locexpr_baton
*baton
;
16878 unsigned int cu_off
;
16879 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16880 LONGEST offset
= 0;
16882 gdb_assert (common_loc
&& member_loc
);
16883 gdb_assert (common_loc
->form_is_block ());
16884 gdb_assert (member_loc
->form_is_block ()
16885 || member_loc
->form_is_constant ());
16887 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16888 baton
->per_objfile
= per_objfile
;
16889 baton
->per_cu
= cu
->per_cu
;
16890 gdb_assert (baton
->per_cu
);
16892 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16894 if (member_loc
->form_is_constant ())
16896 offset
= member_loc
->constant_value (0);
16897 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16900 baton
->size
+= member_loc
->as_block ()->size
;
16902 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16905 *ptr
++ = DW_OP_call4
;
16906 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16907 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16910 if (member_loc
->form_is_constant ())
16912 *ptr
++ = DW_OP_addr
;
16913 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16914 ptr
+= cu
->header
.addr_size
;
16918 /* We have to copy the data here, because DW_OP_call4 will only
16919 use a DW_AT_location attribute. */
16920 struct dwarf_block
*block
= member_loc
->as_block ();
16921 memcpy (ptr
, block
->data
, block
->size
);
16922 ptr
+= block
->size
;
16925 *ptr
++ = DW_OP_plus
;
16926 gdb_assert (ptr
- baton
->data
== baton
->size
);
16928 SYMBOL_LOCATION_BATON (sym
) = baton
;
16929 sym
->set_aclass_index (dwarf2_locexpr_index
);
16932 /* Create appropriate locally-scoped variables for all the
16933 DW_TAG_common_block entries. Also create a struct common_block
16934 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16935 is used to separate the common blocks name namespace from regular
16939 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16941 struct attribute
*attr
;
16943 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16944 if (attr
!= nullptr)
16946 /* Support the .debug_loc offsets. */
16947 if (attr
->form_is_block ())
16951 else if (attr
->form_is_section_offset ())
16953 dwarf2_complex_location_expr_complaint ();
16958 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16959 "common block member");
16964 if (die
->child
!= NULL
)
16966 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16967 struct die_info
*child_die
;
16968 size_t n_entries
= 0, size
;
16969 struct common_block
*common_block
;
16970 struct symbol
*sym
;
16972 for (child_die
= die
->child
;
16973 child_die
&& child_die
->tag
;
16974 child_die
= child_die
->sibling
)
16977 size
= (sizeof (struct common_block
)
16978 + (n_entries
- 1) * sizeof (struct symbol
*));
16980 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16982 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16983 common_block
->n_entries
= 0;
16985 for (child_die
= die
->child
;
16986 child_die
&& child_die
->tag
;
16987 child_die
= child_die
->sibling
)
16989 /* Create the symbol in the DW_TAG_common_block block in the current
16991 sym
= new_symbol (child_die
, NULL
, cu
);
16994 struct attribute
*member_loc
;
16996 common_block
->contents
[common_block
->n_entries
++] = sym
;
16998 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17002 /* GDB has handled this for a long time, but it is
17003 not specified by DWARF. It seems to have been
17004 emitted by gfortran at least as recently as:
17005 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17006 complaint (_("Variable in common block has "
17007 "DW_AT_data_member_location "
17008 "- DIE at %s [in module %s]"),
17009 sect_offset_str (child_die
->sect_off
),
17010 objfile_name (objfile
));
17012 if (member_loc
->form_is_section_offset ())
17013 dwarf2_complex_location_expr_complaint ();
17014 else if (member_loc
->form_is_constant ()
17015 || member_loc
->form_is_block ())
17017 if (attr
!= nullptr)
17018 mark_common_block_symbol_computed (sym
, die
, attr
,
17022 dwarf2_complex_location_expr_complaint ();
17027 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17028 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17032 /* Create a type for a C++ namespace. */
17034 static struct type
*
17035 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17037 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17038 const char *previous_prefix
, *name
;
17042 /* For extensions, reuse the type of the original namespace. */
17043 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17045 struct die_info
*ext_die
;
17046 struct dwarf2_cu
*ext_cu
= cu
;
17048 ext_die
= dwarf2_extension (die
, &ext_cu
);
17049 type
= read_type_die (ext_die
, ext_cu
);
17051 /* EXT_CU may not be the same as CU.
17052 Ensure TYPE is recorded with CU in die_type_hash. */
17053 return set_die_type (die
, type
, cu
);
17056 name
= namespace_name (die
, &is_anonymous
, cu
);
17058 /* Now build the name of the current namespace. */
17060 previous_prefix
= determine_prefix (die
, cu
);
17061 if (previous_prefix
[0] != '\0')
17062 name
= typename_concat (&objfile
->objfile_obstack
,
17063 previous_prefix
, name
, 0, cu
);
17065 /* Create the type. */
17066 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17068 return set_die_type (die
, type
, cu
);
17071 /* Read a namespace scope. */
17074 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17076 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17079 /* Add a symbol associated to this if we haven't seen the namespace
17080 before. Also, add a using directive if it's an anonymous
17083 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17087 type
= read_type_die (die
, cu
);
17088 new_symbol (die
, type
, cu
);
17090 namespace_name (die
, &is_anonymous
, cu
);
17093 const char *previous_prefix
= determine_prefix (die
, cu
);
17095 std::vector
<const char *> excludes
;
17096 add_using_directive (using_directives (cu
),
17097 previous_prefix
, type
->name (), NULL
,
17098 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17102 if (die
->child
!= NULL
)
17104 struct die_info
*child_die
= die
->child
;
17106 while (child_die
&& child_die
->tag
)
17108 process_die (child_die
, cu
);
17109 child_die
= child_die
->sibling
;
17114 /* Read a Fortran module as type. This DIE can be only a declaration used for
17115 imported module. Still we need that type as local Fortran "use ... only"
17116 declaration imports depend on the created type in determine_prefix. */
17118 static struct type
*
17119 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17121 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17122 const char *module_name
;
17125 module_name
= dwarf2_name (die
, cu
);
17126 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17128 return set_die_type (die
, type
, cu
);
17131 /* Read a Fortran module. */
17134 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17136 struct die_info
*child_die
= die
->child
;
17139 type
= read_type_die (die
, cu
);
17140 new_symbol (die
, type
, cu
);
17142 while (child_die
&& child_die
->tag
)
17144 process_die (child_die
, cu
);
17145 child_die
= child_die
->sibling
;
17149 /* Return the name of the namespace represented by DIE. Set
17150 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17153 static const char *
17154 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17156 struct die_info
*current_die
;
17157 const char *name
= NULL
;
17159 /* Loop through the extensions until we find a name. */
17161 for (current_die
= die
;
17162 current_die
!= NULL
;
17163 current_die
= dwarf2_extension (die
, &cu
))
17165 /* We don't use dwarf2_name here so that we can detect the absence
17166 of a name -> anonymous namespace. */
17167 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17173 /* Is it an anonymous namespace? */
17175 *is_anonymous
= (name
== NULL
);
17177 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17182 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17183 the user defined type vector. */
17185 static struct type
*
17186 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17188 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17189 struct comp_unit_head
*cu_header
= &cu
->header
;
17191 struct attribute
*attr_byte_size
;
17192 struct attribute
*attr_address_class
;
17193 int byte_size
, addr_class
;
17194 struct type
*target_type
;
17196 target_type
= die_type (die
, cu
);
17198 /* The die_type call above may have already set the type for this DIE. */
17199 type
= get_die_type (die
, cu
);
17203 type
= lookup_pointer_type (target_type
);
17205 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17206 if (attr_byte_size
)
17207 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17209 byte_size
= cu_header
->addr_size
;
17211 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17212 if (attr_address_class
)
17213 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17215 addr_class
= DW_ADDR_none
;
17217 ULONGEST alignment
= get_alignment (cu
, die
);
17219 /* If the pointer size, alignment, or address class is different
17220 than the default, create a type variant marked as such and set
17221 the length accordingly. */
17222 if (TYPE_LENGTH (type
) != byte_size
17223 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17224 && alignment
!= TYPE_RAW_ALIGN (type
))
17225 || addr_class
!= DW_ADDR_none
)
17227 if (gdbarch_address_class_type_flags_p (gdbarch
))
17229 type_instance_flags type_flags
17230 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17232 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17234 type
= make_type_with_address_space (type
, type_flags
);
17236 else if (TYPE_LENGTH (type
) != byte_size
)
17238 complaint (_("invalid pointer size %d"), byte_size
);
17240 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17242 complaint (_("Invalid DW_AT_alignment"
17243 " - DIE at %s [in module %s]"),
17244 sect_offset_str (die
->sect_off
),
17245 objfile_name (cu
->per_objfile
->objfile
));
17249 /* Should we also complain about unhandled address classes? */
17253 TYPE_LENGTH (type
) = byte_size
;
17254 set_type_align (type
, alignment
);
17255 return set_die_type (die
, type
, cu
);
17258 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17259 the user defined type vector. */
17261 static struct type
*
17262 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17265 struct type
*to_type
;
17266 struct type
*domain
;
17268 to_type
= die_type (die
, cu
);
17269 domain
= die_containing_type (die
, cu
);
17271 /* The calls above may have already set the type for this DIE. */
17272 type
= get_die_type (die
, cu
);
17276 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17277 type
= lookup_methodptr_type (to_type
);
17278 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17280 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17282 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17283 to_type
->fields (), to_type
->num_fields (),
17284 to_type
->has_varargs ());
17285 type
= lookup_methodptr_type (new_type
);
17288 type
= lookup_memberptr_type (to_type
, domain
);
17290 return set_die_type (die
, type
, cu
);
17293 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17294 the user defined type vector. */
17296 static struct type
*
17297 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17298 enum type_code refcode
)
17300 struct comp_unit_head
*cu_header
= &cu
->header
;
17301 struct type
*type
, *target_type
;
17302 struct attribute
*attr
;
17304 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17306 target_type
= die_type (die
, cu
);
17308 /* The die_type call above may have already set the type for this DIE. */
17309 type
= get_die_type (die
, cu
);
17313 type
= lookup_reference_type (target_type
, refcode
);
17314 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17315 if (attr
!= nullptr)
17317 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17321 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17323 maybe_set_alignment (cu
, die
, type
);
17324 return set_die_type (die
, type
, cu
);
17327 /* Add the given cv-qualifiers to the element type of the array. GCC
17328 outputs DWARF type qualifiers that apply to an array, not the
17329 element type. But GDB relies on the array element type to carry
17330 the cv-qualifiers. This mimics section 6.7.3 of the C99
17333 static struct type
*
17334 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17335 struct type
*base_type
, int cnst
, int voltl
)
17337 struct type
*el_type
, *inner_array
;
17339 base_type
= copy_type (base_type
);
17340 inner_array
= base_type
;
17342 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17344 TYPE_TARGET_TYPE (inner_array
) =
17345 copy_type (TYPE_TARGET_TYPE (inner_array
));
17346 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17349 el_type
= TYPE_TARGET_TYPE (inner_array
);
17350 cnst
|= TYPE_CONST (el_type
);
17351 voltl
|= TYPE_VOLATILE (el_type
);
17352 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17354 return set_die_type (die
, base_type
, cu
);
17357 static struct type
*
17358 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17360 struct type
*base_type
, *cv_type
;
17362 base_type
= die_type (die
, cu
);
17364 /* The die_type call above may have already set the type for this DIE. */
17365 cv_type
= get_die_type (die
, cu
);
17369 /* In case the const qualifier is applied to an array type, the element type
17370 is so qualified, not the array type (section 6.7.3 of C99). */
17371 if (base_type
->code () == TYPE_CODE_ARRAY
)
17372 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17374 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17375 return set_die_type (die
, cv_type
, cu
);
17378 static struct type
*
17379 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17381 struct type
*base_type
, *cv_type
;
17383 base_type
= die_type (die
, cu
);
17385 /* The die_type call above may have already set the type for this DIE. */
17386 cv_type
= get_die_type (die
, cu
);
17390 /* In case the volatile qualifier is applied to an array type, the
17391 element type is so qualified, not the array type (section 6.7.3
17393 if (base_type
->code () == TYPE_CODE_ARRAY
)
17394 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17396 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17397 return set_die_type (die
, cv_type
, cu
);
17400 /* Handle DW_TAG_restrict_type. */
17402 static struct type
*
17403 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17405 struct type
*base_type
, *cv_type
;
17407 base_type
= die_type (die
, cu
);
17409 /* The die_type call above may have already set the type for this DIE. */
17410 cv_type
= get_die_type (die
, cu
);
17414 cv_type
= make_restrict_type (base_type
);
17415 return set_die_type (die
, cv_type
, cu
);
17418 /* Handle DW_TAG_atomic_type. */
17420 static struct type
*
17421 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17423 struct type
*base_type
, *cv_type
;
17425 base_type
= die_type (die
, cu
);
17427 /* The die_type call above may have already set the type for this DIE. */
17428 cv_type
= get_die_type (die
, cu
);
17432 cv_type
= make_atomic_type (base_type
);
17433 return set_die_type (die
, cv_type
, cu
);
17436 /* Extract all information from a DW_TAG_string_type DIE and add to
17437 the user defined type vector. It isn't really a user defined type,
17438 but it behaves like one, with other DIE's using an AT_user_def_type
17439 attribute to reference it. */
17441 static struct type
*
17442 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17444 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17445 struct gdbarch
*gdbarch
= objfile
->arch ();
17446 struct type
*type
, *range_type
, *index_type
, *char_type
;
17447 struct attribute
*attr
;
17448 struct dynamic_prop prop
;
17449 bool length_is_constant
= true;
17452 /* There are a couple of places where bit sizes might be made use of
17453 when parsing a DW_TAG_string_type, however, no producer that we know
17454 of make use of these. Handling bit sizes that are a multiple of the
17455 byte size is easy enough, but what about other bit sizes? Lets deal
17456 with that problem when we have to. Warn about these attributes being
17457 unsupported, then parse the type and ignore them like we always
17459 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17460 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17462 static bool warning_printed
= false;
17463 if (!warning_printed
)
17465 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17466 "currently supported on DW_TAG_string_type."));
17467 warning_printed
= true;
17471 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17472 if (attr
!= nullptr && !attr
->form_is_constant ())
17474 /* The string length describes the location at which the length of
17475 the string can be found. The size of the length field can be
17476 specified with one of the attributes below. */
17477 struct type
*prop_type
;
17478 struct attribute
*len
17479 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17480 if (len
== nullptr)
17481 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17482 if (len
!= nullptr && len
->form_is_constant ())
17484 /* Pass 0 as the default as we know this attribute is constant
17485 and the default value will not be returned. */
17486 LONGEST sz
= len
->constant_value (0);
17487 prop_type
= objfile_int_type (objfile
, sz
, true);
17491 /* If the size is not specified then we assume it is the size of
17492 an address on this target. */
17493 prop_type
= cu
->addr_sized_int_type (true);
17496 /* Convert the attribute into a dynamic property. */
17497 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17500 length_is_constant
= false;
17502 else if (attr
!= nullptr)
17504 /* This DW_AT_string_length just contains the length with no
17505 indirection. There's no need to create a dynamic property in this
17506 case. Pass 0 for the default value as we know it will not be
17507 returned in this case. */
17508 length
= attr
->constant_value (0);
17510 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17512 /* We don't currently support non-constant byte sizes for strings. */
17513 length
= attr
->constant_value (1);
17517 /* Use 1 as a fallback length if we have nothing else. */
17521 index_type
= objfile_type (objfile
)->builtin_int
;
17522 if (length_is_constant
)
17523 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17526 struct dynamic_prop low_bound
;
17528 low_bound
.set_const_val (1);
17529 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17531 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17532 type
= create_string_type (NULL
, char_type
, range_type
);
17534 return set_die_type (die
, type
, cu
);
17537 /* Assuming that DIE corresponds to a function, returns nonzero
17538 if the function is prototyped. */
17541 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17543 struct attribute
*attr
;
17545 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17546 if (attr
&& attr
->as_boolean ())
17549 /* The DWARF standard implies that the DW_AT_prototyped attribute
17550 is only meaningful for C, but the concept also extends to other
17551 languages that allow unprototyped functions (Eg: Objective C).
17552 For all other languages, assume that functions are always
17554 if (cu
->per_cu
->lang
!= language_c
17555 && cu
->per_cu
->lang
!= language_objc
17556 && cu
->per_cu
->lang
!= language_opencl
)
17559 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17560 prototyped and unprototyped functions; default to prototyped,
17561 since that is more common in modern code (and RealView warns
17562 about unprototyped functions). */
17563 if (producer_is_realview (cu
->producer
))
17569 /* Handle DIES due to C code like:
17573 int (*funcp)(int a, long l);
17577 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17579 static struct type
*
17580 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17582 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17583 struct type
*type
; /* Type that this function returns. */
17584 struct type
*ftype
; /* Function that returns above type. */
17585 struct attribute
*attr
;
17587 type
= die_type (die
, cu
);
17589 /* The die_type call above may have already set the type for this DIE. */
17590 ftype
= get_die_type (die
, cu
);
17594 ftype
= lookup_function_type (type
);
17596 if (prototyped_function_p (die
, cu
))
17597 ftype
->set_is_prototyped (true);
17599 /* Store the calling convention in the type if it's available in
17600 the subroutine die. Otherwise set the calling convention to
17601 the default value DW_CC_normal. */
17602 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17603 if (attr
!= nullptr
17604 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17605 TYPE_CALLING_CONVENTION (ftype
)
17606 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17607 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17608 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17610 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17612 /* Record whether the function returns normally to its caller or not
17613 if the DWARF producer set that information. */
17614 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17615 if (attr
&& attr
->as_boolean ())
17616 TYPE_NO_RETURN (ftype
) = 1;
17618 /* We need to add the subroutine type to the die immediately so
17619 we don't infinitely recurse when dealing with parameters
17620 declared as the same subroutine type. */
17621 set_die_type (die
, ftype
, cu
);
17623 if (die
->child
!= NULL
)
17625 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17626 struct die_info
*child_die
;
17627 int nparams
, iparams
;
17629 /* Count the number of parameters.
17630 FIXME: GDB currently ignores vararg functions, but knows about
17631 vararg member functions. */
17633 child_die
= die
->child
;
17634 while (child_die
&& child_die
->tag
)
17636 if (child_die
->tag
== DW_TAG_formal_parameter
)
17638 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17639 ftype
->set_has_varargs (true);
17641 child_die
= child_die
->sibling
;
17644 /* Allocate storage for parameters and fill them in. */
17645 ftype
->set_num_fields (nparams
);
17647 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17649 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17650 even if we error out during the parameters reading below. */
17651 for (iparams
= 0; iparams
< nparams
; iparams
++)
17652 ftype
->field (iparams
).set_type (void_type
);
17655 child_die
= die
->child
;
17656 while (child_die
&& child_die
->tag
)
17658 if (child_die
->tag
== DW_TAG_formal_parameter
)
17660 struct type
*arg_type
;
17662 /* DWARF version 2 has no clean way to discern C++
17663 static and non-static member functions. G++ helps
17664 GDB by marking the first parameter for non-static
17665 member functions (which is the this pointer) as
17666 artificial. We pass this information to
17667 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17669 DWARF version 3 added DW_AT_object_pointer, which GCC
17670 4.5 does not yet generate. */
17671 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17672 if (attr
!= nullptr)
17673 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17675 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17676 arg_type
= die_type (child_die
, cu
);
17678 /* RealView does not mark THIS as const, which the testsuite
17679 expects. GCC marks THIS as const in method definitions,
17680 but not in the class specifications (GCC PR 43053). */
17681 if (cu
->per_cu
->lang
== language_cplus
17682 && !TYPE_CONST (arg_type
)
17683 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17686 struct dwarf2_cu
*arg_cu
= cu
;
17687 const char *name
= dwarf2_name (child_die
, cu
);
17689 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17690 if (attr
!= nullptr)
17692 /* If the compiler emits this, use it. */
17693 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17696 else if (name
&& strcmp (name
, "this") == 0)
17697 /* Function definitions will have the argument names. */
17699 else if (name
== NULL
&& iparams
== 0)
17700 /* Declarations may not have the names, so like
17701 elsewhere in GDB, assume an artificial first
17702 argument is "this". */
17706 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17710 ftype
->field (iparams
).set_type (arg_type
);
17713 child_die
= child_die
->sibling
;
17720 static struct type
*
17721 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17723 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17724 const char *name
= NULL
;
17725 struct type
*this_type
, *target_type
;
17727 name
= dwarf2_full_name (NULL
, die
, cu
);
17728 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17729 this_type
->set_target_is_stub (true);
17730 set_die_type (die
, this_type
, cu
);
17731 target_type
= die_type (die
, cu
);
17732 if (target_type
!= this_type
)
17733 TYPE_TARGET_TYPE (this_type
) = target_type
;
17736 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17737 spec and cause infinite loops in GDB. */
17738 complaint (_("Self-referential DW_TAG_typedef "
17739 "- DIE at %s [in module %s]"),
17740 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17741 TYPE_TARGET_TYPE (this_type
) = NULL
;
17745 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17746 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17747 Handle these by just returning the target type, rather than
17748 constructing an anonymous typedef type and trying to handle this
17750 set_die_type (die
, target_type
, cu
);
17751 return target_type
;
17756 /* Helper for get_dwarf2_rational_constant that computes the value of
17757 a given gmp_mpz given an attribute. */
17760 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17762 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17763 location expression that pushes an implicit value. */
17764 if (attr
->form
== DW_FORM_exprloc
)
17766 dwarf_block
*blk
= attr
->as_block ();
17767 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17770 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17771 blk
->data
+ blk
->size
,
17773 if (ptr
- blk
->data
+ len
<= blk
->size
)
17775 mpz_import (value
->val
, len
,
17776 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17782 /* On failure set it to 1. */
17783 *value
= gdb_mpz (1);
17785 else if (attr
->form_is_block ())
17787 dwarf_block
*blk
= attr
->as_block ();
17788 mpz_import (value
->val
, blk
->size
,
17789 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17790 1, 0, 0, blk
->data
);
17793 *value
= gdb_mpz (attr
->constant_value (1));
17796 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17797 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17799 If the numerator and/or numerator attribute is missing,
17800 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17804 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17805 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17807 struct attribute
*num_attr
, *denom_attr
;
17809 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17810 if (num_attr
== nullptr)
17811 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17812 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17814 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17815 if (denom_attr
== nullptr)
17816 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17817 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17819 if (num_attr
== nullptr || denom_attr
== nullptr)
17822 get_mpz (cu
, numerator
, num_attr
);
17823 get_mpz (cu
, denominator
, denom_attr
);
17826 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17827 rational constant, rather than a signed one.
17829 If the rational constant has a negative value, a complaint
17830 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17833 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17834 struct dwarf2_cu
*cu
,
17835 gdb_mpz
*numerator
,
17836 gdb_mpz
*denominator
)
17841 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17842 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17844 mpz_neg (num
.val
, num
.val
);
17845 mpz_neg (denom
.val
, denom
.val
);
17847 else if (mpz_sgn (num
.val
) == -1)
17849 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17851 sect_offset_str (die
->sect_off
));
17854 else if (mpz_sgn (denom
.val
) == -1)
17856 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17858 sect_offset_str (die
->sect_off
));
17862 *numerator
= std::move (num
);
17863 *denominator
= std::move (denom
);
17866 /* Assuming that ENCODING is a string whose contents starting at the
17867 K'th character is "_nn" where "nn" is a decimal number, scan that
17868 number and set RESULT to the value. K is updated to point to the
17869 character immediately following the number.
17871 If the string does not conform to the format described above, false
17872 is returned, and K may or may not be changed. */
17875 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17877 /* The next character should be an underscore ('_') followed
17879 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17882 /* Skip the underscore. */
17886 /* Determine the number of digits for our number. */
17887 while (isdigit (encoding
[k
]))
17892 std::string
copy (&encoding
[start
], k
- start
);
17893 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17899 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17900 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17901 DENOM, update OFFSET, and return true on success. Return false on
17905 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17906 gdb_mpz
*num
, gdb_mpz
*denom
)
17908 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17910 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17913 /* Assuming DIE corresponds to a fixed point type, finish the creation
17914 of the corresponding TYPE by setting its type-specific data. CU is
17915 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17916 encodings. It is nullptr if the GNAT encoding should be
17920 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17921 struct die_info
*die
, struct dwarf2_cu
*cu
)
17923 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17924 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17926 /* If GNAT encodings are preferred, don't examine the
17928 struct attribute
*attr
= nullptr;
17929 if (suffix
== nullptr)
17931 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17932 if (attr
== nullptr)
17933 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17934 if (attr
== nullptr)
17935 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17938 /* Numerator and denominator of our fixed-point type's scaling factor.
17939 The default is a scaling factor of 1, which we use as a fallback
17940 when we are not able to decode it (problem with the debugging info,
17941 unsupported forms, bug in GDB, etc...). Using that as the default
17942 allows us to at least print the unscaled value, which might still
17943 be useful to a user. */
17944 gdb_mpz
scale_num (1);
17945 gdb_mpz
scale_denom (1);
17947 if (attr
== nullptr)
17950 if (suffix
!= nullptr
17951 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17953 /* The number might be encoded as _nn_dd_nn_dd, where the
17954 second ratio is the 'small value. In this situation, we
17955 want the second value. */
17956 && (suffix
[offset
] != '_'
17957 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17964 /* Scaling factor not found. Assume a scaling factor of 1,
17965 and hope for the best. At least the user will be able to
17966 see the encoded value. */
17969 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17970 sect_offset_str (die
->sect_off
));
17973 else if (attr
->name
== DW_AT_binary_scale
)
17975 LONGEST scale_exp
= attr
->constant_value (0);
17976 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17978 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17980 else if (attr
->name
== DW_AT_decimal_scale
)
17982 LONGEST scale_exp
= attr
->constant_value (0);
17983 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17985 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17987 else if (attr
->name
== DW_AT_small
)
17989 struct die_info
*scale_die
;
17990 struct dwarf2_cu
*scale_cu
= cu
;
17992 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17993 if (scale_die
->tag
== DW_TAG_constant
)
17994 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17995 &scale_num
, &scale_denom
);
17997 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17999 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18003 complaint (_("unsupported scale attribute %s for fixed-point type"
18005 dwarf_attr_name (attr
->name
),
18006 sect_offset_str (die
->sect_off
));
18009 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18010 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18011 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18012 mpq_canonicalize (scaling_factor
.val
);
18015 /* The gnat-encoding suffix for fixed point. */
18017 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18019 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18020 "XF" suffix of the name. The text after this is what encodes the
18021 'small and 'delta information. Otherwise, return nullptr. */
18023 static const char *
18024 gnat_encoded_fixed_point_type_info (const char *name
)
18026 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18029 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18030 (which may be different from NAME) to the architecture back-end to allow
18031 it to guess the correct format if necessary. */
18033 static struct type
*
18034 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18035 const char *name_hint
, enum bfd_endian byte_order
)
18037 struct gdbarch
*gdbarch
= objfile
->arch ();
18038 const struct floatformat
**format
;
18041 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18043 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18045 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18050 /* Allocate an integer type of size BITS and name NAME. */
18052 static struct type
*
18053 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18054 int bits
, int unsigned_p
, const char *name
)
18058 /* Versions of Intel's C Compiler generate an integer type called "void"
18059 instead of using DW_TAG_unspecified_type. This has been seen on
18060 at least versions 14, 17, and 18. */
18061 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18062 && strcmp (name
, "void") == 0)
18063 type
= objfile_type (objfile
)->builtin_void
;
18065 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18070 /* Return true if DIE has a DW_AT_small attribute whose value is
18071 a constant rational, where both the numerator and denominator
18074 CU is the DIE's Compilation Unit. */
18077 has_zero_over_zero_small_attribute (struct die_info
*die
,
18078 struct dwarf2_cu
*cu
)
18080 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18081 if (attr
== nullptr)
18084 struct dwarf2_cu
*scale_cu
= cu
;
18085 struct die_info
*scale_die
18086 = follow_die_ref (die
, attr
, &scale_cu
);
18088 if (scale_die
->tag
!= DW_TAG_constant
)
18091 gdb_mpz
num (1), denom (1);
18092 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18093 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18096 /* Initialise and return a floating point type of size BITS suitable for
18097 use as a component of a complex number. The NAME_HINT is passed through
18098 when initialising the floating point type and is the name of the complex
18101 As DWARF doesn't currently provide an explicit name for the components
18102 of a complex number, but it can be helpful to have these components
18103 named, we try to select a suitable name based on the size of the
18105 static struct type
*
18106 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18107 struct objfile
*objfile
,
18108 int bits
, const char *name_hint
,
18109 enum bfd_endian byte_order
)
18111 gdbarch
*gdbarch
= objfile
->arch ();
18112 struct type
*tt
= nullptr;
18114 /* Try to find a suitable floating point builtin type of size BITS.
18115 We're going to use the name of this type as the name for the complex
18116 target type that we are about to create. */
18117 switch (cu
->per_cu
->lang
)
18119 case language_fortran
:
18123 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18126 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18128 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18130 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18138 tt
= builtin_type (gdbarch
)->builtin_float
;
18141 tt
= builtin_type (gdbarch
)->builtin_double
;
18143 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18145 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18151 /* If the type we found doesn't match the size we were looking for, then
18152 pretend we didn't find a type at all, the complex target type we
18153 create will then be nameless. */
18154 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18157 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18158 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18161 /* Find a representation of a given base type and install
18162 it in the TYPE field of the die. */
18164 static struct type
*
18165 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18167 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18169 struct attribute
*attr
;
18170 int encoding
= 0, bits
= 0;
18174 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18175 if (attr
!= nullptr && attr
->form_is_constant ())
18176 encoding
= attr
->constant_value (0);
18177 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18178 if (attr
!= nullptr)
18179 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18180 name
= dwarf2_name (die
, cu
);
18182 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18184 arch
= objfile
->arch ();
18185 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18187 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18188 if (attr
!= nullptr && attr
->form_is_constant ())
18190 int endianity
= attr
->constant_value (0);
18195 byte_order
= BFD_ENDIAN_BIG
;
18197 case DW_END_little
:
18198 byte_order
= BFD_ENDIAN_LITTLE
;
18201 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18206 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18207 && cu
->per_cu
->lang
== language_ada
18208 && has_zero_over_zero_small_attribute (die
, cu
))
18210 /* brobecker/2018-02-24: This is a fixed point type for which
18211 the scaling factor is represented as fraction whose value
18212 does not make sense (zero divided by zero), so we should
18213 normally never see these. However, there is a small category
18214 of fixed point types for which GNAT is unable to provide
18215 the scaling factor via the standard DWARF mechanisms, and
18216 for which the info is provided via the GNAT encodings instead.
18217 This is likely what this DIE is about. */
18218 encoding
= (encoding
== DW_ATE_signed_fixed
18220 : DW_ATE_unsigned
);
18223 /* With GNAT encodings, fixed-point information will be encoded in
18224 the type name. Note that this can also occur with the above
18225 zero-over-zero case, which is why this is a separate "if" rather
18226 than an "else if". */
18227 const char *gnat_encoding_suffix
= nullptr;
18228 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18229 && cu
->per_cu
->lang
== language_ada
18230 && name
!= nullptr)
18232 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18233 if (gnat_encoding_suffix
!= nullptr)
18235 gdb_assert (startswith (gnat_encoding_suffix
,
18236 GNAT_FIXED_POINT_SUFFIX
));
18237 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18238 name
, gnat_encoding_suffix
- name
);
18239 /* Use -1 here so that SUFFIX points at the "_" after the
18241 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18243 encoding
= (encoding
== DW_ATE_signed
18244 ? DW_ATE_signed_fixed
18245 : DW_ATE_unsigned_fixed
);
18251 case DW_ATE_address
:
18252 /* Turn DW_ATE_address into a void * pointer. */
18253 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18254 type
= init_pointer_type (objfile
, bits
, name
, type
);
18256 case DW_ATE_boolean
:
18257 type
= init_boolean_type (objfile
, bits
, 1, name
);
18259 case DW_ATE_complex_float
:
18260 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18262 if (type
->code () == TYPE_CODE_ERROR
)
18264 if (name
== nullptr)
18266 struct obstack
*obstack
18267 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18268 name
= obconcat (obstack
, "_Complex ", type
->name (),
18271 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18274 type
= init_complex_type (name
, type
);
18276 case DW_ATE_decimal_float
:
18277 type
= init_decfloat_type (objfile
, bits
, name
);
18280 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18282 case DW_ATE_signed
:
18283 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18285 case DW_ATE_unsigned
:
18286 if (cu
->per_cu
->lang
== language_fortran
18288 && startswith (name
, "character("))
18289 type
= init_character_type (objfile
, bits
, 1, name
);
18291 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18293 case DW_ATE_signed_char
:
18294 if (cu
->per_cu
->lang
== language_ada
18295 || cu
->per_cu
->lang
== language_m2
18296 || cu
->per_cu
->lang
== language_pascal
18297 || cu
->per_cu
->lang
== language_fortran
)
18298 type
= init_character_type (objfile
, bits
, 0, name
);
18300 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18302 case DW_ATE_unsigned_char
:
18303 if (cu
->per_cu
->lang
== language_ada
18304 || cu
->per_cu
->lang
== language_m2
18305 || cu
->per_cu
->lang
== language_pascal
18306 || cu
->per_cu
->lang
== language_fortran
18307 || cu
->per_cu
->lang
== language_rust
)
18308 type
= init_character_type (objfile
, bits
, 1, name
);
18310 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18314 type
= init_character_type (objfile
, bits
, 1, name
);
18315 return set_die_type (die
, type
, cu
);
18318 case DW_ATE_signed_fixed
:
18319 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18320 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18322 case DW_ATE_unsigned_fixed
:
18323 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18324 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18328 complaint (_("unsupported DW_AT_encoding: '%s'"),
18329 dwarf_type_encoding_name (encoding
));
18330 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18334 if (type
->code () == TYPE_CODE_INT
18336 && strcmp (name
, "char") == 0)
18337 type
->set_has_no_signedness (true);
18339 maybe_set_alignment (cu
, die
, type
);
18341 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18343 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18345 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18346 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18348 unsigned real_bit_size
= attr
->as_unsigned ();
18349 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18350 /* Only use the attributes if they make sense together. */
18351 if (attr
== nullptr
18352 || (attr
->as_unsigned () + real_bit_size
18353 <= 8 * TYPE_LENGTH (type
)))
18355 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18357 if (attr
!= nullptr)
18358 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18359 = attr
->as_unsigned ();
18364 return set_die_type (die
, type
, cu
);
18367 /* A helper function that returns the name of DIE, if it refers to a
18368 variable declaration. */
18370 static const char *
18371 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18373 if (die
->tag
!= DW_TAG_variable
)
18376 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18377 if (attr
== nullptr || !attr
->as_boolean ())
18380 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18381 if (attr
== nullptr)
18383 return attr
->as_string ();
18386 /* Parse dwarf attribute if it's a block, reference or constant and put the
18387 resulting value of the attribute into struct bound_prop.
18388 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18391 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18392 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18393 struct type
*default_type
)
18395 struct dwarf2_property_baton
*baton
;
18396 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18397 struct objfile
*objfile
= per_objfile
->objfile
;
18398 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18400 gdb_assert (default_type
!= NULL
);
18402 if (attr
== NULL
|| prop
== NULL
)
18405 if (attr
->form_is_block ())
18407 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18408 baton
->property_type
= default_type
;
18409 baton
->locexpr
.per_cu
= cu
->per_cu
;
18410 baton
->locexpr
.per_objfile
= per_objfile
;
18412 struct dwarf_block
*block
;
18413 if (attr
->form
== DW_FORM_data16
)
18415 size_t data_size
= 16;
18416 block
= XOBNEW (obstack
, struct dwarf_block
);
18417 block
->size
= (data_size
18418 + 2 /* Extra bytes for DW_OP and arg. */);
18419 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18420 data
[0] = DW_OP_implicit_value
;
18421 data
[1] = data_size
;
18422 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18423 block
->data
= data
;
18426 block
= attr
->as_block ();
18428 baton
->locexpr
.size
= block
->size
;
18429 baton
->locexpr
.data
= block
->data
;
18430 switch (attr
->name
)
18432 case DW_AT_string_length
:
18433 baton
->locexpr
.is_reference
= true;
18436 baton
->locexpr
.is_reference
= false;
18440 prop
->set_locexpr (baton
);
18441 gdb_assert (prop
->baton () != NULL
);
18443 else if (attr
->form_is_ref ())
18445 struct dwarf2_cu
*target_cu
= cu
;
18446 struct die_info
*target_die
;
18447 struct attribute
*target_attr
;
18449 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18450 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18451 if (target_attr
== NULL
)
18452 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18454 if (target_attr
== nullptr)
18455 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
18457 if (target_attr
== NULL
)
18459 const char *name
= var_decl_name (target_die
, target_cu
);
18460 if (name
!= nullptr)
18462 prop
->set_variable_name (name
);
18468 switch (target_attr
->name
)
18470 case DW_AT_location
:
18471 if (target_attr
->form_is_section_offset ())
18473 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18474 baton
->property_type
= die_type (target_die
, target_cu
);
18475 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18476 prop
->set_loclist (baton
);
18477 gdb_assert (prop
->baton () != NULL
);
18479 else if (target_attr
->form_is_block ())
18481 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18482 baton
->property_type
= die_type (target_die
, target_cu
);
18483 baton
->locexpr
.per_cu
= cu
->per_cu
;
18484 baton
->locexpr
.per_objfile
= per_objfile
;
18485 struct dwarf_block
*block
= target_attr
->as_block ();
18486 baton
->locexpr
.size
= block
->size
;
18487 baton
->locexpr
.data
= block
->data
;
18488 baton
->locexpr
.is_reference
= true;
18489 prop
->set_locexpr (baton
);
18490 gdb_assert (prop
->baton () != NULL
);
18494 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18495 "dynamic property");
18499 case DW_AT_data_member_location
:
18500 case DW_AT_data_bit_offset
:
18504 if (!handle_member_location (target_die
, target_cu
, &offset
))
18507 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18508 baton
->property_type
= read_type_die (target_die
->parent
,
18510 baton
->offset_info
.offset
= offset
;
18511 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18512 prop
->set_addr_offset (baton
);
18517 else if (attr
->form_is_constant ())
18518 prop
->set_const_val (attr
->constant_value (0));
18519 else if (attr
->form_is_section_offset ())
18521 switch (attr
->name
)
18523 case DW_AT_string_length
:
18524 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18525 baton
->property_type
= default_type
;
18526 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
18527 prop
->set_loclist (baton
);
18528 gdb_assert (prop
->baton () != NULL
);
18540 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18541 dwarf2_name (die
, cu
));
18547 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18548 present (which is valid) then compute the default type based on the
18549 compilation units address size. */
18551 static struct type
*
18552 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18554 struct type
*index_type
= die_type (die
, cu
);
18556 /* Dwarf-2 specifications explicitly allows to create subrange types
18557 without specifying a base type.
18558 In that case, the base type must be set to the type of
18559 the lower bound, upper bound or count, in that order, if any of these
18560 three attributes references an object that has a type.
18561 If no base type is found, the Dwarf-2 specifications say that
18562 a signed integer type of size equal to the size of an address should
18564 For the following C code: `extern char gdb_int [];'
18565 GCC produces an empty range DIE.
18566 FIXME: muller/2010-05-28: Possible references to object for low bound,
18567 high bound or count are not yet handled by this code. */
18568 if (index_type
->code () == TYPE_CODE_VOID
)
18569 index_type
= cu
->addr_sized_int_type (false);
18574 /* Read the given DW_AT_subrange DIE. */
18576 static struct type
*
18577 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18579 struct type
*base_type
, *orig_base_type
;
18580 struct type
*range_type
;
18581 struct attribute
*attr
;
18582 struct dynamic_prop low
, high
;
18583 int low_default_is_valid
;
18584 int high_bound_is_count
= 0;
18586 ULONGEST negative_mask
;
18588 orig_base_type
= read_subrange_index_type (die
, cu
);
18590 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18591 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18592 creating the range type, but we use the result of check_typedef
18593 when examining properties of the type. */
18594 base_type
= check_typedef (orig_base_type
);
18596 /* The die_type call above may have already set the type for this DIE. */
18597 range_type
= get_die_type (die
, cu
);
18601 high
.set_const_val (0);
18603 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18604 omitting DW_AT_lower_bound. */
18605 switch (cu
->per_cu
->lang
)
18608 case language_cplus
:
18609 low
.set_const_val (0);
18610 low_default_is_valid
= 1;
18612 case language_fortran
:
18613 low
.set_const_val (1);
18614 low_default_is_valid
= 1;
18617 case language_objc
:
18618 case language_rust
:
18619 low
.set_const_val (0);
18620 low_default_is_valid
= (cu
->header
.version
>= 4);
18624 case language_pascal
:
18625 low
.set_const_val (1);
18626 low_default_is_valid
= (cu
->header
.version
>= 4);
18629 low
.set_const_val (0);
18630 low_default_is_valid
= 0;
18634 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18635 if (attr
!= nullptr)
18636 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18637 else if (!low_default_is_valid
)
18638 complaint (_("Missing DW_AT_lower_bound "
18639 "- DIE at %s [in module %s]"),
18640 sect_offset_str (die
->sect_off
),
18641 objfile_name (cu
->per_objfile
->objfile
));
18643 struct attribute
*attr_ub
, *attr_count
;
18644 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18645 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18647 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18648 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18650 /* If bounds are constant do the final calculation here. */
18651 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18652 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18654 high_bound_is_count
= 1;
18658 if (attr_ub
!= NULL
)
18659 complaint (_("Unresolved DW_AT_upper_bound "
18660 "- DIE at %s [in module %s]"),
18661 sect_offset_str (die
->sect_off
),
18662 objfile_name (cu
->per_objfile
->objfile
));
18663 if (attr_count
!= NULL
)
18664 complaint (_("Unresolved DW_AT_count "
18665 "- DIE at %s [in module %s]"),
18666 sect_offset_str (die
->sect_off
),
18667 objfile_name (cu
->per_objfile
->objfile
));
18672 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18673 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18674 bias
= bias_attr
->constant_value (0);
18676 /* Normally, the DWARF producers are expected to use a signed
18677 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18678 But this is unfortunately not always the case, as witnessed
18679 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18680 is used instead. To work around that ambiguity, we treat
18681 the bounds as signed, and thus sign-extend their values, when
18682 the base type is signed. */
18684 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18685 if (low
.kind () == PROP_CONST
18686 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18687 low
.set_const_val (low
.const_val () | negative_mask
);
18688 if (high
.kind () == PROP_CONST
18689 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18690 high
.set_const_val (high
.const_val () | negative_mask
);
18692 /* Check for bit and byte strides. */
18693 struct dynamic_prop byte_stride_prop
;
18694 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18695 if (attr_byte_stride
!= nullptr)
18697 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18698 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18702 struct dynamic_prop bit_stride_prop
;
18703 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18704 if (attr_bit_stride
!= nullptr)
18706 /* It only makes sense to have either a bit or byte stride. */
18707 if (attr_byte_stride
!= nullptr)
18709 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18710 "- DIE at %s [in module %s]"),
18711 sect_offset_str (die
->sect_off
),
18712 objfile_name (cu
->per_objfile
->objfile
));
18713 attr_bit_stride
= nullptr;
18717 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18718 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18723 if (attr_byte_stride
!= nullptr
18724 || attr_bit_stride
!= nullptr)
18726 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18727 struct dynamic_prop
*stride
18728 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18731 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18732 &high
, bias
, stride
, byte_stride_p
);
18735 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18737 if (high_bound_is_count
)
18738 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18740 /* Ada expects an empty array on no boundary attributes. */
18741 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18742 range_type
->bounds ()->high
.set_undefined ();
18744 name
= dwarf2_name (die
, cu
);
18746 range_type
->set_name (name
);
18748 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18749 if (attr
!= nullptr)
18750 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18752 maybe_set_alignment (cu
, die
, range_type
);
18754 set_die_type (die
, range_type
, cu
);
18756 /* set_die_type should be already done. */
18757 set_descriptive_type (range_type
, die
, cu
);
18762 static struct type
*
18763 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18767 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18768 type
->set_name (dwarf2_name (die
, cu
));
18770 /* In Ada, an unspecified type is typically used when the description
18771 of the type is deferred to a different unit. When encountering
18772 such a type, we treat it as a stub, and try to resolve it later on,
18774 if (cu
->per_cu
->lang
== language_ada
)
18775 type
->set_is_stub (true);
18777 return set_die_type (die
, type
, cu
);
18780 /* Read a single die and all its descendents. Set the die's sibling
18781 field to NULL; set other fields in the die correctly, and set all
18782 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18783 location of the info_ptr after reading all of those dies. PARENT
18784 is the parent of the die in question. */
18786 static struct die_info
*
18787 read_die_and_children (const struct die_reader_specs
*reader
,
18788 const gdb_byte
*info_ptr
,
18789 const gdb_byte
**new_info_ptr
,
18790 struct die_info
*parent
)
18792 struct die_info
*die
;
18793 const gdb_byte
*cur_ptr
;
18795 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18798 *new_info_ptr
= cur_ptr
;
18801 store_in_ref_table (die
, reader
->cu
);
18803 if (die
->has_children
)
18804 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18808 *new_info_ptr
= cur_ptr
;
18811 die
->sibling
= NULL
;
18812 die
->parent
= parent
;
18816 /* Read a die, all of its descendents, and all of its siblings; set
18817 all of the fields of all of the dies correctly. Arguments are as
18818 in read_die_and_children. */
18820 static struct die_info
*
18821 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18822 const gdb_byte
*info_ptr
,
18823 const gdb_byte
**new_info_ptr
,
18824 struct die_info
*parent
)
18826 struct die_info
*first_die
, *last_sibling
;
18827 const gdb_byte
*cur_ptr
;
18829 cur_ptr
= info_ptr
;
18830 first_die
= last_sibling
= NULL
;
18834 struct die_info
*die
18835 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18839 *new_info_ptr
= cur_ptr
;
18846 last_sibling
->sibling
= die
;
18848 last_sibling
= die
;
18852 /* Read a die, all of its descendents, and all of its siblings; set
18853 all of the fields of all of the dies correctly. Arguments are as
18854 in read_die_and_children.
18855 This the main entry point for reading a DIE and all its children. */
18857 static struct die_info
*
18858 read_die_and_siblings (const struct die_reader_specs
*reader
,
18859 const gdb_byte
*info_ptr
,
18860 const gdb_byte
**new_info_ptr
,
18861 struct die_info
*parent
)
18863 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18864 new_info_ptr
, parent
);
18866 if (dwarf_die_debug
)
18868 gdb_printf (gdb_stdlog
,
18869 "Read die from %s@0x%x of %s:\n",
18870 reader
->die_section
->get_name (),
18871 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18872 bfd_get_filename (reader
->abfd
));
18873 dump_die (die
, dwarf_die_debug
);
18879 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18881 The caller is responsible for filling in the extra attributes
18882 and updating (*DIEP)->num_attrs.
18883 Set DIEP to point to a newly allocated die with its information,
18884 except for its child, sibling, and parent fields. */
18886 static const gdb_byte
*
18887 read_full_die_1 (const struct die_reader_specs
*reader
,
18888 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18889 int num_extra_attrs
)
18891 unsigned int abbrev_number
, bytes_read
, i
;
18892 const struct abbrev_info
*abbrev
;
18893 struct die_info
*die
;
18894 struct dwarf2_cu
*cu
= reader
->cu
;
18895 bfd
*abfd
= reader
->abfd
;
18897 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18898 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18899 info_ptr
+= bytes_read
;
18900 if (!abbrev_number
)
18906 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18908 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18910 bfd_get_filename (abfd
));
18912 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18913 die
->sect_off
= sect_off
;
18914 die
->tag
= abbrev
->tag
;
18915 die
->abbrev
= abbrev_number
;
18916 die
->has_children
= abbrev
->has_children
;
18918 /* Make the result usable.
18919 The caller needs to update num_attrs after adding the extra
18921 die
->num_attrs
= abbrev
->num_attrs
;
18923 bool any_need_reprocess
= false;
18924 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18926 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18928 if (die
->attrs
[i
].requires_reprocessing_p ())
18929 any_need_reprocess
= true;
18932 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18933 if (attr
!= nullptr && attr
->form_is_unsigned ())
18934 cu
->str_offsets_base
= attr
->as_unsigned ();
18936 attr
= die
->attr (DW_AT_loclists_base
);
18937 if (attr
!= nullptr)
18938 cu
->loclist_base
= attr
->as_unsigned ();
18940 auto maybe_addr_base
= die
->addr_base ();
18941 if (maybe_addr_base
.has_value ())
18942 cu
->addr_base
= *maybe_addr_base
;
18944 attr
= die
->attr (DW_AT_rnglists_base
);
18945 if (attr
!= nullptr)
18946 cu
->rnglists_base
= attr
->as_unsigned ();
18948 if (any_need_reprocess
)
18950 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18952 if (die
->attrs
[i
].requires_reprocessing_p ())
18953 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18960 /* Read a die and all its attributes.
18961 Set DIEP to point to a newly allocated die with its information,
18962 except for its child, sibling, and parent fields. */
18964 static const gdb_byte
*
18965 read_full_die (const struct die_reader_specs
*reader
,
18966 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18968 const gdb_byte
*result
;
18970 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18972 if (dwarf_die_debug
)
18974 gdb_printf (gdb_stdlog
,
18975 "Read die from %s@0x%x of %s:\n",
18976 reader
->die_section
->get_name (),
18977 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18978 bfd_get_filename (reader
->abfd
));
18979 dump_die (*diep
, dwarf_die_debug
);
18986 /* Returns nonzero if TAG represents a type that we might generate a partial
18990 is_type_tag_for_partial (int tag
, enum language lang
)
18995 /* Some types that would be reasonable to generate partial symbols for,
18996 that we don't at present. Note that normally this does not
18997 matter, mainly because C compilers don't give names to these
18998 types, but instead emit DW_TAG_typedef. */
18999 case DW_TAG_file_type
:
19000 case DW_TAG_ptr_to_member_type
:
19001 case DW_TAG_set_type
:
19002 case DW_TAG_string_type
:
19003 case DW_TAG_subroutine_type
:
19006 /* GNAT may emit an array with a name, but no typedef, so we
19007 need to make a symbol in this case. */
19008 case DW_TAG_array_type
:
19009 return lang
== language_ada
;
19011 case DW_TAG_base_type
:
19012 case DW_TAG_class_type
:
19013 case DW_TAG_interface_type
:
19014 case DW_TAG_enumeration_type
:
19015 case DW_TAG_structure_type
:
19016 case DW_TAG_subrange_type
:
19017 case DW_TAG_generic_subrange
:
19018 case DW_TAG_typedef
:
19019 case DW_TAG_union_type
:
19026 /* Load all DIEs that are interesting for partial symbols into memory. */
19028 static struct partial_die_info
*
19029 load_partial_dies (const struct die_reader_specs
*reader
,
19030 const gdb_byte
*info_ptr
, int building_psymtab
)
19032 struct dwarf2_cu
*cu
= reader
->cu
;
19033 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19034 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19035 unsigned int bytes_read
;
19036 unsigned int load_all
= 0;
19037 int nesting_level
= 1;
19042 gdb_assert (cu
->per_cu
!= NULL
);
19043 if (cu
->load_all_dies
)
19047 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19051 &cu
->comp_unit_obstack
,
19052 hashtab_obstack_allocate
,
19053 dummy_obstack_deallocate
);
19057 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19060 /* A NULL abbrev means the end of a series of children. */
19061 if (abbrev
== NULL
)
19063 if (--nesting_level
== 0)
19066 info_ptr
+= bytes_read
;
19067 last_die
= parent_die
;
19068 parent_die
= parent_die
->die_parent
;
19072 /* Check for template arguments. We never save these; if
19073 they're seen, we just mark the parent, and go on our way. */
19074 if (parent_die
!= NULL
19075 && cu
->per_cu
->lang
== language_cplus
19076 && (abbrev
->tag
== DW_TAG_template_type_param
19077 || abbrev
->tag
== DW_TAG_template_value_param
))
19079 parent_die
->has_template_arguments
= 1;
19083 /* We don't need a partial DIE for the template argument. */
19084 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19089 /* We only recurse into c++ subprograms looking for template arguments.
19090 Skip their other children. */
19092 && cu
->per_cu
->lang
== language_cplus
19093 && parent_die
!= NULL
19094 && parent_die
->tag
== DW_TAG_subprogram
19095 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19097 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19101 /* Check whether this DIE is interesting enough to save. Normally
19102 we would not be interested in members here, but there may be
19103 later variables referencing them via DW_AT_specification (for
19104 static members). */
19106 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
19107 && abbrev
->tag
!= DW_TAG_constant
19108 && abbrev
->tag
!= DW_TAG_enumerator
19109 && abbrev
->tag
!= DW_TAG_subprogram
19110 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19111 && abbrev
->tag
!= DW_TAG_lexical_block
19112 && abbrev
->tag
!= DW_TAG_variable
19113 && abbrev
->tag
!= DW_TAG_namespace
19114 && abbrev
->tag
!= DW_TAG_module
19115 && abbrev
->tag
!= DW_TAG_member
19116 && abbrev
->tag
!= DW_TAG_imported_unit
19117 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19119 /* Otherwise we skip to the next sibling, if any. */
19120 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19124 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19127 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19129 /* This two-pass algorithm for processing partial symbols has a
19130 high cost in cache pressure. Thus, handle some simple cases
19131 here which cover the majority of C partial symbols. DIEs
19132 which neither have specification tags in them, nor could have
19133 specification tags elsewhere pointing at them, can simply be
19134 processed and discarded.
19136 This segment is also optional; scan_partial_symbols and
19137 add_partial_symbol will handle these DIEs if we chain
19138 them in normally. When compilers which do not emit large
19139 quantities of duplicate debug information are more common,
19140 this code can probably be removed. */
19142 /* Any complete simple types at the top level (pretty much all
19143 of them, for a language without namespaces), can be processed
19145 if (parent_die
== NULL
19146 && pdi
.has_specification
== 0
19147 && pdi
.is_declaration
== 0
19148 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19149 || pdi
.tag
== DW_TAG_base_type
19150 || pdi
.tag
== DW_TAG_array_type
19151 || pdi
.tag
== DW_TAG_generic_subrange
19152 || pdi
.tag
== DW_TAG_subrange_type
))
19154 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19155 add_partial_symbol (&pdi
, cu
);
19157 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19161 /* The exception for DW_TAG_typedef with has_children above is
19162 a workaround of GCC PR debug/47510. In the case of this complaint
19163 type_name_or_error will error on such types later.
19165 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19166 it could not find the child DIEs referenced later, this is checked
19167 above. In correct DWARF DW_TAG_typedef should have no children. */
19169 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19170 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19171 "- DIE at %s [in module %s]"),
19172 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19174 /* If we're at the second level, and we're an enumerator, and
19175 our parent has no specification (meaning possibly lives in a
19176 namespace elsewhere), then we can add the partial symbol now
19177 instead of queueing it. */
19178 if (pdi
.tag
== DW_TAG_enumerator
19179 && parent_die
!= NULL
19180 && parent_die
->die_parent
== NULL
19181 && parent_die
->tag
== DW_TAG_enumeration_type
19182 && parent_die
->has_specification
== 0)
19184 if (pdi
.raw_name
== NULL
)
19185 complaint (_("malformed enumerator DIE ignored"));
19186 else if (building_psymtab
)
19187 add_partial_symbol (&pdi
, cu
);
19189 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19193 struct partial_die_info
*part_die
19194 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19196 /* We'll save this DIE so link it in. */
19197 part_die
->die_parent
= parent_die
;
19198 part_die
->die_sibling
= NULL
;
19199 part_die
->die_child
= NULL
;
19201 if (last_die
&& last_die
== parent_die
)
19202 last_die
->die_child
= part_die
;
19204 last_die
->die_sibling
= part_die
;
19206 last_die
= part_die
;
19208 if (first_die
== NULL
)
19209 first_die
= part_die
;
19211 /* Maybe add the DIE to the hash table. Not all DIEs that we
19212 find interesting need to be in the hash table, because we
19213 also have the parent/sibling/child chains; only those that we
19214 might refer to by offset later during partial symbol reading.
19216 For now this means things that might have be the target of a
19217 DW_AT_specification, DW_AT_abstract_origin, or
19218 DW_AT_extension. DW_AT_extension will refer only to
19219 namespaces; DW_AT_abstract_origin refers to functions (and
19220 many things under the function DIE, but we do not recurse
19221 into function DIEs during partial symbol reading) and
19222 possibly variables as well; DW_AT_specification refers to
19223 declarations. Declarations ought to have the DW_AT_declaration
19224 flag. It happens that GCC forgets to put it in sometimes, but
19225 only for functions, not for types.
19227 Adding more things than necessary to the hash table is harmless
19228 except for the performance cost. Adding too few will result in
19229 wasted time in find_partial_die, when we reread the compilation
19230 unit with load_all_dies set. */
19233 || abbrev
->tag
== DW_TAG_constant
19234 || abbrev
->tag
== DW_TAG_subprogram
19235 || abbrev
->tag
== DW_TAG_variable
19236 || abbrev
->tag
== DW_TAG_namespace
19237 || part_die
->is_declaration
)
19241 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19242 to_underlying (part_die
->sect_off
),
19247 /* For some DIEs we want to follow their children (if any). For C
19248 we have no reason to follow the children of structures; for other
19249 languages we have to, so that we can get at method physnames
19250 to infer fully qualified class names, for DW_AT_specification,
19251 and for C++ template arguments. For C++, we also look one level
19252 inside functions to find template arguments (if the name of the
19253 function does not already contain the template arguments).
19255 For Ada and Fortran, we need to scan the children of subprograms
19256 and lexical blocks as well because these languages allow the
19257 definition of nested entities that could be interesting for the
19258 debugger, such as nested subprograms for instance. */
19259 if (last_die
->has_children
19261 || last_die
->tag
== DW_TAG_namespace
19262 || last_die
->tag
== DW_TAG_module
19263 || last_die
->tag
== DW_TAG_enumeration_type
19264 || (cu
->per_cu
->lang
== language_cplus
19265 && last_die
->tag
== DW_TAG_subprogram
19266 && (last_die
->raw_name
== NULL
19267 || strchr (last_die
->raw_name
, '<') == NULL
))
19268 || (cu
->per_cu
->lang
!= language_c
19269 && (last_die
->tag
== DW_TAG_class_type
19270 || last_die
->tag
== DW_TAG_interface_type
19271 || last_die
->tag
== DW_TAG_structure_type
19272 || last_die
->tag
== DW_TAG_union_type
))
19273 || ((cu
->per_cu
->lang
== language_ada
19274 || cu
->per_cu
->lang
== language_fortran
)
19275 && (last_die
->tag
== DW_TAG_subprogram
19276 || last_die
->tag
== DW_TAG_lexical_block
))))
19279 parent_die
= last_die
;
19283 /* Otherwise we skip to the next sibling, if any. */
19284 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19286 /* Back to the top, do it again. */
19290 partial_die_info::partial_die_info (sect_offset sect_off_
,
19291 const struct abbrev_info
*abbrev
)
19292 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19296 /* See class definition. */
19299 partial_die_info::name (dwarf2_cu
*cu
)
19301 if (!canonical_name
&& raw_name
!= nullptr)
19303 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19304 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19305 canonical_name
= 1;
19311 /* Read a minimal amount of information into the minimal die structure.
19312 INFO_PTR should point just after the initial uleb128 of a DIE. */
19315 partial_die_info::read (const struct die_reader_specs
*reader
,
19316 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19318 struct dwarf2_cu
*cu
= reader
->cu
;
19319 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19321 int has_low_pc_attr
= 0;
19322 int has_high_pc_attr
= 0;
19323 int high_pc_relative
= 0;
19325 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19328 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19329 /* String and address offsets that need to do the reprocessing have
19330 already been read at this point, so there is no need to wait until
19331 the loop terminates to do the reprocessing. */
19332 if (attr
.requires_reprocessing_p ())
19333 read_attribute_reprocess (reader
, &attr
, tag
);
19334 /* Store the data if it is of an attribute we want to keep in a
19335 partial symbol table. */
19341 case DW_TAG_compile_unit
:
19342 case DW_TAG_partial_unit
:
19343 case DW_TAG_type_unit
:
19344 /* Compilation units have a DW_AT_name that is a filename, not
19345 a source language identifier. */
19346 case DW_TAG_enumeration_type
:
19347 case DW_TAG_enumerator
:
19348 /* These tags always have simple identifiers already; no need
19349 to canonicalize them. */
19350 canonical_name
= 1;
19351 raw_name
= attr
.as_string ();
19354 canonical_name
= 0;
19355 raw_name
= attr
.as_string ();
19359 case DW_AT_linkage_name
:
19360 case DW_AT_MIPS_linkage_name
:
19361 /* Note that both forms of linkage name might appear. We
19362 assume they will be the same, and we only store the last
19364 linkage_name
= attr
.as_string ();
19367 has_low_pc_attr
= 1;
19368 lowpc
= attr
.as_address ();
19370 case DW_AT_high_pc
:
19371 has_high_pc_attr
= 1;
19372 highpc
= attr
.as_address ();
19373 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19374 high_pc_relative
= 1;
19376 case DW_AT_location
:
19377 /* Support the .debug_loc offsets. */
19378 if (attr
.form_is_block ())
19380 d
.locdesc
= attr
.as_block ();
19382 else if (attr
.form_is_section_offset ())
19384 dwarf2_complex_location_expr_complaint ();
19388 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19389 "partial symbol information");
19392 case DW_AT_external
:
19393 is_external
= attr
.as_boolean ();
19395 case DW_AT_declaration
:
19396 is_declaration
= attr
.as_boolean ();
19401 case DW_AT_abstract_origin
:
19402 case DW_AT_specification
:
19403 case DW_AT_extension
:
19404 has_specification
= 1;
19405 spec_offset
= attr
.get_ref_die_offset ();
19406 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19407 || cu
->per_cu
->is_dwz
);
19409 case DW_AT_sibling
:
19410 /* Ignore absolute siblings, they might point outside of
19411 the current compile unit. */
19412 if (attr
.form
== DW_FORM_ref_addr
)
19413 complaint (_("ignoring absolute DW_AT_sibling"));
19416 const gdb_byte
*buffer
= reader
->buffer
;
19417 sect_offset off
= attr
.get_ref_die_offset ();
19418 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19420 if (sibling_ptr
< info_ptr
)
19421 complaint (_("DW_AT_sibling points backwards"));
19422 else if (sibling_ptr
> reader
->buffer_end
)
19423 reader
->die_section
->overflow_complaint ();
19425 sibling
= sibling_ptr
;
19428 case DW_AT_byte_size
:
19431 case DW_AT_const_value
:
19432 has_const_value
= 1;
19434 case DW_AT_calling_convention
:
19435 /* DWARF doesn't provide a way to identify a program's source-level
19436 entry point. DW_AT_calling_convention attributes are only meant
19437 to describe functions' calling conventions.
19439 However, because it's a necessary piece of information in
19440 Fortran, and before DWARF 4 DW_CC_program was the only
19441 piece of debugging information whose definition refers to
19442 a 'main program' at all, several compilers marked Fortran
19443 main programs with DW_CC_program --- even when those
19444 functions use the standard calling conventions.
19446 Although DWARF now specifies a way to provide this
19447 information, we support this practice for backward
19449 if (attr
.constant_value (0) == DW_CC_program
19450 && cu
->per_cu
->lang
== language_fortran
)
19451 main_subprogram
= 1;
19455 LONGEST value
= attr
.constant_value (-1);
19456 if (value
== DW_INL_inlined
19457 || value
== DW_INL_declared_inlined
)
19458 may_be_inlined
= 1;
19463 if (tag
== DW_TAG_imported_unit
)
19465 d
.sect_off
= attr
.get_ref_die_offset ();
19466 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19467 || cu
->per_cu
->is_dwz
);
19471 case DW_AT_main_subprogram
:
19472 main_subprogram
= attr
.as_boolean ();
19477 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19478 on DWARF version). */
19479 ranges_offset
= attr
.as_unsigned ();
19481 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19483 if (tag
!= DW_TAG_compile_unit
)
19484 ranges_offset
+= cu
->gnu_ranges_base
;
19486 has_range_info
= 1;
19495 /* For Ada, if both the name and the linkage name appear, we prefer
19496 the latter. This lets "catch exception" work better, regardless
19497 of the order in which the name and linkage name were emitted.
19498 Really, though, this is just a workaround for the fact that gdb
19499 doesn't store both the name and the linkage name. */
19500 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19501 raw_name
= linkage_name
;
19503 if (high_pc_relative
)
19506 if (has_low_pc_attr
&& has_high_pc_attr
)
19508 /* When using the GNU linker, .gnu.linkonce. sections are used to
19509 eliminate duplicate copies of functions and vtables and such.
19510 The linker will arbitrarily choose one and discard the others.
19511 The AT_*_pc values for such functions refer to local labels in
19512 these sections. If the section from that file was discarded, the
19513 labels are not in the output, so the relocs get a value of 0.
19514 If this is a discarded function, mark the pc bounds as invalid,
19515 so that GDB will ignore it. */
19516 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19518 struct objfile
*objfile
= per_objfile
->objfile
;
19519 struct gdbarch
*gdbarch
= objfile
->arch ();
19521 complaint (_("DW_AT_low_pc %s is zero "
19522 "for DIE at %s [in module %s]"),
19523 paddress (gdbarch
, lowpc
),
19524 sect_offset_str (sect_off
),
19525 objfile_name (objfile
));
19527 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19528 else if (lowpc
>= highpc
)
19530 struct objfile
*objfile
= per_objfile
->objfile
;
19531 struct gdbarch
*gdbarch
= objfile
->arch ();
19533 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19534 "for DIE at %s [in module %s]"),
19535 paddress (gdbarch
, lowpc
),
19536 paddress (gdbarch
, highpc
),
19537 sect_offset_str (sect_off
),
19538 objfile_name (objfile
));
19547 /* Find a cached partial DIE at OFFSET in CU. */
19549 struct partial_die_info
*
19550 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19552 struct partial_die_info
*lookup_die
= NULL
;
19553 struct partial_die_info
part_die (sect_off
);
19555 lookup_die
= ((struct partial_die_info
*)
19556 htab_find_with_hash (partial_dies
, &part_die
,
19557 to_underlying (sect_off
)));
19562 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19563 except in the case of .debug_types DIEs which do not reference
19564 outside their CU (they do however referencing other types via
19565 DW_FORM_ref_sig8). */
19567 static const struct cu_partial_die_info
19568 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19570 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19571 struct objfile
*objfile
= per_objfile
->objfile
;
19572 struct partial_die_info
*pd
= NULL
;
19574 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19575 && cu
->header
.offset_in_cu_p (sect_off
))
19577 pd
= cu
->find_partial_die (sect_off
);
19580 /* We missed recording what we needed.
19581 Load all dies and try again. */
19585 /* TUs don't reference other CUs/TUs (except via type signatures). */
19586 if (cu
->per_cu
->is_debug_types
)
19588 error (_("Dwarf Error: Type Unit at offset %s contains"
19589 " external reference to offset %s [in module %s].\n"),
19590 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19591 bfd_get_filename (objfile
->obfd
));
19593 dwarf2_per_cu_data
*per_cu
19594 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19595 per_objfile
->per_bfd
);
19597 cu
= per_objfile
->get_cu (per_cu
);
19598 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19599 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19601 cu
= per_objfile
->get_cu (per_cu
);
19604 pd
= cu
->find_partial_die (sect_off
);
19607 /* If we didn't find it, and not all dies have been loaded,
19608 load them all and try again. */
19610 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19612 cu
->load_all_dies
= 1;
19614 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19615 THIS_CU->cu may already be in use. So we can't just free it and
19616 replace its DIEs with the ones we read in. Instead, we leave those
19617 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19618 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19620 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19622 pd
= cu
->find_partial_die (sect_off
);
19626 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19627 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19631 /* See if we can figure out if the class lives in a namespace. We do
19632 this by looking for a member function; its demangled name will
19633 contain namespace info, if there is any. */
19636 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19637 struct dwarf2_cu
*cu
)
19639 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19640 what template types look like, because the demangler
19641 frequently doesn't give the same name as the debug info. We
19642 could fix this by only using the demangled name to get the
19643 prefix (but see comment in read_structure_type). */
19645 struct partial_die_info
*real_pdi
;
19646 struct partial_die_info
*child_pdi
;
19648 /* If this DIE (this DIE's specification, if any) has a parent, then
19649 we should not do this. We'll prepend the parent's fully qualified
19650 name when we create the partial symbol. */
19652 real_pdi
= struct_pdi
;
19653 while (real_pdi
->has_specification
)
19655 auto res
= find_partial_die (real_pdi
->spec_offset
,
19656 real_pdi
->spec_is_dwz
, cu
);
19657 real_pdi
= res
.pdi
;
19661 if (real_pdi
->die_parent
!= NULL
)
19664 for (child_pdi
= struct_pdi
->die_child
;
19666 child_pdi
= child_pdi
->die_sibling
)
19668 if (child_pdi
->tag
== DW_TAG_subprogram
19669 && child_pdi
->linkage_name
!= NULL
)
19671 gdb::unique_xmalloc_ptr
<char> actual_class_name
19672 (cu
->language_defn
->class_name_from_physname
19673 (child_pdi
->linkage_name
));
19674 if (actual_class_name
!= NULL
)
19676 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19677 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19678 struct_pdi
->canonical_name
= 1;
19685 /* Return true if a DIE with TAG may have the DW_AT_const_value
19689 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19693 case DW_TAG_constant
:
19694 case DW_TAG_enumerator
:
19695 case DW_TAG_formal_parameter
:
19696 case DW_TAG_template_value_param
:
19697 case DW_TAG_variable
:
19705 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19707 /* Once we've fixed up a die, there's no point in doing so again.
19708 This also avoids a memory leak if we were to call
19709 guess_partial_die_structure_name multiple times. */
19713 /* If we found a reference attribute and the DIE has no name, try
19714 to find a name in the referred to DIE. */
19716 if (raw_name
== NULL
&& has_specification
)
19718 struct partial_die_info
*spec_die
;
19720 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19721 spec_die
= res
.pdi
;
19724 spec_die
->fixup (cu
);
19726 if (spec_die
->raw_name
)
19728 raw_name
= spec_die
->raw_name
;
19729 canonical_name
= spec_die
->canonical_name
;
19731 /* Copy DW_AT_external attribute if it is set. */
19732 if (spec_die
->is_external
)
19733 is_external
= spec_die
->is_external
;
19737 if (!has_const_value
&& has_specification
19738 && can_have_DW_AT_const_value_p (tag
))
19740 struct partial_die_info
*spec_die
;
19742 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19743 spec_die
= res
.pdi
;
19746 spec_die
->fixup (cu
);
19748 if (spec_die
->has_const_value
)
19750 /* Copy DW_AT_const_value attribute if it is set. */
19751 has_const_value
= spec_die
->has_const_value
;
19755 /* Set default names for some unnamed DIEs. */
19757 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19759 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19760 canonical_name
= 1;
19763 /* If there is no parent die to provide a namespace, and there are
19764 children, see if we can determine the namespace from their linkage
19766 if (cu
->per_cu
->lang
== language_cplus
19767 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19768 && die_parent
== NULL
19770 && (tag
== DW_TAG_class_type
19771 || tag
== DW_TAG_structure_type
19772 || tag
== DW_TAG_union_type
))
19773 guess_partial_die_structure_name (this, cu
);
19775 /* GCC might emit a nameless struct or union that has a linkage
19776 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19777 if (raw_name
== NULL
19778 && (tag
== DW_TAG_class_type
19779 || tag
== DW_TAG_interface_type
19780 || tag
== DW_TAG_structure_type
19781 || tag
== DW_TAG_union_type
)
19782 && linkage_name
!= NULL
)
19784 gdb::unique_xmalloc_ptr
<char> demangled
19785 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19786 if (demangled
!= nullptr)
19790 /* Strip any leading namespaces/classes, keep only the base name.
19791 DW_AT_name for named DIEs does not contain the prefixes. */
19792 base
= strrchr (demangled
.get (), ':');
19793 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19796 base
= demangled
.get ();
19798 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19799 raw_name
= objfile
->intern (base
);
19800 canonical_name
= 1;
19807 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19808 contents from the given SECTION in the HEADER.
19810 HEADER_OFFSET is the offset of the header in the section. */
19812 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19813 struct dwarf2_section_info
*section
,
19814 sect_offset header_offset
)
19816 unsigned int bytes_read
;
19817 bfd
*abfd
= section
->get_bfd_owner ();
19818 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19820 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19821 info_ptr
+= bytes_read
;
19823 header
->version
= read_2_bytes (abfd
, info_ptr
);
19826 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19829 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19832 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19835 /* Return the DW_AT_loclists_base value for the CU. */
19837 lookup_loclist_base (struct dwarf2_cu
*cu
)
19839 /* For the .dwo unit, the loclist_base points to the first offset following
19840 the header. The header consists of the following entities-
19841 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19843 2. version (2 bytes)
19844 3. address size (1 byte)
19845 4. segment selector size (1 byte)
19846 5. offset entry count (4 bytes)
19847 These sizes are derived as per the DWARFv5 standard. */
19848 if (cu
->dwo_unit
!= nullptr)
19850 if (cu
->header
.initial_length_size
== 4)
19851 return LOCLIST_HEADER_SIZE32
;
19852 return LOCLIST_HEADER_SIZE64
;
19854 return cu
->loclist_base
;
19857 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19858 array of offsets in the .debug_loclists section. */
19861 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19863 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19864 struct objfile
*objfile
= per_objfile
->objfile
;
19865 bfd
*abfd
= objfile
->obfd
;
19866 ULONGEST loclist_header_size
=
19867 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19868 : LOCLIST_HEADER_SIZE64
);
19869 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19871 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19872 ULONGEST start_offset
=
19873 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19875 /* Get loclists section. */
19876 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19878 /* Read the loclists section content. */
19879 section
->read (objfile
);
19880 if (section
->buffer
== NULL
)
19881 error (_("DW_FORM_loclistx used without .debug_loclists "
19882 "section [in module %s]"), objfile_name (objfile
));
19884 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19885 so if loclist_base is smaller than the header size, we have a problem. */
19886 if (loclist_base
< loclist_header_size
)
19887 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19888 objfile_name (objfile
));
19890 /* Read the header of the loclists contribution. */
19891 struct loclists_rnglists_header header
;
19892 read_loclists_rnglists_header (&header
, section
,
19893 (sect_offset
) (loclist_base
- loclist_header_size
));
19895 /* Verify the loclist index is valid. */
19896 if (loclist_index
>= header
.offset_entry_count
)
19897 error (_("DW_FORM_loclistx pointing outside of "
19898 ".debug_loclists offset array [in module %s]"),
19899 objfile_name (objfile
));
19901 /* Validate that reading won't go beyond the end of the section. */
19902 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19903 error (_("Reading DW_FORM_loclistx index beyond end of"
19904 ".debug_loclists section [in module %s]"),
19905 objfile_name (objfile
));
19907 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19909 if (cu
->header
.offset_size
== 4)
19910 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19912 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19915 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19916 array of offsets in the .debug_rnglists section. */
19919 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19922 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19923 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19924 bfd
*abfd
= objfile
->obfd
;
19925 ULONGEST rnglist_header_size
=
19926 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19927 : RNGLIST_HEADER_SIZE64
);
19929 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19930 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19932 ULONGEST rnglist_base
=
19933 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19935 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19936 ULONGEST start_offset
=
19937 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19939 /* Get rnglists section. */
19940 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19942 /* Read the rnglists section content. */
19943 section
->read (objfile
);
19944 if (section
->buffer
== nullptr)
19945 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19947 objfile_name (objfile
));
19949 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19950 so if rnglist_base is smaller than the header size, we have a problem. */
19951 if (rnglist_base
< rnglist_header_size
)
19952 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19953 objfile_name (objfile
));
19955 /* Read the header of the rnglists contribution. */
19956 struct loclists_rnglists_header header
;
19957 read_loclists_rnglists_header (&header
, section
,
19958 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19960 /* Verify the rnglist index is valid. */
19961 if (rnglist_index
>= header
.offset_entry_count
)
19962 error (_("DW_FORM_rnglistx index pointing outside of "
19963 ".debug_rnglists offset array [in module %s]"),
19964 objfile_name (objfile
));
19966 /* Validate that reading won't go beyond the end of the section. */
19967 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19968 error (_("Reading DW_FORM_rnglistx index beyond end of"
19969 ".debug_rnglists section [in module %s]"),
19970 objfile_name (objfile
));
19972 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19974 if (cu
->header
.offset_size
== 4)
19975 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19977 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19980 /* Process the attributes that had to be skipped in the first round. These
19981 attributes are the ones that need str_offsets_base or addr_base attributes.
19982 They could not have been processed in the first round, because at the time
19983 the values of str_offsets_base or addr_base may not have been known. */
19985 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19986 struct attribute
*attr
, dwarf_tag tag
)
19988 struct dwarf2_cu
*cu
= reader
->cu
;
19989 switch (attr
->form
)
19991 case DW_FORM_addrx
:
19992 case DW_FORM_GNU_addr_index
:
19993 attr
->set_address (read_addr_index (cu
,
19994 attr
->as_unsigned_reprocess ()));
19996 case DW_FORM_loclistx
:
19998 sect_offset loclists_sect_off
19999 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20001 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20004 case DW_FORM_rnglistx
:
20006 sect_offset rnglists_sect_off
20007 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20009 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20013 case DW_FORM_strx1
:
20014 case DW_FORM_strx2
:
20015 case DW_FORM_strx3
:
20016 case DW_FORM_strx4
:
20017 case DW_FORM_GNU_str_index
:
20019 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20020 gdb_assert (!attr
->canonical_string_p ());
20021 if (reader
->dwo_file
!= NULL
)
20022 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20025 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20030 gdb_assert_not_reached ("Unexpected DWARF form.");
20034 /* Read an attribute value described by an attribute form. */
20036 static const gdb_byte
*
20037 read_attribute_value (const struct die_reader_specs
*reader
,
20038 struct attribute
*attr
, unsigned form
,
20039 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20041 struct dwarf2_cu
*cu
= reader
->cu
;
20042 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20043 struct objfile
*objfile
= per_objfile
->objfile
;
20044 bfd
*abfd
= reader
->abfd
;
20045 struct comp_unit_head
*cu_header
= &cu
->header
;
20046 unsigned int bytes_read
;
20047 struct dwarf_block
*blk
;
20049 attr
->form
= (enum dwarf_form
) form
;
20052 case DW_FORM_ref_addr
:
20053 if (cu_header
->version
== 2)
20054 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20057 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20059 info_ptr
+= bytes_read
;
20061 case DW_FORM_GNU_ref_alt
:
20062 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20064 info_ptr
+= bytes_read
;
20068 struct gdbarch
*gdbarch
= objfile
->arch ();
20069 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20070 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20071 attr
->set_address (addr
);
20072 info_ptr
+= bytes_read
;
20075 case DW_FORM_block2
:
20076 blk
= dwarf_alloc_block (cu
);
20077 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20079 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20080 info_ptr
+= blk
->size
;
20081 attr
->set_block (blk
);
20083 case DW_FORM_block4
:
20084 blk
= dwarf_alloc_block (cu
);
20085 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20087 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20088 info_ptr
+= blk
->size
;
20089 attr
->set_block (blk
);
20091 case DW_FORM_data2
:
20092 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20095 case DW_FORM_data4
:
20096 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20099 case DW_FORM_data8
:
20100 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20103 case DW_FORM_data16
:
20104 blk
= dwarf_alloc_block (cu
);
20106 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20108 attr
->set_block (blk
);
20110 case DW_FORM_sec_offset
:
20111 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20113 info_ptr
+= bytes_read
;
20115 case DW_FORM_loclistx
:
20117 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20119 info_ptr
+= bytes_read
;
20122 case DW_FORM_string
:
20123 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20125 info_ptr
+= bytes_read
;
20128 if (!cu
->per_cu
->is_dwz
)
20130 attr
->set_string_noncanonical
20131 (read_indirect_string (per_objfile
,
20132 abfd
, info_ptr
, cu_header
,
20134 info_ptr
+= bytes_read
;
20138 case DW_FORM_line_strp
:
20139 if (!cu
->per_cu
->is_dwz
)
20141 attr
->set_string_noncanonical
20142 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20144 info_ptr
+= bytes_read
;
20148 case DW_FORM_GNU_strp_alt
:
20150 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20151 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20154 attr
->set_string_noncanonical
20155 (dwz
->read_string (objfile
, str_offset
));
20156 info_ptr
+= bytes_read
;
20159 case DW_FORM_exprloc
:
20160 case DW_FORM_block
:
20161 blk
= dwarf_alloc_block (cu
);
20162 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20163 info_ptr
+= bytes_read
;
20164 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20165 info_ptr
+= blk
->size
;
20166 attr
->set_block (blk
);
20168 case DW_FORM_block1
:
20169 blk
= dwarf_alloc_block (cu
);
20170 blk
->size
= read_1_byte (abfd
, info_ptr
);
20172 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20173 info_ptr
+= blk
->size
;
20174 attr
->set_block (blk
);
20176 case DW_FORM_data1
:
20178 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20181 case DW_FORM_flag_present
:
20182 attr
->set_unsigned (1);
20184 case DW_FORM_sdata
:
20185 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20186 info_ptr
+= bytes_read
;
20188 case DW_FORM_rnglistx
:
20190 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20192 info_ptr
+= bytes_read
;
20195 case DW_FORM_udata
:
20196 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20197 info_ptr
+= bytes_read
;
20200 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20201 + read_1_byte (abfd
, info_ptr
)));
20205 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20206 + read_2_bytes (abfd
, info_ptr
)));
20210 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20211 + read_4_bytes (abfd
, info_ptr
)));
20215 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20216 + read_8_bytes (abfd
, info_ptr
)));
20219 case DW_FORM_ref_sig8
:
20220 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20223 case DW_FORM_ref_udata
:
20224 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20225 + read_unsigned_leb128 (abfd
, info_ptr
,
20227 info_ptr
+= bytes_read
;
20229 case DW_FORM_indirect
:
20230 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20231 info_ptr
+= bytes_read
;
20232 if (form
== DW_FORM_implicit_const
)
20234 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20235 info_ptr
+= bytes_read
;
20237 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20240 case DW_FORM_implicit_const
:
20241 attr
->set_signed (implicit_const
);
20243 case DW_FORM_addrx
:
20244 case DW_FORM_GNU_addr_index
:
20245 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20247 info_ptr
+= bytes_read
;
20250 case DW_FORM_strx1
:
20251 case DW_FORM_strx2
:
20252 case DW_FORM_strx3
:
20253 case DW_FORM_strx4
:
20254 case DW_FORM_GNU_str_index
:
20256 ULONGEST str_index
;
20257 if (form
== DW_FORM_strx1
)
20259 str_index
= read_1_byte (abfd
, info_ptr
);
20262 else if (form
== DW_FORM_strx2
)
20264 str_index
= read_2_bytes (abfd
, info_ptr
);
20267 else if (form
== DW_FORM_strx3
)
20269 str_index
= read_3_bytes (abfd
, info_ptr
);
20272 else if (form
== DW_FORM_strx4
)
20274 str_index
= read_4_bytes (abfd
, info_ptr
);
20279 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20280 info_ptr
+= bytes_read
;
20282 attr
->set_unsigned_reprocess (str_index
);
20286 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20287 dwarf_form_name (form
),
20288 bfd_get_filename (abfd
));
20292 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20293 attr
->form
= DW_FORM_GNU_ref_alt
;
20295 /* We have seen instances where the compiler tried to emit a byte
20296 size attribute of -1 which ended up being encoded as an unsigned
20297 0xffffffff. Although 0xffffffff is technically a valid size value,
20298 an object of this size seems pretty unlikely so we can relatively
20299 safely treat these cases as if the size attribute was invalid and
20300 treat them as zero by default. */
20301 if (attr
->name
== DW_AT_byte_size
20302 && form
== DW_FORM_data4
20303 && attr
->as_unsigned () >= 0xffffffff)
20306 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20307 hex_string (attr
->as_unsigned ()));
20308 attr
->set_unsigned (0);
20314 /* Read an attribute described by an abbreviated attribute. */
20316 static const gdb_byte
*
20317 read_attribute (const struct die_reader_specs
*reader
,
20318 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20319 const gdb_byte
*info_ptr
)
20321 attr
->name
= abbrev
->name
;
20322 attr
->string_is_canonical
= 0;
20323 attr
->requires_reprocessing
= 0;
20324 return read_attribute_value (reader
, attr
, abbrev
->form
,
20325 abbrev
->implicit_const
, info_ptr
);
20328 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20330 static const char *
20331 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20332 LONGEST str_offset
)
20334 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20335 str_offset
, "DW_FORM_strp");
20338 /* Return pointer to string at .debug_str offset as read from BUF.
20339 BUF is assumed to be in a compilation unit described by CU_HEADER.
20340 Return *BYTES_READ_PTR count of bytes read from BUF. */
20342 static const char *
20343 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20344 const gdb_byte
*buf
,
20345 const struct comp_unit_head
*cu_header
,
20346 unsigned int *bytes_read_ptr
)
20348 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20350 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20356 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20357 unsigned int offset_size
)
20359 bfd
*abfd
= objfile
->obfd
;
20360 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
20362 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20368 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20369 const struct comp_unit_head
*cu_header
,
20370 unsigned int *bytes_read_ptr
)
20372 bfd
*abfd
= objfile
->obfd
;
20373 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20375 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20378 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20379 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20380 ADDR_SIZE is the size of addresses from the CU header. */
20383 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20384 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20386 struct objfile
*objfile
= per_objfile
->objfile
;
20387 bfd
*abfd
= objfile
->obfd
;
20388 const gdb_byte
*info_ptr
;
20389 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20391 per_objfile
->per_bfd
->addr
.read (objfile
);
20392 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20393 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20394 objfile_name (objfile
));
20395 if (addr_base_or_zero
+ addr_index
* addr_size
20396 >= per_objfile
->per_bfd
->addr
.size
)
20397 error (_("DW_FORM_addr_index pointing outside of "
20398 ".debug_addr section [in module %s]"),
20399 objfile_name (objfile
));
20400 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20401 + addr_index
* addr_size
);
20402 if (addr_size
== 4)
20403 return bfd_get_32 (abfd
, info_ptr
);
20405 return bfd_get_64 (abfd
, info_ptr
);
20408 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20411 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20413 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20414 cu
->addr_base
, cu
->header
.addr_size
);
20417 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20420 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20421 unsigned int *bytes_read
)
20423 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20424 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20426 return read_addr_index (cu
, addr_index
);
20432 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20433 dwarf2_per_objfile
*per_objfile
,
20434 unsigned int addr_index
)
20436 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20437 gdb::optional
<ULONGEST
> addr_base
;
20440 /* We need addr_base and addr_size.
20441 If we don't have PER_CU->cu, we have to get it.
20442 Nasty, but the alternative is storing the needed info in PER_CU,
20443 which at this point doesn't seem justified: it's not clear how frequently
20444 it would get used and it would increase the size of every PER_CU.
20445 Entry points like dwarf2_per_cu_addr_size do a similar thing
20446 so we're not in uncharted territory here.
20447 Alas we need to be a bit more complicated as addr_base is contained
20450 We don't need to read the entire CU(/TU).
20451 We just need the header and top level die.
20453 IWBN to use the aging mechanism to let us lazily later discard the CU.
20454 For now we skip this optimization. */
20458 addr_base
= cu
->addr_base
;
20459 addr_size
= cu
->header
.addr_size
;
20463 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20464 addr_base
= reader
.cu
->addr_base
;
20465 addr_size
= reader
.cu
->header
.addr_size
;
20468 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20471 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20472 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20475 static const char *
20476 read_str_index (struct dwarf2_cu
*cu
,
20477 struct dwarf2_section_info
*str_section
,
20478 struct dwarf2_section_info
*str_offsets_section
,
20479 ULONGEST str_offsets_base
, ULONGEST str_index
)
20481 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20482 struct objfile
*objfile
= per_objfile
->objfile
;
20483 const char *objf_name
= objfile_name (objfile
);
20484 bfd
*abfd
= objfile
->obfd
;
20485 const gdb_byte
*info_ptr
;
20486 ULONGEST str_offset
;
20487 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20489 str_section
->read (objfile
);
20490 str_offsets_section
->read (objfile
);
20491 if (str_section
->buffer
== NULL
)
20492 error (_("%s used without %s section"
20493 " in CU at offset %s [in module %s]"),
20494 form_name
, str_section
->get_name (),
20495 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20496 if (str_offsets_section
->buffer
== NULL
)
20497 error (_("%s used without %s section"
20498 " in CU at offset %s [in module %s]"),
20499 form_name
, str_section
->get_name (),
20500 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20501 info_ptr
= (str_offsets_section
->buffer
20503 + str_index
* cu
->header
.offset_size
);
20504 if (cu
->header
.offset_size
== 4)
20505 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20507 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20508 if (str_offset
>= str_section
->size
)
20509 error (_("Offset from %s pointing outside of"
20510 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20511 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20512 return (const char *) (str_section
->buffer
+ str_offset
);
20515 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20517 static const char *
20518 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20520 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20521 ? reader
->cu
->header
.addr_size
: 0;
20522 return read_str_index (reader
->cu
,
20523 &reader
->dwo_file
->sections
.str
,
20524 &reader
->dwo_file
->sections
.str_offsets
,
20525 str_offsets_base
, str_index
);
20528 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20530 static const char *
20531 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20533 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20534 const char *objf_name
= objfile_name (objfile
);
20535 static const char form_name
[] = "DW_FORM_GNU_str_index";
20536 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20538 if (!cu
->str_offsets_base
.has_value ())
20539 error (_("%s used in Fission stub without %s"
20540 " in CU at offset 0x%lx [in module %s]"),
20541 form_name
, str_offsets_attr_name
,
20542 (long) cu
->header
.offset_size
, objf_name
);
20544 return read_str_index (cu
,
20545 &cu
->per_objfile
->per_bfd
->str
,
20546 &cu
->per_objfile
->per_bfd
->str_offsets
,
20547 *cu
->str_offsets_base
, str_index
);
20550 /* Return the length of an LEB128 number in BUF. */
20553 leb128_size (const gdb_byte
*buf
)
20555 const gdb_byte
*begin
= buf
;
20561 if ((byte
& 128) == 0)
20562 return buf
- begin
;
20566 static enum language
20567 dwarf_lang_to_enum_language (unsigned int lang
)
20569 enum language language
;
20578 language
= language_c
;
20581 case DW_LANG_C_plus_plus
:
20582 case DW_LANG_C_plus_plus_11
:
20583 case DW_LANG_C_plus_plus_14
:
20584 language
= language_cplus
;
20587 language
= language_d
;
20589 case DW_LANG_Fortran77
:
20590 case DW_LANG_Fortran90
:
20591 case DW_LANG_Fortran95
:
20592 case DW_LANG_Fortran03
:
20593 case DW_LANG_Fortran08
:
20594 language
= language_fortran
;
20597 language
= language_go
;
20599 case DW_LANG_Mips_Assembler
:
20600 language
= language_asm
;
20602 case DW_LANG_Ada83
:
20603 case DW_LANG_Ada95
:
20604 language
= language_ada
;
20606 case DW_LANG_Modula2
:
20607 language
= language_m2
;
20609 case DW_LANG_Pascal83
:
20610 language
= language_pascal
;
20613 language
= language_objc
;
20616 case DW_LANG_Rust_old
:
20617 language
= language_rust
;
20619 case DW_LANG_OpenCL
:
20620 language
= language_opencl
;
20622 case DW_LANG_Cobol74
:
20623 case DW_LANG_Cobol85
:
20625 language
= language_minimal
;
20632 /* Return the named attribute or NULL if not there. */
20634 static struct attribute
*
20635 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20640 struct attribute
*spec
= NULL
;
20642 for (i
= 0; i
< die
->num_attrs
; ++i
)
20644 if (die
->attrs
[i
].name
== name
)
20645 return &die
->attrs
[i
];
20646 if (die
->attrs
[i
].name
== DW_AT_specification
20647 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20648 spec
= &die
->attrs
[i
];
20654 die
= follow_die_ref (die
, spec
, &cu
);
20660 /* Return the string associated with a string-typed attribute, or NULL if it
20661 is either not found or is of an incorrect type. */
20663 static const char *
20664 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20666 struct attribute
*attr
;
20667 const char *str
= NULL
;
20669 attr
= dwarf2_attr (die
, name
, cu
);
20673 str
= attr
->as_string ();
20674 if (str
== nullptr)
20675 complaint (_("string type expected for attribute %s for "
20676 "DIE at %s in module %s"),
20677 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20678 objfile_name (cu
->per_objfile
->objfile
));
20684 /* Return the dwo name or NULL if not present. If present, it is in either
20685 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20686 static const char *
20687 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20689 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20690 if (dwo_name
== nullptr)
20691 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20695 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20696 and holds a non-zero value. This function should only be used for
20697 DW_FORM_flag or DW_FORM_flag_present attributes. */
20700 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20702 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20704 return attr
!= nullptr && attr
->as_boolean ();
20708 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20710 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20711 which value is non-zero. However, we have to be careful with
20712 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20713 (via dwarf2_flag_true_p) follows this attribute. So we may
20714 end up accidently finding a declaration attribute that belongs
20715 to a different DIE referenced by the specification attribute,
20716 even though the given DIE does not have a declaration attribute. */
20717 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20718 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20721 /* Return the die giving the specification for DIE, if there is
20722 one. *SPEC_CU is the CU containing DIE on input, and the CU
20723 containing the return value on output. If there is no
20724 specification, but there is an abstract origin, that is
20727 static struct die_info
*
20728 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20730 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20733 if (spec_attr
== NULL
)
20734 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20736 if (spec_attr
== NULL
)
20739 return follow_die_ref (die
, spec_attr
, spec_cu
);
20742 /* A convenience function to find the proper .debug_line section for a CU. */
20744 static struct dwarf2_section_info
*
20745 get_debug_line_section (struct dwarf2_cu
*cu
)
20747 struct dwarf2_section_info
*section
;
20748 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20750 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20752 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20753 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20754 else if (cu
->per_cu
->is_dwz
)
20756 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20758 section
= &dwz
->line
;
20761 section
= &per_objfile
->per_bfd
->line
;
20766 /* Read the statement program header starting at OFFSET in
20767 .debug_line, or .debug_line.dwo. Return a pointer
20768 to a struct line_header, allocated using xmalloc.
20769 Returns NULL if there is a problem reading the header, e.g., if it
20770 has a version we don't understand.
20772 NOTE: the strings in the include directory and file name tables of
20773 the returned object point into the dwarf line section buffer,
20774 and must not be freed. */
20776 static line_header_up
20777 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20779 struct dwarf2_section_info
*section
;
20780 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20782 section
= get_debug_line_section (cu
);
20783 section
->read (per_objfile
->objfile
);
20784 if (section
->buffer
== NULL
)
20786 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20787 complaint (_("missing .debug_line.dwo section"));
20789 complaint (_("missing .debug_line section"));
20793 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20794 per_objfile
, section
, &cu
->header
);
20797 /* Subroutine of dwarf_decode_lines to simplify it.
20798 Return the file name for the given file_entry.
20799 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
20800 If space for the result is malloc'd, *NAME_HOLDER will be set.
20801 Returns NULL if FILE_INDEX should be ignored, i.e., it is
20802 equivalent to CU_INFO. */
20804 static const char *
20805 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20806 const file_and_directory
&cu_info
,
20807 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20809 const char *include_name
= fe
.name
;
20810 const char *include_name_to_compare
= include_name
;
20812 const char *dir_name
= fe
.include_dir (lh
);
20814 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20815 if (!IS_ABSOLUTE_PATH (include_name
)
20816 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
20818 /* Avoid creating a duplicate name for CU_INFO.
20819 We do this by comparing INCLUDE_NAME and CU_INFO.
20820 Before we do the comparison, however, we need to account
20821 for DIR_NAME and COMP_DIR.
20822 First prepend dir_name (if non-NULL). If we still don't
20823 have an absolute path prepend comp_dir (if non-NULL).
20824 However, the directory we record in the include-file's
20825 psymtab does not contain COMP_DIR (to match the
20826 corresponding symtab(s)).
20831 bash$ gcc -g ./hello.c
20832 include_name = "hello.c"
20834 DW_AT_comp_dir = comp_dir = "/tmp"
20835 DW_AT_name = "./hello.c"
20839 if (dir_name
!= NULL
)
20841 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20842 include_name
, (char *) NULL
));
20843 include_name
= name_holder
->get ();
20844 include_name_to_compare
= include_name
;
20846 if (!IS_ABSOLUTE_PATH (include_name
)
20847 && cu_info
.get_comp_dir () != nullptr)
20849 hold_compare
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20850 include_name
, (char *) NULL
));
20851 include_name_to_compare
= hold_compare
.get ();
20855 gdb::unique_xmalloc_ptr
<char> copied_name
;
20856 const char *cu_filename
= cu_info
.get_name ();
20857 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
20859 copied_name
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20860 cu_filename
, (char *) NULL
));
20861 cu_filename
= copied_name
.get ();
20864 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
20866 return include_name
;
20869 /* State machine to track the state of the line number program. */
20871 class lnp_state_machine
20874 /* Initialize a machine state for the start of a line number
20876 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20877 bool record_lines_p
);
20879 file_entry
*current_file ()
20881 /* lh->file_names is 0-based, but the file name numbers in the
20882 statement program are 1-based. */
20883 return m_line_header
->file_name_at (m_file
);
20886 /* Record the line in the state machine. END_SEQUENCE is true if
20887 we're processing the end of a sequence. */
20888 void record_line (bool end_sequence
);
20890 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20891 nop-out rest of the lines in this sequence. */
20892 void check_line_address (struct dwarf2_cu
*cu
,
20893 const gdb_byte
*line_ptr
,
20894 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20896 void handle_set_discriminator (unsigned int discriminator
)
20898 m_discriminator
= discriminator
;
20899 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20902 /* Handle DW_LNE_set_address. */
20903 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20906 address
+= baseaddr
;
20907 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20910 /* Handle DW_LNS_advance_pc. */
20911 void handle_advance_pc (CORE_ADDR adjust
);
20913 /* Handle a special opcode. */
20914 void handle_special_opcode (unsigned char op_code
);
20916 /* Handle DW_LNS_advance_line. */
20917 void handle_advance_line (int line_delta
)
20919 advance_line (line_delta
);
20922 /* Handle DW_LNS_set_file. */
20923 void handle_set_file (file_name_index file
);
20925 /* Handle DW_LNS_negate_stmt. */
20926 void handle_negate_stmt ()
20928 m_is_stmt
= !m_is_stmt
;
20931 /* Handle DW_LNS_const_add_pc. */
20932 void handle_const_add_pc ();
20934 /* Handle DW_LNS_fixed_advance_pc. */
20935 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20937 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20941 /* Handle DW_LNS_copy. */
20942 void handle_copy ()
20944 record_line (false);
20945 m_discriminator
= 0;
20948 /* Handle DW_LNE_end_sequence. */
20949 void handle_end_sequence ()
20951 m_currently_recording_lines
= true;
20955 /* Advance the line by LINE_DELTA. */
20956 void advance_line (int line_delta
)
20958 m_line
+= line_delta
;
20960 if (line_delta
!= 0)
20961 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20964 struct dwarf2_cu
*m_cu
;
20966 gdbarch
*m_gdbarch
;
20968 /* True if we're recording lines.
20969 Otherwise we're building partial symtabs and are just interested in
20970 finding include files mentioned by the line number program. */
20971 bool m_record_lines_p
;
20973 /* The line number header. */
20974 line_header
*m_line_header
;
20976 /* These are part of the standard DWARF line number state machine,
20977 and initialized according to the DWARF spec. */
20979 unsigned char m_op_index
= 0;
20980 /* The line table index of the current file. */
20981 file_name_index m_file
= 1;
20982 unsigned int m_line
= 1;
20984 /* These are initialized in the constructor. */
20986 CORE_ADDR m_address
;
20988 unsigned int m_discriminator
;
20990 /* Additional bits of state we need to track. */
20992 /* The last file that we called dwarf2_start_subfile for.
20993 This is only used for TLLs. */
20994 unsigned int m_last_file
= 0;
20995 /* The last file a line number was recorded for. */
20996 struct subfile
*m_last_subfile
= NULL
;
20998 /* The address of the last line entry. */
20999 CORE_ADDR m_last_address
;
21001 /* Set to true when a previous line at the same address (using
21002 m_last_address) had m_is_stmt true. This is reset to false when a
21003 line entry at a new address (m_address different to m_last_address) is
21005 bool m_stmt_at_address
= false;
21007 /* When true, record the lines we decode. */
21008 bool m_currently_recording_lines
= false;
21010 /* The last line number that was recorded, used to coalesce
21011 consecutive entries for the same line. This can happen, for
21012 example, when discriminators are present. PR 17276. */
21013 unsigned int m_last_line
= 0;
21014 bool m_line_has_non_zero_discriminator
= false;
21018 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21020 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21021 / m_line_header
->maximum_ops_per_instruction
)
21022 * m_line_header
->minimum_instruction_length
);
21023 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21024 m_op_index
= ((m_op_index
+ adjust
)
21025 % m_line_header
->maximum_ops_per_instruction
);
21029 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21031 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21032 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21033 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21034 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21035 / m_line_header
->maximum_ops_per_instruction
)
21036 * m_line_header
->minimum_instruction_length
);
21037 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21038 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21039 % m_line_header
->maximum_ops_per_instruction
);
21041 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21042 advance_line (line_delta
);
21043 record_line (false);
21044 m_discriminator
= 0;
21048 lnp_state_machine::handle_set_file (file_name_index file
)
21052 const file_entry
*fe
= current_file ();
21054 dwarf2_debug_line_missing_file_complaint ();
21055 else if (m_record_lines_p
)
21057 const char *dir
= fe
->include_dir (m_line_header
);
21059 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21060 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21061 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21066 lnp_state_machine::handle_const_add_pc ()
21069 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21072 = (((m_op_index
+ adjust
)
21073 / m_line_header
->maximum_ops_per_instruction
)
21074 * m_line_header
->minimum_instruction_length
);
21076 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21077 m_op_index
= ((m_op_index
+ adjust
)
21078 % m_line_header
->maximum_ops_per_instruction
);
21081 /* Return non-zero if we should add LINE to the line number table.
21082 LINE is the line to add, LAST_LINE is the last line that was added,
21083 LAST_SUBFILE is the subfile for LAST_LINE.
21084 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21085 had a non-zero discriminator.
21087 We have to be careful in the presence of discriminators.
21088 E.g., for this line:
21090 for (i = 0; i < 100000; i++);
21092 clang can emit four line number entries for that one line,
21093 each with a different discriminator.
21094 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21096 However, we want gdb to coalesce all four entries into one.
21097 Otherwise the user could stepi into the middle of the line and
21098 gdb would get confused about whether the pc really was in the
21099 middle of the line.
21101 Things are further complicated by the fact that two consecutive
21102 line number entries for the same line is a heuristic used by gcc
21103 to denote the end of the prologue. So we can't just discard duplicate
21104 entries, we have to be selective about it. The heuristic we use is
21105 that we only collapse consecutive entries for the same line if at least
21106 one of those entries has a non-zero discriminator. PR 17276.
21108 Note: Addresses in the line number state machine can never go backwards
21109 within one sequence, thus this coalescing is ok. */
21112 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21113 unsigned int line
, unsigned int last_line
,
21114 int line_has_non_zero_discriminator
,
21115 struct subfile
*last_subfile
)
21117 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21119 if (line
!= last_line
)
21121 /* Same line for the same file that we've seen already.
21122 As a last check, for pr 17276, only record the line if the line
21123 has never had a non-zero discriminator. */
21124 if (!line_has_non_zero_discriminator
)
21129 /* Use the CU's builder to record line number LINE beginning at
21130 address ADDRESS in the line table of subfile SUBFILE. */
21133 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21134 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21135 struct dwarf2_cu
*cu
)
21137 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21139 if (dwarf_line_debug
)
21141 gdb_printf (gdb_stdlog
,
21142 "Recording line %u, file %s, address %s\n",
21143 line
, lbasename (subfile
->name
),
21144 paddress (gdbarch
, address
));
21148 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21151 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21152 Mark the end of a set of line number records.
21153 The arguments are the same as for dwarf_record_line_1.
21154 If SUBFILE is NULL the request is ignored. */
21157 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21158 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21160 if (subfile
== NULL
)
21163 if (dwarf_line_debug
)
21165 gdb_printf (gdb_stdlog
,
21166 "Finishing current line, file %s, address %s\n",
21167 lbasename (subfile
->name
),
21168 paddress (gdbarch
, address
));
21171 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21175 lnp_state_machine::record_line (bool end_sequence
)
21177 if (dwarf_line_debug
)
21179 gdb_printf (gdb_stdlog
,
21180 "Processing actual line %u: file %u,"
21181 " address %s, is_stmt %u, discrim %u%s\n",
21183 paddress (m_gdbarch
, m_address
),
21184 m_is_stmt
, m_discriminator
,
21185 (end_sequence
? "\t(end sequence)" : ""));
21188 file_entry
*fe
= current_file ();
21191 dwarf2_debug_line_missing_file_complaint ();
21192 /* For now we ignore lines not starting on an instruction boundary.
21193 But not when processing end_sequence for compatibility with the
21194 previous version of the code. */
21195 else if (m_op_index
== 0 || end_sequence
)
21197 fe
->included_p
= true;
21198 if (m_record_lines_p
)
21200 /* When we switch files we insert an end maker in the first file,
21201 switch to the second file and add a new line entry. The
21202 problem is that the end marker inserted in the first file will
21203 discard any previous line entries at the same address. If the
21204 line entries in the first file are marked as is-stmt, while
21205 the new line in the second file is non-stmt, then this means
21206 the end marker will discard is-stmt lines so we can have a
21207 non-stmt line. This means that there are less addresses at
21208 which the user can insert a breakpoint.
21210 To improve this we track the last address in m_last_address,
21211 and whether we have seen an is-stmt at this address. Then
21212 when switching files, if we have seen a stmt at the current
21213 address, and we are switching to create a non-stmt line, then
21214 discard the new line. */
21216 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21217 bool ignore_this_line
21218 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21219 && !m_is_stmt
&& m_stmt_at_address
)
21220 || (!end_sequence
&& m_line
== 0));
21222 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21224 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21225 m_currently_recording_lines
? m_cu
: nullptr);
21228 if (!end_sequence
&& !ignore_this_line
)
21230 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21232 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21233 m_line_has_non_zero_discriminator
,
21236 buildsym_compunit
*builder
= m_cu
->get_builder ();
21237 dwarf_record_line_1 (m_gdbarch
,
21238 builder
->get_current_subfile (),
21239 m_line
, m_address
, is_stmt
,
21240 m_currently_recording_lines
? m_cu
: nullptr);
21242 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21243 m_last_line
= m_line
;
21248 /* Track whether we have seen any m_is_stmt true at m_address in case we
21249 have multiple line table entries all at m_address. */
21250 if (m_last_address
!= m_address
)
21252 m_stmt_at_address
= false;
21253 m_last_address
= m_address
;
21255 m_stmt_at_address
|= m_is_stmt
;
21258 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21259 line_header
*lh
, bool record_lines_p
)
21263 m_record_lines_p
= record_lines_p
;
21264 m_line_header
= lh
;
21266 m_currently_recording_lines
= true;
21268 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21269 was a line entry for it so that the backend has a chance to adjust it
21270 and also record it in case it needs it. This is currently used by MIPS
21271 code, cf. `mips_adjust_dwarf2_line'. */
21272 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21273 m_is_stmt
= lh
->default_is_stmt
;
21274 m_discriminator
= 0;
21276 m_last_address
= m_address
;
21277 m_stmt_at_address
= false;
21281 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21282 const gdb_byte
*line_ptr
,
21283 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21285 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21286 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21287 located at 0x0. In this case, additionally check that if
21288 ADDRESS < UNRELOCATED_LOWPC. */
21290 if ((address
== 0 && address
< unrelocated_lowpc
)
21291 || address
== (CORE_ADDR
) -1)
21293 /* This line table is for a function which has been
21294 GCd by the linker. Ignore it. PR gdb/12528 */
21296 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21297 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21299 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21300 line_offset
, objfile_name (objfile
));
21301 m_currently_recording_lines
= false;
21302 /* Note: m_currently_recording_lines is left as false until we see
21303 DW_LNE_end_sequence. */
21307 /* Subroutine of dwarf_decode_lines to simplify it.
21308 Process the line number information in LH.
21309 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21310 program in order to set included_p for every referenced header. */
21313 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21314 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21316 const gdb_byte
*line_ptr
, *extended_end
;
21317 const gdb_byte
*line_end
;
21318 unsigned int bytes_read
, extended_len
;
21319 unsigned char op_code
, extended_op
;
21320 CORE_ADDR baseaddr
;
21321 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21322 bfd
*abfd
= objfile
->obfd
;
21323 struct gdbarch
*gdbarch
= objfile
->arch ();
21324 /* True if we're recording line info (as opposed to building partial
21325 symtabs and just interested in finding include files mentioned by
21326 the line number program). */
21327 bool record_lines_p
= !decode_for_pst_p
;
21329 baseaddr
= objfile
->text_section_offset ();
21331 line_ptr
= lh
->statement_program_start
;
21332 line_end
= lh
->statement_program_end
;
21334 /* Read the statement sequences until there's nothing left. */
21335 while (line_ptr
< line_end
)
21337 /* The DWARF line number program state machine. Reset the state
21338 machine at the start of each sequence. */
21339 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21340 bool end_sequence
= false;
21342 if (record_lines_p
)
21344 /* Start a subfile for the current file of the state
21346 const file_entry
*fe
= state_machine
.current_file ();
21349 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21352 /* Decode the table. */
21353 while (line_ptr
< line_end
&& !end_sequence
)
21355 op_code
= read_1_byte (abfd
, line_ptr
);
21358 if (op_code
>= lh
->opcode_base
)
21360 /* Special opcode. */
21361 state_machine
.handle_special_opcode (op_code
);
21363 else switch (op_code
)
21365 case DW_LNS_extended_op
:
21366 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21368 line_ptr
+= bytes_read
;
21369 extended_end
= line_ptr
+ extended_len
;
21370 extended_op
= read_1_byte (abfd
, line_ptr
);
21372 if (DW_LNE_lo_user
<= extended_op
21373 && extended_op
<= DW_LNE_hi_user
)
21375 /* Vendor extension, ignore. */
21376 line_ptr
= extended_end
;
21379 switch (extended_op
)
21381 case DW_LNE_end_sequence
:
21382 state_machine
.handle_end_sequence ();
21383 end_sequence
= true;
21385 case DW_LNE_set_address
:
21388 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21389 line_ptr
+= bytes_read
;
21391 state_machine
.check_line_address (cu
, line_ptr
,
21392 lowpc
- baseaddr
, address
);
21393 state_machine
.handle_set_address (baseaddr
, address
);
21396 case DW_LNE_define_file
:
21398 const char *cur_file
;
21399 unsigned int mod_time
, length
;
21402 cur_file
= read_direct_string (abfd
, line_ptr
,
21404 line_ptr
+= bytes_read
;
21405 dindex
= (dir_index
)
21406 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21407 line_ptr
+= bytes_read
;
21409 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21410 line_ptr
+= bytes_read
;
21412 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21413 line_ptr
+= bytes_read
;
21414 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21417 case DW_LNE_set_discriminator
:
21419 /* The discriminator is not interesting to the
21420 debugger; just ignore it. We still need to
21421 check its value though:
21422 if there are consecutive entries for the same
21423 (non-prologue) line we want to coalesce them.
21426 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21427 line_ptr
+= bytes_read
;
21429 state_machine
.handle_set_discriminator (discr
);
21433 complaint (_("mangled .debug_line section"));
21436 /* Make sure that we parsed the extended op correctly. If e.g.
21437 we expected a different address size than the producer used,
21438 we may have read the wrong number of bytes. */
21439 if (line_ptr
!= extended_end
)
21441 complaint (_("mangled .debug_line section"));
21446 state_machine
.handle_copy ();
21448 case DW_LNS_advance_pc
:
21451 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21452 line_ptr
+= bytes_read
;
21454 state_machine
.handle_advance_pc (adjust
);
21457 case DW_LNS_advance_line
:
21460 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21461 line_ptr
+= bytes_read
;
21463 state_machine
.handle_advance_line (line_delta
);
21466 case DW_LNS_set_file
:
21468 file_name_index file
21469 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21471 line_ptr
+= bytes_read
;
21473 state_machine
.handle_set_file (file
);
21476 case DW_LNS_set_column
:
21477 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21478 line_ptr
+= bytes_read
;
21480 case DW_LNS_negate_stmt
:
21481 state_machine
.handle_negate_stmt ();
21483 case DW_LNS_set_basic_block
:
21485 /* Add to the address register of the state machine the
21486 address increment value corresponding to special opcode
21487 255. I.e., this value is scaled by the minimum
21488 instruction length since special opcode 255 would have
21489 scaled the increment. */
21490 case DW_LNS_const_add_pc
:
21491 state_machine
.handle_const_add_pc ();
21493 case DW_LNS_fixed_advance_pc
:
21495 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21498 state_machine
.handle_fixed_advance_pc (addr_adj
);
21503 /* Unknown standard opcode, ignore it. */
21506 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21508 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21509 line_ptr
+= bytes_read
;
21516 dwarf2_debug_line_missing_end_sequence_complaint ();
21518 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21519 in which case we still finish recording the last line). */
21520 state_machine
.record_line (true);
21524 /* Decode the Line Number Program (LNP) for the given line_header
21525 structure and CU. The actual information extracted and the type
21526 of structures created from the LNP depends on the value of PST.
21528 1. If PST is NULL, then this procedure uses the data from the program
21529 to create all necessary symbol tables, and their linetables.
21531 2. If PST is not NULL, this procedure reads the program to determine
21532 the list of files included by the unit represented by PST, and
21533 builds all the associated partial symbol tables.
21535 FND holds the CU file name and directory, if known.
21536 It is used for relative paths in the line table.
21538 NOTE: It is important that psymtabs have the same file name (via
21539 strcmp) as the corresponding symtab. Since the directory is not
21540 used in the name of the symtab we don't use it in the name of the
21541 psymtabs we create. E.g. expand_line_sal requires this when
21542 finding psymtabs to expand. A good testcase for this is
21545 LOWPC is the lowest address in CU (or 0 if not known).
21547 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21548 for its PC<->lines mapping information. Otherwise only the filename
21549 table is read in. */
21552 dwarf_decode_lines (struct line_header
*lh
, const file_and_directory
&fnd
,
21553 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21554 CORE_ADDR lowpc
, int decode_mapping
)
21556 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21557 const int decode_for_pst_p
= (pst
!= NULL
);
21559 if (decode_mapping
)
21560 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21562 if (decode_for_pst_p
)
21564 /* Now that we're done scanning the Line Header Program, we can
21565 create the psymtab of each included file. */
21566 for (auto &file_entry
: lh
->file_names ())
21567 if (file_entry
.included_p
)
21569 gdb::unique_xmalloc_ptr
<char> name_holder
;
21570 const char *include_name
=
21571 compute_include_file_name (lh
, file_entry
, fnd
, &name_holder
);
21572 if (include_name
!= NULL
)
21573 dwarf2_create_include_psymtab
21574 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21575 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21581 /* Make sure a symtab is created for every file, even files
21582 which contain only variables (i.e. no code with associated
21584 buildsym_compunit
*builder
= cu
->get_builder ();
21585 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21587 for (auto &fe
: lh
->file_names ())
21589 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21590 if (builder
->get_current_subfile ()->symtab
== NULL
)
21592 builder
->get_current_subfile ()->symtab
21593 = allocate_symtab (cust
,
21594 builder
->get_current_subfile ()->name
);
21596 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21601 /* Start a subfile for DWARF. FILENAME is the name of the file and
21602 DIRNAME the name of the source directory which contains FILENAME
21603 or NULL if not known.
21604 This routine tries to keep line numbers from identical absolute and
21605 relative file names in a common subfile.
21607 Using the `list' example from the GDB testsuite, which resides in
21608 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21609 of /srcdir/list0.c yields the following debugging information for list0.c:
21611 DW_AT_name: /srcdir/list0.c
21612 DW_AT_comp_dir: /compdir
21613 files.files[0].name: list0.h
21614 files.files[0].dir: /srcdir
21615 files.files[1].name: list0.c
21616 files.files[1].dir: /srcdir
21618 The line number information for list0.c has to end up in a single
21619 subfile, so that `break /srcdir/list0.c:1' works as expected.
21620 start_subfile will ensure that this happens provided that we pass the
21621 concatenation of files.files[1].dir and files.files[1].name as the
21625 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21626 const char *dirname
)
21628 gdb::unique_xmalloc_ptr
<char> copy
;
21630 /* In order not to lose the line information directory,
21631 we concatenate it to the filename when it makes sense.
21632 Note that the Dwarf3 standard says (speaking of filenames in line
21633 information): ``The directory index is ignored for file names
21634 that represent full path names''. Thus ignoring dirname in the
21635 `else' branch below isn't an issue. */
21637 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21639 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21640 filename
= copy
.get ();
21643 cu
->get_builder ()->start_subfile (filename
);
21647 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21648 struct dwarf2_cu
*cu
)
21650 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21651 struct comp_unit_head
*cu_header
= &cu
->header
;
21653 /* NOTE drow/2003-01-30: There used to be a comment and some special
21654 code here to turn a symbol with DW_AT_external and a
21655 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21656 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21657 with some versions of binutils) where shared libraries could have
21658 relocations against symbols in their debug information - the
21659 minimal symbol would have the right address, but the debug info
21660 would not. It's no longer necessary, because we will explicitly
21661 apply relocations when we read in the debug information now. */
21663 /* A DW_AT_location attribute with no contents indicates that a
21664 variable has been optimized away. */
21665 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21667 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
21671 /* Handle one degenerate form of location expression specially, to
21672 preserve GDB's previous behavior when section offsets are
21673 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21674 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21676 if (attr
->form_is_block ())
21678 struct dwarf_block
*block
= attr
->as_block ();
21680 if ((block
->data
[0] == DW_OP_addr
21681 && block
->size
== 1 + cu_header
->addr_size
)
21682 || ((block
->data
[0] == DW_OP_GNU_addr_index
21683 || block
->data
[0] == DW_OP_addrx
)
21685 == 1 + leb128_size (&block
->data
[1]))))
21687 unsigned int dummy
;
21689 if (block
->data
[0] == DW_OP_addr
)
21690 SET_SYMBOL_VALUE_ADDRESS
21691 (sym
, cu
->header
.read_address (objfile
->obfd
,
21695 SET_SYMBOL_VALUE_ADDRESS
21696 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21698 sym
->set_aclass_index (LOC_STATIC
);
21699 fixup_symbol_section (sym
, objfile
);
21700 SET_SYMBOL_VALUE_ADDRESS
21702 SYMBOL_VALUE_ADDRESS (sym
)
21703 + objfile
->section_offsets
[sym
->section_index ()]);
21708 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21709 expression evaluator, and use LOC_COMPUTED only when necessary
21710 (i.e. when the value of a register or memory location is
21711 referenced, or a thread-local block, etc.). Then again, it might
21712 not be worthwhile. I'm assuming that it isn't unless performance
21713 or memory numbers show me otherwise. */
21715 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21717 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21718 cu
->has_loclist
= true;
21721 /* Given a pointer to a DWARF information entry, figure out if we need
21722 to make a symbol table entry for it, and if so, create a new entry
21723 and return a pointer to it.
21724 If TYPE is NULL, determine symbol type from the die, otherwise
21725 used the passed type.
21726 If SPACE is not NULL, use it to hold the new symbol. If it is
21727 NULL, allocate a new symbol on the objfile's obstack. */
21729 static struct symbol
*
21730 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21731 struct symbol
*space
)
21733 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21734 struct objfile
*objfile
= per_objfile
->objfile
;
21735 struct gdbarch
*gdbarch
= objfile
->arch ();
21736 struct symbol
*sym
= NULL
;
21738 struct attribute
*attr
= NULL
;
21739 struct attribute
*attr2
= NULL
;
21740 CORE_ADDR baseaddr
;
21741 struct pending
**list_to_add
= NULL
;
21743 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21745 baseaddr
= objfile
->text_section_offset ();
21747 name
= dwarf2_name (die
, cu
);
21750 int suppress_add
= 0;
21755 sym
= new (&objfile
->objfile_obstack
) symbol
;
21756 OBJSTAT (objfile
, n_syms
++);
21758 /* Cache this symbol's name and the name's demangled form (if any). */
21759 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21760 /* Fortran does not have mangling standard and the mangling does differ
21761 between gfortran, iFort etc. */
21762 const char *physname
21763 = (cu
->per_cu
->lang
== language_fortran
21764 ? dwarf2_full_name (name
, die
, cu
)
21765 : dwarf2_physname (name
, die
, cu
));
21766 const char *linkagename
= dw2_linkage_name (die
, cu
);
21768 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21769 sym
->set_linkage_name (physname
);
21772 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21773 sym
->set_linkage_name (linkagename
);
21776 /* Handle DW_AT_artificial. */
21777 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
21778 if (attr
!= nullptr)
21779 sym
->artificial
= attr
->as_boolean ();
21781 /* Default assumptions.
21782 Use the passed type or decode it from the die. */
21783 sym
->set_domain (VAR_DOMAIN
);
21784 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
21786 sym
->set_type (type
);
21788 sym
->set_type (die_type (die
, cu
));
21789 attr
= dwarf2_attr (die
,
21790 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21792 if (attr
!= nullptr)
21793 sym
->set_line (attr
->constant_value (0));
21795 attr
= dwarf2_attr (die
,
21796 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21798 if (attr
!= nullptr && attr
->is_nonnegative ())
21800 file_name_index file_index
21801 = (file_name_index
) attr
->as_nonnegative ();
21802 struct file_entry
*fe
;
21804 if (cu
->line_header
!= NULL
)
21805 fe
= cu
->line_header
->file_name_at (file_index
);
21810 complaint (_("file index out of range"));
21812 symbol_set_symtab (sym
, fe
->symtab
);
21818 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21819 if (attr
!= nullptr)
21823 addr
= attr
->as_address ();
21824 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21825 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21826 sym
->set_aclass_index (LOC_LABEL
);
21829 sym
->set_aclass_index (LOC_OPTIMIZED_OUT
);
21830 sym
->set_type (objfile_type (objfile
)->builtin_core_addr
);
21831 sym
->set_domain (LABEL_DOMAIN
);
21832 add_symbol_to_list (sym
, cu
->list_in_scope
);
21834 case DW_TAG_subprogram
:
21835 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21837 sym
->set_aclass_index (LOC_BLOCK
);
21838 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21839 if ((attr2
!= nullptr && attr2
->as_boolean ())
21840 || cu
->per_cu
->lang
== language_ada
21841 || cu
->per_cu
->lang
== language_fortran
)
21843 /* Subprograms marked external are stored as a global symbol.
21844 Ada and Fortran subprograms, whether marked external or
21845 not, are always stored as a global symbol, because we want
21846 to be able to access them globally. For instance, we want
21847 to be able to break on a nested subprogram without having
21848 to specify the context. */
21849 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21853 list_to_add
= cu
->list_in_scope
;
21856 case DW_TAG_inlined_subroutine
:
21857 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21859 sym
->set_aclass_index (LOC_BLOCK
);
21860 sym
->set_is_inlined (1);
21861 list_to_add
= cu
->list_in_scope
;
21863 case DW_TAG_template_value_param
:
21865 /* Fall through. */
21866 case DW_TAG_constant
:
21867 case DW_TAG_variable
:
21868 case DW_TAG_member
:
21869 /* Compilation with minimal debug info may result in
21870 variables with missing type entries. Change the
21871 misleading `void' type to something sensible. */
21872 if (sym
->type ()->code () == TYPE_CODE_VOID
)
21873 sym
->set_type (objfile_type (objfile
)->builtin_int
);
21875 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21876 /* In the case of DW_TAG_member, we should only be called for
21877 static const members. */
21878 if (die
->tag
== DW_TAG_member
)
21880 /* dwarf2_add_field uses die_is_declaration,
21881 so we do the same. */
21882 gdb_assert (die_is_declaration (die
, cu
));
21885 if (attr
!= nullptr)
21887 dwarf2_const_value (attr
, sym
, cu
);
21888 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21891 if (attr2
!= nullptr && attr2
->as_boolean ())
21892 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21894 list_to_add
= cu
->list_in_scope
;
21898 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21899 if (attr
!= nullptr)
21901 var_decode_location (attr
, sym
, cu
);
21902 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21904 /* Fortran explicitly imports any global symbols to the local
21905 scope by DW_TAG_common_block. */
21906 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21907 && die
->parent
->tag
== DW_TAG_common_block
)
21910 if (sym
->aclass () == LOC_STATIC
21911 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21912 && !per_objfile
->per_bfd
->has_section_at_zero
)
21914 /* When a static variable is eliminated by the linker,
21915 the corresponding debug information is not stripped
21916 out, but the variable address is set to null;
21917 do not add such variables into symbol table. */
21919 else if (attr2
!= nullptr && attr2
->as_boolean ())
21921 if (sym
->aclass () == LOC_STATIC
21922 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21923 && per_objfile
->per_bfd
->can_copy
)
21925 /* A global static variable might be subject to
21926 copy relocation. We first check for a local
21927 minsym, though, because maybe the symbol was
21928 marked hidden, in which case this would not
21930 bound_minimal_symbol found
21931 = (lookup_minimal_symbol_linkage
21932 (sym
->linkage_name (), objfile
));
21933 if (found
.minsym
!= nullptr)
21934 sym
->maybe_copied
= 1;
21937 /* A variable with DW_AT_external is never static,
21938 but it may be block-scoped. */
21940 = ((cu
->list_in_scope
21941 == cu
->get_builder ()->get_file_symbols ())
21942 ? cu
->get_builder ()->get_global_symbols ()
21943 : cu
->list_in_scope
);
21946 list_to_add
= cu
->list_in_scope
;
21950 /* We do not know the address of this symbol.
21951 If it is an external symbol and we have type information
21952 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21953 The address of the variable will then be determined from
21954 the minimal symbol table whenever the variable is
21956 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21958 /* Fortran explicitly imports any global symbols to the local
21959 scope by DW_TAG_common_block. */
21960 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21961 && die
->parent
->tag
== DW_TAG_common_block
)
21963 /* SYMBOL_CLASS doesn't matter here because
21964 read_common_block is going to reset it. */
21966 list_to_add
= cu
->list_in_scope
;
21968 else if (attr2
!= nullptr && attr2
->as_boolean ()
21969 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21971 /* A variable with DW_AT_external is never static, but it
21972 may be block-scoped. */
21974 = ((cu
->list_in_scope
21975 == cu
->get_builder ()->get_file_symbols ())
21976 ? cu
->get_builder ()->get_global_symbols ()
21977 : cu
->list_in_scope
);
21979 sym
->set_aclass_index (LOC_UNRESOLVED
);
21981 else if (!die_is_declaration (die
, cu
))
21983 /* Use the default LOC_OPTIMIZED_OUT class. */
21984 gdb_assert (sym
->aclass () == LOC_OPTIMIZED_OUT
);
21986 list_to_add
= cu
->list_in_scope
;
21990 case DW_TAG_formal_parameter
:
21992 /* If we are inside a function, mark this as an argument. If
21993 not, we might be looking at an argument to an inlined function
21994 when we do not have enough information to show inlined frames;
21995 pretend it's a local variable in that case so that the user can
21997 struct context_stack
*curr
21998 = cu
->get_builder ()->get_current_context_stack ();
21999 if (curr
!= nullptr && curr
->name
!= nullptr)
22000 sym
->set_is_argument (1);
22001 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22002 if (attr
!= nullptr)
22004 var_decode_location (attr
, sym
, cu
);
22006 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22007 if (attr
!= nullptr)
22009 dwarf2_const_value (attr
, sym
, cu
);
22012 list_to_add
= cu
->list_in_scope
;
22015 case DW_TAG_unspecified_parameters
:
22016 /* From varargs functions; gdb doesn't seem to have any
22017 interest in this information, so just ignore it for now.
22020 case DW_TAG_template_type_param
:
22022 /* Fall through. */
22023 case DW_TAG_class_type
:
22024 case DW_TAG_interface_type
:
22025 case DW_TAG_structure_type
:
22026 case DW_TAG_union_type
:
22027 case DW_TAG_set_type
:
22028 case DW_TAG_enumeration_type
:
22029 case DW_TAG_namelist
:
22030 if (die
->tag
== DW_TAG_namelist
)
22032 sym
->set_aclass_index (LOC_STATIC
);
22033 sym
->set_domain (VAR_DOMAIN
);
22037 sym
->set_aclass_index (LOC_TYPEDEF
);
22038 sym
->set_domain (STRUCT_DOMAIN
);
22041 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22042 really ever be static objects: otherwise, if you try
22043 to, say, break of a class's method and you're in a file
22044 which doesn't mention that class, it won't work unless
22045 the check for all static symbols in lookup_symbol_aux
22046 saves you. See the OtherFileClass tests in
22047 gdb.c++/namespace.exp. */
22051 buildsym_compunit
*builder
= cu
->get_builder ();
22053 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22054 && cu
->per_cu
->lang
== language_cplus
22055 ? builder
->get_global_symbols ()
22056 : cu
->list_in_scope
);
22058 /* The semantics of C++ state that "struct foo {
22059 ... }" also defines a typedef for "foo". */
22060 if (cu
->per_cu
->lang
== language_cplus
22061 || cu
->per_cu
->lang
== language_ada
22062 || cu
->per_cu
->lang
== language_d
22063 || cu
->per_cu
->lang
== language_rust
)
22065 /* The symbol's name is already allocated along
22066 with this objfile, so we don't need to
22067 duplicate it for the type. */
22068 if (sym
->type ()->name () == 0)
22069 sym
->type ()->set_name (sym
->search_name ());
22074 case DW_TAG_typedef
:
22075 sym
->set_aclass_index (LOC_TYPEDEF
);
22076 sym
->set_domain (VAR_DOMAIN
);
22077 list_to_add
= cu
->list_in_scope
;
22079 case DW_TAG_array_type
:
22080 case DW_TAG_base_type
:
22081 case DW_TAG_subrange_type
:
22082 case DW_TAG_generic_subrange
:
22083 sym
->set_aclass_index (LOC_TYPEDEF
);
22084 sym
->set_domain (VAR_DOMAIN
);
22085 list_to_add
= cu
->list_in_scope
;
22087 case DW_TAG_enumerator
:
22088 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22089 if (attr
!= nullptr)
22091 dwarf2_const_value (attr
, sym
, cu
);
22094 /* NOTE: carlton/2003-11-10: See comment above in the
22095 DW_TAG_class_type, etc. block. */
22098 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22099 && cu
->per_cu
->lang
== language_cplus
22100 ? cu
->get_builder ()->get_global_symbols ()
22101 : cu
->list_in_scope
);
22104 case DW_TAG_imported_declaration
:
22105 case DW_TAG_namespace
:
22106 sym
->set_aclass_index (LOC_TYPEDEF
);
22107 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22109 case DW_TAG_module
:
22110 sym
->set_aclass_index (LOC_TYPEDEF
);
22111 sym
->set_domain (MODULE_DOMAIN
);
22112 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22114 case DW_TAG_common_block
:
22115 sym
->set_aclass_index (LOC_COMMON_BLOCK
);
22116 sym
->set_domain (COMMON_BLOCK_DOMAIN
);
22117 add_symbol_to_list (sym
, cu
->list_in_scope
);
22120 /* Not a tag we recognize. Hopefully we aren't processing
22121 trash data, but since we must specifically ignore things
22122 we don't recognize, there is nothing else we should do at
22124 complaint (_("unsupported tag: '%s'"),
22125 dwarf_tag_name (die
->tag
));
22131 sym
->hash_next
= objfile
->template_symbols
;
22132 objfile
->template_symbols
= sym
;
22133 list_to_add
= NULL
;
22136 if (list_to_add
!= NULL
)
22137 add_symbol_to_list (sym
, list_to_add
);
22139 /* For the benefit of old versions of GCC, check for anonymous
22140 namespaces based on the demangled name. */
22141 if (!cu
->processing_has_namespace_info
22142 && cu
->per_cu
->lang
== language_cplus
)
22143 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22148 /* Given an attr with a DW_FORM_dataN value in host byte order,
22149 zero-extend it as appropriate for the symbol's type. The DWARF
22150 standard (v4) is not entirely clear about the meaning of using
22151 DW_FORM_dataN for a constant with a signed type, where the type is
22152 wider than the data. The conclusion of a discussion on the DWARF
22153 list was that this is unspecified. We choose to always zero-extend
22154 because that is the interpretation long in use by GCC. */
22157 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22158 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22160 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22161 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22162 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22163 LONGEST l
= attr
->constant_value (0);
22165 if (bits
< sizeof (*value
) * 8)
22167 l
&= ((LONGEST
) 1 << bits
) - 1;
22170 else if (bits
== sizeof (*value
) * 8)
22174 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22175 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22182 /* Read a constant value from an attribute. Either set *VALUE, or if
22183 the value does not fit in *VALUE, set *BYTES - either already
22184 allocated on the objfile obstack, or newly allocated on OBSTACK,
22185 or, set *BATON, if we translated the constant to a location
22189 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22190 const char *name
, struct obstack
*obstack
,
22191 struct dwarf2_cu
*cu
,
22192 LONGEST
*value
, const gdb_byte
**bytes
,
22193 struct dwarf2_locexpr_baton
**baton
)
22195 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22196 struct objfile
*objfile
= per_objfile
->objfile
;
22197 struct comp_unit_head
*cu_header
= &cu
->header
;
22198 struct dwarf_block
*blk
;
22199 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22200 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22206 switch (attr
->form
)
22209 case DW_FORM_addrx
:
22210 case DW_FORM_GNU_addr_index
:
22214 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22215 dwarf2_const_value_length_mismatch_complaint (name
,
22216 cu_header
->addr_size
,
22217 TYPE_LENGTH (type
));
22218 /* Symbols of this form are reasonably rare, so we just
22219 piggyback on the existing location code rather than writing
22220 a new implementation of symbol_computed_ops. */
22221 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22222 (*baton
)->per_objfile
= per_objfile
;
22223 (*baton
)->per_cu
= cu
->per_cu
;
22224 gdb_assert ((*baton
)->per_cu
);
22226 (*baton
)->size
= 2 + cu_header
->addr_size
;
22227 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22228 (*baton
)->data
= data
;
22230 data
[0] = DW_OP_addr
;
22231 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22232 byte_order
, attr
->as_address ());
22233 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22236 case DW_FORM_string
:
22239 case DW_FORM_GNU_str_index
:
22240 case DW_FORM_GNU_strp_alt
:
22241 /* The string is already allocated on the objfile obstack, point
22243 *bytes
= (const gdb_byte
*) attr
->as_string ();
22245 case DW_FORM_block1
:
22246 case DW_FORM_block2
:
22247 case DW_FORM_block4
:
22248 case DW_FORM_block
:
22249 case DW_FORM_exprloc
:
22250 case DW_FORM_data16
:
22251 blk
= attr
->as_block ();
22252 if (TYPE_LENGTH (type
) != blk
->size
)
22253 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22254 TYPE_LENGTH (type
));
22255 *bytes
= blk
->data
;
22258 /* The DW_AT_const_value attributes are supposed to carry the
22259 symbol's value "represented as it would be on the target
22260 architecture." By the time we get here, it's already been
22261 converted to host endianness, so we just need to sign- or
22262 zero-extend it as appropriate. */
22263 case DW_FORM_data1
:
22264 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22266 case DW_FORM_data2
:
22267 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22269 case DW_FORM_data4
:
22270 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22272 case DW_FORM_data8
:
22273 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22276 case DW_FORM_sdata
:
22277 case DW_FORM_implicit_const
:
22278 *value
= attr
->as_signed ();
22281 case DW_FORM_udata
:
22282 *value
= attr
->as_unsigned ();
22286 complaint (_("unsupported const value attribute form: '%s'"),
22287 dwarf_form_name (attr
->form
));
22294 /* Copy constant value from an attribute to a symbol. */
22297 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22298 struct dwarf2_cu
*cu
)
22300 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22302 const gdb_byte
*bytes
;
22303 struct dwarf2_locexpr_baton
*baton
;
22305 dwarf2_const_value_attr (attr
, sym
->type (),
22306 sym
->print_name (),
22307 &objfile
->objfile_obstack
, cu
,
22308 &value
, &bytes
, &baton
);
22312 SYMBOL_LOCATION_BATON (sym
) = baton
;
22313 sym
->set_aclass_index (dwarf2_locexpr_index
);
22315 else if (bytes
!= NULL
)
22317 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22318 sym
->set_aclass_index (LOC_CONST_BYTES
);
22322 SYMBOL_VALUE (sym
) = value
;
22323 sym
->set_aclass_index (LOC_CONST
);
22327 /* Return the type of the die in question using its DW_AT_type attribute. */
22329 static struct type
*
22330 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22332 struct attribute
*type_attr
;
22334 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22337 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22338 /* A missing DW_AT_type represents a void type. */
22339 return objfile_type (objfile
)->builtin_void
;
22342 return lookup_die_type (die
, type_attr
, cu
);
22345 /* True iff CU's producer generates GNAT Ada auxiliary information
22346 that allows to find parallel types through that information instead
22347 of having to do expensive parallel lookups by type name. */
22350 need_gnat_info (struct dwarf2_cu
*cu
)
22352 /* Assume that the Ada compiler was GNAT, which always produces
22353 the auxiliary information. */
22354 return (cu
->per_cu
->lang
== language_ada
);
22357 /* Return the auxiliary type of the die in question using its
22358 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22359 attribute is not present. */
22361 static struct type
*
22362 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22364 struct attribute
*type_attr
;
22366 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22370 return lookup_die_type (die
, type_attr
, cu
);
22373 /* If DIE has a descriptive_type attribute, then set the TYPE's
22374 descriptive type accordingly. */
22377 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22378 struct dwarf2_cu
*cu
)
22380 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22382 if (descriptive_type
)
22384 ALLOCATE_GNAT_AUX_TYPE (type
);
22385 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22389 /* Return the containing type of the die in question using its
22390 DW_AT_containing_type attribute. */
22392 static struct type
*
22393 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22395 struct attribute
*type_attr
;
22396 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22398 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22400 error (_("Dwarf Error: Problem turning containing type into gdb type "
22401 "[in module %s]"), objfile_name (objfile
));
22403 return lookup_die_type (die
, type_attr
, cu
);
22406 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22408 static struct type
*
22409 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22411 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22412 struct objfile
*objfile
= per_objfile
->objfile
;
22415 std::string message
22416 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22417 objfile_name (objfile
),
22418 sect_offset_str (cu
->header
.sect_off
),
22419 sect_offset_str (die
->sect_off
));
22420 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22422 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22425 /* Look up the type of DIE in CU using its type attribute ATTR.
22426 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22427 DW_AT_containing_type.
22428 If there is no type substitute an error marker. */
22430 static struct type
*
22431 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22432 struct dwarf2_cu
*cu
)
22434 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22435 struct objfile
*objfile
= per_objfile
->objfile
;
22436 struct type
*this_type
;
22438 gdb_assert (attr
->name
== DW_AT_type
22439 || attr
->name
== DW_AT_GNAT_descriptive_type
22440 || attr
->name
== DW_AT_containing_type
);
22442 /* First see if we have it cached. */
22444 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22446 struct dwarf2_per_cu_data
*per_cu
;
22447 sect_offset sect_off
= attr
->get_ref_die_offset ();
22449 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22450 per_objfile
->per_bfd
);
22451 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22453 else if (attr
->form_is_ref ())
22455 sect_offset sect_off
= attr
->get_ref_die_offset ();
22457 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22459 else if (attr
->form
== DW_FORM_ref_sig8
)
22461 ULONGEST signature
= attr
->as_signature ();
22463 return get_signatured_type (die
, signature
, cu
);
22467 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22468 " at %s [in module %s]"),
22469 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22470 objfile_name (objfile
));
22471 return build_error_marker_type (cu
, die
);
22474 /* If not cached we need to read it in. */
22476 if (this_type
== NULL
)
22478 struct die_info
*type_die
= NULL
;
22479 struct dwarf2_cu
*type_cu
= cu
;
22481 if (attr
->form_is_ref ())
22482 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22483 if (type_die
== NULL
)
22484 return build_error_marker_type (cu
, die
);
22485 /* If we find the type now, it's probably because the type came
22486 from an inter-CU reference and the type's CU got expanded before
22488 this_type
= read_type_die (type_die
, type_cu
);
22491 /* If we still don't have a type use an error marker. */
22493 if (this_type
== NULL
)
22494 return build_error_marker_type (cu
, die
);
22499 /* Return the type in DIE, CU.
22500 Returns NULL for invalid types.
22502 This first does a lookup in die_type_hash,
22503 and only reads the die in if necessary.
22505 NOTE: This can be called when reading in partial or full symbols. */
22507 static struct type
*
22508 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22510 struct type
*this_type
;
22512 this_type
= get_die_type (die
, cu
);
22516 return read_type_die_1 (die
, cu
);
22519 /* Read the type in DIE, CU.
22520 Returns NULL for invalid types. */
22522 static struct type
*
22523 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22525 struct type
*this_type
= NULL
;
22529 case DW_TAG_class_type
:
22530 case DW_TAG_interface_type
:
22531 case DW_TAG_structure_type
:
22532 case DW_TAG_union_type
:
22533 this_type
= read_structure_type (die
, cu
);
22535 case DW_TAG_enumeration_type
:
22536 this_type
= read_enumeration_type (die
, cu
);
22538 case DW_TAG_subprogram
:
22539 case DW_TAG_subroutine_type
:
22540 case DW_TAG_inlined_subroutine
:
22541 this_type
= read_subroutine_type (die
, cu
);
22543 case DW_TAG_array_type
:
22544 this_type
= read_array_type (die
, cu
);
22546 case DW_TAG_set_type
:
22547 this_type
= read_set_type (die
, cu
);
22549 case DW_TAG_pointer_type
:
22550 this_type
= read_tag_pointer_type (die
, cu
);
22552 case DW_TAG_ptr_to_member_type
:
22553 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22555 case DW_TAG_reference_type
:
22556 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22558 case DW_TAG_rvalue_reference_type
:
22559 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22561 case DW_TAG_const_type
:
22562 this_type
= read_tag_const_type (die
, cu
);
22564 case DW_TAG_volatile_type
:
22565 this_type
= read_tag_volatile_type (die
, cu
);
22567 case DW_TAG_restrict_type
:
22568 this_type
= read_tag_restrict_type (die
, cu
);
22570 case DW_TAG_string_type
:
22571 this_type
= read_tag_string_type (die
, cu
);
22573 case DW_TAG_typedef
:
22574 this_type
= read_typedef (die
, cu
);
22576 case DW_TAG_generic_subrange
:
22577 case DW_TAG_subrange_type
:
22578 this_type
= read_subrange_type (die
, cu
);
22580 case DW_TAG_base_type
:
22581 this_type
= read_base_type (die
, cu
);
22583 case DW_TAG_unspecified_type
:
22584 this_type
= read_unspecified_type (die
, cu
);
22586 case DW_TAG_namespace
:
22587 this_type
= read_namespace_type (die
, cu
);
22589 case DW_TAG_module
:
22590 this_type
= read_module_type (die
, cu
);
22592 case DW_TAG_atomic_type
:
22593 this_type
= read_tag_atomic_type (die
, cu
);
22596 complaint (_("unexpected tag in read_type_die: '%s'"),
22597 dwarf_tag_name (die
->tag
));
22604 /* See if we can figure out if the class lives in a namespace. We do
22605 this by looking for a member function; its demangled name will
22606 contain namespace info, if there is any.
22607 Return the computed name or NULL.
22608 Space for the result is allocated on the objfile's obstack.
22609 This is the full-die version of guess_partial_die_structure_name.
22610 In this case we know DIE has no useful parent. */
22612 static const char *
22613 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22615 struct die_info
*spec_die
;
22616 struct dwarf2_cu
*spec_cu
;
22617 struct die_info
*child
;
22618 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22621 spec_die
= die_specification (die
, &spec_cu
);
22622 if (spec_die
!= NULL
)
22628 for (child
= die
->child
;
22630 child
= child
->sibling
)
22632 if (child
->tag
== DW_TAG_subprogram
)
22634 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22636 if (linkage_name
!= NULL
)
22638 gdb::unique_xmalloc_ptr
<char> actual_name
22639 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22640 const char *name
= NULL
;
22642 if (actual_name
!= NULL
)
22644 const char *die_name
= dwarf2_name (die
, cu
);
22646 if (die_name
!= NULL
22647 && strcmp (die_name
, actual_name
.get ()) != 0)
22649 /* Strip off the class name from the full name.
22650 We want the prefix. */
22651 int die_name_len
= strlen (die_name
);
22652 int actual_name_len
= strlen (actual_name
.get ());
22653 const char *ptr
= actual_name
.get ();
22655 /* Test for '::' as a sanity check. */
22656 if (actual_name_len
> die_name_len
+ 2
22657 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22658 name
= obstack_strndup (
22659 &objfile
->per_bfd
->storage_obstack
,
22660 ptr
, actual_name_len
- die_name_len
- 2);
22671 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22672 prefix part in such case. See
22673 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22675 static const char *
22676 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22678 struct attribute
*attr
;
22681 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22682 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22685 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22688 attr
= dw2_linkage_name_attr (die
, cu
);
22689 const char *attr_name
= attr
->as_string ();
22690 if (attr
== NULL
|| attr_name
== NULL
)
22693 /* dwarf2_name had to be already called. */
22694 gdb_assert (attr
->canonical_string_p ());
22696 /* Strip the base name, keep any leading namespaces/classes. */
22697 base
= strrchr (attr_name
, ':');
22698 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22701 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22702 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22704 &base
[-1] - attr_name
);
22707 /* Return the name of the namespace/class that DIE is defined within,
22708 or "" if we can't tell. The caller should not xfree the result.
22710 For example, if we're within the method foo() in the following
22720 then determine_prefix on foo's die will return "N::C". */
22722 static const char *
22723 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22725 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22726 struct die_info
*parent
, *spec_die
;
22727 struct dwarf2_cu
*spec_cu
;
22728 struct type
*parent_type
;
22729 const char *retval
;
22731 if (cu
->per_cu
->lang
!= language_cplus
22732 && cu
->per_cu
->lang
!= language_fortran
22733 && cu
->per_cu
->lang
!= language_d
22734 && cu
->per_cu
->lang
!= language_rust
)
22737 retval
= anonymous_struct_prefix (die
, cu
);
22741 /* We have to be careful in the presence of DW_AT_specification.
22742 For example, with GCC 3.4, given the code
22746 // Definition of N::foo.
22750 then we'll have a tree of DIEs like this:
22752 1: DW_TAG_compile_unit
22753 2: DW_TAG_namespace // N
22754 3: DW_TAG_subprogram // declaration of N::foo
22755 4: DW_TAG_subprogram // definition of N::foo
22756 DW_AT_specification // refers to die #3
22758 Thus, when processing die #4, we have to pretend that we're in
22759 the context of its DW_AT_specification, namely the contex of die
22762 spec_die
= die_specification (die
, &spec_cu
);
22763 if (spec_die
== NULL
)
22764 parent
= die
->parent
;
22767 parent
= spec_die
->parent
;
22771 if (parent
== NULL
)
22773 else if (parent
->building_fullname
)
22776 const char *parent_name
;
22778 /* It has been seen on RealView 2.2 built binaries,
22779 DW_TAG_template_type_param types actually _defined_ as
22780 children of the parent class:
22783 template class <class Enum> Class{};
22784 Class<enum E> class_e;
22786 1: DW_TAG_class_type (Class)
22787 2: DW_TAG_enumeration_type (E)
22788 3: DW_TAG_enumerator (enum1:0)
22789 3: DW_TAG_enumerator (enum2:1)
22791 2: DW_TAG_template_type_param
22792 DW_AT_type DW_FORM_ref_udata (E)
22794 Besides being broken debug info, it can put GDB into an
22795 infinite loop. Consider:
22797 When we're building the full name for Class<E>, we'll start
22798 at Class, and go look over its template type parameters,
22799 finding E. We'll then try to build the full name of E, and
22800 reach here. We're now trying to build the full name of E,
22801 and look over the parent DIE for containing scope. In the
22802 broken case, if we followed the parent DIE of E, we'd again
22803 find Class, and once again go look at its template type
22804 arguments, etc., etc. Simply don't consider such parent die
22805 as source-level parent of this die (it can't be, the language
22806 doesn't allow it), and break the loop here. */
22807 name
= dwarf2_name (die
, cu
);
22808 parent_name
= dwarf2_name (parent
, cu
);
22809 complaint (_("template param type '%s' defined within parent '%s'"),
22810 name
? name
: "<unknown>",
22811 parent_name
? parent_name
: "<unknown>");
22815 switch (parent
->tag
)
22817 case DW_TAG_namespace
:
22818 parent_type
= read_type_die (parent
, cu
);
22819 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22820 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22821 Work around this problem here. */
22822 if (cu
->per_cu
->lang
== language_cplus
22823 && strcmp (parent_type
->name (), "::") == 0)
22825 /* We give a name to even anonymous namespaces. */
22826 return parent_type
->name ();
22827 case DW_TAG_class_type
:
22828 case DW_TAG_interface_type
:
22829 case DW_TAG_structure_type
:
22830 case DW_TAG_union_type
:
22831 case DW_TAG_module
:
22832 parent_type
= read_type_die (parent
, cu
);
22833 if (parent_type
->name () != NULL
)
22834 return parent_type
->name ();
22836 /* An anonymous structure is only allowed non-static data
22837 members; no typedefs, no member functions, et cetera.
22838 So it does not need a prefix. */
22840 case DW_TAG_compile_unit
:
22841 case DW_TAG_partial_unit
:
22842 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22843 if (cu
->per_cu
->lang
== language_cplus
22844 && !per_objfile
->per_bfd
->types
.empty ()
22845 && die
->child
!= NULL
22846 && (die
->tag
== DW_TAG_class_type
22847 || die
->tag
== DW_TAG_structure_type
22848 || die
->tag
== DW_TAG_union_type
))
22850 const char *name
= guess_full_die_structure_name (die
, cu
);
22855 case DW_TAG_subprogram
:
22856 /* Nested subroutines in Fortran get a prefix with the name
22857 of the parent's subroutine. */
22858 if (cu
->per_cu
->lang
== language_fortran
)
22860 if ((die
->tag
== DW_TAG_subprogram
)
22861 && (dwarf2_name (parent
, cu
) != NULL
))
22862 return dwarf2_name (parent
, cu
);
22865 case DW_TAG_enumeration_type
:
22866 parent_type
= read_type_die (parent
, cu
);
22867 if (parent_type
->is_declared_class ())
22869 if (parent_type
->name () != NULL
)
22870 return parent_type
->name ();
22873 /* Fall through. */
22875 return determine_prefix (parent
, cu
);
22879 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22880 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22881 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22882 an obconcat, otherwise allocate storage for the result. The CU argument is
22883 used to determine the language and hence, the appropriate separator. */
22885 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22888 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22889 int physname
, struct dwarf2_cu
*cu
)
22891 const char *lead
= "";
22894 if (suffix
== NULL
|| suffix
[0] == '\0'
22895 || prefix
== NULL
|| prefix
[0] == '\0')
22897 else if (cu
->per_cu
->lang
== language_d
)
22899 /* For D, the 'main' function could be defined in any module, but it
22900 should never be prefixed. */
22901 if (strcmp (suffix
, "D main") == 0)
22909 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22911 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22912 DW_AT_MIPS_linkage_name is preferred and used instead. */
22920 if (prefix
== NULL
)
22922 if (suffix
== NULL
)
22929 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22931 strcpy (retval
, lead
);
22932 strcat (retval
, prefix
);
22933 strcat (retval
, sep
);
22934 strcat (retval
, suffix
);
22939 /* We have an obstack. */
22940 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22944 /* Get name of a die, return NULL if not found. */
22946 static const char *
22947 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22948 struct objfile
*objfile
)
22950 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22952 gdb::unique_xmalloc_ptr
<char> canon_name
22953 = cp_canonicalize_string (name
);
22955 if (canon_name
!= nullptr)
22956 name
= objfile
->intern (canon_name
.get ());
22962 /* Get name of a die, return NULL if not found.
22963 Anonymous namespaces are converted to their magic string. */
22965 static const char *
22966 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22968 struct attribute
*attr
;
22969 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22971 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22972 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22973 if (attr_name
== nullptr
22974 && die
->tag
!= DW_TAG_namespace
22975 && die
->tag
!= DW_TAG_class_type
22976 && die
->tag
!= DW_TAG_interface_type
22977 && die
->tag
!= DW_TAG_structure_type
22978 && die
->tag
!= DW_TAG_namelist
22979 && die
->tag
!= DW_TAG_union_type
)
22984 case DW_TAG_compile_unit
:
22985 case DW_TAG_partial_unit
:
22986 /* Compilation units have a DW_AT_name that is a filename, not
22987 a source language identifier. */
22988 case DW_TAG_enumeration_type
:
22989 case DW_TAG_enumerator
:
22990 /* These tags always have simple identifiers already; no need
22991 to canonicalize them. */
22994 case DW_TAG_namespace
:
22995 if (attr_name
!= nullptr)
22997 return CP_ANONYMOUS_NAMESPACE_STR
;
22999 case DW_TAG_class_type
:
23000 case DW_TAG_interface_type
:
23001 case DW_TAG_structure_type
:
23002 case DW_TAG_union_type
:
23003 case DW_TAG_namelist
:
23004 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23005 structures or unions. These were of the form "._%d" in GCC 4.1,
23006 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23007 and GCC 4.4. We work around this problem by ignoring these. */
23008 if (attr_name
!= nullptr
23009 && (startswith (attr_name
, "._")
23010 || startswith (attr_name
, "<anonymous")))
23013 /* GCC might emit a nameless typedef that has a linkage name. See
23014 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23015 if (!attr
|| attr_name
== NULL
)
23017 attr
= dw2_linkage_name_attr (die
, cu
);
23018 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23019 if (attr
== NULL
|| attr_name
== NULL
)
23022 /* Avoid demangling attr_name the second time on a second
23023 call for the same DIE. */
23024 if (!attr
->canonical_string_p ())
23026 gdb::unique_xmalloc_ptr
<char> demangled
23027 (gdb_demangle (attr_name
, DMGL_TYPES
));
23028 if (demangled
== nullptr)
23031 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23032 attr_name
= attr
->as_string ();
23035 /* Strip any leading namespaces/classes, keep only the
23036 base name. DW_AT_name for named DIEs does not
23037 contain the prefixes. */
23038 const char *base
= strrchr (attr_name
, ':');
23039 if (base
&& base
> attr_name
&& base
[-1] == ':')
23050 if (!attr
->canonical_string_p ())
23051 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23053 return attr
->as_string ();
23056 /* Return the die that this die in an extension of, or NULL if there
23057 is none. *EXT_CU is the CU containing DIE on input, and the CU
23058 containing the return value on output. */
23060 static struct die_info
*
23061 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23063 struct attribute
*attr
;
23065 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23069 return follow_die_ref (die
, attr
, ext_cu
);
23073 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23077 gdb_printf (f
, "%*sDie: %s (abbrev %d, offset %s)\n",
23079 dwarf_tag_name (die
->tag
), die
->abbrev
,
23080 sect_offset_str (die
->sect_off
));
23082 if (die
->parent
!= NULL
)
23083 gdb_printf (f
, "%*s parent at offset: %s\n",
23085 sect_offset_str (die
->parent
->sect_off
));
23087 gdb_printf (f
, "%*s has children: %s\n",
23089 dwarf_bool_name (die
->child
!= NULL
));
23091 gdb_printf (f
, "%*s attributes:\n", indent
, "");
23093 for (i
= 0; i
< die
->num_attrs
; ++i
)
23095 gdb_printf (f
, "%*s %s (%s) ",
23097 dwarf_attr_name (die
->attrs
[i
].name
),
23098 dwarf_form_name (die
->attrs
[i
].form
));
23100 switch (die
->attrs
[i
].form
)
23103 case DW_FORM_addrx
:
23104 case DW_FORM_GNU_addr_index
:
23105 gdb_printf (f
, "address: ");
23106 gdb_puts (hex_string (die
->attrs
[i
].as_address ()), f
);
23108 case DW_FORM_block2
:
23109 case DW_FORM_block4
:
23110 case DW_FORM_block
:
23111 case DW_FORM_block1
:
23112 gdb_printf (f
, "block: size %s",
23113 pulongest (die
->attrs
[i
].as_block ()->size
));
23115 case DW_FORM_exprloc
:
23116 gdb_printf (f
, "expression: size %s",
23117 pulongest (die
->attrs
[i
].as_block ()->size
));
23119 case DW_FORM_data16
:
23120 gdb_printf (f
, "constant of 16 bytes");
23122 case DW_FORM_ref_addr
:
23123 gdb_printf (f
, "ref address: ");
23124 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23126 case DW_FORM_GNU_ref_alt
:
23127 gdb_printf (f
, "alt ref address: ");
23128 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23134 case DW_FORM_ref_udata
:
23135 gdb_printf (f
, "constant ref: 0x%lx (adjusted)",
23136 (long) (die
->attrs
[i
].as_unsigned ()));
23138 case DW_FORM_data1
:
23139 case DW_FORM_data2
:
23140 case DW_FORM_data4
:
23141 case DW_FORM_data8
:
23142 case DW_FORM_udata
:
23143 gdb_printf (f
, "constant: %s",
23144 pulongest (die
->attrs
[i
].as_unsigned ()));
23146 case DW_FORM_sec_offset
:
23147 gdb_printf (f
, "section offset: %s",
23148 pulongest (die
->attrs
[i
].as_unsigned ()));
23150 case DW_FORM_ref_sig8
:
23151 gdb_printf (f
, "signature: %s",
23152 hex_string (die
->attrs
[i
].as_signature ()));
23154 case DW_FORM_string
:
23156 case DW_FORM_line_strp
:
23158 case DW_FORM_GNU_str_index
:
23159 case DW_FORM_GNU_strp_alt
:
23160 gdb_printf (f
, "string: \"%s\" (%s canonicalized)",
23161 die
->attrs
[i
].as_string ()
23162 ? die
->attrs
[i
].as_string () : "",
23163 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23166 if (die
->attrs
[i
].as_boolean ())
23167 gdb_printf (f
, "flag: TRUE");
23169 gdb_printf (f
, "flag: FALSE");
23171 case DW_FORM_flag_present
:
23172 gdb_printf (f
, "flag: TRUE");
23174 case DW_FORM_indirect
:
23175 /* The reader will have reduced the indirect form to
23176 the "base form" so this form should not occur. */
23178 "unexpected attribute form: DW_FORM_indirect");
23180 case DW_FORM_sdata
:
23181 case DW_FORM_implicit_const
:
23182 gdb_printf (f
, "constant: %s",
23183 plongest (die
->attrs
[i
].as_signed ()));
23186 gdb_printf (f
, "unsupported attribute form: %d.",
23187 die
->attrs
[i
].form
);
23190 gdb_printf (f
, "\n");
23195 dump_die_for_error (struct die_info
*die
)
23197 dump_die_shallow (gdb_stderr
, 0, die
);
23201 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23203 int indent
= level
* 4;
23205 gdb_assert (die
!= NULL
);
23207 if (level
>= max_level
)
23210 dump_die_shallow (f
, indent
, die
);
23212 if (die
->child
!= NULL
)
23214 gdb_printf (f
, "%*s Children:", indent
, "");
23215 if (level
+ 1 < max_level
)
23217 gdb_printf (f
, "\n");
23218 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23223 " [not printed, max nesting level reached]\n");
23227 if (die
->sibling
!= NULL
&& level
> 0)
23229 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23233 /* This is called from the pdie macro in gdbinit.in.
23234 It's not static so gcc will keep a copy callable from gdb. */
23237 dump_die (struct die_info
*die
, int max_level
)
23239 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23243 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23247 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23248 to_underlying (die
->sect_off
),
23254 /* Follow reference or signature attribute ATTR of SRC_DIE.
23255 On entry *REF_CU is the CU of SRC_DIE.
23256 On exit *REF_CU is the CU of the result. */
23258 static struct die_info
*
23259 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23260 struct dwarf2_cu
**ref_cu
)
23262 struct die_info
*die
;
23264 if (attr
->form_is_ref ())
23265 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23266 else if (attr
->form
== DW_FORM_ref_sig8
)
23267 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23270 dump_die_for_error (src_die
);
23271 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23272 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23278 /* Follow reference OFFSET.
23279 On entry *REF_CU is the CU of the source die referencing OFFSET.
23280 On exit *REF_CU is the CU of the result.
23281 Returns NULL if OFFSET is invalid. */
23283 static struct die_info
*
23284 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23285 struct dwarf2_cu
**ref_cu
)
23287 struct die_info temp_die
;
23288 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23289 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23291 gdb_assert (cu
->per_cu
!= NULL
);
23295 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23296 "source CU contains target offset: %d",
23297 sect_offset_str (cu
->per_cu
->sect_off
),
23298 sect_offset_str (sect_off
),
23299 cu
->header
.offset_in_cu_p (sect_off
));
23301 if (cu
->per_cu
->is_debug_types
)
23303 /* .debug_types CUs cannot reference anything outside their CU.
23304 If they need to, they have to reference a signatured type via
23305 DW_FORM_ref_sig8. */
23306 if (!cu
->header
.offset_in_cu_p (sect_off
))
23309 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23310 || !cu
->header
.offset_in_cu_p (sect_off
))
23312 struct dwarf2_per_cu_data
*per_cu
;
23314 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23315 per_objfile
->per_bfd
);
23317 dwarf_read_debug_printf_v ("target CU offset: %s, "
23318 "target CU DIEs loaded: %d",
23319 sect_offset_str (per_cu
->sect_off
),
23320 per_objfile
->get_cu (per_cu
) != nullptr);
23322 /* If necessary, add it to the queue and load its DIEs.
23324 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23325 it doesn't mean they are currently loaded. Since we require them
23326 to be loaded, we must check for ourselves. */
23327 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23328 || per_objfile
->get_cu (per_cu
) == nullptr)
23329 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23330 false, cu
->per_cu
->lang
);
23332 target_cu
= per_objfile
->get_cu (per_cu
);
23333 gdb_assert (target_cu
!= nullptr);
23335 else if (cu
->dies
== NULL
)
23337 /* We're loading full DIEs during partial symbol reading. */
23338 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23339 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23343 *ref_cu
= target_cu
;
23344 temp_die
.sect_off
= sect_off
;
23346 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23348 to_underlying (sect_off
));
23351 /* Follow reference attribute ATTR of SRC_DIE.
23352 On entry *REF_CU is the CU of SRC_DIE.
23353 On exit *REF_CU is the CU of the result. */
23355 static struct die_info
*
23356 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23357 struct dwarf2_cu
**ref_cu
)
23359 sect_offset sect_off
= attr
->get_ref_die_offset ();
23360 struct dwarf2_cu
*cu
= *ref_cu
;
23361 struct die_info
*die
;
23363 die
= follow_die_offset (sect_off
,
23364 (attr
->form
== DW_FORM_GNU_ref_alt
23365 || cu
->per_cu
->is_dwz
),
23368 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23369 "at %s [in module %s]"),
23370 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23371 objfile_name (cu
->per_objfile
->objfile
));
23378 struct dwarf2_locexpr_baton
23379 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23380 dwarf2_per_cu_data
*per_cu
,
23381 dwarf2_per_objfile
*per_objfile
,
23382 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23383 bool resolve_abstract_p
)
23385 struct die_info
*die
;
23386 struct attribute
*attr
;
23387 struct dwarf2_locexpr_baton retval
;
23388 struct objfile
*objfile
= per_objfile
->objfile
;
23390 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23392 cu
= load_cu (per_cu
, per_objfile
, false);
23396 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23397 Instead just throw an error, not much else we can do. */
23398 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23399 sect_offset_str (sect_off
), objfile_name (objfile
));
23402 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23404 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23405 sect_offset_str (sect_off
), objfile_name (objfile
));
23407 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23408 if (!attr
&& resolve_abstract_p
23409 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23410 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23412 CORE_ADDR pc
= get_frame_pc ();
23413 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23414 struct gdbarch
*gdbarch
= objfile
->arch ();
23416 for (const auto &cand_off
23417 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23419 struct dwarf2_cu
*cand_cu
= cu
;
23420 struct die_info
*cand
23421 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23424 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23427 CORE_ADDR pc_low
, pc_high
;
23428 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23429 if (pc_low
== ((CORE_ADDR
) -1))
23431 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23432 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23433 if (!(pc_low
<= pc
&& pc
< pc_high
))
23437 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23444 /* DWARF: "If there is no such attribute, then there is no effect.".
23445 DATA is ignored if SIZE is 0. */
23447 retval
.data
= NULL
;
23450 else if (attr
->form_is_section_offset ())
23452 struct dwarf2_loclist_baton loclist_baton
;
23453 CORE_ADDR pc
= get_frame_pc ();
23456 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23458 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23460 retval
.size
= size
;
23464 if (!attr
->form_is_block ())
23465 error (_("Dwarf Error: DIE at %s referenced in module %s "
23466 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23467 sect_offset_str (sect_off
), objfile_name (objfile
));
23469 struct dwarf_block
*block
= attr
->as_block ();
23470 retval
.data
= block
->data
;
23471 retval
.size
= block
->size
;
23473 retval
.per_objfile
= per_objfile
;
23474 retval
.per_cu
= cu
->per_cu
;
23476 per_objfile
->age_comp_units ();
23483 struct dwarf2_locexpr_baton
23484 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23485 dwarf2_per_cu_data
*per_cu
,
23486 dwarf2_per_objfile
*per_objfile
,
23487 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23489 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23491 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23495 /* Write a constant of a given type as target-ordered bytes into
23498 static const gdb_byte
*
23499 write_constant_as_bytes (struct obstack
*obstack
,
23500 enum bfd_endian byte_order
,
23507 *len
= TYPE_LENGTH (type
);
23508 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23509 store_unsigned_integer (result
, *len
, byte_order
, value
);
23517 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23518 dwarf2_per_cu_data
*per_cu
,
23519 dwarf2_per_objfile
*per_objfile
,
23523 struct die_info
*die
;
23524 struct attribute
*attr
;
23525 const gdb_byte
*result
= NULL
;
23528 enum bfd_endian byte_order
;
23529 struct objfile
*objfile
= per_objfile
->objfile
;
23531 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23533 cu
= load_cu (per_cu
, per_objfile
, false);
23537 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23538 Instead just throw an error, not much else we can do. */
23539 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23540 sect_offset_str (sect_off
), objfile_name (objfile
));
23543 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23545 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23546 sect_offset_str (sect_off
), objfile_name (objfile
));
23548 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23552 byte_order
= (bfd_big_endian (objfile
->obfd
)
23553 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23555 switch (attr
->form
)
23558 case DW_FORM_addrx
:
23559 case DW_FORM_GNU_addr_index
:
23563 *len
= cu
->header
.addr_size
;
23564 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23565 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23569 case DW_FORM_string
:
23572 case DW_FORM_GNU_str_index
:
23573 case DW_FORM_GNU_strp_alt
:
23574 /* The string is already allocated on the objfile obstack, point
23577 const char *attr_name
= attr
->as_string ();
23578 result
= (const gdb_byte
*) attr_name
;
23579 *len
= strlen (attr_name
);
23582 case DW_FORM_block1
:
23583 case DW_FORM_block2
:
23584 case DW_FORM_block4
:
23585 case DW_FORM_block
:
23586 case DW_FORM_exprloc
:
23587 case DW_FORM_data16
:
23589 struct dwarf_block
*block
= attr
->as_block ();
23590 result
= block
->data
;
23591 *len
= block
->size
;
23595 /* The DW_AT_const_value attributes are supposed to carry the
23596 symbol's value "represented as it would be on the target
23597 architecture." By the time we get here, it's already been
23598 converted to host endianness, so we just need to sign- or
23599 zero-extend it as appropriate. */
23600 case DW_FORM_data1
:
23601 type
= die_type (die
, cu
);
23602 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23603 if (result
== NULL
)
23604 result
= write_constant_as_bytes (obstack
, byte_order
,
23607 case DW_FORM_data2
:
23608 type
= die_type (die
, cu
);
23609 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23610 if (result
== NULL
)
23611 result
= write_constant_as_bytes (obstack
, byte_order
,
23614 case DW_FORM_data4
:
23615 type
= die_type (die
, cu
);
23616 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23617 if (result
== NULL
)
23618 result
= write_constant_as_bytes (obstack
, byte_order
,
23621 case DW_FORM_data8
:
23622 type
= die_type (die
, cu
);
23623 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23624 if (result
== NULL
)
23625 result
= write_constant_as_bytes (obstack
, byte_order
,
23629 case DW_FORM_sdata
:
23630 case DW_FORM_implicit_const
:
23631 type
= die_type (die
, cu
);
23632 result
= write_constant_as_bytes (obstack
, byte_order
,
23633 type
, attr
->as_signed (), len
);
23636 case DW_FORM_udata
:
23637 type
= die_type (die
, cu
);
23638 result
= write_constant_as_bytes (obstack
, byte_order
,
23639 type
, attr
->as_unsigned (), len
);
23643 complaint (_("unsupported const value attribute form: '%s'"),
23644 dwarf_form_name (attr
->form
));
23654 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23655 dwarf2_per_cu_data
*per_cu
,
23656 dwarf2_per_objfile
*per_objfile
,
23657 const char **var_name
)
23659 struct die_info
*die
;
23661 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23663 cu
= load_cu (per_cu
, per_objfile
, false);
23668 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23672 if (var_name
!= nullptr)
23673 *var_name
= var_decl_name (die
, cu
);
23674 return die_type (die
, cu
);
23680 dwarf2_get_die_type (cu_offset die_offset
,
23681 dwarf2_per_cu_data
*per_cu
,
23682 dwarf2_per_objfile
*per_objfile
)
23684 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23685 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23688 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23689 On entry *REF_CU is the CU of SRC_DIE.
23690 On exit *REF_CU is the CU of the result.
23691 Returns NULL if the referenced DIE isn't found. */
23693 static struct die_info
*
23694 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23695 struct dwarf2_cu
**ref_cu
)
23697 struct die_info temp_die
;
23698 struct dwarf2_cu
*sig_cu
;
23699 struct die_info
*die
;
23700 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23703 /* While it might be nice to assert sig_type->type == NULL here,
23704 we can get here for DW_AT_imported_declaration where we need
23705 the DIE not the type. */
23707 /* If necessary, add it to the queue and load its DIEs.
23709 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23710 it doesn't mean they are currently loaded. Since we require them
23711 to be loaded, we must check for ourselves. */
23712 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23714 || per_objfile
->get_cu (sig_type
) == nullptr)
23715 read_signatured_type (sig_type
, per_objfile
);
23717 sig_cu
= per_objfile
->get_cu (sig_type
);
23718 gdb_assert (sig_cu
!= NULL
);
23719 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23720 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23721 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23722 to_underlying (temp_die
.sect_off
));
23725 /* For .gdb_index version 7 keep track of included TUs.
23726 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23727 if (per_objfile
->per_bfd
->index_table
!= NULL
23728 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23730 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23740 /* Follow signatured type referenced by ATTR in SRC_DIE.
23741 On entry *REF_CU is the CU of SRC_DIE.
23742 On exit *REF_CU is the CU of the result.
23743 The result is the DIE of the type.
23744 If the referenced type cannot be found an error is thrown. */
23746 static struct die_info
*
23747 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23748 struct dwarf2_cu
**ref_cu
)
23750 ULONGEST signature
= attr
->as_signature ();
23751 struct signatured_type
*sig_type
;
23752 struct die_info
*die
;
23754 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23756 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23757 /* sig_type will be NULL if the signatured type is missing from
23759 if (sig_type
== NULL
)
23761 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23762 " from DIE at %s [in module %s]"),
23763 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23764 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23767 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23770 dump_die_for_error (src_die
);
23771 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23772 " from DIE at %s [in module %s]"),
23773 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23774 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23780 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23781 reading in and processing the type unit if necessary. */
23783 static struct type
*
23784 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23785 struct dwarf2_cu
*cu
)
23787 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23788 struct signatured_type
*sig_type
;
23789 struct dwarf2_cu
*type_cu
;
23790 struct die_info
*type_die
;
23793 sig_type
= lookup_signatured_type (cu
, signature
);
23794 /* sig_type will be NULL if the signatured type is missing from
23796 if (sig_type
== NULL
)
23798 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23799 " from DIE at %s [in module %s]"),
23800 hex_string (signature
), sect_offset_str (die
->sect_off
),
23801 objfile_name (per_objfile
->objfile
));
23802 return build_error_marker_type (cu
, die
);
23805 /* If we already know the type we're done. */
23806 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23807 if (type
!= nullptr)
23811 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23812 if (type_die
!= NULL
)
23814 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23815 is created. This is important, for example, because for c++ classes
23816 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23817 type
= read_type_die (type_die
, type_cu
);
23820 complaint (_("Dwarf Error: Cannot build signatured type %s"
23821 " referenced from DIE at %s [in module %s]"),
23822 hex_string (signature
), sect_offset_str (die
->sect_off
),
23823 objfile_name (per_objfile
->objfile
));
23824 type
= build_error_marker_type (cu
, die
);
23829 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23830 " from DIE at %s [in module %s]"),
23831 hex_string (signature
), sect_offset_str (die
->sect_off
),
23832 objfile_name (per_objfile
->objfile
));
23833 type
= build_error_marker_type (cu
, die
);
23836 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23841 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23842 reading in and processing the type unit if necessary. */
23844 static struct type
*
23845 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23846 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23848 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23849 if (attr
->form_is_ref ())
23851 struct dwarf2_cu
*type_cu
= cu
;
23852 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23854 return read_type_die (type_die
, type_cu
);
23856 else if (attr
->form
== DW_FORM_ref_sig8
)
23858 return get_signatured_type (die
, attr
->as_signature (), cu
);
23862 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23864 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23865 " at %s [in module %s]"),
23866 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23867 objfile_name (per_objfile
->objfile
));
23868 return build_error_marker_type (cu
, die
);
23872 /* Load the DIEs associated with type unit PER_CU into memory. */
23875 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23876 dwarf2_per_objfile
*per_objfile
)
23878 struct signatured_type
*sig_type
;
23880 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23881 gdb_assert (! per_cu
->type_unit_group_p ());
23883 /* We have the per_cu, but we need the signatured_type.
23884 Fortunately this is an easy translation. */
23885 gdb_assert (per_cu
->is_debug_types
);
23886 sig_type
= (struct signatured_type
*) per_cu
;
23888 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23890 read_signatured_type (sig_type
, per_objfile
);
23892 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23895 /* Read in a signatured type and build its CU and DIEs.
23896 If the type is a stub for the real type in a DWO file,
23897 read in the real type from the DWO file as well. */
23900 read_signatured_type (signatured_type
*sig_type
,
23901 dwarf2_per_objfile
*per_objfile
)
23903 gdb_assert (sig_type
->is_debug_types
);
23904 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23906 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23908 if (!reader
.dummy_p
)
23910 struct dwarf2_cu
*cu
= reader
.cu
;
23911 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23913 gdb_assert (cu
->die_hash
== NULL
);
23915 htab_create_alloc_ex (cu
->header
.length
/ 12,
23919 &cu
->comp_unit_obstack
,
23920 hashtab_obstack_allocate
,
23921 dummy_obstack_deallocate
);
23923 if (reader
.comp_unit_die
->has_children
)
23924 reader
.comp_unit_die
->child
23925 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23926 reader
.comp_unit_die
);
23927 cu
->dies
= reader
.comp_unit_die
;
23928 /* comp_unit_die is not stored in die_hash, no need. */
23930 /* We try not to read any attributes in this function, because
23931 not all CUs needed for references have been loaded yet, and
23932 symbol table processing isn't initialized. But we have to
23933 set the CU language, or we won't be able to build types
23934 correctly. Similarly, if we do not read the producer, we can
23935 not apply producer-specific interpretation. */
23936 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23941 sig_type
->tu_read
= 1;
23944 /* Decode simple location descriptions.
23945 Given a pointer to a dwarf block that defines a location, compute
23946 the location and return the value. If COMPUTED is non-null, it is
23947 set to true to indicate that decoding was successful, and false
23948 otherwise. If COMPUTED is null, then this function may emit a
23952 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23954 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23956 size_t size
= blk
->size
;
23957 const gdb_byte
*data
= blk
->data
;
23958 CORE_ADDR stack
[64];
23960 unsigned int bytes_read
, unsnd
;
23963 if (computed
!= nullptr)
23969 stack
[++stacki
] = 0;
24008 stack
[++stacki
] = op
- DW_OP_lit0
;
24043 stack
[++stacki
] = op
- DW_OP_reg0
;
24046 if (computed
== nullptr)
24047 dwarf2_complex_location_expr_complaint ();
24054 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24056 stack
[++stacki
] = unsnd
;
24059 if (computed
== nullptr)
24060 dwarf2_complex_location_expr_complaint ();
24067 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24072 case DW_OP_const1u
:
24073 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24077 case DW_OP_const1s
:
24078 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24082 case DW_OP_const2u
:
24083 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24087 case DW_OP_const2s
:
24088 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24092 case DW_OP_const4u
:
24093 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24097 case DW_OP_const4s
:
24098 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24102 case DW_OP_const8u
:
24103 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24108 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24114 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24119 stack
[stacki
+ 1] = stack
[stacki
];
24124 stack
[stacki
- 1] += stack
[stacki
];
24128 case DW_OP_plus_uconst
:
24129 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24135 stack
[stacki
- 1] -= stack
[stacki
];
24140 /* If we're not the last op, then we definitely can't encode
24141 this using GDB's address_class enum. This is valid for partial
24142 global symbols, although the variable's address will be bogus
24146 if (computed
== nullptr)
24147 dwarf2_complex_location_expr_complaint ();
24153 case DW_OP_GNU_push_tls_address
:
24154 case DW_OP_form_tls_address
:
24155 /* The top of the stack has the offset from the beginning
24156 of the thread control block at which the variable is located. */
24157 /* Nothing should follow this operator, so the top of stack would
24159 /* This is valid for partial global symbols, but the variable's
24160 address will be bogus in the psymtab. Make it always at least
24161 non-zero to not look as a variable garbage collected by linker
24162 which have DW_OP_addr 0. */
24165 if (computed
== nullptr)
24166 dwarf2_complex_location_expr_complaint ();
24173 case DW_OP_GNU_uninit
:
24174 if (computed
!= nullptr)
24179 case DW_OP_GNU_addr_index
:
24180 case DW_OP_GNU_const_index
:
24181 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24187 if (computed
== nullptr)
24189 const char *name
= get_DW_OP_name (op
);
24192 complaint (_("unsupported stack op: '%s'"),
24195 complaint (_("unsupported stack op: '%02x'"),
24199 return (stack
[stacki
]);
24202 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24203 outside of the allocated space. Also enforce minimum>0. */
24204 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24206 if (computed
== nullptr)
24207 complaint (_("location description stack overflow"));
24213 if (computed
== nullptr)
24214 complaint (_("location description stack underflow"));
24219 if (computed
!= nullptr)
24221 return (stack
[stacki
]);
24224 /* memory allocation interface */
24226 static struct dwarf_block
*
24227 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24229 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24232 static struct die_info
*
24233 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24235 struct die_info
*die
;
24236 size_t size
= sizeof (struct die_info
);
24239 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24241 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24242 memset (die
, 0, sizeof (struct die_info
));
24248 /* Macro support. */
24250 /* An overload of dwarf_decode_macros that finds the correct section
24251 and ensures it is read in before calling the other overload. */
24254 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24255 int section_is_gnu
)
24257 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24258 struct objfile
*objfile
= per_objfile
->objfile
;
24259 const struct line_header
*lh
= cu
->line_header
;
24260 unsigned int offset_size
= cu
->header
.offset_size
;
24261 struct dwarf2_section_info
*section
;
24262 const char *section_name
;
24264 if (cu
->dwo_unit
!= nullptr)
24266 if (section_is_gnu
)
24268 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24269 section_name
= ".debug_macro.dwo";
24273 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24274 section_name
= ".debug_macinfo.dwo";
24279 if (section_is_gnu
)
24281 section
= &per_objfile
->per_bfd
->macro
;
24282 section_name
= ".debug_macro";
24286 section
= &per_objfile
->per_bfd
->macinfo
;
24287 section_name
= ".debug_macinfo";
24291 section
->read (objfile
);
24292 if (section
->buffer
== nullptr)
24294 complaint (_("missing %s section"), section_name
);
24298 buildsym_compunit
*builder
= cu
->get_builder ();
24300 struct dwarf2_section_info
*str_offsets_section
;
24301 struct dwarf2_section_info
*str_section
;
24302 gdb::optional
<ULONGEST
> str_offsets_base
;
24304 if (cu
->dwo_unit
!= nullptr)
24306 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24307 ->sections
.str_offsets
;
24308 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24309 str_offsets_base
= cu
->header
.addr_size
;
24313 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24314 str_section
= &per_objfile
->per_bfd
->str
;
24315 str_offsets_base
= cu
->str_offsets_base
;
24318 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24319 offset_size
, offset
, str_section
, str_offsets_section
,
24320 str_offsets_base
, section_is_gnu
);
24323 /* Return the .debug_loc section to use for CU.
24324 For DWO files use .debug_loc.dwo. */
24326 static struct dwarf2_section_info
*
24327 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24329 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24333 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24335 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24337 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24338 : &per_objfile
->per_bfd
->loc
);
24341 /* Return the .debug_rnglists section to use for CU. */
24342 static struct dwarf2_section_info
*
24343 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24345 if (cu
->header
.version
< 5)
24346 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24347 cu
->header
.version
);
24348 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24350 /* Make sure we read the .debug_rnglists section from the file that
24351 contains the DW_AT_ranges attribute we are reading. Normally that
24352 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24353 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24355 if (cu
->dwo_unit
!= nullptr
24356 && tag
!= DW_TAG_compile_unit
24357 && tag
!= DW_TAG_skeleton_unit
)
24359 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24361 if (sections
->rnglists
.size
> 0)
24362 return §ions
->rnglists
;
24364 error (_(".debug_rnglists section is missing from .dwo file."));
24366 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24369 /* A helper function that fills in a dwarf2_loclist_baton. */
24372 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24373 struct dwarf2_loclist_baton
*baton
,
24374 const struct attribute
*attr
)
24376 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24377 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24379 section
->read (per_objfile
->objfile
);
24381 baton
->per_objfile
= per_objfile
;
24382 baton
->per_cu
= cu
->per_cu
;
24383 gdb_assert (baton
->per_cu
);
24384 /* We don't know how long the location list is, but make sure we
24385 don't run off the edge of the section. */
24386 baton
->size
= section
->size
- attr
->as_unsigned ();
24387 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24388 if (cu
->base_address
.has_value ())
24389 baton
->base_address
= *cu
->base_address
;
24391 baton
->base_address
= 0;
24392 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24396 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24397 struct dwarf2_cu
*cu
, int is_block
)
24399 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24400 struct objfile
*objfile
= per_objfile
->objfile
;
24401 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24403 if (attr
->form_is_section_offset ()
24404 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24405 the section. If so, fall through to the complaint in the
24407 && attr
->as_unsigned () < section
->get_size (objfile
))
24409 struct dwarf2_loclist_baton
*baton
;
24411 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24413 fill_in_loclist_baton (cu
, baton
, attr
);
24415 if (!cu
->base_address
.has_value ())
24416 complaint (_("Location list used without "
24417 "specifying the CU base address."));
24419 sym
->set_aclass_index ((is_block
24420 ? dwarf2_loclist_block_index
24421 : dwarf2_loclist_index
));
24422 SYMBOL_LOCATION_BATON (sym
) = baton
;
24426 struct dwarf2_locexpr_baton
*baton
;
24428 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24429 baton
->per_objfile
= per_objfile
;
24430 baton
->per_cu
= cu
->per_cu
;
24431 gdb_assert (baton
->per_cu
);
24433 if (attr
->form_is_block ())
24435 /* Note that we're just copying the block's data pointer
24436 here, not the actual data. We're still pointing into the
24437 info_buffer for SYM's objfile; right now we never release
24438 that buffer, but when we do clean up properly this may
24440 struct dwarf_block
*block
= attr
->as_block ();
24441 baton
->size
= block
->size
;
24442 baton
->data
= block
->data
;
24446 dwarf2_invalid_attrib_class_complaint ("location description",
24447 sym
->natural_name ());
24451 sym
->set_aclass_index ((is_block
24452 ? dwarf2_locexpr_block_index
24453 : dwarf2_locexpr_index
));
24454 SYMBOL_LOCATION_BATON (sym
) = baton
;
24460 const comp_unit_head
*
24461 dwarf2_per_cu_data::get_header () const
24463 if (!m_header_read_in
)
24465 const gdb_byte
*info_ptr
24466 = this->section
->buffer
+ to_underlying (this->sect_off
);
24468 memset (&m_header
, 0, sizeof (m_header
));
24470 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24471 rcuh_kind::COMPILE
);
24473 m_header_read_in
= true;
24482 dwarf2_per_cu_data::addr_size () const
24484 return this->get_header ()->addr_size
;
24490 dwarf2_per_cu_data::offset_size () const
24492 return this->get_header ()->offset_size
;
24498 dwarf2_per_cu_data::ref_addr_size () const
24500 const comp_unit_head
*header
= this->get_header ();
24502 if (header
->version
== 2)
24503 return header
->addr_size
;
24505 return header
->offset_size
;
24508 /* A helper function for dwarf2_find_containing_comp_unit that returns
24509 the index of the result, and that searches a vector. It will
24510 return a result even if the offset in question does not actually
24511 occur in any CU. This is separate so that it can be unit
24515 dwarf2_find_containing_comp_unit
24516 (sect_offset sect_off
,
24517 unsigned int offset_in_dwz
,
24518 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24523 high
= all_comp_units
.size () - 1;
24526 struct dwarf2_per_cu_data
*mid_cu
;
24527 int mid
= low
+ (high
- low
) / 2;
24529 mid_cu
= all_comp_units
[mid
].get ();
24530 if (mid_cu
->is_dwz
> offset_in_dwz
24531 || (mid_cu
->is_dwz
== offset_in_dwz
24532 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24537 gdb_assert (low
== high
);
24541 /* Locate the .debug_info compilation unit from CU's objfile which contains
24542 the DIE at OFFSET. Raises an error on failure. */
24544 static struct dwarf2_per_cu_data
*
24545 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24546 unsigned int offset_in_dwz
,
24547 dwarf2_per_bfd
*per_bfd
)
24549 int low
= dwarf2_find_containing_comp_unit
24550 (sect_off
, offset_in_dwz
, per_bfd
->all_comp_units
);
24551 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_comp_units
[low
].get ();
24553 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24555 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24556 error (_("Dwarf Error: could not find partial DIE containing "
24557 "offset %s [in module %s]"),
24558 sect_offset_str (sect_off
),
24559 bfd_get_filename (per_bfd
->obfd
));
24561 gdb_assert (per_bfd
->all_comp_units
[low
-1]->sect_off
24563 return per_bfd
->all_comp_units
[low
- 1].get ();
24567 if (low
== per_bfd
->all_comp_units
.size () - 1
24568 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24569 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24570 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24577 namespace selftests
{
24578 namespace find_containing_comp_unit
{
24583 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24584 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24585 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24586 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24587 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24588 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24589 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24590 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24593 two
->sect_off
= sect_offset (one
->length
);
24598 four
->sect_off
= sect_offset (three
->length
);
24602 std::vector
<dwarf2_per_cu_data_up
> units
;
24603 units
.push_back (std::move (one
));
24604 units
.push_back (std::move (two
));
24605 units
.push_back (std::move (three
));
24606 units
.push_back (std::move (four
));
24610 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24611 SELF_CHECK (units
[result
].get () == one_ptr
);
24612 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24613 SELF_CHECK (units
[result
].get () == one_ptr
);
24614 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24615 SELF_CHECK (units
[result
].get () == two_ptr
);
24617 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24618 SELF_CHECK (units
[result
].get () == three_ptr
);
24619 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24620 SELF_CHECK (units
[result
].get () == three_ptr
);
24621 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24622 SELF_CHECK (units
[result
].get () == four_ptr
);
24628 #endif /* GDB_SELF_TEST */
24630 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24633 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24634 enum language pretend_language
)
24636 struct attribute
*attr
;
24638 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24640 /* Set the language we're debugging. */
24641 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24642 if (cu
->producer
!= nullptr
24643 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24645 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24646 attribute is not standardised yet. As a workaround for the
24647 language detection we fall back to the DW_AT_producer
24649 cu
->per_cu
->lang
= language_opencl
;
24651 else if (cu
->producer
!= nullptr
24652 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24654 /* Similar hack for Go. */
24655 cu
->per_cu
->lang
= language_go
;
24657 else if (attr
!= nullptr)
24658 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24660 cu
->per_cu
->lang
= pretend_language
;
24661 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24667 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24669 auto it
= m_dwarf2_cus
.find (per_cu
);
24670 if (it
== m_dwarf2_cus
.end ())
24679 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24681 gdb_assert (this->get_cu (per_cu
) == nullptr);
24683 m_dwarf2_cus
[per_cu
] = cu
;
24689 dwarf2_per_objfile::age_comp_units ()
24691 dwarf_read_debug_printf_v ("running");
24693 /* This is not expected to be called in the middle of CU expansion. There is
24694 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24695 loaded in memory. Calling age_comp_units while the queue is in use could
24696 make us free the DIEs for a CU that is in the queue and therefore break
24698 gdb_assert (!this->per_bfd
->queue
.has_value ());
24700 /* Start by clearing all marks. */
24701 for (auto pair
: m_dwarf2_cus
)
24702 pair
.second
->clear_mark ();
24704 /* Traverse all CUs, mark them and their dependencies if used recently
24706 for (auto pair
: m_dwarf2_cus
)
24708 dwarf2_cu
*cu
= pair
.second
;
24711 if (cu
->last_used
<= dwarf_max_cache_age
)
24715 /* Delete all CUs still not marked. */
24716 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24718 dwarf2_cu
*cu
= it
->second
;
24720 if (!cu
->is_marked ())
24722 dwarf_read_debug_printf_v ("deleting old CU %s",
24723 sect_offset_str (cu
->per_cu
->sect_off
));
24725 it
= m_dwarf2_cus
.erase (it
);
24735 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24737 auto it
= m_dwarf2_cus
.find (per_cu
);
24738 if (it
== m_dwarf2_cus
.end ())
24743 m_dwarf2_cus
.erase (it
);
24746 dwarf2_per_objfile::~dwarf2_per_objfile ()
24751 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24752 We store these in a hash table separate from the DIEs, and preserve them
24753 when the DIEs are flushed out of cache.
24755 The CU "per_cu" pointer is needed because offset alone is not enough to
24756 uniquely identify the type. A file may have multiple .debug_types sections,
24757 or the type may come from a DWO file. Furthermore, while it's more logical
24758 to use per_cu->section+offset, with Fission the section with the data is in
24759 the DWO file but we don't know that section at the point we need it.
24760 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24761 because we can enter the lookup routine, get_die_type_at_offset, from
24762 outside this file, and thus won't necessarily have PER_CU->cu.
24763 Fortunately, PER_CU is stable for the life of the objfile. */
24765 struct dwarf2_per_cu_offset_and_type
24767 const struct dwarf2_per_cu_data
*per_cu
;
24768 sect_offset sect_off
;
24772 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24775 per_cu_offset_and_type_hash (const void *item
)
24777 const struct dwarf2_per_cu_offset_and_type
*ofs
24778 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24780 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24783 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24786 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24788 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24789 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24790 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24791 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24793 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24794 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24797 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24798 table if necessary. For convenience, return TYPE.
24800 The DIEs reading must have careful ordering to:
24801 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24802 reading current DIE.
24803 * Not trying to dereference contents of still incompletely read in types
24804 while reading in other DIEs.
24805 * Enable referencing still incompletely read in types just by a pointer to
24806 the type without accessing its fields.
24808 Therefore caller should follow these rules:
24809 * Try to fetch any prerequisite types we may need to build this DIE type
24810 before building the type and calling set_die_type.
24811 * After building type call set_die_type for current DIE as soon as
24812 possible before fetching more types to complete the current type.
24813 * Make the type as complete as possible before fetching more types. */
24815 static struct type
*
24816 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24817 bool skip_data_location
)
24819 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24820 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24821 struct objfile
*objfile
= per_objfile
->objfile
;
24822 struct attribute
*attr
;
24823 struct dynamic_prop prop
;
24825 /* For Ada types, make sure that the gnat-specific data is always
24826 initialized (if not already set). There are a few types where
24827 we should not be doing so, because the type-specific area is
24828 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24829 where the type-specific area is used to store the floatformat).
24830 But this is not a problem, because the gnat-specific information
24831 is actually not needed for these types. */
24832 if (need_gnat_info (cu
)
24833 && type
->code () != TYPE_CODE_FUNC
24834 && type
->code () != TYPE_CODE_FLT
24835 && type
->code () != TYPE_CODE_METHODPTR
24836 && type
->code () != TYPE_CODE_MEMBERPTR
24837 && type
->code () != TYPE_CODE_METHOD
24838 && type
->code () != TYPE_CODE_FIXED_POINT
24839 && !HAVE_GNAT_AUX_INFO (type
))
24840 INIT_GNAT_SPECIFIC (type
);
24842 /* Read DW_AT_allocated and set in type. */
24843 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24846 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24847 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24848 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24851 /* Read DW_AT_associated and set in type. */
24852 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24855 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24856 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24857 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24860 /* Read DW_AT_rank and set in type. */
24861 attr
= dwarf2_attr (die
, DW_AT_rank
, cu
);
24864 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24865 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24866 type
->add_dyn_prop (DYN_PROP_RANK
, prop
);
24869 /* Read DW_AT_data_location and set in type. */
24870 if (!skip_data_location
)
24872 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24873 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24874 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24877 if (per_objfile
->die_type_hash
== NULL
)
24878 per_objfile
->die_type_hash
24879 = htab_up (htab_create_alloc (127,
24880 per_cu_offset_and_type_hash
,
24881 per_cu_offset_and_type_eq
,
24882 NULL
, xcalloc
, xfree
));
24884 ofs
.per_cu
= cu
->per_cu
;
24885 ofs
.sect_off
= die
->sect_off
;
24887 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24888 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24890 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24891 sect_offset_str (die
->sect_off
));
24892 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24893 struct dwarf2_per_cu_offset_and_type
);
24898 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24899 or return NULL if the die does not have a saved type. */
24901 static struct type
*
24902 get_die_type_at_offset (sect_offset sect_off
,
24903 dwarf2_per_cu_data
*per_cu
,
24904 dwarf2_per_objfile
*per_objfile
)
24906 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24908 if (per_objfile
->die_type_hash
== NULL
)
24911 ofs
.per_cu
= per_cu
;
24912 ofs
.sect_off
= sect_off
;
24913 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24914 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24921 /* Look up the type for DIE in CU in die_type_hash,
24922 or return NULL if DIE does not have a saved type. */
24924 static struct type
*
24925 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24927 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24930 /* Trivial hash function for partial_die_info: the hash value of a DIE
24931 is its offset in .debug_info for this objfile. */
24934 partial_die_hash (const void *item
)
24936 const struct partial_die_info
*part_die
24937 = (const struct partial_die_info
*) item
;
24939 return to_underlying (part_die
->sect_off
);
24942 /* Trivial comparison function for partial_die_info structures: two DIEs
24943 are equal if they have the same offset. */
24946 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24948 const struct partial_die_info
*part_die_lhs
24949 = (const struct partial_die_info
*) item_lhs
;
24950 const struct partial_die_info
*part_die_rhs
24951 = (const struct partial_die_info
*) item_rhs
;
24953 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24956 struct cmd_list_element
*set_dwarf_cmdlist
;
24957 struct cmd_list_element
*show_dwarf_cmdlist
;
24960 show_check_physname (struct ui_file
*file
, int from_tty
,
24961 struct cmd_list_element
*c
, const char *value
)
24964 _("Whether to check \"physname\" is %s.\n"),
24968 void _initialize_dwarf2_read ();
24970 _initialize_dwarf2_read ()
24972 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
24974 Set DWARF specific variables.\n\
24975 Configure DWARF variables such as the cache size."),
24977 Show DWARF specific variables.\n\
24978 Show DWARF variables such as the cache size."),
24979 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
24980 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
24982 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24983 &dwarf_max_cache_age
, _("\
24984 Set the upper bound on the age of cached DWARF compilation units."), _("\
24985 Show the upper bound on the age of cached DWARF compilation units."), _("\
24986 A higher limit means that cached compilation units will be stored\n\
24987 in memory longer, and more total memory will be used. Zero disables\n\
24988 caching, which can slow down startup."),
24990 show_dwarf_max_cache_age
,
24991 &set_dwarf_cmdlist
,
24992 &show_dwarf_cmdlist
);
24994 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24995 Set debugging of the DWARF reader."), _("\
24996 Show debugging of the DWARF reader."), _("\
24997 When enabled (non-zero), debugging messages are printed during DWARF\n\
24998 reading and symtab expansion. A value of 1 (one) provides basic\n\
24999 information. A value greater than 1 provides more verbose information."),
25002 &setdebuglist
, &showdebuglist
);
25004 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25005 Set debugging of the DWARF DIE reader."), _("\
25006 Show debugging of the DWARF DIE reader."), _("\
25007 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25008 The value is the maximum depth to print."),
25011 &setdebuglist
, &showdebuglist
);
25013 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25014 Set debugging of the dwarf line reader."), _("\
25015 Show debugging of the dwarf line reader."), _("\
25016 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25017 A value of 1 (one) provides basic information.\n\
25018 A value greater than 1 provides more verbose information."),
25021 &setdebuglist
, &showdebuglist
);
25023 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25024 Set cross-checking of \"physname\" code against demangler."), _("\
25025 Show cross-checking of \"physname\" code against demangler."), _("\
25026 When enabled, GDB's internal \"physname\" code is checked against\n\
25028 NULL
, show_check_physname
,
25029 &setdebuglist
, &showdebuglist
);
25031 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25032 no_class
, &use_deprecated_index_sections
, _("\
25033 Set whether to use deprecated gdb_index sections."), _("\
25034 Show whether to use deprecated gdb_index sections."), _("\
25035 When enabled, deprecated .gdb_index sections are used anyway.\n\
25036 Normally they are ignored either because of a missing feature or\n\
25037 performance issue.\n\
25038 Warning: This option must be enabled before gdb reads the file."),
25041 &setlist
, &showlist
);
25043 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25044 &dwarf2_locexpr_funcs
);
25045 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25046 &dwarf2_loclist_funcs
);
25048 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25049 &dwarf2_block_frame_base_locexpr_funcs
);
25050 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25051 &dwarf2_block_frame_base_loclist_funcs
);
25054 selftests::register_test ("dw2_expand_symtabs_matching",
25055 selftests::dw2_expand_symtabs_matching::run_test
);
25056 selftests::register_test ("dwarf2_find_containing_comp_unit",
25057 selftests::find_containing_comp_unit::run_test
);