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 may_be_inlined
: 1;
868 /* This DIE has been marked DW_AT_main_subprogram. */
869 unsigned int main_subprogram
: 1;
871 /* Flag set if the SCOPE field of this structure has been
873 unsigned int scope_set
: 1;
875 /* Flag set if the DIE has a byte_size attribute. */
876 unsigned int has_byte_size
: 1;
878 /* Flag set if the DIE has a DW_AT_const_value attribute. */
879 unsigned int has_const_value
: 1;
881 /* Flag set if any of the DIE's children are template arguments. */
882 unsigned int has_template_arguments
: 1;
884 /* Flag set if fixup has been called on this die. */
885 unsigned int fixup_called
: 1;
887 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
888 unsigned int is_dwz
: 1;
890 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
891 unsigned int spec_is_dwz
: 1;
893 unsigned int canonical_name
: 1;
895 /* The name of this DIE. Normally the value of DW_AT_name, but
896 sometimes a default name for unnamed DIEs. */
897 const char *raw_name
= nullptr;
899 /* The linkage name, if present. */
900 const char *linkage_name
= nullptr;
902 /* The scope to prepend to our children. This is generally
903 allocated on the comp_unit_obstack, so will disappear
904 when this compilation unit leaves the cache. */
905 const char *scope
= nullptr;
907 /* Some data associated with the partial DIE. The tag determines
908 which field is live. */
911 /* The location description associated with this DIE, if any. */
912 struct dwarf_block
*locdesc
;
913 /* The offset of an import, for DW_TAG_imported_unit. */
914 sect_offset sect_off
;
917 /* If HAS_PC_INFO, the PC range associated with this DIE. */
919 CORE_ADDR highpc
= 0;
921 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
922 DW_AT_sibling, if any. */
923 /* NOTE: This member isn't strictly necessary, partial_die_info::read
924 could return DW_AT_sibling values to its caller load_partial_dies. */
925 const gdb_byte
*sibling
= nullptr;
927 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
928 DW_AT_specification (or DW_AT_abstract_origin or
930 sect_offset spec_offset
{};
932 /* Pointers to this DIE's parent, first child, and next sibling,
934 struct partial_die_info
*die_parent
= nullptr;
935 struct partial_die_info
*die_child
= nullptr;
936 struct partial_die_info
*die_sibling
= nullptr;
938 friend struct partial_die_info
*
939 dwarf2_cu::find_partial_die (sect_offset sect_off
);
942 /* Only need to do look up in dwarf2_cu::find_partial_die. */
943 partial_die_info (sect_offset sect_off
)
944 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
948 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
950 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
955 has_specification
= 0;
962 has_template_arguments
= 0;
970 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
971 but this would require a corresponding change in unpack_field_as_long
973 static int bits_per_byte
= 8;
975 struct variant_part_builder
;
977 /* When reading a variant, we track a bit more information about the
978 field, and store it in an object of this type. */
982 int first_field
= -1;
985 /* A variant can contain other variant parts. */
986 std::vector
<variant_part_builder
> variant_parts
;
988 /* If we see a DW_TAG_variant, then this will be set if this is the
990 bool default_branch
= false;
991 /* If we see a DW_AT_discr_value, then this will be the discriminant
993 ULONGEST discriminant_value
= 0;
994 /* If we see a DW_AT_discr_list, then this is a pointer to the list
996 struct dwarf_block
*discr_list_data
= nullptr;
999 /* This represents a DW_TAG_variant_part. */
1001 struct variant_part_builder
1003 /* The offset of the discriminant field. */
1004 sect_offset discriminant_offset
{};
1006 /* Variants that are direct children of this variant part. */
1007 std::vector
<variant_field
> variants
;
1009 /* True if we're currently reading a variant. */
1010 bool processing_variant
= false;
1015 int accessibility
= 0;
1017 /* Variant parts need to find the discriminant, which is a DIE
1018 reference. We track the section offset of each field to make
1021 struct field field
{};
1026 const char *name
= nullptr;
1027 std::vector
<struct fn_field
> fnfields
;
1030 /* The routines that read and process dies for a C struct or C++ class
1031 pass lists of data member fields and lists of member function fields
1032 in an instance of a field_info structure, as defined below. */
1035 /* List of data member and baseclasses fields. */
1036 std::vector
<struct nextfield
> fields
;
1037 std::vector
<struct nextfield
> baseclasses
;
1039 /* Set if the accessibility of one of the fields is not public. */
1040 bool non_public_fields
= false;
1042 /* Member function fieldlist array, contains name of possibly overloaded
1043 member function, number of overloaded member functions and a pointer
1044 to the head of the member function field chain. */
1045 std::vector
<struct fnfieldlist
> fnfieldlists
;
1047 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1048 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1049 std::vector
<struct decl_field
> typedef_field_list
;
1051 /* Nested types defined by this class and the number of elements in this
1053 std::vector
<struct decl_field
> nested_types_list
;
1055 /* If non-null, this is the variant part we are currently
1057 variant_part_builder
*current_variant_part
= nullptr;
1058 /* This holds all the top-level variant parts attached to the type
1060 std::vector
<variant_part_builder
> variant_parts
;
1062 /* Return the total number of fields (including baseclasses). */
1063 int nfields () const
1065 return fields
.size () + baseclasses
.size ();
1069 /* Loaded secondary compilation units are kept in memory until they
1070 have not been referenced for the processing of this many
1071 compilation units. Set this to zero to disable caching. Cache
1072 sizes of up to at least twenty will improve startup time for
1073 typical inter-CU-reference binaries, at an obvious memory cost. */
1074 static int dwarf_max_cache_age
= 5;
1076 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1077 struct cmd_list_element
*c
, const char *value
)
1079 fprintf_filtered (file
, _("The upper bound on the age of cached "
1080 "DWARF compilation units is %s.\n"),
1084 /* local function prototypes */
1086 static void dwarf2_find_base_address (struct die_info
*die
,
1087 struct dwarf2_cu
*cu
);
1089 static dwarf2_psymtab
*create_partial_symtab
1090 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1093 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1094 const gdb_byte
*info_ptr
,
1095 struct die_info
*type_unit_die
);
1097 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1099 static void scan_partial_symbols (struct partial_die_info
*,
1100 CORE_ADDR
*, CORE_ADDR
*,
1101 int, struct dwarf2_cu
*);
1103 static void add_partial_symbol (struct partial_die_info
*,
1104 struct dwarf2_cu
*);
1106 static void add_partial_namespace (struct partial_die_info
*pdi
,
1107 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1108 int set_addrmap
, struct dwarf2_cu
*cu
);
1110 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1111 CORE_ADDR
*highpc
, int set_addrmap
,
1112 struct dwarf2_cu
*cu
);
1114 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1115 struct dwarf2_cu
*cu
);
1117 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1118 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1119 int need_pc
, struct dwarf2_cu
*cu
);
1121 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1123 static struct partial_die_info
*load_partial_dies
1124 (const struct die_reader_specs
*, const gdb_byte
*, int);
1126 /* A pair of partial_die_info and compilation unit. */
1127 struct cu_partial_die_info
1129 /* The compilation unit of the partial_die_info. */
1130 struct dwarf2_cu
*cu
;
1131 /* A partial_die_info. */
1132 struct partial_die_info
*pdi
;
1134 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1140 cu_partial_die_info () = delete;
1143 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1144 struct dwarf2_cu
*);
1146 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1148 const struct attr_abbrev
*,
1151 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1152 struct attribute
*attr
, dwarf_tag tag
);
1154 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1156 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1157 dwarf2_section_info
*, sect_offset
);
1159 static const char *read_indirect_string
1160 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1161 const struct comp_unit_head
*, unsigned int *);
1163 static const char *read_indirect_string_at_offset
1164 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1166 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1170 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1171 ULONGEST str_index
);
1173 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1174 ULONGEST str_index
);
1176 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1177 struct dwarf2_cu
*);
1179 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1180 struct dwarf2_cu
*cu
);
1182 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1184 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1185 struct dwarf2_cu
*cu
);
1187 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1189 static struct die_info
*die_specification (struct die_info
*die
,
1190 struct dwarf2_cu
**);
1192 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1193 struct dwarf2_cu
*cu
);
1195 static void dwarf_decode_lines (struct line_header
*, const char *,
1196 struct dwarf2_cu
*, dwarf2_psymtab
*,
1197 CORE_ADDR
, int decode_mapping
);
1199 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1202 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1203 struct dwarf2_cu
*, struct symbol
* = NULL
);
1205 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1206 struct dwarf2_cu
*);
1208 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1211 struct obstack
*obstack
,
1212 struct dwarf2_cu
*cu
, LONGEST
*value
,
1213 const gdb_byte
**bytes
,
1214 struct dwarf2_locexpr_baton
**baton
);
1216 static struct type
*read_subrange_index_type (struct die_info
*die
,
1217 struct dwarf2_cu
*cu
);
1219 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1221 static int need_gnat_info (struct dwarf2_cu
*);
1223 static struct type
*die_descriptive_type (struct die_info
*,
1224 struct dwarf2_cu
*);
1226 static void set_descriptive_type (struct type
*, struct die_info
*,
1227 struct dwarf2_cu
*);
1229 static struct type
*die_containing_type (struct die_info
*,
1230 struct dwarf2_cu
*);
1232 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1233 struct dwarf2_cu
*);
1235 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1237 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1239 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1241 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1242 const char *suffix
, int physname
,
1243 struct dwarf2_cu
*cu
);
1245 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1247 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1249 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1251 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1253 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1255 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1257 /* Return the .debug_loclists section to use for cu. */
1258 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1260 /* Return the .debug_rnglists section to use for cu. */
1261 static struct dwarf2_section_info
*cu_debug_rnglists_section
1262 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1264 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1265 values. Keep the items ordered with increasing constraints compliance. */
1268 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1269 PC_BOUNDS_NOT_PRESENT
,
1271 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1272 were present but they do not form a valid range of PC addresses. */
1275 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1278 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1282 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1283 CORE_ADDR
*, CORE_ADDR
*,
1287 static void get_scope_pc_bounds (struct die_info
*,
1288 CORE_ADDR
*, CORE_ADDR
*,
1289 struct dwarf2_cu
*);
1291 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1292 CORE_ADDR
, struct dwarf2_cu
*);
1294 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1295 struct dwarf2_cu
*);
1297 static void dwarf2_attach_fields_to_type (struct field_info
*,
1298 struct type
*, struct dwarf2_cu
*);
1300 static void dwarf2_add_member_fn (struct field_info
*,
1301 struct die_info
*, struct type
*,
1302 struct dwarf2_cu
*);
1304 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1306 struct dwarf2_cu
*);
1308 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1310 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1312 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1314 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1316 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1318 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1320 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1322 static struct type
*read_module_type (struct die_info
*die
,
1323 struct dwarf2_cu
*cu
);
1325 static const char *namespace_name (struct die_info
*die
,
1326 int *is_anonymous
, struct dwarf2_cu
*);
1328 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1330 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1333 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1334 struct dwarf2_cu
*);
1336 static struct die_info
*read_die_and_siblings_1
1337 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1340 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1341 const gdb_byte
*info_ptr
,
1342 const gdb_byte
**new_info_ptr
,
1343 struct die_info
*parent
);
1345 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1346 struct die_info
**, const gdb_byte
*,
1349 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1350 struct die_info
**, const gdb_byte
*);
1352 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1354 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1357 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1359 static const char *dwarf2_full_name (const char *name
,
1360 struct die_info
*die
,
1361 struct dwarf2_cu
*cu
);
1363 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1364 struct dwarf2_cu
*cu
);
1366 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1367 struct dwarf2_cu
**);
1369 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1371 static void dump_die_for_error (struct die_info
*);
1373 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1376 /*static*/ void dump_die (struct die_info
*, int max_level
);
1378 static void store_in_ref_table (struct die_info
*,
1379 struct dwarf2_cu
*);
1381 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1382 const struct attribute
*,
1383 struct dwarf2_cu
**);
1385 static struct die_info
*follow_die_ref (struct die_info
*,
1386 const struct attribute
*,
1387 struct dwarf2_cu
**);
1389 static struct die_info
*follow_die_sig (struct die_info
*,
1390 const struct attribute
*,
1391 struct dwarf2_cu
**);
1393 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1394 struct dwarf2_cu
*);
1396 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1397 const struct attribute
*,
1398 struct dwarf2_cu
*);
1400 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1401 dwarf2_per_objfile
*per_objfile
);
1403 static void read_signatured_type (signatured_type
*sig_type
,
1404 dwarf2_per_objfile
*per_objfile
);
1406 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1407 struct die_info
*die
, struct dwarf2_cu
*cu
,
1408 struct dynamic_prop
*prop
, struct type
*type
);
1410 /* memory allocation interface */
1412 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1414 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1416 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1418 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1419 struct dwarf2_loclist_baton
*baton
,
1420 const struct attribute
*attr
);
1422 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1424 struct dwarf2_cu
*cu
,
1427 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1428 const gdb_byte
*info_ptr
,
1429 const struct abbrev_info
*abbrev
);
1431 static hashval_t
partial_die_hash (const void *item
);
1433 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1435 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1436 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1437 dwarf2_per_objfile
*per_objfile
);
1439 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1440 struct die_info
*comp_unit_die
,
1441 enum language pretend_language
);
1443 static struct type
*set_die_type (struct die_info
*, struct type
*,
1444 struct dwarf2_cu
*, bool = false);
1446 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1448 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1449 dwarf2_per_objfile
*per_objfile
,
1450 dwarf2_cu
*existing_cu
,
1452 enum language pretend_language
);
1454 static void process_full_comp_unit (dwarf2_cu
*cu
,
1455 enum language pretend_language
);
1457 static void process_full_type_unit (dwarf2_cu
*cu
,
1458 enum language pretend_language
);
1460 static struct type
*get_die_type_at_offset (sect_offset
,
1461 dwarf2_per_cu_data
*per_cu
,
1462 dwarf2_per_objfile
*per_objfile
);
1464 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1466 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1467 dwarf2_per_objfile
*per_objfile
,
1468 enum language pretend_language
);
1470 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1472 /* Class, the destructor of which frees all allocated queue entries. This
1473 will only have work to do if an error was thrown while processing the
1474 dwarf. If no error was thrown then the queue entries should have all
1475 been processed, and freed, as we went along. */
1477 class dwarf2_queue_guard
1480 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1481 : m_per_objfile (per_objfile
)
1483 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1485 m_per_objfile
->per_bfd
->queue
.emplace ();
1488 /* Free any entries remaining on the queue. There should only be
1489 entries left if we hit an error while processing the dwarf. */
1490 ~dwarf2_queue_guard ()
1492 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1494 m_per_objfile
->per_bfd
->queue
.reset ();
1497 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1500 dwarf2_per_objfile
*m_per_objfile
;
1503 dwarf2_queue_item::~dwarf2_queue_item ()
1505 /* Anything still marked queued is likely to be in an
1506 inconsistent state, so discard it. */
1509 per_objfile
->remove_cu (per_cu
);
1514 /* See dwarf2/read.h. */
1517 dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data
*data
)
1519 if (data
->is_debug_types
)
1520 delete static_cast<signatured_type
*> (data
);
1525 /* The return type of find_file_and_directory. Note, the enclosed
1526 string pointers are only valid while this object is valid. */
1528 struct file_and_directory
1530 /* The filename. This is never NULL. */
1533 /* The compilation directory. NULL if not known. If we needed to
1534 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1535 points directly to the DW_AT_comp_dir string attribute owned by
1536 the obstack that owns the DIE. */
1537 const char *comp_dir
;
1539 /* If we needed to build a new string for comp_dir, this is what
1540 owns the storage. */
1541 std::string comp_dir_storage
;
1544 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1545 struct dwarf2_cu
*cu
);
1547 static htab_up
allocate_signatured_type_table ();
1549 static htab_up
allocate_dwo_unit_table ();
1551 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1552 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1553 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1555 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1557 static struct dwo_unit
*lookup_dwo_comp_unit
1558 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1559 ULONGEST signature
);
1561 static struct dwo_unit
*lookup_dwo_type_unit
1562 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1564 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1566 /* A unique pointer to a dwo_file. */
1568 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1570 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1572 static void check_producer (struct dwarf2_cu
*cu
);
1574 /* Various complaints about symbol reading that don't abort the process. */
1577 dwarf2_debug_line_missing_file_complaint (void)
1579 complaint (_(".debug_line section has line data without a file"));
1583 dwarf2_debug_line_missing_end_sequence_complaint (void)
1585 complaint (_(".debug_line section has line "
1586 "program sequence without an end"));
1590 dwarf2_complex_location_expr_complaint (void)
1592 complaint (_("location expression too complex"));
1596 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1599 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1604 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1606 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1610 /* Hash function for line_header_hash. */
1613 line_header_hash (const struct line_header
*ofs
)
1615 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1618 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1621 line_header_hash_voidp (const void *item
)
1623 const struct line_header
*ofs
= (const struct line_header
*) item
;
1625 return line_header_hash (ofs
);
1628 /* Equality function for line_header_hash. */
1631 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1633 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1634 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1636 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1637 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1642 /* See declaration. */
1644 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1647 can_copy (can_copy_
)
1650 names
= &dwarf2_elf_names
;
1652 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1653 locate_sections (obfd
, sec
, *names
);
1656 dwarf2_per_bfd::~dwarf2_per_bfd ()
1658 for (auto &per_cu
: all_comp_units
)
1659 per_cu
->imported_symtabs_free ();
1661 /* Everything else should be on this->obstack. */
1667 dwarf2_per_objfile::remove_all_cus ()
1669 gdb_assert (!this->per_bfd
->queue
.has_value ());
1671 for (auto pair
: m_dwarf2_cus
)
1674 m_dwarf2_cus
.clear ();
1677 /* A helper class that calls free_cached_comp_units on
1680 class free_cached_comp_units
1684 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1685 : m_per_objfile (per_objfile
)
1689 ~free_cached_comp_units ()
1691 m_per_objfile
->remove_all_cus ();
1694 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1698 dwarf2_per_objfile
*m_per_objfile
;
1704 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1706 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1708 return this->m_symtabs
[per_cu
->index
] != nullptr;
1714 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1716 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1718 return this->m_symtabs
[per_cu
->index
];
1724 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1725 compunit_symtab
*symtab
)
1727 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1728 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1730 this->m_symtabs
[per_cu
->index
] = symtab
;
1733 /* Try to locate the sections we need for DWARF 2 debugging
1734 information and return true if we have enough to do something.
1735 NAMES points to the dwarf2 section names, or is NULL if the standard
1736 ELF names are used. CAN_COPY is true for formats where symbol
1737 interposition is possible and so symbol values must follow copy
1738 relocation rules. */
1741 dwarf2_has_info (struct objfile
*objfile
,
1742 const struct dwarf2_debug_sections
*names
,
1745 if (objfile
->flags
& OBJF_READNEVER
)
1748 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1750 if (per_objfile
== NULL
)
1752 dwarf2_per_bfd
*per_bfd
;
1754 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1755 BFD doesn't require relocations.
1757 We don't share with objfiles for which -readnow was requested,
1758 because it would complicate things when loading the same BFD with
1759 -readnow and then without -readnow. */
1760 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1761 && (objfile
->flags
& OBJF_READNOW
) == 0)
1763 /* See if one has been created for this BFD yet. */
1764 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1766 if (per_bfd
== nullptr)
1768 /* No, create it now. */
1769 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1770 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1775 /* No sharing possible, create one specifically for this objfile. */
1776 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1777 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1780 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1783 return (!per_objfile
->per_bfd
->info
.is_virtual
1784 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1785 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1786 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1789 /* See declaration. */
1792 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1793 const dwarf2_debug_sections
&names
)
1795 flagword aflag
= bfd_section_flags (sectp
);
1797 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1800 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1801 > bfd_get_file_size (abfd
))
1803 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1804 warning (_("Discarding section %s which has a section size (%s"
1805 ") larger than the file size [in module %s]"),
1806 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1807 bfd_get_filename (abfd
));
1809 else if (names
.info
.matches (sectp
->name
))
1811 this->info
.s
.section
= sectp
;
1812 this->info
.size
= bfd_section_size (sectp
);
1814 else if (names
.abbrev
.matches (sectp
->name
))
1816 this->abbrev
.s
.section
= sectp
;
1817 this->abbrev
.size
= bfd_section_size (sectp
);
1819 else if (names
.line
.matches (sectp
->name
))
1821 this->line
.s
.section
= sectp
;
1822 this->line
.size
= bfd_section_size (sectp
);
1824 else if (names
.loc
.matches (sectp
->name
))
1826 this->loc
.s
.section
= sectp
;
1827 this->loc
.size
= bfd_section_size (sectp
);
1829 else if (names
.loclists
.matches (sectp
->name
))
1831 this->loclists
.s
.section
= sectp
;
1832 this->loclists
.size
= bfd_section_size (sectp
);
1834 else if (names
.macinfo
.matches (sectp
->name
))
1836 this->macinfo
.s
.section
= sectp
;
1837 this->macinfo
.size
= bfd_section_size (sectp
);
1839 else if (names
.macro
.matches (sectp
->name
))
1841 this->macro
.s
.section
= sectp
;
1842 this->macro
.size
= bfd_section_size (sectp
);
1844 else if (names
.str
.matches (sectp
->name
))
1846 this->str
.s
.section
= sectp
;
1847 this->str
.size
= bfd_section_size (sectp
);
1849 else if (names
.str_offsets
.matches (sectp
->name
))
1851 this->str_offsets
.s
.section
= sectp
;
1852 this->str_offsets
.size
= bfd_section_size (sectp
);
1854 else if (names
.line_str
.matches (sectp
->name
))
1856 this->line_str
.s
.section
= sectp
;
1857 this->line_str
.size
= bfd_section_size (sectp
);
1859 else if (names
.addr
.matches (sectp
->name
))
1861 this->addr
.s
.section
= sectp
;
1862 this->addr
.size
= bfd_section_size (sectp
);
1864 else if (names
.frame
.matches (sectp
->name
))
1866 this->frame
.s
.section
= sectp
;
1867 this->frame
.size
= bfd_section_size (sectp
);
1869 else if (names
.eh_frame
.matches (sectp
->name
))
1871 this->eh_frame
.s
.section
= sectp
;
1872 this->eh_frame
.size
= bfd_section_size (sectp
);
1874 else if (names
.ranges
.matches (sectp
->name
))
1876 this->ranges
.s
.section
= sectp
;
1877 this->ranges
.size
= bfd_section_size (sectp
);
1879 else if (names
.rnglists
.matches (sectp
->name
))
1881 this->rnglists
.s
.section
= sectp
;
1882 this->rnglists
.size
= bfd_section_size (sectp
);
1884 else if (names
.types
.matches (sectp
->name
))
1886 struct dwarf2_section_info type_section
;
1888 memset (&type_section
, 0, sizeof (type_section
));
1889 type_section
.s
.section
= sectp
;
1890 type_section
.size
= bfd_section_size (sectp
);
1892 this->types
.push_back (type_section
);
1894 else if (names
.gdb_index
.matches (sectp
->name
))
1896 this->gdb_index
.s
.section
= sectp
;
1897 this->gdb_index
.size
= bfd_section_size (sectp
);
1899 else if (names
.debug_names
.matches (sectp
->name
))
1901 this->debug_names
.s
.section
= sectp
;
1902 this->debug_names
.size
= bfd_section_size (sectp
);
1904 else if (names
.debug_aranges
.matches (sectp
->name
))
1906 this->debug_aranges
.s
.section
= sectp
;
1907 this->debug_aranges
.size
= bfd_section_size (sectp
);
1910 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1911 && bfd_section_vma (sectp
) == 0)
1912 this->has_section_at_zero
= true;
1915 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1919 dwarf2_get_section_info (struct objfile
*objfile
,
1920 enum dwarf2_section_enum sect
,
1921 asection
**sectp
, const gdb_byte
**bufp
,
1922 bfd_size_type
*sizep
)
1924 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1925 struct dwarf2_section_info
*info
;
1927 /* We may see an objfile without any DWARF, in which case we just
1929 if (per_objfile
== NULL
)
1938 case DWARF2_DEBUG_FRAME
:
1939 info
= &per_objfile
->per_bfd
->frame
;
1941 case DWARF2_EH_FRAME
:
1942 info
= &per_objfile
->per_bfd
->eh_frame
;
1945 gdb_assert_not_reached ("unexpected section");
1948 info
->read (objfile
);
1950 *sectp
= info
->get_bfd_section ();
1951 *bufp
= info
->buffer
;
1952 *sizep
= info
->size
;
1956 /* DWARF quick_symbol_functions support. */
1958 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1959 unique line tables, so we maintain a separate table of all .debug_line
1960 derived entries to support the sharing.
1961 All the quick functions need is the list of file names. We discard the
1962 line_header when we're done and don't need to record it here. */
1963 struct quick_file_names
1965 /* The data used to construct the hash key. */
1966 struct stmt_list_hash hash
;
1968 /* The number of entries in file_names, real_names. */
1969 unsigned int num_file_names
;
1971 /* The file names from the line table, after being run through
1973 const char **file_names
;
1975 /* The file names from the line table after being run through
1976 gdb_realpath. These are computed lazily. */
1977 const char **real_names
;
1980 /* When using the index (and thus not using psymtabs), each CU has an
1981 object of this type. This is used to hold information needed by
1982 the various "quick" methods. */
1983 struct dwarf2_per_cu_quick_data
1985 /* The file table. This can be NULL if there was no file table
1986 or it's currently not read in.
1987 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
1988 struct quick_file_names
*file_names
;
1990 /* A temporary mark bit used when iterating over all CUs in
1991 expand_symtabs_matching. */
1992 unsigned int mark
: 1;
1994 /* True if we've tried to read the file table and found there isn't one.
1995 There will be no point in trying to read it again next time. */
1996 unsigned int no_file_data
: 1;
1999 /* A subclass of psymbol_functions that arranges to read the DWARF
2000 partial symbols when needed. */
2001 struct lazy_dwarf_reader
: public psymbol_functions
2003 using psymbol_functions::psymbol_functions
;
2005 bool can_lazily_read_symbols () override
2010 void read_partial_symbols (struct objfile
*objfile
) override
2012 if (dwarf2_has_info (objfile
, nullptr))
2013 dwarf2_build_psymtabs (objfile
, this);
2017 static quick_symbol_functions_up
2018 make_lazy_dwarf_reader ()
2020 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2023 struct dwarf2_base_index_functions
: public quick_symbol_functions
2025 bool has_symbols (struct objfile
*objfile
) override
;
2027 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2029 void forget_cached_source_info (struct objfile
*objfile
) override
;
2031 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2034 bool *symbol_found_p
) override
2036 *symbol_found_p
= false;
2037 return language_unknown
;
2040 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2042 void expand_all_symtabs (struct objfile
*objfile
) override
;
2044 struct compunit_symtab
*find_pc_sect_compunit_symtab
2045 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2046 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2048 struct compunit_symtab
*find_compunit_symtab_by_address
2049 (struct objfile
*objfile
, CORE_ADDR address
) override
2054 void map_symbol_filenames (struct objfile
*objfile
,
2055 gdb::function_view
<symbol_filename_ftype
> fun
,
2056 bool need_fullname
) override
;
2059 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2061 void dump (struct objfile
*objfile
) override
;
2063 void expand_matching_symbols
2065 const lookup_name_info
&lookup_name
,
2068 symbol_compare_ftype
*ordered_compare
) override
;
2070 bool expand_symtabs_matching
2071 (struct objfile
*objfile
,
2072 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2073 const lookup_name_info
*lookup_name
,
2074 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2075 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2076 block_search_flags search_flags
,
2078 enum search_domain kind
) override
;
2081 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2083 void dump (struct objfile
*objfile
) override
;
2085 void expand_matching_symbols
2087 const lookup_name_info
&lookup_name
,
2090 symbol_compare_ftype
*ordered_compare
) override
;
2092 bool expand_symtabs_matching
2093 (struct objfile
*objfile
,
2094 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2095 const lookup_name_info
*lookup_name
,
2096 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2097 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2098 block_search_flags search_flags
,
2100 enum search_domain kind
) override
;
2103 static quick_symbol_functions_up
2104 make_dwarf_gdb_index ()
2106 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2109 static quick_symbol_functions_up
2110 make_dwarf_debug_names ()
2112 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2115 /* Utility hash function for a stmt_list_hash. */
2118 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2122 if (stmt_list_hash
->dwo_unit
!= NULL
)
2123 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2124 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2128 /* Utility equality function for a stmt_list_hash. */
2131 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2132 const struct stmt_list_hash
*rhs
)
2134 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2136 if (lhs
->dwo_unit
!= NULL
2137 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2140 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2143 /* Hash function for a quick_file_names. */
2146 hash_file_name_entry (const void *e
)
2148 const struct quick_file_names
*file_data
2149 = (const struct quick_file_names
*) e
;
2151 return hash_stmt_list_entry (&file_data
->hash
);
2154 /* Equality function for a quick_file_names. */
2157 eq_file_name_entry (const void *a
, const void *b
)
2159 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2160 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2162 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2165 /* Delete function for a quick_file_names. */
2168 delete_file_name_entry (void *e
)
2170 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2173 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2175 xfree ((void*) file_data
->file_names
[i
]);
2176 if (file_data
->real_names
)
2177 xfree ((void*) file_data
->real_names
[i
]);
2180 /* The space for the struct itself lives on the obstack, so we don't
2184 /* Create a quick_file_names hash table. */
2187 create_quick_file_names_table (unsigned int nr_initial_entries
)
2189 return htab_up (htab_create_alloc (nr_initial_entries
,
2190 hash_file_name_entry
, eq_file_name_entry
,
2191 delete_file_name_entry
, xcalloc
, xfree
));
2194 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2195 function is unrelated to symtabs, symtab would have to be created afterwards.
2196 You should call age_cached_comp_units after processing the CU. */
2199 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2202 if (per_cu
->is_debug_types
)
2203 load_full_type_unit (per_cu
, per_objfile
);
2205 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2206 skip_partial
, language_minimal
);
2208 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2210 return nullptr; /* Dummy CU. */
2212 dwarf2_find_base_address (cu
->dies
, cu
);
2217 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2220 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2221 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2223 /* Skip type_unit_groups, reading the type units they contain
2224 is handled elsewhere. */
2225 if (per_cu
->type_unit_group_p ())
2229 /* The destructor of dwarf2_queue_guard frees any entries left on
2230 the queue. After this point we're guaranteed to leave this function
2231 with the dwarf queue empty. */
2232 dwarf2_queue_guard
q_guard (per_objfile
);
2234 if (!per_objfile
->symtab_set_p (per_cu
))
2236 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2237 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2239 /* If we just loaded a CU from a DWO, and we're working with an index
2240 that may badly handle TUs, load all the TUs in that DWO as well.
2241 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2242 if (!per_cu
->is_debug_types
2244 && cu
->dwo_unit
!= NULL
2245 && per_objfile
->per_bfd
->index_table
!= NULL
2246 && per_objfile
->per_bfd
->index_table
->version
<= 7
2247 /* DWP files aren't supported yet. */
2248 && get_dwp_file (per_objfile
) == NULL
)
2249 queue_and_load_all_dwo_tus (cu
);
2252 process_queue (per_objfile
);
2255 /* Age the cache, releasing compilation units that have not
2256 been used recently. */
2257 per_objfile
->age_comp_units ();
2260 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2261 the per-objfile for which this symtab is instantiated.
2263 Returns the resulting symbol table. */
2265 static struct compunit_symtab
*
2266 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2267 dwarf2_per_objfile
*per_objfile
,
2270 gdb_assert (per_objfile
->per_bfd
->using_index
);
2272 if (!per_objfile
->symtab_set_p (per_cu
))
2274 free_cached_comp_units
freer (per_objfile
);
2275 scoped_restore decrementer
= increment_reading_symtab ();
2276 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2277 process_cu_includes (per_objfile
);
2280 return per_objfile
->get_symtab (per_cu
);
2285 dwarf2_per_cu_data_up
2286 dwarf2_per_bfd::allocate_per_cu ()
2288 dwarf2_per_cu_data_up
result (new dwarf2_per_cu_data
);
2289 result
->per_bfd
= this;
2290 result
->index
= all_comp_units
.size ();
2297 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature
)
2299 signatured_type_up
result (new signatured_type (signature
));
2300 result
->per_bfd
= this;
2301 result
->index
= all_comp_units
.size ();
2302 result
->is_debug_types
= true;
2307 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2308 obstack, and constructed with the specified field values. */
2310 static dwarf2_per_cu_data_up
2311 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2312 struct dwarf2_section_info
*section
,
2314 sect_offset sect_off
, ULONGEST length
)
2316 dwarf2_per_cu_data_up the_cu
= per_bfd
->allocate_per_cu ();
2317 the_cu
->sect_off
= sect_off
;
2318 the_cu
->length
= length
;
2319 the_cu
->section
= section
;
2320 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2321 struct dwarf2_per_cu_quick_data
);
2322 the_cu
->is_dwz
= is_dwz
;
2326 /* A helper for create_cus_from_index that handles a given list of
2330 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2331 const gdb_byte
*cu_list
, offset_type n_elements
,
2332 struct dwarf2_section_info
*section
,
2335 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2337 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2339 sect_offset sect_off
2340 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2341 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2344 dwarf2_per_cu_data_up per_cu
2345 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2347 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2351 /* Read the CU list from the mapped index, and use it to create all
2352 the CU objects for PER_BFD. */
2355 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2356 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2357 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2359 gdb_assert (per_bfd
->all_comp_units
.empty ());
2360 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2362 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2365 if (dwz_elements
== 0)
2368 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2369 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2373 /* Create the signatured type hash table from the index. */
2376 create_signatured_type_table_from_index
2377 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2378 const gdb_byte
*bytes
, offset_type elements
)
2380 htab_up sig_types_hash
= allocate_signatured_type_table ();
2382 for (offset_type i
= 0; i
< elements
; i
+= 3)
2384 signatured_type_up sig_type
;
2387 cu_offset type_offset_in_tu
;
2389 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2390 sect_offset sect_off
2391 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2393 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2395 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2398 sig_type
= per_bfd
->allocate_signatured_type (signature
);
2399 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2400 sig_type
->section
= section
;
2401 sig_type
->sect_off
= sect_off
;
2403 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2404 struct dwarf2_per_cu_quick_data
);
2406 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2407 *slot
= sig_type
.get ();
2409 per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2412 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2415 /* Create the signatured type hash table from .debug_names. */
2418 create_signatured_type_table_from_debug_names
2419 (dwarf2_per_objfile
*per_objfile
,
2420 const mapped_debug_names
&map
,
2421 struct dwarf2_section_info
*section
,
2422 struct dwarf2_section_info
*abbrev_section
)
2424 struct objfile
*objfile
= per_objfile
->objfile
;
2426 section
->read (objfile
);
2427 abbrev_section
->read (objfile
);
2429 htab_up sig_types_hash
= allocate_signatured_type_table ();
2431 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2433 signatured_type_up sig_type
;
2436 sect_offset sect_off
2437 = (sect_offset
) (extract_unsigned_integer
2438 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2440 map
.dwarf5_byte_order
));
2442 comp_unit_head cu_header
;
2443 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2445 section
->buffer
+ to_underlying (sect_off
),
2448 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
2449 (cu_header
.signature
);
2450 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2451 sig_type
->section
= section
;
2452 sig_type
->sect_off
= sect_off
;
2454 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2455 struct dwarf2_per_cu_quick_data
);
2457 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2458 *slot
= sig_type
.get ();
2460 per_objfile
->per_bfd
->all_comp_units
.emplace_back (sig_type
.release ());
2463 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2466 /* Read the address map data from the mapped index, and use it to
2467 populate the psymtabs_addrmap. */
2470 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2471 struct mapped_index
*index
)
2473 struct objfile
*objfile
= per_objfile
->objfile
;
2474 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2475 struct gdbarch
*gdbarch
= objfile
->arch ();
2476 const gdb_byte
*iter
, *end
;
2477 struct addrmap
*mutable_map
;
2480 auto_obstack temp_obstack
;
2482 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2484 iter
= index
->address_table
.data ();
2485 end
= iter
+ index
->address_table
.size ();
2487 baseaddr
= objfile
->text_section_offset ();
2491 ULONGEST hi
, lo
, cu_index
;
2492 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2494 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2496 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2501 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2502 hex_string (lo
), hex_string (hi
));
2506 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2508 complaint (_(".gdb_index address table has invalid CU number %u"),
2509 (unsigned) cu_index
);
2513 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2514 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2515 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2516 per_bfd
->get_cu (cu_index
));
2519 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2523 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2524 populate the psymtabs_addrmap. */
2527 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2528 struct dwarf2_section_info
*section
)
2530 struct objfile
*objfile
= per_objfile
->objfile
;
2531 bfd
*abfd
= objfile
->obfd
;
2532 struct gdbarch
*gdbarch
= objfile
->arch ();
2533 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2534 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2536 auto_obstack temp_obstack
;
2537 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2539 std::unordered_map
<sect_offset
,
2540 dwarf2_per_cu_data
*,
2541 gdb::hash_enum
<sect_offset
>>
2542 debug_info_offset_to_per_cu
;
2543 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2545 const auto insertpair
2546 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2548 if (!insertpair
.second
)
2550 warning (_("Section .debug_aranges in %s has duplicate "
2551 "debug_info_offset %s, ignoring .debug_aranges."),
2552 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2557 section
->read (objfile
);
2559 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2561 const gdb_byte
*addr
= section
->buffer
;
2563 while (addr
< section
->buffer
+ section
->size
)
2565 const gdb_byte
*const entry_addr
= addr
;
2566 unsigned int bytes_read
;
2568 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2572 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2573 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2574 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2575 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2577 warning (_("Section .debug_aranges in %s entry at offset %s "
2578 "length %s exceeds section length %s, "
2579 "ignoring .debug_aranges."),
2580 objfile_name (objfile
),
2581 plongest (entry_addr
- section
->buffer
),
2582 plongest (bytes_read
+ entry_length
),
2583 pulongest (section
->size
));
2587 /* The version number. */
2588 const uint16_t version
= read_2_bytes (abfd
, addr
);
2592 warning (_("Section .debug_aranges in %s entry at offset %s "
2593 "has unsupported version %d, ignoring .debug_aranges."),
2594 objfile_name (objfile
),
2595 plongest (entry_addr
- section
->buffer
), version
);
2599 const uint64_t debug_info_offset
2600 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2601 addr
+= offset_size
;
2602 const auto per_cu_it
2603 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2604 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2606 warning (_("Section .debug_aranges in %s entry at offset %s "
2607 "debug_info_offset %s does not exists, "
2608 "ignoring .debug_aranges."),
2609 objfile_name (objfile
),
2610 plongest (entry_addr
- section
->buffer
),
2611 pulongest (debug_info_offset
));
2614 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2616 const uint8_t address_size
= *addr
++;
2617 if (address_size
< 1 || address_size
> 8)
2619 warning (_("Section .debug_aranges in %s entry at offset %s "
2620 "address_size %u is invalid, ignoring .debug_aranges."),
2621 objfile_name (objfile
),
2622 plongest (entry_addr
- section
->buffer
), address_size
);
2626 const uint8_t segment_selector_size
= *addr
++;
2627 if (segment_selector_size
!= 0)
2629 warning (_("Section .debug_aranges in %s entry at offset %s "
2630 "segment_selector_size %u is not supported, "
2631 "ignoring .debug_aranges."),
2632 objfile_name (objfile
),
2633 plongest (entry_addr
- section
->buffer
),
2634 segment_selector_size
);
2638 /* Must pad to an alignment boundary that is twice the address
2639 size. It is undocumented by the DWARF standard but GCC does
2641 for (size_t padding
= ((-(addr
- section
->buffer
))
2642 & (2 * address_size
- 1));
2643 padding
> 0; padding
--)
2646 warning (_("Section .debug_aranges in %s entry at offset %s "
2647 "padding is not zero, ignoring .debug_aranges."),
2648 objfile_name (objfile
),
2649 plongest (entry_addr
- section
->buffer
));
2655 if (addr
+ 2 * address_size
> entry_end
)
2657 warning (_("Section .debug_aranges in %s entry at offset %s "
2658 "address list is not properly terminated, "
2659 "ignoring .debug_aranges."),
2660 objfile_name (objfile
),
2661 plongest (entry_addr
- section
->buffer
));
2664 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2666 addr
+= address_size
;
2667 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2669 addr
+= address_size
;
2670 if (start
== 0 && length
== 0)
2672 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2674 /* Symbol was eliminated due to a COMDAT group. */
2677 ULONGEST end
= start
+ length
;
2678 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2680 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2682 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2686 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2690 /* A helper function that reads the .gdb_index from BUFFER and fills
2691 in MAP. FILENAME is the name of the file containing the data;
2692 it is used for error reporting. DEPRECATED_OK is true if it is
2693 ok to use deprecated sections.
2695 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2696 out parameters that are filled in with information about the CU and
2697 TU lists in the section.
2699 Returns true if all went well, false otherwise. */
2702 read_gdb_index_from_buffer (const char *filename
,
2704 gdb::array_view
<const gdb_byte
> buffer
,
2705 struct mapped_index
*map
,
2706 const gdb_byte
**cu_list
,
2707 offset_type
*cu_list_elements
,
2708 const gdb_byte
**types_list
,
2709 offset_type
*types_list_elements
)
2711 const gdb_byte
*addr
= &buffer
[0];
2712 offset_view
metadata (buffer
);
2714 /* Version check. */
2715 offset_type version
= metadata
[0];
2716 /* Versions earlier than 3 emitted every copy of a psymbol. This
2717 causes the index to behave very poorly for certain requests. Version 3
2718 contained incomplete addrmap. So, it seems better to just ignore such
2722 static int warning_printed
= 0;
2723 if (!warning_printed
)
2725 warning (_("Skipping obsolete .gdb_index section in %s."),
2727 warning_printed
= 1;
2731 /* Index version 4 uses a different hash function than index version
2734 Versions earlier than 6 did not emit psymbols for inlined
2735 functions. Using these files will cause GDB not to be able to
2736 set breakpoints on inlined functions by name, so we ignore these
2737 indices unless the user has done
2738 "set use-deprecated-index-sections on". */
2739 if (version
< 6 && !deprecated_ok
)
2741 static int warning_printed
= 0;
2742 if (!warning_printed
)
2745 Skipping deprecated .gdb_index section in %s.\n\
2746 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2747 to use the section anyway."),
2749 warning_printed
= 1;
2753 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2754 of the TU (for symbols coming from TUs),
2755 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2756 Plus gold-generated indices can have duplicate entries for global symbols,
2757 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2758 These are just performance bugs, and we can't distinguish gdb-generated
2759 indices from gold-generated ones, so issue no warning here. */
2761 /* Indexes with higher version than the one supported by GDB may be no
2762 longer backward compatible. */
2766 map
->version
= version
;
2769 *cu_list
= addr
+ metadata
[i
];
2770 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2773 *types_list
= addr
+ metadata
[i
];
2774 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
2777 const gdb_byte
*address_table
= addr
+ metadata
[i
];
2778 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
2780 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2783 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
2784 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
2786 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
2790 map
->constant_pool
= buffer
.slice (metadata
[i
]);
2795 /* Callback types for dwarf2_read_gdb_index. */
2797 typedef gdb::function_view
2798 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2799 get_gdb_index_contents_ftype
;
2800 typedef gdb::function_view
2801 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2802 get_gdb_index_contents_dwz_ftype
;
2804 /* Read .gdb_index. If everything went ok, initialize the "quick"
2805 elements of all the CUs and return 1. Otherwise, return 0. */
2808 dwarf2_read_gdb_index
2809 (dwarf2_per_objfile
*per_objfile
,
2810 get_gdb_index_contents_ftype get_gdb_index_contents
,
2811 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2813 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2814 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2815 struct dwz_file
*dwz
;
2816 struct objfile
*objfile
= per_objfile
->objfile
;
2817 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2819 gdb::array_view
<const gdb_byte
> main_index_contents
2820 = get_gdb_index_contents (objfile
, per_bfd
);
2822 if (main_index_contents
.empty ())
2825 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2826 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2827 use_deprecated_index_sections
,
2828 main_index_contents
, map
.get (), &cu_list
,
2829 &cu_list_elements
, &types_list
,
2830 &types_list_elements
))
2833 /* Don't use the index if it's empty. */
2834 if (map
->symbol_table
.empty ())
2837 /* If there is a .dwz file, read it so we can get its CU list as
2839 dwz
= dwarf2_get_dwz_file (per_bfd
);
2842 struct mapped_index dwz_map
;
2843 const gdb_byte
*dwz_types_ignore
;
2844 offset_type dwz_types_elements_ignore
;
2846 gdb::array_view
<const gdb_byte
> dwz_index_content
2847 = get_gdb_index_contents_dwz (objfile
, dwz
);
2849 if (dwz_index_content
.empty ())
2852 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
2853 1, dwz_index_content
, &dwz_map
,
2854 &dwz_list
, &dwz_list_elements
,
2856 &dwz_types_elements_ignore
))
2858 warning (_("could not read '.gdb_index' section from %s; skipping"),
2859 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2864 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
2867 if (types_list_elements
)
2869 /* We can only handle a single .debug_types when we have an
2871 if (per_bfd
->types
.size () != 1)
2874 dwarf2_section_info
*section
= &per_bfd
->types
[0];
2876 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
2877 types_list_elements
);
2880 create_addrmap_from_index (per_objfile
, map
.get ());
2882 per_bfd
->index_table
= std::move (map
);
2883 per_bfd
->using_index
= 1;
2884 per_bfd
->quick_file_names_table
=
2885 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
2890 /* die_reader_func for dw2_get_file_names. */
2893 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2894 struct die_info
*comp_unit_die
)
2896 struct dwarf2_cu
*cu
= reader
->cu
;
2897 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2898 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
2899 struct dwarf2_per_cu_data
*lh_cu
;
2900 struct attribute
*attr
;
2902 struct quick_file_names
*qfn
;
2904 gdb_assert (! this_cu
->is_debug_types
);
2906 /* Our callers never want to match partial units -- instead they
2907 will match the enclosing full CU. */
2908 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2910 this_cu
->v
.quick
->no_file_data
= 1;
2918 sect_offset line_offset
{};
2920 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2921 if (attr
!= nullptr && attr
->form_is_unsigned ())
2923 struct quick_file_names find_entry
;
2925 line_offset
= (sect_offset
) attr
->as_unsigned ();
2927 /* We may have already read in this line header (TU line header sharing).
2928 If we have we're done. */
2929 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2930 find_entry
.hash
.line_sect_off
= line_offset
;
2931 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
2932 &find_entry
, INSERT
);
2935 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
2939 lh
= dwarf_decode_line_header (line_offset
, cu
);
2943 lh_cu
->v
.quick
->no_file_data
= 1;
2947 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
2948 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2949 qfn
->hash
.line_sect_off
= line_offset
;
2950 gdb_assert (slot
!= NULL
);
2953 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
2956 if (strcmp (fnd
.name
, "<unknown>") != 0)
2959 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
2961 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
2962 qfn
->num_file_names
);
2964 qfn
->file_names
[0] = xstrdup (fnd
.name
);
2965 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
2966 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
2967 fnd
.comp_dir
).release ();
2968 qfn
->real_names
= NULL
;
2970 lh_cu
->v
.quick
->file_names
= qfn
;
2973 /* A helper for the "quick" functions which attempts to read the line
2974 table for THIS_CU. */
2976 static struct quick_file_names
*
2977 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
2978 dwarf2_per_objfile
*per_objfile
)
2980 /* This should never be called for TUs. */
2981 gdb_assert (! this_cu
->is_debug_types
);
2982 /* Nor type unit groups. */
2983 gdb_assert (! this_cu
->type_unit_group_p ());
2985 if (this_cu
->v
.quick
->file_names
!= NULL
)
2986 return this_cu
->v
.quick
->file_names
;
2987 /* If we know there is no line data, no point in looking again. */
2988 if (this_cu
->v
.quick
->no_file_data
)
2991 cutu_reader
reader (this_cu
, per_objfile
);
2992 if (!reader
.dummy_p
)
2993 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
2995 if (this_cu
->v
.quick
->no_file_data
)
2997 return this_cu
->v
.quick
->file_names
;
3000 /* A helper for the "quick" functions which computes and caches the
3001 real path for a given file name from the line table. */
3004 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3005 struct quick_file_names
*qfn
, int index
)
3007 if (qfn
->real_names
== NULL
)
3008 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3009 qfn
->num_file_names
, const char *);
3011 if (qfn
->real_names
[index
] == NULL
)
3012 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3014 return qfn
->real_names
[index
];
3018 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3020 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3021 dwarf2_per_cu_data
*dwarf_cu
3022 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3023 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3028 return compunit_primary_filetab (cust
);
3031 /* Traversal function for dw2_forget_cached_source_info. */
3034 dw2_free_cached_file_names (void **slot
, void *info
)
3036 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3038 if (file_data
->real_names
)
3042 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3044 xfree ((void*) file_data
->real_names
[i
]);
3045 file_data
->real_names
[i
] = NULL
;
3053 dwarf2_base_index_functions::forget_cached_source_info
3054 (struct objfile
*objfile
)
3056 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3058 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3059 dw2_free_cached_file_names
, NULL
);
3062 /* Struct used to manage iterating over all CUs looking for a symbol. */
3064 struct dw2_symtab_iterator
3066 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3067 dwarf2_per_objfile
*per_objfile
;
3068 /* If set, only look for symbols that match that block. Valid values are
3069 GLOBAL_BLOCK and STATIC_BLOCK. */
3070 gdb::optional
<block_enum
> block_index
;
3071 /* The kind of symbol we're looking for. */
3073 /* The list of CUs from the index entry of the symbol,
3074 or NULL if not found. */
3076 /* The next element in VEC to look at. */
3078 /* The number of elements in VEC, or zero if there is no match. */
3080 /* Have we seen a global version of the symbol?
3081 If so we can ignore all further global instances.
3082 This is to work around gold/15646, inefficient gold-generated
3087 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3090 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3091 dwarf2_per_objfile
*per_objfile
,
3092 gdb::optional
<block_enum
> block_index
,
3093 domain_enum domain
, offset_type namei
)
3095 iter
->per_objfile
= per_objfile
;
3096 iter
->block_index
= block_index
;
3097 iter
->domain
= domain
;
3099 iter
->global_seen
= 0;
3103 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3104 /* index is NULL if OBJF_READNOW. */
3108 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3109 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3111 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3112 iter
->length
= iter
->vec
[0];
3115 /* Return the next matching CU or NULL if there are no more. */
3117 static struct dwarf2_per_cu_data
*
3118 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3120 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3122 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3124 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3125 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3126 gdb_index_symbol_kind symbol_kind
=
3127 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3128 /* Only check the symbol attributes if they're present.
3129 Indices prior to version 7 don't record them,
3130 and indices >= 7 may elide them for certain symbols
3131 (gold does this). */
3133 (per_objfile
->per_bfd
->index_table
->version
>= 7
3134 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3136 /* Don't crash on bad data. */
3137 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3139 complaint (_(".gdb_index entry has bad CU index"
3140 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3144 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3146 /* Skip if already read in. */
3147 if (per_objfile
->symtab_set_p (per_cu
))
3150 /* Check static vs global. */
3153 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3155 if (iter
->block_index
.has_value ())
3157 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3159 if (is_static
!= want_static
)
3163 /* Work around gold/15646. */
3165 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3167 if (iter
->global_seen
)
3170 iter
->global_seen
= 1;
3174 /* Only check the symbol's kind if it has one. */
3177 switch (iter
->domain
)
3180 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3181 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3182 /* Some types are also in VAR_DOMAIN. */
3183 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3187 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3191 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3195 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3211 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3217 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3218 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3221 for (int i
= 0; i
< total
; ++i
)
3223 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3225 if (!per_objfile
->symtab_set_p (per_cu
))
3228 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3229 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3232 /* This dumps minimal information about the index.
3233 It is called via "mt print objfiles".
3234 One use is to verify .gdb_index has been loaded by the
3235 gdb.dwarf2/gdb-index.exp testcase. */
3238 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3240 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3242 gdb_assert (per_objfile
->per_bfd
->using_index
);
3243 printf_filtered (".gdb_index:");
3244 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3246 printf_filtered (" version %d\n",
3247 per_objfile
->per_bfd
->index_table
->version
);
3250 printf_filtered (" faked for \"readnow\"\n");
3251 printf_filtered ("\n");
3255 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3257 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3258 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3260 for (int i
= 0; i
< total_units
; ++i
)
3262 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3264 /* We don't want to directly expand a partial CU, because if we
3265 read it with the wrong language, then assertion failures can
3266 be triggered later on. See PR symtab/23010. So, tell
3267 dw2_instantiate_symtab to skip partial CUs -- any important
3268 partial CU will be read via DW_TAG_imported_unit anyway. */
3269 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3274 dw2_expand_symtabs_matching_symbol
3275 (mapped_index_base
&index
,
3276 const lookup_name_info
&lookup_name_in
,
3277 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3278 gdb::function_view
<bool (offset_type
)> match_callback
,
3279 dwarf2_per_objfile
*per_objfile
);
3282 dw2_expand_symtabs_matching_one
3283 (dwarf2_per_cu_data
*per_cu
,
3284 dwarf2_per_objfile
*per_objfile
,
3285 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3286 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3289 dwarf2_gdb_index::expand_matching_symbols
3290 (struct objfile
*objfile
,
3291 const lookup_name_info
&name
, domain_enum domain
,
3293 symbol_compare_ftype
*ordered_compare
)
3296 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3298 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3300 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3302 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3304 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3305 auto matcher
= [&] (const char *symname
)
3307 if (ordered_compare
== nullptr)
3309 return ordered_compare (symname
, match_name
) == 0;
3312 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3313 [&] (offset_type namei
)
3315 struct dw2_symtab_iterator iter
;
3316 struct dwarf2_per_cu_data
*per_cu
;
3318 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3320 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3321 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3328 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3329 proceed assuming all symtabs have been read in. */
3333 /* Starting from a search name, return the string that finds the upper
3334 bound of all strings that start with SEARCH_NAME in a sorted name
3335 list. Returns the empty string to indicate that the upper bound is
3336 the end of the list. */
3339 make_sort_after_prefix_name (const char *search_name
)
3341 /* When looking to complete "func", we find the upper bound of all
3342 symbols that start with "func" by looking for where we'd insert
3343 the closest string that would follow "func" in lexicographical
3344 order. Usually, that's "func"-with-last-character-incremented,
3345 i.e. "fund". Mind non-ASCII characters, though. Usually those
3346 will be UTF-8 multi-byte sequences, but we can't be certain.
3347 Especially mind the 0xff character, which is a valid character in
3348 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3349 rule out compilers allowing it in identifiers. Note that
3350 conveniently, strcmp/strcasecmp are specified to compare
3351 characters interpreted as unsigned char. So what we do is treat
3352 the whole string as a base 256 number composed of a sequence of
3353 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3354 to 0, and carries 1 to the following more-significant position.
3355 If the very first character in SEARCH_NAME ends up incremented
3356 and carries/overflows, then the upper bound is the end of the
3357 list. The string after the empty string is also the empty
3360 Some examples of this operation:
3362 SEARCH_NAME => "+1" RESULT
3366 "\xff" "a" "\xff" => "\xff" "b"
3371 Then, with these symbols for example:
3377 completing "func" looks for symbols between "func" and
3378 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3379 which finds "func" and "func1", but not "fund".
3383 funcÿ (Latin1 'ÿ' [0xff])
3387 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3388 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3392 ÿÿ (Latin1 'ÿ' [0xff])
3395 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3396 the end of the list.
3398 std::string after
= search_name
;
3399 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3401 if (!after
.empty ())
3402 after
.back () = (unsigned char) after
.back () + 1;
3406 /* See declaration. */
3408 std::pair
<std::vector
<name_component
>::const_iterator
,
3409 std::vector
<name_component
>::const_iterator
>
3410 mapped_index_base::find_name_components_bounds
3411 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3412 dwarf2_per_objfile
*per_objfile
) const
3415 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3417 const char *lang_name
3418 = lookup_name_without_params
.language_lookup_name (lang
);
3420 /* Comparison function object for lower_bound that matches against a
3421 given symbol name. */
3422 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3425 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3426 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3427 return name_cmp (elem_name
, name
) < 0;
3430 /* Comparison function object for upper_bound that matches against a
3431 given symbol name. */
3432 auto lookup_compare_upper
= [&] (const char *name
,
3433 const name_component
&elem
)
3435 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3436 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3437 return name_cmp (name
, elem_name
) < 0;
3440 auto begin
= this->name_components
.begin ();
3441 auto end
= this->name_components
.end ();
3443 /* Find the lower bound. */
3446 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3449 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3452 /* Find the upper bound. */
3455 if (lookup_name_without_params
.completion_mode ())
3457 /* In completion mode, we want UPPER to point past all
3458 symbols names that have the same prefix. I.e., with
3459 these symbols, and completing "func":
3461 function << lower bound
3463 other_function << upper bound
3465 We find the upper bound by looking for the insertion
3466 point of "func"-with-last-character-incremented,
3468 std::string after
= make_sort_after_prefix_name (lang_name
);
3471 return std::lower_bound (lower
, end
, after
.c_str (),
3472 lookup_compare_lower
);
3475 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3478 return {lower
, upper
};
3481 /* See declaration. */
3484 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3486 if (!this->name_components
.empty ())
3489 this->name_components_casing
= case_sensitivity
;
3491 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3493 /* The code below only knows how to break apart components of C++
3494 symbol names (and other languages that use '::' as
3495 namespace/module separator) and Ada symbol names. */
3496 auto count
= this->symbol_name_count ();
3497 for (offset_type idx
= 0; idx
< count
; idx
++)
3499 if (this->symbol_name_slot_invalid (idx
))
3502 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3504 /* Add each name component to the name component table. */
3505 unsigned int previous_len
= 0;
3507 if (strstr (name
, "::") != nullptr)
3509 for (unsigned int current_len
= cp_find_first_component (name
);
3510 name
[current_len
] != '\0';
3511 current_len
+= cp_find_first_component (name
+ current_len
))
3513 gdb_assert (name
[current_len
] == ':');
3514 this->name_components
.push_back ({previous_len
, idx
});
3515 /* Skip the '::'. */
3517 previous_len
= current_len
;
3522 /* Handle the Ada encoded (aka mangled) form here. */
3523 for (const char *iter
= strstr (name
, "__");
3525 iter
= strstr (iter
, "__"))
3527 this->name_components
.push_back ({previous_len
, idx
});
3529 previous_len
= iter
- name
;
3533 this->name_components
.push_back ({previous_len
, idx
});
3536 /* Sort name_components elements by name. */
3537 auto name_comp_compare
= [&] (const name_component
&left
,
3538 const name_component
&right
)
3540 const char *left_qualified
3541 = this->symbol_name_at (left
.idx
, per_objfile
);
3542 const char *right_qualified
3543 = this->symbol_name_at (right
.idx
, per_objfile
);
3545 const char *left_name
= left_qualified
+ left
.name_offset
;
3546 const char *right_name
= right_qualified
+ right
.name_offset
;
3548 return name_cmp (left_name
, right_name
) < 0;
3551 std::sort (this->name_components
.begin (),
3552 this->name_components
.end (),
3556 /* Helper for dw2_expand_symtabs_matching that works with a
3557 mapped_index_base instead of the containing objfile. This is split
3558 to a separate function in order to be able to unit test the
3559 name_components matching using a mock mapped_index_base. For each
3560 symbol name that matches, calls MATCH_CALLBACK, passing it the
3561 symbol's index in the mapped_index_base symbol table. */
3564 dw2_expand_symtabs_matching_symbol
3565 (mapped_index_base
&index
,
3566 const lookup_name_info
&lookup_name_in
,
3567 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3568 gdb::function_view
<bool (offset_type
)> match_callback
,
3569 dwarf2_per_objfile
*per_objfile
)
3571 lookup_name_info lookup_name_without_params
3572 = lookup_name_in
.make_ignore_params ();
3574 /* Build the symbol name component sorted vector, if we haven't
3576 index
.build_name_components (per_objfile
);
3578 /* The same symbol may appear more than once in the range though.
3579 E.g., if we're looking for symbols that complete "w", and we have
3580 a symbol named "w1::w2", we'll find the two name components for
3581 that same symbol in the range. To be sure we only call the
3582 callback once per symbol, we first collect the symbol name
3583 indexes that matched in a temporary vector and ignore
3585 std::vector
<offset_type
> matches
;
3587 struct name_and_matcher
3589 symbol_name_matcher_ftype
*matcher
;
3592 bool operator== (const name_and_matcher
&other
) const
3594 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3598 /* A vector holding all the different symbol name matchers, for all
3600 std::vector
<name_and_matcher
> matchers
;
3602 for (int i
= 0; i
< nr_languages
; i
++)
3604 enum language lang_e
= (enum language
) i
;
3606 const language_defn
*lang
= language_def (lang_e
);
3607 symbol_name_matcher_ftype
*name_matcher
3608 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3610 name_and_matcher key
{
3612 lookup_name_without_params
.language_lookup_name (lang_e
)
3615 /* Don't insert the same comparison routine more than once.
3616 Note that we do this linear walk. This is not a problem in
3617 practice because the number of supported languages is
3619 if (std::find (matchers
.begin (), matchers
.end (), key
)
3622 matchers
.push_back (std::move (key
));
3625 = index
.find_name_components_bounds (lookup_name_without_params
,
3626 lang_e
, per_objfile
);
3628 /* Now for each symbol name in range, check to see if we have a name
3629 match, and if so, call the MATCH_CALLBACK callback. */
3631 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3633 const char *qualified
3634 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3636 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3637 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3640 matches
.push_back (bounds
.first
->idx
);
3644 std::sort (matches
.begin (), matches
.end ());
3646 /* Finally call the callback, once per match. */
3649 for (offset_type idx
: matches
)
3653 if (!match_callback (idx
))
3662 /* Above we use a type wider than idx's for 'prev', since 0 and
3663 (offset_type)-1 are both possible values. */
3664 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3671 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3673 /* A mock .gdb_index/.debug_names-like name index table, enough to
3674 exercise dw2_expand_symtabs_matching_symbol, which works with the
3675 mapped_index_base interface. Builds an index from the symbol list
3676 passed as parameter to the constructor. */
3677 class mock_mapped_index
: public mapped_index_base
3680 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3681 : m_symbol_table (symbols
)
3684 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3686 /* Return the number of names in the symbol table. */
3687 size_t symbol_name_count () const override
3689 return m_symbol_table
.size ();
3692 /* Get the name of the symbol at IDX in the symbol table. */
3693 const char *symbol_name_at
3694 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3696 return m_symbol_table
[idx
];
3700 gdb::array_view
<const char *> m_symbol_table
;
3703 /* Convenience function that converts a NULL pointer to a "<null>"
3704 string, to pass to print routines. */
3707 string_or_null (const char *str
)
3709 return str
!= NULL
? str
: "<null>";
3712 /* Check if a lookup_name_info built from
3713 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3714 index. EXPECTED_LIST is the list of expected matches, in expected
3715 matching order. If no match expected, then an empty list is
3716 specified. Returns true on success. On failure prints a warning
3717 indicating the file:line that failed, and returns false. */
3720 check_match (const char *file
, int line
,
3721 mock_mapped_index
&mock_index
,
3722 const char *name
, symbol_name_match_type match_type
,
3723 bool completion_mode
,
3724 std::initializer_list
<const char *> expected_list
,
3725 dwarf2_per_objfile
*per_objfile
)
3727 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3729 bool matched
= true;
3731 auto mismatch
= [&] (const char *expected_str
,
3734 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3735 "expected=\"%s\", got=\"%s\"\n"),
3737 (match_type
== symbol_name_match_type::FULL
3739 name
, string_or_null (expected_str
), string_or_null (got
));
3743 auto expected_it
= expected_list
.begin ();
3744 auto expected_end
= expected_list
.end ();
3746 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3748 [&] (offset_type idx
)
3750 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3751 const char *expected_str
3752 = expected_it
== expected_end
? NULL
: *expected_it
++;
3754 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3755 mismatch (expected_str
, matched_name
);
3759 const char *expected_str
3760 = expected_it
== expected_end
? NULL
: *expected_it
++;
3761 if (expected_str
!= NULL
)
3762 mismatch (expected_str
, NULL
);
3767 /* The symbols added to the mock mapped_index for testing (in
3769 static const char *test_symbols
[] = {
3778 "ns2::tmpl<int>::foo2",
3779 "(anonymous namespace)::A::B::C",
3781 /* These are used to check that the increment-last-char in the
3782 matching algorithm for completion doesn't match "t1_fund" when
3783 completing "t1_func". */
3789 /* A UTF-8 name with multi-byte sequences to make sure that
3790 cp-name-parser understands this as a single identifier ("função"
3791 is "function" in PT). */
3794 /* \377 (0xff) is Latin1 'ÿ'. */
3797 /* \377 (0xff) is Latin1 'ÿ'. */
3801 /* A name with all sorts of complications. Starts with "z" to make
3802 it easier for the completion tests below. */
3803 #define Z_SYM_NAME \
3804 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
3805 "::tuple<(anonymous namespace)::ui*, " \
3806 "std::default_delete<(anonymous namespace)::ui>, void>"
3811 /* Returns true if the mapped_index_base::find_name_component_bounds
3812 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
3813 in completion mode. */
3816 check_find_bounds_finds (mapped_index_base
&index
,
3817 const char *search_name
,
3818 gdb::array_view
<const char *> expected_syms
,
3819 dwarf2_per_objfile
*per_objfile
)
3821 lookup_name_info
lookup_name (search_name
,
3822 symbol_name_match_type::FULL
, true);
3824 auto bounds
= index
.find_name_components_bounds (lookup_name
,
3828 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
3829 if (distance
!= expected_syms
.size ())
3832 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
3834 auto nc_elem
= bounds
.first
+ exp_elem
;
3835 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
3836 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
3843 /* Test the lower-level mapped_index::find_name_component_bounds
3847 test_mapped_index_find_name_component_bounds ()
3849 mock_mapped_index
mock_index (test_symbols
);
3851 mock_index
.build_name_components (NULL
/* per_objfile */);
3853 /* Test the lower-level mapped_index::find_name_component_bounds
3854 method in completion mode. */
3856 static const char *expected_syms
[] = {
3861 SELF_CHECK (check_find_bounds_finds
3862 (mock_index
, "t1_func", expected_syms
,
3863 NULL
/* per_objfile */));
3866 /* Check that the increment-last-char in the name matching algorithm
3867 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
3869 static const char *expected_syms1
[] = {
3873 SELF_CHECK (check_find_bounds_finds
3874 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
3876 static const char *expected_syms2
[] = {
3879 SELF_CHECK (check_find_bounds_finds
3880 (mock_index
, "\377\377", expected_syms2
,
3881 NULL
/* per_objfile */));
3885 /* Test dw2_expand_symtabs_matching_symbol. */
3888 test_dw2_expand_symtabs_matching_symbol ()
3890 mock_mapped_index
mock_index (test_symbols
);
3892 /* We let all tests run until the end even if some fails, for debug
3894 bool any_mismatch
= false;
3896 /* Create the expected symbols list (an initializer_list). Needed
3897 because lists have commas, and we need to pass them to CHECK,
3898 which is a macro. */
3899 #define EXPECT(...) { __VA_ARGS__ }
3901 /* Wrapper for check_match that passes down the current
3902 __FILE__/__LINE__. */
3903 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
3904 any_mismatch |= !check_match (__FILE__, __LINE__, \
3906 NAME, MATCH_TYPE, COMPLETION_MODE, \
3907 EXPECTED_LIST, NULL)
3909 /* Identity checks. */
3910 for (const char *sym
: test_symbols
)
3912 /* Should be able to match all existing symbols. */
3913 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
3916 /* Should be able to match all existing symbols with
3918 std::string with_params
= std::string (sym
) + "(int)";
3919 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3922 /* Should be able to match all existing symbols with
3923 parameters and qualifiers. */
3924 with_params
= std::string (sym
) + " ( int ) const";
3925 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3928 /* This should really find sym, but cp-name-parser.y doesn't
3929 know about lvalue/rvalue qualifiers yet. */
3930 with_params
= std::string (sym
) + " ( int ) &&";
3931 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
3935 /* Check that the name matching algorithm for completion doesn't get
3936 confused with Latin1 'ÿ' / 0xff. */
3938 static const char str
[] = "\377";
3939 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3940 EXPECT ("\377", "\377\377123"));
3943 /* Check that the increment-last-char in the matching algorithm for
3944 completion doesn't match "t1_fund" when completing "t1_func". */
3946 static const char str
[] = "t1_func";
3947 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
3948 EXPECT ("t1_func", "t1_func1"));
3951 /* Check that completion mode works at each prefix of the expected
3954 static const char str
[] = "function(int)";
3955 size_t len
= strlen (str
);
3958 for (size_t i
= 1; i
< len
; i
++)
3960 lookup
.assign (str
, i
);
3961 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3962 EXPECT ("function"));
3966 /* While "w" is a prefix of both components, the match function
3967 should still only be called once. */
3969 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
3971 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
3975 /* Same, with a "complicated" symbol. */
3977 static const char str
[] = Z_SYM_NAME
;
3978 size_t len
= strlen (str
);
3981 for (size_t i
= 1; i
< len
; i
++)
3983 lookup
.assign (str
, i
);
3984 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
3985 EXPECT (Z_SYM_NAME
));
3989 /* In FULL mode, an incomplete symbol doesn't match. */
3991 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
3995 /* A complete symbol with parameters matches any overload, since the
3996 index has no overload info. */
3998 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
3999 EXPECT ("std::zfunction", "std::zfunction2"));
4000 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4001 EXPECT ("std::zfunction", "std::zfunction2"));
4002 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4003 EXPECT ("std::zfunction", "std::zfunction2"));
4006 /* Check that whitespace is ignored appropriately. A symbol with a
4007 template argument list. */
4009 static const char expected
[] = "ns::foo<int>";
4010 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4012 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4016 /* Check that whitespace is ignored appropriately. A symbol with a
4017 template argument list that includes a pointer. */
4019 static const char expected
[] = "ns::foo<char*>";
4020 /* Try both completion and non-completion modes. */
4021 static const bool completion_mode
[2] = {false, true};
4022 for (size_t i
= 0; i
< 2; i
++)
4024 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4025 completion_mode
[i
], EXPECT (expected
));
4026 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4027 completion_mode
[i
], EXPECT (expected
));
4029 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4030 completion_mode
[i
], EXPECT (expected
));
4031 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4032 completion_mode
[i
], EXPECT (expected
));
4037 /* Check method qualifiers are ignored. */
4038 static const char expected
[] = "ns::foo<char*>";
4039 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4040 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4041 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4042 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4043 CHECK_MATCH ("foo < char * > ( int ) const",
4044 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4045 CHECK_MATCH ("foo < char * > ( int ) &&",
4046 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4049 /* Test lookup names that don't match anything. */
4051 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4054 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4058 /* Some wild matching tests, exercising "(anonymous namespace)",
4059 which should not be confused with a parameter list. */
4061 static const char *syms
[] = {
4065 "A :: B :: C ( int )",
4070 for (const char *s
: syms
)
4072 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4073 EXPECT ("(anonymous namespace)::A::B::C"));
4078 static const char expected
[] = "ns2::tmpl<int>::foo2";
4079 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4081 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4085 SELF_CHECK (!any_mismatch
);
4094 test_mapped_index_find_name_component_bounds ();
4095 test_dw2_expand_symtabs_matching_symbol ();
4098 }} // namespace selftests::dw2_expand_symtabs_matching
4100 #endif /* GDB_SELF_TEST */
4102 /* If FILE_MATCHER is NULL or if PER_CU has
4103 dwarf2_per_cu_quick_data::MARK set (see
4104 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4105 EXPANSION_NOTIFY on it. */
4108 dw2_expand_symtabs_matching_one
4109 (dwarf2_per_cu_data
*per_cu
,
4110 dwarf2_per_objfile
*per_objfile
,
4111 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4112 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4114 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4116 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4118 compunit_symtab
*symtab
4119 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4120 gdb_assert (symtab
!= nullptr);
4122 if (expansion_notify
!= NULL
&& symtab_was_null
)
4123 return expansion_notify (symtab
);
4128 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4129 matched, to expand corresponding CUs that were marked. IDX is the
4130 index of the symbol name that matched. */
4133 dw2_expand_marked_cus
4134 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4135 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4136 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4137 block_search_flags search_flags
,
4140 offset_type vec_len
, vec_idx
;
4141 bool global_seen
= false;
4142 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4144 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4146 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4148 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4149 /* This value is only valid for index versions >= 7. */
4150 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4151 gdb_index_symbol_kind symbol_kind
=
4152 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4153 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4154 /* Only check the symbol attributes if they're present.
4155 Indices prior to version 7 don't record them,
4156 and indices >= 7 may elide them for certain symbols
4157 (gold does this). */
4160 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4162 /* Work around gold/15646. */
4165 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4173 /* Only check the symbol's kind if it has one. */
4178 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4183 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4189 case VARIABLES_DOMAIN
:
4190 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4193 case FUNCTIONS_DOMAIN
:
4194 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4198 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4201 case MODULES_DOMAIN
:
4202 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4210 /* Don't crash on bad data. */
4211 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4213 complaint (_(".gdb_index entry has bad CU index"
4214 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4218 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4219 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4227 /* If FILE_MATCHER is non-NULL, set all the
4228 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4229 that match FILE_MATCHER. */
4232 dw_expand_symtabs_matching_file_matcher
4233 (dwarf2_per_objfile
*per_objfile
,
4234 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4236 if (file_matcher
== NULL
)
4239 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4241 NULL
, xcalloc
, xfree
));
4242 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4244 NULL
, xcalloc
, xfree
));
4246 /* The rule is CUs specify all the files, including those used by
4247 any TU, so there's no need to scan TUs here. */
4249 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4253 if (per_cu
->is_debug_types
)
4255 per_cu
->v
.quick
->mark
= 0;
4257 /* We only need to look at symtabs not already expanded. */
4258 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4261 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4263 if (file_data
== NULL
)
4266 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4268 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4270 per_cu
->v
.quick
->mark
= 1;
4274 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4276 const char *this_real_name
;
4278 if (file_matcher (file_data
->file_names
[j
], false))
4280 per_cu
->v
.quick
->mark
= 1;
4284 /* Before we invoke realpath, which can get expensive when many
4285 files are involved, do a quick comparison of the basenames. */
4286 if (!basenames_may_differ
4287 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4291 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4292 if (file_matcher (this_real_name
, false))
4294 per_cu
->v
.quick
->mark
= 1;
4299 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4300 ? visited_found
.get ()
4301 : visited_not_found
.get (),
4308 dwarf2_gdb_index::expand_symtabs_matching
4309 (struct objfile
*objfile
,
4310 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4311 const lookup_name_info
*lookup_name
,
4312 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4313 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4314 block_search_flags search_flags
,
4316 enum search_domain kind
)
4318 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4320 /* index_table is NULL if OBJF_READNOW. */
4321 if (!per_objfile
->per_bfd
->index_table
)
4324 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4326 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4328 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4332 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
4340 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4343 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4345 [&] (offset_type idx
)
4347 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4348 expansion_notify
, search_flags
, kind
))
4356 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4359 static struct compunit_symtab
*
4360 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4365 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4366 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4369 if (cust
->includes
== NULL
)
4372 for (i
= 0; cust
->includes
[i
]; ++i
)
4374 struct compunit_symtab
*s
= cust
->includes
[i
];
4376 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4384 struct compunit_symtab
*
4385 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4386 (struct objfile
*objfile
,
4387 struct bound_minimal_symbol msymbol
,
4389 struct obj_section
*section
,
4392 struct dwarf2_per_cu_data
*data
;
4393 struct compunit_symtab
*result
;
4395 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4396 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4399 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4400 data
= ((struct dwarf2_per_cu_data
*)
4401 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4406 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4407 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4408 paddress (objfile
->arch (), pc
));
4410 result
= recursively_find_pc_sect_compunit_symtab
4411 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4413 gdb_assert (result
!= NULL
);
4418 dwarf2_base_index_functions::map_symbol_filenames
4419 (struct objfile
*objfile
,
4420 gdb::function_view
<symbol_filename_ftype
> fun
,
4423 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4425 /* Use caches to ensure we only call FUN once for each filename. */
4426 filename_seen_cache filenames_cache
;
4427 std::unordered_set
<quick_file_names
*> qfn_cache
;
4429 /* The rule is CUs specify all the files, including those used by any TU,
4430 so there's no need to scan TUs here. We can ignore file names coming
4431 from already-expanded CUs. It is possible that an expanded CU might
4432 reuse the file names data from a currently unexpanded CU, in this
4433 case we don't want to report the files from the unexpanded CU. */
4435 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4437 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4439 if (per_cu
->v
.quick
->file_names
!= nullptr)
4440 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4444 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4446 /* We only need to look at symtabs not already expanded. */
4447 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4450 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4452 if (file_data
== nullptr
4453 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4456 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4458 const char *filename
= file_data
->file_names
[j
];
4459 filenames_cache
.seen (filename
);
4463 filenames_cache
.traverse ([&] (const char *filename
)
4465 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4468 this_real_name
= gdb_realpath (filename
);
4469 fun (filename
, this_real_name
.get ());
4474 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4479 /* DWARF-5 debug_names reader. */
4481 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4482 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4484 /* A helper function that reads the .debug_names section in SECTION
4485 and fills in MAP. FILENAME is the name of the file containing the
4486 section; it is used for error reporting.
4488 Returns true if all went well, false otherwise. */
4491 read_debug_names_from_section (struct objfile
*objfile
,
4492 const char *filename
,
4493 struct dwarf2_section_info
*section
,
4494 mapped_debug_names
&map
)
4496 if (section
->empty ())
4499 /* Older elfutils strip versions could keep the section in the main
4500 executable while splitting it for the separate debug info file. */
4501 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4504 section
->read (objfile
);
4506 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4508 const gdb_byte
*addr
= section
->buffer
;
4510 bfd
*const abfd
= section
->get_bfd_owner ();
4512 unsigned int bytes_read
;
4513 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4516 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4517 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4518 if (bytes_read
+ length
!= section
->size
)
4520 /* There may be multiple per-CU indices. */
4521 warning (_("Section .debug_names in %s length %s does not match "
4522 "section length %s, ignoring .debug_names."),
4523 filename
, plongest (bytes_read
+ length
),
4524 pulongest (section
->size
));
4528 /* The version number. */
4529 uint16_t version
= read_2_bytes (abfd
, addr
);
4533 warning (_("Section .debug_names in %s has unsupported version %d, "
4534 "ignoring .debug_names."),
4540 uint16_t padding
= read_2_bytes (abfd
, addr
);
4544 warning (_("Section .debug_names in %s has unsupported padding %d, "
4545 "ignoring .debug_names."),
4550 /* comp_unit_count - The number of CUs in the CU list. */
4551 map
.cu_count
= read_4_bytes (abfd
, addr
);
4554 /* local_type_unit_count - The number of TUs in the local TU
4556 map
.tu_count
= read_4_bytes (abfd
, addr
);
4559 /* foreign_type_unit_count - The number of TUs in the foreign TU
4561 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4563 if (foreign_tu_count
!= 0)
4565 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4566 "ignoring .debug_names."),
4567 filename
, static_cast<unsigned long> (foreign_tu_count
));
4571 /* bucket_count - The number of hash buckets in the hash lookup
4573 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4576 /* name_count - The number of unique names in the index. */
4577 map
.name_count
= read_4_bytes (abfd
, addr
);
4580 /* abbrev_table_size - The size in bytes of the abbreviations
4582 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4585 /* augmentation_string_size - The size in bytes of the augmentation
4586 string. This value is rounded up to a multiple of 4. */
4587 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4589 map
.augmentation_is_gdb
= ((augmentation_string_size
4590 == sizeof (dwarf5_augmentation
))
4591 && memcmp (addr
, dwarf5_augmentation
,
4592 sizeof (dwarf5_augmentation
)) == 0);
4593 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4594 addr
+= augmentation_string_size
;
4597 map
.cu_table_reordered
= addr
;
4598 addr
+= map
.cu_count
* map
.offset_size
;
4600 /* List of Local TUs */
4601 map
.tu_table_reordered
= addr
;
4602 addr
+= map
.tu_count
* map
.offset_size
;
4604 /* Hash Lookup Table */
4605 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4606 addr
+= map
.bucket_count
* 4;
4607 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4608 addr
+= map
.name_count
* 4;
4611 map
.name_table_string_offs_reordered
= addr
;
4612 addr
+= map
.name_count
* map
.offset_size
;
4613 map
.name_table_entry_offs_reordered
= addr
;
4614 addr
+= map
.name_count
* map
.offset_size
;
4616 const gdb_byte
*abbrev_table_start
= addr
;
4619 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4624 const auto insertpair
4625 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4626 if (!insertpair
.second
)
4628 warning (_("Section .debug_names in %s has duplicate index %s, "
4629 "ignoring .debug_names."),
4630 filename
, pulongest (index_num
));
4633 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4634 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4639 mapped_debug_names::index_val::attr attr
;
4640 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4642 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4644 if (attr
.form
== DW_FORM_implicit_const
)
4646 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4650 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4652 indexval
.attr_vec
.push_back (std::move (attr
));
4655 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4657 warning (_("Section .debug_names in %s has abbreviation_table "
4658 "of size %s vs. written as %u, ignoring .debug_names."),
4659 filename
, plongest (addr
- abbrev_table_start
),
4663 map
.entry_pool
= addr
;
4668 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4672 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4673 const mapped_debug_names
&map
,
4674 dwarf2_section_info
§ion
,
4677 if (!map
.augmentation_is_gdb
)
4679 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4681 sect_offset sect_off
4682 = (sect_offset
) (extract_unsigned_integer
4683 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4685 map
.dwarf5_byte_order
));
4686 /* We don't know the length of the CU, because the CU list in a
4687 .debug_names index can be incomplete, so we can't use the start
4688 of the next CU as end of this CU. We create the CUs here with
4689 length 0, and in cutu_reader::cutu_reader we'll fill in the
4691 dwarf2_per_cu_data_up per_cu
4692 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4694 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4699 sect_offset sect_off_prev
;
4700 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4702 sect_offset sect_off_next
;
4703 if (i
< map
.cu_count
)
4706 = (sect_offset
) (extract_unsigned_integer
4707 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4709 map
.dwarf5_byte_order
));
4712 sect_off_next
= (sect_offset
) section
.size
;
4715 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4716 dwarf2_per_cu_data_up per_cu
4717 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4718 sect_off_prev
, length
);
4719 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4721 sect_off_prev
= sect_off_next
;
4725 /* Read the CU list from the mapped index, and use it to create all
4726 the CU objects for this dwarf2_per_objfile. */
4729 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4730 const mapped_debug_names
&map
,
4731 const mapped_debug_names
&dwz_map
)
4733 gdb_assert (per_bfd
->all_comp_units
.empty ());
4734 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4736 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4737 false /* is_dwz */);
4739 if (dwz_map
.cu_count
== 0)
4742 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4743 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4747 /* Read .debug_names. If everything went ok, initialize the "quick"
4748 elements of all the CUs and return true. Otherwise, return false. */
4751 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4753 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4754 mapped_debug_names dwz_map
;
4755 struct objfile
*objfile
= per_objfile
->objfile
;
4756 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4758 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4759 &per_bfd
->debug_names
, *map
))
4762 /* Don't use the index if it's empty. */
4763 if (map
->name_count
== 0)
4766 /* If there is a .dwz file, read it so we can get its CU list as
4768 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4771 if (!read_debug_names_from_section (objfile
,
4772 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4773 &dwz
->debug_names
, dwz_map
))
4775 warning (_("could not read '.debug_names' section from %s; skipping"),
4776 bfd_get_filename (dwz
->dwz_bfd
.get ()));
4781 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
4783 if (map
->tu_count
!= 0)
4785 /* We can only handle a single .debug_types when we have an
4787 if (per_bfd
->types
.size () != 1)
4790 dwarf2_section_info
*section
= &per_bfd
->types
[0];
4792 create_signatured_type_table_from_debug_names
4793 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
4796 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
4798 per_bfd
->debug_names_table
= std::move (map
);
4799 per_bfd
->using_index
= 1;
4800 per_bfd
->quick_file_names_table
=
4801 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
4806 /* Type used to manage iterating over all CUs looking for a symbol for
4809 class dw2_debug_names_iterator
4812 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4813 block_search_flags block_index
,
4815 const char *name
, dwarf2_per_objfile
*per_objfile
)
4816 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4817 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
4818 m_per_objfile (per_objfile
)
4821 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4822 search_domain search
, uint32_t namei
,
4823 dwarf2_per_objfile
*per_objfile
,
4824 domain_enum domain
= UNDEF_DOMAIN
)
4828 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4829 m_per_objfile (per_objfile
)
4832 dw2_debug_names_iterator (const mapped_debug_names
&map
,
4833 block_search_flags block_index
, domain_enum domain
,
4834 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4835 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
4836 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
4837 m_per_objfile (per_objfile
)
4840 /* Return the next matching CU or NULL if there are no more. */
4841 dwarf2_per_cu_data
*next ();
4844 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4846 dwarf2_per_objfile
*per_objfile
);
4847 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
4849 dwarf2_per_objfile
*per_objfile
);
4851 /* The internalized form of .debug_names. */
4852 const mapped_debug_names
&m_map
;
4854 /* Restrict the search to these blocks. */
4855 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
4856 | SEARCH_STATIC_BLOCK
);
4858 /* The kind of symbol we're looking for. */
4859 const domain_enum m_domain
= UNDEF_DOMAIN
;
4860 const search_domain m_search
= ALL_DOMAIN
;
4862 /* The list of CUs from the index entry of the symbol, or NULL if
4864 const gdb_byte
*m_addr
;
4866 dwarf2_per_objfile
*m_per_objfile
;
4870 mapped_debug_names::namei_to_name
4871 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
4873 const ULONGEST namei_string_offs
4874 = extract_unsigned_integer ((name_table_string_offs_reordered
4875 + namei
* offset_size
),
4878 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
4881 /* Find a slot in .debug_names for the object named NAME. If NAME is
4882 found, return pointer to its pool data. If NAME cannot be found,
4886 dw2_debug_names_iterator::find_vec_in_debug_names
4887 (const mapped_debug_names
&map
, const char *name
,
4888 dwarf2_per_objfile
*per_objfile
)
4890 int (*cmp
) (const char *, const char *);
4892 gdb::unique_xmalloc_ptr
<char> without_params
;
4893 if (current_language
->la_language
== language_cplus
4894 || current_language
->la_language
== language_fortran
4895 || current_language
->la_language
== language_d
)
4897 /* NAME is already canonical. Drop any qualifiers as
4898 .debug_names does not contain any. */
4900 if (strchr (name
, '(') != NULL
)
4902 without_params
= cp_remove_params (name
);
4903 if (without_params
!= NULL
)
4904 name
= without_params
.get ();
4908 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
4910 const uint32_t full_hash
= dwarf5_djb_hash (name
);
4912 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4913 (map
.bucket_table_reordered
4914 + (full_hash
% map
.bucket_count
)), 4,
4915 map
.dwarf5_byte_order
);
4919 if (namei
>= map
.name_count
)
4921 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4923 namei
, map
.name_count
,
4924 objfile_name (per_objfile
->objfile
));
4930 const uint32_t namei_full_hash
4931 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
4932 (map
.hash_table_reordered
+ namei
), 4,
4933 map
.dwarf5_byte_order
);
4934 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
4937 if (full_hash
== namei_full_hash
)
4939 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
4941 #if 0 /* An expensive sanity check. */
4942 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
4944 complaint (_("Wrong .debug_names hash for string at index %u "
4946 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
4951 if (cmp (namei_string
, name
) == 0)
4953 const ULONGEST namei_entry_offs
4954 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4955 + namei
* map
.offset_size
),
4956 map
.offset_size
, map
.dwarf5_byte_order
);
4957 return map
.entry_pool
+ namei_entry_offs
;
4962 if (namei
>= map
.name_count
)
4968 dw2_debug_names_iterator::find_vec_in_debug_names
4969 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
4971 if (namei
>= map
.name_count
)
4973 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
4975 namei
, map
.name_count
,
4976 objfile_name (per_objfile
->objfile
));
4980 const ULONGEST namei_entry_offs
4981 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
4982 + namei
* map
.offset_size
),
4983 map
.offset_size
, map
.dwarf5_byte_order
);
4984 return map
.entry_pool
+ namei_entry_offs
;
4987 /* See dw2_debug_names_iterator. */
4989 dwarf2_per_cu_data
*
4990 dw2_debug_names_iterator::next ()
4995 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
4996 struct objfile
*objfile
= m_per_objfile
->objfile
;
4997 bfd
*const abfd
= objfile
->obfd
;
5001 unsigned int bytes_read
;
5002 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5003 m_addr
+= bytes_read
;
5007 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5008 if (indexval_it
== m_map
.abbrev_map
.cend ())
5010 complaint (_("Wrong .debug_names undefined abbrev code %s "
5012 pulongest (abbrev
), objfile_name (objfile
));
5015 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5016 enum class symbol_linkage
{
5020 } symbol_linkage_
= symbol_linkage::unknown
;
5021 dwarf2_per_cu_data
*per_cu
= NULL
;
5022 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5027 case DW_FORM_implicit_const
:
5028 ull
= attr
.implicit_const
;
5030 case DW_FORM_flag_present
:
5034 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5035 m_addr
+= bytes_read
;
5038 ull
= read_4_bytes (abfd
, m_addr
);
5042 ull
= read_8_bytes (abfd
, m_addr
);
5045 case DW_FORM_ref_sig8
:
5046 ull
= read_8_bytes (abfd
, m_addr
);
5050 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5051 dwarf_form_name (attr
.form
),
5052 objfile_name (objfile
));
5055 switch (attr
.dw_idx
)
5057 case DW_IDX_compile_unit
:
5058 /* Don't crash on bad data. */
5059 if (ull
>= per_bfd
->all_comp_units
.size ())
5061 complaint (_(".debug_names entry has bad CU index %s"
5064 objfile_name (objfile
));
5067 per_cu
= per_bfd
->get_cu (ull
);
5069 case DW_IDX_type_unit
:
5070 /* Don't crash on bad data. */
5071 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5073 complaint (_(".debug_names entry has bad TU index %s"
5076 objfile_name (objfile
));
5079 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5081 case DW_IDX_die_offset
:
5082 /* In a per-CU index (as opposed to a per-module index), index
5083 entries without CU attribute implicitly refer to the single CU. */
5085 per_cu
= per_bfd
->get_cu (0);
5087 case DW_IDX_GNU_internal
:
5088 if (!m_map
.augmentation_is_gdb
)
5090 symbol_linkage_
= symbol_linkage::static_
;
5092 case DW_IDX_GNU_external
:
5093 if (!m_map
.augmentation_is_gdb
)
5095 symbol_linkage_
= symbol_linkage::extern_
;
5100 /* Skip if already read in. */
5101 if (m_per_objfile
->symtab_set_p (per_cu
))
5104 /* Check static vs global. */
5105 if (symbol_linkage_
!= symbol_linkage::unknown
)
5107 if (symbol_linkage_
== symbol_linkage::static_
)
5109 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5114 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5119 /* Match dw2_symtab_iter_next, symbol_kind
5120 and debug_names::psymbol_tag. */
5124 switch (indexval
.dwarf_tag
)
5126 case DW_TAG_variable
:
5127 case DW_TAG_subprogram
:
5128 /* Some types are also in VAR_DOMAIN. */
5129 case DW_TAG_typedef
:
5130 case DW_TAG_structure_type
:
5137 switch (indexval
.dwarf_tag
)
5139 case DW_TAG_typedef
:
5140 case DW_TAG_structure_type
:
5147 switch (indexval
.dwarf_tag
)
5150 case DW_TAG_variable
:
5157 switch (indexval
.dwarf_tag
)
5169 /* Match dw2_expand_symtabs_matching, symbol_kind and
5170 debug_names::psymbol_tag. */
5173 case VARIABLES_DOMAIN
:
5174 switch (indexval
.dwarf_tag
)
5176 case DW_TAG_variable
:
5182 case FUNCTIONS_DOMAIN
:
5183 switch (indexval
.dwarf_tag
)
5185 case DW_TAG_subprogram
:
5192 switch (indexval
.dwarf_tag
)
5194 case DW_TAG_typedef
:
5195 case DW_TAG_structure_type
:
5201 case MODULES_DOMAIN
:
5202 switch (indexval
.dwarf_tag
)
5216 /* This dumps minimal information about .debug_names. It is called
5217 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5218 uses this to verify that .debug_names has been loaded. */
5221 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5223 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5225 gdb_assert (per_objfile
->per_bfd
->using_index
);
5226 printf_filtered (".debug_names:");
5227 if (per_objfile
->per_bfd
->debug_names_table
)
5228 printf_filtered (" exists\n");
5230 printf_filtered (" faked for \"readnow\"\n");
5231 printf_filtered ("\n");
5235 dwarf2_debug_names_index::expand_matching_symbols
5236 (struct objfile
*objfile
,
5237 const lookup_name_info
&name
, domain_enum domain
,
5239 symbol_compare_ftype
*ordered_compare
)
5241 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5243 /* debug_names_table is NULL if OBJF_READNOW. */
5244 if (!per_objfile
->per_bfd
->debug_names_table
)
5247 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5248 const block_search_flags block_flags
5249 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5251 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5252 auto matcher
= [&] (const char *symname
)
5254 if (ordered_compare
== nullptr)
5256 return ordered_compare (symname
, match_name
) == 0;
5259 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5260 [&] (offset_type namei
)
5262 /* The name was matched, now expand corresponding CUs that were
5264 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5267 struct dwarf2_per_cu_data
*per_cu
;
5268 while ((per_cu
= iter
.next ()) != NULL
)
5269 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5276 dwarf2_debug_names_index::expand_symtabs_matching
5277 (struct objfile
*objfile
,
5278 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5279 const lookup_name_info
*lookup_name
,
5280 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5281 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5282 block_search_flags search_flags
,
5284 enum search_domain kind
)
5286 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5288 /* debug_names_table is NULL if OBJF_READNOW. */
5289 if (!per_objfile
->per_bfd
->debug_names_table
)
5292 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5294 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5296 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5300 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
5308 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5311 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5313 [&] (offset_type namei
)
5315 /* The name was matched, now expand corresponding CUs that were
5317 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5319 struct dwarf2_per_cu_data
*per_cu
;
5320 while ((per_cu
= iter
.next ()) != NULL
)
5321 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5331 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5332 to either a dwarf2_per_bfd or dwz_file object. */
5334 template <typename T
>
5335 static gdb::array_view
<const gdb_byte
>
5336 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5338 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5340 if (section
->empty ())
5343 /* Older elfutils strip versions could keep the section in the main
5344 executable while splitting it for the separate debug info file. */
5345 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5348 section
->read (obj
);
5350 /* dwarf2_section_info::size is a bfd_size_type, while
5351 gdb::array_view works with size_t. On 32-bit hosts, with
5352 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5353 is 32-bit. So we need an explicit narrowing conversion here.
5354 This is fine, because it's impossible to allocate or mmap an
5355 array/buffer larger than what size_t can represent. */
5356 return gdb::make_array_view (section
->buffer
, section
->size
);
5359 /* Lookup the index cache for the contents of the index associated to
5362 static gdb::array_view
<const gdb_byte
>
5363 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5365 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5366 if (build_id
== nullptr)
5369 return global_index_cache
.lookup_gdb_index (build_id
,
5370 &dwarf2_per_bfd
->index_cache_res
);
5373 /* Same as the above, but for DWZ. */
5375 static gdb::array_view
<const gdb_byte
>
5376 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5378 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5379 if (build_id
== nullptr)
5382 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5385 /* See dwarf2/public.h. */
5388 dwarf2_initialize_objfile (struct objfile
*objfile
)
5390 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5391 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5393 dwarf_read_debug_printf ("called");
5395 /* If we're about to read full symbols, don't bother with the
5396 indices. In this case we also don't care if some other debug
5397 format is making psymtabs, because they are all about to be
5399 if ((objfile
->flags
& OBJF_READNOW
))
5401 dwarf_read_debug_printf ("readnow requested");
5403 /* When using READNOW, the using_index flag (set below) indicates that
5404 PER_BFD was already initialized, when we loaded some other objfile. */
5405 if (per_bfd
->using_index
)
5407 dwarf_read_debug_printf ("using_index already set");
5408 per_objfile
->resize_symtabs ();
5409 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5413 per_bfd
->using_index
= 1;
5414 create_all_comp_units (per_objfile
);
5415 per_bfd
->quick_file_names_table
5416 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5417 per_objfile
->resize_symtabs ();
5419 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5421 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5423 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5424 struct dwarf2_per_cu_quick_data
);
5427 /* Arrange for gdb to see the "quick" functions. However, these
5428 functions will be no-ops because we will have expanded all
5430 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5434 /* Was a debug names index already read when we processed an objfile sharing
5436 if (per_bfd
->debug_names_table
!= nullptr)
5438 dwarf_read_debug_printf ("re-using shared debug names table");
5439 per_objfile
->resize_symtabs ();
5440 objfile
->qf
.push_front (make_dwarf_debug_names ());
5444 /* Was a GDB index already read when we processed an objfile sharing
5446 if (per_bfd
->index_table
!= nullptr)
5448 dwarf_read_debug_printf ("re-using shared index table");
5449 per_objfile
->resize_symtabs ();
5450 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5454 /* There might already be partial symtabs built for this BFD. This happens
5455 when loading the same binary twice with the index-cache enabled. If so,
5456 don't try to read an index. The objfile / per_objfile initialization will
5457 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5459 if (per_bfd
->partial_symtabs
!= nullptr)
5461 dwarf_read_debug_printf ("re-using shared partial symtabs");
5462 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5466 if (dwarf2_read_debug_names (per_objfile
))
5468 dwarf_read_debug_printf ("found debug names");
5469 per_objfile
->resize_symtabs ();
5470 objfile
->qf
.push_front (make_dwarf_debug_names ());
5474 if (dwarf2_read_gdb_index (per_objfile
,
5475 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5476 get_gdb_index_contents_from_section
<dwz_file
>))
5478 dwarf_read_debug_printf ("found gdb index from file");
5479 per_objfile
->resize_symtabs ();
5480 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5484 /* ... otherwise, try to find the index in the index cache. */
5485 if (dwarf2_read_gdb_index (per_objfile
,
5486 get_gdb_index_contents_from_cache
,
5487 get_gdb_index_contents_from_cache_dwz
))
5489 dwarf_read_debug_printf ("found gdb index from cache");
5490 global_index_cache
.hit ();
5491 per_objfile
->resize_symtabs ();
5492 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5496 global_index_cache
.miss ();
5497 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5502 /* Build a partial symbol table. */
5505 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5507 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5508 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5510 if (per_bfd
->partial_symtabs
!= nullptr)
5512 /* Partial symbols were already read, so now we can simply
5516 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5517 objfile
->qf
.emplace_front (psf
);
5520 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5521 per_objfile
->resize_symtabs ();
5527 psf
= new psymbol_functions
;
5528 objfile
->qf
.emplace_front (psf
);
5530 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5531 = psf
->get_partial_symtabs ();
5533 /* Set the local reference to partial symtabs, so that we don't try
5534 to read them again if reading another objfile with the same BFD.
5535 If we can't in fact share, this won't make a difference anyway as
5536 the dwarf2_per_bfd object won't be shared. */
5537 per_bfd
->partial_symtabs
= partial_symtabs
;
5541 /* This isn't really ideal: all the data we allocate on the
5542 objfile's obstack is still uselessly kept around. However,
5543 freeing it seems unsafe. */
5544 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5545 dwarf2_build_psymtabs_hard (per_objfile
);
5548 per_objfile
->resize_symtabs ();
5550 /* (maybe) store an index in the cache. */
5551 global_index_cache
.store (per_objfile
);
5553 catch (const gdb_exception_error
&except
)
5555 exception_print (gdb_stderr
, except
);
5559 /* Find the base address of the compilation unit for range lists and
5560 location lists. It will normally be specified by DW_AT_low_pc.
5561 In DWARF-3 draft 4, the base address could be overridden by
5562 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5563 compilation units with discontinuous ranges. */
5566 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5568 struct attribute
*attr
;
5570 cu
->base_address
.reset ();
5572 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5573 if (attr
!= nullptr)
5574 cu
->base_address
= attr
->as_address ();
5577 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5578 if (attr
!= nullptr)
5579 cu
->base_address
= attr
->as_address ();
5583 /* Helper function that returns the proper abbrev section for
5586 static struct dwarf2_section_info
*
5587 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5589 struct dwarf2_section_info
*abbrev
;
5590 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5592 if (this_cu
->is_dwz
)
5593 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5595 abbrev
= &per_bfd
->abbrev
;
5600 /* Fetch the abbreviation table offset from a comp or type unit header. */
5603 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5604 struct dwarf2_section_info
*section
,
5605 sect_offset sect_off
)
5607 bfd
*abfd
= section
->get_bfd_owner ();
5608 const gdb_byte
*info_ptr
;
5609 unsigned int initial_length_size
, offset_size
;
5612 section
->read (per_objfile
->objfile
);
5613 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5614 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5615 offset_size
= initial_length_size
== 4 ? 4 : 8;
5616 info_ptr
+= initial_length_size
;
5618 version
= read_2_bytes (abfd
, info_ptr
);
5622 /* Skip unit type and address size. */
5626 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5629 /* A partial symtab that is used only for include files. */
5630 struct dwarf2_include_psymtab
: public partial_symtab
5632 dwarf2_include_psymtab (const char *filename
,
5633 psymtab_storage
*partial_symtabs
,
5634 objfile_per_bfd_storage
*objfile_per_bfd
)
5635 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5639 void read_symtab (struct objfile
*objfile
) override
5641 /* It's an include file, no symbols to read for it.
5642 Everything is in the includer symtab. */
5644 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5645 expansion of the includer psymtab. We use the dependencies[0] field to
5646 model the includer. But if we go the regular route of calling
5647 expand_psymtab here, and having expand_psymtab call expand_dependencies
5648 to expand the includer, we'll only use expand_psymtab on the includer
5649 (making it a non-toplevel psymtab), while if we expand the includer via
5650 another path, we'll use read_symtab (making it a toplevel psymtab).
5651 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5652 psymtab, and trigger read_symtab on the includer here directly. */
5653 includer ()->read_symtab (objfile
);
5656 void expand_psymtab (struct objfile
*objfile
) override
5658 /* This is not called by read_symtab, and should not be called by any
5659 expand_dependencies. */
5663 bool readin_p (struct objfile
*objfile
) const override
5665 return includer ()->readin_p (objfile
);
5668 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5674 partial_symtab
*includer () const
5676 /* An include psymtab has exactly one dependency: the psymtab that
5678 gdb_assert (this->number_of_dependencies
== 1);
5679 return this->dependencies
[0];
5683 /* Allocate a new partial symtab for file named NAME and mark this new
5684 partial symtab as being an include of PST. */
5687 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5689 dwarf2_psymtab
*pst
,
5690 psymtab_storage
*partial_symtabs
,
5691 objfile_per_bfd_storage
*objfile_per_bfd
)
5693 dwarf2_include_psymtab
*subpst
5694 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5696 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5697 subpst
->dirname
= pst
->dirname
;
5699 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5700 subpst
->dependencies
[0] = pst
;
5701 subpst
->number_of_dependencies
= 1;
5704 /* Read the Line Number Program data and extract the list of files
5705 included by the source file represented by PST. Build an include
5706 partial symtab for each of these included files. */
5709 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5710 struct die_info
*die
,
5711 dwarf2_psymtab
*pst
)
5714 struct attribute
*attr
;
5716 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5717 if (attr
!= nullptr && attr
->form_is_unsigned ())
5718 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5720 return; /* No linetable, so no includes. */
5722 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5723 that we pass in the raw text_low here; that is ok because we're
5724 only decoding the line table to make include partial symtabs, and
5725 so the addresses aren't really used. */
5726 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5727 pst
->raw_text_low (), 1);
5731 hash_signatured_type (const void *item
)
5733 const struct signatured_type
*sig_type
5734 = (const struct signatured_type
*) item
;
5736 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5737 return sig_type
->signature
;
5741 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5743 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5744 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5746 return lhs
->signature
== rhs
->signature
;
5749 /* Allocate a hash table for signatured types. */
5752 allocate_signatured_type_table ()
5754 return htab_up (htab_create_alloc (41,
5755 hash_signatured_type
,
5757 NULL
, xcalloc
, xfree
));
5760 /* A helper for create_debug_types_hash_table. Read types from SECTION
5761 and fill them into TYPES_HTAB. It will process only type units,
5762 therefore DW_UT_type. */
5765 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
5766 struct dwo_file
*dwo_file
,
5767 dwarf2_section_info
*section
, htab_up
&types_htab
,
5768 rcuh_kind section_kind
)
5770 struct objfile
*objfile
= per_objfile
->objfile
;
5771 struct dwarf2_section_info
*abbrev_section
;
5773 const gdb_byte
*info_ptr
, *end_ptr
;
5775 abbrev_section
= &dwo_file
->sections
.abbrev
;
5777 dwarf_read_debug_printf ("Reading %s for %s",
5778 section
->get_name (),
5779 abbrev_section
->get_file_name ());
5781 section
->read (objfile
);
5782 info_ptr
= section
->buffer
;
5784 if (info_ptr
== NULL
)
5787 /* We can't set abfd until now because the section may be empty or
5788 not present, in which case the bfd is unknown. */
5789 abfd
= section
->get_bfd_owner ();
5791 /* We don't use cutu_reader here because we don't need to read
5792 any dies: the signature is in the header. */
5794 end_ptr
= info_ptr
+ section
->size
;
5795 while (info_ptr
< end_ptr
)
5797 signatured_type_up sig_type
;
5798 struct dwo_unit
*dwo_tu
;
5800 const gdb_byte
*ptr
= info_ptr
;
5801 struct comp_unit_head header
;
5802 unsigned int length
;
5804 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
5806 /* Initialize it due to a false compiler warning. */
5807 header
.signature
= -1;
5808 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
5810 /* We need to read the type's signature in order to build the hash
5811 table, but we don't need anything else just yet. */
5813 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
5814 abbrev_section
, ptr
, section_kind
);
5816 length
= header
.get_length ();
5818 /* Skip dummy type units. */
5819 if (ptr
>= info_ptr
+ length
5820 || peek_abbrev_code (abfd
, ptr
) == 0
5821 || (header
.unit_type
!= DW_UT_type
5822 && header
.unit_type
!= DW_UT_split_type
))
5828 if (types_htab
== NULL
)
5829 types_htab
= allocate_dwo_unit_table ();
5831 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
5832 dwo_tu
->dwo_file
= dwo_file
;
5833 dwo_tu
->signature
= header
.signature
;
5834 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
5835 dwo_tu
->section
= section
;
5836 dwo_tu
->sect_off
= sect_off
;
5837 dwo_tu
->length
= length
;
5839 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
5840 gdb_assert (slot
!= NULL
);
5842 complaint (_("debug type entry at offset %s is duplicate to"
5843 " the entry at offset %s, signature %s"),
5844 sect_offset_str (sect_off
),
5845 sect_offset_str (dwo_tu
->sect_off
),
5846 hex_string (header
.signature
));
5849 dwarf_read_debug_printf_v (" offset %s, signature %s",
5850 sect_offset_str (sect_off
),
5851 hex_string (header
.signature
));
5857 /* Create the hash table of all entries in the .debug_types
5858 (or .debug_types.dwo) section(s).
5859 DWO_FILE is a pointer to the DWO file object.
5861 The result is a pointer to the hash table or NULL if there are no types.
5863 Note: This function processes DWO files only, not DWP files. */
5866 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
5867 struct dwo_file
*dwo_file
,
5868 gdb::array_view
<dwarf2_section_info
> type_sections
,
5869 htab_up
&types_htab
)
5871 for (dwarf2_section_info
§ion
: type_sections
)
5872 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
5876 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
5877 If SLOT is non-NULL, it is the entry to use in the hash table.
5878 Otherwise we find one. */
5880 static struct signatured_type
*
5881 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
5883 if (per_objfile
->per_bfd
->all_comp_units
.size ()
5884 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
5885 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
5887 signatured_type_up sig_type_holder
5888 = per_objfile
->per_bfd
->allocate_signatured_type (sig
);
5889 signatured_type
*sig_type
= sig_type_holder
.get ();
5891 per_objfile
->resize_symtabs ();
5893 per_objfile
->per_bfd
->all_comp_units
.emplace_back
5894 (sig_type_holder
.release ());
5895 if (per_objfile
->per_bfd
->using_index
)
5898 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
5899 struct dwarf2_per_cu_quick_data
);
5904 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5907 gdb_assert (*slot
== NULL
);
5909 /* The rest of sig_type must be filled in by the caller. */
5913 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
5914 Fill in SIG_ENTRY with DWO_ENTRY. */
5917 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
5918 struct signatured_type
*sig_entry
,
5919 struct dwo_unit
*dwo_entry
)
5921 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5923 /* Make sure we're not clobbering something we don't expect to. */
5924 gdb_assert (! sig_entry
->queued
);
5925 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
5926 if (per_bfd
->using_index
)
5928 gdb_assert (sig_entry
->v
.quick
!= NULL
);
5929 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
5932 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
5933 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
5934 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
5935 gdb_assert (sig_entry
->type_unit_group
== NULL
);
5936 gdb_assert (sig_entry
->dwo_unit
== NULL
);
5938 sig_entry
->section
= dwo_entry
->section
;
5939 sig_entry
->sect_off
= dwo_entry
->sect_off
;
5940 sig_entry
->length
= dwo_entry
->length
;
5941 sig_entry
->reading_dwo_directly
= 1;
5942 sig_entry
->per_bfd
= per_bfd
;
5943 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
5944 sig_entry
->dwo_unit
= dwo_entry
;
5947 /* Subroutine of lookup_signatured_type.
5948 If we haven't read the TU yet, create the signatured_type data structure
5949 for a TU to be read in directly from a DWO file, bypassing the stub.
5950 This is the "Stay in DWO Optimization": When there is no DWP file and we're
5951 using .gdb_index, then when reading a CU we want to stay in the DWO file
5952 containing that CU. Otherwise we could end up reading several other DWO
5953 files (due to comdat folding) to process the transitive closure of all the
5954 mentioned TUs, and that can be slow. The current DWO file will have every
5955 type signature that it needs.
5956 We only do this for .gdb_index because in the psymtab case we already have
5957 to read all the DWOs to build the type unit groups. */
5959 static struct signatured_type
*
5960 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
5962 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
5963 struct dwo_file
*dwo_file
;
5964 struct dwo_unit find_dwo_entry
, *dwo_entry
;
5967 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
5969 /* If TU skeletons have been removed then we may not have read in any
5971 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
5972 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
5974 /* We only ever need to read in one copy of a signatured type.
5975 Use the global signatured_types array to do our own comdat-folding
5976 of types. If this is the first time we're reading this TU, and
5977 the TU has an entry in .gdb_index, replace the recorded data from
5978 .gdb_index with this TU. */
5980 signatured_type
find_sig_entry (sig
);
5981 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
5982 &find_sig_entry
, INSERT
);
5983 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
5985 /* We can get here with the TU already read, *or* in the process of being
5986 read. Don't reassign the global entry to point to this DWO if that's
5987 the case. Also note that if the TU is already being read, it may not
5988 have come from a DWO, the program may be a mix of Fission-compiled
5989 code and non-Fission-compiled code. */
5991 /* Have we already tried to read this TU?
5992 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
5993 needn't exist in the global table yet). */
5994 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
5997 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
5998 dwo_unit of the TU itself. */
5999 dwo_file
= cu
->dwo_unit
->dwo_file
;
6001 /* Ok, this is the first time we're reading this TU. */
6002 if (dwo_file
->tus
== NULL
)
6004 find_dwo_entry
.signature
= sig
;
6005 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6007 if (dwo_entry
== NULL
)
6010 /* If the global table doesn't have an entry for this TU, add one. */
6011 if (sig_entry
== NULL
)
6012 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6014 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6015 sig_entry
->tu_read
= 1;
6019 /* Subroutine of lookup_signatured_type.
6020 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6021 then try the DWP file. If the TU stub (skeleton) has been removed then
6022 it won't be in .gdb_index. */
6024 static struct signatured_type
*
6025 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6027 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6028 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6029 struct dwo_unit
*dwo_entry
;
6032 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6033 gdb_assert (dwp_file
!= NULL
);
6035 /* If TU skeletons have been removed then we may not have read in any
6037 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6038 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6040 signatured_type
find_sig_entry (sig
);
6041 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6042 &find_sig_entry
, INSERT
);
6043 signatured_type
*sig_entry
= (struct signatured_type
*) *slot
;
6045 /* Have we already tried to read this TU?
6046 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6047 needn't exist in the global table yet). */
6048 if (sig_entry
!= NULL
)
6051 if (dwp_file
->tus
== NULL
)
6053 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6054 1 /* is_debug_types */);
6055 if (dwo_entry
== NULL
)
6058 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6059 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6064 /* Lookup a signature based type for DW_FORM_ref_sig8.
6065 Returns NULL if signature SIG is not present in the table.
6066 It is up to the caller to complain about this. */
6068 static struct signatured_type
*
6069 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6071 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6073 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6075 /* We're in a DWO/DWP file, and we're using .gdb_index.
6076 These cases require special processing. */
6077 if (get_dwp_file (per_objfile
) == NULL
)
6078 return lookup_dwo_signatured_type (cu
, sig
);
6080 return lookup_dwp_signatured_type (cu
, sig
);
6084 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6086 signatured_type
find_entry (sig
);
6087 return ((struct signatured_type
*)
6088 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6093 /* Low level DIE reading support. */
6095 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6098 init_cu_die_reader (struct die_reader_specs
*reader
,
6099 struct dwarf2_cu
*cu
,
6100 struct dwarf2_section_info
*section
,
6101 struct dwo_file
*dwo_file
,
6102 struct abbrev_table
*abbrev_table
)
6104 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6105 reader
->abfd
= section
->get_bfd_owner ();
6107 reader
->dwo_file
= dwo_file
;
6108 reader
->die_section
= section
;
6109 reader
->buffer
= section
->buffer
;
6110 reader
->buffer_end
= section
->buffer
+ section
->size
;
6111 reader
->abbrev_table
= abbrev_table
;
6114 /* Subroutine of cutu_reader to simplify it.
6115 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6116 There's just a lot of work to do, and cutu_reader is big enough
6119 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6120 from it to the DIE in the DWO. If NULL we are skipping the stub.
6121 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6122 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6123 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6124 STUB_COMP_DIR may be non-NULL.
6125 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6126 are filled in with the info of the DIE from the DWO file.
6127 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6128 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6129 kept around for at least as long as *RESULT_READER.
6131 The result is non-zero if a valid (non-dummy) DIE was found. */
6134 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6135 struct dwo_unit
*dwo_unit
,
6136 struct die_info
*stub_comp_unit_die
,
6137 const char *stub_comp_dir
,
6138 struct die_reader_specs
*result_reader
,
6139 const gdb_byte
**result_info_ptr
,
6140 struct die_info
**result_comp_unit_die
,
6141 abbrev_table_up
*result_dwo_abbrev_table
)
6143 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6144 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6145 struct objfile
*objfile
= per_objfile
->objfile
;
6147 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6148 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6149 int i
,num_extra_attrs
;
6150 struct dwarf2_section_info
*dwo_abbrev_section
;
6151 struct die_info
*comp_unit_die
;
6153 /* At most one of these may be provided. */
6154 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6156 /* These attributes aren't processed until later:
6157 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6158 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6159 referenced later. However, these attributes are found in the stub
6160 which we won't have later. In order to not impose this complication
6161 on the rest of the code, we read them here and copy them to the
6170 if (stub_comp_unit_die
!= NULL
)
6172 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6174 if (!per_cu
->is_debug_types
)
6175 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6176 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6177 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6178 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6179 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6181 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6183 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6184 We need the value before we can process DW_AT_ranges values from the
6186 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6188 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6189 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6190 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6191 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6193 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6195 else if (stub_comp_dir
!= NULL
)
6197 /* Reconstruct the comp_dir attribute to simplify the code below. */
6198 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6199 comp_dir
->name
= DW_AT_comp_dir
;
6200 comp_dir
->form
= DW_FORM_string
;
6201 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6204 /* Set up for reading the DWO CU/TU. */
6205 cu
->dwo_unit
= dwo_unit
;
6206 dwarf2_section_info
*section
= dwo_unit
->section
;
6207 section
->read (objfile
);
6208 abfd
= section
->get_bfd_owner ();
6209 begin_info_ptr
= info_ptr
= (section
->buffer
6210 + to_underlying (dwo_unit
->sect_off
));
6211 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6213 if (per_cu
->is_debug_types
)
6215 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6217 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6218 section
, dwo_abbrev_section
,
6219 info_ptr
, rcuh_kind::TYPE
);
6220 /* This is not an assert because it can be caused by bad debug info. */
6221 if (sig_type
->signature
!= cu
->header
.signature
)
6223 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6224 " TU at offset %s [in module %s]"),
6225 hex_string (sig_type
->signature
),
6226 hex_string (cu
->header
.signature
),
6227 sect_offset_str (dwo_unit
->sect_off
),
6228 bfd_get_filename (abfd
));
6230 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6231 /* For DWOs coming from DWP files, we don't know the CU length
6232 nor the type's offset in the TU until now. */
6233 dwo_unit
->length
= cu
->header
.get_length ();
6234 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6236 /* Establish the type offset that can be used to lookup the type.
6237 For DWO files, we don't know it until now. */
6238 sig_type
->type_offset_in_section
6239 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6243 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6244 section
, dwo_abbrev_section
,
6245 info_ptr
, rcuh_kind::COMPILE
);
6246 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6247 /* For DWOs coming from DWP files, we don't know the CU length
6249 dwo_unit
->length
= cu
->header
.get_length ();
6252 dwo_abbrev_section
->read (objfile
);
6253 *result_dwo_abbrev_table
6254 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6255 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6256 result_dwo_abbrev_table
->get ());
6258 /* Read in the die, but leave space to copy over the attributes
6259 from the stub. This has the benefit of simplifying the rest of
6260 the code - all the work to maintain the illusion of a single
6261 DW_TAG_{compile,type}_unit DIE is done here. */
6262 num_extra_attrs
= ((stmt_list
!= NULL
)
6266 + (comp_dir
!= NULL
));
6267 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6270 /* Copy over the attributes from the stub to the DIE we just read in. */
6271 comp_unit_die
= *result_comp_unit_die
;
6272 i
= comp_unit_die
->num_attrs
;
6273 if (stmt_list
!= NULL
)
6274 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6276 comp_unit_die
->attrs
[i
++] = *low_pc
;
6277 if (high_pc
!= NULL
)
6278 comp_unit_die
->attrs
[i
++] = *high_pc
;
6280 comp_unit_die
->attrs
[i
++] = *ranges
;
6281 if (comp_dir
!= NULL
)
6282 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6283 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6285 if (dwarf_die_debug
)
6287 fprintf_unfiltered (gdb_stdlog
,
6288 "Read die from %s@0x%x of %s:\n",
6289 section
->get_name (),
6290 (unsigned) (begin_info_ptr
- section
->buffer
),
6291 bfd_get_filename (abfd
));
6292 dump_die (comp_unit_die
, dwarf_die_debug
);
6295 /* Skip dummy compilation units. */
6296 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6297 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6300 *result_info_ptr
= info_ptr
;
6304 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6305 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6306 signature is part of the header. */
6307 static gdb::optional
<ULONGEST
>
6308 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6310 if (cu
->header
.version
>= 5)
6311 return cu
->header
.signature
;
6312 struct attribute
*attr
;
6313 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6314 if (attr
== nullptr || !attr
->form_is_unsigned ())
6315 return gdb::optional
<ULONGEST
> ();
6316 return attr
->as_unsigned ();
6319 /* Subroutine of cutu_reader to simplify it.
6320 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6321 Returns NULL if the specified DWO unit cannot be found. */
6323 static struct dwo_unit
*
6324 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6326 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6327 struct dwo_unit
*dwo_unit
;
6328 const char *comp_dir
;
6330 gdb_assert (cu
!= NULL
);
6332 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6333 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6334 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6336 if (per_cu
->is_debug_types
)
6337 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6340 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6342 if (!signature
.has_value ())
6343 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6345 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6347 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6353 /* Subroutine of cutu_reader to simplify it.
6354 See it for a description of the parameters.
6355 Read a TU directly from a DWO file, bypassing the stub. */
6358 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6359 dwarf2_per_objfile
*per_objfile
,
6360 dwarf2_cu
*existing_cu
)
6362 struct signatured_type
*sig_type
;
6364 /* Verify we can do the following downcast, and that we have the
6366 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6367 sig_type
= (struct signatured_type
*) this_cu
;
6368 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6372 if (existing_cu
!= nullptr)
6375 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6376 /* There's no need to do the rereading_dwo_cu handling that
6377 cutu_reader does since we don't read the stub. */
6381 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6382 in per_objfile yet. */
6383 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6384 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6385 cu
= m_new_cu
.get ();
6388 /* A future optimization, if needed, would be to use an existing
6389 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6390 could share abbrev tables. */
6392 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6393 NULL
/* stub_comp_unit_die */,
6394 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6397 &m_dwo_abbrev_table
) == 0)
6404 /* Initialize a CU (or TU) and read its DIEs.
6405 If the CU defers to a DWO file, read the DWO file as well.
6407 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6408 Otherwise the table specified in the comp unit header is read in and used.
6409 This is an optimization for when we already have the abbrev table.
6411 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6414 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6415 dwarf2_per_objfile
*per_objfile
,
6416 struct abbrev_table
*abbrev_table
,
6417 dwarf2_cu
*existing_cu
,
6419 : die_reader_specs
{},
6422 struct objfile
*objfile
= per_objfile
->objfile
;
6423 struct dwarf2_section_info
*section
= this_cu
->section
;
6424 bfd
*abfd
= section
->get_bfd_owner ();
6425 const gdb_byte
*begin_info_ptr
;
6426 struct signatured_type
*sig_type
= NULL
;
6427 struct dwarf2_section_info
*abbrev_section
;
6428 /* Non-zero if CU currently points to a DWO file and we need to
6429 reread it. When this happens we need to reread the skeleton die
6430 before we can reread the DWO file (this only applies to CUs, not TUs). */
6431 int rereading_dwo_cu
= 0;
6433 if (dwarf_die_debug
)
6434 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6435 this_cu
->is_debug_types
? "type" : "comp",
6436 sect_offset_str (this_cu
->sect_off
));
6438 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6439 file (instead of going through the stub), short-circuit all of this. */
6440 if (this_cu
->reading_dwo_directly
)
6442 /* Narrow down the scope of possibilities to have to understand. */
6443 gdb_assert (this_cu
->is_debug_types
);
6444 gdb_assert (abbrev_table
== NULL
);
6445 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6449 /* This is cheap if the section is already read in. */
6450 section
->read (objfile
);
6452 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6454 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6458 if (existing_cu
!= nullptr)
6461 /* If this CU is from a DWO file we need to start over, we need to
6462 refetch the attributes from the skeleton CU.
6463 This could be optimized by retrieving those attributes from when we
6464 were here the first time: the previous comp_unit_die was stored in
6465 comp_unit_obstack. But there's no data yet that we need this
6467 if (cu
->dwo_unit
!= NULL
)
6468 rereading_dwo_cu
= 1;
6472 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6473 in per_objfile yet. */
6474 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6475 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6476 cu
= m_new_cu
.get ();
6479 /* Get the header. */
6480 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6482 /* We already have the header, there's no need to read it in again. */
6483 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6487 if (this_cu
->is_debug_types
)
6489 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6490 section
, abbrev_section
,
6491 info_ptr
, rcuh_kind::TYPE
);
6493 /* Since per_cu is the first member of struct signatured_type,
6494 we can go from a pointer to one to a pointer to the other. */
6495 sig_type
= (struct signatured_type
*) this_cu
;
6496 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6497 gdb_assert (sig_type
->type_offset_in_tu
6498 == cu
->header
.type_cu_offset_in_tu
);
6499 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6501 /* LENGTH has not been set yet for type units if we're
6502 using .gdb_index. */
6503 this_cu
->length
= cu
->header
.get_length ();
6505 /* Establish the type offset that can be used to lookup the type. */
6506 sig_type
->type_offset_in_section
=
6507 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6509 this_cu
->dwarf_version
= cu
->header
.version
;
6513 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6514 section
, abbrev_section
,
6516 rcuh_kind::COMPILE
);
6518 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6519 if (this_cu
->length
== 0)
6520 this_cu
->length
= cu
->header
.get_length ();
6522 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6523 this_cu
->dwarf_version
= cu
->header
.version
;
6527 /* Skip dummy compilation units. */
6528 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6529 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6535 /* If we don't have them yet, read the abbrevs for this compilation unit.
6536 And if we need to read them now, make sure they're freed when we're
6538 if (abbrev_table
!= NULL
)
6539 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6542 abbrev_section
->read (objfile
);
6543 m_abbrev_table_holder
6544 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6545 abbrev_table
= m_abbrev_table_holder
.get ();
6548 /* Read the top level CU/TU die. */
6549 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6550 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6552 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6558 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6559 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6560 table from the DWO file and pass the ownership over to us. It will be
6561 referenced from READER, so we must make sure to free it after we're done
6564 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6565 DWO CU, that this test will fail (the attribute will not be present). */
6566 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6567 if (dwo_name
!= nullptr)
6569 struct dwo_unit
*dwo_unit
;
6570 struct die_info
*dwo_comp_unit_die
;
6572 if (comp_unit_die
->has_children
)
6574 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6575 " has children (offset %s) [in module %s]"),
6576 sect_offset_str (this_cu
->sect_off
),
6577 bfd_get_filename (abfd
));
6579 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6580 if (dwo_unit
!= NULL
)
6582 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6583 comp_unit_die
, NULL
,
6586 &m_dwo_abbrev_table
) == 0)
6592 comp_unit_die
= dwo_comp_unit_die
;
6596 /* Yikes, we couldn't find the rest of the DIE, we only have
6597 the stub. A complaint has already been logged. There's
6598 not much more we can do except pass on the stub DIE to
6599 die_reader_func. We don't want to throw an error on bad
6606 cutu_reader::keep ()
6608 /* Done, clean up. */
6609 gdb_assert (!dummy_p
);
6610 if (m_new_cu
!= NULL
)
6612 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6614 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6615 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6619 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6620 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6621 assumed to have already done the lookup to find the DWO file).
6623 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6624 THIS_CU->is_debug_types, but nothing else.
6626 We fill in THIS_CU->length.
6628 THIS_CU->cu is always freed when done.
6629 This is done in order to not leave THIS_CU->cu in a state where we have
6630 to care whether it refers to the "main" CU or the DWO CU.
6632 When parent_cu is passed, it is used to provide a default value for
6633 str_offsets_base and addr_base from the parent. */
6635 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6636 dwarf2_per_objfile
*per_objfile
,
6637 struct dwarf2_cu
*parent_cu
,
6638 struct dwo_file
*dwo_file
)
6639 : die_reader_specs
{},
6642 struct objfile
*objfile
= per_objfile
->objfile
;
6643 struct dwarf2_section_info
*section
= this_cu
->section
;
6644 bfd
*abfd
= section
->get_bfd_owner ();
6645 struct dwarf2_section_info
*abbrev_section
;
6646 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6648 if (dwarf_die_debug
)
6649 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6650 this_cu
->is_debug_types
? "type" : "comp",
6651 sect_offset_str (this_cu
->sect_off
));
6653 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6655 abbrev_section
= (dwo_file
!= NULL
6656 ? &dwo_file
->sections
.abbrev
6657 : get_abbrev_section_for_cu (this_cu
));
6659 /* This is cheap if the section is already read in. */
6660 section
->read (objfile
);
6662 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6664 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6665 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6666 section
, abbrev_section
, info_ptr
,
6667 (this_cu
->is_debug_types
6669 : rcuh_kind::COMPILE
));
6671 if (parent_cu
!= nullptr)
6673 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6674 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6676 this_cu
->length
= m_new_cu
->header
.get_length ();
6678 /* Skip dummy compilation units. */
6679 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6680 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6686 abbrev_section
->read (objfile
);
6687 m_abbrev_table_holder
6688 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6690 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6691 m_abbrev_table_holder
.get ());
6692 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6696 /* Type Unit Groups.
6698 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6699 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6700 so that all types coming from the same compilation (.o file) are grouped
6701 together. A future step could be to put the types in the same symtab as
6702 the CU the types ultimately came from. */
6705 hash_type_unit_group (const void *item
)
6707 const struct type_unit_group
*tu_group
6708 = (const struct type_unit_group
*) item
;
6710 return hash_stmt_list_entry (&tu_group
->hash
);
6714 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6716 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6717 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6719 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6722 /* Allocate a hash table for type unit groups. */
6725 allocate_type_unit_groups_table ()
6727 return htab_up (htab_create_alloc (3,
6728 hash_type_unit_group
,
6730 htab_delete_entry
<type_unit_group
>,
6734 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6735 partial symtabs. We combine several TUs per psymtab to not let the size
6736 of any one psymtab grow too big. */
6737 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6738 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6740 /* Helper routine for get_type_unit_group.
6741 Create the type_unit_group object used to hold one or more TUs. */
6743 static std::unique_ptr
<type_unit_group
>
6744 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6746 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6747 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6749 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6750 tu_group
->per_bfd
= per_bfd
;
6752 if (per_bfd
->using_index
)
6754 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6755 struct dwarf2_per_cu_quick_data
);
6759 unsigned int line_offset
= to_underlying (line_offset_struct
);
6760 dwarf2_psymtab
*pst
;
6763 /* Give the symtab a useful name for debug purposes. */
6764 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
6765 name
= string_printf ("<type_units_%d>",
6766 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
6768 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
6770 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
6772 pst
->anonymous
= true;
6775 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
6776 tu_group
->hash
.line_sect_off
= line_offset_struct
;
6781 /* Look up the type_unit_group for type unit CU, and create it if necessary.
6782 STMT_LIST is a DW_AT_stmt_list attribute. */
6784 static struct type_unit_group
*
6785 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
6787 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6788 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
6789 struct type_unit_group
*tu_group
;
6791 unsigned int line_offset
;
6792 struct type_unit_group type_unit_group_for_lookup
;
6794 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
6795 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
6797 /* Do we need to create a new group, or can we use an existing one? */
6799 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
6801 line_offset
= stmt_list
->as_unsigned ();
6802 ++tu_stats
->nr_symtab_sharers
;
6806 /* Ugh, no stmt_list. Rare, but we have to handle it.
6807 We can do various things here like create one group per TU or
6808 spread them over multiple groups to split up the expansion work.
6809 To avoid worst case scenarios (too many groups or too large groups)
6810 we, umm, group them in bunches. */
6811 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
6812 | (tu_stats
->nr_stmt_less_type_units
6813 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
6814 ++tu_stats
->nr_stmt_less_type_units
;
6817 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
6818 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
6819 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
6820 &type_unit_group_for_lookup
, INSERT
);
6821 if (*slot
== nullptr)
6823 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
6824 std::unique_ptr
<type_unit_group
> grp
6825 = create_type_unit_group (cu
, line_offset_struct
);
6826 *slot
= grp
.release ();
6827 ++tu_stats
->nr_symtabs
;
6830 tu_group
= (struct type_unit_group
*) *slot
;
6831 gdb_assert (tu_group
!= nullptr);
6835 /* Partial symbol tables. */
6837 /* Create a psymtab named NAME and assign it to PER_CU.
6839 The caller must fill in the following details:
6840 dirname, textlow, texthigh. */
6842 static dwarf2_psymtab
*
6843 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
6844 dwarf2_per_objfile
*per_objfile
,
6848 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
6849 per_objfile
->objfile
->per_bfd
, per_cu
);
6851 pst
->psymtabs_addrmap_supported
= true;
6853 /* This is the glue that links PST into GDB's symbol API. */
6854 per_cu
->v
.psymtab
= pst
;
6859 /* DIE reader function for process_psymtab_comp_unit. */
6862 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
6863 const gdb_byte
*info_ptr
,
6864 struct die_info
*comp_unit_die
,
6865 enum language pretend_language
)
6867 struct dwarf2_cu
*cu
= reader
->cu
;
6868 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6869 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6870 struct objfile
*objfile
= per_objfile
->objfile
;
6871 struct gdbarch
*gdbarch
= objfile
->arch ();
6872 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6874 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
6875 dwarf2_psymtab
*pst
;
6876 enum pc_bounds_kind cu_bounds_kind
;
6877 const char *filename
;
6879 gdb_assert (! per_cu
->is_debug_types
);
6881 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
6883 /* Allocate a new partial symbol table structure. */
6884 gdb::unique_xmalloc_ptr
<char> debug_filename
;
6885 static const char artificial
[] = "<artificial>";
6886 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
6887 if (filename
== NULL
)
6889 else if (strcmp (filename
, artificial
) == 0)
6891 debug_filename
.reset (concat (artificial
, "@",
6892 sect_offset_str (per_cu
->sect_off
),
6894 filename
= debug_filename
.get ();
6897 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
6899 /* This must be done before calling dwarf2_build_include_psymtabs. */
6900 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6902 baseaddr
= objfile
->text_section_offset ();
6904 dwarf2_find_base_address (comp_unit_die
, cu
);
6906 /* Possibly set the default values of LOWPC and HIGHPC from
6908 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
6909 &best_highpc
, cu
, pst
);
6910 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
6913 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
6916 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
6918 /* Store the contiguous range if it is not empty; it can be
6919 empty for CUs with no code. */
6920 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
6924 /* Check if comp unit has_children.
6925 If so, read the rest of the partial symbols from this comp unit.
6926 If not, there's no more debug_info for this comp unit. */
6927 if (comp_unit_die
->has_children
)
6929 struct partial_die_info
*first_die
;
6930 CORE_ADDR lowpc
, highpc
;
6932 lowpc
= ((CORE_ADDR
) -1);
6933 highpc
= ((CORE_ADDR
) 0);
6935 first_die
= load_partial_dies (reader
, info_ptr
, 1);
6937 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
6938 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
6940 /* If we didn't find a lowpc, set it to highpc to avoid
6941 complaints from `maint check'. */
6942 if (lowpc
== ((CORE_ADDR
) -1))
6945 /* If the compilation unit didn't have an explicit address range,
6946 then use the information extracted from its child dies. */
6947 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
6950 best_highpc
= highpc
;
6953 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
6954 best_lowpc
+ baseaddr
)
6956 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
6957 best_highpc
+ baseaddr
)
6962 if (!cu
->per_cu
->imported_symtabs_empty ())
6965 int len
= cu
->per_cu
->imported_symtabs_size ();
6967 /* Fill in 'dependencies' here; we fill in 'users' in a
6969 pst
->number_of_dependencies
= len
;
6971 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
6972 for (i
= 0; i
< len
; ++i
)
6974 pst
->dependencies
[i
]
6975 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
6978 cu
->per_cu
->imported_symtabs_free ();
6981 /* Get the list of files included in the current compilation unit,
6982 and build a psymtab for each of them. */
6983 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
6985 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
6986 ", %d global, %d static syms",
6987 per_cu
->is_debug_types
? "type" : "comp",
6988 sect_offset_str (per_cu
->sect_off
),
6989 paddress (gdbarch
, pst
->text_low (objfile
)),
6990 paddress (gdbarch
, pst
->text_high (objfile
)),
6991 (int) pst
->global_psymbols
.size (),
6992 (int) pst
->static_psymbols
.size ());
6995 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
6996 Process compilation unit THIS_CU for a psymtab. */
6999 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7000 dwarf2_per_objfile
*per_objfile
,
7001 bool want_partial_unit
,
7002 enum language pretend_language
)
7004 /* If this compilation unit was already read in, free the
7005 cached copy in order to read it in again. This is
7006 necessary because we skipped some symbols when we first
7007 read in the compilation unit (see load_partial_dies).
7008 This problem could be avoided, but the benefit is unclear. */
7009 per_objfile
->remove_cu (this_cu
);
7011 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7013 if (reader
.comp_unit_die
== nullptr)
7016 switch (reader
.comp_unit_die
->tag
)
7018 case DW_TAG_compile_unit
:
7019 this_cu
->unit_type
= DW_UT_compile
;
7021 case DW_TAG_partial_unit
:
7022 this_cu
->unit_type
= DW_UT_partial
;
7024 case DW_TAG_type_unit
:
7025 this_cu
->unit_type
= DW_UT_type
;
7028 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7029 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7030 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7031 objfile_name (per_objfile
->objfile
));
7038 else if (this_cu
->is_debug_types
)
7039 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7040 reader
.comp_unit_die
);
7041 else if (want_partial_unit
7042 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7043 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7044 reader
.comp_unit_die
,
7047 /* Age out any secondary CUs. */
7048 per_objfile
->age_comp_units ();
7051 /* Reader function for build_type_psymtabs. */
7054 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7055 const gdb_byte
*info_ptr
,
7056 struct die_info
*type_unit_die
)
7058 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7059 struct dwarf2_cu
*cu
= reader
->cu
;
7060 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7061 struct signatured_type
*sig_type
;
7062 struct type_unit_group
*tu_group
;
7063 struct attribute
*attr
;
7064 struct partial_die_info
*first_die
;
7065 CORE_ADDR lowpc
, highpc
;
7066 dwarf2_psymtab
*pst
;
7068 gdb_assert (per_cu
->is_debug_types
);
7069 sig_type
= (struct signatured_type
*) per_cu
;
7071 if (! type_unit_die
->has_children
)
7074 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7075 tu_group
= get_type_unit_group (cu
, attr
);
7077 if (tu_group
->tus
== nullptr)
7078 tu_group
->tus
= new std::vector
<signatured_type
*>;
7079 tu_group
->tus
->push_back (sig_type
);
7081 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7082 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7083 pst
->anonymous
= true;
7085 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7087 lowpc
= (CORE_ADDR
) -1;
7088 highpc
= (CORE_ADDR
) 0;
7089 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7094 /* Struct used to sort TUs by their abbreviation table offset. */
7096 struct tu_abbrev_offset
7098 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7099 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7102 /* This is used when sorting. */
7103 bool operator< (const tu_abbrev_offset
&other
) const
7105 return abbrev_offset
< other
.abbrev_offset
;
7108 signatured_type
*sig_type
;
7109 sect_offset abbrev_offset
;
7112 /* Efficiently read all the type units.
7114 The efficiency is because we sort TUs by the abbrev table they use and
7115 only read each abbrev table once. In one program there are 200K TUs
7116 sharing 8K abbrev tables.
7118 The main purpose of this function is to support building the
7119 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7120 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7121 can collapse the search space by grouping them by stmt_list.
7122 The savings can be significant, in the same program from above the 200K TUs
7123 share 8K stmt_list tables.
7125 FUNC is expected to call get_type_unit_group, which will create the
7126 struct type_unit_group if necessary and add it to
7127 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7130 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7132 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7133 abbrev_table_up abbrev_table
;
7134 sect_offset abbrev_offset
;
7136 /* It's up to the caller to not call us multiple times. */
7137 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7139 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7142 /* TUs typically share abbrev tables, and there can be way more TUs than
7143 abbrev tables. Sort by abbrev table to reduce the number of times we
7144 read each abbrev table in.
7145 Alternatives are to punt or to maintain a cache of abbrev tables.
7146 This is simpler and efficient enough for now.
7148 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7149 symtab to use). Typically TUs with the same abbrev offset have the same
7150 stmt_list value too so in practice this should work well.
7152 The basic algorithm here is:
7154 sort TUs by abbrev table
7155 for each TU with same abbrev table:
7156 read abbrev table if first user
7157 read TU top level DIE
7158 [IWBN if DWO skeletons had DW_AT_stmt_list]
7161 dwarf_read_debug_printf ("Building type unit groups ...");
7163 /* Sort in a separate table to maintain the order of all_comp_units
7164 for .gdb_index: TU indices directly index all_type_units. */
7165 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7166 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7168 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7170 if (cu
->is_debug_types
)
7172 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7173 sorted_by_abbrev
.emplace_back
7174 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7175 sig_type
->sect_off
));
7179 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end ());
7181 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7183 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7185 /* Switch to the next abbrev table if necessary. */
7186 if (abbrev_table
== NULL
7187 || tu
.abbrev_offset
!= abbrev_offset
)
7189 abbrev_offset
= tu
.abbrev_offset
;
7190 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7192 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7193 ++tu_stats
->nr_uniq_abbrev_tables
;
7196 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7197 abbrev_table
.get (), nullptr, false);
7198 if (!reader
.dummy_p
)
7199 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7200 reader
.comp_unit_die
);
7204 /* Print collected type unit statistics. */
7207 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7209 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7211 dwarf_read_debug_printf ("Type unit statistics:");
7212 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7213 dwarf_read_debug_printf (" %d uniq abbrev tables",
7214 tu_stats
->nr_uniq_abbrev_tables
);
7215 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7216 tu_stats
->nr_symtabs
);
7217 dwarf_read_debug_printf (" %d symtab sharers",
7218 tu_stats
->nr_symtab_sharers
);
7219 dwarf_read_debug_printf (" %d type units without a stmt_list",
7220 tu_stats
->nr_stmt_less_type_units
);
7221 dwarf_read_debug_printf (" %d all_type_units reallocs",
7222 tu_stats
->nr_all_type_units_reallocs
);
7225 /* Traversal function for build_type_psymtabs. */
7228 build_type_psymtab_dependencies (void **slot
, void *info
)
7230 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7231 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7232 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7233 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7234 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7237 gdb_assert (len
> 0);
7238 gdb_assert (tu_group
->type_unit_group_p ());
7240 pst
->number_of_dependencies
= len
;
7241 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7242 for (i
= 0; i
< len
; ++i
)
7244 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7245 gdb_assert (iter
->is_debug_types
);
7246 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7247 iter
->type_unit_group
= tu_group
;
7250 delete tu_group
->tus
;
7251 tu_group
->tus
= nullptr;
7256 /* Traversal function for process_skeletonless_type_unit.
7257 Read a TU in a DWO file and build partial symbols for it. */
7260 process_skeletonless_type_unit (void **slot
, void *info
)
7262 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7263 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7265 /* If this TU doesn't exist in the global table, add it and read it in. */
7267 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7268 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7270 signatured_type
find_entry (dwo_unit
->signature
);
7271 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7272 &find_entry
, INSERT
);
7273 /* If we've already seen this type there's nothing to do. What's happening
7274 is we're doing our own version of comdat-folding here. */
7278 /* This does the job that create_all_comp_units would have done for
7280 signatured_type
*entry
7281 = add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7282 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7285 /* This does the job that build_type_psymtabs would have done. */
7286 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7287 if (!reader
.dummy_p
)
7288 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7289 reader
.comp_unit_die
);
7294 /* Traversal function for process_skeletonless_type_units. */
7297 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7299 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7301 if (dwo_file
->tus
!= NULL
)
7302 htab_traverse_noresize (dwo_file
->tus
.get (),
7303 process_skeletonless_type_unit
, info
);
7308 /* Scan all TUs of DWO files, verifying we've processed them.
7309 This is needed in case a TU was emitted without its skeleton.
7310 Note: This can't be done until we know what all the DWO files are. */
7313 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7315 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7316 if (get_dwp_file (per_objfile
) == NULL
7317 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7319 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7320 process_dwo_file_for_skeletonless_type_units
,
7325 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7328 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7330 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7332 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7337 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7339 /* Set the 'user' field only if it is not already set. */
7340 if (pst
->dependencies
[j
]->user
== NULL
)
7341 pst
->dependencies
[j
]->user
= pst
;
7346 /* Build the partial symbol table by doing a quick pass through the
7347 .debug_info and .debug_abbrev sections. */
7350 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7352 struct objfile
*objfile
= per_objfile
->objfile
;
7353 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7355 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7356 objfile_name (objfile
));
7358 scoped_restore restore_reading_psyms
7359 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7361 per_bfd
->info
.read (objfile
);
7363 /* Any cached compilation units will be linked by the per-objfile
7364 read_in_chain. Make sure to free them when we're done. */
7365 free_cached_comp_units
freer (per_objfile
);
7367 create_all_comp_units (per_objfile
);
7368 build_type_psymtabs (per_objfile
);
7370 /* Create a temporary address map on a temporary obstack. We later
7371 copy this to the final obstack. */
7372 auto_obstack temp_obstack
;
7374 scoped_restore save_psymtabs_addrmap
7375 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7376 addrmap_create_mutable (&temp_obstack
));
7378 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7380 if (per_cu
->v
.psymtab
!= NULL
)
7381 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7383 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7387 /* This has to wait until we read the CUs, we need the list of DWOs. */
7388 process_skeletonless_type_units (per_objfile
);
7390 /* Now that all TUs have been processed we can fill in the dependencies. */
7391 if (per_bfd
->type_unit_groups
!= NULL
)
7393 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7394 build_type_psymtab_dependencies
, per_objfile
);
7397 if (dwarf_read_debug
> 0)
7398 print_tu_stats (per_objfile
);
7400 set_partial_user (per_objfile
);
7402 per_bfd
->partial_symtabs
->psymtabs_addrmap
7403 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7404 per_bfd
->partial_symtabs
->obstack ());
7405 /* At this point we want to keep the address map. */
7406 save_psymtabs_addrmap
.release ();
7408 dwarf_read_debug_printf ("Done building psymtabs of %s",
7409 objfile_name (objfile
));
7412 /* Load the partial DIEs for a secondary CU into memory.
7413 This is also used when rereading a primary CU with load_all_dies. */
7416 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7417 dwarf2_per_objfile
*per_objfile
,
7418 dwarf2_cu
*existing_cu
)
7420 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7422 if (!reader
.dummy_p
)
7424 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7427 /* Check if comp unit has_children.
7428 If so, read the rest of the partial symbols from this comp unit.
7429 If not, there's no more debug_info for this comp unit. */
7430 if (reader
.comp_unit_die
->has_children
)
7431 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7438 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7439 struct dwarf2_section_info
*section
,
7440 struct dwarf2_section_info
*abbrev_section
,
7441 unsigned int is_dwz
,
7442 htab_up
&types_htab
,
7443 rcuh_kind section_kind
)
7445 const gdb_byte
*info_ptr
;
7446 struct objfile
*objfile
= per_objfile
->objfile
;
7448 dwarf_read_debug_printf ("Reading %s for %s",
7449 section
->get_name (),
7450 section
->get_file_name ());
7452 section
->read (objfile
);
7454 info_ptr
= section
->buffer
;
7456 while (info_ptr
< section
->buffer
+ section
->size
)
7458 dwarf2_per_cu_data_up this_cu
;
7460 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7462 comp_unit_head cu_header
;
7463 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7464 abbrev_section
, info_ptr
,
7467 /* Save the compilation unit for later lookup. */
7468 if (cu_header
.unit_type
!= DW_UT_type
)
7469 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7472 if (types_htab
== nullptr)
7473 types_htab
= allocate_signatured_type_table ();
7475 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
7476 (cu_header
.signature
);
7477 signatured_type
*sig_ptr
= sig_type
.get ();
7478 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7479 this_cu
.reset (sig_type
.release ());
7481 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7482 gdb_assert (slot
!= nullptr);
7483 if (*slot
!= nullptr)
7484 complaint (_("debug type entry at offset %s is duplicate to"
7485 " the entry at offset %s, signature %s"),
7486 sect_offset_str (sect_off
),
7487 sect_offset_str (sig_ptr
->sect_off
),
7488 hex_string (sig_ptr
->signature
));
7491 this_cu
->sect_off
= sect_off
;
7492 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7493 this_cu
->is_dwz
= is_dwz
;
7494 this_cu
->section
= section
;
7496 info_ptr
= info_ptr
+ this_cu
->length
;
7497 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7501 /* Create a list of all compilation units in OBJFILE.
7502 This is only done for -readnow and building partial symtabs. */
7505 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7509 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7510 &per_objfile
->per_bfd
->abbrev
, 0,
7511 types_htab
, rcuh_kind::COMPILE
);
7512 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7513 read_comp_units_from_section (per_objfile
, §ion
,
7514 &per_objfile
->per_bfd
->abbrev
, 0,
7515 types_htab
, rcuh_kind::TYPE
);
7517 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7519 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7520 types_htab
, rcuh_kind::COMPILE
);
7522 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7525 /* Process all loaded DIEs for compilation unit CU, starting at
7526 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7527 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7528 DW_AT_ranges). See the comments of add_partial_subprogram on how
7529 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7532 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7533 CORE_ADDR
*highpc
, int set_addrmap
,
7534 struct dwarf2_cu
*cu
)
7536 struct partial_die_info
*pdi
;
7538 /* Now, march along the PDI's, descending into ones which have
7539 interesting children but skipping the children of the other ones,
7540 until we reach the end of the compilation unit. */
7548 /* Anonymous namespaces or modules have no name but have interesting
7549 children, so we need to look at them. Ditto for anonymous
7552 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7553 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7554 || pdi
->tag
== DW_TAG_imported_unit
7555 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7559 case DW_TAG_subprogram
:
7560 case DW_TAG_inlined_subroutine
:
7561 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7562 if (cu
->per_cu
->lang
== language_cplus
)
7563 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7566 case DW_TAG_constant
:
7567 case DW_TAG_variable
:
7568 case DW_TAG_typedef
:
7569 case DW_TAG_union_type
:
7570 if (!pdi
->is_declaration
7571 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7573 add_partial_symbol (pdi
, cu
);
7576 case DW_TAG_class_type
:
7577 case DW_TAG_interface_type
:
7578 case DW_TAG_structure_type
:
7579 if (!pdi
->is_declaration
)
7581 add_partial_symbol (pdi
, cu
);
7583 if ((cu
->per_cu
->lang
== language_rust
7584 || cu
->per_cu
->lang
== language_cplus
)
7585 && pdi
->has_children
)
7586 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7589 case DW_TAG_enumeration_type
:
7590 if (!pdi
->is_declaration
)
7591 add_partial_enumeration (pdi
, cu
);
7593 case DW_TAG_base_type
:
7594 case DW_TAG_subrange_type
:
7595 /* File scope base type definitions are added to the partial
7597 add_partial_symbol (pdi
, cu
);
7599 case DW_TAG_namespace
:
7600 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7603 if (!pdi
->is_declaration
)
7604 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7606 case DW_TAG_imported_unit
:
7608 struct dwarf2_per_cu_data
*per_cu
;
7610 /* For now we don't handle imported units in type units. */
7611 if (cu
->per_cu
->is_debug_types
)
7613 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7614 " supported in type units [in module %s]"),
7615 objfile_name (cu
->per_objfile
->objfile
));
7618 per_cu
= dwarf2_find_containing_comp_unit
7619 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7621 /* Go read the partial unit, if needed. */
7622 if (per_cu
->v
.psymtab
== NULL
)
7623 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7626 cu
->per_cu
->imported_symtabs_push (per_cu
);
7629 case DW_TAG_imported_declaration
:
7630 add_partial_symbol (pdi
, cu
);
7637 /* If the die has a sibling, skip to the sibling. */
7639 pdi
= pdi
->die_sibling
;
7643 /* Functions used to compute the fully scoped name of a partial DIE.
7645 Normally, this is simple. For C++, the parent DIE's fully scoped
7646 name is concatenated with "::" and the partial DIE's name.
7647 Enumerators are an exception; they use the scope of their parent
7648 enumeration type, i.e. the name of the enumeration type is not
7649 prepended to the enumerator.
7651 There are two complexities. One is DW_AT_specification; in this
7652 case "parent" means the parent of the target of the specification,
7653 instead of the direct parent of the DIE. The other is compilers
7654 which do not emit DW_TAG_namespace; in this case we try to guess
7655 the fully qualified name of structure types from their members'
7656 linkage names. This must be done using the DIE's children rather
7657 than the children of any DW_AT_specification target. We only need
7658 to do this for structures at the top level, i.e. if the target of
7659 any DW_AT_specification (if any; otherwise the DIE itself) does not
7662 /* Compute the scope prefix associated with PDI's parent, in
7663 compilation unit CU. The result will be allocated on CU's
7664 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7665 field. NULL is returned if no prefix is necessary. */
7667 partial_die_parent_scope (struct partial_die_info
*pdi
,
7668 struct dwarf2_cu
*cu
)
7670 const char *grandparent_scope
;
7671 struct partial_die_info
*parent
, *real_pdi
;
7673 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7674 then this means the parent of the specification DIE. */
7677 while (real_pdi
->has_specification
)
7679 auto res
= find_partial_die (real_pdi
->spec_offset
,
7680 real_pdi
->spec_is_dwz
, cu
);
7685 parent
= real_pdi
->die_parent
;
7689 if (parent
->scope_set
)
7690 return parent
->scope
;
7694 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7696 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7697 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7698 Work around this problem here. */
7699 if (cu
->per_cu
->lang
== language_cplus
7700 && parent
->tag
== DW_TAG_namespace
7701 && strcmp (parent
->name (cu
), "::") == 0
7702 && grandparent_scope
== NULL
)
7704 parent
->scope
= NULL
;
7705 parent
->scope_set
= 1;
7709 /* Nested subroutines in Fortran get a prefix. */
7710 if (pdi
->tag
== DW_TAG_enumerator
)
7711 /* Enumerators should not get the name of the enumeration as a prefix. */
7712 parent
->scope
= grandparent_scope
;
7713 else if (parent
->tag
== DW_TAG_namespace
7714 || parent
->tag
== DW_TAG_module
7715 || parent
->tag
== DW_TAG_structure_type
7716 || parent
->tag
== DW_TAG_class_type
7717 || parent
->tag
== DW_TAG_interface_type
7718 || parent
->tag
== DW_TAG_union_type
7719 || parent
->tag
== DW_TAG_enumeration_type
7720 || (cu
->per_cu
->lang
== language_fortran
7721 && parent
->tag
== DW_TAG_subprogram
7722 && pdi
->tag
== DW_TAG_subprogram
))
7724 if (grandparent_scope
== NULL
)
7725 parent
->scope
= parent
->name (cu
);
7727 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7729 parent
->name (cu
), 0, cu
);
7733 /* FIXME drow/2004-04-01: What should we be doing with
7734 function-local names? For partial symbols, we should probably be
7736 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7737 dwarf_tag_name (parent
->tag
),
7738 sect_offset_str (pdi
->sect_off
));
7739 parent
->scope
= grandparent_scope
;
7742 parent
->scope_set
= 1;
7743 return parent
->scope
;
7746 /* Return the fully scoped name associated with PDI, from compilation unit
7747 CU. The result will be allocated with malloc. */
7749 static gdb::unique_xmalloc_ptr
<char>
7750 partial_die_full_name (struct partial_die_info
*pdi
,
7751 struct dwarf2_cu
*cu
)
7753 const char *parent_scope
;
7755 /* If this is a template instantiation, we can not work out the
7756 template arguments from partial DIEs. So, unfortunately, we have
7757 to go through the full DIEs. At least any work we do building
7758 types here will be reused if full symbols are loaded later. */
7759 if (pdi
->has_template_arguments
)
7763 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
7765 struct die_info
*die
;
7766 struct attribute attr
;
7767 struct dwarf2_cu
*ref_cu
= cu
;
7769 /* DW_FORM_ref_addr is using section offset. */
7770 attr
.name
= (enum dwarf_attribute
) 0;
7771 attr
.form
= DW_FORM_ref_addr
;
7772 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
7773 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
7775 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
7779 parent_scope
= partial_die_parent_scope (pdi
, cu
);
7780 if (parent_scope
== NULL
)
7783 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
7789 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
7791 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7792 struct objfile
*objfile
= per_objfile
->objfile
;
7793 struct gdbarch
*gdbarch
= objfile
->arch ();
7795 const char *actual_name
= NULL
;
7798 baseaddr
= objfile
->text_section_offset ();
7800 gdb::unique_xmalloc_ptr
<char> built_actual_name
7801 = partial_die_full_name (pdi
, cu
);
7802 if (built_actual_name
!= NULL
)
7803 actual_name
= built_actual_name
.get ();
7805 if (actual_name
== NULL
)
7806 actual_name
= pdi
->name (cu
);
7808 partial_symbol psymbol
;
7809 memset (&psymbol
, 0, sizeof (psymbol
));
7810 psymbol
.ginfo
.set_language (cu
->per_cu
->lang
,
7811 &objfile
->objfile_obstack
);
7812 psymbol
.ginfo
.set_section_index (-1);
7814 /* The code below indicates that the psymbol should be installed by
7816 gdb::optional
<psymbol_placement
> where
;
7820 case DW_TAG_inlined_subroutine
:
7821 case DW_TAG_subprogram
:
7822 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
7824 if (pdi
->is_external
7825 || cu
->per_cu
->lang
== language_ada
7826 || (cu
->per_cu
->lang
== language_fortran
7827 && pdi
->die_parent
!= NULL
7828 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
7830 /* Normally, only "external" DIEs are part of the global scope.
7831 But in Ada and Fortran, we want to be able to access nested
7832 procedures globally. So all Ada and Fortran subprograms are
7833 stored in the global scope. */
7834 where
= psymbol_placement::GLOBAL
;
7837 where
= psymbol_placement::STATIC
;
7839 psymbol
.domain
= VAR_DOMAIN
;
7840 psymbol
.aclass
= LOC_BLOCK
;
7841 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7842 psymbol
.ginfo
.value
.address
= addr
;
7844 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
7845 set_objfile_main_name (objfile
, actual_name
, cu
->per_cu
->lang
);
7847 case DW_TAG_constant
:
7848 psymbol
.domain
= VAR_DOMAIN
;
7849 psymbol
.aclass
= LOC_STATIC
;
7850 where
= (pdi
->is_external
7851 ? psymbol_placement::GLOBAL
7852 : psymbol_placement::STATIC
);
7854 case DW_TAG_variable
:
7856 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
7860 && !per_objfile
->per_bfd
->has_section_at_zero
)
7862 /* A global or static variable may also have been stripped
7863 out by the linker if unused, in which case its address
7864 will be nullified; do not add such variables into partial
7865 symbol table then. */
7867 else if (pdi
->is_external
)
7870 Don't enter into the minimal symbol tables as there is
7871 a minimal symbol table entry from the ELF symbols already.
7872 Enter into partial symbol table if it has a location
7873 descriptor or a type.
7874 If the location descriptor is missing, new_symbol will create
7875 a LOC_UNRESOLVED symbol, the address of the variable will then
7876 be determined from the minimal symbol table whenever the variable
7878 The address for the partial symbol table entry is not
7879 used by GDB, but it comes in handy for debugging partial symbol
7882 if (pdi
->d
.locdesc
|| pdi
->has_type
)
7884 psymbol
.domain
= VAR_DOMAIN
;
7885 psymbol
.aclass
= LOC_STATIC
;
7886 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7887 psymbol
.ginfo
.value
.address
= addr
;
7888 where
= psymbol_placement::GLOBAL
;
7893 int has_loc
= pdi
->d
.locdesc
!= NULL
;
7895 /* Static Variable. Skip symbols whose value we cannot know (those
7896 without location descriptors or constant values). */
7897 if (!has_loc
&& !pdi
->has_const_value
)
7900 psymbol
.domain
= VAR_DOMAIN
;
7901 psymbol
.aclass
= LOC_STATIC
;
7902 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
7904 psymbol
.ginfo
.value
.address
= addr
;
7905 where
= psymbol_placement::STATIC
;
7908 case DW_TAG_array_type
:
7909 case DW_TAG_typedef
:
7910 case DW_TAG_base_type
:
7911 case DW_TAG_subrange_type
:
7912 psymbol
.domain
= VAR_DOMAIN
;
7913 psymbol
.aclass
= LOC_TYPEDEF
;
7914 where
= psymbol_placement::STATIC
;
7916 case DW_TAG_imported_declaration
:
7917 case DW_TAG_namespace
:
7918 psymbol
.domain
= VAR_DOMAIN
;
7919 psymbol
.aclass
= LOC_TYPEDEF
;
7920 where
= psymbol_placement::GLOBAL
;
7923 /* With Fortran 77 there might be a "BLOCK DATA" module
7924 available without any name. If so, we skip the module as it
7925 doesn't bring any value. */
7926 if (actual_name
!= nullptr)
7928 psymbol
.domain
= MODULE_DOMAIN
;
7929 psymbol
.aclass
= LOC_TYPEDEF
;
7930 where
= psymbol_placement::GLOBAL
;
7933 case DW_TAG_class_type
:
7934 case DW_TAG_interface_type
:
7935 case DW_TAG_structure_type
:
7936 case DW_TAG_union_type
:
7937 case DW_TAG_enumeration_type
:
7938 /* Skip external references. The DWARF standard says in the section
7939 about "Structure, Union, and Class Type Entries": "An incomplete
7940 structure, union or class type is represented by a structure,
7941 union or class entry that does not have a byte size attribute
7942 and that has a DW_AT_declaration attribute." */
7943 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
7946 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
7947 static vs. global. */
7948 psymbol
.domain
= STRUCT_DOMAIN
;
7949 psymbol
.aclass
= LOC_TYPEDEF
;
7950 where
= (cu
->per_cu
->lang
== language_cplus
7951 ? psymbol_placement::GLOBAL
7952 : psymbol_placement::STATIC
);
7954 case DW_TAG_enumerator
:
7955 psymbol
.domain
= VAR_DOMAIN
;
7956 psymbol
.aclass
= LOC_CONST
;
7957 where
= (cu
->per_cu
->lang
== language_cplus
7958 ? psymbol_placement::GLOBAL
7959 : psymbol_placement::STATIC
);
7965 if (where
.has_value ())
7967 if (built_actual_name
!= nullptr)
7968 actual_name
= objfile
->intern (actual_name
);
7969 if (pdi
->linkage_name
== nullptr
7970 || cu
->per_cu
->lang
== language_ada
)
7971 psymbol
.ginfo
.set_linkage_name (actual_name
);
7974 psymbol
.ginfo
.set_demangled_name (actual_name
,
7975 &objfile
->objfile_obstack
);
7976 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
7978 cu
->per_cu
->v
.psymtab
->add_psymbol
7979 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7984 /* Read a partial die corresponding to a namespace; also, add a symbol
7985 corresponding to that namespace to the symbol table. NAMESPACE is
7986 the name of the enclosing namespace. */
7989 add_partial_namespace (struct partial_die_info
*pdi
,
7990 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7991 int set_addrmap
, struct dwarf2_cu
*cu
)
7993 /* Add a symbol for the namespace. */
7995 add_partial_symbol (pdi
, cu
);
7997 /* Now scan partial symbols in that namespace. */
7999 if (pdi
->has_children
)
8000 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8003 /* Read a partial die corresponding to a Fortran module. */
8006 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8007 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8009 /* Add a symbol for the namespace. */
8011 add_partial_symbol (pdi
, cu
);
8013 /* Now scan partial symbols in that module. */
8015 if (pdi
->has_children
)
8016 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8019 /* Read a partial die corresponding to a subprogram or an inlined
8020 subprogram and create a partial symbol for that subprogram.
8021 When the CU language allows it, this routine also defines a partial
8022 symbol for each nested subprogram that this subprogram contains.
8023 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8024 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8026 PDI may also be a lexical block, in which case we simply search
8027 recursively for subprograms defined inside that lexical block.
8028 Again, this is only performed when the CU language allows this
8029 type of definitions. */
8032 add_partial_subprogram (struct partial_die_info
*pdi
,
8033 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8034 int set_addrmap
, struct dwarf2_cu
*cu
)
8036 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8038 if (pdi
->has_pc_info
)
8040 if (pdi
->lowpc
< *lowpc
)
8041 *lowpc
= pdi
->lowpc
;
8042 if (pdi
->highpc
> *highpc
)
8043 *highpc
= pdi
->highpc
;
8046 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8047 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8048 struct gdbarch
*gdbarch
= objfile
->arch ();
8050 CORE_ADDR this_highpc
;
8051 CORE_ADDR this_lowpc
;
8053 baseaddr
= objfile
->text_section_offset ();
8055 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8056 pdi
->lowpc
+ baseaddr
)
8059 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8060 pdi
->highpc
+ baseaddr
)
8062 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8063 this_lowpc
, this_highpc
- 1,
8064 cu
->per_cu
->v
.psymtab
);
8068 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8070 if (!pdi
->is_declaration
)
8071 /* Ignore subprogram DIEs that do not have a name, they are
8072 illegal. Do not emit a complaint at this point, we will
8073 do so when we convert this psymtab into a symtab. */
8075 add_partial_symbol (pdi
, cu
);
8079 if (! pdi
->has_children
)
8082 if (cu
->per_cu
->lang
== language_ada
8083 || cu
->per_cu
->lang
== language_fortran
)
8085 pdi
= pdi
->die_child
;
8089 if (pdi
->tag
== DW_TAG_subprogram
8090 || pdi
->tag
== DW_TAG_inlined_subroutine
8091 || pdi
->tag
== DW_TAG_lexical_block
)
8092 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8093 pdi
= pdi
->die_sibling
;
8098 /* Read a partial die corresponding to an enumeration type. */
8101 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8102 struct dwarf2_cu
*cu
)
8104 struct partial_die_info
*pdi
;
8106 if (enum_pdi
->name (cu
) != NULL
)
8107 add_partial_symbol (enum_pdi
, cu
);
8109 pdi
= enum_pdi
->die_child
;
8112 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8113 complaint (_("malformed enumerator DIE ignored"));
8115 add_partial_symbol (pdi
, cu
);
8116 pdi
= pdi
->die_sibling
;
8120 /* Return the initial uleb128 in the die at INFO_PTR. */
8123 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8125 unsigned int bytes_read
;
8127 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8130 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8131 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8133 Return the corresponding abbrev, or NULL if the number is zero (indicating
8134 an empty DIE). In either case *BYTES_READ will be set to the length of
8135 the initial number. */
8137 static const struct abbrev_info
*
8138 peek_die_abbrev (const die_reader_specs
&reader
,
8139 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8141 dwarf2_cu
*cu
= reader
.cu
;
8142 bfd
*abfd
= reader
.abfd
;
8143 unsigned int abbrev_number
8144 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8146 if (abbrev_number
== 0)
8149 const abbrev_info
*abbrev
8150 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8153 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8154 " at offset %s [in module %s]"),
8155 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8156 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8162 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8163 Returns a pointer to the end of a series of DIEs, terminated by an empty
8164 DIE. Any children of the skipped DIEs will also be skipped. */
8166 static const gdb_byte
*
8167 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8171 unsigned int bytes_read
;
8172 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8176 return info_ptr
+ bytes_read
;
8178 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8182 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8183 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8184 abbrev corresponding to that skipped uleb128 should be passed in
8185 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8188 static const gdb_byte
*
8189 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8190 const struct abbrev_info
*abbrev
)
8192 unsigned int bytes_read
;
8193 struct attribute attr
;
8194 bfd
*abfd
= reader
->abfd
;
8195 struct dwarf2_cu
*cu
= reader
->cu
;
8196 const gdb_byte
*buffer
= reader
->buffer
;
8197 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8198 unsigned int form
, i
;
8200 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8202 /* The only abbrev we care about is DW_AT_sibling. */
8203 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8205 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8206 if (attr
.form
== DW_FORM_ref_addr
)
8207 complaint (_("ignoring absolute DW_AT_sibling"));
8210 sect_offset off
= attr
.get_ref_die_offset ();
8211 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8213 if (sibling_ptr
< info_ptr
)
8214 complaint (_("DW_AT_sibling points backwards"));
8215 else if (sibling_ptr
> reader
->buffer_end
)
8216 reader
->die_section
->overflow_complaint ();
8222 /* If it isn't DW_AT_sibling, skip this attribute. */
8223 form
= abbrev
->attrs
[i
].form
;
8227 case DW_FORM_ref_addr
:
8228 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8229 and later it is offset sized. */
8230 if (cu
->header
.version
== 2)
8231 info_ptr
+= cu
->header
.addr_size
;
8233 info_ptr
+= cu
->header
.offset_size
;
8235 case DW_FORM_GNU_ref_alt
:
8236 info_ptr
+= cu
->header
.offset_size
;
8239 info_ptr
+= cu
->header
.addr_size
;
8247 case DW_FORM_flag_present
:
8248 case DW_FORM_implicit_const
:
8265 case DW_FORM_ref_sig8
:
8268 case DW_FORM_data16
:
8271 case DW_FORM_string
:
8272 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8273 info_ptr
+= bytes_read
;
8275 case DW_FORM_sec_offset
:
8277 case DW_FORM_GNU_strp_alt
:
8278 info_ptr
+= cu
->header
.offset_size
;
8280 case DW_FORM_exprloc
:
8282 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8283 info_ptr
+= bytes_read
;
8285 case DW_FORM_block1
:
8286 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8288 case DW_FORM_block2
:
8289 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8291 case DW_FORM_block4
:
8292 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8298 case DW_FORM_ref_udata
:
8299 case DW_FORM_GNU_addr_index
:
8300 case DW_FORM_GNU_str_index
:
8301 case DW_FORM_rnglistx
:
8302 case DW_FORM_loclistx
:
8303 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8305 case DW_FORM_indirect
:
8306 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8307 info_ptr
+= bytes_read
;
8308 /* We need to continue parsing from here, so just go back to
8310 goto skip_attribute
;
8313 error (_("Dwarf Error: Cannot handle %s "
8314 "in DWARF reader [in module %s]"),
8315 dwarf_form_name (form
),
8316 bfd_get_filename (abfd
));
8320 if (abbrev
->has_children
)
8321 return skip_children (reader
, info_ptr
);
8326 /* Locate ORIG_PDI's sibling.
8327 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8329 static const gdb_byte
*
8330 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8331 struct partial_die_info
*orig_pdi
,
8332 const gdb_byte
*info_ptr
)
8334 /* Do we know the sibling already? */
8336 if (orig_pdi
->sibling
)
8337 return orig_pdi
->sibling
;
8339 /* Are there any children to deal with? */
8341 if (!orig_pdi
->has_children
)
8344 /* Skip the children the long way. */
8346 return skip_children (reader
, info_ptr
);
8349 /* Expand this partial symbol table into a full symbol table. SELF is
8353 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8355 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8357 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8359 /* If this psymtab is constructed from a debug-only objfile, the
8360 has_section_at_zero flag will not necessarily be correct. We
8361 can get the correct value for this flag by looking at the data
8362 associated with the (presumably stripped) associated objfile. */
8363 if (objfile
->separate_debug_objfile_backlink
)
8365 dwarf2_per_objfile
*per_objfile_backlink
8366 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8368 per_objfile
->per_bfd
->has_section_at_zero
8369 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8372 expand_psymtab (objfile
);
8374 process_cu_includes (per_objfile
);
8377 /* Reading in full CUs. */
8379 /* Add PER_CU to the queue. */
8382 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8383 dwarf2_per_objfile
*per_objfile
,
8384 enum language pretend_language
)
8388 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8389 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8392 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8394 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8397 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8398 DIEs, false otherwise.
8400 Explanation: there is an invariant that if a CU is queued for expansion
8401 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8402 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8403 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8404 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8405 invariant is respected.
8407 The caller is therefore not required to load the CU's DIEs (we return false)
8410 - the CU is already expanded, and therefore does not get enqueued
8411 - the CU gets enqueued for expansion, but its DIEs are already loaded
8413 Note that the caller should not use this function's return value as an
8414 indicator of whether the CU's DIEs are loaded right now, it should check
8415 that by calling `dwarf2_per_objfile::get_cu` instead. */
8418 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8419 dwarf2_per_cu_data
*per_cu
,
8420 dwarf2_per_objfile
*per_objfile
,
8421 enum language pretend_language
)
8423 /* We may arrive here during partial symbol reading, if we need full
8424 DIEs to process an unusual case (e.g. template arguments). Do
8425 not queue PER_CU, just tell our caller to load its DIEs. */
8426 if (per_cu
->per_bfd
->reading_partial_symbols
)
8428 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8430 if (cu
== NULL
|| cu
->dies
== NULL
)
8435 /* Mark the dependence relation so that we don't flush PER_CU
8437 if (dependent_cu
!= NULL
)
8438 dependent_cu
->add_dependence (per_cu
);
8440 /* If it's already on the queue, we have nothing to do. */
8443 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8445 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8447 /* If the CU is queued for expansion, it should not already be
8449 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8451 /* The DIEs are already loaded, the caller doesn't need to do it. */
8455 bool queued
= false;
8456 if (!per_objfile
->symtab_set_p (per_cu
))
8458 /* Add it to the queue. */
8459 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8463 /* If the compilation unit is already loaded, just mark it as
8465 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8469 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8470 and the DIEs are not already loaded. */
8471 return queued
&& cu
== nullptr;
8474 /* Process the queue. */
8477 process_queue (dwarf2_per_objfile
*per_objfile
)
8479 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8480 objfile_name (per_objfile
->objfile
));
8482 /* The queue starts out with one item, but following a DIE reference
8483 may load a new CU, adding it to the end of the queue. */
8484 while (!per_objfile
->per_bfd
->queue
->empty ())
8486 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8487 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8489 if (!per_objfile
->symtab_set_p (per_cu
))
8491 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8493 /* Skip dummy CUs. */
8496 unsigned int debug_print_threshold
;
8499 if (per_cu
->is_debug_types
)
8501 struct signatured_type
*sig_type
=
8502 (struct signatured_type
*) per_cu
;
8504 sprintf (buf
, "TU %s at offset %s",
8505 hex_string (sig_type
->signature
),
8506 sect_offset_str (per_cu
->sect_off
));
8507 /* There can be 100s of TUs.
8508 Only print them in verbose mode. */
8509 debug_print_threshold
= 2;
8513 sprintf (buf
, "CU at offset %s",
8514 sect_offset_str (per_cu
->sect_off
));
8515 debug_print_threshold
= 1;
8518 if (dwarf_read_debug
>= debug_print_threshold
)
8519 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8521 if (per_cu
->is_debug_types
)
8522 process_full_type_unit (cu
, item
.pretend_language
);
8524 process_full_comp_unit (cu
, item
.pretend_language
);
8526 if (dwarf_read_debug
>= debug_print_threshold
)
8527 dwarf_read_debug_printf ("Done expanding %s", buf
);
8532 per_objfile
->per_bfd
->queue
->pop ();
8535 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8536 objfile_name (per_objfile
->objfile
));
8539 /* Read in full symbols for PST, and anything it depends on. */
8542 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8544 gdb_assert (!readin_p (objfile
));
8546 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8547 free_cached_comp_units
freer (per_objfile
);
8548 expand_dependencies (objfile
);
8550 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8551 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8554 /* See psympriv.h. */
8557 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8559 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8560 return per_objfile
->symtab_set_p (per_cu_data
);
8563 /* See psympriv.h. */
8566 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8568 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8569 return per_objfile
->get_symtab (per_cu_data
);
8572 /* Trivial hash function for die_info: the hash value of a DIE
8573 is its offset in .debug_info for this objfile. */
8576 die_hash (const void *item
)
8578 const struct die_info
*die
= (const struct die_info
*) item
;
8580 return to_underlying (die
->sect_off
);
8583 /* Trivial comparison function for die_info structures: two DIEs
8584 are equal if they have the same offset. */
8587 die_eq (const void *item_lhs
, const void *item_rhs
)
8589 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8590 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8592 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8595 /* Load the DIEs associated with PER_CU into memory.
8597 In some cases, the caller, while reading partial symbols, will need to load
8598 the full symbols for the CU for some reason. It will already have a
8599 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8600 rather than creating a new one. */
8603 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8604 dwarf2_per_objfile
*per_objfile
,
8605 dwarf2_cu
*existing_cu
,
8607 enum language pretend_language
)
8609 gdb_assert (! this_cu
->is_debug_types
);
8611 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8615 struct dwarf2_cu
*cu
= reader
.cu
;
8616 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8618 gdb_assert (cu
->die_hash
== NULL
);
8620 htab_create_alloc_ex (cu
->header
.length
/ 12,
8624 &cu
->comp_unit_obstack
,
8625 hashtab_obstack_allocate
,
8626 dummy_obstack_deallocate
);
8628 if (reader
.comp_unit_die
->has_children
)
8629 reader
.comp_unit_die
->child
8630 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8631 &info_ptr
, reader
.comp_unit_die
);
8632 cu
->dies
= reader
.comp_unit_die
;
8633 /* comp_unit_die is not stored in die_hash, no need. */
8635 /* We try not to read any attributes in this function, because not
8636 all CUs needed for references have been loaded yet, and symbol
8637 table processing isn't initialized. But we have to set the CU language,
8638 or we won't be able to build types correctly.
8639 Similarly, if we do not read the producer, we can not apply
8640 producer-specific interpretation. */
8641 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8646 /* Add a DIE to the delayed physname list. */
8649 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8650 const char *name
, struct die_info
*die
,
8651 struct dwarf2_cu
*cu
)
8653 struct delayed_method_info mi
;
8655 mi
.fnfield_index
= fnfield_index
;
8659 cu
->method_list
.push_back (mi
);
8662 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8663 "const" / "volatile". If so, decrements LEN by the length of the
8664 modifier and return true. Otherwise return false. */
8668 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8670 size_t mod_len
= sizeof (mod
) - 1;
8671 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8679 /* Compute the physnames of any methods on the CU's method list.
8681 The computation of method physnames is delayed in order to avoid the
8682 (bad) condition that one of the method's formal parameters is of an as yet
8686 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8688 /* Only C++ delays computing physnames. */
8689 if (cu
->method_list
.empty ())
8691 gdb_assert (cu
->per_cu
->lang
== language_cplus
);
8693 for (const delayed_method_info
&mi
: cu
->method_list
)
8695 const char *physname
;
8696 struct fn_fieldlist
*fn_flp
8697 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8698 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8699 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8700 = physname
? physname
: "";
8702 /* Since there's no tag to indicate whether a method is a
8703 const/volatile overload, extract that information out of the
8705 if (physname
!= NULL
)
8707 size_t len
= strlen (physname
);
8711 if (physname
[len
] == ')') /* shortcut */
8713 else if (check_modifier (physname
, len
, " const"))
8714 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8715 else if (check_modifier (physname
, len
, " volatile"))
8716 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8723 /* The list is no longer needed. */
8724 cu
->method_list
.clear ();
8727 /* Go objects should be embedded in a DW_TAG_module DIE,
8728 and it's not clear if/how imported objects will appear.
8729 To keep Go support simple until that's worked out,
8730 go back through what we've read and create something usable.
8731 We could do this while processing each DIE, and feels kinda cleaner,
8732 but that way is more invasive.
8733 This is to, for example, allow the user to type "p var" or "b main"
8734 without having to specify the package name, and allow lookups
8735 of module.object to work in contexts that use the expression
8739 fixup_go_packaging (struct dwarf2_cu
*cu
)
8741 gdb::unique_xmalloc_ptr
<char> package_name
;
8742 struct pending
*list
;
8745 for (list
= *cu
->get_builder ()->get_global_symbols ();
8749 for (i
= 0; i
< list
->nsyms
; ++i
)
8751 struct symbol
*sym
= list
->symbol
[i
];
8753 if (sym
->language () == language_go
8754 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8756 gdb::unique_xmalloc_ptr
<char> this_package_name
8757 (go_symbol_package_name (sym
));
8759 if (this_package_name
== NULL
)
8761 if (package_name
== NULL
)
8762 package_name
= std::move (this_package_name
);
8765 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8766 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8767 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8768 (symbol_symtab (sym
) != NULL
8769 ? symtab_to_filename_for_display
8770 (symbol_symtab (sym
))
8771 : objfile_name (objfile
)),
8772 this_package_name
.get (), package_name
.get ());
8778 if (package_name
!= NULL
)
8780 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8781 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8782 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8783 saved_package_name
);
8786 sym
= new (&objfile
->objfile_obstack
) symbol
;
8787 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8788 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8789 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8790 e.g., "main" finds the "main" module and not C's main(). */
8791 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8792 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8793 SYMBOL_TYPE (sym
) = type
;
8795 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
8799 /* Allocate a fully-qualified name consisting of the two parts on the
8803 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
8805 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
8808 /* A helper that allocates a variant part to attach to a Rust enum
8809 type. OBSTACK is where the results should be allocated. TYPE is
8810 the type we're processing. DISCRIMINANT_INDEX is the index of the
8811 discriminant. It must be the index of one of the fields of TYPE,
8812 or -1 to mean there is no discriminant (univariant enum).
8813 DEFAULT_INDEX is the index of the default field; or -1 if there is
8814 no default. RANGES is indexed by "effective" field number (the
8815 field index, but omitting the discriminant and default fields) and
8816 must hold the discriminant values used by the variants. Note that
8817 RANGES must have a lifetime at least as long as OBSTACK -- either
8818 already allocated on it, or static. */
8821 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
8822 int discriminant_index
, int default_index
,
8823 gdb::array_view
<discriminant_range
> ranges
)
8825 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
8826 gdb_assert (discriminant_index
== -1
8827 || (discriminant_index
>= 0
8828 && discriminant_index
< type
->num_fields ()));
8829 gdb_assert (default_index
== -1
8830 || (default_index
>= 0 && default_index
< type
->num_fields ()));
8832 /* We have one variant for each non-discriminant field. */
8833 int n_variants
= type
->num_fields ();
8834 if (discriminant_index
!= -1)
8837 variant
*variants
= new (obstack
) variant
[n_variants
];
8840 for (int i
= 0; i
< type
->num_fields (); ++i
)
8842 if (i
== discriminant_index
)
8845 variants
[var_idx
].first_field
= i
;
8846 variants
[var_idx
].last_field
= i
+ 1;
8848 /* The default field does not need a range, but other fields do.
8849 We skipped the discriminant above. */
8850 if (i
!= default_index
)
8852 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
8859 gdb_assert (range_idx
== ranges
.size ());
8860 gdb_assert (var_idx
== n_variants
);
8862 variant_part
*part
= new (obstack
) variant_part
;
8863 part
->discriminant_index
= discriminant_index
;
8864 /* If there is no discriminant, then whether it is signed is of no
8867 = (discriminant_index
== -1
8869 : type
->field (discriminant_index
).type ()->is_unsigned ());
8870 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
8872 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
8873 gdb::array_view
<variant_part
> *prop_value
8874 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
8876 struct dynamic_prop prop
;
8877 prop
.set_variant_parts (prop_value
);
8879 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
8882 /* Some versions of rustc emitted enums in an unusual way.
8884 Ordinary enums were emitted as unions. The first element of each
8885 structure in the union was named "RUST$ENUM$DISR". This element
8886 held the discriminant.
8888 These versions of Rust also implemented the "non-zero"
8889 optimization. When the enum had two values, and one is empty and
8890 the other holds a pointer that cannot be zero, the pointer is used
8891 as the discriminant, with a zero value meaning the empty variant.
8892 Here, the union's first member is of the form
8893 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
8894 where the fieldnos are the indices of the fields that should be
8895 traversed in order to find the field (which may be several fields deep)
8896 and the variantname is the name of the variant of the case when the
8899 This function recognizes whether TYPE is of one of these forms,
8900 and, if so, smashes it to be a variant type. */
8903 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
8905 gdb_assert (type
->code () == TYPE_CODE_UNION
);
8907 /* We don't need to deal with empty enums. */
8908 if (type
->num_fields () == 0)
8911 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
8912 if (type
->num_fields () == 1
8913 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
8915 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
8917 /* Decode the field name to find the offset of the
8919 ULONGEST bit_offset
= 0;
8920 struct type
*field_type
= type
->field (0).type ();
8921 while (name
[0] >= '0' && name
[0] <= '9')
8924 unsigned long index
= strtoul (name
, &tail
, 10);
8927 || index
>= field_type
->num_fields ()
8928 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
8929 != FIELD_LOC_KIND_BITPOS
))
8931 complaint (_("Could not parse Rust enum encoding string \"%s\""
8933 TYPE_FIELD_NAME (type
, 0),
8934 objfile_name (objfile
));
8939 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
8940 field_type
= field_type
->field (index
).type ();
8943 /* Smash this type to be a structure type. We have to do this
8944 because the type has already been recorded. */
8945 type
->set_code (TYPE_CODE_STRUCT
);
8946 type
->set_num_fields (3);
8947 /* Save the field we care about. */
8948 struct field saved_field
= type
->field (0);
8950 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
8952 /* Put the discriminant at index 0. */
8953 type
->field (0).set_type (field_type
);
8954 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
8955 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
8956 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
8958 /* The order of fields doesn't really matter, so put the real
8959 field at index 1 and the data-less field at index 2. */
8960 type
->field (1) = saved_field
;
8961 TYPE_FIELD_NAME (type
, 1)
8962 = rust_last_path_segment (type
->field (1).type ()->name ());
8963 type
->field (1).type ()->set_name
8964 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8965 TYPE_FIELD_NAME (type
, 1)));
8967 const char *dataless_name
8968 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
8970 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
8972 type
->field (2).set_type (dataless_type
);
8973 /* NAME points into the original discriminant name, which
8974 already has the correct lifetime. */
8975 TYPE_FIELD_NAME (type
, 2) = name
;
8976 SET_FIELD_BITPOS (type
->field (2), 0);
8978 /* Indicate that this is a variant type. */
8979 static discriminant_range ranges
[1] = { { 0, 0 } };
8980 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
8982 /* A union with a single anonymous field is probably an old-style
8984 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
8986 /* Smash this type to be a structure type. We have to do this
8987 because the type has already been recorded. */
8988 type
->set_code (TYPE_CODE_STRUCT
);
8990 struct type
*field_type
= type
->field (0).type ();
8991 const char *variant_name
8992 = rust_last_path_segment (field_type
->name ());
8993 TYPE_FIELD_NAME (type
, 0) = variant_name
;
8994 field_type
->set_name
8995 (rust_fully_qualify (&objfile
->objfile_obstack
,
8996 type
->name (), variant_name
));
8998 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9002 struct type
*disr_type
= nullptr;
9003 for (int i
= 0; i
< type
->num_fields (); ++i
)
9005 disr_type
= type
->field (i
).type ();
9007 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9009 /* All fields of a true enum will be structs. */
9012 else if (disr_type
->num_fields () == 0)
9014 /* Could be data-less variant, so keep going. */
9015 disr_type
= nullptr;
9017 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9018 "RUST$ENUM$DISR") != 0)
9020 /* Not a Rust enum. */
9030 /* If we got here without a discriminant, then it's probably
9032 if (disr_type
== nullptr)
9035 /* Smash this type to be a structure type. We have to do this
9036 because the type has already been recorded. */
9037 type
->set_code (TYPE_CODE_STRUCT
);
9039 /* Make space for the discriminant field. */
9040 struct field
*disr_field
= &disr_type
->field (0);
9042 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9043 * sizeof (struct field
)));
9044 memcpy (new_fields
+ 1, type
->fields (),
9045 type
->num_fields () * sizeof (struct field
));
9046 type
->set_fields (new_fields
);
9047 type
->set_num_fields (type
->num_fields () + 1);
9049 /* Install the discriminant at index 0 in the union. */
9050 type
->field (0) = *disr_field
;
9051 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9052 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9054 /* We need a way to find the correct discriminant given a
9055 variant name. For convenience we build a map here. */
9056 struct type
*enum_type
= disr_field
->type ();
9057 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9058 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9060 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9063 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9064 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9068 int n_fields
= type
->num_fields ();
9069 /* We don't need a range entry for the discriminant, but we do
9070 need one for every other field, as there is no default
9072 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9075 /* Skip the discriminant here. */
9076 for (int i
= 1; i
< n_fields
; ++i
)
9078 /* Find the final word in the name of this variant's type.
9079 That name can be used to look up the correct
9081 const char *variant_name
9082 = rust_last_path_segment (type
->field (i
).type ()->name ());
9084 auto iter
= discriminant_map
.find (variant_name
);
9085 if (iter
!= discriminant_map
.end ())
9087 ranges
[i
- 1].low
= iter
->second
;
9088 ranges
[i
- 1].high
= iter
->second
;
9091 /* In Rust, each element should have the size of the
9093 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9095 /* Remove the discriminant field, if it exists. */
9096 struct type
*sub_type
= type
->field (i
).type ();
9097 if (sub_type
->num_fields () > 0)
9099 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9100 sub_type
->set_fields (sub_type
->fields () + 1);
9102 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9104 (rust_fully_qualify (&objfile
->objfile_obstack
,
9105 type
->name (), variant_name
));
9108 /* Indicate that this is a variant type. */
9109 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9110 gdb::array_view
<discriminant_range
> (ranges
,
9115 /* Rewrite some Rust unions to be structures with variants parts. */
9118 rust_union_quirks (struct dwarf2_cu
*cu
)
9120 gdb_assert (cu
->per_cu
->lang
== language_rust
);
9121 for (type
*type_
: cu
->rust_unions
)
9122 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9123 /* We don't need this any more. */
9124 cu
->rust_unions
.clear ();
9129 type_unit_group_unshareable
*
9130 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9132 auto iter
= this->m_type_units
.find (tu_group
);
9133 if (iter
!= this->m_type_units
.end ())
9134 return iter
->second
.get ();
9136 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9137 type_unit_group_unshareable
*result
= uniq
.get ();
9138 this->m_type_units
[tu_group
] = std::move (uniq
);
9143 dwarf2_per_objfile::get_type_for_signatured_type
9144 (signatured_type
*sig_type
) const
9146 auto iter
= this->m_type_map
.find (sig_type
);
9147 if (iter
== this->m_type_map
.end ())
9150 return iter
->second
;
9153 void dwarf2_per_objfile::set_type_for_signatured_type
9154 (signatured_type
*sig_type
, struct type
*type
)
9156 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9158 this->m_type_map
[sig_type
] = type
;
9161 /* A helper function for computing the list of all symbol tables
9162 included by PER_CU. */
9165 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9166 htab_t all_children
, htab_t all_type_symtabs
,
9167 dwarf2_per_cu_data
*per_cu
,
9168 dwarf2_per_objfile
*per_objfile
,
9169 struct compunit_symtab
*immediate_parent
)
9171 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9174 /* This inclusion and its children have been processed. */
9180 /* Only add a CU if it has a symbol table. */
9181 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9184 /* If this is a type unit only add its symbol table if we haven't
9185 seen it yet (type unit per_cu's can share symtabs). */
9186 if (per_cu
->is_debug_types
)
9188 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9192 result
->push_back (cust
);
9193 if (cust
->user
== NULL
)
9194 cust
->user
= immediate_parent
;
9199 result
->push_back (cust
);
9200 if (cust
->user
== NULL
)
9201 cust
->user
= immediate_parent
;
9205 if (!per_cu
->imported_symtabs_empty ())
9206 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9208 recursively_compute_inclusions (result
, all_children
,
9209 all_type_symtabs
, ptr
, per_objfile
,
9214 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9218 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9219 dwarf2_per_objfile
*per_objfile
)
9221 gdb_assert (! per_cu
->is_debug_types
);
9223 if (!per_cu
->imported_symtabs_empty ())
9226 std::vector
<compunit_symtab
*> result_symtabs
;
9227 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9229 /* If we don't have a symtab, we can just skip this case. */
9233 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9235 NULL
, xcalloc
, xfree
));
9236 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9238 NULL
, xcalloc
, xfree
));
9240 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9242 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9243 all_type_symtabs
.get (), ptr
,
9247 /* Now we have a transitive closure of all the included symtabs. */
9248 len
= result_symtabs
.size ();
9250 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9251 struct compunit_symtab
*, len
+ 1);
9252 memcpy (cust
->includes
, result_symtabs
.data (),
9253 len
* sizeof (compunit_symtab
*));
9254 cust
->includes
[len
] = NULL
;
9258 /* Compute the 'includes' field for the symtabs of all the CUs we just
9262 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9264 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9266 if (! iter
->is_debug_types
)
9267 compute_compunit_symtab_includes (iter
, per_objfile
);
9270 per_objfile
->per_bfd
->just_read_cus
.clear ();
9273 /* Generate full symbol information for CU, whose DIEs have
9274 already been loaded into memory. */
9277 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9279 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9280 struct objfile
*objfile
= per_objfile
->objfile
;
9281 struct gdbarch
*gdbarch
= objfile
->arch ();
9282 CORE_ADDR lowpc
, highpc
;
9283 struct compunit_symtab
*cust
;
9285 struct block
*static_block
;
9288 baseaddr
= objfile
->text_section_offset ();
9290 /* Clear the list here in case something was left over. */
9291 cu
->method_list
.clear ();
9293 dwarf2_find_base_address (cu
->dies
, cu
);
9295 /* Before we start reading the top-level DIE, ensure it has a valid tag
9297 switch (cu
->dies
->tag
)
9299 case DW_TAG_compile_unit
:
9300 case DW_TAG_partial_unit
:
9301 case DW_TAG_type_unit
:
9304 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9305 dwarf_tag_name (cu
->dies
->tag
),
9306 sect_offset_str (cu
->per_cu
->sect_off
),
9307 objfile_name (per_objfile
->objfile
));
9310 /* Do line number decoding in read_file_scope () */
9311 process_die (cu
->dies
, cu
);
9313 /* For now fudge the Go package. */
9314 if (cu
->per_cu
->lang
== language_go
)
9315 fixup_go_packaging (cu
);
9317 /* Now that we have processed all the DIEs in the CU, all the types
9318 should be complete, and it should now be safe to compute all of the
9320 compute_delayed_physnames (cu
);
9322 if (cu
->per_cu
->lang
== language_rust
)
9323 rust_union_quirks (cu
);
9325 /* Some compilers don't define a DW_AT_high_pc attribute for the
9326 compilation unit. If the DW_AT_high_pc is missing, synthesize
9327 it, by scanning the DIE's below the compilation unit. */
9328 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9330 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9331 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9333 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9334 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9335 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9336 addrmap to help ensure it has an accurate map of pc values belonging to
9338 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9340 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9341 SECT_OFF_TEXT (objfile
),
9346 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9348 /* Set symtab language to language from DW_AT_language. If the
9349 compilation is from a C file generated by language preprocessors, do
9350 not set the language if it was already deduced by start_subfile. */
9351 if (!(cu
->per_cu
->lang
== language_c
9352 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9353 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9355 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9356 produce DW_AT_location with location lists but it can be possibly
9357 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9358 there were bugs in prologue debug info, fixed later in GCC-4.5
9359 by "unwind info for epilogues" patch (which is not directly related).
9361 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9362 needed, it would be wrong due to missing DW_AT_producer there.
9364 Still one can confuse GDB by using non-standard GCC compilation
9365 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9367 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9368 cust
->locations_valid
= 1;
9370 if (gcc_4_minor
>= 5)
9371 cust
->epilogue_unwind_valid
= 1;
9373 cust
->call_site_htab
= cu
->call_site_htab
;
9376 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9378 /* Push it for inclusion processing later. */
9379 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9381 /* Not needed any more. */
9382 cu
->reset_builder ();
9385 /* Generate full symbol information for type unit CU, whose DIEs have
9386 already been loaded into memory. */
9389 process_full_type_unit (dwarf2_cu
*cu
,
9390 enum language pretend_language
)
9392 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9393 struct objfile
*objfile
= per_objfile
->objfile
;
9394 struct compunit_symtab
*cust
;
9395 struct signatured_type
*sig_type
;
9397 gdb_assert (cu
->per_cu
->is_debug_types
);
9398 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9400 /* Clear the list here in case something was left over. */
9401 cu
->method_list
.clear ();
9403 /* The symbol tables are set up in read_type_unit_scope. */
9404 process_die (cu
->dies
, cu
);
9406 /* For now fudge the Go package. */
9407 if (cu
->per_cu
->lang
== language_go
)
9408 fixup_go_packaging (cu
);
9410 /* Now that we have processed all the DIEs in the CU, all the types
9411 should be complete, and it should now be safe to compute all of the
9413 compute_delayed_physnames (cu
);
9415 if (cu
->per_cu
->lang
== language_rust
)
9416 rust_union_quirks (cu
);
9418 /* TUs share symbol tables.
9419 If this is the first TU to use this symtab, complete the construction
9420 of it with end_expandable_symtab. Otherwise, complete the addition of
9421 this TU's symbols to the existing symtab. */
9422 type_unit_group_unshareable
*tug_unshare
=
9423 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9424 if (tug_unshare
->compunit_symtab
== NULL
)
9426 buildsym_compunit
*builder
= cu
->get_builder ();
9427 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9428 tug_unshare
->compunit_symtab
= cust
;
9432 /* Set symtab language to language from DW_AT_language. If the
9433 compilation is from a C file generated by language preprocessors,
9434 do not set the language if it was already deduced by
9436 if (!(cu
->per_cu
->lang
== language_c
9437 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9438 COMPUNIT_FILETABS (cust
)->language
= cu
->per_cu
->lang
;
9443 cu
->get_builder ()->augment_type_symtab ();
9444 cust
= tug_unshare
->compunit_symtab
;
9447 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9449 /* Not needed any more. */
9450 cu
->reset_builder ();
9453 /* Process an imported unit DIE. */
9456 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9458 struct attribute
*attr
;
9460 /* For now we don't handle imported units in type units. */
9461 if (cu
->per_cu
->is_debug_types
)
9463 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9464 " supported in type units [in module %s]"),
9465 objfile_name (cu
->per_objfile
->objfile
));
9468 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9471 sect_offset sect_off
= attr
->get_ref_die_offset ();
9472 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9473 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9474 dwarf2_per_cu_data
*per_cu
9475 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9477 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9478 into another compilation unit, at root level. Regard this as a hint,
9480 if (die
->parent
&& die
->parent
->parent
== NULL
9481 && per_cu
->unit_type
== DW_UT_compile
9482 && per_cu
->lang
== language_cplus
)
9485 /* If necessary, add it to the queue and load its DIEs. */
9486 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
,
9488 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9489 false, cu
->per_cu
->lang
);
9491 cu
->per_cu
->imported_symtabs_push (per_cu
);
9495 /* RAII object that represents a process_die scope: i.e.,
9496 starts/finishes processing a DIE. */
9497 class process_die_scope
9500 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9501 : m_die (die
), m_cu (cu
)
9503 /* We should only be processing DIEs not already in process. */
9504 gdb_assert (!m_die
->in_process
);
9505 m_die
->in_process
= true;
9508 ~process_die_scope ()
9510 m_die
->in_process
= false;
9512 /* If we're done processing the DIE for the CU that owns the line
9513 header, we don't need the line header anymore. */
9514 if (m_cu
->line_header_die_owner
== m_die
)
9516 delete m_cu
->line_header
;
9517 m_cu
->line_header
= NULL
;
9518 m_cu
->line_header_die_owner
= NULL
;
9527 /* Process a die and its children. */
9530 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9532 process_die_scope
scope (die
, cu
);
9536 case DW_TAG_padding
:
9538 case DW_TAG_compile_unit
:
9539 case DW_TAG_partial_unit
:
9540 read_file_scope (die
, cu
);
9542 case DW_TAG_type_unit
:
9543 read_type_unit_scope (die
, cu
);
9545 case DW_TAG_subprogram
:
9546 /* Nested subprograms in Fortran get a prefix. */
9547 if (cu
->per_cu
->lang
== language_fortran
9548 && die
->parent
!= NULL
9549 && die
->parent
->tag
== DW_TAG_subprogram
)
9550 cu
->processing_has_namespace_info
= true;
9552 case DW_TAG_inlined_subroutine
:
9553 read_func_scope (die
, cu
);
9555 case DW_TAG_lexical_block
:
9556 case DW_TAG_try_block
:
9557 case DW_TAG_catch_block
:
9558 read_lexical_block_scope (die
, cu
);
9560 case DW_TAG_call_site
:
9561 case DW_TAG_GNU_call_site
:
9562 read_call_site_scope (die
, cu
);
9564 case DW_TAG_class_type
:
9565 case DW_TAG_interface_type
:
9566 case DW_TAG_structure_type
:
9567 case DW_TAG_union_type
:
9568 process_structure_scope (die
, cu
);
9570 case DW_TAG_enumeration_type
:
9571 process_enumeration_scope (die
, cu
);
9574 /* These dies have a type, but processing them does not create
9575 a symbol or recurse to process the children. Therefore we can
9576 read them on-demand through read_type_die. */
9577 case DW_TAG_subroutine_type
:
9578 case DW_TAG_set_type
:
9579 case DW_TAG_pointer_type
:
9580 case DW_TAG_ptr_to_member_type
:
9581 case DW_TAG_reference_type
:
9582 case DW_TAG_rvalue_reference_type
:
9583 case DW_TAG_string_type
:
9586 case DW_TAG_array_type
:
9587 /* We only need to handle this case for Ada -- in other
9588 languages, it's normal for the compiler to emit a typedef
9590 if (cu
->per_cu
->lang
!= language_ada
)
9593 case DW_TAG_base_type
:
9594 case DW_TAG_subrange_type
:
9595 case DW_TAG_typedef
:
9596 /* Add a typedef symbol for the type definition, if it has a
9598 new_symbol (die
, read_type_die (die
, cu
), cu
);
9600 case DW_TAG_common_block
:
9601 read_common_block (die
, cu
);
9603 case DW_TAG_common_inclusion
:
9605 case DW_TAG_namespace
:
9606 cu
->processing_has_namespace_info
= true;
9607 read_namespace (die
, cu
);
9610 cu
->processing_has_namespace_info
= true;
9611 read_module (die
, cu
);
9613 case DW_TAG_imported_declaration
:
9614 cu
->processing_has_namespace_info
= true;
9615 if (read_namespace_alias (die
, cu
))
9617 /* The declaration is not a global namespace alias. */
9619 case DW_TAG_imported_module
:
9620 cu
->processing_has_namespace_info
= true;
9621 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9622 || cu
->per_cu
->lang
!= language_fortran
))
9623 complaint (_("Tag '%s' has unexpected children"),
9624 dwarf_tag_name (die
->tag
));
9625 read_import_statement (die
, cu
);
9628 case DW_TAG_imported_unit
:
9629 process_imported_unit_die (die
, cu
);
9632 case DW_TAG_variable
:
9633 read_variable (die
, cu
);
9637 new_symbol (die
, NULL
, cu
);
9642 /* DWARF name computation. */
9644 /* A helper function for dwarf2_compute_name which determines whether DIE
9645 needs to have the name of the scope prepended to the name listed in the
9649 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9651 struct attribute
*attr
;
9655 case DW_TAG_namespace
:
9656 case DW_TAG_typedef
:
9657 case DW_TAG_class_type
:
9658 case DW_TAG_interface_type
:
9659 case DW_TAG_structure_type
:
9660 case DW_TAG_union_type
:
9661 case DW_TAG_enumeration_type
:
9662 case DW_TAG_enumerator
:
9663 case DW_TAG_subprogram
:
9664 case DW_TAG_inlined_subroutine
:
9666 case DW_TAG_imported_declaration
:
9669 case DW_TAG_variable
:
9670 case DW_TAG_constant
:
9671 /* We only need to prefix "globally" visible variables. These include
9672 any variable marked with DW_AT_external or any variable that
9673 lives in a namespace. [Variables in anonymous namespaces
9674 require prefixing, but they are not DW_AT_external.] */
9676 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9678 struct dwarf2_cu
*spec_cu
= cu
;
9680 return die_needs_namespace (die_specification (die
, &spec_cu
),
9684 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9685 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9686 && die
->parent
->tag
!= DW_TAG_module
)
9688 /* A variable in a lexical block of some kind does not need a
9689 namespace, even though in C++ such variables may be external
9690 and have a mangled name. */
9691 if (die
->parent
->tag
== DW_TAG_lexical_block
9692 || die
->parent
->tag
== DW_TAG_try_block
9693 || die
->parent
->tag
== DW_TAG_catch_block
9694 || die
->parent
->tag
== DW_TAG_subprogram
)
9703 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9704 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9705 defined for the given DIE. */
9707 static struct attribute
*
9708 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9710 struct attribute
*attr
;
9712 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9714 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9719 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9720 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9721 defined for the given DIE. */
9724 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9726 const char *linkage_name
;
9728 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9729 if (linkage_name
== NULL
)
9730 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9732 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9733 See https://github.com/rust-lang/rust/issues/32925. */
9734 if (cu
->per_cu
->lang
== language_rust
&& linkage_name
!= NULL
9735 && strchr (linkage_name
, '{') != NULL
)
9736 linkage_name
= NULL
;
9738 return linkage_name
;
9741 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9742 compute the physname for the object, which include a method's:
9743 - formal parameters (C++),
9744 - receiver type (Go),
9746 The term "physname" is a bit confusing.
9747 For C++, for example, it is the demangled name.
9748 For Go, for example, it's the mangled name.
9750 For Ada, return the DIE's linkage name rather than the fully qualified
9751 name. PHYSNAME is ignored..
9753 The result is allocated on the objfile->per_bfd's obstack and
9757 dwarf2_compute_name (const char *name
,
9758 struct die_info
*die
, struct dwarf2_cu
*cu
,
9761 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9764 name
= dwarf2_name (die
, cu
);
9766 enum language lang
= cu
->per_cu
->lang
;
9768 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9769 but otherwise compute it by typename_concat inside GDB.
9770 FIXME: Actually this is not really true, or at least not always true.
9771 It's all very confusing. compute_and_set_names doesn't try to demangle
9772 Fortran names because there is no mangling standard. So new_symbol
9773 will set the demangled name to the result of dwarf2_full_name, and it is
9774 the demangled name that GDB uses if it exists. */
9775 if (lang
== language_ada
9776 || (lang
== language_fortran
&& physname
))
9778 /* For Ada unit, we prefer the linkage name over the name, as
9779 the former contains the exported name, which the user expects
9780 to be able to reference. Ideally, we want the user to be able
9781 to reference this entity using either natural or linkage name,
9782 but we haven't started looking at this enhancement yet. */
9783 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9785 if (linkage_name
!= NULL
)
9786 return linkage_name
;
9789 /* These are the only languages we know how to qualify names in. */
9791 && (lang
== language_cplus
9792 || lang
== language_fortran
|| lang
== language_d
9793 || lang
== language_rust
))
9795 if (die_needs_namespace (die
, cu
))
9798 const char *canonical_name
= NULL
;
9802 prefix
= determine_prefix (die
, cu
);
9803 if (*prefix
!= '\0')
9805 gdb::unique_xmalloc_ptr
<char> prefixed_name
9806 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9808 buf
.puts (prefixed_name
.get ());
9813 /* Template parameters may be specified in the DIE's DW_AT_name, or
9814 as children with DW_TAG_template_type_param or
9815 DW_TAG_value_type_param. If the latter, add them to the name
9816 here. If the name already has template parameters, then
9817 skip this step; some versions of GCC emit both, and
9818 it is more efficient to use the pre-computed name.
9820 Something to keep in mind about this process: it is very
9821 unlikely, or in some cases downright impossible, to produce
9822 something that will match the mangled name of a function.
9823 If the definition of the function has the same debug info,
9824 we should be able to match up with it anyway. But fallbacks
9825 using the minimal symbol, for instance to find a method
9826 implemented in a stripped copy of libstdc++, will not work.
9827 If we do not have debug info for the definition, we will have to
9828 match them up some other way.
9830 When we do name matching there is a related problem with function
9831 templates; two instantiated function templates are allowed to
9832 differ only by their return types, which we do not add here. */
9834 if (lang
== language_cplus
&& strchr (name
, '<') == NULL
)
9836 struct attribute
*attr
;
9837 struct die_info
*child
;
9840 die
->building_fullname
= 1;
9842 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
9846 const gdb_byte
*bytes
;
9847 struct dwarf2_locexpr_baton
*baton
;
9850 if (child
->tag
!= DW_TAG_template_type_param
9851 && child
->tag
!= DW_TAG_template_value_param
)
9862 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
9865 complaint (_("template parameter missing DW_AT_type"));
9866 buf
.puts ("UNKNOWN_TYPE");
9869 type
= die_type (child
, cu
);
9871 if (child
->tag
== DW_TAG_template_type_param
)
9873 cu
->language_defn
->print_type (type
, "", &buf
, -1, 0,
9874 &type_print_raw_options
);
9878 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
9881 complaint (_("template parameter missing "
9882 "DW_AT_const_value"));
9883 buf
.puts ("UNKNOWN_VALUE");
9887 dwarf2_const_value_attr (attr
, type
, name
,
9888 &cu
->comp_unit_obstack
, cu
,
9889 &value
, &bytes
, &baton
);
9891 if (type
->has_no_signedness ())
9892 /* GDB prints characters as NUMBER 'CHAR'. If that's
9893 changed, this can use value_print instead. */
9894 cu
->language_defn
->printchar (value
, type
, &buf
);
9897 struct value_print_options opts
;
9900 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
9904 baton
->per_objfile
);
9905 else if (bytes
!= NULL
)
9907 v
= allocate_value (type
);
9908 memcpy (value_contents_writeable (v
), bytes
,
9909 TYPE_LENGTH (type
));
9912 v
= value_from_longest (type
, value
);
9914 /* Specify decimal so that we do not depend on
9916 get_formatted_print_options (&opts
, 'd');
9918 value_print (v
, &buf
, &opts
);
9923 die
->building_fullname
= 0;
9927 /* Close the argument list, with a space if necessary
9928 (nested templates). */
9929 if (!buf
.empty () && buf
.string ().back () == '>')
9936 /* For C++ methods, append formal parameter type
9937 information, if PHYSNAME. */
9939 if (physname
&& die
->tag
== DW_TAG_subprogram
9940 && lang
== language_cplus
)
9942 struct type
*type
= read_type_die (die
, cu
);
9944 c_type_print_args (type
, &buf
, 1, lang
,
9945 &type_print_raw_options
);
9947 if (lang
== language_cplus
)
9949 /* Assume that an artificial first parameter is
9950 "this", but do not crash if it is not. RealView
9951 marks unnamed (and thus unused) parameters as
9952 artificial; there is no way to differentiate
9954 if (type
->num_fields () > 0
9955 && TYPE_FIELD_ARTIFICIAL (type
, 0)
9956 && type
->field (0).type ()->code () == TYPE_CODE_PTR
9957 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
9958 buf
.puts (" const");
9962 const std::string
&intermediate_name
= buf
.string ();
9964 if (lang
== language_cplus
)
9966 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
9969 /* If we only computed INTERMEDIATE_NAME, or if
9970 INTERMEDIATE_NAME is already canonical, then we need to
9972 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
9973 name
= objfile
->intern (intermediate_name
);
9975 name
= canonical_name
;
9982 /* Return the fully qualified name of DIE, based on its DW_AT_name.
9983 If scope qualifiers are appropriate they will be added. The result
9984 will be allocated on the storage_obstack, or NULL if the DIE does
9985 not have a name. NAME may either be from a previous call to
9986 dwarf2_name or NULL.
9988 The output string will be canonicalized (if C++). */
9991 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
9993 return dwarf2_compute_name (name
, die
, cu
, 0);
9996 /* Construct a physname for the given DIE in CU. NAME may either be
9997 from a previous call to dwarf2_name or NULL. The result will be
9998 allocated on the objfile_objstack or NULL if the DIE does not have a
10001 The output string will be canonicalized (if C++). */
10003 static const char *
10004 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10006 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10007 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10010 /* In this case dwarf2_compute_name is just a shortcut not building anything
10012 if (!die_needs_namespace (die
, cu
))
10013 return dwarf2_compute_name (name
, die
, cu
, 1);
10015 if (cu
->per_cu
->lang
!= language_rust
)
10016 mangled
= dw2_linkage_name (die
, cu
);
10018 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10020 gdb::unique_xmalloc_ptr
<char> demangled
;
10021 if (mangled
!= NULL
)
10023 if (cu
->language_defn
->store_sym_names_in_linkage_form_p ())
10025 /* Do nothing (do not demangle the symbol name). */
10029 /* Use DMGL_RET_DROP for C++ template functions to suppress
10030 their return type. It is easier for GDB users to search
10031 for such functions as `name(params)' than `long name(params)'.
10032 In such case the minimal symbol names do not match the full
10033 symbol names but for template functions there is never a need
10034 to look up their definition from their declaration so
10035 the only disadvantage remains the minimal symbol variant
10036 `long name(params)' does not have the proper inferior type. */
10037 demangled
.reset (gdb_demangle (mangled
,
10038 (DMGL_PARAMS
| DMGL_ANSI
10039 | DMGL_RET_DROP
)));
10042 canon
= demangled
.get ();
10050 if (canon
== NULL
|| check_physname
)
10052 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10054 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10056 /* It may not mean a bug in GDB. The compiler could also
10057 compute DW_AT_linkage_name incorrectly. But in such case
10058 GDB would need to be bug-to-bug compatible. */
10060 complaint (_("Computed physname <%s> does not match demangled <%s> "
10061 "(from linkage <%s>) - DIE at %s [in module %s]"),
10062 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10063 objfile_name (objfile
));
10065 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10066 is available here - over computed PHYSNAME. It is safer
10067 against both buggy GDB and buggy compilers. */
10081 retval
= objfile
->intern (retval
);
10086 /* Inspect DIE in CU for a namespace alias. If one exists, record
10087 a new symbol for it.
10089 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10092 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10094 struct attribute
*attr
;
10096 /* If the die does not have a name, this is not a namespace
10098 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10102 struct die_info
*d
= die
;
10103 struct dwarf2_cu
*imported_cu
= cu
;
10105 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10106 keep inspecting DIEs until we hit the underlying import. */
10107 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10108 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10110 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10114 d
= follow_die_ref (d
, attr
, &imported_cu
);
10115 if (d
->tag
!= DW_TAG_imported_declaration
)
10119 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10121 complaint (_("DIE at %s has too many recursively imported "
10122 "declarations"), sect_offset_str (d
->sect_off
));
10129 sect_offset sect_off
= attr
->get_ref_die_offset ();
10131 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10132 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10134 /* This declaration is a global namespace alias. Add
10135 a symbol for it whose type is the aliased namespace. */
10136 new_symbol (die
, type
, cu
);
10145 /* Return the using directives repository (global or local?) to use in the
10146 current context for CU.
10148 For Ada, imported declarations can materialize renamings, which *may* be
10149 global. However it is impossible (for now?) in DWARF to distinguish
10150 "external" imported declarations and "static" ones. As all imported
10151 declarations seem to be static in all other languages, make them all CU-wide
10152 global only in Ada. */
10154 static struct using_direct
**
10155 using_directives (struct dwarf2_cu
*cu
)
10157 if (cu
->per_cu
->lang
== language_ada
10158 && cu
->get_builder ()->outermost_context_p ())
10159 return cu
->get_builder ()->get_global_using_directives ();
10161 return cu
->get_builder ()->get_local_using_directives ();
10164 /* Read the import statement specified by the given die and record it. */
10167 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10169 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10170 struct attribute
*import_attr
;
10171 struct die_info
*imported_die
, *child_die
;
10172 struct dwarf2_cu
*imported_cu
;
10173 const char *imported_name
;
10174 const char *imported_name_prefix
;
10175 const char *canonical_name
;
10176 const char *import_alias
;
10177 const char *imported_declaration
= NULL
;
10178 const char *import_prefix
;
10179 std::vector
<const char *> excludes
;
10181 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10182 if (import_attr
== NULL
)
10184 complaint (_("Tag '%s' has no DW_AT_import"),
10185 dwarf_tag_name (die
->tag
));
10190 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10191 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10192 if (imported_name
== NULL
)
10194 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10196 The import in the following code:
10210 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10211 <52> DW_AT_decl_file : 1
10212 <53> DW_AT_decl_line : 6
10213 <54> DW_AT_import : <0x75>
10214 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10215 <59> DW_AT_name : B
10216 <5b> DW_AT_decl_file : 1
10217 <5c> DW_AT_decl_line : 2
10218 <5d> DW_AT_type : <0x6e>
10220 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10221 <76> DW_AT_byte_size : 4
10222 <77> DW_AT_encoding : 5 (signed)
10224 imports the wrong die ( 0x75 instead of 0x58 ).
10225 This case will be ignored until the gcc bug is fixed. */
10229 /* Figure out the local name after import. */
10230 import_alias
= dwarf2_name (die
, cu
);
10232 /* Figure out where the statement is being imported to. */
10233 import_prefix
= determine_prefix (die
, cu
);
10235 /* Figure out what the scope of the imported die is and prepend it
10236 to the name of the imported die. */
10237 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10239 if (imported_die
->tag
!= DW_TAG_namespace
10240 && imported_die
->tag
!= DW_TAG_module
)
10242 imported_declaration
= imported_name
;
10243 canonical_name
= imported_name_prefix
;
10245 else if (strlen (imported_name_prefix
) > 0)
10246 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10247 imported_name_prefix
,
10248 (cu
->per_cu
->lang
== language_d
10251 imported_name
, (char *) NULL
);
10253 canonical_name
= imported_name
;
10255 if (die
->tag
== DW_TAG_imported_module
10256 && cu
->per_cu
->lang
== language_fortran
)
10257 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10258 child_die
= child_die
->sibling
)
10260 /* DWARF-4: A Fortran use statement with a “rename list” may be
10261 represented by an imported module entry with an import attribute
10262 referring to the module and owned entries corresponding to those
10263 entities that are renamed as part of being imported. */
10265 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10267 complaint (_("child DW_TAG_imported_declaration expected "
10268 "- DIE at %s [in module %s]"),
10269 sect_offset_str (child_die
->sect_off
),
10270 objfile_name (objfile
));
10274 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10275 if (import_attr
== NULL
)
10277 complaint (_("Tag '%s' has no DW_AT_import"),
10278 dwarf_tag_name (child_die
->tag
));
10283 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10285 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10286 if (imported_name
== NULL
)
10288 complaint (_("child DW_TAG_imported_declaration has unknown "
10289 "imported name - DIE at %s [in module %s]"),
10290 sect_offset_str (child_die
->sect_off
),
10291 objfile_name (objfile
));
10295 excludes
.push_back (imported_name
);
10297 process_die (child_die
, cu
);
10300 add_using_directive (using_directives (cu
),
10304 imported_declaration
,
10307 &objfile
->objfile_obstack
);
10310 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10311 types, but gives them a size of zero. Starting with version 14,
10312 ICC is compatible with GCC. */
10315 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10317 if (!cu
->checked_producer
)
10318 check_producer (cu
);
10320 return cu
->producer_is_icc_lt_14
;
10323 /* ICC generates a DW_AT_type for C void functions. This was observed on
10324 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10325 which says that void functions should not have a DW_AT_type. */
10328 producer_is_icc (struct dwarf2_cu
*cu
)
10330 if (!cu
->checked_producer
)
10331 check_producer (cu
);
10333 return cu
->producer_is_icc
;
10336 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10337 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10338 this, it was first present in GCC release 4.3.0. */
10341 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10343 if (!cu
->checked_producer
)
10344 check_producer (cu
);
10346 return cu
->producer_is_gcc_lt_4_3
;
10349 static file_and_directory
10350 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10352 file_and_directory res
;
10354 /* Find the filename. Do not use dwarf2_name here, since the filename
10355 is not a source language identifier. */
10356 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10357 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10359 if (res
.comp_dir
== NULL
10360 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10361 && IS_ABSOLUTE_PATH (res
.name
))
10363 res
.comp_dir_storage
= ldirname (res
.name
);
10364 if (!res
.comp_dir_storage
.empty ())
10365 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10367 if (res
.comp_dir
!= NULL
)
10369 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10370 directory, get rid of it. */
10371 const char *cp
= strchr (res
.comp_dir
, ':');
10373 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10374 res
.comp_dir
= cp
+ 1;
10377 if (res
.name
== NULL
)
10378 res
.name
= "<unknown>";
10383 /* Handle DW_AT_stmt_list for a compilation unit.
10384 DIE is the DW_TAG_compile_unit die for CU.
10385 COMP_DIR is the compilation directory. LOWPC is passed to
10386 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10389 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10390 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10392 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10393 struct attribute
*attr
;
10394 struct line_header line_header_local
;
10395 hashval_t line_header_local_hash
;
10397 int decode_mapping
;
10399 gdb_assert (! cu
->per_cu
->is_debug_types
);
10401 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10402 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10405 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10407 /* The line header hash table is only created if needed (it exists to
10408 prevent redundant reading of the line table for partial_units).
10409 If we're given a partial_unit, we'll need it. If we're given a
10410 compile_unit, then use the line header hash table if it's already
10411 created, but don't create one just yet. */
10413 if (per_objfile
->line_header_hash
== NULL
10414 && die
->tag
== DW_TAG_partial_unit
)
10416 per_objfile
->line_header_hash
10417 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10418 line_header_eq_voidp
,
10419 htab_delete_entry
<line_header
>,
10423 line_header_local
.sect_off
= line_offset
;
10424 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10425 line_header_local_hash
= line_header_hash (&line_header_local
);
10426 if (per_objfile
->line_header_hash
!= NULL
)
10428 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10429 &line_header_local
,
10430 line_header_local_hash
, NO_INSERT
);
10432 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10433 is not present in *SLOT (since if there is something in *SLOT then
10434 it will be for a partial_unit). */
10435 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10437 gdb_assert (*slot
!= NULL
);
10438 cu
->line_header
= (struct line_header
*) *slot
;
10443 /* dwarf_decode_line_header does not yet provide sufficient information.
10444 We always have to call also dwarf_decode_lines for it. */
10445 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10449 cu
->line_header
= lh
.release ();
10450 cu
->line_header_die_owner
= die
;
10452 if (per_objfile
->line_header_hash
== NULL
)
10456 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10457 &line_header_local
,
10458 line_header_local_hash
, INSERT
);
10459 gdb_assert (slot
!= NULL
);
10461 if (slot
!= NULL
&& *slot
== NULL
)
10463 /* This newly decoded line number information unit will be owned
10464 by line_header_hash hash table. */
10465 *slot
= cu
->line_header
;
10466 cu
->line_header_die_owner
= NULL
;
10470 /* We cannot free any current entry in (*slot) as that struct line_header
10471 may be already used by multiple CUs. Create only temporary decoded
10472 line_header for this CU - it may happen at most once for each line
10473 number information unit. And if we're not using line_header_hash
10474 then this is what we want as well. */
10475 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10477 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10478 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10483 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10486 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10488 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10489 struct objfile
*objfile
= per_objfile
->objfile
;
10490 struct gdbarch
*gdbarch
= objfile
->arch ();
10491 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10492 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10493 struct attribute
*attr
;
10494 struct die_info
*child_die
;
10495 CORE_ADDR baseaddr
;
10497 prepare_one_comp_unit (cu
, die
, cu
->per_cu
->lang
);
10498 baseaddr
= objfile
->text_section_offset ();
10500 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10502 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10503 from finish_block. */
10504 if (lowpc
== ((CORE_ADDR
) -1))
10506 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10508 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10510 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10512 gdb_assert (per_objfile
->sym_cu
== nullptr);
10513 scoped_restore restore_sym_cu
10514 = make_scoped_restore (&per_objfile
->sym_cu
, cu
);
10516 /* Decode line number information if present. We do this before
10517 processing child DIEs, so that the line header table is available
10518 for DW_AT_decl_file. */
10519 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10521 /* Process all dies in compilation unit. */
10522 if (die
->child
!= NULL
)
10524 child_die
= die
->child
;
10525 while (child_die
&& child_die
->tag
)
10527 process_die (child_die
, cu
);
10528 child_die
= child_die
->sibling
;
10531 per_objfile
->sym_cu
= nullptr;
10533 /* Decode macro information, if present. Dwarf 2 macro information
10534 refers to information in the line number info statement program
10535 header, so we can only read it if we've read the header
10537 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10539 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10540 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10542 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10543 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10545 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10549 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10550 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10552 unsigned int macro_offset
= attr
->as_unsigned ();
10554 dwarf_decode_macros (cu
, macro_offset
, 0);
10560 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10562 struct type_unit_group
*tu_group
;
10564 struct attribute
*attr
;
10566 struct signatured_type
*sig_type
;
10568 gdb_assert (per_cu
->is_debug_types
);
10569 sig_type
= (struct signatured_type
*) per_cu
;
10571 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10573 /* If we're using .gdb_index (includes -readnow) then
10574 per_cu->type_unit_group may not have been set up yet. */
10575 if (sig_type
->type_unit_group
== NULL
)
10576 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10577 tu_group
= sig_type
->type_unit_group
;
10579 /* If we've already processed this stmt_list there's no real need to
10580 do it again, we could fake it and just recreate the part we need
10581 (file name,index -> symtab mapping). If data shows this optimization
10582 is useful we can do it then. */
10583 type_unit_group_unshareable
*tug_unshare
10584 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10585 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10587 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10590 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10592 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10593 lh
= dwarf_decode_line_header (line_offset
, this);
10598 start_symtab ("", NULL
, 0);
10601 gdb_assert (tug_unshare
->symtabs
== NULL
);
10602 gdb_assert (m_builder
== nullptr);
10603 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10604 m_builder
.reset (new struct buildsym_compunit
10605 (COMPUNIT_OBJFILE (cust
), "",
10606 COMPUNIT_DIRNAME (cust
),
10607 compunit_language (cust
),
10609 list_in_scope
= get_builder ()->get_file_symbols ();
10614 line_header
= lh
.release ();
10615 line_header_die_owner
= die
;
10619 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10621 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10622 still initializing it, and our caller (a few levels up)
10623 process_full_type_unit still needs to know if this is the first
10626 tug_unshare
->symtabs
10627 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10628 struct symtab
*, line_header
->file_names_size ());
10630 auto &file_names
= line_header
->file_names ();
10631 for (i
= 0; i
< file_names
.size (); ++i
)
10633 file_entry
&fe
= file_names
[i
];
10634 dwarf2_start_subfile (this, fe
.name
,
10635 fe
.include_dir (line_header
));
10636 buildsym_compunit
*b
= get_builder ();
10637 if (b
->get_current_subfile ()->symtab
== NULL
)
10639 /* NOTE: start_subfile will recognize when it's been
10640 passed a file it has already seen. So we can't
10641 assume there's a simple mapping from
10642 cu->line_header->file_names to subfiles, plus
10643 cu->line_header->file_names may contain dups. */
10644 b
->get_current_subfile ()->symtab
10645 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10648 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10649 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10654 gdb_assert (m_builder
== nullptr);
10655 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10656 m_builder
.reset (new struct buildsym_compunit
10657 (COMPUNIT_OBJFILE (cust
), "",
10658 COMPUNIT_DIRNAME (cust
),
10659 compunit_language (cust
),
10661 list_in_scope
= get_builder ()->get_file_symbols ();
10663 auto &file_names
= line_header
->file_names ();
10664 for (i
= 0; i
< file_names
.size (); ++i
)
10666 file_entry
&fe
= file_names
[i
];
10667 fe
.symtab
= tug_unshare
->symtabs
[i
];
10671 /* The main symtab is allocated last. Type units don't have DW_AT_name
10672 so they don't have a "real" (so to speak) symtab anyway.
10673 There is later code that will assign the main symtab to all symbols
10674 that don't have one. We need to handle the case of a symbol with a
10675 missing symtab (DW_AT_decl_file) anyway. */
10678 /* Process DW_TAG_type_unit.
10679 For TUs we want to skip the first top level sibling if it's not the
10680 actual type being defined by this TU. In this case the first top
10681 level sibling is there to provide context only. */
10684 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10686 struct die_info
*child_die
;
10688 prepare_one_comp_unit (cu
, die
, language_minimal
);
10690 /* Initialize (or reinitialize) the machinery for building symtabs.
10691 We do this before processing child DIEs, so that the line header table
10692 is available for DW_AT_decl_file. */
10693 cu
->setup_type_unit_groups (die
);
10695 if (die
->child
!= NULL
)
10697 child_die
= die
->child
;
10698 while (child_die
&& child_die
->tag
)
10700 process_die (child_die
, cu
);
10701 child_die
= child_die
->sibling
;
10708 http://gcc.gnu.org/wiki/DebugFission
10709 http://gcc.gnu.org/wiki/DebugFissionDWP
10711 To simplify handling of both DWO files ("object" files with the DWARF info)
10712 and DWP files (a file with the DWOs packaged up into one file), we treat
10713 DWP files as having a collection of virtual DWO files. */
10716 hash_dwo_file (const void *item
)
10718 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10721 hash
= htab_hash_string (dwo_file
->dwo_name
);
10722 if (dwo_file
->comp_dir
!= NULL
)
10723 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10728 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10730 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10731 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10733 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10735 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10736 return lhs
->comp_dir
== rhs
->comp_dir
;
10737 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10740 /* Allocate a hash table for DWO files. */
10743 allocate_dwo_file_hash_table ()
10745 return htab_up (htab_create_alloc (41,
10748 htab_delete_entry
<dwo_file
>,
10752 /* Lookup DWO file DWO_NAME. */
10755 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
10756 const char *dwo_name
,
10757 const char *comp_dir
)
10759 struct dwo_file find_entry
;
10762 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
10763 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
10765 find_entry
.dwo_name
= dwo_name
;
10766 find_entry
.comp_dir
= comp_dir
;
10767 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
10774 hash_dwo_unit (const void *item
)
10776 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10778 /* This drops the top 32 bits of the id, but is ok for a hash. */
10779 return dwo_unit
->signature
;
10783 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10785 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10786 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10788 /* The signature is assumed to be unique within the DWO file.
10789 So while object file CU dwo_id's always have the value zero,
10790 that's OK, assuming each object file DWO file has only one CU,
10791 and that's the rule for now. */
10792 return lhs
->signature
== rhs
->signature
;
10795 /* Allocate a hash table for DWO CUs,TUs.
10796 There is one of these tables for each of CUs,TUs for each DWO file. */
10799 allocate_dwo_unit_table ()
10801 /* Start out with a pretty small number.
10802 Generally DWO files contain only one CU and maybe some TUs. */
10803 return htab_up (htab_create_alloc (3,
10806 NULL
, xcalloc
, xfree
));
10809 /* die_reader_func for create_dwo_cu. */
10812 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10813 const gdb_byte
*info_ptr
,
10814 struct die_info
*comp_unit_die
,
10815 struct dwo_file
*dwo_file
,
10816 struct dwo_unit
*dwo_unit
)
10818 struct dwarf2_cu
*cu
= reader
->cu
;
10819 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10820 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10822 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10823 if (!signature
.has_value ())
10825 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10826 " its dwo_id [in module %s]"),
10827 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
10831 dwo_unit
->dwo_file
= dwo_file
;
10832 dwo_unit
->signature
= *signature
;
10833 dwo_unit
->section
= section
;
10834 dwo_unit
->sect_off
= sect_off
;
10835 dwo_unit
->length
= cu
->per_cu
->length
;
10837 dwarf_read_debug_printf (" offset %s, dwo_id %s",
10838 sect_offset_str (sect_off
),
10839 hex_string (dwo_unit
->signature
));
10842 /* Create the dwo_units for the CUs in a DWO_FILE.
10843 Note: This function processes DWO files only, not DWP files. */
10846 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
10847 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
10848 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
10850 struct objfile
*objfile
= per_objfile
->objfile
;
10851 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
10852 const gdb_byte
*info_ptr
, *end_ptr
;
10854 section
.read (objfile
);
10855 info_ptr
= section
.buffer
;
10857 if (info_ptr
== NULL
)
10860 dwarf_read_debug_printf ("Reading %s for %s:",
10861 section
.get_name (),
10862 section
.get_file_name ());
10864 end_ptr
= info_ptr
+ section
.size
;
10865 while (info_ptr
< end_ptr
)
10867 struct dwarf2_per_cu_data per_cu
;
10868 struct dwo_unit read_unit
{};
10869 struct dwo_unit
*dwo_unit
;
10871 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
10873 per_cu
.per_bfd
= per_bfd
;
10874 per_cu
.is_debug_types
= 0;
10875 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
10876 per_cu
.section
= §ion
;
10878 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
10879 if (!reader
.dummy_p
)
10880 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
10881 &dwo_file
, &read_unit
);
10882 info_ptr
+= per_cu
.length
;
10884 // If the unit could not be parsed, skip it.
10885 if (read_unit
.dwo_file
== NULL
)
10888 if (cus_htab
== NULL
)
10889 cus_htab
= allocate_dwo_unit_table ();
10891 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
10893 *dwo_unit
= read_unit
;
10894 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
10895 gdb_assert (slot
!= NULL
);
10898 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
10899 sect_offset dup_sect_off
= dup_cu
->sect_off
;
10901 complaint (_("debug cu entry at offset %s is duplicate to"
10902 " the entry at offset %s, signature %s"),
10903 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
10904 hex_string (dwo_unit
->signature
));
10906 *slot
= (void *)dwo_unit
;
10910 /* DWP file .debug_{cu,tu}_index section format:
10911 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
10912 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
10914 DWP Versions 1 & 2 are older, pre-standard format versions. The first
10915 officially standard DWP format was published with DWARF v5 and is called
10916 Version 5. There are no versions 3 or 4.
10920 Both index sections have the same format, and serve to map a 64-bit
10921 signature to a set of section numbers. Each section begins with a header,
10922 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
10923 indexes, and a pool of 32-bit section numbers. The index sections will be
10924 aligned at 8-byte boundaries in the file.
10926 The index section header consists of:
10928 V, 32 bit version number
10930 N, 32 bit number of compilation units or type units in the index
10931 M, 32 bit number of slots in the hash table
10933 Numbers are recorded using the byte order of the application binary.
10935 The hash table begins at offset 16 in the section, and consists of an array
10936 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
10937 order of the application binary). Unused slots in the hash table are 0.
10938 (We rely on the extreme unlikeliness of a signature being exactly 0.)
10940 The parallel table begins immediately after the hash table
10941 (at offset 16 + 8 * M from the beginning of the section), and consists of an
10942 array of 32-bit indexes (using the byte order of the application binary),
10943 corresponding 1-1 with slots in the hash table. Each entry in the parallel
10944 table contains a 32-bit index into the pool of section numbers. For unused
10945 hash table slots, the corresponding entry in the parallel table will be 0.
10947 The pool of section numbers begins immediately following the hash table
10948 (at offset 16 + 12 * M from the beginning of the section). The pool of
10949 section numbers consists of an array of 32-bit words (using the byte order
10950 of the application binary). Each item in the array is indexed starting
10951 from 0. The hash table entry provides the index of the first section
10952 number in the set. Additional section numbers in the set follow, and the
10953 set is terminated by a 0 entry (section number 0 is not used in ELF).
10955 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
10956 section must be the first entry in the set, and the .debug_abbrev.dwo must
10957 be the second entry. Other members of the set may follow in any order.
10961 DWP Versions 2 and 5:
10963 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
10964 and the entries in the index tables are now offsets into these sections.
10965 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
10968 Index Section Contents:
10970 Hash Table of Signatures dwp_hash_table.hash_table
10971 Parallel Table of Indices dwp_hash_table.unit_table
10972 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
10973 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
10975 The index section header consists of:
10977 V, 32 bit version number
10978 L, 32 bit number of columns in the table of section offsets
10979 N, 32 bit number of compilation units or type units in the index
10980 M, 32 bit number of slots in the hash table
10982 Numbers are recorded using the byte order of the application binary.
10984 The hash table has the same format as version 1.
10985 The parallel table of indices has the same format as version 1,
10986 except that the entries are origin-1 indices into the table of sections
10987 offsets and the table of section sizes.
10989 The table of offsets begins immediately following the parallel table
10990 (at offset 16 + 12 * M from the beginning of the section). The table is
10991 a two-dimensional array of 32-bit words (using the byte order of the
10992 application binary), with L columns and N+1 rows, in row-major order.
10993 Each row in the array is indexed starting from 0. The first row provides
10994 a key to the remaining rows: each column in this row provides an identifier
10995 for a debug section, and the offsets in the same column of subsequent rows
10996 refer to that section. The section identifiers for Version 2 are:
10998 DW_SECT_INFO 1 .debug_info.dwo
10999 DW_SECT_TYPES 2 .debug_types.dwo
11000 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11001 DW_SECT_LINE 4 .debug_line.dwo
11002 DW_SECT_LOC 5 .debug_loc.dwo
11003 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11004 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11005 DW_SECT_MACRO 8 .debug_macro.dwo
11007 The section identifiers for Version 5 are:
11009 DW_SECT_INFO_V5 1 .debug_info.dwo
11010 DW_SECT_RESERVED_V5 2 --
11011 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11012 DW_SECT_LINE_V5 4 .debug_line.dwo
11013 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11014 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11015 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11016 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11018 The offsets provided by the CU and TU index sections are the base offsets
11019 for the contributions made by each CU or TU to the corresponding section
11020 in the package file. Each CU and TU header contains an abbrev_offset
11021 field, used to find the abbreviations table for that CU or TU within the
11022 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11023 be interpreted as relative to the base offset given in the index section.
11024 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11025 should be interpreted as relative to the base offset for .debug_line.dwo,
11026 and offsets into other debug sections obtained from DWARF attributes should
11027 also be interpreted as relative to the corresponding base offset.
11029 The table of sizes begins immediately following the table of offsets.
11030 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11031 with L columns and N rows, in row-major order. Each row in the array is
11032 indexed starting from 1 (row 0 is shared by the two tables).
11036 Hash table lookup is handled the same in version 1 and 2:
11038 We assume that N and M will not exceed 2^32 - 1.
11039 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11041 Given a 64-bit compilation unit signature or a type signature S, an entry
11042 in the hash table is located as follows:
11044 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11045 the low-order k bits all set to 1.
11047 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11049 3) If the hash table entry at index H matches the signature, use that
11050 entry. If the hash table entry at index H is unused (all zeroes),
11051 terminate the search: the signature is not present in the table.
11053 4) Let H = (H + H') modulo M. Repeat at Step 3.
11055 Because M > N and H' and M are relatively prime, the search is guaranteed
11056 to stop at an unused slot or find the match. */
11058 /* Create a hash table to map DWO IDs to their CU/TU entry in
11059 .debug_{info,types}.dwo in DWP_FILE.
11060 Returns NULL if there isn't one.
11061 Note: This function processes DWP files only, not DWO files. */
11063 static struct dwp_hash_table
*
11064 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11065 struct dwp_file
*dwp_file
, int is_debug_types
)
11067 struct objfile
*objfile
= per_objfile
->objfile
;
11068 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11069 const gdb_byte
*index_ptr
, *index_end
;
11070 struct dwarf2_section_info
*index
;
11071 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11072 struct dwp_hash_table
*htab
;
11074 if (is_debug_types
)
11075 index
= &dwp_file
->sections
.tu_index
;
11077 index
= &dwp_file
->sections
.cu_index
;
11079 if (index
->empty ())
11081 index
->read (objfile
);
11083 index_ptr
= index
->buffer
;
11084 index_end
= index_ptr
+ index
->size
;
11086 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11087 For now it's safe to just read 4 bytes (particularly as it's difficult to
11088 tell if you're dealing with Version 5 before you've read the version). */
11089 version
= read_4_bytes (dbfd
, index_ptr
);
11091 if (version
== 2 || version
== 5)
11092 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11096 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11098 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11101 if (version
!= 1 && version
!= 2 && version
!= 5)
11103 error (_("Dwarf Error: unsupported DWP file version (%s)"
11104 " [in module %s]"),
11105 pulongest (version
), dwp_file
->name
);
11107 if (nr_slots
!= (nr_slots
& -nr_slots
))
11109 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11110 " is not power of 2 [in module %s]"),
11111 pulongest (nr_slots
), dwp_file
->name
);
11114 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11115 htab
->version
= version
;
11116 htab
->nr_columns
= nr_columns
;
11117 htab
->nr_units
= nr_units
;
11118 htab
->nr_slots
= nr_slots
;
11119 htab
->hash_table
= index_ptr
;
11120 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11122 /* Exit early if the table is empty. */
11123 if (nr_slots
== 0 || nr_units
== 0
11124 || (version
== 2 && nr_columns
== 0)
11125 || (version
== 5 && nr_columns
== 0))
11127 /* All must be zero. */
11128 if (nr_slots
!= 0 || nr_units
!= 0
11129 || (version
== 2 && nr_columns
!= 0)
11130 || (version
== 5 && nr_columns
!= 0))
11132 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11133 " all zero [in modules %s]"),
11141 htab
->section_pool
.v1
.indices
=
11142 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11143 /* It's harder to decide whether the section is too small in v1.
11144 V1 is deprecated anyway so we punt. */
11146 else if (version
== 2)
11148 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11149 int *ids
= htab
->section_pool
.v2
.section_ids
;
11150 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11151 /* Reverse map for error checking. */
11152 int ids_seen
[DW_SECT_MAX
+ 1];
11155 if (nr_columns
< 2)
11157 error (_("Dwarf Error: bad DWP hash table, too few columns"
11158 " in section table [in module %s]"),
11161 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11163 error (_("Dwarf Error: bad DWP hash table, too many columns"
11164 " in section table [in module %s]"),
11167 memset (ids
, 255, sizeof_ids
);
11168 memset (ids_seen
, 255, sizeof (ids_seen
));
11169 for (i
= 0; i
< nr_columns
; ++i
)
11171 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11173 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11175 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11176 " in section table [in module %s]"),
11177 id
, dwp_file
->name
);
11179 if (ids_seen
[id
] != -1)
11181 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11182 " id %d in section table [in module %s]"),
11183 id
, dwp_file
->name
);
11188 /* Must have exactly one info or types section. */
11189 if (((ids_seen
[DW_SECT_INFO
] != -1)
11190 + (ids_seen
[DW_SECT_TYPES
] != -1))
11193 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11194 " DWO info/types section [in module %s]"),
11197 /* Must have an abbrev section. */
11198 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11200 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11201 " section [in module %s]"),
11204 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11205 htab
->section_pool
.v2
.sizes
=
11206 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11207 * nr_units
* nr_columns
);
11208 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11209 * nr_units
* nr_columns
))
11212 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11213 " [in module %s]"),
11217 else /* version == 5 */
11219 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11220 int *ids
= htab
->section_pool
.v5
.section_ids
;
11221 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11222 /* Reverse map for error checking. */
11223 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11225 if (nr_columns
< 2)
11227 error (_("Dwarf Error: bad DWP hash table, too few columns"
11228 " in section table [in module %s]"),
11231 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11233 error (_("Dwarf Error: bad DWP hash table, too many columns"
11234 " in section table [in module %s]"),
11237 memset (ids
, 255, sizeof_ids
);
11238 memset (ids_seen
, 255, sizeof (ids_seen
));
11239 for (int i
= 0; i
< nr_columns
; ++i
)
11241 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11243 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11245 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11246 " in section table [in module %s]"),
11247 id
, dwp_file
->name
);
11249 if (ids_seen
[id
] != -1)
11251 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11252 " id %d in section table [in module %s]"),
11253 id
, dwp_file
->name
);
11258 /* Must have seen an info section. */
11259 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11261 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11262 " DWO info/types section [in module %s]"),
11265 /* Must have an abbrev section. */
11266 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11268 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11269 " section [in module %s]"),
11272 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11273 htab
->section_pool
.v5
.sizes
11274 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11275 * nr_units
* nr_columns
);
11276 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11277 * nr_units
* nr_columns
))
11280 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11281 " [in module %s]"),
11289 /* Update SECTIONS with the data from SECTP.
11291 This function is like the other "locate" section routines, but in
11292 this context the sections to read comes from the DWP V1 hash table,
11293 not the full ELF section table.
11295 The result is non-zero for success, or zero if an error was found. */
11298 locate_v1_virtual_dwo_sections (asection
*sectp
,
11299 struct virtual_v1_dwo_sections
*sections
)
11301 const struct dwop_section_names
*names
= &dwop_section_names
;
11303 if (names
->abbrev_dwo
.matches (sectp
->name
))
11305 /* There can be only one. */
11306 if (sections
->abbrev
.s
.section
!= NULL
)
11308 sections
->abbrev
.s
.section
= sectp
;
11309 sections
->abbrev
.size
= bfd_section_size (sectp
);
11311 else if (names
->info_dwo
.matches (sectp
->name
)
11312 || names
->types_dwo
.matches (sectp
->name
))
11314 /* There can be only one. */
11315 if (sections
->info_or_types
.s
.section
!= NULL
)
11317 sections
->info_or_types
.s
.section
= sectp
;
11318 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11320 else if (names
->line_dwo
.matches (sectp
->name
))
11322 /* There can be only one. */
11323 if (sections
->line
.s
.section
!= NULL
)
11325 sections
->line
.s
.section
= sectp
;
11326 sections
->line
.size
= bfd_section_size (sectp
);
11328 else if (names
->loc_dwo
.matches (sectp
->name
))
11330 /* There can be only one. */
11331 if (sections
->loc
.s
.section
!= NULL
)
11333 sections
->loc
.s
.section
= sectp
;
11334 sections
->loc
.size
= bfd_section_size (sectp
);
11336 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11338 /* There can be only one. */
11339 if (sections
->macinfo
.s
.section
!= NULL
)
11341 sections
->macinfo
.s
.section
= sectp
;
11342 sections
->macinfo
.size
= bfd_section_size (sectp
);
11344 else if (names
->macro_dwo
.matches (sectp
->name
))
11346 /* There can be only one. */
11347 if (sections
->macro
.s
.section
!= NULL
)
11349 sections
->macro
.s
.section
= sectp
;
11350 sections
->macro
.size
= bfd_section_size (sectp
);
11352 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11354 /* There can be only one. */
11355 if (sections
->str_offsets
.s
.section
!= NULL
)
11357 sections
->str_offsets
.s
.section
= sectp
;
11358 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11362 /* No other kind of section is valid. */
11369 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11370 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11371 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11372 This is for DWP version 1 files. */
11374 static struct dwo_unit
*
11375 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11376 struct dwp_file
*dwp_file
,
11377 uint32_t unit_index
,
11378 const char *comp_dir
,
11379 ULONGEST signature
, int is_debug_types
)
11381 const struct dwp_hash_table
*dwp_htab
=
11382 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11383 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11384 const char *kind
= is_debug_types
? "TU" : "CU";
11385 struct dwo_file
*dwo_file
;
11386 struct dwo_unit
*dwo_unit
;
11387 struct virtual_v1_dwo_sections sections
;
11388 void **dwo_file_slot
;
11391 gdb_assert (dwp_file
->version
== 1);
11393 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11394 kind
, pulongest (unit_index
), hex_string (signature
),
11397 /* Fetch the sections of this DWO unit.
11398 Put a limit on the number of sections we look for so that bad data
11399 doesn't cause us to loop forever. */
11401 #define MAX_NR_V1_DWO_SECTIONS \
11402 (1 /* .debug_info or .debug_types */ \
11403 + 1 /* .debug_abbrev */ \
11404 + 1 /* .debug_line */ \
11405 + 1 /* .debug_loc */ \
11406 + 1 /* .debug_str_offsets */ \
11407 + 1 /* .debug_macro or .debug_macinfo */ \
11408 + 1 /* trailing zero */)
11410 memset (§ions
, 0, sizeof (sections
));
11412 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11415 uint32_t section_nr
=
11416 read_4_bytes (dbfd
,
11417 dwp_htab
->section_pool
.v1
.indices
11418 + (unit_index
+ i
) * sizeof (uint32_t));
11420 if (section_nr
== 0)
11422 if (section_nr
>= dwp_file
->num_sections
)
11424 error (_("Dwarf Error: bad DWP hash table, section number too large"
11425 " [in module %s]"),
11429 sectp
= dwp_file
->elf_sections
[section_nr
];
11430 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11432 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11433 " [in module %s]"),
11439 || sections
.info_or_types
.empty ()
11440 || sections
.abbrev
.empty ())
11442 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11443 " [in module %s]"),
11446 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11448 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11449 " [in module %s]"),
11453 /* It's easier for the rest of the code if we fake a struct dwo_file and
11454 have dwo_unit "live" in that. At least for now.
11456 The DWP file can be made up of a random collection of CUs and TUs.
11457 However, for each CU + set of TUs that came from the same original DWO
11458 file, we can combine them back into a virtual DWO file to save space
11459 (fewer struct dwo_file objects to allocate). Remember that for really
11460 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11462 std::string virtual_dwo_name
=
11463 string_printf ("virtual-dwo/%d-%d-%d-%d",
11464 sections
.abbrev
.get_id (),
11465 sections
.line
.get_id (),
11466 sections
.loc
.get_id (),
11467 sections
.str_offsets
.get_id ());
11468 /* Can we use an existing virtual DWO file? */
11469 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11471 /* Create one if necessary. */
11472 if (*dwo_file_slot
== NULL
)
11474 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11475 virtual_dwo_name
.c_str ());
11477 dwo_file
= new struct dwo_file
;
11478 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11479 dwo_file
->comp_dir
= comp_dir
;
11480 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11481 dwo_file
->sections
.line
= sections
.line
;
11482 dwo_file
->sections
.loc
= sections
.loc
;
11483 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11484 dwo_file
->sections
.macro
= sections
.macro
;
11485 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11486 /* The "str" section is global to the entire DWP file. */
11487 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11488 /* The info or types section is assigned below to dwo_unit,
11489 there's no need to record it in dwo_file.
11490 Also, we can't simply record type sections in dwo_file because
11491 we record a pointer into the vector in dwo_unit. As we collect more
11492 types we'll grow the vector and eventually have to reallocate space
11493 for it, invalidating all copies of pointers into the previous
11495 *dwo_file_slot
= dwo_file
;
11499 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11500 virtual_dwo_name
.c_str ());
11502 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11505 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11506 dwo_unit
->dwo_file
= dwo_file
;
11507 dwo_unit
->signature
= signature
;
11508 dwo_unit
->section
=
11509 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11510 *dwo_unit
->section
= sections
.info_or_types
;
11511 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11516 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11517 simplify them. Given a pointer to the containing section SECTION, and
11518 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11519 virtual section of just that piece. */
11521 static struct dwarf2_section_info
11522 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11523 struct dwarf2_section_info
*section
,
11524 bfd_size_type offset
, bfd_size_type size
)
11526 struct dwarf2_section_info result
;
11529 gdb_assert (section
!= NULL
);
11530 gdb_assert (!section
->is_virtual
);
11532 memset (&result
, 0, sizeof (result
));
11533 result
.s
.containing_section
= section
;
11534 result
.is_virtual
= true;
11539 sectp
= section
->get_bfd_section ();
11541 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11542 bounds of the real section. This is a pretty-rare event, so just
11543 flag an error (easier) instead of a warning and trying to cope. */
11545 || offset
+ size
> bfd_section_size (sectp
))
11547 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11548 " in section %s [in module %s]"),
11549 sectp
? bfd_section_name (sectp
) : "<unknown>",
11550 objfile_name (per_objfile
->objfile
));
11553 result
.virtual_offset
= offset
;
11554 result
.size
= size
;
11558 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11559 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11560 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11561 This is for DWP version 2 files. */
11563 static struct dwo_unit
*
11564 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11565 struct dwp_file
*dwp_file
,
11566 uint32_t unit_index
,
11567 const char *comp_dir
,
11568 ULONGEST signature
, int is_debug_types
)
11570 const struct dwp_hash_table
*dwp_htab
=
11571 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11572 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11573 const char *kind
= is_debug_types
? "TU" : "CU";
11574 struct dwo_file
*dwo_file
;
11575 struct dwo_unit
*dwo_unit
;
11576 struct virtual_v2_or_v5_dwo_sections sections
;
11577 void **dwo_file_slot
;
11580 gdb_assert (dwp_file
->version
== 2);
11582 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11583 kind
, pulongest (unit_index
), hex_string (signature
),
11586 /* Fetch the section offsets of this DWO unit. */
11588 memset (§ions
, 0, sizeof (sections
));
11590 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11592 uint32_t offset
= read_4_bytes (dbfd
,
11593 dwp_htab
->section_pool
.v2
.offsets
11594 + (((unit_index
- 1) * dwp_htab
->nr_columns
11596 * sizeof (uint32_t)));
11597 uint32_t size
= read_4_bytes (dbfd
,
11598 dwp_htab
->section_pool
.v2
.sizes
11599 + (((unit_index
- 1) * dwp_htab
->nr_columns
11601 * sizeof (uint32_t)));
11603 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11606 case DW_SECT_TYPES
:
11607 sections
.info_or_types_offset
= offset
;
11608 sections
.info_or_types_size
= size
;
11610 case DW_SECT_ABBREV
:
11611 sections
.abbrev_offset
= offset
;
11612 sections
.abbrev_size
= size
;
11615 sections
.line_offset
= offset
;
11616 sections
.line_size
= size
;
11619 sections
.loc_offset
= offset
;
11620 sections
.loc_size
= size
;
11622 case DW_SECT_STR_OFFSETS
:
11623 sections
.str_offsets_offset
= offset
;
11624 sections
.str_offsets_size
= size
;
11626 case DW_SECT_MACINFO
:
11627 sections
.macinfo_offset
= offset
;
11628 sections
.macinfo_size
= size
;
11630 case DW_SECT_MACRO
:
11631 sections
.macro_offset
= offset
;
11632 sections
.macro_size
= size
;
11637 /* It's easier for the rest of the code if we fake a struct dwo_file and
11638 have dwo_unit "live" in that. At least for now.
11640 The DWP file can be made up of a random collection of CUs and TUs.
11641 However, for each CU + set of TUs that came from the same original DWO
11642 file, we can combine them back into a virtual DWO file to save space
11643 (fewer struct dwo_file objects to allocate). Remember that for really
11644 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11646 std::string virtual_dwo_name
=
11647 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11648 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11649 (long) (sections
.line_size
? sections
.line_offset
: 0),
11650 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11651 (long) (sections
.str_offsets_size
11652 ? sections
.str_offsets_offset
: 0));
11653 /* Can we use an existing virtual DWO file? */
11654 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11656 /* Create one if necessary. */
11657 if (*dwo_file_slot
== NULL
)
11659 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11660 virtual_dwo_name
.c_str ());
11662 dwo_file
= new struct dwo_file
;
11663 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11664 dwo_file
->comp_dir
= comp_dir
;
11665 dwo_file
->sections
.abbrev
=
11666 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11667 sections
.abbrev_offset
,
11668 sections
.abbrev_size
);
11669 dwo_file
->sections
.line
=
11670 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11671 sections
.line_offset
,
11672 sections
.line_size
);
11673 dwo_file
->sections
.loc
=
11674 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11675 sections
.loc_offset
, sections
.loc_size
);
11676 dwo_file
->sections
.macinfo
=
11677 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11678 sections
.macinfo_offset
,
11679 sections
.macinfo_size
);
11680 dwo_file
->sections
.macro
=
11681 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11682 sections
.macro_offset
,
11683 sections
.macro_size
);
11684 dwo_file
->sections
.str_offsets
=
11685 create_dwp_v2_or_v5_section (per_objfile
,
11686 &dwp_file
->sections
.str_offsets
,
11687 sections
.str_offsets_offset
,
11688 sections
.str_offsets_size
);
11689 /* The "str" section is global to the entire DWP file. */
11690 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11691 /* The info or types section is assigned below to dwo_unit,
11692 there's no need to record it in dwo_file.
11693 Also, we can't simply record type sections in dwo_file because
11694 we record a pointer into the vector in dwo_unit. As we collect more
11695 types we'll grow the vector and eventually have to reallocate space
11696 for it, invalidating all copies of pointers into the previous
11698 *dwo_file_slot
= dwo_file
;
11702 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11703 virtual_dwo_name
.c_str ());
11705 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11708 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11709 dwo_unit
->dwo_file
= dwo_file
;
11710 dwo_unit
->signature
= signature
;
11711 dwo_unit
->section
=
11712 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11713 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11716 ? &dwp_file
->sections
.types
11717 : &dwp_file
->sections
.info
,
11718 sections
.info_or_types_offset
,
11719 sections
.info_or_types_size
);
11720 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11725 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11726 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11727 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11728 This is for DWP version 5 files. */
11730 static struct dwo_unit
*
11731 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11732 struct dwp_file
*dwp_file
,
11733 uint32_t unit_index
,
11734 const char *comp_dir
,
11735 ULONGEST signature
, int is_debug_types
)
11737 const struct dwp_hash_table
*dwp_htab
11738 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11739 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11740 const char *kind
= is_debug_types
? "TU" : "CU";
11741 struct dwo_file
*dwo_file
;
11742 struct dwo_unit
*dwo_unit
;
11743 struct virtual_v2_or_v5_dwo_sections sections
{};
11744 void **dwo_file_slot
;
11746 gdb_assert (dwp_file
->version
== 5);
11748 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
11749 kind
, pulongest (unit_index
), hex_string (signature
),
11752 /* Fetch the section offsets of this DWO unit. */
11754 /* memset (§ions, 0, sizeof (sections)); */
11756 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11758 uint32_t offset
= read_4_bytes (dbfd
,
11759 dwp_htab
->section_pool
.v5
.offsets
11760 + (((unit_index
- 1)
11761 * dwp_htab
->nr_columns
11763 * sizeof (uint32_t)));
11764 uint32_t size
= read_4_bytes (dbfd
,
11765 dwp_htab
->section_pool
.v5
.sizes
11766 + (((unit_index
- 1) * dwp_htab
->nr_columns
11768 * sizeof (uint32_t)));
11770 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
11772 case DW_SECT_ABBREV_V5
:
11773 sections
.abbrev_offset
= offset
;
11774 sections
.abbrev_size
= size
;
11776 case DW_SECT_INFO_V5
:
11777 sections
.info_or_types_offset
= offset
;
11778 sections
.info_or_types_size
= size
;
11780 case DW_SECT_LINE_V5
:
11781 sections
.line_offset
= offset
;
11782 sections
.line_size
= size
;
11784 case DW_SECT_LOCLISTS_V5
:
11785 sections
.loclists_offset
= offset
;
11786 sections
.loclists_size
= size
;
11788 case DW_SECT_MACRO_V5
:
11789 sections
.macro_offset
= offset
;
11790 sections
.macro_size
= size
;
11792 case DW_SECT_RNGLISTS_V5
:
11793 sections
.rnglists_offset
= offset
;
11794 sections
.rnglists_size
= size
;
11796 case DW_SECT_STR_OFFSETS_V5
:
11797 sections
.str_offsets_offset
= offset
;
11798 sections
.str_offsets_size
= size
;
11800 case DW_SECT_RESERVED_V5
:
11806 /* It's easier for the rest of the code if we fake a struct dwo_file and
11807 have dwo_unit "live" in that. At least for now.
11809 The DWP file can be made up of a random collection of CUs and TUs.
11810 However, for each CU + set of TUs that came from the same original DWO
11811 file, we can combine them back into a virtual DWO file to save space
11812 (fewer struct dwo_file objects to allocate). Remember that for really
11813 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11815 std::string virtual_dwo_name
=
11816 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
11817 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11818 (long) (sections
.line_size
? sections
.line_offset
: 0),
11819 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
11820 (long) (sections
.str_offsets_size
11821 ? sections
.str_offsets_offset
: 0),
11822 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
11823 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
11824 /* Can we use an existing virtual DWO file? */
11825 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
11826 virtual_dwo_name
.c_str (),
11828 /* Create one if necessary. */
11829 if (*dwo_file_slot
== NULL
)
11831 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11832 virtual_dwo_name
.c_str ());
11834 dwo_file
= new struct dwo_file
;
11835 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11836 dwo_file
->comp_dir
= comp_dir
;
11837 dwo_file
->sections
.abbrev
=
11838 create_dwp_v2_or_v5_section (per_objfile
,
11839 &dwp_file
->sections
.abbrev
,
11840 sections
.abbrev_offset
,
11841 sections
.abbrev_size
);
11842 dwo_file
->sections
.line
=
11843 create_dwp_v2_or_v5_section (per_objfile
,
11844 &dwp_file
->sections
.line
,
11845 sections
.line_offset
, sections
.line_size
);
11846 dwo_file
->sections
.macro
=
11847 create_dwp_v2_or_v5_section (per_objfile
,
11848 &dwp_file
->sections
.macro
,
11849 sections
.macro_offset
,
11850 sections
.macro_size
);
11851 dwo_file
->sections
.loclists
=
11852 create_dwp_v2_or_v5_section (per_objfile
,
11853 &dwp_file
->sections
.loclists
,
11854 sections
.loclists_offset
,
11855 sections
.loclists_size
);
11856 dwo_file
->sections
.rnglists
=
11857 create_dwp_v2_or_v5_section (per_objfile
,
11858 &dwp_file
->sections
.rnglists
,
11859 sections
.rnglists_offset
,
11860 sections
.rnglists_size
);
11861 dwo_file
->sections
.str_offsets
=
11862 create_dwp_v2_or_v5_section (per_objfile
,
11863 &dwp_file
->sections
.str_offsets
,
11864 sections
.str_offsets_offset
,
11865 sections
.str_offsets_size
);
11866 /* The "str" section is global to the entire DWP file. */
11867 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11868 /* The info or types section is assigned below to dwo_unit,
11869 there's no need to record it in dwo_file.
11870 Also, we can't simply record type sections in dwo_file because
11871 we record a pointer into the vector in dwo_unit. As we collect more
11872 types we'll grow the vector and eventually have to reallocate space
11873 for it, invalidating all copies of pointers into the previous
11875 *dwo_file_slot
= dwo_file
;
11879 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11880 virtual_dwo_name
.c_str ());
11882 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11885 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11886 dwo_unit
->dwo_file
= dwo_file
;
11887 dwo_unit
->signature
= signature
;
11889 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11890 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
11891 &dwp_file
->sections
.info
,
11892 sections
.info_or_types_offset
,
11893 sections
.info_or_types_size
);
11894 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11899 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11900 Returns NULL if the signature isn't found. */
11902 static struct dwo_unit
*
11903 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
11904 struct dwp_file
*dwp_file
, const char *comp_dir
,
11905 ULONGEST signature
, int is_debug_types
)
11907 const struct dwp_hash_table
*dwp_htab
=
11908 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11909 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11910 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11911 uint32_t hash
= signature
& mask
;
11912 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11915 struct dwo_unit find_dwo_cu
;
11917 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11918 find_dwo_cu
.signature
= signature
;
11919 slot
= htab_find_slot (is_debug_types
11920 ? dwp_file
->loaded_tus
.get ()
11921 : dwp_file
->loaded_cus
.get (),
11922 &find_dwo_cu
, INSERT
);
11925 return (struct dwo_unit
*) *slot
;
11927 /* Use a for loop so that we don't loop forever on bad debug info. */
11928 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11930 ULONGEST signature_in_table
;
11932 signature_in_table
=
11933 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11934 if (signature_in_table
== signature
)
11936 uint32_t unit_index
=
11937 read_4_bytes (dbfd
,
11938 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11940 if (dwp_file
->version
== 1)
11942 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
11943 unit_index
, comp_dir
,
11944 signature
, is_debug_types
);
11946 else if (dwp_file
->version
== 2)
11948 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
11949 unit_index
, comp_dir
,
11950 signature
, is_debug_types
);
11952 else /* version == 5 */
11954 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
11955 unit_index
, comp_dir
,
11956 signature
, is_debug_types
);
11958 return (struct dwo_unit
*) *slot
;
11960 if (signature_in_table
== 0)
11962 hash
= (hash
+ hash2
) & mask
;
11965 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11966 " [in module %s]"),
11970 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11971 Open the file specified by FILE_NAME and hand it off to BFD for
11972 preliminary analysis. Return a newly initialized bfd *, which
11973 includes a canonicalized copy of FILE_NAME.
11974 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11975 SEARCH_CWD is true if the current directory is to be searched.
11976 It will be searched before debug-file-directory.
11977 If successful, the file is added to the bfd include table of the
11978 objfile's bfd (see gdb_bfd_record_inclusion).
11979 If unable to find/open the file, return NULL.
11980 NOTE: This function is derived from symfile_bfd_open. */
11982 static gdb_bfd_ref_ptr
11983 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
11984 const char *file_name
, int is_dwp
, int search_cwd
)
11987 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11988 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11989 to debug_file_directory. */
11990 const char *search_path
;
11991 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11993 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11996 if (*debug_file_directory
!= '\0')
11998 search_path_holder
.reset (concat (".", dirname_separator_string
,
11999 debug_file_directory
,
12001 search_path
= search_path_holder
.get ();
12007 search_path
= debug_file_directory
;
12009 /* Add the path for the executable binary to the list of search paths. */
12010 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12011 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12012 dirname_separator_string
,
12013 search_path
, nullptr));
12014 search_path
= search_path_holder
.get ();
12016 openp_flags flags
= OPF_RETURN_REALPATH
;
12018 flags
|= OPF_SEARCH_IN_PATH
;
12020 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12021 desc
= openp (search_path
, flags
, file_name
,
12022 O_RDONLY
| O_BINARY
, &absolute_name
);
12026 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12028 if (sym_bfd
== NULL
)
12030 bfd_set_cacheable (sym_bfd
.get (), 1);
12032 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12035 /* Success. Record the bfd as having been included by the objfile's bfd.
12036 This is important because things like demangled_names_hash lives in the
12037 objfile's per_bfd space and may have references to things like symbol
12038 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12039 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12044 /* Try to open DWO file FILE_NAME.
12045 COMP_DIR is the DW_AT_comp_dir attribute.
12046 The result is the bfd handle of the file.
12047 If there is a problem finding or opening the file, return NULL.
12048 Upon success, the canonicalized path of the file is stored in the bfd,
12049 same as symfile_bfd_open. */
12051 static gdb_bfd_ref_ptr
12052 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12053 const char *file_name
, const char *comp_dir
)
12055 if (IS_ABSOLUTE_PATH (file_name
))
12056 return try_open_dwop_file (per_objfile
, file_name
,
12057 0 /*is_dwp*/, 0 /*search_cwd*/);
12059 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12061 if (comp_dir
!= NULL
)
12063 gdb::unique_xmalloc_ptr
<char> path_to_try
12064 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12066 /* NOTE: If comp_dir is a relative path, this will also try the
12067 search path, which seems useful. */
12068 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12070 1 /*search_cwd*/));
12075 /* That didn't work, try debug-file-directory, which, despite its name,
12076 is a list of paths. */
12078 if (*debug_file_directory
== '\0')
12081 return try_open_dwop_file (per_objfile
, file_name
,
12082 0 /*is_dwp*/, 1 /*search_cwd*/);
12085 /* This function is mapped across the sections and remembers the offset and
12086 size of each of the DWO debugging sections we are interested in. */
12089 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12090 dwo_sections
*dwo_sections
)
12092 const struct dwop_section_names
*names
= &dwop_section_names
;
12094 if (names
->abbrev_dwo
.matches (sectp
->name
))
12096 dwo_sections
->abbrev
.s
.section
= sectp
;
12097 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12099 else if (names
->info_dwo
.matches (sectp
->name
))
12101 dwo_sections
->info
.s
.section
= sectp
;
12102 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12104 else if (names
->line_dwo
.matches (sectp
->name
))
12106 dwo_sections
->line
.s
.section
= sectp
;
12107 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12109 else if (names
->loc_dwo
.matches (sectp
->name
))
12111 dwo_sections
->loc
.s
.section
= sectp
;
12112 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12114 else if (names
->loclists_dwo
.matches (sectp
->name
))
12116 dwo_sections
->loclists
.s
.section
= sectp
;
12117 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12119 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12121 dwo_sections
->macinfo
.s
.section
= sectp
;
12122 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12124 else if (names
->macro_dwo
.matches (sectp
->name
))
12126 dwo_sections
->macro
.s
.section
= sectp
;
12127 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12129 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12131 dwo_sections
->rnglists
.s
.section
= sectp
;
12132 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12134 else if (names
->str_dwo
.matches (sectp
->name
))
12136 dwo_sections
->str
.s
.section
= sectp
;
12137 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12139 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12141 dwo_sections
->str_offsets
.s
.section
= sectp
;
12142 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12144 else if (names
->types_dwo
.matches (sectp
->name
))
12146 struct dwarf2_section_info type_section
;
12148 memset (&type_section
, 0, sizeof (type_section
));
12149 type_section
.s
.section
= sectp
;
12150 type_section
.size
= bfd_section_size (sectp
);
12151 dwo_sections
->types
.push_back (type_section
);
12155 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12156 by PER_CU. This is for the non-DWP case.
12157 The result is NULL if DWO_NAME can't be found. */
12159 static struct dwo_file
*
12160 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12161 const char *comp_dir
)
12163 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12165 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12168 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12173 dwo_file_up
dwo_file (new struct dwo_file
);
12174 dwo_file
->dwo_name
= dwo_name
;
12175 dwo_file
->comp_dir
= comp_dir
;
12176 dwo_file
->dbfd
= std::move (dbfd
);
12178 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12179 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12180 &dwo_file
->sections
);
12182 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12185 if (cu
->per_cu
->dwarf_version
< 5)
12187 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12188 dwo_file
->sections
.types
, dwo_file
->tus
);
12192 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12193 &dwo_file
->sections
.info
, dwo_file
->tus
,
12194 rcuh_kind::COMPILE
);
12197 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12199 return dwo_file
.release ();
12202 /* This function is mapped across the sections and remembers the offset and
12203 size of each of the DWP debugging sections common to version 1 and 2 that
12204 we are interested in. */
12207 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12208 dwp_file
*dwp_file
)
12210 const struct dwop_section_names
*names
= &dwop_section_names
;
12211 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12213 /* Record the ELF section number for later lookup: this is what the
12214 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12215 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12216 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12218 /* Look for specific sections that we need. */
12219 if (names
->str_dwo
.matches (sectp
->name
))
12221 dwp_file
->sections
.str
.s
.section
= sectp
;
12222 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12224 else if (names
->cu_index
.matches (sectp
->name
))
12226 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12227 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12229 else if (names
->tu_index
.matches (sectp
->name
))
12231 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12232 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12236 /* This function is mapped across the sections and remembers the offset and
12237 size of each of the DWP version 2 debugging sections that we are interested
12238 in. This is split into a separate function because we don't know if we
12239 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12242 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12244 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12245 const struct dwop_section_names
*names
= &dwop_section_names
;
12246 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12248 /* Record the ELF section number for later lookup: this is what the
12249 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12250 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12251 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12253 /* Look for specific sections that we need. */
12254 if (names
->abbrev_dwo
.matches (sectp
->name
))
12256 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12257 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12259 else if (names
->info_dwo
.matches (sectp
->name
))
12261 dwp_file
->sections
.info
.s
.section
= sectp
;
12262 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12264 else if (names
->line_dwo
.matches (sectp
->name
))
12266 dwp_file
->sections
.line
.s
.section
= sectp
;
12267 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12269 else if (names
->loc_dwo
.matches (sectp
->name
))
12271 dwp_file
->sections
.loc
.s
.section
= sectp
;
12272 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12274 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12276 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12277 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12279 else if (names
->macro_dwo
.matches (sectp
->name
))
12281 dwp_file
->sections
.macro
.s
.section
= sectp
;
12282 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12284 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12286 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12287 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12289 else if (names
->types_dwo
.matches (sectp
->name
))
12291 dwp_file
->sections
.types
.s
.section
= sectp
;
12292 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12296 /* This function is mapped across the sections and remembers the offset and
12297 size of each of the DWP version 5 debugging sections that we are interested
12298 in. This is split into a separate function because we don't know if we
12299 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12302 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12304 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12305 const struct dwop_section_names
*names
= &dwop_section_names
;
12306 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12308 /* Record the ELF section number for later lookup: this is what the
12309 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12310 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12311 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12313 /* Look for specific sections that we need. */
12314 if (names
->abbrev_dwo
.matches (sectp
->name
))
12316 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12317 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12319 else if (names
->info_dwo
.matches (sectp
->name
))
12321 dwp_file
->sections
.info
.s
.section
= sectp
;
12322 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12324 else if (names
->line_dwo
.matches (sectp
->name
))
12326 dwp_file
->sections
.line
.s
.section
= sectp
;
12327 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12329 else if (names
->loclists_dwo
.matches (sectp
->name
))
12331 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12332 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12334 else if (names
->macro_dwo
.matches (sectp
->name
))
12336 dwp_file
->sections
.macro
.s
.section
= sectp
;
12337 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12339 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12341 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12342 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12344 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12346 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12347 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12351 /* Hash function for dwp_file loaded CUs/TUs. */
12354 hash_dwp_loaded_cutus (const void *item
)
12356 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12358 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12359 return dwo_unit
->signature
;
12362 /* Equality function for dwp_file loaded CUs/TUs. */
12365 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12367 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12368 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12370 return dua
->signature
== dub
->signature
;
12373 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12376 allocate_dwp_loaded_cutus_table ()
12378 return htab_up (htab_create_alloc (3,
12379 hash_dwp_loaded_cutus
,
12380 eq_dwp_loaded_cutus
,
12381 NULL
, xcalloc
, xfree
));
12384 /* Try to open DWP file FILE_NAME.
12385 The result is the bfd handle of the file.
12386 If there is a problem finding or opening the file, return NULL.
12387 Upon success, the canonicalized path of the file is stored in the bfd,
12388 same as symfile_bfd_open. */
12390 static gdb_bfd_ref_ptr
12391 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12393 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12395 1 /*search_cwd*/));
12399 /* Work around upstream bug 15652.
12400 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12401 [Whether that's a "bug" is debatable, but it is getting in our way.]
12402 We have no real idea where the dwp file is, because gdb's realpath-ing
12403 of the executable's path may have discarded the needed info.
12404 [IWBN if the dwp file name was recorded in the executable, akin to
12405 .gnu_debuglink, but that doesn't exist yet.]
12406 Strip the directory from FILE_NAME and search again. */
12407 if (*debug_file_directory
!= '\0')
12409 /* Don't implicitly search the current directory here.
12410 If the user wants to search "." to handle this case,
12411 it must be added to debug-file-directory. */
12412 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12420 /* Initialize the use of the DWP file for the current objfile.
12421 By convention the name of the DWP file is ${objfile}.dwp.
12422 The result is NULL if it can't be found. */
12424 static std::unique_ptr
<struct dwp_file
>
12425 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12427 struct objfile
*objfile
= per_objfile
->objfile
;
12429 /* Try to find first .dwp for the binary file before any symbolic links
12432 /* If the objfile is a debug file, find the name of the real binary
12433 file and get the name of dwp file from there. */
12434 std::string dwp_name
;
12435 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12437 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12438 const char *backlink_basename
= lbasename (backlink
->original_name
);
12440 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12443 dwp_name
= objfile
->original_name
;
12445 dwp_name
+= ".dwp";
12447 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12449 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12451 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12452 dwp_name
= objfile_name (objfile
);
12453 dwp_name
+= ".dwp";
12454 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12459 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12461 return std::unique_ptr
<dwp_file
> ();
12464 const char *name
= bfd_get_filename (dbfd
.get ());
12465 std::unique_ptr
<struct dwp_file
> dwp_file
12466 (new struct dwp_file (name
, std::move (dbfd
)));
12468 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12469 dwp_file
->elf_sections
=
12470 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12471 dwp_file
->num_sections
, asection
*);
12473 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12474 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12477 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12479 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12481 /* The DWP file version is stored in the hash table. Oh well. */
12482 if (dwp_file
->cus
&& dwp_file
->tus
12483 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12485 /* Technically speaking, we should try to limp along, but this is
12486 pretty bizarre. We use pulongest here because that's the established
12487 portability solution (e.g, we cannot use %u for uint32_t). */
12488 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12489 " TU version %s [in DWP file %s]"),
12490 pulongest (dwp_file
->cus
->version
),
12491 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12495 dwp_file
->version
= dwp_file
->cus
->version
;
12496 else if (dwp_file
->tus
)
12497 dwp_file
->version
= dwp_file
->tus
->version
;
12499 dwp_file
->version
= 2;
12501 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12503 if (dwp_file
->version
== 2)
12504 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12507 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12511 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12512 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12514 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12515 dwarf_read_debug_printf (" %s CUs, %s TUs",
12516 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12517 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12522 /* Wrapper around open_and_init_dwp_file, only open it once. */
12524 static struct dwp_file
*
12525 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12527 if (!per_objfile
->per_bfd
->dwp_checked
)
12529 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12530 per_objfile
->per_bfd
->dwp_checked
= 1;
12532 return per_objfile
->per_bfd
->dwp_file
.get ();
12535 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12536 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12537 or in the DWP file for the objfile, referenced by THIS_UNIT.
12538 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12539 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12541 This is called, for example, when wanting to read a variable with a
12542 complex location. Therefore we don't want to do file i/o for every call.
12543 Therefore we don't want to look for a DWO file on every call.
12544 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12545 then we check if we've already seen DWO_NAME, and only THEN do we check
12548 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12549 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12551 static struct dwo_unit
*
12552 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12553 ULONGEST signature
, int is_debug_types
)
12555 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12556 struct objfile
*objfile
= per_objfile
->objfile
;
12557 const char *kind
= is_debug_types
? "TU" : "CU";
12558 void **dwo_file_slot
;
12559 struct dwo_file
*dwo_file
;
12560 struct dwp_file
*dwp_file
;
12562 /* First see if there's a DWP file.
12563 If we have a DWP file but didn't find the DWO inside it, don't
12564 look for the original DWO file. It makes gdb behave differently
12565 depending on whether one is debugging in the build tree. */
12567 dwp_file
= get_dwp_file (per_objfile
);
12568 if (dwp_file
!= NULL
)
12570 const struct dwp_hash_table
*dwp_htab
=
12571 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12573 if (dwp_htab
!= NULL
)
12575 struct dwo_unit
*dwo_cutu
=
12576 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12579 if (dwo_cutu
!= NULL
)
12581 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12582 kind
, hex_string (signature
),
12583 host_address_to_string (dwo_cutu
));
12591 /* No DWP file, look for the DWO file. */
12593 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12594 if (*dwo_file_slot
== NULL
)
12596 /* Read in the file and build a table of the CUs/TUs it contains. */
12597 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12599 /* NOTE: This will be NULL if unable to open the file. */
12600 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12602 if (dwo_file
!= NULL
)
12604 struct dwo_unit
*dwo_cutu
= NULL
;
12606 if (is_debug_types
&& dwo_file
->tus
)
12608 struct dwo_unit find_dwo_cutu
;
12610 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12611 find_dwo_cutu
.signature
= signature
;
12613 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12616 else if (!is_debug_types
&& dwo_file
->cus
)
12618 struct dwo_unit find_dwo_cutu
;
12620 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12621 find_dwo_cutu
.signature
= signature
;
12622 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12626 if (dwo_cutu
!= NULL
)
12628 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12629 kind
, dwo_name
, hex_string (signature
),
12630 host_address_to_string (dwo_cutu
));
12637 /* We didn't find it. This could mean a dwo_id mismatch, or
12638 someone deleted the DWO/DWP file, or the search path isn't set up
12639 correctly to find the file. */
12641 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12642 kind
, dwo_name
, hex_string (signature
));
12644 /* This is a warning and not a complaint because it can be caused by
12645 pilot error (e.g., user accidentally deleting the DWO). */
12647 /* Print the name of the DWP file if we looked there, helps the user
12648 better diagnose the problem. */
12649 std::string dwp_text
;
12651 if (dwp_file
!= NULL
)
12652 dwp_text
= string_printf (" [in DWP file %s]",
12653 lbasename (dwp_file
->name
));
12655 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12656 " [in module %s]"),
12657 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12658 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12663 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12664 See lookup_dwo_cutu_unit for details. */
12666 static struct dwo_unit
*
12667 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12668 ULONGEST signature
)
12670 gdb_assert (!cu
->per_cu
->is_debug_types
);
12672 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12675 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12676 See lookup_dwo_cutu_unit for details. */
12678 static struct dwo_unit
*
12679 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12681 gdb_assert (cu
->per_cu
->is_debug_types
);
12683 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12685 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12688 /* Traversal function for queue_and_load_all_dwo_tus. */
12691 queue_and_load_dwo_tu (void **slot
, void *info
)
12693 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12694 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12695 ULONGEST signature
= dwo_unit
->signature
;
12696 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12698 if (sig_type
!= NULL
)
12700 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12701 a real dependency of PER_CU on SIG_TYPE. That is detected later
12702 while processing PER_CU. */
12703 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12705 load_full_type_unit (sig_type
, cu
->per_objfile
);
12706 cu
->per_cu
->imported_symtabs_push (sig_type
);
12712 /* Queue all TUs contained in the DWO of CU to be read in.
12713 The DWO may have the only definition of the type, though it may not be
12714 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12715 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12718 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12720 struct dwo_unit
*dwo_unit
;
12721 struct dwo_file
*dwo_file
;
12723 gdb_assert (cu
!= nullptr);
12724 gdb_assert (!cu
->per_cu
->is_debug_types
);
12725 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12727 dwo_unit
= cu
->dwo_unit
;
12728 gdb_assert (dwo_unit
!= NULL
);
12730 dwo_file
= dwo_unit
->dwo_file
;
12731 if (dwo_file
->tus
!= NULL
)
12732 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12735 /* Read in various DIEs. */
12737 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12738 Inherit only the children of the DW_AT_abstract_origin DIE not being
12739 already referenced by DW_AT_abstract_origin from the children of the
12743 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12745 struct die_info
*child_die
;
12746 sect_offset
*offsetp
;
12747 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12748 struct die_info
*origin_die
;
12749 /* Iterator of the ORIGIN_DIE children. */
12750 struct die_info
*origin_child_die
;
12751 struct attribute
*attr
;
12752 struct dwarf2_cu
*origin_cu
;
12753 struct pending
**origin_previous_list_in_scope
;
12755 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12759 /* Note that following die references may follow to a die in a
12763 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12765 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12767 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12768 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12770 if (die
->tag
!= origin_die
->tag
12771 && !(die
->tag
== DW_TAG_inlined_subroutine
12772 && origin_die
->tag
== DW_TAG_subprogram
))
12773 complaint (_("DIE %s and its abstract origin %s have different tags"),
12774 sect_offset_str (die
->sect_off
),
12775 sect_offset_str (origin_die
->sect_off
));
12777 /* Find if the concrete and abstract trees are structurally the
12778 same. This is a shallow traversal and it is not bullet-proof;
12779 the compiler can trick the debugger into believing that the trees
12780 are isomorphic, whereas they actually are not. However, the
12781 likelyhood of this happening is pretty low, and a full-fledged
12782 check would be an overkill. */
12783 bool are_isomorphic
= true;
12784 die_info
*concrete_child
= die
->child
;
12785 die_info
*abstract_child
= origin_die
->child
;
12786 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
12788 if (concrete_child
== nullptr
12789 || abstract_child
== nullptr
12790 || concrete_child
->tag
!= abstract_child
->tag
)
12792 are_isomorphic
= false;
12796 concrete_child
= concrete_child
->sibling
;
12797 abstract_child
= abstract_child
->sibling
;
12800 /* Walk the origin's children in parallel to the concrete children.
12801 This helps match an origin child in case the debug info misses
12802 DW_AT_abstract_origin attributes. Keep in mind that the abstract
12803 origin tree may not have the same tree structure as the concrete
12805 die_info
*corresponding_abstract_child
12806 = are_isomorphic
? origin_die
->child
: nullptr;
12808 std::vector
<sect_offset
> offsets
;
12810 for (child_die
= die
->child
;
12811 child_die
&& child_die
->tag
;
12812 child_die
= child_die
->sibling
)
12814 struct die_info
*child_origin_die
;
12815 struct dwarf2_cu
*child_origin_cu
;
12817 /* We are trying to process concrete instance entries:
12818 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12819 it's not relevant to our analysis here. i.e. detecting DIEs that are
12820 present in the abstract instance but not referenced in the concrete
12822 if (child_die
->tag
== DW_TAG_call_site
12823 || child_die
->tag
== DW_TAG_GNU_call_site
)
12825 if (are_isomorphic
)
12826 corresponding_abstract_child
12827 = corresponding_abstract_child
->sibling
;
12831 /* For each CHILD_DIE, find the corresponding child of
12832 ORIGIN_DIE. If there is more than one layer of
12833 DW_AT_abstract_origin, follow them all; there shouldn't be,
12834 but GCC versions at least through 4.4 generate this (GCC PR
12836 child_origin_die
= child_die
;
12837 child_origin_cu
= cu
;
12840 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12844 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12848 /* If missing DW_AT_abstract_origin, try the corresponding child
12849 of the origin. Clang emits such lexical scopes. */
12850 if (child_origin_die
== child_die
12851 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
12853 && child_die
->tag
== DW_TAG_lexical_block
)
12854 child_origin_die
= corresponding_abstract_child
;
12856 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12857 counterpart may exist. */
12858 if (child_origin_die
!= child_die
)
12860 if (child_die
->tag
!= child_origin_die
->tag
12861 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12862 && child_origin_die
->tag
== DW_TAG_subprogram
))
12863 complaint (_("Child DIE %s and its abstract origin %s have "
12865 sect_offset_str (child_die
->sect_off
),
12866 sect_offset_str (child_origin_die
->sect_off
));
12867 if (child_origin_die
->parent
!= origin_die
)
12868 complaint (_("Child DIE %s and its abstract origin %s have "
12869 "different parents"),
12870 sect_offset_str (child_die
->sect_off
),
12871 sect_offset_str (child_origin_die
->sect_off
));
12873 offsets
.push_back (child_origin_die
->sect_off
);
12876 if (are_isomorphic
)
12877 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
12879 std::sort (offsets
.begin (), offsets
.end ());
12880 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12881 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12882 if (offsetp
[-1] == *offsetp
)
12883 complaint (_("Multiple children of DIE %s refer "
12884 "to DIE %s as their abstract origin"),
12885 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12887 offsetp
= offsets
.data ();
12888 origin_child_die
= origin_die
->child
;
12889 while (origin_child_die
&& origin_child_die
->tag
)
12891 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12892 while (offsetp
< offsets_end
12893 && *offsetp
< origin_child_die
->sect_off
)
12895 if (offsetp
>= offsets_end
12896 || *offsetp
> origin_child_die
->sect_off
)
12898 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12899 Check whether we're already processing ORIGIN_CHILD_DIE.
12900 This can happen with mutually referenced abstract_origins.
12902 if (!origin_child_die
->in_process
)
12903 process_die (origin_child_die
, origin_cu
);
12905 origin_child_die
= origin_child_die
->sibling
;
12907 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12909 if (cu
!= origin_cu
)
12910 compute_delayed_physnames (origin_cu
);
12914 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12916 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
12917 struct gdbarch
*gdbarch
= objfile
->arch ();
12918 struct context_stack
*newobj
;
12921 struct die_info
*child_die
;
12922 struct attribute
*attr
, *call_line
, *call_file
;
12924 CORE_ADDR baseaddr
;
12925 struct block
*block
;
12926 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12927 std::vector
<struct symbol
*> template_args
;
12928 struct template_symbol
*templ_func
= NULL
;
12932 /* If we do not have call site information, we can't show the
12933 caller of this inlined function. That's too confusing, so
12934 only use the scope for local variables. */
12935 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12936 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12937 if (call_line
== NULL
|| call_file
== NULL
)
12939 read_lexical_block_scope (die
, cu
);
12944 baseaddr
= objfile
->text_section_offset ();
12946 name
= dwarf2_name (die
, cu
);
12948 /* Ignore functions with missing or empty names. These are actually
12949 illegal according to the DWARF standard. */
12952 complaint (_("missing name for subprogram DIE at %s"),
12953 sect_offset_str (die
->sect_off
));
12957 /* Ignore functions with missing or invalid low and high pc attributes. */
12958 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12959 <= PC_BOUNDS_INVALID
)
12961 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12962 if (attr
== nullptr || !attr
->as_boolean ())
12963 complaint (_("cannot get low and high bounds "
12964 "for subprogram DIE at %s"),
12965 sect_offset_str (die
->sect_off
));
12969 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12970 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12972 /* If we have any template arguments, then we must allocate a
12973 different sort of symbol. */
12974 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12976 if (child_die
->tag
== DW_TAG_template_type_param
12977 || child_die
->tag
== DW_TAG_template_value_param
)
12979 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
12980 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12985 gdb_assert (cu
->get_builder () != nullptr);
12986 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12987 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12988 (struct symbol
*) templ_func
);
12990 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12991 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12994 /* If there is a location expression for DW_AT_frame_base, record
12996 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12997 if (attr
!= nullptr)
12998 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13000 /* If there is a location for the static link, record it. */
13001 newobj
->static_link
= NULL
;
13002 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13003 if (attr
!= nullptr)
13005 newobj
->static_link
13006 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13007 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13011 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13013 if (die
->child
!= NULL
)
13015 child_die
= die
->child
;
13016 while (child_die
&& child_die
->tag
)
13018 if (child_die
->tag
== DW_TAG_template_type_param
13019 || child_die
->tag
== DW_TAG_template_value_param
)
13021 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13024 template_args
.push_back (arg
);
13027 process_die (child_die
, cu
);
13028 child_die
= child_die
->sibling
;
13032 inherit_abstract_dies (die
, cu
);
13034 /* If we have a DW_AT_specification, we might need to import using
13035 directives from the context of the specification DIE. See the
13036 comment in determine_prefix. */
13037 if (cu
->per_cu
->lang
== language_cplus
13038 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13040 struct dwarf2_cu
*spec_cu
= cu
;
13041 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13045 child_die
= spec_die
->child
;
13046 while (child_die
&& child_die
->tag
)
13048 if (child_die
->tag
== DW_TAG_imported_module
)
13049 process_die (child_die
, spec_cu
);
13050 child_die
= child_die
->sibling
;
13053 /* In some cases, GCC generates specification DIEs that
13054 themselves contain DW_AT_specification attributes. */
13055 spec_die
= die_specification (spec_die
, &spec_cu
);
13059 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13060 /* Make a block for the local symbols within. */
13061 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13062 cstk
.static_link
, lowpc
, highpc
);
13064 /* For C++, set the block's scope. */
13065 if ((cu
->per_cu
->lang
== language_cplus
13066 || cu
->per_cu
->lang
== language_fortran
13067 || cu
->per_cu
->lang
== language_d
13068 || cu
->per_cu
->lang
== language_rust
)
13069 && cu
->processing_has_namespace_info
)
13070 block_set_scope (block
, determine_prefix (die
, cu
),
13071 &objfile
->objfile_obstack
);
13073 /* If we have address ranges, record them. */
13074 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13076 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13078 /* Attach template arguments to function. */
13079 if (!template_args
.empty ())
13081 gdb_assert (templ_func
!= NULL
);
13083 templ_func
->n_template_arguments
= template_args
.size ();
13084 templ_func
->template_arguments
13085 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13086 templ_func
->n_template_arguments
);
13087 memcpy (templ_func
->template_arguments
,
13088 template_args
.data (),
13089 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13091 /* Make sure that the symtab is set on the new symbols. Even
13092 though they don't appear in this symtab directly, other parts
13093 of gdb assume that symbols do, and this is reasonably
13095 for (symbol
*sym
: template_args
)
13096 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13099 /* In C++, we can have functions nested inside functions (e.g., when
13100 a function declares a class that has methods). This means that
13101 when we finish processing a function scope, we may need to go
13102 back to building a containing block's symbol lists. */
13103 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13104 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13106 /* If we've finished processing a top-level function, subsequent
13107 symbols go in the file symbol list. */
13108 if (cu
->get_builder ()->outermost_context_p ())
13109 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13112 /* Process all the DIES contained within a lexical block scope. Start
13113 a new scope, process the dies, and then close the scope. */
13116 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13118 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13119 struct gdbarch
*gdbarch
= objfile
->arch ();
13120 CORE_ADDR lowpc
, highpc
;
13121 struct die_info
*child_die
;
13122 CORE_ADDR baseaddr
;
13124 baseaddr
= objfile
->text_section_offset ();
13126 /* Ignore blocks with missing or invalid low and high pc attributes. */
13127 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13128 as multiple lexical blocks? Handling children in a sane way would
13129 be nasty. Might be easier to properly extend generic blocks to
13130 describe ranges. */
13131 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13133 case PC_BOUNDS_NOT_PRESENT
:
13134 /* DW_TAG_lexical_block has no attributes, process its children as if
13135 there was no wrapping by that DW_TAG_lexical_block.
13136 GCC does no longer produces such DWARF since GCC r224161. */
13137 for (child_die
= die
->child
;
13138 child_die
!= NULL
&& child_die
->tag
;
13139 child_die
= child_die
->sibling
)
13141 /* We might already be processing this DIE. This can happen
13142 in an unusual circumstance -- where a subroutine A
13143 appears lexically in another subroutine B, but A actually
13144 inlines B. The recursion is broken here, rather than in
13145 inherit_abstract_dies, because it seems better to simply
13146 drop concrete children here. */
13147 if (!child_die
->in_process
)
13148 process_die (child_die
, cu
);
13151 case PC_BOUNDS_INVALID
:
13154 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13155 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13157 cu
->get_builder ()->push_context (0, lowpc
);
13158 if (die
->child
!= NULL
)
13160 child_die
= die
->child
;
13161 while (child_die
&& child_die
->tag
)
13163 process_die (child_die
, cu
);
13164 child_die
= child_die
->sibling
;
13167 inherit_abstract_dies (die
, cu
);
13168 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13170 if (*cu
->get_builder ()->get_local_symbols () != NULL
13171 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13173 struct block
*block
13174 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13175 cstk
.start_addr
, highpc
);
13177 /* Note that recording ranges after traversing children, as we
13178 do here, means that recording a parent's ranges entails
13179 walking across all its children's ranges as they appear in
13180 the address map, which is quadratic behavior.
13182 It would be nicer to record the parent's ranges before
13183 traversing its children, simply overriding whatever you find
13184 there. But since we don't even decide whether to create a
13185 block until after we've traversed its children, that's hard
13187 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13189 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13190 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13193 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13196 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13198 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13199 struct objfile
*objfile
= per_objfile
->objfile
;
13200 struct gdbarch
*gdbarch
= objfile
->arch ();
13201 CORE_ADDR pc
, baseaddr
;
13202 struct attribute
*attr
;
13203 struct call_site
*call_site
, call_site_local
;
13206 struct die_info
*child_die
;
13208 baseaddr
= objfile
->text_section_offset ();
13210 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13213 /* This was a pre-DWARF-5 GNU extension alias
13214 for DW_AT_call_return_pc. */
13215 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13219 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13220 "DIE %s [in module %s]"),
13221 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13224 pc
= attr
->as_address () + baseaddr
;
13225 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13227 if (cu
->call_site_htab
== NULL
)
13228 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13229 NULL
, &objfile
->objfile_obstack
,
13230 hashtab_obstack_allocate
, NULL
);
13231 call_site_local
.pc
= pc
;
13232 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13235 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13236 "DIE %s [in module %s]"),
13237 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13238 objfile_name (objfile
));
13242 /* Count parameters at the caller. */
13245 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13246 child_die
= child_die
->sibling
)
13248 if (child_die
->tag
!= DW_TAG_call_site_parameter
13249 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13251 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13252 "DW_TAG_call_site child DIE %s [in module %s]"),
13253 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13254 objfile_name (objfile
));
13262 = ((struct call_site
*)
13263 obstack_alloc (&objfile
->objfile_obstack
,
13264 sizeof (*call_site
)
13265 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13267 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13268 call_site
->pc
= pc
;
13270 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13271 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13273 struct die_info
*func_die
;
13275 /* Skip also over DW_TAG_inlined_subroutine. */
13276 for (func_die
= die
->parent
;
13277 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13278 && func_die
->tag
!= DW_TAG_subroutine_type
;
13279 func_die
= func_die
->parent
);
13281 /* DW_AT_call_all_calls is a superset
13282 of DW_AT_call_all_tail_calls. */
13284 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13285 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13286 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13287 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13289 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13290 not complete. But keep CALL_SITE for look ups via call_site_htab,
13291 both the initial caller containing the real return address PC and
13292 the final callee containing the current PC of a chain of tail
13293 calls do not need to have the tail call list complete. But any
13294 function candidate for a virtual tail call frame searched via
13295 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13296 determined unambiguously. */
13300 struct type
*func_type
= NULL
;
13303 func_type
= get_die_type (func_die
, cu
);
13304 if (func_type
!= NULL
)
13306 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13308 /* Enlist this call site to the function. */
13309 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13310 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13313 complaint (_("Cannot find function owning DW_TAG_call_site "
13314 "DIE %s [in module %s]"),
13315 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13319 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13321 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13323 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13326 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13327 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13329 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13330 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13331 /* Keep NULL DWARF_BLOCK. */;
13332 else if (attr
->form_is_block ())
13334 struct dwarf2_locexpr_baton
*dlbaton
;
13335 struct dwarf_block
*block
= attr
->as_block ();
13337 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13338 dlbaton
->data
= block
->data
;
13339 dlbaton
->size
= block
->size
;
13340 dlbaton
->per_objfile
= per_objfile
;
13341 dlbaton
->per_cu
= cu
->per_cu
;
13343 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13345 else if (attr
->form_is_ref ())
13347 struct dwarf2_cu
*target_cu
= cu
;
13348 struct die_info
*target_die
;
13350 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13351 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13352 if (die_is_declaration (target_die
, target_cu
))
13354 const char *target_physname
;
13356 /* Prefer the mangled name; otherwise compute the demangled one. */
13357 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13358 if (target_physname
== NULL
)
13359 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13360 if (target_physname
== NULL
)
13361 complaint (_("DW_AT_call_target target DIE has invalid "
13362 "physname, for referencing DIE %s [in module %s]"),
13363 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13365 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13371 /* DW_AT_entry_pc should be preferred. */
13372 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13373 <= PC_BOUNDS_INVALID
)
13374 complaint (_("DW_AT_call_target target DIE has invalid "
13375 "low pc, for referencing DIE %s [in module %s]"),
13376 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13379 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13380 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13385 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13386 "block nor reference, for DIE %s [in module %s]"),
13387 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13389 call_site
->per_cu
= cu
->per_cu
;
13390 call_site
->per_objfile
= per_objfile
;
13392 for (child_die
= die
->child
;
13393 child_die
&& child_die
->tag
;
13394 child_die
= child_die
->sibling
)
13396 struct call_site_parameter
*parameter
;
13397 struct attribute
*loc
, *origin
;
13399 if (child_die
->tag
!= DW_TAG_call_site_parameter
13400 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13402 /* Already printed the complaint above. */
13406 gdb_assert (call_site
->parameter_count
< nparams
);
13407 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13409 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13410 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13411 register is contained in DW_AT_call_value. */
13413 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13414 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13415 if (origin
== NULL
)
13417 /* This was a pre-DWARF-5 GNU extension alias
13418 for DW_AT_call_parameter. */
13419 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13421 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13423 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13425 sect_offset sect_off
= origin
->get_ref_die_offset ();
13426 if (!cu
->header
.offset_in_cu_p (sect_off
))
13428 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13429 binding can be done only inside one CU. Such referenced DIE
13430 therefore cannot be even moved to DW_TAG_partial_unit. */
13431 complaint (_("DW_AT_call_parameter offset is not in CU for "
13432 "DW_TAG_call_site child DIE %s [in module %s]"),
13433 sect_offset_str (child_die
->sect_off
),
13434 objfile_name (objfile
));
13437 parameter
->u
.param_cu_off
13438 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13440 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13442 complaint (_("No DW_FORM_block* DW_AT_location for "
13443 "DW_TAG_call_site child DIE %s [in module %s]"),
13444 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13449 struct dwarf_block
*block
= loc
->as_block ();
13451 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13452 (block
->data
, &block
->data
[block
->size
]);
13453 if (parameter
->u
.dwarf_reg
!= -1)
13454 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13455 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13456 &block
->data
[block
->size
],
13457 ¶meter
->u
.fb_offset
))
13458 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13461 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13462 "for DW_FORM_block* DW_AT_location is supported for "
13463 "DW_TAG_call_site child DIE %s "
13465 sect_offset_str (child_die
->sect_off
),
13466 objfile_name (objfile
));
13471 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13473 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13474 if (attr
== NULL
|| !attr
->form_is_block ())
13476 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13477 "DW_TAG_call_site child DIE %s [in module %s]"),
13478 sect_offset_str (child_die
->sect_off
),
13479 objfile_name (objfile
));
13483 struct dwarf_block
*block
= attr
->as_block ();
13484 parameter
->value
= block
->data
;
13485 parameter
->value_size
= block
->size
;
13487 /* Parameters are not pre-cleared by memset above. */
13488 parameter
->data_value
= NULL
;
13489 parameter
->data_value_size
= 0;
13490 call_site
->parameter_count
++;
13492 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13494 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13495 if (attr
!= nullptr)
13497 if (!attr
->form_is_block ())
13498 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13499 "DW_TAG_call_site child DIE %s [in module %s]"),
13500 sect_offset_str (child_die
->sect_off
),
13501 objfile_name (objfile
));
13504 block
= attr
->as_block ();
13505 parameter
->data_value
= block
->data
;
13506 parameter
->data_value_size
= block
->size
;
13512 /* Helper function for read_variable. If DIE represents a virtual
13513 table, then return the type of the concrete object that is
13514 associated with the virtual table. Otherwise, return NULL. */
13516 static struct type
*
13517 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13519 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13523 /* Find the type DIE. */
13524 struct die_info
*type_die
= NULL
;
13525 struct dwarf2_cu
*type_cu
= cu
;
13527 if (attr
->form_is_ref ())
13528 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13529 if (type_die
== NULL
)
13532 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13534 return die_containing_type (type_die
, type_cu
);
13537 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13540 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13542 struct rust_vtable_symbol
*storage
= NULL
;
13544 if (cu
->per_cu
->lang
== language_rust
)
13546 struct type
*containing_type
= rust_containing_type (die
, cu
);
13548 if (containing_type
!= NULL
)
13550 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13552 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13553 storage
->concrete_type
= containing_type
;
13554 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13558 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13559 struct attribute
*abstract_origin
13560 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13561 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13562 if (res
== NULL
&& loc
&& abstract_origin
)
13564 /* We have a variable without a name, but with a location and an abstract
13565 origin. This may be a concrete instance of an abstract variable
13566 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13568 struct dwarf2_cu
*origin_cu
= cu
;
13569 struct die_info
*origin_die
13570 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13571 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13572 per_objfile
->per_bfd
->abstract_to_concrete
13573 [origin_die
->sect_off
].push_back (die
->sect_off
);
13577 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13578 reading .debug_rnglists.
13579 Callback's type should be:
13580 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13581 Return true if the attributes are present and valid, otherwise,
13584 template <typename Callback
>
13586 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13587 dwarf_tag tag
, Callback
&&callback
)
13589 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13590 struct objfile
*objfile
= per_objfile
->objfile
;
13591 bfd
*obfd
= objfile
->obfd
;
13592 /* Base address selection entry. */
13593 gdb::optional
<CORE_ADDR
> base
;
13594 const gdb_byte
*buffer
;
13595 CORE_ADDR baseaddr
;
13596 bool overflow
= false;
13597 ULONGEST addr_index
;
13598 struct dwarf2_section_info
*rnglists_section
;
13600 base
= cu
->base_address
;
13601 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13602 rnglists_section
->read (objfile
);
13604 if (offset
>= rnglists_section
->size
)
13606 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13610 buffer
= rnglists_section
->buffer
+ offset
;
13612 baseaddr
= objfile
->text_section_offset ();
13616 /* Initialize it due to a false compiler warning. */
13617 CORE_ADDR range_beginning
= 0, range_end
= 0;
13618 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13619 + rnglists_section
->size
);
13620 unsigned int bytes_read
;
13622 if (buffer
== buf_end
)
13627 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13630 case DW_RLE_end_of_list
:
13632 case DW_RLE_base_address
:
13633 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13638 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13639 buffer
+= bytes_read
;
13641 case DW_RLE_base_addressx
:
13642 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13643 buffer
+= bytes_read
;
13644 base
= read_addr_index (cu
, addr_index
);
13646 case DW_RLE_start_length
:
13647 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13652 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13654 buffer
+= bytes_read
;
13655 range_end
= (range_beginning
13656 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13657 buffer
+= bytes_read
;
13658 if (buffer
> buf_end
)
13664 case DW_RLE_startx_length
:
13665 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13666 buffer
+= bytes_read
;
13667 range_beginning
= read_addr_index (cu
, addr_index
);
13668 if (buffer
> buf_end
)
13673 range_end
= (range_beginning
13674 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13675 buffer
+= bytes_read
;
13677 case DW_RLE_offset_pair
:
13678 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13679 buffer
+= bytes_read
;
13680 if (buffer
> buf_end
)
13685 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13686 buffer
+= bytes_read
;
13687 if (buffer
> buf_end
)
13693 case DW_RLE_start_end
:
13694 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13699 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13701 buffer
+= bytes_read
;
13702 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13703 buffer
+= bytes_read
;
13705 case DW_RLE_startx_endx
:
13706 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13707 buffer
+= bytes_read
;
13708 range_beginning
= read_addr_index (cu
, addr_index
);
13709 if (buffer
> buf_end
)
13714 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13715 buffer
+= bytes_read
;
13716 range_end
= read_addr_index (cu
, addr_index
);
13719 complaint (_("Invalid .debug_rnglists data (no base address)"));
13722 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13724 if (rlet
== DW_RLE_base_address
)
13727 if (range_beginning
> range_end
)
13729 /* Inverted range entries are invalid. */
13730 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13734 /* Empty range entries have no effect. */
13735 if (range_beginning
== range_end
)
13738 /* Only DW_RLE_offset_pair needs the base address added. */
13739 if (rlet
== DW_RLE_offset_pair
)
13741 if (!base
.has_value ())
13743 /* We have no valid base address for the DW_RLE_offset_pair. */
13744 complaint (_("Invalid .debug_rnglists data (no base address for "
13745 "DW_RLE_offset_pair)"));
13749 range_beginning
+= *base
;
13750 range_end
+= *base
;
13753 /* A not-uncommon case of bad debug info.
13754 Don't pollute the addrmap with bad data. */
13755 if (range_beginning
+ baseaddr
== 0
13756 && !per_objfile
->per_bfd
->has_section_at_zero
)
13758 complaint (_(".debug_rnglists entry has start address of zero"
13759 " [in module %s]"), objfile_name (objfile
));
13763 callback (range_beginning
, range_end
);
13768 complaint (_("Offset %d is not terminated "
13769 "for DW_AT_ranges attribute"),
13777 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13778 Callback's type should be:
13779 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13780 Return 1 if the attributes are present and valid, otherwise, return 0. */
13782 template <typename Callback
>
13784 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
13785 Callback
&&callback
)
13787 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13788 struct objfile
*objfile
= per_objfile
->objfile
;
13789 struct comp_unit_head
*cu_header
= &cu
->header
;
13790 bfd
*obfd
= objfile
->obfd
;
13791 unsigned int addr_size
= cu_header
->addr_size
;
13792 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13793 /* Base address selection entry. */
13794 gdb::optional
<CORE_ADDR
> base
;
13795 unsigned int dummy
;
13796 const gdb_byte
*buffer
;
13797 CORE_ADDR baseaddr
;
13799 if (cu_header
->version
>= 5)
13800 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
13802 base
= cu
->base_address
;
13804 per_objfile
->per_bfd
->ranges
.read (objfile
);
13805 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
13807 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13811 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
13813 baseaddr
= objfile
->text_section_offset ();
13817 CORE_ADDR range_beginning
, range_end
;
13819 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13820 buffer
+= addr_size
;
13821 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13822 buffer
+= addr_size
;
13823 offset
+= 2 * addr_size
;
13825 /* An end of list marker is a pair of zero addresses. */
13826 if (range_beginning
== 0 && range_end
== 0)
13827 /* Found the end of list entry. */
13830 /* Each base address selection entry is a pair of 2 values.
13831 The first is the largest possible address, the second is
13832 the base address. Check for a base address here. */
13833 if ((range_beginning
& mask
) == mask
)
13835 /* If we found the largest possible address, then we already
13836 have the base address in range_end. */
13841 if (!base
.has_value ())
13843 /* We have no valid base address for the ranges
13845 complaint (_("Invalid .debug_ranges data (no base address)"));
13849 if (range_beginning
> range_end
)
13851 /* Inverted range entries are invalid. */
13852 complaint (_("Invalid .debug_ranges data (inverted range)"));
13856 /* Empty range entries have no effect. */
13857 if (range_beginning
== range_end
)
13860 range_beginning
+= *base
;
13861 range_end
+= *base
;
13863 /* A not-uncommon case of bad debug info.
13864 Don't pollute the addrmap with bad data. */
13865 if (range_beginning
+ baseaddr
== 0
13866 && !per_objfile
->per_bfd
->has_section_at_zero
)
13868 complaint (_(".debug_ranges entry has start address of zero"
13869 " [in module %s]"), objfile_name (objfile
));
13873 callback (range_beginning
, range_end
);
13879 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13880 Return 1 if the attributes are present and valid, otherwise, return 0.
13881 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
13884 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13885 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13886 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
13888 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13889 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
13890 struct gdbarch
*gdbarch
= objfile
->arch ();
13891 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13894 CORE_ADDR high
= 0;
13897 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
13898 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13900 if (ranges_pst
!= NULL
)
13905 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13906 range_beginning
+ baseaddr
)
13908 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13909 range_end
+ baseaddr
)
13911 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
13912 lowpc
, highpc
- 1, ranges_pst
);
13915 /* FIXME: This is recording everything as a low-high
13916 segment of consecutive addresses. We should have a
13917 data structure for discontiguous block ranges
13921 low
= range_beginning
;
13927 if (range_beginning
< low
)
13928 low
= range_beginning
;
13929 if (range_end
> high
)
13937 /* If the first entry is an end-of-list marker, the range
13938 describes an empty scope, i.e. no instructions. */
13944 *high_return
= high
;
13948 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13949 definition for the return value. *LOWPC and *HIGHPC are set iff
13950 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13952 static enum pc_bounds_kind
13953 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13954 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13955 dwarf2_psymtab
*pst
)
13957 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13958 struct attribute
*attr
;
13959 struct attribute
*attr_high
;
13961 CORE_ADDR high
= 0;
13962 enum pc_bounds_kind ret
;
13964 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13967 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13968 if (attr
!= nullptr)
13970 low
= attr
->as_address ();
13971 high
= attr_high
->as_address ();
13972 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13976 /* Found high w/o low attribute. */
13977 return PC_BOUNDS_INVALID
;
13979 /* Found consecutive range of addresses. */
13980 ret
= PC_BOUNDS_HIGH_LOW
;
13984 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13985 if (attr
!= nullptr && attr
->form_is_unsigned ())
13987 /* Offset in the .debug_ranges or .debug_rnglist section (depending
13988 on DWARF version). */
13989 ULONGEST ranges_offset
= attr
->as_unsigned ();
13991 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
13993 if (die
->tag
!= DW_TAG_compile_unit
)
13994 ranges_offset
+= cu
->gnu_ranges_base
;
13996 /* Value of the DW_AT_ranges attribute is the offset in the
13997 .debug_ranges section. */
13998 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14000 return PC_BOUNDS_INVALID
;
14001 /* Found discontinuous range of addresses. */
14002 ret
= PC_BOUNDS_RANGES
;
14005 return PC_BOUNDS_NOT_PRESENT
;
14008 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14010 return PC_BOUNDS_INVALID
;
14012 /* When using the GNU linker, .gnu.linkonce. sections are used to
14013 eliminate duplicate copies of functions and vtables and such.
14014 The linker will arbitrarily choose one and discard the others.
14015 The AT_*_pc values for such functions refer to local labels in
14016 these sections. If the section from that file was discarded, the
14017 labels are not in the output, so the relocs get a value of 0.
14018 If this is a discarded function, mark the pc bounds as invalid,
14019 so that GDB will ignore it. */
14020 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14021 return PC_BOUNDS_INVALID
;
14029 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14030 its low and high PC addresses. Do nothing if these addresses could not
14031 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14032 and HIGHPC to the high address if greater than HIGHPC. */
14035 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14036 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14037 struct dwarf2_cu
*cu
)
14039 CORE_ADDR low
, high
;
14040 struct die_info
*child
= die
->child
;
14042 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14044 *lowpc
= std::min (*lowpc
, low
);
14045 *highpc
= std::max (*highpc
, high
);
14048 /* If the language does not allow nested subprograms (either inside
14049 subprograms or lexical blocks), we're done. */
14050 if (cu
->per_cu
->lang
!= language_ada
)
14053 /* Check all the children of the given DIE. If it contains nested
14054 subprograms, then check their pc bounds. Likewise, we need to
14055 check lexical blocks as well, as they may also contain subprogram
14057 while (child
&& child
->tag
)
14059 if (child
->tag
== DW_TAG_subprogram
14060 || child
->tag
== DW_TAG_lexical_block
)
14061 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14062 child
= child
->sibling
;
14066 /* Get the low and high pc's represented by the scope DIE, and store
14067 them in *LOWPC and *HIGHPC. If the correct values can't be
14068 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14071 get_scope_pc_bounds (struct die_info
*die
,
14072 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14073 struct dwarf2_cu
*cu
)
14075 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14076 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14077 CORE_ADDR current_low
, current_high
;
14079 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14080 >= PC_BOUNDS_RANGES
)
14082 best_low
= current_low
;
14083 best_high
= current_high
;
14087 struct die_info
*child
= die
->child
;
14089 while (child
&& child
->tag
)
14091 switch (child
->tag
) {
14092 case DW_TAG_subprogram
:
14093 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14095 case DW_TAG_namespace
:
14096 case DW_TAG_module
:
14097 /* FIXME: carlton/2004-01-16: Should we do this for
14098 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14099 that current GCC's always emit the DIEs corresponding
14100 to definitions of methods of classes as children of a
14101 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14102 the DIEs giving the declarations, which could be
14103 anywhere). But I don't see any reason why the
14104 standards says that they have to be there. */
14105 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14107 if (current_low
!= ((CORE_ADDR
) -1))
14109 best_low
= std::min (best_low
, current_low
);
14110 best_high
= std::max (best_high
, current_high
);
14118 child
= child
->sibling
;
14123 *highpc
= best_high
;
14126 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14130 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14131 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14133 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14134 struct gdbarch
*gdbarch
= objfile
->arch ();
14135 struct attribute
*attr
;
14136 struct attribute
*attr_high
;
14138 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14141 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14142 if (attr
!= nullptr)
14144 CORE_ADDR low
= attr
->as_address ();
14145 CORE_ADDR high
= attr_high
->as_address ();
14147 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14150 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14151 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14152 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14156 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14157 if (attr
!= nullptr && attr
->form_is_unsigned ())
14159 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14160 on DWARF version). */
14161 ULONGEST ranges_offset
= attr
->as_unsigned ();
14163 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14165 if (die
->tag
!= DW_TAG_compile_unit
)
14166 ranges_offset
+= cu
->gnu_ranges_base
;
14168 std::vector
<blockrange
> blockvec
;
14169 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14170 [&] (CORE_ADDR start
, CORE_ADDR end
)
14174 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14175 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14176 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14177 blockvec
.emplace_back (start
, end
);
14180 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14184 /* Check whether the producer field indicates either of GCC < 4.6, or the
14185 Intel C/C++ compiler, and cache the result in CU. */
14188 check_producer (struct dwarf2_cu
*cu
)
14192 if (cu
->producer
== NULL
)
14194 /* For unknown compilers expect their behavior is DWARF version
14197 GCC started to support .debug_types sections by -gdwarf-4 since
14198 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14199 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14200 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14201 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14203 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14205 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14206 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14208 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14210 cu
->producer_is_icc
= true;
14211 cu
->producer_is_icc_lt_14
= major
< 14;
14213 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14214 cu
->producer_is_codewarrior
= true;
14217 /* For other non-GCC compilers, expect their behavior is DWARF version
14221 cu
->checked_producer
= true;
14224 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14225 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14226 during 4.6.0 experimental. */
14229 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14231 if (!cu
->checked_producer
)
14232 check_producer (cu
);
14234 return cu
->producer_is_gxx_lt_4_6
;
14238 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14239 with incorrect is_stmt attributes. */
14242 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14244 if (!cu
->checked_producer
)
14245 check_producer (cu
);
14247 return cu
->producer_is_codewarrior
;
14250 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14251 If that attribute is not available, return the appropriate
14254 static enum dwarf_access_attribute
14255 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14257 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14258 if (attr
!= nullptr)
14260 LONGEST value
= attr
->constant_value (-1);
14261 if (value
== DW_ACCESS_public
14262 || value
== DW_ACCESS_protected
14263 || value
== DW_ACCESS_private
)
14264 return (dwarf_access_attribute
) value
;
14265 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14269 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14271 /* The default DWARF 2 accessibility for members is public, the default
14272 accessibility for inheritance is private. */
14274 if (die
->tag
!= DW_TAG_inheritance
)
14275 return DW_ACCESS_public
;
14277 return DW_ACCESS_private
;
14281 /* DWARF 3+ defines the default accessibility a different way. The same
14282 rules apply now for DW_TAG_inheritance as for the members and it only
14283 depends on the container kind. */
14285 if (die
->parent
->tag
== DW_TAG_class_type
)
14286 return DW_ACCESS_private
;
14288 return DW_ACCESS_public
;
14292 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14293 offset. If the attribute was not found return 0, otherwise return
14294 1. If it was found but could not properly be handled, set *OFFSET
14298 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14301 struct attribute
*attr
;
14303 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14308 /* Note that we do not check for a section offset first here.
14309 This is because DW_AT_data_member_location is new in DWARF 4,
14310 so if we see it, we can assume that a constant form is really
14311 a constant and not a section offset. */
14312 if (attr
->form_is_constant ())
14313 *offset
= attr
->constant_value (0);
14314 else if (attr
->form_is_section_offset ())
14315 dwarf2_complex_location_expr_complaint ();
14316 else if (attr
->form_is_block ())
14317 *offset
= decode_locdesc (attr
->as_block (), cu
);
14319 dwarf2_complex_location_expr_complaint ();
14327 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14330 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14331 struct field
*field
)
14333 struct attribute
*attr
;
14335 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14338 if (attr
->form_is_constant ())
14340 LONGEST offset
= attr
->constant_value (0);
14341 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14343 else if (attr
->form_is_section_offset ())
14344 dwarf2_complex_location_expr_complaint ();
14345 else if (attr
->form_is_block ())
14348 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14350 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14353 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14354 struct objfile
*objfile
= per_objfile
->objfile
;
14355 struct dwarf2_locexpr_baton
*dlbaton
14356 = XOBNEW (&objfile
->objfile_obstack
,
14357 struct dwarf2_locexpr_baton
);
14358 dlbaton
->data
= attr
->as_block ()->data
;
14359 dlbaton
->size
= attr
->as_block ()->size
;
14360 /* When using this baton, we want to compute the address
14361 of the field, not the value. This is why
14362 is_reference is set to false here. */
14363 dlbaton
->is_reference
= false;
14364 dlbaton
->per_objfile
= per_objfile
;
14365 dlbaton
->per_cu
= cu
->per_cu
;
14367 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14371 dwarf2_complex_location_expr_complaint ();
14375 /* Add an aggregate field to the field list. */
14378 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14379 struct dwarf2_cu
*cu
)
14381 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14382 struct gdbarch
*gdbarch
= objfile
->arch ();
14383 struct nextfield
*new_field
;
14384 struct attribute
*attr
;
14386 const char *fieldname
= "";
14388 if (die
->tag
== DW_TAG_inheritance
)
14390 fip
->baseclasses
.emplace_back ();
14391 new_field
= &fip
->baseclasses
.back ();
14395 fip
->fields
.emplace_back ();
14396 new_field
= &fip
->fields
.back ();
14399 new_field
->offset
= die
->sect_off
;
14401 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14402 if (new_field
->accessibility
!= DW_ACCESS_public
)
14403 fip
->non_public_fields
= true;
14405 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14406 if (attr
!= nullptr)
14407 new_field
->virtuality
= attr
->as_virtuality ();
14409 new_field
->virtuality
= DW_VIRTUALITY_none
;
14411 fp
= &new_field
->field
;
14413 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14415 /* Data member other than a C++ static data member. */
14417 /* Get type of field. */
14418 fp
->set_type (die_type (die
, cu
));
14420 SET_FIELD_BITPOS (*fp
, 0);
14422 /* Get bit size of field (zero if none). */
14423 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14424 if (attr
!= nullptr)
14426 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14430 FIELD_BITSIZE (*fp
) = 0;
14433 /* Get bit offset of field. */
14434 handle_data_member_location (die
, cu
, fp
);
14435 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14436 if (attr
!= nullptr && attr
->form_is_constant ())
14438 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14440 /* For big endian bits, the DW_AT_bit_offset gives the
14441 additional bit offset from the MSB of the containing
14442 anonymous object to the MSB of the field. We don't
14443 have to do anything special since we don't need to
14444 know the size of the anonymous object. */
14445 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14446 + attr
->constant_value (0)));
14450 /* For little endian bits, compute the bit offset to the
14451 MSB of the anonymous object, subtract off the number of
14452 bits from the MSB of the field to the MSB of the
14453 object, and then subtract off the number of bits of
14454 the field itself. The result is the bit offset of
14455 the LSB of the field. */
14456 int anonymous_size
;
14457 int bit_offset
= attr
->constant_value (0);
14459 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14460 if (attr
!= nullptr && attr
->form_is_constant ())
14462 /* The size of the anonymous object containing
14463 the bit field is explicit, so use the
14464 indicated size (in bytes). */
14465 anonymous_size
= attr
->constant_value (0);
14469 /* The size of the anonymous object containing
14470 the bit field must be inferred from the type
14471 attribute of the data member containing the
14473 anonymous_size
= TYPE_LENGTH (fp
->type ());
14475 SET_FIELD_BITPOS (*fp
,
14476 (FIELD_BITPOS (*fp
)
14477 + anonymous_size
* bits_per_byte
14478 - bit_offset
- FIELD_BITSIZE (*fp
)));
14481 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14483 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14484 + attr
->constant_value (0)));
14486 /* Get name of field. */
14487 fieldname
= dwarf2_name (die
, cu
);
14488 if (fieldname
== NULL
)
14491 /* The name is already allocated along with this objfile, so we don't
14492 need to duplicate it for the type. */
14493 fp
->name
= fieldname
;
14495 /* Change accessibility for artificial fields (e.g. virtual table
14496 pointer or virtual base class pointer) to private. */
14497 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14499 FIELD_ARTIFICIAL (*fp
) = 1;
14500 new_field
->accessibility
= DW_ACCESS_private
;
14501 fip
->non_public_fields
= true;
14504 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14506 /* C++ static member. */
14508 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14509 is a declaration, but all versions of G++ as of this writing
14510 (so through at least 3.2.1) incorrectly generate
14511 DW_TAG_variable tags. */
14513 const char *physname
;
14515 /* Get name of field. */
14516 fieldname
= dwarf2_name (die
, cu
);
14517 if (fieldname
== NULL
)
14520 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14522 /* Only create a symbol if this is an external value.
14523 new_symbol checks this and puts the value in the global symbol
14524 table, which we want. If it is not external, new_symbol
14525 will try to put the value in cu->list_in_scope which is wrong. */
14526 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14528 /* A static const member, not much different than an enum as far as
14529 we're concerned, except that we can support more types. */
14530 new_symbol (die
, NULL
, cu
);
14533 /* Get physical name. */
14534 physname
= dwarf2_physname (fieldname
, die
, cu
);
14536 /* The name is already allocated along with this objfile, so we don't
14537 need to duplicate it for the type. */
14538 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14539 fp
->set_type (die_type (die
, cu
));
14540 FIELD_NAME (*fp
) = fieldname
;
14542 else if (die
->tag
== DW_TAG_inheritance
)
14544 /* C++ base class field. */
14545 handle_data_member_location (die
, cu
, fp
);
14546 FIELD_BITSIZE (*fp
) = 0;
14547 fp
->set_type (die_type (die
, cu
));
14548 FIELD_NAME (*fp
) = fp
->type ()->name ();
14551 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14554 /* Can the type given by DIE define another type? */
14557 type_can_define_types (const struct die_info
*die
)
14561 case DW_TAG_typedef
:
14562 case DW_TAG_class_type
:
14563 case DW_TAG_structure_type
:
14564 case DW_TAG_union_type
:
14565 case DW_TAG_enumeration_type
:
14573 /* Add a type definition defined in the scope of the FIP's class. */
14576 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14577 struct dwarf2_cu
*cu
)
14579 struct decl_field fp
;
14580 memset (&fp
, 0, sizeof (fp
));
14582 gdb_assert (type_can_define_types (die
));
14584 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14585 fp
.name
= dwarf2_name (die
, cu
);
14586 fp
.type
= read_type_die (die
, cu
);
14588 /* Save accessibility. */
14589 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14590 switch (accessibility
)
14592 case DW_ACCESS_public
:
14593 /* The assumed value if neither private nor protected. */
14595 case DW_ACCESS_private
:
14598 case DW_ACCESS_protected
:
14599 fp
.is_protected
= 1;
14603 if (die
->tag
== DW_TAG_typedef
)
14604 fip
->typedef_field_list
.push_back (fp
);
14606 fip
->nested_types_list
.push_back (fp
);
14609 /* A convenience typedef that's used when finding the discriminant
14610 field for a variant part. */
14611 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14614 /* Compute the discriminant range for a given variant. OBSTACK is
14615 where the results will be stored. VARIANT is the variant to
14616 process. IS_UNSIGNED indicates whether the discriminant is signed
14619 static const gdb::array_view
<discriminant_range
>
14620 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14623 std::vector
<discriminant_range
> ranges
;
14625 if (variant
.default_branch
)
14628 if (variant
.discr_list_data
== nullptr)
14630 discriminant_range r
14631 = {variant
.discriminant_value
, variant
.discriminant_value
};
14632 ranges
.push_back (r
);
14636 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14637 variant
.discr_list_data
->size
);
14638 while (!data
.empty ())
14640 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14642 complaint (_("invalid discriminant marker: %d"), data
[0]);
14645 bool is_range
= data
[0] == DW_DSC_range
;
14646 data
= data
.slice (1);
14648 ULONGEST low
, high
;
14649 unsigned int bytes_read
;
14653 complaint (_("DW_AT_discr_list missing low value"));
14657 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14659 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14661 data
= data
.slice (bytes_read
);
14667 complaint (_("DW_AT_discr_list missing high value"));
14671 high
= read_unsigned_leb128 (nullptr, data
.data (),
14674 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14676 data
= data
.slice (bytes_read
);
14681 ranges
.push_back ({ low
, high
});
14685 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14687 std::copy (ranges
.begin (), ranges
.end (), result
);
14688 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14691 static const gdb::array_view
<variant_part
> create_variant_parts
14692 (struct obstack
*obstack
,
14693 const offset_map_type
&offset_map
,
14694 struct field_info
*fi
,
14695 const std::vector
<variant_part_builder
> &variant_parts
);
14697 /* Fill in a "struct variant" for a given variant field. RESULT is
14698 the variant to fill in. OBSTACK is where any needed allocations
14699 will be done. OFFSET_MAP holds the mapping from section offsets to
14700 fields for the type. FI describes the fields of the type we're
14701 processing. FIELD is the variant field we're converting. */
14704 create_one_variant (variant
&result
, struct obstack
*obstack
,
14705 const offset_map_type
&offset_map
,
14706 struct field_info
*fi
, const variant_field
&field
)
14708 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14709 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14710 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14711 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14712 field
.variant_parts
);
14715 /* Fill in a "struct variant_part" for a given variant part. RESULT
14716 is the variant part to fill in. OBSTACK is where any needed
14717 allocations will be done. OFFSET_MAP holds the mapping from
14718 section offsets to fields for the type. FI describes the fields of
14719 the type we're processing. BUILDER is the variant part to be
14723 create_one_variant_part (variant_part
&result
,
14724 struct obstack
*obstack
,
14725 const offset_map_type
&offset_map
,
14726 struct field_info
*fi
,
14727 const variant_part_builder
&builder
)
14729 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14730 if (iter
== offset_map
.end ())
14732 result
.discriminant_index
= -1;
14733 /* Doesn't matter. */
14734 result
.is_unsigned
= false;
14738 result
.discriminant_index
= iter
->second
;
14740 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
14743 size_t n
= builder
.variants
.size ();
14744 variant
*output
= new (obstack
) variant
[n
];
14745 for (size_t i
= 0; i
< n
; ++i
)
14746 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
14747 builder
.variants
[i
]);
14749 result
.variants
= gdb::array_view
<variant
> (output
, n
);
14752 /* Create a vector of variant parts that can be attached to a type.
14753 OBSTACK is where any needed allocations will be done. OFFSET_MAP
14754 holds the mapping from section offsets to fields for the type. FI
14755 describes the fields of the type we're processing. VARIANT_PARTS
14756 is the vector to convert. */
14758 static const gdb::array_view
<variant_part
>
14759 create_variant_parts (struct obstack
*obstack
,
14760 const offset_map_type
&offset_map
,
14761 struct field_info
*fi
,
14762 const std::vector
<variant_part_builder
> &variant_parts
)
14764 if (variant_parts
.empty ())
14767 size_t n
= variant_parts
.size ();
14768 variant_part
*result
= new (obstack
) variant_part
[n
];
14769 for (size_t i
= 0; i
< n
; ++i
)
14770 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
14773 return gdb::array_view
<variant_part
> (result
, n
);
14776 /* Compute the variant part vector for FIP, attaching it to TYPE when
14780 add_variant_property (struct field_info
*fip
, struct type
*type
,
14781 struct dwarf2_cu
*cu
)
14783 /* Map section offsets of fields to their field index. Note the
14784 field index here does not take the number of baseclasses into
14786 offset_map_type offset_map
;
14787 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
14788 offset_map
[fip
->fields
[i
].offset
] = i
;
14790 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14791 gdb::array_view
<variant_part
> parts
14792 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
14793 fip
->variant_parts
);
14795 struct dynamic_prop prop
;
14796 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
14797 obstack_copy (&objfile
->objfile_obstack
, &parts
,
14800 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
14803 /* Create the vector of fields, and attach it to the type. */
14806 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14807 struct dwarf2_cu
*cu
)
14809 int nfields
= fip
->nfields ();
14811 /* Record the field count, allocate space for the array of fields,
14812 and create blank accessibility bitfields if necessary. */
14813 type
->set_num_fields (nfields
);
14815 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
14817 if (fip
->non_public_fields
&& cu
->per_cu
->lang
!= language_ada
)
14819 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14821 TYPE_FIELD_PRIVATE_BITS (type
) =
14822 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14823 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14825 TYPE_FIELD_PROTECTED_BITS (type
) =
14826 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14827 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14829 TYPE_FIELD_IGNORE_BITS (type
) =
14830 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14831 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14834 /* If the type has baseclasses, allocate and clear a bit vector for
14835 TYPE_FIELD_VIRTUAL_BITS. */
14836 if (!fip
->baseclasses
.empty () && cu
->per_cu
->lang
!= language_ada
)
14838 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14839 unsigned char *pointer
;
14841 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14842 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14843 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14844 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14845 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14848 if (!fip
->variant_parts
.empty ())
14849 add_variant_property (fip
, type
, cu
);
14851 /* Copy the saved-up fields into the field vector. */
14852 for (int i
= 0; i
< nfields
; ++i
)
14854 struct nextfield
&field
14855 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14856 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14858 type
->field (i
) = field
.field
;
14859 switch (field
.accessibility
)
14861 case DW_ACCESS_private
:
14862 if (cu
->per_cu
->lang
!= language_ada
)
14863 SET_TYPE_FIELD_PRIVATE (type
, i
);
14866 case DW_ACCESS_protected
:
14867 if (cu
->per_cu
->lang
!= language_ada
)
14868 SET_TYPE_FIELD_PROTECTED (type
, i
);
14871 case DW_ACCESS_public
:
14875 /* Unknown accessibility. Complain and treat it as public. */
14877 complaint (_("unsupported accessibility %d"),
14878 field
.accessibility
);
14882 if (i
< fip
->baseclasses
.size ())
14884 switch (field
.virtuality
)
14886 case DW_VIRTUALITY_virtual
:
14887 case DW_VIRTUALITY_pure_virtual
:
14888 if (cu
->per_cu
->lang
== language_ada
)
14889 error (_("unexpected virtuality in component of Ada type"));
14890 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14897 /* Return true if this member function is a constructor, false
14901 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14903 const char *fieldname
;
14904 const char *type_name
;
14907 if (die
->parent
== NULL
)
14910 if (die
->parent
->tag
!= DW_TAG_structure_type
14911 && die
->parent
->tag
!= DW_TAG_union_type
14912 && die
->parent
->tag
!= DW_TAG_class_type
)
14915 fieldname
= dwarf2_name (die
, cu
);
14916 type_name
= dwarf2_name (die
->parent
, cu
);
14917 if (fieldname
== NULL
|| type_name
== NULL
)
14920 len
= strlen (fieldname
);
14921 return (strncmp (fieldname
, type_name
, len
) == 0
14922 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14925 /* Add a member function to the proper fieldlist. */
14928 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14929 struct type
*type
, struct dwarf2_cu
*cu
)
14931 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14932 struct attribute
*attr
;
14934 struct fnfieldlist
*flp
= nullptr;
14935 struct fn_field
*fnp
;
14936 const char *fieldname
;
14937 struct type
*this_type
;
14939 if (cu
->per_cu
->lang
== language_ada
)
14940 error (_("unexpected member function in Ada type"));
14942 /* Get name of member function. */
14943 fieldname
= dwarf2_name (die
, cu
);
14944 if (fieldname
== NULL
)
14947 /* Look up member function name in fieldlist. */
14948 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14950 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14952 flp
= &fip
->fnfieldlists
[i
];
14957 /* Create a new fnfieldlist if necessary. */
14958 if (flp
== nullptr)
14960 fip
->fnfieldlists
.emplace_back ();
14961 flp
= &fip
->fnfieldlists
.back ();
14962 flp
->name
= fieldname
;
14963 i
= fip
->fnfieldlists
.size () - 1;
14966 /* Create a new member function field and add it to the vector of
14968 flp
->fnfields
.emplace_back ();
14969 fnp
= &flp
->fnfields
.back ();
14971 /* Delay processing of the physname until later. */
14972 if (cu
->per_cu
->lang
== language_cplus
)
14973 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14977 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14978 fnp
->physname
= physname
? physname
: "";
14981 fnp
->type
= alloc_type (objfile
);
14982 this_type
= read_type_die (die
, cu
);
14983 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
14985 int nparams
= this_type
->num_fields ();
14987 /* TYPE is the domain of this method, and THIS_TYPE is the type
14988 of the method itself (TYPE_CODE_METHOD). */
14989 smash_to_method_type (fnp
->type
, type
,
14990 TYPE_TARGET_TYPE (this_type
),
14991 this_type
->fields (),
14992 this_type
->num_fields (),
14993 this_type
->has_varargs ());
14995 /* Handle static member functions.
14996 Dwarf2 has no clean way to discern C++ static and non-static
14997 member functions. G++ helps GDB by marking the first
14998 parameter for non-static member functions (which is the this
14999 pointer) as artificial. We obtain this information from
15000 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15001 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15002 fnp
->voffset
= VOFFSET_STATIC
;
15005 complaint (_("member function type missing for '%s'"),
15006 dwarf2_full_name (fieldname
, die
, cu
));
15008 /* Get fcontext from DW_AT_containing_type if present. */
15009 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15010 fnp
->fcontext
= die_containing_type (die
, cu
);
15012 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15013 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15015 /* Get accessibility. */
15016 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15017 switch (accessibility
)
15019 case DW_ACCESS_private
:
15020 fnp
->is_private
= 1;
15022 case DW_ACCESS_protected
:
15023 fnp
->is_protected
= 1;
15027 /* Check for artificial methods. */
15028 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15029 if (attr
&& attr
->as_boolean ())
15030 fnp
->is_artificial
= 1;
15032 /* Check for defaulted methods. */
15033 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15034 if (attr
!= nullptr)
15035 fnp
->defaulted
= attr
->defaulted ();
15037 /* Check for deleted methods. */
15038 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15039 if (attr
!= nullptr && attr
->as_boolean ())
15040 fnp
->is_deleted
= 1;
15042 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15044 /* Get index in virtual function table if it is a virtual member
15045 function. For older versions of GCC, this is an offset in the
15046 appropriate virtual table, as specified by DW_AT_containing_type.
15047 For everyone else, it is an expression to be evaluated relative
15048 to the object address. */
15050 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15051 if (attr
!= nullptr)
15053 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15055 struct dwarf_block
*block
= attr
->as_block ();
15057 if (block
->data
[0] == DW_OP_constu
)
15059 /* Old-style GCC. */
15060 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15062 else if (block
->data
[0] == DW_OP_deref
15063 || (block
->size
> 1
15064 && block
->data
[0] == DW_OP_deref_size
15065 && block
->data
[1] == cu
->header
.addr_size
))
15067 fnp
->voffset
= decode_locdesc (block
, cu
);
15068 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15069 dwarf2_complex_location_expr_complaint ();
15071 fnp
->voffset
/= cu
->header
.addr_size
;
15075 dwarf2_complex_location_expr_complaint ();
15077 if (!fnp
->fcontext
)
15079 /* If there is no `this' field and no DW_AT_containing_type,
15080 we cannot actually find a base class context for the
15082 if (this_type
->num_fields () == 0
15083 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15085 complaint (_("cannot determine context for virtual member "
15086 "function \"%s\" (offset %s)"),
15087 fieldname
, sect_offset_str (die
->sect_off
));
15092 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15096 else if (attr
->form_is_section_offset ())
15098 dwarf2_complex_location_expr_complaint ();
15102 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15108 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15109 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15111 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15112 complaint (_("Member function \"%s\" (offset %s) is virtual "
15113 "but the vtable offset is not specified"),
15114 fieldname
, sect_offset_str (die
->sect_off
));
15115 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15116 TYPE_CPLUS_DYNAMIC (type
) = 1;
15121 /* Create the vector of member function fields, and attach it to the type. */
15124 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15125 struct dwarf2_cu
*cu
)
15127 if (cu
->per_cu
->lang
== language_ada
)
15128 error (_("unexpected member functions in Ada type"));
15130 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15131 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15133 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15135 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15137 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15138 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15140 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15141 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15142 fn_flp
->fn_fields
= (struct fn_field
*)
15143 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15145 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15146 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15149 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15152 /* Returns non-zero if NAME is the name of a vtable member in CU's
15153 language, zero otherwise. */
15155 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15157 static const char vptr
[] = "_vptr";
15159 /* Look for the C++ form of the vtable. */
15160 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15166 /* GCC outputs unnamed structures that are really pointers to member
15167 functions, with the ABI-specified layout. If TYPE describes
15168 such a structure, smash it into a member function type.
15170 GCC shouldn't do this; it should just output pointer to member DIEs.
15171 This is GCC PR debug/28767. */
15174 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15176 struct type
*pfn_type
, *self_type
, *new_type
;
15178 /* Check for a structure with no name and two children. */
15179 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15182 /* Check for __pfn and __delta members. */
15183 if (TYPE_FIELD_NAME (type
, 0) == NULL
15184 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15185 || TYPE_FIELD_NAME (type
, 1) == NULL
15186 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15189 /* Find the type of the method. */
15190 pfn_type
= type
->field (0).type ();
15191 if (pfn_type
== NULL
15192 || pfn_type
->code () != TYPE_CODE_PTR
15193 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15196 /* Look for the "this" argument. */
15197 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15198 if (pfn_type
->num_fields () == 0
15199 /* || pfn_type->field (0).type () == NULL */
15200 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15203 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15204 new_type
= alloc_type (objfile
);
15205 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15206 pfn_type
->fields (), pfn_type
->num_fields (),
15207 pfn_type
->has_varargs ());
15208 smash_to_methodptr_type (type
, new_type
);
15211 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15212 requires rewriting, then copy it and return the updated copy.
15213 Otherwise return nullptr. */
15215 static struct type
*
15216 rewrite_array_type (struct type
*type
)
15218 if (type
->code () != TYPE_CODE_ARRAY
)
15221 struct type
*index_type
= type
->index_type ();
15222 range_bounds
*current_bounds
= index_type
->bounds ();
15224 /* Handle multi-dimensional arrays. */
15225 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15226 if (new_target
== nullptr)
15228 /* Maybe we don't need to rewrite this array. */
15229 if (current_bounds
->low
.kind () == PROP_CONST
15230 && current_bounds
->high
.kind () == PROP_CONST
)
15234 /* Either the target type was rewritten, or the bounds have to be
15235 updated. Either way we want to copy the type and update
15237 struct type
*copy
= copy_type (type
);
15238 int nfields
= copy
->num_fields ();
15240 = ((struct field
*) TYPE_ZALLOC (copy
,
15241 nfields
* sizeof (struct field
)));
15242 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15243 copy
->set_fields (new_fields
);
15244 if (new_target
!= nullptr)
15245 TYPE_TARGET_TYPE (copy
) = new_target
;
15247 struct type
*index_copy
= copy_type (index_type
);
15248 range_bounds
*bounds
15249 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15250 sizeof (range_bounds
));
15251 *bounds
= *current_bounds
;
15252 bounds
->low
.set_const_val (1);
15253 bounds
->high
.set_const_val (0);
15254 index_copy
->set_bounds (bounds
);
15255 copy
->set_index_type (index_copy
);
15260 /* While some versions of GCC will generate complicated DWARF for an
15261 array (see quirk_ada_thick_pointer), more recent versions were
15262 modified to emit an explicit thick pointer structure. However, in
15263 this case, the array still has DWARF expressions for its ranges,
15264 and these must be ignored. */
15267 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15270 gdb_assert (cu
->per_cu
->lang
== language_ada
);
15272 /* Check for a structure with two children. */
15273 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15276 /* Check for P_ARRAY and P_BOUNDS members. */
15277 if (TYPE_FIELD_NAME (type
, 0) == NULL
15278 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15279 || TYPE_FIELD_NAME (type
, 1) == NULL
15280 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15283 /* Make sure we're looking at a pointer to an array. */
15284 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15287 /* The Ada code already knows how to handle these types, so all that
15288 we need to do is turn the bounds into static bounds. However, we
15289 don't want to rewrite existing array or index types in-place,
15290 because those may be referenced in other contexts where this
15291 rewriting is undesirable. */
15292 struct type
*new_ary_type
15293 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15294 if (new_ary_type
!= nullptr)
15295 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15298 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15299 appropriate error checking and issuing complaints if there is a
15303 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15305 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15307 if (attr
== nullptr)
15310 if (!attr
->form_is_constant ())
15312 complaint (_("DW_AT_alignment must have constant form"
15313 " - DIE at %s [in module %s]"),
15314 sect_offset_str (die
->sect_off
),
15315 objfile_name (cu
->per_objfile
->objfile
));
15319 LONGEST val
= attr
->constant_value (0);
15322 complaint (_("DW_AT_alignment value must not be negative"
15323 " - DIE at %s [in module %s]"),
15324 sect_offset_str (die
->sect_off
),
15325 objfile_name (cu
->per_objfile
->objfile
));
15328 ULONGEST align
= val
;
15332 complaint (_("DW_AT_alignment value must not be zero"
15333 " - DIE at %s [in module %s]"),
15334 sect_offset_str (die
->sect_off
),
15335 objfile_name (cu
->per_objfile
->objfile
));
15338 if ((align
& (align
- 1)) != 0)
15340 complaint (_("DW_AT_alignment value must be a power of 2"
15341 " - DIE at %s [in module %s]"),
15342 sect_offset_str (die
->sect_off
),
15343 objfile_name (cu
->per_objfile
->objfile
));
15350 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15351 the alignment for TYPE. */
15354 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15357 if (!set_type_align (type
, get_alignment (cu
, die
)))
15358 complaint (_("DW_AT_alignment value too large"
15359 " - DIE at %s [in module %s]"),
15360 sect_offset_str (die
->sect_off
),
15361 objfile_name (cu
->per_objfile
->objfile
));
15364 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15365 constant for a type, according to DWARF5 spec, Table 5.5. */
15368 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15373 case DW_CC_pass_by_reference
:
15374 case DW_CC_pass_by_value
:
15378 complaint (_("unrecognized DW_AT_calling_convention value "
15379 "(%s) for a type"), pulongest (value
));
15384 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15385 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15386 also according to GNU-specific values (see include/dwarf2.h). */
15389 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15394 case DW_CC_program
:
15398 case DW_CC_GNU_renesas_sh
:
15399 case DW_CC_GNU_borland_fastcall_i386
:
15400 case DW_CC_GDB_IBM_OpenCL
:
15404 complaint (_("unrecognized DW_AT_calling_convention value "
15405 "(%s) for a subroutine"), pulongest (value
));
15410 /* Called when we find the DIE that starts a structure or union scope
15411 (definition) to create a type for the structure or union. Fill in
15412 the type's name and general properties; the members will not be
15413 processed until process_structure_scope. A symbol table entry for
15414 the type will also not be done until process_structure_scope (assuming
15415 the type has a name).
15417 NOTE: we need to call these functions regardless of whether or not the
15418 DIE has a DW_AT_name attribute, since it might be an anonymous
15419 structure or union. This gets the type entered into our set of
15420 user defined types. */
15422 static struct type
*
15423 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15425 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15427 struct attribute
*attr
;
15430 /* If the definition of this type lives in .debug_types, read that type.
15431 Don't follow DW_AT_specification though, that will take us back up
15432 the chain and we want to go down. */
15433 attr
= die
->attr (DW_AT_signature
);
15434 if (attr
!= nullptr)
15436 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15438 /* The type's CU may not be the same as CU.
15439 Ensure TYPE is recorded with CU in die_type_hash. */
15440 return set_die_type (die
, type
, cu
);
15443 type
= alloc_type (objfile
);
15444 INIT_CPLUS_SPECIFIC (type
);
15446 name
= dwarf2_name (die
, cu
);
15449 if (cu
->per_cu
->lang
== language_cplus
15450 || cu
->per_cu
->lang
== language_d
15451 || cu
->per_cu
->lang
== language_rust
)
15453 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15455 /* dwarf2_full_name might have already finished building the DIE's
15456 type. If so, there is no need to continue. */
15457 if (get_die_type (die
, cu
) != NULL
)
15458 return get_die_type (die
, cu
);
15460 type
->set_name (full_name
);
15464 /* The name is already allocated along with this objfile, so
15465 we don't need to duplicate it for the type. */
15466 type
->set_name (name
);
15470 if (die
->tag
== DW_TAG_structure_type
)
15472 type
->set_code (TYPE_CODE_STRUCT
);
15474 else if (die
->tag
== DW_TAG_union_type
)
15476 type
->set_code (TYPE_CODE_UNION
);
15480 type
->set_code (TYPE_CODE_STRUCT
);
15483 if (cu
->per_cu
->lang
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15484 type
->set_is_declared_class (true);
15486 /* Store the calling convention in the type if it's available in
15487 the die. Otherwise the calling convention remains set to
15488 the default value DW_CC_normal. */
15489 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15490 if (attr
!= nullptr
15491 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15493 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15494 TYPE_CPLUS_CALLING_CONVENTION (type
)
15495 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15498 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15499 if (attr
!= nullptr)
15501 if (attr
->form_is_constant ())
15502 TYPE_LENGTH (type
) = attr
->constant_value (0);
15505 struct dynamic_prop prop
;
15506 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15507 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15508 TYPE_LENGTH (type
) = 0;
15513 TYPE_LENGTH (type
) = 0;
15516 maybe_set_alignment (cu
, die
, type
);
15518 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15520 /* ICC<14 does not output the required DW_AT_declaration on
15521 incomplete types, but gives them a size of zero. */
15522 type
->set_is_stub (true);
15525 type
->set_stub_is_supported (true);
15527 if (die_is_declaration (die
, cu
))
15528 type
->set_is_stub (true);
15529 else if (attr
== NULL
&& die
->child
== NULL
15530 && producer_is_realview (cu
->producer
))
15531 /* RealView does not output the required DW_AT_declaration
15532 on incomplete types. */
15533 type
->set_is_stub (true);
15535 /* We need to add the type field to the die immediately so we don't
15536 infinitely recurse when dealing with pointers to the structure
15537 type within the structure itself. */
15538 set_die_type (die
, type
, cu
);
15540 /* set_die_type should be already done. */
15541 set_descriptive_type (type
, die
, cu
);
15546 static void handle_struct_member_die
15547 (struct die_info
*child_die
,
15549 struct field_info
*fi
,
15550 std::vector
<struct symbol
*> *template_args
,
15551 struct dwarf2_cu
*cu
);
15553 /* A helper for handle_struct_member_die that handles
15554 DW_TAG_variant_part. */
15557 handle_variant_part (struct die_info
*die
, struct type
*type
,
15558 struct field_info
*fi
,
15559 std::vector
<struct symbol
*> *template_args
,
15560 struct dwarf2_cu
*cu
)
15562 variant_part_builder
*new_part
;
15563 if (fi
->current_variant_part
== nullptr)
15565 fi
->variant_parts
.emplace_back ();
15566 new_part
= &fi
->variant_parts
.back ();
15568 else if (!fi
->current_variant_part
->processing_variant
)
15570 complaint (_("nested DW_TAG_variant_part seen "
15571 "- DIE at %s [in module %s]"),
15572 sect_offset_str (die
->sect_off
),
15573 objfile_name (cu
->per_objfile
->objfile
));
15578 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15579 current
.variant_parts
.emplace_back ();
15580 new_part
= ¤t
.variant_parts
.back ();
15583 /* When we recurse, we want callees to add to this new variant
15585 scoped_restore save_current_variant_part
15586 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15588 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15591 /* It's a univariant form, an extension we support. */
15593 else if (discr
->form_is_ref ())
15595 struct dwarf2_cu
*target_cu
= cu
;
15596 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15598 new_part
->discriminant_offset
= target_die
->sect_off
;
15602 complaint (_("DW_AT_discr does not have DIE reference form"
15603 " - DIE at %s [in module %s]"),
15604 sect_offset_str (die
->sect_off
),
15605 objfile_name (cu
->per_objfile
->objfile
));
15608 for (die_info
*child_die
= die
->child
;
15610 child_die
= child_die
->sibling
)
15611 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15614 /* A helper for handle_struct_member_die that handles
15618 handle_variant (struct die_info
*die
, struct type
*type
,
15619 struct field_info
*fi
,
15620 std::vector
<struct symbol
*> *template_args
,
15621 struct dwarf2_cu
*cu
)
15623 if (fi
->current_variant_part
== nullptr)
15625 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15626 "- DIE at %s [in module %s]"),
15627 sect_offset_str (die
->sect_off
),
15628 objfile_name (cu
->per_objfile
->objfile
));
15631 if (fi
->current_variant_part
->processing_variant
)
15633 complaint (_("nested DW_TAG_variant seen "
15634 "- DIE at %s [in module %s]"),
15635 sect_offset_str (die
->sect_off
),
15636 objfile_name (cu
->per_objfile
->objfile
));
15640 scoped_restore save_processing_variant
15641 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15644 fi
->current_variant_part
->variants
.emplace_back ();
15645 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15646 variant
.first_field
= fi
->fields
.size ();
15648 /* In a variant we want to get the discriminant and also add a
15649 field for our sole member child. */
15650 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15651 if (discr
== nullptr || !discr
->form_is_constant ())
15653 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15654 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15655 variant
.default_branch
= true;
15657 variant
.discr_list_data
= discr
->as_block ();
15660 variant
.discriminant_value
= discr
->constant_value (0);
15662 for (die_info
*variant_child
= die
->child
;
15663 variant_child
!= NULL
;
15664 variant_child
= variant_child
->sibling
)
15665 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15667 variant
.last_field
= fi
->fields
.size ();
15670 /* A helper for process_structure_scope that handles a single member
15674 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15675 struct field_info
*fi
,
15676 std::vector
<struct symbol
*> *template_args
,
15677 struct dwarf2_cu
*cu
)
15679 if (child_die
->tag
== DW_TAG_member
15680 || child_die
->tag
== DW_TAG_variable
)
15682 /* NOTE: carlton/2002-11-05: A C++ static data member
15683 should be a DW_TAG_member that is a declaration, but
15684 all versions of G++ as of this writing (so through at
15685 least 3.2.1) incorrectly generate DW_TAG_variable
15686 tags for them instead. */
15687 dwarf2_add_field (fi
, child_die
, cu
);
15689 else if (child_die
->tag
== DW_TAG_subprogram
)
15691 /* Rust doesn't have member functions in the C++ sense.
15692 However, it does emit ordinary functions as children
15693 of a struct DIE. */
15694 if (cu
->per_cu
->lang
== language_rust
)
15695 read_func_scope (child_die
, cu
);
15698 /* C++ member function. */
15699 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15702 else if (child_die
->tag
== DW_TAG_inheritance
)
15704 /* C++ base class field. */
15705 dwarf2_add_field (fi
, child_die
, cu
);
15707 else if (type_can_define_types (child_die
))
15708 dwarf2_add_type_defn (fi
, child_die
, cu
);
15709 else if (child_die
->tag
== DW_TAG_template_type_param
15710 || child_die
->tag
== DW_TAG_template_value_param
)
15712 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15715 template_args
->push_back (arg
);
15717 else if (child_die
->tag
== DW_TAG_variant_part
)
15718 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15719 else if (child_die
->tag
== DW_TAG_variant
)
15720 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15723 /* Finish creating a structure or union type, including filling in
15724 its members and creating a symbol for it. */
15727 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15729 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15730 struct die_info
*child_die
;
15733 type
= get_die_type (die
, cu
);
15735 type
= read_structure_type (die
, cu
);
15737 bool has_template_parameters
= false;
15738 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15740 struct field_info fi
;
15741 std::vector
<struct symbol
*> template_args
;
15743 child_die
= die
->child
;
15745 while (child_die
&& child_die
->tag
)
15747 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15748 child_die
= child_die
->sibling
;
15751 /* Attach template arguments to type. */
15752 if (!template_args
.empty ())
15754 has_template_parameters
= true;
15755 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15756 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15757 TYPE_TEMPLATE_ARGUMENTS (type
)
15758 = XOBNEWVEC (&objfile
->objfile_obstack
,
15760 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15761 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15762 template_args
.data (),
15763 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15764 * sizeof (struct symbol
*)));
15767 /* Attach fields and member functions to the type. */
15768 if (fi
.nfields () > 0)
15769 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15770 if (!fi
.fnfieldlists
.empty ())
15772 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15774 /* Get the type which refers to the base class (possibly this
15775 class itself) which contains the vtable pointer for the current
15776 class from the DW_AT_containing_type attribute. This use of
15777 DW_AT_containing_type is a GNU extension. */
15779 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15781 struct type
*t
= die_containing_type (die
, cu
);
15783 set_type_vptr_basetype (type
, t
);
15788 /* Our own class provides vtbl ptr. */
15789 for (i
= t
->num_fields () - 1;
15790 i
>= TYPE_N_BASECLASSES (t
);
15793 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15795 if (is_vtable_name (fieldname
, cu
))
15797 set_type_vptr_fieldno (type
, i
);
15802 /* Complain if virtual function table field not found. */
15803 if (i
< TYPE_N_BASECLASSES (t
))
15804 complaint (_("virtual function table pointer "
15805 "not found when defining class '%s'"),
15806 type
->name () ? type
->name () : "");
15810 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15813 else if (cu
->producer
15814 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15816 /* The IBM XLC compiler does not provide direct indication
15817 of the containing type, but the vtable pointer is
15818 always named __vfp. */
15822 for (i
= type
->num_fields () - 1;
15823 i
>= TYPE_N_BASECLASSES (type
);
15826 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15828 set_type_vptr_fieldno (type
, i
);
15829 set_type_vptr_basetype (type
, type
);
15836 /* Copy fi.typedef_field_list linked list elements content into the
15837 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15838 if (!fi
.typedef_field_list
.empty ())
15840 int count
= fi
.typedef_field_list
.size ();
15842 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15843 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15844 = ((struct decl_field
*)
15846 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15847 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15849 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15850 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15853 /* Copy fi.nested_types_list linked list elements content into the
15854 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15855 if (!fi
.nested_types_list
.empty ()
15856 && cu
->per_cu
->lang
!= language_ada
)
15858 int count
= fi
.nested_types_list
.size ();
15860 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15861 TYPE_NESTED_TYPES_ARRAY (type
)
15862 = ((struct decl_field
*)
15863 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15864 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15866 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15867 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15871 quirk_gcc_member_function_pointer (type
, objfile
);
15872 if (cu
->per_cu
->lang
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15873 cu
->rust_unions
.push_back (type
);
15874 else if (cu
->per_cu
->lang
== language_ada
)
15875 quirk_ada_thick_pointer_struct (die
, cu
, type
);
15877 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15878 snapshots) has been known to create a die giving a declaration
15879 for a class that has, as a child, a die giving a definition for a
15880 nested class. So we have to process our children even if the
15881 current die is a declaration. Normally, of course, a declaration
15882 won't have any children at all. */
15884 child_die
= die
->child
;
15886 while (child_die
!= NULL
&& child_die
->tag
)
15888 if (child_die
->tag
== DW_TAG_member
15889 || child_die
->tag
== DW_TAG_variable
15890 || child_die
->tag
== DW_TAG_inheritance
15891 || child_die
->tag
== DW_TAG_template_value_param
15892 || child_die
->tag
== DW_TAG_template_type_param
)
15897 process_die (child_die
, cu
);
15899 child_die
= child_die
->sibling
;
15902 /* Do not consider external references. According to the DWARF standard,
15903 these DIEs are identified by the fact that they have no byte_size
15904 attribute, and a declaration attribute. */
15905 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15906 || !die_is_declaration (die
, cu
)
15907 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
15909 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15911 if (has_template_parameters
)
15913 struct symtab
*symtab
;
15914 if (sym
!= nullptr)
15915 symtab
= symbol_symtab (sym
);
15916 else if (cu
->line_header
!= nullptr)
15918 /* Any related symtab will do. */
15920 = cu
->line_header
->file_names ()[0].symtab
;
15925 complaint (_("could not find suitable "
15926 "symtab for template parameter"
15927 " - DIE at %s [in module %s]"),
15928 sect_offset_str (die
->sect_off
),
15929 objfile_name (objfile
));
15932 if (symtab
!= nullptr)
15934 /* Make sure that the symtab is set on the new symbols.
15935 Even though they don't appear in this symtab directly,
15936 other parts of gdb assume that symbols do, and this is
15937 reasonably true. */
15938 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15939 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15945 /* Assuming DIE is an enumeration type, and TYPE is its associated
15946 type, update TYPE using some information only available in DIE's
15947 children. In particular, the fields are computed. */
15950 update_enumeration_type_from_children (struct die_info
*die
,
15952 struct dwarf2_cu
*cu
)
15954 struct die_info
*child_die
;
15955 int unsigned_enum
= 1;
15958 auto_obstack obstack
;
15959 std::vector
<struct field
> fields
;
15961 for (child_die
= die
->child
;
15962 child_die
!= NULL
&& child_die
->tag
;
15963 child_die
= child_die
->sibling
)
15965 struct attribute
*attr
;
15967 const gdb_byte
*bytes
;
15968 struct dwarf2_locexpr_baton
*baton
;
15971 if (child_die
->tag
!= DW_TAG_enumerator
)
15974 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15978 name
= dwarf2_name (child_die
, cu
);
15980 name
= "<anonymous enumerator>";
15982 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15983 &value
, &bytes
, &baton
);
15991 if (count_one_bits_ll (value
) >= 2)
15995 fields
.emplace_back ();
15996 struct field
&field
= fields
.back ();
15997 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
15998 SET_FIELD_ENUMVAL (field
, value
);
16001 if (!fields
.empty ())
16003 type
->set_num_fields (fields
.size ());
16006 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16007 memcpy (type
->fields (), fields
.data (),
16008 sizeof (struct field
) * fields
.size ());
16012 type
->set_is_unsigned (true);
16015 type
->set_is_flag_enum (true);
16018 /* Given a DW_AT_enumeration_type die, set its type. We do not
16019 complete the type's fields yet, or create any symbols. */
16021 static struct type
*
16022 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16024 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16026 struct attribute
*attr
;
16029 /* If the definition of this type lives in .debug_types, read that type.
16030 Don't follow DW_AT_specification though, that will take us back up
16031 the chain and we want to go down. */
16032 attr
= die
->attr (DW_AT_signature
);
16033 if (attr
!= nullptr)
16035 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16037 /* The type's CU may not be the same as CU.
16038 Ensure TYPE is recorded with CU in die_type_hash. */
16039 return set_die_type (die
, type
, cu
);
16042 type
= alloc_type (objfile
);
16044 type
->set_code (TYPE_CODE_ENUM
);
16045 name
= dwarf2_full_name (NULL
, die
, cu
);
16047 type
->set_name (name
);
16049 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16052 struct type
*underlying_type
= die_type (die
, cu
);
16054 TYPE_TARGET_TYPE (type
) = underlying_type
;
16057 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16058 if (attr
!= nullptr)
16060 TYPE_LENGTH (type
) = attr
->constant_value (0);
16064 TYPE_LENGTH (type
) = 0;
16067 maybe_set_alignment (cu
, die
, type
);
16069 /* The enumeration DIE can be incomplete. In Ada, any type can be
16070 declared as private in the package spec, and then defined only
16071 inside the package body. Such types are known as Taft Amendment
16072 Types. When another package uses such a type, an incomplete DIE
16073 may be generated by the compiler. */
16074 if (die_is_declaration (die
, cu
))
16075 type
->set_is_stub (true);
16077 /* If this type has an underlying type that is not a stub, then we
16078 may use its attributes. We always use the "unsigned" attribute
16079 in this situation, because ordinarily we guess whether the type
16080 is unsigned -- but the guess can be wrong and the underlying type
16081 can tell us the reality. However, we defer to a local size
16082 attribute if one exists, because this lets the compiler override
16083 the underlying type if needed. */
16084 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16086 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16087 underlying_type
= check_typedef (underlying_type
);
16089 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16091 if (TYPE_LENGTH (type
) == 0)
16092 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16094 if (TYPE_RAW_ALIGN (type
) == 0
16095 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16096 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16099 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16101 set_die_type (die
, type
, cu
);
16103 /* Finish the creation of this type by using the enum's children.
16104 Note that, as usual, this must come after set_die_type to avoid
16105 infinite recursion when trying to compute the names of the
16107 update_enumeration_type_from_children (die
, type
, cu
);
16112 /* Given a pointer to a die which begins an enumeration, process all
16113 the dies that define the members of the enumeration, and create the
16114 symbol for the enumeration type.
16116 NOTE: We reverse the order of the element list. */
16119 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16121 struct type
*this_type
;
16123 this_type
= get_die_type (die
, cu
);
16124 if (this_type
== NULL
)
16125 this_type
= read_enumeration_type (die
, cu
);
16127 if (die
->child
!= NULL
)
16129 struct die_info
*child_die
;
16132 child_die
= die
->child
;
16133 while (child_die
&& child_die
->tag
)
16135 if (child_die
->tag
!= DW_TAG_enumerator
)
16137 process_die (child_die
, cu
);
16141 name
= dwarf2_name (child_die
, cu
);
16143 new_symbol (child_die
, this_type
, cu
);
16146 child_die
= child_die
->sibling
;
16150 /* If we are reading an enum from a .debug_types unit, and the enum
16151 is a declaration, and the enum is not the signatured type in the
16152 unit, then we do not want to add a symbol for it. Adding a
16153 symbol would in some cases obscure the true definition of the
16154 enum, giving users an incomplete type when the definition is
16155 actually available. Note that we do not want to do this for all
16156 enums which are just declarations, because C++0x allows forward
16157 enum declarations. */
16158 if (cu
->per_cu
->is_debug_types
16159 && die_is_declaration (die
, cu
))
16161 struct signatured_type
*sig_type
;
16163 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16164 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16165 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16169 new_symbol (die
, this_type
, cu
);
16172 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16173 expression for an index type and finds the corresponding field
16174 offset in the hidden "P_BOUNDS" structure. Returns true on success
16175 and updates *FIELD, false if it fails to recognize an
16179 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16180 int *bounds_offset
, struct field
*field
,
16181 struct dwarf2_cu
*cu
)
16183 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16184 if (attr
== nullptr || !attr
->form_is_block ())
16187 const struct dwarf_block
*block
= attr
->as_block ();
16188 const gdb_byte
*start
= block
->data
;
16189 const gdb_byte
*end
= block
->data
+ block
->size
;
16191 /* The expression to recognize generally looks like:
16193 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16194 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16196 However, the second "plus_uconst" may be missing:
16198 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16199 DW_OP_deref_size: 4)
16201 This happens when the field is at the start of the structure.
16203 Also, the final deref may not be sized:
16205 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16208 This happens when the size of the index type happens to be the
16209 same as the architecture's word size. This can occur with or
16210 without the second plus_uconst. */
16212 if (end
- start
< 2)
16214 if (*start
++ != DW_OP_push_object_address
)
16216 if (*start
++ != DW_OP_plus_uconst
)
16219 uint64_t this_bound_off
;
16220 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16221 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16223 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16224 is consistent among all bounds. */
16225 if (*bounds_offset
== -1)
16226 *bounds_offset
= this_bound_off
;
16227 else if (*bounds_offset
!= this_bound_off
)
16230 if (start
== end
|| *start
++ != DW_OP_deref
)
16236 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16238 /* This means an offset of 0. */
16240 else if (*start
++ != DW_OP_plus_uconst
)
16244 /* The size is the parameter to DW_OP_plus_uconst. */
16246 start
= gdb_read_uleb128 (start
, end
, &val
);
16247 if (start
== nullptr)
16249 if ((int) val
!= val
)
16258 if (*start
== DW_OP_deref_size
)
16260 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16261 if (start
== nullptr)
16264 else if (*start
== DW_OP_deref
)
16266 size
= cu
->header
.addr_size
;
16272 SET_FIELD_BITPOS (*field
, 8 * offset
);
16273 if (size
!= TYPE_LENGTH (field
->type ()))
16274 FIELD_BITSIZE (*field
) = 8 * size
;
16279 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16280 some kinds of Ada arrays:
16282 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16283 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16284 <11e0> DW_AT_data_location: 2 byte block: 97 6
16285 (DW_OP_push_object_address; DW_OP_deref)
16286 <11e3> DW_AT_type : <0x1173>
16287 <11e7> DW_AT_sibling : <0x1201>
16288 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16289 <11ec> DW_AT_type : <0x1206>
16290 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16291 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16292 DW_OP_deref_size: 4)
16293 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16294 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16295 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16297 This actually represents a "thick pointer", which is a structure
16298 with two elements: one that is a pointer to the array data, and one
16299 that is a pointer to another structure; this second structure holds
16302 This returns a new type on success, or nullptr if this didn't
16303 recognize the type. */
16305 static struct type
*
16306 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16309 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16310 /* So far we've only seen this with block form. */
16311 if (attr
== nullptr || !attr
->form_is_block ())
16314 /* Note that this will fail if the structure layout is changed by
16315 the compiler. However, we have no good way to recognize some
16316 other layout, because we don't know what expression the compiler
16317 might choose to emit should this happen. */
16318 struct dwarf_block
*blk
= attr
->as_block ();
16320 || blk
->data
[0] != DW_OP_push_object_address
16321 || blk
->data
[1] != DW_OP_deref
)
16324 int bounds_offset
= -1;
16325 int max_align
= -1;
16326 std::vector
<struct field
> range_fields
;
16327 for (struct die_info
*child_die
= die
->child
;
16329 child_die
= child_die
->sibling
)
16331 if (child_die
->tag
== DW_TAG_subrange_type
)
16333 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16335 int this_align
= type_align (underlying
);
16336 if (this_align
> max_align
)
16337 max_align
= this_align
;
16339 range_fields
.emplace_back ();
16340 range_fields
.emplace_back ();
16342 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16343 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16345 lower
.set_type (underlying
);
16346 FIELD_ARTIFICIAL (lower
) = 1;
16348 upper
.set_type (underlying
);
16349 FIELD_ARTIFICIAL (upper
) = 1;
16351 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16352 &bounds_offset
, &lower
, cu
)
16353 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16354 &bounds_offset
, &upper
, cu
))
16359 /* This shouldn't really happen, but double-check that we found
16360 where the bounds are stored. */
16361 if (bounds_offset
== -1)
16364 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16365 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16369 /* Set the name of each field in the bounds. */
16370 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16371 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16372 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16373 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16376 struct type
*bounds
= alloc_type (objfile
);
16377 bounds
->set_code (TYPE_CODE_STRUCT
);
16379 bounds
->set_num_fields (range_fields
.size ());
16381 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16382 * sizeof (struct field
))));
16383 memcpy (bounds
->fields (), range_fields
.data (),
16384 bounds
->num_fields () * sizeof (struct field
));
16386 int last_fieldno
= range_fields
.size () - 1;
16387 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16388 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16389 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16391 /* Rewrite the existing array type in place. Specifically, we
16392 remove any dynamic properties we might have read, and we replace
16393 the index types. */
16394 struct type
*iter
= type
;
16395 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16397 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16398 iter
->main_type
->dyn_prop_list
= nullptr;
16399 iter
->set_index_type
16400 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16401 iter
= TYPE_TARGET_TYPE (iter
);
16404 struct type
*result
= alloc_type (objfile
);
16405 result
->set_code (TYPE_CODE_STRUCT
);
16407 result
->set_num_fields (2);
16409 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16410 * sizeof (struct field
))));
16412 /* The names are chosen to coincide with what the compiler does with
16413 -fgnat-encodings=all, which the Ada code in gdb already
16415 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16416 result
->field (0).set_type (lookup_pointer_type (type
));
16418 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16419 result
->field (1).set_type (lookup_pointer_type (bounds
));
16420 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16422 result
->set_name (type
->name ());
16423 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16424 + TYPE_LENGTH (result
->field (1).type ()));
16429 /* Extract all information from a DW_TAG_array_type DIE and put it in
16430 the DIE's type field. For now, this only handles one dimensional
16433 static struct type
*
16434 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16436 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16437 struct die_info
*child_die
;
16439 struct type
*element_type
, *range_type
, *index_type
;
16440 struct attribute
*attr
;
16442 struct dynamic_prop
*byte_stride_prop
= NULL
;
16443 unsigned int bit_stride
= 0;
16445 element_type
= die_type (die
, cu
);
16447 /* The die_type call above may have already set the type for this DIE. */
16448 type
= get_die_type (die
, cu
);
16452 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16456 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16459 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16460 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16464 complaint (_("unable to read array DW_AT_byte_stride "
16465 " - DIE at %s [in module %s]"),
16466 sect_offset_str (die
->sect_off
),
16467 objfile_name (cu
->per_objfile
->objfile
));
16468 /* Ignore this attribute. We will likely not be able to print
16469 arrays of this type correctly, but there is little we can do
16470 to help if we cannot read the attribute's value. */
16471 byte_stride_prop
= NULL
;
16475 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16477 bit_stride
= attr
->constant_value (0);
16479 /* Irix 6.2 native cc creates array types without children for
16480 arrays with unspecified length. */
16481 if (die
->child
== NULL
)
16483 index_type
= objfile_type (objfile
)->builtin_int
;
16484 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16485 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16486 byte_stride_prop
, bit_stride
);
16487 return set_die_type (die
, type
, cu
);
16490 std::vector
<struct type
*> range_types
;
16491 child_die
= die
->child
;
16492 while (child_die
&& child_die
->tag
)
16494 if (child_die
->tag
== DW_TAG_subrange_type
)
16496 struct type
*child_type
= read_type_die (child_die
, cu
);
16498 if (child_type
!= NULL
)
16500 /* The range type was succesfully read. Save it for the
16501 array type creation. */
16502 range_types
.push_back (child_type
);
16505 child_die
= child_die
->sibling
;
16508 if (range_types
.empty ())
16510 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16511 sect_offset_str (die
->sect_off
),
16512 objfile_name (cu
->per_objfile
->objfile
));
16516 /* Dwarf2 dimensions are output from left to right, create the
16517 necessary array types in backwards order. */
16519 type
= element_type
;
16521 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16525 while (i
< range_types
.size ())
16527 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16528 byte_stride_prop
, bit_stride
);
16530 byte_stride_prop
= nullptr;
16535 size_t ndim
= range_types
.size ();
16538 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16539 byte_stride_prop
, bit_stride
);
16541 byte_stride_prop
= nullptr;
16545 gdb_assert (type
!= element_type
);
16547 /* Understand Dwarf2 support for vector types (like they occur on
16548 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16549 array type. This is not part of the Dwarf2/3 standard yet, but a
16550 custom vendor extension. The main difference between a regular
16551 array and the vector variant is that vectors are passed by value
16553 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16554 if (attr
!= nullptr)
16555 make_vector_type (type
);
16557 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16558 implementation may choose to implement triple vectors using this
16560 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16561 if (attr
!= nullptr && attr
->form_is_unsigned ())
16563 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16564 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16566 complaint (_("DW_AT_byte_size for array type smaller "
16567 "than the total size of elements"));
16570 name
= dwarf2_name (die
, cu
);
16572 type
->set_name (name
);
16574 maybe_set_alignment (cu
, die
, type
);
16576 struct type
*replacement_type
= nullptr;
16577 if (cu
->per_cu
->lang
== language_ada
)
16579 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16580 if (replacement_type
!= nullptr)
16581 type
= replacement_type
;
16584 /* Install the type in the die. */
16585 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16587 /* set_die_type should be already done. */
16588 set_descriptive_type (type
, die
, cu
);
16593 static enum dwarf_array_dim_ordering
16594 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16596 struct attribute
*attr
;
16598 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16600 if (attr
!= nullptr)
16602 LONGEST val
= attr
->constant_value (-1);
16603 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16604 return (enum dwarf_array_dim_ordering
) val
;
16607 /* GNU F77 is a special case, as at 08/2004 array type info is the
16608 opposite order to the dwarf2 specification, but data is still
16609 laid out as per normal fortran.
16611 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16612 version checking. */
16614 if (cu
->per_cu
->lang
== language_fortran
16615 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16617 return DW_ORD_row_major
;
16620 switch (cu
->language_defn
->array_ordering ())
16622 case array_column_major
:
16623 return DW_ORD_col_major
;
16624 case array_row_major
:
16626 return DW_ORD_row_major
;
16630 /* Extract all information from a DW_TAG_set_type DIE and put it in
16631 the DIE's type field. */
16633 static struct type
*
16634 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16636 struct type
*domain_type
, *set_type
;
16637 struct attribute
*attr
;
16639 domain_type
= die_type (die
, cu
);
16641 /* The die_type call above may have already set the type for this DIE. */
16642 set_type
= get_die_type (die
, cu
);
16646 set_type
= create_set_type (NULL
, domain_type
);
16648 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16649 if (attr
!= nullptr && attr
->form_is_unsigned ())
16650 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16652 maybe_set_alignment (cu
, die
, set_type
);
16654 return set_die_type (die
, set_type
, cu
);
16657 /* A helper for read_common_block that creates a locexpr baton.
16658 SYM is the symbol which we are marking as computed.
16659 COMMON_DIE is the DIE for the common block.
16660 COMMON_LOC is the location expression attribute for the common
16662 MEMBER_LOC is the location expression attribute for the particular
16663 member of the common block that we are processing.
16664 CU is the CU from which the above come. */
16667 mark_common_block_symbol_computed (struct symbol
*sym
,
16668 struct die_info
*common_die
,
16669 struct attribute
*common_loc
,
16670 struct attribute
*member_loc
,
16671 struct dwarf2_cu
*cu
)
16673 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16674 struct objfile
*objfile
= per_objfile
->objfile
;
16675 struct dwarf2_locexpr_baton
*baton
;
16677 unsigned int cu_off
;
16678 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16679 LONGEST offset
= 0;
16681 gdb_assert (common_loc
&& member_loc
);
16682 gdb_assert (common_loc
->form_is_block ());
16683 gdb_assert (member_loc
->form_is_block ()
16684 || member_loc
->form_is_constant ());
16686 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16687 baton
->per_objfile
= per_objfile
;
16688 baton
->per_cu
= cu
->per_cu
;
16689 gdb_assert (baton
->per_cu
);
16691 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16693 if (member_loc
->form_is_constant ())
16695 offset
= member_loc
->constant_value (0);
16696 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16699 baton
->size
+= member_loc
->as_block ()->size
;
16701 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16704 *ptr
++ = DW_OP_call4
;
16705 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16706 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16709 if (member_loc
->form_is_constant ())
16711 *ptr
++ = DW_OP_addr
;
16712 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16713 ptr
+= cu
->header
.addr_size
;
16717 /* We have to copy the data here, because DW_OP_call4 will only
16718 use a DW_AT_location attribute. */
16719 struct dwarf_block
*block
= member_loc
->as_block ();
16720 memcpy (ptr
, block
->data
, block
->size
);
16721 ptr
+= block
->size
;
16724 *ptr
++ = DW_OP_plus
;
16725 gdb_assert (ptr
- baton
->data
== baton
->size
);
16727 SYMBOL_LOCATION_BATON (sym
) = baton
;
16728 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16731 /* Create appropriate locally-scoped variables for all the
16732 DW_TAG_common_block entries. Also create a struct common_block
16733 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16734 is used to separate the common blocks name namespace from regular
16738 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16740 struct attribute
*attr
;
16742 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16743 if (attr
!= nullptr)
16745 /* Support the .debug_loc offsets. */
16746 if (attr
->form_is_block ())
16750 else if (attr
->form_is_section_offset ())
16752 dwarf2_complex_location_expr_complaint ();
16757 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16758 "common block member");
16763 if (die
->child
!= NULL
)
16765 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16766 struct die_info
*child_die
;
16767 size_t n_entries
= 0, size
;
16768 struct common_block
*common_block
;
16769 struct symbol
*sym
;
16771 for (child_die
= die
->child
;
16772 child_die
&& child_die
->tag
;
16773 child_die
= child_die
->sibling
)
16776 size
= (sizeof (struct common_block
)
16777 + (n_entries
- 1) * sizeof (struct symbol
*));
16779 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16781 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16782 common_block
->n_entries
= 0;
16784 for (child_die
= die
->child
;
16785 child_die
&& child_die
->tag
;
16786 child_die
= child_die
->sibling
)
16788 /* Create the symbol in the DW_TAG_common_block block in the current
16790 sym
= new_symbol (child_die
, NULL
, cu
);
16793 struct attribute
*member_loc
;
16795 common_block
->contents
[common_block
->n_entries
++] = sym
;
16797 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16801 /* GDB has handled this for a long time, but it is
16802 not specified by DWARF. It seems to have been
16803 emitted by gfortran at least as recently as:
16804 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16805 complaint (_("Variable in common block has "
16806 "DW_AT_data_member_location "
16807 "- DIE at %s [in module %s]"),
16808 sect_offset_str (child_die
->sect_off
),
16809 objfile_name (objfile
));
16811 if (member_loc
->form_is_section_offset ())
16812 dwarf2_complex_location_expr_complaint ();
16813 else if (member_loc
->form_is_constant ()
16814 || member_loc
->form_is_block ())
16816 if (attr
!= nullptr)
16817 mark_common_block_symbol_computed (sym
, die
, attr
,
16821 dwarf2_complex_location_expr_complaint ();
16826 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16827 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16831 /* Create a type for a C++ namespace. */
16833 static struct type
*
16834 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16836 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16837 const char *previous_prefix
, *name
;
16841 /* For extensions, reuse the type of the original namespace. */
16842 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16844 struct die_info
*ext_die
;
16845 struct dwarf2_cu
*ext_cu
= cu
;
16847 ext_die
= dwarf2_extension (die
, &ext_cu
);
16848 type
= read_type_die (ext_die
, ext_cu
);
16850 /* EXT_CU may not be the same as CU.
16851 Ensure TYPE is recorded with CU in die_type_hash. */
16852 return set_die_type (die
, type
, cu
);
16855 name
= namespace_name (die
, &is_anonymous
, cu
);
16857 /* Now build the name of the current namespace. */
16859 previous_prefix
= determine_prefix (die
, cu
);
16860 if (previous_prefix
[0] != '\0')
16861 name
= typename_concat (&objfile
->objfile_obstack
,
16862 previous_prefix
, name
, 0, cu
);
16864 /* Create the type. */
16865 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16867 return set_die_type (die
, type
, cu
);
16870 /* Read a namespace scope. */
16873 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16875 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16878 /* Add a symbol associated to this if we haven't seen the namespace
16879 before. Also, add a using directive if it's an anonymous
16882 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16886 type
= read_type_die (die
, cu
);
16887 new_symbol (die
, type
, cu
);
16889 namespace_name (die
, &is_anonymous
, cu
);
16892 const char *previous_prefix
= determine_prefix (die
, cu
);
16894 std::vector
<const char *> excludes
;
16895 add_using_directive (using_directives (cu
),
16896 previous_prefix
, type
->name (), NULL
,
16897 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16901 if (die
->child
!= NULL
)
16903 struct die_info
*child_die
= die
->child
;
16905 while (child_die
&& child_die
->tag
)
16907 process_die (child_die
, cu
);
16908 child_die
= child_die
->sibling
;
16913 /* Read a Fortran module as type. This DIE can be only a declaration used for
16914 imported module. Still we need that type as local Fortran "use ... only"
16915 declaration imports depend on the created type in determine_prefix. */
16917 static struct type
*
16918 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16920 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16921 const char *module_name
;
16924 module_name
= dwarf2_name (die
, cu
);
16925 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16927 return set_die_type (die
, type
, cu
);
16930 /* Read a Fortran module. */
16933 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16935 struct die_info
*child_die
= die
->child
;
16938 type
= read_type_die (die
, cu
);
16939 new_symbol (die
, type
, cu
);
16941 while (child_die
&& child_die
->tag
)
16943 process_die (child_die
, cu
);
16944 child_die
= child_die
->sibling
;
16948 /* Return the name of the namespace represented by DIE. Set
16949 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16952 static const char *
16953 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16955 struct die_info
*current_die
;
16956 const char *name
= NULL
;
16958 /* Loop through the extensions until we find a name. */
16960 for (current_die
= die
;
16961 current_die
!= NULL
;
16962 current_die
= dwarf2_extension (die
, &cu
))
16964 /* We don't use dwarf2_name here so that we can detect the absence
16965 of a name -> anonymous namespace. */
16966 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16972 /* Is it an anonymous namespace? */
16974 *is_anonymous
= (name
== NULL
);
16976 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16981 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16982 the user defined type vector. */
16984 static struct type
*
16985 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16987 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
16988 struct comp_unit_head
*cu_header
= &cu
->header
;
16990 struct attribute
*attr_byte_size
;
16991 struct attribute
*attr_address_class
;
16992 int byte_size
, addr_class
;
16993 struct type
*target_type
;
16995 target_type
= die_type (die
, cu
);
16997 /* The die_type call above may have already set the type for this DIE. */
16998 type
= get_die_type (die
, cu
);
17002 type
= lookup_pointer_type (target_type
);
17004 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17005 if (attr_byte_size
)
17006 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17008 byte_size
= cu_header
->addr_size
;
17010 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17011 if (attr_address_class
)
17012 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17014 addr_class
= DW_ADDR_none
;
17016 ULONGEST alignment
= get_alignment (cu
, die
);
17018 /* If the pointer size, alignment, or address class is different
17019 than the default, create a type variant marked as such and set
17020 the length accordingly. */
17021 if (TYPE_LENGTH (type
) != byte_size
17022 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17023 && alignment
!= TYPE_RAW_ALIGN (type
))
17024 || addr_class
!= DW_ADDR_none
)
17026 if (gdbarch_address_class_type_flags_p (gdbarch
))
17028 type_instance_flags type_flags
17029 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17031 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17033 type
= make_type_with_address_space (type
, type_flags
);
17035 else if (TYPE_LENGTH (type
) != byte_size
)
17037 complaint (_("invalid pointer size %d"), byte_size
);
17039 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17041 complaint (_("Invalid DW_AT_alignment"
17042 " - DIE at %s [in module %s]"),
17043 sect_offset_str (die
->sect_off
),
17044 objfile_name (cu
->per_objfile
->objfile
));
17048 /* Should we also complain about unhandled address classes? */
17052 TYPE_LENGTH (type
) = byte_size
;
17053 set_type_align (type
, alignment
);
17054 return set_die_type (die
, type
, cu
);
17057 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17058 the user defined type vector. */
17060 static struct type
*
17061 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17064 struct type
*to_type
;
17065 struct type
*domain
;
17067 to_type
= die_type (die
, cu
);
17068 domain
= die_containing_type (die
, cu
);
17070 /* The calls above may have already set the type for this DIE. */
17071 type
= get_die_type (die
, cu
);
17075 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17076 type
= lookup_methodptr_type (to_type
);
17077 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17079 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17081 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17082 to_type
->fields (), to_type
->num_fields (),
17083 to_type
->has_varargs ());
17084 type
= lookup_methodptr_type (new_type
);
17087 type
= lookup_memberptr_type (to_type
, domain
);
17089 return set_die_type (die
, type
, cu
);
17092 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17093 the user defined type vector. */
17095 static struct type
*
17096 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17097 enum type_code refcode
)
17099 struct comp_unit_head
*cu_header
= &cu
->header
;
17100 struct type
*type
, *target_type
;
17101 struct attribute
*attr
;
17103 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17105 target_type
= die_type (die
, cu
);
17107 /* The die_type call above may have already set the type for this DIE. */
17108 type
= get_die_type (die
, cu
);
17112 type
= lookup_reference_type (target_type
, refcode
);
17113 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17114 if (attr
!= nullptr)
17116 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17120 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17122 maybe_set_alignment (cu
, die
, type
);
17123 return set_die_type (die
, type
, cu
);
17126 /* Add the given cv-qualifiers to the element type of the array. GCC
17127 outputs DWARF type qualifiers that apply to an array, not the
17128 element type. But GDB relies on the array element type to carry
17129 the cv-qualifiers. This mimics section 6.7.3 of the C99
17132 static struct type
*
17133 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17134 struct type
*base_type
, int cnst
, int voltl
)
17136 struct type
*el_type
, *inner_array
;
17138 base_type
= copy_type (base_type
);
17139 inner_array
= base_type
;
17141 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17143 TYPE_TARGET_TYPE (inner_array
) =
17144 copy_type (TYPE_TARGET_TYPE (inner_array
));
17145 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17148 el_type
= TYPE_TARGET_TYPE (inner_array
);
17149 cnst
|= TYPE_CONST (el_type
);
17150 voltl
|= TYPE_VOLATILE (el_type
);
17151 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17153 return set_die_type (die
, base_type
, cu
);
17156 static struct type
*
17157 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17159 struct type
*base_type
, *cv_type
;
17161 base_type
= die_type (die
, cu
);
17163 /* The die_type call above may have already set the type for this DIE. */
17164 cv_type
= get_die_type (die
, cu
);
17168 /* In case the const qualifier is applied to an array type, the element type
17169 is so qualified, not the array type (section 6.7.3 of C99). */
17170 if (base_type
->code () == TYPE_CODE_ARRAY
)
17171 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17173 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17174 return set_die_type (die
, cv_type
, cu
);
17177 static struct type
*
17178 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17180 struct type
*base_type
, *cv_type
;
17182 base_type
= die_type (die
, cu
);
17184 /* The die_type call above may have already set the type for this DIE. */
17185 cv_type
= get_die_type (die
, cu
);
17189 /* In case the volatile qualifier is applied to an array type, the
17190 element type is so qualified, not the array type (section 6.7.3
17192 if (base_type
->code () == TYPE_CODE_ARRAY
)
17193 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17195 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17196 return set_die_type (die
, cv_type
, cu
);
17199 /* Handle DW_TAG_restrict_type. */
17201 static struct type
*
17202 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17204 struct type
*base_type
, *cv_type
;
17206 base_type
= die_type (die
, cu
);
17208 /* The die_type call above may have already set the type for this DIE. */
17209 cv_type
= get_die_type (die
, cu
);
17213 cv_type
= make_restrict_type (base_type
);
17214 return set_die_type (die
, cv_type
, cu
);
17217 /* Handle DW_TAG_atomic_type. */
17219 static struct type
*
17220 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17222 struct type
*base_type
, *cv_type
;
17224 base_type
= die_type (die
, cu
);
17226 /* The die_type call above may have already set the type for this DIE. */
17227 cv_type
= get_die_type (die
, cu
);
17231 cv_type
= make_atomic_type (base_type
);
17232 return set_die_type (die
, cv_type
, cu
);
17235 /* Extract all information from a DW_TAG_string_type DIE and add to
17236 the user defined type vector. It isn't really a user defined type,
17237 but it behaves like one, with other DIE's using an AT_user_def_type
17238 attribute to reference it. */
17240 static struct type
*
17241 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17243 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17244 struct gdbarch
*gdbarch
= objfile
->arch ();
17245 struct type
*type
, *range_type
, *index_type
, *char_type
;
17246 struct attribute
*attr
;
17247 struct dynamic_prop prop
;
17248 bool length_is_constant
= true;
17251 /* There are a couple of places where bit sizes might be made use of
17252 when parsing a DW_TAG_string_type, however, no producer that we know
17253 of make use of these. Handling bit sizes that are a multiple of the
17254 byte size is easy enough, but what about other bit sizes? Lets deal
17255 with that problem when we have to. Warn about these attributes being
17256 unsupported, then parse the type and ignore them like we always
17258 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17259 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17261 static bool warning_printed
= false;
17262 if (!warning_printed
)
17264 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17265 "currently supported on DW_TAG_string_type."));
17266 warning_printed
= true;
17270 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17271 if (attr
!= nullptr && !attr
->form_is_constant ())
17273 /* The string length describes the location at which the length of
17274 the string can be found. The size of the length field can be
17275 specified with one of the attributes below. */
17276 struct type
*prop_type
;
17277 struct attribute
*len
17278 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17279 if (len
== nullptr)
17280 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17281 if (len
!= nullptr && len
->form_is_constant ())
17283 /* Pass 0 as the default as we know this attribute is constant
17284 and the default value will not be returned. */
17285 LONGEST sz
= len
->constant_value (0);
17286 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17290 /* If the size is not specified then we assume it is the size of
17291 an address on this target. */
17292 prop_type
= cu
->addr_sized_int_type (true);
17295 /* Convert the attribute into a dynamic property. */
17296 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17299 length_is_constant
= false;
17301 else if (attr
!= nullptr)
17303 /* This DW_AT_string_length just contains the length with no
17304 indirection. There's no need to create a dynamic property in this
17305 case. Pass 0 for the default value as we know it will not be
17306 returned in this case. */
17307 length
= attr
->constant_value (0);
17309 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17311 /* We don't currently support non-constant byte sizes for strings. */
17312 length
= attr
->constant_value (1);
17316 /* Use 1 as a fallback length if we have nothing else. */
17320 index_type
= objfile_type (objfile
)->builtin_int
;
17321 if (length_is_constant
)
17322 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17325 struct dynamic_prop low_bound
;
17327 low_bound
.set_const_val (1);
17328 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17330 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17331 type
= create_string_type (NULL
, char_type
, range_type
);
17333 return set_die_type (die
, type
, cu
);
17336 /* Assuming that DIE corresponds to a function, returns nonzero
17337 if the function is prototyped. */
17340 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17342 struct attribute
*attr
;
17344 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17345 if (attr
&& attr
->as_boolean ())
17348 /* The DWARF standard implies that the DW_AT_prototyped attribute
17349 is only meaningful for C, but the concept also extends to other
17350 languages that allow unprototyped functions (Eg: Objective C).
17351 For all other languages, assume that functions are always
17353 if (cu
->per_cu
->lang
!= language_c
17354 && cu
->per_cu
->lang
!= language_objc
17355 && cu
->per_cu
->lang
!= language_opencl
)
17358 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17359 prototyped and unprototyped functions; default to prototyped,
17360 since that is more common in modern code (and RealView warns
17361 about unprototyped functions). */
17362 if (producer_is_realview (cu
->producer
))
17368 /* Handle DIES due to C code like:
17372 int (*funcp)(int a, long l);
17376 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17378 static struct type
*
17379 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17381 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17382 struct type
*type
; /* Type that this function returns. */
17383 struct type
*ftype
; /* Function that returns above type. */
17384 struct attribute
*attr
;
17386 type
= die_type (die
, cu
);
17388 /* The die_type call above may have already set the type for this DIE. */
17389 ftype
= get_die_type (die
, cu
);
17393 ftype
= lookup_function_type (type
);
17395 if (prototyped_function_p (die
, cu
))
17396 ftype
->set_is_prototyped (true);
17398 /* Store the calling convention in the type if it's available in
17399 the subroutine die. Otherwise set the calling convention to
17400 the default value DW_CC_normal. */
17401 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17402 if (attr
!= nullptr
17403 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17404 TYPE_CALLING_CONVENTION (ftype
)
17405 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17406 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17407 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17409 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17411 /* Record whether the function returns normally to its caller or not
17412 if the DWARF producer set that information. */
17413 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17414 if (attr
&& attr
->as_boolean ())
17415 TYPE_NO_RETURN (ftype
) = 1;
17417 /* We need to add the subroutine type to the die immediately so
17418 we don't infinitely recurse when dealing with parameters
17419 declared as the same subroutine type. */
17420 set_die_type (die
, ftype
, cu
);
17422 if (die
->child
!= NULL
)
17424 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17425 struct die_info
*child_die
;
17426 int nparams
, iparams
;
17428 /* Count the number of parameters.
17429 FIXME: GDB currently ignores vararg functions, but knows about
17430 vararg member functions. */
17432 child_die
= die
->child
;
17433 while (child_die
&& child_die
->tag
)
17435 if (child_die
->tag
== DW_TAG_formal_parameter
)
17437 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17438 ftype
->set_has_varargs (true);
17440 child_die
= child_die
->sibling
;
17443 /* Allocate storage for parameters and fill them in. */
17444 ftype
->set_num_fields (nparams
);
17446 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17448 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17449 even if we error out during the parameters reading below. */
17450 for (iparams
= 0; iparams
< nparams
; iparams
++)
17451 ftype
->field (iparams
).set_type (void_type
);
17454 child_die
= die
->child
;
17455 while (child_die
&& child_die
->tag
)
17457 if (child_die
->tag
== DW_TAG_formal_parameter
)
17459 struct type
*arg_type
;
17461 /* DWARF version 2 has no clean way to discern C++
17462 static and non-static member functions. G++ helps
17463 GDB by marking the first parameter for non-static
17464 member functions (which is the this pointer) as
17465 artificial. We pass this information to
17466 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17468 DWARF version 3 added DW_AT_object_pointer, which GCC
17469 4.5 does not yet generate. */
17470 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17471 if (attr
!= nullptr)
17472 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17474 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17475 arg_type
= die_type (child_die
, cu
);
17477 /* RealView does not mark THIS as const, which the testsuite
17478 expects. GCC marks THIS as const in method definitions,
17479 but not in the class specifications (GCC PR 43053). */
17480 if (cu
->per_cu
->lang
== language_cplus
17481 && !TYPE_CONST (arg_type
)
17482 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17485 struct dwarf2_cu
*arg_cu
= cu
;
17486 const char *name
= dwarf2_name (child_die
, cu
);
17488 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17489 if (attr
!= nullptr)
17491 /* If the compiler emits this, use it. */
17492 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17495 else if (name
&& strcmp (name
, "this") == 0)
17496 /* Function definitions will have the argument names. */
17498 else if (name
== NULL
&& iparams
== 0)
17499 /* Declarations may not have the names, so like
17500 elsewhere in GDB, assume an artificial first
17501 argument is "this". */
17505 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17509 ftype
->field (iparams
).set_type (arg_type
);
17512 child_die
= child_die
->sibling
;
17519 static struct type
*
17520 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17522 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17523 const char *name
= NULL
;
17524 struct type
*this_type
, *target_type
;
17526 name
= dwarf2_full_name (NULL
, die
, cu
);
17527 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17528 this_type
->set_target_is_stub (true);
17529 set_die_type (die
, this_type
, cu
);
17530 target_type
= die_type (die
, cu
);
17531 if (target_type
!= this_type
)
17532 TYPE_TARGET_TYPE (this_type
) = target_type
;
17535 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17536 spec and cause infinite loops in GDB. */
17537 complaint (_("Self-referential DW_TAG_typedef "
17538 "- DIE at %s [in module %s]"),
17539 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17540 TYPE_TARGET_TYPE (this_type
) = NULL
;
17544 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17545 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17546 Handle these by just returning the target type, rather than
17547 constructing an anonymous typedef type and trying to handle this
17549 set_die_type (die
, target_type
, cu
);
17550 return target_type
;
17555 /* Helper for get_dwarf2_rational_constant that computes the value of
17556 a given gmp_mpz given an attribute. */
17559 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17561 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17562 location expression that pushes an implicit value. */
17563 if (attr
->form
== DW_FORM_exprloc
)
17565 dwarf_block
*blk
= attr
->as_block ();
17566 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17569 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17570 blk
->data
+ blk
->size
,
17572 if (ptr
- blk
->data
+ len
<= blk
->size
)
17574 mpz_import (value
->val
, len
,
17575 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17581 /* On failure set it to 1. */
17582 *value
= gdb_mpz (1);
17584 else if (attr
->form_is_block ())
17586 dwarf_block
*blk
= attr
->as_block ();
17587 mpz_import (value
->val
, blk
->size
,
17588 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17589 1, 0, 0, blk
->data
);
17592 *value
= gdb_mpz (attr
->constant_value (1));
17595 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17596 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17598 If the numerator and/or numerator attribute is missing,
17599 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17603 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17604 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17606 struct attribute
*num_attr
, *denom_attr
;
17608 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17609 if (num_attr
== nullptr)
17610 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17611 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17613 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17614 if (denom_attr
== nullptr)
17615 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17616 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17618 if (num_attr
== nullptr || denom_attr
== nullptr)
17621 get_mpz (cu
, numerator
, num_attr
);
17622 get_mpz (cu
, denominator
, denom_attr
);
17625 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17626 rational constant, rather than a signed one.
17628 If the rational constant has a negative value, a complaint
17629 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17632 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17633 struct dwarf2_cu
*cu
,
17634 gdb_mpz
*numerator
,
17635 gdb_mpz
*denominator
)
17640 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17641 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17643 mpz_neg (num
.val
, num
.val
);
17644 mpz_neg (denom
.val
, denom
.val
);
17646 else if (mpz_sgn (num
.val
) == -1)
17648 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17650 sect_offset_str (die
->sect_off
));
17653 else if (mpz_sgn (denom
.val
) == -1)
17655 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17657 sect_offset_str (die
->sect_off
));
17661 *numerator
= std::move (num
);
17662 *denominator
= std::move (denom
);
17665 /* Assuming that ENCODING is a string whose contents starting at the
17666 K'th character is "_nn" where "nn" is a decimal number, scan that
17667 number and set RESULT to the value. K is updated to point to the
17668 character immediately following the number.
17670 If the string does not conform to the format described above, false
17671 is returned, and K may or may not be changed. */
17674 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17676 /* The next character should be an underscore ('_') followed
17678 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17681 /* Skip the underscore. */
17685 /* Determine the number of digits for our number. */
17686 while (isdigit (encoding
[k
]))
17691 std::string
copy (&encoding
[start
], k
- start
);
17692 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17698 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17699 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17700 DENOM, update OFFSET, and return true on success. Return false on
17704 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17705 gdb_mpz
*num
, gdb_mpz
*denom
)
17707 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17709 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17712 /* Assuming DIE corresponds to a fixed point type, finish the creation
17713 of the corresponding TYPE by setting its type-specific data. CU is
17714 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17715 encodings. It is nullptr if the GNAT encoding should be
17719 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17720 struct die_info
*die
, struct dwarf2_cu
*cu
)
17722 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17723 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17725 /* If GNAT encodings are preferred, don't examine the
17727 struct attribute
*attr
= nullptr;
17728 if (suffix
== nullptr)
17730 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17731 if (attr
== nullptr)
17732 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17733 if (attr
== nullptr)
17734 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17737 /* Numerator and denominator of our fixed-point type's scaling factor.
17738 The default is a scaling factor of 1, which we use as a fallback
17739 when we are not able to decode it (problem with the debugging info,
17740 unsupported forms, bug in GDB, etc...). Using that as the default
17741 allows us to at least print the unscaled value, which might still
17742 be useful to a user. */
17743 gdb_mpz
scale_num (1);
17744 gdb_mpz
scale_denom (1);
17746 if (attr
== nullptr)
17749 if (suffix
!= nullptr
17750 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17752 /* The number might be encoded as _nn_dd_nn_dd, where the
17753 second ratio is the 'small value. In this situation, we
17754 want the second value. */
17755 && (suffix
[offset
] != '_'
17756 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
17763 /* Scaling factor not found. Assume a scaling factor of 1,
17764 and hope for the best. At least the user will be able to
17765 see the encoded value. */
17768 complaint (_("no scale found for fixed-point type (DIE at %s)"),
17769 sect_offset_str (die
->sect_off
));
17772 else if (attr
->name
== DW_AT_binary_scale
)
17774 LONGEST scale_exp
= attr
->constant_value (0);
17775 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17777 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
17779 else if (attr
->name
== DW_AT_decimal_scale
)
17781 LONGEST scale_exp
= attr
->constant_value (0);
17782 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
17784 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
17786 else if (attr
->name
== DW_AT_small
)
17788 struct die_info
*scale_die
;
17789 struct dwarf2_cu
*scale_cu
= cu
;
17791 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
17792 if (scale_die
->tag
== DW_TAG_constant
)
17793 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
17794 &scale_num
, &scale_denom
);
17796 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
17798 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17802 complaint (_("unsupported scale attribute %s for fixed-point type"
17804 dwarf_attr_name (attr
->name
),
17805 sect_offset_str (die
->sect_off
));
17808 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
17809 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
17810 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
17811 mpq_canonicalize (scaling_factor
.val
);
17814 /* The gnat-encoding suffix for fixed point. */
17816 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
17818 /* If NAME encodes an Ada fixed-point type, return a pointer to the
17819 "XF" suffix of the name. The text after this is what encodes the
17820 'small and 'delta information. Otherwise, return nullptr. */
17822 static const char *
17823 gnat_encoded_fixed_point_type_info (const char *name
)
17825 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
17828 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17829 (which may be different from NAME) to the architecture back-end to allow
17830 it to guess the correct format if necessary. */
17832 static struct type
*
17833 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17834 const char *name_hint
, enum bfd_endian byte_order
)
17836 struct gdbarch
*gdbarch
= objfile
->arch ();
17837 const struct floatformat
**format
;
17840 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17842 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17844 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17849 /* Allocate an integer type of size BITS and name NAME. */
17851 static struct type
*
17852 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17853 int bits
, int unsigned_p
, const char *name
)
17857 /* Versions of Intel's C Compiler generate an integer type called "void"
17858 instead of using DW_TAG_unspecified_type. This has been seen on
17859 at least versions 14, 17, and 18. */
17860 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17861 && strcmp (name
, "void") == 0)
17862 type
= objfile_type (objfile
)->builtin_void
;
17864 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17869 /* Return true if DIE has a DW_AT_small attribute whose value is
17870 a constant rational, where both the numerator and denominator
17873 CU is the DIE's Compilation Unit. */
17876 has_zero_over_zero_small_attribute (struct die_info
*die
,
17877 struct dwarf2_cu
*cu
)
17879 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17880 if (attr
== nullptr)
17883 struct dwarf2_cu
*scale_cu
= cu
;
17884 struct die_info
*scale_die
17885 = follow_die_ref (die
, attr
, &scale_cu
);
17887 if (scale_die
->tag
!= DW_TAG_constant
)
17890 gdb_mpz
num (1), denom (1);
17891 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
17892 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
17895 /* Initialise and return a floating point type of size BITS suitable for
17896 use as a component of a complex number. The NAME_HINT is passed through
17897 when initialising the floating point type and is the name of the complex
17900 As DWARF doesn't currently provide an explicit name for the components
17901 of a complex number, but it can be helpful to have these components
17902 named, we try to select a suitable name based on the size of the
17904 static struct type
*
17905 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17906 struct objfile
*objfile
,
17907 int bits
, const char *name_hint
,
17908 enum bfd_endian byte_order
)
17910 gdbarch
*gdbarch
= objfile
->arch ();
17911 struct type
*tt
= nullptr;
17913 /* Try to find a suitable floating point builtin type of size BITS.
17914 We're going to use the name of this type as the name for the complex
17915 target type that we are about to create. */
17916 switch (cu
->per_cu
->lang
)
17918 case language_fortran
:
17922 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17925 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17927 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17929 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17937 tt
= builtin_type (gdbarch
)->builtin_float
;
17940 tt
= builtin_type (gdbarch
)->builtin_double
;
17942 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17944 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17950 /* If the type we found doesn't match the size we were looking for, then
17951 pretend we didn't find a type at all, the complex target type we
17952 create will then be nameless. */
17953 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17956 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
17957 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17960 /* Find a representation of a given base type and install
17961 it in the TYPE field of the die. */
17963 static struct type
*
17964 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17966 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17968 struct attribute
*attr
;
17969 int encoding
= 0, bits
= 0;
17973 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17974 if (attr
!= nullptr && attr
->form_is_constant ())
17975 encoding
= attr
->constant_value (0);
17976 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17977 if (attr
!= nullptr)
17978 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
17979 name
= dwarf2_name (die
, cu
);
17981 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17983 arch
= objfile
->arch ();
17984 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17986 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17987 if (attr
!= nullptr && attr
->form_is_constant ())
17989 int endianity
= attr
->constant_value (0);
17994 byte_order
= BFD_ENDIAN_BIG
;
17996 case DW_END_little
:
17997 byte_order
= BFD_ENDIAN_LITTLE
;
18000 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18005 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18006 && cu
->per_cu
->lang
== language_ada
18007 && has_zero_over_zero_small_attribute (die
, cu
))
18009 /* brobecker/2018-02-24: This is a fixed point type for which
18010 the scaling factor is represented as fraction whose value
18011 does not make sense (zero divided by zero), so we should
18012 normally never see these. However, there is a small category
18013 of fixed point types for which GNAT is unable to provide
18014 the scaling factor via the standard DWARF mechanisms, and
18015 for which the info is provided via the GNAT encodings instead.
18016 This is likely what this DIE is about. */
18017 encoding
= (encoding
== DW_ATE_signed_fixed
18019 : DW_ATE_unsigned
);
18022 /* With GNAT encodings, fixed-point information will be encoded in
18023 the type name. Note that this can also occur with the above
18024 zero-over-zero case, which is why this is a separate "if" rather
18025 than an "else if". */
18026 const char *gnat_encoding_suffix
= nullptr;
18027 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18028 && cu
->per_cu
->lang
== language_ada
18029 && name
!= nullptr)
18031 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18032 if (gnat_encoding_suffix
!= nullptr)
18034 gdb_assert (startswith (gnat_encoding_suffix
,
18035 GNAT_FIXED_POINT_SUFFIX
));
18036 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18037 name
, gnat_encoding_suffix
- name
);
18038 /* Use -1 here so that SUFFIX points at the "_" after the
18040 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18042 encoding
= (encoding
== DW_ATE_signed
18043 ? DW_ATE_signed_fixed
18044 : DW_ATE_unsigned_fixed
);
18050 case DW_ATE_address
:
18051 /* Turn DW_ATE_address into a void * pointer. */
18052 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18053 type
= init_pointer_type (objfile
, bits
, name
, type
);
18055 case DW_ATE_boolean
:
18056 type
= init_boolean_type (objfile
, bits
, 1, name
);
18058 case DW_ATE_complex_float
:
18059 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18061 if (type
->code () == TYPE_CODE_ERROR
)
18063 if (name
== nullptr)
18065 struct obstack
*obstack
18066 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18067 name
= obconcat (obstack
, "_Complex ", type
->name (),
18070 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18073 type
= init_complex_type (name
, type
);
18075 case DW_ATE_decimal_float
:
18076 type
= init_decfloat_type (objfile
, bits
, name
);
18079 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18081 case DW_ATE_signed
:
18082 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18084 case DW_ATE_unsigned
:
18085 if (cu
->per_cu
->lang
== language_fortran
18087 && startswith (name
, "character("))
18088 type
= init_character_type (objfile
, bits
, 1, name
);
18090 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18092 case DW_ATE_signed_char
:
18093 if (cu
->per_cu
->lang
== language_ada
18094 || cu
->per_cu
->lang
== language_m2
18095 || cu
->per_cu
->lang
== language_pascal
18096 || cu
->per_cu
->lang
== language_fortran
)
18097 type
= init_character_type (objfile
, bits
, 0, name
);
18099 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18101 case DW_ATE_unsigned_char
:
18102 if (cu
->per_cu
->lang
== language_ada
18103 || cu
->per_cu
->lang
== language_m2
18104 || cu
->per_cu
->lang
== language_pascal
18105 || cu
->per_cu
->lang
== language_fortran
18106 || cu
->per_cu
->lang
== language_rust
)
18107 type
= init_character_type (objfile
, bits
, 1, name
);
18109 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18114 type
= builtin_type (arch
)->builtin_char16
;
18115 else if (bits
== 32)
18116 type
= builtin_type (arch
)->builtin_char32
;
18119 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18121 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18123 return set_die_type (die
, type
, cu
);
18126 case DW_ATE_signed_fixed
:
18127 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18128 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18130 case DW_ATE_unsigned_fixed
:
18131 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18132 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18136 complaint (_("unsupported DW_AT_encoding: '%s'"),
18137 dwarf_type_encoding_name (encoding
));
18138 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18142 if (name
&& strcmp (name
, "char") == 0)
18143 type
->set_has_no_signedness (true);
18145 maybe_set_alignment (cu
, die
, type
);
18147 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18149 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18151 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18152 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18154 unsigned real_bit_size
= attr
->as_unsigned ();
18155 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18156 /* Only use the attributes if they make sense together. */
18157 if (attr
== nullptr
18158 || (attr
->as_unsigned () + real_bit_size
18159 <= 8 * TYPE_LENGTH (type
)))
18161 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18163 if (attr
!= nullptr)
18164 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18165 = attr
->as_unsigned ();
18170 return set_die_type (die
, type
, cu
);
18173 /* A helper function that returns the name of DIE, if it refers to a
18174 variable declaration. */
18176 static const char *
18177 var_decl_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18179 if (die
->tag
!= DW_TAG_variable
)
18182 attribute
*attr
= dwarf2_attr (die
, DW_AT_declaration
, cu
);
18183 if (attr
== nullptr || !attr
->as_boolean ())
18186 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
18187 if (attr
== nullptr)
18189 return attr
->as_string ();
18192 /* Parse dwarf attribute if it's a block, reference or constant and put the
18193 resulting value of the attribute into struct bound_prop.
18194 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18197 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18198 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18199 struct type
*default_type
)
18201 struct dwarf2_property_baton
*baton
;
18202 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18203 struct objfile
*objfile
= per_objfile
->objfile
;
18204 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18206 gdb_assert (default_type
!= NULL
);
18208 if (attr
== NULL
|| prop
== NULL
)
18211 if (attr
->form_is_block ())
18213 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18214 baton
->property_type
= default_type
;
18215 baton
->locexpr
.per_cu
= cu
->per_cu
;
18216 baton
->locexpr
.per_objfile
= per_objfile
;
18218 struct dwarf_block
*block
= attr
->as_block ();
18219 baton
->locexpr
.size
= block
->size
;
18220 baton
->locexpr
.data
= block
->data
;
18221 switch (attr
->name
)
18223 case DW_AT_string_length
:
18224 baton
->locexpr
.is_reference
= true;
18227 baton
->locexpr
.is_reference
= false;
18231 prop
->set_locexpr (baton
);
18232 gdb_assert (prop
->baton () != NULL
);
18234 else if (attr
->form_is_ref ())
18236 struct dwarf2_cu
*target_cu
= cu
;
18237 struct die_info
*target_die
;
18238 struct attribute
*target_attr
;
18240 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18241 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18242 if (target_attr
== NULL
)
18243 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18245 if (target_attr
== NULL
)
18247 const char *name
= var_decl_name (target_die
, target_cu
);
18248 if (name
!= nullptr)
18250 prop
->set_variable_name (name
);
18256 switch (target_attr
->name
)
18258 case DW_AT_location
:
18259 if (target_attr
->form_is_section_offset ())
18261 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18262 baton
->property_type
= die_type (target_die
, target_cu
);
18263 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18264 prop
->set_loclist (baton
);
18265 gdb_assert (prop
->baton () != NULL
);
18267 else if (target_attr
->form_is_block ())
18269 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18270 baton
->property_type
= die_type (target_die
, target_cu
);
18271 baton
->locexpr
.per_cu
= cu
->per_cu
;
18272 baton
->locexpr
.per_objfile
= per_objfile
;
18273 struct dwarf_block
*block
= target_attr
->as_block ();
18274 baton
->locexpr
.size
= block
->size
;
18275 baton
->locexpr
.data
= block
->data
;
18276 baton
->locexpr
.is_reference
= true;
18277 prop
->set_locexpr (baton
);
18278 gdb_assert (prop
->baton () != NULL
);
18282 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18283 "dynamic property");
18287 case DW_AT_data_member_location
:
18291 if (!handle_data_member_location (target_die
, target_cu
,
18295 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18296 baton
->property_type
= read_type_die (target_die
->parent
,
18298 baton
->offset_info
.offset
= offset
;
18299 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18300 prop
->set_addr_offset (baton
);
18305 else if (attr
->form_is_constant ())
18306 prop
->set_const_val (attr
->constant_value (0));
18309 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18310 dwarf2_name (die
, cu
));
18320 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18322 struct type
*int_type
;
18324 /* Helper macro to examine the various builtin types. */
18325 #define TRY_TYPE(F) \
18326 int_type = (unsigned_p \
18327 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18328 : objfile_type (objfile)->builtin_ ## F); \
18329 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18336 TRY_TYPE (long_long
);
18340 gdb_assert_not_reached ("unable to find suitable integer type");
18343 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18344 present (which is valid) then compute the default type based on the
18345 compilation units address size. */
18347 static struct type
*
18348 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18350 struct type
*index_type
= die_type (die
, cu
);
18352 /* Dwarf-2 specifications explicitly allows to create subrange types
18353 without specifying a base type.
18354 In that case, the base type must be set to the type of
18355 the lower bound, upper bound or count, in that order, if any of these
18356 three attributes references an object that has a type.
18357 If no base type is found, the Dwarf-2 specifications say that
18358 a signed integer type of size equal to the size of an address should
18360 For the following C code: `extern char gdb_int [];'
18361 GCC produces an empty range DIE.
18362 FIXME: muller/2010-05-28: Possible references to object for low bound,
18363 high bound or count are not yet handled by this code. */
18364 if (index_type
->code () == TYPE_CODE_VOID
)
18365 index_type
= cu
->addr_sized_int_type (false);
18370 /* Read the given DW_AT_subrange DIE. */
18372 static struct type
*
18373 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18375 struct type
*base_type
, *orig_base_type
;
18376 struct type
*range_type
;
18377 struct attribute
*attr
;
18378 struct dynamic_prop low
, high
;
18379 int low_default_is_valid
;
18380 int high_bound_is_count
= 0;
18382 ULONGEST negative_mask
;
18384 orig_base_type
= read_subrange_index_type (die
, cu
);
18386 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18387 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18388 creating the range type, but we use the result of check_typedef
18389 when examining properties of the type. */
18390 base_type
= check_typedef (orig_base_type
);
18392 /* The die_type call above may have already set the type for this DIE. */
18393 range_type
= get_die_type (die
, cu
);
18397 high
.set_const_val (0);
18399 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18400 omitting DW_AT_lower_bound. */
18401 switch (cu
->per_cu
->lang
)
18404 case language_cplus
:
18405 low
.set_const_val (0);
18406 low_default_is_valid
= 1;
18408 case language_fortran
:
18409 low
.set_const_val (1);
18410 low_default_is_valid
= 1;
18413 case language_objc
:
18414 case language_rust
:
18415 low
.set_const_val (0);
18416 low_default_is_valid
= (cu
->header
.version
>= 4);
18420 case language_pascal
:
18421 low
.set_const_val (1);
18422 low_default_is_valid
= (cu
->header
.version
>= 4);
18425 low
.set_const_val (0);
18426 low_default_is_valid
= 0;
18430 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18431 if (attr
!= nullptr)
18432 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18433 else if (!low_default_is_valid
)
18434 complaint (_("Missing DW_AT_lower_bound "
18435 "- DIE at %s [in module %s]"),
18436 sect_offset_str (die
->sect_off
),
18437 objfile_name (cu
->per_objfile
->objfile
));
18439 struct attribute
*attr_ub
, *attr_count
;
18440 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18441 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18443 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18444 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18446 /* If bounds are constant do the final calculation here. */
18447 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18448 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18450 high_bound_is_count
= 1;
18454 if (attr_ub
!= NULL
)
18455 complaint (_("Unresolved DW_AT_upper_bound "
18456 "- DIE at %s [in module %s]"),
18457 sect_offset_str (die
->sect_off
),
18458 objfile_name (cu
->per_objfile
->objfile
));
18459 if (attr_count
!= NULL
)
18460 complaint (_("Unresolved DW_AT_count "
18461 "- DIE at %s [in module %s]"),
18462 sect_offset_str (die
->sect_off
),
18463 objfile_name (cu
->per_objfile
->objfile
));
18468 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18469 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18470 bias
= bias_attr
->constant_value (0);
18472 /* Normally, the DWARF producers are expected to use a signed
18473 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18474 But this is unfortunately not always the case, as witnessed
18475 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18476 is used instead. To work around that ambiguity, we treat
18477 the bounds as signed, and thus sign-extend their values, when
18478 the base type is signed. */
18480 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18481 if (low
.kind () == PROP_CONST
18482 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18483 low
.set_const_val (low
.const_val () | negative_mask
);
18484 if (high
.kind () == PROP_CONST
18485 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18486 high
.set_const_val (high
.const_val () | negative_mask
);
18488 /* Check for bit and byte strides. */
18489 struct dynamic_prop byte_stride_prop
;
18490 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18491 if (attr_byte_stride
!= nullptr)
18493 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18494 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18498 struct dynamic_prop bit_stride_prop
;
18499 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18500 if (attr_bit_stride
!= nullptr)
18502 /* It only makes sense to have either a bit or byte stride. */
18503 if (attr_byte_stride
!= nullptr)
18505 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18506 "- DIE at %s [in module %s]"),
18507 sect_offset_str (die
->sect_off
),
18508 objfile_name (cu
->per_objfile
->objfile
));
18509 attr_bit_stride
= nullptr;
18513 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18514 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18519 if (attr_byte_stride
!= nullptr
18520 || attr_bit_stride
!= nullptr)
18522 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18523 struct dynamic_prop
*stride
18524 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18527 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18528 &high
, bias
, stride
, byte_stride_p
);
18531 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18533 if (high_bound_is_count
)
18534 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18536 /* Ada expects an empty array on no boundary attributes. */
18537 if (attr
== NULL
&& cu
->per_cu
->lang
!= language_ada
)
18538 range_type
->bounds ()->high
.set_undefined ();
18540 name
= dwarf2_name (die
, cu
);
18542 range_type
->set_name (name
);
18544 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18545 if (attr
!= nullptr)
18546 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18548 maybe_set_alignment (cu
, die
, range_type
);
18550 set_die_type (die
, range_type
, cu
);
18552 /* set_die_type should be already done. */
18553 set_descriptive_type (range_type
, die
, cu
);
18558 static struct type
*
18559 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18563 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18564 type
->set_name (dwarf2_name (die
, cu
));
18566 /* In Ada, an unspecified type is typically used when the description
18567 of the type is deferred to a different unit. When encountering
18568 such a type, we treat it as a stub, and try to resolve it later on,
18570 if (cu
->per_cu
->lang
== language_ada
)
18571 type
->set_is_stub (true);
18573 return set_die_type (die
, type
, cu
);
18576 /* Read a single die and all its descendents. Set the die's sibling
18577 field to NULL; set other fields in the die correctly, and set all
18578 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18579 location of the info_ptr after reading all of those dies. PARENT
18580 is the parent of the die in question. */
18582 static struct die_info
*
18583 read_die_and_children (const struct die_reader_specs
*reader
,
18584 const gdb_byte
*info_ptr
,
18585 const gdb_byte
**new_info_ptr
,
18586 struct die_info
*parent
)
18588 struct die_info
*die
;
18589 const gdb_byte
*cur_ptr
;
18591 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18594 *new_info_ptr
= cur_ptr
;
18597 store_in_ref_table (die
, reader
->cu
);
18599 if (die
->has_children
)
18600 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18604 *new_info_ptr
= cur_ptr
;
18607 die
->sibling
= NULL
;
18608 die
->parent
= parent
;
18612 /* Read a die, all of its descendents, and all of its siblings; set
18613 all of the fields of all of the dies correctly. Arguments are as
18614 in read_die_and_children. */
18616 static struct die_info
*
18617 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18618 const gdb_byte
*info_ptr
,
18619 const gdb_byte
**new_info_ptr
,
18620 struct die_info
*parent
)
18622 struct die_info
*first_die
, *last_sibling
;
18623 const gdb_byte
*cur_ptr
;
18625 cur_ptr
= info_ptr
;
18626 first_die
= last_sibling
= NULL
;
18630 struct die_info
*die
18631 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18635 *new_info_ptr
= cur_ptr
;
18642 last_sibling
->sibling
= die
;
18644 last_sibling
= die
;
18648 /* Read a die, all of its descendents, and all of its siblings; set
18649 all of the fields of all of the dies correctly. Arguments are as
18650 in read_die_and_children.
18651 This the main entry point for reading a DIE and all its children. */
18653 static struct die_info
*
18654 read_die_and_siblings (const struct die_reader_specs
*reader
,
18655 const gdb_byte
*info_ptr
,
18656 const gdb_byte
**new_info_ptr
,
18657 struct die_info
*parent
)
18659 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18660 new_info_ptr
, parent
);
18662 if (dwarf_die_debug
)
18664 fprintf_unfiltered (gdb_stdlog
,
18665 "Read die from %s@0x%x of %s:\n",
18666 reader
->die_section
->get_name (),
18667 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18668 bfd_get_filename (reader
->abfd
));
18669 dump_die (die
, dwarf_die_debug
);
18675 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18677 The caller is responsible for filling in the extra attributes
18678 and updating (*DIEP)->num_attrs.
18679 Set DIEP to point to a newly allocated die with its information,
18680 except for its child, sibling, and parent fields. */
18682 static const gdb_byte
*
18683 read_full_die_1 (const struct die_reader_specs
*reader
,
18684 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18685 int num_extra_attrs
)
18687 unsigned int abbrev_number
, bytes_read
, i
;
18688 const struct abbrev_info
*abbrev
;
18689 struct die_info
*die
;
18690 struct dwarf2_cu
*cu
= reader
->cu
;
18691 bfd
*abfd
= reader
->abfd
;
18693 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18694 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18695 info_ptr
+= bytes_read
;
18696 if (!abbrev_number
)
18702 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18704 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18706 bfd_get_filename (abfd
));
18708 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18709 die
->sect_off
= sect_off
;
18710 die
->tag
= abbrev
->tag
;
18711 die
->abbrev
= abbrev_number
;
18712 die
->has_children
= abbrev
->has_children
;
18714 /* Make the result usable.
18715 The caller needs to update num_attrs after adding the extra
18717 die
->num_attrs
= abbrev
->num_attrs
;
18719 bool any_need_reprocess
= false;
18720 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18722 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18724 if (die
->attrs
[i
].requires_reprocessing_p ())
18725 any_need_reprocess
= true;
18728 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18729 if (attr
!= nullptr && attr
->form_is_unsigned ())
18730 cu
->str_offsets_base
= attr
->as_unsigned ();
18732 attr
= die
->attr (DW_AT_loclists_base
);
18733 if (attr
!= nullptr)
18734 cu
->loclist_base
= attr
->as_unsigned ();
18736 auto maybe_addr_base
= die
->addr_base ();
18737 if (maybe_addr_base
.has_value ())
18738 cu
->addr_base
= *maybe_addr_base
;
18740 attr
= die
->attr (DW_AT_rnglists_base
);
18741 if (attr
!= nullptr)
18742 cu
->rnglists_base
= attr
->as_unsigned ();
18744 if (any_need_reprocess
)
18746 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18748 if (die
->attrs
[i
].requires_reprocessing_p ())
18749 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18756 /* Read a die and all its attributes.
18757 Set DIEP to point to a newly allocated die with its information,
18758 except for its child, sibling, and parent fields. */
18760 static const gdb_byte
*
18761 read_full_die (const struct die_reader_specs
*reader
,
18762 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18764 const gdb_byte
*result
;
18766 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18768 if (dwarf_die_debug
)
18770 fprintf_unfiltered (gdb_stdlog
,
18771 "Read die from %s@0x%x of %s:\n",
18772 reader
->die_section
->get_name (),
18773 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18774 bfd_get_filename (reader
->abfd
));
18775 dump_die (*diep
, dwarf_die_debug
);
18782 /* Returns nonzero if TAG represents a type that we might generate a partial
18786 is_type_tag_for_partial (int tag
, enum language lang
)
18791 /* Some types that would be reasonable to generate partial symbols for,
18792 that we don't at present. Note that normally this does not
18793 matter, mainly because C compilers don't give names to these
18794 types, but instead emit DW_TAG_typedef. */
18795 case DW_TAG_file_type
:
18796 case DW_TAG_ptr_to_member_type
:
18797 case DW_TAG_set_type
:
18798 case DW_TAG_string_type
:
18799 case DW_TAG_subroutine_type
:
18802 /* GNAT may emit an array with a name, but no typedef, so we
18803 need to make a symbol in this case. */
18804 case DW_TAG_array_type
:
18805 return lang
== language_ada
;
18807 case DW_TAG_base_type
:
18808 case DW_TAG_class_type
:
18809 case DW_TAG_interface_type
:
18810 case DW_TAG_enumeration_type
:
18811 case DW_TAG_structure_type
:
18812 case DW_TAG_subrange_type
:
18813 case DW_TAG_typedef
:
18814 case DW_TAG_union_type
:
18821 /* Load all DIEs that are interesting for partial symbols into memory. */
18823 static struct partial_die_info
*
18824 load_partial_dies (const struct die_reader_specs
*reader
,
18825 const gdb_byte
*info_ptr
, int building_psymtab
)
18827 struct dwarf2_cu
*cu
= reader
->cu
;
18828 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18829 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18830 unsigned int bytes_read
;
18831 unsigned int load_all
= 0;
18832 int nesting_level
= 1;
18837 gdb_assert (cu
->per_cu
!= NULL
);
18838 if (cu
->load_all_dies
)
18842 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18846 &cu
->comp_unit_obstack
,
18847 hashtab_obstack_allocate
,
18848 dummy_obstack_deallocate
);
18852 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
18855 /* A NULL abbrev means the end of a series of children. */
18856 if (abbrev
== NULL
)
18858 if (--nesting_level
== 0)
18861 info_ptr
+= bytes_read
;
18862 last_die
= parent_die
;
18863 parent_die
= parent_die
->die_parent
;
18867 /* Check for template arguments. We never save these; if
18868 they're seen, we just mark the parent, and go on our way. */
18869 if (parent_die
!= NULL
18870 && cu
->per_cu
->lang
== language_cplus
18871 && (abbrev
->tag
== DW_TAG_template_type_param
18872 || abbrev
->tag
== DW_TAG_template_value_param
))
18874 parent_die
->has_template_arguments
= 1;
18878 /* We don't need a partial DIE for the template argument. */
18879 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18884 /* We only recurse into c++ subprograms looking for template arguments.
18885 Skip their other children. */
18887 && cu
->per_cu
->lang
== language_cplus
18888 && parent_die
!= NULL
18889 && parent_die
->tag
== DW_TAG_subprogram
18890 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
18892 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18896 /* Check whether this DIE is interesting enough to save. Normally
18897 we would not be interested in members here, but there may be
18898 later variables referencing them via DW_AT_specification (for
18899 static members). */
18901 && !is_type_tag_for_partial (abbrev
->tag
, cu
->per_cu
->lang
)
18902 && abbrev
->tag
!= DW_TAG_constant
18903 && abbrev
->tag
!= DW_TAG_enumerator
18904 && abbrev
->tag
!= DW_TAG_subprogram
18905 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18906 && abbrev
->tag
!= DW_TAG_lexical_block
18907 && abbrev
->tag
!= DW_TAG_variable
18908 && abbrev
->tag
!= DW_TAG_namespace
18909 && abbrev
->tag
!= DW_TAG_module
18910 && abbrev
->tag
!= DW_TAG_member
18911 && abbrev
->tag
!= DW_TAG_imported_unit
18912 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18914 /* Otherwise we skip to the next sibling, if any. */
18915 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18919 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18922 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18924 /* This two-pass algorithm for processing partial symbols has a
18925 high cost in cache pressure. Thus, handle some simple cases
18926 here which cover the majority of C partial symbols. DIEs
18927 which neither have specification tags in them, nor could have
18928 specification tags elsewhere pointing at them, can simply be
18929 processed and discarded.
18931 This segment is also optional; scan_partial_symbols and
18932 add_partial_symbol will handle these DIEs if we chain
18933 them in normally. When compilers which do not emit large
18934 quantities of duplicate debug information are more common,
18935 this code can probably be removed. */
18937 /* Any complete simple types at the top level (pretty much all
18938 of them, for a language without namespaces), can be processed
18940 if (parent_die
== NULL
18941 && pdi
.has_specification
== 0
18942 && pdi
.is_declaration
== 0
18943 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18944 || pdi
.tag
== DW_TAG_base_type
18945 || pdi
.tag
== DW_TAG_array_type
18946 || pdi
.tag
== DW_TAG_subrange_type
))
18948 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
18949 add_partial_symbol (&pdi
, cu
);
18951 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18955 /* The exception for DW_TAG_typedef with has_children above is
18956 a workaround of GCC PR debug/47510. In the case of this complaint
18957 type_name_or_error will error on such types later.
18959 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18960 it could not find the child DIEs referenced later, this is checked
18961 above. In correct DWARF DW_TAG_typedef should have no children. */
18963 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18964 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18965 "- DIE at %s [in module %s]"),
18966 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18968 /* If we're at the second level, and we're an enumerator, and
18969 our parent has no specification (meaning possibly lives in a
18970 namespace elsewhere), then we can add the partial symbol now
18971 instead of queueing it. */
18972 if (pdi
.tag
== DW_TAG_enumerator
18973 && parent_die
!= NULL
18974 && parent_die
->die_parent
== NULL
18975 && parent_die
->tag
== DW_TAG_enumeration_type
18976 && parent_die
->has_specification
== 0)
18978 if (pdi
.raw_name
== NULL
)
18979 complaint (_("malformed enumerator DIE ignored"));
18980 else if (building_psymtab
)
18981 add_partial_symbol (&pdi
, cu
);
18983 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18987 struct partial_die_info
*part_die
18988 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18990 /* We'll save this DIE so link it in. */
18991 part_die
->die_parent
= parent_die
;
18992 part_die
->die_sibling
= NULL
;
18993 part_die
->die_child
= NULL
;
18995 if (last_die
&& last_die
== parent_die
)
18996 last_die
->die_child
= part_die
;
18998 last_die
->die_sibling
= part_die
;
19000 last_die
= part_die
;
19002 if (first_die
== NULL
)
19003 first_die
= part_die
;
19005 /* Maybe add the DIE to the hash table. Not all DIEs that we
19006 find interesting need to be in the hash table, because we
19007 also have the parent/sibling/child chains; only those that we
19008 might refer to by offset later during partial symbol reading.
19010 For now this means things that might have be the target of a
19011 DW_AT_specification, DW_AT_abstract_origin, or
19012 DW_AT_extension. DW_AT_extension will refer only to
19013 namespaces; DW_AT_abstract_origin refers to functions (and
19014 many things under the function DIE, but we do not recurse
19015 into function DIEs during partial symbol reading) and
19016 possibly variables as well; DW_AT_specification refers to
19017 declarations. Declarations ought to have the DW_AT_declaration
19018 flag. It happens that GCC forgets to put it in sometimes, but
19019 only for functions, not for types.
19021 Adding more things than necessary to the hash table is harmless
19022 except for the performance cost. Adding too few will result in
19023 wasted time in find_partial_die, when we reread the compilation
19024 unit with load_all_dies set. */
19027 || abbrev
->tag
== DW_TAG_constant
19028 || abbrev
->tag
== DW_TAG_subprogram
19029 || abbrev
->tag
== DW_TAG_variable
19030 || abbrev
->tag
== DW_TAG_namespace
19031 || part_die
->is_declaration
)
19035 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19036 to_underlying (part_die
->sect_off
),
19041 /* For some DIEs we want to follow their children (if any). For C
19042 we have no reason to follow the children of structures; for other
19043 languages we have to, so that we can get at method physnames
19044 to infer fully qualified class names, for DW_AT_specification,
19045 and for C++ template arguments. For C++, we also look one level
19046 inside functions to find template arguments (if the name of the
19047 function does not already contain the template arguments).
19049 For Ada and Fortran, we need to scan the children of subprograms
19050 and lexical blocks as well because these languages allow the
19051 definition of nested entities that could be interesting for the
19052 debugger, such as nested subprograms for instance. */
19053 if (last_die
->has_children
19055 || last_die
->tag
== DW_TAG_namespace
19056 || last_die
->tag
== DW_TAG_module
19057 || last_die
->tag
== DW_TAG_enumeration_type
19058 || (cu
->per_cu
->lang
== language_cplus
19059 && last_die
->tag
== DW_TAG_subprogram
19060 && (last_die
->raw_name
== NULL
19061 || strchr (last_die
->raw_name
, '<') == NULL
))
19062 || (cu
->per_cu
->lang
!= language_c
19063 && (last_die
->tag
== DW_TAG_class_type
19064 || last_die
->tag
== DW_TAG_interface_type
19065 || last_die
->tag
== DW_TAG_structure_type
19066 || last_die
->tag
== DW_TAG_union_type
))
19067 || ((cu
->per_cu
->lang
== language_ada
19068 || cu
->per_cu
->lang
== language_fortran
)
19069 && (last_die
->tag
== DW_TAG_subprogram
19070 || last_die
->tag
== DW_TAG_lexical_block
))))
19073 parent_die
= last_die
;
19077 /* Otherwise we skip to the next sibling, if any. */
19078 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19080 /* Back to the top, do it again. */
19084 partial_die_info::partial_die_info (sect_offset sect_off_
,
19085 const struct abbrev_info
*abbrev
)
19086 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19090 /* See class definition. */
19093 partial_die_info::name (dwarf2_cu
*cu
)
19095 if (!canonical_name
&& raw_name
!= nullptr)
19097 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19098 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19099 canonical_name
= 1;
19105 /* Read a minimal amount of information into the minimal die structure.
19106 INFO_PTR should point just after the initial uleb128 of a DIE. */
19109 partial_die_info::read (const struct die_reader_specs
*reader
,
19110 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19112 struct dwarf2_cu
*cu
= reader
->cu
;
19113 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19115 int has_low_pc_attr
= 0;
19116 int has_high_pc_attr
= 0;
19117 int high_pc_relative
= 0;
19119 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19122 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19123 /* String and address offsets that need to do the reprocessing have
19124 already been read at this point, so there is no need to wait until
19125 the loop terminates to do the reprocessing. */
19126 if (attr
.requires_reprocessing_p ())
19127 read_attribute_reprocess (reader
, &attr
, tag
);
19128 /* Store the data if it is of an attribute we want to keep in a
19129 partial symbol table. */
19135 case DW_TAG_compile_unit
:
19136 case DW_TAG_partial_unit
:
19137 case DW_TAG_type_unit
:
19138 /* Compilation units have a DW_AT_name that is a filename, not
19139 a source language identifier. */
19140 case DW_TAG_enumeration_type
:
19141 case DW_TAG_enumerator
:
19142 /* These tags always have simple identifiers already; no need
19143 to canonicalize them. */
19144 canonical_name
= 1;
19145 raw_name
= attr
.as_string ();
19148 canonical_name
= 0;
19149 raw_name
= attr
.as_string ();
19153 case DW_AT_linkage_name
:
19154 case DW_AT_MIPS_linkage_name
:
19155 /* Note that both forms of linkage name might appear. We
19156 assume they will be the same, and we only store the last
19158 linkage_name
= attr
.as_string ();
19161 has_low_pc_attr
= 1;
19162 lowpc
= attr
.as_address ();
19164 case DW_AT_high_pc
:
19165 has_high_pc_attr
= 1;
19166 highpc
= attr
.as_address ();
19167 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19168 high_pc_relative
= 1;
19170 case DW_AT_location
:
19171 /* Support the .debug_loc offsets. */
19172 if (attr
.form_is_block ())
19174 d
.locdesc
= attr
.as_block ();
19176 else if (attr
.form_is_section_offset ())
19178 dwarf2_complex_location_expr_complaint ();
19182 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19183 "partial symbol information");
19186 case DW_AT_external
:
19187 is_external
= attr
.as_boolean ();
19189 case DW_AT_declaration
:
19190 is_declaration
= attr
.as_boolean ();
19195 case DW_AT_abstract_origin
:
19196 case DW_AT_specification
:
19197 case DW_AT_extension
:
19198 has_specification
= 1;
19199 spec_offset
= attr
.get_ref_die_offset ();
19200 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19201 || cu
->per_cu
->is_dwz
);
19203 case DW_AT_sibling
:
19204 /* Ignore absolute siblings, they might point outside of
19205 the current compile unit. */
19206 if (attr
.form
== DW_FORM_ref_addr
)
19207 complaint (_("ignoring absolute DW_AT_sibling"));
19210 const gdb_byte
*buffer
= reader
->buffer
;
19211 sect_offset off
= attr
.get_ref_die_offset ();
19212 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19214 if (sibling_ptr
< info_ptr
)
19215 complaint (_("DW_AT_sibling points backwards"));
19216 else if (sibling_ptr
> reader
->buffer_end
)
19217 reader
->die_section
->overflow_complaint ();
19219 sibling
= sibling_ptr
;
19222 case DW_AT_byte_size
:
19225 case DW_AT_const_value
:
19226 has_const_value
= 1;
19228 case DW_AT_calling_convention
:
19229 /* DWARF doesn't provide a way to identify a program's source-level
19230 entry point. DW_AT_calling_convention attributes are only meant
19231 to describe functions' calling conventions.
19233 However, because it's a necessary piece of information in
19234 Fortran, and before DWARF 4 DW_CC_program was the only
19235 piece of debugging information whose definition refers to
19236 a 'main program' at all, several compilers marked Fortran
19237 main programs with DW_CC_program --- even when those
19238 functions use the standard calling conventions.
19240 Although DWARF now specifies a way to provide this
19241 information, we support this practice for backward
19243 if (attr
.constant_value (0) == DW_CC_program
19244 && cu
->per_cu
->lang
== language_fortran
)
19245 main_subprogram
= 1;
19249 LONGEST value
= attr
.constant_value (-1);
19250 if (value
== DW_INL_inlined
19251 || value
== DW_INL_declared_inlined
)
19252 may_be_inlined
= 1;
19257 if (tag
== DW_TAG_imported_unit
)
19259 d
.sect_off
= attr
.get_ref_die_offset ();
19260 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19261 || cu
->per_cu
->is_dwz
);
19265 case DW_AT_main_subprogram
:
19266 main_subprogram
= attr
.as_boolean ();
19271 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19272 on DWARF version). */
19273 ULONGEST ranges_offset
= attr
.as_unsigned ();
19275 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19277 if (tag
!= DW_TAG_compile_unit
)
19278 ranges_offset
+= cu
->gnu_ranges_base
;
19280 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19291 /* For Ada, if both the name and the linkage name appear, we prefer
19292 the latter. This lets "catch exception" work better, regardless
19293 of the order in which the name and linkage name were emitted.
19294 Really, though, this is just a workaround for the fact that gdb
19295 doesn't store both the name and the linkage name. */
19296 if (cu
->per_cu
->lang
== language_ada
&& linkage_name
!= nullptr)
19297 raw_name
= linkage_name
;
19299 if (high_pc_relative
)
19302 if (has_low_pc_attr
&& has_high_pc_attr
)
19304 /* When using the GNU linker, .gnu.linkonce. sections are used to
19305 eliminate duplicate copies of functions and vtables and such.
19306 The linker will arbitrarily choose one and discard the others.
19307 The AT_*_pc values for such functions refer to local labels in
19308 these sections. If the section from that file was discarded, the
19309 labels are not in the output, so the relocs get a value of 0.
19310 If this is a discarded function, mark the pc bounds as invalid,
19311 so that GDB will ignore it. */
19312 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19314 struct objfile
*objfile
= per_objfile
->objfile
;
19315 struct gdbarch
*gdbarch
= objfile
->arch ();
19317 complaint (_("DW_AT_low_pc %s is zero "
19318 "for DIE at %s [in module %s]"),
19319 paddress (gdbarch
, lowpc
),
19320 sect_offset_str (sect_off
),
19321 objfile_name (objfile
));
19323 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19324 else if (lowpc
>= highpc
)
19326 struct objfile
*objfile
= per_objfile
->objfile
;
19327 struct gdbarch
*gdbarch
= objfile
->arch ();
19329 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19330 "for DIE at %s [in module %s]"),
19331 paddress (gdbarch
, lowpc
),
19332 paddress (gdbarch
, highpc
),
19333 sect_offset_str (sect_off
),
19334 objfile_name (objfile
));
19343 /* Find a cached partial DIE at OFFSET in CU. */
19345 struct partial_die_info
*
19346 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19348 struct partial_die_info
*lookup_die
= NULL
;
19349 struct partial_die_info
part_die (sect_off
);
19351 lookup_die
= ((struct partial_die_info
*)
19352 htab_find_with_hash (partial_dies
, &part_die
,
19353 to_underlying (sect_off
)));
19358 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19359 except in the case of .debug_types DIEs which do not reference
19360 outside their CU (they do however referencing other types via
19361 DW_FORM_ref_sig8). */
19363 static const struct cu_partial_die_info
19364 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19366 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19367 struct objfile
*objfile
= per_objfile
->objfile
;
19368 struct partial_die_info
*pd
= NULL
;
19370 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19371 && cu
->header
.offset_in_cu_p (sect_off
))
19373 pd
= cu
->find_partial_die (sect_off
);
19376 /* We missed recording what we needed.
19377 Load all dies and try again. */
19381 /* TUs don't reference other CUs/TUs (except via type signatures). */
19382 if (cu
->per_cu
->is_debug_types
)
19384 error (_("Dwarf Error: Type Unit at offset %s contains"
19385 " external reference to offset %s [in module %s].\n"),
19386 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19387 bfd_get_filename (objfile
->obfd
));
19389 dwarf2_per_cu_data
*per_cu
19390 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19393 cu
= per_objfile
->get_cu (per_cu
);
19394 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19395 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19397 cu
= per_objfile
->get_cu (per_cu
);
19400 pd
= cu
->find_partial_die (sect_off
);
19403 /* If we didn't find it, and not all dies have been loaded,
19404 load them all and try again. */
19406 if (pd
== NULL
&& cu
->load_all_dies
== 0)
19408 cu
->load_all_dies
= 1;
19410 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19411 THIS_CU->cu may already be in use. So we can't just free it and
19412 replace its DIEs with the ones we read in. Instead, we leave those
19413 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19414 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19416 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19418 pd
= cu
->find_partial_die (sect_off
);
19422 error (_("Dwarf Error: Cannot find DIE at %s [from module %s]\n"),
19423 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19427 /* See if we can figure out if the class lives in a namespace. We do
19428 this by looking for a member function; its demangled name will
19429 contain namespace info, if there is any. */
19432 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19433 struct dwarf2_cu
*cu
)
19435 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19436 what template types look like, because the demangler
19437 frequently doesn't give the same name as the debug info. We
19438 could fix this by only using the demangled name to get the
19439 prefix (but see comment in read_structure_type). */
19441 struct partial_die_info
*real_pdi
;
19442 struct partial_die_info
*child_pdi
;
19444 /* If this DIE (this DIE's specification, if any) has a parent, then
19445 we should not do this. We'll prepend the parent's fully qualified
19446 name when we create the partial symbol. */
19448 real_pdi
= struct_pdi
;
19449 while (real_pdi
->has_specification
)
19451 auto res
= find_partial_die (real_pdi
->spec_offset
,
19452 real_pdi
->spec_is_dwz
, cu
);
19453 real_pdi
= res
.pdi
;
19457 if (real_pdi
->die_parent
!= NULL
)
19460 for (child_pdi
= struct_pdi
->die_child
;
19462 child_pdi
= child_pdi
->die_sibling
)
19464 if (child_pdi
->tag
== DW_TAG_subprogram
19465 && child_pdi
->linkage_name
!= NULL
)
19467 gdb::unique_xmalloc_ptr
<char> actual_class_name
19468 (cu
->language_defn
->class_name_from_physname
19469 (child_pdi
->linkage_name
));
19470 if (actual_class_name
!= NULL
)
19472 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19473 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19474 struct_pdi
->canonical_name
= 1;
19481 /* Return true if a DIE with TAG may have the DW_AT_const_value
19485 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19489 case DW_TAG_constant
:
19490 case DW_TAG_enumerator
:
19491 case DW_TAG_formal_parameter
:
19492 case DW_TAG_template_value_param
:
19493 case DW_TAG_variable
:
19501 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19503 /* Once we've fixed up a die, there's no point in doing so again.
19504 This also avoids a memory leak if we were to call
19505 guess_partial_die_structure_name multiple times. */
19509 /* If we found a reference attribute and the DIE has no name, try
19510 to find a name in the referred to DIE. */
19512 if (raw_name
== NULL
&& has_specification
)
19514 struct partial_die_info
*spec_die
;
19516 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19517 spec_die
= res
.pdi
;
19520 spec_die
->fixup (cu
);
19522 if (spec_die
->raw_name
)
19524 raw_name
= spec_die
->raw_name
;
19525 canonical_name
= spec_die
->canonical_name
;
19527 /* Copy DW_AT_external attribute if it is set. */
19528 if (spec_die
->is_external
)
19529 is_external
= spec_die
->is_external
;
19533 if (!has_const_value
&& has_specification
19534 && can_have_DW_AT_const_value_p (tag
))
19536 struct partial_die_info
*spec_die
;
19538 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19539 spec_die
= res
.pdi
;
19542 spec_die
->fixup (cu
);
19544 if (spec_die
->has_const_value
)
19546 /* Copy DW_AT_const_value attribute if it is set. */
19547 has_const_value
= spec_die
->has_const_value
;
19551 /* Set default names for some unnamed DIEs. */
19553 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19555 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19556 canonical_name
= 1;
19559 /* If there is no parent die to provide a namespace, and there are
19560 children, see if we can determine the namespace from their linkage
19562 if (cu
->per_cu
->lang
== language_cplus
19563 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19564 && die_parent
== NULL
19566 && (tag
== DW_TAG_class_type
19567 || tag
== DW_TAG_structure_type
19568 || tag
== DW_TAG_union_type
))
19569 guess_partial_die_structure_name (this, cu
);
19571 /* GCC might emit a nameless struct or union that has a linkage
19572 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19573 if (raw_name
== NULL
19574 && (tag
== DW_TAG_class_type
19575 || tag
== DW_TAG_interface_type
19576 || tag
== DW_TAG_structure_type
19577 || tag
== DW_TAG_union_type
)
19578 && linkage_name
!= NULL
)
19580 gdb::unique_xmalloc_ptr
<char> demangled
19581 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19582 if (demangled
!= nullptr)
19586 /* Strip any leading namespaces/classes, keep only the base name.
19587 DW_AT_name for named DIEs does not contain the prefixes. */
19588 base
= strrchr (demangled
.get (), ':');
19589 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19592 base
= demangled
.get ();
19594 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19595 raw_name
= objfile
->intern (base
);
19596 canonical_name
= 1;
19603 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19604 contents from the given SECTION in the HEADER.
19606 HEADER_OFFSET is the offset of the header in the section. */
19608 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19609 struct dwarf2_section_info
*section
,
19610 sect_offset header_offset
)
19612 unsigned int bytes_read
;
19613 bfd
*abfd
= section
->get_bfd_owner ();
19614 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19616 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19617 info_ptr
+= bytes_read
;
19619 header
->version
= read_2_bytes (abfd
, info_ptr
);
19622 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19625 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19628 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19631 /* Return the DW_AT_loclists_base value for the CU. */
19633 lookup_loclist_base (struct dwarf2_cu
*cu
)
19635 /* For the .dwo unit, the loclist_base points to the first offset following
19636 the header. The header consists of the following entities-
19637 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19639 2. version (2 bytes)
19640 3. address size (1 byte)
19641 4. segment selector size (1 byte)
19642 5. offset entry count (4 bytes)
19643 These sizes are derived as per the DWARFv5 standard. */
19644 if (cu
->dwo_unit
!= nullptr)
19646 if (cu
->header
.initial_length_size
== 4)
19647 return LOCLIST_HEADER_SIZE32
;
19648 return LOCLIST_HEADER_SIZE64
;
19650 return cu
->loclist_base
;
19653 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19654 array of offsets in the .debug_loclists section. */
19657 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19659 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19660 struct objfile
*objfile
= per_objfile
->objfile
;
19661 bfd
*abfd
= objfile
->obfd
;
19662 ULONGEST loclist_header_size
=
19663 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19664 : LOCLIST_HEADER_SIZE64
);
19665 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19667 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19668 ULONGEST start_offset
=
19669 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19671 /* Get loclists section. */
19672 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19674 /* Read the loclists section content. */
19675 section
->read (objfile
);
19676 if (section
->buffer
== NULL
)
19677 error (_("DW_FORM_loclistx used without .debug_loclists "
19678 "section [in module %s]"), objfile_name (objfile
));
19680 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19681 so if loclist_base is smaller than the header size, we have a problem. */
19682 if (loclist_base
< loclist_header_size
)
19683 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19684 objfile_name (objfile
));
19686 /* Read the header of the loclists contribution. */
19687 struct loclists_rnglists_header header
;
19688 read_loclists_rnglists_header (&header
, section
,
19689 (sect_offset
) (loclist_base
- loclist_header_size
));
19691 /* Verify the loclist index is valid. */
19692 if (loclist_index
>= header
.offset_entry_count
)
19693 error (_("DW_FORM_loclistx pointing outside of "
19694 ".debug_loclists offset array [in module %s]"),
19695 objfile_name (objfile
));
19697 /* Validate that reading won't go beyond the end of the section. */
19698 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19699 error (_("Reading DW_FORM_loclistx index beyond end of"
19700 ".debug_loclists section [in module %s]"),
19701 objfile_name (objfile
));
19703 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19705 if (cu
->header
.offset_size
== 4)
19706 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19708 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19711 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19712 array of offsets in the .debug_rnglists section. */
19715 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19718 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19719 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19720 bfd
*abfd
= objfile
->obfd
;
19721 ULONGEST rnglist_header_size
=
19722 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19723 : RNGLIST_HEADER_SIZE64
);
19725 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19726 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19728 ULONGEST rnglist_base
=
19729 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19731 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19732 ULONGEST start_offset
=
19733 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19735 /* Get rnglists section. */
19736 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19738 /* Read the rnglists section content. */
19739 section
->read (objfile
);
19740 if (section
->buffer
== nullptr)
19741 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19743 objfile_name (objfile
));
19745 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19746 so if rnglist_base is smaller than the header size, we have a problem. */
19747 if (rnglist_base
< rnglist_header_size
)
19748 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19749 objfile_name (objfile
));
19751 /* Read the header of the rnglists contribution. */
19752 struct loclists_rnglists_header header
;
19753 read_loclists_rnglists_header (&header
, section
,
19754 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19756 /* Verify the rnglist index is valid. */
19757 if (rnglist_index
>= header
.offset_entry_count
)
19758 error (_("DW_FORM_rnglistx index pointing outside of "
19759 ".debug_rnglists offset array [in module %s]"),
19760 objfile_name (objfile
));
19762 /* Validate that reading won't go beyond the end of the section. */
19763 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19764 error (_("Reading DW_FORM_rnglistx index beyond end of"
19765 ".debug_rnglists section [in module %s]"),
19766 objfile_name (objfile
));
19768 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19770 if (cu
->header
.offset_size
== 4)
19771 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
19773 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
19776 /* Process the attributes that had to be skipped in the first round. These
19777 attributes are the ones that need str_offsets_base or addr_base attributes.
19778 They could not have been processed in the first round, because at the time
19779 the values of str_offsets_base or addr_base may not have been known. */
19781 read_attribute_reprocess (const struct die_reader_specs
*reader
,
19782 struct attribute
*attr
, dwarf_tag tag
)
19784 struct dwarf2_cu
*cu
= reader
->cu
;
19785 switch (attr
->form
)
19787 case DW_FORM_addrx
:
19788 case DW_FORM_GNU_addr_index
:
19789 attr
->set_address (read_addr_index (cu
,
19790 attr
->as_unsigned_reprocess ()));
19792 case DW_FORM_loclistx
:
19794 sect_offset loclists_sect_off
19795 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
19797 attr
->set_unsigned (to_underlying (loclists_sect_off
));
19800 case DW_FORM_rnglistx
:
19802 sect_offset rnglists_sect_off
19803 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
19805 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
19809 case DW_FORM_strx1
:
19810 case DW_FORM_strx2
:
19811 case DW_FORM_strx3
:
19812 case DW_FORM_strx4
:
19813 case DW_FORM_GNU_str_index
:
19815 unsigned int str_index
= attr
->as_unsigned_reprocess ();
19816 gdb_assert (!attr
->canonical_string_p ());
19817 if (reader
->dwo_file
!= NULL
)
19818 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
19821 attr
->set_string_noncanonical (read_stub_str_index (cu
,
19826 gdb_assert_not_reached (_("Unexpected DWARF form."));
19830 /* Read an attribute value described by an attribute form. */
19832 static const gdb_byte
*
19833 read_attribute_value (const struct die_reader_specs
*reader
,
19834 struct attribute
*attr
, unsigned form
,
19835 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19837 struct dwarf2_cu
*cu
= reader
->cu
;
19838 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19839 struct objfile
*objfile
= per_objfile
->objfile
;
19840 bfd
*abfd
= reader
->abfd
;
19841 struct comp_unit_head
*cu_header
= &cu
->header
;
19842 unsigned int bytes_read
;
19843 struct dwarf_block
*blk
;
19845 attr
->form
= (enum dwarf_form
) form
;
19848 case DW_FORM_ref_addr
:
19849 if (cu_header
->version
== 2)
19850 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
19853 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19855 info_ptr
+= bytes_read
;
19857 case DW_FORM_GNU_ref_alt
:
19858 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19860 info_ptr
+= bytes_read
;
19864 struct gdbarch
*gdbarch
= objfile
->arch ();
19865 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
19866 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
19867 attr
->set_address (addr
);
19868 info_ptr
+= bytes_read
;
19871 case DW_FORM_block2
:
19872 blk
= dwarf_alloc_block (cu
);
19873 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19875 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19876 info_ptr
+= blk
->size
;
19877 attr
->set_block (blk
);
19879 case DW_FORM_block4
:
19880 blk
= dwarf_alloc_block (cu
);
19881 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19883 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19884 info_ptr
+= blk
->size
;
19885 attr
->set_block (blk
);
19887 case DW_FORM_data2
:
19888 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
19891 case DW_FORM_data4
:
19892 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
19895 case DW_FORM_data8
:
19896 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
19899 case DW_FORM_data16
:
19900 blk
= dwarf_alloc_block (cu
);
19902 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19904 attr
->set_block (blk
);
19906 case DW_FORM_sec_offset
:
19907 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
19909 info_ptr
+= bytes_read
;
19911 case DW_FORM_loclistx
:
19913 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19915 info_ptr
+= bytes_read
;
19918 case DW_FORM_string
:
19919 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
19921 info_ptr
+= bytes_read
;
19924 if (!cu
->per_cu
->is_dwz
)
19926 attr
->set_string_noncanonical
19927 (read_indirect_string (per_objfile
,
19928 abfd
, info_ptr
, cu_header
,
19930 info_ptr
+= bytes_read
;
19934 case DW_FORM_line_strp
:
19935 if (!cu
->per_cu
->is_dwz
)
19937 attr
->set_string_noncanonical
19938 (per_objfile
->read_line_string (info_ptr
, cu_header
,
19940 info_ptr
+= bytes_read
;
19944 case DW_FORM_GNU_strp_alt
:
19946 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
19947 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
19950 attr
->set_string_noncanonical
19951 (dwz
->read_string (objfile
, str_offset
));
19952 info_ptr
+= bytes_read
;
19955 case DW_FORM_exprloc
:
19956 case DW_FORM_block
:
19957 blk
= dwarf_alloc_block (cu
);
19958 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19959 info_ptr
+= bytes_read
;
19960 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19961 info_ptr
+= blk
->size
;
19962 attr
->set_block (blk
);
19964 case DW_FORM_block1
:
19965 blk
= dwarf_alloc_block (cu
);
19966 blk
->size
= read_1_byte (abfd
, info_ptr
);
19968 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19969 info_ptr
+= blk
->size
;
19970 attr
->set_block (blk
);
19972 case DW_FORM_data1
:
19974 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
19977 case DW_FORM_flag_present
:
19978 attr
->set_unsigned (1);
19980 case DW_FORM_sdata
:
19981 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
19982 info_ptr
+= bytes_read
;
19984 case DW_FORM_rnglistx
:
19986 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
19988 info_ptr
+= bytes_read
;
19991 case DW_FORM_udata
:
19992 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19993 info_ptr
+= bytes_read
;
19996 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
19997 + read_1_byte (abfd
, info_ptr
)));
20001 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20002 + read_2_bytes (abfd
, info_ptr
)));
20006 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20007 + read_4_bytes (abfd
, info_ptr
)));
20011 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20012 + read_8_bytes (abfd
, info_ptr
)));
20015 case DW_FORM_ref_sig8
:
20016 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20019 case DW_FORM_ref_udata
:
20020 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20021 + read_unsigned_leb128 (abfd
, info_ptr
,
20023 info_ptr
+= bytes_read
;
20025 case DW_FORM_indirect
:
20026 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20027 info_ptr
+= bytes_read
;
20028 if (form
== DW_FORM_implicit_const
)
20030 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20031 info_ptr
+= bytes_read
;
20033 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20036 case DW_FORM_implicit_const
:
20037 attr
->set_signed (implicit_const
);
20039 case DW_FORM_addrx
:
20040 case DW_FORM_GNU_addr_index
:
20041 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20043 info_ptr
+= bytes_read
;
20046 case DW_FORM_strx1
:
20047 case DW_FORM_strx2
:
20048 case DW_FORM_strx3
:
20049 case DW_FORM_strx4
:
20050 case DW_FORM_GNU_str_index
:
20052 ULONGEST str_index
;
20053 if (form
== DW_FORM_strx1
)
20055 str_index
= read_1_byte (abfd
, info_ptr
);
20058 else if (form
== DW_FORM_strx2
)
20060 str_index
= read_2_bytes (abfd
, info_ptr
);
20063 else if (form
== DW_FORM_strx3
)
20065 str_index
= read_3_bytes (abfd
, info_ptr
);
20068 else if (form
== DW_FORM_strx4
)
20070 str_index
= read_4_bytes (abfd
, info_ptr
);
20075 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20076 info_ptr
+= bytes_read
;
20078 attr
->set_unsigned_reprocess (str_index
);
20082 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20083 dwarf_form_name (form
),
20084 bfd_get_filename (abfd
));
20088 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20089 attr
->form
= DW_FORM_GNU_ref_alt
;
20091 /* We have seen instances where the compiler tried to emit a byte
20092 size attribute of -1 which ended up being encoded as an unsigned
20093 0xffffffff. Although 0xffffffff is technically a valid size value,
20094 an object of this size seems pretty unlikely so we can relatively
20095 safely treat these cases as if the size attribute was invalid and
20096 treat them as zero by default. */
20097 if (attr
->name
== DW_AT_byte_size
20098 && form
== DW_FORM_data4
20099 && attr
->as_unsigned () >= 0xffffffff)
20102 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20103 hex_string (attr
->as_unsigned ()));
20104 attr
->set_unsigned (0);
20110 /* Read an attribute described by an abbreviated attribute. */
20112 static const gdb_byte
*
20113 read_attribute (const struct die_reader_specs
*reader
,
20114 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20115 const gdb_byte
*info_ptr
)
20117 attr
->name
= abbrev
->name
;
20118 attr
->string_is_canonical
= 0;
20119 attr
->requires_reprocessing
= 0;
20120 return read_attribute_value (reader
, attr
, abbrev
->form
,
20121 abbrev
->implicit_const
, info_ptr
);
20124 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20126 static const char *
20127 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20128 LONGEST str_offset
)
20130 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20131 str_offset
, "DW_FORM_strp");
20134 /* Return pointer to string at .debug_str offset as read from BUF.
20135 BUF is assumed to be in a compilation unit described by CU_HEADER.
20136 Return *BYTES_READ_PTR count of bytes read from BUF. */
20138 static const char *
20139 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20140 const gdb_byte
*buf
,
20141 const struct comp_unit_head
*cu_header
,
20142 unsigned int *bytes_read_ptr
)
20144 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20146 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20152 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20153 const struct comp_unit_head
*cu_header
,
20154 unsigned int *bytes_read_ptr
)
20156 bfd
*abfd
= objfile
->obfd
;
20157 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20159 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20162 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20163 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20164 ADDR_SIZE is the size of addresses from the CU header. */
20167 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20168 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20170 struct objfile
*objfile
= per_objfile
->objfile
;
20171 bfd
*abfd
= objfile
->obfd
;
20172 const gdb_byte
*info_ptr
;
20173 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20175 per_objfile
->per_bfd
->addr
.read (objfile
);
20176 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20177 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20178 objfile_name (objfile
));
20179 if (addr_base_or_zero
+ addr_index
* addr_size
20180 >= per_objfile
->per_bfd
->addr
.size
)
20181 error (_("DW_FORM_addr_index pointing outside of "
20182 ".debug_addr section [in module %s]"),
20183 objfile_name (objfile
));
20184 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20185 + addr_index
* addr_size
);
20186 if (addr_size
== 4)
20187 return bfd_get_32 (abfd
, info_ptr
);
20189 return bfd_get_64 (abfd
, info_ptr
);
20192 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20195 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20197 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20198 cu
->addr_base
, cu
->header
.addr_size
);
20201 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20204 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20205 unsigned int *bytes_read
)
20207 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20208 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20210 return read_addr_index (cu
, addr_index
);
20216 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20217 dwarf2_per_objfile
*per_objfile
,
20218 unsigned int addr_index
)
20220 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20221 gdb::optional
<ULONGEST
> addr_base
;
20224 /* We need addr_base and addr_size.
20225 If we don't have PER_CU->cu, we have to get it.
20226 Nasty, but the alternative is storing the needed info in PER_CU,
20227 which at this point doesn't seem justified: it's not clear how frequently
20228 it would get used and it would increase the size of every PER_CU.
20229 Entry points like dwarf2_per_cu_addr_size do a similar thing
20230 so we're not in uncharted territory here.
20231 Alas we need to be a bit more complicated as addr_base is contained
20234 We don't need to read the entire CU(/TU).
20235 We just need the header and top level die.
20237 IWBN to use the aging mechanism to let us lazily later discard the CU.
20238 For now we skip this optimization. */
20242 addr_base
= cu
->addr_base
;
20243 addr_size
= cu
->header
.addr_size
;
20247 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20248 addr_base
= reader
.cu
->addr_base
;
20249 addr_size
= reader
.cu
->header
.addr_size
;
20252 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20255 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20256 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20259 static const char *
20260 read_str_index (struct dwarf2_cu
*cu
,
20261 struct dwarf2_section_info
*str_section
,
20262 struct dwarf2_section_info
*str_offsets_section
,
20263 ULONGEST str_offsets_base
, ULONGEST str_index
)
20265 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20266 struct objfile
*objfile
= per_objfile
->objfile
;
20267 const char *objf_name
= objfile_name (objfile
);
20268 bfd
*abfd
= objfile
->obfd
;
20269 const gdb_byte
*info_ptr
;
20270 ULONGEST str_offset
;
20271 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20273 str_section
->read (objfile
);
20274 str_offsets_section
->read (objfile
);
20275 if (str_section
->buffer
== NULL
)
20276 error (_("%s used without %s section"
20277 " in CU at offset %s [in module %s]"),
20278 form_name
, str_section
->get_name (),
20279 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20280 if (str_offsets_section
->buffer
== NULL
)
20281 error (_("%s used without %s section"
20282 " in CU at offset %s [in module %s]"),
20283 form_name
, str_section
->get_name (),
20284 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20285 info_ptr
= (str_offsets_section
->buffer
20287 + str_index
* cu
->header
.offset_size
);
20288 if (cu
->header
.offset_size
== 4)
20289 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20291 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20292 if (str_offset
>= str_section
->size
)
20293 error (_("Offset from %s pointing outside of"
20294 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20295 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20296 return (const char *) (str_section
->buffer
+ str_offset
);
20299 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20301 static const char *
20302 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20304 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20305 ? reader
->cu
->header
.addr_size
: 0;
20306 return read_str_index (reader
->cu
,
20307 &reader
->dwo_file
->sections
.str
,
20308 &reader
->dwo_file
->sections
.str_offsets
,
20309 str_offsets_base
, str_index
);
20312 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20314 static const char *
20315 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20317 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20318 const char *objf_name
= objfile_name (objfile
);
20319 static const char form_name
[] = "DW_FORM_GNU_str_index";
20320 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20322 if (!cu
->str_offsets_base
.has_value ())
20323 error (_("%s used in Fission stub without %s"
20324 " in CU at offset 0x%lx [in module %s]"),
20325 form_name
, str_offsets_attr_name
,
20326 (long) cu
->header
.offset_size
, objf_name
);
20328 return read_str_index (cu
,
20329 &cu
->per_objfile
->per_bfd
->str
,
20330 &cu
->per_objfile
->per_bfd
->str_offsets
,
20331 *cu
->str_offsets_base
, str_index
);
20334 /* Return the length of an LEB128 number in BUF. */
20337 leb128_size (const gdb_byte
*buf
)
20339 const gdb_byte
*begin
= buf
;
20345 if ((byte
& 128) == 0)
20346 return buf
- begin
;
20350 static enum language
20351 dwarf_lang_to_enum_language (unsigned int lang
)
20353 enum language language
;
20362 language
= language_c
;
20365 case DW_LANG_C_plus_plus
:
20366 case DW_LANG_C_plus_plus_11
:
20367 case DW_LANG_C_plus_plus_14
:
20368 language
= language_cplus
;
20371 language
= language_d
;
20373 case DW_LANG_Fortran77
:
20374 case DW_LANG_Fortran90
:
20375 case DW_LANG_Fortran95
:
20376 case DW_LANG_Fortran03
:
20377 case DW_LANG_Fortran08
:
20378 language
= language_fortran
;
20381 language
= language_go
;
20383 case DW_LANG_Mips_Assembler
:
20384 language
= language_asm
;
20386 case DW_LANG_Ada83
:
20387 case DW_LANG_Ada95
:
20388 language
= language_ada
;
20390 case DW_LANG_Modula2
:
20391 language
= language_m2
;
20393 case DW_LANG_Pascal83
:
20394 language
= language_pascal
;
20397 language
= language_objc
;
20400 case DW_LANG_Rust_old
:
20401 language
= language_rust
;
20403 case DW_LANG_OpenCL
:
20404 language
= language_opencl
;
20406 case DW_LANG_Cobol74
:
20407 case DW_LANG_Cobol85
:
20409 language
= language_minimal
;
20416 /* Return the named attribute or NULL if not there. */
20418 static struct attribute
*
20419 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20424 struct attribute
*spec
= NULL
;
20426 for (i
= 0; i
< die
->num_attrs
; ++i
)
20428 if (die
->attrs
[i
].name
== name
)
20429 return &die
->attrs
[i
];
20430 if (die
->attrs
[i
].name
== DW_AT_specification
20431 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20432 spec
= &die
->attrs
[i
];
20438 die
= follow_die_ref (die
, spec
, &cu
);
20444 /* Return the string associated with a string-typed attribute, or NULL if it
20445 is either not found or is of an incorrect type. */
20447 static const char *
20448 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20450 struct attribute
*attr
;
20451 const char *str
= NULL
;
20453 attr
= dwarf2_attr (die
, name
, cu
);
20457 str
= attr
->as_string ();
20458 if (str
== nullptr)
20459 complaint (_("string type expected for attribute %s for "
20460 "DIE at %s in module %s"),
20461 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20462 objfile_name (cu
->per_objfile
->objfile
));
20468 /* Return the dwo name or NULL if not present. If present, it is in either
20469 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20470 static const char *
20471 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20473 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20474 if (dwo_name
== nullptr)
20475 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20479 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20480 and holds a non-zero value. This function should only be used for
20481 DW_FORM_flag or DW_FORM_flag_present attributes. */
20484 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20486 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20488 return attr
!= nullptr && attr
->as_boolean ();
20492 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20494 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20495 which value is non-zero. However, we have to be careful with
20496 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20497 (via dwarf2_flag_true_p) follows this attribute. So we may
20498 end up accidently finding a declaration attribute that belongs
20499 to a different DIE referenced by the specification attribute,
20500 even though the given DIE does not have a declaration attribute. */
20501 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20502 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20505 /* Return the die giving the specification for DIE, if there is
20506 one. *SPEC_CU is the CU containing DIE on input, and the CU
20507 containing the return value on output. If there is no
20508 specification, but there is an abstract origin, that is
20511 static struct die_info
*
20512 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20514 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20517 if (spec_attr
== NULL
)
20518 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20520 if (spec_attr
== NULL
)
20523 return follow_die_ref (die
, spec_attr
, spec_cu
);
20526 /* A convenience function to find the proper .debug_line section for a CU. */
20528 static struct dwarf2_section_info
*
20529 get_debug_line_section (struct dwarf2_cu
*cu
)
20531 struct dwarf2_section_info
*section
;
20532 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20534 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20536 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20537 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20538 else if (cu
->per_cu
->is_dwz
)
20540 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20542 section
= &dwz
->line
;
20545 section
= &per_objfile
->per_bfd
->line
;
20550 /* Read the statement program header starting at OFFSET in
20551 .debug_line, or .debug_line.dwo. Return a pointer
20552 to a struct line_header, allocated using xmalloc.
20553 Returns NULL if there is a problem reading the header, e.g., if it
20554 has a version we don't understand.
20556 NOTE: the strings in the include directory and file name tables of
20557 the returned object point into the dwarf line section buffer,
20558 and must not be freed. */
20560 static line_header_up
20561 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20563 struct dwarf2_section_info
*section
;
20564 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20566 section
= get_debug_line_section (cu
);
20567 section
->read (per_objfile
->objfile
);
20568 if (section
->buffer
== NULL
)
20570 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20571 complaint (_("missing .debug_line.dwo section"));
20573 complaint (_("missing .debug_line section"));
20577 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20578 per_objfile
, section
, &cu
->header
);
20581 /* Subroutine of dwarf_decode_lines to simplify it.
20582 Return the file name of the psymtab for the given file_entry.
20583 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20584 If space for the result is malloc'd, *NAME_HOLDER will be set.
20585 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20587 static const char *
20588 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20589 const dwarf2_psymtab
*pst
,
20590 const char *comp_dir
,
20591 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20593 const char *include_name
= fe
.name
;
20594 const char *include_name_to_compare
= include_name
;
20595 const char *pst_filename
;
20598 const char *dir_name
= fe
.include_dir (lh
);
20600 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20601 if (!IS_ABSOLUTE_PATH (include_name
)
20602 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20604 /* Avoid creating a duplicate psymtab for PST.
20605 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20606 Before we do the comparison, however, we need to account
20607 for DIR_NAME and COMP_DIR.
20608 First prepend dir_name (if non-NULL). If we still don't
20609 have an absolute path prepend comp_dir (if non-NULL).
20610 However, the directory we record in the include-file's
20611 psymtab does not contain COMP_DIR (to match the
20612 corresponding symtab(s)).
20617 bash$ gcc -g ./hello.c
20618 include_name = "hello.c"
20620 DW_AT_comp_dir = comp_dir = "/tmp"
20621 DW_AT_name = "./hello.c"
20625 if (dir_name
!= NULL
)
20627 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20628 include_name
, (char *) NULL
));
20629 include_name
= name_holder
->get ();
20630 include_name_to_compare
= include_name
;
20632 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20634 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20635 include_name
, (char *) NULL
));
20636 include_name_to_compare
= hold_compare
.get ();
20640 pst_filename
= pst
->filename
;
20641 gdb::unique_xmalloc_ptr
<char> copied_name
;
20642 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20644 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20645 pst_filename
, (char *) NULL
));
20646 pst_filename
= copied_name
.get ();
20649 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20653 return include_name
;
20656 /* State machine to track the state of the line number program. */
20658 class lnp_state_machine
20661 /* Initialize a machine state for the start of a line number
20663 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20664 bool record_lines_p
);
20666 file_entry
*current_file ()
20668 /* lh->file_names is 0-based, but the file name numbers in the
20669 statement program are 1-based. */
20670 return m_line_header
->file_name_at (m_file
);
20673 /* Record the line in the state machine. END_SEQUENCE is true if
20674 we're processing the end of a sequence. */
20675 void record_line (bool end_sequence
);
20677 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20678 nop-out rest of the lines in this sequence. */
20679 void check_line_address (struct dwarf2_cu
*cu
,
20680 const gdb_byte
*line_ptr
,
20681 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20683 void handle_set_discriminator (unsigned int discriminator
)
20685 m_discriminator
= discriminator
;
20686 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20689 /* Handle DW_LNE_set_address. */
20690 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20693 address
+= baseaddr
;
20694 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20697 /* Handle DW_LNS_advance_pc. */
20698 void handle_advance_pc (CORE_ADDR adjust
);
20700 /* Handle a special opcode. */
20701 void handle_special_opcode (unsigned char op_code
);
20703 /* Handle DW_LNS_advance_line. */
20704 void handle_advance_line (int line_delta
)
20706 advance_line (line_delta
);
20709 /* Handle DW_LNS_set_file. */
20710 void handle_set_file (file_name_index file
);
20712 /* Handle DW_LNS_negate_stmt. */
20713 void handle_negate_stmt ()
20715 m_is_stmt
= !m_is_stmt
;
20718 /* Handle DW_LNS_const_add_pc. */
20719 void handle_const_add_pc ();
20721 /* Handle DW_LNS_fixed_advance_pc. */
20722 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20724 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20728 /* Handle DW_LNS_copy. */
20729 void handle_copy ()
20731 record_line (false);
20732 m_discriminator
= 0;
20735 /* Handle DW_LNE_end_sequence. */
20736 void handle_end_sequence ()
20738 m_currently_recording_lines
= true;
20742 /* Advance the line by LINE_DELTA. */
20743 void advance_line (int line_delta
)
20745 m_line
+= line_delta
;
20747 if (line_delta
!= 0)
20748 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20751 struct dwarf2_cu
*m_cu
;
20753 gdbarch
*m_gdbarch
;
20755 /* True if we're recording lines.
20756 Otherwise we're building partial symtabs and are just interested in
20757 finding include files mentioned by the line number program. */
20758 bool m_record_lines_p
;
20760 /* The line number header. */
20761 line_header
*m_line_header
;
20763 /* These are part of the standard DWARF line number state machine,
20764 and initialized according to the DWARF spec. */
20766 unsigned char m_op_index
= 0;
20767 /* The line table index of the current file. */
20768 file_name_index m_file
= 1;
20769 unsigned int m_line
= 1;
20771 /* These are initialized in the constructor. */
20773 CORE_ADDR m_address
;
20775 unsigned int m_discriminator
;
20777 /* Additional bits of state we need to track. */
20779 /* The last file that we called dwarf2_start_subfile for.
20780 This is only used for TLLs. */
20781 unsigned int m_last_file
= 0;
20782 /* The last file a line number was recorded for. */
20783 struct subfile
*m_last_subfile
= NULL
;
20785 /* The address of the last line entry. */
20786 CORE_ADDR m_last_address
;
20788 /* Set to true when a previous line at the same address (using
20789 m_last_address) had m_is_stmt true. This is reset to false when a
20790 line entry at a new address (m_address different to m_last_address) is
20792 bool m_stmt_at_address
= false;
20794 /* When true, record the lines we decode. */
20795 bool m_currently_recording_lines
= false;
20797 /* The last line number that was recorded, used to coalesce
20798 consecutive entries for the same line. This can happen, for
20799 example, when discriminators are present. PR 17276. */
20800 unsigned int m_last_line
= 0;
20801 bool m_line_has_non_zero_discriminator
= false;
20805 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20807 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20808 / m_line_header
->maximum_ops_per_instruction
)
20809 * m_line_header
->minimum_instruction_length
);
20810 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20811 m_op_index
= ((m_op_index
+ adjust
)
20812 % m_line_header
->maximum_ops_per_instruction
);
20816 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20818 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20819 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
20820 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
20821 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
20822 / m_line_header
->maximum_ops_per_instruction
)
20823 * m_line_header
->minimum_instruction_length
);
20824 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20825 m_op_index
= ((m_op_index
+ adj_opcode_d
)
20826 % m_line_header
->maximum_ops_per_instruction
);
20828 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
20829 advance_line (line_delta
);
20830 record_line (false);
20831 m_discriminator
= 0;
20835 lnp_state_machine::handle_set_file (file_name_index file
)
20839 const file_entry
*fe
= current_file ();
20841 dwarf2_debug_line_missing_file_complaint ();
20842 else if (m_record_lines_p
)
20844 const char *dir
= fe
->include_dir (m_line_header
);
20846 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20847 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20848 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20853 lnp_state_machine::handle_const_add_pc ()
20856 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20859 = (((m_op_index
+ adjust
)
20860 / m_line_header
->maximum_ops_per_instruction
)
20861 * m_line_header
->minimum_instruction_length
);
20863 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20864 m_op_index
= ((m_op_index
+ adjust
)
20865 % m_line_header
->maximum_ops_per_instruction
);
20868 /* Return non-zero if we should add LINE to the line number table.
20869 LINE is the line to add, LAST_LINE is the last line that was added,
20870 LAST_SUBFILE is the subfile for LAST_LINE.
20871 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20872 had a non-zero discriminator.
20874 We have to be careful in the presence of discriminators.
20875 E.g., for this line:
20877 for (i = 0; i < 100000; i++);
20879 clang can emit four line number entries for that one line,
20880 each with a different discriminator.
20881 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20883 However, we want gdb to coalesce all four entries into one.
20884 Otherwise the user could stepi into the middle of the line and
20885 gdb would get confused about whether the pc really was in the
20886 middle of the line.
20888 Things are further complicated by the fact that two consecutive
20889 line number entries for the same line is a heuristic used by gcc
20890 to denote the end of the prologue. So we can't just discard duplicate
20891 entries, we have to be selective about it. The heuristic we use is
20892 that we only collapse consecutive entries for the same line if at least
20893 one of those entries has a non-zero discriminator. PR 17276.
20895 Note: Addresses in the line number state machine can never go backwards
20896 within one sequence, thus this coalescing is ok. */
20899 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20900 unsigned int line
, unsigned int last_line
,
20901 int line_has_non_zero_discriminator
,
20902 struct subfile
*last_subfile
)
20904 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20906 if (line
!= last_line
)
20908 /* Same line for the same file that we've seen already.
20909 As a last check, for pr 17276, only record the line if the line
20910 has never had a non-zero discriminator. */
20911 if (!line_has_non_zero_discriminator
)
20916 /* Use the CU's builder to record line number LINE beginning at
20917 address ADDRESS in the line table of subfile SUBFILE. */
20920 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20921 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
20922 struct dwarf2_cu
*cu
)
20924 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20926 if (dwarf_line_debug
)
20928 fprintf_unfiltered (gdb_stdlog
,
20929 "Recording line %u, file %s, address %s\n",
20930 line
, lbasename (subfile
->name
),
20931 paddress (gdbarch
, address
));
20935 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
20938 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20939 Mark the end of a set of line number records.
20940 The arguments are the same as for dwarf_record_line_1.
20941 If SUBFILE is NULL the request is ignored. */
20944 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20945 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20947 if (subfile
== NULL
)
20950 if (dwarf_line_debug
)
20952 fprintf_unfiltered (gdb_stdlog
,
20953 "Finishing current line, file %s, address %s\n",
20954 lbasename (subfile
->name
),
20955 paddress (gdbarch
, address
));
20958 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
20962 lnp_state_machine::record_line (bool end_sequence
)
20964 if (dwarf_line_debug
)
20966 fprintf_unfiltered (gdb_stdlog
,
20967 "Processing actual line %u: file %u,"
20968 " address %s, is_stmt %u, discrim %u%s\n",
20970 paddress (m_gdbarch
, m_address
),
20971 m_is_stmt
, m_discriminator
,
20972 (end_sequence
? "\t(end sequence)" : ""));
20975 file_entry
*fe
= current_file ();
20978 dwarf2_debug_line_missing_file_complaint ();
20979 /* For now we ignore lines not starting on an instruction boundary.
20980 But not when processing end_sequence for compatibility with the
20981 previous version of the code. */
20982 else if (m_op_index
== 0 || end_sequence
)
20984 fe
->included_p
= 1;
20985 if (m_record_lines_p
)
20987 /* When we switch files we insert an end maker in the first file,
20988 switch to the second file and add a new line entry. The
20989 problem is that the end marker inserted in the first file will
20990 discard any previous line entries at the same address. If the
20991 line entries in the first file are marked as is-stmt, while
20992 the new line in the second file is non-stmt, then this means
20993 the end marker will discard is-stmt lines so we can have a
20994 non-stmt line. This means that there are less addresses at
20995 which the user can insert a breakpoint.
20997 To improve this we track the last address in m_last_address,
20998 and whether we have seen an is-stmt at this address. Then
20999 when switching files, if we have seen a stmt at the current
21000 address, and we are switching to create a non-stmt line, then
21001 discard the new line. */
21003 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21004 bool ignore_this_line
21005 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21006 && !m_is_stmt
&& m_stmt_at_address
)
21007 || (!end_sequence
&& m_line
== 0));
21009 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21011 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21012 m_currently_recording_lines
? m_cu
: nullptr);
21015 if (!end_sequence
&& !ignore_this_line
)
21017 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21019 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21020 m_line_has_non_zero_discriminator
,
21023 buildsym_compunit
*builder
= m_cu
->get_builder ();
21024 dwarf_record_line_1 (m_gdbarch
,
21025 builder
->get_current_subfile (),
21026 m_line
, m_address
, is_stmt
,
21027 m_currently_recording_lines
? m_cu
: nullptr);
21029 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21030 m_last_line
= m_line
;
21035 /* Track whether we have seen any m_is_stmt true at m_address in case we
21036 have multiple line table entries all at m_address. */
21037 if (m_last_address
!= m_address
)
21039 m_stmt_at_address
= false;
21040 m_last_address
= m_address
;
21042 m_stmt_at_address
|= m_is_stmt
;
21045 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21046 line_header
*lh
, bool record_lines_p
)
21050 m_record_lines_p
= record_lines_p
;
21051 m_line_header
= lh
;
21053 m_currently_recording_lines
= true;
21055 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21056 was a line entry for it so that the backend has a chance to adjust it
21057 and also record it in case it needs it. This is currently used by MIPS
21058 code, cf. `mips_adjust_dwarf2_line'. */
21059 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21060 m_is_stmt
= lh
->default_is_stmt
;
21061 m_discriminator
= 0;
21063 m_last_address
= m_address
;
21064 m_stmt_at_address
= false;
21068 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21069 const gdb_byte
*line_ptr
,
21070 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21072 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21073 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21074 located at 0x0. In this case, additionally check that if
21075 ADDRESS < UNRELOCATED_LOWPC. */
21077 if ((address
== 0 && address
< unrelocated_lowpc
)
21078 || address
== (CORE_ADDR
) -1)
21080 /* This line table is for a function which has been
21081 GCd by the linker. Ignore it. PR gdb/12528 */
21083 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21084 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21086 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21087 line_offset
, objfile_name (objfile
));
21088 m_currently_recording_lines
= false;
21089 /* Note: m_currently_recording_lines is left as false until we see
21090 DW_LNE_end_sequence. */
21094 /* Subroutine of dwarf_decode_lines to simplify it.
21095 Process the line number information in LH.
21096 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21097 program in order to set included_p for every referenced header. */
21100 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21101 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21103 const gdb_byte
*line_ptr
, *extended_end
;
21104 const gdb_byte
*line_end
;
21105 unsigned int bytes_read
, extended_len
;
21106 unsigned char op_code
, extended_op
;
21107 CORE_ADDR baseaddr
;
21108 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21109 bfd
*abfd
= objfile
->obfd
;
21110 struct gdbarch
*gdbarch
= objfile
->arch ();
21111 /* True if we're recording line info (as opposed to building partial
21112 symtabs and just interested in finding include files mentioned by
21113 the line number program). */
21114 bool record_lines_p
= !decode_for_pst_p
;
21116 baseaddr
= objfile
->text_section_offset ();
21118 line_ptr
= lh
->statement_program_start
;
21119 line_end
= lh
->statement_program_end
;
21121 /* Read the statement sequences until there's nothing left. */
21122 while (line_ptr
< line_end
)
21124 /* The DWARF line number program state machine. Reset the state
21125 machine at the start of each sequence. */
21126 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21127 bool end_sequence
= false;
21129 if (record_lines_p
)
21131 /* Start a subfile for the current file of the state
21133 const file_entry
*fe
= state_machine
.current_file ();
21136 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21139 /* Decode the table. */
21140 while (line_ptr
< line_end
&& !end_sequence
)
21142 op_code
= read_1_byte (abfd
, line_ptr
);
21145 if (op_code
>= lh
->opcode_base
)
21147 /* Special opcode. */
21148 state_machine
.handle_special_opcode (op_code
);
21150 else switch (op_code
)
21152 case DW_LNS_extended_op
:
21153 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21155 line_ptr
+= bytes_read
;
21156 extended_end
= line_ptr
+ extended_len
;
21157 extended_op
= read_1_byte (abfd
, line_ptr
);
21159 if (DW_LNE_lo_user
<= extended_op
21160 && extended_op
<= DW_LNE_hi_user
)
21162 /* Vendor extension, ignore. */
21163 line_ptr
= extended_end
;
21166 switch (extended_op
)
21168 case DW_LNE_end_sequence
:
21169 state_machine
.handle_end_sequence ();
21170 end_sequence
= true;
21172 case DW_LNE_set_address
:
21175 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21176 line_ptr
+= bytes_read
;
21178 state_machine
.check_line_address (cu
, line_ptr
,
21179 lowpc
- baseaddr
, address
);
21180 state_machine
.handle_set_address (baseaddr
, address
);
21183 case DW_LNE_define_file
:
21185 const char *cur_file
;
21186 unsigned int mod_time
, length
;
21189 cur_file
= read_direct_string (abfd
, line_ptr
,
21191 line_ptr
+= bytes_read
;
21192 dindex
= (dir_index
)
21193 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21194 line_ptr
+= bytes_read
;
21196 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21197 line_ptr
+= bytes_read
;
21199 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21200 line_ptr
+= bytes_read
;
21201 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21204 case DW_LNE_set_discriminator
:
21206 /* The discriminator is not interesting to the
21207 debugger; just ignore it. We still need to
21208 check its value though:
21209 if there are consecutive entries for the same
21210 (non-prologue) line we want to coalesce them.
21213 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21214 line_ptr
+= bytes_read
;
21216 state_machine
.handle_set_discriminator (discr
);
21220 complaint (_("mangled .debug_line section"));
21223 /* Make sure that we parsed the extended op correctly. If e.g.
21224 we expected a different address size than the producer used,
21225 we may have read the wrong number of bytes. */
21226 if (line_ptr
!= extended_end
)
21228 complaint (_("mangled .debug_line section"));
21233 state_machine
.handle_copy ();
21235 case DW_LNS_advance_pc
:
21238 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21239 line_ptr
+= bytes_read
;
21241 state_machine
.handle_advance_pc (adjust
);
21244 case DW_LNS_advance_line
:
21247 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21248 line_ptr
+= bytes_read
;
21250 state_machine
.handle_advance_line (line_delta
);
21253 case DW_LNS_set_file
:
21255 file_name_index file
21256 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21258 line_ptr
+= bytes_read
;
21260 state_machine
.handle_set_file (file
);
21263 case DW_LNS_set_column
:
21264 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21265 line_ptr
+= bytes_read
;
21267 case DW_LNS_negate_stmt
:
21268 state_machine
.handle_negate_stmt ();
21270 case DW_LNS_set_basic_block
:
21272 /* Add to the address register of the state machine the
21273 address increment value corresponding to special opcode
21274 255. I.e., this value is scaled by the minimum
21275 instruction length since special opcode 255 would have
21276 scaled the increment. */
21277 case DW_LNS_const_add_pc
:
21278 state_machine
.handle_const_add_pc ();
21280 case DW_LNS_fixed_advance_pc
:
21282 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21285 state_machine
.handle_fixed_advance_pc (addr_adj
);
21290 /* Unknown standard opcode, ignore it. */
21293 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21295 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21296 line_ptr
+= bytes_read
;
21303 dwarf2_debug_line_missing_end_sequence_complaint ();
21305 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21306 in which case we still finish recording the last line). */
21307 state_machine
.record_line (true);
21311 /* Decode the Line Number Program (LNP) for the given line_header
21312 structure and CU. The actual information extracted and the type
21313 of structures created from the LNP depends on the value of PST.
21315 1. If PST is NULL, then this procedure uses the data from the program
21316 to create all necessary symbol tables, and their linetables.
21318 2. If PST is not NULL, this procedure reads the program to determine
21319 the list of files included by the unit represented by PST, and
21320 builds all the associated partial symbol tables.
21322 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21323 It is used for relative paths in the line table.
21324 NOTE: When processing partial symtabs (pst != NULL),
21325 comp_dir == pst->dirname.
21327 NOTE: It is important that psymtabs have the same file name (via strcmp)
21328 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21329 symtab we don't use it in the name of the psymtabs we create.
21330 E.g. expand_line_sal requires this when finding psymtabs to expand.
21331 A good testcase for this is mb-inline.exp.
21333 LOWPC is the lowest address in CU (or 0 if not known).
21335 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21336 for its PC<->lines mapping information. Otherwise only the filename
21337 table is read in. */
21340 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21341 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21342 CORE_ADDR lowpc
, int decode_mapping
)
21344 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21345 const int decode_for_pst_p
= (pst
!= NULL
);
21347 if (decode_mapping
)
21348 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21350 if (decode_for_pst_p
)
21352 /* Now that we're done scanning the Line Header Program, we can
21353 create the psymtab of each included file. */
21354 for (auto &file_entry
: lh
->file_names ())
21355 if (file_entry
.included_p
== 1)
21357 gdb::unique_xmalloc_ptr
<char> name_holder
;
21358 const char *include_name
=
21359 psymtab_include_file_name (lh
, file_entry
, pst
,
21360 comp_dir
, &name_holder
);
21361 if (include_name
!= NULL
)
21362 dwarf2_create_include_psymtab
21363 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21364 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21370 /* Make sure a symtab is created for every file, even files
21371 which contain only variables (i.e. no code with associated
21373 buildsym_compunit
*builder
= cu
->get_builder ();
21374 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21376 for (auto &fe
: lh
->file_names ())
21378 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21379 if (builder
->get_current_subfile ()->symtab
== NULL
)
21381 builder
->get_current_subfile ()->symtab
21382 = allocate_symtab (cust
,
21383 builder
->get_current_subfile ()->name
);
21385 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21390 /* Start a subfile for DWARF. FILENAME is the name of the file and
21391 DIRNAME the name of the source directory which contains FILENAME
21392 or NULL if not known.
21393 This routine tries to keep line numbers from identical absolute and
21394 relative file names in a common subfile.
21396 Using the `list' example from the GDB testsuite, which resides in
21397 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21398 of /srcdir/list0.c yields the following debugging information for list0.c:
21400 DW_AT_name: /srcdir/list0.c
21401 DW_AT_comp_dir: /compdir
21402 files.files[0].name: list0.h
21403 files.files[0].dir: /srcdir
21404 files.files[1].name: list0.c
21405 files.files[1].dir: /srcdir
21407 The line number information for list0.c has to end up in a single
21408 subfile, so that `break /srcdir/list0.c:1' works as expected.
21409 start_subfile will ensure that this happens provided that we pass the
21410 concatenation of files.files[1].dir and files.files[1].name as the
21414 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21415 const char *dirname
)
21417 gdb::unique_xmalloc_ptr
<char> copy
;
21419 /* In order not to lose the line information directory,
21420 we concatenate it to the filename when it makes sense.
21421 Note that the Dwarf3 standard says (speaking of filenames in line
21422 information): ``The directory index is ignored for file names
21423 that represent full path names''. Thus ignoring dirname in the
21424 `else' branch below isn't an issue. */
21426 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21428 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21429 filename
= copy
.get ();
21432 cu
->get_builder ()->start_subfile (filename
);
21436 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21437 struct dwarf2_cu
*cu
)
21439 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21440 struct comp_unit_head
*cu_header
= &cu
->header
;
21442 /* NOTE drow/2003-01-30: There used to be a comment and some special
21443 code here to turn a symbol with DW_AT_external and a
21444 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21445 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21446 with some versions of binutils) where shared libraries could have
21447 relocations against symbols in their debug information - the
21448 minimal symbol would have the right address, but the debug info
21449 would not. It's no longer necessary, because we will explicitly
21450 apply relocations when we read in the debug information now. */
21452 /* A DW_AT_location attribute with no contents indicates that a
21453 variable has been optimized away. */
21454 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21456 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21460 /* Handle one degenerate form of location expression specially, to
21461 preserve GDB's previous behavior when section offsets are
21462 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21463 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21465 if (attr
->form_is_block ())
21467 struct dwarf_block
*block
= attr
->as_block ();
21469 if ((block
->data
[0] == DW_OP_addr
21470 && block
->size
== 1 + cu_header
->addr_size
)
21471 || ((block
->data
[0] == DW_OP_GNU_addr_index
21472 || block
->data
[0] == DW_OP_addrx
)
21474 == 1 + leb128_size (&block
->data
[1]))))
21476 unsigned int dummy
;
21478 if (block
->data
[0] == DW_OP_addr
)
21479 SET_SYMBOL_VALUE_ADDRESS
21480 (sym
, cu
->header
.read_address (objfile
->obfd
,
21484 SET_SYMBOL_VALUE_ADDRESS
21485 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21487 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21488 fixup_symbol_section (sym
, objfile
);
21489 SET_SYMBOL_VALUE_ADDRESS
21491 SYMBOL_VALUE_ADDRESS (sym
)
21492 + objfile
->section_offsets
[sym
->section_index ()]);
21497 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21498 expression evaluator, and use LOC_COMPUTED only when necessary
21499 (i.e. when the value of a register or memory location is
21500 referenced, or a thread-local block, etc.). Then again, it might
21501 not be worthwhile. I'm assuming that it isn't unless performance
21502 or memory numbers show me otherwise. */
21504 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21506 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21507 cu
->has_loclist
= true;
21510 /* Given a pointer to a DWARF information entry, figure out if we need
21511 to make a symbol table entry for it, and if so, create a new entry
21512 and return a pointer to it.
21513 If TYPE is NULL, determine symbol type from the die, otherwise
21514 used the passed type.
21515 If SPACE is not NULL, use it to hold the new symbol. If it is
21516 NULL, allocate a new symbol on the objfile's obstack. */
21518 static struct symbol
*
21519 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21520 struct symbol
*space
)
21522 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21523 struct objfile
*objfile
= per_objfile
->objfile
;
21524 struct gdbarch
*gdbarch
= objfile
->arch ();
21525 struct symbol
*sym
= NULL
;
21527 struct attribute
*attr
= NULL
;
21528 struct attribute
*attr2
= NULL
;
21529 CORE_ADDR baseaddr
;
21530 struct pending
**list_to_add
= NULL
;
21532 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21534 baseaddr
= objfile
->text_section_offset ();
21536 name
= dwarf2_name (die
, cu
);
21539 int suppress_add
= 0;
21544 sym
= new (&objfile
->objfile_obstack
) symbol
;
21545 OBJSTAT (objfile
, n_syms
++);
21547 /* Cache this symbol's name and the name's demangled form (if any). */
21548 sym
->set_language (cu
->per_cu
->lang
, &objfile
->objfile_obstack
);
21549 /* Fortran does not have mangling standard and the mangling does differ
21550 between gfortran, iFort etc. */
21551 const char *physname
21552 = (cu
->per_cu
->lang
== language_fortran
21553 ? dwarf2_full_name (name
, die
, cu
)
21554 : dwarf2_physname (name
, die
, cu
));
21555 const char *linkagename
= dw2_linkage_name (die
, cu
);
21557 if (linkagename
== nullptr || cu
->per_cu
->lang
== language_ada
)
21558 sym
->set_linkage_name (physname
);
21561 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21562 sym
->set_linkage_name (linkagename
);
21565 /* Default assumptions.
21566 Use the passed type or decode it from the die. */
21567 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21568 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21570 SYMBOL_TYPE (sym
) = type
;
21572 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21573 attr
= dwarf2_attr (die
,
21574 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21576 if (attr
!= nullptr)
21577 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21579 attr
= dwarf2_attr (die
,
21580 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21582 if (attr
!= nullptr && attr
->is_nonnegative ())
21584 file_name_index file_index
21585 = (file_name_index
) attr
->as_nonnegative ();
21586 struct file_entry
*fe
;
21588 if (cu
->line_header
!= NULL
)
21589 fe
= cu
->line_header
->file_name_at (file_index
);
21594 complaint (_("file index out of range"));
21596 symbol_set_symtab (sym
, fe
->symtab
);
21602 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21603 if (attr
!= nullptr)
21607 addr
= attr
->as_address ();
21608 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21609 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21610 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21613 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21614 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21615 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21616 add_symbol_to_list (sym
, cu
->list_in_scope
);
21618 case DW_TAG_subprogram
:
21619 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21621 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21622 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21623 if ((attr2
!= nullptr && attr2
->as_boolean ())
21624 || cu
->per_cu
->lang
== language_ada
21625 || cu
->per_cu
->lang
== language_fortran
)
21627 /* Subprograms marked external are stored as a global symbol.
21628 Ada and Fortran subprograms, whether marked external or
21629 not, are always stored as a global symbol, because we want
21630 to be able to access them globally. For instance, we want
21631 to be able to break on a nested subprogram without having
21632 to specify the context. */
21633 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21637 list_to_add
= cu
->list_in_scope
;
21640 case DW_TAG_inlined_subroutine
:
21641 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21643 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21644 SYMBOL_INLINED (sym
) = 1;
21645 list_to_add
= cu
->list_in_scope
;
21647 case DW_TAG_template_value_param
:
21649 /* Fall through. */
21650 case DW_TAG_constant
:
21651 case DW_TAG_variable
:
21652 case DW_TAG_member
:
21653 /* Compilation with minimal debug info may result in
21654 variables with missing type entries. Change the
21655 misleading `void' type to something sensible. */
21656 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21657 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21659 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21660 /* In the case of DW_TAG_member, we should only be called for
21661 static const members. */
21662 if (die
->tag
== DW_TAG_member
)
21664 /* dwarf2_add_field uses die_is_declaration,
21665 so we do the same. */
21666 gdb_assert (die_is_declaration (die
, cu
));
21669 if (attr
!= nullptr)
21671 dwarf2_const_value (attr
, sym
, cu
);
21672 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21675 if (attr2
!= nullptr && attr2
->as_boolean ())
21676 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21678 list_to_add
= cu
->list_in_scope
;
21682 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21683 if (attr
!= nullptr)
21685 var_decode_location (attr
, sym
, cu
);
21686 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21688 /* Fortran explicitly imports any global symbols to the local
21689 scope by DW_TAG_common_block. */
21690 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21691 && die
->parent
->tag
== DW_TAG_common_block
)
21694 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21695 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21696 && !per_objfile
->per_bfd
->has_section_at_zero
)
21698 /* When a static variable is eliminated by the linker,
21699 the corresponding debug information is not stripped
21700 out, but the variable address is set to null;
21701 do not add such variables into symbol table. */
21703 else if (attr2
!= nullptr && attr2
->as_boolean ())
21705 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21706 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21707 && per_objfile
->per_bfd
->can_copy
)
21709 /* A global static variable might be subject to
21710 copy relocation. We first check for a local
21711 minsym, though, because maybe the symbol was
21712 marked hidden, in which case this would not
21714 bound_minimal_symbol found
21715 = (lookup_minimal_symbol_linkage
21716 (sym
->linkage_name (), objfile
));
21717 if (found
.minsym
!= nullptr)
21718 sym
->maybe_copied
= 1;
21721 /* A variable with DW_AT_external is never static,
21722 but it may be block-scoped. */
21724 = ((cu
->list_in_scope
21725 == cu
->get_builder ()->get_file_symbols ())
21726 ? cu
->get_builder ()->get_global_symbols ()
21727 : cu
->list_in_scope
);
21730 list_to_add
= cu
->list_in_scope
;
21734 /* We do not know the address of this symbol.
21735 If it is an external symbol and we have type information
21736 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21737 The address of the variable will then be determined from
21738 the minimal symbol table whenever the variable is
21740 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21742 /* Fortran explicitly imports any global symbols to the local
21743 scope by DW_TAG_common_block. */
21744 if (cu
->per_cu
->lang
== language_fortran
&& die
->parent
21745 && die
->parent
->tag
== DW_TAG_common_block
)
21747 /* SYMBOL_CLASS doesn't matter here because
21748 read_common_block is going to reset it. */
21750 list_to_add
= cu
->list_in_scope
;
21752 else if (attr2
!= nullptr && attr2
->as_boolean ()
21753 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21755 /* A variable with DW_AT_external is never static, but it
21756 may be block-scoped. */
21758 = ((cu
->list_in_scope
21759 == cu
->get_builder ()->get_file_symbols ())
21760 ? cu
->get_builder ()->get_global_symbols ()
21761 : cu
->list_in_scope
);
21763 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21765 else if (!die_is_declaration (die
, cu
))
21767 /* Use the default LOC_OPTIMIZED_OUT class. */
21768 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21770 list_to_add
= cu
->list_in_scope
;
21774 case DW_TAG_formal_parameter
:
21776 /* If we are inside a function, mark this as an argument. If
21777 not, we might be looking at an argument to an inlined function
21778 when we do not have enough information to show inlined frames;
21779 pretend it's a local variable in that case so that the user can
21781 struct context_stack
*curr
21782 = cu
->get_builder ()->get_current_context_stack ();
21783 if (curr
!= nullptr && curr
->name
!= nullptr)
21784 SYMBOL_IS_ARGUMENT (sym
) = 1;
21785 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21786 if (attr
!= nullptr)
21788 var_decode_location (attr
, sym
, cu
);
21790 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21791 if (attr
!= nullptr)
21793 dwarf2_const_value (attr
, sym
, cu
);
21796 list_to_add
= cu
->list_in_scope
;
21799 case DW_TAG_unspecified_parameters
:
21800 /* From varargs functions; gdb doesn't seem to have any
21801 interest in this information, so just ignore it for now.
21804 case DW_TAG_template_type_param
:
21806 /* Fall through. */
21807 case DW_TAG_class_type
:
21808 case DW_TAG_interface_type
:
21809 case DW_TAG_structure_type
:
21810 case DW_TAG_union_type
:
21811 case DW_TAG_set_type
:
21812 case DW_TAG_enumeration_type
:
21813 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21814 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21817 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21818 really ever be static objects: otherwise, if you try
21819 to, say, break of a class's method and you're in a file
21820 which doesn't mention that class, it won't work unless
21821 the check for all static symbols in lookup_symbol_aux
21822 saves you. See the OtherFileClass tests in
21823 gdb.c++/namespace.exp. */
21827 buildsym_compunit
*builder
= cu
->get_builder ();
21829 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21830 && cu
->per_cu
->lang
== language_cplus
21831 ? builder
->get_global_symbols ()
21832 : cu
->list_in_scope
);
21834 /* The semantics of C++ state that "struct foo {
21835 ... }" also defines a typedef for "foo". */
21836 if (cu
->per_cu
->lang
== language_cplus
21837 || cu
->per_cu
->lang
== language_ada
21838 || cu
->per_cu
->lang
== language_d
21839 || cu
->per_cu
->lang
== language_rust
)
21841 /* The symbol's name is already allocated along
21842 with this objfile, so we don't need to
21843 duplicate it for the type. */
21844 if (SYMBOL_TYPE (sym
)->name () == 0)
21845 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
21850 case DW_TAG_typedef
:
21851 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21852 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21853 list_to_add
= cu
->list_in_scope
;
21855 case DW_TAG_array_type
:
21856 case DW_TAG_base_type
:
21857 case DW_TAG_subrange_type
:
21858 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21859 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21860 list_to_add
= cu
->list_in_scope
;
21862 case DW_TAG_enumerator
:
21863 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21864 if (attr
!= nullptr)
21866 dwarf2_const_value (attr
, sym
, cu
);
21869 /* NOTE: carlton/2003-11-10: See comment above in the
21870 DW_TAG_class_type, etc. block. */
21873 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21874 && cu
->per_cu
->lang
== language_cplus
21875 ? cu
->get_builder ()->get_global_symbols ()
21876 : cu
->list_in_scope
);
21879 case DW_TAG_imported_declaration
:
21880 case DW_TAG_namespace
:
21881 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21882 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21884 case DW_TAG_module
:
21885 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21886 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21887 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21889 case DW_TAG_common_block
:
21890 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21891 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21892 add_symbol_to_list (sym
, cu
->list_in_scope
);
21895 /* Not a tag we recognize. Hopefully we aren't processing
21896 trash data, but since we must specifically ignore things
21897 we don't recognize, there is nothing else we should do at
21899 complaint (_("unsupported tag: '%s'"),
21900 dwarf_tag_name (die
->tag
));
21906 sym
->hash_next
= objfile
->template_symbols
;
21907 objfile
->template_symbols
= sym
;
21908 list_to_add
= NULL
;
21911 if (list_to_add
!= NULL
)
21912 add_symbol_to_list (sym
, list_to_add
);
21914 /* For the benefit of old versions of GCC, check for anonymous
21915 namespaces based on the demangled name. */
21916 if (!cu
->processing_has_namespace_info
21917 && cu
->per_cu
->lang
== language_cplus
)
21918 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21923 /* Given an attr with a DW_FORM_dataN value in host byte order,
21924 zero-extend it as appropriate for the symbol's type. The DWARF
21925 standard (v4) is not entirely clear about the meaning of using
21926 DW_FORM_dataN for a constant with a signed type, where the type is
21927 wider than the data. The conclusion of a discussion on the DWARF
21928 list was that this is unspecified. We choose to always zero-extend
21929 because that is the interpretation long in use by GCC. */
21932 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21933 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21935 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21936 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21937 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21938 LONGEST l
= attr
->constant_value (0);
21940 if (bits
< sizeof (*value
) * 8)
21942 l
&= ((LONGEST
) 1 << bits
) - 1;
21945 else if (bits
== sizeof (*value
) * 8)
21949 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21950 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21957 /* Read a constant value from an attribute. Either set *VALUE, or if
21958 the value does not fit in *VALUE, set *BYTES - either already
21959 allocated on the objfile obstack, or newly allocated on OBSTACK,
21960 or, set *BATON, if we translated the constant to a location
21964 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21965 const char *name
, struct obstack
*obstack
,
21966 struct dwarf2_cu
*cu
,
21967 LONGEST
*value
, const gdb_byte
**bytes
,
21968 struct dwarf2_locexpr_baton
**baton
)
21970 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21971 struct objfile
*objfile
= per_objfile
->objfile
;
21972 struct comp_unit_head
*cu_header
= &cu
->header
;
21973 struct dwarf_block
*blk
;
21974 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21975 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21981 switch (attr
->form
)
21984 case DW_FORM_addrx
:
21985 case DW_FORM_GNU_addr_index
:
21989 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21990 dwarf2_const_value_length_mismatch_complaint (name
,
21991 cu_header
->addr_size
,
21992 TYPE_LENGTH (type
));
21993 /* Symbols of this form are reasonably rare, so we just
21994 piggyback on the existing location code rather than writing
21995 a new implementation of symbol_computed_ops. */
21996 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21997 (*baton
)->per_objfile
= per_objfile
;
21998 (*baton
)->per_cu
= cu
->per_cu
;
21999 gdb_assert ((*baton
)->per_cu
);
22001 (*baton
)->size
= 2 + cu_header
->addr_size
;
22002 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22003 (*baton
)->data
= data
;
22005 data
[0] = DW_OP_addr
;
22006 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22007 byte_order
, attr
->as_address ());
22008 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22011 case DW_FORM_string
:
22014 case DW_FORM_GNU_str_index
:
22015 case DW_FORM_GNU_strp_alt
:
22016 /* The string is already allocated on the objfile obstack, point
22018 *bytes
= (const gdb_byte
*) attr
->as_string ();
22020 case DW_FORM_block1
:
22021 case DW_FORM_block2
:
22022 case DW_FORM_block4
:
22023 case DW_FORM_block
:
22024 case DW_FORM_exprloc
:
22025 case DW_FORM_data16
:
22026 blk
= attr
->as_block ();
22027 if (TYPE_LENGTH (type
) != blk
->size
)
22028 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22029 TYPE_LENGTH (type
));
22030 *bytes
= blk
->data
;
22033 /* The DW_AT_const_value attributes are supposed to carry the
22034 symbol's value "represented as it would be on the target
22035 architecture." By the time we get here, it's already been
22036 converted to host endianness, so we just need to sign- or
22037 zero-extend it as appropriate. */
22038 case DW_FORM_data1
:
22039 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22041 case DW_FORM_data2
:
22042 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22044 case DW_FORM_data4
:
22045 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22047 case DW_FORM_data8
:
22048 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22051 case DW_FORM_sdata
:
22052 case DW_FORM_implicit_const
:
22053 *value
= attr
->as_signed ();
22056 case DW_FORM_udata
:
22057 *value
= attr
->as_unsigned ();
22061 complaint (_("unsupported const value attribute form: '%s'"),
22062 dwarf_form_name (attr
->form
));
22069 /* Copy constant value from an attribute to a symbol. */
22072 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22073 struct dwarf2_cu
*cu
)
22075 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22077 const gdb_byte
*bytes
;
22078 struct dwarf2_locexpr_baton
*baton
;
22080 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22081 sym
->print_name (),
22082 &objfile
->objfile_obstack
, cu
,
22083 &value
, &bytes
, &baton
);
22087 SYMBOL_LOCATION_BATON (sym
) = baton
;
22088 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22090 else if (bytes
!= NULL
)
22092 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22093 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22097 SYMBOL_VALUE (sym
) = value
;
22098 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22102 /* Return the type of the die in question using its DW_AT_type attribute. */
22104 static struct type
*
22105 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22107 struct attribute
*type_attr
;
22109 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22112 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22113 /* A missing DW_AT_type represents a void type. */
22114 return objfile_type (objfile
)->builtin_void
;
22117 return lookup_die_type (die
, type_attr
, cu
);
22120 /* True iff CU's producer generates GNAT Ada auxiliary information
22121 that allows to find parallel types through that information instead
22122 of having to do expensive parallel lookups by type name. */
22125 need_gnat_info (struct dwarf2_cu
*cu
)
22127 /* Assume that the Ada compiler was GNAT, which always produces
22128 the auxiliary information. */
22129 return (cu
->per_cu
->lang
== language_ada
);
22132 /* Return the auxiliary type of the die in question using its
22133 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22134 attribute is not present. */
22136 static struct type
*
22137 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22139 struct attribute
*type_attr
;
22141 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22145 return lookup_die_type (die
, type_attr
, cu
);
22148 /* If DIE has a descriptive_type attribute, then set the TYPE's
22149 descriptive type accordingly. */
22152 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22153 struct dwarf2_cu
*cu
)
22155 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22157 if (descriptive_type
)
22159 ALLOCATE_GNAT_AUX_TYPE (type
);
22160 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22164 /* Return the containing type of the die in question using its
22165 DW_AT_containing_type attribute. */
22167 static struct type
*
22168 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22170 struct attribute
*type_attr
;
22171 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22173 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22175 error (_("Dwarf Error: Problem turning containing type into gdb type "
22176 "[in module %s]"), objfile_name (objfile
));
22178 return lookup_die_type (die
, type_attr
, cu
);
22181 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22183 static struct type
*
22184 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22186 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22187 struct objfile
*objfile
= per_objfile
->objfile
;
22190 std::string message
22191 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22192 objfile_name (objfile
),
22193 sect_offset_str (cu
->header
.sect_off
),
22194 sect_offset_str (die
->sect_off
));
22195 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22197 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22200 /* Look up the type of DIE in CU using its type attribute ATTR.
22201 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22202 DW_AT_containing_type.
22203 If there is no type substitute an error marker. */
22205 static struct type
*
22206 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22207 struct dwarf2_cu
*cu
)
22209 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22210 struct objfile
*objfile
= per_objfile
->objfile
;
22211 struct type
*this_type
;
22213 gdb_assert (attr
->name
== DW_AT_type
22214 || attr
->name
== DW_AT_GNAT_descriptive_type
22215 || attr
->name
== DW_AT_containing_type
);
22217 /* First see if we have it cached. */
22219 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22221 struct dwarf2_per_cu_data
*per_cu
;
22222 sect_offset sect_off
= attr
->get_ref_die_offset ();
22224 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22225 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22227 else if (attr
->form_is_ref ())
22229 sect_offset sect_off
= attr
->get_ref_die_offset ();
22231 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22233 else if (attr
->form
== DW_FORM_ref_sig8
)
22235 ULONGEST signature
= attr
->as_signature ();
22237 return get_signatured_type (die
, signature
, cu
);
22241 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22242 " at %s [in module %s]"),
22243 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22244 objfile_name (objfile
));
22245 return build_error_marker_type (cu
, die
);
22248 /* If not cached we need to read it in. */
22250 if (this_type
== NULL
)
22252 struct die_info
*type_die
= NULL
;
22253 struct dwarf2_cu
*type_cu
= cu
;
22255 if (attr
->form_is_ref ())
22256 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22257 if (type_die
== NULL
)
22258 return build_error_marker_type (cu
, die
);
22259 /* If we find the type now, it's probably because the type came
22260 from an inter-CU reference and the type's CU got expanded before
22262 this_type
= read_type_die (type_die
, type_cu
);
22265 /* If we still don't have a type use an error marker. */
22267 if (this_type
== NULL
)
22268 return build_error_marker_type (cu
, die
);
22273 /* Return the type in DIE, CU.
22274 Returns NULL for invalid types.
22276 This first does a lookup in die_type_hash,
22277 and only reads the die in if necessary.
22279 NOTE: This can be called when reading in partial or full symbols. */
22281 static struct type
*
22282 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22284 struct type
*this_type
;
22286 this_type
= get_die_type (die
, cu
);
22290 return read_type_die_1 (die
, cu
);
22293 /* Read the type in DIE, CU.
22294 Returns NULL for invalid types. */
22296 static struct type
*
22297 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22299 struct type
*this_type
= NULL
;
22303 case DW_TAG_class_type
:
22304 case DW_TAG_interface_type
:
22305 case DW_TAG_structure_type
:
22306 case DW_TAG_union_type
:
22307 this_type
= read_structure_type (die
, cu
);
22309 case DW_TAG_enumeration_type
:
22310 this_type
= read_enumeration_type (die
, cu
);
22312 case DW_TAG_subprogram
:
22313 case DW_TAG_subroutine_type
:
22314 case DW_TAG_inlined_subroutine
:
22315 this_type
= read_subroutine_type (die
, cu
);
22317 case DW_TAG_array_type
:
22318 this_type
= read_array_type (die
, cu
);
22320 case DW_TAG_set_type
:
22321 this_type
= read_set_type (die
, cu
);
22323 case DW_TAG_pointer_type
:
22324 this_type
= read_tag_pointer_type (die
, cu
);
22326 case DW_TAG_ptr_to_member_type
:
22327 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22329 case DW_TAG_reference_type
:
22330 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22332 case DW_TAG_rvalue_reference_type
:
22333 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22335 case DW_TAG_const_type
:
22336 this_type
= read_tag_const_type (die
, cu
);
22338 case DW_TAG_volatile_type
:
22339 this_type
= read_tag_volatile_type (die
, cu
);
22341 case DW_TAG_restrict_type
:
22342 this_type
= read_tag_restrict_type (die
, cu
);
22344 case DW_TAG_string_type
:
22345 this_type
= read_tag_string_type (die
, cu
);
22347 case DW_TAG_typedef
:
22348 this_type
= read_typedef (die
, cu
);
22350 case DW_TAG_subrange_type
:
22351 this_type
= read_subrange_type (die
, cu
);
22353 case DW_TAG_base_type
:
22354 this_type
= read_base_type (die
, cu
);
22356 case DW_TAG_unspecified_type
:
22357 this_type
= read_unspecified_type (die
, cu
);
22359 case DW_TAG_namespace
:
22360 this_type
= read_namespace_type (die
, cu
);
22362 case DW_TAG_module
:
22363 this_type
= read_module_type (die
, cu
);
22365 case DW_TAG_atomic_type
:
22366 this_type
= read_tag_atomic_type (die
, cu
);
22369 complaint (_("unexpected tag in read_type_die: '%s'"),
22370 dwarf_tag_name (die
->tag
));
22377 /* See if we can figure out if the class lives in a namespace. We do
22378 this by looking for a member function; its demangled name will
22379 contain namespace info, if there is any.
22380 Return the computed name or NULL.
22381 Space for the result is allocated on the objfile's obstack.
22382 This is the full-die version of guess_partial_die_structure_name.
22383 In this case we know DIE has no useful parent. */
22385 static const char *
22386 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22388 struct die_info
*spec_die
;
22389 struct dwarf2_cu
*spec_cu
;
22390 struct die_info
*child
;
22391 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22394 spec_die
= die_specification (die
, &spec_cu
);
22395 if (spec_die
!= NULL
)
22401 for (child
= die
->child
;
22403 child
= child
->sibling
)
22405 if (child
->tag
== DW_TAG_subprogram
)
22407 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22409 if (linkage_name
!= NULL
)
22411 gdb::unique_xmalloc_ptr
<char> actual_name
22412 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22413 const char *name
= NULL
;
22415 if (actual_name
!= NULL
)
22417 const char *die_name
= dwarf2_name (die
, cu
);
22419 if (die_name
!= NULL
22420 && strcmp (die_name
, actual_name
.get ()) != 0)
22422 /* Strip off the class name from the full name.
22423 We want the prefix. */
22424 int die_name_len
= strlen (die_name
);
22425 int actual_name_len
= strlen (actual_name
.get ());
22426 const char *ptr
= actual_name
.get ();
22428 /* Test for '::' as a sanity check. */
22429 if (actual_name_len
> die_name_len
+ 2
22430 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22431 name
= obstack_strndup (
22432 &objfile
->per_bfd
->storage_obstack
,
22433 ptr
, actual_name_len
- die_name_len
- 2);
22444 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22445 prefix part in such case. See
22446 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22448 static const char *
22449 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22451 struct attribute
*attr
;
22454 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22455 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22458 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22461 attr
= dw2_linkage_name_attr (die
, cu
);
22462 const char *attr_name
= attr
->as_string ();
22463 if (attr
== NULL
|| attr_name
== NULL
)
22466 /* dwarf2_name had to be already called. */
22467 gdb_assert (attr
->canonical_string_p ());
22469 /* Strip the base name, keep any leading namespaces/classes. */
22470 base
= strrchr (attr_name
, ':');
22471 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22474 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22475 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22477 &base
[-1] - attr_name
);
22480 /* Return the name of the namespace/class that DIE is defined within,
22481 or "" if we can't tell. The caller should not xfree the result.
22483 For example, if we're within the method foo() in the following
22493 then determine_prefix on foo's die will return "N::C". */
22495 static const char *
22496 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22498 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22499 struct die_info
*parent
, *spec_die
;
22500 struct dwarf2_cu
*spec_cu
;
22501 struct type
*parent_type
;
22502 const char *retval
;
22504 if (cu
->per_cu
->lang
!= language_cplus
22505 && cu
->per_cu
->lang
!= language_fortran
22506 && cu
->per_cu
->lang
!= language_d
22507 && cu
->per_cu
->lang
!= language_rust
)
22510 retval
= anonymous_struct_prefix (die
, cu
);
22514 /* We have to be careful in the presence of DW_AT_specification.
22515 For example, with GCC 3.4, given the code
22519 // Definition of N::foo.
22523 then we'll have a tree of DIEs like this:
22525 1: DW_TAG_compile_unit
22526 2: DW_TAG_namespace // N
22527 3: DW_TAG_subprogram // declaration of N::foo
22528 4: DW_TAG_subprogram // definition of N::foo
22529 DW_AT_specification // refers to die #3
22531 Thus, when processing die #4, we have to pretend that we're in
22532 the context of its DW_AT_specification, namely the contex of die
22535 spec_die
= die_specification (die
, &spec_cu
);
22536 if (spec_die
== NULL
)
22537 parent
= die
->parent
;
22540 parent
= spec_die
->parent
;
22544 if (parent
== NULL
)
22546 else if (parent
->building_fullname
)
22549 const char *parent_name
;
22551 /* It has been seen on RealView 2.2 built binaries,
22552 DW_TAG_template_type_param types actually _defined_ as
22553 children of the parent class:
22556 template class <class Enum> Class{};
22557 Class<enum E> class_e;
22559 1: DW_TAG_class_type (Class)
22560 2: DW_TAG_enumeration_type (E)
22561 3: DW_TAG_enumerator (enum1:0)
22562 3: DW_TAG_enumerator (enum2:1)
22564 2: DW_TAG_template_type_param
22565 DW_AT_type DW_FORM_ref_udata (E)
22567 Besides being broken debug info, it can put GDB into an
22568 infinite loop. Consider:
22570 When we're building the full name for Class<E>, we'll start
22571 at Class, and go look over its template type parameters,
22572 finding E. We'll then try to build the full name of E, and
22573 reach here. We're now trying to build the full name of E,
22574 and look over the parent DIE for containing scope. In the
22575 broken case, if we followed the parent DIE of E, we'd again
22576 find Class, and once again go look at its template type
22577 arguments, etc., etc. Simply don't consider such parent die
22578 as source-level parent of this die (it can't be, the language
22579 doesn't allow it), and break the loop here. */
22580 name
= dwarf2_name (die
, cu
);
22581 parent_name
= dwarf2_name (parent
, cu
);
22582 complaint (_("template param type '%s' defined within parent '%s'"),
22583 name
? name
: "<unknown>",
22584 parent_name
? parent_name
: "<unknown>");
22588 switch (parent
->tag
)
22590 case DW_TAG_namespace
:
22591 parent_type
= read_type_die (parent
, cu
);
22592 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22593 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22594 Work around this problem here. */
22595 if (cu
->per_cu
->lang
== language_cplus
22596 && strcmp (parent_type
->name (), "::") == 0)
22598 /* We give a name to even anonymous namespaces. */
22599 return parent_type
->name ();
22600 case DW_TAG_class_type
:
22601 case DW_TAG_interface_type
:
22602 case DW_TAG_structure_type
:
22603 case DW_TAG_union_type
:
22604 case DW_TAG_module
:
22605 parent_type
= read_type_die (parent
, cu
);
22606 if (parent_type
->name () != NULL
)
22607 return parent_type
->name ();
22609 /* An anonymous structure is only allowed non-static data
22610 members; no typedefs, no member functions, et cetera.
22611 So it does not need a prefix. */
22613 case DW_TAG_compile_unit
:
22614 case DW_TAG_partial_unit
:
22615 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22616 if (cu
->per_cu
->lang
== language_cplus
22617 && !per_objfile
->per_bfd
->types
.empty ()
22618 && die
->child
!= NULL
22619 && (die
->tag
== DW_TAG_class_type
22620 || die
->tag
== DW_TAG_structure_type
22621 || die
->tag
== DW_TAG_union_type
))
22623 const char *name
= guess_full_die_structure_name (die
, cu
);
22628 case DW_TAG_subprogram
:
22629 /* Nested subroutines in Fortran get a prefix with the name
22630 of the parent's subroutine. */
22631 if (cu
->per_cu
->lang
== language_fortran
)
22633 if ((die
->tag
== DW_TAG_subprogram
)
22634 && (dwarf2_name (parent
, cu
) != NULL
))
22635 return dwarf2_name (parent
, cu
);
22637 return determine_prefix (parent
, cu
);
22638 case DW_TAG_enumeration_type
:
22639 parent_type
= read_type_die (parent
, cu
);
22640 if (parent_type
->is_declared_class ())
22642 if (parent_type
->name () != NULL
)
22643 return parent_type
->name ();
22646 /* Fall through. */
22648 return determine_prefix (parent
, cu
);
22652 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22653 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22654 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22655 an obconcat, otherwise allocate storage for the result. The CU argument is
22656 used to determine the language and hence, the appropriate separator. */
22658 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22661 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22662 int physname
, struct dwarf2_cu
*cu
)
22664 const char *lead
= "";
22667 if (suffix
== NULL
|| suffix
[0] == '\0'
22668 || prefix
== NULL
|| prefix
[0] == '\0')
22670 else if (cu
->per_cu
->lang
== language_d
)
22672 /* For D, the 'main' function could be defined in any module, but it
22673 should never be prefixed. */
22674 if (strcmp (suffix
, "D main") == 0)
22682 else if (cu
->per_cu
->lang
== language_fortran
&& physname
)
22684 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22685 DW_AT_MIPS_linkage_name is preferred and used instead. */
22693 if (prefix
== NULL
)
22695 if (suffix
== NULL
)
22702 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22704 strcpy (retval
, lead
);
22705 strcat (retval
, prefix
);
22706 strcat (retval
, sep
);
22707 strcat (retval
, suffix
);
22712 /* We have an obstack. */
22713 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22717 /* Get name of a die, return NULL if not found. */
22719 static const char *
22720 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22721 struct objfile
*objfile
)
22723 if (name
&& cu
->per_cu
->lang
== language_cplus
)
22725 gdb::unique_xmalloc_ptr
<char> canon_name
22726 = cp_canonicalize_string (name
);
22728 if (canon_name
!= nullptr)
22729 name
= objfile
->intern (canon_name
.get ());
22735 /* Get name of a die, return NULL if not found.
22736 Anonymous namespaces are converted to their magic string. */
22738 static const char *
22739 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22741 struct attribute
*attr
;
22742 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22744 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22745 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22746 if (attr_name
== nullptr
22747 && die
->tag
!= DW_TAG_namespace
22748 && die
->tag
!= DW_TAG_class_type
22749 && die
->tag
!= DW_TAG_interface_type
22750 && die
->tag
!= DW_TAG_structure_type
22751 && die
->tag
!= DW_TAG_union_type
)
22756 case DW_TAG_compile_unit
:
22757 case DW_TAG_partial_unit
:
22758 /* Compilation units have a DW_AT_name that is a filename, not
22759 a source language identifier. */
22760 case DW_TAG_enumeration_type
:
22761 case DW_TAG_enumerator
:
22762 /* These tags always have simple identifiers already; no need
22763 to canonicalize them. */
22766 case DW_TAG_namespace
:
22767 if (attr_name
!= nullptr)
22769 return CP_ANONYMOUS_NAMESPACE_STR
;
22771 case DW_TAG_class_type
:
22772 case DW_TAG_interface_type
:
22773 case DW_TAG_structure_type
:
22774 case DW_TAG_union_type
:
22775 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22776 structures or unions. These were of the form "._%d" in GCC 4.1,
22777 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22778 and GCC 4.4. We work around this problem by ignoring these. */
22779 if (attr_name
!= nullptr
22780 && (startswith (attr_name
, "._")
22781 || startswith (attr_name
, "<anonymous")))
22784 /* GCC might emit a nameless typedef that has a linkage name. See
22785 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22786 if (!attr
|| attr_name
== NULL
)
22788 attr
= dw2_linkage_name_attr (die
, cu
);
22789 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
22790 if (attr
== NULL
|| attr_name
== NULL
)
22793 /* Avoid demangling attr_name the second time on a second
22794 call for the same DIE. */
22795 if (!attr
->canonical_string_p ())
22797 gdb::unique_xmalloc_ptr
<char> demangled
22798 (gdb_demangle (attr_name
, DMGL_TYPES
));
22799 if (demangled
== nullptr)
22802 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
22803 attr_name
= attr
->as_string ();
22806 /* Strip any leading namespaces/classes, keep only the
22807 base name. DW_AT_name for named DIEs does not
22808 contain the prefixes. */
22809 const char *base
= strrchr (attr_name
, ':');
22810 if (base
&& base
> attr_name
&& base
[-1] == ':')
22821 if (!attr
->canonical_string_p ())
22822 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
22824 return attr
->as_string ();
22827 /* Return the die that this die in an extension of, or NULL if there
22828 is none. *EXT_CU is the CU containing DIE on input, and the CU
22829 containing the return value on output. */
22831 static struct die_info
*
22832 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22834 struct attribute
*attr
;
22836 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22840 return follow_die_ref (die
, attr
, ext_cu
);
22844 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22848 print_spaces (indent
, f
);
22849 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22850 dwarf_tag_name (die
->tag
), die
->abbrev
,
22851 sect_offset_str (die
->sect_off
));
22853 if (die
->parent
!= NULL
)
22855 print_spaces (indent
, f
);
22856 fprintf_unfiltered (f
, " parent at offset: %s\n",
22857 sect_offset_str (die
->parent
->sect_off
));
22860 print_spaces (indent
, f
);
22861 fprintf_unfiltered (f
, " has children: %s\n",
22862 dwarf_bool_name (die
->child
!= NULL
));
22864 print_spaces (indent
, f
);
22865 fprintf_unfiltered (f
, " attributes:\n");
22867 for (i
= 0; i
< die
->num_attrs
; ++i
)
22869 print_spaces (indent
, f
);
22870 fprintf_unfiltered (f
, " %s (%s) ",
22871 dwarf_attr_name (die
->attrs
[i
].name
),
22872 dwarf_form_name (die
->attrs
[i
].form
));
22874 switch (die
->attrs
[i
].form
)
22877 case DW_FORM_addrx
:
22878 case DW_FORM_GNU_addr_index
:
22879 fprintf_unfiltered (f
, "address: ");
22880 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
22882 case DW_FORM_block2
:
22883 case DW_FORM_block4
:
22884 case DW_FORM_block
:
22885 case DW_FORM_block1
:
22886 fprintf_unfiltered (f
, "block: size %s",
22887 pulongest (die
->attrs
[i
].as_block ()->size
));
22889 case DW_FORM_exprloc
:
22890 fprintf_unfiltered (f
, "expression: size %s",
22891 pulongest (die
->attrs
[i
].as_block ()->size
));
22893 case DW_FORM_data16
:
22894 fprintf_unfiltered (f
, "constant of 16 bytes");
22896 case DW_FORM_ref_addr
:
22897 fprintf_unfiltered (f
, "ref address: ");
22898 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22900 case DW_FORM_GNU_ref_alt
:
22901 fprintf_unfiltered (f
, "alt ref address: ");
22902 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
22908 case DW_FORM_ref_udata
:
22909 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22910 (long) (die
->attrs
[i
].as_unsigned ()));
22912 case DW_FORM_data1
:
22913 case DW_FORM_data2
:
22914 case DW_FORM_data4
:
22915 case DW_FORM_data8
:
22916 case DW_FORM_udata
:
22917 fprintf_unfiltered (f
, "constant: %s",
22918 pulongest (die
->attrs
[i
].as_unsigned ()));
22920 case DW_FORM_sec_offset
:
22921 fprintf_unfiltered (f
, "section offset: %s",
22922 pulongest (die
->attrs
[i
].as_unsigned ()));
22924 case DW_FORM_ref_sig8
:
22925 fprintf_unfiltered (f
, "signature: %s",
22926 hex_string (die
->attrs
[i
].as_signature ()));
22928 case DW_FORM_string
:
22930 case DW_FORM_line_strp
:
22932 case DW_FORM_GNU_str_index
:
22933 case DW_FORM_GNU_strp_alt
:
22934 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22935 die
->attrs
[i
].as_string ()
22936 ? die
->attrs
[i
].as_string () : "",
22937 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
22940 if (die
->attrs
[i
].as_boolean ())
22941 fprintf_unfiltered (f
, "flag: TRUE");
22943 fprintf_unfiltered (f
, "flag: FALSE");
22945 case DW_FORM_flag_present
:
22946 fprintf_unfiltered (f
, "flag: TRUE");
22948 case DW_FORM_indirect
:
22949 /* The reader will have reduced the indirect form to
22950 the "base form" so this form should not occur. */
22951 fprintf_unfiltered (f
,
22952 "unexpected attribute form: DW_FORM_indirect");
22954 case DW_FORM_sdata
:
22955 case DW_FORM_implicit_const
:
22956 fprintf_unfiltered (f
, "constant: %s",
22957 plongest (die
->attrs
[i
].as_signed ()));
22960 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22961 die
->attrs
[i
].form
);
22964 fprintf_unfiltered (f
, "\n");
22969 dump_die_for_error (struct die_info
*die
)
22971 dump_die_shallow (gdb_stderr
, 0, die
);
22975 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22977 int indent
= level
* 4;
22979 gdb_assert (die
!= NULL
);
22981 if (level
>= max_level
)
22984 dump_die_shallow (f
, indent
, die
);
22986 if (die
->child
!= NULL
)
22988 print_spaces (indent
, f
);
22989 fprintf_unfiltered (f
, " Children:");
22990 if (level
+ 1 < max_level
)
22992 fprintf_unfiltered (f
, "\n");
22993 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22997 fprintf_unfiltered (f
,
22998 " [not printed, max nesting level reached]\n");
23002 if (die
->sibling
!= NULL
&& level
> 0)
23004 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23008 /* This is called from the pdie macro in gdbinit.in.
23009 It's not static so gcc will keep a copy callable from gdb. */
23012 dump_die (struct die_info
*die
, int max_level
)
23014 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23018 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23022 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23023 to_underlying (die
->sect_off
),
23029 /* Follow reference or signature attribute ATTR of SRC_DIE.
23030 On entry *REF_CU is the CU of SRC_DIE.
23031 On exit *REF_CU is the CU of the result. */
23033 static struct die_info
*
23034 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23035 struct dwarf2_cu
**ref_cu
)
23037 struct die_info
*die
;
23039 if (attr
->form_is_ref ())
23040 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23041 else if (attr
->form
== DW_FORM_ref_sig8
)
23042 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23045 dump_die_for_error (src_die
);
23046 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23047 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23053 /* Follow reference OFFSET.
23054 On entry *REF_CU is the CU of the source die referencing OFFSET.
23055 On exit *REF_CU is the CU of the result.
23056 Returns NULL if OFFSET is invalid. */
23058 static struct die_info
*
23059 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23060 struct dwarf2_cu
**ref_cu
)
23062 struct die_info temp_die
;
23063 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23064 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23066 gdb_assert (cu
->per_cu
!= NULL
);
23070 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23071 "source CU contains target offset: %d",
23072 sect_offset_str (cu
->per_cu
->sect_off
),
23073 sect_offset_str (sect_off
),
23074 cu
->header
.offset_in_cu_p (sect_off
));
23076 if (cu
->per_cu
->is_debug_types
)
23078 /* .debug_types CUs cannot reference anything outside their CU.
23079 If they need to, they have to reference a signatured type via
23080 DW_FORM_ref_sig8. */
23081 if (!cu
->header
.offset_in_cu_p (sect_off
))
23084 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23085 || !cu
->header
.offset_in_cu_p (sect_off
))
23087 struct dwarf2_per_cu_data
*per_cu
;
23089 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23092 dwarf_read_debug_printf_v ("target CU offset: %s, "
23093 "target CU DIEs loaded: %d",
23094 sect_offset_str (per_cu
->sect_off
),
23095 per_objfile
->get_cu (per_cu
) != nullptr);
23097 /* If necessary, add it to the queue and load its DIEs.
23099 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23100 it doesn't mean they are currently loaded. Since we require them
23101 to be loaded, we must check for ourselves. */
23102 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->per_cu
->lang
)
23103 || per_objfile
->get_cu (per_cu
) == nullptr)
23104 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23105 false, cu
->per_cu
->lang
);
23107 target_cu
= per_objfile
->get_cu (per_cu
);
23108 gdb_assert (target_cu
!= nullptr);
23110 else if (cu
->dies
== NULL
)
23112 /* We're loading full DIEs during partial symbol reading. */
23113 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23114 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23118 *ref_cu
= target_cu
;
23119 temp_die
.sect_off
= sect_off
;
23121 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23123 to_underlying (sect_off
));
23126 /* Follow reference attribute ATTR of SRC_DIE.
23127 On entry *REF_CU is the CU of SRC_DIE.
23128 On exit *REF_CU is the CU of the result. */
23130 static struct die_info
*
23131 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23132 struct dwarf2_cu
**ref_cu
)
23134 sect_offset sect_off
= attr
->get_ref_die_offset ();
23135 struct dwarf2_cu
*cu
= *ref_cu
;
23136 struct die_info
*die
;
23138 die
= follow_die_offset (sect_off
,
23139 (attr
->form
== DW_FORM_GNU_ref_alt
23140 || cu
->per_cu
->is_dwz
),
23143 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23144 "at %s [in module %s]"),
23145 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23146 objfile_name (cu
->per_objfile
->objfile
));
23153 struct dwarf2_locexpr_baton
23154 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23155 dwarf2_per_cu_data
*per_cu
,
23156 dwarf2_per_objfile
*per_objfile
,
23157 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23158 bool resolve_abstract_p
)
23160 struct die_info
*die
;
23161 struct attribute
*attr
;
23162 struct dwarf2_locexpr_baton retval
;
23163 struct objfile
*objfile
= per_objfile
->objfile
;
23165 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23167 cu
= load_cu (per_cu
, per_objfile
, false);
23171 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23172 Instead just throw an error, not much else we can do. */
23173 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23174 sect_offset_str (sect_off
), objfile_name (objfile
));
23177 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23179 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23180 sect_offset_str (sect_off
), objfile_name (objfile
));
23182 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23183 if (!attr
&& resolve_abstract_p
23184 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23185 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23187 CORE_ADDR pc
= get_frame_pc ();
23188 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23189 struct gdbarch
*gdbarch
= objfile
->arch ();
23191 for (const auto &cand_off
23192 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23194 struct dwarf2_cu
*cand_cu
= cu
;
23195 struct die_info
*cand
23196 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23199 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23202 CORE_ADDR pc_low
, pc_high
;
23203 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23204 if (pc_low
== ((CORE_ADDR
) -1))
23206 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23207 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23208 if (!(pc_low
<= pc
&& pc
< pc_high
))
23212 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23219 /* DWARF: "If there is no such attribute, then there is no effect.".
23220 DATA is ignored if SIZE is 0. */
23222 retval
.data
= NULL
;
23225 else if (attr
->form_is_section_offset ())
23227 struct dwarf2_loclist_baton loclist_baton
;
23228 CORE_ADDR pc
= get_frame_pc ();
23231 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23233 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23235 retval
.size
= size
;
23239 if (!attr
->form_is_block ())
23240 error (_("Dwarf Error: DIE at %s referenced in module %s "
23241 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23242 sect_offset_str (sect_off
), objfile_name (objfile
));
23244 struct dwarf_block
*block
= attr
->as_block ();
23245 retval
.data
= block
->data
;
23246 retval
.size
= block
->size
;
23248 retval
.per_objfile
= per_objfile
;
23249 retval
.per_cu
= cu
->per_cu
;
23251 per_objfile
->age_comp_units ();
23258 struct dwarf2_locexpr_baton
23259 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23260 dwarf2_per_cu_data
*per_cu
,
23261 dwarf2_per_objfile
*per_objfile
,
23262 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23264 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23266 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23270 /* Write a constant of a given type as target-ordered bytes into
23273 static const gdb_byte
*
23274 write_constant_as_bytes (struct obstack
*obstack
,
23275 enum bfd_endian byte_order
,
23282 *len
= TYPE_LENGTH (type
);
23283 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23284 store_unsigned_integer (result
, *len
, byte_order
, value
);
23292 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23293 dwarf2_per_cu_data
*per_cu
,
23294 dwarf2_per_objfile
*per_objfile
,
23298 struct die_info
*die
;
23299 struct attribute
*attr
;
23300 const gdb_byte
*result
= NULL
;
23303 enum bfd_endian byte_order
;
23304 struct objfile
*objfile
= per_objfile
->objfile
;
23306 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23308 cu
= load_cu (per_cu
, per_objfile
, false);
23312 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23313 Instead just throw an error, not much else we can do. */
23314 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23315 sect_offset_str (sect_off
), objfile_name (objfile
));
23318 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23320 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23321 sect_offset_str (sect_off
), objfile_name (objfile
));
23323 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23327 byte_order
= (bfd_big_endian (objfile
->obfd
)
23328 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23330 switch (attr
->form
)
23333 case DW_FORM_addrx
:
23334 case DW_FORM_GNU_addr_index
:
23338 *len
= cu
->header
.addr_size
;
23339 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23340 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23344 case DW_FORM_string
:
23347 case DW_FORM_GNU_str_index
:
23348 case DW_FORM_GNU_strp_alt
:
23349 /* The string is already allocated on the objfile obstack, point
23352 const char *attr_name
= attr
->as_string ();
23353 result
= (const gdb_byte
*) attr_name
;
23354 *len
= strlen (attr_name
);
23357 case DW_FORM_block1
:
23358 case DW_FORM_block2
:
23359 case DW_FORM_block4
:
23360 case DW_FORM_block
:
23361 case DW_FORM_exprloc
:
23362 case DW_FORM_data16
:
23364 struct dwarf_block
*block
= attr
->as_block ();
23365 result
= block
->data
;
23366 *len
= block
->size
;
23370 /* The DW_AT_const_value attributes are supposed to carry the
23371 symbol's value "represented as it would be on the target
23372 architecture." By the time we get here, it's already been
23373 converted to host endianness, so we just need to sign- or
23374 zero-extend it as appropriate. */
23375 case DW_FORM_data1
:
23376 type
= die_type (die
, cu
);
23377 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23378 if (result
== NULL
)
23379 result
= write_constant_as_bytes (obstack
, byte_order
,
23382 case DW_FORM_data2
:
23383 type
= die_type (die
, cu
);
23384 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23385 if (result
== NULL
)
23386 result
= write_constant_as_bytes (obstack
, byte_order
,
23389 case DW_FORM_data4
:
23390 type
= die_type (die
, cu
);
23391 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23392 if (result
== NULL
)
23393 result
= write_constant_as_bytes (obstack
, byte_order
,
23396 case DW_FORM_data8
:
23397 type
= die_type (die
, cu
);
23398 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23399 if (result
== NULL
)
23400 result
= write_constant_as_bytes (obstack
, byte_order
,
23404 case DW_FORM_sdata
:
23405 case DW_FORM_implicit_const
:
23406 type
= die_type (die
, cu
);
23407 result
= write_constant_as_bytes (obstack
, byte_order
,
23408 type
, attr
->as_signed (), len
);
23411 case DW_FORM_udata
:
23412 type
= die_type (die
, cu
);
23413 result
= write_constant_as_bytes (obstack
, byte_order
,
23414 type
, attr
->as_unsigned (), len
);
23418 complaint (_("unsupported const value attribute form: '%s'"),
23419 dwarf_form_name (attr
->form
));
23429 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23430 dwarf2_per_cu_data
*per_cu
,
23431 dwarf2_per_objfile
*per_objfile
,
23432 const char **var_name
)
23434 struct die_info
*die
;
23436 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23438 cu
= load_cu (per_cu
, per_objfile
, false);
23443 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23447 if (var_name
!= nullptr)
23448 *var_name
= var_decl_name (die
, cu
);
23449 return die_type (die
, cu
);
23455 dwarf2_get_die_type (cu_offset die_offset
,
23456 dwarf2_per_cu_data
*per_cu
,
23457 dwarf2_per_objfile
*per_objfile
)
23459 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23460 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23463 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23464 On entry *REF_CU is the CU of SRC_DIE.
23465 On exit *REF_CU is the CU of the result.
23466 Returns NULL if the referenced DIE isn't found. */
23468 static struct die_info
*
23469 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23470 struct dwarf2_cu
**ref_cu
)
23472 struct die_info temp_die
;
23473 struct dwarf2_cu
*sig_cu
;
23474 struct die_info
*die
;
23475 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23478 /* While it might be nice to assert sig_type->type == NULL here,
23479 we can get here for DW_AT_imported_declaration where we need
23480 the DIE not the type. */
23482 /* If necessary, add it to the queue and load its DIEs.
23484 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23485 it doesn't mean they are currently loaded. Since we require them
23486 to be loaded, we must check for ourselves. */
23487 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23489 || per_objfile
->get_cu (sig_type
) == nullptr)
23490 read_signatured_type (sig_type
, per_objfile
);
23492 sig_cu
= per_objfile
->get_cu (sig_type
);
23493 gdb_assert (sig_cu
!= NULL
);
23494 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23495 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23496 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23497 to_underlying (temp_die
.sect_off
));
23500 /* For .gdb_index version 7 keep track of included TUs.
23501 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23502 if (per_objfile
->per_bfd
->index_table
!= NULL
23503 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23505 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23515 /* Follow signatured type referenced by ATTR in SRC_DIE.
23516 On entry *REF_CU is the CU of SRC_DIE.
23517 On exit *REF_CU is the CU of the result.
23518 The result is the DIE of the type.
23519 If the referenced type cannot be found an error is thrown. */
23521 static struct die_info
*
23522 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23523 struct dwarf2_cu
**ref_cu
)
23525 ULONGEST signature
= attr
->as_signature ();
23526 struct signatured_type
*sig_type
;
23527 struct die_info
*die
;
23529 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23531 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23532 /* sig_type will be NULL if the signatured type is missing from
23534 if (sig_type
== NULL
)
23536 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23537 " from DIE at %s [in module %s]"),
23538 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23539 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23542 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23545 dump_die_for_error (src_die
);
23546 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23547 " from DIE at %s [in module %s]"),
23548 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23549 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23555 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23556 reading in and processing the type unit if necessary. */
23558 static struct type
*
23559 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23560 struct dwarf2_cu
*cu
)
23562 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23563 struct signatured_type
*sig_type
;
23564 struct dwarf2_cu
*type_cu
;
23565 struct die_info
*type_die
;
23568 sig_type
= lookup_signatured_type (cu
, signature
);
23569 /* sig_type will be NULL if the signatured type is missing from
23571 if (sig_type
== NULL
)
23573 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23574 " from DIE at %s [in module %s]"),
23575 hex_string (signature
), sect_offset_str (die
->sect_off
),
23576 objfile_name (per_objfile
->objfile
));
23577 return build_error_marker_type (cu
, die
);
23580 /* If we already know the type we're done. */
23581 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23582 if (type
!= nullptr)
23586 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23587 if (type_die
!= NULL
)
23589 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23590 is created. This is important, for example, because for c++ classes
23591 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23592 type
= read_type_die (type_die
, type_cu
);
23595 complaint (_("Dwarf Error: Cannot build signatured type %s"
23596 " referenced from DIE at %s [in module %s]"),
23597 hex_string (signature
), sect_offset_str (die
->sect_off
),
23598 objfile_name (per_objfile
->objfile
));
23599 type
= build_error_marker_type (cu
, die
);
23604 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23605 " from DIE at %s [in module %s]"),
23606 hex_string (signature
), sect_offset_str (die
->sect_off
),
23607 objfile_name (per_objfile
->objfile
));
23608 type
= build_error_marker_type (cu
, die
);
23611 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23616 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23617 reading in and processing the type unit if necessary. */
23619 static struct type
*
23620 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23621 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23623 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23624 if (attr
->form_is_ref ())
23626 struct dwarf2_cu
*type_cu
= cu
;
23627 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23629 return read_type_die (type_die
, type_cu
);
23631 else if (attr
->form
== DW_FORM_ref_sig8
)
23633 return get_signatured_type (die
, attr
->as_signature (), cu
);
23637 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23639 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23640 " at %s [in module %s]"),
23641 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23642 objfile_name (per_objfile
->objfile
));
23643 return build_error_marker_type (cu
, die
);
23647 /* Load the DIEs associated with type unit PER_CU into memory. */
23650 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23651 dwarf2_per_objfile
*per_objfile
)
23653 struct signatured_type
*sig_type
;
23655 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23656 gdb_assert (! per_cu
->type_unit_group_p ());
23658 /* We have the per_cu, but we need the signatured_type.
23659 Fortunately this is an easy translation. */
23660 gdb_assert (per_cu
->is_debug_types
);
23661 sig_type
= (struct signatured_type
*) per_cu
;
23663 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23665 read_signatured_type (sig_type
, per_objfile
);
23667 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23670 /* Read in a signatured type and build its CU and DIEs.
23671 If the type is a stub for the real type in a DWO file,
23672 read in the real type from the DWO file as well. */
23675 read_signatured_type (signatured_type
*sig_type
,
23676 dwarf2_per_objfile
*per_objfile
)
23678 gdb_assert (sig_type
->is_debug_types
);
23679 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23681 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23683 if (!reader
.dummy_p
)
23685 struct dwarf2_cu
*cu
= reader
.cu
;
23686 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23688 gdb_assert (cu
->die_hash
== NULL
);
23690 htab_create_alloc_ex (cu
->header
.length
/ 12,
23694 &cu
->comp_unit_obstack
,
23695 hashtab_obstack_allocate
,
23696 dummy_obstack_deallocate
);
23698 if (reader
.comp_unit_die
->has_children
)
23699 reader
.comp_unit_die
->child
23700 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23701 reader
.comp_unit_die
);
23702 cu
->dies
= reader
.comp_unit_die
;
23703 /* comp_unit_die is not stored in die_hash, no need. */
23705 /* We try not to read any attributes in this function, because
23706 not all CUs needed for references have been loaded yet, and
23707 symbol table processing isn't initialized. But we have to
23708 set the CU language, or we won't be able to build types
23709 correctly. Similarly, if we do not read the producer, we can
23710 not apply producer-specific interpretation. */
23711 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23716 sig_type
->tu_read
= 1;
23719 /* Decode simple location descriptions.
23720 Given a pointer to a dwarf block that defines a location, compute
23721 the location and return the value. If COMPUTED is non-null, it is
23722 set to true to indicate that decoding was successful, and false
23723 otherwise. If COMPUTED is null, then this function may emit a
23727 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23729 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23731 size_t size
= blk
->size
;
23732 const gdb_byte
*data
= blk
->data
;
23733 CORE_ADDR stack
[64];
23735 unsigned int bytes_read
, unsnd
;
23738 if (computed
!= nullptr)
23744 stack
[++stacki
] = 0;
23783 stack
[++stacki
] = op
- DW_OP_lit0
;
23818 stack
[++stacki
] = op
- DW_OP_reg0
;
23821 if (computed
== nullptr)
23822 dwarf2_complex_location_expr_complaint ();
23829 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23831 stack
[++stacki
] = unsnd
;
23834 if (computed
== nullptr)
23835 dwarf2_complex_location_expr_complaint ();
23842 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
23847 case DW_OP_const1u
:
23848 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23852 case DW_OP_const1s
:
23853 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23857 case DW_OP_const2u
:
23858 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23862 case DW_OP_const2s
:
23863 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23867 case DW_OP_const4u
:
23868 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23872 case DW_OP_const4s
:
23873 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23877 case DW_OP_const8u
:
23878 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23883 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23889 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23894 stack
[stacki
+ 1] = stack
[stacki
];
23899 stack
[stacki
- 1] += stack
[stacki
];
23903 case DW_OP_plus_uconst
:
23904 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23910 stack
[stacki
- 1] -= stack
[stacki
];
23915 /* If we're not the last op, then we definitely can't encode
23916 this using GDB's address_class enum. This is valid for partial
23917 global symbols, although the variable's address will be bogus
23921 if (computed
== nullptr)
23922 dwarf2_complex_location_expr_complaint ();
23928 case DW_OP_GNU_push_tls_address
:
23929 case DW_OP_form_tls_address
:
23930 /* The top of the stack has the offset from the beginning
23931 of the thread control block at which the variable is located. */
23932 /* Nothing should follow this operator, so the top of stack would
23934 /* This is valid for partial global symbols, but the variable's
23935 address will be bogus in the psymtab. Make it always at least
23936 non-zero to not look as a variable garbage collected by linker
23937 which have DW_OP_addr 0. */
23940 if (computed
== nullptr)
23941 dwarf2_complex_location_expr_complaint ();
23948 case DW_OP_GNU_uninit
:
23949 if (computed
!= nullptr)
23954 case DW_OP_GNU_addr_index
:
23955 case DW_OP_GNU_const_index
:
23956 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23962 if (computed
== nullptr)
23964 const char *name
= get_DW_OP_name (op
);
23967 complaint (_("unsupported stack op: '%s'"),
23970 complaint (_("unsupported stack op: '%02x'"),
23974 return (stack
[stacki
]);
23977 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23978 outside of the allocated space. Also enforce minimum>0. */
23979 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23981 if (computed
== nullptr)
23982 complaint (_("location description stack overflow"));
23988 if (computed
== nullptr)
23989 complaint (_("location description stack underflow"));
23994 if (computed
!= nullptr)
23996 return (stack
[stacki
]);
23999 /* memory allocation interface */
24001 static struct dwarf_block
*
24002 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24004 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24007 static struct die_info
*
24008 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24010 struct die_info
*die
;
24011 size_t size
= sizeof (struct die_info
);
24014 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24016 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24017 memset (die
, 0, sizeof (struct die_info
));
24023 /* Macro support. */
24025 /* An overload of dwarf_decode_macros that finds the correct section
24026 and ensures it is read in before calling the other overload. */
24029 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24030 int section_is_gnu
)
24032 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24033 struct objfile
*objfile
= per_objfile
->objfile
;
24034 const struct line_header
*lh
= cu
->line_header
;
24035 unsigned int offset_size
= cu
->header
.offset_size
;
24036 struct dwarf2_section_info
*section
;
24037 const char *section_name
;
24039 if (cu
->dwo_unit
!= nullptr)
24041 if (section_is_gnu
)
24043 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24044 section_name
= ".debug_macro.dwo";
24048 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24049 section_name
= ".debug_macinfo.dwo";
24054 if (section_is_gnu
)
24056 section
= &per_objfile
->per_bfd
->macro
;
24057 section_name
= ".debug_macro";
24061 section
= &per_objfile
->per_bfd
->macinfo
;
24062 section_name
= ".debug_macinfo";
24066 section
->read (objfile
);
24067 if (section
->buffer
== nullptr)
24069 complaint (_("missing %s section"), section_name
);
24073 buildsym_compunit
*builder
= cu
->get_builder ();
24075 struct dwarf2_section_info
*str_offsets_section
;
24076 struct dwarf2_section_info
*str_section
;
24077 ULONGEST str_offsets_base
;
24079 if (cu
->dwo_unit
!= nullptr)
24081 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24082 ->sections
.str_offsets
;
24083 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24084 str_offsets_base
= cu
->header
.addr_size
;
24088 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24089 str_section
= &per_objfile
->per_bfd
->str
;
24090 str_offsets_base
= *cu
->str_offsets_base
;
24093 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24094 offset_size
, offset
, str_section
, str_offsets_section
,
24095 str_offsets_base
, section_is_gnu
);
24098 /* Return the .debug_loc section to use for CU.
24099 For DWO files use .debug_loc.dwo. */
24101 static struct dwarf2_section_info
*
24102 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24104 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24108 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24110 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24112 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24113 : &per_objfile
->per_bfd
->loc
);
24116 /* Return the .debug_rnglists section to use for CU. */
24117 static struct dwarf2_section_info
*
24118 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24120 if (cu
->header
.version
< 5)
24121 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24122 cu
->header
.version
);
24123 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24125 /* Make sure we read the .debug_rnglists section from the file that
24126 contains the DW_AT_ranges attribute we are reading. Normally that
24127 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24128 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24130 if (cu
->dwo_unit
!= nullptr
24131 && tag
!= DW_TAG_compile_unit
24132 && tag
!= DW_TAG_skeleton_unit
)
24134 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24136 if (sections
->rnglists
.size
> 0)
24137 return §ions
->rnglists
;
24139 error (_(".debug_rnglists section is missing from .dwo file."));
24141 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24144 /* A helper function that fills in a dwarf2_loclist_baton. */
24147 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24148 struct dwarf2_loclist_baton
*baton
,
24149 const struct attribute
*attr
)
24151 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24152 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24154 section
->read (per_objfile
->objfile
);
24156 baton
->per_objfile
= per_objfile
;
24157 baton
->per_cu
= cu
->per_cu
;
24158 gdb_assert (baton
->per_cu
);
24159 /* We don't know how long the location list is, but make sure we
24160 don't run off the edge of the section. */
24161 baton
->size
= section
->size
- attr
->as_unsigned ();
24162 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24163 if (cu
->base_address
.has_value ())
24164 baton
->base_address
= *cu
->base_address
;
24166 baton
->base_address
= 0;
24167 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24171 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24172 struct dwarf2_cu
*cu
, int is_block
)
24174 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24175 struct objfile
*objfile
= per_objfile
->objfile
;
24176 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24178 if (attr
->form_is_section_offset ()
24179 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24180 the section. If so, fall through to the complaint in the
24182 && attr
->as_unsigned () < section
->get_size (objfile
))
24184 struct dwarf2_loclist_baton
*baton
;
24186 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24188 fill_in_loclist_baton (cu
, baton
, attr
);
24190 if (!cu
->base_address
.has_value ())
24191 complaint (_("Location list used without "
24192 "specifying the CU base address."));
24194 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24195 ? dwarf2_loclist_block_index
24196 : dwarf2_loclist_index
);
24197 SYMBOL_LOCATION_BATON (sym
) = baton
;
24201 struct dwarf2_locexpr_baton
*baton
;
24203 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24204 baton
->per_objfile
= per_objfile
;
24205 baton
->per_cu
= cu
->per_cu
;
24206 gdb_assert (baton
->per_cu
);
24208 if (attr
->form_is_block ())
24210 /* Note that we're just copying the block's data pointer
24211 here, not the actual data. We're still pointing into the
24212 info_buffer for SYM's objfile; right now we never release
24213 that buffer, but when we do clean up properly this may
24215 struct dwarf_block
*block
= attr
->as_block ();
24216 baton
->size
= block
->size
;
24217 baton
->data
= block
->data
;
24221 dwarf2_invalid_attrib_class_complaint ("location description",
24222 sym
->natural_name ());
24226 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24227 ? dwarf2_locexpr_block_index
24228 : dwarf2_locexpr_index
);
24229 SYMBOL_LOCATION_BATON (sym
) = baton
;
24235 const comp_unit_head
*
24236 dwarf2_per_cu_data::get_header () const
24238 if (!m_header_read_in
)
24240 const gdb_byte
*info_ptr
24241 = this->section
->buffer
+ to_underlying (this->sect_off
);
24243 memset (&m_header
, 0, sizeof (m_header
));
24245 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24246 rcuh_kind::COMPILE
);
24248 m_header_read_in
= true;
24257 dwarf2_per_cu_data::addr_size () const
24259 return this->get_header ()->addr_size
;
24265 dwarf2_per_cu_data::offset_size () const
24267 return this->get_header ()->offset_size
;
24273 dwarf2_per_cu_data::ref_addr_size () const
24275 const comp_unit_head
*header
= this->get_header ();
24277 if (header
->version
== 2)
24278 return header
->addr_size
;
24280 return header
->offset_size
;
24283 /* A helper function for dwarf2_find_containing_comp_unit that returns
24284 the index of the result, and that searches a vector. It will
24285 return a result even if the offset in question does not actually
24286 occur in any CU. This is separate so that it can be unit
24290 dwarf2_find_containing_comp_unit
24291 (sect_offset sect_off
,
24292 unsigned int offset_in_dwz
,
24293 const std::vector
<dwarf2_per_cu_data_up
> &all_comp_units
)
24298 high
= all_comp_units
.size () - 1;
24301 struct dwarf2_per_cu_data
*mid_cu
;
24302 int mid
= low
+ (high
- low
) / 2;
24304 mid_cu
= all_comp_units
[mid
].get ();
24305 if (mid_cu
->is_dwz
> offset_in_dwz
24306 || (mid_cu
->is_dwz
== offset_in_dwz
24307 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24312 gdb_assert (low
== high
);
24316 /* Locate the .debug_info compilation unit from CU's objfile which contains
24317 the DIE at OFFSET. Raises an error on failure. */
24319 static struct dwarf2_per_cu_data
*
24320 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24321 unsigned int offset_in_dwz
,
24322 dwarf2_per_objfile
*per_objfile
)
24324 int low
= dwarf2_find_containing_comp_unit
24325 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24326 dwarf2_per_cu_data
*this_cu
24327 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24329 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24331 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24332 error (_("Dwarf Error: could not find partial DIE containing "
24333 "offset %s [in module %s]"),
24334 sect_offset_str (sect_off
),
24335 bfd_get_filename (per_objfile
->objfile
->obfd
));
24337 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24339 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24343 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24344 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24345 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24346 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24353 namespace selftests
{
24354 namespace find_containing_comp_unit
{
24359 dwarf2_per_cu_data_up
one (new dwarf2_per_cu_data
);
24360 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24361 dwarf2_per_cu_data_up
two (new dwarf2_per_cu_data
);
24362 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24363 dwarf2_per_cu_data_up
three (new dwarf2_per_cu_data
);
24364 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24365 dwarf2_per_cu_data_up
four (new dwarf2_per_cu_data
);
24366 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24369 two
->sect_off
= sect_offset (one
->length
);
24374 four
->sect_off
= sect_offset (three
->length
);
24378 std::vector
<dwarf2_per_cu_data_up
> units
;
24379 units
.push_back (std::move (one
));
24380 units
.push_back (std::move (two
));
24381 units
.push_back (std::move (three
));
24382 units
.push_back (std::move (four
));
24386 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24387 SELF_CHECK (units
[result
].get () == one_ptr
);
24388 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24389 SELF_CHECK (units
[result
].get () == one_ptr
);
24390 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24391 SELF_CHECK (units
[result
].get () == two_ptr
);
24393 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24394 SELF_CHECK (units
[result
].get () == three_ptr
);
24395 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24396 SELF_CHECK (units
[result
].get () == three_ptr
);
24397 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24398 SELF_CHECK (units
[result
].get () == four_ptr
);
24404 #endif /* GDB_SELF_TEST */
24406 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24409 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24410 enum language pretend_language
)
24412 struct attribute
*attr
;
24414 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24416 /* Set the language we're debugging. */
24417 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24418 if (cu
->producer
!= nullptr
24419 && strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
24421 /* The XLCL doesn't generate DW_LANG_OpenCL because this
24422 attribute is not standardised yet. As a workaround for the
24423 language detection we fall back to the DW_AT_producer
24425 cu
->per_cu
->lang
= language_opencl
;
24427 else if (cu
->producer
!= nullptr
24428 && strstr (cu
->producer
, "GNU Go ") != NULL
)
24430 /* Similar hack for Go. */
24431 cu
->per_cu
->lang
= language_go
;
24433 else if (attr
!= nullptr)
24434 cu
->per_cu
->lang
= dwarf_lang_to_enum_language (attr
->constant_value (0));
24436 cu
->per_cu
->lang
= pretend_language
;
24437 cu
->language_defn
= language_def (cu
->per_cu
->lang
);
24443 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24445 auto it
= m_dwarf2_cus
.find (per_cu
);
24446 if (it
== m_dwarf2_cus
.end ())
24455 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24457 gdb_assert (this->get_cu (per_cu
) == nullptr);
24459 m_dwarf2_cus
[per_cu
] = cu
;
24465 dwarf2_per_objfile::age_comp_units ()
24467 dwarf_read_debug_printf_v ("running");
24469 /* This is not expected to be called in the middle of CU expansion. There is
24470 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24471 loaded in memory. Calling age_comp_units while the queue is in use could
24472 make us free the DIEs for a CU that is in the queue and therefore break
24474 gdb_assert (!this->per_bfd
->queue
.has_value ());
24476 /* Start by clearing all marks. */
24477 for (auto pair
: m_dwarf2_cus
)
24478 pair
.second
->clear_mark ();
24480 /* Traverse all CUs, mark them and their dependencies if used recently
24482 for (auto pair
: m_dwarf2_cus
)
24484 dwarf2_cu
*cu
= pair
.second
;
24487 if (cu
->last_used
<= dwarf_max_cache_age
)
24491 /* Delete all CUs still not marked. */
24492 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24494 dwarf2_cu
*cu
= it
->second
;
24496 if (!cu
->is_marked ())
24498 dwarf_read_debug_printf_v ("deleting old CU %s",
24499 sect_offset_str (cu
->per_cu
->sect_off
));
24501 it
= m_dwarf2_cus
.erase (it
);
24511 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24513 auto it
= m_dwarf2_cus
.find (per_cu
);
24514 if (it
== m_dwarf2_cus
.end ())
24519 m_dwarf2_cus
.erase (it
);
24522 dwarf2_per_objfile::~dwarf2_per_objfile ()
24527 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24528 We store these in a hash table separate from the DIEs, and preserve them
24529 when the DIEs are flushed out of cache.
24531 The CU "per_cu" pointer is needed because offset alone is not enough to
24532 uniquely identify the type. A file may have multiple .debug_types sections,
24533 or the type may come from a DWO file. Furthermore, while it's more logical
24534 to use per_cu->section+offset, with Fission the section with the data is in
24535 the DWO file but we don't know that section at the point we need it.
24536 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24537 because we can enter the lookup routine, get_die_type_at_offset, from
24538 outside this file, and thus won't necessarily have PER_CU->cu.
24539 Fortunately, PER_CU is stable for the life of the objfile. */
24541 struct dwarf2_per_cu_offset_and_type
24543 const struct dwarf2_per_cu_data
*per_cu
;
24544 sect_offset sect_off
;
24548 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24551 per_cu_offset_and_type_hash (const void *item
)
24553 const struct dwarf2_per_cu_offset_and_type
*ofs
24554 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24556 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24559 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24562 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24564 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24565 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24566 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24567 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24569 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24570 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24573 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24574 table if necessary. For convenience, return TYPE.
24576 The DIEs reading must have careful ordering to:
24577 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24578 reading current DIE.
24579 * Not trying to dereference contents of still incompletely read in types
24580 while reading in other DIEs.
24581 * Enable referencing still incompletely read in types just by a pointer to
24582 the type without accessing its fields.
24584 Therefore caller should follow these rules:
24585 * Try to fetch any prerequisite types we may need to build this DIE type
24586 before building the type and calling set_die_type.
24587 * After building type call set_die_type for current DIE as soon as
24588 possible before fetching more types to complete the current type.
24589 * Make the type as complete as possible before fetching more types. */
24591 static struct type
*
24592 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24593 bool skip_data_location
)
24595 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24596 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24597 struct objfile
*objfile
= per_objfile
->objfile
;
24598 struct attribute
*attr
;
24599 struct dynamic_prop prop
;
24601 /* For Ada types, make sure that the gnat-specific data is always
24602 initialized (if not already set). There are a few types where
24603 we should not be doing so, because the type-specific area is
24604 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24605 where the type-specific area is used to store the floatformat).
24606 But this is not a problem, because the gnat-specific information
24607 is actually not needed for these types. */
24608 if (need_gnat_info (cu
)
24609 && type
->code () != TYPE_CODE_FUNC
24610 && type
->code () != TYPE_CODE_FLT
24611 && type
->code () != TYPE_CODE_METHODPTR
24612 && type
->code () != TYPE_CODE_MEMBERPTR
24613 && type
->code () != TYPE_CODE_METHOD
24614 && type
->code () != TYPE_CODE_FIXED_POINT
24615 && !HAVE_GNAT_AUX_INFO (type
))
24616 INIT_GNAT_SPECIFIC (type
);
24618 /* Read DW_AT_allocated and set in type. */
24619 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24622 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24623 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24624 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24627 /* Read DW_AT_associated and set in type. */
24628 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24631 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24632 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24633 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24636 /* Read DW_AT_data_location and set in type. */
24637 if (!skip_data_location
)
24639 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24640 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24641 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24644 if (per_objfile
->die_type_hash
== NULL
)
24645 per_objfile
->die_type_hash
24646 = htab_up (htab_create_alloc (127,
24647 per_cu_offset_and_type_hash
,
24648 per_cu_offset_and_type_eq
,
24649 NULL
, xcalloc
, xfree
));
24651 ofs
.per_cu
= cu
->per_cu
;
24652 ofs
.sect_off
= die
->sect_off
;
24654 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24655 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24657 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24658 sect_offset_str (die
->sect_off
));
24659 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24660 struct dwarf2_per_cu_offset_and_type
);
24665 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24666 or return NULL if the die does not have a saved type. */
24668 static struct type
*
24669 get_die_type_at_offset (sect_offset sect_off
,
24670 dwarf2_per_cu_data
*per_cu
,
24671 dwarf2_per_objfile
*per_objfile
)
24673 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24675 if (per_objfile
->die_type_hash
== NULL
)
24678 ofs
.per_cu
= per_cu
;
24679 ofs
.sect_off
= sect_off
;
24680 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24681 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24688 /* Look up the type for DIE in CU in die_type_hash,
24689 or return NULL if DIE does not have a saved type. */
24691 static struct type
*
24692 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24694 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24697 /* Trivial hash function for partial_die_info: the hash value of a DIE
24698 is its offset in .debug_info for this objfile. */
24701 partial_die_hash (const void *item
)
24703 const struct partial_die_info
*part_die
24704 = (const struct partial_die_info
*) item
;
24706 return to_underlying (part_die
->sect_off
);
24709 /* Trivial comparison function for partial_die_info structures: two DIEs
24710 are equal if they have the same offset. */
24713 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24715 const struct partial_die_info
*part_die_lhs
24716 = (const struct partial_die_info
*) item_lhs
;
24717 const struct partial_die_info
*part_die_rhs
24718 = (const struct partial_die_info
*) item_rhs
;
24720 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24723 struct cmd_list_element
*set_dwarf_cmdlist
;
24724 struct cmd_list_element
*show_dwarf_cmdlist
;
24727 show_check_physname (struct ui_file
*file
, int from_tty
,
24728 struct cmd_list_element
*c
, const char *value
)
24730 fprintf_filtered (file
,
24731 _("Whether to check \"physname\" is %s.\n"),
24735 void _initialize_dwarf2_read ();
24737 _initialize_dwarf2_read ()
24739 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
24740 Set DWARF specific variables.\n\
24741 Configure DWARF variables such as the cache size."),
24742 &set_dwarf_cmdlist
,
24743 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24745 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
24746 Show DWARF specific variables.\n\
24747 Show DWARF variables such as the cache size."),
24748 &show_dwarf_cmdlist
,
24749 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24751 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24752 &dwarf_max_cache_age
, _("\
24753 Set the upper bound on the age of cached DWARF compilation units."), _("\
24754 Show the upper bound on the age of cached DWARF compilation units."), _("\
24755 A higher limit means that cached compilation units will be stored\n\
24756 in memory longer, and more total memory will be used. Zero disables\n\
24757 caching, which can slow down startup."),
24759 show_dwarf_max_cache_age
,
24760 &set_dwarf_cmdlist
,
24761 &show_dwarf_cmdlist
);
24763 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24764 Set debugging of the DWARF reader."), _("\
24765 Show debugging of the DWARF reader."), _("\
24766 When enabled (non-zero), debugging messages are printed during DWARF\n\
24767 reading and symtab expansion. A value of 1 (one) provides basic\n\
24768 information. A value greater than 1 provides more verbose information."),
24771 &setdebuglist
, &showdebuglist
);
24773 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24774 Set debugging of the DWARF DIE reader."), _("\
24775 Show debugging of the DWARF DIE reader."), _("\
24776 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24777 The value is the maximum depth to print."),
24780 &setdebuglist
, &showdebuglist
);
24782 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24783 Set debugging of the dwarf line reader."), _("\
24784 Show debugging of the dwarf line reader."), _("\
24785 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24786 A value of 1 (one) provides basic information.\n\
24787 A value greater than 1 provides more verbose information."),
24790 &setdebuglist
, &showdebuglist
);
24792 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24793 Set cross-checking of \"physname\" code against demangler."), _("\
24794 Show cross-checking of \"physname\" code against demangler."), _("\
24795 When enabled, GDB's internal \"physname\" code is checked against\n\
24797 NULL
, show_check_physname
,
24798 &setdebuglist
, &showdebuglist
);
24800 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24801 no_class
, &use_deprecated_index_sections
, _("\
24802 Set whether to use deprecated gdb_index sections."), _("\
24803 Show whether to use deprecated gdb_index sections."), _("\
24804 When enabled, deprecated .gdb_index sections are used anyway.\n\
24805 Normally they are ignored either because of a missing feature or\n\
24806 performance issue.\n\
24807 Warning: This option must be enabled before gdb reads the file."),
24810 &setlist
, &showlist
);
24812 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24813 &dwarf2_locexpr_funcs
);
24814 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24815 &dwarf2_loclist_funcs
);
24817 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24818 &dwarf2_block_frame_base_locexpr_funcs
);
24819 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24820 &dwarf2_block_frame_base_loclist_funcs
);
24823 selftests::register_test ("dw2_expand_symtabs_matching",
24824 selftests::dw2_expand_symtabs_matching::run_test
);
24825 selftests::register_test ("dwarf2_find_containing_comp_unit",
24826 selftests::find_containing_comp_unit::run_test
);