1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2022 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit-head.h"
36 #include "dwarf2/cu.h"
37 #include "dwarf2/index-cache.h"
38 #include "dwarf2/index-common.h"
39 #include "dwarf2/leb.h"
40 #include "dwarf2/line-header.h"
41 #include "dwarf2/dwz.h"
42 #include "dwarf2/macro.h"
43 #include "dwarf2/die.h"
44 #include "dwarf2/sect-names.h"
45 #include "dwarf2/stringify.h"
46 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
91 #include <unordered_set>
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
100 #define dwarf_read_debug_printf(fmt, ...) \
101 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
106 #define dwarf_read_debug_printf_v(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
110 /* When non-zero, dump DIEs after they are read in. */
111 static unsigned int dwarf_die_debug
= 0;
113 /* When non-zero, dump line number entries as they are read in. */
114 unsigned int dwarf_line_debug
= 0;
116 /* When true, cross-check physname against demangler. */
117 static bool check_physname
= false;
119 /* When true, do not reject deprecated .gdb_index sections. */
120 static bool use_deprecated_index_sections
= false;
122 /* This is used to store the data that is always per objfile. */
123 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
125 /* These are used to store the dwarf2_per_bfd objects.
127 objfiles having the same BFD, which doesn't require relocations, are going to
128 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
130 Other objfiles are not going to share a dwarf2_per_bfd with any other
131 objfiles, so they'll have their own version kept in the _objfile_data_key
133 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
134 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
136 /* The "aclass" indices for various kinds of computed DWARF symbols. */
138 static int dwarf2_locexpr_index
;
139 static int dwarf2_loclist_index
;
140 static int dwarf2_locexpr_block_index
;
141 static int dwarf2_loclist_block_index
;
143 /* Size of .debug_loclists section header for 32-bit DWARF format. */
144 #define LOCLIST_HEADER_SIZE32 12
146 /* Size of .debug_loclists section header for 64-bit DWARF format. */
147 #define LOCLIST_HEADER_SIZE64 20
149 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
150 #define RNGLIST_HEADER_SIZE32 12
152 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
153 #define RNGLIST_HEADER_SIZE64 20
155 /* An index into a (C++) symbol name component in a symbol name as
156 recorded in the mapped_index's symbol table. For each C++ symbol
157 in the symbol table, we record one entry for the start of each
158 component in the symbol in a table of name components, and then
159 sort the table, in order to be able to binary search symbol names,
160 ignoring leading namespaces, both completion and regular look up.
161 For example, for symbol "A::B::C", we'll have an entry that points
162 to "A::B::C", another that points to "B::C", and another for "C".
163 Note that function symbols in GDB index have no parameter
164 information, just the function/method names. You can convert a
165 name_component to a "const char *" using the
166 'mapped_index::symbol_name_at(offset_type)' method. */
168 struct name_component
170 /* Offset in the symbol name where the component starts. Stored as
171 a (32-bit) offset instead of a pointer to save memory and improve
172 locality on 64-bit architectures. */
173 offset_type name_offset
;
175 /* The symbol's index in the symbol and constant pool tables of a
180 /* Base class containing bits shared by both .gdb_index and
181 .debug_name indexes. */
183 struct mapped_index_base
185 mapped_index_base () = default;
186 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
188 /* The name_component table (a sorted vector). See name_component's
189 description above. */
190 std::vector
<name_component
> name_components
;
192 /* How NAME_COMPONENTS is sorted. */
193 enum case_sensitivity name_components_casing
;
195 /* Return the number of names in the symbol table. */
196 virtual size_t symbol_name_count () const = 0;
198 /* Get the name of the symbol at IDX in the symbol table. */
199 virtual const char *symbol_name_at
200 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
202 /* Return whether the name at IDX in the symbol table should be
204 virtual bool symbol_name_slot_invalid (offset_type idx
) const
209 /* Build the symbol name component sorted vector, if we haven't
211 void build_name_components (dwarf2_per_objfile
*per_objfile
);
213 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
214 possible matches for LN_NO_PARAMS in the name component
216 std::pair
<std::vector
<name_component
>::const_iterator
,
217 std::vector
<name_component
>::const_iterator
>
218 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
220 dwarf2_per_objfile
*per_objfile
) const;
222 /* Prevent deleting/destroying via a base class pointer. */
224 ~mapped_index_base() = default;
227 /* This is a view into the index that converts from bytes to an
228 offset_type, and allows indexing. Unaligned bytes are specifically
229 allowed here, and handled via unpacking. */
234 offset_view () = default;
236 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
241 /* Extract the INDEXth offset_type from the array. */
242 offset_type
operator[] (size_t index
) const
244 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
245 return (offset_type
) extract_unsigned_integer (bytes
,
246 sizeof (offset_type
),
250 /* Return the number of offset_types in this array. */
253 return m_bytes
.size () / sizeof (offset_type
);
256 /* Return true if this view is empty. */
259 return m_bytes
.empty ();
263 /* The underlying bytes. */
264 gdb::array_view
<const gdb_byte
> m_bytes
;
267 /* A description of the mapped index. The file format is described in
268 a comment by the code that writes the index. */
269 struct mapped_index final
: public mapped_index_base
271 /* Index data format version. */
274 /* The address table data. */
275 gdb::array_view
<const gdb_byte
> address_table
;
277 /* The symbol table, implemented as a hash table. */
278 offset_view symbol_table
;
280 /* A pointer to the constant pool. */
281 gdb::array_view
<const gdb_byte
> constant_pool
;
283 /* Return the index into the constant pool of the name of the IDXth
284 symbol in the symbol table. */
285 offset_type
symbol_name_index (offset_type idx
) const
287 return symbol_table
[2 * idx
];
290 /* Return the index into the constant pool of the CU vector of the
291 IDXth symbol in the symbol table. */
292 offset_type
symbol_vec_index (offset_type idx
) const
294 return symbol_table
[2 * idx
+ 1];
297 bool symbol_name_slot_invalid (offset_type idx
) const override
299 return (symbol_name_index (idx
) == 0
300 && symbol_vec_index (idx
) == 0);
303 /* Convenience method to get at the name of the symbol at IDX in the
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 return (const char *) (this->constant_pool
.data ()
309 + symbol_name_index (idx
));
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size () / 2; }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 bfd_endian dwarf5_byte_order
;
321 bool dwarf5_is_dwarf64
;
322 bool augmentation_is_gdb
;
324 uint32_t cu_count
= 0;
325 uint32_t tu_count
, bucket_count
, name_count
;
326 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
327 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
328 const gdb_byte
*name_table_string_offs_reordered
;
329 const gdb_byte
*name_table_entry_offs_reordered
;
330 const gdb_byte
*entry_pool
;
337 /* Attribute name DW_IDX_*. */
340 /* Attribute form DW_FORM_*. */
343 /* Value if FORM is DW_FORM_implicit_const. */
344 LONGEST implicit_const
;
346 std::vector
<attr
> attr_vec
;
349 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
351 const char *namei_to_name
352 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
354 /* Implementation of the mapped_index_base virtual interface, for
355 the name_components cache. */
357 const char *symbol_name_at
358 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
359 { return namei_to_name (idx
, per_objfile
); }
361 size_t symbol_name_count () const override
362 { return this->name_count
; }
365 /* See dwarf2read.h. */
368 get_dwarf2_per_objfile (struct objfile
*objfile
)
370 return dwarf2_objfile_data_key
.get (objfile
);
373 /* Default names of the debugging sections. */
375 /* Note that if the debugging section has been compressed, it might
376 have a name like .zdebug_info. */
378 const struct dwarf2_debug_sections dwarf2_elf_names
=
380 { ".debug_info", ".zdebug_info" },
381 { ".debug_abbrev", ".zdebug_abbrev" },
382 { ".debug_line", ".zdebug_line" },
383 { ".debug_loc", ".zdebug_loc" },
384 { ".debug_loclists", ".zdebug_loclists" },
385 { ".debug_macinfo", ".zdebug_macinfo" },
386 { ".debug_macro", ".zdebug_macro" },
387 { ".debug_str", ".zdebug_str" },
388 { ".debug_str_offsets", ".zdebug_str_offsets" },
389 { ".debug_line_str", ".zdebug_line_str" },
390 { ".debug_ranges", ".zdebug_ranges" },
391 { ".debug_rnglists", ".zdebug_rnglists" },
392 { ".debug_types", ".zdebug_types" },
393 { ".debug_addr", ".zdebug_addr" },
394 { ".debug_frame", ".zdebug_frame" },
395 { ".eh_frame", NULL
},
396 { ".gdb_index", ".zgdb_index" },
397 { ".debug_names", ".zdebug_names" },
398 { ".debug_aranges", ".zdebug_aranges" },
402 /* List of DWO/DWP sections. */
404 static const struct dwop_section_names
406 struct dwarf2_section_names abbrev_dwo
;
407 struct dwarf2_section_names info_dwo
;
408 struct dwarf2_section_names line_dwo
;
409 struct dwarf2_section_names loc_dwo
;
410 struct dwarf2_section_names loclists_dwo
;
411 struct dwarf2_section_names macinfo_dwo
;
412 struct dwarf2_section_names macro_dwo
;
413 struct dwarf2_section_names rnglists_dwo
;
414 struct dwarf2_section_names str_dwo
;
415 struct dwarf2_section_names str_offsets_dwo
;
416 struct dwarf2_section_names types_dwo
;
417 struct dwarf2_section_names cu_index
;
418 struct dwarf2_section_names tu_index
;
422 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
423 { ".debug_info.dwo", ".zdebug_info.dwo" },
424 { ".debug_line.dwo", ".zdebug_line.dwo" },
425 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
426 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
427 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
428 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
429 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
430 { ".debug_str.dwo", ".zdebug_str.dwo" },
431 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
432 { ".debug_types.dwo", ".zdebug_types.dwo" },
433 { ".debug_cu_index", ".zdebug_cu_index" },
434 { ".debug_tu_index", ".zdebug_tu_index" },
437 /* local data types */
439 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
440 begin with a header, which contains the following information. */
441 struct loclists_rnglists_header
443 /* A 4-byte or 12-byte length containing the length of the
444 set of entries for this compilation unit, not including the
445 length field itself. */
448 /* A 2-byte version identifier. */
451 /* A 1-byte unsigned integer containing the size in bytes of an address on
452 the target system. */
453 unsigned char addr_size
;
455 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
456 on the target system. */
457 unsigned char segment_collector_size
;
459 /* A 4-byte count of the number of offsets that follow the header. */
460 unsigned int offset_entry_count
;
463 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
464 This includes type_unit_group and quick_file_names. */
466 struct stmt_list_hash
468 /* The DWO unit this table is from or NULL if there is none. */
469 struct dwo_unit
*dwo_unit
;
471 /* Offset in .debug_line or .debug_line.dwo. */
472 sect_offset line_sect_off
;
475 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
476 an object of this type. This contains elements of type unit groups
477 that can be shared across objfiles. The non-shareable parts are in
478 type_unit_group_unshareable. */
480 struct type_unit_group
: public dwarf2_per_cu_data
482 /* The TUs that share this DW_AT_stmt_list entry.
483 This is added to while parsing type units to build partial symtabs,
484 and is deleted afterwards and not used again. */
485 std::vector
<signatured_type
*> *tus
= nullptr;
487 /* The data used to construct the hash key. */
488 struct stmt_list_hash hash
{};
491 /* These sections are what may appear in a (real or virtual) DWO file. */
495 struct dwarf2_section_info abbrev
;
496 struct dwarf2_section_info line
;
497 struct dwarf2_section_info loc
;
498 struct dwarf2_section_info loclists
;
499 struct dwarf2_section_info macinfo
;
500 struct dwarf2_section_info macro
;
501 struct dwarf2_section_info rnglists
;
502 struct dwarf2_section_info str
;
503 struct dwarf2_section_info str_offsets
;
504 /* In the case of a virtual DWO file, these two are unused. */
505 struct dwarf2_section_info info
;
506 std::vector
<dwarf2_section_info
> types
;
509 /* CUs/TUs in DWP/DWO files. */
513 /* Backlink to the containing struct dwo_file. */
514 struct dwo_file
*dwo_file
;
516 /* The "id" that distinguishes this CU/TU.
517 .debug_info calls this "dwo_id", .debug_types calls this "signature".
518 Since signatures came first, we stick with it for consistency. */
521 /* The section this CU/TU lives in, in the DWO file. */
522 struct dwarf2_section_info
*section
;
524 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
525 sect_offset sect_off
;
528 /* For types, offset in the type's DIE of the type defined by this TU. */
529 cu_offset type_offset_in_tu
;
532 /* include/dwarf2.h defines the DWP section codes.
533 It defines a max value but it doesn't define a min value, which we
534 use for error checking, so provide one. */
536 enum dwp_v2_section_ids
541 /* Data for one DWO file.
543 This includes virtual DWO files (a virtual DWO file is a DWO file as it
544 appears in a DWP file). DWP files don't really have DWO files per se -
545 comdat folding of types "loses" the DWO file they came from, and from
546 a high level view DWP files appear to contain a mass of random types.
547 However, to maintain consistency with the non-DWP case we pretend DWP
548 files contain virtual DWO files, and we assign each TU with one virtual
549 DWO file (generally based on the line and abbrev section offsets -
550 a heuristic that seems to work in practice). */
554 dwo_file () = default;
555 DISABLE_COPY_AND_ASSIGN (dwo_file
);
557 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
558 For virtual DWO files the name is constructed from the section offsets
559 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
560 from related CU+TUs. */
561 const char *dwo_name
= nullptr;
563 /* The DW_AT_comp_dir attribute. */
564 const char *comp_dir
= nullptr;
566 /* The bfd, when the file is open. Otherwise this is NULL.
567 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
568 gdb_bfd_ref_ptr dbfd
;
570 /* The sections that make up this DWO file.
571 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
572 sections (for lack of a better name). */
573 struct dwo_sections sections
{};
575 /* The CUs in the file.
576 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
577 an extension to handle LLVM's Link Time Optimization output (where
578 multiple source files may be compiled into a single object/dwo pair). */
581 /* Table of TUs in the file.
582 Each element is a struct dwo_unit. */
586 /* These sections are what may appear in a DWP file. */
590 /* These are used by all DWP versions (1, 2 and 5). */
591 struct dwarf2_section_info str
;
592 struct dwarf2_section_info cu_index
;
593 struct dwarf2_section_info tu_index
;
595 /* These are only used by DWP version 2 and version 5 files.
596 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
597 sections are referenced by section number, and are not recorded here.
598 In DWP version 2 or 5 there is at most one copy of all these sections,
599 each section being (effectively) comprised of the concatenation of all of
600 the individual sections that exist in the version 1 format.
601 To keep the code simple we treat each of these concatenated pieces as a
602 section itself (a virtual section?). */
603 struct dwarf2_section_info abbrev
;
604 struct dwarf2_section_info info
;
605 struct dwarf2_section_info line
;
606 struct dwarf2_section_info loc
;
607 struct dwarf2_section_info loclists
;
608 struct dwarf2_section_info macinfo
;
609 struct dwarf2_section_info macro
;
610 struct dwarf2_section_info rnglists
;
611 struct dwarf2_section_info str_offsets
;
612 struct dwarf2_section_info types
;
615 /* These sections are what may appear in a virtual DWO file in DWP version 1.
616 A virtual DWO file is a DWO file as it appears in a DWP file. */
618 struct virtual_v1_dwo_sections
620 struct dwarf2_section_info abbrev
;
621 struct dwarf2_section_info line
;
622 struct dwarf2_section_info loc
;
623 struct dwarf2_section_info macinfo
;
624 struct dwarf2_section_info macro
;
625 struct dwarf2_section_info str_offsets
;
626 /* Each DWP hash table entry records one CU or one TU.
627 That is recorded here, and copied to dwo_unit.section. */
628 struct dwarf2_section_info info_or_types
;
631 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
632 In version 2, the sections of the DWO files are concatenated together
633 and stored in one section of that name. Thus each ELF section contains
634 several "virtual" sections. */
636 struct virtual_v2_or_v5_dwo_sections
638 bfd_size_type abbrev_offset
;
639 bfd_size_type abbrev_size
;
641 bfd_size_type line_offset
;
642 bfd_size_type line_size
;
644 bfd_size_type loc_offset
;
645 bfd_size_type loc_size
;
647 bfd_size_type loclists_offset
;
648 bfd_size_type loclists_size
;
650 bfd_size_type macinfo_offset
;
651 bfd_size_type macinfo_size
;
653 bfd_size_type macro_offset
;
654 bfd_size_type macro_size
;
656 bfd_size_type rnglists_offset
;
657 bfd_size_type rnglists_size
;
659 bfd_size_type str_offsets_offset
;
660 bfd_size_type str_offsets_size
;
662 /* Each DWP hash table entry records one CU or one TU.
663 That is recorded here, and copied to dwo_unit.section. */
664 bfd_size_type info_or_types_offset
;
665 bfd_size_type info_or_types_size
;
668 /* Contents of DWP hash tables. */
670 struct dwp_hash_table
672 uint32_t version
, nr_columns
;
673 uint32_t nr_units
, nr_slots
;
674 const gdb_byte
*hash_table
, *unit_table
;
679 const gdb_byte
*indices
;
683 /* This is indexed by column number and gives the id of the section
685 #define MAX_NR_V2_DWO_SECTIONS \
686 (1 /* .debug_info or .debug_types */ \
687 + 1 /* .debug_abbrev */ \
688 + 1 /* .debug_line */ \
689 + 1 /* .debug_loc */ \
690 + 1 /* .debug_str_offsets */ \
691 + 1 /* .debug_macro or .debug_macinfo */)
692 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
693 const gdb_byte
*offsets
;
694 const gdb_byte
*sizes
;
698 /* This is indexed by column number and gives the id of the section
700 #define MAX_NR_V5_DWO_SECTIONS \
701 (1 /* .debug_info */ \
702 + 1 /* .debug_abbrev */ \
703 + 1 /* .debug_line */ \
704 + 1 /* .debug_loclists */ \
705 + 1 /* .debug_str_offsets */ \
706 + 1 /* .debug_macro */ \
707 + 1 /* .debug_rnglists */)
708 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
709 const gdb_byte
*offsets
;
710 const gdb_byte
*sizes
;
715 /* Data for one DWP file. */
719 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
721 dbfd (std::move (abfd
))
725 /* Name of the file. */
728 /* File format version. */
732 gdb_bfd_ref_ptr dbfd
;
734 /* Section info for this file. */
735 struct dwp_sections sections
{};
737 /* Table of CUs in the file. */
738 const struct dwp_hash_table
*cus
= nullptr;
740 /* Table of TUs in the file. */
741 const struct dwp_hash_table
*tus
= nullptr;
743 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
747 /* Table to map ELF section numbers to their sections.
748 This is only needed for the DWP V1 file format. */
749 unsigned int num_sections
= 0;
750 asection
**elf_sections
= nullptr;
753 /* Struct used to pass misc. parameters to read_die_and_children, et
754 al. which are used for both .debug_info and .debug_types dies.
755 All parameters here are unchanging for the life of the call. This
756 struct exists to abstract away the constant parameters of die reading. */
758 struct die_reader_specs
760 /* The bfd of die_section. */
763 /* The CU of the DIE we are parsing. */
764 struct dwarf2_cu
*cu
;
766 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
767 struct dwo_file
*dwo_file
;
769 /* The section the die comes from.
770 This is either .debug_info or .debug_types, or the .dwo variants. */
771 struct dwarf2_section_info
*die_section
;
773 /* die_section->buffer. */
774 const gdb_byte
*buffer
;
776 /* The end of the buffer. */
777 const gdb_byte
*buffer_end
;
779 /* The abbreviation table to use when reading the DIEs. */
780 struct abbrev_table
*abbrev_table
;
783 /* A subclass of die_reader_specs that holds storage and has complex
784 constructor and destructor behavior. */
786 class cutu_reader
: public die_reader_specs
790 cutu_reader (dwarf2_per_cu_data
*this_cu
,
791 dwarf2_per_objfile
*per_objfile
,
792 struct abbrev_table
*abbrev_table
,
793 dwarf2_cu
*existing_cu
,
796 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
797 dwarf2_per_objfile
*per_objfile
,
798 struct dwarf2_cu
*parent_cu
= nullptr,
799 struct dwo_file
*dwo_file
= nullptr);
801 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
803 const gdb_byte
*info_ptr
= nullptr;
804 struct die_info
*comp_unit_die
= nullptr;
805 bool dummy_p
= false;
807 /* Release the new CU, putting it on the chain. This cannot be done
812 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
813 dwarf2_per_objfile
*per_objfile
,
814 dwarf2_cu
*existing_cu
);
816 struct dwarf2_per_cu_data
*m_this_cu
;
817 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
819 /* The ordinary abbreviation table. */
820 abbrev_table_up m_abbrev_table_holder
;
822 /* The DWO abbreviation table. */
823 abbrev_table_up m_dwo_abbrev_table
;
826 /* When we construct a partial symbol table entry we only
827 need this much information. */
828 struct partial_die_info
: public allocate_on_obstack
830 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
832 /* Disable assign but still keep copy ctor, which is needed
833 load_partial_dies. */
834 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
835 partial_die_info (const partial_die_info
&) = default;
837 /* Adjust the partial die before generating a symbol for it. This
838 function may set the is_external flag or change the DIE's
840 void fixup (struct dwarf2_cu
*cu
);
842 /* Read a minimal amount of information into the minimal die
844 const gdb_byte
*read (const struct die_reader_specs
*reader
,
845 const struct abbrev_info
&abbrev
,
846 const gdb_byte
*info_ptr
);
848 /* Compute the name of this partial DIE. This memoizes the
849 result, so it is safe to call multiple times. */
850 const char *name (dwarf2_cu
*cu
);
852 /* Offset of this DIE. */
853 const sect_offset sect_off
;
855 /* DWARF-2 tag for this DIE. */
856 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
858 /* Assorted flags describing the data found in this DIE. */
859 const unsigned int has_children
: 1;
861 unsigned int is_external
: 1;
862 unsigned int is_declaration
: 1;
863 unsigned int has_type
: 1;
864 unsigned int has_specification
: 1;
865 unsigned int has_pc_info
: 1;
866 unsigned int has_range_info
: 1;
867 unsigned int may_be_inlined
: 1;
869 /* This DIE has been marked DW_AT_main_subprogram. */
870 unsigned int main_subprogram
: 1;
872 /* Flag set if the SCOPE field of this structure has been
874 unsigned int scope_set
: 1;
876 /* Flag set if the DIE has a byte_size attribute. */
877 unsigned int has_byte_size
: 1;
879 /* Flag set if the DIE has a DW_AT_const_value attribute. */
880 unsigned int has_const_value
: 1;
882 /* Flag set if any of the DIE's children are template arguments. */
883 unsigned int has_template_arguments
: 1;
885 /* Flag set if fixup has been called on this die. */
886 unsigned int fixup_called
: 1;
888 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
889 unsigned int is_dwz
: 1;
891 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
892 unsigned int spec_is_dwz
: 1;
894 unsigned int canonical_name
: 1;
896 /* The name of this DIE. Normally the value of DW_AT_name, but
897 sometimes a default name for unnamed DIEs. */
898 const char *raw_name
= nullptr;
900 /* The linkage name, if present. */
901 const char *linkage_name
= nullptr;
903 /* The scope to prepend to our children. This is generally
904 allocated on the comp_unit_obstack, so will disappear
905 when this compilation unit leaves the cache. */
906 const char *scope
= nullptr;
908 /* Some data associated with the partial DIE. The tag determines
909 which field is live. */
912 /* The location description associated with this DIE, if any. */
913 struct dwarf_block
*locdesc
;
914 /* The offset of an import, for DW_TAG_imported_unit. */
915 sect_offset sect_off
;
920 /* If HAS_PC_INFO, the PC range associated with this DIE. */
926 /* If HAS_RANGE_INFO, the ranges offset associated with this DIE. */
927 ULONGEST ranges_offset
;
930 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
931 DW_AT_sibling, if any. */
932 /* NOTE: This member isn't strictly necessary, partial_die_info::read
933 could return DW_AT_sibling values to its caller load_partial_dies. */
934 const gdb_byte
*sibling
= nullptr;
936 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
937 DW_AT_specification (or DW_AT_abstract_origin or
939 sect_offset spec_offset
{};
941 /* Pointers to this DIE's parent, first child, and next sibling,
943 struct partial_die_info
*die_parent
= nullptr;
944 struct partial_die_info
*die_child
= nullptr;
945 struct partial_die_info
*die_sibling
= nullptr;
947 friend struct partial_die_info
*
948 dwarf2_cu::find_partial_die (sect_offset sect_off
);
951 /* Only need to do look up in dwarf2_cu::find_partial_die. */
952 partial_die_info (sect_offset sect_off
)
953 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
957 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
959 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
964 has_specification
= 0;
972 has_template_arguments
= 0;
977 /* Don't set these using NSDMI (Non-static data member initialisation),
978 because g++-4.8 will error out. */
984 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
985 but this would require a corresponding change in unpack_field_as_long
987 static int bits_per_byte
= 8;
989 struct variant_part_builder
;
991 /* When reading a variant, we track a bit more information about the
992 field, and store it in an object of this type. */
996 int first_field
= -1;
999 /* A variant can contain other variant parts. */
1000 std::vector
<variant_part_builder
> variant_parts
;
1002 /* If we see a DW_TAG_variant, then this will be set if this is the
1004 bool default_branch
= false;
1005 /* If we see a DW_AT_discr_value, then this will be the discriminant
1007 ULONGEST discriminant_value
= 0;
1008 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1010 struct dwarf_block
*discr_list_data
= nullptr;
1013 /* This represents a DW_TAG_variant_part. */
1015 struct variant_part_builder
1017 /* The offset of the discriminant field. */
1018 sect_offset discriminant_offset
{};
1020 /* Variants that are direct children of this variant part. */
1021 std::vector
<variant_field
> variants
;
1023 /* True if we're currently reading a variant. */
1024 bool processing_variant
= false;
1029 int accessibility
= 0;
1031 /* Variant parts need to find the discriminant, which is a DIE
1032 reference. We track the section offset of each field to make
1035 struct field field
{};
1040 const char *name
= nullptr;
1041 std::vector
<struct fn_field
> fnfields
;
1044 /* The routines that read and process dies for a C struct or C++ class
1045 pass lists of data member fields and lists of member function fields
1046 in an instance of a field_info structure, as defined below. */
1049 /* List of data member and baseclasses fields. */
1050 std::vector
<struct nextfield
> fields
;
1051 std::vector
<struct nextfield
> baseclasses
;
1053 /* Set if the accessibility of one of the fields is not public. */
1054 bool non_public_fields
= false;
1056 /* Member function fieldlist array, contains name of possibly overloaded
1057 member function, number of overloaded member functions and a pointer
1058 to the head of the member function field chain. */
1059 std::vector
<struct fnfieldlist
> fnfieldlists
;
1061 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1062 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1063 std::vector
<struct decl_field
> typedef_field_list
;
1065 /* Nested types defined by this class and the number of elements in this
1067 std::vector
<struct decl_field
> nested_types_list
;
1069 /* If non-null, this is the variant part we are currently
1071 variant_part_builder
*current_variant_part
= nullptr;
1072 /* This holds all the top-level variant parts attached to the type
1074 std::vector
<variant_part_builder
> variant_parts
;
1076 /* Return the total number of fields (including baseclasses). */
1077 int nfields () const
1079 return fields
.size () + baseclasses
.size ();
1083 /* Loaded secondary compilation units are kept in memory until they
1084 have not been referenced for the processing of this many
1085 compilation units. Set this to zero to disable caching. Cache
1086 sizes of up to at least twenty will improve startup time for
1087 typical inter-CU-reference binaries, at an obvious memory cost. */
1088 static int dwarf_max_cache_age
= 5;
1090 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1091 struct cmd_list_element
*c
, const char *value
)
1093 fprintf_filtered (file
, _("The upper bound on the age of cached "
1094 "DWARF compilation units is %s.\n"),
1098 /* local function prototypes */
1100 static void dwarf2_find_base_address (struct die_info
*die
,
1101 struct dwarf2_cu
*cu
);
1103 static dwarf2_psymtab
*create_partial_symtab
1104 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1107 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1108 const gdb_byte
*info_ptr
,
1109 struct die_info
*type_unit_die
);
1111 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1113 static void scan_partial_symbols (struct partial_die_info
*,
1114 CORE_ADDR
*, CORE_ADDR
*,
1115 int, struct dwarf2_cu
*);
1117 static void add_partial_symbol (struct partial_die_info
*,
1118 struct dwarf2_cu
*);
1120 static void add_partial_namespace (struct partial_die_info
*pdi
,
1121 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1122 int set_addrmap
, struct dwarf2_cu
*cu
);
1124 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1125 CORE_ADDR
*highpc
, int set_addrmap
,
1126 struct dwarf2_cu
*cu
);
1128 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1129 struct dwarf2_cu
*cu
);
1131 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1132 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1133 int need_pc
, struct dwarf2_cu
*cu
);
1135 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1137 static struct partial_die_info
*load_partial_dies
1138 (const struct die_reader_specs
*, const gdb_byte
*, int);
1140 /* A pair of partial_die_info and compilation unit. */
1141 struct cu_partial_die_info
1143 /* The compilation unit of the partial_die_info. */
1144 struct dwarf2_cu
*cu
;
1145 /* A partial_die_info. */
1146 struct partial_die_info
*pdi
;
1148 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1154 cu_partial_die_info () = delete;
1157 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1158 struct dwarf2_cu
*);
1160 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1162 const struct attr_abbrev
*,
1165 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1166 struct attribute
*attr
, dwarf_tag tag
);
1168 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1170 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1171 dwarf2_section_info
*, sect_offset
);
1173 static const char *read_indirect_string
1174 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1175 const struct comp_unit_head
*, unsigned int *);
1177 static const char *read_indirect_string_at_offset
1178 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1180 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1184 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1185 ULONGEST str_index
);
1187 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1188 ULONGEST str_index
);
1190 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1191 struct dwarf2_cu
*);
1193 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1194 struct dwarf2_cu
*cu
);
1196 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1198 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1199 struct dwarf2_cu
*cu
);
1201 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1203 static struct die_info
*die_specification (struct die_info
*die
,
1204 struct dwarf2_cu
**);
1206 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1207 struct dwarf2_cu
*cu
);
1209 static void dwarf_decode_lines (struct line_header
*,
1210 const file_and_directory
&,
1211 struct dwarf2_cu
*, dwarf2_psymtab
*,
1212 CORE_ADDR
, int decode_mapping
);
1214 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1217 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1218 struct dwarf2_cu
*, struct symbol
* = NULL
);
1220 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1221 struct dwarf2_cu
*);
1223 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1226 struct obstack
*obstack
,
1227 struct dwarf2_cu
*cu
, LONGEST
*value
,
1228 const gdb_byte
**bytes
,
1229 struct dwarf2_locexpr_baton
**baton
);
1231 static struct type
*read_subrange_index_type (struct die_info
*die
,
1232 struct dwarf2_cu
*cu
);
1234 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1236 static int need_gnat_info (struct dwarf2_cu
*);
1238 static struct type
*die_descriptive_type (struct die_info
*,
1239 struct dwarf2_cu
*);
1241 static void set_descriptive_type (struct type
*, struct die_info
*,
1242 struct dwarf2_cu
*);
1244 static struct type
*die_containing_type (struct die_info
*,
1245 struct dwarf2_cu
*);
1247 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1248 struct dwarf2_cu
*);
1250 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1252 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1254 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1256 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1257 const char *suffix
, int physname
,
1258 struct dwarf2_cu
*cu
);
1260 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1262 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1264 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1266 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1268 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1270 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1272 /* Return the .debug_loclists section to use for cu. */
1273 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1275 /* Return the .debug_rnglists section to use for cu. */
1276 static struct dwarf2_section_info
*cu_debug_rnglists_section
1277 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1279 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1280 values. Keep the items ordered with increasing constraints compliance. */
1283 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1284 PC_BOUNDS_NOT_PRESENT
,
1286 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1287 were present but they do not form a valid range of PC addresses. */
1290 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1293 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1297 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1298 CORE_ADDR
*, CORE_ADDR
*,
1302 static void get_scope_pc_bounds (struct die_info
*,
1303 CORE_ADDR
*, CORE_ADDR
*,
1304 struct dwarf2_cu
*);
1306 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1307 CORE_ADDR
, struct dwarf2_cu
*);
1309 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1310 struct dwarf2_cu
*);
1312 static void dwarf2_attach_fields_to_type (struct field_info
*,
1313 struct type
*, struct dwarf2_cu
*);
1315 static void dwarf2_add_member_fn (struct field_info
*,
1316 struct die_info
*, struct type
*,
1317 struct dwarf2_cu
*);
1319 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1321 struct dwarf2_cu
*);
1323 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1325 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1327 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1329 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1331 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1333 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1335 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1337 static struct type
*read_module_type (struct die_info
*die
,
1338 struct dwarf2_cu
*cu
);
1340 static const char *namespace_name (struct die_info
*die
,
1341 int *is_anonymous
, struct dwarf2_cu
*);
1343 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1345 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1348 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1349 struct dwarf2_cu
*);
1351 static struct die_info
*read_die_and_siblings_1
1352 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1355 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1356 const gdb_byte
*info_ptr
,
1357 const gdb_byte
**new_info_ptr
,
1358 struct die_info
*parent
);
1360 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1361 struct die_info
**, const gdb_byte
*,
1364 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1365 struct die_info
**, const gdb_byte
*);
1367 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1369 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1372 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1374 static const char *dwarf2_full_name (const char *name
,
1375 struct die_info
*die
,
1376 struct dwarf2_cu
*cu
);
1378 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1379 struct dwarf2_cu
*cu
);
1381 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1382 struct dwarf2_cu
**);
1384 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1386 static void dump_die_for_error (struct die_info
*);
1388 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1391 /*static*/ void dump_die (struct die_info
*, int max_level
);
1393 static void store_in_ref_table (struct die_info
*,
1394 struct dwarf2_cu
*);
1396 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1397 const struct attribute
*,
1398 struct dwarf2_cu
**);
1400 static struct die_info
*follow_die_ref (struct die_info
*,
1401 const struct attribute
*,
1402 struct dwarf2_cu
**);
1404 static struct die_info
*follow_die_sig (struct die_info
*,
1405 const struct attribute
*,
1406 struct dwarf2_cu
**);
1408 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1409 struct dwarf2_cu
*);
1411 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1412 const struct attribute
*,
1413 struct dwarf2_cu
*);
1415 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1416 dwarf2_per_objfile
*per_objfile
);
1418 static void read_signatured_type (signatured_type
*sig_type
,
1419 dwarf2_per_objfile
*per_objfile
);
1421 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1422 struct die_info
*die
, struct dwarf2_cu
*cu
,
1423 struct dynamic_prop
*prop
, struct type
*type
);
1425 /* memory allocation interface */
1427 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1429 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1431 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1433 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1434 struct dwarf2_loclist_baton
*baton
,
1435 const struct attribute
*attr
);
1437 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1439 struct dwarf2_cu
*cu
,
1442 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1443 const gdb_byte
*info_ptr
,
1444 const struct abbrev_info
*abbrev
);
1446 static hashval_t
partial_die_hash (const void *item
);
1448 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1450 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1451 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1452 dwarf2_per_bfd
*per_bfd
);
1454 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1455 struct die_info
*comp_unit_die
,
1456 enum language pretend_language
);
1458 static struct type
*set_die_type (struct die_info
*, struct type
*,
1459 struct dwarf2_cu
*, bool = false);
1461 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1463 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1464 dwarf2_per_objfile
*per_objfile
,
1465 dwarf2_cu
*existing_cu
,
1467 enum language pretend_language
);
1469 static void process_full_comp_unit (dwarf2_cu
*cu
,
1470 enum language pretend_language
);
1472 static void process_full_type_unit (dwarf2_cu
*cu
,
1473 enum language pretend_language
);
1475 static struct type
*get_die_type_at_offset (sect_offset
,
1476 dwarf2_per_cu_data
*per_cu
,
1477 dwarf2_per_objfile
*per_objfile
);
1479 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1481 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1482 dwarf2_per_objfile
*per_objfile
,
1483 enum language pretend_language
);
1485 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1487 /* Class, the destructor of which frees all allocated queue entries. This
1488 will only have work to do if an error was thrown while processing the
1489 dwarf. If no error was thrown then the queue entries should have all
1490 been processed, and freed, as we went along. */
1492 class dwarf2_queue_guard
1495 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1496 : m_per_objfile (per_objfile
)
1498 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1500 m_per_objfile
->per_bfd
->queue
.emplace ();
1503 /* Free any entries remaining on the queue. There should only be
1504 entries left if we hit an error while processing the dwarf. */
1505 ~dwarf2_queue_guard ()
1507 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1509 m_per_objfile
->per_bfd
->queue
.reset ();
1512 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1515 dwarf2_per_objfile
*m_per_objfile
;
1518 dwarf2_queue_item::~dwarf2_queue_item ()
1520 /* Anything still marked queued is likely to be in an
1521 inconsistent state, so discard it. */
1524 per_objfile
->remove_cu (per_cu
);
1529 /* See dwarf2/read.h. */
1532 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1534 if (data
->is_debug_types
)
1535 delete static_cast<signatured_type
*> (data
);
1540 static file_and_directory
&find_file_and_directory
1541 (struct die_info
*die
, struct dwarf2_cu
*cu
);
1543 static const char *compute_include_file_name
1544 (const struct line_header
*lh
,
1545 const file_entry
&fe
,
1546 const file_and_directory
&cu_info
,
1547 gdb::unique_xmalloc_ptr
<char> *name_holder
);
1549 static htab_up
allocate_signatured_type_table ();
1551 static htab_up
allocate_dwo_unit_table ();
1553 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1554 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1555 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1557 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1559 static struct dwo_unit
*lookup_dwo_comp_unit
1560 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1561 ULONGEST signature
);
1563 static struct dwo_unit
*lookup_dwo_type_unit
1564 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1566 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1568 /* A unique pointer to a dwo_file. */
1570 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1572 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1574 static void check_producer (struct dwarf2_cu
*cu
);
1576 /* Various complaints about symbol reading that don't abort the process. */
1579 dwarf2_debug_line_missing_file_complaint (void)
1581 complaint (_(".debug_line section has line data without a file"));
1585 dwarf2_debug_line_missing_end_sequence_complaint (void)
1587 complaint (_(".debug_line section has line "
1588 "program sequence without an end"));
1592 dwarf2_complex_location_expr_complaint (void)
1594 complaint (_("location expression too complex"));
1598 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1601 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1606 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1608 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1612 /* Hash function for line_header_hash. */
1615 line_header_hash (const struct line_header
*ofs
)
1617 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1620 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1623 line_header_hash_voidp (const void *item
)
1625 const struct line_header
*ofs
= (const struct line_header
*) item
;
1627 return line_header_hash (ofs
);
1630 /* Equality function for line_header_hash. */
1633 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1635 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1636 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1638 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1639 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1644 /* An iterator for all_comp_units that is based on index. This
1645 approach makes it possible to iterate over all_comp_units safely,
1646 when some caller in the loop may add new units. */
1648 class all_comp_units_iterator
1652 all_comp_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1653 : m_per_bfd (per_bfd
),
1654 m_index (start
? 0 : per_bfd
->all_comp_units
.size ())
1658 all_comp_units_iterator
&operator++ ()
1664 dwarf2_per_cu_data
*operator* () const
1666 return m_per_bfd
->get_cu (m_index
);
1669 bool operator== (const all_comp_units_iterator
&other
) const
1671 return m_index
== other
.m_index
;
1675 bool operator!= (const all_comp_units_iterator
&other
) const
1677 return m_index
!= other
.m_index
;
1682 dwarf2_per_bfd
*m_per_bfd
;
1686 /* A range adapter for the all_comp_units_iterator. */
1687 class all_comp_units_range
1691 all_comp_units_range (dwarf2_per_bfd
*per_bfd
)
1692 : m_per_bfd (per_bfd
)
1696 all_comp_units_iterator
begin ()
1698 return all_comp_units_iterator (m_per_bfd
, true);
1701 all_comp_units_iterator
end ()
1703 return all_comp_units_iterator (m_per_bfd
, false);
1708 dwarf2_per_bfd
*m_per_bfd
;
1711 /* See declaration. */
1713 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1716 can_copy (can_copy_
)
1719 names
= &dwarf2_elf_names
;
1721 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1722 locate_sections (obfd
, sec
, *names
);
1725 dwarf2_per_bfd::~dwarf2_per_bfd ()
1727 for (auto &per_cu
: all_comp_units
)
1729 per_cu
->imported_symtabs_free ();
1730 per_cu
->free_cached_file_names ();
1733 /* Everything else should be on this->obstack. */
1739 dwarf2_per_objfile::remove_all_cus ()
1741 gdb_assert (!this->per_bfd
->queue
.has_value ());
1743 for (auto pair
: m_dwarf2_cus
)
1746 m_dwarf2_cus
.clear ();
1749 /* A helper class that calls free_cached_comp_units on
1752 class free_cached_comp_units
1756 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1757 : m_per_objfile (per_objfile
)
1761 ~free_cached_comp_units ()
1763 m_per_objfile
->remove_all_cus ();
1766 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1770 dwarf2_per_objfile
*m_per_objfile
;
1776 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1778 if (per_cu
->index
< this->m_symtabs
.size ())
1779 return this->m_symtabs
[per_cu
->index
] != nullptr;
1786 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1788 if (per_cu
->index
< this->m_symtabs
.size ())
1789 return this->m_symtabs
[per_cu
->index
];
1796 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1797 compunit_symtab
*symtab
)
1799 if (per_cu
->index
>= this->m_symtabs
.size ())
1800 this->m_symtabs
.resize (per_cu
->index
+ 1);
1801 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1802 this->m_symtabs
[per_cu
->index
] = symtab
;
1805 /* Try to locate the sections we need for DWARF 2 debugging
1806 information and return true if we have enough to do something.
1807 NAMES points to the dwarf2 section names, or is NULL if the standard
1808 ELF names are used. CAN_COPY is true for formats where symbol
1809 interposition is possible and so symbol values must follow copy
1810 relocation rules. */
1813 dwarf2_has_info (struct objfile
*objfile
,
1814 const struct dwarf2_debug_sections
*names
,
1817 if (objfile
->flags
& OBJF_READNEVER
)
1820 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1822 if (per_objfile
== NULL
)
1824 dwarf2_per_bfd
*per_bfd
;
1826 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1827 BFD doesn't require relocations.
1829 We don't share with objfiles for which -readnow was requested,
1830 because it would complicate things when loading the same BFD with
1831 -readnow and then without -readnow. */
1832 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1833 && (objfile
->flags
& OBJF_READNOW
) == 0)
1835 /* See if one has been created for this BFD yet. */
1836 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1838 if (per_bfd
== nullptr)
1840 /* No, create it now. */
1841 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1842 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1847 /* No sharing possible, create one specifically for this objfile. */
1848 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1849 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1852 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1855 return (!per_objfile
->per_bfd
->info
.is_virtual
1856 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1857 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1858 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1861 /* See declaration. */
1864 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1865 const dwarf2_debug_sections
&names
)
1867 flagword aflag
= bfd_section_flags (sectp
);
1869 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1872 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1873 > bfd_get_file_size (abfd
))
1875 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1876 warning (_("Discarding section %s which has a section size (%s"
1877 ") larger than the file size [in module %s]"),
1878 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1879 bfd_get_filename (abfd
));
1881 else if (names
.info
.matches (sectp
->name
))
1883 this->info
.s
.section
= sectp
;
1884 this->info
.size
= bfd_section_size (sectp
);
1886 else if (names
.abbrev
.matches (sectp
->name
))
1888 this->abbrev
.s
.section
= sectp
;
1889 this->abbrev
.size
= bfd_section_size (sectp
);
1891 else if (names
.line
.matches (sectp
->name
))
1893 this->line
.s
.section
= sectp
;
1894 this->line
.size
= bfd_section_size (sectp
);
1896 else if (names
.loc
.matches (sectp
->name
))
1898 this->loc
.s
.section
= sectp
;
1899 this->loc
.size
= bfd_section_size (sectp
);
1901 else if (names
.loclists
.matches (sectp
->name
))
1903 this->loclists
.s
.section
= sectp
;
1904 this->loclists
.size
= bfd_section_size (sectp
);
1906 else if (names
.macinfo
.matches (sectp
->name
))
1908 this->macinfo
.s
.section
= sectp
;
1909 this->macinfo
.size
= bfd_section_size (sectp
);
1911 else if (names
.macro
.matches (sectp
->name
))
1913 this->macro
.s
.section
= sectp
;
1914 this->macro
.size
= bfd_section_size (sectp
);
1916 else if (names
.str
.matches (sectp
->name
))
1918 this->str
.s
.section
= sectp
;
1919 this->str
.size
= bfd_section_size (sectp
);
1921 else if (names
.str_offsets
.matches (sectp
->name
))
1923 this->str_offsets
.s
.section
= sectp
;
1924 this->str_offsets
.size
= bfd_section_size (sectp
);
1926 else if (names
.line_str
.matches (sectp
->name
))
1928 this->line_str
.s
.section
= sectp
;
1929 this->line_str
.size
= bfd_section_size (sectp
);
1931 else if (names
.addr
.matches (sectp
->name
))
1933 this->addr
.s
.section
= sectp
;
1934 this->addr
.size
= bfd_section_size (sectp
);
1936 else if (names
.frame
.matches (sectp
->name
))
1938 this->frame
.s
.section
= sectp
;
1939 this->frame
.size
= bfd_section_size (sectp
);
1941 else if (names
.eh_frame
.matches (sectp
->name
))
1943 this->eh_frame
.s
.section
= sectp
;
1944 this->eh_frame
.size
= bfd_section_size (sectp
);
1946 else if (names
.ranges
.matches (sectp
->name
))
1948 this->ranges
.s
.section
= sectp
;
1949 this->ranges
.size
= bfd_section_size (sectp
);
1951 else if (names
.rnglists
.matches (sectp
->name
))
1953 this->rnglists
.s
.section
= sectp
;
1954 this->rnglists
.size
= bfd_section_size (sectp
);
1956 else if (names
.types
.matches (sectp
->name
))
1958 struct dwarf2_section_info type_section
;
1960 memset (&type_section
, 0, sizeof (type_section
));
1961 type_section
.s
.section
= sectp
;
1962 type_section
.size
= bfd_section_size (sectp
);
1964 this->types
.push_back (type_section
);
1966 else if (names
.gdb_index
.matches (sectp
->name
))
1968 this->gdb_index
.s
.section
= sectp
;
1969 this->gdb_index
.size
= bfd_section_size (sectp
);
1971 else if (names
.debug_names
.matches (sectp
->name
))
1973 this->debug_names
.s
.section
= sectp
;
1974 this->debug_names
.size
= bfd_section_size (sectp
);
1976 else if (names
.debug_aranges
.matches (sectp
->name
))
1978 this->debug_aranges
.s
.section
= sectp
;
1979 this->debug_aranges
.size
= bfd_section_size (sectp
);
1982 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1983 && bfd_section_vma (sectp
) == 0)
1984 this->has_section_at_zero
= true;
1987 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1991 dwarf2_get_section_info (struct objfile
*objfile
,
1992 enum dwarf2_section_enum sect
,
1993 asection
**sectp
, const gdb_byte
**bufp
,
1994 bfd_size_type
*sizep
)
1996 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1997 struct dwarf2_section_info
*info
;
1999 /* We may see an objfile without any DWARF, in which case we just
2001 if (per_objfile
== NULL
)
2010 case DWARF2_DEBUG_FRAME
:
2011 info
= &per_objfile
->per_bfd
->frame
;
2013 case DWARF2_EH_FRAME
:
2014 info
= &per_objfile
->per_bfd
->eh_frame
;
2017 gdb_assert_not_reached ("unexpected section");
2020 info
->read (objfile
);
2022 *sectp
= info
->get_bfd_section ();
2023 *bufp
= info
->buffer
;
2024 *sizep
= info
->size
;
2028 /* DWARF quick_symbol_functions support. */
2030 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2031 unique line tables, so we maintain a separate table of all .debug_line
2032 derived entries to support the sharing.
2033 All the quick functions need is the list of file names. We discard the
2034 line_header when we're done and don't need to record it here. */
2035 struct quick_file_names
2037 /* The data used to construct the hash key. */
2038 struct stmt_list_hash hash
;
2040 /* The number of entries in file_names, real_names. */
2041 unsigned int num_file_names
;
2043 /* The CU directory, as given by DW_AT_comp_dir. May be
2045 const char *comp_dir
;
2047 /* The file names from the line table, after being run through
2049 const char **file_names
;
2051 /* The file names from the line table after being run through
2052 gdb_realpath. These are computed lazily. */
2053 const char **real_names
;
2056 /* When using the index (and thus not using psymtabs), each CU has an
2057 object of this type. This is used to hold information needed by
2058 the various "quick" methods. */
2059 struct dwarf2_per_cu_quick_data
2061 /* The file table. This can be NULL if there was no file table
2062 or it's currently not read in.
2063 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2064 struct quick_file_names
*file_names
;
2066 /* A temporary mark bit used when iterating over all CUs in
2067 expand_symtabs_matching. */
2068 unsigned int mark
: 1;
2070 /* True if we've tried to read the file table. There will be no
2071 point in trying to read it again next time. */
2072 bool files_read
: 1;
2075 /* A subclass of psymbol_functions that arranges to read the DWARF
2076 partial symbols when needed. */
2077 struct lazy_dwarf_reader
: public psymbol_functions
2079 using psymbol_functions::psymbol_functions
;
2081 bool can_lazily_read_symbols () override
2086 void read_partial_symbols (struct objfile
*objfile
) override
2088 if (dwarf2_has_info (objfile
, nullptr))
2089 dwarf2_build_psymtabs (objfile
, this);
2093 static quick_symbol_functions_up
2094 make_lazy_dwarf_reader ()
2096 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2099 struct dwarf2_base_index_functions
: public quick_symbol_functions
2101 bool has_symbols (struct objfile
*objfile
) override
;
2103 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2105 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2107 void forget_cached_source_info (struct objfile
*objfile
) override
;
2109 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2112 bool *symbol_found_p
) override
2114 *symbol_found_p
= false;
2115 return language_unknown
;
2118 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2120 void expand_all_symtabs (struct objfile
*objfile
) override
;
2122 struct compunit_symtab
*find_pc_sect_compunit_symtab
2123 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2124 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2126 struct compunit_symtab
*find_compunit_symtab_by_address
2127 (struct objfile
*objfile
, CORE_ADDR address
) override
2132 void map_symbol_filenames (struct objfile
*objfile
,
2133 gdb::function_view
<symbol_filename_ftype
> fun
,
2134 bool need_fullname
) override
;
2137 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2139 void dump (struct objfile
*objfile
) override
;
2141 void expand_matching_symbols
2143 const lookup_name_info
&lookup_name
,
2146 symbol_compare_ftype
*ordered_compare
) override
;
2148 bool expand_symtabs_matching
2149 (struct objfile
*objfile
,
2150 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2151 const lookup_name_info
*lookup_name
,
2152 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2153 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2154 block_search_flags search_flags
,
2156 enum search_domain kind
) override
;
2159 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2161 void dump (struct objfile
*objfile
) override
;
2163 void expand_matching_symbols
2165 const lookup_name_info
&lookup_name
,
2168 symbol_compare_ftype
*ordered_compare
) override
;
2170 bool expand_symtabs_matching
2171 (struct objfile
*objfile
,
2172 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2173 const lookup_name_info
*lookup_name
,
2174 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2175 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2176 block_search_flags search_flags
,
2178 enum search_domain kind
) override
;
2181 static quick_symbol_functions_up
2182 make_dwarf_gdb_index ()
2184 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2187 static quick_symbol_functions_up
2188 make_dwarf_debug_names ()
2190 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2193 /* Utility hash function for a stmt_list_hash. */
2196 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2200 if (stmt_list_hash
->dwo_unit
!= NULL
)
2201 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2202 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2206 /* Utility equality function for a stmt_list_hash. */
2209 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2210 const struct stmt_list_hash
*rhs
)
2212 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2214 if (lhs
->dwo_unit
!= NULL
2215 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2218 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2221 /* Hash function for a quick_file_names. */
2224 hash_file_name_entry (const void *e
)
2226 const struct quick_file_names
*file_data
2227 = (const struct quick_file_names
*) e
;
2229 return hash_stmt_list_entry (&file_data
->hash
);
2232 /* Equality function for a quick_file_names. */
2235 eq_file_name_entry (const void *a
, const void *b
)
2237 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2238 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2240 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2243 /* Create a quick_file_names hash table. */
2246 create_quick_file_names_table (unsigned int nr_initial_entries
)
2248 return htab_up (htab_create_alloc (nr_initial_entries
,
2249 hash_file_name_entry
, eq_file_name_entry
,
2250 nullptr, xcalloc
, xfree
));
2253 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2254 function is unrelated to symtabs, symtab would have to be created afterwards.
2255 You should call age_cached_comp_units after processing the CU. */
2258 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2261 if (per_cu
->is_debug_types
)
2262 load_full_type_unit (per_cu
, per_objfile
);
2264 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2265 skip_partial
, language_minimal
);
2267 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2269 return nullptr; /* Dummy CU. */
2271 dwarf2_find_base_address (cu
->dies
, cu
);
2276 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2279 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2280 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2282 /* Skip type_unit_groups, reading the type units they contain
2283 is handled elsewhere. */
2284 if (per_cu
->type_unit_group_p ())
2288 /* The destructor of dwarf2_queue_guard frees any entries left on
2289 the queue. After this point we're guaranteed to leave this function
2290 with the dwarf queue empty. */
2291 dwarf2_queue_guard
q_guard (per_objfile
);
2293 if (!per_objfile
->symtab_set_p (per_cu
))
2295 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2296 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2298 /* If we just loaded a CU from a DWO, and we're working with an index
2299 that may badly handle TUs, load all the TUs in that DWO as well.
2300 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2301 if (!per_cu
->is_debug_types
2303 && cu
->dwo_unit
!= NULL
2304 && per_objfile
->per_bfd
->index_table
!= NULL
2305 && per_objfile
->per_bfd
->index_table
->version
<= 7
2306 /* DWP files aren't supported yet. */
2307 && get_dwp_file (per_objfile
) == NULL
)
2308 queue_and_load_all_dwo_tus (cu
);
2311 process_queue (per_objfile
);
2314 /* Age the cache, releasing compilation units that have not
2315 been used recently. */
2316 per_objfile
->age_comp_units ();
2319 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2320 the per-objfile for which this symtab is instantiated.
2322 Returns the resulting symbol table. */
2324 static struct compunit_symtab
*
2325 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2326 dwarf2_per_objfile
*per_objfile
,
2329 gdb_assert (per_objfile
->per_bfd
->using_index
);
2331 if (!per_objfile
->symtab_set_p (per_cu
))
2333 free_cached_comp_units
freer (per_objfile
);
2334 scoped_restore decrementer
= increment_reading_symtab ();
2335 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2336 process_cu_includes (per_objfile
);
2339 return per_objfile
->get_symtab (per_cu
);
2344 dwarf2_per_cu_data_up
2345 dwarf2_per_bfd::allocate_per_cu ()
2347 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2348 result
->per_bfd
= this;
2349 result
->index
= all_comp_units
.size ();
2356 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2358 signatured_type_up
result (new signatured_type (signature
));
2359 result
->per_bfd
= this;
2360 result
->index
= all_comp_units
.size ();
2361 result
->is_debug_types
= true;
2366 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2367 obstack, and constructed with the specified field values. */
2369 static dwarf2_per_cu_data_up
2370 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2371 struct dwarf2_section_info
*section
,
2373 sect_offset sect_off
, ULONGEST length
)
2375 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2376 the_cu
->sect_off
= sect_off
;
2377 the_cu
->length
= length
;
2378 the_cu
->section
= section
;
2379 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2380 struct dwarf2_per_cu_quick_data
);
2381 the_cu
->is_dwz
= is_dwz
;
2385 /* A helper for create_cus_from_index that handles a given list of
2389 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2390 const gdb_byte
*cu_list
, offset_type n_elements
,
2391 struct dwarf2_section_info
*section
,
2394 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2396 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2398 sect_offset sect_off
2399 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2400 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2403 dwarf2_per_cu_data_up per_cu
2404 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2406 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2410 /* Read the CU list from the mapped index, and use it to create all
2411 the CU objects for PER_BFD. */
2414 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2415 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2416 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2418 gdb_assert (per_bfd
->all_comp_units
.empty ());
2419 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2421 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2424 if (dwz_elements
== 0)
2427 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2428 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2432 /* Create the signatured type hash table from the index. */
2435 create_signatured_type_table_from_index
2436 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2437 const gdb_byte
*bytes
, offset_type elements
)
2439 htab_up sig_types_hash
= allocate_signatured_type_table ();
2441 for (offset_type i
= 0; i
< elements
; i
+= 3)
2443 signatured_type_up sig_type
;
2446 cu_offset type_offset_in_tu
;
2448 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2449 sect_offset sect_off
2450 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2452 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2454 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2457 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2458 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2459 sig_type
->section
= section
;
2460 sig_type
->sect_off
= sect_off
;
2462 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2463 struct dwarf2_per_cu_quick_data
);
2465 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2466 *slot
= sig_type
.get ();
2468 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2471 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2474 /* Create the signatured type hash table from .debug_names. */
2477 create_signatured_type_table_from_debug_names
2478 (dwarf2_per_objfile
*per_objfile
,
2479 const mapped_debug_names
&map
,
2480 struct dwarf2_section_info
*section
,
2481 struct dwarf2_section_info
*abbrev_section
)
2483 struct objfile
*objfile
= per_objfile
->objfile
;
2485 section
->read (objfile
);
2486 abbrev_section
->read (objfile
);
2488 htab_up sig_types_hash
= allocate_signatured_type_table ();
2490 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2492 signatured_type_up sig_type
;
2495 sect_offset sect_off
2496 = (sect_offset
) (extract_unsigned_integer
2497 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2499 map
.dwarf5_byte_order
));
2501 comp_unit_head cu_header
;
2502 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2504 section
->buffer
+ to_underlying (sect_off
),
2507 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2508 (cu_header
.signature
);
2509 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2510 sig_type
->section
= section
;
2511 sig_type
->sect_off
= sect_off
;
2513 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2514 struct dwarf2_per_cu_quick_data
);
2516 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2517 *slot
= sig_type
.get ();
2519 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2522 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2525 /* Read the address map data from the mapped index, and use it to
2526 populate the psymtabs_addrmap. */
2529 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2530 struct mapped_index
*index
)
2532 struct objfile
*objfile
= per_objfile
->objfile
;
2533 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2534 struct gdbarch
*gdbarch
= objfile
->arch ();
2535 const gdb_byte
*iter
, *end
;
2536 struct addrmap
*mutable_map
;
2539 auto_obstack temp_obstack
;
2541 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2543 iter
= index
->address_table
.data ();
2544 end
= iter
+ index
->address_table
.size ();
2546 baseaddr
= objfile
->text_section_offset ();
2550 ULONGEST hi
, lo
, cu_index
;
2551 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2553 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2555 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2560 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2561 hex_string (lo
), hex_string (hi
));
2565 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2567 complaint (_(".gdb_index address table has invalid CU number %u"),
2568 (unsigned) cu_index
);
2572 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2573 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2574 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2575 per_bfd
->get_cu (cu_index
));
2578 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2582 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2583 populate the psymtabs_addrmap. */
2586 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2587 struct dwarf2_section_info
*section
)
2589 struct objfile
*objfile
= per_objfile
->objfile
;
2590 bfd
*abfd
= objfile
->obfd
;
2591 struct gdbarch
*gdbarch
= objfile
->arch ();
2592 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2593 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2595 auto_obstack temp_obstack
;
2596 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2598 std::unordered_map
<sect_offset
,
2599 dwarf2_per_cu_data
*,
2600 gdb::hash_enum
<sect_offset
>>
2601 debug_info_offset_to_per_cu
;
2602 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2604 /* A TU will not need aranges, and skipping them here is an easy
2605 way of ignoring .debug_types -- and possibly seeing a
2606 duplicate section offset -- entirely. */
2607 if (per_cu
->is_debug_types
)
2610 const auto insertpair
2611 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2613 if (!insertpair
.second
)
2615 warning (_("Section .debug_aranges in %s has duplicate "
2616 "debug_info_offset %s, ignoring .debug_aranges."),
2617 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2622 section
->read (objfile
);
2624 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2626 const gdb_byte
*addr
= section
->buffer
;
2628 while (addr
< section
->buffer
+ section
->size
)
2630 const gdb_byte
*const entry_addr
= addr
;
2631 unsigned int bytes_read
;
2633 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2637 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2638 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2639 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2640 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2642 warning (_("Section .debug_aranges in %s entry at offset %s "
2643 "length %s exceeds section length %s, "
2644 "ignoring .debug_aranges."),
2645 objfile_name (objfile
),
2646 plongest (entry_addr
- section
->buffer
),
2647 plongest (bytes_read
+ entry_length
),
2648 pulongest (section
->size
));
2652 /* The version number. */
2653 const uint16_t version
= read_2_bytes (abfd
, addr
);
2657 warning (_("Section .debug_aranges in %s entry at offset %s "
2658 "has unsupported version %d, ignoring .debug_aranges."),
2659 objfile_name (objfile
),
2660 plongest (entry_addr
- section
->buffer
), version
);
2664 const uint64_t debug_info_offset
2665 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2666 addr
+= offset_size
;
2667 const auto per_cu_it
2668 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2669 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2671 warning (_("Section .debug_aranges in %s entry at offset %s "
2672 "debug_info_offset %s does not exists, "
2673 "ignoring .debug_aranges."),
2674 objfile_name (objfile
),
2675 plongest (entry_addr
- section
->buffer
),
2676 pulongest (debug_info_offset
));
2679 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2681 const uint8_t address_size
= *addr
++;
2682 if (address_size
< 1 || address_size
> 8)
2684 warning (_("Section .debug_aranges in %s entry at offset %s "
2685 "address_size %u is invalid, ignoring .debug_aranges."),
2686 objfile_name (objfile
),
2687 plongest (entry_addr
- section
->buffer
), address_size
);
2691 const uint8_t segment_selector_size
= *addr
++;
2692 if (segment_selector_size
!= 0)
2694 warning (_("Section .debug_aranges in %s entry at offset %s "
2695 "segment_selector_size %u is not supported, "
2696 "ignoring .debug_aranges."),
2697 objfile_name (objfile
),
2698 plongest (entry_addr
- section
->buffer
),
2699 segment_selector_size
);
2703 /* Must pad to an alignment boundary that is twice the address
2704 size. It is undocumented by the DWARF standard but GCC does
2705 use it. However, not every compiler does this. We can see
2706 whether it has happened by looking at the total length of the
2707 contents of the aranges for this CU -- it if isn't a multiple
2708 of twice the address size, then we skip any leftover
2710 addr
+= (entry_end
- addr
) % (2 * address_size
);
2714 if (addr
+ 2 * address_size
> entry_end
)
2716 warning (_("Section .debug_aranges in %s entry at offset %s "
2717 "address list is not properly terminated, "
2718 "ignoring .debug_aranges."),
2719 objfile_name (objfile
),
2720 plongest (entry_addr
- section
->buffer
));
2723 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2725 addr
+= address_size
;
2726 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2728 addr
+= address_size
;
2729 if (start
== 0 && length
== 0)
2731 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2733 /* Symbol was eliminated due to a COMDAT group. */
2736 ULONGEST end
= start
+ length
;
2737 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2739 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2741 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2745 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2749 /* A helper function that reads the .gdb_index from BUFFER and fills
2750 in MAP. FILENAME is the name of the file containing the data;
2751 it is used for error reporting. DEPRECATED_OK is true if it is
2752 ok to use deprecated sections.
2754 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2755 out parameters that are filled in with information about the CU and
2756 TU lists in the section.
2758 Returns true if all went well, false otherwise. */
2761 read_gdb_index_from_buffer (const char *filename
,
2763 gdb::array_view
<const gdb_byte
> buffer
,
2764 struct mapped_index
*map
,
2765 const gdb_byte
**cu_list
,
2766 offset_type
*cu_list_elements
,
2767 const gdb_byte
**types_list
,
2768 offset_type
*types_list_elements
)
2770 const gdb_byte
*addr
= &buffer
[0];
2771 offset_view
metadata (buffer
);
2773 /* Version check. */
2774 offset_type version
= metadata
[0];
2775 /* Versions earlier than 3 emitted every copy of a psymbol. This
2776 causes the index to behave very poorly for certain requests. Version 3
2777 contained incomplete addrmap. So, it seems better to just ignore such
2781 static int warning_printed
= 0;
2782 if (!warning_printed
)
2784 warning (_("Skipping obsolete .gdb_index section in %s."),
2786 warning_printed
= 1;
2790 /* Index version 4 uses a different hash function than index version
2793 Versions earlier than 6 did not emit psymbols for inlined
2794 functions. Using these files will cause GDB not to be able to
2795 set breakpoints on inlined functions by name, so we ignore these
2796 indices unless the user has done
2797 "set use-deprecated-index-sections on". */
2798 if (version
< 6 && !deprecated_ok
)
2800 static int warning_printed
= 0;
2801 if (!warning_printed
)
2804 Skipping deprecated .gdb_index section in %s.\n\
2805 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2806 to use the section anyway."),
2808 warning_printed
= 1;
2812 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2813 of the TU (for symbols coming from TUs),
2814 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2815 Plus gold-generated indices can have duplicate entries for global symbols,
2816 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2817 These are just performance bugs, and we can't distinguish gdb-generated
2818 indices from gold-generated ones, so issue no warning here. */
2820 /* Indexes with higher version than the one supported by GDB may be no
2821 longer backward compatible. */
2825 map
->version
= version
;
2828 *cu_list
= addr
+ metadata
[i
];
2829 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2832 *types_list
= addr
+ metadata
[i
];
2833 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2836 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2837 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2839 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2842 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2843 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2845 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2849 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2851 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
2853 /* An empty constant pool implies that all symbol table entries are
2854 empty. Make map->symbol_table.empty () == true. */
2856 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2863 /* Callback types for dwarf2_read_gdb_index. */
2865 typedef gdb::function_view
2866 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2867 get_gdb_index_contents_ftype
;
2868 typedef gdb::function_view
2869 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2870 get_gdb_index_contents_dwz_ftype
;
2872 /* Read .gdb_index. If everything went ok, initialize the "quick"
2873 elements of all the CUs and return 1. Otherwise, return 0. */
2876 dwarf2_read_gdb_index
2877 (dwarf2_per_objfile
*per_objfile
,
2878 get_gdb_index_contents_ftype get_gdb_index_contents
,
2879 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2881 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2882 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2883 struct dwz_file
*dwz
;
2884 struct objfile
*objfile
= per_objfile
->objfile
;
2885 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2887 gdb::array_view
<const gdb_byte
> main_index_contents
2888 = get_gdb_index_contents (objfile
, per_bfd
);
2890 if (main_index_contents
.empty ())
2893 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2894 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2895 use_deprecated_index_sections
,
2896 main_index_contents
, map
.get (), &cu_list
,
2897 &cu_list_elements
, &types_list
,
2898 &types_list_elements
))
2901 /* Don't use the index if it's empty. */
2902 if (map
->symbol_table
.empty ())
2905 /* If there is a .dwz file, read it so we can get its CU list as
2907 dwz
= dwarf2_get_dwz_file (per_bfd
);
2910 struct mapped_index dwz_map
;
2911 const gdb_byte
*dwz_types_ignore
;
2912 offset_type dwz_types_elements_ignore
;
2914 gdb::array_view
<const gdb_byte
> dwz_index_content
2915 = get_gdb_index_contents_dwz (objfile
, dwz
);
2917 if (dwz_index_content
.empty ())
2920 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2921 1, dwz_index_content
, &dwz_map
,
2922 &dwz_list
, &dwz_list_elements
,
2924 &dwz_types_elements_ignore
))
2926 warning (_("could not read '.gdb_index' section from %s; skipping"),
2927 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2932 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2935 if (types_list_elements
)
2937 /* We can only handle a single .debug_types when we have an
2939 if (per_bfd
->types
.size () != 1)
2942 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2944 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2945 types_list_elements
);
2948 create_addrmap_from_index (per_objfile
, map
.get ());
2950 per_bfd
->index_table
= std::move (map
);
2951 per_bfd
->using_index
= 1;
2952 per_bfd
->quick_file_names_table
=
2953 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2958 /* die_reader_func for dw2_get_file_names. */
2961 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2962 struct die_info
*comp_unit_die
)
2964 struct dwarf2_cu
*cu
= reader
->cu
;
2965 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2966 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2967 struct dwarf2_per_cu_data
*lh_cu
;
2968 struct attribute
*attr
;
2970 struct quick_file_names
*qfn
;
2972 gdb_assert (! this_cu
->is_debug_types
);
2974 this_cu
->v
.quick
->files_read
= true;
2975 /* Our callers never want to match partial units -- instead they
2976 will match the enclosing full CU. */
2977 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2984 sect_offset line_offset
{};
2986 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2987 if (attr
!= nullptr && attr
->form_is_unsigned ())
2989 struct quick_file_names find_entry
;
2991 line_offset
= (sect_offset
) attr
->as_unsigned ();
2993 /* We may have already read in this line header (TU line header sharing).
2994 If we have we're done. */
2995 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2996 find_entry
.hash
.line_sect_off
= line_offset
;
2997 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2998 &find_entry
, INSERT
);
3001 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3005 lh
= dwarf_decode_line_header (line_offset
, cu
);
3008 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
3011 if (!fnd
.is_unknown ())
3013 else if (lh
== nullptr)
3016 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3017 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3018 qfn
->hash
.line_sect_off
= line_offset
;
3019 /* There may not be a DW_AT_stmt_list. */
3020 if (slot
!= nullptr)
3023 std::vector
<const char *> include_names
;
3026 for (const auto &entry
: lh
->file_names ())
3028 gdb::unique_xmalloc_ptr
<char> name_holder
;
3029 const char *include_name
=
3030 compute_include_file_name (lh
.get (), entry
, fnd
, &name_holder
);
3031 if (include_name
!= nullptr)
3033 include_name
= per_objfile
->objfile
->intern (include_name
);
3034 include_names
.push_back (include_name
);
3039 qfn
->num_file_names
= offset
+ include_names
.size ();
3040 qfn
->comp_dir
= fnd
.intern_comp_dir (per_objfile
->objfile
);
3042 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3043 qfn
->num_file_names
);
3045 qfn
->file_names
[0] = xstrdup (fnd
.get_name ());
3047 if (!include_names
.empty ())
3048 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
3049 include_names
.size () * sizeof (const char *));
3051 qfn
->real_names
= NULL
;
3053 lh_cu
->v
.quick
->file_names
= qfn
;
3056 /* A helper for the "quick" functions which attempts to read the line
3057 table for THIS_CU. */
3059 static struct quick_file_names
*
3060 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3061 dwarf2_per_objfile
*per_objfile
)
3063 /* This should never be called for TUs. */
3064 gdb_assert (! this_cu
->is_debug_types
);
3065 /* Nor type unit groups. */
3066 gdb_assert (! this_cu
->type_unit_group_p ());
3068 if (this_cu
->v
.quick
->files_read
)
3069 return this_cu
->v
.quick
->file_names
;
3071 cutu_reader
reader (this_cu
, per_objfile
);
3072 if (!reader
.dummy_p
)
3073 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3075 return this_cu
->v
.quick
->file_names
;
3078 /* A helper for the "quick" functions which computes and caches the
3079 real path for a given file name from the line table. */
3082 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3083 struct quick_file_names
*qfn
, int index
)
3085 if (qfn
->real_names
== NULL
)
3086 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3087 qfn
->num_file_names
, const char *);
3089 if (qfn
->real_names
[index
] == NULL
)
3091 const char *dirname
= nullptr;
3093 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
3094 dirname
= qfn
->comp_dir
;
3096 gdb::unique_xmalloc_ptr
<char> fullname
;
3097 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
3099 qfn
->real_names
[index
] = fullname
.release ();
3102 return qfn
->real_names
[index
];
3106 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3108 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3109 dwarf2_per_cu_data
*dwarf_cu
3110 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3111 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3116 return 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 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3315 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3318 /* This dumps minimal information about the index.
3319 It is called via "mt print objfiles".
3320 One use is to verify .gdb_index has been loaded by the
3321 gdb.dwarf2/gdb-index.exp testcase. */
3324 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3326 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3328 gdb_assert (per_objfile
->per_bfd
->using_index
);
3329 printf_filtered (".gdb_index:");
3330 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3332 printf_filtered (" version %d\n",
3333 per_objfile
->per_bfd
->index_table
->version
);
3336 printf_filtered (" faked for \"readnow\"\n");
3337 printf_filtered ("\n");
3341 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3343 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3344 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3346 for (int i
= 0; i
< total_units
; ++i
)
3348 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3350 /* We don't want to directly expand a partial CU, because if we
3351 read it with the wrong language, then assertion failures can
3352 be triggered later on. See PR symtab/23010. So, tell
3353 dw2_instantiate_symtab to skip partial CUs -- any important
3354 partial CU will be read via DW_TAG_imported_unit anyway. */
3355 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3360 dw2_expand_symtabs_matching_symbol
3361 (mapped_index_base
&index
,
3362 const lookup_name_info
&lookup_name_in
,
3363 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3364 gdb::function_view
<bool (offset_type
)> match_callback
,
3365 dwarf2_per_objfile
*per_objfile
);
3368 dw2_expand_symtabs_matching_one
3369 (dwarf2_per_cu_data
*per_cu
,
3370 dwarf2_per_objfile
*per_objfile
,
3371 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3372 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3375 dwarf2_gdb_index::expand_matching_symbols
3376 (struct objfile
*objfile
,
3377 const lookup_name_info
&name
, domain_enum domain
,
3379 symbol_compare_ftype
*ordered_compare
)
3382 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3384 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3386 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3388 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3390 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3391 auto matcher
= [&] (const char *symname
)
3393 if (ordered_compare
== nullptr)
3395 return ordered_compare (symname
, match_name
) == 0;
3398 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3399 [&] (offset_type namei
)
3401 struct dw2_symtab_iterator iter
;
3402 struct dwarf2_per_cu_data
*per_cu
;
3404 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3406 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3407 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3414 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3415 proceed assuming all symtabs have been read in. */
3419 /* Starting from a search name, return the string that finds the upper
3420 bound of all strings that start with SEARCH_NAME in a sorted name
3421 list. Returns the empty string to indicate that the upper bound is
3422 the end of the list. */
3425 make_sort_after_prefix_name (const char *search_name
)
3427 /* When looking to complete "func", we find the upper bound of all
3428 symbols that start with "func" by looking for where we'd insert
3429 the closest string that would follow "func" in lexicographical
3430 order. Usually, that's "func"-with-last-character-incremented,
3431 i.e. "fund". Mind non-ASCII characters, though. Usually those
3432 will be UTF-8 multi-byte sequences, but we can't be certain.
3433 Especially mind the 0xff character, which is a valid character in
3434 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3435 rule out compilers allowing it in identifiers. Note that
3436 conveniently, strcmp/strcasecmp are specified to compare
3437 characters interpreted as unsigned char. So what we do is treat
3438 the whole string as a base 256 number composed of a sequence of
3439 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3440 to 0, and carries 1 to the following more-significant position.
3441 If the very first character in SEARCH_NAME ends up incremented
3442 and carries/overflows, then the upper bound is the end of the
3443 list. The string after the empty string is also the empty
3446 Some examples of this operation:
3448 SEARCH_NAME => "+1" RESULT
3452 "\xff" "a" "\xff" => "\xff" "b"
3457 Then, with these symbols for example:
3463 completing "func" looks for symbols between "func" and
3464 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3465 which finds "func" and "func1", but not "fund".
3469 funcÿ (Latin1 'ÿ' [0xff])
3473 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3474 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3478 ÿÿ (Latin1 'ÿ' [0xff])
3481 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3482 the end of the list.
3484 std::string after
= search_name
;
3485 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3487 if (!after
.empty ())
3488 after
.back () = (unsigned char) after
.back () + 1;
3492 /* See declaration. */
3494 std::pair
<std::vector
<name_component
>::const_iterator
,
3495 std::vector
<name_component
>::const_iterator
>
3496 mapped_index_base::find_name_components_bounds
3497 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3498 dwarf2_per_objfile
*per_objfile
) const
3501 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3503 const char *lang_name
3504 = lookup_name_without_params
.language_lookup_name (lang
);
3506 /* Comparison function object for lower_bound that matches against a
3507 given symbol name. */
3508 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3511 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3512 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3513 return name_cmp (elem_name
, name
) < 0;
3516 /* Comparison function object for upper_bound that matches against a
3517 given symbol name. */
3518 auto lookup_compare_upper
= [&] (const char *name
,
3519 const name_component
&elem
)
3521 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3522 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3523 return name_cmp (name
, elem_name
) < 0;
3526 auto begin
= this->name_components
.begin ();
3527 auto end
= this->name_components
.end ();
3529 /* Find the lower bound. */
3532 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3535 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3538 /* Find the upper bound. */
3541 if (lookup_name_without_params
.completion_mode ())
3543 /* In completion mode, we want UPPER to point past all
3544 symbols names that have the same prefix. I.e., with
3545 these symbols, and completing "func":
3547 function << lower bound
3549 other_function << upper bound
3551 We find the upper bound by looking for the insertion
3552 point of "func"-with-last-character-incremented,
3554 std::string after
= make_sort_after_prefix_name (lang_name
);
3557 return std::lower_bound (lower
, end
, after
.c_str (),
3558 lookup_compare_lower
);
3561 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3564 return {lower
, upper
};
3567 /* See declaration. */
3570 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3572 if (!this->name_components
.empty ())
3575 this->name_components_casing
= case_sensitivity
;
3577 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3579 /* The code below only knows how to break apart components of C++
3580 symbol names (and other languages that use '::' as
3581 namespace/module separator) and Ada symbol names. */
3582 auto count
= this->symbol_name_count ();
3583 for (offset_type idx
= 0; idx
< count
; idx
++)
3585 if (this->symbol_name_slot_invalid (idx
))
3588 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3590 /* Add each name component to the name component table. */
3591 unsigned int previous_len
= 0;
3593 if (strstr (name
, "::") != nullptr)
3595 for (unsigned int current_len
= cp_find_first_component (name
);
3596 name
[current_len
] != '\0';
3597 current_len
+= cp_find_first_component (name
+ current_len
))
3599 gdb_assert (name
[current_len
] == ':');
3600 this->name_components
.push_back ({previous_len
, idx
});
3601 /* Skip the '::'. */
3603 previous_len
= current_len
;
3608 /* Handle the Ada encoded (aka mangled) form here. */
3609 for (const char *iter
= strstr (name
, "__");
3611 iter
= strstr (iter
, "__"))
3613 this->name_components
.push_back ({previous_len
, idx
});
3615 previous_len
= iter
- name
;
3619 this->name_components
.push_back ({previous_len
, idx
});
3622 /* Sort name_components elements by name. */
3623 auto name_comp_compare
= [&] (const name_component
&left
,
3624 const name_component
&right
)
3626 const char *left_qualified
3627 = this->symbol_name_at (left
.idx
, per_objfile
);
3628 const char *right_qualified
3629 = this->symbol_name_at (right
.idx
, per_objfile
);
3631 const char *left_name
= left_qualified
+ left
.name_offset
;
3632 const char *right_name
= right_qualified
+ right
.name_offset
;
3634 return name_cmp (left_name
, right_name
) < 0;
3637 std::sort (this->name_components
.begin (),
3638 this->name_components
.end (),
3642 /* Helper for dw2_expand_symtabs_matching that works with a
3643 mapped_index_base instead of the containing objfile. This is split
3644 to a separate function in order to be able to unit test the
3645 name_components matching using a mock mapped_index_base. For each
3646 symbol name that matches, calls MATCH_CALLBACK, passing it the
3647 symbol's index in the mapped_index_base symbol table. */
3650 dw2_expand_symtabs_matching_symbol
3651 (mapped_index_base
&index
,
3652 const lookup_name_info
&lookup_name_in
,
3653 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3654 gdb::function_view
<bool (offset_type
)> match_callback
,
3655 dwarf2_per_objfile
*per_objfile
)
3657 lookup_name_info lookup_name_without_params
3658 = lookup_name_in
.make_ignore_params ();
3660 /* Build the symbol name component sorted vector, if we haven't
3662 index
.build_name_components (per_objfile
);
3664 /* The same symbol may appear more than once in the range though.
3665 E.g., if we're looking for symbols that complete "w", and we have
3666 a symbol named "w1::w2", we'll find the two name components for
3667 that same symbol in the range. To be sure we only call the
3668 callback once per symbol, we first collect the symbol name
3669 indexes that matched in a temporary vector and ignore
3671 std::vector
<offset_type
> matches
;
3673 struct name_and_matcher
3675 symbol_name_matcher_ftype
*matcher
;
3678 bool operator== (const name_and_matcher
&other
) const
3680 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3684 /* A vector holding all the different symbol name matchers, for all
3686 std::vector
<name_and_matcher
> matchers
;
3688 for (int i
= 0; i
< nr_languages
; i
++)
3690 enum language lang_e
= (enum language
) i
;
3692 const language_defn
*lang
= language_def (lang_e
);
3693 symbol_name_matcher_ftype
*name_matcher
3694 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3696 name_and_matcher key
{
3698 lookup_name_without_params
.language_lookup_name (lang_e
)
3701 /* Don't insert the same comparison routine more than once.
3702 Note that we do this linear walk. This is not a problem in
3703 practice because the number of supported languages is
3705 if (std::find (matchers
.begin (), matchers
.end (), key
)
3708 matchers
.push_back (std::move (key
));
3711 = index
.find_name_components_bounds (lookup_name_without_params
,
3712 lang_e
, per_objfile
);
3714 /* Now for each symbol name in range, check to see if we have a name
3715 match, and if so, call the MATCH_CALLBACK callback. */
3717 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3719 const char *qualified
3720 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3722 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3723 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3726 matches
.push_back (bounds
.first
->idx
);
3730 std::sort (matches
.begin (), matches
.end ());
3732 /* Finally call the callback, once per match. */
3735 for (offset_type idx
: matches
)
3739 if (!match_callback (idx
))
3748 /* Above we use a type wider than idx's for 'prev', since 0 and
3749 (offset_type)-1 are both possible values. */
3750 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3757 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3759 /* A mock .gdb_index/.debug_names-like name index table, enough to
3760 exercise dw2_expand_symtabs_matching_symbol, which works with the
3761 mapped_index_base interface. Builds an index from the symbol list
3762 passed as parameter to the constructor. */
3763 class mock_mapped_index
: public mapped_index_base
3766 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3767 : m_symbol_table (symbols
)
3770 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3772 /* Return the number of names in the symbol table. */
3773 size_t symbol_name_count () const override
3775 return m_symbol_table
.size ();
3778 /* Get the name of the symbol at IDX in the symbol table. */
3779 const char *symbol_name_at
3780 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3782 return m_symbol_table
[idx
];
3786 gdb::array_view
<const char *> m_symbol_table
;
3789 /* Convenience function that converts a NULL pointer to a "<null>"
3790 string, to pass to print routines. */
3793 string_or_null (const char *str
)
3795 return str
!= NULL
? str
: "<null>";
3798 /* Check if a lookup_name_info built from
3799 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3800 index. EXPECTED_LIST is the list of expected matches, in expected
3801 matching order. If no match expected, then an empty list is
3802 specified. Returns true on success. On failure prints a warning
3803 indicating the file:line that failed, and returns false. */
3806 check_match (const char *file
, int line
,
3807 mock_mapped_index
&mock_index
,
3808 const char *name
, symbol_name_match_type match_type
,
3809 bool completion_mode
,
3810 std::initializer_list
<const char *> expected_list
,
3811 dwarf2_per_objfile
*per_objfile
)
3813 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3815 bool matched
= true;
3817 auto mismatch
= [&] (const char *expected_str
,
3820 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3821 "expected=\"%s\", got=\"%s\"\n"),
3823 (match_type
== symbol_name_match_type::FULL
3825 name
, string_or_null (expected_str
), string_or_null (got
));
3829 auto expected_it
= expected_list
.begin ();
3830 auto expected_end
= expected_list
.end ();
3832 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3834 [&] (offset_type idx
)
3836 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3837 const char *expected_str
3838 = expected_it
== expected_end
? NULL
: *expected_it
++;
3840 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3841 mismatch (expected_str
, matched_name
);
3845 const char *expected_str
3846 = expected_it
== expected_end
? NULL
: *expected_it
++;
3847 if (expected_str
!= NULL
)
3848 mismatch (expected_str
, NULL
);
3853 /* The symbols added to the mock mapped_index for testing (in
3855 static const char *test_symbols
[] = {
3864 "ns2::tmpl<int>::foo2",
3865 "(anonymous namespace)::A::B::C",
3867 /* These are used to check that the increment-last-char in the
3868 matching algorithm for completion doesn't match "t1_fund" when
3869 completing "t1_func". */
3875 /* A UTF-8 name with multi-byte sequences to make sure that
3876 cp-name-parser understands this as a single identifier ("função"
3877 is "function" in PT). */
3880 /* \377 (0xff) is Latin1 'ÿ'. */
3883 /* \377 (0xff) is Latin1 'ÿ'. */
3887 /* A name with all sorts of complications. Starts with "z" to make
3888 it easier for the completion tests below. */
3889 #define Z_SYM_NAME \
3890 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3891 "::tuple<(anonymous namespace)::ui*, " \
3892 "std::default_delete<(anonymous namespace)::ui>, void>"
3897 /* Returns true if the mapped_index_base::find_name_component_bounds
3898 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3899 in completion mode. */
3902 check_find_bounds_finds (mapped_index_base
&index
,
3903 const char *search_name
,
3904 gdb::array_view
<const char *> expected_syms
,
3905 dwarf2_per_objfile
*per_objfile
)
3907 lookup_name_info
lookup_name (search_name
,
3908 symbol_name_match_type::FULL
, true);
3910 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3914 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3915 if (distance
!= expected_syms
.size ())
3918 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3920 auto nc_elem
= bounds
.first
+ exp_elem
;
3921 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3922 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3929 /* Test the lower-level mapped_index::find_name_component_bounds
3933 test_mapped_index_find_name_component_bounds ()
3935 mock_mapped_index
mock_index (test_symbols
);
3937 mock_index
.build_name_components (NULL
/* per_objfile */);
3939 /* Test the lower-level mapped_index::find_name_component_bounds
3940 method in completion mode. */
3942 static const char *expected_syms
[] = {
3947 SELF_CHECK (check_find_bounds_finds
3948 (mock_index
, "t1_func", expected_syms
,
3949 NULL
/* per_objfile */));
3952 /* Check that the increment-last-char in the name matching algorithm
3953 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3955 static const char *expected_syms1
[] = {
3959 SELF_CHECK (check_find_bounds_finds
3960 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3962 static const char *expected_syms2
[] = {
3965 SELF_CHECK (check_find_bounds_finds
3966 (mock_index
, "\377\377", expected_syms2
,
3967 NULL
/* per_objfile */));
3971 /* Test dw2_expand_symtabs_matching_symbol. */
3974 test_dw2_expand_symtabs_matching_symbol ()
3976 mock_mapped_index
mock_index (test_symbols
);
3978 /* We let all tests run until the end even if some fails, for debug
3980 bool any_mismatch
= false;
3982 /* Create the expected symbols list (an initializer_list). Needed
3983 because lists have commas, and we need to pass them to CHECK,
3984 which is a macro. */
3985 #define EXPECT(...) { __VA_ARGS__ }
3987 /* Wrapper for check_match that passes down the current
3988 __FILE__/__LINE__. */
3989 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3990 any_mismatch |= !check_match (__FILE__, __LINE__, \
3992 NAME, MATCH_TYPE, COMPLETION_MODE, \
3993 EXPECTED_LIST, NULL)
3995 /* Identity checks. */
3996 for (const char *sym
: test_symbols
)
3998 /* Should be able to match all existing symbols. */
3999 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4002 /* Should be able to match all existing symbols with
4004 std::string with_params
= std::string (sym
) + "(int)";
4005 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4008 /* Should be able to match all existing symbols with
4009 parameters and qualifiers. */
4010 with_params
= std::string (sym
) + " ( int ) const";
4011 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4014 /* This should really find sym, but cp-name-parser.y doesn't
4015 know about lvalue/rvalue qualifiers yet. */
4016 with_params
= std::string (sym
) + " ( int ) &&";
4017 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4021 /* Check that the name matching algorithm for completion doesn't get
4022 confused with Latin1 'ÿ' / 0xff. */
4024 static const char str
[] = "\377";
4025 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4026 EXPECT ("\377", "\377\377123"));
4029 /* Check that the increment-last-char in the matching algorithm for
4030 completion doesn't match "t1_fund" when completing "t1_func". */
4032 static const char str
[] = "t1_func";
4033 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4034 EXPECT ("t1_func", "t1_func1"));
4037 /* Check that completion mode works at each prefix of the expected
4040 static const char str
[] = "function(int)";
4041 size_t len
= strlen (str
);
4044 for (size_t i
= 1; i
< len
; i
++)
4046 lookup
.assign (str
, i
);
4047 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4048 EXPECT ("function"));
4052 /* While "w" is a prefix of both components, the match function
4053 should still only be called once. */
4055 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4057 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4061 /* Same, with a "complicated" symbol. */
4063 static const char str
[] = Z_SYM_NAME
;
4064 size_t len
= strlen (str
);
4067 for (size_t i
= 1; i
< len
; i
++)
4069 lookup
.assign (str
, i
);
4070 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4071 EXPECT (Z_SYM_NAME
));
4075 /* In FULL mode, an incomplete symbol doesn't match. */
4077 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4081 /* A complete symbol with parameters matches any overload, since the
4082 index has no overload info. */
4084 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4085 EXPECT ("std::zfunction", "std::zfunction2"));
4086 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4087 EXPECT ("std::zfunction", "std::zfunction2"));
4088 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4089 EXPECT ("std::zfunction", "std::zfunction2"));
4092 /* Check that whitespace is ignored appropriately. A symbol with a
4093 template argument list. */
4095 static const char expected
[] = "ns::foo<int>";
4096 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4098 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4102 /* Check that whitespace is ignored appropriately. A symbol with a
4103 template argument list that includes a pointer. */
4105 static const char expected
[] = "ns::foo<char*>";
4106 /* Try both completion and non-completion modes. */
4107 static const bool completion_mode
[2] = {false, true};
4108 for (size_t i
= 0; i
< 2; i
++)
4110 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4111 completion_mode
[i
], EXPECT (expected
));
4112 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4113 completion_mode
[i
], EXPECT (expected
));
4115 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4116 completion_mode
[i
], EXPECT (expected
));
4117 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4118 completion_mode
[i
], EXPECT (expected
));
4123 /* Check method qualifiers are ignored. */
4124 static const char expected
[] = "ns::foo<char*>";
4125 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4126 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4127 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4128 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4129 CHECK_MATCH ("foo < char * > ( int ) const",
4130 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4131 CHECK_MATCH ("foo < char * > ( int ) &&",
4132 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4135 /* Test lookup names that don't match anything. */
4137 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4140 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4144 /* Some wild matching tests, exercising "(anonymous namespace)",
4145 which should not be confused with a parameter list. */
4147 static const char *syms
[] = {
4151 "A :: B :: C ( int )",
4156 for (const char *s
: syms
)
4158 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4159 EXPECT ("(anonymous namespace)::A::B::C"));
4164 static const char expected
[] = "ns2::tmpl<int>::foo2";
4165 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4167 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4171 SELF_CHECK (!any_mismatch
);
4180 test_mapped_index_find_name_component_bounds ();
4181 test_dw2_expand_symtabs_matching_symbol ();
4184 }} // namespace selftests::dw2_expand_symtabs_matching
4186 #endif /* GDB_SELF_TEST */
4188 /* If FILE_MATCHER is NULL or if PER_CU has
4189 dwarf2_per_cu_quick_data::MARK set (see
4190 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4191 EXPANSION_NOTIFY on it. */
4194 dw2_expand_symtabs_matching_one
4195 (dwarf2_per_cu_data
*per_cu
,
4196 dwarf2_per_objfile
*per_objfile
,
4197 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4198 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4200 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4202 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4204 compunit_symtab
*symtab
4205 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4206 gdb_assert (symtab
!= nullptr);
4208 if (expansion_notify
!= NULL
&& symtab_was_null
)
4209 return expansion_notify (symtab
);
4214 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4215 matched, to expand corresponding CUs that were marked. IDX is the
4216 index of the symbol name that matched. */
4219 dw2_expand_marked_cus
4220 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4221 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4222 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4223 block_search_flags search_flags
,
4226 offset_type vec_len
, vec_idx
;
4227 bool global_seen
= false;
4228 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4230 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4232 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4234 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4235 /* This value is only valid for index versions >= 7. */
4236 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4237 gdb_index_symbol_kind symbol_kind
=
4238 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4239 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4240 /* Only check the symbol attributes if they're present.
4241 Indices prior to version 7 don't record them,
4242 and indices >= 7 may elide them for certain symbols
4243 (gold does this). */
4246 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4248 /* Work around gold/15646. */
4251 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4259 /* Only check the symbol's kind if it has one. */
4264 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4269 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4275 case VARIABLES_DOMAIN
:
4276 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4279 case FUNCTIONS_DOMAIN
:
4280 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4284 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4287 case MODULES_DOMAIN
:
4288 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4296 /* Don't crash on bad data. */
4297 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4299 complaint (_(".gdb_index entry has bad CU index"
4300 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4304 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4305 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4313 /* If FILE_MATCHER is non-NULL, set all the
4314 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4315 that match FILE_MATCHER. */
4318 dw_expand_symtabs_matching_file_matcher
4319 (dwarf2_per_objfile
*per_objfile
,
4320 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4322 if (file_matcher
== NULL
)
4325 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4327 NULL
, xcalloc
, xfree
));
4328 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4330 NULL
, xcalloc
, xfree
));
4332 /* The rule is CUs specify all the files, including those used by
4333 any TU, so there's no need to scan TUs here. */
4335 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4339 if (per_cu
->is_debug_types
)
4341 per_cu
->v
.quick
->mark
= 0;
4343 /* We only need to look at symtabs not already expanded. */
4344 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4347 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4349 if (file_data
== NULL
)
4352 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4354 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4356 per_cu
->v
.quick
->mark
= 1;
4360 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4362 const char *this_real_name
;
4364 if (file_matcher (file_data
->file_names
[j
], false))
4366 per_cu
->v
.quick
->mark
= 1;
4370 /* Before we invoke realpath, which can get expensive when many
4371 files are involved, do a quick comparison of the basenames. */
4372 if (!basenames_may_differ
4373 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4377 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4378 if (file_matcher (this_real_name
, false))
4380 per_cu
->v
.quick
->mark
= 1;
4385 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4386 ? visited_found
.get ()
4387 : visited_not_found
.get (),
4394 dwarf2_gdb_index::expand_symtabs_matching
4395 (struct objfile
*objfile
,
4396 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4397 const lookup_name_info
*lookup_name
,
4398 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4399 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4400 block_search_flags search_flags
,
4402 enum search_domain kind
)
4404 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4406 /* index_table is NULL if OBJF_READNOW. */
4407 if (!per_objfile
->per_bfd
->index_table
)
4410 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4412 /* This invariant is documented in quick-functions.h. */
4413 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
4414 if (lookup_name
== nullptr)
4416 for (dwarf2_per_cu_data
*per_cu
4417 : all_comp_units_range (per_objfile
->per_bfd
))
4421 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4429 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4432 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4434 [&] (offset_type idx
)
4436 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4437 expansion_notify
, search_flags
, kind
))
4445 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4448 static struct compunit_symtab
*
4449 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4454 if (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 printf_filtered (".debug_names:");
5338 if (per_objfile
->per_bfd
->debug_names_table
)
5339 printf_filtered (" exists\n");
5341 printf_filtered (" faked for \"readnow\"\n");
5342 printf_filtered ("\n");
5346 dwarf2_debug_names_index::expand_matching_symbols
5347 (struct objfile
*objfile
,
5348 const lookup_name_info
&name
, domain_enum domain
,
5350 symbol_compare_ftype
*ordered_compare
)
5352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5354 /* debug_names_table is NULL if OBJF_READNOW. */
5355 if (!per_objfile
->per_bfd
->debug_names_table
)
5358 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5359 const block_search_flags block_flags
5360 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5362 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5363 auto matcher
= [&] (const char *symname
)
5365 if (ordered_compare
== nullptr)
5367 return ordered_compare (symname
, match_name
) == 0;
5370 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5371 [&] (offset_type namei
)
5373 /* The name was matched, now expand corresponding CUs that were
5375 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5378 struct dwarf2_per_cu_data
*per_cu
;
5379 while ((per_cu
= iter
.next ()) != NULL
)
5380 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5387 dwarf2_debug_names_index::expand_symtabs_matching
5388 (struct objfile
*objfile
,
5389 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5390 const lookup_name_info
*lookup_name
,
5391 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5392 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5393 block_search_flags search_flags
,
5395 enum search_domain kind
)
5397 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5399 /* debug_names_table is NULL if OBJF_READNOW. */
5400 if (!per_objfile
->per_bfd
->debug_names_table
)
5403 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5405 /* This invariant is documented in quick-functions.h. */
5406 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
5407 if (lookup_name
== nullptr)
5409 for (dwarf2_per_cu_data
*per_cu
5410 : all_comp_units_range (per_objfile
->per_bfd
))
5414 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5422 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5425 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5427 [&] (offset_type namei
)
5429 /* The name was matched, now expand corresponding CUs that were
5431 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5433 struct dwarf2_per_cu_data
*per_cu
;
5434 while ((per_cu
= iter
.next ()) != NULL
)
5435 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5445 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5446 to either a dwarf2_per_bfd or dwz_file object. */
5448 template <typename T
>
5449 static gdb::array_view
<const gdb_byte
>
5450 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5452 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5454 if (section
->empty ())
5457 /* Older elfutils strip versions could keep the section in the main
5458 executable while splitting it for the separate debug info file. */
5459 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5462 section
->read (obj
);
5464 /* dwarf2_section_info::size is a bfd_size_type, while
5465 gdb::array_view works with size_t. On 32-bit hosts, with
5466 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5467 is 32-bit. So we need an explicit narrowing conversion here.
5468 This is fine, because it's impossible to allocate or mmap an
5469 array/buffer larger than what size_t can represent. */
5470 return gdb::make_array_view (section
->buffer
, section
->size
);
5473 /* Lookup the index cache for the contents of the index associated to
5476 static gdb::array_view
<const gdb_byte
>
5477 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5479 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5480 if (build_id
== nullptr)
5483 return global_index_cache
.lookup_gdb_index (build_id
,
5484 &dwarf2_per_bfd
->index_cache_res
);
5487 /* Same as the above, but for DWZ. */
5489 static gdb::array_view
<const gdb_byte
>
5490 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5492 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5493 if (build_id
== nullptr)
5496 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5499 /* See dwarf2/public.h. */
5502 dwarf2_initialize_objfile (struct objfile
*objfile
)
5504 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5505 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5507 dwarf_read_debug_printf ("called");
5509 /* If we're about to read full symbols, don't bother with the
5510 indices. In this case we also don't care if some other debug
5511 format is making psymtabs, because they are all about to be
5513 if ((objfile
->flags
& OBJF_READNOW
))
5515 dwarf_read_debug_printf ("readnow requested");
5517 /* When using READNOW, the using_index flag (set below) indicates that
5518 PER_BFD was already initialized, when we loaded some other objfile. */
5519 if (per_bfd
->using_index
)
5521 dwarf_read_debug_printf ("using_index already set");
5522 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5526 per_bfd
->using_index
= 1;
5527 create_all_comp_units (per_objfile
);
5528 per_bfd
->quick_file_names_table
5529 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5531 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5533 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5535 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5536 struct dwarf2_per_cu_quick_data
);
5539 /* Arrange for gdb to see the "quick" functions. However, these
5540 functions will be no-ops because we will have expanded all
5542 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5546 /* Was a debug names index already read when we processed an objfile sharing
5548 if (per_bfd
->debug_names_table
!= nullptr)
5550 dwarf_read_debug_printf ("re-using shared debug names table");
5551 objfile
->qf
.push_front (make_dwarf_debug_names ());
5555 /* Was a GDB index already read when we processed an objfile sharing
5557 if (per_bfd
->index_table
!= nullptr)
5559 dwarf_read_debug_printf ("re-using shared index table");
5560 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5564 /* There might already be partial symtabs built for this BFD. This happens
5565 when loading the same binary twice with the index-cache enabled. If so,
5566 don't try to read an index. The objfile / per_objfile initialization will
5567 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5569 if (per_bfd
->partial_symtabs
!= nullptr)
5571 dwarf_read_debug_printf ("re-using shared partial symtabs");
5572 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5576 if (dwarf2_read_debug_names (per_objfile
))
5578 dwarf_read_debug_printf ("found debug names");
5579 objfile
->qf
.push_front (make_dwarf_debug_names ());
5583 if (dwarf2_read_gdb_index (per_objfile
,
5584 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5585 get_gdb_index_contents_from_section
<dwz_file
>))
5587 dwarf_read_debug_printf ("found gdb index from file");
5588 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5592 /* ... otherwise, try to find the index in the index cache. */
5593 if (dwarf2_read_gdb_index (per_objfile
,
5594 get_gdb_index_contents_from_cache
,
5595 get_gdb_index_contents_from_cache_dwz
))
5597 dwarf_read_debug_printf ("found gdb index from cache");
5598 global_index_cache
.hit ();
5599 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5603 global_index_cache
.miss ();
5604 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5609 /* Build a partial symbol table. */
5612 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5614 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5615 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5617 if (per_bfd
->partial_symtabs
!= nullptr)
5619 /* Partial symbols were already read, so now we can simply
5623 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5624 objfile
->qf
.emplace_front (psf
);
5627 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5633 psf
= new psymbol_functions
;
5634 objfile
->qf
.emplace_front (psf
);
5636 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5637 = psf
->get_partial_symtabs ();
5639 /* Set the local reference to partial symtabs, so that we don't try
5640 to read them again if reading another objfile with the same BFD.
5641 If we can't in fact share, this won't make a difference anyway as
5642 the dwarf2_per_bfd object won't be shared. */
5643 per_bfd
->partial_symtabs
= partial_symtabs
;
5647 /* This isn't really ideal: all the data we allocate on the
5648 objfile's obstack is still uselessly kept around. However,
5649 freeing it seems unsafe. */
5650 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5651 dwarf2_build_psymtabs_hard (per_objfile
);
5654 /* (maybe) store an index in the cache. */
5655 global_index_cache
.store (per_objfile
);
5657 catch (const gdb_exception_error
&except
)
5659 exception_print (gdb_stderr
, except
);
5663 /* Find the base address of the compilation unit for range lists and
5664 location lists. It will normally be specified by DW_AT_low_pc.
5665 In DWARF-3 draft 4, the base address could be overridden by
5666 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5667 compilation units with discontinuous ranges. */
5670 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5672 struct attribute
*attr
;
5674 cu
->base_address
.reset ();
5676 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5677 if (attr
!= nullptr)
5678 cu
->base_address
= attr
->as_address ();
5681 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5682 if (attr
!= nullptr)
5683 cu
->base_address
= attr
->as_address ();
5687 /* Helper function that returns the proper abbrev section for
5690 static struct dwarf2_section_info
*
5691 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5693 struct dwarf2_section_info
*abbrev
;
5694 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5696 if (this_cu
->is_dwz
)
5697 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5699 abbrev
= &per_bfd
->abbrev
;
5704 /* Fetch the abbreviation table offset from a comp or type unit header. */
5707 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5708 struct dwarf2_section_info
*section
,
5709 sect_offset sect_off
)
5711 bfd
*abfd
= section
->get_bfd_owner ();
5712 const gdb_byte
*info_ptr
;
5713 unsigned int initial_length_size
, offset_size
;
5716 section
->read (per_objfile
->objfile
);
5717 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5718 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5719 offset_size
= initial_length_size
== 4 ? 4 : 8;
5720 info_ptr
+= initial_length_size
;
5722 version
= read_2_bytes (abfd
, info_ptr
);
5726 /* Skip unit type and address size. */
5730 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5733 /* A partial symtab that is used only for include files. */
5734 struct dwarf2_include_psymtab
: public partial_symtab
5736 dwarf2_include_psymtab (const char *filename
,
5737 psymtab_storage
*partial_symtabs
,
5738 objfile_per_bfd_storage
*objfile_per_bfd
)
5739 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5743 void read_symtab (struct objfile
*objfile
) override
5745 /* It's an include file, no symbols to read for it.
5746 Everything is in the includer symtab. */
5748 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5749 expansion of the includer psymtab. We use the dependencies[0] field to
5750 model the includer. But if we go the regular route of calling
5751 expand_psymtab here, and having expand_psymtab call expand_dependencies
5752 to expand the includer, we'll only use expand_psymtab on the includer
5753 (making it a non-toplevel psymtab), while if we expand the includer via
5754 another path, we'll use read_symtab (making it a toplevel psymtab).
5755 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5756 psymtab, and trigger read_symtab on the includer here directly. */
5757 includer ()->read_symtab (objfile
);
5760 void expand_psymtab (struct objfile
*objfile
) override
5762 /* This is not called by read_symtab, and should not be called by any
5763 expand_dependencies. */
5767 bool readin_p (struct objfile
*objfile
) const override
5769 return includer ()->readin_p (objfile
);
5772 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5774 compunit_symtab
*cust
= includer ()->get_compunit_symtab (objfile
);
5775 while (cust
!= nullptr && cust
->user
!= nullptr)
5781 partial_symtab
*includer () const
5783 /* An include psymtab has exactly one dependency: the psymtab that
5785 gdb_assert (this->number_of_dependencies
== 1);
5786 return this->dependencies
[0];
5790 /* Allocate a new partial symtab for file named NAME and mark this new
5791 partial symtab as being an include of PST. */
5794 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5796 dwarf2_psymtab
*pst
,
5797 psymtab_storage
*partial_symtabs
,
5798 objfile_per_bfd_storage
*objfile_per_bfd
)
5800 dwarf2_include_psymtab
*subpst
5801 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5803 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5804 subpst
->dirname
= pst
->dirname
;
5806 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5807 subpst
->dependencies
[0] = pst
;
5808 subpst
->number_of_dependencies
= 1;
5811 /* Read the Line Number Program data and extract the list of files
5812 included by the source file represented by PST. Build an include
5813 partial symtab for each of these included files. */
5816 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5817 struct die_info
*die
,
5818 const file_and_directory
&fnd
,
5819 dwarf2_psymtab
*pst
)
5822 struct attribute
*attr
;
5824 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5825 if (attr
!= nullptr && attr
->form_is_unsigned ())
5826 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5828 return; /* No linetable, so no includes. */
5830 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5831 that we pass in the raw text_low here; that is ok because we're
5832 only decoding the line table to make include partial symtabs, and
5833 so the addresses aren't really used. */
5834 dwarf_decode_lines (lh
.get (), fnd
, cu
, pst
,
5835 pst
->raw_text_low (), 1);
5839 hash_signatured_type (const void *item
)
5841 const struct signatured_type
*sig_type
5842 = (const struct signatured_type
*) item
;
5844 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5845 return sig_type
->signature
;
5849 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5851 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5852 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5854 return lhs
->signature
== rhs
->signature
;
5857 /* Allocate a hash table for signatured types. */
5860 allocate_signatured_type_table ()
5862 return htab_up (htab_create_alloc (41,
5863 hash_signatured_type
,
5865 NULL
, xcalloc
, xfree
));
5868 /* A helper for create_debug_types_hash_table. Read types from SECTION
5869 and fill them into TYPES_HTAB. It will process only type units,
5870 therefore DW_UT_type. */
5873 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5874 struct dwo_file
*dwo_file
,
5875 dwarf2_section_info
*section
, htab_up
&types_htab
,
5876 rcuh_kind section_kind
)
5878 struct objfile
*objfile
= per_objfile
->objfile
;
5879 struct dwarf2_section_info
*abbrev_section
;
5881 const gdb_byte
*info_ptr
, *end_ptr
;
5883 abbrev_section
= &dwo_file
->sections
.abbrev
;
5885 dwarf_read_debug_printf ("Reading %s for %s",
5886 section
->get_name (),
5887 abbrev_section
->get_file_name ());
5889 section
->read (objfile
);
5890 info_ptr
= section
->buffer
;
5892 if (info_ptr
== NULL
)
5895 /* We can't set abfd until now because the section may be empty or
5896 not present, in which case the bfd is unknown. */
5897 abfd
= section
->get_bfd_owner ();
5899 /* We don't use cutu_reader here because we don't need to read
5900 any dies: the signature is in the header. */
5902 end_ptr
= info_ptr
+ section
->size
;
5903 while (info_ptr
< end_ptr
)
5905 signatured_type_up sig_type
;
5906 struct dwo_unit
*dwo_tu
;
5908 const gdb_byte
*ptr
= info_ptr
;
5909 struct comp_unit_head header
;
5910 unsigned int length
;
5912 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5914 /* Initialize it due to a false compiler warning. */
5915 header
.signature
= -1;
5916 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5918 /* We need to read the type's signature in order to build the hash
5919 table, but we don't need anything else just yet. */
5921 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5922 abbrev_section
, ptr
, section_kind
);
5924 length
= header
.get_length ();
5926 /* Skip dummy type units. */
5927 if (ptr
>= info_ptr
+ length
5928 || peek_abbrev_code (abfd
, ptr
) == 0
5929 || (header
.unit_type
!= DW_UT_type
5930 && header
.unit_type
!= DW_UT_split_type
))
5936 if (types_htab
== NULL
)
5937 types_htab
= allocate_dwo_unit_table ();
5939 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5940 dwo_tu
->dwo_file
= dwo_file
;
5941 dwo_tu
->signature
= header
.signature
;
5942 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5943 dwo_tu
->section
= section
;
5944 dwo_tu
->sect_off
= sect_off
;
5945 dwo_tu
->length
= length
;
5947 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5948 gdb_assert (slot
!= NULL
);
5950 complaint (_("debug type entry at offset %s is duplicate to"
5951 " the entry at offset %s, signature %s"),
5952 sect_offset_str (sect_off
),
5953 sect_offset_str (dwo_tu
->sect_off
),
5954 hex_string (header
.signature
));
5957 dwarf_read_debug_printf_v (" offset %s, signature %s",
5958 sect_offset_str (sect_off
),
5959 hex_string (header
.signature
));
5965 /* Create the hash table of all entries in the .debug_types
5966 (or .debug_types.dwo) section(s).
5967 DWO_FILE is a pointer to the DWO file object.
5969 The result is a pointer to the hash table or NULL if there are no types.
5971 Note: This function processes DWO files only, not DWP files. */
5974 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5975 struct dwo_file
*dwo_file
,
5976 gdb::array_view
<dwarf2_section_info
> type_sections
,
5977 htab_up
&types_htab
)
5979 for (dwarf2_section_info
§ion
: type_sections
)
5980 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5984 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5985 If SLOT is non-NULL, it is the entry to use in the hash table.
5986 Otherwise we find one. */
5988 static struct signatured_type
*
5989 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5991 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5992 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5993 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5995 signatured_type_up sig_type_holder
5996 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
5997 signatured_type
*sig_type
= sig_type_holder
.get ();
5999 per_objfile
->per_bfd
->all_comp_units
.emplace_back
6000 (sig_type_holder
.release ());
6001 if (per_objfile
->per_bfd
->using_index
)
6004 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6005 struct dwarf2_per_cu_quick_data
);
6010 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6013 gdb_assert (*slot
== NULL
);
6015 /* The rest of sig_type must be filled in by the caller. */
6019 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6020 Fill in SIG_ENTRY with DWO_ENTRY. */
6023 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6024 struct signatured_type
*sig_entry
,
6025 struct dwo_unit
*dwo_entry
)
6027 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6029 /* Make sure we're not clobbering something we don't expect to. */
6030 gdb_assert (! sig_entry
->queued
);
6031 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6032 if (per_bfd
->using_index
)
6034 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6035 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6038 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6039 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6040 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6041 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6042 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6044 sig_entry
->section
= dwo_entry
->section
;
6045 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6046 sig_entry
->length
= dwo_entry
->length
;
6047 sig_entry
->reading_dwo_directly
= 1;
6048 sig_entry
->per_bfd
= per_bfd
;
6049 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6050 sig_entry
->dwo_unit
= dwo_entry
;
6053 /* Subroutine of lookup_signatured_type.
6054 If we haven't read the TU yet, create the signatured_type data structure
6055 for a TU to be read in directly from a DWO file, bypassing the stub.
6056 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6057 using .gdb_index, then when reading a CU we want to stay in the DWO file
6058 containing that CU. Otherwise we could end up reading several other DWO
6059 files (due to comdat folding) to process the transitive closure of all the
6060 mentioned TUs, and that can be slow. The current DWO file will have every
6061 type signature that it needs.
6062 We only do this for .gdb_index because in the psymtab case we already have
6063 to read all the DWOs to build the type unit groups. */
6065 static struct signatured_type
*
6066 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6068 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6069 struct dwo_file
*dwo_file
;
6070 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6073 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6075 /* If TU skeletons have been removed then we may not have read in any
6077 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6078 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6080 /* We only ever need to read in one copy of a signatured type.
6081 Use the global signatured_types array to do our own comdat-folding
6082 of types. If this is the first time we're reading this TU, and
6083 the TU has an entry in .gdb_index, replace the recorded data from
6084 .gdb_index with this TU. */
6086 signatured_type
find_sig_entry (sig
);
6087 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6088 &find_sig_entry
, INSERT
);
6089 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6091 /* We can get here with the TU already read, *or* in the process of being
6092 read. Don't reassign the global entry to point to this DWO if that's
6093 the case. Also note that if the TU is already being read, it may not
6094 have come from a DWO, the program may be a mix of Fission-compiled
6095 code and non-Fission-compiled code. */
6097 /* Have we already tried to read this TU?
6098 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6099 needn't exist in the global table yet). */
6100 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6103 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6104 dwo_unit of the TU itself. */
6105 dwo_file
= cu
->dwo_unit
->dwo_file
;
6107 /* Ok, this is the first time we're reading this TU. */
6108 if (dwo_file
->tus
== NULL
)
6110 find_dwo_entry
.signature
= sig
;
6111 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6113 if (dwo_entry
== NULL
)
6116 /* If the global table doesn't have an entry for this TU, add one. */
6117 if (sig_entry
== NULL
)
6118 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6120 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6121 sig_entry
->tu_read
= 1;
6125 /* Subroutine of lookup_signatured_type.
6126 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6127 then try the DWP file. If the TU stub (skeleton) has been removed then
6128 it won't be in .gdb_index. */
6130 static struct signatured_type
*
6131 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6133 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6134 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6135 struct dwo_unit
*dwo_entry
;
6138 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6139 gdb_assert (dwp_file
!= NULL
);
6141 /* If TU skeletons have been removed then we may not have read in any
6143 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6144 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6146 signatured_type
find_sig_entry (sig
);
6147 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6148 &find_sig_entry
, INSERT
);
6149 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6151 /* Have we already tried to read this TU?
6152 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6153 needn't exist in the global table yet). */
6154 if (sig_entry
!= NULL
)
6157 if (dwp_file
->tus
== NULL
)
6159 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6160 1 /* is_debug_types */);
6161 if (dwo_entry
== NULL
)
6164 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6165 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6170 /* Lookup a signature based type for DW_FORM_ref_sig8.
6171 Returns NULL if signature SIG is not present in the table.
6172 It is up to the caller to complain about this. */
6174 static struct signatured_type
*
6175 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6177 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6179 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6181 /* We're in a DWO/DWP file, and we're using .gdb_index.
6182 These cases require special processing. */
6183 if (get_dwp_file (per_objfile
) == NULL
)
6184 return lookup_dwo_signatured_type (cu
, sig
);
6186 return lookup_dwp_signatured_type (cu
, sig
);
6190 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6192 signatured_type
find_entry (sig
);
6193 return ((struct signatured_type
*)
6194 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6199 /* Low level DIE reading support. */
6201 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6204 init_cu_die_reader (struct die_reader_specs
*reader
,
6205 struct dwarf2_cu
*cu
,
6206 struct dwarf2_section_info
*section
,
6207 struct dwo_file
*dwo_file
,
6208 struct abbrev_table
*abbrev_table
)
6210 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6211 reader
->abfd
= section
->get_bfd_owner ();
6213 reader
->dwo_file
= dwo_file
;
6214 reader
->die_section
= section
;
6215 reader
->buffer
= section
->buffer
;
6216 reader
->buffer_end
= section
->buffer
+ section
->size
;
6217 reader
->abbrev_table
= abbrev_table
;
6220 /* Subroutine of cutu_reader to simplify it.
6221 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6222 There's just a lot of work to do, and cutu_reader is big enough
6225 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6226 from it to the DIE in the DWO. If NULL we are skipping the stub.
6227 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6228 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6229 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6230 STUB_COMP_DIR may be non-NULL.
6231 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6232 are filled in with the info of the DIE from the DWO file.
6233 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6234 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6235 kept around for at least as long as *RESULT_READER.
6237 The result is non-zero if a valid (non-dummy) DIE was found. */
6240 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6241 struct dwo_unit
*dwo_unit
,
6242 struct die_info
*stub_comp_unit_die
,
6243 const char *stub_comp_dir
,
6244 struct die_reader_specs
*result_reader
,
6245 const gdb_byte
**result_info_ptr
,
6246 struct die_info
**result_comp_unit_die
,
6247 abbrev_table_up
*result_dwo_abbrev_table
)
6249 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6250 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6251 struct objfile
*objfile
= per_objfile
->objfile
;
6253 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6254 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6255 int i
,num_extra_attrs
;
6256 struct dwarf2_section_info
*dwo_abbrev_section
;
6257 struct die_info
*comp_unit_die
;
6259 /* At most one of these may be provided. */
6260 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6262 /* These attributes aren't processed until later:
6263 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6264 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6265 referenced later. However, these attributes are found in the stub
6266 which we won't have later. In order to not impose this complication
6267 on the rest of the code, we read them here and copy them to the
6276 if (stub_comp_unit_die
!= NULL
)
6278 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6280 if (!per_cu
->is_debug_types
)
6281 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6282 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6283 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6284 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6285 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6287 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6289 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6290 We need the value before we can process DW_AT_ranges values from the
6292 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6294 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6295 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6296 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6297 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6299 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6301 else if (stub_comp_dir
!= NULL
)
6303 /* Reconstruct the comp_dir attribute to simplify the code below. */
6304 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6305 comp_dir
->name
= DW_AT_comp_dir
;
6306 comp_dir
->form
= DW_FORM_string
;
6307 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6310 /* Set up for reading the DWO CU/TU. */
6311 cu
->dwo_unit
= dwo_unit
;
6312 dwarf2_section_info
*section
= dwo_unit
->section
;
6313 section
->read (objfile
);
6314 abfd
= section
->get_bfd_owner ();
6315 begin_info_ptr
= info_ptr
= (section
->buffer
6316 + to_underlying (dwo_unit
->sect_off
));
6317 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6319 if (per_cu
->is_debug_types
)
6321 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6323 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6324 section
, dwo_abbrev_section
,
6325 info_ptr
, rcuh_kind::TYPE
);
6326 /* This is not an assert because it can be caused by bad debug info. */
6327 if (sig_type
->signature
!= cu
->header
.signature
)
6329 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6330 " TU at offset %s [in module %s]"),
6331 hex_string (sig_type
->signature
),
6332 hex_string (cu
->header
.signature
),
6333 sect_offset_str (dwo_unit
->sect_off
),
6334 bfd_get_filename (abfd
));
6336 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6337 /* For DWOs coming from DWP files, we don't know the CU length
6338 nor the type's offset in the TU until now. */
6339 dwo_unit
->length
= cu
->header
.get_length ();
6340 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6342 /* Establish the type offset that can be used to lookup the type.
6343 For DWO files, we don't know it until now. */
6344 sig_type
->type_offset_in_section
6345 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6349 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6350 section
, dwo_abbrev_section
,
6351 info_ptr
, rcuh_kind::COMPILE
);
6352 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6353 /* For DWOs coming from DWP files, we don't know the CU length
6355 dwo_unit
->length
= cu
->header
.get_length ();
6358 dwo_abbrev_section
->read (objfile
);
6359 *result_dwo_abbrev_table
6360 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6361 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6362 result_dwo_abbrev_table
->get ());
6364 /* Read in the die, but leave space to copy over the attributes
6365 from the stub. This has the benefit of simplifying the rest of
6366 the code - all the work to maintain the illusion of a single
6367 DW_TAG_{compile,type}_unit DIE is done here. */
6368 num_extra_attrs
= ((stmt_list
!= NULL
)
6372 + (comp_dir
!= NULL
));
6373 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6376 /* Copy over the attributes from the stub to the DIE we just read in. */
6377 comp_unit_die
= *result_comp_unit_die
;
6378 i
= comp_unit_die
->num_attrs
;
6379 if (stmt_list
!= NULL
)
6380 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6382 comp_unit_die
->attrs
[i
++] = *low_pc
;
6383 if (high_pc
!= NULL
)
6384 comp_unit_die
->attrs
[i
++] = *high_pc
;
6386 comp_unit_die
->attrs
[i
++] = *ranges
;
6387 if (comp_dir
!= NULL
)
6388 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6389 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6391 if (dwarf_die_debug
)
6393 fprintf_unfiltered (gdb_stdlog
,
6394 "Read die from %s@0x%x of %s:\n",
6395 section
->get_name (),
6396 (unsigned) (begin_info_ptr
- section
->buffer
),
6397 bfd_get_filename (abfd
));
6398 dump_die (comp_unit_die
, dwarf_die_debug
);
6401 /* Skip dummy compilation units. */
6402 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6403 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6406 *result_info_ptr
= info_ptr
;
6410 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6411 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6412 signature is part of the header. */
6413 static gdb::optional
<ULONGEST
>
6414 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6416 if (cu
->header
.version
>= 5)
6417 return cu
->header
.signature
;
6418 struct attribute
*attr
;
6419 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6420 if (attr
== nullptr || !attr
->form_is_unsigned ())
6421 return gdb::optional
<ULONGEST
> ();
6422 return attr
->as_unsigned ();
6425 /* Subroutine of cutu_reader to simplify it.
6426 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6427 Returns NULL if the specified DWO unit cannot be found. */
6429 static struct dwo_unit
*
6430 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6432 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6433 struct dwo_unit
*dwo_unit
;
6434 const char *comp_dir
;
6436 gdb_assert (cu
!= NULL
);
6438 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6439 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6440 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6442 if (per_cu
->is_debug_types
)
6443 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6446 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6448 if (!signature
.has_value ())
6449 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6451 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6453 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6459 /* Subroutine of cutu_reader to simplify it.
6460 See it for a description of the parameters.
6461 Read a TU directly from a DWO file, bypassing the stub. */
6464 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6465 dwarf2_per_objfile
*per_objfile
,
6466 dwarf2_cu
*existing_cu
)
6468 struct signatured_type
*sig_type
;
6470 /* Verify we can do the following downcast, and that we have the
6472 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6473 sig_type
= (struct signatured_type
*) this_cu
;
6474 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6478 if (existing_cu
!= nullptr)
6481 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6482 /* There's no need to do the rereading_dwo_cu handling that
6483 cutu_reader does since we don't read the stub. */
6487 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6488 in per_objfile yet. */
6489 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6490 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6491 cu
= m_new_cu
.get ();
6494 /* A future optimization, if needed, would be to use an existing
6495 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6496 could share abbrev tables. */
6498 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6499 NULL
/* stub_comp_unit_die */,
6500 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6503 &m_dwo_abbrev_table
) == 0)
6510 /* Initialize a CU (or TU) and read its DIEs.
6511 If the CU defers to a DWO file, read the DWO file as well.
6513 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6514 Otherwise the table specified in the comp unit header is read in and used.
6515 This is an optimization for when we already have the abbrev table.
6517 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6520 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6521 dwarf2_per_objfile
*per_objfile
,
6522 struct abbrev_table
*abbrev_table
,
6523 dwarf2_cu
*existing_cu
,
6525 : die_reader_specs
{},
6528 struct objfile
*objfile
= per_objfile
->objfile
;
6529 struct dwarf2_section_info
*section
= this_cu
->section
;
6530 bfd
*abfd
= section
->get_bfd_owner ();
6531 const gdb_byte
*begin_info_ptr
;
6532 struct signatured_type
*sig_type
= NULL
;
6533 struct dwarf2_section_info
*abbrev_section
;
6534 /* Non-zero if CU currently points to a DWO file and we need to
6535 reread it. When this happens we need to reread the skeleton die
6536 before we can reread the DWO file (this only applies to CUs, not TUs). */
6537 int rereading_dwo_cu
= 0;
6539 if (dwarf_die_debug
)
6540 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6541 this_cu
->is_debug_types
? "type" : "comp",
6542 sect_offset_str (this_cu
->sect_off
));
6544 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6545 file (instead of going through the stub), short-circuit all of this. */
6546 if (this_cu
->reading_dwo_directly
)
6548 /* Narrow down the scope of possibilities to have to understand. */
6549 gdb_assert (this_cu
->is_debug_types
);
6550 gdb_assert (abbrev_table
== NULL
);
6551 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6555 /* This is cheap if the section is already read in. */
6556 section
->read (objfile
);
6558 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6560 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6564 if (existing_cu
!= nullptr)
6567 /* If this CU is from a DWO file we need to start over, we need to
6568 refetch the attributes from the skeleton CU.
6569 This could be optimized by retrieving those attributes from when we
6570 were here the first time: the previous comp_unit_die was stored in
6571 comp_unit_obstack. But there's no data yet that we need this
6573 if (cu
->dwo_unit
!= NULL
)
6574 rereading_dwo_cu
= 1;
6578 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6579 in per_objfile yet. */
6580 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6581 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6582 cu
= m_new_cu
.get ();
6585 /* Get the header. */
6586 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6588 /* We already have the header, there's no need to read it in again. */
6589 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6593 if (this_cu
->is_debug_types
)
6595 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6596 section
, abbrev_section
,
6597 info_ptr
, rcuh_kind::TYPE
);
6599 /* Since per_cu is the first member of struct signatured_type,
6600 we can go from a pointer to one to a pointer to the other. */
6601 sig_type
= (struct signatured_type
*) this_cu
;
6602 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6603 gdb_assert (sig_type
->type_offset_in_tu
6604 == cu
->header
.type_cu_offset_in_tu
);
6605 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6607 /* LENGTH has not been set yet for type units if we're
6608 using .gdb_index. */
6609 this_cu
->length
= cu
->header
.get_length ();
6611 /* Establish the type offset that can be used to lookup the type. */
6612 sig_type
->type_offset_in_section
=
6613 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6615 this_cu
->dwarf_version
= cu
->header
.version
;
6619 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6620 section
, abbrev_section
,
6622 rcuh_kind::COMPILE
);
6624 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6625 if (this_cu
->length
== 0)
6626 this_cu
->length
= cu
->header
.get_length ();
6628 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6629 this_cu
->dwarf_version
= cu
->header
.version
;
6633 /* Skip dummy compilation units. */
6634 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6635 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6641 /* If we don't have them yet, read the abbrevs for this compilation unit.
6642 And if we need to read them now, make sure they're freed when we're
6644 if (abbrev_table
!= NULL
)
6645 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6648 abbrev_section
->read (objfile
);
6649 m_abbrev_table_holder
6650 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6651 abbrev_table
= m_abbrev_table_holder
.get ();
6654 /* Read the top level CU/TU die. */
6655 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6656 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6658 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6664 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6665 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6666 table from the DWO file and pass the ownership over to us. It will be
6667 referenced from READER, so we must make sure to free it after we're done
6670 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6671 DWO CU, that this test will fail (the attribute will not be present). */
6672 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6673 if (dwo_name
!= nullptr)
6675 struct dwo_unit
*dwo_unit
;
6676 struct die_info
*dwo_comp_unit_die
;
6678 if (comp_unit_die
->has_children
)
6680 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6681 " has children (offset %s) [in module %s]"),
6682 sect_offset_str (this_cu
->sect_off
),
6683 bfd_get_filename (abfd
));
6685 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6686 if (dwo_unit
!= NULL
)
6688 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6689 comp_unit_die
, NULL
,
6692 &m_dwo_abbrev_table
) == 0)
6698 comp_unit_die
= dwo_comp_unit_die
;
6702 /* Yikes, we couldn't find the rest of the DIE, we only have
6703 the stub. A complaint has already been logged. There's
6704 not much more we can do except pass on the stub DIE to
6705 die_reader_func. We don't want to throw an error on bad
6712 cutu_reader::keep ()
6714 /* Done, clean up. */
6715 gdb_assert (!dummy_p
);
6716 if (m_new_cu
!= NULL
)
6718 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6720 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6721 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6725 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6726 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6727 assumed to have already done the lookup to find the DWO file).
6729 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6730 THIS_CU->is_debug_types, but nothing else.
6732 We fill in THIS_CU->length.
6734 THIS_CU->cu is always freed when done.
6735 This is done in order to not leave THIS_CU->cu in a state where we have
6736 to care whether it refers to the "main" CU or the DWO CU.
6738 When parent_cu is passed, it is used to provide a default value for
6739 str_offsets_base and addr_base from the parent. */
6741 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6742 dwarf2_per_objfile
*per_objfile
,
6743 struct dwarf2_cu
*parent_cu
,
6744 struct dwo_file
*dwo_file
)
6745 : die_reader_specs
{},
6748 struct objfile
*objfile
= per_objfile
->objfile
;
6749 struct dwarf2_section_info
*section
= this_cu
->section
;
6750 bfd
*abfd
= section
->get_bfd_owner ();
6751 struct dwarf2_section_info
*abbrev_section
;
6752 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6754 if (dwarf_die_debug
)
6755 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6756 this_cu
->is_debug_types
? "type" : "comp",
6757 sect_offset_str (this_cu
->sect_off
));
6759 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6761 abbrev_section
= (dwo_file
!= NULL
6762 ? &dwo_file
->sections
.abbrev
6763 : get_abbrev_section_for_cu (this_cu
));
6765 /* This is cheap if the section is already read in. */
6766 section
->read (objfile
);
6768 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6770 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6771 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6772 section
, abbrev_section
, info_ptr
,
6773 (this_cu
->is_debug_types
6775 : rcuh_kind::COMPILE
));
6777 if (parent_cu
!= nullptr)
6779 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6780 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6782 this_cu
->length
= m_new_cu
->header
.get_length ();
6784 /* Skip dummy compilation units. */
6785 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6786 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6792 abbrev_section
->read (objfile
);
6793 m_abbrev_table_holder
6794 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6796 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6797 m_abbrev_table_holder
.get ());
6798 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6802 /* Type Unit Groups.
6804 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6805 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6806 so that all types coming from the same compilation (.o file) are grouped
6807 together. A future step could be to put the types in the same symtab as
6808 the CU the types ultimately came from. */
6811 hash_type_unit_group (const void *item
)
6813 const struct type_unit_group
*tu_group
6814 = (const struct type_unit_group
*) item
;
6816 return hash_stmt_list_entry (&tu_group
->hash
);
6820 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6822 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6823 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6825 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6828 /* Allocate a hash table for type unit groups. */
6831 allocate_type_unit_groups_table ()
6833 return htab_up (htab_create_alloc (3,
6834 hash_type_unit_group
,
6836 htab_delete_entry
<type_unit_group
>,
6840 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6841 partial symtabs. We combine several TUs per psymtab to not let the size
6842 of any one psymtab grow too big. */
6843 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6844 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6846 /* Helper routine for get_type_unit_group.
6847 Create the type_unit_group object used to hold one or more TUs. */
6849 static std::unique_ptr
<type_unit_group
>
6850 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6852 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6853 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6855 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6856 tu_group
->per_bfd
= per_bfd
;
6858 if (per_bfd
->using_index
)
6860 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6861 struct dwarf2_per_cu_quick_data
);
6865 unsigned int line_offset
= to_underlying (line_offset_struct
);
6866 dwarf2_psymtab
*pst
;
6869 /* Give the symtab a useful name for debug purposes. */
6870 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6871 name
= string_printf ("<type_units_%d>",
6872 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6874 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6876 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6878 pst
->anonymous
= true;
6881 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6882 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6887 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6888 STMT_LIST is a DW_AT_stmt_list attribute. */
6890 static struct type_unit_group
*
6891 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6893 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6894 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6895 struct type_unit_group
*tu_group
;
6897 unsigned int line_offset
;
6898 struct type_unit_group type_unit_group_for_lookup
;
6900 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6901 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6903 /* Do we need to create a new group, or can we use an existing one? */
6905 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6907 line_offset
= stmt_list
->as_unsigned ();
6908 ++tu_stats
->nr_symtab_sharers
;
6912 /* Ugh, no stmt_list. Rare, but we have to handle it.
6913 We can do various things here like create one group per TU or
6914 spread them over multiple groups to split up the expansion work.
6915 To avoid worst case scenarios (too many groups or too large groups)
6916 we, umm, group them in bunches. */
6917 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6918 | (tu_stats
->nr_stmt_less_type_units
6919 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6920 ++tu_stats
->nr_stmt_less_type_units
;
6923 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6924 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6925 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6926 &type_unit_group_for_lookup
, INSERT
);
6927 if (*slot
== nullptr)
6929 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6930 std::unique_ptr
<type_unit_group
> grp
6931 = create_type_unit_group (cu
, line_offset_struct
);
6932 *slot
= grp
.release ();
6933 ++tu_stats
->nr_symtabs
;
6936 tu_group
= (struct type_unit_group
*) *slot
;
6937 gdb_assert (tu_group
!= nullptr);
6941 /* Partial symbol tables. */
6943 /* Create a psymtab named NAME and assign it to PER_CU.
6945 The caller must fill in the following details:
6946 dirname, textlow, texthigh. */
6948 static dwarf2_psymtab
*
6949 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6950 dwarf2_per_objfile
*per_objfile
,
6954 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6955 per_objfile
->objfile
->per_bfd
, per_cu
);
6957 pst
->psymtabs_addrmap_supported
= true;
6959 /* This is the glue that links PST into GDB's symbol API. */
6960 per_cu
->v
.psymtab
= pst
;
6965 /* DIE reader function for process_psymtab_comp_unit. */
6968 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6969 const gdb_byte
*info_ptr
,
6970 struct die_info
*comp_unit_die
,
6971 enum language pretend_language
)
6973 struct dwarf2_cu
*cu
= reader
->cu
;
6974 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6975 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6976 struct objfile
*objfile
= per_objfile
->objfile
;
6977 struct gdbarch
*gdbarch
= objfile
->arch ();
6978 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6980 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6981 dwarf2_psymtab
*pst
;
6982 enum pc_bounds_kind cu_bounds_kind
;
6984 gdb_assert (! per_cu
->is_debug_types
);
6986 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6988 /* Allocate a new partial symbol table structure. */
6989 static const char artificial
[] = "<artificial>";
6990 file_and_directory
&fnd
= find_file_and_directory (comp_unit_die
, cu
);
6991 if (strcmp (fnd
.get_name (), artificial
) == 0)
6993 gdb::unique_xmalloc_ptr
<char> debug_filename
6994 (concat (artificial
, "@",
6995 sect_offset_str (per_cu
->sect_off
),
6997 fnd
.set_name (std::move (debug_filename
));
7000 pst
= create_partial_symtab (per_cu
, per_objfile
, fnd
.get_name ());
7002 /* This must be done before calling dwarf2_build_include_psymtabs. */
7003 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7005 baseaddr
= objfile
->text_section_offset ();
7007 dwarf2_find_base_address (comp_unit_die
, cu
);
7009 /* Possibly set the default values of LOWPC and HIGHPC from
7011 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7012 &best_highpc
, cu
, pst
);
7013 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7016 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7019 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7021 /* Store the contiguous range if it is not empty; it can be
7022 empty for CUs with no code. */
7023 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7027 /* Check if comp unit has_children.
7028 If so, read the rest of the partial symbols from this comp unit.
7029 If not, there's no more debug_info for this comp unit. */
7030 if (comp_unit_die
->has_children
)
7032 struct partial_die_info
*first_die
;
7033 CORE_ADDR lowpc
, highpc
;
7035 lowpc
= ((CORE_ADDR
) -1);
7036 highpc
= ((CORE_ADDR
) 0);
7038 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7040 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7041 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7043 /* If we didn't find a lowpc, set it to highpc to avoid
7044 complaints from `maint check'. */
7045 if (lowpc
== ((CORE_ADDR
) -1))
7048 /* If the compilation unit didn't have an explicit address range,
7049 then use the information extracted from its child dies. */
7050 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7053 best_highpc
= highpc
;
7056 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7057 best_lowpc
+ baseaddr
)
7059 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7060 best_highpc
+ baseaddr
)
7065 if (!cu
->per_cu
->imported_symtabs_empty ())
7068 int len
= cu
->per_cu
->imported_symtabs_size ();
7070 /* Fill in 'dependencies' here; we fill in 'users' in a
7072 pst
->number_of_dependencies
= len
;
7074 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7075 for (i
= 0; i
< len
; ++i
)
7077 pst
->dependencies
[i
]
7078 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7081 cu
->per_cu
->imported_symtabs_free ();
7084 /* Get the list of files included in the current compilation unit,
7085 and build a psymtab for each of them. */
7086 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, fnd
, pst
);
7088 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7089 ", %d global, %d static syms",
7090 per_cu
->is_debug_types
? "type" : "comp",
7091 sect_offset_str (per_cu
->sect_off
),
7092 paddress (gdbarch
, pst
->text_low (objfile
)),
7093 paddress (gdbarch
, pst
->text_high (objfile
)),
7094 (int) pst
->global_psymbols
.size (),
7095 (int) pst
->static_psymbols
.size ());
7098 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7099 Process compilation unit THIS_CU for a psymtab. */
7102 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7103 dwarf2_per_objfile
*per_objfile
,
7104 bool want_partial_unit
,
7105 enum language pretend_language
)
7107 /* If this compilation unit was already read in, free the
7108 cached copy in order to read it in again. This is
7109 necessary because we skipped some symbols when we first
7110 read in the compilation unit (see load_partial_dies).
7111 This problem could be avoided, but the benefit is unclear. */
7112 per_objfile
->remove_cu (this_cu
);
7114 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7116 if (reader
.comp_unit_die
== nullptr)
7119 switch (reader
.comp_unit_die
->tag
)
7121 case DW_TAG_compile_unit
:
7122 this_cu
->unit_type
= DW_UT_compile
;
7124 case DW_TAG_partial_unit
:
7125 this_cu
->unit_type
= DW_UT_partial
;
7127 case DW_TAG_type_unit
:
7128 this_cu
->unit_type
= DW_UT_type
;
7131 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7132 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7133 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7134 objfile_name (per_objfile
->objfile
));
7141 else if (this_cu
->is_debug_types
)
7142 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7143 reader
.comp_unit_die
);
7144 else if (want_partial_unit
7145 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7146 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7147 reader
.comp_unit_die
,
7150 /* Age out any secondary CUs. */
7151 per_objfile
->age_comp_units ();
7154 /* Reader function for build_type_psymtabs. */
7157 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7158 const gdb_byte
*info_ptr
,
7159 struct die_info
*type_unit_die
)
7161 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7162 struct dwarf2_cu
*cu
= reader
->cu
;
7163 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7164 struct signatured_type
*sig_type
;
7165 struct type_unit_group
*tu_group
;
7166 struct attribute
*attr
;
7167 struct partial_die_info
*first_die
;
7168 CORE_ADDR lowpc
, highpc
;
7169 dwarf2_psymtab
*pst
;
7171 gdb_assert (per_cu
->is_debug_types
);
7172 sig_type
= (struct signatured_type
*) per_cu
;
7174 if (! type_unit_die
->has_children
)
7177 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7178 tu_group
= get_type_unit_group (cu
, attr
);
7180 if (tu_group
->tus
== nullptr)
7181 tu_group
->tus
= new std::vector
<signatured_type
*>;
7182 tu_group
->tus
->push_back (sig_type
);
7184 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7185 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7186 pst
->anonymous
= true;
7188 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7190 lowpc
= (CORE_ADDR
) -1;
7191 highpc
= (CORE_ADDR
) 0;
7192 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7197 /* Struct used to sort TUs by their abbreviation table offset. */
7199 struct tu_abbrev_offset
7201 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7202 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7205 /* This is used when sorting. */
7206 bool operator< (const tu_abbrev_offset
&other
) const
7208 return abbrev_offset
< other
.abbrev_offset
;
7211 signatured_type
*sig_type
;
7212 sect_offset abbrev_offset
;
7215 /* Efficiently read all the type units.
7217 The efficiency is because we sort TUs by the abbrev table they use and
7218 only read each abbrev table once. In one program there are 200K TUs
7219 sharing 8K abbrev tables.
7221 The main purpose of this function is to support building the
7222 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7223 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7224 can collapse the search space by grouping them by stmt_list.
7225 The savings can be significant, in the same program from above the 200K TUs
7226 share 8K stmt_list tables.
7228 FUNC is expected to call get_type_unit_group, which will create the
7229 struct type_unit_group if necessary and add it to
7230 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7233 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7235 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7236 abbrev_table_up abbrev_table
;
7237 sect_offset abbrev_offset
;
7239 /* It's up to the caller to not call us multiple times. */
7240 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7242 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7245 /* TUs typically share abbrev tables, and there can be way more TUs than
7246 abbrev tables. Sort by abbrev table to reduce the number of times we
7247 read each abbrev table in.
7248 Alternatives are to punt or to maintain a cache of abbrev tables.
7249 This is simpler and efficient enough for now.
7251 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7252 symtab to use). Typically TUs with the same abbrev offset have the same
7253 stmt_list value too so in practice this should work well.
7255 The basic algorithm here is:
7257 sort TUs by abbrev table
7258 for each TU with same abbrev table:
7259 read abbrev table if first user
7260 read TU top level DIE
7261 [IWBN if DWO skeletons had DW_AT_stmt_list]
7264 dwarf_read_debug_printf ("Building type unit groups ...");
7266 /* Sort in a separate table to maintain the order of all_comp_units
7267 for .gdb_index: TU indices directly index all_type_units. */
7268 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7269 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7271 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7273 if (cu
->is_debug_types
)
7275 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7276 sorted_by_abbrev
.emplace_back
7277 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7278 sig_type
->sect_off
));
7282 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7284 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7286 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7288 /* Switch to the next abbrev table if necessary. */
7289 if (abbrev_table
== NULL
7290 || tu
.abbrev_offset
!= abbrev_offset
)
7292 abbrev_offset
= tu
.abbrev_offset
;
7293 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7295 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7296 ++tu_stats
->nr_uniq_abbrev_tables
;
7299 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7300 abbrev_table
.get (), nullptr, false);
7301 if (!reader
.dummy_p
)
7302 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7303 reader
.comp_unit_die
);
7307 /* Print collected type unit statistics. */
7310 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7312 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7314 dwarf_read_debug_printf ("Type unit statistics:");
7315 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7316 dwarf_read_debug_printf (" %d uniq abbrev tables",
7317 tu_stats
->nr_uniq_abbrev_tables
);
7318 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7319 tu_stats
->nr_symtabs
);
7320 dwarf_read_debug_printf (" %d symtab sharers",
7321 tu_stats
->nr_symtab_sharers
);
7322 dwarf_read_debug_printf (" %d type units without a stmt_list",
7323 tu_stats
->nr_stmt_less_type_units
);
7324 dwarf_read_debug_printf (" %d all_type_units reallocs",
7325 tu_stats
->nr_all_type_units_reallocs
);
7328 /* Traversal function for build_type_psymtabs. */
7331 build_type_psymtab_dependencies (void **slot
, void *info
)
7333 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7334 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7335 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7336 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7337 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7340 gdb_assert (len
> 0);
7341 gdb_assert (tu_group
->type_unit_group_p ());
7343 pst
->number_of_dependencies
= len
;
7344 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7345 for (i
= 0; i
< len
; ++i
)
7347 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7348 gdb_assert (iter
->is_debug_types
);
7349 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7350 iter
->type_unit_group
= tu_group
;
7353 delete tu_group
->tus
;
7354 tu_group
->tus
= nullptr;
7359 /* Traversal function for process_skeletonless_type_unit.
7360 Read a TU in a DWO file and build partial symbols for it. */
7363 process_skeletonless_type_unit (void **slot
, void *info
)
7365 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7366 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7368 /* If this TU doesn't exist in the global table, add it and read it in. */
7370 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7371 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7373 signatured_type
find_entry (dwo_unit
->signature
);
7374 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7375 &find_entry
, INSERT
);
7376 /* If we've already seen this type there's nothing to do. What's happening
7377 is we're doing our own version of comdat-folding here. */
7381 /* This does the job that create_all_comp_units would have done for
7383 signatured_type
*entry
7384 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7385 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7388 /* This does the job that build_type_psymtabs would have done. */
7389 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7390 if (!reader
.dummy_p
)
7391 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7392 reader
.comp_unit_die
);
7397 /* Traversal function for process_skeletonless_type_units. */
7400 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7402 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7404 if (dwo_file
->tus
!= NULL
)
7405 htab_traverse_noresize (dwo_file
->tus
.get (),
7406 process_skeletonless_type_unit
, info
);
7411 /* Scan all TUs of DWO files, verifying we've processed them.
7412 This is needed in case a TU was emitted without its skeleton.
7413 Note: This can't be done until we know what all the DWO files are. */
7416 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7418 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7419 if (get_dwp_file (per_objfile
) == NULL
7420 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7422 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7423 process_dwo_file_for_skeletonless_type_units
,
7428 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7431 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7433 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7435 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7440 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7442 /* Set the 'user' field only if it is not already set. */
7443 if (pst
->dependencies
[j
]->user
== NULL
)
7444 pst
->dependencies
[j
]->user
= pst
;
7449 /* Build the partial symbol table by doing a quick pass through the
7450 .debug_info and .debug_abbrev sections. */
7453 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7455 struct objfile
*objfile
= per_objfile
->objfile
;
7456 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7458 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7459 objfile_name (objfile
));
7461 scoped_restore restore_reading_psyms
7462 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7464 per_bfd
->info
.read (objfile
);
7466 /* Any cached compilation units will be linked by the per-objfile
7467 read_in_chain. Make sure to free them when we're done. */
7468 free_cached_comp_units
freer (per_objfile
);
7470 create_all_comp_units (per_objfile
);
7471 build_type_psymtabs (per_objfile
);
7473 /* Create a temporary address map on a temporary obstack. We later
7474 copy this to the final obstack. */
7475 auto_obstack temp_obstack
;
7477 scoped_restore save_psymtabs_addrmap
7478 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7479 addrmap_create_mutable (&temp_obstack
));
7481 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7483 if (per_cu
->v
.psymtab
!= NULL
)
7484 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7486 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7490 /* This has to wait until we read the CUs, we need the list of DWOs. */
7491 process_skeletonless_type_units (per_objfile
);
7493 /* Now that all TUs have been processed we can fill in the dependencies. */
7494 if (per_bfd
->type_unit_groups
!= NULL
)
7496 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7497 build_type_psymtab_dependencies
, per_objfile
);
7500 if (dwarf_read_debug
> 0)
7501 print_tu_stats (per_objfile
);
7503 set_partial_user (per_objfile
);
7505 per_bfd
->partial_symtabs
->psymtabs_addrmap
7506 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7507 per_bfd
->partial_symtabs
->obstack ());
7508 /* At this point we want to keep the address map. */
7509 save_psymtabs_addrmap
.release ();
7511 dwarf_read_debug_printf ("Done building psymtabs of %s",
7512 objfile_name (objfile
));
7515 /* Load the partial DIEs for a secondary CU into memory.
7516 This is also used when rereading a primary CU with load_all_dies. */
7519 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7520 dwarf2_per_objfile
*per_objfile
,
7521 dwarf2_cu
*existing_cu
)
7523 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7525 if (!reader
.dummy_p
)
7527 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7530 /* Check if comp unit has_children.
7531 If so, read the rest of the partial symbols from this comp unit.
7532 If not, there's no more debug_info for this comp unit. */
7533 if (reader
.comp_unit_die
->has_children
)
7534 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7541 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7542 struct dwarf2_section_info
*section
,
7543 struct dwarf2_section_info
*abbrev_section
,
7544 unsigned int is_dwz
,
7545 htab_up
&types_htab
,
7546 rcuh_kind section_kind
)
7548 const gdb_byte
*info_ptr
;
7549 struct objfile
*objfile
= per_objfile
->objfile
;
7551 dwarf_read_debug_printf ("Reading %s for %s",
7552 section
->get_name (),
7553 section
->get_file_name ());
7555 section
->read (objfile
);
7557 info_ptr
= section
->buffer
;
7559 while (info_ptr
< section
->buffer
+ section
->size
)
7561 dwarf2_per_cu_data_up this_cu
;
7563 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7565 comp_unit_head cu_header
;
7566 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7567 abbrev_section
, info_ptr
,
7570 /* Save the compilation unit for later lookup. */
7571 if (cu_header
.unit_type
!= DW_UT_type
)
7572 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7575 if (types_htab
== nullptr)
7576 types_htab
= allocate_signatured_type_table ();
7578 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7579 (cu_header
.signature
);
7580 signatured_type
*sig_ptr
= sig_type
.get ();
7581 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7582 this_cu
.reset (sig_type
.release ());
7584 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7585 gdb_assert (slot
!= nullptr);
7586 if (*slot
!= nullptr)
7587 complaint (_("debug type entry at offset %s is duplicate to"
7588 " the entry at offset %s, signature %s"),
7589 sect_offset_str (sect_off
),
7590 sect_offset_str (sig_ptr
->sect_off
),
7591 hex_string (sig_ptr
->signature
));
7594 this_cu
->sect_off
= sect_off
;
7595 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7596 this_cu
->is_dwz
= is_dwz
;
7597 this_cu
->section
= section
;
7599 info_ptr
= info_ptr
+ this_cu
->length
;
7600 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7604 /* Create a list of all compilation units in OBJFILE.
7605 This is only done for -readnow and building partial symtabs. */
7608 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7612 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7613 &per_objfile
->per_bfd
->abbrev
, 0,
7614 types_htab
, rcuh_kind::COMPILE
);
7615 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7616 read_comp_units_from_section (per_objfile
, §ion
,
7617 &per_objfile
->per_bfd
->abbrev
, 0,
7618 types_htab
, rcuh_kind::TYPE
);
7620 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7622 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7623 types_htab
, rcuh_kind::COMPILE
);
7625 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7628 /* Process all loaded DIEs for compilation unit CU, starting at
7629 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7630 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7631 DW_AT_ranges). See the comments of add_partial_subprogram on how
7632 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7635 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7636 CORE_ADDR
*highpc
, int set_addrmap
,
7637 struct dwarf2_cu
*cu
)
7639 struct partial_die_info
*pdi
;
7641 /* Now, march along the PDI's, descending into ones which have
7642 interesting children but skipping the children of the other ones,
7643 until we reach the end of the compilation unit. */
7651 /* Anonymous namespaces or modules have no name but have interesting
7652 children, so we need to look at them. Ditto for anonymous
7655 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7656 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7657 || pdi
->tag
== DW_TAG_imported_unit
7658 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7662 case DW_TAG_subprogram
:
7663 case DW_TAG_inlined_subroutine
:
7664 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7665 if (cu
->per_cu
->lang
== language_cplus
)
7666 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7669 case DW_TAG_constant
:
7670 case DW_TAG_variable
:
7671 case DW_TAG_typedef
:
7672 case DW_TAG_union_type
:
7673 if (!pdi
->is_declaration
7674 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7676 add_partial_symbol (pdi
, cu
);
7679 case DW_TAG_class_type
:
7680 case DW_TAG_interface_type
:
7681 case DW_TAG_structure_type
:
7682 if (!pdi
->is_declaration
)
7684 add_partial_symbol (pdi
, cu
);
7686 if ((cu
->per_cu
->lang
== language_rust
7687 || cu
->per_cu
->lang
== language_cplus
)
7688 && pdi
->has_children
)
7689 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7692 case DW_TAG_enumeration_type
:
7693 if (!pdi
->is_declaration
)
7694 add_partial_enumeration (pdi
, cu
);
7696 case DW_TAG_base_type
:
7697 case DW_TAG_subrange_type
:
7698 /* File scope base type definitions are added to the partial
7700 add_partial_symbol (pdi
, cu
);
7702 case DW_TAG_namespace
:
7703 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7706 if (!pdi
->is_declaration
)
7707 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7709 case DW_TAG_imported_unit
:
7711 struct dwarf2_per_cu_data
*per_cu
;
7713 /* For now we don't handle imported units in type units. */
7714 if (cu
->per_cu
->is_debug_types
)
7716 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7717 " supported in type units [in module %s]"),
7718 objfile_name (cu
->per_objfile
->objfile
));
7721 per_cu
= dwarf2_find_containing_comp_unit
7722 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7723 cu
->per_objfile
->per_bfd
);
7725 /* Go read the partial unit, if needed. */
7726 if (per_cu
->v
.psymtab
== NULL
)
7727 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7730 if (pdi
->die_parent
== nullptr
7731 && per_cu
->unit_type
== DW_UT_compile
7732 && per_cu
->lang
== language_cplus
)
7733 /* Regard import as hint. See corresponding code in
7734 process_imported_unit_die. */
7737 cu
->per_cu
->imported_symtabs_push (per_cu
);
7740 case DW_TAG_imported_declaration
:
7741 add_partial_symbol (pdi
, cu
);
7748 /* If the die has a sibling, skip to the sibling. */
7750 pdi
= pdi
->die_sibling
;
7754 /* Functions used to compute the fully scoped name of a partial DIE.
7756 Normally, this is simple. For C++, the parent DIE's fully scoped
7757 name is concatenated with "::" and the partial DIE's name.
7758 Enumerators are an exception; they use the scope of their parent
7759 enumeration type, i.e. the name of the enumeration type is not
7760 prepended to the enumerator.
7762 There are two complexities. One is DW_AT_specification; in this
7763 case "parent" means the parent of the target of the specification,
7764 instead of the direct parent of the DIE. The other is compilers
7765 which do not emit DW_TAG_namespace; in this case we try to guess
7766 the fully qualified name of structure types from their members'
7767 linkage names. This must be done using the DIE's children rather
7768 than the children of any DW_AT_specification target. We only need
7769 to do this for structures at the top level, i.e. if the target of
7770 any DW_AT_specification (if any; otherwise the DIE itself) does not
7773 /* Compute the scope prefix associated with PDI's parent, in
7774 compilation unit CU. The result will be allocated on CU's
7775 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7776 field. NULL is returned if no prefix is necessary. */
7778 partial_die_parent_scope (struct partial_die_info
*pdi
,
7779 struct dwarf2_cu
*cu
)
7781 const char *grandparent_scope
;
7782 struct partial_die_info
*parent
, *real_pdi
;
7784 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7785 then this means the parent of the specification DIE. */
7788 while (real_pdi
->has_specification
)
7790 auto res
= find_partial_die (real_pdi
->spec_offset
,
7791 real_pdi
->spec_is_dwz
, cu
);
7796 parent
= real_pdi
->die_parent
;
7800 if (parent
->scope_set
)
7801 return parent
->scope
;
7805 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7807 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7808 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7809 Work around this problem here. */
7810 if (cu
->per_cu
->lang
== language_cplus
7811 && parent
->tag
== DW_TAG_namespace
7812 && strcmp (parent
->name (cu
), "::") == 0
7813 && grandparent_scope
== NULL
)
7815 parent
->scope
= NULL
;
7816 parent
->scope_set
= 1;
7820 /* Nested subroutines in Fortran get a prefix. */
7821 if (pdi
->tag
== DW_TAG_enumerator
)
7822 /* Enumerators should not get the name of the enumeration as a prefix. */
7823 parent
->scope
= grandparent_scope
;
7824 else if (parent
->tag
== DW_TAG_namespace
7825 || parent
->tag
== DW_TAG_module
7826 || parent
->tag
== DW_TAG_structure_type
7827 || parent
->tag
== DW_TAG_class_type
7828 || parent
->tag
== DW_TAG_interface_type
7829 || parent
->tag
== DW_TAG_union_type
7830 || parent
->tag
== DW_TAG_enumeration_type
7831 || (cu
->per_cu
->lang
== language_fortran
7832 && parent
->tag
== DW_TAG_subprogram
7833 && pdi
->tag
== DW_TAG_subprogram
))
7835 if (grandparent_scope
== NULL
)
7836 parent
->scope
= parent
->name (cu
);
7838 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7840 parent
->name (cu
), 0, cu
);
7844 /* FIXME drow/2004-04-01: What should we be doing with
7845 function-local names? For partial symbols, we should probably be
7847 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7848 dwarf_tag_name (parent
->tag
),
7849 sect_offset_str (pdi
->sect_off
));
7850 parent
->scope
= grandparent_scope
;
7853 parent
->scope_set
= 1;
7854 return parent
->scope
;
7857 /* Return the fully scoped name associated with PDI, from compilation unit
7858 CU. The result will be allocated with malloc. */
7860 static gdb::unique_xmalloc_ptr
<char>
7861 partial_die_full_name (struct partial_die_info
*pdi
,
7862 struct dwarf2_cu
*cu
)
7864 const char *parent_scope
;
7866 /* If this is a template instantiation, we can not work out the
7867 template arguments from partial DIEs. So, unfortunately, we have
7868 to go through the full DIEs. At least any work we do building
7869 types here will be reused if full symbols are loaded later. */
7870 if (pdi
->has_template_arguments
)
7874 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7876 struct die_info
*die
;
7877 struct attribute attr
;
7878 struct dwarf2_cu
*ref_cu
= cu
;
7880 /* DW_FORM_ref_addr is using section offset. */
7881 attr
.name
= (enum dwarf_attribute
) 0;
7882 attr
.form
= DW_FORM_ref_addr
;
7883 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7884 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7886 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7890 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7891 if (parent_scope
== NULL
)
7894 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7900 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7902 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7903 struct objfile
*objfile
= per_objfile
->objfile
;
7904 struct gdbarch
*gdbarch
= objfile
->arch ();
7906 const char *actual_name
= NULL
;
7909 baseaddr
= objfile
->text_section_offset ();
7911 gdb::unique_xmalloc_ptr
<char> built_actual_name
7912 = partial_die_full_name (pdi
, cu
);
7913 if (built_actual_name
!= NULL
)
7914 actual_name
= built_actual_name
.get ();
7916 if (actual_name
== NULL
)
7917 actual_name
= pdi
->name (cu
);
7919 partial_symbol psymbol
;
7920 memset (&psymbol
, 0, sizeof (psymbol
));
7921 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7922 &objfile
->objfile_obstack
);
7923 psymbol
.ginfo
.set_section_index (-1);
7925 /* The code below indicates that the psymbol should be installed by
7927 gdb::optional
<psymbol_placement
> where
;
7931 case DW_TAG_inlined_subroutine
:
7932 case DW_TAG_subprogram
:
7933 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7935 if (pdi
->is_external
7936 || cu
->per_cu
->lang
== language_ada
7937 || (cu
->per_cu
->lang
== language_fortran
7938 && pdi
->die_parent
!= NULL
7939 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7941 /* Normally, only "external" DIEs are part of the global scope.
7942 But in Ada and Fortran, we want to be able to access nested
7943 procedures globally. So all Ada and Fortran subprograms are
7944 stored in the global scope. */
7945 where
= psymbol_placement::GLOBAL
;
7948 where
= psymbol_placement::STATIC
;
7950 psymbol
.domain
= VAR_DOMAIN
;
7951 psymbol
.aclass
= LOC_BLOCK
;
7952 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7953 psymbol
.ginfo
.value
.address
= addr
;
7955 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7956 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7958 case DW_TAG_constant
:
7959 psymbol
.domain
= VAR_DOMAIN
;
7960 psymbol
.aclass
= LOC_STATIC
;
7961 where
= (pdi
->is_external
7962 ? psymbol_placement::GLOBAL
7963 : psymbol_placement::STATIC
);
7965 case DW_TAG_variable
:
7967 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7971 && !per_objfile
->per_bfd
->has_section_at_zero
)
7973 /* A global or static variable may also have been stripped
7974 out by the linker if unused, in which case its address
7975 will be nullified; do not add such variables into partial
7976 symbol table then. */
7978 else if (pdi
->is_external
)
7981 Don't enter into the minimal symbol tables as there is
7982 a minimal symbol table entry from the ELF symbols already.
7983 Enter into partial symbol table if it has a location
7984 descriptor or a type.
7985 If the location descriptor is missing, new_symbol will create
7986 a LOC_UNRESOLVED symbol, the address of the variable will then
7987 be determined from the minimal symbol table whenever the variable
7989 The address for the partial symbol table entry is not
7990 used by GDB, but it comes in handy for debugging partial symbol
7993 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7995 psymbol
.domain
= VAR_DOMAIN
;
7996 psymbol
.aclass
= LOC_STATIC
;
7997 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7998 psymbol
.ginfo
.value
.address
= addr
;
7999 where
= psymbol_placement::GLOBAL
;
8004 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8006 /* Static Variable. Skip symbols whose value we cannot know (those
8007 without location descriptors or constant values). */
8008 if (!has_loc
&& !pdi
->has_const_value
)
8011 psymbol
.domain
= VAR_DOMAIN
;
8012 psymbol
.aclass
= LOC_STATIC
;
8013 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8015 psymbol
.ginfo
.value
.address
= addr
;
8016 where
= psymbol_placement::STATIC
;
8019 case DW_TAG_array_type
:
8020 case DW_TAG_typedef
:
8021 case DW_TAG_base_type
:
8022 case DW_TAG_subrange_type
:
8023 psymbol
.domain
= VAR_DOMAIN
;
8024 psymbol
.aclass
= LOC_TYPEDEF
;
8025 where
= psymbol_placement::STATIC
;
8027 case DW_TAG_imported_declaration
:
8028 case DW_TAG_namespace
:
8029 psymbol
.domain
= VAR_DOMAIN
;
8030 psymbol
.aclass
= LOC_TYPEDEF
;
8031 where
= psymbol_placement::GLOBAL
;
8034 /* With Fortran 77 there might be a "BLOCK DATA" module
8035 available without any name. If so, we skip the module as it
8036 doesn't bring any value. */
8037 if (actual_name
!= nullptr)
8039 psymbol
.domain
= MODULE_DOMAIN
;
8040 psymbol
.aclass
= LOC_TYPEDEF
;
8041 where
= psymbol_placement::GLOBAL
;
8044 case DW_TAG_class_type
:
8045 case DW_TAG_interface_type
:
8046 case DW_TAG_structure_type
:
8047 case DW_TAG_union_type
:
8048 case DW_TAG_enumeration_type
:
8049 /* Skip external references. The DWARF standard says in the section
8050 about "Structure, Union, and Class Type Entries": "An incomplete
8051 structure, union or class type is represented by a structure,
8052 union or class entry that does not have a byte size attribute
8053 and that has a DW_AT_declaration attribute." */
8054 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8057 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8058 static vs. global. */
8059 psymbol
.domain
= STRUCT_DOMAIN
;
8060 psymbol
.aclass
= LOC_TYPEDEF
;
8061 where
= (cu
->per_cu
->lang
== language_cplus
8062 ? psymbol_placement::GLOBAL
8063 : psymbol_placement::STATIC
);
8065 case DW_TAG_enumerator
:
8066 psymbol
.domain
= VAR_DOMAIN
;
8067 psymbol
.aclass
= LOC_CONST
;
8068 where
= (cu
->per_cu
->lang
== language_cplus
8069 ? psymbol_placement::GLOBAL
8070 : psymbol_placement::STATIC
);
8076 if (where
.has_value ())
8078 if (built_actual_name
!= nullptr)
8079 actual_name
= objfile
->intern (actual_name
);
8080 if (pdi
->linkage_name
== nullptr
8081 || cu
->per_cu
->lang
== language_ada
)
8082 psymbol
.ginfo
.set_linkage_name (actual_name
);
8085 psymbol
.ginfo
.set_demangled_name (actual_name
,
8086 &objfile
->objfile_obstack
);
8087 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8089 cu
->per_cu
->v
.psymtab
->add_psymbol
8090 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8095 /* Read a partial die corresponding to a namespace; also, add a symbol
8096 corresponding to that namespace to the symbol table. NAMESPACE is
8097 the name of the enclosing namespace. */
8100 add_partial_namespace (struct partial_die_info
*pdi
,
8101 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8102 int set_addrmap
, struct dwarf2_cu
*cu
)
8104 /* Add a symbol for the namespace. */
8106 add_partial_symbol (pdi
, cu
);
8108 /* Now scan partial symbols in that namespace. */
8110 if (pdi
->has_children
)
8111 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8114 /* Read a partial die corresponding to a Fortran module. */
8117 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8118 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8120 /* Add a symbol for the namespace. */
8122 add_partial_symbol (pdi
, cu
);
8124 /* Now scan partial symbols in that module. */
8126 if (pdi
->has_children
)
8127 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8131 dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
8132 dwarf2_psymtab
*, dwarf_tag
);
8134 /* Read a partial die corresponding to a subprogram or an inlined
8135 subprogram and create a partial symbol for that subprogram.
8136 When the CU language allows it, this routine also defines a partial
8137 symbol for each nested subprogram that this subprogram contains.
8138 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8139 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8141 PDI may also be a lexical block, in which case we simply search
8142 recursively for subprograms defined inside that lexical block.
8143 Again, this is only performed when the CU language allows this
8144 type of definitions. */
8147 add_partial_subprogram (struct partial_die_info
*pdi
,
8148 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8149 int set_addrmap
, struct dwarf2_cu
*cu
)
8151 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8153 if (pdi
->has_pc_info
)
8155 if (pdi
->lowpc
< *lowpc
)
8156 *lowpc
= pdi
->lowpc
;
8157 if (pdi
->highpc
> *highpc
)
8158 *highpc
= pdi
->highpc
;
8161 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8162 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8163 struct gdbarch
*gdbarch
= objfile
->arch ();
8165 CORE_ADDR this_highpc
;
8166 CORE_ADDR this_lowpc
;
8168 baseaddr
= objfile
->text_section_offset ();
8170 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8171 pdi
->lowpc
+ baseaddr
)
8174 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8175 pdi
->highpc
+ baseaddr
)
8177 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8178 this_lowpc
, this_highpc
- 1,
8179 cu
->per_cu
->v
.psymtab
);
8183 if (pdi
->has_range_info
8184 && dwarf2_ranges_read (pdi
->ranges_offset
, &pdi
->lowpc
, &pdi
->highpc
,
8186 set_addrmap
? cu
->per_cu
->v
.psymtab
: nullptr,
8189 if (pdi
->lowpc
< *lowpc
)
8190 *lowpc
= pdi
->lowpc
;
8191 if (pdi
->highpc
> *highpc
)
8192 *highpc
= pdi
->highpc
;
8195 if (pdi
->has_pc_info
|| pdi
->has_range_info
8196 || (!pdi
->is_external
&& pdi
->may_be_inlined
))
8198 if (!pdi
->is_declaration
)
8199 /* Ignore subprogram DIEs that do not have a name, they are
8200 illegal. Do not emit a complaint at this point, we will
8201 do so when we convert this psymtab into a symtab. */
8203 add_partial_symbol (pdi
, cu
);
8207 if (! pdi
->has_children
)
8210 if (cu
->per_cu
->lang
== language_ada
8211 || cu
->per_cu
->lang
== language_fortran
)
8213 pdi
= pdi
->die_child
;
8217 if (pdi
->tag
== DW_TAG_subprogram
8218 || pdi
->tag
== DW_TAG_inlined_subroutine
8219 || pdi
->tag
== DW_TAG_lexical_block
)
8220 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8221 pdi
= pdi
->die_sibling
;
8226 /* Read a partial die corresponding to an enumeration type. */
8229 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8230 struct dwarf2_cu
*cu
)
8232 struct partial_die_info
*pdi
;
8234 if (enum_pdi
->name (cu
) != NULL
)
8235 add_partial_symbol (enum_pdi
, cu
);
8237 pdi
= enum_pdi
->die_child
;
8240 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8241 complaint (_("malformed enumerator DIE ignored"));
8243 add_partial_symbol (pdi
, cu
);
8244 pdi
= pdi
->die_sibling
;
8248 /* Return the initial uleb128 in the die at INFO_PTR. */
8251 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8253 unsigned int bytes_read
;
8255 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8258 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8259 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8261 Return the corresponding abbrev, or NULL if the number is zero (indicating
8262 an empty DIE). In either case *BYTES_READ will be set to the length of
8263 the initial number. */
8265 static const struct abbrev_info
*
8266 peek_die_abbrev (const die_reader_specs
&reader
,
8267 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8269 dwarf2_cu
*cu
= reader
.cu
;
8270 bfd
*abfd
= reader
.abfd
;
8271 unsigned int abbrev_number
8272 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8274 if (abbrev_number
== 0)
8277 const abbrev_info
*abbrev
8278 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8281 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8282 " at offset %s [in module %s]"),
8283 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8284 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8290 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8291 Returns a pointer to the end of a series of DIEs, terminated by an empty
8292 DIE. Any children of the skipped DIEs will also be skipped. */
8294 static const gdb_byte
*
8295 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8299 unsigned int bytes_read
;
8300 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8304 return info_ptr
+ bytes_read
;
8306 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8310 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8311 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8312 abbrev corresponding to that skipped uleb128 should be passed in
8313 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8316 static const gdb_byte
*
8317 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8318 const struct abbrev_info
*abbrev
)
8320 unsigned int bytes_read
;
8321 struct attribute attr
;
8322 bfd
*abfd
= reader
->abfd
;
8323 struct dwarf2_cu
*cu
= reader
->cu
;
8324 const gdb_byte
*buffer
= reader
->buffer
;
8325 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8326 unsigned int form
, i
;
8328 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8330 /* The only abbrev we care about is DW_AT_sibling. */
8331 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8333 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8334 if (attr
.form
== DW_FORM_ref_addr
)
8335 complaint (_("ignoring absolute DW_AT_sibling"));
8338 sect_offset off
= attr
.get_ref_die_offset ();
8339 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8341 if (sibling_ptr
< info_ptr
)
8342 complaint (_("DW_AT_sibling points backwards"));
8343 else if (sibling_ptr
> reader
->buffer_end
)
8344 reader
->die_section
->overflow_complaint ();
8350 /* If it isn't DW_AT_sibling, skip this attribute. */
8351 form
= abbrev
->attrs
[i
].form
;
8355 case DW_FORM_ref_addr
:
8356 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8357 and later it is offset sized. */
8358 if (cu
->header
.version
== 2)
8359 info_ptr
+= cu
->header
.addr_size
;
8361 info_ptr
+= cu
->header
.offset_size
;
8363 case DW_FORM_GNU_ref_alt
:
8364 info_ptr
+= cu
->header
.offset_size
;
8367 info_ptr
+= cu
->header
.addr_size
;
8375 case DW_FORM_flag_present
:
8376 case DW_FORM_implicit_const
:
8393 case DW_FORM_ref_sig8
:
8396 case DW_FORM_data16
:
8399 case DW_FORM_string
:
8400 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8401 info_ptr
+= bytes_read
;
8403 case DW_FORM_sec_offset
:
8405 case DW_FORM_GNU_strp_alt
:
8406 info_ptr
+= cu
->header
.offset_size
;
8408 case DW_FORM_exprloc
:
8410 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8411 info_ptr
+= bytes_read
;
8413 case DW_FORM_block1
:
8414 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8416 case DW_FORM_block2
:
8417 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8419 case DW_FORM_block4
:
8420 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8426 case DW_FORM_ref_udata
:
8427 case DW_FORM_GNU_addr_index
:
8428 case DW_FORM_GNU_str_index
:
8429 case DW_FORM_rnglistx
:
8430 case DW_FORM_loclistx
:
8431 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8433 case DW_FORM_indirect
:
8434 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8435 info_ptr
+= bytes_read
;
8436 /* We need to continue parsing from here, so just go back to
8438 goto skip_attribute
;
8441 error (_("Dwarf Error: Cannot handle %s "
8442 "in DWARF reader [in module %s]"),
8443 dwarf_form_name (form
),
8444 bfd_get_filename (abfd
));
8448 if (abbrev
->has_children
)
8449 return skip_children (reader
, info_ptr
);
8454 /* Locate ORIG_PDI's sibling.
8455 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8457 static const gdb_byte
*
8458 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8459 struct partial_die_info
*orig_pdi
,
8460 const gdb_byte
*info_ptr
)
8462 /* Do we know the sibling already? */
8464 if (orig_pdi
->sibling
)
8465 return orig_pdi
->sibling
;
8467 /* Are there any children to deal with? */
8469 if (!orig_pdi
->has_children
)
8472 /* Skip the children the long way. */
8474 return skip_children (reader
, info_ptr
);
8477 /* Expand this partial symbol table into a full symbol table. SELF is
8481 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8483 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8485 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8487 /* If this psymtab is constructed from a debug-only objfile, the
8488 has_section_at_zero flag will not necessarily be correct. We
8489 can get the correct value for this flag by looking at the data
8490 associated with the (presumably stripped) associated objfile. */
8491 if (objfile
->separate_debug_objfile_backlink
)
8493 dwarf2_per_objfile
*per_objfile_backlink
8494 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8496 per_objfile
->per_bfd
->has_section_at_zero
8497 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8500 expand_psymtab (objfile
);
8502 process_cu_includes (per_objfile
);
8505 /* Reading in full CUs. */
8507 /* Add PER_CU to the queue. */
8510 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8511 dwarf2_per_objfile
*per_objfile
,
8512 enum language pretend_language
)
8516 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8517 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8520 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8522 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8525 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8526 DIEs, false otherwise.
8528 Explanation: there is an invariant that if a CU is queued for expansion
8529 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8530 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8531 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8532 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8533 invariant is respected.
8535 The caller is therefore not required to load the CU's DIEs (we return false)
8538 - the CU is already expanded, and therefore does not get enqueued
8539 - the CU gets enqueued for expansion, but its DIEs are already loaded
8541 Note that the caller should not use this function's return value as an
8542 indicator of whether the CU's DIEs are loaded right now, it should check
8543 that by calling `dwarf2_per_objfile::get_cu` instead. */
8546 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8547 dwarf2_per_cu_data
*per_cu
,
8548 dwarf2_per_objfile
*per_objfile
,
8549 enum language pretend_language
)
8551 /* We may arrive here during partial symbol reading, if we need full
8552 DIEs to process an unusual case (e.g. template arguments). Do
8553 not queue PER_CU, just tell our caller to load its DIEs. */
8554 if (per_cu
->per_bfd
->reading_partial_symbols
)
8556 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8558 if (cu
== NULL
|| cu
->dies
== NULL
)
8563 /* Mark the dependence relation so that we don't flush PER_CU
8565 if (dependent_cu
!= NULL
)
8566 dependent_cu
->add_dependence (per_cu
);
8568 /* If it's already on the queue, we have nothing to do. */
8571 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8573 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8575 /* If the CU is queued for expansion, it should not already be
8577 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8579 /* The DIEs are already loaded, the caller doesn't need to do it. */
8583 bool queued
= false;
8584 if (!per_objfile
->symtab_set_p (per_cu
))
8586 /* Add it to the queue. */
8587 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8591 /* If the compilation unit is already loaded, just mark it as
8593 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8597 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8598 and the DIEs are not already loaded. */
8599 return queued
&& cu
== nullptr;
8602 /* Process the queue. */
8605 process_queue (dwarf2_per_objfile
*per_objfile
)
8607 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8608 objfile_name (per_objfile
->objfile
));
8610 /* The queue starts out with one item, but following a DIE reference
8611 may load a new CU, adding it to the end of the queue. */
8612 while (!per_objfile
->per_bfd
->queue
->empty ())
8614 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8615 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8617 if (!per_objfile
->symtab_set_p (per_cu
))
8619 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8621 /* Skip dummy CUs. */
8624 unsigned int debug_print_threshold
;
8627 if (per_cu
->is_debug_types
)
8629 struct signatured_type
*sig_type
=
8630 (struct signatured_type
*) per_cu
;
8632 sprintf (buf
, "TU %s at offset %s",
8633 hex_string (sig_type
->signature
),
8634 sect_offset_str (per_cu
->sect_off
));
8635 /* There can be 100s of TUs.
8636 Only print them in verbose mode. */
8637 debug_print_threshold
= 2;
8641 sprintf (buf
, "CU at offset %s",
8642 sect_offset_str (per_cu
->sect_off
));
8643 debug_print_threshold
= 1;
8646 if (dwarf_read_debug
>= debug_print_threshold
)
8647 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8649 if (per_cu
->is_debug_types
)
8650 process_full_type_unit (cu
, item
.pretend_language
);
8652 process_full_comp_unit (cu
, item
.pretend_language
);
8654 if (dwarf_read_debug
>= debug_print_threshold
)
8655 dwarf_read_debug_printf ("Done expanding %s", buf
);
8660 per_objfile
->per_bfd
->queue
->pop ();
8663 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8664 objfile_name (per_objfile
->objfile
));
8667 /* Read in full symbols for PST, and anything it depends on. */
8670 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8672 gdb_assert (!readin_p (objfile
));
8674 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8675 free_cached_comp_units
freer (per_objfile
);
8676 expand_dependencies (objfile
);
8678 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8679 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8682 /* See psympriv.h. */
8685 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8687 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8688 return per_objfile
->symtab_set_p (per_cu_data
);
8691 /* See psympriv.h. */
8694 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8696 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8697 return per_objfile
->get_symtab (per_cu_data
);
8700 /* Trivial hash function for die_info: the hash value of a DIE
8701 is its offset in .debug_info for this objfile. */
8704 die_hash (const void *item
)
8706 const struct die_info
*die
= (const struct die_info
*) item
;
8708 return to_underlying (die
->sect_off
);
8711 /* Trivial comparison function for die_info structures: two DIEs
8712 are equal if they have the same offset. */
8715 die_eq (const void *item_lhs
, const void *item_rhs
)
8717 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8718 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8720 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8723 /* Load the DIEs associated with PER_CU into memory.
8725 In some cases, the caller, while reading partial symbols, will need to load
8726 the full symbols for the CU for some reason. It will already have a
8727 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8728 rather than creating a new one. */
8731 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8732 dwarf2_per_objfile
*per_objfile
,
8733 dwarf2_cu
*existing_cu
,
8735 enum language pretend_language
)
8737 gdb_assert (! this_cu
->is_debug_types
);
8739 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8743 struct dwarf2_cu
*cu
= reader
.cu
;
8744 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8746 gdb_assert (cu
->die_hash
== NULL
);
8748 htab_create_alloc_ex (cu
->header
.length
/ 12,
8752 &cu
->comp_unit_obstack
,
8753 hashtab_obstack_allocate
,
8754 dummy_obstack_deallocate
);
8756 if (reader
.comp_unit_die
->has_children
)
8757 reader
.comp_unit_die
->child
8758 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8759 &info_ptr
, reader
.comp_unit_die
);
8760 cu
->dies
= reader
.comp_unit_die
;
8761 /* comp_unit_die is not stored in die_hash, no need. */
8763 /* We try not to read any attributes in this function, because not
8764 all CUs needed for references have been loaded yet, and symbol
8765 table processing isn't initialized. But we have to set the CU language,
8766 or we won't be able to build types correctly.
8767 Similarly, if we do not read the producer, we can not apply
8768 producer-specific interpretation. */
8769 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8774 /* Add a DIE to the delayed physname list. */
8777 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8778 const char *name
, struct die_info
*die
,
8779 struct dwarf2_cu
*cu
)
8781 struct delayed_method_info mi
;
8783 mi
.fnfield_index
= fnfield_index
;
8787 cu
->method_list
.push_back (mi
);
8790 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8791 "const" / "volatile". If so, decrements LEN by the length of the
8792 modifier and return true. Otherwise return false. */
8796 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8798 size_t mod_len
= sizeof (mod
) - 1;
8799 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8807 /* Compute the physnames of any methods on the CU's method list.
8809 The computation of method physnames is delayed in order to avoid the
8810 (bad) condition that one of the method's formal parameters is of an as yet
8814 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8816 /* Only C++ delays computing physnames. */
8817 if (cu
->method_list
.empty ())
8819 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8821 for (const delayed_method_info
&mi
: cu
->method_list
)
8823 const char *physname
;
8824 struct fn_fieldlist
*fn_flp
8825 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8826 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8827 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8828 = physname
? physname
: "";
8830 /* Since there's no tag to indicate whether a method is a
8831 const/volatile overload, extract that information out of the
8833 if (physname
!= NULL
)
8835 size_t len
= strlen (physname
);
8839 if (physname
[len
] == ')') /* shortcut */
8841 else if (check_modifier (physname
, len
, " const"))
8842 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8843 else if (check_modifier (physname
, len
, " volatile"))
8844 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8851 /* The list is no longer needed. */
8852 cu
->method_list
.clear ();
8855 /* Go objects should be embedded in a DW_TAG_module DIE,
8856 and it's not clear if/how imported objects will appear.
8857 To keep Go support simple until that's worked out,
8858 go back through what we've read and create something usable.
8859 We could do this while processing each DIE, and feels kinda cleaner,
8860 but that way is more invasive.
8861 This is to, for example, allow the user to type "p var" or "b main"
8862 without having to specify the package name, and allow lookups
8863 of module.object to work in contexts that use the expression
8867 fixup_go_packaging (struct dwarf2_cu
*cu
)
8869 gdb::unique_xmalloc_ptr
<char> package_name
;
8870 struct pending
*list
;
8873 for (list
= *cu
->get_builder ()->get_global_symbols ();
8877 for (i
= 0; i
< list
->nsyms
; ++i
)
8879 struct symbol
*sym
= list
->symbol
[i
];
8881 if (sym
->language () == language_go
8882 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8884 gdb::unique_xmalloc_ptr
<char> this_package_name
8885 (go_symbol_package_name (sym
));
8887 if (this_package_name
== NULL
)
8889 if (package_name
== NULL
)
8890 package_name
= std::move (this_package_name
);
8893 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8894 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8895 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8896 (symbol_symtab (sym
) != NULL
8897 ? symtab_to_filename_for_display
8898 (symbol_symtab (sym
))
8899 : objfile_name (objfile
)),
8900 this_package_name
.get (), package_name
.get ());
8906 if (package_name
!= NULL
)
8908 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8909 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8910 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8911 saved_package_name
);
8914 sym
= new (&objfile
->objfile_obstack
) symbol
;
8915 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8916 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8917 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8918 e.g., "main" finds the "main" module and not C's main(). */
8919 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8920 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8921 SYMBOL_TYPE (sym
) = type
;
8923 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8927 /* Allocate a fully-qualified name consisting of the two parts on the
8931 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8933 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8936 /* A helper that allocates a variant part to attach to a Rust enum
8937 type. OBSTACK is where the results should be allocated. TYPE is
8938 the type we're processing. DISCRIMINANT_INDEX is the index of the
8939 discriminant. It must be the index of one of the fields of TYPE,
8940 or -1 to mean there is no discriminant (univariant enum).
8941 DEFAULT_INDEX is the index of the default field; or -1 if there is
8942 no default. RANGES is indexed by "effective" field number (the
8943 field index, but omitting the discriminant and default fields) and
8944 must hold the discriminant values used by the variants. Note that
8945 RANGES must have a lifetime at least as long as OBSTACK -- either
8946 already allocated on it, or static. */
8949 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8950 int discriminant_index
, int default_index
,
8951 gdb::array_view
<discriminant_range
> ranges
)
8953 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8954 gdb_assert (discriminant_index
== -1
8955 || (discriminant_index
>= 0
8956 && discriminant_index
< type
->num_fields ()));
8957 gdb_assert (default_index
== -1
8958 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8960 /* We have one variant for each non-discriminant field. */
8961 int n_variants
= type
->num_fields ();
8962 if (discriminant_index
!= -1)
8965 variant
*variants
= new (obstack
) variant
[n_variants
];
8968 for (int i
= 0; i
< type
->num_fields (); ++i
)
8970 if (i
== discriminant_index
)
8973 variants
[var_idx
].first_field
= i
;
8974 variants
[var_idx
].last_field
= i
+ 1;
8976 /* The default field does not need a range, but other fields do.
8977 We skipped the discriminant above. */
8978 if (i
!= default_index
)
8980 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8987 gdb_assert (range_idx
== ranges
.size ());
8988 gdb_assert (var_idx
== n_variants
);
8990 variant_part
*part
= new (obstack
) variant_part
;
8991 part
->discriminant_index
= discriminant_index
;
8992 /* If there is no discriminant, then whether it is signed is of no
8995 = (discriminant_index
== -1
8997 : type
->field (discriminant_index
).type ()->is_unsigned ());
8998 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9000 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9001 gdb::array_view
<variant_part
> *prop_value
9002 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9004 struct dynamic_prop prop
;
9005 prop
.set_variant_parts (prop_value
);
9007 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9010 /* Some versions of rustc emitted enums in an unusual way.
9012 Ordinary enums were emitted as unions. The first element of each
9013 structure in the union was named "RUST$ENUM$DISR". This element
9014 held the discriminant.
9016 These versions of Rust also implemented the "non-zero"
9017 optimization. When the enum had two values, and one is empty and
9018 the other holds a pointer that cannot be zero, the pointer is used
9019 as the discriminant, with a zero value meaning the empty variant.
9020 Here, the union's first member is of the form
9021 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9022 where the fieldnos are the indices of the fields that should be
9023 traversed in order to find the field (which may be several fields deep)
9024 and the variantname is the name of the variant of the case when the
9027 This function recognizes whether TYPE is of one of these forms,
9028 and, if so, smashes it to be a variant type. */
9031 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9033 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9035 /* We don't need to deal with empty enums. */
9036 if (type
->num_fields () == 0)
9039 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9040 if (type
->num_fields () == 1
9041 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
9043 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
9045 /* Decode the field name to find the offset of the
9047 ULONGEST bit_offset
= 0;
9048 struct type
*field_type
= type
->field (0).type ();
9049 while (name
[0] >= '0' && name
[0] <= '9')
9052 unsigned long index
= strtoul (name
, &tail
, 10);
9055 || index
>= field_type
->num_fields ()
9056 || (field_type
->field (index
).loc_kind ()
9057 != FIELD_LOC_KIND_BITPOS
))
9059 complaint (_("Could not parse Rust enum encoding string \"%s\""
9061 type
->field (0).name (),
9062 objfile_name (objfile
));
9067 bit_offset
+= field_type
->field (index
).loc_bitpos ();
9068 field_type
= field_type
->field (index
).type ();
9071 /* Smash this type to be a structure type. We have to do this
9072 because the type has already been recorded. */
9073 type
->set_code (TYPE_CODE_STRUCT
);
9074 type
->set_num_fields (3);
9075 /* Save the field we care about. */
9076 struct field saved_field
= type
->field (0);
9078 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9080 /* Put the discriminant at index 0. */
9081 type
->field (0).set_type (field_type
);
9082 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9083 type
->field (0).set_name ("<<discriminant>>");
9084 type
->field (0).set_loc_bitpos (bit_offset
);
9086 /* The order of fields doesn't really matter, so put the real
9087 field at index 1 and the data-less field at index 2. */
9088 type
->field (1) = saved_field
;
9089 type
->field (1).set_name
9090 (rust_last_path_segment (type
->field (1).type ()->name ()));
9091 type
->field (1).type ()->set_name
9092 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9093 type
->field (1).name ()));
9095 const char *dataless_name
9096 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9098 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9100 type
->field (2).set_type (dataless_type
);
9101 /* NAME points into the original discriminant name, which
9102 already has the correct lifetime. */
9103 type
->field (2).set_name (name
);
9104 type
->field (2).set_loc_bitpos (0);
9106 /* Indicate that this is a variant type. */
9107 static discriminant_range ranges
[1] = { { 0, 0 } };
9108 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9110 /* A union with a single anonymous field is probably an old-style
9112 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
9114 /* Smash this type to be a structure type. We have to do this
9115 because the type has already been recorded. */
9116 type
->set_code (TYPE_CODE_STRUCT
);
9118 struct type
*field_type
= type
->field (0).type ();
9119 const char *variant_name
9120 = rust_last_path_segment (field_type
->name ());
9121 type
->field (0).set_name (variant_name
);
9122 field_type
->set_name
9123 (rust_fully_qualify (&objfile
->objfile_obstack
,
9124 type
->name (), variant_name
));
9126 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9130 struct type
*disr_type
= nullptr;
9131 for (int i
= 0; i
< type
->num_fields (); ++i
)
9133 disr_type
= type
->field (i
).type ();
9135 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9137 /* All fields of a true enum will be structs. */
9140 else if (disr_type
->num_fields () == 0)
9142 /* Could be data-less variant, so keep going. */
9143 disr_type
= nullptr;
9145 else if (strcmp (disr_type
->field (0).name (),
9146 "RUST$ENUM$DISR") != 0)
9148 /* Not a Rust enum. */
9158 /* If we got here without a discriminant, then it's probably
9160 if (disr_type
== nullptr)
9163 /* Smash this type to be a structure type. We have to do this
9164 because the type has already been recorded. */
9165 type
->set_code (TYPE_CODE_STRUCT
);
9167 /* Make space for the discriminant field. */
9168 struct field
*disr_field
= &disr_type
->field (0);
9170 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9171 * sizeof (struct field
)));
9172 memcpy (new_fields
+ 1, type
->fields (),
9173 type
->num_fields () * sizeof (struct field
));
9174 type
->set_fields (new_fields
);
9175 type
->set_num_fields (type
->num_fields () + 1);
9177 /* Install the discriminant at index 0 in the union. */
9178 type
->field (0) = *disr_field
;
9179 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9180 type
->field (0).set_name ("<<discriminant>>");
9182 /* We need a way to find the correct discriminant given a
9183 variant name. For convenience we build a map here. */
9184 struct type
*enum_type
= disr_field
->type ();
9185 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9186 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9188 if (enum_type
->field (i
).loc_kind () == FIELD_LOC_KIND_ENUMVAL
)
9191 = rust_last_path_segment (enum_type
->field (i
).name ());
9192 discriminant_map
[name
] = enum_type
->field (i
).loc_enumval ();
9196 int n_fields
= type
->num_fields ();
9197 /* We don't need a range entry for the discriminant, but we do
9198 need one for every other field, as there is no default
9200 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9203 /* Skip the discriminant here. */
9204 for (int i
= 1; i
< n_fields
; ++i
)
9206 /* Find the final word in the name of this variant's type.
9207 That name can be used to look up the correct
9209 const char *variant_name
9210 = rust_last_path_segment (type
->field (i
).type ()->name ());
9212 auto iter
= discriminant_map
.find (variant_name
);
9213 if (iter
!= discriminant_map
.end ())
9215 ranges
[i
- 1].low
= iter
->second
;
9216 ranges
[i
- 1].high
= iter
->second
;
9219 /* In Rust, each element should have the size of the
9221 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9223 /* Remove the discriminant field, if it exists. */
9224 struct type
*sub_type
= type
->field (i
).type ();
9225 if (sub_type
->num_fields () > 0)
9227 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9228 sub_type
->set_fields (sub_type
->fields () + 1);
9230 type
->field (i
).set_name (variant_name
);
9232 (rust_fully_qualify (&objfile
->objfile_obstack
,
9233 type
->name (), variant_name
));
9236 /* Indicate that this is a variant type. */
9237 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9238 gdb::array_view
<discriminant_range
> (ranges
,
9243 /* Rewrite some Rust unions to be structures with variants parts. */
9246 rust_union_quirks (struct dwarf2_cu
*cu
)
9248 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9249 for (type
*type_
: cu
->rust_unions
)
9250 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9251 /* We don't need this any more. */
9252 cu
->rust_unions
.clear ();
9257 type_unit_group_unshareable
*
9258 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9260 auto iter
= this->m_type_units
.find (tu_group
);
9261 if (iter
!= this->m_type_units
.end ())
9262 return iter
->second
.get ();
9264 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9265 type_unit_group_unshareable
*result
= uniq
.get ();
9266 this->m_type_units
[tu_group
] = std::move (uniq
);
9271 dwarf2_per_objfile::get_type_for_signatured_type
9272 (signatured_type
*sig_type
) const
9274 auto iter
= this->m_type_map
.find (sig_type
);
9275 if (iter
== this->m_type_map
.end ())
9278 return iter
->second
;
9281 void dwarf2_per_objfile::set_type_for_signatured_type
9282 (signatured_type
*sig_type
, struct type
*type
)
9284 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9286 this->m_type_map
[sig_type
] = type
;
9289 /* A helper function for computing the list of all symbol tables
9290 included by PER_CU. */
9293 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9294 htab_t all_children
, htab_t all_type_symtabs
,
9295 dwarf2_per_cu_data
*per_cu
,
9296 dwarf2_per_objfile
*per_objfile
,
9297 struct compunit_symtab
*immediate_parent
)
9299 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9302 /* This inclusion and its children have been processed. */
9308 /* Only add a CU if it has a symbol table. */
9309 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9312 /* If this is a type unit only add its symbol table if we haven't
9313 seen it yet (type unit per_cu's can share symtabs). */
9314 if (per_cu
->is_debug_types
)
9316 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9320 result
->push_back (cust
);
9321 if (cust
->user
== NULL
)
9322 cust
->user
= immediate_parent
;
9327 result
->push_back (cust
);
9328 if (cust
->user
== NULL
)
9329 cust
->user
= immediate_parent
;
9333 if (!per_cu
->imported_symtabs_empty ())
9334 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9336 recursively_compute_inclusions (result
, all_children
,
9337 all_type_symtabs
, ptr
, per_objfile
,
9342 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9346 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9347 dwarf2_per_objfile
*per_objfile
)
9349 gdb_assert (! per_cu
->is_debug_types
);
9351 if (!per_cu
->imported_symtabs_empty ())
9354 std::vector
<compunit_symtab
*> result_symtabs
;
9355 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9357 /* If we don't have a symtab, we can just skip this case. */
9361 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9363 NULL
, xcalloc
, xfree
));
9364 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9366 NULL
, xcalloc
, xfree
));
9368 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9370 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9371 all_type_symtabs
.get (), ptr
,
9375 /* Now we have a transitive closure of all the included symtabs. */
9376 len
= result_symtabs
.size ();
9378 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9379 struct compunit_symtab
*, len
+ 1);
9380 memcpy (cust
->includes
, result_symtabs
.data (),
9381 len
* sizeof (compunit_symtab
*));
9382 cust
->includes
[len
] = NULL
;
9386 /* Compute the 'includes' field for the symtabs of all the CUs we just
9390 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9392 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9394 if (! iter
->is_debug_types
)
9395 compute_compunit_symtab_includes (iter
, per_objfile
);
9398 per_objfile
->per_bfd
->just_read_cus
.clear ();
9401 /* Generate full symbol information for CU, whose DIEs have
9402 already been loaded into memory. */
9405 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9407 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9408 struct objfile
*objfile
= per_objfile
->objfile
;
9409 struct gdbarch
*gdbarch
= objfile
->arch ();
9410 CORE_ADDR lowpc
, highpc
;
9411 struct compunit_symtab
*cust
;
9413 struct block
*static_block
;
9416 baseaddr
= objfile
->text_section_offset ();
9418 /* Clear the list here in case something was left over. */
9419 cu
->method_list
.clear ();
9421 dwarf2_find_base_address (cu
->dies
, cu
);
9423 /* Before we start reading the top-level DIE, ensure it has a valid tag
9425 switch (cu
->dies
->tag
)
9427 case DW_TAG_compile_unit
:
9428 case DW_TAG_partial_unit
:
9429 case DW_TAG_type_unit
:
9432 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9433 dwarf_tag_name (cu
->dies
->tag
),
9434 sect_offset_str (cu
->per_cu
->sect_off
),
9435 objfile_name (per_objfile
->objfile
));
9438 /* Do line number decoding in read_file_scope () */
9439 process_die (cu
->dies
, cu
);
9441 /* For now fudge the Go package. */
9442 if (cu
->per_cu
->lang
== language_go
)
9443 fixup_go_packaging (cu
);
9445 /* Now that we have processed all the DIEs in the CU, all the types
9446 should be complete, and it should now be safe to compute all of the
9448 compute_delayed_physnames (cu
);
9450 if (cu
->per_cu
->lang
== language_rust
)
9451 rust_union_quirks (cu
);
9453 /* Some compilers don't define a DW_AT_high_pc attribute for the
9454 compilation unit. If the DW_AT_high_pc is missing, synthesize
9455 it, by scanning the DIE's below the compilation unit. */
9456 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9458 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9459 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9461 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9462 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9463 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9464 addrmap to help ensure it has an accurate map of pc values belonging to
9466 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9468 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9469 SECT_OFF_TEXT (objfile
),
9474 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9476 /* Set symtab language to language from DW_AT_language. If the
9477 compilation is from a C file generated by language preprocessors, do
9478 not set the language if it was already deduced by start_subfile. */
9479 if (!(cu
->per_cu
->lang
== language_c
9480 && cust
->primary_filetab ()->language () != language_unknown
))
9481 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
9483 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9484 produce DW_AT_location with location lists but it can be possibly
9485 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9486 there were bugs in prologue debug info, fixed later in GCC-4.5
9487 by "unwind info for epilogues" patch (which is not directly related).
9489 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9490 needed, it would be wrong due to missing DW_AT_producer there.
9492 Still one can confuse GDB by using non-standard GCC compilation
9493 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9495 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9496 cust
->set_locations_valid (true);
9498 if (gcc_4_minor
>= 5)
9499 cust
->set_epilogue_unwind_valid (true);
9501 cust
->set_call_site_htab (cu
->call_site_htab
);
9504 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9506 /* Push it for inclusion processing later. */
9507 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9509 /* Not needed any more. */
9510 cu
->reset_builder ();
9513 /* Generate full symbol information for type unit CU, whose DIEs have
9514 already been loaded into memory. */
9517 process_full_type_unit (dwarf2_cu
*cu
,
9518 enum language pretend_language
)
9520 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9521 struct objfile
*objfile
= per_objfile
->objfile
;
9522 struct compunit_symtab
*cust
;
9523 struct signatured_type
*sig_type
;
9525 gdb_assert (cu
->per_cu
->is_debug_types
);
9526 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9528 /* Clear the list here in case something was left over. */
9529 cu
->method_list
.clear ();
9531 /* The symbol tables are set up in read_type_unit_scope. */
9532 process_die (cu
->dies
, cu
);
9534 /* For now fudge the Go package. */
9535 if (cu
->per_cu
->lang
== language_go
)
9536 fixup_go_packaging (cu
);
9538 /* Now that we have processed all the DIEs in the CU, all the types
9539 should be complete, and it should now be safe to compute all of the
9541 compute_delayed_physnames (cu
);
9543 if (cu
->per_cu
->lang
== language_rust
)
9544 rust_union_quirks (cu
);
9546 /* TUs share symbol tables.
9547 If this is the first TU to use this symtab, complete the construction
9548 of it with end_expandable_symtab. Otherwise, complete the addition of
9549 this TU's symbols to the existing symtab. */
9550 type_unit_group_unshareable
*tug_unshare
=
9551 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9552 if (tug_unshare
->compunit_symtab
== NULL
)
9554 buildsym_compunit
*builder
= cu
->get_builder ();
9555 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9556 tug_unshare
->compunit_symtab
= cust
;
9560 /* Set symtab language to language from DW_AT_language. If the
9561 compilation is from a C file generated by language preprocessors,
9562 do not set the language if it was already deduced by
9564 if (!(cu
->per_cu
->lang
== language_c
9565 && cust
->primary_filetab ()->language () != language_c
))
9566 cust
->primary_filetab ()->set_language (cu
->per_cu
->lang
);
9571 cu
->get_builder ()->augment_type_symtab ();
9572 cust
= tug_unshare
->compunit_symtab
;
9575 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9577 /* Not needed any more. */
9578 cu
->reset_builder ();
9581 /* Process an imported unit DIE. */
9584 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9586 struct attribute
*attr
;
9588 /* For now we don't handle imported units in type units. */
9589 if (cu
->per_cu
->is_debug_types
)
9591 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9592 " supported in type units [in module %s]"),
9593 objfile_name (cu
->per_objfile
->objfile
));
9596 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9599 sect_offset sect_off
= attr
->get_ref_die_offset ();
9600 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9601 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9602 dwarf2_per_cu_data
*per_cu
9603 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9604 per_objfile
->per_bfd
);
9606 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9607 into another compilation unit, at root level. Regard this as a hint,
9609 if (die
->parent
&& die
->parent
->parent
== NULL
9610 && per_cu
->unit_type
== DW_UT_compile
9611 && per_cu
->lang
== language_cplus
)
9614 /* If necessary, add it to the queue and load its DIEs. */
9615 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9617 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9618 false, cu
->per_cu
->lang
);
9620 cu
->per_cu
->imported_symtabs_push (per_cu
);
9624 /* RAII object that represents a process_die scope: i.e.,
9625 starts/finishes processing a DIE. */
9626 class process_die_scope
9629 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9630 : m_die (die
), m_cu (cu
)
9632 /* We should only be processing DIEs not already in process. */
9633 gdb_assert (!m_die
->in_process
);
9634 m_die
->in_process
= true;
9637 ~process_die_scope ()
9639 m_die
->in_process
= false;
9641 /* If we're done processing the DIE for the CU that owns the line
9642 header, we don't need the line header anymore. */
9643 if (m_cu
->line_header_die_owner
== m_die
)
9645 delete m_cu
->line_header
;
9646 m_cu
->line_header
= NULL
;
9647 m_cu
->line_header_die_owner
= NULL
;
9656 /* Process a die and its children. */
9659 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9661 process_die_scope
scope (die
, cu
);
9665 case DW_TAG_padding
:
9667 case DW_TAG_compile_unit
:
9668 case DW_TAG_partial_unit
:
9669 read_file_scope (die
, cu
);
9671 case DW_TAG_type_unit
:
9672 read_type_unit_scope (die
, cu
);
9674 case DW_TAG_subprogram
:
9675 /* Nested subprograms in Fortran get a prefix. */
9676 if (cu
->per_cu
->lang
== language_fortran
9677 && die
->parent
!= NULL
9678 && die
->parent
->tag
== DW_TAG_subprogram
)
9679 cu
->processing_has_namespace_info
= true;
9681 case DW_TAG_inlined_subroutine
:
9682 read_func_scope (die
, cu
);
9684 case DW_TAG_lexical_block
:
9685 case DW_TAG_try_block
:
9686 case DW_TAG_catch_block
:
9687 read_lexical_block_scope (die
, cu
);
9689 case DW_TAG_call_site
:
9690 case DW_TAG_GNU_call_site
:
9691 read_call_site_scope (die
, cu
);
9693 case DW_TAG_class_type
:
9694 case DW_TAG_interface_type
:
9695 case DW_TAG_structure_type
:
9696 case DW_TAG_union_type
:
9697 process_structure_scope (die
, cu
);
9699 case DW_TAG_enumeration_type
:
9700 process_enumeration_scope (die
, cu
);
9703 /* These dies have a type, but processing them does not create
9704 a symbol or recurse to process the children. Therefore we can
9705 read them on-demand through read_type_die. */
9706 case DW_TAG_subroutine_type
:
9707 case DW_TAG_set_type
:
9708 case DW_TAG_pointer_type
:
9709 case DW_TAG_ptr_to_member_type
:
9710 case DW_TAG_reference_type
:
9711 case DW_TAG_rvalue_reference_type
:
9712 case DW_TAG_string_type
:
9715 case DW_TAG_array_type
:
9716 /* We only need to handle this case for Ada -- in other
9717 languages, it's normal for the compiler to emit a typedef
9719 if (cu
->per_cu
->lang
!= language_ada
)
9722 case DW_TAG_base_type
:
9723 case DW_TAG_subrange_type
:
9724 case DW_TAG_typedef
:
9725 /* Add a typedef symbol for the type definition, if it has a
9727 new_symbol (die
, read_type_die (die
, cu
), cu
);
9729 case DW_TAG_common_block
:
9730 read_common_block (die
, cu
);
9732 case DW_TAG_common_inclusion
:
9734 case DW_TAG_namespace
:
9735 cu
->processing_has_namespace_info
= true;
9736 read_namespace (die
, cu
);
9739 cu
->processing_has_namespace_info
= true;
9740 read_module (die
, cu
);
9742 case DW_TAG_imported_declaration
:
9743 cu
->processing_has_namespace_info
= true;
9744 if (read_namespace_alias (die
, cu
))
9746 /* The declaration is not a global namespace alias. */
9748 case DW_TAG_imported_module
:
9749 cu
->processing_has_namespace_info
= true;
9750 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9751 || cu
->per_cu
->lang
!= language_fortran
))
9752 complaint (_("Tag '%s' has unexpected children"),
9753 dwarf_tag_name (die
->tag
));
9754 read_import_statement (die
, cu
);
9757 case DW_TAG_imported_unit
:
9758 process_imported_unit_die (die
, cu
);
9761 case DW_TAG_variable
:
9762 read_variable (die
, cu
);
9766 new_symbol (die
, NULL
, cu
);
9771 /* DWARF name computation. */
9773 /* A helper function for dwarf2_compute_name which determines whether DIE
9774 needs to have the name of the scope prepended to the name listed in the
9778 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9780 struct attribute
*attr
;
9784 case DW_TAG_namespace
:
9785 case DW_TAG_typedef
:
9786 case DW_TAG_class_type
:
9787 case DW_TAG_interface_type
:
9788 case DW_TAG_structure_type
:
9789 case DW_TAG_union_type
:
9790 case DW_TAG_enumeration_type
:
9791 case DW_TAG_enumerator
:
9792 case DW_TAG_subprogram
:
9793 case DW_TAG_inlined_subroutine
:
9795 case DW_TAG_imported_declaration
:
9798 case DW_TAG_variable
:
9799 case DW_TAG_constant
:
9800 /* We only need to prefix "globally" visible variables. These include
9801 any variable marked with DW_AT_external or any variable that
9802 lives in a namespace. [Variables in anonymous namespaces
9803 require prefixing, but they are not DW_AT_external.] */
9805 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9807 struct dwarf2_cu
*spec_cu
= cu
;
9809 return die_needs_namespace (die_specification (die
, &spec_cu
),
9813 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9814 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9815 && die
->parent
->tag
!= DW_TAG_module
)
9817 /* A variable in a lexical block of some kind does not need a
9818 namespace, even though in C++ such variables may be external
9819 and have a mangled name. */
9820 if (die
->parent
->tag
== DW_TAG_lexical_block
9821 || die
->parent
->tag
== DW_TAG_try_block
9822 || die
->parent
->tag
== DW_TAG_catch_block
9823 || die
->parent
->tag
== DW_TAG_subprogram
)
9832 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9833 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9834 defined for the given DIE. */
9836 static struct attribute
*
9837 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9839 struct attribute
*attr
;
9841 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9843 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9848 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9849 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9850 defined for the given DIE. */
9853 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9855 const char *linkage_name
;
9857 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9858 if (linkage_name
== NULL
)
9859 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9861 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9862 See https://github.com/rust-lang/rust/issues/32925. */
9863 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9864 && strchr (linkage_name
, '{') != NULL
)
9865 linkage_name
= NULL
;
9867 return linkage_name
;
9870 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9871 compute the physname for the object, which include a method's:
9872 - formal parameters (C++),
9873 - receiver type (Go),
9875 The term "physname" is a bit confusing.
9876 For C++, for example, it is the demangled name.
9877 For Go, for example, it's the mangled name.
9879 For Ada, return the DIE's linkage name rather than the fully qualified
9880 name. PHYSNAME is ignored..
9882 The result is allocated on the objfile->per_bfd's obstack and
9886 dwarf2_compute_name (const char *name
,
9887 struct die_info
*die
, struct dwarf2_cu
*cu
,
9890 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9893 name
= dwarf2_name (die
, cu
);
9895 enum language lang
= cu
->per_cu
->lang
;
9897 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9898 but otherwise compute it by typename_concat inside GDB.
9899 FIXME: Actually this is not really true, or at least not always true.
9900 It's all very confusing. compute_and_set_names doesn't try to demangle
9901 Fortran names because there is no mangling standard. So new_symbol
9902 will set the demangled name to the result of dwarf2_full_name, and it is
9903 the demangled name that GDB uses if it exists. */
9904 if (lang
== language_ada
9905 || (lang
== language_fortran
&& physname
))
9907 /* For Ada unit, we prefer the linkage name over the name, as
9908 the former contains the exported name, which the user expects
9909 to be able to reference. Ideally, we want the user to be able
9910 to reference this entity using either natural or linkage name,
9911 but we haven't started looking at this enhancement yet. */
9912 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9914 if (linkage_name
!= NULL
)
9915 return linkage_name
;
9918 /* These are the only languages we know how to qualify names in. */
9920 && (lang
== language_cplus
9921 || lang
== language_fortran
|| lang
== language_d
9922 || lang
== language_rust
))
9924 if (die_needs_namespace (die
, cu
))
9927 const char *canonical_name
= NULL
;
9931 prefix
= determine_prefix (die
, cu
);
9932 if (*prefix
!= '\0')
9934 gdb::unique_xmalloc_ptr
<char> prefixed_name
9935 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9937 buf
.puts (prefixed_name
.get ());
9942 /* Template parameters may be specified in the DIE's DW_AT_name, or
9943 as children with DW_TAG_template_type_param or
9944 DW_TAG_value_type_param. If the latter, add them to the name
9945 here. If the name already has template parameters, then
9946 skip this step; some versions of GCC emit both, and
9947 it is more efficient to use the pre-computed name.
9949 Something to keep in mind about this process: it is very
9950 unlikely, or in some cases downright impossible, to produce
9951 something that will match the mangled name of a function.
9952 If the definition of the function has the same debug info,
9953 we should be able to match up with it anyway. But fallbacks
9954 using the minimal symbol, for instance to find a method
9955 implemented in a stripped copy of libstdc++, will not work.
9956 If we do not have debug info for the definition, we will have to
9957 match them up some other way.
9959 When we do name matching there is a related problem with function
9960 templates; two instantiated function templates are allowed to
9961 differ only by their return types, which we do not add here. */
9963 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9965 struct attribute
*attr
;
9966 struct die_info
*child
;
9969 die
->building_fullname
= 1;
9971 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9975 const gdb_byte
*bytes
;
9976 struct dwarf2_locexpr_baton
*baton
;
9979 if (child
->tag
!= DW_TAG_template_type_param
9980 && child
->tag
!= DW_TAG_template_value_param
)
9991 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9994 complaint (_("template parameter missing DW_AT_type"));
9995 buf
.puts ("UNKNOWN_TYPE");
9998 type
= die_type (child
, cu
);
10000 if (child
->tag
== DW_TAG_template_type_param
)
10002 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
10003 &type_print_raw_options
);
10007 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10010 complaint (_("template parameter missing "
10011 "DW_AT_const_value"));
10012 buf
.puts ("UNKNOWN_VALUE");
10016 dwarf2_const_value_attr (attr
, type
, name
,
10017 &cu
->comp_unit_obstack
, cu
,
10018 &value
, &bytes
, &baton
);
10020 if (type
->has_no_signedness ())
10021 /* GDB prints characters as NUMBER 'CHAR'. If that's
10022 changed, this can use value_print instead. */
10023 cu
->language_defn
->printchar (value
, type
, &buf
);
10026 struct value_print_options opts
;
10029 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10033 baton
->per_objfile
);
10034 else if (bytes
!= NULL
)
10036 v
= allocate_value (type
);
10037 memcpy (value_contents_writeable (v
).data (), bytes
,
10038 TYPE_LENGTH (type
));
10041 v
= value_from_longest (type
, value
);
10043 /* Specify decimal so that we do not depend on
10045 get_formatted_print_options (&opts
, 'd');
10047 value_print (v
, &buf
, &opts
);
10052 die
->building_fullname
= 0;
10056 /* Close the argument list, with a space if necessary
10057 (nested templates). */
10058 if (!buf
.empty () && buf
.string ().back () == '>')
10065 /* For C++ methods, append formal parameter type
10066 information, if PHYSNAME. */
10068 if (physname
&& die
->tag
== DW_TAG_subprogram
10069 && lang
== language_cplus
)
10071 struct type
*type
= read_type_die (die
, cu
);
10073 c_type_print_args (type
, &buf
, 1, lang
,
10074 &type_print_raw_options
);
10076 if (lang
== language_cplus
)
10078 /* Assume that an artificial first parameter is
10079 "this", but do not crash if it is not. RealView
10080 marks unnamed (and thus unused) parameters as
10081 artificial; there is no way to differentiate
10083 if (type
->num_fields () > 0
10084 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10085 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10086 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10087 buf
.puts (" const");
10091 const std::string
&intermediate_name
= buf
.string ();
10093 if (lang
== language_cplus
)
10095 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10098 /* If we only computed INTERMEDIATE_NAME, or if
10099 INTERMEDIATE_NAME is already canonical, then we need to
10101 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10102 name
= objfile
->intern (intermediate_name
);
10104 name
= canonical_name
;
10111 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10112 If scope qualifiers are appropriate they will be added. The result
10113 will be allocated on the storage_obstack, or NULL if the DIE does
10114 not have a name. NAME may either be from a previous call to
10115 dwarf2_name or NULL.
10117 The output string will be canonicalized (if C++). */
10119 static const char *
10120 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10122 return dwarf2_compute_name (name
, die
, cu
, 0);
10125 /* Construct a physname for the given DIE in CU. NAME may either be
10126 from a previous call to dwarf2_name or NULL. The result will be
10127 allocated on the objfile_objstack or NULL if the DIE does not have a
10130 The output string will be canonicalized (if C++). */
10132 static const char *
10133 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10135 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10136 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10139 /* In this case dwarf2_compute_name is just a shortcut not building anything
10141 if (!die_needs_namespace (die
, cu
))
10142 return dwarf2_compute_name (name
, die
, cu
, 1);
10144 if (cu
->per_cu
->lang
!= language_rust
)
10145 mangled
= dw2_linkage_name (die
, cu
);
10147 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10149 gdb::unique_xmalloc_ptr
<char> demangled
;
10150 if (mangled
!= NULL
)
10152 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10154 /* Do nothing (do not demangle the symbol name). */
10158 /* Use DMGL_RET_DROP for C++ template functions to suppress
10159 their return type. It is easier for GDB users to search
10160 for such functions as `name(params)' than `long name(params)'.
10161 In such case the minimal symbol names do not match the full
10162 symbol names but for template functions there is never a need
10163 to look up their definition from their declaration so
10164 the only disadvantage remains the minimal symbol variant
10165 `long name(params)' does not have the proper inferior type. */
10166 demangled
= gdb_demangle (mangled
, (DMGL_PARAMS
| DMGL_ANSI
10170 canon
= demangled
.get ();
10178 if (canon
== NULL
|| check_physname
)
10180 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10182 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10184 /* It may not mean a bug in GDB. The compiler could also
10185 compute DW_AT_linkage_name incorrectly. But in such case
10186 GDB would need to be bug-to-bug compatible. */
10188 complaint (_("Computed physname <%s> does not match demangled <%s> "
10189 "(from linkage <%s>) - DIE at %s [in module %s]"),
10190 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10191 objfile_name (objfile
));
10193 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10194 is available here - over computed PHYSNAME. It is safer
10195 against both buggy GDB and buggy compilers. */
10209 retval
= objfile
->intern (retval
);
10214 /* Inspect DIE in CU for a namespace alias. If one exists, record
10215 a new symbol for it.
10217 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10220 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10222 struct attribute
*attr
;
10224 /* If the die does not have a name, this is not a namespace
10226 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10230 struct die_info
*d
= die
;
10231 struct dwarf2_cu
*imported_cu
= cu
;
10233 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10234 keep inspecting DIEs until we hit the underlying import. */
10235 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10236 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10238 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10242 d
= follow_die_ref (d
, attr
, &imported_cu
);
10243 if (d
->tag
!= DW_TAG_imported_declaration
)
10247 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10249 complaint (_("DIE at %s has too many recursively imported "
10250 "declarations"), sect_offset_str (d
->sect_off
));
10257 sect_offset sect_off
= attr
->get_ref_die_offset ();
10259 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10260 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10262 /* This declaration is a global namespace alias. Add
10263 a symbol for it whose type is the aliased namespace. */
10264 new_symbol (die
, type
, cu
);
10273 /* Return the using directives repository (global or local?) to use in the
10274 current context for CU.
10276 For Ada, imported declarations can materialize renamings, which *may* be
10277 global. However it is impossible (for now?) in DWARF to distinguish
10278 "external" imported declarations and "static" ones. As all imported
10279 declarations seem to be static in all other languages, make them all CU-wide
10280 global only in Ada. */
10282 static struct using_direct
**
10283 using_directives (struct dwarf2_cu
*cu
)
10285 if (cu
->per_cu
->lang
== language_ada
10286 && cu
->get_builder ()->outermost_context_p ())
10287 return cu
->get_builder ()->get_global_using_directives ();
10289 return cu
->get_builder ()->get_local_using_directives ();
10292 /* Read the import statement specified by the given die and record it. */
10295 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10297 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10298 struct attribute
*import_attr
;
10299 struct die_info
*imported_die
, *child_die
;
10300 struct dwarf2_cu
*imported_cu
;
10301 const char *imported_name
;
10302 const char *imported_name_prefix
;
10303 const char *canonical_name
;
10304 const char *import_alias
;
10305 const char *imported_declaration
= NULL
;
10306 const char *import_prefix
;
10307 std::vector
<const char *> excludes
;
10309 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10310 if (import_attr
== NULL
)
10312 complaint (_("Tag '%s' has no DW_AT_import"),
10313 dwarf_tag_name (die
->tag
));
10318 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10319 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10320 if (imported_name
== NULL
)
10322 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10324 The import in the following code:
10338 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10339 <52> DW_AT_decl_file : 1
10340 <53> DW_AT_decl_line : 6
10341 <54> DW_AT_import : <0x75>
10342 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10343 <59> DW_AT_name : B
10344 <5b> DW_AT_decl_file : 1
10345 <5c> DW_AT_decl_line : 2
10346 <5d> DW_AT_type : <0x6e>
10348 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10349 <76> DW_AT_byte_size : 4
10350 <77> DW_AT_encoding : 5 (signed)
10352 imports the wrong die ( 0x75 instead of 0x58 ).
10353 This case will be ignored until the gcc bug is fixed. */
10357 /* Figure out the local name after import. */
10358 import_alias
= dwarf2_name (die
, cu
);
10360 /* Figure out where the statement is being imported to. */
10361 import_prefix
= determine_prefix (die
, cu
);
10363 /* Figure out what the scope of the imported die is and prepend it
10364 to the name of the imported die. */
10365 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10367 if (imported_die
->tag
!= DW_TAG_namespace
10368 && imported_die
->tag
!= DW_TAG_module
)
10370 imported_declaration
= imported_name
;
10371 canonical_name
= imported_name_prefix
;
10373 else if (strlen (imported_name_prefix
) > 0)
10374 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10375 imported_name_prefix
,
10376 (cu
->per_cu
->lang
== language_d
10379 imported_name
, (char *) NULL
);
10381 canonical_name
= imported_name
;
10383 if (die
->tag
== DW_TAG_imported_module
10384 && cu
->per_cu
->lang
== language_fortran
)
10385 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10386 child_die
= child_die
->sibling
)
10388 /* DWARF-4: A Fortran use statement with a “rename list” may be
10389 represented by an imported module entry with an import attribute
10390 referring to the module and owned entries corresponding to those
10391 entities that are renamed as part of being imported. */
10393 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10395 complaint (_("child DW_TAG_imported_declaration expected "
10396 "- DIE at %s [in module %s]"),
10397 sect_offset_str (child_die
->sect_off
),
10398 objfile_name (objfile
));
10402 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10403 if (import_attr
== NULL
)
10405 complaint (_("Tag '%s' has no DW_AT_import"),
10406 dwarf_tag_name (child_die
->tag
));
10411 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10413 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10414 if (imported_name
== NULL
)
10416 complaint (_("child DW_TAG_imported_declaration has unknown "
10417 "imported name - DIE at %s [in module %s]"),
10418 sect_offset_str (child_die
->sect_off
),
10419 objfile_name (objfile
));
10423 excludes
.push_back (imported_name
);
10425 process_die (child_die
, cu
);
10428 add_using_directive (using_directives (cu
),
10432 imported_declaration
,
10435 &objfile
->objfile_obstack
);
10438 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10439 types, but gives them a size of zero. Starting with version 14,
10440 ICC is compatible with GCC. */
10443 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10445 if (!cu
->checked_producer
)
10446 check_producer (cu
);
10448 return cu
->producer_is_icc_lt_14
;
10451 /* ICC generates a DW_AT_type for C void functions. This was observed on
10452 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10453 which says that void functions should not have a DW_AT_type. */
10456 producer_is_icc (struct dwarf2_cu
*cu
)
10458 if (!cu
->checked_producer
)
10459 check_producer (cu
);
10461 return cu
->producer_is_icc
;
10464 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10465 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10466 this, it was first present in GCC release 4.3.0. */
10469 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10471 if (!cu
->checked_producer
)
10472 check_producer (cu
);
10474 return cu
->producer_is_gcc_lt_4_3
;
10477 static file_and_directory
&
10478 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10480 if (cu
->per_cu
->fnd
!= nullptr)
10481 return *cu
->per_cu
->fnd
;
10483 /* Find the filename. Do not use dwarf2_name here, since the filename
10484 is not a source language identifier. */
10485 file_and_directory
res (dwarf2_string_attr (die
, DW_AT_name
, cu
),
10486 dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
));
10488 if (res
.get_comp_dir () == nullptr
10489 && producer_is_gcc_lt_4_3 (cu
)
10490 && res
.get_name () != nullptr
10491 && IS_ABSOLUTE_PATH (res
.get_name ()))
10492 res
.set_comp_dir (ldirname (res
.get_name ()));
10494 cu
->per_cu
->fnd
.reset (new file_and_directory (std::move (res
)));
10495 return *cu
->per_cu
->fnd
;
10498 /* Handle DW_AT_stmt_list for a compilation unit.
10499 DIE is the DW_TAG_compile_unit die for CU.
10500 COMP_DIR is the compilation directory. LOWPC is passed to
10501 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10504 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10505 const file_and_directory
&fnd
, CORE_ADDR lowpc
) /* ARI: editCase function */
10507 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10508 struct attribute
*attr
;
10509 struct line_header line_header_local
;
10510 hashval_t line_header_local_hash
;
10512 int decode_mapping
;
10514 gdb_assert (! cu
->per_cu
->is_debug_types
);
10516 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10517 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10520 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10522 /* The line header hash table is only created if needed (it exists to
10523 prevent redundant reading of the line table for partial_units).
10524 If we're given a partial_unit, we'll need it. If we're given a
10525 compile_unit, then use the line header hash table if it's already
10526 created, but don't create one just yet. */
10528 if (per_objfile
->line_header_hash
== NULL
10529 && die
->tag
== DW_TAG_partial_unit
)
10531 per_objfile
->line_header_hash
10532 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10533 line_header_eq_voidp
,
10534 htab_delete_entry
<line_header
>,
10538 line_header_local
.sect_off
= line_offset
;
10539 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10540 line_header_local_hash
= line_header_hash (&line_header_local
);
10541 if (per_objfile
->line_header_hash
!= NULL
)
10543 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10544 &line_header_local
,
10545 line_header_local_hash
, NO_INSERT
);
10547 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10548 is not present in *SLOT (since if there is something in *SLOT then
10549 it will be for a partial_unit). */
10550 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10552 gdb_assert (*slot
!= NULL
);
10553 cu
->line_header
= (struct line_header
*) *slot
;
10558 /* dwarf_decode_line_header does not yet provide sufficient information.
10559 We always have to call also dwarf_decode_lines for it. */
10560 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10564 cu
->line_header
= lh
.release ();
10565 cu
->line_header_die_owner
= die
;
10567 if (per_objfile
->line_header_hash
== NULL
)
10571 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10572 &line_header_local
,
10573 line_header_local_hash
, INSERT
);
10574 gdb_assert (slot
!= NULL
);
10576 if (slot
!= NULL
&& *slot
== NULL
)
10578 /* This newly decoded line number information unit will be owned
10579 by line_header_hash hash table. */
10580 *slot
= cu
->line_header
;
10581 cu
->line_header_die_owner
= NULL
;
10585 /* We cannot free any current entry in (*slot) as that struct line_header
10586 may be already used by multiple CUs. Create only temporary decoded
10587 line_header for this CU - it may happen at most once for each line
10588 number information unit. And if we're not using line_header_hash
10589 then this is what we want as well. */
10590 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10592 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10593 dwarf_decode_lines (cu
->line_header
, fnd
, cu
, nullptr, lowpc
,
10598 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10601 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10603 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10604 struct objfile
*objfile
= per_objfile
->objfile
;
10605 struct gdbarch
*gdbarch
= objfile
->arch ();
10606 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10607 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10608 struct attribute
*attr
;
10609 struct die_info
*child_die
;
10610 CORE_ADDR baseaddr
;
10612 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10613 baseaddr
= objfile
->text_section_offset ();
10615 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10617 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10618 from finish_block. */
10619 if (lowpc
== ((CORE_ADDR
) -1))
10621 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10623 file_and_directory
&fnd
= find_file_and_directory (die
, cu
);
10625 cu
->start_symtab (fnd
.get_name (), fnd
.intern_comp_dir (objfile
), lowpc
);
10627 gdb_assert (per_objfile
->sym_cu
== nullptr);
10628 scoped_restore restore_sym_cu
10629 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10631 /* Decode line number information if present. We do this before
10632 processing child DIEs, so that the line header table is available
10633 for DW_AT_decl_file. The PC check is here because, if LOWPC and
10634 HIGHPC are both 0x0, then there won't be any interesting code in
10635 the CU, but a check later on (in
10636 lnp_state_machine::check_line_address) will fail to properly
10637 exclude an entry that was removed via --gc-sections. */
10638 if (lowpc
!= highpc
)
10639 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
);
10641 /* Process all dies in compilation unit. */
10642 if (die
->child
!= NULL
)
10644 child_die
= die
->child
;
10645 while (child_die
&& child_die
->tag
)
10647 process_die (child_die
, cu
);
10648 child_die
= child_die
->sibling
;
10651 per_objfile
->sym_cu
= nullptr;
10653 /* Decode macro information, if present. Dwarf 2 macro information
10654 refers to information in the line number info statement program
10655 header, so we can only read it if we've read the header
10657 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10659 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10660 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10662 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10663 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10665 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10669 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10670 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10672 unsigned int macro_offset
= attr
->as_unsigned ();
10674 dwarf_decode_macros (cu
, macro_offset
, 0);
10680 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10682 struct type_unit_group
*tu_group
;
10684 struct attribute
*attr
;
10686 struct signatured_type
*sig_type
;
10688 gdb_assert (per_cu
->is_debug_types
);
10689 sig_type
= (struct signatured_type
*) per_cu
;
10691 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10693 /* If we're using .gdb_index (includes -readnow) then
10694 per_cu->type_unit_group may not have been set up yet. */
10695 if (sig_type
->type_unit_group
== NULL
)
10696 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10697 tu_group
= sig_type
->type_unit_group
;
10699 /* If we've already processed this stmt_list there's no real need to
10700 do it again, we could fake it and just recreate the part we need
10701 (file name,index -> symtab mapping). If data shows this optimization
10702 is useful we can do it then. */
10703 type_unit_group_unshareable
*tug_unshare
10704 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10705 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10707 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10710 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10712 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10713 lh
= dwarf_decode_line_header (line_offset
, this);
10718 start_symtab ("", NULL
, 0);
10721 gdb_assert (tug_unshare
->symtabs
== NULL
);
10722 gdb_assert (m_builder
== nullptr);
10723 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10724 m_builder
.reset (new struct buildsym_compunit
10725 (cust
->objfile (), "",
10727 compunit_language (cust
),
10729 list_in_scope
= get_builder ()->get_file_symbols ();
10734 line_header
= lh
.release ();
10735 line_header_die_owner
= die
;
10739 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10741 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10742 still initializing it, and our caller (a few levels up)
10743 process_full_type_unit still needs to know if this is the first
10746 tug_unshare
->symtabs
10747 = XOBNEWVEC (&cust
->objfile ()->objfile_obstack
,
10748 struct symtab
*, line_header
->file_names_size ());
10750 auto &file_names
= line_header
->file_names ();
10751 for (i
= 0; i
< file_names
.size (); ++i
)
10753 file_entry
&fe
= file_names
[i
];
10754 dwarf2_start_subfile (this, fe
.name
,
10755 fe
.include_dir (line_header
));
10756 buildsym_compunit
*b
= get_builder ();
10757 if (b
->get_current_subfile ()->symtab
== NULL
)
10759 /* NOTE: start_subfile will recognize when it's been
10760 passed a file it has already seen. So we can't
10761 assume there's a simple mapping from
10762 cu->line_header->file_names to subfiles, plus
10763 cu->line_header->file_names may contain dups. */
10764 b
->get_current_subfile ()->symtab
10765 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10768 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10769 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10774 gdb_assert (m_builder
== nullptr);
10775 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10776 m_builder
.reset (new struct buildsym_compunit
10777 (cust
->objfile (), "",
10779 compunit_language (cust
),
10781 list_in_scope
= get_builder ()->get_file_symbols ();
10783 auto &file_names
= line_header
->file_names ();
10784 for (i
= 0; i
< file_names
.size (); ++i
)
10786 file_entry
&fe
= file_names
[i
];
10787 fe
.symtab
= tug_unshare
->symtabs
[i
];
10791 /* The main symtab is allocated last. Type units don't have DW_AT_name
10792 so they don't have a "real" (so to speak) symtab anyway.
10793 There is later code that will assign the main symtab to all symbols
10794 that don't have one. We need to handle the case of a symbol with a
10795 missing symtab (DW_AT_decl_file) anyway. */
10798 /* Process DW_TAG_type_unit.
10799 For TUs we want to skip the first top level sibling if it's not the
10800 actual type being defined by this TU. In this case the first top
10801 level sibling is there to provide context only. */
10804 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10806 struct die_info
*child_die
;
10808 prepare_one_comp_unit (cu
, die
, language_minimal
);
10810 /* Initialize (or reinitialize) the machinery for building symtabs.
10811 We do this before processing child DIEs, so that the line header table
10812 is available for DW_AT_decl_file. */
10813 cu
->setup_type_unit_groups (die
);
10815 if (die
->child
!= NULL
)
10817 child_die
= die
->child
;
10818 while (child_die
&& child_die
->tag
)
10820 process_die (child_die
, cu
);
10821 child_die
= child_die
->sibling
;
10828 http://gcc.gnu.org/wiki/DebugFission
10829 http://gcc.gnu.org/wiki/DebugFissionDWP
10831 To simplify handling of both DWO files ("object" files with the DWARF info)
10832 and DWP files (a file with the DWOs packaged up into one file), we treat
10833 DWP files as having a collection of virtual DWO files. */
10836 hash_dwo_file (const void *item
)
10838 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10841 hash
= htab_hash_string (dwo_file
->dwo_name
);
10842 if (dwo_file
->comp_dir
!= NULL
)
10843 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10848 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10850 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10851 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10853 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10855 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10856 return lhs
->comp_dir
== rhs
->comp_dir
;
10857 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10860 /* Allocate a hash table for DWO files. */
10863 allocate_dwo_file_hash_table ()
10865 return htab_up (htab_create_alloc (41,
10868 htab_delete_entry
<dwo_file
>,
10872 /* Lookup DWO file DWO_NAME. */
10875 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10876 const char *dwo_name
,
10877 const char *comp_dir
)
10879 struct dwo_file find_entry
;
10882 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10883 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10885 find_entry
.dwo_name
= dwo_name
;
10886 find_entry
.comp_dir
= comp_dir
;
10887 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10894 hash_dwo_unit (const void *item
)
10896 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10898 /* This drops the top 32 bits of the id, but is ok for a hash. */
10899 return dwo_unit
->signature
;
10903 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10905 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10906 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10908 /* The signature is assumed to be unique within the DWO file.
10909 So while object file CU dwo_id's always have the value zero,
10910 that's OK, assuming each object file DWO file has only one CU,
10911 and that's the rule for now. */
10912 return lhs
->signature
== rhs
->signature
;
10915 /* Allocate a hash table for DWO CUs,TUs.
10916 There is one of these tables for each of CUs,TUs for each DWO file. */
10919 allocate_dwo_unit_table ()
10921 /* Start out with a pretty small number.
10922 Generally DWO files contain only one CU and maybe some TUs. */
10923 return htab_up (htab_create_alloc (3,
10926 NULL
, xcalloc
, xfree
));
10929 /* die_reader_func for create_dwo_cu. */
10932 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10933 const gdb_byte
*info_ptr
,
10934 struct die_info
*comp_unit_die
,
10935 struct dwo_file
*dwo_file
,
10936 struct dwo_unit
*dwo_unit
)
10938 struct dwarf2_cu
*cu
= reader
->cu
;
10939 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10940 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10942 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10943 if (!signature
.has_value ())
10945 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10946 " its dwo_id [in module %s]"),
10947 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10951 dwo_unit
->dwo_file
= dwo_file
;
10952 dwo_unit
->signature
= *signature
;
10953 dwo_unit
->section
= section
;
10954 dwo_unit
->sect_off
= sect_off
;
10955 dwo_unit
->length
= cu
->per_cu
->length
;
10957 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10958 sect_offset_str (sect_off
),
10959 hex_string (dwo_unit
->signature
));
10962 /* Create the dwo_units for the CUs in a DWO_FILE.
10963 Note: This function processes DWO files only, not DWP files. */
10966 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10967 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10968 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10970 struct objfile
*objfile
= per_objfile
->objfile
;
10971 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10972 const gdb_byte
*info_ptr
, *end_ptr
;
10974 section
.read (objfile
);
10975 info_ptr
= section
.buffer
;
10977 if (info_ptr
== NULL
)
10980 dwarf_read_debug_printf ("Reading %s for %s:",
10981 section
.get_name (),
10982 section
.get_file_name ());
10984 end_ptr
= info_ptr
+ section
.size
;
10985 while (info_ptr
< end_ptr
)
10987 struct dwarf2_per_cu_data per_cu
;
10988 struct dwo_unit read_unit
{};
10989 struct dwo_unit
*dwo_unit
;
10991 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10993 per_cu
.per_bfd
= per_bfd
;
10994 per_cu
.is_debug_types
= 0;
10995 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10996 per_cu
.section
= §ion
;
10998 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10999 if (!reader
.dummy_p
)
11000 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11001 &dwo_file
, &read_unit
);
11002 info_ptr
+= per_cu
.length
;
11004 // If the unit could not be parsed, skip it.
11005 if (read_unit
.dwo_file
== NULL
)
11008 if (cus_htab
== NULL
)
11009 cus_htab
= allocate_dwo_unit_table ();
11011 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11013 *dwo_unit
= read_unit
;
11014 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11015 gdb_assert (slot
!= NULL
);
11018 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11019 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11021 complaint (_("debug cu entry at offset %s is duplicate to"
11022 " the entry at offset %s, signature %s"),
11023 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11024 hex_string (dwo_unit
->signature
));
11026 *slot
= (void *)dwo_unit
;
11030 /* DWP file .debug_{cu,tu}_index section format:
11031 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11032 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11034 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11035 officially standard DWP format was published with DWARF v5 and is called
11036 Version 5. There are no versions 3 or 4.
11040 Both index sections have the same format, and serve to map a 64-bit
11041 signature to a set of section numbers. Each section begins with a header,
11042 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11043 indexes, and a pool of 32-bit section numbers. The index sections will be
11044 aligned at 8-byte boundaries in the file.
11046 The index section header consists of:
11048 V, 32 bit version number
11050 N, 32 bit number of compilation units or type units in the index
11051 M, 32 bit number of slots in the hash table
11053 Numbers are recorded using the byte order of the application binary.
11055 The hash table begins at offset 16 in the section, and consists of an array
11056 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11057 order of the application binary). Unused slots in the hash table are 0.
11058 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11060 The parallel table begins immediately after the hash table
11061 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11062 array of 32-bit indexes (using the byte order of the application binary),
11063 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11064 table contains a 32-bit index into the pool of section numbers. For unused
11065 hash table slots, the corresponding entry in the parallel table will be 0.
11067 The pool of section numbers begins immediately following the hash table
11068 (at offset 16 + 12 * M from the beginning of the section). The pool of
11069 section numbers consists of an array of 32-bit words (using the byte order
11070 of the application binary). Each item in the array is indexed starting
11071 from 0. The hash table entry provides the index of the first section
11072 number in the set. Additional section numbers in the set follow, and the
11073 set is terminated by a 0 entry (section number 0 is not used in ELF).
11075 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11076 section must be the first entry in the set, and the .debug_abbrev.dwo must
11077 be the second entry. Other members of the set may follow in any order.
11081 DWP Versions 2 and 5:
11083 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11084 and the entries in the index tables are now offsets into these sections.
11085 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11088 Index Section Contents:
11090 Hash Table of Signatures dwp_hash_table.hash_table
11091 Parallel Table of Indices dwp_hash_table.unit_table
11092 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11093 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11095 The index section header consists of:
11097 V, 32 bit version number
11098 L, 32 bit number of columns in the table of section offsets
11099 N, 32 bit number of compilation units or type units in the index
11100 M, 32 bit number of slots in the hash table
11102 Numbers are recorded using the byte order of the application binary.
11104 The hash table has the same format as version 1.
11105 The parallel table of indices has the same format as version 1,
11106 except that the entries are origin-1 indices into the table of sections
11107 offsets and the table of section sizes.
11109 The table of offsets begins immediately following the parallel table
11110 (at offset 16 + 12 * M from the beginning of the section). The table is
11111 a two-dimensional array of 32-bit words (using the byte order of the
11112 application binary), with L columns and N+1 rows, in row-major order.
11113 Each row in the array is indexed starting from 0. The first row provides
11114 a key to the remaining rows: each column in this row provides an identifier
11115 for a debug section, and the offsets in the same column of subsequent rows
11116 refer to that section. The section identifiers for Version 2 are:
11118 DW_SECT_INFO 1 .debug_info.dwo
11119 DW_SECT_TYPES 2 .debug_types.dwo
11120 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11121 DW_SECT_LINE 4 .debug_line.dwo
11122 DW_SECT_LOC 5 .debug_loc.dwo
11123 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11124 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11125 DW_SECT_MACRO 8 .debug_macro.dwo
11127 The section identifiers for Version 5 are:
11129 DW_SECT_INFO_V5 1 .debug_info.dwo
11130 DW_SECT_RESERVED_V5 2 --
11131 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11132 DW_SECT_LINE_V5 4 .debug_line.dwo
11133 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11134 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11135 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11136 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11138 The offsets provided by the CU and TU index sections are the base offsets
11139 for the contributions made by each CU or TU to the corresponding section
11140 in the package file. Each CU and TU header contains an abbrev_offset
11141 field, used to find the abbreviations table for that CU or TU within the
11142 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11143 be interpreted as relative to the base offset given in the index section.
11144 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11145 should be interpreted as relative to the base offset for .debug_line.dwo,
11146 and offsets into other debug sections obtained from DWARF attributes should
11147 also be interpreted as relative to the corresponding base offset.
11149 The table of sizes begins immediately following the table of offsets.
11150 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11151 with L columns and N rows, in row-major order. Each row in the array is
11152 indexed starting from 1 (row 0 is shared by the two tables).
11156 Hash table lookup is handled the same in version 1 and 2:
11158 We assume that N and M will not exceed 2^32 - 1.
11159 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11161 Given a 64-bit compilation unit signature or a type signature S, an entry
11162 in the hash table is located as follows:
11164 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11165 the low-order k bits all set to 1.
11167 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11169 3) If the hash table entry at index H matches the signature, use that
11170 entry. If the hash table entry at index H is unused (all zeroes),
11171 terminate the search: the signature is not present in the table.
11173 4) Let H = (H + H') modulo M. Repeat at Step 3.
11175 Because M > N and H' and M are relatively prime, the search is guaranteed
11176 to stop at an unused slot or find the match. */
11178 /* Create a hash table to map DWO IDs to their CU/TU entry in
11179 .debug_{info,types}.dwo in DWP_FILE.
11180 Returns NULL if there isn't one.
11181 Note: This function processes DWP files only, not DWO files. */
11183 static struct dwp_hash_table
*
11184 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11185 struct dwp_file
*dwp_file
, int is_debug_types
)
11187 struct objfile
*objfile
= per_objfile
->objfile
;
11188 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11189 const gdb_byte
*index_ptr
, *index_end
;
11190 struct dwarf2_section_info
*index
;
11191 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11192 struct dwp_hash_table
*htab
;
11194 if (is_debug_types
)
11195 index
= &dwp_file
->sections
.tu_index
;
11197 index
= &dwp_file
->sections
.cu_index
;
11199 if (index
->empty ())
11201 index
->read (objfile
);
11203 index_ptr
= index
->buffer
;
11204 index_end
= index_ptr
+ index
->size
;
11206 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11207 For now it's safe to just read 4 bytes (particularly as it's difficult to
11208 tell if you're dealing with Version 5 before you've read the version). */
11209 version
= read_4_bytes (dbfd
, index_ptr
);
11211 if (version
== 2 || version
== 5)
11212 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11216 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11218 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11221 if (version
!= 1 && version
!= 2 && version
!= 5)
11223 error (_("Dwarf Error: unsupported DWP file version (%s)"
11224 " [in module %s]"),
11225 pulongest (version
), dwp_file
->name
);
11227 if (nr_slots
!= (nr_slots
& -nr_slots
))
11229 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11230 " is not power of 2 [in module %s]"),
11231 pulongest (nr_slots
), dwp_file
->name
);
11234 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11235 htab
->version
= version
;
11236 htab
->nr_columns
= nr_columns
;
11237 htab
->nr_units
= nr_units
;
11238 htab
->nr_slots
= nr_slots
;
11239 htab
->hash_table
= index_ptr
;
11240 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11242 /* Exit early if the table is empty. */
11243 if (nr_slots
== 0 || nr_units
== 0
11244 || (version
== 2 && nr_columns
== 0)
11245 || (version
== 5 && nr_columns
== 0))
11247 /* All must be zero. */
11248 if (nr_slots
!= 0 || nr_units
!= 0
11249 || (version
== 2 && nr_columns
!= 0)
11250 || (version
== 5 && nr_columns
!= 0))
11252 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11253 " all zero [in modules %s]"),
11261 htab
->section_pool
.v1
.indices
=
11262 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11263 /* It's harder to decide whether the section is too small in v1.
11264 V1 is deprecated anyway so we punt. */
11266 else if (version
== 2)
11268 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11269 int *ids
= htab
->section_pool
.v2
.section_ids
;
11270 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11271 /* Reverse map for error checking. */
11272 int ids_seen
[DW_SECT_MAX
+ 1];
11275 if (nr_columns
< 2)
11277 error (_("Dwarf Error: bad DWP hash table, too few columns"
11278 " in section table [in module %s]"),
11281 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11283 error (_("Dwarf Error: bad DWP hash table, too many columns"
11284 " in section table [in module %s]"),
11287 memset (ids
, 255, sizeof_ids
);
11288 memset (ids_seen
, 255, sizeof (ids_seen
));
11289 for (i
= 0; i
< nr_columns
; ++i
)
11291 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11293 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11295 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11296 " in section table [in module %s]"),
11297 id
, dwp_file
->name
);
11299 if (ids_seen
[id
] != -1)
11301 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11302 " id %d in section table [in module %s]"),
11303 id
, dwp_file
->name
);
11308 /* Must have exactly one info or types section. */
11309 if (((ids_seen
[DW_SECT_INFO
] != -1)
11310 + (ids_seen
[DW_SECT_TYPES
] != -1))
11313 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11314 " DWO info/types section [in module %s]"),
11317 /* Must have an abbrev section. */
11318 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11320 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11321 " section [in module %s]"),
11324 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11325 htab
->section_pool
.v2
.sizes
=
11326 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11327 * nr_units
* nr_columns
);
11328 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11329 * nr_units
* nr_columns
))
11332 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11333 " [in module %s]"),
11337 else /* version == 5 */
11339 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11340 int *ids
= htab
->section_pool
.v5
.section_ids
;
11341 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11342 /* Reverse map for error checking. */
11343 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11345 if (nr_columns
< 2)
11347 error (_("Dwarf Error: bad DWP hash table, too few columns"
11348 " in section table [in module %s]"),
11351 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11353 error (_("Dwarf Error: bad DWP hash table, too many columns"
11354 " in section table [in module %s]"),
11357 memset (ids
, 255, sizeof_ids
);
11358 memset (ids_seen
, 255, sizeof (ids_seen
));
11359 for (int i
= 0; i
< nr_columns
; ++i
)
11361 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11363 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11365 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11366 " in section table [in module %s]"),
11367 id
, dwp_file
->name
);
11369 if (ids_seen
[id
] != -1)
11371 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11372 " id %d in section table [in module %s]"),
11373 id
, dwp_file
->name
);
11378 /* Must have seen an info section. */
11379 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11381 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11382 " DWO info/types section [in module %s]"),
11385 /* Must have an abbrev section. */
11386 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11388 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11389 " section [in module %s]"),
11392 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11393 htab
->section_pool
.v5
.sizes
11394 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11395 * nr_units
* nr_columns
);
11396 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11397 * nr_units
* nr_columns
))
11400 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11401 " [in module %s]"),
11409 /* Update SECTIONS with the data from SECTP.
11411 This function is like the other "locate" section routines, but in
11412 this context the sections to read comes from the DWP V1 hash table,
11413 not the full ELF section table.
11415 The result is non-zero for success, or zero if an error was found. */
11418 locate_v1_virtual_dwo_sections (asection
*sectp
,
11419 struct virtual_v1_dwo_sections
*sections
)
11421 const struct dwop_section_names
*names
= &dwop_section_names
;
11423 if (names
->abbrev_dwo
.matches (sectp
->name
))
11425 /* There can be only one. */
11426 if (sections
->abbrev
.s
.section
!= NULL
)
11428 sections
->abbrev
.s
.section
= sectp
;
11429 sections
->abbrev
.size
= bfd_section_size (sectp
);
11431 else if (names
->info_dwo
.matches (sectp
->name
)
11432 || names
->types_dwo
.matches (sectp
->name
))
11434 /* There can be only one. */
11435 if (sections
->info_or_types
.s
.section
!= NULL
)
11437 sections
->info_or_types
.s
.section
= sectp
;
11438 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11440 else if (names
->line_dwo
.matches (sectp
->name
))
11442 /* There can be only one. */
11443 if (sections
->line
.s
.section
!= NULL
)
11445 sections
->line
.s
.section
= sectp
;
11446 sections
->line
.size
= bfd_section_size (sectp
);
11448 else if (names
->loc_dwo
.matches (sectp
->name
))
11450 /* There can be only one. */
11451 if (sections
->loc
.s
.section
!= NULL
)
11453 sections
->loc
.s
.section
= sectp
;
11454 sections
->loc
.size
= bfd_section_size (sectp
);
11456 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11458 /* There can be only one. */
11459 if (sections
->macinfo
.s
.section
!= NULL
)
11461 sections
->macinfo
.s
.section
= sectp
;
11462 sections
->macinfo
.size
= bfd_section_size (sectp
);
11464 else if (names
->macro_dwo
.matches (sectp
->name
))
11466 /* There can be only one. */
11467 if (sections
->macro
.s
.section
!= NULL
)
11469 sections
->macro
.s
.section
= sectp
;
11470 sections
->macro
.size
= bfd_section_size (sectp
);
11472 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11474 /* There can be only one. */
11475 if (sections
->str_offsets
.s
.section
!= NULL
)
11477 sections
->str_offsets
.s
.section
= sectp
;
11478 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11482 /* No other kind of section is valid. */
11489 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11490 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11491 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11492 This is for DWP version 1 files. */
11494 static struct dwo_unit
*
11495 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11496 struct dwp_file
*dwp_file
,
11497 uint32_t unit_index
,
11498 const char *comp_dir
,
11499 ULONGEST signature
, int is_debug_types
)
11501 const struct dwp_hash_table
*dwp_htab
=
11502 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11503 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11504 const char *kind
= is_debug_types
? "TU" : "CU";
11505 struct dwo_file
*dwo_file
;
11506 struct dwo_unit
*dwo_unit
;
11507 struct virtual_v1_dwo_sections sections
;
11508 void **dwo_file_slot
;
11511 gdb_assert (dwp_file
->version
== 1);
11513 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11514 kind
, pulongest (unit_index
), hex_string (signature
),
11517 /* Fetch the sections of this DWO unit.
11518 Put a limit on the number of sections we look for so that bad data
11519 doesn't cause us to loop forever. */
11521 #define MAX_NR_V1_DWO_SECTIONS \
11522 (1 /* .debug_info or .debug_types */ \
11523 + 1 /* .debug_abbrev */ \
11524 + 1 /* .debug_line */ \
11525 + 1 /* .debug_loc */ \
11526 + 1 /* .debug_str_offsets */ \
11527 + 1 /* .debug_macro or .debug_macinfo */ \
11528 + 1 /* trailing zero */)
11530 memset (§ions
, 0, sizeof (sections
));
11532 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11535 uint32_t section_nr
=
11536 read_4_bytes (dbfd
,
11537 dwp_htab
->section_pool
.v1
.indices
11538 + (unit_index
+ i
) * sizeof (uint32_t));
11540 if (section_nr
== 0)
11542 if (section_nr
>= dwp_file
->num_sections
)
11544 error (_("Dwarf Error: bad DWP hash table, section number too large"
11545 " [in module %s]"),
11549 sectp
= dwp_file
->elf_sections
[section_nr
];
11550 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11552 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11553 " [in module %s]"),
11559 || sections
.info_or_types
.empty ()
11560 || sections
.abbrev
.empty ())
11562 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11563 " [in module %s]"),
11566 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11568 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11569 " [in module %s]"),
11573 /* It's easier for the rest of the code if we fake a struct dwo_file and
11574 have dwo_unit "live" in that. At least for now.
11576 The DWP file can be made up of a random collection of CUs and TUs.
11577 However, for each CU + set of TUs that came from the same original DWO
11578 file, we can combine them back into a virtual DWO file to save space
11579 (fewer struct dwo_file objects to allocate). Remember that for really
11580 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11582 std::string virtual_dwo_name
=
11583 string_printf ("virtual-dwo/%d-%d-%d-%d",
11584 sections
.abbrev
.get_id (),
11585 sections
.line
.get_id (),
11586 sections
.loc
.get_id (),
11587 sections
.str_offsets
.get_id ());
11588 /* Can we use an existing virtual DWO file? */
11589 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11591 /* Create one if necessary. */
11592 if (*dwo_file_slot
== NULL
)
11594 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11595 virtual_dwo_name
.c_str ());
11597 dwo_file
= new struct dwo_file
;
11598 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11599 dwo_file
->comp_dir
= comp_dir
;
11600 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11601 dwo_file
->sections
.line
= sections
.line
;
11602 dwo_file
->sections
.loc
= sections
.loc
;
11603 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11604 dwo_file
->sections
.macro
= sections
.macro
;
11605 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11606 /* The "str" section is global to the entire DWP file. */
11607 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11608 /* The info or types section is assigned below to dwo_unit,
11609 there's no need to record it in dwo_file.
11610 Also, we can't simply record type sections in dwo_file because
11611 we record a pointer into the vector in dwo_unit. As we collect more
11612 types we'll grow the vector and eventually have to reallocate space
11613 for it, invalidating all copies of pointers into the previous
11615 *dwo_file_slot
= dwo_file
;
11619 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11620 virtual_dwo_name
.c_str ());
11622 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11625 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11626 dwo_unit
->dwo_file
= dwo_file
;
11627 dwo_unit
->signature
= signature
;
11628 dwo_unit
->section
=
11629 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11630 *dwo_unit
->section
= sections
.info_or_types
;
11631 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11636 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11637 simplify them. Given a pointer to the containing section SECTION, and
11638 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11639 virtual section of just that piece. */
11641 static struct dwarf2_section_info
11642 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11643 struct dwarf2_section_info
*section
,
11644 bfd_size_type offset
, bfd_size_type size
)
11646 struct dwarf2_section_info result
;
11649 gdb_assert (section
!= NULL
);
11650 gdb_assert (!section
->is_virtual
);
11652 memset (&result
, 0, sizeof (result
));
11653 result
.s
.containing_section
= section
;
11654 result
.is_virtual
= true;
11659 sectp
= section
->get_bfd_section ();
11661 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11662 bounds of the real section. This is a pretty-rare event, so just
11663 flag an error (easier) instead of a warning and trying to cope. */
11665 || offset
+ size
> bfd_section_size (sectp
))
11667 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11668 " in section %s [in module %s]"),
11669 sectp
? bfd_section_name (sectp
) : "<unknown>",
11670 objfile_name (per_objfile
->objfile
));
11673 result
.virtual_offset
= offset
;
11674 result
.size
= size
;
11678 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11679 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11680 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11681 This is for DWP version 2 files. */
11683 static struct dwo_unit
*
11684 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11685 struct dwp_file
*dwp_file
,
11686 uint32_t unit_index
,
11687 const char *comp_dir
,
11688 ULONGEST signature
, int is_debug_types
)
11690 const struct dwp_hash_table
*dwp_htab
=
11691 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11692 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11693 const char *kind
= is_debug_types
? "TU" : "CU";
11694 struct dwo_file
*dwo_file
;
11695 struct dwo_unit
*dwo_unit
;
11696 struct virtual_v2_or_v5_dwo_sections sections
;
11697 void **dwo_file_slot
;
11700 gdb_assert (dwp_file
->version
== 2);
11702 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11703 kind
, pulongest (unit_index
), hex_string (signature
),
11706 /* Fetch the section offsets of this DWO unit. */
11708 memset (§ions
, 0, sizeof (sections
));
11710 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11712 uint32_t offset
= read_4_bytes (dbfd
,
11713 dwp_htab
->section_pool
.v2
.offsets
11714 + (((unit_index
- 1) * dwp_htab
->nr_columns
11716 * sizeof (uint32_t)));
11717 uint32_t size
= read_4_bytes (dbfd
,
11718 dwp_htab
->section_pool
.v2
.sizes
11719 + (((unit_index
- 1) * dwp_htab
->nr_columns
11721 * sizeof (uint32_t)));
11723 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11726 case DW_SECT_TYPES
:
11727 sections
.info_or_types_offset
= offset
;
11728 sections
.info_or_types_size
= size
;
11730 case DW_SECT_ABBREV
:
11731 sections
.abbrev_offset
= offset
;
11732 sections
.abbrev_size
= size
;
11735 sections
.line_offset
= offset
;
11736 sections
.line_size
= size
;
11739 sections
.loc_offset
= offset
;
11740 sections
.loc_size
= size
;
11742 case DW_SECT_STR_OFFSETS
:
11743 sections
.str_offsets_offset
= offset
;
11744 sections
.str_offsets_size
= size
;
11746 case DW_SECT_MACINFO
:
11747 sections
.macinfo_offset
= offset
;
11748 sections
.macinfo_size
= size
;
11750 case DW_SECT_MACRO
:
11751 sections
.macro_offset
= offset
;
11752 sections
.macro_size
= size
;
11757 /* It's easier for the rest of the code if we fake a struct dwo_file and
11758 have dwo_unit "live" in that. At least for now.
11760 The DWP file can be made up of a random collection of CUs and TUs.
11761 However, for each CU + set of TUs that came from the same original DWO
11762 file, we can combine them back into a virtual DWO file to save space
11763 (fewer struct dwo_file objects to allocate). Remember that for really
11764 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11766 std::string virtual_dwo_name
=
11767 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11768 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11769 (long) (sections
.line_size
? sections
.line_offset
: 0),
11770 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11771 (long) (sections
.str_offsets_size
11772 ? sections
.str_offsets_offset
: 0));
11773 /* Can we use an existing virtual DWO file? */
11774 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11776 /* Create one if necessary. */
11777 if (*dwo_file_slot
== NULL
)
11779 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11780 virtual_dwo_name
.c_str ());
11782 dwo_file
= new struct dwo_file
;
11783 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11784 dwo_file
->comp_dir
= comp_dir
;
11785 dwo_file
->sections
.abbrev
=
11786 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11787 sections
.abbrev_offset
,
11788 sections
.abbrev_size
);
11789 dwo_file
->sections
.line
=
11790 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11791 sections
.line_offset
,
11792 sections
.line_size
);
11793 dwo_file
->sections
.loc
=
11794 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11795 sections
.loc_offset
, sections
.loc_size
);
11796 dwo_file
->sections
.macinfo
=
11797 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11798 sections
.macinfo_offset
,
11799 sections
.macinfo_size
);
11800 dwo_file
->sections
.macro
=
11801 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11802 sections
.macro_offset
,
11803 sections
.macro_size
);
11804 dwo_file
->sections
.str_offsets
=
11805 create_dwp_v2_or_v5_section (per_objfile
,
11806 &dwp_file
->sections
.str_offsets
,
11807 sections
.str_offsets_offset
,
11808 sections
.str_offsets_size
);
11809 /* The "str" section is global to the entire DWP file. */
11810 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11811 /* The info or types section is assigned below to dwo_unit,
11812 there's no need to record it in dwo_file.
11813 Also, we can't simply record type sections in dwo_file because
11814 we record a pointer into the vector in dwo_unit. As we collect more
11815 types we'll grow the vector and eventually have to reallocate space
11816 for it, invalidating all copies of pointers into the previous
11818 *dwo_file_slot
= dwo_file
;
11822 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11823 virtual_dwo_name
.c_str ());
11825 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11828 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11829 dwo_unit
->dwo_file
= dwo_file
;
11830 dwo_unit
->signature
= signature
;
11831 dwo_unit
->section
=
11832 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11833 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11836 ? &dwp_file
->sections
.types
11837 : &dwp_file
->sections
.info
,
11838 sections
.info_or_types_offset
,
11839 sections
.info_or_types_size
);
11840 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11845 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11846 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11847 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11848 This is for DWP version 5 files. */
11850 static struct dwo_unit
*
11851 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11852 struct dwp_file
*dwp_file
,
11853 uint32_t unit_index
,
11854 const char *comp_dir
,
11855 ULONGEST signature
, int is_debug_types
)
11857 const struct dwp_hash_table
*dwp_htab
11858 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11859 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11860 const char *kind
= is_debug_types
? "TU" : "CU";
11861 struct dwo_file
*dwo_file
;
11862 struct dwo_unit
*dwo_unit
;
11863 struct virtual_v2_or_v5_dwo_sections sections
{};
11864 void **dwo_file_slot
;
11866 gdb_assert (dwp_file
->version
== 5);
11868 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11869 kind
, pulongest (unit_index
), hex_string (signature
),
11872 /* Fetch the section offsets of this DWO unit. */
11874 /* memset (§ions, 0, sizeof (sections)); */
11876 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11878 uint32_t offset
= read_4_bytes (dbfd
,
11879 dwp_htab
->section_pool
.v5
.offsets
11880 + (((unit_index
- 1)
11881 * dwp_htab
->nr_columns
11883 * sizeof (uint32_t)));
11884 uint32_t size
= read_4_bytes (dbfd
,
11885 dwp_htab
->section_pool
.v5
.sizes
11886 + (((unit_index
- 1) * dwp_htab
->nr_columns
11888 * sizeof (uint32_t)));
11890 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11892 case DW_SECT_ABBREV_V5
:
11893 sections
.abbrev_offset
= offset
;
11894 sections
.abbrev_size
= size
;
11896 case DW_SECT_INFO_V5
:
11897 sections
.info_or_types_offset
= offset
;
11898 sections
.info_or_types_size
= size
;
11900 case DW_SECT_LINE_V5
:
11901 sections
.line_offset
= offset
;
11902 sections
.line_size
= size
;
11904 case DW_SECT_LOCLISTS_V5
:
11905 sections
.loclists_offset
= offset
;
11906 sections
.loclists_size
= size
;
11908 case DW_SECT_MACRO_V5
:
11909 sections
.macro_offset
= offset
;
11910 sections
.macro_size
= size
;
11912 case DW_SECT_RNGLISTS_V5
:
11913 sections
.rnglists_offset
= offset
;
11914 sections
.rnglists_size
= size
;
11916 case DW_SECT_STR_OFFSETS_V5
:
11917 sections
.str_offsets_offset
= offset
;
11918 sections
.str_offsets_size
= size
;
11920 case DW_SECT_RESERVED_V5
:
11926 /* It's easier for the rest of the code if we fake a struct dwo_file and
11927 have dwo_unit "live" in that. At least for now.
11929 The DWP file can be made up of a random collection of CUs and TUs.
11930 However, for each CU + set of TUs that came from the same original DWO
11931 file, we can combine them back into a virtual DWO file to save space
11932 (fewer struct dwo_file objects to allocate). Remember that for really
11933 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11935 std::string virtual_dwo_name
=
11936 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11937 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11938 (long) (sections
.line_size
? sections
.line_offset
: 0),
11939 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11940 (long) (sections
.str_offsets_size
11941 ? sections
.str_offsets_offset
: 0),
11942 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11943 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11944 /* Can we use an existing virtual DWO file? */
11945 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11946 virtual_dwo_name
.c_str (),
11948 /* Create one if necessary. */
11949 if (*dwo_file_slot
== NULL
)
11951 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11952 virtual_dwo_name
.c_str ());
11954 dwo_file
= new struct dwo_file
;
11955 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11956 dwo_file
->comp_dir
= comp_dir
;
11957 dwo_file
->sections
.abbrev
=
11958 create_dwp_v2_or_v5_section (per_objfile
,
11959 &dwp_file
->sections
.abbrev
,
11960 sections
.abbrev_offset
,
11961 sections
.abbrev_size
);
11962 dwo_file
->sections
.line
=
11963 create_dwp_v2_or_v5_section (per_objfile
,
11964 &dwp_file
->sections
.line
,
11965 sections
.line_offset
, sections
.line_size
);
11966 dwo_file
->sections
.macro
=
11967 create_dwp_v2_or_v5_section (per_objfile
,
11968 &dwp_file
->sections
.macro
,
11969 sections
.macro_offset
,
11970 sections
.macro_size
);
11971 dwo_file
->sections
.loclists
=
11972 create_dwp_v2_or_v5_section (per_objfile
,
11973 &dwp_file
->sections
.loclists
,
11974 sections
.loclists_offset
,
11975 sections
.loclists_size
);
11976 dwo_file
->sections
.rnglists
=
11977 create_dwp_v2_or_v5_section (per_objfile
,
11978 &dwp_file
->sections
.rnglists
,
11979 sections
.rnglists_offset
,
11980 sections
.rnglists_size
);
11981 dwo_file
->sections
.str_offsets
=
11982 create_dwp_v2_or_v5_section (per_objfile
,
11983 &dwp_file
->sections
.str_offsets
,
11984 sections
.str_offsets_offset
,
11985 sections
.str_offsets_size
);
11986 /* The "str" section is global to the entire DWP file. */
11987 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11988 /* The info or types section is assigned below to dwo_unit,
11989 there's no need to record it in dwo_file.
11990 Also, we can't simply record type sections in dwo_file because
11991 we record a pointer into the vector in dwo_unit. As we collect more
11992 types we'll grow the vector and eventually have to reallocate space
11993 for it, invalidating all copies of pointers into the previous
11995 *dwo_file_slot
= dwo_file
;
11999 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12000 virtual_dwo_name
.c_str ());
12002 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12005 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12006 dwo_unit
->dwo_file
= dwo_file
;
12007 dwo_unit
->signature
= signature
;
12009 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12010 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12011 &dwp_file
->sections
.info
,
12012 sections
.info_or_types_offset
,
12013 sections
.info_or_types_size
);
12014 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12019 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12020 Returns NULL if the signature isn't found. */
12022 static struct dwo_unit
*
12023 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12024 struct dwp_file
*dwp_file
, const char *comp_dir
,
12025 ULONGEST signature
, int is_debug_types
)
12027 const struct dwp_hash_table
*dwp_htab
=
12028 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12029 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12030 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12031 uint32_t hash
= signature
& mask
;
12032 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12035 struct dwo_unit find_dwo_cu
;
12037 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12038 find_dwo_cu
.signature
= signature
;
12039 slot
= htab_find_slot (is_debug_types
12040 ? dwp_file
->loaded_tus
.get ()
12041 : dwp_file
->loaded_cus
.get (),
12042 &find_dwo_cu
, INSERT
);
12045 return (struct dwo_unit
*) *slot
;
12047 /* Use a for loop so that we don't loop forever on bad debug info. */
12048 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12050 ULONGEST signature_in_table
;
12052 signature_in_table
=
12053 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12054 if (signature_in_table
== signature
)
12056 uint32_t unit_index
=
12057 read_4_bytes (dbfd
,
12058 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12060 if (dwp_file
->version
== 1)
12062 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12063 unit_index
, comp_dir
,
12064 signature
, is_debug_types
);
12066 else if (dwp_file
->version
== 2)
12068 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12069 unit_index
, comp_dir
,
12070 signature
, is_debug_types
);
12072 else /* version == 5 */
12074 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12075 unit_index
, comp_dir
,
12076 signature
, is_debug_types
);
12078 return (struct dwo_unit
*) *slot
;
12080 if (signature_in_table
== 0)
12082 hash
= (hash
+ hash2
) & mask
;
12085 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12086 " [in module %s]"),
12090 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12091 Open the file specified by FILE_NAME and hand it off to BFD for
12092 preliminary analysis. Return a newly initialized bfd *, which
12093 includes a canonicalized copy of FILE_NAME.
12094 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12095 SEARCH_CWD is true if the current directory is to be searched.
12096 It will be searched before debug-file-directory.
12097 If successful, the file is added to the bfd include table of the
12098 objfile's bfd (see gdb_bfd_record_inclusion).
12099 If unable to find/open the file, return NULL.
12100 NOTE: This function is derived from symfile_bfd_open. */
12102 static gdb_bfd_ref_ptr
12103 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12104 const char *file_name
, int is_dwp
, int search_cwd
)
12107 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12108 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12109 to debug_file_directory. */
12110 const char *search_path
;
12111 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12113 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12116 if (!debug_file_directory
.empty ())
12118 search_path_holder
.reset (concat (".", dirname_separator_string
,
12119 debug_file_directory
.c_str (),
12121 search_path
= search_path_holder
.get ();
12127 search_path
= debug_file_directory
.c_str ();
12129 /* Add the path for the executable binary to the list of search paths. */
12130 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12131 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12132 dirname_separator_string
,
12133 search_path
, nullptr));
12134 search_path
= search_path_holder
.get ();
12136 openp_flags flags
= OPF_RETURN_REALPATH
;
12138 flags
|= OPF_SEARCH_IN_PATH
;
12140 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12141 desc
= openp (search_path
, flags
, file_name
,
12142 O_RDONLY
| O_BINARY
, &absolute_name
);
12146 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12148 if (sym_bfd
== NULL
)
12150 bfd_set_cacheable (sym_bfd
.get (), 1);
12152 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12155 /* Success. Record the bfd as having been included by the objfile's bfd.
12156 This is important because things like demangled_names_hash lives in the
12157 objfile's per_bfd space and may have references to things like symbol
12158 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12159 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12164 /* Try to open DWO file FILE_NAME.
12165 COMP_DIR is the DW_AT_comp_dir attribute.
12166 The result is the bfd handle of the file.
12167 If there is a problem finding or opening the file, return NULL.
12168 Upon success, the canonicalized path of the file is stored in the bfd,
12169 same as symfile_bfd_open. */
12171 static gdb_bfd_ref_ptr
12172 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12173 const char *file_name
, const char *comp_dir
)
12175 if (IS_ABSOLUTE_PATH (file_name
))
12176 return try_open_dwop_file (per_objfile
, file_name
,
12177 0 /*is_dwp*/, 0 /*search_cwd*/);
12179 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12181 if (comp_dir
!= NULL
)
12183 gdb::unique_xmalloc_ptr
<char> path_to_try
12184 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12186 /* NOTE: If comp_dir is a relative path, this will also try the
12187 search path, which seems useful. */
12188 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12190 1 /*search_cwd*/));
12195 /* That didn't work, try debug-file-directory, which, despite its name,
12196 is a list of paths. */
12198 if (debug_file_directory
.empty ())
12201 return try_open_dwop_file (per_objfile
, file_name
,
12202 0 /*is_dwp*/, 1 /*search_cwd*/);
12205 /* This function is mapped across the sections and remembers the offset and
12206 size of each of the DWO debugging sections we are interested in. */
12209 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12210 dwo_sections
*dwo_sections
)
12212 const struct dwop_section_names
*names
= &dwop_section_names
;
12214 if (names
->abbrev_dwo
.matches (sectp
->name
))
12216 dwo_sections
->abbrev
.s
.section
= sectp
;
12217 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12219 else if (names
->info_dwo
.matches (sectp
->name
))
12221 dwo_sections
->info
.s
.section
= sectp
;
12222 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12224 else if (names
->line_dwo
.matches (sectp
->name
))
12226 dwo_sections
->line
.s
.section
= sectp
;
12227 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12229 else if (names
->loc_dwo
.matches (sectp
->name
))
12231 dwo_sections
->loc
.s
.section
= sectp
;
12232 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12234 else if (names
->loclists_dwo
.matches (sectp
->name
))
12236 dwo_sections
->loclists
.s
.section
= sectp
;
12237 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12239 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12241 dwo_sections
->macinfo
.s
.section
= sectp
;
12242 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12244 else if (names
->macro_dwo
.matches (sectp
->name
))
12246 dwo_sections
->macro
.s
.section
= sectp
;
12247 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12249 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12251 dwo_sections
->rnglists
.s
.section
= sectp
;
12252 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12254 else if (names
->str_dwo
.matches (sectp
->name
))
12256 dwo_sections
->str
.s
.section
= sectp
;
12257 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12259 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12261 dwo_sections
->str_offsets
.s
.section
= sectp
;
12262 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12264 else if (names
->types_dwo
.matches (sectp
->name
))
12266 struct dwarf2_section_info type_section
;
12268 memset (&type_section
, 0, sizeof (type_section
));
12269 type_section
.s
.section
= sectp
;
12270 type_section
.size
= bfd_section_size (sectp
);
12271 dwo_sections
->types
.push_back (type_section
);
12275 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12276 by PER_CU. This is for the non-DWP case.
12277 The result is NULL if DWO_NAME can't be found. */
12279 static struct dwo_file
*
12280 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12281 const char *comp_dir
)
12283 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12285 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12288 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12293 dwo_file_up
dwo_file (new struct dwo_file
);
12294 dwo_file
->dwo_name
= dwo_name
;
12295 dwo_file
->comp_dir
= comp_dir
;
12296 dwo_file
->dbfd
= std::move (dbfd
);
12298 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12299 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12300 &dwo_file
->sections
);
12302 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12305 if (cu
->per_cu
->dwarf_version
< 5)
12307 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12308 dwo_file
->sections
.types
, dwo_file
->tus
);
12312 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12313 &dwo_file
->sections
.info
, dwo_file
->tus
,
12314 rcuh_kind::COMPILE
);
12317 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12319 return dwo_file
.release ();
12322 /* This function is mapped across the sections and remembers the offset and
12323 size of each of the DWP debugging sections common to version 1 and 2 that
12324 we are interested in. */
12327 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12328 dwp_file
*dwp_file
)
12330 const struct dwop_section_names
*names
= &dwop_section_names
;
12331 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12333 /* Record the ELF section number for later lookup: this is what the
12334 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12335 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12336 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12338 /* Look for specific sections that we need. */
12339 if (names
->str_dwo
.matches (sectp
->name
))
12341 dwp_file
->sections
.str
.s
.section
= sectp
;
12342 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12344 else if (names
->cu_index
.matches (sectp
->name
))
12346 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12347 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12349 else if (names
->tu_index
.matches (sectp
->name
))
12351 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12352 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12356 /* This function is mapped across the sections and remembers the offset and
12357 size of each of the DWP version 2 debugging sections that we are interested
12358 in. This is split into a separate function because we don't know if we
12359 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12362 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12364 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12365 const struct dwop_section_names
*names
= &dwop_section_names
;
12366 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12368 /* Record the ELF section number for later lookup: this is what the
12369 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12370 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12371 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12373 /* Look for specific sections that we need. */
12374 if (names
->abbrev_dwo
.matches (sectp
->name
))
12376 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12377 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12379 else if (names
->info_dwo
.matches (sectp
->name
))
12381 dwp_file
->sections
.info
.s
.section
= sectp
;
12382 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12384 else if (names
->line_dwo
.matches (sectp
->name
))
12386 dwp_file
->sections
.line
.s
.section
= sectp
;
12387 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12389 else if (names
->loc_dwo
.matches (sectp
->name
))
12391 dwp_file
->sections
.loc
.s
.section
= sectp
;
12392 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12394 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12396 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12397 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12399 else if (names
->macro_dwo
.matches (sectp
->name
))
12401 dwp_file
->sections
.macro
.s
.section
= sectp
;
12402 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12404 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12406 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12407 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12409 else if (names
->types_dwo
.matches (sectp
->name
))
12411 dwp_file
->sections
.types
.s
.section
= sectp
;
12412 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12416 /* This function is mapped across the sections and remembers the offset and
12417 size of each of the DWP version 5 debugging sections that we are interested
12418 in. This is split into a separate function because we don't know if we
12419 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12422 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12424 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12425 const struct dwop_section_names
*names
= &dwop_section_names
;
12426 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12428 /* Record the ELF section number for later lookup: this is what the
12429 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12430 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12431 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12433 /* Look for specific sections that we need. */
12434 if (names
->abbrev_dwo
.matches (sectp
->name
))
12436 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12437 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12439 else if (names
->info_dwo
.matches (sectp
->name
))
12441 dwp_file
->sections
.info
.s
.section
= sectp
;
12442 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12444 else if (names
->line_dwo
.matches (sectp
->name
))
12446 dwp_file
->sections
.line
.s
.section
= sectp
;
12447 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12449 else if (names
->loclists_dwo
.matches (sectp
->name
))
12451 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12452 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12454 else if (names
->macro_dwo
.matches (sectp
->name
))
12456 dwp_file
->sections
.macro
.s
.section
= sectp
;
12457 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12459 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12461 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12462 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12464 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12466 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12467 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12471 /* Hash function for dwp_file loaded CUs/TUs. */
12474 hash_dwp_loaded_cutus (const void *item
)
12476 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12478 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12479 return dwo_unit
->signature
;
12482 /* Equality function for dwp_file loaded CUs/TUs. */
12485 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12487 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12488 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12490 return dua
->signature
== dub
->signature
;
12493 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12496 allocate_dwp_loaded_cutus_table ()
12498 return htab_up (htab_create_alloc (3,
12499 hash_dwp_loaded_cutus
,
12500 eq_dwp_loaded_cutus
,
12501 NULL
, xcalloc
, xfree
));
12504 /* Try to open DWP file FILE_NAME.
12505 The result is the bfd handle of the file.
12506 If there is a problem finding or opening the file, return NULL.
12507 Upon success, the canonicalized path of the file is stored in the bfd,
12508 same as symfile_bfd_open. */
12510 static gdb_bfd_ref_ptr
12511 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12513 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12515 1 /*search_cwd*/));
12519 /* Work around upstream bug 15652.
12520 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12521 [Whether that's a "bug" is debatable, but it is getting in our way.]
12522 We have no real idea where the dwp file is, because gdb's realpath-ing
12523 of the executable's path may have discarded the needed info.
12524 [IWBN if the dwp file name was recorded in the executable, akin to
12525 .gnu_debuglink, but that doesn't exist yet.]
12526 Strip the directory from FILE_NAME and search again. */
12527 if (!debug_file_directory
.empty ())
12529 /* Don't implicitly search the current directory here.
12530 If the user wants to search "." to handle this case,
12531 it must be added to debug-file-directory. */
12532 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12540 /* Initialize the use of the DWP file for the current objfile.
12541 By convention the name of the DWP file is ${objfile}.dwp.
12542 The result is NULL if it can't be found. */
12544 static std::unique_ptr
<struct dwp_file
>
12545 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12547 struct objfile
*objfile
= per_objfile
->objfile
;
12549 /* Try to find first .dwp for the binary file before any symbolic links
12552 /* If the objfile is a debug file, find the name of the real binary
12553 file and get the name of dwp file from there. */
12554 std::string dwp_name
;
12555 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12557 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12558 const char *backlink_basename
= lbasename (backlink
->original_name
);
12560 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12563 dwp_name
= objfile
->original_name
;
12565 dwp_name
+= ".dwp";
12567 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12569 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12571 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12572 dwp_name
= objfile_name (objfile
);
12573 dwp_name
+= ".dwp";
12574 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12579 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12581 return std::unique_ptr
<dwp_file
> ();
12584 const char *name
= bfd_get_filename (dbfd
.get ());
12585 std::unique_ptr
<struct dwp_file
> dwp_file
12586 (new struct dwp_file (name
, std::move (dbfd
)));
12588 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12589 dwp_file
->elf_sections
=
12590 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12591 dwp_file
->num_sections
, asection
*);
12593 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12594 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12597 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12599 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12601 /* The DWP file version is stored in the hash table. Oh well. */
12602 if (dwp_file
->cus
&& dwp_file
->tus
12603 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12605 /* Technically speaking, we should try to limp along, but this is
12606 pretty bizarre. We use pulongest here because that's the established
12607 portability solution (e.g, we cannot use %u for uint32_t). */
12608 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12609 " TU version %s [in DWP file %s]"),
12610 pulongest (dwp_file
->cus
->version
),
12611 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12615 dwp_file
->version
= dwp_file
->cus
->version
;
12616 else if (dwp_file
->tus
)
12617 dwp_file
->version
= dwp_file
->tus
->version
;
12619 dwp_file
->version
= 2;
12621 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12623 if (dwp_file
->version
== 2)
12624 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12627 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12631 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12632 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12634 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12635 dwarf_read_debug_printf (" %s CUs, %s TUs",
12636 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12637 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12642 /* Wrapper around open_and_init_dwp_file, only open it once. */
12644 static struct dwp_file
*
12645 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12647 if (!per_objfile
->per_bfd
->dwp_checked
)
12649 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12650 per_objfile
->per_bfd
->dwp_checked
= 1;
12652 return per_objfile
->per_bfd
->dwp_file
.get ();
12655 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12656 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12657 or in the DWP file for the objfile, referenced by THIS_UNIT.
12658 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12659 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12661 This is called, for example, when wanting to read a variable with a
12662 complex location. Therefore we don't want to do file i/o for every call.
12663 Therefore we don't want to look for a DWO file on every call.
12664 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12665 then we check if we've already seen DWO_NAME, and only THEN do we check
12668 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12669 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12671 static struct dwo_unit
*
12672 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12673 ULONGEST signature
, int is_debug_types
)
12675 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12676 struct objfile
*objfile
= per_objfile
->objfile
;
12677 const char *kind
= is_debug_types
? "TU" : "CU";
12678 void **dwo_file_slot
;
12679 struct dwo_file
*dwo_file
;
12680 struct dwp_file
*dwp_file
;
12682 /* First see if there's a DWP file.
12683 If we have a DWP file but didn't find the DWO inside it, don't
12684 look for the original DWO file. It makes gdb behave differently
12685 depending on whether one is debugging in the build tree. */
12687 dwp_file
= get_dwp_file (per_objfile
);
12688 if (dwp_file
!= NULL
)
12690 const struct dwp_hash_table
*dwp_htab
=
12691 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12693 if (dwp_htab
!= NULL
)
12695 struct dwo_unit
*dwo_cutu
=
12696 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12699 if (dwo_cutu
!= NULL
)
12701 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12702 kind
, hex_string (signature
),
12703 host_address_to_string (dwo_cutu
));
12711 /* No DWP file, look for the DWO file. */
12713 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12714 if (*dwo_file_slot
== NULL
)
12716 /* Read in the file and build a table of the CUs/TUs it contains. */
12717 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12719 /* NOTE: This will be NULL if unable to open the file. */
12720 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12722 if (dwo_file
!= NULL
)
12724 struct dwo_unit
*dwo_cutu
= NULL
;
12726 if (is_debug_types
&& dwo_file
->tus
)
12728 struct dwo_unit find_dwo_cutu
;
12730 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12731 find_dwo_cutu
.signature
= signature
;
12733 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12736 else if (!is_debug_types
&& dwo_file
->cus
)
12738 struct dwo_unit find_dwo_cutu
;
12740 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12741 find_dwo_cutu
.signature
= signature
;
12742 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12746 if (dwo_cutu
!= NULL
)
12748 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12749 kind
, dwo_name
, hex_string (signature
),
12750 host_address_to_string (dwo_cutu
));
12757 /* We didn't find it. This could mean a dwo_id mismatch, or
12758 someone deleted the DWO/DWP file, or the search path isn't set up
12759 correctly to find the file. */
12761 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12762 kind
, dwo_name
, hex_string (signature
));
12764 /* This is a warning and not a complaint because it can be caused by
12765 pilot error (e.g., user accidentally deleting the DWO). */
12767 /* Print the name of the DWP file if we looked there, helps the user
12768 better diagnose the problem. */
12769 std::string dwp_text
;
12771 if (dwp_file
!= NULL
)
12772 dwp_text
= string_printf (" [in DWP file %s]",
12773 lbasename (dwp_file
->name
));
12775 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12776 " [in module %s]"),
12777 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12778 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12783 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12784 See lookup_dwo_cutu_unit for details. */
12786 static struct dwo_unit
*
12787 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12788 ULONGEST signature
)
12790 gdb_assert (!cu
->per_cu
->is_debug_types
);
12792 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12795 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12796 See lookup_dwo_cutu_unit for details. */
12798 static struct dwo_unit
*
12799 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12801 gdb_assert (cu
->per_cu
->is_debug_types
);
12803 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12805 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12808 /* Traversal function for queue_and_load_all_dwo_tus. */
12811 queue_and_load_dwo_tu (void **slot
, void *info
)
12813 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12814 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12815 ULONGEST signature
= dwo_unit
->signature
;
12816 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12818 if (sig_type
!= NULL
)
12820 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12821 a real dependency of PER_CU on SIG_TYPE. That is detected later
12822 while processing PER_CU. */
12823 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12825 load_full_type_unit (sig_type
, cu
->per_objfile
);
12826 cu
->per_cu
->imported_symtabs_push (sig_type
);
12832 /* Queue all TUs contained in the DWO of CU to be read in.
12833 The DWO may have the only definition of the type, though it may not be
12834 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12835 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12838 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12840 struct dwo_unit
*dwo_unit
;
12841 struct dwo_file
*dwo_file
;
12843 gdb_assert (cu
!= nullptr);
12844 gdb_assert (!cu
->per_cu
->is_debug_types
);
12845 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12847 dwo_unit
= cu
->dwo_unit
;
12848 gdb_assert (dwo_unit
!= NULL
);
12850 dwo_file
= dwo_unit
->dwo_file
;
12851 if (dwo_file
->tus
!= NULL
)
12852 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12855 /* Read in various DIEs. */
12857 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12858 Inherit only the children of the DW_AT_abstract_origin DIE not being
12859 already referenced by DW_AT_abstract_origin from the children of the
12863 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12865 struct die_info
*child_die
;
12866 sect_offset
*offsetp
;
12867 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12868 struct die_info
*origin_die
;
12869 /* Iterator of the ORIGIN_DIE children. */
12870 struct die_info
*origin_child_die
;
12871 struct attribute
*attr
;
12872 struct dwarf2_cu
*origin_cu
;
12873 struct pending
**origin_previous_list_in_scope
;
12875 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12879 /* Note that following die references may follow to a die in a
12883 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12885 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12887 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12888 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12890 if (die
->tag
!= origin_die
->tag
12891 && !(die
->tag
== DW_TAG_inlined_subroutine
12892 && origin_die
->tag
== DW_TAG_subprogram
))
12893 complaint (_("DIE %s and its abstract origin %s have different tags"),
12894 sect_offset_str (die
->sect_off
),
12895 sect_offset_str (origin_die
->sect_off
));
12897 /* Find if the concrete and abstract trees are structurally the
12898 same. This is a shallow traversal and it is not bullet-proof;
12899 the compiler can trick the debugger into believing that the trees
12900 are isomorphic, whereas they actually are not. However, the
12901 likelyhood of this happening is pretty low, and a full-fledged
12902 check would be an overkill. */
12903 bool are_isomorphic
= true;
12904 die_info
*concrete_child
= die
->child
;
12905 die_info
*abstract_child
= origin_die
->child
;
12906 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12908 if (concrete_child
== nullptr
12909 || abstract_child
== nullptr
12910 || concrete_child
->tag
!= abstract_child
->tag
)
12912 are_isomorphic
= false;
12916 concrete_child
= concrete_child
->sibling
;
12917 abstract_child
= abstract_child
->sibling
;
12920 /* Walk the origin's children in parallel to the concrete children.
12921 This helps match an origin child in case the debug info misses
12922 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12923 origin tree may not have the same tree structure as the concrete
12925 die_info
*corresponding_abstract_child
12926 = are_isomorphic
? origin_die
->child
: nullptr;
12928 std::vector
<sect_offset
> offsets
;
12930 for (child_die
= die
->child
;
12931 child_die
&& child_die
->tag
;
12932 child_die
= child_die
->sibling
)
12934 struct die_info
*child_origin_die
;
12935 struct dwarf2_cu
*child_origin_cu
;
12937 /* We are trying to process concrete instance entries:
12938 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12939 it's not relevant to our analysis here. i.e. detecting DIEs that are
12940 present in the abstract instance but not referenced in the concrete
12942 if (child_die
->tag
== DW_TAG_call_site
12943 || child_die
->tag
== DW_TAG_GNU_call_site
)
12945 if (are_isomorphic
)
12946 corresponding_abstract_child
12947 = corresponding_abstract_child
->sibling
;
12951 /* For each CHILD_DIE, find the corresponding child of
12952 ORIGIN_DIE. If there is more than one layer of
12953 DW_AT_abstract_origin, follow them all; there shouldn't be,
12954 but GCC versions at least through 4.4 generate this (GCC PR
12956 child_origin_die
= child_die
;
12957 child_origin_cu
= cu
;
12960 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12964 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12968 /* If missing DW_AT_abstract_origin, try the corresponding child
12969 of the origin. Clang emits such lexical scopes. */
12970 if (child_origin_die
== child_die
12971 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12973 && child_die
->tag
== DW_TAG_lexical_block
)
12974 child_origin_die
= corresponding_abstract_child
;
12976 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12977 counterpart may exist. */
12978 if (child_origin_die
!= child_die
)
12980 if (child_die
->tag
!= child_origin_die
->tag
12981 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12982 && child_origin_die
->tag
== DW_TAG_subprogram
))
12983 complaint (_("Child DIE %s and its abstract origin %s have "
12985 sect_offset_str (child_die
->sect_off
),
12986 sect_offset_str (child_origin_die
->sect_off
));
12987 if (child_origin_die
->parent
!= origin_die
)
12988 complaint (_("Child DIE %s and its abstract origin %s have "
12989 "different parents"),
12990 sect_offset_str (child_die
->sect_off
),
12991 sect_offset_str (child_origin_die
->sect_off
));
12993 offsets
.push_back (child_origin_die
->sect_off
);
12996 if (are_isomorphic
)
12997 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12999 std::sort (offsets
.begin (), offsets
.end ());
13000 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13001 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13002 if (offsetp
[-1] == *offsetp
)
13003 complaint (_("Multiple children of DIE %s refer "
13004 "to DIE %s as their abstract origin"),
13005 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13007 offsetp
= offsets
.data ();
13008 origin_child_die
= origin_die
->child
;
13009 while (origin_child_die
&& origin_child_die
->tag
)
13011 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13012 while (offsetp
< offsets_end
13013 && *offsetp
< origin_child_die
->sect_off
)
13015 if (offsetp
>= offsets_end
13016 || *offsetp
> origin_child_die
->sect_off
)
13018 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13019 Check whether we're already processing ORIGIN_CHILD_DIE.
13020 This can happen with mutually referenced abstract_origins.
13022 if (!origin_child_die
->in_process
)
13023 process_die (origin_child_die
, origin_cu
);
13025 origin_child_die
= origin_child_die
->sibling
;
13027 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13029 if (cu
!= origin_cu
)
13030 compute_delayed_physnames (origin_cu
);
13034 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13036 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13037 struct gdbarch
*gdbarch
= objfile
->arch ();
13038 struct context_stack
*newobj
;
13041 struct die_info
*child_die
;
13042 struct attribute
*attr
, *call_line
, *call_file
;
13044 CORE_ADDR baseaddr
;
13045 struct block
*block
;
13046 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13047 std::vector
<struct symbol
*> template_args
;
13048 struct template_symbol
*templ_func
= NULL
;
13052 /* If we do not have call site information, we can't show the
13053 caller of this inlined function. That's too confusing, so
13054 only use the scope for local variables. */
13055 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13056 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13057 if (call_line
== NULL
|| call_file
== NULL
)
13059 read_lexical_block_scope (die
, cu
);
13064 baseaddr
= objfile
->text_section_offset ();
13066 name
= dwarf2_name (die
, cu
);
13068 /* Ignore functions with missing or empty names. These are actually
13069 illegal according to the DWARF standard. */
13072 complaint (_("missing name for subprogram DIE at %s"),
13073 sect_offset_str (die
->sect_off
));
13077 /* Ignore functions with missing or invalid low and high pc attributes. */
13078 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13079 <= PC_BOUNDS_INVALID
)
13081 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13082 if (attr
== nullptr || !attr
->as_boolean ())
13083 complaint (_("cannot get low and high bounds "
13084 "for subprogram DIE at %s"),
13085 sect_offset_str (die
->sect_off
));
13089 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13090 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13092 /* If we have any template arguments, then we must allocate a
13093 different sort of symbol. */
13094 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13096 if (child_die
->tag
== DW_TAG_template_type_param
13097 || child_die
->tag
== DW_TAG_template_value_param
)
13099 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13100 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13105 gdb_assert (cu
->get_builder () != nullptr);
13106 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13107 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13108 (struct symbol
*) templ_func
);
13110 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13111 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13114 /* If there is a location expression for DW_AT_frame_base, record
13116 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13117 if (attr
!= nullptr)
13118 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13120 /* If there is a location for the static link, record it. */
13121 newobj
->static_link
= NULL
;
13122 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13123 if (attr
!= nullptr)
13125 newobj
->static_link
13126 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13127 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13131 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13133 if (die
->child
!= NULL
)
13135 child_die
= die
->child
;
13136 while (child_die
&& child_die
->tag
)
13138 if (child_die
->tag
== DW_TAG_template_type_param
13139 || child_die
->tag
== DW_TAG_template_value_param
)
13141 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13144 template_args
.push_back (arg
);
13147 process_die (child_die
, cu
);
13148 child_die
= child_die
->sibling
;
13152 inherit_abstract_dies (die
, cu
);
13154 /* If we have a DW_AT_specification, we might need to import using
13155 directives from the context of the specification DIE. See the
13156 comment in determine_prefix. */
13157 if (cu
->per_cu
->lang
== language_cplus
13158 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13160 struct dwarf2_cu
*spec_cu
= cu
;
13161 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13165 child_die
= spec_die
->child
;
13166 while (child_die
&& child_die
->tag
)
13168 if (child_die
->tag
== DW_TAG_imported_module
)
13169 process_die (child_die
, spec_cu
);
13170 child_die
= child_die
->sibling
;
13173 /* In some cases, GCC generates specification DIEs that
13174 themselves contain DW_AT_specification attributes. */
13175 spec_die
= die_specification (spec_die
, &spec_cu
);
13179 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13180 /* Make a block for the local symbols within. */
13181 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13182 cstk
.static_link
, lowpc
, highpc
);
13184 /* For C++, set the block's scope. */
13185 if ((cu
->per_cu
->lang
== language_cplus
13186 || cu
->per_cu
->lang
== language_fortran
13187 || cu
->per_cu
->lang
== language_d
13188 || cu
->per_cu
->lang
== language_rust
)
13189 && cu
->processing_has_namespace_info
)
13190 block_set_scope (block
, determine_prefix (die
, cu
),
13191 &objfile
->objfile_obstack
);
13193 /* If we have address ranges, record them. */
13194 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13196 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13198 /* Attach template arguments to function. */
13199 if (!template_args
.empty ())
13201 gdb_assert (templ_func
!= NULL
);
13203 templ_func
->n_template_arguments
= template_args
.size ();
13204 templ_func
->template_arguments
13205 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13206 templ_func
->n_template_arguments
);
13207 memcpy (templ_func
->template_arguments
,
13208 template_args
.data (),
13209 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13211 /* Make sure that the symtab is set on the new symbols. Even
13212 though they don't appear in this symtab directly, other parts
13213 of gdb assume that symbols do, and this is reasonably
13215 for (symbol
*sym
: template_args
)
13216 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13219 /* In C++, we can have functions nested inside functions (e.g., when
13220 a function declares a class that has methods). This means that
13221 when we finish processing a function scope, we may need to go
13222 back to building a containing block's symbol lists. */
13223 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13224 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13226 /* If we've finished processing a top-level function, subsequent
13227 symbols go in the file symbol list. */
13228 if (cu
->get_builder ()->outermost_context_p ())
13229 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13232 /* Process all the DIES contained within a lexical block scope. Start
13233 a new scope, process the dies, and then close the scope. */
13236 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13238 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13239 struct gdbarch
*gdbarch
= objfile
->arch ();
13240 CORE_ADDR lowpc
, highpc
;
13241 struct die_info
*child_die
;
13242 CORE_ADDR baseaddr
;
13244 baseaddr
= objfile
->text_section_offset ();
13246 /* Ignore blocks with missing or invalid low and high pc attributes. */
13247 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13248 as multiple lexical blocks? Handling children in a sane way would
13249 be nasty. Might be easier to properly extend generic blocks to
13250 describe ranges. */
13251 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13253 case PC_BOUNDS_NOT_PRESENT
:
13254 /* DW_TAG_lexical_block has no attributes, process its children as if
13255 there was no wrapping by that DW_TAG_lexical_block.
13256 GCC does no longer produces such DWARF since GCC r224161. */
13257 for (child_die
= die
->child
;
13258 child_die
!= NULL
&& child_die
->tag
;
13259 child_die
= child_die
->sibling
)
13261 /* We might already be processing this DIE. This can happen
13262 in an unusual circumstance -- where a subroutine A
13263 appears lexically in another subroutine B, but A actually
13264 inlines B. The recursion is broken here, rather than in
13265 inherit_abstract_dies, because it seems better to simply
13266 drop concrete children here. */
13267 if (!child_die
->in_process
)
13268 process_die (child_die
, cu
);
13271 case PC_BOUNDS_INVALID
:
13274 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13275 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13277 cu
->get_builder ()->push_context (0, lowpc
);
13278 if (die
->child
!= NULL
)
13280 child_die
= die
->child
;
13281 while (child_die
&& child_die
->tag
)
13283 process_die (child_die
, cu
);
13284 child_die
= child_die
->sibling
;
13287 inherit_abstract_dies (die
, cu
);
13288 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13290 if (*cu
->get_builder ()->get_local_symbols () != NULL
13291 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13293 struct block
*block
13294 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13295 cstk
.start_addr
, highpc
);
13297 /* Note that recording ranges after traversing children, as we
13298 do here, means that recording a parent's ranges entails
13299 walking across all its children's ranges as they appear in
13300 the address map, which is quadratic behavior.
13302 It would be nicer to record the parent's ranges before
13303 traversing its children, simply overriding whatever you find
13304 there. But since we don't even decide whether to create a
13305 block until after we've traversed its children, that's hard
13307 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13309 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13310 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13313 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13316 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13318 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13319 struct objfile
*objfile
= per_objfile
->objfile
;
13320 struct gdbarch
*gdbarch
= objfile
->arch ();
13321 CORE_ADDR pc
, baseaddr
;
13322 struct attribute
*attr
;
13325 struct die_info
*child_die
;
13327 baseaddr
= objfile
->text_section_offset ();
13329 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13332 /* This was a pre-DWARF-5 GNU extension alias
13333 for DW_AT_call_return_pc. */
13334 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13338 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13339 "DIE %s [in module %s]"),
13340 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13343 pc
= attr
->as_address () + baseaddr
;
13344 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13347 if (cu
->call_site_htab
== NULL
)
13348 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
13349 call_site::eq
, NULL
,
13350 &objfile
->objfile_obstack
,
13351 hashtab_obstack_allocate
, NULL
);
13352 struct call_site
call_site_local (pc
, nullptr, nullptr);
13353 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13356 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13357 "DIE %s [in module %s]"),
13358 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13359 objfile_name (objfile
));
13363 /* Count parameters at the caller. */
13366 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13367 child_die
= child_die
->sibling
)
13369 if (child_die
->tag
!= DW_TAG_call_site_parameter
13370 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13372 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13373 "DW_TAG_call_site child DIE %s [in module %s]"),
13374 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13375 objfile_name (objfile
));
13382 struct call_site
*call_site
13383 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
13385 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
13386 struct call_site (pc
, cu
->per_cu
, per_objfile
);
13389 /* We never call the destructor of call_site, so we must ensure it is
13390 trivially destructible. */
13391 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
13393 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13394 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13396 struct die_info
*func_die
;
13398 /* Skip also over DW_TAG_inlined_subroutine. */
13399 for (func_die
= die
->parent
;
13400 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13401 && func_die
->tag
!= DW_TAG_subroutine_type
;
13402 func_die
= func_die
->parent
);
13404 /* DW_AT_call_all_calls is a superset
13405 of DW_AT_call_all_tail_calls. */
13407 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13408 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13409 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13410 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13412 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13413 not complete. But keep CALL_SITE for look ups via call_site_htab,
13414 both the initial caller containing the real return address PC and
13415 the final callee containing the current PC of a chain of tail
13416 calls do not need to have the tail call list complete. But any
13417 function candidate for a virtual tail call frame searched via
13418 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13419 determined unambiguously. */
13423 struct type
*func_type
= NULL
;
13426 func_type
= get_die_type (func_die
, cu
);
13427 if (func_type
!= NULL
)
13429 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13431 /* Enlist this call site to the function. */
13432 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13433 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13436 complaint (_("Cannot find function owning DW_TAG_call_site "
13437 "DIE %s [in module %s]"),
13438 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13442 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13444 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13446 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13449 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13450 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13453 call_site
->target
.set_loc_dwarf_block (nullptr);
13454 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13455 /* Keep NULL DWARF_BLOCK. */;
13456 else if (attr
->form_is_block ())
13458 struct dwarf2_locexpr_baton
*dlbaton
;
13459 struct dwarf_block
*block
= attr
->as_block ();
13461 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13462 dlbaton
->data
= block
->data
;
13463 dlbaton
->size
= block
->size
;
13464 dlbaton
->per_objfile
= per_objfile
;
13465 dlbaton
->per_cu
= cu
->per_cu
;
13467 call_site
->target
.set_loc_dwarf_block (dlbaton
);
13469 else if (attr
->form_is_ref ())
13471 struct dwarf2_cu
*target_cu
= cu
;
13472 struct die_info
*target_die
;
13474 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13475 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13476 if (die_is_declaration (target_die
, target_cu
))
13478 const char *target_physname
;
13480 /* Prefer the mangled name; otherwise compute the demangled one. */
13481 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13482 if (target_physname
== NULL
)
13483 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13484 if (target_physname
== NULL
)
13485 complaint (_("DW_AT_call_target target DIE has invalid "
13486 "physname, for referencing DIE %s [in module %s]"),
13487 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13489 call_site
->target
.set_loc_physname (target_physname
);
13495 /* DW_AT_entry_pc should be preferred. */
13496 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13497 <= PC_BOUNDS_INVALID
)
13498 complaint (_("DW_AT_call_target target DIE has invalid "
13499 "low pc, for referencing DIE %s [in module %s]"),
13500 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13503 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
13505 call_site
->target
.set_loc_physaddr (lowpc
);
13510 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13511 "block nor reference, for DIE %s [in module %s]"),
13512 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13514 for (child_die
= die
->child
;
13515 child_die
&& child_die
->tag
;
13516 child_die
= child_die
->sibling
)
13518 struct call_site_parameter
*parameter
;
13519 struct attribute
*loc
, *origin
;
13521 if (child_die
->tag
!= DW_TAG_call_site_parameter
13522 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13524 /* Already printed the complaint above. */
13528 gdb_assert (call_site
->parameter_count
< nparams
);
13529 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13531 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13532 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13533 register is contained in DW_AT_call_value. */
13535 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13536 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13537 if (origin
== NULL
)
13539 /* This was a pre-DWARF-5 GNU extension alias
13540 for DW_AT_call_parameter. */
13541 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13543 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13545 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13547 sect_offset sect_off
= origin
->get_ref_die_offset ();
13548 if (!cu
->header
.offset_in_cu_p (sect_off
))
13550 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13551 binding can be done only inside one CU. Such referenced DIE
13552 therefore cannot be even moved to DW_TAG_partial_unit. */
13553 complaint (_("DW_AT_call_parameter offset is not in CU for "
13554 "DW_TAG_call_site child DIE %s [in module %s]"),
13555 sect_offset_str (child_die
->sect_off
),
13556 objfile_name (objfile
));
13559 parameter
->u
.param_cu_off
13560 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13562 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13564 complaint (_("No DW_FORM_block* DW_AT_location for "
13565 "DW_TAG_call_site child DIE %s [in module %s]"),
13566 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13571 struct dwarf_block
*block
= loc
->as_block ();
13573 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13574 (block
->data
, &block
->data
[block
->size
]);
13575 if (parameter
->u
.dwarf_reg
!= -1)
13576 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13577 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13578 &block
->data
[block
->size
],
13579 ¶meter
->u
.fb_offset
))
13580 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13583 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13584 "for DW_FORM_block* DW_AT_location is supported for "
13585 "DW_TAG_call_site child DIE %s "
13587 sect_offset_str (child_die
->sect_off
),
13588 objfile_name (objfile
));
13593 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13595 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13596 if (attr
== NULL
|| !attr
->form_is_block ())
13598 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13599 "DW_TAG_call_site child DIE %s [in module %s]"),
13600 sect_offset_str (child_die
->sect_off
),
13601 objfile_name (objfile
));
13605 struct dwarf_block
*block
= attr
->as_block ();
13606 parameter
->value
= block
->data
;
13607 parameter
->value_size
= block
->size
;
13609 /* Parameters are not pre-cleared by memset above. */
13610 parameter
->data_value
= NULL
;
13611 parameter
->data_value_size
= 0;
13612 call_site
->parameter_count
++;
13614 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13616 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13617 if (attr
!= nullptr)
13619 if (!attr
->form_is_block ())
13620 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13621 "DW_TAG_call_site child DIE %s [in module %s]"),
13622 sect_offset_str (child_die
->sect_off
),
13623 objfile_name (objfile
));
13626 block
= attr
->as_block ();
13627 parameter
->data_value
= block
->data
;
13628 parameter
->data_value_size
= block
->size
;
13634 /* Helper function for read_variable. If DIE represents a virtual
13635 table, then return the type of the concrete object that is
13636 associated with the virtual table. Otherwise, return NULL. */
13638 static struct type
*
13639 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13641 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13645 /* Find the type DIE. */
13646 struct die_info
*type_die
= NULL
;
13647 struct dwarf2_cu
*type_cu
= cu
;
13649 if (attr
->form_is_ref ())
13650 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13651 if (type_die
== NULL
)
13654 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13656 return die_containing_type (type_die
, type_cu
);
13659 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13662 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13664 struct rust_vtable_symbol
*storage
= NULL
;
13666 if (cu
->per_cu
->lang
== language_rust
)
13668 struct type
*containing_type
= rust_containing_type (die
, cu
);
13670 if (containing_type
!= NULL
)
13672 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13674 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13675 storage
->concrete_type
= containing_type
;
13676 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13680 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13681 struct attribute
*abstract_origin
13682 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13683 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13684 if (res
== NULL
&& loc
&& abstract_origin
)
13686 /* We have a variable without a name, but with a location and an abstract
13687 origin. This may be a concrete instance of an abstract variable
13688 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13690 struct dwarf2_cu
*origin_cu
= cu
;
13691 struct die_info
*origin_die
13692 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13693 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13694 per_objfile
->per_bfd
->abstract_to_concrete
13695 [origin_die
->sect_off
].push_back (die
->sect_off
);
13699 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13700 reading .debug_rnglists.
13701 Callback's type should be:
13702 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13703 Return true if the attributes are present and valid, otherwise,
13706 template <typename Callback
>
13708 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13709 dwarf_tag tag
, Callback
&&callback
)
13711 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13712 struct objfile
*objfile
= per_objfile
->objfile
;
13713 bfd
*obfd
= objfile
->obfd
;
13714 /* Base address selection entry. */
13715 gdb::optional
<CORE_ADDR
> base
;
13716 const gdb_byte
*buffer
;
13717 bool overflow
= false;
13718 ULONGEST addr_index
;
13719 struct dwarf2_section_info
*rnglists_section
;
13721 base
= cu
->base_address
;
13722 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13723 rnglists_section
->read (objfile
);
13725 if (offset
>= rnglists_section
->size
)
13727 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13731 buffer
= rnglists_section
->buffer
+ offset
;
13735 /* Initialize it due to a false compiler warning. */
13736 CORE_ADDR range_beginning
= 0, range_end
= 0;
13737 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13738 + rnglists_section
->size
);
13739 unsigned int bytes_read
;
13741 if (buffer
== buf_end
)
13746 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13749 case DW_RLE_end_of_list
:
13751 case DW_RLE_base_address
:
13752 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13757 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13758 buffer
+= bytes_read
;
13760 case DW_RLE_base_addressx
:
13761 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13762 buffer
+= bytes_read
;
13763 base
= read_addr_index (cu
, addr_index
);
13765 case DW_RLE_start_length
:
13766 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13771 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13773 buffer
+= bytes_read
;
13774 range_end
= (range_beginning
13775 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13776 buffer
+= bytes_read
;
13777 if (buffer
> buf_end
)
13783 case DW_RLE_startx_length
:
13784 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13785 buffer
+= bytes_read
;
13786 range_beginning
= read_addr_index (cu
, addr_index
);
13787 if (buffer
> buf_end
)
13792 range_end
= (range_beginning
13793 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13794 buffer
+= bytes_read
;
13796 case DW_RLE_offset_pair
:
13797 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13798 buffer
+= bytes_read
;
13799 if (buffer
> buf_end
)
13804 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13805 buffer
+= bytes_read
;
13806 if (buffer
> buf_end
)
13812 case DW_RLE_start_end
:
13813 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13818 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13820 buffer
+= bytes_read
;
13821 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13822 buffer
+= bytes_read
;
13824 case DW_RLE_startx_endx
:
13825 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13826 buffer
+= bytes_read
;
13827 range_beginning
= read_addr_index (cu
, addr_index
);
13828 if (buffer
> buf_end
)
13833 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13834 buffer
+= bytes_read
;
13835 range_end
= read_addr_index (cu
, addr_index
);
13838 complaint (_("Invalid .debug_rnglists data (no base address)"));
13841 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13843 if (rlet
== DW_RLE_base_address
)
13846 if (range_beginning
> range_end
)
13848 /* Inverted range entries are invalid. */
13849 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13853 /* Empty range entries have no effect. */
13854 if (range_beginning
== range_end
)
13857 /* Only DW_RLE_offset_pair needs the base address added. */
13858 if (rlet
== DW_RLE_offset_pair
)
13860 if (!base
.has_value ())
13862 /* We have no valid base address for the DW_RLE_offset_pair. */
13863 complaint (_("Invalid .debug_rnglists data (no base address for "
13864 "DW_RLE_offset_pair)"));
13868 range_beginning
+= *base
;
13869 range_end
+= *base
;
13872 /* A not-uncommon case of bad debug info.
13873 Don't pollute the addrmap with bad data. */
13874 if (range_beginning
== 0
13875 && !per_objfile
->per_bfd
->has_section_at_zero
)
13877 complaint (_(".debug_rnglists entry has start address of zero"
13878 " [in module %s]"), objfile_name (objfile
));
13882 callback (range_beginning
, range_end
);
13887 complaint (_("Offset %d is not terminated "
13888 "for DW_AT_ranges attribute"),
13896 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13897 Callback's type should be:
13898 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13899 Return 1 if the attributes are present and valid, otherwise, return 0. */
13901 template <typename Callback
>
13903 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13904 Callback
&&callback
)
13906 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13907 struct objfile
*objfile
= per_objfile
->objfile
;
13908 struct comp_unit_head
*cu_header
= &cu
->header
;
13909 bfd
*obfd
= objfile
->obfd
;
13910 unsigned int addr_size
= cu_header
->addr_size
;
13911 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13912 /* Base address selection entry. */
13913 gdb::optional
<CORE_ADDR
> base
;
13914 unsigned int dummy
;
13915 const gdb_byte
*buffer
;
13917 if (cu_header
->version
>= 5)
13918 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13920 base
= cu
->base_address
;
13922 per_objfile
->per_bfd
->ranges
.read (objfile
);
13923 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13925 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13929 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13933 CORE_ADDR range_beginning
, range_end
;
13935 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13936 buffer
+= addr_size
;
13937 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13938 buffer
+= addr_size
;
13939 offset
+= 2 * addr_size
;
13941 /* An end of list marker is a pair of zero addresses. */
13942 if (range_beginning
== 0 && range_end
== 0)
13943 /* Found the end of list entry. */
13946 /* Each base address selection entry is a pair of 2 values.
13947 The first is the largest possible address, the second is
13948 the base address. Check for a base address here. */
13949 if ((range_beginning
& mask
) == mask
)
13951 /* If we found the largest possible address, then we already
13952 have the base address in range_end. */
13957 if (!base
.has_value ())
13959 /* We have no valid base address for the ranges
13961 complaint (_("Invalid .debug_ranges data (no base address)"));
13965 if (range_beginning
> range_end
)
13967 /* Inverted range entries are invalid. */
13968 complaint (_("Invalid .debug_ranges data (inverted range)"));
13972 /* Empty range entries have no effect. */
13973 if (range_beginning
== range_end
)
13976 range_beginning
+= *base
;
13977 range_end
+= *base
;
13979 /* A not-uncommon case of bad debug info.
13980 Don't pollute the addrmap with bad data. */
13981 if (range_beginning
== 0
13982 && !per_objfile
->per_bfd
->has_section_at_zero
)
13984 complaint (_(".debug_ranges entry has start address of zero"
13985 " [in module %s]"), objfile_name (objfile
));
13989 callback (range_beginning
, range_end
);
13995 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13996 Return 1 if the attributes are present and valid, otherwise, return 0.
13997 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14000 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14001 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14002 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14004 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14005 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14006 struct gdbarch
*gdbarch
= objfile
->arch ();
14007 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14010 CORE_ADDR high
= 0;
14013 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14014 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14016 if (ranges_pst
!= NULL
)
14021 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14022 range_beginning
+ baseaddr
)
14024 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14025 range_end
+ baseaddr
)
14027 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14028 lowpc
, highpc
- 1, ranges_pst
);
14031 /* FIXME: This is recording everything as a low-high
14032 segment of consecutive addresses. We should have a
14033 data structure for discontiguous block ranges
14037 low
= range_beginning
;
14043 if (range_beginning
< low
)
14044 low
= range_beginning
;
14045 if (range_end
> high
)
14053 /* If the first entry is an end-of-list marker, the range
14054 describes an empty scope, i.e. no instructions. */
14060 *high_return
= high
;
14064 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14065 definition for the return value. *LOWPC and *HIGHPC are set iff
14066 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14068 static enum pc_bounds_kind
14069 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14070 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14071 dwarf2_psymtab
*pst
)
14073 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14074 struct attribute
*attr
;
14075 struct attribute
*attr_high
;
14077 CORE_ADDR high
= 0;
14078 enum pc_bounds_kind ret
;
14080 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14083 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14084 if (attr
!= nullptr)
14086 low
= attr
->as_address ();
14087 high
= attr_high
->as_address ();
14088 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14092 /* Found high w/o low attribute. */
14093 return PC_BOUNDS_INVALID
;
14095 /* Found consecutive range of addresses. */
14096 ret
= PC_BOUNDS_HIGH_LOW
;
14100 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14101 if (attr
!= nullptr && attr
->form_is_unsigned ())
14103 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14104 on DWARF version). */
14105 ULONGEST ranges_offset
= attr
->as_unsigned ();
14107 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14109 if (die
->tag
!= DW_TAG_compile_unit
)
14110 ranges_offset
+= cu
->gnu_ranges_base
;
14112 /* Value of the DW_AT_ranges attribute is the offset in the
14113 .debug_ranges section. */
14114 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14116 return PC_BOUNDS_INVALID
;
14117 /* Found discontinuous range of addresses. */
14118 ret
= PC_BOUNDS_RANGES
;
14121 return PC_BOUNDS_NOT_PRESENT
;
14124 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14126 return PC_BOUNDS_INVALID
;
14128 /* When using the GNU linker, .gnu.linkonce. sections are used to
14129 eliminate duplicate copies of functions and vtables and such.
14130 The linker will arbitrarily choose one and discard the others.
14131 The AT_*_pc values for such functions refer to local labels in
14132 these sections. If the section from that file was discarded, the
14133 labels are not in the output, so the relocs get a value of 0.
14134 If this is a discarded function, mark the pc bounds as invalid,
14135 so that GDB will ignore it. */
14136 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14137 return PC_BOUNDS_INVALID
;
14145 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14146 its low and high PC addresses. Do nothing if these addresses could not
14147 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14148 and HIGHPC to the high address if greater than HIGHPC. */
14151 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14152 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14153 struct dwarf2_cu
*cu
)
14155 CORE_ADDR low
, high
;
14156 struct die_info
*child
= die
->child
;
14158 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14160 *lowpc
= std::min (*lowpc
, low
);
14161 *highpc
= std::max (*highpc
, high
);
14164 /* If the language does not allow nested subprograms (either inside
14165 subprograms or lexical blocks), we're done. */
14166 if (cu
->per_cu
->lang
!= language_ada
)
14169 /* Check all the children of the given DIE. If it contains nested
14170 subprograms, then check their pc bounds. Likewise, we need to
14171 check lexical blocks as well, as they may also contain subprogram
14173 while (child
&& child
->tag
)
14175 if (child
->tag
== DW_TAG_subprogram
14176 || child
->tag
== DW_TAG_lexical_block
)
14177 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14178 child
= child
->sibling
;
14182 /* Get the low and high pc's represented by the scope DIE, and store
14183 them in *LOWPC and *HIGHPC. If the correct values can't be
14184 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14187 get_scope_pc_bounds (struct die_info
*die
,
14188 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14189 struct dwarf2_cu
*cu
)
14191 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14192 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14193 CORE_ADDR current_low
, current_high
;
14195 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14196 >= PC_BOUNDS_RANGES
)
14198 best_low
= current_low
;
14199 best_high
= current_high
;
14203 struct die_info
*child
= die
->child
;
14205 while (child
&& child
->tag
)
14207 switch (child
->tag
) {
14208 case DW_TAG_subprogram
:
14209 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14211 case DW_TAG_namespace
:
14212 case DW_TAG_module
:
14213 /* FIXME: carlton/2004-01-16: Should we do this for
14214 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14215 that current GCC's always emit the DIEs corresponding
14216 to definitions of methods of classes as children of a
14217 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14218 the DIEs giving the declarations, which could be
14219 anywhere). But I don't see any reason why the
14220 standards says that they have to be there. */
14221 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14223 if (current_low
!= ((CORE_ADDR
) -1))
14225 best_low
= std::min (best_low
, current_low
);
14226 best_high
= std::max (best_high
, current_high
);
14234 child
= child
->sibling
;
14239 *highpc
= best_high
;
14242 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14246 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14247 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14249 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14250 struct gdbarch
*gdbarch
= objfile
->arch ();
14251 struct attribute
*attr
;
14252 struct attribute
*attr_high
;
14254 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14257 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14258 if (attr
!= nullptr)
14260 CORE_ADDR low
= attr
->as_address ();
14261 CORE_ADDR high
= attr_high
->as_address ();
14263 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14266 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14267 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14268 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14272 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14273 if (attr
!= nullptr && attr
->form_is_unsigned ())
14275 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14276 on DWARF version). */
14277 ULONGEST ranges_offset
= attr
->as_unsigned ();
14279 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14281 if (die
->tag
!= DW_TAG_compile_unit
)
14282 ranges_offset
+= cu
->gnu_ranges_base
;
14284 std::vector
<blockrange
> blockvec
;
14285 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14286 [&] (CORE_ADDR start
, CORE_ADDR end
)
14290 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14291 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14292 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14293 blockvec
.emplace_back (start
, end
);
14296 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14300 /* Check whether the producer field indicates either of GCC < 4.6, or the
14301 Intel C/C++ compiler, and cache the result in CU. */
14304 check_producer (struct dwarf2_cu
*cu
)
14308 if (cu
->producer
== NULL
)
14310 /* For unknown compilers expect their behavior is DWARF version
14313 GCC started to support .debug_types sections by -gdwarf-4 since
14314 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14315 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14316 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14317 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14319 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14321 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14322 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14323 cu
->producer_is_gcc_11
= major
== 11;
14325 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14327 cu
->producer_is_icc
= true;
14328 cu
->producer_is_icc_lt_14
= major
< 14;
14330 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14331 cu
->producer_is_codewarrior
= true;
14334 /* For other non-GCC compilers, expect their behavior is DWARF version
14338 cu
->checked_producer
= true;
14341 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14342 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14343 during 4.6.0 experimental. */
14346 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14348 if (!cu
->checked_producer
)
14349 check_producer (cu
);
14351 return cu
->producer_is_gxx_lt_4_6
;
14355 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14356 with incorrect is_stmt attributes. */
14359 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14361 if (!cu
->checked_producer
)
14362 check_producer (cu
);
14364 return cu
->producer_is_codewarrior
;
14367 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14368 If that attribute is not available, return the appropriate
14371 static enum dwarf_access_attribute
14372 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14374 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14375 if (attr
!= nullptr)
14377 LONGEST value
= attr
->constant_value (-1);
14378 if (value
== DW_ACCESS_public
14379 || value
== DW_ACCESS_protected
14380 || value
== DW_ACCESS_private
)
14381 return (dwarf_access_attribute
) value
;
14382 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14386 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14388 /* The default DWARF 2 accessibility for members is public, the default
14389 accessibility for inheritance is private. */
14391 if (die
->tag
!= DW_TAG_inheritance
)
14392 return DW_ACCESS_public
;
14394 return DW_ACCESS_private
;
14398 /* DWARF 3+ defines the default accessibility a different way. The same
14399 rules apply now for DW_TAG_inheritance as for the members and it only
14400 depends on the container kind. */
14402 if (die
->parent
->tag
== DW_TAG_class_type
)
14403 return DW_ACCESS_private
;
14405 return DW_ACCESS_public
;
14409 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
14410 *OFFSET to the byte offset. If the attribute was not found return
14411 0, otherwise return 1. If it was found but could not properly be
14412 handled, set *OFFSET to 0. */
14415 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14418 struct attribute
*attr
;
14420 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14425 /* Note that we do not check for a section offset first here.
14426 This is because DW_AT_data_member_location is new in DWARF 4,
14427 so if we see it, we can assume that a constant form is really
14428 a constant and not a section offset. */
14429 if (attr
->form_is_constant ())
14430 *offset
= attr
->constant_value (0);
14431 else if (attr
->form_is_section_offset ())
14432 dwarf2_complex_location_expr_complaint ();
14433 else if (attr
->form_is_block ())
14434 *offset
= decode_locdesc (attr
->as_block (), cu
);
14436 dwarf2_complex_location_expr_complaint ();
14442 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14443 if (attr
!= nullptr)
14445 *offset
= attr
->constant_value (0);
14453 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
14454 store the results in FIELD. */
14457 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14458 struct field
*field
)
14460 struct attribute
*attr
;
14462 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14465 if (attr
->form_is_constant ())
14467 LONGEST offset
= attr
->constant_value (0);
14469 /* Work around this GCC 11 bug, where it would erroneously use -1
14470 data member locations, instead of 0:
14472 Negative DW_AT_data_member_location
14473 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378
14475 if (offset
== -1 && cu
->producer_is_gcc_11
)
14477 complaint (_("DW_AT_data_member_location value of -1, assuming 0"));
14481 field
->set_loc_bitpos (offset
* bits_per_byte
);
14483 else if (attr
->form_is_section_offset ())
14484 dwarf2_complex_location_expr_complaint ();
14485 else if (attr
->form_is_block ())
14488 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14490 field
->set_loc_bitpos (offset
* bits_per_byte
);
14493 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14494 struct objfile
*objfile
= per_objfile
->objfile
;
14495 struct dwarf2_locexpr_baton
*dlbaton
14496 = XOBNEW (&objfile
->objfile_obstack
,
14497 struct dwarf2_locexpr_baton
);
14498 dlbaton
->data
= attr
->as_block ()->data
;
14499 dlbaton
->size
= attr
->as_block ()->size
;
14500 /* When using this baton, we want to compute the address
14501 of the field, not the value. This is why
14502 is_reference is set to false here. */
14503 dlbaton
->is_reference
= false;
14504 dlbaton
->per_objfile
= per_objfile
;
14505 dlbaton
->per_cu
= cu
->per_cu
;
14507 field
->set_loc_dwarf_block (dlbaton
);
14511 dwarf2_complex_location_expr_complaint ();
14515 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14516 if (attr
!= nullptr)
14517 field
->set_loc_bitpos (attr
->constant_value (0));
14521 /* Add an aggregate field to the field list. */
14524 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14525 struct dwarf2_cu
*cu
)
14527 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14528 struct gdbarch
*gdbarch
= objfile
->arch ();
14529 struct nextfield
*new_field
;
14530 struct attribute
*attr
;
14532 const char *fieldname
= "";
14534 if (die
->tag
== DW_TAG_inheritance
)
14536 fip
->baseclasses
.emplace_back ();
14537 new_field
= &fip
->baseclasses
.back ();
14541 fip
->fields
.emplace_back ();
14542 new_field
= &fip
->fields
.back ();
14545 new_field
->offset
= die
->sect_off
;
14547 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14548 if (new_field
->accessibility
!= DW_ACCESS_public
)
14549 fip
->non_public_fields
= true;
14551 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14552 if (attr
!= nullptr)
14553 new_field
->virtuality
= attr
->as_virtuality ();
14555 new_field
->virtuality
= DW_VIRTUALITY_none
;
14557 fp
= &new_field
->field
;
14559 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14561 /* Data member other than a C++ static data member. */
14563 /* Get type of field. */
14564 fp
->set_type (die_type (die
, cu
));
14566 fp
->set_loc_bitpos (0);
14568 /* Get bit size of field (zero if none). */
14569 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14570 if (attr
!= nullptr)
14572 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14576 FIELD_BITSIZE (*fp
) = 0;
14579 /* Get bit offset of field. */
14580 handle_member_location (die
, cu
, fp
);
14581 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14582 if (attr
!= nullptr && attr
->form_is_constant ())
14584 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14586 /* For big endian bits, the DW_AT_bit_offset gives the
14587 additional bit offset from the MSB of the containing
14588 anonymous object to the MSB of the field. We don't
14589 have to do anything special since we don't need to
14590 know the size of the anonymous object. */
14591 fp
->set_loc_bitpos (fp
->loc_bitpos () + attr
->constant_value (0));
14595 /* For little endian bits, compute the bit offset to the
14596 MSB of the anonymous object, subtract off the number of
14597 bits from the MSB of the field to the MSB of the
14598 object, and then subtract off the number of bits of
14599 the field itself. The result is the bit offset of
14600 the LSB of the field. */
14601 int anonymous_size
;
14602 int bit_offset
= attr
->constant_value (0);
14604 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14605 if (attr
!= nullptr && attr
->form_is_constant ())
14607 /* The size of the anonymous object containing
14608 the bit field is explicit, so use the
14609 indicated size (in bytes). */
14610 anonymous_size
= attr
->constant_value (0);
14614 /* The size of the anonymous object containing
14615 the bit field must be inferred from the type
14616 attribute of the data member containing the
14618 anonymous_size
= TYPE_LENGTH (fp
->type ());
14620 fp
->set_loc_bitpos (fp
->loc_bitpos ()
14621 + anonymous_size
* bits_per_byte
14622 - bit_offset
- FIELD_BITSIZE (*fp
));
14626 /* Get name of field. */
14627 fieldname
= dwarf2_name (die
, cu
);
14628 if (fieldname
== NULL
)
14631 /* The name is already allocated along with this objfile, so we don't
14632 need to duplicate it for the type. */
14633 fp
->set_name (fieldname
);
14635 /* Change accessibility for artificial fields (e.g. virtual table
14636 pointer or virtual base class pointer) to private. */
14637 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14639 FIELD_ARTIFICIAL (*fp
) = 1;
14640 new_field
->accessibility
= DW_ACCESS_private
;
14641 fip
->non_public_fields
= true;
14644 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14646 /* C++ static member. */
14648 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14649 is a declaration, but all versions of G++ as of this writing
14650 (so through at least 3.2.1) incorrectly generate
14651 DW_TAG_variable tags. */
14653 const char *physname
;
14655 /* Get name of field. */
14656 fieldname
= dwarf2_name (die
, cu
);
14657 if (fieldname
== NULL
)
14660 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14662 /* Only create a symbol if this is an external value.
14663 new_symbol checks this and puts the value in the global symbol
14664 table, which we want. If it is not external, new_symbol
14665 will try to put the value in cu->list_in_scope which is wrong. */
14666 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14668 /* A static const member, not much different than an enum as far as
14669 we're concerned, except that we can support more types. */
14670 new_symbol (die
, NULL
, cu
);
14673 /* Get physical name. */
14674 physname
= dwarf2_physname (fieldname
, die
, cu
);
14676 /* The name is already allocated along with this objfile, so we don't
14677 need to duplicate it for the type. */
14678 fp
->set_loc_physname (physname
? physname
: "");
14679 fp
->set_type (die_type (die
, cu
));
14680 fp
->set_name (fieldname
);
14682 else if (die
->tag
== DW_TAG_inheritance
)
14684 /* C++ base class field. */
14685 handle_member_location (die
, cu
, fp
);
14686 FIELD_BITSIZE (*fp
) = 0;
14687 fp
->set_type (die_type (die
, cu
));
14688 fp
->set_name (fp
->type ()->name ());
14691 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14694 /* Can the type given by DIE define another type? */
14697 type_can_define_types (const struct die_info
*die
)
14701 case DW_TAG_typedef
:
14702 case DW_TAG_class_type
:
14703 case DW_TAG_structure_type
:
14704 case DW_TAG_union_type
:
14705 case DW_TAG_enumeration_type
:
14713 /* Add a type definition defined in the scope of the FIP's class. */
14716 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14717 struct dwarf2_cu
*cu
)
14719 struct decl_field fp
;
14720 memset (&fp
, 0, sizeof (fp
));
14722 gdb_assert (type_can_define_types (die
));
14724 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14725 fp
.name
= dwarf2_name (die
, cu
);
14726 fp
.type
= read_type_die (die
, cu
);
14728 /* Save accessibility. */
14729 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14730 switch (accessibility
)
14732 case DW_ACCESS_public
:
14733 /* The assumed value if neither private nor protected. */
14735 case DW_ACCESS_private
:
14738 case DW_ACCESS_protected
:
14739 fp
.is_protected
= 1;
14743 if (die
->tag
== DW_TAG_typedef
)
14744 fip
->typedef_field_list
.push_back (fp
);
14746 fip
->nested_types_list
.push_back (fp
);
14749 /* A convenience typedef that's used when finding the discriminant
14750 field for a variant part. */
14751 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14754 /* Compute the discriminant range for a given variant. OBSTACK is
14755 where the results will be stored. VARIANT is the variant to
14756 process. IS_UNSIGNED indicates whether the discriminant is signed
14759 static const gdb::array_view
<discriminant_range
>
14760 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14763 std::vector
<discriminant_range
> ranges
;
14765 if (variant
.default_branch
)
14768 if (variant
.discr_list_data
== nullptr)
14770 discriminant_range r
14771 = {variant
.discriminant_value
, variant
.discriminant_value
};
14772 ranges
.push_back (r
);
14776 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14777 variant
.discr_list_data
->size
);
14778 while (!data
.empty ())
14780 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14782 complaint (_("invalid discriminant marker: %d"), data
[0]);
14785 bool is_range
= data
[0] == DW_DSC_range
;
14786 data
= data
.slice (1);
14788 ULONGEST low
, high
;
14789 unsigned int bytes_read
;
14793 complaint (_("DW_AT_discr_list missing low value"));
14797 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14799 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14801 data
= data
.slice (bytes_read
);
14807 complaint (_("DW_AT_discr_list missing high value"));
14811 high
= read_unsigned_leb128 (nullptr, data
.data (),
14814 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14816 data
= data
.slice (bytes_read
);
14821 ranges
.push_back ({ low
, high
});
14825 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14827 std::copy (ranges
.begin (), ranges
.end (), result
);
14828 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14831 static const gdb::array_view
<variant_part
> create_variant_parts
14832 (struct obstack
*obstack
,
14833 const offset_map_type
&offset_map
,
14834 struct field_info
*fi
,
14835 const std::vector
<variant_part_builder
> &variant_parts
);
14837 /* Fill in a "struct variant" for a given variant field. RESULT is
14838 the variant to fill in. OBSTACK is where any needed allocations
14839 will be done. OFFSET_MAP holds the mapping from section offsets to
14840 fields for the type. FI describes the fields of the type we're
14841 processing. FIELD is the variant field we're converting. */
14844 create_one_variant (variant
&result
, struct obstack
*obstack
,
14845 const offset_map_type
&offset_map
,
14846 struct field_info
*fi
, const variant_field
&field
)
14848 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14849 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14850 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14851 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14852 field
.variant_parts
);
14855 /* Fill in a "struct variant_part" for a given variant part. RESULT
14856 is the variant part to fill in. OBSTACK is where any needed
14857 allocations will be done. OFFSET_MAP holds the mapping from
14858 section offsets to fields for the type. FI describes the fields of
14859 the type we're processing. BUILDER is the variant part to be
14863 create_one_variant_part (variant_part
&result
,
14864 struct obstack
*obstack
,
14865 const offset_map_type
&offset_map
,
14866 struct field_info
*fi
,
14867 const variant_part_builder
&builder
)
14869 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14870 if (iter
== offset_map
.end ())
14872 result
.discriminant_index
= -1;
14873 /* Doesn't matter. */
14874 result
.is_unsigned
= false;
14878 result
.discriminant_index
= iter
->second
;
14880 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14883 size_t n
= builder
.variants
.size ();
14884 variant
*output
= new (obstack
) variant
[n
];
14885 for (size_t i
= 0; i
< n
; ++i
)
14886 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14887 builder
.variants
[i
]);
14889 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14892 /* Create a vector of variant parts that can be attached to a type.
14893 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14894 holds the mapping from section offsets to fields for the type. FI
14895 describes the fields of the type we're processing. VARIANT_PARTS
14896 is the vector to convert. */
14898 static const gdb::array_view
<variant_part
>
14899 create_variant_parts (struct obstack
*obstack
,
14900 const offset_map_type
&offset_map
,
14901 struct field_info
*fi
,
14902 const std::vector
<variant_part_builder
> &variant_parts
)
14904 if (variant_parts
.empty ())
14907 size_t n
= variant_parts
.size ();
14908 variant_part
*result
= new (obstack
) variant_part
[n
];
14909 for (size_t i
= 0; i
< n
; ++i
)
14910 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14913 return gdb::array_view
<variant_part
> (result
, n
);
14916 /* Compute the variant part vector for FIP, attaching it to TYPE when
14920 add_variant_property (struct field_info
*fip
, struct type
*type
,
14921 struct dwarf2_cu
*cu
)
14923 /* Map section offsets of fields to their field index. Note the
14924 field index here does not take the number of baseclasses into
14926 offset_map_type offset_map
;
14927 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14928 offset_map
[fip
->fields
[i
].offset
] = i
;
14930 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14931 gdb::array_view
<const variant_part
> parts
14932 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14933 fip
->variant_parts
);
14935 struct dynamic_prop prop
;
14936 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14937 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14940 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14943 /* Create the vector of fields, and attach it to the type. */
14946 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14947 struct dwarf2_cu
*cu
)
14949 int nfields
= fip
->nfields ();
14951 /* Record the field count, allocate space for the array of fields,
14952 and create blank accessibility bitfields if necessary. */
14953 type
->set_num_fields (nfields
);
14955 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14957 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
14959 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14961 TYPE_FIELD_PRIVATE_BITS (type
) =
14962 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14963 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14965 TYPE_FIELD_PROTECTED_BITS (type
) =
14966 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14967 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14969 TYPE_FIELD_IGNORE_BITS (type
) =
14970 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14971 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14974 /* If the type has baseclasses, allocate and clear a bit vector for
14975 TYPE_FIELD_VIRTUAL_BITS. */
14976 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
14978 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14979 unsigned char *pointer
;
14981 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14982 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14983 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14984 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14985 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14988 if (!fip
->variant_parts
.empty ())
14989 add_variant_property (fip
, type
, cu
);
14991 /* Copy the saved-up fields into the field vector. */
14992 for (int i
= 0; i
< nfields
; ++i
)
14994 struct nextfield
&field
14995 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14996 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14998 type
->field (i
) = field
.field
;
14999 switch (field
.accessibility
)
15001 case DW_ACCESS_private
:
15002 if (cu
->per_cu
->lang
!= language_ada
)
15003 SET_TYPE_FIELD_PRIVATE (type
, i
);
15006 case DW_ACCESS_protected
:
15007 if (cu
->per_cu
->lang
!= language_ada
)
15008 SET_TYPE_FIELD_PROTECTED (type
, i
);
15011 case DW_ACCESS_public
:
15015 /* Unknown accessibility. Complain and treat it as public. */
15017 complaint (_("unsupported accessibility %d"),
15018 field
.accessibility
);
15022 if (i
< fip
->baseclasses
.size ())
15024 switch (field
.virtuality
)
15026 case DW_VIRTUALITY_virtual
:
15027 case DW_VIRTUALITY_pure_virtual
:
15028 if (cu
->per_cu
->lang
== language_ada
)
15029 error (_("unexpected virtuality in component of Ada type"));
15030 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15037 /* Return true if this member function is a constructor, false
15041 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15043 const char *fieldname
;
15044 const char *type_name
;
15047 if (die
->parent
== NULL
)
15050 if (die
->parent
->tag
!= DW_TAG_structure_type
15051 && die
->parent
->tag
!= DW_TAG_union_type
15052 && die
->parent
->tag
!= DW_TAG_class_type
)
15055 fieldname
= dwarf2_name (die
, cu
);
15056 type_name
= dwarf2_name (die
->parent
, cu
);
15057 if (fieldname
== NULL
|| type_name
== NULL
)
15060 len
= strlen (fieldname
);
15061 return (strncmp (fieldname
, type_name
, len
) == 0
15062 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15065 /* Add a member function to the proper fieldlist. */
15068 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15069 struct type
*type
, struct dwarf2_cu
*cu
)
15071 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15072 struct attribute
*attr
;
15074 struct fnfieldlist
*flp
= nullptr;
15075 struct fn_field
*fnp
;
15076 const char *fieldname
;
15077 struct type
*this_type
;
15079 if (cu
->per_cu
->lang
== language_ada
)
15080 error (_("unexpected member function in Ada type"));
15082 /* Get name of member function. */
15083 fieldname
= dwarf2_name (die
, cu
);
15084 if (fieldname
== NULL
)
15087 /* Look up member function name in fieldlist. */
15088 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15090 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15092 flp
= &fip
->fnfieldlists
[i
];
15097 /* Create a new fnfieldlist if necessary. */
15098 if (flp
== nullptr)
15100 fip
->fnfieldlists
.emplace_back ();
15101 flp
= &fip
->fnfieldlists
.back ();
15102 flp
->name
= fieldname
;
15103 i
= fip
->fnfieldlists
.size () - 1;
15106 /* Create a new member function field and add it to the vector of
15108 flp
->fnfields
.emplace_back ();
15109 fnp
= &flp
->fnfields
.back ();
15111 /* Delay processing of the physname until later. */
15112 if (cu
->per_cu
->lang
== language_cplus
)
15113 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15117 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15118 fnp
->physname
= physname
? physname
: "";
15121 fnp
->type
= alloc_type (objfile
);
15122 this_type
= read_type_die (die
, cu
);
15123 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15125 int nparams
= this_type
->num_fields ();
15127 /* TYPE is the domain of this method, and THIS_TYPE is the type
15128 of the method itself (TYPE_CODE_METHOD). */
15129 smash_to_method_type (fnp
->type
, type
,
15130 TYPE_TARGET_TYPE (this_type
),
15131 this_type
->fields (),
15132 this_type
->num_fields (),
15133 this_type
->has_varargs ());
15135 /* Handle static member functions.
15136 Dwarf2 has no clean way to discern C++ static and non-static
15137 member functions. G++ helps GDB by marking the first
15138 parameter for non-static member functions (which is the this
15139 pointer) as artificial. We obtain this information from
15140 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15141 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15142 fnp
->voffset
= VOFFSET_STATIC
;
15145 complaint (_("member function type missing for '%s'"),
15146 dwarf2_full_name (fieldname
, die
, cu
));
15148 /* Get fcontext from DW_AT_containing_type if present. */
15149 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15150 fnp
->fcontext
= die_containing_type (die
, cu
);
15152 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15153 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15155 /* Get accessibility. */
15156 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15157 switch (accessibility
)
15159 case DW_ACCESS_private
:
15160 fnp
->is_private
= 1;
15162 case DW_ACCESS_protected
:
15163 fnp
->is_protected
= 1;
15167 /* Check for artificial methods. */
15168 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15169 if (attr
&& attr
->as_boolean ())
15170 fnp
->is_artificial
= 1;
15172 /* Check for defaulted methods. */
15173 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15174 if (attr
!= nullptr)
15175 fnp
->defaulted
= attr
->defaulted ();
15177 /* Check for deleted methods. */
15178 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15179 if (attr
!= nullptr && attr
->as_boolean ())
15180 fnp
->is_deleted
= 1;
15182 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15184 /* Get index in virtual function table if it is a virtual member
15185 function. For older versions of GCC, this is an offset in the
15186 appropriate virtual table, as specified by DW_AT_containing_type.
15187 For everyone else, it is an expression to be evaluated relative
15188 to the object address. */
15190 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15191 if (attr
!= nullptr)
15193 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15195 struct dwarf_block
*block
= attr
->as_block ();
15197 if (block
->data
[0] == DW_OP_constu
)
15199 /* Old-style GCC. */
15200 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15202 else if (block
->data
[0] == DW_OP_deref
15203 || (block
->size
> 1
15204 && block
->data
[0] == DW_OP_deref_size
15205 && block
->data
[1] == cu
->header
.addr_size
))
15207 fnp
->voffset
= decode_locdesc (block
, cu
);
15208 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15209 dwarf2_complex_location_expr_complaint ();
15211 fnp
->voffset
/= cu
->header
.addr_size
;
15215 dwarf2_complex_location_expr_complaint ();
15217 if (!fnp
->fcontext
)
15219 /* If there is no `this' field and no DW_AT_containing_type,
15220 we cannot actually find a base class context for the
15222 if (this_type
->num_fields () == 0
15223 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15225 complaint (_("cannot determine context for virtual member "
15226 "function \"%s\" (offset %s)"),
15227 fieldname
, sect_offset_str (die
->sect_off
));
15232 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15236 else if (attr
->form_is_section_offset ())
15238 dwarf2_complex_location_expr_complaint ();
15242 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15248 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15249 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15251 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15252 complaint (_("Member function \"%s\" (offset %s) is virtual "
15253 "but the vtable offset is not specified"),
15254 fieldname
, sect_offset_str (die
->sect_off
));
15255 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15256 TYPE_CPLUS_DYNAMIC (type
) = 1;
15261 /* Create the vector of member function fields, and attach it to the type. */
15264 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15265 struct dwarf2_cu
*cu
)
15267 if (cu
->per_cu
->lang
== language_ada
)
15268 error (_("unexpected member functions in Ada type"));
15270 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15271 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15273 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15275 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15277 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15278 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15280 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15281 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15282 fn_flp
->fn_fields
= (struct fn_field
*)
15283 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15285 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15286 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15289 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15292 /* Returns non-zero if NAME is the name of a vtable member in CU's
15293 language, zero otherwise. */
15295 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15297 static const char vptr
[] = "_vptr";
15299 /* Look for the C++ form of the vtable. */
15300 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15306 /* GCC outputs unnamed structures that are really pointers to member
15307 functions, with the ABI-specified layout. If TYPE describes
15308 such a structure, smash it into a member function type.
15310 GCC shouldn't do this; it should just output pointer to member DIEs.
15311 This is GCC PR debug/28767. */
15314 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15316 struct type
*pfn_type
, *self_type
, *new_type
;
15318 /* Check for a structure with no name and two children. */
15319 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15322 /* Check for __pfn and __delta members. */
15323 if (type
->field (0).name () == NULL
15324 || strcmp (type
->field (0).name (), "__pfn") != 0
15325 || type
->field (1).name () == NULL
15326 || strcmp (type
->field (1).name (), "__delta") != 0)
15329 /* Find the type of the method. */
15330 pfn_type
= type
->field (0).type ();
15331 if (pfn_type
== NULL
15332 || pfn_type
->code () != TYPE_CODE_PTR
15333 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15336 /* Look for the "this" argument. */
15337 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15338 if (pfn_type
->num_fields () == 0
15339 /* || pfn_type->field (0).type () == NULL */
15340 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15343 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15344 new_type
= alloc_type (objfile
);
15345 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15346 pfn_type
->fields (), pfn_type
->num_fields (),
15347 pfn_type
->has_varargs ());
15348 smash_to_methodptr_type (type
, new_type
);
15351 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15352 requires rewriting, then copy it and return the updated copy.
15353 Otherwise return nullptr. */
15355 static struct type
*
15356 rewrite_array_type (struct type
*type
)
15358 if (type
->code () != TYPE_CODE_ARRAY
)
15361 struct type
*index_type
= type
->index_type ();
15362 range_bounds
*current_bounds
= index_type
->bounds ();
15364 /* Handle multi-dimensional arrays. */
15365 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15366 if (new_target
== nullptr)
15368 /* Maybe we don't need to rewrite this array. */
15369 if (current_bounds
->low
.kind () == PROP_CONST
15370 && current_bounds
->high
.kind () == PROP_CONST
)
15374 /* Either the target type was rewritten, or the bounds have to be
15375 updated. Either way we want to copy the type and update
15377 struct type
*copy
= copy_type (type
);
15378 int nfields
= copy
->num_fields ();
15380 = ((struct field
*) TYPE_ZALLOC (copy
,
15381 nfields
* sizeof (struct field
)));
15382 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15383 copy
->set_fields (new_fields
);
15384 if (new_target
!= nullptr)
15385 TYPE_TARGET_TYPE (copy
) = new_target
;
15387 struct type
*index_copy
= copy_type (index_type
);
15388 range_bounds
*bounds
15389 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15390 sizeof (range_bounds
));
15391 *bounds
= *current_bounds
;
15392 bounds
->low
.set_const_val (1);
15393 bounds
->high
.set_const_val (0);
15394 index_copy
->set_bounds (bounds
);
15395 copy
->set_index_type (index_copy
);
15400 /* While some versions of GCC will generate complicated DWARF for an
15401 array (see quirk_ada_thick_pointer), more recent versions were
15402 modified to emit an explicit thick pointer structure. However, in
15403 this case, the array still has DWARF expressions for its ranges,
15404 and these must be ignored. */
15407 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15410 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15412 /* Check for a structure with two children. */
15413 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15416 /* Check for P_ARRAY and P_BOUNDS members. */
15417 if (type
->field (0).name () == NULL
15418 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
15419 || type
->field (1).name () == NULL
15420 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
15423 /* Make sure we're looking at a pointer to an array. */
15424 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15427 /* The Ada code already knows how to handle these types, so all that
15428 we need to do is turn the bounds into static bounds. However, we
15429 don't want to rewrite existing array or index types in-place,
15430 because those may be referenced in other contexts where this
15431 rewriting is undesirable. */
15432 struct type
*new_ary_type
15433 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15434 if (new_ary_type
!= nullptr)
15435 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15438 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15439 appropriate error checking and issuing complaints if there is a
15443 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15445 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15447 if (attr
== nullptr)
15450 if (!attr
->form_is_constant ())
15452 complaint (_("DW_AT_alignment must have constant form"
15453 " - DIE at %s [in module %s]"),
15454 sect_offset_str (die
->sect_off
),
15455 objfile_name (cu
->per_objfile
->objfile
));
15459 LONGEST val
= attr
->constant_value (0);
15462 complaint (_("DW_AT_alignment value must not be negative"
15463 " - DIE at %s [in module %s]"),
15464 sect_offset_str (die
->sect_off
),
15465 objfile_name (cu
->per_objfile
->objfile
));
15468 ULONGEST align
= val
;
15472 complaint (_("DW_AT_alignment value must not be zero"
15473 " - DIE at %s [in module %s]"),
15474 sect_offset_str (die
->sect_off
),
15475 objfile_name (cu
->per_objfile
->objfile
));
15478 if ((align
& (align
- 1)) != 0)
15480 complaint (_("DW_AT_alignment value must be a power of 2"
15481 " - DIE at %s [in module %s]"),
15482 sect_offset_str (die
->sect_off
),
15483 objfile_name (cu
->per_objfile
->objfile
));
15490 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15491 the alignment for TYPE. */
15494 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15497 if (!set_type_align (type
, get_alignment (cu
, die
)))
15498 complaint (_("DW_AT_alignment value too large"
15499 " - DIE at %s [in module %s]"),
15500 sect_offset_str (die
->sect_off
),
15501 objfile_name (cu
->per_objfile
->objfile
));
15504 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15505 constant for a type, according to DWARF5 spec, Table 5.5. */
15508 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15513 case DW_CC_pass_by_reference
:
15514 case DW_CC_pass_by_value
:
15518 complaint (_("unrecognized DW_AT_calling_convention value "
15519 "(%s) for a type"), pulongest (value
));
15524 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15525 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15526 also according to GNU-specific values (see include/dwarf2.h). */
15529 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15534 case DW_CC_program
:
15538 case DW_CC_GNU_renesas_sh
:
15539 case DW_CC_GNU_borland_fastcall_i386
:
15540 case DW_CC_GDB_IBM_OpenCL
:
15544 complaint (_("unrecognized DW_AT_calling_convention value "
15545 "(%s) for a subroutine"), pulongest (value
));
15550 /* Called when we find the DIE that starts a structure or union scope
15551 (definition) to create a type for the structure or union. Fill in
15552 the type's name and general properties; the members will not be
15553 processed until process_structure_scope. A symbol table entry for
15554 the type will also not be done until process_structure_scope (assuming
15555 the type has a name).
15557 NOTE: we need to call these functions regardless of whether or not the
15558 DIE has a DW_AT_name attribute, since it might be an anonymous
15559 structure or union. This gets the type entered into our set of
15560 user defined types. */
15562 static struct type
*
15563 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15565 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15567 struct attribute
*attr
;
15570 /* If the definition of this type lives in .debug_types, read that type.
15571 Don't follow DW_AT_specification though, that will take us back up
15572 the chain and we want to go down. */
15573 attr
= die
->attr (DW_AT_signature
);
15574 if (attr
!= nullptr)
15576 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15578 /* The type's CU may not be the same as CU.
15579 Ensure TYPE is recorded with CU in die_type_hash. */
15580 return set_die_type (die
, type
, cu
);
15583 type
= alloc_type (objfile
);
15584 INIT_CPLUS_SPECIFIC (type
);
15586 name
= dwarf2_name (die
, cu
);
15589 if (cu
->per_cu
->lang
== language_cplus
15590 || cu
->per_cu
->lang
== language_d
15591 || cu
->per_cu
->lang
== language_rust
)
15593 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15595 /* dwarf2_full_name might have already finished building the DIE's
15596 type. If so, there is no need to continue. */
15597 if (get_die_type (die
, cu
) != NULL
)
15598 return get_die_type (die
, cu
);
15600 type
->set_name (full_name
);
15604 /* The name is already allocated along with this objfile, so
15605 we don't need to duplicate it for the type. */
15606 type
->set_name (name
);
15610 if (die
->tag
== DW_TAG_structure_type
)
15612 type
->set_code (TYPE_CODE_STRUCT
);
15614 else if (die
->tag
== DW_TAG_union_type
)
15616 type
->set_code (TYPE_CODE_UNION
);
15620 type
->set_code (TYPE_CODE_STRUCT
);
15623 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15624 type
->set_is_declared_class (true);
15626 /* Store the calling convention in the type if it's available in
15627 the die. Otherwise the calling convention remains set to
15628 the default value DW_CC_normal. */
15629 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15630 if (attr
!= nullptr
15631 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15633 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15634 TYPE_CPLUS_CALLING_CONVENTION (type
)
15635 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15638 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15639 if (attr
!= nullptr)
15641 if (attr
->form_is_constant ())
15642 TYPE_LENGTH (type
) = attr
->constant_value (0);
15645 struct dynamic_prop prop
;
15646 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15647 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15648 TYPE_LENGTH (type
) = 0;
15653 TYPE_LENGTH (type
) = 0;
15656 maybe_set_alignment (cu
, die
, type
);
15658 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15660 /* ICC<14 does not output the required DW_AT_declaration on
15661 incomplete types, but gives them a size of zero. */
15662 type
->set_is_stub (true);
15665 type
->set_stub_is_supported (true);
15667 if (die_is_declaration (die
, cu
))
15668 type
->set_is_stub (true);
15669 else if (attr
== NULL
&& die
->child
== NULL
15670 && producer_is_realview (cu
->producer
))
15671 /* RealView does not output the required DW_AT_declaration
15672 on incomplete types. */
15673 type
->set_is_stub (true);
15675 /* We need to add the type field to the die immediately so we don't
15676 infinitely recurse when dealing with pointers to the structure
15677 type within the structure itself. */
15678 set_die_type (die
, type
, cu
);
15680 /* set_die_type should be already done. */
15681 set_descriptive_type (type
, die
, cu
);
15686 static void handle_struct_member_die
15687 (struct die_info
*child_die
,
15689 struct field_info
*fi
,
15690 std::vector
<struct symbol
*> *template_args
,
15691 struct dwarf2_cu
*cu
);
15693 /* A helper for handle_struct_member_die that handles
15694 DW_TAG_variant_part. */
15697 handle_variant_part (struct die_info
*die
, struct type
*type
,
15698 struct field_info
*fi
,
15699 std::vector
<struct symbol
*> *template_args
,
15700 struct dwarf2_cu
*cu
)
15702 variant_part_builder
*new_part
;
15703 if (fi
->current_variant_part
== nullptr)
15705 fi
->variant_parts
.emplace_back ();
15706 new_part
= &fi
->variant_parts
.back ();
15708 else if (!fi
->current_variant_part
->processing_variant
)
15710 complaint (_("nested DW_TAG_variant_part seen "
15711 "- DIE at %s [in module %s]"),
15712 sect_offset_str (die
->sect_off
),
15713 objfile_name (cu
->per_objfile
->objfile
));
15718 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15719 current
.variant_parts
.emplace_back ();
15720 new_part
= ¤t
.variant_parts
.back ();
15723 /* When we recurse, we want callees to add to this new variant
15725 scoped_restore save_current_variant_part
15726 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15728 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15731 /* It's a univariant form, an extension we support. */
15733 else if (discr
->form_is_ref ())
15735 struct dwarf2_cu
*target_cu
= cu
;
15736 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15738 new_part
->discriminant_offset
= target_die
->sect_off
;
15742 complaint (_("DW_AT_discr does not have DIE reference form"
15743 " - DIE at %s [in module %s]"),
15744 sect_offset_str (die
->sect_off
),
15745 objfile_name (cu
->per_objfile
->objfile
));
15748 for (die_info
*child_die
= die
->child
;
15750 child_die
= child_die
->sibling
)
15751 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15754 /* A helper for handle_struct_member_die that handles
15758 handle_variant (struct die_info
*die
, struct type
*type
,
15759 struct field_info
*fi
,
15760 std::vector
<struct symbol
*> *template_args
,
15761 struct dwarf2_cu
*cu
)
15763 if (fi
->current_variant_part
== nullptr)
15765 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15766 "- DIE at %s [in module %s]"),
15767 sect_offset_str (die
->sect_off
),
15768 objfile_name (cu
->per_objfile
->objfile
));
15771 if (fi
->current_variant_part
->processing_variant
)
15773 complaint (_("nested DW_TAG_variant seen "
15774 "- DIE at %s [in module %s]"),
15775 sect_offset_str (die
->sect_off
),
15776 objfile_name (cu
->per_objfile
->objfile
));
15780 scoped_restore save_processing_variant
15781 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15784 fi
->current_variant_part
->variants
.emplace_back ();
15785 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15786 variant
.first_field
= fi
->fields
.size ();
15788 /* In a variant we want to get the discriminant and also add a
15789 field for our sole member child. */
15790 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15791 if (discr
== nullptr || !discr
->form_is_constant ())
15793 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15794 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15795 variant
.default_branch
= true;
15797 variant
.discr_list_data
= discr
->as_block ();
15800 variant
.discriminant_value
= discr
->constant_value (0);
15802 for (die_info
*variant_child
= die
->child
;
15803 variant_child
!= NULL
;
15804 variant_child
= variant_child
->sibling
)
15805 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15807 variant
.last_field
= fi
->fields
.size ();
15810 /* A helper for process_structure_scope that handles a single member
15814 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15815 struct field_info
*fi
,
15816 std::vector
<struct symbol
*> *template_args
,
15817 struct dwarf2_cu
*cu
)
15819 if (child_die
->tag
== DW_TAG_member
15820 || child_die
->tag
== DW_TAG_variable
)
15822 /* NOTE: carlton/2002-11-05: A C++ static data member
15823 should be a DW_TAG_member that is a declaration, but
15824 all versions of G++ as of this writing (so through at
15825 least 3.2.1) incorrectly generate DW_TAG_variable
15826 tags for them instead. */
15827 dwarf2_add_field (fi
, child_die
, cu
);
15829 else if (child_die
->tag
== DW_TAG_subprogram
)
15831 /* Rust doesn't have member functions in the C++ sense.
15832 However, it does emit ordinary functions as children
15833 of a struct DIE. */
15834 if (cu
->per_cu
->lang
== language_rust
)
15835 read_func_scope (child_die
, cu
);
15838 /* C++ member function. */
15839 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15842 else if (child_die
->tag
== DW_TAG_inheritance
)
15844 /* C++ base class field. */
15845 dwarf2_add_field (fi
, child_die
, cu
);
15847 else if (type_can_define_types (child_die
))
15848 dwarf2_add_type_defn (fi
, child_die
, cu
);
15849 else if (child_die
->tag
== DW_TAG_template_type_param
15850 || child_die
->tag
== DW_TAG_template_value_param
)
15852 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15855 template_args
->push_back (arg
);
15857 else if (child_die
->tag
== DW_TAG_variant_part
)
15858 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15859 else if (child_die
->tag
== DW_TAG_variant
)
15860 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15863 /* Finish creating a structure or union type, including filling in
15864 its members and creating a symbol for it. */
15867 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15869 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15870 struct die_info
*child_die
;
15873 type
= get_die_type (die
, cu
);
15875 type
= read_structure_type (die
, cu
);
15877 bool has_template_parameters
= false;
15878 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15880 struct field_info fi
;
15881 std::vector
<struct symbol
*> template_args
;
15883 child_die
= die
->child
;
15885 while (child_die
&& child_die
->tag
)
15887 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15888 child_die
= child_die
->sibling
;
15891 /* Attach template arguments to type. */
15892 if (!template_args
.empty ())
15894 has_template_parameters
= true;
15895 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15896 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15897 TYPE_TEMPLATE_ARGUMENTS (type
)
15898 = XOBNEWVEC (&objfile
->objfile_obstack
,
15900 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15901 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15902 template_args
.data (),
15903 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15904 * sizeof (struct symbol
*)));
15907 /* Attach fields and member functions to the type. */
15908 if (fi
.nfields () > 0)
15909 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15910 if (!fi
.fnfieldlists
.empty ())
15912 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15914 /* Get the type which refers to the base class (possibly this
15915 class itself) which contains the vtable pointer for the current
15916 class from the DW_AT_containing_type attribute. This use of
15917 DW_AT_containing_type is a GNU extension. */
15919 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15921 struct type
*t
= die_containing_type (die
, cu
);
15923 set_type_vptr_basetype (type
, t
);
15928 /* Our own class provides vtbl ptr. */
15929 for (i
= t
->num_fields () - 1;
15930 i
>= TYPE_N_BASECLASSES (t
);
15933 const char *fieldname
= t
->field (i
).name ();
15935 if (is_vtable_name (fieldname
, cu
))
15937 set_type_vptr_fieldno (type
, i
);
15942 /* Complain if virtual function table field not found. */
15943 if (i
< TYPE_N_BASECLASSES (t
))
15944 complaint (_("virtual function table pointer "
15945 "not found when defining class '%s'"),
15946 type
->name () ? type
->name () : "");
15950 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15953 else if (cu
->producer
15954 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15956 /* The IBM XLC compiler does not provide direct indication
15957 of the containing type, but the vtable pointer is
15958 always named __vfp. */
15962 for (i
= type
->num_fields () - 1;
15963 i
>= TYPE_N_BASECLASSES (type
);
15966 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
15968 set_type_vptr_fieldno (type
, i
);
15969 set_type_vptr_basetype (type
, type
);
15976 /* Copy fi.typedef_field_list linked list elements content into the
15977 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15978 if (!fi
.typedef_field_list
.empty ())
15980 int count
= fi
.typedef_field_list
.size ();
15982 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15983 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15984 = ((struct decl_field
*)
15986 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15987 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15989 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15990 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15993 /* Copy fi.nested_types_list linked list elements content into the
15994 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15995 if (!fi
.nested_types_list
.empty ()
15996 && cu
->per_cu
->lang
!= language_ada
)
15998 int count
= fi
.nested_types_list
.size ();
16000 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16001 TYPE_NESTED_TYPES_ARRAY (type
)
16002 = ((struct decl_field
*)
16003 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16004 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16006 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16007 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16011 quirk_gcc_member_function_pointer (type
, objfile
);
16012 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16013 cu
->rust_unions
.push_back (type
);
16014 else if (cu
->per_cu
->lang
== language_ada
)
16015 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16017 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16018 snapshots) has been known to create a die giving a declaration
16019 for a class that has, as a child, a die giving a definition for a
16020 nested class. So we have to process our children even if the
16021 current die is a declaration. Normally, of course, a declaration
16022 won't have any children at all. */
16024 child_die
= die
->child
;
16026 while (child_die
!= NULL
&& child_die
->tag
)
16028 if (child_die
->tag
== DW_TAG_member
16029 || child_die
->tag
== DW_TAG_variable
16030 || child_die
->tag
== DW_TAG_inheritance
16031 || child_die
->tag
== DW_TAG_template_value_param
16032 || child_die
->tag
== DW_TAG_template_type_param
)
16037 process_die (child_die
, cu
);
16039 child_die
= child_die
->sibling
;
16042 /* Do not consider external references. According to the DWARF standard,
16043 these DIEs are identified by the fact that they have no byte_size
16044 attribute, and a declaration attribute. */
16045 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16046 || !die_is_declaration (die
, cu
)
16047 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16049 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16051 if (has_template_parameters
)
16053 struct symtab
*symtab
;
16054 if (sym
!= nullptr)
16055 symtab
= symbol_symtab (sym
);
16056 else if (cu
->line_header
!= nullptr)
16058 /* Any related symtab will do. */
16060 = cu
->line_header
->file_names ()[0].symtab
;
16065 complaint (_("could not find suitable "
16066 "symtab for template parameter"
16067 " - DIE at %s [in module %s]"),
16068 sect_offset_str (die
->sect_off
),
16069 objfile_name (objfile
));
16072 if (symtab
!= nullptr)
16074 /* Make sure that the symtab is set on the new symbols.
16075 Even though they don't appear in this symtab directly,
16076 other parts of gdb assume that symbols do, and this is
16077 reasonably true. */
16078 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16079 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16085 /* Assuming DIE is an enumeration type, and TYPE is its associated
16086 type, update TYPE using some information only available in DIE's
16087 children. In particular, the fields are computed. */
16090 update_enumeration_type_from_children (struct die_info
*die
,
16092 struct dwarf2_cu
*cu
)
16094 struct die_info
*child_die
;
16095 int unsigned_enum
= 1;
16098 auto_obstack obstack
;
16099 std::vector
<struct field
> fields
;
16101 for (child_die
= die
->child
;
16102 child_die
!= NULL
&& child_die
->tag
;
16103 child_die
= child_die
->sibling
)
16105 struct attribute
*attr
;
16107 const gdb_byte
*bytes
;
16108 struct dwarf2_locexpr_baton
*baton
;
16111 if (child_die
->tag
!= DW_TAG_enumerator
)
16114 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16118 name
= dwarf2_name (child_die
, cu
);
16120 name
= "<anonymous enumerator>";
16122 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16123 &value
, &bytes
, &baton
);
16131 if (count_one_bits_ll (value
) >= 2)
16135 fields
.emplace_back ();
16136 struct field
&field
= fields
.back ();
16137 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
16138 field
.set_loc_enumval (value
);
16141 if (!fields
.empty ())
16143 type
->set_num_fields (fields
.size ());
16146 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16147 memcpy (type
->fields (), fields
.data (),
16148 sizeof (struct field
) * fields
.size ());
16152 type
->set_is_unsigned (true);
16155 type
->set_is_flag_enum (true);
16158 /* Given a DW_AT_enumeration_type die, set its type. We do not
16159 complete the type's fields yet, or create any symbols. */
16161 static struct type
*
16162 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16164 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16166 struct attribute
*attr
;
16169 /* If the definition of this type lives in .debug_types, read that type.
16170 Don't follow DW_AT_specification though, that will take us back up
16171 the chain and we want to go down. */
16172 attr
= die
->attr (DW_AT_signature
);
16173 if (attr
!= nullptr)
16175 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16177 /* The type's CU may not be the same as CU.
16178 Ensure TYPE is recorded with CU in die_type_hash. */
16179 return set_die_type (die
, type
, cu
);
16182 type
= alloc_type (objfile
);
16184 type
->set_code (TYPE_CODE_ENUM
);
16185 name
= dwarf2_full_name (NULL
, die
, cu
);
16187 type
->set_name (name
);
16189 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16192 struct type
*underlying_type
= die_type (die
, cu
);
16194 TYPE_TARGET_TYPE (type
) = underlying_type
;
16197 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16198 if (attr
!= nullptr)
16200 TYPE_LENGTH (type
) = attr
->constant_value (0);
16204 TYPE_LENGTH (type
) = 0;
16207 maybe_set_alignment (cu
, die
, type
);
16209 /* The enumeration DIE can be incomplete. In Ada, any type can be
16210 declared as private in the package spec, and then defined only
16211 inside the package body. Such types are known as Taft Amendment
16212 Types. When another package uses such a type, an incomplete DIE
16213 may be generated by the compiler. */
16214 if (die_is_declaration (die
, cu
))
16215 type
->set_is_stub (true);
16217 /* If this type has an underlying type that is not a stub, then we
16218 may use its attributes. We always use the "unsigned" attribute
16219 in this situation, because ordinarily we guess whether the type
16220 is unsigned -- but the guess can be wrong and the underlying type
16221 can tell us the reality. However, we defer to a local size
16222 attribute if one exists, because this lets the compiler override
16223 the underlying type if needed. */
16224 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16226 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16227 underlying_type
= check_typedef (underlying_type
);
16229 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16231 if (TYPE_LENGTH (type
) == 0)
16232 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16234 if (TYPE_RAW_ALIGN (type
) == 0
16235 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16236 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16239 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16241 set_die_type (die
, type
, cu
);
16243 /* Finish the creation of this type by using the enum's children.
16244 Note that, as usual, this must come after set_die_type to avoid
16245 infinite recursion when trying to compute the names of the
16247 update_enumeration_type_from_children (die
, type
, cu
);
16252 /* Given a pointer to a die which begins an enumeration, process all
16253 the dies that define the members of the enumeration, and create the
16254 symbol for the enumeration type.
16256 NOTE: We reverse the order of the element list. */
16259 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16261 struct type
*this_type
;
16263 this_type
= get_die_type (die
, cu
);
16264 if (this_type
== NULL
)
16265 this_type
= read_enumeration_type (die
, cu
);
16267 if (die
->child
!= NULL
)
16269 struct die_info
*child_die
;
16272 child_die
= die
->child
;
16273 while (child_die
&& child_die
->tag
)
16275 if (child_die
->tag
!= DW_TAG_enumerator
)
16277 process_die (child_die
, cu
);
16281 name
= dwarf2_name (child_die
, cu
);
16283 new_symbol (child_die
, this_type
, cu
);
16286 child_die
= child_die
->sibling
;
16290 /* If we are reading an enum from a .debug_types unit, and the enum
16291 is a declaration, and the enum is not the signatured type in the
16292 unit, then we do not want to add a symbol for it. Adding a
16293 symbol would in some cases obscure the true definition of the
16294 enum, giving users an incomplete type when the definition is
16295 actually available. Note that we do not want to do this for all
16296 enums which are just declarations, because C++0x allows forward
16297 enum declarations. */
16298 if (cu
->per_cu
->is_debug_types
16299 && die_is_declaration (die
, cu
))
16301 struct signatured_type
*sig_type
;
16303 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16304 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16305 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16309 new_symbol (die
, this_type
, cu
);
16312 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16313 expression for an index type and finds the corresponding field
16314 offset in the hidden "P_BOUNDS" structure. Returns true on success
16315 and updates *FIELD, false if it fails to recognize an
16319 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16320 int *bounds_offset
, struct field
*field
,
16321 struct dwarf2_cu
*cu
)
16323 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16324 if (attr
== nullptr || !attr
->form_is_block ())
16327 const struct dwarf_block
*block
= attr
->as_block ();
16328 const gdb_byte
*start
= block
->data
;
16329 const gdb_byte
*end
= block
->data
+ block
->size
;
16331 /* The expression to recognize generally looks like:
16333 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16334 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16336 However, the second "plus_uconst" may be missing:
16338 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16339 DW_OP_deref_size: 4)
16341 This happens when the field is at the start of the structure.
16343 Also, the final deref may not be sized:
16345 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16348 This happens when the size of the index type happens to be the
16349 same as the architecture's word size. This can occur with or
16350 without the second plus_uconst. */
16352 if (end
- start
< 2)
16354 if (*start
++ != DW_OP_push_object_address
)
16356 if (*start
++ != DW_OP_plus_uconst
)
16359 uint64_t this_bound_off
;
16360 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16361 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16363 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16364 is consistent among all bounds. */
16365 if (*bounds_offset
== -1)
16366 *bounds_offset
= this_bound_off
;
16367 else if (*bounds_offset
!= this_bound_off
)
16370 if (start
== end
|| *start
++ != DW_OP_deref
)
16376 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16378 /* This means an offset of 0. */
16380 else if (*start
++ != DW_OP_plus_uconst
)
16384 /* The size is the parameter to DW_OP_plus_uconst. */
16386 start
= gdb_read_uleb128 (start
, end
, &val
);
16387 if (start
== nullptr)
16389 if ((int) val
!= val
)
16398 if (*start
== DW_OP_deref_size
)
16400 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16401 if (start
== nullptr)
16404 else if (*start
== DW_OP_deref
)
16406 size
= cu
->header
.addr_size
;
16412 field
->set_loc_bitpos (8 * offset
);
16413 if (size
!= TYPE_LENGTH (field
->type ()))
16414 FIELD_BITSIZE (*field
) = 8 * size
;
16419 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16420 some kinds of Ada arrays:
16422 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16423 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16424 <11e0> DW_AT_data_location: 2 byte block: 97 6
16425 (DW_OP_push_object_address; DW_OP_deref)
16426 <11e3> DW_AT_type : <0x1173>
16427 <11e7> DW_AT_sibling : <0x1201>
16428 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16429 <11ec> DW_AT_type : <0x1206>
16430 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16431 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16432 DW_OP_deref_size: 4)
16433 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16434 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16435 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16437 This actually represents a "thick pointer", which is a structure
16438 with two elements: one that is a pointer to the array data, and one
16439 that is a pointer to another structure; this second structure holds
16442 This returns a new type on success, or nullptr if this didn't
16443 recognize the type. */
16445 static struct type
*
16446 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16449 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16450 /* So far we've only seen this with block form. */
16451 if (attr
== nullptr || !attr
->form_is_block ())
16454 /* Note that this will fail if the structure layout is changed by
16455 the compiler. However, we have no good way to recognize some
16456 other layout, because we don't know what expression the compiler
16457 might choose to emit should this happen. */
16458 struct dwarf_block
*blk
= attr
->as_block ();
16460 || blk
->data
[0] != DW_OP_push_object_address
16461 || blk
->data
[1] != DW_OP_deref
)
16464 int bounds_offset
= -1;
16465 int max_align
= -1;
16466 std::vector
<struct field
> range_fields
;
16467 for (struct die_info
*child_die
= die
->child
;
16469 child_die
= child_die
->sibling
)
16471 if (child_die
->tag
== DW_TAG_subrange_type
)
16473 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16475 int this_align
= type_align (underlying
);
16476 if (this_align
> max_align
)
16477 max_align
= this_align
;
16479 range_fields
.emplace_back ();
16480 range_fields
.emplace_back ();
16482 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16483 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16485 lower
.set_type (underlying
);
16486 FIELD_ARTIFICIAL (lower
) = 1;
16488 upper
.set_type (underlying
);
16489 FIELD_ARTIFICIAL (upper
) = 1;
16491 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16492 &bounds_offset
, &lower
, cu
)
16493 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16494 &bounds_offset
, &upper
, cu
))
16499 /* This shouldn't really happen, but double-check that we found
16500 where the bounds are stored. */
16501 if (bounds_offset
== -1)
16504 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16505 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16509 /* Set the name of each field in the bounds. */
16510 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16511 range_fields
[i
].set_name (objfile
->intern (name
));
16512 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16513 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
16516 struct type
*bounds
= alloc_type (objfile
);
16517 bounds
->set_code (TYPE_CODE_STRUCT
);
16519 bounds
->set_num_fields (range_fields
.size ());
16521 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16522 * sizeof (struct field
))));
16523 memcpy (bounds
->fields (), range_fields
.data (),
16524 bounds
->num_fields () * sizeof (struct field
));
16526 int last_fieldno
= range_fields
.size () - 1;
16527 int bounds_size
= (bounds
->field (last_fieldno
).loc_bitpos () / 8
16528 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16529 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16531 /* Rewrite the existing array type in place. Specifically, we
16532 remove any dynamic properties we might have read, and we replace
16533 the index types. */
16534 struct type
*iter
= type
;
16535 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16537 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16538 iter
->main_type
->dyn_prop_list
= nullptr;
16539 iter
->set_index_type
16540 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16541 iter
= TYPE_TARGET_TYPE (iter
);
16544 struct type
*result
= alloc_type (objfile
);
16545 result
->set_code (TYPE_CODE_STRUCT
);
16547 result
->set_num_fields (2);
16549 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16550 * sizeof (struct field
))));
16552 /* The names are chosen to coincide with what the compiler does with
16553 -fgnat-encodings=all, which the Ada code in gdb already
16555 result
->field (0).set_name ("P_ARRAY");
16556 result
->field (0).set_type (lookup_pointer_type (type
));
16558 result
->field (1).set_name ("P_BOUNDS");
16559 result
->field (1).set_type (lookup_pointer_type (bounds
));
16560 result
->field (1).set_loc_bitpos (8 * bounds_offset
);
16562 result
->set_name (type
->name ());
16563 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16564 + TYPE_LENGTH (result
->field (1).type ()));
16569 /* Extract all information from a DW_TAG_array_type DIE and put it in
16570 the DIE's type field. For now, this only handles one dimensional
16573 static struct type
*
16574 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16576 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16577 struct die_info
*child_die
;
16579 struct type
*element_type
, *range_type
, *index_type
;
16580 struct attribute
*attr
;
16582 struct dynamic_prop
*byte_stride_prop
= NULL
;
16583 unsigned int bit_stride
= 0;
16585 element_type
= die_type (die
, cu
);
16587 /* The die_type call above may have already set the type for this DIE. */
16588 type
= get_die_type (die
, cu
);
16592 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16596 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16599 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16600 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16604 complaint (_("unable to read array DW_AT_byte_stride "
16605 " - DIE at %s [in module %s]"),
16606 sect_offset_str (die
->sect_off
),
16607 objfile_name (cu
->per_objfile
->objfile
));
16608 /* Ignore this attribute. We will likely not be able to print
16609 arrays of this type correctly, but there is little we can do
16610 to help if we cannot read the attribute's value. */
16611 byte_stride_prop
= NULL
;
16615 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16617 bit_stride
= attr
->constant_value (0);
16619 /* Irix 6.2 native cc creates array types without children for
16620 arrays with unspecified length. */
16621 if (die
->child
== NULL
)
16623 index_type
= objfile_type (objfile
)->builtin_int
;
16624 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16625 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16626 byte_stride_prop
, bit_stride
);
16627 return set_die_type (die
, type
, cu
);
16630 std::vector
<struct type
*> range_types
;
16631 child_die
= die
->child
;
16632 while (child_die
&& child_die
->tag
)
16634 if (child_die
->tag
== DW_TAG_subrange_type
)
16636 struct type
*child_type
= read_type_die (child_die
, cu
);
16638 if (child_type
!= NULL
)
16640 /* The range type was succesfully read. Save it for the
16641 array type creation. */
16642 range_types
.push_back (child_type
);
16645 child_die
= child_die
->sibling
;
16648 if (range_types
.empty ())
16650 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16651 sect_offset_str (die
->sect_off
),
16652 objfile_name (cu
->per_objfile
->objfile
));
16656 /* Dwarf2 dimensions are output from left to right, create the
16657 necessary array types in backwards order. */
16659 type
= element_type
;
16661 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16665 while (i
< range_types
.size ())
16667 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16668 byte_stride_prop
, bit_stride
);
16670 byte_stride_prop
= nullptr;
16675 size_t ndim
= range_types
.size ();
16678 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16679 byte_stride_prop
, bit_stride
);
16681 byte_stride_prop
= nullptr;
16685 gdb_assert (type
!= element_type
);
16687 /* Understand Dwarf2 support for vector types (like they occur on
16688 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16689 array type. This is not part of the Dwarf2/3 standard yet, but a
16690 custom vendor extension. The main difference between a regular
16691 array and the vector variant is that vectors are passed by value
16693 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16694 if (attr
!= nullptr)
16695 make_vector_type (type
);
16697 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16698 implementation may choose to implement triple vectors using this
16700 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16701 if (attr
!= nullptr && attr
->form_is_unsigned ())
16703 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16704 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16706 complaint (_("DW_AT_byte_size for array type smaller "
16707 "than the total size of elements"));
16710 name
= dwarf2_name (die
, cu
);
16712 type
->set_name (name
);
16714 maybe_set_alignment (cu
, die
, type
);
16716 struct type
*replacement_type
= nullptr;
16717 if (cu
->per_cu
->lang
== language_ada
)
16719 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16720 if (replacement_type
!= nullptr)
16721 type
= replacement_type
;
16724 /* Install the type in the die. */
16725 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16727 /* set_die_type should be already done. */
16728 set_descriptive_type (type
, die
, cu
);
16733 static enum dwarf_array_dim_ordering
16734 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16736 struct attribute
*attr
;
16738 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16740 if (attr
!= nullptr)
16742 LONGEST val
= attr
->constant_value (-1);
16743 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16744 return (enum dwarf_array_dim_ordering
) val
;
16747 /* GNU F77 is a special case, as at 08/2004 array type info is the
16748 opposite order to the dwarf2 specification, but data is still
16749 laid out as per normal fortran.
16751 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16752 version checking. */
16754 if (cu
->per_cu
->lang
== language_fortran
16755 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16757 return DW_ORD_row_major
;
16760 switch (cu
->language_defn
->array_ordering ())
16762 case array_column_major
:
16763 return DW_ORD_col_major
;
16764 case array_row_major
:
16766 return DW_ORD_row_major
;
16770 /* Extract all information from a DW_TAG_set_type DIE and put it in
16771 the DIE's type field. */
16773 static struct type
*
16774 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16776 struct type
*domain_type
, *set_type
;
16777 struct attribute
*attr
;
16779 domain_type
= die_type (die
, cu
);
16781 /* The die_type call above may have already set the type for this DIE. */
16782 set_type
= get_die_type (die
, cu
);
16786 set_type
= create_set_type (NULL
, domain_type
);
16788 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16789 if (attr
!= nullptr && attr
->form_is_unsigned ())
16790 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16792 maybe_set_alignment (cu
, die
, set_type
);
16794 return set_die_type (die
, set_type
, cu
);
16797 /* A helper for read_common_block that creates a locexpr baton.
16798 SYM is the symbol which we are marking as computed.
16799 COMMON_DIE is the DIE for the common block.
16800 COMMON_LOC is the location expression attribute for the common
16802 MEMBER_LOC is the location expression attribute for the particular
16803 member of the common block that we are processing.
16804 CU is the CU from which the above come. */
16807 mark_common_block_symbol_computed (struct symbol
*sym
,
16808 struct die_info
*common_die
,
16809 struct attribute
*common_loc
,
16810 struct attribute
*member_loc
,
16811 struct dwarf2_cu
*cu
)
16813 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16814 struct objfile
*objfile
= per_objfile
->objfile
;
16815 struct dwarf2_locexpr_baton
*baton
;
16817 unsigned int cu_off
;
16818 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16819 LONGEST offset
= 0;
16821 gdb_assert (common_loc
&& member_loc
);
16822 gdb_assert (common_loc
->form_is_block ());
16823 gdb_assert (member_loc
->form_is_block ()
16824 || member_loc
->form_is_constant ());
16826 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16827 baton
->per_objfile
= per_objfile
;
16828 baton
->per_cu
= cu
->per_cu
;
16829 gdb_assert (baton
->per_cu
);
16831 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16833 if (member_loc
->form_is_constant ())
16835 offset
= member_loc
->constant_value (0);
16836 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16839 baton
->size
+= member_loc
->as_block ()->size
;
16841 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16844 *ptr
++ = DW_OP_call4
;
16845 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16846 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16849 if (member_loc
->form_is_constant ())
16851 *ptr
++ = DW_OP_addr
;
16852 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16853 ptr
+= cu
->header
.addr_size
;
16857 /* We have to copy the data here, because DW_OP_call4 will only
16858 use a DW_AT_location attribute. */
16859 struct dwarf_block
*block
= member_loc
->as_block ();
16860 memcpy (ptr
, block
->data
, block
->size
);
16861 ptr
+= block
->size
;
16864 *ptr
++ = DW_OP_plus
;
16865 gdb_assert (ptr
- baton
->data
== baton
->size
);
16867 SYMBOL_LOCATION_BATON (sym
) = baton
;
16868 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16871 /* Create appropriate locally-scoped variables for all the
16872 DW_TAG_common_block entries. Also create a struct common_block
16873 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16874 is used to separate the common blocks name namespace from regular
16878 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16880 struct attribute
*attr
;
16882 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16883 if (attr
!= nullptr)
16885 /* Support the .debug_loc offsets. */
16886 if (attr
->form_is_block ())
16890 else if (attr
->form_is_section_offset ())
16892 dwarf2_complex_location_expr_complaint ();
16897 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16898 "common block member");
16903 if (die
->child
!= NULL
)
16905 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16906 struct die_info
*child_die
;
16907 size_t n_entries
= 0, size
;
16908 struct common_block
*common_block
;
16909 struct symbol
*sym
;
16911 for (child_die
= die
->child
;
16912 child_die
&& child_die
->tag
;
16913 child_die
= child_die
->sibling
)
16916 size
= (sizeof (struct common_block
)
16917 + (n_entries
- 1) * sizeof (struct symbol
*));
16919 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16921 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16922 common_block
->n_entries
= 0;
16924 for (child_die
= die
->child
;
16925 child_die
&& child_die
->tag
;
16926 child_die
= child_die
->sibling
)
16928 /* Create the symbol in the DW_TAG_common_block block in the current
16930 sym
= new_symbol (child_die
, NULL
, cu
);
16933 struct attribute
*member_loc
;
16935 common_block
->contents
[common_block
->n_entries
++] = sym
;
16937 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16941 /* GDB has handled this for a long time, but it is
16942 not specified by DWARF. It seems to have been
16943 emitted by gfortran at least as recently as:
16944 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16945 complaint (_("Variable in common block has "
16946 "DW_AT_data_member_location "
16947 "- DIE at %s [in module %s]"),
16948 sect_offset_str (child_die
->sect_off
),
16949 objfile_name (objfile
));
16951 if (member_loc
->form_is_section_offset ())
16952 dwarf2_complex_location_expr_complaint ();
16953 else if (member_loc
->form_is_constant ()
16954 || member_loc
->form_is_block ())
16956 if (attr
!= nullptr)
16957 mark_common_block_symbol_computed (sym
, die
, attr
,
16961 dwarf2_complex_location_expr_complaint ();
16966 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16967 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16971 /* Create a type for a C++ namespace. */
16973 static struct type
*
16974 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16976 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16977 const char *previous_prefix
, *name
;
16981 /* For extensions, reuse the type of the original namespace. */
16982 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16984 struct die_info
*ext_die
;
16985 struct dwarf2_cu
*ext_cu
= cu
;
16987 ext_die
= dwarf2_extension (die
, &ext_cu
);
16988 type
= read_type_die (ext_die
, ext_cu
);
16990 /* EXT_CU may not be the same as CU.
16991 Ensure TYPE is recorded with CU in die_type_hash. */
16992 return set_die_type (die
, type
, cu
);
16995 name
= namespace_name (die
, &is_anonymous
, cu
);
16997 /* Now build the name of the current namespace. */
16999 previous_prefix
= determine_prefix (die
, cu
);
17000 if (previous_prefix
[0] != '\0')
17001 name
= typename_concat (&objfile
->objfile_obstack
,
17002 previous_prefix
, name
, 0, cu
);
17004 /* Create the type. */
17005 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17007 return set_die_type (die
, type
, cu
);
17010 /* Read a namespace scope. */
17013 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17015 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17018 /* Add a symbol associated to this if we haven't seen the namespace
17019 before. Also, add a using directive if it's an anonymous
17022 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17026 type
= read_type_die (die
, cu
);
17027 new_symbol (die
, type
, cu
);
17029 namespace_name (die
, &is_anonymous
, cu
);
17032 const char *previous_prefix
= determine_prefix (die
, cu
);
17034 std::vector
<const char *> excludes
;
17035 add_using_directive (using_directives (cu
),
17036 previous_prefix
, type
->name (), NULL
,
17037 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17041 if (die
->child
!= NULL
)
17043 struct die_info
*child_die
= die
->child
;
17045 while (child_die
&& child_die
->tag
)
17047 process_die (child_die
, cu
);
17048 child_die
= child_die
->sibling
;
17053 /* Read a Fortran module as type. This DIE can be only a declaration used for
17054 imported module. Still we need that type as local Fortran "use ... only"
17055 declaration imports depend on the created type in determine_prefix. */
17057 static struct type
*
17058 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17060 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17061 const char *module_name
;
17064 module_name
= dwarf2_name (die
, cu
);
17065 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17067 return set_die_type (die
, type
, cu
);
17070 /* Read a Fortran module. */
17073 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17075 struct die_info
*child_die
= die
->child
;
17078 type
= read_type_die (die
, cu
);
17079 new_symbol (die
, type
, cu
);
17081 while (child_die
&& child_die
->tag
)
17083 process_die (child_die
, cu
);
17084 child_die
= child_die
->sibling
;
17088 /* Return the name of the namespace represented by DIE. Set
17089 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17092 static const char *
17093 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17095 struct die_info
*current_die
;
17096 const char *name
= NULL
;
17098 /* Loop through the extensions until we find a name. */
17100 for (current_die
= die
;
17101 current_die
!= NULL
;
17102 current_die
= dwarf2_extension (die
, &cu
))
17104 /* We don't use dwarf2_name here so that we can detect the absence
17105 of a name -> anonymous namespace. */
17106 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17112 /* Is it an anonymous namespace? */
17114 *is_anonymous
= (name
== NULL
);
17116 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17121 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17122 the user defined type vector. */
17124 static struct type
*
17125 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17127 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17128 struct comp_unit_head
*cu_header
= &cu
->header
;
17130 struct attribute
*attr_byte_size
;
17131 struct attribute
*attr_address_class
;
17132 int byte_size
, addr_class
;
17133 struct type
*target_type
;
17135 target_type
= die_type (die
, cu
);
17137 /* The die_type call above may have already set the type for this DIE. */
17138 type
= get_die_type (die
, cu
);
17142 type
= lookup_pointer_type (target_type
);
17144 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17145 if (attr_byte_size
)
17146 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17148 byte_size
= cu_header
->addr_size
;
17150 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17151 if (attr_address_class
)
17152 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17154 addr_class
= DW_ADDR_none
;
17156 ULONGEST alignment
= get_alignment (cu
, die
);
17158 /* If the pointer size, alignment, or address class is different
17159 than the default, create a type variant marked as such and set
17160 the length accordingly. */
17161 if (TYPE_LENGTH (type
) != byte_size
17162 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17163 && alignment
!= TYPE_RAW_ALIGN (type
))
17164 || addr_class
!= DW_ADDR_none
)
17166 if (gdbarch_address_class_type_flags_p (gdbarch
))
17168 type_instance_flags type_flags
17169 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17171 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17173 type
= make_type_with_address_space (type
, type_flags
);
17175 else if (TYPE_LENGTH (type
) != byte_size
)
17177 complaint (_("invalid pointer size %d"), byte_size
);
17179 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17181 complaint (_("Invalid DW_AT_alignment"
17182 " - DIE at %s [in module %s]"),
17183 sect_offset_str (die
->sect_off
),
17184 objfile_name (cu
->per_objfile
->objfile
));
17188 /* Should we also complain about unhandled address classes? */
17192 TYPE_LENGTH (type
) = byte_size
;
17193 set_type_align (type
, alignment
);
17194 return set_die_type (die
, type
, cu
);
17197 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17198 the user defined type vector. */
17200 static struct type
*
17201 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17204 struct type
*to_type
;
17205 struct type
*domain
;
17207 to_type
= die_type (die
, cu
);
17208 domain
= die_containing_type (die
, cu
);
17210 /* The calls above may have already set the type for this DIE. */
17211 type
= get_die_type (die
, cu
);
17215 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17216 type
= lookup_methodptr_type (to_type
);
17217 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17219 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17221 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17222 to_type
->fields (), to_type
->num_fields (),
17223 to_type
->has_varargs ());
17224 type
= lookup_methodptr_type (new_type
);
17227 type
= lookup_memberptr_type (to_type
, domain
);
17229 return set_die_type (die
, type
, cu
);
17232 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17233 the user defined type vector. */
17235 static struct type
*
17236 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17237 enum type_code refcode
)
17239 struct comp_unit_head
*cu_header
= &cu
->header
;
17240 struct type
*type
, *target_type
;
17241 struct attribute
*attr
;
17243 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17245 target_type
= die_type (die
, cu
);
17247 /* The die_type call above may have already set the type for this DIE. */
17248 type
= get_die_type (die
, cu
);
17252 type
= lookup_reference_type (target_type
, refcode
);
17253 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17254 if (attr
!= nullptr)
17256 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17260 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17262 maybe_set_alignment (cu
, die
, type
);
17263 return set_die_type (die
, type
, cu
);
17266 /* Add the given cv-qualifiers to the element type of the array. GCC
17267 outputs DWARF type qualifiers that apply to an array, not the
17268 element type. But GDB relies on the array element type to carry
17269 the cv-qualifiers. This mimics section 6.7.3 of the C99
17272 static struct type
*
17273 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17274 struct type
*base_type
, int cnst
, int voltl
)
17276 struct type
*el_type
, *inner_array
;
17278 base_type
= copy_type (base_type
);
17279 inner_array
= base_type
;
17281 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17283 TYPE_TARGET_TYPE (inner_array
) =
17284 copy_type (TYPE_TARGET_TYPE (inner_array
));
17285 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17288 el_type
= TYPE_TARGET_TYPE (inner_array
);
17289 cnst
|= TYPE_CONST (el_type
);
17290 voltl
|= TYPE_VOLATILE (el_type
);
17291 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17293 return set_die_type (die
, base_type
, cu
);
17296 static struct type
*
17297 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17299 struct type
*base_type
, *cv_type
;
17301 base_type
= die_type (die
, cu
);
17303 /* The die_type call above may have already set the type for this DIE. */
17304 cv_type
= get_die_type (die
, cu
);
17308 /* In case the const qualifier is applied to an array type, the element type
17309 is so qualified, not the array type (section 6.7.3 of C99). */
17310 if (base_type
->code () == TYPE_CODE_ARRAY
)
17311 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17313 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17314 return set_die_type (die
, cv_type
, cu
);
17317 static struct type
*
17318 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17320 struct type
*base_type
, *cv_type
;
17322 base_type
= die_type (die
, cu
);
17324 /* The die_type call above may have already set the type for this DIE. */
17325 cv_type
= get_die_type (die
, cu
);
17329 /* In case the volatile qualifier is applied to an array type, the
17330 element type is so qualified, not the array type (section 6.7.3
17332 if (base_type
->code () == TYPE_CODE_ARRAY
)
17333 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17335 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17336 return set_die_type (die
, cv_type
, cu
);
17339 /* Handle DW_TAG_restrict_type. */
17341 static struct type
*
17342 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17344 struct type
*base_type
, *cv_type
;
17346 base_type
= die_type (die
, cu
);
17348 /* The die_type call above may have already set the type for this DIE. */
17349 cv_type
= get_die_type (die
, cu
);
17353 cv_type
= make_restrict_type (base_type
);
17354 return set_die_type (die
, cv_type
, cu
);
17357 /* Handle DW_TAG_atomic_type. */
17359 static struct type
*
17360 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17362 struct type
*base_type
, *cv_type
;
17364 base_type
= die_type (die
, cu
);
17366 /* The die_type call above may have already set the type for this DIE. */
17367 cv_type
= get_die_type (die
, cu
);
17371 cv_type
= make_atomic_type (base_type
);
17372 return set_die_type (die
, cv_type
, cu
);
17375 /* Extract all information from a DW_TAG_string_type DIE and add to
17376 the user defined type vector. It isn't really a user defined type,
17377 but it behaves like one, with other DIE's using an AT_user_def_type
17378 attribute to reference it. */
17380 static struct type
*
17381 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17383 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17384 struct gdbarch
*gdbarch
= objfile
->arch ();
17385 struct type
*type
, *range_type
, *index_type
, *char_type
;
17386 struct attribute
*attr
;
17387 struct dynamic_prop prop
;
17388 bool length_is_constant
= true;
17391 /* There are a couple of places where bit sizes might be made use of
17392 when parsing a DW_TAG_string_type, however, no producer that we know
17393 of make use of these. Handling bit sizes that are a multiple of the
17394 byte size is easy enough, but what about other bit sizes? Lets deal
17395 with that problem when we have to. Warn about these attributes being
17396 unsupported, then parse the type and ignore them like we always
17398 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17399 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17401 static bool warning_printed
= false;
17402 if (!warning_printed
)
17404 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17405 "currently supported on DW_TAG_string_type."));
17406 warning_printed
= true;
17410 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17411 if (attr
!= nullptr && !attr
->form_is_constant ())
17413 /* The string length describes the location at which the length of
17414 the string can be found. The size of the length field can be
17415 specified with one of the attributes below. */
17416 struct type
*prop_type
;
17417 struct attribute
*len
17418 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17419 if (len
== nullptr)
17420 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17421 if (len
!= nullptr && len
->form_is_constant ())
17423 /* Pass 0 as the default as we know this attribute is constant
17424 and the default value will not be returned. */
17425 LONGEST sz
= len
->constant_value (0);
17426 prop_type
= objfile_int_type (objfile
, sz
, true);
17430 /* If the size is not specified then we assume it is the size of
17431 an address on this target. */
17432 prop_type
= cu
->addr_sized_int_type (true);
17435 /* Convert the attribute into a dynamic property. */
17436 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17439 length_is_constant
= false;
17441 else if (attr
!= nullptr)
17443 /* This DW_AT_string_length just contains the length with no
17444 indirection. There's no need to create a dynamic property in this
17445 case. Pass 0 for the default value as we know it will not be
17446 returned in this case. */
17447 length
= attr
->constant_value (0);
17449 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17451 /* We don't currently support non-constant byte sizes for strings. */
17452 length
= attr
->constant_value (1);
17456 /* Use 1 as a fallback length if we have nothing else. */
17460 index_type
= objfile_type (objfile
)->builtin_int
;
17461 if (length_is_constant
)
17462 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17465 struct dynamic_prop low_bound
;
17467 low_bound
.set_const_val (1);
17468 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17470 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17471 type
= create_string_type (NULL
, char_type
, range_type
);
17473 return set_die_type (die
, type
, cu
);
17476 /* Assuming that DIE corresponds to a function, returns nonzero
17477 if the function is prototyped. */
17480 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17482 struct attribute
*attr
;
17484 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17485 if (attr
&& attr
->as_boolean ())
17488 /* The DWARF standard implies that the DW_AT_prototyped attribute
17489 is only meaningful for C, but the concept also extends to other
17490 languages that allow unprototyped functions (Eg: Objective C).
17491 For all other languages, assume that functions are always
17493 if (cu
->per_cu
->lang
!= language_c
17494 && cu
->per_cu
->lang
!= language_objc
17495 && cu
->per_cu
->lang
!= language_opencl
)
17498 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17499 prototyped and unprototyped functions; default to prototyped,
17500 since that is more common in modern code (and RealView warns
17501 about unprototyped functions). */
17502 if (producer_is_realview (cu
->producer
))
17508 /* Handle DIES due to C code like:
17512 int (*funcp)(int a, long l);
17516 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17518 static struct type
*
17519 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17521 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17522 struct type
*type
; /* Type that this function returns. */
17523 struct type
*ftype
; /* Function that returns above type. */
17524 struct attribute
*attr
;
17526 type
= die_type (die
, cu
);
17528 /* The die_type call above may have already set the type for this DIE. */
17529 ftype
= get_die_type (die
, cu
);
17533 ftype
= lookup_function_type (type
);
17535 if (prototyped_function_p (die
, cu
))
17536 ftype
->set_is_prototyped (true);
17538 /* Store the calling convention in the type if it's available in
17539 the subroutine die. Otherwise set the calling convention to
17540 the default value DW_CC_normal. */
17541 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17542 if (attr
!= nullptr
17543 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17544 TYPE_CALLING_CONVENTION (ftype
)
17545 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17546 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17547 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17549 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17551 /* Record whether the function returns normally to its caller or not
17552 if the DWARF producer set that information. */
17553 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17554 if (attr
&& attr
->as_boolean ())
17555 TYPE_NO_RETURN (ftype
) = 1;
17557 /* We need to add the subroutine type to the die immediately so
17558 we don't infinitely recurse when dealing with parameters
17559 declared as the same subroutine type. */
17560 set_die_type (die
, ftype
, cu
);
17562 if (die
->child
!= NULL
)
17564 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17565 struct die_info
*child_die
;
17566 int nparams
, iparams
;
17568 /* Count the number of parameters.
17569 FIXME: GDB currently ignores vararg functions, but knows about
17570 vararg member functions. */
17572 child_die
= die
->child
;
17573 while (child_die
&& child_die
->tag
)
17575 if (child_die
->tag
== DW_TAG_formal_parameter
)
17577 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17578 ftype
->set_has_varargs (true);
17580 child_die
= child_die
->sibling
;
17583 /* Allocate storage for parameters and fill them in. */
17584 ftype
->set_num_fields (nparams
);
17586 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17588 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17589 even if we error out during the parameters reading below. */
17590 for (iparams
= 0; iparams
< nparams
; iparams
++)
17591 ftype
->field (iparams
).set_type (void_type
);
17594 child_die
= die
->child
;
17595 while (child_die
&& child_die
->tag
)
17597 if (child_die
->tag
== DW_TAG_formal_parameter
)
17599 struct type
*arg_type
;
17601 /* DWARF version 2 has no clean way to discern C++
17602 static and non-static member functions. G++ helps
17603 GDB by marking the first parameter for non-static
17604 member functions (which is the this pointer) as
17605 artificial. We pass this information to
17606 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17608 DWARF version 3 added DW_AT_object_pointer, which GCC
17609 4.5 does not yet generate. */
17610 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17611 if (attr
!= nullptr)
17612 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17614 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17615 arg_type
= die_type (child_die
, cu
);
17617 /* RealView does not mark THIS as const, which the testsuite
17618 expects. GCC marks THIS as const in method definitions,
17619 but not in the class specifications (GCC PR 43053). */
17620 if (cu
->per_cu
->lang
== language_cplus
17621 && !TYPE_CONST (arg_type
)
17622 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17625 struct dwarf2_cu
*arg_cu
= cu
;
17626 const char *name
= dwarf2_name (child_die
, cu
);
17628 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17629 if (attr
!= nullptr)
17631 /* If the compiler emits this, use it. */
17632 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17635 else if (name
&& strcmp (name
, "this") == 0)
17636 /* Function definitions will have the argument names. */
17638 else if (name
== NULL
&& iparams
== 0)
17639 /* Declarations may not have the names, so like
17640 elsewhere in GDB, assume an artificial first
17641 argument is "this". */
17645 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17649 ftype
->field (iparams
).set_type (arg_type
);
17652 child_die
= child_die
->sibling
;
17659 static struct type
*
17660 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17662 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17663 const char *name
= NULL
;
17664 struct type
*this_type
, *target_type
;
17666 name
= dwarf2_full_name (NULL
, die
, cu
);
17667 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17668 this_type
->set_target_is_stub (true);
17669 set_die_type (die
, this_type
, cu
);
17670 target_type
= die_type (die
, cu
);
17671 if (target_type
!= this_type
)
17672 TYPE_TARGET_TYPE (this_type
) = target_type
;
17675 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17676 spec and cause infinite loops in GDB. */
17677 complaint (_("Self-referential DW_TAG_typedef "
17678 "- DIE at %s [in module %s]"),
17679 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17680 TYPE_TARGET_TYPE (this_type
) = NULL
;
17684 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17685 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17686 Handle these by just returning the target type, rather than
17687 constructing an anonymous typedef type and trying to handle this
17689 set_die_type (die
, target_type
, cu
);
17690 return target_type
;
17695 /* Helper for get_dwarf2_rational_constant that computes the value of
17696 a given gmp_mpz given an attribute. */
17699 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17701 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17702 location expression that pushes an implicit value. */
17703 if (attr
->form
== DW_FORM_exprloc
)
17705 dwarf_block
*blk
= attr
->as_block ();
17706 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17709 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17710 blk
->data
+ blk
->size
,
17712 if (ptr
- blk
->data
+ len
<= blk
->size
)
17714 mpz_import (value
->val
, len
,
17715 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17721 /* On failure set it to 1. */
17722 *value
= gdb_mpz (1);
17724 else if (attr
->form_is_block ())
17726 dwarf_block
*blk
= attr
->as_block ();
17727 mpz_import (value
->val
, blk
->size
,
17728 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17729 1, 0, 0, blk
->data
);
17732 *value
= gdb_mpz (attr
->constant_value (1));
17735 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17736 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17738 If the numerator and/or numerator attribute is missing,
17739 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17743 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17744 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17746 struct attribute
*num_attr
, *denom_attr
;
17748 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17749 if (num_attr
== nullptr)
17750 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17751 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17753 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17754 if (denom_attr
== nullptr)
17755 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17756 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17758 if (num_attr
== nullptr || denom_attr
== nullptr)
17761 get_mpz (cu
, numerator
, num_attr
);
17762 get_mpz (cu
, denominator
, denom_attr
);
17765 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17766 rational constant, rather than a signed one.
17768 If the rational constant has a negative value, a complaint
17769 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17772 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17773 struct dwarf2_cu
*cu
,
17774 gdb_mpz
*numerator
,
17775 gdb_mpz
*denominator
)
17780 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17781 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17783 mpz_neg (num
.val
, num
.val
);
17784 mpz_neg (denom
.val
, denom
.val
);
17786 else if (mpz_sgn (num
.val
) == -1)
17788 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17790 sect_offset_str (die
->sect_off
));
17793 else if (mpz_sgn (denom
.val
) == -1)
17795 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17797 sect_offset_str (die
->sect_off
));
17801 *numerator
= std::move (num
);
17802 *denominator
= std::move (denom
);
17805 /* Assuming that ENCODING is a string whose contents starting at the
17806 K'th character is "_nn" where "nn" is a decimal number, scan that
17807 number and set RESULT to the value. K is updated to point to the
17808 character immediately following the number.
17810 If the string does not conform to the format described above, false
17811 is returned, and K may or may not be changed. */
17814 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17816 /* The next character should be an underscore ('_') followed
17818 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17821 /* Skip the underscore. */
17825 /* Determine the number of digits for our number. */
17826 while (isdigit (encoding
[k
]))
17831 std::string
copy (&encoding
[start
], k
- start
);
17832 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17838 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17839 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17840 DENOM, update OFFSET, and return true on success. Return false on
17844 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17845 gdb_mpz
*num
, gdb_mpz
*denom
)
17847 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17849 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17852 /* Assuming DIE corresponds to a fixed point type, finish the creation
17853 of the corresponding TYPE by setting its type-specific data. CU is
17854 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17855 encodings. It is nullptr if the GNAT encoding should be
17859 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17860 struct die_info
*die
, struct dwarf2_cu
*cu
)
17862 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17863 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17865 /* If GNAT encodings are preferred, don't examine the
17867 struct attribute
*attr
= nullptr;
17868 if (suffix
== nullptr)
17870 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17871 if (attr
== nullptr)
17872 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17873 if (attr
== nullptr)
17874 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17877 /* Numerator and denominator of our fixed-point type's scaling factor.
17878 The default is a scaling factor of 1, which we use as a fallback
17879 when we are not able to decode it (problem with the debugging info,
17880 unsupported forms, bug in GDB, etc...). Using that as the default
17881 allows us to at least print the unscaled value, which might still
17882 be useful to a user. */
17883 gdb_mpz
scale_num (1);
17884 gdb_mpz
scale_denom (1);
17886 if (attr
== nullptr)
17889 if (suffix
!= nullptr
17890 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17892 /* The number might be encoded as _nn_dd_nn_dd, where the
17893 second ratio is the 'small value. In this situation, we
17894 want the second value. */
17895 && (suffix
[offset
] != '_'
17896 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17903 /* Scaling factor not found. Assume a scaling factor of 1,
17904 and hope for the best. At least the user will be able to
17905 see the encoded value. */
17908 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17909 sect_offset_str (die
->sect_off
));
17912 else if (attr
->name
== DW_AT_binary_scale
)
17914 LONGEST scale_exp
= attr
->constant_value (0);
17915 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17917 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17919 else if (attr
->name
== DW_AT_decimal_scale
)
17921 LONGEST scale_exp
= attr
->constant_value (0);
17922 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17924 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17926 else if (attr
->name
== DW_AT_small
)
17928 struct die_info
*scale_die
;
17929 struct dwarf2_cu
*scale_cu
= cu
;
17931 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17932 if (scale_die
->tag
== DW_TAG_constant
)
17933 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17934 &scale_num
, &scale_denom
);
17936 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17938 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17942 complaint (_("unsupported scale attribute %s for fixed-point type"
17944 dwarf_attr_name (attr
->name
),
17945 sect_offset_str (die
->sect_off
));
17948 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17949 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17950 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17951 mpq_canonicalize (scaling_factor
.val
);
17954 /* The gnat-encoding suffix for fixed point. */
17956 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17958 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17959 "XF" suffix of the name. The text after this is what encodes the
17960 'small and 'delta information. Otherwise, return nullptr. */
17962 static const char *
17963 gnat_encoded_fixed_point_type_info (const char *name
)
17965 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17968 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17969 (which may be different from NAME) to the architecture back-end to allow
17970 it to guess the correct format if necessary. */
17972 static struct type
*
17973 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17974 const char *name_hint
, enum bfd_endian byte_order
)
17976 struct gdbarch
*gdbarch
= objfile
->arch ();
17977 const struct floatformat
**format
;
17980 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17982 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17984 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17989 /* Allocate an integer type of size BITS and name NAME. */
17991 static struct type
*
17992 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17993 int bits
, int unsigned_p
, const char *name
)
17997 /* Versions of Intel's C Compiler generate an integer type called "void"
17998 instead of using DW_TAG_unspecified_type. This has been seen on
17999 at least versions 14, 17, and 18. */
18000 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18001 && strcmp (name
, "void") == 0)
18002 type
= objfile_type (objfile
)->builtin_void
;
18004 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18009 /* Return true if DIE has a DW_AT_small attribute whose value is
18010 a constant rational, where both the numerator and denominator
18013 CU is the DIE's Compilation Unit. */
18016 has_zero_over_zero_small_attribute (struct die_info
*die
,
18017 struct dwarf2_cu
*cu
)
18019 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18020 if (attr
== nullptr)
18023 struct dwarf2_cu
*scale_cu
= cu
;
18024 struct die_info
*scale_die
18025 = follow_die_ref (die
, attr
, &scale_cu
);
18027 if (scale_die
->tag
!= DW_TAG_constant
)
18030 gdb_mpz
num (1), denom (1);
18031 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18032 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18035 /* Initialise and return a floating point type of size BITS suitable for
18036 use as a component of a complex number. The NAME_HINT is passed through
18037 when initialising the floating point type and is the name of the complex
18040 As DWARF doesn't currently provide an explicit name for the components
18041 of a complex number, but it can be helpful to have these components
18042 named, we try to select a suitable name based on the size of the
18044 static struct type
*
18045 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18046 struct objfile
*objfile
,
18047 int bits
, const char *name_hint
,
18048 enum bfd_endian byte_order
)
18050 gdbarch
*gdbarch
= objfile
->arch ();
18051 struct type
*tt
= nullptr;
18053 /* Try to find a suitable floating point builtin type of size BITS.
18054 We're going to use the name of this type as the name for the complex
18055 target type that we are about to create. */
18056 switch (cu
->per_cu
->lang
)
18058 case language_fortran
:
18062 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18065 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18067 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18069 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18077 tt
= builtin_type (gdbarch
)->builtin_float
;
18080 tt
= builtin_type (gdbarch
)->builtin_double
;
18082 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18084 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18090 /* If the type we found doesn't match the size we were looking for, then
18091 pretend we didn't find a type at all, the complex target type we
18092 create will then be nameless. */
18093 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18096 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18097 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18100 /* Find a representation of a given base type and install
18101 it in the TYPE field of the die. */
18103 static struct type
*
18104 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18106 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18108 struct attribute
*attr
;
18109 int encoding
= 0, bits
= 0;
18113 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18114 if (attr
!= nullptr && attr
->form_is_constant ())
18115 encoding
= attr
->constant_value (0);
18116 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18117 if (attr
!= nullptr)
18118 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18119 name
= dwarf2_name (die
, cu
);
18121 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18123 arch
= objfile
->arch ();
18124 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18126 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18127 if (attr
!= nullptr && attr
->form_is_constant ())
18129 int endianity
= attr
->constant_value (0);
18134 byte_order
= BFD_ENDIAN_BIG
;
18136 case DW_END_little
:
18137 byte_order
= BFD_ENDIAN_LITTLE
;
18140 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18145 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18146 && cu
->per_cu
->lang
== language_ada
18147 && has_zero_over_zero_small_attribute (die
, cu
))
18149 /* brobecker/2018-02-24: This is a fixed point type for which
18150 the scaling factor is represented as fraction whose value
18151 does not make sense (zero divided by zero), so we should
18152 normally never see these. However, there is a small category
18153 of fixed point types for which GNAT is unable to provide
18154 the scaling factor via the standard DWARF mechanisms, and
18155 for which the info is provided via the GNAT encodings instead.
18156 This is likely what this DIE is about. */
18157 encoding
= (encoding
== DW_ATE_signed_fixed
18159 : DW_ATE_unsigned
);
18162 /* With GNAT encodings, fixed-point information will be encoded in
18163 the type name. Note that this can also occur with the above
18164 zero-over-zero case, which is why this is a separate "if" rather
18165 than an "else if". */
18166 const char *gnat_encoding_suffix
= nullptr;
18167 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18168 && cu
->per_cu
->lang
== language_ada
18169 && name
!= nullptr)
18171 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18172 if (gnat_encoding_suffix
!= nullptr)
18174 gdb_assert (startswith (gnat_encoding_suffix
,
18175 GNAT_FIXED_POINT_SUFFIX
));
18176 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18177 name
, gnat_encoding_suffix
- name
);
18178 /* Use -1 here so that SUFFIX points at the "_" after the
18180 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18182 encoding
= (encoding
== DW_ATE_signed
18183 ? DW_ATE_signed_fixed
18184 : DW_ATE_unsigned_fixed
);
18190 case DW_ATE_address
:
18191 /* Turn DW_ATE_address into a void * pointer. */
18192 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18193 type
= init_pointer_type (objfile
, bits
, name
, type
);
18195 case DW_ATE_boolean
:
18196 type
= init_boolean_type (objfile
, bits
, 1, name
);
18198 case DW_ATE_complex_float
:
18199 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18201 if (type
->code () == TYPE_CODE_ERROR
)
18203 if (name
== nullptr)
18205 struct obstack
*obstack
18206 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18207 name
= obconcat (obstack
, "_Complex ", type
->name (),
18210 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18213 type
= init_complex_type (name
, type
);
18215 case DW_ATE_decimal_float
:
18216 type
= init_decfloat_type (objfile
, bits
, name
);
18219 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18221 case DW_ATE_signed
:
18222 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18224 case DW_ATE_unsigned
:
18225 if (cu
->per_cu
->lang
== language_fortran
18227 && startswith (name
, "character("))
18228 type
= init_character_type (objfile
, bits
, 1, name
);
18230 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18232 case DW_ATE_signed_char
:
18233 if (cu
->per_cu
->lang
== language_ada
18234 || cu
->per_cu
->lang
== language_m2
18235 || cu
->per_cu
->lang
== language_pascal
18236 || cu
->per_cu
->lang
== language_fortran
)
18237 type
= init_character_type (objfile
, bits
, 0, name
);
18239 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18241 case DW_ATE_unsigned_char
:
18242 if (cu
->per_cu
->lang
== language_ada
18243 || cu
->per_cu
->lang
== language_m2
18244 || cu
->per_cu
->lang
== language_pascal
18245 || cu
->per_cu
->lang
== language_fortran
18246 || cu
->per_cu
->lang
== language_rust
)
18247 type
= init_character_type (objfile
, bits
, 1, name
);
18249 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18253 type
= init_character_type (objfile
, bits
, 1, name
);
18254 return set_die_type (die
, type
, cu
);
18257 case DW_ATE_signed_fixed
:
18258 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18259 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18261 case DW_ATE_unsigned_fixed
:
18262 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18263 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18267 complaint (_("unsupported DW_AT_encoding: '%s'"),
18268 dwarf_type_encoding_name (encoding
));
18269 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18273 if (type
->code () == TYPE_CODE_INT
18275 && strcmp (name
, "char") == 0)
18276 type
->set_has_no_signedness (true);
18278 maybe_set_alignment (cu
, die
, type
);
18280 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18282 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18284 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18285 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18287 unsigned real_bit_size
= attr
->as_unsigned ();
18288 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18289 /* Only use the attributes if they make sense together. */
18290 if (attr
== nullptr
18291 || (attr
->as_unsigned () + real_bit_size
18292 <= 8 * TYPE_LENGTH (type
)))
18294 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18296 if (attr
!= nullptr)
18297 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18298 = attr
->as_unsigned ();
18303 return set_die_type (die
, type
, cu
);
18306 /* A helper function that returns the name of DIE, if it refers to a
18307 variable declaration. */
18309 static const char *
18310 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18312 if (die
->tag
!= DW_TAG_variable
)
18315 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18316 if (attr
== nullptr || !attr
->as_boolean ())
18319 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18320 if (attr
== nullptr)
18322 return attr
->as_string ();
18325 /* Parse dwarf attribute if it's a block, reference or constant and put the
18326 resulting value of the attribute into struct bound_prop.
18327 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18330 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18331 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18332 struct type
*default_type
)
18334 struct dwarf2_property_baton
*baton
;
18335 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18336 struct objfile
*objfile
= per_objfile
->objfile
;
18337 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18339 gdb_assert (default_type
!= NULL
);
18341 if (attr
== NULL
|| prop
== NULL
)
18344 if (attr
->form_is_block ())
18346 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18347 baton
->property_type
= default_type
;
18348 baton
->locexpr
.per_cu
= cu
->per_cu
;
18349 baton
->locexpr
.per_objfile
= per_objfile
;
18351 struct dwarf_block
*block
;
18352 if (attr
->form
== DW_FORM_data16
)
18354 size_t data_size
= 16;
18355 block
= XOBNEW (obstack
, struct dwarf_block
);
18356 block
->size
= (data_size
18357 + 2 /* Extra bytes for DW_OP and arg. */);
18358 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18359 data
[0] = DW_OP_implicit_value
;
18360 data
[1] = data_size
;
18361 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18362 block
->data
= data
;
18365 block
= attr
->as_block ();
18367 baton
->locexpr
.size
= block
->size
;
18368 baton
->locexpr
.data
= block
->data
;
18369 switch (attr
->name
)
18371 case DW_AT_string_length
:
18372 baton
->locexpr
.is_reference
= true;
18375 baton
->locexpr
.is_reference
= false;
18379 prop
->set_locexpr (baton
);
18380 gdb_assert (prop
->baton () != NULL
);
18382 else if (attr
->form_is_ref ())
18384 struct dwarf2_cu
*target_cu
= cu
;
18385 struct die_info
*target_die
;
18386 struct attribute
*target_attr
;
18388 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18389 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18390 if (target_attr
== NULL
)
18391 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18393 if (target_attr
== nullptr)
18394 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
18396 if (target_attr
== NULL
)
18398 const char *name
= var_decl_name (target_die
, target_cu
);
18399 if (name
!= nullptr)
18401 prop
->set_variable_name (name
);
18407 switch (target_attr
->name
)
18409 case DW_AT_location
:
18410 if (target_attr
->form_is_section_offset ())
18412 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18413 baton
->property_type
= die_type (target_die
, target_cu
);
18414 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18415 prop
->set_loclist (baton
);
18416 gdb_assert (prop
->baton () != NULL
);
18418 else if (target_attr
->form_is_block ())
18420 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18421 baton
->property_type
= die_type (target_die
, target_cu
);
18422 baton
->locexpr
.per_cu
= cu
->per_cu
;
18423 baton
->locexpr
.per_objfile
= per_objfile
;
18424 struct dwarf_block
*block
= target_attr
->as_block ();
18425 baton
->locexpr
.size
= block
->size
;
18426 baton
->locexpr
.data
= block
->data
;
18427 baton
->locexpr
.is_reference
= true;
18428 prop
->set_locexpr (baton
);
18429 gdb_assert (prop
->baton () != NULL
);
18433 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18434 "dynamic property");
18438 case DW_AT_data_member_location
:
18439 case DW_AT_data_bit_offset
:
18443 if (!handle_member_location (target_die
, target_cu
, &offset
))
18446 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18447 baton
->property_type
= read_type_die (target_die
->parent
,
18449 baton
->offset_info
.offset
= offset
;
18450 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18451 prop
->set_addr_offset (baton
);
18456 else if (attr
->form_is_constant ())
18457 prop
->set_const_val (attr
->constant_value (0));
18458 else if (attr
->form_is_section_offset ())
18460 switch (attr
->name
)
18462 case DW_AT_string_length
:
18463 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18464 baton
->property_type
= default_type
;
18465 fill_in_loclist_baton (cu
, &baton
->loclist
, attr
);
18466 prop
->set_loclist (baton
);
18467 gdb_assert (prop
->baton () != NULL
);
18479 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18480 dwarf2_name (die
, cu
));
18486 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18487 present (which is valid) then compute the default type based on the
18488 compilation units address size. */
18490 static struct type
*
18491 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18493 struct type
*index_type
= die_type (die
, cu
);
18495 /* Dwarf-2 specifications explicitly allows to create subrange types
18496 without specifying a base type.
18497 In that case, the base type must be set to the type of
18498 the lower bound, upper bound or count, in that order, if any of these
18499 three attributes references an object that has a type.
18500 If no base type is found, the Dwarf-2 specifications say that
18501 a signed integer type of size equal to the size of an address should
18503 For the following C code: `extern char gdb_int [];'
18504 GCC produces an empty range DIE.
18505 FIXME: muller/2010-05-28: Possible references to object for low bound,
18506 high bound or count are not yet handled by this code. */
18507 if (index_type
->code () == TYPE_CODE_VOID
)
18508 index_type
= cu
->addr_sized_int_type (false);
18513 /* Read the given DW_AT_subrange DIE. */
18515 static struct type
*
18516 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18518 struct type
*base_type
, *orig_base_type
;
18519 struct type
*range_type
;
18520 struct attribute
*attr
;
18521 struct dynamic_prop low
, high
;
18522 int low_default_is_valid
;
18523 int high_bound_is_count
= 0;
18525 ULONGEST negative_mask
;
18527 orig_base_type
= read_subrange_index_type (die
, cu
);
18529 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18530 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18531 creating the range type, but we use the result of check_typedef
18532 when examining properties of the type. */
18533 base_type
= check_typedef (orig_base_type
);
18535 /* The die_type call above may have already set the type for this DIE. */
18536 range_type
= get_die_type (die
, cu
);
18540 high
.set_const_val (0);
18542 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18543 omitting DW_AT_lower_bound. */
18544 switch (cu
->per_cu
->lang
)
18547 case language_cplus
:
18548 low
.set_const_val (0);
18549 low_default_is_valid
= 1;
18551 case language_fortran
:
18552 low
.set_const_val (1);
18553 low_default_is_valid
= 1;
18556 case language_objc
:
18557 case language_rust
:
18558 low
.set_const_val (0);
18559 low_default_is_valid
= (cu
->header
.version
>= 4);
18563 case language_pascal
:
18564 low
.set_const_val (1);
18565 low_default_is_valid
= (cu
->header
.version
>= 4);
18568 low
.set_const_val (0);
18569 low_default_is_valid
= 0;
18573 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18574 if (attr
!= nullptr)
18575 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18576 else if (!low_default_is_valid
)
18577 complaint (_("Missing DW_AT_lower_bound "
18578 "- DIE at %s [in module %s]"),
18579 sect_offset_str (die
->sect_off
),
18580 objfile_name (cu
->per_objfile
->objfile
));
18582 struct attribute
*attr_ub
, *attr_count
;
18583 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18584 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18586 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18587 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18589 /* If bounds are constant do the final calculation here. */
18590 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18591 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18593 high_bound_is_count
= 1;
18597 if (attr_ub
!= NULL
)
18598 complaint (_("Unresolved DW_AT_upper_bound "
18599 "- DIE at %s [in module %s]"),
18600 sect_offset_str (die
->sect_off
),
18601 objfile_name (cu
->per_objfile
->objfile
));
18602 if (attr_count
!= NULL
)
18603 complaint (_("Unresolved DW_AT_count "
18604 "- DIE at %s [in module %s]"),
18605 sect_offset_str (die
->sect_off
),
18606 objfile_name (cu
->per_objfile
->objfile
));
18611 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18612 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18613 bias
= bias_attr
->constant_value (0);
18615 /* Normally, the DWARF producers are expected to use a signed
18616 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18617 But this is unfortunately not always the case, as witnessed
18618 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18619 is used instead. To work around that ambiguity, we treat
18620 the bounds as signed, and thus sign-extend their values, when
18621 the base type is signed. */
18623 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18624 if (low
.kind () == PROP_CONST
18625 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18626 low
.set_const_val (low
.const_val () | negative_mask
);
18627 if (high
.kind () == PROP_CONST
18628 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18629 high
.set_const_val (high
.const_val () | negative_mask
);
18631 /* Check for bit and byte strides. */
18632 struct dynamic_prop byte_stride_prop
;
18633 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18634 if (attr_byte_stride
!= nullptr)
18636 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18637 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18641 struct dynamic_prop bit_stride_prop
;
18642 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18643 if (attr_bit_stride
!= nullptr)
18645 /* It only makes sense to have either a bit or byte stride. */
18646 if (attr_byte_stride
!= nullptr)
18648 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18649 "- DIE at %s [in module %s]"),
18650 sect_offset_str (die
->sect_off
),
18651 objfile_name (cu
->per_objfile
->objfile
));
18652 attr_bit_stride
= nullptr;
18656 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18657 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18662 if (attr_byte_stride
!= nullptr
18663 || attr_bit_stride
!= nullptr)
18665 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18666 struct dynamic_prop
*stride
18667 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18670 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18671 &high
, bias
, stride
, byte_stride_p
);
18674 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18676 if (high_bound_is_count
)
18677 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18679 /* Ada expects an empty array on no boundary attributes. */
18680 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18681 range_type
->bounds ()->high
.set_undefined ();
18683 name
= dwarf2_name (die
, cu
);
18685 range_type
->set_name (name
);
18687 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18688 if (attr
!= nullptr)
18689 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18691 maybe_set_alignment (cu
, die
, range_type
);
18693 set_die_type (die
, range_type
, cu
);
18695 /* set_die_type should be already done. */
18696 set_descriptive_type (range_type
, die
, cu
);
18701 static struct type
*
18702 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18706 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18707 type
->set_name (dwarf2_name (die
, cu
));
18709 /* In Ada, an unspecified type is typically used when the description
18710 of the type is deferred to a different unit. When encountering
18711 such a type, we treat it as a stub, and try to resolve it later on,
18713 if (cu
->per_cu
->lang
== language_ada
)
18714 type
->set_is_stub (true);
18716 return set_die_type (die
, type
, cu
);
18719 /* Read a single die and all its descendents. Set the die's sibling
18720 field to NULL; set other fields in the die correctly, and set all
18721 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18722 location of the info_ptr after reading all of those dies. PARENT
18723 is the parent of the die in question. */
18725 static struct die_info
*
18726 read_die_and_children (const struct die_reader_specs
*reader
,
18727 const gdb_byte
*info_ptr
,
18728 const gdb_byte
**new_info_ptr
,
18729 struct die_info
*parent
)
18731 struct die_info
*die
;
18732 const gdb_byte
*cur_ptr
;
18734 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18737 *new_info_ptr
= cur_ptr
;
18740 store_in_ref_table (die
, reader
->cu
);
18742 if (die
->has_children
)
18743 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18747 *new_info_ptr
= cur_ptr
;
18750 die
->sibling
= NULL
;
18751 die
->parent
= parent
;
18755 /* Read a die, all of its descendents, and all of its siblings; set
18756 all of the fields of all of the dies correctly. Arguments are as
18757 in read_die_and_children. */
18759 static struct die_info
*
18760 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18761 const gdb_byte
*info_ptr
,
18762 const gdb_byte
**new_info_ptr
,
18763 struct die_info
*parent
)
18765 struct die_info
*first_die
, *last_sibling
;
18766 const gdb_byte
*cur_ptr
;
18768 cur_ptr
= info_ptr
;
18769 first_die
= last_sibling
= NULL
;
18773 struct die_info
*die
18774 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18778 *new_info_ptr
= cur_ptr
;
18785 last_sibling
->sibling
= die
;
18787 last_sibling
= die
;
18791 /* Read a die, all of its descendents, and all of its siblings; set
18792 all of the fields of all of the dies correctly. Arguments are as
18793 in read_die_and_children.
18794 This the main entry point for reading a DIE and all its children. */
18796 static struct die_info
*
18797 read_die_and_siblings (const struct die_reader_specs
*reader
,
18798 const gdb_byte
*info_ptr
,
18799 const gdb_byte
**new_info_ptr
,
18800 struct die_info
*parent
)
18802 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18803 new_info_ptr
, parent
);
18805 if (dwarf_die_debug
)
18807 fprintf_unfiltered (gdb_stdlog
,
18808 "Read die from %s@0x%x of %s:\n",
18809 reader
->die_section
->get_name (),
18810 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18811 bfd_get_filename (reader
->abfd
));
18812 dump_die (die
, dwarf_die_debug
);
18818 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18820 The caller is responsible for filling in the extra attributes
18821 and updating (*DIEP)->num_attrs.
18822 Set DIEP to point to a newly allocated die with its information,
18823 except for its child, sibling, and parent fields. */
18825 static const gdb_byte
*
18826 read_full_die_1 (const struct die_reader_specs
*reader
,
18827 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18828 int num_extra_attrs
)
18830 unsigned int abbrev_number
, bytes_read
, i
;
18831 const struct abbrev_info
*abbrev
;
18832 struct die_info
*die
;
18833 struct dwarf2_cu
*cu
= reader
->cu
;
18834 bfd
*abfd
= reader
->abfd
;
18836 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18837 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18838 info_ptr
+= bytes_read
;
18839 if (!abbrev_number
)
18845 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18847 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18849 bfd_get_filename (abfd
));
18851 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18852 die
->sect_off
= sect_off
;
18853 die
->tag
= abbrev
->tag
;
18854 die
->abbrev
= abbrev_number
;
18855 die
->has_children
= abbrev
->has_children
;
18857 /* Make the result usable.
18858 The caller needs to update num_attrs after adding the extra
18860 die
->num_attrs
= abbrev
->num_attrs
;
18862 bool any_need_reprocess
= false;
18863 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18865 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18867 if (die
->attrs
[i
].requires_reprocessing_p ())
18868 any_need_reprocess
= true;
18871 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18872 if (attr
!= nullptr && attr
->form_is_unsigned ())
18873 cu
->str_offsets_base
= attr
->as_unsigned ();
18875 attr
= die
->attr (DW_AT_loclists_base
);
18876 if (attr
!= nullptr)
18877 cu
->loclist_base
= attr
->as_unsigned ();
18879 auto maybe_addr_base
= die
->addr_base ();
18880 if (maybe_addr_base
.has_value ())
18881 cu
->addr_base
= *maybe_addr_base
;
18883 attr
= die
->attr (DW_AT_rnglists_base
);
18884 if (attr
!= nullptr)
18885 cu
->rnglists_base
= attr
->as_unsigned ();
18887 if (any_need_reprocess
)
18889 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18891 if (die
->attrs
[i
].requires_reprocessing_p ())
18892 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18899 /* Read a die and all its attributes.
18900 Set DIEP to point to a newly allocated die with its information,
18901 except for its child, sibling, and parent fields. */
18903 static const gdb_byte
*
18904 read_full_die (const struct die_reader_specs
*reader
,
18905 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18907 const gdb_byte
*result
;
18909 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18911 if (dwarf_die_debug
)
18913 fprintf_unfiltered (gdb_stdlog
,
18914 "Read die from %s@0x%x of %s:\n",
18915 reader
->die_section
->get_name (),
18916 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18917 bfd_get_filename (reader
->abfd
));
18918 dump_die (*diep
, dwarf_die_debug
);
18925 /* Returns nonzero if TAG represents a type that we might generate a partial
18929 is_type_tag_for_partial (int tag
, enum language lang
)
18934 /* Some types that would be reasonable to generate partial symbols for,
18935 that we don't at present. Note that normally this does not
18936 matter, mainly because C compilers don't give names to these
18937 types, but instead emit DW_TAG_typedef. */
18938 case DW_TAG_file_type
:
18939 case DW_TAG_ptr_to_member_type
:
18940 case DW_TAG_set_type
:
18941 case DW_TAG_string_type
:
18942 case DW_TAG_subroutine_type
:
18945 /* GNAT may emit an array with a name, but no typedef, so we
18946 need to make a symbol in this case. */
18947 case DW_TAG_array_type
:
18948 return lang
== language_ada
;
18950 case DW_TAG_base_type
:
18951 case DW_TAG_class_type
:
18952 case DW_TAG_interface_type
:
18953 case DW_TAG_enumeration_type
:
18954 case DW_TAG_structure_type
:
18955 case DW_TAG_subrange_type
:
18956 case DW_TAG_typedef
:
18957 case DW_TAG_union_type
:
18964 /* Load all DIEs that are interesting for partial symbols into memory. */
18966 static struct partial_die_info
*
18967 load_partial_dies (const struct die_reader_specs
*reader
,
18968 const gdb_byte
*info_ptr
, int building_psymtab
)
18970 struct dwarf2_cu
*cu
= reader
->cu
;
18971 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18972 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18973 unsigned int bytes_read
;
18974 unsigned int load_all
= 0;
18975 int nesting_level
= 1;
18980 gdb_assert (cu
->per_cu
!= NULL
);
18981 if (cu
->load_all_dies
)
18985 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18989 &cu
->comp_unit_obstack
,
18990 hashtab_obstack_allocate
,
18991 dummy_obstack_deallocate
);
18995 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18998 /* A NULL abbrev means the end of a series of children. */
18999 if (abbrev
== NULL
)
19001 if (--nesting_level
== 0)
19004 info_ptr
+= bytes_read
;
19005 last_die
= parent_die
;
19006 parent_die
= parent_die
->die_parent
;
19010 /* Check for template arguments. We never save these; if
19011 they're seen, we just mark the parent, and go on our way. */
19012 if (parent_die
!= NULL
19013 && cu
->per_cu
->lang
== language_cplus
19014 && (abbrev
->tag
== DW_TAG_template_type_param
19015 || abbrev
->tag
== DW_TAG_template_value_param
))
19017 parent_die
->has_template_arguments
= 1;
19021 /* We don't need a partial DIE for the template argument. */
19022 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19027 /* We only recurse into c++ subprograms looking for template arguments.
19028 Skip their other children. */
19030 && cu
->per_cu
->lang
== language_cplus
19031 && parent_die
!= NULL
19032 && parent_die
->tag
== DW_TAG_subprogram
19033 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19035 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19039 /* Check whether this DIE is interesting enough to save. Normally
19040 we would not be interested in members here, but there may be
19041 later variables referencing them via DW_AT_specification (for
19042 static members). */
19044 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
19045 && abbrev
->tag
!= DW_TAG_constant
19046 && abbrev
->tag
!= DW_TAG_enumerator
19047 && abbrev
->tag
!= DW_TAG_subprogram
19048 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19049 && abbrev
->tag
!= DW_TAG_lexical_block
19050 && abbrev
->tag
!= DW_TAG_variable
19051 && abbrev
->tag
!= DW_TAG_namespace
19052 && abbrev
->tag
!= DW_TAG_module
19053 && abbrev
->tag
!= DW_TAG_member
19054 && abbrev
->tag
!= DW_TAG_imported_unit
19055 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19057 /* Otherwise we skip to the next sibling, if any. */
19058 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19062 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19065 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19067 /* This two-pass algorithm for processing partial symbols has a
19068 high cost in cache pressure. Thus, handle some simple cases
19069 here which cover the majority of C partial symbols. DIEs
19070 which neither have specification tags in them, nor could have
19071 specification tags elsewhere pointing at them, can simply be
19072 processed and discarded.
19074 This segment is also optional; scan_partial_symbols and
19075 add_partial_symbol will handle these DIEs if we chain
19076 them in normally. When compilers which do not emit large
19077 quantities of duplicate debug information are more common,
19078 this code can probably be removed. */
19080 /* Any complete simple types at the top level (pretty much all
19081 of them, for a language without namespaces), can be processed
19083 if (parent_die
== NULL
19084 && pdi
.has_specification
== 0
19085 && pdi
.is_declaration
== 0
19086 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19087 || pdi
.tag
== DW_TAG_base_type
19088 || pdi
.tag
== DW_TAG_array_type
19089 || pdi
.tag
== DW_TAG_subrange_type
))
19091 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19092 add_partial_symbol (&pdi
, cu
);
19094 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19098 /* The exception for DW_TAG_typedef with has_children above is
19099 a workaround of GCC PR debug/47510. In the case of this complaint
19100 type_name_or_error will error on such types later.
19102 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19103 it could not find the child DIEs referenced later, this is checked
19104 above. In correct DWARF DW_TAG_typedef should have no children. */
19106 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19107 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19108 "- DIE at %s [in module %s]"),
19109 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19111 /* If we're at the second level, and we're an enumerator, and
19112 our parent has no specification (meaning possibly lives in a
19113 namespace elsewhere), then we can add the partial symbol now
19114 instead of queueing it. */
19115 if (pdi
.tag
== DW_TAG_enumerator
19116 && parent_die
!= NULL
19117 && parent_die
->die_parent
== NULL
19118 && parent_die
->tag
== DW_TAG_enumeration_type
19119 && parent_die
->has_specification
== 0)
19121 if (pdi
.raw_name
== NULL
)
19122 complaint (_("malformed enumerator DIE ignored"));
19123 else if (building_psymtab
)
19124 add_partial_symbol (&pdi
, cu
);
19126 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19130 struct partial_die_info
*part_die
19131 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19133 /* We'll save this DIE so link it in. */
19134 part_die
->die_parent
= parent_die
;
19135 part_die
->die_sibling
= NULL
;
19136 part_die
->die_child
= NULL
;
19138 if (last_die
&& last_die
== parent_die
)
19139 last_die
->die_child
= part_die
;
19141 last_die
->die_sibling
= part_die
;
19143 last_die
= part_die
;
19145 if (first_die
== NULL
)
19146 first_die
= part_die
;
19148 /* Maybe add the DIE to the hash table. Not all DIEs that we
19149 find interesting need to be in the hash table, because we
19150 also have the parent/sibling/child chains; only those that we
19151 might refer to by offset later during partial symbol reading.
19153 For now this means things that might have be the target of a
19154 DW_AT_specification, DW_AT_abstract_origin, or
19155 DW_AT_extension. DW_AT_extension will refer only to
19156 namespaces; DW_AT_abstract_origin refers to functions (and
19157 many things under the function DIE, but we do not recurse
19158 into function DIEs during partial symbol reading) and
19159 possibly variables as well; DW_AT_specification refers to
19160 declarations. Declarations ought to have the DW_AT_declaration
19161 flag. It happens that GCC forgets to put it in sometimes, but
19162 only for functions, not for types.
19164 Adding more things than necessary to the hash table is harmless
19165 except for the performance cost. Adding too few will result in
19166 wasted time in find_partial_die, when we reread the compilation
19167 unit with load_all_dies set. */
19170 || abbrev
->tag
== DW_TAG_constant
19171 || abbrev
->tag
== DW_TAG_subprogram
19172 || abbrev
->tag
== DW_TAG_variable
19173 || abbrev
->tag
== DW_TAG_namespace
19174 || part_die
->is_declaration
)
19178 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19179 to_underlying (part_die
->sect_off
),
19184 /* For some DIEs we want to follow their children (if any). For C
19185 we have no reason to follow the children of structures; for other
19186 languages we have to, so that we can get at method physnames
19187 to infer fully qualified class names, for DW_AT_specification,
19188 and for C++ template arguments. For C++, we also look one level
19189 inside functions to find template arguments (if the name of the
19190 function does not already contain the template arguments).
19192 For Ada and Fortran, we need to scan the children of subprograms
19193 and lexical blocks as well because these languages allow the
19194 definition of nested entities that could be interesting for the
19195 debugger, such as nested subprograms for instance. */
19196 if (last_die
->has_children
19198 || last_die
->tag
== DW_TAG_namespace
19199 || last_die
->tag
== DW_TAG_module
19200 || last_die
->tag
== DW_TAG_enumeration_type
19201 || (cu
->per_cu
->lang
== language_cplus
19202 && last_die
->tag
== DW_TAG_subprogram
19203 && (last_die
->raw_name
== NULL
19204 || strchr (last_die
->raw_name
, '<') == NULL
))
19205 || (cu
->per_cu
->lang
!= language_c
19206 && (last_die
->tag
== DW_TAG_class_type
19207 || last_die
->tag
== DW_TAG_interface_type
19208 || last_die
->tag
== DW_TAG_structure_type
19209 || last_die
->tag
== DW_TAG_union_type
))
19210 || ((cu
->per_cu
->lang
== language_ada
19211 || cu
->per_cu
->lang
== language_fortran
)
19212 && (last_die
->tag
== DW_TAG_subprogram
19213 || last_die
->tag
== DW_TAG_lexical_block
))))
19216 parent_die
= last_die
;
19220 /* Otherwise we skip to the next sibling, if any. */
19221 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19223 /* Back to the top, do it again. */
19227 partial_die_info::partial_die_info (sect_offset sect_off_
,
19228 const struct abbrev_info
*abbrev
)
19229 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19233 /* See class definition. */
19236 partial_die_info::name (dwarf2_cu
*cu
)
19238 if (!canonical_name
&& raw_name
!= nullptr)
19240 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19241 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19242 canonical_name
= 1;
19248 /* Read a minimal amount of information into the minimal die structure.
19249 INFO_PTR should point just after the initial uleb128 of a DIE. */
19252 partial_die_info::read (const struct die_reader_specs
*reader
,
19253 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19255 struct dwarf2_cu
*cu
= reader
->cu
;
19256 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19258 int has_low_pc_attr
= 0;
19259 int has_high_pc_attr
= 0;
19260 int high_pc_relative
= 0;
19262 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19265 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19266 /* String and address offsets that need to do the reprocessing have
19267 already been read at this point, so there is no need to wait until
19268 the loop terminates to do the reprocessing. */
19269 if (attr
.requires_reprocessing_p ())
19270 read_attribute_reprocess (reader
, &attr
, tag
);
19271 /* Store the data if it is of an attribute we want to keep in a
19272 partial symbol table. */
19278 case DW_TAG_compile_unit
:
19279 case DW_TAG_partial_unit
:
19280 case DW_TAG_type_unit
:
19281 /* Compilation units have a DW_AT_name that is a filename, not
19282 a source language identifier. */
19283 case DW_TAG_enumeration_type
:
19284 case DW_TAG_enumerator
:
19285 /* These tags always have simple identifiers already; no need
19286 to canonicalize them. */
19287 canonical_name
= 1;
19288 raw_name
= attr
.as_string ();
19291 canonical_name
= 0;
19292 raw_name
= attr
.as_string ();
19296 case DW_AT_linkage_name
:
19297 case DW_AT_MIPS_linkage_name
:
19298 /* Note that both forms of linkage name might appear. We
19299 assume they will be the same, and we only store the last
19301 linkage_name
= attr
.as_string ();
19304 has_low_pc_attr
= 1;
19305 lowpc
= attr
.as_address ();
19307 case DW_AT_high_pc
:
19308 has_high_pc_attr
= 1;
19309 highpc
= attr
.as_address ();
19310 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19311 high_pc_relative
= 1;
19313 case DW_AT_location
:
19314 /* Support the .debug_loc offsets. */
19315 if (attr
.form_is_block ())
19317 d
.locdesc
= attr
.as_block ();
19319 else if (attr
.form_is_section_offset ())
19321 dwarf2_complex_location_expr_complaint ();
19325 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19326 "partial symbol information");
19329 case DW_AT_external
:
19330 is_external
= attr
.as_boolean ();
19332 case DW_AT_declaration
:
19333 is_declaration
= attr
.as_boolean ();
19338 case DW_AT_abstract_origin
:
19339 case DW_AT_specification
:
19340 case DW_AT_extension
:
19341 has_specification
= 1;
19342 spec_offset
= attr
.get_ref_die_offset ();
19343 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19344 || cu
->per_cu
->is_dwz
);
19346 case DW_AT_sibling
:
19347 /* Ignore absolute siblings, they might point outside of
19348 the current compile unit. */
19349 if (attr
.form
== DW_FORM_ref_addr
)
19350 complaint (_("ignoring absolute DW_AT_sibling"));
19353 const gdb_byte
*buffer
= reader
->buffer
;
19354 sect_offset off
= attr
.get_ref_die_offset ();
19355 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19357 if (sibling_ptr
< info_ptr
)
19358 complaint (_("DW_AT_sibling points backwards"));
19359 else if (sibling_ptr
> reader
->buffer_end
)
19360 reader
->die_section
->overflow_complaint ();
19362 sibling
= sibling_ptr
;
19365 case DW_AT_byte_size
:
19368 case DW_AT_const_value
:
19369 has_const_value
= 1;
19371 case DW_AT_calling_convention
:
19372 /* DWARF doesn't provide a way to identify a program's source-level
19373 entry point. DW_AT_calling_convention attributes are only meant
19374 to describe functions' calling conventions.
19376 However, because it's a necessary piece of information in
19377 Fortran, and before DWARF 4 DW_CC_program was the only
19378 piece of debugging information whose definition refers to
19379 a 'main program' at all, several compilers marked Fortran
19380 main programs with DW_CC_program --- even when those
19381 functions use the standard calling conventions.
19383 Although DWARF now specifies a way to provide this
19384 information, we support this practice for backward
19386 if (attr
.constant_value (0) == DW_CC_program
19387 && cu
->per_cu
->lang
== language_fortran
)
19388 main_subprogram
= 1;
19392 LONGEST value
= attr
.constant_value (-1);
19393 if (value
== DW_INL_inlined
19394 || value
== DW_INL_declared_inlined
)
19395 may_be_inlined
= 1;
19400 if (tag
== DW_TAG_imported_unit
)
19402 d
.sect_off
= attr
.get_ref_die_offset ();
19403 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19404 || cu
->per_cu
->is_dwz
);
19408 case DW_AT_main_subprogram
:
19409 main_subprogram
= attr
.as_boolean ();
19414 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19415 on DWARF version). */
19416 ranges_offset
= attr
.as_unsigned ();
19418 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19420 if (tag
!= DW_TAG_compile_unit
)
19421 ranges_offset
+= cu
->gnu_ranges_base
;
19423 has_range_info
= 1;
19432 /* For Ada, if both the name and the linkage name appear, we prefer
19433 the latter. This lets "catch exception" work better, regardless
19434 of the order in which the name and linkage name were emitted.
19435 Really, though, this is just a workaround for the fact that gdb
19436 doesn't store both the name and the linkage name. */
19437 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19438 raw_name
= linkage_name
;
19440 if (high_pc_relative
)
19443 if (has_low_pc_attr
&& has_high_pc_attr
)
19445 /* When using the GNU linker, .gnu.linkonce. sections are used to
19446 eliminate duplicate copies of functions and vtables and such.
19447 The linker will arbitrarily choose one and discard the others.
19448 The AT_*_pc values for such functions refer to local labels in
19449 these sections. If the section from that file was discarded, the
19450 labels are not in the output, so the relocs get a value of 0.
19451 If this is a discarded function, mark the pc bounds as invalid,
19452 so that GDB will ignore it. */
19453 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19455 struct objfile
*objfile
= per_objfile
->objfile
;
19456 struct gdbarch
*gdbarch
= objfile
->arch ();
19458 complaint (_("DW_AT_low_pc %s is zero "
19459 "for DIE at %s [in module %s]"),
19460 paddress (gdbarch
, lowpc
),
19461 sect_offset_str (sect_off
),
19462 objfile_name (objfile
));
19464 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19465 else if (lowpc
>= highpc
)
19467 struct objfile
*objfile
= per_objfile
->objfile
;
19468 struct gdbarch
*gdbarch
= objfile
->arch ();
19470 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19471 "for DIE at %s [in module %s]"),
19472 paddress (gdbarch
, lowpc
),
19473 paddress (gdbarch
, highpc
),
19474 sect_offset_str (sect_off
),
19475 objfile_name (objfile
));
19484 /* Find a cached partial DIE at OFFSET in CU. */
19486 struct partial_die_info
*
19487 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19489 struct partial_die_info
*lookup_die
= NULL
;
19490 struct partial_die_info
part_die (sect_off
);
19492 lookup_die
= ((struct partial_die_info
*)
19493 htab_find_with_hash (partial_dies
, &part_die
,
19494 to_underlying (sect_off
)));
19499 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19500 except in the case of .debug_types DIEs which do not reference
19501 outside their CU (they do however referencing other types via
19502 DW_FORM_ref_sig8). */
19504 static const struct cu_partial_die_info
19505 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19507 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19508 struct objfile
*objfile
= per_objfile
->objfile
;
19509 struct partial_die_info
*pd
= NULL
;
19511 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19512 && cu
->header
.offset_in_cu_p (sect_off
))
19514 pd
= cu
->find_partial_die (sect_off
);
19517 /* We missed recording what we needed.
19518 Load all dies and try again. */
19522 /* TUs don't reference other CUs/TUs (except via type signatures). */
19523 if (cu
->per_cu
->is_debug_types
)
19525 error (_("Dwarf Error: Type Unit at offset %s contains"
19526 " external reference to offset %s [in module %s].\n"),
19527 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19528 bfd_get_filename (objfile
->obfd
));
19530 dwarf2_per_cu_data
*per_cu
19531 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19532 per_objfile
->per_bfd
);
19534 cu
= per_objfile
->get_cu (per_cu
);
19535 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19536 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19538 cu
= per_objfile
->get_cu (per_cu
);
19541 pd
= cu
->find_partial_die (sect_off
);
19544 /* If we didn't find it, and not all dies have been loaded,
19545 load them all and try again. */
19547 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19549 cu
->load_all_dies
= 1;
19551 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19552 THIS_CU->cu may already be in use. So we can't just free it and
19553 replace its DIEs with the ones we read in. Instead, we leave those
19554 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19555 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19557 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19559 pd
= cu
->find_partial_die (sect_off
);
19563 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19564 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19568 /* See if we can figure out if the class lives in a namespace. We do
19569 this by looking for a member function; its demangled name will
19570 contain namespace info, if there is any. */
19573 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19574 struct dwarf2_cu
*cu
)
19576 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19577 what template types look like, because the demangler
19578 frequently doesn't give the same name as the debug info. We
19579 could fix this by only using the demangled name to get the
19580 prefix (but see comment in read_structure_type). */
19582 struct partial_die_info
*real_pdi
;
19583 struct partial_die_info
*child_pdi
;
19585 /* If this DIE (this DIE's specification, if any) has a parent, then
19586 we should not do this. We'll prepend the parent's fully qualified
19587 name when we create the partial symbol. */
19589 real_pdi
= struct_pdi
;
19590 while (real_pdi
->has_specification
)
19592 auto res
= find_partial_die (real_pdi
->spec_offset
,
19593 real_pdi
->spec_is_dwz
, cu
);
19594 real_pdi
= res
.pdi
;
19598 if (real_pdi
->die_parent
!= NULL
)
19601 for (child_pdi
= struct_pdi
->die_child
;
19603 child_pdi
= child_pdi
->die_sibling
)
19605 if (child_pdi
->tag
== DW_TAG_subprogram
19606 && child_pdi
->linkage_name
!= NULL
)
19608 gdb::unique_xmalloc_ptr
<char> actual_class_name
19609 (cu
->language_defn
->class_name_from_physname
19610 (child_pdi
->linkage_name
));
19611 if (actual_class_name
!= NULL
)
19613 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19614 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19615 struct_pdi
->canonical_name
= 1;
19622 /* Return true if a DIE with TAG may have the DW_AT_const_value
19626 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19630 case DW_TAG_constant
:
19631 case DW_TAG_enumerator
:
19632 case DW_TAG_formal_parameter
:
19633 case DW_TAG_template_value_param
:
19634 case DW_TAG_variable
:
19642 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19644 /* Once we've fixed up a die, there's no point in doing so again.
19645 This also avoids a memory leak if we were to call
19646 guess_partial_die_structure_name multiple times. */
19650 /* If we found a reference attribute and the DIE has no name, try
19651 to find a name in the referred to DIE. */
19653 if (raw_name
== NULL
&& has_specification
)
19655 struct partial_die_info
*spec_die
;
19657 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19658 spec_die
= res
.pdi
;
19661 spec_die
->fixup (cu
);
19663 if (spec_die
->raw_name
)
19665 raw_name
= spec_die
->raw_name
;
19666 canonical_name
= spec_die
->canonical_name
;
19668 /* Copy DW_AT_external attribute if it is set. */
19669 if (spec_die
->is_external
)
19670 is_external
= spec_die
->is_external
;
19674 if (!has_const_value
&& has_specification
19675 && can_have_DW_AT_const_value_p (tag
))
19677 struct partial_die_info
*spec_die
;
19679 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19680 spec_die
= res
.pdi
;
19683 spec_die
->fixup (cu
);
19685 if (spec_die
->has_const_value
)
19687 /* Copy DW_AT_const_value attribute if it is set. */
19688 has_const_value
= spec_die
->has_const_value
;
19692 /* Set default names for some unnamed DIEs. */
19694 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19696 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19697 canonical_name
= 1;
19700 /* If there is no parent die to provide a namespace, and there are
19701 children, see if we can determine the namespace from their linkage
19703 if (cu
->per_cu
->lang
== language_cplus
19704 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19705 && die_parent
== NULL
19707 && (tag
== DW_TAG_class_type
19708 || tag
== DW_TAG_structure_type
19709 || tag
== DW_TAG_union_type
))
19710 guess_partial_die_structure_name (this, cu
);
19712 /* GCC might emit a nameless struct or union that has a linkage
19713 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19714 if (raw_name
== NULL
19715 && (tag
== DW_TAG_class_type
19716 || tag
== DW_TAG_interface_type
19717 || tag
== DW_TAG_structure_type
19718 || tag
== DW_TAG_union_type
)
19719 && linkage_name
!= NULL
)
19721 gdb::unique_xmalloc_ptr
<char> demangled
19722 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19723 if (demangled
!= nullptr)
19727 /* Strip any leading namespaces/classes, keep only the base name.
19728 DW_AT_name for named DIEs does not contain the prefixes. */
19729 base
= strrchr (demangled
.get (), ':');
19730 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19733 base
= demangled
.get ();
19735 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19736 raw_name
= objfile
->intern (base
);
19737 canonical_name
= 1;
19744 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19745 contents from the given SECTION in the HEADER.
19747 HEADER_OFFSET is the offset of the header in the section. */
19749 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19750 struct dwarf2_section_info
*section
,
19751 sect_offset header_offset
)
19753 unsigned int bytes_read
;
19754 bfd
*abfd
= section
->get_bfd_owner ();
19755 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19757 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19758 info_ptr
+= bytes_read
;
19760 header
->version
= read_2_bytes (abfd
, info_ptr
);
19763 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19766 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19769 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19772 /* Return the DW_AT_loclists_base value for the CU. */
19774 lookup_loclist_base (struct dwarf2_cu
*cu
)
19776 /* For the .dwo unit, the loclist_base points to the first offset following
19777 the header. The header consists of the following entities-
19778 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19780 2. version (2 bytes)
19781 3. address size (1 byte)
19782 4. segment selector size (1 byte)
19783 5. offset entry count (4 bytes)
19784 These sizes are derived as per the DWARFv5 standard. */
19785 if (cu
->dwo_unit
!= nullptr)
19787 if (cu
->header
.initial_length_size
== 4)
19788 return LOCLIST_HEADER_SIZE32
;
19789 return LOCLIST_HEADER_SIZE64
;
19791 return cu
->loclist_base
;
19794 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19795 array of offsets in the .debug_loclists section. */
19798 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19800 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19801 struct objfile
*objfile
= per_objfile
->objfile
;
19802 bfd
*abfd
= objfile
->obfd
;
19803 ULONGEST loclist_header_size
=
19804 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19805 : LOCLIST_HEADER_SIZE64
);
19806 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19808 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19809 ULONGEST start_offset
=
19810 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19812 /* Get loclists section. */
19813 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19815 /* Read the loclists section content. */
19816 section
->read (objfile
);
19817 if (section
->buffer
== NULL
)
19818 error (_("DW_FORM_loclistx used without .debug_loclists "
19819 "section [in module %s]"), objfile_name (objfile
));
19821 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19822 so if loclist_base is smaller than the header size, we have a problem. */
19823 if (loclist_base
< loclist_header_size
)
19824 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19825 objfile_name (objfile
));
19827 /* Read the header of the loclists contribution. */
19828 struct loclists_rnglists_header header
;
19829 read_loclists_rnglists_header (&header
, section
,
19830 (sect_offset
) (loclist_base
- loclist_header_size
));
19832 /* Verify the loclist index is valid. */
19833 if (loclist_index
>= header
.offset_entry_count
)
19834 error (_("DW_FORM_loclistx pointing outside of "
19835 ".debug_loclists offset array [in module %s]"),
19836 objfile_name (objfile
));
19838 /* Validate that reading won't go beyond the end of the section. */
19839 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19840 error (_("Reading DW_FORM_loclistx index beyond end of"
19841 ".debug_loclists section [in module %s]"),
19842 objfile_name (objfile
));
19844 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19846 if (cu
->header
.offset_size
== 4)
19847 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19849 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19852 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19853 array of offsets in the .debug_rnglists section. */
19856 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19859 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19860 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19861 bfd
*abfd
= objfile
->obfd
;
19862 ULONGEST rnglist_header_size
=
19863 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19864 : RNGLIST_HEADER_SIZE64
);
19866 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19867 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19869 ULONGEST rnglist_base
=
19870 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19872 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19873 ULONGEST start_offset
=
19874 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19876 /* Get rnglists section. */
19877 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19879 /* Read the rnglists section content. */
19880 section
->read (objfile
);
19881 if (section
->buffer
== nullptr)
19882 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19884 objfile_name (objfile
));
19886 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19887 so if rnglist_base is smaller than the header size, we have a problem. */
19888 if (rnglist_base
< rnglist_header_size
)
19889 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19890 objfile_name (objfile
));
19892 /* Read the header of the rnglists contribution. */
19893 struct loclists_rnglists_header header
;
19894 read_loclists_rnglists_header (&header
, section
,
19895 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19897 /* Verify the rnglist index is valid. */
19898 if (rnglist_index
>= header
.offset_entry_count
)
19899 error (_("DW_FORM_rnglistx index pointing outside of "
19900 ".debug_rnglists offset array [in module %s]"),
19901 objfile_name (objfile
));
19903 /* Validate that reading won't go beyond the end of the section. */
19904 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19905 error (_("Reading DW_FORM_rnglistx index beyond end of"
19906 ".debug_rnglists section [in module %s]"),
19907 objfile_name (objfile
));
19909 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19911 if (cu
->header
.offset_size
== 4)
19912 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19914 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19917 /* Process the attributes that had to be skipped in the first round. These
19918 attributes are the ones that need str_offsets_base or addr_base attributes.
19919 They could not have been processed in the first round, because at the time
19920 the values of str_offsets_base or addr_base may not have been known. */
19922 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19923 struct attribute
*attr
, dwarf_tag tag
)
19925 struct dwarf2_cu
*cu
= reader
->cu
;
19926 switch (attr
->form
)
19928 case DW_FORM_addrx
:
19929 case DW_FORM_GNU_addr_index
:
19930 attr
->set_address (read_addr_index (cu
,
19931 attr
->as_unsigned_reprocess ()));
19933 case DW_FORM_loclistx
:
19935 sect_offset loclists_sect_off
19936 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19938 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19941 case DW_FORM_rnglistx
:
19943 sect_offset rnglists_sect_off
19944 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19946 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19950 case DW_FORM_strx1
:
19951 case DW_FORM_strx2
:
19952 case DW_FORM_strx3
:
19953 case DW_FORM_strx4
:
19954 case DW_FORM_GNU_str_index
:
19956 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19957 gdb_assert (!attr
->canonical_string_p ());
19958 if (reader
->dwo_file
!= NULL
)
19959 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19962 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19967 gdb_assert_not_reached ("Unexpected DWARF form.");
19971 /* Read an attribute value described by an attribute form. */
19973 static const gdb_byte
*
19974 read_attribute_value (const struct die_reader_specs
*reader
,
19975 struct attribute
*attr
, unsigned form
,
19976 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19978 struct dwarf2_cu
*cu
= reader
->cu
;
19979 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19980 struct objfile
*objfile
= per_objfile
->objfile
;
19981 bfd
*abfd
= reader
->abfd
;
19982 struct comp_unit_head
*cu_header
= &cu
->header
;
19983 unsigned int bytes_read
;
19984 struct dwarf_block
*blk
;
19986 attr
->form
= (enum dwarf_form
) form
;
19989 case DW_FORM_ref_addr
:
19990 if (cu_header
->version
== 2)
19991 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19994 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19996 info_ptr
+= bytes_read
;
19998 case DW_FORM_GNU_ref_alt
:
19999 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20001 info_ptr
+= bytes_read
;
20005 struct gdbarch
*gdbarch
= objfile
->arch ();
20006 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20007 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20008 attr
->set_address (addr
);
20009 info_ptr
+= bytes_read
;
20012 case DW_FORM_block2
:
20013 blk
= dwarf_alloc_block (cu
);
20014 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20016 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20017 info_ptr
+= blk
->size
;
20018 attr
->set_block (blk
);
20020 case DW_FORM_block4
:
20021 blk
= dwarf_alloc_block (cu
);
20022 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20024 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20025 info_ptr
+= blk
->size
;
20026 attr
->set_block (blk
);
20028 case DW_FORM_data2
:
20029 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20032 case DW_FORM_data4
:
20033 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20036 case DW_FORM_data8
:
20037 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20040 case DW_FORM_data16
:
20041 blk
= dwarf_alloc_block (cu
);
20043 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20045 attr
->set_block (blk
);
20047 case DW_FORM_sec_offset
:
20048 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20050 info_ptr
+= bytes_read
;
20052 case DW_FORM_loclistx
:
20054 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20056 info_ptr
+= bytes_read
;
20059 case DW_FORM_string
:
20060 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20062 info_ptr
+= bytes_read
;
20065 if (!cu
->per_cu
->is_dwz
)
20067 attr
->set_string_noncanonical
20068 (read_indirect_string (per_objfile
,
20069 abfd
, info_ptr
, cu_header
,
20071 info_ptr
+= bytes_read
;
20075 case DW_FORM_line_strp
:
20076 if (!cu
->per_cu
->is_dwz
)
20078 attr
->set_string_noncanonical
20079 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20081 info_ptr
+= bytes_read
;
20085 case DW_FORM_GNU_strp_alt
:
20087 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20088 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20091 attr
->set_string_noncanonical
20092 (dwz
->read_string (objfile
, str_offset
));
20093 info_ptr
+= bytes_read
;
20096 case DW_FORM_exprloc
:
20097 case DW_FORM_block
:
20098 blk
= dwarf_alloc_block (cu
);
20099 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20100 info_ptr
+= bytes_read
;
20101 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20102 info_ptr
+= blk
->size
;
20103 attr
->set_block (blk
);
20105 case DW_FORM_block1
:
20106 blk
= dwarf_alloc_block (cu
);
20107 blk
->size
= read_1_byte (abfd
, info_ptr
);
20109 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20110 info_ptr
+= blk
->size
;
20111 attr
->set_block (blk
);
20113 case DW_FORM_data1
:
20115 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20118 case DW_FORM_flag_present
:
20119 attr
->set_unsigned (1);
20121 case DW_FORM_sdata
:
20122 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20123 info_ptr
+= bytes_read
;
20125 case DW_FORM_rnglistx
:
20127 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20129 info_ptr
+= bytes_read
;
20132 case DW_FORM_udata
:
20133 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20134 info_ptr
+= bytes_read
;
20137 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20138 + read_1_byte (abfd
, info_ptr
)));
20142 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20143 + read_2_bytes (abfd
, info_ptr
)));
20147 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20148 + read_4_bytes (abfd
, info_ptr
)));
20152 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20153 + read_8_bytes (abfd
, info_ptr
)));
20156 case DW_FORM_ref_sig8
:
20157 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20160 case DW_FORM_ref_udata
:
20161 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20162 + read_unsigned_leb128 (abfd
, info_ptr
,
20164 info_ptr
+= bytes_read
;
20166 case DW_FORM_indirect
:
20167 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20168 info_ptr
+= bytes_read
;
20169 if (form
== DW_FORM_implicit_const
)
20171 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20172 info_ptr
+= bytes_read
;
20174 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20177 case DW_FORM_implicit_const
:
20178 attr
->set_signed (implicit_const
);
20180 case DW_FORM_addrx
:
20181 case DW_FORM_GNU_addr_index
:
20182 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20184 info_ptr
+= bytes_read
;
20187 case DW_FORM_strx1
:
20188 case DW_FORM_strx2
:
20189 case DW_FORM_strx3
:
20190 case DW_FORM_strx4
:
20191 case DW_FORM_GNU_str_index
:
20193 ULONGEST str_index
;
20194 if (form
== DW_FORM_strx1
)
20196 str_index
= read_1_byte (abfd
, info_ptr
);
20199 else if (form
== DW_FORM_strx2
)
20201 str_index
= read_2_bytes (abfd
, info_ptr
);
20204 else if (form
== DW_FORM_strx3
)
20206 str_index
= read_3_bytes (abfd
, info_ptr
);
20209 else if (form
== DW_FORM_strx4
)
20211 str_index
= read_4_bytes (abfd
, info_ptr
);
20216 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20217 info_ptr
+= bytes_read
;
20219 attr
->set_unsigned_reprocess (str_index
);
20223 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20224 dwarf_form_name (form
),
20225 bfd_get_filename (abfd
));
20229 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20230 attr
->form
= DW_FORM_GNU_ref_alt
;
20232 /* We have seen instances where the compiler tried to emit a byte
20233 size attribute of -1 which ended up being encoded as an unsigned
20234 0xffffffff. Although 0xffffffff is technically a valid size value,
20235 an object of this size seems pretty unlikely so we can relatively
20236 safely treat these cases as if the size attribute was invalid and
20237 treat them as zero by default. */
20238 if (attr
->name
== DW_AT_byte_size
20239 && form
== DW_FORM_data4
20240 && attr
->as_unsigned () >= 0xffffffff)
20243 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20244 hex_string (attr
->as_unsigned ()));
20245 attr
->set_unsigned (0);
20251 /* Read an attribute described by an abbreviated attribute. */
20253 static const gdb_byte
*
20254 read_attribute (const struct die_reader_specs
*reader
,
20255 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20256 const gdb_byte
*info_ptr
)
20258 attr
->name
= abbrev
->name
;
20259 attr
->string_is_canonical
= 0;
20260 attr
->requires_reprocessing
= 0;
20261 return read_attribute_value (reader
, attr
, abbrev
->form
,
20262 abbrev
->implicit_const
, info_ptr
);
20265 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20267 static const char *
20268 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20269 LONGEST str_offset
)
20271 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20272 str_offset
, "DW_FORM_strp");
20275 /* Return pointer to string at .debug_str offset as read from BUF.
20276 BUF is assumed to be in a compilation unit described by CU_HEADER.
20277 Return *BYTES_READ_PTR count of bytes read from BUF. */
20279 static const char *
20280 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20281 const gdb_byte
*buf
,
20282 const struct comp_unit_head
*cu_header
,
20283 unsigned int *bytes_read_ptr
)
20285 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20287 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20293 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20294 unsigned int offset_size
)
20296 bfd
*abfd
= objfile
->obfd
;
20297 ULONGEST str_offset
= read_offset (abfd
, buf
, offset_size
);
20299 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20305 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20306 const struct comp_unit_head
*cu_header
,
20307 unsigned int *bytes_read_ptr
)
20309 bfd
*abfd
= objfile
->obfd
;
20310 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20312 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20315 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20316 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20317 ADDR_SIZE is the size of addresses from the CU header. */
20320 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20321 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20323 struct objfile
*objfile
= per_objfile
->objfile
;
20324 bfd
*abfd
= objfile
->obfd
;
20325 const gdb_byte
*info_ptr
;
20326 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20328 per_objfile
->per_bfd
->addr
.read (objfile
);
20329 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20330 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20331 objfile_name (objfile
));
20332 if (addr_base_or_zero
+ addr_index
* addr_size
20333 >= per_objfile
->per_bfd
->addr
.size
)
20334 error (_("DW_FORM_addr_index pointing outside of "
20335 ".debug_addr section [in module %s]"),
20336 objfile_name (objfile
));
20337 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20338 + addr_index
* addr_size
);
20339 if (addr_size
== 4)
20340 return bfd_get_32 (abfd
, info_ptr
);
20342 return bfd_get_64 (abfd
, info_ptr
);
20345 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20348 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20350 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20351 cu
->addr_base
, cu
->header
.addr_size
);
20354 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20357 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20358 unsigned int *bytes_read
)
20360 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20361 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20363 return read_addr_index (cu
, addr_index
);
20369 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20370 dwarf2_per_objfile
*per_objfile
,
20371 unsigned int addr_index
)
20373 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20374 gdb::optional
<ULONGEST
> addr_base
;
20377 /* We need addr_base and addr_size.
20378 If we don't have PER_CU->cu, we have to get it.
20379 Nasty, but the alternative is storing the needed info in PER_CU,
20380 which at this point doesn't seem justified: it's not clear how frequently
20381 it would get used and it would increase the size of every PER_CU.
20382 Entry points like dwarf2_per_cu_addr_size do a similar thing
20383 so we're not in uncharted territory here.
20384 Alas we need to be a bit more complicated as addr_base is contained
20387 We don't need to read the entire CU(/TU).
20388 We just need the header and top level die.
20390 IWBN to use the aging mechanism to let us lazily later discard the CU.
20391 For now we skip this optimization. */
20395 addr_base
= cu
->addr_base
;
20396 addr_size
= cu
->header
.addr_size
;
20400 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20401 addr_base
= reader
.cu
->addr_base
;
20402 addr_size
= reader
.cu
->header
.addr_size
;
20405 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20408 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20409 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20412 static const char *
20413 read_str_index (struct dwarf2_cu
*cu
,
20414 struct dwarf2_section_info
*str_section
,
20415 struct dwarf2_section_info
*str_offsets_section
,
20416 ULONGEST str_offsets_base
, ULONGEST str_index
)
20418 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20419 struct objfile
*objfile
= per_objfile
->objfile
;
20420 const char *objf_name
= objfile_name (objfile
);
20421 bfd
*abfd
= objfile
->obfd
;
20422 const gdb_byte
*info_ptr
;
20423 ULONGEST str_offset
;
20424 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20426 str_section
->read (objfile
);
20427 str_offsets_section
->read (objfile
);
20428 if (str_section
->buffer
== NULL
)
20429 error (_("%s used without %s section"
20430 " in CU at offset %s [in module %s]"),
20431 form_name
, str_section
->get_name (),
20432 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20433 if (str_offsets_section
->buffer
== NULL
)
20434 error (_("%s used without %s section"
20435 " in CU at offset %s [in module %s]"),
20436 form_name
, str_section
->get_name (),
20437 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20438 info_ptr
= (str_offsets_section
->buffer
20440 + str_index
* cu
->header
.offset_size
);
20441 if (cu
->header
.offset_size
== 4)
20442 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20444 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20445 if (str_offset
>= str_section
->size
)
20446 error (_("Offset from %s pointing outside of"
20447 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20448 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20449 return (const char *) (str_section
->buffer
+ str_offset
);
20452 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20454 static const char *
20455 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20457 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20458 ? reader
->cu
->header
.addr_size
: 0;
20459 return read_str_index (reader
->cu
,
20460 &reader
->dwo_file
->sections
.str
,
20461 &reader
->dwo_file
->sections
.str_offsets
,
20462 str_offsets_base
, str_index
);
20465 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20467 static const char *
20468 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20470 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20471 const char *objf_name
= objfile_name (objfile
);
20472 static const char form_name
[] = "DW_FORM_GNU_str_index";
20473 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20475 if (!cu
->str_offsets_base
.has_value ())
20476 error (_("%s used in Fission stub without %s"
20477 " in CU at offset 0x%lx [in module %s]"),
20478 form_name
, str_offsets_attr_name
,
20479 (long) cu
->header
.offset_size
, objf_name
);
20481 return read_str_index (cu
,
20482 &cu
->per_objfile
->per_bfd
->str
,
20483 &cu
->per_objfile
->per_bfd
->str_offsets
,
20484 *cu
->str_offsets_base
, str_index
);
20487 /* Return the length of an LEB128 number in BUF. */
20490 leb128_size (const gdb_byte
*buf
)
20492 const gdb_byte
*begin
= buf
;
20498 if ((byte
& 128) == 0)
20499 return buf
- begin
;
20503 static enum language
20504 dwarf_lang_to_enum_language (unsigned int lang
)
20506 enum language language
;
20515 language
= language_c
;
20518 case DW_LANG_C_plus_plus
:
20519 case DW_LANG_C_plus_plus_11
:
20520 case DW_LANG_C_plus_plus_14
:
20521 language
= language_cplus
;
20524 language
= language_d
;
20526 case DW_LANG_Fortran77
:
20527 case DW_LANG_Fortran90
:
20528 case DW_LANG_Fortran95
:
20529 case DW_LANG_Fortran03
:
20530 case DW_LANG_Fortran08
:
20531 language
= language_fortran
;
20534 language
= language_go
;
20536 case DW_LANG_Mips_Assembler
:
20537 language
= language_asm
;
20539 case DW_LANG_Ada83
:
20540 case DW_LANG_Ada95
:
20541 language
= language_ada
;
20543 case DW_LANG_Modula2
:
20544 language
= language_m2
;
20546 case DW_LANG_Pascal83
:
20547 language
= language_pascal
;
20550 language
= language_objc
;
20553 case DW_LANG_Rust_old
:
20554 language
= language_rust
;
20556 case DW_LANG_OpenCL
:
20557 language
= language_opencl
;
20559 case DW_LANG_Cobol74
:
20560 case DW_LANG_Cobol85
:
20562 language
= language_minimal
;
20569 /* Return the named attribute or NULL if not there. */
20571 static struct attribute
*
20572 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20577 struct attribute
*spec
= NULL
;
20579 for (i
= 0; i
< die
->num_attrs
; ++i
)
20581 if (die
->attrs
[i
].name
== name
)
20582 return &die
->attrs
[i
];
20583 if (die
->attrs
[i
].name
== DW_AT_specification
20584 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20585 spec
= &die
->attrs
[i
];
20591 die
= follow_die_ref (die
, spec
, &cu
);
20597 /* Return the string associated with a string-typed attribute, or NULL if it
20598 is either not found or is of an incorrect type. */
20600 static const char *
20601 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20603 struct attribute
*attr
;
20604 const char *str
= NULL
;
20606 attr
= dwarf2_attr (die
, name
, cu
);
20610 str
= attr
->as_string ();
20611 if (str
== nullptr)
20612 complaint (_("string type expected for attribute %s for "
20613 "DIE at %s in module %s"),
20614 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20615 objfile_name (cu
->per_objfile
->objfile
));
20621 /* Return the dwo name or NULL if not present. If present, it is in either
20622 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20623 static const char *
20624 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20626 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20627 if (dwo_name
== nullptr)
20628 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20632 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20633 and holds a non-zero value. This function should only be used for
20634 DW_FORM_flag or DW_FORM_flag_present attributes. */
20637 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20639 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20641 return attr
!= nullptr && attr
->as_boolean ();
20645 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20647 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20648 which value is non-zero. However, we have to be careful with
20649 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20650 (via dwarf2_flag_true_p) follows this attribute. So we may
20651 end up accidently finding a declaration attribute that belongs
20652 to a different DIE referenced by the specification attribute,
20653 even though the given DIE does not have a declaration attribute. */
20654 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20655 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20658 /* Return the die giving the specification for DIE, if there is
20659 one. *SPEC_CU is the CU containing DIE on input, and the CU
20660 containing the return value on output. If there is no
20661 specification, but there is an abstract origin, that is
20664 static struct die_info
*
20665 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20667 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20670 if (spec_attr
== NULL
)
20671 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20673 if (spec_attr
== NULL
)
20676 return follow_die_ref (die
, spec_attr
, spec_cu
);
20679 /* A convenience function to find the proper .debug_line section for a CU. */
20681 static struct dwarf2_section_info
*
20682 get_debug_line_section (struct dwarf2_cu
*cu
)
20684 struct dwarf2_section_info
*section
;
20685 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20687 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20689 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20690 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20691 else if (cu
->per_cu
->is_dwz
)
20693 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20695 section
= &dwz
->line
;
20698 section
= &per_objfile
->per_bfd
->line
;
20703 /* Read the statement program header starting at OFFSET in
20704 .debug_line, or .debug_line.dwo. Return a pointer
20705 to a struct line_header, allocated using xmalloc.
20706 Returns NULL if there is a problem reading the header, e.g., if it
20707 has a version we don't understand.
20709 NOTE: the strings in the include directory and file name tables of
20710 the returned object point into the dwarf line section buffer,
20711 and must not be freed. */
20713 static line_header_up
20714 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20716 struct dwarf2_section_info
*section
;
20717 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20719 section
= get_debug_line_section (cu
);
20720 section
->read (per_objfile
->objfile
);
20721 if (section
->buffer
== NULL
)
20723 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20724 complaint (_("missing .debug_line.dwo section"));
20726 complaint (_("missing .debug_line section"));
20730 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20731 per_objfile
, section
, &cu
->header
);
20734 /* Subroutine of dwarf_decode_lines to simplify it.
20735 Return the file name for the given file_entry.
20736 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
20737 If space for the result is malloc'd, *NAME_HOLDER will be set.
20738 Returns NULL if FILE_INDEX should be ignored, i.e., it is
20739 equivalent to CU_INFO. */
20741 static const char *
20742 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20743 const file_and_directory
&cu_info
,
20744 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20746 const char *include_name
= fe
.name
;
20747 const char *include_name_to_compare
= include_name
;
20749 const char *dir_name
= fe
.include_dir (lh
);
20751 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20752 if (!IS_ABSOLUTE_PATH (include_name
)
20753 && (dir_name
!= nullptr || cu_info
.get_comp_dir () != nullptr))
20755 /* Avoid creating a duplicate name for CU_INFO.
20756 We do this by comparing INCLUDE_NAME and CU_INFO.
20757 Before we do the comparison, however, we need to account
20758 for DIR_NAME and COMP_DIR.
20759 First prepend dir_name (if non-NULL). If we still don't
20760 have an absolute path prepend comp_dir (if non-NULL).
20761 However, the directory we record in the include-file's
20762 psymtab does not contain COMP_DIR (to match the
20763 corresponding symtab(s)).
20768 bash$ gcc -g ./hello.c
20769 include_name = "hello.c"
20771 DW_AT_comp_dir = comp_dir = "/tmp"
20772 DW_AT_name = "./hello.c"
20776 if (dir_name
!= NULL
)
20778 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20779 include_name
, (char *) NULL
));
20780 include_name
= name_holder
->get ();
20781 include_name_to_compare
= include_name
;
20783 if (!IS_ABSOLUTE_PATH (include_name
)
20784 && cu_info
.get_comp_dir () != nullptr)
20786 hold_compare
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20787 include_name
, (char *) NULL
));
20788 include_name_to_compare
= hold_compare
.get ();
20792 gdb::unique_xmalloc_ptr
<char> copied_name
;
20793 const char *cu_filename
= cu_info
.get_name ();
20794 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.get_comp_dir () != nullptr)
20796 copied_name
.reset (concat (cu_info
.get_comp_dir (), SLASH_STRING
,
20797 cu_filename
, (char *) NULL
));
20798 cu_filename
= copied_name
.get ();
20801 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
20803 return include_name
;
20806 /* State machine to track the state of the line number program. */
20808 class lnp_state_machine
20811 /* Initialize a machine state for the start of a line number
20813 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20814 bool record_lines_p
);
20816 file_entry
*current_file ()
20818 /* lh->file_names is 0-based, but the file name numbers in the
20819 statement program are 1-based. */
20820 return m_line_header
->file_name_at (m_file
);
20823 /* Record the line in the state machine. END_SEQUENCE is true if
20824 we're processing the end of a sequence. */
20825 void record_line (bool end_sequence
);
20827 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20828 nop-out rest of the lines in this sequence. */
20829 void check_line_address (struct dwarf2_cu
*cu
,
20830 const gdb_byte
*line_ptr
,
20831 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20833 void handle_set_discriminator (unsigned int discriminator
)
20835 m_discriminator
= discriminator
;
20836 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20839 /* Handle DW_LNE_set_address. */
20840 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20843 address
+= baseaddr
;
20844 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20847 /* Handle DW_LNS_advance_pc. */
20848 void handle_advance_pc (CORE_ADDR adjust
);
20850 /* Handle a special opcode. */
20851 void handle_special_opcode (unsigned char op_code
);
20853 /* Handle DW_LNS_advance_line. */
20854 void handle_advance_line (int line_delta
)
20856 advance_line (line_delta
);
20859 /* Handle DW_LNS_set_file. */
20860 void handle_set_file (file_name_index file
);
20862 /* Handle DW_LNS_negate_stmt. */
20863 void handle_negate_stmt ()
20865 m_is_stmt
= !m_is_stmt
;
20868 /* Handle DW_LNS_const_add_pc. */
20869 void handle_const_add_pc ();
20871 /* Handle DW_LNS_fixed_advance_pc. */
20872 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20874 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20878 /* Handle DW_LNS_copy. */
20879 void handle_copy ()
20881 record_line (false);
20882 m_discriminator
= 0;
20885 /* Handle DW_LNE_end_sequence. */
20886 void handle_end_sequence ()
20888 m_currently_recording_lines
= true;
20892 /* Advance the line by LINE_DELTA. */
20893 void advance_line (int line_delta
)
20895 m_line
+= line_delta
;
20897 if (line_delta
!= 0)
20898 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20901 struct dwarf2_cu
*m_cu
;
20903 gdbarch
*m_gdbarch
;
20905 /* True if we're recording lines.
20906 Otherwise we're building partial symtabs and are just interested in
20907 finding include files mentioned by the line number program. */
20908 bool m_record_lines_p
;
20910 /* The line number header. */
20911 line_header
*m_line_header
;
20913 /* These are part of the standard DWARF line number state machine,
20914 and initialized according to the DWARF spec. */
20916 unsigned char m_op_index
= 0;
20917 /* The line table index of the current file. */
20918 file_name_index m_file
= 1;
20919 unsigned int m_line
= 1;
20921 /* These are initialized in the constructor. */
20923 CORE_ADDR m_address
;
20925 unsigned int m_discriminator
;
20927 /* Additional bits of state we need to track. */
20929 /* The last file that we called dwarf2_start_subfile for.
20930 This is only used for TLLs. */
20931 unsigned int m_last_file
= 0;
20932 /* The last file a line number was recorded for. */
20933 struct subfile
*m_last_subfile
= NULL
;
20935 /* The address of the last line entry. */
20936 CORE_ADDR m_last_address
;
20938 /* Set to true when a previous line at the same address (using
20939 m_last_address) had m_is_stmt true. This is reset to false when a
20940 line entry at a new address (m_address different to m_last_address) is
20942 bool m_stmt_at_address
= false;
20944 /* When true, record the lines we decode. */
20945 bool m_currently_recording_lines
= false;
20947 /* The last line number that was recorded, used to coalesce
20948 consecutive entries for the same line. This can happen, for
20949 example, when discriminators are present. PR 17276. */
20950 unsigned int m_last_line
= 0;
20951 bool m_line_has_non_zero_discriminator
= false;
20955 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20957 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20958 / m_line_header
->maximum_ops_per_instruction
)
20959 * m_line_header
->minimum_instruction_length
);
20960 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20961 m_op_index
= ((m_op_index
+ adjust
)
20962 % m_line_header
->maximum_ops_per_instruction
);
20966 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20968 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20969 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20970 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20971 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20972 / m_line_header
->maximum_ops_per_instruction
)
20973 * m_line_header
->minimum_instruction_length
);
20974 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20975 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20976 % m_line_header
->maximum_ops_per_instruction
);
20978 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20979 advance_line (line_delta
);
20980 record_line (false);
20981 m_discriminator
= 0;
20985 lnp_state_machine::handle_set_file (file_name_index file
)
20989 const file_entry
*fe
= current_file ();
20991 dwarf2_debug_line_missing_file_complaint ();
20992 else if (m_record_lines_p
)
20994 const char *dir
= fe
->include_dir (m_line_header
);
20996 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20997 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20998 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21003 lnp_state_machine::handle_const_add_pc ()
21006 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21009 = (((m_op_index
+ adjust
)
21010 / m_line_header
->maximum_ops_per_instruction
)
21011 * m_line_header
->minimum_instruction_length
);
21013 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21014 m_op_index
= ((m_op_index
+ adjust
)
21015 % m_line_header
->maximum_ops_per_instruction
);
21018 /* Return non-zero if we should add LINE to the line number table.
21019 LINE is the line to add, LAST_LINE is the last line that was added,
21020 LAST_SUBFILE is the subfile for LAST_LINE.
21021 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21022 had a non-zero discriminator.
21024 We have to be careful in the presence of discriminators.
21025 E.g., for this line:
21027 for (i = 0; i < 100000; i++);
21029 clang can emit four line number entries for that one line,
21030 each with a different discriminator.
21031 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21033 However, we want gdb to coalesce all four entries into one.
21034 Otherwise the user could stepi into the middle of the line and
21035 gdb would get confused about whether the pc really was in the
21036 middle of the line.
21038 Things are further complicated by the fact that two consecutive
21039 line number entries for the same line is a heuristic used by gcc
21040 to denote the end of the prologue. So we can't just discard duplicate
21041 entries, we have to be selective about it. The heuristic we use is
21042 that we only collapse consecutive entries for the same line if at least
21043 one of those entries has a non-zero discriminator. PR 17276.
21045 Note: Addresses in the line number state machine can never go backwards
21046 within one sequence, thus this coalescing is ok. */
21049 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21050 unsigned int line
, unsigned int last_line
,
21051 int line_has_non_zero_discriminator
,
21052 struct subfile
*last_subfile
)
21054 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21056 if (line
!= last_line
)
21058 /* Same line for the same file that we've seen already.
21059 As a last check, for pr 17276, only record the line if the line
21060 has never had a non-zero discriminator. */
21061 if (!line_has_non_zero_discriminator
)
21066 /* Use the CU's builder to record line number LINE beginning at
21067 address ADDRESS in the line table of subfile SUBFILE. */
21070 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21071 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21072 struct dwarf2_cu
*cu
)
21074 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21076 if (dwarf_line_debug
)
21078 fprintf_unfiltered (gdb_stdlog
,
21079 "Recording line %u, file %s, address %s\n",
21080 line
, lbasename (subfile
->name
),
21081 paddress (gdbarch
, address
));
21085 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21088 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21089 Mark the end of a set of line number records.
21090 The arguments are the same as for dwarf_record_line_1.
21091 If SUBFILE is NULL the request is ignored. */
21094 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21095 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21097 if (subfile
== NULL
)
21100 if (dwarf_line_debug
)
21102 fprintf_unfiltered (gdb_stdlog
,
21103 "Finishing current line, file %s, address %s\n",
21104 lbasename (subfile
->name
),
21105 paddress (gdbarch
, address
));
21108 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21112 lnp_state_machine::record_line (bool end_sequence
)
21114 if (dwarf_line_debug
)
21116 fprintf_unfiltered (gdb_stdlog
,
21117 "Processing actual line %u: file %u,"
21118 " address %s, is_stmt %u, discrim %u%s\n",
21120 paddress (m_gdbarch
, m_address
),
21121 m_is_stmt
, m_discriminator
,
21122 (end_sequence
? "\t(end sequence)" : ""));
21125 file_entry
*fe
= current_file ();
21128 dwarf2_debug_line_missing_file_complaint ();
21129 /* For now we ignore lines not starting on an instruction boundary.
21130 But not when processing end_sequence for compatibility with the
21131 previous version of the code. */
21132 else if (m_op_index
== 0 || end_sequence
)
21134 fe
->included_p
= true;
21135 if (m_record_lines_p
)
21137 /* When we switch files we insert an end maker in the first file,
21138 switch to the second file and add a new line entry. The
21139 problem is that the end marker inserted in the first file will
21140 discard any previous line entries at the same address. If the
21141 line entries in the first file are marked as is-stmt, while
21142 the new line in the second file is non-stmt, then this means
21143 the end marker will discard is-stmt lines so we can have a
21144 non-stmt line. This means that there are less addresses at
21145 which the user can insert a breakpoint.
21147 To improve this we track the last address in m_last_address,
21148 and whether we have seen an is-stmt at this address. Then
21149 when switching files, if we have seen a stmt at the current
21150 address, and we are switching to create a non-stmt line, then
21151 discard the new line. */
21153 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21154 bool ignore_this_line
21155 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21156 && !m_is_stmt
&& m_stmt_at_address
)
21157 || (!end_sequence
&& m_line
== 0));
21159 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21161 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21162 m_currently_recording_lines
? m_cu
: nullptr);
21165 if (!end_sequence
&& !ignore_this_line
)
21167 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21169 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21170 m_line_has_non_zero_discriminator
,
21173 buildsym_compunit
*builder
= m_cu
->get_builder ();
21174 dwarf_record_line_1 (m_gdbarch
,
21175 builder
->get_current_subfile (),
21176 m_line
, m_address
, is_stmt
,
21177 m_currently_recording_lines
? m_cu
: nullptr);
21179 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21180 m_last_line
= m_line
;
21185 /* Track whether we have seen any m_is_stmt true at m_address in case we
21186 have multiple line table entries all at m_address. */
21187 if (m_last_address
!= m_address
)
21189 m_stmt_at_address
= false;
21190 m_last_address
= m_address
;
21192 m_stmt_at_address
|= m_is_stmt
;
21195 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21196 line_header
*lh
, bool record_lines_p
)
21200 m_record_lines_p
= record_lines_p
;
21201 m_line_header
= lh
;
21203 m_currently_recording_lines
= true;
21205 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21206 was a line entry for it so that the backend has a chance to adjust it
21207 and also record it in case it needs it. This is currently used by MIPS
21208 code, cf. `mips_adjust_dwarf2_line'. */
21209 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21210 m_is_stmt
= lh
->default_is_stmt
;
21211 m_discriminator
= 0;
21213 m_last_address
= m_address
;
21214 m_stmt_at_address
= false;
21218 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21219 const gdb_byte
*line_ptr
,
21220 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21222 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21223 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21224 located at 0x0. In this case, additionally check that if
21225 ADDRESS < UNRELOCATED_LOWPC. */
21227 if ((address
== 0 && address
< unrelocated_lowpc
)
21228 || address
== (CORE_ADDR
) -1)
21230 /* This line table is for a function which has been
21231 GCd by the linker. Ignore it. PR gdb/12528 */
21233 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21234 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21236 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21237 line_offset
, objfile_name (objfile
));
21238 m_currently_recording_lines
= false;
21239 /* Note: m_currently_recording_lines is left as false until we see
21240 DW_LNE_end_sequence. */
21244 /* Subroutine of dwarf_decode_lines to simplify it.
21245 Process the line number information in LH.
21246 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21247 program in order to set included_p for every referenced header. */
21250 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21251 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21253 const gdb_byte
*line_ptr
, *extended_end
;
21254 const gdb_byte
*line_end
;
21255 unsigned int bytes_read
, extended_len
;
21256 unsigned char op_code
, extended_op
;
21257 CORE_ADDR baseaddr
;
21258 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21259 bfd
*abfd
= objfile
->obfd
;
21260 struct gdbarch
*gdbarch
= objfile
->arch ();
21261 /* True if we're recording line info (as opposed to building partial
21262 symtabs and just interested in finding include files mentioned by
21263 the line number program). */
21264 bool record_lines_p
= !decode_for_pst_p
;
21266 baseaddr
= objfile
->text_section_offset ();
21268 line_ptr
= lh
->statement_program_start
;
21269 line_end
= lh
->statement_program_end
;
21271 /* Read the statement sequences until there's nothing left. */
21272 while (line_ptr
< line_end
)
21274 /* The DWARF line number program state machine. Reset the state
21275 machine at the start of each sequence. */
21276 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21277 bool end_sequence
= false;
21279 if (record_lines_p
)
21281 /* Start a subfile for the current file of the state
21283 const file_entry
*fe
= state_machine
.current_file ();
21286 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21289 /* Decode the table. */
21290 while (line_ptr
< line_end
&& !end_sequence
)
21292 op_code
= read_1_byte (abfd
, line_ptr
);
21295 if (op_code
>= lh
->opcode_base
)
21297 /* Special opcode. */
21298 state_machine
.handle_special_opcode (op_code
);
21300 else switch (op_code
)
21302 case DW_LNS_extended_op
:
21303 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21305 line_ptr
+= bytes_read
;
21306 extended_end
= line_ptr
+ extended_len
;
21307 extended_op
= read_1_byte (abfd
, line_ptr
);
21309 if (DW_LNE_lo_user
<= extended_op
21310 && extended_op
<= DW_LNE_hi_user
)
21312 /* Vendor extension, ignore. */
21313 line_ptr
= extended_end
;
21316 switch (extended_op
)
21318 case DW_LNE_end_sequence
:
21319 state_machine
.handle_end_sequence ();
21320 end_sequence
= true;
21322 case DW_LNE_set_address
:
21325 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21326 line_ptr
+= bytes_read
;
21328 state_machine
.check_line_address (cu
, line_ptr
,
21329 lowpc
- baseaddr
, address
);
21330 state_machine
.handle_set_address (baseaddr
, address
);
21333 case DW_LNE_define_file
:
21335 const char *cur_file
;
21336 unsigned int mod_time
, length
;
21339 cur_file
= read_direct_string (abfd
, line_ptr
,
21341 line_ptr
+= bytes_read
;
21342 dindex
= (dir_index
)
21343 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21344 line_ptr
+= bytes_read
;
21346 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21347 line_ptr
+= bytes_read
;
21349 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21350 line_ptr
+= bytes_read
;
21351 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21354 case DW_LNE_set_discriminator
:
21356 /* The discriminator is not interesting to the
21357 debugger; just ignore it. We still need to
21358 check its value though:
21359 if there are consecutive entries for the same
21360 (non-prologue) line we want to coalesce them.
21363 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21364 line_ptr
+= bytes_read
;
21366 state_machine
.handle_set_discriminator (discr
);
21370 complaint (_("mangled .debug_line section"));
21373 /* Make sure that we parsed the extended op correctly. If e.g.
21374 we expected a different address size than the producer used,
21375 we may have read the wrong number of bytes. */
21376 if (line_ptr
!= extended_end
)
21378 complaint (_("mangled .debug_line section"));
21383 state_machine
.handle_copy ();
21385 case DW_LNS_advance_pc
:
21388 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21389 line_ptr
+= bytes_read
;
21391 state_machine
.handle_advance_pc (adjust
);
21394 case DW_LNS_advance_line
:
21397 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21398 line_ptr
+= bytes_read
;
21400 state_machine
.handle_advance_line (line_delta
);
21403 case DW_LNS_set_file
:
21405 file_name_index file
21406 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21408 line_ptr
+= bytes_read
;
21410 state_machine
.handle_set_file (file
);
21413 case DW_LNS_set_column
:
21414 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21415 line_ptr
+= bytes_read
;
21417 case DW_LNS_negate_stmt
:
21418 state_machine
.handle_negate_stmt ();
21420 case DW_LNS_set_basic_block
:
21422 /* Add to the address register of the state machine the
21423 address increment value corresponding to special opcode
21424 255. I.e., this value is scaled by the minimum
21425 instruction length since special opcode 255 would have
21426 scaled the increment. */
21427 case DW_LNS_const_add_pc
:
21428 state_machine
.handle_const_add_pc ();
21430 case DW_LNS_fixed_advance_pc
:
21432 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21435 state_machine
.handle_fixed_advance_pc (addr_adj
);
21440 /* Unknown standard opcode, ignore it. */
21443 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21445 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21446 line_ptr
+= bytes_read
;
21453 dwarf2_debug_line_missing_end_sequence_complaint ();
21455 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21456 in which case we still finish recording the last line). */
21457 state_machine
.record_line (true);
21461 /* Decode the Line Number Program (LNP) for the given line_header
21462 structure and CU. The actual information extracted and the type
21463 of structures created from the LNP depends on the value of PST.
21465 1. If PST is NULL, then this procedure uses the data from the program
21466 to create all necessary symbol tables, and their linetables.
21468 2. If PST is not NULL, this procedure reads the program to determine
21469 the list of files included by the unit represented by PST, and
21470 builds all the associated partial symbol tables.
21472 FND holds the CU file name and directory, if known.
21473 It is used for relative paths in the line table.
21475 NOTE: It is important that psymtabs have the same file name (via
21476 strcmp) as the corresponding symtab. Since the directory is not
21477 used in the name of the symtab we don't use it in the name of the
21478 psymtabs we create. E.g. expand_line_sal requires this when
21479 finding psymtabs to expand. A good testcase for this is
21482 LOWPC is the lowest address in CU (or 0 if not known).
21484 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21485 for its PC<->lines mapping information. Otherwise only the filename
21486 table is read in. */
21489 dwarf_decode_lines (struct line_header
*lh
, const file_and_directory
&fnd
,
21490 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21491 CORE_ADDR lowpc
, int decode_mapping
)
21493 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21494 const int decode_for_pst_p
= (pst
!= NULL
);
21496 if (decode_mapping
)
21497 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21499 if (decode_for_pst_p
)
21501 /* Now that we're done scanning the Line Header Program, we can
21502 create the psymtab of each included file. */
21503 for (auto &file_entry
: lh
->file_names ())
21504 if (file_entry
.included_p
)
21506 gdb::unique_xmalloc_ptr
<char> name_holder
;
21507 const char *include_name
=
21508 compute_include_file_name (lh
, file_entry
, fnd
, &name_holder
);
21509 if (include_name
!= NULL
)
21510 dwarf2_create_include_psymtab
21511 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21512 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21518 /* Make sure a symtab is created for every file, even files
21519 which contain only variables (i.e. no code with associated
21521 buildsym_compunit
*builder
= cu
->get_builder ();
21522 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21524 for (auto &fe
: lh
->file_names ())
21526 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21527 if (builder
->get_current_subfile ()->symtab
== NULL
)
21529 builder
->get_current_subfile ()->symtab
21530 = allocate_symtab (cust
,
21531 builder
->get_current_subfile ()->name
);
21533 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21538 /* Start a subfile for DWARF. FILENAME is the name of the file and
21539 DIRNAME the name of the source directory which contains FILENAME
21540 or NULL if not known.
21541 This routine tries to keep line numbers from identical absolute and
21542 relative file names in a common subfile.
21544 Using the `list' example from the GDB testsuite, which resides in
21545 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21546 of /srcdir/list0.c yields the following debugging information for list0.c:
21548 DW_AT_name: /srcdir/list0.c
21549 DW_AT_comp_dir: /compdir
21550 files.files[0].name: list0.h
21551 files.files[0].dir: /srcdir
21552 files.files[1].name: list0.c
21553 files.files[1].dir: /srcdir
21555 The line number information for list0.c has to end up in a single
21556 subfile, so that `break /srcdir/list0.c:1' works as expected.
21557 start_subfile will ensure that this happens provided that we pass the
21558 concatenation of files.files[1].dir and files.files[1].name as the
21562 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21563 const char *dirname
)
21565 gdb::unique_xmalloc_ptr
<char> copy
;
21567 /* In order not to lose the line information directory,
21568 we concatenate it to the filename when it makes sense.
21569 Note that the Dwarf3 standard says (speaking of filenames in line
21570 information): ``The directory index is ignored for file names
21571 that represent full path names''. Thus ignoring dirname in the
21572 `else' branch below isn't an issue. */
21574 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21576 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21577 filename
= copy
.get ();
21580 cu
->get_builder ()->start_subfile (filename
);
21584 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21585 struct dwarf2_cu
*cu
)
21587 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21588 struct comp_unit_head
*cu_header
= &cu
->header
;
21590 /* NOTE drow/2003-01-30: There used to be a comment and some special
21591 code here to turn a symbol with DW_AT_external and a
21592 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21593 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21594 with some versions of binutils) where shared libraries could have
21595 relocations against symbols in their debug information - the
21596 minimal symbol would have the right address, but the debug info
21597 would not. It's no longer necessary, because we will explicitly
21598 apply relocations when we read in the debug information now. */
21600 /* A DW_AT_location attribute with no contents indicates that a
21601 variable has been optimized away. */
21602 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21604 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21608 /* Handle one degenerate form of location expression specially, to
21609 preserve GDB's previous behavior when section offsets are
21610 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21611 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21613 if (attr
->form_is_block ())
21615 struct dwarf_block
*block
= attr
->as_block ();
21617 if ((block
->data
[0] == DW_OP_addr
21618 && block
->size
== 1 + cu_header
->addr_size
)
21619 || ((block
->data
[0] == DW_OP_GNU_addr_index
21620 || block
->data
[0] == DW_OP_addrx
)
21622 == 1 + leb128_size (&block
->data
[1]))))
21624 unsigned int dummy
;
21626 if (block
->data
[0] == DW_OP_addr
)
21627 SET_SYMBOL_VALUE_ADDRESS
21628 (sym
, cu
->header
.read_address (objfile
->obfd
,
21632 SET_SYMBOL_VALUE_ADDRESS
21633 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21635 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21636 fixup_symbol_section (sym
, objfile
);
21637 SET_SYMBOL_VALUE_ADDRESS
21639 SYMBOL_VALUE_ADDRESS (sym
)
21640 + objfile
->section_offsets
[sym
->section_index ()]);
21645 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21646 expression evaluator, and use LOC_COMPUTED only when necessary
21647 (i.e. when the value of a register or memory location is
21648 referenced, or a thread-local block, etc.). Then again, it might
21649 not be worthwhile. I'm assuming that it isn't unless performance
21650 or memory numbers show me otherwise. */
21652 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21654 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21655 cu
->has_loclist
= true;
21658 /* Given a pointer to a DWARF information entry, figure out if we need
21659 to make a symbol table entry for it, and if so, create a new entry
21660 and return a pointer to it.
21661 If TYPE is NULL, determine symbol type from the die, otherwise
21662 used the passed type.
21663 If SPACE is not NULL, use it to hold the new symbol. If it is
21664 NULL, allocate a new symbol on the objfile's obstack. */
21666 static struct symbol
*
21667 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21668 struct symbol
*space
)
21670 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21671 struct objfile
*objfile
= per_objfile
->objfile
;
21672 struct gdbarch
*gdbarch
= objfile
->arch ();
21673 struct symbol
*sym
= NULL
;
21675 struct attribute
*attr
= NULL
;
21676 struct attribute
*attr2
= NULL
;
21677 CORE_ADDR baseaddr
;
21678 struct pending
**list_to_add
= NULL
;
21680 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21682 baseaddr
= objfile
->text_section_offset ();
21684 name
= dwarf2_name (die
, cu
);
21687 int suppress_add
= 0;
21692 sym
= new (&objfile
->objfile_obstack
) symbol
;
21693 OBJSTAT (objfile
, n_syms
++);
21695 /* Cache this symbol's name and the name's demangled form (if any). */
21696 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21697 /* Fortran does not have mangling standard and the mangling does differ
21698 between gfortran, iFort etc. */
21699 const char *physname
21700 = (cu
->per_cu
->lang
== language_fortran
21701 ? dwarf2_full_name (name
, die
, cu
)
21702 : dwarf2_physname (name
, die
, cu
));
21703 const char *linkagename
= dw2_linkage_name (die
, cu
);
21705 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21706 sym
->set_linkage_name (physname
);
21709 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21710 sym
->set_linkage_name (linkagename
);
21713 /* Handle DW_AT_artificial. */
21714 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
21715 if (attr
!= nullptr)
21716 sym
->artificial
= attr
->as_boolean ();
21718 /* Default assumptions.
21719 Use the passed type or decode it from the die. */
21720 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21721 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21723 SYMBOL_TYPE (sym
) = type
;
21725 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21726 attr
= dwarf2_attr (die
,
21727 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21729 if (attr
!= nullptr)
21730 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21732 attr
= dwarf2_attr (die
,
21733 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21735 if (attr
!= nullptr && attr
->is_nonnegative ())
21737 file_name_index file_index
21738 = (file_name_index
) attr
->as_nonnegative ();
21739 struct file_entry
*fe
;
21741 if (cu
->line_header
!= NULL
)
21742 fe
= cu
->line_header
->file_name_at (file_index
);
21747 complaint (_("file index out of range"));
21749 symbol_set_symtab (sym
, fe
->symtab
);
21755 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21756 if (attr
!= nullptr)
21760 addr
= attr
->as_address ();
21761 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21762 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21763 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21766 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21767 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21768 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21769 add_symbol_to_list (sym
, cu
->list_in_scope
);
21771 case DW_TAG_subprogram
:
21772 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21774 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21775 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21776 if ((attr2
!= nullptr && attr2
->as_boolean ())
21777 || cu
->per_cu
->lang
== language_ada
21778 || cu
->per_cu
->lang
== language_fortran
)
21780 /* Subprograms marked external are stored as a global symbol.
21781 Ada and Fortran subprograms, whether marked external or
21782 not, are always stored as a global symbol, because we want
21783 to be able to access them globally. For instance, we want
21784 to be able to break on a nested subprogram without having
21785 to specify the context. */
21786 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21790 list_to_add
= cu
->list_in_scope
;
21793 case DW_TAG_inlined_subroutine
:
21794 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21796 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21797 SYMBOL_INLINED (sym
) = 1;
21798 list_to_add
= cu
->list_in_scope
;
21800 case DW_TAG_template_value_param
:
21802 /* Fall through. */
21803 case DW_TAG_constant
:
21804 case DW_TAG_variable
:
21805 case DW_TAG_member
:
21806 /* Compilation with minimal debug info may result in
21807 variables with missing type entries. Change the
21808 misleading `void' type to something sensible. */
21809 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21810 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21812 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21813 /* In the case of DW_TAG_member, we should only be called for
21814 static const members. */
21815 if (die
->tag
== DW_TAG_member
)
21817 /* dwarf2_add_field uses die_is_declaration,
21818 so we do the same. */
21819 gdb_assert (die_is_declaration (die
, cu
));
21822 if (attr
!= nullptr)
21824 dwarf2_const_value (attr
, sym
, cu
);
21825 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21828 if (attr2
!= nullptr && attr2
->as_boolean ())
21829 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21831 list_to_add
= cu
->list_in_scope
;
21835 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21836 if (attr
!= nullptr)
21838 var_decode_location (attr
, sym
, cu
);
21839 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21841 /* Fortran explicitly imports any global symbols to the local
21842 scope by DW_TAG_common_block. */
21843 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21844 && die
->parent
->tag
== DW_TAG_common_block
)
21847 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21848 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21849 && !per_objfile
->per_bfd
->has_section_at_zero
)
21851 /* When a static variable is eliminated by the linker,
21852 the corresponding debug information is not stripped
21853 out, but the variable address is set to null;
21854 do not add such variables into symbol table. */
21856 else if (attr2
!= nullptr && attr2
->as_boolean ())
21858 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21859 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21860 && per_objfile
->per_bfd
->can_copy
)
21862 /* A global static variable might be subject to
21863 copy relocation. We first check for a local
21864 minsym, though, because maybe the symbol was
21865 marked hidden, in which case this would not
21867 bound_minimal_symbol found
21868 = (lookup_minimal_symbol_linkage
21869 (sym
->linkage_name (), objfile
));
21870 if (found
.minsym
!= nullptr)
21871 sym
->maybe_copied
= 1;
21874 /* A variable with DW_AT_external is never static,
21875 but it may be block-scoped. */
21877 = ((cu
->list_in_scope
21878 == cu
->get_builder ()->get_file_symbols ())
21879 ? cu
->get_builder ()->get_global_symbols ()
21880 : cu
->list_in_scope
);
21883 list_to_add
= cu
->list_in_scope
;
21887 /* We do not know the address of this symbol.
21888 If it is an external symbol and we have type information
21889 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21890 The address of the variable will then be determined from
21891 the minimal symbol table whenever the variable is
21893 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21895 /* Fortran explicitly imports any global symbols to the local
21896 scope by DW_TAG_common_block. */
21897 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21898 && die
->parent
->tag
== DW_TAG_common_block
)
21900 /* SYMBOL_CLASS doesn't matter here because
21901 read_common_block is going to reset it. */
21903 list_to_add
= cu
->list_in_scope
;
21905 else if (attr2
!= nullptr && attr2
->as_boolean ()
21906 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21908 /* A variable with DW_AT_external is never static, but it
21909 may be block-scoped. */
21911 = ((cu
->list_in_scope
21912 == cu
->get_builder ()->get_file_symbols ())
21913 ? cu
->get_builder ()->get_global_symbols ()
21914 : cu
->list_in_scope
);
21916 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21918 else if (!die_is_declaration (die
, cu
))
21920 /* Use the default LOC_OPTIMIZED_OUT class. */
21921 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21923 list_to_add
= cu
->list_in_scope
;
21927 case DW_TAG_formal_parameter
:
21929 /* If we are inside a function, mark this as an argument. If
21930 not, we might be looking at an argument to an inlined function
21931 when we do not have enough information to show inlined frames;
21932 pretend it's a local variable in that case so that the user can
21934 struct context_stack
*curr
21935 = cu
->get_builder ()->get_current_context_stack ();
21936 if (curr
!= nullptr && curr
->name
!= nullptr)
21937 SYMBOL_IS_ARGUMENT (sym
) = 1;
21938 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21939 if (attr
!= nullptr)
21941 var_decode_location (attr
, sym
, cu
);
21943 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21944 if (attr
!= nullptr)
21946 dwarf2_const_value (attr
, sym
, cu
);
21949 list_to_add
= cu
->list_in_scope
;
21952 case DW_TAG_unspecified_parameters
:
21953 /* From varargs functions; gdb doesn't seem to have any
21954 interest in this information, so just ignore it for now.
21957 case DW_TAG_template_type_param
:
21959 /* Fall through. */
21960 case DW_TAG_class_type
:
21961 case DW_TAG_interface_type
:
21962 case DW_TAG_structure_type
:
21963 case DW_TAG_union_type
:
21964 case DW_TAG_set_type
:
21965 case DW_TAG_enumeration_type
:
21966 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21967 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21970 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21971 really ever be static objects: otherwise, if you try
21972 to, say, break of a class's method and you're in a file
21973 which doesn't mention that class, it won't work unless
21974 the check for all static symbols in lookup_symbol_aux
21975 saves you. See the OtherFileClass tests in
21976 gdb.c++/namespace.exp. */
21980 buildsym_compunit
*builder
= cu
->get_builder ();
21982 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21983 && cu
->per_cu
->lang
== language_cplus
21984 ? builder
->get_global_symbols ()
21985 : cu
->list_in_scope
);
21987 /* The semantics of C++ state that "struct foo {
21988 ... }" also defines a typedef for "foo". */
21989 if (cu
->per_cu
->lang
== language_cplus
21990 || cu
->per_cu
->lang
== language_ada
21991 || cu
->per_cu
->lang
== language_d
21992 || cu
->per_cu
->lang
== language_rust
)
21994 /* The symbol's name is already allocated along
21995 with this objfile, so we don't need to
21996 duplicate it for the type. */
21997 if (SYMBOL_TYPE (sym
)->name () == 0)
21998 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22003 case DW_TAG_typedef
:
22004 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22005 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22006 list_to_add
= cu
->list_in_scope
;
22008 case DW_TAG_array_type
:
22009 case DW_TAG_base_type
:
22010 case DW_TAG_subrange_type
:
22011 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22012 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22013 list_to_add
= cu
->list_in_scope
;
22015 case DW_TAG_enumerator
:
22016 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22017 if (attr
!= nullptr)
22019 dwarf2_const_value (attr
, sym
, cu
);
22022 /* NOTE: carlton/2003-11-10: See comment above in the
22023 DW_TAG_class_type, etc. block. */
22026 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22027 && cu
->per_cu
->lang
== language_cplus
22028 ? cu
->get_builder ()->get_global_symbols ()
22029 : cu
->list_in_scope
);
22032 case DW_TAG_imported_declaration
:
22033 case DW_TAG_namespace
:
22034 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22035 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22037 case DW_TAG_module
:
22038 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22039 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22040 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22042 case DW_TAG_common_block
:
22043 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22044 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22045 add_symbol_to_list (sym
, cu
->list_in_scope
);
22048 /* Not a tag we recognize. Hopefully we aren't processing
22049 trash data, but since we must specifically ignore things
22050 we don't recognize, there is nothing else we should do at
22052 complaint (_("unsupported tag: '%s'"),
22053 dwarf_tag_name (die
->tag
));
22059 sym
->hash_next
= objfile
->template_symbols
;
22060 objfile
->template_symbols
= sym
;
22061 list_to_add
= NULL
;
22064 if (list_to_add
!= NULL
)
22065 add_symbol_to_list (sym
, list_to_add
);
22067 /* For the benefit of old versions of GCC, check for anonymous
22068 namespaces based on the demangled name. */
22069 if (!cu
->processing_has_namespace_info
22070 && cu
->per_cu
->lang
== language_cplus
)
22071 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22076 /* Given an attr with a DW_FORM_dataN value in host byte order,
22077 zero-extend it as appropriate for the symbol's type. The DWARF
22078 standard (v4) is not entirely clear about the meaning of using
22079 DW_FORM_dataN for a constant with a signed type, where the type is
22080 wider than the data. The conclusion of a discussion on the DWARF
22081 list was that this is unspecified. We choose to always zero-extend
22082 because that is the interpretation long in use by GCC. */
22085 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22086 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22088 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22089 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22090 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22091 LONGEST l
= attr
->constant_value (0);
22093 if (bits
< sizeof (*value
) * 8)
22095 l
&= ((LONGEST
) 1 << bits
) - 1;
22098 else if (bits
== sizeof (*value
) * 8)
22102 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22103 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22110 /* Read a constant value from an attribute. Either set *VALUE, or if
22111 the value does not fit in *VALUE, set *BYTES - either already
22112 allocated on the objfile obstack, or newly allocated on OBSTACK,
22113 or, set *BATON, if we translated the constant to a location
22117 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22118 const char *name
, struct obstack
*obstack
,
22119 struct dwarf2_cu
*cu
,
22120 LONGEST
*value
, const gdb_byte
**bytes
,
22121 struct dwarf2_locexpr_baton
**baton
)
22123 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22124 struct objfile
*objfile
= per_objfile
->objfile
;
22125 struct comp_unit_head
*cu_header
= &cu
->header
;
22126 struct dwarf_block
*blk
;
22127 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22128 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22134 switch (attr
->form
)
22137 case DW_FORM_addrx
:
22138 case DW_FORM_GNU_addr_index
:
22142 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22143 dwarf2_const_value_length_mismatch_complaint (name
,
22144 cu_header
->addr_size
,
22145 TYPE_LENGTH (type
));
22146 /* Symbols of this form are reasonably rare, so we just
22147 piggyback on the existing location code rather than writing
22148 a new implementation of symbol_computed_ops. */
22149 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22150 (*baton
)->per_objfile
= per_objfile
;
22151 (*baton
)->per_cu
= cu
->per_cu
;
22152 gdb_assert ((*baton
)->per_cu
);
22154 (*baton
)->size
= 2 + cu_header
->addr_size
;
22155 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22156 (*baton
)->data
= data
;
22158 data
[0] = DW_OP_addr
;
22159 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22160 byte_order
, attr
->as_address ());
22161 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22164 case DW_FORM_string
:
22167 case DW_FORM_GNU_str_index
:
22168 case DW_FORM_GNU_strp_alt
:
22169 /* The string is already allocated on the objfile obstack, point
22171 *bytes
= (const gdb_byte
*) attr
->as_string ();
22173 case DW_FORM_block1
:
22174 case DW_FORM_block2
:
22175 case DW_FORM_block4
:
22176 case DW_FORM_block
:
22177 case DW_FORM_exprloc
:
22178 case DW_FORM_data16
:
22179 blk
= attr
->as_block ();
22180 if (TYPE_LENGTH (type
) != blk
->size
)
22181 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22182 TYPE_LENGTH (type
));
22183 *bytes
= blk
->data
;
22186 /* The DW_AT_const_value attributes are supposed to carry the
22187 symbol's value "represented as it would be on the target
22188 architecture." By the time we get here, it's already been
22189 converted to host endianness, so we just need to sign- or
22190 zero-extend it as appropriate. */
22191 case DW_FORM_data1
:
22192 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22194 case DW_FORM_data2
:
22195 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22197 case DW_FORM_data4
:
22198 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22200 case DW_FORM_data8
:
22201 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22204 case DW_FORM_sdata
:
22205 case DW_FORM_implicit_const
:
22206 *value
= attr
->as_signed ();
22209 case DW_FORM_udata
:
22210 *value
= attr
->as_unsigned ();
22214 complaint (_("unsupported const value attribute form: '%s'"),
22215 dwarf_form_name (attr
->form
));
22222 /* Copy constant value from an attribute to a symbol. */
22225 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22226 struct dwarf2_cu
*cu
)
22228 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22230 const gdb_byte
*bytes
;
22231 struct dwarf2_locexpr_baton
*baton
;
22233 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22234 sym
->print_name (),
22235 &objfile
->objfile_obstack
, cu
,
22236 &value
, &bytes
, &baton
);
22240 SYMBOL_LOCATION_BATON (sym
) = baton
;
22241 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22243 else if (bytes
!= NULL
)
22245 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22246 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22250 SYMBOL_VALUE (sym
) = value
;
22251 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22255 /* Return the type of the die in question using its DW_AT_type attribute. */
22257 static struct type
*
22258 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22260 struct attribute
*type_attr
;
22262 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22265 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22266 /* A missing DW_AT_type represents a void type. */
22267 return objfile_type (objfile
)->builtin_void
;
22270 return lookup_die_type (die
, type_attr
, cu
);
22273 /* True iff CU's producer generates GNAT Ada auxiliary information
22274 that allows to find parallel types through that information instead
22275 of having to do expensive parallel lookups by type name. */
22278 need_gnat_info (struct dwarf2_cu
*cu
)
22280 /* Assume that the Ada compiler was GNAT, which always produces
22281 the auxiliary information. */
22282 return (cu
->per_cu
->lang
== language_ada
);
22285 /* Return the auxiliary type of the die in question using its
22286 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22287 attribute is not present. */
22289 static struct type
*
22290 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22292 struct attribute
*type_attr
;
22294 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22298 return lookup_die_type (die
, type_attr
, cu
);
22301 /* If DIE has a descriptive_type attribute, then set the TYPE's
22302 descriptive type accordingly. */
22305 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22306 struct dwarf2_cu
*cu
)
22308 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22310 if (descriptive_type
)
22312 ALLOCATE_GNAT_AUX_TYPE (type
);
22313 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22317 /* Return the containing type of the die in question using its
22318 DW_AT_containing_type attribute. */
22320 static struct type
*
22321 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22323 struct attribute
*type_attr
;
22324 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22326 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22328 error (_("Dwarf Error: Problem turning containing type into gdb type "
22329 "[in module %s]"), objfile_name (objfile
));
22331 return lookup_die_type (die
, type_attr
, cu
);
22334 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22336 static struct type
*
22337 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22339 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22340 struct objfile
*objfile
= per_objfile
->objfile
;
22343 std::string message
22344 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22345 objfile_name (objfile
),
22346 sect_offset_str (cu
->header
.sect_off
),
22347 sect_offset_str (die
->sect_off
));
22348 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22350 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22353 /* Look up the type of DIE in CU using its type attribute ATTR.
22354 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22355 DW_AT_containing_type.
22356 If there is no type substitute an error marker. */
22358 static struct type
*
22359 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22360 struct dwarf2_cu
*cu
)
22362 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22363 struct objfile
*objfile
= per_objfile
->objfile
;
22364 struct type
*this_type
;
22366 gdb_assert (attr
->name
== DW_AT_type
22367 || attr
->name
== DW_AT_GNAT_descriptive_type
22368 || attr
->name
== DW_AT_containing_type
);
22370 /* First see if we have it cached. */
22372 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22374 struct dwarf2_per_cu_data
*per_cu
;
22375 sect_offset sect_off
= attr
->get_ref_die_offset ();
22377 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22378 per_objfile
->per_bfd
);
22379 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22381 else if (attr
->form_is_ref ())
22383 sect_offset sect_off
= attr
->get_ref_die_offset ();
22385 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22387 else if (attr
->form
== DW_FORM_ref_sig8
)
22389 ULONGEST signature
= attr
->as_signature ();
22391 return get_signatured_type (die
, signature
, cu
);
22395 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22396 " at %s [in module %s]"),
22397 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22398 objfile_name (objfile
));
22399 return build_error_marker_type (cu
, die
);
22402 /* If not cached we need to read it in. */
22404 if (this_type
== NULL
)
22406 struct die_info
*type_die
= NULL
;
22407 struct dwarf2_cu
*type_cu
= cu
;
22409 if (attr
->form_is_ref ())
22410 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22411 if (type_die
== NULL
)
22412 return build_error_marker_type (cu
, die
);
22413 /* If we find the type now, it's probably because the type came
22414 from an inter-CU reference and the type's CU got expanded before
22416 this_type
= read_type_die (type_die
, type_cu
);
22419 /* If we still don't have a type use an error marker. */
22421 if (this_type
== NULL
)
22422 return build_error_marker_type (cu
, die
);
22427 /* Return the type in DIE, CU.
22428 Returns NULL for invalid types.
22430 This first does a lookup in die_type_hash,
22431 and only reads the die in if necessary.
22433 NOTE: This can be called when reading in partial or full symbols. */
22435 static struct type
*
22436 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22438 struct type
*this_type
;
22440 this_type
= get_die_type (die
, cu
);
22444 return read_type_die_1 (die
, cu
);
22447 /* Read the type in DIE, CU.
22448 Returns NULL for invalid types. */
22450 static struct type
*
22451 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22453 struct type
*this_type
= NULL
;
22457 case DW_TAG_class_type
:
22458 case DW_TAG_interface_type
:
22459 case DW_TAG_structure_type
:
22460 case DW_TAG_union_type
:
22461 this_type
= read_structure_type (die
, cu
);
22463 case DW_TAG_enumeration_type
:
22464 this_type
= read_enumeration_type (die
, cu
);
22466 case DW_TAG_subprogram
:
22467 case DW_TAG_subroutine_type
:
22468 case DW_TAG_inlined_subroutine
:
22469 this_type
= read_subroutine_type (die
, cu
);
22471 case DW_TAG_array_type
:
22472 this_type
= read_array_type (die
, cu
);
22474 case DW_TAG_set_type
:
22475 this_type
= read_set_type (die
, cu
);
22477 case DW_TAG_pointer_type
:
22478 this_type
= read_tag_pointer_type (die
, cu
);
22480 case DW_TAG_ptr_to_member_type
:
22481 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22483 case DW_TAG_reference_type
:
22484 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22486 case DW_TAG_rvalue_reference_type
:
22487 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22489 case DW_TAG_const_type
:
22490 this_type
= read_tag_const_type (die
, cu
);
22492 case DW_TAG_volatile_type
:
22493 this_type
= read_tag_volatile_type (die
, cu
);
22495 case DW_TAG_restrict_type
:
22496 this_type
= read_tag_restrict_type (die
, cu
);
22498 case DW_TAG_string_type
:
22499 this_type
= read_tag_string_type (die
, cu
);
22501 case DW_TAG_typedef
:
22502 this_type
= read_typedef (die
, cu
);
22504 case DW_TAG_subrange_type
:
22505 this_type
= read_subrange_type (die
, cu
);
22507 case DW_TAG_base_type
:
22508 this_type
= read_base_type (die
, cu
);
22510 case DW_TAG_unspecified_type
:
22511 this_type
= read_unspecified_type (die
, cu
);
22513 case DW_TAG_namespace
:
22514 this_type
= read_namespace_type (die
, cu
);
22516 case DW_TAG_module
:
22517 this_type
= read_module_type (die
, cu
);
22519 case DW_TAG_atomic_type
:
22520 this_type
= read_tag_atomic_type (die
, cu
);
22523 complaint (_("unexpected tag in read_type_die: '%s'"),
22524 dwarf_tag_name (die
->tag
));
22531 /* See if we can figure out if the class lives in a namespace. We do
22532 this by looking for a member function; its demangled name will
22533 contain namespace info, if there is any.
22534 Return the computed name or NULL.
22535 Space for the result is allocated on the objfile's obstack.
22536 This is the full-die version of guess_partial_die_structure_name.
22537 In this case we know DIE has no useful parent. */
22539 static const char *
22540 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22542 struct die_info
*spec_die
;
22543 struct dwarf2_cu
*spec_cu
;
22544 struct die_info
*child
;
22545 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22548 spec_die
= die_specification (die
, &spec_cu
);
22549 if (spec_die
!= NULL
)
22555 for (child
= die
->child
;
22557 child
= child
->sibling
)
22559 if (child
->tag
== DW_TAG_subprogram
)
22561 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22563 if (linkage_name
!= NULL
)
22565 gdb::unique_xmalloc_ptr
<char> actual_name
22566 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22567 const char *name
= NULL
;
22569 if (actual_name
!= NULL
)
22571 const char *die_name
= dwarf2_name (die
, cu
);
22573 if (die_name
!= NULL
22574 && strcmp (die_name
, actual_name
.get ()) != 0)
22576 /* Strip off the class name from the full name.
22577 We want the prefix. */
22578 int die_name_len
= strlen (die_name
);
22579 int actual_name_len
= strlen (actual_name
.get ());
22580 const char *ptr
= actual_name
.get ();
22582 /* Test for '::' as a sanity check. */
22583 if (actual_name_len
> die_name_len
+ 2
22584 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22585 name
= obstack_strndup (
22586 &objfile
->per_bfd
->storage_obstack
,
22587 ptr
, actual_name_len
- die_name_len
- 2);
22598 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22599 prefix part in such case. See
22600 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22602 static const char *
22603 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22605 struct attribute
*attr
;
22608 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22609 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22612 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22615 attr
= dw2_linkage_name_attr (die
, cu
);
22616 const char *attr_name
= attr
->as_string ();
22617 if (attr
== NULL
|| attr_name
== NULL
)
22620 /* dwarf2_name had to be already called. */
22621 gdb_assert (attr
->canonical_string_p ());
22623 /* Strip the base name, keep any leading namespaces/classes. */
22624 base
= strrchr (attr_name
, ':');
22625 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22628 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22629 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22631 &base
[-1] - attr_name
);
22634 /* Return the name of the namespace/class that DIE is defined within,
22635 or "" if we can't tell. The caller should not xfree the result.
22637 For example, if we're within the method foo() in the following
22647 then determine_prefix on foo's die will return "N::C". */
22649 static const char *
22650 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22652 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22653 struct die_info
*parent
, *spec_die
;
22654 struct dwarf2_cu
*spec_cu
;
22655 struct type
*parent_type
;
22656 const char *retval
;
22658 if (cu
->per_cu
->lang
!= language_cplus
22659 && cu
->per_cu
->lang
!= language_fortran
22660 && cu
->per_cu
->lang
!= language_d
22661 && cu
->per_cu
->lang
!= language_rust
)
22664 retval
= anonymous_struct_prefix (die
, cu
);
22668 /* We have to be careful in the presence of DW_AT_specification.
22669 For example, with GCC 3.4, given the code
22673 // Definition of N::foo.
22677 then we'll have a tree of DIEs like this:
22679 1: DW_TAG_compile_unit
22680 2: DW_TAG_namespace // N
22681 3: DW_TAG_subprogram // declaration of N::foo
22682 4: DW_TAG_subprogram // definition of N::foo
22683 DW_AT_specification // refers to die #3
22685 Thus, when processing die #4, we have to pretend that we're in
22686 the context of its DW_AT_specification, namely the contex of die
22689 spec_die
= die_specification (die
, &spec_cu
);
22690 if (spec_die
== NULL
)
22691 parent
= die
->parent
;
22694 parent
= spec_die
->parent
;
22698 if (parent
== NULL
)
22700 else if (parent
->building_fullname
)
22703 const char *parent_name
;
22705 /* It has been seen on RealView 2.2 built binaries,
22706 DW_TAG_template_type_param types actually _defined_ as
22707 children of the parent class:
22710 template class <class Enum> Class{};
22711 Class<enum E> class_e;
22713 1: DW_TAG_class_type (Class)
22714 2: DW_TAG_enumeration_type (E)
22715 3: DW_TAG_enumerator (enum1:0)
22716 3: DW_TAG_enumerator (enum2:1)
22718 2: DW_TAG_template_type_param
22719 DW_AT_type DW_FORM_ref_udata (E)
22721 Besides being broken debug info, it can put GDB into an
22722 infinite loop. Consider:
22724 When we're building the full name for Class<E>, we'll start
22725 at Class, and go look over its template type parameters,
22726 finding E. We'll then try to build the full name of E, and
22727 reach here. We're now trying to build the full name of E,
22728 and look over the parent DIE for containing scope. In the
22729 broken case, if we followed the parent DIE of E, we'd again
22730 find Class, and once again go look at its template type
22731 arguments, etc., etc. Simply don't consider such parent die
22732 as source-level parent of this die (it can't be, the language
22733 doesn't allow it), and break the loop here. */
22734 name
= dwarf2_name (die
, cu
);
22735 parent_name
= dwarf2_name (parent
, cu
);
22736 complaint (_("template param type '%s' defined within parent '%s'"),
22737 name
? name
: "<unknown>",
22738 parent_name
? parent_name
: "<unknown>");
22742 switch (parent
->tag
)
22744 case DW_TAG_namespace
:
22745 parent_type
= read_type_die (parent
, cu
);
22746 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22747 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22748 Work around this problem here. */
22749 if (cu
->per_cu
->lang
== language_cplus
22750 && strcmp (parent_type
->name (), "::") == 0)
22752 /* We give a name to even anonymous namespaces. */
22753 return parent_type
->name ();
22754 case DW_TAG_class_type
:
22755 case DW_TAG_interface_type
:
22756 case DW_TAG_structure_type
:
22757 case DW_TAG_union_type
:
22758 case DW_TAG_module
:
22759 parent_type
= read_type_die (parent
, cu
);
22760 if (parent_type
->name () != NULL
)
22761 return parent_type
->name ();
22763 /* An anonymous structure is only allowed non-static data
22764 members; no typedefs, no member functions, et cetera.
22765 So it does not need a prefix. */
22767 case DW_TAG_compile_unit
:
22768 case DW_TAG_partial_unit
:
22769 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22770 if (cu
->per_cu
->lang
== language_cplus
22771 && !per_objfile
->per_bfd
->types
.empty ()
22772 && die
->child
!= NULL
22773 && (die
->tag
== DW_TAG_class_type
22774 || die
->tag
== DW_TAG_structure_type
22775 || die
->tag
== DW_TAG_union_type
))
22777 const char *name
= guess_full_die_structure_name (die
, cu
);
22782 case DW_TAG_subprogram
:
22783 /* Nested subroutines in Fortran get a prefix with the name
22784 of the parent's subroutine. */
22785 if (cu
->per_cu
->lang
== language_fortran
)
22787 if ((die
->tag
== DW_TAG_subprogram
)
22788 && (dwarf2_name (parent
, cu
) != NULL
))
22789 return dwarf2_name (parent
, cu
);
22792 case DW_TAG_enumeration_type
:
22793 parent_type
= read_type_die (parent
, cu
);
22794 if (parent_type
->is_declared_class ())
22796 if (parent_type
->name () != NULL
)
22797 return parent_type
->name ();
22800 /* Fall through. */
22802 return determine_prefix (parent
, cu
);
22806 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22807 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22808 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22809 an obconcat, otherwise allocate storage for the result. The CU argument is
22810 used to determine the language and hence, the appropriate separator. */
22812 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22815 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22816 int physname
, struct dwarf2_cu
*cu
)
22818 const char *lead
= "";
22821 if (suffix
== NULL
|| suffix
[0] == '\0'
22822 || prefix
== NULL
|| prefix
[0] == '\0')
22824 else if (cu
->per_cu
->lang
== language_d
)
22826 /* For D, the 'main' function could be defined in any module, but it
22827 should never be prefixed. */
22828 if (strcmp (suffix
, "D main") == 0)
22836 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22838 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22839 DW_AT_MIPS_linkage_name is preferred and used instead. */
22847 if (prefix
== NULL
)
22849 if (suffix
== NULL
)
22856 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22858 strcpy (retval
, lead
);
22859 strcat (retval
, prefix
);
22860 strcat (retval
, sep
);
22861 strcat (retval
, suffix
);
22866 /* We have an obstack. */
22867 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22871 /* Get name of a die, return NULL if not found. */
22873 static const char *
22874 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22875 struct objfile
*objfile
)
22877 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22879 gdb::unique_xmalloc_ptr
<char> canon_name
22880 = cp_canonicalize_string (name
);
22882 if (canon_name
!= nullptr)
22883 name
= objfile
->intern (canon_name
.get ());
22889 /* Get name of a die, return NULL if not found.
22890 Anonymous namespaces are converted to their magic string. */
22892 static const char *
22893 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22895 struct attribute
*attr
;
22896 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22898 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22899 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22900 if (attr_name
== nullptr
22901 && die
->tag
!= DW_TAG_namespace
22902 && die
->tag
!= DW_TAG_class_type
22903 && die
->tag
!= DW_TAG_interface_type
22904 && die
->tag
!= DW_TAG_structure_type
22905 && die
->tag
!= DW_TAG_union_type
)
22910 case DW_TAG_compile_unit
:
22911 case DW_TAG_partial_unit
:
22912 /* Compilation units have a DW_AT_name that is a filename, not
22913 a source language identifier. */
22914 case DW_TAG_enumeration_type
:
22915 case DW_TAG_enumerator
:
22916 /* These tags always have simple identifiers already; no need
22917 to canonicalize them. */
22920 case DW_TAG_namespace
:
22921 if (attr_name
!= nullptr)
22923 return CP_ANONYMOUS_NAMESPACE_STR
;
22925 case DW_TAG_class_type
:
22926 case DW_TAG_interface_type
:
22927 case DW_TAG_structure_type
:
22928 case DW_TAG_union_type
:
22929 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22930 structures or unions. These were of the form "._%d" in GCC 4.1,
22931 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22932 and GCC 4.4. We work around this problem by ignoring these. */
22933 if (attr_name
!= nullptr
22934 && (startswith (attr_name
, "._")
22935 || startswith (attr_name
, "<anonymous")))
22938 /* GCC might emit a nameless typedef that has a linkage name. See
22939 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22940 if (!attr
|| attr_name
== NULL
)
22942 attr
= dw2_linkage_name_attr (die
, cu
);
22943 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22944 if (attr
== NULL
|| attr_name
== NULL
)
22947 /* Avoid demangling attr_name the second time on a second
22948 call for the same DIE. */
22949 if (!attr
->canonical_string_p ())
22951 gdb::unique_xmalloc_ptr
<char> demangled
22952 (gdb_demangle (attr_name
, DMGL_TYPES
));
22953 if (demangled
== nullptr)
22956 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22957 attr_name
= attr
->as_string ();
22960 /* Strip any leading namespaces/classes, keep only the
22961 base name. DW_AT_name for named DIEs does not
22962 contain the prefixes. */
22963 const char *base
= strrchr (attr_name
, ':');
22964 if (base
&& base
> attr_name
&& base
[-1] == ':')
22975 if (!attr
->canonical_string_p ())
22976 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22978 return attr
->as_string ();
22981 /* Return the die that this die in an extension of, or NULL if there
22982 is none. *EXT_CU is the CU containing DIE on input, and the CU
22983 containing the return value on output. */
22985 static struct die_info
*
22986 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22988 struct attribute
*attr
;
22990 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22994 return follow_die_ref (die
, attr
, ext_cu
);
22998 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23002 fprintf_unfiltered (f
, "%*sDie: %s (abbrev %d, offset %s)\n",
23004 dwarf_tag_name (die
->tag
), die
->abbrev
,
23005 sect_offset_str (die
->sect_off
));
23007 if (die
->parent
!= NULL
)
23008 fprintf_unfiltered (f
, "%*s parent at offset: %s\n",
23010 sect_offset_str (die
->parent
->sect_off
));
23012 fprintf_unfiltered (f
, "%*s has children: %s\n",
23014 dwarf_bool_name (die
->child
!= NULL
));
23016 fprintf_unfiltered (f
, "%*s attributes:\n", indent
, "");
23018 for (i
= 0; i
< die
->num_attrs
; ++i
)
23020 fprintf_unfiltered (f
, "%*s %s (%s) ",
23022 dwarf_attr_name (die
->attrs
[i
].name
),
23023 dwarf_form_name (die
->attrs
[i
].form
));
23025 switch (die
->attrs
[i
].form
)
23028 case DW_FORM_addrx
:
23029 case DW_FORM_GNU_addr_index
:
23030 fprintf_unfiltered (f
, "address: ");
23031 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23033 case DW_FORM_block2
:
23034 case DW_FORM_block4
:
23035 case DW_FORM_block
:
23036 case DW_FORM_block1
:
23037 fprintf_unfiltered (f
, "block: size %s",
23038 pulongest (die
->attrs
[i
].as_block ()->size
));
23040 case DW_FORM_exprloc
:
23041 fprintf_unfiltered (f
, "expression: size %s",
23042 pulongest (die
->attrs
[i
].as_block ()->size
));
23044 case DW_FORM_data16
:
23045 fprintf_unfiltered (f
, "constant of 16 bytes");
23047 case DW_FORM_ref_addr
:
23048 fprintf_unfiltered (f
, "ref address: ");
23049 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23051 case DW_FORM_GNU_ref_alt
:
23052 fprintf_unfiltered (f
, "alt ref address: ");
23053 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23059 case DW_FORM_ref_udata
:
23060 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23061 (long) (die
->attrs
[i
].as_unsigned ()));
23063 case DW_FORM_data1
:
23064 case DW_FORM_data2
:
23065 case DW_FORM_data4
:
23066 case DW_FORM_data8
:
23067 case DW_FORM_udata
:
23068 fprintf_unfiltered (f
, "constant: %s",
23069 pulongest (die
->attrs
[i
].as_unsigned ()));
23071 case DW_FORM_sec_offset
:
23072 fprintf_unfiltered (f
, "section offset: %s",
23073 pulongest (die
->attrs
[i
].as_unsigned ()));
23075 case DW_FORM_ref_sig8
:
23076 fprintf_unfiltered (f
, "signature: %s",
23077 hex_string (die
->attrs
[i
].as_signature ()));
23079 case DW_FORM_string
:
23081 case DW_FORM_line_strp
:
23083 case DW_FORM_GNU_str_index
:
23084 case DW_FORM_GNU_strp_alt
:
23085 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23086 die
->attrs
[i
].as_string ()
23087 ? die
->attrs
[i
].as_string () : "",
23088 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23091 if (die
->attrs
[i
].as_boolean ())
23092 fprintf_unfiltered (f
, "flag: TRUE");
23094 fprintf_unfiltered (f
, "flag: FALSE");
23096 case DW_FORM_flag_present
:
23097 fprintf_unfiltered (f
, "flag: TRUE");
23099 case DW_FORM_indirect
:
23100 /* The reader will have reduced the indirect form to
23101 the "base form" so this form should not occur. */
23102 fprintf_unfiltered (f
,
23103 "unexpected attribute form: DW_FORM_indirect");
23105 case DW_FORM_sdata
:
23106 case DW_FORM_implicit_const
:
23107 fprintf_unfiltered (f
, "constant: %s",
23108 plongest (die
->attrs
[i
].as_signed ()));
23111 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23112 die
->attrs
[i
].form
);
23115 fprintf_unfiltered (f
, "\n");
23120 dump_die_for_error (struct die_info
*die
)
23122 dump_die_shallow (gdb_stderr
, 0, die
);
23126 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23128 int indent
= level
* 4;
23130 gdb_assert (die
!= NULL
);
23132 if (level
>= max_level
)
23135 dump_die_shallow (f
, indent
, die
);
23137 if (die
->child
!= NULL
)
23139 fprintf_unfiltered (f
, "%*s Children:", indent
, "");
23140 if (level
+ 1 < max_level
)
23142 fprintf_unfiltered (f
, "\n");
23143 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23147 fprintf_unfiltered (f
,
23148 " [not printed, max nesting level reached]\n");
23152 if (die
->sibling
!= NULL
&& level
> 0)
23154 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23158 /* This is called from the pdie macro in gdbinit.in.
23159 It's not static so gcc will keep a copy callable from gdb. */
23162 dump_die (struct die_info
*die
, int max_level
)
23164 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23168 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23172 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23173 to_underlying (die
->sect_off
),
23179 /* Follow reference or signature attribute ATTR of SRC_DIE.
23180 On entry *REF_CU is the CU of SRC_DIE.
23181 On exit *REF_CU is the CU of the result. */
23183 static struct die_info
*
23184 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23185 struct dwarf2_cu
**ref_cu
)
23187 struct die_info
*die
;
23189 if (attr
->form_is_ref ())
23190 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23191 else if (attr
->form
== DW_FORM_ref_sig8
)
23192 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23195 dump_die_for_error (src_die
);
23196 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23197 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23203 /* Follow reference OFFSET.
23204 On entry *REF_CU is the CU of the source die referencing OFFSET.
23205 On exit *REF_CU is the CU of the result.
23206 Returns NULL if OFFSET is invalid. */
23208 static struct die_info
*
23209 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23210 struct dwarf2_cu
**ref_cu
)
23212 struct die_info temp_die
;
23213 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23214 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23216 gdb_assert (cu
->per_cu
!= NULL
);
23220 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23221 "source CU contains target offset: %d",
23222 sect_offset_str (cu
->per_cu
->sect_off
),
23223 sect_offset_str (sect_off
),
23224 cu
->header
.offset_in_cu_p (sect_off
));
23226 if (cu
->per_cu
->is_debug_types
)
23228 /* .debug_types CUs cannot reference anything outside their CU.
23229 If they need to, they have to reference a signatured type via
23230 DW_FORM_ref_sig8. */
23231 if (!cu
->header
.offset_in_cu_p (sect_off
))
23234 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23235 || !cu
->header
.offset_in_cu_p (sect_off
))
23237 struct dwarf2_per_cu_data
*per_cu
;
23239 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23240 per_objfile
->per_bfd
);
23242 dwarf_read_debug_printf_v ("target CU offset: %s, "
23243 "target CU DIEs loaded: %d",
23244 sect_offset_str (per_cu
->sect_off
),
23245 per_objfile
->get_cu (per_cu
) != nullptr);
23247 /* If necessary, add it to the queue and load its DIEs.
23249 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23250 it doesn't mean they are currently loaded. Since we require them
23251 to be loaded, we must check for ourselves. */
23252 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23253 || per_objfile
->get_cu (per_cu
) == nullptr)
23254 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23255 false, cu
->per_cu
->lang
);
23257 target_cu
= per_objfile
->get_cu (per_cu
);
23258 gdb_assert (target_cu
!= nullptr);
23260 else if (cu
->dies
== NULL
)
23262 /* We're loading full DIEs during partial symbol reading. */
23263 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23264 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23268 *ref_cu
= target_cu
;
23269 temp_die
.sect_off
= sect_off
;
23271 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23273 to_underlying (sect_off
));
23276 /* Follow reference attribute ATTR of SRC_DIE.
23277 On entry *REF_CU is the CU of SRC_DIE.
23278 On exit *REF_CU is the CU of the result. */
23280 static struct die_info
*
23281 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23282 struct dwarf2_cu
**ref_cu
)
23284 sect_offset sect_off
= attr
->get_ref_die_offset ();
23285 struct dwarf2_cu
*cu
= *ref_cu
;
23286 struct die_info
*die
;
23288 die
= follow_die_offset (sect_off
,
23289 (attr
->form
== DW_FORM_GNU_ref_alt
23290 || cu
->per_cu
->is_dwz
),
23293 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23294 "at %s [in module %s]"),
23295 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23296 objfile_name (cu
->per_objfile
->objfile
));
23303 struct dwarf2_locexpr_baton
23304 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23305 dwarf2_per_cu_data
*per_cu
,
23306 dwarf2_per_objfile
*per_objfile
,
23307 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23308 bool resolve_abstract_p
)
23310 struct die_info
*die
;
23311 struct attribute
*attr
;
23312 struct dwarf2_locexpr_baton retval
;
23313 struct objfile
*objfile
= per_objfile
->objfile
;
23315 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23317 cu
= load_cu (per_cu
, per_objfile
, false);
23321 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23322 Instead just throw an error, not much else we can do. */
23323 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23324 sect_offset_str (sect_off
), objfile_name (objfile
));
23327 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23329 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23330 sect_offset_str (sect_off
), objfile_name (objfile
));
23332 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23333 if (!attr
&& resolve_abstract_p
23334 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23335 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23337 CORE_ADDR pc
= get_frame_pc ();
23338 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23339 struct gdbarch
*gdbarch
= objfile
->arch ();
23341 for (const auto &cand_off
23342 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23344 struct dwarf2_cu
*cand_cu
= cu
;
23345 struct die_info
*cand
23346 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23349 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23352 CORE_ADDR pc_low
, pc_high
;
23353 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23354 if (pc_low
== ((CORE_ADDR
) -1))
23356 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23357 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23358 if (!(pc_low
<= pc
&& pc
< pc_high
))
23362 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23369 /* DWARF: "If there is no such attribute, then there is no effect.".
23370 DATA is ignored if SIZE is 0. */
23372 retval
.data
= NULL
;
23375 else if (attr
->form_is_section_offset ())
23377 struct dwarf2_loclist_baton loclist_baton
;
23378 CORE_ADDR pc
= get_frame_pc ();
23381 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23383 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23385 retval
.size
= size
;
23389 if (!attr
->form_is_block ())
23390 error (_("Dwarf Error: DIE at %s referenced in module %s "
23391 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23392 sect_offset_str (sect_off
), objfile_name (objfile
));
23394 struct dwarf_block
*block
= attr
->as_block ();
23395 retval
.data
= block
->data
;
23396 retval
.size
= block
->size
;
23398 retval
.per_objfile
= per_objfile
;
23399 retval
.per_cu
= cu
->per_cu
;
23401 per_objfile
->age_comp_units ();
23408 struct dwarf2_locexpr_baton
23409 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23410 dwarf2_per_cu_data
*per_cu
,
23411 dwarf2_per_objfile
*per_objfile
,
23412 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23414 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23416 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23420 /* Write a constant of a given type as target-ordered bytes into
23423 static const gdb_byte
*
23424 write_constant_as_bytes (struct obstack
*obstack
,
23425 enum bfd_endian byte_order
,
23432 *len
= TYPE_LENGTH (type
);
23433 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23434 store_unsigned_integer (result
, *len
, byte_order
, value
);
23442 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23443 dwarf2_per_cu_data
*per_cu
,
23444 dwarf2_per_objfile
*per_objfile
,
23448 struct die_info
*die
;
23449 struct attribute
*attr
;
23450 const gdb_byte
*result
= NULL
;
23453 enum bfd_endian byte_order
;
23454 struct objfile
*objfile
= per_objfile
->objfile
;
23456 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23458 cu
= load_cu (per_cu
, per_objfile
, false);
23462 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23463 Instead just throw an error, not much else we can do. */
23464 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23465 sect_offset_str (sect_off
), objfile_name (objfile
));
23468 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23470 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23471 sect_offset_str (sect_off
), objfile_name (objfile
));
23473 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23477 byte_order
= (bfd_big_endian (objfile
->obfd
)
23478 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23480 switch (attr
->form
)
23483 case DW_FORM_addrx
:
23484 case DW_FORM_GNU_addr_index
:
23488 *len
= cu
->header
.addr_size
;
23489 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23490 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23494 case DW_FORM_string
:
23497 case DW_FORM_GNU_str_index
:
23498 case DW_FORM_GNU_strp_alt
:
23499 /* The string is already allocated on the objfile obstack, point
23502 const char *attr_name
= attr
->as_string ();
23503 result
= (const gdb_byte
*) attr_name
;
23504 *len
= strlen (attr_name
);
23507 case DW_FORM_block1
:
23508 case DW_FORM_block2
:
23509 case DW_FORM_block4
:
23510 case DW_FORM_block
:
23511 case DW_FORM_exprloc
:
23512 case DW_FORM_data16
:
23514 struct dwarf_block
*block
= attr
->as_block ();
23515 result
= block
->data
;
23516 *len
= block
->size
;
23520 /* The DW_AT_const_value attributes are supposed to carry the
23521 symbol's value "represented as it would be on the target
23522 architecture." By the time we get here, it's already been
23523 converted to host endianness, so we just need to sign- or
23524 zero-extend it as appropriate. */
23525 case DW_FORM_data1
:
23526 type
= die_type (die
, cu
);
23527 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23528 if (result
== NULL
)
23529 result
= write_constant_as_bytes (obstack
, byte_order
,
23532 case DW_FORM_data2
:
23533 type
= die_type (die
, cu
);
23534 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23535 if (result
== NULL
)
23536 result
= write_constant_as_bytes (obstack
, byte_order
,
23539 case DW_FORM_data4
:
23540 type
= die_type (die
, cu
);
23541 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23542 if (result
== NULL
)
23543 result
= write_constant_as_bytes (obstack
, byte_order
,
23546 case DW_FORM_data8
:
23547 type
= die_type (die
, cu
);
23548 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23549 if (result
== NULL
)
23550 result
= write_constant_as_bytes (obstack
, byte_order
,
23554 case DW_FORM_sdata
:
23555 case DW_FORM_implicit_const
:
23556 type
= die_type (die
, cu
);
23557 result
= write_constant_as_bytes (obstack
, byte_order
,
23558 type
, attr
->as_signed (), len
);
23561 case DW_FORM_udata
:
23562 type
= die_type (die
, cu
);
23563 result
= write_constant_as_bytes (obstack
, byte_order
,
23564 type
, attr
->as_unsigned (), len
);
23568 complaint (_("unsupported const value attribute form: '%s'"),
23569 dwarf_form_name (attr
->form
));
23579 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23580 dwarf2_per_cu_data
*per_cu
,
23581 dwarf2_per_objfile
*per_objfile
,
23582 const char **var_name
)
23584 struct die_info
*die
;
23586 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23588 cu
= load_cu (per_cu
, per_objfile
, false);
23593 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23597 if (var_name
!= nullptr)
23598 *var_name
= var_decl_name (die
, cu
);
23599 return die_type (die
, cu
);
23605 dwarf2_get_die_type (cu_offset die_offset
,
23606 dwarf2_per_cu_data
*per_cu
,
23607 dwarf2_per_objfile
*per_objfile
)
23609 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23610 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23613 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23614 On entry *REF_CU is the CU of SRC_DIE.
23615 On exit *REF_CU is the CU of the result.
23616 Returns NULL if the referenced DIE isn't found. */
23618 static struct die_info
*
23619 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23620 struct dwarf2_cu
**ref_cu
)
23622 struct die_info temp_die
;
23623 struct dwarf2_cu
*sig_cu
;
23624 struct die_info
*die
;
23625 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23628 /* While it might be nice to assert sig_type->type == NULL here,
23629 we can get here for DW_AT_imported_declaration where we need
23630 the DIE not the type. */
23632 /* If necessary, add it to the queue and load its DIEs.
23634 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23635 it doesn't mean they are currently loaded. Since we require them
23636 to be loaded, we must check for ourselves. */
23637 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23639 || per_objfile
->get_cu (sig_type
) == nullptr)
23640 read_signatured_type (sig_type
, per_objfile
);
23642 sig_cu
= per_objfile
->get_cu (sig_type
);
23643 gdb_assert (sig_cu
!= NULL
);
23644 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23645 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23646 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23647 to_underlying (temp_die
.sect_off
));
23650 /* For .gdb_index version 7 keep track of included TUs.
23651 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23652 if (per_objfile
->per_bfd
->index_table
!= NULL
23653 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23655 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23665 /* Follow signatured type referenced by ATTR in SRC_DIE.
23666 On entry *REF_CU is the CU of SRC_DIE.
23667 On exit *REF_CU is the CU of the result.
23668 The result is the DIE of the type.
23669 If the referenced type cannot be found an error is thrown. */
23671 static struct die_info
*
23672 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23673 struct dwarf2_cu
**ref_cu
)
23675 ULONGEST signature
= attr
->as_signature ();
23676 struct signatured_type
*sig_type
;
23677 struct die_info
*die
;
23679 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23681 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23682 /* sig_type will be NULL if the signatured type is missing from
23684 if (sig_type
== NULL
)
23686 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23687 " from DIE at %s [in module %s]"),
23688 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23689 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23692 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23695 dump_die_for_error (src_die
);
23696 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23697 " from DIE at %s [in module %s]"),
23698 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23699 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23705 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23706 reading in and processing the type unit if necessary. */
23708 static struct type
*
23709 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23710 struct dwarf2_cu
*cu
)
23712 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23713 struct signatured_type
*sig_type
;
23714 struct dwarf2_cu
*type_cu
;
23715 struct die_info
*type_die
;
23718 sig_type
= lookup_signatured_type (cu
, signature
);
23719 /* sig_type will be NULL if the signatured type is missing from
23721 if (sig_type
== NULL
)
23723 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23724 " from DIE at %s [in module %s]"),
23725 hex_string (signature
), sect_offset_str (die
->sect_off
),
23726 objfile_name (per_objfile
->objfile
));
23727 return build_error_marker_type (cu
, die
);
23730 /* If we already know the type we're done. */
23731 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23732 if (type
!= nullptr)
23736 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23737 if (type_die
!= NULL
)
23739 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23740 is created. This is important, for example, because for c++ classes
23741 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23742 type
= read_type_die (type_die
, type_cu
);
23745 complaint (_("Dwarf Error: Cannot build signatured type %s"
23746 " referenced from DIE at %s [in module %s]"),
23747 hex_string (signature
), sect_offset_str (die
->sect_off
),
23748 objfile_name (per_objfile
->objfile
));
23749 type
= build_error_marker_type (cu
, die
);
23754 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23755 " from DIE at %s [in module %s]"),
23756 hex_string (signature
), sect_offset_str (die
->sect_off
),
23757 objfile_name (per_objfile
->objfile
));
23758 type
= build_error_marker_type (cu
, die
);
23761 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23766 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23767 reading in and processing the type unit if necessary. */
23769 static struct type
*
23770 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23771 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23773 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23774 if (attr
->form_is_ref ())
23776 struct dwarf2_cu
*type_cu
= cu
;
23777 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23779 return read_type_die (type_die
, type_cu
);
23781 else if (attr
->form
== DW_FORM_ref_sig8
)
23783 return get_signatured_type (die
, attr
->as_signature (), cu
);
23787 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23789 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23790 " at %s [in module %s]"),
23791 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23792 objfile_name (per_objfile
->objfile
));
23793 return build_error_marker_type (cu
, die
);
23797 /* Load the DIEs associated with type unit PER_CU into memory. */
23800 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23801 dwarf2_per_objfile
*per_objfile
)
23803 struct signatured_type
*sig_type
;
23805 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23806 gdb_assert (! per_cu
->type_unit_group_p ());
23808 /* We have the per_cu, but we need the signatured_type.
23809 Fortunately this is an easy translation. */
23810 gdb_assert (per_cu
->is_debug_types
);
23811 sig_type
= (struct signatured_type
*) per_cu
;
23813 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23815 read_signatured_type (sig_type
, per_objfile
);
23817 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23820 /* Read in a signatured type and build its CU and DIEs.
23821 If the type is a stub for the real type in a DWO file,
23822 read in the real type from the DWO file as well. */
23825 read_signatured_type (signatured_type
*sig_type
,
23826 dwarf2_per_objfile
*per_objfile
)
23828 gdb_assert (sig_type
->is_debug_types
);
23829 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23831 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23833 if (!reader
.dummy_p
)
23835 struct dwarf2_cu
*cu
= reader
.cu
;
23836 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23838 gdb_assert (cu
->die_hash
== NULL
);
23840 htab_create_alloc_ex (cu
->header
.length
/ 12,
23844 &cu
->comp_unit_obstack
,
23845 hashtab_obstack_allocate
,
23846 dummy_obstack_deallocate
);
23848 if (reader
.comp_unit_die
->has_children
)
23849 reader
.comp_unit_die
->child
23850 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23851 reader
.comp_unit_die
);
23852 cu
->dies
= reader
.comp_unit_die
;
23853 /* comp_unit_die is not stored in die_hash, no need. */
23855 /* We try not to read any attributes in this function, because
23856 not all CUs needed for references have been loaded yet, and
23857 symbol table processing isn't initialized. But we have to
23858 set the CU language, or we won't be able to build types
23859 correctly. Similarly, if we do not read the producer, we can
23860 not apply producer-specific interpretation. */
23861 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23866 sig_type
->tu_read
= 1;
23869 /* Decode simple location descriptions.
23870 Given a pointer to a dwarf block that defines a location, compute
23871 the location and return the value. If COMPUTED is non-null, it is
23872 set to true to indicate that decoding was successful, and false
23873 otherwise. If COMPUTED is null, then this function may emit a
23877 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23879 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23881 size_t size
= blk
->size
;
23882 const gdb_byte
*data
= blk
->data
;
23883 CORE_ADDR stack
[64];
23885 unsigned int bytes_read
, unsnd
;
23888 if (computed
!= nullptr)
23894 stack
[++stacki
] = 0;
23933 stack
[++stacki
] = op
- DW_OP_lit0
;
23968 stack
[++stacki
] = op
- DW_OP_reg0
;
23971 if (computed
== nullptr)
23972 dwarf2_complex_location_expr_complaint ();
23979 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23981 stack
[++stacki
] = unsnd
;
23984 if (computed
== nullptr)
23985 dwarf2_complex_location_expr_complaint ();
23992 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23997 case DW_OP_const1u
:
23998 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24002 case DW_OP_const1s
:
24003 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24007 case DW_OP_const2u
:
24008 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24012 case DW_OP_const2s
:
24013 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24017 case DW_OP_const4u
:
24018 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24022 case DW_OP_const4s
:
24023 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24027 case DW_OP_const8u
:
24028 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24033 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24039 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24044 stack
[stacki
+ 1] = stack
[stacki
];
24049 stack
[stacki
- 1] += stack
[stacki
];
24053 case DW_OP_plus_uconst
:
24054 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24060 stack
[stacki
- 1] -= stack
[stacki
];
24065 /* If we're not the last op, then we definitely can't encode
24066 this using GDB's address_class enum. This is valid for partial
24067 global symbols, although the variable's address will be bogus
24071 if (computed
== nullptr)
24072 dwarf2_complex_location_expr_complaint ();
24078 case DW_OP_GNU_push_tls_address
:
24079 case DW_OP_form_tls_address
:
24080 /* The top of the stack has the offset from the beginning
24081 of the thread control block at which the variable is located. */
24082 /* Nothing should follow this operator, so the top of stack would
24084 /* This is valid for partial global symbols, but the variable's
24085 address will be bogus in the psymtab. Make it always at least
24086 non-zero to not look as a variable garbage collected by linker
24087 which have DW_OP_addr 0. */
24090 if (computed
== nullptr)
24091 dwarf2_complex_location_expr_complaint ();
24098 case DW_OP_GNU_uninit
:
24099 if (computed
!= nullptr)
24104 case DW_OP_GNU_addr_index
:
24105 case DW_OP_GNU_const_index
:
24106 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24112 if (computed
== nullptr)
24114 const char *name
= get_DW_OP_name (op
);
24117 complaint (_("unsupported stack op: '%s'"),
24120 complaint (_("unsupported stack op: '%02x'"),
24124 return (stack
[stacki
]);
24127 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24128 outside of the allocated space. Also enforce minimum>0. */
24129 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24131 if (computed
== nullptr)
24132 complaint (_("location description stack overflow"));
24138 if (computed
== nullptr)
24139 complaint (_("location description stack underflow"));
24144 if (computed
!= nullptr)
24146 return (stack
[stacki
]);
24149 /* memory allocation interface */
24151 static struct dwarf_block
*
24152 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24154 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24157 static struct die_info
*
24158 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24160 struct die_info
*die
;
24161 size_t size
= sizeof (struct die_info
);
24164 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24166 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24167 memset (die
, 0, sizeof (struct die_info
));
24173 /* Macro support. */
24175 /* An overload of dwarf_decode_macros that finds the correct section
24176 and ensures it is read in before calling the other overload. */
24179 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24180 int section_is_gnu
)
24182 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24183 struct objfile
*objfile
= per_objfile
->objfile
;
24184 const struct line_header
*lh
= cu
->line_header
;
24185 unsigned int offset_size
= cu
->header
.offset_size
;
24186 struct dwarf2_section_info
*section
;
24187 const char *section_name
;
24189 if (cu
->dwo_unit
!= nullptr)
24191 if (section_is_gnu
)
24193 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24194 section_name
= ".debug_macro.dwo";
24198 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24199 section_name
= ".debug_macinfo.dwo";
24204 if (section_is_gnu
)
24206 section
= &per_objfile
->per_bfd
->macro
;
24207 section_name
= ".debug_macro";
24211 section
= &per_objfile
->per_bfd
->macinfo
;
24212 section_name
= ".debug_macinfo";
24216 section
->read (objfile
);
24217 if (section
->buffer
== nullptr)
24219 complaint (_("missing %s section"), section_name
);
24223 buildsym_compunit
*builder
= cu
->get_builder ();
24225 struct dwarf2_section_info
*str_offsets_section
;
24226 struct dwarf2_section_info
*str_section
;
24227 gdb::optional
<ULONGEST
> str_offsets_base
;
24229 if (cu
->dwo_unit
!= nullptr)
24231 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24232 ->sections
.str_offsets
;
24233 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24234 str_offsets_base
= cu
->header
.addr_size
;
24238 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24239 str_section
= &per_objfile
->per_bfd
->str
;
24240 str_offsets_base
= cu
->str_offsets_base
;
24243 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24244 offset_size
, offset
, str_section
, str_offsets_section
,
24245 str_offsets_base
, section_is_gnu
);
24248 /* Return the .debug_loc section to use for CU.
24249 For DWO files use .debug_loc.dwo. */
24251 static struct dwarf2_section_info
*
24252 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24254 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24258 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24260 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24262 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24263 : &per_objfile
->per_bfd
->loc
);
24266 /* Return the .debug_rnglists section to use for CU. */
24267 static struct dwarf2_section_info
*
24268 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24270 if (cu
->header
.version
< 5)
24271 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24272 cu
->header
.version
);
24273 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24275 /* Make sure we read the .debug_rnglists section from the file that
24276 contains the DW_AT_ranges attribute we are reading. Normally that
24277 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24278 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24280 if (cu
->dwo_unit
!= nullptr
24281 && tag
!= DW_TAG_compile_unit
24282 && tag
!= DW_TAG_skeleton_unit
)
24284 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24286 if (sections
->rnglists
.size
> 0)
24287 return §ions
->rnglists
;
24289 error (_(".debug_rnglists section is missing from .dwo file."));
24291 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24294 /* A helper function that fills in a dwarf2_loclist_baton. */
24297 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24298 struct dwarf2_loclist_baton
*baton
,
24299 const struct attribute
*attr
)
24301 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24302 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24304 section
->read (per_objfile
->objfile
);
24306 baton
->per_objfile
= per_objfile
;
24307 baton
->per_cu
= cu
->per_cu
;
24308 gdb_assert (baton
->per_cu
);
24309 /* We don't know how long the location list is, but make sure we
24310 don't run off the edge of the section. */
24311 baton
->size
= section
->size
- attr
->as_unsigned ();
24312 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24313 if (cu
->base_address
.has_value ())
24314 baton
->base_address
= *cu
->base_address
;
24316 baton
->base_address
= 0;
24317 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24321 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24322 struct dwarf2_cu
*cu
, int is_block
)
24324 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24325 struct objfile
*objfile
= per_objfile
->objfile
;
24326 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24328 if (attr
->form_is_section_offset ()
24329 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24330 the section. If so, fall through to the complaint in the
24332 && attr
->as_unsigned () < section
->get_size (objfile
))
24334 struct dwarf2_loclist_baton
*baton
;
24336 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24338 fill_in_loclist_baton (cu
, baton
, attr
);
24340 if (!cu
->base_address
.has_value ())
24341 complaint (_("Location list used without "
24342 "specifying the CU base address."));
24344 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24345 ? dwarf2_loclist_block_index
24346 : dwarf2_loclist_index
);
24347 SYMBOL_LOCATION_BATON (sym
) = baton
;
24351 struct dwarf2_locexpr_baton
*baton
;
24353 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24354 baton
->per_objfile
= per_objfile
;
24355 baton
->per_cu
= cu
->per_cu
;
24356 gdb_assert (baton
->per_cu
);
24358 if (attr
->form_is_block ())
24360 /* Note that we're just copying the block's data pointer
24361 here, not the actual data. We're still pointing into the
24362 info_buffer for SYM's objfile; right now we never release
24363 that buffer, but when we do clean up properly this may
24365 struct dwarf_block
*block
= attr
->as_block ();
24366 baton
->size
= block
->size
;
24367 baton
->data
= block
->data
;
24371 dwarf2_invalid_attrib_class_complaint ("location description",
24372 sym
->natural_name ());
24376 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24377 ? dwarf2_locexpr_block_index
24378 : dwarf2_locexpr_index
);
24379 SYMBOL_LOCATION_BATON (sym
) = baton
;
24385 const comp_unit_head
*
24386 dwarf2_per_cu_data::get_header () const
24388 if (!m_header_read_in
)
24390 const gdb_byte
*info_ptr
24391 = this->section
->buffer
+ to_underlying (this->sect_off
);
24393 memset (&m_header
, 0, sizeof (m_header
));
24395 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24396 rcuh_kind::COMPILE
);
24398 m_header_read_in
= true;
24407 dwarf2_per_cu_data::addr_size () const
24409 return this->get_header ()->addr_size
;
24415 dwarf2_per_cu_data::offset_size () const
24417 return this->get_header ()->offset_size
;
24423 dwarf2_per_cu_data::ref_addr_size () const
24425 const comp_unit_head
*header
= this->get_header ();
24427 if (header
->version
== 2)
24428 return header
->addr_size
;
24430 return header
->offset_size
;
24433 /* A helper function for dwarf2_find_containing_comp_unit that returns
24434 the index of the result, and that searches a vector. It will
24435 return a result even if the offset in question does not actually
24436 occur in any CU. This is separate so that it can be unit
24440 dwarf2_find_containing_comp_unit
24441 (sect_offset sect_off
,
24442 unsigned int offset_in_dwz
,
24443 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24448 high
= all_comp_units
.size () - 1;
24451 struct dwarf2_per_cu_data
*mid_cu
;
24452 int mid
= low
+ (high
- low
) / 2;
24454 mid_cu
= all_comp_units
[mid
].get ();
24455 if (mid_cu
->is_dwz
> offset_in_dwz
24456 || (mid_cu
->is_dwz
== offset_in_dwz
24457 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24462 gdb_assert (low
== high
);
24466 /* Locate the .debug_info compilation unit from CU's objfile which contains
24467 the DIE at OFFSET. Raises an error on failure. */
24469 static struct dwarf2_per_cu_data
*
24470 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24471 unsigned int offset_in_dwz
,
24472 dwarf2_per_bfd
*per_bfd
)
24474 int low
= dwarf2_find_containing_comp_unit
24475 (sect_off
, offset_in_dwz
, per_bfd
->all_comp_units
);
24476 dwarf2_per_cu_data
*this_cu
= per_bfd
->all_comp_units
[low
].get ();
24478 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24480 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24481 error (_("Dwarf Error: could not find partial DIE containing "
24482 "offset %s [in module %s]"),
24483 sect_offset_str (sect_off
),
24484 bfd_get_filename (per_bfd
->obfd
));
24486 gdb_assert (per_bfd
->all_comp_units
[low
-1]->sect_off
24488 return per_bfd
->all_comp_units
[low
- 1].get ();
24492 if (low
== per_bfd
->all_comp_units
.size () - 1
24493 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24494 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24495 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24502 namespace selftests
{
24503 namespace find_containing_comp_unit
{
24508 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24509 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24510 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24511 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24512 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24513 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24514 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24515 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24518 two
->sect_off
= sect_offset (one
->length
);
24523 four
->sect_off
= sect_offset (three
->length
);
24527 std::vector
<dwarf2_per_cu_data_up
> units
;
24528 units
.push_back (std::move (one
));
24529 units
.push_back (std::move (two
));
24530 units
.push_back (std::move (three
));
24531 units
.push_back (std::move (four
));
24535 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24536 SELF_CHECK (units
[result
].get () == one_ptr
);
24537 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24538 SELF_CHECK (units
[result
].get () == one_ptr
);
24539 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24540 SELF_CHECK (units
[result
].get () == two_ptr
);
24542 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24543 SELF_CHECK (units
[result
].get () == three_ptr
);
24544 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24545 SELF_CHECK (units
[result
].get () == three_ptr
);
24546 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24547 SELF_CHECK (units
[result
].get () == four_ptr
);
24553 #endif /* GDB_SELF_TEST */
24555 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24558 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24559 enum language pretend_language
)
24561 struct attribute
*attr
;
24563 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24565 /* Set the language we're debugging. */
24566 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24567 if (cu
->producer
!= nullptr
24568 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24570 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24571 attribute is not standardised yet. As a workaround for the
24572 language detection we fall back to the DW_AT_producer
24574 cu
->per_cu
->lang
= language_opencl
;
24576 else if (cu
->producer
!= nullptr
24577 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24579 /* Similar hack for Go. */
24580 cu
->per_cu
->lang
= language_go
;
24582 else if (attr
!= nullptr)
24583 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24585 cu
->per_cu
->lang
= pretend_language
;
24586 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24592 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24594 auto it
= m_dwarf2_cus
.find (per_cu
);
24595 if (it
== m_dwarf2_cus
.end ())
24604 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24606 gdb_assert (this->get_cu (per_cu
) == nullptr);
24608 m_dwarf2_cus
[per_cu
] = cu
;
24614 dwarf2_per_objfile::age_comp_units ()
24616 dwarf_read_debug_printf_v ("running");
24618 /* This is not expected to be called in the middle of CU expansion. There is
24619 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24620 loaded in memory. Calling age_comp_units while the queue is in use could
24621 make us free the DIEs for a CU that is in the queue and therefore break
24623 gdb_assert (!this->per_bfd
->queue
.has_value ());
24625 /* Start by clearing all marks. */
24626 for (auto pair
: m_dwarf2_cus
)
24627 pair
.second
->clear_mark ();
24629 /* Traverse all CUs, mark them and their dependencies if used recently
24631 for (auto pair
: m_dwarf2_cus
)
24633 dwarf2_cu
*cu
= pair
.second
;
24636 if (cu
->last_used
<= dwarf_max_cache_age
)
24640 /* Delete all CUs still not marked. */
24641 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24643 dwarf2_cu
*cu
= it
->second
;
24645 if (!cu
->is_marked ())
24647 dwarf_read_debug_printf_v ("deleting old CU %s",
24648 sect_offset_str (cu
->per_cu
->sect_off
));
24650 it
= m_dwarf2_cus
.erase (it
);
24660 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24662 auto it
= m_dwarf2_cus
.find (per_cu
);
24663 if (it
== m_dwarf2_cus
.end ())
24668 m_dwarf2_cus
.erase (it
);
24671 dwarf2_per_objfile::~dwarf2_per_objfile ()
24676 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24677 We store these in a hash table separate from the DIEs, and preserve them
24678 when the DIEs are flushed out of cache.
24680 The CU "per_cu" pointer is needed because offset alone is not enough to
24681 uniquely identify the type. A file may have multiple .debug_types sections,
24682 or the type may come from a DWO file. Furthermore, while it's more logical
24683 to use per_cu->section+offset, with Fission the section with the data is in
24684 the DWO file but we don't know that section at the point we need it.
24685 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24686 because we can enter the lookup routine, get_die_type_at_offset, from
24687 outside this file, and thus won't necessarily have PER_CU->cu.
24688 Fortunately, PER_CU is stable for the life of the objfile. */
24690 struct dwarf2_per_cu_offset_and_type
24692 const struct dwarf2_per_cu_data
*per_cu
;
24693 sect_offset sect_off
;
24697 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24700 per_cu_offset_and_type_hash (const void *item
)
24702 const struct dwarf2_per_cu_offset_and_type
*ofs
24703 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24705 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24708 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24711 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24713 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24714 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24715 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24716 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24718 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24719 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24722 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24723 table if necessary. For convenience, return TYPE.
24725 The DIEs reading must have careful ordering to:
24726 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24727 reading current DIE.
24728 * Not trying to dereference contents of still incompletely read in types
24729 while reading in other DIEs.
24730 * Enable referencing still incompletely read in types just by a pointer to
24731 the type without accessing its fields.
24733 Therefore caller should follow these rules:
24734 * Try to fetch any prerequisite types we may need to build this DIE type
24735 before building the type and calling set_die_type.
24736 * After building type call set_die_type for current DIE as soon as
24737 possible before fetching more types to complete the current type.
24738 * Make the type as complete as possible before fetching more types. */
24740 static struct type
*
24741 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24742 bool skip_data_location
)
24744 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24745 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24746 struct objfile
*objfile
= per_objfile
->objfile
;
24747 struct attribute
*attr
;
24748 struct dynamic_prop prop
;
24750 /* For Ada types, make sure that the gnat-specific data is always
24751 initialized (if not already set). There are a few types where
24752 we should not be doing so, because the type-specific area is
24753 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24754 where the type-specific area is used to store the floatformat).
24755 But this is not a problem, because the gnat-specific information
24756 is actually not needed for these types. */
24757 if (need_gnat_info (cu
)
24758 && type
->code () != TYPE_CODE_FUNC
24759 && type
->code () != TYPE_CODE_FLT
24760 && type
->code () != TYPE_CODE_METHODPTR
24761 && type
->code () != TYPE_CODE_MEMBERPTR
24762 && type
->code () != TYPE_CODE_METHOD
24763 && type
->code () != TYPE_CODE_FIXED_POINT
24764 && !HAVE_GNAT_AUX_INFO (type
))
24765 INIT_GNAT_SPECIFIC (type
);
24767 /* Read DW_AT_allocated and set in type. */
24768 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24771 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24772 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24773 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24776 /* Read DW_AT_associated and set in type. */
24777 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24780 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24781 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24782 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24785 /* Read DW_AT_data_location and set in type. */
24786 if (!skip_data_location
)
24788 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24789 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24790 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24793 if (per_objfile
->die_type_hash
== NULL
)
24794 per_objfile
->die_type_hash
24795 = htab_up (htab_create_alloc (127,
24796 per_cu_offset_and_type_hash
,
24797 per_cu_offset_and_type_eq
,
24798 NULL
, xcalloc
, xfree
));
24800 ofs
.per_cu
= cu
->per_cu
;
24801 ofs
.sect_off
= die
->sect_off
;
24803 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24804 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24806 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24807 sect_offset_str (die
->sect_off
));
24808 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24809 struct dwarf2_per_cu_offset_and_type
);
24814 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24815 or return NULL if the die does not have a saved type. */
24817 static struct type
*
24818 get_die_type_at_offset (sect_offset sect_off
,
24819 dwarf2_per_cu_data
*per_cu
,
24820 dwarf2_per_objfile
*per_objfile
)
24822 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24824 if (per_objfile
->die_type_hash
== NULL
)
24827 ofs
.per_cu
= per_cu
;
24828 ofs
.sect_off
= sect_off
;
24829 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24830 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24837 /* Look up the type for DIE in CU in die_type_hash,
24838 or return NULL if DIE does not have a saved type. */
24840 static struct type
*
24841 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24843 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24846 /* Trivial hash function for partial_die_info: the hash value of a DIE
24847 is its offset in .debug_info for this objfile. */
24850 partial_die_hash (const void *item
)
24852 const struct partial_die_info
*part_die
24853 = (const struct partial_die_info
*) item
;
24855 return to_underlying (part_die
->sect_off
);
24858 /* Trivial comparison function for partial_die_info structures: two DIEs
24859 are equal if they have the same offset. */
24862 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24864 const struct partial_die_info
*part_die_lhs
24865 = (const struct partial_die_info
*) item_lhs
;
24866 const struct partial_die_info
*part_die_rhs
24867 = (const struct partial_die_info
*) item_rhs
;
24869 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24872 struct cmd_list_element
*set_dwarf_cmdlist
;
24873 struct cmd_list_element
*show_dwarf_cmdlist
;
24876 show_check_physname (struct ui_file
*file
, int from_tty
,
24877 struct cmd_list_element
*c
, const char *value
)
24879 fprintf_filtered (file
,
24880 _("Whether to check \"physname\" is %s.\n"),
24884 void _initialize_dwarf2_read ();
24886 _initialize_dwarf2_read ()
24888 add_setshow_prefix_cmd ("dwarf", class_maintenance
,
24890 Set DWARF specific variables.\n\
24891 Configure DWARF variables such as the cache size."),
24893 Show DWARF specific variables.\n\
24894 Show DWARF variables such as the cache size."),
24895 &set_dwarf_cmdlist
, &show_dwarf_cmdlist
,
24896 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
24898 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24899 &dwarf_max_cache_age
, _("\
24900 Set the upper bound on the age of cached DWARF compilation units."), _("\
24901 Show the upper bound on the age of cached DWARF compilation units."), _("\
24902 A higher limit means that cached compilation units will be stored\n\
24903 in memory longer, and more total memory will be used. Zero disables\n\
24904 caching, which can slow down startup."),
24906 show_dwarf_max_cache_age
,
24907 &set_dwarf_cmdlist
,
24908 &show_dwarf_cmdlist
);
24910 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24911 Set debugging of the DWARF reader."), _("\
24912 Show debugging of the DWARF reader."), _("\
24913 When enabled (non-zero), debugging messages are printed during DWARF\n\
24914 reading and symtab expansion. A value of 1 (one) provides basic\n\
24915 information. A value greater than 1 provides more verbose information."),
24918 &setdebuglist
, &showdebuglist
);
24920 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24921 Set debugging of the DWARF DIE reader."), _("\
24922 Show debugging of the DWARF DIE reader."), _("\
24923 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24924 The value is the maximum depth to print."),
24927 &setdebuglist
, &showdebuglist
);
24929 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24930 Set debugging of the dwarf line reader."), _("\
24931 Show debugging of the dwarf line reader."), _("\
24932 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24933 A value of 1 (one) provides basic information.\n\
24934 A value greater than 1 provides more verbose information."),
24937 &setdebuglist
, &showdebuglist
);
24939 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24940 Set cross-checking of \"physname\" code against demangler."), _("\
24941 Show cross-checking of \"physname\" code against demangler."), _("\
24942 When enabled, GDB's internal \"physname\" code is checked against\n\
24944 NULL
, show_check_physname
,
24945 &setdebuglist
, &showdebuglist
);
24947 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24948 no_class
, &use_deprecated_index_sections
, _("\
24949 Set whether to use deprecated gdb_index sections."), _("\
24950 Show whether to use deprecated gdb_index sections."), _("\
24951 When enabled, deprecated .gdb_index sections are used anyway.\n\
24952 Normally they are ignored either because of a missing feature or\n\
24953 performance issue.\n\
24954 Warning: This option must be enabled before gdb reads the file."),
24957 &setlist
, &showlist
);
24959 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24960 &dwarf2_locexpr_funcs
);
24961 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24962 &dwarf2_loclist_funcs
);
24964 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24965 &dwarf2_block_frame_base_locexpr_funcs
);
24966 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24967 &dwarf2_block_frame_base_loclist_funcs
);
24970 selftests::register_test ("dw2_expand_symtabs_matching",
24971 selftests::dw2_expand_symtabs_matching::run_test
);
24972 selftests::register_test ("dwarf2_find_containing_comp_unit",
24973 selftests::find_containing_comp_unit::run_test
);