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 may_be_inlined
: 1;
868 /* This DIE has been marked DW_AT_main_subprogram. */
869 unsigned int main_subprogram
: 1;
871 /* Flag set if the SCOPE field of this structure has been
873 unsigned int scope_set
: 1;
875 /* Flag set if the DIE has a byte_size attribute. */
876 unsigned int has_byte_size
: 1;
878 /* Flag set if the DIE has a DW_AT_const_value attribute. */
879 unsigned int has_const_value
: 1;
881 /* Flag set if any of the DIE's children are template arguments. */
882 unsigned int has_template_arguments
: 1;
884 /* Flag set if fixup has been called on this die. */
885 unsigned int fixup_called
: 1;
887 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
888 unsigned int is_dwz
: 1;
890 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
891 unsigned int spec_is_dwz
: 1;
893 unsigned int canonical_name
: 1;
895 /* The name of this DIE. Normally the value of DW_AT_name, but
896 sometimes a default name for unnamed DIEs. */
897 const char *raw_name
= nullptr;
899 /* The linkage name, if present. */
900 const char *linkage_name
= nullptr;
902 /* The scope to prepend to our children. This is generally
903 allocated on the comp_unit_obstack, so will disappear
904 when this compilation unit leaves the cache. */
905 const char *scope
= nullptr;
907 /* Some data associated with the partial DIE. The tag determines
908 which field is live. */
911 /* The location description associated with this DIE, if any. */
912 struct dwarf_block
*locdesc
;
913 /* The offset of an import, for DW_TAG_imported_unit. */
914 sect_offset sect_off
;
917 /* If HAS_PC_INFO, the PC range associated with this DIE. */
919 CORE_ADDR highpc
= 0;
921 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
922 DW_AT_sibling, if any. */
923 /* NOTE: This member isn't strictly necessary, partial_die_info::read
924 could return DW_AT_sibling values to its caller load_partial_dies. */
925 const gdb_byte
*sibling
= nullptr;
927 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
928 DW_AT_specification (or DW_AT_abstract_origin or
930 sect_offset spec_offset
{};
932 /* Pointers to this DIE's parent, first child, and next sibling,
934 struct partial_die_info
*die_parent
= nullptr;
935 struct partial_die_info
*die_child
= nullptr;
936 struct partial_die_info
*die_sibling
= nullptr;
938 friend struct partial_die_info
*
939 dwarf2_cu::find_partial_die (sect_offset sect_off
);
942 /* Only need to do look up in dwarf2_cu::find_partial_die. */
943 partial_die_info (sect_offset sect_off
)
944 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
948 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
950 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
955 has_specification
= 0;
962 has_template_arguments
= 0;
970 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
971 but this would require a corresponding change in unpack_field_as_long
973 static int bits_per_byte
= 8;
975 struct variant_part_builder
;
977 /* When reading a variant, we track a bit more information about the
978 field, and store it in an object of this type. */
982 int first_field
= -1;
985 /* A variant can contain other variant parts. */
986 std::vector
<variant_part_builder
> variant_parts
;
988 /* If we see a DW_TAG_variant, then this will be set if this is the
990 bool default_branch
= false;
991 /* If we see a DW_AT_discr_value, then this will be the discriminant
993 ULONGEST discriminant_value
= 0;
994 /* If we see a DW_AT_discr_list, then this is a pointer to the list
996 struct dwarf_block
*discr_list_data
= nullptr;
999 /* This represents a DW_TAG_variant_part. */
1001 struct variant_part_builder
1003 /* The offset of the discriminant field. */
1004 sect_offset discriminant_offset
{};
1006 /* Variants that are direct children of this variant part. */
1007 std::vector
<variant_field
> variants
;
1009 /* True if we're currently reading a variant. */
1010 bool processing_variant
= false;
1015 int accessibility
= 0;
1017 /* Variant parts need to find the discriminant, which is a DIE
1018 reference. We track the section offset of each field to make
1021 struct field field
{};
1026 const char *name
= nullptr;
1027 std::vector
<struct fn_field
> fnfields
;
1030 /* The routines that read and process dies for a C struct or C++ class
1031 pass lists of data member fields and lists of member function fields
1032 in an instance of a field_info structure, as defined below. */
1035 /* List of data member and baseclasses fields. */
1036 std::vector
<struct nextfield
> fields
;
1037 std::vector
<struct nextfield
> baseclasses
;
1039 /* Set if the accessibility of one of the fields is not public. */
1040 bool non_public_fields
= false;
1042 /* Member function fieldlist array, contains name of possibly overloaded
1043 member function, number of overloaded member functions and a pointer
1044 to the head of the member function field chain. */
1045 std::vector
<struct fnfieldlist
> fnfieldlists
;
1047 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1048 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1049 std::vector
<struct decl_field
> typedef_field_list
;
1051 /* Nested types defined by this class and the number of elements in this
1053 std::vector
<struct decl_field
> nested_types_list
;
1055 /* If non-null, this is the variant part we are currently
1057 variant_part_builder
*current_variant_part
= nullptr;
1058 /* This holds all the top-level variant parts attached to the type
1060 std::vector
<variant_part_builder
> variant_parts
;
1062 /* Return the total number of fields (including baseclasses). */
1063 int nfields () const
1065 return fields
.size () + baseclasses
.size ();
1069 /* Loaded secondary compilation units are kept in memory until they
1070 have not been referenced for the processing of this many
1071 compilation units. Set this to zero to disable caching. Cache
1072 sizes of up to at least twenty will improve startup time for
1073 typical inter-CU-reference binaries, at an obvious memory cost. */
1074 static int dwarf_max_cache_age
= 5;
1076 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1077 struct cmd_list_element
*c
, const char *value
)
1079 fprintf_filtered (file
, _("The upper bound on the age of cached "
1080 "DWARF compilation units is %s.\n"),
1084 /* local function prototypes */
1086 static void dwarf2_find_base_address (struct die_info
*die
,
1087 struct dwarf2_cu
*cu
);
1089 static dwarf2_psymtab
*create_partial_symtab
1090 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1093 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1094 const gdb_byte
*info_ptr
,
1095 struct die_info
*type_unit_die
);
1097 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1099 static void scan_partial_symbols (struct partial_die_info
*,
1100 CORE_ADDR
*, CORE_ADDR
*,
1101 int, struct dwarf2_cu
*);
1103 static void add_partial_symbol (struct partial_die_info
*,
1104 struct dwarf2_cu
*);
1106 static void add_partial_namespace (struct partial_die_info
*pdi
,
1107 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1108 int set_addrmap
, struct dwarf2_cu
*cu
);
1110 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1111 CORE_ADDR
*highpc
, int set_addrmap
,
1112 struct dwarf2_cu
*cu
);
1114 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1115 struct dwarf2_cu
*cu
);
1117 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1118 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1119 int need_pc
, struct dwarf2_cu
*cu
);
1121 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1123 static struct partial_die_info
*load_partial_dies
1124 (const struct die_reader_specs
*, const gdb_byte
*, int);
1126 /* A pair of partial_die_info and compilation unit. */
1127 struct cu_partial_die_info
1129 /* The compilation unit of the partial_die_info. */
1130 struct dwarf2_cu
*cu
;
1131 /* A partial_die_info. */
1132 struct partial_die_info
*pdi
;
1134 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1140 cu_partial_die_info () = delete;
1143 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1144 struct dwarf2_cu
*);
1146 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1148 const struct attr_abbrev
*,
1151 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1152 struct attribute
*attr
, dwarf_tag tag
);
1154 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1156 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1157 dwarf2_section_info
*, sect_offset
);
1159 static const char *read_indirect_string
1160 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1161 const struct comp_unit_head
*, unsigned int *);
1163 static const char *read_indirect_string_at_offset
1164 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1166 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1170 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1171 ULONGEST str_index
);
1173 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1174 ULONGEST str_index
);
1176 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1177 struct dwarf2_cu
*);
1179 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1180 struct dwarf2_cu
*cu
);
1182 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1184 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1185 struct dwarf2_cu
*cu
);
1187 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1189 static struct die_info
*die_specification (struct die_info
*die
,
1190 struct dwarf2_cu
**);
1192 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1193 struct dwarf2_cu
*cu
);
1195 static void dwarf_decode_lines (struct line_header
*, const char *,
1196 struct dwarf2_cu
*, dwarf2_psymtab
*,
1197 CORE_ADDR
, int decode_mapping
);
1199 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1202 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1203 struct dwarf2_cu
*, struct symbol
* = NULL
);
1205 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1206 struct dwarf2_cu
*);
1208 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1211 struct obstack
*obstack
,
1212 struct dwarf2_cu
*cu
, LONGEST
*value
,
1213 const gdb_byte
**bytes
,
1214 struct dwarf2_locexpr_baton
**baton
);
1216 static struct type
*read_subrange_index_type (struct die_info
*die
,
1217 struct dwarf2_cu
*cu
);
1219 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1221 static int need_gnat_info (struct dwarf2_cu
*);
1223 static struct type
*die_descriptive_type (struct die_info
*,
1224 struct dwarf2_cu
*);
1226 static void set_descriptive_type (struct type
*, struct die_info
*,
1227 struct dwarf2_cu
*);
1229 static struct type
*die_containing_type (struct die_info
*,
1230 struct dwarf2_cu
*);
1232 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1233 struct dwarf2_cu
*);
1235 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1237 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1239 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1241 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1242 const char *suffix
, int physname
,
1243 struct dwarf2_cu
*cu
);
1245 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1247 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1249 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1251 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1253 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1255 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1257 /* Return the .debug_loclists section to use for cu. */
1258 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1260 /* Return the .debug_rnglists section to use for cu. */
1261 static struct dwarf2_section_info
*cu_debug_rnglists_section
1262 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1264 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1265 values. Keep the items ordered with increasing constraints compliance. */
1268 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1269 PC_BOUNDS_NOT_PRESENT
,
1271 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1272 were present but they do not form a valid range of PC addresses. */
1275 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1278 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1282 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1283 CORE_ADDR
*, CORE_ADDR
*,
1287 static void get_scope_pc_bounds (struct die_info
*,
1288 CORE_ADDR
*, CORE_ADDR
*,
1289 struct dwarf2_cu
*);
1291 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1292 CORE_ADDR
, struct dwarf2_cu
*);
1294 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1295 struct dwarf2_cu
*);
1297 static void dwarf2_attach_fields_to_type (struct field_info
*,
1298 struct type
*, struct dwarf2_cu
*);
1300 static void dwarf2_add_member_fn (struct field_info
*,
1301 struct die_info
*, struct type
*,
1302 struct dwarf2_cu
*);
1304 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1306 struct dwarf2_cu
*);
1308 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1310 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1312 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1314 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1316 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1318 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1320 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1322 static struct type
*read_module_type (struct die_info
*die
,
1323 struct dwarf2_cu
*cu
);
1325 static const char *namespace_name (struct die_info
*die
,
1326 int *is_anonymous
, struct dwarf2_cu
*);
1328 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1330 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1333 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1334 struct dwarf2_cu
*);
1336 static struct die_info
*read_die_and_siblings_1
1337 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1340 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1341 const gdb_byte
*info_ptr
,
1342 const gdb_byte
**new_info_ptr
,
1343 struct die_info
*parent
);
1345 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1346 struct die_info
**, const gdb_byte
*,
1349 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1350 struct die_info
**, const gdb_byte
*);
1352 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1354 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1357 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1359 static const char *dwarf2_full_name (const char *name
,
1360 struct die_info
*die
,
1361 struct dwarf2_cu
*cu
);
1363 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1364 struct dwarf2_cu
*cu
);
1366 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1367 struct dwarf2_cu
**);
1369 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1371 static void dump_die_for_error (struct die_info
*);
1373 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1376 /*static*/ void dump_die (struct die_info
*, int max_level
);
1378 static void store_in_ref_table (struct die_info
*,
1379 struct dwarf2_cu
*);
1381 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1382 const struct attribute
*,
1383 struct dwarf2_cu
**);
1385 static struct die_info
*follow_die_ref (struct die_info
*,
1386 const struct attribute
*,
1387 struct dwarf2_cu
**);
1389 static struct die_info
*follow_die_sig (struct die_info
*,
1390 const struct attribute
*,
1391 struct dwarf2_cu
**);
1393 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1394 struct dwarf2_cu
*);
1396 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1397 const struct attribute
*,
1398 struct dwarf2_cu
*);
1400 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1401 dwarf2_per_objfile
*per_objfile
);
1403 static void read_signatured_type (signatured_type
*sig_type
,
1404 dwarf2_per_objfile
*per_objfile
);
1406 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1407 struct die_info
*die
, struct dwarf2_cu
*cu
,
1408 struct dynamic_prop
*prop
, struct type
*type
);
1410 /* memory allocation interface */
1412 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1414 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1416 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1418 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1419 struct dwarf2_loclist_baton
*baton
,
1420 const struct attribute
*attr
);
1422 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1424 struct dwarf2_cu
*cu
,
1427 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1428 const gdb_byte
*info_ptr
,
1429 const struct abbrev_info
*abbrev
);
1431 static hashval_t
partial_die_hash (const void *item
);
1433 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1435 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1436 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1437 dwarf2_per_objfile
*per_objfile
);
1439 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1440 struct die_info
*comp_unit_die
,
1441 enum language pretend_language
);
1443 static struct type
*set_die_type (struct die_info
*, struct type
*,
1444 struct dwarf2_cu
*, bool = false);
1446 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1448 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1449 dwarf2_per_objfile
*per_objfile
,
1450 dwarf2_cu
*existing_cu
,
1452 enum language pretend_language
);
1454 static void process_full_comp_unit (dwarf2_cu
*cu
,
1455 enum language pretend_language
);
1457 static void process_full_type_unit (dwarf2_cu
*cu
,
1458 enum language pretend_language
);
1460 static struct type
*get_die_type_at_offset (sect_offset
,
1461 dwarf2_per_cu_data
*per_cu
,
1462 dwarf2_per_objfile
*per_objfile
);
1464 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1466 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1467 dwarf2_per_objfile
*per_objfile
,
1468 enum language pretend_language
);
1470 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1472 /* Class, the destructor of which frees all allocated queue entries. This
1473 will only have work to do if an error was thrown while processing the
1474 dwarf. If no error was thrown then the queue entries should have all
1475 been processed, and freed, as we went along. */
1477 class dwarf2_queue_guard
1480 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1481 : m_per_objfile (per_objfile
)
1483 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1485 m_per_objfile
->per_bfd
->queue
.emplace ();
1488 /* Free any entries remaining on the queue. There should only be
1489 entries left if we hit an error while processing the dwarf. */
1490 ~dwarf2_queue_guard ()
1492 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1494 m_per_objfile
->per_bfd
->queue
.reset ();
1497 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1500 dwarf2_per_objfile
*m_per_objfile
;
1503 dwarf2_queue_item::~dwarf2_queue_item ()
1505 /* Anything still marked queued is likely to be in an
1506 inconsistent state, so discard it. */
1509 per_objfile
->remove_cu (per_cu
);
1514 /* See dwarf2/read.h. */
1517 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1519 if (data
->is_debug_types
)
1520 delete static_cast<signatured_type
*> (data
);
1525 /* The return type of find_file_and_directory. Note, the enclosed
1526 string pointers are only valid while this object is valid. */
1528 struct file_and_directory
1530 /* The filename. This is never NULL. */
1533 /* The compilation directory. NULL if not known. If we needed to
1534 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1535 points directly to the DW_AT_comp_dir string attribute owned by
1536 the obstack that owns the DIE. */
1537 const char *comp_dir
;
1539 /* If we needed to build a new string for comp_dir, this is what
1540 owns the storage. */
1541 std::string comp_dir_storage
;
1544 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1545 struct dwarf2_cu
*cu
);
1547 static htab_up
allocate_signatured_type_table ();
1549 static htab_up
allocate_dwo_unit_table ();
1551 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1552 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1553 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1555 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1557 static struct dwo_unit
*lookup_dwo_comp_unit
1558 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1559 ULONGEST signature
);
1561 static struct dwo_unit
*lookup_dwo_type_unit
1562 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1564 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1566 /* A unique pointer to a dwo_file. */
1568 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1570 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1572 static void check_producer (struct dwarf2_cu
*cu
);
1574 /* Various complaints about symbol reading that don't abort the process. */
1577 dwarf2_debug_line_missing_file_complaint (void)
1579 complaint (_(".debug_line section has line data without a file"));
1583 dwarf2_debug_line_missing_end_sequence_complaint (void)
1585 complaint (_(".debug_line section has line "
1586 "program sequence without an end"));
1590 dwarf2_complex_location_expr_complaint (void)
1592 complaint (_("location expression too complex"));
1596 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1599 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1604 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1606 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1610 /* Hash function for line_header_hash. */
1613 line_header_hash (const struct line_header
*ofs
)
1615 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1618 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1621 line_header_hash_voidp (const void *item
)
1623 const struct line_header
*ofs
= (const struct line_header
*) item
;
1625 return line_header_hash (ofs
);
1628 /* Equality function for line_header_hash. */
1631 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1633 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1634 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1636 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1637 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1642 /* An iterator for all_comp_units that is based on index. This
1643 approach makes it possible to iterate over all_comp_units safely,
1644 when some caller in the loop may add new units. */
1646 class all_comp_units_iterator
1650 all_comp_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1651 : m_per_bfd (per_bfd
),
1652 m_index (start
? 0 : per_bfd
->all_comp_units
.size ())
1656 all_comp_units_iterator
&operator++ ()
1662 dwarf2_per_cu_data
*operator* () const
1664 return m_per_bfd
->get_cu (m_index
);
1667 bool operator== (const all_comp_units_iterator
&other
) const
1669 return m_index
== other
.m_index
;
1673 bool operator!= (const all_comp_units_iterator
&other
) const
1675 return m_index
!= other
.m_index
;
1680 dwarf2_per_bfd
*m_per_bfd
;
1684 /* A range adapter for the all_comp_units_iterator. */
1685 class all_comp_units_range
1689 all_comp_units_range (dwarf2_per_bfd
*per_bfd
)
1690 : m_per_bfd (per_bfd
)
1694 all_comp_units_iterator
begin ()
1696 return all_comp_units_iterator (m_per_bfd
, true);
1699 all_comp_units_iterator
end ()
1701 return all_comp_units_iterator (m_per_bfd
, false);
1706 dwarf2_per_bfd
*m_per_bfd
;
1709 /* See declaration. */
1711 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1714 can_copy (can_copy_
)
1717 names
= &dwarf2_elf_names
;
1719 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1720 locate_sections (obfd
, sec
, *names
);
1723 dwarf2_per_bfd::~dwarf2_per_bfd ()
1725 for (auto &per_cu
: all_comp_units
)
1726 per_cu
->imported_symtabs_free ();
1728 /* Everything else should be on this->obstack. */
1734 dwarf2_per_objfile::remove_all_cus ()
1736 gdb_assert (!this->per_bfd
->queue
.has_value ());
1738 for (auto pair
: m_dwarf2_cus
)
1741 m_dwarf2_cus
.clear ();
1744 /* A helper class that calls free_cached_comp_units on
1747 class free_cached_comp_units
1751 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1752 : m_per_objfile (per_objfile
)
1756 ~free_cached_comp_units ()
1758 m_per_objfile
->remove_all_cus ();
1761 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1765 dwarf2_per_objfile
*m_per_objfile
;
1771 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1773 if (per_cu
->index
< this->m_symtabs
.size ())
1774 return this->m_symtabs
[per_cu
->index
] != nullptr;
1781 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1783 if (per_cu
->index
< this->m_symtabs
.size ())
1784 return this->m_symtabs
[per_cu
->index
];
1791 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1792 compunit_symtab
*symtab
)
1794 if (per_cu
->index
>= this->m_symtabs
.size ())
1795 this->m_symtabs
.resize (per_cu
->index
+ 1);
1796 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1797 this->m_symtabs
[per_cu
->index
] = symtab
;
1800 /* Try to locate the sections we need for DWARF 2 debugging
1801 information and return true if we have enough to do something.
1802 NAMES points to the dwarf2 section names, or is NULL if the standard
1803 ELF names are used. CAN_COPY is true for formats where symbol
1804 interposition is possible and so symbol values must follow copy
1805 relocation rules. */
1808 dwarf2_has_info (struct objfile
*objfile
,
1809 const struct dwarf2_debug_sections
*names
,
1812 if (objfile
->flags
& OBJF_READNEVER
)
1815 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1817 if (per_objfile
== NULL
)
1819 dwarf2_per_bfd
*per_bfd
;
1821 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1822 BFD doesn't require relocations.
1824 We don't share with objfiles for which -readnow was requested,
1825 because it would complicate things when loading the same BFD with
1826 -readnow and then without -readnow. */
1827 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1828 && (objfile
->flags
& OBJF_READNOW
) == 0)
1830 /* See if one has been created for this BFD yet. */
1831 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1833 if (per_bfd
== nullptr)
1835 /* No, create it now. */
1836 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1837 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1842 /* No sharing possible, create one specifically for this objfile. */
1843 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1844 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1847 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1850 return (!per_objfile
->per_bfd
->info
.is_virtual
1851 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1852 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1853 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1856 /* See declaration. */
1859 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1860 const dwarf2_debug_sections
&names
)
1862 flagword aflag
= bfd_section_flags (sectp
);
1864 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1867 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1868 > bfd_get_file_size (abfd
))
1870 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1871 warning (_("Discarding section %s which has a section size (%s"
1872 ") larger than the file size [in module %s]"),
1873 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1874 bfd_get_filename (abfd
));
1876 else if (names
.info
.matches (sectp
->name
))
1878 this->info
.s
.section
= sectp
;
1879 this->info
.size
= bfd_section_size (sectp
);
1881 else if (names
.abbrev
.matches (sectp
->name
))
1883 this->abbrev
.s
.section
= sectp
;
1884 this->abbrev
.size
= bfd_section_size (sectp
);
1886 else if (names
.line
.matches (sectp
->name
))
1888 this->line
.s
.section
= sectp
;
1889 this->line
.size
= bfd_section_size (sectp
);
1891 else if (names
.loc
.matches (sectp
->name
))
1893 this->loc
.s
.section
= sectp
;
1894 this->loc
.size
= bfd_section_size (sectp
);
1896 else if (names
.loclists
.matches (sectp
->name
))
1898 this->loclists
.s
.section
= sectp
;
1899 this->loclists
.size
= bfd_section_size (sectp
);
1901 else if (names
.macinfo
.matches (sectp
->name
))
1903 this->macinfo
.s
.section
= sectp
;
1904 this->macinfo
.size
= bfd_section_size (sectp
);
1906 else if (names
.macro
.matches (sectp
->name
))
1908 this->macro
.s
.section
= sectp
;
1909 this->macro
.size
= bfd_section_size (sectp
);
1911 else if (names
.str
.matches (sectp
->name
))
1913 this->str
.s
.section
= sectp
;
1914 this->str
.size
= bfd_section_size (sectp
);
1916 else if (names
.str_offsets
.matches (sectp
->name
))
1918 this->str_offsets
.s
.section
= sectp
;
1919 this->str_offsets
.size
= bfd_section_size (sectp
);
1921 else if (names
.line_str
.matches (sectp
->name
))
1923 this->line_str
.s
.section
= sectp
;
1924 this->line_str
.size
= bfd_section_size (sectp
);
1926 else if (names
.addr
.matches (sectp
->name
))
1928 this->addr
.s
.section
= sectp
;
1929 this->addr
.size
= bfd_section_size (sectp
);
1931 else if (names
.frame
.matches (sectp
->name
))
1933 this->frame
.s
.section
= sectp
;
1934 this->frame
.size
= bfd_section_size (sectp
);
1936 else if (names
.eh_frame
.matches (sectp
->name
))
1938 this->eh_frame
.s
.section
= sectp
;
1939 this->eh_frame
.size
= bfd_section_size (sectp
);
1941 else if (names
.ranges
.matches (sectp
->name
))
1943 this->ranges
.s
.section
= sectp
;
1944 this->ranges
.size
= bfd_section_size (sectp
);
1946 else if (names
.rnglists
.matches (sectp
->name
))
1948 this->rnglists
.s
.section
= sectp
;
1949 this->rnglists
.size
= bfd_section_size (sectp
);
1951 else if (names
.types
.matches (sectp
->name
))
1953 struct dwarf2_section_info type_section
;
1955 memset (&type_section
, 0, sizeof (type_section
));
1956 type_section
.s
.section
= sectp
;
1957 type_section
.size
= bfd_section_size (sectp
);
1959 this->types
.push_back (type_section
);
1961 else if (names
.gdb_index
.matches (sectp
->name
))
1963 this->gdb_index
.s
.section
= sectp
;
1964 this->gdb_index
.size
= bfd_section_size (sectp
);
1966 else if (names
.debug_names
.matches (sectp
->name
))
1968 this->debug_names
.s
.section
= sectp
;
1969 this->debug_names
.size
= bfd_section_size (sectp
);
1971 else if (names
.debug_aranges
.matches (sectp
->name
))
1973 this->debug_aranges
.s
.section
= sectp
;
1974 this->debug_aranges
.size
= bfd_section_size (sectp
);
1977 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1978 && bfd_section_vma (sectp
) == 0)
1979 this->has_section_at_zero
= true;
1982 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1986 dwarf2_get_section_info (struct objfile
*objfile
,
1987 enum dwarf2_section_enum sect
,
1988 asection
**sectp
, const gdb_byte
**bufp
,
1989 bfd_size_type
*sizep
)
1991 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1992 struct dwarf2_section_info
*info
;
1994 /* We may see an objfile without any DWARF, in which case we just
1996 if (per_objfile
== NULL
)
2005 case DWARF2_DEBUG_FRAME
:
2006 info
= &per_objfile
->per_bfd
->frame
;
2008 case DWARF2_EH_FRAME
:
2009 info
= &per_objfile
->per_bfd
->eh_frame
;
2012 gdb_assert_not_reached ("unexpected section");
2015 info
->read (objfile
);
2017 *sectp
= info
->get_bfd_section ();
2018 *bufp
= info
->buffer
;
2019 *sizep
= info
->size
;
2023 /* DWARF quick_symbol_functions support. */
2025 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2026 unique line tables, so we maintain a separate table of all .debug_line
2027 derived entries to support the sharing.
2028 All the quick functions need is the list of file names. We discard the
2029 line_header when we're done and don't need to record it here. */
2030 struct quick_file_names
2032 /* The data used to construct the hash key. */
2033 struct stmt_list_hash hash
;
2035 /* The number of entries in file_names, real_names. */
2036 unsigned int num_file_names
;
2038 /* The file names from the line table, after being run through
2040 const char **file_names
;
2042 /* The file names from the line table after being run through
2043 gdb_realpath. These are computed lazily. */
2044 const char **real_names
;
2047 /* When using the index (and thus not using psymtabs), each CU has an
2048 object of this type. This is used to hold information needed by
2049 the various "quick" methods. */
2050 struct dwarf2_per_cu_quick_data
2052 /* The file table. This can be NULL if there was no file table
2053 or it's currently not read in.
2054 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2055 struct quick_file_names
*file_names
;
2057 /* A temporary mark bit used when iterating over all CUs in
2058 expand_symtabs_matching. */
2059 unsigned int mark
: 1;
2061 /* True if we've tried to read the file table and found there isn't one.
2062 There will be no point in trying to read it again next time. */
2063 unsigned int no_file_data
: 1;
2066 /* A subclass of psymbol_functions that arranges to read the DWARF
2067 partial symbols when needed. */
2068 struct lazy_dwarf_reader
: public psymbol_functions
2070 using psymbol_functions::psymbol_functions
;
2072 bool can_lazily_read_symbols () override
2077 void read_partial_symbols (struct objfile
*objfile
) override
2079 if (dwarf2_has_info (objfile
, nullptr))
2080 dwarf2_build_psymtabs (objfile
, this);
2084 static quick_symbol_functions_up
2085 make_lazy_dwarf_reader ()
2087 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2090 struct dwarf2_base_index_functions
: public quick_symbol_functions
2092 bool has_symbols (struct objfile
*objfile
) override
;
2094 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2096 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2098 void forget_cached_source_info (struct objfile
*objfile
) override
;
2100 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2103 bool *symbol_found_p
) override
2105 *symbol_found_p
= false;
2106 return language_unknown
;
2109 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2111 void expand_all_symtabs (struct objfile
*objfile
) override
;
2113 struct compunit_symtab
*find_pc_sect_compunit_symtab
2114 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2115 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2117 struct compunit_symtab
*find_compunit_symtab_by_address
2118 (struct objfile
*objfile
, CORE_ADDR address
) override
2123 void map_symbol_filenames (struct objfile
*objfile
,
2124 gdb::function_view
<symbol_filename_ftype
> fun
,
2125 bool need_fullname
) override
;
2128 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2130 void dump (struct objfile
*objfile
) override
;
2132 void expand_matching_symbols
2134 const lookup_name_info
&lookup_name
,
2137 symbol_compare_ftype
*ordered_compare
) override
;
2139 bool expand_symtabs_matching
2140 (struct objfile
*objfile
,
2141 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2142 const lookup_name_info
*lookup_name
,
2143 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2144 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2145 block_search_flags search_flags
,
2147 enum search_domain kind
) override
;
2150 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2152 void dump (struct objfile
*objfile
) override
;
2154 void expand_matching_symbols
2156 const lookup_name_info
&lookup_name
,
2159 symbol_compare_ftype
*ordered_compare
) override
;
2161 bool expand_symtabs_matching
2162 (struct objfile
*objfile
,
2163 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2164 const lookup_name_info
*lookup_name
,
2165 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2166 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2167 block_search_flags search_flags
,
2169 enum search_domain kind
) override
;
2172 static quick_symbol_functions_up
2173 make_dwarf_gdb_index ()
2175 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2178 static quick_symbol_functions_up
2179 make_dwarf_debug_names ()
2181 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2184 /* Utility hash function for a stmt_list_hash. */
2187 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2191 if (stmt_list_hash
->dwo_unit
!= NULL
)
2192 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2193 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2197 /* Utility equality function for a stmt_list_hash. */
2200 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2201 const struct stmt_list_hash
*rhs
)
2203 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2205 if (lhs
->dwo_unit
!= NULL
2206 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2209 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2212 /* Hash function for a quick_file_names. */
2215 hash_file_name_entry (const void *e
)
2217 const struct quick_file_names
*file_data
2218 = (const struct quick_file_names
*) e
;
2220 return hash_stmt_list_entry (&file_data
->hash
);
2223 /* Equality function for a quick_file_names. */
2226 eq_file_name_entry (const void *a
, const void *b
)
2228 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2229 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2231 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2234 /* Delete function for a quick_file_names. */
2237 delete_file_name_entry (void *e
)
2239 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2242 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2244 xfree ((void*) file_data
->file_names
[i
]);
2245 if (file_data
->real_names
)
2246 xfree ((void*) file_data
->real_names
[i
]);
2249 /* The space for the struct itself lives on the obstack, so we don't
2253 /* Create a quick_file_names hash table. */
2256 create_quick_file_names_table (unsigned int nr_initial_entries
)
2258 return htab_up (htab_create_alloc (nr_initial_entries
,
2259 hash_file_name_entry
, eq_file_name_entry
,
2260 delete_file_name_entry
, xcalloc
, xfree
));
2263 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2264 function is unrelated to symtabs, symtab would have to be created afterwards.
2265 You should call age_cached_comp_units after processing the CU. */
2268 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2271 if (per_cu
->is_debug_types
)
2272 load_full_type_unit (per_cu
, per_objfile
);
2274 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2275 skip_partial
, language_minimal
);
2277 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2279 return nullptr; /* Dummy CU. */
2281 dwarf2_find_base_address (cu
->dies
, cu
);
2286 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2289 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2290 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2292 /* Skip type_unit_groups, reading the type units they contain
2293 is handled elsewhere. */
2294 if (per_cu
->type_unit_group_p ())
2298 /* The destructor of dwarf2_queue_guard frees any entries left on
2299 the queue. After this point we're guaranteed to leave this function
2300 with the dwarf queue empty. */
2301 dwarf2_queue_guard
q_guard (per_objfile
);
2303 if (!per_objfile
->symtab_set_p (per_cu
))
2305 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2306 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2308 /* If we just loaded a CU from a DWO, and we're working with an index
2309 that may badly handle TUs, load all the TUs in that DWO as well.
2310 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2311 if (!per_cu
->is_debug_types
2313 && cu
->dwo_unit
!= NULL
2314 && per_objfile
->per_bfd
->index_table
!= NULL
2315 && per_objfile
->per_bfd
->index_table
->version
<= 7
2316 /* DWP files aren't supported yet. */
2317 && get_dwp_file (per_objfile
) == NULL
)
2318 queue_and_load_all_dwo_tus (cu
);
2321 process_queue (per_objfile
);
2324 /* Age the cache, releasing compilation units that have not
2325 been used recently. */
2326 per_objfile
->age_comp_units ();
2329 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2330 the per-objfile for which this symtab is instantiated.
2332 Returns the resulting symbol table. */
2334 static struct compunit_symtab
*
2335 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2336 dwarf2_per_objfile
*per_objfile
,
2339 gdb_assert (per_objfile
->per_bfd
->using_index
);
2341 if (!per_objfile
->symtab_set_p (per_cu
))
2343 free_cached_comp_units
freer (per_objfile
);
2344 scoped_restore decrementer
= increment_reading_symtab ();
2345 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2346 process_cu_includes (per_objfile
);
2349 return per_objfile
->get_symtab (per_cu
);
2354 dwarf2_per_cu_data_up
2355 dwarf2_per_bfd::allocate_per_cu ()
2357 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2358 result
->per_bfd
= this;
2359 result
->index
= all_comp_units
.size ();
2366 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2368 signatured_type_up
result (new signatured_type (signature
));
2369 result
->per_bfd
= this;
2370 result
->index
= all_comp_units
.size ();
2371 result
->is_debug_types
= true;
2376 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2377 obstack, and constructed with the specified field values. */
2379 static dwarf2_per_cu_data_up
2380 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2381 struct dwarf2_section_info
*section
,
2383 sect_offset sect_off
, ULONGEST length
)
2385 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2386 the_cu
->sect_off
= sect_off
;
2387 the_cu
->length
= length
;
2388 the_cu
->section
= section
;
2389 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2390 struct dwarf2_per_cu_quick_data
);
2391 the_cu
->is_dwz
= is_dwz
;
2395 /* A helper for create_cus_from_index that handles a given list of
2399 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2400 const gdb_byte
*cu_list
, offset_type n_elements
,
2401 struct dwarf2_section_info
*section
,
2404 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2406 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2408 sect_offset sect_off
2409 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2410 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2413 dwarf2_per_cu_data_up per_cu
2414 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2416 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2420 /* Read the CU list from the mapped index, and use it to create all
2421 the CU objects for PER_BFD. */
2424 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2425 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2426 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2428 gdb_assert (per_bfd
->all_comp_units
.empty ());
2429 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2431 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2434 if (dwz_elements
== 0)
2437 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2438 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2442 /* Create the signatured type hash table from the index. */
2445 create_signatured_type_table_from_index
2446 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2447 const gdb_byte
*bytes
, offset_type elements
)
2449 htab_up sig_types_hash
= allocate_signatured_type_table ();
2451 for (offset_type i
= 0; i
< elements
; i
+= 3)
2453 signatured_type_up sig_type
;
2456 cu_offset type_offset_in_tu
;
2458 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2459 sect_offset sect_off
2460 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2462 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2464 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2467 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2468 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2469 sig_type
->section
= section
;
2470 sig_type
->sect_off
= sect_off
;
2472 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2473 struct dwarf2_per_cu_quick_data
);
2475 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2476 *slot
= sig_type
.get ();
2478 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2481 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2484 /* Create the signatured type hash table from .debug_names. */
2487 create_signatured_type_table_from_debug_names
2488 (dwarf2_per_objfile
*per_objfile
,
2489 const mapped_debug_names
&map
,
2490 struct dwarf2_section_info
*section
,
2491 struct dwarf2_section_info
*abbrev_section
)
2493 struct objfile
*objfile
= per_objfile
->objfile
;
2495 section
->read (objfile
);
2496 abbrev_section
->read (objfile
);
2498 htab_up sig_types_hash
= allocate_signatured_type_table ();
2500 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2502 signatured_type_up sig_type
;
2505 sect_offset sect_off
2506 = (sect_offset
) (extract_unsigned_integer
2507 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2509 map
.dwarf5_byte_order
));
2511 comp_unit_head cu_header
;
2512 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2514 section
->buffer
+ to_underlying (sect_off
),
2517 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2518 (cu_header
.signature
);
2519 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2520 sig_type
->section
= section
;
2521 sig_type
->sect_off
= sect_off
;
2523 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2524 struct dwarf2_per_cu_quick_data
);
2526 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2527 *slot
= sig_type
.get ();
2529 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2532 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2535 /* Read the address map data from the mapped index, and use it to
2536 populate the psymtabs_addrmap. */
2539 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2540 struct mapped_index
*index
)
2542 struct objfile
*objfile
= per_objfile
->objfile
;
2543 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2544 struct gdbarch
*gdbarch
= objfile
->arch ();
2545 const gdb_byte
*iter
, *end
;
2546 struct addrmap
*mutable_map
;
2549 auto_obstack temp_obstack
;
2551 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2553 iter
= index
->address_table
.data ();
2554 end
= iter
+ index
->address_table
.size ();
2556 baseaddr
= objfile
->text_section_offset ();
2560 ULONGEST hi
, lo
, cu_index
;
2561 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2563 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2565 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2570 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2571 hex_string (lo
), hex_string (hi
));
2575 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2577 complaint (_(".gdb_index address table has invalid CU number %u"),
2578 (unsigned) cu_index
);
2582 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2583 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2584 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2585 per_bfd
->get_cu (cu_index
));
2588 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2592 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2593 populate the psymtabs_addrmap. */
2596 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2597 struct dwarf2_section_info
*section
)
2599 struct objfile
*objfile
= per_objfile
->objfile
;
2600 bfd
*abfd
= objfile
->obfd
;
2601 struct gdbarch
*gdbarch
= objfile
->arch ();
2602 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2603 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2605 auto_obstack temp_obstack
;
2606 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2608 std::unordered_map
<sect_offset
,
2609 dwarf2_per_cu_data
*,
2610 gdb::hash_enum
<sect_offset
>>
2611 debug_info_offset_to_per_cu
;
2612 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2614 const auto insertpair
2615 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2617 if (!insertpair
.second
)
2619 warning (_("Section .debug_aranges in %s has duplicate "
2620 "debug_info_offset %s, ignoring .debug_aranges."),
2621 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2626 section
->read (objfile
);
2628 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2630 const gdb_byte
*addr
= section
->buffer
;
2632 while (addr
< section
->buffer
+ section
->size
)
2634 const gdb_byte
*const entry_addr
= addr
;
2635 unsigned int bytes_read
;
2637 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2641 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2642 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2643 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2644 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2646 warning (_("Section .debug_aranges in %s entry at offset %s "
2647 "length %s exceeds section length %s, "
2648 "ignoring .debug_aranges."),
2649 objfile_name (objfile
),
2650 plongest (entry_addr
- section
->buffer
),
2651 plongest (bytes_read
+ entry_length
),
2652 pulongest (section
->size
));
2656 /* The version number. */
2657 const uint16_t version
= read_2_bytes (abfd
, addr
);
2661 warning (_("Section .debug_aranges in %s entry at offset %s "
2662 "has unsupported version %d, ignoring .debug_aranges."),
2663 objfile_name (objfile
),
2664 plongest (entry_addr
- section
->buffer
), version
);
2668 const uint64_t debug_info_offset
2669 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2670 addr
+= offset_size
;
2671 const auto per_cu_it
2672 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2673 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2675 warning (_("Section .debug_aranges in %s entry at offset %s "
2676 "debug_info_offset %s does not exists, "
2677 "ignoring .debug_aranges."),
2678 objfile_name (objfile
),
2679 plongest (entry_addr
- section
->buffer
),
2680 pulongest (debug_info_offset
));
2683 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2685 const uint8_t address_size
= *addr
++;
2686 if (address_size
< 1 || address_size
> 8)
2688 warning (_("Section .debug_aranges in %s entry at offset %s "
2689 "address_size %u is invalid, ignoring .debug_aranges."),
2690 objfile_name (objfile
),
2691 plongest (entry_addr
- section
->buffer
), address_size
);
2695 const uint8_t segment_selector_size
= *addr
++;
2696 if (segment_selector_size
!= 0)
2698 warning (_("Section .debug_aranges in %s entry at offset %s "
2699 "segment_selector_size %u is not supported, "
2700 "ignoring .debug_aranges."),
2701 objfile_name (objfile
),
2702 plongest (entry_addr
- section
->buffer
),
2703 segment_selector_size
);
2707 /* Must pad to an alignment boundary that is twice the address
2708 size. It is undocumented by the DWARF standard but GCC does
2709 use it. However, not every compiler does this. We can see
2710 whether it has happened by looking at the total length of the
2711 contents of the aranges for this CU -- it if isn't a multiple
2712 of twice the address size, then we skip any leftover
2714 addr
+= (entry_end
- addr
) % (2 * address_size
);
2718 if (addr
+ 2 * address_size
> entry_end
)
2720 warning (_("Section .debug_aranges in %s entry at offset %s "
2721 "address list is not properly terminated, "
2722 "ignoring .debug_aranges."),
2723 objfile_name (objfile
),
2724 plongest (entry_addr
- section
->buffer
));
2727 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2729 addr
+= address_size
;
2730 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2732 addr
+= address_size
;
2733 if (start
== 0 && length
== 0)
2735 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2737 /* Symbol was eliminated due to a COMDAT group. */
2740 ULONGEST end
= start
+ length
;
2741 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2743 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2745 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2749 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2753 /* A helper function that reads the .gdb_index from BUFFER and fills
2754 in MAP. FILENAME is the name of the file containing the data;
2755 it is used for error reporting. DEPRECATED_OK is true if it is
2756 ok to use deprecated sections.
2758 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2759 out parameters that are filled in with information about the CU and
2760 TU lists in the section.
2762 Returns true if all went well, false otherwise. */
2765 read_gdb_index_from_buffer (const char *filename
,
2767 gdb::array_view
<const gdb_byte
> buffer
,
2768 struct mapped_index
*map
,
2769 const gdb_byte
**cu_list
,
2770 offset_type
*cu_list_elements
,
2771 const gdb_byte
**types_list
,
2772 offset_type
*types_list_elements
)
2774 const gdb_byte
*addr
= &buffer
[0];
2775 offset_view
metadata (buffer
);
2777 /* Version check. */
2778 offset_type version
= metadata
[0];
2779 /* Versions earlier than 3 emitted every copy of a psymbol. This
2780 causes the index to behave very poorly for certain requests. Version 3
2781 contained incomplete addrmap. So, it seems better to just ignore such
2785 static int warning_printed
= 0;
2786 if (!warning_printed
)
2788 warning (_("Skipping obsolete .gdb_index section in %s."),
2790 warning_printed
= 1;
2794 /* Index version 4 uses a different hash function than index version
2797 Versions earlier than 6 did not emit psymbols for inlined
2798 functions. Using these files will cause GDB not to be able to
2799 set breakpoints on inlined functions by name, so we ignore these
2800 indices unless the user has done
2801 "set use-deprecated-index-sections on". */
2802 if (version
< 6 && !deprecated_ok
)
2804 static int warning_printed
= 0;
2805 if (!warning_printed
)
2808 Skipping deprecated .gdb_index section in %s.\n\
2809 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2810 to use the section anyway."),
2812 warning_printed
= 1;
2816 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2817 of the TU (for symbols coming from TUs),
2818 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2819 Plus gold-generated indices can have duplicate entries for global symbols,
2820 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2821 These are just performance bugs, and we can't distinguish gdb-generated
2822 indices from gold-generated ones, so issue no warning here. */
2824 /* Indexes with higher version than the one supported by GDB may be no
2825 longer backward compatible. */
2829 map
->version
= version
;
2832 *cu_list
= addr
+ metadata
[i
];
2833 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2836 *types_list
= addr
+ metadata
[i
];
2837 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2840 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2841 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2843 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2846 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2847 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2849 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2853 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2858 /* Callback types for dwarf2_read_gdb_index. */
2860 typedef gdb::function_view
2861 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2862 get_gdb_index_contents_ftype
;
2863 typedef gdb::function_view
2864 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2865 get_gdb_index_contents_dwz_ftype
;
2867 /* Read .gdb_index. If everything went ok, initialize the "quick"
2868 elements of all the CUs and return 1. Otherwise, return 0. */
2871 dwarf2_read_gdb_index
2872 (dwarf2_per_objfile
*per_objfile
,
2873 get_gdb_index_contents_ftype get_gdb_index_contents
,
2874 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2876 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2877 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2878 struct dwz_file
*dwz
;
2879 struct objfile
*objfile
= per_objfile
->objfile
;
2880 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2882 gdb::array_view
<const gdb_byte
> main_index_contents
2883 = get_gdb_index_contents (objfile
, per_bfd
);
2885 if (main_index_contents
.empty ())
2888 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2889 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2890 use_deprecated_index_sections
,
2891 main_index_contents
, map
.get (), &cu_list
,
2892 &cu_list_elements
, &types_list
,
2893 &types_list_elements
))
2896 /* Don't use the index if it's empty. */
2897 if (map
->symbol_table
.empty ())
2900 /* If there is a .dwz file, read it so we can get its CU list as
2902 dwz
= dwarf2_get_dwz_file (per_bfd
);
2905 struct mapped_index dwz_map
;
2906 const gdb_byte
*dwz_types_ignore
;
2907 offset_type dwz_types_elements_ignore
;
2909 gdb::array_view
<const gdb_byte
> dwz_index_content
2910 = get_gdb_index_contents_dwz (objfile
, dwz
);
2912 if (dwz_index_content
.empty ())
2915 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2916 1, dwz_index_content
, &dwz_map
,
2917 &dwz_list
, &dwz_list_elements
,
2919 &dwz_types_elements_ignore
))
2921 warning (_("could not read '.gdb_index' section from %s; skipping"),
2922 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2927 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2930 if (types_list_elements
)
2932 /* We can only handle a single .debug_types when we have an
2934 if (per_bfd
->types
.size () != 1)
2937 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2939 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2940 types_list_elements
);
2943 create_addrmap_from_index (per_objfile
, map
.get ());
2945 per_bfd
->index_table
= std::move (map
);
2946 per_bfd
->using_index
= 1;
2947 per_bfd
->quick_file_names_table
=
2948 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2953 /* die_reader_func for dw2_get_file_names. */
2956 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2957 struct die_info
*comp_unit_die
)
2959 struct dwarf2_cu
*cu
= reader
->cu
;
2960 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2961 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2962 struct dwarf2_per_cu_data
*lh_cu
;
2963 struct attribute
*attr
;
2965 struct quick_file_names
*qfn
;
2967 gdb_assert (! this_cu
->is_debug_types
);
2969 /* Our callers never want to match partial units -- instead they
2970 will match the enclosing full CU. */
2971 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2973 this_cu
->v
.quick
->no_file_data
= 1;
2981 sect_offset line_offset
{};
2983 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2984 if (attr
!= nullptr && attr
->form_is_unsigned ())
2986 struct quick_file_names find_entry
;
2988 line_offset
= (sect_offset
) attr
->as_unsigned ();
2990 /* We may have already read in this line header (TU line header sharing).
2991 If we have we're done. */
2992 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2993 find_entry
.hash
.line_sect_off
= line_offset
;
2994 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2995 &find_entry
, INSERT
);
2998 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3002 lh
= dwarf_decode_line_header (line_offset
, cu
);
3006 lh_cu
->v
.quick
->no_file_data
= 1;
3010 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3011 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3012 qfn
->hash
.line_sect_off
= line_offset
;
3013 gdb_assert (slot
!= NULL
);
3016 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3019 if (strcmp (fnd
.name
, "<unknown>") != 0)
3022 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3024 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3025 qfn
->num_file_names
);
3027 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3028 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3029 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3030 fnd
.comp_dir
).release ();
3031 qfn
->real_names
= NULL
;
3033 lh_cu
->v
.quick
->file_names
= qfn
;
3036 /* A helper for the "quick" functions which attempts to read the line
3037 table for THIS_CU. */
3039 static struct quick_file_names
*
3040 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3041 dwarf2_per_objfile
*per_objfile
)
3043 /* This should never be called for TUs. */
3044 gdb_assert (! this_cu
->is_debug_types
);
3045 /* Nor type unit groups. */
3046 gdb_assert (! this_cu
->type_unit_group_p ());
3048 if (this_cu
->v
.quick
->file_names
!= NULL
)
3049 return this_cu
->v
.quick
->file_names
;
3050 /* If we know there is no line data, no point in looking again. */
3051 if (this_cu
->v
.quick
->no_file_data
)
3054 cutu_reader
reader (this_cu
, per_objfile
);
3055 if (!reader
.dummy_p
)
3056 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3058 if (this_cu
->v
.quick
->no_file_data
)
3060 return this_cu
->v
.quick
->file_names
;
3063 /* A helper for the "quick" functions which computes and caches the
3064 real path for a given file name from the line table. */
3067 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3068 struct quick_file_names
*qfn
, int index
)
3070 if (qfn
->real_names
== NULL
)
3071 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3072 qfn
->num_file_names
, const char *);
3074 if (qfn
->real_names
[index
] == NULL
)
3075 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3077 return qfn
->real_names
[index
];
3081 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3083 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3084 dwarf2_per_cu_data
*dwarf_cu
3085 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3086 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3091 return compunit_primary_filetab (cust
);
3094 /* Traversal function for dw2_forget_cached_source_info. */
3097 dw2_free_cached_file_names (void **slot
, void *info
)
3099 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3101 if (file_data
->real_names
)
3105 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3107 xfree ((void*) file_data
->real_names
[i
]);
3108 file_data
->real_names
[i
] = NULL
;
3116 dwarf2_base_index_functions::forget_cached_source_info
3117 (struct objfile
*objfile
)
3119 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3121 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3122 dw2_free_cached_file_names
, NULL
);
3125 /* Struct used to manage iterating over all CUs looking for a symbol. */
3127 struct dw2_symtab_iterator
3129 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3130 dwarf2_per_objfile
*per_objfile
;
3131 /* If set, only look for symbols that match that block. Valid values are
3132 GLOBAL_BLOCK and STATIC_BLOCK. */
3133 gdb::optional
<block_enum
> block_index
;
3134 /* The kind of symbol we're looking for. */
3136 /* The list of CUs from the index entry of the symbol,
3137 or NULL if not found. */
3139 /* The next element in VEC to look at. */
3141 /* The number of elements in VEC, or zero if there is no match. */
3143 /* Have we seen a global version of the symbol?
3144 If so we can ignore all further global instances.
3145 This is to work around gold/15646, inefficient gold-generated
3150 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3153 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3154 dwarf2_per_objfile
*per_objfile
,
3155 gdb::optional
<block_enum
> block_index
,
3156 domain_enum domain
, offset_type namei
)
3158 iter
->per_objfile
= per_objfile
;
3159 iter
->block_index
= block_index
;
3160 iter
->domain
= domain
;
3162 iter
->global_seen
= 0;
3166 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3167 /* index is NULL if OBJF_READNOW. */
3171 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3172 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3174 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3175 iter
->length
= iter
->vec
[0];
3178 /* Return the next matching CU or NULL if there are no more. */
3180 static struct dwarf2_per_cu_data
*
3181 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3183 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3185 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3187 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3188 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3189 gdb_index_symbol_kind symbol_kind
=
3190 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3191 /* Only check the symbol attributes if they're present.
3192 Indices prior to version 7 don't record them,
3193 and indices >= 7 may elide them for certain symbols
3194 (gold does this). */
3196 (per_objfile
->per_bfd
->index_table
->version
>= 7
3197 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3199 /* Don't crash on bad data. */
3200 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3202 complaint (_(".gdb_index entry has bad CU index"
3203 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3207 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3209 /* Skip if already read in. */
3210 if (per_objfile
->symtab_set_p (per_cu
))
3213 /* Check static vs global. */
3216 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3218 if (iter
->block_index
.has_value ())
3220 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3222 if (is_static
!= want_static
)
3226 /* Work around gold/15646. */
3228 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3230 if (iter
->global_seen
)
3233 iter
->global_seen
= 1;
3237 /* Only check the symbol's kind if it has one. */
3240 switch (iter
->domain
)
3243 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3244 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3245 /* Some types are also in VAR_DOMAIN. */
3246 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3250 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3254 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3258 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3274 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3280 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3281 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3284 for (int i
= 0; i
< total
; ++i
)
3286 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3288 if (!per_objfile
->symtab_set_p (per_cu
))
3291 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3292 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3295 /* This dumps minimal information about the index.
3296 It is called via "mt print objfiles".
3297 One use is to verify .gdb_index has been loaded by the
3298 gdb.dwarf2/gdb-index.exp testcase. */
3301 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3303 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3305 gdb_assert (per_objfile
->per_bfd
->using_index
);
3306 printf_filtered (".gdb_index:");
3307 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3309 printf_filtered (" version %d\n",
3310 per_objfile
->per_bfd
->index_table
->version
);
3313 printf_filtered (" faked for \"readnow\"\n");
3314 printf_filtered ("\n");
3318 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3320 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3321 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3323 for (int i
= 0; i
< total_units
; ++i
)
3325 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3327 /* We don't want to directly expand a partial CU, because if we
3328 read it with the wrong language, then assertion failures can
3329 be triggered later on. See PR symtab/23010. So, tell
3330 dw2_instantiate_symtab to skip partial CUs -- any important
3331 partial CU will be read via DW_TAG_imported_unit anyway. */
3332 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3337 dw2_expand_symtabs_matching_symbol
3338 (mapped_index_base
&index
,
3339 const lookup_name_info
&lookup_name_in
,
3340 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3341 gdb::function_view
<bool (offset_type
)> match_callback
,
3342 dwarf2_per_objfile
*per_objfile
);
3345 dw2_expand_symtabs_matching_one
3346 (dwarf2_per_cu_data
*per_cu
,
3347 dwarf2_per_objfile
*per_objfile
,
3348 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3349 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3352 dwarf2_gdb_index::expand_matching_symbols
3353 (struct objfile
*objfile
,
3354 const lookup_name_info
&name
, domain_enum domain
,
3356 symbol_compare_ftype
*ordered_compare
)
3359 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3361 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3363 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3365 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3367 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3368 auto matcher
= [&] (const char *symname
)
3370 if (ordered_compare
== nullptr)
3372 return ordered_compare (symname
, match_name
) == 0;
3375 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3376 [&] (offset_type namei
)
3378 struct dw2_symtab_iterator iter
;
3379 struct dwarf2_per_cu_data
*per_cu
;
3381 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3383 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3384 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3391 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3392 proceed assuming all symtabs have been read in. */
3396 /* Starting from a search name, return the string that finds the upper
3397 bound of all strings that start with SEARCH_NAME in a sorted name
3398 list. Returns the empty string to indicate that the upper bound is
3399 the end of the list. */
3402 make_sort_after_prefix_name (const char *search_name
)
3404 /* When looking to complete "func", we find the upper bound of all
3405 symbols that start with "func" by looking for where we'd insert
3406 the closest string that would follow "func" in lexicographical
3407 order. Usually, that's "func"-with-last-character-incremented,
3408 i.e. "fund". Mind non-ASCII characters, though. Usually those
3409 will be UTF-8 multi-byte sequences, but we can't be certain.
3410 Especially mind the 0xff character, which is a valid character in
3411 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3412 rule out compilers allowing it in identifiers. Note that
3413 conveniently, strcmp/strcasecmp are specified to compare
3414 characters interpreted as unsigned char. So what we do is treat
3415 the whole string as a base 256 number composed of a sequence of
3416 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3417 to 0, and carries 1 to the following more-significant position.
3418 If the very first character in SEARCH_NAME ends up incremented
3419 and carries/overflows, then the upper bound is the end of the
3420 list. The string after the empty string is also the empty
3423 Some examples of this operation:
3425 SEARCH_NAME => "+1" RESULT
3429 "\xff" "a" "\xff" => "\xff" "b"
3434 Then, with these symbols for example:
3440 completing "func" looks for symbols between "func" and
3441 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3442 which finds "func" and "func1", but not "fund".
3446 funcÿ (Latin1 'ÿ' [0xff])
3450 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3451 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3455 ÿÿ (Latin1 'ÿ' [0xff])
3458 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3459 the end of the list.
3461 std::string after
= search_name
;
3462 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3464 if (!after
.empty ())
3465 after
.back () = (unsigned char) after
.back () + 1;
3469 /* See declaration. */
3471 std::pair
<std::vector
<name_component
>::const_iterator
,
3472 std::vector
<name_component
>::const_iterator
>
3473 mapped_index_base::find_name_components_bounds
3474 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3475 dwarf2_per_objfile
*per_objfile
) const
3478 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3480 const char *lang_name
3481 = lookup_name_without_params
.language_lookup_name (lang
);
3483 /* Comparison function object for lower_bound that matches against a
3484 given symbol name. */
3485 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3488 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3489 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3490 return name_cmp (elem_name
, name
) < 0;
3493 /* Comparison function object for upper_bound that matches against a
3494 given symbol name. */
3495 auto lookup_compare_upper
= [&] (const char *name
,
3496 const name_component
&elem
)
3498 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3499 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3500 return name_cmp (name
, elem_name
) < 0;
3503 auto begin
= this->name_components
.begin ();
3504 auto end
= this->name_components
.end ();
3506 /* Find the lower bound. */
3509 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3512 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3515 /* Find the upper bound. */
3518 if (lookup_name_without_params
.completion_mode ())
3520 /* In completion mode, we want UPPER to point past all
3521 symbols names that have the same prefix. I.e., with
3522 these symbols, and completing "func":
3524 function << lower bound
3526 other_function << upper bound
3528 We find the upper bound by looking for the insertion
3529 point of "func"-with-last-character-incremented,
3531 std::string after
= make_sort_after_prefix_name (lang_name
);
3534 return std::lower_bound (lower
, end
, after
.c_str (),
3535 lookup_compare_lower
);
3538 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3541 return {lower
, upper
};
3544 /* See declaration. */
3547 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3549 if (!this->name_components
.empty ())
3552 this->name_components_casing
= case_sensitivity
;
3554 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3556 /* The code below only knows how to break apart components of C++
3557 symbol names (and other languages that use '::' as
3558 namespace/module separator) and Ada symbol names. */
3559 auto count
= this->symbol_name_count ();
3560 for (offset_type idx
= 0; idx
< count
; idx
++)
3562 if (this->symbol_name_slot_invalid (idx
))
3565 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3567 /* Add each name component to the name component table. */
3568 unsigned int previous_len
= 0;
3570 if (strstr (name
, "::") != nullptr)
3572 for (unsigned int current_len
= cp_find_first_component (name
);
3573 name
[current_len
] != '\0';
3574 current_len
+= cp_find_first_component (name
+ current_len
))
3576 gdb_assert (name
[current_len
] == ':');
3577 this->name_components
.push_back ({previous_len
, idx
});
3578 /* Skip the '::'. */
3580 previous_len
= current_len
;
3585 /* Handle the Ada encoded (aka mangled) form here. */
3586 for (const char *iter
= strstr (name
, "__");
3588 iter
= strstr (iter
, "__"))
3590 this->name_components
.push_back ({previous_len
, idx
});
3592 previous_len
= iter
- name
;
3596 this->name_components
.push_back ({previous_len
, idx
});
3599 /* Sort name_components elements by name. */
3600 auto name_comp_compare
= [&] (const name_component
&left
,
3601 const name_component
&right
)
3603 const char *left_qualified
3604 = this->symbol_name_at (left
.idx
, per_objfile
);
3605 const char *right_qualified
3606 = this->symbol_name_at (right
.idx
, per_objfile
);
3608 const char *left_name
= left_qualified
+ left
.name_offset
;
3609 const char *right_name
= right_qualified
+ right
.name_offset
;
3611 return name_cmp (left_name
, right_name
) < 0;
3614 std::sort (this->name_components
.begin (),
3615 this->name_components
.end (),
3619 /* Helper for dw2_expand_symtabs_matching that works with a
3620 mapped_index_base instead of the containing objfile. This is split
3621 to a separate function in order to be able to unit test the
3622 name_components matching using a mock mapped_index_base. For each
3623 symbol name that matches, calls MATCH_CALLBACK, passing it the
3624 symbol's index in the mapped_index_base symbol table. */
3627 dw2_expand_symtabs_matching_symbol
3628 (mapped_index_base
&index
,
3629 const lookup_name_info
&lookup_name_in
,
3630 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3631 gdb::function_view
<bool (offset_type
)> match_callback
,
3632 dwarf2_per_objfile
*per_objfile
)
3634 lookup_name_info lookup_name_without_params
3635 = lookup_name_in
.make_ignore_params ();
3637 /* Build the symbol name component sorted vector, if we haven't
3639 index
.build_name_components (per_objfile
);
3641 /* The same symbol may appear more than once in the range though.
3642 E.g., if we're looking for symbols that complete "w", and we have
3643 a symbol named "w1::w2", we'll find the two name components for
3644 that same symbol in the range. To be sure we only call the
3645 callback once per symbol, we first collect the symbol name
3646 indexes that matched in a temporary vector and ignore
3648 std::vector
<offset_type
> matches
;
3650 struct name_and_matcher
3652 symbol_name_matcher_ftype
*matcher
;
3655 bool operator== (const name_and_matcher
&other
) const
3657 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3661 /* A vector holding all the different symbol name matchers, for all
3663 std::vector
<name_and_matcher
> matchers
;
3665 for (int i
= 0; i
< nr_languages
; i
++)
3667 enum language lang_e
= (enum language
) i
;
3669 const language_defn
*lang
= language_def (lang_e
);
3670 symbol_name_matcher_ftype
*name_matcher
3671 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3673 name_and_matcher key
{
3675 lookup_name_without_params
.language_lookup_name (lang_e
)
3678 /* Don't insert the same comparison routine more than once.
3679 Note that we do this linear walk. This is not a problem in
3680 practice because the number of supported languages is
3682 if (std::find (matchers
.begin (), matchers
.end (), key
)
3685 matchers
.push_back (std::move (key
));
3688 = index
.find_name_components_bounds (lookup_name_without_params
,
3689 lang_e
, per_objfile
);
3691 /* Now for each symbol name in range, check to see if we have a name
3692 match, and if so, call the MATCH_CALLBACK callback. */
3694 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3696 const char *qualified
3697 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3699 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3700 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3703 matches
.push_back (bounds
.first
->idx
);
3707 std::sort (matches
.begin (), matches
.end ());
3709 /* Finally call the callback, once per match. */
3712 for (offset_type idx
: matches
)
3716 if (!match_callback (idx
))
3725 /* Above we use a type wider than idx's for 'prev', since 0 and
3726 (offset_type)-1 are both possible values. */
3727 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3734 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3736 /* A mock .gdb_index/.debug_names-like name index table, enough to
3737 exercise dw2_expand_symtabs_matching_symbol, which works with the
3738 mapped_index_base interface. Builds an index from the symbol list
3739 passed as parameter to the constructor. */
3740 class mock_mapped_index
: public mapped_index_base
3743 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3744 : m_symbol_table (symbols
)
3747 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3749 /* Return the number of names in the symbol table. */
3750 size_t symbol_name_count () const override
3752 return m_symbol_table
.size ();
3755 /* Get the name of the symbol at IDX in the symbol table. */
3756 const char *symbol_name_at
3757 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3759 return m_symbol_table
[idx
];
3763 gdb::array_view
<const char *> m_symbol_table
;
3766 /* Convenience function that converts a NULL pointer to a "<null>"
3767 string, to pass to print routines. */
3770 string_or_null (const char *str
)
3772 return str
!= NULL
? str
: "<null>";
3775 /* Check if a lookup_name_info built from
3776 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3777 index. EXPECTED_LIST is the list of expected matches, in expected
3778 matching order. If no match expected, then an empty list is
3779 specified. Returns true on success. On failure prints a warning
3780 indicating the file:line that failed, and returns false. */
3783 check_match (const char *file
, int line
,
3784 mock_mapped_index
&mock_index
,
3785 const char *name
, symbol_name_match_type match_type
,
3786 bool completion_mode
,
3787 std::initializer_list
<const char *> expected_list
,
3788 dwarf2_per_objfile
*per_objfile
)
3790 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3792 bool matched
= true;
3794 auto mismatch
= [&] (const char *expected_str
,
3797 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3798 "expected=\"%s\", got=\"%s\"\n"),
3800 (match_type
== symbol_name_match_type::FULL
3802 name
, string_or_null (expected_str
), string_or_null (got
));
3806 auto expected_it
= expected_list
.begin ();
3807 auto expected_end
= expected_list
.end ();
3809 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3811 [&] (offset_type idx
)
3813 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3814 const char *expected_str
3815 = expected_it
== expected_end
? NULL
: *expected_it
++;
3817 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3818 mismatch (expected_str
, matched_name
);
3822 const char *expected_str
3823 = expected_it
== expected_end
? NULL
: *expected_it
++;
3824 if (expected_str
!= NULL
)
3825 mismatch (expected_str
, NULL
);
3830 /* The symbols added to the mock mapped_index for testing (in
3832 static const char *test_symbols
[] = {
3841 "ns2::tmpl<int>::foo2",
3842 "(anonymous namespace)::A::B::C",
3844 /* These are used to check that the increment-last-char in the
3845 matching algorithm for completion doesn't match "t1_fund" when
3846 completing "t1_func". */
3852 /* A UTF-8 name with multi-byte sequences to make sure that
3853 cp-name-parser understands this as a single identifier ("função"
3854 is "function" in PT). */
3857 /* \377 (0xff) is Latin1 'ÿ'. */
3860 /* \377 (0xff) is Latin1 'ÿ'. */
3864 /* A name with all sorts of complications. Starts with "z" to make
3865 it easier for the completion tests below. */
3866 #define Z_SYM_NAME \
3867 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3868 "::tuple<(anonymous namespace)::ui*, " \
3869 "std::default_delete<(anonymous namespace)::ui>, void>"
3874 /* Returns true if the mapped_index_base::find_name_component_bounds
3875 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3876 in completion mode. */
3879 check_find_bounds_finds (mapped_index_base
&index
,
3880 const char *search_name
,
3881 gdb::array_view
<const char *> expected_syms
,
3882 dwarf2_per_objfile
*per_objfile
)
3884 lookup_name_info
lookup_name (search_name
,
3885 symbol_name_match_type::FULL
, true);
3887 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3891 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3892 if (distance
!= expected_syms
.size ())
3895 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3897 auto nc_elem
= bounds
.first
+ exp_elem
;
3898 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3899 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3906 /* Test the lower-level mapped_index::find_name_component_bounds
3910 test_mapped_index_find_name_component_bounds ()
3912 mock_mapped_index
mock_index (test_symbols
);
3914 mock_index
.build_name_components (NULL
/* per_objfile */);
3916 /* Test the lower-level mapped_index::find_name_component_bounds
3917 method in completion mode. */
3919 static const char *expected_syms
[] = {
3924 SELF_CHECK (check_find_bounds_finds
3925 (mock_index
, "t1_func", expected_syms
,
3926 NULL
/* per_objfile */));
3929 /* Check that the increment-last-char in the name matching algorithm
3930 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3932 static const char *expected_syms1
[] = {
3936 SELF_CHECK (check_find_bounds_finds
3937 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3939 static const char *expected_syms2
[] = {
3942 SELF_CHECK (check_find_bounds_finds
3943 (mock_index
, "\377\377", expected_syms2
,
3944 NULL
/* per_objfile */));
3948 /* Test dw2_expand_symtabs_matching_symbol. */
3951 test_dw2_expand_symtabs_matching_symbol ()
3953 mock_mapped_index
mock_index (test_symbols
);
3955 /* We let all tests run until the end even if some fails, for debug
3957 bool any_mismatch
= false;
3959 /* Create the expected symbols list (an initializer_list). Needed
3960 because lists have commas, and we need to pass them to CHECK,
3961 which is a macro. */
3962 #define EXPECT(...) { __VA_ARGS__ }
3964 /* Wrapper for check_match that passes down the current
3965 __FILE__/__LINE__. */
3966 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3967 any_mismatch |= !check_match (__FILE__, __LINE__, \
3969 NAME, MATCH_TYPE, COMPLETION_MODE, \
3970 EXPECTED_LIST, NULL)
3972 /* Identity checks. */
3973 for (const char *sym
: test_symbols
)
3975 /* Should be able to match all existing symbols. */
3976 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
3979 /* Should be able to match all existing symbols with
3981 std::string with_params
= std::string (sym
) + "(int)";
3982 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3985 /* Should be able to match all existing symbols with
3986 parameters and qualifiers. */
3987 with_params
= std::string (sym
) + " ( int ) const";
3988 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3991 /* This should really find sym, but cp-name-parser.y doesn't
3992 know about lvalue/rvalue qualifiers yet. */
3993 with_params
= std::string (sym
) + " ( int ) &&";
3994 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3998 /* Check that the name matching algorithm for completion doesn't get
3999 confused with Latin1 'ÿ' / 0xff. */
4001 static const char str
[] = "\377";
4002 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4003 EXPECT ("\377", "\377\377123"));
4006 /* Check that the increment-last-char in the matching algorithm for
4007 completion doesn't match "t1_fund" when completing "t1_func". */
4009 static const char str
[] = "t1_func";
4010 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4011 EXPECT ("t1_func", "t1_func1"));
4014 /* Check that completion mode works at each prefix of the expected
4017 static const char str
[] = "function(int)";
4018 size_t len
= strlen (str
);
4021 for (size_t i
= 1; i
< len
; i
++)
4023 lookup
.assign (str
, i
);
4024 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4025 EXPECT ("function"));
4029 /* While "w" is a prefix of both components, the match function
4030 should still only be called once. */
4032 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4034 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4038 /* Same, with a "complicated" symbol. */
4040 static const char str
[] = Z_SYM_NAME
;
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 (Z_SYM_NAME
));
4052 /* In FULL mode, an incomplete symbol doesn't match. */
4054 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4058 /* A complete symbol with parameters matches any overload, since the
4059 index has no overload info. */
4061 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4062 EXPECT ("std::zfunction", "std::zfunction2"));
4063 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4064 EXPECT ("std::zfunction", "std::zfunction2"));
4065 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4066 EXPECT ("std::zfunction", "std::zfunction2"));
4069 /* Check that whitespace is ignored appropriately. A symbol with a
4070 template argument list. */
4072 static const char expected
[] = "ns::foo<int>";
4073 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4075 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4079 /* Check that whitespace is ignored appropriately. A symbol with a
4080 template argument list that includes a pointer. */
4082 static const char expected
[] = "ns::foo<char*>";
4083 /* Try both completion and non-completion modes. */
4084 static const bool completion_mode
[2] = {false, true};
4085 for (size_t i
= 0; i
< 2; i
++)
4087 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4088 completion_mode
[i
], EXPECT (expected
));
4089 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4090 completion_mode
[i
], EXPECT (expected
));
4092 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4093 completion_mode
[i
], EXPECT (expected
));
4094 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4095 completion_mode
[i
], EXPECT (expected
));
4100 /* Check method qualifiers are ignored. */
4101 static const char expected
[] = "ns::foo<char*>";
4102 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4103 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4104 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4105 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4106 CHECK_MATCH ("foo < char * > ( int ) const",
4107 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4108 CHECK_MATCH ("foo < char * > ( int ) &&",
4109 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4112 /* Test lookup names that don't match anything. */
4114 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4117 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4121 /* Some wild matching tests, exercising "(anonymous namespace)",
4122 which should not be confused with a parameter list. */
4124 static const char *syms
[] = {
4128 "A :: B :: C ( int )",
4133 for (const char *s
: syms
)
4135 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4136 EXPECT ("(anonymous namespace)::A::B::C"));
4141 static const char expected
[] = "ns2::tmpl<int>::foo2";
4142 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4144 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4148 SELF_CHECK (!any_mismatch
);
4157 test_mapped_index_find_name_component_bounds ();
4158 test_dw2_expand_symtabs_matching_symbol ();
4161 }} // namespace selftests::dw2_expand_symtabs_matching
4163 #endif /* GDB_SELF_TEST */
4165 /* If FILE_MATCHER is NULL or if PER_CU has
4166 dwarf2_per_cu_quick_data::MARK set (see
4167 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4168 EXPANSION_NOTIFY on it. */
4171 dw2_expand_symtabs_matching_one
4172 (dwarf2_per_cu_data
*per_cu
,
4173 dwarf2_per_objfile
*per_objfile
,
4174 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4175 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4177 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4179 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4181 compunit_symtab
*symtab
4182 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4183 gdb_assert (symtab
!= nullptr);
4185 if (expansion_notify
!= NULL
&& symtab_was_null
)
4186 return expansion_notify (symtab
);
4191 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4192 matched, to expand corresponding CUs that were marked. IDX is the
4193 index of the symbol name that matched. */
4196 dw2_expand_marked_cus
4197 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4198 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4199 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4200 block_search_flags search_flags
,
4203 offset_type vec_len
, vec_idx
;
4204 bool global_seen
= false;
4205 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4207 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4209 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4211 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4212 /* This value is only valid for index versions >= 7. */
4213 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4214 gdb_index_symbol_kind symbol_kind
=
4215 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4216 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4217 /* Only check the symbol attributes if they're present.
4218 Indices prior to version 7 don't record them,
4219 and indices >= 7 may elide them for certain symbols
4220 (gold does this). */
4223 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4225 /* Work around gold/15646. */
4228 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4236 /* Only check the symbol's kind if it has one. */
4241 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4246 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4252 case VARIABLES_DOMAIN
:
4253 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4256 case FUNCTIONS_DOMAIN
:
4257 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4261 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4264 case MODULES_DOMAIN
:
4265 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4273 /* Don't crash on bad data. */
4274 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4276 complaint (_(".gdb_index entry has bad CU index"
4277 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4281 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4282 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4290 /* If FILE_MATCHER is non-NULL, set all the
4291 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4292 that match FILE_MATCHER. */
4295 dw_expand_symtabs_matching_file_matcher
4296 (dwarf2_per_objfile
*per_objfile
,
4297 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4299 if (file_matcher
== NULL
)
4302 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4304 NULL
, xcalloc
, xfree
));
4305 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4307 NULL
, xcalloc
, xfree
));
4309 /* The rule is CUs specify all the files, including those used by
4310 any TU, so there's no need to scan TUs here. */
4312 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4316 if (per_cu
->is_debug_types
)
4318 per_cu
->v
.quick
->mark
= 0;
4320 /* We only need to look at symtabs not already expanded. */
4321 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4324 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4326 if (file_data
== NULL
)
4329 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4331 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4333 per_cu
->v
.quick
->mark
= 1;
4337 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4339 const char *this_real_name
;
4341 if (file_matcher (file_data
->file_names
[j
], false))
4343 per_cu
->v
.quick
->mark
= 1;
4347 /* Before we invoke realpath, which can get expensive when many
4348 files are involved, do a quick comparison of the basenames. */
4349 if (!basenames_may_differ
4350 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4354 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4355 if (file_matcher (this_real_name
, false))
4357 per_cu
->v
.quick
->mark
= 1;
4362 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4363 ? visited_found
.get ()
4364 : visited_not_found
.get (),
4371 dwarf2_gdb_index::expand_symtabs_matching
4372 (struct objfile
*objfile
,
4373 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4374 const lookup_name_info
*lookup_name
,
4375 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4376 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4377 block_search_flags search_flags
,
4379 enum search_domain kind
)
4381 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4383 /* index_table is NULL if OBJF_READNOW. */
4384 if (!per_objfile
->per_bfd
->index_table
)
4387 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4389 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4391 for (dwarf2_per_cu_data
*per_cu
4392 : all_comp_units_range (per_objfile
->per_bfd
))
4396 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4404 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4407 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4409 [&] (offset_type idx
)
4411 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4412 expansion_notify
, search_flags
, kind
))
4420 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4423 static struct compunit_symtab
*
4424 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4429 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4430 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4433 if (cust
->includes
== NULL
)
4436 for (i
= 0; cust
->includes
[i
]; ++i
)
4438 struct compunit_symtab
*s
= cust
->includes
[i
];
4440 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4448 struct compunit_symtab
*
4449 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4450 (struct objfile
*objfile
,
4451 struct bound_minimal_symbol msymbol
,
4453 struct obj_section
*section
,
4456 struct dwarf2_per_cu_data
*data
;
4457 struct compunit_symtab
*result
;
4459 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4460 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4463 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4464 data
= ((struct dwarf2_per_cu_data
*)
4465 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4470 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4471 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4472 paddress (objfile
->arch (), pc
));
4474 result
= recursively_find_pc_sect_compunit_symtab
4475 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4477 gdb_assert (result
!= NULL
);
4482 dwarf2_base_index_functions::map_symbol_filenames
4483 (struct objfile
*objfile
,
4484 gdb::function_view
<symbol_filename_ftype
> fun
,
4487 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4489 /* Use caches to ensure we only call FUN once for each filename. */
4490 filename_seen_cache filenames_cache
;
4491 std::unordered_set
<quick_file_names
*> qfn_cache
;
4493 /* The rule is CUs specify all the files, including those used by any TU,
4494 so there's no need to scan TUs here. We can ignore file names coming
4495 from already-expanded CUs. It is possible that an expanded CU might
4496 reuse the file names data from a currently unexpanded CU, in this
4497 case we don't want to report the files from the unexpanded CU. */
4499 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4501 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4503 if (per_cu
->v
.quick
->file_names
!= nullptr)
4504 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4508 for (dwarf2_per_cu_data
*per_cu
4509 : all_comp_units_range (per_objfile
->per_bfd
))
4511 /* We only need to look at symtabs not already expanded. */
4512 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
4515 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4516 if (file_data
== nullptr
4517 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4520 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4522 const char *filename
= file_data
->file_names
[j
];
4523 filenames_cache
.seen (filename
);
4527 filenames_cache
.traverse ([&] (const char *filename
)
4529 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4532 this_real_name
= gdb_realpath (filename
);
4533 fun (filename
, this_real_name
.get ());
4538 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4543 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4546 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4548 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4550 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4552 /* Is this already expanded? */
4553 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4556 /* It has not yet been expanded. */
4563 /* DWARF-5 debug_names reader. */
4565 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4566 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4568 /* A helper function that reads the .debug_names section in SECTION
4569 and fills in MAP. FILENAME is the name of the file containing the
4570 section; it is used for error reporting.
4572 Returns true if all went well, false otherwise. */
4575 read_debug_names_from_section (struct objfile
*objfile
,
4576 const char *filename
,
4577 struct dwarf2_section_info
*section
,
4578 mapped_debug_names
&map
)
4580 if (section
->empty ())
4583 /* Older elfutils strip versions could keep the section in the main
4584 executable while splitting it for the separate debug info file. */
4585 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4588 section
->read (objfile
);
4590 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4592 const gdb_byte
*addr
= section
->buffer
;
4594 bfd
*const abfd
= section
->get_bfd_owner ();
4596 unsigned int bytes_read
;
4597 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4600 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4601 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4602 if (bytes_read
+ length
!= section
->size
)
4604 /* There may be multiple per-CU indices. */
4605 warning (_("Section .debug_names in %s length %s does not match "
4606 "section length %s, ignoring .debug_names."),
4607 filename
, plongest (bytes_read
+ length
),
4608 pulongest (section
->size
));
4612 /* The version number. */
4613 uint16_t version
= read_2_bytes (abfd
, addr
);
4617 warning (_("Section .debug_names in %s has unsupported version %d, "
4618 "ignoring .debug_names."),
4624 uint16_t padding
= read_2_bytes (abfd
, addr
);
4628 warning (_("Section .debug_names in %s has unsupported padding %d, "
4629 "ignoring .debug_names."),
4634 /* comp_unit_count - The number of CUs in the CU list. */
4635 map
.cu_count
= read_4_bytes (abfd
, addr
);
4638 /* local_type_unit_count - The number of TUs in the local TU
4640 map
.tu_count
= read_4_bytes (abfd
, addr
);
4643 /* foreign_type_unit_count - The number of TUs in the foreign TU
4645 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4647 if (foreign_tu_count
!= 0)
4649 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4650 "ignoring .debug_names."),
4651 filename
, static_cast<unsigned long> (foreign_tu_count
));
4655 /* bucket_count - The number of hash buckets in the hash lookup
4657 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4660 /* name_count - The number of unique names in the index. */
4661 map
.name_count
= read_4_bytes (abfd
, addr
);
4664 /* abbrev_table_size - The size in bytes of the abbreviations
4666 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4669 /* augmentation_string_size - The size in bytes of the augmentation
4670 string. This value is rounded up to a multiple of 4. */
4671 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4673 map
.augmentation_is_gdb
= ((augmentation_string_size
4674 == sizeof (dwarf5_augmentation
))
4675 && memcmp (addr
, dwarf5_augmentation
,
4676 sizeof (dwarf5_augmentation
)) == 0);
4677 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4678 addr
+= augmentation_string_size
;
4681 map
.cu_table_reordered
= addr
;
4682 addr
+= map
.cu_count
* map
.offset_size
;
4684 /* List of Local TUs */
4685 map
.tu_table_reordered
= addr
;
4686 addr
+= map
.tu_count
* map
.offset_size
;
4688 /* Hash Lookup Table */
4689 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4690 addr
+= map
.bucket_count
* 4;
4691 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4692 addr
+= map
.name_count
* 4;
4695 map
.name_table_string_offs_reordered
= addr
;
4696 addr
+= map
.name_count
* map
.offset_size
;
4697 map
.name_table_entry_offs_reordered
= addr
;
4698 addr
+= map
.name_count
* map
.offset_size
;
4700 const gdb_byte
*abbrev_table_start
= addr
;
4703 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4708 const auto insertpair
4709 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4710 if (!insertpair
.second
)
4712 warning (_("Section .debug_names in %s has duplicate index %s, "
4713 "ignoring .debug_names."),
4714 filename
, pulongest (index_num
));
4717 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4718 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4723 mapped_debug_names::index_val::attr attr
;
4724 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4726 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4728 if (attr
.form
== DW_FORM_implicit_const
)
4730 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4734 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4736 indexval
.attr_vec
.push_back (std::move (attr
));
4739 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4741 warning (_("Section .debug_names in %s has abbreviation_table "
4742 "of size %s vs. written as %u, ignoring .debug_names."),
4743 filename
, plongest (addr
- abbrev_table_start
),
4747 map
.entry_pool
= addr
;
4752 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4756 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4757 const mapped_debug_names
&map
,
4758 dwarf2_section_info
§ion
,
4761 if (!map
.augmentation_is_gdb
)
4763 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4765 sect_offset sect_off
4766 = (sect_offset
) (extract_unsigned_integer
4767 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4769 map
.dwarf5_byte_order
));
4770 /* We don't know the length of the CU, because the CU list in a
4771 .debug_names index can be incomplete, so we can't use the start
4772 of the next CU as end of this CU. We create the CUs here with
4773 length 0, and in cutu_reader::cutu_reader we'll fill in the
4775 dwarf2_per_cu_data_up per_cu
4776 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4778 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4783 sect_offset sect_off_prev
;
4784 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4786 sect_offset sect_off_next
;
4787 if (i
< map
.cu_count
)
4790 = (sect_offset
) (extract_unsigned_integer
4791 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4793 map
.dwarf5_byte_order
));
4796 sect_off_next
= (sect_offset
) section
.size
;
4799 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4800 dwarf2_per_cu_data_up per_cu
4801 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4802 sect_off_prev
, length
);
4803 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4805 sect_off_prev
= sect_off_next
;
4809 /* Read the CU list from the mapped index, and use it to create all
4810 the CU objects for this dwarf2_per_objfile. */
4813 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4814 const mapped_debug_names
&map
,
4815 const mapped_debug_names
&dwz_map
)
4817 gdb_assert (per_bfd
->all_comp_units
.empty ());
4818 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4820 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4821 false /* is_dwz */);
4823 if (dwz_map
.cu_count
== 0)
4826 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4827 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4831 /* Read .debug_names. If everything went ok, initialize the "quick"
4832 elements of all the CUs and return true. Otherwise, return false. */
4835 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4837 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4838 mapped_debug_names dwz_map
;
4839 struct objfile
*objfile
= per_objfile
->objfile
;
4840 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4842 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4843 &per_bfd
->debug_names
, *map
))
4846 /* Don't use the index if it's empty. */
4847 if (map
->name_count
== 0)
4850 /* If there is a .dwz file, read it so we can get its CU list as
4852 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4855 if (!read_debug_names_from_section (objfile
,
4856 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4857 &dwz
->debug_names
, dwz_map
))
4859 warning (_("could not read '.debug_names' section from %s; skipping"),
4860 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4865 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4867 if (map
->tu_count
!= 0)
4869 /* We can only handle a single .debug_types when we have an
4871 if (per_bfd
->types
.size () != 1)
4874 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4876 create_signatured_type_table_from_debug_names
4877 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4880 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4882 per_bfd
->debug_names_table
= std::move (map
);
4883 per_bfd
->using_index
= 1;
4884 per_bfd
->quick_file_names_table
=
4885 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4890 /* Type used to manage iterating over all CUs looking for a symbol for
4893 class dw2_debug_names_iterator
4896 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4897 block_search_flags block_index
,
4899 const char *name
, dwarf2_per_objfile
*per_objfile
)
4900 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4901 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4902 m_per_objfile (per_objfile
)
4905 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4906 search_domain search
, uint32_t namei
,
4907 dwarf2_per_objfile
*per_objfile
,
4908 domain_enum domain
= UNDEF_DOMAIN
)
4912 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4913 m_per_objfile (per_objfile
)
4916 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4917 block_search_flags block_index
, domain_enum domain
,
4918 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4919 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4920 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4921 m_per_objfile (per_objfile
)
4924 /* Return the next matching CU or NULL if there are no more. */
4925 dwarf2_per_cu_data
*next ();
4928 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4930 dwarf2_per_objfile
*per_objfile
);
4931 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4933 dwarf2_per_objfile
*per_objfile
);
4935 /* The internalized form of .debug_names. */
4936 const mapped_debug_names
&m_map
;
4938 /* Restrict the search to these blocks. */
4939 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4940 | SEARCH_STATIC_BLOCK
);
4942 /* The kind of symbol we're looking for. */
4943 const domain_enum m_domain
= UNDEF_DOMAIN
;
4944 const search_domain m_search
= ALL_DOMAIN
;
4946 /* The list of CUs from the index entry of the symbol, or NULL if
4948 const gdb_byte
*m_addr
;
4950 dwarf2_per_objfile
*m_per_objfile
;
4954 mapped_debug_names::namei_to_name
4955 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4957 const ULONGEST namei_string_offs
4958 = extract_unsigned_integer ((name_table_string_offs_reordered
4959 + namei
* offset_size
),
4962 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4965 /* Find a slot in .debug_names for the object named NAME. If NAME is
4966 found, return pointer to its pool data. If NAME cannot be found,
4970 dw2_debug_names_iterator::find_vec_in_debug_names
4971 (const mapped_debug_names
&map
, const char *name
,
4972 dwarf2_per_objfile
*per_objfile
)
4974 int (*cmp
) (const char *, const char *);
4976 gdb::unique_xmalloc_ptr
<char> without_params
;
4977 if (current_language
->la_language
== language_cplus
4978 || current_language
->la_language
== language_fortran
4979 || current_language
->la_language
== language_d
)
4981 /* NAME is already canonical. Drop any qualifiers as
4982 .debug_names does not contain any. */
4984 if (strchr (name
, '(') != NULL
)
4986 without_params
= cp_remove_params (name
);
4987 if (without_params
!= NULL
)
4988 name
= without_params
.get ();
4992 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
4994 const uint32_t full_hash
= dwarf5_djb_hash (name
);
4996 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4997 (map
.bucket_table_reordered
4998 + (full_hash
% map
.bucket_count
)), 4,
4999 map
.dwarf5_byte_order
);
5003 if (namei
>= map
.name_count
)
5005 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5007 namei
, map
.name_count
,
5008 objfile_name (per_objfile
->objfile
));
5014 const uint32_t namei_full_hash
5015 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5016 (map
.hash_table_reordered
+ namei
), 4,
5017 map
.dwarf5_byte_order
);
5018 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5021 if (full_hash
== namei_full_hash
)
5023 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5025 #if 0 /* An expensive sanity check. */
5026 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5028 complaint (_("Wrong .debug_names hash for string at index %u "
5030 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5035 if (cmp (namei_string
, name
) == 0)
5037 const ULONGEST namei_entry_offs
5038 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5039 + namei
* map
.offset_size
),
5040 map
.offset_size
, map
.dwarf5_byte_order
);
5041 return map
.entry_pool
+ namei_entry_offs
;
5046 if (namei
>= map
.name_count
)
5052 dw2_debug_names_iterator::find_vec_in_debug_names
5053 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5055 if (namei
>= map
.name_count
)
5057 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5059 namei
, map
.name_count
,
5060 objfile_name (per_objfile
->objfile
));
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
;
5071 /* See dw2_debug_names_iterator. */
5073 dwarf2_per_cu_data
*
5074 dw2_debug_names_iterator::next ()
5079 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5080 struct objfile
*objfile
= m_per_objfile
->objfile
;
5081 bfd
*const abfd
= objfile
->obfd
;
5085 unsigned int bytes_read
;
5086 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5087 m_addr
+= bytes_read
;
5091 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5092 if (indexval_it
== m_map
.abbrev_map
.cend ())
5094 complaint (_("Wrong .debug_names undefined abbrev code %s "
5096 pulongest (abbrev
), objfile_name (objfile
));
5099 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5100 enum class symbol_linkage
{
5104 } symbol_linkage_
= symbol_linkage::unknown
;
5105 dwarf2_per_cu_data
*per_cu
= NULL
;
5106 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5111 case DW_FORM_implicit_const
:
5112 ull
= attr
.implicit_const
;
5114 case DW_FORM_flag_present
:
5118 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5119 m_addr
+= bytes_read
;
5122 ull
= read_4_bytes (abfd
, m_addr
);
5126 ull
= read_8_bytes (abfd
, m_addr
);
5129 case DW_FORM_ref_sig8
:
5130 ull
= read_8_bytes (abfd
, m_addr
);
5134 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5135 dwarf_form_name (attr
.form
),
5136 objfile_name (objfile
));
5139 switch (attr
.dw_idx
)
5141 case DW_IDX_compile_unit
:
5142 /* Don't crash on bad data. */
5143 if (ull
>= per_bfd
->all_comp_units
.size ())
5145 complaint (_(".debug_names entry has bad CU index %s"
5148 objfile_name (objfile
));
5151 per_cu
= per_bfd
->get_cu (ull
);
5153 case DW_IDX_type_unit
:
5154 /* Don't crash on bad data. */
5155 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5157 complaint (_(".debug_names entry has bad TU index %s"
5160 objfile_name (objfile
));
5163 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5165 case DW_IDX_die_offset
:
5166 /* In a per-CU index (as opposed to a per-module index), index
5167 entries without CU attribute implicitly refer to the single CU. */
5169 per_cu
= per_bfd
->get_cu (0);
5171 case DW_IDX_GNU_internal
:
5172 if (!m_map
.augmentation_is_gdb
)
5174 symbol_linkage_
= symbol_linkage::static_
;
5176 case DW_IDX_GNU_external
:
5177 if (!m_map
.augmentation_is_gdb
)
5179 symbol_linkage_
= symbol_linkage::extern_
;
5184 /* Skip if already read in. */
5185 if (m_per_objfile
->symtab_set_p (per_cu
))
5188 /* Check static vs global. */
5189 if (symbol_linkage_
!= symbol_linkage::unknown
)
5191 if (symbol_linkage_
== symbol_linkage::static_
)
5193 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5198 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5203 /* Match dw2_symtab_iter_next, symbol_kind
5204 and debug_names::psymbol_tag. */
5208 switch (indexval
.dwarf_tag
)
5210 case DW_TAG_variable
:
5211 case DW_TAG_subprogram
:
5212 /* Some types are also in VAR_DOMAIN. */
5213 case DW_TAG_typedef
:
5214 case DW_TAG_structure_type
:
5221 switch (indexval
.dwarf_tag
)
5223 case DW_TAG_typedef
:
5224 case DW_TAG_structure_type
:
5231 switch (indexval
.dwarf_tag
)
5234 case DW_TAG_variable
:
5241 switch (indexval
.dwarf_tag
)
5253 /* Match dw2_expand_symtabs_matching, symbol_kind and
5254 debug_names::psymbol_tag. */
5257 case VARIABLES_DOMAIN
:
5258 switch (indexval
.dwarf_tag
)
5260 case DW_TAG_variable
:
5266 case FUNCTIONS_DOMAIN
:
5267 switch (indexval
.dwarf_tag
)
5269 case DW_TAG_subprogram
:
5276 switch (indexval
.dwarf_tag
)
5278 case DW_TAG_typedef
:
5279 case DW_TAG_structure_type
:
5285 case MODULES_DOMAIN
:
5286 switch (indexval
.dwarf_tag
)
5300 /* This dumps minimal information about .debug_names. It is called
5301 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5302 uses this to verify that .debug_names has been loaded. */
5305 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5307 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5309 gdb_assert (per_objfile
->per_bfd
->using_index
);
5310 printf_filtered (".debug_names:");
5311 if (per_objfile
->per_bfd
->debug_names_table
)
5312 printf_filtered (" exists\n");
5314 printf_filtered (" faked for \"readnow\"\n");
5315 printf_filtered ("\n");
5319 dwarf2_debug_names_index::expand_matching_symbols
5320 (struct objfile
*objfile
,
5321 const lookup_name_info
&name
, domain_enum domain
,
5323 symbol_compare_ftype
*ordered_compare
)
5325 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5327 /* debug_names_table is NULL if OBJF_READNOW. */
5328 if (!per_objfile
->per_bfd
->debug_names_table
)
5331 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5332 const block_search_flags block_flags
5333 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5335 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5336 auto matcher
= [&] (const char *symname
)
5338 if (ordered_compare
== nullptr)
5340 return ordered_compare (symname
, match_name
) == 0;
5343 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5344 [&] (offset_type namei
)
5346 /* The name was matched, now expand corresponding CUs that were
5348 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5351 struct dwarf2_per_cu_data
*per_cu
;
5352 while ((per_cu
= iter
.next ()) != NULL
)
5353 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5360 dwarf2_debug_names_index::expand_symtabs_matching
5361 (struct objfile
*objfile
,
5362 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5363 const lookup_name_info
*lookup_name
,
5364 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5365 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5366 block_search_flags search_flags
,
5368 enum search_domain kind
)
5370 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5372 /* debug_names_table is NULL if OBJF_READNOW. */
5373 if (!per_objfile
->per_bfd
->debug_names_table
)
5376 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5378 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5380 for (dwarf2_per_cu_data
*per_cu
5381 : all_comp_units_range (per_objfile
->per_bfd
))
5385 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5393 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5396 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5398 [&] (offset_type namei
)
5400 /* The name was matched, now expand corresponding CUs that were
5402 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5404 struct dwarf2_per_cu_data
*per_cu
;
5405 while ((per_cu
= iter
.next ()) != NULL
)
5406 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5416 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5417 to either a dwarf2_per_bfd or dwz_file object. */
5419 template <typename T
>
5420 static gdb::array_view
<const gdb_byte
>
5421 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5423 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5425 if (section
->empty ())
5428 /* Older elfutils strip versions could keep the section in the main
5429 executable while splitting it for the separate debug info file. */
5430 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5433 section
->read (obj
);
5435 /* dwarf2_section_info::size is a bfd_size_type, while
5436 gdb::array_view works with size_t. On 32-bit hosts, with
5437 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5438 is 32-bit. So we need an explicit narrowing conversion here.
5439 This is fine, because it's impossible to allocate or mmap an
5440 array/buffer larger than what size_t can represent. */
5441 return gdb::make_array_view (section
->buffer
, section
->size
);
5444 /* Lookup the index cache for the contents of the index associated to
5447 static gdb::array_view
<const gdb_byte
>
5448 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5450 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5451 if (build_id
== nullptr)
5454 return global_index_cache
.lookup_gdb_index (build_id
,
5455 &dwarf2_per_bfd
->index_cache_res
);
5458 /* Same as the above, but for DWZ. */
5460 static gdb::array_view
<const gdb_byte
>
5461 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5463 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5464 if (build_id
== nullptr)
5467 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5470 /* See dwarf2/public.h. */
5473 dwarf2_initialize_objfile (struct objfile
*objfile
)
5475 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5476 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5478 dwarf_read_debug_printf ("called");
5480 /* If we're about to read full symbols, don't bother with the
5481 indices. In this case we also don't care if some other debug
5482 format is making psymtabs, because they are all about to be
5484 if ((objfile
->flags
& OBJF_READNOW
))
5486 dwarf_read_debug_printf ("readnow requested");
5488 /* When using READNOW, the using_index flag (set below) indicates that
5489 PER_BFD was already initialized, when we loaded some other objfile. */
5490 if (per_bfd
->using_index
)
5492 dwarf_read_debug_printf ("using_index already set");
5493 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5497 per_bfd
->using_index
= 1;
5498 create_all_comp_units (per_objfile
);
5499 per_bfd
->quick_file_names_table
5500 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5502 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5504 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5506 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5507 struct dwarf2_per_cu_quick_data
);
5510 /* Arrange for gdb to see the "quick" functions. However, these
5511 functions will be no-ops because we will have expanded all
5513 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5517 /* Was a debug names index already read when we processed an objfile sharing
5519 if (per_bfd
->debug_names_table
!= nullptr)
5521 dwarf_read_debug_printf ("re-using shared debug names table");
5522 objfile
->qf
.push_front (make_dwarf_debug_names ());
5526 /* Was a GDB index already read when we processed an objfile sharing
5528 if (per_bfd
->index_table
!= nullptr)
5530 dwarf_read_debug_printf ("re-using shared index table");
5531 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5535 /* There might already be partial symtabs built for this BFD. This happens
5536 when loading the same binary twice with the index-cache enabled. If so,
5537 don't try to read an index. The objfile / per_objfile initialization will
5538 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5540 if (per_bfd
->partial_symtabs
!= nullptr)
5542 dwarf_read_debug_printf ("re-using shared partial symtabs");
5543 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5547 if (dwarf2_read_debug_names (per_objfile
))
5549 dwarf_read_debug_printf ("found debug names");
5550 objfile
->qf
.push_front (make_dwarf_debug_names ());
5554 if (dwarf2_read_gdb_index (per_objfile
,
5555 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5556 get_gdb_index_contents_from_section
<dwz_file
>))
5558 dwarf_read_debug_printf ("found gdb index from file");
5559 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5563 /* ... otherwise, try to find the index in the index cache. */
5564 if (dwarf2_read_gdb_index (per_objfile
,
5565 get_gdb_index_contents_from_cache
,
5566 get_gdb_index_contents_from_cache_dwz
))
5568 dwarf_read_debug_printf ("found gdb index from cache");
5569 global_index_cache
.hit ();
5570 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5574 global_index_cache
.miss ();
5575 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5580 /* Build a partial symbol table. */
5583 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5585 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5586 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5588 if (per_bfd
->partial_symtabs
!= nullptr)
5590 /* Partial symbols were already read, so now we can simply
5594 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5595 objfile
->qf
.emplace_front (psf
);
5598 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5604 psf
= new psymbol_functions
;
5605 objfile
->qf
.emplace_front (psf
);
5607 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5608 = psf
->get_partial_symtabs ();
5610 /* Set the local reference to partial symtabs, so that we don't try
5611 to read them again if reading another objfile with the same BFD.
5612 If we can't in fact share, this won't make a difference anyway as
5613 the dwarf2_per_bfd object won't be shared. */
5614 per_bfd
->partial_symtabs
= partial_symtabs
;
5618 /* This isn't really ideal: all the data we allocate on the
5619 objfile's obstack is still uselessly kept around. However,
5620 freeing it seems unsafe. */
5621 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5622 dwarf2_build_psymtabs_hard (per_objfile
);
5625 /* (maybe) store an index in the cache. */
5626 global_index_cache
.store (per_objfile
);
5628 catch (const gdb_exception_error
&except
)
5630 exception_print (gdb_stderr
, except
);
5634 /* Find the base address of the compilation unit for range lists and
5635 location lists. It will normally be specified by DW_AT_low_pc.
5636 In DWARF-3 draft 4, the base address could be overridden by
5637 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5638 compilation units with discontinuous ranges. */
5641 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5643 struct attribute
*attr
;
5645 cu
->base_address
.reset ();
5647 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5648 if (attr
!= nullptr)
5649 cu
->base_address
= attr
->as_address ();
5652 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5653 if (attr
!= nullptr)
5654 cu
->base_address
= attr
->as_address ();
5658 /* Helper function that returns the proper abbrev section for
5661 static struct dwarf2_section_info
*
5662 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5664 struct dwarf2_section_info
*abbrev
;
5665 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5667 if (this_cu
->is_dwz
)
5668 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5670 abbrev
= &per_bfd
->abbrev
;
5675 /* Fetch the abbreviation table offset from a comp or type unit header. */
5678 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5679 struct dwarf2_section_info
*section
,
5680 sect_offset sect_off
)
5682 bfd
*abfd
= section
->get_bfd_owner ();
5683 const gdb_byte
*info_ptr
;
5684 unsigned int initial_length_size
, offset_size
;
5687 section
->read (per_objfile
->objfile
);
5688 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5689 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5690 offset_size
= initial_length_size
== 4 ? 4 : 8;
5691 info_ptr
+= initial_length_size
;
5693 version
= read_2_bytes (abfd
, info_ptr
);
5697 /* Skip unit type and address size. */
5701 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5704 /* A partial symtab that is used only for include files. */
5705 struct dwarf2_include_psymtab
: public partial_symtab
5707 dwarf2_include_psymtab (const char *filename
,
5708 psymtab_storage
*partial_symtabs
,
5709 objfile_per_bfd_storage
*objfile_per_bfd
)
5710 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5714 void read_symtab (struct objfile
*objfile
) override
5716 /* It's an include file, no symbols to read for it.
5717 Everything is in the includer symtab. */
5719 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5720 expansion of the includer psymtab. We use the dependencies[0] field to
5721 model the includer. But if we go the regular route of calling
5722 expand_psymtab here, and having expand_psymtab call expand_dependencies
5723 to expand the includer, we'll only use expand_psymtab on the includer
5724 (making it a non-toplevel psymtab), while if we expand the includer via
5725 another path, we'll use read_symtab (making it a toplevel psymtab).
5726 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5727 psymtab, and trigger read_symtab on the includer here directly. */
5728 includer ()->read_symtab (objfile
);
5731 void expand_psymtab (struct objfile
*objfile
) override
5733 /* This is not called by read_symtab, and should not be called by any
5734 expand_dependencies. */
5738 bool readin_p (struct objfile
*objfile
) const override
5740 return includer ()->readin_p (objfile
);
5743 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5749 partial_symtab
*includer () const
5751 /* An include psymtab has exactly one dependency: the psymtab that
5753 gdb_assert (this->number_of_dependencies
== 1);
5754 return this->dependencies
[0];
5758 /* Allocate a new partial symtab for file named NAME and mark this new
5759 partial symtab as being an include of PST. */
5762 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5764 dwarf2_psymtab
*pst
,
5765 psymtab_storage
*partial_symtabs
,
5766 objfile_per_bfd_storage
*objfile_per_bfd
)
5768 dwarf2_include_psymtab
*subpst
5769 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5771 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5772 subpst
->dirname
= pst
->dirname
;
5774 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5775 subpst
->dependencies
[0] = pst
;
5776 subpst
->number_of_dependencies
= 1;
5779 /* Read the Line Number Program data and extract the list of files
5780 included by the source file represented by PST. Build an include
5781 partial symtab for each of these included files. */
5784 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5785 struct die_info
*die
,
5786 dwarf2_psymtab
*pst
)
5789 struct attribute
*attr
;
5791 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5792 if (attr
!= nullptr && attr
->form_is_unsigned ())
5793 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5795 return; /* No linetable, so no includes. */
5797 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5798 that we pass in the raw text_low here; that is ok because we're
5799 only decoding the line table to make include partial symtabs, and
5800 so the addresses aren't really used. */
5801 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5802 pst
->raw_text_low (), 1);
5806 hash_signatured_type (const void *item
)
5808 const struct signatured_type
*sig_type
5809 = (const struct signatured_type
*) item
;
5811 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5812 return sig_type
->signature
;
5816 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5818 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5819 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5821 return lhs
->signature
== rhs
->signature
;
5824 /* Allocate a hash table for signatured types. */
5827 allocate_signatured_type_table ()
5829 return htab_up (htab_create_alloc (41,
5830 hash_signatured_type
,
5832 NULL
, xcalloc
, xfree
));
5835 /* A helper for create_debug_types_hash_table. Read types from SECTION
5836 and fill them into TYPES_HTAB. It will process only type units,
5837 therefore DW_UT_type. */
5840 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5841 struct dwo_file
*dwo_file
,
5842 dwarf2_section_info
*section
, htab_up
&types_htab
,
5843 rcuh_kind section_kind
)
5845 struct objfile
*objfile
= per_objfile
->objfile
;
5846 struct dwarf2_section_info
*abbrev_section
;
5848 const gdb_byte
*info_ptr
, *end_ptr
;
5850 abbrev_section
= &dwo_file
->sections
.abbrev
;
5852 dwarf_read_debug_printf ("Reading %s for %s",
5853 section
->get_name (),
5854 abbrev_section
->get_file_name ());
5856 section
->read (objfile
);
5857 info_ptr
= section
->buffer
;
5859 if (info_ptr
== NULL
)
5862 /* We can't set abfd until now because the section may be empty or
5863 not present, in which case the bfd is unknown. */
5864 abfd
= section
->get_bfd_owner ();
5866 /* We don't use cutu_reader here because we don't need to read
5867 any dies: the signature is in the header. */
5869 end_ptr
= info_ptr
+ section
->size
;
5870 while (info_ptr
< end_ptr
)
5872 signatured_type_up sig_type
;
5873 struct dwo_unit
*dwo_tu
;
5875 const gdb_byte
*ptr
= info_ptr
;
5876 struct comp_unit_head header
;
5877 unsigned int length
;
5879 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5881 /* Initialize it due to a false compiler warning. */
5882 header
.signature
= -1;
5883 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5885 /* We need to read the type's signature in order to build the hash
5886 table, but we don't need anything else just yet. */
5888 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5889 abbrev_section
, ptr
, section_kind
);
5891 length
= header
.get_length ();
5893 /* Skip dummy type units. */
5894 if (ptr
>= info_ptr
+ length
5895 || peek_abbrev_code (abfd
, ptr
) == 0
5896 || (header
.unit_type
!= DW_UT_type
5897 && header
.unit_type
!= DW_UT_split_type
))
5903 if (types_htab
== NULL
)
5904 types_htab
= allocate_dwo_unit_table ();
5906 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5907 dwo_tu
->dwo_file
= dwo_file
;
5908 dwo_tu
->signature
= header
.signature
;
5909 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5910 dwo_tu
->section
= section
;
5911 dwo_tu
->sect_off
= sect_off
;
5912 dwo_tu
->length
= length
;
5914 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5915 gdb_assert (slot
!= NULL
);
5917 complaint (_("debug type entry at offset %s is duplicate to"
5918 " the entry at offset %s, signature %s"),
5919 sect_offset_str (sect_off
),
5920 sect_offset_str (dwo_tu
->sect_off
),
5921 hex_string (header
.signature
));
5924 dwarf_read_debug_printf_v (" offset %s, signature %s",
5925 sect_offset_str (sect_off
),
5926 hex_string (header
.signature
));
5932 /* Create the hash table of all entries in the .debug_types
5933 (or .debug_types.dwo) section(s).
5934 DWO_FILE is a pointer to the DWO file object.
5936 The result is a pointer to the hash table or NULL if there are no types.
5938 Note: This function processes DWO files only, not DWP files. */
5941 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5942 struct dwo_file
*dwo_file
,
5943 gdb::array_view
<dwarf2_section_info
> type_sections
,
5944 htab_up
&types_htab
)
5946 for (dwarf2_section_info
§ion
: type_sections
)
5947 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5951 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5952 If SLOT is non-NULL, it is the entry to use in the hash table.
5953 Otherwise we find one. */
5955 static struct signatured_type
*
5956 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5958 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5959 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5960 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5962 signatured_type_up sig_type_holder
5963 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
5964 signatured_type
*sig_type
= sig_type_holder
.get ();
5966 per_objfile
->per_bfd
->all_comp_units
.emplace_back
5967 (sig_type_holder
.release ());
5968 if (per_objfile
->per_bfd
->using_index
)
5971 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
5972 struct dwarf2_per_cu_quick_data
);
5977 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5980 gdb_assert (*slot
== NULL
);
5982 /* The rest of sig_type must be filled in by the caller. */
5986 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5987 Fill in SIG_ENTRY with DWO_ENTRY. */
5990 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
5991 struct signatured_type
*sig_entry
,
5992 struct dwo_unit
*dwo_entry
)
5994 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5996 /* Make sure we're not clobbering something we don't expect to. */
5997 gdb_assert (! sig_entry
->queued
);
5998 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
5999 if (per_bfd
->using_index
)
6001 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6002 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6005 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6006 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6007 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6008 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6009 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6011 sig_entry
->section
= dwo_entry
->section
;
6012 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6013 sig_entry
->length
= dwo_entry
->length
;
6014 sig_entry
->reading_dwo_directly
= 1;
6015 sig_entry
->per_bfd
= per_bfd
;
6016 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6017 sig_entry
->dwo_unit
= dwo_entry
;
6020 /* Subroutine of lookup_signatured_type.
6021 If we haven't read the TU yet, create the signatured_type data structure
6022 for a TU to be read in directly from a DWO file, bypassing the stub.
6023 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6024 using .gdb_index, then when reading a CU we want to stay in the DWO file
6025 containing that CU. Otherwise we could end up reading several other DWO
6026 files (due to comdat folding) to process the transitive closure of all the
6027 mentioned TUs, and that can be slow. The current DWO file will have every
6028 type signature that it needs.
6029 We only do this for .gdb_index because in the psymtab case we already have
6030 to read all the DWOs to build the type unit groups. */
6032 static struct signatured_type
*
6033 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6035 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6036 struct dwo_file
*dwo_file
;
6037 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6040 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6042 /* If TU skeletons have been removed then we may not have read in any
6044 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6045 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6047 /* We only ever need to read in one copy of a signatured type.
6048 Use the global signatured_types array to do our own comdat-folding
6049 of types. If this is the first time we're reading this TU, and
6050 the TU has an entry in .gdb_index, replace the recorded data from
6051 .gdb_index with this TU. */
6053 signatured_type
find_sig_entry (sig
);
6054 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6055 &find_sig_entry
, INSERT
);
6056 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6058 /* We can get here with the TU already read, *or* in the process of being
6059 read. Don't reassign the global entry to point to this DWO if that's
6060 the case. Also note that if the TU is already being read, it may not
6061 have come from a DWO, the program may be a mix of Fission-compiled
6062 code and non-Fission-compiled code. */
6064 /* Have we already tried to read this TU?
6065 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6066 needn't exist in the global table yet). */
6067 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6070 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6071 dwo_unit of the TU itself. */
6072 dwo_file
= cu
->dwo_unit
->dwo_file
;
6074 /* Ok, this is the first time we're reading this TU. */
6075 if (dwo_file
->tus
== NULL
)
6077 find_dwo_entry
.signature
= sig
;
6078 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6080 if (dwo_entry
== NULL
)
6083 /* If the global table doesn't have an entry for this TU, add one. */
6084 if (sig_entry
== NULL
)
6085 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6087 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6088 sig_entry
->tu_read
= 1;
6092 /* Subroutine of lookup_signatured_type.
6093 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6094 then try the DWP file. If the TU stub (skeleton) has been removed then
6095 it won't be in .gdb_index. */
6097 static struct signatured_type
*
6098 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6100 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6101 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6102 struct dwo_unit
*dwo_entry
;
6105 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6106 gdb_assert (dwp_file
!= NULL
);
6108 /* If TU skeletons have been removed then we may not have read in any
6110 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6111 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6113 signatured_type
find_sig_entry (sig
);
6114 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6115 &find_sig_entry
, INSERT
);
6116 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6118 /* Have we already tried to read this TU?
6119 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6120 needn't exist in the global table yet). */
6121 if (sig_entry
!= NULL
)
6124 if (dwp_file
->tus
== NULL
)
6126 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6127 1 /* is_debug_types */);
6128 if (dwo_entry
== NULL
)
6131 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6132 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6137 /* Lookup a signature based type for DW_FORM_ref_sig8.
6138 Returns NULL if signature SIG is not present in the table.
6139 It is up to the caller to complain about this. */
6141 static struct signatured_type
*
6142 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6144 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6146 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6148 /* We're in a DWO/DWP file, and we're using .gdb_index.
6149 These cases require special processing. */
6150 if (get_dwp_file (per_objfile
) == NULL
)
6151 return lookup_dwo_signatured_type (cu
, sig
);
6153 return lookup_dwp_signatured_type (cu
, sig
);
6157 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6159 signatured_type
find_entry (sig
);
6160 return ((struct signatured_type
*)
6161 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6166 /* Low level DIE reading support. */
6168 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6171 init_cu_die_reader (struct die_reader_specs
*reader
,
6172 struct dwarf2_cu
*cu
,
6173 struct dwarf2_section_info
*section
,
6174 struct dwo_file
*dwo_file
,
6175 struct abbrev_table
*abbrev_table
)
6177 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6178 reader
->abfd
= section
->get_bfd_owner ();
6180 reader
->dwo_file
= dwo_file
;
6181 reader
->die_section
= section
;
6182 reader
->buffer
= section
->buffer
;
6183 reader
->buffer_end
= section
->buffer
+ section
->size
;
6184 reader
->abbrev_table
= abbrev_table
;
6187 /* Subroutine of cutu_reader to simplify it.
6188 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6189 There's just a lot of work to do, and cutu_reader is big enough
6192 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6193 from it to the DIE in the DWO. If NULL we are skipping the stub.
6194 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6195 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6196 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6197 STUB_COMP_DIR may be non-NULL.
6198 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6199 are filled in with the info of the DIE from the DWO file.
6200 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6201 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6202 kept around for at least as long as *RESULT_READER.
6204 The result is non-zero if a valid (non-dummy) DIE was found. */
6207 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6208 struct dwo_unit
*dwo_unit
,
6209 struct die_info
*stub_comp_unit_die
,
6210 const char *stub_comp_dir
,
6211 struct die_reader_specs
*result_reader
,
6212 const gdb_byte
**result_info_ptr
,
6213 struct die_info
**result_comp_unit_die
,
6214 abbrev_table_up
*result_dwo_abbrev_table
)
6216 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6217 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6218 struct objfile
*objfile
= per_objfile
->objfile
;
6220 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6221 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6222 int i
,num_extra_attrs
;
6223 struct dwarf2_section_info
*dwo_abbrev_section
;
6224 struct die_info
*comp_unit_die
;
6226 /* At most one of these may be provided. */
6227 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6229 /* These attributes aren't processed until later:
6230 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6231 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6232 referenced later. However, these attributes are found in the stub
6233 which we won't have later. In order to not impose this complication
6234 on the rest of the code, we read them here and copy them to the
6243 if (stub_comp_unit_die
!= NULL
)
6245 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6247 if (!per_cu
->is_debug_types
)
6248 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6249 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6250 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6251 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6252 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6254 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6256 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6257 We need the value before we can process DW_AT_ranges values from the
6259 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6261 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6262 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6263 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6264 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6266 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6268 else if (stub_comp_dir
!= NULL
)
6270 /* Reconstruct the comp_dir attribute to simplify the code below. */
6271 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6272 comp_dir
->name
= DW_AT_comp_dir
;
6273 comp_dir
->form
= DW_FORM_string
;
6274 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6277 /* Set up for reading the DWO CU/TU. */
6278 cu
->dwo_unit
= dwo_unit
;
6279 dwarf2_section_info
*section
= dwo_unit
->section
;
6280 section
->read (objfile
);
6281 abfd
= section
->get_bfd_owner ();
6282 begin_info_ptr
= info_ptr
= (section
->buffer
6283 + to_underlying (dwo_unit
->sect_off
));
6284 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6286 if (per_cu
->is_debug_types
)
6288 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6290 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6291 section
, dwo_abbrev_section
,
6292 info_ptr
, rcuh_kind::TYPE
);
6293 /* This is not an assert because it can be caused by bad debug info. */
6294 if (sig_type
->signature
!= cu
->header
.signature
)
6296 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6297 " TU at offset %s [in module %s]"),
6298 hex_string (sig_type
->signature
),
6299 hex_string (cu
->header
.signature
),
6300 sect_offset_str (dwo_unit
->sect_off
),
6301 bfd_get_filename (abfd
));
6303 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6304 /* For DWOs coming from DWP files, we don't know the CU length
6305 nor the type's offset in the TU until now. */
6306 dwo_unit
->length
= cu
->header
.get_length ();
6307 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6309 /* Establish the type offset that can be used to lookup the type.
6310 For DWO files, we don't know it until now. */
6311 sig_type
->type_offset_in_section
6312 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6316 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6317 section
, dwo_abbrev_section
,
6318 info_ptr
, rcuh_kind::COMPILE
);
6319 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6320 /* For DWOs coming from DWP files, we don't know the CU length
6322 dwo_unit
->length
= cu
->header
.get_length ();
6325 dwo_abbrev_section
->read (objfile
);
6326 *result_dwo_abbrev_table
6327 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6328 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6329 result_dwo_abbrev_table
->get ());
6331 /* Read in the die, but leave space to copy over the attributes
6332 from the stub. This has the benefit of simplifying the rest of
6333 the code - all the work to maintain the illusion of a single
6334 DW_TAG_{compile,type}_unit DIE is done here. */
6335 num_extra_attrs
= ((stmt_list
!= NULL
)
6339 + (comp_dir
!= NULL
));
6340 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6343 /* Copy over the attributes from the stub to the DIE we just read in. */
6344 comp_unit_die
= *result_comp_unit_die
;
6345 i
= comp_unit_die
->num_attrs
;
6346 if (stmt_list
!= NULL
)
6347 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6349 comp_unit_die
->attrs
[i
++] = *low_pc
;
6350 if (high_pc
!= NULL
)
6351 comp_unit_die
->attrs
[i
++] = *high_pc
;
6353 comp_unit_die
->attrs
[i
++] = *ranges
;
6354 if (comp_dir
!= NULL
)
6355 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6356 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6358 if (dwarf_die_debug
)
6360 fprintf_unfiltered (gdb_stdlog
,
6361 "Read die from %s@0x%x of %s:\n",
6362 section
->get_name (),
6363 (unsigned) (begin_info_ptr
- section
->buffer
),
6364 bfd_get_filename (abfd
));
6365 dump_die (comp_unit_die
, dwarf_die_debug
);
6368 /* Skip dummy compilation units. */
6369 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6370 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6373 *result_info_ptr
= info_ptr
;
6377 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6378 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6379 signature is part of the header. */
6380 static gdb::optional
<ULONGEST
>
6381 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6383 if (cu
->header
.version
>= 5)
6384 return cu
->header
.signature
;
6385 struct attribute
*attr
;
6386 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6387 if (attr
== nullptr || !attr
->form_is_unsigned ())
6388 return gdb::optional
<ULONGEST
> ();
6389 return attr
->as_unsigned ();
6392 /* Subroutine of cutu_reader to simplify it.
6393 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6394 Returns NULL if the specified DWO unit cannot be found. */
6396 static struct dwo_unit
*
6397 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6399 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6400 struct dwo_unit
*dwo_unit
;
6401 const char *comp_dir
;
6403 gdb_assert (cu
!= NULL
);
6405 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6406 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6407 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6409 if (per_cu
->is_debug_types
)
6410 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6413 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6415 if (!signature
.has_value ())
6416 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6418 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6420 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6426 /* Subroutine of cutu_reader to simplify it.
6427 See it for a description of the parameters.
6428 Read a TU directly from a DWO file, bypassing the stub. */
6431 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6432 dwarf2_per_objfile
*per_objfile
,
6433 dwarf2_cu
*existing_cu
)
6435 struct signatured_type
*sig_type
;
6437 /* Verify we can do the following downcast, and that we have the
6439 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6440 sig_type
= (struct signatured_type
*) this_cu
;
6441 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6445 if (existing_cu
!= nullptr)
6448 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6449 /* There's no need to do the rereading_dwo_cu handling that
6450 cutu_reader does since we don't read the stub. */
6454 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6455 in per_objfile yet. */
6456 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6457 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6458 cu
= m_new_cu
.get ();
6461 /* A future optimization, if needed, would be to use an existing
6462 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6463 could share abbrev tables. */
6465 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6466 NULL
/* stub_comp_unit_die */,
6467 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6470 &m_dwo_abbrev_table
) == 0)
6477 /* Initialize a CU (or TU) and read its DIEs.
6478 If the CU defers to a DWO file, read the DWO file as well.
6480 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6481 Otherwise the table specified in the comp unit header is read in and used.
6482 This is an optimization for when we already have the abbrev table.
6484 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6487 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6488 dwarf2_per_objfile
*per_objfile
,
6489 struct abbrev_table
*abbrev_table
,
6490 dwarf2_cu
*existing_cu
,
6492 : die_reader_specs
{},
6495 struct objfile
*objfile
= per_objfile
->objfile
;
6496 struct dwarf2_section_info
*section
= this_cu
->section
;
6497 bfd
*abfd
= section
->get_bfd_owner ();
6498 const gdb_byte
*begin_info_ptr
;
6499 struct signatured_type
*sig_type
= NULL
;
6500 struct dwarf2_section_info
*abbrev_section
;
6501 /* Non-zero if CU currently points to a DWO file and we need to
6502 reread it. When this happens we need to reread the skeleton die
6503 before we can reread the DWO file (this only applies to CUs, not TUs). */
6504 int rereading_dwo_cu
= 0;
6506 if (dwarf_die_debug
)
6507 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6508 this_cu
->is_debug_types
? "type" : "comp",
6509 sect_offset_str (this_cu
->sect_off
));
6511 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6512 file (instead of going through the stub), short-circuit all of this. */
6513 if (this_cu
->reading_dwo_directly
)
6515 /* Narrow down the scope of possibilities to have to understand. */
6516 gdb_assert (this_cu
->is_debug_types
);
6517 gdb_assert (abbrev_table
== NULL
);
6518 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6522 /* This is cheap if the section is already read in. */
6523 section
->read (objfile
);
6525 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6527 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6531 if (existing_cu
!= nullptr)
6534 /* If this CU is from a DWO file we need to start over, we need to
6535 refetch the attributes from the skeleton CU.
6536 This could be optimized by retrieving those attributes from when we
6537 were here the first time: the previous comp_unit_die was stored in
6538 comp_unit_obstack. But there's no data yet that we need this
6540 if (cu
->dwo_unit
!= NULL
)
6541 rereading_dwo_cu
= 1;
6545 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6546 in per_objfile yet. */
6547 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6548 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6549 cu
= m_new_cu
.get ();
6552 /* Get the header. */
6553 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6555 /* We already have the header, there's no need to read it in again. */
6556 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6560 if (this_cu
->is_debug_types
)
6562 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6563 section
, abbrev_section
,
6564 info_ptr
, rcuh_kind::TYPE
);
6566 /* Since per_cu is the first member of struct signatured_type,
6567 we can go from a pointer to one to a pointer to the other. */
6568 sig_type
= (struct signatured_type
*) this_cu
;
6569 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6570 gdb_assert (sig_type
->type_offset_in_tu
6571 == cu
->header
.type_cu_offset_in_tu
);
6572 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6574 /* LENGTH has not been set yet for type units if we're
6575 using .gdb_index. */
6576 this_cu
->length
= cu
->header
.get_length ();
6578 /* Establish the type offset that can be used to lookup the type. */
6579 sig_type
->type_offset_in_section
=
6580 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6582 this_cu
->dwarf_version
= cu
->header
.version
;
6586 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6587 section
, abbrev_section
,
6589 rcuh_kind::COMPILE
);
6591 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6592 if (this_cu
->length
== 0)
6593 this_cu
->length
= cu
->header
.get_length ();
6595 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6596 this_cu
->dwarf_version
= cu
->header
.version
;
6600 /* Skip dummy compilation units. */
6601 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6602 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6608 /* If we don't have them yet, read the abbrevs for this compilation unit.
6609 And if we need to read them now, make sure they're freed when we're
6611 if (abbrev_table
!= NULL
)
6612 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6615 abbrev_section
->read (objfile
);
6616 m_abbrev_table_holder
6617 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6618 abbrev_table
= m_abbrev_table_holder
.get ();
6621 /* Read the top level CU/TU die. */
6622 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6623 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6625 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6631 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6632 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6633 table from the DWO file and pass the ownership over to us. It will be
6634 referenced from READER, so we must make sure to free it after we're done
6637 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6638 DWO CU, that this test will fail (the attribute will not be present). */
6639 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6640 if (dwo_name
!= nullptr)
6642 struct dwo_unit
*dwo_unit
;
6643 struct die_info
*dwo_comp_unit_die
;
6645 if (comp_unit_die
->has_children
)
6647 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6648 " has children (offset %s) [in module %s]"),
6649 sect_offset_str (this_cu
->sect_off
),
6650 bfd_get_filename (abfd
));
6652 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6653 if (dwo_unit
!= NULL
)
6655 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6656 comp_unit_die
, NULL
,
6659 &m_dwo_abbrev_table
) == 0)
6665 comp_unit_die
= dwo_comp_unit_die
;
6669 /* Yikes, we couldn't find the rest of the DIE, we only have
6670 the stub. A complaint has already been logged. There's
6671 not much more we can do except pass on the stub DIE to
6672 die_reader_func. We don't want to throw an error on bad
6679 cutu_reader::keep ()
6681 /* Done, clean up. */
6682 gdb_assert (!dummy_p
);
6683 if (m_new_cu
!= NULL
)
6685 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6687 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6688 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6692 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6693 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6694 assumed to have already done the lookup to find the DWO file).
6696 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6697 THIS_CU->is_debug_types, but nothing else.
6699 We fill in THIS_CU->length.
6701 THIS_CU->cu is always freed when done.
6702 This is done in order to not leave THIS_CU->cu in a state where we have
6703 to care whether it refers to the "main" CU or the DWO CU.
6705 When parent_cu is passed, it is used to provide a default value for
6706 str_offsets_base and addr_base from the parent. */
6708 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6709 dwarf2_per_objfile
*per_objfile
,
6710 struct dwarf2_cu
*parent_cu
,
6711 struct dwo_file
*dwo_file
)
6712 : die_reader_specs
{},
6715 struct objfile
*objfile
= per_objfile
->objfile
;
6716 struct dwarf2_section_info
*section
= this_cu
->section
;
6717 bfd
*abfd
= section
->get_bfd_owner ();
6718 struct dwarf2_section_info
*abbrev_section
;
6719 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6721 if (dwarf_die_debug
)
6722 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6723 this_cu
->is_debug_types
? "type" : "comp",
6724 sect_offset_str (this_cu
->sect_off
));
6726 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6728 abbrev_section
= (dwo_file
!= NULL
6729 ? &dwo_file
->sections
.abbrev
6730 : get_abbrev_section_for_cu (this_cu
));
6732 /* This is cheap if the section is already read in. */
6733 section
->read (objfile
);
6735 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6737 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6738 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6739 section
, abbrev_section
, info_ptr
,
6740 (this_cu
->is_debug_types
6742 : rcuh_kind::COMPILE
));
6744 if (parent_cu
!= nullptr)
6746 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6747 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6749 this_cu
->length
= m_new_cu
->header
.get_length ();
6751 /* Skip dummy compilation units. */
6752 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6753 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6759 abbrev_section
->read (objfile
);
6760 m_abbrev_table_holder
6761 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6763 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6764 m_abbrev_table_holder
.get ());
6765 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6769 /* Type Unit Groups.
6771 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6772 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6773 so that all types coming from the same compilation (.o file) are grouped
6774 together. A future step could be to put the types in the same symtab as
6775 the CU the types ultimately came from. */
6778 hash_type_unit_group (const void *item
)
6780 const struct type_unit_group
*tu_group
6781 = (const struct type_unit_group
*) item
;
6783 return hash_stmt_list_entry (&tu_group
->hash
);
6787 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6789 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6790 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6792 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6795 /* Allocate a hash table for type unit groups. */
6798 allocate_type_unit_groups_table ()
6800 return htab_up (htab_create_alloc (3,
6801 hash_type_unit_group
,
6803 htab_delete_entry
<type_unit_group
>,
6807 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6808 partial symtabs. We combine several TUs per psymtab to not let the size
6809 of any one psymtab grow too big. */
6810 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6811 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6813 /* Helper routine for get_type_unit_group.
6814 Create the type_unit_group object used to hold one or more TUs. */
6816 static std::unique_ptr
<type_unit_group
>
6817 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6819 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6820 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6822 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6823 tu_group
->per_bfd
= per_bfd
;
6825 if (per_bfd
->using_index
)
6827 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6828 struct dwarf2_per_cu_quick_data
);
6832 unsigned int line_offset
= to_underlying (line_offset_struct
);
6833 dwarf2_psymtab
*pst
;
6836 /* Give the symtab a useful name for debug purposes. */
6837 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6838 name
= string_printf ("<type_units_%d>",
6839 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6841 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6843 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6845 pst
->anonymous
= true;
6848 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6849 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6854 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6855 STMT_LIST is a DW_AT_stmt_list attribute. */
6857 static struct type_unit_group
*
6858 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6860 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6861 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6862 struct type_unit_group
*tu_group
;
6864 unsigned int line_offset
;
6865 struct type_unit_group type_unit_group_for_lookup
;
6867 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6868 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6870 /* Do we need to create a new group, or can we use an existing one? */
6872 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6874 line_offset
= stmt_list
->as_unsigned ();
6875 ++tu_stats
->nr_symtab_sharers
;
6879 /* Ugh, no stmt_list. Rare, but we have to handle it.
6880 We can do various things here like create one group per TU or
6881 spread them over multiple groups to split up the expansion work.
6882 To avoid worst case scenarios (too many groups or too large groups)
6883 we, umm, group them in bunches. */
6884 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6885 | (tu_stats
->nr_stmt_less_type_units
6886 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6887 ++tu_stats
->nr_stmt_less_type_units
;
6890 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6891 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6892 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6893 &type_unit_group_for_lookup
, INSERT
);
6894 if (*slot
== nullptr)
6896 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6897 std::unique_ptr
<type_unit_group
> grp
6898 = create_type_unit_group (cu
, line_offset_struct
);
6899 *slot
= grp
.release ();
6900 ++tu_stats
->nr_symtabs
;
6903 tu_group
= (struct type_unit_group
*) *slot
;
6904 gdb_assert (tu_group
!= nullptr);
6908 /* Partial symbol tables. */
6910 /* Create a psymtab named NAME and assign it to PER_CU.
6912 The caller must fill in the following details:
6913 dirname, textlow, texthigh. */
6915 static dwarf2_psymtab
*
6916 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6917 dwarf2_per_objfile
*per_objfile
,
6921 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6922 per_objfile
->objfile
->per_bfd
, per_cu
);
6924 pst
->psymtabs_addrmap_supported
= true;
6926 /* This is the glue that links PST into GDB's symbol API. */
6927 per_cu
->v
.psymtab
= pst
;
6932 /* DIE reader function for process_psymtab_comp_unit. */
6935 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6936 const gdb_byte
*info_ptr
,
6937 struct die_info
*comp_unit_die
,
6938 enum language pretend_language
)
6940 struct dwarf2_cu
*cu
= reader
->cu
;
6941 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6942 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6943 struct objfile
*objfile
= per_objfile
->objfile
;
6944 struct gdbarch
*gdbarch
= objfile
->arch ();
6945 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6947 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6948 dwarf2_psymtab
*pst
;
6949 enum pc_bounds_kind cu_bounds_kind
;
6950 const char *filename
;
6952 gdb_assert (! per_cu
->is_debug_types
);
6954 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6956 /* Allocate a new partial symbol table structure. */
6957 gdb::unique_xmalloc_ptr
<char> debug_filename
;
6958 static const char artificial
[] = "<artificial>";
6959 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6960 if (filename
== NULL
)
6962 else if (strcmp (filename
, artificial
) == 0)
6964 debug_filename
.reset (concat (artificial
, "@",
6965 sect_offset_str (per_cu
->sect_off
),
6967 filename
= debug_filename
.get ();
6970 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
6972 /* This must be done before calling dwarf2_build_include_psymtabs. */
6973 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6975 baseaddr
= objfile
->text_section_offset ();
6977 dwarf2_find_base_address (comp_unit_die
, cu
);
6979 /* Possibly set the default values of LOWPC and HIGHPC from
6981 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6982 &best_highpc
, cu
, pst
);
6983 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6986 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
6989 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
6991 /* Store the contiguous range if it is not empty; it can be
6992 empty for CUs with no code. */
6993 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
6997 /* Check if comp unit has_children.
6998 If so, read the rest of the partial symbols from this comp unit.
6999 If not, there's no more debug_info for this comp unit. */
7000 if (comp_unit_die
->has_children
)
7002 struct partial_die_info
*first_die
;
7003 CORE_ADDR lowpc
, highpc
;
7005 lowpc
= ((CORE_ADDR
) -1);
7006 highpc
= ((CORE_ADDR
) 0);
7008 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7010 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7011 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7013 /* If we didn't find a lowpc, set it to highpc to avoid
7014 complaints from `maint check'. */
7015 if (lowpc
== ((CORE_ADDR
) -1))
7018 /* If the compilation unit didn't have an explicit address range,
7019 then use the information extracted from its child dies. */
7020 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7023 best_highpc
= highpc
;
7026 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7027 best_lowpc
+ baseaddr
)
7029 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7030 best_highpc
+ baseaddr
)
7035 if (!cu
->per_cu
->imported_symtabs_empty ())
7038 int len
= cu
->per_cu
->imported_symtabs_size ();
7040 /* Fill in 'dependencies' here; we fill in 'users' in a
7042 pst
->number_of_dependencies
= len
;
7044 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7045 for (i
= 0; i
< len
; ++i
)
7047 pst
->dependencies
[i
]
7048 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7051 cu
->per_cu
->imported_symtabs_free ();
7054 /* Get the list of files included in the current compilation unit,
7055 and build a psymtab for each of them. */
7056 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7058 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7059 ", %d global, %d static syms",
7060 per_cu
->is_debug_types
? "type" : "comp",
7061 sect_offset_str (per_cu
->sect_off
),
7062 paddress (gdbarch
, pst
->text_low (objfile
)),
7063 paddress (gdbarch
, pst
->text_high (objfile
)),
7064 (int) pst
->global_psymbols
.size (),
7065 (int) pst
->static_psymbols
.size ());
7068 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7069 Process compilation unit THIS_CU for a psymtab. */
7072 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7073 dwarf2_per_objfile
*per_objfile
,
7074 bool want_partial_unit
,
7075 enum language pretend_language
)
7077 /* If this compilation unit was already read in, free the
7078 cached copy in order to read it in again. This is
7079 necessary because we skipped some symbols when we first
7080 read in the compilation unit (see load_partial_dies).
7081 This problem could be avoided, but the benefit is unclear. */
7082 per_objfile
->remove_cu (this_cu
);
7084 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7086 if (reader
.comp_unit_die
== nullptr)
7089 switch (reader
.comp_unit_die
->tag
)
7091 case DW_TAG_compile_unit
:
7092 this_cu
->unit_type
= DW_UT_compile
;
7094 case DW_TAG_partial_unit
:
7095 this_cu
->unit_type
= DW_UT_partial
;
7097 case DW_TAG_type_unit
:
7098 this_cu
->unit_type
= DW_UT_type
;
7101 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7102 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7103 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7104 objfile_name (per_objfile
->objfile
));
7111 else if (this_cu
->is_debug_types
)
7112 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7113 reader
.comp_unit_die
);
7114 else if (want_partial_unit
7115 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7116 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7117 reader
.comp_unit_die
,
7120 /* Age out any secondary CUs. */
7121 per_objfile
->age_comp_units ();
7124 /* Reader function for build_type_psymtabs. */
7127 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7128 const gdb_byte
*info_ptr
,
7129 struct die_info
*type_unit_die
)
7131 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7132 struct dwarf2_cu
*cu
= reader
->cu
;
7133 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7134 struct signatured_type
*sig_type
;
7135 struct type_unit_group
*tu_group
;
7136 struct attribute
*attr
;
7137 struct partial_die_info
*first_die
;
7138 CORE_ADDR lowpc
, highpc
;
7139 dwarf2_psymtab
*pst
;
7141 gdb_assert (per_cu
->is_debug_types
);
7142 sig_type
= (struct signatured_type
*) per_cu
;
7144 if (! type_unit_die
->has_children
)
7147 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7148 tu_group
= get_type_unit_group (cu
, attr
);
7150 if (tu_group
->tus
== nullptr)
7151 tu_group
->tus
= new std::vector
<signatured_type
*>;
7152 tu_group
->tus
->push_back (sig_type
);
7154 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7155 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7156 pst
->anonymous
= true;
7158 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7160 lowpc
= (CORE_ADDR
) -1;
7161 highpc
= (CORE_ADDR
) 0;
7162 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7167 /* Struct used to sort TUs by their abbreviation table offset. */
7169 struct tu_abbrev_offset
7171 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7172 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7175 /* This is used when sorting. */
7176 bool operator< (const tu_abbrev_offset
&other
) const
7178 return abbrev_offset
< other
.abbrev_offset
;
7181 signatured_type
*sig_type
;
7182 sect_offset abbrev_offset
;
7185 /* Efficiently read all the type units.
7187 The efficiency is because we sort TUs by the abbrev table they use and
7188 only read each abbrev table once. In one program there are 200K TUs
7189 sharing 8K abbrev tables.
7191 The main purpose of this function is to support building the
7192 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7193 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7194 can collapse the search space by grouping them by stmt_list.
7195 The savings can be significant, in the same program from above the 200K TUs
7196 share 8K stmt_list tables.
7198 FUNC is expected to call get_type_unit_group, which will create the
7199 struct type_unit_group if necessary and add it to
7200 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7203 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7205 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7206 abbrev_table_up abbrev_table
;
7207 sect_offset abbrev_offset
;
7209 /* It's up to the caller to not call us multiple times. */
7210 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7212 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7215 /* TUs typically share abbrev tables, and there can be way more TUs than
7216 abbrev tables. Sort by abbrev table to reduce the number of times we
7217 read each abbrev table in.
7218 Alternatives are to punt or to maintain a cache of abbrev tables.
7219 This is simpler and efficient enough for now.
7221 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7222 symtab to use). Typically TUs with the same abbrev offset have the same
7223 stmt_list value too so in practice this should work well.
7225 The basic algorithm here is:
7227 sort TUs by abbrev table
7228 for each TU with same abbrev table:
7229 read abbrev table if first user
7230 read TU top level DIE
7231 [IWBN if DWO skeletons had DW_AT_stmt_list]
7234 dwarf_read_debug_printf ("Building type unit groups ...");
7236 /* Sort in a separate table to maintain the order of all_comp_units
7237 for .gdb_index: TU indices directly index all_type_units. */
7238 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7239 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7241 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7243 if (cu
->is_debug_types
)
7245 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7246 sorted_by_abbrev
.emplace_back
7247 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7248 sig_type
->sect_off
));
7252 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7254 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7256 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7258 /* Switch to the next abbrev table if necessary. */
7259 if (abbrev_table
== NULL
7260 || tu
.abbrev_offset
!= abbrev_offset
)
7262 abbrev_offset
= tu
.abbrev_offset
;
7263 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7265 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7266 ++tu_stats
->nr_uniq_abbrev_tables
;
7269 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7270 abbrev_table
.get (), nullptr, false);
7271 if (!reader
.dummy_p
)
7272 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7273 reader
.comp_unit_die
);
7277 /* Print collected type unit statistics. */
7280 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7282 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7284 dwarf_read_debug_printf ("Type unit statistics:");
7285 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7286 dwarf_read_debug_printf (" %d uniq abbrev tables",
7287 tu_stats
->nr_uniq_abbrev_tables
);
7288 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7289 tu_stats
->nr_symtabs
);
7290 dwarf_read_debug_printf (" %d symtab sharers",
7291 tu_stats
->nr_symtab_sharers
);
7292 dwarf_read_debug_printf (" %d type units without a stmt_list",
7293 tu_stats
->nr_stmt_less_type_units
);
7294 dwarf_read_debug_printf (" %d all_type_units reallocs",
7295 tu_stats
->nr_all_type_units_reallocs
);
7298 /* Traversal function for build_type_psymtabs. */
7301 build_type_psymtab_dependencies (void **slot
, void *info
)
7303 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7304 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7305 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7306 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7307 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7310 gdb_assert (len
> 0);
7311 gdb_assert (tu_group
->type_unit_group_p ());
7313 pst
->number_of_dependencies
= len
;
7314 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7315 for (i
= 0; i
< len
; ++i
)
7317 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7318 gdb_assert (iter
->is_debug_types
);
7319 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7320 iter
->type_unit_group
= tu_group
;
7323 delete tu_group
->tus
;
7324 tu_group
->tus
= nullptr;
7329 /* Traversal function for process_skeletonless_type_unit.
7330 Read a TU in a DWO file and build partial symbols for it. */
7333 process_skeletonless_type_unit (void **slot
, void *info
)
7335 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7336 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7338 /* If this TU doesn't exist in the global table, add it and read it in. */
7340 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7341 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7343 signatured_type
find_entry (dwo_unit
->signature
);
7344 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7345 &find_entry
, INSERT
);
7346 /* If we've already seen this type there's nothing to do. What's happening
7347 is we're doing our own version of comdat-folding here. */
7351 /* This does the job that create_all_comp_units would have done for
7353 signatured_type
*entry
7354 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7355 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7358 /* This does the job that build_type_psymtabs would have done. */
7359 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7360 if (!reader
.dummy_p
)
7361 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7362 reader
.comp_unit_die
);
7367 /* Traversal function for process_skeletonless_type_units. */
7370 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7372 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7374 if (dwo_file
->tus
!= NULL
)
7375 htab_traverse_noresize (dwo_file
->tus
.get (),
7376 process_skeletonless_type_unit
, info
);
7381 /* Scan all TUs of DWO files, verifying we've processed them.
7382 This is needed in case a TU was emitted without its skeleton.
7383 Note: This can't be done until we know what all the DWO files are. */
7386 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7388 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7389 if (get_dwp_file (per_objfile
) == NULL
7390 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7392 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7393 process_dwo_file_for_skeletonless_type_units
,
7398 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7401 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7403 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7405 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7410 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7412 /* Set the 'user' field only if it is not already set. */
7413 if (pst
->dependencies
[j
]->user
== NULL
)
7414 pst
->dependencies
[j
]->user
= pst
;
7419 /* Build the partial symbol table by doing a quick pass through the
7420 .debug_info and .debug_abbrev sections. */
7423 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7425 struct objfile
*objfile
= per_objfile
->objfile
;
7426 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7428 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7429 objfile_name (objfile
));
7431 scoped_restore restore_reading_psyms
7432 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7434 per_bfd
->info
.read (objfile
);
7436 /* Any cached compilation units will be linked by the per-objfile
7437 read_in_chain. Make sure to free them when we're done. */
7438 free_cached_comp_units
freer (per_objfile
);
7440 create_all_comp_units (per_objfile
);
7441 build_type_psymtabs (per_objfile
);
7443 /* Create a temporary address map on a temporary obstack. We later
7444 copy this to the final obstack. */
7445 auto_obstack temp_obstack
;
7447 scoped_restore save_psymtabs_addrmap
7448 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7449 addrmap_create_mutable (&temp_obstack
));
7451 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7453 if (per_cu
->v
.psymtab
!= NULL
)
7454 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7456 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7460 /* This has to wait until we read the CUs, we need the list of DWOs. */
7461 process_skeletonless_type_units (per_objfile
);
7463 /* Now that all TUs have been processed we can fill in the dependencies. */
7464 if (per_bfd
->type_unit_groups
!= NULL
)
7466 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7467 build_type_psymtab_dependencies
, per_objfile
);
7470 if (dwarf_read_debug
> 0)
7471 print_tu_stats (per_objfile
);
7473 set_partial_user (per_objfile
);
7475 per_bfd
->partial_symtabs
->psymtabs_addrmap
7476 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7477 per_bfd
->partial_symtabs
->obstack ());
7478 /* At this point we want to keep the address map. */
7479 save_psymtabs_addrmap
.release ();
7481 dwarf_read_debug_printf ("Done building psymtabs of %s",
7482 objfile_name (objfile
));
7485 /* Load the partial DIEs for a secondary CU into memory.
7486 This is also used when rereading a primary CU with load_all_dies. */
7489 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7490 dwarf2_per_objfile
*per_objfile
,
7491 dwarf2_cu
*existing_cu
)
7493 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7495 if (!reader
.dummy_p
)
7497 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7500 /* Check if comp unit has_children.
7501 If so, read the rest of the partial symbols from this comp unit.
7502 If not, there's no more debug_info for this comp unit. */
7503 if (reader
.comp_unit_die
->has_children
)
7504 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7511 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7512 struct dwarf2_section_info
*section
,
7513 struct dwarf2_section_info
*abbrev_section
,
7514 unsigned int is_dwz
,
7515 htab_up
&types_htab
,
7516 rcuh_kind section_kind
)
7518 const gdb_byte
*info_ptr
;
7519 struct objfile
*objfile
= per_objfile
->objfile
;
7521 dwarf_read_debug_printf ("Reading %s for %s",
7522 section
->get_name (),
7523 section
->get_file_name ());
7525 section
->read (objfile
);
7527 info_ptr
= section
->buffer
;
7529 while (info_ptr
< section
->buffer
+ section
->size
)
7531 dwarf2_per_cu_data_up this_cu
;
7533 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7535 comp_unit_head cu_header
;
7536 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7537 abbrev_section
, info_ptr
,
7540 /* Save the compilation unit for later lookup. */
7541 if (cu_header
.unit_type
!= DW_UT_type
)
7542 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7545 if (types_htab
== nullptr)
7546 types_htab
= allocate_signatured_type_table ();
7548 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7549 (cu_header
.signature
);
7550 signatured_type
*sig_ptr
= sig_type
.get ();
7551 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7552 this_cu
.reset (sig_type
.release ());
7554 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7555 gdb_assert (slot
!= nullptr);
7556 if (*slot
!= nullptr)
7557 complaint (_("debug type entry at offset %s is duplicate to"
7558 " the entry at offset %s, signature %s"),
7559 sect_offset_str (sect_off
),
7560 sect_offset_str (sig_ptr
->sect_off
),
7561 hex_string (sig_ptr
->signature
));
7564 this_cu
->sect_off
= sect_off
;
7565 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7566 this_cu
->is_dwz
= is_dwz
;
7567 this_cu
->section
= section
;
7569 info_ptr
= info_ptr
+ this_cu
->length
;
7570 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7574 /* Create a list of all compilation units in OBJFILE.
7575 This is only done for -readnow and building partial symtabs. */
7578 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7582 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7583 &per_objfile
->per_bfd
->abbrev
, 0,
7584 types_htab
, rcuh_kind::COMPILE
);
7585 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7586 read_comp_units_from_section (per_objfile
, §ion
,
7587 &per_objfile
->per_bfd
->abbrev
, 0,
7588 types_htab
, rcuh_kind::TYPE
);
7590 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7592 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7593 types_htab
, rcuh_kind::COMPILE
);
7595 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7598 /* Process all loaded DIEs for compilation unit CU, starting at
7599 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7600 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7601 DW_AT_ranges). See the comments of add_partial_subprogram on how
7602 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7605 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7606 CORE_ADDR
*highpc
, int set_addrmap
,
7607 struct dwarf2_cu
*cu
)
7609 struct partial_die_info
*pdi
;
7611 /* Now, march along the PDI's, descending into ones which have
7612 interesting children but skipping the children of the other ones,
7613 until we reach the end of the compilation unit. */
7621 /* Anonymous namespaces or modules have no name but have interesting
7622 children, so we need to look at them. Ditto for anonymous
7625 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7626 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7627 || pdi
->tag
== DW_TAG_imported_unit
7628 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7632 case DW_TAG_subprogram
:
7633 case DW_TAG_inlined_subroutine
:
7634 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7635 if (cu
->per_cu
->lang
== language_cplus
)
7636 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7639 case DW_TAG_constant
:
7640 case DW_TAG_variable
:
7641 case DW_TAG_typedef
:
7642 case DW_TAG_union_type
:
7643 if (!pdi
->is_declaration
7644 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7646 add_partial_symbol (pdi
, cu
);
7649 case DW_TAG_class_type
:
7650 case DW_TAG_interface_type
:
7651 case DW_TAG_structure_type
:
7652 if (!pdi
->is_declaration
)
7654 add_partial_symbol (pdi
, cu
);
7656 if ((cu
->per_cu
->lang
== language_rust
7657 || cu
->per_cu
->lang
== language_cplus
)
7658 && pdi
->has_children
)
7659 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7662 case DW_TAG_enumeration_type
:
7663 if (!pdi
->is_declaration
)
7664 add_partial_enumeration (pdi
, cu
);
7666 case DW_TAG_base_type
:
7667 case DW_TAG_subrange_type
:
7668 /* File scope base type definitions are added to the partial
7670 add_partial_symbol (pdi
, cu
);
7672 case DW_TAG_namespace
:
7673 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7676 if (!pdi
->is_declaration
)
7677 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7679 case DW_TAG_imported_unit
:
7681 struct dwarf2_per_cu_data
*per_cu
;
7683 /* For now we don't handle imported units in type units. */
7684 if (cu
->per_cu
->is_debug_types
)
7686 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7687 " supported in type units [in module %s]"),
7688 objfile_name (cu
->per_objfile
->objfile
));
7691 per_cu
= dwarf2_find_containing_comp_unit
7692 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7694 /* Go read the partial unit, if needed. */
7695 if (per_cu
->v
.psymtab
== NULL
)
7696 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7699 cu
->per_cu
->imported_symtabs_push (per_cu
);
7702 case DW_TAG_imported_declaration
:
7703 add_partial_symbol (pdi
, cu
);
7710 /* If the die has a sibling, skip to the sibling. */
7712 pdi
= pdi
->die_sibling
;
7716 /* Functions used to compute the fully scoped name of a partial DIE.
7718 Normally, this is simple. For C++, the parent DIE's fully scoped
7719 name is concatenated with "::" and the partial DIE's name.
7720 Enumerators are an exception; they use the scope of their parent
7721 enumeration type, i.e. the name of the enumeration type is not
7722 prepended to the enumerator.
7724 There are two complexities. One is DW_AT_specification; in this
7725 case "parent" means the parent of the target of the specification,
7726 instead of the direct parent of the DIE. The other is compilers
7727 which do not emit DW_TAG_namespace; in this case we try to guess
7728 the fully qualified name of structure types from their members'
7729 linkage names. This must be done using the DIE's children rather
7730 than the children of any DW_AT_specification target. We only need
7731 to do this for structures at the top level, i.e. if the target of
7732 any DW_AT_specification (if any; otherwise the DIE itself) does not
7735 /* Compute the scope prefix associated with PDI's parent, in
7736 compilation unit CU. The result will be allocated on CU's
7737 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7738 field. NULL is returned if no prefix is necessary. */
7740 partial_die_parent_scope (struct partial_die_info
*pdi
,
7741 struct dwarf2_cu
*cu
)
7743 const char *grandparent_scope
;
7744 struct partial_die_info
*parent
, *real_pdi
;
7746 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7747 then this means the parent of the specification DIE. */
7750 while (real_pdi
->has_specification
)
7752 auto res
= find_partial_die (real_pdi
->spec_offset
,
7753 real_pdi
->spec_is_dwz
, cu
);
7758 parent
= real_pdi
->die_parent
;
7762 if (parent
->scope_set
)
7763 return parent
->scope
;
7767 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7769 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7770 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7771 Work around this problem here. */
7772 if (cu
->per_cu
->lang
== language_cplus
7773 && parent
->tag
== DW_TAG_namespace
7774 && strcmp (parent
->name (cu
), "::") == 0
7775 && grandparent_scope
== NULL
)
7777 parent
->scope
= NULL
;
7778 parent
->scope_set
= 1;
7782 /* Nested subroutines in Fortran get a prefix. */
7783 if (pdi
->tag
== DW_TAG_enumerator
)
7784 /* Enumerators should not get the name of the enumeration as a prefix. */
7785 parent
->scope
= grandparent_scope
;
7786 else if (parent
->tag
== DW_TAG_namespace
7787 || parent
->tag
== DW_TAG_module
7788 || parent
->tag
== DW_TAG_structure_type
7789 || parent
->tag
== DW_TAG_class_type
7790 || parent
->tag
== DW_TAG_interface_type
7791 || parent
->tag
== DW_TAG_union_type
7792 || parent
->tag
== DW_TAG_enumeration_type
7793 || (cu
->per_cu
->lang
== language_fortran
7794 && parent
->tag
== DW_TAG_subprogram
7795 && pdi
->tag
== DW_TAG_subprogram
))
7797 if (grandparent_scope
== NULL
)
7798 parent
->scope
= parent
->name (cu
);
7800 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7802 parent
->name (cu
), 0, cu
);
7806 /* FIXME drow/2004-04-01: What should we be doing with
7807 function-local names? For partial symbols, we should probably be
7809 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7810 dwarf_tag_name (parent
->tag
),
7811 sect_offset_str (pdi
->sect_off
));
7812 parent
->scope
= grandparent_scope
;
7815 parent
->scope_set
= 1;
7816 return parent
->scope
;
7819 /* Return the fully scoped name associated with PDI, from compilation unit
7820 CU. The result will be allocated with malloc. */
7822 static gdb::unique_xmalloc_ptr
<char>
7823 partial_die_full_name (struct partial_die_info
*pdi
,
7824 struct dwarf2_cu
*cu
)
7826 const char *parent_scope
;
7828 /* If this is a template instantiation, we can not work out the
7829 template arguments from partial DIEs. So, unfortunately, we have
7830 to go through the full DIEs. At least any work we do building
7831 types here will be reused if full symbols are loaded later. */
7832 if (pdi
->has_template_arguments
)
7836 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7838 struct die_info
*die
;
7839 struct attribute attr
;
7840 struct dwarf2_cu
*ref_cu
= cu
;
7842 /* DW_FORM_ref_addr is using section offset. */
7843 attr
.name
= (enum dwarf_attribute
) 0;
7844 attr
.form
= DW_FORM_ref_addr
;
7845 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7846 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7848 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7852 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7853 if (parent_scope
== NULL
)
7856 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7862 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7864 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7865 struct objfile
*objfile
= per_objfile
->objfile
;
7866 struct gdbarch
*gdbarch
= objfile
->arch ();
7868 const char *actual_name
= NULL
;
7871 baseaddr
= objfile
->text_section_offset ();
7873 gdb::unique_xmalloc_ptr
<char> built_actual_name
7874 = partial_die_full_name (pdi
, cu
);
7875 if (built_actual_name
!= NULL
)
7876 actual_name
= built_actual_name
.get ();
7878 if (actual_name
== NULL
)
7879 actual_name
= pdi
->name (cu
);
7881 partial_symbol psymbol
;
7882 memset (&psymbol
, 0, sizeof (psymbol
));
7883 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7884 &objfile
->objfile_obstack
);
7885 psymbol
.ginfo
.set_section_index (-1);
7887 /* The code below indicates that the psymbol should be installed by
7889 gdb::optional
<psymbol_placement
> where
;
7893 case DW_TAG_inlined_subroutine
:
7894 case DW_TAG_subprogram
:
7895 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7897 if (pdi
->is_external
7898 || cu
->per_cu
->lang
== language_ada
7899 || (cu
->per_cu
->lang
== language_fortran
7900 && pdi
->die_parent
!= NULL
7901 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7903 /* Normally, only "external" DIEs are part of the global scope.
7904 But in Ada and Fortran, we want to be able to access nested
7905 procedures globally. So all Ada and Fortran subprograms are
7906 stored in the global scope. */
7907 where
= psymbol_placement::GLOBAL
;
7910 where
= psymbol_placement::STATIC
;
7912 psymbol
.domain
= VAR_DOMAIN
;
7913 psymbol
.aclass
= LOC_BLOCK
;
7914 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7915 psymbol
.ginfo
.value
.address
= addr
;
7917 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7918 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7920 case DW_TAG_constant
:
7921 psymbol
.domain
= VAR_DOMAIN
;
7922 psymbol
.aclass
= LOC_STATIC
;
7923 where
= (pdi
->is_external
7924 ? psymbol_placement::GLOBAL
7925 : psymbol_placement::STATIC
);
7927 case DW_TAG_variable
:
7929 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7933 && !per_objfile
->per_bfd
->has_section_at_zero
)
7935 /* A global or static variable may also have been stripped
7936 out by the linker if unused, in which case its address
7937 will be nullified; do not add such variables into partial
7938 symbol table then. */
7940 else if (pdi
->is_external
)
7943 Don't enter into the minimal symbol tables as there is
7944 a minimal symbol table entry from the ELF symbols already.
7945 Enter into partial symbol table if it has a location
7946 descriptor or a type.
7947 If the location descriptor is missing, new_symbol will create
7948 a LOC_UNRESOLVED symbol, the address of the variable will then
7949 be determined from the minimal symbol table whenever the variable
7951 The address for the partial symbol table entry is not
7952 used by GDB, but it comes in handy for debugging partial symbol
7955 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7957 psymbol
.domain
= VAR_DOMAIN
;
7958 psymbol
.aclass
= LOC_STATIC
;
7959 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7960 psymbol
.ginfo
.value
.address
= addr
;
7961 where
= psymbol_placement::GLOBAL
;
7966 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7968 /* Static Variable. Skip symbols whose value we cannot know (those
7969 without location descriptors or constant values). */
7970 if (!has_loc
&& !pdi
->has_const_value
)
7973 psymbol
.domain
= VAR_DOMAIN
;
7974 psymbol
.aclass
= LOC_STATIC
;
7975 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7977 psymbol
.ginfo
.value
.address
= addr
;
7978 where
= psymbol_placement::STATIC
;
7981 case DW_TAG_array_type
:
7982 case DW_TAG_typedef
:
7983 case DW_TAG_base_type
:
7984 case DW_TAG_subrange_type
:
7985 psymbol
.domain
= VAR_DOMAIN
;
7986 psymbol
.aclass
= LOC_TYPEDEF
;
7987 where
= psymbol_placement::STATIC
;
7989 case DW_TAG_imported_declaration
:
7990 case DW_TAG_namespace
:
7991 psymbol
.domain
= VAR_DOMAIN
;
7992 psymbol
.aclass
= LOC_TYPEDEF
;
7993 where
= psymbol_placement::GLOBAL
;
7996 /* With Fortran 77 there might be a "BLOCK DATA" module
7997 available without any name. If so, we skip the module as it
7998 doesn't bring any value. */
7999 if (actual_name
!= nullptr)
8001 psymbol
.domain
= MODULE_DOMAIN
;
8002 psymbol
.aclass
= LOC_TYPEDEF
;
8003 where
= psymbol_placement::GLOBAL
;
8006 case DW_TAG_class_type
:
8007 case DW_TAG_interface_type
:
8008 case DW_TAG_structure_type
:
8009 case DW_TAG_union_type
:
8010 case DW_TAG_enumeration_type
:
8011 /* Skip external references. The DWARF standard says in the section
8012 about "Structure, Union, and Class Type Entries": "An incomplete
8013 structure, union or class type is represented by a structure,
8014 union or class entry that does not have a byte size attribute
8015 and that has a DW_AT_declaration attribute." */
8016 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8019 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8020 static vs. global. */
8021 psymbol
.domain
= STRUCT_DOMAIN
;
8022 psymbol
.aclass
= LOC_TYPEDEF
;
8023 where
= (cu
->per_cu
->lang
== language_cplus
8024 ? psymbol_placement::GLOBAL
8025 : psymbol_placement::STATIC
);
8027 case DW_TAG_enumerator
:
8028 psymbol
.domain
= VAR_DOMAIN
;
8029 psymbol
.aclass
= LOC_CONST
;
8030 where
= (cu
->per_cu
->lang
== language_cplus
8031 ? psymbol_placement::GLOBAL
8032 : psymbol_placement::STATIC
);
8038 if (where
.has_value ())
8040 if (built_actual_name
!= nullptr)
8041 actual_name
= objfile
->intern (actual_name
);
8042 if (pdi
->linkage_name
== nullptr
8043 || cu
->per_cu
->lang
== language_ada
)
8044 psymbol
.ginfo
.set_linkage_name (actual_name
);
8047 psymbol
.ginfo
.set_demangled_name (actual_name
,
8048 &objfile
->objfile_obstack
);
8049 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8051 cu
->per_cu
->v
.psymtab
->add_psymbol
8052 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8057 /* Read a partial die corresponding to a namespace; also, add a symbol
8058 corresponding to that namespace to the symbol table. NAMESPACE is
8059 the name of the enclosing namespace. */
8062 add_partial_namespace (struct partial_die_info
*pdi
,
8063 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8064 int set_addrmap
, struct dwarf2_cu
*cu
)
8066 /* Add a symbol for the namespace. */
8068 add_partial_symbol (pdi
, cu
);
8070 /* Now scan partial symbols in that namespace. */
8072 if (pdi
->has_children
)
8073 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8076 /* Read a partial die corresponding to a Fortran module. */
8079 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8080 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8082 /* Add a symbol for the namespace. */
8084 add_partial_symbol (pdi
, cu
);
8086 /* Now scan partial symbols in that module. */
8088 if (pdi
->has_children
)
8089 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8092 /* Read a partial die corresponding to a subprogram or an inlined
8093 subprogram and create a partial symbol for that subprogram.
8094 When the CU language allows it, this routine also defines a partial
8095 symbol for each nested subprogram that this subprogram contains.
8096 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8097 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8099 PDI may also be a lexical block, in which case we simply search
8100 recursively for subprograms defined inside that lexical block.
8101 Again, this is only performed when the CU language allows this
8102 type of definitions. */
8105 add_partial_subprogram (struct partial_die_info
*pdi
,
8106 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8107 int set_addrmap
, struct dwarf2_cu
*cu
)
8109 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8111 if (pdi
->has_pc_info
)
8113 if (pdi
->lowpc
< *lowpc
)
8114 *lowpc
= pdi
->lowpc
;
8115 if (pdi
->highpc
> *highpc
)
8116 *highpc
= pdi
->highpc
;
8119 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8120 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8121 struct gdbarch
*gdbarch
= objfile
->arch ();
8123 CORE_ADDR this_highpc
;
8124 CORE_ADDR this_lowpc
;
8126 baseaddr
= objfile
->text_section_offset ();
8128 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8129 pdi
->lowpc
+ baseaddr
)
8132 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8133 pdi
->highpc
+ baseaddr
)
8135 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8136 this_lowpc
, this_highpc
- 1,
8137 cu
->per_cu
->v
.psymtab
);
8141 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8143 if (!pdi
->is_declaration
)
8144 /* Ignore subprogram DIEs that do not have a name, they are
8145 illegal. Do not emit a complaint at this point, we will
8146 do so when we convert this psymtab into a symtab. */
8148 add_partial_symbol (pdi
, cu
);
8152 if (! pdi
->has_children
)
8155 if (cu
->per_cu
->lang
== language_ada
8156 || cu
->per_cu
->lang
== language_fortran
)
8158 pdi
= pdi
->die_child
;
8162 if (pdi
->tag
== DW_TAG_subprogram
8163 || pdi
->tag
== DW_TAG_inlined_subroutine
8164 || pdi
->tag
== DW_TAG_lexical_block
)
8165 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8166 pdi
= pdi
->die_sibling
;
8171 /* Read a partial die corresponding to an enumeration type. */
8174 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8175 struct dwarf2_cu
*cu
)
8177 struct partial_die_info
*pdi
;
8179 if (enum_pdi
->name (cu
) != NULL
)
8180 add_partial_symbol (enum_pdi
, cu
);
8182 pdi
= enum_pdi
->die_child
;
8185 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8186 complaint (_("malformed enumerator DIE ignored"));
8188 add_partial_symbol (pdi
, cu
);
8189 pdi
= pdi
->die_sibling
;
8193 /* Return the initial uleb128 in the die at INFO_PTR. */
8196 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8198 unsigned int bytes_read
;
8200 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8203 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8204 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8206 Return the corresponding abbrev, or NULL if the number is zero (indicating
8207 an empty DIE). In either case *BYTES_READ will be set to the length of
8208 the initial number. */
8210 static const struct abbrev_info
*
8211 peek_die_abbrev (const die_reader_specs
&reader
,
8212 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8214 dwarf2_cu
*cu
= reader
.cu
;
8215 bfd
*abfd
= reader
.abfd
;
8216 unsigned int abbrev_number
8217 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8219 if (abbrev_number
== 0)
8222 const abbrev_info
*abbrev
8223 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8226 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8227 " at offset %s [in module %s]"),
8228 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8229 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8235 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8236 Returns a pointer to the end of a series of DIEs, terminated by an empty
8237 DIE. Any children of the skipped DIEs will also be skipped. */
8239 static const gdb_byte
*
8240 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8244 unsigned int bytes_read
;
8245 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8249 return info_ptr
+ bytes_read
;
8251 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8255 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8256 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8257 abbrev corresponding to that skipped uleb128 should be passed in
8258 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8261 static const gdb_byte
*
8262 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8263 const struct abbrev_info
*abbrev
)
8265 unsigned int bytes_read
;
8266 struct attribute attr
;
8267 bfd
*abfd
= reader
->abfd
;
8268 struct dwarf2_cu
*cu
= reader
->cu
;
8269 const gdb_byte
*buffer
= reader
->buffer
;
8270 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8271 unsigned int form
, i
;
8273 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8275 /* The only abbrev we care about is DW_AT_sibling. */
8276 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8278 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8279 if (attr
.form
== DW_FORM_ref_addr
)
8280 complaint (_("ignoring absolute DW_AT_sibling"));
8283 sect_offset off
= attr
.get_ref_die_offset ();
8284 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8286 if (sibling_ptr
< info_ptr
)
8287 complaint (_("DW_AT_sibling points backwards"));
8288 else if (sibling_ptr
> reader
->buffer_end
)
8289 reader
->die_section
->overflow_complaint ();
8295 /* If it isn't DW_AT_sibling, skip this attribute. */
8296 form
= abbrev
->attrs
[i
].form
;
8300 case DW_FORM_ref_addr
:
8301 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8302 and later it is offset sized. */
8303 if (cu
->header
.version
== 2)
8304 info_ptr
+= cu
->header
.addr_size
;
8306 info_ptr
+= cu
->header
.offset_size
;
8308 case DW_FORM_GNU_ref_alt
:
8309 info_ptr
+= cu
->header
.offset_size
;
8312 info_ptr
+= cu
->header
.addr_size
;
8320 case DW_FORM_flag_present
:
8321 case DW_FORM_implicit_const
:
8338 case DW_FORM_ref_sig8
:
8341 case DW_FORM_data16
:
8344 case DW_FORM_string
:
8345 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8346 info_ptr
+= bytes_read
;
8348 case DW_FORM_sec_offset
:
8350 case DW_FORM_GNU_strp_alt
:
8351 info_ptr
+= cu
->header
.offset_size
;
8353 case DW_FORM_exprloc
:
8355 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8356 info_ptr
+= bytes_read
;
8358 case DW_FORM_block1
:
8359 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8361 case DW_FORM_block2
:
8362 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8364 case DW_FORM_block4
:
8365 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8371 case DW_FORM_ref_udata
:
8372 case DW_FORM_GNU_addr_index
:
8373 case DW_FORM_GNU_str_index
:
8374 case DW_FORM_rnglistx
:
8375 case DW_FORM_loclistx
:
8376 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8378 case DW_FORM_indirect
:
8379 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8380 info_ptr
+= bytes_read
;
8381 /* We need to continue parsing from here, so just go back to
8383 goto skip_attribute
;
8386 error (_("Dwarf Error: Cannot handle %s "
8387 "in DWARF reader [in module %s]"),
8388 dwarf_form_name (form
),
8389 bfd_get_filename (abfd
));
8393 if (abbrev
->has_children
)
8394 return skip_children (reader
, info_ptr
);
8399 /* Locate ORIG_PDI's sibling.
8400 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8402 static const gdb_byte
*
8403 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8404 struct partial_die_info
*orig_pdi
,
8405 const gdb_byte
*info_ptr
)
8407 /* Do we know the sibling already? */
8409 if (orig_pdi
->sibling
)
8410 return orig_pdi
->sibling
;
8412 /* Are there any children to deal with? */
8414 if (!orig_pdi
->has_children
)
8417 /* Skip the children the long way. */
8419 return skip_children (reader
, info_ptr
);
8422 /* Expand this partial symbol table into a full symbol table. SELF is
8426 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8428 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8430 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8432 /* If this psymtab is constructed from a debug-only objfile, the
8433 has_section_at_zero flag will not necessarily be correct. We
8434 can get the correct value for this flag by looking at the data
8435 associated with the (presumably stripped) associated objfile. */
8436 if (objfile
->separate_debug_objfile_backlink
)
8438 dwarf2_per_objfile
*per_objfile_backlink
8439 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8441 per_objfile
->per_bfd
->has_section_at_zero
8442 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8445 expand_psymtab (objfile
);
8447 process_cu_includes (per_objfile
);
8450 /* Reading in full CUs. */
8452 /* Add PER_CU to the queue. */
8455 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8456 dwarf2_per_objfile
*per_objfile
,
8457 enum language pretend_language
)
8461 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8462 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8465 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8467 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8470 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8471 DIEs, false otherwise.
8473 Explanation: there is an invariant that if a CU is queued for expansion
8474 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8475 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8476 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8477 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8478 invariant is respected.
8480 The caller is therefore not required to load the CU's DIEs (we return false)
8483 - the CU is already expanded, and therefore does not get enqueued
8484 - the CU gets enqueued for expansion, but its DIEs are already loaded
8486 Note that the caller should not use this function's return value as an
8487 indicator of whether the CU's DIEs are loaded right now, it should check
8488 that by calling `dwarf2_per_objfile::get_cu` instead. */
8491 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8492 dwarf2_per_cu_data
*per_cu
,
8493 dwarf2_per_objfile
*per_objfile
,
8494 enum language pretend_language
)
8496 /* We may arrive here during partial symbol reading, if we need full
8497 DIEs to process an unusual case (e.g. template arguments). Do
8498 not queue PER_CU, just tell our caller to load its DIEs. */
8499 if (per_cu
->per_bfd
->reading_partial_symbols
)
8501 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8503 if (cu
== NULL
|| cu
->dies
== NULL
)
8508 /* Mark the dependence relation so that we don't flush PER_CU
8510 if (dependent_cu
!= NULL
)
8511 dependent_cu
->add_dependence (per_cu
);
8513 /* If it's already on the queue, we have nothing to do. */
8516 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8518 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8520 /* If the CU is queued for expansion, it should not already be
8522 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8524 /* The DIEs are already loaded, the caller doesn't need to do it. */
8528 bool queued
= false;
8529 if (!per_objfile
->symtab_set_p (per_cu
))
8531 /* Add it to the queue. */
8532 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8536 /* If the compilation unit is already loaded, just mark it as
8538 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8542 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8543 and the DIEs are not already loaded. */
8544 return queued
&& cu
== nullptr;
8547 /* Process the queue. */
8550 process_queue (dwarf2_per_objfile
*per_objfile
)
8552 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8553 objfile_name (per_objfile
->objfile
));
8555 /* The queue starts out with one item, but following a DIE reference
8556 may load a new CU, adding it to the end of the queue. */
8557 while (!per_objfile
->per_bfd
->queue
->empty ())
8559 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8560 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8562 if (!per_objfile
->symtab_set_p (per_cu
))
8564 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8566 /* Skip dummy CUs. */
8569 unsigned int debug_print_threshold
;
8572 if (per_cu
->is_debug_types
)
8574 struct signatured_type
*sig_type
=
8575 (struct signatured_type
*) per_cu
;
8577 sprintf (buf
, "TU %s at offset %s",
8578 hex_string (sig_type
->signature
),
8579 sect_offset_str (per_cu
->sect_off
));
8580 /* There can be 100s of TUs.
8581 Only print them in verbose mode. */
8582 debug_print_threshold
= 2;
8586 sprintf (buf
, "CU at offset %s",
8587 sect_offset_str (per_cu
->sect_off
));
8588 debug_print_threshold
= 1;
8591 if (dwarf_read_debug
>= debug_print_threshold
)
8592 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8594 if (per_cu
->is_debug_types
)
8595 process_full_type_unit (cu
, item
.pretend_language
);
8597 process_full_comp_unit (cu
, item
.pretend_language
);
8599 if (dwarf_read_debug
>= debug_print_threshold
)
8600 dwarf_read_debug_printf ("Done expanding %s", buf
);
8605 per_objfile
->per_bfd
->queue
->pop ();
8608 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8609 objfile_name (per_objfile
->objfile
));
8612 /* Read in full symbols for PST, and anything it depends on. */
8615 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8617 gdb_assert (!readin_p (objfile
));
8619 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8620 free_cached_comp_units
freer (per_objfile
);
8621 expand_dependencies (objfile
);
8623 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8624 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8627 /* See psympriv.h. */
8630 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8632 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8633 return per_objfile
->symtab_set_p (per_cu_data
);
8636 /* See psympriv.h. */
8639 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8641 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8642 return per_objfile
->get_symtab (per_cu_data
);
8645 /* Trivial hash function for die_info: the hash value of a DIE
8646 is its offset in .debug_info for this objfile. */
8649 die_hash (const void *item
)
8651 const struct die_info
*die
= (const struct die_info
*) item
;
8653 return to_underlying (die
->sect_off
);
8656 /* Trivial comparison function for die_info structures: two DIEs
8657 are equal if they have the same offset. */
8660 die_eq (const void *item_lhs
, const void *item_rhs
)
8662 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8663 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8665 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8668 /* Load the DIEs associated with PER_CU into memory.
8670 In some cases, the caller, while reading partial symbols, will need to load
8671 the full symbols for the CU for some reason. It will already have a
8672 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8673 rather than creating a new one. */
8676 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8677 dwarf2_per_objfile
*per_objfile
,
8678 dwarf2_cu
*existing_cu
,
8680 enum language pretend_language
)
8682 gdb_assert (! this_cu
->is_debug_types
);
8684 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8688 struct dwarf2_cu
*cu
= reader
.cu
;
8689 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8691 gdb_assert (cu
->die_hash
== NULL
);
8693 htab_create_alloc_ex (cu
->header
.length
/ 12,
8697 &cu
->comp_unit_obstack
,
8698 hashtab_obstack_allocate
,
8699 dummy_obstack_deallocate
);
8701 if (reader
.comp_unit_die
->has_children
)
8702 reader
.comp_unit_die
->child
8703 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8704 &info_ptr
, reader
.comp_unit_die
);
8705 cu
->dies
= reader
.comp_unit_die
;
8706 /* comp_unit_die is not stored in die_hash, no need. */
8708 /* We try not to read any attributes in this function, because not
8709 all CUs needed for references have been loaded yet, and symbol
8710 table processing isn't initialized. But we have to set the CU language,
8711 or we won't be able to build types correctly.
8712 Similarly, if we do not read the producer, we can not apply
8713 producer-specific interpretation. */
8714 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8719 /* Add a DIE to the delayed physname list. */
8722 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8723 const char *name
, struct die_info
*die
,
8724 struct dwarf2_cu
*cu
)
8726 struct delayed_method_info mi
;
8728 mi
.fnfield_index
= fnfield_index
;
8732 cu
->method_list
.push_back (mi
);
8735 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8736 "const" / "volatile". If so, decrements LEN by the length of the
8737 modifier and return true. Otherwise return false. */
8741 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8743 size_t mod_len
= sizeof (mod
) - 1;
8744 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8752 /* Compute the physnames of any methods on the CU's method list.
8754 The computation of method physnames is delayed in order to avoid the
8755 (bad) condition that one of the method's formal parameters is of an as yet
8759 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8761 /* Only C++ delays computing physnames. */
8762 if (cu
->method_list
.empty ())
8764 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8766 for (const delayed_method_info
&mi
: cu
->method_list
)
8768 const char *physname
;
8769 struct fn_fieldlist
*fn_flp
8770 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8771 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8772 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8773 = physname
? physname
: "";
8775 /* Since there's no tag to indicate whether a method is a
8776 const/volatile overload, extract that information out of the
8778 if (physname
!= NULL
)
8780 size_t len
= strlen (physname
);
8784 if (physname
[len
] == ')') /* shortcut */
8786 else if (check_modifier (physname
, len
, " const"))
8787 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8788 else if (check_modifier (physname
, len
, " volatile"))
8789 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8796 /* The list is no longer needed. */
8797 cu
->method_list
.clear ();
8800 /* Go objects should be embedded in a DW_TAG_module DIE,
8801 and it's not clear if/how imported objects will appear.
8802 To keep Go support simple until that's worked out,
8803 go back through what we've read and create something usable.
8804 We could do this while processing each DIE, and feels kinda cleaner,
8805 but that way is more invasive.
8806 This is to, for example, allow the user to type "p var" or "b main"
8807 without having to specify the package name, and allow lookups
8808 of module.object to work in contexts that use the expression
8812 fixup_go_packaging (struct dwarf2_cu
*cu
)
8814 gdb::unique_xmalloc_ptr
<char> package_name
;
8815 struct pending
*list
;
8818 for (list
= *cu
->get_builder ()->get_global_symbols ();
8822 for (i
= 0; i
< list
->nsyms
; ++i
)
8824 struct symbol
*sym
= list
->symbol
[i
];
8826 if (sym
->language () == language_go
8827 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8829 gdb::unique_xmalloc_ptr
<char> this_package_name
8830 (go_symbol_package_name (sym
));
8832 if (this_package_name
== NULL
)
8834 if (package_name
== NULL
)
8835 package_name
= std::move (this_package_name
);
8838 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8839 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8840 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8841 (symbol_symtab (sym
) != NULL
8842 ? symtab_to_filename_for_display
8843 (symbol_symtab (sym
))
8844 : objfile_name (objfile
)),
8845 this_package_name
.get (), package_name
.get ());
8851 if (package_name
!= NULL
)
8853 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8854 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8855 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8856 saved_package_name
);
8859 sym
= new (&objfile
->objfile_obstack
) symbol
;
8860 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8861 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8862 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8863 e.g., "main" finds the "main" module and not C's main(). */
8864 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8865 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8866 SYMBOL_TYPE (sym
) = type
;
8868 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8872 /* Allocate a fully-qualified name consisting of the two parts on the
8876 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8878 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8881 /* A helper that allocates a variant part to attach to a Rust enum
8882 type. OBSTACK is where the results should be allocated. TYPE is
8883 the type we're processing. DISCRIMINANT_INDEX is the index of the
8884 discriminant. It must be the index of one of the fields of TYPE,
8885 or -1 to mean there is no discriminant (univariant enum).
8886 DEFAULT_INDEX is the index of the default field; or -1 if there is
8887 no default. RANGES is indexed by "effective" field number (the
8888 field index, but omitting the discriminant and default fields) and
8889 must hold the discriminant values used by the variants. Note that
8890 RANGES must have a lifetime at least as long as OBSTACK -- either
8891 already allocated on it, or static. */
8894 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8895 int discriminant_index
, int default_index
,
8896 gdb::array_view
<discriminant_range
> ranges
)
8898 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8899 gdb_assert (discriminant_index
== -1
8900 || (discriminant_index
>= 0
8901 && discriminant_index
< type
->num_fields ()));
8902 gdb_assert (default_index
== -1
8903 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8905 /* We have one variant for each non-discriminant field. */
8906 int n_variants
= type
->num_fields ();
8907 if (discriminant_index
!= -1)
8910 variant
*variants
= new (obstack
) variant
[n_variants
];
8913 for (int i
= 0; i
< type
->num_fields (); ++i
)
8915 if (i
== discriminant_index
)
8918 variants
[var_idx
].first_field
= i
;
8919 variants
[var_idx
].last_field
= i
+ 1;
8921 /* The default field does not need a range, but other fields do.
8922 We skipped the discriminant above. */
8923 if (i
!= default_index
)
8925 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8932 gdb_assert (range_idx
== ranges
.size ());
8933 gdb_assert (var_idx
== n_variants
);
8935 variant_part
*part
= new (obstack
) variant_part
;
8936 part
->discriminant_index
= discriminant_index
;
8937 /* If there is no discriminant, then whether it is signed is of no
8940 = (discriminant_index
== -1
8942 : type
->field (discriminant_index
).type ()->is_unsigned ());
8943 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
8945 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
8946 gdb::array_view
<variant_part
> *prop_value
8947 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
8949 struct dynamic_prop prop
;
8950 prop
.set_variant_parts (prop_value
);
8952 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
8955 /* Some versions of rustc emitted enums in an unusual way.
8957 Ordinary enums were emitted as unions. The first element of each
8958 structure in the union was named "RUST$ENUM$DISR". This element
8959 held the discriminant.
8961 These versions of Rust also implemented the "non-zero"
8962 optimization. When the enum had two values, and one is empty and
8963 the other holds a pointer that cannot be zero, the pointer is used
8964 as the discriminant, with a zero value meaning the empty variant.
8965 Here, the union's first member is of the form
8966 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8967 where the fieldnos are the indices of the fields that should be
8968 traversed in order to find the field (which may be several fields deep)
8969 and the variantname is the name of the variant of the case when the
8972 This function recognizes whether TYPE is of one of these forms,
8973 and, if so, smashes it to be a variant type. */
8976 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
8978 gdb_assert (type
->code () == TYPE_CODE_UNION
);
8980 /* We don't need to deal with empty enums. */
8981 if (type
->num_fields () == 0)
8984 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8985 if (type
->num_fields () == 1
8986 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
8988 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
8990 /* Decode the field name to find the offset of the
8992 ULONGEST bit_offset
= 0;
8993 struct type
*field_type
= type
->field (0).type ();
8994 while (name
[0] >= '0' && name
[0] <= '9')
8997 unsigned long index
= strtoul (name
, &tail
, 10);
9000 || index
>= field_type
->num_fields ()
9001 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9002 != FIELD_LOC_KIND_BITPOS
))
9004 complaint (_("Could not parse Rust enum encoding string \"%s\""
9006 TYPE_FIELD_NAME (type
, 0),
9007 objfile_name (objfile
));
9012 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9013 field_type
= field_type
->field (index
).type ();
9016 /* Smash this type to be a structure type. We have to do this
9017 because the type has already been recorded. */
9018 type
->set_code (TYPE_CODE_STRUCT
);
9019 type
->set_num_fields (3);
9020 /* Save the field we care about. */
9021 struct field saved_field
= type
->field (0);
9023 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9025 /* Put the discriminant at index 0. */
9026 type
->field (0).set_type (field_type
);
9027 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9028 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9029 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9031 /* The order of fields doesn't really matter, so put the real
9032 field at index 1 and the data-less field at index 2. */
9033 type
->field (1) = saved_field
;
9034 TYPE_FIELD_NAME (type
, 1)
9035 = rust_last_path_segment (type
->field (1).type ()->name ());
9036 type
->field (1).type ()->set_name
9037 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9038 TYPE_FIELD_NAME (type
, 1)));
9040 const char *dataless_name
9041 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9043 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9045 type
->field (2).set_type (dataless_type
);
9046 /* NAME points into the original discriminant name, which
9047 already has the correct lifetime. */
9048 TYPE_FIELD_NAME (type
, 2) = name
;
9049 SET_FIELD_BITPOS (type
->field (2), 0);
9051 /* Indicate that this is a variant type. */
9052 static discriminant_range ranges
[1] = { { 0, 0 } };
9053 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9055 /* A union with a single anonymous field is probably an old-style
9057 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9059 /* Smash this type to be a structure type. We have to do this
9060 because the type has already been recorded. */
9061 type
->set_code (TYPE_CODE_STRUCT
);
9063 struct type
*field_type
= type
->field (0).type ();
9064 const char *variant_name
9065 = rust_last_path_segment (field_type
->name ());
9066 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9067 field_type
->set_name
9068 (rust_fully_qualify (&objfile
->objfile_obstack
,
9069 type
->name (), variant_name
));
9071 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9075 struct type
*disr_type
= nullptr;
9076 for (int i
= 0; i
< type
->num_fields (); ++i
)
9078 disr_type
= type
->field (i
).type ();
9080 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9082 /* All fields of a true enum will be structs. */
9085 else if (disr_type
->num_fields () == 0)
9087 /* Could be data-less variant, so keep going. */
9088 disr_type
= nullptr;
9090 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9091 "RUST$ENUM$DISR") != 0)
9093 /* Not a Rust enum. */
9103 /* If we got here without a discriminant, then it's probably
9105 if (disr_type
== nullptr)
9108 /* Smash this type to be a structure type. We have to do this
9109 because the type has already been recorded. */
9110 type
->set_code (TYPE_CODE_STRUCT
);
9112 /* Make space for the discriminant field. */
9113 struct field
*disr_field
= &disr_type
->field (0);
9115 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9116 * sizeof (struct field
)));
9117 memcpy (new_fields
+ 1, type
->fields (),
9118 type
->num_fields () * sizeof (struct field
));
9119 type
->set_fields (new_fields
);
9120 type
->set_num_fields (type
->num_fields () + 1);
9122 /* Install the discriminant at index 0 in the union. */
9123 type
->field (0) = *disr_field
;
9124 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9125 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9127 /* We need a way to find the correct discriminant given a
9128 variant name. For convenience we build a map here. */
9129 struct type
*enum_type
= disr_field
->type ();
9130 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9131 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9133 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9136 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9137 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9141 int n_fields
= type
->num_fields ();
9142 /* We don't need a range entry for the discriminant, but we do
9143 need one for every other field, as there is no default
9145 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9148 /* Skip the discriminant here. */
9149 for (int i
= 1; i
< n_fields
; ++i
)
9151 /* Find the final word in the name of this variant's type.
9152 That name can be used to look up the correct
9154 const char *variant_name
9155 = rust_last_path_segment (type
->field (i
).type ()->name ());
9157 auto iter
= discriminant_map
.find (variant_name
);
9158 if (iter
!= discriminant_map
.end ())
9160 ranges
[i
- 1].low
= iter
->second
;
9161 ranges
[i
- 1].high
= iter
->second
;
9164 /* In Rust, each element should have the size of the
9166 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9168 /* Remove the discriminant field, if it exists. */
9169 struct type
*sub_type
= type
->field (i
).type ();
9170 if (sub_type
->num_fields () > 0)
9172 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9173 sub_type
->set_fields (sub_type
->fields () + 1);
9175 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9177 (rust_fully_qualify (&objfile
->objfile_obstack
,
9178 type
->name (), variant_name
));
9181 /* Indicate that this is a variant type. */
9182 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9183 gdb::array_view
<discriminant_range
> (ranges
,
9188 /* Rewrite some Rust unions to be structures with variants parts. */
9191 rust_union_quirks (struct dwarf2_cu
*cu
)
9193 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9194 for (type
*type_
: cu
->rust_unions
)
9195 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9196 /* We don't need this any more. */
9197 cu
->rust_unions
.clear ();
9202 type_unit_group_unshareable
*
9203 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9205 auto iter
= this->m_type_units
.find (tu_group
);
9206 if (iter
!= this->m_type_units
.end ())
9207 return iter
->second
.get ();
9209 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9210 type_unit_group_unshareable
*result
= uniq
.get ();
9211 this->m_type_units
[tu_group
] = std::move (uniq
);
9216 dwarf2_per_objfile::get_type_for_signatured_type
9217 (signatured_type
*sig_type
) const
9219 auto iter
= this->m_type_map
.find (sig_type
);
9220 if (iter
== this->m_type_map
.end ())
9223 return iter
->second
;
9226 void dwarf2_per_objfile::set_type_for_signatured_type
9227 (signatured_type
*sig_type
, struct type
*type
)
9229 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9231 this->m_type_map
[sig_type
] = type
;
9234 /* A helper function for computing the list of all symbol tables
9235 included by PER_CU. */
9238 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9239 htab_t all_children
, htab_t all_type_symtabs
,
9240 dwarf2_per_cu_data
*per_cu
,
9241 dwarf2_per_objfile
*per_objfile
,
9242 struct compunit_symtab
*immediate_parent
)
9244 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9247 /* This inclusion and its children have been processed. */
9253 /* Only add a CU if it has a symbol table. */
9254 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9257 /* If this is a type unit only add its symbol table if we haven't
9258 seen it yet (type unit per_cu's can share symtabs). */
9259 if (per_cu
->is_debug_types
)
9261 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9265 result
->push_back (cust
);
9266 if (cust
->user
== NULL
)
9267 cust
->user
= immediate_parent
;
9272 result
->push_back (cust
);
9273 if (cust
->user
== NULL
)
9274 cust
->user
= immediate_parent
;
9278 if (!per_cu
->imported_symtabs_empty ())
9279 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9281 recursively_compute_inclusions (result
, all_children
,
9282 all_type_symtabs
, ptr
, per_objfile
,
9287 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9291 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9292 dwarf2_per_objfile
*per_objfile
)
9294 gdb_assert (! per_cu
->is_debug_types
);
9296 if (!per_cu
->imported_symtabs_empty ())
9299 std::vector
<compunit_symtab
*> result_symtabs
;
9300 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9302 /* If we don't have a symtab, we can just skip this case. */
9306 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9308 NULL
, xcalloc
, xfree
));
9309 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9311 NULL
, xcalloc
, xfree
));
9313 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9315 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9316 all_type_symtabs
.get (), ptr
,
9320 /* Now we have a transitive closure of all the included symtabs. */
9321 len
= result_symtabs
.size ();
9323 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9324 struct compunit_symtab
*, len
+ 1);
9325 memcpy (cust
->includes
, result_symtabs
.data (),
9326 len
* sizeof (compunit_symtab
*));
9327 cust
->includes
[len
] = NULL
;
9331 /* Compute the 'includes' field for the symtabs of all the CUs we just
9335 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9337 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9339 if (! iter
->is_debug_types
)
9340 compute_compunit_symtab_includes (iter
, per_objfile
);
9343 per_objfile
->per_bfd
->just_read_cus
.clear ();
9346 /* Generate full symbol information for CU, whose DIEs have
9347 already been loaded into memory. */
9350 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9352 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9353 struct objfile
*objfile
= per_objfile
->objfile
;
9354 struct gdbarch
*gdbarch
= objfile
->arch ();
9355 CORE_ADDR lowpc
, highpc
;
9356 struct compunit_symtab
*cust
;
9358 struct block
*static_block
;
9361 baseaddr
= objfile
->text_section_offset ();
9363 /* Clear the list here in case something was left over. */
9364 cu
->method_list
.clear ();
9366 dwarf2_find_base_address (cu
->dies
, cu
);
9368 /* Before we start reading the top-level DIE, ensure it has a valid tag
9370 switch (cu
->dies
->tag
)
9372 case DW_TAG_compile_unit
:
9373 case DW_TAG_partial_unit
:
9374 case DW_TAG_type_unit
:
9377 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9378 dwarf_tag_name (cu
->dies
->tag
),
9379 sect_offset_str (cu
->per_cu
->sect_off
),
9380 objfile_name (per_objfile
->objfile
));
9383 /* Do line number decoding in read_file_scope () */
9384 process_die (cu
->dies
, cu
);
9386 /* For now fudge the Go package. */
9387 if (cu
->per_cu
->lang
== language_go
)
9388 fixup_go_packaging (cu
);
9390 /* Now that we have processed all the DIEs in the CU, all the types
9391 should be complete, and it should now be safe to compute all of the
9393 compute_delayed_physnames (cu
);
9395 if (cu
->per_cu
->lang
== language_rust
)
9396 rust_union_quirks (cu
);
9398 /* Some compilers don't define a DW_AT_high_pc attribute for the
9399 compilation unit. If the DW_AT_high_pc is missing, synthesize
9400 it, by scanning the DIE's below the compilation unit. */
9401 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9403 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9404 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9406 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9407 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9408 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9409 addrmap to help ensure it has an accurate map of pc values belonging to
9411 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9413 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9414 SECT_OFF_TEXT (objfile
),
9419 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9421 /* Set symtab language to language from DW_AT_language. If the
9422 compilation is from a C file generated by language preprocessors, do
9423 not set the language if it was already deduced by start_subfile. */
9424 if (!(cu
->per_cu
->lang
== language_c
9425 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9426 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9428 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9429 produce DW_AT_location with location lists but it can be possibly
9430 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9431 there were bugs in prologue debug info, fixed later in GCC-4.5
9432 by "unwind info for epilogues" patch (which is not directly related).
9434 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9435 needed, it would be wrong due to missing DW_AT_producer there.
9437 Still one can confuse GDB by using non-standard GCC compilation
9438 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9440 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9441 cust
->locations_valid
= 1;
9443 if (gcc_4_minor
>= 5)
9444 cust
->epilogue_unwind_valid
= 1;
9446 cust
->call_site_htab
= cu
->call_site_htab
;
9449 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9451 /* Push it for inclusion processing later. */
9452 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9454 /* Not needed any more. */
9455 cu
->reset_builder ();
9458 /* Generate full symbol information for type unit CU, whose DIEs have
9459 already been loaded into memory. */
9462 process_full_type_unit (dwarf2_cu
*cu
,
9463 enum language pretend_language
)
9465 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9466 struct objfile
*objfile
= per_objfile
->objfile
;
9467 struct compunit_symtab
*cust
;
9468 struct signatured_type
*sig_type
;
9470 gdb_assert (cu
->per_cu
->is_debug_types
);
9471 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9473 /* Clear the list here in case something was left over. */
9474 cu
->method_list
.clear ();
9476 /* The symbol tables are set up in read_type_unit_scope. */
9477 process_die (cu
->dies
, cu
);
9479 /* For now fudge the Go package. */
9480 if (cu
->per_cu
->lang
== language_go
)
9481 fixup_go_packaging (cu
);
9483 /* Now that we have processed all the DIEs in the CU, all the types
9484 should be complete, and it should now be safe to compute all of the
9486 compute_delayed_physnames (cu
);
9488 if (cu
->per_cu
->lang
== language_rust
)
9489 rust_union_quirks (cu
);
9491 /* TUs share symbol tables.
9492 If this is the first TU to use this symtab, complete the construction
9493 of it with end_expandable_symtab. Otherwise, complete the addition of
9494 this TU's symbols to the existing symtab. */
9495 type_unit_group_unshareable
*tug_unshare
=
9496 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9497 if (tug_unshare
->compunit_symtab
== NULL
)
9499 buildsym_compunit
*builder
= cu
->get_builder ();
9500 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9501 tug_unshare
->compunit_symtab
= cust
;
9505 /* Set symtab language to language from DW_AT_language. If the
9506 compilation is from a C file generated by language preprocessors,
9507 do not set the language if it was already deduced by
9509 if (!(cu
->per_cu
->lang
== language_c
9510 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9511 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9516 cu
->get_builder ()->augment_type_symtab ();
9517 cust
= tug_unshare
->compunit_symtab
;
9520 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9522 /* Not needed any more. */
9523 cu
->reset_builder ();
9526 /* Process an imported unit DIE. */
9529 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9531 struct attribute
*attr
;
9533 /* For now we don't handle imported units in type units. */
9534 if (cu
->per_cu
->is_debug_types
)
9536 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9537 " supported in type units [in module %s]"),
9538 objfile_name (cu
->per_objfile
->objfile
));
9541 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9544 sect_offset sect_off
= attr
->get_ref_die_offset ();
9545 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9546 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9547 dwarf2_per_cu_data
*per_cu
9548 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9550 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9551 into another compilation unit, at root level. Regard this as a hint,
9553 if (die
->parent
&& die
->parent
->parent
== NULL
9554 && per_cu
->unit_type
== DW_UT_compile
9555 && per_cu
->lang
== language_cplus
)
9558 /* If necessary, add it to the queue and load its DIEs. */
9559 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9561 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9562 false, cu
->per_cu
->lang
);
9564 cu
->per_cu
->imported_symtabs_push (per_cu
);
9568 /* RAII object that represents a process_die scope: i.e.,
9569 starts/finishes processing a DIE. */
9570 class process_die_scope
9573 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9574 : m_die (die
), m_cu (cu
)
9576 /* We should only be processing DIEs not already in process. */
9577 gdb_assert (!m_die
->in_process
);
9578 m_die
->in_process
= true;
9581 ~process_die_scope ()
9583 m_die
->in_process
= false;
9585 /* If we're done processing the DIE for the CU that owns the line
9586 header, we don't need the line header anymore. */
9587 if (m_cu
->line_header_die_owner
== m_die
)
9589 delete m_cu
->line_header
;
9590 m_cu
->line_header
= NULL
;
9591 m_cu
->line_header_die_owner
= NULL
;
9600 /* Process a die and its children. */
9603 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9605 process_die_scope
scope (die
, cu
);
9609 case DW_TAG_padding
:
9611 case DW_TAG_compile_unit
:
9612 case DW_TAG_partial_unit
:
9613 read_file_scope (die
, cu
);
9615 case DW_TAG_type_unit
:
9616 read_type_unit_scope (die
, cu
);
9618 case DW_TAG_subprogram
:
9619 /* Nested subprograms in Fortran get a prefix. */
9620 if (cu
->per_cu
->lang
== language_fortran
9621 && die
->parent
!= NULL
9622 && die
->parent
->tag
== DW_TAG_subprogram
)
9623 cu
->processing_has_namespace_info
= true;
9625 case DW_TAG_inlined_subroutine
:
9626 read_func_scope (die
, cu
);
9628 case DW_TAG_lexical_block
:
9629 case DW_TAG_try_block
:
9630 case DW_TAG_catch_block
:
9631 read_lexical_block_scope (die
, cu
);
9633 case DW_TAG_call_site
:
9634 case DW_TAG_GNU_call_site
:
9635 read_call_site_scope (die
, cu
);
9637 case DW_TAG_class_type
:
9638 case DW_TAG_interface_type
:
9639 case DW_TAG_structure_type
:
9640 case DW_TAG_union_type
:
9641 process_structure_scope (die
, cu
);
9643 case DW_TAG_enumeration_type
:
9644 process_enumeration_scope (die
, cu
);
9647 /* These dies have a type, but processing them does not create
9648 a symbol or recurse to process the children. Therefore we can
9649 read them on-demand through read_type_die. */
9650 case DW_TAG_subroutine_type
:
9651 case DW_TAG_set_type
:
9652 case DW_TAG_pointer_type
:
9653 case DW_TAG_ptr_to_member_type
:
9654 case DW_TAG_reference_type
:
9655 case DW_TAG_rvalue_reference_type
:
9656 case DW_TAG_string_type
:
9659 case DW_TAG_array_type
:
9660 /* We only need to handle this case for Ada -- in other
9661 languages, it's normal for the compiler to emit a typedef
9663 if (cu
->per_cu
->lang
!= language_ada
)
9666 case DW_TAG_base_type
:
9667 case DW_TAG_subrange_type
:
9668 case DW_TAG_typedef
:
9669 /* Add a typedef symbol for the type definition, if it has a
9671 new_symbol (die
, read_type_die (die
, cu
), cu
);
9673 case DW_TAG_common_block
:
9674 read_common_block (die
, cu
);
9676 case DW_TAG_common_inclusion
:
9678 case DW_TAG_namespace
:
9679 cu
->processing_has_namespace_info
= true;
9680 read_namespace (die
, cu
);
9683 cu
->processing_has_namespace_info
= true;
9684 read_module (die
, cu
);
9686 case DW_TAG_imported_declaration
:
9687 cu
->processing_has_namespace_info
= true;
9688 if (read_namespace_alias (die
, cu
))
9690 /* The declaration is not a global namespace alias. */
9692 case DW_TAG_imported_module
:
9693 cu
->processing_has_namespace_info
= true;
9694 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9695 || cu
->per_cu
->lang
!= language_fortran
))
9696 complaint (_("Tag '%s' has unexpected children"),
9697 dwarf_tag_name (die
->tag
));
9698 read_import_statement (die
, cu
);
9701 case DW_TAG_imported_unit
:
9702 process_imported_unit_die (die
, cu
);
9705 case DW_TAG_variable
:
9706 read_variable (die
, cu
);
9710 new_symbol (die
, NULL
, cu
);
9715 /* DWARF name computation. */
9717 /* A helper function for dwarf2_compute_name which determines whether DIE
9718 needs to have the name of the scope prepended to the name listed in the
9722 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9724 struct attribute
*attr
;
9728 case DW_TAG_namespace
:
9729 case DW_TAG_typedef
:
9730 case DW_TAG_class_type
:
9731 case DW_TAG_interface_type
:
9732 case DW_TAG_structure_type
:
9733 case DW_TAG_union_type
:
9734 case DW_TAG_enumeration_type
:
9735 case DW_TAG_enumerator
:
9736 case DW_TAG_subprogram
:
9737 case DW_TAG_inlined_subroutine
:
9739 case DW_TAG_imported_declaration
:
9742 case DW_TAG_variable
:
9743 case DW_TAG_constant
:
9744 /* We only need to prefix "globally" visible variables. These include
9745 any variable marked with DW_AT_external or any variable that
9746 lives in a namespace. [Variables in anonymous namespaces
9747 require prefixing, but they are not DW_AT_external.] */
9749 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9751 struct dwarf2_cu
*spec_cu
= cu
;
9753 return die_needs_namespace (die_specification (die
, &spec_cu
),
9757 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9758 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9759 && die
->parent
->tag
!= DW_TAG_module
)
9761 /* A variable in a lexical block of some kind does not need a
9762 namespace, even though in C++ such variables may be external
9763 and have a mangled name. */
9764 if (die
->parent
->tag
== DW_TAG_lexical_block
9765 || die
->parent
->tag
== DW_TAG_try_block
9766 || die
->parent
->tag
== DW_TAG_catch_block
9767 || die
->parent
->tag
== DW_TAG_subprogram
)
9776 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9777 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9778 defined for the given DIE. */
9780 static struct attribute
*
9781 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9783 struct attribute
*attr
;
9785 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9787 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9792 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9793 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9794 defined for the given DIE. */
9797 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9799 const char *linkage_name
;
9801 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9802 if (linkage_name
== NULL
)
9803 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9805 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9806 See https://github.com/rust-lang/rust/issues/32925. */
9807 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9808 && strchr (linkage_name
, '{') != NULL
)
9809 linkage_name
= NULL
;
9811 return linkage_name
;
9814 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9815 compute the physname for the object, which include a method's:
9816 - formal parameters (C++),
9817 - receiver type (Go),
9819 The term "physname" is a bit confusing.
9820 For C++, for example, it is the demangled name.
9821 For Go, for example, it's the mangled name.
9823 For Ada, return the DIE's linkage name rather than the fully qualified
9824 name. PHYSNAME is ignored..
9826 The result is allocated on the objfile->per_bfd's obstack and
9830 dwarf2_compute_name (const char *name
,
9831 struct die_info
*die
, struct dwarf2_cu
*cu
,
9834 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9837 name
= dwarf2_name (die
, cu
);
9839 enum language lang
= cu
->per_cu
->lang
;
9841 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9842 but otherwise compute it by typename_concat inside GDB.
9843 FIXME: Actually this is not really true, or at least not always true.
9844 It's all very confusing. compute_and_set_names doesn't try to demangle
9845 Fortran names because there is no mangling standard. So new_symbol
9846 will set the demangled name to the result of dwarf2_full_name, and it is
9847 the demangled name that GDB uses if it exists. */
9848 if (lang
== language_ada
9849 || (lang
== language_fortran
&& physname
))
9851 /* For Ada unit, we prefer the linkage name over the name, as
9852 the former contains the exported name, which the user expects
9853 to be able to reference. Ideally, we want the user to be able
9854 to reference this entity using either natural or linkage name,
9855 but we haven't started looking at this enhancement yet. */
9856 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9858 if (linkage_name
!= NULL
)
9859 return linkage_name
;
9862 /* These are the only languages we know how to qualify names in. */
9864 && (lang
== language_cplus
9865 || lang
== language_fortran
|| lang
== language_d
9866 || lang
== language_rust
))
9868 if (die_needs_namespace (die
, cu
))
9871 const char *canonical_name
= NULL
;
9875 prefix
= determine_prefix (die
, cu
);
9876 if (*prefix
!= '\0')
9878 gdb::unique_xmalloc_ptr
<char> prefixed_name
9879 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9881 buf
.puts (prefixed_name
.get ());
9886 /* Template parameters may be specified in the DIE's DW_AT_name, or
9887 as children with DW_TAG_template_type_param or
9888 DW_TAG_value_type_param. If the latter, add them to the name
9889 here. If the name already has template parameters, then
9890 skip this step; some versions of GCC emit both, and
9891 it is more efficient to use the pre-computed name.
9893 Something to keep in mind about this process: it is very
9894 unlikely, or in some cases downright impossible, to produce
9895 something that will match the mangled name of a function.
9896 If the definition of the function has the same debug info,
9897 we should be able to match up with it anyway. But fallbacks
9898 using the minimal symbol, for instance to find a method
9899 implemented in a stripped copy of libstdc++, will not work.
9900 If we do not have debug info for the definition, we will have to
9901 match them up some other way.
9903 When we do name matching there is a related problem with function
9904 templates; two instantiated function templates are allowed to
9905 differ only by their return types, which we do not add here. */
9907 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9909 struct attribute
*attr
;
9910 struct die_info
*child
;
9913 die
->building_fullname
= 1;
9915 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9919 const gdb_byte
*bytes
;
9920 struct dwarf2_locexpr_baton
*baton
;
9923 if (child
->tag
!= DW_TAG_template_type_param
9924 && child
->tag
!= DW_TAG_template_value_param
)
9935 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9938 complaint (_("template parameter missing DW_AT_type"));
9939 buf
.puts ("UNKNOWN_TYPE");
9942 type
= die_type (child
, cu
);
9944 if (child
->tag
== DW_TAG_template_type_param
)
9946 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
9947 &type_print_raw_options
);
9951 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9954 complaint (_("template parameter missing "
9955 "DW_AT_const_value"));
9956 buf
.puts ("UNKNOWN_VALUE");
9960 dwarf2_const_value_attr (attr
, type
, name
,
9961 &cu
->comp_unit_obstack
, cu
,
9962 &value
, &bytes
, &baton
);
9964 if (type
->has_no_signedness ())
9965 /* GDB prints characters as NUMBER 'CHAR'. If that's
9966 changed, this can use value_print instead. */
9967 cu
->language_defn
->printchar (value
, type
, &buf
);
9970 struct value_print_options opts
;
9973 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9977 baton
->per_objfile
);
9978 else if (bytes
!= NULL
)
9980 v
= allocate_value (type
);
9981 memcpy (value_contents_writeable (v
), bytes
,
9982 TYPE_LENGTH (type
));
9985 v
= value_from_longest (type
, value
);
9987 /* Specify decimal so that we do not depend on
9989 get_formatted_print_options (&opts
, 'd');
9991 value_print (v
, &buf
, &opts
);
9996 die
->building_fullname
= 0;
10000 /* Close the argument list, with a space if necessary
10001 (nested templates). */
10002 if (!buf
.empty () && buf
.string ().back () == '>')
10009 /* For C++ methods, append formal parameter type
10010 information, if PHYSNAME. */
10012 if (physname
&& die
->tag
== DW_TAG_subprogram
10013 && lang
== language_cplus
)
10015 struct type
*type
= read_type_die (die
, cu
);
10017 c_type_print_args (type
, &buf
, 1, lang
,
10018 &type_print_raw_options
);
10020 if (lang
== language_cplus
)
10022 /* Assume that an artificial first parameter is
10023 "this", but do not crash if it is not. RealView
10024 marks unnamed (and thus unused) parameters as
10025 artificial; there is no way to differentiate
10027 if (type
->num_fields () > 0
10028 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10029 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10030 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10031 buf
.puts (" const");
10035 const std::string
&intermediate_name
= buf
.string ();
10037 if (lang
== language_cplus
)
10039 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10042 /* If we only computed INTERMEDIATE_NAME, or if
10043 INTERMEDIATE_NAME is already canonical, then we need to
10045 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10046 name
= objfile
->intern (intermediate_name
);
10048 name
= canonical_name
;
10055 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10056 If scope qualifiers are appropriate they will be added. The result
10057 will be allocated on the storage_obstack, or NULL if the DIE does
10058 not have a name. NAME may either be from a previous call to
10059 dwarf2_name or NULL.
10061 The output string will be canonicalized (if C++). */
10063 static const char *
10064 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10066 return dwarf2_compute_name (name
, die
, cu
, 0);
10069 /* Construct a physname for the given DIE in CU. NAME may either be
10070 from a previous call to dwarf2_name or NULL. The result will be
10071 allocated on the objfile_objstack or NULL if the DIE does not have a
10074 The output string will be canonicalized (if C++). */
10076 static const char *
10077 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10079 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10080 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10083 /* In this case dwarf2_compute_name is just a shortcut not building anything
10085 if (!die_needs_namespace (die
, cu
))
10086 return dwarf2_compute_name (name
, die
, cu
, 1);
10088 if (cu
->per_cu
->lang
!= language_rust
)
10089 mangled
= dw2_linkage_name (die
, cu
);
10091 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10093 gdb::unique_xmalloc_ptr
<char> demangled
;
10094 if (mangled
!= NULL
)
10096 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10098 /* Do nothing (do not demangle the symbol name). */
10102 /* Use DMGL_RET_DROP for C++ template functions to suppress
10103 their return type. It is easier for GDB users to search
10104 for such functions as `name(params)' than `long name(params)'.
10105 In such case the minimal symbol names do not match the full
10106 symbol names but for template functions there is never a need
10107 to look up their definition from their declaration so
10108 the only disadvantage remains the minimal symbol variant
10109 `long name(params)' does not have the proper inferior type. */
10110 demangled
.reset (gdb_demangle (mangled
,
10111 (DMGL_PARAMS
| DMGL_ANSI
10112 | DMGL_RET_DROP
)));
10115 canon
= demangled
.get ();
10123 if (canon
== NULL
|| check_physname
)
10125 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10127 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10129 /* It may not mean a bug in GDB. The compiler could also
10130 compute DW_AT_linkage_name incorrectly. But in such case
10131 GDB would need to be bug-to-bug compatible. */
10133 complaint (_("Computed physname <%s> does not match demangled <%s> "
10134 "(from linkage <%s>) - DIE at %s [in module %s]"),
10135 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10136 objfile_name (objfile
));
10138 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10139 is available here - over computed PHYSNAME. It is safer
10140 against both buggy GDB and buggy compilers. */
10154 retval
= objfile
->intern (retval
);
10159 /* Inspect DIE in CU for a namespace alias. If one exists, record
10160 a new symbol for it.
10162 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10165 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10167 struct attribute
*attr
;
10169 /* If the die does not have a name, this is not a namespace
10171 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10175 struct die_info
*d
= die
;
10176 struct dwarf2_cu
*imported_cu
= cu
;
10178 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10179 keep inspecting DIEs until we hit the underlying import. */
10180 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10181 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10183 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10187 d
= follow_die_ref (d
, attr
, &imported_cu
);
10188 if (d
->tag
!= DW_TAG_imported_declaration
)
10192 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10194 complaint (_("DIE at %s has too many recursively imported "
10195 "declarations"), sect_offset_str (d
->sect_off
));
10202 sect_offset sect_off
= attr
->get_ref_die_offset ();
10204 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10205 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10207 /* This declaration is a global namespace alias. Add
10208 a symbol for it whose type is the aliased namespace. */
10209 new_symbol (die
, type
, cu
);
10218 /* Return the using directives repository (global or local?) to use in the
10219 current context for CU.
10221 For Ada, imported declarations can materialize renamings, which *may* be
10222 global. However it is impossible (for now?) in DWARF to distinguish
10223 "external" imported declarations and "static" ones. As all imported
10224 declarations seem to be static in all other languages, make them all CU-wide
10225 global only in Ada. */
10227 static struct using_direct
**
10228 using_directives (struct dwarf2_cu
*cu
)
10230 if (cu
->per_cu
->lang
== language_ada
10231 && cu
->get_builder ()->outermost_context_p ())
10232 return cu
->get_builder ()->get_global_using_directives ();
10234 return cu
->get_builder ()->get_local_using_directives ();
10237 /* Read the import statement specified by the given die and record it. */
10240 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10242 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10243 struct attribute
*import_attr
;
10244 struct die_info
*imported_die
, *child_die
;
10245 struct dwarf2_cu
*imported_cu
;
10246 const char *imported_name
;
10247 const char *imported_name_prefix
;
10248 const char *canonical_name
;
10249 const char *import_alias
;
10250 const char *imported_declaration
= NULL
;
10251 const char *import_prefix
;
10252 std::vector
<const char *> excludes
;
10254 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10255 if (import_attr
== NULL
)
10257 complaint (_("Tag '%s' has no DW_AT_import"),
10258 dwarf_tag_name (die
->tag
));
10263 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10264 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10265 if (imported_name
== NULL
)
10267 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10269 The import in the following code:
10283 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10284 <52> DW_AT_decl_file : 1
10285 <53> DW_AT_decl_line : 6
10286 <54> DW_AT_import : <0x75>
10287 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10288 <59> DW_AT_name : B
10289 <5b> DW_AT_decl_file : 1
10290 <5c> DW_AT_decl_line : 2
10291 <5d> DW_AT_type : <0x6e>
10293 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10294 <76> DW_AT_byte_size : 4
10295 <77> DW_AT_encoding : 5 (signed)
10297 imports the wrong die ( 0x75 instead of 0x58 ).
10298 This case will be ignored until the gcc bug is fixed. */
10302 /* Figure out the local name after import. */
10303 import_alias
= dwarf2_name (die
, cu
);
10305 /* Figure out where the statement is being imported to. */
10306 import_prefix
= determine_prefix (die
, cu
);
10308 /* Figure out what the scope of the imported die is and prepend it
10309 to the name of the imported die. */
10310 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10312 if (imported_die
->tag
!= DW_TAG_namespace
10313 && imported_die
->tag
!= DW_TAG_module
)
10315 imported_declaration
= imported_name
;
10316 canonical_name
= imported_name_prefix
;
10318 else if (strlen (imported_name_prefix
) > 0)
10319 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10320 imported_name_prefix
,
10321 (cu
->per_cu
->lang
== language_d
10324 imported_name
, (char *) NULL
);
10326 canonical_name
= imported_name
;
10328 if (die
->tag
== DW_TAG_imported_module
10329 && cu
->per_cu
->lang
== language_fortran
)
10330 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10331 child_die
= child_die
->sibling
)
10333 /* DWARF-4: A Fortran use statement with a “rename list” may be
10334 represented by an imported module entry with an import attribute
10335 referring to the module and owned entries corresponding to those
10336 entities that are renamed as part of being imported. */
10338 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10340 complaint (_("child DW_TAG_imported_declaration expected "
10341 "- DIE at %s [in module %s]"),
10342 sect_offset_str (child_die
->sect_off
),
10343 objfile_name (objfile
));
10347 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10348 if (import_attr
== NULL
)
10350 complaint (_("Tag '%s' has no DW_AT_import"),
10351 dwarf_tag_name (child_die
->tag
));
10356 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10358 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10359 if (imported_name
== NULL
)
10361 complaint (_("child DW_TAG_imported_declaration has unknown "
10362 "imported name - DIE at %s [in module %s]"),
10363 sect_offset_str (child_die
->sect_off
),
10364 objfile_name (objfile
));
10368 excludes
.push_back (imported_name
);
10370 process_die (child_die
, cu
);
10373 add_using_directive (using_directives (cu
),
10377 imported_declaration
,
10380 &objfile
->objfile_obstack
);
10383 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10384 types, but gives them a size of zero. Starting with version 14,
10385 ICC is compatible with GCC. */
10388 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10390 if (!cu
->checked_producer
)
10391 check_producer (cu
);
10393 return cu
->producer_is_icc_lt_14
;
10396 /* ICC generates a DW_AT_type for C void functions. This was observed on
10397 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10398 which says that void functions should not have a DW_AT_type. */
10401 producer_is_icc (struct dwarf2_cu
*cu
)
10403 if (!cu
->checked_producer
)
10404 check_producer (cu
);
10406 return cu
->producer_is_icc
;
10409 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10410 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10411 this, it was first present in GCC release 4.3.0. */
10414 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10416 if (!cu
->checked_producer
)
10417 check_producer (cu
);
10419 return cu
->producer_is_gcc_lt_4_3
;
10422 static file_and_directory
10423 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10425 file_and_directory res
;
10427 /* Find the filename. Do not use dwarf2_name here, since the filename
10428 is not a source language identifier. */
10429 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10430 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10432 if (res
.comp_dir
== NULL
10433 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10434 && IS_ABSOLUTE_PATH (res
.name
))
10436 res
.comp_dir_storage
= ldirname (res
.name
);
10437 if (!res
.comp_dir_storage
.empty ())
10438 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10440 if (res
.comp_dir
!= NULL
)
10442 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10443 directory, get rid of it. */
10444 const char *cp
= strchr (res
.comp_dir
, ':');
10446 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10447 res
.comp_dir
= cp
+ 1;
10450 if (res
.name
== NULL
)
10451 res
.name
= "<unknown>";
10456 /* Handle DW_AT_stmt_list for a compilation unit.
10457 DIE is the DW_TAG_compile_unit die for CU.
10458 COMP_DIR is the compilation directory. LOWPC is passed to
10459 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10462 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10463 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10465 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10466 struct attribute
*attr
;
10467 struct line_header line_header_local
;
10468 hashval_t line_header_local_hash
;
10470 int decode_mapping
;
10472 gdb_assert (! cu
->per_cu
->is_debug_types
);
10474 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10475 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10478 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10480 /* The line header hash table is only created if needed (it exists to
10481 prevent redundant reading of the line table for partial_units).
10482 If we're given a partial_unit, we'll need it. If we're given a
10483 compile_unit, then use the line header hash table if it's already
10484 created, but don't create one just yet. */
10486 if (per_objfile
->line_header_hash
== NULL
10487 && die
->tag
== DW_TAG_partial_unit
)
10489 per_objfile
->line_header_hash
10490 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10491 line_header_eq_voidp
,
10492 htab_delete_entry
<line_header
>,
10496 line_header_local
.sect_off
= line_offset
;
10497 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10498 line_header_local_hash
= line_header_hash (&line_header_local
);
10499 if (per_objfile
->line_header_hash
!= NULL
)
10501 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10502 &line_header_local
,
10503 line_header_local_hash
, NO_INSERT
);
10505 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10506 is not present in *SLOT (since if there is something in *SLOT then
10507 it will be for a partial_unit). */
10508 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10510 gdb_assert (*slot
!= NULL
);
10511 cu
->line_header
= (struct line_header
*) *slot
;
10516 /* dwarf_decode_line_header does not yet provide sufficient information.
10517 We always have to call also dwarf_decode_lines for it. */
10518 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10522 cu
->line_header
= lh
.release ();
10523 cu
->line_header_die_owner
= die
;
10525 if (per_objfile
->line_header_hash
== NULL
)
10529 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10530 &line_header_local
,
10531 line_header_local_hash
, INSERT
);
10532 gdb_assert (slot
!= NULL
);
10534 if (slot
!= NULL
&& *slot
== NULL
)
10536 /* This newly decoded line number information unit will be owned
10537 by line_header_hash hash table. */
10538 *slot
= cu
->line_header
;
10539 cu
->line_header_die_owner
= NULL
;
10543 /* We cannot free any current entry in (*slot) as that struct line_header
10544 may be already used by multiple CUs. Create only temporary decoded
10545 line_header for this CU - it may happen at most once for each line
10546 number information unit. And if we're not using line_header_hash
10547 then this is what we want as well. */
10548 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10550 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10551 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10556 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10559 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10561 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10562 struct objfile
*objfile
= per_objfile
->objfile
;
10563 struct gdbarch
*gdbarch
= objfile
->arch ();
10564 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10565 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10566 struct attribute
*attr
;
10567 struct die_info
*child_die
;
10568 CORE_ADDR baseaddr
;
10570 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10571 baseaddr
= objfile
->text_section_offset ();
10573 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10575 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10576 from finish_block. */
10577 if (lowpc
== ((CORE_ADDR
) -1))
10579 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10581 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10583 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10585 gdb_assert (per_objfile
->sym_cu
== nullptr);
10586 scoped_restore restore_sym_cu
10587 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10589 /* Decode line number information if present. We do this before
10590 processing child DIEs, so that the line header table is available
10591 for DW_AT_decl_file. */
10592 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10594 /* Process all dies in compilation unit. */
10595 if (die
->child
!= NULL
)
10597 child_die
= die
->child
;
10598 while (child_die
&& child_die
->tag
)
10600 process_die (child_die
, cu
);
10601 child_die
= child_die
->sibling
;
10604 per_objfile
->sym_cu
= nullptr;
10606 /* Decode macro information, if present. Dwarf 2 macro information
10607 refers to information in the line number info statement program
10608 header, so we can only read it if we've read the header
10610 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10612 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10613 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10615 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10616 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10618 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10622 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10623 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10625 unsigned int macro_offset
= attr
->as_unsigned ();
10627 dwarf_decode_macros (cu
, macro_offset
, 0);
10633 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10635 struct type_unit_group
*tu_group
;
10637 struct attribute
*attr
;
10639 struct signatured_type
*sig_type
;
10641 gdb_assert (per_cu
->is_debug_types
);
10642 sig_type
= (struct signatured_type
*) per_cu
;
10644 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10646 /* If we're using .gdb_index (includes -readnow) then
10647 per_cu->type_unit_group may not have been set up yet. */
10648 if (sig_type
->type_unit_group
== NULL
)
10649 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10650 tu_group
= sig_type
->type_unit_group
;
10652 /* If we've already processed this stmt_list there's no real need to
10653 do it again, we could fake it and just recreate the part we need
10654 (file name,index -> symtab mapping). If data shows this optimization
10655 is useful we can do it then. */
10656 type_unit_group_unshareable
*tug_unshare
10657 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10658 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10660 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10663 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10665 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10666 lh
= dwarf_decode_line_header (line_offset
, this);
10671 start_symtab ("", NULL
, 0);
10674 gdb_assert (tug_unshare
->symtabs
== NULL
);
10675 gdb_assert (m_builder
== nullptr);
10676 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10677 m_builder
.reset (new struct buildsym_compunit
10678 (COMPUNIT_OBJFILE (cust
), "",
10679 COMPUNIT_DIRNAME (cust
),
10680 compunit_language (cust
),
10682 list_in_scope
= get_builder ()->get_file_symbols ();
10687 line_header
= lh
.release ();
10688 line_header_die_owner
= die
;
10692 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10694 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10695 still initializing it, and our caller (a few levels up)
10696 process_full_type_unit still needs to know if this is the first
10699 tug_unshare
->symtabs
10700 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10701 struct symtab
*, line_header
->file_names_size ());
10703 auto &file_names
= line_header
->file_names ();
10704 for (i
= 0; i
< file_names
.size (); ++i
)
10706 file_entry
&fe
= file_names
[i
];
10707 dwarf2_start_subfile (this, fe
.name
,
10708 fe
.include_dir (line_header
));
10709 buildsym_compunit
*b
= get_builder ();
10710 if (b
->get_current_subfile ()->symtab
== NULL
)
10712 /* NOTE: start_subfile will recognize when it's been
10713 passed a file it has already seen. So we can't
10714 assume there's a simple mapping from
10715 cu->line_header->file_names to subfiles, plus
10716 cu->line_header->file_names may contain dups. */
10717 b
->get_current_subfile ()->symtab
10718 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10721 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10722 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10727 gdb_assert (m_builder
== nullptr);
10728 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10729 m_builder
.reset (new struct buildsym_compunit
10730 (COMPUNIT_OBJFILE (cust
), "",
10731 COMPUNIT_DIRNAME (cust
),
10732 compunit_language (cust
),
10734 list_in_scope
= get_builder ()->get_file_symbols ();
10736 auto &file_names
= line_header
->file_names ();
10737 for (i
= 0; i
< file_names
.size (); ++i
)
10739 file_entry
&fe
= file_names
[i
];
10740 fe
.symtab
= tug_unshare
->symtabs
[i
];
10744 /* The main symtab is allocated last. Type units don't have DW_AT_name
10745 so they don't have a "real" (so to speak) symtab anyway.
10746 There is later code that will assign the main symtab to all symbols
10747 that don't have one. We need to handle the case of a symbol with a
10748 missing symtab (DW_AT_decl_file) anyway. */
10751 /* Process DW_TAG_type_unit.
10752 For TUs we want to skip the first top level sibling if it's not the
10753 actual type being defined by this TU. In this case the first top
10754 level sibling is there to provide context only. */
10757 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10759 struct die_info
*child_die
;
10761 prepare_one_comp_unit (cu
, die
, language_minimal
);
10763 /* Initialize (or reinitialize) the machinery for building symtabs.
10764 We do this before processing child DIEs, so that the line header table
10765 is available for DW_AT_decl_file. */
10766 cu
->setup_type_unit_groups (die
);
10768 if (die
->child
!= NULL
)
10770 child_die
= die
->child
;
10771 while (child_die
&& child_die
->tag
)
10773 process_die (child_die
, cu
);
10774 child_die
= child_die
->sibling
;
10781 http://gcc.gnu.org/wiki/DebugFission
10782 http://gcc.gnu.org/wiki/DebugFissionDWP
10784 To simplify handling of both DWO files ("object" files with the DWARF info)
10785 and DWP files (a file with the DWOs packaged up into one file), we treat
10786 DWP files as having a collection of virtual DWO files. */
10789 hash_dwo_file (const void *item
)
10791 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10794 hash
= htab_hash_string (dwo_file
->dwo_name
);
10795 if (dwo_file
->comp_dir
!= NULL
)
10796 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10801 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10803 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10804 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10806 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10808 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10809 return lhs
->comp_dir
== rhs
->comp_dir
;
10810 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10813 /* Allocate a hash table for DWO files. */
10816 allocate_dwo_file_hash_table ()
10818 return htab_up (htab_create_alloc (41,
10821 htab_delete_entry
<dwo_file
>,
10825 /* Lookup DWO file DWO_NAME. */
10828 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10829 const char *dwo_name
,
10830 const char *comp_dir
)
10832 struct dwo_file find_entry
;
10835 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10836 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10838 find_entry
.dwo_name
= dwo_name
;
10839 find_entry
.comp_dir
= comp_dir
;
10840 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10847 hash_dwo_unit (const void *item
)
10849 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10851 /* This drops the top 32 bits of the id, but is ok for a hash. */
10852 return dwo_unit
->signature
;
10856 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10858 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10859 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10861 /* The signature is assumed to be unique within the DWO file.
10862 So while object file CU dwo_id's always have the value zero,
10863 that's OK, assuming each object file DWO file has only one CU,
10864 and that's the rule for now. */
10865 return lhs
->signature
== rhs
->signature
;
10868 /* Allocate a hash table for DWO CUs,TUs.
10869 There is one of these tables for each of CUs,TUs for each DWO file. */
10872 allocate_dwo_unit_table ()
10874 /* Start out with a pretty small number.
10875 Generally DWO files contain only one CU and maybe some TUs. */
10876 return htab_up (htab_create_alloc (3,
10879 NULL
, xcalloc
, xfree
));
10882 /* die_reader_func for create_dwo_cu. */
10885 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10886 const gdb_byte
*info_ptr
,
10887 struct die_info
*comp_unit_die
,
10888 struct dwo_file
*dwo_file
,
10889 struct dwo_unit
*dwo_unit
)
10891 struct dwarf2_cu
*cu
= reader
->cu
;
10892 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10893 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10895 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10896 if (!signature
.has_value ())
10898 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10899 " its dwo_id [in module %s]"),
10900 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10904 dwo_unit
->dwo_file
= dwo_file
;
10905 dwo_unit
->signature
= *signature
;
10906 dwo_unit
->section
= section
;
10907 dwo_unit
->sect_off
= sect_off
;
10908 dwo_unit
->length
= cu
->per_cu
->length
;
10910 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10911 sect_offset_str (sect_off
),
10912 hex_string (dwo_unit
->signature
));
10915 /* Create the dwo_units for the CUs in a DWO_FILE.
10916 Note: This function processes DWO files only, not DWP files. */
10919 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10920 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10921 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10923 struct objfile
*objfile
= per_objfile
->objfile
;
10924 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10925 const gdb_byte
*info_ptr
, *end_ptr
;
10927 section
.read (objfile
);
10928 info_ptr
= section
.buffer
;
10930 if (info_ptr
== NULL
)
10933 dwarf_read_debug_printf ("Reading %s for %s:",
10934 section
.get_name (),
10935 section
.get_file_name ());
10937 end_ptr
= info_ptr
+ section
.size
;
10938 while (info_ptr
< end_ptr
)
10940 struct dwarf2_per_cu_data per_cu
;
10941 struct dwo_unit read_unit
{};
10942 struct dwo_unit
*dwo_unit
;
10944 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10946 per_cu
.per_bfd
= per_bfd
;
10947 per_cu
.is_debug_types
= 0;
10948 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10949 per_cu
.section
= §ion
;
10951 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10952 if (!reader
.dummy_p
)
10953 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10954 &dwo_file
, &read_unit
);
10955 info_ptr
+= per_cu
.length
;
10957 // If the unit could not be parsed, skip it.
10958 if (read_unit
.dwo_file
== NULL
)
10961 if (cus_htab
== NULL
)
10962 cus_htab
= allocate_dwo_unit_table ();
10964 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
10966 *dwo_unit
= read_unit
;
10967 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
10968 gdb_assert (slot
!= NULL
);
10971 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10972 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10974 complaint (_("debug cu entry at offset %s is duplicate to"
10975 " the entry at offset %s, signature %s"),
10976 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
10977 hex_string (dwo_unit
->signature
));
10979 *slot
= (void *)dwo_unit
;
10983 /* DWP file .debug_{cu,tu}_index section format:
10984 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10985 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10987 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10988 officially standard DWP format was published with DWARF v5 and is called
10989 Version 5. There are no versions 3 or 4.
10993 Both index sections have the same format, and serve to map a 64-bit
10994 signature to a set of section numbers. Each section begins with a header,
10995 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10996 indexes, and a pool of 32-bit section numbers. The index sections will be
10997 aligned at 8-byte boundaries in the file.
10999 The index section header consists of:
11001 V, 32 bit version number
11003 N, 32 bit number of compilation units or type units in the index
11004 M, 32 bit number of slots in the hash table
11006 Numbers are recorded using the byte order of the application binary.
11008 The hash table begins at offset 16 in the section, and consists of an array
11009 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11010 order of the application binary). Unused slots in the hash table are 0.
11011 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11013 The parallel table begins immediately after the hash table
11014 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11015 array of 32-bit indexes (using the byte order of the application binary),
11016 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11017 table contains a 32-bit index into the pool of section numbers. For unused
11018 hash table slots, the corresponding entry in the parallel table will be 0.
11020 The pool of section numbers begins immediately following the hash table
11021 (at offset 16 + 12 * M from the beginning of the section). The pool of
11022 section numbers consists of an array of 32-bit words (using the byte order
11023 of the application binary). Each item in the array is indexed starting
11024 from 0. The hash table entry provides the index of the first section
11025 number in the set. Additional section numbers in the set follow, and the
11026 set is terminated by a 0 entry (section number 0 is not used in ELF).
11028 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11029 section must be the first entry in the set, and the .debug_abbrev.dwo must
11030 be the second entry. Other members of the set may follow in any order.
11034 DWP Versions 2 and 5:
11036 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11037 and the entries in the index tables are now offsets into these sections.
11038 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11041 Index Section Contents:
11043 Hash Table of Signatures dwp_hash_table.hash_table
11044 Parallel Table of Indices dwp_hash_table.unit_table
11045 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11046 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11048 The index section header consists of:
11050 V, 32 bit version number
11051 L, 32 bit number of columns in the table of section offsets
11052 N, 32 bit number of compilation units or type units in the index
11053 M, 32 bit number of slots in the hash table
11055 Numbers are recorded using the byte order of the application binary.
11057 The hash table has the same format as version 1.
11058 The parallel table of indices has the same format as version 1,
11059 except that the entries are origin-1 indices into the table of sections
11060 offsets and the table of section sizes.
11062 The table of offsets begins immediately following the parallel table
11063 (at offset 16 + 12 * M from the beginning of the section). The table is
11064 a two-dimensional array of 32-bit words (using the byte order of the
11065 application binary), with L columns and N+1 rows, in row-major order.
11066 Each row in the array is indexed starting from 0. The first row provides
11067 a key to the remaining rows: each column in this row provides an identifier
11068 for a debug section, and the offsets in the same column of subsequent rows
11069 refer to that section. The section identifiers for Version 2 are:
11071 DW_SECT_INFO 1 .debug_info.dwo
11072 DW_SECT_TYPES 2 .debug_types.dwo
11073 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11074 DW_SECT_LINE 4 .debug_line.dwo
11075 DW_SECT_LOC 5 .debug_loc.dwo
11076 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11077 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11078 DW_SECT_MACRO 8 .debug_macro.dwo
11080 The section identifiers for Version 5 are:
11082 DW_SECT_INFO_V5 1 .debug_info.dwo
11083 DW_SECT_RESERVED_V5 2 --
11084 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11085 DW_SECT_LINE_V5 4 .debug_line.dwo
11086 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11087 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11088 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11089 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11091 The offsets provided by the CU and TU index sections are the base offsets
11092 for the contributions made by each CU or TU to the corresponding section
11093 in the package file. Each CU and TU header contains an abbrev_offset
11094 field, used to find the abbreviations table for that CU or TU within the
11095 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11096 be interpreted as relative to the base offset given in the index section.
11097 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11098 should be interpreted as relative to the base offset for .debug_line.dwo,
11099 and offsets into other debug sections obtained from DWARF attributes should
11100 also be interpreted as relative to the corresponding base offset.
11102 The table of sizes begins immediately following the table of offsets.
11103 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11104 with L columns and N rows, in row-major order. Each row in the array is
11105 indexed starting from 1 (row 0 is shared by the two tables).
11109 Hash table lookup is handled the same in version 1 and 2:
11111 We assume that N and M will not exceed 2^32 - 1.
11112 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11114 Given a 64-bit compilation unit signature or a type signature S, an entry
11115 in the hash table is located as follows:
11117 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11118 the low-order k bits all set to 1.
11120 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11122 3) If the hash table entry at index H matches the signature, use that
11123 entry. If the hash table entry at index H is unused (all zeroes),
11124 terminate the search: the signature is not present in the table.
11126 4) Let H = (H + H') modulo M. Repeat at Step 3.
11128 Because M > N and H' and M are relatively prime, the search is guaranteed
11129 to stop at an unused slot or find the match. */
11131 /* Create a hash table to map DWO IDs to their CU/TU entry in
11132 .debug_{info,types}.dwo in DWP_FILE.
11133 Returns NULL if there isn't one.
11134 Note: This function processes DWP files only, not DWO files. */
11136 static struct dwp_hash_table
*
11137 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11138 struct dwp_file
*dwp_file
, int is_debug_types
)
11140 struct objfile
*objfile
= per_objfile
->objfile
;
11141 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11142 const gdb_byte
*index_ptr
, *index_end
;
11143 struct dwarf2_section_info
*index
;
11144 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11145 struct dwp_hash_table
*htab
;
11147 if (is_debug_types
)
11148 index
= &dwp_file
->sections
.tu_index
;
11150 index
= &dwp_file
->sections
.cu_index
;
11152 if (index
->empty ())
11154 index
->read (objfile
);
11156 index_ptr
= index
->buffer
;
11157 index_end
= index_ptr
+ index
->size
;
11159 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11160 For now it's safe to just read 4 bytes (particularly as it's difficult to
11161 tell if you're dealing with Version 5 before you've read the version). */
11162 version
= read_4_bytes (dbfd
, index_ptr
);
11164 if (version
== 2 || version
== 5)
11165 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11169 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11171 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11174 if (version
!= 1 && version
!= 2 && version
!= 5)
11176 error (_("Dwarf Error: unsupported DWP file version (%s)"
11177 " [in module %s]"),
11178 pulongest (version
), dwp_file
->name
);
11180 if (nr_slots
!= (nr_slots
& -nr_slots
))
11182 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11183 " is not power of 2 [in module %s]"),
11184 pulongest (nr_slots
), dwp_file
->name
);
11187 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11188 htab
->version
= version
;
11189 htab
->nr_columns
= nr_columns
;
11190 htab
->nr_units
= nr_units
;
11191 htab
->nr_slots
= nr_slots
;
11192 htab
->hash_table
= index_ptr
;
11193 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11195 /* Exit early if the table is empty. */
11196 if (nr_slots
== 0 || nr_units
== 0
11197 || (version
== 2 && nr_columns
== 0)
11198 || (version
== 5 && nr_columns
== 0))
11200 /* All must be zero. */
11201 if (nr_slots
!= 0 || nr_units
!= 0
11202 || (version
== 2 && nr_columns
!= 0)
11203 || (version
== 5 && nr_columns
!= 0))
11205 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11206 " all zero [in modules %s]"),
11214 htab
->section_pool
.v1
.indices
=
11215 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11216 /* It's harder to decide whether the section is too small in v1.
11217 V1 is deprecated anyway so we punt. */
11219 else if (version
== 2)
11221 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11222 int *ids
= htab
->section_pool
.v2
.section_ids
;
11223 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11224 /* Reverse map for error checking. */
11225 int ids_seen
[DW_SECT_MAX
+ 1];
11228 if (nr_columns
< 2)
11230 error (_("Dwarf Error: bad DWP hash table, too few columns"
11231 " in section table [in module %s]"),
11234 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11236 error (_("Dwarf Error: bad DWP hash table, too many columns"
11237 " in section table [in module %s]"),
11240 memset (ids
, 255, sizeof_ids
);
11241 memset (ids_seen
, 255, sizeof (ids_seen
));
11242 for (i
= 0; i
< nr_columns
; ++i
)
11244 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11246 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11248 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11249 " in section table [in module %s]"),
11250 id
, dwp_file
->name
);
11252 if (ids_seen
[id
] != -1)
11254 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11255 " id %d in section table [in module %s]"),
11256 id
, dwp_file
->name
);
11261 /* Must have exactly one info or types section. */
11262 if (((ids_seen
[DW_SECT_INFO
] != -1)
11263 + (ids_seen
[DW_SECT_TYPES
] != -1))
11266 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11267 " DWO info/types section [in module %s]"),
11270 /* Must have an abbrev section. */
11271 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11273 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11274 " section [in module %s]"),
11277 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11278 htab
->section_pool
.v2
.sizes
=
11279 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11280 * nr_units
* nr_columns
);
11281 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11282 * nr_units
* nr_columns
))
11285 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11286 " [in module %s]"),
11290 else /* version == 5 */
11292 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11293 int *ids
= htab
->section_pool
.v5
.section_ids
;
11294 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11295 /* Reverse map for error checking. */
11296 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11298 if (nr_columns
< 2)
11300 error (_("Dwarf Error: bad DWP hash table, too few columns"
11301 " in section table [in module %s]"),
11304 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11306 error (_("Dwarf Error: bad DWP hash table, too many columns"
11307 " in section table [in module %s]"),
11310 memset (ids
, 255, sizeof_ids
);
11311 memset (ids_seen
, 255, sizeof (ids_seen
));
11312 for (int i
= 0; i
< nr_columns
; ++i
)
11314 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11316 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11318 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11319 " in section table [in module %s]"),
11320 id
, dwp_file
->name
);
11322 if (ids_seen
[id
] != -1)
11324 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11325 " id %d in section table [in module %s]"),
11326 id
, dwp_file
->name
);
11331 /* Must have seen an info section. */
11332 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11334 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11335 " DWO info/types section [in module %s]"),
11338 /* Must have an abbrev section. */
11339 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11341 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11342 " section [in module %s]"),
11345 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11346 htab
->section_pool
.v5
.sizes
11347 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11348 * nr_units
* nr_columns
);
11349 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11350 * nr_units
* nr_columns
))
11353 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11354 " [in module %s]"),
11362 /* Update SECTIONS with the data from SECTP.
11364 This function is like the other "locate" section routines, but in
11365 this context the sections to read comes from the DWP V1 hash table,
11366 not the full ELF section table.
11368 The result is non-zero for success, or zero if an error was found. */
11371 locate_v1_virtual_dwo_sections (asection
*sectp
,
11372 struct virtual_v1_dwo_sections
*sections
)
11374 const struct dwop_section_names
*names
= &dwop_section_names
;
11376 if (names
->abbrev_dwo
.matches (sectp
->name
))
11378 /* There can be only one. */
11379 if (sections
->abbrev
.s
.section
!= NULL
)
11381 sections
->abbrev
.s
.section
= sectp
;
11382 sections
->abbrev
.size
= bfd_section_size (sectp
);
11384 else if (names
->info_dwo
.matches (sectp
->name
)
11385 || names
->types_dwo
.matches (sectp
->name
))
11387 /* There can be only one. */
11388 if (sections
->info_or_types
.s
.section
!= NULL
)
11390 sections
->info_or_types
.s
.section
= sectp
;
11391 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11393 else if (names
->line_dwo
.matches (sectp
->name
))
11395 /* There can be only one. */
11396 if (sections
->line
.s
.section
!= NULL
)
11398 sections
->line
.s
.section
= sectp
;
11399 sections
->line
.size
= bfd_section_size (sectp
);
11401 else if (names
->loc_dwo
.matches (sectp
->name
))
11403 /* There can be only one. */
11404 if (sections
->loc
.s
.section
!= NULL
)
11406 sections
->loc
.s
.section
= sectp
;
11407 sections
->loc
.size
= bfd_section_size (sectp
);
11409 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11411 /* There can be only one. */
11412 if (sections
->macinfo
.s
.section
!= NULL
)
11414 sections
->macinfo
.s
.section
= sectp
;
11415 sections
->macinfo
.size
= bfd_section_size (sectp
);
11417 else if (names
->macro_dwo
.matches (sectp
->name
))
11419 /* There can be only one. */
11420 if (sections
->macro
.s
.section
!= NULL
)
11422 sections
->macro
.s
.section
= sectp
;
11423 sections
->macro
.size
= bfd_section_size (sectp
);
11425 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11427 /* There can be only one. */
11428 if (sections
->str_offsets
.s
.section
!= NULL
)
11430 sections
->str_offsets
.s
.section
= sectp
;
11431 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11435 /* No other kind of section is valid. */
11442 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11443 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11444 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11445 This is for DWP version 1 files. */
11447 static struct dwo_unit
*
11448 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11449 struct dwp_file
*dwp_file
,
11450 uint32_t unit_index
,
11451 const char *comp_dir
,
11452 ULONGEST signature
, int is_debug_types
)
11454 const struct dwp_hash_table
*dwp_htab
=
11455 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11456 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11457 const char *kind
= is_debug_types
? "TU" : "CU";
11458 struct dwo_file
*dwo_file
;
11459 struct dwo_unit
*dwo_unit
;
11460 struct virtual_v1_dwo_sections sections
;
11461 void **dwo_file_slot
;
11464 gdb_assert (dwp_file
->version
== 1);
11466 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11467 kind
, pulongest (unit_index
), hex_string (signature
),
11470 /* Fetch the sections of this DWO unit.
11471 Put a limit on the number of sections we look for so that bad data
11472 doesn't cause us to loop forever. */
11474 #define MAX_NR_V1_DWO_SECTIONS \
11475 (1 /* .debug_info or .debug_types */ \
11476 + 1 /* .debug_abbrev */ \
11477 + 1 /* .debug_line */ \
11478 + 1 /* .debug_loc */ \
11479 + 1 /* .debug_str_offsets */ \
11480 + 1 /* .debug_macro or .debug_macinfo */ \
11481 + 1 /* trailing zero */)
11483 memset (§ions
, 0, sizeof (sections
));
11485 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11488 uint32_t section_nr
=
11489 read_4_bytes (dbfd
,
11490 dwp_htab
->section_pool
.v1
.indices
11491 + (unit_index
+ i
) * sizeof (uint32_t));
11493 if (section_nr
== 0)
11495 if (section_nr
>= dwp_file
->num_sections
)
11497 error (_("Dwarf Error: bad DWP hash table, section number too large"
11498 " [in module %s]"),
11502 sectp
= dwp_file
->elf_sections
[section_nr
];
11503 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11505 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11506 " [in module %s]"),
11512 || sections
.info_or_types
.empty ()
11513 || sections
.abbrev
.empty ())
11515 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11516 " [in module %s]"),
11519 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11521 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11522 " [in module %s]"),
11526 /* It's easier for the rest of the code if we fake a struct dwo_file and
11527 have dwo_unit "live" in that. At least for now.
11529 The DWP file can be made up of a random collection of CUs and TUs.
11530 However, for each CU + set of TUs that came from the same original DWO
11531 file, we can combine them back into a virtual DWO file to save space
11532 (fewer struct dwo_file objects to allocate). Remember that for really
11533 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11535 std::string virtual_dwo_name
=
11536 string_printf ("virtual-dwo/%d-%d-%d-%d",
11537 sections
.abbrev
.get_id (),
11538 sections
.line
.get_id (),
11539 sections
.loc
.get_id (),
11540 sections
.str_offsets
.get_id ());
11541 /* Can we use an existing virtual DWO file? */
11542 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11544 /* Create one if necessary. */
11545 if (*dwo_file_slot
== NULL
)
11547 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11548 virtual_dwo_name
.c_str ());
11550 dwo_file
= new struct dwo_file
;
11551 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11552 dwo_file
->comp_dir
= comp_dir
;
11553 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11554 dwo_file
->sections
.line
= sections
.line
;
11555 dwo_file
->sections
.loc
= sections
.loc
;
11556 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11557 dwo_file
->sections
.macro
= sections
.macro
;
11558 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11559 /* The "str" section is global to the entire DWP file. */
11560 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11561 /* The info or types section is assigned below to dwo_unit,
11562 there's no need to record it in dwo_file.
11563 Also, we can't simply record type sections in dwo_file because
11564 we record a pointer into the vector in dwo_unit. As we collect more
11565 types we'll grow the vector and eventually have to reallocate space
11566 for it, invalidating all copies of pointers into the previous
11568 *dwo_file_slot
= dwo_file
;
11572 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11573 virtual_dwo_name
.c_str ());
11575 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11578 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11579 dwo_unit
->dwo_file
= dwo_file
;
11580 dwo_unit
->signature
= signature
;
11581 dwo_unit
->section
=
11582 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11583 *dwo_unit
->section
= sections
.info_or_types
;
11584 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11589 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11590 simplify them. Given a pointer to the containing section SECTION, and
11591 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11592 virtual section of just that piece. */
11594 static struct dwarf2_section_info
11595 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11596 struct dwarf2_section_info
*section
,
11597 bfd_size_type offset
, bfd_size_type size
)
11599 struct dwarf2_section_info result
;
11602 gdb_assert (section
!= NULL
);
11603 gdb_assert (!section
->is_virtual
);
11605 memset (&result
, 0, sizeof (result
));
11606 result
.s
.containing_section
= section
;
11607 result
.is_virtual
= true;
11612 sectp
= section
->get_bfd_section ();
11614 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11615 bounds of the real section. This is a pretty-rare event, so just
11616 flag an error (easier) instead of a warning and trying to cope. */
11618 || offset
+ size
> bfd_section_size (sectp
))
11620 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11621 " in section %s [in module %s]"),
11622 sectp
? bfd_section_name (sectp
) : "<unknown>",
11623 objfile_name (per_objfile
->objfile
));
11626 result
.virtual_offset
= offset
;
11627 result
.size
= size
;
11631 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11632 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11633 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11634 This is for DWP version 2 files. */
11636 static struct dwo_unit
*
11637 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11638 struct dwp_file
*dwp_file
,
11639 uint32_t unit_index
,
11640 const char *comp_dir
,
11641 ULONGEST signature
, int is_debug_types
)
11643 const struct dwp_hash_table
*dwp_htab
=
11644 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11645 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11646 const char *kind
= is_debug_types
? "TU" : "CU";
11647 struct dwo_file
*dwo_file
;
11648 struct dwo_unit
*dwo_unit
;
11649 struct virtual_v2_or_v5_dwo_sections sections
;
11650 void **dwo_file_slot
;
11653 gdb_assert (dwp_file
->version
== 2);
11655 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11656 kind
, pulongest (unit_index
), hex_string (signature
),
11659 /* Fetch the section offsets of this DWO unit. */
11661 memset (§ions
, 0, sizeof (sections
));
11663 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11665 uint32_t offset
= read_4_bytes (dbfd
,
11666 dwp_htab
->section_pool
.v2
.offsets
11667 + (((unit_index
- 1) * dwp_htab
->nr_columns
11669 * sizeof (uint32_t)));
11670 uint32_t size
= read_4_bytes (dbfd
,
11671 dwp_htab
->section_pool
.v2
.sizes
11672 + (((unit_index
- 1) * dwp_htab
->nr_columns
11674 * sizeof (uint32_t)));
11676 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11679 case DW_SECT_TYPES
:
11680 sections
.info_or_types_offset
= offset
;
11681 sections
.info_or_types_size
= size
;
11683 case DW_SECT_ABBREV
:
11684 sections
.abbrev_offset
= offset
;
11685 sections
.abbrev_size
= size
;
11688 sections
.line_offset
= offset
;
11689 sections
.line_size
= size
;
11692 sections
.loc_offset
= offset
;
11693 sections
.loc_size
= size
;
11695 case DW_SECT_STR_OFFSETS
:
11696 sections
.str_offsets_offset
= offset
;
11697 sections
.str_offsets_size
= size
;
11699 case DW_SECT_MACINFO
:
11700 sections
.macinfo_offset
= offset
;
11701 sections
.macinfo_size
= size
;
11703 case DW_SECT_MACRO
:
11704 sections
.macro_offset
= offset
;
11705 sections
.macro_size
= size
;
11710 /* It's easier for the rest of the code if we fake a struct dwo_file and
11711 have dwo_unit "live" in that. At least for now.
11713 The DWP file can be made up of a random collection of CUs and TUs.
11714 However, for each CU + set of TUs that came from the same original DWO
11715 file, we can combine them back into a virtual DWO file to save space
11716 (fewer struct dwo_file objects to allocate). Remember that for really
11717 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11719 std::string virtual_dwo_name
=
11720 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11721 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11722 (long) (sections
.line_size
? sections
.line_offset
: 0),
11723 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11724 (long) (sections
.str_offsets_size
11725 ? sections
.str_offsets_offset
: 0));
11726 /* Can we use an existing virtual DWO file? */
11727 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11729 /* Create one if necessary. */
11730 if (*dwo_file_slot
== NULL
)
11732 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11733 virtual_dwo_name
.c_str ());
11735 dwo_file
= new struct dwo_file
;
11736 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11737 dwo_file
->comp_dir
= comp_dir
;
11738 dwo_file
->sections
.abbrev
=
11739 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11740 sections
.abbrev_offset
,
11741 sections
.abbrev_size
);
11742 dwo_file
->sections
.line
=
11743 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11744 sections
.line_offset
,
11745 sections
.line_size
);
11746 dwo_file
->sections
.loc
=
11747 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11748 sections
.loc_offset
, sections
.loc_size
);
11749 dwo_file
->sections
.macinfo
=
11750 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11751 sections
.macinfo_offset
,
11752 sections
.macinfo_size
);
11753 dwo_file
->sections
.macro
=
11754 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11755 sections
.macro_offset
,
11756 sections
.macro_size
);
11757 dwo_file
->sections
.str_offsets
=
11758 create_dwp_v2_or_v5_section (per_objfile
,
11759 &dwp_file
->sections
.str_offsets
,
11760 sections
.str_offsets_offset
,
11761 sections
.str_offsets_size
);
11762 /* The "str" section is global to the entire DWP file. */
11763 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11764 /* The info or types section is assigned below to dwo_unit,
11765 there's no need to record it in dwo_file.
11766 Also, we can't simply record type sections in dwo_file because
11767 we record a pointer into the vector in dwo_unit. As we collect more
11768 types we'll grow the vector and eventually have to reallocate space
11769 for it, invalidating all copies of pointers into the previous
11771 *dwo_file_slot
= dwo_file
;
11775 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11776 virtual_dwo_name
.c_str ());
11778 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11781 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11782 dwo_unit
->dwo_file
= dwo_file
;
11783 dwo_unit
->signature
= signature
;
11784 dwo_unit
->section
=
11785 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11786 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11789 ? &dwp_file
->sections
.types
11790 : &dwp_file
->sections
.info
,
11791 sections
.info_or_types_offset
,
11792 sections
.info_or_types_size
);
11793 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11798 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11799 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11800 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11801 This is for DWP version 5 files. */
11803 static struct dwo_unit
*
11804 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11805 struct dwp_file
*dwp_file
,
11806 uint32_t unit_index
,
11807 const char *comp_dir
,
11808 ULONGEST signature
, int is_debug_types
)
11810 const struct dwp_hash_table
*dwp_htab
11811 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11812 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11813 const char *kind
= is_debug_types
? "TU" : "CU";
11814 struct dwo_file
*dwo_file
;
11815 struct dwo_unit
*dwo_unit
;
11816 struct virtual_v2_or_v5_dwo_sections sections
{};
11817 void **dwo_file_slot
;
11819 gdb_assert (dwp_file
->version
== 5);
11821 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11822 kind
, pulongest (unit_index
), hex_string (signature
),
11825 /* Fetch the section offsets of this DWO unit. */
11827 /* memset (§ions, 0, sizeof (sections)); */
11829 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11831 uint32_t offset
= read_4_bytes (dbfd
,
11832 dwp_htab
->section_pool
.v5
.offsets
11833 + (((unit_index
- 1)
11834 * dwp_htab
->nr_columns
11836 * sizeof (uint32_t)));
11837 uint32_t size
= read_4_bytes (dbfd
,
11838 dwp_htab
->section_pool
.v5
.sizes
11839 + (((unit_index
- 1) * dwp_htab
->nr_columns
11841 * sizeof (uint32_t)));
11843 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11845 case DW_SECT_ABBREV_V5
:
11846 sections
.abbrev_offset
= offset
;
11847 sections
.abbrev_size
= size
;
11849 case DW_SECT_INFO_V5
:
11850 sections
.info_or_types_offset
= offset
;
11851 sections
.info_or_types_size
= size
;
11853 case DW_SECT_LINE_V5
:
11854 sections
.line_offset
= offset
;
11855 sections
.line_size
= size
;
11857 case DW_SECT_LOCLISTS_V5
:
11858 sections
.loclists_offset
= offset
;
11859 sections
.loclists_size
= size
;
11861 case DW_SECT_MACRO_V5
:
11862 sections
.macro_offset
= offset
;
11863 sections
.macro_size
= size
;
11865 case DW_SECT_RNGLISTS_V5
:
11866 sections
.rnglists_offset
= offset
;
11867 sections
.rnglists_size
= size
;
11869 case DW_SECT_STR_OFFSETS_V5
:
11870 sections
.str_offsets_offset
= offset
;
11871 sections
.str_offsets_size
= size
;
11873 case DW_SECT_RESERVED_V5
:
11879 /* It's easier for the rest of the code if we fake a struct dwo_file and
11880 have dwo_unit "live" in that. At least for now.
11882 The DWP file can be made up of a random collection of CUs and TUs.
11883 However, for each CU + set of TUs that came from the same original DWO
11884 file, we can combine them back into a virtual DWO file to save space
11885 (fewer struct dwo_file objects to allocate). Remember that for really
11886 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11888 std::string virtual_dwo_name
=
11889 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11890 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11891 (long) (sections
.line_size
? sections
.line_offset
: 0),
11892 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11893 (long) (sections
.str_offsets_size
11894 ? sections
.str_offsets_offset
: 0),
11895 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11896 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11897 /* Can we use an existing virtual DWO file? */
11898 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11899 virtual_dwo_name
.c_str (),
11901 /* Create one if necessary. */
11902 if (*dwo_file_slot
== NULL
)
11904 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11905 virtual_dwo_name
.c_str ());
11907 dwo_file
= new struct dwo_file
;
11908 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11909 dwo_file
->comp_dir
= comp_dir
;
11910 dwo_file
->sections
.abbrev
=
11911 create_dwp_v2_or_v5_section (per_objfile
,
11912 &dwp_file
->sections
.abbrev
,
11913 sections
.abbrev_offset
,
11914 sections
.abbrev_size
);
11915 dwo_file
->sections
.line
=
11916 create_dwp_v2_or_v5_section (per_objfile
,
11917 &dwp_file
->sections
.line
,
11918 sections
.line_offset
, sections
.line_size
);
11919 dwo_file
->sections
.macro
=
11920 create_dwp_v2_or_v5_section (per_objfile
,
11921 &dwp_file
->sections
.macro
,
11922 sections
.macro_offset
,
11923 sections
.macro_size
);
11924 dwo_file
->sections
.loclists
=
11925 create_dwp_v2_or_v5_section (per_objfile
,
11926 &dwp_file
->sections
.loclists
,
11927 sections
.loclists_offset
,
11928 sections
.loclists_size
);
11929 dwo_file
->sections
.rnglists
=
11930 create_dwp_v2_or_v5_section (per_objfile
,
11931 &dwp_file
->sections
.rnglists
,
11932 sections
.rnglists_offset
,
11933 sections
.rnglists_size
);
11934 dwo_file
->sections
.str_offsets
=
11935 create_dwp_v2_or_v5_section (per_objfile
,
11936 &dwp_file
->sections
.str_offsets
,
11937 sections
.str_offsets_offset
,
11938 sections
.str_offsets_size
);
11939 /* The "str" section is global to the entire DWP file. */
11940 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11941 /* The info or types section is assigned below to dwo_unit,
11942 there's no need to record it in dwo_file.
11943 Also, we can't simply record type sections in dwo_file because
11944 we record a pointer into the vector in dwo_unit. As we collect more
11945 types we'll grow the vector and eventually have to reallocate space
11946 for it, invalidating all copies of pointers into the previous
11948 *dwo_file_slot
= dwo_file
;
11952 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11953 virtual_dwo_name
.c_str ());
11955 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11958 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11959 dwo_unit
->dwo_file
= dwo_file
;
11960 dwo_unit
->signature
= signature
;
11962 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11963 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
11964 &dwp_file
->sections
.info
,
11965 sections
.info_or_types_offset
,
11966 sections
.info_or_types_size
);
11967 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11972 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11973 Returns NULL if the signature isn't found. */
11975 static struct dwo_unit
*
11976 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
11977 struct dwp_file
*dwp_file
, const char *comp_dir
,
11978 ULONGEST signature
, int is_debug_types
)
11980 const struct dwp_hash_table
*dwp_htab
=
11981 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11982 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11983 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11984 uint32_t hash
= signature
& mask
;
11985 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11988 struct dwo_unit find_dwo_cu
;
11990 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11991 find_dwo_cu
.signature
= signature
;
11992 slot
= htab_find_slot (is_debug_types
11993 ? dwp_file
->loaded_tus
.get ()
11994 : dwp_file
->loaded_cus
.get (),
11995 &find_dwo_cu
, INSERT
);
11998 return (struct dwo_unit
*) *slot
;
12000 /* Use a for loop so that we don't loop forever on bad debug info. */
12001 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12003 ULONGEST signature_in_table
;
12005 signature_in_table
=
12006 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12007 if (signature_in_table
== signature
)
12009 uint32_t unit_index
=
12010 read_4_bytes (dbfd
,
12011 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12013 if (dwp_file
->version
== 1)
12015 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12016 unit_index
, comp_dir
,
12017 signature
, is_debug_types
);
12019 else if (dwp_file
->version
== 2)
12021 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12022 unit_index
, comp_dir
,
12023 signature
, is_debug_types
);
12025 else /* version == 5 */
12027 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12028 unit_index
, comp_dir
,
12029 signature
, is_debug_types
);
12031 return (struct dwo_unit
*) *slot
;
12033 if (signature_in_table
== 0)
12035 hash
= (hash
+ hash2
) & mask
;
12038 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12039 " [in module %s]"),
12043 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12044 Open the file specified by FILE_NAME and hand it off to BFD for
12045 preliminary analysis. Return a newly initialized bfd *, which
12046 includes a canonicalized copy of FILE_NAME.
12047 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12048 SEARCH_CWD is true if the current directory is to be searched.
12049 It will be searched before debug-file-directory.
12050 If successful, the file is added to the bfd include table of the
12051 objfile's bfd (see gdb_bfd_record_inclusion).
12052 If unable to find/open the file, return NULL.
12053 NOTE: This function is derived from symfile_bfd_open. */
12055 static gdb_bfd_ref_ptr
12056 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12057 const char *file_name
, int is_dwp
, int search_cwd
)
12060 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12061 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12062 to debug_file_directory. */
12063 const char *search_path
;
12064 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12066 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12069 if (*debug_file_directory
!= '\0')
12071 search_path_holder
.reset (concat (".", dirname_separator_string
,
12072 debug_file_directory
,
12074 search_path
= search_path_holder
.get ();
12080 search_path
= debug_file_directory
;
12082 /* Add the path for the executable binary to the list of search paths. */
12083 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12084 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12085 dirname_separator_string
,
12086 search_path
, nullptr));
12087 search_path
= search_path_holder
.get ();
12089 openp_flags flags
= OPF_RETURN_REALPATH
;
12091 flags
|= OPF_SEARCH_IN_PATH
;
12093 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12094 desc
= openp (search_path
, flags
, file_name
,
12095 O_RDONLY
| O_BINARY
, &absolute_name
);
12099 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12101 if (sym_bfd
== NULL
)
12103 bfd_set_cacheable (sym_bfd
.get (), 1);
12105 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12108 /* Success. Record the bfd as having been included by the objfile's bfd.
12109 This is important because things like demangled_names_hash lives in the
12110 objfile's per_bfd space and may have references to things like symbol
12111 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12112 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12117 /* Try to open DWO file FILE_NAME.
12118 COMP_DIR is the DW_AT_comp_dir attribute.
12119 The result is the bfd handle of the file.
12120 If there is a problem finding or opening the file, return NULL.
12121 Upon success, the canonicalized path of the file is stored in the bfd,
12122 same as symfile_bfd_open. */
12124 static gdb_bfd_ref_ptr
12125 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12126 const char *file_name
, const char *comp_dir
)
12128 if (IS_ABSOLUTE_PATH (file_name
))
12129 return try_open_dwop_file (per_objfile
, file_name
,
12130 0 /*is_dwp*/, 0 /*search_cwd*/);
12132 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12134 if (comp_dir
!= NULL
)
12136 gdb::unique_xmalloc_ptr
<char> path_to_try
12137 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12139 /* NOTE: If comp_dir is a relative path, this will also try the
12140 search path, which seems useful. */
12141 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12143 1 /*search_cwd*/));
12148 /* That didn't work, try debug-file-directory, which, despite its name,
12149 is a list of paths. */
12151 if (*debug_file_directory
== '\0')
12154 return try_open_dwop_file (per_objfile
, file_name
,
12155 0 /*is_dwp*/, 1 /*search_cwd*/);
12158 /* This function is mapped across the sections and remembers the offset and
12159 size of each of the DWO debugging sections we are interested in. */
12162 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12163 dwo_sections
*dwo_sections
)
12165 const struct dwop_section_names
*names
= &dwop_section_names
;
12167 if (names
->abbrev_dwo
.matches (sectp
->name
))
12169 dwo_sections
->abbrev
.s
.section
= sectp
;
12170 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12172 else if (names
->info_dwo
.matches (sectp
->name
))
12174 dwo_sections
->info
.s
.section
= sectp
;
12175 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12177 else if (names
->line_dwo
.matches (sectp
->name
))
12179 dwo_sections
->line
.s
.section
= sectp
;
12180 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12182 else if (names
->loc_dwo
.matches (sectp
->name
))
12184 dwo_sections
->loc
.s
.section
= sectp
;
12185 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12187 else if (names
->loclists_dwo
.matches (sectp
->name
))
12189 dwo_sections
->loclists
.s
.section
= sectp
;
12190 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12192 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12194 dwo_sections
->macinfo
.s
.section
= sectp
;
12195 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12197 else if (names
->macro_dwo
.matches (sectp
->name
))
12199 dwo_sections
->macro
.s
.section
= sectp
;
12200 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12202 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12204 dwo_sections
->rnglists
.s
.section
= sectp
;
12205 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12207 else if (names
->str_dwo
.matches (sectp
->name
))
12209 dwo_sections
->str
.s
.section
= sectp
;
12210 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12212 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12214 dwo_sections
->str_offsets
.s
.section
= sectp
;
12215 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12217 else if (names
->types_dwo
.matches (sectp
->name
))
12219 struct dwarf2_section_info type_section
;
12221 memset (&type_section
, 0, sizeof (type_section
));
12222 type_section
.s
.section
= sectp
;
12223 type_section
.size
= bfd_section_size (sectp
);
12224 dwo_sections
->types
.push_back (type_section
);
12228 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12229 by PER_CU. This is for the non-DWP case.
12230 The result is NULL if DWO_NAME can't be found. */
12232 static struct dwo_file
*
12233 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12234 const char *comp_dir
)
12236 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12238 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12241 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12246 dwo_file_up
dwo_file (new struct dwo_file
);
12247 dwo_file
->dwo_name
= dwo_name
;
12248 dwo_file
->comp_dir
= comp_dir
;
12249 dwo_file
->dbfd
= std::move (dbfd
);
12251 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12252 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12253 &dwo_file
->sections
);
12255 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12258 if (cu
->per_cu
->dwarf_version
< 5)
12260 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12261 dwo_file
->sections
.types
, dwo_file
->tus
);
12265 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12266 &dwo_file
->sections
.info
, dwo_file
->tus
,
12267 rcuh_kind::COMPILE
);
12270 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12272 return dwo_file
.release ();
12275 /* This function is mapped across the sections and remembers the offset and
12276 size of each of the DWP debugging sections common to version 1 and 2 that
12277 we are interested in. */
12280 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12281 dwp_file
*dwp_file
)
12283 const struct dwop_section_names
*names
= &dwop_section_names
;
12284 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12286 /* Record the ELF section number for later lookup: this is what the
12287 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12288 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12289 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12291 /* Look for specific sections that we need. */
12292 if (names
->str_dwo
.matches (sectp
->name
))
12294 dwp_file
->sections
.str
.s
.section
= sectp
;
12295 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12297 else if (names
->cu_index
.matches (sectp
->name
))
12299 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12300 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12302 else if (names
->tu_index
.matches (sectp
->name
))
12304 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12305 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12309 /* This function is mapped across the sections and remembers the offset and
12310 size of each of the DWP version 2 debugging sections that we are interested
12311 in. This is split into a separate function because we don't know if we
12312 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12315 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12317 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12318 const struct dwop_section_names
*names
= &dwop_section_names
;
12319 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12321 /* Record the ELF section number for later lookup: this is what the
12322 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12323 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12324 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12326 /* Look for specific sections that we need. */
12327 if (names
->abbrev_dwo
.matches (sectp
->name
))
12329 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12330 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12332 else if (names
->info_dwo
.matches (sectp
->name
))
12334 dwp_file
->sections
.info
.s
.section
= sectp
;
12335 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12337 else if (names
->line_dwo
.matches (sectp
->name
))
12339 dwp_file
->sections
.line
.s
.section
= sectp
;
12340 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12342 else if (names
->loc_dwo
.matches (sectp
->name
))
12344 dwp_file
->sections
.loc
.s
.section
= sectp
;
12345 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12347 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12349 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12350 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12352 else if (names
->macro_dwo
.matches (sectp
->name
))
12354 dwp_file
->sections
.macro
.s
.section
= sectp
;
12355 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12357 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12359 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12360 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12362 else if (names
->types_dwo
.matches (sectp
->name
))
12364 dwp_file
->sections
.types
.s
.section
= sectp
;
12365 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12369 /* This function is mapped across the sections and remembers the offset and
12370 size of each of the DWP version 5 debugging sections that we are interested
12371 in. This is split into a separate function because we don't know if we
12372 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12375 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12377 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12378 const struct dwop_section_names
*names
= &dwop_section_names
;
12379 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12381 /* Record the ELF section number for later lookup: this is what the
12382 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12383 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12384 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12386 /* Look for specific sections that we need. */
12387 if (names
->abbrev_dwo
.matches (sectp
->name
))
12389 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12390 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12392 else if (names
->info_dwo
.matches (sectp
->name
))
12394 dwp_file
->sections
.info
.s
.section
= sectp
;
12395 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12397 else if (names
->line_dwo
.matches (sectp
->name
))
12399 dwp_file
->sections
.line
.s
.section
= sectp
;
12400 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12402 else if (names
->loclists_dwo
.matches (sectp
->name
))
12404 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12405 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12407 else if (names
->macro_dwo
.matches (sectp
->name
))
12409 dwp_file
->sections
.macro
.s
.section
= sectp
;
12410 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12412 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12414 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12415 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12417 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12419 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12420 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12424 /* Hash function for dwp_file loaded CUs/TUs. */
12427 hash_dwp_loaded_cutus (const void *item
)
12429 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12431 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12432 return dwo_unit
->signature
;
12435 /* Equality function for dwp_file loaded CUs/TUs. */
12438 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12440 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12441 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12443 return dua
->signature
== dub
->signature
;
12446 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12449 allocate_dwp_loaded_cutus_table ()
12451 return htab_up (htab_create_alloc (3,
12452 hash_dwp_loaded_cutus
,
12453 eq_dwp_loaded_cutus
,
12454 NULL
, xcalloc
, xfree
));
12457 /* Try to open DWP file FILE_NAME.
12458 The result is the bfd handle of the file.
12459 If there is a problem finding or opening the file, return NULL.
12460 Upon success, the canonicalized path of the file is stored in the bfd,
12461 same as symfile_bfd_open. */
12463 static gdb_bfd_ref_ptr
12464 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12466 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12468 1 /*search_cwd*/));
12472 /* Work around upstream bug 15652.
12473 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12474 [Whether that's a "bug" is debatable, but it is getting in our way.]
12475 We have no real idea where the dwp file is, because gdb's realpath-ing
12476 of the executable's path may have discarded the needed info.
12477 [IWBN if the dwp file name was recorded in the executable, akin to
12478 .gnu_debuglink, but that doesn't exist yet.]
12479 Strip the directory from FILE_NAME and search again. */
12480 if (*debug_file_directory
!= '\0')
12482 /* Don't implicitly search the current directory here.
12483 If the user wants to search "." to handle this case,
12484 it must be added to debug-file-directory. */
12485 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12493 /* Initialize the use of the DWP file for the current objfile.
12494 By convention the name of the DWP file is ${objfile}.dwp.
12495 The result is NULL if it can't be found. */
12497 static std::unique_ptr
<struct dwp_file
>
12498 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12500 struct objfile
*objfile
= per_objfile
->objfile
;
12502 /* Try to find first .dwp for the binary file before any symbolic links
12505 /* If the objfile is a debug file, find the name of the real binary
12506 file and get the name of dwp file from there. */
12507 std::string dwp_name
;
12508 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12510 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12511 const char *backlink_basename
= lbasename (backlink
->original_name
);
12513 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12516 dwp_name
= objfile
->original_name
;
12518 dwp_name
+= ".dwp";
12520 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12522 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12524 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12525 dwp_name
= objfile_name (objfile
);
12526 dwp_name
+= ".dwp";
12527 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12532 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12534 return std::unique_ptr
<dwp_file
> ();
12537 const char *name
= bfd_get_filename (dbfd
.get ());
12538 std::unique_ptr
<struct dwp_file
> dwp_file
12539 (new struct dwp_file (name
, std::move (dbfd
)));
12541 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12542 dwp_file
->elf_sections
=
12543 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12544 dwp_file
->num_sections
, asection
*);
12546 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12547 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12550 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12552 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12554 /* The DWP file version is stored in the hash table. Oh well. */
12555 if (dwp_file
->cus
&& dwp_file
->tus
12556 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12558 /* Technically speaking, we should try to limp along, but this is
12559 pretty bizarre. We use pulongest here because that's the established
12560 portability solution (e.g, we cannot use %u for uint32_t). */
12561 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12562 " TU version %s [in DWP file %s]"),
12563 pulongest (dwp_file
->cus
->version
),
12564 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12568 dwp_file
->version
= dwp_file
->cus
->version
;
12569 else if (dwp_file
->tus
)
12570 dwp_file
->version
= dwp_file
->tus
->version
;
12572 dwp_file
->version
= 2;
12574 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12576 if (dwp_file
->version
== 2)
12577 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12580 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12584 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12585 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12587 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12588 dwarf_read_debug_printf (" %s CUs, %s TUs",
12589 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12590 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12595 /* Wrapper around open_and_init_dwp_file, only open it once. */
12597 static struct dwp_file
*
12598 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12600 if (!per_objfile
->per_bfd
->dwp_checked
)
12602 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12603 per_objfile
->per_bfd
->dwp_checked
= 1;
12605 return per_objfile
->per_bfd
->dwp_file
.get ();
12608 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12609 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12610 or in the DWP file for the objfile, referenced by THIS_UNIT.
12611 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12612 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12614 This is called, for example, when wanting to read a variable with a
12615 complex location. Therefore we don't want to do file i/o for every call.
12616 Therefore we don't want to look for a DWO file on every call.
12617 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12618 then we check if we've already seen DWO_NAME, and only THEN do we check
12621 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12622 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12624 static struct dwo_unit
*
12625 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12626 ULONGEST signature
, int is_debug_types
)
12628 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12629 struct objfile
*objfile
= per_objfile
->objfile
;
12630 const char *kind
= is_debug_types
? "TU" : "CU";
12631 void **dwo_file_slot
;
12632 struct dwo_file
*dwo_file
;
12633 struct dwp_file
*dwp_file
;
12635 /* First see if there's a DWP file.
12636 If we have a DWP file but didn't find the DWO inside it, don't
12637 look for the original DWO file. It makes gdb behave differently
12638 depending on whether one is debugging in the build tree. */
12640 dwp_file
= get_dwp_file (per_objfile
);
12641 if (dwp_file
!= NULL
)
12643 const struct dwp_hash_table
*dwp_htab
=
12644 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12646 if (dwp_htab
!= NULL
)
12648 struct dwo_unit
*dwo_cutu
=
12649 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12652 if (dwo_cutu
!= NULL
)
12654 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12655 kind
, hex_string (signature
),
12656 host_address_to_string (dwo_cutu
));
12664 /* No DWP file, look for the DWO file. */
12666 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12667 if (*dwo_file_slot
== NULL
)
12669 /* Read in the file and build a table of the CUs/TUs it contains. */
12670 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12672 /* NOTE: This will be NULL if unable to open the file. */
12673 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12675 if (dwo_file
!= NULL
)
12677 struct dwo_unit
*dwo_cutu
= NULL
;
12679 if (is_debug_types
&& dwo_file
->tus
)
12681 struct dwo_unit find_dwo_cutu
;
12683 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12684 find_dwo_cutu
.signature
= signature
;
12686 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12689 else if (!is_debug_types
&& dwo_file
->cus
)
12691 struct dwo_unit find_dwo_cutu
;
12693 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12694 find_dwo_cutu
.signature
= signature
;
12695 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12699 if (dwo_cutu
!= NULL
)
12701 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12702 kind
, dwo_name
, hex_string (signature
),
12703 host_address_to_string (dwo_cutu
));
12710 /* We didn't find it. This could mean a dwo_id mismatch, or
12711 someone deleted the DWO/DWP file, or the search path isn't set up
12712 correctly to find the file. */
12714 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12715 kind
, dwo_name
, hex_string (signature
));
12717 /* This is a warning and not a complaint because it can be caused by
12718 pilot error (e.g., user accidentally deleting the DWO). */
12720 /* Print the name of the DWP file if we looked there, helps the user
12721 better diagnose the problem. */
12722 std::string dwp_text
;
12724 if (dwp_file
!= NULL
)
12725 dwp_text
= string_printf (" [in DWP file %s]",
12726 lbasename (dwp_file
->name
));
12728 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12729 " [in module %s]"),
12730 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12731 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12736 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12737 See lookup_dwo_cutu_unit for details. */
12739 static struct dwo_unit
*
12740 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12741 ULONGEST signature
)
12743 gdb_assert (!cu
->per_cu
->is_debug_types
);
12745 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12748 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12749 See lookup_dwo_cutu_unit for details. */
12751 static struct dwo_unit
*
12752 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12754 gdb_assert (cu
->per_cu
->is_debug_types
);
12756 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12758 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12761 /* Traversal function for queue_and_load_all_dwo_tus. */
12764 queue_and_load_dwo_tu (void **slot
, void *info
)
12766 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12767 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12768 ULONGEST signature
= dwo_unit
->signature
;
12769 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12771 if (sig_type
!= NULL
)
12773 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12774 a real dependency of PER_CU on SIG_TYPE. That is detected later
12775 while processing PER_CU. */
12776 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12778 load_full_type_unit (sig_type
, cu
->per_objfile
);
12779 cu
->per_cu
->imported_symtabs_push (sig_type
);
12785 /* Queue all TUs contained in the DWO of CU to be read in.
12786 The DWO may have the only definition of the type, though it may not be
12787 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12788 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12791 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12793 struct dwo_unit
*dwo_unit
;
12794 struct dwo_file
*dwo_file
;
12796 gdb_assert (cu
!= nullptr);
12797 gdb_assert (!cu
->per_cu
->is_debug_types
);
12798 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12800 dwo_unit
= cu
->dwo_unit
;
12801 gdb_assert (dwo_unit
!= NULL
);
12803 dwo_file
= dwo_unit
->dwo_file
;
12804 if (dwo_file
->tus
!= NULL
)
12805 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12808 /* Read in various DIEs. */
12810 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12811 Inherit only the children of the DW_AT_abstract_origin DIE not being
12812 already referenced by DW_AT_abstract_origin from the children of the
12816 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12818 struct die_info
*child_die
;
12819 sect_offset
*offsetp
;
12820 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12821 struct die_info
*origin_die
;
12822 /* Iterator of the ORIGIN_DIE children. */
12823 struct die_info
*origin_child_die
;
12824 struct attribute
*attr
;
12825 struct dwarf2_cu
*origin_cu
;
12826 struct pending
**origin_previous_list_in_scope
;
12828 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12832 /* Note that following die references may follow to a die in a
12836 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12838 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12840 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12841 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12843 if (die
->tag
!= origin_die
->tag
12844 && !(die
->tag
== DW_TAG_inlined_subroutine
12845 && origin_die
->tag
== DW_TAG_subprogram
))
12846 complaint (_("DIE %s and its abstract origin %s have different tags"),
12847 sect_offset_str (die
->sect_off
),
12848 sect_offset_str (origin_die
->sect_off
));
12850 /* Find if the concrete and abstract trees are structurally the
12851 same. This is a shallow traversal and it is not bullet-proof;
12852 the compiler can trick the debugger into believing that the trees
12853 are isomorphic, whereas they actually are not. However, the
12854 likelyhood of this happening is pretty low, and a full-fledged
12855 check would be an overkill. */
12856 bool are_isomorphic
= true;
12857 die_info
*concrete_child
= die
->child
;
12858 die_info
*abstract_child
= origin_die
->child
;
12859 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12861 if (concrete_child
== nullptr
12862 || abstract_child
== nullptr
12863 || concrete_child
->tag
!= abstract_child
->tag
)
12865 are_isomorphic
= false;
12869 concrete_child
= concrete_child
->sibling
;
12870 abstract_child
= abstract_child
->sibling
;
12873 /* Walk the origin's children in parallel to the concrete children.
12874 This helps match an origin child in case the debug info misses
12875 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12876 origin tree may not have the same tree structure as the concrete
12878 die_info
*corresponding_abstract_child
12879 = are_isomorphic
? origin_die
->child
: nullptr;
12881 std::vector
<sect_offset
> offsets
;
12883 for (child_die
= die
->child
;
12884 child_die
&& child_die
->tag
;
12885 child_die
= child_die
->sibling
)
12887 struct die_info
*child_origin_die
;
12888 struct dwarf2_cu
*child_origin_cu
;
12890 /* We are trying to process concrete instance entries:
12891 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12892 it's not relevant to our analysis here. i.e. detecting DIEs that are
12893 present in the abstract instance but not referenced in the concrete
12895 if (child_die
->tag
== DW_TAG_call_site
12896 || child_die
->tag
== DW_TAG_GNU_call_site
)
12898 if (are_isomorphic
)
12899 corresponding_abstract_child
12900 = corresponding_abstract_child
->sibling
;
12904 /* For each CHILD_DIE, find the corresponding child of
12905 ORIGIN_DIE. If there is more than one layer of
12906 DW_AT_abstract_origin, follow them all; there shouldn't be,
12907 but GCC versions at least through 4.4 generate this (GCC PR
12909 child_origin_die
= child_die
;
12910 child_origin_cu
= cu
;
12913 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12917 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12921 /* If missing DW_AT_abstract_origin, try the corresponding child
12922 of the origin. Clang emits such lexical scopes. */
12923 if (child_origin_die
== child_die
12924 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12926 && child_die
->tag
== DW_TAG_lexical_block
)
12927 child_origin_die
= corresponding_abstract_child
;
12929 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12930 counterpart may exist. */
12931 if (child_origin_die
!= child_die
)
12933 if (child_die
->tag
!= child_origin_die
->tag
12934 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12935 && child_origin_die
->tag
== DW_TAG_subprogram
))
12936 complaint (_("Child DIE %s and its abstract origin %s have "
12938 sect_offset_str (child_die
->sect_off
),
12939 sect_offset_str (child_origin_die
->sect_off
));
12940 if (child_origin_die
->parent
!= origin_die
)
12941 complaint (_("Child DIE %s and its abstract origin %s have "
12942 "different parents"),
12943 sect_offset_str (child_die
->sect_off
),
12944 sect_offset_str (child_origin_die
->sect_off
));
12946 offsets
.push_back (child_origin_die
->sect_off
);
12949 if (are_isomorphic
)
12950 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12952 std::sort (offsets
.begin (), offsets
.end ());
12953 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12954 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12955 if (offsetp
[-1] == *offsetp
)
12956 complaint (_("Multiple children of DIE %s refer "
12957 "to DIE %s as their abstract origin"),
12958 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12960 offsetp
= offsets
.data ();
12961 origin_child_die
= origin_die
->child
;
12962 while (origin_child_die
&& origin_child_die
->tag
)
12964 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12965 while (offsetp
< offsets_end
12966 && *offsetp
< origin_child_die
->sect_off
)
12968 if (offsetp
>= offsets_end
12969 || *offsetp
> origin_child_die
->sect_off
)
12971 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12972 Check whether we're already processing ORIGIN_CHILD_DIE.
12973 This can happen with mutually referenced abstract_origins.
12975 if (!origin_child_die
->in_process
)
12976 process_die (origin_child_die
, origin_cu
);
12978 origin_child_die
= origin_child_die
->sibling
;
12980 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12982 if (cu
!= origin_cu
)
12983 compute_delayed_physnames (origin_cu
);
12987 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12989 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12990 struct gdbarch
*gdbarch
= objfile
->arch ();
12991 struct context_stack
*newobj
;
12994 struct die_info
*child_die
;
12995 struct attribute
*attr
, *call_line
, *call_file
;
12997 CORE_ADDR baseaddr
;
12998 struct block
*block
;
12999 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13000 std::vector
<struct symbol
*> template_args
;
13001 struct template_symbol
*templ_func
= NULL
;
13005 /* If we do not have call site information, we can't show the
13006 caller of this inlined function. That's too confusing, so
13007 only use the scope for local variables. */
13008 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13009 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13010 if (call_line
== NULL
|| call_file
== NULL
)
13012 read_lexical_block_scope (die
, cu
);
13017 baseaddr
= objfile
->text_section_offset ();
13019 name
= dwarf2_name (die
, cu
);
13021 /* Ignore functions with missing or empty names. These are actually
13022 illegal according to the DWARF standard. */
13025 complaint (_("missing name for subprogram DIE at %s"),
13026 sect_offset_str (die
->sect_off
));
13030 /* Ignore functions with missing or invalid low and high pc attributes. */
13031 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13032 <= PC_BOUNDS_INVALID
)
13034 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13035 if (attr
== nullptr || !attr
->as_boolean ())
13036 complaint (_("cannot get low and high bounds "
13037 "for subprogram DIE at %s"),
13038 sect_offset_str (die
->sect_off
));
13042 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13043 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13045 /* If we have any template arguments, then we must allocate a
13046 different sort of symbol. */
13047 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13049 if (child_die
->tag
== DW_TAG_template_type_param
13050 || child_die
->tag
== DW_TAG_template_value_param
)
13052 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13053 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13058 gdb_assert (cu
->get_builder () != nullptr);
13059 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13060 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13061 (struct symbol
*) templ_func
);
13063 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13064 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13067 /* If there is a location expression for DW_AT_frame_base, record
13069 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13070 if (attr
!= nullptr)
13071 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13073 /* If there is a location for the static link, record it. */
13074 newobj
->static_link
= NULL
;
13075 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13076 if (attr
!= nullptr)
13078 newobj
->static_link
13079 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13080 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13084 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13086 if (die
->child
!= NULL
)
13088 child_die
= die
->child
;
13089 while (child_die
&& child_die
->tag
)
13091 if (child_die
->tag
== DW_TAG_template_type_param
13092 || child_die
->tag
== DW_TAG_template_value_param
)
13094 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13097 template_args
.push_back (arg
);
13100 process_die (child_die
, cu
);
13101 child_die
= child_die
->sibling
;
13105 inherit_abstract_dies (die
, cu
);
13107 /* If we have a DW_AT_specification, we might need to import using
13108 directives from the context of the specification DIE. See the
13109 comment in determine_prefix. */
13110 if (cu
->per_cu
->lang
== language_cplus
13111 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13113 struct dwarf2_cu
*spec_cu
= cu
;
13114 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13118 child_die
= spec_die
->child
;
13119 while (child_die
&& child_die
->tag
)
13121 if (child_die
->tag
== DW_TAG_imported_module
)
13122 process_die (child_die
, spec_cu
);
13123 child_die
= child_die
->sibling
;
13126 /* In some cases, GCC generates specification DIEs that
13127 themselves contain DW_AT_specification attributes. */
13128 spec_die
= die_specification (spec_die
, &spec_cu
);
13132 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13133 /* Make a block for the local symbols within. */
13134 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13135 cstk
.static_link
, lowpc
, highpc
);
13137 /* For C++, set the block's scope. */
13138 if ((cu
->per_cu
->lang
== language_cplus
13139 || cu
->per_cu
->lang
== language_fortran
13140 || cu
->per_cu
->lang
== language_d
13141 || cu
->per_cu
->lang
== language_rust
)
13142 && cu
->processing_has_namespace_info
)
13143 block_set_scope (block
, determine_prefix (die
, cu
),
13144 &objfile
->objfile_obstack
);
13146 /* If we have address ranges, record them. */
13147 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13149 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13151 /* Attach template arguments to function. */
13152 if (!template_args
.empty ())
13154 gdb_assert (templ_func
!= NULL
);
13156 templ_func
->n_template_arguments
= template_args
.size ();
13157 templ_func
->template_arguments
13158 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13159 templ_func
->n_template_arguments
);
13160 memcpy (templ_func
->template_arguments
,
13161 template_args
.data (),
13162 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13164 /* Make sure that the symtab is set on the new symbols. Even
13165 though they don't appear in this symtab directly, other parts
13166 of gdb assume that symbols do, and this is reasonably
13168 for (symbol
*sym
: template_args
)
13169 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13172 /* In C++, we can have functions nested inside functions (e.g., when
13173 a function declares a class that has methods). This means that
13174 when we finish processing a function scope, we may need to go
13175 back to building a containing block's symbol lists. */
13176 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13177 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13179 /* If we've finished processing a top-level function, subsequent
13180 symbols go in the file symbol list. */
13181 if (cu
->get_builder ()->outermost_context_p ())
13182 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13185 /* Process all the DIES contained within a lexical block scope. Start
13186 a new scope, process the dies, and then close the scope. */
13189 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13191 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13192 struct gdbarch
*gdbarch
= objfile
->arch ();
13193 CORE_ADDR lowpc
, highpc
;
13194 struct die_info
*child_die
;
13195 CORE_ADDR baseaddr
;
13197 baseaddr
= objfile
->text_section_offset ();
13199 /* Ignore blocks with missing or invalid low and high pc attributes. */
13200 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13201 as multiple lexical blocks? Handling children in a sane way would
13202 be nasty. Might be easier to properly extend generic blocks to
13203 describe ranges. */
13204 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13206 case PC_BOUNDS_NOT_PRESENT
:
13207 /* DW_TAG_lexical_block has no attributes, process its children as if
13208 there was no wrapping by that DW_TAG_lexical_block.
13209 GCC does no longer produces such DWARF since GCC r224161. */
13210 for (child_die
= die
->child
;
13211 child_die
!= NULL
&& child_die
->tag
;
13212 child_die
= child_die
->sibling
)
13214 /* We might already be processing this DIE. This can happen
13215 in an unusual circumstance -- where a subroutine A
13216 appears lexically in another subroutine B, but A actually
13217 inlines B. The recursion is broken here, rather than in
13218 inherit_abstract_dies, because it seems better to simply
13219 drop concrete children here. */
13220 if (!child_die
->in_process
)
13221 process_die (child_die
, cu
);
13224 case PC_BOUNDS_INVALID
:
13227 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13228 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13230 cu
->get_builder ()->push_context (0, lowpc
);
13231 if (die
->child
!= NULL
)
13233 child_die
= die
->child
;
13234 while (child_die
&& child_die
->tag
)
13236 process_die (child_die
, cu
);
13237 child_die
= child_die
->sibling
;
13240 inherit_abstract_dies (die
, cu
);
13241 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13243 if (*cu
->get_builder ()->get_local_symbols () != NULL
13244 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13246 struct block
*block
13247 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13248 cstk
.start_addr
, highpc
);
13250 /* Note that recording ranges after traversing children, as we
13251 do here, means that recording a parent's ranges entails
13252 walking across all its children's ranges as they appear in
13253 the address map, which is quadratic behavior.
13255 It would be nicer to record the parent's ranges before
13256 traversing its children, simply overriding whatever you find
13257 there. But since we don't even decide whether to create a
13258 block until after we've traversed its children, that's hard
13260 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13262 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13263 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13266 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13269 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13271 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13272 struct objfile
*objfile
= per_objfile
->objfile
;
13273 struct gdbarch
*gdbarch
= objfile
->arch ();
13274 CORE_ADDR pc
, baseaddr
;
13275 struct attribute
*attr
;
13276 struct call_site
*call_site
, call_site_local
;
13279 struct die_info
*child_die
;
13281 baseaddr
= objfile
->text_section_offset ();
13283 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13286 /* This was a pre-DWARF-5 GNU extension alias
13287 for DW_AT_call_return_pc. */
13288 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13292 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13293 "DIE %s [in module %s]"),
13294 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13297 pc
= attr
->as_address () + baseaddr
;
13298 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13300 if (cu
->call_site_htab
== NULL
)
13301 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13302 NULL
, &objfile
->objfile_obstack
,
13303 hashtab_obstack_allocate
, NULL
);
13304 call_site_local
.pc
= pc
;
13305 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13308 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13309 "DIE %s [in module %s]"),
13310 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13311 objfile_name (objfile
));
13315 /* Count parameters at the caller. */
13318 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13319 child_die
= child_die
->sibling
)
13321 if (child_die
->tag
!= DW_TAG_call_site_parameter
13322 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13324 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13325 "DW_TAG_call_site child DIE %s [in module %s]"),
13326 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13327 objfile_name (objfile
));
13335 = ((struct call_site
*)
13336 obstack_alloc (&objfile
->objfile_obstack
,
13337 sizeof (*call_site
)
13338 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13340 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13341 call_site
->pc
= pc
;
13343 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13344 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13346 struct die_info
*func_die
;
13348 /* Skip also over DW_TAG_inlined_subroutine. */
13349 for (func_die
= die
->parent
;
13350 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13351 && func_die
->tag
!= DW_TAG_subroutine_type
;
13352 func_die
= func_die
->parent
);
13354 /* DW_AT_call_all_calls is a superset
13355 of DW_AT_call_all_tail_calls. */
13357 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13358 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13359 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13360 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13362 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13363 not complete. But keep CALL_SITE for look ups via call_site_htab,
13364 both the initial caller containing the real return address PC and
13365 the final callee containing the current PC of a chain of tail
13366 calls do not need to have the tail call list complete. But any
13367 function candidate for a virtual tail call frame searched via
13368 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13369 determined unambiguously. */
13373 struct type
*func_type
= NULL
;
13376 func_type
= get_die_type (func_die
, cu
);
13377 if (func_type
!= NULL
)
13379 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13381 /* Enlist this call site to the function. */
13382 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13383 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13386 complaint (_("Cannot find function owning DW_TAG_call_site "
13387 "DIE %s [in module %s]"),
13388 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13392 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13394 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13396 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13399 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13400 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13402 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13403 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13404 /* Keep NULL DWARF_BLOCK. */;
13405 else if (attr
->form_is_block ())
13407 struct dwarf2_locexpr_baton
*dlbaton
;
13408 struct dwarf_block
*block
= attr
->as_block ();
13410 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13411 dlbaton
->data
= block
->data
;
13412 dlbaton
->size
= block
->size
;
13413 dlbaton
->per_objfile
= per_objfile
;
13414 dlbaton
->per_cu
= cu
->per_cu
;
13416 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13418 else if (attr
->form_is_ref ())
13420 struct dwarf2_cu
*target_cu
= cu
;
13421 struct die_info
*target_die
;
13423 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13424 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13425 if (die_is_declaration (target_die
, target_cu
))
13427 const char *target_physname
;
13429 /* Prefer the mangled name; otherwise compute the demangled one. */
13430 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13431 if (target_physname
== NULL
)
13432 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13433 if (target_physname
== NULL
)
13434 complaint (_("DW_AT_call_target target DIE has invalid "
13435 "physname, for referencing DIE %s [in module %s]"),
13436 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13438 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13444 /* DW_AT_entry_pc should be preferred. */
13445 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13446 <= PC_BOUNDS_INVALID
)
13447 complaint (_("DW_AT_call_target target DIE has invalid "
13448 "low pc, for referencing DIE %s [in module %s]"),
13449 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13452 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13453 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13458 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13459 "block nor reference, for DIE %s [in module %s]"),
13460 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13462 call_site
->per_cu
= cu
->per_cu
;
13463 call_site
->per_objfile
= per_objfile
;
13465 for (child_die
= die
->child
;
13466 child_die
&& child_die
->tag
;
13467 child_die
= child_die
->sibling
)
13469 struct call_site_parameter
*parameter
;
13470 struct attribute
*loc
, *origin
;
13472 if (child_die
->tag
!= DW_TAG_call_site_parameter
13473 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13475 /* Already printed the complaint above. */
13479 gdb_assert (call_site
->parameter_count
< nparams
);
13480 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13482 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13483 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13484 register is contained in DW_AT_call_value. */
13486 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13487 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13488 if (origin
== NULL
)
13490 /* This was a pre-DWARF-5 GNU extension alias
13491 for DW_AT_call_parameter. */
13492 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13494 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13496 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13498 sect_offset sect_off
= origin
->get_ref_die_offset ();
13499 if (!cu
->header
.offset_in_cu_p (sect_off
))
13501 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13502 binding can be done only inside one CU. Such referenced DIE
13503 therefore cannot be even moved to DW_TAG_partial_unit. */
13504 complaint (_("DW_AT_call_parameter offset is not in CU for "
13505 "DW_TAG_call_site child DIE %s [in module %s]"),
13506 sect_offset_str (child_die
->sect_off
),
13507 objfile_name (objfile
));
13510 parameter
->u
.param_cu_off
13511 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13513 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13515 complaint (_("No DW_FORM_block* DW_AT_location for "
13516 "DW_TAG_call_site child DIE %s [in module %s]"),
13517 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13522 struct dwarf_block
*block
= loc
->as_block ();
13524 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13525 (block
->data
, &block
->data
[block
->size
]);
13526 if (parameter
->u
.dwarf_reg
!= -1)
13527 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13528 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13529 &block
->data
[block
->size
],
13530 ¶meter
->u
.fb_offset
))
13531 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13534 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13535 "for DW_FORM_block* DW_AT_location is supported for "
13536 "DW_TAG_call_site child DIE %s "
13538 sect_offset_str (child_die
->sect_off
),
13539 objfile_name (objfile
));
13544 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13546 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13547 if (attr
== NULL
|| !attr
->form_is_block ())
13549 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13550 "DW_TAG_call_site child DIE %s [in module %s]"),
13551 sect_offset_str (child_die
->sect_off
),
13552 objfile_name (objfile
));
13556 struct dwarf_block
*block
= attr
->as_block ();
13557 parameter
->value
= block
->data
;
13558 parameter
->value_size
= block
->size
;
13560 /* Parameters are not pre-cleared by memset above. */
13561 parameter
->data_value
= NULL
;
13562 parameter
->data_value_size
= 0;
13563 call_site
->parameter_count
++;
13565 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13567 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13568 if (attr
!= nullptr)
13570 if (!attr
->form_is_block ())
13571 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13572 "DW_TAG_call_site child DIE %s [in module %s]"),
13573 sect_offset_str (child_die
->sect_off
),
13574 objfile_name (objfile
));
13577 block
= attr
->as_block ();
13578 parameter
->data_value
= block
->data
;
13579 parameter
->data_value_size
= block
->size
;
13585 /* Helper function for read_variable. If DIE represents a virtual
13586 table, then return the type of the concrete object that is
13587 associated with the virtual table. Otherwise, return NULL. */
13589 static struct type
*
13590 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13592 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13596 /* Find the type DIE. */
13597 struct die_info
*type_die
= NULL
;
13598 struct dwarf2_cu
*type_cu
= cu
;
13600 if (attr
->form_is_ref ())
13601 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13602 if (type_die
== NULL
)
13605 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13607 return die_containing_type (type_die
, type_cu
);
13610 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13613 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13615 struct rust_vtable_symbol
*storage
= NULL
;
13617 if (cu
->per_cu
->lang
== language_rust
)
13619 struct type
*containing_type
= rust_containing_type (die
, cu
);
13621 if (containing_type
!= NULL
)
13623 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13625 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13626 storage
->concrete_type
= containing_type
;
13627 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13631 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13632 struct attribute
*abstract_origin
13633 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13634 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13635 if (res
== NULL
&& loc
&& abstract_origin
)
13637 /* We have a variable without a name, but with a location and an abstract
13638 origin. This may be a concrete instance of an abstract variable
13639 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13641 struct dwarf2_cu
*origin_cu
= cu
;
13642 struct die_info
*origin_die
13643 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13644 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13645 per_objfile
->per_bfd
->abstract_to_concrete
13646 [origin_die
->sect_off
].push_back (die
->sect_off
);
13650 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13651 reading .debug_rnglists.
13652 Callback's type should be:
13653 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13654 Return true if the attributes are present and valid, otherwise,
13657 template <typename Callback
>
13659 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13660 dwarf_tag tag
, Callback
&&callback
)
13662 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13663 struct objfile
*objfile
= per_objfile
->objfile
;
13664 bfd
*obfd
= objfile
->obfd
;
13665 /* Base address selection entry. */
13666 gdb::optional
<CORE_ADDR
> base
;
13667 const gdb_byte
*buffer
;
13668 bool overflow
= false;
13669 ULONGEST addr_index
;
13670 struct dwarf2_section_info
*rnglists_section
;
13672 base
= cu
->base_address
;
13673 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13674 rnglists_section
->read (objfile
);
13676 if (offset
>= rnglists_section
->size
)
13678 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13682 buffer
= rnglists_section
->buffer
+ offset
;
13686 /* Initialize it due to a false compiler warning. */
13687 CORE_ADDR range_beginning
= 0, range_end
= 0;
13688 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13689 + rnglists_section
->size
);
13690 unsigned int bytes_read
;
13692 if (buffer
== buf_end
)
13697 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13700 case DW_RLE_end_of_list
:
13702 case DW_RLE_base_address
:
13703 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13708 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13709 buffer
+= bytes_read
;
13711 case DW_RLE_base_addressx
:
13712 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13713 buffer
+= bytes_read
;
13714 base
= read_addr_index (cu
, addr_index
);
13716 case DW_RLE_start_length
:
13717 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13722 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13724 buffer
+= bytes_read
;
13725 range_end
= (range_beginning
13726 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13727 buffer
+= bytes_read
;
13728 if (buffer
> buf_end
)
13734 case DW_RLE_startx_length
:
13735 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13736 buffer
+= bytes_read
;
13737 range_beginning
= read_addr_index (cu
, addr_index
);
13738 if (buffer
> buf_end
)
13743 range_end
= (range_beginning
13744 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13745 buffer
+= bytes_read
;
13747 case DW_RLE_offset_pair
:
13748 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13749 buffer
+= bytes_read
;
13750 if (buffer
> buf_end
)
13755 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13756 buffer
+= bytes_read
;
13757 if (buffer
> buf_end
)
13763 case DW_RLE_start_end
:
13764 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13769 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13771 buffer
+= bytes_read
;
13772 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13773 buffer
+= bytes_read
;
13775 case DW_RLE_startx_endx
:
13776 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13777 buffer
+= bytes_read
;
13778 range_beginning
= read_addr_index (cu
, addr_index
);
13779 if (buffer
> buf_end
)
13784 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13785 buffer
+= bytes_read
;
13786 range_end
= read_addr_index (cu
, addr_index
);
13789 complaint (_("Invalid .debug_rnglists data (no base address)"));
13792 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13794 if (rlet
== DW_RLE_base_address
)
13797 if (range_beginning
> range_end
)
13799 /* Inverted range entries are invalid. */
13800 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13804 /* Empty range entries have no effect. */
13805 if (range_beginning
== range_end
)
13808 /* Only DW_RLE_offset_pair needs the base address added. */
13809 if (rlet
== DW_RLE_offset_pair
)
13811 if (!base
.has_value ())
13813 /* We have no valid base address for the DW_RLE_offset_pair. */
13814 complaint (_("Invalid .debug_rnglists data (no base address for "
13815 "DW_RLE_offset_pair)"));
13819 range_beginning
+= *base
;
13820 range_end
+= *base
;
13823 /* A not-uncommon case of bad debug info.
13824 Don't pollute the addrmap with bad data. */
13825 if (range_beginning
== 0
13826 && !per_objfile
->per_bfd
->has_section_at_zero
)
13828 complaint (_(".debug_rnglists entry has start address of zero"
13829 " [in module %s]"), objfile_name (objfile
));
13833 callback (range_beginning
, range_end
);
13838 complaint (_("Offset %d is not terminated "
13839 "for DW_AT_ranges attribute"),
13847 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13848 Callback's type should be:
13849 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13850 Return 1 if the attributes are present and valid, otherwise, return 0. */
13852 template <typename Callback
>
13854 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13855 Callback
&&callback
)
13857 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13858 struct objfile
*objfile
= per_objfile
->objfile
;
13859 struct comp_unit_head
*cu_header
= &cu
->header
;
13860 bfd
*obfd
= objfile
->obfd
;
13861 unsigned int addr_size
= cu_header
->addr_size
;
13862 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13863 /* Base address selection entry. */
13864 gdb::optional
<CORE_ADDR
> base
;
13865 unsigned int dummy
;
13866 const gdb_byte
*buffer
;
13868 if (cu_header
->version
>= 5)
13869 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13871 base
= cu
->base_address
;
13873 per_objfile
->per_bfd
->ranges
.read (objfile
);
13874 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13876 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13880 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13884 CORE_ADDR range_beginning
, range_end
;
13886 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13887 buffer
+= addr_size
;
13888 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13889 buffer
+= addr_size
;
13890 offset
+= 2 * addr_size
;
13892 /* An end of list marker is a pair of zero addresses. */
13893 if (range_beginning
== 0 && range_end
== 0)
13894 /* Found the end of list entry. */
13897 /* Each base address selection entry is a pair of 2 values.
13898 The first is the largest possible address, the second is
13899 the base address. Check for a base address here. */
13900 if ((range_beginning
& mask
) == mask
)
13902 /* If we found the largest possible address, then we already
13903 have the base address in range_end. */
13908 if (!base
.has_value ())
13910 /* We have no valid base address for the ranges
13912 complaint (_("Invalid .debug_ranges data (no base address)"));
13916 if (range_beginning
> range_end
)
13918 /* Inverted range entries are invalid. */
13919 complaint (_("Invalid .debug_ranges data (inverted range)"));
13923 /* Empty range entries have no effect. */
13924 if (range_beginning
== range_end
)
13927 range_beginning
+= *base
;
13928 range_end
+= *base
;
13930 /* A not-uncommon case of bad debug info.
13931 Don't pollute the addrmap with bad data. */
13932 if (range_beginning
== 0
13933 && !per_objfile
->per_bfd
->has_section_at_zero
)
13935 complaint (_(".debug_ranges entry has start address of zero"
13936 " [in module %s]"), objfile_name (objfile
));
13940 callback (range_beginning
, range_end
);
13946 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13947 Return 1 if the attributes are present and valid, otherwise, return 0.
13948 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
13951 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13952 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13953 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
13955 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13956 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
13957 struct gdbarch
*gdbarch
= objfile
->arch ();
13958 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13961 CORE_ADDR high
= 0;
13964 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
13965 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13967 if (ranges_pst
!= NULL
)
13972 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13973 range_beginning
+ baseaddr
)
13975 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13976 range_end
+ baseaddr
)
13978 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
13979 lowpc
, highpc
- 1, ranges_pst
);
13982 /* FIXME: This is recording everything as a low-high
13983 segment of consecutive addresses. We should have a
13984 data structure for discontiguous block ranges
13988 low
= range_beginning
;
13994 if (range_beginning
< low
)
13995 low
= range_beginning
;
13996 if (range_end
> high
)
14004 /* If the first entry is an end-of-list marker, the range
14005 describes an empty scope, i.e. no instructions. */
14011 *high_return
= high
;
14015 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14016 definition for the return value. *LOWPC and *HIGHPC are set iff
14017 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14019 static enum pc_bounds_kind
14020 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14021 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14022 dwarf2_psymtab
*pst
)
14024 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14025 struct attribute
*attr
;
14026 struct attribute
*attr_high
;
14028 CORE_ADDR high
= 0;
14029 enum pc_bounds_kind ret
;
14031 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14034 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14035 if (attr
!= nullptr)
14037 low
= attr
->as_address ();
14038 high
= attr_high
->as_address ();
14039 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14043 /* Found high w/o low attribute. */
14044 return PC_BOUNDS_INVALID
;
14046 /* Found consecutive range of addresses. */
14047 ret
= PC_BOUNDS_HIGH_LOW
;
14051 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14052 if (attr
!= nullptr && attr
->form_is_unsigned ())
14054 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14055 on DWARF version). */
14056 ULONGEST ranges_offset
= attr
->as_unsigned ();
14058 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14060 if (die
->tag
!= DW_TAG_compile_unit
)
14061 ranges_offset
+= cu
->gnu_ranges_base
;
14063 /* Value of the DW_AT_ranges attribute is the offset in the
14064 .debug_ranges section. */
14065 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14067 return PC_BOUNDS_INVALID
;
14068 /* Found discontinuous range of addresses. */
14069 ret
= PC_BOUNDS_RANGES
;
14072 return PC_BOUNDS_NOT_PRESENT
;
14075 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14077 return PC_BOUNDS_INVALID
;
14079 /* When using the GNU linker, .gnu.linkonce. sections are used to
14080 eliminate duplicate copies of functions and vtables and such.
14081 The linker will arbitrarily choose one and discard the others.
14082 The AT_*_pc values for such functions refer to local labels in
14083 these sections. If the section from that file was discarded, the
14084 labels are not in the output, so the relocs get a value of 0.
14085 If this is a discarded function, mark the pc bounds as invalid,
14086 so that GDB will ignore it. */
14087 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14088 return PC_BOUNDS_INVALID
;
14096 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14097 its low and high PC addresses. Do nothing if these addresses could not
14098 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14099 and HIGHPC to the high address if greater than HIGHPC. */
14102 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14103 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14104 struct dwarf2_cu
*cu
)
14106 CORE_ADDR low
, high
;
14107 struct die_info
*child
= die
->child
;
14109 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14111 *lowpc
= std::min (*lowpc
, low
);
14112 *highpc
= std::max (*highpc
, high
);
14115 /* If the language does not allow nested subprograms (either inside
14116 subprograms or lexical blocks), we're done. */
14117 if (cu
->per_cu
->lang
!= language_ada
)
14120 /* Check all the children of the given DIE. If it contains nested
14121 subprograms, then check their pc bounds. Likewise, we need to
14122 check lexical blocks as well, as they may also contain subprogram
14124 while (child
&& child
->tag
)
14126 if (child
->tag
== DW_TAG_subprogram
14127 || child
->tag
== DW_TAG_lexical_block
)
14128 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14129 child
= child
->sibling
;
14133 /* Get the low and high pc's represented by the scope DIE, and store
14134 them in *LOWPC and *HIGHPC. If the correct values can't be
14135 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14138 get_scope_pc_bounds (struct die_info
*die
,
14139 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14140 struct dwarf2_cu
*cu
)
14142 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14143 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14144 CORE_ADDR current_low
, current_high
;
14146 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14147 >= PC_BOUNDS_RANGES
)
14149 best_low
= current_low
;
14150 best_high
= current_high
;
14154 struct die_info
*child
= die
->child
;
14156 while (child
&& child
->tag
)
14158 switch (child
->tag
) {
14159 case DW_TAG_subprogram
:
14160 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14162 case DW_TAG_namespace
:
14163 case DW_TAG_module
:
14164 /* FIXME: carlton/2004-01-16: Should we do this for
14165 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14166 that current GCC's always emit the DIEs corresponding
14167 to definitions of methods of classes as children of a
14168 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14169 the DIEs giving the declarations, which could be
14170 anywhere). But I don't see any reason why the
14171 standards says that they have to be there. */
14172 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14174 if (current_low
!= ((CORE_ADDR
) -1))
14176 best_low
= std::min (best_low
, current_low
);
14177 best_high
= std::max (best_high
, current_high
);
14185 child
= child
->sibling
;
14190 *highpc
= best_high
;
14193 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14197 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14198 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14200 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14201 struct gdbarch
*gdbarch
= objfile
->arch ();
14202 struct attribute
*attr
;
14203 struct attribute
*attr_high
;
14205 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14208 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14209 if (attr
!= nullptr)
14211 CORE_ADDR low
= attr
->as_address ();
14212 CORE_ADDR high
= attr_high
->as_address ();
14214 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14217 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14218 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14219 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14223 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14224 if (attr
!= nullptr && attr
->form_is_unsigned ())
14226 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14227 on DWARF version). */
14228 ULONGEST ranges_offset
= attr
->as_unsigned ();
14230 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14232 if (die
->tag
!= DW_TAG_compile_unit
)
14233 ranges_offset
+= cu
->gnu_ranges_base
;
14235 std::vector
<blockrange
> blockvec
;
14236 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14237 [&] (CORE_ADDR start
, CORE_ADDR end
)
14241 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14242 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14243 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14244 blockvec
.emplace_back (start
, end
);
14247 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14251 /* Check whether the producer field indicates either of GCC < 4.6, or the
14252 Intel C/C++ compiler, and cache the result in CU. */
14255 check_producer (struct dwarf2_cu
*cu
)
14259 if (cu
->producer
== NULL
)
14261 /* For unknown compilers expect their behavior is DWARF version
14264 GCC started to support .debug_types sections by -gdwarf-4 since
14265 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14266 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14267 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14268 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14270 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14272 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14273 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14275 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14277 cu
->producer_is_icc
= true;
14278 cu
->producer_is_icc_lt_14
= major
< 14;
14280 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14281 cu
->producer_is_codewarrior
= true;
14284 /* For other non-GCC compilers, expect their behavior is DWARF version
14288 cu
->checked_producer
= true;
14291 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14292 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14293 during 4.6.0 experimental. */
14296 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14298 if (!cu
->checked_producer
)
14299 check_producer (cu
);
14301 return cu
->producer_is_gxx_lt_4_6
;
14305 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14306 with incorrect is_stmt attributes. */
14309 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14311 if (!cu
->checked_producer
)
14312 check_producer (cu
);
14314 return cu
->producer_is_codewarrior
;
14317 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14318 If that attribute is not available, return the appropriate
14321 static enum dwarf_access_attribute
14322 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14324 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14325 if (attr
!= nullptr)
14327 LONGEST value
= attr
->constant_value (-1);
14328 if (value
== DW_ACCESS_public
14329 || value
== DW_ACCESS_protected
14330 || value
== DW_ACCESS_private
)
14331 return (dwarf_access_attribute
) value
;
14332 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14336 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14338 /* The default DWARF 2 accessibility for members is public, the default
14339 accessibility for inheritance is private. */
14341 if (die
->tag
!= DW_TAG_inheritance
)
14342 return DW_ACCESS_public
;
14344 return DW_ACCESS_private
;
14348 /* DWARF 3+ defines the default accessibility a different way. The same
14349 rules apply now for DW_TAG_inheritance as for the members and it only
14350 depends on the container kind. */
14352 if (die
->parent
->tag
== DW_TAG_class_type
)
14353 return DW_ACCESS_private
;
14355 return DW_ACCESS_public
;
14359 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14360 offset. If the attribute was not found return 0, otherwise return
14361 1. If it was found but could not properly be handled, set *OFFSET
14365 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14368 struct attribute
*attr
;
14370 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14375 /* Note that we do not check for a section offset first here.
14376 This is because DW_AT_data_member_location is new in DWARF 4,
14377 so if we see it, we can assume that a constant form is really
14378 a constant and not a section offset. */
14379 if (attr
->form_is_constant ())
14380 *offset
= attr
->constant_value (0);
14381 else if (attr
->form_is_section_offset ())
14382 dwarf2_complex_location_expr_complaint ();
14383 else if (attr
->form_is_block ())
14384 *offset
= decode_locdesc (attr
->as_block (), cu
);
14386 dwarf2_complex_location_expr_complaint ();
14394 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14397 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14398 struct field
*field
)
14400 struct attribute
*attr
;
14402 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14405 if (attr
->form_is_constant ())
14407 LONGEST offset
= attr
->constant_value (0);
14408 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14410 else if (attr
->form_is_section_offset ())
14411 dwarf2_complex_location_expr_complaint ();
14412 else if (attr
->form_is_block ())
14415 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14417 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14420 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14421 struct objfile
*objfile
= per_objfile
->objfile
;
14422 struct dwarf2_locexpr_baton
*dlbaton
14423 = XOBNEW (&objfile
->objfile_obstack
,
14424 struct dwarf2_locexpr_baton
);
14425 dlbaton
->data
= attr
->as_block ()->data
;
14426 dlbaton
->size
= attr
->as_block ()->size
;
14427 /* When using this baton, we want to compute the address
14428 of the field, not the value. This is why
14429 is_reference is set to false here. */
14430 dlbaton
->is_reference
= false;
14431 dlbaton
->per_objfile
= per_objfile
;
14432 dlbaton
->per_cu
= cu
->per_cu
;
14434 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14438 dwarf2_complex_location_expr_complaint ();
14442 /* Add an aggregate field to the field list. */
14445 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14446 struct dwarf2_cu
*cu
)
14448 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14449 struct gdbarch
*gdbarch
= objfile
->arch ();
14450 struct nextfield
*new_field
;
14451 struct attribute
*attr
;
14453 const char *fieldname
= "";
14455 if (die
->tag
== DW_TAG_inheritance
)
14457 fip
->baseclasses
.emplace_back ();
14458 new_field
= &fip
->baseclasses
.back ();
14462 fip
->fields
.emplace_back ();
14463 new_field
= &fip
->fields
.back ();
14466 new_field
->offset
= die
->sect_off
;
14468 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14469 if (new_field
->accessibility
!= DW_ACCESS_public
)
14470 fip
->non_public_fields
= true;
14472 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14473 if (attr
!= nullptr)
14474 new_field
->virtuality
= attr
->as_virtuality ();
14476 new_field
->virtuality
= DW_VIRTUALITY_none
;
14478 fp
= &new_field
->field
;
14480 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14482 /* Data member other than a C++ static data member. */
14484 /* Get type of field. */
14485 fp
->set_type (die_type (die
, cu
));
14487 SET_FIELD_BITPOS (*fp
, 0);
14489 /* Get bit size of field (zero if none). */
14490 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14491 if (attr
!= nullptr)
14493 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14497 FIELD_BITSIZE (*fp
) = 0;
14500 /* Get bit offset of field. */
14501 handle_data_member_location (die
, cu
, fp
);
14502 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14503 if (attr
!= nullptr && attr
->form_is_constant ())
14505 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14507 /* For big endian bits, the DW_AT_bit_offset gives the
14508 additional bit offset from the MSB of the containing
14509 anonymous object to the MSB of the field. We don't
14510 have to do anything special since we don't need to
14511 know the size of the anonymous object. */
14512 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14513 + attr
->constant_value (0)));
14517 /* For little endian bits, compute the bit offset to the
14518 MSB of the anonymous object, subtract off the number of
14519 bits from the MSB of the field to the MSB of the
14520 object, and then subtract off the number of bits of
14521 the field itself. The result is the bit offset of
14522 the LSB of the field. */
14523 int anonymous_size
;
14524 int bit_offset
= attr
->constant_value (0);
14526 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14527 if (attr
!= nullptr && attr
->form_is_constant ())
14529 /* The size of the anonymous object containing
14530 the bit field is explicit, so use the
14531 indicated size (in bytes). */
14532 anonymous_size
= attr
->constant_value (0);
14536 /* The size of the anonymous object containing
14537 the bit field must be inferred from the type
14538 attribute of the data member containing the
14540 anonymous_size
= TYPE_LENGTH (fp
->type ());
14542 SET_FIELD_BITPOS (*fp
,
14543 (FIELD_BITPOS (*fp
)
14544 + anonymous_size
* bits_per_byte
14545 - bit_offset
- FIELD_BITSIZE (*fp
)));
14548 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14550 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14551 + attr
->constant_value (0)));
14553 /* Get name of field. */
14554 fieldname
= dwarf2_name (die
, cu
);
14555 if (fieldname
== NULL
)
14558 /* The name is already allocated along with this objfile, so we don't
14559 need to duplicate it for the type. */
14560 fp
->name
= fieldname
;
14562 /* Change accessibility for artificial fields (e.g. virtual table
14563 pointer or virtual base class pointer) to private. */
14564 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14566 FIELD_ARTIFICIAL (*fp
) = 1;
14567 new_field
->accessibility
= DW_ACCESS_private
;
14568 fip
->non_public_fields
= true;
14571 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14573 /* C++ static member. */
14575 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14576 is a declaration, but all versions of G++ as of this writing
14577 (so through at least 3.2.1) incorrectly generate
14578 DW_TAG_variable tags. */
14580 const char *physname
;
14582 /* Get name of field. */
14583 fieldname
= dwarf2_name (die
, cu
);
14584 if (fieldname
== NULL
)
14587 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14589 /* Only create a symbol if this is an external value.
14590 new_symbol checks this and puts the value in the global symbol
14591 table, which we want. If it is not external, new_symbol
14592 will try to put the value in cu->list_in_scope which is wrong. */
14593 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14595 /* A static const member, not much different than an enum as far as
14596 we're concerned, except that we can support more types. */
14597 new_symbol (die
, NULL
, cu
);
14600 /* Get physical name. */
14601 physname
= dwarf2_physname (fieldname
, die
, cu
);
14603 /* The name is already allocated along with this objfile, so we don't
14604 need to duplicate it for the type. */
14605 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14606 fp
->set_type (die_type (die
, cu
));
14607 FIELD_NAME (*fp
) = fieldname
;
14609 else if (die
->tag
== DW_TAG_inheritance
)
14611 /* C++ base class field. */
14612 handle_data_member_location (die
, cu
, fp
);
14613 FIELD_BITSIZE (*fp
) = 0;
14614 fp
->set_type (die_type (die
, cu
));
14615 FIELD_NAME (*fp
) = fp
->type ()->name ();
14618 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14621 /* Can the type given by DIE define another type? */
14624 type_can_define_types (const struct die_info
*die
)
14628 case DW_TAG_typedef
:
14629 case DW_TAG_class_type
:
14630 case DW_TAG_structure_type
:
14631 case DW_TAG_union_type
:
14632 case DW_TAG_enumeration_type
:
14640 /* Add a type definition defined in the scope of the FIP's class. */
14643 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14644 struct dwarf2_cu
*cu
)
14646 struct decl_field fp
;
14647 memset (&fp
, 0, sizeof (fp
));
14649 gdb_assert (type_can_define_types (die
));
14651 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14652 fp
.name
= dwarf2_name (die
, cu
);
14653 fp
.type
= read_type_die (die
, cu
);
14655 /* Save accessibility. */
14656 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14657 switch (accessibility
)
14659 case DW_ACCESS_public
:
14660 /* The assumed value if neither private nor protected. */
14662 case DW_ACCESS_private
:
14665 case DW_ACCESS_protected
:
14666 fp
.is_protected
= 1;
14670 if (die
->tag
== DW_TAG_typedef
)
14671 fip
->typedef_field_list
.push_back (fp
);
14673 fip
->nested_types_list
.push_back (fp
);
14676 /* A convenience typedef that's used when finding the discriminant
14677 field for a variant part. */
14678 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14681 /* Compute the discriminant range for a given variant. OBSTACK is
14682 where the results will be stored. VARIANT is the variant to
14683 process. IS_UNSIGNED indicates whether the discriminant is signed
14686 static const gdb::array_view
<discriminant_range
>
14687 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14690 std::vector
<discriminant_range
> ranges
;
14692 if (variant
.default_branch
)
14695 if (variant
.discr_list_data
== nullptr)
14697 discriminant_range r
14698 = {variant
.discriminant_value
, variant
.discriminant_value
};
14699 ranges
.push_back (r
);
14703 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14704 variant
.discr_list_data
->size
);
14705 while (!data
.empty ())
14707 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14709 complaint (_("invalid discriminant marker: %d"), data
[0]);
14712 bool is_range
= data
[0] == DW_DSC_range
;
14713 data
= data
.slice (1);
14715 ULONGEST low
, high
;
14716 unsigned int bytes_read
;
14720 complaint (_("DW_AT_discr_list missing low value"));
14724 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14726 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14728 data
= data
.slice (bytes_read
);
14734 complaint (_("DW_AT_discr_list missing high value"));
14738 high
= read_unsigned_leb128 (nullptr, data
.data (),
14741 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14743 data
= data
.slice (bytes_read
);
14748 ranges
.push_back ({ low
, high
});
14752 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14754 std::copy (ranges
.begin (), ranges
.end (), result
);
14755 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14758 static const gdb::array_view
<variant_part
> create_variant_parts
14759 (struct obstack
*obstack
,
14760 const offset_map_type
&offset_map
,
14761 struct field_info
*fi
,
14762 const std::vector
<variant_part_builder
> &variant_parts
);
14764 /* Fill in a "struct variant" for a given variant field. RESULT is
14765 the variant to fill in. OBSTACK is where any needed allocations
14766 will be done. OFFSET_MAP holds the mapping from section offsets to
14767 fields for the type. FI describes the fields of the type we're
14768 processing. FIELD is the variant field we're converting. */
14771 create_one_variant (variant
&result
, struct obstack
*obstack
,
14772 const offset_map_type
&offset_map
,
14773 struct field_info
*fi
, const variant_field
&field
)
14775 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14776 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14777 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14778 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14779 field
.variant_parts
);
14782 /* Fill in a "struct variant_part" for a given variant part. RESULT
14783 is the variant part to fill in. OBSTACK is where any needed
14784 allocations will be done. OFFSET_MAP holds the mapping from
14785 section offsets to fields for the type. FI describes the fields of
14786 the type we're processing. BUILDER is the variant part to be
14790 create_one_variant_part (variant_part
&result
,
14791 struct obstack
*obstack
,
14792 const offset_map_type
&offset_map
,
14793 struct field_info
*fi
,
14794 const variant_part_builder
&builder
)
14796 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14797 if (iter
== offset_map
.end ())
14799 result
.discriminant_index
= -1;
14800 /* Doesn't matter. */
14801 result
.is_unsigned
= false;
14805 result
.discriminant_index
= iter
->second
;
14807 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14810 size_t n
= builder
.variants
.size ();
14811 variant
*output
= new (obstack
) variant
[n
];
14812 for (size_t i
= 0; i
< n
; ++i
)
14813 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14814 builder
.variants
[i
]);
14816 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14819 /* Create a vector of variant parts that can be attached to a type.
14820 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14821 holds the mapping from section offsets to fields for the type. FI
14822 describes the fields of the type we're processing. VARIANT_PARTS
14823 is the vector to convert. */
14825 static const gdb::array_view
<variant_part
>
14826 create_variant_parts (struct obstack
*obstack
,
14827 const offset_map_type
&offset_map
,
14828 struct field_info
*fi
,
14829 const std::vector
<variant_part_builder
> &variant_parts
)
14831 if (variant_parts
.empty ())
14834 size_t n
= variant_parts
.size ();
14835 variant_part
*result
= new (obstack
) variant_part
[n
];
14836 for (size_t i
= 0; i
< n
; ++i
)
14837 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14840 return gdb::array_view
<variant_part
> (result
, n
);
14843 /* Compute the variant part vector for FIP, attaching it to TYPE when
14847 add_variant_property (struct field_info
*fip
, struct type
*type
,
14848 struct dwarf2_cu
*cu
)
14850 /* Map section offsets of fields to their field index. Note the
14851 field index here does not take the number of baseclasses into
14853 offset_map_type offset_map
;
14854 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14855 offset_map
[fip
->fields
[i
].offset
] = i
;
14857 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14858 gdb::array_view
<variant_part
> parts
14859 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14860 fip
->variant_parts
);
14862 struct dynamic_prop prop
;
14863 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14864 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14867 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14870 /* Create the vector of fields, and attach it to the type. */
14873 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14874 struct dwarf2_cu
*cu
)
14876 int nfields
= fip
->nfields ();
14878 /* Record the field count, allocate space for the array of fields,
14879 and create blank accessibility bitfields if necessary. */
14880 type
->set_num_fields (nfields
);
14882 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14884 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
14886 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14888 TYPE_FIELD_PRIVATE_BITS (type
) =
14889 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14890 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14892 TYPE_FIELD_PROTECTED_BITS (type
) =
14893 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14894 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14896 TYPE_FIELD_IGNORE_BITS (type
) =
14897 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14898 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14901 /* If the type has baseclasses, allocate and clear a bit vector for
14902 TYPE_FIELD_VIRTUAL_BITS. */
14903 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
14905 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14906 unsigned char *pointer
;
14908 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14909 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14910 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14911 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14912 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14915 if (!fip
->variant_parts
.empty ())
14916 add_variant_property (fip
, type
, cu
);
14918 /* Copy the saved-up fields into the field vector. */
14919 for (int i
= 0; i
< nfields
; ++i
)
14921 struct nextfield
&field
14922 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14923 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14925 type
->field (i
) = field
.field
;
14926 switch (field
.accessibility
)
14928 case DW_ACCESS_private
:
14929 if (cu
->per_cu
->lang
!= language_ada
)
14930 SET_TYPE_FIELD_PRIVATE (type
, i
);
14933 case DW_ACCESS_protected
:
14934 if (cu
->per_cu
->lang
!= language_ada
)
14935 SET_TYPE_FIELD_PROTECTED (type
, i
);
14938 case DW_ACCESS_public
:
14942 /* Unknown accessibility. Complain and treat it as public. */
14944 complaint (_("unsupported accessibility %d"),
14945 field
.accessibility
);
14949 if (i
< fip
->baseclasses
.size ())
14951 switch (field
.virtuality
)
14953 case DW_VIRTUALITY_virtual
:
14954 case DW_VIRTUALITY_pure_virtual
:
14955 if (cu
->per_cu
->lang
== language_ada
)
14956 error (_("unexpected virtuality in component of Ada type"));
14957 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14964 /* Return true if this member function is a constructor, false
14968 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14970 const char *fieldname
;
14971 const char *type_name
;
14974 if (die
->parent
== NULL
)
14977 if (die
->parent
->tag
!= DW_TAG_structure_type
14978 && die
->parent
->tag
!= DW_TAG_union_type
14979 && die
->parent
->tag
!= DW_TAG_class_type
)
14982 fieldname
= dwarf2_name (die
, cu
);
14983 type_name
= dwarf2_name (die
->parent
, cu
);
14984 if (fieldname
== NULL
|| type_name
== NULL
)
14987 len
= strlen (fieldname
);
14988 return (strncmp (fieldname
, type_name
, len
) == 0
14989 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14992 /* Add a member function to the proper fieldlist. */
14995 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14996 struct type
*type
, struct dwarf2_cu
*cu
)
14998 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14999 struct attribute
*attr
;
15001 struct fnfieldlist
*flp
= nullptr;
15002 struct fn_field
*fnp
;
15003 const char *fieldname
;
15004 struct type
*this_type
;
15006 if (cu
->per_cu
->lang
== language_ada
)
15007 error (_("unexpected member function in Ada type"));
15009 /* Get name of member function. */
15010 fieldname
= dwarf2_name (die
, cu
);
15011 if (fieldname
== NULL
)
15014 /* Look up member function name in fieldlist. */
15015 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15017 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15019 flp
= &fip
->fnfieldlists
[i
];
15024 /* Create a new fnfieldlist if necessary. */
15025 if (flp
== nullptr)
15027 fip
->fnfieldlists
.emplace_back ();
15028 flp
= &fip
->fnfieldlists
.back ();
15029 flp
->name
= fieldname
;
15030 i
= fip
->fnfieldlists
.size () - 1;
15033 /* Create a new member function field and add it to the vector of
15035 flp
->fnfields
.emplace_back ();
15036 fnp
= &flp
->fnfields
.back ();
15038 /* Delay processing of the physname until later. */
15039 if (cu
->per_cu
->lang
== language_cplus
)
15040 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15044 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15045 fnp
->physname
= physname
? physname
: "";
15048 fnp
->type
= alloc_type (objfile
);
15049 this_type
= read_type_die (die
, cu
);
15050 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15052 int nparams
= this_type
->num_fields ();
15054 /* TYPE is the domain of this method, and THIS_TYPE is the type
15055 of the method itself (TYPE_CODE_METHOD). */
15056 smash_to_method_type (fnp
->type
, type
,
15057 TYPE_TARGET_TYPE (this_type
),
15058 this_type
->fields (),
15059 this_type
->num_fields (),
15060 this_type
->has_varargs ());
15062 /* Handle static member functions.
15063 Dwarf2 has no clean way to discern C++ static and non-static
15064 member functions. G++ helps GDB by marking the first
15065 parameter for non-static member functions (which is the this
15066 pointer) as artificial. We obtain this information from
15067 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15068 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15069 fnp
->voffset
= VOFFSET_STATIC
;
15072 complaint (_("member function type missing for '%s'"),
15073 dwarf2_full_name (fieldname
, die
, cu
));
15075 /* Get fcontext from DW_AT_containing_type if present. */
15076 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15077 fnp
->fcontext
= die_containing_type (die
, cu
);
15079 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15080 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15082 /* Get accessibility. */
15083 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15084 switch (accessibility
)
15086 case DW_ACCESS_private
:
15087 fnp
->is_private
= 1;
15089 case DW_ACCESS_protected
:
15090 fnp
->is_protected
= 1;
15094 /* Check for artificial methods. */
15095 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15096 if (attr
&& attr
->as_boolean ())
15097 fnp
->is_artificial
= 1;
15099 /* Check for defaulted methods. */
15100 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15101 if (attr
!= nullptr)
15102 fnp
->defaulted
= attr
->defaulted ();
15104 /* Check for deleted methods. */
15105 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15106 if (attr
!= nullptr && attr
->as_boolean ())
15107 fnp
->is_deleted
= 1;
15109 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15111 /* Get index in virtual function table if it is a virtual member
15112 function. For older versions of GCC, this is an offset in the
15113 appropriate virtual table, as specified by DW_AT_containing_type.
15114 For everyone else, it is an expression to be evaluated relative
15115 to the object address. */
15117 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15118 if (attr
!= nullptr)
15120 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15122 struct dwarf_block
*block
= attr
->as_block ();
15124 if (block
->data
[0] == DW_OP_constu
)
15126 /* Old-style GCC. */
15127 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15129 else if (block
->data
[0] == DW_OP_deref
15130 || (block
->size
> 1
15131 && block
->data
[0] == DW_OP_deref_size
15132 && block
->data
[1] == cu
->header
.addr_size
))
15134 fnp
->voffset
= decode_locdesc (block
, cu
);
15135 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15136 dwarf2_complex_location_expr_complaint ();
15138 fnp
->voffset
/= cu
->header
.addr_size
;
15142 dwarf2_complex_location_expr_complaint ();
15144 if (!fnp
->fcontext
)
15146 /* If there is no `this' field and no DW_AT_containing_type,
15147 we cannot actually find a base class context for the
15149 if (this_type
->num_fields () == 0
15150 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15152 complaint (_("cannot determine context for virtual member "
15153 "function \"%s\" (offset %s)"),
15154 fieldname
, sect_offset_str (die
->sect_off
));
15159 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15163 else if (attr
->form_is_section_offset ())
15165 dwarf2_complex_location_expr_complaint ();
15169 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15175 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15176 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15178 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15179 complaint (_("Member function \"%s\" (offset %s) is virtual "
15180 "but the vtable offset is not specified"),
15181 fieldname
, sect_offset_str (die
->sect_off
));
15182 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15183 TYPE_CPLUS_DYNAMIC (type
) = 1;
15188 /* Create the vector of member function fields, and attach it to the type. */
15191 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15192 struct dwarf2_cu
*cu
)
15194 if (cu
->per_cu
->lang
== language_ada
)
15195 error (_("unexpected member functions in Ada type"));
15197 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15198 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15200 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15202 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15204 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15205 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15207 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15208 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15209 fn_flp
->fn_fields
= (struct fn_field
*)
15210 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15212 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15213 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15216 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15219 /* Returns non-zero if NAME is the name of a vtable member in CU's
15220 language, zero otherwise. */
15222 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15224 static const char vptr
[] = "_vptr";
15226 /* Look for the C++ form of the vtable. */
15227 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15233 /* GCC outputs unnamed structures that are really pointers to member
15234 functions, with the ABI-specified layout. If TYPE describes
15235 such a structure, smash it into a member function type.
15237 GCC shouldn't do this; it should just output pointer to member DIEs.
15238 This is GCC PR debug/28767. */
15241 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15243 struct type
*pfn_type
, *self_type
, *new_type
;
15245 /* Check for a structure with no name and two children. */
15246 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15249 /* Check for __pfn and __delta members. */
15250 if (TYPE_FIELD_NAME (type
, 0) == NULL
15251 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15252 || TYPE_FIELD_NAME (type
, 1) == NULL
15253 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15256 /* Find the type of the method. */
15257 pfn_type
= type
->field (0).type ();
15258 if (pfn_type
== NULL
15259 || pfn_type
->code () != TYPE_CODE_PTR
15260 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15263 /* Look for the "this" argument. */
15264 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15265 if (pfn_type
->num_fields () == 0
15266 /* || pfn_type->field (0).type () == NULL */
15267 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15270 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15271 new_type
= alloc_type (objfile
);
15272 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15273 pfn_type
->fields (), pfn_type
->num_fields (),
15274 pfn_type
->has_varargs ());
15275 smash_to_methodptr_type (type
, new_type
);
15278 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15279 requires rewriting, then copy it and return the updated copy.
15280 Otherwise return nullptr. */
15282 static struct type
*
15283 rewrite_array_type (struct type
*type
)
15285 if (type
->code () != TYPE_CODE_ARRAY
)
15288 struct type
*index_type
= type
->index_type ();
15289 range_bounds
*current_bounds
= index_type
->bounds ();
15291 /* Handle multi-dimensional arrays. */
15292 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15293 if (new_target
== nullptr)
15295 /* Maybe we don't need to rewrite this array. */
15296 if (current_bounds
->low
.kind () == PROP_CONST
15297 && current_bounds
->high
.kind () == PROP_CONST
)
15301 /* Either the target type was rewritten, or the bounds have to be
15302 updated. Either way we want to copy the type and update
15304 struct type
*copy
= copy_type (type
);
15305 int nfields
= copy
->num_fields ();
15307 = ((struct field
*) TYPE_ZALLOC (copy
,
15308 nfields
* sizeof (struct field
)));
15309 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15310 copy
->set_fields (new_fields
);
15311 if (new_target
!= nullptr)
15312 TYPE_TARGET_TYPE (copy
) = new_target
;
15314 struct type
*index_copy
= copy_type (index_type
);
15315 range_bounds
*bounds
15316 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15317 sizeof (range_bounds
));
15318 *bounds
= *current_bounds
;
15319 bounds
->low
.set_const_val (1);
15320 bounds
->high
.set_const_val (0);
15321 index_copy
->set_bounds (bounds
);
15322 copy
->set_index_type (index_copy
);
15327 /* While some versions of GCC will generate complicated DWARF for an
15328 array (see quirk_ada_thick_pointer), more recent versions were
15329 modified to emit an explicit thick pointer structure. However, in
15330 this case, the array still has DWARF expressions for its ranges,
15331 and these must be ignored. */
15334 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15337 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15339 /* Check for a structure with two children. */
15340 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15343 /* Check for P_ARRAY and P_BOUNDS members. */
15344 if (TYPE_FIELD_NAME (type
, 0) == NULL
15345 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15346 || TYPE_FIELD_NAME (type
, 1) == NULL
15347 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15350 /* Make sure we're looking at a pointer to an array. */
15351 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15354 /* The Ada code already knows how to handle these types, so all that
15355 we need to do is turn the bounds into static bounds. However, we
15356 don't want to rewrite existing array or index types in-place,
15357 because those may be referenced in other contexts where this
15358 rewriting is undesirable. */
15359 struct type
*new_ary_type
15360 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15361 if (new_ary_type
!= nullptr)
15362 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15365 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15366 appropriate error checking and issuing complaints if there is a
15370 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15372 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15374 if (attr
== nullptr)
15377 if (!attr
->form_is_constant ())
15379 complaint (_("DW_AT_alignment must have constant form"
15380 " - DIE at %s [in module %s]"),
15381 sect_offset_str (die
->sect_off
),
15382 objfile_name (cu
->per_objfile
->objfile
));
15386 LONGEST val
= attr
->constant_value (0);
15389 complaint (_("DW_AT_alignment value must not be negative"
15390 " - DIE at %s [in module %s]"),
15391 sect_offset_str (die
->sect_off
),
15392 objfile_name (cu
->per_objfile
->objfile
));
15395 ULONGEST align
= val
;
15399 complaint (_("DW_AT_alignment value must not be zero"
15400 " - DIE at %s [in module %s]"),
15401 sect_offset_str (die
->sect_off
),
15402 objfile_name (cu
->per_objfile
->objfile
));
15405 if ((align
& (align
- 1)) != 0)
15407 complaint (_("DW_AT_alignment value must be a power of 2"
15408 " - DIE at %s [in module %s]"),
15409 sect_offset_str (die
->sect_off
),
15410 objfile_name (cu
->per_objfile
->objfile
));
15417 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15418 the alignment for TYPE. */
15421 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15424 if (!set_type_align (type
, get_alignment (cu
, die
)))
15425 complaint (_("DW_AT_alignment value too large"
15426 " - DIE at %s [in module %s]"),
15427 sect_offset_str (die
->sect_off
),
15428 objfile_name (cu
->per_objfile
->objfile
));
15431 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15432 constant for a type, according to DWARF5 spec, Table 5.5. */
15435 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15440 case DW_CC_pass_by_reference
:
15441 case DW_CC_pass_by_value
:
15445 complaint (_("unrecognized DW_AT_calling_convention value "
15446 "(%s) for a type"), pulongest (value
));
15451 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15452 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15453 also according to GNU-specific values (see include/dwarf2.h). */
15456 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15461 case DW_CC_program
:
15465 case DW_CC_GNU_renesas_sh
:
15466 case DW_CC_GNU_borland_fastcall_i386
:
15467 case DW_CC_GDB_IBM_OpenCL
:
15471 complaint (_("unrecognized DW_AT_calling_convention value "
15472 "(%s) for a subroutine"), pulongest (value
));
15477 /* Called when we find the DIE that starts a structure or union scope
15478 (definition) to create a type for the structure or union. Fill in
15479 the type's name and general properties; the members will not be
15480 processed until process_structure_scope. A symbol table entry for
15481 the type will also not be done until process_structure_scope (assuming
15482 the type has a name).
15484 NOTE: we need to call these functions regardless of whether or not the
15485 DIE has a DW_AT_name attribute, since it might be an anonymous
15486 structure or union. This gets the type entered into our set of
15487 user defined types. */
15489 static struct type
*
15490 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15492 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15494 struct attribute
*attr
;
15497 /* If the definition of this type lives in .debug_types, read that type.
15498 Don't follow DW_AT_specification though, that will take us back up
15499 the chain and we want to go down. */
15500 attr
= die
->attr (DW_AT_signature
);
15501 if (attr
!= nullptr)
15503 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15505 /* The type's CU may not be the same as CU.
15506 Ensure TYPE is recorded with CU in die_type_hash. */
15507 return set_die_type (die
, type
, cu
);
15510 type
= alloc_type (objfile
);
15511 INIT_CPLUS_SPECIFIC (type
);
15513 name
= dwarf2_name (die
, cu
);
15516 if (cu
->per_cu
->lang
== language_cplus
15517 || cu
->per_cu
->lang
== language_d
15518 || cu
->per_cu
->lang
== language_rust
)
15520 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15522 /* dwarf2_full_name might have already finished building the DIE's
15523 type. If so, there is no need to continue. */
15524 if (get_die_type (die
, cu
) != NULL
)
15525 return get_die_type (die
, cu
);
15527 type
->set_name (full_name
);
15531 /* The name is already allocated along with this objfile, so
15532 we don't need to duplicate it for the type. */
15533 type
->set_name (name
);
15537 if (die
->tag
== DW_TAG_structure_type
)
15539 type
->set_code (TYPE_CODE_STRUCT
);
15541 else if (die
->tag
== DW_TAG_union_type
)
15543 type
->set_code (TYPE_CODE_UNION
);
15547 type
->set_code (TYPE_CODE_STRUCT
);
15550 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15551 type
->set_is_declared_class (true);
15553 /* Store the calling convention in the type if it's available in
15554 the die. Otherwise the calling convention remains set to
15555 the default value DW_CC_normal. */
15556 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15557 if (attr
!= nullptr
15558 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15560 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15561 TYPE_CPLUS_CALLING_CONVENTION (type
)
15562 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15565 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15566 if (attr
!= nullptr)
15568 if (attr
->form_is_constant ())
15569 TYPE_LENGTH (type
) = attr
->constant_value (0);
15572 struct dynamic_prop prop
;
15573 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15574 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15575 TYPE_LENGTH (type
) = 0;
15580 TYPE_LENGTH (type
) = 0;
15583 maybe_set_alignment (cu
, die
, type
);
15585 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15587 /* ICC<14 does not output the required DW_AT_declaration on
15588 incomplete types, but gives them a size of zero. */
15589 type
->set_is_stub (true);
15592 type
->set_stub_is_supported (true);
15594 if (die_is_declaration (die
, cu
))
15595 type
->set_is_stub (true);
15596 else if (attr
== NULL
&& die
->child
== NULL
15597 && producer_is_realview (cu
->producer
))
15598 /* RealView does not output the required DW_AT_declaration
15599 on incomplete types. */
15600 type
->set_is_stub (true);
15602 /* We need to add the type field to the die immediately so we don't
15603 infinitely recurse when dealing with pointers to the structure
15604 type within the structure itself. */
15605 set_die_type (die
, type
, cu
);
15607 /* set_die_type should be already done. */
15608 set_descriptive_type (type
, die
, cu
);
15613 static void handle_struct_member_die
15614 (struct die_info
*child_die
,
15616 struct field_info
*fi
,
15617 std::vector
<struct symbol
*> *template_args
,
15618 struct dwarf2_cu
*cu
);
15620 /* A helper for handle_struct_member_die that handles
15621 DW_TAG_variant_part. */
15624 handle_variant_part (struct die_info
*die
, struct type
*type
,
15625 struct field_info
*fi
,
15626 std::vector
<struct symbol
*> *template_args
,
15627 struct dwarf2_cu
*cu
)
15629 variant_part_builder
*new_part
;
15630 if (fi
->current_variant_part
== nullptr)
15632 fi
->variant_parts
.emplace_back ();
15633 new_part
= &fi
->variant_parts
.back ();
15635 else if (!fi
->current_variant_part
->processing_variant
)
15637 complaint (_("nested DW_TAG_variant_part seen "
15638 "- DIE at %s [in module %s]"),
15639 sect_offset_str (die
->sect_off
),
15640 objfile_name (cu
->per_objfile
->objfile
));
15645 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15646 current
.variant_parts
.emplace_back ();
15647 new_part
= ¤t
.variant_parts
.back ();
15650 /* When we recurse, we want callees to add to this new variant
15652 scoped_restore save_current_variant_part
15653 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15655 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15658 /* It's a univariant form, an extension we support. */
15660 else if (discr
->form_is_ref ())
15662 struct dwarf2_cu
*target_cu
= cu
;
15663 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15665 new_part
->discriminant_offset
= target_die
->sect_off
;
15669 complaint (_("DW_AT_discr does not have DIE reference form"
15670 " - DIE at %s [in module %s]"),
15671 sect_offset_str (die
->sect_off
),
15672 objfile_name (cu
->per_objfile
->objfile
));
15675 for (die_info
*child_die
= die
->child
;
15677 child_die
= child_die
->sibling
)
15678 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15681 /* A helper for handle_struct_member_die that handles
15685 handle_variant (struct die_info
*die
, struct type
*type
,
15686 struct field_info
*fi
,
15687 std::vector
<struct symbol
*> *template_args
,
15688 struct dwarf2_cu
*cu
)
15690 if (fi
->current_variant_part
== nullptr)
15692 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15693 "- DIE at %s [in module %s]"),
15694 sect_offset_str (die
->sect_off
),
15695 objfile_name (cu
->per_objfile
->objfile
));
15698 if (fi
->current_variant_part
->processing_variant
)
15700 complaint (_("nested DW_TAG_variant seen "
15701 "- DIE at %s [in module %s]"),
15702 sect_offset_str (die
->sect_off
),
15703 objfile_name (cu
->per_objfile
->objfile
));
15707 scoped_restore save_processing_variant
15708 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15711 fi
->current_variant_part
->variants
.emplace_back ();
15712 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15713 variant
.first_field
= fi
->fields
.size ();
15715 /* In a variant we want to get the discriminant and also add a
15716 field for our sole member child. */
15717 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15718 if (discr
== nullptr || !discr
->form_is_constant ())
15720 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15721 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15722 variant
.default_branch
= true;
15724 variant
.discr_list_data
= discr
->as_block ();
15727 variant
.discriminant_value
= discr
->constant_value (0);
15729 for (die_info
*variant_child
= die
->child
;
15730 variant_child
!= NULL
;
15731 variant_child
= variant_child
->sibling
)
15732 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15734 variant
.last_field
= fi
->fields
.size ();
15737 /* A helper for process_structure_scope that handles a single member
15741 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15742 struct field_info
*fi
,
15743 std::vector
<struct symbol
*> *template_args
,
15744 struct dwarf2_cu
*cu
)
15746 if (child_die
->tag
== DW_TAG_member
15747 || child_die
->tag
== DW_TAG_variable
)
15749 /* NOTE: carlton/2002-11-05: A C++ static data member
15750 should be a DW_TAG_member that is a declaration, but
15751 all versions of G++ as of this writing (so through at
15752 least 3.2.1) incorrectly generate DW_TAG_variable
15753 tags for them instead. */
15754 dwarf2_add_field (fi
, child_die
, cu
);
15756 else if (child_die
->tag
== DW_TAG_subprogram
)
15758 /* Rust doesn't have member functions in the C++ sense.
15759 However, it does emit ordinary functions as children
15760 of a struct DIE. */
15761 if (cu
->per_cu
->lang
== language_rust
)
15762 read_func_scope (child_die
, cu
);
15765 /* C++ member function. */
15766 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15769 else if (child_die
->tag
== DW_TAG_inheritance
)
15771 /* C++ base class field. */
15772 dwarf2_add_field (fi
, child_die
, cu
);
15774 else if (type_can_define_types (child_die
))
15775 dwarf2_add_type_defn (fi
, child_die
, cu
);
15776 else if (child_die
->tag
== DW_TAG_template_type_param
15777 || child_die
->tag
== DW_TAG_template_value_param
)
15779 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15782 template_args
->push_back (arg
);
15784 else if (child_die
->tag
== DW_TAG_variant_part
)
15785 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15786 else if (child_die
->tag
== DW_TAG_variant
)
15787 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15790 /* Finish creating a structure or union type, including filling in
15791 its members and creating a symbol for it. */
15794 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15796 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15797 struct die_info
*child_die
;
15800 type
= get_die_type (die
, cu
);
15802 type
= read_structure_type (die
, cu
);
15804 bool has_template_parameters
= false;
15805 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15807 struct field_info fi
;
15808 std::vector
<struct symbol
*> template_args
;
15810 child_die
= die
->child
;
15812 while (child_die
&& child_die
->tag
)
15814 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15815 child_die
= child_die
->sibling
;
15818 /* Attach template arguments to type. */
15819 if (!template_args
.empty ())
15821 has_template_parameters
= true;
15822 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15823 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15824 TYPE_TEMPLATE_ARGUMENTS (type
)
15825 = XOBNEWVEC (&objfile
->objfile_obstack
,
15827 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15828 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15829 template_args
.data (),
15830 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15831 * sizeof (struct symbol
*)));
15834 /* Attach fields and member functions to the type. */
15835 if (fi
.nfields () > 0)
15836 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15837 if (!fi
.fnfieldlists
.empty ())
15839 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15841 /* Get the type which refers to the base class (possibly this
15842 class itself) which contains the vtable pointer for the current
15843 class from the DW_AT_containing_type attribute. This use of
15844 DW_AT_containing_type is a GNU extension. */
15846 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15848 struct type
*t
= die_containing_type (die
, cu
);
15850 set_type_vptr_basetype (type
, t
);
15855 /* Our own class provides vtbl ptr. */
15856 for (i
= t
->num_fields () - 1;
15857 i
>= TYPE_N_BASECLASSES (t
);
15860 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15862 if (is_vtable_name (fieldname
, cu
))
15864 set_type_vptr_fieldno (type
, i
);
15869 /* Complain if virtual function table field not found. */
15870 if (i
< TYPE_N_BASECLASSES (t
))
15871 complaint (_("virtual function table pointer "
15872 "not found when defining class '%s'"),
15873 type
->name () ? type
->name () : "");
15877 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15880 else if (cu
->producer
15881 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15883 /* The IBM XLC compiler does not provide direct indication
15884 of the containing type, but the vtable pointer is
15885 always named __vfp. */
15889 for (i
= type
->num_fields () - 1;
15890 i
>= TYPE_N_BASECLASSES (type
);
15893 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15895 set_type_vptr_fieldno (type
, i
);
15896 set_type_vptr_basetype (type
, type
);
15903 /* Copy fi.typedef_field_list linked list elements content into the
15904 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15905 if (!fi
.typedef_field_list
.empty ())
15907 int count
= fi
.typedef_field_list
.size ();
15909 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15910 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15911 = ((struct decl_field
*)
15913 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15914 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15916 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15917 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15920 /* Copy fi.nested_types_list linked list elements content into the
15921 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15922 if (!fi
.nested_types_list
.empty ()
15923 && cu
->per_cu
->lang
!= language_ada
)
15925 int count
= fi
.nested_types_list
.size ();
15927 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15928 TYPE_NESTED_TYPES_ARRAY (type
)
15929 = ((struct decl_field
*)
15930 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15931 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15933 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15934 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15938 quirk_gcc_member_function_pointer (type
, objfile
);
15939 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15940 cu
->rust_unions
.push_back (type
);
15941 else if (cu
->per_cu
->lang
== language_ada
)
15942 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15944 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15945 snapshots) has been known to create a die giving a declaration
15946 for a class that has, as a child, a die giving a definition for a
15947 nested class. So we have to process our children even if the
15948 current die is a declaration. Normally, of course, a declaration
15949 won't have any children at all. */
15951 child_die
= die
->child
;
15953 while (child_die
!= NULL
&& child_die
->tag
)
15955 if (child_die
->tag
== DW_TAG_member
15956 || child_die
->tag
== DW_TAG_variable
15957 || child_die
->tag
== DW_TAG_inheritance
15958 || child_die
->tag
== DW_TAG_template_value_param
15959 || child_die
->tag
== DW_TAG_template_type_param
)
15964 process_die (child_die
, cu
);
15966 child_die
= child_die
->sibling
;
15969 /* Do not consider external references. According to the DWARF standard,
15970 these DIEs are identified by the fact that they have no byte_size
15971 attribute, and a declaration attribute. */
15972 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15973 || !die_is_declaration (die
, cu
)
15974 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15976 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15978 if (has_template_parameters
)
15980 struct symtab
*symtab
;
15981 if (sym
!= nullptr)
15982 symtab
= symbol_symtab (sym
);
15983 else if (cu
->line_header
!= nullptr)
15985 /* Any related symtab will do. */
15987 = cu
->line_header
->file_names ()[0].symtab
;
15992 complaint (_("could not find suitable "
15993 "symtab for template parameter"
15994 " - DIE at %s [in module %s]"),
15995 sect_offset_str (die
->sect_off
),
15996 objfile_name (objfile
));
15999 if (symtab
!= nullptr)
16001 /* Make sure that the symtab is set on the new symbols.
16002 Even though they don't appear in this symtab directly,
16003 other parts of gdb assume that symbols do, and this is
16004 reasonably true. */
16005 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16006 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16012 /* Assuming DIE is an enumeration type, and TYPE is its associated
16013 type, update TYPE using some information only available in DIE's
16014 children. In particular, the fields are computed. */
16017 update_enumeration_type_from_children (struct die_info
*die
,
16019 struct dwarf2_cu
*cu
)
16021 struct die_info
*child_die
;
16022 int unsigned_enum
= 1;
16025 auto_obstack obstack
;
16026 std::vector
<struct field
> fields
;
16028 for (child_die
= die
->child
;
16029 child_die
!= NULL
&& child_die
->tag
;
16030 child_die
= child_die
->sibling
)
16032 struct attribute
*attr
;
16034 const gdb_byte
*bytes
;
16035 struct dwarf2_locexpr_baton
*baton
;
16038 if (child_die
->tag
!= DW_TAG_enumerator
)
16041 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16045 name
= dwarf2_name (child_die
, cu
);
16047 name
= "<anonymous enumerator>";
16049 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16050 &value
, &bytes
, &baton
);
16058 if (count_one_bits_ll (value
) >= 2)
16062 fields
.emplace_back ();
16063 struct field
&field
= fields
.back ();
16064 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16065 SET_FIELD_ENUMVAL (field
, value
);
16068 if (!fields
.empty ())
16070 type
->set_num_fields (fields
.size ());
16073 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16074 memcpy (type
->fields (), fields
.data (),
16075 sizeof (struct field
) * fields
.size ());
16079 type
->set_is_unsigned (true);
16082 type
->set_is_flag_enum (true);
16085 /* Given a DW_AT_enumeration_type die, set its type. We do not
16086 complete the type's fields yet, or create any symbols. */
16088 static struct type
*
16089 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16091 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16093 struct attribute
*attr
;
16096 /* If the definition of this type lives in .debug_types, read that type.
16097 Don't follow DW_AT_specification though, that will take us back up
16098 the chain and we want to go down. */
16099 attr
= die
->attr (DW_AT_signature
);
16100 if (attr
!= nullptr)
16102 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16104 /* The type's CU may not be the same as CU.
16105 Ensure TYPE is recorded with CU in die_type_hash. */
16106 return set_die_type (die
, type
, cu
);
16109 type
= alloc_type (objfile
);
16111 type
->set_code (TYPE_CODE_ENUM
);
16112 name
= dwarf2_full_name (NULL
, die
, cu
);
16114 type
->set_name (name
);
16116 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16119 struct type
*underlying_type
= die_type (die
, cu
);
16121 TYPE_TARGET_TYPE (type
) = underlying_type
;
16124 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16125 if (attr
!= nullptr)
16127 TYPE_LENGTH (type
) = attr
->constant_value (0);
16131 TYPE_LENGTH (type
) = 0;
16134 maybe_set_alignment (cu
, die
, type
);
16136 /* The enumeration DIE can be incomplete. In Ada, any type can be
16137 declared as private in the package spec, and then defined only
16138 inside the package body. Such types are known as Taft Amendment
16139 Types. When another package uses such a type, an incomplete DIE
16140 may be generated by the compiler. */
16141 if (die_is_declaration (die
, cu
))
16142 type
->set_is_stub (true);
16144 /* If this type has an underlying type that is not a stub, then we
16145 may use its attributes. We always use the "unsigned" attribute
16146 in this situation, because ordinarily we guess whether the type
16147 is unsigned -- but the guess can be wrong and the underlying type
16148 can tell us the reality. However, we defer to a local size
16149 attribute if one exists, because this lets the compiler override
16150 the underlying type if needed. */
16151 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16153 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16154 underlying_type
= check_typedef (underlying_type
);
16156 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16158 if (TYPE_LENGTH (type
) == 0)
16159 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16161 if (TYPE_RAW_ALIGN (type
) == 0
16162 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16163 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16166 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16168 set_die_type (die
, type
, cu
);
16170 /* Finish the creation of this type by using the enum's children.
16171 Note that, as usual, this must come after set_die_type to avoid
16172 infinite recursion when trying to compute the names of the
16174 update_enumeration_type_from_children (die
, type
, cu
);
16179 /* Given a pointer to a die which begins an enumeration, process all
16180 the dies that define the members of the enumeration, and create the
16181 symbol for the enumeration type.
16183 NOTE: We reverse the order of the element list. */
16186 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16188 struct type
*this_type
;
16190 this_type
= get_die_type (die
, cu
);
16191 if (this_type
== NULL
)
16192 this_type
= read_enumeration_type (die
, cu
);
16194 if (die
->child
!= NULL
)
16196 struct die_info
*child_die
;
16199 child_die
= die
->child
;
16200 while (child_die
&& child_die
->tag
)
16202 if (child_die
->tag
!= DW_TAG_enumerator
)
16204 process_die (child_die
, cu
);
16208 name
= dwarf2_name (child_die
, cu
);
16210 new_symbol (child_die
, this_type
, cu
);
16213 child_die
= child_die
->sibling
;
16217 /* If we are reading an enum from a .debug_types unit, and the enum
16218 is a declaration, and the enum is not the signatured type in the
16219 unit, then we do not want to add a symbol for it. Adding a
16220 symbol would in some cases obscure the true definition of the
16221 enum, giving users an incomplete type when the definition is
16222 actually available. Note that we do not want to do this for all
16223 enums which are just declarations, because C++0x allows forward
16224 enum declarations. */
16225 if (cu
->per_cu
->is_debug_types
16226 && die_is_declaration (die
, cu
))
16228 struct signatured_type
*sig_type
;
16230 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16231 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16232 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16236 new_symbol (die
, this_type
, cu
);
16239 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16240 expression for an index type and finds the corresponding field
16241 offset in the hidden "P_BOUNDS" structure. Returns true on success
16242 and updates *FIELD, false if it fails to recognize an
16246 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16247 int *bounds_offset
, struct field
*field
,
16248 struct dwarf2_cu
*cu
)
16250 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16251 if (attr
== nullptr || !attr
->form_is_block ())
16254 const struct dwarf_block
*block
= attr
->as_block ();
16255 const gdb_byte
*start
= block
->data
;
16256 const gdb_byte
*end
= block
->data
+ block
->size
;
16258 /* The expression to recognize generally looks like:
16260 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16261 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16263 However, the second "plus_uconst" may be missing:
16265 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16266 DW_OP_deref_size: 4)
16268 This happens when the field is at the start of the structure.
16270 Also, the final deref may not be sized:
16272 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16275 This happens when the size of the index type happens to be the
16276 same as the architecture's word size. This can occur with or
16277 without the second plus_uconst. */
16279 if (end
- start
< 2)
16281 if (*start
++ != DW_OP_push_object_address
)
16283 if (*start
++ != DW_OP_plus_uconst
)
16286 uint64_t this_bound_off
;
16287 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16288 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16290 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16291 is consistent among all bounds. */
16292 if (*bounds_offset
== -1)
16293 *bounds_offset
= this_bound_off
;
16294 else if (*bounds_offset
!= this_bound_off
)
16297 if (start
== end
|| *start
++ != DW_OP_deref
)
16303 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16305 /* This means an offset of 0. */
16307 else if (*start
++ != DW_OP_plus_uconst
)
16311 /* The size is the parameter to DW_OP_plus_uconst. */
16313 start
= gdb_read_uleb128 (start
, end
, &val
);
16314 if (start
== nullptr)
16316 if ((int) val
!= val
)
16325 if (*start
== DW_OP_deref_size
)
16327 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16328 if (start
== nullptr)
16331 else if (*start
== DW_OP_deref
)
16333 size
= cu
->header
.addr_size
;
16339 SET_FIELD_BITPOS (*field
, 8 * offset
);
16340 if (size
!= TYPE_LENGTH (field
->type ()))
16341 FIELD_BITSIZE (*field
) = 8 * size
;
16346 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16347 some kinds of Ada arrays:
16349 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16350 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16351 <11e0> DW_AT_data_location: 2 byte block: 97 6
16352 (DW_OP_push_object_address; DW_OP_deref)
16353 <11e3> DW_AT_type : <0x1173>
16354 <11e7> DW_AT_sibling : <0x1201>
16355 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16356 <11ec> DW_AT_type : <0x1206>
16357 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16358 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16359 DW_OP_deref_size: 4)
16360 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16361 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16362 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16364 This actually represents a "thick pointer", which is a structure
16365 with two elements: one that is a pointer to the array data, and one
16366 that is a pointer to another structure; this second structure holds
16369 This returns a new type on success, or nullptr if this didn't
16370 recognize the type. */
16372 static struct type
*
16373 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16376 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16377 /* So far we've only seen this with block form. */
16378 if (attr
== nullptr || !attr
->form_is_block ())
16381 /* Note that this will fail if the structure layout is changed by
16382 the compiler. However, we have no good way to recognize some
16383 other layout, because we don't know what expression the compiler
16384 might choose to emit should this happen. */
16385 struct dwarf_block
*blk
= attr
->as_block ();
16387 || blk
->data
[0] != DW_OP_push_object_address
16388 || blk
->data
[1] != DW_OP_deref
)
16391 int bounds_offset
= -1;
16392 int max_align
= -1;
16393 std::vector
<struct field
> range_fields
;
16394 for (struct die_info
*child_die
= die
->child
;
16396 child_die
= child_die
->sibling
)
16398 if (child_die
->tag
== DW_TAG_subrange_type
)
16400 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16402 int this_align
= type_align (underlying
);
16403 if (this_align
> max_align
)
16404 max_align
= this_align
;
16406 range_fields
.emplace_back ();
16407 range_fields
.emplace_back ();
16409 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16410 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16412 lower
.set_type (underlying
);
16413 FIELD_ARTIFICIAL (lower
) = 1;
16415 upper
.set_type (underlying
);
16416 FIELD_ARTIFICIAL (upper
) = 1;
16418 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16419 &bounds_offset
, &lower
, cu
)
16420 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16421 &bounds_offset
, &upper
, cu
))
16426 /* This shouldn't really happen, but double-check that we found
16427 where the bounds are stored. */
16428 if (bounds_offset
== -1)
16431 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16432 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16436 /* Set the name of each field in the bounds. */
16437 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16438 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16439 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16440 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16443 struct type
*bounds
= alloc_type (objfile
);
16444 bounds
->set_code (TYPE_CODE_STRUCT
);
16446 bounds
->set_num_fields (range_fields
.size ());
16448 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16449 * sizeof (struct field
))));
16450 memcpy (bounds
->fields (), range_fields
.data (),
16451 bounds
->num_fields () * sizeof (struct field
));
16453 int last_fieldno
= range_fields
.size () - 1;
16454 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16455 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16456 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16458 /* Rewrite the existing array type in place. Specifically, we
16459 remove any dynamic properties we might have read, and we replace
16460 the index types. */
16461 struct type
*iter
= type
;
16462 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16464 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16465 iter
->main_type
->dyn_prop_list
= nullptr;
16466 iter
->set_index_type
16467 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16468 iter
= TYPE_TARGET_TYPE (iter
);
16471 struct type
*result
= alloc_type (objfile
);
16472 result
->set_code (TYPE_CODE_STRUCT
);
16474 result
->set_num_fields (2);
16476 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16477 * sizeof (struct field
))));
16479 /* The names are chosen to coincide with what the compiler does with
16480 -fgnat-encodings=all, which the Ada code in gdb already
16482 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16483 result
->field (0).set_type (lookup_pointer_type (type
));
16485 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16486 result
->field (1).set_type (lookup_pointer_type (bounds
));
16487 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16489 result
->set_name (type
->name ());
16490 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16491 + TYPE_LENGTH (result
->field (1).type ()));
16496 /* Extract all information from a DW_TAG_array_type DIE and put it in
16497 the DIE's type field. For now, this only handles one dimensional
16500 static struct type
*
16501 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16503 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16504 struct die_info
*child_die
;
16506 struct type
*element_type
, *range_type
, *index_type
;
16507 struct attribute
*attr
;
16509 struct dynamic_prop
*byte_stride_prop
= NULL
;
16510 unsigned int bit_stride
= 0;
16512 element_type
= die_type (die
, cu
);
16514 /* The die_type call above may have already set the type for this DIE. */
16515 type
= get_die_type (die
, cu
);
16519 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16523 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16526 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16527 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16531 complaint (_("unable to read array DW_AT_byte_stride "
16532 " - DIE at %s [in module %s]"),
16533 sect_offset_str (die
->sect_off
),
16534 objfile_name (cu
->per_objfile
->objfile
));
16535 /* Ignore this attribute. We will likely not be able to print
16536 arrays of this type correctly, but there is little we can do
16537 to help if we cannot read the attribute's value. */
16538 byte_stride_prop
= NULL
;
16542 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16544 bit_stride
= attr
->constant_value (0);
16546 /* Irix 6.2 native cc creates array types without children for
16547 arrays with unspecified length. */
16548 if (die
->child
== NULL
)
16550 index_type
= objfile_type (objfile
)->builtin_int
;
16551 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16552 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16553 byte_stride_prop
, bit_stride
);
16554 return set_die_type (die
, type
, cu
);
16557 std::vector
<struct type
*> range_types
;
16558 child_die
= die
->child
;
16559 while (child_die
&& child_die
->tag
)
16561 if (child_die
->tag
== DW_TAG_subrange_type
)
16563 struct type
*child_type
= read_type_die (child_die
, cu
);
16565 if (child_type
!= NULL
)
16567 /* The range type was succesfully read. Save it for the
16568 array type creation. */
16569 range_types
.push_back (child_type
);
16572 child_die
= child_die
->sibling
;
16575 if (range_types
.empty ())
16577 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16578 sect_offset_str (die
->sect_off
),
16579 objfile_name (cu
->per_objfile
->objfile
));
16583 /* Dwarf2 dimensions are output from left to right, create the
16584 necessary array types in backwards order. */
16586 type
= element_type
;
16588 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16592 while (i
< range_types
.size ())
16594 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16595 byte_stride_prop
, bit_stride
);
16597 byte_stride_prop
= nullptr;
16602 size_t ndim
= range_types
.size ();
16605 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16606 byte_stride_prop
, bit_stride
);
16608 byte_stride_prop
= nullptr;
16612 gdb_assert (type
!= element_type
);
16614 /* Understand Dwarf2 support for vector types (like they occur on
16615 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16616 array type. This is not part of the Dwarf2/3 standard yet, but a
16617 custom vendor extension. The main difference between a regular
16618 array and the vector variant is that vectors are passed by value
16620 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16621 if (attr
!= nullptr)
16622 make_vector_type (type
);
16624 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16625 implementation may choose to implement triple vectors using this
16627 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16628 if (attr
!= nullptr && attr
->form_is_unsigned ())
16630 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16631 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16633 complaint (_("DW_AT_byte_size for array type smaller "
16634 "than the total size of elements"));
16637 name
= dwarf2_name (die
, cu
);
16639 type
->set_name (name
);
16641 maybe_set_alignment (cu
, die
, type
);
16643 struct type
*replacement_type
= nullptr;
16644 if (cu
->per_cu
->lang
== language_ada
)
16646 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16647 if (replacement_type
!= nullptr)
16648 type
= replacement_type
;
16651 /* Install the type in the die. */
16652 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16654 /* set_die_type should be already done. */
16655 set_descriptive_type (type
, die
, cu
);
16660 static enum dwarf_array_dim_ordering
16661 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16663 struct attribute
*attr
;
16665 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16667 if (attr
!= nullptr)
16669 LONGEST val
= attr
->constant_value (-1);
16670 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16671 return (enum dwarf_array_dim_ordering
) val
;
16674 /* GNU F77 is a special case, as at 08/2004 array type info is the
16675 opposite order to the dwarf2 specification, but data is still
16676 laid out as per normal fortran.
16678 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16679 version checking. */
16681 if (cu
->per_cu
->lang
== language_fortran
16682 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16684 return DW_ORD_row_major
;
16687 switch (cu
->language_defn
->array_ordering ())
16689 case array_column_major
:
16690 return DW_ORD_col_major
;
16691 case array_row_major
:
16693 return DW_ORD_row_major
;
16697 /* Extract all information from a DW_TAG_set_type DIE and put it in
16698 the DIE's type field. */
16700 static struct type
*
16701 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16703 struct type
*domain_type
, *set_type
;
16704 struct attribute
*attr
;
16706 domain_type
= die_type (die
, cu
);
16708 /* The die_type call above may have already set the type for this DIE. */
16709 set_type
= get_die_type (die
, cu
);
16713 set_type
= create_set_type (NULL
, domain_type
);
16715 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16716 if (attr
!= nullptr && attr
->form_is_unsigned ())
16717 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16719 maybe_set_alignment (cu
, die
, set_type
);
16721 return set_die_type (die
, set_type
, cu
);
16724 /* A helper for read_common_block that creates a locexpr baton.
16725 SYM is the symbol which we are marking as computed.
16726 COMMON_DIE is the DIE for the common block.
16727 COMMON_LOC is the location expression attribute for the common
16729 MEMBER_LOC is the location expression attribute for the particular
16730 member of the common block that we are processing.
16731 CU is the CU from which the above come. */
16734 mark_common_block_symbol_computed (struct symbol
*sym
,
16735 struct die_info
*common_die
,
16736 struct attribute
*common_loc
,
16737 struct attribute
*member_loc
,
16738 struct dwarf2_cu
*cu
)
16740 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16741 struct objfile
*objfile
= per_objfile
->objfile
;
16742 struct dwarf2_locexpr_baton
*baton
;
16744 unsigned int cu_off
;
16745 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16746 LONGEST offset
= 0;
16748 gdb_assert (common_loc
&& member_loc
);
16749 gdb_assert (common_loc
->form_is_block ());
16750 gdb_assert (member_loc
->form_is_block ()
16751 || member_loc
->form_is_constant ());
16753 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16754 baton
->per_objfile
= per_objfile
;
16755 baton
->per_cu
= cu
->per_cu
;
16756 gdb_assert (baton
->per_cu
);
16758 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16760 if (member_loc
->form_is_constant ())
16762 offset
= member_loc
->constant_value (0);
16763 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16766 baton
->size
+= member_loc
->as_block ()->size
;
16768 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16771 *ptr
++ = DW_OP_call4
;
16772 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16773 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16776 if (member_loc
->form_is_constant ())
16778 *ptr
++ = DW_OP_addr
;
16779 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16780 ptr
+= cu
->header
.addr_size
;
16784 /* We have to copy the data here, because DW_OP_call4 will only
16785 use a DW_AT_location attribute. */
16786 struct dwarf_block
*block
= member_loc
->as_block ();
16787 memcpy (ptr
, block
->data
, block
->size
);
16788 ptr
+= block
->size
;
16791 *ptr
++ = DW_OP_plus
;
16792 gdb_assert (ptr
- baton
->data
== baton
->size
);
16794 SYMBOL_LOCATION_BATON (sym
) = baton
;
16795 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16798 /* Create appropriate locally-scoped variables for all the
16799 DW_TAG_common_block entries. Also create a struct common_block
16800 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16801 is used to separate the common blocks name namespace from regular
16805 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16807 struct attribute
*attr
;
16809 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16810 if (attr
!= nullptr)
16812 /* Support the .debug_loc offsets. */
16813 if (attr
->form_is_block ())
16817 else if (attr
->form_is_section_offset ())
16819 dwarf2_complex_location_expr_complaint ();
16824 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16825 "common block member");
16830 if (die
->child
!= NULL
)
16832 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16833 struct die_info
*child_die
;
16834 size_t n_entries
= 0, size
;
16835 struct common_block
*common_block
;
16836 struct symbol
*sym
;
16838 for (child_die
= die
->child
;
16839 child_die
&& child_die
->tag
;
16840 child_die
= child_die
->sibling
)
16843 size
= (sizeof (struct common_block
)
16844 + (n_entries
- 1) * sizeof (struct symbol
*));
16846 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16848 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16849 common_block
->n_entries
= 0;
16851 for (child_die
= die
->child
;
16852 child_die
&& child_die
->tag
;
16853 child_die
= child_die
->sibling
)
16855 /* Create the symbol in the DW_TAG_common_block block in the current
16857 sym
= new_symbol (child_die
, NULL
, cu
);
16860 struct attribute
*member_loc
;
16862 common_block
->contents
[common_block
->n_entries
++] = sym
;
16864 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16868 /* GDB has handled this for a long time, but it is
16869 not specified by DWARF. It seems to have been
16870 emitted by gfortran at least as recently as:
16871 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16872 complaint (_("Variable in common block has "
16873 "DW_AT_data_member_location "
16874 "- DIE at %s [in module %s]"),
16875 sect_offset_str (child_die
->sect_off
),
16876 objfile_name (objfile
));
16878 if (member_loc
->form_is_section_offset ())
16879 dwarf2_complex_location_expr_complaint ();
16880 else if (member_loc
->form_is_constant ()
16881 || member_loc
->form_is_block ())
16883 if (attr
!= nullptr)
16884 mark_common_block_symbol_computed (sym
, die
, attr
,
16888 dwarf2_complex_location_expr_complaint ();
16893 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16894 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16898 /* Create a type for a C++ namespace. */
16900 static struct type
*
16901 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16903 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16904 const char *previous_prefix
, *name
;
16908 /* For extensions, reuse the type of the original namespace. */
16909 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16911 struct die_info
*ext_die
;
16912 struct dwarf2_cu
*ext_cu
= cu
;
16914 ext_die
= dwarf2_extension (die
, &ext_cu
);
16915 type
= read_type_die (ext_die
, ext_cu
);
16917 /* EXT_CU may not be the same as CU.
16918 Ensure TYPE is recorded with CU in die_type_hash. */
16919 return set_die_type (die
, type
, cu
);
16922 name
= namespace_name (die
, &is_anonymous
, cu
);
16924 /* Now build the name of the current namespace. */
16926 previous_prefix
= determine_prefix (die
, cu
);
16927 if (previous_prefix
[0] != '\0')
16928 name
= typename_concat (&objfile
->objfile_obstack
,
16929 previous_prefix
, name
, 0, cu
);
16931 /* Create the type. */
16932 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16934 return set_die_type (die
, type
, cu
);
16937 /* Read a namespace scope. */
16940 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16942 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16945 /* Add a symbol associated to this if we haven't seen the namespace
16946 before. Also, add a using directive if it's an anonymous
16949 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16953 type
= read_type_die (die
, cu
);
16954 new_symbol (die
, type
, cu
);
16956 namespace_name (die
, &is_anonymous
, cu
);
16959 const char *previous_prefix
= determine_prefix (die
, cu
);
16961 std::vector
<const char *> excludes
;
16962 add_using_directive (using_directives (cu
),
16963 previous_prefix
, type
->name (), NULL
,
16964 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16968 if (die
->child
!= NULL
)
16970 struct die_info
*child_die
= die
->child
;
16972 while (child_die
&& child_die
->tag
)
16974 process_die (child_die
, cu
);
16975 child_die
= child_die
->sibling
;
16980 /* Read a Fortran module as type. This DIE can be only a declaration used for
16981 imported module. Still we need that type as local Fortran "use ... only"
16982 declaration imports depend on the created type in determine_prefix. */
16984 static struct type
*
16985 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16987 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16988 const char *module_name
;
16991 module_name
= dwarf2_name (die
, cu
);
16992 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16994 return set_die_type (die
, type
, cu
);
16997 /* Read a Fortran module. */
17000 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17002 struct die_info
*child_die
= die
->child
;
17005 type
= read_type_die (die
, cu
);
17006 new_symbol (die
, type
, cu
);
17008 while (child_die
&& child_die
->tag
)
17010 process_die (child_die
, cu
);
17011 child_die
= child_die
->sibling
;
17015 /* Return the name of the namespace represented by DIE. Set
17016 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17019 static const char *
17020 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17022 struct die_info
*current_die
;
17023 const char *name
= NULL
;
17025 /* Loop through the extensions until we find a name. */
17027 for (current_die
= die
;
17028 current_die
!= NULL
;
17029 current_die
= dwarf2_extension (die
, &cu
))
17031 /* We don't use dwarf2_name here so that we can detect the absence
17032 of a name -> anonymous namespace. */
17033 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17039 /* Is it an anonymous namespace? */
17041 *is_anonymous
= (name
== NULL
);
17043 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17048 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17049 the user defined type vector. */
17051 static struct type
*
17052 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17054 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17055 struct comp_unit_head
*cu_header
= &cu
->header
;
17057 struct attribute
*attr_byte_size
;
17058 struct attribute
*attr_address_class
;
17059 int byte_size
, addr_class
;
17060 struct type
*target_type
;
17062 target_type
= die_type (die
, cu
);
17064 /* The die_type call above may have already set the type for this DIE. */
17065 type
= get_die_type (die
, cu
);
17069 type
= lookup_pointer_type (target_type
);
17071 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17072 if (attr_byte_size
)
17073 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17075 byte_size
= cu_header
->addr_size
;
17077 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17078 if (attr_address_class
)
17079 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17081 addr_class
= DW_ADDR_none
;
17083 ULONGEST alignment
= get_alignment (cu
, die
);
17085 /* If the pointer size, alignment, or address class is different
17086 than the default, create a type variant marked as such and set
17087 the length accordingly. */
17088 if (TYPE_LENGTH (type
) != byte_size
17089 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17090 && alignment
!= TYPE_RAW_ALIGN (type
))
17091 || addr_class
!= DW_ADDR_none
)
17093 if (gdbarch_address_class_type_flags_p (gdbarch
))
17095 type_instance_flags type_flags
17096 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17098 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17100 type
= make_type_with_address_space (type
, type_flags
);
17102 else if (TYPE_LENGTH (type
) != byte_size
)
17104 complaint (_("invalid pointer size %d"), byte_size
);
17106 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17108 complaint (_("Invalid DW_AT_alignment"
17109 " - DIE at %s [in module %s]"),
17110 sect_offset_str (die
->sect_off
),
17111 objfile_name (cu
->per_objfile
->objfile
));
17115 /* Should we also complain about unhandled address classes? */
17119 TYPE_LENGTH (type
) = byte_size
;
17120 set_type_align (type
, alignment
);
17121 return set_die_type (die
, type
, cu
);
17124 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17125 the user defined type vector. */
17127 static struct type
*
17128 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17131 struct type
*to_type
;
17132 struct type
*domain
;
17134 to_type
= die_type (die
, cu
);
17135 domain
= die_containing_type (die
, cu
);
17137 /* The calls above may have already set the type for this DIE. */
17138 type
= get_die_type (die
, cu
);
17142 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17143 type
= lookup_methodptr_type (to_type
);
17144 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17146 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17148 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17149 to_type
->fields (), to_type
->num_fields (),
17150 to_type
->has_varargs ());
17151 type
= lookup_methodptr_type (new_type
);
17154 type
= lookup_memberptr_type (to_type
, domain
);
17156 return set_die_type (die
, type
, cu
);
17159 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17160 the user defined type vector. */
17162 static struct type
*
17163 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17164 enum type_code refcode
)
17166 struct comp_unit_head
*cu_header
= &cu
->header
;
17167 struct type
*type
, *target_type
;
17168 struct attribute
*attr
;
17170 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17172 target_type
= die_type (die
, cu
);
17174 /* The die_type call above may have already set the type for this DIE. */
17175 type
= get_die_type (die
, cu
);
17179 type
= lookup_reference_type (target_type
, refcode
);
17180 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17181 if (attr
!= nullptr)
17183 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17187 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17189 maybe_set_alignment (cu
, die
, type
);
17190 return set_die_type (die
, type
, cu
);
17193 /* Add the given cv-qualifiers to the element type of the array. GCC
17194 outputs DWARF type qualifiers that apply to an array, not the
17195 element type. But GDB relies on the array element type to carry
17196 the cv-qualifiers. This mimics section 6.7.3 of the C99
17199 static struct type
*
17200 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17201 struct type
*base_type
, int cnst
, int voltl
)
17203 struct type
*el_type
, *inner_array
;
17205 base_type
= copy_type (base_type
);
17206 inner_array
= base_type
;
17208 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17210 TYPE_TARGET_TYPE (inner_array
) =
17211 copy_type (TYPE_TARGET_TYPE (inner_array
));
17212 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17215 el_type
= TYPE_TARGET_TYPE (inner_array
);
17216 cnst
|= TYPE_CONST (el_type
);
17217 voltl
|= TYPE_VOLATILE (el_type
);
17218 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17220 return set_die_type (die
, base_type
, cu
);
17223 static struct type
*
17224 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17226 struct type
*base_type
, *cv_type
;
17228 base_type
= die_type (die
, cu
);
17230 /* The die_type call above may have already set the type for this DIE. */
17231 cv_type
= get_die_type (die
, cu
);
17235 /* In case the const qualifier is applied to an array type, the element type
17236 is so qualified, not the array type (section 6.7.3 of C99). */
17237 if (base_type
->code () == TYPE_CODE_ARRAY
)
17238 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17240 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17241 return set_die_type (die
, cv_type
, cu
);
17244 static struct type
*
17245 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17247 struct type
*base_type
, *cv_type
;
17249 base_type
= die_type (die
, cu
);
17251 /* The die_type call above may have already set the type for this DIE. */
17252 cv_type
= get_die_type (die
, cu
);
17256 /* In case the volatile qualifier is applied to an array type, the
17257 element type is so qualified, not the array type (section 6.7.3
17259 if (base_type
->code () == TYPE_CODE_ARRAY
)
17260 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17262 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17263 return set_die_type (die
, cv_type
, cu
);
17266 /* Handle DW_TAG_restrict_type. */
17268 static struct type
*
17269 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17271 struct type
*base_type
, *cv_type
;
17273 base_type
= die_type (die
, cu
);
17275 /* The die_type call above may have already set the type for this DIE. */
17276 cv_type
= get_die_type (die
, cu
);
17280 cv_type
= make_restrict_type (base_type
);
17281 return set_die_type (die
, cv_type
, cu
);
17284 /* Handle DW_TAG_atomic_type. */
17286 static struct type
*
17287 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17289 struct type
*base_type
, *cv_type
;
17291 base_type
= die_type (die
, cu
);
17293 /* The die_type call above may have already set the type for this DIE. */
17294 cv_type
= get_die_type (die
, cu
);
17298 cv_type
= make_atomic_type (base_type
);
17299 return set_die_type (die
, cv_type
, cu
);
17302 /* Extract all information from a DW_TAG_string_type DIE and add to
17303 the user defined type vector. It isn't really a user defined type,
17304 but it behaves like one, with other DIE's using an AT_user_def_type
17305 attribute to reference it. */
17307 static struct type
*
17308 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17310 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17311 struct gdbarch
*gdbarch
= objfile
->arch ();
17312 struct type
*type
, *range_type
, *index_type
, *char_type
;
17313 struct attribute
*attr
;
17314 struct dynamic_prop prop
;
17315 bool length_is_constant
= true;
17318 /* There are a couple of places where bit sizes might be made use of
17319 when parsing a DW_TAG_string_type, however, no producer that we know
17320 of make use of these. Handling bit sizes that are a multiple of the
17321 byte size is easy enough, but what about other bit sizes? Lets deal
17322 with that problem when we have to. Warn about these attributes being
17323 unsupported, then parse the type and ignore them like we always
17325 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17326 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17328 static bool warning_printed
= false;
17329 if (!warning_printed
)
17331 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17332 "currently supported on DW_TAG_string_type."));
17333 warning_printed
= true;
17337 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17338 if (attr
!= nullptr && !attr
->form_is_constant ())
17340 /* The string length describes the location at which the length of
17341 the string can be found. The size of the length field can be
17342 specified with one of the attributes below. */
17343 struct type
*prop_type
;
17344 struct attribute
*len
17345 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17346 if (len
== nullptr)
17347 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17348 if (len
!= nullptr && len
->form_is_constant ())
17350 /* Pass 0 as the default as we know this attribute is constant
17351 and the default value will not be returned. */
17352 LONGEST sz
= len
->constant_value (0);
17353 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17357 /* If the size is not specified then we assume it is the size of
17358 an address on this target. */
17359 prop_type
= cu
->addr_sized_int_type (true);
17362 /* Convert the attribute into a dynamic property. */
17363 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17366 length_is_constant
= false;
17368 else if (attr
!= nullptr)
17370 /* This DW_AT_string_length just contains the length with no
17371 indirection. There's no need to create a dynamic property in this
17372 case. Pass 0 for the default value as we know it will not be
17373 returned in this case. */
17374 length
= attr
->constant_value (0);
17376 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17378 /* We don't currently support non-constant byte sizes for strings. */
17379 length
= attr
->constant_value (1);
17383 /* Use 1 as a fallback length if we have nothing else. */
17387 index_type
= objfile_type (objfile
)->builtin_int
;
17388 if (length_is_constant
)
17389 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17392 struct dynamic_prop low_bound
;
17394 low_bound
.set_const_val (1);
17395 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17397 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17398 type
= create_string_type (NULL
, char_type
, range_type
);
17400 return set_die_type (die
, type
, cu
);
17403 /* Assuming that DIE corresponds to a function, returns nonzero
17404 if the function is prototyped. */
17407 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17409 struct attribute
*attr
;
17411 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17412 if (attr
&& attr
->as_boolean ())
17415 /* The DWARF standard implies that the DW_AT_prototyped attribute
17416 is only meaningful for C, but the concept also extends to other
17417 languages that allow unprototyped functions (Eg: Objective C).
17418 For all other languages, assume that functions are always
17420 if (cu
->per_cu
->lang
!= language_c
17421 && cu
->per_cu
->lang
!= language_objc
17422 && cu
->per_cu
->lang
!= language_opencl
)
17425 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17426 prototyped and unprototyped functions; default to prototyped,
17427 since that is more common in modern code (and RealView warns
17428 about unprototyped functions). */
17429 if (producer_is_realview (cu
->producer
))
17435 /* Handle DIES due to C code like:
17439 int (*funcp)(int a, long l);
17443 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17445 static struct type
*
17446 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17448 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17449 struct type
*type
; /* Type that this function returns. */
17450 struct type
*ftype
; /* Function that returns above type. */
17451 struct attribute
*attr
;
17453 type
= die_type (die
, cu
);
17455 /* The die_type call above may have already set the type for this DIE. */
17456 ftype
= get_die_type (die
, cu
);
17460 ftype
= lookup_function_type (type
);
17462 if (prototyped_function_p (die
, cu
))
17463 ftype
->set_is_prototyped (true);
17465 /* Store the calling convention in the type if it's available in
17466 the subroutine die. Otherwise set the calling convention to
17467 the default value DW_CC_normal. */
17468 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17469 if (attr
!= nullptr
17470 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17471 TYPE_CALLING_CONVENTION (ftype
)
17472 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17473 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17474 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17476 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17478 /* Record whether the function returns normally to its caller or not
17479 if the DWARF producer set that information. */
17480 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17481 if (attr
&& attr
->as_boolean ())
17482 TYPE_NO_RETURN (ftype
) = 1;
17484 /* We need to add the subroutine type to the die immediately so
17485 we don't infinitely recurse when dealing with parameters
17486 declared as the same subroutine type. */
17487 set_die_type (die
, ftype
, cu
);
17489 if (die
->child
!= NULL
)
17491 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17492 struct die_info
*child_die
;
17493 int nparams
, iparams
;
17495 /* Count the number of parameters.
17496 FIXME: GDB currently ignores vararg functions, but knows about
17497 vararg member functions. */
17499 child_die
= die
->child
;
17500 while (child_die
&& child_die
->tag
)
17502 if (child_die
->tag
== DW_TAG_formal_parameter
)
17504 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17505 ftype
->set_has_varargs (true);
17507 child_die
= child_die
->sibling
;
17510 /* Allocate storage for parameters and fill them in. */
17511 ftype
->set_num_fields (nparams
);
17513 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17515 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17516 even if we error out during the parameters reading below. */
17517 for (iparams
= 0; iparams
< nparams
; iparams
++)
17518 ftype
->field (iparams
).set_type (void_type
);
17521 child_die
= die
->child
;
17522 while (child_die
&& child_die
->tag
)
17524 if (child_die
->tag
== DW_TAG_formal_parameter
)
17526 struct type
*arg_type
;
17528 /* DWARF version 2 has no clean way to discern C++
17529 static and non-static member functions. G++ helps
17530 GDB by marking the first parameter for non-static
17531 member functions (which is the this pointer) as
17532 artificial. We pass this information to
17533 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17535 DWARF version 3 added DW_AT_object_pointer, which GCC
17536 4.5 does not yet generate. */
17537 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17538 if (attr
!= nullptr)
17539 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17541 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17542 arg_type
= die_type (child_die
, cu
);
17544 /* RealView does not mark THIS as const, which the testsuite
17545 expects. GCC marks THIS as const in method definitions,
17546 but not in the class specifications (GCC PR 43053). */
17547 if (cu
->per_cu
->lang
== language_cplus
17548 && !TYPE_CONST (arg_type
)
17549 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17552 struct dwarf2_cu
*arg_cu
= cu
;
17553 const char *name
= dwarf2_name (child_die
, cu
);
17555 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17556 if (attr
!= nullptr)
17558 /* If the compiler emits this, use it. */
17559 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17562 else if (name
&& strcmp (name
, "this") == 0)
17563 /* Function definitions will have the argument names. */
17565 else if (name
== NULL
&& iparams
== 0)
17566 /* Declarations may not have the names, so like
17567 elsewhere in GDB, assume an artificial first
17568 argument is "this". */
17572 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17576 ftype
->field (iparams
).set_type (arg_type
);
17579 child_die
= child_die
->sibling
;
17586 static struct type
*
17587 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17589 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17590 const char *name
= NULL
;
17591 struct type
*this_type
, *target_type
;
17593 name
= dwarf2_full_name (NULL
, die
, cu
);
17594 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17595 this_type
->set_target_is_stub (true);
17596 set_die_type (die
, this_type
, cu
);
17597 target_type
= die_type (die
, cu
);
17598 if (target_type
!= this_type
)
17599 TYPE_TARGET_TYPE (this_type
) = target_type
;
17602 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17603 spec and cause infinite loops in GDB. */
17604 complaint (_("Self-referential DW_TAG_typedef "
17605 "- DIE at %s [in module %s]"),
17606 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17607 TYPE_TARGET_TYPE (this_type
) = NULL
;
17611 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17612 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17613 Handle these by just returning the target type, rather than
17614 constructing an anonymous typedef type and trying to handle this
17616 set_die_type (die
, target_type
, cu
);
17617 return target_type
;
17622 /* Helper for get_dwarf2_rational_constant that computes the value of
17623 a given gmp_mpz given an attribute. */
17626 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17628 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17629 location expression that pushes an implicit value. */
17630 if (attr
->form
== DW_FORM_exprloc
)
17632 dwarf_block
*blk
= attr
->as_block ();
17633 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17636 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17637 blk
->data
+ blk
->size
,
17639 if (ptr
- blk
->data
+ len
<= blk
->size
)
17641 mpz_import (value
->val
, len
,
17642 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17648 /* On failure set it to 1. */
17649 *value
= gdb_mpz (1);
17651 else if (attr
->form_is_block ())
17653 dwarf_block
*blk
= attr
->as_block ();
17654 mpz_import (value
->val
, blk
->size
,
17655 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17656 1, 0, 0, blk
->data
);
17659 *value
= gdb_mpz (attr
->constant_value (1));
17662 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17663 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17665 If the numerator and/or numerator attribute is missing,
17666 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17670 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17671 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17673 struct attribute
*num_attr
, *denom_attr
;
17675 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17676 if (num_attr
== nullptr)
17677 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17678 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17680 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17681 if (denom_attr
== nullptr)
17682 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17683 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17685 if (num_attr
== nullptr || denom_attr
== nullptr)
17688 get_mpz (cu
, numerator
, num_attr
);
17689 get_mpz (cu
, denominator
, denom_attr
);
17692 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17693 rational constant, rather than a signed one.
17695 If the rational constant has a negative value, a complaint
17696 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17699 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17700 struct dwarf2_cu
*cu
,
17701 gdb_mpz
*numerator
,
17702 gdb_mpz
*denominator
)
17707 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17708 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17710 mpz_neg (num
.val
, num
.val
);
17711 mpz_neg (denom
.val
, denom
.val
);
17713 else if (mpz_sgn (num
.val
) == -1)
17715 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17717 sect_offset_str (die
->sect_off
));
17720 else if (mpz_sgn (denom
.val
) == -1)
17722 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17724 sect_offset_str (die
->sect_off
));
17728 *numerator
= std::move (num
);
17729 *denominator
= std::move (denom
);
17732 /* Assuming that ENCODING is a string whose contents starting at the
17733 K'th character is "_nn" where "nn" is a decimal number, scan that
17734 number and set RESULT to the value. K is updated to point to the
17735 character immediately following the number.
17737 If the string does not conform to the format described above, false
17738 is returned, and K may or may not be changed. */
17741 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17743 /* The next character should be an underscore ('_') followed
17745 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17748 /* Skip the underscore. */
17752 /* Determine the number of digits for our number. */
17753 while (isdigit (encoding
[k
]))
17758 std::string
copy (&encoding
[start
], k
- start
);
17759 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17765 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17766 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17767 DENOM, update OFFSET, and return true on success. Return false on
17771 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17772 gdb_mpz
*num
, gdb_mpz
*denom
)
17774 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17776 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17779 /* Assuming DIE corresponds to a fixed point type, finish the creation
17780 of the corresponding TYPE by setting its type-specific data. CU is
17781 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17782 encodings. It is nullptr if the GNAT encoding should be
17786 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17787 struct die_info
*die
, struct dwarf2_cu
*cu
)
17789 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17790 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17792 /* If GNAT encodings are preferred, don't examine the
17794 struct attribute
*attr
= nullptr;
17795 if (suffix
== nullptr)
17797 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17798 if (attr
== nullptr)
17799 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17800 if (attr
== nullptr)
17801 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17804 /* Numerator and denominator of our fixed-point type's scaling factor.
17805 The default is a scaling factor of 1, which we use as a fallback
17806 when we are not able to decode it (problem with the debugging info,
17807 unsupported forms, bug in GDB, etc...). Using that as the default
17808 allows us to at least print the unscaled value, which might still
17809 be useful to a user. */
17810 gdb_mpz
scale_num (1);
17811 gdb_mpz
scale_denom (1);
17813 if (attr
== nullptr)
17816 if (suffix
!= nullptr
17817 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17819 /* The number might be encoded as _nn_dd_nn_dd, where the
17820 second ratio is the 'small value. In this situation, we
17821 want the second value. */
17822 && (suffix
[offset
] != '_'
17823 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17830 /* Scaling factor not found. Assume a scaling factor of 1,
17831 and hope for the best. At least the user will be able to
17832 see the encoded value. */
17835 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17836 sect_offset_str (die
->sect_off
));
17839 else if (attr
->name
== DW_AT_binary_scale
)
17841 LONGEST scale_exp
= attr
->constant_value (0);
17842 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17844 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17846 else if (attr
->name
== DW_AT_decimal_scale
)
17848 LONGEST scale_exp
= attr
->constant_value (0);
17849 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17851 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17853 else if (attr
->name
== DW_AT_small
)
17855 struct die_info
*scale_die
;
17856 struct dwarf2_cu
*scale_cu
= cu
;
17858 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17859 if (scale_die
->tag
== DW_TAG_constant
)
17860 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17861 &scale_num
, &scale_denom
);
17863 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17865 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17869 complaint (_("unsupported scale attribute %s for fixed-point type"
17871 dwarf_attr_name (attr
->name
),
17872 sect_offset_str (die
->sect_off
));
17875 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17876 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17877 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17878 mpq_canonicalize (scaling_factor
.val
);
17881 /* The gnat-encoding suffix for fixed point. */
17883 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17885 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17886 "XF" suffix of the name. The text after this is what encodes the
17887 'small and 'delta information. Otherwise, return nullptr. */
17889 static const char *
17890 gnat_encoded_fixed_point_type_info (const char *name
)
17892 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17895 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17896 (which may be different from NAME) to the architecture back-end to allow
17897 it to guess the correct format if necessary. */
17899 static struct type
*
17900 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17901 const char *name_hint
, enum bfd_endian byte_order
)
17903 struct gdbarch
*gdbarch
= objfile
->arch ();
17904 const struct floatformat
**format
;
17907 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17909 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17911 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17916 /* Allocate an integer type of size BITS and name NAME. */
17918 static struct type
*
17919 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17920 int bits
, int unsigned_p
, const char *name
)
17924 /* Versions of Intel's C Compiler generate an integer type called "void"
17925 instead of using DW_TAG_unspecified_type. This has been seen on
17926 at least versions 14, 17, and 18. */
17927 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17928 && strcmp (name
, "void") == 0)
17929 type
= objfile_type (objfile
)->builtin_void
;
17931 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17936 /* Return true if DIE has a DW_AT_small attribute whose value is
17937 a constant rational, where both the numerator and denominator
17940 CU is the DIE's Compilation Unit. */
17943 has_zero_over_zero_small_attribute (struct die_info
*die
,
17944 struct dwarf2_cu
*cu
)
17946 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17947 if (attr
== nullptr)
17950 struct dwarf2_cu
*scale_cu
= cu
;
17951 struct die_info
*scale_die
17952 = follow_die_ref (die
, attr
, &scale_cu
);
17954 if (scale_die
->tag
!= DW_TAG_constant
)
17957 gdb_mpz
num (1), denom (1);
17958 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
17959 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
17962 /* Initialise and return a floating point type of size BITS suitable for
17963 use as a component of a complex number. The NAME_HINT is passed through
17964 when initialising the floating point type and is the name of the complex
17967 As DWARF doesn't currently provide an explicit name for the components
17968 of a complex number, but it can be helpful to have these components
17969 named, we try to select a suitable name based on the size of the
17971 static struct type
*
17972 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17973 struct objfile
*objfile
,
17974 int bits
, const char *name_hint
,
17975 enum bfd_endian byte_order
)
17977 gdbarch
*gdbarch
= objfile
->arch ();
17978 struct type
*tt
= nullptr;
17980 /* Try to find a suitable floating point builtin type of size BITS.
17981 We're going to use the name of this type as the name for the complex
17982 target type that we are about to create. */
17983 switch (cu
->per_cu
->lang
)
17985 case language_fortran
:
17989 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17992 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17994 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17996 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18004 tt
= builtin_type (gdbarch
)->builtin_float
;
18007 tt
= builtin_type (gdbarch
)->builtin_double
;
18009 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18011 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18017 /* If the type we found doesn't match the size we were looking for, then
18018 pretend we didn't find a type at all, the complex target type we
18019 create will then be nameless. */
18020 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18023 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18024 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18027 /* Find a representation of a given base type and install
18028 it in the TYPE field of the die. */
18030 static struct type
*
18031 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18033 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18035 struct attribute
*attr
;
18036 int encoding
= 0, bits
= 0;
18040 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18041 if (attr
!= nullptr && attr
->form_is_constant ())
18042 encoding
= attr
->constant_value (0);
18043 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18044 if (attr
!= nullptr)
18045 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18046 name
= dwarf2_name (die
, cu
);
18048 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18050 arch
= objfile
->arch ();
18051 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18053 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18054 if (attr
!= nullptr && attr
->form_is_constant ())
18056 int endianity
= attr
->constant_value (0);
18061 byte_order
= BFD_ENDIAN_BIG
;
18063 case DW_END_little
:
18064 byte_order
= BFD_ENDIAN_LITTLE
;
18067 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18072 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18073 && cu
->per_cu
->lang
== language_ada
18074 && has_zero_over_zero_small_attribute (die
, cu
))
18076 /* brobecker/2018-02-24: This is a fixed point type for which
18077 the scaling factor is represented as fraction whose value
18078 does not make sense (zero divided by zero), so we should
18079 normally never see these. However, there is a small category
18080 of fixed point types for which GNAT is unable to provide
18081 the scaling factor via the standard DWARF mechanisms, and
18082 for which the info is provided via the GNAT encodings instead.
18083 This is likely what this DIE is about. */
18084 encoding
= (encoding
== DW_ATE_signed_fixed
18086 : DW_ATE_unsigned
);
18089 /* With GNAT encodings, fixed-point information will be encoded in
18090 the type name. Note that this can also occur with the above
18091 zero-over-zero case, which is why this is a separate "if" rather
18092 than an "else if". */
18093 const char *gnat_encoding_suffix
= nullptr;
18094 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18095 && cu
->per_cu
->lang
== language_ada
18096 && name
!= nullptr)
18098 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18099 if (gnat_encoding_suffix
!= nullptr)
18101 gdb_assert (startswith (gnat_encoding_suffix
,
18102 GNAT_FIXED_POINT_SUFFIX
));
18103 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18104 name
, gnat_encoding_suffix
- name
);
18105 /* Use -1 here so that SUFFIX points at the "_" after the
18107 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18109 encoding
= (encoding
== DW_ATE_signed
18110 ? DW_ATE_signed_fixed
18111 : DW_ATE_unsigned_fixed
);
18117 case DW_ATE_address
:
18118 /* Turn DW_ATE_address into a void * pointer. */
18119 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18120 type
= init_pointer_type (objfile
, bits
, name
, type
);
18122 case DW_ATE_boolean
:
18123 type
= init_boolean_type (objfile
, bits
, 1, name
);
18125 case DW_ATE_complex_float
:
18126 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18128 if (type
->code () == TYPE_CODE_ERROR
)
18130 if (name
== nullptr)
18132 struct obstack
*obstack
18133 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18134 name
= obconcat (obstack
, "_Complex ", type
->name (),
18137 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18140 type
= init_complex_type (name
, type
);
18142 case DW_ATE_decimal_float
:
18143 type
= init_decfloat_type (objfile
, bits
, name
);
18146 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18148 case DW_ATE_signed
:
18149 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18151 case DW_ATE_unsigned
:
18152 if (cu
->per_cu
->lang
== language_fortran
18154 && startswith (name
, "character("))
18155 type
= init_character_type (objfile
, bits
, 1, name
);
18157 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18159 case DW_ATE_signed_char
:
18160 if (cu
->per_cu
->lang
== language_ada
18161 || cu
->per_cu
->lang
== language_m2
18162 || cu
->per_cu
->lang
== language_pascal
18163 || cu
->per_cu
->lang
== language_fortran
)
18164 type
= init_character_type (objfile
, bits
, 0, name
);
18166 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18168 case DW_ATE_unsigned_char
:
18169 if (cu
->per_cu
->lang
== language_ada
18170 || cu
->per_cu
->lang
== language_m2
18171 || cu
->per_cu
->lang
== language_pascal
18172 || cu
->per_cu
->lang
== language_fortran
18173 || cu
->per_cu
->lang
== language_rust
)
18174 type
= init_character_type (objfile
, bits
, 1, name
);
18176 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18180 type
= init_character_type (objfile
, bits
, 1, name
);
18181 return set_die_type (die
, type
, cu
);
18184 case DW_ATE_signed_fixed
:
18185 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18186 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18188 case DW_ATE_unsigned_fixed
:
18189 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18190 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18194 complaint (_("unsupported DW_AT_encoding: '%s'"),
18195 dwarf_type_encoding_name (encoding
));
18196 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18200 if (type
->code () == TYPE_CODE_INT
18202 && strcmp (name
, "char") == 0)
18203 type
->set_has_no_signedness (true);
18205 maybe_set_alignment (cu
, die
, type
);
18207 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18209 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18211 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18212 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18214 unsigned real_bit_size
= attr
->as_unsigned ();
18215 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18216 /* Only use the attributes if they make sense together. */
18217 if (attr
== nullptr
18218 || (attr
->as_unsigned () + real_bit_size
18219 <= 8 * TYPE_LENGTH (type
)))
18221 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18223 if (attr
!= nullptr)
18224 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18225 = attr
->as_unsigned ();
18230 return set_die_type (die
, type
, cu
);
18233 /* A helper function that returns the name of DIE, if it refers to a
18234 variable declaration. */
18236 static const char *
18237 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18239 if (die
->tag
!= DW_TAG_variable
)
18242 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18243 if (attr
== nullptr || !attr
->as_boolean ())
18246 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18247 if (attr
== nullptr)
18249 return attr
->as_string ();
18252 /* Parse dwarf attribute if it's a block, reference or constant and put the
18253 resulting value of the attribute into struct bound_prop.
18254 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18257 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18258 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18259 struct type
*default_type
)
18261 struct dwarf2_property_baton
*baton
;
18262 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18263 struct objfile
*objfile
= per_objfile
->objfile
;
18264 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18266 gdb_assert (default_type
!= NULL
);
18268 if (attr
== NULL
|| prop
== NULL
)
18271 if (attr
->form_is_block ())
18273 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18274 baton
->property_type
= default_type
;
18275 baton
->locexpr
.per_cu
= cu
->per_cu
;
18276 baton
->locexpr
.per_objfile
= per_objfile
;
18278 struct dwarf_block
*block
;
18279 if (attr
->form
== DW_FORM_data16
)
18281 size_t data_size
= 16;
18282 block
= XOBNEW (obstack
, struct dwarf_block
);
18283 block
->size
= (data_size
18284 + 2 /* Extra bytes for DW_OP and arg. */);
18285 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18286 data
[0] = DW_OP_implicit_value
;
18287 data
[1] = data_size
;
18288 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18289 block
->data
= data
;
18292 block
= attr
->as_block ();
18294 baton
->locexpr
.size
= block
->size
;
18295 baton
->locexpr
.data
= block
->data
;
18296 switch (attr
->name
)
18298 case DW_AT_string_length
:
18299 baton
->locexpr
.is_reference
= true;
18302 baton
->locexpr
.is_reference
= false;
18306 prop
->set_locexpr (baton
);
18307 gdb_assert (prop
->baton () != NULL
);
18309 else if (attr
->form_is_ref ())
18311 struct dwarf2_cu
*target_cu
= cu
;
18312 struct die_info
*target_die
;
18313 struct attribute
*target_attr
;
18315 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18316 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18317 if (target_attr
== NULL
)
18318 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18320 if (target_attr
== NULL
)
18322 const char *name
= var_decl_name (target_die
, target_cu
);
18323 if (name
!= nullptr)
18325 prop
->set_variable_name (name
);
18331 switch (target_attr
->name
)
18333 case DW_AT_location
:
18334 if (target_attr
->form_is_section_offset ())
18336 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18337 baton
->property_type
= die_type (target_die
, target_cu
);
18338 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18339 prop
->set_loclist (baton
);
18340 gdb_assert (prop
->baton () != NULL
);
18342 else if (target_attr
->form_is_block ())
18344 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18345 baton
->property_type
= die_type (target_die
, target_cu
);
18346 baton
->locexpr
.per_cu
= cu
->per_cu
;
18347 baton
->locexpr
.per_objfile
= per_objfile
;
18348 struct dwarf_block
*block
= target_attr
->as_block ();
18349 baton
->locexpr
.size
= block
->size
;
18350 baton
->locexpr
.data
= block
->data
;
18351 baton
->locexpr
.is_reference
= true;
18352 prop
->set_locexpr (baton
);
18353 gdb_assert (prop
->baton () != NULL
);
18357 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18358 "dynamic property");
18362 case DW_AT_data_member_location
:
18366 if (!handle_data_member_location (target_die
, target_cu
,
18370 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18371 baton
->property_type
= read_type_die (target_die
->parent
,
18373 baton
->offset_info
.offset
= offset
;
18374 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18375 prop
->set_addr_offset (baton
);
18380 else if (attr
->form_is_constant ())
18381 prop
->set_const_val (attr
->constant_value (0));
18384 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18385 dwarf2_name (die
, cu
));
18395 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18397 struct type
*int_type
;
18399 /* Helper macro to examine the various builtin types. */
18400 #define TRY_TYPE(F) \
18401 int_type = (unsigned_p \
18402 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18403 : objfile_type (objfile)->builtin_ ## F); \
18404 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18411 TRY_TYPE (long_long
);
18415 gdb_assert_not_reached ("unable to find suitable integer type");
18418 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18419 present (which is valid) then compute the default type based on the
18420 compilation units address size. */
18422 static struct type
*
18423 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18425 struct type
*index_type
= die_type (die
, cu
);
18427 /* Dwarf-2 specifications explicitly allows to create subrange types
18428 without specifying a base type.
18429 In that case, the base type must be set to the type of
18430 the lower bound, upper bound or count, in that order, if any of these
18431 three attributes references an object that has a type.
18432 If no base type is found, the Dwarf-2 specifications say that
18433 a signed integer type of size equal to the size of an address should
18435 For the following C code: `extern char gdb_int [];'
18436 GCC produces an empty range DIE.
18437 FIXME: muller/2010-05-28: Possible references to object for low bound,
18438 high bound or count are not yet handled by this code. */
18439 if (index_type
->code () == TYPE_CODE_VOID
)
18440 index_type
= cu
->addr_sized_int_type (false);
18445 /* Read the given DW_AT_subrange DIE. */
18447 static struct type
*
18448 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18450 struct type
*base_type
, *orig_base_type
;
18451 struct type
*range_type
;
18452 struct attribute
*attr
;
18453 struct dynamic_prop low
, high
;
18454 int low_default_is_valid
;
18455 int high_bound_is_count
= 0;
18457 ULONGEST negative_mask
;
18459 orig_base_type
= read_subrange_index_type (die
, cu
);
18461 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18462 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18463 creating the range type, but we use the result of check_typedef
18464 when examining properties of the type. */
18465 base_type
= check_typedef (orig_base_type
);
18467 /* The die_type call above may have already set the type for this DIE. */
18468 range_type
= get_die_type (die
, cu
);
18472 high
.set_const_val (0);
18474 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18475 omitting DW_AT_lower_bound. */
18476 switch (cu
->per_cu
->lang
)
18479 case language_cplus
:
18480 low
.set_const_val (0);
18481 low_default_is_valid
= 1;
18483 case language_fortran
:
18484 low
.set_const_val (1);
18485 low_default_is_valid
= 1;
18488 case language_objc
:
18489 case language_rust
:
18490 low
.set_const_val (0);
18491 low_default_is_valid
= (cu
->header
.version
>= 4);
18495 case language_pascal
:
18496 low
.set_const_val (1);
18497 low_default_is_valid
= (cu
->header
.version
>= 4);
18500 low
.set_const_val (0);
18501 low_default_is_valid
= 0;
18505 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18506 if (attr
!= nullptr)
18507 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18508 else if (!low_default_is_valid
)
18509 complaint (_("Missing DW_AT_lower_bound "
18510 "- DIE at %s [in module %s]"),
18511 sect_offset_str (die
->sect_off
),
18512 objfile_name (cu
->per_objfile
->objfile
));
18514 struct attribute
*attr_ub
, *attr_count
;
18515 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18516 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18518 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18519 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18521 /* If bounds are constant do the final calculation here. */
18522 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18523 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18525 high_bound_is_count
= 1;
18529 if (attr_ub
!= NULL
)
18530 complaint (_("Unresolved DW_AT_upper_bound "
18531 "- DIE at %s [in module %s]"),
18532 sect_offset_str (die
->sect_off
),
18533 objfile_name (cu
->per_objfile
->objfile
));
18534 if (attr_count
!= NULL
)
18535 complaint (_("Unresolved DW_AT_count "
18536 "- DIE at %s [in module %s]"),
18537 sect_offset_str (die
->sect_off
),
18538 objfile_name (cu
->per_objfile
->objfile
));
18543 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18544 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18545 bias
= bias_attr
->constant_value (0);
18547 /* Normally, the DWARF producers are expected to use a signed
18548 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18549 But this is unfortunately not always the case, as witnessed
18550 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18551 is used instead. To work around that ambiguity, we treat
18552 the bounds as signed, and thus sign-extend their values, when
18553 the base type is signed. */
18555 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18556 if (low
.kind () == PROP_CONST
18557 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18558 low
.set_const_val (low
.const_val () | negative_mask
);
18559 if (high
.kind () == PROP_CONST
18560 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18561 high
.set_const_val (high
.const_val () | negative_mask
);
18563 /* Check for bit and byte strides. */
18564 struct dynamic_prop byte_stride_prop
;
18565 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18566 if (attr_byte_stride
!= nullptr)
18568 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18569 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18573 struct dynamic_prop bit_stride_prop
;
18574 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18575 if (attr_bit_stride
!= nullptr)
18577 /* It only makes sense to have either a bit or byte stride. */
18578 if (attr_byte_stride
!= nullptr)
18580 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18581 "- DIE at %s [in module %s]"),
18582 sect_offset_str (die
->sect_off
),
18583 objfile_name (cu
->per_objfile
->objfile
));
18584 attr_bit_stride
= nullptr;
18588 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18589 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18594 if (attr_byte_stride
!= nullptr
18595 || attr_bit_stride
!= nullptr)
18597 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18598 struct dynamic_prop
*stride
18599 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18602 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18603 &high
, bias
, stride
, byte_stride_p
);
18606 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18608 if (high_bound_is_count
)
18609 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18611 /* Ada expects an empty array on no boundary attributes. */
18612 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18613 range_type
->bounds ()->high
.set_undefined ();
18615 name
= dwarf2_name (die
, cu
);
18617 range_type
->set_name (name
);
18619 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18620 if (attr
!= nullptr)
18621 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18623 maybe_set_alignment (cu
, die
, range_type
);
18625 set_die_type (die
, range_type
, cu
);
18627 /* set_die_type should be already done. */
18628 set_descriptive_type (range_type
, die
, cu
);
18633 static struct type
*
18634 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18638 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18639 type
->set_name (dwarf2_name (die
, cu
));
18641 /* In Ada, an unspecified type is typically used when the description
18642 of the type is deferred to a different unit. When encountering
18643 such a type, we treat it as a stub, and try to resolve it later on,
18645 if (cu
->per_cu
->lang
== language_ada
)
18646 type
->set_is_stub (true);
18648 return set_die_type (die
, type
, cu
);
18651 /* Read a single die and all its descendents. Set the die's sibling
18652 field to NULL; set other fields in the die correctly, and set all
18653 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18654 location of the info_ptr after reading all of those dies. PARENT
18655 is the parent of the die in question. */
18657 static struct die_info
*
18658 read_die_and_children (const struct die_reader_specs
*reader
,
18659 const gdb_byte
*info_ptr
,
18660 const gdb_byte
**new_info_ptr
,
18661 struct die_info
*parent
)
18663 struct die_info
*die
;
18664 const gdb_byte
*cur_ptr
;
18666 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18669 *new_info_ptr
= cur_ptr
;
18672 store_in_ref_table (die
, reader
->cu
);
18674 if (die
->has_children
)
18675 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18679 *new_info_ptr
= cur_ptr
;
18682 die
->sibling
= NULL
;
18683 die
->parent
= parent
;
18687 /* Read a die, all of its descendents, and all of its siblings; set
18688 all of the fields of all of the dies correctly. Arguments are as
18689 in read_die_and_children. */
18691 static struct die_info
*
18692 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18693 const gdb_byte
*info_ptr
,
18694 const gdb_byte
**new_info_ptr
,
18695 struct die_info
*parent
)
18697 struct die_info
*first_die
, *last_sibling
;
18698 const gdb_byte
*cur_ptr
;
18700 cur_ptr
= info_ptr
;
18701 first_die
= last_sibling
= NULL
;
18705 struct die_info
*die
18706 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18710 *new_info_ptr
= cur_ptr
;
18717 last_sibling
->sibling
= die
;
18719 last_sibling
= die
;
18723 /* Read a die, all of its descendents, and all of its siblings; set
18724 all of the fields of all of the dies correctly. Arguments are as
18725 in read_die_and_children.
18726 This the main entry point for reading a DIE and all its children. */
18728 static struct die_info
*
18729 read_die_and_siblings (const struct die_reader_specs
*reader
,
18730 const gdb_byte
*info_ptr
,
18731 const gdb_byte
**new_info_ptr
,
18732 struct die_info
*parent
)
18734 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18735 new_info_ptr
, parent
);
18737 if (dwarf_die_debug
)
18739 fprintf_unfiltered (gdb_stdlog
,
18740 "Read die from %s@0x%x of %s:\n",
18741 reader
->die_section
->get_name (),
18742 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18743 bfd_get_filename (reader
->abfd
));
18744 dump_die (die
, dwarf_die_debug
);
18750 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18752 The caller is responsible for filling in the extra attributes
18753 and updating (*DIEP)->num_attrs.
18754 Set DIEP to point to a newly allocated die with its information,
18755 except for its child, sibling, and parent fields. */
18757 static const gdb_byte
*
18758 read_full_die_1 (const struct die_reader_specs
*reader
,
18759 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18760 int num_extra_attrs
)
18762 unsigned int abbrev_number
, bytes_read
, i
;
18763 const struct abbrev_info
*abbrev
;
18764 struct die_info
*die
;
18765 struct dwarf2_cu
*cu
= reader
->cu
;
18766 bfd
*abfd
= reader
->abfd
;
18768 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18769 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18770 info_ptr
+= bytes_read
;
18771 if (!abbrev_number
)
18777 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18779 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18781 bfd_get_filename (abfd
));
18783 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18784 die
->sect_off
= sect_off
;
18785 die
->tag
= abbrev
->tag
;
18786 die
->abbrev
= abbrev_number
;
18787 die
->has_children
= abbrev
->has_children
;
18789 /* Make the result usable.
18790 The caller needs to update num_attrs after adding the extra
18792 die
->num_attrs
= abbrev
->num_attrs
;
18794 bool any_need_reprocess
= false;
18795 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18797 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18799 if (die
->attrs
[i
].requires_reprocessing_p ())
18800 any_need_reprocess
= true;
18803 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18804 if (attr
!= nullptr && attr
->form_is_unsigned ())
18805 cu
->str_offsets_base
= attr
->as_unsigned ();
18807 attr
= die
->attr (DW_AT_loclists_base
);
18808 if (attr
!= nullptr)
18809 cu
->loclist_base
= attr
->as_unsigned ();
18811 auto maybe_addr_base
= die
->addr_base ();
18812 if (maybe_addr_base
.has_value ())
18813 cu
->addr_base
= *maybe_addr_base
;
18815 attr
= die
->attr (DW_AT_rnglists_base
);
18816 if (attr
!= nullptr)
18817 cu
->rnglists_base
= attr
->as_unsigned ();
18819 if (any_need_reprocess
)
18821 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18823 if (die
->attrs
[i
].requires_reprocessing_p ())
18824 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18831 /* Read a die and all its attributes.
18832 Set DIEP to point to a newly allocated die with its information,
18833 except for its child, sibling, and parent fields. */
18835 static const gdb_byte
*
18836 read_full_die (const struct die_reader_specs
*reader
,
18837 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18839 const gdb_byte
*result
;
18841 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18843 if (dwarf_die_debug
)
18845 fprintf_unfiltered (gdb_stdlog
,
18846 "Read die from %s@0x%x of %s:\n",
18847 reader
->die_section
->get_name (),
18848 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18849 bfd_get_filename (reader
->abfd
));
18850 dump_die (*diep
, dwarf_die_debug
);
18857 /* Returns nonzero if TAG represents a type that we might generate a partial
18861 is_type_tag_for_partial (int tag
, enum language lang
)
18866 /* Some types that would be reasonable to generate partial symbols for,
18867 that we don't at present. Note that normally this does not
18868 matter, mainly because C compilers don't give names to these
18869 types, but instead emit DW_TAG_typedef. */
18870 case DW_TAG_file_type
:
18871 case DW_TAG_ptr_to_member_type
:
18872 case DW_TAG_set_type
:
18873 case DW_TAG_string_type
:
18874 case DW_TAG_subroutine_type
:
18877 /* GNAT may emit an array with a name, but no typedef, so we
18878 need to make a symbol in this case. */
18879 case DW_TAG_array_type
:
18880 return lang
== language_ada
;
18882 case DW_TAG_base_type
:
18883 case DW_TAG_class_type
:
18884 case DW_TAG_interface_type
:
18885 case DW_TAG_enumeration_type
:
18886 case DW_TAG_structure_type
:
18887 case DW_TAG_subrange_type
:
18888 case DW_TAG_typedef
:
18889 case DW_TAG_union_type
:
18896 /* Load all DIEs that are interesting for partial symbols into memory. */
18898 static struct partial_die_info
*
18899 load_partial_dies (const struct die_reader_specs
*reader
,
18900 const gdb_byte
*info_ptr
, int building_psymtab
)
18902 struct dwarf2_cu
*cu
= reader
->cu
;
18903 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18904 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18905 unsigned int bytes_read
;
18906 unsigned int load_all
= 0;
18907 int nesting_level
= 1;
18912 gdb_assert (cu
->per_cu
!= NULL
);
18913 if (cu
->load_all_dies
)
18917 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18921 &cu
->comp_unit_obstack
,
18922 hashtab_obstack_allocate
,
18923 dummy_obstack_deallocate
);
18927 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18930 /* A NULL abbrev means the end of a series of children. */
18931 if (abbrev
== NULL
)
18933 if (--nesting_level
== 0)
18936 info_ptr
+= bytes_read
;
18937 last_die
= parent_die
;
18938 parent_die
= parent_die
->die_parent
;
18942 /* Check for template arguments. We never save these; if
18943 they're seen, we just mark the parent, and go on our way. */
18944 if (parent_die
!= NULL
18945 && cu
->per_cu
->lang
== language_cplus
18946 && (abbrev
->tag
== DW_TAG_template_type_param
18947 || abbrev
->tag
== DW_TAG_template_value_param
))
18949 parent_die
->has_template_arguments
= 1;
18953 /* We don't need a partial DIE for the template argument. */
18954 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18959 /* We only recurse into c++ subprograms looking for template arguments.
18960 Skip their other children. */
18962 && cu
->per_cu
->lang
== language_cplus
18963 && parent_die
!= NULL
18964 && parent_die
->tag
== DW_TAG_subprogram
18965 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18967 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18971 /* Check whether this DIE is interesting enough to save. Normally
18972 we would not be interested in members here, but there may be
18973 later variables referencing them via DW_AT_specification (for
18974 static members). */
18976 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
18977 && abbrev
->tag
!= DW_TAG_constant
18978 && abbrev
->tag
!= DW_TAG_enumerator
18979 && abbrev
->tag
!= DW_TAG_subprogram
18980 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18981 && abbrev
->tag
!= DW_TAG_lexical_block
18982 && abbrev
->tag
!= DW_TAG_variable
18983 && abbrev
->tag
!= DW_TAG_namespace
18984 && abbrev
->tag
!= DW_TAG_module
18985 && abbrev
->tag
!= DW_TAG_member
18986 && abbrev
->tag
!= DW_TAG_imported_unit
18987 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18989 /* Otherwise we skip to the next sibling, if any. */
18990 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18994 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18997 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18999 /* This two-pass algorithm for processing partial symbols has a
19000 high cost in cache pressure. Thus, handle some simple cases
19001 here which cover the majority of C partial symbols. DIEs
19002 which neither have specification tags in them, nor could have
19003 specification tags elsewhere pointing at them, can simply be
19004 processed and discarded.
19006 This segment is also optional; scan_partial_symbols and
19007 add_partial_symbol will handle these DIEs if we chain
19008 them in normally. When compilers which do not emit large
19009 quantities of duplicate debug information are more common,
19010 this code can probably be removed. */
19012 /* Any complete simple types at the top level (pretty much all
19013 of them, for a language without namespaces), can be processed
19015 if (parent_die
== NULL
19016 && pdi
.has_specification
== 0
19017 && pdi
.is_declaration
== 0
19018 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19019 || pdi
.tag
== DW_TAG_base_type
19020 || pdi
.tag
== DW_TAG_array_type
19021 || pdi
.tag
== DW_TAG_subrange_type
))
19023 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19024 add_partial_symbol (&pdi
, cu
);
19026 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19030 /* The exception for DW_TAG_typedef with has_children above is
19031 a workaround of GCC PR debug/47510. In the case of this complaint
19032 type_name_or_error will error on such types later.
19034 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19035 it could not find the child DIEs referenced later, this is checked
19036 above. In correct DWARF DW_TAG_typedef should have no children. */
19038 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19039 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19040 "- DIE at %s [in module %s]"),
19041 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19043 /* If we're at the second level, and we're an enumerator, and
19044 our parent has no specification (meaning possibly lives in a
19045 namespace elsewhere), then we can add the partial symbol now
19046 instead of queueing it. */
19047 if (pdi
.tag
== DW_TAG_enumerator
19048 && parent_die
!= NULL
19049 && parent_die
->die_parent
== NULL
19050 && parent_die
->tag
== DW_TAG_enumeration_type
19051 && parent_die
->has_specification
== 0)
19053 if (pdi
.raw_name
== NULL
)
19054 complaint (_("malformed enumerator DIE ignored"));
19055 else if (building_psymtab
)
19056 add_partial_symbol (&pdi
, cu
);
19058 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19062 struct partial_die_info
*part_die
19063 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19065 /* We'll save this DIE so link it in. */
19066 part_die
->die_parent
= parent_die
;
19067 part_die
->die_sibling
= NULL
;
19068 part_die
->die_child
= NULL
;
19070 if (last_die
&& last_die
== parent_die
)
19071 last_die
->die_child
= part_die
;
19073 last_die
->die_sibling
= part_die
;
19075 last_die
= part_die
;
19077 if (first_die
== NULL
)
19078 first_die
= part_die
;
19080 /* Maybe add the DIE to the hash table. Not all DIEs that we
19081 find interesting need to be in the hash table, because we
19082 also have the parent/sibling/child chains; only those that we
19083 might refer to by offset later during partial symbol reading.
19085 For now this means things that might have be the target of a
19086 DW_AT_specification, DW_AT_abstract_origin, or
19087 DW_AT_extension. DW_AT_extension will refer only to
19088 namespaces; DW_AT_abstract_origin refers to functions (and
19089 many things under the function DIE, but we do not recurse
19090 into function DIEs during partial symbol reading) and
19091 possibly variables as well; DW_AT_specification refers to
19092 declarations. Declarations ought to have the DW_AT_declaration
19093 flag. It happens that GCC forgets to put it in sometimes, but
19094 only for functions, not for types.
19096 Adding more things than necessary to the hash table is harmless
19097 except for the performance cost. Adding too few will result in
19098 wasted time in find_partial_die, when we reread the compilation
19099 unit with load_all_dies set. */
19102 || abbrev
->tag
== DW_TAG_constant
19103 || abbrev
->tag
== DW_TAG_subprogram
19104 || abbrev
->tag
== DW_TAG_variable
19105 || abbrev
->tag
== DW_TAG_namespace
19106 || part_die
->is_declaration
)
19110 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19111 to_underlying (part_die
->sect_off
),
19116 /* For some DIEs we want to follow their children (if any). For C
19117 we have no reason to follow the children of structures; for other
19118 languages we have to, so that we can get at method physnames
19119 to infer fully qualified class names, for DW_AT_specification,
19120 and for C++ template arguments. For C++, we also look one level
19121 inside functions to find template arguments (if the name of the
19122 function does not already contain the template arguments).
19124 For Ada and Fortran, we need to scan the children of subprograms
19125 and lexical blocks as well because these languages allow the
19126 definition of nested entities that could be interesting for the
19127 debugger, such as nested subprograms for instance. */
19128 if (last_die
->has_children
19130 || last_die
->tag
== DW_TAG_namespace
19131 || last_die
->tag
== DW_TAG_module
19132 || last_die
->tag
== DW_TAG_enumeration_type
19133 || (cu
->per_cu
->lang
== language_cplus
19134 && last_die
->tag
== DW_TAG_subprogram
19135 && (last_die
->raw_name
== NULL
19136 || strchr (last_die
->raw_name
, '<') == NULL
))
19137 || (cu
->per_cu
->lang
!= language_c
19138 && (last_die
->tag
== DW_TAG_class_type
19139 || last_die
->tag
== DW_TAG_interface_type
19140 || last_die
->tag
== DW_TAG_structure_type
19141 || last_die
->tag
== DW_TAG_union_type
))
19142 || ((cu
->per_cu
->lang
== language_ada
19143 || cu
->per_cu
->lang
== language_fortran
)
19144 && (last_die
->tag
== DW_TAG_subprogram
19145 || last_die
->tag
== DW_TAG_lexical_block
))))
19148 parent_die
= last_die
;
19152 /* Otherwise we skip to the next sibling, if any. */
19153 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19155 /* Back to the top, do it again. */
19159 partial_die_info::partial_die_info (sect_offset sect_off_
,
19160 const struct abbrev_info
*abbrev
)
19161 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19165 /* See class definition. */
19168 partial_die_info::name (dwarf2_cu
*cu
)
19170 if (!canonical_name
&& raw_name
!= nullptr)
19172 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19173 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19174 canonical_name
= 1;
19180 /* Read a minimal amount of information into the minimal die structure.
19181 INFO_PTR should point just after the initial uleb128 of a DIE. */
19184 partial_die_info::read (const struct die_reader_specs
*reader
,
19185 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19187 struct dwarf2_cu
*cu
= reader
->cu
;
19188 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19190 int has_low_pc_attr
= 0;
19191 int has_high_pc_attr
= 0;
19192 int high_pc_relative
= 0;
19194 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19197 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19198 /* String and address offsets that need to do the reprocessing have
19199 already been read at this point, so there is no need to wait until
19200 the loop terminates to do the reprocessing. */
19201 if (attr
.requires_reprocessing_p ())
19202 read_attribute_reprocess (reader
, &attr
, tag
);
19203 /* Store the data if it is of an attribute we want to keep in a
19204 partial symbol table. */
19210 case DW_TAG_compile_unit
:
19211 case DW_TAG_partial_unit
:
19212 case DW_TAG_type_unit
:
19213 /* Compilation units have a DW_AT_name that is a filename, not
19214 a source language identifier. */
19215 case DW_TAG_enumeration_type
:
19216 case DW_TAG_enumerator
:
19217 /* These tags always have simple identifiers already; no need
19218 to canonicalize them. */
19219 canonical_name
= 1;
19220 raw_name
= attr
.as_string ();
19223 canonical_name
= 0;
19224 raw_name
= attr
.as_string ();
19228 case DW_AT_linkage_name
:
19229 case DW_AT_MIPS_linkage_name
:
19230 /* Note that both forms of linkage name might appear. We
19231 assume they will be the same, and we only store the last
19233 linkage_name
= attr
.as_string ();
19236 has_low_pc_attr
= 1;
19237 lowpc
= attr
.as_address ();
19239 case DW_AT_high_pc
:
19240 has_high_pc_attr
= 1;
19241 highpc
= attr
.as_address ();
19242 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19243 high_pc_relative
= 1;
19245 case DW_AT_location
:
19246 /* Support the .debug_loc offsets. */
19247 if (attr
.form_is_block ())
19249 d
.locdesc
= attr
.as_block ();
19251 else if (attr
.form_is_section_offset ())
19253 dwarf2_complex_location_expr_complaint ();
19257 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19258 "partial symbol information");
19261 case DW_AT_external
:
19262 is_external
= attr
.as_boolean ();
19264 case DW_AT_declaration
:
19265 is_declaration
= attr
.as_boolean ();
19270 case DW_AT_abstract_origin
:
19271 case DW_AT_specification
:
19272 case DW_AT_extension
:
19273 has_specification
= 1;
19274 spec_offset
= attr
.get_ref_die_offset ();
19275 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19276 || cu
->per_cu
->is_dwz
);
19278 case DW_AT_sibling
:
19279 /* Ignore absolute siblings, they might point outside of
19280 the current compile unit. */
19281 if (attr
.form
== DW_FORM_ref_addr
)
19282 complaint (_("ignoring absolute DW_AT_sibling"));
19285 const gdb_byte
*buffer
= reader
->buffer
;
19286 sect_offset off
= attr
.get_ref_die_offset ();
19287 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19289 if (sibling_ptr
< info_ptr
)
19290 complaint (_("DW_AT_sibling points backwards"));
19291 else if (sibling_ptr
> reader
->buffer_end
)
19292 reader
->die_section
->overflow_complaint ();
19294 sibling
= sibling_ptr
;
19297 case DW_AT_byte_size
:
19300 case DW_AT_const_value
:
19301 has_const_value
= 1;
19303 case DW_AT_calling_convention
:
19304 /* DWARF doesn't provide a way to identify a program's source-level
19305 entry point. DW_AT_calling_convention attributes are only meant
19306 to describe functions' calling conventions.
19308 However, because it's a necessary piece of information in
19309 Fortran, and before DWARF 4 DW_CC_program was the only
19310 piece of debugging information whose definition refers to
19311 a 'main program' at all, several compilers marked Fortran
19312 main programs with DW_CC_program --- even when those
19313 functions use the standard calling conventions.
19315 Although DWARF now specifies a way to provide this
19316 information, we support this practice for backward
19318 if (attr
.constant_value (0) == DW_CC_program
19319 && cu
->per_cu
->lang
== language_fortran
)
19320 main_subprogram
= 1;
19324 LONGEST value
= attr
.constant_value (-1);
19325 if (value
== DW_INL_inlined
19326 || value
== DW_INL_declared_inlined
)
19327 may_be_inlined
= 1;
19332 if (tag
== DW_TAG_imported_unit
)
19334 d
.sect_off
= attr
.get_ref_die_offset ();
19335 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19336 || cu
->per_cu
->is_dwz
);
19340 case DW_AT_main_subprogram
:
19341 main_subprogram
= attr
.as_boolean ();
19346 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19347 on DWARF version). */
19348 ULONGEST ranges_offset
= attr
.as_unsigned ();
19350 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19352 if (tag
!= DW_TAG_compile_unit
)
19353 ranges_offset
+= cu
->gnu_ranges_base
;
19355 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19366 /* For Ada, if both the name and the linkage name appear, we prefer
19367 the latter. This lets "catch exception" work better, regardless
19368 of the order in which the name and linkage name were emitted.
19369 Really, though, this is just a workaround for the fact that gdb
19370 doesn't store both the name and the linkage name. */
19371 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19372 raw_name
= linkage_name
;
19374 if (high_pc_relative
)
19377 if (has_low_pc_attr
&& has_high_pc_attr
)
19379 /* When using the GNU linker, .gnu.linkonce. sections are used to
19380 eliminate duplicate copies of functions and vtables and such.
19381 The linker will arbitrarily choose one and discard the others.
19382 The AT_*_pc values for such functions refer to local labels in
19383 these sections. If the section from that file was discarded, the
19384 labels are not in the output, so the relocs get a value of 0.
19385 If this is a discarded function, mark the pc bounds as invalid,
19386 so that GDB will ignore it. */
19387 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19389 struct objfile
*objfile
= per_objfile
->objfile
;
19390 struct gdbarch
*gdbarch
= objfile
->arch ();
19392 complaint (_("DW_AT_low_pc %s is zero "
19393 "for DIE at %s [in module %s]"),
19394 paddress (gdbarch
, lowpc
),
19395 sect_offset_str (sect_off
),
19396 objfile_name (objfile
));
19398 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19399 else if (lowpc
>= highpc
)
19401 struct objfile
*objfile
= per_objfile
->objfile
;
19402 struct gdbarch
*gdbarch
= objfile
->arch ();
19404 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19405 "for DIE at %s [in module %s]"),
19406 paddress (gdbarch
, lowpc
),
19407 paddress (gdbarch
, highpc
),
19408 sect_offset_str (sect_off
),
19409 objfile_name (objfile
));
19418 /* Find a cached partial DIE at OFFSET in CU. */
19420 struct partial_die_info
*
19421 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19423 struct partial_die_info
*lookup_die
= NULL
;
19424 struct partial_die_info
part_die (sect_off
);
19426 lookup_die
= ((struct partial_die_info
*)
19427 htab_find_with_hash (partial_dies
, &part_die
,
19428 to_underlying (sect_off
)));
19433 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19434 except in the case of .debug_types DIEs which do not reference
19435 outside their CU (they do however referencing other types via
19436 DW_FORM_ref_sig8). */
19438 static const struct cu_partial_die_info
19439 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19441 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19442 struct objfile
*objfile
= per_objfile
->objfile
;
19443 struct partial_die_info
*pd
= NULL
;
19445 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19446 && cu
->header
.offset_in_cu_p (sect_off
))
19448 pd
= cu
->find_partial_die (sect_off
);
19451 /* We missed recording what we needed.
19452 Load all dies and try again. */
19456 /* TUs don't reference other CUs/TUs (except via type signatures). */
19457 if (cu
->per_cu
->is_debug_types
)
19459 error (_("Dwarf Error: Type Unit at offset %s contains"
19460 " external reference to offset %s [in module %s].\n"),
19461 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19462 bfd_get_filename (objfile
->obfd
));
19464 dwarf2_per_cu_data
*per_cu
19465 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19468 cu
= per_objfile
->get_cu (per_cu
);
19469 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19470 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19472 cu
= per_objfile
->get_cu (per_cu
);
19475 pd
= cu
->find_partial_die (sect_off
);
19478 /* If we didn't find it, and not all dies have been loaded,
19479 load them all and try again. */
19481 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19483 cu
->load_all_dies
= 1;
19485 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19486 THIS_CU->cu may already be in use. So we can't just free it and
19487 replace its DIEs with the ones we read in. Instead, we leave those
19488 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19489 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19491 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19493 pd
= cu
->find_partial_die (sect_off
);
19497 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19498 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19502 /* See if we can figure out if the class lives in a namespace. We do
19503 this by looking for a member function; its demangled name will
19504 contain namespace info, if there is any. */
19507 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19508 struct dwarf2_cu
*cu
)
19510 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19511 what template types look like, because the demangler
19512 frequently doesn't give the same name as the debug info. We
19513 could fix this by only using the demangled name to get the
19514 prefix (but see comment in read_structure_type). */
19516 struct partial_die_info
*real_pdi
;
19517 struct partial_die_info
*child_pdi
;
19519 /* If this DIE (this DIE's specification, if any) has a parent, then
19520 we should not do this. We'll prepend the parent's fully qualified
19521 name when we create the partial symbol. */
19523 real_pdi
= struct_pdi
;
19524 while (real_pdi
->has_specification
)
19526 auto res
= find_partial_die (real_pdi
->spec_offset
,
19527 real_pdi
->spec_is_dwz
, cu
);
19528 real_pdi
= res
.pdi
;
19532 if (real_pdi
->die_parent
!= NULL
)
19535 for (child_pdi
= struct_pdi
->die_child
;
19537 child_pdi
= child_pdi
->die_sibling
)
19539 if (child_pdi
->tag
== DW_TAG_subprogram
19540 && child_pdi
->linkage_name
!= NULL
)
19542 gdb::unique_xmalloc_ptr
<char> actual_class_name
19543 (cu
->language_defn
->class_name_from_physname
19544 (child_pdi
->linkage_name
));
19545 if (actual_class_name
!= NULL
)
19547 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19548 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19549 struct_pdi
->canonical_name
= 1;
19556 /* Return true if a DIE with TAG may have the DW_AT_const_value
19560 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19564 case DW_TAG_constant
:
19565 case DW_TAG_enumerator
:
19566 case DW_TAG_formal_parameter
:
19567 case DW_TAG_template_value_param
:
19568 case DW_TAG_variable
:
19576 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19578 /* Once we've fixed up a die, there's no point in doing so again.
19579 This also avoids a memory leak if we were to call
19580 guess_partial_die_structure_name multiple times. */
19584 /* If we found a reference attribute and the DIE has no name, try
19585 to find a name in the referred to DIE. */
19587 if (raw_name
== NULL
&& has_specification
)
19589 struct partial_die_info
*spec_die
;
19591 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19592 spec_die
= res
.pdi
;
19595 spec_die
->fixup (cu
);
19597 if (spec_die
->raw_name
)
19599 raw_name
= spec_die
->raw_name
;
19600 canonical_name
= spec_die
->canonical_name
;
19602 /* Copy DW_AT_external attribute if it is set. */
19603 if (spec_die
->is_external
)
19604 is_external
= spec_die
->is_external
;
19608 if (!has_const_value
&& has_specification
19609 && can_have_DW_AT_const_value_p (tag
))
19611 struct partial_die_info
*spec_die
;
19613 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19614 spec_die
= res
.pdi
;
19617 spec_die
->fixup (cu
);
19619 if (spec_die
->has_const_value
)
19621 /* Copy DW_AT_const_value attribute if it is set. */
19622 has_const_value
= spec_die
->has_const_value
;
19626 /* Set default names for some unnamed DIEs. */
19628 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19630 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19631 canonical_name
= 1;
19634 /* If there is no parent die to provide a namespace, and there are
19635 children, see if we can determine the namespace from their linkage
19637 if (cu
->per_cu
->lang
== language_cplus
19638 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19639 && die_parent
== NULL
19641 && (tag
== DW_TAG_class_type
19642 || tag
== DW_TAG_structure_type
19643 || tag
== DW_TAG_union_type
))
19644 guess_partial_die_structure_name (this, cu
);
19646 /* GCC might emit a nameless struct or union that has a linkage
19647 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19648 if (raw_name
== NULL
19649 && (tag
== DW_TAG_class_type
19650 || tag
== DW_TAG_interface_type
19651 || tag
== DW_TAG_structure_type
19652 || tag
== DW_TAG_union_type
)
19653 && linkage_name
!= NULL
)
19655 gdb::unique_xmalloc_ptr
<char> demangled
19656 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19657 if (demangled
!= nullptr)
19661 /* Strip any leading namespaces/classes, keep only the base name.
19662 DW_AT_name for named DIEs does not contain the prefixes. */
19663 base
= strrchr (demangled
.get (), ':');
19664 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19667 base
= demangled
.get ();
19669 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19670 raw_name
= objfile
->intern (base
);
19671 canonical_name
= 1;
19678 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19679 contents from the given SECTION in the HEADER.
19681 HEADER_OFFSET is the offset of the header in the section. */
19683 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19684 struct dwarf2_section_info
*section
,
19685 sect_offset header_offset
)
19687 unsigned int bytes_read
;
19688 bfd
*abfd
= section
->get_bfd_owner ();
19689 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19691 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19692 info_ptr
+= bytes_read
;
19694 header
->version
= read_2_bytes (abfd
, info_ptr
);
19697 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19700 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19703 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19706 /* Return the DW_AT_loclists_base value for the CU. */
19708 lookup_loclist_base (struct dwarf2_cu
*cu
)
19710 /* For the .dwo unit, the loclist_base points to the first offset following
19711 the header. The header consists of the following entities-
19712 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19714 2. version (2 bytes)
19715 3. address size (1 byte)
19716 4. segment selector size (1 byte)
19717 5. offset entry count (4 bytes)
19718 These sizes are derived as per the DWARFv5 standard. */
19719 if (cu
->dwo_unit
!= nullptr)
19721 if (cu
->header
.initial_length_size
== 4)
19722 return LOCLIST_HEADER_SIZE32
;
19723 return LOCLIST_HEADER_SIZE64
;
19725 return cu
->loclist_base
;
19728 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19729 array of offsets in the .debug_loclists section. */
19732 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19734 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19735 struct objfile
*objfile
= per_objfile
->objfile
;
19736 bfd
*abfd
= objfile
->obfd
;
19737 ULONGEST loclist_header_size
=
19738 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19739 : LOCLIST_HEADER_SIZE64
);
19740 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19742 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19743 ULONGEST start_offset
=
19744 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19746 /* Get loclists section. */
19747 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19749 /* Read the loclists section content. */
19750 section
->read (objfile
);
19751 if (section
->buffer
== NULL
)
19752 error (_("DW_FORM_loclistx used without .debug_loclists "
19753 "section [in module %s]"), objfile_name (objfile
));
19755 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19756 so if loclist_base is smaller than the header size, we have a problem. */
19757 if (loclist_base
< loclist_header_size
)
19758 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19759 objfile_name (objfile
));
19761 /* Read the header of the loclists contribution. */
19762 struct loclists_rnglists_header header
;
19763 read_loclists_rnglists_header (&header
, section
,
19764 (sect_offset
) (loclist_base
- loclist_header_size
));
19766 /* Verify the loclist index is valid. */
19767 if (loclist_index
>= header
.offset_entry_count
)
19768 error (_("DW_FORM_loclistx pointing outside of "
19769 ".debug_loclists offset array [in module %s]"),
19770 objfile_name (objfile
));
19772 /* Validate that reading won't go beyond the end of the section. */
19773 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19774 error (_("Reading DW_FORM_loclistx index beyond end of"
19775 ".debug_loclists section [in module %s]"),
19776 objfile_name (objfile
));
19778 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19780 if (cu
->header
.offset_size
== 4)
19781 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19783 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19786 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19787 array of offsets in the .debug_rnglists section. */
19790 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19793 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19794 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19795 bfd
*abfd
= objfile
->obfd
;
19796 ULONGEST rnglist_header_size
=
19797 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19798 : RNGLIST_HEADER_SIZE64
);
19800 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19801 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19803 ULONGEST rnglist_base
=
19804 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19806 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19807 ULONGEST start_offset
=
19808 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19810 /* Get rnglists section. */
19811 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19813 /* Read the rnglists section content. */
19814 section
->read (objfile
);
19815 if (section
->buffer
== nullptr)
19816 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19818 objfile_name (objfile
));
19820 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19821 so if rnglist_base is smaller than the header size, we have a problem. */
19822 if (rnglist_base
< rnglist_header_size
)
19823 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19824 objfile_name (objfile
));
19826 /* Read the header of the rnglists contribution. */
19827 struct loclists_rnglists_header header
;
19828 read_loclists_rnglists_header (&header
, section
,
19829 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19831 /* Verify the rnglist index is valid. */
19832 if (rnglist_index
>= header
.offset_entry_count
)
19833 error (_("DW_FORM_rnglistx index pointing outside of "
19834 ".debug_rnglists offset array [in module %s]"),
19835 objfile_name (objfile
));
19837 /* Validate that reading won't go beyond the end of the section. */
19838 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19839 error (_("Reading DW_FORM_rnglistx index beyond end of"
19840 ".debug_rnglists section [in module %s]"),
19841 objfile_name (objfile
));
19843 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19845 if (cu
->header
.offset_size
== 4)
19846 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19848 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19851 /* Process the attributes that had to be skipped in the first round. These
19852 attributes are the ones that need str_offsets_base or addr_base attributes.
19853 They could not have been processed in the first round, because at the time
19854 the values of str_offsets_base or addr_base may not have been known. */
19856 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19857 struct attribute
*attr
, dwarf_tag tag
)
19859 struct dwarf2_cu
*cu
= reader
->cu
;
19860 switch (attr
->form
)
19862 case DW_FORM_addrx
:
19863 case DW_FORM_GNU_addr_index
:
19864 attr
->set_address (read_addr_index (cu
,
19865 attr
->as_unsigned_reprocess ()));
19867 case DW_FORM_loclistx
:
19869 sect_offset loclists_sect_off
19870 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19872 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19875 case DW_FORM_rnglistx
:
19877 sect_offset rnglists_sect_off
19878 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19880 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19884 case DW_FORM_strx1
:
19885 case DW_FORM_strx2
:
19886 case DW_FORM_strx3
:
19887 case DW_FORM_strx4
:
19888 case DW_FORM_GNU_str_index
:
19890 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19891 gdb_assert (!attr
->canonical_string_p ());
19892 if (reader
->dwo_file
!= NULL
)
19893 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19896 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19901 gdb_assert_not_reached (_("Unexpected DWARF form."));
19905 /* Read an attribute value described by an attribute form. */
19907 static const gdb_byte
*
19908 read_attribute_value (const struct die_reader_specs
*reader
,
19909 struct attribute
*attr
, unsigned form
,
19910 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19912 struct dwarf2_cu
*cu
= reader
->cu
;
19913 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19914 struct objfile
*objfile
= per_objfile
->objfile
;
19915 bfd
*abfd
= reader
->abfd
;
19916 struct comp_unit_head
*cu_header
= &cu
->header
;
19917 unsigned int bytes_read
;
19918 struct dwarf_block
*blk
;
19920 attr
->form
= (enum dwarf_form
) form
;
19923 case DW_FORM_ref_addr
:
19924 if (cu_header
->version
== 2)
19925 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19928 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19930 info_ptr
+= bytes_read
;
19932 case DW_FORM_GNU_ref_alt
:
19933 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19935 info_ptr
+= bytes_read
;
19939 struct gdbarch
*gdbarch
= objfile
->arch ();
19940 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19941 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19942 attr
->set_address (addr
);
19943 info_ptr
+= bytes_read
;
19946 case DW_FORM_block2
:
19947 blk
= dwarf_alloc_block (cu
);
19948 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19950 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19951 info_ptr
+= blk
->size
;
19952 attr
->set_block (blk
);
19954 case DW_FORM_block4
:
19955 blk
= dwarf_alloc_block (cu
);
19956 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19958 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19959 info_ptr
+= blk
->size
;
19960 attr
->set_block (blk
);
19962 case DW_FORM_data2
:
19963 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19966 case DW_FORM_data4
:
19967 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19970 case DW_FORM_data8
:
19971 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19974 case DW_FORM_data16
:
19975 blk
= dwarf_alloc_block (cu
);
19977 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19979 attr
->set_block (blk
);
19981 case DW_FORM_sec_offset
:
19982 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19984 info_ptr
+= bytes_read
;
19986 case DW_FORM_loclistx
:
19988 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19990 info_ptr
+= bytes_read
;
19993 case DW_FORM_string
:
19994 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19996 info_ptr
+= bytes_read
;
19999 if (!cu
->per_cu
->is_dwz
)
20001 attr
->set_string_noncanonical
20002 (read_indirect_string (per_objfile
,
20003 abfd
, info_ptr
, cu_header
,
20005 info_ptr
+= bytes_read
;
20009 case DW_FORM_line_strp
:
20010 if (!cu
->per_cu
->is_dwz
)
20012 attr
->set_string_noncanonical
20013 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20015 info_ptr
+= bytes_read
;
20019 case DW_FORM_GNU_strp_alt
:
20021 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20022 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20025 attr
->set_string_noncanonical
20026 (dwz
->read_string (objfile
, str_offset
));
20027 info_ptr
+= bytes_read
;
20030 case DW_FORM_exprloc
:
20031 case DW_FORM_block
:
20032 blk
= dwarf_alloc_block (cu
);
20033 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20034 info_ptr
+= bytes_read
;
20035 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20036 info_ptr
+= blk
->size
;
20037 attr
->set_block (blk
);
20039 case DW_FORM_block1
:
20040 blk
= dwarf_alloc_block (cu
);
20041 blk
->size
= read_1_byte (abfd
, info_ptr
);
20043 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20044 info_ptr
+= blk
->size
;
20045 attr
->set_block (blk
);
20047 case DW_FORM_data1
:
20049 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20052 case DW_FORM_flag_present
:
20053 attr
->set_unsigned (1);
20055 case DW_FORM_sdata
:
20056 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20057 info_ptr
+= bytes_read
;
20059 case DW_FORM_rnglistx
:
20061 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20063 info_ptr
+= bytes_read
;
20066 case DW_FORM_udata
:
20067 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20068 info_ptr
+= bytes_read
;
20071 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20072 + read_1_byte (abfd
, info_ptr
)));
20076 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20077 + read_2_bytes (abfd
, info_ptr
)));
20081 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20082 + read_4_bytes (abfd
, info_ptr
)));
20086 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20087 + read_8_bytes (abfd
, info_ptr
)));
20090 case DW_FORM_ref_sig8
:
20091 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20094 case DW_FORM_ref_udata
:
20095 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20096 + read_unsigned_leb128 (abfd
, info_ptr
,
20098 info_ptr
+= bytes_read
;
20100 case DW_FORM_indirect
:
20101 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20102 info_ptr
+= bytes_read
;
20103 if (form
== DW_FORM_implicit_const
)
20105 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20106 info_ptr
+= bytes_read
;
20108 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20111 case DW_FORM_implicit_const
:
20112 attr
->set_signed (implicit_const
);
20114 case DW_FORM_addrx
:
20115 case DW_FORM_GNU_addr_index
:
20116 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20118 info_ptr
+= bytes_read
;
20121 case DW_FORM_strx1
:
20122 case DW_FORM_strx2
:
20123 case DW_FORM_strx3
:
20124 case DW_FORM_strx4
:
20125 case DW_FORM_GNU_str_index
:
20127 ULONGEST str_index
;
20128 if (form
== DW_FORM_strx1
)
20130 str_index
= read_1_byte (abfd
, info_ptr
);
20133 else if (form
== DW_FORM_strx2
)
20135 str_index
= read_2_bytes (abfd
, info_ptr
);
20138 else if (form
== DW_FORM_strx3
)
20140 str_index
= read_3_bytes (abfd
, info_ptr
);
20143 else if (form
== DW_FORM_strx4
)
20145 str_index
= read_4_bytes (abfd
, info_ptr
);
20150 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20151 info_ptr
+= bytes_read
;
20153 attr
->set_unsigned_reprocess (str_index
);
20157 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20158 dwarf_form_name (form
),
20159 bfd_get_filename (abfd
));
20163 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20164 attr
->form
= DW_FORM_GNU_ref_alt
;
20166 /* We have seen instances where the compiler tried to emit a byte
20167 size attribute of -1 which ended up being encoded as an unsigned
20168 0xffffffff. Although 0xffffffff is technically a valid size value,
20169 an object of this size seems pretty unlikely so we can relatively
20170 safely treat these cases as if the size attribute was invalid and
20171 treat them as zero by default. */
20172 if (attr
->name
== DW_AT_byte_size
20173 && form
== DW_FORM_data4
20174 && attr
->as_unsigned () >= 0xffffffff)
20177 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20178 hex_string (attr
->as_unsigned ()));
20179 attr
->set_unsigned (0);
20185 /* Read an attribute described by an abbreviated attribute. */
20187 static const gdb_byte
*
20188 read_attribute (const struct die_reader_specs
*reader
,
20189 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20190 const gdb_byte
*info_ptr
)
20192 attr
->name
= abbrev
->name
;
20193 attr
->string_is_canonical
= 0;
20194 attr
->requires_reprocessing
= 0;
20195 return read_attribute_value (reader
, attr
, abbrev
->form
,
20196 abbrev
->implicit_const
, info_ptr
);
20199 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20201 static const char *
20202 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20203 LONGEST str_offset
)
20205 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20206 str_offset
, "DW_FORM_strp");
20209 /* Return pointer to string at .debug_str offset as read from BUF.
20210 BUF is assumed to be in a compilation unit described by CU_HEADER.
20211 Return *BYTES_READ_PTR count of bytes read from BUF. */
20213 static const char *
20214 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20215 const gdb_byte
*buf
,
20216 const struct comp_unit_head
*cu_header
,
20217 unsigned int *bytes_read_ptr
)
20219 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20221 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20227 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20228 const struct comp_unit_head
*cu_header
,
20229 unsigned int *bytes_read_ptr
)
20231 bfd
*abfd
= objfile
->obfd
;
20232 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20234 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20237 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20238 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20239 ADDR_SIZE is the size of addresses from the CU header. */
20242 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20243 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20245 struct objfile
*objfile
= per_objfile
->objfile
;
20246 bfd
*abfd
= objfile
->obfd
;
20247 const gdb_byte
*info_ptr
;
20248 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20250 per_objfile
->per_bfd
->addr
.read (objfile
);
20251 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20252 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20253 objfile_name (objfile
));
20254 if (addr_base_or_zero
+ addr_index
* addr_size
20255 >= per_objfile
->per_bfd
->addr
.size
)
20256 error (_("DW_FORM_addr_index pointing outside of "
20257 ".debug_addr section [in module %s]"),
20258 objfile_name (objfile
));
20259 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20260 + addr_index
* addr_size
);
20261 if (addr_size
== 4)
20262 return bfd_get_32 (abfd
, info_ptr
);
20264 return bfd_get_64 (abfd
, info_ptr
);
20267 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20270 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20272 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20273 cu
->addr_base
, cu
->header
.addr_size
);
20276 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20279 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20280 unsigned int *bytes_read
)
20282 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20283 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20285 return read_addr_index (cu
, addr_index
);
20291 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20292 dwarf2_per_objfile
*per_objfile
,
20293 unsigned int addr_index
)
20295 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20296 gdb::optional
<ULONGEST
> addr_base
;
20299 /* We need addr_base and addr_size.
20300 If we don't have PER_CU->cu, we have to get it.
20301 Nasty, but the alternative is storing the needed info in PER_CU,
20302 which at this point doesn't seem justified: it's not clear how frequently
20303 it would get used and it would increase the size of every PER_CU.
20304 Entry points like dwarf2_per_cu_addr_size do a similar thing
20305 so we're not in uncharted territory here.
20306 Alas we need to be a bit more complicated as addr_base is contained
20309 We don't need to read the entire CU(/TU).
20310 We just need the header and top level die.
20312 IWBN to use the aging mechanism to let us lazily later discard the CU.
20313 For now we skip this optimization. */
20317 addr_base
= cu
->addr_base
;
20318 addr_size
= cu
->header
.addr_size
;
20322 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20323 addr_base
= reader
.cu
->addr_base
;
20324 addr_size
= reader
.cu
->header
.addr_size
;
20327 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20330 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20331 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20334 static const char *
20335 read_str_index (struct dwarf2_cu
*cu
,
20336 struct dwarf2_section_info
*str_section
,
20337 struct dwarf2_section_info
*str_offsets_section
,
20338 ULONGEST str_offsets_base
, ULONGEST str_index
)
20340 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20341 struct objfile
*objfile
= per_objfile
->objfile
;
20342 const char *objf_name
= objfile_name (objfile
);
20343 bfd
*abfd
= objfile
->obfd
;
20344 const gdb_byte
*info_ptr
;
20345 ULONGEST str_offset
;
20346 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20348 str_section
->read (objfile
);
20349 str_offsets_section
->read (objfile
);
20350 if (str_section
->buffer
== NULL
)
20351 error (_("%s used without %s section"
20352 " in CU at offset %s [in module %s]"),
20353 form_name
, str_section
->get_name (),
20354 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20355 if (str_offsets_section
->buffer
== NULL
)
20356 error (_("%s used without %s section"
20357 " in CU at offset %s [in module %s]"),
20358 form_name
, str_section
->get_name (),
20359 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20360 info_ptr
= (str_offsets_section
->buffer
20362 + str_index
* cu
->header
.offset_size
);
20363 if (cu
->header
.offset_size
== 4)
20364 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20366 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20367 if (str_offset
>= str_section
->size
)
20368 error (_("Offset from %s pointing outside of"
20369 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20370 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20371 return (const char *) (str_section
->buffer
+ str_offset
);
20374 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20376 static const char *
20377 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20379 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20380 ? reader
->cu
->header
.addr_size
: 0;
20381 return read_str_index (reader
->cu
,
20382 &reader
->dwo_file
->sections
.str
,
20383 &reader
->dwo_file
->sections
.str_offsets
,
20384 str_offsets_base
, str_index
);
20387 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20389 static const char *
20390 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20392 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20393 const char *objf_name
= objfile_name (objfile
);
20394 static const char form_name
[] = "DW_FORM_GNU_str_index";
20395 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20397 if (!cu
->str_offsets_base
.has_value ())
20398 error (_("%s used in Fission stub without %s"
20399 " in CU at offset 0x%lx [in module %s]"),
20400 form_name
, str_offsets_attr_name
,
20401 (long) cu
->header
.offset_size
, objf_name
);
20403 return read_str_index (cu
,
20404 &cu
->per_objfile
->per_bfd
->str
,
20405 &cu
->per_objfile
->per_bfd
->str_offsets
,
20406 *cu
->str_offsets_base
, str_index
);
20409 /* Return the length of an LEB128 number in BUF. */
20412 leb128_size (const gdb_byte
*buf
)
20414 const gdb_byte
*begin
= buf
;
20420 if ((byte
& 128) == 0)
20421 return buf
- begin
;
20425 static enum language
20426 dwarf_lang_to_enum_language (unsigned int lang
)
20428 enum language language
;
20437 language
= language_c
;
20440 case DW_LANG_C_plus_plus
:
20441 case DW_LANG_C_plus_plus_11
:
20442 case DW_LANG_C_plus_plus_14
:
20443 language
= language_cplus
;
20446 language
= language_d
;
20448 case DW_LANG_Fortran77
:
20449 case DW_LANG_Fortran90
:
20450 case DW_LANG_Fortran95
:
20451 case DW_LANG_Fortran03
:
20452 case DW_LANG_Fortran08
:
20453 language
= language_fortran
;
20456 language
= language_go
;
20458 case DW_LANG_Mips_Assembler
:
20459 language
= language_asm
;
20461 case DW_LANG_Ada83
:
20462 case DW_LANG_Ada95
:
20463 language
= language_ada
;
20465 case DW_LANG_Modula2
:
20466 language
= language_m2
;
20468 case DW_LANG_Pascal83
:
20469 language
= language_pascal
;
20472 language
= language_objc
;
20475 case DW_LANG_Rust_old
:
20476 language
= language_rust
;
20478 case DW_LANG_OpenCL
:
20479 language
= language_opencl
;
20481 case DW_LANG_Cobol74
:
20482 case DW_LANG_Cobol85
:
20484 language
= language_minimal
;
20491 /* Return the named attribute or NULL if not there. */
20493 static struct attribute
*
20494 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20499 struct attribute
*spec
= NULL
;
20501 for (i
= 0; i
< die
->num_attrs
; ++i
)
20503 if (die
->attrs
[i
].name
== name
)
20504 return &die
->attrs
[i
];
20505 if (die
->attrs
[i
].name
== DW_AT_specification
20506 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20507 spec
= &die
->attrs
[i
];
20513 die
= follow_die_ref (die
, spec
, &cu
);
20519 /* Return the string associated with a string-typed attribute, or NULL if it
20520 is either not found or is of an incorrect type. */
20522 static const char *
20523 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20525 struct attribute
*attr
;
20526 const char *str
= NULL
;
20528 attr
= dwarf2_attr (die
, name
, cu
);
20532 str
= attr
->as_string ();
20533 if (str
== nullptr)
20534 complaint (_("string type expected for attribute %s for "
20535 "DIE at %s in module %s"),
20536 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20537 objfile_name (cu
->per_objfile
->objfile
));
20543 /* Return the dwo name or NULL if not present. If present, it is in either
20544 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20545 static const char *
20546 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20548 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20549 if (dwo_name
== nullptr)
20550 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20554 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20555 and holds a non-zero value. This function should only be used for
20556 DW_FORM_flag or DW_FORM_flag_present attributes. */
20559 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20561 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20563 return attr
!= nullptr && attr
->as_boolean ();
20567 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20569 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20570 which value is non-zero. However, we have to be careful with
20571 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20572 (via dwarf2_flag_true_p) follows this attribute. So we may
20573 end up accidently finding a declaration attribute that belongs
20574 to a different DIE referenced by the specification attribute,
20575 even though the given DIE does not have a declaration attribute. */
20576 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20577 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20580 /* Return the die giving the specification for DIE, if there is
20581 one. *SPEC_CU is the CU containing DIE on input, and the CU
20582 containing the return value on output. If there is no
20583 specification, but there is an abstract origin, that is
20586 static struct die_info
*
20587 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20589 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20592 if (spec_attr
== NULL
)
20593 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20595 if (spec_attr
== NULL
)
20598 return follow_die_ref (die
, spec_attr
, spec_cu
);
20601 /* A convenience function to find the proper .debug_line section for a CU. */
20603 static struct dwarf2_section_info
*
20604 get_debug_line_section (struct dwarf2_cu
*cu
)
20606 struct dwarf2_section_info
*section
;
20607 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20609 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20611 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20612 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20613 else if (cu
->per_cu
->is_dwz
)
20615 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20617 section
= &dwz
->line
;
20620 section
= &per_objfile
->per_bfd
->line
;
20625 /* Read the statement program header starting at OFFSET in
20626 .debug_line, or .debug_line.dwo. Return a pointer
20627 to a struct line_header, allocated using xmalloc.
20628 Returns NULL if there is a problem reading the header, e.g., if it
20629 has a version we don't understand.
20631 NOTE: the strings in the include directory and file name tables of
20632 the returned object point into the dwarf line section buffer,
20633 and must not be freed. */
20635 static line_header_up
20636 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20638 struct dwarf2_section_info
*section
;
20639 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20641 section
= get_debug_line_section (cu
);
20642 section
->read (per_objfile
->objfile
);
20643 if (section
->buffer
== NULL
)
20645 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20646 complaint (_("missing .debug_line.dwo section"));
20648 complaint (_("missing .debug_line section"));
20652 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20653 per_objfile
, section
, &cu
->header
);
20656 /* Subroutine of dwarf_decode_lines to simplify it.
20657 Return the file name of the psymtab for the given file_entry.
20658 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20659 If space for the result is malloc'd, *NAME_HOLDER will be set.
20660 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20662 static const char *
20663 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20664 const dwarf2_psymtab
*pst
,
20665 const char *comp_dir
,
20666 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20668 const char *include_name
= fe
.name
;
20669 const char *include_name_to_compare
= include_name
;
20670 const char *pst_filename
;
20673 const char *dir_name
= fe
.include_dir (lh
);
20675 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20676 if (!IS_ABSOLUTE_PATH (include_name
)
20677 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20679 /* Avoid creating a duplicate psymtab for PST.
20680 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20681 Before we do the comparison, however, we need to account
20682 for DIR_NAME and COMP_DIR.
20683 First prepend dir_name (if non-NULL). If we still don't
20684 have an absolute path prepend comp_dir (if non-NULL).
20685 However, the directory we record in the include-file's
20686 psymtab does not contain COMP_DIR (to match the
20687 corresponding symtab(s)).
20692 bash$ gcc -g ./hello.c
20693 include_name = "hello.c"
20695 DW_AT_comp_dir = comp_dir = "/tmp"
20696 DW_AT_name = "./hello.c"
20700 if (dir_name
!= NULL
)
20702 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20703 include_name
, (char *) NULL
));
20704 include_name
= name_holder
->get ();
20705 include_name_to_compare
= include_name
;
20707 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20709 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20710 include_name
, (char *) NULL
));
20711 include_name_to_compare
= hold_compare
.get ();
20715 pst_filename
= pst
->filename
;
20716 gdb::unique_xmalloc_ptr
<char> copied_name
;
20717 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20719 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20720 pst_filename
, (char *) NULL
));
20721 pst_filename
= copied_name
.get ();
20724 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20728 return include_name
;
20731 /* State machine to track the state of the line number program. */
20733 class lnp_state_machine
20736 /* Initialize a machine state for the start of a line number
20738 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20739 bool record_lines_p
);
20741 file_entry
*current_file ()
20743 /* lh->file_names is 0-based, but the file name numbers in the
20744 statement program are 1-based. */
20745 return m_line_header
->file_name_at (m_file
);
20748 /* Record the line in the state machine. END_SEQUENCE is true if
20749 we're processing the end of a sequence. */
20750 void record_line (bool end_sequence
);
20752 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20753 nop-out rest of the lines in this sequence. */
20754 void check_line_address (struct dwarf2_cu
*cu
,
20755 const gdb_byte
*line_ptr
,
20756 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20758 void handle_set_discriminator (unsigned int discriminator
)
20760 m_discriminator
= discriminator
;
20761 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20764 /* Handle DW_LNE_set_address. */
20765 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20768 address
+= baseaddr
;
20769 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20772 /* Handle DW_LNS_advance_pc. */
20773 void handle_advance_pc (CORE_ADDR adjust
);
20775 /* Handle a special opcode. */
20776 void handle_special_opcode (unsigned char op_code
);
20778 /* Handle DW_LNS_advance_line. */
20779 void handle_advance_line (int line_delta
)
20781 advance_line (line_delta
);
20784 /* Handle DW_LNS_set_file. */
20785 void handle_set_file (file_name_index file
);
20787 /* Handle DW_LNS_negate_stmt. */
20788 void handle_negate_stmt ()
20790 m_is_stmt
= !m_is_stmt
;
20793 /* Handle DW_LNS_const_add_pc. */
20794 void handle_const_add_pc ();
20796 /* Handle DW_LNS_fixed_advance_pc. */
20797 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20799 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20803 /* Handle DW_LNS_copy. */
20804 void handle_copy ()
20806 record_line (false);
20807 m_discriminator
= 0;
20810 /* Handle DW_LNE_end_sequence. */
20811 void handle_end_sequence ()
20813 m_currently_recording_lines
= true;
20817 /* Advance the line by LINE_DELTA. */
20818 void advance_line (int line_delta
)
20820 m_line
+= line_delta
;
20822 if (line_delta
!= 0)
20823 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20826 struct dwarf2_cu
*m_cu
;
20828 gdbarch
*m_gdbarch
;
20830 /* True if we're recording lines.
20831 Otherwise we're building partial symtabs and are just interested in
20832 finding include files mentioned by the line number program. */
20833 bool m_record_lines_p
;
20835 /* The line number header. */
20836 line_header
*m_line_header
;
20838 /* These are part of the standard DWARF line number state machine,
20839 and initialized according to the DWARF spec. */
20841 unsigned char m_op_index
= 0;
20842 /* The line table index of the current file. */
20843 file_name_index m_file
= 1;
20844 unsigned int m_line
= 1;
20846 /* These are initialized in the constructor. */
20848 CORE_ADDR m_address
;
20850 unsigned int m_discriminator
;
20852 /* Additional bits of state we need to track. */
20854 /* The last file that we called dwarf2_start_subfile for.
20855 This is only used for TLLs. */
20856 unsigned int m_last_file
= 0;
20857 /* The last file a line number was recorded for. */
20858 struct subfile
*m_last_subfile
= NULL
;
20860 /* The address of the last line entry. */
20861 CORE_ADDR m_last_address
;
20863 /* Set to true when a previous line at the same address (using
20864 m_last_address) had m_is_stmt true. This is reset to false when a
20865 line entry at a new address (m_address different to m_last_address) is
20867 bool m_stmt_at_address
= false;
20869 /* When true, record the lines we decode. */
20870 bool m_currently_recording_lines
= false;
20872 /* The last line number that was recorded, used to coalesce
20873 consecutive entries for the same line. This can happen, for
20874 example, when discriminators are present. PR 17276. */
20875 unsigned int m_last_line
= 0;
20876 bool m_line_has_non_zero_discriminator
= false;
20880 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20882 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20883 / m_line_header
->maximum_ops_per_instruction
)
20884 * m_line_header
->minimum_instruction_length
);
20885 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20886 m_op_index
= ((m_op_index
+ adjust
)
20887 % m_line_header
->maximum_ops_per_instruction
);
20891 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20893 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20894 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20895 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20896 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20897 / m_line_header
->maximum_ops_per_instruction
)
20898 * m_line_header
->minimum_instruction_length
);
20899 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20900 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20901 % m_line_header
->maximum_ops_per_instruction
);
20903 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20904 advance_line (line_delta
);
20905 record_line (false);
20906 m_discriminator
= 0;
20910 lnp_state_machine::handle_set_file (file_name_index file
)
20914 const file_entry
*fe
= current_file ();
20916 dwarf2_debug_line_missing_file_complaint ();
20917 else if (m_record_lines_p
)
20919 const char *dir
= fe
->include_dir (m_line_header
);
20921 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20922 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20923 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20928 lnp_state_machine::handle_const_add_pc ()
20931 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20934 = (((m_op_index
+ adjust
)
20935 / m_line_header
->maximum_ops_per_instruction
)
20936 * m_line_header
->minimum_instruction_length
);
20938 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20939 m_op_index
= ((m_op_index
+ adjust
)
20940 % m_line_header
->maximum_ops_per_instruction
);
20943 /* Return non-zero if we should add LINE to the line number table.
20944 LINE is the line to add, LAST_LINE is the last line that was added,
20945 LAST_SUBFILE is the subfile for LAST_LINE.
20946 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20947 had a non-zero discriminator.
20949 We have to be careful in the presence of discriminators.
20950 E.g., for this line:
20952 for (i = 0; i < 100000; i++);
20954 clang can emit four line number entries for that one line,
20955 each with a different discriminator.
20956 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20958 However, we want gdb to coalesce all four entries into one.
20959 Otherwise the user could stepi into the middle of the line and
20960 gdb would get confused about whether the pc really was in the
20961 middle of the line.
20963 Things are further complicated by the fact that two consecutive
20964 line number entries for the same line is a heuristic used by gcc
20965 to denote the end of the prologue. So we can't just discard duplicate
20966 entries, we have to be selective about it. The heuristic we use is
20967 that we only collapse consecutive entries for the same line if at least
20968 one of those entries has a non-zero discriminator. PR 17276.
20970 Note: Addresses in the line number state machine can never go backwards
20971 within one sequence, thus this coalescing is ok. */
20974 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20975 unsigned int line
, unsigned int last_line
,
20976 int line_has_non_zero_discriminator
,
20977 struct subfile
*last_subfile
)
20979 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20981 if (line
!= last_line
)
20983 /* Same line for the same file that we've seen already.
20984 As a last check, for pr 17276, only record the line if the line
20985 has never had a non-zero discriminator. */
20986 if (!line_has_non_zero_discriminator
)
20991 /* Use the CU's builder to record line number LINE beginning at
20992 address ADDRESS in the line table of subfile SUBFILE. */
20995 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20996 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20997 struct dwarf2_cu
*cu
)
20999 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21001 if (dwarf_line_debug
)
21003 fprintf_unfiltered (gdb_stdlog
,
21004 "Recording line %u, file %s, address %s\n",
21005 line
, lbasename (subfile
->name
),
21006 paddress (gdbarch
, address
));
21010 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21013 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21014 Mark the end of a set of line number records.
21015 The arguments are the same as for dwarf_record_line_1.
21016 If SUBFILE is NULL the request is ignored. */
21019 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21020 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21022 if (subfile
== NULL
)
21025 if (dwarf_line_debug
)
21027 fprintf_unfiltered (gdb_stdlog
,
21028 "Finishing current line, file %s, address %s\n",
21029 lbasename (subfile
->name
),
21030 paddress (gdbarch
, address
));
21033 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21037 lnp_state_machine::record_line (bool end_sequence
)
21039 if (dwarf_line_debug
)
21041 fprintf_unfiltered (gdb_stdlog
,
21042 "Processing actual line %u: file %u,"
21043 " address %s, is_stmt %u, discrim %u%s\n",
21045 paddress (m_gdbarch
, m_address
),
21046 m_is_stmt
, m_discriminator
,
21047 (end_sequence
? "\t(end sequence)" : ""));
21050 file_entry
*fe
= current_file ();
21053 dwarf2_debug_line_missing_file_complaint ();
21054 /* For now we ignore lines not starting on an instruction boundary.
21055 But not when processing end_sequence for compatibility with the
21056 previous version of the code. */
21057 else if (m_op_index
== 0 || end_sequence
)
21059 fe
->included_p
= 1;
21060 if (m_record_lines_p
)
21062 /* When we switch files we insert an end maker in the first file,
21063 switch to the second file and add a new line entry. The
21064 problem is that the end marker inserted in the first file will
21065 discard any previous line entries at the same address. If the
21066 line entries in the first file are marked as is-stmt, while
21067 the new line in the second file is non-stmt, then this means
21068 the end marker will discard is-stmt lines so we can have a
21069 non-stmt line. This means that there are less addresses at
21070 which the user can insert a breakpoint.
21072 To improve this we track the last address in m_last_address,
21073 and whether we have seen an is-stmt at this address. Then
21074 when switching files, if we have seen a stmt at the current
21075 address, and we are switching to create a non-stmt line, then
21076 discard the new line. */
21078 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21079 bool ignore_this_line
21080 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21081 && !m_is_stmt
&& m_stmt_at_address
)
21082 || (!end_sequence
&& m_line
== 0));
21084 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21086 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21087 m_currently_recording_lines
? m_cu
: nullptr);
21090 if (!end_sequence
&& !ignore_this_line
)
21092 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21094 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21095 m_line_has_non_zero_discriminator
,
21098 buildsym_compunit
*builder
= m_cu
->get_builder ();
21099 dwarf_record_line_1 (m_gdbarch
,
21100 builder
->get_current_subfile (),
21101 m_line
, m_address
, is_stmt
,
21102 m_currently_recording_lines
? m_cu
: nullptr);
21104 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21105 m_last_line
= m_line
;
21110 /* Track whether we have seen any m_is_stmt true at m_address in case we
21111 have multiple line table entries all at m_address. */
21112 if (m_last_address
!= m_address
)
21114 m_stmt_at_address
= false;
21115 m_last_address
= m_address
;
21117 m_stmt_at_address
|= m_is_stmt
;
21120 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21121 line_header
*lh
, bool record_lines_p
)
21125 m_record_lines_p
= record_lines_p
;
21126 m_line_header
= lh
;
21128 m_currently_recording_lines
= true;
21130 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21131 was a line entry for it so that the backend has a chance to adjust it
21132 and also record it in case it needs it. This is currently used by MIPS
21133 code, cf. `mips_adjust_dwarf2_line'. */
21134 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21135 m_is_stmt
= lh
->default_is_stmt
;
21136 m_discriminator
= 0;
21138 m_last_address
= m_address
;
21139 m_stmt_at_address
= false;
21143 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21144 const gdb_byte
*line_ptr
,
21145 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21147 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21148 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21149 located at 0x0. In this case, additionally check that if
21150 ADDRESS < UNRELOCATED_LOWPC. */
21152 if ((address
== 0 && address
< unrelocated_lowpc
)
21153 || address
== (CORE_ADDR
) -1)
21155 /* This line table is for a function which has been
21156 GCd by the linker. Ignore it. PR gdb/12528 */
21158 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21159 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21161 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21162 line_offset
, objfile_name (objfile
));
21163 m_currently_recording_lines
= false;
21164 /* Note: m_currently_recording_lines is left as false until we see
21165 DW_LNE_end_sequence. */
21169 /* Subroutine of dwarf_decode_lines to simplify it.
21170 Process the line number information in LH.
21171 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21172 program in order to set included_p for every referenced header. */
21175 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21176 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21178 const gdb_byte
*line_ptr
, *extended_end
;
21179 const gdb_byte
*line_end
;
21180 unsigned int bytes_read
, extended_len
;
21181 unsigned char op_code
, extended_op
;
21182 CORE_ADDR baseaddr
;
21183 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21184 bfd
*abfd
= objfile
->obfd
;
21185 struct gdbarch
*gdbarch
= objfile
->arch ();
21186 /* True if we're recording line info (as opposed to building partial
21187 symtabs and just interested in finding include files mentioned by
21188 the line number program). */
21189 bool record_lines_p
= !decode_for_pst_p
;
21191 baseaddr
= objfile
->text_section_offset ();
21193 line_ptr
= lh
->statement_program_start
;
21194 line_end
= lh
->statement_program_end
;
21196 /* Read the statement sequences until there's nothing left. */
21197 while (line_ptr
< line_end
)
21199 /* The DWARF line number program state machine. Reset the state
21200 machine at the start of each sequence. */
21201 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21202 bool end_sequence
= false;
21204 if (record_lines_p
)
21206 /* Start a subfile for the current file of the state
21208 const file_entry
*fe
= state_machine
.current_file ();
21211 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21214 /* Decode the table. */
21215 while (line_ptr
< line_end
&& !end_sequence
)
21217 op_code
= read_1_byte (abfd
, line_ptr
);
21220 if (op_code
>= lh
->opcode_base
)
21222 /* Special opcode. */
21223 state_machine
.handle_special_opcode (op_code
);
21225 else switch (op_code
)
21227 case DW_LNS_extended_op
:
21228 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21230 line_ptr
+= bytes_read
;
21231 extended_end
= line_ptr
+ extended_len
;
21232 extended_op
= read_1_byte (abfd
, line_ptr
);
21234 if (DW_LNE_lo_user
<= extended_op
21235 && extended_op
<= DW_LNE_hi_user
)
21237 /* Vendor extension, ignore. */
21238 line_ptr
= extended_end
;
21241 switch (extended_op
)
21243 case DW_LNE_end_sequence
:
21244 state_machine
.handle_end_sequence ();
21245 end_sequence
= true;
21247 case DW_LNE_set_address
:
21250 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21251 line_ptr
+= bytes_read
;
21253 state_machine
.check_line_address (cu
, line_ptr
,
21254 lowpc
- baseaddr
, address
);
21255 state_machine
.handle_set_address (baseaddr
, address
);
21258 case DW_LNE_define_file
:
21260 const char *cur_file
;
21261 unsigned int mod_time
, length
;
21264 cur_file
= read_direct_string (abfd
, line_ptr
,
21266 line_ptr
+= bytes_read
;
21267 dindex
= (dir_index
)
21268 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21269 line_ptr
+= bytes_read
;
21271 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21272 line_ptr
+= bytes_read
;
21274 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21275 line_ptr
+= bytes_read
;
21276 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21279 case DW_LNE_set_discriminator
:
21281 /* The discriminator is not interesting to the
21282 debugger; just ignore it. We still need to
21283 check its value though:
21284 if there are consecutive entries for the same
21285 (non-prologue) line we want to coalesce them.
21288 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21289 line_ptr
+= bytes_read
;
21291 state_machine
.handle_set_discriminator (discr
);
21295 complaint (_("mangled .debug_line section"));
21298 /* Make sure that we parsed the extended op correctly. If e.g.
21299 we expected a different address size than the producer used,
21300 we may have read the wrong number of bytes. */
21301 if (line_ptr
!= extended_end
)
21303 complaint (_("mangled .debug_line section"));
21308 state_machine
.handle_copy ();
21310 case DW_LNS_advance_pc
:
21313 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21314 line_ptr
+= bytes_read
;
21316 state_machine
.handle_advance_pc (adjust
);
21319 case DW_LNS_advance_line
:
21322 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21323 line_ptr
+= bytes_read
;
21325 state_machine
.handle_advance_line (line_delta
);
21328 case DW_LNS_set_file
:
21330 file_name_index file
21331 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21333 line_ptr
+= bytes_read
;
21335 state_machine
.handle_set_file (file
);
21338 case DW_LNS_set_column
:
21339 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21340 line_ptr
+= bytes_read
;
21342 case DW_LNS_negate_stmt
:
21343 state_machine
.handle_negate_stmt ();
21345 case DW_LNS_set_basic_block
:
21347 /* Add to the address register of the state machine the
21348 address increment value corresponding to special opcode
21349 255. I.e., this value is scaled by the minimum
21350 instruction length since special opcode 255 would have
21351 scaled the increment. */
21352 case DW_LNS_const_add_pc
:
21353 state_machine
.handle_const_add_pc ();
21355 case DW_LNS_fixed_advance_pc
:
21357 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21360 state_machine
.handle_fixed_advance_pc (addr_adj
);
21365 /* Unknown standard opcode, ignore it. */
21368 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21370 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21371 line_ptr
+= bytes_read
;
21378 dwarf2_debug_line_missing_end_sequence_complaint ();
21380 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21381 in which case we still finish recording the last line). */
21382 state_machine
.record_line (true);
21386 /* Decode the Line Number Program (LNP) for the given line_header
21387 structure and CU. The actual information extracted and the type
21388 of structures created from the LNP depends on the value of PST.
21390 1. If PST is NULL, then this procedure uses the data from the program
21391 to create all necessary symbol tables, and their linetables.
21393 2. If PST is not NULL, this procedure reads the program to determine
21394 the list of files included by the unit represented by PST, and
21395 builds all the associated partial symbol tables.
21397 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21398 It is used for relative paths in the line table.
21399 NOTE: When processing partial symtabs (pst != NULL),
21400 comp_dir == pst->dirname.
21402 NOTE: It is important that psymtabs have the same file name (via strcmp)
21403 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21404 symtab we don't use it in the name of the psymtabs we create.
21405 E.g. expand_line_sal requires this when finding psymtabs to expand.
21406 A good testcase for this is mb-inline.exp.
21408 LOWPC is the lowest address in CU (or 0 if not known).
21410 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21411 for its PC<->lines mapping information. Otherwise only the filename
21412 table is read in. */
21415 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21416 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21417 CORE_ADDR lowpc
, int decode_mapping
)
21419 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21420 const int decode_for_pst_p
= (pst
!= NULL
);
21422 if (decode_mapping
)
21423 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21425 if (decode_for_pst_p
)
21427 /* Now that we're done scanning the Line Header Program, we can
21428 create the psymtab of each included file. */
21429 for (auto &file_entry
: lh
->file_names ())
21430 if (file_entry
.included_p
== 1)
21432 gdb::unique_xmalloc_ptr
<char> name_holder
;
21433 const char *include_name
=
21434 psymtab_include_file_name (lh
, file_entry
, pst
,
21435 comp_dir
, &name_holder
);
21436 if (include_name
!= NULL
)
21437 dwarf2_create_include_psymtab
21438 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21439 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21445 /* Make sure a symtab is created for every file, even files
21446 which contain only variables (i.e. no code with associated
21448 buildsym_compunit
*builder
= cu
->get_builder ();
21449 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21451 for (auto &fe
: lh
->file_names ())
21453 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21454 if (builder
->get_current_subfile ()->symtab
== NULL
)
21456 builder
->get_current_subfile ()->symtab
21457 = allocate_symtab (cust
,
21458 builder
->get_current_subfile ()->name
);
21460 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21465 /* Start a subfile for DWARF. FILENAME is the name of the file and
21466 DIRNAME the name of the source directory which contains FILENAME
21467 or NULL if not known.
21468 This routine tries to keep line numbers from identical absolute and
21469 relative file names in a common subfile.
21471 Using the `list' example from the GDB testsuite, which resides in
21472 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21473 of /srcdir/list0.c yields the following debugging information for list0.c:
21475 DW_AT_name: /srcdir/list0.c
21476 DW_AT_comp_dir: /compdir
21477 files.files[0].name: list0.h
21478 files.files[0].dir: /srcdir
21479 files.files[1].name: list0.c
21480 files.files[1].dir: /srcdir
21482 The line number information for list0.c has to end up in a single
21483 subfile, so that `break /srcdir/list0.c:1' works as expected.
21484 start_subfile will ensure that this happens provided that we pass the
21485 concatenation of files.files[1].dir and files.files[1].name as the
21489 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21490 const char *dirname
)
21492 gdb::unique_xmalloc_ptr
<char> copy
;
21494 /* In order not to lose the line information directory,
21495 we concatenate it to the filename when it makes sense.
21496 Note that the Dwarf3 standard says (speaking of filenames in line
21497 information): ``The directory index is ignored for file names
21498 that represent full path names''. Thus ignoring dirname in the
21499 `else' branch below isn't an issue. */
21501 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21503 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21504 filename
= copy
.get ();
21507 cu
->get_builder ()->start_subfile (filename
);
21511 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21512 struct dwarf2_cu
*cu
)
21514 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21515 struct comp_unit_head
*cu_header
= &cu
->header
;
21517 /* NOTE drow/2003-01-30: There used to be a comment and some special
21518 code here to turn a symbol with DW_AT_external and a
21519 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21520 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21521 with some versions of binutils) where shared libraries could have
21522 relocations against symbols in their debug information - the
21523 minimal symbol would have the right address, but the debug info
21524 would not. It's no longer necessary, because we will explicitly
21525 apply relocations when we read in the debug information now. */
21527 /* A DW_AT_location attribute with no contents indicates that a
21528 variable has been optimized away. */
21529 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21531 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21535 /* Handle one degenerate form of location expression specially, to
21536 preserve GDB's previous behavior when section offsets are
21537 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21538 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21540 if (attr
->form_is_block ())
21542 struct dwarf_block
*block
= attr
->as_block ();
21544 if ((block
->data
[0] == DW_OP_addr
21545 && block
->size
== 1 + cu_header
->addr_size
)
21546 || ((block
->data
[0] == DW_OP_GNU_addr_index
21547 || block
->data
[0] == DW_OP_addrx
)
21549 == 1 + leb128_size (&block
->data
[1]))))
21551 unsigned int dummy
;
21553 if (block
->data
[0] == DW_OP_addr
)
21554 SET_SYMBOL_VALUE_ADDRESS
21555 (sym
, cu
->header
.read_address (objfile
->obfd
,
21559 SET_SYMBOL_VALUE_ADDRESS
21560 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21562 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21563 fixup_symbol_section (sym
, objfile
);
21564 SET_SYMBOL_VALUE_ADDRESS
21566 SYMBOL_VALUE_ADDRESS (sym
)
21567 + objfile
->section_offsets
[sym
->section_index ()]);
21572 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21573 expression evaluator, and use LOC_COMPUTED only when necessary
21574 (i.e. when the value of a register or memory location is
21575 referenced, or a thread-local block, etc.). Then again, it might
21576 not be worthwhile. I'm assuming that it isn't unless performance
21577 or memory numbers show me otherwise. */
21579 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21581 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21582 cu
->has_loclist
= true;
21585 /* Given a pointer to a DWARF information entry, figure out if we need
21586 to make a symbol table entry for it, and if so, create a new entry
21587 and return a pointer to it.
21588 If TYPE is NULL, determine symbol type from the die, otherwise
21589 used the passed type.
21590 If SPACE is not NULL, use it to hold the new symbol. If it is
21591 NULL, allocate a new symbol on the objfile's obstack. */
21593 static struct symbol
*
21594 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21595 struct symbol
*space
)
21597 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21598 struct objfile
*objfile
= per_objfile
->objfile
;
21599 struct gdbarch
*gdbarch
= objfile
->arch ();
21600 struct symbol
*sym
= NULL
;
21602 struct attribute
*attr
= NULL
;
21603 struct attribute
*attr2
= NULL
;
21604 CORE_ADDR baseaddr
;
21605 struct pending
**list_to_add
= NULL
;
21607 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21609 baseaddr
= objfile
->text_section_offset ();
21611 name
= dwarf2_name (die
, cu
);
21614 int suppress_add
= 0;
21619 sym
= new (&objfile
->objfile_obstack
) symbol
;
21620 OBJSTAT (objfile
, n_syms
++);
21622 /* Cache this symbol's name and the name's demangled form (if any). */
21623 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21624 /* Fortran does not have mangling standard and the mangling does differ
21625 between gfortran, iFort etc. */
21626 const char *physname
21627 = (cu
->per_cu
->lang
== language_fortran
21628 ? dwarf2_full_name (name
, die
, cu
)
21629 : dwarf2_physname (name
, die
, cu
));
21630 const char *linkagename
= dw2_linkage_name (die
, cu
);
21632 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21633 sym
->set_linkage_name (physname
);
21636 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21637 sym
->set_linkage_name (linkagename
);
21640 /* Default assumptions.
21641 Use the passed type or decode it from the die. */
21642 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21643 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21645 SYMBOL_TYPE (sym
) = type
;
21647 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21648 attr
= dwarf2_attr (die
,
21649 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21651 if (attr
!= nullptr)
21652 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21654 attr
= dwarf2_attr (die
,
21655 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21657 if (attr
!= nullptr && attr
->is_nonnegative ())
21659 file_name_index file_index
21660 = (file_name_index
) attr
->as_nonnegative ();
21661 struct file_entry
*fe
;
21663 if (cu
->line_header
!= NULL
)
21664 fe
= cu
->line_header
->file_name_at (file_index
);
21669 complaint (_("file index out of range"));
21671 symbol_set_symtab (sym
, fe
->symtab
);
21677 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21678 if (attr
!= nullptr)
21682 addr
= attr
->as_address ();
21683 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21684 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21685 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21688 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21689 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21690 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21691 add_symbol_to_list (sym
, cu
->list_in_scope
);
21693 case DW_TAG_subprogram
:
21694 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21696 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21697 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21698 if ((attr2
!= nullptr && attr2
->as_boolean ())
21699 || cu
->per_cu
->lang
== language_ada
21700 || cu
->per_cu
->lang
== language_fortran
)
21702 /* Subprograms marked external are stored as a global symbol.
21703 Ada and Fortran subprograms, whether marked external or
21704 not, are always stored as a global symbol, because we want
21705 to be able to access them globally. For instance, we want
21706 to be able to break on a nested subprogram without having
21707 to specify the context. */
21708 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21712 list_to_add
= cu
->list_in_scope
;
21715 case DW_TAG_inlined_subroutine
:
21716 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21718 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21719 SYMBOL_INLINED (sym
) = 1;
21720 list_to_add
= cu
->list_in_scope
;
21722 case DW_TAG_template_value_param
:
21724 /* Fall through. */
21725 case DW_TAG_constant
:
21726 case DW_TAG_variable
:
21727 case DW_TAG_member
:
21728 /* Compilation with minimal debug info may result in
21729 variables with missing type entries. Change the
21730 misleading `void' type to something sensible. */
21731 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21732 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21734 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21735 /* In the case of DW_TAG_member, we should only be called for
21736 static const members. */
21737 if (die
->tag
== DW_TAG_member
)
21739 /* dwarf2_add_field uses die_is_declaration,
21740 so we do the same. */
21741 gdb_assert (die_is_declaration (die
, cu
));
21744 if (attr
!= nullptr)
21746 dwarf2_const_value (attr
, sym
, cu
);
21747 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21750 if (attr2
!= nullptr && attr2
->as_boolean ())
21751 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21753 list_to_add
= cu
->list_in_scope
;
21757 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21758 if (attr
!= nullptr)
21760 var_decode_location (attr
, sym
, cu
);
21761 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21763 /* Fortran explicitly imports any global symbols to the local
21764 scope by DW_TAG_common_block. */
21765 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21766 && die
->parent
->tag
== DW_TAG_common_block
)
21769 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21770 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21771 && !per_objfile
->per_bfd
->has_section_at_zero
)
21773 /* When a static variable is eliminated by the linker,
21774 the corresponding debug information is not stripped
21775 out, but the variable address is set to null;
21776 do not add such variables into symbol table. */
21778 else if (attr2
!= nullptr && attr2
->as_boolean ())
21780 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21781 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21782 && per_objfile
->per_bfd
->can_copy
)
21784 /* A global static variable might be subject to
21785 copy relocation. We first check for a local
21786 minsym, though, because maybe the symbol was
21787 marked hidden, in which case this would not
21789 bound_minimal_symbol found
21790 = (lookup_minimal_symbol_linkage
21791 (sym
->linkage_name (), objfile
));
21792 if (found
.minsym
!= nullptr)
21793 sym
->maybe_copied
= 1;
21796 /* A variable with DW_AT_external is never static,
21797 but it may be block-scoped. */
21799 = ((cu
->list_in_scope
21800 == cu
->get_builder ()->get_file_symbols ())
21801 ? cu
->get_builder ()->get_global_symbols ()
21802 : cu
->list_in_scope
);
21805 list_to_add
= cu
->list_in_scope
;
21809 /* We do not know the address of this symbol.
21810 If it is an external symbol and we have type information
21811 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21812 The address of the variable will then be determined from
21813 the minimal symbol table whenever the variable is
21815 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21817 /* Fortran explicitly imports any global symbols to the local
21818 scope by DW_TAG_common_block. */
21819 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21820 && die
->parent
->tag
== DW_TAG_common_block
)
21822 /* SYMBOL_CLASS doesn't matter here because
21823 read_common_block is going to reset it. */
21825 list_to_add
= cu
->list_in_scope
;
21827 else if (attr2
!= nullptr && attr2
->as_boolean ()
21828 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21830 /* A variable with DW_AT_external is never static, but it
21831 may be block-scoped. */
21833 = ((cu
->list_in_scope
21834 == cu
->get_builder ()->get_file_symbols ())
21835 ? cu
->get_builder ()->get_global_symbols ()
21836 : cu
->list_in_scope
);
21838 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21840 else if (!die_is_declaration (die
, cu
))
21842 /* Use the default LOC_OPTIMIZED_OUT class. */
21843 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21845 list_to_add
= cu
->list_in_scope
;
21849 case DW_TAG_formal_parameter
:
21851 /* If we are inside a function, mark this as an argument. If
21852 not, we might be looking at an argument to an inlined function
21853 when we do not have enough information to show inlined frames;
21854 pretend it's a local variable in that case so that the user can
21856 struct context_stack
*curr
21857 = cu
->get_builder ()->get_current_context_stack ();
21858 if (curr
!= nullptr && curr
->name
!= nullptr)
21859 SYMBOL_IS_ARGUMENT (sym
) = 1;
21860 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21861 if (attr
!= nullptr)
21863 var_decode_location (attr
, sym
, cu
);
21865 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21866 if (attr
!= nullptr)
21868 dwarf2_const_value (attr
, sym
, cu
);
21871 list_to_add
= cu
->list_in_scope
;
21874 case DW_TAG_unspecified_parameters
:
21875 /* From varargs functions; gdb doesn't seem to have any
21876 interest in this information, so just ignore it for now.
21879 case DW_TAG_template_type_param
:
21881 /* Fall through. */
21882 case DW_TAG_class_type
:
21883 case DW_TAG_interface_type
:
21884 case DW_TAG_structure_type
:
21885 case DW_TAG_union_type
:
21886 case DW_TAG_set_type
:
21887 case DW_TAG_enumeration_type
:
21888 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21889 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21892 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21893 really ever be static objects: otherwise, if you try
21894 to, say, break of a class's method and you're in a file
21895 which doesn't mention that class, it won't work unless
21896 the check for all static symbols in lookup_symbol_aux
21897 saves you. See the OtherFileClass tests in
21898 gdb.c++/namespace.exp. */
21902 buildsym_compunit
*builder
= cu
->get_builder ();
21904 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21905 && cu
->per_cu
->lang
== language_cplus
21906 ? builder
->get_global_symbols ()
21907 : cu
->list_in_scope
);
21909 /* The semantics of C++ state that "struct foo {
21910 ... }" also defines a typedef for "foo". */
21911 if (cu
->per_cu
->lang
== language_cplus
21912 || cu
->per_cu
->lang
== language_ada
21913 || cu
->per_cu
->lang
== language_d
21914 || cu
->per_cu
->lang
== language_rust
)
21916 /* The symbol's name is already allocated along
21917 with this objfile, so we don't need to
21918 duplicate it for the type. */
21919 if (SYMBOL_TYPE (sym
)->name () == 0)
21920 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21925 case DW_TAG_typedef
:
21926 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21927 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21928 list_to_add
= cu
->list_in_scope
;
21930 case DW_TAG_array_type
:
21931 case DW_TAG_base_type
:
21932 case DW_TAG_subrange_type
:
21933 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21934 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21935 list_to_add
= cu
->list_in_scope
;
21937 case DW_TAG_enumerator
:
21938 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21939 if (attr
!= nullptr)
21941 dwarf2_const_value (attr
, sym
, cu
);
21944 /* NOTE: carlton/2003-11-10: See comment above in the
21945 DW_TAG_class_type, etc. block. */
21948 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21949 && cu
->per_cu
->lang
== language_cplus
21950 ? cu
->get_builder ()->get_global_symbols ()
21951 : cu
->list_in_scope
);
21954 case DW_TAG_imported_declaration
:
21955 case DW_TAG_namespace
:
21956 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21957 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21959 case DW_TAG_module
:
21960 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21961 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21962 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21964 case DW_TAG_common_block
:
21965 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21966 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21967 add_symbol_to_list (sym
, cu
->list_in_scope
);
21970 /* Not a tag we recognize. Hopefully we aren't processing
21971 trash data, but since we must specifically ignore things
21972 we don't recognize, there is nothing else we should do at
21974 complaint (_("unsupported tag: '%s'"),
21975 dwarf_tag_name (die
->tag
));
21981 sym
->hash_next
= objfile
->template_symbols
;
21982 objfile
->template_symbols
= sym
;
21983 list_to_add
= NULL
;
21986 if (list_to_add
!= NULL
)
21987 add_symbol_to_list (sym
, list_to_add
);
21989 /* For the benefit of old versions of GCC, check for anonymous
21990 namespaces based on the demangled name. */
21991 if (!cu
->processing_has_namespace_info
21992 && cu
->per_cu
->lang
== language_cplus
)
21993 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21998 /* Given an attr with a DW_FORM_dataN value in host byte order,
21999 zero-extend it as appropriate for the symbol's type. The DWARF
22000 standard (v4) is not entirely clear about the meaning of using
22001 DW_FORM_dataN for a constant with a signed type, where the type is
22002 wider than the data. The conclusion of a discussion on the DWARF
22003 list was that this is unspecified. We choose to always zero-extend
22004 because that is the interpretation long in use by GCC. */
22007 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22008 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22010 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22011 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22012 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22013 LONGEST l
= attr
->constant_value (0);
22015 if (bits
< sizeof (*value
) * 8)
22017 l
&= ((LONGEST
) 1 << bits
) - 1;
22020 else if (bits
== sizeof (*value
) * 8)
22024 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22025 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22032 /* Read a constant value from an attribute. Either set *VALUE, or if
22033 the value does not fit in *VALUE, set *BYTES - either already
22034 allocated on the objfile obstack, or newly allocated on OBSTACK,
22035 or, set *BATON, if we translated the constant to a location
22039 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22040 const char *name
, struct obstack
*obstack
,
22041 struct dwarf2_cu
*cu
,
22042 LONGEST
*value
, const gdb_byte
**bytes
,
22043 struct dwarf2_locexpr_baton
**baton
)
22045 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22046 struct objfile
*objfile
= per_objfile
->objfile
;
22047 struct comp_unit_head
*cu_header
= &cu
->header
;
22048 struct dwarf_block
*blk
;
22049 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22050 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22056 switch (attr
->form
)
22059 case DW_FORM_addrx
:
22060 case DW_FORM_GNU_addr_index
:
22064 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22065 dwarf2_const_value_length_mismatch_complaint (name
,
22066 cu_header
->addr_size
,
22067 TYPE_LENGTH (type
));
22068 /* Symbols of this form are reasonably rare, so we just
22069 piggyback on the existing location code rather than writing
22070 a new implementation of symbol_computed_ops. */
22071 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22072 (*baton
)->per_objfile
= per_objfile
;
22073 (*baton
)->per_cu
= cu
->per_cu
;
22074 gdb_assert ((*baton
)->per_cu
);
22076 (*baton
)->size
= 2 + cu_header
->addr_size
;
22077 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22078 (*baton
)->data
= data
;
22080 data
[0] = DW_OP_addr
;
22081 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22082 byte_order
, attr
->as_address ());
22083 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22086 case DW_FORM_string
:
22089 case DW_FORM_GNU_str_index
:
22090 case DW_FORM_GNU_strp_alt
:
22091 /* The string is already allocated on the objfile obstack, point
22093 *bytes
= (const gdb_byte
*) attr
->as_string ();
22095 case DW_FORM_block1
:
22096 case DW_FORM_block2
:
22097 case DW_FORM_block4
:
22098 case DW_FORM_block
:
22099 case DW_FORM_exprloc
:
22100 case DW_FORM_data16
:
22101 blk
= attr
->as_block ();
22102 if (TYPE_LENGTH (type
) != blk
->size
)
22103 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22104 TYPE_LENGTH (type
));
22105 *bytes
= blk
->data
;
22108 /* The DW_AT_const_value attributes are supposed to carry the
22109 symbol's value "represented as it would be on the target
22110 architecture." By the time we get here, it's already been
22111 converted to host endianness, so we just need to sign- or
22112 zero-extend it as appropriate. */
22113 case DW_FORM_data1
:
22114 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22116 case DW_FORM_data2
:
22117 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22119 case DW_FORM_data4
:
22120 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22122 case DW_FORM_data8
:
22123 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22126 case DW_FORM_sdata
:
22127 case DW_FORM_implicit_const
:
22128 *value
= attr
->as_signed ();
22131 case DW_FORM_udata
:
22132 *value
= attr
->as_unsigned ();
22136 complaint (_("unsupported const value attribute form: '%s'"),
22137 dwarf_form_name (attr
->form
));
22144 /* Copy constant value from an attribute to a symbol. */
22147 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22148 struct dwarf2_cu
*cu
)
22150 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22152 const gdb_byte
*bytes
;
22153 struct dwarf2_locexpr_baton
*baton
;
22155 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22156 sym
->print_name (),
22157 &objfile
->objfile_obstack
, cu
,
22158 &value
, &bytes
, &baton
);
22162 SYMBOL_LOCATION_BATON (sym
) = baton
;
22163 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22165 else if (bytes
!= NULL
)
22167 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22168 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22172 SYMBOL_VALUE (sym
) = value
;
22173 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22177 /* Return the type of the die in question using its DW_AT_type attribute. */
22179 static struct type
*
22180 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22182 struct attribute
*type_attr
;
22184 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22187 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22188 /* A missing DW_AT_type represents a void type. */
22189 return objfile_type (objfile
)->builtin_void
;
22192 return lookup_die_type (die
, type_attr
, cu
);
22195 /* True iff CU's producer generates GNAT Ada auxiliary information
22196 that allows to find parallel types through that information instead
22197 of having to do expensive parallel lookups by type name. */
22200 need_gnat_info (struct dwarf2_cu
*cu
)
22202 /* Assume that the Ada compiler was GNAT, which always produces
22203 the auxiliary information. */
22204 return (cu
->per_cu
->lang
== language_ada
);
22207 /* Return the auxiliary type of the die in question using its
22208 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22209 attribute is not present. */
22211 static struct type
*
22212 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22214 struct attribute
*type_attr
;
22216 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22220 return lookup_die_type (die
, type_attr
, cu
);
22223 /* If DIE has a descriptive_type attribute, then set the TYPE's
22224 descriptive type accordingly. */
22227 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22228 struct dwarf2_cu
*cu
)
22230 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22232 if (descriptive_type
)
22234 ALLOCATE_GNAT_AUX_TYPE (type
);
22235 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22239 /* Return the containing type of the die in question using its
22240 DW_AT_containing_type attribute. */
22242 static struct type
*
22243 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22245 struct attribute
*type_attr
;
22246 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22248 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22250 error (_("Dwarf Error: Problem turning containing type into gdb type "
22251 "[in module %s]"), objfile_name (objfile
));
22253 return lookup_die_type (die
, type_attr
, cu
);
22256 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22258 static struct type
*
22259 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22261 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22262 struct objfile
*objfile
= per_objfile
->objfile
;
22265 std::string message
22266 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22267 objfile_name (objfile
),
22268 sect_offset_str (cu
->header
.sect_off
),
22269 sect_offset_str (die
->sect_off
));
22270 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22272 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22275 /* Look up the type of DIE in CU using its type attribute ATTR.
22276 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22277 DW_AT_containing_type.
22278 If there is no type substitute an error marker. */
22280 static struct type
*
22281 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22282 struct dwarf2_cu
*cu
)
22284 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22285 struct objfile
*objfile
= per_objfile
->objfile
;
22286 struct type
*this_type
;
22288 gdb_assert (attr
->name
== DW_AT_type
22289 || attr
->name
== DW_AT_GNAT_descriptive_type
22290 || attr
->name
== DW_AT_containing_type
);
22292 /* First see if we have it cached. */
22294 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22296 struct dwarf2_per_cu_data
*per_cu
;
22297 sect_offset sect_off
= attr
->get_ref_die_offset ();
22299 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22300 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22302 else if (attr
->form_is_ref ())
22304 sect_offset sect_off
= attr
->get_ref_die_offset ();
22306 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22308 else if (attr
->form
== DW_FORM_ref_sig8
)
22310 ULONGEST signature
= attr
->as_signature ();
22312 return get_signatured_type (die
, signature
, cu
);
22316 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22317 " at %s [in module %s]"),
22318 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22319 objfile_name (objfile
));
22320 return build_error_marker_type (cu
, die
);
22323 /* If not cached we need to read it in. */
22325 if (this_type
== NULL
)
22327 struct die_info
*type_die
= NULL
;
22328 struct dwarf2_cu
*type_cu
= cu
;
22330 if (attr
->form_is_ref ())
22331 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22332 if (type_die
== NULL
)
22333 return build_error_marker_type (cu
, die
);
22334 /* If we find the type now, it's probably because the type came
22335 from an inter-CU reference and the type's CU got expanded before
22337 this_type
= read_type_die (type_die
, type_cu
);
22340 /* If we still don't have a type use an error marker. */
22342 if (this_type
== NULL
)
22343 return build_error_marker_type (cu
, die
);
22348 /* Return the type in DIE, CU.
22349 Returns NULL for invalid types.
22351 This first does a lookup in die_type_hash,
22352 and only reads the die in if necessary.
22354 NOTE: This can be called when reading in partial or full symbols. */
22356 static struct type
*
22357 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22359 struct type
*this_type
;
22361 this_type
= get_die_type (die
, cu
);
22365 return read_type_die_1 (die
, cu
);
22368 /* Read the type in DIE, CU.
22369 Returns NULL for invalid types. */
22371 static struct type
*
22372 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22374 struct type
*this_type
= NULL
;
22378 case DW_TAG_class_type
:
22379 case DW_TAG_interface_type
:
22380 case DW_TAG_structure_type
:
22381 case DW_TAG_union_type
:
22382 this_type
= read_structure_type (die
, cu
);
22384 case DW_TAG_enumeration_type
:
22385 this_type
= read_enumeration_type (die
, cu
);
22387 case DW_TAG_subprogram
:
22388 case DW_TAG_subroutine_type
:
22389 case DW_TAG_inlined_subroutine
:
22390 this_type
= read_subroutine_type (die
, cu
);
22392 case DW_TAG_array_type
:
22393 this_type
= read_array_type (die
, cu
);
22395 case DW_TAG_set_type
:
22396 this_type
= read_set_type (die
, cu
);
22398 case DW_TAG_pointer_type
:
22399 this_type
= read_tag_pointer_type (die
, cu
);
22401 case DW_TAG_ptr_to_member_type
:
22402 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22404 case DW_TAG_reference_type
:
22405 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22407 case DW_TAG_rvalue_reference_type
:
22408 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22410 case DW_TAG_const_type
:
22411 this_type
= read_tag_const_type (die
, cu
);
22413 case DW_TAG_volatile_type
:
22414 this_type
= read_tag_volatile_type (die
, cu
);
22416 case DW_TAG_restrict_type
:
22417 this_type
= read_tag_restrict_type (die
, cu
);
22419 case DW_TAG_string_type
:
22420 this_type
= read_tag_string_type (die
, cu
);
22422 case DW_TAG_typedef
:
22423 this_type
= read_typedef (die
, cu
);
22425 case DW_TAG_subrange_type
:
22426 this_type
= read_subrange_type (die
, cu
);
22428 case DW_TAG_base_type
:
22429 this_type
= read_base_type (die
, cu
);
22431 case DW_TAG_unspecified_type
:
22432 this_type
= read_unspecified_type (die
, cu
);
22434 case DW_TAG_namespace
:
22435 this_type
= read_namespace_type (die
, cu
);
22437 case DW_TAG_module
:
22438 this_type
= read_module_type (die
, cu
);
22440 case DW_TAG_atomic_type
:
22441 this_type
= read_tag_atomic_type (die
, cu
);
22444 complaint (_("unexpected tag in read_type_die: '%s'"),
22445 dwarf_tag_name (die
->tag
));
22452 /* See if we can figure out if the class lives in a namespace. We do
22453 this by looking for a member function; its demangled name will
22454 contain namespace info, if there is any.
22455 Return the computed name or NULL.
22456 Space for the result is allocated on the objfile's obstack.
22457 This is the full-die version of guess_partial_die_structure_name.
22458 In this case we know DIE has no useful parent. */
22460 static const char *
22461 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22463 struct die_info
*spec_die
;
22464 struct dwarf2_cu
*spec_cu
;
22465 struct die_info
*child
;
22466 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22469 spec_die
= die_specification (die
, &spec_cu
);
22470 if (spec_die
!= NULL
)
22476 for (child
= die
->child
;
22478 child
= child
->sibling
)
22480 if (child
->tag
== DW_TAG_subprogram
)
22482 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22484 if (linkage_name
!= NULL
)
22486 gdb::unique_xmalloc_ptr
<char> actual_name
22487 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22488 const char *name
= NULL
;
22490 if (actual_name
!= NULL
)
22492 const char *die_name
= dwarf2_name (die
, cu
);
22494 if (die_name
!= NULL
22495 && strcmp (die_name
, actual_name
.get ()) != 0)
22497 /* Strip off the class name from the full name.
22498 We want the prefix. */
22499 int die_name_len
= strlen (die_name
);
22500 int actual_name_len
= strlen (actual_name
.get ());
22501 const char *ptr
= actual_name
.get ();
22503 /* Test for '::' as a sanity check. */
22504 if (actual_name_len
> die_name_len
+ 2
22505 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22506 name
= obstack_strndup (
22507 &objfile
->per_bfd
->storage_obstack
,
22508 ptr
, actual_name_len
- die_name_len
- 2);
22519 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22520 prefix part in such case. See
22521 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22523 static const char *
22524 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22526 struct attribute
*attr
;
22529 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22530 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22533 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22536 attr
= dw2_linkage_name_attr (die
, cu
);
22537 const char *attr_name
= attr
->as_string ();
22538 if (attr
== NULL
|| attr_name
== NULL
)
22541 /* dwarf2_name had to be already called. */
22542 gdb_assert (attr
->canonical_string_p ());
22544 /* Strip the base name, keep any leading namespaces/classes. */
22545 base
= strrchr (attr_name
, ':');
22546 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22549 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22550 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22552 &base
[-1] - attr_name
);
22555 /* Return the name of the namespace/class that DIE is defined within,
22556 or "" if we can't tell. The caller should not xfree the result.
22558 For example, if we're within the method foo() in the following
22568 then determine_prefix on foo's die will return "N::C". */
22570 static const char *
22571 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22573 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22574 struct die_info
*parent
, *spec_die
;
22575 struct dwarf2_cu
*spec_cu
;
22576 struct type
*parent_type
;
22577 const char *retval
;
22579 if (cu
->per_cu
->lang
!= language_cplus
22580 && cu
->per_cu
->lang
!= language_fortran
22581 && cu
->per_cu
->lang
!= language_d
22582 && cu
->per_cu
->lang
!= language_rust
)
22585 retval
= anonymous_struct_prefix (die
, cu
);
22589 /* We have to be careful in the presence of DW_AT_specification.
22590 For example, with GCC 3.4, given the code
22594 // Definition of N::foo.
22598 then we'll have a tree of DIEs like this:
22600 1: DW_TAG_compile_unit
22601 2: DW_TAG_namespace // N
22602 3: DW_TAG_subprogram // declaration of N::foo
22603 4: DW_TAG_subprogram // definition of N::foo
22604 DW_AT_specification // refers to die #3
22606 Thus, when processing die #4, we have to pretend that we're in
22607 the context of its DW_AT_specification, namely the contex of die
22610 spec_die
= die_specification (die
, &spec_cu
);
22611 if (spec_die
== NULL
)
22612 parent
= die
->parent
;
22615 parent
= spec_die
->parent
;
22619 if (parent
== NULL
)
22621 else if (parent
->building_fullname
)
22624 const char *parent_name
;
22626 /* It has been seen on RealView 2.2 built binaries,
22627 DW_TAG_template_type_param types actually _defined_ as
22628 children of the parent class:
22631 template class <class Enum> Class{};
22632 Class<enum E> class_e;
22634 1: DW_TAG_class_type (Class)
22635 2: DW_TAG_enumeration_type (E)
22636 3: DW_TAG_enumerator (enum1:0)
22637 3: DW_TAG_enumerator (enum2:1)
22639 2: DW_TAG_template_type_param
22640 DW_AT_type DW_FORM_ref_udata (E)
22642 Besides being broken debug info, it can put GDB into an
22643 infinite loop. Consider:
22645 When we're building the full name for Class<E>, we'll start
22646 at Class, and go look over its template type parameters,
22647 finding E. We'll then try to build the full name of E, and
22648 reach here. We're now trying to build the full name of E,
22649 and look over the parent DIE for containing scope. In the
22650 broken case, if we followed the parent DIE of E, we'd again
22651 find Class, and once again go look at its template type
22652 arguments, etc., etc. Simply don't consider such parent die
22653 as source-level parent of this die (it can't be, the language
22654 doesn't allow it), and break the loop here. */
22655 name
= dwarf2_name (die
, cu
);
22656 parent_name
= dwarf2_name (parent
, cu
);
22657 complaint (_("template param type '%s' defined within parent '%s'"),
22658 name
? name
: "<unknown>",
22659 parent_name
? parent_name
: "<unknown>");
22663 switch (parent
->tag
)
22665 case DW_TAG_namespace
:
22666 parent_type
= read_type_die (parent
, cu
);
22667 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22668 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22669 Work around this problem here. */
22670 if (cu
->per_cu
->lang
== language_cplus
22671 && strcmp (parent_type
->name (), "::") == 0)
22673 /* We give a name to even anonymous namespaces. */
22674 return parent_type
->name ();
22675 case DW_TAG_class_type
:
22676 case DW_TAG_interface_type
:
22677 case DW_TAG_structure_type
:
22678 case DW_TAG_union_type
:
22679 case DW_TAG_module
:
22680 parent_type
= read_type_die (parent
, cu
);
22681 if (parent_type
->name () != NULL
)
22682 return parent_type
->name ();
22684 /* An anonymous structure is only allowed non-static data
22685 members; no typedefs, no member functions, et cetera.
22686 So it does not need a prefix. */
22688 case DW_TAG_compile_unit
:
22689 case DW_TAG_partial_unit
:
22690 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22691 if (cu
->per_cu
->lang
== language_cplus
22692 && !per_objfile
->per_bfd
->types
.empty ()
22693 && die
->child
!= NULL
22694 && (die
->tag
== DW_TAG_class_type
22695 || die
->tag
== DW_TAG_structure_type
22696 || die
->tag
== DW_TAG_union_type
))
22698 const char *name
= guess_full_die_structure_name (die
, cu
);
22703 case DW_TAG_subprogram
:
22704 /* Nested subroutines in Fortran get a prefix with the name
22705 of the parent's subroutine. */
22706 if (cu
->per_cu
->lang
== language_fortran
)
22708 if ((die
->tag
== DW_TAG_subprogram
)
22709 && (dwarf2_name (parent
, cu
) != NULL
))
22710 return dwarf2_name (parent
, cu
);
22712 return determine_prefix (parent
, cu
);
22713 case DW_TAG_enumeration_type
:
22714 parent_type
= read_type_die (parent
, cu
);
22715 if (parent_type
->is_declared_class ())
22717 if (parent_type
->name () != NULL
)
22718 return parent_type
->name ();
22721 /* Fall through. */
22723 return determine_prefix (parent
, cu
);
22727 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22728 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22729 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22730 an obconcat, otherwise allocate storage for the result. The CU argument is
22731 used to determine the language and hence, the appropriate separator. */
22733 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22736 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22737 int physname
, struct dwarf2_cu
*cu
)
22739 const char *lead
= "";
22742 if (suffix
== NULL
|| suffix
[0] == '\0'
22743 || prefix
== NULL
|| prefix
[0] == '\0')
22745 else if (cu
->per_cu
->lang
== language_d
)
22747 /* For D, the 'main' function could be defined in any module, but it
22748 should never be prefixed. */
22749 if (strcmp (suffix
, "D main") == 0)
22757 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22759 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22760 DW_AT_MIPS_linkage_name is preferred and used instead. */
22768 if (prefix
== NULL
)
22770 if (suffix
== NULL
)
22777 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22779 strcpy (retval
, lead
);
22780 strcat (retval
, prefix
);
22781 strcat (retval
, sep
);
22782 strcat (retval
, suffix
);
22787 /* We have an obstack. */
22788 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22792 /* Get name of a die, return NULL if not found. */
22794 static const char *
22795 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22796 struct objfile
*objfile
)
22798 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22800 gdb::unique_xmalloc_ptr
<char> canon_name
22801 = cp_canonicalize_string (name
);
22803 if (canon_name
!= nullptr)
22804 name
= objfile
->intern (canon_name
.get ());
22810 /* Get name of a die, return NULL if not found.
22811 Anonymous namespaces are converted to their magic string. */
22813 static const char *
22814 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22816 struct attribute
*attr
;
22817 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22819 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22820 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22821 if (attr_name
== nullptr
22822 && die
->tag
!= DW_TAG_namespace
22823 && die
->tag
!= DW_TAG_class_type
22824 && die
->tag
!= DW_TAG_interface_type
22825 && die
->tag
!= DW_TAG_structure_type
22826 && die
->tag
!= DW_TAG_union_type
)
22831 case DW_TAG_compile_unit
:
22832 case DW_TAG_partial_unit
:
22833 /* Compilation units have a DW_AT_name that is a filename, not
22834 a source language identifier. */
22835 case DW_TAG_enumeration_type
:
22836 case DW_TAG_enumerator
:
22837 /* These tags always have simple identifiers already; no need
22838 to canonicalize them. */
22841 case DW_TAG_namespace
:
22842 if (attr_name
!= nullptr)
22844 return CP_ANONYMOUS_NAMESPACE_STR
;
22846 case DW_TAG_class_type
:
22847 case DW_TAG_interface_type
:
22848 case DW_TAG_structure_type
:
22849 case DW_TAG_union_type
:
22850 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22851 structures or unions. These were of the form "._%d" in GCC 4.1,
22852 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22853 and GCC 4.4. We work around this problem by ignoring these. */
22854 if (attr_name
!= nullptr
22855 && (startswith (attr_name
, "._")
22856 || startswith (attr_name
, "<anonymous")))
22859 /* GCC might emit a nameless typedef that has a linkage name. See
22860 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22861 if (!attr
|| attr_name
== NULL
)
22863 attr
= dw2_linkage_name_attr (die
, cu
);
22864 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22865 if (attr
== NULL
|| attr_name
== NULL
)
22868 /* Avoid demangling attr_name the second time on a second
22869 call for the same DIE. */
22870 if (!attr
->canonical_string_p ())
22872 gdb::unique_xmalloc_ptr
<char> demangled
22873 (gdb_demangle (attr_name
, DMGL_TYPES
));
22874 if (demangled
== nullptr)
22877 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22878 attr_name
= attr
->as_string ();
22881 /* Strip any leading namespaces/classes, keep only the
22882 base name. DW_AT_name for named DIEs does not
22883 contain the prefixes. */
22884 const char *base
= strrchr (attr_name
, ':');
22885 if (base
&& base
> attr_name
&& base
[-1] == ':')
22896 if (!attr
->canonical_string_p ())
22897 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22899 return attr
->as_string ();
22902 /* Return the die that this die in an extension of, or NULL if there
22903 is none. *EXT_CU is the CU containing DIE on input, and the CU
22904 containing the return value on output. */
22906 static struct die_info
*
22907 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22909 struct attribute
*attr
;
22911 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22915 return follow_die_ref (die
, attr
, ext_cu
);
22919 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22923 print_spaces (indent
, f
);
22924 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22925 dwarf_tag_name (die
->tag
), die
->abbrev
,
22926 sect_offset_str (die
->sect_off
));
22928 if (die
->parent
!= NULL
)
22930 print_spaces (indent
, f
);
22931 fprintf_unfiltered (f
, " parent at offset: %s\n",
22932 sect_offset_str (die
->parent
->sect_off
));
22935 print_spaces (indent
, f
);
22936 fprintf_unfiltered (f
, " has children: %s\n",
22937 dwarf_bool_name (die
->child
!= NULL
));
22939 print_spaces (indent
, f
);
22940 fprintf_unfiltered (f
, " attributes:\n");
22942 for (i
= 0; i
< die
->num_attrs
; ++i
)
22944 print_spaces (indent
, f
);
22945 fprintf_unfiltered (f
, " %s (%s) ",
22946 dwarf_attr_name (die
->attrs
[i
].name
),
22947 dwarf_form_name (die
->attrs
[i
].form
));
22949 switch (die
->attrs
[i
].form
)
22952 case DW_FORM_addrx
:
22953 case DW_FORM_GNU_addr_index
:
22954 fprintf_unfiltered (f
, "address: ");
22955 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
22957 case DW_FORM_block2
:
22958 case DW_FORM_block4
:
22959 case DW_FORM_block
:
22960 case DW_FORM_block1
:
22961 fprintf_unfiltered (f
, "block: size %s",
22962 pulongest (die
->attrs
[i
].as_block ()->size
));
22964 case DW_FORM_exprloc
:
22965 fprintf_unfiltered (f
, "expression: size %s",
22966 pulongest (die
->attrs
[i
].as_block ()->size
));
22968 case DW_FORM_data16
:
22969 fprintf_unfiltered (f
, "constant of 16 bytes");
22971 case DW_FORM_ref_addr
:
22972 fprintf_unfiltered (f
, "ref address: ");
22973 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22975 case DW_FORM_GNU_ref_alt
:
22976 fprintf_unfiltered (f
, "alt ref address: ");
22977 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22983 case DW_FORM_ref_udata
:
22984 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22985 (long) (die
->attrs
[i
].as_unsigned ()));
22987 case DW_FORM_data1
:
22988 case DW_FORM_data2
:
22989 case DW_FORM_data4
:
22990 case DW_FORM_data8
:
22991 case DW_FORM_udata
:
22992 fprintf_unfiltered (f
, "constant: %s",
22993 pulongest (die
->attrs
[i
].as_unsigned ()));
22995 case DW_FORM_sec_offset
:
22996 fprintf_unfiltered (f
, "section offset: %s",
22997 pulongest (die
->attrs
[i
].as_unsigned ()));
22999 case DW_FORM_ref_sig8
:
23000 fprintf_unfiltered (f
, "signature: %s",
23001 hex_string (die
->attrs
[i
].as_signature ()));
23003 case DW_FORM_string
:
23005 case DW_FORM_line_strp
:
23007 case DW_FORM_GNU_str_index
:
23008 case DW_FORM_GNU_strp_alt
:
23009 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23010 die
->attrs
[i
].as_string ()
23011 ? die
->attrs
[i
].as_string () : "",
23012 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23015 if (die
->attrs
[i
].as_boolean ())
23016 fprintf_unfiltered (f
, "flag: TRUE");
23018 fprintf_unfiltered (f
, "flag: FALSE");
23020 case DW_FORM_flag_present
:
23021 fprintf_unfiltered (f
, "flag: TRUE");
23023 case DW_FORM_indirect
:
23024 /* The reader will have reduced the indirect form to
23025 the "base form" so this form should not occur. */
23026 fprintf_unfiltered (f
,
23027 "unexpected attribute form: DW_FORM_indirect");
23029 case DW_FORM_sdata
:
23030 case DW_FORM_implicit_const
:
23031 fprintf_unfiltered (f
, "constant: %s",
23032 plongest (die
->attrs
[i
].as_signed ()));
23035 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23036 die
->attrs
[i
].form
);
23039 fprintf_unfiltered (f
, "\n");
23044 dump_die_for_error (struct die_info
*die
)
23046 dump_die_shallow (gdb_stderr
, 0, die
);
23050 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23052 int indent
= level
* 4;
23054 gdb_assert (die
!= NULL
);
23056 if (level
>= max_level
)
23059 dump_die_shallow (f
, indent
, die
);
23061 if (die
->child
!= NULL
)
23063 print_spaces (indent
, f
);
23064 fprintf_unfiltered (f
, " Children:");
23065 if (level
+ 1 < max_level
)
23067 fprintf_unfiltered (f
, "\n");
23068 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23072 fprintf_unfiltered (f
,
23073 " [not printed, max nesting level reached]\n");
23077 if (die
->sibling
!= NULL
&& level
> 0)
23079 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23083 /* This is called from the pdie macro in gdbinit.in.
23084 It's not static so gcc will keep a copy callable from gdb. */
23087 dump_die (struct die_info
*die
, int max_level
)
23089 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23093 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23097 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23098 to_underlying (die
->sect_off
),
23104 /* Follow reference or signature attribute ATTR of SRC_DIE.
23105 On entry *REF_CU is the CU of SRC_DIE.
23106 On exit *REF_CU is the CU of the result. */
23108 static struct die_info
*
23109 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23110 struct dwarf2_cu
**ref_cu
)
23112 struct die_info
*die
;
23114 if (attr
->form_is_ref ())
23115 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23116 else if (attr
->form
== DW_FORM_ref_sig8
)
23117 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23120 dump_die_for_error (src_die
);
23121 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23122 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23128 /* Follow reference OFFSET.
23129 On entry *REF_CU is the CU of the source die referencing OFFSET.
23130 On exit *REF_CU is the CU of the result.
23131 Returns NULL if OFFSET is invalid. */
23133 static struct die_info
*
23134 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23135 struct dwarf2_cu
**ref_cu
)
23137 struct die_info temp_die
;
23138 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23139 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23141 gdb_assert (cu
->per_cu
!= NULL
);
23145 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23146 "source CU contains target offset: %d",
23147 sect_offset_str (cu
->per_cu
->sect_off
),
23148 sect_offset_str (sect_off
),
23149 cu
->header
.offset_in_cu_p (sect_off
));
23151 if (cu
->per_cu
->is_debug_types
)
23153 /* .debug_types CUs cannot reference anything outside their CU.
23154 If they need to, they have to reference a signatured type via
23155 DW_FORM_ref_sig8. */
23156 if (!cu
->header
.offset_in_cu_p (sect_off
))
23159 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23160 || !cu
->header
.offset_in_cu_p (sect_off
))
23162 struct dwarf2_per_cu_data
*per_cu
;
23164 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23167 dwarf_read_debug_printf_v ("target CU offset: %s, "
23168 "target CU DIEs loaded: %d",
23169 sect_offset_str (per_cu
->sect_off
),
23170 per_objfile
->get_cu (per_cu
) != nullptr);
23172 /* If necessary, add it to the queue and load its DIEs.
23174 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23175 it doesn't mean they are currently loaded. Since we require them
23176 to be loaded, we must check for ourselves. */
23177 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23178 || per_objfile
->get_cu (per_cu
) == nullptr)
23179 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23180 false, cu
->per_cu
->lang
);
23182 target_cu
= per_objfile
->get_cu (per_cu
);
23183 gdb_assert (target_cu
!= nullptr);
23185 else if (cu
->dies
== NULL
)
23187 /* We're loading full DIEs during partial symbol reading. */
23188 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23189 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23193 *ref_cu
= target_cu
;
23194 temp_die
.sect_off
= sect_off
;
23196 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23198 to_underlying (sect_off
));
23201 /* Follow reference attribute ATTR of SRC_DIE.
23202 On entry *REF_CU is the CU of SRC_DIE.
23203 On exit *REF_CU is the CU of the result. */
23205 static struct die_info
*
23206 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23207 struct dwarf2_cu
**ref_cu
)
23209 sect_offset sect_off
= attr
->get_ref_die_offset ();
23210 struct dwarf2_cu
*cu
= *ref_cu
;
23211 struct die_info
*die
;
23213 die
= follow_die_offset (sect_off
,
23214 (attr
->form
== DW_FORM_GNU_ref_alt
23215 || cu
->per_cu
->is_dwz
),
23218 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23219 "at %s [in module %s]"),
23220 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23221 objfile_name (cu
->per_objfile
->objfile
));
23228 struct dwarf2_locexpr_baton
23229 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23230 dwarf2_per_cu_data
*per_cu
,
23231 dwarf2_per_objfile
*per_objfile
,
23232 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23233 bool resolve_abstract_p
)
23235 struct die_info
*die
;
23236 struct attribute
*attr
;
23237 struct dwarf2_locexpr_baton retval
;
23238 struct objfile
*objfile
= per_objfile
->objfile
;
23240 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23242 cu
= load_cu (per_cu
, per_objfile
, false);
23246 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23247 Instead just throw an error, not much else we can do. */
23248 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23249 sect_offset_str (sect_off
), objfile_name (objfile
));
23252 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23254 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23255 sect_offset_str (sect_off
), objfile_name (objfile
));
23257 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23258 if (!attr
&& resolve_abstract_p
23259 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23260 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23262 CORE_ADDR pc
= get_frame_pc ();
23263 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23264 struct gdbarch
*gdbarch
= objfile
->arch ();
23266 for (const auto &cand_off
23267 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23269 struct dwarf2_cu
*cand_cu
= cu
;
23270 struct die_info
*cand
23271 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23274 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23277 CORE_ADDR pc_low
, pc_high
;
23278 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23279 if (pc_low
== ((CORE_ADDR
) -1))
23281 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23282 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23283 if (!(pc_low
<= pc
&& pc
< pc_high
))
23287 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23294 /* DWARF: "If there is no such attribute, then there is no effect.".
23295 DATA is ignored if SIZE is 0. */
23297 retval
.data
= NULL
;
23300 else if (attr
->form_is_section_offset ())
23302 struct dwarf2_loclist_baton loclist_baton
;
23303 CORE_ADDR pc
= get_frame_pc ();
23306 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23308 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23310 retval
.size
= size
;
23314 if (!attr
->form_is_block ())
23315 error (_("Dwarf Error: DIE at %s referenced in module %s "
23316 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23317 sect_offset_str (sect_off
), objfile_name (objfile
));
23319 struct dwarf_block
*block
= attr
->as_block ();
23320 retval
.data
= block
->data
;
23321 retval
.size
= block
->size
;
23323 retval
.per_objfile
= per_objfile
;
23324 retval
.per_cu
= cu
->per_cu
;
23326 per_objfile
->age_comp_units ();
23333 struct dwarf2_locexpr_baton
23334 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23335 dwarf2_per_cu_data
*per_cu
,
23336 dwarf2_per_objfile
*per_objfile
,
23337 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23339 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23341 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23345 /* Write a constant of a given type as target-ordered bytes into
23348 static const gdb_byte
*
23349 write_constant_as_bytes (struct obstack
*obstack
,
23350 enum bfd_endian byte_order
,
23357 *len
= TYPE_LENGTH (type
);
23358 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23359 store_unsigned_integer (result
, *len
, byte_order
, value
);
23367 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23368 dwarf2_per_cu_data
*per_cu
,
23369 dwarf2_per_objfile
*per_objfile
,
23373 struct die_info
*die
;
23374 struct attribute
*attr
;
23375 const gdb_byte
*result
= NULL
;
23378 enum bfd_endian byte_order
;
23379 struct objfile
*objfile
= per_objfile
->objfile
;
23381 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23383 cu
= load_cu (per_cu
, per_objfile
, false);
23387 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23388 Instead just throw an error, not much else we can do. */
23389 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23390 sect_offset_str (sect_off
), objfile_name (objfile
));
23393 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23395 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23396 sect_offset_str (sect_off
), objfile_name (objfile
));
23398 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23402 byte_order
= (bfd_big_endian (objfile
->obfd
)
23403 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23405 switch (attr
->form
)
23408 case DW_FORM_addrx
:
23409 case DW_FORM_GNU_addr_index
:
23413 *len
= cu
->header
.addr_size
;
23414 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23415 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23419 case DW_FORM_string
:
23422 case DW_FORM_GNU_str_index
:
23423 case DW_FORM_GNU_strp_alt
:
23424 /* The string is already allocated on the objfile obstack, point
23427 const char *attr_name
= attr
->as_string ();
23428 result
= (const gdb_byte
*) attr_name
;
23429 *len
= strlen (attr_name
);
23432 case DW_FORM_block1
:
23433 case DW_FORM_block2
:
23434 case DW_FORM_block4
:
23435 case DW_FORM_block
:
23436 case DW_FORM_exprloc
:
23437 case DW_FORM_data16
:
23439 struct dwarf_block
*block
= attr
->as_block ();
23440 result
= block
->data
;
23441 *len
= block
->size
;
23445 /* The DW_AT_const_value attributes are supposed to carry the
23446 symbol's value "represented as it would be on the target
23447 architecture." By the time we get here, it's already been
23448 converted to host endianness, so we just need to sign- or
23449 zero-extend it as appropriate. */
23450 case DW_FORM_data1
:
23451 type
= die_type (die
, cu
);
23452 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23453 if (result
== NULL
)
23454 result
= write_constant_as_bytes (obstack
, byte_order
,
23457 case DW_FORM_data2
:
23458 type
= die_type (die
, cu
);
23459 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23460 if (result
== NULL
)
23461 result
= write_constant_as_bytes (obstack
, byte_order
,
23464 case DW_FORM_data4
:
23465 type
= die_type (die
, cu
);
23466 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23467 if (result
== NULL
)
23468 result
= write_constant_as_bytes (obstack
, byte_order
,
23471 case DW_FORM_data8
:
23472 type
= die_type (die
, cu
);
23473 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23474 if (result
== NULL
)
23475 result
= write_constant_as_bytes (obstack
, byte_order
,
23479 case DW_FORM_sdata
:
23480 case DW_FORM_implicit_const
:
23481 type
= die_type (die
, cu
);
23482 result
= write_constant_as_bytes (obstack
, byte_order
,
23483 type
, attr
->as_signed (), len
);
23486 case DW_FORM_udata
:
23487 type
= die_type (die
, cu
);
23488 result
= write_constant_as_bytes (obstack
, byte_order
,
23489 type
, attr
->as_unsigned (), len
);
23493 complaint (_("unsupported const value attribute form: '%s'"),
23494 dwarf_form_name (attr
->form
));
23504 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23505 dwarf2_per_cu_data
*per_cu
,
23506 dwarf2_per_objfile
*per_objfile
,
23507 const char **var_name
)
23509 struct die_info
*die
;
23511 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23513 cu
= load_cu (per_cu
, per_objfile
, false);
23518 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23522 if (var_name
!= nullptr)
23523 *var_name
= var_decl_name (die
, cu
);
23524 return die_type (die
, cu
);
23530 dwarf2_get_die_type (cu_offset die_offset
,
23531 dwarf2_per_cu_data
*per_cu
,
23532 dwarf2_per_objfile
*per_objfile
)
23534 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23535 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23538 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23539 On entry *REF_CU is the CU of SRC_DIE.
23540 On exit *REF_CU is the CU of the result.
23541 Returns NULL if the referenced DIE isn't found. */
23543 static struct die_info
*
23544 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23545 struct dwarf2_cu
**ref_cu
)
23547 struct die_info temp_die
;
23548 struct dwarf2_cu
*sig_cu
;
23549 struct die_info
*die
;
23550 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23553 /* While it might be nice to assert sig_type->type == NULL here,
23554 we can get here for DW_AT_imported_declaration where we need
23555 the DIE not the type. */
23557 /* If necessary, add it to the queue and load its DIEs.
23559 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23560 it doesn't mean they are currently loaded. Since we require them
23561 to be loaded, we must check for ourselves. */
23562 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23564 || per_objfile
->get_cu (sig_type
) == nullptr)
23565 read_signatured_type (sig_type
, per_objfile
);
23567 sig_cu
= per_objfile
->get_cu (sig_type
);
23568 gdb_assert (sig_cu
!= NULL
);
23569 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23570 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23571 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23572 to_underlying (temp_die
.sect_off
));
23575 /* For .gdb_index version 7 keep track of included TUs.
23576 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23577 if (per_objfile
->per_bfd
->index_table
!= NULL
23578 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23580 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23590 /* Follow signatured type referenced by ATTR in SRC_DIE.
23591 On entry *REF_CU is the CU of SRC_DIE.
23592 On exit *REF_CU is the CU of the result.
23593 The result is the DIE of the type.
23594 If the referenced type cannot be found an error is thrown. */
23596 static struct die_info
*
23597 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23598 struct dwarf2_cu
**ref_cu
)
23600 ULONGEST signature
= attr
->as_signature ();
23601 struct signatured_type
*sig_type
;
23602 struct die_info
*die
;
23604 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23606 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23607 /* sig_type will be NULL if the signatured type is missing from
23609 if (sig_type
== NULL
)
23611 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23612 " from DIE at %s [in module %s]"),
23613 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23614 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23617 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23620 dump_die_for_error (src_die
);
23621 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23622 " from DIE at %s [in module %s]"),
23623 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23624 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23630 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23631 reading in and processing the type unit if necessary. */
23633 static struct type
*
23634 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23635 struct dwarf2_cu
*cu
)
23637 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23638 struct signatured_type
*sig_type
;
23639 struct dwarf2_cu
*type_cu
;
23640 struct die_info
*type_die
;
23643 sig_type
= lookup_signatured_type (cu
, signature
);
23644 /* sig_type will be NULL if the signatured type is missing from
23646 if (sig_type
== NULL
)
23648 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23649 " from DIE at %s [in module %s]"),
23650 hex_string (signature
), sect_offset_str (die
->sect_off
),
23651 objfile_name (per_objfile
->objfile
));
23652 return build_error_marker_type (cu
, die
);
23655 /* If we already know the type we're done. */
23656 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23657 if (type
!= nullptr)
23661 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23662 if (type_die
!= NULL
)
23664 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23665 is created. This is important, for example, because for c++ classes
23666 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23667 type
= read_type_die (type_die
, type_cu
);
23670 complaint (_("Dwarf Error: Cannot build signatured type %s"
23671 " referenced from DIE at %s [in module %s]"),
23672 hex_string (signature
), sect_offset_str (die
->sect_off
),
23673 objfile_name (per_objfile
->objfile
));
23674 type
= build_error_marker_type (cu
, die
);
23679 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23680 " from DIE at %s [in module %s]"),
23681 hex_string (signature
), sect_offset_str (die
->sect_off
),
23682 objfile_name (per_objfile
->objfile
));
23683 type
= build_error_marker_type (cu
, die
);
23686 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23691 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23692 reading in and processing the type unit if necessary. */
23694 static struct type
*
23695 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23696 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23698 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23699 if (attr
->form_is_ref ())
23701 struct dwarf2_cu
*type_cu
= cu
;
23702 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23704 return read_type_die (type_die
, type_cu
);
23706 else if (attr
->form
== DW_FORM_ref_sig8
)
23708 return get_signatured_type (die
, attr
->as_signature (), cu
);
23712 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23714 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23715 " at %s [in module %s]"),
23716 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23717 objfile_name (per_objfile
->objfile
));
23718 return build_error_marker_type (cu
, die
);
23722 /* Load the DIEs associated with type unit PER_CU into memory. */
23725 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23726 dwarf2_per_objfile
*per_objfile
)
23728 struct signatured_type
*sig_type
;
23730 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23731 gdb_assert (! per_cu
->type_unit_group_p ());
23733 /* We have the per_cu, but we need the signatured_type.
23734 Fortunately this is an easy translation. */
23735 gdb_assert (per_cu
->is_debug_types
);
23736 sig_type
= (struct signatured_type
*) per_cu
;
23738 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23740 read_signatured_type (sig_type
, per_objfile
);
23742 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23745 /* Read in a signatured type and build its CU and DIEs.
23746 If the type is a stub for the real type in a DWO file,
23747 read in the real type from the DWO file as well. */
23750 read_signatured_type (signatured_type
*sig_type
,
23751 dwarf2_per_objfile
*per_objfile
)
23753 gdb_assert (sig_type
->is_debug_types
);
23754 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23756 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23758 if (!reader
.dummy_p
)
23760 struct dwarf2_cu
*cu
= reader
.cu
;
23761 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23763 gdb_assert (cu
->die_hash
== NULL
);
23765 htab_create_alloc_ex (cu
->header
.length
/ 12,
23769 &cu
->comp_unit_obstack
,
23770 hashtab_obstack_allocate
,
23771 dummy_obstack_deallocate
);
23773 if (reader
.comp_unit_die
->has_children
)
23774 reader
.comp_unit_die
->child
23775 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23776 reader
.comp_unit_die
);
23777 cu
->dies
= reader
.comp_unit_die
;
23778 /* comp_unit_die is not stored in die_hash, no need. */
23780 /* We try not to read any attributes in this function, because
23781 not all CUs needed for references have been loaded yet, and
23782 symbol table processing isn't initialized. But we have to
23783 set the CU language, or we won't be able to build types
23784 correctly. Similarly, if we do not read the producer, we can
23785 not apply producer-specific interpretation. */
23786 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23791 sig_type
->tu_read
= 1;
23794 /* Decode simple location descriptions.
23795 Given a pointer to a dwarf block that defines a location, compute
23796 the location and return the value. If COMPUTED is non-null, it is
23797 set to true to indicate that decoding was successful, and false
23798 otherwise. If COMPUTED is null, then this function may emit a
23802 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23804 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23806 size_t size
= blk
->size
;
23807 const gdb_byte
*data
= blk
->data
;
23808 CORE_ADDR stack
[64];
23810 unsigned int bytes_read
, unsnd
;
23813 if (computed
!= nullptr)
23819 stack
[++stacki
] = 0;
23858 stack
[++stacki
] = op
- DW_OP_lit0
;
23893 stack
[++stacki
] = op
- DW_OP_reg0
;
23896 if (computed
== nullptr)
23897 dwarf2_complex_location_expr_complaint ();
23904 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23906 stack
[++stacki
] = unsnd
;
23909 if (computed
== nullptr)
23910 dwarf2_complex_location_expr_complaint ();
23917 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23922 case DW_OP_const1u
:
23923 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23927 case DW_OP_const1s
:
23928 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23932 case DW_OP_const2u
:
23933 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23937 case DW_OP_const2s
:
23938 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23942 case DW_OP_const4u
:
23943 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23947 case DW_OP_const4s
:
23948 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23952 case DW_OP_const8u
:
23953 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23958 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23964 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23969 stack
[stacki
+ 1] = stack
[stacki
];
23974 stack
[stacki
- 1] += stack
[stacki
];
23978 case DW_OP_plus_uconst
:
23979 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23985 stack
[stacki
- 1] -= stack
[stacki
];
23990 /* If we're not the last op, then we definitely can't encode
23991 this using GDB's address_class enum. This is valid for partial
23992 global symbols, although the variable's address will be bogus
23996 if (computed
== nullptr)
23997 dwarf2_complex_location_expr_complaint ();
24003 case DW_OP_GNU_push_tls_address
:
24004 case DW_OP_form_tls_address
:
24005 /* The top of the stack has the offset from the beginning
24006 of the thread control block at which the variable is located. */
24007 /* Nothing should follow this operator, so the top of stack would
24009 /* This is valid for partial global symbols, but the variable's
24010 address will be bogus in the psymtab. Make it always at least
24011 non-zero to not look as a variable garbage collected by linker
24012 which have DW_OP_addr 0. */
24015 if (computed
== nullptr)
24016 dwarf2_complex_location_expr_complaint ();
24023 case DW_OP_GNU_uninit
:
24024 if (computed
!= nullptr)
24029 case DW_OP_GNU_addr_index
:
24030 case DW_OP_GNU_const_index
:
24031 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24037 if (computed
== nullptr)
24039 const char *name
= get_DW_OP_name (op
);
24042 complaint (_("unsupported stack op: '%s'"),
24045 complaint (_("unsupported stack op: '%02x'"),
24049 return (stack
[stacki
]);
24052 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24053 outside of the allocated space. Also enforce minimum>0. */
24054 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24056 if (computed
== nullptr)
24057 complaint (_("location description stack overflow"));
24063 if (computed
== nullptr)
24064 complaint (_("location description stack underflow"));
24069 if (computed
!= nullptr)
24071 return (stack
[stacki
]);
24074 /* memory allocation interface */
24076 static struct dwarf_block
*
24077 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24079 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24082 static struct die_info
*
24083 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24085 struct die_info
*die
;
24086 size_t size
= sizeof (struct die_info
);
24089 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24091 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24092 memset (die
, 0, sizeof (struct die_info
));
24098 /* Macro support. */
24100 /* An overload of dwarf_decode_macros that finds the correct section
24101 and ensures it is read in before calling the other overload. */
24104 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24105 int section_is_gnu
)
24107 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24108 struct objfile
*objfile
= per_objfile
->objfile
;
24109 const struct line_header
*lh
= cu
->line_header
;
24110 unsigned int offset_size
= cu
->header
.offset_size
;
24111 struct dwarf2_section_info
*section
;
24112 const char *section_name
;
24114 if (cu
->dwo_unit
!= nullptr)
24116 if (section_is_gnu
)
24118 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24119 section_name
= ".debug_macro.dwo";
24123 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24124 section_name
= ".debug_macinfo.dwo";
24129 if (section_is_gnu
)
24131 section
= &per_objfile
->per_bfd
->macro
;
24132 section_name
= ".debug_macro";
24136 section
= &per_objfile
->per_bfd
->macinfo
;
24137 section_name
= ".debug_macinfo";
24141 section
->read (objfile
);
24142 if (section
->buffer
== nullptr)
24144 complaint (_("missing %s section"), section_name
);
24148 buildsym_compunit
*builder
= cu
->get_builder ();
24150 struct dwarf2_section_info
*str_offsets_section
;
24151 struct dwarf2_section_info
*str_section
;
24152 ULONGEST str_offsets_base
;
24154 if (cu
->dwo_unit
!= nullptr)
24156 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24157 ->sections
.str_offsets
;
24158 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24159 str_offsets_base
= cu
->header
.addr_size
;
24163 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24164 str_section
= &per_objfile
->per_bfd
->str
;
24165 str_offsets_base
= *cu
->str_offsets_base
;
24168 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24169 offset_size
, offset
, str_section
, str_offsets_section
,
24170 str_offsets_base
, section_is_gnu
);
24173 /* Return the .debug_loc section to use for CU.
24174 For DWO files use .debug_loc.dwo. */
24176 static struct dwarf2_section_info
*
24177 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24179 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24183 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24185 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24187 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24188 : &per_objfile
->per_bfd
->loc
);
24191 /* Return the .debug_rnglists section to use for CU. */
24192 static struct dwarf2_section_info
*
24193 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24195 if (cu
->header
.version
< 5)
24196 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24197 cu
->header
.version
);
24198 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24200 /* Make sure we read the .debug_rnglists section from the file that
24201 contains the DW_AT_ranges attribute we are reading. Normally that
24202 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24203 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24205 if (cu
->dwo_unit
!= nullptr
24206 && tag
!= DW_TAG_compile_unit
24207 && tag
!= DW_TAG_skeleton_unit
)
24209 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24211 if (sections
->rnglists
.size
> 0)
24212 return §ions
->rnglists
;
24214 error (_(".debug_rnglists section is missing from .dwo file."));
24216 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24219 /* A helper function that fills in a dwarf2_loclist_baton. */
24222 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24223 struct dwarf2_loclist_baton
*baton
,
24224 const struct attribute
*attr
)
24226 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24227 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24229 section
->read (per_objfile
->objfile
);
24231 baton
->per_objfile
= per_objfile
;
24232 baton
->per_cu
= cu
->per_cu
;
24233 gdb_assert (baton
->per_cu
);
24234 /* We don't know how long the location list is, but make sure we
24235 don't run off the edge of the section. */
24236 baton
->size
= section
->size
- attr
->as_unsigned ();
24237 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24238 if (cu
->base_address
.has_value ())
24239 baton
->base_address
= *cu
->base_address
;
24241 baton
->base_address
= 0;
24242 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24246 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24247 struct dwarf2_cu
*cu
, int is_block
)
24249 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24250 struct objfile
*objfile
= per_objfile
->objfile
;
24251 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24253 if (attr
->form_is_section_offset ()
24254 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24255 the section. If so, fall through to the complaint in the
24257 && attr
->as_unsigned () < section
->get_size (objfile
))
24259 struct dwarf2_loclist_baton
*baton
;
24261 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24263 fill_in_loclist_baton (cu
, baton
, attr
);
24265 if (!cu
->base_address
.has_value ())
24266 complaint (_("Location list used without "
24267 "specifying the CU base address."));
24269 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24270 ? dwarf2_loclist_block_index
24271 : dwarf2_loclist_index
);
24272 SYMBOL_LOCATION_BATON (sym
) = baton
;
24276 struct dwarf2_locexpr_baton
*baton
;
24278 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24279 baton
->per_objfile
= per_objfile
;
24280 baton
->per_cu
= cu
->per_cu
;
24281 gdb_assert (baton
->per_cu
);
24283 if (attr
->form_is_block ())
24285 /* Note that we're just copying the block's data pointer
24286 here, not the actual data. We're still pointing into the
24287 info_buffer for SYM's objfile; right now we never release
24288 that buffer, but when we do clean up properly this may
24290 struct dwarf_block
*block
= attr
->as_block ();
24291 baton
->size
= block
->size
;
24292 baton
->data
= block
->data
;
24296 dwarf2_invalid_attrib_class_complaint ("location description",
24297 sym
->natural_name ());
24301 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24302 ? dwarf2_locexpr_block_index
24303 : dwarf2_locexpr_index
);
24304 SYMBOL_LOCATION_BATON (sym
) = baton
;
24310 const comp_unit_head
*
24311 dwarf2_per_cu_data::get_header () const
24313 if (!m_header_read_in
)
24315 const gdb_byte
*info_ptr
24316 = this->section
->buffer
+ to_underlying (this->sect_off
);
24318 memset (&m_header
, 0, sizeof (m_header
));
24320 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24321 rcuh_kind::COMPILE
);
24323 m_header_read_in
= true;
24332 dwarf2_per_cu_data::addr_size () const
24334 return this->get_header ()->addr_size
;
24340 dwarf2_per_cu_data::offset_size () const
24342 return this->get_header ()->offset_size
;
24348 dwarf2_per_cu_data::ref_addr_size () const
24350 const comp_unit_head
*header
= this->get_header ();
24352 if (header
->version
== 2)
24353 return header
->addr_size
;
24355 return header
->offset_size
;
24358 /* A helper function for dwarf2_find_containing_comp_unit that returns
24359 the index of the result, and that searches a vector. It will
24360 return a result even if the offset in question does not actually
24361 occur in any CU. This is separate so that it can be unit
24365 dwarf2_find_containing_comp_unit
24366 (sect_offset sect_off
,
24367 unsigned int offset_in_dwz
,
24368 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24373 high
= all_comp_units
.size () - 1;
24376 struct dwarf2_per_cu_data
*mid_cu
;
24377 int mid
= low
+ (high
- low
) / 2;
24379 mid_cu
= all_comp_units
[mid
].get ();
24380 if (mid_cu
->is_dwz
> offset_in_dwz
24381 || (mid_cu
->is_dwz
== offset_in_dwz
24382 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24387 gdb_assert (low
== high
);
24391 /* Locate the .debug_info compilation unit from CU's objfile which contains
24392 the DIE at OFFSET. Raises an error on failure. */
24394 static struct dwarf2_per_cu_data
*
24395 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24396 unsigned int offset_in_dwz
,
24397 dwarf2_per_objfile
*per_objfile
)
24399 int low
= dwarf2_find_containing_comp_unit
24400 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24401 dwarf2_per_cu_data
*this_cu
24402 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24404 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24406 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24407 error (_("Dwarf Error: could not find partial DIE containing "
24408 "offset %s [in module %s]"),
24409 sect_offset_str (sect_off
),
24410 bfd_get_filename (per_objfile
->objfile
->obfd
));
24412 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24414 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24418 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24419 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24420 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24421 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24428 namespace selftests
{
24429 namespace find_containing_comp_unit
{
24434 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24435 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24436 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24437 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24438 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24439 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24440 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24441 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24444 two
->sect_off
= sect_offset (one
->length
);
24449 four
->sect_off
= sect_offset (three
->length
);
24453 std::vector
<dwarf2_per_cu_data_up
> units
;
24454 units
.push_back (std::move (one
));
24455 units
.push_back (std::move (two
));
24456 units
.push_back (std::move (three
));
24457 units
.push_back (std::move (four
));
24461 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24462 SELF_CHECK (units
[result
].get () == one_ptr
);
24463 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24464 SELF_CHECK (units
[result
].get () == one_ptr
);
24465 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24466 SELF_CHECK (units
[result
].get () == two_ptr
);
24468 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24469 SELF_CHECK (units
[result
].get () == three_ptr
);
24470 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24471 SELF_CHECK (units
[result
].get () == three_ptr
);
24472 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24473 SELF_CHECK (units
[result
].get () == four_ptr
);
24479 #endif /* GDB_SELF_TEST */
24481 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24484 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24485 enum language pretend_language
)
24487 struct attribute
*attr
;
24489 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24491 /* Set the language we're debugging. */
24492 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24493 if (cu
->producer
!= nullptr
24494 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24496 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24497 attribute is not standardised yet. As a workaround for the
24498 language detection we fall back to the DW_AT_producer
24500 cu
->per_cu
->lang
= language_opencl
;
24502 else if (cu
->producer
!= nullptr
24503 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24505 /* Similar hack for Go. */
24506 cu
->per_cu
->lang
= language_go
;
24508 else if (attr
!= nullptr)
24509 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24511 cu
->per_cu
->lang
= pretend_language
;
24512 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24518 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24520 auto it
= m_dwarf2_cus
.find (per_cu
);
24521 if (it
== m_dwarf2_cus
.end ())
24530 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24532 gdb_assert (this->get_cu (per_cu
) == nullptr);
24534 m_dwarf2_cus
[per_cu
] = cu
;
24540 dwarf2_per_objfile::age_comp_units ()
24542 dwarf_read_debug_printf_v ("running");
24544 /* This is not expected to be called in the middle of CU expansion. There is
24545 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24546 loaded in memory. Calling age_comp_units while the queue is in use could
24547 make us free the DIEs for a CU that is in the queue and therefore break
24549 gdb_assert (!this->per_bfd
->queue
.has_value ());
24551 /* Start by clearing all marks. */
24552 for (auto pair
: m_dwarf2_cus
)
24553 pair
.second
->clear_mark ();
24555 /* Traverse all CUs, mark them and their dependencies if used recently
24557 for (auto pair
: m_dwarf2_cus
)
24559 dwarf2_cu
*cu
= pair
.second
;
24562 if (cu
->last_used
<= dwarf_max_cache_age
)
24566 /* Delete all CUs still not marked. */
24567 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24569 dwarf2_cu
*cu
= it
->second
;
24571 if (!cu
->is_marked ())
24573 dwarf_read_debug_printf_v ("deleting old CU %s",
24574 sect_offset_str (cu
->per_cu
->sect_off
));
24576 it
= m_dwarf2_cus
.erase (it
);
24586 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24588 auto it
= m_dwarf2_cus
.find (per_cu
);
24589 if (it
== m_dwarf2_cus
.end ())
24594 m_dwarf2_cus
.erase (it
);
24597 dwarf2_per_objfile::~dwarf2_per_objfile ()
24602 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24603 We store these in a hash table separate from the DIEs, and preserve them
24604 when the DIEs are flushed out of cache.
24606 The CU "per_cu" pointer is needed because offset alone is not enough to
24607 uniquely identify the type. A file may have multiple .debug_types sections,
24608 or the type may come from a DWO file. Furthermore, while it's more logical
24609 to use per_cu->section+offset, with Fission the section with the data is in
24610 the DWO file but we don't know that section at the point we need it.
24611 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24612 because we can enter the lookup routine, get_die_type_at_offset, from
24613 outside this file, and thus won't necessarily have PER_CU->cu.
24614 Fortunately, PER_CU is stable for the life of the objfile. */
24616 struct dwarf2_per_cu_offset_and_type
24618 const struct dwarf2_per_cu_data
*per_cu
;
24619 sect_offset sect_off
;
24623 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24626 per_cu_offset_and_type_hash (const void *item
)
24628 const struct dwarf2_per_cu_offset_and_type
*ofs
24629 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24631 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24634 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24637 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24639 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24640 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24641 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24642 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24644 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24645 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24648 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24649 table if necessary. For convenience, return TYPE.
24651 The DIEs reading must have careful ordering to:
24652 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24653 reading current DIE.
24654 * Not trying to dereference contents of still incompletely read in types
24655 while reading in other DIEs.
24656 * Enable referencing still incompletely read in types just by a pointer to
24657 the type without accessing its fields.
24659 Therefore caller should follow these rules:
24660 * Try to fetch any prerequisite types we may need to build this DIE type
24661 before building the type and calling set_die_type.
24662 * After building type call set_die_type for current DIE as soon as
24663 possible before fetching more types to complete the current type.
24664 * Make the type as complete as possible before fetching more types. */
24666 static struct type
*
24667 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24668 bool skip_data_location
)
24670 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24671 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24672 struct objfile
*objfile
= per_objfile
->objfile
;
24673 struct attribute
*attr
;
24674 struct dynamic_prop prop
;
24676 /* For Ada types, make sure that the gnat-specific data is always
24677 initialized (if not already set). There are a few types where
24678 we should not be doing so, because the type-specific area is
24679 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24680 where the type-specific area is used to store the floatformat).
24681 But this is not a problem, because the gnat-specific information
24682 is actually not needed for these types. */
24683 if (need_gnat_info (cu
)
24684 && type
->code () != TYPE_CODE_FUNC
24685 && type
->code () != TYPE_CODE_FLT
24686 && type
->code () != TYPE_CODE_METHODPTR
24687 && type
->code () != TYPE_CODE_MEMBERPTR
24688 && type
->code () != TYPE_CODE_METHOD
24689 && type
->code () != TYPE_CODE_FIXED_POINT
24690 && !HAVE_GNAT_AUX_INFO (type
))
24691 INIT_GNAT_SPECIFIC (type
);
24693 /* Read DW_AT_allocated and set in type. */
24694 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24697 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24698 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24699 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24702 /* Read DW_AT_associated and set in type. */
24703 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24706 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24707 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24708 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24711 /* Read DW_AT_data_location and set in type. */
24712 if (!skip_data_location
)
24714 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24715 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24716 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24719 if (per_objfile
->die_type_hash
== NULL
)
24720 per_objfile
->die_type_hash
24721 = htab_up (htab_create_alloc (127,
24722 per_cu_offset_and_type_hash
,
24723 per_cu_offset_and_type_eq
,
24724 NULL
, xcalloc
, xfree
));
24726 ofs
.per_cu
= cu
->per_cu
;
24727 ofs
.sect_off
= die
->sect_off
;
24729 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24730 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24732 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24733 sect_offset_str (die
->sect_off
));
24734 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24735 struct dwarf2_per_cu_offset_and_type
);
24740 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24741 or return NULL if the die does not have a saved type. */
24743 static struct type
*
24744 get_die_type_at_offset (sect_offset sect_off
,
24745 dwarf2_per_cu_data
*per_cu
,
24746 dwarf2_per_objfile
*per_objfile
)
24748 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24750 if (per_objfile
->die_type_hash
== NULL
)
24753 ofs
.per_cu
= per_cu
;
24754 ofs
.sect_off
= sect_off
;
24755 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24756 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24763 /* Look up the type for DIE in CU in die_type_hash,
24764 or return NULL if DIE does not have a saved type. */
24766 static struct type
*
24767 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24769 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24772 /* Trivial hash function for partial_die_info: the hash value of a DIE
24773 is its offset in .debug_info for this objfile. */
24776 partial_die_hash (const void *item
)
24778 const struct partial_die_info
*part_die
24779 = (const struct partial_die_info
*) item
;
24781 return to_underlying (part_die
->sect_off
);
24784 /* Trivial comparison function for partial_die_info structures: two DIEs
24785 are equal if they have the same offset. */
24788 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24790 const struct partial_die_info
*part_die_lhs
24791 = (const struct partial_die_info
*) item_lhs
;
24792 const struct partial_die_info
*part_die_rhs
24793 = (const struct partial_die_info
*) item_rhs
;
24795 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24798 struct cmd_list_element
*set_dwarf_cmdlist
;
24799 struct cmd_list_element
*show_dwarf_cmdlist
;
24802 show_check_physname (struct ui_file
*file
, int from_tty
,
24803 struct cmd_list_element
*c
, const char *value
)
24805 fprintf_filtered (file
,
24806 _("Whether to check \"physname\" is %s.\n"),
24810 void _initialize_dwarf2_read ();
24812 _initialize_dwarf2_read ()
24814 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24815 Set DWARF specific variables.\n\
24816 Configure DWARF variables such as the cache size."),
24817 &set_dwarf_cmdlist
,
24818 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24820 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24821 Show DWARF specific variables.\n\
24822 Show DWARF variables such as the cache size."),
24823 &show_dwarf_cmdlist
,
24824 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24826 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24827 &dwarf_max_cache_age
, _("\
24828 Set the upper bound on the age of cached DWARF compilation units."), _("\
24829 Show the upper bound on the age of cached DWARF compilation units."), _("\
24830 A higher limit means that cached compilation units will be stored\n\
24831 in memory longer, and more total memory will be used. Zero disables\n\
24832 caching, which can slow down startup."),
24834 show_dwarf_max_cache_age
,
24835 &set_dwarf_cmdlist
,
24836 &show_dwarf_cmdlist
);
24838 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24839 Set debugging of the DWARF reader."), _("\
24840 Show debugging of the DWARF reader."), _("\
24841 When enabled (non-zero), debugging messages are printed during DWARF\n\
24842 reading and symtab expansion. A value of 1 (one) provides basic\n\
24843 information. A value greater than 1 provides more verbose information."),
24846 &setdebuglist
, &showdebuglist
);
24848 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24849 Set debugging of the DWARF DIE reader."), _("\
24850 Show debugging of the DWARF DIE reader."), _("\
24851 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24852 The value is the maximum depth to print."),
24855 &setdebuglist
, &showdebuglist
);
24857 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24858 Set debugging of the dwarf line reader."), _("\
24859 Show debugging of the dwarf line reader."), _("\
24860 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24861 A value of 1 (one) provides basic information.\n\
24862 A value greater than 1 provides more verbose information."),
24865 &setdebuglist
, &showdebuglist
);
24867 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24868 Set cross-checking of \"physname\" code against demangler."), _("\
24869 Show cross-checking of \"physname\" code against demangler."), _("\
24870 When enabled, GDB's internal \"physname\" code is checked against\n\
24872 NULL
, show_check_physname
,
24873 &setdebuglist
, &showdebuglist
);
24875 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24876 no_class
, &use_deprecated_index_sections
, _("\
24877 Set whether to use deprecated gdb_index sections."), _("\
24878 Show whether to use deprecated gdb_index sections."), _("\
24879 When enabled, deprecated .gdb_index sections are used anyway.\n\
24880 Normally they are ignored either because of a missing feature or\n\
24881 performance issue.\n\
24882 Warning: This option must be enabled before gdb reads the file."),
24885 &setlist
, &showlist
);
24887 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24888 &dwarf2_locexpr_funcs
);
24889 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24890 &dwarf2_loclist_funcs
);
24892 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24893 &dwarf2_block_frame_base_locexpr_funcs
);
24894 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24895 &dwarf2_block_frame_base_loclist_funcs
);
24898 selftests::register_test ("dw2_expand_symtabs_matching",
24899 selftests::dw2_expand_symtabs_matching::run_test
);
24900 selftests::register_test ("dwarf2_find_containing_comp_unit",
24901 selftests::find_containing_comp_unit::run_test
);