1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit-head.h"
36 #include "dwarf2/cu.h"
37 #include "dwarf2/index-cache.h"
38 #include "dwarf2/index-common.h"
39 #include "dwarf2/leb.h"
40 #include "dwarf2/line-header.h"
41 #include "dwarf2/dwz.h"
42 #include "dwarf2/macro.h"
43 #include "dwarf2/die.h"
44 #include "dwarf2/sect-names.h"
45 #include "dwarf2/stringify.h"
46 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
91 #include <unordered_set>
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
100 #define dwarf_read_debug_printf(fmt, ...) \
101 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
106 #define dwarf_read_debug_printf_v(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
110 /* When non-zero, dump DIEs after they are read in. */
111 static unsigned int dwarf_die_debug
= 0;
113 /* When non-zero, dump line number entries as they are read in. */
114 unsigned int dwarf_line_debug
= 0;
116 /* When true, cross-check physname against demangler. */
117 static bool check_physname
= false;
119 /* When true, do not reject deprecated .gdb_index sections. */
120 static bool use_deprecated_index_sections
= false;
122 /* This is used to store the data that is always per objfile. */
123 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
125 /* These are used to store the dwarf2_per_bfd objects.
127 objfiles having the same BFD, which doesn't require relocations, are going to
128 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
130 Other objfiles are not going to share a dwarf2_per_bfd with any other
131 objfiles, so they'll have their own version kept in the _objfile_data_key
133 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
134 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
136 /* The "aclass" indices for various kinds of computed DWARF symbols. */
138 static int dwarf2_locexpr_index
;
139 static int dwarf2_loclist_index
;
140 static int dwarf2_locexpr_block_index
;
141 static int dwarf2_loclist_block_index
;
143 /* Size of .debug_loclists section header for 32-bit DWARF format. */
144 #define LOCLIST_HEADER_SIZE32 12
146 /* Size of .debug_loclists section header for 64-bit DWARF format. */
147 #define LOCLIST_HEADER_SIZE64 20
149 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
150 #define RNGLIST_HEADER_SIZE32 12
152 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
153 #define RNGLIST_HEADER_SIZE64 20
155 /* An index into a (C++) symbol name component in a symbol name as
156 recorded in the mapped_index's symbol table. For each C++ symbol
157 in the symbol table, we record one entry for the start of each
158 component in the symbol in a table of name components, and then
159 sort the table, in order to be able to binary search symbol names,
160 ignoring leading namespaces, both completion and regular look up.
161 For example, for symbol "A::B::C", we'll have an entry that points
162 to "A::B::C", another that points to "B::C", and another for "C".
163 Note that function symbols in GDB index have no parameter
164 information, just the function/method names. You can convert a
165 name_component to a "const char *" using the
166 'mapped_index::symbol_name_at(offset_type)' method. */
168 struct name_component
170 /* Offset in the symbol name where the component starts. Stored as
171 a (32-bit) offset instead of a pointer to save memory and improve
172 locality on 64-bit architectures. */
173 offset_type name_offset
;
175 /* The symbol's index in the symbol and constant pool tables of a
180 /* Base class containing bits shared by both .gdb_index and
181 .debug_name indexes. */
183 struct mapped_index_base
185 mapped_index_base () = default;
186 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
188 /* The name_component table (a sorted vector). See name_component's
189 description above. */
190 std::vector
<name_component
> name_components
;
192 /* How NAME_COMPONENTS is sorted. */
193 enum case_sensitivity name_components_casing
;
195 /* Return the number of names in the symbol table. */
196 virtual size_t symbol_name_count () const = 0;
198 /* Get the name of the symbol at IDX in the symbol table. */
199 virtual const char *symbol_name_at
200 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
202 /* Return whether the name at IDX in the symbol table should be
204 virtual bool symbol_name_slot_invalid (offset_type idx
) const
209 /* Build the symbol name component sorted vector, if we haven't
211 void build_name_components (dwarf2_per_objfile
*per_objfile
);
213 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
214 possible matches for LN_NO_PARAMS in the name component
216 std::pair
<std::vector
<name_component
>::const_iterator
,
217 std::vector
<name_component
>::const_iterator
>
218 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
220 dwarf2_per_objfile
*per_objfile
) const;
222 /* Prevent deleting/destroying via a base class pointer. */
224 ~mapped_index_base() = default;
227 /* This is a view into the index that converts from bytes to an
228 offset_type, and allows indexing. Unaligned bytes are specifically
229 allowed here, and handled via unpacking. */
234 offset_view () = default;
236 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
241 /* Extract the INDEXth offset_type from the array. */
242 offset_type
operator[] (size_t index
) const
244 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
245 return (offset_type
) extract_unsigned_integer (bytes
,
246 sizeof (offset_type
),
250 /* Return the number of offset_types in this array. */
253 return m_bytes
.size () / sizeof (offset_type
);
256 /* Return true if this view is empty. */
259 return m_bytes
.empty ();
263 /* The underlying bytes. */
264 gdb::array_view
<const gdb_byte
> m_bytes
;
267 /* A description of the mapped index. The file format is described in
268 a comment by the code that writes the index. */
269 struct mapped_index final
: public mapped_index_base
271 /* Index data format version. */
274 /* The address table data. */
275 gdb::array_view
<const gdb_byte
> address_table
;
277 /* The symbol table, implemented as a hash table. */
278 offset_view symbol_table
;
280 /* A pointer to the constant pool. */
281 gdb::array_view
<const gdb_byte
> constant_pool
;
283 /* Return the index into the constant pool of the name of the IDXth
284 symbol in the symbol table. */
285 offset_type
symbol_name_index (offset_type idx
) const
287 return symbol_table
[2 * idx
];
290 /* Return the index into the constant pool of the CU vector of the
291 IDXth symbol in the symbol table. */
292 offset_type
symbol_vec_index (offset_type idx
) const
294 return symbol_table
[2 * idx
+ 1];
297 bool symbol_name_slot_invalid (offset_type idx
) const override
299 return (symbol_name_index (idx
) == 0
300 && symbol_vec_index (idx
) == 0);
303 /* Convenience method to get at the name of the symbol at IDX in the
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 return (const char *) (this->constant_pool
.data ()
309 + symbol_name_index (idx
));
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size () / 2; }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 bfd_endian dwarf5_byte_order
;
321 bool dwarf5_is_dwarf64
;
322 bool augmentation_is_gdb
;
324 uint32_t cu_count
= 0;
325 uint32_t tu_count
, bucket_count
, name_count
;
326 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
327 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
328 const gdb_byte
*name_table_string_offs_reordered
;
329 const gdb_byte
*name_table_entry_offs_reordered
;
330 const gdb_byte
*entry_pool
;
337 /* Attribute name DW_IDX_*. */
340 /* Attribute form DW_FORM_*. */
343 /* Value if FORM is DW_FORM_implicit_const. */
344 LONGEST implicit_const
;
346 std::vector
<attr
> attr_vec
;
349 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
351 const char *namei_to_name
352 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
354 /* Implementation of the mapped_index_base virtual interface, for
355 the name_components cache. */
357 const char *symbol_name_at
358 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
359 { return namei_to_name (idx
, per_objfile
); }
361 size_t symbol_name_count () const override
362 { return this->name_count
; }
365 /* See dwarf2read.h. */
368 get_dwarf2_per_objfile (struct objfile
*objfile
)
370 return dwarf2_objfile_data_key
.get (objfile
);
373 /* Default names of the debugging sections. */
375 /* Note that if the debugging section has been compressed, it might
376 have a name like .zdebug_info. */
378 const struct dwarf2_debug_sections dwarf2_elf_names
=
380 { ".debug_info", ".zdebug_info" },
381 { ".debug_abbrev", ".zdebug_abbrev" },
382 { ".debug_line", ".zdebug_line" },
383 { ".debug_loc", ".zdebug_loc" },
384 { ".debug_loclists", ".zdebug_loclists" },
385 { ".debug_macinfo", ".zdebug_macinfo" },
386 { ".debug_macro", ".zdebug_macro" },
387 { ".debug_str", ".zdebug_str" },
388 { ".debug_str_offsets", ".zdebug_str_offsets" },
389 { ".debug_line_str", ".zdebug_line_str" },
390 { ".debug_ranges", ".zdebug_ranges" },
391 { ".debug_rnglists", ".zdebug_rnglists" },
392 { ".debug_types", ".zdebug_types" },
393 { ".debug_addr", ".zdebug_addr" },
394 { ".debug_frame", ".zdebug_frame" },
395 { ".eh_frame", NULL
},
396 { ".gdb_index", ".zgdb_index" },
397 { ".debug_names", ".zdebug_names" },
398 { ".debug_aranges", ".zdebug_aranges" },
402 /* List of DWO/DWP sections. */
404 static const struct dwop_section_names
406 struct dwarf2_section_names abbrev_dwo
;
407 struct dwarf2_section_names info_dwo
;
408 struct dwarf2_section_names line_dwo
;
409 struct dwarf2_section_names loc_dwo
;
410 struct dwarf2_section_names loclists_dwo
;
411 struct dwarf2_section_names macinfo_dwo
;
412 struct dwarf2_section_names macro_dwo
;
413 struct dwarf2_section_names rnglists_dwo
;
414 struct dwarf2_section_names str_dwo
;
415 struct dwarf2_section_names str_offsets_dwo
;
416 struct dwarf2_section_names types_dwo
;
417 struct dwarf2_section_names cu_index
;
418 struct dwarf2_section_names tu_index
;
422 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
423 { ".debug_info.dwo", ".zdebug_info.dwo" },
424 { ".debug_line.dwo", ".zdebug_line.dwo" },
425 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
426 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
427 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
428 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
429 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
430 { ".debug_str.dwo", ".zdebug_str.dwo" },
431 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
432 { ".debug_types.dwo", ".zdebug_types.dwo" },
433 { ".debug_cu_index", ".zdebug_cu_index" },
434 { ".debug_tu_index", ".zdebug_tu_index" },
437 /* local data types */
439 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
440 begin with a header, which contains the following information. */
441 struct loclists_rnglists_header
443 /* A 4-byte or 12-byte length containing the length of the
444 set of entries for this compilation unit, not including the
445 length field itself. */
448 /* A 2-byte version identifier. */
451 /* A 1-byte unsigned integer containing the size in bytes of an address on
452 the target system. */
453 unsigned char addr_size
;
455 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
456 on the target system. */
457 unsigned char segment_collector_size
;
459 /* A 4-byte count of the number of offsets that follow the header. */
460 unsigned int offset_entry_count
;
463 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
464 This includes type_unit_group and quick_file_names. */
466 struct stmt_list_hash
468 /* The DWO unit this table is from or NULL if there is none. */
469 struct dwo_unit
*dwo_unit
;
471 /* Offset in .debug_line or .debug_line.dwo. */
472 sect_offset line_sect_off
;
475 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
476 an object of this type. This contains elements of type unit groups
477 that can be shared across objfiles. The non-shareable parts are in
478 type_unit_group_unshareable. */
480 struct type_unit_group
: public dwarf2_per_cu_data
482 /* The TUs that share this DW_AT_stmt_list entry.
483 This is added to while parsing type units to build partial symtabs,
484 and is deleted afterwards and not used again. */
485 std::vector
<signatured_type
*> *tus
= nullptr;
487 /* The data used to construct the hash key. */
488 struct stmt_list_hash hash
{};
491 /* These sections are what may appear in a (real or virtual) DWO file. */
495 struct dwarf2_section_info abbrev
;
496 struct dwarf2_section_info line
;
497 struct dwarf2_section_info loc
;
498 struct dwarf2_section_info loclists
;
499 struct dwarf2_section_info macinfo
;
500 struct dwarf2_section_info macro
;
501 struct dwarf2_section_info rnglists
;
502 struct dwarf2_section_info str
;
503 struct dwarf2_section_info str_offsets
;
504 /* In the case of a virtual DWO file, these two are unused. */
505 struct dwarf2_section_info info
;
506 std::vector
<dwarf2_section_info
> types
;
509 /* CUs/TUs in DWP/DWO files. */
513 /* Backlink to the containing struct dwo_file. */
514 struct dwo_file
*dwo_file
;
516 /* The "id" that distinguishes this CU/TU.
517 .debug_info calls this "dwo_id", .debug_types calls this "signature".
518 Since signatures came first, we stick with it for consistency. */
521 /* The section this CU/TU lives in, in the DWO file. */
522 struct dwarf2_section_info
*section
;
524 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
525 sect_offset sect_off
;
528 /* For types, offset in the type's DIE of the type defined by this TU. */
529 cu_offset type_offset_in_tu
;
532 /* include/dwarf2.h defines the DWP section codes.
533 It defines a max value but it doesn't define a min value, which we
534 use for error checking, so provide one. */
536 enum dwp_v2_section_ids
541 /* Data for one DWO file.
543 This includes virtual DWO files (a virtual DWO file is a DWO file as it
544 appears in a DWP file). DWP files don't really have DWO files per se -
545 comdat folding of types "loses" the DWO file they came from, and from
546 a high level view DWP files appear to contain a mass of random types.
547 However, to maintain consistency with the non-DWP case we pretend DWP
548 files contain virtual DWO files, and we assign each TU with one virtual
549 DWO file (generally based on the line and abbrev section offsets -
550 a heuristic that seems to work in practice). */
554 dwo_file () = default;
555 DISABLE_COPY_AND_ASSIGN (dwo_file
);
557 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
558 For virtual DWO files the name is constructed from the section offsets
559 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
560 from related CU+TUs. */
561 const char *dwo_name
= nullptr;
563 /* The DW_AT_comp_dir attribute. */
564 const char *comp_dir
= nullptr;
566 /* The bfd, when the file is open. Otherwise this is NULL.
567 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
568 gdb_bfd_ref_ptr dbfd
;
570 /* The sections that make up this DWO file.
571 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
572 sections (for lack of a better name). */
573 struct dwo_sections sections
{};
575 /* The CUs in the file.
576 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
577 an extension to handle LLVM's Link Time Optimization output (where
578 multiple source files may be compiled into a single object/dwo pair). */
581 /* Table of TUs in the file.
582 Each element is a struct dwo_unit. */
586 /* These sections are what may appear in a DWP file. */
590 /* These are used by all DWP versions (1, 2 and 5). */
591 struct dwarf2_section_info str
;
592 struct dwarf2_section_info cu_index
;
593 struct dwarf2_section_info tu_index
;
595 /* These are only used by DWP version 2 and version 5 files.
596 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
597 sections are referenced by section number, and are not recorded here.
598 In DWP version 2 or 5 there is at most one copy of all these sections,
599 each section being (effectively) comprised of the concatenation of all of
600 the individual sections that exist in the version 1 format.
601 To keep the code simple we treat each of these concatenated pieces as a
602 section itself (a virtual section?). */
603 struct dwarf2_section_info abbrev
;
604 struct dwarf2_section_info info
;
605 struct dwarf2_section_info line
;
606 struct dwarf2_section_info loc
;
607 struct dwarf2_section_info loclists
;
608 struct dwarf2_section_info macinfo
;
609 struct dwarf2_section_info macro
;
610 struct dwarf2_section_info rnglists
;
611 struct dwarf2_section_info str_offsets
;
612 struct dwarf2_section_info types
;
615 /* These sections are what may appear in a virtual DWO file in DWP version 1.
616 A virtual DWO file is a DWO file as it appears in a DWP file. */
618 struct virtual_v1_dwo_sections
620 struct dwarf2_section_info abbrev
;
621 struct dwarf2_section_info line
;
622 struct dwarf2_section_info loc
;
623 struct dwarf2_section_info macinfo
;
624 struct dwarf2_section_info macro
;
625 struct dwarf2_section_info str_offsets
;
626 /* Each DWP hash table entry records one CU or one TU.
627 That is recorded here, and copied to dwo_unit.section. */
628 struct dwarf2_section_info info_or_types
;
631 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
632 In version 2, the sections of the DWO files are concatenated together
633 and stored in one section of that name. Thus each ELF section contains
634 several "virtual" sections. */
636 struct virtual_v2_or_v5_dwo_sections
638 bfd_size_type abbrev_offset
;
639 bfd_size_type abbrev_size
;
641 bfd_size_type line_offset
;
642 bfd_size_type line_size
;
644 bfd_size_type loc_offset
;
645 bfd_size_type loc_size
;
647 bfd_size_type loclists_offset
;
648 bfd_size_type loclists_size
;
650 bfd_size_type macinfo_offset
;
651 bfd_size_type macinfo_size
;
653 bfd_size_type macro_offset
;
654 bfd_size_type macro_size
;
656 bfd_size_type rnglists_offset
;
657 bfd_size_type rnglists_size
;
659 bfd_size_type str_offsets_offset
;
660 bfd_size_type str_offsets_size
;
662 /* Each DWP hash table entry records one CU or one TU.
663 That is recorded here, and copied to dwo_unit.section. */
664 bfd_size_type info_or_types_offset
;
665 bfd_size_type info_or_types_size
;
668 /* Contents of DWP hash tables. */
670 struct dwp_hash_table
672 uint32_t version
, nr_columns
;
673 uint32_t nr_units
, nr_slots
;
674 const gdb_byte
*hash_table
, *unit_table
;
679 const gdb_byte
*indices
;
683 /* This is indexed by column number and gives the id of the section
685 #define MAX_NR_V2_DWO_SECTIONS \
686 (1 /* .debug_info or .debug_types */ \
687 + 1 /* .debug_abbrev */ \
688 + 1 /* .debug_line */ \
689 + 1 /* .debug_loc */ \
690 + 1 /* .debug_str_offsets */ \
691 + 1 /* .debug_macro or .debug_macinfo */)
692 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
693 const gdb_byte
*offsets
;
694 const gdb_byte
*sizes
;
698 /* This is indexed by column number and gives the id of the section
700 #define MAX_NR_V5_DWO_SECTIONS \
701 (1 /* .debug_info */ \
702 + 1 /* .debug_abbrev */ \
703 + 1 /* .debug_line */ \
704 + 1 /* .debug_loclists */ \
705 + 1 /* .debug_str_offsets */ \
706 + 1 /* .debug_macro */ \
707 + 1 /* .debug_rnglists */)
708 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
709 const gdb_byte
*offsets
;
710 const gdb_byte
*sizes
;
715 /* Data for one DWP file. */
719 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
721 dbfd (std::move (abfd
))
725 /* Name of the file. */
728 /* File format version. */
732 gdb_bfd_ref_ptr dbfd
;
734 /* Section info for this file. */
735 struct dwp_sections sections
{};
737 /* Table of CUs in the file. */
738 const struct dwp_hash_table
*cus
= nullptr;
740 /* Table of TUs in the file. */
741 const struct dwp_hash_table
*tus
= nullptr;
743 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
747 /* Table to map ELF section numbers to their sections.
748 This is only needed for the DWP V1 file format. */
749 unsigned int num_sections
= 0;
750 asection
**elf_sections
= nullptr;
753 /* Struct used to pass misc. parameters to read_die_and_children, et
754 al. which are used for both .debug_info and .debug_types dies.
755 All parameters here are unchanging for the life of the call. This
756 struct exists to abstract away the constant parameters of die reading. */
758 struct die_reader_specs
760 /* The bfd of die_section. */
763 /* The CU of the DIE we are parsing. */
764 struct dwarf2_cu
*cu
;
766 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
767 struct dwo_file
*dwo_file
;
769 /* The section the die comes from.
770 This is either .debug_info or .debug_types, or the .dwo variants. */
771 struct dwarf2_section_info
*die_section
;
773 /* die_section->buffer. */
774 const gdb_byte
*buffer
;
776 /* The end of the buffer. */
777 const gdb_byte
*buffer_end
;
779 /* The abbreviation table to use when reading the DIEs. */
780 struct abbrev_table
*abbrev_table
;
783 /* A subclass of die_reader_specs that holds storage and has complex
784 constructor and destructor behavior. */
786 class cutu_reader
: public die_reader_specs
790 cutu_reader (dwarf2_per_cu_data
*this_cu
,
791 dwarf2_per_objfile
*per_objfile
,
792 struct abbrev_table
*abbrev_table
,
793 dwarf2_cu
*existing_cu
,
796 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
797 dwarf2_per_objfile
*per_objfile
,
798 struct dwarf2_cu
*parent_cu
= nullptr,
799 struct dwo_file
*dwo_file
= nullptr);
801 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
803 const gdb_byte
*info_ptr
= nullptr;
804 struct die_info
*comp_unit_die
= nullptr;
805 bool dummy_p
= false;
807 /* Release the new CU, putting it on the chain. This cannot be done
812 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
813 dwarf2_per_objfile
*per_objfile
,
814 dwarf2_cu
*existing_cu
);
816 struct dwarf2_per_cu_data
*m_this_cu
;
817 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
819 /* The ordinary abbreviation table. */
820 abbrev_table_up m_abbrev_table_holder
;
822 /* The DWO abbreviation table. */
823 abbrev_table_up m_dwo_abbrev_table
;
826 /* When we construct a partial symbol table entry we only
827 need this much information. */
828 struct partial_die_info
: public allocate_on_obstack
830 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
832 /* Disable assign but still keep copy ctor, which is needed
833 load_partial_dies. */
834 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
835 partial_die_info (const partial_die_info
&) = default;
837 /* Adjust the partial die before generating a symbol for it. This
838 function may set the is_external flag or change the DIE's
840 void fixup (struct dwarf2_cu
*cu
);
842 /* Read a minimal amount of information into the minimal die
844 const gdb_byte
*read (const struct die_reader_specs
*reader
,
845 const struct abbrev_info
&abbrev
,
846 const gdb_byte
*info_ptr
);
848 /* Compute the name of this partial DIE. This memoizes the
849 result, so it is safe to call multiple times. */
850 const char *name (dwarf2_cu
*cu
);
852 /* Offset of this DIE. */
853 const sect_offset sect_off
;
855 /* DWARF-2 tag for this DIE. */
856 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
858 /* Assorted flags describing the data found in this DIE. */
859 const unsigned int has_children
: 1;
861 unsigned int is_external
: 1;
862 unsigned int is_declaration
: 1;
863 unsigned int has_type
: 1;
864 unsigned int has_specification
: 1;
865 unsigned int has_pc_info
: 1;
866 unsigned int has_range_info
: 1;
867 unsigned int may_be_inlined
: 1;
869 /* This DIE has been marked DW_AT_main_subprogram. */
870 unsigned int main_subprogram
: 1;
872 /* Flag set if the SCOPE field of this structure has been
874 unsigned int scope_set
: 1;
876 /* Flag set if the DIE has a byte_size attribute. */
877 unsigned int has_byte_size
: 1;
879 /* Flag set if the DIE has a DW_AT_const_value attribute. */
880 unsigned int has_const_value
: 1;
882 /* Flag set if any of the DIE's children are template arguments. */
883 unsigned int has_template_arguments
: 1;
885 /* Flag set if fixup has been called on this die. */
886 unsigned int fixup_called
: 1;
888 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
889 unsigned int is_dwz
: 1;
891 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
892 unsigned int spec_is_dwz
: 1;
894 unsigned int canonical_name
: 1;
896 /* The name of this DIE. Normally the value of DW_AT_name, but
897 sometimes a default name for unnamed DIEs. */
898 const char *raw_name
= nullptr;
900 /* The linkage name, if present. */
901 const char *linkage_name
= nullptr;
903 /* The scope to prepend to our children. This is generally
904 allocated on the comp_unit_obstack, so will disappear
905 when this compilation unit leaves the cache. */
906 const char *scope
= nullptr;
908 /* Some data associated with the partial DIE. The tag determines
909 which field is live. */
912 /* The location description associated with this DIE, if any. */
913 struct dwarf_block
*locdesc
;
914 /* The offset of an import, for DW_TAG_imported_unit. */
915 sect_offset sect_off
;
920 /* If HAS_PC_INFO, the PC range associated with this DIE. */
926 /* If HAS_RANGE_INFO, the ranges offset associated with this DIE. */
927 ULONGEST ranges_offset
;
930 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
931 DW_AT_sibling, if any. */
932 /* NOTE: This member isn't strictly necessary, partial_die_info::read
933 could return DW_AT_sibling values to its caller load_partial_dies. */
934 const gdb_byte
*sibling
= nullptr;
936 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
937 DW_AT_specification (or DW_AT_abstract_origin or
939 sect_offset spec_offset
{};
941 /* Pointers to this DIE's parent, first child, and next sibling,
943 struct partial_die_info
*die_parent
= nullptr;
944 struct partial_die_info
*die_child
= nullptr;
945 struct partial_die_info
*die_sibling
= nullptr;
947 friend struct partial_die_info
*
948 dwarf2_cu::find_partial_die (sect_offset sect_off
);
951 /* Only need to do look up in dwarf2_cu::find_partial_die. */
952 partial_die_info (sect_offset sect_off
)
953 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
957 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
959 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
964 has_specification
= 0;
972 has_template_arguments
= 0;
977 /* Don't set these using NSDMI (Non-static data member initialisation),
978 because g++-4.8 will error out. */
984 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
985 but this would require a corresponding change in unpack_field_as_long
987 static int bits_per_byte
= 8;
989 struct variant_part_builder
;
991 /* When reading a variant, we track a bit more information about the
992 field, and store it in an object of this type. */
996 int first_field
= -1;
999 /* A variant can contain other variant parts. */
1000 std::vector
<variant_part_builder
> variant_parts
;
1002 /* If we see a DW_TAG_variant, then this will be set if this is the
1004 bool default_branch
= false;
1005 /* If we see a DW_AT_discr_value, then this will be the discriminant
1007 ULONGEST discriminant_value
= 0;
1008 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1010 struct dwarf_block
*discr_list_data
= nullptr;
1013 /* This represents a DW_TAG_variant_part. */
1015 struct variant_part_builder
1017 /* The offset of the discriminant field. */
1018 sect_offset discriminant_offset
{};
1020 /* Variants that are direct children of this variant part. */
1021 std::vector
<variant_field
> variants
;
1023 /* True if we're currently reading a variant. */
1024 bool processing_variant
= false;
1029 int accessibility
= 0;
1031 /* Variant parts need to find the discriminant, which is a DIE
1032 reference. We track the section offset of each field to make
1035 struct field field
{};
1040 const char *name
= nullptr;
1041 std::vector
<struct fn_field
> fnfields
;
1044 /* The routines that read and process dies for a C struct or C++ class
1045 pass lists of data member fields and lists of member function fields
1046 in an instance of a field_info structure, as defined below. */
1049 /* List of data member and baseclasses fields. */
1050 std::vector
<struct nextfield
> fields
;
1051 std::vector
<struct nextfield
> baseclasses
;
1053 /* Set if the accessibility of one of the fields is not public. */
1054 bool non_public_fields
= false;
1056 /* Member function fieldlist array, contains name of possibly overloaded
1057 member function, number of overloaded member functions and a pointer
1058 to the head of the member function field chain. */
1059 std::vector
<struct fnfieldlist
> fnfieldlists
;
1061 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1062 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1063 std::vector
<struct decl_field
> typedef_field_list
;
1065 /* Nested types defined by this class and the number of elements in this
1067 std::vector
<struct decl_field
> nested_types_list
;
1069 /* If non-null, this is the variant part we are currently
1071 variant_part_builder
*current_variant_part
= nullptr;
1072 /* This holds all the top-level variant parts attached to the type
1074 std::vector
<variant_part_builder
> variant_parts
;
1076 /* Return the total number of fields (including baseclasses). */
1077 int nfields () const
1079 return fields
.size () + baseclasses
.size ();
1083 /* Loaded secondary compilation units are kept in memory until they
1084 have not been referenced for the processing of this many
1085 compilation units. Set this to zero to disable caching. Cache
1086 sizes of up to at least twenty will improve startup time for
1087 typical inter-CU-reference binaries, at an obvious memory cost. */
1088 static int dwarf_max_cache_age
= 5;
1090 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1091 struct cmd_list_element
*c
, const char *value
)
1093 fprintf_filtered (file
, _("The upper bound on the age of cached "
1094 "DWARF compilation units is %s.\n"),
1098 /* local function prototypes */
1100 static void dwarf2_find_base_address (struct die_info
*die
,
1101 struct dwarf2_cu
*cu
);
1103 static dwarf2_psymtab
*create_partial_symtab
1104 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1107 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1108 const gdb_byte
*info_ptr
,
1109 struct die_info
*type_unit_die
);
1111 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1113 static void scan_partial_symbols (struct partial_die_info
*,
1114 CORE_ADDR
*, CORE_ADDR
*,
1115 int, struct dwarf2_cu
*);
1117 static void add_partial_symbol (struct partial_die_info
*,
1118 struct dwarf2_cu
*);
1120 static void add_partial_namespace (struct partial_die_info
*pdi
,
1121 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1122 int set_addrmap
, struct dwarf2_cu
*cu
);
1124 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1125 CORE_ADDR
*highpc
, int set_addrmap
,
1126 struct dwarf2_cu
*cu
);
1128 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1129 struct dwarf2_cu
*cu
);
1131 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1132 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1133 int need_pc
, struct dwarf2_cu
*cu
);
1135 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1137 static struct partial_die_info
*load_partial_dies
1138 (const struct die_reader_specs
*, const gdb_byte
*, int);
1140 /* A pair of partial_die_info and compilation unit. */
1141 struct cu_partial_die_info
1143 /* The compilation unit of the partial_die_info. */
1144 struct dwarf2_cu
*cu
;
1145 /* A partial_die_info. */
1146 struct partial_die_info
*pdi
;
1148 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1154 cu_partial_die_info () = delete;
1157 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1158 struct dwarf2_cu
*);
1160 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1162 const struct attr_abbrev
*,
1165 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1166 struct attribute
*attr
, dwarf_tag tag
);
1168 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1170 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1171 dwarf2_section_info
*, sect_offset
);
1173 static const char *read_indirect_string
1174 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1175 const struct comp_unit_head
*, unsigned int *);
1177 static const char *read_indirect_string_at_offset
1178 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1180 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1184 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1185 ULONGEST str_index
);
1187 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1188 ULONGEST str_index
);
1190 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1191 struct dwarf2_cu
*);
1193 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1194 struct dwarf2_cu
*cu
);
1196 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1198 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1199 struct dwarf2_cu
*cu
);
1201 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1203 static struct die_info
*die_specification (struct die_info
*die
,
1204 struct dwarf2_cu
**);
1206 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1207 struct dwarf2_cu
*cu
);
1209 struct file_and_directory
;
1210 static void dwarf_decode_lines (struct line_header
*,
1211 const file_and_directory
&,
1212 struct dwarf2_cu
*, dwarf2_psymtab
*,
1213 CORE_ADDR
, int decode_mapping
);
1215 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1218 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1219 struct dwarf2_cu
*, struct symbol
* = NULL
);
1221 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1222 struct dwarf2_cu
*);
1224 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1227 struct obstack
*obstack
,
1228 struct dwarf2_cu
*cu
, LONGEST
*value
,
1229 const gdb_byte
**bytes
,
1230 struct dwarf2_locexpr_baton
**baton
);
1232 static struct type
*read_subrange_index_type (struct die_info
*die
,
1233 struct dwarf2_cu
*cu
);
1235 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1237 static int need_gnat_info (struct dwarf2_cu
*);
1239 static struct type
*die_descriptive_type (struct die_info
*,
1240 struct dwarf2_cu
*);
1242 static void set_descriptive_type (struct type
*, struct die_info
*,
1243 struct dwarf2_cu
*);
1245 static struct type
*die_containing_type (struct die_info
*,
1246 struct dwarf2_cu
*);
1248 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1249 struct dwarf2_cu
*);
1251 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1253 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1255 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1257 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1258 const char *suffix
, int physname
,
1259 struct dwarf2_cu
*cu
);
1261 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1263 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1265 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1267 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1269 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1271 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1273 /* Return the .debug_loclists section to use for cu. */
1274 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1276 /* Return the .debug_rnglists section to use for cu. */
1277 static struct dwarf2_section_info
*cu_debug_rnglists_section
1278 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1280 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1281 values. Keep the items ordered with increasing constraints compliance. */
1284 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1285 PC_BOUNDS_NOT_PRESENT
,
1287 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1288 were present but they do not form a valid range of PC addresses. */
1291 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1294 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1298 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1299 CORE_ADDR
*, CORE_ADDR
*,
1303 static void get_scope_pc_bounds (struct die_info
*,
1304 CORE_ADDR
*, CORE_ADDR
*,
1305 struct dwarf2_cu
*);
1307 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1308 CORE_ADDR
, struct dwarf2_cu
*);
1310 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1311 struct dwarf2_cu
*);
1313 static void dwarf2_attach_fields_to_type (struct field_info
*,
1314 struct type
*, struct dwarf2_cu
*);
1316 static void dwarf2_add_member_fn (struct field_info
*,
1317 struct die_info
*, struct type
*,
1318 struct dwarf2_cu
*);
1320 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1322 struct dwarf2_cu
*);
1324 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1326 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1328 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1330 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1332 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1334 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1336 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1338 static struct type
*read_module_type (struct die_info
*die
,
1339 struct dwarf2_cu
*cu
);
1341 static const char *namespace_name (struct die_info
*die
,
1342 int *is_anonymous
, struct dwarf2_cu
*);
1344 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1346 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1349 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1350 struct dwarf2_cu
*);
1352 static struct die_info
*read_die_and_siblings_1
1353 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1356 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1357 const gdb_byte
*info_ptr
,
1358 const gdb_byte
**new_info_ptr
,
1359 struct die_info
*parent
);
1361 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1362 struct die_info
**, const gdb_byte
*,
1365 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1366 struct die_info
**, const gdb_byte
*);
1368 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1370 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1373 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1375 static const char *dwarf2_full_name (const char *name
,
1376 struct die_info
*die
,
1377 struct dwarf2_cu
*cu
);
1379 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1380 struct dwarf2_cu
*cu
);
1382 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1383 struct dwarf2_cu
**);
1385 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1387 static void dump_die_for_error (struct die_info
*);
1389 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1392 /*static*/ void dump_die (struct die_info
*, int max_level
);
1394 static void store_in_ref_table (struct die_info
*,
1395 struct dwarf2_cu
*);
1397 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1398 const struct attribute
*,
1399 struct dwarf2_cu
**);
1401 static struct die_info
*follow_die_ref (struct die_info
*,
1402 const struct attribute
*,
1403 struct dwarf2_cu
**);
1405 static struct die_info
*follow_die_sig (struct die_info
*,
1406 const struct attribute
*,
1407 struct dwarf2_cu
**);
1409 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1410 struct dwarf2_cu
*);
1412 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1413 const struct attribute
*,
1414 struct dwarf2_cu
*);
1416 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1417 dwarf2_per_objfile
*per_objfile
);
1419 static void read_signatured_type (signatured_type
*sig_type
,
1420 dwarf2_per_objfile
*per_objfile
);
1422 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1423 struct die_info
*die
, struct dwarf2_cu
*cu
,
1424 struct dynamic_prop
*prop
, struct type
*type
);
1426 /* memory allocation interface */
1428 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1430 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1432 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1434 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1435 struct dwarf2_loclist_baton
*baton
,
1436 const struct attribute
*attr
);
1438 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1440 struct dwarf2_cu
*cu
,
1443 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1444 const gdb_byte
*info_ptr
,
1445 const struct abbrev_info
*abbrev
);
1447 static hashval_t
partial_die_hash (const void *item
);
1449 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1451 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1452 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1453 dwarf2_per_objfile
*per_objfile
);
1455 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1456 struct die_info
*comp_unit_die
,
1457 enum language pretend_language
);
1459 static struct type
*set_die_type (struct die_info
*, struct type
*,
1460 struct dwarf2_cu
*, bool = false);
1462 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1464 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1465 dwarf2_per_objfile
*per_objfile
,
1466 dwarf2_cu
*existing_cu
,
1468 enum language pretend_language
);
1470 static void process_full_comp_unit (dwarf2_cu
*cu
,
1471 enum language pretend_language
);
1473 static void process_full_type_unit (dwarf2_cu
*cu
,
1474 enum language pretend_language
);
1476 static struct type
*get_die_type_at_offset (sect_offset
,
1477 dwarf2_per_cu_data
*per_cu
,
1478 dwarf2_per_objfile
*per_objfile
);
1480 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1482 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1483 dwarf2_per_objfile
*per_objfile
,
1484 enum language pretend_language
);
1486 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1488 /* Class, the destructor of which frees all allocated queue entries. This
1489 will only have work to do if an error was thrown while processing the
1490 dwarf. If no error was thrown then the queue entries should have all
1491 been processed, and freed, as we went along. */
1493 class dwarf2_queue_guard
1496 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1497 : m_per_objfile (per_objfile
)
1499 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1501 m_per_objfile
->per_bfd
->queue
.emplace ();
1504 /* Free any entries remaining on the queue. There should only be
1505 entries left if we hit an error while processing the dwarf. */
1506 ~dwarf2_queue_guard ()
1508 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1510 m_per_objfile
->per_bfd
->queue
.reset ();
1513 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1516 dwarf2_per_objfile
*m_per_objfile
;
1519 dwarf2_queue_item::~dwarf2_queue_item ()
1521 /* Anything still marked queued is likely to be in an
1522 inconsistent state, so discard it. */
1525 per_objfile
->remove_cu (per_cu
);
1530 /* See dwarf2/read.h. */
1533 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1535 if (data
->is_debug_types
)
1536 delete static_cast<signatured_type
*> (data
);
1541 /* The return type of find_file_and_directory. Note, the enclosed
1542 string pointers are only valid while this object is valid. */
1544 struct file_and_directory
1546 /* The filename. This is never NULL. */
1549 /* The compilation directory. NULL if not known. If we needed to
1550 compute a new string, it will be stored in the per-BFD string
1551 bcache; otherwise, points directly to the DW_AT_comp_dir string
1552 attribute owned by the obstack that owns the DIE. */
1553 const char *comp_dir
;
1556 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1557 struct dwarf2_cu
*cu
);
1559 static const char *compute_include_file_name
1560 (const struct line_header
*lh
,
1561 const file_entry
&fe
,
1562 const file_and_directory
&cu_info
,
1563 gdb::unique_xmalloc_ptr
<char> *name_holder
);
1565 static htab_up
allocate_signatured_type_table ();
1567 static htab_up
allocate_dwo_unit_table ();
1569 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1570 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1571 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1573 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1575 static struct dwo_unit
*lookup_dwo_comp_unit
1576 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1577 ULONGEST signature
);
1579 static struct dwo_unit
*lookup_dwo_type_unit
1580 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1582 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1584 /* A unique pointer to a dwo_file. */
1586 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1588 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1590 static void check_producer (struct dwarf2_cu
*cu
);
1592 /* Various complaints about symbol reading that don't abort the process. */
1595 dwarf2_debug_line_missing_file_complaint (void)
1597 complaint (_(".debug_line section has line data without a file"));
1601 dwarf2_debug_line_missing_end_sequence_complaint (void)
1603 complaint (_(".debug_line section has line "
1604 "program sequence without an end"));
1608 dwarf2_complex_location_expr_complaint (void)
1610 complaint (_("location expression too complex"));
1614 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1617 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1622 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1624 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1628 /* Hash function for line_header_hash. */
1631 line_header_hash (const struct line_header
*ofs
)
1633 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1636 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1639 line_header_hash_voidp (const void *item
)
1641 const struct line_header
*ofs
= (const struct line_header
*) item
;
1643 return line_header_hash (ofs
);
1646 /* Equality function for line_header_hash. */
1649 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1651 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1652 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1654 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1655 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1660 /* An iterator for all_comp_units that is based on index. This
1661 approach makes it possible to iterate over all_comp_units safely,
1662 when some caller in the loop may add new units. */
1664 class all_comp_units_iterator
1668 all_comp_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
1669 : m_per_bfd (per_bfd
),
1670 m_index (start
? 0 : per_bfd
->all_comp_units
.size ())
1674 all_comp_units_iterator
&operator++ ()
1680 dwarf2_per_cu_data
*operator* () const
1682 return m_per_bfd
->get_cu (m_index
);
1685 bool operator== (const all_comp_units_iterator
&other
) const
1687 return m_index
== other
.m_index
;
1691 bool operator!= (const all_comp_units_iterator
&other
) const
1693 return m_index
!= other
.m_index
;
1698 dwarf2_per_bfd
*m_per_bfd
;
1702 /* A range adapter for the all_comp_units_iterator. */
1703 class all_comp_units_range
1707 all_comp_units_range (dwarf2_per_bfd
*per_bfd
)
1708 : m_per_bfd (per_bfd
)
1712 all_comp_units_iterator
begin ()
1714 return all_comp_units_iterator (m_per_bfd
, true);
1717 all_comp_units_iterator
end ()
1719 return all_comp_units_iterator (m_per_bfd
, false);
1724 dwarf2_per_bfd
*m_per_bfd
;
1727 /* See declaration. */
1729 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1732 can_copy (can_copy_
)
1735 names
= &dwarf2_elf_names
;
1737 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1738 locate_sections (obfd
, sec
, *names
);
1741 dwarf2_per_bfd::~dwarf2_per_bfd ()
1743 for (auto &per_cu
: all_comp_units
)
1745 per_cu
->imported_symtabs_free ();
1746 per_cu
->free_cached_file_names ();
1749 /* Everything else should be on this->obstack. */
1755 dwarf2_per_objfile::remove_all_cus ()
1757 gdb_assert (!this->per_bfd
->queue
.has_value ());
1759 for (auto pair
: m_dwarf2_cus
)
1762 m_dwarf2_cus
.clear ();
1765 /* A helper class that calls free_cached_comp_units on
1768 class free_cached_comp_units
1772 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1773 : m_per_objfile (per_objfile
)
1777 ~free_cached_comp_units ()
1779 m_per_objfile
->remove_all_cus ();
1782 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1786 dwarf2_per_objfile
*m_per_objfile
;
1792 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1794 if (per_cu
->index
< this->m_symtabs
.size ())
1795 return this->m_symtabs
[per_cu
->index
] != nullptr;
1802 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1804 if (per_cu
->index
< this->m_symtabs
.size ())
1805 return this->m_symtabs
[per_cu
->index
];
1812 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1813 compunit_symtab
*symtab
)
1815 if (per_cu
->index
>= this->m_symtabs
.size ())
1816 this->m_symtabs
.resize (per_cu
->index
+ 1);
1817 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1818 this->m_symtabs
[per_cu
->index
] = symtab
;
1821 /* Try to locate the sections we need for DWARF 2 debugging
1822 information and return true if we have enough to do something.
1823 NAMES points to the dwarf2 section names, or is NULL if the standard
1824 ELF names are used. CAN_COPY is true for formats where symbol
1825 interposition is possible and so symbol values must follow copy
1826 relocation rules. */
1829 dwarf2_has_info (struct objfile
*objfile
,
1830 const struct dwarf2_debug_sections
*names
,
1833 if (objfile
->flags
& OBJF_READNEVER
)
1836 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1838 if (per_objfile
== NULL
)
1840 dwarf2_per_bfd
*per_bfd
;
1842 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1843 BFD doesn't require relocations.
1845 We don't share with objfiles for which -readnow was requested,
1846 because it would complicate things when loading the same BFD with
1847 -readnow and then without -readnow. */
1848 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1849 && (objfile
->flags
& OBJF_READNOW
) == 0)
1851 /* See if one has been created for this BFD yet. */
1852 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1854 if (per_bfd
== nullptr)
1856 /* No, create it now. */
1857 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1858 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1863 /* No sharing possible, create one specifically for this objfile. */
1864 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1865 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1868 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1871 return (!per_objfile
->per_bfd
->info
.is_virtual
1872 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1873 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1874 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1877 /* See declaration. */
1880 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1881 const dwarf2_debug_sections
&names
)
1883 flagword aflag
= bfd_section_flags (sectp
);
1885 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1888 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1889 > bfd_get_file_size (abfd
))
1891 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1892 warning (_("Discarding section %s which has a section size (%s"
1893 ") larger than the file size [in module %s]"),
1894 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1895 bfd_get_filename (abfd
));
1897 else if (names
.info
.matches (sectp
->name
))
1899 this->info
.s
.section
= sectp
;
1900 this->info
.size
= bfd_section_size (sectp
);
1902 else if (names
.abbrev
.matches (sectp
->name
))
1904 this->abbrev
.s
.section
= sectp
;
1905 this->abbrev
.size
= bfd_section_size (sectp
);
1907 else if (names
.line
.matches (sectp
->name
))
1909 this->line
.s
.section
= sectp
;
1910 this->line
.size
= bfd_section_size (sectp
);
1912 else if (names
.loc
.matches (sectp
->name
))
1914 this->loc
.s
.section
= sectp
;
1915 this->loc
.size
= bfd_section_size (sectp
);
1917 else if (names
.loclists
.matches (sectp
->name
))
1919 this->loclists
.s
.section
= sectp
;
1920 this->loclists
.size
= bfd_section_size (sectp
);
1922 else if (names
.macinfo
.matches (sectp
->name
))
1924 this->macinfo
.s
.section
= sectp
;
1925 this->macinfo
.size
= bfd_section_size (sectp
);
1927 else if (names
.macro
.matches (sectp
->name
))
1929 this->macro
.s
.section
= sectp
;
1930 this->macro
.size
= bfd_section_size (sectp
);
1932 else if (names
.str
.matches (sectp
->name
))
1934 this->str
.s
.section
= sectp
;
1935 this->str
.size
= bfd_section_size (sectp
);
1937 else if (names
.str_offsets
.matches (sectp
->name
))
1939 this->str_offsets
.s
.section
= sectp
;
1940 this->str_offsets
.size
= bfd_section_size (sectp
);
1942 else if (names
.line_str
.matches (sectp
->name
))
1944 this->line_str
.s
.section
= sectp
;
1945 this->line_str
.size
= bfd_section_size (sectp
);
1947 else if (names
.addr
.matches (sectp
->name
))
1949 this->addr
.s
.section
= sectp
;
1950 this->addr
.size
= bfd_section_size (sectp
);
1952 else if (names
.frame
.matches (sectp
->name
))
1954 this->frame
.s
.section
= sectp
;
1955 this->frame
.size
= bfd_section_size (sectp
);
1957 else if (names
.eh_frame
.matches (sectp
->name
))
1959 this->eh_frame
.s
.section
= sectp
;
1960 this->eh_frame
.size
= bfd_section_size (sectp
);
1962 else if (names
.ranges
.matches (sectp
->name
))
1964 this->ranges
.s
.section
= sectp
;
1965 this->ranges
.size
= bfd_section_size (sectp
);
1967 else if (names
.rnglists
.matches (sectp
->name
))
1969 this->rnglists
.s
.section
= sectp
;
1970 this->rnglists
.size
= bfd_section_size (sectp
);
1972 else if (names
.types
.matches (sectp
->name
))
1974 struct dwarf2_section_info type_section
;
1976 memset (&type_section
, 0, sizeof (type_section
));
1977 type_section
.s
.section
= sectp
;
1978 type_section
.size
= bfd_section_size (sectp
);
1980 this->types
.push_back (type_section
);
1982 else if (names
.gdb_index
.matches (sectp
->name
))
1984 this->gdb_index
.s
.section
= sectp
;
1985 this->gdb_index
.size
= bfd_section_size (sectp
);
1987 else if (names
.debug_names
.matches (sectp
->name
))
1989 this->debug_names
.s
.section
= sectp
;
1990 this->debug_names
.size
= bfd_section_size (sectp
);
1992 else if (names
.debug_aranges
.matches (sectp
->name
))
1994 this->debug_aranges
.s
.section
= sectp
;
1995 this->debug_aranges
.size
= bfd_section_size (sectp
);
1998 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1999 && bfd_section_vma (sectp
) == 0)
2000 this->has_section_at_zero
= true;
2003 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2007 dwarf2_get_section_info (struct objfile
*objfile
,
2008 enum dwarf2_section_enum sect
,
2009 asection
**sectp
, const gdb_byte
**bufp
,
2010 bfd_size_type
*sizep
)
2012 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2013 struct dwarf2_section_info
*info
;
2015 /* We may see an objfile without any DWARF, in which case we just
2017 if (per_objfile
== NULL
)
2026 case DWARF2_DEBUG_FRAME
:
2027 info
= &per_objfile
->per_bfd
->frame
;
2029 case DWARF2_EH_FRAME
:
2030 info
= &per_objfile
->per_bfd
->eh_frame
;
2033 gdb_assert_not_reached ("unexpected section");
2036 info
->read (objfile
);
2038 *sectp
= info
->get_bfd_section ();
2039 *bufp
= info
->buffer
;
2040 *sizep
= info
->size
;
2044 /* DWARF quick_symbol_functions support. */
2046 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2047 unique line tables, so we maintain a separate table of all .debug_line
2048 derived entries to support the sharing.
2049 All the quick functions need is the list of file names. We discard the
2050 line_header when we're done and don't need to record it here. */
2051 struct quick_file_names
2053 /* The data used to construct the hash key. */
2054 struct stmt_list_hash hash
;
2056 /* The number of entries in file_names, real_names. */
2057 unsigned int num_file_names
;
2059 /* The CU directory, as given by DW_AT_comp_dir. May be
2061 const char *comp_dir
;
2063 /* The file names from the line table, after being run through
2065 const char **file_names
;
2067 /* The file names from the line table after being run through
2068 gdb_realpath. These are computed lazily. */
2069 const char **real_names
;
2072 /* When using the index (and thus not using psymtabs), each CU has an
2073 object of this type. This is used to hold information needed by
2074 the various "quick" methods. */
2075 struct dwarf2_per_cu_quick_data
2077 /* The file table. This can be NULL if there was no file table
2078 or it's currently not read in.
2079 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2080 struct quick_file_names
*file_names
;
2082 /* A temporary mark bit used when iterating over all CUs in
2083 expand_symtabs_matching. */
2084 unsigned int mark
: 1;
2086 /* True if we've tried to read the file table. There will be no
2087 point in trying to read it again next time. */
2088 bool files_read
: 1;
2091 /* A subclass of psymbol_functions that arranges to read the DWARF
2092 partial symbols when needed. */
2093 struct lazy_dwarf_reader
: public psymbol_functions
2095 using psymbol_functions::psymbol_functions
;
2097 bool can_lazily_read_symbols () override
2102 void read_partial_symbols (struct objfile
*objfile
) override
2104 if (dwarf2_has_info (objfile
, nullptr))
2105 dwarf2_build_psymtabs (objfile
, this);
2109 static quick_symbol_functions_up
2110 make_lazy_dwarf_reader ()
2112 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2115 struct dwarf2_base_index_functions
: public quick_symbol_functions
2117 bool has_symbols (struct objfile
*objfile
) override
;
2119 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
2121 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2123 void forget_cached_source_info (struct objfile
*objfile
) override
;
2125 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2128 bool *symbol_found_p
) override
2130 *symbol_found_p
= false;
2131 return language_unknown
;
2134 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2136 void expand_all_symtabs (struct objfile
*objfile
) override
;
2138 struct compunit_symtab
*find_pc_sect_compunit_symtab
2139 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2140 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2142 struct compunit_symtab
*find_compunit_symtab_by_address
2143 (struct objfile
*objfile
, CORE_ADDR address
) override
2148 void map_symbol_filenames (struct objfile
*objfile
,
2149 gdb::function_view
<symbol_filename_ftype
> fun
,
2150 bool need_fullname
) override
;
2153 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2155 void dump (struct objfile
*objfile
) override
;
2157 void expand_matching_symbols
2159 const lookup_name_info
&lookup_name
,
2162 symbol_compare_ftype
*ordered_compare
) override
;
2164 bool expand_symtabs_matching
2165 (struct objfile
*objfile
,
2166 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2167 const lookup_name_info
*lookup_name
,
2168 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2169 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2170 block_search_flags search_flags
,
2172 enum search_domain kind
) override
;
2175 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2177 void dump (struct objfile
*objfile
) override
;
2179 void expand_matching_symbols
2181 const lookup_name_info
&lookup_name
,
2184 symbol_compare_ftype
*ordered_compare
) override
;
2186 bool expand_symtabs_matching
2187 (struct objfile
*objfile
,
2188 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2189 const lookup_name_info
*lookup_name
,
2190 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2191 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2192 block_search_flags search_flags
,
2194 enum search_domain kind
) override
;
2197 static quick_symbol_functions_up
2198 make_dwarf_gdb_index ()
2200 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2203 static quick_symbol_functions_up
2204 make_dwarf_debug_names ()
2206 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2209 /* Utility hash function for a stmt_list_hash. */
2212 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2216 if (stmt_list_hash
->dwo_unit
!= NULL
)
2217 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2218 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2222 /* Utility equality function for a stmt_list_hash. */
2225 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2226 const struct stmt_list_hash
*rhs
)
2228 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2230 if (lhs
->dwo_unit
!= NULL
2231 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2234 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2237 /* Hash function for a quick_file_names. */
2240 hash_file_name_entry (const void *e
)
2242 const struct quick_file_names
*file_data
2243 = (const struct quick_file_names
*) e
;
2245 return hash_stmt_list_entry (&file_data
->hash
);
2248 /* Equality function for a quick_file_names. */
2251 eq_file_name_entry (const void *a
, const void *b
)
2253 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2254 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2256 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2259 /* Create a quick_file_names hash table. */
2262 create_quick_file_names_table (unsigned int nr_initial_entries
)
2264 return htab_up (htab_create_alloc (nr_initial_entries
,
2265 hash_file_name_entry
, eq_file_name_entry
,
2266 nullptr, xcalloc
, xfree
));
2269 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2270 function is unrelated to symtabs, symtab would have to be created afterwards.
2271 You should call age_cached_comp_units after processing the CU. */
2274 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2277 if (per_cu
->is_debug_types
)
2278 load_full_type_unit (per_cu
, per_objfile
);
2280 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2281 skip_partial
, language_minimal
);
2283 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2285 return nullptr; /* Dummy CU. */
2287 dwarf2_find_base_address (cu
->dies
, cu
);
2292 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2295 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2296 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2298 /* Skip type_unit_groups, reading the type units they contain
2299 is handled elsewhere. */
2300 if (per_cu
->type_unit_group_p ())
2304 /* The destructor of dwarf2_queue_guard frees any entries left on
2305 the queue. After this point we're guaranteed to leave this function
2306 with the dwarf queue empty. */
2307 dwarf2_queue_guard
q_guard (per_objfile
);
2309 if (!per_objfile
->symtab_set_p (per_cu
))
2311 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2312 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2314 /* If we just loaded a CU from a DWO, and we're working with an index
2315 that may badly handle TUs, load all the TUs in that DWO as well.
2316 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2317 if (!per_cu
->is_debug_types
2319 && cu
->dwo_unit
!= NULL
2320 && per_objfile
->per_bfd
->index_table
!= NULL
2321 && per_objfile
->per_bfd
->index_table
->version
<= 7
2322 /* DWP files aren't supported yet. */
2323 && get_dwp_file (per_objfile
) == NULL
)
2324 queue_and_load_all_dwo_tus (cu
);
2327 process_queue (per_objfile
);
2330 /* Age the cache, releasing compilation units that have not
2331 been used recently. */
2332 per_objfile
->age_comp_units ();
2335 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2336 the per-objfile for which this symtab is instantiated.
2338 Returns the resulting symbol table. */
2340 static struct compunit_symtab
*
2341 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2342 dwarf2_per_objfile
*per_objfile
,
2345 gdb_assert (per_objfile
->per_bfd
->using_index
);
2347 if (!per_objfile
->symtab_set_p (per_cu
))
2349 free_cached_comp_units
freer (per_objfile
);
2350 scoped_restore decrementer
= increment_reading_symtab ();
2351 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2352 process_cu_includes (per_objfile
);
2355 return per_objfile
->get_symtab (per_cu
);
2360 dwarf2_per_cu_data_up
2361 dwarf2_per_bfd::allocate_per_cu ()
2363 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2364 result
->per_bfd
= this;
2365 result
->index
= all_comp_units
.size ();
2372 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2374 signatured_type_up
result (new signatured_type (signature
));
2375 result
->per_bfd
= this;
2376 result
->index
= all_comp_units
.size ();
2377 result
->is_debug_types
= true;
2382 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2383 obstack, and constructed with the specified field values. */
2385 static dwarf2_per_cu_data_up
2386 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2387 struct dwarf2_section_info
*section
,
2389 sect_offset sect_off
, ULONGEST length
)
2391 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2392 the_cu
->sect_off
= sect_off
;
2393 the_cu
->length
= length
;
2394 the_cu
->section
= section
;
2395 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2396 struct dwarf2_per_cu_quick_data
);
2397 the_cu
->is_dwz
= is_dwz
;
2401 /* A helper for create_cus_from_index that handles a given list of
2405 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2406 const gdb_byte
*cu_list
, offset_type n_elements
,
2407 struct dwarf2_section_info
*section
,
2410 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2412 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2414 sect_offset sect_off
2415 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2416 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2419 dwarf2_per_cu_data_up per_cu
2420 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2422 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2426 /* Read the CU list from the mapped index, and use it to create all
2427 the CU objects for PER_BFD. */
2430 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2431 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2432 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2434 gdb_assert (per_bfd
->all_comp_units
.empty ());
2435 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2437 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2440 if (dwz_elements
== 0)
2443 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2444 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2448 /* Create the signatured type hash table from the index. */
2451 create_signatured_type_table_from_index
2452 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2453 const gdb_byte
*bytes
, offset_type elements
)
2455 htab_up sig_types_hash
= allocate_signatured_type_table ();
2457 for (offset_type i
= 0; i
< elements
; i
+= 3)
2459 signatured_type_up sig_type
;
2462 cu_offset type_offset_in_tu
;
2464 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2465 sect_offset sect_off
2466 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2468 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2470 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2473 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2474 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2475 sig_type
->section
= section
;
2476 sig_type
->sect_off
= sect_off
;
2478 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2479 struct dwarf2_per_cu_quick_data
);
2481 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2482 *slot
= sig_type
.get ();
2484 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2487 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2490 /* Create the signatured type hash table from .debug_names. */
2493 create_signatured_type_table_from_debug_names
2494 (dwarf2_per_objfile
*per_objfile
,
2495 const mapped_debug_names
&map
,
2496 struct dwarf2_section_info
*section
,
2497 struct dwarf2_section_info
*abbrev_section
)
2499 struct objfile
*objfile
= per_objfile
->objfile
;
2501 section
->read (objfile
);
2502 abbrev_section
->read (objfile
);
2504 htab_up sig_types_hash
= allocate_signatured_type_table ();
2506 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2508 signatured_type_up sig_type
;
2511 sect_offset sect_off
2512 = (sect_offset
) (extract_unsigned_integer
2513 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2515 map
.dwarf5_byte_order
));
2517 comp_unit_head cu_header
;
2518 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2520 section
->buffer
+ to_underlying (sect_off
),
2523 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2524 (cu_header
.signature
);
2525 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2526 sig_type
->section
= section
;
2527 sig_type
->sect_off
= sect_off
;
2529 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2530 struct dwarf2_per_cu_quick_data
);
2532 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2533 *slot
= sig_type
.get ();
2535 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2538 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2541 /* Read the address map data from the mapped index, and use it to
2542 populate the psymtabs_addrmap. */
2545 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2546 struct mapped_index
*index
)
2548 struct objfile
*objfile
= per_objfile
->objfile
;
2549 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2550 struct gdbarch
*gdbarch
= objfile
->arch ();
2551 const gdb_byte
*iter
, *end
;
2552 struct addrmap
*mutable_map
;
2555 auto_obstack temp_obstack
;
2557 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2559 iter
= index
->address_table
.data ();
2560 end
= iter
+ index
->address_table
.size ();
2562 baseaddr
= objfile
->text_section_offset ();
2566 ULONGEST hi
, lo
, cu_index
;
2567 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2569 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2571 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2576 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2577 hex_string (lo
), hex_string (hi
));
2581 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2583 complaint (_(".gdb_index address table has invalid CU number %u"),
2584 (unsigned) cu_index
);
2588 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2589 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2590 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2591 per_bfd
->get_cu (cu_index
));
2594 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2598 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2599 populate the psymtabs_addrmap. */
2602 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2603 struct dwarf2_section_info
*section
)
2605 struct objfile
*objfile
= per_objfile
->objfile
;
2606 bfd
*abfd
= objfile
->obfd
;
2607 struct gdbarch
*gdbarch
= objfile
->arch ();
2608 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2609 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2611 auto_obstack temp_obstack
;
2612 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2614 std::unordered_map
<sect_offset
,
2615 dwarf2_per_cu_data
*,
2616 gdb::hash_enum
<sect_offset
>>
2617 debug_info_offset_to_per_cu
;
2618 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2620 /* A TU will not need aranges, and skipping them here is an easy
2621 way of ignoring .debug_types -- and possibly seeing a
2622 duplicate section offset -- entirely. */
2623 if (per_cu
->is_debug_types
)
2626 const auto insertpair
2627 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2629 if (!insertpair
.second
)
2631 warning (_("Section .debug_aranges in %s has duplicate "
2632 "debug_info_offset %s, ignoring .debug_aranges."),
2633 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2638 section
->read (objfile
);
2640 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2642 const gdb_byte
*addr
= section
->buffer
;
2644 while (addr
< section
->buffer
+ section
->size
)
2646 const gdb_byte
*const entry_addr
= addr
;
2647 unsigned int bytes_read
;
2649 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2653 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2654 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2655 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2656 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2658 warning (_("Section .debug_aranges in %s entry at offset %s "
2659 "length %s exceeds section length %s, "
2660 "ignoring .debug_aranges."),
2661 objfile_name (objfile
),
2662 plongest (entry_addr
- section
->buffer
),
2663 plongest (bytes_read
+ entry_length
),
2664 pulongest (section
->size
));
2668 /* The version number. */
2669 const uint16_t version
= read_2_bytes (abfd
, addr
);
2673 warning (_("Section .debug_aranges in %s entry at offset %s "
2674 "has unsupported version %d, ignoring .debug_aranges."),
2675 objfile_name (objfile
),
2676 plongest (entry_addr
- section
->buffer
), version
);
2680 const uint64_t debug_info_offset
2681 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2682 addr
+= offset_size
;
2683 const auto per_cu_it
2684 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2685 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2687 warning (_("Section .debug_aranges in %s entry at offset %s "
2688 "debug_info_offset %s does not exists, "
2689 "ignoring .debug_aranges."),
2690 objfile_name (objfile
),
2691 plongest (entry_addr
- section
->buffer
),
2692 pulongest (debug_info_offset
));
2695 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2697 const uint8_t address_size
= *addr
++;
2698 if (address_size
< 1 || address_size
> 8)
2700 warning (_("Section .debug_aranges in %s entry at offset %s "
2701 "address_size %u is invalid, ignoring .debug_aranges."),
2702 objfile_name (objfile
),
2703 plongest (entry_addr
- section
->buffer
), address_size
);
2707 const uint8_t segment_selector_size
= *addr
++;
2708 if (segment_selector_size
!= 0)
2710 warning (_("Section .debug_aranges in %s entry at offset %s "
2711 "segment_selector_size %u is not supported, "
2712 "ignoring .debug_aranges."),
2713 objfile_name (objfile
),
2714 plongest (entry_addr
- section
->buffer
),
2715 segment_selector_size
);
2719 /* Must pad to an alignment boundary that is twice the address
2720 size. It is undocumented by the DWARF standard but GCC does
2721 use it. However, not every compiler does this. We can see
2722 whether it has happened by looking at the total length of the
2723 contents of the aranges for this CU -- it if isn't a multiple
2724 of twice the address size, then we skip any leftover
2726 addr
+= (entry_end
- addr
) % (2 * address_size
);
2730 if (addr
+ 2 * address_size
> entry_end
)
2732 warning (_("Section .debug_aranges in %s entry at offset %s "
2733 "address list is not properly terminated, "
2734 "ignoring .debug_aranges."),
2735 objfile_name (objfile
),
2736 plongest (entry_addr
- section
->buffer
));
2739 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2741 addr
+= address_size
;
2742 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2744 addr
+= address_size
;
2745 if (start
== 0 && length
== 0)
2747 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2749 /* Symbol was eliminated due to a COMDAT group. */
2752 ULONGEST end
= start
+ length
;
2753 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2755 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2757 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2761 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2765 /* A helper function that reads the .gdb_index from BUFFER and fills
2766 in MAP. FILENAME is the name of the file containing the data;
2767 it is used for error reporting. DEPRECATED_OK is true if it is
2768 ok to use deprecated sections.
2770 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2771 out parameters that are filled in with information about the CU and
2772 TU lists in the section.
2774 Returns true if all went well, false otherwise. */
2777 read_gdb_index_from_buffer (const char *filename
,
2779 gdb::array_view
<const gdb_byte
> buffer
,
2780 struct mapped_index
*map
,
2781 const gdb_byte
**cu_list
,
2782 offset_type
*cu_list_elements
,
2783 const gdb_byte
**types_list
,
2784 offset_type
*types_list_elements
)
2786 const gdb_byte
*addr
= &buffer
[0];
2787 offset_view
metadata (buffer
);
2789 /* Version check. */
2790 offset_type version
= metadata
[0];
2791 /* Versions earlier than 3 emitted every copy of a psymbol. This
2792 causes the index to behave very poorly for certain requests. Version 3
2793 contained incomplete addrmap. So, it seems better to just ignore such
2797 static int warning_printed
= 0;
2798 if (!warning_printed
)
2800 warning (_("Skipping obsolete .gdb_index section in %s."),
2802 warning_printed
= 1;
2806 /* Index version 4 uses a different hash function than index version
2809 Versions earlier than 6 did not emit psymbols for inlined
2810 functions. Using these files will cause GDB not to be able to
2811 set breakpoints on inlined functions by name, so we ignore these
2812 indices unless the user has done
2813 "set use-deprecated-index-sections on". */
2814 if (version
< 6 && !deprecated_ok
)
2816 static int warning_printed
= 0;
2817 if (!warning_printed
)
2820 Skipping deprecated .gdb_index section in %s.\n\
2821 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2822 to use the section anyway."),
2824 warning_printed
= 1;
2828 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2829 of the TU (for symbols coming from TUs),
2830 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2831 Plus gold-generated indices can have duplicate entries for global symbols,
2832 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2833 These are just performance bugs, and we can't distinguish gdb-generated
2834 indices from gold-generated ones, so issue no warning here. */
2836 /* Indexes with higher version than the one supported by GDB may be no
2837 longer backward compatible. */
2841 map
->version
= version
;
2844 *cu_list
= addr
+ metadata
[i
];
2845 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2848 *types_list
= addr
+ metadata
[i
];
2849 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2852 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2853 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2855 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2858 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2859 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2861 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2865 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2867 if (map
->constant_pool
.empty () && !map
->symbol_table
.empty ())
2869 /* An empty constant pool implies that all symbol table entries are
2870 empty. Make map->symbol_table.empty () == true. */
2872 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2879 /* Callback types for dwarf2_read_gdb_index. */
2881 typedef gdb::function_view
2882 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2883 get_gdb_index_contents_ftype
;
2884 typedef gdb::function_view
2885 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2886 get_gdb_index_contents_dwz_ftype
;
2888 /* Read .gdb_index. If everything went ok, initialize the "quick"
2889 elements of all the CUs and return 1. Otherwise, return 0. */
2892 dwarf2_read_gdb_index
2893 (dwarf2_per_objfile
*per_objfile
,
2894 get_gdb_index_contents_ftype get_gdb_index_contents
,
2895 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2897 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2898 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2899 struct dwz_file
*dwz
;
2900 struct objfile
*objfile
= per_objfile
->objfile
;
2901 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2903 gdb::array_view
<const gdb_byte
> main_index_contents
2904 = get_gdb_index_contents (objfile
, per_bfd
);
2906 if (main_index_contents
.empty ())
2909 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2910 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2911 use_deprecated_index_sections
,
2912 main_index_contents
, map
.get (), &cu_list
,
2913 &cu_list_elements
, &types_list
,
2914 &types_list_elements
))
2917 /* Don't use the index if it's empty. */
2918 if (map
->symbol_table
.empty ())
2921 /* If there is a .dwz file, read it so we can get its CU list as
2923 dwz
= dwarf2_get_dwz_file (per_bfd
);
2926 struct mapped_index dwz_map
;
2927 const gdb_byte
*dwz_types_ignore
;
2928 offset_type dwz_types_elements_ignore
;
2930 gdb::array_view
<const gdb_byte
> dwz_index_content
2931 = get_gdb_index_contents_dwz (objfile
, dwz
);
2933 if (dwz_index_content
.empty ())
2936 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2937 1, dwz_index_content
, &dwz_map
,
2938 &dwz_list
, &dwz_list_elements
,
2940 &dwz_types_elements_ignore
))
2942 warning (_("could not read '.gdb_index' section from %s; skipping"),
2943 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2948 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2951 if (types_list_elements
)
2953 /* We can only handle a single .debug_types when we have an
2955 if (per_bfd
->types
.size () != 1)
2958 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2960 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2961 types_list_elements
);
2964 create_addrmap_from_index (per_objfile
, map
.get ());
2966 per_bfd
->index_table
= std::move (map
);
2967 per_bfd
->using_index
= 1;
2968 per_bfd
->quick_file_names_table
=
2969 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2974 /* die_reader_func for dw2_get_file_names. */
2977 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2978 struct die_info
*comp_unit_die
)
2980 struct dwarf2_cu
*cu
= reader
->cu
;
2981 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2982 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2983 struct dwarf2_per_cu_data
*lh_cu
;
2984 struct attribute
*attr
;
2986 struct quick_file_names
*qfn
;
2988 gdb_assert (! this_cu
->is_debug_types
);
2990 this_cu
->v
.quick
->files_read
= true;
2991 /* Our callers never want to match partial units -- instead they
2992 will match the enclosing full CU. */
2993 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3000 sect_offset line_offset
{};
3002 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3003 if (attr
!= nullptr && attr
->form_is_unsigned ())
3005 struct quick_file_names find_entry
;
3007 line_offset
= (sect_offset
) attr
->as_unsigned ();
3009 /* We may have already read in this line header (TU line header sharing).
3010 If we have we're done. */
3011 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3012 find_entry
.hash
.line_sect_off
= line_offset
;
3013 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3014 &find_entry
, INSERT
);
3017 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3021 lh
= dwarf_decode_line_header (line_offset
, cu
);
3024 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3027 if (strcmp (fnd
.name
, "<unknown>") != 0)
3029 else if (lh
== nullptr)
3032 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3033 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3034 qfn
->hash
.line_sect_off
= line_offset
;
3035 /* There may not be a DW_AT_stmt_list. */
3036 if (slot
!= nullptr)
3039 std::vector
<const char *> include_names
;
3042 for (const auto &entry
: lh
->file_names ())
3044 gdb::unique_xmalloc_ptr
<char> name_holder
;
3045 const char *include_name
=
3046 compute_include_file_name (lh
.get (), entry
, fnd
, &name_holder
);
3047 if (include_name
!= nullptr)
3049 include_name
= per_objfile
->objfile
->intern (include_name
);
3050 include_names
.push_back (include_name
);
3055 qfn
->num_file_names
= offset
+ include_names
.size ();
3056 qfn
->comp_dir
= fnd
.comp_dir
;
3058 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3059 qfn
->num_file_names
);
3061 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3063 if (!include_names
.empty ())
3064 memcpy (&qfn
->file_names
[offset
], include_names
.data (),
3065 include_names
.size () * sizeof (const char *));
3067 qfn
->real_names
= NULL
;
3069 lh_cu
->v
.quick
->file_names
= qfn
;
3072 /* A helper for the "quick" functions which attempts to read the line
3073 table for THIS_CU. */
3075 static struct quick_file_names
*
3076 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3077 dwarf2_per_objfile
*per_objfile
)
3079 /* This should never be called for TUs. */
3080 gdb_assert (! this_cu
->is_debug_types
);
3081 /* Nor type unit groups. */
3082 gdb_assert (! this_cu
->type_unit_group_p ());
3084 if (this_cu
->v
.quick
->files_read
)
3085 return this_cu
->v
.quick
->file_names
;
3087 cutu_reader
reader (this_cu
, per_objfile
);
3088 if (!reader
.dummy_p
)
3089 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3091 return this_cu
->v
.quick
->file_names
;
3094 /* A helper for the "quick" functions which computes and caches the
3095 real path for a given file name from the line table. */
3098 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3099 struct quick_file_names
*qfn
, int index
)
3101 if (qfn
->real_names
== NULL
)
3102 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3103 qfn
->num_file_names
, const char *);
3105 if (qfn
->real_names
[index
] == NULL
)
3107 const char *dirname
= nullptr;
3109 if (!IS_ABSOLUTE_PATH (qfn
->file_names
[index
]))
3110 dirname
= qfn
->comp_dir
;
3112 gdb::unique_xmalloc_ptr
<char> fullname
;
3113 fullname
= find_source_or_rewrite (qfn
->file_names
[index
], dirname
);
3115 qfn
->real_names
[index
] = fullname
.release ();
3118 return qfn
->real_names
[index
];
3122 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3124 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3125 dwarf2_per_cu_data
*dwarf_cu
3126 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3127 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3132 return compunit_primary_filetab (cust
);
3138 dwarf2_per_cu_data::free_cached_file_names ()
3140 if (per_bfd
== nullptr || !per_bfd
->using_index
|| v
.quick
== nullptr)
3143 struct quick_file_names
*file_data
= v
.quick
->file_names
;
3144 if (file_data
!= nullptr && file_data
->real_names
!= nullptr)
3146 for (int i
= 0; i
< file_data
->num_file_names
; ++i
)
3148 xfree ((void *) file_data
->real_names
[i
]);
3149 file_data
->real_names
[i
] = nullptr;
3155 dwarf2_base_index_functions::forget_cached_source_info
3156 (struct objfile
*objfile
)
3158 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3160 for (auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3161 per_cu
->free_cached_file_names ();
3164 /* Struct used to manage iterating over all CUs looking for a symbol. */
3166 struct dw2_symtab_iterator
3168 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3169 dwarf2_per_objfile
*per_objfile
;
3170 /* If set, only look for symbols that match that block. Valid values are
3171 GLOBAL_BLOCK and STATIC_BLOCK. */
3172 gdb::optional
<block_enum
> block_index
;
3173 /* The kind of symbol we're looking for. */
3175 /* The list of CUs from the index entry of the symbol,
3176 or NULL if not found. */
3178 /* The next element in VEC to look at. */
3180 /* The number of elements in VEC, or zero if there is no match. */
3182 /* Have we seen a global version of the symbol?
3183 If so we can ignore all further global instances.
3184 This is to work around gold/15646, inefficient gold-generated
3189 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3192 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3193 dwarf2_per_objfile
*per_objfile
,
3194 gdb::optional
<block_enum
> block_index
,
3195 domain_enum domain
, offset_type namei
)
3197 iter
->per_objfile
= per_objfile
;
3198 iter
->block_index
= block_index
;
3199 iter
->domain
= domain
;
3201 iter
->global_seen
= 0;
3205 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3206 /* index is NULL if OBJF_READNOW. */
3210 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3211 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3213 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3214 iter
->length
= iter
->vec
[0];
3217 /* Return the next matching CU or NULL if there are no more. */
3219 static struct dwarf2_per_cu_data
*
3220 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3222 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3224 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3226 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3227 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3228 gdb_index_symbol_kind symbol_kind
=
3229 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3230 /* Only check the symbol attributes if they're present.
3231 Indices prior to version 7 don't record them,
3232 and indices >= 7 may elide them for certain symbols
3233 (gold does this). */
3235 (per_objfile
->per_bfd
->index_table
->version
>= 7
3236 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3238 /* Don't crash on bad data. */
3239 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3241 complaint (_(".gdb_index entry has bad CU index"
3242 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3246 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3248 /* Skip if already read in. */
3249 if (per_objfile
->symtab_set_p (per_cu
))
3252 /* Check static vs global. */
3255 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3257 if (iter
->block_index
.has_value ())
3259 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3261 if (is_static
!= want_static
)
3265 /* Work around gold/15646. */
3267 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3269 if (iter
->global_seen
)
3272 iter
->global_seen
= 1;
3276 /* Only check the symbol's kind if it has one. */
3279 switch (iter
->domain
)
3282 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3283 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3284 /* Some types are also in VAR_DOMAIN. */
3285 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3289 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3293 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3297 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3313 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3319 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3320 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3323 for (int i
= 0; i
< total
; ++i
)
3325 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3327 if (!per_objfile
->symtab_set_p (per_cu
))
3330 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3331 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3334 /* This dumps minimal information about the index.
3335 It is called via "mt print objfiles".
3336 One use is to verify .gdb_index has been loaded by the
3337 gdb.dwarf2/gdb-index.exp testcase. */
3340 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3342 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3344 gdb_assert (per_objfile
->per_bfd
->using_index
);
3345 printf_filtered (".gdb_index:");
3346 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3348 printf_filtered (" version %d\n",
3349 per_objfile
->per_bfd
->index_table
->version
);
3352 printf_filtered (" faked for \"readnow\"\n");
3353 printf_filtered ("\n");
3357 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3359 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3360 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3362 for (int i
= 0; i
< total_units
; ++i
)
3364 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3366 /* We don't want to directly expand a partial CU, because if we
3367 read it with the wrong language, then assertion failures can
3368 be triggered later on. See PR symtab/23010. So, tell
3369 dw2_instantiate_symtab to skip partial CUs -- any important
3370 partial CU will be read via DW_TAG_imported_unit anyway. */
3371 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3376 dw2_expand_symtabs_matching_symbol
3377 (mapped_index_base
&index
,
3378 const lookup_name_info
&lookup_name_in
,
3379 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3380 gdb::function_view
<bool (offset_type
)> match_callback
,
3381 dwarf2_per_objfile
*per_objfile
);
3384 dw2_expand_symtabs_matching_one
3385 (dwarf2_per_cu_data
*per_cu
,
3386 dwarf2_per_objfile
*per_objfile
,
3387 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3388 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3391 dwarf2_gdb_index::expand_matching_symbols
3392 (struct objfile
*objfile
,
3393 const lookup_name_info
&name
, domain_enum domain
,
3395 symbol_compare_ftype
*ordered_compare
)
3398 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3400 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3402 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3404 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3406 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3407 auto matcher
= [&] (const char *symname
)
3409 if (ordered_compare
== nullptr)
3411 return ordered_compare (symname
, match_name
) == 0;
3414 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3415 [&] (offset_type namei
)
3417 struct dw2_symtab_iterator iter
;
3418 struct dwarf2_per_cu_data
*per_cu
;
3420 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3422 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3423 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3430 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3431 proceed assuming all symtabs have been read in. */
3435 /* Starting from a search name, return the string that finds the upper
3436 bound of all strings that start with SEARCH_NAME in a sorted name
3437 list. Returns the empty string to indicate that the upper bound is
3438 the end of the list. */
3441 make_sort_after_prefix_name (const char *search_name
)
3443 /* When looking to complete "func", we find the upper bound of all
3444 symbols that start with "func" by looking for where we'd insert
3445 the closest string that would follow "func" in lexicographical
3446 order. Usually, that's "func"-with-last-character-incremented,
3447 i.e. "fund". Mind non-ASCII characters, though. Usually those
3448 will be UTF-8 multi-byte sequences, but we can't be certain.
3449 Especially mind the 0xff character, which is a valid character in
3450 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3451 rule out compilers allowing it in identifiers. Note that
3452 conveniently, strcmp/strcasecmp are specified to compare
3453 characters interpreted as unsigned char. So what we do is treat
3454 the whole string as a base 256 number composed of a sequence of
3455 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3456 to 0, and carries 1 to the following more-significant position.
3457 If the very first character in SEARCH_NAME ends up incremented
3458 and carries/overflows, then the upper bound is the end of the
3459 list. The string after the empty string is also the empty
3462 Some examples of this operation:
3464 SEARCH_NAME => "+1" RESULT
3468 "\xff" "a" "\xff" => "\xff" "b"
3473 Then, with these symbols for example:
3479 completing "func" looks for symbols between "func" and
3480 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3481 which finds "func" and "func1", but not "fund".
3485 funcÿ (Latin1 'ÿ' [0xff])
3489 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3490 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3494 ÿÿ (Latin1 'ÿ' [0xff])
3497 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3498 the end of the list.
3500 std::string after
= search_name
;
3501 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3503 if (!after
.empty ())
3504 after
.back () = (unsigned char) after
.back () + 1;
3508 /* See declaration. */
3510 std::pair
<std::vector
<name_component
>::const_iterator
,
3511 std::vector
<name_component
>::const_iterator
>
3512 mapped_index_base::find_name_components_bounds
3513 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3514 dwarf2_per_objfile
*per_objfile
) const
3517 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3519 const char *lang_name
3520 = lookup_name_without_params
.language_lookup_name (lang
);
3522 /* Comparison function object for lower_bound that matches against a
3523 given symbol name. */
3524 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3527 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3528 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3529 return name_cmp (elem_name
, name
) < 0;
3532 /* Comparison function object for upper_bound that matches against a
3533 given symbol name. */
3534 auto lookup_compare_upper
= [&] (const char *name
,
3535 const name_component
&elem
)
3537 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3538 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3539 return name_cmp (name
, elem_name
) < 0;
3542 auto begin
= this->name_components
.begin ();
3543 auto end
= this->name_components
.end ();
3545 /* Find the lower bound. */
3548 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3551 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3554 /* Find the upper bound. */
3557 if (lookup_name_without_params
.completion_mode ())
3559 /* In completion mode, we want UPPER to point past all
3560 symbols names that have the same prefix. I.e., with
3561 these symbols, and completing "func":
3563 function << lower bound
3565 other_function << upper bound
3567 We find the upper bound by looking for the insertion
3568 point of "func"-with-last-character-incremented,
3570 std::string after
= make_sort_after_prefix_name (lang_name
);
3573 return std::lower_bound (lower
, end
, after
.c_str (),
3574 lookup_compare_lower
);
3577 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3580 return {lower
, upper
};
3583 /* See declaration. */
3586 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3588 if (!this->name_components
.empty ())
3591 this->name_components_casing
= case_sensitivity
;
3593 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3595 /* The code below only knows how to break apart components of C++
3596 symbol names (and other languages that use '::' as
3597 namespace/module separator) and Ada symbol names. */
3598 auto count
= this->symbol_name_count ();
3599 for (offset_type idx
= 0; idx
< count
; idx
++)
3601 if (this->symbol_name_slot_invalid (idx
))
3604 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3606 /* Add each name component to the name component table. */
3607 unsigned int previous_len
= 0;
3609 if (strstr (name
, "::") != nullptr)
3611 for (unsigned int current_len
= cp_find_first_component (name
);
3612 name
[current_len
] != '\0';
3613 current_len
+= cp_find_first_component (name
+ current_len
))
3615 gdb_assert (name
[current_len
] == ':');
3616 this->name_components
.push_back ({previous_len
, idx
});
3617 /* Skip the '::'. */
3619 previous_len
= current_len
;
3624 /* Handle the Ada encoded (aka mangled) form here. */
3625 for (const char *iter
= strstr (name
, "__");
3627 iter
= strstr (iter
, "__"))
3629 this->name_components
.push_back ({previous_len
, idx
});
3631 previous_len
= iter
- name
;
3635 this->name_components
.push_back ({previous_len
, idx
});
3638 /* Sort name_components elements by name. */
3639 auto name_comp_compare
= [&] (const name_component
&left
,
3640 const name_component
&right
)
3642 const char *left_qualified
3643 = this->symbol_name_at (left
.idx
, per_objfile
);
3644 const char *right_qualified
3645 = this->symbol_name_at (right
.idx
, per_objfile
);
3647 const char *left_name
= left_qualified
+ left
.name_offset
;
3648 const char *right_name
= right_qualified
+ right
.name_offset
;
3650 return name_cmp (left_name
, right_name
) < 0;
3653 std::sort (this->name_components
.begin (),
3654 this->name_components
.end (),
3658 /* Helper for dw2_expand_symtabs_matching that works with a
3659 mapped_index_base instead of the containing objfile. This is split
3660 to a separate function in order to be able to unit test the
3661 name_components matching using a mock mapped_index_base. For each
3662 symbol name that matches, calls MATCH_CALLBACK, passing it the
3663 symbol's index in the mapped_index_base symbol table. */
3666 dw2_expand_symtabs_matching_symbol
3667 (mapped_index_base
&index
,
3668 const lookup_name_info
&lookup_name_in
,
3669 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3670 gdb::function_view
<bool (offset_type
)> match_callback
,
3671 dwarf2_per_objfile
*per_objfile
)
3673 lookup_name_info lookup_name_without_params
3674 = lookup_name_in
.make_ignore_params ();
3676 /* Build the symbol name component sorted vector, if we haven't
3678 index
.build_name_components (per_objfile
);
3680 /* The same symbol may appear more than once in the range though.
3681 E.g., if we're looking for symbols that complete "w", and we have
3682 a symbol named "w1::w2", we'll find the two name components for
3683 that same symbol in the range. To be sure we only call the
3684 callback once per symbol, we first collect the symbol name
3685 indexes that matched in a temporary vector and ignore
3687 std::vector
<offset_type
> matches
;
3689 struct name_and_matcher
3691 symbol_name_matcher_ftype
*matcher
;
3694 bool operator== (const name_and_matcher
&other
) const
3696 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3700 /* A vector holding all the different symbol name matchers, for all
3702 std::vector
<name_and_matcher
> matchers
;
3704 for (int i
= 0; i
< nr_languages
; i
++)
3706 enum language lang_e
= (enum language
) i
;
3708 const language_defn
*lang
= language_def (lang_e
);
3709 symbol_name_matcher_ftype
*name_matcher
3710 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3712 name_and_matcher key
{
3714 lookup_name_without_params
.language_lookup_name (lang_e
)
3717 /* Don't insert the same comparison routine more than once.
3718 Note that we do this linear walk. This is not a problem in
3719 practice because the number of supported languages is
3721 if (std::find (matchers
.begin (), matchers
.end (), key
)
3724 matchers
.push_back (std::move (key
));
3727 = index
.find_name_components_bounds (lookup_name_without_params
,
3728 lang_e
, per_objfile
);
3730 /* Now for each symbol name in range, check to see if we have a name
3731 match, and if so, call the MATCH_CALLBACK callback. */
3733 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3735 const char *qualified
3736 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3738 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3739 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3742 matches
.push_back (bounds
.first
->idx
);
3746 std::sort (matches
.begin (), matches
.end ());
3748 /* Finally call the callback, once per match. */
3751 for (offset_type idx
: matches
)
3755 if (!match_callback (idx
))
3764 /* Above we use a type wider than idx's for 'prev', since 0 and
3765 (offset_type)-1 are both possible values. */
3766 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3773 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3775 /* A mock .gdb_index/.debug_names-like name index table, enough to
3776 exercise dw2_expand_symtabs_matching_symbol, which works with the
3777 mapped_index_base interface. Builds an index from the symbol list
3778 passed as parameter to the constructor. */
3779 class mock_mapped_index
: public mapped_index_base
3782 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3783 : m_symbol_table (symbols
)
3786 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3788 /* Return the number of names in the symbol table. */
3789 size_t symbol_name_count () const override
3791 return m_symbol_table
.size ();
3794 /* Get the name of the symbol at IDX in the symbol table. */
3795 const char *symbol_name_at
3796 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3798 return m_symbol_table
[idx
];
3802 gdb::array_view
<const char *> m_symbol_table
;
3805 /* Convenience function that converts a NULL pointer to a "<null>"
3806 string, to pass to print routines. */
3809 string_or_null (const char *str
)
3811 return str
!= NULL
? str
: "<null>";
3814 /* Check if a lookup_name_info built from
3815 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3816 index. EXPECTED_LIST is the list of expected matches, in expected
3817 matching order. If no match expected, then an empty list is
3818 specified. Returns true on success. On failure prints a warning
3819 indicating the file:line that failed, and returns false. */
3822 check_match (const char *file
, int line
,
3823 mock_mapped_index
&mock_index
,
3824 const char *name
, symbol_name_match_type match_type
,
3825 bool completion_mode
,
3826 std::initializer_list
<const char *> expected_list
,
3827 dwarf2_per_objfile
*per_objfile
)
3829 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3831 bool matched
= true;
3833 auto mismatch
= [&] (const char *expected_str
,
3836 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3837 "expected=\"%s\", got=\"%s\"\n"),
3839 (match_type
== symbol_name_match_type::FULL
3841 name
, string_or_null (expected_str
), string_or_null (got
));
3845 auto expected_it
= expected_list
.begin ();
3846 auto expected_end
= expected_list
.end ();
3848 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3850 [&] (offset_type idx
)
3852 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3853 const char *expected_str
3854 = expected_it
== expected_end
? NULL
: *expected_it
++;
3856 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3857 mismatch (expected_str
, matched_name
);
3861 const char *expected_str
3862 = expected_it
== expected_end
? NULL
: *expected_it
++;
3863 if (expected_str
!= NULL
)
3864 mismatch (expected_str
, NULL
);
3869 /* The symbols added to the mock mapped_index for testing (in
3871 static const char *test_symbols
[] = {
3880 "ns2::tmpl<int>::foo2",
3881 "(anonymous namespace)::A::B::C",
3883 /* These are used to check that the increment-last-char in the
3884 matching algorithm for completion doesn't match "t1_fund" when
3885 completing "t1_func". */
3891 /* A UTF-8 name with multi-byte sequences to make sure that
3892 cp-name-parser understands this as a single identifier ("função"
3893 is "function" in PT). */
3896 /* \377 (0xff) is Latin1 'ÿ'. */
3899 /* \377 (0xff) is Latin1 'ÿ'. */
3903 /* A name with all sorts of complications. Starts with "z" to make
3904 it easier for the completion tests below. */
3905 #define Z_SYM_NAME \
3906 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3907 "::tuple<(anonymous namespace)::ui*, " \
3908 "std::default_delete<(anonymous namespace)::ui>, void>"
3913 /* Returns true if the mapped_index_base::find_name_component_bounds
3914 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3915 in completion mode. */
3918 check_find_bounds_finds (mapped_index_base
&index
,
3919 const char *search_name
,
3920 gdb::array_view
<const char *> expected_syms
,
3921 dwarf2_per_objfile
*per_objfile
)
3923 lookup_name_info
lookup_name (search_name
,
3924 symbol_name_match_type::FULL
, true);
3926 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3930 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3931 if (distance
!= expected_syms
.size ())
3934 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3936 auto nc_elem
= bounds
.first
+ exp_elem
;
3937 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3938 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3945 /* Test the lower-level mapped_index::find_name_component_bounds
3949 test_mapped_index_find_name_component_bounds ()
3951 mock_mapped_index
mock_index (test_symbols
);
3953 mock_index
.build_name_components (NULL
/* per_objfile */);
3955 /* Test the lower-level mapped_index::find_name_component_bounds
3956 method in completion mode. */
3958 static const char *expected_syms
[] = {
3963 SELF_CHECK (check_find_bounds_finds
3964 (mock_index
, "t1_func", expected_syms
,
3965 NULL
/* per_objfile */));
3968 /* Check that the increment-last-char in the name matching algorithm
3969 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3971 static const char *expected_syms1
[] = {
3975 SELF_CHECK (check_find_bounds_finds
3976 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3978 static const char *expected_syms2
[] = {
3981 SELF_CHECK (check_find_bounds_finds
3982 (mock_index
, "\377\377", expected_syms2
,
3983 NULL
/* per_objfile */));
3987 /* Test dw2_expand_symtabs_matching_symbol. */
3990 test_dw2_expand_symtabs_matching_symbol ()
3992 mock_mapped_index
mock_index (test_symbols
);
3994 /* We let all tests run until the end even if some fails, for debug
3996 bool any_mismatch
= false;
3998 /* Create the expected symbols list (an initializer_list). Needed
3999 because lists have commas, and we need to pass them to CHECK,
4000 which is a macro. */
4001 #define EXPECT(...) { __VA_ARGS__ }
4003 /* Wrapper for check_match that passes down the current
4004 __FILE__/__LINE__. */
4005 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4006 any_mismatch |= !check_match (__FILE__, __LINE__, \
4008 NAME, MATCH_TYPE, COMPLETION_MODE, \
4009 EXPECTED_LIST, NULL)
4011 /* Identity checks. */
4012 for (const char *sym
: test_symbols
)
4014 /* Should be able to match all existing symbols. */
4015 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4018 /* Should be able to match all existing symbols with
4020 std::string with_params
= std::string (sym
) + "(int)";
4021 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4024 /* Should be able to match all existing symbols with
4025 parameters and qualifiers. */
4026 with_params
= std::string (sym
) + " ( int ) const";
4027 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4030 /* This should really find sym, but cp-name-parser.y doesn't
4031 know about lvalue/rvalue qualifiers yet. */
4032 with_params
= std::string (sym
) + " ( int ) &&";
4033 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4037 /* Check that the name matching algorithm for completion doesn't get
4038 confused with Latin1 'ÿ' / 0xff. */
4040 static const char str
[] = "\377";
4041 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4042 EXPECT ("\377", "\377\377123"));
4045 /* Check that the increment-last-char in the matching algorithm for
4046 completion doesn't match "t1_fund" when completing "t1_func". */
4048 static const char str
[] = "t1_func";
4049 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4050 EXPECT ("t1_func", "t1_func1"));
4053 /* Check that completion mode works at each prefix of the expected
4056 static const char str
[] = "function(int)";
4057 size_t len
= strlen (str
);
4060 for (size_t i
= 1; i
< len
; i
++)
4062 lookup
.assign (str
, i
);
4063 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4064 EXPECT ("function"));
4068 /* While "w" is a prefix of both components, the match function
4069 should still only be called once. */
4071 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4073 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4077 /* Same, with a "complicated" symbol. */
4079 static const char str
[] = Z_SYM_NAME
;
4080 size_t len
= strlen (str
);
4083 for (size_t i
= 1; i
< len
; i
++)
4085 lookup
.assign (str
, i
);
4086 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4087 EXPECT (Z_SYM_NAME
));
4091 /* In FULL mode, an incomplete symbol doesn't match. */
4093 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4097 /* A complete symbol with parameters matches any overload, since the
4098 index has no overload info. */
4100 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4101 EXPECT ("std::zfunction", "std::zfunction2"));
4102 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4103 EXPECT ("std::zfunction", "std::zfunction2"));
4104 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4105 EXPECT ("std::zfunction", "std::zfunction2"));
4108 /* Check that whitespace is ignored appropriately. A symbol with a
4109 template argument list. */
4111 static const char expected
[] = "ns::foo<int>";
4112 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4114 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4118 /* Check that whitespace is ignored appropriately. A symbol with a
4119 template argument list that includes a pointer. */
4121 static const char expected
[] = "ns::foo<char*>";
4122 /* Try both completion and non-completion modes. */
4123 static const bool completion_mode
[2] = {false, true};
4124 for (size_t i
= 0; i
< 2; i
++)
4126 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4127 completion_mode
[i
], EXPECT (expected
));
4128 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4129 completion_mode
[i
], EXPECT (expected
));
4131 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4132 completion_mode
[i
], EXPECT (expected
));
4133 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4134 completion_mode
[i
], EXPECT (expected
));
4139 /* Check method qualifiers are ignored. */
4140 static const char expected
[] = "ns::foo<char*>";
4141 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4142 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4143 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4144 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4145 CHECK_MATCH ("foo < char * > ( int ) const",
4146 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4147 CHECK_MATCH ("foo < char * > ( int ) &&",
4148 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4151 /* Test lookup names that don't match anything. */
4153 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4156 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4160 /* Some wild matching tests, exercising "(anonymous namespace)",
4161 which should not be confused with a parameter list. */
4163 static const char *syms
[] = {
4167 "A :: B :: C ( int )",
4172 for (const char *s
: syms
)
4174 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4175 EXPECT ("(anonymous namespace)::A::B::C"));
4180 static const char expected
[] = "ns2::tmpl<int>::foo2";
4181 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4183 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4187 SELF_CHECK (!any_mismatch
);
4196 test_mapped_index_find_name_component_bounds ();
4197 test_dw2_expand_symtabs_matching_symbol ();
4200 }} // namespace selftests::dw2_expand_symtabs_matching
4202 #endif /* GDB_SELF_TEST */
4204 /* If FILE_MATCHER is NULL or if PER_CU has
4205 dwarf2_per_cu_quick_data::MARK set (see
4206 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4207 EXPANSION_NOTIFY on it. */
4210 dw2_expand_symtabs_matching_one
4211 (dwarf2_per_cu_data
*per_cu
,
4212 dwarf2_per_objfile
*per_objfile
,
4213 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4214 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4216 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4218 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4220 compunit_symtab
*symtab
4221 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4222 gdb_assert (symtab
!= nullptr);
4224 if (expansion_notify
!= NULL
&& symtab_was_null
)
4225 return expansion_notify (symtab
);
4230 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4231 matched, to expand corresponding CUs that were marked. IDX is the
4232 index of the symbol name that matched. */
4235 dw2_expand_marked_cus
4236 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4237 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4238 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4239 block_search_flags search_flags
,
4242 offset_type vec_len
, vec_idx
;
4243 bool global_seen
= false;
4244 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4246 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4248 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4250 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4251 /* This value is only valid for index versions >= 7. */
4252 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4253 gdb_index_symbol_kind symbol_kind
=
4254 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4255 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4256 /* Only check the symbol attributes if they're present.
4257 Indices prior to version 7 don't record them,
4258 and indices >= 7 may elide them for certain symbols
4259 (gold does this). */
4262 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4264 /* Work around gold/15646. */
4267 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4275 /* Only check the symbol's kind if it has one. */
4280 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4285 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4291 case VARIABLES_DOMAIN
:
4292 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4295 case FUNCTIONS_DOMAIN
:
4296 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4300 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4303 case MODULES_DOMAIN
:
4304 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4312 /* Don't crash on bad data. */
4313 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4315 complaint (_(".gdb_index entry has bad CU index"
4316 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4320 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4321 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4329 /* If FILE_MATCHER is non-NULL, set all the
4330 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4331 that match FILE_MATCHER. */
4334 dw_expand_symtabs_matching_file_matcher
4335 (dwarf2_per_objfile
*per_objfile
,
4336 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4338 if (file_matcher
== NULL
)
4341 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4343 NULL
, xcalloc
, xfree
));
4344 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4346 NULL
, xcalloc
, xfree
));
4348 /* The rule is CUs specify all the files, including those used by
4349 any TU, so there's no need to scan TUs here. */
4351 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4355 if (per_cu
->is_debug_types
)
4357 per_cu
->v
.quick
->mark
= 0;
4359 /* We only need to look at symtabs not already expanded. */
4360 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4363 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4365 if (file_data
== NULL
)
4368 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4370 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4372 per_cu
->v
.quick
->mark
= 1;
4376 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4378 const char *this_real_name
;
4380 if (file_matcher (file_data
->file_names
[j
], false))
4382 per_cu
->v
.quick
->mark
= 1;
4386 /* Before we invoke realpath, which can get expensive when many
4387 files are involved, do a quick comparison of the basenames. */
4388 if (!basenames_may_differ
4389 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4393 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4394 if (file_matcher (this_real_name
, false))
4396 per_cu
->v
.quick
->mark
= 1;
4401 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4402 ? visited_found
.get ()
4403 : visited_not_found
.get (),
4410 dwarf2_gdb_index::expand_symtabs_matching
4411 (struct objfile
*objfile
,
4412 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4413 const lookup_name_info
*lookup_name
,
4414 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4415 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4416 block_search_flags search_flags
,
4418 enum search_domain kind
)
4420 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4422 /* index_table is NULL if OBJF_READNOW. */
4423 if (!per_objfile
->per_bfd
->index_table
)
4426 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4428 /* This invariant is documented in quick-functions.h. */
4429 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
4430 if (lookup_name
== nullptr)
4432 for (dwarf2_per_cu_data
*per_cu
4433 : all_comp_units_range (per_objfile
->per_bfd
))
4437 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4445 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4448 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4450 [&] (offset_type idx
)
4452 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4453 expansion_notify
, search_flags
, kind
))
4461 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4464 static struct compunit_symtab
*
4465 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4470 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4471 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4474 if (cust
->includes
== NULL
)
4477 for (i
= 0; cust
->includes
[i
]; ++i
)
4479 struct compunit_symtab
*s
= cust
->includes
[i
];
4481 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4489 struct compunit_symtab
*
4490 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4491 (struct objfile
*objfile
,
4492 struct bound_minimal_symbol msymbol
,
4494 struct obj_section
*section
,
4497 struct dwarf2_per_cu_data
*data
;
4498 struct compunit_symtab
*result
;
4500 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4501 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4504 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4505 data
= ((struct dwarf2_per_cu_data
*)
4506 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4511 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4512 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4513 paddress (objfile
->arch (), pc
));
4515 result
= recursively_find_pc_sect_compunit_symtab
4516 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4518 gdb_assert (result
!= NULL
);
4523 dwarf2_base_index_functions::map_symbol_filenames
4524 (struct objfile
*objfile
,
4525 gdb::function_view
<symbol_filename_ftype
> fun
,
4528 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4530 /* Use caches to ensure we only call FUN once for each filename. */
4531 filename_seen_cache filenames_cache
;
4532 std::unordered_set
<quick_file_names
*> qfn_cache
;
4534 /* The rule is CUs specify all the files, including those used by any TU,
4535 so there's no need to scan TUs here. We can ignore file names coming
4536 from already-expanded CUs. It is possible that an expanded CU might
4537 reuse the file names data from a currently unexpanded CU, in this
4538 case we don't want to report the files from the unexpanded CU. */
4540 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4542 if (!per_cu
->is_debug_types
4543 && per_objfile
->symtab_set_p (per_cu
.get ()))
4545 if (per_cu
->v
.quick
->file_names
!= nullptr)
4546 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4550 for (dwarf2_per_cu_data
*per_cu
4551 : all_comp_units_range (per_objfile
->per_bfd
))
4553 /* We only need to look at symtabs not already expanded. */
4554 if (per_cu
->is_debug_types
|| per_objfile
->symtab_set_p (per_cu
))
4557 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4558 if (file_data
== nullptr
4559 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4562 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4564 const char *filename
= file_data
->file_names
[j
];
4565 const char *key
= filename
;
4566 const char *fullname
= nullptr;
4570 fullname
= dw2_get_real_path (per_objfile
, file_data
, j
);
4574 if (!filenames_cache
.seen (key
))
4575 fun (filename
, fullname
);
4581 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4586 /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */
4589 dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile
*objfile
)
4591 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4593 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4595 /* Is this already expanded? */
4596 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4599 /* It has not yet been expanded. */
4606 /* DWARF-5 debug_names reader. */
4608 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4609 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4611 /* A helper function that reads the .debug_names section in SECTION
4612 and fills in MAP. FILENAME is the name of the file containing the
4613 section; it is used for error reporting.
4615 Returns true if all went well, false otherwise. */
4618 read_debug_names_from_section (struct objfile
*objfile
,
4619 const char *filename
,
4620 struct dwarf2_section_info
*section
,
4621 mapped_debug_names
&map
)
4623 if (section
->empty ())
4626 /* Older elfutils strip versions could keep the section in the main
4627 executable while splitting it for the separate debug info file. */
4628 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4631 section
->read (objfile
);
4633 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4635 const gdb_byte
*addr
= section
->buffer
;
4637 bfd
*const abfd
= section
->get_bfd_owner ();
4639 unsigned int bytes_read
;
4640 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4643 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4644 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4645 if (bytes_read
+ length
!= section
->size
)
4647 /* There may be multiple per-CU indices. */
4648 warning (_("Section .debug_names in %s length %s does not match "
4649 "section length %s, ignoring .debug_names."),
4650 filename
, plongest (bytes_read
+ length
),
4651 pulongest (section
->size
));
4655 /* The version number. */
4656 uint16_t version
= read_2_bytes (abfd
, addr
);
4660 warning (_("Section .debug_names in %s has unsupported version %d, "
4661 "ignoring .debug_names."),
4667 uint16_t padding
= read_2_bytes (abfd
, addr
);
4671 warning (_("Section .debug_names in %s has unsupported padding %d, "
4672 "ignoring .debug_names."),
4677 /* comp_unit_count - The number of CUs in the CU list. */
4678 map
.cu_count
= read_4_bytes (abfd
, addr
);
4681 /* local_type_unit_count - The number of TUs in the local TU
4683 map
.tu_count
= read_4_bytes (abfd
, addr
);
4686 /* foreign_type_unit_count - The number of TUs in the foreign TU
4688 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4690 if (foreign_tu_count
!= 0)
4692 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4693 "ignoring .debug_names."),
4694 filename
, static_cast<unsigned long> (foreign_tu_count
));
4698 /* bucket_count - The number of hash buckets in the hash lookup
4700 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4703 /* name_count - The number of unique names in the index. */
4704 map
.name_count
= read_4_bytes (abfd
, addr
);
4707 /* abbrev_table_size - The size in bytes of the abbreviations
4709 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4712 /* augmentation_string_size - The size in bytes of the augmentation
4713 string. This value is rounded up to a multiple of 4. */
4714 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4716 map
.augmentation_is_gdb
= ((augmentation_string_size
4717 == sizeof (dwarf5_augmentation
))
4718 && memcmp (addr
, dwarf5_augmentation
,
4719 sizeof (dwarf5_augmentation
)) == 0);
4720 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4721 addr
+= augmentation_string_size
;
4724 map
.cu_table_reordered
= addr
;
4725 addr
+= map
.cu_count
* map
.offset_size
;
4727 /* List of Local TUs */
4728 map
.tu_table_reordered
= addr
;
4729 addr
+= map
.tu_count
* map
.offset_size
;
4731 /* Hash Lookup Table */
4732 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4733 addr
+= map
.bucket_count
* 4;
4734 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4735 addr
+= map
.name_count
* 4;
4738 map
.name_table_string_offs_reordered
= addr
;
4739 addr
+= map
.name_count
* map
.offset_size
;
4740 map
.name_table_entry_offs_reordered
= addr
;
4741 addr
+= map
.name_count
* map
.offset_size
;
4743 const gdb_byte
*abbrev_table_start
= addr
;
4746 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4751 const auto insertpair
4752 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4753 if (!insertpair
.second
)
4755 warning (_("Section .debug_names in %s has duplicate index %s, "
4756 "ignoring .debug_names."),
4757 filename
, pulongest (index_num
));
4760 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4761 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4766 mapped_debug_names::index_val::attr attr
;
4767 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4769 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4771 if (attr
.form
== DW_FORM_implicit_const
)
4773 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4777 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4779 indexval
.attr_vec
.push_back (std::move (attr
));
4782 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4784 warning (_("Section .debug_names in %s has abbreviation_table "
4785 "of size %s vs. written as %u, ignoring .debug_names."),
4786 filename
, plongest (addr
- abbrev_table_start
),
4790 map
.entry_pool
= addr
;
4795 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4799 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4800 const mapped_debug_names
&map
,
4801 dwarf2_section_info
§ion
,
4804 if (!map
.augmentation_is_gdb
)
4806 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4808 sect_offset sect_off
4809 = (sect_offset
) (extract_unsigned_integer
4810 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4812 map
.dwarf5_byte_order
));
4813 /* We don't know the length of the CU, because the CU list in a
4814 .debug_names index can be incomplete, so we can't use the start
4815 of the next CU as end of this CU. We create the CUs here with
4816 length 0, and in cutu_reader::cutu_reader we'll fill in the
4818 dwarf2_per_cu_data_up per_cu
4819 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4821 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4826 sect_offset sect_off_prev
;
4827 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4829 sect_offset sect_off_next
;
4830 if (i
< map
.cu_count
)
4833 = (sect_offset
) (extract_unsigned_integer
4834 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4836 map
.dwarf5_byte_order
));
4839 sect_off_next
= (sect_offset
) section
.size
;
4842 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4843 dwarf2_per_cu_data_up per_cu
4844 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4845 sect_off_prev
, length
);
4846 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4848 sect_off_prev
= sect_off_next
;
4852 /* Read the CU list from the mapped index, and use it to create all
4853 the CU objects for this dwarf2_per_objfile. */
4856 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4857 const mapped_debug_names
&map
,
4858 const mapped_debug_names
&dwz_map
)
4860 gdb_assert (per_bfd
->all_comp_units
.empty ());
4861 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4863 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4864 false /* is_dwz */);
4866 if (dwz_map
.cu_count
== 0)
4869 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4870 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4874 /* Read .debug_names. If everything went ok, initialize the "quick"
4875 elements of all the CUs and return true. Otherwise, return false. */
4878 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4880 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4881 mapped_debug_names dwz_map
;
4882 struct objfile
*objfile
= per_objfile
->objfile
;
4883 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4885 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4886 &per_bfd
->debug_names
, *map
))
4889 /* Don't use the index if it's empty. */
4890 if (map
->name_count
== 0)
4893 /* If there is a .dwz file, read it so we can get its CU list as
4895 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4898 if (!read_debug_names_from_section (objfile
,
4899 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4900 &dwz
->debug_names
, dwz_map
))
4902 warning (_("could not read '.debug_names' section from %s; skipping"),
4903 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4908 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4910 if (map
->tu_count
!= 0)
4912 /* We can only handle a single .debug_types when we have an
4914 if (per_bfd
->types
.size () != 1)
4917 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4919 create_signatured_type_table_from_debug_names
4920 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4923 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4925 per_bfd
->debug_names_table
= std::move (map
);
4926 per_bfd
->using_index
= 1;
4927 per_bfd
->quick_file_names_table
=
4928 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4933 /* Type used to manage iterating over all CUs looking for a symbol for
4936 class dw2_debug_names_iterator
4939 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4940 block_search_flags block_index
,
4942 const char *name
, dwarf2_per_objfile
*per_objfile
)
4943 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4944 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4945 m_per_objfile (per_objfile
)
4948 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4949 search_domain search
, uint32_t namei
,
4950 dwarf2_per_objfile
*per_objfile
,
4951 domain_enum domain
= UNDEF_DOMAIN
)
4955 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4956 m_per_objfile (per_objfile
)
4959 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4960 block_search_flags block_index
, domain_enum domain
,
4961 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4962 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4963 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4964 m_per_objfile (per_objfile
)
4967 /* Return the next matching CU or NULL if there are no more. */
4968 dwarf2_per_cu_data
*next ();
4971 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4973 dwarf2_per_objfile
*per_objfile
);
4974 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4976 dwarf2_per_objfile
*per_objfile
);
4978 /* The internalized form of .debug_names. */
4979 const mapped_debug_names
&m_map
;
4981 /* Restrict the search to these blocks. */
4982 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4983 | SEARCH_STATIC_BLOCK
);
4985 /* The kind of symbol we're looking for. */
4986 const domain_enum m_domain
= UNDEF_DOMAIN
;
4987 const search_domain m_search
= ALL_DOMAIN
;
4989 /* The list of CUs from the index entry of the symbol, or NULL if
4991 const gdb_byte
*m_addr
;
4993 dwarf2_per_objfile
*m_per_objfile
;
4997 mapped_debug_names::namei_to_name
4998 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5000 const ULONGEST namei_string_offs
5001 = extract_unsigned_integer ((name_table_string_offs_reordered
5002 + namei
* offset_size
),
5005 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5008 /* Find a slot in .debug_names for the object named NAME. If NAME is
5009 found, return pointer to its pool data. If NAME cannot be found,
5013 dw2_debug_names_iterator::find_vec_in_debug_names
5014 (const mapped_debug_names
&map
, const char *name
,
5015 dwarf2_per_objfile
*per_objfile
)
5017 int (*cmp
) (const char *, const char *);
5019 gdb::unique_xmalloc_ptr
<char> without_params
;
5020 if (current_language
->la_language
== language_cplus
5021 || current_language
->la_language
== language_fortran
5022 || current_language
->la_language
== language_d
)
5024 /* NAME is already canonical. Drop any qualifiers as
5025 .debug_names does not contain any. */
5027 if (strchr (name
, '(') != NULL
)
5029 without_params
= cp_remove_params (name
);
5030 if (without_params
!= NULL
)
5031 name
= without_params
.get ();
5035 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5037 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5039 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5040 (map
.bucket_table_reordered
5041 + (full_hash
% map
.bucket_count
)), 4,
5042 map
.dwarf5_byte_order
);
5046 if (namei
>= map
.name_count
)
5048 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5050 namei
, map
.name_count
,
5051 objfile_name (per_objfile
->objfile
));
5057 const uint32_t namei_full_hash
5058 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5059 (map
.hash_table_reordered
+ namei
), 4,
5060 map
.dwarf5_byte_order
);
5061 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5064 if (full_hash
== namei_full_hash
)
5066 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5068 #if 0 /* An expensive sanity check. */
5069 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5071 complaint (_("Wrong .debug_names hash for string at index %u "
5073 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5078 if (cmp (namei_string
, name
) == 0)
5080 const ULONGEST namei_entry_offs
5081 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5082 + namei
* map
.offset_size
),
5083 map
.offset_size
, map
.dwarf5_byte_order
);
5084 return map
.entry_pool
+ namei_entry_offs
;
5089 if (namei
>= map
.name_count
)
5095 dw2_debug_names_iterator::find_vec_in_debug_names
5096 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5098 if (namei
>= map
.name_count
)
5100 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5102 namei
, map
.name_count
,
5103 objfile_name (per_objfile
->objfile
));
5107 const ULONGEST namei_entry_offs
5108 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5109 + namei
* map
.offset_size
),
5110 map
.offset_size
, map
.dwarf5_byte_order
);
5111 return map
.entry_pool
+ namei_entry_offs
;
5114 /* See dw2_debug_names_iterator. */
5116 dwarf2_per_cu_data
*
5117 dw2_debug_names_iterator::next ()
5122 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5123 struct objfile
*objfile
= m_per_objfile
->objfile
;
5124 bfd
*const abfd
= objfile
->obfd
;
5128 unsigned int bytes_read
;
5129 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5130 m_addr
+= bytes_read
;
5134 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5135 if (indexval_it
== m_map
.abbrev_map
.cend ())
5137 complaint (_("Wrong .debug_names undefined abbrev code %s "
5139 pulongest (abbrev
), objfile_name (objfile
));
5142 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5143 enum class symbol_linkage
{
5147 } symbol_linkage_
= symbol_linkage::unknown
;
5148 dwarf2_per_cu_data
*per_cu
= NULL
;
5149 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5154 case DW_FORM_implicit_const
:
5155 ull
= attr
.implicit_const
;
5157 case DW_FORM_flag_present
:
5161 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5162 m_addr
+= bytes_read
;
5165 ull
= read_4_bytes (abfd
, m_addr
);
5169 ull
= read_8_bytes (abfd
, m_addr
);
5172 case DW_FORM_ref_sig8
:
5173 ull
= read_8_bytes (abfd
, m_addr
);
5177 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5178 dwarf_form_name (attr
.form
),
5179 objfile_name (objfile
));
5182 switch (attr
.dw_idx
)
5184 case DW_IDX_compile_unit
:
5185 /* Don't crash on bad data. */
5186 if (ull
>= per_bfd
->all_comp_units
.size ())
5188 complaint (_(".debug_names entry has bad CU index %s"
5191 objfile_name (objfile
));
5194 per_cu
= per_bfd
->get_cu (ull
);
5196 case DW_IDX_type_unit
:
5197 /* Don't crash on bad data. */
5198 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5200 complaint (_(".debug_names entry has bad TU index %s"
5203 objfile_name (objfile
));
5206 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5208 case DW_IDX_die_offset
:
5209 /* In a per-CU index (as opposed to a per-module index), index
5210 entries without CU attribute implicitly refer to the single CU. */
5212 per_cu
= per_bfd
->get_cu (0);
5214 case DW_IDX_GNU_internal
:
5215 if (!m_map
.augmentation_is_gdb
)
5217 symbol_linkage_
= symbol_linkage::static_
;
5219 case DW_IDX_GNU_external
:
5220 if (!m_map
.augmentation_is_gdb
)
5222 symbol_linkage_
= symbol_linkage::extern_
;
5227 /* Skip if already read in. */
5228 if (m_per_objfile
->symtab_set_p (per_cu
))
5231 /* Check static vs global. */
5232 if (symbol_linkage_
!= symbol_linkage::unknown
)
5234 if (symbol_linkage_
== symbol_linkage::static_
)
5236 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5241 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5246 /* Match dw2_symtab_iter_next, symbol_kind
5247 and debug_names::psymbol_tag. */
5251 switch (indexval
.dwarf_tag
)
5253 case DW_TAG_variable
:
5254 case DW_TAG_subprogram
:
5255 /* Some types are also in VAR_DOMAIN. */
5256 case DW_TAG_typedef
:
5257 case DW_TAG_structure_type
:
5264 switch (indexval
.dwarf_tag
)
5266 case DW_TAG_typedef
:
5267 case DW_TAG_structure_type
:
5274 switch (indexval
.dwarf_tag
)
5277 case DW_TAG_variable
:
5284 switch (indexval
.dwarf_tag
)
5296 /* Match dw2_expand_symtabs_matching, symbol_kind and
5297 debug_names::psymbol_tag. */
5300 case VARIABLES_DOMAIN
:
5301 switch (indexval
.dwarf_tag
)
5303 case DW_TAG_variable
:
5309 case FUNCTIONS_DOMAIN
:
5310 switch (indexval
.dwarf_tag
)
5312 case DW_TAG_subprogram
:
5319 switch (indexval
.dwarf_tag
)
5321 case DW_TAG_typedef
:
5322 case DW_TAG_structure_type
:
5328 case MODULES_DOMAIN
:
5329 switch (indexval
.dwarf_tag
)
5343 /* This dumps minimal information about .debug_names. It is called
5344 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5345 uses this to verify that .debug_names has been loaded. */
5348 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5350 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5352 gdb_assert (per_objfile
->per_bfd
->using_index
);
5353 printf_filtered (".debug_names:");
5354 if (per_objfile
->per_bfd
->debug_names_table
)
5355 printf_filtered (" exists\n");
5357 printf_filtered (" faked for \"readnow\"\n");
5358 printf_filtered ("\n");
5362 dwarf2_debug_names_index::expand_matching_symbols
5363 (struct objfile
*objfile
,
5364 const lookup_name_info
&name
, domain_enum domain
,
5366 symbol_compare_ftype
*ordered_compare
)
5368 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5370 /* debug_names_table is NULL if OBJF_READNOW. */
5371 if (!per_objfile
->per_bfd
->debug_names_table
)
5374 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5375 const block_search_flags block_flags
5376 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5378 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5379 auto matcher
= [&] (const char *symname
)
5381 if (ordered_compare
== nullptr)
5383 return ordered_compare (symname
, match_name
) == 0;
5386 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5387 [&] (offset_type namei
)
5389 /* The name was matched, now expand corresponding CUs that were
5391 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5394 struct dwarf2_per_cu_data
*per_cu
;
5395 while ((per_cu
= iter
.next ()) != NULL
)
5396 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5403 dwarf2_debug_names_index::expand_symtabs_matching
5404 (struct objfile
*objfile
,
5405 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5406 const lookup_name_info
*lookup_name
,
5407 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5408 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5409 block_search_flags search_flags
,
5411 enum search_domain kind
)
5413 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5415 /* debug_names_table is NULL if OBJF_READNOW. */
5416 if (!per_objfile
->per_bfd
->debug_names_table
)
5419 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5421 /* This invariant is documented in quick-functions.h. */
5422 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
5423 if (lookup_name
== nullptr)
5425 for (dwarf2_per_cu_data
*per_cu
5426 : all_comp_units_range (per_objfile
->per_bfd
))
5430 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5438 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5441 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5443 [&] (offset_type namei
)
5445 /* The name was matched, now expand corresponding CUs that were
5447 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5449 struct dwarf2_per_cu_data
*per_cu
;
5450 while ((per_cu
= iter
.next ()) != NULL
)
5451 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5461 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5462 to either a dwarf2_per_bfd or dwz_file object. */
5464 template <typename T
>
5465 static gdb::array_view
<const gdb_byte
>
5466 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5468 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5470 if (section
->empty ())
5473 /* Older elfutils strip versions could keep the section in the main
5474 executable while splitting it for the separate debug info file. */
5475 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5478 section
->read (obj
);
5480 /* dwarf2_section_info::size is a bfd_size_type, while
5481 gdb::array_view works with size_t. On 32-bit hosts, with
5482 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5483 is 32-bit. So we need an explicit narrowing conversion here.
5484 This is fine, because it's impossible to allocate or mmap an
5485 array/buffer larger than what size_t can represent. */
5486 return gdb::make_array_view (section
->buffer
, section
->size
);
5489 /* Lookup the index cache for the contents of the index associated to
5492 static gdb::array_view
<const gdb_byte
>
5493 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5495 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5496 if (build_id
== nullptr)
5499 return global_index_cache
.lookup_gdb_index (build_id
,
5500 &dwarf2_per_bfd
->index_cache_res
);
5503 /* Same as the above, but for DWZ. */
5505 static gdb::array_view
<const gdb_byte
>
5506 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5508 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5509 if (build_id
== nullptr)
5512 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5515 /* See dwarf2/public.h. */
5518 dwarf2_initialize_objfile (struct objfile
*objfile
)
5520 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5521 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5523 dwarf_read_debug_printf ("called");
5525 /* If we're about to read full symbols, don't bother with the
5526 indices. In this case we also don't care if some other debug
5527 format is making psymtabs, because they are all about to be
5529 if ((objfile
->flags
& OBJF_READNOW
))
5531 dwarf_read_debug_printf ("readnow requested");
5533 /* When using READNOW, the using_index flag (set below) indicates that
5534 PER_BFD was already initialized, when we loaded some other objfile. */
5535 if (per_bfd
->using_index
)
5537 dwarf_read_debug_printf ("using_index already set");
5538 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5542 per_bfd
->using_index
= 1;
5543 create_all_comp_units (per_objfile
);
5544 per_bfd
->quick_file_names_table
5545 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5547 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5549 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5551 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5552 struct dwarf2_per_cu_quick_data
);
5555 /* Arrange for gdb to see the "quick" functions. However, these
5556 functions will be no-ops because we will have expanded all
5558 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5562 /* Was a debug names index already read when we processed an objfile sharing
5564 if (per_bfd
->debug_names_table
!= nullptr)
5566 dwarf_read_debug_printf ("re-using shared debug names table");
5567 objfile
->qf
.push_front (make_dwarf_debug_names ());
5571 /* Was a GDB index already read when we processed an objfile sharing
5573 if (per_bfd
->index_table
!= nullptr)
5575 dwarf_read_debug_printf ("re-using shared index table");
5576 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5580 /* There might already be partial symtabs built for this BFD. This happens
5581 when loading the same binary twice with the index-cache enabled. If so,
5582 don't try to read an index. The objfile / per_objfile initialization will
5583 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5585 if (per_bfd
->partial_symtabs
!= nullptr)
5587 dwarf_read_debug_printf ("re-using shared partial symtabs");
5588 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5592 if (dwarf2_read_debug_names (per_objfile
))
5594 dwarf_read_debug_printf ("found debug names");
5595 objfile
->qf
.push_front (make_dwarf_debug_names ());
5599 if (dwarf2_read_gdb_index (per_objfile
,
5600 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5601 get_gdb_index_contents_from_section
<dwz_file
>))
5603 dwarf_read_debug_printf ("found gdb index from file");
5604 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5608 /* ... otherwise, try to find the index in the index cache. */
5609 if (dwarf2_read_gdb_index (per_objfile
,
5610 get_gdb_index_contents_from_cache
,
5611 get_gdb_index_contents_from_cache_dwz
))
5613 dwarf_read_debug_printf ("found gdb index from cache");
5614 global_index_cache
.hit ();
5615 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5619 global_index_cache
.miss ();
5620 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5625 /* Build a partial symbol table. */
5628 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5630 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5631 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5633 if (per_bfd
->partial_symtabs
!= nullptr)
5635 /* Partial symbols were already read, so now we can simply
5639 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5640 objfile
->qf
.emplace_front (psf
);
5643 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5649 psf
= new psymbol_functions
;
5650 objfile
->qf
.emplace_front (psf
);
5652 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5653 = psf
->get_partial_symtabs ();
5655 /* Set the local reference to partial symtabs, so that we don't try
5656 to read them again if reading another objfile with the same BFD.
5657 If we can't in fact share, this won't make a difference anyway as
5658 the dwarf2_per_bfd object won't be shared. */
5659 per_bfd
->partial_symtabs
= partial_symtabs
;
5663 /* This isn't really ideal: all the data we allocate on the
5664 objfile's obstack is still uselessly kept around. However,
5665 freeing it seems unsafe. */
5666 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5667 dwarf2_build_psymtabs_hard (per_objfile
);
5670 /* (maybe) store an index in the cache. */
5671 global_index_cache
.store (per_objfile
);
5673 catch (const gdb_exception_error
&except
)
5675 exception_print (gdb_stderr
, except
);
5679 /* Find the base address of the compilation unit for range lists and
5680 location lists. It will normally be specified by DW_AT_low_pc.
5681 In DWARF-3 draft 4, the base address could be overridden by
5682 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5683 compilation units with discontinuous ranges. */
5686 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5688 struct attribute
*attr
;
5690 cu
->base_address
.reset ();
5692 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5693 if (attr
!= nullptr)
5694 cu
->base_address
= attr
->as_address ();
5697 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5698 if (attr
!= nullptr)
5699 cu
->base_address
= attr
->as_address ();
5703 /* Helper function that returns the proper abbrev section for
5706 static struct dwarf2_section_info
*
5707 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5709 struct dwarf2_section_info
*abbrev
;
5710 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5712 if (this_cu
->is_dwz
)
5713 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5715 abbrev
= &per_bfd
->abbrev
;
5720 /* Fetch the abbreviation table offset from a comp or type unit header. */
5723 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5724 struct dwarf2_section_info
*section
,
5725 sect_offset sect_off
)
5727 bfd
*abfd
= section
->get_bfd_owner ();
5728 const gdb_byte
*info_ptr
;
5729 unsigned int initial_length_size
, offset_size
;
5732 section
->read (per_objfile
->objfile
);
5733 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5734 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5735 offset_size
= initial_length_size
== 4 ? 4 : 8;
5736 info_ptr
+= initial_length_size
;
5738 version
= read_2_bytes (abfd
, info_ptr
);
5742 /* Skip unit type and address size. */
5746 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5749 /* A partial symtab that is used only for include files. */
5750 struct dwarf2_include_psymtab
: public partial_symtab
5752 dwarf2_include_psymtab (const char *filename
,
5753 psymtab_storage
*partial_symtabs
,
5754 objfile_per_bfd_storage
*objfile_per_bfd
)
5755 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5759 void read_symtab (struct objfile
*objfile
) override
5761 /* It's an include file, no symbols to read for it.
5762 Everything is in the includer symtab. */
5764 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5765 expansion of the includer psymtab. We use the dependencies[0] field to
5766 model the includer. But if we go the regular route of calling
5767 expand_psymtab here, and having expand_psymtab call expand_dependencies
5768 to expand the includer, we'll only use expand_psymtab on the includer
5769 (making it a non-toplevel psymtab), while if we expand the includer via
5770 another path, we'll use read_symtab (making it a toplevel psymtab).
5771 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5772 psymtab, and trigger read_symtab on the includer here directly. */
5773 includer ()->read_symtab (objfile
);
5776 void expand_psymtab (struct objfile
*objfile
) override
5778 /* This is not called by read_symtab, and should not be called by any
5779 expand_dependencies. */
5783 bool readin_p (struct objfile
*objfile
) const override
5785 return includer ()->readin_p (objfile
);
5788 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5794 partial_symtab
*includer () const
5796 /* An include psymtab has exactly one dependency: the psymtab that
5798 gdb_assert (this->number_of_dependencies
== 1);
5799 return this->dependencies
[0];
5803 /* Allocate a new partial symtab for file named NAME and mark this new
5804 partial symtab as being an include of PST. */
5807 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5809 dwarf2_psymtab
*pst
,
5810 psymtab_storage
*partial_symtabs
,
5811 objfile_per_bfd_storage
*objfile_per_bfd
)
5813 dwarf2_include_psymtab
*subpst
5814 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5816 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5817 subpst
->dirname
= pst
->dirname
;
5819 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5820 subpst
->dependencies
[0] = pst
;
5821 subpst
->number_of_dependencies
= 1;
5824 /* Read the Line Number Program data and extract the list of files
5825 included by the source file represented by PST. Build an include
5826 partial symtab for each of these included files. */
5829 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5830 struct die_info
*die
,
5831 const file_and_directory
&fnd
,
5832 dwarf2_psymtab
*pst
)
5835 struct attribute
*attr
;
5837 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5838 if (attr
!= nullptr && attr
->form_is_unsigned ())
5839 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5841 return; /* No linetable, so no includes. */
5843 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5844 that we pass in the raw text_low here; that is ok because we're
5845 only decoding the line table to make include partial symtabs, and
5846 so the addresses aren't really used. */
5847 dwarf_decode_lines (lh
.get (), fnd
, cu
, pst
,
5848 pst
->raw_text_low (), 1);
5852 hash_signatured_type (const void *item
)
5854 const struct signatured_type
*sig_type
5855 = (const struct signatured_type
*) item
;
5857 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5858 return sig_type
->signature
;
5862 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5864 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5865 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5867 return lhs
->signature
== rhs
->signature
;
5870 /* Allocate a hash table for signatured types. */
5873 allocate_signatured_type_table ()
5875 return htab_up (htab_create_alloc (41,
5876 hash_signatured_type
,
5878 NULL
, xcalloc
, xfree
));
5881 /* A helper for create_debug_types_hash_table. Read types from SECTION
5882 and fill them into TYPES_HTAB. It will process only type units,
5883 therefore DW_UT_type. */
5886 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5887 struct dwo_file
*dwo_file
,
5888 dwarf2_section_info
*section
, htab_up
&types_htab
,
5889 rcuh_kind section_kind
)
5891 struct objfile
*objfile
= per_objfile
->objfile
;
5892 struct dwarf2_section_info
*abbrev_section
;
5894 const gdb_byte
*info_ptr
, *end_ptr
;
5896 abbrev_section
= &dwo_file
->sections
.abbrev
;
5898 dwarf_read_debug_printf ("Reading %s for %s",
5899 section
->get_name (),
5900 abbrev_section
->get_file_name ());
5902 section
->read (objfile
);
5903 info_ptr
= section
->buffer
;
5905 if (info_ptr
== NULL
)
5908 /* We can't set abfd until now because the section may be empty or
5909 not present, in which case the bfd is unknown. */
5910 abfd
= section
->get_bfd_owner ();
5912 /* We don't use cutu_reader here because we don't need to read
5913 any dies: the signature is in the header. */
5915 end_ptr
= info_ptr
+ section
->size
;
5916 while (info_ptr
< end_ptr
)
5918 signatured_type_up sig_type
;
5919 struct dwo_unit
*dwo_tu
;
5921 const gdb_byte
*ptr
= info_ptr
;
5922 struct comp_unit_head header
;
5923 unsigned int length
;
5925 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5927 /* Initialize it due to a false compiler warning. */
5928 header
.signature
= -1;
5929 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5931 /* We need to read the type's signature in order to build the hash
5932 table, but we don't need anything else just yet. */
5934 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5935 abbrev_section
, ptr
, section_kind
);
5937 length
= header
.get_length ();
5939 /* Skip dummy type units. */
5940 if (ptr
>= info_ptr
+ length
5941 || peek_abbrev_code (abfd
, ptr
) == 0
5942 || (header
.unit_type
!= DW_UT_type
5943 && header
.unit_type
!= DW_UT_split_type
))
5949 if (types_htab
== NULL
)
5950 types_htab
= allocate_dwo_unit_table ();
5952 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5953 dwo_tu
->dwo_file
= dwo_file
;
5954 dwo_tu
->signature
= header
.signature
;
5955 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5956 dwo_tu
->section
= section
;
5957 dwo_tu
->sect_off
= sect_off
;
5958 dwo_tu
->length
= length
;
5960 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5961 gdb_assert (slot
!= NULL
);
5963 complaint (_("debug type entry at offset %s is duplicate to"
5964 " the entry at offset %s, signature %s"),
5965 sect_offset_str (sect_off
),
5966 sect_offset_str (dwo_tu
->sect_off
),
5967 hex_string (header
.signature
));
5970 dwarf_read_debug_printf_v (" offset %s, signature %s",
5971 sect_offset_str (sect_off
),
5972 hex_string (header
.signature
));
5978 /* Create the hash table of all entries in the .debug_types
5979 (or .debug_types.dwo) section(s).
5980 DWO_FILE is a pointer to the DWO file object.
5982 The result is a pointer to the hash table or NULL if there are no types.
5984 Note: This function processes DWO files only, not DWP files. */
5987 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5988 struct dwo_file
*dwo_file
,
5989 gdb::array_view
<dwarf2_section_info
> type_sections
,
5990 htab_up
&types_htab
)
5992 for (dwarf2_section_info
§ion
: type_sections
)
5993 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5997 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5998 If SLOT is non-NULL, it is the entry to use in the hash table.
5999 Otherwise we find one. */
6001 static struct signatured_type
*
6002 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6004 if (per_objfile
->per_bfd
->all_comp_units
.size ()
6005 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
6006 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6008 signatured_type_up sig_type_holder
6009 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
6010 signatured_type
*sig_type
= sig_type_holder
.get ();
6012 per_objfile
->per_bfd
->all_comp_units
.emplace_back
6013 (sig_type_holder
.release ());
6014 if (per_objfile
->per_bfd
->using_index
)
6017 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6018 struct dwarf2_per_cu_quick_data
);
6023 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6026 gdb_assert (*slot
== NULL
);
6028 /* The rest of sig_type must be filled in by the caller. */
6032 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6033 Fill in SIG_ENTRY with DWO_ENTRY. */
6036 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6037 struct signatured_type
*sig_entry
,
6038 struct dwo_unit
*dwo_entry
)
6040 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6042 /* Make sure we're not clobbering something we don't expect to. */
6043 gdb_assert (! sig_entry
->queued
);
6044 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6045 if (per_bfd
->using_index
)
6047 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6048 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6051 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6052 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6053 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6054 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6055 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6057 sig_entry
->section
= dwo_entry
->section
;
6058 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6059 sig_entry
->length
= dwo_entry
->length
;
6060 sig_entry
->reading_dwo_directly
= 1;
6061 sig_entry
->per_bfd
= per_bfd
;
6062 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6063 sig_entry
->dwo_unit
= dwo_entry
;
6066 /* Subroutine of lookup_signatured_type.
6067 If we haven't read the TU yet, create the signatured_type data structure
6068 for a TU to be read in directly from a DWO file, bypassing the stub.
6069 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6070 using .gdb_index, then when reading a CU we want to stay in the DWO file
6071 containing that CU. Otherwise we could end up reading several other DWO
6072 files (due to comdat folding) to process the transitive closure of all the
6073 mentioned TUs, and that can be slow. The current DWO file will have every
6074 type signature that it needs.
6075 We only do this for .gdb_index because in the psymtab case we already have
6076 to read all the DWOs to build the type unit groups. */
6078 static struct signatured_type
*
6079 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6081 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6082 struct dwo_file
*dwo_file
;
6083 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6086 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6088 /* If TU skeletons have been removed then we may not have read in any
6090 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6091 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6093 /* We only ever need to read in one copy of a signatured type.
6094 Use the global signatured_types array to do our own comdat-folding
6095 of types. If this is the first time we're reading this TU, and
6096 the TU has an entry in .gdb_index, replace the recorded data from
6097 .gdb_index with this TU. */
6099 signatured_type
find_sig_entry (sig
);
6100 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6101 &find_sig_entry
, INSERT
);
6102 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6104 /* We can get here with the TU already read, *or* in the process of being
6105 read. Don't reassign the global entry to point to this DWO if that's
6106 the case. Also note that if the TU is already being read, it may not
6107 have come from a DWO, the program may be a mix of Fission-compiled
6108 code and non-Fission-compiled code. */
6110 /* Have we already tried to read this TU?
6111 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6112 needn't exist in the global table yet). */
6113 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6116 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6117 dwo_unit of the TU itself. */
6118 dwo_file
= cu
->dwo_unit
->dwo_file
;
6120 /* Ok, this is the first time we're reading this TU. */
6121 if (dwo_file
->tus
== NULL
)
6123 find_dwo_entry
.signature
= sig
;
6124 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6126 if (dwo_entry
== NULL
)
6129 /* If the global table doesn't have an entry for this TU, add one. */
6130 if (sig_entry
== NULL
)
6131 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6133 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6134 sig_entry
->tu_read
= 1;
6138 /* Subroutine of lookup_signatured_type.
6139 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6140 then try the DWP file. If the TU stub (skeleton) has been removed then
6141 it won't be in .gdb_index. */
6143 static struct signatured_type
*
6144 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6146 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6147 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6148 struct dwo_unit
*dwo_entry
;
6151 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6152 gdb_assert (dwp_file
!= NULL
);
6154 /* If TU skeletons have been removed then we may not have read in any
6156 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6157 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6159 signatured_type
find_sig_entry (sig
);
6160 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6161 &find_sig_entry
, INSERT
);
6162 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6164 /* Have we already tried to read this TU?
6165 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6166 needn't exist in the global table yet). */
6167 if (sig_entry
!= NULL
)
6170 if (dwp_file
->tus
== NULL
)
6172 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6173 1 /* is_debug_types */);
6174 if (dwo_entry
== NULL
)
6177 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6178 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6183 /* Lookup a signature based type for DW_FORM_ref_sig8.
6184 Returns NULL if signature SIG is not present in the table.
6185 It is up to the caller to complain about this. */
6187 static struct signatured_type
*
6188 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6190 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6192 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6194 /* We're in a DWO/DWP file, and we're using .gdb_index.
6195 These cases require special processing. */
6196 if (get_dwp_file (per_objfile
) == NULL
)
6197 return lookup_dwo_signatured_type (cu
, sig
);
6199 return lookup_dwp_signatured_type (cu
, sig
);
6203 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6205 signatured_type
find_entry (sig
);
6206 return ((struct signatured_type
*)
6207 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6212 /* Low level DIE reading support. */
6214 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6217 init_cu_die_reader (struct die_reader_specs
*reader
,
6218 struct dwarf2_cu
*cu
,
6219 struct dwarf2_section_info
*section
,
6220 struct dwo_file
*dwo_file
,
6221 struct abbrev_table
*abbrev_table
)
6223 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6224 reader
->abfd
= section
->get_bfd_owner ();
6226 reader
->dwo_file
= dwo_file
;
6227 reader
->die_section
= section
;
6228 reader
->buffer
= section
->buffer
;
6229 reader
->buffer_end
= section
->buffer
+ section
->size
;
6230 reader
->abbrev_table
= abbrev_table
;
6233 /* Subroutine of cutu_reader to simplify it.
6234 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6235 There's just a lot of work to do, and cutu_reader is big enough
6238 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6239 from it to the DIE in the DWO. If NULL we are skipping the stub.
6240 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6241 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6242 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6243 STUB_COMP_DIR may be non-NULL.
6244 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6245 are filled in with the info of the DIE from the DWO file.
6246 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6247 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6248 kept around for at least as long as *RESULT_READER.
6250 The result is non-zero if a valid (non-dummy) DIE was found. */
6253 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6254 struct dwo_unit
*dwo_unit
,
6255 struct die_info
*stub_comp_unit_die
,
6256 const char *stub_comp_dir
,
6257 struct die_reader_specs
*result_reader
,
6258 const gdb_byte
**result_info_ptr
,
6259 struct die_info
**result_comp_unit_die
,
6260 abbrev_table_up
*result_dwo_abbrev_table
)
6262 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6263 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6264 struct objfile
*objfile
= per_objfile
->objfile
;
6266 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6267 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6268 int i
,num_extra_attrs
;
6269 struct dwarf2_section_info
*dwo_abbrev_section
;
6270 struct die_info
*comp_unit_die
;
6272 /* At most one of these may be provided. */
6273 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6275 /* These attributes aren't processed until later:
6276 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6277 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6278 referenced later. However, these attributes are found in the stub
6279 which we won't have later. In order to not impose this complication
6280 on the rest of the code, we read them here and copy them to the
6289 if (stub_comp_unit_die
!= NULL
)
6291 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6293 if (!per_cu
->is_debug_types
)
6294 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6295 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6296 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6297 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6298 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6300 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6302 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6303 We need the value before we can process DW_AT_ranges values from the
6305 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6307 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6308 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6309 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6310 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6312 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6314 else if (stub_comp_dir
!= NULL
)
6316 /* Reconstruct the comp_dir attribute to simplify the code below. */
6317 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6318 comp_dir
->name
= DW_AT_comp_dir
;
6319 comp_dir
->form
= DW_FORM_string
;
6320 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6323 /* Set up for reading the DWO CU/TU. */
6324 cu
->dwo_unit
= dwo_unit
;
6325 dwarf2_section_info
*section
= dwo_unit
->section
;
6326 section
->read (objfile
);
6327 abfd
= section
->get_bfd_owner ();
6328 begin_info_ptr
= info_ptr
= (section
->buffer
6329 + to_underlying (dwo_unit
->sect_off
));
6330 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6332 if (per_cu
->is_debug_types
)
6334 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6336 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6337 section
, dwo_abbrev_section
,
6338 info_ptr
, rcuh_kind::TYPE
);
6339 /* This is not an assert because it can be caused by bad debug info. */
6340 if (sig_type
->signature
!= cu
->header
.signature
)
6342 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6343 " TU at offset %s [in module %s]"),
6344 hex_string (sig_type
->signature
),
6345 hex_string (cu
->header
.signature
),
6346 sect_offset_str (dwo_unit
->sect_off
),
6347 bfd_get_filename (abfd
));
6349 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6350 /* For DWOs coming from DWP files, we don't know the CU length
6351 nor the type's offset in the TU until now. */
6352 dwo_unit
->length
= cu
->header
.get_length ();
6353 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6355 /* Establish the type offset that can be used to lookup the type.
6356 For DWO files, we don't know it until now. */
6357 sig_type
->type_offset_in_section
6358 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6362 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6363 section
, dwo_abbrev_section
,
6364 info_ptr
, rcuh_kind::COMPILE
);
6365 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6366 /* For DWOs coming from DWP files, we don't know the CU length
6368 dwo_unit
->length
= cu
->header
.get_length ();
6371 dwo_abbrev_section
->read (objfile
);
6372 *result_dwo_abbrev_table
6373 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6374 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6375 result_dwo_abbrev_table
->get ());
6377 /* Read in the die, but leave space to copy over the attributes
6378 from the stub. This has the benefit of simplifying the rest of
6379 the code - all the work to maintain the illusion of a single
6380 DW_TAG_{compile,type}_unit DIE is done here. */
6381 num_extra_attrs
= ((stmt_list
!= NULL
)
6385 + (comp_dir
!= NULL
));
6386 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6389 /* Copy over the attributes from the stub to the DIE we just read in. */
6390 comp_unit_die
= *result_comp_unit_die
;
6391 i
= comp_unit_die
->num_attrs
;
6392 if (stmt_list
!= NULL
)
6393 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6395 comp_unit_die
->attrs
[i
++] = *low_pc
;
6396 if (high_pc
!= NULL
)
6397 comp_unit_die
->attrs
[i
++] = *high_pc
;
6399 comp_unit_die
->attrs
[i
++] = *ranges
;
6400 if (comp_dir
!= NULL
)
6401 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6402 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6404 if (dwarf_die_debug
)
6406 fprintf_unfiltered (gdb_stdlog
,
6407 "Read die from %s@0x%x of %s:\n",
6408 section
->get_name (),
6409 (unsigned) (begin_info_ptr
- section
->buffer
),
6410 bfd_get_filename (abfd
));
6411 dump_die (comp_unit_die
, dwarf_die_debug
);
6414 /* Skip dummy compilation units. */
6415 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6416 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6419 *result_info_ptr
= info_ptr
;
6423 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6424 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6425 signature is part of the header. */
6426 static gdb::optional
<ULONGEST
>
6427 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6429 if (cu
->header
.version
>= 5)
6430 return cu
->header
.signature
;
6431 struct attribute
*attr
;
6432 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6433 if (attr
== nullptr || !attr
->form_is_unsigned ())
6434 return gdb::optional
<ULONGEST
> ();
6435 return attr
->as_unsigned ();
6438 /* Subroutine of cutu_reader to simplify it.
6439 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6440 Returns NULL if the specified DWO unit cannot be found. */
6442 static struct dwo_unit
*
6443 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6445 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6446 struct dwo_unit
*dwo_unit
;
6447 const char *comp_dir
;
6449 gdb_assert (cu
!= NULL
);
6451 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6452 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6453 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6455 if (per_cu
->is_debug_types
)
6456 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6459 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6461 if (!signature
.has_value ())
6462 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6464 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6466 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6472 /* Subroutine of cutu_reader to simplify it.
6473 See it for a description of the parameters.
6474 Read a TU directly from a DWO file, bypassing the stub. */
6477 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6478 dwarf2_per_objfile
*per_objfile
,
6479 dwarf2_cu
*existing_cu
)
6481 struct signatured_type
*sig_type
;
6483 /* Verify we can do the following downcast, and that we have the
6485 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6486 sig_type
= (struct signatured_type
*) this_cu
;
6487 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6491 if (existing_cu
!= nullptr)
6494 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6495 /* There's no need to do the rereading_dwo_cu handling that
6496 cutu_reader does since we don't read the stub. */
6500 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6501 in per_objfile yet. */
6502 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6503 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6504 cu
= m_new_cu
.get ();
6507 /* A future optimization, if needed, would be to use an existing
6508 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6509 could share abbrev tables. */
6511 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6512 NULL
/* stub_comp_unit_die */,
6513 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6516 &m_dwo_abbrev_table
) == 0)
6523 /* Initialize a CU (or TU) and read its DIEs.
6524 If the CU defers to a DWO file, read the DWO file as well.
6526 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6527 Otherwise the table specified in the comp unit header is read in and used.
6528 This is an optimization for when we already have the abbrev table.
6530 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6533 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6534 dwarf2_per_objfile
*per_objfile
,
6535 struct abbrev_table
*abbrev_table
,
6536 dwarf2_cu
*existing_cu
,
6538 : die_reader_specs
{},
6541 struct objfile
*objfile
= per_objfile
->objfile
;
6542 struct dwarf2_section_info
*section
= this_cu
->section
;
6543 bfd
*abfd
= section
->get_bfd_owner ();
6544 const gdb_byte
*begin_info_ptr
;
6545 struct signatured_type
*sig_type
= NULL
;
6546 struct dwarf2_section_info
*abbrev_section
;
6547 /* Non-zero if CU currently points to a DWO file and we need to
6548 reread it. When this happens we need to reread the skeleton die
6549 before we can reread the DWO file (this only applies to CUs, not TUs). */
6550 int rereading_dwo_cu
= 0;
6552 if (dwarf_die_debug
)
6553 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6554 this_cu
->is_debug_types
? "type" : "comp",
6555 sect_offset_str (this_cu
->sect_off
));
6557 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6558 file (instead of going through the stub), short-circuit all of this. */
6559 if (this_cu
->reading_dwo_directly
)
6561 /* Narrow down the scope of possibilities to have to understand. */
6562 gdb_assert (this_cu
->is_debug_types
);
6563 gdb_assert (abbrev_table
== NULL
);
6564 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6568 /* This is cheap if the section is already read in. */
6569 section
->read (objfile
);
6571 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6573 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6577 if (existing_cu
!= nullptr)
6580 /* If this CU is from a DWO file we need to start over, we need to
6581 refetch the attributes from the skeleton CU.
6582 This could be optimized by retrieving those attributes from when we
6583 were here the first time: the previous comp_unit_die was stored in
6584 comp_unit_obstack. But there's no data yet that we need this
6586 if (cu
->dwo_unit
!= NULL
)
6587 rereading_dwo_cu
= 1;
6591 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6592 in per_objfile yet. */
6593 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6594 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6595 cu
= m_new_cu
.get ();
6598 /* Get the header. */
6599 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6601 /* We already have the header, there's no need to read it in again. */
6602 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6606 if (this_cu
->is_debug_types
)
6608 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6609 section
, abbrev_section
,
6610 info_ptr
, rcuh_kind::TYPE
);
6612 /* Since per_cu is the first member of struct signatured_type,
6613 we can go from a pointer to one to a pointer to the other. */
6614 sig_type
= (struct signatured_type
*) this_cu
;
6615 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6616 gdb_assert (sig_type
->type_offset_in_tu
6617 == cu
->header
.type_cu_offset_in_tu
);
6618 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6620 /* LENGTH has not been set yet for type units if we're
6621 using .gdb_index. */
6622 this_cu
->length
= cu
->header
.get_length ();
6624 /* Establish the type offset that can be used to lookup the type. */
6625 sig_type
->type_offset_in_section
=
6626 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6628 this_cu
->dwarf_version
= cu
->header
.version
;
6632 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6633 section
, abbrev_section
,
6635 rcuh_kind::COMPILE
);
6637 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6638 if (this_cu
->length
== 0)
6639 this_cu
->length
= cu
->header
.get_length ();
6641 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6642 this_cu
->dwarf_version
= cu
->header
.version
;
6646 /* Skip dummy compilation units. */
6647 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6648 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6654 /* If we don't have them yet, read the abbrevs for this compilation unit.
6655 And if we need to read them now, make sure they're freed when we're
6657 if (abbrev_table
!= NULL
)
6658 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6661 abbrev_section
->read (objfile
);
6662 m_abbrev_table_holder
6663 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6664 abbrev_table
= m_abbrev_table_holder
.get ();
6667 /* Read the top level CU/TU die. */
6668 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6669 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6671 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6677 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6678 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6679 table from the DWO file and pass the ownership over to us. It will be
6680 referenced from READER, so we must make sure to free it after we're done
6683 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6684 DWO CU, that this test will fail (the attribute will not be present). */
6685 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6686 if (dwo_name
!= nullptr)
6688 struct dwo_unit
*dwo_unit
;
6689 struct die_info
*dwo_comp_unit_die
;
6691 if (comp_unit_die
->has_children
)
6693 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6694 " has children (offset %s) [in module %s]"),
6695 sect_offset_str (this_cu
->sect_off
),
6696 bfd_get_filename (abfd
));
6698 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6699 if (dwo_unit
!= NULL
)
6701 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6702 comp_unit_die
, NULL
,
6705 &m_dwo_abbrev_table
) == 0)
6711 comp_unit_die
= dwo_comp_unit_die
;
6715 /* Yikes, we couldn't find the rest of the DIE, we only have
6716 the stub. A complaint has already been logged. There's
6717 not much more we can do except pass on the stub DIE to
6718 die_reader_func. We don't want to throw an error on bad
6725 cutu_reader::keep ()
6727 /* Done, clean up. */
6728 gdb_assert (!dummy_p
);
6729 if (m_new_cu
!= NULL
)
6731 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6733 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6734 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6738 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6739 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6740 assumed to have already done the lookup to find the DWO file).
6742 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6743 THIS_CU->is_debug_types, but nothing else.
6745 We fill in THIS_CU->length.
6747 THIS_CU->cu is always freed when done.
6748 This is done in order to not leave THIS_CU->cu in a state where we have
6749 to care whether it refers to the "main" CU or the DWO CU.
6751 When parent_cu is passed, it is used to provide a default value for
6752 str_offsets_base and addr_base from the parent. */
6754 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6755 dwarf2_per_objfile
*per_objfile
,
6756 struct dwarf2_cu
*parent_cu
,
6757 struct dwo_file
*dwo_file
)
6758 : die_reader_specs
{},
6761 struct objfile
*objfile
= per_objfile
->objfile
;
6762 struct dwarf2_section_info
*section
= this_cu
->section
;
6763 bfd
*abfd
= section
->get_bfd_owner ();
6764 struct dwarf2_section_info
*abbrev_section
;
6765 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6767 if (dwarf_die_debug
)
6768 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6769 this_cu
->is_debug_types
? "type" : "comp",
6770 sect_offset_str (this_cu
->sect_off
));
6772 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6774 abbrev_section
= (dwo_file
!= NULL
6775 ? &dwo_file
->sections
.abbrev
6776 : get_abbrev_section_for_cu (this_cu
));
6778 /* This is cheap if the section is already read in. */
6779 section
->read (objfile
);
6781 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6783 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6784 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6785 section
, abbrev_section
, info_ptr
,
6786 (this_cu
->is_debug_types
6788 : rcuh_kind::COMPILE
));
6790 if (parent_cu
!= nullptr)
6792 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6793 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6795 this_cu
->length
= m_new_cu
->header
.get_length ();
6797 /* Skip dummy compilation units. */
6798 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6799 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6805 abbrev_section
->read (objfile
);
6806 m_abbrev_table_holder
6807 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6809 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6810 m_abbrev_table_holder
.get ());
6811 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6815 /* Type Unit Groups.
6817 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6818 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6819 so that all types coming from the same compilation (.o file) are grouped
6820 together. A future step could be to put the types in the same symtab as
6821 the CU the types ultimately came from. */
6824 hash_type_unit_group (const void *item
)
6826 const struct type_unit_group
*tu_group
6827 = (const struct type_unit_group
*) item
;
6829 return hash_stmt_list_entry (&tu_group
->hash
);
6833 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6835 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6836 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6838 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6841 /* Allocate a hash table for type unit groups. */
6844 allocate_type_unit_groups_table ()
6846 return htab_up (htab_create_alloc (3,
6847 hash_type_unit_group
,
6849 htab_delete_entry
<type_unit_group
>,
6853 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6854 partial symtabs. We combine several TUs per psymtab to not let the size
6855 of any one psymtab grow too big. */
6856 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6857 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6859 /* Helper routine for get_type_unit_group.
6860 Create the type_unit_group object used to hold one or more TUs. */
6862 static std::unique_ptr
<type_unit_group
>
6863 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6865 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6866 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6868 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6869 tu_group
->per_bfd
= per_bfd
;
6871 if (per_bfd
->using_index
)
6873 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6874 struct dwarf2_per_cu_quick_data
);
6878 unsigned int line_offset
= to_underlying (line_offset_struct
);
6879 dwarf2_psymtab
*pst
;
6882 /* Give the symtab a useful name for debug purposes. */
6883 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6884 name
= string_printf ("<type_units_%d>",
6885 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6887 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6889 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6891 pst
->anonymous
= true;
6894 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6895 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6900 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6901 STMT_LIST is a DW_AT_stmt_list attribute. */
6903 static struct type_unit_group
*
6904 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6906 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6907 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6908 struct type_unit_group
*tu_group
;
6910 unsigned int line_offset
;
6911 struct type_unit_group type_unit_group_for_lookup
;
6913 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6914 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6916 /* Do we need to create a new group, or can we use an existing one? */
6918 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6920 line_offset
= stmt_list
->as_unsigned ();
6921 ++tu_stats
->nr_symtab_sharers
;
6925 /* Ugh, no stmt_list. Rare, but we have to handle it.
6926 We can do various things here like create one group per TU or
6927 spread them over multiple groups to split up the expansion work.
6928 To avoid worst case scenarios (too many groups or too large groups)
6929 we, umm, group them in bunches. */
6930 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6931 | (tu_stats
->nr_stmt_less_type_units
6932 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6933 ++tu_stats
->nr_stmt_less_type_units
;
6936 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6937 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6938 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6939 &type_unit_group_for_lookup
, INSERT
);
6940 if (*slot
== nullptr)
6942 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6943 std::unique_ptr
<type_unit_group
> grp
6944 = create_type_unit_group (cu
, line_offset_struct
);
6945 *slot
= grp
.release ();
6946 ++tu_stats
->nr_symtabs
;
6949 tu_group
= (struct type_unit_group
*) *slot
;
6950 gdb_assert (tu_group
!= nullptr);
6954 /* Partial symbol tables. */
6956 /* Create a psymtab named NAME and assign it to PER_CU.
6958 The caller must fill in the following details:
6959 dirname, textlow, texthigh. */
6961 static dwarf2_psymtab
*
6962 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6963 dwarf2_per_objfile
*per_objfile
,
6967 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6968 per_objfile
->objfile
->per_bfd
, per_cu
);
6970 pst
->psymtabs_addrmap_supported
= true;
6972 /* This is the glue that links PST into GDB's symbol API. */
6973 per_cu
->v
.psymtab
= pst
;
6978 /* DIE reader function for process_psymtab_comp_unit. */
6981 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6982 const gdb_byte
*info_ptr
,
6983 struct die_info
*comp_unit_die
,
6984 enum language pretend_language
)
6986 struct dwarf2_cu
*cu
= reader
->cu
;
6987 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6988 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6989 struct objfile
*objfile
= per_objfile
->objfile
;
6990 struct gdbarch
*gdbarch
= objfile
->arch ();
6991 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6993 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6994 dwarf2_psymtab
*pst
;
6995 enum pc_bounds_kind cu_bounds_kind
;
6997 gdb_assert (! per_cu
->is_debug_types
);
6999 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7001 /* Allocate a new partial symbol table structure. */
7002 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7003 static const char artificial
[] = "<artificial>";
7004 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
7005 if (strcmp (fnd
.name
, artificial
) == 0)
7007 debug_filename
.reset (concat (artificial
, "@",
7008 sect_offset_str (per_cu
->sect_off
),
7010 fnd
.name
= debug_filename
.get ();
7013 pst
= create_partial_symtab (per_cu
, per_objfile
, fnd
.name
);
7015 /* This must be done before calling dwarf2_build_include_psymtabs. */
7016 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7018 baseaddr
= objfile
->text_section_offset ();
7020 dwarf2_find_base_address (comp_unit_die
, cu
);
7022 /* Possibly set the default values of LOWPC and HIGHPC from
7024 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7025 &best_highpc
, cu
, pst
);
7026 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7029 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7032 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7034 /* Store the contiguous range if it is not empty; it can be
7035 empty for CUs with no code. */
7036 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7040 /* Check if comp unit has_children.
7041 If so, read the rest of the partial symbols from this comp unit.
7042 If not, there's no more debug_info for this comp unit. */
7043 if (comp_unit_die
->has_children
)
7045 struct partial_die_info
*first_die
;
7046 CORE_ADDR lowpc
, highpc
;
7048 lowpc
= ((CORE_ADDR
) -1);
7049 highpc
= ((CORE_ADDR
) 0);
7051 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7053 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7054 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7056 /* If we didn't find a lowpc, set it to highpc to avoid
7057 complaints from `maint check'. */
7058 if (lowpc
== ((CORE_ADDR
) -1))
7061 /* If the compilation unit didn't have an explicit address range,
7062 then use the information extracted from its child dies. */
7063 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7066 best_highpc
= highpc
;
7069 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7070 best_lowpc
+ baseaddr
)
7072 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7073 best_highpc
+ baseaddr
)
7078 if (!cu
->per_cu
->imported_symtabs_empty ())
7081 int len
= cu
->per_cu
->imported_symtabs_size ();
7083 /* Fill in 'dependencies' here; we fill in 'users' in a
7085 pst
->number_of_dependencies
= len
;
7087 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7088 for (i
= 0; i
< len
; ++i
)
7090 pst
->dependencies
[i
]
7091 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7094 cu
->per_cu
->imported_symtabs_free ();
7097 /* Get the list of files included in the current compilation unit,
7098 and build a psymtab for each of them. */
7099 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, fnd
, pst
);
7101 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7102 ", %d global, %d static syms",
7103 per_cu
->is_debug_types
? "type" : "comp",
7104 sect_offset_str (per_cu
->sect_off
),
7105 paddress (gdbarch
, pst
->text_low (objfile
)),
7106 paddress (gdbarch
, pst
->text_high (objfile
)),
7107 (int) pst
->global_psymbols
.size (),
7108 (int) pst
->static_psymbols
.size ());
7111 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7112 Process compilation unit THIS_CU for a psymtab. */
7115 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7116 dwarf2_per_objfile
*per_objfile
,
7117 bool want_partial_unit
,
7118 enum language pretend_language
)
7120 /* If this compilation unit was already read in, free the
7121 cached copy in order to read it in again. This is
7122 necessary because we skipped some symbols when we first
7123 read in the compilation unit (see load_partial_dies).
7124 This problem could be avoided, but the benefit is unclear. */
7125 per_objfile
->remove_cu (this_cu
);
7127 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7129 if (reader
.comp_unit_die
== nullptr)
7132 switch (reader
.comp_unit_die
->tag
)
7134 case DW_TAG_compile_unit
:
7135 this_cu
->unit_type
= DW_UT_compile
;
7137 case DW_TAG_partial_unit
:
7138 this_cu
->unit_type
= DW_UT_partial
;
7140 case DW_TAG_type_unit
:
7141 this_cu
->unit_type
= DW_UT_type
;
7144 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7145 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7146 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7147 objfile_name (per_objfile
->objfile
));
7154 else if (this_cu
->is_debug_types
)
7155 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7156 reader
.comp_unit_die
);
7157 else if (want_partial_unit
7158 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7159 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7160 reader
.comp_unit_die
,
7163 /* Age out any secondary CUs. */
7164 per_objfile
->age_comp_units ();
7167 /* Reader function for build_type_psymtabs. */
7170 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7171 const gdb_byte
*info_ptr
,
7172 struct die_info
*type_unit_die
)
7174 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7175 struct dwarf2_cu
*cu
= reader
->cu
;
7176 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7177 struct signatured_type
*sig_type
;
7178 struct type_unit_group
*tu_group
;
7179 struct attribute
*attr
;
7180 struct partial_die_info
*first_die
;
7181 CORE_ADDR lowpc
, highpc
;
7182 dwarf2_psymtab
*pst
;
7184 gdb_assert (per_cu
->is_debug_types
);
7185 sig_type
= (struct signatured_type
*) per_cu
;
7187 if (! type_unit_die
->has_children
)
7190 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7191 tu_group
= get_type_unit_group (cu
, attr
);
7193 if (tu_group
->tus
== nullptr)
7194 tu_group
->tus
= new std::vector
<signatured_type
*>;
7195 tu_group
->tus
->push_back (sig_type
);
7197 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7198 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7199 pst
->anonymous
= true;
7201 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7203 lowpc
= (CORE_ADDR
) -1;
7204 highpc
= (CORE_ADDR
) 0;
7205 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7210 /* Struct used to sort TUs by their abbreviation table offset. */
7212 struct tu_abbrev_offset
7214 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7215 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7218 /* This is used when sorting. */
7219 bool operator< (const tu_abbrev_offset
&other
) const
7221 return abbrev_offset
< other
.abbrev_offset
;
7224 signatured_type
*sig_type
;
7225 sect_offset abbrev_offset
;
7228 /* Efficiently read all the type units.
7230 The efficiency is because we sort TUs by the abbrev table they use and
7231 only read each abbrev table once. In one program there are 200K TUs
7232 sharing 8K abbrev tables.
7234 The main purpose of this function is to support building the
7235 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7236 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7237 can collapse the search space by grouping them by stmt_list.
7238 The savings can be significant, in the same program from above the 200K TUs
7239 share 8K stmt_list tables.
7241 FUNC is expected to call get_type_unit_group, which will create the
7242 struct type_unit_group if necessary and add it to
7243 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7246 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7248 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7249 abbrev_table_up abbrev_table
;
7250 sect_offset abbrev_offset
;
7252 /* It's up to the caller to not call us multiple times. */
7253 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7255 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7258 /* TUs typically share abbrev tables, and there can be way more TUs than
7259 abbrev tables. Sort by abbrev table to reduce the number of times we
7260 read each abbrev table in.
7261 Alternatives are to punt or to maintain a cache of abbrev tables.
7262 This is simpler and efficient enough for now.
7264 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7265 symtab to use). Typically TUs with the same abbrev offset have the same
7266 stmt_list value too so in practice this should work well.
7268 The basic algorithm here is:
7270 sort TUs by abbrev table
7271 for each TU with same abbrev table:
7272 read abbrev table if first user
7273 read TU top level DIE
7274 [IWBN if DWO skeletons had DW_AT_stmt_list]
7277 dwarf_read_debug_printf ("Building type unit groups ...");
7279 /* Sort in a separate table to maintain the order of all_comp_units
7280 for .gdb_index: TU indices directly index all_type_units. */
7281 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7282 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7284 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7286 if (cu
->is_debug_types
)
7288 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7289 sorted_by_abbrev
.emplace_back
7290 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7291 sig_type
->sect_off
));
7295 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7297 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7299 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7301 /* Switch to the next abbrev table if necessary. */
7302 if (abbrev_table
== NULL
7303 || tu
.abbrev_offset
!= abbrev_offset
)
7305 abbrev_offset
= tu
.abbrev_offset
;
7306 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7308 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7309 ++tu_stats
->nr_uniq_abbrev_tables
;
7312 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7313 abbrev_table
.get (), nullptr, false);
7314 if (!reader
.dummy_p
)
7315 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7316 reader
.comp_unit_die
);
7320 /* Print collected type unit statistics. */
7323 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7325 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7327 dwarf_read_debug_printf ("Type unit statistics:");
7328 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7329 dwarf_read_debug_printf (" %d uniq abbrev tables",
7330 tu_stats
->nr_uniq_abbrev_tables
);
7331 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7332 tu_stats
->nr_symtabs
);
7333 dwarf_read_debug_printf (" %d symtab sharers",
7334 tu_stats
->nr_symtab_sharers
);
7335 dwarf_read_debug_printf (" %d type units without a stmt_list",
7336 tu_stats
->nr_stmt_less_type_units
);
7337 dwarf_read_debug_printf (" %d all_type_units reallocs",
7338 tu_stats
->nr_all_type_units_reallocs
);
7341 /* Traversal function for build_type_psymtabs. */
7344 build_type_psymtab_dependencies (void **slot
, void *info
)
7346 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7347 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7348 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7349 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7350 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7353 gdb_assert (len
> 0);
7354 gdb_assert (tu_group
->type_unit_group_p ());
7356 pst
->number_of_dependencies
= len
;
7357 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7358 for (i
= 0; i
< len
; ++i
)
7360 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7361 gdb_assert (iter
->is_debug_types
);
7362 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7363 iter
->type_unit_group
= tu_group
;
7366 delete tu_group
->tus
;
7367 tu_group
->tus
= nullptr;
7372 /* Traversal function for process_skeletonless_type_unit.
7373 Read a TU in a DWO file and build partial symbols for it. */
7376 process_skeletonless_type_unit (void **slot
, void *info
)
7378 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7379 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7381 /* If this TU doesn't exist in the global table, add it and read it in. */
7383 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7384 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7386 signatured_type
find_entry (dwo_unit
->signature
);
7387 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7388 &find_entry
, INSERT
);
7389 /* If we've already seen this type there's nothing to do. What's happening
7390 is we're doing our own version of comdat-folding here. */
7394 /* This does the job that create_all_comp_units would have done for
7396 signatured_type
*entry
7397 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7398 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7401 /* This does the job that build_type_psymtabs would have done. */
7402 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7403 if (!reader
.dummy_p
)
7404 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7405 reader
.comp_unit_die
);
7410 /* Traversal function for process_skeletonless_type_units. */
7413 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7415 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7417 if (dwo_file
->tus
!= NULL
)
7418 htab_traverse_noresize (dwo_file
->tus
.get (),
7419 process_skeletonless_type_unit
, info
);
7424 /* Scan all TUs of DWO files, verifying we've processed them.
7425 This is needed in case a TU was emitted without its skeleton.
7426 Note: This can't be done until we know what all the DWO files are. */
7429 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7431 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7432 if (get_dwp_file (per_objfile
) == NULL
7433 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7435 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7436 process_dwo_file_for_skeletonless_type_units
,
7441 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7444 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7446 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7448 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7453 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7455 /* Set the 'user' field only if it is not already set. */
7456 if (pst
->dependencies
[j
]->user
== NULL
)
7457 pst
->dependencies
[j
]->user
= pst
;
7462 /* Build the partial symbol table by doing a quick pass through the
7463 .debug_info and .debug_abbrev sections. */
7466 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7468 struct objfile
*objfile
= per_objfile
->objfile
;
7469 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7471 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7472 objfile_name (objfile
));
7474 scoped_restore restore_reading_psyms
7475 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7477 per_bfd
->info
.read (objfile
);
7479 /* Any cached compilation units will be linked by the per-objfile
7480 read_in_chain. Make sure to free them when we're done. */
7481 free_cached_comp_units
freer (per_objfile
);
7483 create_all_comp_units (per_objfile
);
7484 build_type_psymtabs (per_objfile
);
7486 /* Create a temporary address map on a temporary obstack. We later
7487 copy this to the final obstack. */
7488 auto_obstack temp_obstack
;
7490 scoped_restore save_psymtabs_addrmap
7491 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7492 addrmap_create_mutable (&temp_obstack
));
7494 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7496 if (per_cu
->v
.psymtab
!= NULL
)
7497 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7499 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7503 /* This has to wait until we read the CUs, we need the list of DWOs. */
7504 process_skeletonless_type_units (per_objfile
);
7506 /* Now that all TUs have been processed we can fill in the dependencies. */
7507 if (per_bfd
->type_unit_groups
!= NULL
)
7509 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7510 build_type_psymtab_dependencies
, per_objfile
);
7513 if (dwarf_read_debug
> 0)
7514 print_tu_stats (per_objfile
);
7516 set_partial_user (per_objfile
);
7518 per_bfd
->partial_symtabs
->psymtabs_addrmap
7519 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7520 per_bfd
->partial_symtabs
->obstack ());
7521 /* At this point we want to keep the address map. */
7522 save_psymtabs_addrmap
.release ();
7524 dwarf_read_debug_printf ("Done building psymtabs of %s",
7525 objfile_name (objfile
));
7528 /* Load the partial DIEs for a secondary CU into memory.
7529 This is also used when rereading a primary CU with load_all_dies. */
7532 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7533 dwarf2_per_objfile
*per_objfile
,
7534 dwarf2_cu
*existing_cu
)
7536 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7538 if (!reader
.dummy_p
)
7540 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7543 /* Check if comp unit has_children.
7544 If so, read the rest of the partial symbols from this comp unit.
7545 If not, there's no more debug_info for this comp unit. */
7546 if (reader
.comp_unit_die
->has_children
)
7547 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7554 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7555 struct dwarf2_section_info
*section
,
7556 struct dwarf2_section_info
*abbrev_section
,
7557 unsigned int is_dwz
,
7558 htab_up
&types_htab
,
7559 rcuh_kind section_kind
)
7561 const gdb_byte
*info_ptr
;
7562 struct objfile
*objfile
= per_objfile
->objfile
;
7564 dwarf_read_debug_printf ("Reading %s for %s",
7565 section
->get_name (),
7566 section
->get_file_name ());
7568 section
->read (objfile
);
7570 info_ptr
= section
->buffer
;
7572 while (info_ptr
< section
->buffer
+ section
->size
)
7574 dwarf2_per_cu_data_up this_cu
;
7576 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7578 comp_unit_head cu_header
;
7579 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7580 abbrev_section
, info_ptr
,
7583 /* Save the compilation unit for later lookup. */
7584 if (cu_header
.unit_type
!= DW_UT_type
)
7585 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7588 if (types_htab
== nullptr)
7589 types_htab
= allocate_signatured_type_table ();
7591 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7592 (cu_header
.signature
);
7593 signatured_type
*sig_ptr
= sig_type
.get ();
7594 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7595 this_cu
.reset (sig_type
.release ());
7597 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7598 gdb_assert (slot
!= nullptr);
7599 if (*slot
!= nullptr)
7600 complaint (_("debug type entry at offset %s is duplicate to"
7601 " the entry at offset %s, signature %s"),
7602 sect_offset_str (sect_off
),
7603 sect_offset_str (sig_ptr
->sect_off
),
7604 hex_string (sig_ptr
->signature
));
7607 this_cu
->sect_off
= sect_off
;
7608 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7609 this_cu
->is_dwz
= is_dwz
;
7610 this_cu
->section
= section
;
7612 info_ptr
= info_ptr
+ this_cu
->length
;
7613 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7617 /* Create a list of all compilation units in OBJFILE.
7618 This is only done for -readnow and building partial symtabs. */
7621 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7625 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7626 &per_objfile
->per_bfd
->abbrev
, 0,
7627 types_htab
, rcuh_kind::COMPILE
);
7628 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7629 read_comp_units_from_section (per_objfile
, §ion
,
7630 &per_objfile
->per_bfd
->abbrev
, 0,
7631 types_htab
, rcuh_kind::TYPE
);
7633 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7635 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7636 types_htab
, rcuh_kind::COMPILE
);
7638 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7641 /* Process all loaded DIEs for compilation unit CU, starting at
7642 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7643 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7644 DW_AT_ranges). See the comments of add_partial_subprogram on how
7645 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7648 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7649 CORE_ADDR
*highpc
, int set_addrmap
,
7650 struct dwarf2_cu
*cu
)
7652 struct partial_die_info
*pdi
;
7654 /* Now, march along the PDI's, descending into ones which have
7655 interesting children but skipping the children of the other ones,
7656 until we reach the end of the compilation unit. */
7664 /* Anonymous namespaces or modules have no name but have interesting
7665 children, so we need to look at them. Ditto for anonymous
7668 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7669 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7670 || pdi
->tag
== DW_TAG_imported_unit
7671 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7675 case DW_TAG_subprogram
:
7676 case DW_TAG_inlined_subroutine
:
7677 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7678 if (cu
->per_cu
->lang
== language_cplus
)
7679 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7682 case DW_TAG_constant
:
7683 case DW_TAG_variable
:
7684 case DW_TAG_typedef
:
7685 case DW_TAG_union_type
:
7686 if (!pdi
->is_declaration
7687 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7689 add_partial_symbol (pdi
, cu
);
7692 case DW_TAG_class_type
:
7693 case DW_TAG_interface_type
:
7694 case DW_TAG_structure_type
:
7695 if (!pdi
->is_declaration
)
7697 add_partial_symbol (pdi
, cu
);
7699 if ((cu
->per_cu
->lang
== language_rust
7700 || cu
->per_cu
->lang
== language_cplus
)
7701 && pdi
->has_children
)
7702 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7705 case DW_TAG_enumeration_type
:
7706 if (!pdi
->is_declaration
)
7707 add_partial_enumeration (pdi
, cu
);
7709 case DW_TAG_base_type
:
7710 case DW_TAG_subrange_type
:
7711 /* File scope base type definitions are added to the partial
7713 add_partial_symbol (pdi
, cu
);
7715 case DW_TAG_namespace
:
7716 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7719 if (!pdi
->is_declaration
)
7720 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7722 case DW_TAG_imported_unit
:
7724 struct dwarf2_per_cu_data
*per_cu
;
7726 /* For now we don't handle imported units in type units. */
7727 if (cu
->per_cu
->is_debug_types
)
7729 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7730 " supported in type units [in module %s]"),
7731 objfile_name (cu
->per_objfile
->objfile
));
7734 per_cu
= dwarf2_find_containing_comp_unit
7735 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7737 /* Go read the partial unit, if needed. */
7738 if (per_cu
->v
.psymtab
== NULL
)
7739 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7742 if (pdi
->die_parent
== nullptr
7743 && per_cu
->unit_type
== DW_UT_compile
7744 && per_cu
->lang
== language_cplus
)
7745 /* Regard import as hint. See corresponding code in
7746 process_imported_unit_die. */
7749 cu
->per_cu
->imported_symtabs_push (per_cu
);
7752 case DW_TAG_imported_declaration
:
7753 add_partial_symbol (pdi
, cu
);
7760 /* If the die has a sibling, skip to the sibling. */
7762 pdi
= pdi
->die_sibling
;
7766 /* Functions used to compute the fully scoped name of a partial DIE.
7768 Normally, this is simple. For C++, the parent DIE's fully scoped
7769 name is concatenated with "::" and the partial DIE's name.
7770 Enumerators are an exception; they use the scope of their parent
7771 enumeration type, i.e. the name of the enumeration type is not
7772 prepended to the enumerator.
7774 There are two complexities. One is DW_AT_specification; in this
7775 case "parent" means the parent of the target of the specification,
7776 instead of the direct parent of the DIE. The other is compilers
7777 which do not emit DW_TAG_namespace; in this case we try to guess
7778 the fully qualified name of structure types from their members'
7779 linkage names. This must be done using the DIE's children rather
7780 than the children of any DW_AT_specification target. We only need
7781 to do this for structures at the top level, i.e. if the target of
7782 any DW_AT_specification (if any; otherwise the DIE itself) does not
7785 /* Compute the scope prefix associated with PDI's parent, in
7786 compilation unit CU. The result will be allocated on CU's
7787 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7788 field. NULL is returned if no prefix is necessary. */
7790 partial_die_parent_scope (struct partial_die_info
*pdi
,
7791 struct dwarf2_cu
*cu
)
7793 const char *grandparent_scope
;
7794 struct partial_die_info
*parent
, *real_pdi
;
7796 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7797 then this means the parent of the specification DIE. */
7800 while (real_pdi
->has_specification
)
7802 auto res
= find_partial_die (real_pdi
->spec_offset
,
7803 real_pdi
->spec_is_dwz
, cu
);
7808 parent
= real_pdi
->die_parent
;
7812 if (parent
->scope_set
)
7813 return parent
->scope
;
7817 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7819 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7820 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7821 Work around this problem here. */
7822 if (cu
->per_cu
->lang
== language_cplus
7823 && parent
->tag
== DW_TAG_namespace
7824 && strcmp (parent
->name (cu
), "::") == 0
7825 && grandparent_scope
== NULL
)
7827 parent
->scope
= NULL
;
7828 parent
->scope_set
= 1;
7832 /* Nested subroutines in Fortran get a prefix. */
7833 if (pdi
->tag
== DW_TAG_enumerator
)
7834 /* Enumerators should not get the name of the enumeration as a prefix. */
7835 parent
->scope
= grandparent_scope
;
7836 else if (parent
->tag
== DW_TAG_namespace
7837 || parent
->tag
== DW_TAG_module
7838 || parent
->tag
== DW_TAG_structure_type
7839 || parent
->tag
== DW_TAG_class_type
7840 || parent
->tag
== DW_TAG_interface_type
7841 || parent
->tag
== DW_TAG_union_type
7842 || parent
->tag
== DW_TAG_enumeration_type
7843 || (cu
->per_cu
->lang
== language_fortran
7844 && parent
->tag
== DW_TAG_subprogram
7845 && pdi
->tag
== DW_TAG_subprogram
))
7847 if (grandparent_scope
== NULL
)
7848 parent
->scope
= parent
->name (cu
);
7850 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7852 parent
->name (cu
), 0, cu
);
7856 /* FIXME drow/2004-04-01: What should we be doing with
7857 function-local names? For partial symbols, we should probably be
7859 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7860 dwarf_tag_name (parent
->tag
),
7861 sect_offset_str (pdi
->sect_off
));
7862 parent
->scope
= grandparent_scope
;
7865 parent
->scope_set
= 1;
7866 return parent
->scope
;
7869 /* Return the fully scoped name associated with PDI, from compilation unit
7870 CU. The result will be allocated with malloc. */
7872 static gdb::unique_xmalloc_ptr
<char>
7873 partial_die_full_name (struct partial_die_info
*pdi
,
7874 struct dwarf2_cu
*cu
)
7876 const char *parent_scope
;
7878 /* If this is a template instantiation, we can not work out the
7879 template arguments from partial DIEs. So, unfortunately, we have
7880 to go through the full DIEs. At least any work we do building
7881 types here will be reused if full symbols are loaded later. */
7882 if (pdi
->has_template_arguments
)
7886 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7888 struct die_info
*die
;
7889 struct attribute attr
;
7890 struct dwarf2_cu
*ref_cu
= cu
;
7892 /* DW_FORM_ref_addr is using section offset. */
7893 attr
.name
= (enum dwarf_attribute
) 0;
7894 attr
.form
= DW_FORM_ref_addr
;
7895 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7896 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7898 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7902 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7903 if (parent_scope
== NULL
)
7906 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7912 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7914 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7915 struct objfile
*objfile
= per_objfile
->objfile
;
7916 struct gdbarch
*gdbarch
= objfile
->arch ();
7918 const char *actual_name
= NULL
;
7921 baseaddr
= objfile
->text_section_offset ();
7923 gdb::unique_xmalloc_ptr
<char> built_actual_name
7924 = partial_die_full_name (pdi
, cu
);
7925 if (built_actual_name
!= NULL
)
7926 actual_name
= built_actual_name
.get ();
7928 if (actual_name
== NULL
)
7929 actual_name
= pdi
->name (cu
);
7931 partial_symbol psymbol
;
7932 memset (&psymbol
, 0, sizeof (psymbol
));
7933 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7934 &objfile
->objfile_obstack
);
7935 psymbol
.ginfo
.set_section_index (-1);
7937 /* The code below indicates that the psymbol should be installed by
7939 gdb::optional
<psymbol_placement
> where
;
7943 case DW_TAG_inlined_subroutine
:
7944 case DW_TAG_subprogram
:
7945 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7947 if (pdi
->is_external
7948 || cu
->per_cu
->lang
== language_ada
7949 || (cu
->per_cu
->lang
== language_fortran
7950 && pdi
->die_parent
!= NULL
7951 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7953 /* Normally, only "external" DIEs are part of the global scope.
7954 But in Ada and Fortran, we want to be able to access nested
7955 procedures globally. So all Ada and Fortran subprograms are
7956 stored in the global scope. */
7957 where
= psymbol_placement::GLOBAL
;
7960 where
= psymbol_placement::STATIC
;
7962 psymbol
.domain
= VAR_DOMAIN
;
7963 psymbol
.aclass
= LOC_BLOCK
;
7964 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7965 psymbol
.ginfo
.value
.address
= addr
;
7967 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7968 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7970 case DW_TAG_constant
:
7971 psymbol
.domain
= VAR_DOMAIN
;
7972 psymbol
.aclass
= LOC_STATIC
;
7973 where
= (pdi
->is_external
7974 ? psymbol_placement::GLOBAL
7975 : psymbol_placement::STATIC
);
7977 case DW_TAG_variable
:
7979 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7983 && !per_objfile
->per_bfd
->has_section_at_zero
)
7985 /* A global or static variable may also have been stripped
7986 out by the linker if unused, in which case its address
7987 will be nullified; do not add such variables into partial
7988 symbol table then. */
7990 else if (pdi
->is_external
)
7993 Don't enter into the minimal symbol tables as there is
7994 a minimal symbol table entry from the ELF symbols already.
7995 Enter into partial symbol table if it has a location
7996 descriptor or a type.
7997 If the location descriptor is missing, new_symbol will create
7998 a LOC_UNRESOLVED symbol, the address of the variable will then
7999 be determined from the minimal symbol table whenever the variable
8001 The address for the partial symbol table entry is not
8002 used by GDB, but it comes in handy for debugging partial symbol
8005 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8007 psymbol
.domain
= VAR_DOMAIN
;
8008 psymbol
.aclass
= LOC_STATIC
;
8009 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8010 psymbol
.ginfo
.value
.address
= addr
;
8011 where
= psymbol_placement::GLOBAL
;
8016 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8018 /* Static Variable. Skip symbols whose value we cannot know (those
8019 without location descriptors or constant values). */
8020 if (!has_loc
&& !pdi
->has_const_value
)
8023 psymbol
.domain
= VAR_DOMAIN
;
8024 psymbol
.aclass
= LOC_STATIC
;
8025 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8027 psymbol
.ginfo
.value
.address
= addr
;
8028 where
= psymbol_placement::STATIC
;
8031 case DW_TAG_array_type
:
8032 case DW_TAG_typedef
:
8033 case DW_TAG_base_type
:
8034 case DW_TAG_subrange_type
:
8035 psymbol
.domain
= VAR_DOMAIN
;
8036 psymbol
.aclass
= LOC_TYPEDEF
;
8037 where
= psymbol_placement::STATIC
;
8039 case DW_TAG_imported_declaration
:
8040 case DW_TAG_namespace
:
8041 psymbol
.domain
= VAR_DOMAIN
;
8042 psymbol
.aclass
= LOC_TYPEDEF
;
8043 where
= psymbol_placement::GLOBAL
;
8046 /* With Fortran 77 there might be a "BLOCK DATA" module
8047 available without any name. If so, we skip the module as it
8048 doesn't bring any value. */
8049 if (actual_name
!= nullptr)
8051 psymbol
.domain
= MODULE_DOMAIN
;
8052 psymbol
.aclass
= LOC_TYPEDEF
;
8053 where
= psymbol_placement::GLOBAL
;
8056 case DW_TAG_class_type
:
8057 case DW_TAG_interface_type
:
8058 case DW_TAG_structure_type
:
8059 case DW_TAG_union_type
:
8060 case DW_TAG_enumeration_type
:
8061 /* Skip external references. The DWARF standard says in the section
8062 about "Structure, Union, and Class Type Entries": "An incomplete
8063 structure, union or class type is represented by a structure,
8064 union or class entry that does not have a byte size attribute
8065 and that has a DW_AT_declaration attribute." */
8066 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8069 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8070 static vs. global. */
8071 psymbol
.domain
= STRUCT_DOMAIN
;
8072 psymbol
.aclass
= LOC_TYPEDEF
;
8073 where
= (cu
->per_cu
->lang
== language_cplus
8074 ? psymbol_placement::GLOBAL
8075 : psymbol_placement::STATIC
);
8077 case DW_TAG_enumerator
:
8078 psymbol
.domain
= VAR_DOMAIN
;
8079 psymbol
.aclass
= LOC_CONST
;
8080 where
= (cu
->per_cu
->lang
== language_cplus
8081 ? psymbol_placement::GLOBAL
8082 : psymbol_placement::STATIC
);
8088 if (where
.has_value ())
8090 if (built_actual_name
!= nullptr)
8091 actual_name
= objfile
->intern (actual_name
);
8092 if (pdi
->linkage_name
== nullptr
8093 || cu
->per_cu
->lang
== language_ada
)
8094 psymbol
.ginfo
.set_linkage_name (actual_name
);
8097 psymbol
.ginfo
.set_demangled_name (actual_name
,
8098 &objfile
->objfile_obstack
);
8099 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8101 cu
->per_cu
->v
.psymtab
->add_psymbol
8102 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8107 /* Read a partial die corresponding to a namespace; also, add a symbol
8108 corresponding to that namespace to the symbol table. NAMESPACE is
8109 the name of the enclosing namespace. */
8112 add_partial_namespace (struct partial_die_info
*pdi
,
8113 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8114 int set_addrmap
, struct dwarf2_cu
*cu
)
8116 /* Add a symbol for the namespace. */
8118 add_partial_symbol (pdi
, cu
);
8120 /* Now scan partial symbols in that namespace. */
8122 if (pdi
->has_children
)
8123 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8126 /* Read a partial die corresponding to a Fortran module. */
8129 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8130 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8132 /* Add a symbol for the namespace. */
8134 add_partial_symbol (pdi
, cu
);
8136 /* Now scan partial symbols in that module. */
8138 if (pdi
->has_children
)
8139 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8143 dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
8144 dwarf2_psymtab
*, dwarf_tag
);
8146 /* Read a partial die corresponding to a subprogram or an inlined
8147 subprogram and create a partial symbol for that subprogram.
8148 When the CU language allows it, this routine also defines a partial
8149 symbol for each nested subprogram that this subprogram contains.
8150 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8151 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8153 PDI may also be a lexical block, in which case we simply search
8154 recursively for subprograms defined inside that lexical block.
8155 Again, this is only performed when the CU language allows this
8156 type of definitions. */
8159 add_partial_subprogram (struct partial_die_info
*pdi
,
8160 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8161 int set_addrmap
, struct dwarf2_cu
*cu
)
8163 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8165 if (pdi
->has_pc_info
)
8167 if (pdi
->lowpc
< *lowpc
)
8168 *lowpc
= pdi
->lowpc
;
8169 if (pdi
->highpc
> *highpc
)
8170 *highpc
= pdi
->highpc
;
8173 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8174 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8175 struct gdbarch
*gdbarch
= objfile
->arch ();
8177 CORE_ADDR this_highpc
;
8178 CORE_ADDR this_lowpc
;
8180 baseaddr
= objfile
->text_section_offset ();
8182 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8183 pdi
->lowpc
+ baseaddr
)
8186 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8187 pdi
->highpc
+ baseaddr
)
8189 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8190 this_lowpc
, this_highpc
- 1,
8191 cu
->per_cu
->v
.psymtab
);
8195 if (pdi
->has_range_info
8196 && dwarf2_ranges_read (pdi
->ranges_offset
, &pdi
->lowpc
, &pdi
->highpc
,
8198 set_addrmap
? cu
->per_cu
->v
.psymtab
: nullptr,
8201 if (pdi
->lowpc
< *lowpc
)
8202 *lowpc
= pdi
->lowpc
;
8203 if (pdi
->highpc
> *highpc
)
8204 *highpc
= pdi
->highpc
;
8207 if (pdi
->has_pc_info
|| pdi
->has_range_info
8208 || (!pdi
->is_external
&& pdi
->may_be_inlined
))
8210 if (!pdi
->is_declaration
)
8211 /* Ignore subprogram DIEs that do not have a name, they are
8212 illegal. Do not emit a complaint at this point, we will
8213 do so when we convert this psymtab into a symtab. */
8215 add_partial_symbol (pdi
, cu
);
8219 if (! pdi
->has_children
)
8222 if (cu
->per_cu
->lang
== language_ada
8223 || cu
->per_cu
->lang
== language_fortran
)
8225 pdi
= pdi
->die_child
;
8229 if (pdi
->tag
== DW_TAG_subprogram
8230 || pdi
->tag
== DW_TAG_inlined_subroutine
8231 || pdi
->tag
== DW_TAG_lexical_block
)
8232 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8233 pdi
= pdi
->die_sibling
;
8238 /* Read a partial die corresponding to an enumeration type. */
8241 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8242 struct dwarf2_cu
*cu
)
8244 struct partial_die_info
*pdi
;
8246 if (enum_pdi
->name (cu
) != NULL
)
8247 add_partial_symbol (enum_pdi
, cu
);
8249 pdi
= enum_pdi
->die_child
;
8252 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8253 complaint (_("malformed enumerator DIE ignored"));
8255 add_partial_symbol (pdi
, cu
);
8256 pdi
= pdi
->die_sibling
;
8260 /* Return the initial uleb128 in the die at INFO_PTR. */
8263 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8265 unsigned int bytes_read
;
8267 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8270 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8271 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8273 Return the corresponding abbrev, or NULL if the number is zero (indicating
8274 an empty DIE). In either case *BYTES_READ will be set to the length of
8275 the initial number. */
8277 static const struct abbrev_info
*
8278 peek_die_abbrev (const die_reader_specs
&reader
,
8279 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8281 dwarf2_cu
*cu
= reader
.cu
;
8282 bfd
*abfd
= reader
.abfd
;
8283 unsigned int abbrev_number
8284 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8286 if (abbrev_number
== 0)
8289 const abbrev_info
*abbrev
8290 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8293 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8294 " at offset %s [in module %s]"),
8295 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8296 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8302 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8303 Returns a pointer to the end of a series of DIEs, terminated by an empty
8304 DIE. Any children of the skipped DIEs will also be skipped. */
8306 static const gdb_byte
*
8307 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8311 unsigned int bytes_read
;
8312 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8316 return info_ptr
+ bytes_read
;
8318 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8322 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8323 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8324 abbrev corresponding to that skipped uleb128 should be passed in
8325 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8328 static const gdb_byte
*
8329 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8330 const struct abbrev_info
*abbrev
)
8332 unsigned int bytes_read
;
8333 struct attribute attr
;
8334 bfd
*abfd
= reader
->abfd
;
8335 struct dwarf2_cu
*cu
= reader
->cu
;
8336 const gdb_byte
*buffer
= reader
->buffer
;
8337 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8338 unsigned int form
, i
;
8340 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8342 /* The only abbrev we care about is DW_AT_sibling. */
8343 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8345 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8346 if (attr
.form
== DW_FORM_ref_addr
)
8347 complaint (_("ignoring absolute DW_AT_sibling"));
8350 sect_offset off
= attr
.get_ref_die_offset ();
8351 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8353 if (sibling_ptr
< info_ptr
)
8354 complaint (_("DW_AT_sibling points backwards"));
8355 else if (sibling_ptr
> reader
->buffer_end
)
8356 reader
->die_section
->overflow_complaint ();
8362 /* If it isn't DW_AT_sibling, skip this attribute. */
8363 form
= abbrev
->attrs
[i
].form
;
8367 case DW_FORM_ref_addr
:
8368 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8369 and later it is offset sized. */
8370 if (cu
->header
.version
== 2)
8371 info_ptr
+= cu
->header
.addr_size
;
8373 info_ptr
+= cu
->header
.offset_size
;
8375 case DW_FORM_GNU_ref_alt
:
8376 info_ptr
+= cu
->header
.offset_size
;
8379 info_ptr
+= cu
->header
.addr_size
;
8387 case DW_FORM_flag_present
:
8388 case DW_FORM_implicit_const
:
8405 case DW_FORM_ref_sig8
:
8408 case DW_FORM_data16
:
8411 case DW_FORM_string
:
8412 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8413 info_ptr
+= bytes_read
;
8415 case DW_FORM_sec_offset
:
8417 case DW_FORM_GNU_strp_alt
:
8418 info_ptr
+= cu
->header
.offset_size
;
8420 case DW_FORM_exprloc
:
8422 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8423 info_ptr
+= bytes_read
;
8425 case DW_FORM_block1
:
8426 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8428 case DW_FORM_block2
:
8429 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8431 case DW_FORM_block4
:
8432 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8438 case DW_FORM_ref_udata
:
8439 case DW_FORM_GNU_addr_index
:
8440 case DW_FORM_GNU_str_index
:
8441 case DW_FORM_rnglistx
:
8442 case DW_FORM_loclistx
:
8443 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8445 case DW_FORM_indirect
:
8446 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8447 info_ptr
+= bytes_read
;
8448 /* We need to continue parsing from here, so just go back to
8450 goto skip_attribute
;
8453 error (_("Dwarf Error: Cannot handle %s "
8454 "in DWARF reader [in module %s]"),
8455 dwarf_form_name (form
),
8456 bfd_get_filename (abfd
));
8460 if (abbrev
->has_children
)
8461 return skip_children (reader
, info_ptr
);
8466 /* Locate ORIG_PDI's sibling.
8467 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8469 static const gdb_byte
*
8470 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8471 struct partial_die_info
*orig_pdi
,
8472 const gdb_byte
*info_ptr
)
8474 /* Do we know the sibling already? */
8476 if (orig_pdi
->sibling
)
8477 return orig_pdi
->sibling
;
8479 /* Are there any children to deal with? */
8481 if (!orig_pdi
->has_children
)
8484 /* Skip the children the long way. */
8486 return skip_children (reader
, info_ptr
);
8489 /* Expand this partial symbol table into a full symbol table. SELF is
8493 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8495 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8497 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8499 /* If this psymtab is constructed from a debug-only objfile, the
8500 has_section_at_zero flag will not necessarily be correct. We
8501 can get the correct value for this flag by looking at the data
8502 associated with the (presumably stripped) associated objfile. */
8503 if (objfile
->separate_debug_objfile_backlink
)
8505 dwarf2_per_objfile
*per_objfile_backlink
8506 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8508 per_objfile
->per_bfd
->has_section_at_zero
8509 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8512 expand_psymtab (objfile
);
8514 process_cu_includes (per_objfile
);
8517 /* Reading in full CUs. */
8519 /* Add PER_CU to the queue. */
8522 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8523 dwarf2_per_objfile
*per_objfile
,
8524 enum language pretend_language
)
8528 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8529 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8532 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8534 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8537 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8538 DIEs, false otherwise.
8540 Explanation: there is an invariant that if a CU is queued for expansion
8541 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8542 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8543 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8544 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8545 invariant is respected.
8547 The caller is therefore not required to load the CU's DIEs (we return false)
8550 - the CU is already expanded, and therefore does not get enqueued
8551 - the CU gets enqueued for expansion, but its DIEs are already loaded
8553 Note that the caller should not use this function's return value as an
8554 indicator of whether the CU's DIEs are loaded right now, it should check
8555 that by calling `dwarf2_per_objfile::get_cu` instead. */
8558 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8559 dwarf2_per_cu_data
*per_cu
,
8560 dwarf2_per_objfile
*per_objfile
,
8561 enum language pretend_language
)
8563 /* We may arrive here during partial symbol reading, if we need full
8564 DIEs to process an unusual case (e.g. template arguments). Do
8565 not queue PER_CU, just tell our caller to load its DIEs. */
8566 if (per_cu
->per_bfd
->reading_partial_symbols
)
8568 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8570 if (cu
== NULL
|| cu
->dies
== NULL
)
8575 /* Mark the dependence relation so that we don't flush PER_CU
8577 if (dependent_cu
!= NULL
)
8578 dependent_cu
->add_dependence (per_cu
);
8580 /* If it's already on the queue, we have nothing to do. */
8583 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8585 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8587 /* If the CU is queued for expansion, it should not already be
8589 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8591 /* The DIEs are already loaded, the caller doesn't need to do it. */
8595 bool queued
= false;
8596 if (!per_objfile
->symtab_set_p (per_cu
))
8598 /* Add it to the queue. */
8599 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8603 /* If the compilation unit is already loaded, just mark it as
8605 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8609 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8610 and the DIEs are not already loaded. */
8611 return queued
&& cu
== nullptr;
8614 /* Process the queue. */
8617 process_queue (dwarf2_per_objfile
*per_objfile
)
8619 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8620 objfile_name (per_objfile
->objfile
));
8622 /* The queue starts out with one item, but following a DIE reference
8623 may load a new CU, adding it to the end of the queue. */
8624 while (!per_objfile
->per_bfd
->queue
->empty ())
8626 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8627 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8629 if (!per_objfile
->symtab_set_p (per_cu
))
8631 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8633 /* Skip dummy CUs. */
8636 unsigned int debug_print_threshold
;
8639 if (per_cu
->is_debug_types
)
8641 struct signatured_type
*sig_type
=
8642 (struct signatured_type
*) per_cu
;
8644 sprintf (buf
, "TU %s at offset %s",
8645 hex_string (sig_type
->signature
),
8646 sect_offset_str (per_cu
->sect_off
));
8647 /* There can be 100s of TUs.
8648 Only print them in verbose mode. */
8649 debug_print_threshold
= 2;
8653 sprintf (buf
, "CU at offset %s",
8654 sect_offset_str (per_cu
->sect_off
));
8655 debug_print_threshold
= 1;
8658 if (dwarf_read_debug
>= debug_print_threshold
)
8659 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8661 if (per_cu
->is_debug_types
)
8662 process_full_type_unit (cu
, item
.pretend_language
);
8664 process_full_comp_unit (cu
, item
.pretend_language
);
8666 if (dwarf_read_debug
>= debug_print_threshold
)
8667 dwarf_read_debug_printf ("Done expanding %s", buf
);
8672 per_objfile
->per_bfd
->queue
->pop ();
8675 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8676 objfile_name (per_objfile
->objfile
));
8679 /* Read in full symbols for PST, and anything it depends on. */
8682 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8684 gdb_assert (!readin_p (objfile
));
8686 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8687 free_cached_comp_units
freer (per_objfile
);
8688 expand_dependencies (objfile
);
8690 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8691 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8694 /* See psympriv.h. */
8697 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8699 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8700 return per_objfile
->symtab_set_p (per_cu_data
);
8703 /* See psympriv.h. */
8706 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8708 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8709 return per_objfile
->get_symtab (per_cu_data
);
8712 /* Trivial hash function for die_info: the hash value of a DIE
8713 is its offset in .debug_info for this objfile. */
8716 die_hash (const void *item
)
8718 const struct die_info
*die
= (const struct die_info
*) item
;
8720 return to_underlying (die
->sect_off
);
8723 /* Trivial comparison function for die_info structures: two DIEs
8724 are equal if they have the same offset. */
8727 die_eq (const void *item_lhs
, const void *item_rhs
)
8729 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8730 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8732 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8735 /* Load the DIEs associated with PER_CU into memory.
8737 In some cases, the caller, while reading partial symbols, will need to load
8738 the full symbols for the CU for some reason. It will already have a
8739 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8740 rather than creating a new one. */
8743 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8744 dwarf2_per_objfile
*per_objfile
,
8745 dwarf2_cu
*existing_cu
,
8747 enum language pretend_language
)
8749 gdb_assert (! this_cu
->is_debug_types
);
8751 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8755 struct dwarf2_cu
*cu
= reader
.cu
;
8756 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8758 gdb_assert (cu
->die_hash
== NULL
);
8760 htab_create_alloc_ex (cu
->header
.length
/ 12,
8764 &cu
->comp_unit_obstack
,
8765 hashtab_obstack_allocate
,
8766 dummy_obstack_deallocate
);
8768 if (reader
.comp_unit_die
->has_children
)
8769 reader
.comp_unit_die
->child
8770 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8771 &info_ptr
, reader
.comp_unit_die
);
8772 cu
->dies
= reader
.comp_unit_die
;
8773 /* comp_unit_die is not stored in die_hash, no need. */
8775 /* We try not to read any attributes in this function, because not
8776 all CUs needed for references have been loaded yet, and symbol
8777 table processing isn't initialized. But we have to set the CU language,
8778 or we won't be able to build types correctly.
8779 Similarly, if we do not read the producer, we can not apply
8780 producer-specific interpretation. */
8781 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8786 /* Add a DIE to the delayed physname list. */
8789 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8790 const char *name
, struct die_info
*die
,
8791 struct dwarf2_cu
*cu
)
8793 struct delayed_method_info mi
;
8795 mi
.fnfield_index
= fnfield_index
;
8799 cu
->method_list
.push_back (mi
);
8802 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8803 "const" / "volatile". If so, decrements LEN by the length of the
8804 modifier and return true. Otherwise return false. */
8808 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8810 size_t mod_len
= sizeof (mod
) - 1;
8811 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8819 /* Compute the physnames of any methods on the CU's method list.
8821 The computation of method physnames is delayed in order to avoid the
8822 (bad) condition that one of the method's formal parameters is of an as yet
8826 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8828 /* Only C++ delays computing physnames. */
8829 if (cu
->method_list
.empty ())
8831 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8833 for (const delayed_method_info
&mi
: cu
->method_list
)
8835 const char *physname
;
8836 struct fn_fieldlist
*fn_flp
8837 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8838 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8839 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8840 = physname
? physname
: "";
8842 /* Since there's no tag to indicate whether a method is a
8843 const/volatile overload, extract that information out of the
8845 if (physname
!= NULL
)
8847 size_t len
= strlen (physname
);
8851 if (physname
[len
] == ')') /* shortcut */
8853 else if (check_modifier (physname
, len
, " const"))
8854 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8855 else if (check_modifier (physname
, len
, " volatile"))
8856 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8863 /* The list is no longer needed. */
8864 cu
->method_list
.clear ();
8867 /* Go objects should be embedded in a DW_TAG_module DIE,
8868 and it's not clear if/how imported objects will appear.
8869 To keep Go support simple until that's worked out,
8870 go back through what we've read and create something usable.
8871 We could do this while processing each DIE, and feels kinda cleaner,
8872 but that way is more invasive.
8873 This is to, for example, allow the user to type "p var" or "b main"
8874 without having to specify the package name, and allow lookups
8875 of module.object to work in contexts that use the expression
8879 fixup_go_packaging (struct dwarf2_cu
*cu
)
8881 gdb::unique_xmalloc_ptr
<char> package_name
;
8882 struct pending
*list
;
8885 for (list
= *cu
->get_builder ()->get_global_symbols ();
8889 for (i
= 0; i
< list
->nsyms
; ++i
)
8891 struct symbol
*sym
= list
->symbol
[i
];
8893 if (sym
->language () == language_go
8894 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8896 gdb::unique_xmalloc_ptr
<char> this_package_name
8897 (go_symbol_package_name (sym
));
8899 if (this_package_name
== NULL
)
8901 if (package_name
== NULL
)
8902 package_name
= std::move (this_package_name
);
8905 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8906 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8907 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8908 (symbol_symtab (sym
) != NULL
8909 ? symtab_to_filename_for_display
8910 (symbol_symtab (sym
))
8911 : objfile_name (objfile
)),
8912 this_package_name
.get (), package_name
.get ());
8918 if (package_name
!= NULL
)
8920 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8921 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8922 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8923 saved_package_name
);
8926 sym
= new (&objfile
->objfile_obstack
) symbol
;
8927 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8928 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8929 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8930 e.g., "main" finds the "main" module and not C's main(). */
8931 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8932 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8933 SYMBOL_TYPE (sym
) = type
;
8935 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8939 /* Allocate a fully-qualified name consisting of the two parts on the
8943 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8945 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8948 /* A helper that allocates a variant part to attach to a Rust enum
8949 type. OBSTACK is where the results should be allocated. TYPE is
8950 the type we're processing. DISCRIMINANT_INDEX is the index of the
8951 discriminant. It must be the index of one of the fields of TYPE,
8952 or -1 to mean there is no discriminant (univariant enum).
8953 DEFAULT_INDEX is the index of the default field; or -1 if there is
8954 no default. RANGES is indexed by "effective" field number (the
8955 field index, but omitting the discriminant and default fields) and
8956 must hold the discriminant values used by the variants. Note that
8957 RANGES must have a lifetime at least as long as OBSTACK -- either
8958 already allocated on it, or static. */
8961 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8962 int discriminant_index
, int default_index
,
8963 gdb::array_view
<discriminant_range
> ranges
)
8965 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8966 gdb_assert (discriminant_index
== -1
8967 || (discriminant_index
>= 0
8968 && discriminant_index
< type
->num_fields ()));
8969 gdb_assert (default_index
== -1
8970 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8972 /* We have one variant for each non-discriminant field. */
8973 int n_variants
= type
->num_fields ();
8974 if (discriminant_index
!= -1)
8977 variant
*variants
= new (obstack
) variant
[n_variants
];
8980 for (int i
= 0; i
< type
->num_fields (); ++i
)
8982 if (i
== discriminant_index
)
8985 variants
[var_idx
].first_field
= i
;
8986 variants
[var_idx
].last_field
= i
+ 1;
8988 /* The default field does not need a range, but other fields do.
8989 We skipped the discriminant above. */
8990 if (i
!= default_index
)
8992 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8999 gdb_assert (range_idx
== ranges
.size ());
9000 gdb_assert (var_idx
== n_variants
);
9002 variant_part
*part
= new (obstack
) variant_part
;
9003 part
->discriminant_index
= discriminant_index
;
9004 /* If there is no discriminant, then whether it is signed is of no
9007 = (discriminant_index
== -1
9009 : type
->field (discriminant_index
).type ()->is_unsigned ());
9010 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9012 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9013 gdb::array_view
<variant_part
> *prop_value
9014 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9016 struct dynamic_prop prop
;
9017 prop
.set_variant_parts (prop_value
);
9019 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9022 /* Some versions of rustc emitted enums in an unusual way.
9024 Ordinary enums were emitted as unions. The first element of each
9025 structure in the union was named "RUST$ENUM$DISR". This element
9026 held the discriminant.
9028 These versions of Rust also implemented the "non-zero"
9029 optimization. When the enum had two values, and one is empty and
9030 the other holds a pointer that cannot be zero, the pointer is used
9031 as the discriminant, with a zero value meaning the empty variant.
9032 Here, the union's first member is of the form
9033 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9034 where the fieldnos are the indices of the fields that should be
9035 traversed in order to find the field (which may be several fields deep)
9036 and the variantname is the name of the variant of the case when the
9039 This function recognizes whether TYPE is of one of these forms,
9040 and, if so, smashes it to be a variant type. */
9043 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9045 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9047 /* We don't need to deal with empty enums. */
9048 if (type
->num_fields () == 0)
9051 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9052 if (type
->num_fields () == 1
9053 && startswith (type
->field (0).name (), RUST_ENUM_PREFIX
))
9055 const char *name
= type
->field (0).name () + strlen (RUST_ENUM_PREFIX
);
9057 /* Decode the field name to find the offset of the
9059 ULONGEST bit_offset
= 0;
9060 struct type
*field_type
= type
->field (0).type ();
9061 while (name
[0] >= '0' && name
[0] <= '9')
9064 unsigned long index
= strtoul (name
, &tail
, 10);
9067 || index
>= field_type
->num_fields ()
9068 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9069 != FIELD_LOC_KIND_BITPOS
))
9071 complaint (_("Could not parse Rust enum encoding string \"%s\""
9073 type
->field (0).name (),
9074 objfile_name (objfile
));
9079 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9080 field_type
= field_type
->field (index
).type ();
9083 /* Smash this type to be a structure type. We have to do this
9084 because the type has already been recorded. */
9085 type
->set_code (TYPE_CODE_STRUCT
);
9086 type
->set_num_fields (3);
9087 /* Save the field we care about. */
9088 struct field saved_field
= type
->field (0);
9090 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9092 /* Put the discriminant at index 0. */
9093 type
->field (0).set_type (field_type
);
9094 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9095 type
->field (0).set_name ("<<discriminant>>");
9096 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9098 /* The order of fields doesn't really matter, so put the real
9099 field at index 1 and the data-less field at index 2. */
9100 type
->field (1) = saved_field
;
9101 type
->field (1).set_name
9102 (rust_last_path_segment (type
->field (1).type ()->name ()));
9103 type
->field (1).type ()->set_name
9104 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9105 type
->field (1).name ()));
9107 const char *dataless_name
9108 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9110 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9112 type
->field (2).set_type (dataless_type
);
9113 /* NAME points into the original discriminant name, which
9114 already has the correct lifetime. */
9115 type
->field (2).set_name (name
);
9116 SET_FIELD_BITPOS (type
->field (2), 0);
9118 /* Indicate that this is a variant type. */
9119 static discriminant_range ranges
[1] = { { 0, 0 } };
9120 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9122 /* A union with a single anonymous field is probably an old-style
9124 else if (type
->num_fields () == 1 && streq (type
->field (0).name (), ""))
9126 /* Smash this type to be a structure type. We have to do this
9127 because the type has already been recorded. */
9128 type
->set_code (TYPE_CODE_STRUCT
);
9130 struct type
*field_type
= type
->field (0).type ();
9131 const char *variant_name
9132 = rust_last_path_segment (field_type
->name ());
9133 type
->field (0).set_name (variant_name
);
9134 field_type
->set_name
9135 (rust_fully_qualify (&objfile
->objfile_obstack
,
9136 type
->name (), variant_name
));
9138 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9142 struct type
*disr_type
= nullptr;
9143 for (int i
= 0; i
< type
->num_fields (); ++i
)
9145 disr_type
= type
->field (i
).type ();
9147 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9149 /* All fields of a true enum will be structs. */
9152 else if (disr_type
->num_fields () == 0)
9154 /* Could be data-less variant, so keep going. */
9155 disr_type
= nullptr;
9157 else if (strcmp (disr_type
->field (0).name (),
9158 "RUST$ENUM$DISR") != 0)
9160 /* Not a Rust enum. */
9170 /* If we got here without a discriminant, then it's probably
9172 if (disr_type
== nullptr)
9175 /* Smash this type to be a structure type. We have to do this
9176 because the type has already been recorded. */
9177 type
->set_code (TYPE_CODE_STRUCT
);
9179 /* Make space for the discriminant field. */
9180 struct field
*disr_field
= &disr_type
->field (0);
9182 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9183 * sizeof (struct field
)));
9184 memcpy (new_fields
+ 1, type
->fields (),
9185 type
->num_fields () * sizeof (struct field
));
9186 type
->set_fields (new_fields
);
9187 type
->set_num_fields (type
->num_fields () + 1);
9189 /* Install the discriminant at index 0 in the union. */
9190 type
->field (0) = *disr_field
;
9191 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9192 type
->field (0).set_name ("<<discriminant>>");
9194 /* We need a way to find the correct discriminant given a
9195 variant name. For convenience we build a map here. */
9196 struct type
*enum_type
= disr_field
->type ();
9197 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9198 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9200 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9203 = rust_last_path_segment (enum_type
->field (i
).name ());
9204 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9208 int n_fields
= type
->num_fields ();
9209 /* We don't need a range entry for the discriminant, but we do
9210 need one for every other field, as there is no default
9212 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9215 /* Skip the discriminant here. */
9216 for (int i
= 1; i
< n_fields
; ++i
)
9218 /* Find the final word in the name of this variant's type.
9219 That name can be used to look up the correct
9221 const char *variant_name
9222 = rust_last_path_segment (type
->field (i
).type ()->name ());
9224 auto iter
= discriminant_map
.find (variant_name
);
9225 if (iter
!= discriminant_map
.end ())
9227 ranges
[i
- 1].low
= iter
->second
;
9228 ranges
[i
- 1].high
= iter
->second
;
9231 /* In Rust, each element should have the size of the
9233 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9235 /* Remove the discriminant field, if it exists. */
9236 struct type
*sub_type
= type
->field (i
).type ();
9237 if (sub_type
->num_fields () > 0)
9239 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9240 sub_type
->set_fields (sub_type
->fields () + 1);
9242 type
->field (i
).set_name (variant_name
);
9244 (rust_fully_qualify (&objfile
->objfile_obstack
,
9245 type
->name (), variant_name
));
9248 /* Indicate that this is a variant type. */
9249 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9250 gdb::array_view
<discriminant_range
> (ranges
,
9255 /* Rewrite some Rust unions to be structures with variants parts. */
9258 rust_union_quirks (struct dwarf2_cu
*cu
)
9260 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9261 for (type
*type_
: cu
->rust_unions
)
9262 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9263 /* We don't need this any more. */
9264 cu
->rust_unions
.clear ();
9269 type_unit_group_unshareable
*
9270 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9272 auto iter
= this->m_type_units
.find (tu_group
);
9273 if (iter
!= this->m_type_units
.end ())
9274 return iter
->second
.get ();
9276 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9277 type_unit_group_unshareable
*result
= uniq
.get ();
9278 this->m_type_units
[tu_group
] = std::move (uniq
);
9283 dwarf2_per_objfile::get_type_for_signatured_type
9284 (signatured_type
*sig_type
) const
9286 auto iter
= this->m_type_map
.find (sig_type
);
9287 if (iter
== this->m_type_map
.end ())
9290 return iter
->second
;
9293 void dwarf2_per_objfile::set_type_for_signatured_type
9294 (signatured_type
*sig_type
, struct type
*type
)
9296 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9298 this->m_type_map
[sig_type
] = type
;
9301 /* A helper function for computing the list of all symbol tables
9302 included by PER_CU. */
9305 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9306 htab_t all_children
, htab_t all_type_symtabs
,
9307 dwarf2_per_cu_data
*per_cu
,
9308 dwarf2_per_objfile
*per_objfile
,
9309 struct compunit_symtab
*immediate_parent
)
9311 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9314 /* This inclusion and its children have been processed. */
9320 /* Only add a CU if it has a symbol table. */
9321 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9324 /* If this is a type unit only add its symbol table if we haven't
9325 seen it yet (type unit per_cu's can share symtabs). */
9326 if (per_cu
->is_debug_types
)
9328 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9332 result
->push_back (cust
);
9333 if (cust
->user
== NULL
)
9334 cust
->user
= immediate_parent
;
9339 result
->push_back (cust
);
9340 if (cust
->user
== NULL
)
9341 cust
->user
= immediate_parent
;
9345 if (!per_cu
->imported_symtabs_empty ())
9346 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9348 recursively_compute_inclusions (result
, all_children
,
9349 all_type_symtabs
, ptr
, per_objfile
,
9354 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9358 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9359 dwarf2_per_objfile
*per_objfile
)
9361 gdb_assert (! per_cu
->is_debug_types
);
9363 if (!per_cu
->imported_symtabs_empty ())
9366 std::vector
<compunit_symtab
*> result_symtabs
;
9367 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9369 /* If we don't have a symtab, we can just skip this case. */
9373 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9375 NULL
, xcalloc
, xfree
));
9376 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9378 NULL
, xcalloc
, xfree
));
9380 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9382 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9383 all_type_symtabs
.get (), ptr
,
9387 /* Now we have a transitive closure of all the included symtabs. */
9388 len
= result_symtabs
.size ();
9390 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9391 struct compunit_symtab
*, len
+ 1);
9392 memcpy (cust
->includes
, result_symtabs
.data (),
9393 len
* sizeof (compunit_symtab
*));
9394 cust
->includes
[len
] = NULL
;
9398 /* Compute the 'includes' field for the symtabs of all the CUs we just
9402 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9404 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9406 if (! iter
->is_debug_types
)
9407 compute_compunit_symtab_includes (iter
, per_objfile
);
9410 per_objfile
->per_bfd
->just_read_cus
.clear ();
9413 /* Generate full symbol information for CU, whose DIEs have
9414 already been loaded into memory. */
9417 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9419 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9420 struct objfile
*objfile
= per_objfile
->objfile
;
9421 struct gdbarch
*gdbarch
= objfile
->arch ();
9422 CORE_ADDR lowpc
, highpc
;
9423 struct compunit_symtab
*cust
;
9425 struct block
*static_block
;
9428 baseaddr
= objfile
->text_section_offset ();
9430 /* Clear the list here in case something was left over. */
9431 cu
->method_list
.clear ();
9433 dwarf2_find_base_address (cu
->dies
, cu
);
9435 /* Before we start reading the top-level DIE, ensure it has a valid tag
9437 switch (cu
->dies
->tag
)
9439 case DW_TAG_compile_unit
:
9440 case DW_TAG_partial_unit
:
9441 case DW_TAG_type_unit
:
9444 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9445 dwarf_tag_name (cu
->dies
->tag
),
9446 sect_offset_str (cu
->per_cu
->sect_off
),
9447 objfile_name (per_objfile
->objfile
));
9450 /* Do line number decoding in read_file_scope () */
9451 process_die (cu
->dies
, cu
);
9453 /* For now fudge the Go package. */
9454 if (cu
->per_cu
->lang
== language_go
)
9455 fixup_go_packaging (cu
);
9457 /* Now that we have processed all the DIEs in the CU, all the types
9458 should be complete, and it should now be safe to compute all of the
9460 compute_delayed_physnames (cu
);
9462 if (cu
->per_cu
->lang
== language_rust
)
9463 rust_union_quirks (cu
);
9465 /* Some compilers don't define a DW_AT_high_pc attribute for the
9466 compilation unit. If the DW_AT_high_pc is missing, synthesize
9467 it, by scanning the DIE's below the compilation unit. */
9468 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9470 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9471 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9473 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9474 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9475 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9476 addrmap to help ensure it has an accurate map of pc values belonging to
9478 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9480 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9481 SECT_OFF_TEXT (objfile
),
9486 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9488 /* Set symtab language to language from DW_AT_language. If the
9489 compilation is from a C file generated by language preprocessors, do
9490 not set the language if it was already deduced by start_subfile. */
9491 if (!(cu
->per_cu
->lang
== language_c
9492 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9493 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9495 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9496 produce DW_AT_location with location lists but it can be possibly
9497 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9498 there were bugs in prologue debug info, fixed later in GCC-4.5
9499 by "unwind info for epilogues" patch (which is not directly related).
9501 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9502 needed, it would be wrong due to missing DW_AT_producer there.
9504 Still one can confuse GDB by using non-standard GCC compilation
9505 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9507 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9508 cust
->locations_valid
= 1;
9510 if (gcc_4_minor
>= 5)
9511 cust
->epilogue_unwind_valid
= 1;
9513 cust
->set_call_site_htab (cu
->call_site_htab
);
9516 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9518 /* Push it for inclusion processing later. */
9519 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9521 /* Not needed any more. */
9522 cu
->reset_builder ();
9525 /* Generate full symbol information for type unit CU, whose DIEs have
9526 already been loaded into memory. */
9529 process_full_type_unit (dwarf2_cu
*cu
,
9530 enum language pretend_language
)
9532 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9533 struct objfile
*objfile
= per_objfile
->objfile
;
9534 struct compunit_symtab
*cust
;
9535 struct signatured_type
*sig_type
;
9537 gdb_assert (cu
->per_cu
->is_debug_types
);
9538 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9540 /* Clear the list here in case something was left over. */
9541 cu
->method_list
.clear ();
9543 /* The symbol tables are set up in read_type_unit_scope. */
9544 process_die (cu
->dies
, cu
);
9546 /* For now fudge the Go package. */
9547 if (cu
->per_cu
->lang
== language_go
)
9548 fixup_go_packaging (cu
);
9550 /* Now that we have processed all the DIEs in the CU, all the types
9551 should be complete, and it should now be safe to compute all of the
9553 compute_delayed_physnames (cu
);
9555 if (cu
->per_cu
->lang
== language_rust
)
9556 rust_union_quirks (cu
);
9558 /* TUs share symbol tables.
9559 If this is the first TU to use this symtab, complete the construction
9560 of it with end_expandable_symtab. Otherwise, complete the addition of
9561 this TU's symbols to the existing symtab. */
9562 type_unit_group_unshareable
*tug_unshare
=
9563 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9564 if (tug_unshare
->compunit_symtab
== NULL
)
9566 buildsym_compunit
*builder
= cu
->get_builder ();
9567 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9568 tug_unshare
->compunit_symtab
= cust
;
9572 /* Set symtab language to language from DW_AT_language. If the
9573 compilation is from a C file generated by language preprocessors,
9574 do not set the language if it was already deduced by
9576 if (!(cu
->per_cu
->lang
== language_c
9577 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9578 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9583 cu
->get_builder ()->augment_type_symtab ();
9584 cust
= tug_unshare
->compunit_symtab
;
9587 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9589 /* Not needed any more. */
9590 cu
->reset_builder ();
9593 /* Process an imported unit DIE. */
9596 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9598 struct attribute
*attr
;
9600 /* For now we don't handle imported units in type units. */
9601 if (cu
->per_cu
->is_debug_types
)
9603 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9604 " supported in type units [in module %s]"),
9605 objfile_name (cu
->per_objfile
->objfile
));
9608 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9611 sect_offset sect_off
= attr
->get_ref_die_offset ();
9612 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9613 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9614 dwarf2_per_cu_data
*per_cu
9615 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9617 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9618 into another compilation unit, at root level. Regard this as a hint,
9620 if (die
->parent
&& die
->parent
->parent
== NULL
9621 && per_cu
->unit_type
== DW_UT_compile
9622 && per_cu
->lang
== language_cplus
)
9625 /* If necessary, add it to the queue and load its DIEs. */
9626 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9628 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9629 false, cu
->per_cu
->lang
);
9631 cu
->per_cu
->imported_symtabs_push (per_cu
);
9635 /* RAII object that represents a process_die scope: i.e.,
9636 starts/finishes processing a DIE. */
9637 class process_die_scope
9640 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9641 : m_die (die
), m_cu (cu
)
9643 /* We should only be processing DIEs not already in process. */
9644 gdb_assert (!m_die
->in_process
);
9645 m_die
->in_process
= true;
9648 ~process_die_scope ()
9650 m_die
->in_process
= false;
9652 /* If we're done processing the DIE for the CU that owns the line
9653 header, we don't need the line header anymore. */
9654 if (m_cu
->line_header_die_owner
== m_die
)
9656 delete m_cu
->line_header
;
9657 m_cu
->line_header
= NULL
;
9658 m_cu
->line_header_die_owner
= NULL
;
9667 /* Process a die and its children. */
9670 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9672 process_die_scope
scope (die
, cu
);
9676 case DW_TAG_padding
:
9678 case DW_TAG_compile_unit
:
9679 case DW_TAG_partial_unit
:
9680 read_file_scope (die
, cu
);
9682 case DW_TAG_type_unit
:
9683 read_type_unit_scope (die
, cu
);
9685 case DW_TAG_subprogram
:
9686 /* Nested subprograms in Fortran get a prefix. */
9687 if (cu
->per_cu
->lang
== language_fortran
9688 && die
->parent
!= NULL
9689 && die
->parent
->tag
== DW_TAG_subprogram
)
9690 cu
->processing_has_namespace_info
= true;
9692 case DW_TAG_inlined_subroutine
:
9693 read_func_scope (die
, cu
);
9695 case DW_TAG_lexical_block
:
9696 case DW_TAG_try_block
:
9697 case DW_TAG_catch_block
:
9698 read_lexical_block_scope (die
, cu
);
9700 case DW_TAG_call_site
:
9701 case DW_TAG_GNU_call_site
:
9702 read_call_site_scope (die
, cu
);
9704 case DW_TAG_class_type
:
9705 case DW_TAG_interface_type
:
9706 case DW_TAG_structure_type
:
9707 case DW_TAG_union_type
:
9708 process_structure_scope (die
, cu
);
9710 case DW_TAG_enumeration_type
:
9711 process_enumeration_scope (die
, cu
);
9714 /* These dies have a type, but processing them does not create
9715 a symbol or recurse to process the children. Therefore we can
9716 read them on-demand through read_type_die. */
9717 case DW_TAG_subroutine_type
:
9718 case DW_TAG_set_type
:
9719 case DW_TAG_pointer_type
:
9720 case DW_TAG_ptr_to_member_type
:
9721 case DW_TAG_reference_type
:
9722 case DW_TAG_rvalue_reference_type
:
9723 case DW_TAG_string_type
:
9726 case DW_TAG_array_type
:
9727 /* We only need to handle this case for Ada -- in other
9728 languages, it's normal for the compiler to emit a typedef
9730 if (cu
->per_cu
->lang
!= language_ada
)
9733 case DW_TAG_base_type
:
9734 case DW_TAG_subrange_type
:
9735 case DW_TAG_typedef
:
9736 /* Add a typedef symbol for the type definition, if it has a
9738 new_symbol (die
, read_type_die (die
, cu
), cu
);
9740 case DW_TAG_common_block
:
9741 read_common_block (die
, cu
);
9743 case DW_TAG_common_inclusion
:
9745 case DW_TAG_namespace
:
9746 cu
->processing_has_namespace_info
= true;
9747 read_namespace (die
, cu
);
9750 cu
->processing_has_namespace_info
= true;
9751 read_module (die
, cu
);
9753 case DW_TAG_imported_declaration
:
9754 cu
->processing_has_namespace_info
= true;
9755 if (read_namespace_alias (die
, cu
))
9757 /* The declaration is not a global namespace alias. */
9759 case DW_TAG_imported_module
:
9760 cu
->processing_has_namespace_info
= true;
9761 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9762 || cu
->per_cu
->lang
!= language_fortran
))
9763 complaint (_("Tag '%s' has unexpected children"),
9764 dwarf_tag_name (die
->tag
));
9765 read_import_statement (die
, cu
);
9768 case DW_TAG_imported_unit
:
9769 process_imported_unit_die (die
, cu
);
9772 case DW_TAG_variable
:
9773 read_variable (die
, cu
);
9777 new_symbol (die
, NULL
, cu
);
9782 /* DWARF name computation. */
9784 /* A helper function for dwarf2_compute_name which determines whether DIE
9785 needs to have the name of the scope prepended to the name listed in the
9789 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9791 struct attribute
*attr
;
9795 case DW_TAG_namespace
:
9796 case DW_TAG_typedef
:
9797 case DW_TAG_class_type
:
9798 case DW_TAG_interface_type
:
9799 case DW_TAG_structure_type
:
9800 case DW_TAG_union_type
:
9801 case DW_TAG_enumeration_type
:
9802 case DW_TAG_enumerator
:
9803 case DW_TAG_subprogram
:
9804 case DW_TAG_inlined_subroutine
:
9806 case DW_TAG_imported_declaration
:
9809 case DW_TAG_variable
:
9810 case DW_TAG_constant
:
9811 /* We only need to prefix "globally" visible variables. These include
9812 any variable marked with DW_AT_external or any variable that
9813 lives in a namespace. [Variables in anonymous namespaces
9814 require prefixing, but they are not DW_AT_external.] */
9816 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9818 struct dwarf2_cu
*spec_cu
= cu
;
9820 return die_needs_namespace (die_specification (die
, &spec_cu
),
9824 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9825 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9826 && die
->parent
->tag
!= DW_TAG_module
)
9828 /* A variable in a lexical block of some kind does not need a
9829 namespace, even though in C++ such variables may be external
9830 and have a mangled name. */
9831 if (die
->parent
->tag
== DW_TAG_lexical_block
9832 || die
->parent
->tag
== DW_TAG_try_block
9833 || die
->parent
->tag
== DW_TAG_catch_block
9834 || die
->parent
->tag
== DW_TAG_subprogram
)
9843 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9844 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9845 defined for the given DIE. */
9847 static struct attribute
*
9848 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9850 struct attribute
*attr
;
9852 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9854 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9859 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9860 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9861 defined for the given DIE. */
9864 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9866 const char *linkage_name
;
9868 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9869 if (linkage_name
== NULL
)
9870 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9872 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9873 See https://github.com/rust-lang/rust/issues/32925. */
9874 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9875 && strchr (linkage_name
, '{') != NULL
)
9876 linkage_name
= NULL
;
9878 return linkage_name
;
9881 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9882 compute the physname for the object, which include a method's:
9883 - formal parameters (C++),
9884 - receiver type (Go),
9886 The term "physname" is a bit confusing.
9887 For C++, for example, it is the demangled name.
9888 For Go, for example, it's the mangled name.
9890 For Ada, return the DIE's linkage name rather than the fully qualified
9891 name. PHYSNAME is ignored..
9893 The result is allocated on the objfile->per_bfd's obstack and
9897 dwarf2_compute_name (const char *name
,
9898 struct die_info
*die
, struct dwarf2_cu
*cu
,
9901 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9904 name
= dwarf2_name (die
, cu
);
9906 enum language lang
= cu
->per_cu
->lang
;
9908 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9909 but otherwise compute it by typename_concat inside GDB.
9910 FIXME: Actually this is not really true, or at least not always true.
9911 It's all very confusing. compute_and_set_names doesn't try to demangle
9912 Fortran names because there is no mangling standard. So new_symbol
9913 will set the demangled name to the result of dwarf2_full_name, and it is
9914 the demangled name that GDB uses if it exists. */
9915 if (lang
== language_ada
9916 || (lang
== language_fortran
&& physname
))
9918 /* For Ada unit, we prefer the linkage name over the name, as
9919 the former contains the exported name, which the user expects
9920 to be able to reference. Ideally, we want the user to be able
9921 to reference this entity using either natural or linkage name,
9922 but we haven't started looking at this enhancement yet. */
9923 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9925 if (linkage_name
!= NULL
)
9926 return linkage_name
;
9929 /* These are the only languages we know how to qualify names in. */
9931 && (lang
== language_cplus
9932 || lang
== language_fortran
|| lang
== language_d
9933 || lang
== language_rust
))
9935 if (die_needs_namespace (die
, cu
))
9938 const char *canonical_name
= NULL
;
9942 prefix
= determine_prefix (die
, cu
);
9943 if (*prefix
!= '\0')
9945 gdb::unique_xmalloc_ptr
<char> prefixed_name
9946 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9948 buf
.puts (prefixed_name
.get ());
9953 /* Template parameters may be specified in the DIE's DW_AT_name, or
9954 as children with DW_TAG_template_type_param or
9955 DW_TAG_value_type_param. If the latter, add them to the name
9956 here. If the name already has template parameters, then
9957 skip this step; some versions of GCC emit both, and
9958 it is more efficient to use the pre-computed name.
9960 Something to keep in mind about this process: it is very
9961 unlikely, or in some cases downright impossible, to produce
9962 something that will match the mangled name of a function.
9963 If the definition of the function has the same debug info,
9964 we should be able to match up with it anyway. But fallbacks
9965 using the minimal symbol, for instance to find a method
9966 implemented in a stripped copy of libstdc++, will not work.
9967 If we do not have debug info for the definition, we will have to
9968 match them up some other way.
9970 When we do name matching there is a related problem with function
9971 templates; two instantiated function templates are allowed to
9972 differ only by their return types, which we do not add here. */
9974 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9976 struct attribute
*attr
;
9977 struct die_info
*child
;
9980 die
->building_fullname
= 1;
9982 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9986 const gdb_byte
*bytes
;
9987 struct dwarf2_locexpr_baton
*baton
;
9990 if (child
->tag
!= DW_TAG_template_type_param
9991 && child
->tag
!= DW_TAG_template_value_param
)
10002 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10005 complaint (_("template parameter missing DW_AT_type"));
10006 buf
.puts ("UNKNOWN_TYPE");
10009 type
= die_type (child
, cu
);
10011 if (child
->tag
== DW_TAG_template_type_param
)
10013 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
10014 &type_print_raw_options
);
10018 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10021 complaint (_("template parameter missing "
10022 "DW_AT_const_value"));
10023 buf
.puts ("UNKNOWN_VALUE");
10027 dwarf2_const_value_attr (attr
, type
, name
,
10028 &cu
->comp_unit_obstack
, cu
,
10029 &value
, &bytes
, &baton
);
10031 if (type
->has_no_signedness ())
10032 /* GDB prints characters as NUMBER 'CHAR'. If that's
10033 changed, this can use value_print instead. */
10034 cu
->language_defn
->printchar (value
, type
, &buf
);
10037 struct value_print_options opts
;
10040 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10044 baton
->per_objfile
);
10045 else if (bytes
!= NULL
)
10047 v
= allocate_value (type
);
10048 memcpy (value_contents_writeable (v
), bytes
,
10049 TYPE_LENGTH (type
));
10052 v
= value_from_longest (type
, value
);
10054 /* Specify decimal so that we do not depend on
10056 get_formatted_print_options (&opts
, 'd');
10058 value_print (v
, &buf
, &opts
);
10063 die
->building_fullname
= 0;
10067 /* Close the argument list, with a space if necessary
10068 (nested templates). */
10069 if (!buf
.empty () && buf
.string ().back () == '>')
10076 /* For C++ methods, append formal parameter type
10077 information, if PHYSNAME. */
10079 if (physname
&& die
->tag
== DW_TAG_subprogram
10080 && lang
== language_cplus
)
10082 struct type
*type
= read_type_die (die
, cu
);
10084 c_type_print_args (type
, &buf
, 1, lang
,
10085 &type_print_raw_options
);
10087 if (lang
== language_cplus
)
10089 /* Assume that an artificial first parameter is
10090 "this", but do not crash if it is not. RealView
10091 marks unnamed (and thus unused) parameters as
10092 artificial; there is no way to differentiate
10094 if (type
->num_fields () > 0
10095 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10096 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10097 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10098 buf
.puts (" const");
10102 const std::string
&intermediate_name
= buf
.string ();
10104 if (lang
== language_cplus
)
10106 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10109 /* If we only computed INTERMEDIATE_NAME, or if
10110 INTERMEDIATE_NAME is already canonical, then we need to
10112 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10113 name
= objfile
->intern (intermediate_name
);
10115 name
= canonical_name
;
10122 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10123 If scope qualifiers are appropriate they will be added. The result
10124 will be allocated on the storage_obstack, or NULL if the DIE does
10125 not have a name. NAME may either be from a previous call to
10126 dwarf2_name or NULL.
10128 The output string will be canonicalized (if C++). */
10130 static const char *
10131 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10133 return dwarf2_compute_name (name
, die
, cu
, 0);
10136 /* Construct a physname for the given DIE in CU. NAME may either be
10137 from a previous call to dwarf2_name or NULL. The result will be
10138 allocated on the objfile_objstack or NULL if the DIE does not have a
10141 The output string will be canonicalized (if C++). */
10143 static const char *
10144 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10146 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10147 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10150 /* In this case dwarf2_compute_name is just a shortcut not building anything
10152 if (!die_needs_namespace (die
, cu
))
10153 return dwarf2_compute_name (name
, die
, cu
, 1);
10155 if (cu
->per_cu
->lang
!= language_rust
)
10156 mangled
= dw2_linkage_name (die
, cu
);
10158 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10160 gdb::unique_xmalloc_ptr
<char> demangled
;
10161 if (mangled
!= NULL
)
10163 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10165 /* Do nothing (do not demangle the symbol name). */
10169 /* Use DMGL_RET_DROP for C++ template functions to suppress
10170 their return type. It is easier for GDB users to search
10171 for such functions as `name(params)' than `long name(params)'.
10172 In such case the minimal symbol names do not match the full
10173 symbol names but for template functions there is never a need
10174 to look up their definition from their declaration so
10175 the only disadvantage remains the minimal symbol variant
10176 `long name(params)' does not have the proper inferior type. */
10177 demangled
.reset (gdb_demangle (mangled
,
10178 (DMGL_PARAMS
| DMGL_ANSI
10179 | DMGL_RET_DROP
)));
10182 canon
= demangled
.get ();
10190 if (canon
== NULL
|| check_physname
)
10192 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10194 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10196 /* It may not mean a bug in GDB. The compiler could also
10197 compute DW_AT_linkage_name incorrectly. But in such case
10198 GDB would need to be bug-to-bug compatible. */
10200 complaint (_("Computed physname <%s> does not match demangled <%s> "
10201 "(from linkage <%s>) - DIE at %s [in module %s]"),
10202 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10203 objfile_name (objfile
));
10205 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10206 is available here - over computed PHYSNAME. It is safer
10207 against both buggy GDB and buggy compilers. */
10221 retval
= objfile
->intern (retval
);
10226 /* Inspect DIE in CU for a namespace alias. If one exists, record
10227 a new symbol for it.
10229 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10232 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10234 struct attribute
*attr
;
10236 /* If the die does not have a name, this is not a namespace
10238 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10242 struct die_info
*d
= die
;
10243 struct dwarf2_cu
*imported_cu
= cu
;
10245 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10246 keep inspecting DIEs until we hit the underlying import. */
10247 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10248 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10250 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10254 d
= follow_die_ref (d
, attr
, &imported_cu
);
10255 if (d
->tag
!= DW_TAG_imported_declaration
)
10259 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10261 complaint (_("DIE at %s has too many recursively imported "
10262 "declarations"), sect_offset_str (d
->sect_off
));
10269 sect_offset sect_off
= attr
->get_ref_die_offset ();
10271 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10272 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10274 /* This declaration is a global namespace alias. Add
10275 a symbol for it whose type is the aliased namespace. */
10276 new_symbol (die
, type
, cu
);
10285 /* Return the using directives repository (global or local?) to use in the
10286 current context for CU.
10288 For Ada, imported declarations can materialize renamings, which *may* be
10289 global. However it is impossible (for now?) in DWARF to distinguish
10290 "external" imported declarations and "static" ones. As all imported
10291 declarations seem to be static in all other languages, make them all CU-wide
10292 global only in Ada. */
10294 static struct using_direct
**
10295 using_directives (struct dwarf2_cu
*cu
)
10297 if (cu
->per_cu
->lang
== language_ada
10298 && cu
->get_builder ()->outermost_context_p ())
10299 return cu
->get_builder ()->get_global_using_directives ();
10301 return cu
->get_builder ()->get_local_using_directives ();
10304 /* Read the import statement specified by the given die and record it. */
10307 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10309 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10310 struct attribute
*import_attr
;
10311 struct die_info
*imported_die
, *child_die
;
10312 struct dwarf2_cu
*imported_cu
;
10313 const char *imported_name
;
10314 const char *imported_name_prefix
;
10315 const char *canonical_name
;
10316 const char *import_alias
;
10317 const char *imported_declaration
= NULL
;
10318 const char *import_prefix
;
10319 std::vector
<const char *> excludes
;
10321 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10322 if (import_attr
== NULL
)
10324 complaint (_("Tag '%s' has no DW_AT_import"),
10325 dwarf_tag_name (die
->tag
));
10330 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10331 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10332 if (imported_name
== NULL
)
10334 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10336 The import in the following code:
10350 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10351 <52> DW_AT_decl_file : 1
10352 <53> DW_AT_decl_line : 6
10353 <54> DW_AT_import : <0x75>
10354 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10355 <59> DW_AT_name : B
10356 <5b> DW_AT_decl_file : 1
10357 <5c> DW_AT_decl_line : 2
10358 <5d> DW_AT_type : <0x6e>
10360 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10361 <76> DW_AT_byte_size : 4
10362 <77> DW_AT_encoding : 5 (signed)
10364 imports the wrong die ( 0x75 instead of 0x58 ).
10365 This case will be ignored until the gcc bug is fixed. */
10369 /* Figure out the local name after import. */
10370 import_alias
= dwarf2_name (die
, cu
);
10372 /* Figure out where the statement is being imported to. */
10373 import_prefix
= determine_prefix (die
, cu
);
10375 /* Figure out what the scope of the imported die is and prepend it
10376 to the name of the imported die. */
10377 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10379 if (imported_die
->tag
!= DW_TAG_namespace
10380 && imported_die
->tag
!= DW_TAG_module
)
10382 imported_declaration
= imported_name
;
10383 canonical_name
= imported_name_prefix
;
10385 else if (strlen (imported_name_prefix
) > 0)
10386 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10387 imported_name_prefix
,
10388 (cu
->per_cu
->lang
== language_d
10391 imported_name
, (char *) NULL
);
10393 canonical_name
= imported_name
;
10395 if (die
->tag
== DW_TAG_imported_module
10396 && cu
->per_cu
->lang
== language_fortran
)
10397 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10398 child_die
= child_die
->sibling
)
10400 /* DWARF-4: A Fortran use statement with a “rename list” may be
10401 represented by an imported module entry with an import attribute
10402 referring to the module and owned entries corresponding to those
10403 entities that are renamed as part of being imported. */
10405 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10407 complaint (_("child DW_TAG_imported_declaration expected "
10408 "- DIE at %s [in module %s]"),
10409 sect_offset_str (child_die
->sect_off
),
10410 objfile_name (objfile
));
10414 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10415 if (import_attr
== NULL
)
10417 complaint (_("Tag '%s' has no DW_AT_import"),
10418 dwarf_tag_name (child_die
->tag
));
10423 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10425 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10426 if (imported_name
== NULL
)
10428 complaint (_("child DW_TAG_imported_declaration has unknown "
10429 "imported name - DIE at %s [in module %s]"),
10430 sect_offset_str (child_die
->sect_off
),
10431 objfile_name (objfile
));
10435 excludes
.push_back (imported_name
);
10437 process_die (child_die
, cu
);
10440 add_using_directive (using_directives (cu
),
10444 imported_declaration
,
10447 &objfile
->objfile_obstack
);
10450 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10451 types, but gives them a size of zero. Starting with version 14,
10452 ICC is compatible with GCC. */
10455 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10457 if (!cu
->checked_producer
)
10458 check_producer (cu
);
10460 return cu
->producer_is_icc_lt_14
;
10463 /* ICC generates a DW_AT_type for C void functions. This was observed on
10464 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10465 which says that void functions should not have a DW_AT_type. */
10468 producer_is_icc (struct dwarf2_cu
*cu
)
10470 if (!cu
->checked_producer
)
10471 check_producer (cu
);
10473 return cu
->producer_is_icc
;
10476 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10477 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10478 this, it was first present in GCC release 4.3.0. */
10481 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10483 if (!cu
->checked_producer
)
10484 check_producer (cu
);
10486 return cu
->producer_is_gcc_lt_4_3
;
10489 static file_and_directory
10490 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10492 file_and_directory res
;
10494 /* Find the filename. Do not use dwarf2_name here, since the filename
10495 is not a source language identifier. */
10496 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10497 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10499 if (res
.comp_dir
== NULL
10500 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10501 && IS_ABSOLUTE_PATH (res
.name
))
10503 std::string comp_dir_storage
= ldirname (res
.name
);
10504 if (!comp_dir_storage
.empty ())
10506 = cu
->per_objfile
->objfile
->intern (comp_dir_storage
.c_str ());
10508 if (res
.comp_dir
!= NULL
)
10510 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10511 directory, get rid of it. */
10512 const char *cp
= strchr (res
.comp_dir
, ':');
10514 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10515 res
.comp_dir
= cp
+ 1;
10518 if (res
.name
== NULL
)
10519 res
.name
= "<unknown>";
10524 /* Handle DW_AT_stmt_list for a compilation unit.
10525 DIE is the DW_TAG_compile_unit die for CU.
10526 COMP_DIR is the compilation directory. LOWPC is passed to
10527 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10530 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10531 const file_and_directory
&fnd
, CORE_ADDR lowpc
) /* ARI: editCase function */
10533 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10534 struct attribute
*attr
;
10535 struct line_header line_header_local
;
10536 hashval_t line_header_local_hash
;
10538 int decode_mapping
;
10540 gdb_assert (! cu
->per_cu
->is_debug_types
);
10542 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10543 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10546 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10548 /* The line header hash table is only created if needed (it exists to
10549 prevent redundant reading of the line table for partial_units).
10550 If we're given a partial_unit, we'll need it. If we're given a
10551 compile_unit, then use the line header hash table if it's already
10552 created, but don't create one just yet. */
10554 if (per_objfile
->line_header_hash
== NULL
10555 && die
->tag
== DW_TAG_partial_unit
)
10557 per_objfile
->line_header_hash
10558 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10559 line_header_eq_voidp
,
10560 htab_delete_entry
<line_header
>,
10564 line_header_local
.sect_off
= line_offset
;
10565 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10566 line_header_local_hash
= line_header_hash (&line_header_local
);
10567 if (per_objfile
->line_header_hash
!= NULL
)
10569 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10570 &line_header_local
,
10571 line_header_local_hash
, NO_INSERT
);
10573 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10574 is not present in *SLOT (since if there is something in *SLOT then
10575 it will be for a partial_unit). */
10576 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10578 gdb_assert (*slot
!= NULL
);
10579 cu
->line_header
= (struct line_header
*) *slot
;
10584 /* dwarf_decode_line_header does not yet provide sufficient information.
10585 We always have to call also dwarf_decode_lines for it. */
10586 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10590 cu
->line_header
= lh
.release ();
10591 cu
->line_header_die_owner
= die
;
10593 if (per_objfile
->line_header_hash
== NULL
)
10597 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10598 &line_header_local
,
10599 line_header_local_hash
, INSERT
);
10600 gdb_assert (slot
!= NULL
);
10602 if (slot
!= NULL
&& *slot
== NULL
)
10604 /* This newly decoded line number information unit will be owned
10605 by line_header_hash hash table. */
10606 *slot
= cu
->line_header
;
10607 cu
->line_header_die_owner
= NULL
;
10611 /* We cannot free any current entry in (*slot) as that struct line_header
10612 may be already used by multiple CUs. Create only temporary decoded
10613 line_header for this CU - it may happen at most once for each line
10614 number information unit. And if we're not using line_header_hash
10615 then this is what we want as well. */
10616 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10618 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10619 dwarf_decode_lines (cu
->line_header
, fnd
, cu
, nullptr, lowpc
,
10624 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10627 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10629 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10630 struct objfile
*objfile
= per_objfile
->objfile
;
10631 struct gdbarch
*gdbarch
= objfile
->arch ();
10632 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10633 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10634 struct attribute
*attr
;
10635 struct die_info
*child_die
;
10636 CORE_ADDR baseaddr
;
10638 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10639 baseaddr
= objfile
->text_section_offset ();
10641 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10643 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10644 from finish_block. */
10645 if (lowpc
== ((CORE_ADDR
) -1))
10647 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10649 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10651 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10653 gdb_assert (per_objfile
->sym_cu
== nullptr);
10654 scoped_restore restore_sym_cu
10655 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10657 /* Decode line number information if present. We do this before
10658 processing child DIEs, so that the line header table is available
10659 for DW_AT_decl_file. */
10660 handle_DW_AT_stmt_list (die
, cu
, fnd
, lowpc
);
10662 /* Process all dies in compilation unit. */
10663 if (die
->child
!= NULL
)
10665 child_die
= die
->child
;
10666 while (child_die
&& child_die
->tag
)
10668 process_die (child_die
, cu
);
10669 child_die
= child_die
->sibling
;
10672 per_objfile
->sym_cu
= nullptr;
10674 /* Decode macro information, if present. Dwarf 2 macro information
10675 refers to information in the line number info statement program
10676 header, so we can only read it if we've read the header
10678 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10680 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10681 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10683 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10684 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10686 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10690 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10691 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10693 unsigned int macro_offset
= attr
->as_unsigned ();
10695 dwarf_decode_macros (cu
, macro_offset
, 0);
10701 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10703 struct type_unit_group
*tu_group
;
10705 struct attribute
*attr
;
10707 struct signatured_type
*sig_type
;
10709 gdb_assert (per_cu
->is_debug_types
);
10710 sig_type
= (struct signatured_type
*) per_cu
;
10712 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10714 /* If we're using .gdb_index (includes -readnow) then
10715 per_cu->type_unit_group may not have been set up yet. */
10716 if (sig_type
->type_unit_group
== NULL
)
10717 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10718 tu_group
= sig_type
->type_unit_group
;
10720 /* If we've already processed this stmt_list there's no real need to
10721 do it again, we could fake it and just recreate the part we need
10722 (file name,index -> symtab mapping). If data shows this optimization
10723 is useful we can do it then. */
10724 type_unit_group_unshareable
*tug_unshare
10725 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10726 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10728 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10731 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10733 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10734 lh
= dwarf_decode_line_header (line_offset
, this);
10739 start_symtab ("", NULL
, 0);
10742 gdb_assert (tug_unshare
->symtabs
== NULL
);
10743 gdb_assert (m_builder
== nullptr);
10744 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10745 m_builder
.reset (new struct buildsym_compunit
10746 (COMPUNIT_OBJFILE (cust
), "",
10747 COMPUNIT_DIRNAME (cust
),
10748 compunit_language (cust
),
10750 list_in_scope
= get_builder ()->get_file_symbols ();
10755 line_header
= lh
.release ();
10756 line_header_die_owner
= die
;
10760 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10762 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10763 still initializing it, and our caller (a few levels up)
10764 process_full_type_unit still needs to know if this is the first
10767 tug_unshare
->symtabs
10768 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10769 struct symtab
*, line_header
->file_names_size ());
10771 auto &file_names
= line_header
->file_names ();
10772 for (i
= 0; i
< file_names
.size (); ++i
)
10774 file_entry
&fe
= file_names
[i
];
10775 dwarf2_start_subfile (this, fe
.name
,
10776 fe
.include_dir (line_header
));
10777 buildsym_compunit
*b
= get_builder ();
10778 if (b
->get_current_subfile ()->symtab
== NULL
)
10780 /* NOTE: start_subfile will recognize when it's been
10781 passed a file it has already seen. So we can't
10782 assume there's a simple mapping from
10783 cu->line_header->file_names to subfiles, plus
10784 cu->line_header->file_names may contain dups. */
10785 b
->get_current_subfile ()->symtab
10786 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10789 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10790 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10795 gdb_assert (m_builder
== nullptr);
10796 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10797 m_builder
.reset (new struct buildsym_compunit
10798 (COMPUNIT_OBJFILE (cust
), "",
10799 COMPUNIT_DIRNAME (cust
),
10800 compunit_language (cust
),
10802 list_in_scope
= get_builder ()->get_file_symbols ();
10804 auto &file_names
= line_header
->file_names ();
10805 for (i
= 0; i
< file_names
.size (); ++i
)
10807 file_entry
&fe
= file_names
[i
];
10808 fe
.symtab
= tug_unshare
->symtabs
[i
];
10812 /* The main symtab is allocated last. Type units don't have DW_AT_name
10813 so they don't have a "real" (so to speak) symtab anyway.
10814 There is later code that will assign the main symtab to all symbols
10815 that don't have one. We need to handle the case of a symbol with a
10816 missing symtab (DW_AT_decl_file) anyway. */
10819 /* Process DW_TAG_type_unit.
10820 For TUs we want to skip the first top level sibling if it's not the
10821 actual type being defined by this TU. In this case the first top
10822 level sibling is there to provide context only. */
10825 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10827 struct die_info
*child_die
;
10829 prepare_one_comp_unit (cu
, die
, language_minimal
);
10831 /* Initialize (or reinitialize) the machinery for building symtabs.
10832 We do this before processing child DIEs, so that the line header table
10833 is available for DW_AT_decl_file. */
10834 cu
->setup_type_unit_groups (die
);
10836 if (die
->child
!= NULL
)
10838 child_die
= die
->child
;
10839 while (child_die
&& child_die
->tag
)
10841 process_die (child_die
, cu
);
10842 child_die
= child_die
->sibling
;
10849 http://gcc.gnu.org/wiki/DebugFission
10850 http://gcc.gnu.org/wiki/DebugFissionDWP
10852 To simplify handling of both DWO files ("object" files with the DWARF info)
10853 and DWP files (a file with the DWOs packaged up into one file), we treat
10854 DWP files as having a collection of virtual DWO files. */
10857 hash_dwo_file (const void *item
)
10859 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10862 hash
= htab_hash_string (dwo_file
->dwo_name
);
10863 if (dwo_file
->comp_dir
!= NULL
)
10864 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10869 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10871 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10872 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10874 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10876 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10877 return lhs
->comp_dir
== rhs
->comp_dir
;
10878 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10881 /* Allocate a hash table for DWO files. */
10884 allocate_dwo_file_hash_table ()
10886 return htab_up (htab_create_alloc (41,
10889 htab_delete_entry
<dwo_file
>,
10893 /* Lookup DWO file DWO_NAME. */
10896 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10897 const char *dwo_name
,
10898 const char *comp_dir
)
10900 struct dwo_file find_entry
;
10903 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10904 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10906 find_entry
.dwo_name
= dwo_name
;
10907 find_entry
.comp_dir
= comp_dir
;
10908 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10915 hash_dwo_unit (const void *item
)
10917 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10919 /* This drops the top 32 bits of the id, but is ok for a hash. */
10920 return dwo_unit
->signature
;
10924 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10926 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10927 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10929 /* The signature is assumed to be unique within the DWO file.
10930 So while object file CU dwo_id's always have the value zero,
10931 that's OK, assuming each object file DWO file has only one CU,
10932 and that's the rule for now. */
10933 return lhs
->signature
== rhs
->signature
;
10936 /* Allocate a hash table for DWO CUs,TUs.
10937 There is one of these tables for each of CUs,TUs for each DWO file. */
10940 allocate_dwo_unit_table ()
10942 /* Start out with a pretty small number.
10943 Generally DWO files contain only one CU and maybe some TUs. */
10944 return htab_up (htab_create_alloc (3,
10947 NULL
, xcalloc
, xfree
));
10950 /* die_reader_func for create_dwo_cu. */
10953 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10954 const gdb_byte
*info_ptr
,
10955 struct die_info
*comp_unit_die
,
10956 struct dwo_file
*dwo_file
,
10957 struct dwo_unit
*dwo_unit
)
10959 struct dwarf2_cu
*cu
= reader
->cu
;
10960 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10961 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10963 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10964 if (!signature
.has_value ())
10966 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10967 " its dwo_id [in module %s]"),
10968 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10972 dwo_unit
->dwo_file
= dwo_file
;
10973 dwo_unit
->signature
= *signature
;
10974 dwo_unit
->section
= section
;
10975 dwo_unit
->sect_off
= sect_off
;
10976 dwo_unit
->length
= cu
->per_cu
->length
;
10978 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10979 sect_offset_str (sect_off
),
10980 hex_string (dwo_unit
->signature
));
10983 /* Create the dwo_units for the CUs in a DWO_FILE.
10984 Note: This function processes DWO files only, not DWP files. */
10987 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10988 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10989 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10991 struct objfile
*objfile
= per_objfile
->objfile
;
10992 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10993 const gdb_byte
*info_ptr
, *end_ptr
;
10995 section
.read (objfile
);
10996 info_ptr
= section
.buffer
;
10998 if (info_ptr
== NULL
)
11001 dwarf_read_debug_printf ("Reading %s for %s:",
11002 section
.get_name (),
11003 section
.get_file_name ());
11005 end_ptr
= info_ptr
+ section
.size
;
11006 while (info_ptr
< end_ptr
)
11008 struct dwarf2_per_cu_data per_cu
;
11009 struct dwo_unit read_unit
{};
11010 struct dwo_unit
*dwo_unit
;
11012 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11014 per_cu
.per_bfd
= per_bfd
;
11015 per_cu
.is_debug_types
= 0;
11016 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11017 per_cu
.section
= §ion
;
11019 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11020 if (!reader
.dummy_p
)
11021 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11022 &dwo_file
, &read_unit
);
11023 info_ptr
+= per_cu
.length
;
11025 // If the unit could not be parsed, skip it.
11026 if (read_unit
.dwo_file
== NULL
)
11029 if (cus_htab
== NULL
)
11030 cus_htab
= allocate_dwo_unit_table ();
11032 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11034 *dwo_unit
= read_unit
;
11035 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11036 gdb_assert (slot
!= NULL
);
11039 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11040 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11042 complaint (_("debug cu entry at offset %s is duplicate to"
11043 " the entry at offset %s, signature %s"),
11044 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11045 hex_string (dwo_unit
->signature
));
11047 *slot
= (void *)dwo_unit
;
11051 /* DWP file .debug_{cu,tu}_index section format:
11052 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11053 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11055 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11056 officially standard DWP format was published with DWARF v5 and is called
11057 Version 5. There are no versions 3 or 4.
11061 Both index sections have the same format, and serve to map a 64-bit
11062 signature to a set of section numbers. Each section begins with a header,
11063 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11064 indexes, and a pool of 32-bit section numbers. The index sections will be
11065 aligned at 8-byte boundaries in the file.
11067 The index section header consists of:
11069 V, 32 bit version number
11071 N, 32 bit number of compilation units or type units in the index
11072 M, 32 bit number of slots in the hash table
11074 Numbers are recorded using the byte order of the application binary.
11076 The hash table begins at offset 16 in the section, and consists of an array
11077 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11078 order of the application binary). Unused slots in the hash table are 0.
11079 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11081 The parallel table begins immediately after the hash table
11082 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11083 array of 32-bit indexes (using the byte order of the application binary),
11084 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11085 table contains a 32-bit index into the pool of section numbers. For unused
11086 hash table slots, the corresponding entry in the parallel table will be 0.
11088 The pool of section numbers begins immediately following the hash table
11089 (at offset 16 + 12 * M from the beginning of the section). The pool of
11090 section numbers consists of an array of 32-bit words (using the byte order
11091 of the application binary). Each item in the array is indexed starting
11092 from 0. The hash table entry provides the index of the first section
11093 number in the set. Additional section numbers in the set follow, and the
11094 set is terminated by a 0 entry (section number 0 is not used in ELF).
11096 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11097 section must be the first entry in the set, and the .debug_abbrev.dwo must
11098 be the second entry. Other members of the set may follow in any order.
11102 DWP Versions 2 and 5:
11104 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11105 and the entries in the index tables are now offsets into these sections.
11106 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11109 Index Section Contents:
11111 Hash Table of Signatures dwp_hash_table.hash_table
11112 Parallel Table of Indices dwp_hash_table.unit_table
11113 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11114 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11116 The index section header consists of:
11118 V, 32 bit version number
11119 L, 32 bit number of columns in the table of section offsets
11120 N, 32 bit number of compilation units or type units in the index
11121 M, 32 bit number of slots in the hash table
11123 Numbers are recorded using the byte order of the application binary.
11125 The hash table has the same format as version 1.
11126 The parallel table of indices has the same format as version 1,
11127 except that the entries are origin-1 indices into the table of sections
11128 offsets and the table of section sizes.
11130 The table of offsets begins immediately following the parallel table
11131 (at offset 16 + 12 * M from the beginning of the section). The table is
11132 a two-dimensional array of 32-bit words (using the byte order of the
11133 application binary), with L columns and N+1 rows, in row-major order.
11134 Each row in the array is indexed starting from 0. The first row provides
11135 a key to the remaining rows: each column in this row provides an identifier
11136 for a debug section, and the offsets in the same column of subsequent rows
11137 refer to that section. The section identifiers for Version 2 are:
11139 DW_SECT_INFO 1 .debug_info.dwo
11140 DW_SECT_TYPES 2 .debug_types.dwo
11141 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11142 DW_SECT_LINE 4 .debug_line.dwo
11143 DW_SECT_LOC 5 .debug_loc.dwo
11144 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11145 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11146 DW_SECT_MACRO 8 .debug_macro.dwo
11148 The section identifiers for Version 5 are:
11150 DW_SECT_INFO_V5 1 .debug_info.dwo
11151 DW_SECT_RESERVED_V5 2 --
11152 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11153 DW_SECT_LINE_V5 4 .debug_line.dwo
11154 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11155 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11156 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11157 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11159 The offsets provided by the CU and TU index sections are the base offsets
11160 for the contributions made by each CU or TU to the corresponding section
11161 in the package file. Each CU and TU header contains an abbrev_offset
11162 field, used to find the abbreviations table for that CU or TU within the
11163 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11164 be interpreted as relative to the base offset given in the index section.
11165 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11166 should be interpreted as relative to the base offset for .debug_line.dwo,
11167 and offsets into other debug sections obtained from DWARF attributes should
11168 also be interpreted as relative to the corresponding base offset.
11170 The table of sizes begins immediately following the table of offsets.
11171 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11172 with L columns and N rows, in row-major order. Each row in the array is
11173 indexed starting from 1 (row 0 is shared by the two tables).
11177 Hash table lookup is handled the same in version 1 and 2:
11179 We assume that N and M will not exceed 2^32 - 1.
11180 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11182 Given a 64-bit compilation unit signature or a type signature S, an entry
11183 in the hash table is located as follows:
11185 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11186 the low-order k bits all set to 1.
11188 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11190 3) If the hash table entry at index H matches the signature, use that
11191 entry. If the hash table entry at index H is unused (all zeroes),
11192 terminate the search: the signature is not present in the table.
11194 4) Let H = (H + H') modulo M. Repeat at Step 3.
11196 Because M > N and H' and M are relatively prime, the search is guaranteed
11197 to stop at an unused slot or find the match. */
11199 /* Create a hash table to map DWO IDs to their CU/TU entry in
11200 .debug_{info,types}.dwo in DWP_FILE.
11201 Returns NULL if there isn't one.
11202 Note: This function processes DWP files only, not DWO files. */
11204 static struct dwp_hash_table
*
11205 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11206 struct dwp_file
*dwp_file
, int is_debug_types
)
11208 struct objfile
*objfile
= per_objfile
->objfile
;
11209 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11210 const gdb_byte
*index_ptr
, *index_end
;
11211 struct dwarf2_section_info
*index
;
11212 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11213 struct dwp_hash_table
*htab
;
11215 if (is_debug_types
)
11216 index
= &dwp_file
->sections
.tu_index
;
11218 index
= &dwp_file
->sections
.cu_index
;
11220 if (index
->empty ())
11222 index
->read (objfile
);
11224 index_ptr
= index
->buffer
;
11225 index_end
= index_ptr
+ index
->size
;
11227 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11228 For now it's safe to just read 4 bytes (particularly as it's difficult to
11229 tell if you're dealing with Version 5 before you've read the version). */
11230 version
= read_4_bytes (dbfd
, index_ptr
);
11232 if (version
== 2 || version
== 5)
11233 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11237 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11239 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11242 if (version
!= 1 && version
!= 2 && version
!= 5)
11244 error (_("Dwarf Error: unsupported DWP file version (%s)"
11245 " [in module %s]"),
11246 pulongest (version
), dwp_file
->name
);
11248 if (nr_slots
!= (nr_slots
& -nr_slots
))
11250 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11251 " is not power of 2 [in module %s]"),
11252 pulongest (nr_slots
), dwp_file
->name
);
11255 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11256 htab
->version
= version
;
11257 htab
->nr_columns
= nr_columns
;
11258 htab
->nr_units
= nr_units
;
11259 htab
->nr_slots
= nr_slots
;
11260 htab
->hash_table
= index_ptr
;
11261 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11263 /* Exit early if the table is empty. */
11264 if (nr_slots
== 0 || nr_units
== 0
11265 || (version
== 2 && nr_columns
== 0)
11266 || (version
== 5 && nr_columns
== 0))
11268 /* All must be zero. */
11269 if (nr_slots
!= 0 || nr_units
!= 0
11270 || (version
== 2 && nr_columns
!= 0)
11271 || (version
== 5 && nr_columns
!= 0))
11273 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11274 " all zero [in modules %s]"),
11282 htab
->section_pool
.v1
.indices
=
11283 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11284 /* It's harder to decide whether the section is too small in v1.
11285 V1 is deprecated anyway so we punt. */
11287 else if (version
== 2)
11289 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11290 int *ids
= htab
->section_pool
.v2
.section_ids
;
11291 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11292 /* Reverse map for error checking. */
11293 int ids_seen
[DW_SECT_MAX
+ 1];
11296 if (nr_columns
< 2)
11298 error (_("Dwarf Error: bad DWP hash table, too few columns"
11299 " in section table [in module %s]"),
11302 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11304 error (_("Dwarf Error: bad DWP hash table, too many columns"
11305 " in section table [in module %s]"),
11308 memset (ids
, 255, sizeof_ids
);
11309 memset (ids_seen
, 255, sizeof (ids_seen
));
11310 for (i
= 0; i
< nr_columns
; ++i
)
11312 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11314 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11316 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11317 " in section table [in module %s]"),
11318 id
, dwp_file
->name
);
11320 if (ids_seen
[id
] != -1)
11322 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11323 " id %d in section table [in module %s]"),
11324 id
, dwp_file
->name
);
11329 /* Must have exactly one info or types section. */
11330 if (((ids_seen
[DW_SECT_INFO
] != -1)
11331 + (ids_seen
[DW_SECT_TYPES
] != -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
] == -1)
11341 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11342 " section [in module %s]"),
11345 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11346 htab
->section_pool
.v2
.sizes
=
11347 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11348 * nr_units
* nr_columns
);
11349 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11350 * nr_units
* nr_columns
))
11353 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11354 " [in module %s]"),
11358 else /* version == 5 */
11360 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11361 int *ids
= htab
->section_pool
.v5
.section_ids
;
11362 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11363 /* Reverse map for error checking. */
11364 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11366 if (nr_columns
< 2)
11368 error (_("Dwarf Error: bad DWP hash table, too few columns"
11369 " in section table [in module %s]"),
11372 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11374 error (_("Dwarf Error: bad DWP hash table, too many columns"
11375 " in section table [in module %s]"),
11378 memset (ids
, 255, sizeof_ids
);
11379 memset (ids_seen
, 255, sizeof (ids_seen
));
11380 for (int i
= 0; i
< nr_columns
; ++i
)
11382 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11384 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11386 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11387 " in section table [in module %s]"),
11388 id
, dwp_file
->name
);
11390 if (ids_seen
[id
] != -1)
11392 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11393 " id %d in section table [in module %s]"),
11394 id
, dwp_file
->name
);
11399 /* Must have seen an info section. */
11400 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11402 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11403 " DWO info/types section [in module %s]"),
11406 /* Must have an abbrev section. */
11407 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11409 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11410 " section [in module %s]"),
11413 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11414 htab
->section_pool
.v5
.sizes
11415 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11416 * nr_units
* nr_columns
);
11417 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11418 * nr_units
* nr_columns
))
11421 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11422 " [in module %s]"),
11430 /* Update SECTIONS with the data from SECTP.
11432 This function is like the other "locate" section routines, but in
11433 this context the sections to read comes from the DWP V1 hash table,
11434 not the full ELF section table.
11436 The result is non-zero for success, or zero if an error was found. */
11439 locate_v1_virtual_dwo_sections (asection
*sectp
,
11440 struct virtual_v1_dwo_sections
*sections
)
11442 const struct dwop_section_names
*names
= &dwop_section_names
;
11444 if (names
->abbrev_dwo
.matches (sectp
->name
))
11446 /* There can be only one. */
11447 if (sections
->abbrev
.s
.section
!= NULL
)
11449 sections
->abbrev
.s
.section
= sectp
;
11450 sections
->abbrev
.size
= bfd_section_size (sectp
);
11452 else if (names
->info_dwo
.matches (sectp
->name
)
11453 || names
->types_dwo
.matches (sectp
->name
))
11455 /* There can be only one. */
11456 if (sections
->info_or_types
.s
.section
!= NULL
)
11458 sections
->info_or_types
.s
.section
= sectp
;
11459 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11461 else if (names
->line_dwo
.matches (sectp
->name
))
11463 /* There can be only one. */
11464 if (sections
->line
.s
.section
!= NULL
)
11466 sections
->line
.s
.section
= sectp
;
11467 sections
->line
.size
= bfd_section_size (sectp
);
11469 else if (names
->loc_dwo
.matches (sectp
->name
))
11471 /* There can be only one. */
11472 if (sections
->loc
.s
.section
!= NULL
)
11474 sections
->loc
.s
.section
= sectp
;
11475 sections
->loc
.size
= bfd_section_size (sectp
);
11477 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11479 /* There can be only one. */
11480 if (sections
->macinfo
.s
.section
!= NULL
)
11482 sections
->macinfo
.s
.section
= sectp
;
11483 sections
->macinfo
.size
= bfd_section_size (sectp
);
11485 else if (names
->macro_dwo
.matches (sectp
->name
))
11487 /* There can be only one. */
11488 if (sections
->macro
.s
.section
!= NULL
)
11490 sections
->macro
.s
.section
= sectp
;
11491 sections
->macro
.size
= bfd_section_size (sectp
);
11493 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11495 /* There can be only one. */
11496 if (sections
->str_offsets
.s
.section
!= NULL
)
11498 sections
->str_offsets
.s
.section
= sectp
;
11499 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11503 /* No other kind of section is valid. */
11510 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11511 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11512 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11513 This is for DWP version 1 files. */
11515 static struct dwo_unit
*
11516 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11517 struct dwp_file
*dwp_file
,
11518 uint32_t unit_index
,
11519 const char *comp_dir
,
11520 ULONGEST signature
, int is_debug_types
)
11522 const struct dwp_hash_table
*dwp_htab
=
11523 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11524 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11525 const char *kind
= is_debug_types
? "TU" : "CU";
11526 struct dwo_file
*dwo_file
;
11527 struct dwo_unit
*dwo_unit
;
11528 struct virtual_v1_dwo_sections sections
;
11529 void **dwo_file_slot
;
11532 gdb_assert (dwp_file
->version
== 1);
11534 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11535 kind
, pulongest (unit_index
), hex_string (signature
),
11538 /* Fetch the sections of this DWO unit.
11539 Put a limit on the number of sections we look for so that bad data
11540 doesn't cause us to loop forever. */
11542 #define MAX_NR_V1_DWO_SECTIONS \
11543 (1 /* .debug_info or .debug_types */ \
11544 + 1 /* .debug_abbrev */ \
11545 + 1 /* .debug_line */ \
11546 + 1 /* .debug_loc */ \
11547 + 1 /* .debug_str_offsets */ \
11548 + 1 /* .debug_macro or .debug_macinfo */ \
11549 + 1 /* trailing zero */)
11551 memset (§ions
, 0, sizeof (sections
));
11553 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11556 uint32_t section_nr
=
11557 read_4_bytes (dbfd
,
11558 dwp_htab
->section_pool
.v1
.indices
11559 + (unit_index
+ i
) * sizeof (uint32_t));
11561 if (section_nr
== 0)
11563 if (section_nr
>= dwp_file
->num_sections
)
11565 error (_("Dwarf Error: bad DWP hash table, section number too large"
11566 " [in module %s]"),
11570 sectp
= dwp_file
->elf_sections
[section_nr
];
11571 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11573 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11574 " [in module %s]"),
11580 || sections
.info_or_types
.empty ()
11581 || sections
.abbrev
.empty ())
11583 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11584 " [in module %s]"),
11587 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11589 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11590 " [in module %s]"),
11594 /* It's easier for the rest of the code if we fake a struct dwo_file and
11595 have dwo_unit "live" in that. At least for now.
11597 The DWP file can be made up of a random collection of CUs and TUs.
11598 However, for each CU + set of TUs that came from the same original DWO
11599 file, we can combine them back into a virtual DWO file to save space
11600 (fewer struct dwo_file objects to allocate). Remember that for really
11601 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11603 std::string virtual_dwo_name
=
11604 string_printf ("virtual-dwo/%d-%d-%d-%d",
11605 sections
.abbrev
.get_id (),
11606 sections
.line
.get_id (),
11607 sections
.loc
.get_id (),
11608 sections
.str_offsets
.get_id ());
11609 /* Can we use an existing virtual DWO file? */
11610 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11612 /* Create one if necessary. */
11613 if (*dwo_file_slot
== NULL
)
11615 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11616 virtual_dwo_name
.c_str ());
11618 dwo_file
= new struct dwo_file
;
11619 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11620 dwo_file
->comp_dir
= comp_dir
;
11621 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11622 dwo_file
->sections
.line
= sections
.line
;
11623 dwo_file
->sections
.loc
= sections
.loc
;
11624 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11625 dwo_file
->sections
.macro
= sections
.macro
;
11626 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11627 /* The "str" section is global to the entire DWP file. */
11628 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11629 /* The info or types section is assigned below to dwo_unit,
11630 there's no need to record it in dwo_file.
11631 Also, we can't simply record type sections in dwo_file because
11632 we record a pointer into the vector in dwo_unit. As we collect more
11633 types we'll grow the vector and eventually have to reallocate space
11634 for it, invalidating all copies of pointers into the previous
11636 *dwo_file_slot
= dwo_file
;
11640 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11641 virtual_dwo_name
.c_str ());
11643 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11646 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11647 dwo_unit
->dwo_file
= dwo_file
;
11648 dwo_unit
->signature
= signature
;
11649 dwo_unit
->section
=
11650 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11651 *dwo_unit
->section
= sections
.info_or_types
;
11652 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11657 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11658 simplify them. Given a pointer to the containing section SECTION, and
11659 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11660 virtual section of just that piece. */
11662 static struct dwarf2_section_info
11663 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11664 struct dwarf2_section_info
*section
,
11665 bfd_size_type offset
, bfd_size_type size
)
11667 struct dwarf2_section_info result
;
11670 gdb_assert (section
!= NULL
);
11671 gdb_assert (!section
->is_virtual
);
11673 memset (&result
, 0, sizeof (result
));
11674 result
.s
.containing_section
= section
;
11675 result
.is_virtual
= true;
11680 sectp
= section
->get_bfd_section ();
11682 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11683 bounds of the real section. This is a pretty-rare event, so just
11684 flag an error (easier) instead of a warning and trying to cope. */
11686 || offset
+ size
> bfd_section_size (sectp
))
11688 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11689 " in section %s [in module %s]"),
11690 sectp
? bfd_section_name (sectp
) : "<unknown>",
11691 objfile_name (per_objfile
->objfile
));
11694 result
.virtual_offset
= offset
;
11695 result
.size
= size
;
11699 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11700 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11701 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11702 This is for DWP version 2 files. */
11704 static struct dwo_unit
*
11705 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11706 struct dwp_file
*dwp_file
,
11707 uint32_t unit_index
,
11708 const char *comp_dir
,
11709 ULONGEST signature
, int is_debug_types
)
11711 const struct dwp_hash_table
*dwp_htab
=
11712 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11713 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11714 const char *kind
= is_debug_types
? "TU" : "CU";
11715 struct dwo_file
*dwo_file
;
11716 struct dwo_unit
*dwo_unit
;
11717 struct virtual_v2_or_v5_dwo_sections sections
;
11718 void **dwo_file_slot
;
11721 gdb_assert (dwp_file
->version
== 2);
11723 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11724 kind
, pulongest (unit_index
), hex_string (signature
),
11727 /* Fetch the section offsets of this DWO unit. */
11729 memset (§ions
, 0, sizeof (sections
));
11731 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11733 uint32_t offset
= read_4_bytes (dbfd
,
11734 dwp_htab
->section_pool
.v2
.offsets
11735 + (((unit_index
- 1) * dwp_htab
->nr_columns
11737 * sizeof (uint32_t)));
11738 uint32_t size
= read_4_bytes (dbfd
,
11739 dwp_htab
->section_pool
.v2
.sizes
11740 + (((unit_index
- 1) * dwp_htab
->nr_columns
11742 * sizeof (uint32_t)));
11744 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11747 case DW_SECT_TYPES
:
11748 sections
.info_or_types_offset
= offset
;
11749 sections
.info_or_types_size
= size
;
11751 case DW_SECT_ABBREV
:
11752 sections
.abbrev_offset
= offset
;
11753 sections
.abbrev_size
= size
;
11756 sections
.line_offset
= offset
;
11757 sections
.line_size
= size
;
11760 sections
.loc_offset
= offset
;
11761 sections
.loc_size
= size
;
11763 case DW_SECT_STR_OFFSETS
:
11764 sections
.str_offsets_offset
= offset
;
11765 sections
.str_offsets_size
= size
;
11767 case DW_SECT_MACINFO
:
11768 sections
.macinfo_offset
= offset
;
11769 sections
.macinfo_size
= size
;
11771 case DW_SECT_MACRO
:
11772 sections
.macro_offset
= offset
;
11773 sections
.macro_size
= size
;
11778 /* It's easier for the rest of the code if we fake a struct dwo_file and
11779 have dwo_unit "live" in that. At least for now.
11781 The DWP file can be made up of a random collection of CUs and TUs.
11782 However, for each CU + set of TUs that came from the same original DWO
11783 file, we can combine them back into a virtual DWO file to save space
11784 (fewer struct dwo_file objects to allocate). Remember that for really
11785 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11787 std::string virtual_dwo_name
=
11788 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11789 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11790 (long) (sections
.line_size
? sections
.line_offset
: 0),
11791 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11792 (long) (sections
.str_offsets_size
11793 ? sections
.str_offsets_offset
: 0));
11794 /* Can we use an existing virtual DWO file? */
11795 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11797 /* Create one if necessary. */
11798 if (*dwo_file_slot
== NULL
)
11800 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11801 virtual_dwo_name
.c_str ());
11803 dwo_file
= new struct dwo_file
;
11804 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11805 dwo_file
->comp_dir
= comp_dir
;
11806 dwo_file
->sections
.abbrev
=
11807 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11808 sections
.abbrev_offset
,
11809 sections
.abbrev_size
);
11810 dwo_file
->sections
.line
=
11811 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11812 sections
.line_offset
,
11813 sections
.line_size
);
11814 dwo_file
->sections
.loc
=
11815 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11816 sections
.loc_offset
, sections
.loc_size
);
11817 dwo_file
->sections
.macinfo
=
11818 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11819 sections
.macinfo_offset
,
11820 sections
.macinfo_size
);
11821 dwo_file
->sections
.macro
=
11822 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11823 sections
.macro_offset
,
11824 sections
.macro_size
);
11825 dwo_file
->sections
.str_offsets
=
11826 create_dwp_v2_or_v5_section (per_objfile
,
11827 &dwp_file
->sections
.str_offsets
,
11828 sections
.str_offsets_offset
,
11829 sections
.str_offsets_size
);
11830 /* The "str" section is global to the entire DWP file. */
11831 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11832 /* The info or types section is assigned below to dwo_unit,
11833 there's no need to record it in dwo_file.
11834 Also, we can't simply record type sections in dwo_file because
11835 we record a pointer into the vector in dwo_unit. As we collect more
11836 types we'll grow the vector and eventually have to reallocate space
11837 for it, invalidating all copies of pointers into the previous
11839 *dwo_file_slot
= dwo_file
;
11843 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11844 virtual_dwo_name
.c_str ());
11846 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11849 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11850 dwo_unit
->dwo_file
= dwo_file
;
11851 dwo_unit
->signature
= signature
;
11852 dwo_unit
->section
=
11853 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11854 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11857 ? &dwp_file
->sections
.types
11858 : &dwp_file
->sections
.info
,
11859 sections
.info_or_types_offset
,
11860 sections
.info_or_types_size
);
11861 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11866 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11867 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11868 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11869 This is for DWP version 5 files. */
11871 static struct dwo_unit
*
11872 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11873 struct dwp_file
*dwp_file
,
11874 uint32_t unit_index
,
11875 const char *comp_dir
,
11876 ULONGEST signature
, int is_debug_types
)
11878 const struct dwp_hash_table
*dwp_htab
11879 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11880 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11881 const char *kind
= is_debug_types
? "TU" : "CU";
11882 struct dwo_file
*dwo_file
;
11883 struct dwo_unit
*dwo_unit
;
11884 struct virtual_v2_or_v5_dwo_sections sections
{};
11885 void **dwo_file_slot
;
11887 gdb_assert (dwp_file
->version
== 5);
11889 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11890 kind
, pulongest (unit_index
), hex_string (signature
),
11893 /* Fetch the section offsets of this DWO unit. */
11895 /* memset (§ions, 0, sizeof (sections)); */
11897 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11899 uint32_t offset
= read_4_bytes (dbfd
,
11900 dwp_htab
->section_pool
.v5
.offsets
11901 + (((unit_index
- 1)
11902 * dwp_htab
->nr_columns
11904 * sizeof (uint32_t)));
11905 uint32_t size
= read_4_bytes (dbfd
,
11906 dwp_htab
->section_pool
.v5
.sizes
11907 + (((unit_index
- 1) * dwp_htab
->nr_columns
11909 * sizeof (uint32_t)));
11911 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11913 case DW_SECT_ABBREV_V5
:
11914 sections
.abbrev_offset
= offset
;
11915 sections
.abbrev_size
= size
;
11917 case DW_SECT_INFO_V5
:
11918 sections
.info_or_types_offset
= offset
;
11919 sections
.info_or_types_size
= size
;
11921 case DW_SECT_LINE_V5
:
11922 sections
.line_offset
= offset
;
11923 sections
.line_size
= size
;
11925 case DW_SECT_LOCLISTS_V5
:
11926 sections
.loclists_offset
= offset
;
11927 sections
.loclists_size
= size
;
11929 case DW_SECT_MACRO_V5
:
11930 sections
.macro_offset
= offset
;
11931 sections
.macro_size
= size
;
11933 case DW_SECT_RNGLISTS_V5
:
11934 sections
.rnglists_offset
= offset
;
11935 sections
.rnglists_size
= size
;
11937 case DW_SECT_STR_OFFSETS_V5
:
11938 sections
.str_offsets_offset
= offset
;
11939 sections
.str_offsets_size
= size
;
11941 case DW_SECT_RESERVED_V5
:
11947 /* It's easier for the rest of the code if we fake a struct dwo_file and
11948 have dwo_unit "live" in that. At least for now.
11950 The DWP file can be made up of a random collection of CUs and TUs.
11951 However, for each CU + set of TUs that came from the same original DWO
11952 file, we can combine them back into a virtual DWO file to save space
11953 (fewer struct dwo_file objects to allocate). Remember that for really
11954 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11956 std::string virtual_dwo_name
=
11957 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11958 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11959 (long) (sections
.line_size
? sections
.line_offset
: 0),
11960 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11961 (long) (sections
.str_offsets_size
11962 ? sections
.str_offsets_offset
: 0),
11963 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11964 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11965 /* Can we use an existing virtual DWO file? */
11966 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11967 virtual_dwo_name
.c_str (),
11969 /* Create one if necessary. */
11970 if (*dwo_file_slot
== NULL
)
11972 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11973 virtual_dwo_name
.c_str ());
11975 dwo_file
= new struct dwo_file
;
11976 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11977 dwo_file
->comp_dir
= comp_dir
;
11978 dwo_file
->sections
.abbrev
=
11979 create_dwp_v2_or_v5_section (per_objfile
,
11980 &dwp_file
->sections
.abbrev
,
11981 sections
.abbrev_offset
,
11982 sections
.abbrev_size
);
11983 dwo_file
->sections
.line
=
11984 create_dwp_v2_or_v5_section (per_objfile
,
11985 &dwp_file
->sections
.line
,
11986 sections
.line_offset
, sections
.line_size
);
11987 dwo_file
->sections
.macro
=
11988 create_dwp_v2_or_v5_section (per_objfile
,
11989 &dwp_file
->sections
.macro
,
11990 sections
.macro_offset
,
11991 sections
.macro_size
);
11992 dwo_file
->sections
.loclists
=
11993 create_dwp_v2_or_v5_section (per_objfile
,
11994 &dwp_file
->sections
.loclists
,
11995 sections
.loclists_offset
,
11996 sections
.loclists_size
);
11997 dwo_file
->sections
.rnglists
=
11998 create_dwp_v2_or_v5_section (per_objfile
,
11999 &dwp_file
->sections
.rnglists
,
12000 sections
.rnglists_offset
,
12001 sections
.rnglists_size
);
12002 dwo_file
->sections
.str_offsets
=
12003 create_dwp_v2_or_v5_section (per_objfile
,
12004 &dwp_file
->sections
.str_offsets
,
12005 sections
.str_offsets_offset
,
12006 sections
.str_offsets_size
);
12007 /* The "str" section is global to the entire DWP file. */
12008 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12009 /* The info or types section is assigned below to dwo_unit,
12010 there's no need to record it in dwo_file.
12011 Also, we can't simply record type sections in dwo_file because
12012 we record a pointer into the vector in dwo_unit. As we collect more
12013 types we'll grow the vector and eventually have to reallocate space
12014 for it, invalidating all copies of pointers into the previous
12016 *dwo_file_slot
= dwo_file
;
12020 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12021 virtual_dwo_name
.c_str ());
12023 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12026 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12027 dwo_unit
->dwo_file
= dwo_file
;
12028 dwo_unit
->signature
= signature
;
12030 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12031 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12032 &dwp_file
->sections
.info
,
12033 sections
.info_or_types_offset
,
12034 sections
.info_or_types_size
);
12035 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12040 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12041 Returns NULL if the signature isn't found. */
12043 static struct dwo_unit
*
12044 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12045 struct dwp_file
*dwp_file
, const char *comp_dir
,
12046 ULONGEST signature
, int is_debug_types
)
12048 const struct dwp_hash_table
*dwp_htab
=
12049 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12050 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12051 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12052 uint32_t hash
= signature
& mask
;
12053 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12056 struct dwo_unit find_dwo_cu
;
12058 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12059 find_dwo_cu
.signature
= signature
;
12060 slot
= htab_find_slot (is_debug_types
12061 ? dwp_file
->loaded_tus
.get ()
12062 : dwp_file
->loaded_cus
.get (),
12063 &find_dwo_cu
, INSERT
);
12066 return (struct dwo_unit
*) *slot
;
12068 /* Use a for loop so that we don't loop forever on bad debug info. */
12069 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12071 ULONGEST signature_in_table
;
12073 signature_in_table
=
12074 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12075 if (signature_in_table
== signature
)
12077 uint32_t unit_index
=
12078 read_4_bytes (dbfd
,
12079 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12081 if (dwp_file
->version
== 1)
12083 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12084 unit_index
, comp_dir
,
12085 signature
, is_debug_types
);
12087 else if (dwp_file
->version
== 2)
12089 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12090 unit_index
, comp_dir
,
12091 signature
, is_debug_types
);
12093 else /* version == 5 */
12095 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12096 unit_index
, comp_dir
,
12097 signature
, is_debug_types
);
12099 return (struct dwo_unit
*) *slot
;
12101 if (signature_in_table
== 0)
12103 hash
= (hash
+ hash2
) & mask
;
12106 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12107 " [in module %s]"),
12111 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12112 Open the file specified by FILE_NAME and hand it off to BFD for
12113 preliminary analysis. Return a newly initialized bfd *, which
12114 includes a canonicalized copy of FILE_NAME.
12115 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12116 SEARCH_CWD is true if the current directory is to be searched.
12117 It will be searched before debug-file-directory.
12118 If successful, the file is added to the bfd include table of the
12119 objfile's bfd (see gdb_bfd_record_inclusion).
12120 If unable to find/open the file, return NULL.
12121 NOTE: This function is derived from symfile_bfd_open. */
12123 static gdb_bfd_ref_ptr
12124 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12125 const char *file_name
, int is_dwp
, int search_cwd
)
12128 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12129 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12130 to debug_file_directory. */
12131 const char *search_path
;
12132 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12134 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12137 if (!debug_file_directory
.empty ())
12139 search_path_holder
.reset (concat (".", dirname_separator_string
,
12140 debug_file_directory
.c_str (),
12142 search_path
= search_path_holder
.get ();
12148 search_path
= debug_file_directory
.c_str ();
12150 /* Add the path for the executable binary to the list of search paths. */
12151 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12152 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12153 dirname_separator_string
,
12154 search_path
, nullptr));
12155 search_path
= search_path_holder
.get ();
12157 openp_flags flags
= OPF_RETURN_REALPATH
;
12159 flags
|= OPF_SEARCH_IN_PATH
;
12161 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12162 desc
= openp (search_path
, flags
, file_name
,
12163 O_RDONLY
| O_BINARY
, &absolute_name
);
12167 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12169 if (sym_bfd
== NULL
)
12171 bfd_set_cacheable (sym_bfd
.get (), 1);
12173 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12176 /* Success. Record the bfd as having been included by the objfile's bfd.
12177 This is important because things like demangled_names_hash lives in the
12178 objfile's per_bfd space and may have references to things like symbol
12179 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12180 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12185 /* Try to open DWO file FILE_NAME.
12186 COMP_DIR is the DW_AT_comp_dir attribute.
12187 The result is the bfd handle of the file.
12188 If there is a problem finding or opening the file, return NULL.
12189 Upon success, the canonicalized path of the file is stored in the bfd,
12190 same as symfile_bfd_open. */
12192 static gdb_bfd_ref_ptr
12193 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12194 const char *file_name
, const char *comp_dir
)
12196 if (IS_ABSOLUTE_PATH (file_name
))
12197 return try_open_dwop_file (per_objfile
, file_name
,
12198 0 /*is_dwp*/, 0 /*search_cwd*/);
12200 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12202 if (comp_dir
!= NULL
)
12204 gdb::unique_xmalloc_ptr
<char> path_to_try
12205 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12207 /* NOTE: If comp_dir is a relative path, this will also try the
12208 search path, which seems useful. */
12209 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12211 1 /*search_cwd*/));
12216 /* That didn't work, try debug-file-directory, which, despite its name,
12217 is a list of paths. */
12219 if (debug_file_directory
.empty ())
12222 return try_open_dwop_file (per_objfile
, file_name
,
12223 0 /*is_dwp*/, 1 /*search_cwd*/);
12226 /* This function is mapped across the sections and remembers the offset and
12227 size of each of the DWO debugging sections we are interested in. */
12230 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12231 dwo_sections
*dwo_sections
)
12233 const struct dwop_section_names
*names
= &dwop_section_names
;
12235 if (names
->abbrev_dwo
.matches (sectp
->name
))
12237 dwo_sections
->abbrev
.s
.section
= sectp
;
12238 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12240 else if (names
->info_dwo
.matches (sectp
->name
))
12242 dwo_sections
->info
.s
.section
= sectp
;
12243 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12245 else if (names
->line_dwo
.matches (sectp
->name
))
12247 dwo_sections
->line
.s
.section
= sectp
;
12248 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12250 else if (names
->loc_dwo
.matches (sectp
->name
))
12252 dwo_sections
->loc
.s
.section
= sectp
;
12253 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12255 else if (names
->loclists_dwo
.matches (sectp
->name
))
12257 dwo_sections
->loclists
.s
.section
= sectp
;
12258 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12260 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12262 dwo_sections
->macinfo
.s
.section
= sectp
;
12263 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12265 else if (names
->macro_dwo
.matches (sectp
->name
))
12267 dwo_sections
->macro
.s
.section
= sectp
;
12268 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12270 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12272 dwo_sections
->rnglists
.s
.section
= sectp
;
12273 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12275 else if (names
->str_dwo
.matches (sectp
->name
))
12277 dwo_sections
->str
.s
.section
= sectp
;
12278 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12280 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12282 dwo_sections
->str_offsets
.s
.section
= sectp
;
12283 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12285 else if (names
->types_dwo
.matches (sectp
->name
))
12287 struct dwarf2_section_info type_section
;
12289 memset (&type_section
, 0, sizeof (type_section
));
12290 type_section
.s
.section
= sectp
;
12291 type_section
.size
= bfd_section_size (sectp
);
12292 dwo_sections
->types
.push_back (type_section
);
12296 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12297 by PER_CU. This is for the non-DWP case.
12298 The result is NULL if DWO_NAME can't be found. */
12300 static struct dwo_file
*
12301 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12302 const char *comp_dir
)
12304 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12306 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12309 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12314 dwo_file_up
dwo_file (new struct dwo_file
);
12315 dwo_file
->dwo_name
= dwo_name
;
12316 dwo_file
->comp_dir
= comp_dir
;
12317 dwo_file
->dbfd
= std::move (dbfd
);
12319 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12320 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12321 &dwo_file
->sections
);
12323 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12326 if (cu
->per_cu
->dwarf_version
< 5)
12328 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12329 dwo_file
->sections
.types
, dwo_file
->tus
);
12333 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12334 &dwo_file
->sections
.info
, dwo_file
->tus
,
12335 rcuh_kind::COMPILE
);
12338 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12340 return dwo_file
.release ();
12343 /* This function is mapped across the sections and remembers the offset and
12344 size of each of the DWP debugging sections common to version 1 and 2 that
12345 we are interested in. */
12348 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12349 dwp_file
*dwp_file
)
12351 const struct dwop_section_names
*names
= &dwop_section_names
;
12352 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12354 /* Record the ELF section number for later lookup: this is what the
12355 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12356 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12357 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12359 /* Look for specific sections that we need. */
12360 if (names
->str_dwo
.matches (sectp
->name
))
12362 dwp_file
->sections
.str
.s
.section
= sectp
;
12363 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12365 else if (names
->cu_index
.matches (sectp
->name
))
12367 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12368 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12370 else if (names
->tu_index
.matches (sectp
->name
))
12372 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12373 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12377 /* This function is mapped across the sections and remembers the offset and
12378 size of each of the DWP version 2 debugging sections that we are interested
12379 in. This is split into a separate function because we don't know if we
12380 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12383 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12385 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12386 const struct dwop_section_names
*names
= &dwop_section_names
;
12387 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12389 /* Record the ELF section number for later lookup: this is what the
12390 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12391 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12392 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12394 /* Look for specific sections that we need. */
12395 if (names
->abbrev_dwo
.matches (sectp
->name
))
12397 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12398 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12400 else if (names
->info_dwo
.matches (sectp
->name
))
12402 dwp_file
->sections
.info
.s
.section
= sectp
;
12403 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12405 else if (names
->line_dwo
.matches (sectp
->name
))
12407 dwp_file
->sections
.line
.s
.section
= sectp
;
12408 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12410 else if (names
->loc_dwo
.matches (sectp
->name
))
12412 dwp_file
->sections
.loc
.s
.section
= sectp
;
12413 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12415 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12417 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12418 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12420 else if (names
->macro_dwo
.matches (sectp
->name
))
12422 dwp_file
->sections
.macro
.s
.section
= sectp
;
12423 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12425 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12427 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12428 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12430 else if (names
->types_dwo
.matches (sectp
->name
))
12432 dwp_file
->sections
.types
.s
.section
= sectp
;
12433 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12437 /* This function is mapped across the sections and remembers the offset and
12438 size of each of the DWP version 5 debugging sections that we are interested
12439 in. This is split into a separate function because we don't know if we
12440 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12443 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12445 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12446 const struct dwop_section_names
*names
= &dwop_section_names
;
12447 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12449 /* Record the ELF section number for later lookup: this is what the
12450 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12451 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12452 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12454 /* Look for specific sections that we need. */
12455 if (names
->abbrev_dwo
.matches (sectp
->name
))
12457 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12458 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12460 else if (names
->info_dwo
.matches (sectp
->name
))
12462 dwp_file
->sections
.info
.s
.section
= sectp
;
12463 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12465 else if (names
->line_dwo
.matches (sectp
->name
))
12467 dwp_file
->sections
.line
.s
.section
= sectp
;
12468 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12470 else if (names
->loclists_dwo
.matches (sectp
->name
))
12472 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12473 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12475 else if (names
->macro_dwo
.matches (sectp
->name
))
12477 dwp_file
->sections
.macro
.s
.section
= sectp
;
12478 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12480 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12482 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12483 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12485 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12487 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12488 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12492 /* Hash function for dwp_file loaded CUs/TUs. */
12495 hash_dwp_loaded_cutus (const void *item
)
12497 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12499 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12500 return dwo_unit
->signature
;
12503 /* Equality function for dwp_file loaded CUs/TUs. */
12506 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12508 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12509 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12511 return dua
->signature
== dub
->signature
;
12514 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12517 allocate_dwp_loaded_cutus_table ()
12519 return htab_up (htab_create_alloc (3,
12520 hash_dwp_loaded_cutus
,
12521 eq_dwp_loaded_cutus
,
12522 NULL
, xcalloc
, xfree
));
12525 /* Try to open DWP file FILE_NAME.
12526 The result is the bfd handle of the file.
12527 If there is a problem finding or opening the file, return NULL.
12528 Upon success, the canonicalized path of the file is stored in the bfd,
12529 same as symfile_bfd_open. */
12531 static gdb_bfd_ref_ptr
12532 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12534 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12536 1 /*search_cwd*/));
12540 /* Work around upstream bug 15652.
12541 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12542 [Whether that's a "bug" is debatable, but it is getting in our way.]
12543 We have no real idea where the dwp file is, because gdb's realpath-ing
12544 of the executable's path may have discarded the needed info.
12545 [IWBN if the dwp file name was recorded in the executable, akin to
12546 .gnu_debuglink, but that doesn't exist yet.]
12547 Strip the directory from FILE_NAME and search again. */
12548 if (!debug_file_directory
.empty ())
12550 /* Don't implicitly search the current directory here.
12551 If the user wants to search "." to handle this case,
12552 it must be added to debug-file-directory. */
12553 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12561 /* Initialize the use of the DWP file for the current objfile.
12562 By convention the name of the DWP file is ${objfile}.dwp.
12563 The result is NULL if it can't be found. */
12565 static std::unique_ptr
<struct dwp_file
>
12566 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12568 struct objfile
*objfile
= per_objfile
->objfile
;
12570 /* Try to find first .dwp for the binary file before any symbolic links
12573 /* If the objfile is a debug file, find the name of the real binary
12574 file and get the name of dwp file from there. */
12575 std::string dwp_name
;
12576 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12578 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12579 const char *backlink_basename
= lbasename (backlink
->original_name
);
12581 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12584 dwp_name
= objfile
->original_name
;
12586 dwp_name
+= ".dwp";
12588 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12590 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12592 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12593 dwp_name
= objfile_name (objfile
);
12594 dwp_name
+= ".dwp";
12595 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12600 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12602 return std::unique_ptr
<dwp_file
> ();
12605 const char *name
= bfd_get_filename (dbfd
.get ());
12606 std::unique_ptr
<struct dwp_file
> dwp_file
12607 (new struct dwp_file (name
, std::move (dbfd
)));
12609 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12610 dwp_file
->elf_sections
=
12611 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12612 dwp_file
->num_sections
, asection
*);
12614 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12615 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12618 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12620 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12622 /* The DWP file version is stored in the hash table. Oh well. */
12623 if (dwp_file
->cus
&& dwp_file
->tus
12624 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12626 /* Technically speaking, we should try to limp along, but this is
12627 pretty bizarre. We use pulongest here because that's the established
12628 portability solution (e.g, we cannot use %u for uint32_t). */
12629 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12630 " TU version %s [in DWP file %s]"),
12631 pulongest (dwp_file
->cus
->version
),
12632 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12636 dwp_file
->version
= dwp_file
->cus
->version
;
12637 else if (dwp_file
->tus
)
12638 dwp_file
->version
= dwp_file
->tus
->version
;
12640 dwp_file
->version
= 2;
12642 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12644 if (dwp_file
->version
== 2)
12645 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12648 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12652 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12653 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12655 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12656 dwarf_read_debug_printf (" %s CUs, %s TUs",
12657 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12658 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12663 /* Wrapper around open_and_init_dwp_file, only open it once. */
12665 static struct dwp_file
*
12666 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12668 if (!per_objfile
->per_bfd
->dwp_checked
)
12670 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12671 per_objfile
->per_bfd
->dwp_checked
= 1;
12673 return per_objfile
->per_bfd
->dwp_file
.get ();
12676 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12677 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12678 or in the DWP file for the objfile, referenced by THIS_UNIT.
12679 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12680 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12682 This is called, for example, when wanting to read a variable with a
12683 complex location. Therefore we don't want to do file i/o for every call.
12684 Therefore we don't want to look for a DWO file on every call.
12685 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12686 then we check if we've already seen DWO_NAME, and only THEN do we check
12689 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12690 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12692 static struct dwo_unit
*
12693 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12694 ULONGEST signature
, int is_debug_types
)
12696 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12697 struct objfile
*objfile
= per_objfile
->objfile
;
12698 const char *kind
= is_debug_types
? "TU" : "CU";
12699 void **dwo_file_slot
;
12700 struct dwo_file
*dwo_file
;
12701 struct dwp_file
*dwp_file
;
12703 /* First see if there's a DWP file.
12704 If we have a DWP file but didn't find the DWO inside it, don't
12705 look for the original DWO file. It makes gdb behave differently
12706 depending on whether one is debugging in the build tree. */
12708 dwp_file
= get_dwp_file (per_objfile
);
12709 if (dwp_file
!= NULL
)
12711 const struct dwp_hash_table
*dwp_htab
=
12712 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12714 if (dwp_htab
!= NULL
)
12716 struct dwo_unit
*dwo_cutu
=
12717 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12720 if (dwo_cutu
!= NULL
)
12722 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12723 kind
, hex_string (signature
),
12724 host_address_to_string (dwo_cutu
));
12732 /* No DWP file, look for the DWO file. */
12734 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12735 if (*dwo_file_slot
== NULL
)
12737 /* Read in the file and build a table of the CUs/TUs it contains. */
12738 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12740 /* NOTE: This will be NULL if unable to open the file. */
12741 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12743 if (dwo_file
!= NULL
)
12745 struct dwo_unit
*dwo_cutu
= NULL
;
12747 if (is_debug_types
&& dwo_file
->tus
)
12749 struct dwo_unit find_dwo_cutu
;
12751 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12752 find_dwo_cutu
.signature
= signature
;
12754 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12757 else if (!is_debug_types
&& dwo_file
->cus
)
12759 struct dwo_unit find_dwo_cutu
;
12761 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12762 find_dwo_cutu
.signature
= signature
;
12763 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12767 if (dwo_cutu
!= NULL
)
12769 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12770 kind
, dwo_name
, hex_string (signature
),
12771 host_address_to_string (dwo_cutu
));
12778 /* We didn't find it. This could mean a dwo_id mismatch, or
12779 someone deleted the DWO/DWP file, or the search path isn't set up
12780 correctly to find the file. */
12782 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12783 kind
, dwo_name
, hex_string (signature
));
12785 /* This is a warning and not a complaint because it can be caused by
12786 pilot error (e.g., user accidentally deleting the DWO). */
12788 /* Print the name of the DWP file if we looked there, helps the user
12789 better diagnose the problem. */
12790 std::string dwp_text
;
12792 if (dwp_file
!= NULL
)
12793 dwp_text
= string_printf (" [in DWP file %s]",
12794 lbasename (dwp_file
->name
));
12796 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12797 " [in module %s]"),
12798 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12799 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12804 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12805 See lookup_dwo_cutu_unit for details. */
12807 static struct dwo_unit
*
12808 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12809 ULONGEST signature
)
12811 gdb_assert (!cu
->per_cu
->is_debug_types
);
12813 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12816 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12817 See lookup_dwo_cutu_unit for details. */
12819 static struct dwo_unit
*
12820 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12822 gdb_assert (cu
->per_cu
->is_debug_types
);
12824 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12826 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12829 /* Traversal function for queue_and_load_all_dwo_tus. */
12832 queue_and_load_dwo_tu (void **slot
, void *info
)
12834 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12835 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12836 ULONGEST signature
= dwo_unit
->signature
;
12837 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12839 if (sig_type
!= NULL
)
12841 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12842 a real dependency of PER_CU on SIG_TYPE. That is detected later
12843 while processing PER_CU. */
12844 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12846 load_full_type_unit (sig_type
, cu
->per_objfile
);
12847 cu
->per_cu
->imported_symtabs_push (sig_type
);
12853 /* Queue all TUs contained in the DWO of CU to be read in.
12854 The DWO may have the only definition of the type, though it may not be
12855 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12856 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12859 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12861 struct dwo_unit
*dwo_unit
;
12862 struct dwo_file
*dwo_file
;
12864 gdb_assert (cu
!= nullptr);
12865 gdb_assert (!cu
->per_cu
->is_debug_types
);
12866 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12868 dwo_unit
= cu
->dwo_unit
;
12869 gdb_assert (dwo_unit
!= NULL
);
12871 dwo_file
= dwo_unit
->dwo_file
;
12872 if (dwo_file
->tus
!= NULL
)
12873 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12876 /* Read in various DIEs. */
12878 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12879 Inherit only the children of the DW_AT_abstract_origin DIE not being
12880 already referenced by DW_AT_abstract_origin from the children of the
12884 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12886 struct die_info
*child_die
;
12887 sect_offset
*offsetp
;
12888 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12889 struct die_info
*origin_die
;
12890 /* Iterator of the ORIGIN_DIE children. */
12891 struct die_info
*origin_child_die
;
12892 struct attribute
*attr
;
12893 struct dwarf2_cu
*origin_cu
;
12894 struct pending
**origin_previous_list_in_scope
;
12896 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12900 /* Note that following die references may follow to a die in a
12904 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12906 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12908 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12909 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12911 if (die
->tag
!= origin_die
->tag
12912 && !(die
->tag
== DW_TAG_inlined_subroutine
12913 && origin_die
->tag
== DW_TAG_subprogram
))
12914 complaint (_("DIE %s and its abstract origin %s have different tags"),
12915 sect_offset_str (die
->sect_off
),
12916 sect_offset_str (origin_die
->sect_off
));
12918 /* Find if the concrete and abstract trees are structurally the
12919 same. This is a shallow traversal and it is not bullet-proof;
12920 the compiler can trick the debugger into believing that the trees
12921 are isomorphic, whereas they actually are not. However, the
12922 likelyhood of this happening is pretty low, and a full-fledged
12923 check would be an overkill. */
12924 bool are_isomorphic
= true;
12925 die_info
*concrete_child
= die
->child
;
12926 die_info
*abstract_child
= origin_die
->child
;
12927 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12929 if (concrete_child
== nullptr
12930 || abstract_child
== nullptr
12931 || concrete_child
->tag
!= abstract_child
->tag
)
12933 are_isomorphic
= false;
12937 concrete_child
= concrete_child
->sibling
;
12938 abstract_child
= abstract_child
->sibling
;
12941 /* Walk the origin's children in parallel to the concrete children.
12942 This helps match an origin child in case the debug info misses
12943 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12944 origin tree may not have the same tree structure as the concrete
12946 die_info
*corresponding_abstract_child
12947 = are_isomorphic
? origin_die
->child
: nullptr;
12949 std::vector
<sect_offset
> offsets
;
12951 for (child_die
= die
->child
;
12952 child_die
&& child_die
->tag
;
12953 child_die
= child_die
->sibling
)
12955 struct die_info
*child_origin_die
;
12956 struct dwarf2_cu
*child_origin_cu
;
12958 /* We are trying to process concrete instance entries:
12959 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12960 it's not relevant to our analysis here. i.e. detecting DIEs that are
12961 present in the abstract instance but not referenced in the concrete
12963 if (child_die
->tag
== DW_TAG_call_site
12964 || child_die
->tag
== DW_TAG_GNU_call_site
)
12966 if (are_isomorphic
)
12967 corresponding_abstract_child
12968 = corresponding_abstract_child
->sibling
;
12972 /* For each CHILD_DIE, find the corresponding child of
12973 ORIGIN_DIE. If there is more than one layer of
12974 DW_AT_abstract_origin, follow them all; there shouldn't be,
12975 but GCC versions at least through 4.4 generate this (GCC PR
12977 child_origin_die
= child_die
;
12978 child_origin_cu
= cu
;
12981 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12985 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12989 /* If missing DW_AT_abstract_origin, try the corresponding child
12990 of the origin. Clang emits such lexical scopes. */
12991 if (child_origin_die
== child_die
12992 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12994 && child_die
->tag
== DW_TAG_lexical_block
)
12995 child_origin_die
= corresponding_abstract_child
;
12997 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12998 counterpart may exist. */
12999 if (child_origin_die
!= child_die
)
13001 if (child_die
->tag
!= child_origin_die
->tag
13002 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13003 && child_origin_die
->tag
== DW_TAG_subprogram
))
13004 complaint (_("Child DIE %s and its abstract origin %s have "
13006 sect_offset_str (child_die
->sect_off
),
13007 sect_offset_str (child_origin_die
->sect_off
));
13008 if (child_origin_die
->parent
!= origin_die
)
13009 complaint (_("Child DIE %s and its abstract origin %s have "
13010 "different parents"),
13011 sect_offset_str (child_die
->sect_off
),
13012 sect_offset_str (child_origin_die
->sect_off
));
13014 offsets
.push_back (child_origin_die
->sect_off
);
13017 if (are_isomorphic
)
13018 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13020 std::sort (offsets
.begin (), offsets
.end ());
13021 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13022 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13023 if (offsetp
[-1] == *offsetp
)
13024 complaint (_("Multiple children of DIE %s refer "
13025 "to DIE %s as their abstract origin"),
13026 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13028 offsetp
= offsets
.data ();
13029 origin_child_die
= origin_die
->child
;
13030 while (origin_child_die
&& origin_child_die
->tag
)
13032 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13033 while (offsetp
< offsets_end
13034 && *offsetp
< origin_child_die
->sect_off
)
13036 if (offsetp
>= offsets_end
13037 || *offsetp
> origin_child_die
->sect_off
)
13039 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13040 Check whether we're already processing ORIGIN_CHILD_DIE.
13041 This can happen with mutually referenced abstract_origins.
13043 if (!origin_child_die
->in_process
)
13044 process_die (origin_child_die
, origin_cu
);
13046 origin_child_die
= origin_child_die
->sibling
;
13048 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13050 if (cu
!= origin_cu
)
13051 compute_delayed_physnames (origin_cu
);
13055 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13057 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13058 struct gdbarch
*gdbarch
= objfile
->arch ();
13059 struct context_stack
*newobj
;
13062 struct die_info
*child_die
;
13063 struct attribute
*attr
, *call_line
, *call_file
;
13065 CORE_ADDR baseaddr
;
13066 struct block
*block
;
13067 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13068 std::vector
<struct symbol
*> template_args
;
13069 struct template_symbol
*templ_func
= NULL
;
13073 /* If we do not have call site information, we can't show the
13074 caller of this inlined function. That's too confusing, so
13075 only use the scope for local variables. */
13076 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13077 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13078 if (call_line
== NULL
|| call_file
== NULL
)
13080 read_lexical_block_scope (die
, cu
);
13085 baseaddr
= objfile
->text_section_offset ();
13087 name
= dwarf2_name (die
, cu
);
13089 /* Ignore functions with missing or empty names. These are actually
13090 illegal according to the DWARF standard. */
13093 complaint (_("missing name for subprogram DIE at %s"),
13094 sect_offset_str (die
->sect_off
));
13098 /* Ignore functions with missing or invalid low and high pc attributes. */
13099 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13100 <= PC_BOUNDS_INVALID
)
13102 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13103 if (attr
== nullptr || !attr
->as_boolean ())
13104 complaint (_("cannot get low and high bounds "
13105 "for subprogram DIE at %s"),
13106 sect_offset_str (die
->sect_off
));
13110 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13111 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13113 /* If we have any template arguments, then we must allocate a
13114 different sort of symbol. */
13115 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13117 if (child_die
->tag
== DW_TAG_template_type_param
13118 || child_die
->tag
== DW_TAG_template_value_param
)
13120 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13121 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13126 gdb_assert (cu
->get_builder () != nullptr);
13127 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13128 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13129 (struct symbol
*) templ_func
);
13131 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13132 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13135 /* If there is a location expression for DW_AT_frame_base, record
13137 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13138 if (attr
!= nullptr)
13139 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13141 /* If there is a location for the static link, record it. */
13142 newobj
->static_link
= NULL
;
13143 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13144 if (attr
!= nullptr)
13146 newobj
->static_link
13147 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13148 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13152 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13154 if (die
->child
!= NULL
)
13156 child_die
= die
->child
;
13157 while (child_die
&& child_die
->tag
)
13159 if (child_die
->tag
== DW_TAG_template_type_param
13160 || child_die
->tag
== DW_TAG_template_value_param
)
13162 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13165 template_args
.push_back (arg
);
13168 process_die (child_die
, cu
);
13169 child_die
= child_die
->sibling
;
13173 inherit_abstract_dies (die
, cu
);
13175 /* If we have a DW_AT_specification, we might need to import using
13176 directives from the context of the specification DIE. See the
13177 comment in determine_prefix. */
13178 if (cu
->per_cu
->lang
== language_cplus
13179 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13181 struct dwarf2_cu
*spec_cu
= cu
;
13182 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13186 child_die
= spec_die
->child
;
13187 while (child_die
&& child_die
->tag
)
13189 if (child_die
->tag
== DW_TAG_imported_module
)
13190 process_die (child_die
, spec_cu
);
13191 child_die
= child_die
->sibling
;
13194 /* In some cases, GCC generates specification DIEs that
13195 themselves contain DW_AT_specification attributes. */
13196 spec_die
= die_specification (spec_die
, &spec_cu
);
13200 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13201 /* Make a block for the local symbols within. */
13202 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13203 cstk
.static_link
, lowpc
, highpc
);
13205 /* For C++, set the block's scope. */
13206 if ((cu
->per_cu
->lang
== language_cplus
13207 || cu
->per_cu
->lang
== language_fortran
13208 || cu
->per_cu
->lang
== language_d
13209 || cu
->per_cu
->lang
== language_rust
)
13210 && cu
->processing_has_namespace_info
)
13211 block_set_scope (block
, determine_prefix (die
, cu
),
13212 &objfile
->objfile_obstack
);
13214 /* If we have address ranges, record them. */
13215 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13217 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13219 /* Attach template arguments to function. */
13220 if (!template_args
.empty ())
13222 gdb_assert (templ_func
!= NULL
);
13224 templ_func
->n_template_arguments
= template_args
.size ();
13225 templ_func
->template_arguments
13226 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13227 templ_func
->n_template_arguments
);
13228 memcpy (templ_func
->template_arguments
,
13229 template_args
.data (),
13230 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13232 /* Make sure that the symtab is set on the new symbols. Even
13233 though they don't appear in this symtab directly, other parts
13234 of gdb assume that symbols do, and this is reasonably
13236 for (symbol
*sym
: template_args
)
13237 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13240 /* In C++, we can have functions nested inside functions (e.g., when
13241 a function declares a class that has methods). This means that
13242 when we finish processing a function scope, we may need to go
13243 back to building a containing block's symbol lists. */
13244 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13245 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13247 /* If we've finished processing a top-level function, subsequent
13248 symbols go in the file symbol list. */
13249 if (cu
->get_builder ()->outermost_context_p ())
13250 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13253 /* Process all the DIES contained within a lexical block scope. Start
13254 a new scope, process the dies, and then close the scope. */
13257 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13259 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13260 struct gdbarch
*gdbarch
= objfile
->arch ();
13261 CORE_ADDR lowpc
, highpc
;
13262 struct die_info
*child_die
;
13263 CORE_ADDR baseaddr
;
13265 baseaddr
= objfile
->text_section_offset ();
13267 /* Ignore blocks with missing or invalid low and high pc attributes. */
13268 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13269 as multiple lexical blocks? Handling children in a sane way would
13270 be nasty. Might be easier to properly extend generic blocks to
13271 describe ranges. */
13272 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13274 case PC_BOUNDS_NOT_PRESENT
:
13275 /* DW_TAG_lexical_block has no attributes, process its children as if
13276 there was no wrapping by that DW_TAG_lexical_block.
13277 GCC does no longer produces such DWARF since GCC r224161. */
13278 for (child_die
= die
->child
;
13279 child_die
!= NULL
&& child_die
->tag
;
13280 child_die
= child_die
->sibling
)
13282 /* We might already be processing this DIE. This can happen
13283 in an unusual circumstance -- where a subroutine A
13284 appears lexically in another subroutine B, but A actually
13285 inlines B. The recursion is broken here, rather than in
13286 inherit_abstract_dies, because it seems better to simply
13287 drop concrete children here. */
13288 if (!child_die
->in_process
)
13289 process_die (child_die
, cu
);
13292 case PC_BOUNDS_INVALID
:
13295 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13296 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13298 cu
->get_builder ()->push_context (0, lowpc
);
13299 if (die
->child
!= NULL
)
13301 child_die
= die
->child
;
13302 while (child_die
&& child_die
->tag
)
13304 process_die (child_die
, cu
);
13305 child_die
= child_die
->sibling
;
13308 inherit_abstract_dies (die
, cu
);
13309 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13311 if (*cu
->get_builder ()->get_local_symbols () != NULL
13312 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13314 struct block
*block
13315 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13316 cstk
.start_addr
, highpc
);
13318 /* Note that recording ranges after traversing children, as we
13319 do here, means that recording a parent's ranges entails
13320 walking across all its children's ranges as they appear in
13321 the address map, which is quadratic behavior.
13323 It would be nicer to record the parent's ranges before
13324 traversing its children, simply overriding whatever you find
13325 there. But since we don't even decide whether to create a
13326 block until after we've traversed its children, that's hard
13328 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13330 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13331 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13334 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13337 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13339 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13340 struct objfile
*objfile
= per_objfile
->objfile
;
13341 struct gdbarch
*gdbarch
= objfile
->arch ();
13342 CORE_ADDR pc
, baseaddr
;
13343 struct attribute
*attr
;
13346 struct die_info
*child_die
;
13348 baseaddr
= objfile
->text_section_offset ();
13350 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13353 /* This was a pre-DWARF-5 GNU extension alias
13354 for DW_AT_call_return_pc. */
13355 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13359 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13360 "DIE %s [in module %s]"),
13361 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13364 pc
= attr
->as_address () + baseaddr
;
13365 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13368 if (cu
->call_site_htab
== NULL
)
13369 cu
->call_site_htab
= htab_create_alloc_ex (16, call_site::hash
,
13370 call_site::eq
, NULL
,
13371 &objfile
->objfile_obstack
,
13372 hashtab_obstack_allocate
, NULL
);
13373 struct call_site
call_site_local (pc
, nullptr, nullptr);
13374 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13377 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13378 "DIE %s [in module %s]"),
13379 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13380 objfile_name (objfile
));
13384 /* Count parameters at the caller. */
13387 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13388 child_die
= child_die
->sibling
)
13390 if (child_die
->tag
!= DW_TAG_call_site_parameter
13391 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13393 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13394 "DW_TAG_call_site child DIE %s [in module %s]"),
13395 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13396 objfile_name (objfile
));
13403 struct call_site
*call_site
13404 = new (XOBNEWVAR (&objfile
->objfile_obstack
,
13406 sizeof (*call_site
) + sizeof (call_site
->parameter
[0]) * nparams
))
13407 struct call_site (pc
, cu
->per_cu
, per_objfile
);
13410 /* We never call the destructor of call_site, so we must ensure it is
13411 trivially destructible. */
13412 gdb_static_assert(std::is_trivially_destructible
<struct call_site
>::value
);
13414 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13415 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13417 struct die_info
*func_die
;
13419 /* Skip also over DW_TAG_inlined_subroutine. */
13420 for (func_die
= die
->parent
;
13421 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13422 && func_die
->tag
!= DW_TAG_subroutine_type
;
13423 func_die
= func_die
->parent
);
13425 /* DW_AT_call_all_calls is a superset
13426 of DW_AT_call_all_tail_calls. */
13428 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13429 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13430 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13431 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13433 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13434 not complete. But keep CALL_SITE for look ups via call_site_htab,
13435 both the initial caller containing the real return address PC and
13436 the final callee containing the current PC of a chain of tail
13437 calls do not need to have the tail call list complete. But any
13438 function candidate for a virtual tail call frame searched via
13439 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13440 determined unambiguously. */
13444 struct type
*func_type
= NULL
;
13447 func_type
= get_die_type (func_die
, cu
);
13448 if (func_type
!= NULL
)
13450 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13452 /* Enlist this call site to the function. */
13453 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13454 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13457 complaint (_("Cannot find function owning DW_TAG_call_site "
13458 "DIE %s [in module %s]"),
13459 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13463 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13465 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13467 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13470 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13471 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13473 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13474 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13475 /* Keep NULL DWARF_BLOCK. */;
13476 else if (attr
->form_is_block ())
13478 struct dwarf2_locexpr_baton
*dlbaton
;
13479 struct dwarf_block
*block
= attr
->as_block ();
13481 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13482 dlbaton
->data
= block
->data
;
13483 dlbaton
->size
= block
->size
;
13484 dlbaton
->per_objfile
= per_objfile
;
13485 dlbaton
->per_cu
= cu
->per_cu
;
13487 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13489 else if (attr
->form_is_ref ())
13491 struct dwarf2_cu
*target_cu
= cu
;
13492 struct die_info
*target_die
;
13494 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13495 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13496 if (die_is_declaration (target_die
, target_cu
))
13498 const char *target_physname
;
13500 /* Prefer the mangled name; otherwise compute the demangled one. */
13501 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13502 if (target_physname
== NULL
)
13503 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13504 if (target_physname
== NULL
)
13505 complaint (_("DW_AT_call_target target DIE has invalid "
13506 "physname, for referencing DIE %s [in module %s]"),
13507 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13509 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13515 /* DW_AT_entry_pc should be preferred. */
13516 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13517 <= PC_BOUNDS_INVALID
)
13518 complaint (_("DW_AT_call_target target DIE has invalid "
13519 "low pc, for referencing DIE %s [in module %s]"),
13520 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13523 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
)
13525 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13530 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13531 "block nor reference, for DIE %s [in module %s]"),
13532 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13534 for (child_die
= die
->child
;
13535 child_die
&& child_die
->tag
;
13536 child_die
= child_die
->sibling
)
13538 struct call_site_parameter
*parameter
;
13539 struct attribute
*loc
, *origin
;
13541 if (child_die
->tag
!= DW_TAG_call_site_parameter
13542 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13544 /* Already printed the complaint above. */
13548 gdb_assert (call_site
->parameter_count
< nparams
);
13549 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13551 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13552 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13553 register is contained in DW_AT_call_value. */
13555 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13556 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13557 if (origin
== NULL
)
13559 /* This was a pre-DWARF-5 GNU extension alias
13560 for DW_AT_call_parameter. */
13561 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13563 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13565 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13567 sect_offset sect_off
= origin
->get_ref_die_offset ();
13568 if (!cu
->header
.offset_in_cu_p (sect_off
))
13570 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13571 binding can be done only inside one CU. Such referenced DIE
13572 therefore cannot be even moved to DW_TAG_partial_unit. */
13573 complaint (_("DW_AT_call_parameter offset is not in CU for "
13574 "DW_TAG_call_site child DIE %s [in module %s]"),
13575 sect_offset_str (child_die
->sect_off
),
13576 objfile_name (objfile
));
13579 parameter
->u
.param_cu_off
13580 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13582 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13584 complaint (_("No DW_FORM_block* DW_AT_location for "
13585 "DW_TAG_call_site child DIE %s [in module %s]"),
13586 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13591 struct dwarf_block
*block
= loc
->as_block ();
13593 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13594 (block
->data
, &block
->data
[block
->size
]);
13595 if (parameter
->u
.dwarf_reg
!= -1)
13596 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13597 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13598 &block
->data
[block
->size
],
13599 ¶meter
->u
.fb_offset
))
13600 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13603 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13604 "for DW_FORM_block* DW_AT_location is supported for "
13605 "DW_TAG_call_site child DIE %s "
13607 sect_offset_str (child_die
->sect_off
),
13608 objfile_name (objfile
));
13613 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13615 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13616 if (attr
== NULL
|| !attr
->form_is_block ())
13618 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13619 "DW_TAG_call_site child DIE %s [in module %s]"),
13620 sect_offset_str (child_die
->sect_off
),
13621 objfile_name (objfile
));
13625 struct dwarf_block
*block
= attr
->as_block ();
13626 parameter
->value
= block
->data
;
13627 parameter
->value_size
= block
->size
;
13629 /* Parameters are not pre-cleared by memset above. */
13630 parameter
->data_value
= NULL
;
13631 parameter
->data_value_size
= 0;
13632 call_site
->parameter_count
++;
13634 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13636 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13637 if (attr
!= nullptr)
13639 if (!attr
->form_is_block ())
13640 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13641 "DW_TAG_call_site child DIE %s [in module %s]"),
13642 sect_offset_str (child_die
->sect_off
),
13643 objfile_name (objfile
));
13646 block
= attr
->as_block ();
13647 parameter
->data_value
= block
->data
;
13648 parameter
->data_value_size
= block
->size
;
13654 /* Helper function for read_variable. If DIE represents a virtual
13655 table, then return the type of the concrete object that is
13656 associated with the virtual table. Otherwise, return NULL. */
13658 static struct type
*
13659 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13661 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13665 /* Find the type DIE. */
13666 struct die_info
*type_die
= NULL
;
13667 struct dwarf2_cu
*type_cu
= cu
;
13669 if (attr
->form_is_ref ())
13670 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13671 if (type_die
== NULL
)
13674 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13676 return die_containing_type (type_die
, type_cu
);
13679 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13682 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13684 struct rust_vtable_symbol
*storage
= NULL
;
13686 if (cu
->per_cu
->lang
== language_rust
)
13688 struct type
*containing_type
= rust_containing_type (die
, cu
);
13690 if (containing_type
!= NULL
)
13692 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13694 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13695 storage
->concrete_type
= containing_type
;
13696 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13700 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13701 struct attribute
*abstract_origin
13702 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13703 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13704 if (res
== NULL
&& loc
&& abstract_origin
)
13706 /* We have a variable without a name, but with a location and an abstract
13707 origin. This may be a concrete instance of an abstract variable
13708 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13710 struct dwarf2_cu
*origin_cu
= cu
;
13711 struct die_info
*origin_die
13712 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13713 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13714 per_objfile
->per_bfd
->abstract_to_concrete
13715 [origin_die
->sect_off
].push_back (die
->sect_off
);
13719 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13720 reading .debug_rnglists.
13721 Callback's type should be:
13722 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13723 Return true if the attributes are present and valid, otherwise,
13726 template <typename Callback
>
13728 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13729 dwarf_tag tag
, Callback
&&callback
)
13731 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13732 struct objfile
*objfile
= per_objfile
->objfile
;
13733 bfd
*obfd
= objfile
->obfd
;
13734 /* Base address selection entry. */
13735 gdb::optional
<CORE_ADDR
> base
;
13736 const gdb_byte
*buffer
;
13737 bool overflow
= false;
13738 ULONGEST addr_index
;
13739 struct dwarf2_section_info
*rnglists_section
;
13741 base
= cu
->base_address
;
13742 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13743 rnglists_section
->read (objfile
);
13745 if (offset
>= rnglists_section
->size
)
13747 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13751 buffer
= rnglists_section
->buffer
+ offset
;
13755 /* Initialize it due to a false compiler warning. */
13756 CORE_ADDR range_beginning
= 0, range_end
= 0;
13757 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13758 + rnglists_section
->size
);
13759 unsigned int bytes_read
;
13761 if (buffer
== buf_end
)
13766 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13769 case DW_RLE_end_of_list
:
13771 case DW_RLE_base_address
:
13772 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13777 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13778 buffer
+= bytes_read
;
13780 case DW_RLE_base_addressx
:
13781 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13782 buffer
+= bytes_read
;
13783 base
= read_addr_index (cu
, addr_index
);
13785 case DW_RLE_start_length
:
13786 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13791 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13793 buffer
+= bytes_read
;
13794 range_end
= (range_beginning
13795 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13796 buffer
+= bytes_read
;
13797 if (buffer
> buf_end
)
13803 case DW_RLE_startx_length
:
13804 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13805 buffer
+= bytes_read
;
13806 range_beginning
= read_addr_index (cu
, addr_index
);
13807 if (buffer
> buf_end
)
13812 range_end
= (range_beginning
13813 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13814 buffer
+= bytes_read
;
13816 case DW_RLE_offset_pair
:
13817 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13818 buffer
+= bytes_read
;
13819 if (buffer
> buf_end
)
13824 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13825 buffer
+= bytes_read
;
13826 if (buffer
> buf_end
)
13832 case DW_RLE_start_end
:
13833 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13838 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13840 buffer
+= bytes_read
;
13841 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13842 buffer
+= bytes_read
;
13844 case DW_RLE_startx_endx
:
13845 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13846 buffer
+= bytes_read
;
13847 range_beginning
= read_addr_index (cu
, addr_index
);
13848 if (buffer
> buf_end
)
13853 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13854 buffer
+= bytes_read
;
13855 range_end
= read_addr_index (cu
, addr_index
);
13858 complaint (_("Invalid .debug_rnglists data (no base address)"));
13861 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13863 if (rlet
== DW_RLE_base_address
)
13866 if (range_beginning
> range_end
)
13868 /* Inverted range entries are invalid. */
13869 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13873 /* Empty range entries have no effect. */
13874 if (range_beginning
== range_end
)
13877 /* Only DW_RLE_offset_pair needs the base address added. */
13878 if (rlet
== DW_RLE_offset_pair
)
13880 if (!base
.has_value ())
13882 /* We have no valid base address for the DW_RLE_offset_pair. */
13883 complaint (_("Invalid .debug_rnglists data (no base address for "
13884 "DW_RLE_offset_pair)"));
13888 range_beginning
+= *base
;
13889 range_end
+= *base
;
13892 /* A not-uncommon case of bad debug info.
13893 Don't pollute the addrmap with bad data. */
13894 if (range_beginning
== 0
13895 && !per_objfile
->per_bfd
->has_section_at_zero
)
13897 complaint (_(".debug_rnglists entry has start address of zero"
13898 " [in module %s]"), objfile_name (objfile
));
13902 callback (range_beginning
, range_end
);
13907 complaint (_("Offset %d is not terminated "
13908 "for DW_AT_ranges attribute"),
13916 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13917 Callback's type should be:
13918 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13919 Return 1 if the attributes are present and valid, otherwise, return 0. */
13921 template <typename Callback
>
13923 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13924 Callback
&&callback
)
13926 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13927 struct objfile
*objfile
= per_objfile
->objfile
;
13928 struct comp_unit_head
*cu_header
= &cu
->header
;
13929 bfd
*obfd
= objfile
->obfd
;
13930 unsigned int addr_size
= cu_header
->addr_size
;
13931 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13932 /* Base address selection entry. */
13933 gdb::optional
<CORE_ADDR
> base
;
13934 unsigned int dummy
;
13935 const gdb_byte
*buffer
;
13937 if (cu_header
->version
>= 5)
13938 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13940 base
= cu
->base_address
;
13942 per_objfile
->per_bfd
->ranges
.read (objfile
);
13943 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13945 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13949 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13953 CORE_ADDR range_beginning
, range_end
;
13955 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13956 buffer
+= addr_size
;
13957 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13958 buffer
+= addr_size
;
13959 offset
+= 2 * addr_size
;
13961 /* An end of list marker is a pair of zero addresses. */
13962 if (range_beginning
== 0 && range_end
== 0)
13963 /* Found the end of list entry. */
13966 /* Each base address selection entry is a pair of 2 values.
13967 The first is the largest possible address, the second is
13968 the base address. Check for a base address here. */
13969 if ((range_beginning
& mask
) == mask
)
13971 /* If we found the largest possible address, then we already
13972 have the base address in range_end. */
13977 if (!base
.has_value ())
13979 /* We have no valid base address for the ranges
13981 complaint (_("Invalid .debug_ranges data (no base address)"));
13985 if (range_beginning
> range_end
)
13987 /* Inverted range entries are invalid. */
13988 complaint (_("Invalid .debug_ranges data (inverted range)"));
13992 /* Empty range entries have no effect. */
13993 if (range_beginning
== range_end
)
13996 range_beginning
+= *base
;
13997 range_end
+= *base
;
13999 /* A not-uncommon case of bad debug info.
14000 Don't pollute the addrmap with bad data. */
14001 if (range_beginning
== 0
14002 && !per_objfile
->per_bfd
->has_section_at_zero
)
14004 complaint (_(".debug_ranges entry has start address of zero"
14005 " [in module %s]"), objfile_name (objfile
));
14009 callback (range_beginning
, range_end
);
14015 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14016 Return 1 if the attributes are present and valid, otherwise, return 0.
14017 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14020 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14021 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14022 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14024 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14025 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14026 struct gdbarch
*gdbarch
= objfile
->arch ();
14027 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14030 CORE_ADDR high
= 0;
14033 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14034 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14036 if (ranges_pst
!= NULL
)
14041 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14042 range_beginning
+ baseaddr
)
14044 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14045 range_end
+ baseaddr
)
14047 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14048 lowpc
, highpc
- 1, ranges_pst
);
14051 /* FIXME: This is recording everything as a low-high
14052 segment of consecutive addresses. We should have a
14053 data structure for discontiguous block ranges
14057 low
= range_beginning
;
14063 if (range_beginning
< low
)
14064 low
= range_beginning
;
14065 if (range_end
> high
)
14073 /* If the first entry is an end-of-list marker, the range
14074 describes an empty scope, i.e. no instructions. */
14080 *high_return
= high
;
14084 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14085 definition for the return value. *LOWPC and *HIGHPC are set iff
14086 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14088 static enum pc_bounds_kind
14089 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14090 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14091 dwarf2_psymtab
*pst
)
14093 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14094 struct attribute
*attr
;
14095 struct attribute
*attr_high
;
14097 CORE_ADDR high
= 0;
14098 enum pc_bounds_kind ret
;
14100 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14103 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14104 if (attr
!= nullptr)
14106 low
= attr
->as_address ();
14107 high
= attr_high
->as_address ();
14108 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14112 /* Found high w/o low attribute. */
14113 return PC_BOUNDS_INVALID
;
14115 /* Found consecutive range of addresses. */
14116 ret
= PC_BOUNDS_HIGH_LOW
;
14120 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14121 if (attr
!= nullptr && attr
->form_is_unsigned ())
14123 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14124 on DWARF version). */
14125 ULONGEST ranges_offset
= attr
->as_unsigned ();
14127 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14129 if (die
->tag
!= DW_TAG_compile_unit
)
14130 ranges_offset
+= cu
->gnu_ranges_base
;
14132 /* Value of the DW_AT_ranges attribute is the offset in the
14133 .debug_ranges section. */
14134 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14136 return PC_BOUNDS_INVALID
;
14137 /* Found discontinuous range of addresses. */
14138 ret
= PC_BOUNDS_RANGES
;
14141 return PC_BOUNDS_NOT_PRESENT
;
14144 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14146 return PC_BOUNDS_INVALID
;
14148 /* When using the GNU linker, .gnu.linkonce. sections are used to
14149 eliminate duplicate copies of functions and vtables and such.
14150 The linker will arbitrarily choose one and discard the others.
14151 The AT_*_pc values for such functions refer to local labels in
14152 these sections. If the section from that file was discarded, the
14153 labels are not in the output, so the relocs get a value of 0.
14154 If this is a discarded function, mark the pc bounds as invalid,
14155 so that GDB will ignore it. */
14156 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14157 return PC_BOUNDS_INVALID
;
14165 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14166 its low and high PC addresses. Do nothing if these addresses could not
14167 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14168 and HIGHPC to the high address if greater than HIGHPC. */
14171 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14172 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14173 struct dwarf2_cu
*cu
)
14175 CORE_ADDR low
, high
;
14176 struct die_info
*child
= die
->child
;
14178 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14180 *lowpc
= std::min (*lowpc
, low
);
14181 *highpc
= std::max (*highpc
, high
);
14184 /* If the language does not allow nested subprograms (either inside
14185 subprograms or lexical blocks), we're done. */
14186 if (cu
->per_cu
->lang
!= language_ada
)
14189 /* Check all the children of the given DIE. If it contains nested
14190 subprograms, then check their pc bounds. Likewise, we need to
14191 check lexical blocks as well, as they may also contain subprogram
14193 while (child
&& child
->tag
)
14195 if (child
->tag
== DW_TAG_subprogram
14196 || child
->tag
== DW_TAG_lexical_block
)
14197 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14198 child
= child
->sibling
;
14202 /* Get the low and high pc's represented by the scope DIE, and store
14203 them in *LOWPC and *HIGHPC. If the correct values can't be
14204 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14207 get_scope_pc_bounds (struct die_info
*die
,
14208 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14209 struct dwarf2_cu
*cu
)
14211 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14212 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14213 CORE_ADDR current_low
, current_high
;
14215 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14216 >= PC_BOUNDS_RANGES
)
14218 best_low
= current_low
;
14219 best_high
= current_high
;
14223 struct die_info
*child
= die
->child
;
14225 while (child
&& child
->tag
)
14227 switch (child
->tag
) {
14228 case DW_TAG_subprogram
:
14229 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14231 case DW_TAG_namespace
:
14232 case DW_TAG_module
:
14233 /* FIXME: carlton/2004-01-16: Should we do this for
14234 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14235 that current GCC's always emit the DIEs corresponding
14236 to definitions of methods of classes as children of a
14237 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14238 the DIEs giving the declarations, which could be
14239 anywhere). But I don't see any reason why the
14240 standards says that they have to be there. */
14241 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14243 if (current_low
!= ((CORE_ADDR
) -1))
14245 best_low
= std::min (best_low
, current_low
);
14246 best_high
= std::max (best_high
, current_high
);
14254 child
= child
->sibling
;
14259 *highpc
= best_high
;
14262 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14266 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14267 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14269 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14270 struct gdbarch
*gdbarch
= objfile
->arch ();
14271 struct attribute
*attr
;
14272 struct attribute
*attr_high
;
14274 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14277 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14278 if (attr
!= nullptr)
14280 CORE_ADDR low
= attr
->as_address ();
14281 CORE_ADDR high
= attr_high
->as_address ();
14283 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14286 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14287 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14288 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14292 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14293 if (attr
!= nullptr && attr
->form_is_unsigned ())
14295 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14296 on DWARF version). */
14297 ULONGEST ranges_offset
= attr
->as_unsigned ();
14299 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14301 if (die
->tag
!= DW_TAG_compile_unit
)
14302 ranges_offset
+= cu
->gnu_ranges_base
;
14304 std::vector
<blockrange
> blockvec
;
14305 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14306 [&] (CORE_ADDR start
, CORE_ADDR end
)
14310 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14311 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14312 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14313 blockvec
.emplace_back (start
, end
);
14316 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14320 /* Check whether the producer field indicates either of GCC < 4.6, or the
14321 Intel C/C++ compiler, and cache the result in CU. */
14324 check_producer (struct dwarf2_cu
*cu
)
14328 if (cu
->producer
== NULL
)
14330 /* For unknown compilers expect their behavior is DWARF version
14333 GCC started to support .debug_types sections by -gdwarf-4 since
14334 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14335 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14336 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14337 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14339 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14341 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14342 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14344 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14346 cu
->producer_is_icc
= true;
14347 cu
->producer_is_icc_lt_14
= major
< 14;
14349 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14350 cu
->producer_is_codewarrior
= true;
14353 /* For other non-GCC compilers, expect their behavior is DWARF version
14357 cu
->checked_producer
= true;
14360 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14361 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14362 during 4.6.0 experimental. */
14365 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14367 if (!cu
->checked_producer
)
14368 check_producer (cu
);
14370 return cu
->producer_is_gxx_lt_4_6
;
14374 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14375 with incorrect is_stmt attributes. */
14378 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14380 if (!cu
->checked_producer
)
14381 check_producer (cu
);
14383 return cu
->producer_is_codewarrior
;
14386 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14387 If that attribute is not available, return the appropriate
14390 static enum dwarf_access_attribute
14391 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14393 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14394 if (attr
!= nullptr)
14396 LONGEST value
= attr
->constant_value (-1);
14397 if (value
== DW_ACCESS_public
14398 || value
== DW_ACCESS_protected
14399 || value
== DW_ACCESS_private
)
14400 return (dwarf_access_attribute
) value
;
14401 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14405 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14407 /* The default DWARF 2 accessibility for members is public, the default
14408 accessibility for inheritance is private. */
14410 if (die
->tag
!= DW_TAG_inheritance
)
14411 return DW_ACCESS_public
;
14413 return DW_ACCESS_private
;
14417 /* DWARF 3+ defines the default accessibility a different way. The same
14418 rules apply now for DW_TAG_inheritance as for the members and it only
14419 depends on the container kind. */
14421 if (die
->parent
->tag
== DW_TAG_class_type
)
14422 return DW_ACCESS_private
;
14424 return DW_ACCESS_public
;
14428 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset. Set
14429 *OFFSET to the byte offset. If the attribute was not found return
14430 0, otherwise return 1. If it was found but could not properly be
14431 handled, set *OFFSET to 0. */
14434 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14437 struct attribute
*attr
;
14439 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14444 /* Note that we do not check for a section offset first here.
14445 This is because DW_AT_data_member_location is new in DWARF 4,
14446 so if we see it, we can assume that a constant form is really
14447 a constant and not a section offset. */
14448 if (attr
->form_is_constant ())
14449 *offset
= attr
->constant_value (0);
14450 else if (attr
->form_is_section_offset ())
14451 dwarf2_complex_location_expr_complaint ();
14452 else if (attr
->form_is_block ())
14453 *offset
= decode_locdesc (attr
->as_block (), cu
);
14455 dwarf2_complex_location_expr_complaint ();
14461 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14462 if (attr
!= nullptr)
14464 *offset
= attr
->constant_value (0);
14472 /* Look for DW_AT_data_member_location or DW_AT_data_bit_offset and
14473 store the results in FIELD. */
14476 handle_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14477 struct field
*field
)
14479 struct attribute
*attr
;
14481 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14484 if (attr
->form_is_constant ())
14486 LONGEST offset
= attr
->constant_value (0);
14487 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14489 else if (attr
->form_is_section_offset ())
14490 dwarf2_complex_location_expr_complaint ();
14491 else if (attr
->form_is_block ())
14494 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14496 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14499 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14500 struct objfile
*objfile
= per_objfile
->objfile
;
14501 struct dwarf2_locexpr_baton
*dlbaton
14502 = XOBNEW (&objfile
->objfile_obstack
,
14503 struct dwarf2_locexpr_baton
);
14504 dlbaton
->data
= attr
->as_block ()->data
;
14505 dlbaton
->size
= attr
->as_block ()->size
;
14506 /* When using this baton, we want to compute the address
14507 of the field, not the value. This is why
14508 is_reference is set to false here. */
14509 dlbaton
->is_reference
= false;
14510 dlbaton
->per_objfile
= per_objfile
;
14511 dlbaton
->per_cu
= cu
->per_cu
;
14513 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14517 dwarf2_complex_location_expr_complaint ();
14521 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14522 if (attr
!= nullptr)
14523 SET_FIELD_BITPOS (*field
, attr
->constant_value (0));
14527 /* Add an aggregate field to the field list. */
14530 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14531 struct dwarf2_cu
*cu
)
14533 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14534 struct gdbarch
*gdbarch
= objfile
->arch ();
14535 struct nextfield
*new_field
;
14536 struct attribute
*attr
;
14538 const char *fieldname
= "";
14540 if (die
->tag
== DW_TAG_inheritance
)
14542 fip
->baseclasses
.emplace_back ();
14543 new_field
= &fip
->baseclasses
.back ();
14547 fip
->fields
.emplace_back ();
14548 new_field
= &fip
->fields
.back ();
14551 new_field
->offset
= die
->sect_off
;
14553 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14554 if (new_field
->accessibility
!= DW_ACCESS_public
)
14555 fip
->non_public_fields
= true;
14557 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14558 if (attr
!= nullptr)
14559 new_field
->virtuality
= attr
->as_virtuality ();
14561 new_field
->virtuality
= DW_VIRTUALITY_none
;
14563 fp
= &new_field
->field
;
14565 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14567 /* Data member other than a C++ static data member. */
14569 /* Get type of field. */
14570 fp
->set_type (die_type (die
, cu
));
14572 SET_FIELD_BITPOS (*fp
, 0);
14574 /* Get bit size of field (zero if none). */
14575 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14576 if (attr
!= nullptr)
14578 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14582 FIELD_BITSIZE (*fp
) = 0;
14585 /* Get bit offset of field. */
14586 handle_member_location (die
, cu
, fp
);
14587 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14588 if (attr
!= nullptr && attr
->form_is_constant ())
14590 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14592 /* For big endian bits, the DW_AT_bit_offset gives the
14593 additional bit offset from the MSB of the containing
14594 anonymous object to the MSB of the field. We don't
14595 have to do anything special since we don't need to
14596 know the size of the anonymous object. */
14597 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14598 + attr
->constant_value (0)));
14602 /* For little endian bits, compute the bit offset to the
14603 MSB of the anonymous object, subtract off the number of
14604 bits from the MSB of the field to the MSB of the
14605 object, and then subtract off the number of bits of
14606 the field itself. The result is the bit offset of
14607 the LSB of the field. */
14608 int anonymous_size
;
14609 int bit_offset
= attr
->constant_value (0);
14611 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14612 if (attr
!= nullptr && attr
->form_is_constant ())
14614 /* The size of the anonymous object containing
14615 the bit field is explicit, so use the
14616 indicated size (in bytes). */
14617 anonymous_size
= attr
->constant_value (0);
14621 /* The size of the anonymous object containing
14622 the bit field must be inferred from the type
14623 attribute of the data member containing the
14625 anonymous_size
= TYPE_LENGTH (fp
->type ());
14627 SET_FIELD_BITPOS (*fp
,
14628 (FIELD_BITPOS (*fp
)
14629 + anonymous_size
* bits_per_byte
14630 - bit_offset
- FIELD_BITSIZE (*fp
)));
14634 /* Get name of field. */
14635 fieldname
= dwarf2_name (die
, cu
);
14636 if (fieldname
== NULL
)
14639 /* The name is already allocated along with this objfile, so we don't
14640 need to duplicate it for the type. */
14641 fp
->set_name (fieldname
);
14643 /* Change accessibility for artificial fields (e.g. virtual table
14644 pointer or virtual base class pointer) to private. */
14645 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14647 FIELD_ARTIFICIAL (*fp
) = 1;
14648 new_field
->accessibility
= DW_ACCESS_private
;
14649 fip
->non_public_fields
= true;
14652 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14654 /* C++ static member. */
14656 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14657 is a declaration, but all versions of G++ as of this writing
14658 (so through at least 3.2.1) incorrectly generate
14659 DW_TAG_variable tags. */
14661 const char *physname
;
14663 /* Get name of field. */
14664 fieldname
= dwarf2_name (die
, cu
);
14665 if (fieldname
== NULL
)
14668 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14670 /* Only create a symbol if this is an external value.
14671 new_symbol checks this and puts the value in the global symbol
14672 table, which we want. If it is not external, new_symbol
14673 will try to put the value in cu->list_in_scope which is wrong. */
14674 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14676 /* A static const member, not much different than an enum as far as
14677 we're concerned, except that we can support more types. */
14678 new_symbol (die
, NULL
, cu
);
14681 /* Get physical name. */
14682 physname
= dwarf2_physname (fieldname
, die
, cu
);
14684 /* The name is already allocated along with this objfile, so we don't
14685 need to duplicate it for the type. */
14686 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14687 fp
->set_type (die_type (die
, cu
));
14688 fp
->set_name (fieldname
);
14690 else if (die
->tag
== DW_TAG_inheritance
)
14692 /* C++ base class field. */
14693 handle_member_location (die
, cu
, fp
);
14694 FIELD_BITSIZE (*fp
) = 0;
14695 fp
->set_type (die_type (die
, cu
));
14696 fp
->set_name (fp
->type ()->name ());
14699 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14702 /* Can the type given by DIE define another type? */
14705 type_can_define_types (const struct die_info
*die
)
14709 case DW_TAG_typedef
:
14710 case DW_TAG_class_type
:
14711 case DW_TAG_structure_type
:
14712 case DW_TAG_union_type
:
14713 case DW_TAG_enumeration_type
:
14721 /* Add a type definition defined in the scope of the FIP's class. */
14724 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14725 struct dwarf2_cu
*cu
)
14727 struct decl_field fp
;
14728 memset (&fp
, 0, sizeof (fp
));
14730 gdb_assert (type_can_define_types (die
));
14732 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14733 fp
.name
= dwarf2_name (die
, cu
);
14734 fp
.type
= read_type_die (die
, cu
);
14736 /* Save accessibility. */
14737 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14738 switch (accessibility
)
14740 case DW_ACCESS_public
:
14741 /* The assumed value if neither private nor protected. */
14743 case DW_ACCESS_private
:
14746 case DW_ACCESS_protected
:
14747 fp
.is_protected
= 1;
14751 if (die
->tag
== DW_TAG_typedef
)
14752 fip
->typedef_field_list
.push_back (fp
);
14754 fip
->nested_types_list
.push_back (fp
);
14757 /* A convenience typedef that's used when finding the discriminant
14758 field for a variant part. */
14759 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14762 /* Compute the discriminant range for a given variant. OBSTACK is
14763 where the results will be stored. VARIANT is the variant to
14764 process. IS_UNSIGNED indicates whether the discriminant is signed
14767 static const gdb::array_view
<discriminant_range
>
14768 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14771 std::vector
<discriminant_range
> ranges
;
14773 if (variant
.default_branch
)
14776 if (variant
.discr_list_data
== nullptr)
14778 discriminant_range r
14779 = {variant
.discriminant_value
, variant
.discriminant_value
};
14780 ranges
.push_back (r
);
14784 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14785 variant
.discr_list_data
->size
);
14786 while (!data
.empty ())
14788 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14790 complaint (_("invalid discriminant marker: %d"), data
[0]);
14793 bool is_range
= data
[0] == DW_DSC_range
;
14794 data
= data
.slice (1);
14796 ULONGEST low
, high
;
14797 unsigned int bytes_read
;
14801 complaint (_("DW_AT_discr_list missing low value"));
14805 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14807 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14809 data
= data
.slice (bytes_read
);
14815 complaint (_("DW_AT_discr_list missing high value"));
14819 high
= read_unsigned_leb128 (nullptr, data
.data (),
14822 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14824 data
= data
.slice (bytes_read
);
14829 ranges
.push_back ({ low
, high
});
14833 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14835 std::copy (ranges
.begin (), ranges
.end (), result
);
14836 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14839 static const gdb::array_view
<variant_part
> create_variant_parts
14840 (struct obstack
*obstack
,
14841 const offset_map_type
&offset_map
,
14842 struct field_info
*fi
,
14843 const std::vector
<variant_part_builder
> &variant_parts
);
14845 /* Fill in a "struct variant" for a given variant field. RESULT is
14846 the variant to fill in. OBSTACK is where any needed allocations
14847 will be done. OFFSET_MAP holds the mapping from section offsets to
14848 fields for the type. FI describes the fields of the type we're
14849 processing. FIELD is the variant field we're converting. */
14852 create_one_variant (variant
&result
, struct obstack
*obstack
,
14853 const offset_map_type
&offset_map
,
14854 struct field_info
*fi
, const variant_field
&field
)
14856 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14857 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14858 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14859 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14860 field
.variant_parts
);
14863 /* Fill in a "struct variant_part" for a given variant part. RESULT
14864 is the variant part to fill in. OBSTACK is where any needed
14865 allocations will be done. OFFSET_MAP holds the mapping from
14866 section offsets to fields for the type. FI describes the fields of
14867 the type we're processing. BUILDER is the variant part to be
14871 create_one_variant_part (variant_part
&result
,
14872 struct obstack
*obstack
,
14873 const offset_map_type
&offset_map
,
14874 struct field_info
*fi
,
14875 const variant_part_builder
&builder
)
14877 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14878 if (iter
== offset_map
.end ())
14880 result
.discriminant_index
= -1;
14881 /* Doesn't matter. */
14882 result
.is_unsigned
= false;
14886 result
.discriminant_index
= iter
->second
;
14888 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14891 size_t n
= builder
.variants
.size ();
14892 variant
*output
= new (obstack
) variant
[n
];
14893 for (size_t i
= 0; i
< n
; ++i
)
14894 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14895 builder
.variants
[i
]);
14897 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14900 /* Create a vector of variant parts that can be attached to a type.
14901 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14902 holds the mapping from section offsets to fields for the type. FI
14903 describes the fields of the type we're processing. VARIANT_PARTS
14904 is the vector to convert. */
14906 static const gdb::array_view
<variant_part
>
14907 create_variant_parts (struct obstack
*obstack
,
14908 const offset_map_type
&offset_map
,
14909 struct field_info
*fi
,
14910 const std::vector
<variant_part_builder
> &variant_parts
)
14912 if (variant_parts
.empty ())
14915 size_t n
= variant_parts
.size ();
14916 variant_part
*result
= new (obstack
) variant_part
[n
];
14917 for (size_t i
= 0; i
< n
; ++i
)
14918 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14921 return gdb::array_view
<variant_part
> (result
, n
);
14924 /* Compute the variant part vector for FIP, attaching it to TYPE when
14928 add_variant_property (struct field_info
*fip
, struct type
*type
,
14929 struct dwarf2_cu
*cu
)
14931 /* Map section offsets of fields to their field index. Note the
14932 field index here does not take the number of baseclasses into
14934 offset_map_type offset_map
;
14935 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14936 offset_map
[fip
->fields
[i
].offset
] = i
;
14938 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14939 gdb::array_view
<variant_part
> parts
14940 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14941 fip
->variant_parts
);
14943 struct dynamic_prop prop
;
14944 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14945 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14948 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14951 /* Create the vector of fields, and attach it to the type. */
14954 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14955 struct dwarf2_cu
*cu
)
14957 int nfields
= fip
->nfields ();
14959 /* Record the field count, allocate space for the array of fields,
14960 and create blank accessibility bitfields if necessary. */
14961 type
->set_num_fields (nfields
);
14963 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14965 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
14967 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14969 TYPE_FIELD_PRIVATE_BITS (type
) =
14970 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14971 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14973 TYPE_FIELD_PROTECTED_BITS (type
) =
14974 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14975 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14977 TYPE_FIELD_IGNORE_BITS (type
) =
14978 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14979 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14982 /* If the type has baseclasses, allocate and clear a bit vector for
14983 TYPE_FIELD_VIRTUAL_BITS. */
14984 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
14986 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14987 unsigned char *pointer
;
14989 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14990 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14991 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14992 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14993 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14996 if (!fip
->variant_parts
.empty ())
14997 add_variant_property (fip
, type
, cu
);
14999 /* Copy the saved-up fields into the field vector. */
15000 for (int i
= 0; i
< nfields
; ++i
)
15002 struct nextfield
&field
15003 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15004 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15006 type
->field (i
) = field
.field
;
15007 switch (field
.accessibility
)
15009 case DW_ACCESS_private
:
15010 if (cu
->per_cu
->lang
!= language_ada
)
15011 SET_TYPE_FIELD_PRIVATE (type
, i
);
15014 case DW_ACCESS_protected
:
15015 if (cu
->per_cu
->lang
!= language_ada
)
15016 SET_TYPE_FIELD_PROTECTED (type
, i
);
15019 case DW_ACCESS_public
:
15023 /* Unknown accessibility. Complain and treat it as public. */
15025 complaint (_("unsupported accessibility %d"),
15026 field
.accessibility
);
15030 if (i
< fip
->baseclasses
.size ())
15032 switch (field
.virtuality
)
15034 case DW_VIRTUALITY_virtual
:
15035 case DW_VIRTUALITY_pure_virtual
:
15036 if (cu
->per_cu
->lang
== language_ada
)
15037 error (_("unexpected virtuality in component of Ada type"));
15038 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15045 /* Return true if this member function is a constructor, false
15049 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15051 const char *fieldname
;
15052 const char *type_name
;
15055 if (die
->parent
== NULL
)
15058 if (die
->parent
->tag
!= DW_TAG_structure_type
15059 && die
->parent
->tag
!= DW_TAG_union_type
15060 && die
->parent
->tag
!= DW_TAG_class_type
)
15063 fieldname
= dwarf2_name (die
, cu
);
15064 type_name
= dwarf2_name (die
->parent
, cu
);
15065 if (fieldname
== NULL
|| type_name
== NULL
)
15068 len
= strlen (fieldname
);
15069 return (strncmp (fieldname
, type_name
, len
) == 0
15070 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15073 /* Add a member function to the proper fieldlist. */
15076 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15077 struct type
*type
, struct dwarf2_cu
*cu
)
15079 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15080 struct attribute
*attr
;
15082 struct fnfieldlist
*flp
= nullptr;
15083 struct fn_field
*fnp
;
15084 const char *fieldname
;
15085 struct type
*this_type
;
15087 if (cu
->per_cu
->lang
== language_ada
)
15088 error (_("unexpected member function in Ada type"));
15090 /* Get name of member function. */
15091 fieldname
= dwarf2_name (die
, cu
);
15092 if (fieldname
== NULL
)
15095 /* Look up member function name in fieldlist. */
15096 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15098 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15100 flp
= &fip
->fnfieldlists
[i
];
15105 /* Create a new fnfieldlist if necessary. */
15106 if (flp
== nullptr)
15108 fip
->fnfieldlists
.emplace_back ();
15109 flp
= &fip
->fnfieldlists
.back ();
15110 flp
->name
= fieldname
;
15111 i
= fip
->fnfieldlists
.size () - 1;
15114 /* Create a new member function field and add it to the vector of
15116 flp
->fnfields
.emplace_back ();
15117 fnp
= &flp
->fnfields
.back ();
15119 /* Delay processing of the physname until later. */
15120 if (cu
->per_cu
->lang
== language_cplus
)
15121 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15125 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15126 fnp
->physname
= physname
? physname
: "";
15129 fnp
->type
= alloc_type (objfile
);
15130 this_type
= read_type_die (die
, cu
);
15131 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15133 int nparams
= this_type
->num_fields ();
15135 /* TYPE is the domain of this method, and THIS_TYPE is the type
15136 of the method itself (TYPE_CODE_METHOD). */
15137 smash_to_method_type (fnp
->type
, type
,
15138 TYPE_TARGET_TYPE (this_type
),
15139 this_type
->fields (),
15140 this_type
->num_fields (),
15141 this_type
->has_varargs ());
15143 /* Handle static member functions.
15144 Dwarf2 has no clean way to discern C++ static and non-static
15145 member functions. G++ helps GDB by marking the first
15146 parameter for non-static member functions (which is the this
15147 pointer) as artificial. We obtain this information from
15148 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15149 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15150 fnp
->voffset
= VOFFSET_STATIC
;
15153 complaint (_("member function type missing for '%s'"),
15154 dwarf2_full_name (fieldname
, die
, cu
));
15156 /* Get fcontext from DW_AT_containing_type if present. */
15157 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15158 fnp
->fcontext
= die_containing_type (die
, cu
);
15160 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15161 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15163 /* Get accessibility. */
15164 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15165 switch (accessibility
)
15167 case DW_ACCESS_private
:
15168 fnp
->is_private
= 1;
15170 case DW_ACCESS_protected
:
15171 fnp
->is_protected
= 1;
15175 /* Check for artificial methods. */
15176 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15177 if (attr
&& attr
->as_boolean ())
15178 fnp
->is_artificial
= 1;
15180 /* Check for defaulted methods. */
15181 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15182 if (attr
!= nullptr)
15183 fnp
->defaulted
= attr
->defaulted ();
15185 /* Check for deleted methods. */
15186 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15187 if (attr
!= nullptr && attr
->as_boolean ())
15188 fnp
->is_deleted
= 1;
15190 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15192 /* Get index in virtual function table if it is a virtual member
15193 function. For older versions of GCC, this is an offset in the
15194 appropriate virtual table, as specified by DW_AT_containing_type.
15195 For everyone else, it is an expression to be evaluated relative
15196 to the object address. */
15198 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15199 if (attr
!= nullptr)
15201 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15203 struct dwarf_block
*block
= attr
->as_block ();
15205 if (block
->data
[0] == DW_OP_constu
)
15207 /* Old-style GCC. */
15208 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15210 else if (block
->data
[0] == DW_OP_deref
15211 || (block
->size
> 1
15212 && block
->data
[0] == DW_OP_deref_size
15213 && block
->data
[1] == cu
->header
.addr_size
))
15215 fnp
->voffset
= decode_locdesc (block
, cu
);
15216 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15217 dwarf2_complex_location_expr_complaint ();
15219 fnp
->voffset
/= cu
->header
.addr_size
;
15223 dwarf2_complex_location_expr_complaint ();
15225 if (!fnp
->fcontext
)
15227 /* If there is no `this' field and no DW_AT_containing_type,
15228 we cannot actually find a base class context for the
15230 if (this_type
->num_fields () == 0
15231 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15233 complaint (_("cannot determine context for virtual member "
15234 "function \"%s\" (offset %s)"),
15235 fieldname
, sect_offset_str (die
->sect_off
));
15240 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15244 else if (attr
->form_is_section_offset ())
15246 dwarf2_complex_location_expr_complaint ();
15250 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15256 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15257 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15259 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15260 complaint (_("Member function \"%s\" (offset %s) is virtual "
15261 "but the vtable offset is not specified"),
15262 fieldname
, sect_offset_str (die
->sect_off
));
15263 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15264 TYPE_CPLUS_DYNAMIC (type
) = 1;
15269 /* Create the vector of member function fields, and attach it to the type. */
15272 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15273 struct dwarf2_cu
*cu
)
15275 if (cu
->per_cu
->lang
== language_ada
)
15276 error (_("unexpected member functions in Ada type"));
15278 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15279 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15281 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15283 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15285 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15286 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15288 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15289 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15290 fn_flp
->fn_fields
= (struct fn_field
*)
15291 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15293 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15294 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15297 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15300 /* Returns non-zero if NAME is the name of a vtable member in CU's
15301 language, zero otherwise. */
15303 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15305 static const char vptr
[] = "_vptr";
15307 /* Look for the C++ form of the vtable. */
15308 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15314 /* GCC outputs unnamed structures that are really pointers to member
15315 functions, with the ABI-specified layout. If TYPE describes
15316 such a structure, smash it into a member function type.
15318 GCC shouldn't do this; it should just output pointer to member DIEs.
15319 This is GCC PR debug/28767. */
15322 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15324 struct type
*pfn_type
, *self_type
, *new_type
;
15326 /* Check for a structure with no name and two children. */
15327 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15330 /* Check for __pfn and __delta members. */
15331 if (type
->field (0).name () == NULL
15332 || strcmp (type
->field (0).name (), "__pfn") != 0
15333 || type
->field (1).name () == NULL
15334 || strcmp (type
->field (1).name (), "__delta") != 0)
15337 /* Find the type of the method. */
15338 pfn_type
= type
->field (0).type ();
15339 if (pfn_type
== NULL
15340 || pfn_type
->code () != TYPE_CODE_PTR
15341 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15344 /* Look for the "this" argument. */
15345 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15346 if (pfn_type
->num_fields () == 0
15347 /* || pfn_type->field (0).type () == NULL */
15348 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15351 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15352 new_type
= alloc_type (objfile
);
15353 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15354 pfn_type
->fields (), pfn_type
->num_fields (),
15355 pfn_type
->has_varargs ());
15356 smash_to_methodptr_type (type
, new_type
);
15359 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15360 requires rewriting, then copy it and return the updated copy.
15361 Otherwise return nullptr. */
15363 static struct type
*
15364 rewrite_array_type (struct type
*type
)
15366 if (type
->code () != TYPE_CODE_ARRAY
)
15369 struct type
*index_type
= type
->index_type ();
15370 range_bounds
*current_bounds
= index_type
->bounds ();
15372 /* Handle multi-dimensional arrays. */
15373 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15374 if (new_target
== nullptr)
15376 /* Maybe we don't need to rewrite this array. */
15377 if (current_bounds
->low
.kind () == PROP_CONST
15378 && current_bounds
->high
.kind () == PROP_CONST
)
15382 /* Either the target type was rewritten, or the bounds have to be
15383 updated. Either way we want to copy the type and update
15385 struct type
*copy
= copy_type (type
);
15386 int nfields
= copy
->num_fields ();
15388 = ((struct field
*) TYPE_ZALLOC (copy
,
15389 nfields
* sizeof (struct field
)));
15390 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15391 copy
->set_fields (new_fields
);
15392 if (new_target
!= nullptr)
15393 TYPE_TARGET_TYPE (copy
) = new_target
;
15395 struct type
*index_copy
= copy_type (index_type
);
15396 range_bounds
*bounds
15397 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15398 sizeof (range_bounds
));
15399 *bounds
= *current_bounds
;
15400 bounds
->low
.set_const_val (1);
15401 bounds
->high
.set_const_val (0);
15402 index_copy
->set_bounds (bounds
);
15403 copy
->set_index_type (index_copy
);
15408 /* While some versions of GCC will generate complicated DWARF for an
15409 array (see quirk_ada_thick_pointer), more recent versions were
15410 modified to emit an explicit thick pointer structure. However, in
15411 this case, the array still has DWARF expressions for its ranges,
15412 and these must be ignored. */
15415 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15418 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15420 /* Check for a structure with two children. */
15421 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15424 /* Check for P_ARRAY and P_BOUNDS members. */
15425 if (type
->field (0).name () == NULL
15426 || strcmp (type
->field (0).name (), "P_ARRAY") != 0
15427 || type
->field (1).name () == NULL
15428 || strcmp (type
->field (1).name (), "P_BOUNDS") != 0)
15431 /* Make sure we're looking at a pointer to an array. */
15432 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15435 /* The Ada code already knows how to handle these types, so all that
15436 we need to do is turn the bounds into static bounds. However, we
15437 don't want to rewrite existing array or index types in-place,
15438 because those may be referenced in other contexts where this
15439 rewriting is undesirable. */
15440 struct type
*new_ary_type
15441 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15442 if (new_ary_type
!= nullptr)
15443 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15446 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15447 appropriate error checking and issuing complaints if there is a
15451 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15453 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15455 if (attr
== nullptr)
15458 if (!attr
->form_is_constant ())
15460 complaint (_("DW_AT_alignment must have constant form"
15461 " - DIE at %s [in module %s]"),
15462 sect_offset_str (die
->sect_off
),
15463 objfile_name (cu
->per_objfile
->objfile
));
15467 LONGEST val
= attr
->constant_value (0);
15470 complaint (_("DW_AT_alignment value must not be negative"
15471 " - DIE at %s [in module %s]"),
15472 sect_offset_str (die
->sect_off
),
15473 objfile_name (cu
->per_objfile
->objfile
));
15476 ULONGEST align
= val
;
15480 complaint (_("DW_AT_alignment value must not be zero"
15481 " - DIE at %s [in module %s]"),
15482 sect_offset_str (die
->sect_off
),
15483 objfile_name (cu
->per_objfile
->objfile
));
15486 if ((align
& (align
- 1)) != 0)
15488 complaint (_("DW_AT_alignment value must be a power of 2"
15489 " - DIE at %s [in module %s]"),
15490 sect_offset_str (die
->sect_off
),
15491 objfile_name (cu
->per_objfile
->objfile
));
15498 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15499 the alignment for TYPE. */
15502 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15505 if (!set_type_align (type
, get_alignment (cu
, die
)))
15506 complaint (_("DW_AT_alignment value too large"
15507 " - DIE at %s [in module %s]"),
15508 sect_offset_str (die
->sect_off
),
15509 objfile_name (cu
->per_objfile
->objfile
));
15512 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15513 constant for a type, according to DWARF5 spec, Table 5.5. */
15516 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15521 case DW_CC_pass_by_reference
:
15522 case DW_CC_pass_by_value
:
15526 complaint (_("unrecognized DW_AT_calling_convention value "
15527 "(%s) for a type"), pulongest (value
));
15532 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15533 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15534 also according to GNU-specific values (see include/dwarf2.h). */
15537 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15542 case DW_CC_program
:
15546 case DW_CC_GNU_renesas_sh
:
15547 case DW_CC_GNU_borland_fastcall_i386
:
15548 case DW_CC_GDB_IBM_OpenCL
:
15552 complaint (_("unrecognized DW_AT_calling_convention value "
15553 "(%s) for a subroutine"), pulongest (value
));
15558 /* Called when we find the DIE that starts a structure or union scope
15559 (definition) to create a type for the structure or union. Fill in
15560 the type's name and general properties; the members will not be
15561 processed until process_structure_scope. A symbol table entry for
15562 the type will also not be done until process_structure_scope (assuming
15563 the type has a name).
15565 NOTE: we need to call these functions regardless of whether or not the
15566 DIE has a DW_AT_name attribute, since it might be an anonymous
15567 structure or union. This gets the type entered into our set of
15568 user defined types. */
15570 static struct type
*
15571 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15573 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15575 struct attribute
*attr
;
15578 /* If the definition of this type lives in .debug_types, read that type.
15579 Don't follow DW_AT_specification though, that will take us back up
15580 the chain and we want to go down. */
15581 attr
= die
->attr (DW_AT_signature
);
15582 if (attr
!= nullptr)
15584 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15586 /* The type's CU may not be the same as CU.
15587 Ensure TYPE is recorded with CU in die_type_hash. */
15588 return set_die_type (die
, type
, cu
);
15591 type
= alloc_type (objfile
);
15592 INIT_CPLUS_SPECIFIC (type
);
15594 name
= dwarf2_name (die
, cu
);
15597 if (cu
->per_cu
->lang
== language_cplus
15598 || cu
->per_cu
->lang
== language_d
15599 || cu
->per_cu
->lang
== language_rust
)
15601 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15603 /* dwarf2_full_name might have already finished building the DIE's
15604 type. If so, there is no need to continue. */
15605 if (get_die_type (die
, cu
) != NULL
)
15606 return get_die_type (die
, cu
);
15608 type
->set_name (full_name
);
15612 /* The name is already allocated along with this objfile, so
15613 we don't need to duplicate it for the type. */
15614 type
->set_name (name
);
15618 if (die
->tag
== DW_TAG_structure_type
)
15620 type
->set_code (TYPE_CODE_STRUCT
);
15622 else if (die
->tag
== DW_TAG_union_type
)
15624 type
->set_code (TYPE_CODE_UNION
);
15628 type
->set_code (TYPE_CODE_STRUCT
);
15631 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15632 type
->set_is_declared_class (true);
15634 /* Store the calling convention in the type if it's available in
15635 the die. Otherwise the calling convention remains set to
15636 the default value DW_CC_normal. */
15637 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15638 if (attr
!= nullptr
15639 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15641 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15642 TYPE_CPLUS_CALLING_CONVENTION (type
)
15643 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15646 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15647 if (attr
!= nullptr)
15649 if (attr
->form_is_constant ())
15650 TYPE_LENGTH (type
) = attr
->constant_value (0);
15653 struct dynamic_prop prop
;
15654 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15655 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15656 TYPE_LENGTH (type
) = 0;
15661 TYPE_LENGTH (type
) = 0;
15664 maybe_set_alignment (cu
, die
, type
);
15666 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15668 /* ICC<14 does not output the required DW_AT_declaration on
15669 incomplete types, but gives them a size of zero. */
15670 type
->set_is_stub (true);
15673 type
->set_stub_is_supported (true);
15675 if (die_is_declaration (die
, cu
))
15676 type
->set_is_stub (true);
15677 else if (attr
== NULL
&& die
->child
== NULL
15678 && producer_is_realview (cu
->producer
))
15679 /* RealView does not output the required DW_AT_declaration
15680 on incomplete types. */
15681 type
->set_is_stub (true);
15683 /* We need to add the type field to the die immediately so we don't
15684 infinitely recurse when dealing with pointers to the structure
15685 type within the structure itself. */
15686 set_die_type (die
, type
, cu
);
15688 /* set_die_type should be already done. */
15689 set_descriptive_type (type
, die
, cu
);
15694 static void handle_struct_member_die
15695 (struct die_info
*child_die
,
15697 struct field_info
*fi
,
15698 std::vector
<struct symbol
*> *template_args
,
15699 struct dwarf2_cu
*cu
);
15701 /* A helper for handle_struct_member_die that handles
15702 DW_TAG_variant_part. */
15705 handle_variant_part (struct die_info
*die
, struct type
*type
,
15706 struct field_info
*fi
,
15707 std::vector
<struct symbol
*> *template_args
,
15708 struct dwarf2_cu
*cu
)
15710 variant_part_builder
*new_part
;
15711 if (fi
->current_variant_part
== nullptr)
15713 fi
->variant_parts
.emplace_back ();
15714 new_part
= &fi
->variant_parts
.back ();
15716 else if (!fi
->current_variant_part
->processing_variant
)
15718 complaint (_("nested DW_TAG_variant_part seen "
15719 "- DIE at %s [in module %s]"),
15720 sect_offset_str (die
->sect_off
),
15721 objfile_name (cu
->per_objfile
->objfile
));
15726 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15727 current
.variant_parts
.emplace_back ();
15728 new_part
= ¤t
.variant_parts
.back ();
15731 /* When we recurse, we want callees to add to this new variant
15733 scoped_restore save_current_variant_part
15734 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15736 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15739 /* It's a univariant form, an extension we support. */
15741 else if (discr
->form_is_ref ())
15743 struct dwarf2_cu
*target_cu
= cu
;
15744 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15746 new_part
->discriminant_offset
= target_die
->sect_off
;
15750 complaint (_("DW_AT_discr does not have DIE reference form"
15751 " - DIE at %s [in module %s]"),
15752 sect_offset_str (die
->sect_off
),
15753 objfile_name (cu
->per_objfile
->objfile
));
15756 for (die_info
*child_die
= die
->child
;
15758 child_die
= child_die
->sibling
)
15759 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15762 /* A helper for handle_struct_member_die that handles
15766 handle_variant (struct die_info
*die
, struct type
*type
,
15767 struct field_info
*fi
,
15768 std::vector
<struct symbol
*> *template_args
,
15769 struct dwarf2_cu
*cu
)
15771 if (fi
->current_variant_part
== nullptr)
15773 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15774 "- DIE at %s [in module %s]"),
15775 sect_offset_str (die
->sect_off
),
15776 objfile_name (cu
->per_objfile
->objfile
));
15779 if (fi
->current_variant_part
->processing_variant
)
15781 complaint (_("nested DW_TAG_variant seen "
15782 "- DIE at %s [in module %s]"),
15783 sect_offset_str (die
->sect_off
),
15784 objfile_name (cu
->per_objfile
->objfile
));
15788 scoped_restore save_processing_variant
15789 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15792 fi
->current_variant_part
->variants
.emplace_back ();
15793 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15794 variant
.first_field
= fi
->fields
.size ();
15796 /* In a variant we want to get the discriminant and also add a
15797 field for our sole member child. */
15798 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15799 if (discr
== nullptr || !discr
->form_is_constant ())
15801 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15802 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15803 variant
.default_branch
= true;
15805 variant
.discr_list_data
= discr
->as_block ();
15808 variant
.discriminant_value
= discr
->constant_value (0);
15810 for (die_info
*variant_child
= die
->child
;
15811 variant_child
!= NULL
;
15812 variant_child
= variant_child
->sibling
)
15813 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15815 variant
.last_field
= fi
->fields
.size ();
15818 /* A helper for process_structure_scope that handles a single member
15822 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15823 struct field_info
*fi
,
15824 std::vector
<struct symbol
*> *template_args
,
15825 struct dwarf2_cu
*cu
)
15827 if (child_die
->tag
== DW_TAG_member
15828 || child_die
->tag
== DW_TAG_variable
)
15830 /* NOTE: carlton/2002-11-05: A C++ static data member
15831 should be a DW_TAG_member that is a declaration, but
15832 all versions of G++ as of this writing (so through at
15833 least 3.2.1) incorrectly generate DW_TAG_variable
15834 tags for them instead. */
15835 dwarf2_add_field (fi
, child_die
, cu
);
15837 else if (child_die
->tag
== DW_TAG_subprogram
)
15839 /* Rust doesn't have member functions in the C++ sense.
15840 However, it does emit ordinary functions as children
15841 of a struct DIE. */
15842 if (cu
->per_cu
->lang
== language_rust
)
15843 read_func_scope (child_die
, cu
);
15846 /* C++ member function. */
15847 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15850 else if (child_die
->tag
== DW_TAG_inheritance
)
15852 /* C++ base class field. */
15853 dwarf2_add_field (fi
, child_die
, cu
);
15855 else if (type_can_define_types (child_die
))
15856 dwarf2_add_type_defn (fi
, child_die
, cu
);
15857 else if (child_die
->tag
== DW_TAG_template_type_param
15858 || child_die
->tag
== DW_TAG_template_value_param
)
15860 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15863 template_args
->push_back (arg
);
15865 else if (child_die
->tag
== DW_TAG_variant_part
)
15866 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15867 else if (child_die
->tag
== DW_TAG_variant
)
15868 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15871 /* Finish creating a structure or union type, including filling in
15872 its members and creating a symbol for it. */
15875 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15877 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15878 struct die_info
*child_die
;
15881 type
= get_die_type (die
, cu
);
15883 type
= read_structure_type (die
, cu
);
15885 bool has_template_parameters
= false;
15886 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15888 struct field_info fi
;
15889 std::vector
<struct symbol
*> template_args
;
15891 child_die
= die
->child
;
15893 while (child_die
&& child_die
->tag
)
15895 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15896 child_die
= child_die
->sibling
;
15899 /* Attach template arguments to type. */
15900 if (!template_args
.empty ())
15902 has_template_parameters
= true;
15903 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15904 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15905 TYPE_TEMPLATE_ARGUMENTS (type
)
15906 = XOBNEWVEC (&objfile
->objfile_obstack
,
15908 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15909 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15910 template_args
.data (),
15911 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15912 * sizeof (struct symbol
*)));
15915 /* Attach fields and member functions to the type. */
15916 if (fi
.nfields () > 0)
15917 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15918 if (!fi
.fnfieldlists
.empty ())
15920 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15922 /* Get the type which refers to the base class (possibly this
15923 class itself) which contains the vtable pointer for the current
15924 class from the DW_AT_containing_type attribute. This use of
15925 DW_AT_containing_type is a GNU extension. */
15927 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15929 struct type
*t
= die_containing_type (die
, cu
);
15931 set_type_vptr_basetype (type
, t
);
15936 /* Our own class provides vtbl ptr. */
15937 for (i
= t
->num_fields () - 1;
15938 i
>= TYPE_N_BASECLASSES (t
);
15941 const char *fieldname
= t
->field (i
).name ();
15943 if (is_vtable_name (fieldname
, cu
))
15945 set_type_vptr_fieldno (type
, i
);
15950 /* Complain if virtual function table field not found. */
15951 if (i
< TYPE_N_BASECLASSES (t
))
15952 complaint (_("virtual function table pointer "
15953 "not found when defining class '%s'"),
15954 type
->name () ? type
->name () : "");
15958 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15961 else if (cu
->producer
15962 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15964 /* The IBM XLC compiler does not provide direct indication
15965 of the containing type, but the vtable pointer is
15966 always named __vfp. */
15970 for (i
= type
->num_fields () - 1;
15971 i
>= TYPE_N_BASECLASSES (type
);
15974 if (strcmp (type
->field (i
).name (), "__vfp") == 0)
15976 set_type_vptr_fieldno (type
, i
);
15977 set_type_vptr_basetype (type
, type
);
15984 /* Copy fi.typedef_field_list linked list elements content into the
15985 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15986 if (!fi
.typedef_field_list
.empty ())
15988 int count
= fi
.typedef_field_list
.size ();
15990 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15991 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15992 = ((struct decl_field
*)
15994 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15995 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15997 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15998 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16001 /* Copy fi.nested_types_list linked list elements content into the
16002 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16003 if (!fi
.nested_types_list
.empty ()
16004 && cu
->per_cu
->lang
!= language_ada
)
16006 int count
= fi
.nested_types_list
.size ();
16008 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16009 TYPE_NESTED_TYPES_ARRAY (type
)
16010 = ((struct decl_field
*)
16011 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16012 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16014 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16015 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16019 quirk_gcc_member_function_pointer (type
, objfile
);
16020 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16021 cu
->rust_unions
.push_back (type
);
16022 else if (cu
->per_cu
->lang
== language_ada
)
16023 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16025 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16026 snapshots) has been known to create a die giving a declaration
16027 for a class that has, as a child, a die giving a definition for a
16028 nested class. So we have to process our children even if the
16029 current die is a declaration. Normally, of course, a declaration
16030 won't have any children at all. */
16032 child_die
= die
->child
;
16034 while (child_die
!= NULL
&& child_die
->tag
)
16036 if (child_die
->tag
== DW_TAG_member
16037 || child_die
->tag
== DW_TAG_variable
16038 || child_die
->tag
== DW_TAG_inheritance
16039 || child_die
->tag
== DW_TAG_template_value_param
16040 || child_die
->tag
== DW_TAG_template_type_param
)
16045 process_die (child_die
, cu
);
16047 child_die
= child_die
->sibling
;
16050 /* Do not consider external references. According to the DWARF standard,
16051 these DIEs are identified by the fact that they have no byte_size
16052 attribute, and a declaration attribute. */
16053 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16054 || !die_is_declaration (die
, cu
)
16055 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16057 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16059 if (has_template_parameters
)
16061 struct symtab
*symtab
;
16062 if (sym
!= nullptr)
16063 symtab
= symbol_symtab (sym
);
16064 else if (cu
->line_header
!= nullptr)
16066 /* Any related symtab will do. */
16068 = cu
->line_header
->file_names ()[0].symtab
;
16073 complaint (_("could not find suitable "
16074 "symtab for template parameter"
16075 " - DIE at %s [in module %s]"),
16076 sect_offset_str (die
->sect_off
),
16077 objfile_name (objfile
));
16080 if (symtab
!= nullptr)
16082 /* Make sure that the symtab is set on the new symbols.
16083 Even though they don't appear in this symtab directly,
16084 other parts of gdb assume that symbols do, and this is
16085 reasonably true. */
16086 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16087 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16093 /* Assuming DIE is an enumeration type, and TYPE is its associated
16094 type, update TYPE using some information only available in DIE's
16095 children. In particular, the fields are computed. */
16098 update_enumeration_type_from_children (struct die_info
*die
,
16100 struct dwarf2_cu
*cu
)
16102 struct die_info
*child_die
;
16103 int unsigned_enum
= 1;
16106 auto_obstack obstack
;
16107 std::vector
<struct field
> fields
;
16109 for (child_die
= die
->child
;
16110 child_die
!= NULL
&& child_die
->tag
;
16111 child_die
= child_die
->sibling
)
16113 struct attribute
*attr
;
16115 const gdb_byte
*bytes
;
16116 struct dwarf2_locexpr_baton
*baton
;
16119 if (child_die
->tag
!= DW_TAG_enumerator
)
16122 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16126 name
= dwarf2_name (child_die
, cu
);
16128 name
= "<anonymous enumerator>";
16130 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16131 &value
, &bytes
, &baton
);
16139 if (count_one_bits_ll (value
) >= 2)
16143 fields
.emplace_back ();
16144 struct field
&field
= fields
.back ();
16145 field
.set_name (dwarf2_physname (name
, child_die
, cu
));
16146 SET_FIELD_ENUMVAL (field
, value
);
16149 if (!fields
.empty ())
16151 type
->set_num_fields (fields
.size ());
16154 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16155 memcpy (type
->fields (), fields
.data (),
16156 sizeof (struct field
) * fields
.size ());
16160 type
->set_is_unsigned (true);
16163 type
->set_is_flag_enum (true);
16166 /* Given a DW_AT_enumeration_type die, set its type. We do not
16167 complete the type's fields yet, or create any symbols. */
16169 static struct type
*
16170 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16172 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16174 struct attribute
*attr
;
16177 /* If the definition of this type lives in .debug_types, read that type.
16178 Don't follow DW_AT_specification though, that will take us back up
16179 the chain and we want to go down. */
16180 attr
= die
->attr (DW_AT_signature
);
16181 if (attr
!= nullptr)
16183 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16185 /* The type's CU may not be the same as CU.
16186 Ensure TYPE is recorded with CU in die_type_hash. */
16187 return set_die_type (die
, type
, cu
);
16190 type
= alloc_type (objfile
);
16192 type
->set_code (TYPE_CODE_ENUM
);
16193 name
= dwarf2_full_name (NULL
, die
, cu
);
16195 type
->set_name (name
);
16197 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16200 struct type
*underlying_type
= die_type (die
, cu
);
16202 TYPE_TARGET_TYPE (type
) = underlying_type
;
16205 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16206 if (attr
!= nullptr)
16208 TYPE_LENGTH (type
) = attr
->constant_value (0);
16212 TYPE_LENGTH (type
) = 0;
16215 maybe_set_alignment (cu
, die
, type
);
16217 /* The enumeration DIE can be incomplete. In Ada, any type can be
16218 declared as private in the package spec, and then defined only
16219 inside the package body. Such types are known as Taft Amendment
16220 Types. When another package uses such a type, an incomplete DIE
16221 may be generated by the compiler. */
16222 if (die_is_declaration (die
, cu
))
16223 type
->set_is_stub (true);
16225 /* If this type has an underlying type that is not a stub, then we
16226 may use its attributes. We always use the "unsigned" attribute
16227 in this situation, because ordinarily we guess whether the type
16228 is unsigned -- but the guess can be wrong and the underlying type
16229 can tell us the reality. However, we defer to a local size
16230 attribute if one exists, because this lets the compiler override
16231 the underlying type if needed. */
16232 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16234 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16235 underlying_type
= check_typedef (underlying_type
);
16237 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16239 if (TYPE_LENGTH (type
) == 0)
16240 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16242 if (TYPE_RAW_ALIGN (type
) == 0
16243 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16244 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16247 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16249 set_die_type (die
, type
, cu
);
16251 /* Finish the creation of this type by using the enum's children.
16252 Note that, as usual, this must come after set_die_type to avoid
16253 infinite recursion when trying to compute the names of the
16255 update_enumeration_type_from_children (die
, type
, cu
);
16260 /* Given a pointer to a die which begins an enumeration, process all
16261 the dies that define the members of the enumeration, and create the
16262 symbol for the enumeration type.
16264 NOTE: We reverse the order of the element list. */
16267 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16269 struct type
*this_type
;
16271 this_type
= get_die_type (die
, cu
);
16272 if (this_type
== NULL
)
16273 this_type
= read_enumeration_type (die
, cu
);
16275 if (die
->child
!= NULL
)
16277 struct die_info
*child_die
;
16280 child_die
= die
->child
;
16281 while (child_die
&& child_die
->tag
)
16283 if (child_die
->tag
!= DW_TAG_enumerator
)
16285 process_die (child_die
, cu
);
16289 name
= dwarf2_name (child_die
, cu
);
16291 new_symbol (child_die
, this_type
, cu
);
16294 child_die
= child_die
->sibling
;
16298 /* If we are reading an enum from a .debug_types unit, and the enum
16299 is a declaration, and the enum is not the signatured type in the
16300 unit, then we do not want to add a symbol for it. Adding a
16301 symbol would in some cases obscure the true definition of the
16302 enum, giving users an incomplete type when the definition is
16303 actually available. Note that we do not want to do this for all
16304 enums which are just declarations, because C++0x allows forward
16305 enum declarations. */
16306 if (cu
->per_cu
->is_debug_types
16307 && die_is_declaration (die
, cu
))
16309 struct signatured_type
*sig_type
;
16311 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16312 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16313 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16317 new_symbol (die
, this_type
, cu
);
16320 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16321 expression for an index type and finds the corresponding field
16322 offset in the hidden "P_BOUNDS" structure. Returns true on success
16323 and updates *FIELD, false if it fails to recognize an
16327 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16328 int *bounds_offset
, struct field
*field
,
16329 struct dwarf2_cu
*cu
)
16331 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16332 if (attr
== nullptr || !attr
->form_is_block ())
16335 const struct dwarf_block
*block
= attr
->as_block ();
16336 const gdb_byte
*start
= block
->data
;
16337 const gdb_byte
*end
= block
->data
+ block
->size
;
16339 /* The expression to recognize generally looks like:
16341 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16342 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16344 However, the second "plus_uconst" may be missing:
16346 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16347 DW_OP_deref_size: 4)
16349 This happens when the field is at the start of the structure.
16351 Also, the final deref may not be sized:
16353 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16356 This happens when the size of the index type happens to be the
16357 same as the architecture's word size. This can occur with or
16358 without the second plus_uconst. */
16360 if (end
- start
< 2)
16362 if (*start
++ != DW_OP_push_object_address
)
16364 if (*start
++ != DW_OP_plus_uconst
)
16367 uint64_t this_bound_off
;
16368 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16369 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16371 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16372 is consistent among all bounds. */
16373 if (*bounds_offset
== -1)
16374 *bounds_offset
= this_bound_off
;
16375 else if (*bounds_offset
!= this_bound_off
)
16378 if (start
== end
|| *start
++ != DW_OP_deref
)
16384 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16386 /* This means an offset of 0. */
16388 else if (*start
++ != DW_OP_plus_uconst
)
16392 /* The size is the parameter to DW_OP_plus_uconst. */
16394 start
= gdb_read_uleb128 (start
, end
, &val
);
16395 if (start
== nullptr)
16397 if ((int) val
!= val
)
16406 if (*start
== DW_OP_deref_size
)
16408 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16409 if (start
== nullptr)
16412 else if (*start
== DW_OP_deref
)
16414 size
= cu
->header
.addr_size
;
16420 SET_FIELD_BITPOS (*field
, 8 * offset
);
16421 if (size
!= TYPE_LENGTH (field
->type ()))
16422 FIELD_BITSIZE (*field
) = 8 * size
;
16427 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16428 some kinds of Ada arrays:
16430 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16431 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16432 <11e0> DW_AT_data_location: 2 byte block: 97 6
16433 (DW_OP_push_object_address; DW_OP_deref)
16434 <11e3> DW_AT_type : <0x1173>
16435 <11e7> DW_AT_sibling : <0x1201>
16436 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16437 <11ec> DW_AT_type : <0x1206>
16438 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16439 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16440 DW_OP_deref_size: 4)
16441 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16442 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16443 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16445 This actually represents a "thick pointer", which is a structure
16446 with two elements: one that is a pointer to the array data, and one
16447 that is a pointer to another structure; this second structure holds
16450 This returns a new type on success, or nullptr if this didn't
16451 recognize the type. */
16453 static struct type
*
16454 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16457 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16458 /* So far we've only seen this with block form. */
16459 if (attr
== nullptr || !attr
->form_is_block ())
16462 /* Note that this will fail if the structure layout is changed by
16463 the compiler. However, we have no good way to recognize some
16464 other layout, because we don't know what expression the compiler
16465 might choose to emit should this happen. */
16466 struct dwarf_block
*blk
= attr
->as_block ();
16468 || blk
->data
[0] != DW_OP_push_object_address
16469 || blk
->data
[1] != DW_OP_deref
)
16472 int bounds_offset
= -1;
16473 int max_align
= -1;
16474 std::vector
<struct field
> range_fields
;
16475 for (struct die_info
*child_die
= die
->child
;
16477 child_die
= child_die
->sibling
)
16479 if (child_die
->tag
== DW_TAG_subrange_type
)
16481 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16483 int this_align
= type_align (underlying
);
16484 if (this_align
> max_align
)
16485 max_align
= this_align
;
16487 range_fields
.emplace_back ();
16488 range_fields
.emplace_back ();
16490 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16491 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16493 lower
.set_type (underlying
);
16494 FIELD_ARTIFICIAL (lower
) = 1;
16496 upper
.set_type (underlying
);
16497 FIELD_ARTIFICIAL (upper
) = 1;
16499 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16500 &bounds_offset
, &lower
, cu
)
16501 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16502 &bounds_offset
, &upper
, cu
))
16507 /* This shouldn't really happen, but double-check that we found
16508 where the bounds are stored. */
16509 if (bounds_offset
== -1)
16512 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16513 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16517 /* Set the name of each field in the bounds. */
16518 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16519 range_fields
[i
].set_name (objfile
->intern (name
));
16520 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16521 range_fields
[i
+ 1].set_name (objfile
->intern (name
));
16524 struct type
*bounds
= alloc_type (objfile
);
16525 bounds
->set_code (TYPE_CODE_STRUCT
);
16527 bounds
->set_num_fields (range_fields
.size ());
16529 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16530 * sizeof (struct field
))));
16531 memcpy (bounds
->fields (), range_fields
.data (),
16532 bounds
->num_fields () * sizeof (struct field
));
16534 int last_fieldno
= range_fields
.size () - 1;
16535 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16536 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16537 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16539 /* Rewrite the existing array type in place. Specifically, we
16540 remove any dynamic properties we might have read, and we replace
16541 the index types. */
16542 struct type
*iter
= type
;
16543 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16545 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16546 iter
->main_type
->dyn_prop_list
= nullptr;
16547 iter
->set_index_type
16548 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16549 iter
= TYPE_TARGET_TYPE (iter
);
16552 struct type
*result
= alloc_type (objfile
);
16553 result
->set_code (TYPE_CODE_STRUCT
);
16555 result
->set_num_fields (2);
16557 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16558 * sizeof (struct field
))));
16560 /* The names are chosen to coincide with what the compiler does with
16561 -fgnat-encodings=all, which the Ada code in gdb already
16563 result
->field (0).set_name ("P_ARRAY");
16564 result
->field (0).set_type (lookup_pointer_type (type
));
16566 result
->field (1).set_name ("P_BOUNDS");
16567 result
->field (1).set_type (lookup_pointer_type (bounds
));
16568 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16570 result
->set_name (type
->name ());
16571 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16572 + TYPE_LENGTH (result
->field (1).type ()));
16577 /* Extract all information from a DW_TAG_array_type DIE and put it in
16578 the DIE's type field. For now, this only handles one dimensional
16581 static struct type
*
16582 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16584 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16585 struct die_info
*child_die
;
16587 struct type
*element_type
, *range_type
, *index_type
;
16588 struct attribute
*attr
;
16590 struct dynamic_prop
*byte_stride_prop
= NULL
;
16591 unsigned int bit_stride
= 0;
16593 element_type
= die_type (die
, cu
);
16595 /* The die_type call above may have already set the type for this DIE. */
16596 type
= get_die_type (die
, cu
);
16600 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16604 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16607 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16608 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16612 complaint (_("unable to read array DW_AT_byte_stride "
16613 " - DIE at %s [in module %s]"),
16614 sect_offset_str (die
->sect_off
),
16615 objfile_name (cu
->per_objfile
->objfile
));
16616 /* Ignore this attribute. We will likely not be able to print
16617 arrays of this type correctly, but there is little we can do
16618 to help if we cannot read the attribute's value. */
16619 byte_stride_prop
= NULL
;
16623 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16625 bit_stride
= attr
->constant_value (0);
16627 /* Irix 6.2 native cc creates array types without children for
16628 arrays with unspecified length. */
16629 if (die
->child
== NULL
)
16631 index_type
= objfile_type (objfile
)->builtin_int
;
16632 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16633 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16634 byte_stride_prop
, bit_stride
);
16635 return set_die_type (die
, type
, cu
);
16638 std::vector
<struct type
*> range_types
;
16639 child_die
= die
->child
;
16640 while (child_die
&& child_die
->tag
)
16642 if (child_die
->tag
== DW_TAG_subrange_type
)
16644 struct type
*child_type
= read_type_die (child_die
, cu
);
16646 if (child_type
!= NULL
)
16648 /* The range type was succesfully read. Save it for the
16649 array type creation. */
16650 range_types
.push_back (child_type
);
16653 child_die
= child_die
->sibling
;
16656 if (range_types
.empty ())
16658 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16659 sect_offset_str (die
->sect_off
),
16660 objfile_name (cu
->per_objfile
->objfile
));
16664 /* Dwarf2 dimensions are output from left to right, create the
16665 necessary array types in backwards order. */
16667 type
= element_type
;
16669 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16673 while (i
< range_types
.size ())
16675 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16676 byte_stride_prop
, bit_stride
);
16678 byte_stride_prop
= nullptr;
16683 size_t ndim
= range_types
.size ();
16686 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16687 byte_stride_prop
, bit_stride
);
16689 byte_stride_prop
= nullptr;
16693 gdb_assert (type
!= element_type
);
16695 /* Understand Dwarf2 support for vector types (like they occur on
16696 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16697 array type. This is not part of the Dwarf2/3 standard yet, but a
16698 custom vendor extension. The main difference between a regular
16699 array and the vector variant is that vectors are passed by value
16701 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16702 if (attr
!= nullptr)
16703 make_vector_type (type
);
16705 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16706 implementation may choose to implement triple vectors using this
16708 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16709 if (attr
!= nullptr && attr
->form_is_unsigned ())
16711 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16712 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16714 complaint (_("DW_AT_byte_size for array type smaller "
16715 "than the total size of elements"));
16718 name
= dwarf2_name (die
, cu
);
16720 type
->set_name (name
);
16722 maybe_set_alignment (cu
, die
, type
);
16724 struct type
*replacement_type
= nullptr;
16725 if (cu
->per_cu
->lang
== language_ada
)
16727 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16728 if (replacement_type
!= nullptr)
16729 type
= replacement_type
;
16732 /* Install the type in the die. */
16733 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16735 /* set_die_type should be already done. */
16736 set_descriptive_type (type
, die
, cu
);
16741 static enum dwarf_array_dim_ordering
16742 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16744 struct attribute
*attr
;
16746 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16748 if (attr
!= nullptr)
16750 LONGEST val
= attr
->constant_value (-1);
16751 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16752 return (enum dwarf_array_dim_ordering
) val
;
16755 /* GNU F77 is a special case, as at 08/2004 array type info is the
16756 opposite order to the dwarf2 specification, but data is still
16757 laid out as per normal fortran.
16759 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16760 version checking. */
16762 if (cu
->per_cu
->lang
== language_fortran
16763 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16765 return DW_ORD_row_major
;
16768 switch (cu
->language_defn
->array_ordering ())
16770 case array_column_major
:
16771 return DW_ORD_col_major
;
16772 case array_row_major
:
16774 return DW_ORD_row_major
;
16778 /* Extract all information from a DW_TAG_set_type DIE and put it in
16779 the DIE's type field. */
16781 static struct type
*
16782 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16784 struct type
*domain_type
, *set_type
;
16785 struct attribute
*attr
;
16787 domain_type
= die_type (die
, cu
);
16789 /* The die_type call above may have already set the type for this DIE. */
16790 set_type
= get_die_type (die
, cu
);
16794 set_type
= create_set_type (NULL
, domain_type
);
16796 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16797 if (attr
!= nullptr && attr
->form_is_unsigned ())
16798 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16800 maybe_set_alignment (cu
, die
, set_type
);
16802 return set_die_type (die
, set_type
, cu
);
16805 /* A helper for read_common_block that creates a locexpr baton.
16806 SYM is the symbol which we are marking as computed.
16807 COMMON_DIE is the DIE for the common block.
16808 COMMON_LOC is the location expression attribute for the common
16810 MEMBER_LOC is the location expression attribute for the particular
16811 member of the common block that we are processing.
16812 CU is the CU from which the above come. */
16815 mark_common_block_symbol_computed (struct symbol
*sym
,
16816 struct die_info
*common_die
,
16817 struct attribute
*common_loc
,
16818 struct attribute
*member_loc
,
16819 struct dwarf2_cu
*cu
)
16821 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16822 struct objfile
*objfile
= per_objfile
->objfile
;
16823 struct dwarf2_locexpr_baton
*baton
;
16825 unsigned int cu_off
;
16826 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16827 LONGEST offset
= 0;
16829 gdb_assert (common_loc
&& member_loc
);
16830 gdb_assert (common_loc
->form_is_block ());
16831 gdb_assert (member_loc
->form_is_block ()
16832 || member_loc
->form_is_constant ());
16834 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16835 baton
->per_objfile
= per_objfile
;
16836 baton
->per_cu
= cu
->per_cu
;
16837 gdb_assert (baton
->per_cu
);
16839 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16841 if (member_loc
->form_is_constant ())
16843 offset
= member_loc
->constant_value (0);
16844 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16847 baton
->size
+= member_loc
->as_block ()->size
;
16849 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16852 *ptr
++ = DW_OP_call4
;
16853 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16854 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16857 if (member_loc
->form_is_constant ())
16859 *ptr
++ = DW_OP_addr
;
16860 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16861 ptr
+= cu
->header
.addr_size
;
16865 /* We have to copy the data here, because DW_OP_call4 will only
16866 use a DW_AT_location attribute. */
16867 struct dwarf_block
*block
= member_loc
->as_block ();
16868 memcpy (ptr
, block
->data
, block
->size
);
16869 ptr
+= block
->size
;
16872 *ptr
++ = DW_OP_plus
;
16873 gdb_assert (ptr
- baton
->data
== baton
->size
);
16875 SYMBOL_LOCATION_BATON (sym
) = baton
;
16876 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16879 /* Create appropriate locally-scoped variables for all the
16880 DW_TAG_common_block entries. Also create a struct common_block
16881 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16882 is used to separate the common blocks name namespace from regular
16886 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16888 struct attribute
*attr
;
16890 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16891 if (attr
!= nullptr)
16893 /* Support the .debug_loc offsets. */
16894 if (attr
->form_is_block ())
16898 else if (attr
->form_is_section_offset ())
16900 dwarf2_complex_location_expr_complaint ();
16905 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16906 "common block member");
16911 if (die
->child
!= NULL
)
16913 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16914 struct die_info
*child_die
;
16915 size_t n_entries
= 0, size
;
16916 struct common_block
*common_block
;
16917 struct symbol
*sym
;
16919 for (child_die
= die
->child
;
16920 child_die
&& child_die
->tag
;
16921 child_die
= child_die
->sibling
)
16924 size
= (sizeof (struct common_block
)
16925 + (n_entries
- 1) * sizeof (struct symbol
*));
16927 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16929 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16930 common_block
->n_entries
= 0;
16932 for (child_die
= die
->child
;
16933 child_die
&& child_die
->tag
;
16934 child_die
= child_die
->sibling
)
16936 /* Create the symbol in the DW_TAG_common_block block in the current
16938 sym
= new_symbol (child_die
, NULL
, cu
);
16941 struct attribute
*member_loc
;
16943 common_block
->contents
[common_block
->n_entries
++] = sym
;
16945 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16949 /* GDB has handled this for a long time, but it is
16950 not specified by DWARF. It seems to have been
16951 emitted by gfortran at least as recently as:
16952 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16953 complaint (_("Variable in common block has "
16954 "DW_AT_data_member_location "
16955 "- DIE at %s [in module %s]"),
16956 sect_offset_str (child_die
->sect_off
),
16957 objfile_name (objfile
));
16959 if (member_loc
->form_is_section_offset ())
16960 dwarf2_complex_location_expr_complaint ();
16961 else if (member_loc
->form_is_constant ()
16962 || member_loc
->form_is_block ())
16964 if (attr
!= nullptr)
16965 mark_common_block_symbol_computed (sym
, die
, attr
,
16969 dwarf2_complex_location_expr_complaint ();
16974 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16975 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16979 /* Create a type for a C++ namespace. */
16981 static struct type
*
16982 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16984 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16985 const char *previous_prefix
, *name
;
16989 /* For extensions, reuse the type of the original namespace. */
16990 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16992 struct die_info
*ext_die
;
16993 struct dwarf2_cu
*ext_cu
= cu
;
16995 ext_die
= dwarf2_extension (die
, &ext_cu
);
16996 type
= read_type_die (ext_die
, ext_cu
);
16998 /* EXT_CU may not be the same as CU.
16999 Ensure TYPE is recorded with CU in die_type_hash. */
17000 return set_die_type (die
, type
, cu
);
17003 name
= namespace_name (die
, &is_anonymous
, cu
);
17005 /* Now build the name of the current namespace. */
17007 previous_prefix
= determine_prefix (die
, cu
);
17008 if (previous_prefix
[0] != '\0')
17009 name
= typename_concat (&objfile
->objfile_obstack
,
17010 previous_prefix
, name
, 0, cu
);
17012 /* Create the type. */
17013 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17015 return set_die_type (die
, type
, cu
);
17018 /* Read a namespace scope. */
17021 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17023 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17026 /* Add a symbol associated to this if we haven't seen the namespace
17027 before. Also, add a using directive if it's an anonymous
17030 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17034 type
= read_type_die (die
, cu
);
17035 new_symbol (die
, type
, cu
);
17037 namespace_name (die
, &is_anonymous
, cu
);
17040 const char *previous_prefix
= determine_prefix (die
, cu
);
17042 std::vector
<const char *> excludes
;
17043 add_using_directive (using_directives (cu
),
17044 previous_prefix
, type
->name (), NULL
,
17045 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17049 if (die
->child
!= NULL
)
17051 struct die_info
*child_die
= die
->child
;
17053 while (child_die
&& child_die
->tag
)
17055 process_die (child_die
, cu
);
17056 child_die
= child_die
->sibling
;
17061 /* Read a Fortran module as type. This DIE can be only a declaration used for
17062 imported module. Still we need that type as local Fortran "use ... only"
17063 declaration imports depend on the created type in determine_prefix. */
17065 static struct type
*
17066 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17068 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17069 const char *module_name
;
17072 module_name
= dwarf2_name (die
, cu
);
17073 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17075 return set_die_type (die
, type
, cu
);
17078 /* Read a Fortran module. */
17081 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17083 struct die_info
*child_die
= die
->child
;
17086 type
= read_type_die (die
, cu
);
17087 new_symbol (die
, type
, cu
);
17089 while (child_die
&& child_die
->tag
)
17091 process_die (child_die
, cu
);
17092 child_die
= child_die
->sibling
;
17096 /* Return the name of the namespace represented by DIE. Set
17097 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17100 static const char *
17101 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17103 struct die_info
*current_die
;
17104 const char *name
= NULL
;
17106 /* Loop through the extensions until we find a name. */
17108 for (current_die
= die
;
17109 current_die
!= NULL
;
17110 current_die
= dwarf2_extension (die
, &cu
))
17112 /* We don't use dwarf2_name here so that we can detect the absence
17113 of a name -> anonymous namespace. */
17114 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17120 /* Is it an anonymous namespace? */
17122 *is_anonymous
= (name
== NULL
);
17124 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17129 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17130 the user defined type vector. */
17132 static struct type
*
17133 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17135 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17136 struct comp_unit_head
*cu_header
= &cu
->header
;
17138 struct attribute
*attr_byte_size
;
17139 struct attribute
*attr_address_class
;
17140 int byte_size
, addr_class
;
17141 struct type
*target_type
;
17143 target_type
= die_type (die
, cu
);
17145 /* The die_type call above may have already set the type for this DIE. */
17146 type
= get_die_type (die
, cu
);
17150 type
= lookup_pointer_type (target_type
);
17152 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17153 if (attr_byte_size
)
17154 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17156 byte_size
= cu_header
->addr_size
;
17158 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17159 if (attr_address_class
)
17160 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17162 addr_class
= DW_ADDR_none
;
17164 ULONGEST alignment
= get_alignment (cu
, die
);
17166 /* If the pointer size, alignment, or address class is different
17167 than the default, create a type variant marked as such and set
17168 the length accordingly. */
17169 if (TYPE_LENGTH (type
) != byte_size
17170 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17171 && alignment
!= TYPE_RAW_ALIGN (type
))
17172 || addr_class
!= DW_ADDR_none
)
17174 if (gdbarch_address_class_type_flags_p (gdbarch
))
17176 type_instance_flags type_flags
17177 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17179 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17181 type
= make_type_with_address_space (type
, type_flags
);
17183 else if (TYPE_LENGTH (type
) != byte_size
)
17185 complaint (_("invalid pointer size %d"), byte_size
);
17187 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17189 complaint (_("Invalid DW_AT_alignment"
17190 " - DIE at %s [in module %s]"),
17191 sect_offset_str (die
->sect_off
),
17192 objfile_name (cu
->per_objfile
->objfile
));
17196 /* Should we also complain about unhandled address classes? */
17200 TYPE_LENGTH (type
) = byte_size
;
17201 set_type_align (type
, alignment
);
17202 return set_die_type (die
, type
, cu
);
17205 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17206 the user defined type vector. */
17208 static struct type
*
17209 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17212 struct type
*to_type
;
17213 struct type
*domain
;
17215 to_type
= die_type (die
, cu
);
17216 domain
= die_containing_type (die
, cu
);
17218 /* The calls above may have already set the type for this DIE. */
17219 type
= get_die_type (die
, cu
);
17223 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17224 type
= lookup_methodptr_type (to_type
);
17225 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17227 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17229 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17230 to_type
->fields (), to_type
->num_fields (),
17231 to_type
->has_varargs ());
17232 type
= lookup_methodptr_type (new_type
);
17235 type
= lookup_memberptr_type (to_type
, domain
);
17237 return set_die_type (die
, type
, cu
);
17240 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17241 the user defined type vector. */
17243 static struct type
*
17244 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17245 enum type_code refcode
)
17247 struct comp_unit_head
*cu_header
= &cu
->header
;
17248 struct type
*type
, *target_type
;
17249 struct attribute
*attr
;
17251 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17253 target_type
= die_type (die
, cu
);
17255 /* The die_type call above may have already set the type for this DIE. */
17256 type
= get_die_type (die
, cu
);
17260 type
= lookup_reference_type (target_type
, refcode
);
17261 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17262 if (attr
!= nullptr)
17264 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17268 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17270 maybe_set_alignment (cu
, die
, type
);
17271 return set_die_type (die
, type
, cu
);
17274 /* Add the given cv-qualifiers to the element type of the array. GCC
17275 outputs DWARF type qualifiers that apply to an array, not the
17276 element type. But GDB relies on the array element type to carry
17277 the cv-qualifiers. This mimics section 6.7.3 of the C99
17280 static struct type
*
17281 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17282 struct type
*base_type
, int cnst
, int voltl
)
17284 struct type
*el_type
, *inner_array
;
17286 base_type
= copy_type (base_type
);
17287 inner_array
= base_type
;
17289 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17291 TYPE_TARGET_TYPE (inner_array
) =
17292 copy_type (TYPE_TARGET_TYPE (inner_array
));
17293 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17296 el_type
= TYPE_TARGET_TYPE (inner_array
);
17297 cnst
|= TYPE_CONST (el_type
);
17298 voltl
|= TYPE_VOLATILE (el_type
);
17299 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17301 return set_die_type (die
, base_type
, cu
);
17304 static struct type
*
17305 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17307 struct type
*base_type
, *cv_type
;
17309 base_type
= die_type (die
, cu
);
17311 /* The die_type call above may have already set the type for this DIE. */
17312 cv_type
= get_die_type (die
, cu
);
17316 /* In case the const qualifier is applied to an array type, the element type
17317 is so qualified, not the array type (section 6.7.3 of C99). */
17318 if (base_type
->code () == TYPE_CODE_ARRAY
)
17319 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17321 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17322 return set_die_type (die
, cv_type
, cu
);
17325 static struct type
*
17326 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17328 struct type
*base_type
, *cv_type
;
17330 base_type
= die_type (die
, cu
);
17332 /* The die_type call above may have already set the type for this DIE. */
17333 cv_type
= get_die_type (die
, cu
);
17337 /* In case the volatile qualifier is applied to an array type, the
17338 element type is so qualified, not the array type (section 6.7.3
17340 if (base_type
->code () == TYPE_CODE_ARRAY
)
17341 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17343 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17344 return set_die_type (die
, cv_type
, cu
);
17347 /* Handle DW_TAG_restrict_type. */
17349 static struct type
*
17350 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17352 struct type
*base_type
, *cv_type
;
17354 base_type
= die_type (die
, cu
);
17356 /* The die_type call above may have already set the type for this DIE. */
17357 cv_type
= get_die_type (die
, cu
);
17361 cv_type
= make_restrict_type (base_type
);
17362 return set_die_type (die
, cv_type
, cu
);
17365 /* Handle DW_TAG_atomic_type. */
17367 static struct type
*
17368 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17370 struct type
*base_type
, *cv_type
;
17372 base_type
= die_type (die
, cu
);
17374 /* The die_type call above may have already set the type for this DIE. */
17375 cv_type
= get_die_type (die
, cu
);
17379 cv_type
= make_atomic_type (base_type
);
17380 return set_die_type (die
, cv_type
, cu
);
17383 /* Extract all information from a DW_TAG_string_type DIE and add to
17384 the user defined type vector. It isn't really a user defined type,
17385 but it behaves like one, with other DIE's using an AT_user_def_type
17386 attribute to reference it. */
17388 static struct type
*
17389 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17391 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17392 struct gdbarch
*gdbarch
= objfile
->arch ();
17393 struct type
*type
, *range_type
, *index_type
, *char_type
;
17394 struct attribute
*attr
;
17395 struct dynamic_prop prop
;
17396 bool length_is_constant
= true;
17399 /* There are a couple of places where bit sizes might be made use of
17400 when parsing a DW_TAG_string_type, however, no producer that we know
17401 of make use of these. Handling bit sizes that are a multiple of the
17402 byte size is easy enough, but what about other bit sizes? Lets deal
17403 with that problem when we have to. Warn about these attributes being
17404 unsupported, then parse the type and ignore them like we always
17406 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17407 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17409 static bool warning_printed
= false;
17410 if (!warning_printed
)
17412 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17413 "currently supported on DW_TAG_string_type."));
17414 warning_printed
= true;
17418 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17419 if (attr
!= nullptr && !attr
->form_is_constant ())
17421 /* The string length describes the location at which the length of
17422 the string can be found. The size of the length field can be
17423 specified with one of the attributes below. */
17424 struct type
*prop_type
;
17425 struct attribute
*len
17426 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17427 if (len
== nullptr)
17428 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17429 if (len
!= nullptr && len
->form_is_constant ())
17431 /* Pass 0 as the default as we know this attribute is constant
17432 and the default value will not be returned. */
17433 LONGEST sz
= len
->constant_value (0);
17434 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17438 /* If the size is not specified then we assume it is the size of
17439 an address on this target. */
17440 prop_type
= cu
->addr_sized_int_type (true);
17443 /* Convert the attribute into a dynamic property. */
17444 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17447 length_is_constant
= false;
17449 else if (attr
!= nullptr)
17451 /* This DW_AT_string_length just contains the length with no
17452 indirection. There's no need to create a dynamic property in this
17453 case. Pass 0 for the default value as we know it will not be
17454 returned in this case. */
17455 length
= attr
->constant_value (0);
17457 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17459 /* We don't currently support non-constant byte sizes for strings. */
17460 length
= attr
->constant_value (1);
17464 /* Use 1 as a fallback length if we have nothing else. */
17468 index_type
= objfile_type (objfile
)->builtin_int
;
17469 if (length_is_constant
)
17470 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17473 struct dynamic_prop low_bound
;
17475 low_bound
.set_const_val (1);
17476 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17478 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17479 type
= create_string_type (NULL
, char_type
, range_type
);
17481 return set_die_type (die
, type
, cu
);
17484 /* Assuming that DIE corresponds to a function, returns nonzero
17485 if the function is prototyped. */
17488 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17490 struct attribute
*attr
;
17492 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17493 if (attr
&& attr
->as_boolean ())
17496 /* The DWARF standard implies that the DW_AT_prototyped attribute
17497 is only meaningful for C, but the concept also extends to other
17498 languages that allow unprototyped functions (Eg: Objective C).
17499 For all other languages, assume that functions are always
17501 if (cu
->per_cu
->lang
!= language_c
17502 && cu
->per_cu
->lang
!= language_objc
17503 && cu
->per_cu
->lang
!= language_opencl
)
17506 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17507 prototyped and unprototyped functions; default to prototyped,
17508 since that is more common in modern code (and RealView warns
17509 about unprototyped functions). */
17510 if (producer_is_realview (cu
->producer
))
17516 /* Handle DIES due to C code like:
17520 int (*funcp)(int a, long l);
17524 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17526 static struct type
*
17527 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17529 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17530 struct type
*type
; /* Type that this function returns. */
17531 struct type
*ftype
; /* Function that returns above type. */
17532 struct attribute
*attr
;
17534 type
= die_type (die
, cu
);
17536 /* The die_type call above may have already set the type for this DIE. */
17537 ftype
= get_die_type (die
, cu
);
17541 ftype
= lookup_function_type (type
);
17543 if (prototyped_function_p (die
, cu
))
17544 ftype
->set_is_prototyped (true);
17546 /* Store the calling convention in the type if it's available in
17547 the subroutine die. Otherwise set the calling convention to
17548 the default value DW_CC_normal. */
17549 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17550 if (attr
!= nullptr
17551 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17552 TYPE_CALLING_CONVENTION (ftype
)
17553 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17554 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17555 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17557 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17559 /* Record whether the function returns normally to its caller or not
17560 if the DWARF producer set that information. */
17561 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17562 if (attr
&& attr
->as_boolean ())
17563 TYPE_NO_RETURN (ftype
) = 1;
17565 /* We need to add the subroutine type to the die immediately so
17566 we don't infinitely recurse when dealing with parameters
17567 declared as the same subroutine type. */
17568 set_die_type (die
, ftype
, cu
);
17570 if (die
->child
!= NULL
)
17572 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17573 struct die_info
*child_die
;
17574 int nparams
, iparams
;
17576 /* Count the number of parameters.
17577 FIXME: GDB currently ignores vararg functions, but knows about
17578 vararg member functions. */
17580 child_die
= die
->child
;
17581 while (child_die
&& child_die
->tag
)
17583 if (child_die
->tag
== DW_TAG_formal_parameter
)
17585 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17586 ftype
->set_has_varargs (true);
17588 child_die
= child_die
->sibling
;
17591 /* Allocate storage for parameters and fill them in. */
17592 ftype
->set_num_fields (nparams
);
17594 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17596 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17597 even if we error out during the parameters reading below. */
17598 for (iparams
= 0; iparams
< nparams
; iparams
++)
17599 ftype
->field (iparams
).set_type (void_type
);
17602 child_die
= die
->child
;
17603 while (child_die
&& child_die
->tag
)
17605 if (child_die
->tag
== DW_TAG_formal_parameter
)
17607 struct type
*arg_type
;
17609 /* DWARF version 2 has no clean way to discern C++
17610 static and non-static member functions. G++ helps
17611 GDB by marking the first parameter for non-static
17612 member functions (which is the this pointer) as
17613 artificial. We pass this information to
17614 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17616 DWARF version 3 added DW_AT_object_pointer, which GCC
17617 4.5 does not yet generate. */
17618 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17619 if (attr
!= nullptr)
17620 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17622 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17623 arg_type
= die_type (child_die
, cu
);
17625 /* RealView does not mark THIS as const, which the testsuite
17626 expects. GCC marks THIS as const in method definitions,
17627 but not in the class specifications (GCC PR 43053). */
17628 if (cu
->per_cu
->lang
== language_cplus
17629 && !TYPE_CONST (arg_type
)
17630 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17633 struct dwarf2_cu
*arg_cu
= cu
;
17634 const char *name
= dwarf2_name (child_die
, cu
);
17636 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17637 if (attr
!= nullptr)
17639 /* If the compiler emits this, use it. */
17640 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17643 else if (name
&& strcmp (name
, "this") == 0)
17644 /* Function definitions will have the argument names. */
17646 else if (name
== NULL
&& iparams
== 0)
17647 /* Declarations may not have the names, so like
17648 elsewhere in GDB, assume an artificial first
17649 argument is "this". */
17653 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17657 ftype
->field (iparams
).set_type (arg_type
);
17660 child_die
= child_die
->sibling
;
17667 static struct type
*
17668 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17670 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17671 const char *name
= NULL
;
17672 struct type
*this_type
, *target_type
;
17674 name
= dwarf2_full_name (NULL
, die
, cu
);
17675 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17676 this_type
->set_target_is_stub (true);
17677 set_die_type (die
, this_type
, cu
);
17678 target_type
= die_type (die
, cu
);
17679 if (target_type
!= this_type
)
17680 TYPE_TARGET_TYPE (this_type
) = target_type
;
17683 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17684 spec and cause infinite loops in GDB. */
17685 complaint (_("Self-referential DW_TAG_typedef "
17686 "- DIE at %s [in module %s]"),
17687 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17688 TYPE_TARGET_TYPE (this_type
) = NULL
;
17692 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17693 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17694 Handle these by just returning the target type, rather than
17695 constructing an anonymous typedef type and trying to handle this
17697 set_die_type (die
, target_type
, cu
);
17698 return target_type
;
17703 /* Helper for get_dwarf2_rational_constant that computes the value of
17704 a given gmp_mpz given an attribute. */
17707 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17709 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17710 location expression that pushes an implicit value. */
17711 if (attr
->form
== DW_FORM_exprloc
)
17713 dwarf_block
*blk
= attr
->as_block ();
17714 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17717 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17718 blk
->data
+ blk
->size
,
17720 if (ptr
- blk
->data
+ len
<= blk
->size
)
17722 mpz_import (value
->val
, len
,
17723 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17729 /* On failure set it to 1. */
17730 *value
= gdb_mpz (1);
17732 else if (attr
->form_is_block ())
17734 dwarf_block
*blk
= attr
->as_block ();
17735 mpz_import (value
->val
, blk
->size
,
17736 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17737 1, 0, 0, blk
->data
);
17740 *value
= gdb_mpz (attr
->constant_value (1));
17743 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17744 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17746 If the numerator and/or numerator attribute is missing,
17747 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17751 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17752 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17754 struct attribute
*num_attr
, *denom_attr
;
17756 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17757 if (num_attr
== nullptr)
17758 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17759 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17761 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17762 if (denom_attr
== nullptr)
17763 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17764 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17766 if (num_attr
== nullptr || denom_attr
== nullptr)
17769 get_mpz (cu
, numerator
, num_attr
);
17770 get_mpz (cu
, denominator
, denom_attr
);
17773 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17774 rational constant, rather than a signed one.
17776 If the rational constant has a negative value, a complaint
17777 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17780 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17781 struct dwarf2_cu
*cu
,
17782 gdb_mpz
*numerator
,
17783 gdb_mpz
*denominator
)
17788 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17789 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17791 mpz_neg (num
.val
, num
.val
);
17792 mpz_neg (denom
.val
, denom
.val
);
17794 else if (mpz_sgn (num
.val
) == -1)
17796 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17798 sect_offset_str (die
->sect_off
));
17801 else if (mpz_sgn (denom
.val
) == -1)
17803 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17805 sect_offset_str (die
->sect_off
));
17809 *numerator
= std::move (num
);
17810 *denominator
= std::move (denom
);
17813 /* Assuming that ENCODING is a string whose contents starting at the
17814 K'th character is "_nn" where "nn" is a decimal number, scan that
17815 number and set RESULT to the value. K is updated to point to the
17816 character immediately following the number.
17818 If the string does not conform to the format described above, false
17819 is returned, and K may or may not be changed. */
17822 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17824 /* The next character should be an underscore ('_') followed
17826 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17829 /* Skip the underscore. */
17833 /* Determine the number of digits for our number. */
17834 while (isdigit (encoding
[k
]))
17839 std::string
copy (&encoding
[start
], k
- start
);
17840 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17846 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17847 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17848 DENOM, update OFFSET, and return true on success. Return false on
17852 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17853 gdb_mpz
*num
, gdb_mpz
*denom
)
17855 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17857 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17860 /* Assuming DIE corresponds to a fixed point type, finish the creation
17861 of the corresponding TYPE by setting its type-specific data. CU is
17862 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17863 encodings. It is nullptr if the GNAT encoding should be
17867 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17868 struct die_info
*die
, struct dwarf2_cu
*cu
)
17870 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17871 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17873 /* If GNAT encodings are preferred, don't examine the
17875 struct attribute
*attr
= nullptr;
17876 if (suffix
== nullptr)
17878 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17879 if (attr
== nullptr)
17880 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17881 if (attr
== nullptr)
17882 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17885 /* Numerator and denominator of our fixed-point type's scaling factor.
17886 The default is a scaling factor of 1, which we use as a fallback
17887 when we are not able to decode it (problem with the debugging info,
17888 unsupported forms, bug in GDB, etc...). Using that as the default
17889 allows us to at least print the unscaled value, which might still
17890 be useful to a user. */
17891 gdb_mpz
scale_num (1);
17892 gdb_mpz
scale_denom (1);
17894 if (attr
== nullptr)
17897 if (suffix
!= nullptr
17898 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17900 /* The number might be encoded as _nn_dd_nn_dd, where the
17901 second ratio is the 'small value. In this situation, we
17902 want the second value. */
17903 && (suffix
[offset
] != '_'
17904 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17911 /* Scaling factor not found. Assume a scaling factor of 1,
17912 and hope for the best. At least the user will be able to
17913 see the encoded value. */
17916 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17917 sect_offset_str (die
->sect_off
));
17920 else if (attr
->name
== DW_AT_binary_scale
)
17922 LONGEST scale_exp
= attr
->constant_value (0);
17923 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17925 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17927 else if (attr
->name
== DW_AT_decimal_scale
)
17929 LONGEST scale_exp
= attr
->constant_value (0);
17930 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17932 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17934 else if (attr
->name
== DW_AT_small
)
17936 struct die_info
*scale_die
;
17937 struct dwarf2_cu
*scale_cu
= cu
;
17939 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17940 if (scale_die
->tag
== DW_TAG_constant
)
17941 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17942 &scale_num
, &scale_denom
);
17944 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17946 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17950 complaint (_("unsupported scale attribute %s for fixed-point type"
17952 dwarf_attr_name (attr
->name
),
17953 sect_offset_str (die
->sect_off
));
17956 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17957 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17958 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17959 mpq_canonicalize (scaling_factor
.val
);
17962 /* The gnat-encoding suffix for fixed point. */
17964 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17966 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17967 "XF" suffix of the name. The text after this is what encodes the
17968 'small and 'delta information. Otherwise, return nullptr. */
17970 static const char *
17971 gnat_encoded_fixed_point_type_info (const char *name
)
17973 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17976 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17977 (which may be different from NAME) to the architecture back-end to allow
17978 it to guess the correct format if necessary. */
17980 static struct type
*
17981 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17982 const char *name_hint
, enum bfd_endian byte_order
)
17984 struct gdbarch
*gdbarch
= objfile
->arch ();
17985 const struct floatformat
**format
;
17988 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17990 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17992 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17997 /* Allocate an integer type of size BITS and name NAME. */
17999 static struct type
*
18000 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18001 int bits
, int unsigned_p
, const char *name
)
18005 /* Versions of Intel's C Compiler generate an integer type called "void"
18006 instead of using DW_TAG_unspecified_type. This has been seen on
18007 at least versions 14, 17, and 18. */
18008 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18009 && strcmp (name
, "void") == 0)
18010 type
= objfile_type (objfile
)->builtin_void
;
18012 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18017 /* Return true if DIE has a DW_AT_small attribute whose value is
18018 a constant rational, where both the numerator and denominator
18021 CU is the DIE's Compilation Unit. */
18024 has_zero_over_zero_small_attribute (struct die_info
*die
,
18025 struct dwarf2_cu
*cu
)
18027 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18028 if (attr
== nullptr)
18031 struct dwarf2_cu
*scale_cu
= cu
;
18032 struct die_info
*scale_die
18033 = follow_die_ref (die
, attr
, &scale_cu
);
18035 if (scale_die
->tag
!= DW_TAG_constant
)
18038 gdb_mpz
num (1), denom (1);
18039 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18040 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18043 /* Initialise and return a floating point type of size BITS suitable for
18044 use as a component of a complex number. The NAME_HINT is passed through
18045 when initialising the floating point type and is the name of the complex
18048 As DWARF doesn't currently provide an explicit name for the components
18049 of a complex number, but it can be helpful to have these components
18050 named, we try to select a suitable name based on the size of the
18052 static struct type
*
18053 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18054 struct objfile
*objfile
,
18055 int bits
, const char *name_hint
,
18056 enum bfd_endian byte_order
)
18058 gdbarch
*gdbarch
= objfile
->arch ();
18059 struct type
*tt
= nullptr;
18061 /* Try to find a suitable floating point builtin type of size BITS.
18062 We're going to use the name of this type as the name for the complex
18063 target type that we are about to create. */
18064 switch (cu
->per_cu
->lang
)
18066 case language_fortran
:
18070 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18073 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18075 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18077 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18085 tt
= builtin_type (gdbarch
)->builtin_float
;
18088 tt
= builtin_type (gdbarch
)->builtin_double
;
18090 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18092 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18098 /* If the type we found doesn't match the size we were looking for, then
18099 pretend we didn't find a type at all, the complex target type we
18100 create will then be nameless. */
18101 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18104 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18105 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18108 /* Find a representation of a given base type and install
18109 it in the TYPE field of the die. */
18111 static struct type
*
18112 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18114 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18116 struct attribute
*attr
;
18117 int encoding
= 0, bits
= 0;
18121 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18122 if (attr
!= nullptr && attr
->form_is_constant ())
18123 encoding
= attr
->constant_value (0);
18124 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18125 if (attr
!= nullptr)
18126 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18127 name
= dwarf2_name (die
, cu
);
18129 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18131 arch
= objfile
->arch ();
18132 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18134 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18135 if (attr
!= nullptr && attr
->form_is_constant ())
18137 int endianity
= attr
->constant_value (0);
18142 byte_order
= BFD_ENDIAN_BIG
;
18144 case DW_END_little
:
18145 byte_order
= BFD_ENDIAN_LITTLE
;
18148 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18153 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18154 && cu
->per_cu
->lang
== language_ada
18155 && has_zero_over_zero_small_attribute (die
, cu
))
18157 /* brobecker/2018-02-24: This is a fixed point type for which
18158 the scaling factor is represented as fraction whose value
18159 does not make sense (zero divided by zero), so we should
18160 normally never see these. However, there is a small category
18161 of fixed point types for which GNAT is unable to provide
18162 the scaling factor via the standard DWARF mechanisms, and
18163 for which the info is provided via the GNAT encodings instead.
18164 This is likely what this DIE is about. */
18165 encoding
= (encoding
== DW_ATE_signed_fixed
18167 : DW_ATE_unsigned
);
18170 /* With GNAT encodings, fixed-point information will be encoded in
18171 the type name. Note that this can also occur with the above
18172 zero-over-zero case, which is why this is a separate "if" rather
18173 than an "else if". */
18174 const char *gnat_encoding_suffix
= nullptr;
18175 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18176 && cu
->per_cu
->lang
== language_ada
18177 && name
!= nullptr)
18179 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18180 if (gnat_encoding_suffix
!= nullptr)
18182 gdb_assert (startswith (gnat_encoding_suffix
,
18183 GNAT_FIXED_POINT_SUFFIX
));
18184 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18185 name
, gnat_encoding_suffix
- name
);
18186 /* Use -1 here so that SUFFIX points at the "_" after the
18188 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18190 encoding
= (encoding
== DW_ATE_signed
18191 ? DW_ATE_signed_fixed
18192 : DW_ATE_unsigned_fixed
);
18198 case DW_ATE_address
:
18199 /* Turn DW_ATE_address into a void * pointer. */
18200 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18201 type
= init_pointer_type (objfile
, bits
, name
, type
);
18203 case DW_ATE_boolean
:
18204 type
= init_boolean_type (objfile
, bits
, 1, name
);
18206 case DW_ATE_complex_float
:
18207 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18209 if (type
->code () == TYPE_CODE_ERROR
)
18211 if (name
== nullptr)
18213 struct obstack
*obstack
18214 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18215 name
= obconcat (obstack
, "_Complex ", type
->name (),
18218 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18221 type
= init_complex_type (name
, type
);
18223 case DW_ATE_decimal_float
:
18224 type
= init_decfloat_type (objfile
, bits
, name
);
18227 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18229 case DW_ATE_signed
:
18230 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18232 case DW_ATE_unsigned
:
18233 if (cu
->per_cu
->lang
== language_fortran
18235 && startswith (name
, "character("))
18236 type
= init_character_type (objfile
, bits
, 1, name
);
18238 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18240 case DW_ATE_signed_char
:
18241 if (cu
->per_cu
->lang
== language_ada
18242 || cu
->per_cu
->lang
== language_m2
18243 || cu
->per_cu
->lang
== language_pascal
18244 || cu
->per_cu
->lang
== language_fortran
)
18245 type
= init_character_type (objfile
, bits
, 0, name
);
18247 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18249 case DW_ATE_unsigned_char
:
18250 if (cu
->per_cu
->lang
== language_ada
18251 || cu
->per_cu
->lang
== language_m2
18252 || cu
->per_cu
->lang
== language_pascal
18253 || cu
->per_cu
->lang
== language_fortran
18254 || cu
->per_cu
->lang
== language_rust
)
18255 type
= init_character_type (objfile
, bits
, 1, name
);
18257 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18262 type
= builtin_type (arch
)->builtin_char16
;
18263 else if (bits
== 32)
18264 type
= builtin_type (arch
)->builtin_char32
;
18267 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18269 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18271 return set_die_type (die
, type
, cu
);
18274 case DW_ATE_signed_fixed
:
18275 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18276 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18278 case DW_ATE_unsigned_fixed
:
18279 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18280 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18284 complaint (_("unsupported DW_AT_encoding: '%s'"),
18285 dwarf_type_encoding_name (encoding
));
18286 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18290 if (name
&& strcmp (name
, "char") == 0)
18291 type
->set_has_no_signedness (true);
18293 maybe_set_alignment (cu
, die
, type
);
18295 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18297 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18299 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18300 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18302 unsigned real_bit_size
= attr
->as_unsigned ();
18303 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18304 /* Only use the attributes if they make sense together. */
18305 if (attr
== nullptr
18306 || (attr
->as_unsigned () + real_bit_size
18307 <= 8 * TYPE_LENGTH (type
)))
18309 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18311 if (attr
!= nullptr)
18312 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18313 = attr
->as_unsigned ();
18318 return set_die_type (die
, type
, cu
);
18321 /* A helper function that returns the name of DIE, if it refers to a
18322 variable declaration. */
18324 static const char *
18325 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18327 if (die
->tag
!= DW_TAG_variable
)
18330 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18331 if (attr
== nullptr || !attr
->as_boolean ())
18334 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18335 if (attr
== nullptr)
18337 return attr
->as_string ();
18340 /* Parse dwarf attribute if it's a block, reference or constant and put the
18341 resulting value of the attribute into struct bound_prop.
18342 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18345 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18346 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18347 struct type
*default_type
)
18349 struct dwarf2_property_baton
*baton
;
18350 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18351 struct objfile
*objfile
= per_objfile
->objfile
;
18352 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18354 gdb_assert (default_type
!= NULL
);
18356 if (attr
== NULL
|| prop
== NULL
)
18359 if (attr
->form_is_block ())
18361 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18362 baton
->property_type
= default_type
;
18363 baton
->locexpr
.per_cu
= cu
->per_cu
;
18364 baton
->locexpr
.per_objfile
= per_objfile
;
18366 struct dwarf_block
*block
;
18367 if (attr
->form
== DW_FORM_data16
)
18369 size_t data_size
= 16;
18370 block
= XOBNEW (obstack
, struct dwarf_block
);
18371 block
->size
= (data_size
18372 + 2 /* Extra bytes for DW_OP and arg. */);
18373 gdb_byte
*data
= XOBNEWVEC (obstack
, gdb_byte
, block
->size
);
18374 data
[0] = DW_OP_implicit_value
;
18375 data
[1] = data_size
;
18376 memcpy (&data
[2], attr
->as_block ()->data
, data_size
);
18377 block
->data
= data
;
18380 block
= attr
->as_block ();
18382 baton
->locexpr
.size
= block
->size
;
18383 baton
->locexpr
.data
= block
->data
;
18384 switch (attr
->name
)
18386 case DW_AT_string_length
:
18387 baton
->locexpr
.is_reference
= true;
18390 baton
->locexpr
.is_reference
= false;
18394 prop
->set_locexpr (baton
);
18395 gdb_assert (prop
->baton () != NULL
);
18397 else if (attr
->form_is_ref ())
18399 struct dwarf2_cu
*target_cu
= cu
;
18400 struct die_info
*target_die
;
18401 struct attribute
*target_attr
;
18403 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18404 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18405 if (target_attr
== NULL
)
18406 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18408 if (target_attr
== nullptr)
18409 target_attr
= dwarf2_attr (target_die
, DW_AT_data_bit_offset
,
18411 if (target_attr
== NULL
)
18413 const char *name
= var_decl_name (target_die
, target_cu
);
18414 if (name
!= nullptr)
18416 prop
->set_variable_name (name
);
18422 switch (target_attr
->name
)
18424 case DW_AT_location
:
18425 if (target_attr
->form_is_section_offset ())
18427 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18428 baton
->property_type
= die_type (target_die
, target_cu
);
18429 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18430 prop
->set_loclist (baton
);
18431 gdb_assert (prop
->baton () != NULL
);
18433 else if (target_attr
->form_is_block ())
18435 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18436 baton
->property_type
= die_type (target_die
, target_cu
);
18437 baton
->locexpr
.per_cu
= cu
->per_cu
;
18438 baton
->locexpr
.per_objfile
= per_objfile
;
18439 struct dwarf_block
*block
= target_attr
->as_block ();
18440 baton
->locexpr
.size
= block
->size
;
18441 baton
->locexpr
.data
= block
->data
;
18442 baton
->locexpr
.is_reference
= true;
18443 prop
->set_locexpr (baton
);
18444 gdb_assert (prop
->baton () != NULL
);
18448 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18449 "dynamic property");
18453 case DW_AT_data_member_location
:
18454 case DW_AT_data_bit_offset
:
18458 if (!handle_member_location (target_die
, target_cu
, &offset
))
18461 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18462 baton
->property_type
= read_type_die (target_die
->parent
,
18464 baton
->offset_info
.offset
= offset
;
18465 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18466 prop
->set_addr_offset (baton
);
18471 else if (attr
->form_is_constant ())
18472 prop
->set_const_val (attr
->constant_value (0));
18475 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18476 dwarf2_name (die
, cu
));
18486 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18488 struct type
*int_type
;
18490 /* Helper macro to examine the various builtin types. */
18491 #define TRY_TYPE(F) \
18492 int_type = (unsigned_p \
18493 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18494 : objfile_type (objfile)->builtin_ ## F); \
18495 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18502 TRY_TYPE (long_long
);
18506 gdb_assert_not_reached ("unable to find suitable integer type");
18509 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18510 present (which is valid) then compute the default type based on the
18511 compilation units address size. */
18513 static struct type
*
18514 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18516 struct type
*index_type
= die_type (die
, cu
);
18518 /* Dwarf-2 specifications explicitly allows to create subrange types
18519 without specifying a base type.
18520 In that case, the base type must be set to the type of
18521 the lower bound, upper bound or count, in that order, if any of these
18522 three attributes references an object that has a type.
18523 If no base type is found, the Dwarf-2 specifications say that
18524 a signed integer type of size equal to the size of an address should
18526 For the following C code: `extern char gdb_int [];'
18527 GCC produces an empty range DIE.
18528 FIXME: muller/2010-05-28: Possible references to object for low bound,
18529 high bound or count are not yet handled by this code. */
18530 if (index_type
->code () == TYPE_CODE_VOID
)
18531 index_type
= cu
->addr_sized_int_type (false);
18536 /* Read the given DW_AT_subrange DIE. */
18538 static struct type
*
18539 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18541 struct type
*base_type
, *orig_base_type
;
18542 struct type
*range_type
;
18543 struct attribute
*attr
;
18544 struct dynamic_prop low
, high
;
18545 int low_default_is_valid
;
18546 int high_bound_is_count
= 0;
18548 ULONGEST negative_mask
;
18550 orig_base_type
= read_subrange_index_type (die
, cu
);
18552 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18553 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18554 creating the range type, but we use the result of check_typedef
18555 when examining properties of the type. */
18556 base_type
= check_typedef (orig_base_type
);
18558 /* The die_type call above may have already set the type for this DIE. */
18559 range_type
= get_die_type (die
, cu
);
18563 high
.set_const_val (0);
18565 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18566 omitting DW_AT_lower_bound. */
18567 switch (cu
->per_cu
->lang
)
18570 case language_cplus
:
18571 low
.set_const_val (0);
18572 low_default_is_valid
= 1;
18574 case language_fortran
:
18575 low
.set_const_val (1);
18576 low_default_is_valid
= 1;
18579 case language_objc
:
18580 case language_rust
:
18581 low
.set_const_val (0);
18582 low_default_is_valid
= (cu
->header
.version
>= 4);
18586 case language_pascal
:
18587 low
.set_const_val (1);
18588 low_default_is_valid
= (cu
->header
.version
>= 4);
18591 low
.set_const_val (0);
18592 low_default_is_valid
= 0;
18596 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18597 if (attr
!= nullptr)
18598 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18599 else if (!low_default_is_valid
)
18600 complaint (_("Missing DW_AT_lower_bound "
18601 "- DIE at %s [in module %s]"),
18602 sect_offset_str (die
->sect_off
),
18603 objfile_name (cu
->per_objfile
->objfile
));
18605 struct attribute
*attr_ub
, *attr_count
;
18606 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18607 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18609 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18610 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18612 /* If bounds are constant do the final calculation here. */
18613 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18614 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18616 high_bound_is_count
= 1;
18620 if (attr_ub
!= NULL
)
18621 complaint (_("Unresolved DW_AT_upper_bound "
18622 "- DIE at %s [in module %s]"),
18623 sect_offset_str (die
->sect_off
),
18624 objfile_name (cu
->per_objfile
->objfile
));
18625 if (attr_count
!= NULL
)
18626 complaint (_("Unresolved DW_AT_count "
18627 "- DIE at %s [in module %s]"),
18628 sect_offset_str (die
->sect_off
),
18629 objfile_name (cu
->per_objfile
->objfile
));
18634 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18635 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18636 bias
= bias_attr
->constant_value (0);
18638 /* Normally, the DWARF producers are expected to use a signed
18639 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18640 But this is unfortunately not always the case, as witnessed
18641 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18642 is used instead. To work around that ambiguity, we treat
18643 the bounds as signed, and thus sign-extend their values, when
18644 the base type is signed. */
18646 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18647 if (low
.kind () == PROP_CONST
18648 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18649 low
.set_const_val (low
.const_val () | negative_mask
);
18650 if (high
.kind () == PROP_CONST
18651 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18652 high
.set_const_val (high
.const_val () | negative_mask
);
18654 /* Check for bit and byte strides. */
18655 struct dynamic_prop byte_stride_prop
;
18656 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18657 if (attr_byte_stride
!= nullptr)
18659 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18660 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18664 struct dynamic_prop bit_stride_prop
;
18665 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18666 if (attr_bit_stride
!= nullptr)
18668 /* It only makes sense to have either a bit or byte stride. */
18669 if (attr_byte_stride
!= nullptr)
18671 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18672 "- DIE at %s [in module %s]"),
18673 sect_offset_str (die
->sect_off
),
18674 objfile_name (cu
->per_objfile
->objfile
));
18675 attr_bit_stride
= nullptr;
18679 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18680 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18685 if (attr_byte_stride
!= nullptr
18686 || attr_bit_stride
!= nullptr)
18688 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18689 struct dynamic_prop
*stride
18690 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18693 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18694 &high
, bias
, stride
, byte_stride_p
);
18697 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18699 if (high_bound_is_count
)
18700 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18702 /* Ada expects an empty array on no boundary attributes. */
18703 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18704 range_type
->bounds ()->high
.set_undefined ();
18706 name
= dwarf2_name (die
, cu
);
18708 range_type
->set_name (name
);
18710 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18711 if (attr
!= nullptr)
18712 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18714 maybe_set_alignment (cu
, die
, range_type
);
18716 set_die_type (die
, range_type
, cu
);
18718 /* set_die_type should be already done. */
18719 set_descriptive_type (range_type
, die
, cu
);
18724 static struct type
*
18725 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18729 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18730 type
->set_name (dwarf2_name (die
, cu
));
18732 /* In Ada, an unspecified type is typically used when the description
18733 of the type is deferred to a different unit. When encountering
18734 such a type, we treat it as a stub, and try to resolve it later on,
18736 if (cu
->per_cu
->lang
== language_ada
)
18737 type
->set_is_stub (true);
18739 return set_die_type (die
, type
, cu
);
18742 /* Read a single die and all its descendents. Set the die's sibling
18743 field to NULL; set other fields in the die correctly, and set all
18744 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18745 location of the info_ptr after reading all of those dies. PARENT
18746 is the parent of the die in question. */
18748 static struct die_info
*
18749 read_die_and_children (const struct die_reader_specs
*reader
,
18750 const gdb_byte
*info_ptr
,
18751 const gdb_byte
**new_info_ptr
,
18752 struct die_info
*parent
)
18754 struct die_info
*die
;
18755 const gdb_byte
*cur_ptr
;
18757 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18760 *new_info_ptr
= cur_ptr
;
18763 store_in_ref_table (die
, reader
->cu
);
18765 if (die
->has_children
)
18766 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18770 *new_info_ptr
= cur_ptr
;
18773 die
->sibling
= NULL
;
18774 die
->parent
= parent
;
18778 /* Read a die, all of its descendents, and all of its siblings; set
18779 all of the fields of all of the dies correctly. Arguments are as
18780 in read_die_and_children. */
18782 static struct die_info
*
18783 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18784 const gdb_byte
*info_ptr
,
18785 const gdb_byte
**new_info_ptr
,
18786 struct die_info
*parent
)
18788 struct die_info
*first_die
, *last_sibling
;
18789 const gdb_byte
*cur_ptr
;
18791 cur_ptr
= info_ptr
;
18792 first_die
= last_sibling
= NULL
;
18796 struct die_info
*die
18797 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18801 *new_info_ptr
= cur_ptr
;
18808 last_sibling
->sibling
= die
;
18810 last_sibling
= die
;
18814 /* Read a die, all of its descendents, and all of its siblings; set
18815 all of the fields of all of the dies correctly. Arguments are as
18816 in read_die_and_children.
18817 This the main entry point for reading a DIE and all its children. */
18819 static struct die_info
*
18820 read_die_and_siblings (const struct die_reader_specs
*reader
,
18821 const gdb_byte
*info_ptr
,
18822 const gdb_byte
**new_info_ptr
,
18823 struct die_info
*parent
)
18825 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18826 new_info_ptr
, parent
);
18828 if (dwarf_die_debug
)
18830 fprintf_unfiltered (gdb_stdlog
,
18831 "Read die from %s@0x%x of %s:\n",
18832 reader
->die_section
->get_name (),
18833 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18834 bfd_get_filename (reader
->abfd
));
18835 dump_die (die
, dwarf_die_debug
);
18841 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18843 The caller is responsible for filling in the extra attributes
18844 and updating (*DIEP)->num_attrs.
18845 Set DIEP to point to a newly allocated die with its information,
18846 except for its child, sibling, and parent fields. */
18848 static const gdb_byte
*
18849 read_full_die_1 (const struct die_reader_specs
*reader
,
18850 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18851 int num_extra_attrs
)
18853 unsigned int abbrev_number
, bytes_read
, i
;
18854 const struct abbrev_info
*abbrev
;
18855 struct die_info
*die
;
18856 struct dwarf2_cu
*cu
= reader
->cu
;
18857 bfd
*abfd
= reader
->abfd
;
18859 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18860 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18861 info_ptr
+= bytes_read
;
18862 if (!abbrev_number
)
18868 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18870 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18872 bfd_get_filename (abfd
));
18874 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18875 die
->sect_off
= sect_off
;
18876 die
->tag
= abbrev
->tag
;
18877 die
->abbrev
= abbrev_number
;
18878 die
->has_children
= abbrev
->has_children
;
18880 /* Make the result usable.
18881 The caller needs to update num_attrs after adding the extra
18883 die
->num_attrs
= abbrev
->num_attrs
;
18885 bool any_need_reprocess
= false;
18886 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18888 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18890 if (die
->attrs
[i
].requires_reprocessing_p ())
18891 any_need_reprocess
= true;
18894 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18895 if (attr
!= nullptr && attr
->form_is_unsigned ())
18896 cu
->str_offsets_base
= attr
->as_unsigned ();
18898 attr
= die
->attr (DW_AT_loclists_base
);
18899 if (attr
!= nullptr)
18900 cu
->loclist_base
= attr
->as_unsigned ();
18902 auto maybe_addr_base
= die
->addr_base ();
18903 if (maybe_addr_base
.has_value ())
18904 cu
->addr_base
= *maybe_addr_base
;
18906 attr
= die
->attr (DW_AT_rnglists_base
);
18907 if (attr
!= nullptr)
18908 cu
->rnglists_base
= attr
->as_unsigned ();
18910 if (any_need_reprocess
)
18912 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18914 if (die
->attrs
[i
].requires_reprocessing_p ())
18915 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18922 /* Read a die and all its attributes.
18923 Set DIEP to point to a newly allocated die with its information,
18924 except for its child, sibling, and parent fields. */
18926 static const gdb_byte
*
18927 read_full_die (const struct die_reader_specs
*reader
,
18928 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18930 const gdb_byte
*result
;
18932 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18934 if (dwarf_die_debug
)
18936 fprintf_unfiltered (gdb_stdlog
,
18937 "Read die from %s@0x%x of %s:\n",
18938 reader
->die_section
->get_name (),
18939 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18940 bfd_get_filename (reader
->abfd
));
18941 dump_die (*diep
, dwarf_die_debug
);
18948 /* Returns nonzero if TAG represents a type that we might generate a partial
18952 is_type_tag_for_partial (int tag
, enum language lang
)
18957 /* Some types that would be reasonable to generate partial symbols for,
18958 that we don't at present. Note that normally this does not
18959 matter, mainly because C compilers don't give names to these
18960 types, but instead emit DW_TAG_typedef. */
18961 case DW_TAG_file_type
:
18962 case DW_TAG_ptr_to_member_type
:
18963 case DW_TAG_set_type
:
18964 case DW_TAG_string_type
:
18965 case DW_TAG_subroutine_type
:
18968 /* GNAT may emit an array with a name, but no typedef, so we
18969 need to make a symbol in this case. */
18970 case DW_TAG_array_type
:
18971 return lang
== language_ada
;
18973 case DW_TAG_base_type
:
18974 case DW_TAG_class_type
:
18975 case DW_TAG_interface_type
:
18976 case DW_TAG_enumeration_type
:
18977 case DW_TAG_structure_type
:
18978 case DW_TAG_subrange_type
:
18979 case DW_TAG_typedef
:
18980 case DW_TAG_union_type
:
18987 /* Load all DIEs that are interesting for partial symbols into memory. */
18989 static struct partial_die_info
*
18990 load_partial_dies (const struct die_reader_specs
*reader
,
18991 const gdb_byte
*info_ptr
, int building_psymtab
)
18993 struct dwarf2_cu
*cu
= reader
->cu
;
18994 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18995 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18996 unsigned int bytes_read
;
18997 unsigned int load_all
= 0;
18998 int nesting_level
= 1;
19003 gdb_assert (cu
->per_cu
!= NULL
);
19004 if (cu
->load_all_dies
)
19008 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19012 &cu
->comp_unit_obstack
,
19013 hashtab_obstack_allocate
,
19014 dummy_obstack_deallocate
);
19018 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19021 /* A NULL abbrev means the end of a series of children. */
19022 if (abbrev
== NULL
)
19024 if (--nesting_level
== 0)
19027 info_ptr
+= bytes_read
;
19028 last_die
= parent_die
;
19029 parent_die
= parent_die
->die_parent
;
19033 /* Check for template arguments. We never save these; if
19034 they're seen, we just mark the parent, and go on our way. */
19035 if (parent_die
!= NULL
19036 && cu
->per_cu
->lang
== language_cplus
19037 && (abbrev
->tag
== DW_TAG_template_type_param
19038 || abbrev
->tag
== DW_TAG_template_value_param
))
19040 parent_die
->has_template_arguments
= 1;
19044 /* We don't need a partial DIE for the template argument. */
19045 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19050 /* We only recurse into c++ subprograms looking for template arguments.
19051 Skip their other children. */
19053 && cu
->per_cu
->lang
== language_cplus
19054 && parent_die
!= NULL
19055 && parent_die
->tag
== DW_TAG_subprogram
19056 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19058 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19062 /* Check whether this DIE is interesting enough to save. Normally
19063 we would not be interested in members here, but there may be
19064 later variables referencing them via DW_AT_specification (for
19065 static members). */
19067 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
19068 && abbrev
->tag
!= DW_TAG_constant
19069 && abbrev
->tag
!= DW_TAG_enumerator
19070 && abbrev
->tag
!= DW_TAG_subprogram
19071 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19072 && abbrev
->tag
!= DW_TAG_lexical_block
19073 && abbrev
->tag
!= DW_TAG_variable
19074 && abbrev
->tag
!= DW_TAG_namespace
19075 && abbrev
->tag
!= DW_TAG_module
19076 && abbrev
->tag
!= DW_TAG_member
19077 && abbrev
->tag
!= DW_TAG_imported_unit
19078 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19080 /* Otherwise we skip to the next sibling, if any. */
19081 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19085 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19088 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19090 /* This two-pass algorithm for processing partial symbols has a
19091 high cost in cache pressure. Thus, handle some simple cases
19092 here which cover the majority of C partial symbols. DIEs
19093 which neither have specification tags in them, nor could have
19094 specification tags elsewhere pointing at them, can simply be
19095 processed and discarded.
19097 This segment is also optional; scan_partial_symbols and
19098 add_partial_symbol will handle these DIEs if we chain
19099 them in normally. When compilers which do not emit large
19100 quantities of duplicate debug information are more common,
19101 this code can probably be removed. */
19103 /* Any complete simple types at the top level (pretty much all
19104 of them, for a language without namespaces), can be processed
19106 if (parent_die
== NULL
19107 && pdi
.has_specification
== 0
19108 && pdi
.is_declaration
== 0
19109 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19110 || pdi
.tag
== DW_TAG_base_type
19111 || pdi
.tag
== DW_TAG_array_type
19112 || pdi
.tag
== DW_TAG_subrange_type
))
19114 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19115 add_partial_symbol (&pdi
, cu
);
19117 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19121 /* The exception for DW_TAG_typedef with has_children above is
19122 a workaround of GCC PR debug/47510. In the case of this complaint
19123 type_name_or_error will error on such types later.
19125 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19126 it could not find the child DIEs referenced later, this is checked
19127 above. In correct DWARF DW_TAG_typedef should have no children. */
19129 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19130 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19131 "- DIE at %s [in module %s]"),
19132 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19134 /* If we're at the second level, and we're an enumerator, and
19135 our parent has no specification (meaning possibly lives in a
19136 namespace elsewhere), then we can add the partial symbol now
19137 instead of queueing it. */
19138 if (pdi
.tag
== DW_TAG_enumerator
19139 && parent_die
!= NULL
19140 && parent_die
->die_parent
== NULL
19141 && parent_die
->tag
== DW_TAG_enumeration_type
19142 && parent_die
->has_specification
== 0)
19144 if (pdi
.raw_name
== NULL
)
19145 complaint (_("malformed enumerator DIE ignored"));
19146 else if (building_psymtab
)
19147 add_partial_symbol (&pdi
, cu
);
19149 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19153 struct partial_die_info
*part_die
19154 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19156 /* We'll save this DIE so link it in. */
19157 part_die
->die_parent
= parent_die
;
19158 part_die
->die_sibling
= NULL
;
19159 part_die
->die_child
= NULL
;
19161 if (last_die
&& last_die
== parent_die
)
19162 last_die
->die_child
= part_die
;
19164 last_die
->die_sibling
= part_die
;
19166 last_die
= part_die
;
19168 if (first_die
== NULL
)
19169 first_die
= part_die
;
19171 /* Maybe add the DIE to the hash table. Not all DIEs that we
19172 find interesting need to be in the hash table, because we
19173 also have the parent/sibling/child chains; only those that we
19174 might refer to by offset later during partial symbol reading.
19176 For now this means things that might have be the target of a
19177 DW_AT_specification, DW_AT_abstract_origin, or
19178 DW_AT_extension. DW_AT_extension will refer only to
19179 namespaces; DW_AT_abstract_origin refers to functions (and
19180 many things under the function DIE, but we do not recurse
19181 into function DIEs during partial symbol reading) and
19182 possibly variables as well; DW_AT_specification refers to
19183 declarations. Declarations ought to have the DW_AT_declaration
19184 flag. It happens that GCC forgets to put it in sometimes, but
19185 only for functions, not for types.
19187 Adding more things than necessary to the hash table is harmless
19188 except for the performance cost. Adding too few will result in
19189 wasted time in find_partial_die, when we reread the compilation
19190 unit with load_all_dies set. */
19193 || abbrev
->tag
== DW_TAG_constant
19194 || abbrev
->tag
== DW_TAG_subprogram
19195 || abbrev
->tag
== DW_TAG_variable
19196 || abbrev
->tag
== DW_TAG_namespace
19197 || part_die
->is_declaration
)
19201 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19202 to_underlying (part_die
->sect_off
),
19207 /* For some DIEs we want to follow their children (if any). For C
19208 we have no reason to follow the children of structures; for other
19209 languages we have to, so that we can get at method physnames
19210 to infer fully qualified class names, for DW_AT_specification,
19211 and for C++ template arguments. For C++, we also look one level
19212 inside functions to find template arguments (if the name of the
19213 function does not already contain the template arguments).
19215 For Ada and Fortran, we need to scan the children of subprograms
19216 and lexical blocks as well because these languages allow the
19217 definition of nested entities that could be interesting for the
19218 debugger, such as nested subprograms for instance. */
19219 if (last_die
->has_children
19221 || last_die
->tag
== DW_TAG_namespace
19222 || last_die
->tag
== DW_TAG_module
19223 || last_die
->tag
== DW_TAG_enumeration_type
19224 || (cu
->per_cu
->lang
== language_cplus
19225 && last_die
->tag
== DW_TAG_subprogram
19226 && (last_die
->raw_name
== NULL
19227 || strchr (last_die
->raw_name
, '<') == NULL
))
19228 || (cu
->per_cu
->lang
!= language_c
19229 && (last_die
->tag
== DW_TAG_class_type
19230 || last_die
->tag
== DW_TAG_interface_type
19231 || last_die
->tag
== DW_TAG_structure_type
19232 || last_die
->tag
== DW_TAG_union_type
))
19233 || ((cu
->per_cu
->lang
== language_ada
19234 || cu
->per_cu
->lang
== language_fortran
)
19235 && (last_die
->tag
== DW_TAG_subprogram
19236 || last_die
->tag
== DW_TAG_lexical_block
))))
19239 parent_die
= last_die
;
19243 /* Otherwise we skip to the next sibling, if any. */
19244 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19246 /* Back to the top, do it again. */
19250 partial_die_info::partial_die_info (sect_offset sect_off_
,
19251 const struct abbrev_info
*abbrev
)
19252 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19256 /* See class definition. */
19259 partial_die_info::name (dwarf2_cu
*cu
)
19261 if (!canonical_name
&& raw_name
!= nullptr)
19263 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19264 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19265 canonical_name
= 1;
19271 /* Read a minimal amount of information into the minimal die structure.
19272 INFO_PTR should point just after the initial uleb128 of a DIE. */
19275 partial_die_info::read (const struct die_reader_specs
*reader
,
19276 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19278 struct dwarf2_cu
*cu
= reader
->cu
;
19279 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19281 int has_low_pc_attr
= 0;
19282 int has_high_pc_attr
= 0;
19283 int high_pc_relative
= 0;
19285 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19288 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19289 /* String and address offsets that need to do the reprocessing have
19290 already been read at this point, so there is no need to wait until
19291 the loop terminates to do the reprocessing. */
19292 if (attr
.requires_reprocessing_p ())
19293 read_attribute_reprocess (reader
, &attr
, tag
);
19294 /* Store the data if it is of an attribute we want to keep in a
19295 partial symbol table. */
19301 case DW_TAG_compile_unit
:
19302 case DW_TAG_partial_unit
:
19303 case DW_TAG_type_unit
:
19304 /* Compilation units have a DW_AT_name that is a filename, not
19305 a source language identifier. */
19306 case DW_TAG_enumeration_type
:
19307 case DW_TAG_enumerator
:
19308 /* These tags always have simple identifiers already; no need
19309 to canonicalize them. */
19310 canonical_name
= 1;
19311 raw_name
= attr
.as_string ();
19314 canonical_name
= 0;
19315 raw_name
= attr
.as_string ();
19319 case DW_AT_linkage_name
:
19320 case DW_AT_MIPS_linkage_name
:
19321 /* Note that both forms of linkage name might appear. We
19322 assume they will be the same, and we only store the last
19324 linkage_name
= attr
.as_string ();
19327 has_low_pc_attr
= 1;
19328 lowpc
= attr
.as_address ();
19330 case DW_AT_high_pc
:
19331 has_high_pc_attr
= 1;
19332 highpc
= attr
.as_address ();
19333 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19334 high_pc_relative
= 1;
19336 case DW_AT_location
:
19337 /* Support the .debug_loc offsets. */
19338 if (attr
.form_is_block ())
19340 d
.locdesc
= attr
.as_block ();
19342 else if (attr
.form_is_section_offset ())
19344 dwarf2_complex_location_expr_complaint ();
19348 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19349 "partial symbol information");
19352 case DW_AT_external
:
19353 is_external
= attr
.as_boolean ();
19355 case DW_AT_declaration
:
19356 is_declaration
= attr
.as_boolean ();
19361 case DW_AT_abstract_origin
:
19362 case DW_AT_specification
:
19363 case DW_AT_extension
:
19364 has_specification
= 1;
19365 spec_offset
= attr
.get_ref_die_offset ();
19366 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19367 || cu
->per_cu
->is_dwz
);
19369 case DW_AT_sibling
:
19370 /* Ignore absolute siblings, they might point outside of
19371 the current compile unit. */
19372 if (attr
.form
== DW_FORM_ref_addr
)
19373 complaint (_("ignoring absolute DW_AT_sibling"));
19376 const gdb_byte
*buffer
= reader
->buffer
;
19377 sect_offset off
= attr
.get_ref_die_offset ();
19378 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19380 if (sibling_ptr
< info_ptr
)
19381 complaint (_("DW_AT_sibling points backwards"));
19382 else if (sibling_ptr
> reader
->buffer_end
)
19383 reader
->die_section
->overflow_complaint ();
19385 sibling
= sibling_ptr
;
19388 case DW_AT_byte_size
:
19391 case DW_AT_const_value
:
19392 has_const_value
= 1;
19394 case DW_AT_calling_convention
:
19395 /* DWARF doesn't provide a way to identify a program's source-level
19396 entry point. DW_AT_calling_convention attributes are only meant
19397 to describe functions' calling conventions.
19399 However, because it's a necessary piece of information in
19400 Fortran, and before DWARF 4 DW_CC_program was the only
19401 piece of debugging information whose definition refers to
19402 a 'main program' at all, several compilers marked Fortran
19403 main programs with DW_CC_program --- even when those
19404 functions use the standard calling conventions.
19406 Although DWARF now specifies a way to provide this
19407 information, we support this practice for backward
19409 if (attr
.constant_value (0) == DW_CC_program
19410 && cu
->per_cu
->lang
== language_fortran
)
19411 main_subprogram
= 1;
19415 LONGEST value
= attr
.constant_value (-1);
19416 if (value
== DW_INL_inlined
19417 || value
== DW_INL_declared_inlined
)
19418 may_be_inlined
= 1;
19423 if (tag
== DW_TAG_imported_unit
)
19425 d
.sect_off
= attr
.get_ref_die_offset ();
19426 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19427 || cu
->per_cu
->is_dwz
);
19431 case DW_AT_main_subprogram
:
19432 main_subprogram
= attr
.as_boolean ();
19437 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19438 on DWARF version). */
19439 ranges_offset
= attr
.as_unsigned ();
19441 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19443 if (tag
!= DW_TAG_compile_unit
)
19444 ranges_offset
+= cu
->gnu_ranges_base
;
19446 has_range_info
= 1;
19455 /* For Ada, if both the name and the linkage name appear, we prefer
19456 the latter. This lets "catch exception" work better, regardless
19457 of the order in which the name and linkage name were emitted.
19458 Really, though, this is just a workaround for the fact that gdb
19459 doesn't store both the name and the linkage name. */
19460 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19461 raw_name
= linkage_name
;
19463 if (high_pc_relative
)
19466 if (has_low_pc_attr
&& has_high_pc_attr
)
19468 /* When using the GNU linker, .gnu.linkonce. sections are used to
19469 eliminate duplicate copies of functions and vtables and such.
19470 The linker will arbitrarily choose one and discard the others.
19471 The AT_*_pc values for such functions refer to local labels in
19472 these sections. If the section from that file was discarded, the
19473 labels are not in the output, so the relocs get a value of 0.
19474 If this is a discarded function, mark the pc bounds as invalid,
19475 so that GDB will ignore it. */
19476 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19478 struct objfile
*objfile
= per_objfile
->objfile
;
19479 struct gdbarch
*gdbarch
= objfile
->arch ();
19481 complaint (_("DW_AT_low_pc %s is zero "
19482 "for DIE at %s [in module %s]"),
19483 paddress (gdbarch
, lowpc
),
19484 sect_offset_str (sect_off
),
19485 objfile_name (objfile
));
19487 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19488 else if (lowpc
>= highpc
)
19490 struct objfile
*objfile
= per_objfile
->objfile
;
19491 struct gdbarch
*gdbarch
= objfile
->arch ();
19493 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19494 "for DIE at %s [in module %s]"),
19495 paddress (gdbarch
, lowpc
),
19496 paddress (gdbarch
, highpc
),
19497 sect_offset_str (sect_off
),
19498 objfile_name (objfile
));
19507 /* Find a cached partial DIE at OFFSET in CU. */
19509 struct partial_die_info
*
19510 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19512 struct partial_die_info
*lookup_die
= NULL
;
19513 struct partial_die_info
part_die (sect_off
);
19515 lookup_die
= ((struct partial_die_info
*)
19516 htab_find_with_hash (partial_dies
, &part_die
,
19517 to_underlying (sect_off
)));
19522 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19523 except in the case of .debug_types DIEs which do not reference
19524 outside their CU (they do however referencing other types via
19525 DW_FORM_ref_sig8). */
19527 static const struct cu_partial_die_info
19528 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19530 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19531 struct objfile
*objfile
= per_objfile
->objfile
;
19532 struct partial_die_info
*pd
= NULL
;
19534 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19535 && cu
->header
.offset_in_cu_p (sect_off
))
19537 pd
= cu
->find_partial_die (sect_off
);
19540 /* We missed recording what we needed.
19541 Load all dies and try again. */
19545 /* TUs don't reference other CUs/TUs (except via type signatures). */
19546 if (cu
->per_cu
->is_debug_types
)
19548 error (_("Dwarf Error: Type Unit at offset %s contains"
19549 " external reference to offset %s [in module %s].\n"),
19550 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19551 bfd_get_filename (objfile
->obfd
));
19553 dwarf2_per_cu_data
*per_cu
19554 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19557 cu
= per_objfile
->get_cu (per_cu
);
19558 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19559 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19561 cu
= per_objfile
->get_cu (per_cu
);
19564 pd
= cu
->find_partial_die (sect_off
);
19567 /* If we didn't find it, and not all dies have been loaded,
19568 load them all and try again. */
19570 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19572 cu
->load_all_dies
= 1;
19574 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19575 THIS_CU->cu may already be in use. So we can't just free it and
19576 replace its DIEs with the ones we read in. Instead, we leave those
19577 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19578 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19580 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19582 pd
= cu
->find_partial_die (sect_off
);
19586 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19587 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19591 /* See if we can figure out if the class lives in a namespace. We do
19592 this by looking for a member function; its demangled name will
19593 contain namespace info, if there is any. */
19596 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19597 struct dwarf2_cu
*cu
)
19599 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19600 what template types look like, because the demangler
19601 frequently doesn't give the same name as the debug info. We
19602 could fix this by only using the demangled name to get the
19603 prefix (but see comment in read_structure_type). */
19605 struct partial_die_info
*real_pdi
;
19606 struct partial_die_info
*child_pdi
;
19608 /* If this DIE (this DIE's specification, if any) has a parent, then
19609 we should not do this. We'll prepend the parent's fully qualified
19610 name when we create the partial symbol. */
19612 real_pdi
= struct_pdi
;
19613 while (real_pdi
->has_specification
)
19615 auto res
= find_partial_die (real_pdi
->spec_offset
,
19616 real_pdi
->spec_is_dwz
, cu
);
19617 real_pdi
= res
.pdi
;
19621 if (real_pdi
->die_parent
!= NULL
)
19624 for (child_pdi
= struct_pdi
->die_child
;
19626 child_pdi
= child_pdi
->die_sibling
)
19628 if (child_pdi
->tag
== DW_TAG_subprogram
19629 && child_pdi
->linkage_name
!= NULL
)
19631 gdb::unique_xmalloc_ptr
<char> actual_class_name
19632 (cu
->language_defn
->class_name_from_physname
19633 (child_pdi
->linkage_name
));
19634 if (actual_class_name
!= NULL
)
19636 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19637 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19638 struct_pdi
->canonical_name
= 1;
19645 /* Return true if a DIE with TAG may have the DW_AT_const_value
19649 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19653 case DW_TAG_constant
:
19654 case DW_TAG_enumerator
:
19655 case DW_TAG_formal_parameter
:
19656 case DW_TAG_template_value_param
:
19657 case DW_TAG_variable
:
19665 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19667 /* Once we've fixed up a die, there's no point in doing so again.
19668 This also avoids a memory leak if we were to call
19669 guess_partial_die_structure_name multiple times. */
19673 /* If we found a reference attribute and the DIE has no name, try
19674 to find a name in the referred to DIE. */
19676 if (raw_name
== NULL
&& has_specification
)
19678 struct partial_die_info
*spec_die
;
19680 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19681 spec_die
= res
.pdi
;
19684 spec_die
->fixup (cu
);
19686 if (spec_die
->raw_name
)
19688 raw_name
= spec_die
->raw_name
;
19689 canonical_name
= spec_die
->canonical_name
;
19691 /* Copy DW_AT_external attribute if it is set. */
19692 if (spec_die
->is_external
)
19693 is_external
= spec_die
->is_external
;
19697 if (!has_const_value
&& has_specification
19698 && can_have_DW_AT_const_value_p (tag
))
19700 struct partial_die_info
*spec_die
;
19702 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19703 spec_die
= res
.pdi
;
19706 spec_die
->fixup (cu
);
19708 if (spec_die
->has_const_value
)
19710 /* Copy DW_AT_const_value attribute if it is set. */
19711 has_const_value
= spec_die
->has_const_value
;
19715 /* Set default names for some unnamed DIEs. */
19717 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19719 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19720 canonical_name
= 1;
19723 /* If there is no parent die to provide a namespace, and there are
19724 children, see if we can determine the namespace from their linkage
19726 if (cu
->per_cu
->lang
== language_cplus
19727 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19728 && die_parent
== NULL
19730 && (tag
== DW_TAG_class_type
19731 || tag
== DW_TAG_structure_type
19732 || tag
== DW_TAG_union_type
))
19733 guess_partial_die_structure_name (this, cu
);
19735 /* GCC might emit a nameless struct or union that has a linkage
19736 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19737 if (raw_name
== NULL
19738 && (tag
== DW_TAG_class_type
19739 || tag
== DW_TAG_interface_type
19740 || tag
== DW_TAG_structure_type
19741 || tag
== DW_TAG_union_type
)
19742 && linkage_name
!= NULL
)
19744 gdb::unique_xmalloc_ptr
<char> demangled
19745 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19746 if (demangled
!= nullptr)
19750 /* Strip any leading namespaces/classes, keep only the base name.
19751 DW_AT_name for named DIEs does not contain the prefixes. */
19752 base
= strrchr (demangled
.get (), ':');
19753 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19756 base
= demangled
.get ();
19758 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19759 raw_name
= objfile
->intern (base
);
19760 canonical_name
= 1;
19767 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19768 contents from the given SECTION in the HEADER.
19770 HEADER_OFFSET is the offset of the header in the section. */
19772 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19773 struct dwarf2_section_info
*section
,
19774 sect_offset header_offset
)
19776 unsigned int bytes_read
;
19777 bfd
*abfd
= section
->get_bfd_owner ();
19778 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19780 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19781 info_ptr
+= bytes_read
;
19783 header
->version
= read_2_bytes (abfd
, info_ptr
);
19786 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19789 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19792 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19795 /* Return the DW_AT_loclists_base value for the CU. */
19797 lookup_loclist_base (struct dwarf2_cu
*cu
)
19799 /* For the .dwo unit, the loclist_base points to the first offset following
19800 the header. The header consists of the following entities-
19801 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19803 2. version (2 bytes)
19804 3. address size (1 byte)
19805 4. segment selector size (1 byte)
19806 5. offset entry count (4 bytes)
19807 These sizes are derived as per the DWARFv5 standard. */
19808 if (cu
->dwo_unit
!= nullptr)
19810 if (cu
->header
.initial_length_size
== 4)
19811 return LOCLIST_HEADER_SIZE32
;
19812 return LOCLIST_HEADER_SIZE64
;
19814 return cu
->loclist_base
;
19817 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19818 array of offsets in the .debug_loclists section. */
19821 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19823 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19824 struct objfile
*objfile
= per_objfile
->objfile
;
19825 bfd
*abfd
= objfile
->obfd
;
19826 ULONGEST loclist_header_size
=
19827 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19828 : LOCLIST_HEADER_SIZE64
);
19829 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19831 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19832 ULONGEST start_offset
=
19833 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19835 /* Get loclists section. */
19836 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19838 /* Read the loclists section content. */
19839 section
->read (objfile
);
19840 if (section
->buffer
== NULL
)
19841 error (_("DW_FORM_loclistx used without .debug_loclists "
19842 "section [in module %s]"), objfile_name (objfile
));
19844 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19845 so if loclist_base is smaller than the header size, we have a problem. */
19846 if (loclist_base
< loclist_header_size
)
19847 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19848 objfile_name (objfile
));
19850 /* Read the header of the loclists contribution. */
19851 struct loclists_rnglists_header header
;
19852 read_loclists_rnglists_header (&header
, section
,
19853 (sect_offset
) (loclist_base
- loclist_header_size
));
19855 /* Verify the loclist index is valid. */
19856 if (loclist_index
>= header
.offset_entry_count
)
19857 error (_("DW_FORM_loclistx pointing outside of "
19858 ".debug_loclists offset array [in module %s]"),
19859 objfile_name (objfile
));
19861 /* Validate that reading won't go beyond the end of the section. */
19862 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19863 error (_("Reading DW_FORM_loclistx index beyond end of"
19864 ".debug_loclists section [in module %s]"),
19865 objfile_name (objfile
));
19867 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19869 if (cu
->header
.offset_size
== 4)
19870 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19872 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19875 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19876 array of offsets in the .debug_rnglists section. */
19879 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19882 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19883 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19884 bfd
*abfd
= objfile
->obfd
;
19885 ULONGEST rnglist_header_size
=
19886 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19887 : RNGLIST_HEADER_SIZE64
);
19889 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19890 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19892 ULONGEST rnglist_base
=
19893 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19895 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19896 ULONGEST start_offset
=
19897 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19899 /* Get rnglists section. */
19900 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19902 /* Read the rnglists section content. */
19903 section
->read (objfile
);
19904 if (section
->buffer
== nullptr)
19905 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19907 objfile_name (objfile
));
19909 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19910 so if rnglist_base is smaller than the header size, we have a problem. */
19911 if (rnglist_base
< rnglist_header_size
)
19912 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19913 objfile_name (objfile
));
19915 /* Read the header of the rnglists contribution. */
19916 struct loclists_rnglists_header header
;
19917 read_loclists_rnglists_header (&header
, section
,
19918 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19920 /* Verify the rnglist index is valid. */
19921 if (rnglist_index
>= header
.offset_entry_count
)
19922 error (_("DW_FORM_rnglistx index pointing outside of "
19923 ".debug_rnglists offset array [in module %s]"),
19924 objfile_name (objfile
));
19926 /* Validate that reading won't go beyond the end of the section. */
19927 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19928 error (_("Reading DW_FORM_rnglistx index beyond end of"
19929 ".debug_rnglists section [in module %s]"),
19930 objfile_name (objfile
));
19932 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19934 if (cu
->header
.offset_size
== 4)
19935 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19937 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19940 /* Process the attributes that had to be skipped in the first round. These
19941 attributes are the ones that need str_offsets_base or addr_base attributes.
19942 They could not have been processed in the first round, because at the time
19943 the values of str_offsets_base or addr_base may not have been known. */
19945 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19946 struct attribute
*attr
, dwarf_tag tag
)
19948 struct dwarf2_cu
*cu
= reader
->cu
;
19949 switch (attr
->form
)
19951 case DW_FORM_addrx
:
19952 case DW_FORM_GNU_addr_index
:
19953 attr
->set_address (read_addr_index (cu
,
19954 attr
->as_unsigned_reprocess ()));
19956 case DW_FORM_loclistx
:
19958 sect_offset loclists_sect_off
19959 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19961 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19964 case DW_FORM_rnglistx
:
19966 sect_offset rnglists_sect_off
19967 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19969 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19973 case DW_FORM_strx1
:
19974 case DW_FORM_strx2
:
19975 case DW_FORM_strx3
:
19976 case DW_FORM_strx4
:
19977 case DW_FORM_GNU_str_index
:
19979 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19980 gdb_assert (!attr
->canonical_string_p ());
19981 if (reader
->dwo_file
!= NULL
)
19982 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19985 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19990 gdb_assert_not_reached (_("Unexpected DWARF form."));
19994 /* Read an attribute value described by an attribute form. */
19996 static const gdb_byte
*
19997 read_attribute_value (const struct die_reader_specs
*reader
,
19998 struct attribute
*attr
, unsigned form
,
19999 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20001 struct dwarf2_cu
*cu
= reader
->cu
;
20002 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20003 struct objfile
*objfile
= per_objfile
->objfile
;
20004 bfd
*abfd
= reader
->abfd
;
20005 struct comp_unit_head
*cu_header
= &cu
->header
;
20006 unsigned int bytes_read
;
20007 struct dwarf_block
*blk
;
20009 attr
->form
= (enum dwarf_form
) form
;
20012 case DW_FORM_ref_addr
:
20013 if (cu_header
->version
== 2)
20014 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20017 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20019 info_ptr
+= bytes_read
;
20021 case DW_FORM_GNU_ref_alt
:
20022 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20024 info_ptr
+= bytes_read
;
20028 struct gdbarch
*gdbarch
= objfile
->arch ();
20029 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20030 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20031 attr
->set_address (addr
);
20032 info_ptr
+= bytes_read
;
20035 case DW_FORM_block2
:
20036 blk
= dwarf_alloc_block (cu
);
20037 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20039 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20040 info_ptr
+= blk
->size
;
20041 attr
->set_block (blk
);
20043 case DW_FORM_block4
:
20044 blk
= dwarf_alloc_block (cu
);
20045 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20047 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20048 info_ptr
+= blk
->size
;
20049 attr
->set_block (blk
);
20051 case DW_FORM_data2
:
20052 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20055 case DW_FORM_data4
:
20056 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20059 case DW_FORM_data8
:
20060 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20063 case DW_FORM_data16
:
20064 blk
= dwarf_alloc_block (cu
);
20066 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20068 attr
->set_block (blk
);
20070 case DW_FORM_sec_offset
:
20071 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20073 info_ptr
+= bytes_read
;
20075 case DW_FORM_loclistx
:
20077 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20079 info_ptr
+= bytes_read
;
20082 case DW_FORM_string
:
20083 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20085 info_ptr
+= bytes_read
;
20088 if (!cu
->per_cu
->is_dwz
)
20090 attr
->set_string_noncanonical
20091 (read_indirect_string (per_objfile
,
20092 abfd
, info_ptr
, cu_header
,
20094 info_ptr
+= bytes_read
;
20098 case DW_FORM_line_strp
:
20099 if (!cu
->per_cu
->is_dwz
)
20101 attr
->set_string_noncanonical
20102 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20104 info_ptr
+= bytes_read
;
20108 case DW_FORM_GNU_strp_alt
:
20110 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20111 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20114 attr
->set_string_noncanonical
20115 (dwz
->read_string (objfile
, str_offset
));
20116 info_ptr
+= bytes_read
;
20119 case DW_FORM_exprloc
:
20120 case DW_FORM_block
:
20121 blk
= dwarf_alloc_block (cu
);
20122 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20123 info_ptr
+= bytes_read
;
20124 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20125 info_ptr
+= blk
->size
;
20126 attr
->set_block (blk
);
20128 case DW_FORM_block1
:
20129 blk
= dwarf_alloc_block (cu
);
20130 blk
->size
= read_1_byte (abfd
, info_ptr
);
20132 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20133 info_ptr
+= blk
->size
;
20134 attr
->set_block (blk
);
20136 case DW_FORM_data1
:
20138 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20141 case DW_FORM_flag_present
:
20142 attr
->set_unsigned (1);
20144 case DW_FORM_sdata
:
20145 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20146 info_ptr
+= bytes_read
;
20148 case DW_FORM_rnglistx
:
20150 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20152 info_ptr
+= bytes_read
;
20155 case DW_FORM_udata
:
20156 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20157 info_ptr
+= bytes_read
;
20160 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20161 + read_1_byte (abfd
, info_ptr
)));
20165 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20166 + read_2_bytes (abfd
, info_ptr
)));
20170 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20171 + read_4_bytes (abfd
, info_ptr
)));
20175 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20176 + read_8_bytes (abfd
, info_ptr
)));
20179 case DW_FORM_ref_sig8
:
20180 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20183 case DW_FORM_ref_udata
:
20184 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20185 + read_unsigned_leb128 (abfd
, info_ptr
,
20187 info_ptr
+= bytes_read
;
20189 case DW_FORM_indirect
:
20190 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20191 info_ptr
+= bytes_read
;
20192 if (form
== DW_FORM_implicit_const
)
20194 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20195 info_ptr
+= bytes_read
;
20197 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20200 case DW_FORM_implicit_const
:
20201 attr
->set_signed (implicit_const
);
20203 case DW_FORM_addrx
:
20204 case DW_FORM_GNU_addr_index
:
20205 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20207 info_ptr
+= bytes_read
;
20210 case DW_FORM_strx1
:
20211 case DW_FORM_strx2
:
20212 case DW_FORM_strx3
:
20213 case DW_FORM_strx4
:
20214 case DW_FORM_GNU_str_index
:
20216 ULONGEST str_index
;
20217 if (form
== DW_FORM_strx1
)
20219 str_index
= read_1_byte (abfd
, info_ptr
);
20222 else if (form
== DW_FORM_strx2
)
20224 str_index
= read_2_bytes (abfd
, info_ptr
);
20227 else if (form
== DW_FORM_strx3
)
20229 str_index
= read_3_bytes (abfd
, info_ptr
);
20232 else if (form
== DW_FORM_strx4
)
20234 str_index
= read_4_bytes (abfd
, info_ptr
);
20239 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20240 info_ptr
+= bytes_read
;
20242 attr
->set_unsigned_reprocess (str_index
);
20246 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20247 dwarf_form_name (form
),
20248 bfd_get_filename (abfd
));
20252 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20253 attr
->form
= DW_FORM_GNU_ref_alt
;
20255 /* We have seen instances where the compiler tried to emit a byte
20256 size attribute of -1 which ended up being encoded as an unsigned
20257 0xffffffff. Although 0xffffffff is technically a valid size value,
20258 an object of this size seems pretty unlikely so we can relatively
20259 safely treat these cases as if the size attribute was invalid and
20260 treat them as zero by default. */
20261 if (attr
->name
== DW_AT_byte_size
20262 && form
== DW_FORM_data4
20263 && attr
->as_unsigned () >= 0xffffffff)
20266 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20267 hex_string (attr
->as_unsigned ()));
20268 attr
->set_unsigned (0);
20274 /* Read an attribute described by an abbreviated attribute. */
20276 static const gdb_byte
*
20277 read_attribute (const struct die_reader_specs
*reader
,
20278 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20279 const gdb_byte
*info_ptr
)
20281 attr
->name
= abbrev
->name
;
20282 attr
->string_is_canonical
= 0;
20283 attr
->requires_reprocessing
= 0;
20284 return read_attribute_value (reader
, attr
, abbrev
->form
,
20285 abbrev
->implicit_const
, info_ptr
);
20288 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20290 static const char *
20291 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20292 LONGEST str_offset
)
20294 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20295 str_offset
, "DW_FORM_strp");
20298 /* Return pointer to string at .debug_str offset as read from BUF.
20299 BUF is assumed to be in a compilation unit described by CU_HEADER.
20300 Return *BYTES_READ_PTR count of bytes read from BUF. */
20302 static const char *
20303 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20304 const gdb_byte
*buf
,
20305 const struct comp_unit_head
*cu_header
,
20306 unsigned int *bytes_read_ptr
)
20308 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20310 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20316 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20317 const struct comp_unit_head
*cu_header
,
20318 unsigned int *bytes_read_ptr
)
20320 bfd
*abfd
= objfile
->obfd
;
20321 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20323 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20326 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20327 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20328 ADDR_SIZE is the size of addresses from the CU header. */
20331 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20332 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20334 struct objfile
*objfile
= per_objfile
->objfile
;
20335 bfd
*abfd
= objfile
->obfd
;
20336 const gdb_byte
*info_ptr
;
20337 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20339 per_objfile
->per_bfd
->addr
.read (objfile
);
20340 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20341 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20342 objfile_name (objfile
));
20343 if (addr_base_or_zero
+ addr_index
* addr_size
20344 >= per_objfile
->per_bfd
->addr
.size
)
20345 error (_("DW_FORM_addr_index pointing outside of "
20346 ".debug_addr section [in module %s]"),
20347 objfile_name (objfile
));
20348 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20349 + addr_index
* addr_size
);
20350 if (addr_size
== 4)
20351 return bfd_get_32 (abfd
, info_ptr
);
20353 return bfd_get_64 (abfd
, info_ptr
);
20356 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20359 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20361 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20362 cu
->addr_base
, cu
->header
.addr_size
);
20365 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20368 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20369 unsigned int *bytes_read
)
20371 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20372 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20374 return read_addr_index (cu
, addr_index
);
20380 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20381 dwarf2_per_objfile
*per_objfile
,
20382 unsigned int addr_index
)
20384 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20385 gdb::optional
<ULONGEST
> addr_base
;
20388 /* We need addr_base and addr_size.
20389 If we don't have PER_CU->cu, we have to get it.
20390 Nasty, but the alternative is storing the needed info in PER_CU,
20391 which at this point doesn't seem justified: it's not clear how frequently
20392 it would get used and it would increase the size of every PER_CU.
20393 Entry points like dwarf2_per_cu_addr_size do a similar thing
20394 so we're not in uncharted territory here.
20395 Alas we need to be a bit more complicated as addr_base is contained
20398 We don't need to read the entire CU(/TU).
20399 We just need the header and top level die.
20401 IWBN to use the aging mechanism to let us lazily later discard the CU.
20402 For now we skip this optimization. */
20406 addr_base
= cu
->addr_base
;
20407 addr_size
= cu
->header
.addr_size
;
20411 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20412 addr_base
= reader
.cu
->addr_base
;
20413 addr_size
= reader
.cu
->header
.addr_size
;
20416 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20419 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20420 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20423 static const char *
20424 read_str_index (struct dwarf2_cu
*cu
,
20425 struct dwarf2_section_info
*str_section
,
20426 struct dwarf2_section_info
*str_offsets_section
,
20427 ULONGEST str_offsets_base
, ULONGEST str_index
)
20429 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20430 struct objfile
*objfile
= per_objfile
->objfile
;
20431 const char *objf_name
= objfile_name (objfile
);
20432 bfd
*abfd
= objfile
->obfd
;
20433 const gdb_byte
*info_ptr
;
20434 ULONGEST str_offset
;
20435 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20437 str_section
->read (objfile
);
20438 str_offsets_section
->read (objfile
);
20439 if (str_section
->buffer
== NULL
)
20440 error (_("%s used without %s section"
20441 " in CU at offset %s [in module %s]"),
20442 form_name
, str_section
->get_name (),
20443 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20444 if (str_offsets_section
->buffer
== NULL
)
20445 error (_("%s used without %s section"
20446 " in CU at offset %s [in module %s]"),
20447 form_name
, str_section
->get_name (),
20448 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20449 info_ptr
= (str_offsets_section
->buffer
20451 + str_index
* cu
->header
.offset_size
);
20452 if (cu
->header
.offset_size
== 4)
20453 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20455 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20456 if (str_offset
>= str_section
->size
)
20457 error (_("Offset from %s pointing outside of"
20458 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20459 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20460 return (const char *) (str_section
->buffer
+ str_offset
);
20463 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20465 static const char *
20466 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20468 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20469 ? reader
->cu
->header
.addr_size
: 0;
20470 return read_str_index (reader
->cu
,
20471 &reader
->dwo_file
->sections
.str
,
20472 &reader
->dwo_file
->sections
.str_offsets
,
20473 str_offsets_base
, str_index
);
20476 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20478 static const char *
20479 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20481 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20482 const char *objf_name
= objfile_name (objfile
);
20483 static const char form_name
[] = "DW_FORM_GNU_str_index";
20484 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20486 if (!cu
->str_offsets_base
.has_value ())
20487 error (_("%s used in Fission stub without %s"
20488 " in CU at offset 0x%lx [in module %s]"),
20489 form_name
, str_offsets_attr_name
,
20490 (long) cu
->header
.offset_size
, objf_name
);
20492 return read_str_index (cu
,
20493 &cu
->per_objfile
->per_bfd
->str
,
20494 &cu
->per_objfile
->per_bfd
->str_offsets
,
20495 *cu
->str_offsets_base
, str_index
);
20498 /* Return the length of an LEB128 number in BUF. */
20501 leb128_size (const gdb_byte
*buf
)
20503 const gdb_byte
*begin
= buf
;
20509 if ((byte
& 128) == 0)
20510 return buf
- begin
;
20514 static enum language
20515 dwarf_lang_to_enum_language (unsigned int lang
)
20517 enum language language
;
20526 language
= language_c
;
20529 case DW_LANG_C_plus_plus
:
20530 case DW_LANG_C_plus_plus_11
:
20531 case DW_LANG_C_plus_plus_14
:
20532 language
= language_cplus
;
20535 language
= language_d
;
20537 case DW_LANG_Fortran77
:
20538 case DW_LANG_Fortran90
:
20539 case DW_LANG_Fortran95
:
20540 case DW_LANG_Fortran03
:
20541 case DW_LANG_Fortran08
:
20542 language
= language_fortran
;
20545 language
= language_go
;
20547 case DW_LANG_Mips_Assembler
:
20548 language
= language_asm
;
20550 case DW_LANG_Ada83
:
20551 case DW_LANG_Ada95
:
20552 language
= language_ada
;
20554 case DW_LANG_Modula2
:
20555 language
= language_m2
;
20557 case DW_LANG_Pascal83
:
20558 language
= language_pascal
;
20561 language
= language_objc
;
20564 case DW_LANG_Rust_old
:
20565 language
= language_rust
;
20567 case DW_LANG_OpenCL
:
20568 language
= language_opencl
;
20570 case DW_LANG_Cobol74
:
20571 case DW_LANG_Cobol85
:
20573 language
= language_minimal
;
20580 /* Return the named attribute or NULL if not there. */
20582 static struct attribute
*
20583 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20588 struct attribute
*spec
= NULL
;
20590 for (i
= 0; i
< die
->num_attrs
; ++i
)
20592 if (die
->attrs
[i
].name
== name
)
20593 return &die
->attrs
[i
];
20594 if (die
->attrs
[i
].name
== DW_AT_specification
20595 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20596 spec
= &die
->attrs
[i
];
20602 die
= follow_die_ref (die
, spec
, &cu
);
20608 /* Return the string associated with a string-typed attribute, or NULL if it
20609 is either not found or is of an incorrect type. */
20611 static const char *
20612 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20614 struct attribute
*attr
;
20615 const char *str
= NULL
;
20617 attr
= dwarf2_attr (die
, name
, cu
);
20621 str
= attr
->as_string ();
20622 if (str
== nullptr)
20623 complaint (_("string type expected for attribute %s for "
20624 "DIE at %s in module %s"),
20625 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20626 objfile_name (cu
->per_objfile
->objfile
));
20632 /* Return the dwo name or NULL if not present. If present, it is in either
20633 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20634 static const char *
20635 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20637 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20638 if (dwo_name
== nullptr)
20639 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20643 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20644 and holds a non-zero value. This function should only be used for
20645 DW_FORM_flag or DW_FORM_flag_present attributes. */
20648 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20650 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20652 return attr
!= nullptr && attr
->as_boolean ();
20656 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20658 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20659 which value is non-zero. However, we have to be careful with
20660 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20661 (via dwarf2_flag_true_p) follows this attribute. So we may
20662 end up accidently finding a declaration attribute that belongs
20663 to a different DIE referenced by the specification attribute,
20664 even though the given DIE does not have a declaration attribute. */
20665 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20666 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20669 /* Return the die giving the specification for DIE, if there is
20670 one. *SPEC_CU is the CU containing DIE on input, and the CU
20671 containing the return value on output. If there is no
20672 specification, but there is an abstract origin, that is
20675 static struct die_info
*
20676 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20678 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20681 if (spec_attr
== NULL
)
20682 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20684 if (spec_attr
== NULL
)
20687 return follow_die_ref (die
, spec_attr
, spec_cu
);
20690 /* A convenience function to find the proper .debug_line section for a CU. */
20692 static struct dwarf2_section_info
*
20693 get_debug_line_section (struct dwarf2_cu
*cu
)
20695 struct dwarf2_section_info
*section
;
20696 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20698 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20700 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20701 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20702 else if (cu
->per_cu
->is_dwz
)
20704 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20706 section
= &dwz
->line
;
20709 section
= &per_objfile
->per_bfd
->line
;
20714 /* Read the statement program header starting at OFFSET in
20715 .debug_line, or .debug_line.dwo. Return a pointer
20716 to a struct line_header, allocated using xmalloc.
20717 Returns NULL if there is a problem reading the header, e.g., if it
20718 has a version we don't understand.
20720 NOTE: the strings in the include directory and file name tables of
20721 the returned object point into the dwarf line section buffer,
20722 and must not be freed. */
20724 static line_header_up
20725 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20727 struct dwarf2_section_info
*section
;
20728 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20730 section
= get_debug_line_section (cu
);
20731 section
->read (per_objfile
->objfile
);
20732 if (section
->buffer
== NULL
)
20734 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20735 complaint (_("missing .debug_line.dwo section"));
20737 complaint (_("missing .debug_line section"));
20741 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20742 per_objfile
, section
, &cu
->header
);
20745 /* Subroutine of dwarf_decode_lines to simplify it.
20746 Return the file name for the given file_entry.
20747 CU_INFO describes the CU's DW_AT_name and DW_AT_comp_dir.
20748 If space for the result is malloc'd, *NAME_HOLDER will be set.
20749 Returns NULL if FILE_INDEX should be ignored, i.e., it is
20750 equivalent to CU_INFO. */
20752 static const char *
20753 compute_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20754 const file_and_directory
&cu_info
,
20755 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20757 const char *include_name
= fe
.name
;
20758 const char *include_name_to_compare
= include_name
;
20760 const char *dir_name
= fe
.include_dir (lh
);
20762 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20763 if (!IS_ABSOLUTE_PATH (include_name
)
20764 && (dir_name
!= NULL
|| cu_info
.comp_dir
!= NULL
))
20766 /* Avoid creating a duplicate name for CU_INFO.
20767 We do this by comparing INCLUDE_NAME and CU_INFO.
20768 Before we do the comparison, however, we need to account
20769 for DIR_NAME and COMP_DIR.
20770 First prepend dir_name (if non-NULL). If we still don't
20771 have an absolute path prepend comp_dir (if non-NULL).
20772 However, the directory we record in the include-file's
20773 psymtab does not contain COMP_DIR (to match the
20774 corresponding symtab(s)).
20779 bash$ gcc -g ./hello.c
20780 include_name = "hello.c"
20782 DW_AT_comp_dir = comp_dir = "/tmp"
20783 DW_AT_name = "./hello.c"
20787 if (dir_name
!= NULL
)
20789 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20790 include_name
, (char *) NULL
));
20791 include_name
= name_holder
->get ();
20792 include_name_to_compare
= include_name
;
20794 if (!IS_ABSOLUTE_PATH (include_name
) && cu_info
.comp_dir
!= nullptr)
20796 hold_compare
.reset (concat (cu_info
.comp_dir
, SLASH_STRING
,
20797 include_name
, (char *) NULL
));
20798 include_name_to_compare
= hold_compare
.get ();
20802 gdb::unique_xmalloc_ptr
<char> copied_name
;
20803 const char *cu_filename
= cu_info
.name
;
20804 if (!IS_ABSOLUTE_PATH (cu_filename
) && cu_info
.comp_dir
!= nullptr)
20806 copied_name
.reset (concat (cu_info
.comp_dir
, SLASH_STRING
,
20807 cu_filename
, (char *) NULL
));
20808 cu_filename
= copied_name
.get ();
20811 if (FILENAME_CMP (include_name_to_compare
, cu_filename
) == 0)
20813 return include_name
;
20816 /* State machine to track the state of the line number program. */
20818 class lnp_state_machine
20821 /* Initialize a machine state for the start of a line number
20823 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20824 bool record_lines_p
);
20826 file_entry
*current_file ()
20828 /* lh->file_names is 0-based, but the file name numbers in the
20829 statement program are 1-based. */
20830 return m_line_header
->file_name_at (m_file
);
20833 /* Record the line in the state machine. END_SEQUENCE is true if
20834 we're processing the end of a sequence. */
20835 void record_line (bool end_sequence
);
20837 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20838 nop-out rest of the lines in this sequence. */
20839 void check_line_address (struct dwarf2_cu
*cu
,
20840 const gdb_byte
*line_ptr
,
20841 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20843 void handle_set_discriminator (unsigned int discriminator
)
20845 m_discriminator
= discriminator
;
20846 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20849 /* Handle DW_LNE_set_address. */
20850 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20853 address
+= baseaddr
;
20854 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20857 /* Handle DW_LNS_advance_pc. */
20858 void handle_advance_pc (CORE_ADDR adjust
);
20860 /* Handle a special opcode. */
20861 void handle_special_opcode (unsigned char op_code
);
20863 /* Handle DW_LNS_advance_line. */
20864 void handle_advance_line (int line_delta
)
20866 advance_line (line_delta
);
20869 /* Handle DW_LNS_set_file. */
20870 void handle_set_file (file_name_index file
);
20872 /* Handle DW_LNS_negate_stmt. */
20873 void handle_negate_stmt ()
20875 m_is_stmt
= !m_is_stmt
;
20878 /* Handle DW_LNS_const_add_pc. */
20879 void handle_const_add_pc ();
20881 /* Handle DW_LNS_fixed_advance_pc. */
20882 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20884 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20888 /* Handle DW_LNS_copy. */
20889 void handle_copy ()
20891 record_line (false);
20892 m_discriminator
= 0;
20895 /* Handle DW_LNE_end_sequence. */
20896 void handle_end_sequence ()
20898 m_currently_recording_lines
= true;
20902 /* Advance the line by LINE_DELTA. */
20903 void advance_line (int line_delta
)
20905 m_line
+= line_delta
;
20907 if (line_delta
!= 0)
20908 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20911 struct dwarf2_cu
*m_cu
;
20913 gdbarch
*m_gdbarch
;
20915 /* True if we're recording lines.
20916 Otherwise we're building partial symtabs and are just interested in
20917 finding include files mentioned by the line number program. */
20918 bool m_record_lines_p
;
20920 /* The line number header. */
20921 line_header
*m_line_header
;
20923 /* These are part of the standard DWARF line number state machine,
20924 and initialized according to the DWARF spec. */
20926 unsigned char m_op_index
= 0;
20927 /* The line table index of the current file. */
20928 file_name_index m_file
= 1;
20929 unsigned int m_line
= 1;
20931 /* These are initialized in the constructor. */
20933 CORE_ADDR m_address
;
20935 unsigned int m_discriminator
;
20937 /* Additional bits of state we need to track. */
20939 /* The last file that we called dwarf2_start_subfile for.
20940 This is only used for TLLs. */
20941 unsigned int m_last_file
= 0;
20942 /* The last file a line number was recorded for. */
20943 struct subfile
*m_last_subfile
= NULL
;
20945 /* The address of the last line entry. */
20946 CORE_ADDR m_last_address
;
20948 /* Set to true when a previous line at the same address (using
20949 m_last_address) had m_is_stmt true. This is reset to false when a
20950 line entry at a new address (m_address different to m_last_address) is
20952 bool m_stmt_at_address
= false;
20954 /* When true, record the lines we decode. */
20955 bool m_currently_recording_lines
= false;
20957 /* The last line number that was recorded, used to coalesce
20958 consecutive entries for the same line. This can happen, for
20959 example, when discriminators are present. PR 17276. */
20960 unsigned int m_last_line
= 0;
20961 bool m_line_has_non_zero_discriminator
= false;
20965 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20967 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20968 / m_line_header
->maximum_ops_per_instruction
)
20969 * m_line_header
->minimum_instruction_length
);
20970 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20971 m_op_index
= ((m_op_index
+ adjust
)
20972 % m_line_header
->maximum_ops_per_instruction
);
20976 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20978 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20979 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20980 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20981 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20982 / m_line_header
->maximum_ops_per_instruction
)
20983 * m_line_header
->minimum_instruction_length
);
20984 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20985 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20986 % m_line_header
->maximum_ops_per_instruction
);
20988 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20989 advance_line (line_delta
);
20990 record_line (false);
20991 m_discriminator
= 0;
20995 lnp_state_machine::handle_set_file (file_name_index file
)
20999 const file_entry
*fe
= current_file ();
21001 dwarf2_debug_line_missing_file_complaint ();
21002 else if (m_record_lines_p
)
21004 const char *dir
= fe
->include_dir (m_line_header
);
21006 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21007 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21008 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21013 lnp_state_machine::handle_const_add_pc ()
21016 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21019 = (((m_op_index
+ adjust
)
21020 / m_line_header
->maximum_ops_per_instruction
)
21021 * m_line_header
->minimum_instruction_length
);
21023 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21024 m_op_index
= ((m_op_index
+ adjust
)
21025 % m_line_header
->maximum_ops_per_instruction
);
21028 /* Return non-zero if we should add LINE to the line number table.
21029 LINE is the line to add, LAST_LINE is the last line that was added,
21030 LAST_SUBFILE is the subfile for LAST_LINE.
21031 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21032 had a non-zero discriminator.
21034 We have to be careful in the presence of discriminators.
21035 E.g., for this line:
21037 for (i = 0; i < 100000; i++);
21039 clang can emit four line number entries for that one line,
21040 each with a different discriminator.
21041 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21043 However, we want gdb to coalesce all four entries into one.
21044 Otherwise the user could stepi into the middle of the line and
21045 gdb would get confused about whether the pc really was in the
21046 middle of the line.
21048 Things are further complicated by the fact that two consecutive
21049 line number entries for the same line is a heuristic used by gcc
21050 to denote the end of the prologue. So we can't just discard duplicate
21051 entries, we have to be selective about it. The heuristic we use is
21052 that we only collapse consecutive entries for the same line if at least
21053 one of those entries has a non-zero discriminator. PR 17276.
21055 Note: Addresses in the line number state machine can never go backwards
21056 within one sequence, thus this coalescing is ok. */
21059 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21060 unsigned int line
, unsigned int last_line
,
21061 int line_has_non_zero_discriminator
,
21062 struct subfile
*last_subfile
)
21064 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21066 if (line
!= last_line
)
21068 /* Same line for the same file that we've seen already.
21069 As a last check, for pr 17276, only record the line if the line
21070 has never had a non-zero discriminator. */
21071 if (!line_has_non_zero_discriminator
)
21076 /* Use the CU's builder to record line number LINE beginning at
21077 address ADDRESS in the line table of subfile SUBFILE. */
21080 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21081 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21082 struct dwarf2_cu
*cu
)
21084 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21086 if (dwarf_line_debug
)
21088 fprintf_unfiltered (gdb_stdlog
,
21089 "Recording line %u, file %s, address %s\n",
21090 line
, lbasename (subfile
->name
),
21091 paddress (gdbarch
, address
));
21095 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21098 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21099 Mark the end of a set of line number records.
21100 The arguments are the same as for dwarf_record_line_1.
21101 If SUBFILE is NULL the request is ignored. */
21104 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21105 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21107 if (subfile
== NULL
)
21110 if (dwarf_line_debug
)
21112 fprintf_unfiltered (gdb_stdlog
,
21113 "Finishing current line, file %s, address %s\n",
21114 lbasename (subfile
->name
),
21115 paddress (gdbarch
, address
));
21118 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21122 lnp_state_machine::record_line (bool end_sequence
)
21124 if (dwarf_line_debug
)
21126 fprintf_unfiltered (gdb_stdlog
,
21127 "Processing actual line %u: file %u,"
21128 " address %s, is_stmt %u, discrim %u%s\n",
21130 paddress (m_gdbarch
, m_address
),
21131 m_is_stmt
, m_discriminator
,
21132 (end_sequence
? "\t(end sequence)" : ""));
21135 file_entry
*fe
= current_file ();
21138 dwarf2_debug_line_missing_file_complaint ();
21139 /* For now we ignore lines not starting on an instruction boundary.
21140 But not when processing end_sequence for compatibility with the
21141 previous version of the code. */
21142 else if (m_op_index
== 0 || end_sequence
)
21144 fe
->included_p
= true;
21145 if (m_record_lines_p
)
21147 /* When we switch files we insert an end maker in the first file,
21148 switch to the second file and add a new line entry. The
21149 problem is that the end marker inserted in the first file will
21150 discard any previous line entries at the same address. If the
21151 line entries in the first file are marked as is-stmt, while
21152 the new line in the second file is non-stmt, then this means
21153 the end marker will discard is-stmt lines so we can have a
21154 non-stmt line. This means that there are less addresses at
21155 which the user can insert a breakpoint.
21157 To improve this we track the last address in m_last_address,
21158 and whether we have seen an is-stmt at this address. Then
21159 when switching files, if we have seen a stmt at the current
21160 address, and we are switching to create a non-stmt line, then
21161 discard the new line. */
21163 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21164 bool ignore_this_line
21165 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21166 && !m_is_stmt
&& m_stmt_at_address
)
21167 || (!end_sequence
&& m_line
== 0));
21169 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21171 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21172 m_currently_recording_lines
? m_cu
: nullptr);
21175 if (!end_sequence
&& !ignore_this_line
)
21177 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21179 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21180 m_line_has_non_zero_discriminator
,
21183 buildsym_compunit
*builder
= m_cu
->get_builder ();
21184 dwarf_record_line_1 (m_gdbarch
,
21185 builder
->get_current_subfile (),
21186 m_line
, m_address
, is_stmt
,
21187 m_currently_recording_lines
? m_cu
: nullptr);
21189 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21190 m_last_line
= m_line
;
21195 /* Track whether we have seen any m_is_stmt true at m_address in case we
21196 have multiple line table entries all at m_address. */
21197 if (m_last_address
!= m_address
)
21199 m_stmt_at_address
= false;
21200 m_last_address
= m_address
;
21202 m_stmt_at_address
|= m_is_stmt
;
21205 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21206 line_header
*lh
, bool record_lines_p
)
21210 m_record_lines_p
= record_lines_p
;
21211 m_line_header
= lh
;
21213 m_currently_recording_lines
= true;
21215 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21216 was a line entry for it so that the backend has a chance to adjust it
21217 and also record it in case it needs it. This is currently used by MIPS
21218 code, cf. `mips_adjust_dwarf2_line'. */
21219 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21220 m_is_stmt
= lh
->default_is_stmt
;
21221 m_discriminator
= 0;
21223 m_last_address
= m_address
;
21224 m_stmt_at_address
= false;
21228 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21229 const gdb_byte
*line_ptr
,
21230 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21232 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21233 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21234 located at 0x0. In this case, additionally check that if
21235 ADDRESS < UNRELOCATED_LOWPC. */
21237 if ((address
== 0 && address
< unrelocated_lowpc
)
21238 || address
== (CORE_ADDR
) -1)
21240 /* This line table is for a function which has been
21241 GCd by the linker. Ignore it. PR gdb/12528 */
21243 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21244 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21246 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21247 line_offset
, objfile_name (objfile
));
21248 m_currently_recording_lines
= false;
21249 /* Note: m_currently_recording_lines is left as false until we see
21250 DW_LNE_end_sequence. */
21254 /* Subroutine of dwarf_decode_lines to simplify it.
21255 Process the line number information in LH.
21256 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21257 program in order to set included_p for every referenced header. */
21260 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21261 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21263 const gdb_byte
*line_ptr
, *extended_end
;
21264 const gdb_byte
*line_end
;
21265 unsigned int bytes_read
, extended_len
;
21266 unsigned char op_code
, extended_op
;
21267 CORE_ADDR baseaddr
;
21268 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21269 bfd
*abfd
= objfile
->obfd
;
21270 struct gdbarch
*gdbarch
= objfile
->arch ();
21271 /* True if we're recording line info (as opposed to building partial
21272 symtabs and just interested in finding include files mentioned by
21273 the line number program). */
21274 bool record_lines_p
= !decode_for_pst_p
;
21276 baseaddr
= objfile
->text_section_offset ();
21278 line_ptr
= lh
->statement_program_start
;
21279 line_end
= lh
->statement_program_end
;
21281 /* Read the statement sequences until there's nothing left. */
21282 while (line_ptr
< line_end
)
21284 /* The DWARF line number program state machine. Reset the state
21285 machine at the start of each sequence. */
21286 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21287 bool end_sequence
= false;
21289 if (record_lines_p
)
21291 /* Start a subfile for the current file of the state
21293 const file_entry
*fe
= state_machine
.current_file ();
21296 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21299 /* Decode the table. */
21300 while (line_ptr
< line_end
&& !end_sequence
)
21302 op_code
= read_1_byte (abfd
, line_ptr
);
21305 if (op_code
>= lh
->opcode_base
)
21307 /* Special opcode. */
21308 state_machine
.handle_special_opcode (op_code
);
21310 else switch (op_code
)
21312 case DW_LNS_extended_op
:
21313 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21315 line_ptr
+= bytes_read
;
21316 extended_end
= line_ptr
+ extended_len
;
21317 extended_op
= read_1_byte (abfd
, line_ptr
);
21319 if (DW_LNE_lo_user
<= extended_op
21320 && extended_op
<= DW_LNE_hi_user
)
21322 /* Vendor extension, ignore. */
21323 line_ptr
= extended_end
;
21326 switch (extended_op
)
21328 case DW_LNE_end_sequence
:
21329 state_machine
.handle_end_sequence ();
21330 end_sequence
= true;
21332 case DW_LNE_set_address
:
21335 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21336 line_ptr
+= bytes_read
;
21338 state_machine
.check_line_address (cu
, line_ptr
,
21339 lowpc
- baseaddr
, address
);
21340 state_machine
.handle_set_address (baseaddr
, address
);
21343 case DW_LNE_define_file
:
21345 const char *cur_file
;
21346 unsigned int mod_time
, length
;
21349 cur_file
= read_direct_string (abfd
, line_ptr
,
21351 line_ptr
+= bytes_read
;
21352 dindex
= (dir_index
)
21353 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21354 line_ptr
+= bytes_read
;
21356 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21357 line_ptr
+= bytes_read
;
21359 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21360 line_ptr
+= bytes_read
;
21361 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21364 case DW_LNE_set_discriminator
:
21366 /* The discriminator is not interesting to the
21367 debugger; just ignore it. We still need to
21368 check its value though:
21369 if there are consecutive entries for the same
21370 (non-prologue) line we want to coalesce them.
21373 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21374 line_ptr
+= bytes_read
;
21376 state_machine
.handle_set_discriminator (discr
);
21380 complaint (_("mangled .debug_line section"));
21383 /* Make sure that we parsed the extended op correctly. If e.g.
21384 we expected a different address size than the producer used,
21385 we may have read the wrong number of bytes. */
21386 if (line_ptr
!= extended_end
)
21388 complaint (_("mangled .debug_line section"));
21393 state_machine
.handle_copy ();
21395 case DW_LNS_advance_pc
:
21398 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21399 line_ptr
+= bytes_read
;
21401 state_machine
.handle_advance_pc (adjust
);
21404 case DW_LNS_advance_line
:
21407 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21408 line_ptr
+= bytes_read
;
21410 state_machine
.handle_advance_line (line_delta
);
21413 case DW_LNS_set_file
:
21415 file_name_index file
21416 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21418 line_ptr
+= bytes_read
;
21420 state_machine
.handle_set_file (file
);
21423 case DW_LNS_set_column
:
21424 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21425 line_ptr
+= bytes_read
;
21427 case DW_LNS_negate_stmt
:
21428 state_machine
.handle_negate_stmt ();
21430 case DW_LNS_set_basic_block
:
21432 /* Add to the address register of the state machine the
21433 address increment value corresponding to special opcode
21434 255. I.e., this value is scaled by the minimum
21435 instruction length since special opcode 255 would have
21436 scaled the increment. */
21437 case DW_LNS_const_add_pc
:
21438 state_machine
.handle_const_add_pc ();
21440 case DW_LNS_fixed_advance_pc
:
21442 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21445 state_machine
.handle_fixed_advance_pc (addr_adj
);
21450 /* Unknown standard opcode, ignore it. */
21453 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21455 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21456 line_ptr
+= bytes_read
;
21463 dwarf2_debug_line_missing_end_sequence_complaint ();
21465 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21466 in which case we still finish recording the last line). */
21467 state_machine
.record_line (true);
21471 /* Decode the Line Number Program (LNP) for the given line_header
21472 structure and CU. The actual information extracted and the type
21473 of structures created from the LNP depends on the value of PST.
21475 1. If PST is NULL, then this procedure uses the data from the program
21476 to create all necessary symbol tables, and their linetables.
21478 2. If PST is not NULL, this procedure reads the program to determine
21479 the list of files included by the unit represented by PST, and
21480 builds all the associated partial symbol tables.
21482 FND holds the CU file name and directory, if known.
21483 It is used for relative paths in the line table.
21485 NOTE: It is important that psymtabs have the same file name (via
21486 strcmp) as the corresponding symtab. Since the directory is not
21487 used in the name of the symtab we don't use it in the name of the
21488 psymtabs we create. E.g. expand_line_sal requires this when
21489 finding psymtabs to expand. A good testcase for this is
21492 LOWPC is the lowest address in CU (or 0 if not known).
21494 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21495 for its PC<->lines mapping information. Otherwise only the filename
21496 table is read in. */
21499 dwarf_decode_lines (struct line_header
*lh
, const file_and_directory
&fnd
,
21500 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21501 CORE_ADDR lowpc
, int decode_mapping
)
21503 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21504 const int decode_for_pst_p
= (pst
!= NULL
);
21506 if (decode_mapping
)
21507 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21509 if (decode_for_pst_p
)
21511 /* Now that we're done scanning the Line Header Program, we can
21512 create the psymtab of each included file. */
21513 for (auto &file_entry
: lh
->file_names ())
21514 if (file_entry
.included_p
)
21516 gdb::unique_xmalloc_ptr
<char> name_holder
;
21517 const char *include_name
=
21518 compute_include_file_name (lh
, file_entry
, fnd
, &name_holder
);
21519 if (include_name
!= NULL
)
21520 dwarf2_create_include_psymtab
21521 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21522 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21528 /* Make sure a symtab is created for every file, even files
21529 which contain only variables (i.e. no code with associated
21531 buildsym_compunit
*builder
= cu
->get_builder ();
21532 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21534 for (auto &fe
: lh
->file_names ())
21536 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21537 if (builder
->get_current_subfile ()->symtab
== NULL
)
21539 builder
->get_current_subfile ()->symtab
21540 = allocate_symtab (cust
,
21541 builder
->get_current_subfile ()->name
);
21543 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21548 /* Start a subfile for DWARF. FILENAME is the name of the file and
21549 DIRNAME the name of the source directory which contains FILENAME
21550 or NULL if not known.
21551 This routine tries to keep line numbers from identical absolute and
21552 relative file names in a common subfile.
21554 Using the `list' example from the GDB testsuite, which resides in
21555 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21556 of /srcdir/list0.c yields the following debugging information for list0.c:
21558 DW_AT_name: /srcdir/list0.c
21559 DW_AT_comp_dir: /compdir
21560 files.files[0].name: list0.h
21561 files.files[0].dir: /srcdir
21562 files.files[1].name: list0.c
21563 files.files[1].dir: /srcdir
21565 The line number information for list0.c has to end up in a single
21566 subfile, so that `break /srcdir/list0.c:1' works as expected.
21567 start_subfile will ensure that this happens provided that we pass the
21568 concatenation of files.files[1].dir and files.files[1].name as the
21572 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21573 const char *dirname
)
21575 gdb::unique_xmalloc_ptr
<char> copy
;
21577 /* In order not to lose the line information directory,
21578 we concatenate it to the filename when it makes sense.
21579 Note that the Dwarf3 standard says (speaking of filenames in line
21580 information): ``The directory index is ignored for file names
21581 that represent full path names''. Thus ignoring dirname in the
21582 `else' branch below isn't an issue. */
21584 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21586 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21587 filename
= copy
.get ();
21590 cu
->get_builder ()->start_subfile (filename
);
21594 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21595 struct dwarf2_cu
*cu
)
21597 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21598 struct comp_unit_head
*cu_header
= &cu
->header
;
21600 /* NOTE drow/2003-01-30: There used to be a comment and some special
21601 code here to turn a symbol with DW_AT_external and a
21602 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21603 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21604 with some versions of binutils) where shared libraries could have
21605 relocations against symbols in their debug information - the
21606 minimal symbol would have the right address, but the debug info
21607 would not. It's no longer necessary, because we will explicitly
21608 apply relocations when we read in the debug information now. */
21610 /* A DW_AT_location attribute with no contents indicates that a
21611 variable has been optimized away. */
21612 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21614 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21618 /* Handle one degenerate form of location expression specially, to
21619 preserve GDB's previous behavior when section offsets are
21620 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21621 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21623 if (attr
->form_is_block ())
21625 struct dwarf_block
*block
= attr
->as_block ();
21627 if ((block
->data
[0] == DW_OP_addr
21628 && block
->size
== 1 + cu_header
->addr_size
)
21629 || ((block
->data
[0] == DW_OP_GNU_addr_index
21630 || block
->data
[0] == DW_OP_addrx
)
21632 == 1 + leb128_size (&block
->data
[1]))))
21634 unsigned int dummy
;
21636 if (block
->data
[0] == DW_OP_addr
)
21637 SET_SYMBOL_VALUE_ADDRESS
21638 (sym
, cu
->header
.read_address (objfile
->obfd
,
21642 SET_SYMBOL_VALUE_ADDRESS
21643 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21645 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21646 fixup_symbol_section (sym
, objfile
);
21647 SET_SYMBOL_VALUE_ADDRESS
21649 SYMBOL_VALUE_ADDRESS (sym
)
21650 + objfile
->section_offsets
[sym
->section_index ()]);
21655 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21656 expression evaluator, and use LOC_COMPUTED only when necessary
21657 (i.e. when the value of a register or memory location is
21658 referenced, or a thread-local block, etc.). Then again, it might
21659 not be worthwhile. I'm assuming that it isn't unless performance
21660 or memory numbers show me otherwise. */
21662 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21664 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21665 cu
->has_loclist
= true;
21668 /* Given a pointer to a DWARF information entry, figure out if we need
21669 to make a symbol table entry for it, and if so, create a new entry
21670 and return a pointer to it.
21671 If TYPE is NULL, determine symbol type from the die, otherwise
21672 used the passed type.
21673 If SPACE is not NULL, use it to hold the new symbol. If it is
21674 NULL, allocate a new symbol on the objfile's obstack. */
21676 static struct symbol
*
21677 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21678 struct symbol
*space
)
21680 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21681 struct objfile
*objfile
= per_objfile
->objfile
;
21682 struct gdbarch
*gdbarch
= objfile
->arch ();
21683 struct symbol
*sym
= NULL
;
21685 struct attribute
*attr
= NULL
;
21686 struct attribute
*attr2
= NULL
;
21687 CORE_ADDR baseaddr
;
21688 struct pending
**list_to_add
= NULL
;
21690 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21692 baseaddr
= objfile
->text_section_offset ();
21694 name
= dwarf2_name (die
, cu
);
21697 int suppress_add
= 0;
21702 sym
= new (&objfile
->objfile_obstack
) symbol
;
21703 OBJSTAT (objfile
, n_syms
++);
21705 /* Cache this symbol's name and the name's demangled form (if any). */
21706 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21707 /* Fortran does not have mangling standard and the mangling does differ
21708 between gfortran, iFort etc. */
21709 const char *physname
21710 = (cu
->per_cu
->lang
== language_fortran
21711 ? dwarf2_full_name (name
, die
, cu
)
21712 : dwarf2_physname (name
, die
, cu
));
21713 const char *linkagename
= dw2_linkage_name (die
, cu
);
21715 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21716 sym
->set_linkage_name (physname
);
21719 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21720 sym
->set_linkage_name (linkagename
);
21723 /* Handle DW_AT_artificial. */
21724 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
21725 if (attr
!= nullptr)
21726 sym
->artificial
= attr
->as_boolean ();
21728 /* Default assumptions.
21729 Use the passed type or decode it from the die. */
21730 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21731 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21733 SYMBOL_TYPE (sym
) = type
;
21735 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21736 attr
= dwarf2_attr (die
,
21737 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21739 if (attr
!= nullptr)
21740 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21742 attr
= dwarf2_attr (die
,
21743 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21745 if (attr
!= nullptr && attr
->is_nonnegative ())
21747 file_name_index file_index
21748 = (file_name_index
) attr
->as_nonnegative ();
21749 struct file_entry
*fe
;
21751 if (cu
->line_header
!= NULL
)
21752 fe
= cu
->line_header
->file_name_at (file_index
);
21757 complaint (_("file index out of range"));
21759 symbol_set_symtab (sym
, fe
->symtab
);
21765 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21766 if (attr
!= nullptr)
21770 addr
= attr
->as_address ();
21771 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21772 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21773 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21776 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21777 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21778 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21779 add_symbol_to_list (sym
, cu
->list_in_scope
);
21781 case DW_TAG_subprogram
:
21782 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21784 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21785 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21786 if ((attr2
!= nullptr && attr2
->as_boolean ())
21787 || cu
->per_cu
->lang
== language_ada
21788 || cu
->per_cu
->lang
== language_fortran
)
21790 /* Subprograms marked external are stored as a global symbol.
21791 Ada and Fortran subprograms, whether marked external or
21792 not, are always stored as a global symbol, because we want
21793 to be able to access them globally. For instance, we want
21794 to be able to break on a nested subprogram without having
21795 to specify the context. */
21796 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21800 list_to_add
= cu
->list_in_scope
;
21803 case DW_TAG_inlined_subroutine
:
21804 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21806 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21807 SYMBOL_INLINED (sym
) = 1;
21808 list_to_add
= cu
->list_in_scope
;
21810 case DW_TAG_template_value_param
:
21812 /* Fall through. */
21813 case DW_TAG_constant
:
21814 case DW_TAG_variable
:
21815 case DW_TAG_member
:
21816 /* Compilation with minimal debug info may result in
21817 variables with missing type entries. Change the
21818 misleading `void' type to something sensible. */
21819 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21820 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21822 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21823 /* In the case of DW_TAG_member, we should only be called for
21824 static const members. */
21825 if (die
->tag
== DW_TAG_member
)
21827 /* dwarf2_add_field uses die_is_declaration,
21828 so we do the same. */
21829 gdb_assert (die_is_declaration (die
, cu
));
21832 if (attr
!= nullptr)
21834 dwarf2_const_value (attr
, sym
, cu
);
21835 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21838 if (attr2
!= nullptr && attr2
->as_boolean ())
21839 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21841 list_to_add
= cu
->list_in_scope
;
21845 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21846 if (attr
!= nullptr)
21848 var_decode_location (attr
, sym
, cu
);
21849 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21851 /* Fortran explicitly imports any global symbols to the local
21852 scope by DW_TAG_common_block. */
21853 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21854 && die
->parent
->tag
== DW_TAG_common_block
)
21857 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21858 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21859 && !per_objfile
->per_bfd
->has_section_at_zero
)
21861 /* When a static variable is eliminated by the linker,
21862 the corresponding debug information is not stripped
21863 out, but the variable address is set to null;
21864 do not add such variables into symbol table. */
21866 else if (attr2
!= nullptr && attr2
->as_boolean ())
21868 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21869 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21870 && per_objfile
->per_bfd
->can_copy
)
21872 /* A global static variable might be subject to
21873 copy relocation. We first check for a local
21874 minsym, though, because maybe the symbol was
21875 marked hidden, in which case this would not
21877 bound_minimal_symbol found
21878 = (lookup_minimal_symbol_linkage
21879 (sym
->linkage_name (), objfile
));
21880 if (found
.minsym
!= nullptr)
21881 sym
->maybe_copied
= 1;
21884 /* A variable with DW_AT_external is never static,
21885 but it may be block-scoped. */
21887 = ((cu
->list_in_scope
21888 == cu
->get_builder ()->get_file_symbols ())
21889 ? cu
->get_builder ()->get_global_symbols ()
21890 : cu
->list_in_scope
);
21893 list_to_add
= cu
->list_in_scope
;
21897 /* We do not know the address of this symbol.
21898 If it is an external symbol and we have type information
21899 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21900 The address of the variable will then be determined from
21901 the minimal symbol table whenever the variable is
21903 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21905 /* Fortran explicitly imports any global symbols to the local
21906 scope by DW_TAG_common_block. */
21907 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21908 && die
->parent
->tag
== DW_TAG_common_block
)
21910 /* SYMBOL_CLASS doesn't matter here because
21911 read_common_block is going to reset it. */
21913 list_to_add
= cu
->list_in_scope
;
21915 else if (attr2
!= nullptr && attr2
->as_boolean ()
21916 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21918 /* A variable with DW_AT_external is never static, but it
21919 may be block-scoped. */
21921 = ((cu
->list_in_scope
21922 == cu
->get_builder ()->get_file_symbols ())
21923 ? cu
->get_builder ()->get_global_symbols ()
21924 : cu
->list_in_scope
);
21926 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21928 else if (!die_is_declaration (die
, cu
))
21930 /* Use the default LOC_OPTIMIZED_OUT class. */
21931 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21933 list_to_add
= cu
->list_in_scope
;
21937 case DW_TAG_formal_parameter
:
21939 /* If we are inside a function, mark this as an argument. If
21940 not, we might be looking at an argument to an inlined function
21941 when we do not have enough information to show inlined frames;
21942 pretend it's a local variable in that case so that the user can
21944 struct context_stack
*curr
21945 = cu
->get_builder ()->get_current_context_stack ();
21946 if (curr
!= nullptr && curr
->name
!= nullptr)
21947 SYMBOL_IS_ARGUMENT (sym
) = 1;
21948 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21949 if (attr
!= nullptr)
21951 var_decode_location (attr
, sym
, cu
);
21953 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21954 if (attr
!= nullptr)
21956 dwarf2_const_value (attr
, sym
, cu
);
21959 list_to_add
= cu
->list_in_scope
;
21962 case DW_TAG_unspecified_parameters
:
21963 /* From varargs functions; gdb doesn't seem to have any
21964 interest in this information, so just ignore it for now.
21967 case DW_TAG_template_type_param
:
21969 /* Fall through. */
21970 case DW_TAG_class_type
:
21971 case DW_TAG_interface_type
:
21972 case DW_TAG_structure_type
:
21973 case DW_TAG_union_type
:
21974 case DW_TAG_set_type
:
21975 case DW_TAG_enumeration_type
:
21976 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21977 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21980 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21981 really ever be static objects: otherwise, if you try
21982 to, say, break of a class's method and you're in a file
21983 which doesn't mention that class, it won't work unless
21984 the check for all static symbols in lookup_symbol_aux
21985 saves you. See the OtherFileClass tests in
21986 gdb.c++/namespace.exp. */
21990 buildsym_compunit
*builder
= cu
->get_builder ();
21992 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21993 && cu
->per_cu
->lang
== language_cplus
21994 ? builder
->get_global_symbols ()
21995 : cu
->list_in_scope
);
21997 /* The semantics of C++ state that "struct foo {
21998 ... }" also defines a typedef for "foo". */
21999 if (cu
->per_cu
->lang
== language_cplus
22000 || cu
->per_cu
->lang
== language_ada
22001 || cu
->per_cu
->lang
== language_d
22002 || cu
->per_cu
->lang
== language_rust
)
22004 /* The symbol's name is already allocated along
22005 with this objfile, so we don't need to
22006 duplicate it for the type. */
22007 if (SYMBOL_TYPE (sym
)->name () == 0)
22008 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22013 case DW_TAG_typedef
:
22014 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22015 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22016 list_to_add
= cu
->list_in_scope
;
22018 case DW_TAG_array_type
:
22019 case DW_TAG_base_type
:
22020 case DW_TAG_subrange_type
:
22021 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22022 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22023 list_to_add
= cu
->list_in_scope
;
22025 case DW_TAG_enumerator
:
22026 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22027 if (attr
!= nullptr)
22029 dwarf2_const_value (attr
, sym
, cu
);
22032 /* NOTE: carlton/2003-11-10: See comment above in the
22033 DW_TAG_class_type, etc. block. */
22036 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22037 && cu
->per_cu
->lang
== language_cplus
22038 ? cu
->get_builder ()->get_global_symbols ()
22039 : cu
->list_in_scope
);
22042 case DW_TAG_imported_declaration
:
22043 case DW_TAG_namespace
:
22044 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22045 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22047 case DW_TAG_module
:
22048 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22049 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22050 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22052 case DW_TAG_common_block
:
22053 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22054 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22055 add_symbol_to_list (sym
, cu
->list_in_scope
);
22058 /* Not a tag we recognize. Hopefully we aren't processing
22059 trash data, but since we must specifically ignore things
22060 we don't recognize, there is nothing else we should do at
22062 complaint (_("unsupported tag: '%s'"),
22063 dwarf_tag_name (die
->tag
));
22069 sym
->hash_next
= objfile
->template_symbols
;
22070 objfile
->template_symbols
= sym
;
22071 list_to_add
= NULL
;
22074 if (list_to_add
!= NULL
)
22075 add_symbol_to_list (sym
, list_to_add
);
22077 /* For the benefit of old versions of GCC, check for anonymous
22078 namespaces based on the demangled name. */
22079 if (!cu
->processing_has_namespace_info
22080 && cu
->per_cu
->lang
== language_cplus
)
22081 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22086 /* Given an attr with a DW_FORM_dataN value in host byte order,
22087 zero-extend it as appropriate for the symbol's type. The DWARF
22088 standard (v4) is not entirely clear about the meaning of using
22089 DW_FORM_dataN for a constant with a signed type, where the type is
22090 wider than the data. The conclusion of a discussion on the DWARF
22091 list was that this is unspecified. We choose to always zero-extend
22092 because that is the interpretation long in use by GCC. */
22095 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22096 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22098 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22099 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22100 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22101 LONGEST l
= attr
->constant_value (0);
22103 if (bits
< sizeof (*value
) * 8)
22105 l
&= ((LONGEST
) 1 << bits
) - 1;
22108 else if (bits
== sizeof (*value
) * 8)
22112 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22113 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22120 /* Read a constant value from an attribute. Either set *VALUE, or if
22121 the value does not fit in *VALUE, set *BYTES - either already
22122 allocated on the objfile obstack, or newly allocated on OBSTACK,
22123 or, set *BATON, if we translated the constant to a location
22127 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22128 const char *name
, struct obstack
*obstack
,
22129 struct dwarf2_cu
*cu
,
22130 LONGEST
*value
, const gdb_byte
**bytes
,
22131 struct dwarf2_locexpr_baton
**baton
)
22133 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22134 struct objfile
*objfile
= per_objfile
->objfile
;
22135 struct comp_unit_head
*cu_header
= &cu
->header
;
22136 struct dwarf_block
*blk
;
22137 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22138 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22144 switch (attr
->form
)
22147 case DW_FORM_addrx
:
22148 case DW_FORM_GNU_addr_index
:
22152 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22153 dwarf2_const_value_length_mismatch_complaint (name
,
22154 cu_header
->addr_size
,
22155 TYPE_LENGTH (type
));
22156 /* Symbols of this form are reasonably rare, so we just
22157 piggyback on the existing location code rather than writing
22158 a new implementation of symbol_computed_ops. */
22159 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22160 (*baton
)->per_objfile
= per_objfile
;
22161 (*baton
)->per_cu
= cu
->per_cu
;
22162 gdb_assert ((*baton
)->per_cu
);
22164 (*baton
)->size
= 2 + cu_header
->addr_size
;
22165 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22166 (*baton
)->data
= data
;
22168 data
[0] = DW_OP_addr
;
22169 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22170 byte_order
, attr
->as_address ());
22171 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22174 case DW_FORM_string
:
22177 case DW_FORM_GNU_str_index
:
22178 case DW_FORM_GNU_strp_alt
:
22179 /* The string is already allocated on the objfile obstack, point
22181 *bytes
= (const gdb_byte
*) attr
->as_string ();
22183 case DW_FORM_block1
:
22184 case DW_FORM_block2
:
22185 case DW_FORM_block4
:
22186 case DW_FORM_block
:
22187 case DW_FORM_exprloc
:
22188 case DW_FORM_data16
:
22189 blk
= attr
->as_block ();
22190 if (TYPE_LENGTH (type
) != blk
->size
)
22191 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22192 TYPE_LENGTH (type
));
22193 *bytes
= blk
->data
;
22196 /* The DW_AT_const_value attributes are supposed to carry the
22197 symbol's value "represented as it would be on the target
22198 architecture." By the time we get here, it's already been
22199 converted to host endianness, so we just need to sign- or
22200 zero-extend it as appropriate. */
22201 case DW_FORM_data1
:
22202 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22204 case DW_FORM_data2
:
22205 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22207 case DW_FORM_data4
:
22208 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22210 case DW_FORM_data8
:
22211 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22214 case DW_FORM_sdata
:
22215 case DW_FORM_implicit_const
:
22216 *value
= attr
->as_signed ();
22219 case DW_FORM_udata
:
22220 *value
= attr
->as_unsigned ();
22224 complaint (_("unsupported const value attribute form: '%s'"),
22225 dwarf_form_name (attr
->form
));
22232 /* Copy constant value from an attribute to a symbol. */
22235 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22236 struct dwarf2_cu
*cu
)
22238 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22240 const gdb_byte
*bytes
;
22241 struct dwarf2_locexpr_baton
*baton
;
22243 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22244 sym
->print_name (),
22245 &objfile
->objfile_obstack
, cu
,
22246 &value
, &bytes
, &baton
);
22250 SYMBOL_LOCATION_BATON (sym
) = baton
;
22251 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22253 else if (bytes
!= NULL
)
22255 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22256 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22260 SYMBOL_VALUE (sym
) = value
;
22261 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22265 /* Return the type of the die in question using its DW_AT_type attribute. */
22267 static struct type
*
22268 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22270 struct attribute
*type_attr
;
22272 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22275 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22276 /* A missing DW_AT_type represents a void type. */
22277 return objfile_type (objfile
)->builtin_void
;
22280 return lookup_die_type (die
, type_attr
, cu
);
22283 /* True iff CU's producer generates GNAT Ada auxiliary information
22284 that allows to find parallel types through that information instead
22285 of having to do expensive parallel lookups by type name. */
22288 need_gnat_info (struct dwarf2_cu
*cu
)
22290 /* Assume that the Ada compiler was GNAT, which always produces
22291 the auxiliary information. */
22292 return (cu
->per_cu
->lang
== language_ada
);
22295 /* Return the auxiliary type of the die in question using its
22296 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22297 attribute is not present. */
22299 static struct type
*
22300 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22302 struct attribute
*type_attr
;
22304 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22308 return lookup_die_type (die
, type_attr
, cu
);
22311 /* If DIE has a descriptive_type attribute, then set the TYPE's
22312 descriptive type accordingly. */
22315 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22316 struct dwarf2_cu
*cu
)
22318 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22320 if (descriptive_type
)
22322 ALLOCATE_GNAT_AUX_TYPE (type
);
22323 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22327 /* Return the containing type of the die in question using its
22328 DW_AT_containing_type attribute. */
22330 static struct type
*
22331 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22333 struct attribute
*type_attr
;
22334 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22336 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22338 error (_("Dwarf Error: Problem turning containing type into gdb type "
22339 "[in module %s]"), objfile_name (objfile
));
22341 return lookup_die_type (die
, type_attr
, cu
);
22344 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22346 static struct type
*
22347 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22349 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22350 struct objfile
*objfile
= per_objfile
->objfile
;
22353 std::string message
22354 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22355 objfile_name (objfile
),
22356 sect_offset_str (cu
->header
.sect_off
),
22357 sect_offset_str (die
->sect_off
));
22358 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22360 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22363 /* Look up the type of DIE in CU using its type attribute ATTR.
22364 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22365 DW_AT_containing_type.
22366 If there is no type substitute an error marker. */
22368 static struct type
*
22369 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22370 struct dwarf2_cu
*cu
)
22372 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22373 struct objfile
*objfile
= per_objfile
->objfile
;
22374 struct type
*this_type
;
22376 gdb_assert (attr
->name
== DW_AT_type
22377 || attr
->name
== DW_AT_GNAT_descriptive_type
22378 || attr
->name
== DW_AT_containing_type
);
22380 /* First see if we have it cached. */
22382 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22384 struct dwarf2_per_cu_data
*per_cu
;
22385 sect_offset sect_off
= attr
->get_ref_die_offset ();
22387 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22388 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22390 else if (attr
->form_is_ref ())
22392 sect_offset sect_off
= attr
->get_ref_die_offset ();
22394 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22396 else if (attr
->form
== DW_FORM_ref_sig8
)
22398 ULONGEST signature
= attr
->as_signature ();
22400 return get_signatured_type (die
, signature
, cu
);
22404 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22405 " at %s [in module %s]"),
22406 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22407 objfile_name (objfile
));
22408 return build_error_marker_type (cu
, die
);
22411 /* If not cached we need to read it in. */
22413 if (this_type
== NULL
)
22415 struct die_info
*type_die
= NULL
;
22416 struct dwarf2_cu
*type_cu
= cu
;
22418 if (attr
->form_is_ref ())
22419 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22420 if (type_die
== NULL
)
22421 return build_error_marker_type (cu
, die
);
22422 /* If we find the type now, it's probably because the type came
22423 from an inter-CU reference and the type's CU got expanded before
22425 this_type
= read_type_die (type_die
, type_cu
);
22428 /* If we still don't have a type use an error marker. */
22430 if (this_type
== NULL
)
22431 return build_error_marker_type (cu
, die
);
22436 /* Return the type in DIE, CU.
22437 Returns NULL for invalid types.
22439 This first does a lookup in die_type_hash,
22440 and only reads the die in if necessary.
22442 NOTE: This can be called when reading in partial or full symbols. */
22444 static struct type
*
22445 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22447 struct type
*this_type
;
22449 this_type
= get_die_type (die
, cu
);
22453 return read_type_die_1 (die
, cu
);
22456 /* Read the type in DIE, CU.
22457 Returns NULL for invalid types. */
22459 static struct type
*
22460 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22462 struct type
*this_type
= NULL
;
22466 case DW_TAG_class_type
:
22467 case DW_TAG_interface_type
:
22468 case DW_TAG_structure_type
:
22469 case DW_TAG_union_type
:
22470 this_type
= read_structure_type (die
, cu
);
22472 case DW_TAG_enumeration_type
:
22473 this_type
= read_enumeration_type (die
, cu
);
22475 case DW_TAG_subprogram
:
22476 case DW_TAG_subroutine_type
:
22477 case DW_TAG_inlined_subroutine
:
22478 this_type
= read_subroutine_type (die
, cu
);
22480 case DW_TAG_array_type
:
22481 this_type
= read_array_type (die
, cu
);
22483 case DW_TAG_set_type
:
22484 this_type
= read_set_type (die
, cu
);
22486 case DW_TAG_pointer_type
:
22487 this_type
= read_tag_pointer_type (die
, cu
);
22489 case DW_TAG_ptr_to_member_type
:
22490 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22492 case DW_TAG_reference_type
:
22493 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22495 case DW_TAG_rvalue_reference_type
:
22496 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22498 case DW_TAG_const_type
:
22499 this_type
= read_tag_const_type (die
, cu
);
22501 case DW_TAG_volatile_type
:
22502 this_type
= read_tag_volatile_type (die
, cu
);
22504 case DW_TAG_restrict_type
:
22505 this_type
= read_tag_restrict_type (die
, cu
);
22507 case DW_TAG_string_type
:
22508 this_type
= read_tag_string_type (die
, cu
);
22510 case DW_TAG_typedef
:
22511 this_type
= read_typedef (die
, cu
);
22513 case DW_TAG_subrange_type
:
22514 this_type
= read_subrange_type (die
, cu
);
22516 case DW_TAG_base_type
:
22517 this_type
= read_base_type (die
, cu
);
22519 case DW_TAG_unspecified_type
:
22520 this_type
= read_unspecified_type (die
, cu
);
22522 case DW_TAG_namespace
:
22523 this_type
= read_namespace_type (die
, cu
);
22525 case DW_TAG_module
:
22526 this_type
= read_module_type (die
, cu
);
22528 case DW_TAG_atomic_type
:
22529 this_type
= read_tag_atomic_type (die
, cu
);
22532 complaint (_("unexpected tag in read_type_die: '%s'"),
22533 dwarf_tag_name (die
->tag
));
22540 /* See if we can figure out if the class lives in a namespace. We do
22541 this by looking for a member function; its demangled name will
22542 contain namespace info, if there is any.
22543 Return the computed name or NULL.
22544 Space for the result is allocated on the objfile's obstack.
22545 This is the full-die version of guess_partial_die_structure_name.
22546 In this case we know DIE has no useful parent. */
22548 static const char *
22549 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22551 struct die_info
*spec_die
;
22552 struct dwarf2_cu
*spec_cu
;
22553 struct die_info
*child
;
22554 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22557 spec_die
= die_specification (die
, &spec_cu
);
22558 if (spec_die
!= NULL
)
22564 for (child
= die
->child
;
22566 child
= child
->sibling
)
22568 if (child
->tag
== DW_TAG_subprogram
)
22570 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22572 if (linkage_name
!= NULL
)
22574 gdb::unique_xmalloc_ptr
<char> actual_name
22575 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22576 const char *name
= NULL
;
22578 if (actual_name
!= NULL
)
22580 const char *die_name
= dwarf2_name (die
, cu
);
22582 if (die_name
!= NULL
22583 && strcmp (die_name
, actual_name
.get ()) != 0)
22585 /* Strip off the class name from the full name.
22586 We want the prefix. */
22587 int die_name_len
= strlen (die_name
);
22588 int actual_name_len
= strlen (actual_name
.get ());
22589 const char *ptr
= actual_name
.get ();
22591 /* Test for '::' as a sanity check. */
22592 if (actual_name_len
> die_name_len
+ 2
22593 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22594 name
= obstack_strndup (
22595 &objfile
->per_bfd
->storage_obstack
,
22596 ptr
, actual_name_len
- die_name_len
- 2);
22607 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22608 prefix part in such case. See
22609 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22611 static const char *
22612 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22614 struct attribute
*attr
;
22617 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22618 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22621 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22624 attr
= dw2_linkage_name_attr (die
, cu
);
22625 const char *attr_name
= attr
->as_string ();
22626 if (attr
== NULL
|| attr_name
== NULL
)
22629 /* dwarf2_name had to be already called. */
22630 gdb_assert (attr
->canonical_string_p ());
22632 /* Strip the base name, keep any leading namespaces/classes. */
22633 base
= strrchr (attr_name
, ':');
22634 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22637 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22638 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22640 &base
[-1] - attr_name
);
22643 /* Return the name of the namespace/class that DIE is defined within,
22644 or "" if we can't tell. The caller should not xfree the result.
22646 For example, if we're within the method foo() in the following
22656 then determine_prefix on foo's die will return "N::C". */
22658 static const char *
22659 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22661 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22662 struct die_info
*parent
, *spec_die
;
22663 struct dwarf2_cu
*spec_cu
;
22664 struct type
*parent_type
;
22665 const char *retval
;
22667 if (cu
->per_cu
->lang
!= language_cplus
22668 && cu
->per_cu
->lang
!= language_fortran
22669 && cu
->per_cu
->lang
!= language_d
22670 && cu
->per_cu
->lang
!= language_rust
)
22673 retval
= anonymous_struct_prefix (die
, cu
);
22677 /* We have to be careful in the presence of DW_AT_specification.
22678 For example, with GCC 3.4, given the code
22682 // Definition of N::foo.
22686 then we'll have a tree of DIEs like this:
22688 1: DW_TAG_compile_unit
22689 2: DW_TAG_namespace // N
22690 3: DW_TAG_subprogram // declaration of N::foo
22691 4: DW_TAG_subprogram // definition of N::foo
22692 DW_AT_specification // refers to die #3
22694 Thus, when processing die #4, we have to pretend that we're in
22695 the context of its DW_AT_specification, namely the contex of die
22698 spec_die
= die_specification (die
, &spec_cu
);
22699 if (spec_die
== NULL
)
22700 parent
= die
->parent
;
22703 parent
= spec_die
->parent
;
22707 if (parent
== NULL
)
22709 else if (parent
->building_fullname
)
22712 const char *parent_name
;
22714 /* It has been seen on RealView 2.2 built binaries,
22715 DW_TAG_template_type_param types actually _defined_ as
22716 children of the parent class:
22719 template class <class Enum> Class{};
22720 Class<enum E> class_e;
22722 1: DW_TAG_class_type (Class)
22723 2: DW_TAG_enumeration_type (E)
22724 3: DW_TAG_enumerator (enum1:0)
22725 3: DW_TAG_enumerator (enum2:1)
22727 2: DW_TAG_template_type_param
22728 DW_AT_type DW_FORM_ref_udata (E)
22730 Besides being broken debug info, it can put GDB into an
22731 infinite loop. Consider:
22733 When we're building the full name for Class<E>, we'll start
22734 at Class, and go look over its template type parameters,
22735 finding E. We'll then try to build the full name of E, and
22736 reach here. We're now trying to build the full name of E,
22737 and look over the parent DIE for containing scope. In the
22738 broken case, if we followed the parent DIE of E, we'd again
22739 find Class, and once again go look at its template type
22740 arguments, etc., etc. Simply don't consider such parent die
22741 as source-level parent of this die (it can't be, the language
22742 doesn't allow it), and break the loop here. */
22743 name
= dwarf2_name (die
, cu
);
22744 parent_name
= dwarf2_name (parent
, cu
);
22745 complaint (_("template param type '%s' defined within parent '%s'"),
22746 name
? name
: "<unknown>",
22747 parent_name
? parent_name
: "<unknown>");
22751 switch (parent
->tag
)
22753 case DW_TAG_namespace
:
22754 parent_type
= read_type_die (parent
, cu
);
22755 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22756 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22757 Work around this problem here. */
22758 if (cu
->per_cu
->lang
== language_cplus
22759 && strcmp (parent_type
->name (), "::") == 0)
22761 /* We give a name to even anonymous namespaces. */
22762 return parent_type
->name ();
22763 case DW_TAG_class_type
:
22764 case DW_TAG_interface_type
:
22765 case DW_TAG_structure_type
:
22766 case DW_TAG_union_type
:
22767 case DW_TAG_module
:
22768 parent_type
= read_type_die (parent
, cu
);
22769 if (parent_type
->name () != NULL
)
22770 return parent_type
->name ();
22772 /* An anonymous structure is only allowed non-static data
22773 members; no typedefs, no member functions, et cetera.
22774 So it does not need a prefix. */
22776 case DW_TAG_compile_unit
:
22777 case DW_TAG_partial_unit
:
22778 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22779 if (cu
->per_cu
->lang
== language_cplus
22780 && !per_objfile
->per_bfd
->types
.empty ()
22781 && die
->child
!= NULL
22782 && (die
->tag
== DW_TAG_class_type
22783 || die
->tag
== DW_TAG_structure_type
22784 || die
->tag
== DW_TAG_union_type
))
22786 const char *name
= guess_full_die_structure_name (die
, cu
);
22791 case DW_TAG_subprogram
:
22792 /* Nested subroutines in Fortran get a prefix with the name
22793 of the parent's subroutine. */
22794 if (cu
->per_cu
->lang
== language_fortran
)
22796 if ((die
->tag
== DW_TAG_subprogram
)
22797 && (dwarf2_name (parent
, cu
) != NULL
))
22798 return dwarf2_name (parent
, cu
);
22801 case DW_TAG_enumeration_type
:
22802 parent_type
= read_type_die (parent
, cu
);
22803 if (parent_type
->is_declared_class ())
22805 if (parent_type
->name () != NULL
)
22806 return parent_type
->name ();
22809 /* Fall through. */
22811 return determine_prefix (parent
, cu
);
22815 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22816 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22817 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22818 an obconcat, otherwise allocate storage for the result. The CU argument is
22819 used to determine the language and hence, the appropriate separator. */
22821 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22824 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22825 int physname
, struct dwarf2_cu
*cu
)
22827 const char *lead
= "";
22830 if (suffix
== NULL
|| suffix
[0] == '\0'
22831 || prefix
== NULL
|| prefix
[0] == '\0')
22833 else if (cu
->per_cu
->lang
== language_d
)
22835 /* For D, the 'main' function could be defined in any module, but it
22836 should never be prefixed. */
22837 if (strcmp (suffix
, "D main") == 0)
22845 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22847 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22848 DW_AT_MIPS_linkage_name is preferred and used instead. */
22856 if (prefix
== NULL
)
22858 if (suffix
== NULL
)
22865 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22867 strcpy (retval
, lead
);
22868 strcat (retval
, prefix
);
22869 strcat (retval
, sep
);
22870 strcat (retval
, suffix
);
22875 /* We have an obstack. */
22876 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22880 /* Get name of a die, return NULL if not found. */
22882 static const char *
22883 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22884 struct objfile
*objfile
)
22886 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22888 gdb::unique_xmalloc_ptr
<char> canon_name
22889 = cp_canonicalize_string (name
);
22891 if (canon_name
!= nullptr)
22892 name
= objfile
->intern (canon_name
.get ());
22898 /* Get name of a die, return NULL if not found.
22899 Anonymous namespaces are converted to their magic string. */
22901 static const char *
22902 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22904 struct attribute
*attr
;
22905 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22907 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22908 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22909 if (attr_name
== nullptr
22910 && die
->tag
!= DW_TAG_namespace
22911 && die
->tag
!= DW_TAG_class_type
22912 && die
->tag
!= DW_TAG_interface_type
22913 && die
->tag
!= DW_TAG_structure_type
22914 && die
->tag
!= DW_TAG_union_type
)
22919 case DW_TAG_compile_unit
:
22920 case DW_TAG_partial_unit
:
22921 /* Compilation units have a DW_AT_name that is a filename, not
22922 a source language identifier. */
22923 case DW_TAG_enumeration_type
:
22924 case DW_TAG_enumerator
:
22925 /* These tags always have simple identifiers already; no need
22926 to canonicalize them. */
22929 case DW_TAG_namespace
:
22930 if (attr_name
!= nullptr)
22932 return CP_ANONYMOUS_NAMESPACE_STR
;
22934 case DW_TAG_class_type
:
22935 case DW_TAG_interface_type
:
22936 case DW_TAG_structure_type
:
22937 case DW_TAG_union_type
:
22938 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22939 structures or unions. These were of the form "._%d" in GCC 4.1,
22940 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22941 and GCC 4.4. We work around this problem by ignoring these. */
22942 if (attr_name
!= nullptr
22943 && (startswith (attr_name
, "._")
22944 || startswith (attr_name
, "<anonymous")))
22947 /* GCC might emit a nameless typedef that has a linkage name. See
22948 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22949 if (!attr
|| attr_name
== NULL
)
22951 attr
= dw2_linkage_name_attr (die
, cu
);
22952 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22953 if (attr
== NULL
|| attr_name
== NULL
)
22956 /* Avoid demangling attr_name the second time on a second
22957 call for the same DIE. */
22958 if (!attr
->canonical_string_p ())
22960 gdb::unique_xmalloc_ptr
<char> demangled
22961 (gdb_demangle (attr_name
, DMGL_TYPES
));
22962 if (demangled
== nullptr)
22965 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22966 attr_name
= attr
->as_string ();
22969 /* Strip any leading namespaces/classes, keep only the
22970 base name. DW_AT_name for named DIEs does not
22971 contain the prefixes. */
22972 const char *base
= strrchr (attr_name
, ':');
22973 if (base
&& base
> attr_name
&& base
[-1] == ':')
22984 if (!attr
->canonical_string_p ())
22985 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22987 return attr
->as_string ();
22990 /* Return the die that this die in an extension of, or NULL if there
22991 is none. *EXT_CU is the CU containing DIE on input, and the CU
22992 containing the return value on output. */
22994 static struct die_info
*
22995 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22997 struct attribute
*attr
;
22999 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23003 return follow_die_ref (die
, attr
, ext_cu
);
23007 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23011 print_spaces (indent
, f
);
23012 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23013 dwarf_tag_name (die
->tag
), die
->abbrev
,
23014 sect_offset_str (die
->sect_off
));
23016 if (die
->parent
!= NULL
)
23018 print_spaces (indent
, f
);
23019 fprintf_unfiltered (f
, " parent at offset: %s\n",
23020 sect_offset_str (die
->parent
->sect_off
));
23023 print_spaces (indent
, f
);
23024 fprintf_unfiltered (f
, " has children: %s\n",
23025 dwarf_bool_name (die
->child
!= NULL
));
23027 print_spaces (indent
, f
);
23028 fprintf_unfiltered (f
, " attributes:\n");
23030 for (i
= 0; i
< die
->num_attrs
; ++i
)
23032 print_spaces (indent
, f
);
23033 fprintf_unfiltered (f
, " %s (%s) ",
23034 dwarf_attr_name (die
->attrs
[i
].name
),
23035 dwarf_form_name (die
->attrs
[i
].form
));
23037 switch (die
->attrs
[i
].form
)
23040 case DW_FORM_addrx
:
23041 case DW_FORM_GNU_addr_index
:
23042 fprintf_unfiltered (f
, "address: ");
23043 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23045 case DW_FORM_block2
:
23046 case DW_FORM_block4
:
23047 case DW_FORM_block
:
23048 case DW_FORM_block1
:
23049 fprintf_unfiltered (f
, "block: size %s",
23050 pulongest (die
->attrs
[i
].as_block ()->size
));
23052 case DW_FORM_exprloc
:
23053 fprintf_unfiltered (f
, "expression: size %s",
23054 pulongest (die
->attrs
[i
].as_block ()->size
));
23056 case DW_FORM_data16
:
23057 fprintf_unfiltered (f
, "constant of 16 bytes");
23059 case DW_FORM_ref_addr
:
23060 fprintf_unfiltered (f
, "ref address: ");
23061 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23063 case DW_FORM_GNU_ref_alt
:
23064 fprintf_unfiltered (f
, "alt ref address: ");
23065 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23071 case DW_FORM_ref_udata
:
23072 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23073 (long) (die
->attrs
[i
].as_unsigned ()));
23075 case DW_FORM_data1
:
23076 case DW_FORM_data2
:
23077 case DW_FORM_data4
:
23078 case DW_FORM_data8
:
23079 case DW_FORM_udata
:
23080 fprintf_unfiltered (f
, "constant: %s",
23081 pulongest (die
->attrs
[i
].as_unsigned ()));
23083 case DW_FORM_sec_offset
:
23084 fprintf_unfiltered (f
, "section offset: %s",
23085 pulongest (die
->attrs
[i
].as_unsigned ()));
23087 case DW_FORM_ref_sig8
:
23088 fprintf_unfiltered (f
, "signature: %s",
23089 hex_string (die
->attrs
[i
].as_signature ()));
23091 case DW_FORM_string
:
23093 case DW_FORM_line_strp
:
23095 case DW_FORM_GNU_str_index
:
23096 case DW_FORM_GNU_strp_alt
:
23097 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23098 die
->attrs
[i
].as_string ()
23099 ? die
->attrs
[i
].as_string () : "",
23100 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23103 if (die
->attrs
[i
].as_boolean ())
23104 fprintf_unfiltered (f
, "flag: TRUE");
23106 fprintf_unfiltered (f
, "flag: FALSE");
23108 case DW_FORM_flag_present
:
23109 fprintf_unfiltered (f
, "flag: TRUE");
23111 case DW_FORM_indirect
:
23112 /* The reader will have reduced the indirect form to
23113 the "base form" so this form should not occur. */
23114 fprintf_unfiltered (f
,
23115 "unexpected attribute form: DW_FORM_indirect");
23117 case DW_FORM_sdata
:
23118 case DW_FORM_implicit_const
:
23119 fprintf_unfiltered (f
, "constant: %s",
23120 plongest (die
->attrs
[i
].as_signed ()));
23123 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23124 die
->attrs
[i
].form
);
23127 fprintf_unfiltered (f
, "\n");
23132 dump_die_for_error (struct die_info
*die
)
23134 dump_die_shallow (gdb_stderr
, 0, die
);
23138 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23140 int indent
= level
* 4;
23142 gdb_assert (die
!= NULL
);
23144 if (level
>= max_level
)
23147 dump_die_shallow (f
, indent
, die
);
23149 if (die
->child
!= NULL
)
23151 print_spaces (indent
, f
);
23152 fprintf_unfiltered (f
, " Children:");
23153 if (level
+ 1 < max_level
)
23155 fprintf_unfiltered (f
, "\n");
23156 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23160 fprintf_unfiltered (f
,
23161 " [not printed, max nesting level reached]\n");
23165 if (die
->sibling
!= NULL
&& level
> 0)
23167 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23171 /* This is called from the pdie macro in gdbinit.in.
23172 It's not static so gcc will keep a copy callable from gdb. */
23175 dump_die (struct die_info
*die
, int max_level
)
23177 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23181 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23185 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23186 to_underlying (die
->sect_off
),
23192 /* Follow reference or signature attribute ATTR of SRC_DIE.
23193 On entry *REF_CU is the CU of SRC_DIE.
23194 On exit *REF_CU is the CU of the result. */
23196 static struct die_info
*
23197 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23198 struct dwarf2_cu
**ref_cu
)
23200 struct die_info
*die
;
23202 if (attr
->form_is_ref ())
23203 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23204 else if (attr
->form
== DW_FORM_ref_sig8
)
23205 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23208 dump_die_for_error (src_die
);
23209 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23210 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23216 /* Follow reference OFFSET.
23217 On entry *REF_CU is the CU of the source die referencing OFFSET.
23218 On exit *REF_CU is the CU of the result.
23219 Returns NULL if OFFSET is invalid. */
23221 static struct die_info
*
23222 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23223 struct dwarf2_cu
**ref_cu
)
23225 struct die_info temp_die
;
23226 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23227 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23229 gdb_assert (cu
->per_cu
!= NULL
);
23233 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23234 "source CU contains target offset: %d",
23235 sect_offset_str (cu
->per_cu
->sect_off
),
23236 sect_offset_str (sect_off
),
23237 cu
->header
.offset_in_cu_p (sect_off
));
23239 if (cu
->per_cu
->is_debug_types
)
23241 /* .debug_types CUs cannot reference anything outside their CU.
23242 If they need to, they have to reference a signatured type via
23243 DW_FORM_ref_sig8. */
23244 if (!cu
->header
.offset_in_cu_p (sect_off
))
23247 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23248 || !cu
->header
.offset_in_cu_p (sect_off
))
23250 struct dwarf2_per_cu_data
*per_cu
;
23252 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23255 dwarf_read_debug_printf_v ("target CU offset: %s, "
23256 "target CU DIEs loaded: %d",
23257 sect_offset_str (per_cu
->sect_off
),
23258 per_objfile
->get_cu (per_cu
) != nullptr);
23260 /* If necessary, add it to the queue and load its DIEs.
23262 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23263 it doesn't mean they are currently loaded. Since we require them
23264 to be loaded, we must check for ourselves. */
23265 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23266 || per_objfile
->get_cu (per_cu
) == nullptr)
23267 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23268 false, cu
->per_cu
->lang
);
23270 target_cu
= per_objfile
->get_cu (per_cu
);
23271 gdb_assert (target_cu
!= nullptr);
23273 else if (cu
->dies
== NULL
)
23275 /* We're loading full DIEs during partial symbol reading. */
23276 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23277 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23281 *ref_cu
= target_cu
;
23282 temp_die
.sect_off
= sect_off
;
23284 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23286 to_underlying (sect_off
));
23289 /* Follow reference attribute ATTR of SRC_DIE.
23290 On entry *REF_CU is the CU of SRC_DIE.
23291 On exit *REF_CU is the CU of the result. */
23293 static struct die_info
*
23294 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23295 struct dwarf2_cu
**ref_cu
)
23297 sect_offset sect_off
= attr
->get_ref_die_offset ();
23298 struct dwarf2_cu
*cu
= *ref_cu
;
23299 struct die_info
*die
;
23301 die
= follow_die_offset (sect_off
,
23302 (attr
->form
== DW_FORM_GNU_ref_alt
23303 || cu
->per_cu
->is_dwz
),
23306 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23307 "at %s [in module %s]"),
23308 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23309 objfile_name (cu
->per_objfile
->objfile
));
23316 struct dwarf2_locexpr_baton
23317 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23318 dwarf2_per_cu_data
*per_cu
,
23319 dwarf2_per_objfile
*per_objfile
,
23320 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23321 bool resolve_abstract_p
)
23323 struct die_info
*die
;
23324 struct attribute
*attr
;
23325 struct dwarf2_locexpr_baton retval
;
23326 struct objfile
*objfile
= per_objfile
->objfile
;
23328 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23330 cu
= load_cu (per_cu
, per_objfile
, false);
23334 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23335 Instead just throw an error, not much else we can do. */
23336 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23337 sect_offset_str (sect_off
), objfile_name (objfile
));
23340 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23342 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23343 sect_offset_str (sect_off
), objfile_name (objfile
));
23345 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23346 if (!attr
&& resolve_abstract_p
23347 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23348 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23350 CORE_ADDR pc
= get_frame_pc ();
23351 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23352 struct gdbarch
*gdbarch
= objfile
->arch ();
23354 for (const auto &cand_off
23355 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23357 struct dwarf2_cu
*cand_cu
= cu
;
23358 struct die_info
*cand
23359 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23362 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23365 CORE_ADDR pc_low
, pc_high
;
23366 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23367 if (pc_low
== ((CORE_ADDR
) -1))
23369 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23370 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23371 if (!(pc_low
<= pc
&& pc
< pc_high
))
23375 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23382 /* DWARF: "If there is no such attribute, then there is no effect.".
23383 DATA is ignored if SIZE is 0. */
23385 retval
.data
= NULL
;
23388 else if (attr
->form_is_section_offset ())
23390 struct dwarf2_loclist_baton loclist_baton
;
23391 CORE_ADDR pc
= get_frame_pc ();
23394 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23396 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23398 retval
.size
= size
;
23402 if (!attr
->form_is_block ())
23403 error (_("Dwarf Error: DIE at %s referenced in module %s "
23404 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23405 sect_offset_str (sect_off
), objfile_name (objfile
));
23407 struct dwarf_block
*block
= attr
->as_block ();
23408 retval
.data
= block
->data
;
23409 retval
.size
= block
->size
;
23411 retval
.per_objfile
= per_objfile
;
23412 retval
.per_cu
= cu
->per_cu
;
23414 per_objfile
->age_comp_units ();
23421 struct dwarf2_locexpr_baton
23422 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23423 dwarf2_per_cu_data
*per_cu
,
23424 dwarf2_per_objfile
*per_objfile
,
23425 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23427 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23429 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23433 /* Write a constant of a given type as target-ordered bytes into
23436 static const gdb_byte
*
23437 write_constant_as_bytes (struct obstack
*obstack
,
23438 enum bfd_endian byte_order
,
23445 *len
= TYPE_LENGTH (type
);
23446 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23447 store_unsigned_integer (result
, *len
, byte_order
, value
);
23455 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23456 dwarf2_per_cu_data
*per_cu
,
23457 dwarf2_per_objfile
*per_objfile
,
23461 struct die_info
*die
;
23462 struct attribute
*attr
;
23463 const gdb_byte
*result
= NULL
;
23466 enum bfd_endian byte_order
;
23467 struct objfile
*objfile
= per_objfile
->objfile
;
23469 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23471 cu
= load_cu (per_cu
, per_objfile
, false);
23475 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23476 Instead just throw an error, not much else we can do. */
23477 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23478 sect_offset_str (sect_off
), objfile_name (objfile
));
23481 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23483 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23484 sect_offset_str (sect_off
), objfile_name (objfile
));
23486 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23490 byte_order
= (bfd_big_endian (objfile
->obfd
)
23491 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23493 switch (attr
->form
)
23496 case DW_FORM_addrx
:
23497 case DW_FORM_GNU_addr_index
:
23501 *len
= cu
->header
.addr_size
;
23502 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23503 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23507 case DW_FORM_string
:
23510 case DW_FORM_GNU_str_index
:
23511 case DW_FORM_GNU_strp_alt
:
23512 /* The string is already allocated on the objfile obstack, point
23515 const char *attr_name
= attr
->as_string ();
23516 result
= (const gdb_byte
*) attr_name
;
23517 *len
= strlen (attr_name
);
23520 case DW_FORM_block1
:
23521 case DW_FORM_block2
:
23522 case DW_FORM_block4
:
23523 case DW_FORM_block
:
23524 case DW_FORM_exprloc
:
23525 case DW_FORM_data16
:
23527 struct dwarf_block
*block
= attr
->as_block ();
23528 result
= block
->data
;
23529 *len
= block
->size
;
23533 /* The DW_AT_const_value attributes are supposed to carry the
23534 symbol's value "represented as it would be on the target
23535 architecture." By the time we get here, it's already been
23536 converted to host endianness, so we just need to sign- or
23537 zero-extend it as appropriate. */
23538 case DW_FORM_data1
:
23539 type
= die_type (die
, cu
);
23540 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23541 if (result
== NULL
)
23542 result
= write_constant_as_bytes (obstack
, byte_order
,
23545 case DW_FORM_data2
:
23546 type
= die_type (die
, cu
);
23547 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23548 if (result
== NULL
)
23549 result
= write_constant_as_bytes (obstack
, byte_order
,
23552 case DW_FORM_data4
:
23553 type
= die_type (die
, cu
);
23554 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23555 if (result
== NULL
)
23556 result
= write_constant_as_bytes (obstack
, byte_order
,
23559 case DW_FORM_data8
:
23560 type
= die_type (die
, cu
);
23561 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23562 if (result
== NULL
)
23563 result
= write_constant_as_bytes (obstack
, byte_order
,
23567 case DW_FORM_sdata
:
23568 case DW_FORM_implicit_const
:
23569 type
= die_type (die
, cu
);
23570 result
= write_constant_as_bytes (obstack
, byte_order
,
23571 type
, attr
->as_signed (), len
);
23574 case DW_FORM_udata
:
23575 type
= die_type (die
, cu
);
23576 result
= write_constant_as_bytes (obstack
, byte_order
,
23577 type
, attr
->as_unsigned (), len
);
23581 complaint (_("unsupported const value attribute form: '%s'"),
23582 dwarf_form_name (attr
->form
));
23592 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23593 dwarf2_per_cu_data
*per_cu
,
23594 dwarf2_per_objfile
*per_objfile
,
23595 const char **var_name
)
23597 struct die_info
*die
;
23599 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23601 cu
= load_cu (per_cu
, per_objfile
, false);
23606 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23610 if (var_name
!= nullptr)
23611 *var_name
= var_decl_name (die
, cu
);
23612 return die_type (die
, cu
);
23618 dwarf2_get_die_type (cu_offset die_offset
,
23619 dwarf2_per_cu_data
*per_cu
,
23620 dwarf2_per_objfile
*per_objfile
)
23622 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23623 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23626 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23627 On entry *REF_CU is the CU of SRC_DIE.
23628 On exit *REF_CU is the CU of the result.
23629 Returns NULL if the referenced DIE isn't found. */
23631 static struct die_info
*
23632 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23633 struct dwarf2_cu
**ref_cu
)
23635 struct die_info temp_die
;
23636 struct dwarf2_cu
*sig_cu
;
23637 struct die_info
*die
;
23638 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23641 /* While it might be nice to assert sig_type->type == NULL here,
23642 we can get here for DW_AT_imported_declaration where we need
23643 the DIE not the type. */
23645 /* If necessary, add it to the queue and load its DIEs.
23647 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23648 it doesn't mean they are currently loaded. Since we require them
23649 to be loaded, we must check for ourselves. */
23650 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23652 || per_objfile
->get_cu (sig_type
) == nullptr)
23653 read_signatured_type (sig_type
, per_objfile
);
23655 sig_cu
= per_objfile
->get_cu (sig_type
);
23656 gdb_assert (sig_cu
!= NULL
);
23657 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23658 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23659 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23660 to_underlying (temp_die
.sect_off
));
23663 /* For .gdb_index version 7 keep track of included TUs.
23664 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23665 if (per_objfile
->per_bfd
->index_table
!= NULL
23666 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23668 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23678 /* Follow signatured type referenced by ATTR in SRC_DIE.
23679 On entry *REF_CU is the CU of SRC_DIE.
23680 On exit *REF_CU is the CU of the result.
23681 The result is the DIE of the type.
23682 If the referenced type cannot be found an error is thrown. */
23684 static struct die_info
*
23685 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23686 struct dwarf2_cu
**ref_cu
)
23688 ULONGEST signature
= attr
->as_signature ();
23689 struct signatured_type
*sig_type
;
23690 struct die_info
*die
;
23692 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23694 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23695 /* sig_type will be NULL if the signatured type is missing from
23697 if (sig_type
== NULL
)
23699 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23700 " from DIE at %s [in module %s]"),
23701 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23702 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23705 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23708 dump_die_for_error (src_die
);
23709 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23710 " from DIE at %s [in module %s]"),
23711 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23712 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23718 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23719 reading in and processing the type unit if necessary. */
23721 static struct type
*
23722 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23723 struct dwarf2_cu
*cu
)
23725 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23726 struct signatured_type
*sig_type
;
23727 struct dwarf2_cu
*type_cu
;
23728 struct die_info
*type_die
;
23731 sig_type
= lookup_signatured_type (cu
, signature
);
23732 /* sig_type will be NULL if the signatured type is missing from
23734 if (sig_type
== NULL
)
23736 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23737 " from DIE at %s [in module %s]"),
23738 hex_string (signature
), sect_offset_str (die
->sect_off
),
23739 objfile_name (per_objfile
->objfile
));
23740 return build_error_marker_type (cu
, die
);
23743 /* If we already know the type we're done. */
23744 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23745 if (type
!= nullptr)
23749 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23750 if (type_die
!= NULL
)
23752 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23753 is created. This is important, for example, because for c++ classes
23754 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23755 type
= read_type_die (type_die
, type_cu
);
23758 complaint (_("Dwarf Error: Cannot build signatured type %s"
23759 " referenced from DIE at %s [in module %s]"),
23760 hex_string (signature
), sect_offset_str (die
->sect_off
),
23761 objfile_name (per_objfile
->objfile
));
23762 type
= build_error_marker_type (cu
, die
);
23767 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23768 " from DIE at %s [in module %s]"),
23769 hex_string (signature
), sect_offset_str (die
->sect_off
),
23770 objfile_name (per_objfile
->objfile
));
23771 type
= build_error_marker_type (cu
, die
);
23774 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23779 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23780 reading in and processing the type unit if necessary. */
23782 static struct type
*
23783 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23784 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23786 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23787 if (attr
->form_is_ref ())
23789 struct dwarf2_cu
*type_cu
= cu
;
23790 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23792 return read_type_die (type_die
, type_cu
);
23794 else if (attr
->form
== DW_FORM_ref_sig8
)
23796 return get_signatured_type (die
, attr
->as_signature (), cu
);
23800 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23802 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23803 " at %s [in module %s]"),
23804 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23805 objfile_name (per_objfile
->objfile
));
23806 return build_error_marker_type (cu
, die
);
23810 /* Load the DIEs associated with type unit PER_CU into memory. */
23813 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23814 dwarf2_per_objfile
*per_objfile
)
23816 struct signatured_type
*sig_type
;
23818 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23819 gdb_assert (! per_cu
->type_unit_group_p ());
23821 /* We have the per_cu, but we need the signatured_type.
23822 Fortunately this is an easy translation. */
23823 gdb_assert (per_cu
->is_debug_types
);
23824 sig_type
= (struct signatured_type
*) per_cu
;
23826 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23828 read_signatured_type (sig_type
, per_objfile
);
23830 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23833 /* Read in a signatured type and build its CU and DIEs.
23834 If the type is a stub for the real type in a DWO file,
23835 read in the real type from the DWO file as well. */
23838 read_signatured_type (signatured_type
*sig_type
,
23839 dwarf2_per_objfile
*per_objfile
)
23841 gdb_assert (sig_type
->is_debug_types
);
23842 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23844 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23846 if (!reader
.dummy_p
)
23848 struct dwarf2_cu
*cu
= reader
.cu
;
23849 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23851 gdb_assert (cu
->die_hash
== NULL
);
23853 htab_create_alloc_ex (cu
->header
.length
/ 12,
23857 &cu
->comp_unit_obstack
,
23858 hashtab_obstack_allocate
,
23859 dummy_obstack_deallocate
);
23861 if (reader
.comp_unit_die
->has_children
)
23862 reader
.comp_unit_die
->child
23863 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23864 reader
.comp_unit_die
);
23865 cu
->dies
= reader
.comp_unit_die
;
23866 /* comp_unit_die is not stored in die_hash, no need. */
23868 /* We try not to read any attributes in this function, because
23869 not all CUs needed for references have been loaded yet, and
23870 symbol table processing isn't initialized. But we have to
23871 set the CU language, or we won't be able to build types
23872 correctly. Similarly, if we do not read the producer, we can
23873 not apply producer-specific interpretation. */
23874 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23879 sig_type
->tu_read
= 1;
23882 /* Decode simple location descriptions.
23883 Given a pointer to a dwarf block that defines a location, compute
23884 the location and return the value. If COMPUTED is non-null, it is
23885 set to true to indicate that decoding was successful, and false
23886 otherwise. If COMPUTED is null, then this function may emit a
23890 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23892 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23894 size_t size
= blk
->size
;
23895 const gdb_byte
*data
= blk
->data
;
23896 CORE_ADDR stack
[64];
23898 unsigned int bytes_read
, unsnd
;
23901 if (computed
!= nullptr)
23907 stack
[++stacki
] = 0;
23946 stack
[++stacki
] = op
- DW_OP_lit0
;
23981 stack
[++stacki
] = op
- DW_OP_reg0
;
23984 if (computed
== nullptr)
23985 dwarf2_complex_location_expr_complaint ();
23992 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23994 stack
[++stacki
] = unsnd
;
23997 if (computed
== nullptr)
23998 dwarf2_complex_location_expr_complaint ();
24005 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24010 case DW_OP_const1u
:
24011 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24015 case DW_OP_const1s
:
24016 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24020 case DW_OP_const2u
:
24021 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24025 case DW_OP_const2s
:
24026 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24030 case DW_OP_const4u
:
24031 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24035 case DW_OP_const4s
:
24036 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24040 case DW_OP_const8u
:
24041 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24046 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24052 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24057 stack
[stacki
+ 1] = stack
[stacki
];
24062 stack
[stacki
- 1] += stack
[stacki
];
24066 case DW_OP_plus_uconst
:
24067 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24073 stack
[stacki
- 1] -= stack
[stacki
];
24078 /* If we're not the last op, then we definitely can't encode
24079 this using GDB's address_class enum. This is valid for partial
24080 global symbols, although the variable's address will be bogus
24084 if (computed
== nullptr)
24085 dwarf2_complex_location_expr_complaint ();
24091 case DW_OP_GNU_push_tls_address
:
24092 case DW_OP_form_tls_address
:
24093 /* The top of the stack has the offset from the beginning
24094 of the thread control block at which the variable is located. */
24095 /* Nothing should follow this operator, so the top of stack would
24097 /* This is valid for partial global symbols, but the variable's
24098 address will be bogus in the psymtab. Make it always at least
24099 non-zero to not look as a variable garbage collected by linker
24100 which have DW_OP_addr 0. */
24103 if (computed
== nullptr)
24104 dwarf2_complex_location_expr_complaint ();
24111 case DW_OP_GNU_uninit
:
24112 if (computed
!= nullptr)
24117 case DW_OP_GNU_addr_index
:
24118 case DW_OP_GNU_const_index
:
24119 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24125 if (computed
== nullptr)
24127 const char *name
= get_DW_OP_name (op
);
24130 complaint (_("unsupported stack op: '%s'"),
24133 complaint (_("unsupported stack op: '%02x'"),
24137 return (stack
[stacki
]);
24140 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24141 outside of the allocated space. Also enforce minimum>0. */
24142 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24144 if (computed
== nullptr)
24145 complaint (_("location description stack overflow"));
24151 if (computed
== nullptr)
24152 complaint (_("location description stack underflow"));
24157 if (computed
!= nullptr)
24159 return (stack
[stacki
]);
24162 /* memory allocation interface */
24164 static struct dwarf_block
*
24165 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24167 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24170 static struct die_info
*
24171 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24173 struct die_info
*die
;
24174 size_t size
= sizeof (struct die_info
);
24177 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24179 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24180 memset (die
, 0, sizeof (struct die_info
));
24186 /* Macro support. */
24188 /* An overload of dwarf_decode_macros that finds the correct section
24189 and ensures it is read in before calling the other overload. */
24192 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24193 int section_is_gnu
)
24195 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24196 struct objfile
*objfile
= per_objfile
->objfile
;
24197 const struct line_header
*lh
= cu
->line_header
;
24198 unsigned int offset_size
= cu
->header
.offset_size
;
24199 struct dwarf2_section_info
*section
;
24200 const char *section_name
;
24202 if (cu
->dwo_unit
!= nullptr)
24204 if (section_is_gnu
)
24206 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24207 section_name
= ".debug_macro.dwo";
24211 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24212 section_name
= ".debug_macinfo.dwo";
24217 if (section_is_gnu
)
24219 section
= &per_objfile
->per_bfd
->macro
;
24220 section_name
= ".debug_macro";
24224 section
= &per_objfile
->per_bfd
->macinfo
;
24225 section_name
= ".debug_macinfo";
24229 section
->read (objfile
);
24230 if (section
->buffer
== nullptr)
24232 complaint (_("missing %s section"), section_name
);
24236 buildsym_compunit
*builder
= cu
->get_builder ();
24238 struct dwarf2_section_info
*str_offsets_section
;
24239 struct dwarf2_section_info
*str_section
;
24240 gdb::optional
<ULONGEST
> str_offsets_base
;
24242 if (cu
->dwo_unit
!= nullptr)
24244 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24245 ->sections
.str_offsets
;
24246 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24247 str_offsets_base
= cu
->header
.addr_size
;
24251 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24252 str_section
= &per_objfile
->per_bfd
->str
;
24253 str_offsets_base
= cu
->str_offsets_base
;
24256 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24257 offset_size
, offset
, str_section
, str_offsets_section
,
24258 str_offsets_base
, section_is_gnu
);
24261 /* Return the .debug_loc section to use for CU.
24262 For DWO files use .debug_loc.dwo. */
24264 static struct dwarf2_section_info
*
24265 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24267 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24271 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24273 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24275 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24276 : &per_objfile
->per_bfd
->loc
);
24279 /* Return the .debug_rnglists section to use for CU. */
24280 static struct dwarf2_section_info
*
24281 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24283 if (cu
->header
.version
< 5)
24284 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24285 cu
->header
.version
);
24286 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24288 /* Make sure we read the .debug_rnglists section from the file that
24289 contains the DW_AT_ranges attribute we are reading. Normally that
24290 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24291 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24293 if (cu
->dwo_unit
!= nullptr
24294 && tag
!= DW_TAG_compile_unit
24295 && tag
!= DW_TAG_skeleton_unit
)
24297 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24299 if (sections
->rnglists
.size
> 0)
24300 return §ions
->rnglists
;
24302 error (_(".debug_rnglists section is missing from .dwo file."));
24304 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24307 /* A helper function that fills in a dwarf2_loclist_baton. */
24310 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24311 struct dwarf2_loclist_baton
*baton
,
24312 const struct attribute
*attr
)
24314 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24315 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24317 section
->read (per_objfile
->objfile
);
24319 baton
->per_objfile
= per_objfile
;
24320 baton
->per_cu
= cu
->per_cu
;
24321 gdb_assert (baton
->per_cu
);
24322 /* We don't know how long the location list is, but make sure we
24323 don't run off the edge of the section. */
24324 baton
->size
= section
->size
- attr
->as_unsigned ();
24325 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24326 if (cu
->base_address
.has_value ())
24327 baton
->base_address
= *cu
->base_address
;
24329 baton
->base_address
= 0;
24330 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24334 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24335 struct dwarf2_cu
*cu
, int is_block
)
24337 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24338 struct objfile
*objfile
= per_objfile
->objfile
;
24339 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24341 if (attr
->form_is_section_offset ()
24342 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24343 the section. If so, fall through to the complaint in the
24345 && attr
->as_unsigned () < section
->get_size (objfile
))
24347 struct dwarf2_loclist_baton
*baton
;
24349 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24351 fill_in_loclist_baton (cu
, baton
, attr
);
24353 if (!cu
->base_address
.has_value ())
24354 complaint (_("Location list used without "
24355 "specifying the CU base address."));
24357 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24358 ? dwarf2_loclist_block_index
24359 : dwarf2_loclist_index
);
24360 SYMBOL_LOCATION_BATON (sym
) = baton
;
24364 struct dwarf2_locexpr_baton
*baton
;
24366 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24367 baton
->per_objfile
= per_objfile
;
24368 baton
->per_cu
= cu
->per_cu
;
24369 gdb_assert (baton
->per_cu
);
24371 if (attr
->form_is_block ())
24373 /* Note that we're just copying the block's data pointer
24374 here, not the actual data. We're still pointing into the
24375 info_buffer for SYM's objfile; right now we never release
24376 that buffer, but when we do clean up properly this may
24378 struct dwarf_block
*block
= attr
->as_block ();
24379 baton
->size
= block
->size
;
24380 baton
->data
= block
->data
;
24384 dwarf2_invalid_attrib_class_complaint ("location description",
24385 sym
->natural_name ());
24389 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24390 ? dwarf2_locexpr_block_index
24391 : dwarf2_locexpr_index
);
24392 SYMBOL_LOCATION_BATON (sym
) = baton
;
24398 const comp_unit_head
*
24399 dwarf2_per_cu_data::get_header () const
24401 if (!m_header_read_in
)
24403 const gdb_byte
*info_ptr
24404 = this->section
->buffer
+ to_underlying (this->sect_off
);
24406 memset (&m_header
, 0, sizeof (m_header
));
24408 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24409 rcuh_kind::COMPILE
);
24411 m_header_read_in
= true;
24420 dwarf2_per_cu_data::addr_size () const
24422 return this->get_header ()->addr_size
;
24428 dwarf2_per_cu_data::offset_size () const
24430 return this->get_header ()->offset_size
;
24436 dwarf2_per_cu_data::ref_addr_size () const
24438 const comp_unit_head
*header
= this->get_header ();
24440 if (header
->version
== 2)
24441 return header
->addr_size
;
24443 return header
->offset_size
;
24446 /* A helper function for dwarf2_find_containing_comp_unit that returns
24447 the index of the result, and that searches a vector. It will
24448 return a result even if the offset in question does not actually
24449 occur in any CU. This is separate so that it can be unit
24453 dwarf2_find_containing_comp_unit
24454 (sect_offset sect_off
,
24455 unsigned int offset_in_dwz
,
24456 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24461 high
= all_comp_units
.size () - 1;
24464 struct dwarf2_per_cu_data
*mid_cu
;
24465 int mid
= low
+ (high
- low
) / 2;
24467 mid_cu
= all_comp_units
[mid
].get ();
24468 if (mid_cu
->is_dwz
> offset_in_dwz
24469 || (mid_cu
->is_dwz
== offset_in_dwz
24470 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24475 gdb_assert (low
== high
);
24479 /* Locate the .debug_info compilation unit from CU's objfile which contains
24480 the DIE at OFFSET. Raises an error on failure. */
24482 static struct dwarf2_per_cu_data
*
24483 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24484 unsigned int offset_in_dwz
,
24485 dwarf2_per_objfile
*per_objfile
)
24487 int low
= dwarf2_find_containing_comp_unit
24488 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24489 dwarf2_per_cu_data
*this_cu
24490 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24492 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24494 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24495 error (_("Dwarf Error: could not find partial DIE containing "
24496 "offset %s [in module %s]"),
24497 sect_offset_str (sect_off
),
24498 bfd_get_filename (per_objfile
->objfile
->obfd
));
24500 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24502 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24506 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24507 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24508 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24509 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24516 namespace selftests
{
24517 namespace find_containing_comp_unit
{
24522 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24523 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24524 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24525 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24526 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24527 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24528 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24529 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24532 two
->sect_off
= sect_offset (one
->length
);
24537 four
->sect_off
= sect_offset (three
->length
);
24541 std::vector
<dwarf2_per_cu_data_up
> units
;
24542 units
.push_back (std::move (one
));
24543 units
.push_back (std::move (two
));
24544 units
.push_back (std::move (three
));
24545 units
.push_back (std::move (four
));
24549 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24550 SELF_CHECK (units
[result
].get () == one_ptr
);
24551 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24552 SELF_CHECK (units
[result
].get () == one_ptr
);
24553 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24554 SELF_CHECK (units
[result
].get () == two_ptr
);
24556 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24557 SELF_CHECK (units
[result
].get () == three_ptr
);
24558 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24559 SELF_CHECK (units
[result
].get () == three_ptr
);
24560 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24561 SELF_CHECK (units
[result
].get () == four_ptr
);
24567 #endif /* GDB_SELF_TEST */
24569 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24572 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24573 enum language pretend_language
)
24575 struct attribute
*attr
;
24577 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24579 /* Set the language we're debugging. */
24580 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24581 if (cu
->producer
!= nullptr
24582 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24584 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24585 attribute is not standardised yet. As a workaround for the
24586 language detection we fall back to the DW_AT_producer
24588 cu
->per_cu
->lang
= language_opencl
;
24590 else if (cu
->producer
!= nullptr
24591 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24593 /* Similar hack for Go. */
24594 cu
->per_cu
->lang
= language_go
;
24596 else if (attr
!= nullptr)
24597 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24599 cu
->per_cu
->lang
= pretend_language
;
24600 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24606 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24608 auto it
= m_dwarf2_cus
.find (per_cu
);
24609 if (it
== m_dwarf2_cus
.end ())
24618 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24620 gdb_assert (this->get_cu (per_cu
) == nullptr);
24622 m_dwarf2_cus
[per_cu
] = cu
;
24628 dwarf2_per_objfile::age_comp_units ()
24630 dwarf_read_debug_printf_v ("running");
24632 /* This is not expected to be called in the middle of CU expansion. There is
24633 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24634 loaded in memory. Calling age_comp_units while the queue is in use could
24635 make us free the DIEs for a CU that is in the queue and therefore break
24637 gdb_assert (!this->per_bfd
->queue
.has_value ());
24639 /* Start by clearing all marks. */
24640 for (auto pair
: m_dwarf2_cus
)
24641 pair
.second
->clear_mark ();
24643 /* Traverse all CUs, mark them and their dependencies if used recently
24645 for (auto pair
: m_dwarf2_cus
)
24647 dwarf2_cu
*cu
= pair
.second
;
24650 if (cu
->last_used
<= dwarf_max_cache_age
)
24654 /* Delete all CUs still not marked. */
24655 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24657 dwarf2_cu
*cu
= it
->second
;
24659 if (!cu
->is_marked ())
24661 dwarf_read_debug_printf_v ("deleting old CU %s",
24662 sect_offset_str (cu
->per_cu
->sect_off
));
24664 it
= m_dwarf2_cus
.erase (it
);
24674 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24676 auto it
= m_dwarf2_cus
.find (per_cu
);
24677 if (it
== m_dwarf2_cus
.end ())
24682 m_dwarf2_cus
.erase (it
);
24685 dwarf2_per_objfile::~dwarf2_per_objfile ()
24690 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24691 We store these in a hash table separate from the DIEs, and preserve them
24692 when the DIEs are flushed out of cache.
24694 The CU "per_cu" pointer is needed because offset alone is not enough to
24695 uniquely identify the type. A file may have multiple .debug_types sections,
24696 or the type may come from a DWO file. Furthermore, while it's more logical
24697 to use per_cu->section+offset, with Fission the section with the data is in
24698 the DWO file but we don't know that section at the point we need it.
24699 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24700 because we can enter the lookup routine, get_die_type_at_offset, from
24701 outside this file, and thus won't necessarily have PER_CU->cu.
24702 Fortunately, PER_CU is stable for the life of the objfile. */
24704 struct dwarf2_per_cu_offset_and_type
24706 const struct dwarf2_per_cu_data
*per_cu
;
24707 sect_offset sect_off
;
24711 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24714 per_cu_offset_and_type_hash (const void *item
)
24716 const struct dwarf2_per_cu_offset_and_type
*ofs
24717 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24719 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24722 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24725 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24727 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24728 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24729 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24730 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24732 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24733 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24736 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24737 table if necessary. For convenience, return TYPE.
24739 The DIEs reading must have careful ordering to:
24740 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24741 reading current DIE.
24742 * Not trying to dereference contents of still incompletely read in types
24743 while reading in other DIEs.
24744 * Enable referencing still incompletely read in types just by a pointer to
24745 the type without accessing its fields.
24747 Therefore caller should follow these rules:
24748 * Try to fetch any prerequisite types we may need to build this DIE type
24749 before building the type and calling set_die_type.
24750 * After building type call set_die_type for current DIE as soon as
24751 possible before fetching more types to complete the current type.
24752 * Make the type as complete as possible before fetching more types. */
24754 static struct type
*
24755 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24756 bool skip_data_location
)
24758 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24759 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24760 struct objfile
*objfile
= per_objfile
->objfile
;
24761 struct attribute
*attr
;
24762 struct dynamic_prop prop
;
24764 /* For Ada types, make sure that the gnat-specific data is always
24765 initialized (if not already set). There are a few types where
24766 we should not be doing so, because the type-specific area is
24767 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24768 where the type-specific area is used to store the floatformat).
24769 But this is not a problem, because the gnat-specific information
24770 is actually not needed for these types. */
24771 if (need_gnat_info (cu
)
24772 && type
->code () != TYPE_CODE_FUNC
24773 && type
->code () != TYPE_CODE_FLT
24774 && type
->code () != TYPE_CODE_METHODPTR
24775 && type
->code () != TYPE_CODE_MEMBERPTR
24776 && type
->code () != TYPE_CODE_METHOD
24777 && type
->code () != TYPE_CODE_FIXED_POINT
24778 && !HAVE_GNAT_AUX_INFO (type
))
24779 INIT_GNAT_SPECIFIC (type
);
24781 /* Read DW_AT_allocated and set in type. */
24782 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24785 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24786 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24787 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24790 /* Read DW_AT_associated and set in type. */
24791 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24794 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24795 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24796 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24799 /* Read DW_AT_data_location and set in type. */
24800 if (!skip_data_location
)
24802 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24803 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24804 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24807 if (per_objfile
->die_type_hash
== NULL
)
24808 per_objfile
->die_type_hash
24809 = htab_up (htab_create_alloc (127,
24810 per_cu_offset_and_type_hash
,
24811 per_cu_offset_and_type_eq
,
24812 NULL
, xcalloc
, xfree
));
24814 ofs
.per_cu
= cu
->per_cu
;
24815 ofs
.sect_off
= die
->sect_off
;
24817 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24818 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24820 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24821 sect_offset_str (die
->sect_off
));
24822 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24823 struct dwarf2_per_cu_offset_and_type
);
24828 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24829 or return NULL if the die does not have a saved type. */
24831 static struct type
*
24832 get_die_type_at_offset (sect_offset sect_off
,
24833 dwarf2_per_cu_data
*per_cu
,
24834 dwarf2_per_objfile
*per_objfile
)
24836 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24838 if (per_objfile
->die_type_hash
== NULL
)
24841 ofs
.per_cu
= per_cu
;
24842 ofs
.sect_off
= sect_off
;
24843 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24844 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24851 /* Look up the type for DIE in CU in die_type_hash,
24852 or return NULL if DIE does not have a saved type. */
24854 static struct type
*
24855 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24857 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24860 /* Trivial hash function for partial_die_info: the hash value of a DIE
24861 is its offset in .debug_info for this objfile. */
24864 partial_die_hash (const void *item
)
24866 const struct partial_die_info
*part_die
24867 = (const struct partial_die_info
*) item
;
24869 return to_underlying (part_die
->sect_off
);
24872 /* Trivial comparison function for partial_die_info structures: two DIEs
24873 are equal if they have the same offset. */
24876 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24878 const struct partial_die_info
*part_die_lhs
24879 = (const struct partial_die_info
*) item_lhs
;
24880 const struct partial_die_info
*part_die_rhs
24881 = (const struct partial_die_info
*) item_rhs
;
24883 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24886 struct cmd_list_element
*set_dwarf_cmdlist
;
24887 struct cmd_list_element
*show_dwarf_cmdlist
;
24890 show_check_physname (struct ui_file
*file
, int from_tty
,
24891 struct cmd_list_element
*c
, const char *value
)
24893 fprintf_filtered (file
,
24894 _("Whether to check \"physname\" is %s.\n"),
24898 void _initialize_dwarf2_read ();
24900 _initialize_dwarf2_read ()
24902 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24903 Set DWARF specific variables.\n\
24904 Configure DWARF variables such as the cache size."),
24905 &set_dwarf_cmdlist
,
24906 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24908 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24909 Show DWARF specific variables.\n\
24910 Show DWARF variables such as the cache size."),
24911 &show_dwarf_cmdlist
,
24912 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24914 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24915 &dwarf_max_cache_age
, _("\
24916 Set the upper bound on the age of cached DWARF compilation units."), _("\
24917 Show the upper bound on the age of cached DWARF compilation units."), _("\
24918 A higher limit means that cached compilation units will be stored\n\
24919 in memory longer, and more total memory will be used. Zero disables\n\
24920 caching, which can slow down startup."),
24922 show_dwarf_max_cache_age
,
24923 &set_dwarf_cmdlist
,
24924 &show_dwarf_cmdlist
);
24926 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24927 Set debugging of the DWARF reader."), _("\
24928 Show debugging of the DWARF reader."), _("\
24929 When enabled (non-zero), debugging messages are printed during DWARF\n\
24930 reading and symtab expansion. A value of 1 (one) provides basic\n\
24931 information. A value greater than 1 provides more verbose information."),
24934 &setdebuglist
, &showdebuglist
);
24936 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24937 Set debugging of the DWARF DIE reader."), _("\
24938 Show debugging of the DWARF DIE reader."), _("\
24939 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24940 The value is the maximum depth to print."),
24943 &setdebuglist
, &showdebuglist
);
24945 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24946 Set debugging of the dwarf line reader."), _("\
24947 Show debugging of the dwarf line reader."), _("\
24948 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24949 A value of 1 (one) provides basic information.\n\
24950 A value greater than 1 provides more verbose information."),
24953 &setdebuglist
, &showdebuglist
);
24955 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24956 Set cross-checking of \"physname\" code against demangler."), _("\
24957 Show cross-checking of \"physname\" code against demangler."), _("\
24958 When enabled, GDB's internal \"physname\" code is checked against\n\
24960 NULL
, show_check_physname
,
24961 &setdebuglist
, &showdebuglist
);
24963 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24964 no_class
, &use_deprecated_index_sections
, _("\
24965 Set whether to use deprecated gdb_index sections."), _("\
24966 Show whether to use deprecated gdb_index sections."), _("\
24967 When enabled, deprecated .gdb_index sections are used anyway.\n\
24968 Normally they are ignored either because of a missing feature or\n\
24969 performance issue.\n\
24970 Warning: This option must be enabled before gdb reads the file."),
24973 &setlist
, &showlist
);
24975 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24976 &dwarf2_locexpr_funcs
);
24977 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24978 &dwarf2_loclist_funcs
);
24980 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24981 &dwarf2_block_frame_base_locexpr_funcs
);
24982 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24983 &dwarf2_block_frame_base_loclist_funcs
);
24986 selftests::register_test ("dw2_expand_symtabs_matching",
24987 selftests::dw2_expand_symtabs_matching::run_test
);
24988 selftests::register_test ("dwarf2_find_containing_comp_unit",
24989 selftests::find_containing_comp_unit::run_test
);